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

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

Window destruction fixes

File size: 30.5 KB
Line 
1/* $Id: pmwindow.cpp,v 1.30 1999-10-15 13:52:54 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 return (MRESULT)win32wnd->SendMessageA((ULONG)msg-WIN32APP_USERMSGBASE, (ULONG)mp1, (ULONG)mp2);
187 }
188 switch( msg )
189 {
190 //OS/2 msgs
191 case WM_CREATE:
192 {
193 THDB *thdb = GetThreadTHDB();
194
195 if(thdb == NULL || thdb->newWindow == 0)
196 goto createfail;
197
198 //Processing is done in after WinCreateWindow returns
199 dprintf(("OS2: WM_CREATE %x", hwnd));
200 win32wnd = (Win32BaseWindow *)thdb->newWindow;
201
202 if(win32wnd->MsgCreate(WinQueryWindow(hwnd, QW_PARENT), hwnd) == FALSE)
203 {
204 RestoreOS2TIB();
205 return (MRESULT)TRUE; //discontinue window creation
206 }
207 createfail:
208 RestoreOS2TIB();
209 return (MRESULT)FALSE;
210 }
211
212 case WM_QUIT:
213 dprintf(("OS2: WM_QUIT %x", hwnd));
214 if(win32wnd->MsgQuit()) {
215 goto RunDefWndProc;
216 }
217 break;
218
219 case WM_CLOSE:
220 dprintf(("OS2: WM_CLOSE %x", hwnd));
221// win32wnd->RemoveFakeOpen32();
222 if(win32wnd->MsgClose()) {
223 goto RunDefWndProc;
224 }
225 break;
226
227 case WM_DESTROY:
228 dprintf(("OS2: WM_DESTROY %x", hwnd));
229 if(win32wnd->MsgDestroy()) {
230 goto RunDefWndProc;
231 }
232 break;
233
234 case WM_ENABLE:
235 dprintf(("OS2: WM_ENABLE %x", hwnd));
236 if(win32wnd->MsgEnable(SHORT1FROMMP(mp1))) {
237 goto RunDefWndProc;
238 }
239 break;
240
241 case WM_SHOW:
242 dprintf(("OS2: WM_SHOW %x %d", hwnd, mp1));
243 if(win32wnd->MsgShow((ULONG)mp1)) {
244 goto RunDefWndProc;
245 }
246 break;
247
248 case WM_ADJUSTWINDOWPOS:
249 {
250 PSWP pswp = (PSWP)mp1;
251 SWP swpOld;
252 WINDOWPOS wp;
253 ULONG parentHeight = 0;
254 HWND hParent = NULLHANDLE, hFrame = NULLHANDLE;
255
256 dprintf(("OS2: WM_ADJUSTWINDOWPOS %x %x (%d,%d) (%d,%d)", hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
257
258 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) break;
259
260 WinQueryWindowPos(hwnd, &swpOld);
261
262 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
263 if (win32wnd->isChild()) {
264 if(win32wnd->getParent()) {
265 hParent = win32wnd->getParent()->getOS2WindowHandle();
266 }
267 else break;
268 }
269 else
270 hFrame = win32wnd->getOS2FrameWindowHandle();
271 }
272 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, hParent, hFrame);
273
274 wp.hwnd = win32wnd->getWindowHandle();
275 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
276 {
277 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
278 if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
279 }
280 win32wnd->MsgPosChanging((LPARAM)&wp);
281 break;
282 }
283
284 case WM_WINDOWPOSCHANGED:
285 {
286 PSWP pswp = (PSWP)mp1;
287 PSWP pswpo = pswp + 1;
288 WINDOWPOS wp;
289 ULONG parentHeight = 0;
290 HWND hParent = NULLHANDLE, hFrame = NULLHANDLE;
291 LONG yDelta = pswp->cy - pswpo->cy;
292 LONG xDelta = pswp->cx - pswpo->cx;
293 ULONG classStyle;
294
295 dprintf(("OS2: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
296
297 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) break;
298
299 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
300 if (win32wnd->isChild()) {
301 if(win32wnd->getParent()) {
302 hParent = win32wnd->getParent()->getOS2WindowHandle();
303 }
304 else goto RunDefWndProc; //parent has just been destroyed
305 }
306 else
307 hFrame = WinQueryWindow(hwnd, QW_PARENT);
308 }
309 OSLibMapSWPtoWINDOWPOS(pswp, &wp, pswpo, hParent, hFrame);
310
311 SWP swpFrame;
312 WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT), &swpFrame);
313 dprintf(("WINDOWPOSCHANGE %x %x %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), win32wnd->getOS2FrameWindowHandle(),
314 swpFrame.fl,swpFrame.x, swpFrame.y, swpFrame.cx, swpFrame.cy));
315 POINTL point;
316
317 point.x = swpFrame.x;
318 point.y = swpFrame.y;
319 if(win32wnd->getParent() != NULL)
320 {
321 WinMapWindowPoints(WinQueryWindow(hwnd, QW_PARENT), HWND_DESKTOP,
322 &point, 1);
323 }
324 point.y = OSLibQueryScreenHeight() - point.y - swpFrame.cy;
325 win32wnd->setWindowRect(point.x, point.y, point.x+swpFrame.cx, point.y+swpFrame.cy);
326 win32wnd->setClientRect(pswpo->x, pswpo->y, pswpo->x + pswpo->cx, pswpo->y + pswpo->cy);
327
328 wp.hwnd = win32wnd->getWindowHandle();
329 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
330 {
331 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
332 wp.hwndInsertAfter = wndAfter->getWindowHandle();
333 }
334 classStyle = win32wnd->getClass()->getStyle();
335
336 if (yDelta != 0 || xDelta != 0)
337 {
338 HENUM henum = WinBeginEnumWindows(pswp->hwnd);
339 SWP swp[10];
340 int i = 0;
341 HWND hwnd;
342
343 while ((hwnd = WinGetNextWindow(henum)) != NULLHANDLE)
344 {
345#if 0
346 if (mdiClient )
347 {
348 continue;
349 }
350#endif
351 WinQueryWindowPos(hwnd, &(swp[i]));
352
353#ifdef DEBUG
354 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
355 dprintf(("ENUMERATE %x delta %d (%d,%d) (%d,%d) %x", (window) ? window->getWindowHandle() : hwnd,
356 yDelta, swp[i].x, swp[i].y, swp[i].cx, swp[i].cy, swp[i].fl));
357#endif
358
359 if(swp[i].y != 0) {
360 //child window at offset <> 0 from client area -> offset now changes
361 swp[i].y += yDelta;
362 swp[i].fl &= ~(SWP_NOREDRAW);
363 }
364 //else child window with the same start coorindates as the client area
365 //The app should resize it.
366
367 if (i == 9)
368 {
369 WinSetMultWindowPos(GetThreadHAB(), swp, 10);
370 i = 0;
371 }
372 else
373 {
374 i++;
375 }
376 }
377
378 WinEndEnumWindows(henum);
379
380 if (i)
381 WinSetMultWindowPos(GetThreadHAB(), swp, i);
382 }
383 if (yDelta != 0)
384 {
385 POINT pt;
386 if(GetCaretPos (&pt) == TRUE)
387 {
388 pt.y -= yDelta;
389 SetCaretPos (pt.x, pt.y);
390 }
391 }
392 win32wnd->MsgPosChanged((LPARAM)&wp);
393
394 goto RunDefWndProc;
395// break;
396 }
397
398 case WM_ERASEBACKGROUND:
399 {
400 dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
401 if (!win32wnd->isSupressErase()) {
402 BOOL erased = sendEraseBkgnd (win32wnd);
403 win32wnd->setEraseBkgnd (!erased, !erased);
404 }
405 break;
406 }
407
408 case WM_MOVE:
409 {
410 if (!win32wnd->isFrameWindow()) break;
411
412 HWND hFrame = win32wnd->getOS2FrameWindowHandle();
413 SWP swp, swpo;
414 WINDOWPOS wp;
415 ULONG parentHeight = 0;
416 RECTL rcl;
417
418 WinQueryWindowRect (hwnd, &rcl);
419 WinMapWindowPoints (hwnd, hFrame, (PPOINTL)&rcl, 2);
420 swp.x = swpo.x = rcl.xLeft;
421 swp.y = swpo.y = rcl.yBottom;
422 swp.cx = swpo.cx = rcl.xRight - rcl.xLeft;
423 swp.cy = swpo.cy = rcl.yTop - rcl.yBottom;
424 swp.fl = SWP_MOVE | SWP_NOREDRAW;
425 swp.hwnd = hwnd;
426 swp.hwndInsertBehind = NULLHANDLE;
427 dprintf(("OS2: WM_MOVE %x %x (%d,%d) (%d,%d)", hwnd, swp.fl, swp.x, swp.y, swp.cx, swp.cy));
428
429 OSLibMapSWPtoWINDOWPOS(&swp, &wp, &swpo, NULLHANDLE, hFrame);
430
431 wp.flags &= ~SWP_NOMOVE_W;
432 wp.hwnd = win32wnd->getWindowHandle();
433 win32wnd->setWindowRect(wp.x, wp.y, wp.x + wp.cx, wp.y + wp.cy);
434 win32wnd->setClientRect(swpo.x, swpo.y, swpo.x + swpo.cx, swpo.y + swpo.cy);
435 win32wnd->MsgPosChanged((LPARAM)&wp);
436 break;
437 }
438
439 case WM_SIZE:
440 {
441 break;
442 }
443
444 case WM_ACTIVATE:
445 {
446 HWND hwndActivate = (HWND)mp2;
447 BOOL fMinimized = FALSE;
448
449 dprintf(("OS2: WM_ACTIVATE %x %x", hwnd, hwndActivate));
450 if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
451 //another (non-win32) application's window
452 //set to NULL (allowed according to win32 SDK) to avoid problems
453 hwndActivate = NULL;
454 }
455 if(WinQueryWindowULong(hwnd, QWL_STYLE) & WS_MINIMIZED)
456 {
457 fMinimized = TRUE;
458 }
459
460 if(win32wnd->MsgActivate(SHORT1FROMMP(mp1), fMinimized, Win32BaseWindow::OS2ToWin32Handle(hwndActivate))) {
461 goto RunDefWndProc;
462 }
463 break;
464 }
465 case WM_FOCUSCHANGE:
466 dprintf(("OS2: WM_FOCUSCHANGE %x", hwnd));
467 goto RunDefWndProc;
468
469 case WM_SETFOCUS:
470 {
471 HWND hwndFocus = (HWND)mp1;
472
473 dprintf(("OS2: WM_SETFOCUS %x %d", hwnd, mp2));
474 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
475 //another (non-win32) application's window
476 //set to NULL (allowed according to win32 SDK) to avoid problems
477 hwndFocus = NULL;
478 }
479 if((ULONG)mp2 == TRUE) {
480 HWND hwndFocusWin32 = Win32BaseWindow::OS2ToWin32Handle(hwndFocus);
481 recreateCaret (hwndFocusWin32);
482 rc = win32wnd->MsgSetFocus(hwndFocusWin32);
483 }
484 else rc = win32wnd->MsgKillFocus(Win32BaseWindow::OS2ToWin32Handle(hwndFocus));
485 if(rc) {
486 goto RunDefWndProc;
487 }
488 break;
489 }
490 //**************************************************************************
491 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
492 //**************************************************************************
493 case WM_BUTTON1DOWN:
494 dprintf(("OS2: WM_BUTTON1DOWN %x", hwnd));
495 point.x = (*(POINTS *)&mp1).x;
496 point.y = (*(POINTS *)&mp1).y;
497 ClientPoint.x = point.x;
498 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
499 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
500 if(win32wnd->MsgButton(BUTTON_LEFTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
501 goto RunDefWndProc;
502 }
503 break;
504
505 case WM_BUTTON1UP:
506 dprintf(("OS2: WM_BUTTON1UP %x", hwnd));
507 point.x = (*(POINTS *)&mp1).x;
508 point.y = (*(POINTS *)&mp1).y;
509 ClientPoint.x = point.x;
510 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
511 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
512 if(win32wnd->MsgButton(BUTTON_LEFTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
513 goto RunDefWndProc;
514 }
515 break;
516 case WM_BUTTON1DBLCLK:
517 point.x = (*(POINTS *)&mp1).x;
518 point.y = (*(POINTS *)&mp1).y;
519 ClientPoint.x = point.x;
520 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
521 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
522 if(win32wnd->MsgButton(BUTTON_LEFTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
523 goto RunDefWndProc;
524 }
525 break;
526 case WM_BUTTON2DOWN:
527 point.x = (*(POINTS *)&mp1).x;
528 point.y = (*(POINTS *)&mp1).y;
529 ClientPoint.x = point.x;
530 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
531 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
532 if(win32wnd->MsgButton(BUTTON_RIGHTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
533 goto RunDefWndProc;
534 }
535 break;
536 case WM_BUTTON2UP:
537 point.x = (*(POINTS *)&mp1).x;
538 point.y = (*(POINTS *)&mp1).y;
539 ClientPoint.x = point.x;
540 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
541 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
542 if(win32wnd->MsgButton(BUTTON_RIGHTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
543 goto RunDefWndProc;
544 }
545 break;
546 case WM_BUTTON2DBLCLK:
547 point.x = (*(POINTS *)&mp1).x;
548 point.y = (*(POINTS *)&mp1).y;
549 ClientPoint.x = point.x;
550 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
551 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
552 if(win32wnd->MsgButton(BUTTON_RIGHTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
553 goto RunDefWndProc;
554 }
555 break;
556 case WM_BUTTON3DOWN:
557 point.x = (*(POINTS *)&mp1).x;
558 point.y = (*(POINTS *)&mp1).y;
559 ClientPoint.x = point.x;
560 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
561 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
562 if(win32wnd->MsgButton(BUTTON_MIDDLEDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
563 goto RunDefWndProc;
564 }
565 break;
566 case WM_BUTTON3UP:
567 point.x = (*(POINTS *)&mp1).x;
568 point.y = (*(POINTS *)&mp1).y;
569 ClientPoint.x = point.x;
570 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
571 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
572 if(win32wnd->MsgButton(BUTTON_MIDDLEUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
573 goto RunDefWndProc;
574 }
575 break;
576 case WM_BUTTON3DBLCLK:
577 point.x = (*(POINTS *)&mp1).x;
578 point.y = (*(POINTS *)&mp1).y;
579 ClientPoint.x = point.x;
580 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
581 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
582 if(win32wnd->MsgButton(BUTTON_MIDDLEDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
583 goto RunDefWndProc;
584 }
585 break;
586
587 case WM_BUTTON2MOTIONSTART:
588 case WM_BUTTON2MOTIONEND:
589 case WM_BUTTON2CLICK:
590 case WM_BUTTON1MOTIONSTART:
591 case WM_BUTTON1MOTIONEND:
592 case WM_BUTTON1CLICK:
593 case WM_BUTTON3MOTIONSTART:
594 case WM_BUTTON3MOTIONEND:
595 case WM_BUTTON3CLICK:
596 goto RunDefWndProc;
597
598 case WM_MOUSEMOVE:
599 {
600 ULONG keystate = 0;
601 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1))
602 keystate |= WMMOVE_LBUTTON;
603 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2))
604 keystate |= WMMOVE_MBUTTON;
605 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3))
606 keystate |= WMMOVE_RBUTTON;
607 if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT))
608 keystate |= WMMOVE_SHIFT;
609 if(WinGetKeyState(HWND_DESKTOP, VK_CTRL))
610 keystate |= WMMOVE_CTRL;
611
612 //OS/2 Window coordinates -> Win32 Window coordinates
613 if(win32wnd->MsgMouseMove(keystate, SHORT1FROMMP(mp1), MapOS2ToWin32Y(win32wnd, SHORT2FROMMP(mp1))))
614 {
615 //Changes mouse cursor to default
616 goto RunDefWndProc;
617 }
618 break;
619 }
620
621 //**************************************************************************
622 //Slider messages
623 //**************************************************************************
624 case WM_VSCROLL:
625 case WM_HSCROLL:
626 {
627 ULONG scrollPos, scrollCode, scrollMsg;
628
629 scrollCode = SHORT2FROMMP(mp2);
630 scrollPos = SHORT1FROMMP(mp2);
631 scrollMsg = msg;
632
633 OSLibTranslateScrollCmdAndMsg(&scrollMsg, &scrollCode);
634
635 if(win32wnd->MsgScroll(scrollMsg, scrollCode, scrollPos)) {
636 goto RunDefWndProc;
637 }
638 break;
639 }
640
641 case WM_CONTROL:
642
643 case WM_COMMAND:
644 if(SHORT1FROMMP(mp2) == CMDSRC_MENU) {
645 win32wnd->MsgCommand(CMD_MENU, SHORT1FROMMP(mp1), 0);
646 }
647 if(SHORT1FROMMP(mp2) == CMDSRC_ACCELERATOR) {
648 win32wnd->MsgCommand(CMD_ACCELERATOR, SHORT1FROMMP(mp1), 0);
649 }
650 //todo controls + accelerators
651 break;
652
653 case WM_SYSCOMMAND:
654 {
655 ULONG x = 0, y = 0;
656 ULONG win32sc;
657
658 if(SHORT2FROMMP(mp2) == TRUE) {//syscommand caused by mouse action
659 POINTL pointl;
660 WinQueryPointerPos(HWND_DESKTOP, &pointl);
661 x = pointl.x;
662 y = ScreenHeight - y;
663 }
664 switch(SHORT1FROMMP(mp1)) {
665 case SC_MOVE:
666 win32sc = SC_MOVE_W;
667 break;
668 case SC_CLOSE:
669 win32sc = SC_CLOSE_W;
670 break;
671 case SC_MAXIMIZE:
672 win32sc = SC_MAXIMIZE_W;
673 break;
674 case SC_MINIMIZE:
675 win32sc = SC_MINIMIZE_W;
676 break;
677 case SC_NEXTFRAME:
678 case SC_NEXTWINDOW:
679 win32sc = SC_NEXTWINDOW_W;
680 break;
681 case SC_RESTORE:
682 win32sc = SC_RESTORE_W;
683 break;
684 case SC_TASKMANAGER:
685 win32sc = SC_TASKLIST_W;
686 break;
687 default:
688 goto RunDefWndProc;
689 }
690 dprintf(("WM_SYSCOMMAND %x %x (%d,%d)", hwnd, win32sc, x, y));
691 if(win32wnd->MsgSysCommand(win32sc, x, y)) {
692 goto RunDefWndProc;
693 }
694 break;
695 }
696 case WM_CHAR:
697 {
698 THDB *thdb;
699 ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
700 ULONG flags = SHORT1FROMMP(mp1);
701 BOOL keyWasPressed, fTranslated = FALSE, fRunDefWndProc = FALSE;
702 char c;
703
704 repeatCount = CHAR3FROMMP(mp1);
705 scanCode = CHAR4FROMMP(mp1);
706 keyWasPressed = ((SHORT1FROMMP (mp1) & KC_PREVDOWN) == KC_PREVDOWN);
707
708 // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
709 // given the OS/2 virtual key and OS/2 character
710
711 if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
712 ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
713 {
714 c = SHORT1FROMMP (mp2);
715 if ((c >= 'A') && (c <= 'Z')) {
716 virtualKey = c;
717 goto VirtualKeyFound;
718 }
719 if ((c >='a') && (c <= 'z')) {
720 virtualKey = c - 32; // make it uppercase
721 goto VirtualKeyFound;
722 }
723 if ((c >= '0') && (c <= '9')) {
724 virtualKey = c;
725 goto VirtualKeyFound;
726 }
727 }
728
729 // convert OS/2 virtual keys to Win32 virtual key
730 if (SHORT2FROMMP (mp2) <= VK_BLK2)
731 virtualKey = virtualKeyTable [SHORT2FROMMP (mp2)];
732
733VirtualKeyFound:
734
735 if(!(SHORT1FROMMP(mp1) & KC_ALT))
736 {
737 //
738 // the Alt key is not pressed
739 //
740 if ((flags & KC_KEYUP) == KC_KEYUP) {
741 // send WM_KEYUP message
742
743 if(win32wnd->MsgKeyUp (repeatCount, scanCode, virtualKey)) {
744 fRunDefWndProc = TRUE;
745 }
746 }
747 else {
748 // send WM_KEYDOWN message
749 if (win32wnd->MsgKeyDown (repeatCount, scanCode, virtualKey, keyWasPressed))
750 fRunDefWndProc = TRUE;
751 }
752 }
753 else {
754 //
755 // the Alt key is pressed
756 //
757 if ((flags & KC_KEYUP) == KC_KEYUP) {
758 // send WM_SYSKEYUP message
759
760 if(win32wnd->MsgSysKeyUp (repeatCount, scanCode, virtualKey)) {
761 fRunDefWndProc = TRUE;
762 }
763 }
764 else {
765 // send WM_SYSKEYDOWN message
766 if (win32wnd->MsgSysKeyDown (repeatCount, scanCode, virtualKey, keyWasPressed))
767 fRunDefWndProc = TRUE;
768 }
769 }
770
771 thdb = GetThreadTHDB();
772 if(thdb) {
773 fTranslated = thdb->fMsgTranslated;
774 thdb->fMsgTranslated = FALSE; //reset flag
775 }
776 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
777 // the newly generated WM_CHAR message.
778 if(fTranslated && !((flags & KC_KEYUP) == KC_KEYUP)) {//TranslatedMessage was called before DispatchMessage, so send WM_CHAR messages
779 ULONG keyflags = 0, vkey = 0;
780 ULONG fl = SHORT1FROMMP(mp1);
781
782 if(!(fl & KC_CHAR)) {
783 goto RunDefWndProc;
784 }
785 if(fl & KC_VIRTUALKEY) {
786 vkey = SHORT2FROMMP(mp2);
787 }
788 if(fl & KC_KEYUP) {
789 keyflags |= KEY_UP;
790 }
791 if(fl & KC_ALT) {
792 keyflags |= KEY_ALTDOWN;
793 }
794 if(fl & KC_PREVDOWN) {
795 keyflags |= KEY_PREVDOWN;
796 }
797 if(fl & KC_DEADKEY) {
798 keyflags |= KEY_DEADKEY;
799 }
800 if(win32wnd->MsgChar(SHORT1FROMMP(mp2), CHAR3FROMMP(mp1), CHAR4FROMMP(mp1), virtualKey, keyflags)) {
801 goto RunDefWndProc;
802 }
803 }
804 if(fRunDefWndProc) goto RunDefWndProc;
805 break;
806 }
807
808 case WM_INITMENU:
809 case WM_MENUSELECT:
810 case WM_MENUEND:
811 case WM_NEXTMENU:
812 goto RunDefWndProc;
813
814 case WM_TIMER:
815 if (mp2) win32wnd->MsgTimer((ULONG)mp1);
816 goto RunDefWndProc;
817
818 case WM_SETWINDOWPARAMS:
819 {
820 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
821
822 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
823 if(wndParams->fsStatus & WPM_TEXT) {
824 if(win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText)) {
825 goto RunDefWndProc;
826 }
827 }
828 goto RunDefWndProc;
829 }
830
831 case WM_QUERYWINDOWPARAMS:
832 {
833 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
834 ULONG textlen;
835 PSZ wintext;
836
837 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
838 {
839 if(wndpars->fsStatus & WPM_CCHTEXT)
840 wndpars->cchText = win32wnd->MsgGetTextLength();
841 if(wndpars->fsStatus & WPM_TEXT)
842 wndpars->pszText = win32wnd->MsgGetText();
843
844 wndpars->fsStatus = 0;
845 wndpars->cbCtlData = 0;
846 wndpars->cbPresParams = 0;
847 RestoreOS2TIB();
848 return (MRESULT)TRUE;
849 }
850 goto RunDefWndProc;
851 }
852
853 case WM_PAINT:
854 dprintf(("OS2: WM_PAINT %x", hwnd));
855
856 if (WinQueryUpdateRect (hwnd, NULL)) {
857 if (!win32wnd->isSupressErase()) {
858 BOOL erased = sendEraseBkgnd (win32wnd);
859 win32wnd->setEraseBkgnd (!erased, !erased);
860 }
861 }
862 win32wnd->setSupressErase (FALSE);
863
864 if(win32wnd->MsgPaint(0, 0)) {
865 goto RunDefWndProc;
866 }
867 break;
868
869 case WM_HITTEST:
870 // Only send this message if the window is enabled
871 if (WinIsWindowEnabled(hwnd))
872 {
873 if(win32wnd->MsgHitTest((*(POINTS *)&mp1).x, MapOS2ToWin32Y(OSLIB_HWND_DESKTOP, hwnd, (*(POINTS *)&mp1).y))) {
874 goto RunDefWndProc;
875 }
876 }
877 else goto RunDefWndProc;
878 break;
879
880 case WM_SYSCOLORCHANGE:
881 case WM_SYSVALUECHANGED:
882 case WM_CALCVALIDRECTS:
883 case WM_SETSELECTION:
884 case WM_PPAINT:
885 case WM_PSETFOCUS:
886 case WM_PSYSCOLORCHANGE:
887 case WM_PSIZE:
888 case WM_PACTIVATE:
889 case WM_PCONTROL:
890 case WM_HELP:
891 case WM_APPTERMINATENOTIFY:
892 case WM_PRESPARAMCHANGED:
893 case WM_DRAWITEM:
894 case WM_MEASUREITEM:
895 case WM_CONTROLPOINTER:
896 case WM_QUERYDLGCODE:
897 case WM_SUBSTITUTESTRING:
898 case WM_MATCHMNEMONIC:
899 case WM_SAVEAPPLICATION:
900 case WM_SEMANTICEVENT:
901 default:
902// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
903 RestoreOS2TIB();
904 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
905 }
906 RestoreOS2TIB();
907 return (MRESULT)FALSE;
908
909RunDefWndProc:
910// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
911 RestoreOS2TIB();
912 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
913} /* End of Win32WindowProc */
914//******************************************************************************
915//******************************************************************************
Note: See TracBrowser for help on using the repository browser.