]> git.sesse.net Git - vlc/blob - modules/gui/skins/gtk2/gtk2_window.cpp
* it works event better !!
[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.8 2003/04/14 20:17:33 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 #if !defined WIN32
26
27 //--- GENERAL ---------------------------------------------------------------
28 //#include <math.h>
29
30 //--- VLC -------------------------------------------------------------------
31 #include <vlc/intf.h>
32
33 //--- GTK2 ------------------------------------------------------------------
34 #include <gdk/gdk.h>
35
36 //--- SKIN ------------------------------------------------------------------
37 #include "os_api.h"
38 #include "anchor.h"
39 #include "generic.h"
40 #include "window.h"
41 #include "os_window.h"
42 #include "event.h"
43 #include "os_event.h"
44 #include "graphics.h"
45 #include "os_graphics.h"
46 #include "skin_common.h"
47 #include "theme.h"
48
49
50
51 //---------------------------------------------------------------------------
52 // Fading API
53 //---------------------------------------------------------------------------
54 /*#define LWA_COLORKEY  0x00000001
55 #define LWA_ALPHA     0x00000002
56 typedef BOOL (WINAPI *SLWA)(HWND, COLORREF, BYTE, DWORD);
57 HMODULE hModule = LoadLibrary( "user32.dll" );
58 SLWA SetLayeredWindowAttributes =
59     (SLWA)GetProcAddress( hModule, "SetLayeredWindowAttributes" );
60 */
61
62 //---------------------------------------------------------------------------
63 // Skinable Window
64 //---------------------------------------------------------------------------
65 GTK2Window::GTK2Window( intf_thread_t *p_intf, GdkWindow *gwnd, int x, int y,
66     bool visible, int transition, int normalalpha, int movealpha,
67     bool dragdrop )
68     : Window( p_intf, x, y, visible, transition, normalalpha, movealpha,
69               dragdrop )
70 {
71     // Set handles
72     gWnd           = gwnd;
73     gc = gdk_gc_new( gwnd );
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 GTK2DropObject();
104         // register the listview as a drop target
105         RegisterDragDrop( hWnd, DropTarget );
106     }
107 */
108     // Create Tool Tip window
109 /*    GdkWindowAttr attr;
110     attr.event_mask = GDK_ALL_EVENTS_MASK;
111     attr.width = 100;
112     attr.height = 100;
113     attr.window_type = GDK_WINDOW_CHILD;
114     attr.wclass = GDK_INPUT_OUTPUT;
115     gint mask = 0;
116     ToolTipWindow = gdk_window_new( gwnd, &attr, mask);*/
117
118 }
119 //---------------------------------------------------------------------------
120 GTK2Window::~GTK2Window()
121 {
122 /*    delete CursorPos;
123     delete WindowPos;
124
125     if( hWnd != NULL )
126     {
127         DestroyWindow( hWnd );
128     }
129     if( ToolTipWindow != NULL )
130     {
131         DestroyWindow( ToolTipWindow );
132     }
133     if( DragDrop )
134     {
135         // Remove the listview from the list of drop targets
136         RevokeDragDrop( hWnd );
137         DropTarget->Release();
138         // Uninitialize the OLE library
139         OleUninitialize();
140     }
141 */
142 }
143 //---------------------------------------------------------------------------
144 void GTK2Window::OSShow( bool show )
145 {
146     if( show )
147     {
148         gdk_window_show( gWnd );
149     }
150     else
151     {
152         gdk_window_hide( gWnd );
153     }
154 }
155 //---------------------------------------------------------------------------
156 bool GTK2Window::ProcessOSEvent( Event *evt )
157 {
158 /*    unsigned int msg = evt->GetMessage();
159     unsigned int p1  = evt->GetParam1();
160     int          p2  = evt->GetParam2();
161
162     switch( msg )
163     {
164         case WM_PAINT:
165             HDC DC;
166             PAINTSTRUCT Infos;
167             DC = BeginPaint( hWnd , &Infos );
168             EndPaint( hWnd , &Infos );
169             RefreshFromImage( 0, 0, Width, Height );
170             return true;
171
172         case WM_MOUSEMOVE:
173             TRACKMOUSEEVENT TrackEvent;
174             TrackEvent.cbSize      = sizeof( TRACKMOUSEEVENT );\r
175             TrackEvent.dwFlags     = TME_LEAVE;\r
176             TrackEvent.hwndTrack   = hWnd;\r
177             TrackEvent.dwHoverTime = 1;
178             TrackMouseEvent( &TrackEvent );
179             if( p1 == MK_LBUTTON )
180                 MouseMove( LOWORD( p2 ), HIWORD( p2 ), 1 );
181             else if( p1 == MK_RBUTTON )
182                 MouseMove( LOWORD( p2 ), HIWORD( p2 ), 2 );
183             else
184                 MouseMove( LOWORD( p2 ), HIWORD( p2 ), 0 );
185
186             return true;
187
188         case WM_LBUTTONDOWN:
189             SetCapture( hWnd );
190             MouseDown( LOWORD( p2 ), HIWORD( p2 ), 1 );
191             return true;
192
193         case WM_LBUTTONUP:
194             ReleaseCapture();
195             MouseUp( LOWORD( p2 ), HIWORD( p2 ), 1 );
196             return true;
197
198         case WM_RBUTTONDOWN:
199             MouseDown( LOWORD( p2 ), HIWORD( p2 ), 2 );
200             return true;
201
202         case WM_RBUTTONUP:
203             MouseUp( LOWORD( p2 ), HIWORD( p2 ), 2 );
204             return true;
205
206         case WM_LBUTTONDBLCLK:
207             MouseDblClick( LOWORD( p2 ), HIWORD( p2 ), 1 );
208             return true;
209
210         case WM_MOUSELEAVE:
211             OSAPI_PostMessage( this, WINDOW_LEAVE, 0, 0 );
212             return true;
213
214         default:
215             return false;
216     }*/
217 }
218 //---------------------------------------------------------------------------
219 void GTK2Window::SetTransparency( int Value )
220 {
221 /*    if( Value > -1 )
222         Alpha = Value;
223     SetLayeredWindowAttributes( hWnd, 0, Alpha, LWA_ALPHA | LWA_COLORKEY );
224     UpdateWindow( hWnd );*/
225 }
226 //---------------------------------------------------------------------------
227 void GTK2Window::RefreshFromImage( int x, int y, int w, int h )
228 {
229     // Initialize painting
230 /*    HDC DC = GetWindowDC( hWnd );
231
232     // Draw image on window
233     BitBlt( DC, x, y, w, h, ( (GTK2Graphics *)Image )->GetImageHandle(),
234             x, y, SRCCOPY );
235
236     // Release window device context
237     ReleaseDC( hWnd, DC );
238     
239 */
240     
241  fprintf(stderr, "window %d %d %d %d\n", x, y, w, h);
242     gdk_draw_drawable( gWnd, gc, (( GTK2Graphics* )Image )->GetImage(),
243             x, y, x, y, w, h );
244 }
245 //---------------------------------------------------------------------------
246 void GTK2Window::WindowManualMove()
247 {
248 /*    // Get mouse cursor position
249     LPPOINT NewPos = new POINT;
250     GetCursorPos( NewPos );
251
252     // Move window and chek for magnetism
253     p_intf->p_sys->p_theme->MoveSkinMagnet( this,
254         WindowPos->x + NewPos->x - CursorPos->x,
255         WindowPos->y + NewPos->y - CursorPos->y );
256
257     // Free memory
258     delete[] NewPos;
259 */
260 }
261 //---------------------------------------------------------------------------
262 void GTK2Window::WindowManualMoveInit()
263 {
264 /*    GetCursorPos( CursorPos );
265     WindowPos->x = Left;
266     WindowPos->y = Top;*/
267 }
268 //---------------------------------------------------------------------------
269 void GTK2Window::Move( int left, int top )
270 {
271     Left = left;
272     Top  = top;
273     gdk_window_move( gWnd, left, top );
274 }
275 //---------------------------------------------------------------------------
276 void GTK2Window::Size( int width, int height )
277 {
278     Width  = width;
279     Height = height;
280     gdk_window_resize( gWnd, width, height );
281 }
282 //---------------------------------------------------------------------------
283 void GTK2Window::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