comparison src/video/wincommon/SDL_syswm.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 720f8bb49d7d
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
37 #ifdef _WIN32_WCE 37 #ifdef _WIN32_WCE
38 #define DISABLE_ICON_SUPPORT 38 #define DISABLE_ICON_SUPPORT
39 #endif 39 #endif
40 40
41 /* The screen icon -- needs to be freed on SDL_VideoQuit() */ 41 /* The screen icon -- needs to be freed on SDL_VideoQuit() */
42 HICON screen_icn = NULL; 42 HICON screen_icn = NULL;
43 43
44 #ifdef _WIN32_WCE 44 #ifdef _WIN32_WCE
45 45
46 BOOL (WINAPI *CoreCatchInput)(int flag) = NULL; 46 BOOL (WINAPI * CoreCatchInput) (int flag) = NULL;
47 int input_catched = 0; 47 int input_catched = 0;
48 HINSTANCE coredll = NULL; 48 HINSTANCE coredll = NULL;
49 49
50 // the same API call that gx.dll does to catch the input 50 // the same API call that gx.dll does to catch the input
51 void LoadInputCatchFunc() 51 void
52 { 52 LoadInputCatchFunc ()
53 coredll = SDL_LoadObject("coredll.dll"); 53 {
54 if( coredll ) 54 coredll = SDL_LoadObject ("coredll.dll");
55 { 55 if (coredll) {
56 CoreCatchInput = (int (WINAPI *)(int)) GetProcAddress(coredll, (const unsigned short *) 1453); 56 CoreCatchInput =
57 } 57 (int (WINAPI *) (int)) GetProcAddress (coredll,
58 (const unsigned short *)
59 1453);
60 }
58 } 61 }
59 62
60 #endif 63 #endif
61 64
62 65
64 SDL applies the mask to the icon and copies result to desktop. 67 SDL applies the mask to the icon and copies result to desktop.
65 Win32 applies the mask to the desktop and XORs the icon on. 68 Win32 applies the mask to the desktop and XORs the icon on.
66 This means that the SDL mask needs to be applied to the icon and 69 This means that the SDL mask needs to be applied to the icon and
67 then inverted and passed to Win32. 70 then inverted and passed to Win32.
68 */ 71 */
69 void WIN_SetWMIcon(_THIS, SDL_Surface *icon, Uint8 *mask) 72 void
73 WIN_SetWMIcon (_THIS, SDL_Surface * icon, Uint8 * mask)
70 { 74 {
71 #ifdef DISABLE_ICON_SUPPORT 75 #ifdef DISABLE_ICON_SUPPORT
72 return; 76 return;
73 #else 77 #else
74 SDL_Palette *pal_256; 78 SDL_Palette *pal_256;
75 SDL_Surface *icon_256; 79 SDL_Surface *icon_256;
76 Uint8 *pdata, *pwin32; 80 Uint8 *pdata, *pwin32;
77 Uint8 *mdata, *mwin32, m = 0; 81 Uint8 *mdata, *mwin32, m = 0;
78 int icon_len; 82 int icon_len;
79 int icon_plen; 83 int icon_plen;
80 int icon_mlen; 84 int icon_mlen;
81 int icon_pitch; 85 int icon_pitch;
82 int mask_pitch; 86 int mask_pitch;
83 SDL_Rect bounds; 87 SDL_Rect bounds;
84 int i, skip; 88 int i, skip;
85 int row, col; 89 int row, col;
86 struct /* quasi-BMP format */ Win32Icon { 90 struct /* quasi-BMP format */ Win32Icon
87 Uint32 biSize; 91 {
88 Sint32 biWidth; 92 Uint32 biSize;
89 Sint32 biHeight; 93 Sint32 biWidth;
90 Uint16 biPlanes; 94 Sint32 biHeight;
91 Uint16 biBitCount; 95 Uint16 biPlanes;
92 Uint32 biCompression; 96 Uint16 biBitCount;
93 Uint32 biSizeImage; 97 Uint32 biCompression;
94 Sint32 biXPelsPerMeter; 98 Uint32 biSizeImage;
95 Sint32 biYPelsPerMeter; 99 Sint32 biXPelsPerMeter;
96 Uint32 biClrUsed; 100 Sint32 biYPelsPerMeter;
97 Uint32 biClrImportant; 101 Uint32 biClrUsed;
98 struct /* RGBQUAD -- note it's BGR ordered */ { 102 Uint32 biClrImportant;
99 Uint8 rgbBlue; 103 struct /* RGBQUAD -- note it's BGR ordered */
100 Uint8 rgbGreen; 104 {
101 Uint8 rgbRed; 105 Uint8 rgbBlue;
102 Uint8 rgbReserved; 106 Uint8 rgbGreen;
103 } biColors[256]; 107 Uint8 rgbRed;
104 /* Pixels: 108 Uint8 rgbReserved;
105 Uint8 pixels[] 109 } biColors[256];
106 */ 110 /* Pixels:
107 /* Mask: 111 Uint8 pixels[]
108 Uint8 mask[] 112 */
109 */ 113 /* Mask:
110 } *icon_win32; 114 Uint8 mask[]
111 115 */
112 /* Allocate the win32 bmp icon and set everything to zero */ 116 } *icon_win32;
113 icon_pitch = ((icon->w+3)&~3); 117
114 mask_pitch = ((icon->w+7)/8); 118 /* Allocate the win32 bmp icon and set everything to zero */
115 icon_plen = icon->h*icon_pitch; 119 icon_pitch = ((icon->w + 3) & ~3);
116 icon_mlen = icon->h*mask_pitch; 120 mask_pitch = ((icon->w + 7) / 8);
117 icon_len = sizeof(*icon_win32)+icon_plen+icon_mlen; 121 icon_plen = icon->h * icon_pitch;
118 icon_win32 = (struct Win32Icon *)SDL_stack_alloc(Uint8, icon_len); 122 icon_mlen = icon->h * mask_pitch;
119 if ( icon_win32 == NULL ) { 123 icon_len = sizeof (*icon_win32) + icon_plen + icon_mlen;
120 return; 124 icon_win32 = (struct Win32Icon *) SDL_stack_alloc (Uint8, icon_len);
121 } 125 if (icon_win32 == NULL) {
122 SDL_memset(icon_win32, 0, icon_len); 126 return;
123 127 }
124 /* Set the basic BMP parameters */ 128 SDL_memset (icon_win32, 0, icon_len);
125 icon_win32->biSize = sizeof(*icon_win32)-sizeof(icon_win32->biColors); 129
126 icon_win32->biWidth = icon->w; 130 /* Set the basic BMP parameters */
127 icon_win32->biHeight = icon->h*2; 131 icon_win32->biSize = sizeof (*icon_win32) - sizeof (icon_win32->biColors);
128 icon_win32->biPlanes = 1; 132 icon_win32->biWidth = icon->w;
129 icon_win32->biBitCount = 8; 133 icon_win32->biHeight = icon->h * 2;
130 icon_win32->biSizeImage = icon_plen+icon_mlen; 134 icon_win32->biPlanes = 1;
131 135 icon_win32->biBitCount = 8;
132 /* Allocate a standard 256 color icon surface */ 136 icon_win32->biSizeImage = icon_plen + icon_mlen;
133 icon_256 = SDL_CreateRGBSurface(SDL_SWSURFACE, icon->w, icon->h, 137
134 icon_win32->biBitCount, 0, 0, 0, 0); 138 /* Allocate a standard 256 color icon surface */
135 if ( icon_256 == NULL ) { 139 icon_256 = SDL_CreateRGBSurface (SDL_SWSURFACE, icon->w, icon->h,
136 SDL_stack_free(icon_win32); 140 icon_win32->biBitCount, 0, 0, 0, 0);
137 return; 141 if (icon_256 == NULL) {
138 } 142 SDL_stack_free (icon_win32);
139 pal_256 = icon_256->format->palette; 143 return;
140 if (icon->format->palette && 144 }
141 (icon->format->BitsPerPixel == icon_256->format->BitsPerPixel)){ 145 pal_256 = icon_256->format->palette;
142 Uint8 black; 146 if (icon->format->palette &&
143 SDL_memcpy(pal_256->colors, icon->format->palette->colors, 147 (icon->format->BitsPerPixel == icon_256->format->BitsPerPixel)) {
144 pal_256->ncolors*sizeof(SDL_Color)); 148 Uint8 black;
145 /* Make sure that 0 is black! */ 149 SDL_memcpy (pal_256->colors, icon->format->palette->colors,
146 black = SDL_FindColor(pal_256, 0x00, 0x00, 0x00); 150 pal_256->ncolors * sizeof (SDL_Color));
147 pal_256->colors[black] = pal_256->colors[0]; 151 /* Make sure that 0 is black! */
148 pal_256->colors[0].r = 0x00; 152 black = SDL_FindColor (pal_256, 0x00, 0x00, 0x00);
149 pal_256->colors[0].g = 0x00; 153 pal_256->colors[black] = pal_256->colors[0];
150 pal_256->colors[0].b = 0x00; 154 pal_256->colors[0].r = 0x00;
151 } else { 155 pal_256->colors[0].g = 0x00;
152 SDL_DitherColors(pal_256->colors, 156 pal_256->colors[0].b = 0x00;
153 icon_256->format->BitsPerPixel); 157 } else {
154 } 158 SDL_DitherColors (pal_256->colors, icon_256->format->BitsPerPixel);
155 159 }
156 /* Now copy color data to the icon BMP */ 160
157 for ( i=0; i<(1<<icon_win32->biBitCount); ++i ) { 161 /* Now copy color data to the icon BMP */
158 icon_win32->biColors[i].rgbRed = pal_256->colors[i].r; 162 for (i = 0; i < (1 << icon_win32->biBitCount); ++i) {
159 icon_win32->biColors[i].rgbGreen = pal_256->colors[i].g; 163 icon_win32->biColors[i].rgbRed = pal_256->colors[i].r;
160 icon_win32->biColors[i].rgbBlue = pal_256->colors[i].b; 164 icon_win32->biColors[i].rgbGreen = pal_256->colors[i].g;
161 } 165 icon_win32->biColors[i].rgbBlue = pal_256->colors[i].b;
162 166 }
163 /* Convert icon to a standard surface format. This may not always 167
164 be necessary, as Windows supports a variety of BMP formats, but 168 /* Convert icon to a standard surface format. This may not always
165 it greatly simplifies our code. 169 be necessary, as Windows supports a variety of BMP formats, but
166 */ 170 it greatly simplifies our code.
171 */
167 bounds.x = 0; 172 bounds.x = 0;
168 bounds.y = 0; 173 bounds.y = 0;
169 bounds.w = icon->w; 174 bounds.w = icon->w;
170 bounds.h = icon->h; 175 bounds.h = icon->h;
171 if ( SDL_LowerBlit(icon, &bounds, icon_256, &bounds) < 0 ) { 176 if (SDL_LowerBlit (icon, &bounds, icon_256, &bounds) < 0) {
172 SDL_stack_free(icon_win32); 177 SDL_stack_free (icon_win32);
173 SDL_FreeSurface(icon_256); 178 SDL_FreeSurface (icon_256);
174 return; 179 return;
175 } 180 }
176 181
177 /* Copy pixels upside-down to icon BMP, masked with the icon mask */ 182 /* Copy pixels upside-down to icon BMP, masked with the icon mask */
178 if ( SDL_MUSTLOCK(icon_256) || (icon_256->pitch != icon_pitch) ) { 183 if (SDL_MUSTLOCK (icon_256) || (icon_256->pitch != icon_pitch)) {
179 SDL_stack_free(icon_win32); 184 SDL_stack_free (icon_win32);
180 SDL_FreeSurface(icon_256); 185 SDL_FreeSurface (icon_256);
181 SDL_SetError("Warning: Unexpected icon_256 characteristics"); 186 SDL_SetError ("Warning: Unexpected icon_256 characteristics");
182 return; 187 return;
183 } 188 }
184 pdata = (Uint8 *)icon_256->pixels; 189 pdata = (Uint8 *) icon_256->pixels;
185 mdata = mask; 190 mdata = mask;
186 pwin32 = (Uint8 *)icon_win32+sizeof(*icon_win32)+icon_plen-icon_pitch; 191 pwin32 =
187 skip = icon_pitch - icon->w; 192 (Uint8 *) icon_win32 + sizeof (*icon_win32) + icon_plen - icon_pitch;
188 for ( row=0; row<icon->h; ++row ) { 193 skip = icon_pitch - icon->w;
189 for ( col=0; col<icon->w; ++col ) { 194 for (row = 0; row < icon->h; ++row) {
190 if ( (col%8) == 0 ) { 195 for (col = 0; col < icon->w; ++col) {
191 m = *mdata++; 196 if ((col % 8) == 0) {
192 } 197 m = *mdata++;
193 if ( (m&0x80) != 0x00 ) { 198 }
194 *pwin32 = *pdata; 199 if ((m & 0x80) != 0x00) {
195 } 200 *pwin32 = *pdata;
196 m <<= 1; 201 }
197 ++pdata; 202 m <<= 1;
198 ++pwin32; 203 ++pdata;
199 } 204 ++pwin32;
200 pdata += skip; 205 }
201 pwin32 += skip; 206 pdata += skip;
202 pwin32 -= 2*icon_pitch; 207 pwin32 += skip;
203 } 208 pwin32 -= 2 * icon_pitch;
204 SDL_FreeSurface(icon_256); 209 }
205 210 SDL_FreeSurface (icon_256);
206 /* Copy mask inverted and upside-down to icon BMP */ 211
207 mdata = mask; 212 /* Copy mask inverted and upside-down to icon BMP */
208 mwin32 = (Uint8 *)icon_win32 213 mdata = mask;
209 +sizeof(*icon_win32)+icon_plen+icon_mlen-mask_pitch; 214 mwin32 = (Uint8 *) icon_win32
210 for ( row=0; row<icon->h; ++row ) { 215 + sizeof (*icon_win32) + icon_plen + icon_mlen - mask_pitch;
211 for ( col=0; col<mask_pitch; ++col ) { 216 for (row = 0; row < icon->h; ++row) {
212 *mwin32++ = ~*mdata++; 217 for (col = 0; col < mask_pitch; ++col) {
213 } 218 *mwin32++ = ~*mdata++;
214 mwin32 -= 2*mask_pitch; 219 }
215 } 220 mwin32 -= 2 * mask_pitch;
216 221 }
217 /* Finally, create the icon handle and set the window icon */ 222
218 screen_icn = CreateIconFromResourceEx((Uint8 *)icon_win32, icon_len, 223 /* Finally, create the icon handle and set the window icon */
219 TRUE, 0x00030000, icon->w, icon->h, LR_DEFAULTCOLOR); 224 screen_icn = CreateIconFromResourceEx ((Uint8 *) icon_win32, icon_len,
220 if ( screen_icn == NULL ) { 225 TRUE, 0x00030000, icon->w, icon->h,
221 SDL_SetError("Couldn't create Win32 icon handle"); 226 LR_DEFAULTCOLOR);
222 } else { 227 if (screen_icn == NULL) {
223 SetClassLongPtr(SDL_Window, GCLP_HICON, (LONG_PTR)screen_icn); 228 SDL_SetError ("Couldn't create Win32 icon handle");
224 } 229 } else {
225 SDL_stack_free(icon_win32); 230 SetClassLongPtr (SDL_Window, GCLP_HICON, (LONG_PTR) screen_icn);
231 }
232 SDL_stack_free (icon_win32);
226 #endif /* DISABLE_ICON_SUPPORT */ 233 #endif /* DISABLE_ICON_SUPPORT */
227 } 234 }
228 235
229 void WIN_SetWMCaption(_THIS, const char *title, const char *icon) 236 void
230 { 237 WIN_SetWMCaption (_THIS, const char *title, const char *icon)
231 #ifdef _WIN32_WCE 238 {
232 /* WinCE uses the UNICODE version */ 239 #ifdef _WIN32_WCE
233 LPWSTR lpszW = SDL_iconv_utf8_ucs2((char *)title); 240 /* WinCE uses the UNICODE version */
234 SetWindowText(SDL_Window, lpszW); 241 LPWSTR lpszW = SDL_iconv_utf8_ucs2 ((char *) title);
235 SDL_free(lpszW); 242 SetWindowText (SDL_Window, lpszW);
243 SDL_free (lpszW);
236 #else 244 #else
237 char *lpsz = SDL_iconv_utf8_latin1((char *)title); 245 char *lpsz = SDL_iconv_utf8_latin1 ((char *) title);
238 SetWindowText(SDL_Window, lpsz); 246 SetWindowText (SDL_Window, lpsz);
239 SDL_free(lpsz); 247 SDL_free (lpsz);
240 #endif 248 #endif
241 } 249 }
242 250
243 int WIN_IconifyWindow(_THIS) 251 int
244 { 252 WIN_IconifyWindow (_THIS)
245 ShowWindow(SDL_Window, SW_MINIMIZE); 253 {
246 return(1); 254 ShowWindow (SDL_Window, SW_MINIMIZE);
247 } 255 return (1);
248 256 }
249 SDL_GrabMode WIN_GrabInput(_THIS, SDL_GrabMode mode) 257
250 { 258 SDL_GrabMode
251 if ( mode == SDL_GRAB_OFF ) { 259 WIN_GrabInput (_THIS, SDL_GrabMode mode)
252 ClipCursor(NULL); 260 {
253 if ( !(SDL_cursorstate & CURSOR_VISIBLE) ) { 261 if (mode == SDL_GRAB_OFF) {
254 /* RJR: March 28, 2000 262 ClipCursor (NULL);
255 must be leaving relative mode, move mouse from 263 if (!(SDL_cursorstate & CURSOR_VISIBLE)) {
256 center of window to where it belongs ... */ 264 /* RJR: March 28, 2000
257 POINT pt; 265 must be leaving relative mode, move mouse from
258 int x, y; 266 center of window to where it belongs ... */
259 SDL_GetMouseState(&x,&y); 267 POINT pt;
260 pt.x = x; 268 int x, y;
261 pt.y = y; 269 SDL_GetMouseState (&x, &y);
262 ClientToScreen(SDL_Window, &pt); 270 pt.x = x;
263 SetCursorPos(pt.x,pt.y); 271 pt.y = y;
264 } 272 ClientToScreen (SDL_Window, &pt);
265 #ifdef _WIN32_WCE 273 SetCursorPos (pt.x, pt.y);
266 if( input_catched ) 274 }
267 { 275 #ifdef _WIN32_WCE
268 if( !CoreCatchInput ) LoadInputCatchFunc(); 276 if (input_catched) {
269 277 if (!CoreCatchInput)
270 if( CoreCatchInput ) 278 LoadInputCatchFunc ();
271 CoreCatchInput(0); 279
272 } 280 if (CoreCatchInput)
273 #endif 281 CoreCatchInput (0);
274 } else { 282 }
275 ClipCursor(&SDL_bounds); 283 #endif
276 if ( !(SDL_cursorstate & CURSOR_VISIBLE) ) { 284 } else {
277 /* RJR: March 28, 2000 285 ClipCursor (&SDL_bounds);
278 must be entering relative mode, get ready by 286 if (!(SDL_cursorstate & CURSOR_VISIBLE)) {
279 moving mouse to center of window ... */ 287 /* RJR: March 28, 2000
280 POINT pt; 288 must be entering relative mode, get ready by
281 pt.x = (SDL_VideoSurface->w/2); 289 moving mouse to center of window ... */
282 pt.y = (SDL_VideoSurface->h/2); 290 POINT pt;
283 ClientToScreen(SDL_Window, &pt); 291 pt.x = (SDL_VideoSurface->w / 2);
284 SetCursorPos(pt.x, pt.y); 292 pt.y = (SDL_VideoSurface->h / 2);
285 } 293 ClientToScreen (SDL_Window, &pt);
286 #ifdef _WIN32_WCE 294 SetCursorPos (pt.x, pt.y);
287 if( !input_catched ) 295 }
288 { 296 #ifdef _WIN32_WCE
289 if( !CoreCatchInput ) LoadInputCatchFunc(); 297 if (!input_catched) {
290 298 if (!CoreCatchInput)
291 if( CoreCatchInput ) 299 LoadInputCatchFunc ();
292 CoreCatchInput(1); 300
293 } 301 if (CoreCatchInput)
294 #endif 302 CoreCatchInput (1);
295 } 303 }
296 return(mode); 304 #endif
305 }
306 return (mode);
297 } 307 }
298 308
299 /* If 'info' is the right version, this function fills it and returns 1. 309 /* If 'info' is the right version, this function fills it and returns 1.
300 Otherwise, in case of a version mismatch, it returns -1. 310 Otherwise, in case of a version mismatch, it returns -1.
301 */ 311 */
302 int WIN_GetWMInfo(_THIS, SDL_SysWMinfo *info) 312 int
303 { 313 WIN_GetWMInfo (_THIS, SDL_SysWMinfo * info)
304 if ( info->version.major <= SDL_MAJOR_VERSION ) { 314 {
305 info->window = SDL_Window; 315 if (info->version.major <= SDL_MAJOR_VERSION) {
306 if ( SDL_VERSIONNUM(info->version.major, 316 info->window = SDL_Window;
307 info->version.minor, 317 if (SDL_VERSIONNUM (info->version.major,
308 info->version.patch) >= 318 info->version.minor,
309 SDL_VERSIONNUM(1, 2, 5) ) { 319 info->version.patch) >=
320 SDL_VERSIONNUM (1, 2, 5)) {
310 #if SDL_VIDEO_OPENGL 321 #if SDL_VIDEO_OPENGL
311 info->hglrc = GL_hrc; 322 info->hglrc = GL_hrc;
312 #else 323 #else
313 info->hglrc = NULL; 324 info->hglrc = NULL;
314 #endif 325 #endif
315 } 326 }
316 return(1); 327 return (1);
317 } else { 328 } else {
318 SDL_SetError("Application not compiled with SDL %d.%d\n", 329 SDL_SetError ("Application not compiled with SDL %d.%d\n",
319 SDL_MAJOR_VERSION, SDL_MINOR_VERSION); 330 SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
320 return(-1); 331 return (-1);
321 } 332 }
322 } 333 }
334
335 /* vi: set ts=4 sw=4 expandtab: */