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 $
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 *****************************************************************************/
26 //--- GENERAL ---------------------------------------------------------------
29 //--- VLC -------------------------------------------------------------------
32 //--- GTK2 ------------------------------------------------------------------
35 //--- SKIN ------------------------------------------------------------------
40 #include "os_window.h"
44 #include "os_graphics.h"
45 #include "skin_common.h"
50 //---------------------------------------------------------------------------
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" );
61 //---------------------------------------------------------------------------
63 //---------------------------------------------------------------------------
64 GTK2Window::GTK2Window( intf_thread_t *p_intf, GdkWindow *gwnd, int x, int y,
65 bool visible, int transition, int normalalpha, int movealpha,
67 : Window( p_intf, x, y, visible, transition, normalalpha, movealpha,
73 // Set position parameters
74 CursorPos = new POINT;
75 WindowPos = new POINT;
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);
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;
93 SendMessage( ToolTipWindow, TTM_ADDTOOL, 0,
94 (LPARAM)(LPTOOLINFO) &ToolTipInfo );
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 );
106 // Create Tool Tip window
107 /* GdkWindowAttr attr;
108 attr.event_mask = GDK_ALL_EVENTS_MASK;
111 attr.window_type = GDK_WINDOW_CHILD;
112 attr.wclass = GDK_INPUT_OUTPUT;
114 ToolTipWindow = gdk_window_new( gwnd, &attr, mask);*/
117 //---------------------------------------------------------------------------
118 GTK2Window::~GTK2Window()
125 DestroyWindow( hWnd );
127 if( ToolTipWindow != NULL )
129 DestroyWindow( ToolTipWindow );
133 // Remove the listview from the list of drop targets
134 RevokeDragDrop( hWnd );
135 DropTarget->Release();
136 // Uninitialize the OLE library
141 //---------------------------------------------------------------------------
142 void GTK2Window::OSShow( bool show )
146 gdk_window_show( gWnd );
150 gdk_window_hide( gWnd );
153 //---------------------------------------------------------------------------
154 bool GTK2Window::ProcessOSEvent( Event *evt )
156 /* unsigned int msg = evt->GetMessage();
157 unsigned int p1 = evt->GetParam1();
158 int p2 = evt->GetParam2();
165 DC = BeginPaint( hWnd , &Infos );
166 EndPaint( hWnd , &Infos );
167 RefreshFromImage( 0, 0, Width, Height );
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 );
182 MouseMove( LOWORD( p2 ), HIWORD( p2 ), 0 );
188 MouseDown( LOWORD( p2 ), HIWORD( p2 ), 1 );
193 MouseUp( LOWORD( p2 ), HIWORD( p2 ), 1 );
197 MouseDown( LOWORD( p2 ), HIWORD( p2 ), 2 );
201 MouseUp( LOWORD( p2 ), HIWORD( p2 ), 2 );
204 case WM_LBUTTONDBLCLK:
205 MouseDblClick( LOWORD( p2 ), HIWORD( p2 ), 1 );
209 OSAPI_PostMessage( this, WINDOW_LEAVE, 0, 0 );
216 //---------------------------------------------------------------------------
217 void GTK2Window::SetTransparency( int Value )
221 SetLayeredWindowAttributes( hWnd, 0, Alpha, LWA_ALPHA | LWA_COLORKEY );
222 UpdateWindow( hWnd );*/
224 //---------------------------------------------------------------------------
225 void GTK2Window::RefreshFromImage( int x, int y, int w, int h )
227 // Initialize painting
228 /* HDC DC = GetWindowDC( hWnd );
230 // Draw image on window
231 BitBlt( DC, x, y, w, h, ( (GTK2Graphics *)Image )->GetImageHandle(),
234 // Release window device context
235 ReleaseDC( hWnd, DC );
238 //---------------------------------------------------------------------------
239 void GTK2Window::WindowManualMove()
241 /* // Get mouse cursor position
242 LPPOINT NewPos = new POINT;
243 GetCursorPos( NewPos );
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 );
254 //---------------------------------------------------------------------------
255 void GTK2Window::WindowManualMoveInit()
257 /* GetCursorPos( CursorPos );
259 WindowPos->y = Top;*/
261 //---------------------------------------------------------------------------
262 void GTK2Window::Move( int left, int 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 );*/
270 //---------------------------------------------------------------------------
271 void GTK2Window::Size( int width, int height )
275 SetWindowPos( hWnd, HWND_TOP, Left, Top, Width, Height,
276 SWP_NOMOVE|SWP_NOREDRAW|SWP_NOZORDER );*/
278 //---------------------------------------------------------------------------
279 void GTK2Window::ChangeToolTipText( string text )
281 /* if( text == "none" )
283 if( ToolTipText != "none" )
285 ToolTipText = "none";
286 ToolTipInfo.lpszText = NULL;
287 SendMessage( ToolTipWindow, TTM_ACTIVATE, 0 , 0 );
292 if( text != ToolTipText )
295 ToolTipInfo.lpszText = (char *)ToolTipText.c_str();
296 SendMessage( ToolTipWindow, TTM_ACTIVATE, 1 , 0 );
297 SendMessage( ToolTipWindow, TTM_UPDATETIPTEXT, 0,
298 (LPARAM)(LPTOOLINFO)&ToolTipInfo );
303 //---------------------------------------------------------------------------