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

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

WM_ACTIVATE(APP) changes

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