source: trunk/src/user32/pmwindow.cpp@ 1405

Last change on this file since 1405 was 1405, checked in by sandervl, 26 years ago

Lots of changes/fixes

File size: 25.9 KB
Line 
1/* $Id: pmwindow.cpp,v 1.40 1999-10-22 18:11:47 sandervl Exp $ */
2/*
3 * Win32 Window Managment Code for OS/2
4 *
5 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
6 * Copyright 1999 Daniela Engert (dani@ngrt.de)
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12#define INCL_WIN
13#define INCL_GPI
14
15#include <os2.h> /* PM header file */
16#include <os2wrap.h>
17#include <stdlib.h>
18#include "win32type.h"
19#include <winconst.h>
20#include <wprocess.h>
21#include <misc.h>
22#include <win32wbase.h>
23#include <win32dlg.h>
24#include "win32wdesktop.h"
25#include "pmwindow.h"
26#include "oslibwin.h"
27#include "oslibutil.h"
28#include "oslibgdi.h"
29#include "oslibmsg.h"
30#include "dc.h"
31#include <thread.h>
32#include <wprocess.h>
33#include <caret.h>
34
35HMQ hmq = 0; /* Message queue handle */
36HAB hab = 0;
37
38RECTL desktopRectl = {0};
39ULONG ScreenWidth = 0;
40ULONG ScreenHeight = 0;
41
42//Used for key translation while processing WM_CHAR message
43USHORT virtualKeyTable [66] = {
44 0x00, // OS/2 VK Win32 VK, Entry 0 is not used
45 0x01, // VK_BUTTON1 VK_LBUTTON
46 0x02, // VK_BUTTON2 VK_RBUTTON
47 0x04, // VK_BUTTON3 VK_MBUTTON
48 0x03, // VK_BREAK VK_CANCEL
49 0x08, // VK_BACKSPACE VK_BACK
50 0x09, // VK_TAB VK_TAB
51 0x00, // VK_BACKTAB No equivalent!
52 0x0D, // VK_NEWLINE VK_RETURN
53 0x10, // VK_SHIFT VK_SHIFT
54 0x11, // VK_CTRL VK_CONTROL
55 0x12, // VK_ALT VK_MENU, best match I guess
56 0x12, // VK_ALTGRAF VK_MENU, best match I guess
57 0x13, // VK_PAUSE VK_PAUSE
58 0x14, // VK_CAPSLOCK VK_CAPITAL
59 0x1B, // VK_ESC VK_ESCAPE
60 0x20, // VK_SPACE VK_SPACE
61 0x21, // VK_PAGEUP VK_PRIOR
62 0x22, // VK_PAGEDOWN VK_NEXT
63 0x23, // VK_END VK_END
64 0x24, // VK_HOME VK_HOME
65 0x25, // VK_LEFT VK_LEFT
66 0x26, // VK_UP VK_UP
67 0x27, // VK_RIGHT VK_RIGHT
68 0x28, // VK_DOWN VK_DOWN
69 0x2C, // VK_PRINTSCRN VK_SNAPSHOT
70 0x2D, // VK_INSERT VK_INSERT
71 0x2E, // VK_DELETE VK_DELETE
72 0x91, // VK_SCRLLOCK VK_SCROLL
73 0x90, // VK_NUMLOCK VK_NUMLOCK
74 0x2B, // VK_ENTER VK_EXECUTE, best match I guess
75 0x00, // VK_SYSRQ No equivalent!
76 0x70, // VK_F1 VK_F1
77 0x71, // VK_F2 VK_F2
78 0x72, // VK_F3 VK_F3
79 0x73, // VK_F4 VK_F4
80 0x74, // VK_F5 VK_F5
81 0x75, // VK_F6 VK_F6
82 0x76, // VK_F7 VK_F7
83 0x77, // VK_F8 VK_F8
84 0x78, // VK_F9 VK_F9
85 0x79, // VK_F10 VK_F10
86 0x7A, // VK_F11 VK_F11
87 0x7B, // VK_F12 VK_F12
88 0x7C, // VK_F13 VK_F13
89 0x7D, // VK_F14 VK_F14
90 0x7E, // VK_F15 VK_F15
91 0x7F, // VK_F16 VK_F16
92 0x80, // VK_F17 VK_F17
93 0x81, // VK_F18 VK_F18
94 0x82, // VK_F19 VK_F19
95 0x83, // VK_F20 VK_F20
96 0x84, // VK_F21 VK_F21
97 0x85, // VK_F22 VK_F22
98 0x86, // VK_F23 VK_F23
99 0x87, // VK_F24 VK_F24
100 0x00, // VK_ENDDRAG No equivalent!
101 0x0C, // VK_CLEAR VK_CLEAR
102 0xF9, // VK_EREOF VK_EREOF
103 0xFD, // VK_PA1 VK_PA1
104 0xF6, // VK_ATTN VK_ATTN
105 0xF7, // VK_CRSEL VK_CRSEL
106 0xF8, // VK_EXSEL VK_EXSEL
107 0x00, // VK_COPY No equivalent!
108 0x00, // VK_BLK1 No equivalent!
109 0x00}; // VK_BLK2 No equivalent!
110
111MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
112
113//******************************************************************************
114//Initialize PM; create hab, message queue and register special Win32 window classes
115//******************************************************************************
116BOOL InitPM()
117{
118 hab = WinInitialize(0);
119 dprintf(("Winitialize returned %x", hab));
120 hmq = WinCreateMsgQueue(hab, 0);
121
122 if(!hab || !hmq)
123 {
124 UINT error;
125 //CB: only fail on real error
126 error = WinGetLastError(hab) & 0xFFFF; //error code
127 if (!hab || error != PMERR_MSG_QUEUE_ALREADY_EXISTS)
128 {
129 dprintf(("WinInitialize or WinCreateMsgQueue failed %x %x", hab, hmq));
130 dprintf((" Error = %x",error));
131 return(FALSE);
132 }
133 else
134 {
135 if(!hab) {
136 hab = WinQueryAnchorBlock(HWND_DESKTOP);
137 dprintf(("WinQueryAnchorBlock returned %x", hab));
138 }
139 if(!hmq) {
140 hmq = HMQ_CURRENT;
141 }
142 }
143 }
144 SetThreadHAB(hab);
145 dprintf(("InitPM: hmq = %x", hmq));
146 SetThreadMessageQueue(hmq);
147
148 if(!WinRegisterClass( /* Register window class */
149 hab, /* Anchor block handle */
150 (PSZ)WIN32_STDCLASS, /* Window class name */
151 (PFNWP)Win32WindowProc, /* Address of window procedure */
152// CS_SIZEREDRAW | CS_HITTEST | CS_MOVENOTIFY,
153 CS_SIZEREDRAW | CS_HITTEST,
154 NROF_WIN32WNDBYTES)) {
155 dprintf(("WinRegisterClass Win32BaseWindow failed"));
156 return(FALSE);
157 }
158
159 WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
160 ScreenWidth = desktopRectl.xRight;
161 ScreenHeight = desktopRectl.yTop;
162
163 dprintf(("InitPM: Desktop (%d,%d)", ScreenWidth, ScreenHeight));
164 return OSLibInitMsgQueue();
165} /* End of main */
166//******************************************************************************
167//Win32 window message handler
168//******************************************************************************
169MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
170{
171 POSTMSG_PACKET *postmsg;
172 OSLIBPOINT point, ClientPoint;
173 Win32BaseWindow *win32wnd;
174 APIRET rc;
175
176 //Restore our FS selector
177 SetWin32TIB();
178
179 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
180
181 if(msg != WM_CREATE && win32wnd == NULL) {
182 dprintf(("Invalid win32wnd pointer for window %x!!", hwnd));
183 goto RunDefWndProc;
184 }
185 if(msg > WIN32APP_USERMSGBASE) {
186 //win32 app user message
187 return (MRESULT)win32wnd->SendMessageA((ULONG)msg-WIN32APP_USERMSGBASE, (ULONG)mp1, (ULONG)mp2);
188 }
189 switch( msg )
190 {
191 //OS/2 msgs
192 case WM_CREATE:
193 {
194 THDB *thdb = GetThreadTHDB();
195
196 if(thdb == NULL || thdb->newWindow == 0)
197 goto createfail;
198
199 //Processing is done in after WinCreateWindow returns
200 dprintf(("OS2: WM_CREATE %x", hwnd));
201 win32wnd = (Win32BaseWindow *)thdb->newWindow;
202
203 if(win32wnd->MsgCreate(WinQueryWindow(hwnd, QW_PARENT), hwnd) == FALSE)
204 {
205 RestoreOS2TIB();
206 return (MRESULT)TRUE; //discontinue window creation
207 }
208 createfail:
209 RestoreOS2TIB();
210 return (MRESULT)FALSE;
211 }
212
213 case WM_QUIT:
214 dprintf(("OS2: WM_QUIT %x", hwnd));
215 if(win32wnd->MsgQuit()) {
216 goto RunDefWndProc;
217 }
218 break;
219
220 case WM_CLOSE:
221 dprintf(("OS2: WM_CLOSE %x", hwnd));
222// win32wnd->RemoveFakeOpen32();
223 if(win32wnd->MsgClose()) {
224 goto RunDefWndProc;
225 }
226 break;
227
228 case WM_DESTROY:
229 dprintf(("OS2: WM_DESTROY %x", hwnd));
230 if(win32wnd->MsgDestroy()) {
231 goto RunDefWndProc;
232 }
233 break;
234
235 case WM_ENABLE:
236 dprintf(("OS2: WM_ENABLE %x", hwnd));
237 if(win32wnd->MsgEnable(SHORT1FROMMP(mp1))) {
238 goto RunDefWndProc;
239 }
240 break;
241
242 case WM_SHOW:
243 dprintf(("OS2: WM_SHOW %x %d", hwnd, mp1));
244 if(win32wnd->MsgShow((ULONG)mp1)) {
245 goto RunDefWndProc;
246 }
247 break;
248
249 case WM_SIZE:
250 {
251 dprintf(("OS2: WM_SIZE (%d,%d) (%d,%d)", SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), SHORT1FROMMP(mp1), SHORT2FROMMP(mp2)));
252 break;
253 }
254
255 case WM_OWNERPOSCHANGE:
256 {
257 dprintf(("OS2: WM_OWNERPOSCHANGE"));
258 goto RunDefWndProc;
259 }
260
261 case WM_CALCVALIDRECTS:
262 {
263 dprintf(("OS2: WM_CALCVALIDRECTS"));
264 goto RunDefWndProc;
265 }
266
267 case WM_ACTIVATE:
268 {
269 HWND hwndActivate = (HWND)mp2;
270 BOOL fMinimized = FALSE;
271
272 dprintf(("OS2: WM_ACTIVATE %x %x", hwnd, hwndActivate));
273 if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
274 //another (non-win32) application's window
275 //set to NULL (allowed according to win32 SDK) to avoid problems
276 hwndActivate = NULL;
277 }
278 if(WinQueryWindowULong(hwnd, QWL_STYLE) & WS_MINIMIZED)
279 {
280 fMinimized = TRUE;
281 }
282
283 if(win32wnd->MsgActivate(SHORT1FROMMP(mp1), fMinimized, Win32BaseWindow::OS2ToWin32Handle(hwndActivate))) {
284 goto RunDefWndProc;
285 }
286 break;
287 }
288 case WM_FOCUSCHANGE:
289 dprintf(("OS2: WM_FOCUSCHANGE %x", hwnd));
290 goto RunDefWndProc;
291
292 case WM_SETFOCUS:
293 {
294 HWND hwndFocus = (HWND)mp1;
295
296 dprintf(("OS2: WM_SETFOCUS %x %d", hwnd, mp2));
297 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
298 //another (non-win32) application's window
299 //set to NULL (allowed according to win32 SDK) to avoid problems
300 hwndFocus = NULL;
301 }
302 if((ULONG)mp2 == TRUE) {
303 HWND hwndFocusWin32 = Win32BaseWindow::OS2ToWin32Handle(hwndFocus);
304 recreateCaret (hwndFocusWin32);
305 rc = win32wnd->MsgSetFocus(hwndFocusWin32);
306 }
307 else rc = win32wnd->MsgKillFocus(Win32BaseWindow::OS2ToWin32Handle(hwndFocus));
308 if(rc) {
309 goto RunDefWndProc;
310 }
311 break;
312 }
313 //**************************************************************************
314 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
315 //**************************************************************************
316 case WM_BUTTON1DOWN:
317 dprintf(("OS2: WM_BUTTON1DOWN %x", hwnd));
318 point.x = (*(POINTS *)&mp1).x;
319 point.y = (*(POINTS *)&mp1).y;
320 ClientPoint.x = point.x;
321 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
322 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
323 if(win32wnd->MsgButton(BUTTON_LEFTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
324 goto RunDefWndProc;
325 }
326 break;
327
328 case WM_BUTTON1UP:
329 dprintf(("OS2: WM_BUTTON1UP %x", hwnd));
330 point.x = (*(POINTS *)&mp1).x;
331 point.y = (*(POINTS *)&mp1).y;
332 ClientPoint.x = point.x;
333 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
334 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
335 if(win32wnd->MsgButton(BUTTON_LEFTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
336 goto RunDefWndProc;
337 }
338 break;
339 case WM_BUTTON1DBLCLK:
340 point.x = (*(POINTS *)&mp1).x;
341 point.y = (*(POINTS *)&mp1).y;
342 ClientPoint.x = point.x;
343 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
344 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
345 if(win32wnd->MsgButton(BUTTON_LEFTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
346 goto RunDefWndProc;
347 }
348 break;
349 case WM_BUTTON2DOWN:
350 point.x = (*(POINTS *)&mp1).x;
351 point.y = (*(POINTS *)&mp1).y;
352 ClientPoint.x = point.x;
353 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
354 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
355 if(win32wnd->MsgButton(BUTTON_RIGHTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
356 goto RunDefWndProc;
357 }
358 break;
359 case WM_BUTTON2UP:
360 point.x = (*(POINTS *)&mp1).x;
361 point.y = (*(POINTS *)&mp1).y;
362 ClientPoint.x = point.x;
363 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
364 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
365 if(win32wnd->MsgButton(BUTTON_RIGHTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
366 goto RunDefWndProc;
367 }
368 break;
369 case WM_BUTTON2DBLCLK:
370 point.x = (*(POINTS *)&mp1).x;
371 point.y = (*(POINTS *)&mp1).y;
372 ClientPoint.x = point.x;
373 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
374 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
375 if(win32wnd->MsgButton(BUTTON_RIGHTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
376 goto RunDefWndProc;
377 }
378 break;
379 case WM_BUTTON3DOWN:
380 point.x = (*(POINTS *)&mp1).x;
381 point.y = (*(POINTS *)&mp1).y;
382 ClientPoint.x = point.x;
383 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
384 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
385 if(win32wnd->MsgButton(BUTTON_MIDDLEDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
386 goto RunDefWndProc;
387 }
388 break;
389 case WM_BUTTON3UP:
390 point.x = (*(POINTS *)&mp1).x;
391 point.y = (*(POINTS *)&mp1).y;
392 ClientPoint.x = point.x;
393 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
394 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
395 if(win32wnd->MsgButton(BUTTON_MIDDLEUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
396 goto RunDefWndProc;
397 }
398 break;
399 case WM_BUTTON3DBLCLK:
400 point.x = (*(POINTS *)&mp1).x;
401 point.y = (*(POINTS *)&mp1).y;
402 ClientPoint.x = point.x;
403 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
404 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
405 if(win32wnd->MsgButton(BUTTON_MIDDLEDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
406 goto RunDefWndProc;
407 }
408 break;
409
410 case WM_BUTTON2MOTIONSTART:
411 case WM_BUTTON2MOTIONEND:
412 case WM_BUTTON2CLICK:
413 case WM_BUTTON1MOTIONSTART:
414 case WM_BUTTON1MOTIONEND:
415 case WM_BUTTON1CLICK:
416 case WM_BUTTON3MOTIONSTART:
417 case WM_BUTTON3MOTIONEND:
418 case WM_BUTTON3CLICK:
419 goto RunDefWndProc;
420
421 case WM_MOUSEMOVE:
422 {
423 ULONG keystate = 0;
424 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1))
425 keystate |= WMMOVE_LBUTTON;
426 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2))
427 keystate |= WMMOVE_MBUTTON;
428 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3))
429 keystate |= WMMOVE_RBUTTON;
430 if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT))
431 keystate |= WMMOVE_SHIFT;
432 if(WinGetKeyState(HWND_DESKTOP, VK_CTRL))
433 keystate |= WMMOVE_CTRL;
434
435 //OS/2 Window coordinates -> Win32 Window coordinates
436 if(win32wnd->MsgMouseMove(keystate, SHORT1FROMMP(mp1), MapOS2ToWin32Y(win32wnd, SHORT2FROMMP(mp1))))
437 {
438 //Changes mouse cursor to default
439 goto RunDefWndProc;
440 }
441 break;
442 }
443
444 case WM_CONTROL:
445
446 case WM_COMMAND:
447 if(SHORT1FROMMP(mp2) == CMDSRC_MENU) {
448 win32wnd->MsgCommand(CMD_MENU, SHORT1FROMMP(mp1), 0);
449 }
450 if(SHORT1FROMMP(mp2) == CMDSRC_ACCELERATOR) {
451 win32wnd->MsgCommand(CMD_ACCELERATOR, SHORT1FROMMP(mp1), 0);
452 }
453 //todo controls + accelerators
454 break;
455
456 case WM_SYSCOMMAND:
457 {
458 ULONG x = 0, y = 0;
459 ULONG win32sc;
460
461 if(SHORT2FROMMP(mp2) == TRUE) {//syscommand caused by mouse action
462 POINTL pointl;
463 WinQueryPointerPos(HWND_DESKTOP, &pointl);
464 x = pointl.x;
465 y = ScreenHeight - y;
466 }
467 switch(SHORT1FROMMP(mp1)) {
468 case SC_MOVE:
469 win32sc = SC_MOVE_W;
470 break;
471 case SC_CLOSE:
472 win32sc = SC_CLOSE_W;
473 break;
474 case SC_MAXIMIZE:
475 win32sc = SC_MAXIMIZE_W;
476 break;
477 case SC_MINIMIZE:
478 win32sc = SC_MINIMIZE_W;
479 break;
480 case SC_NEXTFRAME:
481 case SC_NEXTWINDOW:
482 win32sc = SC_NEXTWINDOW_W;
483 break;
484 case SC_RESTORE:
485 win32sc = SC_RESTORE_W;
486 break;
487 case SC_TASKMANAGER:
488 win32sc = SC_TASKLIST_W;
489 break;
490 default:
491 goto RunDefWndProc;
492 }
493 dprintf(("WM_SYSCOMMAND %x %x (%d,%d)", hwnd, win32sc, x, y));
494 if(win32wnd->MsgSysCommand(win32sc, x, y)) {
495 goto RunDefWndProc;
496 }
497 break;
498 }
499 case WM_CHAR:
500 {
501 THDB *thdb;
502 ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
503 ULONG flags = SHORT1FROMMP(mp1);
504 BOOL keyWasPressed, fTranslated = FALSE, fRunDefWndProc = FALSE;
505 char c;
506
507 repeatCount = CHAR3FROMMP(mp1);
508 scanCode = CHAR4FROMMP(mp1);
509 keyWasPressed = ((SHORT1FROMMP (mp1) & KC_PREVDOWN) == KC_PREVDOWN);
510
511 // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
512 // given the OS/2 virtual key and OS/2 character
513
514 if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
515 ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
516 {
517 c = SHORT1FROMMP (mp2);
518 if ((c >= 'A') && (c <= 'Z')) {
519 virtualKey = c;
520 goto VirtualKeyFound;
521 }
522 if ((c >='a') && (c <= 'z')) {
523 virtualKey = c - 32; // make it uppercase
524 goto VirtualKeyFound;
525 }
526 if ((c >= '0') && (c <= '9')) {
527 virtualKey = c;
528 goto VirtualKeyFound;
529 }
530 }
531
532 // convert OS/2 virtual keys to Win32 virtual key
533 if (SHORT2FROMMP (mp2) <= VK_BLK2)
534 virtualKey = virtualKeyTable [SHORT2FROMMP (mp2)];
535
536VirtualKeyFound:
537
538 if(!(SHORT1FROMMP(mp1) & KC_ALT))
539 {
540 //
541 // the Alt key is not pressed
542 //
543 if ((flags & KC_KEYUP) == KC_KEYUP) {
544 // send WM_KEYUP message
545
546 if(win32wnd->MsgKeyUp (repeatCount, scanCode, virtualKey)) {
547 fRunDefWndProc = TRUE;
548 }
549 }
550 else {
551 // send WM_KEYDOWN message
552 if (win32wnd->MsgKeyDown (repeatCount, scanCode, virtualKey, keyWasPressed))
553 fRunDefWndProc = TRUE;
554 }
555 }
556 else {
557 //
558 // the Alt key is pressed
559 //
560 if ((flags & KC_KEYUP) == KC_KEYUP) {
561 // send WM_SYSKEYUP message
562
563 if(win32wnd->MsgSysKeyUp (repeatCount, scanCode, virtualKey)) {
564 fRunDefWndProc = TRUE;
565 }
566 }
567 else {
568 // send WM_SYSKEYDOWN message
569 if (win32wnd->MsgSysKeyDown (repeatCount, scanCode, virtualKey, keyWasPressed))
570 fRunDefWndProc = TRUE;
571 }
572 }
573
574 thdb = GetThreadTHDB();
575 if(thdb) {
576 fTranslated = thdb->fMsgTranslated;
577 thdb->fMsgTranslated = FALSE; //reset flag
578 }
579 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
580 // the newly generated WM_CHAR message.
581 if(fTranslated && !((flags & KC_KEYUP) == KC_KEYUP)) {//TranslatedMessage was called before DispatchMessage, so send WM_CHAR messages
582 ULONG keyflags = 0, vkey = 0;
583 ULONG fl = SHORT1FROMMP(mp1);
584
585 if(!(fl & KC_CHAR)) {
586 goto RunDefWndProc;
587 }
588 if(fl & KC_VIRTUALKEY) {
589 vkey = SHORT2FROMMP(mp2);
590 }
591 if(fl & KC_KEYUP) {
592 keyflags |= KEY_UP;
593 }
594 if(fl & KC_ALT) {
595 keyflags |= KEY_ALTDOWN;
596 }
597 if(fl & KC_PREVDOWN) {
598 keyflags |= KEY_PREVDOWN;
599 }
600 if(fl & KC_DEADKEY) {
601 keyflags |= KEY_DEADKEY;
602 }
603 if(win32wnd->MsgChar(SHORT1FROMMP(mp2), CHAR3FROMMP(mp1), CHAR4FROMMP(mp1), virtualKey, keyflags)) {
604 goto RunDefWndProc;
605 }
606 }
607 if(fRunDefWndProc) goto RunDefWndProc;
608 break;
609 }
610
611 case WM_INITMENU:
612 case WM_MENUSELECT:
613 case WM_MENUEND:
614 case WM_NEXTMENU:
615 goto RunDefWndProc;
616
617 case WM_TIMER:
618 if (mp2) win32wnd->MsgTimer((ULONG)mp1);
619 goto RunDefWndProc;
620
621 case WM_SETWINDOWPARAMS:
622 {
623 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
624
625 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
626 if(wndParams->fsStatus & WPM_TEXT) {
627 if(win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText)) {
628 goto RunDefWndProc;
629 }
630 }
631 goto RunDefWndProc;
632 }
633
634 case WM_QUERYWINDOWPARAMS:
635 {
636 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
637 ULONG textlen;
638 PSZ wintext;
639
640 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
641 {
642 if(wndpars->fsStatus & WPM_CCHTEXT)
643 wndpars->cchText = win32wnd->MsgGetTextLength();
644 if(wndpars->fsStatus & WPM_TEXT)
645 wndpars->pszText = win32wnd->MsgGetText();
646
647 wndpars->fsStatus = 0;
648 wndpars->cbCtlData = 0;
649 wndpars->cbPresParams = 0;
650 RestoreOS2TIB();
651 return (MRESULT)TRUE;
652 }
653 goto RunDefWndProc;
654 }
655
656 case WM_ERASEBACKGROUND:
657 {
658 dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
659 if (WinQueryUpdateRect (hwnd, NULL) && !win32wnd->isSupressErase()) {
660 BOOL erased = sendEraseBkgnd (win32wnd);
661 win32wnd->setEraseBkgnd (!erased, !erased);
662 }
663 break;
664 }
665
666 case WM_PAINT:
667 dprintf(("OS2: WM_PAINT %x", hwnd));
668
669 if (WinQueryUpdateRect (hwnd, NULL)) {
670 if (!win32wnd->isSupressErase()) {
671 BOOL erased = sendEraseBkgnd (win32wnd);
672 win32wnd->setEraseBkgnd (!erased, !erased);
673 }
674 }
675 win32wnd->setSupressErase (FALSE);
676
677 if(win32wnd->MsgPaint(0, 0)) {
678 goto RunDefWndProc;
679 }
680 break;
681
682 case WM_HITTEST:
683 // Only send this message if the window is enabled
684 if (WinIsWindowEnabled(hwnd))
685 {
686 if(win32wnd->MsgHitTest((*(POINTS *)&mp1).x, MapOS2ToWin32Y(OSLIB_HWND_DESKTOP, hwnd, (*(POINTS *)&mp1).y))) {
687 goto RunDefWndProc;
688 }
689 }
690 else goto RunDefWndProc;
691 break;
692
693 case WM_SYSCOLORCHANGE:
694 case WM_SYSVALUECHANGED:
695 case WM_SETSELECTION:
696 case WM_PPAINT:
697 case WM_PSETFOCUS:
698 case WM_PSYSCOLORCHANGE:
699 case WM_PSIZE:
700 case WM_PACTIVATE:
701 case WM_PCONTROL:
702 case WM_HELP:
703 case WM_APPTERMINATENOTIFY:
704 case WM_PRESPARAMCHANGED:
705 case WM_DRAWITEM:
706 case WM_MEASUREITEM:
707 case WM_CONTROLPOINTER:
708 case WM_QUERYDLGCODE:
709 case WM_SUBSTITUTESTRING:
710 case WM_MATCHMNEMONIC:
711 case WM_SAVEAPPLICATION:
712 case WM_SEMANTICEVENT:
713 default:
714// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
715 RestoreOS2TIB();
716 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
717 }
718 RestoreOS2TIB();
719 return (MRESULT)FALSE;
720
721RunDefWndProc:
722// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
723 RestoreOS2TIB();
724 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
725} /* End of Win32WindowProc */
726//******************************************************************************
727//******************************************************************************
728MRESULT EXPENTRY Win32SubclassWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
729{
730 Win32BaseWindow* win32wnd;
731
732 //Restore our FS selector
733 SetWin32TIB();
734
735 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
736
737 if (!win32wnd)
738 {
739 dprintf(("Invalid win32wnd pointer for subclassed window %x!!", hwnd));
740 goto RunDefWndProc;
741 }
742
743 switch (msg)
744 {
745 case WM_WINDOWPOSCHANGED:
746 {
747 PSWP pswp = (PSWP)mp1;
748 SWP swpOld = *(pswp + 1);
749 WINDOWPOS wp;
750 HWND hParent = NULLHANDLE, hFrame = NULLHANDLE;
751
752 dprintf(("OS2Subclass: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
753 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) break;
754
755 hParent = hFrame = WinQueryWindow(hwnd, QW_PARENT);
756
757 OSLibMapSWPtoWINDOWPOS(pswp,&wp, &swpOld,hParent,hFrame);
758
759 win32wnd->setWindowRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
760 win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
761 wp.x = swpOld.x;
762 wp.y = swpOld.y;
763 wp.cx = swpOld.cx;
764 wp.cy = swpOld.cy;
765
766 wp.hwnd = win32wnd->getWindowHandle();
767
768 win32wnd->MsgPosChanged((LPARAM)&wp);
769
770 goto RunOldWndProc;
771 }
772
773 default:
774 goto RunDefHandler;
775 }
776
777RunDefWndProc:
778 RestoreOS2TIB();
779 return WinDefWindowProc(hwnd,msg,mp1,mp2);
780
781RunOldWndProc:
782 RestoreOS2TIB();
783 return ((PFNWP)win32wnd->getOldWndProc())(hwnd,msg,mp1,mp2);
784
785RunDefHandler:
786 RestoreOS2TIB();
787 return Win32WindowProc(hwnd,msg,mp1,mp2);
788}
789
790PVOID SubclassWithDefHandler(HWND hwnd)
791{
792 return WinSubclassWindow(hwnd,Win32SubclassWindowProc);
793}
Note: See TracBrowser for help on using the repository browser.