]> git.sesse.net Git - vlc/blob - modules/gui/skins/win32/win32_api.cpp
4c940d0de275073d9a238fa6ec04350dac020ef7
[vlc] / modules / gui / skins / win32 / win32_api.cpp
1 /*****************************************************************************
2  * win32_api.cpp: Various win32-specific functions
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: win32_api.cpp,v 1.1 2003/03/18 02:21:47 ipkiss Exp $
6  *
7  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
8  *          Emmanuel Puig    <karibu@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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,
23  * USA.
24  *****************************************************************************/
25
26
27 //--- WIN32 -----------------------------------------------------------------
28 #include <windows.h>
29
30 //--- SKIN ------------------------------------------------------------------
31 #include "window.h"
32 #include "os_window.h"
33 #include "os_api.h"
34 #include "event.h"         // for MAX_PARAM_SIZE
35
36
37
38 //---------------------------------------------------------------------------
39 // Event API
40 //---------------------------------------------------------------------------
41 void OSAPI_SendMessage( Window *win, unsigned int message, unsigned int param1,
42                         long param2 )
43 {
44     if( win == NULL )
45         SendMessage( NULL, message, param1, param2 );
46     else
47         SendMessage( ( (Win32Window *)win )->GetHandle(), message, param1,
48                      param2 );
49 }
50 //---------------------------------------------------------------------------
51 void OSAPI_PostMessage( Window *win, unsigned int message, unsigned int param1,
52                         long param2 )
53 {
54     if( win == NULL )
55         PostMessage( NULL, message, param1, param2 );
56     else
57         PostMessage( ( (Win32Window *)win )->GetHandle(), message, param1,
58                      param2 );
59 }
60 //---------------------------------------------------------------------------
61
62
63
64
65 //---------------------------------------------------------------------------
66 // Graphic API
67 //---------------------------------------------------------------------------
68 int OSAPI_GetNonTransparentColor( int c )
69 {
70     // Get desktop device context
71     HDC DeskDC = GetWindowDC( GetDesktopWindow() );
72
73     // If color is black or color is same as black wether pixel color depth
74     if( c == 0 || SetPixel( DeskDC, 0, 0, c ) == 0 )
75     {
76         if( GetDeviceCaps( DeskDC, BITSPIXEL ) < 24 )
77             c = RGB(8, 0, 0);
78         else
79             c = RGB(1, 0, 0);
80     }
81     ReleaseDC( GetDesktopWindow(), DeskDC );
82     return c;
83 }
84 //---------------------------------------------------------------------------
85
86
87
88
89 //---------------------------------------------------------------------------
90 // General
91 //---------------------------------------------------------------------------
92 int OSAPI_GetTime()
93 {
94     return GetTickCount();
95 }
96 //---------------------------------------------------------------------------
97 void OSAPI_GetScreenSize( int &w, int &h )
98 {
99     w = GetSystemMetrics(SM_CXSCREEN);
100     h = GetSystemMetrics(SM_CYSCREEN);
101 }
102 //---------------------------------------------------------------------------
103 void OSAPI_GetMousePos( int &x, int &y )
104 {
105     LPPOINT MousePos = new POINT;
106     GetCursorPos( MousePos );
107     x = MousePos->x;
108     y = MousePos->y;
109     delete MousePos;
110 }
111 //---------------------------------------------------------------------------
112 string OSAPI_GetWindowTitle( Window *win )
113 {
114     char *buffer = new char[MAX_PARAM_SIZE];
115     GetWindowText( ((Win32Window *)win)->GetHandle(), buffer, MAX_PARAM_SIZE );
116     string Title = buffer;
117     delete buffer;
118
119     return Title;
120 }
121 //---------------------------------------------------------------------------
122 bool OSAPI_RmDir( string path )
123 {
124     WIN32_FIND_DATA find;
125     string File;
126     string FindFiles = path + "\\*.*";
127     HANDLE handle    = FindFirstFile( (char *)FindFiles.c_str(), &find );
128
129     while( handle != INVALID_HANDLE_VALUE )
130     {
131         // If file is neither "." nor ".."
132         if( strcmp( find.cFileName, "." ) && strcmp( find.cFileName, ".." ) )
133         {
134             // Set file name
135             File = path + "\\" + (string)find.cFileName;
136
137             // If file is a directory, delete it recursively
138             if( find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
139             {
140                 OSAPI_RmDir( File );
141             }
142             // Else, it is a file so simply delete it
143             else
144             {
145                 DeleteFile( (char *)File.c_str() );
146             }
147         }
148
149         // If no more file in directory, exit while
150         if( !FindNextFile( handle, &find ) )
151             break;
152     }
153
154     // Now directory is empty so can be removed
155     FindClose( handle );
156     RemoveDirectory( (char *)path.c_str() );
157
158     return true;
159 }
160 //---------------------------------------------------------------------------
161