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

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

mouse dragging fix + updated isMdiClient code/headers

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