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

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

Send/PostMessage changes

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