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

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

display api fixes

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