]> git.sesse.net Git - vlc/blob - modules/gui/skins/win32/win32_window.cpp
* modules/gui/skins/*: compilation fixes for MSVC. Almost working, we just to find...
[vlc] / modules / gui / skins / win32 / win32_window.cpp
1 /*****************************************************************************
2  * win32_window.cpp: Win32 implementation of the Window class
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: win32_window.cpp,v 1.12 2003/05/02 15:53:32 gbazin Exp $
6  *
7  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8  *          Emmanuel Puig    <karibu@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,
23  * USA.
24  *****************************************************************************/
25
26 #ifdef WIN32
27
28 /* For TrackMouseEvent, WM_MOUSEWHEEL and GET_WHEEL_DELTA_WPARAM */
29 #undef WINVER
30 #undef _WIN32_WINNT
31 #define _WIN32_WINNT 0x0500
32 #define WINVER 0x0500
33
34 //--- GENERAL ---------------------------------------------------------------
35 //#include <math.h>
36
37 //--- VLC -------------------------------------------------------------------
38 #include <vlc/intf.h>
39
40 //--- WIN32 -----------------------------------------------------------------
41 #include <windows.h>
42
43 //--- SKIN ------------------------------------------------------------------
44 #include "../os_api.h"
45 #include "../src/anchor.h"
46 #include "../controls/generic.h"
47 #include "../src/window.h"
48 #include "../os_window.h"
49 #include "../src/event.h"
50 #include "../os_event.h"
51 #include "../src/graphics.h"
52 #include "../os_graphics.h"
53 #include "../src/skin_common.h"
54 #include "../src/theme.h"
55
56 //---------------------------------------------------------------------------
57 // Fading API
58 //---------------------------------------------------------------------------
59 #define LWA_COLORKEY  0x00000001
60 #define LWA_ALPHA     0x00000002
61
62 //---------------------------------------------------------------------------
63 // Skinable Window
64 //---------------------------------------------------------------------------
65 Win32Window::Win32Window( intf_thread_t *p_intf, HWND hwnd, int x, int y,
66     bool visible, int transition, int normalalpha, int movealpha,
67     bool dragdrop )
68     : SkinWindow( p_intf, x, y, visible, transition, normalalpha, movealpha,
69               dragdrop )
70 {
71     // Set handles
72     hWnd           = hwnd;
73
74     // Set position parameters
75     CursorPos    = new POINT;
76     WindowPos    = new POINT;
77
78     // Create Tool Tip Window
79     ToolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
80         WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
81         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
82         hWnd, 0, GetModuleHandle( NULL ), 0);
83
84     // Create Tool Tip infos
85     ToolTipInfo.cbSize = sizeof(TOOLINFO);
86     ToolTipInfo.uFlags = TTF_SUBCLASS|TTF_IDISHWND;
87     ToolTipInfo.hwnd = hWnd;
88     ToolTipInfo.hinst = GetModuleHandle( NULL );
89     ToolTipInfo.uId = (unsigned int)hWnd;
90     ToolTipInfo.lpszText = NULL;
91     ToolTipInfo.rect.left = ToolTipInfo.rect.top = 0;
92         ToolTipInfo.rect.right = ToolTipInfo.rect.bottom = 0;
93
94     SendMessage( ToolTipWindow, TTM_ADDTOOL, 0,
95                     (LPARAM)(LPTOOLINFO) &ToolTipInfo );
96
97     // Drag & drop
98     if( DragDrop )
99     {
100         // Initialize the OLE library
101         OleInitialize( NULL );
102         DropTarget = (LPDROPTARGET) new Win32DropObject();
103         // register the listview as a drop target
104         RegisterDragDrop( hWnd, DropTarget );
105     }
106
107 }
108 //---------------------------------------------------------------------------
109 Win32Window::~Win32Window()
110 {
111     delete CursorPos;
112     delete WindowPos;
113
114     if( hWnd != NULL )
115     {
116         DestroyWindow( hWnd );
117     }
118     if( ToolTipWindow != NULL )
119     {
120         DestroyWindow( ToolTipWindow );
121     }
122     if( DragDrop )
123     {
124         // Remove the listview from the list of drop targets
125         RevokeDragDrop( hWnd );
126         DropTarget->Release();
127         // Uninitialize the OLE library
128         OleUninitialize();
129     }
130
131 }
132 //---------------------------------------------------------------------------
133 void Win32Window::OSShow( bool show )
134 {
135     if( show )
136     {
137         ShowWindow( hWnd, SW_SHOW );
138     }
139     else
140     {
141         ShowWindow( hWnd, SW_HIDE );
142     }
143 }
144 //---------------------------------------------------------------------------
145 bool Win32Window::ProcessOSEvent( Event *evt )
146 {
147     unsigned int msg = evt->GetMessage();
148     unsigned int p1  = evt->GetParam1();
149     int          p2  = evt->GetParam2();
150
151     switch( msg )
152     {
153         case WM_PAINT:
154             HDC DC;
155             PAINTSTRUCT Infos;
156             DC = BeginPaint( hWnd , &Infos );
157             EndPaint( hWnd , &Infos );
158             RefreshFromImage( 0, 0, Width, Height );
159             return true;
160
161         case WM_MOUSEMOVE:
162             TRACKMOUSEEVENT TrackEvent;
163             TrackEvent.cbSize      = sizeof( TRACKMOUSEEVENT );\r
164             TrackEvent.dwFlags     = TME_LEAVE;\r
165             TrackEvent.hwndTrack   = hWnd;\r
166             TrackEvent.dwHoverTime = 1;
167             TrackMouseEvent( &TrackEvent );
168             if( p1 == MK_LBUTTON )
169                 MouseMove( LOWORD( p2 ), HIWORD( p2 ), 1 );
170             else if( p1 == MK_RBUTTON )
171                 MouseMove( LOWORD( p2 ), HIWORD( p2 ), 2 );
172             else
173                 MouseMove( LOWORD( p2 ), HIWORD( p2 ), 0 );
174
175             return true;
176
177         case WM_LBUTTONDOWN:
178             SetCapture( hWnd );
179             MouseDown( LOWORD( p2 ), HIWORD( p2 ), 1 );
180             return true;
181
182         case WM_LBUTTONUP:
183             ReleaseCapture();
184             MouseUp( LOWORD( p2 ), HIWORD( p2 ), 1 );
185             return true;
186
187         case WM_RBUTTONDOWN:
188             MouseDown( LOWORD( p2 ), HIWORD( p2 ), 2 );
189             return true;
190
191         case WM_RBUTTONUP:
192             MouseUp( LOWORD( p2 ), HIWORD( p2 ), 2 );
193             return true;
194
195         case WM_LBUTTONDBLCLK:
196             MouseDblClick( LOWORD( p2 ), HIWORD( p2 ), 1 );
197             return true;
198
199         case WM_MOUSELEAVE:
200             OSAPI_PostMessage( this, WINDOW_LEAVE, 0, 0 );
201             return true;
202
203         case WM_MOUSEWHEEL:
204             if( GET_WHEEL_DELTA_WPARAM( p1 ) > 0 )
205                 MouseScroll( LOWORD( p2 ) - Left, HIWORD( p2 ) - Top,
206                     MOUSE_SCROLL_UP );
207             else if( GET_WHEEL_DELTA_WPARAM( p1 ) < 0 )
208                 MouseScroll( LOWORD( p2 ) - Left, HIWORD( p2 ) - Top,
209                     MOUSE_SCROLL_DOWN );
210             return true;
211
212         default:
213             return false;
214     }
215 }
216 //---------------------------------------------------------------------------
217 void Win32Window::SetTransparency( int Value )
218 {
219     if( Value > -1 )
220         Alpha = Value;
221
222     if( p_intf->p_sys->SetLayeredWindowAttributes )
223         p_intf->p_sys->SetLayeredWindowAttributes( hWnd, 0, Alpha,
224                                                    LWA_ALPHA | LWA_COLORKEY );
225
226     UpdateWindow( hWnd );
227 }
228 //---------------------------------------------------------------------------
229 void Win32Window::RefreshFromImage( int x, int y, int w, int h )
230 {
231     // Initialize painting
232     HDC DC = GetWindowDC( hWnd );
233
234     // Draw image on window
235     BitBlt( DC, x, y, w, h, ( (Win32Graphics *)Image )->GetImageHandle(),
236             x, y, SRCCOPY );
237
238     // Release window device context
239     ReleaseDC( hWnd, DC );
240
241 }
242 //---------------------------------------------------------------------------
243 void Win32Window::WindowManualMove()
244 {
245     // Get mouse cursor position
246     LPPOINT NewPos = new POINT;
247     GetCursorPos( NewPos );
248
249     // Move window and chek for magnetism
250     p_intf->p_sys->p_theme->MoveSkinMagnet( this,
251         WindowPos->x + NewPos->x - CursorPos->x,
252         WindowPos->y + NewPos->y - CursorPos->y );
253
254     // Free memory
255     delete[] NewPos;
256
257 }
258 //---------------------------------------------------------------------------
259 void Win32Window::WindowManualMoveInit()
260 {
261     GetCursorPos( CursorPos );
262     WindowPos->x = Left;
263     WindowPos->y = Top;
264 }
265 //---------------------------------------------------------------------------
266 void Win32Window::Move( int left, int top )
267 {
268     Left = left;
269     Top  = top;
270     //SetWindowPos( hWnd, HWND_TOP, Left, Top, Width, Height,
271     //              SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER );
272     MoveWindow( hWnd, Left, Top, Width, Height, false );
273 }
274 //---------------------------------------------------------------------------
275 void Win32Window::Size( int width, int height )
276 {
277     Width  = width;
278     Height = height;
279     SetWindowPos( hWnd, HWND_TOP, Left, Top, Width, Height,
280                   SWP_NOMOVE|SWP_NOREDRAW|SWP_NOZORDER );
281 }
282 //---------------------------------------------------------------------------
283 void Win32Window::ChangeToolTipText( string text )
284 {
285     if( text == "none" )
286     {
287         if( ToolTipText != "none" )
288         {
289             ToolTipText = "none";
290             ToolTipInfo.lpszText = NULL;
291             SendMessage( ToolTipWindow, TTM_ACTIVATE, 0 , 0 );
292         }
293     }
294     else
295     {
296         if( text != ToolTipText )
297         {
298             ToolTipText = text;
299             ToolTipInfo.lpszText = (char *)ToolTipText.c_str();
300             SendMessage( ToolTipWindow, TTM_ACTIVATE, 1 , 0 );
301             SendMessage( ToolTipWindow, TTM_UPDATETIPTEXT, 0,
302                              (LPARAM)(LPTOOLINFO)&ToolTipInfo );
303         }
304     }
305
306 }
307 //---------------------------------------------------------------------------
308
309 #endif