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 $
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 ------------------------------------------------------------------
36 //--- SKIN ------------------------------------------------------------------
41 #include "os_window.h"
45 #include "os_graphics.h"
46 #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 );
75 // Set position parameters
76 CursorPos = new POINT;
77 WindowPos = new POINT;
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);
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;
95 SendMessage( ToolTipWindow, TTM_ADDTOOL, 0,
96 (LPARAM)(LPTOOLINFO) &ToolTipInfo );
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 );
108 // Create Tool Tip window
109 /* GdkWindowAttr attr;
110 attr.event_mask = GDK_ALL_EVENTS_MASK;
113 attr.window_type = GDK_WINDOW_CHILD;
114 attr.wclass = GDK_INPUT_OUTPUT;
116 ToolTipWindow = gdk_window_new( gwnd, &attr, mask);*/
119 //---------------------------------------------------------------------------
120 GTK2Window::~GTK2Window()
127 DestroyWindow( hWnd );
129 if( ToolTipWindow != NULL )
131 DestroyWindow( ToolTipWindow );
135 // Remove the listview from the list of drop targets
136 RevokeDragDrop( hWnd );
137 DropTarget->Release();
138 // Uninitialize the OLE library
143 //---------------------------------------------------------------------------
144 void GTK2Window::OSShow( bool show )
148 gdk_window_show( gWnd );
152 gdk_window_hide( gWnd );
155 //---------------------------------------------------------------------------
156 bool GTK2Window::ProcessOSEvent( Event *evt )
158 /* unsigned int msg = evt->GetMessage();
159 unsigned int p1 = evt->GetParam1();
160 int p2 = evt->GetParam2();
167 DC = BeginPaint( hWnd , &Infos );
168 EndPaint( hWnd , &Infos );
169 RefreshFromImage( 0, 0, Width, Height );
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 );
184 MouseMove( LOWORD( p2 ), HIWORD( p2 ), 0 );
190 MouseDown( LOWORD( p2 ), HIWORD( p2 ), 1 );
195 MouseUp( LOWORD( p2 ), HIWORD( p2 ), 1 );
199 MouseDown( LOWORD( p2 ), HIWORD( p2 ), 2 );
203 MouseUp( LOWORD( p2 ), HIWORD( p2 ), 2 );
206 case WM_LBUTTONDBLCLK:
207 MouseDblClick( LOWORD( p2 ), HIWORD( p2 ), 1 );
211 OSAPI_PostMessage( this, WINDOW_LEAVE, 0, 0 );
218 //---------------------------------------------------------------------------
219 void GTK2Window::SetTransparency( int Value )
223 SetLayeredWindowAttributes( hWnd, 0, Alpha, LWA_ALPHA | LWA_COLORKEY );
224 UpdateWindow( hWnd );*/
226 //---------------------------------------------------------------------------
227 void GTK2Window::RefreshFromImage( int x, int y, int w, int h )
229 // Initialize painting
230 /* HDC DC = GetWindowDC( hWnd );
232 // Draw image on window
233 BitBlt( DC, x, y, w, h, ( (GTK2Graphics *)Image )->GetImageHandle(),
236 // Release window device context
237 ReleaseDC( hWnd, DC );
241 fprintf(stderr, "window %d %d %d %d\n", x, y, w, h);
242 gdk_draw_drawable( gWnd, gc, (( GTK2Graphics* )Image )->GetImage(),
245 //---------------------------------------------------------------------------
246 void GTK2Window::WindowManualMove()
248 /* // Get mouse cursor position
249 LPPOINT NewPos = new POINT;
250 GetCursorPos( NewPos );
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 );
261 //---------------------------------------------------------------------------
262 void GTK2Window::WindowManualMoveInit()
264 /* GetCursorPos( CursorPos );
266 WindowPos->y = Top;*/
268 //---------------------------------------------------------------------------
269 void GTK2Window::Move( int left, int top )
273 gdk_window_move( gWnd, left, top );
275 //---------------------------------------------------------------------------
276 void GTK2Window::Size( int width, int height )
280 gdk_window_resize( gWnd, width, height );
282 //---------------------------------------------------------------------------
283 void GTK2Window::ChangeToolTipText( string text )
285 /* if( text == "none" )
287 if( ToolTipText != "none" )
289 ToolTipText = "none";
290 ToolTipInfo.lpszText = NULL;
291 SendMessage( ToolTipWindow, TTM_ACTIVATE, 0 , 0 );
296 if( text != ToolTipText )
299 ToolTipInfo.lpszText = (char *)ToolTipText.c_str();
300 SendMessage( ToolTipWindow, TTM_ACTIVATE, 1 , 0 );
301 SendMessage( ToolTipWindow, TTM_UPDATETIPTEXT, 0,
302 (LPARAM)(LPTOOLINFO)&ToolTipInfo );
307 //---------------------------------------------------------------------------