1 /*****************************************************************************
2 * gtk2_window.cpp: GTK2 implementation of the Window class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: gtk2_window.cpp,v 1.10 2003/04/15 11:46:19 ipkiss Exp $
7 * Authors: Cyril Deguet <asmax@videolan.org>
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.
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.
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,
23 *****************************************************************************/
27 //--- GENERAL ---------------------------------------------------------------
30 //--- VLC -------------------------------------------------------------------
33 //--- GTK2 ------------------------------------------------------------------
37 //--- SKIN ------------------------------------------------------------------
42 #include "os_window.h"
46 #include "os_graphics.h"
47 #include "skin_common.h"
51 //---------------------------------------------------------------------------
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" );
62 //---------------------------------------------------------------------------
64 //---------------------------------------------------------------------------
65 GTK2Window::GTK2Window( intf_thread_t *p_intf, GdkWindow *gwnd, int x, int y,
66 bool visible, int transition, int normalalpha, int movealpha,
68 : Window( p_intf, x, y, visible, transition, normalalpha, movealpha,
73 gc = gdk_gc_new( gwnd );
78 // Set position parameters
79 CursorPos = new POINT;
80 WindowPos = new POINT;
82 // Create Tool Tip Window
83 ToolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
84 WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
85 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
86 hWnd, 0, GetModuleHandle( NULL ), 0);
88 // Create Tool Tip infos
89 ToolTipInfo.cbSize = sizeof(TOOLINFO);
90 ToolTipInfo.uFlags = TTF_SUBCLASS|TTF_IDISHWND;
91 ToolTipInfo.hwnd = hWnd;
92 ToolTipInfo.hinst = GetModuleHandle( NULL );
93 ToolTipInfo.uId = (unsigned int)hWnd;
94 ToolTipInfo.lpszText = NULL;
95 ToolTipInfo.rect.left = ToolTipInfo.rect.top = 0;
96 ToolTipInfo.rect.right = ToolTipInfo.rect.bottom = 0;
98 SendMessage( ToolTipWindow, TTM_ADDTOOL, 0,
99 (LPARAM)(LPTOOLINFO) &ToolTipInfo );
104 // Initialize the OLE library
105 OleInitialize( NULL );
106 DropTarget = (LPDROPTARGET) new GTK2DropObject();
107 // register the listview as a drop target
108 RegisterDragDrop( hWnd, DropTarget );
111 // Create Tool Tip window
112 /* GdkWindowAttr attr;
113 attr.event_mask = GDK_ALL_EVENTS_MASK;
116 attr.window_type = GDK_WINDOW_CHILD;
117 attr.wclass = GDK_INPUT_OUTPUT;
119 ToolTipWindow = gdk_window_new( gwnd, &attr, mask);*/
122 //---------------------------------------------------------------------------
123 GTK2Window::~GTK2Window()
130 DestroyWindow( hWnd );
132 if( ToolTipWindow != NULL )
134 DestroyWindow( ToolTipWindow );
138 // Remove the listview from the list of drop targets
139 RevokeDragDrop( hWnd );
140 DropTarget->Release();
141 // Uninitialize the OLE library
146 //---------------------------------------------------------------------------
147 void GTK2Window::OSShow( bool show )
151 gdk_window_show( gWnd );
155 gdk_window_hide( gWnd );
158 //---------------------------------------------------------------------------
159 bool GTK2Window::ProcessOSEvent( Event *evt )
161 unsigned int msg = evt->GetMessage();
162 unsigned int p1 = evt->GetParam1();
163 int p2 = evt->GetParam2();
165 fprintf( stderr, "salut %li\n", evt->GetMessage() );
170 RefreshFromImage( 0, 0, Width, Height );
174 case GDK_MOTION_NOTIFY:
175 // TRACKMOUSEEVENT TrackEvent;
176 // TrackEvent.cbSize = sizeof( TRACKMOUSEEVENT );
177 // TrackEvent.dwFlags = TME_LEAVE;
178 // TrackEvent.hwndTrack = hWnd;
179 // TrackEvent.dwHoverTime = 1;
180 // TrackMouseEvent( &TrackEvent );
182 MouseMove( ((GdkEventButton *)p2)->x_root, ((GdkEventButton *)p2)->y_root,
184 else if( RButtonDown )
185 MouseMove( ((GdkEventButton *)p2)->x_root, ((GdkEventButton *)p2)->y_root,
188 MouseMove( ((GdkEventButton *)p2)->x_root, ((GdkEventButton *)p2)->y_root,
194 case GDK_BUTTON_PRESS:
195 switch( ((GdkEventButton *)p2)->button )
200 MouseDown( ((GdkEventButton *)p2)->x_root,
201 ((GdkEventButton *)p2)->y_root, 1 );
206 MouseDown( ((GdkEventButton *)p2)->x_root,
207 ((GdkEventButton *)p2)->y_root, 2 );
214 case GDK_BUTTON_RELEASE:
215 switch( ((GdkEventButton *)p2)->button )
220 MouseUp( ((GdkEventButton *)p2)->x_root,
221 ((GdkEventButton *)p2)->y_root, 1 );
226 MouseUp( ((GdkEventButton *)p2)->x_root,
227 ((GdkEventButton *)p2)->y_root, 2 );
236 MouseDown( LOWORD( p2 ), HIWORD( p2 ), 2 );
240 MouseUp( LOWORD( p2 ), HIWORD( p2 ), 2 );
243 case WM_LBUTTONDBLCLK:
244 MouseDblClick( LOWORD( p2 ), HIWORD( p2 ), 1 );
248 OSAPI_PostMessage( this, WINDOW_LEAVE, 0, 0 );
255 //---------------------------------------------------------------------------
256 void GTK2Window::SetTransparency( int Value )
260 SetLayeredWindowAttributes( hWnd, 0, Alpha, LWA_ALPHA | LWA_COLORKEY );
261 UpdateWindow( hWnd );*/
263 //---------------------------------------------------------------------------
264 void GTK2Window::RefreshFromImage( int x, int y, int w, int h )
266 // Initialize painting
267 /* HDC DC = GetWindowDC( hWnd );
269 // Draw image on window
270 BitBlt( DC, x, y, w, h, ( (GTK2Graphics *)Image )->GetImageHandle(),
273 // Release window device context
274 ReleaseDC( hWnd, DC );
278 fprintf(stderr, "window %d %d %d %d\n", x, y, w, h);
279 gdk_draw_drawable( gWnd, gc, (( GTK2Graphics* )Image )->GetImage(),
282 //---------------------------------------------------------------------------
283 void GTK2Window::WindowManualMove()
285 // Get mouse cursor position
287 gdk_window_get_pointer( gdk_get_default_root_window(), &x, &y, NULL );
289 // Move window and chek for magnetism
290 p_intf->p_sys->p_theme->MoveSkinMagnet( this,
291 WindowX + x - CursorX, WindowY + y - CursorY );
293 fprintf( stderr, "---------\n" );
295 //---------------------------------------------------------------------------
296 void GTK2Window::WindowManualMoveInit()
298 gdk_window_get_pointer( gdk_get_default_root_window(), &CursorX, &CursorY,
303 //---------------------------------------------------------------------------
304 void GTK2Window::Move( int left, int top )
308 gdk_window_move( gWnd, left, top );
310 //---------------------------------------------------------------------------
311 void GTK2Window::Size( int width, int height )
315 gdk_window_resize( gWnd, width, height );
317 //---------------------------------------------------------------------------
318 void GTK2Window::ChangeToolTipText( string text )
320 /* if( text == "none" )
322 if( ToolTipText != "none" )
324 ToolTipText = "none";
325 ToolTipInfo.lpszText = NULL;
326 SendMessage( ToolTipWindow, TTM_ACTIVATE, 0 , 0 );
331 if( text != ToolTipText )
334 ToolTipInfo.lpszText = (char *)ToolTipText.c_str();
335 SendMessage( ToolTipWindow, TTM_ACTIVATE, 1 , 0 );
336 SendMessage( ToolTipWindow, TTM_UPDATETIPTEXT, 0,
337 (LPARAM)(LPTOOLINFO)&ToolTipInfo );
342 //---------------------------------------------------------------------------