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

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

WM_WINDOWPOSCHANGED bugfix: don't pass it on to win32 app if frame size/pos changed

File size: 33.2 KB
Line 
1/* $Id: pmwindow.cpp,v 1.63 1999-12-05 14:31:41 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#define INCL_DEV /* Device Function definitions */
15#define INCL_GPICONTROL /* GPI control Functions */
16
17#include <os2wrap.h>
18#include <stdlib.h>
19#include "win32type.h"
20#include <winconst.h>
21#include <wprocess.h>
22#include <misc.h>
23#include <win32wbase.h>
24#include <win32dlg.h>
25#include "win32wdesktop.h"
26#include "pmwindow.h"
27#include "oslibwin.h"
28#include "oslibutil.h"
29#include "oslibgdi.h"
30#include "oslibmsg.h"
31#include "dc.h"
32#include <thread.h>
33#include <wprocess.h>
34#include "caret.h"
35#include "timer.h"
36
37HMQ hmq = 0; /* Message queue handle */
38HAB hab = 0;
39
40RECTL desktopRectl = {0};
41ULONG ScreenWidth = 0;
42ULONG ScreenHeight = 0;
43ULONG ScreenBitsPerPel = 0;
44
45//Used for key translation while processing WM_CHAR message
46USHORT virtualKeyTable [66] = {
47 0x00, // OS/2 VK Win32 VK, Entry 0 is not used
48 0x01, // VK_BUTTON1 VK_LBUTTON
49 0x02, // VK_BUTTON2 VK_RBUTTON
50 0x04, // VK_BUTTON3 VK_MBUTTON
51 0x03, // VK_BREAK VK_CANCEL
52 0x08, // VK_BACKSPACE VK_BACK
53 0x09, // VK_TAB VK_TAB
54 0x00, // VK_BACKTAB No equivalent!
55 0x0A, // VK_NEWLINE 0x0A (no VK_* def)
56 0x10, // VK_SHIFT VK_SHIFT
57 0x11, // VK_CTRL VK_CONTROL
58 0x12, // VK_ALT VK_MENU, best match I guess
59 0x12, // VK_ALTGRAF VK_MENU, best match I guess
60 0x13, // VK_PAUSE VK_PAUSE
61 0x14, // VK_CAPSLOCK VK_CAPITAL
62 0x1B, // VK_ESC VK_ESCAPE
63 0x20, // VK_SPACE VK_SPACE
64 0x21, // VK_PAGEUP VK_PRIOR
65 0x22, // VK_PAGEDOWN VK_NEXT
66 0x23, // VK_END VK_END
67 0x24, // VK_HOME VK_HOME
68 0x25, // VK_LEFT VK_LEFT
69 0x26, // VK_UP VK_UP
70 0x27, // VK_RIGHT VK_RIGHT
71 0x28, // VK_DOWN VK_DOWN
72 0x2C, // VK_PRINTSCRN VK_SNAPSHOT
73 0x2D, // VK_INSERT VK_INSERT
74 0x2E, // VK_DELETE VK_DELETE
75 0x91, // VK_SCRLLOCK VK_SCROLL
76 0x90, // VK_NUMLOCK VK_NUMLOCK
77 0x0D, // VK_ENTER VK_RETURN
78 0x00, // VK_SYSRQ No equivalent!
79 0x70, // VK_F1 VK_F1
80 0x71, // VK_F2 VK_F2
81 0x72, // VK_F3 VK_F3
82 0x73, // VK_F4 VK_F4
83 0x74, // VK_F5 VK_F5
84 0x75, // VK_F6 VK_F6
85 0x76, // VK_F7 VK_F7
86 0x77, // VK_F8 VK_F8
87 0x78, // VK_F9 VK_F9
88 0x79, // VK_F10 VK_F10
89 0x7A, // VK_F11 VK_F11
90 0x7B, // VK_F12 VK_F12
91 0x7C, // VK_F13 VK_F13
92 0x7D, // VK_F14 VK_F14
93 0x7E, // VK_F15 VK_F15
94 0x7F, // VK_F16 VK_F16
95 0x80, // VK_F17 VK_F17
96 0x81, // VK_F18 VK_F18
97 0x82, // VK_F19 VK_F19
98 0x83, // VK_F20 VK_F20
99 0x84, // VK_F21 VK_F21
100 0x85, // VK_F22 VK_F22
101 0x86, // VK_F23 VK_F23
102 0x87, // VK_F24 VK_F24
103 0x00, // VK_ENDDRAG No equivalent!
104 0x0C, // VK_CLEAR VK_CLEAR
105 0xF9, // VK_EREOF VK_EREOF
106 0xFD, // VK_PA1 VK_PA1
107 0xF6, // VK_ATTN VK_ATTN
108 0xF7, // VK_CRSEL VK_CRSEL
109 0xF8, // VK_EXSEL VK_EXSEL
110 0x00, // VK_COPY No equivalent!
111 0x00, // VK_BLK1 No equivalent!
112 0x00}; // VK_BLK2 No equivalent!
113
114MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
115
116//******************************************************************************
117//Initialize PM; create hab, message queue and register special Win32 window classes
118//******************************************************************************
119BOOL InitPM()
120{
121 CLASSINFO FrameClassInfo;
122
123 hab = WinInitialize(0);
124 dprintf(("Winitialize returned %x", hab));
125 hmq = WinCreateMsgQueue(hab, 0);
126
127 if(!hab || !hmq)
128 {
129 UINT error;
130 //CB: only fail on real error
131 error = WinGetLastError(hab) & 0xFFFF; //error code
132 if (!hab || error != PMERR_MSG_QUEUE_ALREADY_EXISTS)
133 {
134 dprintf(("WinInitialize or WinCreateMsgQueue failed %x %x", hab, hmq));
135 dprintf((" Error = %x",error));
136 return(FALSE);
137 }
138 else
139 {
140 if(!hab) {
141 hab = WinQueryAnchorBlock(HWND_DESKTOP);
142 dprintf(("WinQueryAnchorBlock returned %x", hab));
143 }
144 if(!hmq) {
145 hmq = HMQ_CURRENT;
146 }
147 }
148 }
149 SetThreadHAB(hab);
150 dprintf(("InitPM: hmq = %x", hmq));
151 SetThreadMessageQueue(hmq);
152
153 if(!WinRegisterClass( /* Register window class */
154 hab, /* Anchor block handle */
155 (PSZ)WIN32_STDCLASS, /* Window class name */
156 (PFNWP)Win32WindowProc, /* Address of window procedure */
157// CS_SIZEREDRAW | CS_HITTEST | CS_MOVENOTIFY,
158 CS_SIZEREDRAW | CS_HITTEST,
159 NROF_WIN32WNDBYTES)) {
160 dprintf(("WinRegisterClass Win32BaseWindow failed"));
161 return(FALSE);
162 }
163 if (!WinQueryClassInfo (hab, WC_FRAME, &FrameClassInfo)) {
164 dprintf (("WinQueryClassInfo WC_FRAME failed"));
165 return (FALSE);
166 }
167 FrameClassInfo.flClassStyle &= ~(CS_PUBLIC | CS_CLIPSIBLINGS);
168 if (!WinRegisterClass (hab,
169 WIN32_INNERFRAME,
170 FrameClassInfo.pfnWindowProc,
171 FrameClassInfo.flClassStyle,
172 FrameClassInfo.cbWindowData)) {
173 dprintf (("WinRegisterClass Win32InnerFrame failed"));
174 return (FALSE);
175 }
176
177 WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
178 ScreenWidth = desktopRectl.xRight;
179 ScreenHeight = desktopRectl.yTop;
180
181
182 HDC hdc; /* Device-context handle */
183 /* context data structure */
184 DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL,
185 NULL, NULL, NULL};
186
187 /* create memory device context */
188 hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
189 DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1, (PLONG)&ScreenBitsPerPel);
190 DevCloseDC(hdc);
191
192 dprintf(("InitPM: Desktop (%d,%d)", ScreenWidth, ScreenHeight));
193 return OSLibInitMsgQueue();
194} /* End of main */
195//******************************************************************************
196//Win32 window message handler
197//******************************************************************************
198MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
199{
200 POSTMSG_PACKET *postmsg;
201 OSLIBPOINT point, ClientPoint;
202 Win32BaseWindow *win32wnd;
203 APIRET rc;
204
205 //Restore our FS selector
206 SetWin32TIB();
207
208 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
209
210 if(msg != WM_CREATE && win32wnd == NULL) {
211 dprintf(("Invalid win32wnd pointer for window %x!!", hwnd));
212 goto RunDefWndProc;
213 }
214 if(msg == WIN32APP_POSTMSG && (ULONG)mp1 == WIN32PM_MAGIC) {
215 //win32 app user message
216 win32wnd->PostMessage((POSTMSG_PACKET *)mp2);
217 return (MRESULT)0;
218 }
219 switch( msg )
220 {
221 //OS/2 msgs
222 case WM_CREATE:
223 {
224 THDB *thdb = GetThreadTHDB();
225
226 if(thdb == NULL || thdb->newWindow == 0)
227 goto createfail;
228
229 //Processing is done in after WinCreateWindow returns
230 dprintf(("OS2: WM_CREATE %x", hwnd));
231 win32wnd = (Win32BaseWindow *)thdb->newWindow;
232
233 if(win32wnd->MsgCreate(WinQueryWindow(hwnd, QW_PARENT), hwnd) == FALSE)
234 {
235 RestoreOS2TIB();
236 return (MRESULT)TRUE; //discontinue window creation
237 }
238 createfail:
239 RestoreOS2TIB();
240 return (MRESULT)FALSE;
241 }
242
243 case WM_QUIT:
244 dprintf(("OS2: WM_QUIT %x", hwnd));
245 if(win32wnd->MsgQuit()) {
246 goto RunDefWndProc;
247 }
248 break;
249
250 case WM_CLOSE:
251 dprintf(("OS2: WM_CLOSE %x", hwnd));
252// win32wnd->RemoveFakeOpen32();
253 if(win32wnd->MsgClose()) {
254 goto RunDefWndProc;
255 }
256 break;
257
258 case WM_DESTROY:
259 dprintf(("OS2: WM_DESTROY %x", hwnd));
260 if(win32wnd->MsgDestroy()) {
261 goto RunDefWndProc;
262 }
263 break;
264
265 case WM_ENABLE:
266 dprintf(("OS2: WM_ENABLE %x", hwnd));
267 if(win32wnd->MsgEnable(SHORT1FROMMP(mp1))) {
268 goto RunDefWndProc;
269 }
270 break;
271
272 case WM_SHOW:
273 dprintf(("OS2: WM_SHOW %x %d", hwnd, mp1));
274 if(win32wnd->MsgShow((ULONG)mp1)) {
275 goto RunDefWndProc;
276 }
277 break;
278
279#if 1
280 case WM_ADJUSTWINDOWPOS:
281 {
282 PSWP pswp = (PSWP)mp1;
283
284 dprintf(("OS2: WM_ADJUSTWINDOWPOS %x %x %x (%d,%d) (%d,%d)", hwnd, pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
285 goto RunDefWndProc;
286 }
287#else
288 case WM_ADJUSTWINDOWPOS:
289 {
290 PSWP pswp = (PSWP)mp1;
291 SWP swpOld, swpNew;
292 WINDOWPOS wp;
293 ULONG parentHeight = 0;
294 HWND hParent = NULLHANDLE, hFrame = NULLHANDLE, hwndAfter;
295
296 dprintf(("OS2: WM_ADJUSTWINDOWPOS %x %x %x (%d,%d) (%d,%d)", hwnd, pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
297
298 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) goto RunDefWndProc;;
299
300 //SvL: TODO: Workaround. Why is this happening?
301 // When this flag is set the coordinates are 0, even though SWP_SIZE & SWP_MOVE are set.
302// if ((pswp->fl & SWP_NOADJUST)) goto RunDefWndProc;
303
304 if(!win32wnd->CanReceiveSizeMsgs()) goto RunDefWndProc;;
305
306 WinQueryWindowPos(hwnd, &swpOld);
307
308 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
309 if (win32wnd->isChild()) {
310 if(win32wnd->getParent()) {
311 hParent = win32wnd->getParent()->getOS2WindowHandle();
312 }
313 else goto RunDefWndProc;;
314 }
315 }
316 hwndAfter = pswp->hwndInsertBehind;
317 hFrame = win32wnd->getOS2FrameWindowHandle();
318 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, hParent, hFrame);
319
320 wp.hwnd = win32wnd->getWindowHandle();
321 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
322 {
323 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
324 if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
325 }
326 if(win32wnd->MsgPosChanging((LPARAM)&wp) == 0)
327 {//app or default window handler changed wp
328 dprintf(("OS2: WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
329 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
330 OSLibMapWINDOWPOStoSWP(&wp, &swpNew, &swpOld, hParent, hFrame);
331 dprintf(("%x (%d,%d), (%d,%d)", swpNew.fl, swpNew.x, swpNew.y, swpNew.cx, swpNew.cy));
332 swpNew.fl |= SWP_NOADJUST;
333 swpNew.hwndInsertBehind = hwndAfter;
334 swpNew.hwnd = hFrame;
335
336 WinSetMultWindowPos(GetThreadHAB(), &swpNew, 1);
337 return (MRESULT)0;
338 }
339 break;
340 }
341#endif
342
343#if 1
344 case WM_WINDOWPOSCHANGED:
345 {
346 PSWP pswp = (PSWP)mp1;
347 SWP swpOld = *(pswp + 1);
348 WINDOWPOS wp;
349 HWND hParent = NULLHANDLE;
350 LONG yDelta = pswp->cy - swpOld.cy;
351 LONG xDelta = pswp->cx - swpOld.cx;
352
353 dprintf(("OS2: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
354
355 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) goto RunDefWndProc;
356
357 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
358 if (win32wnd->isChild()) {
359 if(win32wnd->getParent()) {
360 hParent = win32wnd->getParent()->getOS2WindowHandle();
361 }
362 else goto RunDefWndProc; //parent has just been destroyed
363 }
364 }
365 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, hParent, win32wnd->getOS2FrameWindowHandle());
366
367 if (!win32wnd->CanReceiveSizeMsgs()) goto RunDefWndProc;
368
369 dprintf(("Set client rectangle to (%d,%d)(%d,%d)", swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy));
370 win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
371
372 wp.hwnd = win32wnd->getWindowHandle();
373 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
374 {
375 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
376 wp.hwndInsertAfter = wndAfter->getWindowHandle();
377 }
378
379 PRECT lpRect = win32wnd->getWindowRect();
380 //SvL: Only send it when the client has changed & the frame hasn't
381 // If the frame size/position has changed, pmframe.cpp will send
382 // this message
383 if(lpRect->right == wp.x+wp.cx && lpRect->bottom == wp.y+wp.cy) {
384 win32wnd->MsgPosChanged((LPARAM)&wp);
385 }
386 else win32wnd->setWindowRect(wp.x, wp.y, wp.x+wp.cx, wp.y+wp.cy);
387
388 goto RunDefWndProc;
389 }
390#endif
391
392 case WM_ACTIVATE:
393 {
394 HWND hwndActivate = (HWND)mp2;
395 BOOL fMinimized = FALSE;
396
397 dprintf(("OS2: WM_ACTIVATE %x %x", hwnd, hwndActivate));
398 if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
399 //another (non-win32) application's window
400 //set to NULL (allowed according to win32 SDK) to avoid problems
401 hwndActivate = NULL;
402 }
403 if(WinQueryWindowULong(hwnd, QWL_STYLE) & WS_MINIMIZED)
404 {
405 fMinimized = TRUE;
406 }
407
408 if(win32wnd->MsgActivate(SHORT1FROMMP(mp1), fMinimized, Win32BaseWindow::OS2ToWin32Handle(hwndActivate))) {
409 goto RunDefWndProc;
410 }
411 break;
412 }
413
414 case WM_SIZE:
415 {
416 dprintf(("OS2: WM_SIZE (%d,%d) (%d,%d)", SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), SHORT1FROMMP(mp1), SHORT2FROMMP(mp2)));
417 break;
418 }
419
420 case WM_OWNERPOSCHANGE:
421 {
422 dprintf(("OS2: WM_OWNERPOSCHANGE"));
423 goto RunDefWndProc;
424 }
425
426 case WM_CALCVALIDRECTS:
427 {
428 dprintf(("OS2: WM_CALCVALIDRECTS"));
429 goto RunDefWndProc;
430 }
431
432 case WM_FOCUSCHANGE:
433 dprintf(("OS2: WM_FOCUSCHANGE %x", win32wnd->getWindowHandle()));
434 goto RunDefWndProc;
435
436 case WM_SETFOCUS:
437 {
438 HWND hwndFocus = (HWND)mp1;
439
440 dprintf(("OS2: WM_SETFOCUS %x %x %d", win32wnd->getWindowHandle(), mp1, mp2));
441 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
442 //another (non-win32) application's window
443 //set to NULL (allowed according to win32 SDK) to avoid problems
444 hwndFocus = NULL;
445 }
446 if((ULONG)mp2 == TRUE) {
447 HWND hwndFocusWin32 = Win32BaseWindow::OS2ToWin32Handle(hwndFocus);
448 recreateCaret (hwndFocusWin32);
449 rc = win32wnd->MsgSetFocus(hwndFocusWin32);
450 }
451 else rc = win32wnd->MsgKillFocus(Win32BaseWindow::OS2ToWin32Handle(hwndFocus));
452 if(rc) {
453 goto RunDefWndProc;
454 }
455 break;
456 }
457
458 //**************************************************************************
459 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
460 //**************************************************************************
461 case WM_BUTTON1DOWN:
462 dprintf(("OS2: WM_BUTTON1DOWN %x", hwnd));
463 point.x = (*(POINTS *)&mp1).x;
464 point.y = (*(POINTS *)&mp1).y;
465 ClientPoint.x = point.x;
466 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
467 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
468 if(win32wnd->MsgButton(BUTTON_LEFTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
469 goto RunDefWndProc;
470 }
471 break;
472
473 case WM_BUTTON1UP:
474 dprintf(("OS2: WM_BUTTON1UP %x", hwnd));
475 point.x = (*(POINTS *)&mp1).x;
476 point.y = (*(POINTS *)&mp1).y;
477 ClientPoint.x = point.x;
478 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
479 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
480 if(win32wnd->MsgButton(BUTTON_LEFTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
481 goto RunDefWndProc;
482 }
483 break;
484 case WM_BUTTON1DBLCLK:
485 point.x = (*(POINTS *)&mp1).x;
486 point.y = (*(POINTS *)&mp1).y;
487 ClientPoint.x = point.x;
488 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
489 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
490 if(win32wnd->MsgButton(BUTTON_LEFTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
491 goto RunDefWndProc;
492 }
493 break;
494 case WM_BUTTON2DOWN:
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_RIGHTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
501 goto RunDefWndProc;
502 }
503 break;
504 case WM_BUTTON2UP:
505 point.x = (*(POINTS *)&mp1).x;
506 point.y = (*(POINTS *)&mp1).y;
507 ClientPoint.x = point.x;
508 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
509 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
510 if(win32wnd->MsgButton(BUTTON_RIGHTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
511 goto RunDefWndProc;
512 }
513 break;
514 case WM_BUTTON2DBLCLK:
515 point.x = (*(POINTS *)&mp1).x;
516 point.y = (*(POINTS *)&mp1).y;
517 ClientPoint.x = point.x;
518 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
519 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
520 if(win32wnd->MsgButton(BUTTON_RIGHTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
521 goto RunDefWndProc;
522 }
523 break;
524 case WM_BUTTON3DOWN:
525 point.x = (*(POINTS *)&mp1).x;
526 point.y = (*(POINTS *)&mp1).y;
527 ClientPoint.x = point.x;
528 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
529 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
530 if(win32wnd->MsgButton(BUTTON_MIDDLEDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
531 goto RunDefWndProc;
532 }
533 break;
534 case WM_BUTTON3UP:
535 point.x = (*(POINTS *)&mp1).x;
536 point.y = (*(POINTS *)&mp1).y;
537 ClientPoint.x = point.x;
538 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
539 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
540 if(win32wnd->MsgButton(BUTTON_MIDDLEUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
541 goto RunDefWndProc;
542 }
543 break;
544 case WM_BUTTON3DBLCLK:
545 point.x = (*(POINTS *)&mp1).x;
546 point.y = (*(POINTS *)&mp1).y;
547 ClientPoint.x = point.x;
548 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
549 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
550 if(win32wnd->MsgButton(BUTTON_MIDDLEDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
551 goto RunDefWndProc;
552 }
553 break;
554
555 case WM_BUTTON2MOTIONSTART:
556 case WM_BUTTON2MOTIONEND:
557 case WM_BUTTON2CLICK:
558 case WM_BUTTON1MOTIONSTART:
559 case WM_BUTTON1MOTIONEND:
560 case WM_BUTTON1CLICK:
561 case WM_BUTTON3MOTIONSTART:
562 case WM_BUTTON3MOTIONEND:
563 case WM_BUTTON3CLICK:
564 goto RunDefWndProc;
565
566 case WM_MOUSEMOVE:
567 {
568 ULONG keystate = 0;
569 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1))
570 keystate |= WMMOVE_LBUTTON;
571 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2))
572 keystate |= WMMOVE_MBUTTON;
573 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3))
574 keystate |= WMMOVE_RBUTTON;
575 if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT))
576 keystate |= WMMOVE_SHIFT;
577 if(WinGetKeyState(HWND_DESKTOP, VK_CTRL))
578 keystate |= WMMOVE_CTRL;
579
580 //OS/2 Window coordinates -> Win32 Window coordinates
581 win32wnd->MsgMouseMove(keystate, SHORT1FROMMP(mp1), MapOS2ToWin32Y(win32wnd, SHORT2FROMMP(mp1)));
582 break;
583 }
584
585 case WM_CONTROL:
586
587 case WM_COMMAND:
588 if(SHORT1FROMMP(mp2) == CMDSRC_MENU) {
589 win32wnd->MsgCommand(CMD_MENU, SHORT1FROMMP(mp1), 0);
590 }
591 if(SHORT1FROMMP(mp2) == CMDSRC_ACCELERATOR) {
592 win32wnd->MsgCommand(CMD_ACCELERATOR, SHORT1FROMMP(mp1), 0);
593 }
594 //todo controls + accelerators
595 break;
596
597 case WM_SYSCOMMAND:
598 {
599 ULONG x = 0, y = 0;
600 ULONG win32sc;
601
602 if(SHORT2FROMMP(mp2) == TRUE) {//syscommand caused by mouse action
603 POINTL pointl;
604 WinQueryPointerPos(HWND_DESKTOP, &pointl);
605 x = pointl.x;
606 y = ScreenHeight - y;
607 }
608 switch(SHORT1FROMMP(mp1)) {
609 case SC_MOVE:
610 win32sc = SC_MOVE_W;
611 break;
612 case SC_CLOSE:
613 win32sc = SC_CLOSE_W;
614 break;
615 case SC_MAXIMIZE:
616 win32sc = SC_MAXIMIZE_W;
617 break;
618 case SC_MINIMIZE:
619 win32sc = SC_MINIMIZE_W;
620 break;
621 case SC_NEXTFRAME:
622 case SC_NEXTWINDOW:
623 win32sc = SC_NEXTWINDOW_W;
624 break;
625 case SC_RESTORE:
626 win32sc = SC_RESTORE_W;
627 break;
628 case SC_TASKMANAGER:
629 win32sc = SC_TASKLIST_W;
630 break;
631 default:
632 goto RunDefWndProc;
633 }
634 dprintf(("WM_SYSCOMMAND %x %x (%d,%d)", hwnd, win32sc, x, y));
635 if(win32wnd->MsgSysCommand(win32sc, x, y)) {
636 goto RunDefWndProc;
637 }
638 break;
639 }
640 case WM_CHAR:
641 {
642 THDB *thdb;
643 ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
644 ULONG flags = SHORT1FROMMP(mp1);
645 BOOL keyWasPressed, fTranslated = FALSE, fRunDefWndProc = FALSE;
646
647 char c;
648
649 repeatCount = CHAR3FROMMP(mp1);
650 scanCode = CHAR4FROMMP(mp1);
651 keyWasPressed = ((SHORT1FROMMP (mp1) & KC_PREVDOWN) == KC_PREVDOWN);
652
653 dprintf(("PM: WM_CHAR: %x %x %d %x", SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), repeatCount, scanCode));
654 dprintf(("PM: WM_CHAR: %x", flags));
655
656 // vitali add begin
657 if ( ( SHORT1FROMMP(mp2) & 0x0FF ) == 0x0E0 )
658 {
659 // an extended key ( arrows, ins, del and so on )
660 // get "virtual" scancode from character code cause
661 // for "regular" keys they are equal
662 scanCode = ( SHORT1FROMMP(mp2) >> 8) & 0x0FF;
663 }
664 // vitali add end
665
666 // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
667 // given the OS/2 virtual key and OS/2 character
668
669 //if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
670 // ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
671 c = 0;
672 if ((SHORT1FROMMP (mp1) & 0xFF) != 0)
673 {
674 c = SHORT1FROMMP (mp2);
675 if ((c >= 'A') && (c <= 'Z')) {
676 virtualKey = c;
677 goto VirtualKeyFound;
678 }
679 if ((c >='a') && (c <= 'z')) {
680 virtualKey = c - 32; // make it uppercase
681 goto VirtualKeyFound;
682 }
683 if ((c >= '0') && (c <= '9')) {
684 virtualKey = c;
685 goto VirtualKeyFound;
686 }
687 }
688
689 // convert OS/2 virtual keys to Win32 virtual key
690 if (SHORT2FROMMP (mp2) <= VK_BLK2)
691 virtualKey = virtualKeyTable [SHORT2FROMMP (mp2)];
692
693VirtualKeyFound:
694 dprintf (("VIRTUALKEYFOUND:(%x)", virtualKey));
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,
711 virtualKey, keyWasPressed))
712 fRunDefWndProc = TRUE;
713 }
714 }
715 else {
716 //
717 // the Alt key is pressed
718 //
719 if ((flags & KC_KEYUP) == KC_KEYUP) {
720 // send WM_SYSKEYUP message
721
722 dprintf(("PMWINDOW_WM_SYSKEYUP: vkey:(%x)", virtualKey));
723 if(win32wnd->MsgSysKeyUp (repeatCount, scanCode, virtualKey)) {
724 fRunDefWndProc = TRUE;
725 }
726 }
727 else {
728 // send WM_SYSKEYDOWN message
729 dprintf(("PMWINDOW_WM_SYSKEYDOWN: vkey:(%x)", virtualKey));
730 if (win32wnd->MsgSysKeyDown (repeatCount, scanCode, virtualKey, keyWasPressed))
731 fRunDefWndProc = TRUE;
732 }
733 }
734
735 thdb = GetThreadTHDB();
736 if(thdb) {
737 fTranslated = thdb->fMsgTranslated;
738 thdb->fMsgTranslated = FALSE; //reset flag
739 }
740 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
741 // the newly generated WM_CHAR message.
742 if(fTranslated && !((flags & KC_KEYUP) == KC_KEYUP))
743 {//TranslatedMessage was called before DispatchMessage, so send WM_CHAR messages
744 ULONG keyflags = 0, vkey = 0;
745 ULONG fl = SHORT1FROMMP(mp1);
746 ULONG chCode = SHORT1FROMMP(mp2);
747
748 if(!(fl & KC_CHAR)) {
749//SvL: Test
750 break;
751// goto RunDefWndProc;
752 }
753 if(fl & KC_VIRTUALKEY) {
754 if(virtualKey)
755 vkey = virtualKey;
756 else vkey = SHORT2FROMMP(mp2);
757 chCode = vkey;
758 }
759 if(fl & KC_KEYUP) {
760 keyflags |= KEY_UP;
761 }
762 if(fl & KC_ALT) {
763 keyflags |= KEY_ALTDOWN;
764 }
765 if(fl & KC_PREVDOWN) {
766 keyflags |= KEY_PREVDOWN;
767 }
768 if(fl & KC_DEADKEY) {
769 keyflags |= KEY_DEADKEY;
770 }
771 if(win32wnd->MsgChar(chCode, CHAR3FROMMP(mp1), CHAR4FROMMP(mp1), virtualKey, keyflags)) {
772//SvL: Test
773// goto RunDefWndProc;
774
775 }
776 }
777//SvL: Test
778// if(fRunDefWndProc) goto RunDefWndProc;
779 break;
780 }
781
782 case WM_INITMENU:
783 case WM_MENUSELECT:
784 case WM_MENUEND:
785 case WM_NEXTMENU:
786 goto RunDefWndProc;
787
788 case WM_TIMER:
789 if (mp2)
790 {
791 BOOL sys;
792 ULONG id;
793
794 dprintf(("OS2: WM_TIMER %x %d", hwnd, mp1));
795 if (TIMER_GetTimerInfo(hwnd,(ULONG)mp1,&sys,&id))
796 {
797 if (sys)
798 win32wnd->MsgSysTimer(id);
799 else
800 win32wnd->MsgTimer(id);
801 }
802 }
803 goto RunDefWndProc;
804
805 case WM_SETWINDOWPARAMS:
806 {
807 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
808
809 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
810 if(wndParams->fsStatus & WPM_TEXT) {
811 if(win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText)) {
812 goto RunDefWndProc;
813 }
814 }
815 goto RunDefWndProc;
816 }
817
818 case WM_QUERYWINDOWPARAMS:
819 {
820 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
821 ULONG textlen;
822 PSZ wintext;
823
824 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
825 {
826 if(wndpars->fsStatus & WPM_CCHTEXT)
827 wndpars->cchText = win32wnd->MsgGetTextLength();
828 if(wndpars->fsStatus & WPM_TEXT)
829 wndpars->pszText = win32wnd->MsgGetText();
830
831 wndpars->fsStatus = 0;
832 wndpars->cbCtlData = 0;
833 wndpars->cbPresParams = 0;
834 RestoreOS2TIB();
835 return (MRESULT)TRUE;
836 }
837 goto RunDefWndProc;
838 }
839
840 case WM_ERASEBACKGROUND:
841 {
842 dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
843#if 1
844 break;
845#else
846
847 if (WinQueryUpdateRect (hwnd, NULL) && !win32wnd->isSupressErase()) {
848 BOOL erased = sendEraseBkgnd (win32wnd);
849 win32wnd->setEraseBkgnd (!erased, !erased);
850 }
851
852 break;
853#endif
854 }
855
856 case WM_PAINT:
857 {
858 dprintf(("OS2: WM_PAINT %x", hwnd));
859
860#if 0
861 if (WinQueryUpdateRect (hwnd, NULL)) {
862 if (!win32wnd->isSupressErase() && win32wnd->isEraseBkgnd()) {
863 BOOL erased = sendEraseBkgnd (win32wnd);
864 win32wnd->setEraseBkgnd (!erased, !erased);
865 }
866 }
867
868 win32wnd->setSupressErase (FALSE);
869#endif
870
871 win32wnd->MsgPaint(0, 0);
872
873 //validate the update region, WM_PAINT has no return value
874 goto RunDefWndProc;
875 }
876
877 case WM_HITTEST:
878 // Only send this message if the window is enabled
879 if (WinIsWindowEnabled(hwnd))
880 {
881 if(win32wnd->MsgHitTest((*(POINTS *)&mp1).x, MapOS2ToWin32Y(OSLIB_HWND_DESKTOP, hwnd, (*(POINTS *)&mp1).y))) {
882 goto RunDefWndProc;
883 }
884 }
885 else goto RunDefWndProc;
886 break;
887
888 case WM_CONTEXTMENU:
889 {
890 POINTL pt;
891
892 dprintf(("OS2: WM_CONTEXTMENU %x", hwnd));
893 pt.x = (*(POINTS *)&mp1).x;
894 pt.y = (*(POINTS *)&mp1).y;
895 WinMapWindowPoints(hwnd,HWND_DESKTOP,&pt,1);
896 pt.y = WinQuerySysValue(HWND_DESKTOP,SV_CYSCREEN)-pt.y-1;
897 win32wnd->MsgContextMenu(pt.x,pt.y);
898
899 RestoreOS2TIB();
900 return (MRESULT)TRUE;
901 }
902
903 case WM_SYSCOLORCHANGE:
904 case WM_SYSVALUECHANGED:
905 case WM_SETSELECTION:
906 case WM_PPAINT:
907 case WM_PSETFOCUS:
908 case WM_PSYSCOLORCHANGE:
909 case WM_PSIZE:
910 case WM_PACTIVATE:
911 case WM_PCONTROL:
912 case WM_HELP:
913 case WM_APPTERMINATENOTIFY:
914 case WM_PRESPARAMCHANGED:
915 case WM_DRAWITEM:
916 case WM_MEASUREITEM:
917 case WM_CONTROLPOINTER:
918 case WM_QUERYDLGCODE:
919 case WM_SUBSTITUTESTRING:
920 case WM_MATCHMNEMONIC:
921 case WM_SAVEAPPLICATION:
922 case WM_SEMANTICEVENT:
923 default:
924// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
925 RestoreOS2TIB();
926 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
927 }
928 RestoreOS2TIB();
929 return (MRESULT)FALSE;
930
931RunDefWndProc:
932// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
933 RestoreOS2TIB();
934
935 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
936} /* End of Win32WindowProc */
937//******************************************************************************
938//******************************************************************************
939MRESULT EXPENTRY Win32SubclassWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
940{
941 Win32BaseWindow* win32wnd;
942
943 //Restore our FS selector
944 SetWin32TIB();
945
946 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
947
948 if (!win32wnd)
949 {
950 dprintf(("Invalid win32wnd pointer for subclassed window %x!!", hwnd));
951 goto RunDefWndProc;
952 }
953
954 switch (msg)
955 {
956 case WM_WINDOWPOSCHANGED:
957 {
958 PSWP pswp = (PSWP)mp1;
959 SWP swpOld = *(pswp + 1);
960 WINDOWPOS wp;
961 HWND hParent = NULLHANDLE, hFrame = NULLHANDLE;
962
963 dprintf(("OS2Subclass: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
964 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) break;
965
966 hParent = hFrame = WinQueryWindow(hwnd, QW_PARENT);
967
968 OSLibMapSWPtoWINDOWPOS(pswp,&wp, &swpOld,hParent,hFrame);
969
970 win32wnd->setWindowRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
971 win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
972 wp.x = swpOld.x;
973 wp.y = swpOld.y;
974 wp.cx = swpOld.cx;
975 wp.cy = swpOld.cy;
976
977 wp.hwnd = win32wnd->getWindowHandle();
978
979 win32wnd->MsgPosChanged((LPARAM)&wp);
980
981 goto RunOldWndProc;
982 }
983
984 default:
985 goto RunDefHandler;
986 }
987
988RunDefWndProc:
989 RestoreOS2TIB();
990 return WinDefWindowProc(hwnd,msg,mp1,mp2);
991
992RunOldWndProc:
993 RestoreOS2TIB();
994 return ((PFNWP)win32wnd->getOldWndProc())(hwnd,msg,mp1,mp2);
995
996RunDefHandler:
997 RestoreOS2TIB();
998 return Win32WindowProc(hwnd,msg,mp1,mp2);
999}
1000
1001PVOID SubclassWithDefHandler(HWND hwnd)
1002{
1003 return WinSubclassWindow(hwnd,Win32SubclassWindowProc);
1004}
Note: See TracBrowser for help on using the repository browser.