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

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

Lots of changes/additions

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