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

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

WM_ERASEBKGND sent from BeginPaint now

File size: 14.9 KB
Line 
1/* $Id: pmwindow.cpp,v 1.20 1999-08-23 15:34:46 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 return (MRESULT) FALSE;
210 }
211 case WM_SIZE:
212 {
213 SWP swp;
214
215 rc = WinQueryWindowPos(hwnd, &swp);
216 if(rc == FALSE) {
217 dprintf(("WM_SIZE: WinQueryWindowPos failed!"));
218 break;
219 }
220 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)));
221 if(win32wnd->MsgSize(SHORT1FROMMP(mp2), SHORT2FROMMP(mp2),
222 (swp.fl & SWP_MINIMIZE) != 0,
223 (swp.fl & SWP_MAXIMIZE) != 0))
224 {
225 goto RunDefWndProc;
226 }
227 break;
228 }
229
230 case WM_ACTIVATE:
231 {
232 HWND hwndActivate = (HWND)mp1;
233
234 dprintf(("OS2: WM_ACTIVATE %x", hwnd));
235 if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
236 //another (non-win32) application's window
237 //set to NULL (allowed according to win32 SDK) to avoid problems
238 hwndActivate = NULL;
239 }
240 if(win32wnd->MsgActivate(1, hwndActivate)) {
241 goto RunDefWndProc;
242 }
243 break;
244 }
245 case WM_FOCUSCHANGE:
246 dprintf(("OS2: WM_FOCUSCHANGE %x", hwnd));
247 goto RunDefWndProc;
248
249 case WM_SETFOCUS:
250 {
251 HWND hwndFocus = (HWND)mp1;
252
253 dprintf(("OS2: WM_SETFOCUS %x %d", hwnd, mp2));
254 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
255 //another (non-win32) application's window
256 //set to NULL (allowed according to win32 SDK) to avoid problems
257 hwndFocus = NULL;
258 }
259 if((ULONG)mp2 == TRUE) {
260 rc = win32wnd->MsgSetFocus(hwndFocus);
261 }
262 else rc = win32wnd->MsgKillFocus(hwndFocus);
263 if(rc) {
264 goto RunDefWndProc;
265 }
266 break;
267 }
268 //**************************************************************************
269 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
270 //**************************************************************************
271 case WM_BUTTON1DOWN:
272 dprintf(("OS2: WM_BUTTON1DOWN %x", hwnd));
273 point.x = (*(POINTS *)&mp1).x;
274 point.y = (*(POINTS *)&mp1).y;
275 ClientPoint.x = point.x;
276 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
277 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
278 if(win32wnd->MsgButton(BUTTON_LEFTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
279 goto RunDefWndProc;
280 }
281 break;
282
283 case WM_BUTTON1UP:
284 dprintf(("OS2: WM_BUTTON1UP %x", hwnd));
285 point.x = (*(POINTS *)&mp1).x;
286 point.y = (*(POINTS *)&mp1).y;
287 ClientPoint.x = point.x;
288 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
289 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
290 if(win32wnd->MsgButton(BUTTON_LEFTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
291 goto RunDefWndProc;
292 }
293 break;
294 case WM_BUTTON1DBLCLK:
295 point.x = (*(POINTS *)&mp1).x;
296 point.y = (*(POINTS *)&mp1).y;
297 ClientPoint.x = point.x;
298 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
299 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
300 if(win32wnd->MsgButton(BUTTON_LEFTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
301 goto RunDefWndProc;
302 }
303 break;
304 case WM_BUTTON2DOWN:
305 point.x = (*(POINTS *)&mp1).x;
306 point.y = (*(POINTS *)&mp1).y;
307 ClientPoint.x = point.x;
308 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
309 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
310 if(win32wnd->MsgButton(BUTTON_RIGHTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
311 goto RunDefWndProc;
312 }
313 break;
314 case WM_BUTTON2UP:
315 point.x = (*(POINTS *)&mp1).x;
316 point.y = (*(POINTS *)&mp1).y;
317 ClientPoint.x = point.x;
318 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
319 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
320 if(win32wnd->MsgButton(BUTTON_RIGHTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
321 goto RunDefWndProc;
322 }
323 break;
324 case WM_BUTTON2DBLCLK:
325 point.x = (*(POINTS *)&mp1).x;
326 point.y = (*(POINTS *)&mp1).y;
327 ClientPoint.x = point.x;
328 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
329 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
330 if(win32wnd->MsgButton(BUTTON_RIGHTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
331 goto RunDefWndProc;
332 }
333 break;
334 case WM_BUTTON3DOWN:
335 point.x = (*(POINTS *)&mp1).x;
336 point.y = (*(POINTS *)&mp1).y;
337 ClientPoint.x = point.x;
338 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
339 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
340 if(win32wnd->MsgButton(BUTTON_MIDDLEDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
341 goto RunDefWndProc;
342 }
343 break;
344 case WM_BUTTON3UP:
345 point.x = (*(POINTS *)&mp1).x;
346 point.y = (*(POINTS *)&mp1).y;
347 ClientPoint.x = point.x;
348 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
349 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
350 if(win32wnd->MsgButton(BUTTON_MIDDLEUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
351 goto RunDefWndProc;
352 }
353 break;
354 case WM_BUTTON3DBLCLK:
355 point.x = (*(POINTS *)&mp1).x;
356 point.y = (*(POINTS *)&mp1).y;
357 ClientPoint.x = point.x;
358 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
359 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
360 if(win32wnd->MsgButton(BUTTON_MIDDLEDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
361 goto RunDefWndProc;
362 }
363 break;
364
365 case WM_BUTTON2MOTIONSTART:
366 case WM_BUTTON2MOTIONEND:
367 case WM_BUTTON2CLICK:
368 case WM_BUTTON1MOTIONSTART:
369 case WM_BUTTON1MOTIONEND:
370 case WM_BUTTON1CLICK:
371 case WM_BUTTON3MOTIONSTART:
372 case WM_BUTTON3MOTIONEND:
373 case WM_BUTTON3CLICK:
374 goto RunDefWndProc;
375
376 case WM_MOUSEMOVE:
377 {
378 ULONG keystate = 0;
379 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1))
380 keystate |= WMMOVE_LBUTTON;
381 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2))
382 keystate |= WMMOVE_MBUTTON;
383 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3))
384 keystate |= WMMOVE_RBUTTON;
385 if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT))
386 keystate |= WMMOVE_SHIFT;
387 if(WinGetKeyState(HWND_DESKTOP, VK_CTRL))
388 keystate |= WMMOVE_CTRL;
389
390 //OS/2 Window coordinates -> Win32 Window coordinates
391 //TODO: What do windows apps that handle this messages return?
392 if(!win32wnd->MsgMouseMove(keystate, SHORT1FROMMP(mp1), MapOS2ToWin32Y(win32wnd, SHORT2FROMMP(mp1)))) {
393 goto RunDefWndProc;
394 }
395 break;
396 }
397
398 //**************************************************************************
399 //Slider messages
400 //**************************************************************************
401 case WM_VSCROLL:
402 case WM_HSCROLL:
403
404 case WM_CONTROL:
405
406 case WM_COMMAND:
407 if(SHORT1FROMMP(mp2) == CMDSRC_MENU) {
408 win32wnd->MsgCommand(CMD_MENU, SHORT1FROMMP(mp1), 0);
409 }
410 if(SHORT1FROMMP(mp2) == CMDSRC_ACCELERATOR) {
411 win32wnd->MsgCommand(CMD_ACCELERATOR, SHORT1FROMMP(mp1), 0);
412 }
413 //todo controls + accelerators
414 break;
415
416 case WM_SYSCOMMAND:
417 {
418 ULONG x = 0, y = 0;
419 ULONG win32sc;
420
421 if(SHORT2FROMMP(mp2) == TRUE) {//syscommand caused by mouse action
422 POINTL pointl;
423 WinQueryPointerPos(HWND_DESKTOP, &pointl);
424 x = pointl.x;
425 y = desktopRectl.yTop - y;
426 }
427 switch(SHORT1FROMMP(mp1)) {
428 case SC_MOVE:
429 win32sc = WIN32SC_MOVE;
430 break;
431 case SC_CLOSE:
432 win32sc = WIN32SC_CLOSE;
433 break;
434 case SC_MAXIMIZE:
435 win32sc = WIN32SC_MAXIMIZE;
436 break;
437 case SC_MINIMIZE:
438 win32sc = WIN32SC_MINIMIZE;
439 break;
440 case SC_NEXTFRAME:
441 case SC_NEXTWINDOW:
442 win32sc = WIN32SC_NEXTWINDOW;
443 break;
444 case SC_RESTORE:
445 win32sc = WIN32SC_RESTORE;
446 break;
447 case SC_TASKMANAGER:
448 win32sc = WIN32SC_TASKLIST;
449 break;
450 default:
451 goto RunDefWndProc;
452 }
453 dprintf(("WM_SYSCOMMAND %x %x (%d,%d)", hwnd, win32sc, x, y));
454 if(win32wnd->MsgSysCommand(win32sc, x, y)) {
455 goto RunDefWndProc;
456 }
457 break;
458 }
459 case WM_CHAR:
460 {
461 ULONG keyflags = 0, vkey = 0;
462 ULONG fl = SHORT1FROMMP(mp1);
463
464 if(!(fl & KC_CHAR)) {
465 dprintf(("WM_CHAR: no valid character code"));
466 goto RunDefWndProc;
467 }
468 if(fl & KC_VIRTUALKEY) {
469 vkey = SHORT2FROMMP(mp2);
470 }
471 if(fl & KC_KEYUP) {
472 keyflags |= KEY_UP;
473 }
474 if(fl & KC_ALT) {
475 keyflags |= KEY_ALTDOWN;
476 }
477 if(fl & KC_PREVDOWN) {
478 keyflags |= KEY_PREVDOWN;
479 }
480 if(fl & KC_DEADKEY) {
481 keyflags |= KEY_DEADKEY;
482 }
483 if(win32wnd->MsgChar(SHORT1FROMMP(mp2), CHAR3FROMMP(mp1), CHAR4FROMMP(mp1), vkey, keyflags)) {
484 goto RunDefWndProc;
485 }
486 break;
487 }
488 case WM_INITMENU:
489 case WM_MENUSELECT:
490 case WM_MENUEND:
491 case WM_NEXTMENU:
492
493 case WM_TIMER:
494 goto RunDefWndProc;
495
496 case WM_SETWINDOWPARAMS:
497 {
498 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
499
500 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
501 if(wndParams->fsStatus & WPM_TEXT) {
502 if(win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText)) {
503 goto RunDefWndProc;
504 }
505 }
506 goto RunDefWndProc;
507 }
508
509 case WM_QUERYWINDOWPARAMS:
510 {
511 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
512 ULONG textlen;
513 PSZ wintext;
514
515 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT)) {
516 if(wndpars->fsStatus & WPM_CCHTEXT)
517 wndpars->cchText = win32wnd->MsgGetTextLength();
518 if(wndpars->fsStatus & WPM_TEXT)
519 wndpars->pszText = win32wnd->MsgGetText();
520 return (MRESULT)TRUE;
521 }
522 goto RunDefWndProc;
523 }
524
525 case WM_PAINT:
526 dprintf(("OS2: WM_PAINT %x", hwnd));
527 if(win32wnd->MsgPaint(0, 0)) {
528 goto RunDefWndProc;
529 }
530 break;
531
532 case WM_HITTEST:
533 if(win32wnd->MsgHitTest((*(POINTS *)&mp1).x, MapOS2ToWin32Y(OSLIB_HWND_DESKTOP, hwnd, (*(POINTS *)&mp1).y))) {
534 goto RunDefWndProc;
535 }
536 break;
537
538 case WM_SYSCOLORCHANGE:
539 case WM_SYSVALUECHANGED:
540 case WM_CALCVALIDRECTS:
541 case WM_SETSELECTION:
542 case WM_PPAINT:
543 case WM_PSETFOCUS:
544 case WM_PSYSCOLORCHANGE:
545 case WM_PSIZE:
546 case WM_PACTIVATE:
547 case WM_PCONTROL:
548 case WM_HELP:
549 case WM_APPTERMINATENOTIFY:
550 case WM_PRESPARAMCHANGED:
551 case WM_DRAWITEM:
552 case WM_MEASUREITEM:
553 case WM_CONTROLPOINTER:
554 case WM_QUERYDLGCODE:
555 case WM_SUBSTITUTESTRING:
556 case WM_MATCHMNEMONIC:
557 case WM_SAVEAPPLICATION:
558 case WM_SEMANTICEVENT:
559 default:
560// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
561 RestoreOS2TIB();
562 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
563 }
564 RestoreOS2TIB();
565 return (MRESULT)FALSE;
566
567RunDefWndProc:
568// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
569 RestoreOS2TIB();
570 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
571} /* End of Win32WindowProc */
572//******************************************************************************
573//******************************************************************************
Note: See TracBrowser for help on using the repository browser.