Skip to content

Latest commit

 

History

History
3018 lines (2655 loc) · 93.6 KB

SDL_os2fslib.c

File metadata and controls

3018 lines (2655 loc) · 93.6 KB
 
Nov 23, 2005
Nov 23, 2005
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2004 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Nov 23, 2005
Nov 23, 2005
23
Feb 26, 2006
Feb 26, 2006
24
25
26
27
28
#define _ULS_CALLCONV_
#define CALLCONV _System
#include <unidef.h> // Unicode API
#include <uconv.h> // Unicode API (codepage conversion)
Nov 23, 2005
Nov 23, 2005
29
30
31
32
33
#include <process.h>
#include <time.h>
#include "SDL_video.h"
#include "SDL_mouse.h"
Feb 16, 2006
Feb 16, 2006
34
35
36
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
Nov 23, 2005
Nov 23, 2005
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "SDL_os2fslib.h"
static ULONG ulFCFToUse =
FCF_TITLEBAR |
FCF_SYSMENU |
FCF_MINBUTTON |
FCF_MAXBUTTON |
FCF_NOBYTEALIGN |
FCF_SIZEBORDER |
FCF_TASKLIST;
static int bMouseCaptured = 0;
static int bMouseCapturable = 0;
static HPOINTER hptrGlobalPointer = NULL;
static HPOINTER hptrCurrentIcon = NULL;
static int iWindowSizeX = 320;
static int iWindowSizeY = 200;
static int bWindowResized = 0;
#pragma pack(1)
typedef struct BMPINFO
{
BITMAPINFO;
RGB clr;
} BMPINFO, *PBMPINFO;
#pragma pack()
// Backdoors:
DECLSPEC void SDLCALL SDL_OS2FSLIB_SetFCFToUse(ULONG ulFCF)
{
ulFCFToUse = ulFCF;
}
// Configuration defines:
// We have to report empty alpha mask, otherwise SDL will select
// alpha blitters, and this will have unwanted results, as we don't
// support alpha channel in FSLib yet.
#define REPORT_EMPTY_ALPHA_MASK
// Experimental: Move every FSLib_BitBlt() call into window message
// processing function.
// This may fix dirt left on desktop. Or not.
//#define BITBLT_IN_WINMESSAGEPROC
// Experimental-2: Use WinLockWindowUpdate() in around bitblts!
// This is not enabled, because it seems to cause more problems
// than good.
//#define USE_WINLOCKWINDOWUPDATE_AROUND_BITBLTS
// Use the following to show resized image instead of black stuff
// even if the surface is resizable.
//#define RESIZE_EVEN_IF_RESIZABLE
/* The translation table from a VK keysym to a SDL keysym */
static SDLKey HWScanKeyMap[256];
static SDL_keysym *TranslateKey(int vkey, int chcode, int scancode, SDL_keysym *keysym, int iPressed);
static int iShiftIsPressed;
#ifdef BITBLT_IN_WINMESSAGEPROC
#define WM_UPDATERECTSREQUEST WM_USER+50
#endif
#ifdef USE_WINLOCKWINDOWUPDATE_AROUND_BITBLTS
#define FSLIB_BITBLT(hwnd, buffer, top, left, width, height) \
{ \
WinLockWindowUpdate(HWND_DESKTOP, HWND_DESKTOP); \
FSLib_BitBlt(hwnd, buffer, top, left, width, height); \
WinLockWindowUpdate(HWND_DESKTOP, NULL); \
}
#else
#define FSLIB_BITBLT(hwnd, buffer, top, left, width, height) \
FSLib_BitBlt(hwnd, buffer, top, left, width, height);
#endif
/////////////////////////////////////////////////////////////////////
//
// SetAccessableWindowPos
//
// Same as WinSetWindowPos(), but takes care for the window to be
// always on the screen, the titlebar will be accessable everytime.
//
/////////////////////////////////////////////////////////////////////
static BOOL SetAccessableWindowPos(HWND hwnd, HWND hwndInsertBehind,
Feb 26, 2006
Feb 26, 2006
123
124
LONG x, LONG y,
LONG cx, LONG cy,
Nov 23, 2005
Nov 23, 2005
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
ULONG fl)
{
SWP swpDesktop, swp;
// Get desktop area
WinQueryWindowPos(HWND_DESKTOP, &swpDesktop);
if ((fl & SWP_MOVE) && (fl & SWP_SIZE))
{
// If both moving and sizing, then change size and pos now!!
if (x+cx>swpDesktop.cx)
x = swpDesktop.cx - cx;
if (x<0)
x = 0;
if (y<0)
y = 0;
if (y+cy>swpDesktop.cy)
y = swpDesktop.cy - cy;
return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
} else
if (fl & SWP_MOVE)
{
// Just moving
WinQueryWindowPos(hwnd, &swp);
if (x+swp.cx>swpDesktop.cx)
x = swpDesktop.cx - swp.cx;
if (x<0)
x = 0;
if (y<0)
y = 0;
if (y+swp.cy>swpDesktop.cy)
y = swpDesktop.cy - swp.cy;
return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
} else
if (fl & SWP_SIZE)
{
// Just sizing
WinQueryWindowPos(hwnd, &swp);
x = swp.x;
y = swp.y;
if (x+cx>swpDesktop.cx)
x = swpDesktop.cx - cx;
if (x<0)
x = 0;
if (y<0)
y = 0;
if (y+cy>swpDesktop.cy)
y = swpDesktop.cy - cy;
return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl | SWP_MOVE);
} else
return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
}
Feb 26, 2006
Feb 26, 2006
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
static UniChar NativeCharToUniChar(int chcode)
{
UniChar ucResult = (UniChar) chcode;
int rc;
UconvObject ucoTemp;
char achFrom[2];
char *pchFrom;
size_t iFromCount;
UniChar aucTo[10];
UniChar *pucTo;
size_t iToCount;
size_t iNonIdentical;
// Create unicode convert object
rc = UniCreateUconvObject(L"", &ucoTemp);
if (rc!=ULS_SUCCESS)
{
// Could not create convert object!
return ucResult;
}
// Convert language code string to unicode string
achFrom[0] = (char) chcode;
achFrom[1] = 0;
iFromCount = sizeof(char) * 2;
iToCount = sizeof(UniChar) * 2;
pucTo = &(aucTo[0]);
pchFrom = &(achFrom[0]);
rc = UniUconvToUcs(ucoTemp,
&pchFrom,
&iFromCount,
&pucTo,
&iToCount,
&iNonIdentical);
if (rc!=ULS_SUCCESS)
{
// Could not convert language code to UCS string!
UniFreeUconvObject(ucoTemp);
return ucResult;
}
UniFreeUconvObject(ucoTemp);
#ifdef DEBUG_BUILD
printf("%02x converted to %02x\n", (int) chcode, (int) (aucTo[0]));
#endif
return aucTo[0];
}
Nov 23, 2005
Nov 23, 2005
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/////////////////////////////////////////////////////////////////////
//
// TranslateKey
//
// This creates SDL Keycodes from VK_ and hardware scan codes
//
/////////////////////////////////////////////////////////////////////
static SDL_keysym *TranslateKey(int vkey, int chcode, int scancode, SDL_keysym *keysym, int iPressed)
{
keysym->scancode = (unsigned char) scancode;
keysym->mod = KMOD_NONE;
keysym->unicode = 0;
if (iPressed && SDL_TranslateUNICODE)
{
if (chcode)
Feb 26, 2006
Feb 26, 2006
245
keysym->unicode = NativeCharToUniChar(chcode);
Nov 23, 2005
Nov 23, 2005
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
else
keysym->unicode = vkey;
}
keysym->sym = HWScanKeyMap[scancode];
// Now stuffs based on state of shift key(s)!
if (vkey == VK_SHIFT)
{
iShiftIsPressed = iPressed;
}
if ((iShiftIsPressed) && (SDL_TranslateUNICODE))
{
// Change syms, if Unicode stuff is required
// I think it's silly, but it's SDL...
switch (keysym->sym)
{
case SDLK_BACKQUOTE:
Feb 26, 2006
Feb 26, 2006
265
266
keysym->sym = '~';
break;
Nov 23, 2005
Nov 23, 2005
267
case SDLK_1:
Feb 26, 2006
Feb 26, 2006
268
269
keysym->sym = SDLK_EXCLAIM;
break;
Nov 23, 2005
Nov 23, 2005
270
case SDLK_2:
Feb 26, 2006
Feb 26, 2006
271
272
keysym->sym = SDLK_AT;
break;
Nov 23, 2005
Nov 23, 2005
273
case SDLK_3:
Feb 26, 2006
Feb 26, 2006
274
275
keysym->sym = SDLK_HASH;
break;
Nov 23, 2005
Nov 23, 2005
276
case SDLK_4:
Feb 26, 2006
Feb 26, 2006
277
278
keysym->sym = SDLK_DOLLAR;
break;
Nov 23, 2005
Nov 23, 2005
279
case SDLK_5:
Feb 26, 2006
Feb 26, 2006
280
281
keysym->sym = '%';
break;
Nov 23, 2005
Nov 23, 2005
282
case SDLK_6:
Feb 26, 2006
Feb 26, 2006
283
284
keysym->sym = SDLK_CARET;
break;
Nov 23, 2005
Nov 23, 2005
285
case SDLK_7:
Feb 26, 2006
Feb 26, 2006
286
287
keysym->sym = SDLK_AMPERSAND;
break;
Nov 23, 2005
Nov 23, 2005
288
case SDLK_8:
Feb 26, 2006
Feb 26, 2006
289
290
keysym->sym = SDLK_ASTERISK;
break;
Nov 23, 2005
Nov 23, 2005
291
case SDLK_9:
Feb 26, 2006
Feb 26, 2006
292
293
keysym->sym = SDLK_LEFTPAREN;
break;
Nov 23, 2005
Nov 23, 2005
294
case SDLK_0:
Feb 26, 2006
Feb 26, 2006
295
296
keysym->sym = SDLK_RIGHTPAREN;
break;
Nov 23, 2005
Nov 23, 2005
297
case SDLK_MINUS:
Feb 26, 2006
Feb 26, 2006
298
299
keysym->sym = SDLK_UNDERSCORE;
break;
Nov 23, 2005
Nov 23, 2005
300
case SDLK_PLUS:
Feb 26, 2006
Feb 26, 2006
301
302
keysym->sym = SDLK_EQUALS;
break;
Nov 23, 2005
Nov 23, 2005
303
304
case SDLK_LEFTBRACKET:
Feb 26, 2006
Feb 26, 2006
305
306
keysym->sym = '{';
break;
Nov 23, 2005
Nov 23, 2005
307
case SDLK_RIGHTBRACKET:
Feb 26, 2006
Feb 26, 2006
308
309
keysym->sym = '}';
break;
Nov 23, 2005
Nov 23, 2005
310
311
case SDLK_SEMICOLON:
Feb 26, 2006
Feb 26, 2006
312
313
keysym->sym = SDLK_COLON;
break;
Nov 23, 2005
Nov 23, 2005
314
case SDLK_QUOTE:
Feb 26, 2006
Feb 26, 2006
315
316
keysym->sym = SDLK_QUOTEDBL;
break;
Nov 23, 2005
Nov 23, 2005
317
case SDLK_BACKSLASH:
Feb 26, 2006
Feb 26, 2006
318
319
keysym->sym = '|';
break;
Nov 23, 2005
Nov 23, 2005
320
321
case SDLK_COMMA:
Feb 26, 2006
Feb 26, 2006
322
323
keysym->sym = SDLK_LESS;
break;
Nov 23, 2005
Nov 23, 2005
324
case SDLK_PERIOD:
Feb 26, 2006
Feb 26, 2006
325
326
keysym->sym = SDLK_GREATER;
break;
Nov 23, 2005
Nov 23, 2005
327
case SDLK_SLASH:
Feb 26, 2006
Feb 26, 2006
328
329
keysym->sym = SDLK_QUESTION;
break;
Nov 23, 2005
Nov 23, 2005
330
331
default:
Feb 26, 2006
Feb 26, 2006
332
break;
Nov 23, 2005
Nov 23, 2005
333
334
335
336
337
338
339
340
}
}
return keysym;
}
#define CONVERTMOUSEPOSITION() \
/* We have to inverse the mouse position, because every non-os/2 system */ \
/* has a coordinate system where the (0;0) is the top-left corner, */ \
Feb 26, 2006
Feb 26, 2006
341
342
343
344
345
346
/* while on os/2 it's the bottom left corner! */ \
if (FSLib_QueryFSMode(hwnd)) \
{ \
/* We're in FS mode! */ \
/* In FS mode our window is as big as fullscreen mode, but not necessary as */ \
/* big as the source buffer (can be bigger) */ \
Nov 23, 2005
Nov 23, 2005
347
/* So, limit mouse pos to source buffer size! */ \
Feb 26, 2006
Feb 26, 2006
348
349
350
if (ppts->x<0) ppts->x = 0; \
if (ppts->y<0) ppts->y = 0; \
if (ppts->x>=pVideo->hidden->SrcBufferDesc.uiXResolution) ppts->x = pVideo->hidden->SrcBufferDesc.uiXResolution-1; \
Nov 23, 2005
Nov 23, 2005
351
352
353
354
if (ppts->y>=pVideo->hidden->SrcBufferDesc.uiYResolution) ppts->y = pVideo->hidden->SrcBufferDesc.uiYResolution-1; \
pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */ \
ptl.x = ppts->x; ptl.y = ppts->y; \
WinMapWindowPoints(pVideo->hidden->hwndClient, HWND_DESKTOP, &ptl, 1); \
Feb 26, 2006
Feb 26, 2006
355
356
WinSetPointerPos(HWND_DESKTOP, ptl.x, ptl.y); \
/* Then convert OS/2 position to SDL position */ \
Nov 23, 2005
Nov 23, 2005
357
ppts->y = pVideo->hidden->SrcBufferDesc.uiYResolution - ppts->y - 1; \
Feb 26, 2006
Feb 26, 2006
358
359
360
} else \
{ \
SWP swpClient; \
Nov 23, 2005
Nov 23, 2005
361
/* We're in windowed mode! */ \
Feb 26, 2006
Feb 26, 2006
362
WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient); \
Nov 23, 2005
Nov 23, 2005
363
/* Convert OS/2 mouse position to SDL position, and also scale it! */ \
Feb 26, 2006
Feb 26, 2006
364
365
366
367
(ppts->x) = (ppts->x) * pVideo->hidden->SrcBufferDesc.uiXResolution / swpClient.cx; \
(ppts->y) = (ppts->y) * pVideo->hidden->SrcBufferDesc.uiYResolution / swpClient.cy; \
(ppts->y) = pVideo->hidden->SrcBufferDesc.uiYResolution - (ppts->y) - 1; \
}
Nov 23, 2005
Nov 23, 2005
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
/////////////////////////////////////////////////////////////////////
//
// WndProc
//
// This is the message processing window procedure for the
// SDLWindowClass, which is the client window in our application.
// It handles switching back and away from the app (taking care of
// going out and back to and from fullscreen mode), sending keystrokes
// and mouse events to where it has to be sent, etc...
//
/////////////////////////////////////////////////////////////////////
static MRESULT EXPENTRY WndProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
HPS ps;
RECTL rcl;
SDL_VideoDevice *pVideo = NULL;
switch (msg)
{
case WM_CHAR: // Keypress notification
#ifdef DEBUG_BUILD
// printf("WM_CHAR\n"); fflush(stdout);
#endif
pVideo = WinQueryWindowPtr(hwnd, 0);
if (pVideo)
{
/*
// We skip repeated keys:
if (CHARMSG(&msg)->cRepeat>1)
{
#ifdef DEBUG_BUILD
// printf("Repeated key (%d), skipping...\n", CHARMSG(&msg)->cRepeat); fflush(stdout);
#endif
return (MRESULT) TRUE;
}
*/
// If it's not repeated, then let's see if its pressed or released!
Feb 26, 2006
Feb 26, 2006
409
410
411
if (SHORT1FROMMP(mp1) & KC_KEYUP)
{
// A key has been released
Nov 23, 2005
Nov 23, 2005
412
413
414
415
416
417
418
419
SDL_keysym keysym;
#ifdef DEBUG_BUILD
// printf("WM_CHAR, keyup, code is [0x%0x]\n", CHAR4FROMMP(mp1)); // HW scan code
#endif
// One problem is with F1, which gets only the keyup message because
// it is a system key.
Feb 26, 2006
Feb 26, 2006
420
421
422
423
// So, when we get keyup message, we simulate keydown too!
// UPDATE:
// This problem should be solved now, that the accelerator keys are
// disabled for this window!
Nov 23, 2005
Nov 23, 2005
424
425
426
427
428
429
430
/*
if (SHORT2FROMMP(mp2)==VK_F1)
{
SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(SHORT2FROMMP(mp2), // VK_ code
SHORT1FROMMP(mp2), // Character code
CHAR4FROMMP(mp1), // HW Scan code
&keysym,0));
Feb 26, 2006
Feb 26, 2006
431
}*/
Nov 23, 2005
Nov 23, 2005
432
433
SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(SHORT2FROMMP(mp2), // VK_ code
Feb 26, 2006
Feb 26, 2006
434
435
SHORT1FROMMP(mp2), // Character code
CHAR4FROMMP(mp1), // HW Scan code
Nov 23, 2005
Nov 23, 2005
436
437
&keysym,0));
Feb 26, 2006
Feb 26, 2006
438
439
} else
{
Nov 23, 2005
Nov 23, 2005
440
441
442
443
444
445
// A key has been pressed
SDL_keysym keysym;
#ifdef DEBUG_BUILD
// printf("WM_CHAR, keydown, code is [0x%0x]\n", CHAR4FROMMP(mp1)); // HW scan code
#endif
Feb 26, 2006
Feb 26, 2006
446
// Check for fastkeys: ALT+HOME to toggle FS mode
Nov 23, 2005
Nov 23, 2005
447
// ALT+END to close app
Feb 26, 2006
Feb 26, 2006
448
449
450
if ((SHORT1FROMMP(mp1) & KC_ALT) &&
(SHORT2FROMMP(mp2) == VK_HOME))
{
Nov 23, 2005
Nov 23, 2005
451
#ifdef DEBUG_BUILD
Feb 26, 2006
Feb 26, 2006
452
printf(" Pressed ALT+HOME!\n"); fflush(stdout);
Nov 23, 2005
Nov 23, 2005
453
#endif
Feb 26, 2006
Feb 26, 2006
454
455
// Only switch between fullscreen and back if it's not
// a resizable mode!
Nov 23, 2005
Nov 23, 2005
456
457
458
459
460
461
if (
(!pVideo->hidden->pSDLSurface) ||
((pVideo->hidden->pSDLSurface)
&& ((pVideo->hidden->pSDLSurface->flags & SDL_RESIZABLE)==0)
)
)
Feb 26, 2006
Feb 26, 2006
462
FSLib_ToggleFSMode(hwnd, !FSLib_QueryFSMode(hwnd));
Nov 23, 2005
Nov 23, 2005
463
464
#ifdef DEBUG_BUILD
else
Feb 26, 2006
Feb 26, 2006
465
printf(" Resizable mode, so discarding ALT+HOME!\n"); fflush(stdout);
Nov 23, 2005
Nov 23, 2005
466
#endif
Feb 26, 2006
Feb 26, 2006
467
468
469
} else
if ((SHORT1FROMMP(mp1) & KC_ALT) &&
(SHORT2FROMMP(mp2) == VK_END))
Nov 23, 2005
Nov 23, 2005
470
471
472
473
474
475
476
477
478
{
#ifdef DEBUG_BUILD
printf(" Pressed ALT+END!\n"); fflush(stdout);
#endif
// Close window, and get out of loop!
// Also send event to SDL application, but we won't
// wait for it to be processed!
SDL_PrivateQuit();
WinPostMsg(hwnd, WM_QUIT, 0, 0);
Feb 26, 2006
Feb 26, 2006
479
} else
Nov 23, 2005
Nov 23, 2005
480
481
{
Feb 26, 2006
Feb 26, 2006
482
483
484
SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(SHORT2FROMMP(mp2), // VK_ code
SHORT1FROMMP(mp2), // Character code
CHAR4FROMMP(mp1), // HW Scan code
Nov 23, 2005
Nov 23, 2005
485
486
&keysym,1));
Feb 26, 2006
Feb 26, 2006
487
488
}
}
Nov 23, 2005
Nov 23, 2005
489
490
491
492
493
}
return (MRESULT) TRUE;
case WM_TRANSLATEACCEL:
{
Feb 26, 2006
Feb 26, 2006
494
495
496
497
498
499
500
501
502
503
504
PQMSG pqmsg;
pqmsg = (PQMSG) mp1;
if (mp1)
{
if (pqmsg->msg == WM_CHAR)
{
// WM_CHAR message!
// Let's filter the ALT keypress and all other acceleration keys!
return (MRESULT) FALSE;
}
}
Nov 23, 2005
Nov 23, 2005
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
break; // Default processing (pass to parent until frame control)
}
case WM_PAINT: // Window redraw!
#ifdef DEBUG_BUILD
printf("WM_PAINT (0x%x)\n", hwnd); fflush(stdout);
#endif
ps = WinBeginPaint(hwnd,0,&rcl);
pVideo = FSLib_GetUserParm(hwnd);
if (pVideo)
{
if (!pVideo->hidden->pSDLSurface)
{
RECTL rclRect;
// So, don't blit now!
#ifdef DEBUG_BUILD
printf("WM_PAINT : Skipping blit while resizing (Pre!)!\n"); fflush(stdout);
#endif
WinQueryWindowRect(hwnd, &rclRect);
// Fill with black
WinFillRect(ps, &rclRect, CLR_BLACK);
} else
{
if (DosRequestMutexSem(pVideo->hidden->hmtxUseSrcBuffer, 1000)==NO_ERROR)
{
int iTop, iLeft, iWidth, iHeight;
int iXScaleError, iYScaleError;
int iXScaleError2, iYScaleError2;
SWP swp;
// Re-blit the modified area!
// For this, we have to calculate the points, scaled!
WinQueryWindowPos(hwnd, &swp);
#ifdef DEBUG_BUILD
printf("WM_PAINT : WinSize: %d %d, BufSize: %d %d\n",
swp.cx,
swp.cy,
pVideo->hidden->SrcBufferDesc.uiXResolution,
pVideo->hidden->SrcBufferDesc.uiYResolution
);
fflush(stdout);
#endif
#ifndef RESIZE_EVEN_IF_RESIZABLE
// But only blit if the window is not resizable, or if
// the window is resizable and the source buffer size is the
// same as the destination buffer size!
if ((!pVideo->hidden->pSDLSurface) ||
((pVideo->hidden->pSDLSurface) &&
(pVideo->hidden->pSDLSurface->flags & SDL_RESIZABLE) &&
((swp.cx != pVideo->hidden->SrcBufferDesc.uiXResolution) ||
(swp.cy != pVideo->hidden->SrcBufferDesc.uiYResolution)
) &&
(!FSLib_QueryFSMode(hwnd))
)
)
{
RECTL rclRect;
// Resizable surface and in resizing!
// So, don't blit now!
#ifdef DEBUG_BUILD
printf("WM_PAINT : Skipping blit while resizing!\n"); fflush(stdout);
#endif
WinQueryWindowRect(hwnd, &rclRect);
// Fill with black
WinFillRect(ps, &rclRect, CLR_BLACK);
} else
#endif
{
iXScaleError = (pVideo->hidden->SrcBufferDesc.uiXResolution-1) / swp.cx;
iYScaleError = (pVideo->hidden->SrcBufferDesc.uiYResolution-1) / swp.cy;
if (iXScaleError<0) iXScaleError = 0;
if (iYScaleError<0) iYScaleError = 0;
iXScaleError2 = (swp.cx-1)/(pVideo->hidden->SrcBufferDesc.uiXResolution);
iYScaleError2 = (swp.cy-1)/(pVideo->hidden->SrcBufferDesc.uiYResolution);
if (iXScaleError2<0) iXScaleError2 = 0;
if (iYScaleError2<0) iYScaleError2 = 0;
iTop = (swp.cy - rcl.yTop) * pVideo->hidden->SrcBufferDesc.uiYResolution / swp.cy - iYScaleError;
iLeft = rcl.xLeft * pVideo->hidden->SrcBufferDesc.uiXResolution / swp.cx - iXScaleError;
iWidth = ((rcl.xRight-rcl.xLeft) * pVideo->hidden->SrcBufferDesc.uiXResolution + swp.cx-1)
/ swp.cx + 2*iXScaleError;
iHeight = ((rcl.yTop-rcl.yBottom) * pVideo->hidden->SrcBufferDesc.uiYResolution + swp.cy-1)
/ swp.cy + 2*iYScaleError;
iWidth+=iXScaleError2;
iHeight+=iYScaleError2;
if (iTop<0) iTop = 0;
if (iLeft<0) iLeft = 0;
if (iTop+iHeight>pVideo->hidden->SrcBufferDesc.uiYResolution) iHeight = pVideo->hidden->SrcBufferDesc.uiYResolution-iTop;
if (iLeft+iWidth>pVideo->hidden->SrcBufferDesc.uiXResolution) iWidth = pVideo->hidden->SrcBufferDesc.uiXResolution-iLeft;
#ifdef DEBUG_BUILD
printf("WM_PAINT : BitBlt: %d %d -> %d %d (Buf %d x %d)\n",
iTop, iLeft, iWidth, iHeight,
pVideo->hidden->SrcBufferDesc.uiXResolution,
pVideo->hidden->SrcBufferDesc.uiYResolution
);
fflush(stdout);
#endif
FSLIB_BITBLT(hwnd, pVideo->hidden->pchSrcBuffer, iTop, iLeft, iWidth, iHeight);
}
DosReleaseMutexSem(pVideo->hidden->hmtxUseSrcBuffer);
}
}
}
#ifdef DEBUG_BUILD
else
{
Feb 26, 2006
Feb 26, 2006
618
printf("WM_PAINT : No pVideo!\n"); fflush(stdout);
Nov 23, 2005
Nov 23, 2005
619
620
621
622
623
624
625
626
627
628
629
630
}
#endif
WinEndPaint(ps);
#ifdef DEBUG_BUILD
printf("WM_PAINT : Done.\n");
fflush(stdout);
#endif
return 0;
case WM_SIZE:
{
#ifdef DEBUG_BUILD
Feb 26, 2006
Feb 26, 2006
631
632
printf("WM_SIZE : (%d %d)\n",
SHORT1FROMMP(mp2), SHORT2FROMMP(mp2)); fflush(stdout);
Nov 23, 2005
Nov 23, 2005
633
634
635
636
637
#endif
iWindowSizeX = SHORT1FROMMP(mp2);
iWindowSizeY = SHORT2FROMMP(mp2);
bWindowResized = 1;
Feb 26, 2006
Feb 26, 2006
638
// Make sure the window will be redrawn
Nov 23, 2005
Nov 23, 2005
639
640
641
642
643
644
645
646
647
648
WinInvalidateRegion(hwnd, NULL, TRUE);
}
break;
case WM_FSLIBNOTIFICATION:
#ifdef DEBUG_BUILD
printf("WM_FSLIBNOTIFICATION\n"); fflush(stdout);
#endif
if ((int)mp1 == FSLN_TOGGLEFSMODE)
{
Feb 26, 2006
Feb 26, 2006
649
650
651
// FS mode changed, reblit image!
pVideo = FSLib_GetUserParm(hwnd);
if (pVideo)
Nov 23, 2005
Nov 23, 2005
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
{
if (!pVideo->hidden->pSDLSurface)
{
// Resizable surface and in resizing!
// So, don't blit now!
#ifdef DEBUG_BUILD
printf("WM_FSLIBNOTIFICATION : Can not blit if there is no surface, doing nothing.\n"); fflush(stdout);
#endif
} else
{
if (DosRequestMutexSem(pVideo->hidden->hmtxUseSrcBuffer, 1000)==NO_ERROR)
{
if (pVideo->hidden->pSDLSurface)
{
#ifndef RESIZE_EVEN_IF_RESIZABLE
SWP swp;
// But only blit if the window is not resizable, or if
// the window is resizable and the source buffer size is the
// same as the destination buffer size!
WinQueryWindowPos(hwnd, &swp);
if ((!pVideo->hidden->pSDLSurface) ||
(
(pVideo->hidden->pSDLSurface) &&
(pVideo->hidden->pSDLSurface->flags & SDL_RESIZABLE) &&
((swp.cx != pVideo->hidden->SrcBufferDesc.uiXResolution) ||
(swp.cy != pVideo->hidden->SrcBufferDesc.uiYResolution)
) &&
(!FSLib_QueryFSMode(hwnd))
)
)
{
// Resizable surface and in resizing!
// So, don't blit now!
#ifdef DEBUG_BUILD
printf("WM_FSLIBNOTIFICATION : Cannot blit while resizing, doing nothing.\n"); fflush(stdout);
#endif
} else
#endif
{
#ifdef DEBUG_BUILD
printf("WM_FSLIBNOTIFICATION : Blitting!\n"); fflush(stdout);
#endif
FSLIB_BITBLT(hwnd, pVideo->hidden->pchSrcBuffer,
0, 0,
pVideo->hidden->SrcBufferDesc.uiXResolution,
pVideo->hidden->SrcBufferDesc.uiYResolution);
}
}
#ifdef DEBUG_BUILD
else
printf("WM_FSLIBNOTIFICATION : No public surface!\n"); fflush(stdout);
#endif
DosReleaseMutexSem(pVideo->hidden->hmtxUseSrcBuffer);
}
}
Feb 26, 2006
Feb 26, 2006
709
}
Nov 23, 2005
Nov 23, 2005
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
}
return (MPARAM) 1;
case WM_ACTIVATE:
#ifdef DEBUG_BUILD
printf("WM_ACTIVATE\n"); fflush(stdout);
#endif
pVideo = FSLib_GetUserParm(hwnd);
if (pVideo)
{
pVideo->hidden->fInFocus = (int) mp1;
if (pVideo->hidden->fInFocus)
{
// Went into focus
if ((pVideo->hidden->iMouseVisible) && (!bMouseCaptured))
WinSetPointer(HWND_DESKTOP, WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE));
else
Feb 26, 2006
Feb 26, 2006
728
WinSetPointer(HWND_DESKTOP, NULL);
Nov 23, 2005
Nov 23, 2005
729
Feb 26, 2006
Feb 26, 2006
730
731
if (bMouseCapturable)
{
Nov 23, 2005
Nov 23, 2005
732
// Re-capture the mouse, if we captured it before!
Feb 26, 2006
Feb 26, 2006
733
WinSetCapture(HWND_DESKTOP, hwnd);
Nov 23, 2005
Nov 23, 2005
734
735
736
737
738
739
740
741
742
743
744
745
746
bMouseCaptured = 1;
{
SWP swpClient;
POINTL ptl;
// Center the mouse to the middle of the window!
WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient);
ptl.x = 0; ptl.y = 0;
WinMapWindowPoints(pVideo->hidden->hwndClient, HWND_DESKTOP, &ptl, 1);
pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
WinSetPointerPos(HWND_DESKTOP,
ptl.x + swpClient.cx/2,
ptl.y + swpClient.cy/2);
}
Feb 26, 2006
Feb 26, 2006
747
}
Nov 23, 2005
Nov 23, 2005
748
749
750
} else
{
// Went out of focus
Feb 26, 2006
Feb 26, 2006
751
WinSetPointer(HWND_DESKTOP, WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE));
Nov 23, 2005
Nov 23, 2005
752
Feb 26, 2006
Feb 26, 2006
753
754
if (bMouseCaptured)
{
Nov 23, 2005
Nov 23, 2005
755
// Release the mouse
Feb 26, 2006
Feb 26, 2006
756
WinSetCapture(HWND_DESKTOP, hwnd);
Nov 23, 2005
Nov 23, 2005
757
bMouseCaptured = 0;
Feb 26, 2006
Feb 26, 2006
758
}
Nov 23, 2005
Nov 23, 2005
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
}
}
#ifdef DEBUG_BUILD
printf("WM_ACTIVATE done\n"); fflush(stdout);
#endif
break;
case WM_BUTTON1DOWN:
#ifdef DEBUG_BUILD
printf("WM_BUTTON1DOWN\n"); fflush(stdout);
#endif
pVideo = FSLib_GetUserParm(hwnd);
if (pVideo)
{
Feb 26, 2006
Feb 26, 2006
775
SDL_PrivateMouseButton(SDL_PRESSED,
Nov 23, 2005
Nov 23, 2005
776
777
778
SDL_BUTTON_LEFT,
0, 0); // Don't report mouse movement!
Feb 26, 2006
Feb 26, 2006
779
780
781
782
783
784
if (bMouseCapturable)
{
// We should capture the mouse!
if (!bMouseCaptured)
{
WinSetCapture(HWND_DESKTOP, hwnd);
Nov 23, 2005
Nov 23, 2005
785
786
787
788
789
790
791
792
793
794
795
796
797
798
WinSetPointer(HWND_DESKTOP, NULL);
bMouseCaptured = 1;
{
SWP swpClient;
POINTL ptl;
// Center the mouse to the middle of the window!
WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient);
ptl.x = 0; ptl.y = 0;
WinMapWindowPoints(pVideo->hidden->hwndClient, HWND_DESKTOP, &ptl, 1);
pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
WinSetPointerPos(HWND_DESKTOP,
ptl.x + swpClient.cx/2,
ptl.y + swpClient.cy/2);
}
Feb 26, 2006
Feb 26, 2006
799
800
}
}
Nov 23, 2005
Nov 23, 2005
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
}
break;
case WM_BUTTON1UP:
#ifdef DEBUG_BUILD
printf("WM_BUTTON1UP\n"); fflush(stdout);
#endif
SDL_PrivateMouseButton(SDL_RELEASED,
SDL_BUTTON_LEFT,
0, 0); // Don't report mouse movement!
break;
case WM_BUTTON2DOWN:
#ifdef DEBUG_BUILD
printf("WM_BUTTON2DOWN\n"); fflush(stdout);
#endif
pVideo = FSLib_GetUserParm(hwnd);
if (pVideo)
{
Feb 26, 2006
Feb 26, 2006
819
SDL_PrivateMouseButton(SDL_PRESSED,
Nov 23, 2005
Nov 23, 2005
820
821
822
SDL_BUTTON_RIGHT,
0, 0); // Don't report mouse movement!
Feb 26, 2006
Feb 26, 2006
823
824
825
826
827
828
if (bMouseCapturable)
{
// We should capture the mouse!
if (!bMouseCaptured)
{
WinSetCapture(HWND_DESKTOP, hwnd);
Nov 23, 2005
Nov 23, 2005
829
830
831
832
833
834
835
836
837
838
839
840
841
842
WinSetPointer(HWND_DESKTOP, NULL);
bMouseCaptured = 1;
{
SWP swpClient;
POINTL ptl;
// Center the mouse to the middle of the window!
WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient);
ptl.x = 0; ptl.y = 0;
WinMapWindowPoints(pVideo->hidden->hwndClient, HWND_DESKTOP, &ptl, 1);
pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
WinSetPointerPos(HWND_DESKTOP,
ptl.x + swpClient.cx/2,
ptl.y + swpClient.cy/2);
}
Feb 26, 2006
Feb 26, 2006
843
844
}
}
Nov 23, 2005
Nov 23, 2005
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
}
break;
case WM_BUTTON2UP:
#ifdef DEBUG_BUILD
printf("WM_BUTTON2UP\n"); fflush(stdout);
#endif
SDL_PrivateMouseButton(SDL_RELEASED,
SDL_BUTTON_RIGHT,
0, 0); // Don't report mouse movement!
break;
case WM_BUTTON3DOWN:
#ifdef DEBUG_BUILD
printf("WM_BUTTON3DOWN\n"); fflush(stdout);
#endif
pVideo = FSLib_GetUserParm(hwnd);
if (pVideo)
{
SDL_PrivateMouseButton(SDL_PRESSED,
SDL_BUTTON_MIDDLE,
0, 0); // Don't report mouse movement!
Feb 26, 2006
Feb 26, 2006
868
869
870
871
872
873
if (bMouseCapturable)
{
// We should capture the mouse!
if (!bMouseCaptured)
{
WinSetCapture(HWND_DESKTOP, hwnd);
Nov 23, 2005
Nov 23, 2005
874
875
876
877
878
879
880
881
882
883
884
885
886
887
WinSetPointer(HWND_DESKTOP, NULL);
bMouseCaptured = 1;
{
SWP swpClient;
POINTL ptl;
// Center the mouse to the middle of the window!
WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient);
ptl.x = 0; ptl.y = 0;
WinMapWindowPoints(pVideo->hidden->hwndClient, HWND_DESKTOP, &ptl, 1);
pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
WinSetPointerPos(HWND_DESKTOP,
ptl.x + swpClient.cx/2,
ptl.y + swpClient.cy/2);
}
Feb 26, 2006
Feb 26, 2006
888
889
}
}
Nov 23, 2005
Nov 23, 2005
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
}
break;
case WM_BUTTON3UP:
#ifdef DEBUG_BUILD
printf("WM_BUTTON3UP\n"); fflush(stdout);
#endif
SDL_PrivateMouseButton(SDL_RELEASED,
SDL_BUTTON_MIDDLE,
0, 0); // Don't report mouse movement!
break;
case WM_MOUSEMOVE:
#ifdef DEBUG_BUILD
// printf("WM_MOUSEMOVE\n"); fflush(stdout);
#endif
pVideo = FSLib_GetUserParm(hwnd);
if (pVideo)
{
if (pVideo->hidden->iSkipWMMOUSEMOVE)
{
pVideo->hidden->iSkipWMMOUSEMOVE--;
} else
{
POINTS *ppts = (POINTS *) (&mp1);
POINTL ptl;
if (bMouseCaptured)
{
SWP swpClient;
Feb 26, 2006
Feb 26, 2006
919
920
921
WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient);
Nov 23, 2005
Nov 23, 2005
922
923
924
925
// Send relative mouse position, and re-center the mouse
// Reposition the mouse to the center of the screen/window
SDL_PrivateMouseMotion(0, // Buttons not changed
1, // Relative position
Feb 26, 2006
Feb 26, 2006
926
927
ppts->x - (swpClient.cx/2),
(swpClient.cy/2) - ppts->y);
Nov 23, 2005
Nov 23, 2005
928
929
930
931
932
933
934
935
936
937
ptl.x = 0; ptl.y = 0;
WinMapWindowPoints(pVideo->hidden->hwndClient, HWND_DESKTOP, &ptl, 1);
pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
// Center the mouse to the middle of the window!
WinSetPointerPos(HWND_DESKTOP,
ptl.x + swpClient.cx/2,
ptl.y + swpClient.cy/2);
} else
{
Feb 26, 2006
Feb 26, 2006
938
939
CONVERTMOUSEPOSITION();
Nov 23, 2005
Nov 23, 2005
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Send absolute mouse position
SDL_PrivateMouseMotion(0, // Buttons not changed
0, // Absolute position
ppts->x,
ppts->y);
}
}
if ((pVideo->hidden->iMouseVisible) && (!bMouseCaptured))
{
#ifdef DEBUG_BUILD
// printf("WM_MOUSEMOVE : ptr = %p\n", hptrGlobalPointer); fflush(stdout);
#endif
if (hptrGlobalPointer)
WinSetPointer(HWND_DESKTOP, hptrGlobalPointer);
else
WinSetPointer(HWND_DESKTOP, WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE));
}
else
{
WinSetPointer(HWND_DESKTOP, NULL);
}
}
#ifdef DEBUG_BUILD
// printf("WM_MOUSEMOVE done\n"); fflush(stdout);
#endif
return (MRESULT) FALSE;
case WM_CLOSE: // Window close
#ifdef DEBUG_BUILD
printf("WM_CLOSE\n"); fflush(stdout);
#endif
pVideo = FSLib_GetUserParm(hwnd);
if (pVideo)
{
// Send Quit message to the SDL application!
SDL_PrivateQuit();
return 0;
}
break;
#ifdef BITBLT_IN_WINMESSAGEPROC
case WM_UPDATERECTSREQUEST:
pVideo = FSLib_GetUserParm(hwnd);
if ((pVideo) && (pVideo->hidden->pSDLSurface))
{
if (DosRequestMutexSem(pVideo->hidden->hmtxUseSrcBuffer, SEM_INDEFINITE_WAIT)==NO_ERROR)
{
int numrects;
SDL_Rect *rects;
int i;
SWP swp;
numrects = (int) mp1;
rects = (SDL_Rect *) mp2;
WinQueryWindowPos(hwnd, &swp);
#ifndef RESIZE_EVEN_IF_RESIZABLE
if ((!pVideo->hidden->pSDLSurface) ||
(