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

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

Resize bugfix

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