]> git.sesse.net Git - vlc/blob - modules/gui/skins2/win32/win32_window.cpp
Disabled my last changes, since they don't seem to work in all cases.
[vlc] / modules / gui / skins2 / win32 / win32_window.cpp
1 /*****************************************************************************
2  * win32_window.cpp
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id$
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *          Olivier Teulière <ipkiss@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 #ifdef WIN32_SKINS
26
27 #include "../src/generic_window.hpp"
28 #include "win32_window.hpp"
29 #include "win32_dragdrop.hpp"
30 #include "win32_factory.hpp"
31
32
33 /// Fading API
34 #ifndef LWA_COLORKEY
35 #   define LWA_COLORKEY  0x00000001
36 #   define LWA_ALPHA     0x00000002
37 #endif
38
39
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 )
45 {
46     // Create the window
47     if( pParentWindow )
48     {
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 );
54     }
55     else
56     {
57         // Normal window
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 );
61     }
62
63     if( !m_hWnd )
64     {
65         msg_Err( getIntf(), "CreateWindow failed" );
66         return;
67     }
68
69     // We do it this way otherwise CreateWindowEx will fail if WS_EX_LAYERED
70     // is not supported
71 //     SetWindowLongPtr( m_hWnd, GWL_EXSTYLE,
72 //                       GetWindowLong( m_hWnd, GWL_EXSTYLE ) | WS_EX_LAYERED );
73
74     // Store a pointer to the GenericWindow in a map
75     Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
76     pFactory->m_windowMap[m_hWnd] = &rWindow;
77
78     // Drag & drop
79     if( m_dragDrop )
80     {
81         m_pDropTarget = (LPDROPTARGET) new Win32DragDrop( getIntf(),
82                                                           playOnDrop );
83         // Register the window as a drop target
84         RegisterDragDrop( m_hWnd, m_pDropTarget );
85     }
86     // XXX: Kludge to tell VLC that this window is the vout
87     if( pParentWindow )
88     {
89         vlc_value_t value;
90         value.i_int = (int) (ptrdiff_t) (void *) m_hWnd;
91         var_Set( getIntf()->p_vlc, "drawable", value );
92     }
93 }
94
95
96 Win32Window::~Win32Window()
97 {
98     Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
99     pFactory->m_windowMap[m_hWnd] = NULL;
100
101     if( m_hWnd )
102     {
103         if( m_dragDrop )
104         {
105             // Remove the window from the list of drop targets
106             RevokeDragDrop( m_hWnd );
107             m_pDropTarget->Release();
108         }
109
110         DestroyWindow( m_hWnd );
111     }
112 }
113
114
115 void Win32Window::show( int left, int top ) const
116 {
117     ShowWindow( m_hWnd, SW_SHOW );
118 }
119
120
121 void Win32Window::hide() const
122 {
123     ShowWindow( m_hWnd, SW_HIDE );
124 }
125
126
127 void Win32Window::moveResize( int left, int top, int width, int height ) const
128 {
129     MoveWindow( m_hWnd, left, top, width, height, true );
130 }
131
132
133 void Win32Window::raise() const
134 {
135     SetWindowPos( m_hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
136 }
137
138
139 void Win32Window::setOpacity( uint8_t value ) const
140 {
141 #if 0
142     Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
143
144     if( value == 255 )
145     {
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 );
152     }
153     else
154     {
155         if( pFactory->SetLayeredWindowAttributes )
156         {
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 );
163
164             // Change the opacity
165             pFactory->SetLayeredWindowAttributes(
166                 m_hWnd, 0, value, LWA_ALPHA|LWA_COLORKEY );
167         }
168     }
169
170    UpdateWindow( m_hWnd );
171 #endif
172 }
173
174
175 void Win32Window::toggleOnTop( bool onTop ) const
176 {
177     if( onTop )
178     {
179         // Set the window on top
180         SetWindowPos( m_hWnd, HWND_TOPMOST, 0, 0, 0, 0,
181                       SWP_NOSIZE | SWP_NOMOVE );
182     }
183     else
184     {
185         // Set the window not on top
186         SetWindowPos( m_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
187                       SWP_NOSIZE | SWP_NOMOVE );
188     }
189 }
190
191
192 #endif