comparison src/video/os2fslib/SDL_os2fslib.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 066236f0cbf0
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
21 */ 21 */
22 #include "SDL_config.h" 22 #include "SDL_config.h"
23 23
24 #define _ULS_CALLCONV_ 24 #define _ULS_CALLCONV_
25 #define CALLCONV _System 25 #define CALLCONV _System
26 #include <unidef.h> // Unicode API 26 #include <unidef.h> // Unicode API
27 #include <uconv.h> // Unicode API (codepage conversion) 27 #include <uconv.h> // Unicode API (codepage conversion)
28 28
29 #include <process.h> 29 #include <process.h>
30 #include <time.h> 30 #include <time.h>
31 31
32 #include "SDL_video.h" 32 #include "SDL_video.h"
36 #include "../../events/SDL_events_c.h" 36 #include "../../events/SDL_events_c.h"
37 37
38 #include "SDL_os2fslib.h" 38 #include "SDL_os2fslib.h"
39 39
40 static ULONG ulFCFToUse = 40 static ULONG ulFCFToUse =
41 FCF_TITLEBAR | 41 FCF_TITLEBAR |
42 FCF_SYSMENU | 42 FCF_SYSMENU |
43 FCF_MINBUTTON | 43 FCF_MINBUTTON |
44 FCF_MAXBUTTON | 44 FCF_MAXBUTTON | FCF_NOBYTEALIGN | FCF_SIZEBORDER | FCF_TASKLIST;
45 FCF_NOBYTEALIGN | 45
46 FCF_SIZEBORDER | 46 static int bMouseCaptured = 0;
47 FCF_TASKLIST;
48
49 static int bMouseCaptured = 0;
50 static int bMouseCapturable = 0; 47 static int bMouseCapturable = 0;
51 static HPOINTER hptrGlobalPointer = NULL; 48 static HPOINTER hptrGlobalPointer = NULL;
52 static HPOINTER hptrCurrentIcon = NULL; 49 static HPOINTER hptrCurrentIcon = NULL;
53 static int iWindowSizeX = 320; 50 static int iWindowSizeX = 320;
54 static int iWindowSizeY = 200; 51 static int iWindowSizeY = 200;
55 static int bWindowResized = 0; 52 static int bWindowResized = 0;
56 53
57 #pragma pack(1) 54 #pragma pack(1)
58 typedef struct BMPINFO 55 typedef struct BMPINFO
59 { 56 {
60 BITMAPINFO; 57 BITMAPINFO;
61 RGB clr; 58 RGB clr;
62 } BMPINFO, *PBMPINFO; 59 } BMPINFO, *PBMPINFO;
63 #pragma pack() 60 #pragma pack()
64 61
65 62
66 // Backdoors: 63 // Backdoors:
67 DECLSPEC void SDLCALL SDL_OS2FSLIB_SetFCFToUse(ULONG ulFCF) 64 DECLSPEC void SDLCALL
68 { 65 SDL_OS2FSLIB_SetFCFToUse (ULONG ulFCF)
69 ulFCFToUse = ulFCF; 66 {
67 ulFCFToUse = ulFCF;
70 } 68 }
71 69
72 // Configuration defines: 70 // Configuration defines:
73 71
74 // We have to report empty alpha mask, otherwise SDL will select 72 // We have to report empty alpha mask, otherwise SDL will select
90 // even if the surface is resizable. 88 // even if the surface is resizable.
91 //#define RESIZE_EVEN_IF_RESIZABLE 89 //#define RESIZE_EVEN_IF_RESIZABLE
92 90
93 /* The translation table from a VK keysym to a SDL keysym */ 91 /* The translation table from a VK keysym to a SDL keysym */
94 static SDLKey HWScanKeyMap[256]; 92 static SDLKey HWScanKeyMap[256];
95 static SDL_keysym *TranslateKey(int vkey, int chcode, int scancode, SDL_keysym *keysym, int iPressed); 93 static SDL_keysym *TranslateKey (int vkey, int chcode, int scancode,
96 static int iShiftIsPressed; 94 SDL_keysym * keysym, int iPressed);
95 static int iShiftIsPressed;
97 96
98 #ifdef BITBLT_IN_WINMESSAGEPROC 97 #ifdef BITBLT_IN_WINMESSAGEPROC
99 #define WM_UPDATERECTSREQUEST WM_USER+50 98 #define WM_UPDATERECTSREQUEST WM_USER+50
100 #endif 99 #endif
101 100
117 // 116 //
118 // Same as WinSetWindowPos(), but takes care for the window to be 117 // Same as WinSetWindowPos(), but takes care for the window to be
119 // always on the screen, the titlebar will be accessable everytime. 118 // always on the screen, the titlebar will be accessable everytime.
120 // 119 //
121 ///////////////////////////////////////////////////////////////////// 120 /////////////////////////////////////////////////////////////////////
122 static BOOL SetAccessableWindowPos(HWND hwnd, HWND hwndInsertBehind, 121 static BOOL
123 LONG x, LONG y, 122 SetAccessableWindowPos (HWND hwnd, HWND hwndInsertBehind,
124 LONG cx, LONG cy, 123 LONG x, LONG y, LONG cx, LONG cy, ULONG fl)
125 ULONG fl) 124 {
126 { 125 SWP swpDesktop, swp;
127 SWP swpDesktop, swp; 126 // Get desktop area
128 // Get desktop area 127 WinQueryWindowPos (HWND_DESKTOP, &swpDesktop);
129 WinQueryWindowPos(HWND_DESKTOP, &swpDesktop); 128
130 129 if ((fl & SWP_MOVE) && (fl & SWP_SIZE)) {
131 if ((fl & SWP_MOVE) && (fl & SWP_SIZE)) 130 // If both moving and sizing, then change size and pos now!!
132 { 131 if (x + cx > swpDesktop.cx)
133 // If both moving and sizing, then change size and pos now!! 132 x = swpDesktop.cx - cx;
134 if (x+cx>swpDesktop.cx) 133 if (x < 0)
135 x = swpDesktop.cx - cx; 134 x = 0;
136 if (x<0) 135 if (y < 0)
137 x = 0; 136 y = 0;
138 if (y<0) 137 if (y + cy > swpDesktop.cy)
139 y = 0; 138 y = swpDesktop.cy - cy;
140 if (y+cy>swpDesktop.cy) 139 return WinSetWindowPos (hwnd, hwndInsertBehind, x, y, cx, cy, fl);
141 y = swpDesktop.cy - cy; 140 } else if (fl & SWP_MOVE) {
142 return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl); 141 // Just moving
143 } else 142 WinQueryWindowPos (hwnd, &swp);
144 if (fl & SWP_MOVE) 143 if (x + swp.cx > swpDesktop.cx)
145 { 144 x = swpDesktop.cx - swp.cx;
146 // Just moving 145 if (x < 0)
147 WinQueryWindowPos(hwnd, &swp); 146 x = 0;
148 if (x+swp.cx>swpDesktop.cx) 147 if (y < 0)
149 x = swpDesktop.cx - swp.cx; 148 y = 0;
150 if (x<0) 149 if (y + swp.cy > swpDesktop.cy)
151 x = 0; 150 y = swpDesktop.cy - swp.cy;
152 if (y<0) 151 return WinSetWindowPos (hwnd, hwndInsertBehind, x, y, cx, cy, fl);
153 y = 0; 152 } else if (fl & SWP_SIZE) {
154 if (y+swp.cy>swpDesktop.cy) 153 // Just sizing
155 y = swpDesktop.cy - swp.cy; 154 WinQueryWindowPos (hwnd, &swp);
156 return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl); 155 x = swp.x;
157 } else 156 y = swp.y;
158 if (fl & SWP_SIZE) 157 if (x + cx > swpDesktop.cx)
159 { 158 x = swpDesktop.cx - cx;
160 // Just sizing 159 if (x < 0)
161 WinQueryWindowPos(hwnd, &swp); 160 x = 0;
162 x = swp.x; 161 if (y < 0)
163 y = swp.y; 162 y = 0;
164 if (x+cx>swpDesktop.cx) 163 if (y + cy > swpDesktop.cy)
165 x = swpDesktop.cx - cx; 164 y = swpDesktop.cy - cy;
166 if (x<0) 165 return WinSetWindowPos (hwnd, hwndInsertBehind, x, y, cx, cy,
167 x = 0; 166 fl | SWP_MOVE);
168 if (y<0) 167 } else
169 y = 0; 168 return WinSetWindowPos (hwnd, hwndInsertBehind, x, y, cx, cy, fl);
170 if (y+cy>swpDesktop.cy) 169 }
171 y = swpDesktop.cy - cy; 170
172 return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl | SWP_MOVE); 171 static UniChar
173 } else 172 NativeCharToUniChar (int chcode)
174 return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl); 173 {
175 } 174 UniChar ucResult = (UniChar) chcode;
176 175 int rc;
177 static UniChar NativeCharToUniChar(int chcode) 176 UconvObject ucoTemp;
178 { 177 char achFrom[2];
179 UniChar ucResult = (UniChar) chcode; 178 char *pchFrom;
180 int rc; 179 size_t iFromCount;
181 UconvObject ucoTemp; 180 UniChar aucTo[10];
182 char achFrom[2]; 181 UniChar *pucTo;
183 char *pchFrom; 182 size_t iToCount;
184 size_t iFromCount; 183 size_t iNonIdentical;
185 UniChar aucTo[10]; 184
186 UniChar *pucTo; 185 // Create unicode convert object
187 size_t iToCount; 186 rc = UniCreateUconvObject (L"", &ucoTemp);
188 size_t iNonIdentical; 187 if (rc != ULS_SUCCESS) {
189 188 // Could not create convert object!
190 // Create unicode convert object 189 return ucResult;
191 rc = UniCreateUconvObject(L"", &ucoTemp); 190 }
192 if (rc!=ULS_SUCCESS) 191 // Convert language code string to unicode string
193 { 192 achFrom[0] = (char) chcode;
194 // Could not create convert object! 193 achFrom[1] = 0;
195 return ucResult; 194 iFromCount = sizeof (char) * 2;
196 } 195 iToCount = sizeof (UniChar) * 2;
197 196 pucTo = &(aucTo[0]);
198 // Convert language code string to unicode string 197 pchFrom = &(achFrom[0]);
199 achFrom[0] = (char) chcode; 198
200 achFrom[1] = 0; 199 rc = UniUconvToUcs (ucoTemp,
201 iFromCount = sizeof(char) * 2; 200 &pchFrom,
202 iToCount = sizeof(UniChar) * 2; 201 &iFromCount, &pucTo, &iToCount, &iNonIdentical);
203 pucTo = &(aucTo[0]); 202
204 pchFrom = &(achFrom[0]); 203 if (rc != ULS_SUCCESS) {
205 204 // Could not convert language code to UCS string!
206 rc = UniUconvToUcs(ucoTemp, 205 UniFreeUconvObject (ucoTemp);
207 &pchFrom, 206 return ucResult;
208 &iFromCount, 207 }
209 &pucTo, 208
210 &iToCount, 209 UniFreeUconvObject (ucoTemp);
211 &iNonIdentical); 210
212 211 #ifdef DEBUG_BUILD
213 if (rc!=ULS_SUCCESS) 212 printf ("%02x converted to %02x\n", (int) chcode, (int) (aucTo[0]));
214 { 213 #endif
215 // Could not convert language code to UCS string! 214
216 UniFreeUconvObject(ucoTemp); 215 return aucTo[0];
217 return ucResult;
218 }
219
220 UniFreeUconvObject(ucoTemp);
221
222 #ifdef DEBUG_BUILD
223 printf("%02x converted to %02x\n", (int) chcode, (int) (aucTo[0]));
224 #endif
225
226 return aucTo[0];
227 } 216 }
228 217
229 ///////////////////////////////////////////////////////////////////// 218 /////////////////////////////////////////////////////////////////////
230 // 219 //
231 // TranslateKey 220 // TranslateKey
232 // 221 //
233 // This creates SDL Keycodes from VK_ and hardware scan codes 222 // This creates SDL Keycodes from VK_ and hardware scan codes
234 // 223 //
235 ///////////////////////////////////////////////////////////////////// 224 /////////////////////////////////////////////////////////////////////
236 static SDL_keysym *TranslateKey(int vkey, int chcode, int scancode, SDL_keysym *keysym, int iPressed) 225 static SDL_keysym *
237 { 226 TranslateKey (int vkey, int chcode, int scancode, SDL_keysym * keysym,
238 keysym->scancode = (unsigned char) scancode; 227 int iPressed)
239 keysym->mod = KMOD_NONE; 228 {
240 keysym->unicode = 0; 229 keysym->scancode = (unsigned char) scancode;
241 230 keysym->mod = KMOD_NONE;
242 if (iPressed && SDL_TranslateUNICODE) 231 keysym->unicode = 0;
243 { 232
244 if (chcode) 233 if (iPressed && SDL_TranslateUNICODE) {
245 keysym->unicode = NativeCharToUniChar(chcode); 234 if (chcode)
246 else 235 keysym->unicode = NativeCharToUniChar (chcode);
247 keysym->unicode = vkey; 236 else
248 } 237 keysym->unicode = vkey;
249 238 }
250 keysym->sym = HWScanKeyMap[scancode]; 239
251 240 keysym->sym = HWScanKeyMap[scancode];
252 // Now stuffs based on state of shift key(s)! 241
253 if (vkey == VK_SHIFT) 242 // Now stuffs based on state of shift key(s)!
254 { 243 if (vkey == VK_SHIFT) {
255 iShiftIsPressed = iPressed; 244 iShiftIsPressed = iPressed;
256 } 245 }
257 246
258 if ((iShiftIsPressed) && (SDL_TranslateUNICODE)) 247 if ((iShiftIsPressed) && (SDL_TranslateUNICODE)) {
259 { 248 // Change syms, if Unicode stuff is required
260 // Change syms, if Unicode stuff is required 249 // I think it's silly, but it's SDL...
261 // I think it's silly, but it's SDL... 250 switch (keysym->sym) {
262 switch (keysym->sym) 251 case SDLK_BACKQUOTE:
263 { 252 keysym->sym = '~';
264 case SDLK_BACKQUOTE: 253 break;
265 keysym->sym = '~'; 254 case SDLK_1:
266 break; 255 keysym->sym = SDLK_EXCLAIM;
267 case SDLK_1: 256 break;
268 keysym->sym = SDLK_EXCLAIM; 257 case SDLK_2:
269 break; 258 keysym->sym = SDLK_AT;
270 case SDLK_2: 259 break;
271 keysym->sym = SDLK_AT; 260 case SDLK_3:
272 break; 261 keysym->sym = SDLK_HASH;
273 case SDLK_3: 262 break;
274 keysym->sym = SDLK_HASH; 263 case SDLK_4:
275 break; 264 keysym->sym = SDLK_DOLLAR;
276 case SDLK_4: 265 break;
277 keysym->sym = SDLK_DOLLAR; 266 case SDLK_5:
278 break; 267 keysym->sym = '%';
279 case SDLK_5: 268 break;
280 keysym->sym = '%'; 269 case SDLK_6:
281 break; 270 keysym->sym = SDLK_CARET;
282 case SDLK_6: 271 break;
283 keysym->sym = SDLK_CARET; 272 case SDLK_7:
284 break; 273 keysym->sym = SDLK_AMPERSAND;
285 case SDLK_7: 274 break;
286 keysym->sym = SDLK_AMPERSAND; 275 case SDLK_8:
287 break; 276 keysym->sym = SDLK_ASTERISK;
288 case SDLK_8: 277 break;
289 keysym->sym = SDLK_ASTERISK; 278 case SDLK_9:
290 break; 279 keysym->sym = SDLK_LEFTPAREN;
291 case SDLK_9: 280 break;
292 keysym->sym = SDLK_LEFTPAREN; 281 case SDLK_0:
293 break; 282 keysym->sym = SDLK_RIGHTPAREN;
294 case SDLK_0: 283 break;
295 keysym->sym = SDLK_RIGHTPAREN; 284 case SDLK_MINUS:
296 break; 285 keysym->sym = SDLK_UNDERSCORE;
297 case SDLK_MINUS: 286 break;
298 keysym->sym = SDLK_UNDERSCORE; 287 case SDLK_PLUS:
299 break; 288 keysym->sym = SDLK_EQUALS;
300 case SDLK_PLUS: 289 break;
301 keysym->sym = SDLK_EQUALS; 290
302 break; 291 case SDLK_LEFTBRACKET:
303 292 keysym->sym = '{';
304 case SDLK_LEFTBRACKET: 293 break;
305 keysym->sym = '{'; 294 case SDLK_RIGHTBRACKET:
306 break; 295 keysym->sym = '}';
307 case SDLK_RIGHTBRACKET: 296 break;
308 keysym->sym = '}'; 297
309 break; 298 case SDLK_SEMICOLON:
310 299 keysym->sym = SDLK_COLON;
311 case SDLK_SEMICOLON: 300 break;
312 keysym->sym = SDLK_COLON; 301 case SDLK_QUOTE:
313 break; 302 keysym->sym = SDLK_QUOTEDBL;
314 case SDLK_QUOTE: 303 break;
315 keysym->sym = SDLK_QUOTEDBL; 304 case SDLK_BACKSLASH:
316 break; 305 keysym->sym = '|';
317 case SDLK_BACKSLASH: 306 break;
318 keysym->sym = '|'; 307
319 break; 308 case SDLK_COMMA:
320 309 keysym->sym = SDLK_LESS;
321 case SDLK_COMMA: 310 break;
322 keysym->sym = SDLK_LESS; 311 case SDLK_PERIOD:
323 break; 312 keysym->sym = SDLK_GREATER;
324 case SDLK_PERIOD: 313 break;
325 keysym->sym = SDLK_GREATER; 314 case SDLK_SLASH:
326 break; 315 keysym->sym = SDLK_QUESTION;
327 case SDLK_SLASH: 316 break;
328 keysym->sym = SDLK_QUESTION; 317
329 break; 318 default:
330 319 break;
331 default: 320 }
332 break; 321 }
333 } 322 return keysym;
334 }
335 return keysym;
336 } 323 }
337 324
338 #define CONVERTMOUSEPOSITION() \ 325 #define CONVERTMOUSEPOSITION() \
339 /* We have to inverse the mouse position, because every non-os/2 system */ \ 326 /* We have to inverse the mouse position, because every non-os/2 system */ \
340 /* has a coordinate system where the (0;0) is the top-left corner, */ \ 327 /* has a coordinate system where the (0;0) is the top-left corner, */ \
377 // It handles switching back and away from the app (taking care of 364 // It handles switching back and away from the app (taking care of
378 // going out and back to and from fullscreen mode), sending keystrokes 365 // going out and back to and from fullscreen mode), sending keystrokes
379 // and mouse events to where it has to be sent, etc... 366 // and mouse events to where it has to be sent, etc...
380 // 367 //
381 ///////////////////////////////////////////////////////////////////// 368 /////////////////////////////////////////////////////////////////////
382 static MRESULT EXPENTRY WndProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) 369 static MRESULT EXPENTRY
383 { 370 WndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
384 HPS ps; 371 {
385 RECTL rcl; 372 HPS ps;
386 SDL_VideoDevice *pVideo = NULL; 373 RECTL rcl;
387 374 SDL_VideoDevice *pVideo = NULL;
388 switch (msg) 375
389 { 376 switch (msg) {
390 case WM_CHAR: // Keypress notification 377 case WM_CHAR: // Keypress notification
391 #ifdef DEBUG_BUILD 378 #ifdef DEBUG_BUILD
392 // printf("WM_CHAR\n"); fflush(stdout); 379 // printf("WM_CHAR\n"); fflush(stdout);
393 #endif 380 #endif
394 pVideo = WinQueryWindowPtr(hwnd, 0); 381 pVideo = WinQueryWindowPtr (hwnd, 0);
395 if (pVideo) 382 if (pVideo) {
396 { 383 /*
397 /* 384 // We skip repeated keys:
398 // We skip repeated keys: 385 if (CHARMSG(&msg)->cRepeat>1)
399 if (CHARMSG(&msg)->cRepeat>1) 386 {
387 #ifdef DEBUG_BUILD
388 // printf("Repeated key (%d), skipping...\n", CHARMSG(&msg)->cRepeat); fflush(stdout);
389 #endif
390 return (MRESULT) TRUE;
391 }
392 */
393
394 // If it's not repeated, then let's see if its pressed or released!
395 if (SHORT1FROMMP (mp1) & KC_KEYUP) {
396 // A key has been released
397 SDL_keysym keysym;
398
399 #ifdef DEBUG_BUILD
400 // printf("WM_CHAR, keyup, code is [0x%0x]\n", CHAR4FROMMP(mp1)); // HW scan code
401 #endif
402
403 // One problem is with F1, which gets only the keyup message because
404 // it is a system key.
405 // So, when we get keyup message, we simulate keydown too!
406 // UPDATE:
407 // This problem should be solved now, that the accelerator keys are
408 // disabled for this window!
409 /*
410 if (SHORT2FROMMP(mp2)==VK_F1)
411 {
412 SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(SHORT2FROMMP(mp2), // VK_ code
413 SHORT1FROMMP(mp2), // Character code
414 CHAR4FROMMP(mp1), // HW Scan code
415 &keysym,0));
416 } */
417
418 SDL_PrivateKeyboard (SDL_RELEASED, TranslateKey (SHORT2FROMMP (mp2), // VK_ code
419 SHORT1FROMMP (mp2), // Character code
420 CHAR4FROMMP (mp1), // HW Scan code
421 &keysym, 0));
422
423 } else {
424 // A key has been pressed
425 SDL_keysym keysym;
426
427 #ifdef DEBUG_BUILD
428 // printf("WM_CHAR, keydown, code is [0x%0x]\n", CHAR4FROMMP(mp1)); // HW scan code
429 #endif
430 // Check for fastkeys: ALT+HOME to toggle FS mode
431 // ALT+END to close app
432 if ((SHORT1FROMMP (mp1) & KC_ALT) &&
433 (SHORT2FROMMP (mp2) == VK_HOME)) {
434 #ifdef DEBUG_BUILD
435 printf (" Pressed ALT+HOME!\n");
436 fflush (stdout);
437 #endif
438 // Only switch between fullscreen and back if it's not
439 // a resizable mode!
440 if ((!pVideo->hidden->pSDLSurface) ||
441 ((pVideo->hidden->pSDLSurface)
442 &&
443 ((pVideo->hidden->pSDLSurface->
444 flags & SDL_RESIZABLE) == 0)))
445 FSLib_ToggleFSMode (hwnd, !FSLib_QueryFSMode (hwnd));
446 #ifdef DEBUG_BUILD
447 else
448 printf (" Resizable mode, so discarding ALT+HOME!\n");
449 fflush (stdout);
450 #endif
451 } else if ((SHORT1FROMMP (mp1) & KC_ALT) &&
452 (SHORT2FROMMP (mp2) == VK_END)) {
453 #ifdef DEBUG_BUILD
454 printf (" Pressed ALT+END!\n");
455 fflush (stdout);
456 #endif
457 // Close window, and get out of loop!
458 // Also send event to SDL application, but we won't
459 // wait for it to be processed!
460 SDL_PrivateQuit ();
461 WinPostMsg (hwnd, WM_QUIT, 0, 0);
462 } else {
463
464 SDL_PrivateKeyboard (SDL_PRESSED, TranslateKey (SHORT2FROMMP (mp2), // VK_ code
465 SHORT1FROMMP (mp2), // Character code
466 CHAR4FROMMP (mp1), // HW Scan code
467 &keysym,
468 1));
469
470 }
471 }
472 }
473 return (MRESULT) TRUE;
474
475 case WM_TRANSLATEACCEL:
400 { 476 {
401 #ifdef DEBUG_BUILD 477 PQMSG pqmsg;
402 // printf("Repeated key (%d), skipping...\n", CHARMSG(&msg)->cRepeat); fflush(stdout); 478 pqmsg = (PQMSG) mp1;
403 #endif 479 if (mp1) {
404 return (MRESULT) TRUE; 480 if (pqmsg->msg == WM_CHAR) {
405 } 481 // WM_CHAR message!
406 */ 482 // Let's filter the ALT keypress and all other acceleration keys!
407 483 return (MRESULT) FALSE;
408 // If it's not repeated, then let's see if its pressed or released! 484 }
409 if (SHORT1FROMMP(mp1) & KC_KEYUP) 485 }
486 break; // Default processing (pass to parent until frame control)
487 }
488
489 case WM_PAINT: // Window redraw!
490 #ifdef DEBUG_BUILD
491 printf ("WM_PAINT (0x%x)\n", hwnd);
492 fflush (stdout);
493 #endif
494 ps = WinBeginPaint (hwnd, 0, &rcl);
495 pVideo = FSLib_GetUserParm (hwnd);
496 if (pVideo) {
497 if (!pVideo->hidden->pSDLSurface) {
498 RECTL rclRect;
499 // So, don't blit now!
500 #ifdef DEBUG_BUILD
501 printf ("WM_PAINT : Skipping blit while resizing (Pre!)!\n");
502 fflush (stdout);
503 #endif
504 WinQueryWindowRect (hwnd, &rclRect);
505 // Fill with black
506 WinFillRect (ps, &rclRect, CLR_BLACK);
507 } else {
508 if (DosRequestMutexSem
509 (pVideo->hidden->hmtxUseSrcBuffer, 1000) == NO_ERROR) {
510 int iTop, iLeft, iWidth, iHeight;
511 int iXScaleError, iYScaleError;
512 int iXScaleError2, iYScaleError2;
513 SWP swp;
514
515 // Re-blit the modified area!
516 // For this, we have to calculate the points, scaled!
517 WinQueryWindowPos (hwnd, &swp);
518 #ifdef DEBUG_BUILD
519 printf
520 ("WM_PAINT : WinSize: %d %d, BufSize: %d %d\n",
521 swp.cx, swp.cy,
522 pVideo->hidden->SrcBufferDesc.uiXResolution,
523 pVideo->hidden->SrcBufferDesc.uiYResolution);
524 fflush (stdout);
525 #endif
526
527 #ifndef RESIZE_EVEN_IF_RESIZABLE
528 // But only blit if the window is not resizable, or if
529 // the window is resizable and the source buffer size is the
530 // same as the destination buffer size!
531 if ((!pVideo->hidden->pSDLSurface) ||
532 ((pVideo->hidden->pSDLSurface) &&
533 (pVideo->hidden->pSDLSurface->flags & SDL_RESIZABLE)
534 &&
535 ((swp.cx !=
536 pVideo->hidden->SrcBufferDesc.uiXResolution)
537 || (swp.cy !=
538 pVideo->hidden->SrcBufferDesc.uiYResolution))
539 && (!FSLib_QueryFSMode (hwnd)))) {
540 RECTL rclRect;
541 // Resizable surface and in resizing!
542 // So, don't blit now!
543 #ifdef DEBUG_BUILD
544 printf ("WM_PAINT : Skipping blit while resizing!\n");
545 fflush (stdout);
546 #endif
547 WinQueryWindowRect (hwnd, &rclRect);
548 // Fill with black
549 WinFillRect (ps, &rclRect, CLR_BLACK);
550 } else
551 #endif
552 {
553
554 iXScaleError =
555 (pVideo->hidden->SrcBufferDesc.
556 uiXResolution - 1) / swp.cx;
557 iYScaleError =
558 (pVideo->hidden->SrcBufferDesc.
559 uiYResolution - 1) / swp.cy;
560 if (iXScaleError < 0)
561 iXScaleError = 0;
562 if (iYScaleError < 0)
563 iYScaleError = 0;
564 iXScaleError2 =
565 (swp.cx -
566 1) /
567 (pVideo->hidden->SrcBufferDesc.uiXResolution);
568 iYScaleError2 =
569 (swp.cy -
570 1) /
571 (pVideo->hidden->SrcBufferDesc.uiYResolution);
572 if (iXScaleError2 < 0)
573 iXScaleError2 = 0;
574 if (iYScaleError2 < 0)
575 iYScaleError2 = 0;
576
577 iTop =
578 (swp.cy -
579 rcl.yTop) *
580 pVideo->hidden->SrcBufferDesc.
581 uiYResolution / swp.cy - iYScaleError;
582 iLeft =
583 rcl.xLeft *
584 pVideo->hidden->SrcBufferDesc.
585 uiXResolution / swp.cx - iXScaleError;
586 iWidth =
587 ((rcl.xRight -
588 rcl.xLeft) *
589 pVideo->hidden->SrcBufferDesc.
590 uiXResolution + swp.cx - 1) / swp.cx +
591 2 * iXScaleError;
592 iHeight =
593 ((rcl.yTop -
594 rcl.yBottom) *
595 pVideo->hidden->SrcBufferDesc.
596 uiYResolution + swp.cy - 1) / swp.cy +
597 2 * iYScaleError;
598
599 iWidth += iXScaleError2;
600 iHeight += iYScaleError2;
601
602 if (iTop < 0)
603 iTop = 0;
604 if (iLeft < 0)
605 iLeft = 0;
606 if (iTop + iHeight >
607 pVideo->hidden->SrcBufferDesc.uiYResolution)
608 iHeight =
609 pVideo->hidden->SrcBufferDesc.
610 uiYResolution - iTop;
611 if (iLeft + iWidth >
612 pVideo->hidden->SrcBufferDesc.uiXResolution)
613 iWidth =
614 pVideo->hidden->SrcBufferDesc.
615 uiXResolution - iLeft;
616
617 #ifdef DEBUG_BUILD
618 printf
619 ("WM_PAINT : BitBlt: %d %d -> %d %d (Buf %d x %d)\n",
620 iTop, iLeft, iWidth, iHeight,
621 pVideo->hidden->SrcBufferDesc.
622 uiXResolution,
623 pVideo->hidden->SrcBufferDesc.uiYResolution);
624 fflush (stdout);
625 #endif
626
627 FSLIB_BITBLT (hwnd,
628 pVideo->hidden->pchSrcBuffer,
629 iTop, iLeft, iWidth, iHeight);
630 }
631
632 DosReleaseMutexSem (pVideo->hidden->hmtxUseSrcBuffer);
633 }
634 }
635 }
636 #ifdef DEBUG_BUILD
637 else {
638 printf ("WM_PAINT : No pVideo!\n");
639 fflush (stdout);
640 }
641 #endif
642 WinEndPaint (ps);
643 #ifdef DEBUG_BUILD
644 printf ("WM_PAINT : Done.\n");
645 fflush (stdout);
646 #endif
647 return 0;
648
649 case WM_SIZE:
410 { 650 {
411 // A key has been released 651 #ifdef DEBUG_BUILD
412 SDL_keysym keysym; 652 printf ("WM_SIZE : (%d %d)\n",
413 653 SHORT1FROMMP (mp2), SHORT2FROMMP (mp2));
414 #ifdef DEBUG_BUILD 654 fflush (stdout);
415 // printf("WM_CHAR, keyup, code is [0x%0x]\n", CHAR4FROMMP(mp1)); // HW scan code 655 #endif
416 #endif 656 iWindowSizeX = SHORT1FROMMP (mp2);
417 657 iWindowSizeY = SHORT2FROMMP (mp2);
418 // One problem is with F1, which gets only the keyup message because 658 bWindowResized = 1;
419 // it is a system key. 659
420 // So, when we get keyup message, we simulate keydown too! 660 // Make sure the window will be redrawn
421 // UPDATE: 661 WinInvalidateRegion (hwnd, NULL, TRUE);
422 // This problem should be solved now, that the accelerator keys are 662 }
423 // disabled for this window! 663 break;
424 /* 664
425 if (SHORT2FROMMP(mp2)==VK_F1) 665 case WM_FSLIBNOTIFICATION:
426 { 666 #ifdef DEBUG_BUILD
427 SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(SHORT2FROMMP(mp2), // VK_ code 667 printf ("WM_FSLIBNOTIFICATION\n");
428 SHORT1FROMMP(mp2), // Character code 668 fflush (stdout);
429 CHAR4FROMMP(mp1), // HW Scan code 669 #endif
430 &keysym,0)); 670 if ((int) mp1 == FSLN_TOGGLEFSMODE) {
431 }*/ 671 // FS mode changed, reblit image!
432 672 pVideo = FSLib_GetUserParm (hwnd);
433 SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(SHORT2FROMMP(mp2), // VK_ code 673 if (pVideo) {
434 SHORT1FROMMP(mp2), // Character code 674 if (!pVideo->hidden->pSDLSurface) {
435 CHAR4FROMMP(mp1), // HW Scan code 675 // Resizable surface and in resizing!
436 &keysym,0)); 676 // So, don't blit now!
437 677 #ifdef DEBUG_BUILD
438 } else 678 printf
439 { 679 ("WM_FSLIBNOTIFICATION : Can not blit if there is no surface, doing nothing.\n");
440 // A key has been pressed 680 fflush (stdout);
441 SDL_keysym keysym; 681 #endif
442 682 } else {
443 #ifdef DEBUG_BUILD 683 if (DosRequestMutexSem
444 // printf("WM_CHAR, keydown, code is [0x%0x]\n", CHAR4FROMMP(mp1)); // HW scan code 684 (pVideo->hidden->hmtxUseSrcBuffer,
445 #endif 685 1000) == NO_ERROR) {
446 // Check for fastkeys: ALT+HOME to toggle FS mode 686 if (pVideo->hidden->pSDLSurface) {
447 // ALT+END to close app
448 if ((SHORT1FROMMP(mp1) & KC_ALT) &&
449 (SHORT2FROMMP(mp2) == VK_HOME))
450 {
451 #ifdef DEBUG_BUILD
452 printf(" Pressed ALT+HOME!\n"); fflush(stdout);
453 #endif
454 // Only switch between fullscreen and back if it's not
455 // a resizable mode!
456 if (
457 (!pVideo->hidden->pSDLSurface) ||
458 ((pVideo->hidden->pSDLSurface)
459 && ((pVideo->hidden->pSDLSurface->flags & SDL_RESIZABLE)==0)
460 )
461 )
462 FSLib_ToggleFSMode(hwnd, !FSLib_QueryFSMode(hwnd));
463 #ifdef DEBUG_BUILD
464 else
465 printf(" Resizable mode, so discarding ALT+HOME!\n"); fflush(stdout);
466 #endif
467 } else
468 if ((SHORT1FROMMP(mp1) & KC_ALT) &&
469 (SHORT2FROMMP(mp2) == VK_END))
470 {
471 #ifdef DEBUG_BUILD
472 printf(" Pressed ALT+END!\n"); fflush(stdout);
473 #endif
474 // Close window, and get out of loop!
475 // Also send event to SDL application, but we won't
476 // wait for it to be processed!
477 SDL_PrivateQuit();
478 WinPostMsg(hwnd, WM_QUIT, 0, 0);
479 } else
480 {
481
482 SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(SHORT2FROMMP(mp2), // VK_ code
483 SHORT1FROMMP(mp2), // Character code
484 CHAR4FROMMP(mp1), // HW Scan code
485 &keysym,1));
486
487 }
488 }
489 }
490 return (MRESULT) TRUE;
491
492 case WM_TRANSLATEACCEL:
493 {
494 PQMSG pqmsg;
495 pqmsg = (PQMSG) mp1;
496 if (mp1)
497 {
498 if (pqmsg->msg == WM_CHAR)
499 {
500 // WM_CHAR message!
501 // Let's filter the ALT keypress and all other acceleration keys!
502 return (MRESULT) FALSE;
503 }
504 }
505 break; // Default processing (pass to parent until frame control)
506 }
507
508 case WM_PAINT: // Window redraw!
509 #ifdef DEBUG_BUILD
510 printf("WM_PAINT (0x%x)\n", hwnd); fflush(stdout);
511 #endif
512 ps = WinBeginPaint(hwnd,0,&rcl);
513 pVideo = FSLib_GetUserParm(hwnd);
514 if (pVideo)
515 {
516 if (!pVideo->hidden->pSDLSurface)
517 {
518 RECTL rclRect;
519 // So, don't blit now!
520 #ifdef DEBUG_BUILD
521 printf("WM_PAINT : Skipping blit while resizing (Pre!)!\n"); fflush(stdout);
522 #endif
523 WinQueryWindowRect(hwnd, &rclRect);
524 // Fill with black
525 WinFillRect(ps, &rclRect, CLR_BLACK);
526 } else
527 {
528 if (DosRequestMutexSem(pVideo->hidden->hmtxUseSrcBuffer, 1000)==NO_ERROR)
529 {
530 int iTop, iLeft, iWidth, iHeight;
531 int iXScaleError, iYScaleError;
532 int iXScaleError2, iYScaleError2;
533 SWP swp;
534
535 // Re-blit the modified area!
536 // For this, we have to calculate the points, scaled!
537 WinQueryWindowPos(hwnd, &swp);
538 #ifdef DEBUG_BUILD
539 printf("WM_PAINT : WinSize: %d %d, BufSize: %d %d\n",
540 swp.cx,
541 swp.cy,
542 pVideo->hidden->SrcBufferDesc.uiXResolution,
543 pVideo->hidden->SrcBufferDesc.uiYResolution
544 );
545 fflush(stdout);
546 #endif
547
548 #ifndef RESIZE_EVEN_IF_RESIZABLE 687 #ifndef RESIZE_EVEN_IF_RESIZABLE
549 // But only blit if the window is not resizable, or if 688 SWP swp;
550 // the window is resizable and the source buffer size is the 689
551 // same as the destination buffer size! 690 // But only blit if the window is not resizable, or if
552 if ((!pVideo->hidden->pSDLSurface) || 691 // the window is resizable and the source buffer size is the
553 ((pVideo->hidden->pSDLSurface) && 692 // same as the destination buffer size!
554 (pVideo->hidden->pSDLSurface->flags & SDL_RESIZABLE) && 693 WinQueryWindowPos (hwnd, &swp);
555 ((swp.cx != pVideo->hidden->SrcBufferDesc.uiXResolution) || 694 if ((!pVideo->hidden->pSDLSurface) ||
556 (swp.cy != pVideo->hidden->SrcBufferDesc.uiYResolution) 695 ((pVideo->hidden->pSDLSurface) &&
557 ) && 696 (pVideo->hidden->pSDLSurface->
558 (!FSLib_QueryFSMode(hwnd)) 697 flags & SDL_RESIZABLE)
559 ) 698 &&
560 ) 699 ((swp.cx !=
561 { 700 pVideo->hidden->SrcBufferDesc.
562 RECTL rclRect; 701 uiXResolution)
563 // Resizable surface and in resizing! 702 || (swp.cy !=
564 // So, don't blit now! 703 pVideo->hidden->
565 #ifdef DEBUG_BUILD 704 SrcBufferDesc.uiYResolution))
566 printf("WM_PAINT : Skipping blit while resizing!\n"); fflush(stdout); 705 && (!FSLib_QueryFSMode (hwnd)))) {
567 #endif 706 // Resizable surface and in resizing!
568 WinQueryWindowRect(hwnd, &rclRect); 707 // So, don't blit now!
569 // Fill with black 708 #ifdef DEBUG_BUILD
570 WinFillRect(ps, &rclRect, CLR_BLACK); 709 printf
571 } else 710 ("WM_FSLIBNOTIFICATION : Cannot blit while resizing, doing nothing.\n");
572 #endif 711 fflush (stdout);
573 { 712 #endif
574 713 } else
575 iXScaleError = (pVideo->hidden->SrcBufferDesc.uiXResolution-1) / swp.cx; 714 #endif
576 iYScaleError = (pVideo->hidden->SrcBufferDesc.uiYResolution-1) / swp.cy; 715 {
577 if (iXScaleError<0) iXScaleError = 0; 716 #ifdef DEBUG_BUILD
578 if (iYScaleError<0) iYScaleError = 0; 717 printf ("WM_FSLIBNOTIFICATION : Blitting!\n");
579 iXScaleError2 = (swp.cx-1)/(pVideo->hidden->SrcBufferDesc.uiXResolution); 718 fflush (stdout);
580 iYScaleError2 = (swp.cy-1)/(pVideo->hidden->SrcBufferDesc.uiYResolution); 719 #endif
581 if (iXScaleError2<0) iXScaleError2 = 0; 720 FSLIB_BITBLT (hwnd,
582 if (iYScaleError2<0) iYScaleError2 = 0; 721 pVideo->hidden->
583 722 pchSrcBuffer, 0,
584 iTop = (swp.cy - rcl.yTop) * pVideo->hidden->SrcBufferDesc.uiYResolution / swp.cy - iYScaleError; 723 0,
585 iLeft = rcl.xLeft * pVideo->hidden->SrcBufferDesc.uiXResolution / swp.cx - iXScaleError; 724 pVideo->hidden->
586 iWidth = ((rcl.xRight-rcl.xLeft) * pVideo->hidden->SrcBufferDesc.uiXResolution + swp.cx-1) 725 SrcBufferDesc.
587 / swp.cx + 2*iXScaleError; 726 uiXResolution,
588 iHeight = ((rcl.yTop-rcl.yBottom) * pVideo->hidden->SrcBufferDesc.uiYResolution + swp.cy-1) 727 pVideo->hidden->
589 / swp.cy + 2*iYScaleError; 728 SrcBufferDesc.uiYResolution);
590 729 }
591 iWidth+=iXScaleError2; 730 }
592 iHeight+=iYScaleError2; 731 #ifdef DEBUG_BUILD
593 732 else
594 if (iTop<0) iTop = 0; 733 printf
595 if (iLeft<0) iLeft = 0; 734 ("WM_FSLIBNOTIFICATION : No public surface!\n");
596 if (iTop+iHeight>pVideo->hidden->SrcBufferDesc.uiYResolution) iHeight = pVideo->hidden->SrcBufferDesc.uiYResolution-iTop; 735 fflush (stdout);
597 if (iLeft+iWidth>pVideo->hidden->SrcBufferDesc.uiXResolution) iWidth = pVideo->hidden->SrcBufferDesc.uiXResolution-iLeft; 736 #endif
598 737
599 #ifdef DEBUG_BUILD 738 DosReleaseMutexSem (pVideo->hidden->hmtxUseSrcBuffer);
600 printf("WM_PAINT : BitBlt: %d %d -> %d %d (Buf %d x %d)\n", 739 }
601 iTop, iLeft, iWidth, iHeight, 740 }
602 pVideo->hidden->SrcBufferDesc.uiXResolution,
603 pVideo->hidden->SrcBufferDesc.uiYResolution
604 );
605 fflush(stdout);
606 #endif
607
608 FSLIB_BITBLT(hwnd, pVideo->hidden->pchSrcBuffer, iTop, iLeft, iWidth, iHeight);
609 } 741 }
610 742 }
611 DosReleaseMutexSem(pVideo->hidden->hmtxUseSrcBuffer); 743 return (MPARAM) 1;
612 } 744
613 } 745 case WM_ACTIVATE:
614 } 746 #ifdef DEBUG_BUILD
615 #ifdef DEBUG_BUILD 747 printf ("WM_ACTIVATE\n");
616 else 748 fflush (stdout);
617 { 749 #endif
618 printf("WM_PAINT : No pVideo!\n"); fflush(stdout); 750
619 } 751 pVideo = FSLib_GetUserParm (hwnd);
620 #endif 752 if (pVideo) {
621 WinEndPaint(ps); 753 pVideo->hidden->fInFocus = (int) mp1;
622 #ifdef DEBUG_BUILD 754 if (pVideo->hidden->fInFocus) {
623 printf("WM_PAINT : Done.\n"); 755 // Went into focus
624 fflush(stdout); 756 if ((pVideo->hidden->iMouseVisible)
625 #endif 757 && (!bMouseCaptured))
626 return 0; 758 WinSetPointer (HWND_DESKTOP,
627 759 WinQuerySysPointer (HWND_DESKTOP,
628 case WM_SIZE: 760 SPTR_ARROW, FALSE));
629 { 761 else
630 #ifdef DEBUG_BUILD 762 WinSetPointer (HWND_DESKTOP, NULL);
631 printf("WM_SIZE : (%d %d)\n", 763
632 SHORT1FROMMP(mp2), SHORT2FROMMP(mp2)); fflush(stdout); 764 if (bMouseCapturable) {
633 #endif 765 // Re-capture the mouse, if we captured it before!
634 iWindowSizeX = SHORT1FROMMP(mp2); 766 WinSetCapture (HWND_DESKTOP, hwnd);
635 iWindowSizeY = SHORT2FROMMP(mp2); 767 bMouseCaptured = 1;
636 bWindowResized = 1; 768 {
637 769 SWP swpClient;
638 // Make sure the window will be redrawn 770 POINTL ptl;
639 WinInvalidateRegion(hwnd, NULL, TRUE); 771 // Center the mouse to the middle of the window!
640 } 772 WinQueryWindowPos (pVideo->hidden->hwndClient,
641 break; 773 &swpClient);
642 774 ptl.x = 0;
643 case WM_FSLIBNOTIFICATION: 775 ptl.y = 0;
644 #ifdef DEBUG_BUILD 776 WinMapWindowPoints (pVideo->hidden->
645 printf("WM_FSLIBNOTIFICATION\n"); fflush(stdout); 777 hwndClient, HWND_DESKTOP,
646 #endif 778 &ptl, 1);
647 if ((int)mp1 == FSLN_TOGGLEFSMODE) 779 pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
648 { 780 WinSetPointerPos (HWND_DESKTOP,
649 // FS mode changed, reblit image! 781 ptl.x + swpClient.cx / 2,
650 pVideo = FSLib_GetUserParm(hwnd); 782 ptl.y + swpClient.cy / 2);
651 if (pVideo) 783 }
652 {
653 if (!pVideo->hidden->pSDLSurface)
654 {
655 // Resizable surface and in resizing!
656 // So, don't blit now!
657 #ifdef DEBUG_BUILD
658 printf("WM_FSLIBNOTIFICATION : Can not blit if there is no surface, doing nothing.\n"); fflush(stdout);
659 #endif
660 } else
661 {
662 if (DosRequestMutexSem(pVideo->hidden->hmtxUseSrcBuffer, 1000)==NO_ERROR)
663 {
664 if (pVideo->hidden->pSDLSurface)
665 {
666 #ifndef RESIZE_EVEN_IF_RESIZABLE
667 SWP swp;
668
669 // But only blit if the window is not resizable, or if
670 // the window is resizable and the source buffer size is the
671 // same as the destination buffer size!
672 WinQueryWindowPos(hwnd, &swp);
673 if ((!pVideo->hidden->pSDLSurface) ||
674 (
675 (pVideo->hidden->pSDLSurface) &&
676 (pVideo->hidden->pSDLSurface->flags & SDL_RESIZABLE) &&
677 ((swp.cx != pVideo->hidden->SrcBufferDesc.uiXResolution) ||
678 (swp.cy != pVideo->hidden->SrcBufferDesc.uiYResolution)
679 ) &&
680 (!FSLib_QueryFSMode(hwnd))
681 )
682 )
683 {
684 // Resizable surface and in resizing!
685 // So, don't blit now!
686 #ifdef DEBUG_BUILD
687 printf("WM_FSLIBNOTIFICATION : Cannot blit while resizing, doing nothing.\n"); fflush(stdout);
688 #endif
689 } else
690 #endif
691 {
692 #ifdef DEBUG_BUILD
693 printf("WM_FSLIBNOTIFICATION : Blitting!\n"); fflush(stdout);
694 #endif
695 FSLIB_BITBLT(hwnd, pVideo->hidden->pchSrcBuffer,
696 0, 0,
697 pVideo->hidden->SrcBufferDesc.uiXResolution,
698 pVideo->hidden->SrcBufferDesc.uiYResolution);
699 } 784 }
700 } 785 } else {
701 #ifdef DEBUG_BUILD 786 // Went out of focus
702 else 787 WinSetPointer (HWND_DESKTOP,
703 printf("WM_FSLIBNOTIFICATION : No public surface!\n"); fflush(stdout); 788 WinQuerySysPointer (HWND_DESKTOP,
704 #endif 789 SPTR_ARROW, FALSE));
705 790
706 DosReleaseMutexSem(pVideo->hidden->hmtxUseSrcBuffer); 791 if (bMouseCaptured) {
792 // Release the mouse
793 WinSetCapture (HWND_DESKTOP, hwnd);
794 bMouseCaptured = 0;
795 }
707 } 796 }
708 } 797 }
709 } 798 #ifdef DEBUG_BUILD
710 } 799 printf ("WM_ACTIVATE done\n");
711 return (MPARAM) 1; 800 fflush (stdout);
712 801 #endif
713 case WM_ACTIVATE: 802
714 #ifdef DEBUG_BUILD 803 break;
715 printf("WM_ACTIVATE\n"); fflush(stdout); 804
716 #endif 805 case WM_BUTTON1DOWN:
717 806 #ifdef DEBUG_BUILD
718 pVideo = FSLib_GetUserParm(hwnd); 807 printf ("WM_BUTTON1DOWN\n");
719 if (pVideo) 808 fflush (stdout);
720 { 809 #endif
721 pVideo->hidden->fInFocus = (int) mp1; 810
722 if (pVideo->hidden->fInFocus) 811 pVideo = FSLib_GetUserParm (hwnd);
723 { 812 if (pVideo) {
724 // Went into focus 813 SDL_PrivateMouseButton (SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0); // Don't report mouse movement!
725 if ((pVideo->hidden->iMouseVisible) && (!bMouseCaptured)) 814
726 WinSetPointer(HWND_DESKTOP, WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE)); 815 if (bMouseCapturable) {
727 else 816 // We should capture the mouse!
728 WinSetPointer(HWND_DESKTOP, NULL); 817 if (!bMouseCaptured) {
729 818 WinSetCapture (HWND_DESKTOP, hwnd);
730 if (bMouseCapturable) 819 WinSetPointer (HWND_DESKTOP, NULL);
731 { 820 bMouseCaptured = 1;
732 // Re-capture the mouse, if we captured it before! 821 {
733 WinSetCapture(HWND_DESKTOP, hwnd); 822 SWP swpClient;
734 bMouseCaptured = 1; 823 POINTL ptl;
735 { 824 // Center the mouse to the middle of the window!
736 SWP swpClient; 825 WinQueryWindowPos (pVideo->hidden->hwndClient,
737 POINTL ptl; 826 &swpClient);
738 // Center the mouse to the middle of the window! 827 ptl.x = 0;
739 WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient); 828 ptl.y = 0;
740 ptl.x = 0; ptl.y = 0; 829 WinMapWindowPoints (pVideo->hidden->
741 WinMapWindowPoints(pVideo->hidden->hwndClient, HWND_DESKTOP, &ptl, 1); 830 hwndClient, HWND_DESKTOP,
742 pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */ 831 &ptl, 1);
743 WinSetPointerPos(HWND_DESKTOP, 832 pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
744 ptl.x + swpClient.cx/2, 833 WinSetPointerPos (HWND_DESKTOP,
745 ptl.y + swpClient.cy/2); 834 ptl.x + swpClient.cx / 2,
835 ptl.y + swpClient.cy / 2);
836 }
837 }
746 } 838 }
747 } 839 }
748 } else 840 break;
749 { 841 case WM_BUTTON1UP:
750 // Went out of focus 842 #ifdef DEBUG_BUILD
751 WinSetPointer(HWND_DESKTOP, WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE)); 843 printf ("WM_BUTTON1UP\n");
752 844 fflush (stdout);
753 if (bMouseCaptured) 845 #endif
754 { 846 SDL_PrivateMouseButton (SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0); // Don't report mouse movement!
755 // Release the mouse 847 break;
756 WinSetCapture(HWND_DESKTOP, hwnd); 848 case WM_BUTTON2DOWN:
757 bMouseCaptured = 0; 849 #ifdef DEBUG_BUILD
758 } 850 printf ("WM_BUTTON2DOWN\n");
759 } 851 fflush (stdout);
760 } 852 #endif
761 #ifdef DEBUG_BUILD 853
762 printf("WM_ACTIVATE done\n"); fflush(stdout); 854 pVideo = FSLib_GetUserParm (hwnd);
763 #endif 855 if (pVideo) {
764 856 SDL_PrivateMouseButton (SDL_PRESSED, SDL_BUTTON_RIGHT, 0, 0); // Don't report mouse movement!
765 break; 857
766 858 if (bMouseCapturable) {
767 case WM_BUTTON1DOWN: 859 // We should capture the mouse!
768 #ifdef DEBUG_BUILD 860 if (!bMouseCaptured) {
769 printf("WM_BUTTON1DOWN\n"); fflush(stdout); 861 WinSetCapture (HWND_DESKTOP, hwnd);
770 #endif 862 WinSetPointer (HWND_DESKTOP, NULL);
771 863 bMouseCaptured = 1;
772 pVideo = FSLib_GetUserParm(hwnd); 864 {
773 if (pVideo) 865 SWP swpClient;
774 { 866 POINTL ptl;
775 SDL_PrivateMouseButton(SDL_PRESSED, 867 // Center the mouse to the middle of the window!
776 SDL_BUTTON_LEFT, 868 WinQueryWindowPos (pVideo->hidden->hwndClient,
777 0, 0); // Don't report mouse movement! 869 &swpClient);
778 870 ptl.x = 0;
779 if (bMouseCapturable) 871 ptl.y = 0;
780 { 872 WinMapWindowPoints (pVideo->hidden->
781 // We should capture the mouse! 873 hwndClient, HWND_DESKTOP,
782 if (!bMouseCaptured) 874 &ptl, 1);
783 { 875 pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
784 WinSetCapture(HWND_DESKTOP, hwnd); 876 WinSetPointerPos (HWND_DESKTOP,
785 WinSetPointer(HWND_DESKTOP, NULL); 877 ptl.x + swpClient.cx / 2,
786 bMouseCaptured = 1; 878 ptl.y + swpClient.cy / 2);
787 { 879 }
788 SWP swpClient; 880 }
789 POINTL ptl;
790 // Center the mouse to the middle of the window!
791 WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient);
792 ptl.x = 0; ptl.y = 0;
793 WinMapWindowPoints(pVideo->hidden->hwndClient, HWND_DESKTOP, &ptl, 1);
794 pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
795 WinSetPointerPos(HWND_DESKTOP,
796 ptl.x + swpClient.cx/2,
797 ptl.y + swpClient.cy/2);
798 } 881 }
799 } 882
800 } 883 }
801 } 884 break;
802 break; 885 case WM_BUTTON2UP:
803 case WM_BUTTON1UP: 886 #ifdef DEBUG_BUILD
804 #ifdef DEBUG_BUILD 887 printf ("WM_BUTTON2UP\n");
805 printf("WM_BUTTON1UP\n"); fflush(stdout); 888 fflush (stdout);
806 #endif 889 #endif
807 SDL_PrivateMouseButton(SDL_RELEASED, 890 SDL_PrivateMouseButton (SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0); // Don't report mouse movement!
808 SDL_BUTTON_LEFT, 891 break;
809 0, 0); // Don't report mouse movement! 892 case WM_BUTTON3DOWN:
810 break; 893 #ifdef DEBUG_BUILD
811 case WM_BUTTON2DOWN: 894 printf ("WM_BUTTON3DOWN\n");
812 #ifdef DEBUG_BUILD 895 fflush (stdout);
813 printf("WM_BUTTON2DOWN\n"); fflush(stdout); 896 #endif
814 #endif 897
815 898 pVideo = FSLib_GetUserParm (hwnd);
816 pVideo = FSLib_GetUserParm(hwnd); 899 if (pVideo) {
817 if (pVideo) 900 SDL_PrivateMouseButton (SDL_PRESSED, SDL_BUTTON_MIDDLE, 0, 0); // Don't report mouse movement!
818 { 901
819 SDL_PrivateMouseButton(SDL_PRESSED, 902 if (bMouseCapturable) {
820 SDL_BUTTON_RIGHT, 903 // We should capture the mouse!
821 0, 0); // Don't report mouse movement! 904 if (!bMouseCaptured) {
822 905 WinSetCapture (HWND_DESKTOP, hwnd);
823 if (bMouseCapturable) 906 WinSetPointer (HWND_DESKTOP, NULL);
824 { 907 bMouseCaptured = 1;
825 // We should capture the mouse! 908 {
826 if (!bMouseCaptured) 909 SWP swpClient;
827 { 910 POINTL ptl;
828 WinSetCapture(HWND_DESKTOP, hwnd); 911 // Center the mouse to the middle of the window!
829 WinSetPointer(HWND_DESKTOP, NULL); 912 WinQueryWindowPos (pVideo->hidden->hwndClient,
830 bMouseCaptured = 1; 913 &swpClient);
831 { 914 ptl.x = 0;
832 SWP swpClient; 915 ptl.y = 0;
833 POINTL ptl; 916 WinMapWindowPoints (pVideo->hidden->
834 // Center the mouse to the middle of the window! 917 hwndClient, HWND_DESKTOP,
835 WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient); 918 &ptl, 1);
836 ptl.x = 0; ptl.y = 0; 919 pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
837 WinMapWindowPoints(pVideo->hidden->hwndClient, HWND_DESKTOP, &ptl, 1); 920 WinSetPointerPos (HWND_DESKTOP,
838 pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */ 921 ptl.x + swpClient.cx / 2,
839 WinSetPointerPos(HWND_DESKTOP, 922 ptl.y + swpClient.cy / 2);
840 ptl.x + swpClient.cx/2, 923 }
841 ptl.y + swpClient.cy/2); 924 }
842 } 925 }
843 } 926 }
844 } 927 break;
845 928 case WM_BUTTON3UP:
846 } 929 #ifdef DEBUG_BUILD
847 break; 930 printf ("WM_BUTTON3UP\n");
848 case WM_BUTTON2UP: 931 fflush (stdout);
849 #ifdef DEBUG_BUILD 932 #endif
850 printf("WM_BUTTON2UP\n"); fflush(stdout); 933 SDL_PrivateMouseButton (SDL_RELEASED, SDL_BUTTON_MIDDLE, 0, 0); // Don't report mouse movement!
851 #endif 934 break;
852 SDL_PrivateMouseButton(SDL_RELEASED, 935 case WM_MOUSEMOVE:
853 SDL_BUTTON_RIGHT, 936 #ifdef DEBUG_BUILD
854 0, 0); // Don't report mouse movement! 937 // printf("WM_MOUSEMOVE\n"); fflush(stdout);
855 break; 938 #endif
856 case WM_BUTTON3DOWN: 939
857 #ifdef DEBUG_BUILD 940 pVideo = FSLib_GetUserParm (hwnd);
858 printf("WM_BUTTON3DOWN\n"); fflush(stdout); 941 if (pVideo) {
859 #endif 942 if (pVideo->hidden->iSkipWMMOUSEMOVE) {
860 943 pVideo->hidden->iSkipWMMOUSEMOVE--;
861 pVideo = FSLib_GetUserParm(hwnd); 944 } else {
862 if (pVideo) 945 POINTS *ppts = (POINTS *) (&mp1);
863 { 946 POINTL ptl;
864 SDL_PrivateMouseButton(SDL_PRESSED, 947
865 SDL_BUTTON_MIDDLE, 948 if (bMouseCaptured) {
866 0, 0); // Don't report mouse movement! 949 SWP swpClient;
867 950
868 if (bMouseCapturable) 951 WinQueryWindowPos (pVideo->hidden->hwndClient,
869 { 952 &swpClient);
870 // We should capture the mouse! 953
871 if (!bMouseCaptured) 954 // Send relative mouse position, and re-center the mouse
872 { 955 // Reposition the mouse to the center of the screen/window
873 WinSetCapture(HWND_DESKTOP, hwnd); 956 SDL_PrivateMouseMotion (0, // Buttons not changed
874 WinSetPointer(HWND_DESKTOP, NULL); 957 1, // Relative position
875 bMouseCaptured = 1; 958 ppts->x -
876 { 959 (swpClient.cx / 2),
877 SWP swpClient; 960 (swpClient.cy / 2) - ppts->y);
878 POINTL ptl; 961
879 // Center the mouse to the middle of the window! 962 ptl.x = 0;
880 WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient); 963 ptl.y = 0;
881 ptl.x = 0; ptl.y = 0; 964 WinMapWindowPoints (pVideo->hidden->hwndClient,
882 WinMapWindowPoints(pVideo->hidden->hwndClient, HWND_DESKTOP, &ptl, 1); 965 HWND_DESKTOP, &ptl, 1);
883 pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */ 966 pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
884 WinSetPointerPos(HWND_DESKTOP, 967 // Center the mouse to the middle of the window!
885 ptl.x + swpClient.cx/2, 968 WinSetPointerPos (HWND_DESKTOP,
886 ptl.y + swpClient.cy/2); 969 ptl.x + swpClient.cx / 2,
970 ptl.y + swpClient.cy / 2);
971 } else {
972 CONVERTMOUSEPOSITION ();
973
974 // Send absolute mouse position
975 SDL_PrivateMouseMotion (0, // Buttons not changed
976 0, // Absolute position
977 ppts->x, ppts->y);
978 }
887 } 979 }
888 } 980 if ((pVideo->hidden->iMouseVisible) && (!bMouseCaptured)) {
889 }
890 }
891 break;
892 case WM_BUTTON3UP:
893 #ifdef DEBUG_BUILD
894 printf("WM_BUTTON3UP\n"); fflush(stdout);
895 #endif
896 SDL_PrivateMouseButton(SDL_RELEASED,
897 SDL_BUTTON_MIDDLE,
898 0, 0); // Don't report mouse movement!
899 break;
900 case WM_MOUSEMOVE:
901 #ifdef DEBUG_BUILD
902 // printf("WM_MOUSEMOVE\n"); fflush(stdout);
903 #endif
904
905 pVideo = FSLib_GetUserParm(hwnd);
906 if (pVideo)
907 {
908 if (pVideo->hidden->iSkipWMMOUSEMOVE)
909 {
910 pVideo->hidden->iSkipWMMOUSEMOVE--;
911 } else
912 {
913 POINTS *ppts = (POINTS *) (&mp1);
914 POINTL ptl;
915
916 if (bMouseCaptured)
917 {
918 SWP swpClient;
919
920 WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient);
921
922 // Send relative mouse position, and re-center the mouse
923 // Reposition the mouse to the center of the screen/window
924 SDL_PrivateMouseMotion(0, // Buttons not changed
925 1, // Relative position
926 ppts->x - (swpClient.cx/2),
927 (swpClient.cy/2) - ppts->y);
928
929 ptl.x = 0; ptl.y = 0;
930 WinMapWindowPoints(pVideo->hidden->hwndClient, HWND_DESKTOP, &ptl, 1);
931 pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
932 // Center the mouse to the middle of the window!
933 WinSetPointerPos(HWND_DESKTOP,
934 ptl.x + swpClient.cx/2,
935 ptl.y + swpClient.cy/2);
936 } else
937 {
938 CONVERTMOUSEPOSITION();
939
940 // Send absolute mouse position
941 SDL_PrivateMouseMotion(0, // Buttons not changed
942 0, // Absolute position
943 ppts->x,
944 ppts->y);
945 }
946 }
947 if ((pVideo->hidden->iMouseVisible) && (!bMouseCaptured))
948 {
949 #ifdef DEBUG_BUILD 981 #ifdef DEBUG_BUILD
950 // printf("WM_MOUSEMOVE : ptr = %p\n", hptrGlobalPointer); fflush(stdout); 982 // printf("WM_MOUSEMOVE : ptr = %p\n", hptrGlobalPointer); fflush(stdout);
951 #endif 983 #endif
952 984
953 if (hptrGlobalPointer) 985 if (hptrGlobalPointer)
954 WinSetPointer(HWND_DESKTOP, hptrGlobalPointer); 986 WinSetPointer (HWND_DESKTOP, hptrGlobalPointer);
955 else 987 else
956 WinSetPointer(HWND_DESKTOP, WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE)); 988 WinSetPointer (HWND_DESKTOP,
957 } 989 WinQuerySysPointer (HWND_DESKTOP,
958 else 990 SPTR_ARROW, FALSE));
959 { 991 } else {
960 WinSetPointer(HWND_DESKTOP, NULL); 992 WinSetPointer (HWND_DESKTOP, NULL);
961 } 993 }
962 } 994 }
963 #ifdef DEBUG_BUILD 995 #ifdef DEBUG_BUILD
964 // printf("WM_MOUSEMOVE done\n"); fflush(stdout); 996 // printf("WM_MOUSEMOVE done\n"); fflush(stdout);
965 #endif 997 #endif
966 998
967 return (MRESULT) FALSE; 999 return (MRESULT) FALSE;
968 case WM_CLOSE: // Window close 1000 case WM_CLOSE: // Window close
969 #ifdef DEBUG_BUILD 1001 #ifdef DEBUG_BUILD
970 printf("WM_CLOSE\n"); fflush(stdout); 1002 printf ("WM_CLOSE\n");
971 #endif 1003 fflush (stdout);
972 1004 #endif
973 pVideo = FSLib_GetUserParm(hwnd); 1005
974 if (pVideo) 1006 pVideo = FSLib_GetUserParm (hwnd);
975 { 1007 if (pVideo) {
976 // Send Quit message to the SDL application! 1008 // Send Quit message to the SDL application!
977 SDL_PrivateQuit(); 1009 SDL_PrivateQuit ();
978 return 0; 1010 return 0;
979 } 1011 }
980 break; 1012 break;
981 1013
982 #ifdef BITBLT_IN_WINMESSAGEPROC 1014 #ifdef BITBLT_IN_WINMESSAGEPROC
983 case WM_UPDATERECTSREQUEST: 1015 case WM_UPDATERECTSREQUEST:
984 pVideo = FSLib_GetUserParm(hwnd); 1016 pVideo = FSLib_GetUserParm (hwnd);
985 if ((pVideo) && (pVideo->hidden->pSDLSurface)) 1017 if ((pVideo) && (pVideo->hidden->pSDLSurface)) {
986 { 1018 if (DosRequestMutexSem
987 if (DosRequestMutexSem(pVideo->hidden->hmtxUseSrcBuffer, SEM_INDEFINITE_WAIT)==NO_ERROR) 1019 (pVideo->hidden->hmtxUseSrcBuffer,
988 { 1020 SEM_INDEFINITE_WAIT) == NO_ERROR) {
989 int numrects; 1021 int numrects;
990 SDL_Rect *rects; 1022 SDL_Rect *rects;
991 int i; 1023 int i;
992 SWP swp; 1024 SWP swp;
993 1025
994 numrects = (int) mp1; 1026 numrects = (int) mp1;
995 rects = (SDL_Rect *) mp2; 1027 rects = (SDL_Rect *) mp2;
996 1028
997 WinQueryWindowPos(hwnd, &swp); 1029 WinQueryWindowPos (hwnd, &swp);
998 #ifndef RESIZE_EVEN_IF_RESIZABLE 1030 #ifndef RESIZE_EVEN_IF_RESIZABLE
999 if ((!pVideo->hidden->pSDLSurface) || 1031 if ((!pVideo->hidden->pSDLSurface) ||
1000 ( 1032 ((pVideo->hidden->pSDLSurface) &&
1001 (pVideo->hidden->pSDLSurface) && 1033 (pVideo->hidden->pSDLSurface->flags & SDL_RESIZABLE)
1002 (pVideo->hidden->pSDLSurface->flags & SDL_RESIZABLE) && 1034 &&
1003 ((swp.cx != pVideo->hidden->SrcBufferDesc.uiXResolution) || 1035 ((swp.cx != pVideo->hidden->SrcBufferDesc.uiXResolution)
1004 (swp.cy != pVideo->hidden->SrcBufferDesc.uiYResolution) 1036 || (swp.cy !=
1005 ) && 1037 pVideo->hidden->SrcBufferDesc.uiYResolution))
1006 (!FSLib_QueryFSMode(hwnd)) 1038 && (!FSLib_QueryFSMode (hwnd)))) {
1007 ) 1039 // Resizable surface and in resizing!
1008 ) 1040 // So, don't blit now!
1009 { 1041 #ifdef DEBUG_BUILD
1010 // Resizable surface and in resizing! 1042 printf
1011 // So, don't blit now! 1043 ("[WM_UPDATERECTSREQUEST] : Skipping blit while resizing!\n");
1012 #ifdef DEBUG_BUILD 1044 fflush (stdout);
1013 printf("[WM_UPDATERECTSREQUEST] : Skipping blit while resizing!\n"); fflush(stdout); 1045 #endif
1014 #endif 1046 } else
1015 } else 1047 #endif
1016 #endif 1048 {
1017 { 1049 #ifdef DEBUG_BUILD
1018 #ifdef DEBUG_BUILD 1050 printf ("[WM_UPDATERECTSREQUEST] : Blitting!\n");
1019 printf("[WM_UPDATERECTSREQUEST] : Blitting!\n"); fflush(stdout); 1051 fflush (stdout);
1020 #endif 1052 #endif
1021 1053
1022 // Blit the changed areas 1054 // Blit the changed areas
1023 for (i=0; i<numrects; i++) 1055 for (i = 0; i < numrects; i++)
1024 FSLIB_BITBLT(hwnd, pVideo->hidden->pchSrcBuffer, 1056 FSLIB_BITBLT (hwnd,
1025 rects[i].y, rects[i].x, rects[i].w, rects[i].h); 1057 pVideo->hidden->pchSrcBuffer,
1026 } 1058 rects[i].y, rects[i].x,
1027 DosReleaseMutexSem(pVideo->hidden->hmtxUseSrcBuffer); 1059 rects[i].w, rects[i].h);
1028 } 1060 }
1029 } 1061 DosReleaseMutexSem (pVideo->hidden->hmtxUseSrcBuffer);
1030 return 0; 1062 }
1063 }
1064 return 0;
1031 #endif 1065 #endif
1032 1066
1033 default: 1067 default:
1034 #ifdef DEBUG_BUILD 1068 #ifdef DEBUG_BUILD
1035 printf("Unhandled: %x\n", msg); fflush(stdout); 1069 printf ("Unhandled: %x\n", msg);
1036 #endif 1070 fflush (stdout);
1037 1071 #endif
1038 break; 1072
1039 } 1073 break;
1040 // Run the default window procedure for unhandled stuffs 1074 }
1041 return WinDefWindowProc(hwnd, msg, mp1, mp2); 1075 // Run the default window procedure for unhandled stuffs
1076 return WinDefWindowProc (hwnd, msg, mp1, mp2);
1042 } 1077 }
1043 1078
1044 ///////////////////////////////////////////////////////////////////// 1079 /////////////////////////////////////////////////////////////////////
1045 // 1080 //
1046 // FrameWndProc 1081 // FrameWndProc
1047 // 1082 //
1048 // This is the message processing window procedure for the 1083 // This is the message processing window procedure for the
1049 // frame window of SDLWindowClass. 1084 // frame window of SDLWindowClass.
1050 // 1085 //
1051 ///////////////////////////////////////////////////////////////////// 1086 /////////////////////////////////////////////////////////////////////
1052 static MRESULT EXPENTRY FrameWndProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) 1087 static MRESULT EXPENTRY
1053 { 1088 FrameWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1054 PFNWP pOldFrameProc; 1089 {
1055 MRESULT result; 1090 PFNWP pOldFrameProc;
1056 PTRACKINFO ti; 1091 MRESULT result;
1057 int cx, cy, ncx, ncy; 1092 PTRACKINFO ti;
1058 RECTL rclTemp; 1093 int cx, cy, ncx, ncy;
1059 PSWP pswpTemp; 1094 RECTL rclTemp;
1060 1095 PSWP pswpTemp;
1061 SDL_VideoDevice *pVideo = NULL; 1096
1062 1097 SDL_VideoDevice *pVideo = NULL;
1063 pVideo = (SDL_VideoDevice *) WinQueryWindowULong(hwnd, QWL_USER); 1098
1064 1099 pVideo = (SDL_VideoDevice *) WinQueryWindowULong (hwnd, QWL_USER);
1065 pOldFrameProc = pVideo->hidden->pfnOldFrameProc; 1100
1066 1101 pOldFrameProc = pVideo->hidden->pfnOldFrameProc;
1067 if ((pVideo->hidden->bProportionalResize) && 1102
1068 (msg==WM_ADJUSTWINDOWPOS) && 1103 if ((pVideo->hidden->bProportionalResize) &&
1069 (!FSLib_QueryFSMode(pVideo->hidden->hwndClient)) 1104 (msg == WM_ADJUSTWINDOWPOS) &&
1070 ) 1105 (!FSLib_QueryFSMode (pVideo->hidden->hwndClient))) {
1071 { 1106 pswpTemp = (PSWP) mp1;
1072 pswpTemp = (PSWP) mp1; 1107
1073 1108 /* Resizing? */
1074 /* Resizing? */ 1109 if (pswpTemp->fl & SWP_SIZE) {
1075 if (pswpTemp->fl & SWP_SIZE) 1110 /* Calculate client size */
1076 { 1111 rclTemp.xLeft = pswpTemp->x;
1077 /* Calculate client size */ 1112 rclTemp.xRight = pswpTemp->x + pswpTemp->cx;
1078 rclTemp.xLeft = pswpTemp->x; 1113 rclTemp.yBottom = pswpTemp->y;
1079 rclTemp.xRight = pswpTemp->x + pswpTemp->cx; 1114 rclTemp.yTop = pswpTemp->y + pswpTemp->cy;
1080 rclTemp.yBottom = pswpTemp->y; 1115 WinCalcFrameRect (hwnd, &rclTemp, TRUE);
1081 rclTemp.yTop = pswpTemp->y + pswpTemp->cy; 1116
1082 WinCalcFrameRect(hwnd, &rclTemp, TRUE); 1117 ncx = cx = rclTemp.xRight - rclTemp.xLeft;
1083 1118 ncy = cy = rclTemp.yTop - rclTemp.yBottom;
1084 ncx = cx = rclTemp.xRight - rclTemp.xLeft; 1119
1085 ncy = cy = rclTemp.yTop - rclTemp.yBottom; 1120 /* Calculate new size to keep it proportional */
1086 1121
1087 /* Calculate new size to keep it proportional */ 1122 if ((pVideo->hidden->ulResizingFlag & TF_LEFT)
1088 1123 || (pVideo->hidden->ulResizingFlag & TF_RIGHT)) {
1089 if ((pVideo->hidden->ulResizingFlag & TF_LEFT) || (pVideo->hidden->ulResizingFlag & TF_RIGHT)) 1124 /* The window is resized horizontally */
1090 { 1125 ncy =
1091 /* The window is resized horizontally */ 1126 pVideo->hidden->SrcBufferDesc.uiYResolution * cx /
1092 ncy = pVideo->hidden->SrcBufferDesc.uiYResolution * cx / pVideo->hidden->SrcBufferDesc.uiXResolution; 1127 pVideo->hidden->SrcBufferDesc.uiXResolution;
1093 } else 1128 } else if ((pVideo->hidden->ulResizingFlag & TF_TOP)
1094 if ((pVideo->hidden->ulResizingFlag & TF_TOP) || (pVideo->hidden->ulResizingFlag & TF_BOTTOM)) 1129 || (pVideo->hidden->ulResizingFlag & TF_BOTTOM)) {
1095 { 1130 /* The window is resized vertically */
1096 /* The window is resized vertically */ 1131 ncx =
1097 ncx = pVideo->hidden->SrcBufferDesc.uiXResolution * cy / pVideo->hidden->SrcBufferDesc.uiYResolution; 1132 pVideo->hidden->SrcBufferDesc.uiXResolution * cy /
1098 } 1133 pVideo->hidden->SrcBufferDesc.uiYResolution;
1099 1134 }
1100 /* Calculate back frame coordinates */ 1135
1101 rclTemp.xLeft = pswpTemp->x; 1136 /* Calculate back frame coordinates */
1102 rclTemp.xRight = pswpTemp->x + ncx; 1137 rclTemp.xLeft = pswpTemp->x;
1103 rclTemp.yBottom = pswpTemp->y; 1138 rclTemp.xRight = pswpTemp->x + ncx;
1104 rclTemp.yTop = pswpTemp->y + ncy; 1139 rclTemp.yBottom = pswpTemp->y;
1105 WinCalcFrameRect(hwnd, &rclTemp, FALSE); 1140 rclTemp.yTop = pswpTemp->y + ncy;
1106 1141 WinCalcFrameRect (hwnd, &rclTemp, FALSE);
1107 /* Store new size/position info */ 1142
1108 pswpTemp->cx = rclTemp.xRight - rclTemp.xLeft; 1143 /* Store new size/position info */
1109 1144 pswpTemp->cx = rclTemp.xRight - rclTemp.xLeft;
1110 if (!(pVideo->hidden->ulResizingFlag & TF_TOP)) 1145
1111 { 1146 if (!(pVideo->hidden->ulResizingFlag & TF_TOP)) {
1112 pswpTemp->y = pswpTemp->y + pswpTemp->cy - (rclTemp.yTop - rclTemp.yBottom); 1147 pswpTemp->y =
1113 pswpTemp->cy = rclTemp.yTop - rclTemp.yBottom; 1148 pswpTemp->y + pswpTemp->cy - (rclTemp.yTop -
1114 } else 1149 rclTemp.yBottom);
1115 { 1150 pswpTemp->cy = rclTemp.yTop - rclTemp.yBottom;
1116 pswpTemp->cy = rclTemp.yTop - rclTemp.yBottom; 1151 } else {
1117 } 1152 pswpTemp->cy = rclTemp.yTop - rclTemp.yBottom;
1118 } 1153 }
1119 } 1154 }
1120 1155 }
1121 result = (*pOldFrameProc)(hwnd, msg, mp1, mp2); 1156
1122 1157 result = (*pOldFrameProc) (hwnd, msg, mp1, mp2);
1123 if ((pVideo->hidden->bProportionalResize) && (msg==WM_QUERYTRACKINFO)) 1158
1124 { 1159 if ((pVideo->hidden->bProportionalResize) && (msg == WM_QUERYTRACKINFO)) {
1125 ti = (PTRACKINFO) mp2; 1160 ti = (PTRACKINFO) mp2;
1126 1161
1127 /* Store the direction of resizing */ 1162 /* Store the direction of resizing */
1128 if ((ti->fs & TF_LEFT) || (ti->fs & TF_RIGHT) || 1163 if ((ti->fs & TF_LEFT) || (ti->fs & TF_RIGHT) ||
1129 (ti->fs & TF_TOP) || (ti->fs & TF_BOTTOM)) 1164 (ti->fs & TF_TOP) || (ti->fs & TF_BOTTOM))
1130 pVideo->hidden->ulResizingFlag = ti->fs; 1165 pVideo->hidden->ulResizingFlag = ti->fs;
1131 } 1166 }
1132 1167
1133 return result; 1168 return result;
1134 } 1169 }
1135 1170
1136 ///////////////////////////////////////////////////////////////////// 1171 /////////////////////////////////////////////////////////////////////
1137 // 1172 //
1138 // PMThreadFunc 1173 // PMThreadFunc
1139 // 1174 //
1140 // This function implements the PM-Thread, which initializes the 1175 // This function implements the PM-Thread, which initializes the
1141 // application window itself, the DIVE, and start message processing. 1176 // application window itself, the DIVE, and start message processing.
1142 // 1177 //
1143 ///////////////////////////////////////////////////////////////////// 1178 /////////////////////////////////////////////////////////////////////
1144 int iNumOfPMThreadInstances = 0; // Global! 1179 int iNumOfPMThreadInstances = 0; // Global!
1145 static void PMThreadFunc(void *pParm) 1180 static void
1146 { 1181 PMThreadFunc (void *pParm)
1147 SDL_VideoDevice *pVideo = pParm; 1182 {
1148 HAB hab; 1183 SDL_VideoDevice *pVideo = pParm;
1149 HMQ hmq; 1184 HAB hab;
1150 QMSG msg; 1185 HMQ hmq;
1151 ULONG fcf; 1186 QMSG msg;
1152 1187 ULONG fcf;
1153 #ifdef DEBUG_BUILD 1188
1154 printf("[PMThreadFunc] : Starting\n"); fflush(stdout); 1189 #ifdef DEBUG_BUILD
1155 #endif 1190 printf ("[PMThreadFunc] : Starting\n");
1156 1191 fflush (stdout);
1157 iNumOfPMThreadInstances++; 1192 #endif
1158 1193
1159 // Initialize PM, create a message queue. 1194 iNumOfPMThreadInstances++;
1160 1195
1161 hab=WinInitialize(0); 1196 // Initialize PM, create a message queue.
1162 hmq=WinCreateMsgQueue(hab,0); 1197
1163 if (hmq==0) 1198 hab = WinInitialize (0);
1164 { 1199 hmq = WinCreateMsgQueue (hab, 0);
1165 #ifdef DEBUG_BUILD 1200 if (hmq == 0) {
1166 printf("[PMThreadFunc] : Could not create message queue!\n"); 1201 #ifdef DEBUG_BUILD
1167 printf(" It might be that the application using SDL is not a PM app!\n"); 1202 printf ("[PMThreadFunc] : Could not create message queue!\n");
1168 fflush(stdout); 1203 printf
1169 #endif 1204 (" It might be that the application using SDL is not a PM app!\n");
1170 pVideo->hidden->iPMThreadStatus = 2; 1205 fflush (stdout);
1171 } else 1206 #endif
1172 { 1207 pVideo->hidden->iPMThreadStatus = 2;
1173 int rc; 1208 } else {
1174 RECTL rectl; 1209 int rc;
1175 1210 RECTL rectl;
1176 fcf = ulFCFToUse; // Get from global setting 1211
1177 1212 fcf = ulFCFToUse; // Get from global setting
1178 #ifdef DEBUG_BUILD 1213
1179 printf("[PMThreadFunc] : FSLib_CreateWindow()!\n"); 1214 #ifdef DEBUG_BUILD
1180 fflush(stdout); 1215 printf ("[PMThreadFunc] : FSLib_CreateWindow()!\n");
1181 #endif 1216 fflush (stdout);
1182 1217 #endif
1183 rc = FSLib_CreateWindow(HWND_DESKTOP, 0, &fcf, 1218
1184 "SDL Application", 1219 rc = FSLib_CreateWindow (HWND_DESKTOP, 0, &fcf,
1185 NULLHANDLE, 0, 1220 "SDL Application",
1186 &(pVideo->hidden->SrcBufferDesc), 1221 NULLHANDLE, 0,
1187 WndProc, 1222 &(pVideo->hidden->SrcBufferDesc),
1188 &(pVideo->hidden->hwndClient), 1223 WndProc,
1189 &(pVideo->hidden->hwndFrame)); 1224 &(pVideo->hidden->hwndClient),
1190 1225 &(pVideo->hidden->hwndFrame));
1191 #ifdef DEBUG_BUILD 1226
1192 printf("[PMThreadFunc] : FSLib_CreateWindow() rc = %d\n", rc); 1227 #ifdef DEBUG_BUILD
1193 fflush(stdout); 1228 printf ("[PMThreadFunc] : FSLib_CreateWindow() rc = %d\n", rc);
1194 #endif 1229 fflush (stdout);
1195 1230 #endif
1196 if (!rc) 1231
1197 { 1232 if (!rc) {
1198 #ifdef DEBUG_BUILD 1233 #ifdef DEBUG_BUILD
1199 printf("[PMThreadFunc] : Could not create FSLib window!\n"); 1234 printf ("[PMThreadFunc] : Could not create FSLib window!\n");
1200 fflush(stdout); 1235 fflush (stdout);
1201 #endif 1236 #endif
1202 pVideo->hidden->iPMThreadStatus = 3; 1237 pVideo->hidden->iPMThreadStatus = 3;
1203 } else 1238 } else {
1204 { 1239 #ifdef DEBUG_BUILD
1205 #ifdef DEBUG_BUILD 1240 printf ("[PMThreadFunc] : FSLib_AddUserParm()!\n");
1206 printf("[PMThreadFunc] : FSLib_AddUserParm()!\n"); 1241 fflush (stdout);
1207 fflush(stdout); 1242 #endif
1208 #endif 1243
1209 1244 // Store pVideo pointer in window data for client window, so
1210 // Store pVideo pointer in window data for client window, so 1245 // it will know the instance to which it belongs to.
1211 // it will know the instance to which it belongs to. 1246 FSLib_AddUserParm (pVideo->hidden->hwndClient, pVideo);
1212 FSLib_AddUserParm(pVideo->hidden->hwndClient, pVideo); 1247
1213 1248 // Now set default image width height and fourcc!
1214 // Now set default image width height and fourcc! 1249 #ifdef DEBUG_BUILD
1215 #ifdef DEBUG_BUILD 1250 printf ("[PMThreadFunc] : SetWindowPos()!\n");
1216 printf("[PMThreadFunc] : SetWindowPos()!\n"); 1251 fflush (stdout);
1217 fflush(stdout); 1252 #endif
1218 #endif 1253
1219 1254 // Set the position and size of the main window,
1220 // Set the position and size of the main window, 1255 // and make it visible!
1221 // and make it visible! 1256 // Calculate frame window size from client window size
1222 // Calculate frame window size from client window size 1257 rectl.xLeft = 0;
1223 rectl.xLeft = 0; 1258 rectl.yBottom = 0;
1224 rectl.yBottom = 0; 1259 rectl.xRight = pVideo->hidden->SrcBufferDesc.uiXResolution; // Noninclusive
1225 rectl.xRight = pVideo->hidden->SrcBufferDesc.uiXResolution; // Noninclusive 1260 rectl.yTop = pVideo->hidden->SrcBufferDesc.uiYResolution; // Noninclusive
1226 rectl.yTop = pVideo->hidden->SrcBufferDesc.uiYResolution; // Noninclusive 1261 WinCalcFrameRect (pVideo->hidden->hwndFrame, &rectl, FALSE);
1227 WinCalcFrameRect(pVideo->hidden->hwndFrame, &rectl, FALSE); 1262
1228 1263 SetAccessableWindowPos (pVideo->hidden->hwndFrame,
1229 SetAccessableWindowPos(pVideo->hidden->hwndFrame, 1264 HWND_TOP,
1230 HWND_TOP, 1265 (WinQuerySysValue
1231 (WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN) - (rectl.xRight-rectl.xLeft)) / 2, 1266 (HWND_DESKTOP,
1232 (WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN) - (rectl.yTop-rectl.yBottom)) / 2, 1267 SV_CXSCREEN) - (rectl.xRight -
1233 (rectl.xRight-rectl.xLeft), 1268 rectl.xLeft)) / 2,
1234 (rectl.yTop-rectl.yBottom), 1269 (WinQuerySysValue
1235 SWP_SIZE | SWP_ACTIVATE | SWP_SHOW | SWP_MOVE); 1270 (HWND_DESKTOP,
1236 1271 SV_CYSCREEN) - (rectl.yTop -
1237 // Subclass frame procedure and store old window proc address 1272 rectl.yBottom)) / 2,
1238 pVideo->hidden->pfnOldFrameProc = 1273 (rectl.xRight - rectl.xLeft),
1239 WinSubclassWindow(pVideo->hidden->hwndFrame, FrameWndProc); 1274 (rectl.yTop - rectl.yBottom),
1240 WinSetWindowULong(pVideo->hidden->hwndFrame, QWL_USER, (ULONG) pVideo); 1275 SWP_SIZE | SWP_ACTIVATE | SWP_SHOW |
1241 1276 SWP_MOVE);
1242 #ifdef DEBUG_BUILD 1277
1243 printf("[PMThreadFunc] : Entering message loop\n"); fflush(stdout); 1278 // Subclass frame procedure and store old window proc address
1244 #endif 1279 pVideo->hidden->pfnOldFrameProc =
1245 pVideo->hidden->iPMThreadStatus = 1; 1280 WinSubclassWindow (pVideo->hidden->hwndFrame, FrameWndProc);
1246 1281 WinSetWindowULong (pVideo->hidden->hwndFrame, QWL_USER,
1247 while (WinGetMsg(hab, (PQMSG)&msg, 0, 0, 0)) 1282 (ULONG) pVideo);
1248 WinDispatchMsg(hab, (PQMSG) &msg); 1283
1249 1284 #ifdef DEBUG_BUILD
1250 #ifdef DEBUG_BUILD 1285 printf ("[PMThreadFunc] : Entering message loop\n");
1251 printf("[PMThreadFunc] : Leaving message loop\n"); fflush(stdout); 1286 fflush (stdout);
1252 #endif 1287 #endif
1253 // We should release the captured the mouse! 1288 pVideo->hidden->iPMThreadStatus = 1;
1254 if (bMouseCaptured) 1289
1255 { 1290 while (WinGetMsg (hab, (PQMSG) & msg, 0, 0, 0))
1256 WinSetCapture(HWND_DESKTOP, NULLHANDLE); 1291 WinDispatchMsg (hab, (PQMSG) & msg);
1257 bMouseCaptured = 0; 1292
1258 } 1293 #ifdef DEBUG_BUILD
1259 // Destroy our window 1294 printf ("[PMThreadFunc] : Leaving message loop\n");
1260 WinDestroyWindow(pVideo->hidden->hwndFrame); pVideo->hidden->hwndFrame=NULL; 1295 fflush (stdout);
1261 // Show pointer to make sure it will not be left hidden. 1296 #endif
1262 WinSetPointer(HWND_DESKTOP, WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE)); 1297 // We should release the captured the mouse!
1263 WinShowPointer(HWND_DESKTOP, TRUE); 1298 if (bMouseCaptured) {
1264 } 1299 WinSetCapture (HWND_DESKTOP, NULLHANDLE);
1265 // Uninitialize PM 1300 bMouseCaptured = 0;
1266 WinDestroyMsgQueue(hmq); 1301 }
1267 // All done! 1302 // Destroy our window
1268 pVideo->hidden->iPMThreadStatus = 0; 1303 WinDestroyWindow (pVideo->hidden->hwndFrame);
1269 } 1304 pVideo->hidden->hwndFrame = NULL;
1270 WinTerminate(hab); 1305 // Show pointer to make sure it will not be left hidden.
1271 /* Commented out, should not be needed anymore, because we send it 1306 WinSetPointer (HWND_DESKTOP,
1272 from WM_CLOSE. 1307 WinQuerySysPointer (HWND_DESKTOP, SPTR_ARROW,
1273 // Notify SDL that it should really die now... 1308 FALSE));
1274 SDL_PrivateQuit(); SDL_PrivateQuit(); SDL_PrivateQuit(); //... :)) 1309 WinShowPointer (HWND_DESKTOP, TRUE);
1275 */ 1310 }
1276 #ifdef DEBUG_BUILD 1311 // Uninitialize PM
1277 printf("[PMThreadFunc] : End, status is %d!\n", pVideo->hidden->iPMThreadStatus); fflush(stdout); 1312 WinDestroyMsgQueue (hmq);
1278 #endif 1313 // All done!
1279 1314 pVideo->hidden->iPMThreadStatus = 0;
1280 iNumOfPMThreadInstances--; 1315 }
1281 1316 WinTerminate (hab);
1282 // HACK to prevent zombie and hanging SDL applications, which does not take 1317 /* Commented out, should not be needed anymore, because we send it
1283 // care of closing the window for some reason: 1318 from WM_CLOSE.
1284 // There are some apps which do not process messages, so do a lot of things 1319 // Notify SDL that it should really die now...
1285 // without noticing that the application should close. To close these, 1320 SDL_PrivateQuit(); SDL_PrivateQuit(); SDL_PrivateQuit(); //... :))
1286 // I've thought about the following: 1321 */
1287 // If the window is closed (the execution came here), I wait a bit to 1322 #ifdef DEBUG_BUILD
1288 // give time to the app to finish its execution. If it does not, I kill it 1323 printf ("[PMThreadFunc] : End, status is %d!\n",
1289 // using DosExit(). Brute force, but should work. 1324 pVideo->hidden->iPMThreadStatus);
1290 if (pVideo->hidden->iPMThreadStatus==0) 1325 fflush (stdout);
1291 { 1326 #endif
1292 DosSleep(5000); // Wait 5 secs 1327
1293 // If a new PM thread has been spawned (reinitializing video mode), then all right. 1328 iNumOfPMThreadInstances--;
1294 // Otherwise, we have a problem, the app doesn't want to stop. Kill! 1329
1295 if (iNumOfPMThreadInstances==0) 1330 // HACK to prevent zombie and hanging SDL applications, which does not take
1296 { 1331 // care of closing the window for some reason:
1297 #ifdef DEBUG_BUILD 1332 // There are some apps which do not process messages, so do a lot of things
1298 printf("[PMThreadFunc] : It seems that the application haven't terminated itself\n"); fflush(stdout); 1333 // without noticing that the application should close. To close these,
1299 printf("[PMThreadFunc] : in the last 5 seconds, so we go berserk.\n"); fflush(stdout); 1334 // I've thought about the following:
1300 printf("[PMThreadFunc] : Brute force mode. :) Killing process! Dieeeee...\n"); fflush(stdout); 1335 // If the window is closed (the execution came here), I wait a bit to
1301 #endif 1336 // give time to the app to finish its execution. If it does not, I kill it
1302 DosExit(EXIT_PROCESS, -1); 1337 // using DosExit(). Brute force, but should work.
1303 } 1338 if (pVideo->hidden->iPMThreadStatus == 0) {
1304 } 1339 DosSleep (5000); // Wait 5 secs
1305 _endthread(); 1340 // If a new PM thread has been spawned (reinitializing video mode), then all right.
1341 // Otherwise, we have a problem, the app doesn't want to stop. Kill!
1342 if (iNumOfPMThreadInstances == 0) {
1343 #ifdef DEBUG_BUILD
1344 printf
1345 ("[PMThreadFunc] : It seems that the application haven't terminated itself\n");
1346 fflush (stdout);
1347 printf
1348 ("[PMThreadFunc] : in the last 5 seconds, so we go berserk.\n");
1349 fflush (stdout);
1350 printf
1351 ("[PMThreadFunc] : Brute force mode. :) Killing process! Dieeeee...\n");
1352 fflush (stdout);
1353 #endif
1354 DosExit (EXIT_PROCESS, -1);
1355 }
1356 }
1357 _endthread ();
1306 } 1358 }
1307 1359
1308 struct WMcursor 1360 struct WMcursor
1309 { 1361 {
1310 HBITMAP hbm; 1362 HBITMAP hbm;
1311 HPOINTER hptr; 1363 HPOINTER hptr;
1312 char *pchData; 1364 char *pchData;
1313 }; 1365 };
1314 1366
1315 /* Free a window manager cursor */ 1367 /* Free a window manager cursor */
1316 void os2fslib_FreeWMCursor(_THIS, WMcursor *cursor) 1368 void
1317 { 1369 os2fslib_FreeWMCursor (_THIS, WMcursor * cursor)
1318 if (cursor) 1370 {
1319 { 1371 if (cursor) {
1320 GpiDeleteBitmap(cursor->hbm); 1372 GpiDeleteBitmap (cursor->hbm);
1321 WinDestroyPointer(cursor->hptr); 1373 WinDestroyPointer (cursor->hptr);
1322 SDL_free(cursor->pchData); 1374 SDL_free (cursor->pchData);
1323 SDL_free(cursor); 1375 SDL_free (cursor);
1324 } 1376 }
1325 } 1377 }
1326 1378
1327 /* Local functions to convert the SDL cursor mask into OS/2 format */ 1379 /* Local functions to convert the SDL cursor mask into OS/2 format */
1328 static void memnot(Uint8 *dst, Uint8 *src, int len) 1380 static void
1329 { 1381 memnot (Uint8 * dst, Uint8 * src, int len)
1330 while ( len-- > 0 ) 1382 {
1331 *dst++ = ~*src++; 1383 while (len-- > 0)
1332 } 1384 *dst++ = ~*src++;
1333 static void memxor(Uint8 *dst, Uint8 *src1, Uint8 *src2, int len) 1385 }
1334 { 1386 static void
1335 while ( len-- > 0 ) 1387 memxor (Uint8 * dst, Uint8 * src1, Uint8 * src2, int len)
1336 *dst++ = (*src1++)^(*src2++); 1388 {
1389 while (len-- > 0)
1390 *dst++ = (*src1++) ^ (*src2++);
1337 } 1391 }
1338 1392
1339 /* Create a black/white window manager cursor */ 1393 /* Create a black/white window manager cursor */
1340 WMcursor *os2fslib_CreateWMCursor_Win(_THIS, Uint8 *data, Uint8 *mask, 1394 WMcursor *
1341 int w, int h, int hot_x, int hot_y) 1395 os2fslib_CreateWMCursor_Win (_THIS, Uint8 * data, Uint8 * mask,
1342 { 1396 int w, int h, int hot_x, int hot_y)
1343 HPOINTER hptr; 1397 {
1344 HBITMAP hbm; 1398 HPOINTER hptr;
1345 BITMAPINFOHEADER bmih; 1399 HBITMAP hbm;
1346 BMPINFO bmi; 1400 BITMAPINFOHEADER bmih;
1347 HPS hps; 1401 BMPINFO bmi;
1348 char *pchTemp; 1402 HPS hps;
1349 char *xptr, *aptr; 1403 char *pchTemp;
1350 int maxx, maxy; 1404 char *xptr, *aptr;
1351 int i, run, pad; 1405 int maxx, maxy;
1352 WMcursor *pResult; 1406 int i, run, pad;
1353 1407 WMcursor *pResult;
1354 maxx = WinQuerySysValue(HWND_DESKTOP, SV_CXPOINTER); 1408
1355 maxy = WinQuerySysValue(HWND_DESKTOP, SV_CYPOINTER); 1409 maxx = WinQuerySysValue (HWND_DESKTOP, SV_CXPOINTER);
1356 1410 maxy = WinQuerySysValue (HWND_DESKTOP, SV_CYPOINTER);
1357 // Check for max size! 1411
1358 if ((w>maxx) || (h>maxy)) 1412 // Check for max size!
1413 if ((w > maxx) || (h > maxy))
1414 return (WMcursor *) NULL;
1415
1416 pResult = (WMcursor *) SDL_malloc (sizeof (WMcursor));
1417 if (!pResult)
1418 return (WMcursor *) NULL;
1419
1420 pchTemp = (char *) SDL_malloc ((maxx + 7) / 8 * maxy * 2);
1421 if (!pchTemp) {
1422 SDL_free (pResult);
1423 return (WMcursor *) NULL;
1424 }
1425
1426 SDL_memset (pchTemp, 0, (maxx + 7) / 8 * maxy * 2);
1427
1428 hps = WinGetPS (_this->hidden->hwndClient);
1429
1430 bmi.cbFix = sizeof (BITMAPINFOHEADER);
1431 bmi.cx = maxx;
1432 bmi.cy = 2 * maxy;
1433 bmi.cPlanes = 1;
1434 bmi.cBitCount = 1;
1435 bmi.argbColor[0].bBlue = 0x00;
1436 bmi.argbColor[0].bGreen = 0x00;
1437 bmi.argbColor[0].bRed = 0x00;
1438 bmi.argbColor[1].bBlue = 0x00;
1439 bmi.argbColor[1].bGreen = 0x00;
1440 bmi.argbColor[1].bRed = 0xff;
1441
1442 SDL_memset (&bmih, 0, sizeof (BITMAPINFOHEADER));
1443 bmih.cbFix = sizeof (BITMAPINFOHEADER);
1444 bmih.cx = maxx;
1445 bmih.cy = 2 * maxy;
1446 bmih.cPlanes = 1;
1447 bmih.cBitCount = 1;
1448
1449 run = (w + 7) / 8;
1450 pad = (maxx + 7) / 8 - run;
1451
1452 for (i = 0; i < h; i++) {
1453 xptr = pchTemp + (maxx + 7) / 8 * (maxy - 1 - i);
1454 aptr = pchTemp + (maxx + 7) / 8 * (maxy + maxy - 1 - i);
1455 memxor (xptr, data, mask, run);
1456 xptr += run;
1457 data += run;
1458 memnot (aptr, mask, run);
1459 mask += run;
1460 aptr += run;
1461 SDL_memset (xptr, 0, pad);
1462 xptr += pad;
1463 SDL_memset (aptr, ~0, pad);
1464 aptr += pad;
1465 }
1466 pad += run;
1467 for (i = h; i < maxy; i++) {
1468 xptr = pchTemp + (maxx + 7) / 8 * (maxy - 1 - i);
1469 aptr = pchTemp + (maxx + 7) / 8 * (maxy + maxy - 1 - i);
1470
1471 SDL_memset (xptr, 0, (maxx + 7) / 8);
1472 xptr += (maxx + 7) / 8;
1473 SDL_memset (aptr, ~0, (maxx + 7) / 8);
1474 aptr += (maxx + 7) / 8;
1475 }
1476
1477 hbm =
1478 GpiCreateBitmap (hps, (PBITMAPINFOHEADER2) & bmih, CBM_INIT,
1479 (PBYTE) pchTemp, (PBITMAPINFO2) & bmi);
1480 hptr =
1481 WinCreatePointer (HWND_DESKTOP, hbm, TRUE, hot_x, maxy - hot_y - 1);
1482
1483 #ifdef DEBUG_BUILD
1484 printf ("HotSpot : %d ; %d\n", hot_x, hot_y);
1485 printf ("HPS returned : %x\n", (ULONG) hps);
1486 printf ("HBITMAP returned : %x\n", (ULONG) hbm);
1487 printf ("HPOINTER returned: %x\n", (ULONG) hptr);
1488 #endif
1489
1490 WinReleasePS (hps);
1491
1492 #ifdef DEBUG_BUILD
1493 printf ("[CreateWMCursor] : ptr = %p\n", hptr);
1494 fflush (stdout);
1495 #endif
1496
1497 pResult->hptr = hptr;
1498 pResult->hbm = hbm;
1499 pResult->pchData = pchTemp;
1500
1501 #ifdef DEBUG_BUILD
1502 printf ("[CreateWMCursor] : ptr = %p return.\n", hptr);
1503 fflush (stdout);
1504 #endif
1505
1506 return (WMcursor *) pResult;
1507 }
1508
1509 WMcursor *
1510 os2fslib_CreateWMCursor_FS (_THIS, Uint8 * data, Uint8 * mask,
1511 int w, int h, int hot_x, int hot_y)
1512 {
1513 #ifdef DEBUG_BUILD
1514 printf ("[CreateWMCursor_FS] : returning pointer NULL\n");
1515 fflush (stdout);
1516 #endif
1517
1518 // In FS mode we'll use software cursor
1359 return (WMcursor *) NULL; 1519 return (WMcursor *) NULL;
1360
1361 pResult = (WMcursor *) SDL_malloc(sizeof(WMcursor));
1362 if (!pResult) return (WMcursor *) NULL;
1363
1364 pchTemp = (char *) SDL_malloc((maxx + 7)/8 * maxy*2);
1365 if (!pchTemp)
1366 {
1367 SDL_free(pResult);
1368 return (WMcursor *) NULL;
1369 }
1370
1371 SDL_memset(pchTemp, 0, (maxx + 7)/8 * maxy*2);
1372
1373 hps = WinGetPS(_this->hidden->hwndClient);
1374
1375 bmi.cbFix = sizeof(BITMAPINFOHEADER);
1376 bmi.cx = maxx;
1377 bmi.cy = 2*maxy;
1378 bmi.cPlanes = 1;
1379 bmi.cBitCount = 1;
1380 bmi.argbColor[0].bBlue = 0x00;
1381 bmi.argbColor[0].bGreen = 0x00;
1382 bmi.argbColor[0].bRed = 0x00;
1383 bmi.argbColor[1].bBlue = 0x00;
1384 bmi.argbColor[1].bGreen = 0x00;
1385 bmi.argbColor[1].bRed = 0xff;
1386
1387 SDL_memset(&bmih, 0, sizeof(BITMAPINFOHEADER));
1388 bmih.cbFix = sizeof(BITMAPINFOHEADER);
1389 bmih.cx = maxx;
1390 bmih.cy = 2*maxy;
1391 bmih.cPlanes = 1;
1392 bmih.cBitCount = 1;
1393
1394 run = (w+7)/8;
1395 pad = (maxx+7)/8 - run;
1396
1397 for (i=0; i<h; i++)
1398 {
1399 xptr = pchTemp + (maxx+7)/8 * (maxy-1-i);
1400 aptr = pchTemp + (maxx+7)/8 * (maxy+maxy-1-i);
1401 memxor(xptr, data, mask, run);
1402 xptr += run;
1403 data += run;
1404 memnot(aptr, mask, run);
1405 mask += run;
1406 aptr += run;
1407 SDL_memset(xptr, 0, pad);
1408 xptr += pad;
1409 SDL_memset(aptr, ~0, pad);
1410 aptr += pad;
1411 }
1412 pad += run;
1413 for (i=h ; i<maxy; i++ )
1414 {
1415 xptr = pchTemp + (maxx+7)/8 * (maxy-1-i);
1416 aptr = pchTemp + (maxx+7)/8 * (maxy+maxy-1-i);
1417
1418 SDL_memset(xptr, 0, (maxx+7)/8);
1419 xptr += (maxx+7)/8;
1420 SDL_memset(aptr, ~0, (maxx+7)/8);
1421 aptr += (maxx+7)/8;
1422 }
1423
1424 hbm = GpiCreateBitmap(hps, (PBITMAPINFOHEADER2)&bmih, CBM_INIT, (PBYTE) pchTemp, (PBITMAPINFO2)&bmi);
1425 hptr = WinCreatePointer(HWND_DESKTOP, hbm, TRUE, hot_x, maxy - hot_y - 1);
1426
1427 #ifdef DEBUG_BUILD
1428 printf("HotSpot : %d ; %d\n", hot_x, hot_y);
1429 printf("HPS returned : %x\n", (ULONG)hps);
1430 printf("HBITMAP returned : %x\n", (ULONG)hbm);
1431 printf("HPOINTER returned: %x\n", (ULONG)hptr);
1432 #endif
1433
1434 WinReleasePS(hps);
1435
1436 #ifdef DEBUG_BUILD
1437 printf("[CreateWMCursor] : ptr = %p\n", hptr); fflush(stdout);
1438 #endif
1439
1440 pResult->hptr = hptr;
1441 pResult->hbm = hbm;
1442 pResult->pchData = pchTemp;
1443
1444 #ifdef DEBUG_BUILD
1445 printf("[CreateWMCursor] : ptr = %p return.\n", hptr); fflush(stdout);
1446 #endif
1447
1448 return (WMcursor *) pResult;
1449 }
1450
1451 WMcursor *os2fslib_CreateWMCursor_FS(_THIS, Uint8 *data, Uint8 *mask,
1452 int w, int h, int hot_x, int hot_y)
1453 {
1454 #ifdef DEBUG_BUILD
1455 printf("[CreateWMCursor_FS] : returning pointer NULL\n"); fflush(stdout);
1456 #endif
1457
1458 // In FS mode we'll use software cursor
1459 return (WMcursor *) NULL;
1460 } 1520 }
1461 1521
1462 /* Show the specified cursor, or hide if cursor is NULL */ 1522 /* Show the specified cursor, or hide if cursor is NULL */
1463 int os2fslib_ShowWMCursor(_THIS, WMcursor *cursor) 1523 int
1464 { 1524 os2fslib_ShowWMCursor (_THIS, WMcursor * cursor)
1465 #ifdef DEBUG_BUILD 1525 {
1466 printf("[ShowWMCursor] : ptr = %p\n", cursor); fflush(stdout); 1526 #ifdef DEBUG_BUILD
1467 #endif 1527 printf ("[ShowWMCursor] : ptr = %p\n", cursor);
1468 1528 fflush (stdout);
1469 if (cursor) 1529 #endif
1470 { 1530
1471 WinSetPointer(HWND_DESKTOP, cursor->hptr); 1531 if (cursor) {
1472 hptrGlobalPointer = cursor->hptr; 1532 WinSetPointer (HWND_DESKTOP, cursor->hptr);
1473 _this->hidden->iMouseVisible = 1; 1533 hptrGlobalPointer = cursor->hptr;
1474 } 1534 _this->hidden->iMouseVisible = 1;
1475 else 1535 } else {
1476 { 1536 WinSetPointer (HWND_DESKTOP, FALSE);
1477 WinSetPointer(HWND_DESKTOP, FALSE); 1537 hptrGlobalPointer = NULL;
1478 hptrGlobalPointer = NULL; 1538 _this->hidden->iMouseVisible = 0;
1479 _this->hidden->iMouseVisible = 0; 1539 }
1480 } 1540
1481 1541 #ifdef DEBUG_BUILD
1482 #ifdef DEBUG_BUILD 1542 printf ("[ShowWMCursor] : ptr = %p, DONE\n", cursor);
1483 printf("[ShowWMCursor] : ptr = %p, DONE\n", cursor); fflush(stdout); 1543 fflush (stdout);
1484 #endif 1544 #endif
1485 1545
1486 return 1; 1546 return 1;
1487 } 1547 }
1488 1548
1489 /* Warp the window manager cursor to (x,y) 1549 /* Warp the window manager cursor to (x,y)
1490 If NULL, a mouse motion event is posted internally. 1550 If NULL, a mouse motion event is posted internally.
1491 */ 1551 */
1492 void os2fslib_WarpWMCursor(_THIS, Uint16 x, Uint16 y) 1552 void
1493 { 1553 os2fslib_WarpWMCursor (_THIS, Uint16 x, Uint16 y)
1494 LONG lx, ly; 1554 {
1495 SWP swpClient; 1555 LONG lx, ly;
1496 POINTL ptlPoints; 1556 SWP swpClient;
1497 WinQueryWindowPos(_this->hidden->hwndClient, &swpClient); 1557 POINTL ptlPoints;
1498 ptlPoints.x = swpClient.x; 1558 WinQueryWindowPos (_this->hidden->hwndClient, &swpClient);
1499 ptlPoints.y = swpClient.y; 1559 ptlPoints.x = swpClient.x;
1500 WinMapWindowPoints(_this->hidden->hwndFrame, HWND_DESKTOP, &ptlPoints, 1); 1560 ptlPoints.y = swpClient.y;
1501 lx = ptlPoints.x + (x*swpClient.cx) / _this->hidden->SrcBufferDesc.uiXResolution; 1561 WinMapWindowPoints (_this->hidden->hwndFrame, HWND_DESKTOP, &ptlPoints,
1502 ly = ptlPoints.y + swpClient.cy - ((y*swpClient.cy) / _this->hidden->SrcBufferDesc.uiYResolution) - 1; 1562 1);
1503 1563 lx = ptlPoints.x +
1504 SDL_PrivateMouseMotion(0, // Buttons not changed 1564 (x * swpClient.cx) / _this->hidden->SrcBufferDesc.uiXResolution;
1505 0, // Absolute position 1565 ly = ptlPoints.y + swpClient.cy -
1506 x, 1566 ((y * swpClient.cy) / _this->hidden->SrcBufferDesc.uiYResolution) - 1;
1507 y); 1567
1508 1568 SDL_PrivateMouseMotion (0, // Buttons not changed
1509 WinSetPointerPos(HWND_DESKTOP, lx, ly); 1569 0, // Absolute position
1570 x, y);
1571
1572 WinSetPointerPos (HWND_DESKTOP, lx, ly);
1510 1573
1511 } 1574 }
1512 1575
1513 /* If not NULL, this is called when a mouse motion event occurs */ 1576 /* If not NULL, this is called when a mouse motion event occurs */
1514 void os2fslib_MoveWMCursor(_THIS, int x, int y) 1577 void
1515 { 1578 os2fslib_MoveWMCursor (_THIS, int x, int y)
1516 /* 1579 {
1517 SDL_Rect rect; 1580 /*
1518 1581 SDL_Rect rect;
1519 #ifdef DEBUG_BUILD 1582
1520 printf("[MoveWMCursor] : at %d ; %d\n", x, y); fflush(stdout); 1583 #ifdef DEBUG_BUILD
1521 #endif 1584 printf("[MoveWMCursor] : at %d ; %d\n", x, y); fflush(stdout);
1522 1585 #endif
1523 rect.x = x; 1586
1524 rect.y = y; 1587 rect.x = x;
1525 rect.w = 32; 1588 rect.y = y;
1526 rect.h = 32; 1589 rect.w = 32;
1527 os2fslib_UpdateRects(_this, 1, &rect); 1590 rect.h = 32;
1528 // TODO! 1591 os2fslib_UpdateRects(_this, 1, &rect);
1529 */ 1592 // TODO!
1593 */
1530 } 1594 }
1531 1595
1532 /* Determine whether the mouse should be in relative mode or not. 1596 /* Determine whether the mouse should be in relative mode or not.
1533 This function is called when the input grab state or cursor 1597 This function is called when the input grab state or cursor
1534 visibility state changes. 1598 visibility state changes.
1535 If the cursor is not visible, and the input is grabbed, the 1599 If the cursor is not visible, and the input is grabbed, the
1536 driver can place the mouse in relative mode, which may result 1600 driver can place the mouse in relative mode, which may result
1537 in higher accuracy sampling of the pointer motion. 1601 in higher accuracy sampling of the pointer motion.
1538 */ 1602 */
1539 void os2fslib_CheckMouseMode(_THIS) 1603 void
1540 { 1604 os2fslib_CheckMouseMode (_THIS)
1541 } 1605 {
1542 1606 }
1543 static void os2fslib_PumpEvents(_THIS) 1607
1544 { 1608 static void
1545 // Notify SDL that if window has been resized! 1609 os2fslib_PumpEvents (_THIS)
1546 if ( 1610 {
1547 (_this->hidden->pSDLSurface) && 1611 // Notify SDL that if window has been resized!
1548 (_this->hidden->pSDLSurface->flags & SDL_RESIZABLE) && 1612 if ((_this->hidden->pSDLSurface) &&
1549 ( 1613 (_this->hidden->pSDLSurface->flags & SDL_RESIZABLE) &&
1550 (_this->hidden->SrcBufferDesc.uiXResolution!=iWindowSizeX) || 1614 ((_this->hidden->SrcBufferDesc.uiXResolution != iWindowSizeX) ||
1551 (_this->hidden->SrcBufferDesc.uiYResolution!=iWindowSizeY) 1615 (_this->hidden->SrcBufferDesc.uiYResolution != iWindowSizeY)) &&
1552 ) && 1616 (iWindowSizeX > 0) && (iWindowSizeY > 0)) {
1553 (iWindowSizeX>0) && 1617 static time_t prev_time;
1554 (iWindowSizeY>0) 1618 time_t curr_time;
1555 ) 1619
1556 { 1620 curr_time = time (NULL);
1557 static time_t prev_time; 1621 if ((difftime (curr_time, prev_time) >= 0.25) || (bWindowResized)) {
1558 time_t curr_time; 1622 // Make sure we won't flood the event queue with resize events,
1559 1623 // only send them at 250 msecs!
1560 curr_time = time(NULL); 1624 // (or when the window is resized)
1561 if ((difftime(curr_time, prev_time)>=0.25) || 1625 #ifdef DEBUG_BUILD
1562 (bWindowResized)) 1626 printf
1563 { 1627 ("[os2fslib_PumpEvents] : Calling PrivateResize (%d %d).\n",
1564 // Make sure we won't flood the event queue with resize events, 1628 iWindowSizeX, iWindowSizeY);
1565 // only send them at 250 msecs! 1629 fflush (stdout);
1566 // (or when the window is resized) 1630 #endif
1567 #ifdef DEBUG_BUILD 1631 // Tell SDL the new size
1568 printf("[os2fslib_PumpEvents] : Calling PrivateResize (%d %d).\n", 1632 SDL_PrivateResize (iWindowSizeX, iWindowSizeY);
1569 iWindowSizeX, iWindowSizeY); 1633 prev_time = curr_time;
1570 fflush(stdout); 1634 bWindowResized = 0;
1571 #endif 1635 }
1572 // Tell SDL the new size 1636 }
1573 SDL_PrivateResize(iWindowSizeX, iWindowSizeY);
1574 prev_time = curr_time;
1575 bWindowResized = 0;
1576 }
1577 }
1578 } 1637 }
1579 1638
1580 /* We don't actually allow hardware surfaces other than the main one */ 1639 /* We don't actually allow hardware surfaces other than the main one */
1581 static int os2fslib_AllocHWSurface(_THIS, SDL_Surface *surface) 1640 static int
1582 { 1641 os2fslib_AllocHWSurface (_THIS, SDL_Surface * surface)
1583 return(-1); 1642 {
1584 } 1643 return (-1);
1585 static void os2fslib_FreeHWSurface(_THIS, SDL_Surface *surface) 1644 }
1586 { 1645 static void
1587 return; 1646 os2fslib_FreeHWSurface (_THIS, SDL_Surface * surface)
1647 {
1648 return;
1588 } 1649 }
1589 1650
1590 /* We need to wait for vertical retrace on page flipped displays */ 1651 /* We need to wait for vertical retrace on page flipped displays */
1591 static int os2fslib_LockHWSurface(_THIS, SDL_Surface *surface) 1652 static int
1592 { 1653 os2fslib_LockHWSurface (_THIS, SDL_Surface * surface)
1593 return(0); 1654 {
1594 } 1655 return (0);
1595 1656 }
1596 static void os2fslib_UnlockHWSurface(_THIS, SDL_Surface *surface) 1657
1597 { 1658 static void
1598 return; 1659 os2fslib_UnlockHWSurface (_THIS, SDL_Surface * surface)
1599 } 1660 {
1600 1661 return;
1601 static int os2fslib_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) 1662 }
1602 { 1663
1603 printf("[os2fslib_SetColors] : TODO!\n"); fflush(stdout); 1664 static int
1604 // TODO: Implement paletted modes 1665 os2fslib_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors)
1605 return(1); 1666 {
1606 } 1667 printf ("[os2fslib_SetColors] : TODO!\n");
1607 1668 fflush (stdout);
1608 static void os2fslib_DestroyIcon(HWND hwndFrame) 1669 // TODO: Implement paletted modes
1609 { 1670 return (1);
1610 if (hptrCurrentIcon) 1671 }
1611 { 1672
1612 WinDestroyPointer(hptrCurrentIcon); 1673 static void
1613 hptrCurrentIcon = NULL; 1674 os2fslib_DestroyIcon (HWND hwndFrame)
1614 1675 {
1615 WinSendMsg(hwndFrame, 1676 if (hptrCurrentIcon) {
1616 WM_SETICON, 1677 WinDestroyPointer (hptrCurrentIcon);
1617 NULL, 1678 hptrCurrentIcon = NULL;
1618 NULL); 1679
1619 } 1680 WinSendMsg (hwndFrame, WM_SETICON, NULL, NULL);
1681 }
1620 1682
1621 } 1683 }
1622 1684
1623 /* Set the window icon image */ 1685 /* Set the window icon image */
1624 void os2fslib_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask) 1686 void
1625 { 1687 os2fslib_SetIcon (_THIS, SDL_Surface * icon, Uint8 * mask)
1626 HWND hwndFrame; 1688 {
1627 SDL_Surface *icon_rgb; 1689 HWND hwndFrame;
1628 HPOINTER hptrIcon; 1690 SDL_Surface *icon_rgb;
1629 HBITMAP hbm; 1691 HPOINTER hptrIcon;
1630 BITMAPINFOHEADER bmih; 1692 HBITMAP hbm;
1631 BMPINFO bmi; 1693 BITMAPINFOHEADER bmih;
1632 HPS hps; 1694 BMPINFO bmi;
1633 char *pchTemp; 1695 HPS hps;
1634 char *pptr, *mptr, *dptr, *dmptr; 1696 char *pchTemp;
1635 int maxx, maxy, w, h, x, y; 1697 char *pptr, *mptr, *dptr, *dmptr;
1636 SDL_Rect bounds; 1698 int maxx, maxy, w, h, x, y;
1637 1699 SDL_Rect bounds;
1638 #ifdef DEBUG_BUILD 1700
1639 printf("[os2fslib_SetIcon] : Creating and setting new icon\n"); fflush(stdout); 1701 #ifdef DEBUG_BUILD
1640 #endif 1702 printf ("[os2fslib_SetIcon] : Creating and setting new icon\n");
1641 1703 fflush (stdout);
1642 hwndFrame = WinQueryWindow(_this->hidden->hwndClient, QW_PARENT); 1704 #endif
1643 1705
1644 // Make sure the old icon resource will be free'd! 1706 hwndFrame = WinQueryWindow (_this->hidden->hwndClient, QW_PARENT);
1645 os2fslib_DestroyIcon(hwndFrame); 1707
1646 1708 // Make sure the old icon resource will be free'd!
1647 if ((!icon) || (!mask)) 1709 os2fslib_DestroyIcon (hwndFrame);
1648 return; 1710
1649 1711 if ((!icon) || (!mask))
1650 w = icon->w; 1712 return;
1651 h = icon->h; 1713
1652 1714 w = icon->w;
1653 maxx = WinQuerySysValue(HWND_DESKTOP, SV_CXICON); 1715 h = icon->h;
1654 maxy = WinQuerySysValue(HWND_DESKTOP, SV_CYICON); 1716
1655 1717 maxx = WinQuerySysValue (HWND_DESKTOP, SV_CXICON);
1656 // Check for max size! 1718 maxy = WinQuerySysValue (HWND_DESKTOP, SV_CYICON);
1657 if ((w>maxx) || (h>maxy)) 1719
1658 return; 1720 // Check for max size!
1659 1721 if ((w > maxx) || (h > maxy))
1660 pchTemp = (char *) SDL_malloc(w * h*2 * 4); 1722 return;
1661 if (!pchTemp) 1723
1662 return; 1724 pchTemp = (char *) SDL_malloc (w * h * 2 * 4);
1663 1725 if (!pchTemp)
1664 SDL_memset(pchTemp, 0, w * h*2 * 4); 1726 return;
1665 1727
1666 // Convert surface to RGB, if it's not RGB yet! 1728 SDL_memset (pchTemp, 0, w * h * 2 * 4);
1667 icon_rgb = SDL_CreateRGBSurface(SDL_SWSURFACE, icon->w, icon->h, 1729
1668 32, 0, 0, 0, 0); 1730 // Convert surface to RGB, if it's not RGB yet!
1669 if ( icon_rgb == NULL ) 1731 icon_rgb = SDL_CreateRGBSurface (SDL_SWSURFACE, icon->w, icon->h,
1670 { 1732 32, 0, 0, 0, 0);
1671 SDL_free(pchTemp); 1733 if (icon_rgb == NULL) {
1672 return; 1734 SDL_free (pchTemp);
1673 } 1735 return;
1674 bounds.x = 0; 1736 }
1675 bounds.y = 0; 1737 bounds.x = 0;
1676 bounds.w = icon->w; 1738 bounds.y = 0;
1677 bounds.h = icon->h; 1739 bounds.w = icon->w;
1678 if ( SDL_LowerBlit(icon, &bounds, icon_rgb, &bounds) < 0 ) 1740 bounds.h = icon->h;
1679 { 1741 if (SDL_LowerBlit (icon, &bounds, icon_rgb, &bounds) < 0) {
1680 SDL_FreeSurface(icon_rgb); 1742 SDL_FreeSurface (icon_rgb);
1681 SDL_free(pchTemp); 1743 SDL_free (pchTemp);
1682 return; 1744 return;
1683 } 1745 }
1684 1746
1685 /* Copy pixels upside-down from RGB surface into BMP, masked with the icon mask */ 1747 /* Copy pixels upside-down from RGB surface into BMP, masked with the icon mask */
1686 1748
1687 // Pixels 1749 // Pixels
1688 pptr = (char *) (icon_rgb->pixels); 1750 pptr = (char *) (icon_rgb->pixels);
1689 // Mask 1751 // Mask
1690 mptr = mask; 1752 mptr = mask;
1691 1753
1692 for (y=0; y<h; y++) 1754 for (y = 0; y < h; y++) {
1693 { 1755 unsigned char uchMaskByte;
1694 unsigned char uchMaskByte; 1756
1695 1757 // Destination
1696 // Destination 1758 dptr = pchTemp + w * 4 * (h - y - 1);
1697 dptr = pchTemp + w*4 * (h-y-1); 1759 // Destination mask
1698 // Destination mask 1760 dmptr = pchTemp + w * h * 4 + w * 4 * (h - y - 1);
1699 dmptr = pchTemp + w*h*4 + w*4 * (h-y-1); 1761
1700 1762 for (x = 0; x < w; x++) {
1701 for (x=0; x<w; x++) 1763 if (x % 8 == 0) {
1702 { 1764 uchMaskByte = (unsigned char) (*mptr);
1703 if (x%8==0) 1765 mptr++;
1704 { 1766 } else
1705 uchMaskByte = (unsigned char) (*mptr); 1767 uchMaskByte <<= 1;
1706 mptr++; 1768
1707 } else 1769 if (uchMaskByte & 0x80) {
1708 uchMaskByte <<= 1; 1770 // Copy RGB
1709 1771 *dptr++ = *pptr++;
1710 if (uchMaskByte & 0x80) 1772 *dptr++ = *pptr++;
1711 { 1773 *dptr++ = *pptr++;
1712 // Copy RGB 1774 *dptr++ = *pptr++;
1713 *dptr++ = *pptr++; 1775
1714 *dptr++ = *pptr++; 1776 *dmptr++ = 0;
1715 *dptr++ = *pptr++; 1777 *dmptr++ = 0;
1716 *dptr++ = *pptr++; 1778 *dmptr++ = 0;
1717 1779 *dmptr++ = 0;
1718 *dmptr++ = 0; 1780 } else {
1719 *dmptr++ = 0; 1781 // Set pixels to fully transparent
1720 *dmptr++ = 0; 1782 *dptr++ = 0;
1721 *dmptr++ = 0; 1783 pptr++;
1722 } else 1784 *dptr++ = 0;
1723 { 1785 pptr++;
1724 // Set pixels to fully transparent 1786 *dptr++ = 0;
1725 *dptr++ = 0; pptr++; 1787 pptr++;
1726 *dptr++ = 0; pptr++; 1788 *dptr++ = 0;
1727 *dptr++ = 0; pptr++; 1789 pptr++;
1728 *dptr++ = 0; pptr++; 1790
1729 1791 *dmptr++ = 255;
1730 *dmptr++ = 255; 1792 *dmptr++ = 255;
1731 *dmptr++ = 255; 1793 *dmptr++ = 255;
1732 *dmptr++ = 255; 1794 *dmptr++ = 255;
1733 *dmptr++ = 255; 1795 }
1734 } 1796 }
1735 } 1797 }
1736 } 1798
1737 1799 // There is no more need for the RGB surface
1738 // There is no more need for the RGB surface 1800 SDL_FreeSurface (icon_rgb);
1739 SDL_FreeSurface(icon_rgb); 1801
1740 1802 hps = WinGetPS (_this->hidden->hwndClient);
1741 hps = WinGetPS(_this->hidden->hwndClient); 1803
1742 1804 bmi.cbFix = sizeof (BITMAPINFOHEADER);
1743 bmi.cbFix = sizeof(BITMAPINFOHEADER); 1805 bmi.cx = w;
1744 bmi.cx = w; 1806 bmi.cy = 2 * h;
1745 bmi.cy = 2*h; 1807 bmi.cPlanes = 1;
1746 bmi.cPlanes = 1; 1808 bmi.cBitCount = 32;
1747 bmi.cBitCount = 32; 1809
1748 1810 SDL_memset (&bmih, 0, sizeof (BITMAPINFOHEADER));
1749 SDL_memset(&bmih, 0, sizeof(BITMAPINFOHEADER)); 1811 bmih.cbFix = sizeof (BITMAPINFOHEADER);
1750 bmih.cbFix = sizeof(BITMAPINFOHEADER); 1812 bmih.cx = w;
1751 bmih.cx = w; 1813 bmih.cy = 2 * h;
1752 bmih.cy = 2*h; 1814 bmih.cPlanes = 1;
1753 bmih.cPlanes = 1; 1815 bmih.cBitCount = 32;
1754 bmih.cBitCount = 32; 1816
1755 1817 hbm =
1756 hbm = GpiCreateBitmap(hps, (PBITMAPINFOHEADER2)&bmih, CBM_INIT, (PBYTE) pchTemp, (PBITMAPINFO2)&bmi); 1818 GpiCreateBitmap (hps, (PBITMAPINFOHEADER2) & bmih, CBM_INIT,
1757 hptrIcon = WinCreatePointer(HWND_DESKTOP, hbm, FALSE, 0, 0); 1819 (PBYTE) pchTemp, (PBITMAPINFO2) & bmi);
1758 1820 hptrIcon = WinCreatePointer (HWND_DESKTOP, hbm, FALSE, 0, 0);
1759 WinReleasePS(hps); 1821
1760 1822 WinReleasePS (hps);
1761 // Free pixel array 1823
1762 SDL_free(pchTemp); 1824 // Free pixel array
1763 1825 SDL_free (pchTemp);
1764 // Change icon in frame window 1826
1765 WinSendMsg(hwndFrame, 1827 // Change icon in frame window
1766 WM_SETICON, 1828 WinSendMsg (hwndFrame, WM_SETICON, (MPARAM) hptrIcon, NULL);
1767 (MPARAM) hptrIcon, 1829
1768 NULL); 1830 /*
1769 1831 // Change icon in switchlist
1770 /* 1832 // Seems like it's not needed, the WM_SETICON already does it.
1771 // Change icon in switchlist 1833 {
1772 // Seems like it's not needed, the WM_SETICON already does it. 1834 PID pidFrame;
1773 { 1835 HSWITCH hswitchFrame;
1774 PID pidFrame; 1836 SWCNTRL swctl;
1775 HSWITCH hswitchFrame; 1837
1776 SWCNTRL swctl; 1838 WinQueryWindowProcess(hwndFrame, &pidFrame, NULL);
1777 1839 hswitchFrame = WinQuerySwitchHandle(hwndFrame, pidFrame);
1778 WinQueryWindowProcess(hwndFrame, &pidFrame, NULL); 1840 WinQuerySwitchEntry(hswitchFrame, &swctl);
1779 hswitchFrame = WinQuerySwitchHandle(hwndFrame, pidFrame); 1841
1780 WinQuerySwitchEntry(hswitchFrame, &swctl); 1842 swctl.hwndIcon = hptrIcon;
1781 1843
1782 swctl.hwndIcon = hptrIcon; 1844 WinChangeSwitchEntry(hswitchFrame, &swctl);
1783 1845 }
1784 WinChangeSwitchEntry(hswitchFrame, &swctl); 1846 */
1785 } 1847
1786 */ 1848 // Store icon handle in global variable
1787 1849 hptrCurrentIcon = hptrIcon;
1788 // Store icon handle in global variable
1789 hptrCurrentIcon = hptrIcon;
1790 } 1850 }
1791 1851
1792 // ------------------------ REAL FUNCTIONS ----------------- 1852 // ------------------------ REAL FUNCTIONS -----------------
1793 1853
1794 1854
1795 static void os2fslib_SetCursorManagementFunctions(_THIS, int iForWindowedMode) 1855 static void
1796 { 1856 os2fslib_SetCursorManagementFunctions (_THIS, int iForWindowedMode)
1797 if (iForWindowedMode) 1857 {
1798 { 1858 if (iForWindowedMode) {
1799 _this->FreeWMCursor = os2fslib_FreeWMCursor; 1859 _this->FreeWMCursor = os2fslib_FreeWMCursor;
1800 _this->CreateWMCursor = os2fslib_CreateWMCursor_Win; 1860 _this->CreateWMCursor = os2fslib_CreateWMCursor_Win;
1801 _this->ShowWMCursor = os2fslib_ShowWMCursor; 1861 _this->ShowWMCursor = os2fslib_ShowWMCursor;
1802 _this->WarpWMCursor = os2fslib_WarpWMCursor; 1862 _this->WarpWMCursor = os2fslib_WarpWMCursor;
1803 _this->MoveWMCursor = os2fslib_MoveWMCursor; 1863 _this->MoveWMCursor = os2fslib_MoveWMCursor;
1804 _this->CheckMouseMode = NULL;//os2fslib_CheckMouseMode; 1864 _this->CheckMouseMode = NULL; //os2fslib_CheckMouseMode;
1805 } else 1865 } else {
1806 { 1866 // We'll have software mouse cursor in FS mode!
1807 // We'll have software mouse cursor in FS mode! 1867 _this->FreeWMCursor = os2fslib_FreeWMCursor;
1808 _this->FreeWMCursor = os2fslib_FreeWMCursor; 1868 _this->CreateWMCursor = os2fslib_CreateWMCursor_FS;
1809 _this->CreateWMCursor = os2fslib_CreateWMCursor_FS; 1869 _this->ShowWMCursor = os2fslib_ShowWMCursor;
1810 _this->ShowWMCursor = os2fslib_ShowWMCursor; 1870 _this->WarpWMCursor = os2fslib_WarpWMCursor;
1811 _this->WarpWMCursor = os2fslib_WarpWMCursor; 1871 _this->MoveWMCursor = os2fslib_MoveWMCursor;
1812 _this->MoveWMCursor = os2fslib_MoveWMCursor; 1872 _this->CheckMouseMode = NULL; //os2fslib_CheckMouseMode;
1813 _this->CheckMouseMode = NULL;//os2fslib_CheckMouseMode; 1873 }
1814 } 1874 }
1815 } 1875
1816 1876 static void
1817 static void os2fslib_InitOSKeymap(_THIS) 1877 os2fslib_InitOSKeymap (_THIS)
1818 { 1878 {
1819 int i; 1879 int i;
1820 1880
1821 iShiftIsPressed = 0; 1881 iShiftIsPressed = 0;
1822 1882
1823 /* Map the VK and CH keysyms */ 1883 /* Map the VK and CH keysyms */
1824 for ( i=0; i<=255; ++i ) 1884 for (i = 0; i <= 255; ++i)
1825 HWScanKeyMap[i] = SDLK_UNKNOWN; 1885 HWScanKeyMap[i] = SDLK_UNKNOWN;
1826 1886
1827 // First line of keyboard: 1887 // First line of keyboard:
1828 HWScanKeyMap[0x1] = SDLK_ESCAPE; 1888 HWScanKeyMap[0x1] = SDLK_ESCAPE;
1829 HWScanKeyMap[0x3b] = SDLK_F1; 1889 HWScanKeyMap[0x3b] = SDLK_F1;
1830 HWScanKeyMap[0x3c] = SDLK_F2; 1890 HWScanKeyMap[0x3c] = SDLK_F2;
1831 HWScanKeyMap[0x3d] = SDLK_F3; 1891 HWScanKeyMap[0x3d] = SDLK_F3;
1832 HWScanKeyMap[0x3e] = SDLK_F4; 1892 HWScanKeyMap[0x3e] = SDLK_F4;
1833 HWScanKeyMap[0x3f] = SDLK_F5; 1893 HWScanKeyMap[0x3f] = SDLK_F5;
1834 HWScanKeyMap[0x40] = SDLK_F6; 1894 HWScanKeyMap[0x40] = SDLK_F6;
1835 HWScanKeyMap[0x41] = SDLK_F7; 1895 HWScanKeyMap[0x41] = SDLK_F7;
1836 HWScanKeyMap[0x42] = SDLK_F8; 1896 HWScanKeyMap[0x42] = SDLK_F8;
1837 HWScanKeyMap[0x43] = SDLK_F9; 1897 HWScanKeyMap[0x43] = SDLK_F9;
1838 HWScanKeyMap[0x44] = SDLK_F10; 1898 HWScanKeyMap[0x44] = SDLK_F10;
1839 HWScanKeyMap[0x57] = SDLK_F11; 1899 HWScanKeyMap[0x57] = SDLK_F11;
1840 HWScanKeyMap[0x58] = SDLK_F12; 1900 HWScanKeyMap[0x58] = SDLK_F12;
1841 HWScanKeyMap[0x5d] = SDLK_PRINT; 1901 HWScanKeyMap[0x5d] = SDLK_PRINT;
1842 HWScanKeyMap[0x46] = SDLK_SCROLLOCK; 1902 HWScanKeyMap[0x46] = SDLK_SCROLLOCK;
1843 HWScanKeyMap[0x5f] = SDLK_PAUSE; 1903 HWScanKeyMap[0x5f] = SDLK_PAUSE;
1844 1904
1845 // Second line of keyboard: 1905 // Second line of keyboard:
1846 HWScanKeyMap[0x29] = SDLK_BACKQUOTE; 1906 HWScanKeyMap[0x29] = SDLK_BACKQUOTE;
1847 HWScanKeyMap[0x2] = SDLK_1; 1907 HWScanKeyMap[0x2] = SDLK_1;
1848 HWScanKeyMap[0x3] = SDLK_2; 1908 HWScanKeyMap[0x3] = SDLK_2;
1849 HWScanKeyMap[0x4] = SDLK_3; 1909 HWScanKeyMap[0x4] = SDLK_3;
1850 HWScanKeyMap[0x5] = SDLK_4; 1910 HWScanKeyMap[0x5] = SDLK_4;
1851 HWScanKeyMap[0x6] = SDLK_5; 1911 HWScanKeyMap[0x6] = SDLK_5;
1852 HWScanKeyMap[0x7] = SDLK_6; 1912 HWScanKeyMap[0x7] = SDLK_6;
1853 HWScanKeyMap[0x8] = SDLK_7; 1913 HWScanKeyMap[0x8] = SDLK_7;
1854 HWScanKeyMap[0x9] = SDLK_8; 1914 HWScanKeyMap[0x9] = SDLK_8;
1855 HWScanKeyMap[0xa] = SDLK_9; 1915 HWScanKeyMap[0xa] = SDLK_9;
1856 HWScanKeyMap[0xb] = SDLK_0; 1916 HWScanKeyMap[0xb] = SDLK_0;
1857 HWScanKeyMap[0xc] = SDLK_MINUS; 1917 HWScanKeyMap[0xc] = SDLK_MINUS;
1858 HWScanKeyMap[0xd] = SDLK_EQUALS; 1918 HWScanKeyMap[0xd] = SDLK_EQUALS;
1859 HWScanKeyMap[0xe] = SDLK_BACKSPACE; 1919 HWScanKeyMap[0xe] = SDLK_BACKSPACE;
1860 HWScanKeyMap[0x68] = SDLK_INSERT; 1920 HWScanKeyMap[0x68] = SDLK_INSERT;
1861 HWScanKeyMap[0x60] = SDLK_HOME; 1921 HWScanKeyMap[0x60] = SDLK_HOME;
1862 HWScanKeyMap[0x62] = SDLK_PAGEUP; 1922 HWScanKeyMap[0x62] = SDLK_PAGEUP;
1863 HWScanKeyMap[0x45] = SDLK_NUMLOCK; 1923 HWScanKeyMap[0x45] = SDLK_NUMLOCK;
1864 HWScanKeyMap[0x5c] = SDLK_KP_DIVIDE; 1924 HWScanKeyMap[0x5c] = SDLK_KP_DIVIDE;
1865 HWScanKeyMap[0x37] = SDLK_KP_MULTIPLY; 1925 HWScanKeyMap[0x37] = SDLK_KP_MULTIPLY;
1866 HWScanKeyMap[0x4a] = SDLK_KP_MINUS; 1926 HWScanKeyMap[0x4a] = SDLK_KP_MINUS;
1867 1927
1868 // Third line of keyboard: 1928 // Third line of keyboard:
1869 HWScanKeyMap[0xf] = SDLK_TAB; 1929 HWScanKeyMap[0xf] = SDLK_TAB;
1870 HWScanKeyMap[0x10] = SDLK_q; 1930 HWScanKeyMap[0x10] = SDLK_q;
1871 HWScanKeyMap[0x11] = SDLK_w; 1931 HWScanKeyMap[0x11] = SDLK_w;
1872 HWScanKeyMap[0x12] = SDLK_e; 1932 HWScanKeyMap[0x12] = SDLK_e;
1873 HWScanKeyMap[0x13] = SDLK_r; 1933 HWScanKeyMap[0x13] = SDLK_r;
1874 HWScanKeyMap[0x14] = SDLK_t; 1934 HWScanKeyMap[0x14] = SDLK_t;
1875 HWScanKeyMap[0x15] = SDLK_y; 1935 HWScanKeyMap[0x15] = SDLK_y;
1876 HWScanKeyMap[0x16] = SDLK_u; 1936 HWScanKeyMap[0x16] = SDLK_u;
1877 HWScanKeyMap[0x17] = SDLK_i; 1937 HWScanKeyMap[0x17] = SDLK_i;
1878 HWScanKeyMap[0x18] = SDLK_o; 1938 HWScanKeyMap[0x18] = SDLK_o;
1879 HWScanKeyMap[0x19] = SDLK_p; 1939 HWScanKeyMap[0x19] = SDLK_p;
1880 HWScanKeyMap[0x1a] = SDLK_LEFTBRACKET; 1940 HWScanKeyMap[0x1a] = SDLK_LEFTBRACKET;
1881 HWScanKeyMap[0x1b] = SDLK_RIGHTBRACKET; 1941 HWScanKeyMap[0x1b] = SDLK_RIGHTBRACKET;
1882 HWScanKeyMap[0x1c] = SDLK_RETURN; 1942 HWScanKeyMap[0x1c] = SDLK_RETURN;
1883 HWScanKeyMap[0x69] = SDLK_DELETE; 1943 HWScanKeyMap[0x69] = SDLK_DELETE;
1884 HWScanKeyMap[0x65] = SDLK_END; 1944 HWScanKeyMap[0x65] = SDLK_END;
1885 HWScanKeyMap[0x67] = SDLK_PAGEDOWN; 1945 HWScanKeyMap[0x67] = SDLK_PAGEDOWN;
1886 HWScanKeyMap[0x47] = SDLK_KP7; 1946 HWScanKeyMap[0x47] = SDLK_KP7;
1887 HWScanKeyMap[0x48] = SDLK_KP8; 1947 HWScanKeyMap[0x48] = SDLK_KP8;
1888 HWScanKeyMap[0x49] = SDLK_KP9; 1948 HWScanKeyMap[0x49] = SDLK_KP9;
1889 HWScanKeyMap[0x4e] = SDLK_KP_PLUS; 1949 HWScanKeyMap[0x4e] = SDLK_KP_PLUS;
1890 1950
1891 // Fourth line of keyboard: 1951 // Fourth line of keyboard:
1892 HWScanKeyMap[0x3a] = SDLK_CAPSLOCK; 1952 HWScanKeyMap[0x3a] = SDLK_CAPSLOCK;
1893 HWScanKeyMap[0x1e] = SDLK_a; 1953 HWScanKeyMap[0x1e] = SDLK_a;
1894 HWScanKeyMap[0x1f] = SDLK_s; 1954 HWScanKeyMap[0x1f] = SDLK_s;
1895 HWScanKeyMap[0x20] = SDLK_d; 1955 HWScanKeyMap[0x20] = SDLK_d;
1896 HWScanKeyMap[0x21] = SDLK_f; 1956 HWScanKeyMap[0x21] = SDLK_f;
1897 HWScanKeyMap[0x22] = SDLK_g; 1957 HWScanKeyMap[0x22] = SDLK_g;
1898 HWScanKeyMap[0x23] = SDLK_h; 1958 HWScanKeyMap[0x23] = SDLK_h;
1899 HWScanKeyMap[0x24] = SDLK_j; 1959 HWScanKeyMap[0x24] = SDLK_j;
1900 HWScanKeyMap[0x25] = SDLK_k; 1960 HWScanKeyMap[0x25] = SDLK_k;
1901 HWScanKeyMap[0x26] = SDLK_l; 1961 HWScanKeyMap[0x26] = SDLK_l;
1902 HWScanKeyMap[0x27] = SDLK_SEMICOLON; 1962 HWScanKeyMap[0x27] = SDLK_SEMICOLON;
1903 HWScanKeyMap[0x28] = SDLK_QUOTE; 1963 HWScanKeyMap[0x28] = SDLK_QUOTE;
1904 HWScanKeyMap[0x2b] = SDLK_BACKSLASH; 1964 HWScanKeyMap[0x2b] = SDLK_BACKSLASH;
1905 HWScanKeyMap[0x4b] = SDLK_KP4; 1965 HWScanKeyMap[0x4b] = SDLK_KP4;
1906 HWScanKeyMap[0x4c] = SDLK_KP5; 1966 HWScanKeyMap[0x4c] = SDLK_KP5;
1907 HWScanKeyMap[0x4d] = SDLK_KP6; 1967 HWScanKeyMap[0x4d] = SDLK_KP6;
1908 1968
1909 // Fifth line of keyboard: 1969 // Fifth line of keyboard:
1910 HWScanKeyMap[0x2a] = SDLK_LSHIFT; 1970 HWScanKeyMap[0x2a] = SDLK_LSHIFT;
1911 HWScanKeyMap[0x56] = SDLK_WORLD_1; // Code 161, letter i' on hungarian keyboard 1971 HWScanKeyMap[0x56] = SDLK_WORLD_1; // Code 161, letter i' on hungarian keyboard
1912 HWScanKeyMap[0x2c] = SDLK_z; 1972 HWScanKeyMap[0x2c] = SDLK_z;
1913 HWScanKeyMap[0x2d] = SDLK_x; 1973 HWScanKeyMap[0x2d] = SDLK_x;
1914 HWScanKeyMap[0x2e] = SDLK_c; 1974 HWScanKeyMap[0x2e] = SDLK_c;
1915 HWScanKeyMap[0x2f] = SDLK_v; 1975 HWScanKeyMap[0x2f] = SDLK_v;
1916 HWScanKeyMap[0x30] = SDLK_b; 1976 HWScanKeyMap[0x30] = SDLK_b;
1917 HWScanKeyMap[0x31] = SDLK_n; 1977 HWScanKeyMap[0x31] = SDLK_n;
1918 HWScanKeyMap[0x32] = SDLK_m; 1978 HWScanKeyMap[0x32] = SDLK_m;
1919 HWScanKeyMap[0x33] = SDLK_COMMA; 1979 HWScanKeyMap[0x33] = SDLK_COMMA;
1920 HWScanKeyMap[0x34] = SDLK_PERIOD; 1980 HWScanKeyMap[0x34] = SDLK_PERIOD;
1921 HWScanKeyMap[0x35] = SDLK_SLASH; 1981 HWScanKeyMap[0x35] = SDLK_SLASH;
1922 HWScanKeyMap[0x36] = SDLK_RSHIFT; 1982 HWScanKeyMap[0x36] = SDLK_RSHIFT;
1923 HWScanKeyMap[0x61] = SDLK_UP; 1983 HWScanKeyMap[0x61] = SDLK_UP;
1924 HWScanKeyMap[0x4f] = SDLK_KP1; 1984 HWScanKeyMap[0x4f] = SDLK_KP1;
1925 HWScanKeyMap[0x50] = SDLK_KP2; 1985 HWScanKeyMap[0x50] = SDLK_KP2;
1926 HWScanKeyMap[0x51] = SDLK_KP3; 1986 HWScanKeyMap[0x51] = SDLK_KP3;
1927 HWScanKeyMap[0x5a] = SDLK_KP_ENTER; 1987 HWScanKeyMap[0x5a] = SDLK_KP_ENTER;
1928 1988
1929 // Sixth line of keyboard: 1989 // Sixth line of keyboard:
1930 HWScanKeyMap[0x1d] = SDLK_LCTRL; 1990 HWScanKeyMap[0x1d] = SDLK_LCTRL;
1931 HWScanKeyMap[0x7e] = SDLK_LSUPER; // Windows key 1991 HWScanKeyMap[0x7e] = SDLK_LSUPER; // Windows key
1932 HWScanKeyMap[0x38] = SDLK_LALT; 1992 HWScanKeyMap[0x38] = SDLK_LALT;
1933 HWScanKeyMap[0x39] = SDLK_SPACE; 1993 HWScanKeyMap[0x39] = SDLK_SPACE;
1934 HWScanKeyMap[0x5e] = SDLK_RALT;// Actually, altgr on my keyboard... 1994 HWScanKeyMap[0x5e] = SDLK_RALT; // Actually, altgr on my keyboard...
1935 HWScanKeyMap[0x7f] = SDLK_RSUPER; 1995 HWScanKeyMap[0x7f] = SDLK_RSUPER;
1936 HWScanKeyMap[0x7c] = SDLK_MENU; 1996 HWScanKeyMap[0x7c] = SDLK_MENU;
1937 HWScanKeyMap[0x5b] = SDLK_RCTRL; 1997 HWScanKeyMap[0x5b] = SDLK_RCTRL;
1938 HWScanKeyMap[0x63] = SDLK_LEFT; 1998 HWScanKeyMap[0x63] = SDLK_LEFT;
1939 HWScanKeyMap[0x66] = SDLK_DOWN; 1999 HWScanKeyMap[0x66] = SDLK_DOWN;
1940 HWScanKeyMap[0x64] = SDLK_RIGHT; 2000 HWScanKeyMap[0x64] = SDLK_RIGHT;
1941 HWScanKeyMap[0x52] = SDLK_KP0; 2001 HWScanKeyMap[0x52] = SDLK_KP0;
1942 HWScanKeyMap[0x53] = SDLK_KP_PERIOD; 2002 HWScanKeyMap[0x53] = SDLK_KP_PERIOD;
1943 } 2003 }
1944 2004
1945 2005
1946 /* Iconify the window. 2006 /* Iconify the window.
1947 This function returns 1 if there is a window manager and the 2007 This function returns 1 if there is a window manager and the
1948 window was actually iconified, it returns 0 otherwise. 2008 window was actually iconified, it returns 0 otherwise.
1949 */ 2009 */
1950 int os2fslib_IconifyWindow(_THIS) 2010 int
1951 { 2011 os2fslib_IconifyWindow (_THIS)
1952 HAB hab; 2012 {
1953 HMQ hmq; 2013 HAB hab;
1954 ERRORID hmqerror; 2014 HMQ hmq;
1955 2015 ERRORID hmqerror;
1956 // If there is no more window, nothing we can do! 2016
1957 if (_this->hidden->iPMThreadStatus!=1) return 0; 2017 // If there is no more window, nothing we can do!
1958 2018 if (_this->hidden->iPMThreadStatus != 1)
1959 // Cannot do anything in fullscreen mode! 2019 return 0;
1960 if (FSLib_QueryFSMode(_this->hidden->hwndClient)) 2020
1961 return 0; 2021 // Cannot do anything in fullscreen mode!
1962 2022 if (FSLib_QueryFSMode (_this->hidden->hwndClient))
1963 // Make sure this thread is prepared for using the Presentation Manager! 2023 return 0;
1964 hab = WinInitialize(0); 2024
1965 hmq = WinCreateMsgQueue(hab,0); 2025 // Make sure this thread is prepared for using the Presentation Manager!
1966 // Remember if there was an error at WinCreateMsgQueue(), because we don't 2026 hab = WinInitialize (0);
1967 // want to destroy somebody else's queue later. :) 2027 hmq = WinCreateMsgQueue (hab, 0);
1968 hmqerror = WinGetLastError(hab); 2028 // Remember if there was an error at WinCreateMsgQueue(), because we don't
1969 2029 // want to destroy somebody else's queue later. :)
1970 WinSetWindowPos(_this->hidden->hwndFrame, HWND_TOP, 2030 hmqerror = WinGetLastError (hab);
1971 0, 0, 0, 0, SWP_MINIMIZE); 2031
1972 2032 WinSetWindowPos (_this->hidden->hwndFrame, HWND_TOP,
1973 // Now destroy the message queue, if we've created it! 2033 0, 0, 0, 0, SWP_MINIMIZE);
1974 if (ERRORIDERROR(hmqerror)==0) 2034
1975 WinDestroyMsgQueue(hmq); 2035 // Now destroy the message queue, if we've created it!
1976 2036 if (ERRORIDERROR (hmqerror) == 0)
1977 return 1; 2037 WinDestroyMsgQueue (hmq);
1978 } 2038
1979 2039 return 1;
1980 static SDL_GrabMode os2fslib_GrabInput(_THIS, SDL_GrabMode mode) 2040 }
1981 { 2041
1982 HAB hab; 2042 static SDL_GrabMode
1983 HMQ hmq; 2043 os2fslib_GrabInput (_THIS, SDL_GrabMode mode)
1984 ERRORID hmqerror; 2044 {
1985 2045 HAB hab;
1986 2046 HMQ hmq;
1987 // If there is no more window, nothing we can do! 2047 ERRORID hmqerror;
1988 if (_this->hidden->iPMThreadStatus!=1) 2048
1989 return SDL_GRAB_OFF; 2049
1990 2050 // If there is no more window, nothing we can do!
1991 // Make sure this thread is prepared for using the Presentation Manager! 2051 if (_this->hidden->iPMThreadStatus != 1)
1992 hab = WinInitialize(0); 2052 return SDL_GRAB_OFF;
1993 hmq = WinCreateMsgQueue(hab,0); 2053
1994 // Remember if there was an error at WinCreateMsgQueue(), because we don't 2054 // Make sure this thread is prepared for using the Presentation Manager!
1995 // want to destroy somebody else's queue later. :) 2055 hab = WinInitialize (0);
1996 hmqerror = WinGetLastError(hab); 2056 hmq = WinCreateMsgQueue (hab, 0);
1997 2057 // Remember if there was an error at WinCreateMsgQueue(), because we don't
1998 2058 // want to destroy somebody else's queue later. :)
1999 if (mode == SDL_GRAB_OFF) 2059 hmqerror = WinGetLastError (hab);
2000 { 2060
2001 #ifdef DEBUG_BUILD 2061
2002 printf("[os2fslib_GrabInput] : Releasing mouse\n"); fflush(stdout); 2062 if (mode == SDL_GRAB_OFF) {
2003 #endif 2063 #ifdef DEBUG_BUILD
2004 2064 printf ("[os2fslib_GrabInput] : Releasing mouse\n");
2005 // Release the mouse 2065 fflush (stdout);
2006 bMouseCapturable = 0; 2066 #endif
2007 if (bMouseCaptured) 2067
2008 { 2068 // Release the mouse
2009 WinSetCapture(HWND_DESKTOP, NULLHANDLE); 2069 bMouseCapturable = 0;
2010 bMouseCaptured = 0; 2070 if (bMouseCaptured) {
2011 } 2071 WinSetCapture (HWND_DESKTOP, NULLHANDLE);
2012 } else 2072 bMouseCaptured = 0;
2013 { 2073 }
2014 #ifdef DEBUG_BUILD 2074 } else {
2015 printf("[os2fslib_GrabInput] : Capturing mouse\n"); fflush(stdout); 2075 #ifdef DEBUG_BUILD
2016 #endif 2076 printf ("[os2fslib_GrabInput] : Capturing mouse\n");
2017 2077 fflush (stdout);
2018 // Capture the mouse 2078 #endif
2019 bMouseCapturable = 1; 2079
2020 if (WinQueryFocus(HWND_DESKTOP) == _this->hidden->hwndClient) 2080 // Capture the mouse
2021 { 2081 bMouseCapturable = 1;
2022 WinSetCapture(HWND_DESKTOP, _this->hidden->hwndClient); 2082 if (WinQueryFocus (HWND_DESKTOP) == _this->hidden->hwndClient) {
2023 bMouseCaptured = 1; 2083 WinSetCapture (HWND_DESKTOP, _this->hidden->hwndClient);
2024 { 2084 bMouseCaptured = 1;
2025 SWP swpClient; 2085 {
2026 POINTL ptl; 2086 SWP swpClient;
2027 // Center the mouse to the middle of the window! 2087 POINTL ptl;
2028 WinQueryWindowPos(_this->hidden->hwndClient, &swpClient); 2088 // Center the mouse to the middle of the window!
2029 ptl.x = 0; ptl.y = 0; 2089 WinQueryWindowPos (_this->hidden->hwndClient, &swpClient);
2030 WinMapWindowPoints(_this->hidden->hwndClient, HWND_DESKTOP, &ptl, 1); 2090 ptl.x = 0;
2031 _this->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */ 2091 ptl.y = 0;
2032 WinSetPointerPos(HWND_DESKTOP, 2092 WinMapWindowPoints (_this->hidden->hwndClient,
2033 ptl.x + swpClient.cx/2, 2093 HWND_DESKTOP, &ptl, 1);
2034 ptl.y + swpClient.cy/2); 2094 _this->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
2035 } 2095 WinSetPointerPos (HWND_DESKTOP,
2036 } 2096 ptl.x + swpClient.cx / 2,
2037 } 2097 ptl.y + swpClient.cy / 2);
2038 2098 }
2039 // Now destroy the message queue, if we've created it! 2099 }
2040 if (ERRORIDERROR(hmqerror)==0) 2100 }
2041 WinDestroyMsgQueue(hmq); 2101
2042 2102 // Now destroy the message queue, if we've created it!
2043 return mode; 2103 if (ERRORIDERROR (hmqerror) == 0)
2104 WinDestroyMsgQueue (hmq);
2105
2106 return mode;
2044 } 2107 }
2045 2108
2046 /* Set the title and icon text */ 2109 /* Set the title and icon text */
2047 static void os2fslib_SetCaption(_THIS, const char *title, const char *icon) 2110 static void
2048 { 2111 os2fslib_SetCaption (_THIS, const char *title, const char *icon)
2049 HAB hab; 2112 {
2050 HMQ hmq; 2113 HAB hab;
2051 ERRORID hmqerror; 2114 HMQ hmq;
2052 2115 ERRORID hmqerror;
2053 // If there is no more window, nothing we can do! 2116
2054 if (_this->hidden->iPMThreadStatus!=1) return; 2117 // If there is no more window, nothing we can do!
2055 2118 if (_this->hidden->iPMThreadStatus != 1)
2056 // Make sure this thread is prepared for using the Presentation Manager! 2119 return;
2057 hab = WinInitialize(0); 2120
2058 hmq = WinCreateMsgQueue(hab,0); 2121 // Make sure this thread is prepared for using the Presentation Manager!
2059 // Remember if there was an error at WinCreateMsgQueue(), because we don't 2122 hab = WinInitialize (0);
2060 // want to destroy somebody else's queue later. :) 2123 hmq = WinCreateMsgQueue (hab, 0);
2061 hmqerror = WinGetLastError(hab); 2124 // Remember if there was an error at WinCreateMsgQueue(), because we don't
2062 2125 // want to destroy somebody else's queue later. :)
2063 WinSetWindowText(_this->hidden->hwndFrame, (char *) title); 2126 hmqerror = WinGetLastError (hab);
2064 2127
2065 // Now destroy the message queue, if we've created it! 2128 WinSetWindowText (_this->hidden->hwndFrame, (char *) title);
2066 if (ERRORIDERROR(hmqerror)==0) 2129
2067 WinDestroyMsgQueue(hmq); 2130 // Now destroy the message queue, if we've created it!
2068 } 2131 if (ERRORIDERROR (hmqerror) == 0)
2069 2132 WinDestroyMsgQueue (hmq);
2070 static int os2fslib_ToggleFullScreen(_THIS, int on) 2133 }
2071 { 2134
2072 #ifdef DEBUG_BUILD 2135 static int
2073 printf("[os2fslib_ToggleFullScreen] : %d\n", on); fflush(stdout); 2136 os2fslib_ToggleFullScreen (_THIS, int on)
2074 #endif 2137 {
2075 // If there is no more window, nothing we can do! 2138 #ifdef DEBUG_BUILD
2076 if (_this->hidden->iPMThreadStatus!=1) return 0; 2139 printf ("[os2fslib_ToggleFullScreen] : %d\n", on);
2077 2140 fflush (stdout);
2078 FSLib_ToggleFSMode(_this->hidden->hwndClient, on); 2141 #endif
2079 /* Cursor manager functions to Windowed/FS mode*/ 2142 // If there is no more window, nothing we can do!
2080 os2fslib_SetCursorManagementFunctions(_this, !on); 2143 if (_this->hidden->iPMThreadStatus != 1)
2081 return 1; 2144 return 0;
2145
2146 FSLib_ToggleFSMode (_this->hidden->hwndClient, on);
2147 /* Cursor manager functions to Windowed/FS mode */
2148 os2fslib_SetCursorManagementFunctions (_this, !on);
2149 return 1;
2082 } 2150 }
2083 2151
2084 /* This is called after the video mode has been set, to get the 2152 /* This is called after the video mode has been set, to get the
2085 initial mouse state. It should queue events as necessary to 2153 initial mouse state. It should queue events as necessary to
2086 properly represent the current mouse focus and position. 2154 properly represent the current mouse focus and position.
2087 */ 2155 */
2088 static void os2fslib_UpdateMouse(_THIS) 2156 static void
2089 { 2157 os2fslib_UpdateMouse (_THIS)
2090 POINTL ptl; 2158 {
2091 HAB hab; 2159 POINTL ptl;
2092 HMQ hmq; 2160 HAB hab;
2093 ERRORID hmqerror; 2161 HMQ hmq;
2094 SWP swpClient; 2162 ERRORID hmqerror;
2095 2163 SWP swpClient;
2096 // If there is no more window, nothing we can do! 2164
2097 if (_this->hidden->iPMThreadStatus!=1) return; 2165 // If there is no more window, nothing we can do!
2098 2166 if (_this->hidden->iPMThreadStatus != 1)
2099 2167 return;
2100 // Make sure this thread is prepared for using the Presentation Manager! 2168
2101 hab = WinInitialize(0); 2169
2102 hmq = WinCreateMsgQueue(hab,0); 2170 // Make sure this thread is prepared for using the Presentation Manager!
2103 // Remember if there was an error at WinCreateMsgQueue(), because we don't 2171 hab = WinInitialize (0);
2104 // want to destroy somebody else's queue later. :) 2172 hmq = WinCreateMsgQueue (hab, 0);
2105 hmqerror = WinGetLastError(hab); 2173 // Remember if there was an error at WinCreateMsgQueue(), because we don't
2106 2174 // want to destroy somebody else's queue later. :)
2107 2175 hmqerror = WinGetLastError (hab);
2108 2176
2109 if (_this->hidden->fInFocus) 2177
2110 { 2178
2111 // If our app is in focus 2179 if (_this->hidden->fInFocus) {
2112 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); 2180 // If our app is in focus
2113 SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); 2181 SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS);
2114 SDL_PrivateAppActive(1, SDL_APPACTIVE); 2182 SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS);
2115 WinQueryPointerPos(HWND_DESKTOP, &ptl); 2183 SDL_PrivateAppActive (1, SDL_APPACTIVE);
2116 WinMapWindowPoints(HWND_DESKTOP, _this->hidden->hwndClient, &ptl, 1); 2184 WinQueryPointerPos (HWND_DESKTOP, &ptl);
2117 WinQueryWindowPos(_this->hidden->hwndClient, &swpClient); 2185 WinMapWindowPoints (HWND_DESKTOP, _this->hidden->hwndClient, &ptl, 1);
2118 // Convert OS/2 mouse position to SDL position, and also scale it! 2186 WinQueryWindowPos (_this->hidden->hwndClient, &swpClient);
2119 ptl.x = ptl.x * _this->hidden->SrcBufferDesc.uiXResolution / swpClient.cx; 2187 // Convert OS/2 mouse position to SDL position, and also scale it!
2120 ptl.y = ptl.y * _this->hidden->SrcBufferDesc.uiYResolution / swpClient.cy; 2188 ptl.x =
2121 ptl.y = _this->hidden->SrcBufferDesc.uiYResolution - ptl.y - 1; 2189 ptl.x * _this->hidden->SrcBufferDesc.uiXResolution / swpClient.cx;
2122 SDL_PrivateMouseMotion(0, 0, (Sint16) (ptl.x), (Sint16) (ptl.y)); 2190 ptl.y =
2123 } else 2191 ptl.y * _this->hidden->SrcBufferDesc.uiYResolution / swpClient.cy;
2124 { 2192 ptl.y = _this->hidden->SrcBufferDesc.uiYResolution - ptl.y - 1;
2125 // If we're not in focus 2193 SDL_PrivateMouseMotion (0, 0, (Sint16) (ptl.x), (Sint16) (ptl.y));
2126 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); 2194 } else {
2127 SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS); 2195 // If we're not in focus
2128 SDL_PrivateAppActive(0, SDL_APPACTIVE); 2196 SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS);
2129 SDL_PrivateMouseMotion(0, 0, (Sint16) -1, (Sint16) -1); 2197 SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
2130 } 2198 SDL_PrivateAppActive (0, SDL_APPACTIVE);
2131 2199 SDL_PrivateMouseMotion (0, 0, (Sint16) - 1, (Sint16) - 1);
2132 // Now destroy the message queue, if we've created it! 2200 }
2133 if (ERRORIDERROR(hmqerror)==0) 2201
2134 WinDestroyMsgQueue(hmq); 2202 // Now destroy the message queue, if we've created it!
2203 if (ERRORIDERROR (hmqerror) == 0)
2204 WinDestroyMsgQueue (hmq);
2135 2205
2136 } 2206 }
2137 2207
2138 /* This pointer should exist in the native video subsystem and should 2208 /* This pointer should exist in the native video subsystem and should
2139 point to an appropriate update function for the current video mode 2209 point to an appropriate update function for the current video mode
2140 */ 2210 */
2141 static void os2fslib_UpdateRects(_THIS, int numrects, SDL_Rect *rects) 2211 static void
2142 { 2212 os2fslib_UpdateRects (_THIS, int numrects, SDL_Rect * rects)
2143 // If there is no more window, nothing we can do! 2213 {
2144 if (_this->hidden->iPMThreadStatus!=1) return; 2214 // If there is no more window, nothing we can do!
2215 if (_this->hidden->iPMThreadStatus != 1)
2216 return;
2145 2217
2146 #ifdef BITBLT_IN_WINMESSAGEPROC 2218 #ifdef BITBLT_IN_WINMESSAGEPROC
2147 WinSendMsg(_this->hidden->hwndClient, 2219 WinSendMsg (_this->hidden->hwndClient,
2148 WM_UPDATERECTSREQUEST, 2220 WM_UPDATERECTSREQUEST, (MPARAM) numrects, (MPARAM) rects);
2149 (MPARAM) numrects,
2150 (MPARAM) rects);
2151 #else 2221 #else
2152 if (DosRequestMutexSem(_this->hidden->hmtxUseSrcBuffer, SEM_INDEFINITE_WAIT)==NO_ERROR) 2222 if (DosRequestMutexSem
2153 { 2223 (_this->hidden->hmtxUseSrcBuffer, SEM_INDEFINITE_WAIT) == NO_ERROR) {
2154 int i; 2224 int i;
2155 2225
2156 if (_this->hidden->pSDLSurface) 2226 if (_this->hidden->pSDLSurface) {
2157 {
2158 #ifndef RESIZE_EVEN_IF_RESIZABLE 2227 #ifndef RESIZE_EVEN_IF_RESIZABLE
2159 SWP swp; 2228 SWP swp;
2160 // But only blit if the window is not resizable, or if 2229 // But only blit if the window is not resizable, or if
2161 // the window is resizable and the source buffer size is the 2230 // the window is resizable and the source buffer size is the
2162 // same as the destination buffer size! 2231 // same as the destination buffer size!
2163 WinQueryWindowPos(_this->hidden->hwndClient, &swp); 2232 WinQueryWindowPos (_this->hidden->hwndClient, &swp);
2164 if ((_this->hidden->pSDLSurface) && 2233 if ((_this->hidden->pSDLSurface) &&
2165 (_this->hidden->pSDLSurface->flags & SDL_RESIZABLE) && 2234 (_this->hidden->pSDLSurface->flags & SDL_RESIZABLE) &&
2166 ((swp.cx != _this->hidden->SrcBufferDesc.uiXResolution) || 2235 ((swp.cx != _this->hidden->SrcBufferDesc.uiXResolution) ||
2167 (swp.cy != _this->hidden->SrcBufferDesc.uiYResolution) 2236 (swp.cy != _this->hidden->SrcBufferDesc.uiYResolution))
2168 ) && 2237 && (!FSLib_QueryFSMode (_this->hidden->hwndClient))) {
2169 (!FSLib_QueryFSMode(_this->hidden->hwndClient)) 2238 // Resizable surface and in resizing!
2170 ) 2239 // So, don't blit now!
2171 { 2240 #ifdef DEBUG_BUILD
2172 // Resizable surface and in resizing! 2241 printf ("[UpdateRects] : Skipping blit while resizing!\n");
2173 // So, don't blit now! 2242 fflush (stdout);
2174 #ifdef DEBUG_BUILD 2243 #endif
2175 printf("[UpdateRects] : Skipping blit while resizing!\n"); fflush(stdout); 2244 } else
2176 #endif 2245 #endif
2177 } else 2246 {
2178 #endif 2247 /*
2179 { 2248 // Blit the whole window
2180 /* 2249 FSLIB_BITBLT(_this->hidden->hwndClient, _this->hidden->pchSrcBuffer,
2181 // Blit the whole window 2250 0, 0,
2182 FSLIB_BITBLT(_this->hidden->hwndClient, _this->hidden->pchSrcBuffer, 2251 _this->hidden->SrcBufferDesc.uiXResolution,
2183 0, 0, 2252 _this->hidden->SrcBufferDesc.uiYResolution);
2184 _this->hidden->SrcBufferDesc.uiXResolution, 2253 */
2185 _this->hidden->SrcBufferDesc.uiYResolution); 2254 #ifdef DEBUG_BUILD
2186 */ 2255 printf ("[os2fslib_UpdateRects] : Blitting!\n");
2187 #ifdef DEBUG_BUILD 2256 fflush (stdout);
2188 printf("[os2fslib_UpdateRects] : Blitting!\n"); fflush(stdout); 2257 #endif
2189 #endif 2258
2190 2259 // Blit the changed areas
2191 // Blit the changed areas 2260 for (i = 0; i < numrects; i++)
2192 for (i=0; i<numrects; i++) 2261 FSLIB_BITBLT (_this->hidden->hwndClient,
2193 FSLIB_BITBLT(_this->hidden->hwndClient, _this->hidden->pchSrcBuffer, 2262 _this->hidden->pchSrcBuffer,
2194 rects[i].y, rects[i].x, rects[i].w, rects[i].h); 2263 rects[i].y, rects[i].x, rects[i].w,
2195 } 2264 rects[i].h);
2196 } 2265 }
2197 #ifdef DEBUG_BUILD 2266 }
2198 else 2267 #ifdef DEBUG_BUILD
2199 printf("[os2fslib_UpdateRects] : No public surface!\n"); fflush(stdout); 2268 else
2200 #endif 2269 printf ("[os2fslib_UpdateRects] : No public surface!\n");
2201 DosReleaseMutexSem(_this->hidden->hmtxUseSrcBuffer); 2270 fflush (stdout);
2202 } 2271 #endif
2203 #ifdef DEBUG_BUILD 2272 DosReleaseMutexSem (_this->hidden->hmtxUseSrcBuffer);
2204 else 2273 }
2205 printf("[os2fslib_UpdateRects] : Error in mutex!\n"); fflush(stdout); 2274 #ifdef DEBUG_BUILD
2275 else
2276 printf ("[os2fslib_UpdateRects] : Error in mutex!\n");
2277 fflush (stdout);
2206 #endif 2278 #endif
2207 #endif 2279 #endif
2208 } 2280 }
2209 2281
2210 2282
2211 /* Reverse the effects VideoInit() -- called if VideoInit() fails 2283 /* Reverse the effects VideoInit() -- called if VideoInit() fails
2212 or if the application is shutting down the video subsystem. 2284 or if the application is shutting down the video subsystem.
2213 */ 2285 */
2214 static void os2fslib_VideoQuit(_THIS) 2286 static void
2215 { 2287 os2fslib_VideoQuit (_THIS)
2216 #ifdef DEBUG_BUILD 2288 {
2217 printf("[os2fslib_VideoQuit]\n"); fflush(stdout); 2289 #ifdef DEBUG_BUILD
2218 #endif 2290 printf ("[os2fslib_VideoQuit]\n");
2219 // Close PM stuff if running! 2291 fflush (stdout);
2220 if (_this->hidden->iPMThreadStatus == 1) 2292 #endif
2221 { 2293 // Close PM stuff if running!
2222 int iTimeout; 2294 if (_this->hidden->iPMThreadStatus == 1) {
2223 WinPostMsg(_this->hidden->hwndFrame, WM_QUIT, (MPARAM) 0, (MPARAM) 0); 2295 int iTimeout;
2224 // HACK: We had this line before: 2296 WinPostMsg (_this->hidden->hwndFrame, WM_QUIT, (MPARAM) 0,
2225 //DosWaitThread((TID *) &(_this->hidden->tidPMThread), DCWW_WAIT); 2297 (MPARAM) 0);
2226 // We don't use it, because the PMThread will never stop, or if it stops, 2298 // HACK: We had this line before:
2227 // it will kill the whole process as a emergency fallback. 2299 //DosWaitThread((TID *) &(_this->hidden->tidPMThread), DCWW_WAIT);
2228 // So, we only check for the iPMThreadStatus stuff! 2300 // We don't use it, because the PMThread will never stop, or if it stops,
2229 #ifdef DEBUG_BUILD 2301 // it will kill the whole process as a emergency fallback.
2230 printf("[os2fslib_VideoQuit] : Waiting for PM thread to die\n"); fflush(stdout); 2302 // So, we only check for the iPMThreadStatus stuff!
2231 #endif 2303 #ifdef DEBUG_BUILD
2232 2304 printf ("[os2fslib_VideoQuit] : Waiting for PM thread to die\n");
2233 iTimeout=0; 2305 fflush (stdout);
2234 while ((_this->hidden->iPMThreadStatus == 1) && (iTimeout<100)) 2306 #endif
2235 { 2307
2236 iTimeout++; 2308 iTimeout = 0;
2237 DosSleep(64); 2309 while ((_this->hidden->iPMThreadStatus == 1) && (iTimeout < 100)) {
2238 } 2310 iTimeout++;
2239 2311 DosSleep (64);
2240 #ifdef DEBUG_BUILD 2312 }
2241 printf("[os2fslib_VideoQuit] : End of wait.\n"); fflush(stdout); 2313
2242 #endif 2314 #ifdef DEBUG_BUILD
2243 2315 printf ("[os2fslib_VideoQuit] : End of wait.\n");
2244 if (_this->hidden->iPMThreadStatus == 1) 2316 fflush (stdout);
2245 { 2317 #endif
2246 #ifdef DEBUG_BUILD 2318
2247 printf("[os2fslib_VideoQuit] : Killing PM thread!\n"); fflush(stdout); 2319 if (_this->hidden->iPMThreadStatus == 1) {
2248 #endif 2320 #ifdef DEBUG_BUILD
2249 2321 printf ("[os2fslib_VideoQuit] : Killing PM thread!\n");
2250 _this->hidden->iPMThreadStatus = 0; 2322 fflush (stdout);
2251 DosKillThread(_this->hidden->tidPMThread); 2323 #endif
2252 2324
2253 if (_this->hidden->hwndFrame) 2325 _this->hidden->iPMThreadStatus = 0;
2254 { 2326 DosKillThread (_this->hidden->tidPMThread);
2255 #ifdef DEBUG_BUILD 2327
2256 printf("[os2fslib_VideoQuit] : Destroying PM window!\n"); fflush(stdout); 2328 if (_this->hidden->hwndFrame) {
2257 #endif 2329 #ifdef DEBUG_BUILD
2258 2330 printf ("[os2fslib_VideoQuit] : Destroying PM window!\n");
2259 WinDestroyWindow(_this->hidden->hwndFrame); _this->hidden->hwndFrame=NULL; 2331 fflush (stdout);
2260 } 2332 #endif
2261 } 2333
2262 2334 WinDestroyWindow (_this->hidden->hwndFrame);
2263 } 2335 _this->hidden->hwndFrame = NULL;
2264 2336 }
2265 // Free result of an old ListModes() call, because there is 2337 }
2266 // no FreeListModes() call in SDL! 2338
2267 if (_this->hidden->pListModesResult) 2339 }
2268 { 2340 // Free result of an old ListModes() call, because there is
2269 SDL_free(_this->hidden->pListModesResult); _this->hidden->pListModesResult = NULL; 2341 // no FreeListModes() call in SDL!
2270 } 2342 if (_this->hidden->pListModesResult) {
2271 2343 SDL_free (_this->hidden->pListModesResult);
2272 // Free list of available fullscreen modes 2344 _this->hidden->pListModesResult = NULL;
2273 if (_this->hidden->pAvailableFSLibVideoModes) 2345 }
2274 { 2346 // Free list of available fullscreen modes
2275 FSLib_FreeVideoModeList(_this->hidden->pAvailableFSLibVideoModes); 2347 if (_this->hidden->pAvailableFSLibVideoModes) {
2276 _this->hidden->pAvailableFSLibVideoModes = NULL; 2348 FSLib_FreeVideoModeList (_this->hidden->pAvailableFSLibVideoModes);
2277 } 2349 _this->hidden->pAvailableFSLibVideoModes = NULL;
2278 2350 }
2279 // Free application icon if we had one 2351 // Free application icon if we had one
2280 if (hptrCurrentIcon) 2352 if (hptrCurrentIcon) {
2281 { 2353 WinDestroyPointer (hptrCurrentIcon);
2282 WinDestroyPointer(hptrCurrentIcon); 2354 hptrCurrentIcon = NULL;
2283 hptrCurrentIcon = NULL; 2355 }
2284 }
2285 } 2356 }
2286 2357
2287 /* Set the requested video mode, returning a surface which will be 2358 /* Set the requested video mode, returning a surface which will be
2288 set to the SDL_VideoSurface. The width and height will already 2359 set to the SDL_VideoSurface. The width and height will already
2289 be verified by ListModes(), and the video subsystem is free to 2360 be verified by ListModes(), and the video subsystem is free to
2290 set the mode to a supported bit depth different from the one 2361 set the mode to a supported bit depth different from the one
2291 specified -- the desired bpp will be emulated with a shadow 2362 specified -- the desired bpp will be emulated with a shadow
2292 surface if necessary. If a new mode is returned, this function 2363 surface if necessary. If a new mode is returned, this function
2293 should take care of cleaning up the current mode. 2364 should take care of cleaning up the current mode.
2294 */ 2365 */
2295 static SDL_Surface *os2fslib_SetVideoMode(_THIS, SDL_Surface *current, 2366 static SDL_Surface *
2296 int width, int height, int bpp, Uint32 flags) 2367 os2fslib_SetVideoMode (_THIS, SDL_Surface * current,
2297 { 2368 int width, int height, int bpp, Uint32 flags)
2298 static int bFirstCall = 1; 2369 {
2299 FSLib_VideoMode_p pModeInfo, pModeInfoFound; 2370 static int bFirstCall = 1;
2300 FSLib_VideoMode TempModeInfo; 2371 FSLib_VideoMode_p pModeInfo, pModeInfoFound;
2301 HAB hab; 2372 FSLib_VideoMode TempModeInfo;
2302 HMQ hmq; 2373 HAB hab;
2303 ERRORID hmqerror; 2374 HMQ hmq;
2304 RECTL rectl; 2375 ERRORID hmqerror;
2305 SDL_Surface *pResult; 2376 RECTL rectl;
2306 2377 SDL_Surface *pResult;
2307 // If there is no more window, nothing we can do! 2378
2308 if (_this->hidden->iPMThreadStatus!=1) return NULL; 2379 // If there is no more window, nothing we can do!
2309 2380 if (_this->hidden->iPMThreadStatus != 1)
2310 #ifdef DEBUG_BUILD 2381 return NULL;
2311 printf("[os2fslib_SetVideoMode] : Request for %dx%d @ %dBPP, flags=0x%x\n", width, height, bpp, flags); fflush(stdout); 2382
2312 #endif 2383 #ifdef DEBUG_BUILD
2313 2384 printf
2314 // We don't support palette modes! 2385 ("[os2fslib_SetVideoMode] : Request for %dx%d @ %dBPP, flags=0x%x\n",
2315 if (bpp==8) bpp=32; 2386 width, height, bpp, flags);
2316 2387 fflush (stdout);
2317 // Also, we don't support resizable modes in fullscreen mode. 2388 #endif
2318 if (flags & SDL_RESIZABLE) 2389
2319 flags &= ~SDL_FULLSCREEN; 2390 // We don't support palette modes!
2320 2391 if (bpp == 8)
2321 // No double buffered mode 2392 bpp = 32;
2322 if (flags & SDL_DOUBLEBUF) 2393
2323 flags &= ~SDL_DOUBLEBUF; 2394 // Also, we don't support resizable modes in fullscreen mode.
2324 2395 if (flags & SDL_RESIZABLE)
2325 // And, we don't support HWSURFACE yet. 2396 flags &= ~SDL_FULLSCREEN;
2326 if (flags & SDL_HWSURFACE) 2397
2327 { 2398 // No double buffered mode
2328 flags &= ~SDL_HWSURFACE; 2399 if (flags & SDL_DOUBLEBUF)
2329 flags |= SDL_SWSURFACE; 2400 flags &= ~SDL_DOUBLEBUF;
2330 } 2401
2331 2402 // And, we don't support HWSURFACE yet.
2332 #ifdef DEBUG_BUILD 2403 if (flags & SDL_HWSURFACE) {
2333 printf("[os2fslib_SetVideoMode] : Changed request to %dx%d @ %dBPP, flags=0x%x\n", width, height, bpp, flags); fflush(stdout); 2404 flags &= ~SDL_HWSURFACE;
2334 #endif 2405 flags |= SDL_SWSURFACE;
2335 2406 }
2336 // First check if there is such a video mode they want! 2407 #ifdef DEBUG_BUILD
2337 pModeInfoFound = NULL; 2408 printf
2338 2409 ("[os2fslib_SetVideoMode] : Changed request to %dx%d @ %dBPP, flags=0x%x\n",
2339 // For fullscreen mode we don't support every resolution! 2410 width, height, bpp, flags);
2340 // So, go through the video modes, and check for such a resolution! 2411 fflush (stdout);
2341 pModeInfoFound = NULL; 2412 #endif
2342 pModeInfo = _this->hidden->pAvailableFSLibVideoModes; 2413
2343 2414 // First check if there is such a video mode they want!
2344 while (pModeInfo) 2415 pModeInfoFound = NULL;
2345 { 2416
2346 // Check all available fullscreen modes for this resolution 2417 // For fullscreen mode we don't support every resolution!
2347 if ((pModeInfo->uiXResolution == width) && 2418 // So, go through the video modes, and check for such a resolution!
2348 (pModeInfo->uiYResolution == height) && 2419 pModeInfoFound = NULL;
2349 (pModeInfo->uiBPP!=8)) // palettized modes not yet supported
2350 {
2351 // If good resolution, try to find the exact BPP, or at least
2352 // something similar...
2353 if (!pModeInfoFound)
2354 pModeInfoFound = pModeInfo;
2355 else
2356 if ((pModeInfoFound->uiBPP!=bpp) &&
2357 (pModeInfoFound->uiBPP<pModeInfo->uiBPP))
2358 pModeInfoFound = pModeInfo;
2359 }
2360 pModeInfo = pModeInfo->pNext;
2361 }
2362
2363 // If we did not find a good fullscreen mode, then try a similar
2364 if (!pModeInfoFound)
2365 {
2366 #ifdef DEBUG_BUILD
2367 printf("[os2fslib_SetVideoMode] : Requested video mode not found, looking for a similar one!\n"); fflush(stdout);
2368 #endif
2369 // Go through the video modes again, and find a similar resolution!
2370 pModeInfo = _this->hidden->pAvailableFSLibVideoModes; 2420 pModeInfo = _this->hidden->pAvailableFSLibVideoModes;
2371 while (pModeInfo) 2421
2372 { 2422 while (pModeInfo) {
2373 // Check all available fullscreen modes for this resolution 2423 // Check all available fullscreen modes for this resolution
2374 if ((pModeInfo->uiXResolution >= width) && 2424 if ((pModeInfo->uiXResolution == width) && (pModeInfo->uiYResolution == height) && (pModeInfo->uiBPP != 8)) // palettized modes not yet supported
2375 (pModeInfo->uiYResolution >= height) &&
2376 (pModeInfo->uiBPP == bpp))
2377 {
2378 if (!pModeInfoFound)
2379 pModeInfoFound = pModeInfo;
2380 else
2381 if (((pModeInfoFound->uiXResolution-width)*(pModeInfoFound->uiYResolution-height))>
2382 ((pModeInfo->uiXResolution-width)*(pModeInfo->uiYResolution-height)))
2383 { 2425 {
2384 // Found a mode which is closer than the current one 2426 // If good resolution, try to find the exact BPP, or at least
2385 pModeInfoFound = pModeInfo; 2427 // something similar...
2386 } 2428 if (!pModeInfoFound)
2387 } 2429 pModeInfoFound = pModeInfo;
2388 pModeInfo = pModeInfo->pNext; 2430 else if ((pModeInfoFound->uiBPP != bpp) &&
2389 } 2431 (pModeInfoFound->uiBPP < pModeInfo->uiBPP))
2390 } 2432 pModeInfoFound = pModeInfo;
2391 2433 }
2392 // If we did not find a good fullscreen mode, then return NULL 2434 pModeInfo = pModeInfo->pNext;
2393 if (!pModeInfoFound) 2435 }
2394 { 2436
2395 #ifdef DEBUG_BUILD 2437 // If we did not find a good fullscreen mode, then try a similar
2396 printf("[os2fslib_SetVideoMode] : Requested video mode not found!\n"); fflush(stdout); 2438 if (!pModeInfoFound) {
2397 #endif 2439 #ifdef DEBUG_BUILD
2398 return NULL; 2440 printf
2399 } 2441 ("[os2fslib_SetVideoMode] : Requested video mode not found, looking for a similar one!\n");
2400 2442 fflush (stdout);
2401 #ifdef DEBUG_BUILD 2443 #endif
2402 printf("[os2fslib_SetVideoMode] : Found mode!\n"); fflush(stdout); 2444 // Go through the video modes again, and find a similar resolution!
2403 #endif 2445 pModeInfo = _this->hidden->pAvailableFSLibVideoModes;
2404 2446 while (pModeInfo) {
2405 // We'll possibly adjust the structure, so copy out the values 2447 // Check all available fullscreen modes for this resolution
2406 // into TempModeInfo! 2448 if ((pModeInfo->uiXResolution >= width) &&
2407 SDL_memcpy(&TempModeInfo, pModeInfoFound, sizeof(TempModeInfo)); 2449 (pModeInfo->uiYResolution >= height) &&
2408 pModeInfoFound = &TempModeInfo; 2450 (pModeInfo->uiBPP == bpp)) {
2409 2451 if (!pModeInfoFound)
2410 if (flags & SDL_RESIZABLE) 2452 pModeInfoFound = pModeInfo;
2411 { 2453 else if (((pModeInfoFound->uiXResolution -
2412 #ifdef DEBUG_BUILD 2454 width) * (pModeInfoFound->uiYResolution -
2413 printf("[os2fslib_SetVideoMode] : Requested mode is resizable, changing width/height\n"); fflush(stdout); 2455 height)) >
2414 #endif 2456 ((pModeInfo->uiXResolution -
2415 // Change width and height to requested one! 2457 width) * (pModeInfo->uiYResolution - height))) {
2416 TempModeInfo.uiXResolution = width; 2458 // Found a mode which is closer than the current one
2417 TempModeInfo.uiYResolution = height; 2459 pModeInfoFound = pModeInfo;
2418 TempModeInfo.uiScanLineSize = width * ((TempModeInfo.uiBPP+7)/8); 2460 }
2419 } 2461 }
2420 2462 pModeInfo = pModeInfo->pNext;
2421 // We can try create new surface! 2463 }
2422 2464 }
2423 // Make sure this thread is prepared for using the Presentation Manager! 2465 // If we did not find a good fullscreen mode, then return NULL
2424 hab = WinInitialize(0); 2466 if (!pModeInfoFound) {
2425 hmq = WinCreateMsgQueue(hab,0); 2467 #ifdef DEBUG_BUILD
2426 // Remember if there was an error at WinCreateMsgQueue(), because we don't 2468 printf
2427 // want to destroy somebody else's queue later. :) 2469 ("[os2fslib_SetVideoMode] : Requested video mode not found!\n");
2428 hmqerror = WinGetLastError(hab); 2470 fflush (stdout);
2429 2471 #endif
2430 2472 return NULL;
2431 2473 }
2432 if (DosRequestMutexSem(_this->hidden->hmtxUseSrcBuffer, SEM_INDEFINITE_WAIT)==NO_ERROR) 2474 #ifdef DEBUG_BUILD
2433 { 2475 printf ("[os2fslib_SetVideoMode] : Found mode!\n");
2434 #ifdef DEBUG_BUILD 2476 fflush (stdout);
2435 printf("[os2fslib_SetVideoMode] : Creating new SW surface\n"); fflush(stdout); 2477 #endif
2436 #endif 2478
2437 2479 // We'll possibly adjust the structure, so copy out the values
2438 // Create new software surface! 2480 // into TempModeInfo!
2439 pResult = SDL_CreateRGBSurface(SDL_SWSURFACE, 2481 SDL_memcpy (&TempModeInfo, pModeInfoFound, sizeof (TempModeInfo));
2440 pModeInfoFound->uiXResolution, 2482 pModeInfoFound = &TempModeInfo;
2441 pModeInfoFound->uiYResolution, 2483
2442 pModeInfoFound->uiBPP, 2484 if (flags & SDL_RESIZABLE) {
2443 ((unsigned int) pModeInfoFound->PixelFormat.ucRedMask) << pModeInfoFound->PixelFormat.ucRedPosition, 2485 #ifdef DEBUG_BUILD
2444 ((unsigned int) pModeInfoFound->PixelFormat.ucGreenMask) << pModeInfoFound->PixelFormat.ucGreenPosition, 2486 printf
2445 ((unsigned int) pModeInfoFound->PixelFormat.ucBlueMask) << pModeInfoFound->PixelFormat.ucBluePosition, 2487 ("[os2fslib_SetVideoMode] : Requested mode is resizable, changing width/height\n");
2446 ((unsigned int) pModeInfoFound->PixelFormat.ucAlphaMask) << pModeInfoFound->PixelFormat.ucAlphaPosition); 2488 fflush (stdout);
2447 2489 #endif
2448 if (pResult == NULL) 2490 // Change width and height to requested one!
2449 { 2491 TempModeInfo.uiXResolution = width;
2450 DosReleaseMutexSem(_this->hidden->hmtxUseSrcBuffer); 2492 TempModeInfo.uiYResolution = height;
2451 SDL_OutOfMemory(); 2493 TempModeInfo.uiScanLineSize = width * ((TempModeInfo.uiBPP + 7) / 8);
2452 return NULL; 2494 }
2453 } 2495 // We can try create new surface!
2454 2496
2455 #ifdef DEBUG_BUILD 2497 // Make sure this thread is prepared for using the Presentation Manager!
2456 printf("[os2fslib_SetVideoMode] : Adjusting pixel format\n"); fflush(stdout); 2498 hab = WinInitialize (0);
2457 #endif 2499 hmq = WinCreateMsgQueue (hab, 0);
2458 2500 // Remember if there was an error at WinCreateMsgQueue(), because we don't
2459 // Adjust pixel format mask! 2501 // want to destroy somebody else's queue later. :)
2460 pResult->format->Rmask = ((unsigned int) pModeInfoFound->PixelFormat.ucRedMask) << pModeInfoFound->PixelFormat.ucRedPosition; 2502 hmqerror = WinGetLastError (hab);
2461 pResult->format->Rshift = pModeInfoFound->PixelFormat.ucRedPosition; 2503
2462 pResult->format->Rloss = pModeInfoFound->PixelFormat.ucRedAdjust; 2504
2463 pResult->format->Gmask = ((unsigned int) pModeInfoFound->PixelFormat.ucGreenMask) << pModeInfoFound->PixelFormat.ucGreenPosition; 2505
2464 pResult->format->Gshift = pModeInfoFound->PixelFormat.ucGreenPosition; 2506 if (DosRequestMutexSem
2465 pResult->format->Gloss = pModeInfoFound->PixelFormat.ucGreenAdjust; 2507 (_this->hidden->hmtxUseSrcBuffer, SEM_INDEFINITE_WAIT) == NO_ERROR) {
2466 pResult->format->Bmask = ((unsigned int) pModeInfoFound->PixelFormat.ucBlueMask) << pModeInfoFound->PixelFormat.ucBluePosition; 2508 #ifdef DEBUG_BUILD
2467 pResult->format->Bshift = pModeInfoFound->PixelFormat.ucBluePosition; 2509 printf ("[os2fslib_SetVideoMode] : Creating new SW surface\n");
2468 pResult->format->Bloss = pModeInfoFound->PixelFormat.ucBlueAdjust; 2510 fflush (stdout);
2469 pResult->format->Amask = ((unsigned int) pModeInfoFound->PixelFormat.ucAlphaMask) << pModeInfoFound->PixelFormat.ucAlphaPosition; 2511 #endif
2470 pResult->format->Ashift = pModeInfoFound->PixelFormat.ucAlphaPosition; 2512
2471 pResult->format->Aloss = pModeInfoFound->PixelFormat.ucAlphaAdjust; 2513 // Create new software surface!
2514 pResult = SDL_CreateRGBSurface (SDL_SWSURFACE,
2515 pModeInfoFound->uiXResolution,
2516 pModeInfoFound->uiYResolution,
2517 pModeInfoFound->uiBPP,
2518 ((unsigned int) pModeInfoFound->
2519 PixelFormat.
2520 ucRedMask) << pModeInfoFound->
2521 PixelFormat.ucRedPosition,
2522 ((unsigned int) pModeInfoFound->
2523 PixelFormat.
2524 ucGreenMask) << pModeInfoFound->
2525 PixelFormat.ucGreenPosition,
2526 ((unsigned int) pModeInfoFound->
2527 PixelFormat.
2528 ucBlueMask) << pModeInfoFound->
2529 PixelFormat.ucBluePosition,
2530 ((unsigned int) pModeInfoFound->
2531 PixelFormat.
2532 ucAlphaMask) << pModeInfoFound->
2533 PixelFormat.ucAlphaPosition);
2534
2535 if (pResult == NULL) {
2536 DosReleaseMutexSem (_this->hidden->hmtxUseSrcBuffer);
2537 SDL_OutOfMemory ();
2538 return NULL;
2539 }
2540 #ifdef DEBUG_BUILD
2541 printf ("[os2fslib_SetVideoMode] : Adjusting pixel format\n");
2542 fflush (stdout);
2543 #endif
2544
2545 // Adjust pixel format mask!
2546 pResult->format->Rmask =
2547 ((unsigned int) pModeInfoFound->PixelFormat.
2548 ucRedMask) << pModeInfoFound->PixelFormat.ucRedPosition;
2549 pResult->format->Rshift = pModeInfoFound->PixelFormat.ucRedPosition;
2550 pResult->format->Rloss = pModeInfoFound->PixelFormat.ucRedAdjust;
2551 pResult->format->Gmask =
2552 ((unsigned int) pModeInfoFound->PixelFormat.
2553 ucGreenMask) << pModeInfoFound->PixelFormat.ucGreenPosition;
2554 pResult->format->Gshift = pModeInfoFound->PixelFormat.ucGreenPosition;
2555 pResult->format->Gloss = pModeInfoFound->PixelFormat.ucGreenAdjust;
2556 pResult->format->Bmask =
2557 ((unsigned int) pModeInfoFound->PixelFormat.
2558 ucBlueMask) << pModeInfoFound->PixelFormat.ucBluePosition;
2559 pResult->format->Bshift = pModeInfoFound->PixelFormat.ucBluePosition;
2560 pResult->format->Bloss = pModeInfoFound->PixelFormat.ucBlueAdjust;
2561 pResult->format->Amask =
2562 ((unsigned int) pModeInfoFound->PixelFormat.
2563 ucAlphaMask) << pModeInfoFound->PixelFormat.ucAlphaPosition;
2564 pResult->format->Ashift = pModeInfoFound->PixelFormat.ucAlphaPosition;
2565 pResult->format->Aloss = pModeInfoFound->PixelFormat.ucAlphaAdjust;
2472 2566
2473 #ifdef REPORT_EMPTY_ALPHA_MASK 2567 #ifdef REPORT_EMPTY_ALPHA_MASK
2474 pResult->format->Amask = 2568 pResult->format->Amask =
2475 pResult->format->Ashift = 2569 pResult->format->Ashift = pResult->format->Aloss = 0;
2476 pResult->format->Aloss = 0; 2570 #endif
2477 #endif 2571
2478 2572 // Adjust surface flags
2479 // Adjust surface flags 2573 pResult->flags |= (flags & SDL_FULLSCREEN);
2480 pResult->flags |= (flags & SDL_FULLSCREEN); 2574 pResult->flags |= (flags & SDL_RESIZABLE);
2481 pResult->flags |= (flags & SDL_RESIZABLE); 2575
2482 2576 // It might be that the software surface pitch is not the same as
2483 // It might be that the software surface pitch is not the same as 2577 // the pitch we have, so adjust that!
2484 // the pitch we have, so adjust that! 2578 pModeInfoFound->uiScanLineSize = pResult->pitch;
2485 pModeInfoFound->uiScanLineSize = pResult->pitch; 2579
2486 2580 // Store new source buffer parameters!
2487 // Store new source buffer parameters! 2581 SDL_memcpy (&(_this->hidden->SrcBufferDesc), pModeInfoFound,
2488 SDL_memcpy(&(_this->hidden->SrcBufferDesc), pModeInfoFound, sizeof(*pModeInfoFound)); 2582 sizeof (*pModeInfoFound));
2489 _this->hidden->pchSrcBuffer = pResult->pixels; 2583 _this->hidden->pchSrcBuffer = pResult->pixels;
2490 2584
2491 #ifdef DEBUG_BUILD 2585 #ifdef DEBUG_BUILD
2492 printf("[os2fslib_SetVideoMode] : Telling FSLib the stuffs\n"); fflush(stdout); 2586 printf ("[os2fslib_SetVideoMode] : Telling FSLib the stuffs\n");
2493 #endif 2587 fflush (stdout);
2494 2588 #endif
2495 // Tell the FSLib window the new source image format 2589
2496 FSLib_SetSrcBufferDesc(_this->hidden->hwndClient, &(_this->hidden->SrcBufferDesc)); 2590 // Tell the FSLib window the new source image format
2497 2591 FSLib_SetSrcBufferDesc (_this->hidden->hwndClient,
2498 if ( 2592 &(_this->hidden->SrcBufferDesc));
2499 ((flags & SDL_RESIZABLE)==0) || 2593
2500 (bFirstCall) 2594 if (((flags & SDL_RESIZABLE) == 0) || (bFirstCall)) {
2501 ) 2595 bFirstCall = 0;
2502 { 2596 #ifdef DEBUG_BUILD
2503 bFirstCall = 0; 2597 printf ("[os2fslib_SetVideoMode] : Modifying window size\n");
2504 #ifdef DEBUG_BUILD 2598 fflush (stdout);
2505 printf("[os2fslib_SetVideoMode] : Modifying window size\n"); fflush(stdout); 2599 #endif
2506 #endif 2600
2507 2601 // Calculate frame window size from client window size
2508 // Calculate frame window size from client window size 2602 rectl.xLeft = 0;
2509 rectl.xLeft = 0; 2603 rectl.yBottom = 0;
2510 rectl.yBottom = 0; 2604 rectl.xRight = pModeInfoFound->uiXResolution; // Noninclusive
2511 rectl.xRight = pModeInfoFound->uiXResolution; // Noninclusive 2605 rectl.yTop = pModeInfoFound->uiYResolution; // Noninclusive
2512 rectl.yTop = pModeInfoFound->uiYResolution; // Noninclusive 2606 WinCalcFrameRect (_this->hidden->hwndFrame, &rectl, FALSE);
2513 WinCalcFrameRect(_this->hidden->hwndFrame, &rectl, FALSE); 2607
2514 2608 // Set the new size of the main window
2515 // Set the new size of the main window 2609 SetAccessableWindowPos (_this->hidden->hwndFrame,
2516 SetAccessableWindowPos(_this->hidden->hwndFrame, 2610 HWND_TOP,
2517 HWND_TOP, 2611 0, 0,
2518 0, 0, 2612 (rectl.xRight - rectl.xLeft),
2519 (rectl.xRight-rectl.xLeft), 2613 (rectl.yTop - rectl.yBottom),
2520 (rectl.yTop-rectl.yBottom), 2614 SWP_SIZE | SWP_ACTIVATE | SWP_SHOW);
2521 SWP_SIZE | SWP_ACTIVATE | SWP_SHOW); 2615 }
2522 } 2616 // Set fullscreen mode flag, and switch to fullscreen if needed!
2523 2617 if (flags & SDL_FULLSCREEN) {
2524 // Set fullscreen mode flag, and switch to fullscreen if needed! 2618 #ifdef DEBUG_BUILD
2525 if (flags & SDL_FULLSCREEN) 2619 printf
2526 { 2620 ("[os2fslib_SetVideoMode] : Also trying to switch to fullscreen\n");
2527 #ifdef DEBUG_BUILD 2621 fflush (stdout);
2528 printf("[os2fslib_SetVideoMode] : Also trying to switch to fullscreen\n"); 2622 #endif
2529 fflush(stdout); 2623 FSLib_ToggleFSMode (_this->hidden->hwndClient, 1);
2530 #endif 2624 /* Cursor manager functions to FS mode */
2531 FSLib_ToggleFSMode(_this->hidden->hwndClient, 1); 2625 os2fslib_SetCursorManagementFunctions (_this, 0);
2532 /* Cursor manager functions to FS mode*/ 2626 } else {
2533 os2fslib_SetCursorManagementFunctions(_this, 0); 2627 #ifdef DEBUG_BUILD
2534 } else 2628 printf
2535 { 2629 ("[os2fslib_SetVideoMode] : Also trying to switch to desktop mode\n");
2536 #ifdef DEBUG_BUILD 2630 fflush (stdout);
2537 printf("[os2fslib_SetVideoMode] : Also trying to switch to desktop mode\n"); 2631 #endif
2538 fflush(stdout); 2632 FSLib_ToggleFSMode (_this->hidden->hwndClient, 0);
2539 #endif 2633 /* Cursor manager functions to Windowed mode */
2540 FSLib_ToggleFSMode(_this->hidden->hwndClient, 0); 2634 os2fslib_SetCursorManagementFunctions (_this, 1);
2541 /* Cursor manager functions to Windowed mode*/ 2635 }
2542 os2fslib_SetCursorManagementFunctions(_this, 1); 2636
2543 } 2637 _this->hidden->pSDLSurface = pResult;
2544 2638
2545 _this->hidden->pSDLSurface = pResult; 2639 DosReleaseMutexSem (_this->hidden->hmtxUseSrcBuffer);
2546 2640 } else {
2547 DosReleaseMutexSem(_this->hidden->hmtxUseSrcBuffer); 2641 #ifdef DEBUG_BUILD
2548 } else 2642 printf
2549 { 2643 ("[os2fslib_SetVideoMode] : Could not get hmtxUseSrcBuffer!\n");
2550 #ifdef DEBUG_BUILD 2644 fflush (stdout);
2551 printf("[os2fslib_SetVideoMode] : Could not get hmtxUseSrcBuffer!\n"); fflush(stdout); 2645 #endif
2552 #endif 2646
2553 2647 pResult = NULL;
2554 pResult = NULL; 2648 }
2555 } 2649
2556 2650 // As we have the new surface, we don't need the current one anymore!
2557 // As we have the new surface, we don't need the current one anymore! 2651 if ((pResult) && (current)) {
2558 if ((pResult) && (current)) 2652 #ifdef DEBUG_BUILD
2559 { 2653 printf ("[os2fslib_SetVideoMode] : Freeing old surface\n");
2560 #ifdef DEBUG_BUILD 2654 fflush (stdout);
2561 printf("[os2fslib_SetVideoMode] : Freeing old surface\n"); fflush(stdout); 2655 #endif
2562 #endif 2656 SDL_FreeSurface (current);
2563 SDL_FreeSurface(current); 2657 }
2564 } 2658 // Redraw window
2565 2659 WinInvalidateRegion (_this->hidden->hwndClient, NULL, TRUE);
2566 // Redraw window 2660
2567 WinInvalidateRegion(_this->hidden->hwndClient, NULL, TRUE); 2661 // Now destroy the message queue, if we've created it!
2568 2662 if (ERRORIDERROR (hmqerror) == 0) {
2569 // Now destroy the message queue, if we've created it! 2663 #ifdef DEBUG_BUILD
2570 if (ERRORIDERROR(hmqerror)==0) 2664 printf ("[os2fslib_SetVideoMode] : Destroying message queue\n");
2571 { 2665 fflush (stdout);
2572 #ifdef DEBUG_BUILD 2666 #endif
2573 printf("[os2fslib_SetVideoMode] : Destroying message queue\n"); fflush(stdout); 2667 WinDestroyMsgQueue (hmq);
2574 #endif 2668 }
2575 WinDestroyMsgQueue(hmq); 2669 #ifdef DEBUG_BUILD
2576 } 2670 printf ("[os2fslib_SetVideoMode] : Done\n");
2577 2671 fflush (stdout);
2578 #ifdef DEBUG_BUILD 2672 #endif
2579 printf("[os2fslib_SetVideoMode] : Done\n"); fflush(stdout); 2673
2580 #endif 2674 /* We're done */
2581 2675
2582 /* We're done */ 2676 // Return with the new surface!
2583 2677 return pResult;
2584 // Return with the new surface!
2585 return pResult;
2586 } 2678 }
2587 2679
2588 /* List the available video modes for the given pixel format, sorted 2680 /* List the available video modes for the given pixel format, sorted
2589 from largest to smallest. 2681 from largest to smallest.
2590 */ 2682 */
2591 static SDL_Rect **os2fslib_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) 2683 static SDL_Rect **
2592 { 2684 os2fslib_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags)
2593 #ifdef DEBUG_BUILD 2685 {
2594 printf("[os2fslib_ListModes] : ListModes of %d Bpp\n", format->BitsPerPixel); 2686 #ifdef DEBUG_BUILD
2595 #endif 2687 printf ("[os2fslib_ListModes] : ListModes of %d Bpp\n",
2596 // Destroy result of previous call, if there is any 2688 format->BitsPerPixel);
2597 if (_this->hidden->pListModesResult) 2689 #endif
2598 { 2690 // Destroy result of previous call, if there is any
2599 SDL_free(_this->hidden->pListModesResult); _this->hidden->pListModesResult = NULL; 2691 if (_this->hidden->pListModesResult) {
2600 } 2692 SDL_free (_this->hidden->pListModesResult);
2601 2693 _this->hidden->pListModesResult = NULL;
2602 // For resizable and windowed mode we support every resolution! 2694 }
2603 if ((flags & SDL_RESIZABLE) && ((flags & SDL_FULLSCREEN) == 0)) 2695 // For resizable and windowed mode we support every resolution!
2604 return (SDL_Rect **)-1; 2696 if ((flags & SDL_RESIZABLE) && ((flags & SDL_FULLSCREEN) == 0))
2605 2697 return (SDL_Rect **) - 1;
2606 // Check if they need fullscreen or non-fullscreen video modes! 2698
2607 if ((flags & SDL_FULLSCREEN) == 0) 2699 // Check if they need fullscreen or non-fullscreen video modes!
2608 2700 if ((flags & SDL_FULLSCREEN) == 0) {
2609 { 2701 // For windowed mode we support every resolution!
2610 // For windowed mode we support every resolution! 2702 return (SDL_Rect **) - 1;
2611 return (SDL_Rect **)-1; 2703 } else {
2612 } else 2704 FSLib_VideoMode_p pFSMode;
2613 { 2705 // For fullscreen mode we don't support every resolution!
2614 FSLib_VideoMode_p pFSMode; 2706 // Now create a new list
2615 // For fullscreen mode we don't support every resolution! 2707 pFSMode = _this->hidden->pAvailableFSLibVideoModes;
2616 // Now create a new list 2708 while (pFSMode) {
2617 pFSMode = _this->hidden->pAvailableFSLibVideoModes; 2709 if (pFSMode->uiBPP == format->BitsPerPixel) {
2618 while (pFSMode) 2710 SDL_Rect *pRect = (SDL_Rect *) SDL_malloc (sizeof (SDL_Rect));
2619 { 2711 if (pRect) {
2620 if (pFSMode->uiBPP == format->BitsPerPixel) 2712 // Fill description
2621 { 2713 pRect->x = 0;
2622 SDL_Rect *pRect = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect)); 2714 pRect->y = 0;
2623 if (pRect) 2715 pRect->w = pFSMode->uiXResolution;
2624 { 2716 pRect->h = pFSMode->uiYResolution;
2625 // Fill description
2626 pRect->x = 0;
2627 pRect->y = 0;
2628 pRect->w = pFSMode->uiXResolution;
2629 pRect->h = pFSMode->uiYResolution;
2630 #ifdef DEBUG_BUILD 2717 #ifdef DEBUG_BUILD
2631 // printf("!!! Seems to be good!\n"); 2718 // printf("!!! Seems to be good!\n");
2632 // printf("F: %dx%d\n", pRect->w, pRect->h); 2719 // printf("F: %dx%d\n", pRect->w, pRect->h);
2633 #endif 2720 #endif
2634 // And insert into list of pRects 2721 // And insert into list of pRects
2635 if (!(_this->hidden->pListModesResult)) 2722 if (!(_this->hidden->pListModesResult)) {
2636 {
2637 #ifdef DEBUG_BUILD 2723 #ifdef DEBUG_BUILD
2638 // printf("!!! Inserting to beginning\n"); 2724 // printf("!!! Inserting to beginning\n");
2639 #endif 2725 #endif
2640 2726
2641 // We're the first one to be inserted! 2727 // We're the first one to be inserted!
2642 _this->hidden->pListModesResult = (SDL_Rect**) SDL_malloc(2*sizeof(SDL_Rect*)); 2728 _this->hidden->pListModesResult =
2643 if (_this->hidden->pListModesResult) 2729 (SDL_Rect **) SDL_malloc (2 *
2644 { 2730 sizeof (SDL_Rect *));
2645 _this->hidden->pListModesResult[0] = pRect; 2731 if (_this->hidden->pListModesResult) {
2646 _this->hidden->pListModesResult[1] = NULL; 2732 _this->hidden->pListModesResult[0] = pRect;
2647 } else 2733 _this->hidden->pListModesResult[1] = NULL;
2648 { 2734 } else {
2649 SDL_free(pRect); 2735 SDL_free (pRect);
2736 }
2737 } else {
2738 // We're not the first ones, so find the place where we
2739 // have to insert ourselves
2740 SDL_Rect **pNewList;
2741 int iPlace, iNumOfSlots, i;
2742
2743 #ifdef DEBUG_BUILD
2744 // printf("!!! Searching where to insert\n");
2745 #endif
2746
2747 iPlace = -1;
2748 iNumOfSlots = 1; // Count the last NULL too!
2749 for (i = 0; _this->hidden->pListModesResult[i]; i++) {
2750 iNumOfSlots++;
2751 if (iPlace == -1) {
2752 if ((_this->hidden->
2753 pListModesResult[i]->w *
2754 _this->hidden->
2755 pListModesResult[i]->h) <
2756 (pRect->w * pRect->h)) {
2757 iPlace = i;
2758 }
2759 }
2760 }
2761 if (iPlace == -1)
2762 iPlace = iNumOfSlots - 1;
2763
2764 #ifdef DEBUG_BUILD
2765 // printf("!!! From %d slots, it will be at %d\n", iNumOfSlots, iPlace);
2766 #endif
2767
2768 pNewList =
2769 (SDL_Rect **) SDL_realloc (_this->
2770 hidden->
2771 pListModesResult,
2772 (iNumOfSlots
2773 +
2774 1) *
2775 sizeof (SDL_Rect *));
2776 if (pNewList) {
2777 for (i = iNumOfSlots; i > iPlace; i--)
2778 pNewList[i] = pNewList[i - 1];
2779 pNewList[iPlace] = pRect;
2780 _this->hidden->pListModesResult = pNewList;
2781 } else {
2782 SDL_free (pRect);
2783 }
2784 }
2785 }
2650 } 2786 }
2651 } else 2787 pFSMode = pFSMode->pNext;
2652 { 2788 }
2653 // We're not the first ones, so find the place where we 2789 }
2654 // have to insert ourselves
2655 SDL_Rect **pNewList;
2656 int iPlace, iNumOfSlots, i;
2657
2658 #ifdef DEBUG_BUILD
2659 // printf("!!! Searching where to insert\n");
2660 #endif
2661
2662 iPlace = -1; iNumOfSlots = 1; // Count the last NULL too!
2663 for (i=0; _this->hidden->pListModesResult[i]; i++)
2664 {
2665 iNumOfSlots++;
2666 if (iPlace==-1)
2667 {
2668 if ((_this->hidden->pListModesResult[i]->w*_this->hidden->pListModesResult[i]->h)<
2669 (pRect->w*pRect->h))
2670 {
2671 iPlace = i;
2672 }
2673 }
2674 }
2675 if (iPlace==-1) iPlace = iNumOfSlots-1;
2676
2677 #ifdef DEBUG_BUILD
2678 // printf("!!! From %d slots, it will be at %d\n", iNumOfSlots, iPlace);
2679 #endif
2680
2681 pNewList = (SDL_Rect**) SDL_realloc(_this->hidden->pListModesResult, (iNumOfSlots+1)*sizeof(SDL_Rect*));
2682 if (pNewList)
2683 {
2684 for (i=iNumOfSlots;i>iPlace;i--)
2685 pNewList[i] = pNewList[i-1];
2686 pNewList[iPlace] = pRect;
2687 _this->hidden->pListModesResult = pNewList;
2688 } else
2689 {
2690 SDL_free(pRect);
2691 }
2692 }
2693 }
2694 }
2695 pFSMode = pFSMode->pNext;
2696 }
2697 }
2698 #ifdef DEBUG_BUILD 2790 #ifdef DEBUG_BUILD
2699 // printf("Returning list\n"); 2791 // printf("Returning list\n");
2700 #endif 2792 #endif
2701 return _this->hidden->pListModesResult; 2793 return _this->hidden->pListModesResult;
2702 } 2794 }
2703 2795
2704 /* Initialize the native video subsystem, filling 'vformat' with the 2796 /* Initialize the native video subsystem, filling 'vformat' with the
2705 "best" display pixel format, returning 0 or -1 if there's an error. 2797 "best" display pixel format, returning 0 or -1 if there's an error.
2706 */ 2798 */
2707 static int os2fslib_VideoInit(_THIS, SDL_PixelFormat *vformat) 2799 static int
2708 { 2800 os2fslib_VideoInit (_THIS, SDL_PixelFormat * vformat)
2709 FSLib_VideoMode_p pDesktopMode; 2801 {
2710 2802 FSLib_VideoMode_p pDesktopMode;
2711 #ifdef DEBUG_BUILD 2803
2712 printf("[os2fslib_VideoInit] : Enter\n"); fflush(stdout); 2804 #ifdef DEBUG_BUILD
2713 #endif 2805 printf ("[os2fslib_VideoInit] : Enter\n");
2714 2806 fflush (stdout);
2715 // Report the best pixel format. For this, 2807 #endif
2716 // we'll use the current desktop format. 2808
2717 pDesktopMode = FSLib_GetDesktopVideoMode(); 2809 // Report the best pixel format. For this,
2718 if (!pDesktopMode) 2810 // we'll use the current desktop format.
2719 { 2811 pDesktopMode = FSLib_GetDesktopVideoMode ();
2720 SDL_SetError("Could not query desktop video mode!"); 2812 if (!pDesktopMode) {
2721 #ifdef DEBUG_BUILD 2813 SDL_SetError ("Could not query desktop video mode!");
2722 printf("[os2fslib_VideoInit] : Could not query desktop video mode!\n"); 2814 #ifdef DEBUG_BUILD
2723 #endif 2815 printf
2724 return -1; 2816 ("[os2fslib_VideoInit] : Could not query desktop video mode!\n");
2725 } 2817 #endif
2726 2818 return -1;
2727 /* Determine the current screen size */ 2819 }
2728 _this->info.current_w = pDesktopMode->uiXResolution; 2820
2729 _this->info.current_h = pDesktopMode->uiYResolution; 2821 /* Determine the current screen size */
2730 2822 _this->info.current_w = pDesktopMode->uiXResolution;
2731 /* Determine the screen depth */ 2823 _this->info.current_h = pDesktopMode->uiYResolution;
2732 vformat->BitsPerPixel = pDesktopMode->uiBPP; 2824
2733 vformat->BytesPerPixel = (vformat->BitsPerPixel+7)/8; 2825 /* Determine the screen depth */
2734 2826 vformat->BitsPerPixel = pDesktopMode->uiBPP;
2735 vformat->Rmask = ((unsigned int) pDesktopMode->PixelFormat.ucRedMask) << pDesktopMode->PixelFormat.ucRedPosition; 2827 vformat->BytesPerPixel = (vformat->BitsPerPixel + 7) / 8;
2736 vformat->Rshift = pDesktopMode->PixelFormat.ucRedPosition; 2828
2737 vformat->Rloss = pDesktopMode->PixelFormat.ucRedAdjust; 2829 vformat->Rmask =
2738 vformat->Gmask = ((unsigned int) pDesktopMode->PixelFormat.ucGreenMask) << pDesktopMode->PixelFormat.ucGreenPosition; 2830 ((unsigned int) pDesktopMode->PixelFormat.ucRedMask) << pDesktopMode->
2739 vformat->Gshift = pDesktopMode->PixelFormat.ucGreenPosition; 2831 PixelFormat.ucRedPosition;
2740 vformat->Gloss = pDesktopMode->PixelFormat.ucGreenAdjust; 2832 vformat->Rshift = pDesktopMode->PixelFormat.ucRedPosition;
2741 vformat->Bmask = ((unsigned int) pDesktopMode->PixelFormat.ucBlueMask) << pDesktopMode->PixelFormat.ucBluePosition; 2833 vformat->Rloss = pDesktopMode->PixelFormat.ucRedAdjust;
2742 vformat->Bshift = pDesktopMode->PixelFormat.ucBluePosition; 2834 vformat->Gmask =
2743 vformat->Bloss = pDesktopMode->PixelFormat.ucBlueAdjust; 2835 ((unsigned int) pDesktopMode->PixelFormat.
2744 vformat->Amask = ((unsigned int) pDesktopMode->PixelFormat.ucAlphaMask) << pDesktopMode->PixelFormat.ucAlphaPosition; 2836 ucGreenMask) << pDesktopMode->PixelFormat.ucGreenPosition;
2745 vformat->Ashift = pDesktopMode->PixelFormat.ucAlphaPosition; 2837 vformat->Gshift = pDesktopMode->PixelFormat.ucGreenPosition;
2746 vformat->Aloss = pDesktopMode->PixelFormat.ucAlphaAdjust; 2838 vformat->Gloss = pDesktopMode->PixelFormat.ucGreenAdjust;
2839 vformat->Bmask =
2840 ((unsigned int) pDesktopMode->PixelFormat.
2841 ucBlueMask) << pDesktopMode->PixelFormat.ucBluePosition;
2842 vformat->Bshift = pDesktopMode->PixelFormat.ucBluePosition;
2843 vformat->Bloss = pDesktopMode->PixelFormat.ucBlueAdjust;
2844 vformat->Amask =
2845 ((unsigned int) pDesktopMode->PixelFormat.
2846 ucAlphaMask) << pDesktopMode->PixelFormat.ucAlphaPosition;
2847 vformat->Ashift = pDesktopMode->PixelFormat.ucAlphaPosition;
2848 vformat->Aloss = pDesktopMode->PixelFormat.ucAlphaAdjust;
2747 2849
2748 #ifdef REPORT_EMPTY_ALPHA_MASK 2850 #ifdef REPORT_EMPTY_ALPHA_MASK
2749 vformat->Amask = 2851 vformat->Amask = vformat->Ashift = vformat->Aloss = 0;
2750 vformat->Ashift = 2852 #endif
2751 vformat->Aloss = 0; 2853
2752 #endif 2854 // Fill in some window manager capabilities
2753 2855 _this->info.wm_available = 1;
2754 // Fill in some window manager capabilities 2856
2755 _this->info.wm_available = 1; 2857 // Initialize some internal variables
2756 2858 _this->hidden->pListModesResult = NULL;
2757 // Initialize some internal variables 2859 _this->hidden->fInFocus = 0;
2758 _this->hidden->pListModesResult = NULL; 2860 _this->hidden->iSkipWMMOUSEMOVE = 0;
2759 _this->hidden->fInFocus = 0; 2861 _this->hidden->iMouseVisible = 1;
2760 _this->hidden->iSkipWMMOUSEMOVE = 0; 2862
2761 _this->hidden->iMouseVisible = 1; 2863 if (getenv ("SDL_USE_PROPORTIONAL_WINDOW"))
2762 2864 _this->hidden->bProportionalResize = 1;
2763 if (getenv("SDL_USE_PROPORTIONAL_WINDOW")) 2865 else {
2764 _this->hidden->bProportionalResize = 1; 2866 PPIB pib;
2765 else 2867 PTIB tib;
2766 { 2868 char *pchFileName, *pchTemp;
2869 char achConfigFile[CCHMAXPATH];
2870 FILE *hFile;
2871
2872 /* No environment variable to have proportional window.
2873 * Ok, let's check if this executable is in config file!
2874 */
2875 _this->hidden->bProportionalResize = 0;
2876
2877 DosGetInfoBlocks (&tib, &pib);
2878 pchTemp = pchFileName = pib->pib_pchcmd;
2879 while (*pchTemp) {
2880 if (*pchTemp == '\\')
2881 pchFileName = pchTemp + 1;
2882 pchTemp++;
2883 }
2884 if (getenv ("HOME")) {
2885 sprintf (achConfigFile, "%s\\.sdl.proportionals",
2886 getenv ("HOME"));
2887 hFile = fopen (achConfigFile, "rt");
2888 if (!hFile) {
2889 /* Seems like the file cannot be opened or does not exist.
2890 * Let's try to create it with defaults!
2891 */
2892 hFile = fopen (achConfigFile, "wt");
2893 if (hFile) {
2894 fprintf (hFile,
2895 "; This file is a config file of SDL/2, containing\n");
2896 fprintf (hFile,
2897 "; the list of executables that must have proportional\n");
2898 fprintf (hFile, "; windows.\n");
2899 fprintf (hFile, ";\n");
2900 fprintf (hFile,
2901 "; You can add executable filenames into this file,\n");
2902 fprintf (hFile,
2903 "; one under the other. If SDL finds that a given\n");
2904 fprintf (hFile,
2905 "; program is in this list, then that application\n");
2906 fprintf (hFile,
2907 "; will have proportional windows, just like if\n");
2908 fprintf (hFile,
2909 "; the SET SDL_USE_PROPORTIONAL_WINDOW env. variable\n");
2910 fprintf (hFile,
2911 "; would have been set for that process.\n");
2912 fprintf (hFile, ";\n");
2913 fprintf (hFile, "\n");
2914 fprintf (hFile, "dosbox.exe\n");
2915 fclose (hFile);
2916 }
2917
2918 hFile = fopen (achConfigFile, "rt");
2919 }
2920
2921 if (hFile) {
2922 while (fgets (achConfigFile, sizeof (achConfigFile), hFile)) {
2923 /* Cut \n from end of string */
2924
2925 while (achConfigFile[strlen (achConfigFile) - 1]
2926 == '\n')
2927 achConfigFile[strlen (achConfigFile) - 1] = 0;
2928
2929 /* Compare... */
2930 if (stricmp (achConfigFile, pchFileName) == 0) {
2931 /* Found it in config file! */
2932 _this->hidden->bProportionalResize = 1;
2933 break;
2934 }
2935 }
2936 fclose (hFile);
2937 }
2938 }
2939 }
2940
2941 DosCreateMutexSem (NULL, &(_this->hidden->hmtxUseSrcBuffer), 0, FALSE);
2942
2943 // Now create our window with a default size
2944
2945 // For this, we select the first available fullscreen mode as
2946 // current window size!
2947 SDL_memcpy (&(_this->hidden->SrcBufferDesc),
2948 _this->hidden->pAvailableFSLibVideoModes,
2949 sizeof (_this->hidden->SrcBufferDesc));
2950 // Allocate new video buffer!
2951 _this->hidden->pchSrcBuffer =
2952 (char *) SDL_malloc (_this->hidden->pAvailableFSLibVideoModes->
2953 uiScanLineSize *
2954 _this->hidden->pAvailableFSLibVideoModes->
2955 uiYResolution);
2956 if (!_this->hidden->pchSrcBuffer) {
2957 #ifdef DEBUG_BUILD
2958 printf
2959 ("[os2fslib_VideoInit] : Yikes, not enough memory for new video buffer!\n");
2960 fflush (stdout);
2961 #endif
2962 SDL_SetError ("Not enough memory for new video buffer!\n");
2963 return -1;
2964 }
2965 // For this, we need a message processing thread.
2966 // We'll create a new thread for this, which will do everything
2967 // what is related to PM
2968 _this->hidden->iPMThreadStatus = 0;
2969 _this->hidden->tidPMThread =
2970 _beginthread (PMThreadFunc, NULL, 65536, (void *) _this);
2971 if (_this->hidden->tidPMThread <= 0) {
2972 #ifdef DEBUG_BUILD
2973 printf ("[os2fslib_VideoInit] : Could not create PM thread!\n");
2974 #endif
2975 SDL_SetError ("Could not create PM thread");
2976 return -1;
2977 }
2978 #ifdef USE_DOSSETPRIORITY
2979 // Burst the priority of PM Thread!
2980 DosSetPriority (PRTYS_THREAD, PRTYC_TIMECRITICAL, 0,
2981 _this->hidden->tidPMThread);
2982 #endif
2983 // Wait for the PM thread to initialize!
2984 while (_this->hidden->iPMThreadStatus == 0)
2985 DosSleep (32);
2986 // If the PM thread could not set up everything, then
2987 // report an error!
2988 if (_this->hidden->iPMThreadStatus != 1) {
2989 #ifdef DEBUG_BUILD
2990 printf ("[os2fslib_VideoInit] : PMThread reported an error : %d\n",
2991 _this->hidden->iPMThreadStatus);
2992 #endif
2993 SDL_SetError ("Error initializing PM thread");
2994 return -1;
2995 }
2996
2997 return 0;
2998 }
2999
3000
3001 static void
3002 os2fslib_DeleteDevice (_THIS)
3003 {
3004 #ifdef DEBUG_BUILD
3005 printf ("[os2fslib_DeleteDevice]\n");
3006 fflush (stdout);
3007 #endif
3008 // Free used memory
3009 FSLib_FreeVideoModeList (_this->hidden->pAvailableFSLibVideoModes);
3010 if (_this->hidden->pListModesResult)
3011 SDL_free (_this->hidden->pListModesResult);
3012 if (_this->hidden->pchSrcBuffer)
3013 SDL_free (_this->hidden->pchSrcBuffer);
3014 DosCloseMutexSem (_this->hidden->hmtxUseSrcBuffer);
3015 SDL_free (_this->hidden);
3016 SDL_free (_this);
3017 FSLib_Uninitialize ();
3018 }
3019
3020 static int
3021 os2fslib_Available (void)
3022 {
3023
3024 // If we can run, it means that we could load FSLib,
3025 // so we assume that it's available then!
3026 return 1;
3027 }
3028
3029 static void
3030 os2fslib_MorphToPM ()
3031 {
2767 PPIB pib; 3032 PPIB pib;
2768 PTIB tib; 3033 PTIB tib;
2769 char *pchFileName, *pchTemp; 3034
2770 char achConfigFile[CCHMAXPATH]; 3035 DosGetInfoBlocks (&tib, &pib);
2771 FILE *hFile; 3036
2772 3037 // Change flag from VIO to PM:
2773 /* No environment variable to have proportional window. 3038 if (pib->pib_ultype == 2)
2774 * Ok, let's check if this executable is in config file! 3039 pib->pib_ultype = 3;
2775 */ 3040 }
2776 _this->hidden->bProportionalResize = 0; 3041
2777 3042 static SDL_VideoDevice *
2778 DosGetInfoBlocks(&tib, &pib); 3043 os2fslib_CreateDevice (int devindex)
2779 pchTemp = pchFileName = pib->pib_pchcmd; 3044 {
2780 while (*pchTemp) 3045 SDL_VideoDevice *device;
2781 { 3046
2782 if (*pchTemp=='\\') 3047 #ifdef DEBUG_BUILD
2783 pchFileName = pchTemp+1; 3048 printf ("[os2fslib_CreateDevice] : Enter\n");
2784 pchTemp++; 3049 fflush (stdout);
2785 } 3050 #endif
2786 if (getenv("HOME")) 3051
2787 { 3052 /* Initialize all variables that we clean on shutdown */
2788 sprintf(achConfigFile, "%s\\.sdl.proportionals", getenv("HOME")); 3053 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice));
2789 hFile = fopen(achConfigFile, "rt"); 3054 if (device) {
2790 if (!hFile) 3055 SDL_memset (device, 0, (sizeof *device));
2791 { 3056 // Also allocate memory for private data
2792 /* Seems like the file cannot be opened or does not exist. 3057 device->hidden = (struct SDL_PrivateVideoData *)
2793 * Let's try to create it with defaults! 3058 SDL_malloc ((sizeof (struct SDL_PrivateVideoData)));
2794 */ 3059 }
2795 hFile = fopen(achConfigFile, "wt"); 3060 if ((device == NULL) || (device->hidden == NULL)) {
2796 if (hFile) 3061 SDL_OutOfMemory ();
2797 { 3062 if (device)
2798 fprintf(hFile, "; This file is a config file of SDL/2, containing\n"); 3063 SDL_free (device);
2799 fprintf(hFile, "; the list of executables that must have proportional\n"); 3064 return NULL;
2800 fprintf(hFile, "; windows.\n"); 3065 }
2801 fprintf(hFile, ";\n"); 3066 SDL_memset (device->hidden, 0, (sizeof *device->hidden));
2802 fprintf(hFile, "; You can add executable filenames into this file,\n"); 3067
2803 fprintf(hFile, "; one under the other. If SDL finds that a given\n"); 3068 /* Set the function pointers */
2804 fprintf(hFile, "; program is in this list, then that application\n"); 3069 #ifdef DEBUG_BUILD
2805 fprintf(hFile, "; will have proportional windows, just like if\n"); 3070 printf ("[os2fslib_CreateDevice] : VideoInit is %p\n",
2806 fprintf(hFile, "; the SET SDL_USE_PROPORTIONAL_WINDOW env. variable\n"); 3071 os2fslib_VideoInit);
2807 fprintf(hFile, "; would have been set for that process.\n"); 3072 fflush (stdout);
2808 fprintf(hFile, ";\n"); 3073 #endif
2809 fprintf(hFile, "\n"); 3074
2810 fprintf(hFile, "dosbox.exe\n"); 3075 /* Initialization/Query functions */
2811 fclose(hFile); 3076 device->VideoInit = os2fslib_VideoInit;
2812 } 3077 device->ListModes = os2fslib_ListModes;
2813 3078 device->SetVideoMode = os2fslib_SetVideoMode;
2814 hFile = fopen(achConfigFile, "rt"); 3079 device->ToggleFullScreen = os2fslib_ToggleFullScreen;
2815 } 3080 device->UpdateMouse = os2fslib_UpdateMouse;
2816 3081 device->CreateYUVOverlay = NULL;
2817 if (hFile) 3082 device->SetColors = os2fslib_SetColors;
2818 { 3083 device->UpdateRects = os2fslib_UpdateRects;
2819 while (fgets(achConfigFile, sizeof(achConfigFile), hFile)) 3084 device->VideoQuit = os2fslib_VideoQuit;
2820 { 3085 /* Hardware acceleration functions */
2821 /* Cut \n from end of string */ 3086 device->AllocHWSurface = os2fslib_AllocHWSurface;
2822 3087 device->CheckHWBlit = NULL;
2823 while (achConfigFile[strlen(achConfigFile)-1] == '\n') 3088 device->FillHWRect = NULL;
2824 achConfigFile[strlen(achConfigFile)-1] = 0; 3089 device->SetHWColorKey = NULL;
2825 3090 device->SetHWAlpha = NULL;
2826 /* Compare... */ 3091 device->LockHWSurface = os2fslib_LockHWSurface;
2827 if (stricmp(achConfigFile, pchFileName)==0) 3092 device->UnlockHWSurface = os2fslib_UnlockHWSurface;
2828 { 3093 device->FlipHWSurface = NULL;
2829 /* Found it in config file! */ 3094 device->FreeHWSurface = os2fslib_FreeHWSurface;
2830 _this->hidden->bProportionalResize = 1; 3095 /* Window manager functions */
2831 break; 3096 device->SetCaption = os2fslib_SetCaption;
2832 } 3097 device->SetIcon = os2fslib_SetIcon;
2833 } 3098 device->IconifyWindow = os2fslib_IconifyWindow;
2834 fclose(hFile); 3099 device->GrabInput = os2fslib_GrabInput;
2835 } 3100 device->GetWMInfo = NULL;
2836 } 3101 /* Cursor manager functions to Windowed mode */
2837 } 3102 os2fslib_SetCursorManagementFunctions (device, 1);
2838 3103 /* Event manager functions */
2839 DosCreateMutexSem(NULL, &(_this->hidden->hmtxUseSrcBuffer), 0, FALSE); 3104 device->InitOSKeymap = os2fslib_InitOSKeymap;
2840 3105 device->PumpEvents = os2fslib_PumpEvents;
2841 // Now create our window with a default size 3106 /* The function used to dispose of this structure */
2842 3107 device->free = os2fslib_DeleteDevice;
2843 // For this, we select the first available fullscreen mode as 3108
2844 // current window size! 3109 // Make sure we'll be able to use Win* API even if the application
2845 SDL_memcpy(&(_this->hidden->SrcBufferDesc), _this->hidden->pAvailableFSLibVideoModes, sizeof(_this->hidden->SrcBufferDesc)); 3110 // was linked to be a VIO application!
2846 // Allocate new video buffer! 3111 os2fslib_MorphToPM ();
2847 _this->hidden->pchSrcBuffer = (char *) SDL_malloc(_this->hidden->pAvailableFSLibVideoModes->uiScanLineSize * _this->hidden->pAvailableFSLibVideoModes->uiYResolution); 3112
2848 if (!_this->hidden->pchSrcBuffer) 3113 // Now initialize FSLib, and query available video modes!
2849 { 3114 if (!FSLib_Initialize ()) {
2850 #ifdef DEBUG_BUILD 3115 // Could not initialize FSLib!
2851 printf("[os2fslib_VideoInit] : Yikes, not enough memory for new video buffer!\n"); fflush(stdout); 3116 #ifdef DEBUG_BUILD
2852 #endif 3117 printf ("[os2fslib_CreateDevice] : Could not initialize FSLib!\n");
2853 SDL_SetError("Not enough memory for new video buffer!\n"); 3118 #endif
2854 return -1; 3119 SDL_SetError ("Could not initialize FSLib!");
2855 } 3120 SDL_free (device->hidden);
2856 3121 SDL_free (device);
2857 // For this, we need a message processing thread. 3122 return NULL;
2858 // We'll create a new thread for this, which will do everything 3123 }
2859 // what is related to PM 3124 device->hidden->pAvailableFSLibVideoModes = FSLib_GetVideoModeList ();
2860 _this->hidden->iPMThreadStatus = 0; 3125
2861 _this->hidden->tidPMThread = _beginthread(PMThreadFunc, NULL, 65536, (void *) _this); 3126 return device;
2862 if (_this->hidden->tidPMThread <= 0)
2863 {
2864 #ifdef DEBUG_BUILD
2865 printf("[os2fslib_VideoInit] : Could not create PM thread!\n");
2866 #endif
2867 SDL_SetError("Could not create PM thread");
2868 return -1;
2869 }
2870 #ifdef USE_DOSSETPRIORITY
2871 // Burst the priority of PM Thread!
2872 DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, _this->hidden->tidPMThread);
2873 #endif
2874 // Wait for the PM thread to initialize!
2875 while (_this->hidden->iPMThreadStatus==0)
2876 DosSleep(32);
2877 // If the PM thread could not set up everything, then
2878 // report an error!
2879 if (_this->hidden->iPMThreadStatus!=1)
2880 {
2881 #ifdef DEBUG_BUILD
2882 printf("[os2fslib_VideoInit] : PMThread reported an error : %d\n", _this->hidden->iPMThreadStatus);
2883 #endif
2884 SDL_SetError("Error initializing PM thread");
2885 return -1;
2886 }
2887
2888 return 0;
2889 }
2890
2891
2892 static void os2fslib_DeleteDevice(_THIS)
2893 {
2894 #ifdef DEBUG_BUILD
2895 printf("[os2fslib_DeleteDevice]\n"); fflush(stdout);
2896 #endif
2897 // Free used memory
2898 FSLib_FreeVideoModeList(_this->hidden->pAvailableFSLibVideoModes);
2899 if (_this->hidden->pListModesResult)
2900 SDL_free(_this->hidden->pListModesResult);
2901 if (_this->hidden->pchSrcBuffer)
2902 SDL_free(_this->hidden->pchSrcBuffer);
2903 DosCloseMutexSem(_this->hidden->hmtxUseSrcBuffer);
2904 SDL_free(_this->hidden);
2905 SDL_free(_this);
2906 FSLib_Uninitialize();
2907 }
2908
2909 static int os2fslib_Available(void)
2910 {
2911
2912 // If we can run, it means that we could load FSLib,
2913 // so we assume that it's available then!
2914 return 1;
2915 }
2916
2917 static void os2fslib_MorphToPM()
2918 {
2919 PPIB pib;
2920 PTIB tib;
2921
2922 DosGetInfoBlocks(&tib, &pib);
2923
2924 // Change flag from VIO to PM:
2925 if (pib->pib_ultype==2) pib->pib_ultype = 3;
2926 }
2927
2928 static SDL_VideoDevice *os2fslib_CreateDevice(int devindex)
2929 {
2930 SDL_VideoDevice *device;
2931
2932 #ifdef DEBUG_BUILD
2933 printf("[os2fslib_CreateDevice] : Enter\n"); fflush(stdout);
2934 #endif
2935
2936 /* Initialize all variables that we clean on shutdown */
2937 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
2938 if ( device )
2939 {
2940 SDL_memset(device, 0, (sizeof *device));
2941 // Also allocate memory for private data
2942 device->hidden = (struct SDL_PrivateVideoData *) SDL_malloc((sizeof(struct SDL_PrivateVideoData)));
2943 }
2944 if ( (device == NULL) || (device->hidden == NULL) )
2945 {
2946 SDL_OutOfMemory();
2947 if ( device )
2948 SDL_free(device);
2949 return NULL;
2950 }
2951 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
2952
2953 /* Set the function pointers */
2954 #ifdef DEBUG_BUILD
2955 printf("[os2fslib_CreateDevice] : VideoInit is %p\n", os2fslib_VideoInit); fflush(stdout);
2956 #endif
2957
2958 /* Initialization/Query functions */
2959 device->VideoInit = os2fslib_VideoInit;
2960 device->ListModes = os2fslib_ListModes;
2961 device->SetVideoMode = os2fslib_SetVideoMode;
2962 device->ToggleFullScreen = os2fslib_ToggleFullScreen;
2963 device->UpdateMouse = os2fslib_UpdateMouse;
2964 device->CreateYUVOverlay = NULL;
2965 device->SetColors = os2fslib_SetColors;
2966 device->UpdateRects = os2fslib_UpdateRects;
2967 device->VideoQuit = os2fslib_VideoQuit;
2968 /* Hardware acceleration functions */
2969 device->AllocHWSurface = os2fslib_AllocHWSurface;
2970 device->CheckHWBlit = NULL;
2971 device->FillHWRect = NULL;
2972 device->SetHWColorKey = NULL;
2973 device->SetHWAlpha = NULL;
2974 device->LockHWSurface = os2fslib_LockHWSurface;
2975 device->UnlockHWSurface = os2fslib_UnlockHWSurface;
2976 device->FlipHWSurface = NULL;
2977 device->FreeHWSurface = os2fslib_FreeHWSurface;
2978 /* Window manager functions */
2979 device->SetCaption = os2fslib_SetCaption;
2980 device->SetIcon = os2fslib_SetIcon;
2981 device->IconifyWindow = os2fslib_IconifyWindow;
2982 device->GrabInput = os2fslib_GrabInput;
2983 device->GetWMInfo = NULL;
2984 /* Cursor manager functions to Windowed mode*/
2985 os2fslib_SetCursorManagementFunctions(device, 1);
2986 /* Event manager functions */
2987 device->InitOSKeymap = os2fslib_InitOSKeymap;
2988 device->PumpEvents = os2fslib_PumpEvents;
2989 /* The function used to dispose of this structure */
2990 device->free = os2fslib_DeleteDevice;
2991
2992 // Make sure we'll be able to use Win* API even if the application
2993 // was linked to be a VIO application!
2994 os2fslib_MorphToPM();
2995
2996 // Now initialize FSLib, and query available video modes!
2997 if (!FSLib_Initialize())
2998 {
2999 // Could not initialize FSLib!
3000 #ifdef DEBUG_BUILD
3001 printf("[os2fslib_CreateDevice] : Could not initialize FSLib!\n");
3002 #endif
3003 SDL_SetError("Could not initialize FSLib!");
3004 SDL_free(device->hidden);
3005 SDL_free(device);
3006 return NULL;
3007 }
3008 device->hidden->pAvailableFSLibVideoModes =
3009 FSLib_GetVideoModeList();
3010
3011 return device;
3012 } 3127 }
3013 3128
3014 VideoBootStrap OS2FSLib_bootstrap = { 3129 VideoBootStrap OS2FSLib_bootstrap = {
3015 "os2fslib", "OS/2 Video Output using FSLib", 3130 "os2fslib", "OS/2 Video Output using FSLib",
3016 os2fslib_Available, os2fslib_CreateDevice 3131 os2fslib_Available, os2fslib_CreateDevice
3017 }; 3132 };
3018 3133
3134 /* vi: set ts=4 sw=4 expandtab: */