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

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

WM_CHAR bugfix

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