1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2003 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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 // XXX layered windows are supposed to work only with at least win2k
43 # define WS_EX_LAYERED 0x00080000
46 Win32Window::Win32Window( intf_thread_t *pIntf, GenericWindow &rWindow,
47 HINSTANCE hInst, HWND hParentWindow,
48 bool dragDrop, bool playOnDrop,
49 Win32Window *pParentWindow ):
50 OSWindow( pIntf ), m_dragDrop( dragDrop ), m_isLayered( false ),
51 m_pParent( pParentWindow )
56 // Child window (for vout)
57 m_hWnd_parent = pParentWindow->getHandle();
58 m_hWnd = CreateWindowEx( WS_EX_TOOLWINDOW, "SkinWindowClass",
59 "default name", WS_CHILD, CW_USEDEFAULT, CW_USEDEFAULT,
60 CW_USEDEFAULT, CW_USEDEFAULT, m_hWnd_parent, 0, hInst, NULL );
65 m_hWnd_parent = hParentWindow;
66 m_hWnd = CreateWindowEx( WS_EX_TOOLWINDOW, "SkinWindowClass",
67 "default name", WS_POPUP | WS_CLIPCHILDREN,
68 CW_USEDEFAULT, CW_USEDEFAULT,
69 CW_USEDEFAULT, CW_USEDEFAULT, m_hWnd_parent, 0, hInst, NULL );
74 msg_Err( getIntf(), "CreateWindow failed" );
78 // Store a pointer to the GenericWindow in a map
79 Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
80 pFactory->m_windowMap[m_hWnd] = &rWindow;
85 m_pDropTarget = (LPDROPTARGET) new Win32DragDrop( getIntf(),
87 // Register the window as a drop target
88 RegisterDragDrop( m_hWnd, m_pDropTarget );
93 Win32Window::~Win32Window()
95 Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
96 pFactory->m_windowMap[m_hWnd] = NULL;
102 // Remove the window from the list of drop targets
103 RevokeDragDrop( m_hWnd );
104 m_pDropTarget->Release();
107 DestroyWindow( m_hWnd );
112 void Win32Window::reparent( void* OSHandle, int x, int y, int w, int h )
114 // Reparent the window
115 SetParent( m_hWnd, (HWND)OSHandle );
116 MoveWindow( m_hWnd, x, y, w, h, true );
120 void Win32Window::show( int left, int top ) const
122 ShowWindow( m_hWnd, SW_SHOW );
126 void Win32Window::hide() const
128 ShowWindow( m_hWnd, SW_HIDE );
132 void Win32Window::moveResize( int left, int top, int width, int height ) const
134 MoveWindow( m_hWnd, left, top, width, height, true );
138 void Win32Window::raise() const
140 // SetWindowPos( m_hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
141 SetForegroundWindow( m_hWnd );
145 void Win32Window::setOpacity( uint8_t value ) const
147 Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
151 // If the window is opaque, we remove the WS_EX_LAYERED attribute
152 // which slows down resizing for nothing
155 SetWindowLongPtr( m_hWnd, GWL_EXSTYLE,
156 GetWindowLong( m_hWnd, GWL_EXSTYLE ) & ~WS_EX_LAYERED );
158 // Redraw the window, otherwise we may end up with a grey rectangle
159 // for some strange reason
160 RedrawWindow(m_hWnd, NULL, NULL,
161 RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
168 if( pFactory->SetLayeredWindowAttributes )
172 // (Re)Add the WS_EX_LAYERED attribute.
173 // Resizing will be very slow, now :)
174 SetWindowLongPtr( m_hWnd, GWL_EXSTYLE,
175 GetWindowLong( m_hWnd, GWL_EXSTYLE ) | WS_EX_LAYERED );
177 // Redraw the window, otherwise we may end up with a grey
178 // rectangle for some strange reason
179 RedrawWindow(m_hWnd, NULL, NULL,
180 RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
185 // Change the opacity
186 pFactory->SetLayeredWindowAttributes(
187 m_hWnd, 0, value, LWA_ALPHA|LWA_COLORKEY );
193 void Win32Window::toggleOnTop( bool onTop ) const
197 // Set the window on top
198 SetWindowPos( m_hWnd, HWND_TOPMOST, 0, 0, 0, 0,
199 SWP_NOSIZE | SWP_NOMOVE );
203 // Set the window not on top
204 SetWindowPos( m_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
205 SWP_NOSIZE | SWP_NOMOVE );