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

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

* empty log message *

File size: 10.7 KB
Line 
1/* $Id: pmwindow.cpp,v 1.7 1999-07-17 18:30:51 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 rectChild;
167 ULONG xParent, yParent;
168
169 dprintf(("OS2: WM_MOVE %x", hwnd));
170
171 WinQueryWindowRect(hwnd, &rectChild);
172
173 //Calculate position relative to parent window (real window or desktop)
174 xParent = rectChild.xLeft;
175 yParent = MapOS2ToWin32Y(hwnd, &rectChild, rectChild.yBottom);
176
177 if(win32wnd->MsgMove(xParent, yParent)) {
178 goto RunDefWndProc;
179 }
180 break;
181 }
182
183 case WM_WINDOWPOSCHANGED:
184 {
185 break;
186 }
187
188 case WM_ADJUSTWINDOWPOS:
189 {
190 dprintf(("OS2: WM_ADJUSTWINDOWPOS %x", hwnd));
191// if(win32wnd->MsgWindowPosChanging(0, 0)) {
192 goto RunDefWndProc;
193// }
194 break;
195 }
196
197 case WM_ERASEBACKGROUND:
198 {
199 HPS hps;
200
201 dprintf(("OS2: WM_ERASEBACKGROUND %x", hwnd));
202 hps = WinGetPS(hwnd);
203 if(win32wnd->MsgEraseBackGround((ULONG)hps))
204 {
205 /*
206 * Return TRUE to request PM to paint the window background
207 * in SYSCLR_WINDOW.
208 */
209 WinReleasePS(hps);
210 return (MRESULT)( TRUE );
211 }
212 WinReleasePS(hps);
213 return (MRESULT) FALSE;
214 }
215 case WM_SIZE:
216 {
217 SWP swp;
218
219 dprintf(("OS2: WM_SIZE %x", hwnd));
220 rc = WinQueryWindowPos(hwnd, &swp);
221 if(rc == FALSE) {
222 dprintf(("WM_SIZE: WinQueryWindowPos failed!"));
223 break;
224 }
225 if(win32wnd->MsgSize(SHORT1FROMMP(mp2), SHORT2FROMMP(mp2),
226 (swp.fl & SWP_MINIMIZE) != 0,
227 (swp.fl & SWP_MAXIMIZE) != 0))
228 {
229 goto RunDefWndProc;
230 }
231 break;
232 }
233
234 case WM_ACTIVATE:
235 {
236 HWND hwndActivate = (HWND)mp1;
237
238 dprintf(("OS2: WM_ACTIVATE %x", hwnd));
239 if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
240 //another (non-win32) application's window
241 //set to NULL (allowed according to win32 SDK) to avoid problems
242 hwndActivate = NULL;
243 }
244 if(win32wnd->MsgActivate(1, hwndActivate)) {
245 goto RunDefWndProc;
246 }
247 break;
248 }
249 case WM_FOCUSCHANGE:
250 break;
251
252 case WM_SETFOCUS:
253 {
254 HWND hwndFocus = (HWND)mp1;
255
256 dprintf(("OS2: WM_SETFOCUS %x", hwnd));
257 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
258 //another (non-win32) application's window
259 //set to NULL (allowed according to win32 SDK) to avoid problems
260 hwndFocus = NULL;
261 }
262 if((ULONG)mp2 == TRUE) {
263 rc = win32wnd->MsgSetFocus(hwndFocus);
264 }
265 else rc = win32wnd->MsgKillFocus(hwndFocus);
266 if(rc) {
267 goto RunDefWndProc;
268 }
269 break;
270 }
271 //**************************************************************************
272 //Mouse messages
273 //**************************************************************************
274 case WM_BUTTON1DOWN:
275 if(win32wnd->MsgButton(BUTTON_LEFTDOWN, (*(POINTS *)&mp1).x, (*(POINTS *)&mp1).y)) {
276 goto RunDefWndProc;
277 }
278 break;
279 case WM_BUTTON1UP:
280 if(win32wnd->MsgButton(BUTTON_LEFTUP, (*(POINTS *)&mp1).x, (*(POINTS *)&mp1).y)) {
281 goto RunDefWndProc;
282 }
283 break;
284 case WM_BUTTON1DBLCLK:
285 if(win32wnd->MsgButton(BUTTON_LEFTDBLCLICK, (*(POINTS *)&mp1).x, (*(POINTS *)&mp1).y)) {
286 goto RunDefWndProc;
287 }
288 break;
289 case WM_BUTTON2DOWN:
290 if(win32wnd->MsgButton(BUTTON_RIGHTDOWN, (*(POINTS *)&mp1).x, (*(POINTS *)&mp1).y)) {
291 goto RunDefWndProc;
292 }
293 break;
294 case WM_BUTTON2UP:
295 if(win32wnd->MsgButton(BUTTON_RIGHTUP, (*(POINTS *)&mp1).x, (*(POINTS *)&mp1).y)) {
296 goto RunDefWndProc;
297 }
298 break;
299 case WM_BUTTON2DBLCLK:
300 if(win32wnd->MsgButton(BUTTON_RIGHTDBLCLICK, (*(POINTS *)&mp1).x, (*(POINTS *)&mp1).y)) {
301 goto RunDefWndProc;
302 }
303 break;
304 case WM_BUTTON2MOTIONSTART:
305 case WM_BUTTON2MOTIONEND:
306 case WM_BUTTON2CLICK:
307 case WM_BUTTON1MOTIONSTART:
308 case WM_BUTTON1MOTIONEND:
309 case WM_BUTTON1CLICK:
310 case WM_BUTTON3DOWN:
311 case WM_BUTTON3UP:
312 case WM_BUTTON3DBLCLK:
313 case WM_BUTTON3MOTIONSTART:
314 case WM_BUTTON3MOTIONEND:
315 case WM_BUTTON3CLICK:
316 break;
317
318 case WM_MOUSEMOVE:
319 break;
320
321 //**************************************************************************
322 //Slider messages
323 //**************************************************************************
324 case WM_VSCROLL:
325 break;
326 case WM_HSCROLL:
327 break;
328
329 case WM_CONTROL:
330 break;
331
332 case WM_COMMAND:
333 case WM_SYSCOMMAND:
334 break;
335
336 case WM_CHAR:
337 break;
338
339 case WM_INITMENU:
340 case WM_MENUSELECT:
341 case WM_MENUEND:
342 case WM_NEXTMENU:
343 break;
344
345 case WM_TIMER:
346 break;
347
348 case WM_PAINT:
349 dprintf(("OS2: WM_PAINT %x", hwnd));
350 if(win32wnd->MsgPaint(0, 0)) {
351 goto RunDefWndProc;
352 }
353 break;
354
355 case WM_SYSCOLORCHANGE:
356 case WM_SYSVALUECHANGED:
357 break;
358
359 case WM_CALCVALIDRECTS:
360 case WM_SETWINDOWPARAMS:
361 case WM_QUERYWINDOWPARAMS:
362 case WM_HITTEST:
363 case WM_SETSELECTION:
364 case WM_PPAINT:
365 case WM_PSETFOCUS:
366 case WM_PSYSCOLORCHANGE:
367 case WM_PSIZE:
368 case WM_PACTIVATE:
369 case WM_PCONTROL:
370 case WM_HELP:
371 case WM_APPTERMINATENOTIFY:
372 case WM_PRESPARAMCHANGED:
373 case WM_DRAWITEM:
374 case WM_MEASUREITEM:
375 case WM_CONTROLPOINTER:
376 case WM_QUERYDLGCODE:
377 case WM_SUBSTITUTESTRING:
378 case WM_MATCHMNEMONIC:
379 case WM_SAVEAPPLICATION:
380 case WM_SEMANTICEVENT:
381 break;
382 default:
383 dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
384 RestoreOS2TIB();
385 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
386 }
387 RestoreOS2TIB();
388 return (MRESULT)FALSE;
389
390RunDefWndProc:
391 dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
392 RestoreOS2TIB();
393 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
394} /* End of Win32WindowProc */
395//******************************************************************************
396//******************************************************************************
Note: See TracBrowser for help on using the repository browser.