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