Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
334 lines (304 loc) · 9.85 KB

SDL_syswm.c

File metadata and controls

334 lines (304 loc) · 9.85 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Feb 1, 2006
Feb 1, 2006
3
Copyright (C) 1997-2006 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
Apr 26, 2001
Apr 26, 2001
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
Apr 26, 2001
Apr 26, 2001
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Apr 26, 2001
Apr 26, 2001
14
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Apr 26, 2001
Apr 26, 2001
18
19
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
23
Feb 25, 2006
Feb 25, 2006
24
25
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
Apr 26, 2001
Apr 26, 2001
26
27
28
#include "SDL_version.h"
#include "SDL_video.h"
Feb 16, 2006
Feb 16, 2006
29
#include "SDL_loadso.h"
Apr 26, 2001
Apr 26, 2001
30
#include "SDL_syswm.h"
Feb 16, 2006
Feb 16, 2006
31
32
#include "../SDL_pixels_c.h"
#include "../SDL_cursor_c.h"
Apr 26, 2001
Apr 26, 2001
33
#include "SDL_syswm_c.h"
Aug 17, 2002
Aug 17, 2002
34
#include "SDL_wingl_c.h"
Sep 29, 2005
Sep 29, 2005
35
Apr 26, 2001
Apr 26, 2001
36
37
38
39
40
41
#ifdef _WIN32_WCE
#define DISABLE_ICON_SUPPORT
#endif
/* The screen icon -- needs to be freed on SDL_VideoQuit() */
Jul 10, 2006
Jul 10, 2006
42
HICON screen_icn = NULL;
Apr 26, 2001
Apr 26, 2001
43
Sep 29, 2005
Sep 29, 2005
44
45
#ifdef _WIN32_WCE
Jul 10, 2006
Jul 10, 2006
46
BOOL(WINAPI * CoreCatchInput) (int flag) = NULL;
Sep 29, 2005
Sep 29, 2005
47
48
49
50
int input_catched = 0;
HINSTANCE coredll = NULL;
// the same API call that gx.dll does to catch the input
Jul 10, 2006
Jul 10, 2006
51
52
void
LoadInputCatchFunc()
Sep 29, 2005
Sep 29, 2005
53
{
Jul 10, 2006
Jul 10, 2006
54
55
56
57
58
59
60
coredll = SDL_LoadObject("coredll.dll");
if (coredll) {
CoreCatchInput =
(int (WINAPI *) (int)) GetProcAddress(coredll,
(const unsigned short *)
1453);
}
Sep 29, 2005
Sep 29, 2005
61
62
63
64
65
}
#endif
Apr 26, 2001
Apr 26, 2001
66
67
68
69
70
71
/* Win32 icon mask semantics are different from those of SDL:
SDL applies the mask to the icon and copies result to desktop.
Win32 applies the mask to the desktop and XORs the icon on.
This means that the SDL mask needs to be applied to the icon and
then inverted and passed to Win32.
*/
Jul 10, 2006
Jul 10, 2006
72
73
void
WIN_SetWMIcon(_THIS, SDL_Surface * icon, Uint8 * mask)
Apr 26, 2001
Apr 26, 2001
74
75
{
#ifdef DISABLE_ICON_SUPPORT
Jul 10, 2006
Jul 10, 2006
76
return;
Apr 26, 2001
Apr 26, 2001
77
#else
Jul 10, 2006
Jul 10, 2006
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
SDL_Palette *pal_256;
SDL_Surface *icon_256;
Uint8 *pdata, *pwin32;
Uint8 *mdata, *mwin32, m = 0;
int icon_len;
int icon_plen;
int icon_mlen;
int icon_pitch;
int mask_pitch;
SDL_Rect bounds;
int i, skip;
int row, col;
struct /* quasi-BMP format */ Win32Icon
{
Uint32 biSize;
Sint32 biWidth;
Sint32 biHeight;
Uint16 biPlanes;
Uint16 biBitCount;
Uint32 biCompression;
Uint32 biSizeImage;
Sint32 biXPelsPerMeter;
Sint32 biYPelsPerMeter;
Uint32 biClrUsed;
Uint32 biClrImportant;
struct /* RGBQUAD -- note it's BGR ordered */
{
Uint8 rgbBlue;
Uint8 rgbGreen;
Uint8 rgbRed;
Uint8 rgbReserved;
} biColors[256];
/* Pixels:
Uint8 pixels[]
*/
/* Mask:
Uint8 mask[]
*/
} *icon_win32;
Apr 26, 2001
Apr 26, 2001
117
Jul 10, 2006
Jul 10, 2006
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* Allocate the win32 bmp icon and set everything to zero */
icon_pitch = ((icon->w + 3) & ~3);
mask_pitch = ((icon->w + 7) / 8);
icon_plen = icon->h * icon_pitch;
icon_mlen = icon->h * mask_pitch;
icon_len = sizeof(*icon_win32) + icon_plen + icon_mlen;
icon_win32 = (struct Win32Icon *) SDL_stack_alloc(Uint8, icon_len);
if (icon_win32 == NULL) {
return;
}
SDL_memset(icon_win32, 0, icon_len);
/* Set the basic BMP parameters */
icon_win32->biSize = sizeof(*icon_win32) - sizeof(icon_win32->biColors);
icon_win32->biWidth = icon->w;
icon_win32->biHeight = icon->h * 2;
icon_win32->biPlanes = 1;
icon_win32->biBitCount = 8;
icon_win32->biSizeImage = icon_plen + icon_mlen;
Apr 26, 2001
Apr 26, 2001
137
Jul 10, 2006
Jul 10, 2006
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/* Allocate a standard 256 color icon surface */
icon_256 = SDL_CreateRGBSurface(SDL_SWSURFACE, icon->w, icon->h,
icon_win32->biBitCount, 0, 0, 0, 0);
if (icon_256 == NULL) {
SDL_stack_free(icon_win32);
return;
}
pal_256 = icon_256->format->palette;
if (icon->format->palette &&
(icon->format->BitsPerPixel == icon_256->format->BitsPerPixel)) {
Uint8 black;
SDL_memcpy(pal_256->colors, icon->format->palette->colors,
pal_256->ncolors * sizeof(SDL_Color));
/* Make sure that 0 is black! */
black = SDL_FindColor(pal_256, 0x00, 0x00, 0x00);
pal_256->colors[black] = pal_256->colors[0];
pal_256->colors[0].r = 0x00;
pal_256->colors[0].g = 0x00;
pal_256->colors[0].b = 0x00;
} else {
SDL_DitherColors(pal_256->colors, icon_256->format->BitsPerPixel);
}
Apr 26, 2001
Apr 26, 2001
160
Jul 10, 2006
Jul 10, 2006
161
162
163
164
165
166
/* Now copy color data to the icon BMP */
for (i = 0; i < (1 << icon_win32->biBitCount); ++i) {
icon_win32->biColors[i].rgbRed = pal_256->colors[i].r;
icon_win32->biColors[i].rgbGreen = pal_256->colors[i].g;
icon_win32->biColors[i].rgbBlue = pal_256->colors[i].b;
}
Apr 26, 2001
Apr 26, 2001
167
Jul 10, 2006
Jul 10, 2006
168
169
170
171
/* Convert icon to a standard surface format. This may not always
be necessary, as Windows supports a variety of BMP formats, but
it greatly simplifies our code.
*/
Feb 6, 2006
Feb 6, 2006
172
173
174
175
bounds.x = 0;
bounds.y = 0;
bounds.w = icon->w;
bounds.h = icon->h;
Jul 10, 2006
Jul 10, 2006
176
177
178
if (SDL_LowerBlit(icon, &bounds, icon_256, &bounds) < 0) {
SDL_stack_free(icon_win32);
SDL_FreeSurface(icon_256);
Feb 6, 2006
Feb 6, 2006
179
return;
Jul 10, 2006
Jul 10, 2006
180
}
Apr 26, 2001
Apr 26, 2001
181
Jul 10, 2006
Jul 10, 2006
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* Copy pixels upside-down to icon BMP, masked with the icon mask */
if (SDL_MUSTLOCK(icon_256) || (icon_256->pitch != icon_pitch)) {
SDL_stack_free(icon_win32);
SDL_FreeSurface(icon_256);
SDL_SetError("Warning: Unexpected icon_256 characteristics");
return;
}
pdata = (Uint8 *) icon_256->pixels;
mdata = mask;
pwin32 =
(Uint8 *) icon_win32 + sizeof(*icon_win32) + icon_plen - icon_pitch;
skip = icon_pitch - icon->w;
for (row = 0; row < icon->h; ++row) {
for (col = 0; col < icon->w; ++col) {
if ((col % 8) == 0) {
m = *mdata++;
}
if ((m & 0x80) != 0x00) {
*pwin32 = *pdata;
}
m <<= 1;
++pdata;
++pwin32;
}
pdata += skip;
pwin32 += skip;
pwin32 -= 2 * icon_pitch;
}
SDL_FreeSurface(icon_256);
Apr 26, 2001
Apr 26, 2001
211
Jul 10, 2006
Jul 10, 2006
212
213
214
215
216
217
218
219
220
221
/* Copy mask inverted and upside-down to icon BMP */
mdata = mask;
mwin32 = (Uint8 *) icon_win32
+ sizeof(*icon_win32) + icon_plen + icon_mlen - mask_pitch;
for (row = 0; row < icon->h; ++row) {
for (col = 0; col < mask_pitch; ++col) {
*mwin32++ = ~*mdata++;
}
mwin32 -= 2 * mask_pitch;
}
Apr 26, 2001
Apr 26, 2001
222
Jul 10, 2006
Jul 10, 2006
223
224
225
226
227
228
229
230
231
232
/* Finally, create the icon handle and set the window icon */
screen_icn = CreateIconFromResourceEx((Uint8 *) icon_win32, icon_len,
TRUE, 0x00030000, icon->w, icon->h,
LR_DEFAULTCOLOR);
if (screen_icn == NULL) {
SDL_SetError("Couldn't create Win32 icon handle");
} else {
SetClassLongPtr(SDL_Window, GCLP_HICON, (LONG_PTR) screen_icn);
}
SDL_stack_free(icon_win32);
Apr 26, 2001
Apr 26, 2001
233
234
235
#endif /* DISABLE_ICON_SUPPORT */
}
Jul 10, 2006
Jul 10, 2006
236
237
void
WIN_SetWMCaption(_THIS, const char *title, const char *icon)
Apr 26, 2001
Apr 26, 2001
238
239
{
#ifdef _WIN32_WCE
Jul 10, 2006
Jul 10, 2006
240
241
242
243
/* WinCE uses the UNICODE version */
LPWSTR lpszW = SDL_iconv_utf8_ucs2((char *) title);
SetWindowText(SDL_Window, lpszW);
SDL_free(lpszW);
Apr 26, 2001
Apr 26, 2001
244
#else
Jul 10, 2006
Jul 10, 2006
245
246
247
char *lpsz = SDL_iconv_utf8_latin1((char *) title);
SetWindowText(SDL_Window, lpsz);
SDL_free(lpsz);
Apr 26, 2001
Apr 26, 2001
248
249
250
#endif
}
Jul 10, 2006
Jul 10, 2006
251
252
int
WIN_IconifyWindow(_THIS)
Apr 26, 2001
Apr 26, 2001
253
{
Jul 10, 2006
Jul 10, 2006
254
255
ShowWindow(SDL_Window, SW_MINIMIZE);
return (1);
Apr 26, 2001
Apr 26, 2001
256
257
}
Jul 10, 2006
Jul 10, 2006
258
259
SDL_GrabMode
WIN_GrabInput(_THIS, SDL_GrabMode mode)
Apr 26, 2001
Apr 26, 2001
260
{
Jul 10, 2006
Jul 10, 2006
261
262
263
264
265
266
267
268
269
270
271
272
273
274
if (mode == SDL_GRAB_OFF) {
ClipCursor(NULL);
if (!(SDL_cursorstate & CURSOR_VISIBLE)) {
/* RJR: March 28, 2000
must be leaving relative mode, move mouse from
center of window to where it belongs ... */
POINT pt;
int x, y;
SDL_GetMouseState(&x, &y);
pt.x = x;
pt.y = y;
ClientToScreen(SDL_Window, &pt);
SetCursorPos(pt.x, pt.y);
}
Sep 29, 2005
Sep 29, 2005
275
#ifdef _WIN32_WCE
Jul 10, 2006
Jul 10, 2006
276
277
278
if (input_catched) {
if (!CoreCatchInput)
LoadInputCatchFunc();
Sep 29, 2005
Sep 29, 2005
279
Jul 10, 2006
Jul 10, 2006
280
281
282
if (CoreCatchInput)
CoreCatchInput(0);
}
Sep 29, 2005
Sep 29, 2005
283
#endif
Jul 10, 2006
Jul 10, 2006
284
285
286
287
288
289
290
291
292
293
294
295
} else {
ClipCursor(&SDL_bounds);
if (!(SDL_cursorstate & CURSOR_VISIBLE)) {
/* RJR: March 28, 2000
must be entering relative mode, get ready by
moving mouse to center of window ... */
POINT pt;
pt.x = (SDL_VideoSurface->w / 2);
pt.y = (SDL_VideoSurface->h / 2);
ClientToScreen(SDL_Window, &pt);
SetCursorPos(pt.x, pt.y);
}
Sep 29, 2005
Sep 29, 2005
296
#ifdef _WIN32_WCE
Jul 10, 2006
Jul 10, 2006
297
298
299
if (!input_catched) {
if (!CoreCatchInput)
LoadInputCatchFunc();
Sep 29, 2005
Sep 29, 2005
300
Jul 10, 2006
Jul 10, 2006
301
302
303
if (CoreCatchInput)
CoreCatchInput(1);
}
Sep 29, 2005
Sep 29, 2005
304
#endif
Jul 10, 2006
Jul 10, 2006
305
306
}
return (mode);
Apr 26, 2001
Apr 26, 2001
307
308
309
310
311
}
/* If 'info' is the right version, this function fills it and returns 1.
Otherwise, in case of a version mismatch, it returns -1.
*/
Jul 10, 2006
Jul 10, 2006
312
313
int
WIN_GetWMInfo(_THIS, SDL_SysWMinfo * info)
Apr 26, 2001
Apr 26, 2001
314
{
Jul 10, 2006
Jul 10, 2006
315
316
317
318
319
if (info->version.major <= SDL_MAJOR_VERSION) {
info->window = SDL_Window;
if (SDL_VERSIONNUM(info->version.major,
info->version.minor,
info->version.patch) >= SDL_VERSIONNUM(1, 2, 5)) {
Feb 16, 2006
Feb 16, 2006
320
#if SDL_VIDEO_OPENGL
Jul 10, 2006
Jul 10, 2006
321
info->hglrc = GL_hrc;
Aug 17, 2002
Aug 17, 2002
322
#else
Jul 10, 2006
Jul 10, 2006
323
info->hglrc = NULL;
Aug 17, 2002
Aug 17, 2002
324
#endif
Jul 10, 2006
Jul 10, 2006
325
326
327
328
329
330
331
}
return (1);
} else {
SDL_SetError("Application not compiled with SDL %d.%d\n",
SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
return (-1);
}
Apr 26, 2001
Apr 26, 2001
332
}
Jul 10, 2006
Jul 10, 2006
333
334
/* vi: set ts=4 sw=4 expandtab: */