1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
8 * Olivier Teulière <ipkiss@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
27 #include "../src/generic_window.hpp"
28 #include "../src/vlcproc.hpp"
29 #include "win32_window.hpp"
30 #include "win32_dragdrop.hpp"
31 #include "win32_factory.hpp"
36 # define LWA_COLORKEY 0x00000001
37 # define LWA_ALPHA 0x00000002
41 Win32Window::Win32Window( intf_thread_t *pIntf, GenericWindow &rWindow,
42 HINSTANCE hInst, HWND hParentWindow,
43 bool dragDrop, bool playOnDrop,
44 Win32Window *pParentWindow ):
45 OSWindow( pIntf ), m_dragDrop( dragDrop ), m_isLayered( false )
50 // Child window (for vout)
51 HWND hParent = pParentWindow->getHandle();
52 m_hWnd = CreateWindowEx( WS_EX_TOOLWINDOW, "SkinWindowClass",
53 "default name", WS_CHILD, CW_USEDEFAULT, CW_USEDEFAULT,
54 CW_USEDEFAULT, CW_USEDEFAULT, hParent, 0, hInst, NULL );
59 m_hWnd = CreateWindowEx( WS_EX_TOOLWINDOW, "SkinWindowClass",
60 "default name", WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
61 CW_USEDEFAULT, CW_USEDEFAULT, hParentWindow, 0, hInst, NULL );
66 msg_Err( getIntf(), "CreateWindow failed" );
70 // Store a pointer to the GenericWindow in a map
71 Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
72 pFactory->m_windowMap[m_hWnd] = &rWindow;
77 m_pDropTarget = (LPDROPTARGET) new Win32DragDrop( getIntf(),
79 // Register the window as a drop target
80 RegisterDragDrop( m_hWnd, m_pDropTarget );
83 // XXX Set this window as the vout
86 VlcProc::instance( getIntf() )->setVoutWindow( (void*)m_hWnd );
91 Win32Window::~Win32Window()
93 Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
94 pFactory->m_windowMap[m_hWnd] = NULL;
100 // Remove the window from the list of drop targets
101 RevokeDragDrop( m_hWnd );
102 m_pDropTarget->Release();
105 DestroyWindow( m_hWnd );
110 void Win32Window::show( int left, int top ) const
112 ShowWindow( m_hWnd, SW_SHOW );
116 void Win32Window::hide() const
118 ShowWindow( m_hWnd, SW_HIDE );
122 void Win32Window::moveResize( int left, int top, int width, int height ) const
124 MoveWindow( m_hWnd, left, top, width, height, true );
128 void Win32Window::raise() const
130 // SetWindowPos( m_hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
131 SetForegroundWindow( m_hWnd );
135 void Win32Window::setOpacity( uint8_t value ) const
137 Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
141 // If the window is opaque, we remove the WS_EX_LAYERED attribute
142 // which slows down resizing for nothing
145 SetWindowLongPtr( m_hWnd, GWL_EXSTYLE,
146 GetWindowLong( m_hWnd, GWL_EXSTYLE ) & ~WS_EX_LAYERED );
148 // Redraw the window, otherwise we may end up with a grey rectangle
149 // for some strange reason
150 RedrawWindow(m_hWnd, NULL, NULL,
151 RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
158 if( pFactory->SetLayeredWindowAttributes )
162 // (Re)Add the WS_EX_LAYERED attribute.
163 // Resizing will be very slow, now :)
164 SetWindowLongPtr( m_hWnd, GWL_EXSTYLE,
165 GetWindowLong( m_hWnd, GWL_EXSTYLE ) | WS_EX_LAYERED );
167 // Redraw the window, otherwise we may end up with a grey
168 // rectangle for some strange reason
169 RedrawWindow(m_hWnd, NULL, NULL,
170 RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
175 // Change the opacity
176 pFactory->SetLayeredWindowAttributes(
177 m_hWnd, 0, value, LWA_ALPHA|LWA_COLORKEY );
183 void Win32Window::toggleOnTop( bool onTop ) const
187 // Set the window on top
188 SetWindowPos( m_hWnd, HWND_TOPMOST, 0, 0, 0, 0,
189 SWP_NOSIZE | SWP_NOMOVE );
193 // Set the window not on top
194 SetWindowPos( m_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
195 SWP_NOSIZE | SWP_NOMOVE );