]> git.sesse.net Git - vlc/blob - modules/gui/skins/win32/win32_window.cpp
* Added support of wheel with win32
[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.8 2003/04/20 15:06:07 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 "../src/anchor.h"
40 #include "../controls/generic.h"
41 #include "../src/window.h"
42 #include "../os_window.h"
43 #include "../src/event.h"
44 #include "../os_event.h"
45 #include "../src/graphics.h"
46 #include "../os_graphics.h"
47 #include "../src/skin_common.h"
48 #include "../src/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         case WM_MOUSEWHEEL:
205             if( HIWORD( p1 ) > 0 )
206                 MouseScroll( LOWORD( p2 ), HIWORD( p2 ), MOUSE_SCROLL_UP );
207             else if( HIWORD( p1 ) < 0 )
208                 MouseScroll( LOWORD( p2 ), HIWORD( p2 ), MOUSE_SCROLL_DOWN );
209             return true;
210
211         default:
212             return false;
213     }
214 }
215 //---------------------------------------------------------------------------
216 void Win32Window::SetTransparency( int Value )
217 {
218     if( Value > -1 )
219         Alpha = Value;
220     SetLayeredWindowAttributes( hWnd, 0, Alpha, LWA_ALPHA | LWA_COLORKEY );
221     UpdateWindow( hWnd );
222 }
223 //---------------------------------------------------------------------------
224 void Win32Window::RefreshFromImage( int x, int y, int w, int h )
225 {
226     // Initialize painting
227     HDC DC = GetWindowDC( hWnd );
228
229     // Draw image on window
230     BitBlt( DC, x, y, w, h, ( (Win32Graphics *)Image )->GetImageHandle(),
231             x, y, SRCCOPY );
232
233     // Release window device context
234     ReleaseDC( hWnd, DC );
235
236 }
237 //---------------------------------------------------------------------------
238 void Win32Window::WindowManualMove()
239 {
240     // Get mouse cursor position
241     LPPOINT NewPos = new POINT;
242     GetCursorPos( NewPos );
243
244     // Move window and chek for magnetism
245     p_intf->p_sys->p_theme->MoveSkinMagnet( this,
246         WindowPos->x + NewPos->x - CursorPos->x,
247         WindowPos->y + NewPos->y - CursorPos->y );
248
249     // Free memory
250     delete[] NewPos;
251
252 }
253 //---------------------------------------------------------------------------
254 void Win32Window::WindowManualMoveInit()
255 {
256     GetCursorPos( CursorPos );
257     WindowPos->x = Left;
258     WindowPos->y = Top;
259 }
260 //---------------------------------------------------------------------------
261 void Win32Window::Move( int left, int top )
262 {
263     Left = left;
264     Top  = top;
265     //SetWindowPos( hWnd, HWND_TOP, Left, Top, Width, Height,
266     //              SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER );
267     MoveWindow( hWnd, Left, Top, Width, Height, false );
268 }
269 //---------------------------------------------------------------------------
270 void Win32Window::Size( int width, int height )
271 {
272     Width  = width;
273     Height = height;
274     SetWindowPos( hWnd, HWND_TOP, Left, Top, Width, Height,
275                   SWP_NOMOVE|SWP_NOREDRAW|SWP_NOZORDER );
276 }
277 //---------------------------------------------------------------------------
278 void Win32Window::ChangeToolTipText( string text )
279 {
280     if( text == "none" )
281     {
282         if( ToolTipText != "none" )
283         {
284             ToolTipText = "none";
285             ToolTipInfo.lpszText = NULL;
286             SendMessage( ToolTipWindow, TTM_ACTIVATE, 0 , 0 );
287         }
288     }
289     else
290     {
291         if( text != ToolTipText )
292         {
293             ToolTipText = text;
294             ToolTipInfo.lpszText = (char *)ToolTipText.c_str();
295             SendMessage( ToolTipWindow, TTM_ACTIVATE, 1 , 0 );
296             SendMessage( ToolTipWindow, TTM_UPDATETIPTEXT, 0,
297                              (LPARAM)(LPTOOLINFO)&ToolTipInfo );
298         }
299     }
300
301 }
302 //---------------------------------------------------------------------------
303
304 #endif