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

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

Added new logging feature

File size: 13.8 KB
Line 
1/* $Id: pmwindow.cpp,v 1.85 2000-02-16 14:34:31 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 0,
99 NROF_WIN32WNDBYTES)) {
100 dprintf(("WinRegisterClass Win32BaseWindow failed"));
101 return(FALSE);
102 }
103 if(!WinRegisterClass( /* Register window class */
104 hab, /* Anchor block handle */
105 (PSZ)WIN32_STDCLASS2, /* Window class name */
106 (PFNWP)Win32WindowProc, /* Address of window procedure */
107 CS_SAVEBITS,
108 NROF_WIN32WNDBYTES)) {
109 dprintf(("WinRegisterClass Win32BaseWindow failed"));
110 return(FALSE);
111 }
112 if (!WinQueryClassInfo (hab, WC_FRAME, &FrameClassInfo)) {
113 dprintf (("WinQueryClassInfo WC_FRAME failed"));
114 return (FALSE);
115 }
116 FrameClassInfo.flClassStyle &= ~(CS_PUBLIC | CS_CLIPSIBLINGS);
117 if (!WinRegisterClass (hab,
118 WIN32_INNERFRAME,
119 FrameClassInfo.pfnWindowProc,
120 FrameClassInfo.flClassStyle,
121 FrameClassInfo.cbWindowData)) {
122 dprintf (("WinRegisterClass Win32InnerFrame failed"));
123 return (FALSE);
124 }
125
126 WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
127 ScreenWidth = desktopRectl.xRight;
128 ScreenHeight = desktopRectl.yTop;
129
130
131 HDC hdc; /* Device-context handle */
132 /* context data structure */
133 DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL,
134 NULL, NULL, NULL};
135
136 /* create memory device context */
137 hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
138 DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1, (PLONG)&ScreenBitsPerPel);
139 DevCloseDC(hdc);
140
141 dprintf(("InitPM: Desktop (%d,%d)", ScreenWidth, ScreenHeight));
142 return OSLibInitMsgQueue();
143} /* End of main */
144//******************************************************************************
145//Win32 window message handler
146//******************************************************************************
147MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
148{
149 POSTMSG_PACKET *postmsg;
150 OSLIBPOINT point, ClientPoint;
151 Win32BaseWindow *win32wnd;
152 THDB *thdb;
153 APIRET rc = 0;
154 MSG winMsg, *pWinMsg;
155
156 //Restore our FS selector
157 SetWin32TIB();
158
159 thdb = GetThreadTHDB();
160 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
161
162 if(!thdb || (msg != WM_CREATE && win32wnd == NULL)) {
163 dprintf(("Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
164 goto RunDefWndProc;
165 }
166
167 if((thdb->msgstate & 1) == 0)
168 {//message that was sent directly to our window proc handler; translate it here
169 QMSG qmsg;
170
171 qmsg.msg = msg;
172 qmsg.hwnd = hwnd;
173 qmsg.mp1 = mp1;
174 qmsg.mp2 = mp2;
175 qmsg.time = WinQueryMsgTime(thdb->hab);
176 WinQueryMsgPos(thdb->hab, &qmsg.ptl);
177 qmsg.reserved = 0;
178
179 if(OS2ToWinMsgTranslate((PVOID)thdb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
180 {//message was not translated
181 memset(&winMsg, 0, sizeof(MSG));
182 }
183 pWinMsg = &winMsg;
184 }
185 else {
186 pWinMsg = &thdb->msg;
187 thdb->msgstate++;
188 }
189
190 if(msg == WIN32APP_POSTMSG) {
191 //probably win32 app user message
192 if((ULONG)mp1 == WIN32MSG_MAGICA) {
193 return (MRESULT)win32wnd->DispatchMsgA(pWinMsg);
194 }
195 else
196 if((ULONG)mp1 == WIN32MSG_MAGICW) {
197 return (MRESULT)win32wnd->DispatchMsgW(pWinMsg);
198 }
199 }
200 switch( msg )
201 {
202 //OS/2 msgs
203 case WM_CREATE:
204 {
205
206 if(thdb->newWindow == 0)
207 goto createfail;
208
209 //Processing is done in after WinCreateWindow returns
210 dprintf(("OS2: WM_CREATE %x", hwnd));
211 win32wnd = (Win32BaseWindow *)thdb->newWindow;
212 thdb->newWindow = 0;
213
214 if(win32wnd->MsgCreate(WinQueryWindow(hwnd, QW_PARENT), hwnd) == FALSE)
215 {
216 RestoreOS2TIB();
217 return (MRESULT)TRUE; //discontinue window creation
218 }
219 createfail:
220 RestoreOS2TIB();
221 return (MRESULT)FALSE;
222 }
223
224 case WM_QUIT:
225 dprintf(("OS2: WM_QUIT %x", hwnd));
226 win32wnd->MsgQuit();
227 break;
228
229 case WM_CLOSE:
230 dprintf(("OS2: WM_CLOSE %x", hwnd));
231 win32wnd->MsgClose();
232 break;
233
234 case WM_DESTROY:
235 dprintf(("OS2: WM_DESTROY %x", hwnd));
236 win32wnd->MsgDestroy();
237 break;
238
239 case WM_ENABLE:
240 dprintf(("OS2: WM_ENABLE %x", hwnd));
241 win32wnd->MsgEnable(SHORT1FROMMP(mp1));
242 break;
243
244 case WM_SHOW:
245 dprintf(("OS2: WM_SHOW %x %d", hwnd, mp1));
246 win32wnd->MsgShow((ULONG)mp1);
247 break;
248
249 case WM_ADJUSTWINDOWPOS:
250 {
251 PSWP pswp = (PSWP)mp1;
252 dprintf(("PMWINDOW: WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
253 goto RunDefWndProc;
254 }
255
256 case WM_WINDOWPOSCHANGED:
257 {
258 if(pWinMsg->message != 0)
259 win32wnd->MsgPosChanged((LPARAM)&thdb->wp);
260 goto RunDefWndProc;
261 }
262
263 case WM_ACTIVATE:
264 {
265 dprintf(("OS2: WM_ACTIVATE %x %x", hwnd, mp2));
266
267 if(win32wnd->IsWindowCreated())
268 win32wnd->MsgActivate((LOWORD(pWinMsg->wParam) == WA_ACTIVE_W) ? 1 : 0, HIWORD(pWinMsg->wParam), pWinMsg->lParam, (HWND)mp2);
269
270 break;
271 }
272
273 case WM_SIZE:
274 {
275 dprintf(("OS2: WM_SIZE (%d,%d) (%d,%d)", SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), SHORT1FROMMP(mp1), SHORT2FROMMP(mp2)));
276 break;
277 }
278
279 case WM_MINMAXFRAME:
280 {
281 dprintf(("OS2: WM_MINMAXFRAME"));
282 break;
283 }
284
285 case WM_OWNERPOSCHANGE:
286 {
287 dprintf(("OS2: WM_OWNERPOSCHANGE"));
288 goto RunDefWndProc;
289 }
290
291 case WM_CALCVALIDRECTS:
292#if 0
293 {
294 PRECTL oldRect = (PRECTL)mp1,newRect = oldRect+1;
295 UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
296
297//CB: todo: use WM_NCCALCSIZE result
298 if (win32wnd->getWindowClass())
299 {
300 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
301
302 if ((dwStyle & CS_HREDRAW_W) && (newRect->xRight-newRect->xLeft != oldRect->xRight-oldRect->xLeft))
303 res |= CVR_REDRAW;
304 else if ((dwStyle & CS_VREDRAW_W) && (newRect->yTop-newRect->yBottom != oldRect->yTop-oldRect->yBottom))
305 res |= CVR_REDRAW;
306 } else res |= CVR_REDRAW;
307
308 RestoreOS2TIB();
309 return (MRESULT)res;
310 }
311#else
312 RestoreOS2TIB();
313 return (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
314#endif
315
316 case WM_SETFOCUS:
317 {
318 HWND hwndFocus = (HWND)mp1;
319
320 dprintf(("OS2: WM_SETFOCUS %x %x %d", win32wnd->getWindowHandle(), mp1, mp2));
321 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
322 //another (non-win32) application's window
323 //set to NULL (allowed according to win32 SDK) to avoid problems
324 hwndFocus = NULL;
325 }
326 if((ULONG)mp2 == TRUE) {
327 HWND hwndFocusWin32 = Win32BaseWindow::OS2ToWin32Handle(hwndFocus);
328 recreateCaret (hwndFocusWin32);
329 win32wnd->MsgSetFocus(hwndFocusWin32);
330 }
331 else win32wnd->MsgKillFocus(Win32BaseWindow::OS2ToWin32Handle(hwndFocus));
332 break;
333 }
334
335 //**************************************************************************
336 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
337 //**************************************************************************
338 case WM_BUTTON1DOWN:
339 case WM_BUTTON1UP:
340 case WM_BUTTON1DBLCLK:
341 case WM_BUTTON2DOWN:
342 case WM_BUTTON2UP:
343 case WM_BUTTON2DBLCLK:
344 case WM_BUTTON3DOWN:
345 case WM_BUTTON3UP:
346 case WM_BUTTON3DBLCLK:
347 win32wnd->MsgButton(pWinMsg);
348 rc = TRUE;
349 break;
350
351 case WM_BUTTON2MOTIONSTART:
352 case WM_BUTTON2MOTIONEND:
353 case WM_BUTTON2CLICK:
354 case WM_BUTTON1MOTIONSTART:
355 case WM_BUTTON1MOTIONEND:
356 case WM_BUTTON1CLICK:
357 case WM_BUTTON3MOTIONSTART:
358 case WM_BUTTON3MOTIONEND:
359 case WM_BUTTON3CLICK:
360 rc = TRUE;
361 break;
362
363 case WM_MOUSEMOVE:
364 {
365 //OS/2 Window coordinates -> Win32 Window coordinates
366 win32wnd->MsgMouseMove(pWinMsg);
367 break;
368 }
369
370 case WM_CONTROL:
371 goto RunDefWndProc;
372
373 case WM_COMMAND:
374 dprintf(("OS2: WM_COMMAND %x %x %x", hwnd, mp1, mp2));
375 win32wnd->DispatchMsgA(pWinMsg);
376 break;
377
378 case WM_SYSCOMMAND:
379 win32wnd->DispatchMsgA(pWinMsg);
380 break;
381
382 case WM_CHAR:
383 win32wnd->MsgChar(pWinMsg);
384 break;
385
386 case WM_TIMER:
387 win32wnd->DispatchMsgA(pWinMsg);
388 goto RunDefWndProc;
389
390 case WM_SETWINDOWPARAMS:
391 {
392 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
393
394 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
395 if(wndParams->fsStatus & WPM_TEXT) {
396 win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText);
397 }
398 goto RunDefWndProc;
399 }
400
401 case WM_QUERYWINDOWPARAMS:
402 {
403 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
404 ULONG textlen;
405 PSZ wintext;
406
407 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
408 {
409 if(wndpars->fsStatus & WPM_TEXT)
410 win32wnd->MsgGetText(wndpars->pszText, wndpars->cchText);
411 if(wndpars->fsStatus & WPM_CCHTEXT)
412 wndpars->cchText = win32wnd->MsgGetTextLength();
413
414 wndpars->fsStatus = 0;
415 wndpars->cbCtlData = 0;
416 wndpars->cbPresParams = 0;
417 RestoreOS2TIB();
418 return (MRESULT)TRUE;
419 }
420 goto RunDefWndProc;
421 }
422
423 case WM_PAINT:
424 dprintf(("OS2: WM_PAINT"));
425 win32wnd->DispatchMsgA(pWinMsg);
426 goto RunDefWndProc;
427
428 case WM_CONTEXTMENU:
429 {
430 win32wnd->DispatchMsgA(pWinMsg);
431
432 RestoreOS2TIB();
433 return (MRESULT)TRUE;
434 }
435
436 case WM_ERASEBACKGROUND:
437 {
438 dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
439 RestoreOS2TIB();
440 return (MRESULT)FALSE;
441 }
442
443 case WM_FOCUSCHANGE:
444 dprintf(("OS2: WM_FOCUSCHANGE %x", win32wnd->getWindowHandle()));
445 goto RunDefWndProc;
446
447 case WM_INITMENU:
448 case WM_MENUSELECT:
449 case WM_MENUEND:
450 case WM_NEXTMENU:
451 case WM_SYSCOLORCHANGE:
452 case WM_SYSVALUECHANGED:
453 case WM_SETSELECTION:
454 case WM_PPAINT:
455 case WM_PSETFOCUS:
456 case WM_PSYSCOLORCHANGE:
457 case WM_PSIZE:
458 case WM_PACTIVATE:
459 case WM_PCONTROL:
460 case WM_HELP:
461 case WM_APPTERMINATENOTIFY:
462 case WM_PRESPARAMCHANGED:
463 case WM_DRAWITEM:
464 case WM_MEASUREITEM:
465 case WM_CONTROLPOINTER:
466 case WM_QUERYDLGCODE:
467 case WM_SUBSTITUTESTRING:
468 case WM_MATCHMNEMONIC:
469 case WM_SAVEAPPLICATION:
470 case WM_SEMANTICEVENT:
471 default:
472 //dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
473 RestoreOS2TIB();
474 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
475 }
476 RestoreOS2TIB();
477 return (MRESULT)rc;
478
479RunDefWndProc:
480// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
481 RestoreOS2TIB();
482
483 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
484} /* End of Win32WindowProc */
485//******************************************************************************
486//******************************************************************************
Note: See TracBrowser for help on using the repository browser.