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

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

Rewrote some message apis + WM_WINDOWPOSCHANGED fix

File size: 32.9 KB
Line 
1/* $Id: pmwindow.cpp,v 1.62 1999-12-05 00:31:47 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 //SvL: Can be sent twice now (once in pmframe, once here); shouldn't really matter though...
379 win32wnd->MsgPosChanged((LPARAM)&wp);
380
381 goto RunDefWndProc;
382 }
383#endif
384
385 case WM_ACTIVATE:
386 {
387 HWND hwndActivate = (HWND)mp2;
388 BOOL fMinimized = FALSE;
389
390 dprintf(("OS2: WM_ACTIVATE %x %x", hwnd, hwndActivate));
391 if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
392 //another (non-win32) application's window
393 //set to NULL (allowed according to win32 SDK) to avoid problems
394 hwndActivate = NULL;
395 }
396 if(WinQueryWindowULong(hwnd, QWL_STYLE) & WS_MINIMIZED)
397 {
398 fMinimized = TRUE;
399 }
400
401 if(win32wnd->MsgActivate(SHORT1FROMMP(mp1), fMinimized, Win32BaseWindow::OS2ToWin32Handle(hwndActivate))) {
402 goto RunDefWndProc;
403 }
404 break;
405 }
406
407 case WM_SIZE:
408 {
409 dprintf(("OS2: WM_SIZE (%d,%d) (%d,%d)", SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), SHORT1FROMMP(mp1), SHORT2FROMMP(mp2)));
410 break;
411 }
412
413 case WM_OWNERPOSCHANGE:
414 {
415 dprintf(("OS2: WM_OWNERPOSCHANGE"));
416 goto RunDefWndProc;
417 }
418
419 case WM_CALCVALIDRECTS:
420 {
421 dprintf(("OS2: WM_CALCVALIDRECTS"));
422 goto RunDefWndProc;
423 }
424
425 case WM_FOCUSCHANGE:
426 dprintf(("OS2: WM_FOCUSCHANGE %x", win32wnd->getWindowHandle()));
427 goto RunDefWndProc;
428
429 case WM_SETFOCUS:
430 {
431 HWND hwndFocus = (HWND)mp1;
432
433 dprintf(("OS2: WM_SETFOCUS %x %x %d", win32wnd->getWindowHandle(), mp1, mp2));
434 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
435 //another (non-win32) application's window
436 //set to NULL (allowed according to win32 SDK) to avoid problems
437 hwndFocus = NULL;
438 }
439 if((ULONG)mp2 == TRUE) {
440 HWND hwndFocusWin32 = Win32BaseWindow::OS2ToWin32Handle(hwndFocus);
441 recreateCaret (hwndFocusWin32);
442 rc = win32wnd->MsgSetFocus(hwndFocusWin32);
443 }
444 else rc = win32wnd->MsgKillFocus(Win32BaseWindow::OS2ToWin32Handle(hwndFocus));
445 if(rc) {
446 goto RunDefWndProc;
447 }
448 break;
449 }
450
451 //**************************************************************************
452 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
453 //**************************************************************************
454 case WM_BUTTON1DOWN:
455 dprintf(("OS2: WM_BUTTON1DOWN %x", hwnd));
456 point.x = (*(POINTS *)&mp1).x;
457 point.y = (*(POINTS *)&mp1).y;
458 ClientPoint.x = point.x;
459 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
460 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
461 if(win32wnd->MsgButton(BUTTON_LEFTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
462 goto RunDefWndProc;
463 }
464 break;
465
466 case WM_BUTTON1UP:
467 dprintf(("OS2: WM_BUTTON1UP %x", hwnd));
468 point.x = (*(POINTS *)&mp1).x;
469 point.y = (*(POINTS *)&mp1).y;
470 ClientPoint.x = point.x;
471 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
472 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
473 if(win32wnd->MsgButton(BUTTON_LEFTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
474 goto RunDefWndProc;
475 }
476 break;
477 case WM_BUTTON1DBLCLK:
478 point.x = (*(POINTS *)&mp1).x;
479 point.y = (*(POINTS *)&mp1).y;
480 ClientPoint.x = point.x;
481 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
482 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
483 if(win32wnd->MsgButton(BUTTON_LEFTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
484 goto RunDefWndProc;
485 }
486 break;
487 case WM_BUTTON2DOWN:
488 point.x = (*(POINTS *)&mp1).x;
489 point.y = (*(POINTS *)&mp1).y;
490 ClientPoint.x = point.x;
491 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
492 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
493 if(win32wnd->MsgButton(BUTTON_RIGHTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
494 goto RunDefWndProc;
495 }
496 break;
497 case WM_BUTTON2UP:
498 point.x = (*(POINTS *)&mp1).x;
499 point.y = (*(POINTS *)&mp1).y;
500 ClientPoint.x = point.x;
501 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
502 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
503 if(win32wnd->MsgButton(BUTTON_RIGHTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
504 goto RunDefWndProc;
505 }
506 break;
507 case WM_BUTTON2DBLCLK:
508 point.x = (*(POINTS *)&mp1).x;
509 point.y = (*(POINTS *)&mp1).y;
510 ClientPoint.x = point.x;
511 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
512 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
513 if(win32wnd->MsgButton(BUTTON_RIGHTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
514 goto RunDefWndProc;
515 }
516 break;
517 case WM_BUTTON3DOWN:
518 point.x = (*(POINTS *)&mp1).x;
519 point.y = (*(POINTS *)&mp1).y;
520 ClientPoint.x = point.x;
521 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
522 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
523 if(win32wnd->MsgButton(BUTTON_MIDDLEDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
524 goto RunDefWndProc;
525 }
526 break;
527 case WM_BUTTON3UP:
528 point.x = (*(POINTS *)&mp1).x;
529 point.y = (*(POINTS *)&mp1).y;
530 ClientPoint.x = point.x;
531 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
532 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
533 if(win32wnd->MsgButton(BUTTON_MIDDLEUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
534 goto RunDefWndProc;
535 }
536 break;
537 case WM_BUTTON3DBLCLK:
538 point.x = (*(POINTS *)&mp1).x;
539 point.y = (*(POINTS *)&mp1).y;
540 ClientPoint.x = point.x;
541 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
542 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
543 if(win32wnd->MsgButton(BUTTON_MIDDLEDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
544 goto RunDefWndProc;
545 }
546 break;
547
548 case WM_BUTTON2MOTIONSTART:
549 case WM_BUTTON2MOTIONEND:
550 case WM_BUTTON2CLICK:
551 case WM_BUTTON1MOTIONSTART:
552 case WM_BUTTON1MOTIONEND:
553 case WM_BUTTON1CLICK:
554 case WM_BUTTON3MOTIONSTART:
555 case WM_BUTTON3MOTIONEND:
556 case WM_BUTTON3CLICK:
557 goto RunDefWndProc;
558
559 case WM_MOUSEMOVE:
560 {
561 ULONG keystate = 0;
562 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1))
563 keystate |= WMMOVE_LBUTTON;
564 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2))
565 keystate |= WMMOVE_MBUTTON;
566 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3))
567 keystate |= WMMOVE_RBUTTON;
568 if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT))
569 keystate |= WMMOVE_SHIFT;
570 if(WinGetKeyState(HWND_DESKTOP, VK_CTRL))
571 keystate |= WMMOVE_CTRL;
572
573 //OS/2 Window coordinates -> Win32 Window coordinates
574 win32wnd->MsgMouseMove(keystate, SHORT1FROMMP(mp1), MapOS2ToWin32Y(win32wnd, SHORT2FROMMP(mp1)));
575 break;
576 }
577
578 case WM_CONTROL:
579
580 case WM_COMMAND:
581 if(SHORT1FROMMP(mp2) == CMDSRC_MENU) {
582 win32wnd->MsgCommand(CMD_MENU, SHORT1FROMMP(mp1), 0);
583 }
584 if(SHORT1FROMMP(mp2) == CMDSRC_ACCELERATOR) {
585 win32wnd->MsgCommand(CMD_ACCELERATOR, SHORT1FROMMP(mp1), 0);
586 }
587 //todo controls + accelerators
588 break;
589
590 case WM_SYSCOMMAND:
591 {
592 ULONG x = 0, y = 0;
593 ULONG win32sc;
594
595 if(SHORT2FROMMP(mp2) == TRUE) {//syscommand caused by mouse action
596 POINTL pointl;
597 WinQueryPointerPos(HWND_DESKTOP, &pointl);
598 x = pointl.x;
599 y = ScreenHeight - y;
600 }
601 switch(SHORT1FROMMP(mp1)) {
602 case SC_MOVE:
603 win32sc = SC_MOVE_W;
604 break;
605 case SC_CLOSE:
606 win32sc = SC_CLOSE_W;
607 break;
608 case SC_MAXIMIZE:
609 win32sc = SC_MAXIMIZE_W;
610 break;
611 case SC_MINIMIZE:
612 win32sc = SC_MINIMIZE_W;
613 break;
614 case SC_NEXTFRAME:
615 case SC_NEXTWINDOW:
616 win32sc = SC_NEXTWINDOW_W;
617 break;
618 case SC_RESTORE:
619 win32sc = SC_RESTORE_W;
620 break;
621 case SC_TASKMANAGER:
622 win32sc = SC_TASKLIST_W;
623 break;
624 default:
625 goto RunDefWndProc;
626 }
627 dprintf(("WM_SYSCOMMAND %x %x (%d,%d)", hwnd, win32sc, x, y));
628 if(win32wnd->MsgSysCommand(win32sc, x, y)) {
629 goto RunDefWndProc;
630 }
631 break;
632 }
633 case WM_CHAR:
634 {
635 THDB *thdb;
636 ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
637 ULONG flags = SHORT1FROMMP(mp1);
638 BOOL keyWasPressed, fTranslated = FALSE, fRunDefWndProc = FALSE;
639
640 char c;
641
642 repeatCount = CHAR3FROMMP(mp1);
643 scanCode = CHAR4FROMMP(mp1);
644 keyWasPressed = ((SHORT1FROMMP (mp1) & KC_PREVDOWN) == KC_PREVDOWN);
645
646 dprintf(("PM: WM_CHAR: %x %x %d %x", SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), repeatCount, scanCode));
647 dprintf(("PM: WM_CHAR: %x", flags));
648
649 // vitali add begin
650 if ( ( SHORT1FROMMP(mp2) & 0x0FF ) == 0x0E0 )
651 {
652 // an extended key ( arrows, ins, del and so on )
653 // get "virtual" scancode from character code cause
654 // for "regular" keys they are equal
655 scanCode = ( SHORT1FROMMP(mp2) >> 8) & 0x0FF;
656 }
657 // vitali add end
658
659 // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
660 // given the OS/2 virtual key and OS/2 character
661
662 //if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
663 // ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
664 c = 0;
665 if ((SHORT1FROMMP (mp1) & 0xFF) != 0)
666 {
667 c = SHORT1FROMMP (mp2);
668 if ((c >= 'A') && (c <= 'Z')) {
669 virtualKey = c;
670 goto VirtualKeyFound;
671 }
672 if ((c >='a') && (c <= 'z')) {
673 virtualKey = c - 32; // make it uppercase
674 goto VirtualKeyFound;
675 }
676 if ((c >= '0') && (c <= '9')) {
677 virtualKey = c;
678 goto VirtualKeyFound;
679 }
680 }
681
682 // convert OS/2 virtual keys to Win32 virtual key
683 if (SHORT2FROMMP (mp2) <= VK_BLK2)
684 virtualKey = virtualKeyTable [SHORT2FROMMP (mp2)];
685
686VirtualKeyFound:
687 dprintf (("VIRTUALKEYFOUND:(%x)", virtualKey));
688
689 if(!(SHORT1FROMMP(mp1) & KC_ALT))
690 {
691 //
692 // the Alt key is not pressed
693 //
694 if ((flags & KC_KEYUP) == KC_KEYUP) {
695 // send WM_KEYUP message
696
697 if(win32wnd->MsgKeyUp (repeatCount, scanCode, virtualKey)) {
698 fRunDefWndProc = TRUE;
699 }
700 }
701 else {
702 // send WM_KEYDOWN message
703 if (win32wnd->MsgKeyDown (repeatCount, scanCode,
704 virtualKey, keyWasPressed))
705 fRunDefWndProc = TRUE;
706 }
707 }
708 else {
709 //
710 // the Alt key is pressed
711 //
712 if ((flags & KC_KEYUP) == KC_KEYUP) {
713 // send WM_SYSKEYUP message
714
715 dprintf(("PMWINDOW_WM_SYSKEYUP: vkey:(%x)", virtualKey));
716 if(win32wnd->MsgSysKeyUp (repeatCount, scanCode, virtualKey)) {
717 fRunDefWndProc = TRUE;
718 }
719 }
720 else {
721 // send WM_SYSKEYDOWN message
722 dprintf(("PMWINDOW_WM_SYSKEYDOWN: vkey:(%x)", virtualKey));
723 if (win32wnd->MsgSysKeyDown (repeatCount, scanCode, virtualKey, keyWasPressed))
724 fRunDefWndProc = TRUE;
725 }
726 }
727
728 thdb = GetThreadTHDB();
729 if(thdb) {
730 fTranslated = thdb->fMsgTranslated;
731 thdb->fMsgTranslated = FALSE; //reset flag
732 }
733 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
734 // the newly generated WM_CHAR message.
735 if(fTranslated && !((flags & KC_KEYUP) == KC_KEYUP))
736 {//TranslatedMessage was called before DispatchMessage, so send WM_CHAR messages
737 ULONG keyflags = 0, vkey = 0;
738 ULONG fl = SHORT1FROMMP(mp1);
739 ULONG chCode = SHORT1FROMMP(mp2);
740
741 if(!(fl & KC_CHAR)) {
742//SvL: Test
743 break;
744// goto RunDefWndProc;
745 }
746 if(fl & KC_VIRTUALKEY) {
747 if(virtualKey)
748 vkey = virtualKey;
749 else vkey = SHORT2FROMMP(mp2);
750 chCode = vkey;
751 }
752 if(fl & KC_KEYUP) {
753 keyflags |= KEY_UP;
754 }
755 if(fl & KC_ALT) {
756 keyflags |= KEY_ALTDOWN;
757 }
758 if(fl & KC_PREVDOWN) {
759 keyflags |= KEY_PREVDOWN;
760 }
761 if(fl & KC_DEADKEY) {
762 keyflags |= KEY_DEADKEY;
763 }
764 if(win32wnd->MsgChar(chCode, CHAR3FROMMP(mp1), CHAR4FROMMP(mp1), virtualKey, keyflags)) {
765//SvL: Test
766// goto RunDefWndProc;
767
768 }
769 }
770//SvL: Test
771// if(fRunDefWndProc) goto RunDefWndProc;
772 break;
773 }
774
775 case WM_INITMENU:
776 case WM_MENUSELECT:
777 case WM_MENUEND:
778 case WM_NEXTMENU:
779 goto RunDefWndProc;
780
781 case WM_TIMER:
782 if (mp2)
783 {
784 BOOL sys;
785 ULONG id;
786
787 dprintf(("OS2: WM_TIMER %x %d", hwnd, mp1));
788 if (TIMER_GetTimerInfo(hwnd,(ULONG)mp1,&sys,&id))
789 {
790 if (sys)
791 win32wnd->MsgSysTimer(id);
792 else
793 win32wnd->MsgTimer(id);
794 }
795 }
796 goto RunDefWndProc;
797
798 case WM_SETWINDOWPARAMS:
799 {
800 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
801
802 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
803 if(wndParams->fsStatus & WPM_TEXT) {
804 if(win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText)) {
805 goto RunDefWndProc;
806 }
807 }
808 goto RunDefWndProc;
809 }
810
811 case WM_QUERYWINDOWPARAMS:
812 {
813 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
814 ULONG textlen;
815 PSZ wintext;
816
817 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
818 {
819 if(wndpars->fsStatus & WPM_CCHTEXT)
820 wndpars->cchText = win32wnd->MsgGetTextLength();
821 if(wndpars->fsStatus & WPM_TEXT)
822 wndpars->pszText = win32wnd->MsgGetText();
823
824 wndpars->fsStatus = 0;
825 wndpars->cbCtlData = 0;
826 wndpars->cbPresParams = 0;
827 RestoreOS2TIB();
828 return (MRESULT)TRUE;
829 }
830 goto RunDefWndProc;
831 }
832
833 case WM_ERASEBACKGROUND:
834 {
835 dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
836#if 1
837 break;
838#else
839
840 if (WinQueryUpdateRect (hwnd, NULL) && !win32wnd->isSupressErase()) {
841 BOOL erased = sendEraseBkgnd (win32wnd);
842 win32wnd->setEraseBkgnd (!erased, !erased);
843 }
844
845 break;
846#endif
847 }
848
849 case WM_PAINT:
850 {
851 dprintf(("OS2: WM_PAINT %x", hwnd));
852
853#if 0
854 if (WinQueryUpdateRect (hwnd, NULL)) {
855 if (!win32wnd->isSupressErase() && win32wnd->isEraseBkgnd()) {
856 BOOL erased = sendEraseBkgnd (win32wnd);
857 win32wnd->setEraseBkgnd (!erased, !erased);
858 }
859 }
860
861 win32wnd->setSupressErase (FALSE);
862#endif
863
864 win32wnd->MsgPaint(0, 0);
865
866 //validate the update region, WM_PAINT has no return value
867 goto RunDefWndProc;
868 }
869
870 case WM_HITTEST:
871 // Only send this message if the window is enabled
872 if (WinIsWindowEnabled(hwnd))
873 {
874 if(win32wnd->MsgHitTest((*(POINTS *)&mp1).x, MapOS2ToWin32Y(OSLIB_HWND_DESKTOP, hwnd, (*(POINTS *)&mp1).y))) {
875 goto RunDefWndProc;
876 }
877 }
878 else goto RunDefWndProc;
879 break;
880
881 case WM_CONTEXTMENU:
882 {
883 POINTL pt;
884
885 dprintf(("OS2: WM_CONTEXTMENU %x", hwnd));
886 pt.x = (*(POINTS *)&mp1).x;
887 pt.y = (*(POINTS *)&mp1).y;
888 WinMapWindowPoints(hwnd,HWND_DESKTOP,&pt,1);
889 pt.y = WinQuerySysValue(HWND_DESKTOP,SV_CYSCREEN)-pt.y-1;
890 win32wnd->MsgContextMenu(pt.x,pt.y);
891
892 RestoreOS2TIB();
893 return (MRESULT)TRUE;
894 }
895
896 case WM_SYSCOLORCHANGE:
897 case WM_SYSVALUECHANGED:
898 case WM_SETSELECTION:
899 case WM_PPAINT:
900 case WM_PSETFOCUS:
901 case WM_PSYSCOLORCHANGE:
902 case WM_PSIZE:
903 case WM_PACTIVATE:
904 case WM_PCONTROL:
905 case WM_HELP:
906 case WM_APPTERMINATENOTIFY:
907 case WM_PRESPARAMCHANGED:
908 case WM_DRAWITEM:
909 case WM_MEASUREITEM:
910 case WM_CONTROLPOINTER:
911 case WM_QUERYDLGCODE:
912 case WM_SUBSTITUTESTRING:
913 case WM_MATCHMNEMONIC:
914 case WM_SAVEAPPLICATION:
915 case WM_SEMANTICEVENT:
916 default:
917// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
918 RestoreOS2TIB();
919 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
920 }
921 RestoreOS2TIB();
922 return (MRESULT)FALSE;
923
924RunDefWndProc:
925// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
926 RestoreOS2TIB();
927
928 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
929} /* End of Win32WindowProc */
930//******************************************************************************
931//******************************************************************************
932MRESULT EXPENTRY Win32SubclassWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
933{
934 Win32BaseWindow* win32wnd;
935
936 //Restore our FS selector
937 SetWin32TIB();
938
939 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
940
941 if (!win32wnd)
942 {
943 dprintf(("Invalid win32wnd pointer for subclassed window %x!!", hwnd));
944 goto RunDefWndProc;
945 }
946
947 switch (msg)
948 {
949 case WM_WINDOWPOSCHANGED:
950 {
951 PSWP pswp = (PSWP)mp1;
952 SWP swpOld = *(pswp + 1);
953 WINDOWPOS wp;
954 HWND hParent = NULLHANDLE, hFrame = NULLHANDLE;
955
956 dprintf(("OS2Subclass: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
957 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) break;
958
959 hParent = hFrame = WinQueryWindow(hwnd, QW_PARENT);
960
961 OSLibMapSWPtoWINDOWPOS(pswp,&wp, &swpOld,hParent,hFrame);
962
963 win32wnd->setWindowRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
964 win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
965 wp.x = swpOld.x;
966 wp.y = swpOld.y;
967 wp.cx = swpOld.cx;
968 wp.cy = swpOld.cy;
969
970 wp.hwnd = win32wnd->getWindowHandle();
971
972 win32wnd->MsgPosChanged((LPARAM)&wp);
973
974 goto RunOldWndProc;
975 }
976
977 default:
978 goto RunDefHandler;
979 }
980
981RunDefWndProc:
982 RestoreOS2TIB();
983 return WinDefWindowProc(hwnd,msg,mp1,mp2);
984
985RunOldWndProc:
986 RestoreOS2TIB();
987 return ((PFNWP)win32wnd->getOldWndProc())(hwnd,msg,mp1,mp2);
988
989RunDefHandler:
990 RestoreOS2TIB();
991 return Win32WindowProc(hwnd,msg,mp1,mp2);
992}
993
994PVOID SubclassWithDefHandler(HWND hwnd)
995{
996 return WinSubclassWindow(hwnd,Win32SubclassWindowProc);
997}
Note: See TracBrowser for help on using the repository browser.