1 /*****************************************************************************
2 * win32_window.cpp: Win32 implementation of the Window class
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: win32_window.cpp,v 1.4 2003/04/12 21:43:27 asmax Exp $
7 * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8 * Emmanuel Puig <karibu@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111,
24 *****************************************************************************/
28 //--- GENERAL ---------------------------------------------------------------
31 //--- VLC -------------------------------------------------------------------
34 //--- WIN32 -----------------------------------------------------------------
37 //--- SKIN ------------------------------------------------------------------
42 #include "os_window.h"
46 #include "os_graphics.h"
47 #include "skin_common.h"
52 //---------------------------------------------------------------------------
54 //---------------------------------------------------------------------------
55 #define LWA_COLORKEY 0x00000001
56 #define LWA_ALPHA 0x00000002
57 typedef BOOL (WINAPI *SLWA)(HWND, COLORREF, BYTE, DWORD);
58 HMODULE hModule = LoadLibrary( "user32.dll" );
59 SLWA SetLayeredWindowAttributes =
60 (SLWA)GetProcAddress( hModule, "SetLayeredWindowAttributes" );
63 //---------------------------------------------------------------------------
65 //---------------------------------------------------------------------------
66 Win32Window::Win32Window( intf_thread_t *p_intf, HWND hwnd, int x, int y,
67 bool visible, int transition, int normalalpha, int movealpha,
69 : Window( p_intf, x, y, visible, transition, normalalpha, movealpha,
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 Win32DropObject();
104 // register the listview as a drop target
105 RegisterDragDrop( hWnd, DropTarget );
109 //---------------------------------------------------------------------------
110 Win32Window::~Win32Window()
117 DestroyWindow( hWnd );
119 if( ToolTipWindow != NULL )
121 DestroyWindow( ToolTipWindow );
125 // Remove the listview from the list of drop targets
126 RevokeDragDrop( hWnd );
127 DropTarget->Release();
128 // Uninitialize the OLE library
133 //---------------------------------------------------------------------------
134 void Win32Window::OSShow( bool show )
138 ShowWindow( hWnd, SW_SHOW );
142 ShowWindow( hWnd, SW_HIDE );
145 //---------------------------------------------------------------------------
146 bool Win32Window::ProcessOSEvent( Event *evt )
148 unsigned int msg = evt->GetMessage();
149 unsigned int p1 = evt->GetParam1();
150 int p2 = evt->GetParam2();
157 DC = BeginPaint( hWnd , &Infos );
158 EndPaint( hWnd , &Infos );
159 RefreshFromImage( 0, 0, Width, Height );
163 TRACKMOUSEEVENT TrackEvent;
164 TrackEvent.cbSize = sizeof( TRACKMOUSEEVENT );
\r
165 TrackEvent.dwFlags = TME_LEAVE;
\r
166 TrackEvent.hwndTrack = hWnd;
\r
167 TrackEvent.dwHoverTime = 1;
168 TrackMouseEvent( &TrackEvent );
169 if( p1 == MK_LBUTTON )
170 MouseMove( LOWORD( p2 ), HIWORD( p2 ), 1 );
171 else if( p1 == MK_RBUTTON )
172 MouseMove( LOWORD( p2 ), HIWORD( p2 ), 2 );
174 MouseMove( LOWORD( p2 ), HIWORD( p2 ), 0 );
180 MouseDown( LOWORD( p2 ), HIWORD( p2 ), 1 );
185 MouseUp( LOWORD( p2 ), HIWORD( p2 ), 1 );
189 MouseDown( LOWORD( p2 ), HIWORD( p2 ), 2 );
193 MouseUp( LOWORD( p2 ), HIWORD( p2 ), 2 );
196 case WM_LBUTTONDBLCLK:
197 MouseDblClick( LOWORD( p2 ), HIWORD( p2 ), 1 );
201 OSAPI_PostMessage( this, WINDOW_LEAVE, 0, 0 );
208 //---------------------------------------------------------------------------
209 void Win32Window::SetTransparency( int Value )
213 SetLayeredWindowAttributes( hWnd, 0, Alpha, LWA_ALPHA | LWA_COLORKEY );
214 UpdateWindow( hWnd );
216 //---------------------------------------------------------------------------
217 void Win32Window::RefreshFromImage( int x, int y, int w, int h )
219 // Initialize painting
220 HDC DC = GetWindowDC( hWnd );
222 // Draw image on window
223 BitBlt( DC, x, y, w, h, ( (Win32Graphics *)Image )->GetImageHandle(),
226 // Release window device context
227 ReleaseDC( hWnd, DC );
230 //---------------------------------------------------------------------------
231 void Win32Window::WindowManualMove()
233 // Get mouse cursor position
234 LPPOINT NewPos = new POINT;
235 GetCursorPos( NewPos );
237 // Move window and chek for magnetism
238 p_intf->p_sys->p_theme->MoveSkinMagnet( this,
239 WindowPos->x + NewPos->x - CursorPos->x,
240 WindowPos->y + NewPos->y - CursorPos->y );
246 //---------------------------------------------------------------------------
247 void Win32Window::WindowManualMoveInit()
249 GetCursorPos( CursorPos );
253 //---------------------------------------------------------------------------
254 void Win32Window::Move( int left, int top )
258 //SetWindowPos( hWnd, HWND_TOP, Left, Top, Width, Height,
259 // SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER );
260 MoveWindow( hWnd, Left, Top, Width, Height, false );
262 //---------------------------------------------------------------------------
263 void Win32Window::Size( int width, int height )
267 SetWindowPos( hWnd, HWND_TOP, Left, Top, Width, Height,
268 SWP_NOMOVE|SWP_NOREDRAW|SWP_NOZORDER );
270 //---------------------------------------------------------------------------
271 void Win32Window::ChangeToolTipText( string text )
275 if( ToolTipText != "none" )
277 ToolTipText = "none";
278 ToolTipInfo.lpszText = NULL;
279 SendMessage( ToolTipWindow, TTM_ACTIVATE, 0 , 0 );
284 if( text != ToolTipText )
287 ToolTipInfo.lpszText = (char *)ToolTipText.c_str();
288 SendMessage( ToolTipWindow, TTM_ACTIVATE, 1 , 0 );
289 SendMessage( ToolTipWindow, TTM_UPDATETIPTEXT, 0,
290 (LPARAM)(LPTOOLINFO)&ToolTipInfo );
295 //---------------------------------------------------------------------------