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

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

single frame works now

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