source: trunk/src/user32/pmframe.cpp@ 1408

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

Put back pos change messages in pmwindow.cpp, changed message logging

File size: 11.7 KB
Line 
1/* $Id: pmframe.cpp,v 1.10 1999-10-23 10:21:43 sandervl Exp $ */
2/*
3 * Win32 Frame Managment Code for OS/2
4 *
5 * Copyright 1999 by Christoph Bratschi (cbratschi@datacomm.ch)
6 *
7 *
8 * Project Odin Software License can be found in LICENSE.TXT
9 *
10 */
11
12#define INCL_WIN
13#define INCL_GPI
14
15#include <os2.h> /* PM header file */
16#include <os2wrap.h>
17#include <stdlib.h>
18#include "win32type.h"
19#include <misc.h>
20#include <win32wbase.h>
21#include "wprocess.h"
22#include "pmframe.h"
23#include "oslibutil.h"
24#include "oslibwin.h"
25#include "caret.h"
26
27#define PMFRAMELOG
28
29VOID Draw3DRect(HPS hps,RECTL rect,LONG colorBR,LONG colorTL)
30{
31 POINTL point;
32
33 GpiSetColor(hps,colorBR);
34 point.x = rect.xLeft;
35 point.y = rect.yBottom;
36 GpiMove(hps,&point);
37 point.x = rect.xRight-1;
38 GpiLine(hps,&point);
39 point.y = rect.yTop-1;
40 GpiLine(hps,&point);
41 GpiSetColor(hps,colorTL);
42 point.x--;
43 GpiMove(hps,&point);
44 point.x = rect.xLeft;
45 GpiLine(hps,&point);
46 point.y = rect.yBottom+1;
47 GpiLine(hps,&point);
48}
49
50VOID DeflateRect(RECTL *rect)
51{
52 rect->xLeft++;
53 rect->xRight--;
54 rect->yTop--;
55 rect->yBottom++;
56}
57
58VOID DrawFrame(HPS hps,RECTL *rect,Win32BaseWindow *win32wnd)
59{
60 LONG clrWhite,clrBlack,clrDark,clrLight;
61 POINTL point;
62 DWORD dwExStyle = win32wnd->getExStyle();
63 DWORD dwStyle = win32wnd->getStyle();
64
65 clrWhite = CLR_WHITE;
66 clrBlack = CLR_BLACK;
67 clrLight = CLR_PALEGRAY;
68 clrDark = CLR_DARKGRAY;
69
70 if (dwExStyle & WS_EX_CLIENTEDGE_W)
71 {
72 Draw3DRect(hps,*rect,clrWhite,clrDark);
73 DeflateRect(rect);
74 Draw3DRect(hps,*rect,clrLight,clrBlack);
75 } else if (dwExStyle & WS_EX_DLGMODALFRAME_W)
76 {
77 Draw3DRect(hps,*rect,clrBlack,clrLight);
78 DeflateRect(rect);
79 Draw3DRect(hps,*rect,clrDark,clrWhite);
80 DeflateRect(rect);
81 Draw3DRect(hps,*rect,clrLight,clrLight);
82 } else if (dwExStyle & WS_EX_STATICEDGE_W)
83 {
84 Draw3DRect(hps,*rect,clrWhite,clrDark);
85 } else if (dwExStyle & WS_EX_WINDOWEDGE_W);
86 else if (dwStyle & WS_BORDER_W)
87 {
88 Draw3DRect(hps,*rect,clrBlack,clrBlack);
89 }
90
91 DeflateRect(rect);
92}
93
94BOOL CanDrawSizeBox(Win32BaseWindow *win32wnd)
95{
96 return (win32wnd->getStyle() & WS_SIZEBOX_W && WinQueryWindowULong(win32wnd->getOS2FrameWindowHandle(),QWL_STYLE) & FS_SIZEBORDER
97 && win32wnd->getVertScrollHandle() && WinQueryWindow(win32wnd->getVertScrollHandle(),QW_PARENT) == win32wnd->getOS2FrameWindowHandle()
98 && win32wnd->getHorzScrollHandle() && WinQueryWindow(win32wnd->getHorzScrollHandle(),QW_PARENT) == win32wnd->getOS2FrameWindowHandle());
99}
100
101VOID GetSizeBox(Win32BaseWindow *win32wnd,RECTL *rect)
102{
103 SWP swpHorz,swpVert;
104
105 WinQueryWindowPos(win32wnd->getVertScrollHandle(),&swpVert);
106 WinQueryWindowPos(win32wnd->getHorzScrollHandle(),&swpHorz);
107 rect->xLeft = swpVert.x;
108 rect->xRight = swpVert.x+swpVert.cx;
109 rect->yTop = swpHorz.y+swpHorz.cy;
110 rect->yBottom = swpHorz.y;
111}
112
113BOOL InSizeBox(Win32BaseWindow *win32wnd,POINTS *points)
114{
115 if (CanDrawSizeBox(win32wnd))
116 {
117 RECTL rect;
118 POINTL point;
119
120 point.x = points->x;
121 point.y = points->y;
122 GetSizeBox(win32wnd,&rect);
123 return (WinPtInRect(GetThreadHAB(),&rect,&point));
124 }
125
126 return FALSE;
127}
128
129VOID DrawSizeBox(HPS hps,RECTL rect)
130{
131 POINTL p1,p2;
132 LONG clrDark = CLR_DARKGRAY,clrWhite = CLR_WHITE;
133 INT x;
134
135 WinFillRect(hps,&rect,SYSCLR_DIALOGBACKGROUND);
136 p1.x = rect.xRight-2;
137 p1.y = rect.yBottom;
138 p2.x = rect.xRight-1;
139 p2.y = rect.yBottom+1;
140 for (x = 0;x < 3;x++)
141 {
142 GpiSetColor(hps,clrDark);
143 GpiMove(hps,&p1);
144 GpiLine(hps,&p2);
145 p1.x--;
146 p2.y++;
147 GpiMove(hps,&p1);
148 GpiLine(hps,&p2);
149 GpiSetColor(hps,clrWhite);
150 p1.x--;
151 p2.y++;
152 GpiMove(hps,&p1);
153 GpiLine(hps,&p2);
154 p1.x -= 2;
155 p2.y += 2;
156 }
157}
158
159//******************************************************************************
160//Win32 frame message handler
161//******************************************************************************
162MRESULT EXPENTRY Win32FrameProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
163{
164 Win32BaseWindow *win32wnd;
165 PFNWP OldFrameProc;
166 MRESULT rc;
167
168 SetWin32TIB();
169
170 win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
171
172 if(win32wnd == NULL || !win32wnd->getOldFrameProc())
173 {
174 dprintf(("Invalid win32wnd pointer for frame %x!!", hwnd));
175 goto RunDefWndProc;
176 }
177
178 OldFrameProc = (PFNWP)win32wnd->getOldFrameProc();
179
180 switch(msg)
181 {
182#if 0
183 case WM_ADJUSTWINDOWPOS:
184 {
185 PSWP pswp = (PSWP)mp1;
186 SWP swpOld;
187 WINDOWPOS wp;
188 ULONG parentHeight = 0;
189 HWND hParent = NULLHANDLE, hFrame = NULLHANDLE, hwndAfter;
190
191 dprintf(("PMFRAME: WM_ADJUSTWINDOWPOS %x %x %x (%d,%d) (%d,%d)", hwnd, pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
192
193 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
194 goto RunDefFrameProc;
195 if(!win32wnd->CanReceiveSizeMsgs()) {
196 goto RunDefFrameProc;
197 }
198
199 WinQueryWindowPos(hwnd, &swpOld);
200
201 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
202 if (win32wnd->isChild()) {
203 if(win32wnd->getParent()) {
204 hParent = win32wnd->getParent()->getOS2WindowHandle();
205 }
206 else goto RunDefFrameProc;
207 }
208 }
209 hwndAfter = pswp->hwndInsertBehind;
210 hFrame = win32wnd->getOS2FrameWindowHandle();
211 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hFrame);
212
213 wp.hwnd = win32wnd->getWindowHandle();
214 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
215 {
216 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
217 if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
218 }
219 if(win32wnd->MsgPosChanging((LPARAM)&wp) == 0)
220 {//app or default window handler changed wp
221 dprintf(("OS2: WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
222 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
223 OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, hParent, hFrame);
224 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
225 pswp->fl |= SWP_NOADJUST;
226 pswp->hwndInsertBehind = hwndAfter;
227 pswp->hwnd = hFrame;
228
229 RestoreOS2TIB();
230 return (MRESULT)0xf;
231 }
232 break;
233 }
234
235#else
236 case WM_ADJUSTWINDOWPOS:
237 {
238 PSWP pswp = (PSWP)mp1;
239 Win32BaseWindow *wndchild;
240
241 wndchild = Win32BaseWindow::GetWindowFromOS2FrameHandle(pswp->hwnd);
242 if(wndchild && wndchild->isChild())
243 {
244 dprintf(("PMFRAME: WM_ADJUSTWINDOWPOS %x %x %x (%d,%d) (%d,%d)", hwnd, pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
245 RestoreOS2TIB();
246 return (MRESULT)0;
247 }
248 goto RunDefFrameProc;
249 }
250
251#endif
252
253 case WM_DESTROY:
254 #ifdef PMFRAMELOG
255 dprintf(("PMFRAME: WM_DESTROY"));
256 #endif
257 WinSubclassWindow(hwnd,OldFrameProc);
258 win32wnd->setOldFrameProc(NULL);
259 goto RunDefFrameProc;
260
261 case WM_MOUSEMOVE:
262 if (InSizeBox(win32wnd,(POINTS*)&mp1))
263 {
264 WinSetPointer(HWND_DESKTOP,WinQuerySysPointer(HWND_DESKTOP,SPTR_SIZENWSE,FALSE));
265 RestoreOS2TIB();
266 return (MRESULT)TRUE;
267 } else if (win32wnd->isChild()) goto RunDefWndProc;
268 else goto RunDefFrameProc;
269
270 case WM_BUTTON1DOWN:
271 #ifdef PMFRAMELOG
272 dprintf(("PMFRAME: WM_BUTTON1DOWN"));
273 #endif
274 if (InSizeBox(win32wnd,(POINTS*)&mp1))
275 {
276 WinSendMsg(hwnd,WM_TRACKFRAME,(MPARAM)(TF_RIGHT | TF_BOTTOM),(MPARAM)0);
277 RestoreOS2TIB();
278 return (MRESULT)TRUE;
279 } else if (win32wnd->isChild()) goto RunDefWndProc;
280 else goto RunDefFrameProc;
281
282 case WM_BUTTON2DOWN:
283 case WM_BUTTON3DOWN:
284 #ifdef PMFRAMELOG
285 dprintf(("PMFRAME: WM_BUTTON2/3DOWN"));
286 #endif
287 if (win32wnd->isChild()) goto RunDefWndProc;
288 else goto RunDefFrameProc;
289
290 case WM_ACTIVATE:
291 #ifdef PMFRAMELOG
292 dprintf(("PMFRAME: WM_ACTIVATE"));
293 #endif
294 if (!win32wnd->isChild())
295 {
296 if (CanDrawSizeBox(win32wnd))
297 {
298 MRESULT res;
299 HPS hps;
300 RECTL rect;
301
302 RestoreOS2TIB();
303 res = OldFrameProc(hwnd,msg,mp1,mp2);
304 SetWin32TIB();
305
306 GetSizeBox(win32wnd,&rect);
307 hps = WinGetClipPS(hwnd,0,PSF_CLIPCHILDREN | PSF_CLIPSIBLINGS);
308 DrawSizeBox(hps,rect);
309 WinReleasePS(hps);
310
311 RestoreOS2TIB();
312 return res;
313 } else goto RunDefFrameProc;
314 } else
315 {
316 MRESULT res;
317 HPS hps;
318 RECTL rect;
319
320 RestoreOS2TIB();
321 res = OldFrameProc(hwnd,msg,mp1,mp2);
322 SetWin32TIB();
323
324 WinQueryWindowRect(hwnd,&rect);
325 rect.xRight = rect.xRight-rect.xLeft;
326 rect.yTop = rect.yTop-rect.yBottom;
327 rect.xLeft = rect.yBottom = 0;
328 hps = WinGetClipPS(hwnd,0,PSF_CLIPCHILDREN | PSF_CLIPSIBLINGS);
329 DrawFrame(hps,&rect,win32wnd);
330 WinReleasePS(hps);
331
332 RestoreOS2TIB();
333 return res;
334 }
335
336 case WM_PAINT:
337 #ifdef PMFRAMELOG
338 dprintf(("PMFRAME: WM_PAINT"));
339 #endif
340 if (!win32wnd->isChild())
341 {
342 if (CanDrawSizeBox(win32wnd))
343 {
344 MRESULT res;
345 HPS hps;
346 RECTL rect;
347
348 RestoreOS2TIB();
349 res = OldFrameProc(hwnd,msg,mp1,mp2);
350 SetWin32TIB();
351
352 GetSizeBox(win32wnd,&rect);
353 hps = WinGetClipPS(hwnd,0,PSF_CLIPCHILDREN | PSF_CLIPSIBLINGS);
354 DrawSizeBox(hps,rect);
355 WinReleasePS(hps);
356
357 RestoreOS2TIB();
358 return res;
359 } else goto RunDefFrameProc;
360 } else
361 {
362 RECTL rect;
363 HPS hps;
364
365 RestoreOS2TIB();
366 OldFrameProc(hwnd,msg,mp1,mp2);
367 SetWin32TIB();
368
369 WinQueryWindowRect(hwnd,&rect);
370 rect.xRight = rect.xRight-rect.xLeft;
371 rect.yTop = rect.yTop-rect.yBottom;
372 rect.xLeft = rect.yBottom = 0;
373 hps = WinGetClipPS(hwnd,0,PSF_CLIPCHILDREN | PSF_CLIPSIBLINGS);
374 DrawFrame(hps,&rect,win32wnd);
375 WinReleasePS(hps);
376
377 RestoreOS2TIB();
378 return (MRESULT)0;
379 }
380
381 default:
382 RestoreOS2TIB();
383 return OldFrameProc(hwnd,msg,mp1,mp2);
384 }
385
386 RestoreOS2TIB();
387 return (MRESULT)FALSE;
388
389RunDefFrameProc:
390 RestoreOS2TIB();
391 return OldFrameProc(hwnd,msg,mp1,mp2);
392
393RunDefWndProc:
394 RestoreOS2TIB();
395 return WinDefWindowProc(hwnd,msg,mp1,mp2);
396}
397
398PVOID FrameSubclassFrameWindow(Win32BaseWindow *win32wnd)
399{
400 return WinSubclassWindow(win32wnd->getOS2FrameWindowHandle(),PFNWP(Win32FrameProc));
401}
402
403VOID FrameGetBorderSize(Win32BaseWindow *win32wnd,PWPOINT pSize)
404{
405 WinSendMsg(win32wnd->getOS2FrameWindowHandle(),WM_QUERYBORDERSIZE,(MPARAM)pSize,(MPARAM)0);
406}
407
408VOID FrameSetBorderSize(Win32BaseWindow *win32wnd,BOOL resize)
409{
410 POINTL point;
411
412 if (!resize)
413 {
414 WinSendMsg(win32wnd->getOS2FrameWindowHandle(),WM_SETBORDERSIZE,(MPARAM)win32wnd->getBorderWidth(),(MPARAM)win32wnd->getBorderHeight());
415
416 return;
417 }
418
419 FrameGetBorderSize(win32wnd,&point);
420 WinSendMsg(win32wnd->getOS2FrameWindowHandle(),WM_SETBORDERSIZE,(MPARAM)win32wnd->getBorderWidth(),(MPARAM)win32wnd->getBorderHeight());
421 if (point.x != win32wnd->getBorderWidth() || point.y != win32wnd->getBorderHeight())
422 {
423 INT xDiff = win32wnd->getBorderWidth()-point.x;
424 INT yDiff = win32wnd->getBorderHeight()-point.y;
425 SWP swp;
426
427 WinQueryWindowPos(win32wnd->getOS2FrameWindowHandle(),&swp);
428 swp.x += xDiff;
429 swp.y += yDiff;
430 swp.cx -= 2*xDiff;
431 swp.cy -= 2*yDiff;
432 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),0,swp.x,swp.y,swp.cx,swp.cy,SWP_MOVE | SWP_SIZE);
433 }
434}
435
436UINT FrameGetDefSizeBorderSize(VOID)
437{
438 return WinQuerySysValue(HWND_DESKTOP,SV_CXSIZEBORDER);
439}
Note: See TracBrowser for help on using the repository browser.