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

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

sendmessage + hook updates + misc fixes

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