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

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

Lots of window fixes & changes

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