]> git.sesse.net Git - vlc/blob - modules/gui/skins/gtk2/gtk2_window.cpp
385ce6e15d4d6757c0f9a1c7e9277da13b0516ea
[vlc] / modules / gui / skins / gtk2 / gtk2_window.cpp
1 /*****************************************************************************
2  * gtk2_window.cpp: GTK2 implementation of the Window class
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: gtk2_window.cpp,v 1.3 2003/04/13 17:46:22 asmax Exp $
6  *
7  * Authors: Cyril Deguet     <asmax@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111,
22  * USA.
23  *****************************************************************************/
24
25
26 //--- GENERAL ---------------------------------------------------------------
27 //#include <math.h>
28
29 //--- VLC -------------------------------------------------------------------
30 #include <vlc/intf.h>
31
32 //--- GTK2 ------------------------------------------------------------------
33 #include <gdk/gdk.h>
34
35 //--- SKIN ------------------------------------------------------------------
36 #include "os_api.h"
37 #include "anchor.h"
38 #include "generic.h"
39 #include "window.h"
40 #include "os_window.h"
41 #include "event.h"
42 #include "os_event.h"
43 #include "graphics.h"
44 #include "os_graphics.h"
45 #include "skin_common.h"
46 #include "theme.h"
47
48
49
50 //---------------------------------------------------------------------------
51 // Fading API
52 //---------------------------------------------------------------------------
53 /*#define LWA_COLORKEY  0x00000001
54 #define LWA_ALPHA     0x00000002
55 typedef BOOL (WINAPI *SLWA)(HWND, COLORREF, BYTE, DWORD);
56 HMODULE hModule = LoadLibrary( "user32.dll" );
57 SLWA SetLayeredWindowAttributes =
58     (SLWA)GetProcAddress( hModule, "SetLayeredWindowAttributes" );
59 */
60
61 //---------------------------------------------------------------------------
62 // Skinable Window
63 //---------------------------------------------------------------------------
64 GTK2Window::GTK2Window( intf_thread_t *p_intf, GdkWindow *gwnd, int x, int y,
65     bool visible, int transition, int normalalpha, int movealpha,
66     bool dragdrop )
67     : Window( p_intf, x, y, visible, transition, normalalpha, movealpha,
68               dragdrop )
69 {
70     // Set handles
71     gWnd           = gwnd;
72 /*
73     // Set position parameters
74     CursorPos    = new POINT;
75     WindowPos    = new POINT;
76
77     // Create Tool Tip Window
78     ToolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
79         WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
80         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
81         hWnd, 0, GetModuleHandle( NULL ), 0);
82
83     // Create Tool Tip infos
84     ToolTipInfo.cbSize = sizeof(TOOLINFO);
85     ToolTipInfo.uFlags = TTF_SUBCLASS|TTF_IDISHWND;
86     ToolTipInfo.hwnd = hWnd;
87     ToolTipInfo.hinst = GetModuleHandle( NULL );
88     ToolTipInfo.uId = (unsigned int)hWnd;
89     ToolTipInfo.lpszText = NULL;
90     ToolTipInfo.rect.left = ToolTipInfo.rect.top = 0;
91         ToolTipInfo.rect.right = ToolTipInfo.rect.bottom = 0;
92
93     SendMessage( ToolTipWindow, TTM_ADDTOOL, 0,
94                     (LPARAM)(LPTOOLINFO) &ToolTipInfo );
95
96     // Drag & drop
97     if( DragDrop )
98     {
99         // Initialize the OLE library
100         OleInitialize( NULL );
101         DropTarget = (LPDROPTARGET) new GTK2DropObject();
102         // register the listview as a drop target
103         RegisterDragDrop( hWnd, DropTarget );
104     }
105 */
106     // Create Tool Tip window
107 /*    GdkWindowAttr attr;
108     attr.event_mask = GDK_ALL_EVENTS_MASK;
109     attr.width = 100;
110     attr.height = 100;
111     attr.window_type = GDK_WINDOW_CHILD;
112     attr.wclass = GDK_INPUT_OUTPUT;
113     gint mask = 0;
114     ToolTipWindow = gdk_window_new( gwnd, &attr, mask);*/
115
116 }
117 //---------------------------------------------------------------------------
118 GTK2Window::~GTK2Window()
119 {
120 /*    delete CursorPos;
121     delete WindowPos;
122
123     if( hWnd != NULL )
124     {
125         DestroyWindow( hWnd );
126     }
127     if( ToolTipWindow != NULL )
128     {
129         DestroyWindow( ToolTipWindow );
130     }
131     if( DragDrop )
132     {
133         // Remove the listview from the list of drop targets
134         RevokeDragDrop( hWnd );
135         DropTarget->Release();
136         // Uninitialize the OLE library
137         OleUninitialize();
138     }
139 */
140 }
141 //---------------------------------------------------------------------------
142 void GTK2Window::OSShow( bool show )
143 {
144 /*    if( show )
145     {
146         gdk_window_show( gWnd );
147     }
148     else
149     {
150         gdk_window_hide( gWnd );
151     }*/
152 }
153 //---------------------------------------------------------------------------
154 bool GTK2Window::ProcessOSEvent( Event *evt )
155 {
156 /*    unsigned int msg = evt->GetMessage();
157     unsigned int p1  = evt->GetParam1();
158     int          p2  = evt->GetParam2();
159
160     switch( msg )
161     {
162         case WM_PAINT:
163             HDC DC;
164             PAINTSTRUCT Infos;
165             DC = BeginPaint( hWnd , &Infos );
166             EndPaint( hWnd , &Infos );
167             RefreshFromImage( 0, 0, Width, Height );
168             return true;
169
170         case WM_MOUSEMOVE:
171             TRACKMOUSEEVENT TrackEvent;
172             TrackEvent.cbSize      = sizeof( TRACKMOUSEEVENT );\r
173             TrackEvent.dwFlags     = TME_LEAVE;\r
174             TrackEvent.hwndTrack   = hWnd;\r
175             TrackEvent.dwHoverTime = 1;
176             TrackMouseEvent( &TrackEvent );
177             if( p1 == MK_LBUTTON )
178                 MouseMove( LOWORD( p2 ), HIWORD( p2 ), 1 );
179             else if( p1 == MK_RBUTTON )
180                 MouseMove( LOWORD( p2 ), HIWORD( p2 ), 2 );
181             else
182                 MouseMove( LOWORD( p2 ), HIWORD( p2 ), 0 );
183
184             return true;
185
186         case WM_LBUTTONDOWN:
187             SetCapture( hWnd );
188             MouseDown( LOWORD( p2 ), HIWORD( p2 ), 1 );
189             return true;
190
191         case WM_LBUTTONUP:
192             ReleaseCapture();
193             MouseUp( LOWORD( p2 ), HIWORD( p2 ), 1 );
194             return true;
195
196         case WM_RBUTTONDOWN:
197             MouseDown( LOWORD( p2 ), HIWORD( p2 ), 2 );
198             return true;
199
200         case WM_RBUTTONUP:
201             MouseUp( LOWORD( p2 ), HIWORD( p2 ), 2 );
202             return true;
203
204         case WM_LBUTTONDBLCLK:
205             MouseDblClick( LOWORD( p2 ), HIWORD( p2 ), 1 );
206             return true;
207
208         case WM_MOUSELEAVE:
209             OSAPI_PostMessage( this, WINDOW_LEAVE, 0, 0 );
210             return true;
211
212         default:
213             return false;
214     }*/
215 }
216 //---------------------------------------------------------------------------
217 void GTK2Window::SetTransparency( int Value )
218 {
219 /*    if( Value > -1 )
220         Alpha = Value;
221     SetLayeredWindowAttributes( hWnd, 0, Alpha, LWA_ALPHA | LWA_COLORKEY );
222     UpdateWindow( hWnd );*/
223 }
224 //---------------------------------------------------------------------------
225 void GTK2Window::RefreshFromImage( int x, int y, int w, int h )
226 {
227     // Initialize painting
228 /*    HDC DC = GetWindowDC( hWnd );
229
230     // Draw image on window
231     BitBlt( DC, x, y, w, h, ( (GTK2Graphics *)Image )->GetImageHandle(),
232             x, y, SRCCOPY );
233
234     // Release window device context
235     ReleaseDC( hWnd, DC );
236 */
237 }
238 //---------------------------------------------------------------------------
239 void GTK2Window::WindowManualMove()
240 {
241 /*    // Get mouse cursor position
242     LPPOINT NewPos = new POINT;
243     GetCursorPos( NewPos );
244
245     // Move window and chek for magnetism
246     p_intf->p_sys->p_theme->MoveSkinMagnet( this,
247         WindowPos->x + NewPos->x - CursorPos->x,
248         WindowPos->y + NewPos->y - CursorPos->y );
249
250     // Free memory
251     delete[] NewPos;
252 */
253 }
254 //---------------------------------------------------------------------------
255 void GTK2Window::WindowManualMoveInit()
256 {
257 /*    GetCursorPos( CursorPos );
258     WindowPos->x = Left;
259     WindowPos->y = Top;*/
260 }
261 //---------------------------------------------------------------------------
262 void GTK2Window::Move( int left, int top )
263 {
264 /*    Left = left;
265     Top  = top;
266     //SetWindowPos( hWnd, HWND_TOP, Left, Top, Width, Height,
267     //              SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER );
268     MoveWindow( hWnd, Left, Top, Width, Height, false );*/
269 }
270 //---------------------------------------------------------------------------
271 void GTK2Window::Size( int width, int height )
272 {
273 /*    Width  = width;
274     Height = height;
275     SetWindowPos( hWnd, HWND_TOP, Left, Top, Width, Height,
276                   SWP_NOMOVE|SWP_NOREDRAW|SWP_NOZORDER );*/
277 }
278 //---------------------------------------------------------------------------
279 void GTK2Window::ChangeToolTipText( string text )
280 {
281 /*    if( text == "none" )
282     {
283         if( ToolTipText != "none" )
284         {
285             ToolTipText = "none";
286             ToolTipInfo.lpszText = NULL;
287             SendMessage( ToolTipWindow, TTM_ACTIVATE, 0 , 0 );
288         }
289     }
290     else
291     {
292         if( text != ToolTipText )
293         {
294             ToolTipText = text;
295             ToolTipInfo.lpszText = (char *)ToolTipText.c_str();
296             SendMessage( ToolTipWindow, TTM_ACTIVATE, 1 , 0 );
297             SendMessage( ToolTipWindow, TTM_UPDATETIPTEXT, 0,
298                              (LPARAM)(LPTOOLINFO)&ToolTipInfo );
299         }
300     }
301 */
302 }
303 //---------------------------------------------------------------------------
304