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

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

* empty log message *

File size: 12.4 KB
Line 
1/* $Id: pmwindow.cpp,v 1.6 1999-07-17 15:23:38 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
26HMQ hmq = 0; /* Message queue handle */
27HAB hab = 0;
28
29MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
30
31//******************************************************************************
32//Initialize PM; create hab, message queue and register special Win32 window classes
33//******************************************************************************
34BOOL InitPM()
35{
36 hab = WinInitialize(0);
37 dprintf(("Winitialize returned %x", hab));
38 hmq = WinCreateMsgQueue(hab, 0);
39
40 if(!hab || !hmq)
41 {
42 UINT error;
43
44 //CB: only fail on real error
45 error = WinGetLastError(hab) & 0xFFFF; //error code
46 if (!hab || error != PMERR_MSG_QUEUE_ALREADY_EXISTS)
47 {
48 dprintf(("WinInitialize or WinCreateMsgQueue failed %x %x", hab, hmq));
49 dprintf((" Error = %x",error));
50 return(FALSE);
51 }
52 else
53 {
54 if(!hab) {
55 hab = WinQueryAnchorBlock(HWND_DESKTOP);
56 dprintf(("WinQueryAnchorBlock returned %x", hab));
57 }
58 if(!hmq) {
59 hmq = HMQ_CURRENT;
60 }
61 }
62 }
63 SetThreadHAB(hab);
64 dprintf(("InitPM: hmq = %x", hmq));
65 SetThreadMessageQueue(hmq);
66
67 if(!WinRegisterClass( /* Register window class */
68 hab, /* Anchor block handle */
69 (PSZ)WIN32_STDCLASS, /* Window class name */
70 (PFNWP)Win32WindowProc, /* Address of window procedure */
71 CS_SIZEREDRAW, /* Class style */
72 8)) {
73 dprintf(("WinRegisterClass Win32Window failed"));
74 return(FALSE);
75 }
76
77 return(TRUE);
78} /* End of main */
79//******************************************************************************
80//Win32 window message handler
81//******************************************************************************
82MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
83{
84 POSTMSG_PACKET *postmsg;
85 Win32Window *win32wnd;
86 ULONG magic;
87 APIRET rc;
88
89 //Restore our FS selector
90 SetWin32TIB();
91
92 win32wnd = (Win32Window *)WinQueryWindowULong(hwnd, OFFSET_WIN32WNDPTR);
93 magic = WinQueryWindowULong(hwnd, OFFSET_WIN32PM_MAGIC);
94
95 if(msg != WM_CREATE && win32wnd == NULL && magic != WIN32PM_MAGIC) {
96 dprintf(("Invalid win32wnd pointer for window %x!!", hwnd));
97 goto RunDefWndProc;
98 }
99 switch( msg )
100 {
101 //internal messages
102 case WM_WIN32_POSTMESSAGEA:
103 postmsg = (POSTMSG_PACKET *)mp1;
104 if(postmsg == NULL) {
105 dprintf(("WM_WIN32_POSTMESSAGEA, postmsg NULL!!"));
106 break;
107 }
108 win32wnd->SendMessageA(postmsg->Msg, postmsg->wParam, postmsg->lParam);
109 free(postmsg);
110 break;
111
112 case WM_WIN32_POSTMESSAGEW:
113 postmsg = (POSTMSG_PACKET *)mp1;
114 if(postmsg == NULL) {
115 dprintf(("WM_WIN32_POSTMESSAGEW, postmsg NULL!!"));
116 break;
117 }
118 win32wnd->SendMessageW(postmsg->Msg, postmsg->wParam, postmsg->lParam);
119 free(postmsg);
120 break;
121
122 //OS/2 msgs
123 case WM_CREATE:
124 //Processing is done in after WinCreateWindow returns
125 dprintf(("OS2: WM_CREATE %x", hwnd));
126 RestoreOS2TIB();
127 return (MRESULT)FALSE;
128
129 case WM_QUIT:
130 dprintf(("OS2: WM_QUIT %x", hwnd));
131 if(win32wnd->MsgQuit()) {
132 goto RunDefWndProc;
133 }
134 break;
135
136 case WM_CLOSE:
137 dprintf(("OS2: WM_CLOSE %x", hwnd));
138 if(win32wnd->MsgClose()) {
139 goto RunDefWndProc;
140 }
141 break;
142
143 case WM_DESTROY:
144 dprintf(("OS2: WM_DESTROY %x", hwnd));
145 if(win32wnd->MsgDestroy()) {
146 goto RunDefWndProc;
147 }
148 break;
149
150 case WM_ENABLE:
151 dprintf(("OS2: WM_ENABLE %x", hwnd));
152 if(win32wnd->MsgEnable((ULONG)mp1)) {
153 goto RunDefWndProc;
154 }
155 break;
156
157 case WM_SHOW:
158 dprintf(("OS2: WM_SHOW %x", hwnd));
159 if(win32wnd->MsgShow((ULONG)mp1)) {
160 goto RunDefWndProc;
161 }
162 break;
163
164 case WM_MOVE:
165 {
166 RECTL rectl, rectl2;
167 POINTL point;
168 HWND hwndParent;
169 ULONG xScreen, yScreen, yParent, xParent;
170
171 dprintf(("OS2: WM_MOVE %x", hwnd));
172 rc = WinQueryWindowRect(hwnd, &rectl);
173 if(rc == TRUE) {
174 point.x = rectl.xLeft;
175 point.y = rectl.yBottom;
176
177 //If the window has a parent, calculate position relative to that window
178 if((hwndParent = WinQueryWindow(hwnd, QW_PARENT)) != WinQueryDesktopWindow(hab, NULLHANDLE)) {
179 rc = WinMapWindowPoints(hwnd, hwndParent, &point, 1);
180 if(rc == FALSE) {
181 dprintf(("WM_MOVE: WinMapWindowPoints (parent) failed!"));
182 break;
183 }
184 rc = WinQueryWindowRect(hwndParent, &rectl2);
185 if(rc == FALSE) {
186 dprintf(("WM_MOVE: WinQueryWindowRect(HWND_DESKTOP, &rectl) failed!"));
187 break;
188 }
189 xParent = point.x;
190 yParent = OS2TOWIN32POINT(rectl2.yTop - rectl2.yBottom, point.y);
191 }
192 else xParent = yParent = -1;
193
194 point.x = rectl.xLeft;
195 point.y = rectl.yBottom;
196
197 rc = WinMapWindowPoints(hwnd, HWND_DESKTOP, &point, 1);
198 if(rc == FALSE) {
199 dprintf(("WM_MOVE: WinMapWindowPoints (desktop) failed!"));
200 break;
201 }
202 rc = WinQueryWindowRect(HWND_DESKTOP, &rectl);
203 if(rc == FALSE) {
204 dprintf(("WM_MOVE: WinQueryWindowRect(HWND_DESKTOP, &rectl) failed!"));
205 break;
206 }
207 xScreen = point.x;
208 yScreen = OS2TOWIN32POINT(rectl.yTop - rectl.yBottom, point.y);
209
210 if(win32wnd->MsgMove(xScreen, yScreen, xParent, yParent)) {
211 goto RunDefWndProc;
212 }
213 }
214 else {
215 dprintf(("WM_MOVE: WinQueryWindowRect failed!"));
216 }
217 break;
218 }
219
220 case WM_WINDOWPOSCHANGED:
221 {
222 break;
223 }
224
225 case WM_ADJUSTWINDOWPOS:
226 {
227 dprintf(("OS2: WM_ADJUSTWINDOWPOS %x", hwnd));
228// if(win32wnd->MsgWindowPosChanging(0, 0)) {
229 goto RunDefWndProc;
230// }
231 break;
232 }
233
234 case WM_ERASEBACKGROUND:
235 {
236 HPS hps;
237
238 dprintf(("OS2: WM_ERASEBACKGROUND %x", hwnd));
239 hps = WinGetPS(hwnd);
240 if(win32wnd->MsgEraseBackGround((ULONG)hps))
241 {
242 /*
243 * Return TRUE to request PM to paint the window background
244 * in SYSCLR_WINDOW.
245 */
246 WinReleasePS(hps);
247 return (MRESULT)( TRUE );
248 }
249 WinReleasePS(hps);
250 return (MRESULT) FALSE;
251 }
252 case WM_SIZE:
253 {
254 SWP swp;
255
256 dprintf(("OS2: WM_SIZE %x", hwnd));
257 rc = WinQueryWindowPos(hwnd, &swp);
258 if(rc == FALSE) {
259 dprintf(("WM_SIZE: WinQueryWindowPos failed!"));
260 break;
261 }
262 if(win32wnd->MsgSize(SHORT1FROMMP(mp2), SHORT2FROMMP(mp2),
263 (swp.fl & SWP_MINIMIZE) != 0,
264 (swp.fl & SWP_MAXIMIZE) != 0))
265 {
266 goto RunDefWndProc;
267 }
268
269 break;
270 }
271
272 case WM_ACTIVATE:
273 {
274 HWND hwndActivate = (HWND)mp1;
275
276 dprintf(("OS2: WM_ACTIVATE %x", hwnd));
277 if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
278 //another (non-win32) application's window
279 //set to NULL (allowed according to win32 SDK) to avoid problems
280 hwndActivate = NULL;
281 }
282 if(win32wnd->MsgActivate(1, hwndActivate)) {
283 goto RunDefWndProc;
284 }
285 break;
286 }
287 case WM_FOCUSCHANGE:
288 break;
289
290 case WM_SETFOCUS:
291 {
292 HWND hwndFocus = (HWND)mp1;
293
294 dprintf(("OS2: WM_SETFOCUS %x", hwnd));
295 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
296 //another (non-win32) application's window
297 //set to NULL (allowed according to win32 SDK) to avoid problems
298 hwndFocus = NULL;
299 }
300 if((ULONG)mp2 == TRUE) {
301 rc = win32wnd->MsgSetFocus(hwndFocus);
302 }
303 else rc = win32wnd->MsgKillFocus(hwndFocus);
304 if(rc) {
305 goto RunDefWndProc;
306 }
307 break;
308 }
309 //**************************************************************************
310 //Mouse messages
311 //**************************************************************************
312 case WM_BUTTON1DOWN:
313 if(win32wnd->MsgButton(BUTTON_LEFTDOWN, (*(POINTS *)&mp1).x, (*(POINTS *)&mp1).y)) {
314 goto RunDefWndProc;
315 }
316 break;
317 case WM_BUTTON1UP:
318 if(win32wnd->MsgButton(BUTTON_LEFTUP, (*(POINTS *)&mp1).x, (*(POINTS *)&mp1).y)) {
319 goto RunDefWndProc;
320 }
321 break;
322 case WM_BUTTON1DBLCLK:
323 if(win32wnd->MsgButton(BUTTON_LEFTDBLCLICK, (*(POINTS *)&mp1).x, (*(POINTS *)&mp1).y)) {
324 goto RunDefWndProc;
325 }
326 break;
327 case WM_BUTTON2DOWN:
328 if(win32wnd->MsgButton(BUTTON_RIGHTDOWN, (*(POINTS *)&mp1).x, (*(POINTS *)&mp1).y)) {
329 goto RunDefWndProc;
330 }
331 break;
332 case WM_BUTTON2UP:
333 if(win32wnd->MsgButton(BUTTON_RIGHTUP, (*(POINTS *)&mp1).x, (*(POINTS *)&mp1).y)) {
334 goto RunDefWndProc;
335 }
336 break;
337 case WM_BUTTON2DBLCLK:
338 if(win32wnd->MsgButton(BUTTON_RIGHTDBLCLICK, (*(POINTS *)&mp1).x, (*(POINTS *)&mp1).y)) {
339 goto RunDefWndProc;
340 }
341 break;
342 case WM_BUTTON2MOTIONSTART:
343 case WM_BUTTON2MOTIONEND:
344 case WM_BUTTON2CLICK:
345 case WM_BUTTON1MOTIONSTART:
346 case WM_BUTTON1MOTIONEND:
347 case WM_BUTTON1CLICK:
348 case WM_BUTTON3DOWN:
349 case WM_BUTTON3UP:
350 case WM_BUTTON3DBLCLK:
351 case WM_BUTTON3MOTIONSTART:
352 case WM_BUTTON3MOTIONEND:
353 case WM_BUTTON3CLICK:
354 break;
355
356 case WM_MOUSEMOVE:
357 break;
358
359 //**************************************************************************
360 //Slider messages
361 //**************************************************************************
362 case WM_VSCROLL:
363 break;
364 case WM_HSCROLL:
365 break;
366
367 case WM_CONTROL:
368 break;
369
370 case WM_COMMAND:
371 case WM_SYSCOMMAND:
372 break;
373
374 case WM_CHAR:
375 break;
376
377 case WM_INITMENU:
378 case WM_MENUSELECT:
379 case WM_MENUEND:
380 case WM_NEXTMENU:
381 break;
382
383 case WM_TIMER:
384 break;
385
386 case WM_PAINT:
387 dprintf(("OS2: WM_PAINT %x", hwnd));
388 if(win32wnd->MsgPaint(0, 0)) {
389 goto RunDefWndProc;
390 }
391 break;
392
393 case WM_SYSCOLORCHANGE:
394 case WM_SYSVALUECHANGED:
395 break;
396
397 case WM_CALCVALIDRECTS:
398 case WM_SETWINDOWPARAMS:
399 case WM_QUERYWINDOWPARAMS:
400 case WM_HITTEST:
401 case WM_SETSELECTION:
402 case WM_PPAINT:
403 case WM_PSETFOCUS:
404 case WM_PSYSCOLORCHANGE:
405 case WM_PSIZE:
406 case WM_PACTIVATE:
407 case WM_PCONTROL:
408 case WM_HELP:
409 case WM_APPTERMINATENOTIFY:
410 case WM_PRESPARAMCHANGED:
411 case WM_DRAWITEM:
412 case WM_MEASUREITEM:
413 case WM_CONTROLPOINTER:
414 case WM_QUERYDLGCODE:
415 case WM_SUBSTITUTESTRING:
416 case WM_MATCHMNEMONIC:
417 case WM_SAVEAPPLICATION:
418 case WM_SEMANTICEVENT:
419 break;
420 default:
421 dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
422 RestoreOS2TIB();
423 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
424 }
425 RestoreOS2TIB();
426 return (MRESULT)FALSE;
427
428RunDefWndProc:
429 dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
430 RestoreOS2TIB();
431 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
432} /* End of Win32WindowProc */
433//******************************************************************************
434//******************************************************************************
Note: See TracBrowser for help on using the repository browser.