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

Last change on this file since 3603 was 3603, checked in by sandervl, 25 years ago

experimental WM_NCHITTEST generation (disabled) + MDI fixes

File size: 15.0 KB
Line 
1/* $Id: pmwindow.cpp,v 1.91 2000-05-24 19:30:06 sandervl 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#define INCL_DEV /* Device Function definitions */
15#define INCL_GPICONTROL /* GPI control Functions */
16#define INCL_DOSPROCESS
17
18#include <os2wrap.h>
19#include <stdlib.h>
20#include <string.h>
21#include <win32type.h>
22#include <winconst.h>
23#include <wprocess.h>
24#include <misc.h>
25#include <win32wbase.h>
26#include <win32dlg.h>
27#include "win32wdesktop.h"
28#include "pmwindow.h"
29#include "oslibwin.h"
30#include "oslibutil.h"
31#include "oslibgdi.h"
32#include "oslibmsg.h"
33#include "dc.h"
34#include <thread.h>
35#include <wprocess.h>
36#include "caret.h"
37#include "timer.h"
38#include <codepage.h>
39
40#define DBG_LOCALLOG DBG_pmwindow
41#include "dbglocal.h"
42
43HMQ hmq = 0; /* Message queue handle */
44HAB hab = 0;
45
46RECTL desktopRectl = {0};
47ULONG ScreenWidth = 0;
48ULONG ScreenHeight = 0;
49ULONG ScreenBitsPerPel = 0;
50
51
52MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
53
54//******************************************************************************
55//Initialize PM; create hab, message queue and register special Win32 window classes
56//******************************************************************************
57BOOL InitPM()
58{
59 CLASSINFO FrameClassInfo;
60
61 hab = WinInitialize(0);
62 dprintf(("Winitialize returned %x", hab));
63 hmq = WinCreateMsgQueue(hab, 0);
64
65 if(!hab || !hmq)
66 {
67 UINT error;
68 //CB: only fail on real error
69 error = WinGetLastError(hab) & 0xFFFF; //error code
70 if (!hab || (error != PMERR_MSG_QUEUE_ALREADY_EXISTS))
71 {
72 dprintf(("WinInitialize or WinCreateMsgQueue failed %x %x", hab, hmq));
73 dprintf((" Error = %x",error));
74 return(FALSE);
75 }
76 else
77 {
78 if(!hab) {
79 hab = WinQueryAnchorBlock(HWND_DESKTOP);
80 dprintf(("WinQueryAnchorBlock returned %x", hab));
81 }
82 if(!hmq) {
83 hmq = HMQ_CURRENT;
84 }
85 }
86 }
87 SetThreadHAB(hab);
88 dprintf(("InitPM: hmq = %x", hmq));
89 SetThreadMessageQueue(hmq);
90
91 BOOL rc = WinSetCp(hmq, GetDisplayCodepage());
92 dprintf(("InitPM: WinSetCP was %sOK", rc ? "" : "not "));
93
94 if(!WinRegisterClass( /* Register window class */
95 hab, /* Anchor block handle */
96 (PSZ)WIN32_STDCLASS, /* Window class name */
97 (PFNWP)Win32WindowProc, /* Address of window procedure */
98#ifdef ODIN_HITTEST
99 0,
100#else
101 CS_HITTEST,
102#endif
103 NROF_WIN32WNDBYTES)) {
104 dprintf(("WinRegisterClass Win32BaseWindow failed"));
105 return(FALSE);
106 }
107 if(!WinRegisterClass( /* Register window class */
108 hab, /* Anchor block handle */
109 (PSZ)WIN32_STDCLASS2, /* Window class name */
110 (PFNWP)Win32WindowProc, /* Address of window procedure */
111#ifdef ODIN_HITTEST
112 CS_SAVEBITS,
113#else
114 CS_SAVEBITS | CS_HITTEST,
115#endif
116 NROF_WIN32WNDBYTES)) {
117 dprintf(("WinRegisterClass Win32BaseWindow failed"));
118 return(FALSE);
119 }
120 if (!WinQueryClassInfo (hab, WC_FRAME, &FrameClassInfo)) {
121 dprintf (("WinQueryClassInfo WC_FRAME failed"));
122 return (FALSE);
123 }
124 FrameClassInfo.flClassStyle &= ~(CS_PUBLIC | CS_CLIPSIBLINGS);
125 if (!WinRegisterClass (hab,
126 WIN32_INNERFRAME,
127 FrameClassInfo.pfnWindowProc,
128#ifdef ODIN_HITTEST
129 FrameClassInfo.flClassStyle,
130#else
131 FrameClassInfo.flClassStyle | CS_HITTEST,
132#endif
133 FrameClassInfo.cbWindowData)) {
134 dprintf (("WinRegisterClass Win32InnerFrame failed"));
135 return (FALSE);
136 }
137
138 WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
139 ScreenWidth = desktopRectl.xRight;
140 ScreenHeight = desktopRectl.yTop;
141
142
143 HDC hdc; /* Device-context handle */
144 /* context data structure */
145 DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL,
146 NULL, NULL, NULL};
147
148 /* create memory device context */
149 hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
150 DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1, (PLONG)&ScreenBitsPerPel);
151 DevCloseDC(hdc);
152
153 dprintf(("InitPM: Desktop (%d,%d)", ScreenWidth, ScreenHeight));
154 return TRUE;
155} /* End of main */
156//******************************************************************************
157//Win32 window message handler
158//******************************************************************************
159MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
160{
161 POSTMSG_PACKET *postmsg;
162 OSLIBPOINT point, ClientPoint;
163 Win32BaseWindow *win32wnd;
164 THDB *thdb;
165 APIRET rc = 0;
166 MSG winMsg, *pWinMsg;
167
168 //Restore our FS selector
169 SetWin32TIB();
170
171 thdb = GetThreadTHDB();
172 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
173
174 if(!thdb || (msg != WM_CREATE && win32wnd == NULL)) {
175 dprintf(("Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
176 goto RunDefWndProc;
177 }
178
179 if((thdb->msgstate & 1) == 0)
180 {//message that was sent directly to our window proc handler; translate it here
181 QMSG qmsg;
182
183 qmsg.msg = msg;
184 qmsg.hwnd = hwnd;
185 qmsg.mp1 = mp1;
186 qmsg.mp2 = mp2;
187 qmsg.time = WinQueryMsgTime(thdb->hab);
188 WinQueryMsgPos(thdb->hab, &qmsg.ptl);
189 qmsg.reserved = 0;
190
191 if(OS2ToWinMsgTranslate((PVOID)thdb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
192 {//message was not translated
193 memset(&winMsg, 0, sizeof(MSG));
194 }
195 pWinMsg = &winMsg;
196 }
197 else {
198 pWinMsg = &thdb->msg;
199 thdb->msgstate++;
200 }
201
202 if(msg == WIN32APP_POSTMSG) {
203 //probably win32 app user message
204 if((ULONG)mp1 == WIN32MSG_MAGICA) {
205 return (MRESULT)win32wnd->DispatchMsgA(pWinMsg);
206 }
207 else
208 if((ULONG)mp1 == WIN32MSG_MAGICW) {
209 return (MRESULT)win32wnd->DispatchMsgW(pWinMsg);
210 }
211 }
212 switch( msg )
213 {
214 //OS/2 msgs
215 case WM_CREATE:
216 {
217
218 if(thdb->newWindow == 0)
219 goto createfail;
220
221 //Processing is done in after WinCreateWindow returns
222 dprintf(("OS2: WM_CREATE %x", hwnd));
223 win32wnd = (Win32BaseWindow *)thdb->newWindow;
224 thdb->newWindow = 0;
225
226 if(win32wnd->MsgCreate(WinQueryWindow(hwnd, QW_PARENT), hwnd) == FALSE)
227 {
228 RestoreOS2TIB();
229 return (MRESULT)TRUE; //discontinue window creation
230 }
231 createfail:
232 RestoreOS2TIB();
233 return (MRESULT)FALSE;
234 }
235
236 case WM_QUIT:
237 dprintf(("OS2: WM_QUIT %x", hwnd));
238 win32wnd->MsgQuit();
239 break;
240
241 case WM_CLOSE:
242 dprintf(("OS2: WM_CLOSE %x", hwnd));
243 win32wnd->MsgClose();
244 break;
245
246 case WM_DESTROY:
247 dprintf(("OS2: WM_DESTROY %x", hwnd));
248 win32wnd->MsgDestroy();
249 break;
250
251 case WM_ENABLE:
252 dprintf(("OS2: WM_ENABLE %x", hwnd));
253 win32wnd->MsgEnable(SHORT1FROMMP(mp1));
254 break;
255
256 case WM_SHOW:
257 dprintf(("OS2: WM_SHOW %x %d", hwnd, mp1));
258 win32wnd->MsgShow((ULONG)mp1);
259 break;
260
261 case WM_ADJUSTWINDOWPOS:
262 {
263 PSWP pswp = (PSWP)mp1;
264 dprintf(("PMWINDOW: WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
265 goto RunDefWndProc;
266 }
267
268 case WM_WINDOWPOSCHANGED:
269 {
270 if(pWinMsg->message != 0)
271 win32wnd->MsgPosChanged((LPARAM)&thdb->wp);
272 goto RunDefWndProc;
273 }
274
275 case WM_ACTIVATE:
276 {
277 dprintf(("OS2: WM_ACTIVATE %x %x %x", hwnd, mp1, mp2));
278
279 if(win32wnd->IsWindowCreated())
280 win32wnd->MsgActivate((LOWORD(pWinMsg->wParam) == WA_ACTIVE_W) ? 1 : 0, HIWORD(pWinMsg->wParam), pWinMsg->lParam, (HWND)mp2);
281
282 break;
283 }
284
285 case WM_SIZE:
286 {
287 dprintf(("OS2: WM_SIZE (%d,%d) (%d,%d)", SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), SHORT1FROMMP(mp1), SHORT2FROMMP(mp2)));
288 break;
289 }
290
291 case WM_MINMAXFRAME:
292 {
293 dprintf(("OS2: WM_MINMAXFRAME"));
294 break;
295 }
296
297 case WM_OWNERPOSCHANGE:
298 {
299 dprintf(("OS2: WM_OWNERPOSCHANGE"));
300 goto RunDefWndProc;
301 }
302
303 case WM_CALCVALIDRECTS:
304#if 0
305 {
306 PRECTL oldRect = (PRECTL)mp1,newRect = oldRect+1;
307 UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
308
309//CB: todo: use WM_NCCALCSIZE result
310 if (win32wnd->getWindowClass())
311 {
312 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
313
314 if ((dwStyle & CS_HREDRAW_W) && (newRect->xRight-newRect->xLeft != oldRect->xRight-oldRect->xLeft))
315 res |= CVR_REDRAW;
316 else if ((dwStyle & CS_VREDRAW_W) && (newRect->yTop-newRect->yBottom != oldRect->yTop-oldRect->yBottom))
317 res |= CVR_REDRAW;
318 } else res |= CVR_REDRAW;
319
320 RestoreOS2TIB();
321 return (MRESULT)res;
322 }
323#else
324 dprintf(("PMWINDOW: WM_CALCVALIDRECTS"));
325 RestoreOS2TIB();
326 return (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
327#endif
328
329 case WM_SETFOCUS:
330 {
331 HWND hwndFocus = (HWND)mp1;
332
333 dprintf(("OS2: WM_SETFOCUS %x %x %d", win32wnd->getWindowHandle(), mp1, mp2));
334 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
335 //another (non-win32) application's window
336 //set to NULL (allowed according to win32 SDK) to avoid problems
337 hwndFocus = NULL;
338 }
339 if((ULONG)mp2 == TRUE) {
340 HWND hwndFocusWin32 = Win32BaseWindow::OS2ToWin32Handle(hwndFocus);
341 recreateCaret (hwndFocusWin32);
342 win32wnd->MsgSetFocus(hwndFocusWin32);
343 }
344 else win32wnd->MsgKillFocus(Win32BaseWindow::OS2ToWin32Handle(hwndFocus));
345 break;
346 }
347
348 //**************************************************************************
349 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
350 //**************************************************************************
351 case WM_HITTEST:
352 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
353 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
354 }
355 if(win32wnd)
356 rc = win32wnd->MsgHitTest(pWinMsg);
357 break;
358
359
360 case WM_BUTTON1DOWN:
361 case WM_BUTTON1UP:
362 case WM_BUTTON1DBLCLK:
363 case WM_BUTTON2DOWN:
364 case WM_BUTTON2UP:
365 case WM_BUTTON2DBLCLK:
366 case WM_BUTTON3DOWN:
367 case WM_BUTTON3UP:
368 case WM_BUTTON3DBLCLK:
369 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
370 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
371 }
372 if(win32wnd)
373 win32wnd->MsgButton(pWinMsg);
374 rc = TRUE;
375 break;
376
377 case WM_BUTTON2MOTIONSTART:
378 case WM_BUTTON2MOTIONEND:
379 case WM_BUTTON2CLICK:
380 case WM_BUTTON1MOTIONSTART:
381 case WM_BUTTON1MOTIONEND:
382 case WM_BUTTON1CLICK:
383 case WM_BUTTON3MOTIONSTART:
384 case WM_BUTTON3MOTIONEND:
385 case WM_BUTTON3CLICK:
386 rc = TRUE;
387 break;
388
389 case WM_MOUSEMOVE:
390 {
391 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
392 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
393 }
394 if(win32wnd)
395 win32wnd->MsgMouseMove(pWinMsg);
396 break;
397 }
398
399 case WM_CONTROL:
400 goto RunDefWndProc;
401
402 case WM_COMMAND:
403 dprintf(("OS2: WM_COMMAND %x %x %x", hwnd, mp1, mp2));
404 win32wnd->DispatchMsgA(pWinMsg);
405 break;
406
407 case WM_SYSCOMMAND:
408 win32wnd->DispatchMsgA(pWinMsg);
409 break;
410
411 case WM_CHAR:
412 win32wnd->MsgChar(pWinMsg);
413 break;
414
415 case WM_TIMER:
416 win32wnd->DispatchMsgA(pWinMsg);
417 goto RunDefWndProc;
418
419 case WM_SETWINDOWPARAMS:
420 {
421 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
422
423 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
424 if(wndParams->fsStatus & WPM_TEXT) {
425 win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText);
426 }
427 goto RunDefWndProc;
428 }
429
430 case WM_QUERYWINDOWPARAMS:
431 {
432 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
433 ULONG textlen;
434 PSZ wintext;
435
436 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
437 {
438 if(wndpars->fsStatus & WPM_TEXT)
439 win32wnd->MsgGetText(wndpars->pszText, wndpars->cchText);
440 if(wndpars->fsStatus & WPM_CCHTEXT)
441 wndpars->cchText = win32wnd->MsgGetTextLength();
442
443 wndpars->fsStatus = 0;
444 wndpars->cbCtlData = 0;
445 wndpars->cbPresParams = 0;
446 RestoreOS2TIB();
447 return (MRESULT)TRUE;
448 }
449 goto RunDefWndProc;
450 }
451
452 case WM_PAINT:
453 {
454// RECTL rectl;
455
456 dprintf(("OS2: WM_PAINT"));
457 win32wnd->DispatchMsgA(pWinMsg);
458 //SvL: Not calling the default window procedure causes all sorts of
459 // strange problems (redraw & hanging app)
460// WinQueryUpdateRect(hwnd, &rectl);
461// if(rectl.xLeft == 0 && rectl.yTop == 0 && rectl.xRight == 0 && rectl.yBottom == 0) {
462// RestoreOS2TIB();
463// return (MRESULT)FALSE;
464// }
465// dprintf(("Update rectangle (%d,%d)(%d,%d) not empty, msg %x", rectl.xLeft, rectl.yTop, rectl.xRight, rectl.yBottom, pWinMsg->message));
466 goto RunDefWndProc;
467 }
468
469 case WM_CONTEXTMENU:
470 {
471 win32wnd->DispatchMsgA(pWinMsg);
472
473 RestoreOS2TIB();
474 return (MRESULT)TRUE;
475 }
476
477 case WM_ERASEBACKGROUND:
478 {
479 dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
480 RestoreOS2TIB();
481 return (MRESULT)FALSE;
482 }
483
484 case WM_FOCUSCHANGE:
485 dprintf(("OS2: WM_FOCUSCHANGE %x", win32wnd->getWindowHandle()));
486 goto RunDefWndProc;
487
488 case WM_INITMENU:
489 case WM_MENUSELECT:
490 case WM_MENUEND:
491 case WM_NEXTMENU:
492 case WM_SYSCOLORCHANGE:
493 case WM_SYSVALUECHANGED:
494 case WM_SETSELECTION:
495 case WM_PPAINT:
496 case WM_PSETFOCUS:
497 case WM_PSYSCOLORCHANGE:
498 case WM_PSIZE:
499 case WM_PACTIVATE:
500 case WM_PCONTROL:
501 case WM_HELP:
502 case WM_APPTERMINATENOTIFY:
503 case WM_PRESPARAMCHANGED:
504 case WM_DRAWITEM:
505 case WM_MEASUREITEM:
506 case WM_CONTROLPOINTER:
507 case WM_QUERYDLGCODE:
508 case WM_SUBSTITUTESTRING:
509 case WM_MATCHMNEMONIC:
510 case WM_SAVEAPPLICATION:
511 case WM_SEMANTICEVENT:
512 default:
513 //dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
514 RestoreOS2TIB();
515 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
516 }
517 RestoreOS2TIB();
518 return (MRESULT)rc;
519
520RunDefWndProc:
521// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
522 RestoreOS2TIB();
523
524 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
525} /* End of Win32WindowProc */
526//******************************************************************************
527//******************************************************************************
Note: See TracBrowser for help on using the repository browser.