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

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

added WINE scrollbars to frame, fixed pmframe, WM_ENTERIDLE

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