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

Last change on this file since 1343 was 1343, checked in by cbratschi, 26 years ago

DrawIcon/DrawIconEx, fixed other icon handling problems

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