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

Last change on this file since 2912 was 2834, checked in by cbratschi, 26 years ago

WM_EX_CONTEXTHELP

File size: 13.9 KB
Line 
1/* $Id: pmwindow.cpp,v 1.86 2000-02-20 18:28:32 cbratschi 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 dprintf(("PMWINDOW: WM_CALCVALIDRECTS"));
313 RestoreOS2TIB();
314 return (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
315#endif
316
317 case WM_SETFOCUS:
318 {
319 HWND hwndFocus = (HWND)mp1;
320
321 dprintf(("OS2: WM_SETFOCUS %x %x %d", win32wnd->getWindowHandle(), mp1, mp2));
322 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
323 //another (non-win32) application's window
324 //set to NULL (allowed according to win32 SDK) to avoid problems
325 hwndFocus = NULL;
326 }
327 if((ULONG)mp2 == TRUE) {
328 HWND hwndFocusWin32 = Win32BaseWindow::OS2ToWin32Handle(hwndFocus);
329 recreateCaret (hwndFocusWin32);
330 win32wnd->MsgSetFocus(hwndFocusWin32);
331 }
332 else win32wnd->MsgKillFocus(Win32BaseWindow::OS2ToWin32Handle(hwndFocus));
333 break;
334 }
335
336 //**************************************************************************
337 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
338 //**************************************************************************
339 case WM_BUTTON1DOWN:
340 case WM_BUTTON1UP:
341 case WM_BUTTON1DBLCLK:
342 case WM_BUTTON2DOWN:
343 case WM_BUTTON2UP:
344 case WM_BUTTON2DBLCLK:
345 case WM_BUTTON3DOWN:
346 case WM_BUTTON3UP:
347 case WM_BUTTON3DBLCLK:
348 win32wnd->MsgButton(pWinMsg);
349 rc = TRUE;
350 break;
351
352 case WM_BUTTON2MOTIONSTART:
353 case WM_BUTTON2MOTIONEND:
354 case WM_BUTTON2CLICK:
355 case WM_BUTTON1MOTIONSTART:
356 case WM_BUTTON1MOTIONEND:
357 case WM_BUTTON1CLICK:
358 case WM_BUTTON3MOTIONSTART:
359 case WM_BUTTON3MOTIONEND:
360 case WM_BUTTON3CLICK:
361 rc = TRUE;
362 break;
363
364 case WM_MOUSEMOVE:
365 {
366 //OS/2 Window coordinates -> Win32 Window coordinates
367 win32wnd->MsgMouseMove(pWinMsg);
368 break;
369 }
370
371 case WM_CONTROL:
372 goto RunDefWndProc;
373
374 case WM_COMMAND:
375 dprintf(("OS2: WM_COMMAND %x %x %x", hwnd, mp1, mp2));
376 win32wnd->DispatchMsgA(pWinMsg);
377 break;
378
379 case WM_SYSCOMMAND:
380 win32wnd->DispatchMsgA(pWinMsg);
381 break;
382
383 case WM_CHAR:
384 win32wnd->MsgChar(pWinMsg);
385 break;
386
387 case WM_TIMER:
388 win32wnd->DispatchMsgA(pWinMsg);
389 goto RunDefWndProc;
390
391 case WM_SETWINDOWPARAMS:
392 {
393 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
394
395 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
396 if(wndParams->fsStatus & WPM_TEXT) {
397 win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText);
398 }
399 goto RunDefWndProc;
400 }
401
402 case WM_QUERYWINDOWPARAMS:
403 {
404 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
405 ULONG textlen;
406 PSZ wintext;
407
408 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
409 {
410 if(wndpars->fsStatus & WPM_TEXT)
411 win32wnd->MsgGetText(wndpars->pszText, wndpars->cchText);
412 if(wndpars->fsStatus & WPM_CCHTEXT)
413 wndpars->cchText = win32wnd->MsgGetTextLength();
414
415 wndpars->fsStatus = 0;
416 wndpars->cbCtlData = 0;
417 wndpars->cbPresParams = 0;
418 RestoreOS2TIB();
419 return (MRESULT)TRUE;
420 }
421 goto RunDefWndProc;
422 }
423
424 case WM_PAINT:
425 dprintf(("OS2: WM_PAINT"));
426 win32wnd->DispatchMsgA(pWinMsg);
427 goto RunDefWndProc;
428
429 case WM_CONTEXTMENU:
430 {
431 win32wnd->DispatchMsgA(pWinMsg);
432
433 RestoreOS2TIB();
434 return (MRESULT)TRUE;
435 }
436
437 case WM_ERASEBACKGROUND:
438 {
439 dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
440 RestoreOS2TIB();
441 return (MRESULT)FALSE;
442 }
443
444 case WM_FOCUSCHANGE:
445 dprintf(("OS2: WM_FOCUSCHANGE %x", win32wnd->getWindowHandle()));
446 goto RunDefWndProc;
447
448 case WM_INITMENU:
449 case WM_MENUSELECT:
450 case WM_MENUEND:
451 case WM_NEXTMENU:
452 case WM_SYSCOLORCHANGE:
453 case WM_SYSVALUECHANGED:
454 case WM_SETSELECTION:
455 case WM_PPAINT:
456 case WM_PSETFOCUS:
457 case WM_PSYSCOLORCHANGE:
458 case WM_PSIZE:
459 case WM_PACTIVATE:
460 case WM_PCONTROL:
461 case WM_HELP:
462 case WM_APPTERMINATENOTIFY:
463 case WM_PRESPARAMCHANGED:
464 case WM_DRAWITEM:
465 case WM_MEASUREITEM:
466 case WM_CONTROLPOINTER:
467 case WM_QUERYDLGCODE:
468 case WM_SUBSTITUTESTRING:
469 case WM_MATCHMNEMONIC:
470 case WM_SAVEAPPLICATION:
471 case WM_SEMANTICEVENT:
472 default:
473 //dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
474 RestoreOS2TIB();
475 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
476 }
477 RestoreOS2TIB();
478 return (MRESULT)rc;
479
480RunDefWndProc:
481// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
482 RestoreOS2TIB();
483
484 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
485} /* End of Win32WindowProc */
486//******************************************************************************
487//******************************************************************************
Note: See TracBrowser for help on using the repository browser.