source: trunk/src/user32/new/pmwindow.cpp@ 509

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

Client window mouse button messages improved.

File size: 18.0 KB
Line 
1/* $Id: pmwindow.cpp,v 1.18 1999-08-16 15:55:28 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 <wprocess.h>
20#include <misc.h>
21#include <win32wnd.h>
22#include <win32dlg.h>
23#include "pmwindow.h"
24#include "oslibwin.h"
25#include "oslibutil.h"
26#include "oslibgdi.h"
27#include "oslibmsg.h"
28
29HMQ hmq = 0; /* Message queue handle */
30HAB hab = 0;
31
32RECTL desktopRectl = {0};
33
34MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
35
36//******************************************************************************
37//Initialize PM; create hab, message queue and register special Win32 window classes
38//******************************************************************************
39BOOL InitPM()
40{
41 hab = WinInitialize(0);
42 dprintf(("Winitialize returned %x", hab));
43 hmq = WinCreateMsgQueue(hab, 0);
44
45 if(!hab || !hmq)
46 {
47 UINT error;
48 //CB: only fail on real error
49 error = WinGetLastError(hab) & 0xFFFF; //error code
50 if (!hab || error != PMERR_MSG_QUEUE_ALREADY_EXISTS)
51 {
52 dprintf(("WinInitialize or WinCreateMsgQueue failed %x %x", hab, hmq));
53 dprintf((" Error = %x",error));
54 return(FALSE);
55 }
56 else
57 {
58 if(!hab) {
59 hab = WinQueryAnchorBlock(HWND_DESKTOP);
60 dprintf(("WinQueryAnchorBlock returned %x", hab));
61 }
62 if(!hmq) {
63 hmq = HMQ_CURRENT;
64 }
65 }
66 }
67 SetThreadHAB(hab);
68 dprintf(("InitPM: hmq = %x", hmq));
69 SetThreadMessageQueue(hmq);
70
71 if(!WinRegisterClass( /* Register window class */
72 hab, /* Anchor block handle */
73 (PSZ)WIN32_STDCLASS, /* Window class name */
74 (PFNWP)Win32WindowProc, /* Address of window procedure */
75 CS_SIZEREDRAW | CS_HITTEST,
76 8)) {
77 dprintf(("WinRegisterClass Win32Window failed"));
78 return(FALSE);
79 }
80
81 WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
82 dprintf(("InitPM: Desktop (%d,%d)", desktopRectl.xRight, desktopRectl.yTop));
83 return OSLibInitMsgQueue();
84} /* End of main */
85//******************************************************************************
86//Win32 window message handler
87//******************************************************************************
88MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
89{
90 POSTMSG_PACKET *postmsg;
91 OSLIBPOINT point, ClientPoint;
92 Win32Window *win32wnd;
93 APIRET rc;
94
95 //Restore our FS selector
96 SetWin32TIB();
97
98 win32wnd = Win32Window::GetWindowFromOS2Handle(hwnd);
99
100 if(msg != WM_CREATE && win32wnd == NULL) {
101 dprintf(("Invalid win32wnd pointer for window %x!!", hwnd));
102 goto RunDefWndProc;
103 }
104 switch( msg )
105 {
106 //internal messages
107 case WM_WIN32_POSTMESSAGEA:
108 postmsg = (POSTMSG_PACKET *)mp1;
109 if(postmsg == NULL) {
110 dprintf(("WM_WIN32_POSTMESSAGEA, postmsg NULL!!"));
111 break;
112 }
113 win32wnd->SendMessageA(postmsg->Msg, postmsg->wParam, postmsg->lParam);
114 free(postmsg);
115 break;
116
117 case WM_WIN32_POSTMESSAGEW:
118 postmsg = (POSTMSG_PACKET *)mp1;
119 if(postmsg == NULL) {
120 dprintf(("WM_WIN32_POSTMESSAGEW, postmsg NULL!!"));
121 break;
122 }
123 win32wnd->SendMessageW(postmsg->Msg, postmsg->wParam, postmsg->lParam);
124 free(postmsg);
125 break;
126
127 //OS/2 msgs
128 case WM_CREATE:
129 //Processing is done in after WinCreateWindow returns
130 dprintf(("OS2: WM_CREATE %x", hwnd));
131 RestoreOS2TIB();
132 return (MRESULT)FALSE;
133
134 case WM_QUIT:
135 dprintf(("OS2: WM_QUIT %x", hwnd));
136 if(win32wnd->MsgQuit()) {
137 goto RunDefWndProc;
138 }
139 break;
140
141 case WM_CLOSE:
142 dprintf(("OS2: WM_CLOSE %x", hwnd));
143 if(win32wnd->MsgClose()) {
144 goto RunDefWndProc;
145 }
146 break;
147
148 case WM_DESTROY:
149 dprintf(("OS2: WM_DESTROY %x", hwnd));
150 if(win32wnd->MsgDestroy()) {
151 goto RunDefWndProc;
152 }
153 break;
154
155 case WM_ENABLE:
156 dprintf(("OS2: WM_ENABLE %x", hwnd));
157 if(win32wnd->MsgEnable((ULONG)mp1)) {
158 goto RunDefWndProc;
159 }
160 break;
161
162 case WM_SHOW:
163 dprintf(("OS2: WM_SHOW %x", hwnd));
164 if(win32wnd->MsgShow((ULONG)mp1)) {
165 goto RunDefWndProc;
166 }
167 break;
168
169 case WM_ADJUSTWINDOWPOS:
170 {
171 ULONG x, y;
172 PSWP pswp = (PSWP)mp1;
173
174 dprintf(("OS2: WM_ADJUSTWINDOWPOS %x", hwnd));
175
176 if(pswp->fl & SWP_MOVE) {
177 if(win32wnd->isChild()) {
178 x = pswp->x;
179 y = pswp->cy - y - 1;
180 }
181 else {
182 OSLIBPOINT point;
183
184 point.x = pswp->x;
185 point.y = pswp->y;
186
187 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
188 x = point.x;
189 y = point.y;
190 }
191 if(win32wnd->MsgMove(x, y)) {
192 goto RunDefWndProc;
193 }
194 break;
195 }
196 goto RunDefWndProc;
197 }
198
199 case WM_WINDOWPOSCHANGED:
200 {
201 PSWP pswp = (PSWP)mp1;
202
203 dprintf(("OS2: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
204 goto RunDefWndProc;
205 }
206
207 case WM_ERASEBACKGROUND:
208 {
209 HPS hps;
210
211 dprintf(("OS2: WM_ERASEBACKGROUND %x", hwnd));
212 hps = WinGetPS(hwnd);
213 if(!win32wnd->MsgEraseBackGround((ULONG)hps))
214 {
215 /*
216 * Return TRUE to request PM to paint the window background
217 * in SYSCLR_WINDOW.
218 */
219 WinReleasePS(hps);
220 return (MRESULT)( TRUE );
221 }
222 WinReleasePS(hps);
223 return (MRESULT) FALSE;
224 }
225 case WM_SIZE:
226 {
227 SWP swp;
228
229 rc = WinQueryWindowPos(hwnd, &swp);
230 if(rc == FALSE) {
231 dprintf(("WM_SIZE: WinQueryWindowPos failed!"));
232 break;
233 }
234 dprintf(("OS2: WM_SIZE %x %x (%d,%d) (%d,%d) (%d,%d)", hwnd, swp.fl, swp.x, swp.y, swp.cx, swp.cy, SHORT1FROMMP(mp2), SHORT2FROMMP(mp2)));
235 if(win32wnd->MsgSize(SHORT1FROMMP(mp2), SHORT2FROMMP(mp2),
236 (swp.fl & SWP_MINIMIZE) != 0,
237 (swp.fl & SWP_MAXIMIZE) != 0))
238 {
239 goto RunDefWndProc;
240 }
241 break;
242 }
243
244 case WM_ACTIVATE:
245 {
246 HWND hwndActivate = (HWND)mp1;
247
248 dprintf(("OS2: WM_ACTIVATE %x", hwnd));
249 if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
250 //another (non-win32) application's window
251 //set to NULL (allowed according to win32 SDK) to avoid problems
252 hwndActivate = NULL;
253 }
254 if(win32wnd->MsgActivate(1, hwndActivate)) {
255 goto RunDefWndProc;
256 }
257 break;
258 }
259 case WM_FOCUSCHANGE:
260 dprintf(("OS2: WM_FOCUSCHANGE %x", hwnd));
261 goto RunDefWndProc;
262
263 case WM_SETFOCUS:
264 {
265 HWND hwndFocus = (HWND)mp1;
266
267 dprintf(("OS2: WM_SETFOCUS %x %d", hwnd, mp2));
268 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
269 //another (non-win32) application's window
270 //set to NULL (allowed according to win32 SDK) to avoid problems
271 hwndFocus = NULL;
272 }
273 if((ULONG)mp2 == TRUE) {
274 rc = win32wnd->MsgSetFocus(hwndFocus);
275 }
276 else rc = win32wnd->MsgKillFocus(hwndFocus);
277 if(rc) {
278 goto RunDefWndProc;
279 }
280 break;
281 }
282 //**************************************************************************
283 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
284 //**************************************************************************
285 case WM_BUTTON1DOWN:
286 dprintf(("OS2: WM_BUTTON1DOWN %x", hwnd));
287 point.x = (*(POINTS *)&mp1).x;
288 point.y = (*(POINTS *)&mp1).y;
289 ClientPoint.x = point.x;
290 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
291 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
292 if(win32wnd->MsgButton(BUTTON_LEFTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
293 goto RunDefWndProc;
294 }
295 break;
296
297 case WM_BUTTON1UP:
298 dprintf(("OS2: WM_BUTTON1UP %x", hwnd));
299 point.x = (*(POINTS *)&mp1).x;
300 point.y = (*(POINTS *)&mp1).y;
301 ClientPoint.x = point.x;
302 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
303 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
304 if(win32wnd->MsgButton(BUTTON_LEFTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
305 goto RunDefWndProc;
306 }
307 break;
308 case WM_BUTTON1DBLCLK:
309 point.x = (*(POINTS *)&mp1).x;
310 point.y = (*(POINTS *)&mp1).y;
311 ClientPoint.x = point.x;
312 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
313 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
314 if(win32wnd->MsgButton(BUTTON_LEFTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
315 goto RunDefWndProc;
316 }
317 break;
318 case WM_BUTTON2DOWN:
319 point.x = (*(POINTS *)&mp1).x;
320 point.y = (*(POINTS *)&mp1).y;
321 ClientPoint.x = point.x;
322 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
323 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
324 if(win32wnd->MsgButton(BUTTON_RIGHTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
325 goto RunDefWndProc;
326 }
327 break;
328 case WM_BUTTON2UP:
329 point.x = (*(POINTS *)&mp1).x;
330 point.y = (*(POINTS *)&mp1).y;
331 ClientPoint.x = point.x;
332 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
333 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
334 if(win32wnd->MsgButton(BUTTON_RIGHTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
335 goto RunDefWndProc;
336 }
337 break;
338 case WM_BUTTON2DBLCLK:
339 point.x = (*(POINTS *)&mp1).x;
340 point.y = (*(POINTS *)&mp1).y;
341 ClientPoint.x = point.x;
342 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
343 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
344 if(win32wnd->MsgButton(BUTTON_RIGHTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
345 goto RunDefWndProc;
346 }
347 break;
348 case WM_BUTTON3DOWN:
349 point.x = (*(POINTS *)&mp1).x;
350 point.y = (*(POINTS *)&mp1).y;
351 ClientPoint.x = point.x;
352 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
353 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
354 if(win32wnd->MsgButton(BUTTON_MIDDLEDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
355 goto RunDefWndProc;
356 }
357 break;
358 case WM_BUTTON3UP:
359 point.x = (*(POINTS *)&mp1).x;
360 point.y = (*(POINTS *)&mp1).y;
361 ClientPoint.x = point.x;
362 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
363 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
364 if(win32wnd->MsgButton(BUTTON_MIDDLEUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
365 goto RunDefWndProc;
366 }
367 break;
368 case WM_BUTTON3DBLCLK:
369 point.x = (*(POINTS *)&mp1).x;
370 point.y = (*(POINTS *)&mp1).y;
371 ClientPoint.x = point.x;
372 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
373 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
374 if(win32wnd->MsgButton(BUTTON_MIDDLEDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
375 goto RunDefWndProc;
376 }
377 break;
378
379 case WM_BUTTON2MOTIONSTART:
380 case WM_BUTTON2MOTIONEND:
381 case WM_BUTTON2CLICK:
382 case WM_BUTTON1MOTIONSTART:
383 case WM_BUTTON1MOTIONEND:
384 case WM_BUTTON1CLICK:
385 case WM_BUTTON3MOTIONSTART:
386 case WM_BUTTON3MOTIONEND:
387 case WM_BUTTON3CLICK:
388 goto RunDefWndProc;
389
390 case WM_MOUSEMOVE:
391 {
392 ULONG keystate = 0;
393 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1))
394 keystate |= WMMOVE_LBUTTON;
395 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2))
396 keystate |= WMMOVE_MBUTTON;
397 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3))
398 keystate |= WMMOVE_RBUTTON;
399 if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT))
400 keystate |= WMMOVE_SHIFT;
401 if(WinGetKeyState(HWND_DESKTOP, VK_CTRL))
402 keystate |= WMMOVE_CTRL;
403
404 //OS/2 Window coordinates -> Win32 Window coordinates
405 //TODO: What do windows apps that handle this messages return?
406 if(!win32wnd->MsgMouseMove(keystate, SHORT1FROMMP(mp1), MapOS2ToWin32Y(win32wnd, SHORT2FROMMP(mp1)))) {
407 goto RunDefWndProc;
408 }
409 break;
410 }
411
412 //**************************************************************************
413 //Slider messages
414 //**************************************************************************
415 case WM_VSCROLL:
416 case WM_HSCROLL:
417
418 case WM_CONTROL:
419
420 case WM_COMMAND:
421 if(SHORT1FROMMP(mp2) == CMDSRC_MENU) {
422 win32wnd->MsgCommand(CMD_MENU, SHORT1FROMMP(mp1), 0);
423 }
424 if(SHORT1FROMMP(mp2) == CMDSRC_ACCELERATOR) {
425 win32wnd->MsgCommand(CMD_ACCELERATOR, SHORT1FROMMP(mp1), 0);
426 }
427 //todo controls + accelerators
428 break;
429
430 case WM_SYSCOMMAND:
431 {
432 ULONG x = 0, y = 0;
433 ULONG win32sc;
434
435 if(SHORT2FROMMP(mp2) == TRUE) {//syscommand caused by mouse action
436 POINTL pointl;
437 WinQueryPointerPos(HWND_DESKTOP, &pointl);
438 x = pointl.x;
439 y = desktopRectl.yTop - y;
440 }
441 switch(SHORT1FROMMP(mp1)) {
442 case SC_MOVE:
443 win32sc = WIN32SC_MOVE;
444 break;
445 case SC_CLOSE:
446 win32sc = WIN32SC_CLOSE;
447 break;
448 case SC_MAXIMIZE:
449 win32sc = WIN32SC_MAXIMIZE;
450 break;
451 case SC_MINIMIZE:
452 win32sc = WIN32SC_MINIMIZE;
453 break;
454 case SC_NEXTFRAME:
455 case SC_NEXTWINDOW:
456 win32sc = WIN32SC_NEXTWINDOW;
457 break;
458 case SC_RESTORE:
459 win32sc = WIN32SC_RESTORE;
460 break;
461 case SC_TASKMANAGER:
462 win32sc = WIN32SC_TASKLIST;
463 break;
464 default:
465 goto RunDefWndProc;
466 }
467 dprintf(("WM_SYSCOMMAND %x %x (%d,%d)", hwnd, win32sc, x, y));
468 if(win32wnd->MsgSysCommand(win32sc, x, y)) {
469 goto RunDefWndProc;
470 }
471 break;
472 }
473 case WM_CHAR:
474 {
475 ULONG keyflags = 0, vkey = 0;
476 ULONG fl = SHORT1FROMMP(mp1);
477
478 if(!(fl & KC_CHAR)) {
479 dprintf(("WM_CHAR: no valid character code"));
480 goto RunDefWndProc;
481 }
482 if(fl & KC_VIRTUALKEY) {
483 vkey = SHORT2FROMMP(mp2);
484 }
485 if(fl & KC_KEYUP) {
486 keyflags |= KEY_UP;
487 }
488 if(fl & KC_ALT) {
489 keyflags |= KEY_ALTDOWN;
490 }
491 if(fl & KC_PREVDOWN) {
492 keyflags |= KEY_PREVDOWN;
493 }
494 if(fl & KC_DEADKEY) {
495 keyflags |= KEY_DEADKEY;
496 }
497 if(win32wnd->MsgChar(SHORT1FROMMP(mp2), CHAR3FROMMP(mp1), CHAR4FROMMP(mp1), vkey, keyflags)) {
498 goto RunDefWndProc;
499 }
500 break;
501 }
502 case WM_INITMENU:
503 case WM_MENUSELECT:
504 case WM_MENUEND:
505 case WM_NEXTMENU:
506
507 case WM_TIMER:
508 goto RunDefWndProc;
509
510 case WM_SETWINDOWPARAMS:
511 {
512 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
513
514 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
515 if(wndParams->fsStatus & WPM_TEXT) {
516 if(win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText)) {
517 goto RunDefWndProc;
518 }
519 }
520 goto RunDefWndProc;
521 }
522
523 case WM_QUERYWINDOWPARAMS:
524 {
525 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
526 ULONG textlen;
527 PSZ wintext;
528
529 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT)) {
530 if(wndpars->fsStatus & WPM_CCHTEXT)
531 wndpars->cchText = win32wnd->MsgGetTextLength();
532 if(wndpars->fsStatus & WPM_TEXT)
533 wndpars->pszText = win32wnd->MsgGetText();
534 return (MRESULT)TRUE;
535 }
536 goto RunDefWndProc;
537 }
538
539 case WM_PAINT:
540 dprintf(("OS2: WM_PAINT %x", hwnd));
541 if(win32wnd->MsgPaint(0, 0)) {
542 goto RunDefWndProc;
543 }
544 break;
545
546 case WM_HITTEST:
547 if(win32wnd->MsgHitTest((*(POINTS *)&mp1).x, MapOS2ToWin32Y(OSLIB_HWND_DESKTOP, hwnd, (*(POINTS *)&mp1).y))) {
548 goto RunDefWndProc;
549 }
550 break;
551
552 case WM_SYSCOLORCHANGE:
553 case WM_SYSVALUECHANGED:
554 case WM_CALCVALIDRECTS:
555 case WM_SETSELECTION:
556 case WM_PPAINT:
557 case WM_PSETFOCUS:
558 case WM_PSYSCOLORCHANGE:
559 case WM_PSIZE:
560 case WM_PACTIVATE:
561 case WM_PCONTROL:
562 case WM_HELP:
563 case WM_APPTERMINATENOTIFY:
564 case WM_PRESPARAMCHANGED:
565 case WM_DRAWITEM:
566 case WM_MEASUREITEM:
567 case WM_CONTROLPOINTER:
568 case WM_QUERYDLGCODE:
569 case WM_SUBSTITUTESTRING:
570 case WM_MATCHMNEMONIC:
571 case WM_SAVEAPPLICATION:
572 case WM_SEMANTICEVENT:
573 default:
574// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
575 RestoreOS2TIB();
576 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
577 }
578 RestoreOS2TIB();
579 return (MRESULT)FALSE;
580
581RunDefWndProc:
582// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
583 RestoreOS2TIB();
584 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
585} /* End of Win32WindowProc */
586//******************************************************************************
587//******************************************************************************
Note: See TracBrowser for help on using the repository browser.