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

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

Winhlp32 resize bugfix

File size: 29.1 KB
Line 
1/* $Id: pmwindow.cpp,v 1.20 1999-10-07 19:38:27 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 NROF_WIN32WNDBYTES)) {
153 dprintf(("WinRegisterClass Win32BaseWindow failed"));
154 return(FALSE);
155 }
156
157 WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
158 ScreenWidth = desktopRectl.xRight;
159 ScreenHeight = desktopRectl.yTop;
160
161 dprintf(("InitPM: Desktop (%d,%d)", ScreenWidth, ScreenHeight));
162 return OSLibInitMsgQueue();
163} /* End of main */
164//******************************************************************************
165//Win32 window message handler
166//******************************************************************************
167MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
168{
169 POSTMSG_PACKET *postmsg;
170 OSLIBPOINT point, ClientPoint;
171 Win32BaseWindow *win32wnd;
172 APIRET rc;
173
174 //Restore our FS selector
175 SetWin32TIB();
176
177 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
178
179 if(msg != WM_CREATE && win32wnd == NULL) {
180 dprintf(("Invalid win32wnd pointer for window %x!!", hwnd));
181 goto RunDefWndProc;
182 }
183 if(msg > WIN32APP_USERMSGBASE) {
184 //win32 app user message
185 dprintf(("PMWINDOW: Message %x (%x,%x) posted to window %x", (ULONG)msg-WIN32APP_USERMSGBASE, mp1, mp2, hwnd));
186 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((ULONG)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 swp[i].cy += yDelta;
323 swp[i].fl = SWP_SIZE;
324
325 if (i == 9)
326 {
327 WinSetMultWindowPos(GetThreadHAB(), swp, 10);
328 i = 0;
329 }
330 else
331 {
332 i++;
333 }
334 }
335
336 WinEndEnumWindows(henum);
337
338 if (i)
339 WinSetMultWindowPos(GetThreadHAB(), swp, i);
340 }
341 if (yDelta != 0)
342 {
343 POINT pt;
344#if 1
345 if(GetCaretPos (&pt) == TRUE)
346 {
347 pt.y -= yDelta;
348 SetCaretPos (pt.x, pt.y);
349 }
350#else
351 GetCaretPos (&pt);
352 pt.y -= yDelta;
353 SetCaretPos (pt.x, pt.y);
354#endif
355 }
356 win32wnd->MsgPosChanged((LPARAM)&wp);
357
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
390 OSLibMapSWPtoWINDOWPOS(&swp, &wp, &swpo, NULLHANDLE, hFrame);
391
392 dprintf(("OS2: WM_MOVE %x %x (%d,%d) (%d,%d)", hwnd, swp.fl, swp.x, swp.y, swp.cx, swp.cy));
393
394 wp.flags &= ~SWP_NOMOVE_W;
395 wp.hwnd = win32wnd->getWindowHandle();
396 win32wnd->setWindowRect(wp.x, wp.y, wp.x + wp.cx, wp.y + wp.cy);
397 win32wnd->setClientRect(swpo.x, swpo.y, swpo.x + swpo.cx, swpo.y + swpo.cy);
398 win32wnd->MsgPosChanged((LPARAM)&wp);
399 break;
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 //NOTE: Do not call the default OS/2 window handler as that one changes
576 // the mousepointer!
577 win32wnd->MsgMouseMove(keystate, SHORT1FROMMP(mp1), MapOS2ToWin32Y(win32wnd, SHORT2FROMMP(mp1)));
578 break;
579 }
580
581 //**************************************************************************
582 //Slider messages
583 //**************************************************************************
584 case WM_VSCROLL:
585 case WM_HSCROLL:
586 {
587 ULONG scrollPos, scrollCode, scrollMsg;
588
589 scrollCode = SHORT2FROMMP(mp2);
590 scrollPos = SHORT1FROMMP(mp2);
591 scrollMsg = msg;
592
593 OSLibTranslateScrollCmdAndMsg(&scrollMsg, &scrollCode);
594
595 if(win32wnd->MsgScroll(scrollMsg, scrollCode, scrollPos)) {
596 goto RunDefWndProc;
597 }
598 break;
599 }
600
601 case WM_CONTROL:
602
603 case WM_COMMAND:
604 if(SHORT1FROMMP(mp2) == CMDSRC_MENU) {
605 win32wnd->MsgCommand(CMD_MENU, SHORT1FROMMP(mp1), 0);
606 }
607 if(SHORT1FROMMP(mp2) == CMDSRC_ACCELERATOR) {
608 win32wnd->MsgCommand(CMD_ACCELERATOR, SHORT1FROMMP(mp1), 0);
609 }
610 //todo controls + accelerators
611 break;
612
613 case WM_SYSCOMMAND:
614 {
615 ULONG x = 0, y = 0;
616 ULONG win32sc;
617
618 if(SHORT2FROMMP(mp2) == TRUE) {//syscommand caused by mouse action
619 POINTL pointl;
620 WinQueryPointerPos(HWND_DESKTOP, &pointl);
621 x = pointl.x;
622 y = ScreenHeight - y;
623 }
624 switch(SHORT1FROMMP(mp1)) {
625 case SC_MOVE:
626 win32sc = SC_MOVE_W;
627 break;
628 case SC_CLOSE:
629 win32sc = SC_CLOSE_W;
630 break;
631 case SC_MAXIMIZE:
632 win32sc = SC_MAXIMIZE_W;
633 break;
634 case SC_MINIMIZE:
635 win32sc = SC_MINIMIZE_W;
636 break;
637 case SC_NEXTFRAME:
638 case SC_NEXTWINDOW:
639 win32sc = SC_NEXTWINDOW_W;
640 break;
641 case SC_RESTORE:
642 win32sc = SC_RESTORE_W;
643 break;
644 case SC_TASKMANAGER:
645 win32sc = SC_TASKLIST_W;
646 break;
647 default:
648 goto RunDefWndProc;
649 }
650 dprintf(("WM_SYSCOMMAND %x %x (%d,%d)", hwnd, win32sc, x, y));
651 if(win32wnd->MsgSysCommand(win32sc, x, y)) {
652 goto RunDefWndProc;
653 }
654 break;
655 }
656 case WM_CHAR:
657 {
658 THDB *thdb;
659 ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
660 ULONG flags = SHORT1FROMMP(mp1);
661 BOOL keyWasPressed, fTranslated = FALSE, fRunDefWndProc = FALSE;
662 char c;
663
664 repeatCount = CHAR3FROMMP(mp1);
665 scanCode = CHAR4FROMMP(mp1);
666 keyWasPressed = ((SHORT1FROMMP (mp1) & KC_PREVDOWN) == KC_PREVDOWN);
667
668 // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
669 // given the OS/2 virtual key and OS/2 character
670
671 if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
672 ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
673 {
674 c = SHORT1FROMMP (mp2);
675 if ((c >= 'A') && (c <= 'Z')) {
676 virtualKey = c;
677 goto VirtualKeyFound;
678 }
679 if ((c >='a') && (c <= 'z')) {
680 virtualKey = c - 32; // make it uppercase
681 goto VirtualKeyFound;
682 }
683 if ((c >= '0') && (c <= '9')) {
684 virtualKey = c;
685 goto VirtualKeyFound;
686 }
687 }
688
689 // convert OS/2 virtual keys to Win32 virtual key
690 if (SHORT2FROMMP (mp2) <= VK_BLK2)
691 virtualKey = virtualKeyTable [SHORT2FROMMP (mp2)];
692
693VirtualKeyFound:
694
695 if(!(SHORT1FROMMP(mp1) & KC_ALT))
696 {
697 //
698 // the Alt key is not pressed
699 //
700 if ((flags & KC_KEYUP) == KC_KEYUP) {
701 // send WM_KEYUP message
702
703 if(win32wnd->MsgKeyUp (repeatCount, scanCode, virtualKey)) {
704 fRunDefWndProc = TRUE;
705 }
706 }
707 else {
708 // send WM_KEYDOWN message
709 if (win32wnd->MsgKeyDown (repeatCount, scanCode, virtualKey, keyWasPressed))
710 fRunDefWndProc = TRUE;
711 }
712 }
713 else {
714 //
715 // the Alt key is pressed
716 //
717 if ((flags & KC_KEYUP) == KC_KEYUP) {
718 // send WM_SYSKEYUP message
719
720 if(win32wnd->MsgSysKeyUp (repeatCount, scanCode, virtualKey)) {
721 fRunDefWndProc = TRUE;
722 }
723 }
724 else {
725 // send WM_SYSKEYDOWN message
726 if (win32wnd->MsgSysKeyDown (repeatCount, scanCode, virtualKey, keyWasPressed))
727 fRunDefWndProc = TRUE;
728 }
729 }
730
731 thdb = GetThreadTHDB();
732 if(thdb) {
733 fTranslated = thdb->fMsgTranslated;
734 thdb->fMsgTranslated = FALSE; //reset flag
735 }
736 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
737 // the newly generated WM_CHAR message.
738 if(fTranslated && !((flags & KC_KEYUP) == KC_KEYUP)) {//TranslatedMessage was called before DispatchMessage, so send WM_CHAR messages
739 ULONG keyflags = 0, vkey = 0;
740 ULONG fl = SHORT1FROMMP(mp1);
741
742 if(!(fl & KC_CHAR)) {
743 goto RunDefWndProc;
744 }
745 if(fl & KC_VIRTUALKEY) {
746 vkey = SHORT2FROMMP(mp2);
747 }
748 if(fl & KC_KEYUP) {
749 keyflags |= KEY_UP;
750 }
751 if(fl & KC_ALT) {
752 keyflags |= KEY_ALTDOWN;
753 }
754 if(fl & KC_PREVDOWN) {
755 keyflags |= KEY_PREVDOWN;
756 }
757 if(fl & KC_DEADKEY) {
758 keyflags |= KEY_DEADKEY;
759 }
760 if(win32wnd->MsgChar(SHORT1FROMMP(mp2), CHAR3FROMMP(mp1), CHAR4FROMMP(mp1), virtualKey, keyflags)) {
761 goto RunDefWndProc;
762 }
763 }
764 if(fRunDefWndProc) goto RunDefWndProc;
765 break;
766 }
767
768 case WM_INITMENU:
769 case WM_MENUSELECT:
770 case WM_MENUEND:
771 case WM_NEXTMENU:
772 goto RunDefWndProc;
773
774 case WM_TIMER:
775 if (mp2) win32wnd->MsgTimer((ULONG)mp1);
776 goto RunDefWndProc;
777
778 case WM_SETWINDOWPARAMS:
779 {
780 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
781
782 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
783 if(wndParams->fsStatus & WPM_TEXT) {
784 if(win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText)) {
785 goto RunDefWndProc;
786 }
787 }
788 goto RunDefWndProc;
789 }
790
791 case WM_QUERYWINDOWPARAMS:
792 {
793 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
794 ULONG textlen;
795 PSZ wintext;
796
797 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
798 {
799 if(wndpars->fsStatus & WPM_CCHTEXT)
800 wndpars->cchText = win32wnd->MsgGetTextLength();
801 if(wndpars->fsStatus & WPM_TEXT)
802 wndpars->pszText = win32wnd->MsgGetText();
803
804 wndpars->fsStatus = 0;
805 wndpars->cbCtlData = 0;
806 wndpars->cbPresParams = 0;
807 RestoreOS2TIB();
808 return (MRESULT)TRUE;
809 }
810 goto RunDefWndProc;
811 }
812
813 case WM_PAINT:
814 dprintf(("OS2: WM_PAINT %x", hwnd));
815
816 if (WinQueryUpdateRect (hwnd, NULL)) {
817 if (!win32wnd->isSupressErase()) {
818 BOOL erased = sendEraseBkgnd (win32wnd);
819 win32wnd->setEraseBkgnd (!erased, !erased);
820 }
821 }
822 win32wnd->setSupressErase (FALSE);
823
824 if(win32wnd->MsgPaint(0, 0)) {
825 goto RunDefWndProc;
826 }
827 break;
828
829 case WM_HITTEST:
830 // Only send this message if the window is enabled
831 if (WinIsWindowEnabled(hwnd))
832 {
833 if(win32wnd->MsgHitTest((*(POINTS *)&mp1).x, MapOS2ToWin32Y(OSLIB_HWND_DESKTOP, hwnd, (*(POINTS *)&mp1).y))) {
834 goto RunDefWndProc;
835 }
836 }
837 else goto RunDefWndProc;
838 break;
839
840 case WM_SYSCOLORCHANGE:
841 case WM_SYSVALUECHANGED:
842 case WM_CALCVALIDRECTS:
843 case WM_SETSELECTION:
844 case WM_PPAINT:
845 case WM_PSETFOCUS:
846 case WM_PSYSCOLORCHANGE:
847 case WM_PSIZE:
848 case WM_PACTIVATE:
849 case WM_PCONTROL:
850 case WM_HELP:
851 case WM_APPTERMINATENOTIFY:
852 case WM_PRESPARAMCHANGED:
853 case WM_DRAWITEM:
854 case WM_MEASUREITEM:
855 case WM_CONTROLPOINTER:
856 case WM_QUERYDLGCODE:
857 case WM_SUBSTITUTESTRING:
858 case WM_MATCHMNEMONIC:
859 case WM_SAVEAPPLICATION:
860 case WM_SEMANTICEVENT:
861 default:
862// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
863 RestoreOS2TIB();
864 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
865 }
866 RestoreOS2TIB();
867 return (MRESULT)FALSE;
868
869RunDefWndProc:
870// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
871 RestoreOS2TIB();
872 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
873} /* End of Win32WindowProc */
874//******************************************************************************
875//******************************************************************************
Note: See TracBrowser for help on using the repository browser.