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

Last change on this file since 1094 was 1094, checked in by dengert, 26 years ago

caret blinking and recreation

File size: 28.4 KB
Line 
1/* $Id: pmwindow.cpp,v 1.13 1999-09-29 09:31:18 dengert 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 0x22, // VK_PAGEUP VK_NEXT
61 0x21, // VK_PAGEDOWN VK_PRIOR
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 NROF_WIN32WNDBYTES)) {
153 dprintf(("WinRegisterClass Win32BaseWindow failed"));
154 return(FALSE);
155 }
156
157 WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
158 ScreenWidth = desktopRectl.xRight;
159 ScreenHeight = desktopRectl.yTop;
160
161 dprintf(("InitPM: Desktop (%d,%d)", ScreenWidth, ScreenHeight));
162 return OSLibInitMsgQueue();
163} /* End of main */
164//******************************************************************************
165//Win32 window message handler
166//******************************************************************************
167MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
168{
169 POSTMSG_PACKET *postmsg;
170 OSLIBPOINT point, ClientPoint;
171 Win32BaseWindow *win32wnd;
172 APIRET rc;
173
174 //Restore our FS selector
175 SetWin32TIB();
176
177 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
178
179 if(msg != WM_CREATE && win32wnd == NULL) {
180 dprintf(("Invalid win32wnd pointer for window %x!!", hwnd));
181 goto RunDefWndProc;
182 }
183 if(msg > WIN32APP_USERMSGBASE) {
184 //win32 app user message
185 dprintf(("PMWINDOW: Message %x (%x,%x) posted to window %x", (ULONG)msg-WIN32APP_USERMSGBASE, mp1, mp2, hwnd));
186 win32wnd->SendMessageA((ULONG)msg-WIN32APP_USERMSGBASE, (ULONG)mp1, (ULONG)mp2);
187 }
188 switch( msg )
189 {
190 //OS/2 msgs
191 case WM_CREATE:
192 //Processing is done in after WinCreateWindow returns
193 dprintf(("OS2: WM_CREATE %x", hwnd));
194 RestoreOS2TIB();
195 return (MRESULT)FALSE;
196
197 case WM_QUIT:
198 dprintf(("OS2: WM_QUIT %x", hwnd));
199 if(win32wnd->MsgQuit()) {
200 goto RunDefWndProc;
201 }
202 break;
203
204 case WM_CLOSE:
205 dprintf(("OS2: WM_CLOSE %x", hwnd));
206// win32wnd->RemoveFakeOpen32();
207 if(win32wnd->MsgClose()) {
208 goto RunDefWndProc;
209 }
210 break;
211
212 case WM_DESTROY:
213 dprintf(("OS2: WM_DESTROY %x", hwnd));
214 if(win32wnd->MsgDestroy()) {
215 goto RunDefWndProc;
216 }
217 break;
218
219 case WM_ENABLE:
220 dprintf(("OS2: WM_ENABLE %x", hwnd));
221 if(win32wnd->MsgEnable((ULONG)mp1)) {
222 goto RunDefWndProc;
223 }
224 break;
225
226 case WM_SHOW:
227 dprintf(("OS2: WM_SHOW %x", hwnd));
228 if(win32wnd->MsgShow((ULONG)mp1)) {
229 goto RunDefWndProc;
230 }
231 break;
232
233 case WM_ADJUSTWINDOWPOS:
234 {
235 PSWP pswp = (PSWP)mp1;
236 SWP swpOld;
237 WINDOWPOS wp;
238 ULONG parentHeight = 0;
239 HWND hParent = NULLHANDLE, hFrame = NULLHANDLE;
240
241 dprintf(("OS2: WM_ADJUSTWINDOWPOS %x %x (%d,%d) (%d,%d)", hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
242
243 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) break;
244
245 WinQueryWindowPos(hwnd, &swpOld);
246
247 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
248 if (win32wnd->isChild())
249 hParent = win32wnd->getParent()->getOS2WindowHandle();
250 else
251 hFrame = win32wnd->getOS2FrameWindowHandle();
252 }
253 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, hParent, hFrame);
254
255 wp.hwnd = win32wnd->getWindowHandle();
256 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
257 {
258 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
259 if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
260 }
261 win32wnd->MsgPosChanging((LPARAM)&wp);
262 break;
263 }
264
265 case WM_WINDOWPOSCHANGED:
266 {
267 PSWP pswp = (PSWP)mp1;
268 PSWP pswpo = pswp + 1;
269 WINDOWPOS wp;
270 ULONG parentHeight = 0;
271 HWND hParent = NULLHANDLE, hFrame = NULLHANDLE;
272 LONG yDelta = pswp->cy - pswpo->cy;
273 ULONG classStyle;
274
275 dprintf(("OS2: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
276
277 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) break;
278
279 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
280 if (win32wnd->isChild())
281 hParent = win32wnd->getParent()->getOS2WindowHandle();
282 else
283 hFrame = win32wnd->getOS2FrameWindowHandle();
284 }
285 OSLibMapSWPtoWINDOWPOS(pswp, &wp, pswpo, hParent, hFrame);
286
287 win32wnd->setWindowRect(wp.x, wp.y, wp.x + wp.cx, wp.y + wp.cy);
288 win32wnd->setClientRect(pswpo->x, pswpo->y, pswpo->x + pswpo->cx, pswpo->y + pswpo->cy);
289
290 wp.hwnd = win32wnd->getWindowHandle();
291 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
292 {
293 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
294 wp.hwndInsertAfter = wndAfter->getWindowHandle();
295 }
296 classStyle = win32wnd->getClass()->getStyle();
297 if ((yDelta != 0) && ((classStyle & CS_VREDRAW_W) ||
298 ((classStyle & CS_HREDRAW_W) && (pswp->cx != pswpo->cx))))
299 {
300 HENUM henum = WinBeginEnumWindows(pswp->hwnd);
301 SWP swp[10];
302 int i = 0;
303 HWND hwnd;
304
305 while ((hwnd = WinGetNextWindow(henum)) != NULLHANDLE)
306 {
307#if 0
308 if (mdiClient )
309 {
310 continue;
311 }
312#endif
313 WinQueryWindowPos(hwnd, &(swp[i]));
314 swp[i].y += yDelta;
315
316 if (i == 9)
317 {
318 WinSetMultWindowPos(GetThreadHAB(), swp, 10);
319 i = 0;
320 }
321 else
322 {
323 i++;
324 }
325 }
326
327 WinEndEnumWindows(henum);
328
329 if (i)
330 WinSetMultWindowPos(GetThreadHAB(), swp, i);
331 }
332 win32wnd->MsgPosChanged((LPARAM)&wp);
333
334 break;
335 }
336
337 case WM_ERASEBACKGROUND:
338 {
339 if (!win32wnd->isSupressErase()) {
340 BOOL erased = sendEraseBkgnd (win32wnd);
341 win32wnd->setEraseBkgnd (!erased, !erased);
342 }
343 break;
344 }
345
346 case WM_MOVE:
347 {
348 if (!win32wnd->isFrameWindow()) break;
349
350 HWND hFrame = win32wnd->getOS2FrameWindowHandle();
351 SWP swp, swpo;
352 WINDOWPOS wp;
353 ULONG parentHeight = 0;
354 RECTL rcl;
355
356 WinQueryWindowRect (hwnd, &rcl);
357 WinMapWindowPoints (hwnd, hFrame, (PPOINTL)&rcl, 2);
358 swp.x = swpo.x = rcl.xLeft;
359 swp.y = swpo.y = rcl.yBottom;
360 swp.cx = swpo.cx = rcl.xRight - rcl.xLeft;
361 swp.cy = swpo.cy = rcl.yTop - rcl.yBottom;
362 swp.fl = SWP_MOVE | SWP_NOREDRAW;
363 swp.hwnd = hwnd;
364 swp.hwndInsertBehind = NULLHANDLE;
365
366 OSLibMapSWPtoWINDOWPOS(&swp, &wp, &swpo, NULLHANDLE, hFrame);
367
368 wp.flags &= ~SWP_NOMOVE_W;
369 wp.hwnd = win32wnd->getWindowHandle();
370 win32wnd->setWindowRect(wp.x, wp.y, wp.x + wp.cx, wp.y + wp.cy);
371 win32wnd->setClientRect(swpo.x, swpo.y, swpo.x + swpo.cx, swpo.y + swpo.cy);
372 win32wnd->MsgPosChanged((LPARAM)&wp);
373 break;
374 }
375 case WM_SIZE:
376 {
377 break;
378 }
379
380 case WM_ACTIVATE:
381 {
382 HWND hwndActivate = (HWND)mp2;
383 BOOL fMinimized = FALSE;
384
385 dprintf(("OS2: WM_ACTIVATE %x %x", hwnd, hwndActivate));
386 if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
387 //another (non-win32) application's window
388 //set to NULL (allowed according to win32 SDK) to avoid problems
389 hwndActivate = NULL;
390 }
391 if(WinQueryWindowULong(hwnd, QWL_STYLE) & WS_MINIMIZED)
392 {
393 fMinimized = TRUE;
394 }
395
396 if(win32wnd->MsgActivate(SHORT1FROMMP(mp1), fMinimized, Win32BaseWindow::OS2ToWin32Handle(hwndActivate))) {
397 goto RunDefWndProc;
398 }
399 break;
400 }
401 case WM_FOCUSCHANGE:
402 dprintf(("OS2: WM_FOCUSCHANGE %x", hwnd));
403 goto RunDefWndProc;
404
405 case WM_SETFOCUS:
406 {
407 HWND hwndFocus = (HWND)mp1;
408
409 dprintf(("OS2: WM_SETFOCUS %x %d", hwnd, mp2));
410 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
411 //another (non-win32) application's window
412 //set to NULL (allowed according to win32 SDK) to avoid problems
413 hwndFocus = NULL;
414 }
415 if((ULONG)mp2 == TRUE) {
416 HWND hwndFocusWin32 = Win32BaseWindow::OS2ToWin32Handle(hwndFocus);
417 recreateCaret (hwndFocusWin32);
418 rc = win32wnd->MsgSetFocus(hwndFocusWin32);
419 }
420 else rc = win32wnd->MsgKillFocus(Win32BaseWindow::OS2ToWin32Handle(hwndFocus));
421 if(rc) {
422 goto RunDefWndProc;
423 }
424 break;
425 }
426 //**************************************************************************
427 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
428 //**************************************************************************
429 case WM_BUTTON1DOWN:
430 dprintf(("OS2: WM_BUTTON1DOWN %x", hwnd));
431 point.x = (*(POINTS *)&mp1).x;
432 point.y = (*(POINTS *)&mp1).y;
433 ClientPoint.x = point.x;
434 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
435 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
436 if(win32wnd->MsgButton(BUTTON_LEFTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
437 goto RunDefWndProc;
438 }
439 break;
440
441 case WM_BUTTON1UP:
442 dprintf(("OS2: WM_BUTTON1UP %x", hwnd));
443 point.x = (*(POINTS *)&mp1).x;
444 point.y = (*(POINTS *)&mp1).y;
445 ClientPoint.x = point.x;
446 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
447 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
448 if(win32wnd->MsgButton(BUTTON_LEFTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
449 goto RunDefWndProc;
450 }
451 break;
452 case WM_BUTTON1DBLCLK:
453 point.x = (*(POINTS *)&mp1).x;
454 point.y = (*(POINTS *)&mp1).y;
455 ClientPoint.x = point.x;
456 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
457 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
458 if(win32wnd->MsgButton(BUTTON_LEFTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
459 goto RunDefWndProc;
460 }
461 break;
462 case WM_BUTTON2DOWN:
463 point.x = (*(POINTS *)&mp1).x;
464 point.y = (*(POINTS *)&mp1).y;
465 ClientPoint.x = point.x;
466 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
467 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
468 if(win32wnd->MsgButton(BUTTON_RIGHTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
469 goto RunDefWndProc;
470 }
471 break;
472 case WM_BUTTON2UP:
473 point.x = (*(POINTS *)&mp1).x;
474 point.y = (*(POINTS *)&mp1).y;
475 ClientPoint.x = point.x;
476 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
477 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
478 if(win32wnd->MsgButton(BUTTON_RIGHTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
479 goto RunDefWndProc;
480 }
481 break;
482 case WM_BUTTON2DBLCLK:
483 point.x = (*(POINTS *)&mp1).x;
484 point.y = (*(POINTS *)&mp1).y;
485 ClientPoint.x = point.x;
486 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
487 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
488 if(win32wnd->MsgButton(BUTTON_RIGHTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
489 goto RunDefWndProc;
490 }
491 break;
492 case WM_BUTTON3DOWN:
493 point.x = (*(POINTS *)&mp1).x;
494 point.y = (*(POINTS *)&mp1).y;
495 ClientPoint.x = point.x;
496 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
497 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
498 if(win32wnd->MsgButton(BUTTON_MIDDLEDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
499 goto RunDefWndProc;
500 }
501 break;
502 case WM_BUTTON3UP:
503 point.x = (*(POINTS *)&mp1).x;
504 point.y = (*(POINTS *)&mp1).y;
505 ClientPoint.x = point.x;
506 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
507 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
508 if(win32wnd->MsgButton(BUTTON_MIDDLEUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
509 goto RunDefWndProc;
510 }
511 break;
512 case WM_BUTTON3DBLCLK:
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_MIDDLEDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
519 goto RunDefWndProc;
520 }
521 break;
522
523 case WM_BUTTON2MOTIONSTART:
524 case WM_BUTTON2MOTIONEND:
525 case WM_BUTTON2CLICK:
526 case WM_BUTTON1MOTIONSTART:
527 case WM_BUTTON1MOTIONEND:
528 case WM_BUTTON1CLICK:
529 case WM_BUTTON3MOTIONSTART:
530 case WM_BUTTON3MOTIONEND:
531 case WM_BUTTON3CLICK:
532 goto RunDefWndProc;
533
534 case WM_MOUSEMOVE:
535 {
536 //Only send this message when the mouse isn't captured
537 if(WinQueryCapture(HWND_DESKTOP) != NULLHANDLE) {
538 goto RunDefWndProc;
539 }
540 ULONG keystate = 0;
541 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1))
542 keystate |= WMMOVE_LBUTTON;
543 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2))
544 keystate |= WMMOVE_MBUTTON;
545 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3))
546 keystate |= WMMOVE_RBUTTON;
547 if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT))
548 keystate |= WMMOVE_SHIFT;
549 if(WinGetKeyState(HWND_DESKTOP, VK_CTRL))
550 keystate |= WMMOVE_CTRL;
551
552 //OS/2 Window coordinates -> Win32 Window coordinates
553 //NOTE: Do not call the default OS/2 window handler as that one changes
554 // the mousepointer!
555 win32wnd->MsgMouseMove(keystate, SHORT1FROMMP(mp1), MapOS2ToWin32Y(win32wnd, SHORT2FROMMP(mp1)));
556 break;
557 }
558
559 //**************************************************************************
560 //Slider messages
561 //**************************************************************************
562 case WM_VSCROLL:
563 case WM_HSCROLL:
564 {
565 ULONG scrollPos, scrollCode, scrollMsg;
566
567 scrollCode = SHORT2FROMMP(mp2);
568 scrollPos = SHORT1FROMMP(mp2);
569 scrollMsg = msg;
570
571 OSLibTranslateScrollCmdAndMsg(&scrollMsg, &scrollCode);
572
573 if(win32wnd->MsgScroll(scrollMsg, scrollCode, scrollPos)) {
574 goto RunDefWndProc;
575 }
576 break;
577 }
578
579 case WM_CONTROL:
580
581 case WM_COMMAND:
582 if(SHORT1FROMMP(mp2) == CMDSRC_MENU) {
583 win32wnd->MsgCommand(CMD_MENU, SHORT1FROMMP(mp1), 0);
584 }
585 if(SHORT1FROMMP(mp2) == CMDSRC_ACCELERATOR) {
586 win32wnd->MsgCommand(CMD_ACCELERATOR, SHORT1FROMMP(mp1), 0);
587 }
588 //todo controls + accelerators
589 break;
590
591 case WM_SYSCOMMAND:
592 {
593 ULONG x = 0, y = 0;
594 ULONG win32sc;
595
596 if(SHORT2FROMMP(mp2) == TRUE) {//syscommand caused by mouse action
597 POINTL pointl;
598 WinQueryPointerPos(HWND_DESKTOP, &pointl);
599 x = pointl.x;
600 y = ScreenHeight - y;
601 }
602 switch(SHORT1FROMMP(mp1)) {
603 case SC_MOVE:
604 win32sc = SC_MOVE_W;
605 break;
606 case SC_CLOSE:
607 win32sc = SC_CLOSE_W;
608 break;
609 case SC_MAXIMIZE:
610 win32sc = SC_MAXIMIZE_W;
611 break;
612 case SC_MINIMIZE:
613 win32sc = SC_MINIMIZE_W;
614 break;
615 case SC_NEXTFRAME:
616 case SC_NEXTWINDOW:
617 win32sc = SC_NEXTWINDOW_W;
618 break;
619 case SC_RESTORE:
620 win32sc = SC_RESTORE_W;
621 break;
622 case SC_TASKMANAGER:
623 win32sc = SC_TASKLIST_W;
624 break;
625 default:
626 goto RunDefWndProc;
627 }
628 dprintf(("WM_SYSCOMMAND %x %x (%d,%d)", hwnd, win32sc, x, y));
629 if(win32wnd->MsgSysCommand(win32sc, x, y)) {
630 goto RunDefWndProc;
631 }
632 break;
633 }
634 case WM_CHAR:
635 {
636 THDB *thdb;
637 ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
638 ULONG flags = SHORT1FROMMP(mp1);
639 BOOL keyWasPressed, fTranslated = FALSE, fRunDefWndProc = FALSE;
640 char c;
641
642 repeatCount = CHAR3FROMMP(mp1);
643 scanCode = CHAR4FROMMP(mp1);
644 keyWasPressed = ((SHORT1FROMMP (mp1) & KC_PREVDOWN) == KC_PREVDOWN);
645
646 // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
647 // given the OS/2 virtual key and OS/2 character
648
649 if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
650 ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
651 {
652 c = SHORT1FROMMP (mp2);
653 if ((c >= 'A') && (c <= 'Z')) {
654 virtualKey = c;
655 goto VirtualKeyFound;
656 }
657 if ((c >='a') && (c <= 'z')) {
658 virtualKey = c - 32; // make it uppercase
659 goto VirtualKeyFound;
660 }
661 if ((c >= '0') && (c <= '9')) {
662 virtualKey = c;
663 goto VirtualKeyFound;
664 }
665 }
666
667 // convert OS/2 virtual keys to Win32 virtual key
668 if (SHORT2FROMMP (mp2) <= VK_BLK2)
669 virtualKey = virtualKeyTable [SHORT2FROMMP (mp2)];
670
671VirtualKeyFound:
672
673 if(!(SHORT1FROMMP(mp1) & KC_ALT))
674 {
675 //
676 // the Alt key is not pressed
677 //
678 if ((flags & KC_KEYUP) == KC_KEYUP) {
679 // send WM_KEYUP message
680
681 if(win32wnd->MsgKeyUp (repeatCount, scanCode, virtualKey)) {
682 fRunDefWndProc = TRUE;
683 }
684 }
685 else {
686 // send WM_KEYDOWN message
687 if (win32wnd->MsgKeyDown (repeatCount, scanCode, virtualKey, keyWasPressed))
688 fRunDefWndProc = TRUE;
689 }
690 }
691 else {
692 //
693 // the Alt key is pressed
694 //
695 if ((flags & KC_KEYUP) == KC_KEYUP) {
696 // send WM_SYSKEYUP message
697
698 if(win32wnd->MsgSysKeyUp (repeatCount, scanCode, virtualKey)) {
699 fRunDefWndProc = TRUE;
700 }
701 }
702 else {
703 // send WM_SYSKEYDOWN message
704 if (win32wnd->MsgSysKeyDown (repeatCount, scanCode, virtualKey, keyWasPressed))
705 fRunDefWndProc = TRUE;
706 }
707 }
708
709 thdb = GetThreadTHDB();
710 if(thdb) {
711 fTranslated = thdb->fMsgTranslated;
712 thdb->fMsgTranslated = FALSE; //reset flag
713 }
714 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
715 // the newly generated WM_CHAR message.
716 if(fTranslated && !((flags & KC_KEYUP) == KC_KEYUP)) {//TranslatedMessage was called before DispatchMessage, so send WM_CHAR messages
717 ULONG keyflags = 0, vkey = 0;
718 ULONG fl = SHORT1FROMMP(mp1);
719
720 if(!(fl & KC_CHAR)) {
721 goto RunDefWndProc;
722 }
723 if(fl & KC_VIRTUALKEY) {
724 vkey = SHORT2FROMMP(mp2);
725 }
726 if(fl & KC_KEYUP) {
727 keyflags |= KEY_UP;
728 }
729 if(fl & KC_ALT) {
730 keyflags |= KEY_ALTDOWN;
731 }
732 if(fl & KC_PREVDOWN) {
733 keyflags |= KEY_PREVDOWN;
734 }
735 if(fl & KC_DEADKEY) {
736 keyflags |= KEY_DEADKEY;
737 }
738 if(win32wnd->MsgChar(SHORT1FROMMP(mp2), CHAR3FROMMP(mp1), CHAR4FROMMP(mp1), virtualKey, keyflags)) {
739 goto RunDefWndProc;
740 }
741 }
742 if(fRunDefWndProc) goto RunDefWndProc;
743 break;
744 }
745
746 case WM_INITMENU:
747 case WM_MENUSELECT:
748 case WM_MENUEND:
749 case WM_NEXTMENU:
750 goto RunDefWndProc;
751
752 case WM_TIMER:
753 if (mp2) win32wnd->MsgTimer((ULONG)mp1);
754 goto RunDefWndProc;
755
756 case WM_SETWINDOWPARAMS:
757 {
758 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
759
760 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
761 if(wndParams->fsStatus & WPM_TEXT) {
762 if(win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText)) {
763 goto RunDefWndProc;
764 }
765 }
766 goto RunDefWndProc;
767 }
768
769 case WM_QUERYWINDOWPARAMS:
770 {
771 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
772 ULONG textlen;
773 PSZ wintext;
774
775 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT)) {
776 if(wndpars->fsStatus & WPM_CCHTEXT)
777 wndpars->cchText = win32wnd->MsgGetTextLength();
778 if(wndpars->fsStatus & WPM_TEXT)
779 wndpars->pszText = win32wnd->MsgGetText();
780 return (MRESULT)TRUE;
781 }
782 goto RunDefWndProc;
783 }
784
785 case WM_PAINT:
786 dprintf(("OS2: WM_PAINT %x", hwnd));
787
788 if (WinQueryUpdateRect (hwnd, NULL)) {
789 if (!win32wnd->isSupressErase()) {
790 BOOL erased = sendEraseBkgnd (win32wnd);
791 win32wnd->setEraseBkgnd (!erased, !erased);
792 }
793 }
794 win32wnd->setSupressErase (FALSE);
795
796 if(win32wnd->MsgPaint(0, 0)) {
797 goto RunDefWndProc;
798 }
799 break;
800
801 case WM_HITTEST:
802 // Only send this message if the window is enabled
803 if (WinIsWindowEnabled(hwnd))
804 {
805 if(win32wnd->MsgHitTest((*(POINTS *)&mp1).x, MapOS2ToWin32Y(OSLIB_HWND_DESKTOP, hwnd, (*(POINTS *)&mp1).y))) {
806 goto RunDefWndProc;
807 }
808 }
809 else goto RunDefWndProc;
810 break;
811
812 case WM_SYSCOLORCHANGE:
813 case WM_SYSVALUECHANGED:
814 case WM_CALCVALIDRECTS:
815 case WM_SETSELECTION:
816 case WM_PPAINT:
817 case WM_PSETFOCUS:
818 case WM_PSYSCOLORCHANGE:
819 case WM_PSIZE:
820 case WM_PACTIVATE:
821 case WM_PCONTROL:
822 case WM_HELP:
823 case WM_APPTERMINATENOTIFY:
824 case WM_PRESPARAMCHANGED:
825 case WM_DRAWITEM:
826 case WM_MEASUREITEM:
827 case WM_CONTROLPOINTER:
828 case WM_QUERYDLGCODE:
829 case WM_SUBSTITUTESTRING:
830 case WM_MATCHMNEMONIC:
831 case WM_SAVEAPPLICATION:
832 case WM_SEMANTICEVENT:
833 default:
834// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
835 RestoreOS2TIB();
836 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
837 }
838 RestoreOS2TIB();
839 return (MRESULT)FALSE;
840
841RunDefWndProc:
842// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
843 RestoreOS2TIB();
844 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
845} /* End of Win32WindowProc */
846//******************************************************************************
847//******************************************************************************
Note: See TracBrowser for help on using the repository browser.