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

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

MDI fix, extra message support etc

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