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

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

Scrollbar changes

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