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

Last change on this file since 395 was 395, checked in by sandervl, 26 years ago

* empty log message *

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