1 /*****************************************************************************
2 * gtk2_window.cpp: GTK2 implementation of the Window class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: gtk2_window.cpp,v 1.6 2003/04/14 17:03:42 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,
74 // Set position parameters
75 CursorPos = new POINT;
76 WindowPos = new POINT;
78 // Create Tool Tip Window
79 ToolTipWindow = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
80 WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
81 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
82 hWnd, 0, GetModuleHandle( NULL ), 0);
84 // Create Tool Tip infos
85 ToolTipInfo.cbSize = sizeof(TOOLINFO);
86 ToolTipInfo.uFlags = TTF_SUBCLASS|TTF_IDISHWND;
87 ToolTipInfo.hwnd = hWnd;
88 ToolTipInfo.hinst = GetModuleHandle( NULL );
89 ToolTipInfo.uId = (unsigned int)hWnd;
90 ToolTipInfo.lpszText = NULL;
91 ToolTipInfo.rect.left = ToolTipInfo.rect.top = 0;
92 ToolTipInfo.rect.right = ToolTipInfo.rect.bottom = 0;
94 SendMessage( ToolTipWindow, TTM_ADDTOOL, 0,
95 (LPARAM)(LPTOOLINFO) &ToolTipInfo );
100 // Initialize the OLE library
101 OleInitialize( NULL );
102 DropTarget = (LPDROPTARGET) new GTK2DropObject();
103 // register the listview as a drop target
104 RegisterDragDrop( hWnd, DropTarget );
107 // Create Tool Tip window
108 /* GdkWindowAttr attr;
109 attr.event_mask = GDK_ALL_EVENTS_MASK;
112 attr.window_type = GDK_WINDOW_CHILD;
113 attr.wclass = GDK_INPUT_OUTPUT;
115 ToolTipWindow = gdk_window_new( gwnd, &attr, mask);*/
118 //---------------------------------------------------------------------------
119 GTK2Window::~GTK2Window()
126 DestroyWindow( hWnd );
128 if( ToolTipWindow != NULL )
130 DestroyWindow( ToolTipWindow );
134 // Remove the listview from the list of drop targets
135 RevokeDragDrop( hWnd );
136 DropTarget->Release();
137 // Uninitialize the OLE library
142 //---------------------------------------------------------------------------
143 void GTK2Window::OSShow( bool show )
147 gdk_window_show( gWnd );
151 gdk_window_hide( gWnd );
154 //---------------------------------------------------------------------------
155 bool GTK2Window::ProcessOSEvent( Event *evt )
157 /* unsigned int msg = evt->GetMessage();
158 unsigned int p1 = evt->GetParam1();
159 int p2 = evt->GetParam2();
166 DC = BeginPaint( hWnd , &Infos );
167 EndPaint( hWnd , &Infos );
168 RefreshFromImage( 0, 0, Width, Height );
172 TRACKMOUSEEVENT TrackEvent;
173 TrackEvent.cbSize = sizeof( TRACKMOUSEEVENT );
\r
174 TrackEvent.dwFlags = TME_LEAVE;
\r
175 TrackEvent.hwndTrack = hWnd;
\r
176 TrackEvent.dwHoverTime = 1;
177 TrackMouseEvent( &TrackEvent );
178 if( p1 == MK_LBUTTON )
179 MouseMove( LOWORD( p2 ), HIWORD( p2 ), 1 );
180 else if( p1 == MK_RBUTTON )
181 MouseMove( LOWORD( p2 ), HIWORD( p2 ), 2 );
183 MouseMove( LOWORD( p2 ), HIWORD( p2 ), 0 );
189 MouseDown( LOWORD( p2 ), HIWORD( p2 ), 1 );
194 MouseUp( LOWORD( p2 ), HIWORD( p2 ), 1 );
198 MouseDown( LOWORD( p2 ), HIWORD( p2 ), 2 );
202 MouseUp( LOWORD( p2 ), HIWORD( p2 ), 2 );
205 case WM_LBUTTONDBLCLK:
206 MouseDblClick( LOWORD( p2 ), HIWORD( p2 ), 1 );
210 OSAPI_PostMessage( this, WINDOW_LEAVE, 0, 0 );
217 //---------------------------------------------------------------------------
218 void GTK2Window::SetTransparency( int Value )
222 SetLayeredWindowAttributes( hWnd, 0, Alpha, LWA_ALPHA | LWA_COLORKEY );
223 UpdateWindow( hWnd );*/
225 //---------------------------------------------------------------------------
226 void GTK2Window::RefreshFromImage( int x, int y, int w, int h )
228 // Initialize painting
229 /* HDC DC = GetWindowDC( hWnd );
231 // Draw image on window
232 BitBlt( DC, x, y, w, h, ( (GTK2Graphics *)Image )->GetImageHandle(),
235 // Release window device context
236 ReleaseDC( hWnd, DC );
239 //---------------------------------------------------------------------------
240 void GTK2Window::WindowManualMove()
242 /* // Get mouse cursor position
243 LPPOINT NewPos = new POINT;
244 GetCursorPos( NewPos );
246 // Move window and chek for magnetism
247 p_intf->p_sys->p_theme->MoveSkinMagnet( this,
248 WindowPos->x + NewPos->x - CursorPos->x,
249 WindowPos->y + NewPos->y - CursorPos->y );
255 //---------------------------------------------------------------------------
256 void GTK2Window::WindowManualMoveInit()
258 /* GetCursorPos( CursorPos );
260 WindowPos->y = Top;*/
262 //---------------------------------------------------------------------------
263 void GTK2Window::Move( int left, int top )
267 //SetWindowPos( hWnd, HWND_TOP, Left, Top, Width, Height,
268 // SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER );
269 MoveWindow( hWnd, Left, Top, Width, Height, false );*/
271 //---------------------------------------------------------------------------
272 void GTK2Window::Size( int width, int height )
274 fprintf(stderr, "size %d %d\n", width, height);
277 gdk_window_resize( gWnd, width, height );
279 //---------------------------------------------------------------------------
280 void GTK2Window::ChangeToolTipText( string text )
282 /* if( text == "none" )
284 if( ToolTipText != "none" )
286 ToolTipText = "none";
287 ToolTipInfo.lpszText = NULL;
288 SendMessage( ToolTipWindow, TTM_ACTIVATE, 0 , 0 );
293 if( text != ToolTipText )
296 ToolTipInfo.lpszText = (char *)ToolTipText.c_str();
297 SendMessage( ToolTipWindow, TTM_ACTIVATE, 1 , 0 );
298 SendMessage( ToolTipWindow, TTM_UPDATETIPTEXT, 0,
299 (LPARAM)(LPTOOLINFO)&ToolTipInfo );
304 //---------------------------------------------------------------------------