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 "win32_window.hpp"
29 #include "win32_dragdrop.hpp"
30 #include "win32_factory.hpp"
35 # define LWA_COLORKEY 0x00000001
36 # define LWA_ALPHA 0x00000002
40 Win32Window::Win32Window( intf_thread_t *pIntf, GenericWindow &rWindow,
41 HINSTANCE hInst, HWND hParentWindow,
42 bool dragDrop, bool playOnDrop,
43 Win32Window *pParentWindow ):
44 OSWindow( pIntf ), m_dragDrop( dragDrop )
49 // Child window (for vout)
50 HWND hParent = pParentWindow->getHandle();
51 m_hWnd = CreateWindowEx( WS_EX_TOOLWINDOW, "SkinWindowClass",
52 "default name", WS_CHILD, CW_USEDEFAULT, CW_USEDEFAULT,
53 CW_USEDEFAULT, CW_USEDEFAULT, hParent, 0, hInst, NULL );
58 m_hWnd = CreateWindowEx( WS_EX_TOOLWINDOW, "SkinWindowClass",
59 "default name", WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
60 CW_USEDEFAULT, CW_USEDEFAULT, hParentWindow, 0, hInst, NULL );
65 msg_Err( getIntf(), "CreateWindow failed" );
69 // We do it this way otherwise CreateWindowEx will fail if WS_EX_LAYERED
71 // SetWindowLongPtr( m_hWnd, GWL_EXSTYLE,
72 // GetWindowLong( m_hWnd, GWL_EXSTYLE ) | WS_EX_LAYERED );
74 // Store a pointer to the GenericWindow in a map
75 Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
76 pFactory->m_windowMap[m_hWnd] = &rWindow;
81 m_pDropTarget = (LPDROPTARGET) new Win32DragDrop( getIntf(),
83 // Register the window as a drop target
84 RegisterDragDrop( m_hWnd, m_pDropTarget );
86 // XXX: Kludge to tell VLC that this window is the vout
90 value.i_int = (int) (ptrdiff_t) (void *) m_hWnd;
91 var_Set( getIntf()->p_vlc, "drawable", value );
96 Win32Window::~Win32Window()
98 Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
99 pFactory->m_windowMap[m_hWnd] = NULL;
105 // Remove the window from the list of drop targets
106 RevokeDragDrop( m_hWnd );
107 m_pDropTarget->Release();
110 DestroyWindow( m_hWnd );
115 void Win32Window::show( int left, int top ) const
117 ShowWindow( m_hWnd, SW_SHOW );
121 void Win32Window::hide() const
123 ShowWindow( m_hWnd, SW_HIDE );
127 void Win32Window::moveResize( int left, int top, int width, int height ) const
129 MoveWindow( m_hWnd, left, top, width, height, true );
133 void Win32Window::raise() const
135 SetWindowPos( m_hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
139 void Win32Window::setOpacity( uint8_t value ) const
142 Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
146 // If the window is opaque, we remove the WS_EX_LAYERED attribute
147 // which slows resizing for nothing
148 SetWindowLongPtr( m_hWnd, GWL_EXSTYLE,
149 GetWindowLong( m_hWnd, GWL_EXSTYLE ) & !WS_EX_LAYERED );
150 SetWindowPos( m_hWnd, HWND_TOP, 0, 0, 0, 0,
151 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED );
155 if( pFactory->SetLayeredWindowAttributes )
157 // (Re)Add the WS_EX_LAYERED attribute.
158 // Resizing will be very slow, now :)
159 SetWindowLongPtr( m_hWnd, GWL_EXSTYLE,
160 GetWindowLong( m_hWnd, GWL_EXSTYLE ) | WS_EX_LAYERED );
161 SetWindowPos( m_hWnd, HWND_TOP, 0, 0, 0, 0,
162 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED );
164 // Change the opacity
165 pFactory->SetLayeredWindowAttributes(
166 m_hWnd, 0, value, LWA_ALPHA|LWA_COLORKEY );
170 UpdateWindow( m_hWnd );
175 void Win32Window::toggleOnTop( bool onTop ) const
179 // Set the window on top
180 SetWindowPos( m_hWnd, HWND_TOPMOST, 0, 0, 0, 0,
181 SWP_NOSIZE | SWP_NOMOVE );
185 // Set the window not on top
186 SetWindowPos( m_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
187 SWP_NOSIZE | SWP_NOMOVE );