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

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

* empty log message *

File size: 12.6 KB
Line 
1/* $Id: pmwindow.cpp,v 1.9 1999-07-18 14:39:35 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#include "oslibgdi.h"
26
27HMQ hmq = 0; /* Message queue handle */
28HAB hab = 0;
29
30MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
31
32//******************************************************************************
33//Initialize PM; create hab, message queue and register special Win32 window classes
34//******************************************************************************
35BOOL InitPM()
36{
37 hab = WinInitialize(0);
38 dprintf(("Winitialize returned %x", hab));
39 hmq = WinCreateMsgQueue(hab, 0);
40
41 if(!hab || !hmq)
42 {
43 UINT error;
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 | CS_MOVENOTIFY | CS_HITTEST,
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 RECTLOS2 rectChild;
167 ULONG x, y;
168
169 dprintf(("OS2: WM_MOVE %x", hwnd));
170
171 WinQueryWindowRect(hwnd, (PRECTL)&rectChild);
172
173 //Calculate position relative to parent window (real window or desktop)
174 x = rectChild.xLeft;
175 y = MapOS2ToWin32Y(hwnd, &rectChild, rectChild.yBottom);
176
177 if(win32wnd->MsgMove(x, y)) {
178 goto RunDefWndProc;
179 }
180 break;
181 }
182
183 case WM_WINDOWPOSCHANGED:
184 {
185 dprintf(("OS2: WM_WINDOWPOSCHANGED %x", hwnd));
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 dprintf(("OS2: WM_FOCUSCHANGE %x", hwnd));
251 goto RunDefWndProc;
252
253 case WM_SETFOCUS:
254 {
255 HWND hwndFocus = (HWND)mp1;
256
257 dprintf(("OS2: WM_SETFOCUS %x", hwnd));
258 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
259 //another (non-win32) application's window
260 //set to NULL (allowed according to win32 SDK) to avoid problems
261 hwndFocus = NULL;
262 }
263 if((ULONG)mp2 == TRUE) {
264 rc = win32wnd->MsgSetFocus(hwndFocus);
265 }
266 else rc = win32wnd->MsgKillFocus(hwndFocus);
267 if(rc) {
268 goto RunDefWndProc;
269 }
270 break;
271 }
272 //**************************************************************************
273 //Mouse messages
274 //**************************************************************************
275 case WM_BUTTON1DOWN:
276 dprintf(("OS2: WM_BUTTON1DOWN %x", hwnd));
277 if(win32wnd->MsgButton(BUTTON_LEFTDOWN, (*(POINTS *)&mp1).x, MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
278 goto RunDefWndProc;
279 }
280 break;
281 case WM_BUTTON1UP:
282 dprintf(("OS2: WM_BUTTON1UP %x", hwnd));
283 if(win32wnd->MsgButton(BUTTON_LEFTUP, (*(POINTS *)&mp1).x, MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
284 goto RunDefWndProc;
285 }
286 break;
287 case WM_BUTTON1DBLCLK:
288 if(win32wnd->MsgButton(BUTTON_LEFTDBLCLICK, (*(POINTS *)&mp1).x, MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
289 goto RunDefWndProc;
290 }
291 break;
292 case WM_BUTTON2DOWN:
293 if(win32wnd->MsgButton(BUTTON_RIGHTDOWN, (*(POINTS *)&mp1).x, MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
294 goto RunDefWndProc;
295 }
296 break;
297 case WM_BUTTON2UP:
298 if(win32wnd->MsgButton(BUTTON_RIGHTUP, (*(POINTS *)&mp1).x,MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
299 goto RunDefWndProc;
300 }
301 break;
302 case WM_BUTTON2DBLCLK:
303 if(win32wnd->MsgButton(BUTTON_RIGHTDBLCLICK, (*(POINTS *)&mp1).x,MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
304 goto RunDefWndProc;
305 }
306 break;
307 case WM_BUTTON3DOWN:
308 if(win32wnd->MsgButton(BUTTON_MIDDLEDOWN, (*(POINTS *)&mp1).x, MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
309 goto RunDefWndProc;
310 }
311 break;
312 case WM_BUTTON3UP:
313 if(win32wnd->MsgButton(BUTTON_MIDDLEUP, (*(POINTS *)&mp1).x,MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
314 goto RunDefWndProc;
315 }
316 break;
317 case WM_BUTTON3DBLCLK:
318 if(win32wnd->MsgButton(BUTTON_MIDDLEDBLCLICK, (*(POINTS *)&mp1).x,MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
319 goto RunDefWndProc;
320 }
321 break;
322
323 case WM_BUTTON2MOTIONSTART:
324 case WM_BUTTON2MOTIONEND:
325 case WM_BUTTON2CLICK:
326 case WM_BUTTON1MOTIONSTART:
327 case WM_BUTTON1MOTIONEND:
328 case WM_BUTTON1CLICK:
329 case WM_BUTTON3MOTIONSTART:
330 case WM_BUTTON3MOTIONEND:
331 case WM_BUTTON3CLICK:
332 goto RunDefWndProc;
333
334 case WM_MOUSEMOVE:
335 {
336 ULONG keystate = 0;
337 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1))
338 keystate |= WMMOVE_LBUTTON;
339 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2))
340 keystate |= WMMOVE_MBUTTON;
341 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3))
342 keystate |= WMMOVE_RBUTTON;
343 if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT))
344 keystate |= WMMOVE_SHIFT;
345 if(WinGetKeyState(HWND_DESKTOP, VK_CTRL))
346 keystate |= WMMOVE_CTRL;
347
348 if(!win32wnd->MsgMouseMove(keystate, (*(POINTS *)&mp1).x, MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
349 goto RunDefWndProc;
350 }
351 break;
352 }
353
354 //**************************************************************************
355 //Slider messages
356 //**************************************************************************
357 case WM_VSCROLL:
358 case WM_HSCROLL:
359
360 case WM_CONTROL:
361
362 case WM_COMMAND:
363 case WM_SYSCOMMAND:
364
365 case WM_CHAR:
366
367 case WM_INITMENU:
368 case WM_MENUSELECT:
369 case WM_MENUEND:
370 case WM_NEXTMENU:
371
372 case WM_TIMER:
373 goto RunDefWndProc;
374
375 case WM_SETWINDOWPARAMS:
376 {
377 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
378
379 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
380 if(wndParams->fsStatus & WPM_TEXT) {
381 if(win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText)) {
382 goto RunDefWndProc;
383 }
384 }
385 goto RunDefWndProc;
386 }
387
388 case WM_PAINT:
389 dprintf(("OS2: WM_PAINT %x", hwnd));
390 if(win32wnd->MsgPaint(0, 0)) {
391 goto RunDefWndProc;
392 }
393 break;
394
395 case WM_HITTEST:
396 if(win32wnd->MsgHitTest((*(POINTS *)&mp1).x, MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
397 goto RunDefWndProc;
398 }
399 break;
400
401 case WM_SYSCOLORCHANGE:
402 case WM_SYSVALUECHANGED:
403 case WM_CALCVALIDRECTS:
404 case WM_QUERYWINDOWPARAMS:
405 case WM_SETSELECTION:
406 case WM_PPAINT:
407 case WM_PSETFOCUS:
408 case WM_PSYSCOLORCHANGE:
409 case WM_PSIZE:
410 case WM_PACTIVATE:
411 case WM_PCONTROL:
412 case WM_HELP:
413 case WM_APPTERMINATENOTIFY:
414 case WM_PRESPARAMCHANGED:
415 case WM_DRAWITEM:
416 case WM_MEASUREITEM:
417 case WM_CONTROLPOINTER:
418 case WM_QUERYDLGCODE:
419 case WM_SUBSTITUTESTRING:
420 case WM_MATCHMNEMONIC:
421 case WM_SAVEAPPLICATION:
422 case WM_SEMANTICEVENT:
423 default:
424 dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
425 RestoreOS2TIB();
426 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
427 }
428 RestoreOS2TIB();
429 return (MRESULT)FALSE;
430
431RunDefWndProc:
432 dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
433 RestoreOS2TIB();
434 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
435} /* End of Win32WindowProc */
436//******************************************************************************
437//******************************************************************************
Note: See TracBrowser for help on using the repository browser.