]> git.sesse.net Git - vlc/blob - modules/gui/skins2/win32/win32_window.cpp
- modules/control/showintf.c: new control module, able to show the
[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 "../src/vlcproc.hpp"
29 #include "win32_window.hpp"
30 #include "win32_dragdrop.hpp"
31 #include "win32_factory.hpp"
32
33
34 /// Fading API
35 #ifndef LWA_COLORKEY
36 #   define LWA_COLORKEY  0x00000001
37 #   define LWA_ALPHA     0x00000002
38 #endif
39
40
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 )
46 {
47     // Create the window
48     if( pParentWindow )
49     {
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 );
55     }
56     else
57     {
58         // Normal window
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 );
62     }
63
64     if( !m_hWnd )
65     {
66         msg_Err( getIntf(), "CreateWindow failed" );
67         return;
68     }
69
70     // Store a pointer to the GenericWindow in a map
71     Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
72     pFactory->m_windowMap[m_hWnd] = &rWindow;
73
74     // Drag & drop
75     if( m_dragDrop )
76     {
77         m_pDropTarget = (LPDROPTARGET) new Win32DragDrop( getIntf(),
78                                                           playOnDrop );
79         // Register the window as a drop target
80         RegisterDragDrop( m_hWnd, m_pDropTarget );
81     }
82
83     // XXX Set this window as the vout
84     if( pParentWindow )
85     {
86         VlcProc::instance( getIntf() )->setVoutWindow( (void*)m_hWnd );
87     }
88 }
89
90
91 Win32Window::~Win32Window()
92 {
93     Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
94     pFactory->m_windowMap[m_hWnd] = NULL;
95
96     if( m_hWnd )
97     {
98         if( m_dragDrop )
99         {
100             // Remove the window from the list of drop targets
101             RevokeDragDrop( m_hWnd );
102             m_pDropTarget->Release();
103         }
104
105         DestroyWindow( m_hWnd );
106     }
107 }
108
109
110 void Win32Window::show( int left, int top ) const
111 {
112     ShowWindow( m_hWnd, SW_SHOW );
113 }
114
115
116 void Win32Window::hide() const
117 {
118     ShowWindow( m_hWnd, SW_HIDE );
119 }
120
121
122 void Win32Window::moveResize( int left, int top, int width, int height ) const
123 {
124     MoveWindow( m_hWnd, left, top, width, height, true );
125 }
126
127
128 void Win32Window::raise() const
129 {
130 //     SetWindowPos( m_hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
131     SetForegroundWindow( m_hWnd );
132 }
133
134
135 void Win32Window::setOpacity( uint8_t value ) const
136 {
137     Win32Factory *pFactory = (Win32Factory*)Win32Factory::instance( getIntf() );
138
139     if( value == 255 )
140     {
141         // If the window is opaque, we remove the WS_EX_LAYERED attribute
142         // which slows down resizing for nothing
143         if( m_isLayered )
144         {
145             SetWindowLongPtr( m_hWnd, GWL_EXSTYLE,
146                 GetWindowLong( m_hWnd, GWL_EXSTYLE ) & ~WS_EX_LAYERED );
147
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);
152
153             m_isLayered = false;
154         }
155     }
156     else
157     {
158         if( pFactory->SetLayeredWindowAttributes )
159         {
160             if( ! m_isLayered )
161             {
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 );
166
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);
171
172                 m_isLayered = true;
173             }
174
175             // Change the opacity
176             pFactory->SetLayeredWindowAttributes(
177                 m_hWnd, 0, value, LWA_ALPHA|LWA_COLORKEY );
178         }
179     }
180 }
181
182
183 void Win32Window::toggleOnTop( bool onTop ) const
184 {
185     if( onTop )
186     {
187         // Set the window on top
188         SetWindowPos( m_hWnd, HWND_TOPMOST, 0, 0, 0, 0,
189                       SWP_NOSIZE | SWP_NOMOVE );
190     }
191     else
192     {
193         // Set the window not on top
194         SetWindowPos( m_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
195                       SWP_NOSIZE | SWP_NOMOVE );
196     }
197 }
198
199
200 #endif