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

Last change on this file since 2140 was 2140, checked in by cbratschi, 26 years ago

removed CS_SIZEREDRAW

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