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

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

EB's fixes + scrollbar changes

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