00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifdef WIN32_SKINS
00026
00027 #include "win32_factory.hpp"
00028 #include "win32_graphics.hpp"
00029 #include "win32_timer.hpp"
00030 #include "win32_window.hpp"
00031 #include "win32_tooltip.hpp"
00032 #include "win32_loop.hpp"
00033 #include "../src/theme.hpp"
00034
00035
00036 LRESULT CALLBACK Win32Proc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
00037 {
00038
00039 intf_thread_t *p_intf = (intf_thread_t *)GetWindowLongPtr( hwnd,
00040 GWLP_USERDATA );
00041
00042
00043 if( p_intf == NULL || p_intf->p_sys->p_osFactory == NULL )
00044 {
00045 return DefWindowProc( hwnd, uMsg, wParam, lParam );
00046 }
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 {
00058 if( uMsg == WM_SYSCOMMAND )
00059 {
00060
00061 if( wParam == SC_CLOSE )
00062 {
00063 Win32Loop *pLoop = (Win32Loop*)Win32Loop::instance( p_intf );
00064 pLoop->exit();
00065 return 0;
00066 }
00067 else
00068 {
00069 msg_Err( p_intf, "WM_SYSCOMMAND %i", wParam );
00070 }
00071
00072
00073
00074 }
00075 }
00076
00077
00078 return DefWindowProc( hwnd, uMsg, wParam, lParam );
00079 }
00080
00081
00082 Win32Factory::Win32Factory( intf_thread_t *pIntf ):
00083 OSFactory( pIntf ), TransparentBlt( NULL ), AlphaBlend( NULL ),
00084 SetLayeredWindowAttributes( NULL ), m_hParentWindow( NULL ),
00085 m_dirSep( "\\" )
00086 {
00087
00088 }
00089
00090
00091 bool Win32Factory::init()
00092 {
00093
00094 m_hInst = GetModuleHandle( NULL );
00095 if( m_hInst == NULL )
00096 {
00097 msg_Err( getIntf(), "Cannot get module handle" );
00098 }
00099
00100
00101 WNDCLASS skinWindowClass;
00102 skinWindowClass.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
00103 skinWindowClass.lpfnWndProc = (WNDPROC) Win32Proc;
00104 skinWindowClass.lpszClassName = _T("SkinWindowClass");
00105 skinWindowClass.lpszMenuName = NULL;
00106 skinWindowClass.cbClsExtra = 0;
00107 skinWindowClass.cbWndExtra = 0;
00108 skinWindowClass.hbrBackground = NULL;
00109 skinWindowClass.hCursor = LoadCursor( NULL , IDC_ARROW );
00110 skinWindowClass.hIcon = LoadIcon( m_hInst, _T("VLC_ICON") );
00111 skinWindowClass.hInstance = m_hInst;
00112
00113
00114 if( !RegisterClass( &skinWindowClass ) )
00115 {
00116 WNDCLASS wndclass;
00117
00118
00119
00120 if( !GetClassInfo( m_hInst, _T("SkinWindowClass"), &wndclass ) )
00121 {
00122 msg_Err( getIntf(), "Cannot register window class" );
00123 return false;
00124 }
00125 }
00126
00127
00128 m_hParentWindow = CreateWindowEx( WS_EX_APPWINDOW, _T("SkinWindowClass"),
00129 _T("VLC media player"), WS_SYSMENU|WS_POPUP,
00130 -200, -200, 0, 0, 0, 0, m_hInst, 0 );
00131 if( m_hParentWindow == NULL )
00132 {
00133 msg_Err( getIntf(), "Cannot create parent window" );
00134 return false;
00135 }
00136
00137
00138
00139 SetWindowLongPtr( m_hParentWindow, GWL_EXSTYLE,
00140 GetWindowLong( m_hParentWindow, GWL_EXSTYLE ) |
00141 WS_EX_LAYERED );
00142
00143
00144 SetWindowLongPtr( m_hParentWindow, GWLP_USERDATA, (LONG_PTR)getIntf() );
00145 ShowWindow( m_hParentWindow, SW_SHOW );
00146
00147
00148 OleInitialize( NULL );
00149
00150
00151 m_hMsimg32 = LoadLibrary( _T("msimg32.dll") );
00152 if( !m_hMsimg32 ||
00153 !( TransparentBlt =
00154 (BOOL (WINAPI*)(HDC, int, int, int, int,
00155 HDC, int, int, int, int, unsigned int))
00156 GetProcAddress( m_hMsimg32, _T("TransparentBlt") ) ) )
00157 {
00158 TransparentBlt = NULL;
00159 msg_Dbg( getIntf(), "Couldn't find TransparentBlt(), "
00160 "falling back to BitBlt()" );
00161 }
00162 if( !m_hMsimg32 ||
00163 !( AlphaBlend =
00164 (BOOL (WINAPI*)( HDC, int, int, int, int, HDC, int, int,
00165 int, int, BLENDFUNCTION ))
00166 GetProcAddress( m_hMsimg32, _T("AlphaBlend") ) ) )
00167 {
00168 AlphaBlend = NULL;
00169 msg_Dbg( getIntf(), "Couldn't find AlphaBlend()" );
00170 }
00171
00172
00173 m_hUser32 = LoadLibrary( _T("user32.dll") );
00174 if( !m_hUser32 ||
00175 !( SetLayeredWindowAttributes =
00176 (BOOL (WINAPI *)(HWND, COLORREF, BYTE, DWORD))
00177 GetProcAddress( m_hUser32, _T("SetLayeredWindowAttributes") ) ) )
00178 {
00179 SetLayeredWindowAttributes = NULL;
00180 msg_Dbg( getIntf(), "Couldn't find SetLayeredWindowAttributes()" );
00181 }
00182
00183
00184 m_resourcePath.push_back( (string)getIntf()->p_vlc->psz_homedir +
00185 "\\" + CONFIG_DIR + "\\skins" );
00186 m_resourcePath.push_back( (string)getIntf()->p_libvlc->psz_vlcpath +
00187 "\\skins" );
00188 m_resourcePath.push_back( (string)getIntf()->p_libvlc->psz_vlcpath +
00189 "\\skins2" );
00190 m_resourcePath.push_back( (string)getIntf()->p_libvlc->psz_vlcpath +
00191 "\\share\\skins" );
00192 m_resourcePath.push_back( (string)getIntf()->p_libvlc->psz_vlcpath +
00193 "\\share\\skins2" );
00194
00195
00196 return true;
00197 }
00198
00199
00200 Win32Factory::~Win32Factory()
00201 {
00202
00203 OleUninitialize();
00204
00205 if( m_hParentWindow ) DestroyWindow( m_hParentWindow );
00206
00207
00208 if( m_hMsimg32 )
00209 FreeLibrary( m_hMsimg32 );
00210 if( m_hUser32 )
00211 FreeLibrary( m_hUser32 );
00212 }
00213
00214
00215 OSGraphics *Win32Factory::createOSGraphics( int width, int height )
00216 {
00217 return new Win32Graphics( getIntf(), width, height );
00218 }
00219
00220
00221 OSLoop *Win32Factory::getOSLoop()
00222 {
00223 return Win32Loop::instance( getIntf() );
00224 }
00225
00226
00227 void Win32Factory::destroyOSLoop()
00228 {
00229 Win32Loop::destroy( getIntf() );
00230 }
00231
00232 void Win32Factory::minimize()
00233 {
00234
00235 getIntf()->p_sys->p_theme->getWindowManager().hideTooltip();
00236
00237 ShowWindow( m_hParentWindow, SW_MINIMIZE );
00238 }
00239
00240 OSTimer *Win32Factory::createOSTimer( CmdGeneric &rCmd )
00241 {
00242 return new Win32Timer( getIntf(), rCmd, m_hParentWindow );
00243 }
00244
00245
00246 OSWindow *Win32Factory::createOSWindow( GenericWindow &rWindow, bool dragDrop,
00247 bool playOnDrop, OSWindow *pParent )
00248 {
00249 return new Win32Window( getIntf(), rWindow, m_hInst, m_hParentWindow,
00250 dragDrop, playOnDrop, (Win32Window*)pParent );
00251 }
00252
00253
00254 OSTooltip *Win32Factory::createOSTooltip()
00255 {
00256 return new Win32Tooltip( getIntf(), m_hInst, m_hParentWindow );
00257 }
00258
00259
00260 int Win32Factory::getScreenWidth() const
00261 {
00262 return GetSystemMetrics(SM_CXSCREEN);
00263
00264 }
00265
00266
00267 int Win32Factory::getScreenHeight() const
00268 {
00269 return GetSystemMetrics(SM_CYSCREEN);
00270 }
00271
00272
00273 Rect Win32Factory::getWorkArea() const
00274 {
00275 RECT r;
00276 SystemParametersInfo( SPI_GETWORKAREA, 0, &r, 0 );
00277
00278 Rect rect( r.left, r.top, r.right, r.bottom );
00279 return rect;
00280 }
00281
00282
00283 void Win32Factory::getMousePos( int &rXPos, int &rYPos ) const
00284 {
00285 POINT mousePos;
00286 GetCursorPos( &mousePos );
00287 rXPos = mousePos.x;
00288 rYPos = mousePos.y;
00289 }
00290
00291
00292 void Win32Factory::changeCursor( CursorType_t type ) const
00293 {
00294 LPCTSTR id;
00295 switch( type )
00296 {
00297 case kDefaultArrow:
00298 id = IDC_ARROW;
00299 break;
00300 case kResizeNWSE:
00301 id = IDC_SIZENWSE;
00302 break;
00303 case kResizeNS:
00304 id = IDC_SIZENS;
00305 break;
00306 case kResizeWE:
00307 id = IDC_SIZEWE;
00308 break;
00309 case kResizeNESW:
00310 id = IDC_SIZENESW;
00311 break;
00312 default:
00313 id = IDC_ARROW;
00314 break;
00315 }
00316
00317 HCURSOR hCurs = LoadCursor( NULL, id );
00318 SetCursor( hCurs );
00319 }
00320
00321
00322 void Win32Factory::rmDir( const string &rPath )
00323 {
00324 WIN32_FIND_DATA find;
00325 string file;
00326 string findFiles = rPath + "\\*";
00327 HANDLE handle = FindFirstFile( findFiles.c_str(), &find );
00328
00329 while( handle != INVALID_HANDLE_VALUE )
00330 {
00331
00332 if( strcmp( find.cFileName, "." ) && strcmp( find.cFileName, ".." ) )
00333 {
00334
00335 file = rPath + "\\" + (string)find.cFileName;
00336
00337
00338 if( find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
00339 {
00340 rmDir( file );
00341 }
00342
00343 else
00344 {
00345 DeleteFile( file.c_str() );
00346 }
00347 }
00348
00349
00350 if( !FindNextFile( handle, &find ) )
00351 break;
00352 }
00353
00354
00355 FindClose( handle );
00356 RemoveDirectory( rPath.c_str() );
00357 }
00358
00359 #endif