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

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

SetWindowPos bugfix

File size: 29.1 KB
Line 
1/* $Id: pmwindow.cpp,v 1.21 1999-10-07 23:21:30 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 dprintf(("PMWINDOW: Message %x (%x,%x) posted to window %x", (ULONG)msg-WIN32APP_USERMSGBASE, mp1, mp2, hwnd));
187 win32wnd->SendMessageA((ULONG)msg-WIN32APP_USERMSGBASE, (ULONG)mp1, (ULONG)mp2);
188 }
189 switch( msg )
190 {
191 //OS/2 msgs
192 case WM_CREATE:
193 //Processing is done in after WinCreateWindow returns
194 dprintf(("OS2: WM_CREATE %x", hwnd));
195 RestoreOS2TIB();
196 return (MRESULT)FALSE;
197
198 case WM_QUIT:
199 dprintf(("OS2: WM_QUIT %x", hwnd));
200 if(win32wnd->MsgQuit()) {
201 goto RunDefWndProc;
202 }
203 break;
204
205 case WM_CLOSE:
206 dprintf(("OS2: WM_CLOSE %x", hwnd));
207// win32wnd->RemoveFakeOpen32();
208 if(win32wnd->MsgClose()) {
209 goto RunDefWndProc;
210 }
211 break;
212
213 case WM_DESTROY:
214 dprintf(("OS2: WM_DESTROY %x", hwnd));
215 if(win32wnd->MsgDestroy()) {
216 goto RunDefWndProc;
217 }
218 break;
219
220 case WM_ENABLE:
221 dprintf(("OS2: WM_ENABLE %x", hwnd));
222 if(win32wnd->MsgEnable((ULONG)mp1)) {
223 goto RunDefWndProc;
224 }
225 break;
226
227 case WM_SHOW:
228 dprintf(("OS2: WM_SHOW %x", hwnd));
229 if(win32wnd->MsgShow((ULONG)mp1)) {
230 goto RunDefWndProc;
231 }
232 break;
233
234 case WM_ADJUSTWINDOWPOS:
235 {
236 PSWP pswp = (PSWP)mp1;
237 SWP swpOld;
238 WINDOWPOS wp;
239 ULONG parentHeight = 0;
240 HWND hParent = NULLHANDLE, hFrame = NULLHANDLE;
241
242 dprintf(("OS2: WM_ADJUSTWINDOWPOS %x %x (%d,%d) (%d,%d)", hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
243
244 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) break;
245
246 WinQueryWindowPos(hwnd, &swpOld);
247
248 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
249 if (win32wnd->isChild())
250 hParent = win32wnd->getParent()->getOS2WindowHandle();
251 else
252 hFrame = win32wnd->getOS2FrameWindowHandle();
253 }
254 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, hParent, hFrame);
255
256 wp.hwnd = win32wnd->getWindowHandle();
257 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
258 {
259 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
260 if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
261 }
262 win32wnd->MsgPosChanging((LPARAM)&wp);
263 break;
264 }
265
266 case WM_WINDOWPOSCHANGED:
267 {
268 PSWP pswp = (PSWP)mp1;
269 PSWP pswpo = pswp + 1;
270 WINDOWPOS wp;
271 ULONG parentHeight = 0;
272 HWND hParent = NULLHANDLE, hFrame = NULLHANDLE;
273 LONG yDelta = pswp->cy - pswpo->cy;
274 LONG xDelta = pswp->cx - pswpo->cx;
275 ULONG classStyle;
276
277 dprintf(("OS2: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
278
279 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) break;
280
281 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
282 if (win32wnd->isChild())
283 hParent = win32wnd->getParent()->getOS2WindowHandle();
284 else
285 hFrame = win32wnd->getOS2FrameWindowHandle();
286 }
287 OSLibMapSWPtoWINDOWPOS(pswp, &wp, pswpo, hParent, hFrame);
288
289 win32wnd->setWindowRect(wp.x, wp.y, wp.x + wp.cx, wp.y + wp.cy);
290 win32wnd->setClientRect(pswpo->x, pswpo->y, pswpo->x + pswpo->cx, pswpo->y + pswpo->cy);
291
292 wp.hwnd = win32wnd->getWindowHandle();
293 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
294 {
295 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
296 wp.hwndInsertAfter = wndAfter->getWindowHandle();
297 }
298 classStyle = win32wnd->getClass()->getStyle();
299
300 if (yDelta != 0 || xDelta != 0)
301 {
302 HENUM henum = WinBeginEnumWindows(pswp->hwnd);
303 SWP swp[10];
304 int i = 0;
305 HWND hwnd;
306
307 while ((hwnd = WinGetNextWindow(henum)) != NULLHANDLE)
308 {
309#if 0
310 if (mdiClient )
311 {
312 continue;
313 }
314#endif
315 WinQueryWindowPos(hwnd, &(swp[i]));
316
317#ifdef DEBUG
318 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
319 dprintf(("ENUMERATE %x delta %d (%d,%d) (%d,%d)", (window) ? window->getWindowHandle() : hwnd,
320 yDelta, swp[i].x, swp[i].y, swp[i].cx, swp[i].cy));
321#endif
322
323 swp[i].cy += yDelta;
324 swp[i].fl = SWP_SIZE;
325
326 if (i == 9)
327 {
328 WinSetMultWindowPos(GetThreadHAB(), swp, 10);
329 i = 0;
330 }
331 else
332 {
333 i++;
334 }
335 }
336
337 WinEndEnumWindows(henum);
338
339 if (i)
340 WinSetMultWindowPos(GetThreadHAB(), swp, i);
341 }
342 if (yDelta != 0)
343 {
344 POINT pt;
345 if(GetCaretPos (&pt) == TRUE)
346 {
347 pt.y -= yDelta;
348 SetCaretPos (pt.x, pt.y);
349 }
350 }
351 win32wnd->MsgPosChanged((LPARAM)&wp);
352
353 goto RunDefWndProc;
354// break;
355 }
356
357 case WM_ERASEBACKGROUND:
358 {
359 if (!win32wnd->isSupressErase()) {
360 BOOL erased = sendEraseBkgnd (win32wnd);
361 win32wnd->setEraseBkgnd (!erased, !erased);
362 }
363 break;
364 }
365
366 case WM_MOVE:
367 {
368 if (!win32wnd->isFrameWindow()) break;
369
370 HWND hFrame = win32wnd->getOS2FrameWindowHandle();
371 SWP swp, swpo;
372 WINDOWPOS wp;
373 ULONG parentHeight = 0;
374 RECTL rcl;
375
376 WinQueryWindowRect (hwnd, &rcl);
377 WinMapWindowPoints (hwnd, hFrame, (PPOINTL)&rcl, 2);
378 swp.x = swpo.x = rcl.xLeft;
379 swp.y = swpo.y = rcl.yBottom;
380 swp.cx = swpo.cx = rcl.xRight - rcl.xLeft;
381 swp.cy = swpo.cy = rcl.yTop - rcl.yBottom;
382 swp.fl = SWP_MOVE | SWP_NOREDRAW;
383 swp.hwnd = hwnd;
384 swp.hwndInsertBehind = NULLHANDLE;
385 dprintf(("OS2: WM_MOVE %x %x (%d,%d) (%d,%d)", hwnd, swp.fl, swp.x, swp.y, swp.cx, swp.cy));
386
387 OSLibMapSWPtoWINDOWPOS(&swp, &wp, &swpo, NULLHANDLE, hFrame);
388
389 wp.flags &= ~SWP_NOMOVE_W;
390 wp.hwnd = win32wnd->getWindowHandle();
391 win32wnd->setWindowRect(wp.x, wp.y, wp.x + wp.cx, wp.y + wp.cy);
392 win32wnd->setClientRect(swpo.x, swpo.y, swpo.x + swpo.cx, swpo.y + swpo.cy);
393 win32wnd->MsgPosChanged((LPARAM)&wp);
394 break;
395 }
396
397 case WM_SIZE:
398 {
399 break;
400 }
401
402 case WM_ACTIVATE:
403 {
404 HWND hwndActivate = (HWND)mp2;
405 BOOL fMinimized = FALSE;
406
407 dprintf(("OS2: WM_ACTIVATE %x %x", hwnd, hwndActivate));
408 if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
409 //another (non-win32) application's window
410 //set to NULL (allowed according to win32 SDK) to avoid problems
411 hwndActivate = NULL;
412 }
413 if(WinQueryWindowULong(hwnd, QWL_STYLE) & WS_MINIMIZED)
414 {
415 fMinimized = TRUE;
416 }
417
418 if(win32wnd->MsgActivate(SHORT1FROMMP(mp1), fMinimized, Win32BaseWindow::OS2ToWin32Handle(hwndActivate))) {
419 goto RunDefWndProc;
420 }
421 break;
422 }
423 case WM_FOCUSCHANGE:
424 dprintf(("OS2: WM_FOCUSCHANGE %x", hwnd));
425 goto RunDefWndProc;
426
427 case WM_SETFOCUS:
428 {
429 HWND hwndFocus = (HWND)mp1;
430
431 dprintf(("OS2: WM_SETFOCUS %x %d", hwnd, mp2));
432 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
433 //another (non-win32) application's window
434 //set to NULL (allowed according to win32 SDK) to avoid problems
435 hwndFocus = NULL;
436 }
437 if((ULONG)mp2 == TRUE) {
438 HWND hwndFocusWin32 = Win32BaseWindow::OS2ToWin32Handle(hwndFocus);
439 recreateCaret (hwndFocusWin32);
440 rc = win32wnd->MsgSetFocus(hwndFocusWin32);
441 }
442 else rc = win32wnd->MsgKillFocus(Win32BaseWindow::OS2ToWin32Handle(hwndFocus));
443 if(rc) {
444 goto RunDefWndProc;
445 }
446 break;
447 }
448 //**************************************************************************
449 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
450 //**************************************************************************
451 case WM_BUTTON1DOWN:
452 dprintf(("OS2: WM_BUTTON1DOWN %x", hwnd));
453 point.x = (*(POINTS *)&mp1).x;
454 point.y = (*(POINTS *)&mp1).y;
455 ClientPoint.x = point.x;
456 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
457 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
458 if(win32wnd->MsgButton(BUTTON_LEFTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
459 goto RunDefWndProc;
460 }
461 break;
462
463 case WM_BUTTON1UP:
464 dprintf(("OS2: WM_BUTTON1UP %x", hwnd));
465 point.x = (*(POINTS *)&mp1).x;
466 point.y = (*(POINTS *)&mp1).y;
467 ClientPoint.x = point.x;
468 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
469 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
470 if(win32wnd->MsgButton(BUTTON_LEFTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
471 goto RunDefWndProc;
472 }
473 break;
474 case WM_BUTTON1DBLCLK:
475 point.x = (*(POINTS *)&mp1).x;
476 point.y = (*(POINTS *)&mp1).y;
477 ClientPoint.x = point.x;
478 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
479 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
480 if(win32wnd->MsgButton(BUTTON_LEFTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
481 goto RunDefWndProc;
482 }
483 break;
484 case WM_BUTTON2DOWN:
485 point.x = (*(POINTS *)&mp1).x;
486 point.y = (*(POINTS *)&mp1).y;
487 ClientPoint.x = point.x;
488 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
489 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
490 if(win32wnd->MsgButton(BUTTON_RIGHTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
491 goto RunDefWndProc;
492 }
493 break;
494 case WM_BUTTON2UP:
495 point.x = (*(POINTS *)&mp1).x;
496 point.y = (*(POINTS *)&mp1).y;
497 ClientPoint.x = point.x;
498 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
499 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
500 if(win32wnd->MsgButton(BUTTON_RIGHTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
501 goto RunDefWndProc;
502 }
503 break;
504 case WM_BUTTON2DBLCLK:
505 point.x = (*(POINTS *)&mp1).x;
506 point.y = (*(POINTS *)&mp1).y;
507 ClientPoint.x = point.x;
508 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
509 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
510 if(win32wnd->MsgButton(BUTTON_RIGHTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
511 goto RunDefWndProc;
512 }
513 break;
514 case WM_BUTTON3DOWN:
515 point.x = (*(POINTS *)&mp1).x;
516 point.y = (*(POINTS *)&mp1).y;
517 ClientPoint.x = point.x;
518 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
519 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
520 if(win32wnd->MsgButton(BUTTON_MIDDLEDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
521 goto RunDefWndProc;
522 }
523 break;
524 case WM_BUTTON3UP:
525 point.x = (*(POINTS *)&mp1).x;
526 point.y = (*(POINTS *)&mp1).y;
527 ClientPoint.x = point.x;
528 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
529 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
530 if(win32wnd->MsgButton(BUTTON_MIDDLEUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
531 goto RunDefWndProc;
532 }
533 break;
534 case WM_BUTTON3DBLCLK:
535 point.x = (*(POINTS *)&mp1).x;
536 point.y = (*(POINTS *)&mp1).y;
537 ClientPoint.x = point.x;
538 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
539 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
540 if(win32wnd->MsgButton(BUTTON_MIDDLEDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
541 goto RunDefWndProc;
542 }
543 break;
544
545 case WM_BUTTON2MOTIONSTART:
546 case WM_BUTTON2MOTIONEND:
547 case WM_BUTTON2CLICK:
548 case WM_BUTTON1MOTIONSTART:
549 case WM_BUTTON1MOTIONEND:
550 case WM_BUTTON1CLICK:
551 case WM_BUTTON3MOTIONSTART:
552 case WM_BUTTON3MOTIONEND:
553 case WM_BUTTON3CLICK:
554 goto RunDefWndProc;
555
556 case WM_MOUSEMOVE:
557 {
558 ULONG keystate = 0;
559 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1))
560 keystate |= WMMOVE_LBUTTON;
561 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2))
562 keystate |= WMMOVE_MBUTTON;
563 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3))
564 keystate |= WMMOVE_RBUTTON;
565 if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT))
566 keystate |= WMMOVE_SHIFT;
567 if(WinGetKeyState(HWND_DESKTOP, VK_CTRL))
568 keystate |= WMMOVE_CTRL;
569
570 //OS/2 Window coordinates -> Win32 Window coordinates
571 //NOTE: Do not call the default OS/2 window handler as that one changes
572 // the mousepointer!
573 win32wnd->MsgMouseMove(keystate, SHORT1FROMMP(mp1), MapOS2ToWin32Y(win32wnd, SHORT2FROMMP(mp1)));
574 break;
575 }
576
577 //**************************************************************************
578 //Slider messages
579 //**************************************************************************
580 case WM_VSCROLL:
581 case WM_HSCROLL:
582 {
583 ULONG scrollPos, scrollCode, scrollMsg;
584
585 scrollCode = SHORT2FROMMP(mp2);
586 scrollPos = SHORT1FROMMP(mp2);
587 scrollMsg = msg;
588
589 OSLibTranslateScrollCmdAndMsg(&scrollMsg, &scrollCode);
590
591 if(win32wnd->MsgScroll(scrollMsg, scrollCode, scrollPos)) {
592 goto RunDefWndProc;
593 }
594 break;
595 }
596
597 case WM_CONTROL:
598
599 case WM_COMMAND:
600 if(SHORT1FROMMP(mp2) == CMDSRC_MENU) {
601 win32wnd->MsgCommand(CMD_MENU, SHORT1FROMMP(mp1), 0);
602 }
603 if(SHORT1FROMMP(mp2) == CMDSRC_ACCELERATOR) {
604 win32wnd->MsgCommand(CMD_ACCELERATOR, SHORT1FROMMP(mp1), 0);
605 }
606 //todo controls + accelerators
607 break;
608
609 case WM_SYSCOMMAND:
610 {
611 ULONG x = 0, y = 0;
612 ULONG win32sc;
613
614 if(SHORT2FROMMP(mp2) == TRUE) {//syscommand caused by mouse action
615 POINTL pointl;
616 WinQueryPointerPos(HWND_DESKTOP, &pointl);
617 x = pointl.x;
618 y = ScreenHeight - y;
619 }
620 switch(SHORT1FROMMP(mp1)) {
621 case SC_MOVE:
622 win32sc = SC_MOVE_W;
623 break;
624 case SC_CLOSE:
625 win32sc = SC_CLOSE_W;
626 break;
627 case SC_MAXIMIZE:
628 win32sc = SC_MAXIMIZE_W;
629 break;
630 case SC_MINIMIZE:
631 win32sc = SC_MINIMIZE_W;
632 break;
633 case SC_NEXTFRAME:
634 case SC_NEXTWINDOW:
635 win32sc = SC_NEXTWINDOW_W;
636 break;
637 case SC_RESTORE:
638 win32sc = SC_RESTORE_W;
639 break;
640 case SC_TASKMANAGER:
641 win32sc = SC_TASKLIST_W;
642 break;
643 default:
644 goto RunDefWndProc;
645 }
646 dprintf(("WM_SYSCOMMAND %x %x (%d,%d)", hwnd, win32sc, x, y));
647 if(win32wnd->MsgSysCommand(win32sc, x, y)) {
648 goto RunDefWndProc;
649 }
650 break;
651 }
652 case WM_CHAR:
653 {
654 THDB *thdb;
655 ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
656 ULONG flags = SHORT1FROMMP(mp1);
657 BOOL keyWasPressed, fTranslated = FALSE, fRunDefWndProc = FALSE;
658 char c;
659
660 repeatCount = CHAR3FROMMP(mp1);
661 scanCode = CHAR4FROMMP(mp1);
662 keyWasPressed = ((SHORT1FROMMP (mp1) & KC_PREVDOWN) == KC_PREVDOWN);
663
664 // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
665 // given the OS/2 virtual key and OS/2 character
666
667 if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
668 ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
669 {
670 c = SHORT1FROMMP (mp2);
671 if ((c >= 'A') && (c <= 'Z')) {
672 virtualKey = c;
673 goto VirtualKeyFound;
674 }
675 if ((c >='a') && (c <= 'z')) {
676 virtualKey = c - 32; // make it uppercase
677 goto VirtualKeyFound;
678 }
679 if ((c >= '0') && (c <= '9')) {
680 virtualKey = c;
681 goto VirtualKeyFound;
682 }
683 }
684
685 // convert OS/2 virtual keys to Win32 virtual key
686 if (SHORT2FROMMP (mp2) <= VK_BLK2)
687 virtualKey = virtualKeyTable [SHORT2FROMMP (mp2)];
688
689VirtualKeyFound:
690
691 if(!(SHORT1FROMMP(mp1) & KC_ALT))
692 {
693 //
694 // the Alt key is not pressed
695 //
696 if ((flags & KC_KEYUP) == KC_KEYUP) {
697 // send WM_KEYUP message
698
699 if(win32wnd->MsgKeyUp (repeatCount, scanCode, virtualKey)) {
700 fRunDefWndProc = TRUE;
701 }
702 }
703 else {
704 // send WM_KEYDOWN message
705 if (win32wnd->MsgKeyDown (repeatCount, scanCode, virtualKey, keyWasPressed))
706 fRunDefWndProc = TRUE;
707 }
708 }
709 else {
710 //
711 // the Alt key is pressed
712 //
713 if ((flags & KC_KEYUP) == KC_KEYUP) {
714 // send WM_SYSKEYUP message
715
716 if(win32wnd->MsgSysKeyUp (repeatCount, scanCode, virtualKey)) {
717 fRunDefWndProc = TRUE;
718 }
719 }
720 else {
721 // send WM_SYSKEYDOWN message
722 if (win32wnd->MsgSysKeyDown (repeatCount, scanCode, virtualKey, keyWasPressed))
723 fRunDefWndProc = TRUE;
724 }
725 }
726
727 thdb = GetThreadTHDB();
728 if(thdb) {
729 fTranslated = thdb->fMsgTranslated;
730 thdb->fMsgTranslated = FALSE; //reset flag
731 }
732 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
733 // the newly generated WM_CHAR message.
734 if(fTranslated && !((flags & KC_KEYUP) == KC_KEYUP)) {//TranslatedMessage was called before DispatchMessage, so send WM_CHAR messages
735 ULONG keyflags = 0, vkey = 0;
736 ULONG fl = SHORT1FROMMP(mp1);
737
738 if(!(fl & KC_CHAR)) {
739 goto RunDefWndProc;
740 }
741 if(fl & KC_VIRTUALKEY) {
742 vkey = SHORT2FROMMP(mp2);
743 }
744 if(fl & KC_KEYUP) {
745 keyflags |= KEY_UP;
746 }
747 if(fl & KC_ALT) {
748 keyflags |= KEY_ALTDOWN;
749 }
750 if(fl & KC_PREVDOWN) {
751 keyflags |= KEY_PREVDOWN;
752 }
753 if(fl & KC_DEADKEY) {
754 keyflags |= KEY_DEADKEY;
755 }
756 if(win32wnd->MsgChar(SHORT1FROMMP(mp2), CHAR3FROMMP(mp1), CHAR4FROMMP(mp1), virtualKey, keyflags)) {
757 goto RunDefWndProc;
758 }
759 }
760 if(fRunDefWndProc) goto RunDefWndProc;
761 break;
762 }
763
764 case WM_INITMENU:
765 case WM_MENUSELECT:
766 case WM_MENUEND:
767 case WM_NEXTMENU:
768 goto RunDefWndProc;
769
770 case WM_TIMER:
771 if (mp2) win32wnd->MsgTimer((ULONG)mp1);
772 goto RunDefWndProc;
773
774 case WM_SETWINDOWPARAMS:
775 {
776 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
777
778 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
779 if(wndParams->fsStatus & WPM_TEXT) {
780 if(win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText)) {
781 goto RunDefWndProc;
782 }
783 }
784 goto RunDefWndProc;
785 }
786
787 case WM_QUERYWINDOWPARAMS:
788 {
789 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
790 ULONG textlen;
791 PSZ wintext;
792
793 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
794 {
795 if(wndpars->fsStatus & WPM_CCHTEXT)
796 wndpars->cchText = win32wnd->MsgGetTextLength();
797 if(wndpars->fsStatus & WPM_TEXT)
798 wndpars->pszText = win32wnd->MsgGetText();
799
800 wndpars->fsStatus = 0;
801 wndpars->cbCtlData = 0;
802 wndpars->cbPresParams = 0;
803 RestoreOS2TIB();
804 return (MRESULT)TRUE;
805 }
806 goto RunDefWndProc;
807 }
808
809 case WM_PAINT:
810 dprintf(("OS2: WM_PAINT %x", hwnd));
811
812 if (WinQueryUpdateRect (hwnd, NULL)) {
813 if (!win32wnd->isSupressErase()) {
814 BOOL erased = sendEraseBkgnd (win32wnd);
815 win32wnd->setEraseBkgnd (!erased, !erased);
816 }
817 }
818 win32wnd->setSupressErase (FALSE);
819
820 if(win32wnd->MsgPaint(0, 0)) {
821 goto RunDefWndProc;
822 }
823 break;
824
825 case WM_HITTEST:
826 // Only send this message if the window is enabled
827 if (WinIsWindowEnabled(hwnd))
828 {
829 if(win32wnd->MsgHitTest((*(POINTS *)&mp1).x, MapOS2ToWin32Y(OSLIB_HWND_DESKTOP, hwnd, (*(POINTS *)&mp1).y))) {
830 goto RunDefWndProc;
831 }
832 }
833 else goto RunDefWndProc;
834 break;
835
836 case WM_SYSCOLORCHANGE:
837 case WM_SYSVALUECHANGED:
838 case WM_CALCVALIDRECTS:
839 case WM_SETSELECTION:
840 case WM_PPAINT:
841 case WM_PSETFOCUS:
842 case WM_PSYSCOLORCHANGE:
843 case WM_PSIZE:
844 case WM_PACTIVATE:
845 case WM_PCONTROL:
846 case WM_HELP:
847 case WM_APPTERMINATENOTIFY:
848 case WM_PRESPARAMCHANGED:
849 case WM_DRAWITEM:
850 case WM_MEASUREITEM:
851 case WM_CONTROLPOINTER:
852 case WM_QUERYDLGCODE:
853 case WM_SUBSTITUTESTRING:
854 case WM_MATCHMNEMONIC:
855 case WM_SAVEAPPLICATION:
856 case WM_SEMANTICEVENT:
857 default:
858// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
859 RestoreOS2TIB();
860 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
861 }
862 RestoreOS2TIB();
863 return (MRESULT)FALSE;
864
865RunDefWndProc:
866// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
867 RestoreOS2TIB();
868 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
869} /* End of Win32WindowProc */
870//******************************************************************************
871//******************************************************************************
Note: See TracBrowser for help on using the repository browser.