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

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

Accelerator support (not working) + bugfixes

File size: 14.2 KB
Line 
1/* $Id: pmwindow.cpp,v 1.13 1999-07-20 07:42: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#include "oslibmsg.h"
27
28HMQ hmq = 0; /* Message queue handle */
29HAB hab = 0;
30
31MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
32
33//******************************************************************************
34//Initialize PM; create hab, message queue and register special Win32 window classes
35//******************************************************************************
36BOOL InitPM()
37{
38 hab = WinInitialize(0);
39 dprintf(("Winitialize returned %x", hab));
40 hmq = WinCreateMsgQueue(hab, 0);
41
42 if(!hab || !hmq)
43 {
44 UINT error;
45 //CB: only fail on real error
46 error = WinGetLastError(hab) & 0xFFFF; //error code
47 if (!hab || error != PMERR_MSG_QUEUE_ALREADY_EXISTS)
48 {
49 dprintf(("WinInitialize or WinCreateMsgQueue failed %x %x", hab, hmq));
50 dprintf((" Error = %x",error));
51 return(FALSE);
52 }
53 else
54 {
55 if(!hab) {
56 hab = WinQueryAnchorBlock(HWND_DESKTOP);
57 dprintf(("WinQueryAnchorBlock returned %x", hab));
58 }
59 if(!hmq) {
60 hmq = HMQ_CURRENT;
61 }
62 }
63 }
64 SetThreadHAB(hab);
65 dprintf(("InitPM: hmq = %x", hmq));
66 SetThreadMessageQueue(hmq);
67
68 if(!WinRegisterClass( /* Register window class */
69 hab, /* Anchor block handle */
70 (PSZ)WIN32_STDCLASS, /* Window class name */
71 (PFNWP)Win32WindowProc, /* Address of window procedure */
72 CS_SIZEREDRAW | CS_HITTEST,
73 8)) {
74 dprintf(("WinRegisterClass Win32Window failed"));
75 return(FALSE);
76 }
77
78 return OSLibInitMsgQueue();
79} /* End of main */
80//******************************************************************************
81//Win32 window message handler
82//******************************************************************************
83MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
84{
85 POSTMSG_PACKET *postmsg;
86 OSLIBPOINT point;
87 Win32Window *win32wnd;
88 APIRET rc;
89
90 //Restore our FS selector
91 SetWin32TIB();
92
93 win32wnd = Win32Window::GetWindowFromOS2Handle(hwnd);
94
95 if(msg != WM_CREATE && win32wnd == NULL) {
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_ADJUSTWINDOWPOS:
165 {
166 ULONG x, y;
167 PSWP pswp = (PSWP)mp1;
168
169 dprintf(("OS2: WM_ADJUSTWINDOWPOS %x", hwnd));
170
171 if(pswp->fl & SWP_MOVE) {
172 if(win32wnd->isChild()) {
173 x = pswp->x;
174 y = pswp->cy - y - 1;
175 }
176 else {
177 OSLIBPOINT point;
178
179 point.x = pswp->x;
180 point.y = pswp->y;
181
182 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
183 x = point.x;
184 y = point.y;
185 }
186 if(win32wnd->MsgMove(x, y)) {
187 goto RunDefWndProc;
188 }
189 break;
190 }
191 goto RunDefWndProc;
192 }
193
194 case WM_WINDOWPOSCHANGED:
195 {
196 dprintf(("OS2: WM_WINDOWPOSCHANGED %x", hwnd));
197 goto RunDefWndProc;
198 }
199
200 case WM_ERASEBACKGROUND:
201 {
202 HPS hps;
203
204 dprintf(("OS2: WM_ERASEBACKGROUND %x", hwnd));
205 hps = WinGetPS(hwnd);
206 if(!win32wnd->MsgEraseBackGround((ULONG)hps))
207 {
208 /*
209 * Return TRUE to request PM to paint the window background
210 * in SYSCLR_WINDOW.
211 */
212 WinReleasePS(hps);
213 return (MRESULT)( TRUE );
214 }
215 WinReleasePS(hps);
216 return (MRESULT) FALSE;
217 }
218 case WM_SIZE:
219 {
220 SWP swp;
221
222 dprintf(("OS2: WM_SIZE %x", hwnd));
223 rc = WinQueryWindowPos(hwnd, &swp);
224 if(rc == FALSE) {
225 dprintf(("WM_SIZE: WinQueryWindowPos failed!"));
226 break;
227 }
228 if(win32wnd->MsgSize(SHORT1FROMMP(mp2), SHORT2FROMMP(mp2),
229 (swp.fl & SWP_MINIMIZE) != 0,
230 (swp.fl & SWP_MAXIMIZE) != 0))
231 {
232 goto RunDefWndProc;
233 }
234 break;
235 }
236
237 case WM_ACTIVATE:
238 {
239 HWND hwndActivate = (HWND)mp1;
240
241 dprintf(("OS2: WM_ACTIVATE %x", hwnd));
242 if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
243 //another (non-win32) application's window
244 //set to NULL (allowed according to win32 SDK) to avoid problems
245 hwndActivate = NULL;
246 }
247 if(win32wnd->MsgActivate(1, hwndActivate)) {
248 goto RunDefWndProc;
249 }
250 break;
251 }
252 case WM_FOCUSCHANGE:
253 dprintf(("OS2: WM_FOCUSCHANGE %x", hwnd));
254 goto RunDefWndProc;
255
256 case WM_SETFOCUS:
257 {
258 HWND hwndFocus = (HWND)mp1;
259
260 dprintf(("OS2: WM_SETFOCUS %x", hwnd));
261 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
262 //another (non-win32) application's window
263 //set to NULL (allowed according to win32 SDK) to avoid problems
264 hwndFocus = NULL;
265 }
266 if((ULONG)mp2 == TRUE) {
267 rc = win32wnd->MsgSetFocus(hwndFocus);
268 }
269 else rc = win32wnd->MsgKillFocus(hwndFocus);
270 if(rc) {
271 goto RunDefWndProc;
272 }
273 break;
274 }
275 //**************************************************************************
276 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
277 //**************************************************************************
278 case WM_BUTTON1DOWN:
279 dprintf(("OS2: WM_BUTTON1DOWN %x", hwnd));
280 point.x = (*(POINTS *)&mp1).x;
281 point.y = (*(POINTS *)&mp1).y;
282 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
283 if(win32wnd->MsgButton(BUTTON_LEFTDOWN, point.x, point.y)) {
284 goto RunDefWndProc;
285 }
286 break;
287
288 case WM_BUTTON1UP:
289 dprintf(("OS2: WM_BUTTON1UP %x", hwnd));
290 point.x = (*(POINTS *)&mp1).x;
291 point.y = (*(POINTS *)&mp1).y;
292 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
293 if(win32wnd->MsgButton(BUTTON_LEFTUP, point.x, point.y)) {
294 goto RunDefWndProc;
295 }
296 break;
297 case WM_BUTTON1DBLCLK:
298 point.x = (*(POINTS *)&mp1).x;
299 point.y = (*(POINTS *)&mp1).y;
300 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
301 if(win32wnd->MsgButton(BUTTON_LEFTDBLCLICK, point.x, point.y)) {
302 goto RunDefWndProc;
303 }
304 break;
305 case WM_BUTTON2DOWN:
306 point.x = (*(POINTS *)&mp1).x;
307 point.y = (*(POINTS *)&mp1).y;
308 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
309 if(win32wnd->MsgButton(BUTTON_RIGHTDOWN, point.x, point.y)) {
310 goto RunDefWndProc;
311 }
312 break;
313 case WM_BUTTON2UP:
314 point.x = (*(POINTS *)&mp1).x;
315 point.y = (*(POINTS *)&mp1).y;
316 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
317 if(win32wnd->MsgButton(BUTTON_RIGHTUP, point.x, point.y)) {
318 goto RunDefWndProc;
319 }
320 break;
321 case WM_BUTTON2DBLCLK:
322 point.x = (*(POINTS *)&mp1).x;
323 point.y = (*(POINTS *)&mp1).y;
324 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
325 if(win32wnd->MsgButton(BUTTON_RIGHTDBLCLICK, point.x, point.y)) {
326 goto RunDefWndProc;
327 }
328 break;
329 case WM_BUTTON3DOWN:
330 point.x = (*(POINTS *)&mp1).x;
331 point.y = (*(POINTS *)&mp1).y;
332 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
333 if(win32wnd->MsgButton(BUTTON_MIDDLEDOWN, point.x, point.y)) {
334 goto RunDefWndProc;
335 }
336 break;
337 case WM_BUTTON3UP:
338 point.x = (*(POINTS *)&mp1).x;
339 point.y = (*(POINTS *)&mp1).y;
340 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
341 if(win32wnd->MsgButton(BUTTON_MIDDLEUP, point.x, point.y)) {
342 goto RunDefWndProc;
343 }
344 break;
345 case WM_BUTTON3DBLCLK:
346 point.x = (*(POINTS *)&mp1).x;
347 point.y = (*(POINTS *)&mp1).y;
348 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
349 if(win32wnd->MsgButton(BUTTON_MIDDLEDBLCLICK, point.x, point.y)) {
350 goto RunDefWndProc;
351 }
352 break;
353
354 case WM_BUTTON2MOTIONSTART:
355 case WM_BUTTON2MOTIONEND:
356 case WM_BUTTON2CLICK:
357 case WM_BUTTON1MOTIONSTART:
358 case WM_BUTTON1MOTIONEND:
359 case WM_BUTTON1CLICK:
360 case WM_BUTTON3MOTIONSTART:
361 case WM_BUTTON3MOTIONEND:
362 case WM_BUTTON3CLICK:
363 goto RunDefWndProc;
364
365 case WM_MOUSEMOVE:
366 {
367 ULONG keystate = 0;
368 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1))
369 keystate |= WMMOVE_LBUTTON;
370 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2))
371 keystate |= WMMOVE_MBUTTON;
372 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3))
373 keystate |= WMMOVE_RBUTTON;
374 if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT))
375 keystate |= WMMOVE_SHIFT;
376 if(WinGetKeyState(HWND_DESKTOP, VK_CTRL))
377 keystate |= WMMOVE_CTRL;
378
379 //OS/2 Window coordinates -> Win32 Window coordinates
380 if(!win32wnd->MsgMouseMove(keystate, SHORT1FROMMP(mp1), MapOS2ToWin32Y(win32wnd, SHORT2FROMMP(mp1)))) {
381 goto RunDefWndProc;
382 }
383 break;
384 }
385
386 //**************************************************************************
387 //Slider messages
388 //**************************************************************************
389 case WM_VSCROLL:
390 case WM_HSCROLL:
391
392 case WM_CONTROL:
393
394 case WM_COMMAND:
395 if(SHORT1FROMMP(mp2) == CMDSRC_MENU) {
396 win32wnd->MsgCommand(CMD_MENU, SHORT1FROMMP(mp1), 0);
397 }
398 if(SHORT1FROMMP(mp2) == CMDSRC_ACCELERATOR) {
399 win32wnd->MsgCommand(CMD_ACCELERATOR, SHORT1FROMMP(mp1), 0);
400 }
401 //todo controls + accelerators
402 break;
403
404 case WM_SYSCOMMAND:
405 dprintf(("WM_SYSCOMMAND"));
406 break;
407
408 case WM_CHAR:
409 dprintf(("WM_CHAR"));
410
411 case WM_INITMENU:
412 case WM_MENUSELECT:
413 case WM_MENUEND:
414 case WM_NEXTMENU:
415
416 case WM_TIMER:
417 goto RunDefWndProc;
418
419 case WM_SETWINDOWPARAMS:
420 {
421 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
422
423 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
424 if(wndParams->fsStatus & WPM_TEXT) {
425 if(win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText)) {
426 goto RunDefWndProc;
427 }
428 }
429 goto RunDefWndProc;
430 }
431
432 case WM_PAINT:
433 dprintf(("OS2: WM_PAINT %x", hwnd));
434 if(win32wnd->MsgPaint(0, 0)) {
435 goto RunDefWndProc;
436 }
437 break;
438
439 case WM_HITTEST:
440 if(win32wnd->MsgHitTest((*(POINTS *)&mp1).x, MapOS2ToWin32Y(OSLIB_HWND_DESKTOP, hwnd, (*(POINTS *)&mp1).y))) {
441 goto RunDefWndProc;
442 }
443 break;
444
445 case WM_SYSCOLORCHANGE:
446 case WM_SYSVALUECHANGED:
447 case WM_CALCVALIDRECTS:
448 case WM_QUERYWINDOWPARAMS:
449 case WM_SETSELECTION:
450 case WM_PPAINT:
451 case WM_PSETFOCUS:
452 case WM_PSYSCOLORCHANGE:
453 case WM_PSIZE:
454 case WM_PACTIVATE:
455 case WM_PCONTROL:
456 case WM_HELP:
457 case WM_APPTERMINATENOTIFY:
458 case WM_PRESPARAMCHANGED:
459 case WM_DRAWITEM:
460 case WM_MEASUREITEM:
461 case WM_CONTROLPOINTER:
462 case WM_QUERYDLGCODE:
463 case WM_SUBSTITUTESTRING:
464 case WM_MATCHMNEMONIC:
465 case WM_SAVEAPPLICATION:
466 case WM_SEMANTICEVENT:
467 default:
468 dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
469 RestoreOS2TIB();
470 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
471 }
472 RestoreOS2TIB();
473 return (MRESULT)FALSE;
474
475RunDefWndProc:
476 dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
477 RestoreOS2TIB();
478 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
479} /* End of Win32WindowProc */
480//******************************************************************************
481//******************************************************************************
Note: See TracBrowser for help on using the repository browser.