1 | /* $Id: pmwindow.cpp,v 1.10 1999-07-18 14:56:36 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 |
|
---|
27 | HMQ hmq = 0; /* Message queue handle */
|
---|
28 | HAB hab = 0;
|
---|
29 |
|
---|
30 | MRESULT 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 | //******************************************************************************
|
---|
35 | BOOL 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 | //******************************************************************************
|
---|
82 | MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
83 | {
|
---|
84 | POSTMSG_PACKET *postmsg;
|
---|
85 | Win32Window *win32wnd;
|
---|
86 | APIRET rc;
|
---|
87 |
|
---|
88 | //Restore our FS selector
|
---|
89 | SetWin32TIB();
|
---|
90 |
|
---|
91 | win32wnd = Win32Window::GetWindowFromOS2Handle(hwnd);
|
---|
92 |
|
---|
93 | if(msg != WM_CREATE && win32wnd == NULL) {
|
---|
94 | dprintf(("Invalid win32wnd pointer for window %x!!", hwnd));
|
---|
95 | goto RunDefWndProc;
|
---|
96 | }
|
---|
97 | switch( msg )
|
---|
98 | {
|
---|
99 | //internal messages
|
---|
100 | case WM_WIN32_POSTMESSAGEA:
|
---|
101 | postmsg = (POSTMSG_PACKET *)mp1;
|
---|
102 | if(postmsg == NULL) {
|
---|
103 | dprintf(("WM_WIN32_POSTMESSAGEA, postmsg NULL!!"));
|
---|
104 | break;
|
---|
105 | }
|
---|
106 | win32wnd->SendMessageA(postmsg->Msg, postmsg->wParam, postmsg->lParam);
|
---|
107 | free(postmsg);
|
---|
108 | break;
|
---|
109 |
|
---|
110 | case WM_WIN32_POSTMESSAGEW:
|
---|
111 | postmsg = (POSTMSG_PACKET *)mp1;
|
---|
112 | if(postmsg == NULL) {
|
---|
113 | dprintf(("WM_WIN32_POSTMESSAGEW, postmsg NULL!!"));
|
---|
114 | break;
|
---|
115 | }
|
---|
116 | win32wnd->SendMessageW(postmsg->Msg, postmsg->wParam, postmsg->lParam);
|
---|
117 | free(postmsg);
|
---|
118 | break;
|
---|
119 |
|
---|
120 | //OS/2 msgs
|
---|
121 | case WM_CREATE:
|
---|
122 | //Processing is done in after WinCreateWindow returns
|
---|
123 | dprintf(("OS2: WM_CREATE %x", hwnd));
|
---|
124 | RestoreOS2TIB();
|
---|
125 | return (MRESULT)FALSE;
|
---|
126 |
|
---|
127 | case WM_QUIT:
|
---|
128 | dprintf(("OS2: WM_QUIT %x", hwnd));
|
---|
129 | if(win32wnd->MsgQuit()) {
|
---|
130 | goto RunDefWndProc;
|
---|
131 | }
|
---|
132 | break;
|
---|
133 |
|
---|
134 | case WM_CLOSE:
|
---|
135 | dprintf(("OS2: WM_CLOSE %x", hwnd));
|
---|
136 | if(win32wnd->MsgClose()) {
|
---|
137 | goto RunDefWndProc;
|
---|
138 | }
|
---|
139 | break;
|
---|
140 |
|
---|
141 | case WM_DESTROY:
|
---|
142 | dprintf(("OS2: WM_DESTROY %x", hwnd));
|
---|
143 | if(win32wnd->MsgDestroy()) {
|
---|
144 | goto RunDefWndProc;
|
---|
145 | }
|
---|
146 | break;
|
---|
147 |
|
---|
148 | case WM_ENABLE:
|
---|
149 | dprintf(("OS2: WM_ENABLE %x", hwnd));
|
---|
150 | if(win32wnd->MsgEnable((ULONG)mp1)) {
|
---|
151 | goto RunDefWndProc;
|
---|
152 | }
|
---|
153 | break;
|
---|
154 |
|
---|
155 | case WM_SHOW:
|
---|
156 | dprintf(("OS2: WM_SHOW %x", hwnd));
|
---|
157 | if(win32wnd->MsgShow((ULONG)mp1)) {
|
---|
158 | goto RunDefWndProc;
|
---|
159 | }
|
---|
160 | break;
|
---|
161 |
|
---|
162 | case WM_MOVE:
|
---|
163 | {
|
---|
164 | RECTLOS2 rectChild;
|
---|
165 | ULONG x, y;
|
---|
166 |
|
---|
167 | dprintf(("OS2: WM_MOVE %x", hwnd));
|
---|
168 |
|
---|
169 | WinQueryWindowRect(hwnd, (PRECTL)&rectChild);
|
---|
170 |
|
---|
171 | //Calculate position relative to parent window (real window or desktop)
|
---|
172 | x = rectChild.xLeft;
|
---|
173 | y = MapOS2ToWin32Y(hwnd, &rectChild, rectChild.yBottom);
|
---|
174 |
|
---|
175 | if(win32wnd->MsgMove(x, y)) {
|
---|
176 | goto RunDefWndProc;
|
---|
177 | }
|
---|
178 | break;
|
---|
179 | }
|
---|
180 |
|
---|
181 | case WM_WINDOWPOSCHANGED:
|
---|
182 | {
|
---|
183 | dprintf(("OS2: WM_WINDOWPOSCHANGED %x", hwnd));
|
---|
184 | }
|
---|
185 |
|
---|
186 | case WM_ADJUSTWINDOWPOS:
|
---|
187 | {
|
---|
188 | dprintf(("OS2: WM_ADJUSTWINDOWPOS %x", hwnd));
|
---|
189 | // if(win32wnd->MsgWindowPosChanging(0, 0)) {
|
---|
190 | goto RunDefWndProc;
|
---|
191 | // }
|
---|
192 | break;
|
---|
193 | }
|
---|
194 |
|
---|
195 | case WM_ERASEBACKGROUND:
|
---|
196 | {
|
---|
197 | HPS hps;
|
---|
198 |
|
---|
199 | dprintf(("OS2: WM_ERASEBACKGROUND %x", hwnd));
|
---|
200 | hps = WinGetPS(hwnd);
|
---|
201 | if(!win32wnd->MsgEraseBackGround((ULONG)hps))
|
---|
202 | {
|
---|
203 | /*
|
---|
204 | * Return TRUE to request PM to paint the window background
|
---|
205 | * in SYSCLR_WINDOW.
|
---|
206 | */
|
---|
207 | WinReleasePS(hps);
|
---|
208 | return (MRESULT)( TRUE );
|
---|
209 | }
|
---|
210 | WinReleasePS(hps);
|
---|
211 | return (MRESULT) FALSE;
|
---|
212 | }
|
---|
213 | case WM_SIZE:
|
---|
214 | {
|
---|
215 | SWP swp;
|
---|
216 |
|
---|
217 | dprintf(("OS2: WM_SIZE %x", hwnd));
|
---|
218 | rc = WinQueryWindowPos(hwnd, &swp);
|
---|
219 | if(rc == FALSE) {
|
---|
220 | dprintf(("WM_SIZE: WinQueryWindowPos failed!"));
|
---|
221 | break;
|
---|
222 | }
|
---|
223 | if(win32wnd->MsgSize(SHORT1FROMMP(mp2), SHORT2FROMMP(mp2),
|
---|
224 | (swp.fl & SWP_MINIMIZE) != 0,
|
---|
225 | (swp.fl & SWP_MAXIMIZE) != 0))
|
---|
226 | {
|
---|
227 | goto RunDefWndProc;
|
---|
228 | }
|
---|
229 | break;
|
---|
230 | }
|
---|
231 |
|
---|
232 | case WM_ACTIVATE:
|
---|
233 | {
|
---|
234 | HWND hwndActivate = (HWND)mp1;
|
---|
235 |
|
---|
236 | dprintf(("OS2: WM_ACTIVATE %x", hwnd));
|
---|
237 | if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
|
---|
238 | //another (non-win32) application's window
|
---|
239 | //set to NULL (allowed according to win32 SDK) to avoid problems
|
---|
240 | hwndActivate = NULL;
|
---|
241 | }
|
---|
242 | if(win32wnd->MsgActivate(1, hwndActivate)) {
|
---|
243 | goto RunDefWndProc;
|
---|
244 | }
|
---|
245 | break;
|
---|
246 | }
|
---|
247 | case WM_FOCUSCHANGE:
|
---|
248 | dprintf(("OS2: WM_FOCUSCHANGE %x", hwnd));
|
---|
249 | goto RunDefWndProc;
|
---|
250 |
|
---|
251 | case WM_SETFOCUS:
|
---|
252 | {
|
---|
253 | HWND hwndFocus = (HWND)mp1;
|
---|
254 |
|
---|
255 | dprintf(("OS2: WM_SETFOCUS %x", hwnd));
|
---|
256 | if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
|
---|
257 | //another (non-win32) application's window
|
---|
258 | //set to NULL (allowed according to win32 SDK) to avoid problems
|
---|
259 | hwndFocus = NULL;
|
---|
260 | }
|
---|
261 | if((ULONG)mp2 == TRUE) {
|
---|
262 | rc = win32wnd->MsgSetFocus(hwndFocus);
|
---|
263 | }
|
---|
264 | else rc = win32wnd->MsgKillFocus(hwndFocus);
|
---|
265 | if(rc) {
|
---|
266 | goto RunDefWndProc;
|
---|
267 | }
|
---|
268 | break;
|
---|
269 | }
|
---|
270 | //**************************************************************************
|
---|
271 | //Mouse messages
|
---|
272 | //**************************************************************************
|
---|
273 | case WM_BUTTON1DOWN:
|
---|
274 | dprintf(("OS2: WM_BUTTON1DOWN %x", hwnd));
|
---|
275 | if(win32wnd->MsgButton(BUTTON_LEFTDOWN, (*(POINTS *)&mp1).x, MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
|
---|
276 | goto RunDefWndProc;
|
---|
277 | }
|
---|
278 | break;
|
---|
279 | case WM_BUTTON1UP:
|
---|
280 | dprintf(("OS2: WM_BUTTON1UP %x", hwnd));
|
---|
281 | if(win32wnd->MsgButton(BUTTON_LEFTUP, (*(POINTS *)&mp1).x, MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
|
---|
282 | goto RunDefWndProc;
|
---|
283 | }
|
---|
284 | break;
|
---|
285 | case WM_BUTTON1DBLCLK:
|
---|
286 | if(win32wnd->MsgButton(BUTTON_LEFTDBLCLICK, (*(POINTS *)&mp1).x, MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
|
---|
287 | goto RunDefWndProc;
|
---|
288 | }
|
---|
289 | break;
|
---|
290 | case WM_BUTTON2DOWN:
|
---|
291 | if(win32wnd->MsgButton(BUTTON_RIGHTDOWN, (*(POINTS *)&mp1).x, MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
|
---|
292 | goto RunDefWndProc;
|
---|
293 | }
|
---|
294 | break;
|
---|
295 | case WM_BUTTON2UP:
|
---|
296 | if(win32wnd->MsgButton(BUTTON_RIGHTUP, (*(POINTS *)&mp1).x,MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
|
---|
297 | goto RunDefWndProc;
|
---|
298 | }
|
---|
299 | break;
|
---|
300 | case WM_BUTTON2DBLCLK:
|
---|
301 | if(win32wnd->MsgButton(BUTTON_RIGHTDBLCLICK, (*(POINTS *)&mp1).x,MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
|
---|
302 | goto RunDefWndProc;
|
---|
303 | }
|
---|
304 | break;
|
---|
305 | case WM_BUTTON3DOWN:
|
---|
306 | if(win32wnd->MsgButton(BUTTON_MIDDLEDOWN, (*(POINTS *)&mp1).x, MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
|
---|
307 | goto RunDefWndProc;
|
---|
308 | }
|
---|
309 | break;
|
---|
310 | case WM_BUTTON3UP:
|
---|
311 | if(win32wnd->MsgButton(BUTTON_MIDDLEUP, (*(POINTS *)&mp1).x,MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
|
---|
312 | goto RunDefWndProc;
|
---|
313 | }
|
---|
314 | break;
|
---|
315 | case WM_BUTTON3DBLCLK:
|
---|
316 | if(win32wnd->MsgButton(BUTTON_MIDDLEDBLCLICK, (*(POINTS *)&mp1).x,MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
|
---|
317 | goto RunDefWndProc;
|
---|
318 | }
|
---|
319 | break;
|
---|
320 |
|
---|
321 | case WM_BUTTON2MOTIONSTART:
|
---|
322 | case WM_BUTTON2MOTIONEND:
|
---|
323 | case WM_BUTTON2CLICK:
|
---|
324 | case WM_BUTTON1MOTIONSTART:
|
---|
325 | case WM_BUTTON1MOTIONEND:
|
---|
326 | case WM_BUTTON1CLICK:
|
---|
327 | case WM_BUTTON3MOTIONSTART:
|
---|
328 | case WM_BUTTON3MOTIONEND:
|
---|
329 | case WM_BUTTON3CLICK:
|
---|
330 | goto RunDefWndProc;
|
---|
331 |
|
---|
332 | case WM_MOUSEMOVE:
|
---|
333 | {
|
---|
334 | ULONG keystate = 0;
|
---|
335 | if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1))
|
---|
336 | keystate |= WMMOVE_LBUTTON;
|
---|
337 | if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2))
|
---|
338 | keystate |= WMMOVE_MBUTTON;
|
---|
339 | if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3))
|
---|
340 | keystate |= WMMOVE_RBUTTON;
|
---|
341 | if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT))
|
---|
342 | keystate |= WMMOVE_SHIFT;
|
---|
343 | if(WinGetKeyState(HWND_DESKTOP, VK_CTRL))
|
---|
344 | keystate |= WMMOVE_CTRL;
|
---|
345 |
|
---|
346 | if(!win32wnd->MsgMouseMove(keystate, (*(POINTS *)&mp1).x, MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
|
---|
347 | goto RunDefWndProc;
|
---|
348 | }
|
---|
349 | break;
|
---|
350 | }
|
---|
351 |
|
---|
352 | //**************************************************************************
|
---|
353 | //Slider messages
|
---|
354 | //**************************************************************************
|
---|
355 | case WM_VSCROLL:
|
---|
356 | case WM_HSCROLL:
|
---|
357 |
|
---|
358 | case WM_CONTROL:
|
---|
359 |
|
---|
360 | case WM_COMMAND:
|
---|
361 | case WM_SYSCOMMAND:
|
---|
362 |
|
---|
363 | case WM_CHAR:
|
---|
364 |
|
---|
365 | case WM_INITMENU:
|
---|
366 | case WM_MENUSELECT:
|
---|
367 | case WM_MENUEND:
|
---|
368 | case WM_NEXTMENU:
|
---|
369 |
|
---|
370 | case WM_TIMER:
|
---|
371 | goto RunDefWndProc;
|
---|
372 |
|
---|
373 | case WM_SETWINDOWPARAMS:
|
---|
374 | {
|
---|
375 | WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
|
---|
376 |
|
---|
377 | dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
|
---|
378 | if(wndParams->fsStatus & WPM_TEXT) {
|
---|
379 | if(win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText)) {
|
---|
380 | goto RunDefWndProc;
|
---|
381 | }
|
---|
382 | }
|
---|
383 | goto RunDefWndProc;
|
---|
384 | }
|
---|
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_HITTEST:
|
---|
394 | if(win32wnd->MsgHitTest((*(POINTS *)&mp1).x, MapOS2ToWin32Y(hwnd, (*(POINTS *)&mp1).y))) {
|
---|
395 | goto RunDefWndProc;
|
---|
396 | }
|
---|
397 | break;
|
---|
398 |
|
---|
399 | case WM_SYSCOLORCHANGE:
|
---|
400 | case WM_SYSVALUECHANGED:
|
---|
401 | case WM_CALCVALIDRECTS:
|
---|
402 | case WM_QUERYWINDOWPARAMS:
|
---|
403 | case WM_SETSELECTION:
|
---|
404 | case WM_PPAINT:
|
---|
405 | case WM_PSETFOCUS:
|
---|
406 | case WM_PSYSCOLORCHANGE:
|
---|
407 | case WM_PSIZE:
|
---|
408 | case WM_PACTIVATE:
|
---|
409 | case WM_PCONTROL:
|
---|
410 | case WM_HELP:
|
---|
411 | case WM_APPTERMINATENOTIFY:
|
---|
412 | case WM_PRESPARAMCHANGED:
|
---|
413 | case WM_DRAWITEM:
|
---|
414 | case WM_MEASUREITEM:
|
---|
415 | case WM_CONTROLPOINTER:
|
---|
416 | case WM_QUERYDLGCODE:
|
---|
417 | case WM_SUBSTITUTESTRING:
|
---|
418 | case WM_MATCHMNEMONIC:
|
---|
419 | case WM_SAVEAPPLICATION:
|
---|
420 | case WM_SEMANTICEVENT:
|
---|
421 | default:
|
---|
422 | dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
|
---|
423 | RestoreOS2TIB();
|
---|
424 | return WinDefWindowProc( hwnd, msg, mp1, mp2 );
|
---|
425 | }
|
---|
426 | RestoreOS2TIB();
|
---|
427 | return (MRESULT)FALSE;
|
---|
428 |
|
---|
429 | RunDefWndProc:
|
---|
430 | dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
|
---|
431 | RestoreOS2TIB();
|
---|
432 | return WinDefWindowProc( hwnd, msg, mp1, mp2 );
|
---|
433 | } /* End of Win32WindowProc */
|
---|
434 | //******************************************************************************
|
---|
435 | //******************************************************************************
|
---|