This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
SDL_os2fslib.c
3121 lines (2773 loc) · 107 KB
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
*/
22
#include "SDL_config.h"
23
24
25
#define _ULS_CALLCONV_
#define CALLCONV _System
26
27
#include <unidef.h> // Unicode API
#include <uconv.h> // Unicode API (codepage conversion)
28
29
30
31
32
33
#include <process.h>
#include <time.h>
#include "SDL_video.h"
#include "SDL_mouse.h"
34
35
36
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
37
38
39
40
#include "SDL_os2fslib.h"
static ULONG ulFCFToUse =
41
42
43
44
45
46
FCF_TITLEBAR |
FCF_SYSMENU |
FCF_MINBUTTON |
FCF_MAXBUTTON | FCF_NOBYTEALIGN | FCF_SIZEBORDER | FCF_TASKLIST;
static int bMouseCaptured = 0;
47
48
49
50
51
52
53
54
55
56
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
{
57
58
BITMAPINFO;
RGB clr;
59
60
61
62
63
} BMPINFO, *PBMPINFO;
#pragma pack()
// Backdoors:
64
DECLSPEC void SDLCALL
65
SDL_OS2FSLIB_SetFCFToUse(ULONG ulFCF)
66
{
67
ulFCFToUse = ulFCF;
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
}
// 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];
93
94
static SDL_keysym *TranslateKey(int vkey, int chcode, int scancode,
SDL_keysym * keysym, int iPressed);
95
static int iShiftIsPressed;
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
#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.
//
/////////////////////////////////////////////////////////////////////
121
static BOOL
122
123
SetAccessableWindowPos(HWND hwnd, HWND hwndInsertBehind,
LONG x, LONG y, LONG cx, LONG cy, ULONG fl)
124
{
125
126
SWP swpDesktop, swp;
// Get desktop area
127
WinQueryWindowPos(HWND_DESKTOP, &swpDesktop);
128
129
130
131
132
133
134
135
136
137
138
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;
139
return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
140
141
} else if (fl & SWP_MOVE) {
// Just moving
142
WinQueryWindowPos(hwnd, &swp);
143
144
145
146
147
148
149
150
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;
151
return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
152
153
} else if (fl & SWP_SIZE) {
// Just sizing
154
WinQueryWindowPos(hwnd, &swp);
155
156
157
158
159
160
161
162
163
164
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;
165
166
return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy,
fl | SWP_MOVE);
167
} else
168
return WinSetWindowPos(hwnd, hwndInsertBehind, x, y, cx, cy, fl);
169
170
}
171
static UniChar
172
NativeCharToUniChar(int chcode)
173
{
174
175
176
177
178
179
180
181
182
183
184
185
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
186
rc = UniCreateUconvObject(L"", &ucoTemp);
187
188
189
190
191
192
193
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;
194
195
iFromCount = sizeof(char) * 2;
iToCount = sizeof(UniChar) * 2;
196
197
198
pucTo = &(aucTo[0]);
pchFrom = &(achFrom[0]);
199
200
201
rc = UniUconvToUcs(ucoTemp,
&pchFrom,
&iFromCount, &pucTo, &iToCount, &iNonIdentical);
202
203
204
if (rc != ULS_SUCCESS) {
// Could not convert language code to UCS string!
205
UniFreeUconvObject(ucoTemp);
206
207
208
return ucResult;
}
209
UniFreeUconvObject(ucoTemp);
210
211
#ifdef DEBUG_BUILD
212
printf("%02x converted to %02x\n", (int) chcode, (int) (aucTo[0]));
213
214
215
#endif
return aucTo[0];
216
217
}
218
219
220
221
222
223
224
/////////////////////////////////////////////////////////////////////
//
// TranslateKey
//
// This creates SDL Keycodes from VK_ and hardware scan codes
//
/////////////////////////////////////////////////////////////////////
225
static SDL_keysym *
226
227
TranslateKey(int vkey, int chcode, int scancode, SDL_keysym * keysym,
int iPressed)
228
{
229
230
231
keysym->scancode = (unsigned char) scancode;
keysym->mod = KMOD_NONE;
keysym->unicode = 0;
232
233
234
if (iPressed && SDL_TranslateUNICODE) {
if (chcode)
235
keysym->unicode = NativeCharToUniChar(chcode);
236
237
238
else
keysym->unicode = vkey;
}
239
240
keysym->sym = HWScanKeyMap[scancode];
241
242
243
244
245
// Now stuffs based on state of shift key(s)!
if (vkey == VK_SHIFT) {
iShiftIsPressed = iPressed;
}
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
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:
keysym->sym = '~';
break;
case SDLK_1:
keysym->sym = SDLK_EXCLAIM;
break;
case SDLK_2:
keysym->sym = SDLK_AT;
break;
case SDLK_3:
keysym->sym = SDLK_HASH;
break;
case SDLK_4:
keysym->sym = SDLK_DOLLAR;
break;
case SDLK_5:
keysym->sym = '%';
break;
case SDLK_6:
keysym->sym = SDLK_CARET;
break;
case SDLK_7:
keysym->sym = SDLK_AMPERSAND;
break;
case SDLK_8:
keysym->sym = SDLK_ASTERISK;
break;
case SDLK_9:
keysym->sym = SDLK_LEFTPAREN;
break;
case SDLK_0:
keysym->sym = SDLK_RIGHTPAREN;
break;
case SDLK_MINUS:
keysym->sym = SDLK_UNDERSCORE;
break;
case SDLK_PLUS:
keysym->sym = SDLK_EQUALS;
break;
case SDLK_LEFTBRACKET:
keysym->sym = '{';
break;
case SDLK_RIGHTBRACKET:
keysym->sym = '}';
break;
case SDLK_SEMICOLON:
keysym->sym = SDLK_COLON;
break;
case SDLK_QUOTE:
keysym->sym = SDLK_QUOTEDBL;
break;
case SDLK_BACKSLASH:
keysym->sym = '|';
break;
case SDLK_COMMA:
keysym->sym = SDLK_LESS;
break;
case SDLK_PERIOD:
keysym->sym = SDLK_GREATER;
break;
case SDLK_SLASH:
keysym->sym = SDLK_QUESTION;
break;
default:
break;
}
321
}
322
return keysym;
323
324
325
326
327
}
#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, */ \
328
329
330
331
332
333
/* 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) */ \
334
/* So, limit mouse pos to source buffer size! */ \
335
336
337
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; \
338
339
340
341
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); \
342
343
WinSetPointerPos(HWND_DESKTOP, ptl.x, ptl.y); \
/* Then convert OS/2 position to SDL position */ \
344
ppts->y = pVideo->hidden->SrcBufferDesc.uiYResolution - ppts->y - 1; \
345
346
347
} else \
{ \
SWP swpClient; \
348
/* We're in windowed mode! */ \
349
WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient); \
350
/* Convert OS/2 mouse position to SDL position, and also scale it! */ \
351
352
353
354
(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; \
}
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/////////////////////////////////////////////////////////////////////
//
// 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...
//
/////////////////////////////////////////////////////////////////////
369
static MRESULT EXPENTRY
370
WndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
371
{
372
373
374
HPS ps;
RECTL rcl;
SDL_VideoDevice *pVideo = NULL;
375
376
377
switch (msg) {
case WM_CHAR: // Keypress notification
378
379
380
#ifdef DEBUG_BUILD
// printf("WM_CHAR\n"); fflush(stdout);
#endif
381
pVideo = WinQueryWindowPtr(hwnd, 0);
382
383
384
385
386
387
388
389
390
391
392
393
394
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!
395
if (SHORT1FROMMP(mp1) & KC_KEYUP) {
396
397
// A key has been released
SDL_keysym keysym;
398
399
400
401
402
#ifdef DEBUG_BUILD
// printf("WM_CHAR, keyup, code is [0x%0x]\n", CHAR4FROMMP(mp1)); // HW scan code
#endif
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
// One problem is with F1, which gets only the keyup message because
// it is a system key.
// 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!
/*
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));
} */
418
419
420
421
SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(SHORT2FROMMP(mp2), // VK_ code
SHORT1FROMMP(mp2), // Character code
CHAR4FROMMP(mp1), // HW Scan code
&keysym, 0));
422
423
424
425
} else {
// A key has been pressed
SDL_keysym keysym;
426
427
428
429
#ifdef DEBUG_BUILD
// printf("WM_CHAR, keydown, code is [0x%0x]\n", CHAR4FROMMP(mp1)); // HW scan code
#endif
430
431
// Check for fastkeys: ALT+HOME to toggle FS mode
// ALT+END to close app
432
433
if ((SHORT1FROMMP(mp1) & KC_ALT) &&
(SHORT2FROMMP(mp2) == VK_HOME)) {
434
#ifdef DEBUG_BUILD
435
436
printf(" Pressed ALT+HOME!\n");
fflush(stdout);
437
438
439
440
441
442
443
444
#endif
// Only switch between fullscreen and back if it's not
// a resizable mode!
if ((!pVideo->hidden->pSDLSurface) ||
((pVideo->hidden->pSDLSurface)
&&
((pVideo->hidden->pSDLSurface->
flags & SDL_RESIZABLE) == 0)))
445
FSLib_ToggleFSMode(hwnd, !FSLib_QueryFSMode(hwnd));
446
447
#ifdef DEBUG_BUILD
else
448
449
printf(" Resizable mode, so discarding ALT+HOME!\n");
fflush(stdout);
450
#endif
451
452
} else if ((SHORT1FROMMP(mp1) & KC_ALT) &&
(SHORT2FROMMP(mp2) == VK_END)) {
453
#ifdef DEBUG_BUILD
454
455
printf(" Pressed ALT+END!\n");
fflush(stdout);
456
457
458
459
#endif
// Close window, and get out of loop!
// Also send event to SDL application, but we won't
// wait for it to be processed!
460
461
SDL_PrivateQuit();
WinPostMsg(hwnd, WM_QUIT, 0, 0);
462
463
} else {
464
465
466
467
468
SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(SHORT2FROMMP(mp2), // VK_ code
SHORT1FROMMP(mp2), // Character code
CHAR4FROMMP(mp1), // HW Scan code
&keysym,
1));
469
470
471
}
}
472
}
473
return (MRESULT) TRUE;
474
475
case WM_TRANSLATEACCEL:
476
{
477
478
479
480
481
482
483
484
485
486
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;
}
}
break; // Default processing (pass to parent until frame control)
487
}
488
489
case WM_PAINT: // Window redraw!
490
#ifdef DEBUG_BUILD
491
492
printf("WM_PAINT (0x%x)\n", hwnd);
fflush(stdout);
493
#endif
494
495
ps = WinBeginPaint(hwnd, 0, &rcl);
pVideo = FSLib_GetUserParm(hwnd);
496
497
498
499
if (pVideo) {
if (!pVideo->hidden->pSDLSurface) {
RECTL rclRect;
// So, don't blit now!
500
#ifdef DEBUG_BUILD
501
502
printf("WM_PAINT : Skipping blit while resizing (Pre!)!\n");
fflush(stdout);
503
#endif
504
WinQueryWindowRect(hwnd, &rclRect);
505
// Fill with black
506
WinFillRect(ps, &rclRect, CLR_BLACK);
507
508
509
510
511
512
513
514
515
516
} 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!
517
WinQueryWindowPos(hwnd, &swp);
518
#ifdef DEBUG_BUILD
519
520
521
522
523
printf
("WM_PAINT : WinSize: %d %d, BufSize: %d %d\n",
swp.cx, swp.cy,
pVideo->hidden->SrcBufferDesc.uiXResolution,
pVideo->hidden->SrcBufferDesc.uiYResolution);
524
fflush(stdout);
525
526
527
#endif
#ifndef RESIZE_EVEN_IF_RESIZABLE
528
529
530
531
532
533
534
535
536
537
538
// 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))
539
&& (!FSLib_QueryFSMode(hwnd)))) {
540
541
542
543
RECTL rclRect;
// Resizable surface and in resizing!
// So, don't blit now!
#ifdef DEBUG_BUILD
544
545
printf("WM_PAINT : Skipping blit while resizing!\n");
fflush(stdout);
546
#endif
547
WinQueryWindowRect(hwnd, &rclRect);
548
// Fill with black
549
WinFillRect(ps, &rclRect, CLR_BLACK);
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
618
619
620
621
622
623
} 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);
624
fflush(stdout);
625
626
#endif
627
628
629
FSLIB_BITBLT(hwnd,
pVideo->hidden->pchSrcBuffer,
iTop, iLeft, iWidth, iHeight);
630
631
}
632
DosReleaseMutexSem(pVideo->hidden->hmtxUseSrcBuffer);
633
}
634
635
636
}
}
#ifdef DEBUG_BUILD
637
else {
638
639
printf("WM_PAINT : No pVideo!\n");
fflush(stdout);
640
}
641
#endif
642
WinEndPaint(ps);
643
#ifdef DEBUG_BUILD
644
645
printf("WM_PAINT : Done.\n");
fflush(stdout);
646
#endif
647
return 0;
648
649
case WM_SIZE:
650
{
651
#ifdef DEBUG_BUILD
652
653
654
printf("WM_SIZE : (%d %d)\n",
SHORT1FROMMP(mp2), SHORT2FROMMP(mp2));
fflush(stdout);
655
#endif
656
657
iWindowSizeX = SHORT1FROMMP(mp2);
iWindowSizeY = SHORT2FROMMP(mp2);
658
bWindowResized = 1;
659
660
// Make sure the window will be redrawn
661
WinInvalidateRegion(hwnd, NULL, TRUE);
662
663
}
break;
664
665
666
case WM_FSLIBNOTIFICATION:
#ifdef DEBUG_BUILD
667
668
printf("WM_FSLIBNOTIFICATION\n");
fflush(stdout);
669
670
671
#endif
if ((int) mp1 == FSLN_TOGGLEFSMODE) {
// FS mode changed, reblit image!
672
pVideo = FSLib_GetUserParm(hwnd);
673
674
675
676
677
678
679
if (pVideo) {
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");
680
fflush(stdout);
681
682
683
684
685
686
#endif
} else {
if (DosRequestMutexSem
(pVideo->hidden->hmtxUseSrcBuffer,
1000) == NO_ERROR) {
if (pVideo->hidden->pSDLSurface) {
687
#ifndef RESIZE_EVEN_IF_RESIZABLE
688
689
690
691
692
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!
693
WinQueryWindowPos(hwnd, &swp);
694
695
696
697
698
699
700
701
702
703
704
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))
705
&& (!FSLib_QueryFSMode(hwnd)))) {
706
707
708
709
710
// Resizable surface and in resizing!
// So, don't blit now!
#ifdef DEBUG_BUILD
printf
("WM_FSLIBNOTIFICATION : Cannot blit while resizing, doing nothing.\n");
711
fflush(stdout);
712
713
714
715
716
#endif
} else
#endif
{
#ifdef DEBUG_BUILD
717
718
719
720
721
722
723
724
725
726
727
728
printf("WM_FSLIBNOTIFICATION : Blitting!\n");
fflush(stdout);
#endif
FSLIB_BITBLT(hwnd,
pVideo->hidden->
pchSrcBuffer, 0,
0,
pVideo->hidden->
SrcBufferDesc.
uiXResolution,
pVideo->hidden->
SrcBufferDesc.uiYResolution);
729
730
731
732
733
734
}
}
#ifdef DEBUG_BUILD
else
printf
("WM_FSLIBNOTIFICATION : No public surface!\n");
735
fflush(stdout);
736
737
#endif
738
DosReleaseMutexSem(pVideo->hidden->hmtxUseSrcBuffer);
739
}
740
741
}
}
742
}
743
return (MPARAM) 1;
744
745
746
case WM_ACTIVATE:
#ifdef DEBUG_BUILD
747
748
printf("WM_ACTIVATE\n");
fflush(stdout);
749
750
#endif
751
pVideo = FSLib_GetUserParm(hwnd);
752
753
754
755
756
757
if (pVideo) {
pVideo->hidden->fInFocus = (int) mp1;
if (pVideo->hidden->fInFocus) {
// Went into focus
if ((pVideo->hidden->iMouseVisible)
&& (!bMouseCaptured))
758
759
760
WinSetPointer(HWND_DESKTOP,
WinQuerySysPointer(HWND_DESKTOP,
SPTR_ARROW, FALSE));
761
else
762
WinSetPointer(HWND_DESKTOP, NULL);
763
764
765
if (bMouseCapturable) {
// Re-capture the mouse, if we captured it before!
766
WinSetCapture(HWND_DESKTOP, hwnd);
767
768
769
770
771
bMouseCaptured = 1;
{
SWP swpClient;
POINTL ptl;
// Center the mouse to the middle of the window!
772
773
WinQueryWindowPos(pVideo->hidden->hwndClient,
&swpClient);
774
775
ptl.x = 0;
ptl.y = 0;
776
777
WinMapWindowPoints(pVideo->hidden->
hwndClient, HWND_DESKTOP, &ptl, 1);
778
pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
779
780
781
WinSetPointerPos(HWND_DESKTOP,
ptl.x + swpClient.cx / 2,
ptl.y + swpClient.cy / 2);
782
783
784
785
}
}
} else {
// Went out of focus
786
787
788
WinSetPointer(HWND_DESKTOP,
WinQuerySysPointer(HWND_DESKTOP,
SPTR_ARROW, FALSE));
789
790
791
if (bMouseCaptured) {
// Release the mouse
792
WinSetCapture(HWND_DESKTOP, hwnd);
793
794
bMouseCaptured = 0;
}
795
796
797
}
}
#ifdef DEBUG_BUILD
798
799
printf("WM_ACTIVATE done\n");
fflush(stdout);
800
801
#endif
802
break;
803
804
805
case WM_BUTTON1DOWN:
#ifdef DEBUG_BUILD
806
807
printf("WM_BUTTON1DOWN\n");
fflush(stdout);
808
809
#endif
810
pVideo = FSLib_GetUserParm(hwnd);
811
if (pVideo) {
812
SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0); // Don't report mouse movement!
813
814
815
816
if (bMouseCapturable) {
// We should capture the mouse!
if (!bMouseCaptured) {
817
818
WinSetCapture(HWND_DESKTOP, hwnd);
WinSetPointer(HWND_DESKTOP, NULL);
819
820
821
822
823
bMouseCaptured = 1;
{
SWP swpClient;
POINTL ptl;
// Center the mouse to the middle of the window!
824
825
WinQueryWindowPos(pVideo->hidden->hwndClient,
&swpClient);
826
827
ptl.x = 0;
ptl.y = 0;
828
829
WinMapWindowPoints(pVideo->hidden->
hwndClient, HWND_DESKTOP, &ptl, 1);
830
pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
831
832
833
WinSetPointerPos(HWND_DESKTOP,
ptl.x + swpClient.cx / 2,
ptl.y + swpClient.cy / 2);
834
835
}
}
836
}
837
}
838
break;
839
840
case WM_BUTTON1UP:
#ifdef DEBUG_BUILD
841
842
printf("WM_BUTTON1UP\n");
fflush(stdout);
843
#endif
844
SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0); // Don't report mouse movement!
845
break;
846
847
case WM_BUTTON2DOWN:
#ifdef DEBUG_BUILD
848
849
printf("WM_BUTTON2DOWN\n");
fflush(stdout);
850
851
#endif
852
pVideo = FSLib_GetUserParm(hwnd);
853
if (pVideo) {
854
SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_RIGHT, 0, 0); // Don't report mouse movement!
855
856
857
858
if (bMouseCapturable) {
// We should capture the mouse!
if (!bMouseCaptured) {
859
860
WinSetCapture(HWND_DESKTOP, hwnd);
WinSetPointer(HWND_DESKTOP, NULL);
861
862
863
864
865
bMouseCaptured = 1;
{
SWP swpClient;
POINTL ptl;
// Center the mouse to the middle of the window!
866
867
WinQueryWindowPos(pVideo->hidden->hwndClient,
&swpClient);
868
869
ptl.x = 0;
ptl.y = 0;
870
871
WinMapWindowPoints(pVideo->hidden->
hwndClient, HWND_DESKTOP, &ptl, 1);
872
pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
873
874
875
WinSetPointerPos(HWND_DESKTOP,
ptl.x + swpClient.cx / 2,
ptl.y + swpClient.cy / 2);
876
877
}
}
878
879
}
880
881
}
break;
882
883
case WM_BUTTON2UP:
#ifdef DEBUG_BUILD
884
885
printf("WM_BUTTON2UP\n");
fflush(stdout);
886
#endif
887
SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0); // Don't report mouse movement!
888
break;
889
890
case WM_BUTTON3DOWN:
#ifdef DEBUG_BUILD
891
892
printf("WM_BUTTON3DOWN\n");
fflush(stdout);
893
894
#endif
895
pVideo = FSLib_GetUserParm(hwnd);
896
if (pVideo) {
897
SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_MIDDLE, 0, 0); // Don't report mouse movement!
898
899
900
901
if (bMouseCapturable) {
// We should capture the mouse!
if (!bMouseCaptured) {
902
903
WinSetCapture(HWND_DESKTOP, hwnd);
WinSetPointer(HWND_DESKTOP, NULL);
904
905
906
907
908
bMouseCaptured = 1;
{
SWP swpClient;
POINTL ptl;
// Center the mouse to the middle of the window!
909
910
WinQueryWindowPos(pVideo->hidden->hwndClient,
&swpClient);
911
912
ptl.x = 0;
ptl.y = 0;
913
914
WinMapWindowPoints(pVideo->hidden->
hwndClient, HWND_DESKTOP, &ptl, 1);
915
pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
916
917
918
WinSetPointerPos(HWND_DESKTOP,
ptl.x + swpClient.cx / 2,
ptl.y + swpClient.cy / 2);
919
920
}
}
921
}
922
}
923
break;
924
925
case WM_BUTTON3UP:
#ifdef DEBUG_BUILD
926
927
printf("WM_BUTTON3UP\n");
fflush(stdout);
928
#endif
929
SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_MIDDLE, 0, 0); // Don't report mouse movement!
930
break;
931
932
933
934
935
case WM_MOUSEMOVE:
#ifdef DEBUG_BUILD
// printf("WM_MOUSEMOVE\n"); fflush(stdout);
#endif
936
pVideo = FSLib_GetUserParm(hwnd);
937
938
939
940
941
942
943
944
945
946
if (pVideo) {
if (pVideo->hidden->iSkipWMMOUSEMOVE) {
pVideo->hidden->iSkipWMMOUSEMOVE--;
} else {
POINTS *ppts = (POINTS *) (&mp1);
POINTL ptl;
if (bMouseCaptured) {
SWP swpClient;
947
WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient);
948
949
950
// Send relative mouse position, and re-center the mouse
// Reposition the mouse to the center of the screen/window
951
952
953
954
955
SDL_PrivateMouseMotion(0, // Buttons not changed
1, // Relative position
ppts->x -
(swpClient.cx / 2),
(swpClient.cy / 2) - ppts->y);
956
957
958
ptl.x = 0;
ptl.y = 0;
959
960
WinMapWindowPoints(pVideo->hidden->hwndClient,
HWND_DESKTOP, &ptl, 1);
961
962
pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */
// Center the mouse to the middle of the window!
963
964
965
WinSetPointerPos(HWND_DESKTOP,
ptl.x + swpClient.cx / 2,
ptl.y + swpClient.cy / 2);
966
} else {
967
CONVERTMOUSEPOSITION();
968
969
// Send absolute mouse position
970
971
972
SDL_PrivateMouseMotion(0, // Buttons not changed
0, // Absolute position
ppts->x, ppts->y);
973
974
975
}
}
if ((pVideo->hidden->iMouseVisible) && (!bMouseCaptured)) {
976
977
978
979
#ifdef DEBUG_BUILD
// printf("WM_MOUSEMOVE : ptr = %p\n", hptrGlobalPointer); fflush(stdout);
#endif
980
if (hptrGlobalPointer)
981
WinSetPointer(HWND_DESKTOP, hptrGlobalPointer);
982
else
983
984
985
WinSetPointer(HWND_DESKTOP,
WinQuerySysPointer(HWND_DESKTOP,
SPTR_ARROW, FALSE));
986
} else {
987
WinSetPointer(HWND_DESKTOP, NULL);
988
}
989
990
991
992
993
}
#ifdef DEBUG_BUILD
// printf("WM_MOUSEMOVE done\n"); fflush(stdout);
#endif
994
995
return (MRESULT) FALSE;
case WM_CLOSE: // Window close
996
#ifdef DEBUG_BUILD
997
998
printf("WM_CLOSE\n");
fflush(stdout);
999
1000
#endif