Skip to content

Latest commit

 

History

History
2782 lines (2456 loc) · 85.6 KB

SDL_os2fslib.c

File metadata and controls

2782 lines (2456 loc) · 85.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
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
123
124
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
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
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
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
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
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
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
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
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
/*
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
*/
#include <process.h>
#include <time.h>
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "SDL_sysvideo.h"
#include "SDL_pixels_c.h"
#include "SDL_events_c.h"
#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,
LONG x, LONG y,
LONG cx, LONG cy,
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);
}
/////////////////////////////////////////////////////////////////////
//
// 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)
{
// TODO:
// Implement real unicode conversion!
if (chcode)
keysym->unicode = chcode;
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:
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;
}
}
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, */ \
/* 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) */ \
/* So, limit mouse pos to source buffer size! */ \
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; \
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); \
WinSetPointerPos(HWND_DESKTOP, ptl.x, ptl.y); \
/* Then convert OS/2 position to SDL position */ \
ppts->y = pVideo->hidden->SrcBufferDesc.uiYResolution - ppts->y - 1; \
} else \
{ \
SWP swpClient; \
/* We're in windowed mode! */ \
WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient); \
/* Convert OS/2 mouse position to SDL position, and also scale it! */ \
(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; \
}
/////////////////////////////////////////////////////////////////////
//
// 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!
if (SHORT1FROMMP(mp1) & KC_KEYUP)
{
// A key has been released
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.
// 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));
}*/
SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(SHORT2FROMMP(mp2), // VK_ code
SHORT1FROMMP(mp2), // Character code
CHAR4FROMMP(mp1), // HW Scan code
&keysym,0));
} else
{
// 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
// Check for fastkeys: ALT+HOME to toggle FS mode
// ALT+END to close app
if ((SHORT1FROMMP(mp1) & KC_ALT) &&
(SHORT2FROMMP(mp2) == VK_HOME))
{
#ifdef DEBUG_BUILD
printf(" Pressed ALT+HOME!\n"); fflush(stdout);
#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)
)
)
FSLib_ToggleFSMode(hwnd, !FSLib_QueryFSMode(hwnd));
#ifdef DEBUG_BUILD
else
printf(" Resizable mode, so discarding ALT+HOME!\n"); fflush(stdout);
#endif
} else
if ((SHORT1FROMMP(mp1) & KC_ALT) &&
(SHORT2FROMMP(mp2) == VK_END))
{
#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);
} else
{
SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(SHORT2FROMMP(mp2), // VK_ code
SHORT1FROMMP(mp2), // Character code
CHAR4FROMMP(mp1), // HW Scan code
&keysym,1));
}
}
}
return (MRESULT) TRUE;
case WM_TRANSLATEACCEL:
{
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)
}
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
{
printf("WM_PAINT : No pVideo!\n"); fflush(stdout);
}
#endif
WinEndPaint(ps);
#ifdef DEBUG_BUILD
printf("WM_PAINT : Done.\n");
fflush(stdout);
#endif
return 0;
case WM_SIZE:
{
#ifdef DEBUG_BUILD
printf("WM_SIZE : (%d %d)\n",
SHORT1FROMMP(mp2), SHORT2FROMMP(mp2)); fflush(stdout);
#endif
iWindowSizeX = SHORT1FROMMP(mp2);
iWindowSizeY = SHORT2FROMMP(mp2);
bWindowResized = 1;
// Make sure the window will be redrawn
WinInvalidateRegion(hwnd, NULL, TRUE);
}
break;
case WM_FSLIBNOTIFICATION:
#ifdef DEBUG_BUILD
printf("WM_FSLIBNOTIFICATION\n"); fflush(stdout);
#endif
if ((int)mp1 == FSLN_TOGGLEFSMODE)
{
// FS mode changed, reblit image!
pVideo = FSLib_GetUserParm(hwnd);
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"); 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);
}
}
}
}
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
WinSetPointer(HWND_DESKTOP, NULL);
if (bMouseCapturable)
{
// Re-capture the mouse, if we captured it before!
WinSetCapture(HWND_DESKTOP, hwnd);
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);
}
}
} else
{
// Went out of focus
WinSetPointer(HWND_DESKTOP, WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE));
if (bMouseCaptured)
{
// Release the mouse
WinSetCapture(HWND_DESKTOP, hwnd);
bMouseCaptured = 0;
}
}
}
#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)
{
SDL_PrivateMouseButton(SDL_PRESSED,
SDL_BUTTON_LEFT,
0, 0); // Don't report mouse movement!
if (bMouseCapturable)
{
// We should capture the mouse!
if (!bMouseCaptured)
{
WinSetCapture(HWND_DESKTOP, hwnd);
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);
}
}
}
}
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)
{
SDL_PrivateMouseButton(SDL_PRESSED,
SDL_BUTTON_RIGHT,
0, 0); // Don't report mouse movement!
if (bMouseCapturable)
{
// We should capture the mouse!
if (!bMouseCaptured)
{
WinSetCapture(HWND_DESKTOP, hwnd);
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);
}
}
}
}
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!
if (bMouseCapturable)
{
// We should capture the mouse!
if (!bMouseCaptured)
{
WinSetCapture(HWND_DESKTOP, hwnd);
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);
}
}
}
}
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;
CONVERTMOUSEPOSITION();
if (bMouseCaptured)
{
SWP swpClient;
// 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
ppts->x - (pVideo->hidden->SrcBufferDesc.uiXResolution/2),
ppts->y+1 - (pVideo->hidden->SrcBufferDesc.uiYResolution/2));
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! */
// Center the mouse to the middle of the window!
WinSetPointerPos(HWND_DESKTOP,
ptl.x + swpClient.cx/2,
ptl.y + swpClient.cy/2);
} else
{
// 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) ||
(
(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_UPDATERECTSREQUEST] : Skipping blit while resizing!\n"); fflush(stdout);
#endif
} else
#endif
{
#ifdef DEBUG_BUILD
printf("[WM_UPDATERECTSREQUEST] : Blitting!\n"); fflush(stdout);
#endif
// Blit the changed areas
for (i=0; i<numrects; i++)
FSLIB_BITBLT(hwnd, pVideo->hidden->pchSrcBuffer,
rects[i].y, rects[i].x, rects[i].w, rects[i].h);
}
DosReleaseMutexSem(pVideo->hidden->hmtxUseSrcBuffer);
}
}
return 0;
#endif
default:
#ifdef DEBUG_BUILD
printf("Unhandled: %x\n", msg); fflush(stdout);
#endif
break;
}
// Run the default window procedure for unhandled stuffs
return WinDefWindowProc(hwnd, msg, mp1, mp2);
}
/////////////////////////////////////////////////////////////////////
//
// PMThreadFunc
//
// This function implements the PM-Thread, which initializes the
// application window itself, the DIVE, and start message processing.
//
/////////////////////////////////////////////////////////////////////
int iNumOfPMThreadInstances = 0; // Global!
static void PMThreadFunc(void *pParm)
{
SDL_VideoDevice *pVideo = pParm;
HAB hab;
HMQ hmq;
QMSG msg;