source: trunk/src/user32/new/pmframe.cpp@ 2418

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

client positioning + scrollbar fixes

File size: 13.1 KB
Line 
1/* $Id: pmframe.cpp,v 1.12 2000-01-12 15:14:16 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 <string.h>
19#include "win32type.h"
20#include <misc.h>
21#include <win32wbase.h>
22#include "wprocess.h"
23#include "pmframe.h"
24#include "oslibutil.h"
25#include "oslibwin.h"
26#include "caret.h"
27#include "oslibmsg.h"
28
29#define PMFRAMELOG
30
31//******************************************************************************
32//******************************************************************************
33VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags)
34{
35 WinSendMsg(win32wnd->getOS2FrameWindowHandle(),WM_TRACKFRAME,(MPARAM)flags,(MPARAM)0);
36}
37//******************************************************************************
38//******************************************************************************
39VOID FrameUpdateChildPositions(HWND hwnd)
40{
41 HENUM henum;
42 HWND hchild;
43 RECTL rectl;
44
45 henum = WinBeginEnumWindows(hwnd);
46 while ((hchild = WinGetNextWindow(henum)) != NULLHANDLE)
47 {
48 Win32BaseWindow *child = Win32BaseWindow::GetWindowFromOS2FrameHandle(hchild);
49
50 if (child)
51 {
52 WinQueryWindowRect(child->getOS2FrameWindowHandle(),&rectl);
53 mapOS2ToWin32Rect(child->getOS2FrameWindowHandle(),OSLIB_HWND_DESKTOP,(PRECTLOS2)&rectl,child->getWindowRect());
54 FrameUpdateChildPositions(child->getOS2WindowHandle());
55 }
56 }
57 WinEndEnumWindows(henum);
58}
59//******************************************************************************
60//Win32 frame message handler
61//******************************************************************************
62MRESULT EXPENTRY Win32FrameProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
63{
64 Win32BaseWindow *win32wnd;
65 PFNWP OldFrameProc;
66 MRESULT rc;
67 THDB *thdb;
68 MSG *pWinMsg,winMsg;
69
70 SetWin32TIB();
71
72 thdb = GetThreadTHDB();
73 win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
74
75 if (!thdb || (win32wnd == NULL) || !win32wnd->getOldFrameProc())
76 {
77 dprintf(("Invalid win32wnd pointer for frame %x!!", hwnd));
78 goto RunDefWndProc;
79 }
80
81 if((thdb->msgstate & 1) == 0)
82 {//message that was sent directly to our window proc handler; translate it here
83 QMSG qmsg;
84
85 qmsg.msg = msg;
86 qmsg.hwnd = hwnd;
87 qmsg.mp1 = mp1;
88 qmsg.mp2 = mp2;
89 qmsg.time = WinQueryMsgTime(thdb->hab);
90 WinQueryMsgPos(thdb->hab, &qmsg.ptl);
91 qmsg.reserved = 0;
92
93 if(OS2ToWinMsgTranslate((PVOID)thdb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
94 {//message was not translated
95 memset(&winMsg, 0, sizeof(MSG));
96 }
97 pWinMsg = &winMsg;
98 }
99 else {
100 pWinMsg = &thdb->msg;
101 thdb->msgstate++;
102 }
103
104 OldFrameProc = (PFNWP)win32wnd->getOldFrameProc();
105
106 switch(msg)
107 {
108 case WM_FORMATFRAME:
109 break;
110
111 case WM_MINMAXFRAME:
112 {
113 PSWP swp = (PSWP)mp1;
114
115 if (!win32wnd->IsWindowCreated()) goto RunDefFrameProc;
116 dprintf(("PMFRAME: WM_MINMAXFRAME %x",hwnd));
117 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
118 {
119 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W);
120 }
121 else if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
122 {
123 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
124 }
125 else if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
126 {
127 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
128 }
129 goto RunDefFrameProc;
130 }
131
132 case WM_QUERYBORDERSIZE:
133 goto RunDefFrameProc;
134
135 case WM_BUTTON1DOWN:
136 case WM_BUTTON1UP:
137 case WM_BUTTON1DBLCLK:
138 case WM_BUTTON2DOWN:
139 case WM_BUTTON2UP:
140 case WM_BUTTON2DBLCLK:
141 case WM_BUTTON3DOWN:
142 case WM_BUTTON3UP:
143 case WM_BUTTON3DBLCLK:
144 {
145 if (win32wnd->IsWindowCreated())
146 {
147 win32wnd->MsgButton(pWinMsg);
148 RestoreOS2TIB();
149 }
150 return (MRESULT)TRUE;
151 }
152
153 case WM_BUTTON2MOTIONSTART:
154 case WM_BUTTON2MOTIONEND:
155 case WM_BUTTON2CLICK:
156 case WM_BUTTON1MOTIONSTART:
157 case WM_BUTTON1MOTIONEND:
158 case WM_BUTTON1CLICK:
159 case WM_BUTTON3MOTIONSTART:
160 case WM_BUTTON3MOTIONEND:
161 case WM_BUTTON3CLICK:
162 RestoreOS2TIB();
163 return (MRESULT)TRUE;
164
165 case WM_MOUSEMOVE:
166 {
167 //OS/2 Window coordinates -> Win32 Window coordinates
168 if (win32wnd->IsWindowCreated())
169 win32wnd->MsgMouseMove(pWinMsg);
170 RestoreOS2TIB();
171 return (MRESULT)TRUE;
172 }
173
174 case WM_PAINT:
175 {
176 dprintf(("PMFRAME: WM_PAINT"));
177 if (win32wnd->getStyle() & WS_MINIMIZE_W)
178 goto RunDefFrameProc;
179 if (win32wnd->IsWindowCreated())
180 win32wnd->MsgNCPaint();
181 goto RunDefWndProc;
182 }
183
184 case WM_SIZE:
185 dprintf(("PMFRAME: WM_SIZE"));
186 goto RunDefFrameProc;
187
188 case WM_ADJUSTWINDOWPOS:
189 {
190 PSWP pswp = (PSWP)mp1;
191 SWP swpOld;
192 WINDOWPOS wp;
193 HWND hParent = NULLHANDLE, hwndAfter;
194
195 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));
196
197 //CB: show dialog in front of owner
198 if (win32wnd->IsModalDialogOwner())
199 {
200 pswp->fl |= SWP_ZORDER;
201 pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
202 if (pswp->fl & SWP_ACTIVATE)
203 {
204 pswp->fl &= ~SWP_ACTIVATE;
205 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
206 }
207 }
208
209 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
210 goto RunDefFrameProc;
211
212 if(!win32wnd->CanReceiveSizeMsgs())
213 break;
214
215 WinQueryWindowPos(hwnd, &swpOld);
216 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
217 if (win32wnd->isChild()) {
218 if(win32wnd->getParent()) {
219 hParent = win32wnd->getParent()->getOS2WindowHandle();
220 }
221 else goto RunDefFrameProc;
222 }
223 }
224 hwndAfter = pswp->hwndInsertBehind;
225 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hwnd);
226
227 wp.hwnd = win32wnd->getWindowHandle();
228 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
229 {
230 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
231 if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
232 }
233
234 //CB: problems with profmine titlebar tracking
235 if(win32wnd->MsgPosChanging((LPARAM)&wp) == 0)
236 {//app or default window handler changed wp
237 dprintf(("PMFRAME: WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
238 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
239
240 OSLibMapWINDOWPOStoSWPFrame(&wp, pswp, &swpOld, hParent, hwnd);
241 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
242 pswp->fl |= SWP_NOADJUST;
243 pswp->hwndInsertBehind = hwndAfter;
244 pswp->hwnd = hwnd;
245
246 RestoreOS2TIB();
247 return (MRESULT)0xf;
248 }
249 goto RunDefFrameProc;
250 }
251
252 case WM_WINDOWPOSCHANGED:
253 {
254 PSWP pswp = (PSWP)mp1;
255 SWP swpOld = *(pswp + 1);
256 WINDOWPOS wp;
257 HWND hParent = NULLHANDLE;
258 RECTL rect;
259 SWP swpClient = {0};
260
261 dprintf(("PMFRAME: WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
262
263 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
264 {
265 swpClient.hwnd = win32wnd->getOS2WindowHandle();
266 swpClient.hwndInsertBehind = 0;
267 swpClient.x = 0;
268 swpClient.y = 0;
269 swpClient.cx = 0;
270 swpClient.cy = 0;
271 swpClient.fl = pswp->fl & ~SWP_ZORDER;
272 WinSetMultWindowPos(thdb->hab, &swpClient, 1);
273 goto PosChangedEnd;
274 }
275
276 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
277 if (win32wnd->isChild()) {
278 if(win32wnd->getParent()) {
279 hParent = win32wnd->getParent()->getOS2WindowHandle();
280 }
281 else goto PosChangedEnd; //parent has just been destroyed
282 }
283 }
284 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hwnd);
285
286 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
287 win32wnd->setWindowRect(wp.x, wp.y, wp.x+wp.cx, wp.y+wp.cy);
288
289 win32wnd->MsgFormatFrame();
290 //CB: todo: use result for WM_CALCVALIDRECTS
291 mapWin32ToOS2Rect(WinQueryWindow(hwnd,QW_PARENT),hwnd,win32wnd->getClientRectPtr(),(PRECTLOS2)&rect);
292
293 swpClient.hwnd = win32wnd->getOS2WindowHandle();
294 swpClient.hwndInsertBehind = 0;
295 swpClient.x = rect.xLeft;
296 swpClient.y = rect.yBottom;
297 swpClient.cx = rect.xRight-rect.xLeft;
298 swpClient.cy = rect.yTop-rect.yBottom;
299 //TODO: Get rid of SWP_SHOW; needed for winhlp32 button bar for now
300 swpClient.fl = (pswp->fl & ~SWP_ZORDER) | SWP_MOVE | SWP_SHOW;
301 WinSetMultWindowPos(thdb->hab, &swpClient, 1);
302 }
303
304 if(win32wnd->CanReceiveSizeMsgs())
305 win32wnd->MsgPosChanged((LPARAM)&wp);
306
307 //update child positions: rectWindow is in window coordinates
308 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
309 FrameUpdateChildPositions(win32wnd->getOS2WindowHandle());
310 }
311
312PosChangedEnd:
313 RestoreOS2TIB();
314 return (MRESULT)FALSE;
315 }
316
317 case WM_CALCVALIDRECTS:
318 {
319 PRECTL oldRect = (PRECTL)mp1,newRect = oldRect+1;
320 UINT res = 0; //= CVR_ALIGNLEFT | CVR_ALIGNTOP;
321
322//CB: todo: use WM_NCCALCSIZE result
323 if (win32wnd->getWindowClass())
324 {
325 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
326
327 if ((dwStyle & CS_HREDRAW_W) && (newRect->xRight-newRect->xLeft != oldRect->xRight-oldRect->xLeft))
328 res |= CVR_REDRAW;
329 else if ((dwStyle & CS_VREDRAW_W) && (newRect->yTop-newRect->yBottom != oldRect->yTop-oldRect->yBottom))
330 res |= CVR_REDRAW;
331 } else res |= CVR_REDRAW;
332
333 //CB: PM sets client window position
334// RestoreOS2TIB();
335// OldFrameProc(hwnd,msg,mp1,mp2);
336// SetWin32TIB();
337
338 RestoreOS2TIB();
339 return (MRESULT)res;
340 }
341
342 case WM_ACTIVATE:
343 {
344 HWND hwndTitle;
345 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
346
347 if (win32wnd->IsWindowCreated())
348 {
349 WinSendMsg(WinWindowFromID(hwnd,FID_CLIENT),WM_ACTIVATE,mp1,mp2);
350 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
351
352 //CB: show owner behind the dialog
353 if (win32wnd->IsModalDialog())
354 {
355 Win32BaseWindow *topOwner = win32wnd->getOwner()->GetTopParent();
356
357 if (topOwner) WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
358 }
359 }
360 else
361 {
362 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
363 }
364 if(win32wnd->IsWindowCreated())
365 win32wnd->DispatchMsgA(pWinMsg);
366
367 RestoreOS2TIB();
368 return 0;
369 }
370
371 case WM_DESTROY:
372 dprintf(("PMFRAME: WM_DESTROY %x",hwnd));
373 WinSubclassWindow(hwnd,OldFrameProc);
374 win32wnd->setOldFrameProc(NULL);
375 goto RunDefFrameProc;
376
377 default:
378 RestoreOS2TIB();
379 return OldFrameProc(hwnd,msg,mp1,mp2);
380 }
381
382 RestoreOS2TIB();
383 return (MRESULT)FALSE;
384
385RunDefFrameProc:
386 RestoreOS2TIB();
387 return OldFrameProc(hwnd,msg,mp1,mp2);
388
389RunDefWndProc:
390 RestoreOS2TIB();
391 return WinDefWindowProc(hwnd,msg,mp1,mp2);
392}
393//******************************************************************************
394//******************************************************************************
395PVOID FrameSubclassFrameWindow(Win32BaseWindow *win32wnd)
396{
397 return WinSubclassWindow(win32wnd->getOS2FrameWindowHandle(),PFNWP(Win32FrameProc));
398}
399//******************************************************************************
400//******************************************************************************
401VOID FrameUpdateClient(Win32BaseWindow *win32wnd)
402{
403 RECTL rect;
404 SWP swpClient = {0};
405
406 win32wnd->MsgFormatFrame();
407 //CB: todo: use result for WM_CALCVALIDRECTS
408 mapWin32ToOS2Rect(WinQueryWindow(win32wnd->getOS2FrameWindowHandle(),QW_PARENT),win32wnd->getOS2FrameWindowHandle(),win32wnd->getClientRectPtr(),(PRECTLOS2)&rect);
409
410 swpClient.hwnd = win32wnd->getOS2WindowHandle();
411 swpClient.hwndInsertBehind = 0;
412 swpClient.x = rect.xLeft;
413 swpClient.y = rect.yBottom;
414 swpClient.cx = rect.xRight-rect.xLeft;
415 swpClient.cy = rect.yTop-rect.yBottom;
416 swpClient.fl = SWP_MOVE | SWP_SIZE;
417 WinSetMultWindowPos(GetThreadHAB(), &swpClient, 1);
418}
419//******************************************************************************
420//******************************************************************************
Note: See TracBrowser for help on using the repository browser.