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

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

mouse activate + CreateIconIndirect fix

File size: 17.6 KB
Line 
1/* $Id: pmframe.cpp,v 1.19 1999-11-03 19:51: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
29//******************************************************************************
30//******************************************************************************
31VOID Draw3DRect(HPS hps,RECTL rect,LONG colorBR,LONG colorTL)
32{
33 POINTL point;
34
35 GpiSetColor(hps,colorBR);
36 point.x = rect.xLeft;
37 point.y = rect.yBottom;
38 GpiMove(hps,&point);
39 point.x = rect.xRight-1;
40 GpiLine(hps,&point);
41 point.y = rect.yTop-1;
42 GpiLine(hps,&point);
43 GpiSetColor(hps,colorTL);
44 point.x--;
45 GpiMove(hps,&point);
46 point.x = rect.xLeft;
47 GpiLine(hps,&point);
48 point.y = rect.yBottom+1;
49 GpiLine(hps,&point);
50}
51//******************************************************************************
52//******************************************************************************
53VOID DeflateRect(RECTL *rect)
54{
55 rect->xLeft++;
56 rect->xRight--;
57 rect->yTop--;
58 rect->yBottom++;
59}
60//******************************************************************************
61//******************************************************************************
62VOID DrawFrame(HPS hps,RECTL *rect,Win32BaseWindow *win32wnd)
63{
64 LONG clrWhite,clrBlack,clrDark,clrLight;
65 POINTL point;
66 DWORD dwExStyle = win32wnd->getExStyle();
67 DWORD dwStyle = win32wnd->getStyle();
68
69 //CB: todo: switch to RGB mode and use win colors
70 clrWhite = CLR_WHITE;
71 clrBlack = CLR_BLACK;
72 clrLight = CLR_PALEGRAY;
73 clrDark = CLR_DARKGRAY;
74
75 if (dwExStyle & WS_EX_CLIENTEDGE_W)
76 {
77 Draw3DRect(hps,*rect,clrWhite,clrDark);
78 DeflateRect(rect);
79 Draw3DRect(hps,*rect,clrLight,clrBlack);
80 }
81 else if (dwExStyle & WS_EX_DLGMODALFRAME_W)
82 {
83 Draw3DRect(hps,*rect,clrBlack,clrLight);
84 DeflateRect(rect);
85 Draw3DRect(hps,*rect,clrDark,clrWhite);
86 DeflateRect(rect);
87 Draw3DRect(hps,*rect,clrLight,clrLight);
88 }
89 else if (dwExStyle & WS_EX_STATICEDGE_W)
90 {
91 Draw3DRect(hps,*rect,clrWhite,clrDark);
92 }
93 else if (dwExStyle & WS_EX_WINDOWEDGE_W);
94 else if (dwStyle & WS_BORDER_W)
95 {
96 Draw3DRect(hps,*rect,clrBlack,clrBlack);
97 }
98
99 DeflateRect(rect);
100}
101//******************************************************************************
102//******************************************************************************
103BOOL CanDrawSizeBox(Win32BaseWindow *win32wnd)
104{
105 return (win32wnd->getStyle() & WS_SIZEBOX_W && WinQueryWindowULong(win32wnd->getOS2FrameWindowHandle(),QWL_STYLE) & FS_SIZEBORDER
106 && win32wnd->getVertScrollHandle() && WinQueryWindow(win32wnd->getVertScrollHandle(),QW_PARENT) == win32wnd->getOS2FrameWindowHandle()
107 && win32wnd->getHorzScrollHandle() && WinQueryWindow(win32wnd->getHorzScrollHandle(),QW_PARENT) == win32wnd->getOS2FrameWindowHandle());
108}
109//******************************************************************************
110//******************************************************************************
111VOID GetSizeBox(Win32BaseWindow *win32wnd,RECTL *rect)
112{
113 SWP swpHorz,swpVert;
114
115 WinQueryWindowPos(win32wnd->getVertScrollHandle(),&swpVert);
116 WinQueryWindowPos(win32wnd->getHorzScrollHandle(),&swpHorz);
117 rect->xLeft = swpVert.x;
118 rect->xRight = swpVert.x+swpVert.cx;
119 rect->yTop = swpHorz.y+swpHorz.cy;
120 rect->yBottom = swpHorz.y;
121}
122//******************************************************************************
123//******************************************************************************
124BOOL InSizeBox(Win32BaseWindow *win32wnd,POINTS *points)
125{
126 if (CanDrawSizeBox(win32wnd))
127 {
128 RECTL rect;
129 POINTL point;
130
131 point.x = points->x;
132 point.y = points->y;
133 GetSizeBox(win32wnd,&rect);
134 return (WinPtInRect(GetThreadHAB(),&rect,&point));
135 }
136
137 return FALSE;
138}
139//******************************************************************************
140//******************************************************************************
141VOID DrawSizeBox(HPS hps,RECTL rect)
142{
143 POINTL p1,p2;
144 LONG clrDark = CLR_DARKGRAY,clrWhite = CLR_WHITE;
145 INT x;
146
147 //CB: todo: switch to RGB mode and use win colors
148 WinFillRect(hps,&rect,SYSCLR_DIALOGBACKGROUND);
149 p1.x = rect.xRight-2;
150 p1.y = rect.yBottom;
151 p2.x = rect.xRight-1;
152 p2.y = rect.yBottom+1;
153 for (x = 0;x < 3;x++)
154 {
155 GpiSetColor(hps,clrDark);
156 GpiMove(hps,&p1);
157 GpiLine(hps,&p2);
158 p1.x--;
159 p2.y++;
160 GpiMove(hps,&p1);
161 GpiLine(hps,&p2);
162 GpiSetColor(hps,clrWhite);
163 p1.x--;
164 p2.y++;
165 GpiMove(hps,&p1);
166 GpiLine(hps,&p2);
167 p1.x -= 2;
168 p2.y += 2;
169 }
170}
171//******************************************************************************
172//******************************************************************************
173void DrawActivate(Win32BaseWindow *win32wnd, HWND hwnd)
174{
175 if (!win32wnd->isChild())
176 {
177 if (CanDrawSizeBox(win32wnd))
178 {
179 HPS hps;
180 RECTL rect;
181
182 GetSizeBox(win32wnd,&rect);
183 hps = WinGetClipPS(hwnd,0,PSF_CLIPCHILDREN | PSF_CLIPSIBLINGS);
184 DrawSizeBox(hps,rect);
185 WinReleasePS(hps);
186
187 }
188 }
189 else
190 {
191 HPS hps;
192 RECTL rect;
193
194 WinQueryWindowRect(hwnd,&rect);
195 rect.xRight = rect.xRight-rect.xLeft;
196 rect.yTop = rect.yTop-rect.yBottom;
197 rect.xLeft = rect.yBottom = 0;
198 hps = WinGetClipPS(hwnd,0,PSF_CLIPCHILDREN | PSF_CLIPSIBLINGS);
199 DrawFrame(hps,&rect,win32wnd);
200 WinReleasePS(hps);
201 }
202}
203//******************************************************************************
204//******************************************************************************
205void FrameTrackFrame(Win32BaseWindow *win32wnd,BOOL lefttop)
206{
207 INT flags = lefttop ? (TF_LEFT | TF_TOP):(TF_RIGHT | TF_BOTTOM);
208
209 WinSendMsg(win32wnd->getOS2FrameWindowHandle(),WM_TRACKFRAME,(MPARAM)flags,(MPARAM)0);
210}
211//******************************************************************************
212//Win32 frame message handler
213//******************************************************************************
214MRESULT EXPENTRY Win32FrameProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
215{
216 Win32BaseWindow *win32wnd;
217 PFNWP OldFrameProc;
218 MRESULT rc;
219
220 SetWin32TIB();
221
222 win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
223
224 if(win32wnd == NULL || !win32wnd->getOldFrameProc())
225 {
226 dprintf(("Invalid win32wnd pointer for frame %x!!", hwnd));
227 goto RunDefWndProc;
228 }
229
230 OldFrameProc = (PFNWP)win32wnd->getOldFrameProc();
231
232 switch(msg)
233 {
234 case WM_ADJUSTWINDOWPOS:
235 {
236 PSWP pswp = (PSWP)mp1;
237 SWP swpOld;
238 WINDOWPOS wp;
239 HWND hParent = NULLHANDLE, hwndAfter;
240
241 dprintf(("PMFRAME: WM_ADJUSTWINDOWPOS %x %x %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
242
243 //CB: show dialog in front of owner
244 if (win32wnd->IsModalDialogOwner())
245 {
246 pswp->fl |= SWP_ZORDER;
247 pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
248 if (pswp->fl & SWP_ACTIVATE)
249 {
250 pswp->fl &= ~SWP_ACTIVATE;
251 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
252 }
253 }
254
255 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
256 goto RunDefFrameProc;
257
258 if(!win32wnd->CanReceiveSizeMsgs()) {
259//SvL: Doing this breaks button.exe, header4(a).exe & style.exe
260// goto RunDefFrameProc; //CB: must call def frame proc or frame control activation is broken
261 break;
262 }
263
264 WinQueryWindowPos(hwnd, &swpOld);
265
266 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
267 if (win32wnd->isChild()) {
268 if(win32wnd->getParent()) {
269 hParent = win32wnd->getParent()->getOS2WindowHandle();
270 }
271 else goto RunDefFrameProc;
272 }
273 }
274 hwndAfter = pswp->hwndInsertBehind;
275 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hwnd);
276
277 wp.hwnd = win32wnd->getWindowHandle();
278 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
279 {
280 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
281 if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
282 }
283
284 //CB: problems with profmine titlebar tracking
285 if(win32wnd->MsgPosChanging((LPARAM)&wp) == 0)
286 {//app or default window handler changed wp
287 dprintf(("PMFRAME: WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
288 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
289
290 OSLibMapWINDOWPOStoSWPFrame(&wp, pswp, &swpOld, hParent, hwnd);
291 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
292 pswp->fl |= SWP_NOADJUST;
293 pswp->hwndInsertBehind = hwndAfter;
294 pswp->hwnd = hwnd;
295
296// goto RunDefFrameProc; //CB: must call def frame proc or frame control activation is broken
297 RestoreOS2TIB();
298 return (MRESULT)0xf;
299 }
300 goto RunDefFrameProc; //CB: must call def frame proc or frame control activation is broken
301 }
302
303 case WM_WINDOWPOSCHANGED:
304 {
305 PSWP pswp = (PSWP)mp1;
306 SWP swpOld = *(pswp + 1);
307 WINDOWPOS wp;
308 HWND hParent = NULLHANDLE;
309 LONG yDelta = pswp->cy - swpOld.cy;
310 LONG xDelta = pswp->cx - swpOld.cx;
311
312 dprintf(("PMFRAME: WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
313
314 RestoreOS2TIB();
315 rc = OldFrameProc(hwnd,msg,mp1,mp2);
316 SetWin32TIB();
317
318 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
319 goto PosChangedEnd;
320
321 if(!win32wnd->CanReceiveSizeMsgs())
322 goto PosChangedEnd;
323
324 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
325 if (win32wnd->isChild()) {
326 if(win32wnd->getParent()) {
327 hParent = win32wnd->getParent()->getOS2WindowHandle();
328 }
329 else goto PosChangedEnd; //parent has just been destroyed
330 }
331 }
332 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hwnd);
333
334 //delta is difference between old and new client height
335 yDelta = swpOld.cy - win32wnd->getWindowHeight();
336
337 win32wnd->setWindowRect(wp.x, wp.y, wp.x+wp.cx, wp.y+wp.cy);
338 win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
339
340 wp.hwnd = win32wnd->getWindowHandle();
341 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
342 {
343 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
344 if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
345 }
346
347 if (yDelta != 0 || xDelta != 0)
348 {
349 HENUM henum = WinBeginEnumWindows(WinWindowFromID(pswp->hwnd, FID_CLIENT));
350 SWP swp[10];
351 int i = 0;
352 HWND hwnd;
353
354 while ((hwnd = WinGetNextWindow(henum)) != NULLHANDLE)
355 {
356#if 0
357 if (mdiClient )
358 {
359 continue;
360 }
361#endif
362 WinQueryWindowPos(hwnd, &(swp[i]));
363
364#ifdef DEBUG
365 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
366 dprintf(("ENUMERATE %x delta %d (%d,%d) (%d,%d) %x", (window) ? window->getWindowHandle() : hwnd,
367 yDelta, swp[i].x, swp[i].y, swp[i].cx, swp[i].cy, swp[i].fl));
368#endif
369
370 if(swp[i].y != 0) {
371 //child window at offset <> 0 from client area -> offset now changes
372 swp[i].y += yDelta;
373 swp[i].fl &= ~(SWP_NOREDRAW);
374 }
375 //else child window with the same start coorindates as the client area
376 //The app should resize it.
377
378 if (i == 9)
379 {
380 WinSetMultWindowPos(GetThreadHAB(), swp, 10);
381 i = 0;
382 }
383 else
384 {
385 i++;
386 }
387 }
388
389 WinEndEnumWindows(henum);
390
391 if (i)
392 WinSetMultWindowPos(GetThreadHAB(), swp, i);
393 }
394 if (yDelta != 0)
395 {
396 POINT pt;
397 if(GetCaretPos (&pt) == TRUE)
398 {
399 pt.y -= yDelta;
400 SetCaretPos (pt.x, pt.y);
401 }
402 }
403 win32wnd->MsgPosChanged((LPARAM)&wp);
404
405PosChangedEnd:
406 RestoreOS2TIB();
407 return rc;
408 }
409
410 case WM_ACTIVATE:
411 {
412 HWND hwndTitle;
413 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
414
415 //CB: emulate WM_ACTIVATE -> no flickering
416 hwndTitle = WinWindowFromID(hwnd,FID_TITLEBAR);
417 if (hwndTitle) WinSendMsg(hwndTitle,TBM_SETHILITE,mp1,MPVOID);
418
419 WinSendMsg(WinWindowFromID(hwnd,FID_CLIENT),WM_ACTIVATE,mp1,mp2);
420 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
421
422 //CB: show owner behind the dialog
423 if (win32wnd->IsModalDialog())
424 {
425 Win32BaseWindow *topOwner = win32wnd->getOwner()->GetTopParent();
426
427 if (topOwner) WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
428 }
429
430 RestoreOS2TIB();
431 return 0;
432 }
433
434 case WM_DESTROY:
435 #ifdef PMFRAMELOG
436 dprintf(("PMFRAME: WM_DESTROY"));
437 #endif
438 WinSubclassWindow(hwnd,OldFrameProc);
439 win32wnd->setOldFrameProc(NULL);
440 goto RunDefFrameProc;
441
442 case WM_MOUSEMOVE:
443 if (InSizeBox(win32wnd,(POINTS*)&mp1))
444 {
445 WinSetPointer(HWND_DESKTOP,WinQuerySysPointer(HWND_DESKTOP,SPTR_SIZENWSE,FALSE));
446 RestoreOS2TIB();
447 return (MRESULT)TRUE;
448 }
449 else if (win32wnd->isChild()) goto RunDefWndProc;
450 else goto RunDefFrameProc;
451
452 case WM_BUTTON1DOWN:
453 #ifdef PMFRAMELOG
454 dprintf(("PMFRAME: WM_BUTTON1DOWN"));
455 #endif
456
457 if (InSizeBox(win32wnd,(POINTS*)&mp1))
458 {
459 WinSetActiveWindow(HWND_DESKTOP,hwnd);
460 WinSendMsg(hwnd,WM_TRACKFRAME,(MPARAM)(TF_RIGHT | TF_BOTTOM),(MPARAM)0);
461 RestoreOS2TIB();
462 return (MRESULT)TRUE;
463 }
464 else if (win32wnd->isChild()) goto RunDefWndProc;
465 else goto RunDefFrameProc;
466
467 case WM_BUTTON2DOWN:
468 case WM_BUTTON3DOWN:
469 #ifdef PMFRAMELOG
470 dprintf(("PMFRAME: WM_BUTTON2/3DOWN"));
471 #endif
472 if (win32wnd->isChild()) goto RunDefWndProc;
473 else goto RunDefFrameProc;
474
475 case WM_PAINT:
476 #ifdef PMFRAMELOG
477 dprintf(("PMFRAME: WM_PAINT"));
478 #endif
479 if (!win32wnd->isChild())
480 {
481 if (CanDrawSizeBox(win32wnd))
482 {
483 MRESULT res;
484 HPS hps;
485 RECTL rect;
486
487 RestoreOS2TIB();
488 res = OldFrameProc(hwnd,msg,mp1,mp2);
489 SetWin32TIB();
490
491 GetSizeBox(win32wnd,&rect);
492 hps = WinGetClipPS(hwnd,0,PSF_CLIPCHILDREN | PSF_CLIPSIBLINGS);
493 DrawSizeBox(hps,rect);
494 WinReleasePS(hps);
495
496 RestoreOS2TIB();
497 return res;
498 }
499 else goto RunDefFrameProc;
500 }
501 else
502 {
503 RECTL rect;
504 HPS hps;
505
506 RestoreOS2TIB();
507 OldFrameProc(hwnd,msg,mp1,mp2);
508 SetWin32TIB();
509
510 WinQueryWindowRect(hwnd,&rect);
511 rect.xRight = rect.xRight-rect.xLeft;
512 rect.yTop = rect.yTop-rect.yBottom;
513 rect.xLeft = rect.yBottom = 0;
514 hps = WinGetClipPS(hwnd,0,PSF_CLIPCHILDREN | PSF_CLIPSIBLINGS);
515 DrawFrame(hps,&rect,win32wnd);
516 WinReleasePS(hps);
517
518 RestoreOS2TIB();
519 return (MRESULT)0;
520 }
521
522 default:
523 RestoreOS2TIB();
524 return OldFrameProc(hwnd,msg,mp1,mp2);
525 }
526
527 RestoreOS2TIB();
528 return (MRESULT)FALSE;
529
530RunDefFrameProc:
531 RestoreOS2TIB();
532 return OldFrameProc(hwnd,msg,mp1,mp2);
533
534RunDefWndProc:
535 RestoreOS2TIB();
536 return WinDefWindowProc(hwnd,msg,mp1,mp2);
537}
538
539PVOID FrameSubclassFrameWindow(Win32BaseWindow *win32wnd)
540{
541 return WinSubclassWindow(win32wnd->getOS2FrameWindowHandle(),PFNWP(Win32FrameProc));
542}
543
544VOID FrameGetBorderSize(Win32BaseWindow *win32wnd,PWPOINT pSize)
545{
546 WinSendMsg(win32wnd->getOS2FrameWindowHandle(),WM_QUERYBORDERSIZE,(MPARAM)pSize,(MPARAM)0);
547}
548
549VOID FrameSetBorderSize(Win32BaseWindow *win32wnd,BOOL resize)
550{
551 POINTL point;
552
553 if (!resize)
554 {
555 WinSendMsg(win32wnd->getOS2FrameWindowHandle(),WM_SETBORDERSIZE,(MPARAM)win32wnd->getBorderWidth(),(MPARAM)win32wnd->getBorderHeight());
556
557 return;
558 }
559
560 FrameGetBorderSize(win32wnd,&point);
561 WinSendMsg(win32wnd->getOS2FrameWindowHandle(),WM_SETBORDERSIZE,(MPARAM)win32wnd->getBorderWidth(),(MPARAM)win32wnd->getBorderHeight());
562 if (point.x != win32wnd->getBorderWidth() || point.y != win32wnd->getBorderHeight())
563 {
564 INT xDiff = win32wnd->getBorderWidth()-point.x;
565 INT yDiff = win32wnd->getBorderHeight()-point.y;
566 SWP swp;
567
568 WinQueryWindowPos(win32wnd->getOS2FrameWindowHandle(),&swp);
569 swp.x += xDiff;
570 swp.y += yDiff;
571 swp.cx -= 2*xDiff;
572 swp.cy -= 2*yDiff;
573 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),0,swp.x,swp.y,swp.cx,swp.cy,SWP_MOVE | SWP_SIZE);
574 }
575}
576
577UINT FrameGetDefSizeBorderSize(VOID)
578{
579 return WinQuerySysValue(HWND_DESKTOP,SV_CXSIZEBORDER);
580}
Note: See TracBrowser for help on using the repository browser.