source: trunk/src/user32/win32wmdichild.cpp@ 1322

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

isFrameWindow bugfix + MDI creation & WM_NCCALCSIZE bugfix

File size: 17.5 KB
Line 
1/* $Id: win32wmdichild.cpp,v 1.5 1999-10-16 14:51:43 sandervl Exp $ */
2/*
3 * Win32 MDI Child Window Class for OS/2
4 *
5 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
6 *
7 * Based on Wine (windows\mdi.c) (990815)
8 *
9 * Copyright 1994, Bob Amstadt
10 * 1995,1996 Alex Korobka
11 *
12 *
13 * TODO: See #if 0's
14 *
15 * Project Odin Software License can be found in LICENSE.TXT
16 *
17 */
18#include <os2win.h>
19#include <win.h>
20#include <stdlib.h>
21#include <stdio.h>
22#include <string.h>
23#include <stdarg.h>
24#include <assert.h>
25#include <misc.h>
26#include <heapstring.h>
27#include <win32wnd.h>
28#include <win32wmdiclient.h>
29#include <win32wmdichild.h>
30#include <spy.h>
31#include "wndmsg.h"
32#include "hooks.h"
33#include <oslibwin.h>
34#include <oslibutil.h>
35#include <oslibgdi.h>
36#include <oslibres.h>
37#include "oslibdos.h"
38#include <winres.h>
39#include "syscolor.h"
40#include "win32wndhandle.h"
41#include "heapshared.h"
42
43
44//******************************************************************************
45//******************************************************************************
46Win32MDIChildWindow::Win32MDIChildWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode)
47 : Win32BaseWindow(lpCreateStructA, classAtom, isUnicode)
48{
49}
50//******************************************************************************
51//******************************************************************************
52Win32MDIChildWindow::~Win32MDIChildWindow()
53{
54}
55//******************************************************************************
56//******************************************************************************
57ULONG Win32MDIChildWindow::MsgActivate(BOOL fActivate, BOOL fMinimized, HWND hwnd)
58{
59 ULONG rc, curprocid, procidhwnd = -1, threadidhwnd = 0;
60
61 //According to SDK docs, if app returns FALSE & window is being deactivated,
62 //default processing is cancelled
63 //TODO: According to Wine we should proceed anyway if window is sysmodal
64 if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE && !fActivate)
65 {
66 return 0;
67 }
68 if(fActivate)
69 {
70 rc = SendInternalMessageA(WM_CHILDACTIVATE, MAKELONG((fActivate) ? WA_ACTIVE : WA_INACTIVE, fMinimized), hwnd);
71 curprocid = GetCurrentProcessId();
72 if(hwnd) {
73 threadidhwnd = GetWindowThreadProcessId(hwnd, &procidhwnd);
74 }
75
76 if(curprocid != procidhwnd && fActivate) {
77 SendInternalMessageA(WM_ACTIVATEAPP, 1, threadidhwnd);
78 }
79 return rc;
80 }
81 else return 1;
82}
83//******************************************************************************
84//******************************************************************************
85BOOL Win32MDIChildWindow::isMDIChild()
86{
87 return TRUE;
88}
89//******************************************************************************
90//******************************************************************************
91LRESULT Win32MDIChildWindow::DefMDIChildProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
92{
93 Win32MDIClientWindow *client = (Win32MDIClientWindow *)getParent();
94
95 switch (Msg)
96 {
97 case WM_SETTEXT:
98 DefWindowProcA(Msg, wParam, lParam);
99 menuModifyItem();
100 if( client->getMaximizedChild() == this )
101 client->updateFrameText(MDI_REPAINTFRAME, NULL);
102 return 0;
103
104 case WM_GETMINMAXINFO:
105 {
106 childGetMinMaxInfo((MINMAXINFO *)lParam);
107 return 0;
108 }
109
110 case WM_MENUCHAR:
111 /* MDI children don't have menu bars */
112 client->PostMessageA(WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)LOWORD(wParam) );
113 return 0x00010000L;
114
115 case WM_CLOSE:
116 client->SendMessageA(WM_MDIDESTROY,(WPARAM16)getWindowHandle(), 0L);
117 return 0;
118
119 case WM_SETFOCUS:
120 if(client->getActiveChild() != this )
121 client->childActivate(this);
122 break;
123
124 case WM_CHILDACTIVATE:
125 client->childActivate(this);
126 return 0;
127
128 case WM_NCPAINT:
129 break;
130
131 case WM_SYSCOMMAND:
132 switch( wParam )
133 {
134 case SC_MOVE:
135 if( client->getMaximizedChild() == this)
136 {
137 return 0;
138 }
139 break;
140 case SC_RESTORE:
141 case SC_MINIMIZE:
142 setStyle(getStyle() | WS_SYSMENU);
143 break;
144
145 case SC_MAXIMIZE:
146 if( client->getMaximizedChild() == this)
147 {
148 return client->SendMessageA(Msg, wParam, lParam);
149 }
150 setStyle(getStyle() & ~WS_SYSMENU);
151 break;
152
153 case SC_NEXTWINDOW:
154 client->SendMessageA(WM_MDINEXT, 0, 0);
155 return 0;
156
157 case SC_PREVWINDOW: //WM_MDINEXT??
158 client->SendMessageA(WM_MDINEXT, 0, 0);
159 return 0;
160 }
161 break;
162
163 case WM_SETVISIBLE:
164 if( client->getMaximizedChild()) {
165 client->setMdiFlags(client->getMdiFlags() & ~MDIF_NEEDUPDATE);
166 }
167 else client->postUpdate(SB_BOTH+1);
168 break;
169
170 case WM_SIZE:
171 /* do not change */
172 if( client->getActiveChild() == this && wParam != SIZE_MAXIMIZED )
173 {
174 client->setActiveChild(NULL);
175#if 0
176 MDI_RestoreFrameMenu( clientWnd->parent, hwnd);
177#endif
178 client->updateFrameText(MDI_REPAINTFRAME, NULL );
179 }
180
181 if( wParam == SIZE_MAXIMIZED )
182 {
183 Win32MDIChildWindow *maxChild = client->getMaximizedChild();
184
185 if( maxChild == this ) break;
186
187 if( maxChild)
188 {
189 maxChild->SendMessageA(WM_SETREDRAW, FALSE, 0L );
190#if 0
191 MDI_RestoreFrameMenu( clientWnd->parent, hMaxChild);
192#endif
193 maxChild->ShowWindow(SW_SHOWNOACTIVATE);
194
195 maxChild->SendMessageA(WM_SETREDRAW, TRUE, 0L );
196 }
197
198 client->setMaximizedChild(this);
199 client->setActiveChild(this);
200
201#if 0
202 MDI_AugmentFrameMenu( ci, clientWnd->parent, hwnd);
203#endif
204 client->updateFrameText(MDI_REPAINTFRAME, NULL );
205 }
206
207 if( wParam == SIZE_MINIMIZED )
208 {
209 Win32MDIChildWindow *switchTo = client->getWindow(this, TRUE, WS_MINIMIZE);
210
211 if( switchTo )
212 switchTo->SendMessageA(WM_CHILDACTIVATE, 0, 0L);
213 }
214
215 client->postUpdate(SB_BOTH+1);
216 break;
217
218#if 0
219 case WM_NEXTMENU:
220 if( wParam == VK_LEFT ) /* switch to frame system menu */
221 {
222 return MAKELONG( GetSubMenu(clientWnd->parent->hSysMenu, 0),
223 clientWnd->parent->hwndSelf );
224 goto END;
225 }
226 if( wParam == VK_RIGHT ) /* to frame menu bar */
227 {
228 retvalue = MAKELONG( clientWnd->parent->wIDmenu,
229 clientWnd->parent->hwndSelf );
230 goto END;
231 }
232#endif
233 case WM_SYSCHAR:
234 if (wParam == '-')
235 {
236 SendMessageA(WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)VK_SPACE);
237 return 0;
238 }
239 }
240 return DefWindowProcA(Msg, wParam, lParam);
241}
242//******************************************************************************
243//******************************************************************************
244LRESULT Win32MDIChildWindow::DefMDIChildProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
245{
246 Win32MDIClientWindow *client = (Win32MDIClientWindow *)getParent();
247
248 switch (Msg)
249 {
250 case WM_SETTEXT:
251 DefWindowProcW(Msg, wParam, lParam);
252 menuModifyItem();
253 if( client->getMaximizedChild() == this )
254 client->updateFrameText(MDI_REPAINTFRAME, NULL );
255
256 return 0;
257
258 case WM_GETMINMAXINFO:
259 case WM_MENUCHAR:
260 case WM_CLOSE:
261 case WM_SETFOCUS:
262 case WM_CHILDACTIVATE:
263 case WM_NCPAINT:
264 case WM_SYSCOMMAND:
265 case WM_SETVISIBLE:
266 case WM_SIZE:
267 case WM_NEXTMENU:
268 return DefMDIChildProcA(Msg, wParam, lParam );
269
270 case WM_SYSCHAR:
271 if (wParam == '-')
272 {
273 SendMessageW(WM_SYSCOMMAND, SC_KEYMENU, (LPARAM)(DWORD)VK_SPACE);
274 return 0;
275 }
276 break;
277 }
278 return DefWindowProcW(Msg, wParam, lParam);
279}
280/**********************************************************************
281 * MDICreateChild
282 */
283HWND Win32MDIChildWindow::createChild(Win32MDIClientWindow *client, LPMDICREATESTRUCTA cs )
284{
285 POINT pos[2];
286 DWORD style = cs->style | (WS_CHILD | WS_CLIPSIBLINGS);
287 WORD wIDmenu = client->getFirstChildId() + client->getNrOfChildren();
288 char lpstrDef[]="junk!";
289 Win32MDIChildWindow *maximizedChild, *newchild;
290 CREATESTRUCTA createstruct;
291 ATOM classAtom;
292 char tmpClassA[20] = "";
293 WCHAR tmpClassW[20];
294 LPSTR className;
295
296 dprintf(("Win32MDIChildWindow::createChild %i,%i - dim %i,%i, style %08x\n",
297 cs->x, cs->y, cs->cx, cs->cy, (unsigned)cs->style));
298
299 /* calculate placement */
300 calcDefaultChildPos(client, client->incTotalCreated(), pos, 0);
301
302 if (cs->cx == CW_USEDEFAULT || !cs->cx) cs->cx = pos[1].x;
303 if (cs->cy == CW_USEDEFAULT || !cs->cy) cs->cy = pos[1].y;
304
305 if( cs->x == CW_USEDEFAULT )
306 {
307 cs->x = pos[0].x;
308 cs->y = pos[0].y;
309 }
310
311 /* restore current maximized child */
312 if( style & WS_VISIBLE && client->getMaximizedChild() )
313 {
314 if( style & WS_MAXIMIZE )
315 client->SendMessageA(WM_SETREDRAW, FALSE, 0L );
316
317 maximizedChild = client->getMaximizedChild();
318
319 maximizedChild->ShowWindow( SW_SHOWNOACTIVATE );
320
321 if( style & WS_MAXIMIZE )
322 client->SendMessageA(WM_SETREDRAW, TRUE, 0L );
323 }
324
325 /* this menu is needed to set a check mark in MDI_ChildActivate */
326 AppendMenuA(client->getMDIMenu(), MF_STRING ,wIDmenu, lpstrDef );
327
328 client->incNrActiveChildren();
329
330 /* fix window style */
331 if( !(client->getStyle() & MDIS_ALLCHILDSTYLES) )
332 {
333 style &= (WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZE | WS_MAXIMIZE |
334 WS_CLIPCHILDREN | WS_DISABLED | WS_VSCROLL | WS_HSCROLL );
335 style |= (WS_VISIBLE | WS_OVERLAPPEDWINDOW);
336 }
337
338 createstruct.lpszName = cs->szTitle;
339 createstruct.style = style;
340 createstruct.dwExStyle = 0;
341 createstruct.x = cs->x;
342 createstruct.y = cs->y;
343 createstruct.cx = cs->cx;
344 createstruct.cy = cs->cy;
345 createstruct.hInstance = cs->hOwner;
346 createstruct.hMenu = wIDmenu;
347 createstruct.hwndParent= client->getWindowHandle();
348 createstruct.lpCreateParams = (LPVOID)cs;
349
350 className = (LPSTR)cs->szClass;
351 /* Find the class atom */
352 if (!(classAtom = (client->IsUnicode() ? GlobalFindAtomW((LPWSTR)cs->szClass) :
353 GlobalFindAtomA(cs->szClass))))
354 {
355 if (!HIWORD(cs->szClass))
356 {
357 if(!client->IsUnicode())
358 {
359 sprintf(tmpClassA,"#%d", (int) className);
360 classAtom = GlobalFindAtomA(tmpClassA);
361 className = tmpClassA;
362 }
363 else
364 {
365 sprintf(tmpClassA,"#%d", (int) className);
366 AsciiToUnicode(tmpClassA, tmpClassW);
367 classAtom = GlobalFindAtomW(tmpClassW);
368 className = (LPSTR)tmpClassW;
369 }
370 }
371 if (!classAtom)
372 {
373 if (!HIWORD(cs->szClass)) {
374 dprintf(("createChild: bad class name %04x\n", LOWORD(className)));
375 }
376 else dprintf(("createChild: bad class name '%s'\n", tmpClassA ));
377
378 SetLastError(ERROR_INVALID_PARAMETER);
379 return 0;
380 }
381 }
382 createstruct.lpszClass = className;
383
384 newchild = new Win32MDIChildWindow(&createstruct, classAtom, client->IsUnicode());
385
386 if(newchild && GetLastError() == 0)
387 {
388 newchild->menuModifyItem();
389
390 if( newchild->getStyle() & WS_MINIMIZE && client->getActiveChild()) {
391 newchild->ShowWindow(SW_SHOWMINNOACTIVE);
392 }
393 else
394 {
395 /* WS_VISIBLE is clear if a) the MDI client has
396 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
397 * MDICreateStruct. If so the created window is not shown nor
398 * activated.
399 */
400 int showflag = newchild->getStyle() & WS_VISIBLE;
401 /* clear visible flag, otherwise SetWindoPos32 ignores
402 * the SWP_SHOWWINDOW command.
403 */
404//SvL: Not here. This causes problems in OS/2
405// newchild->SetWindowLongA(GWL_STYLE, showflag & ~WS_VISIBLE);
406 if(showflag){
407 newchild->SetWindowPos(0, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE );
408
409 /* Set maximized state here in case hwnd didn't receive WM_SIZE
410 * during CreateWindow - bad!
411 */
412
413 if((newchild->getStyle() & WS_MAXIMIZE) && !client->getMaximizedChild() )
414 {
415 client->setMaximizedChild(newchild);
416#if 0
417 MDI_AugmentFrameMenu( ci, w->parent, newchild->getWindowHandle() );
418#endif
419 client->updateFrameText(MDI_REPAINTFRAME, NULL );
420 }
421 }
422 else
423 /* needed, harmless ? */
424 newchild->SetWindowPos(0, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE );
425
426 }
427 }
428 else
429 {
430 client->decNrActiveChildren();
431 DeleteMenu(client->getMDIMenu(), wIDmenu,MF_BYCOMMAND);
432
433 maximizedChild = client->getMaximizedChild();
434 if( maximizedChild && maximizedChild->IsWindow() )
435 maximizedChild->ShowWindow(SW_SHOWMAXIMIZED);
436
437 dprintf(("MDI child creation failed!!"));
438 return 0;
439 }
440 return newchild->getWindowHandle();
441}
442/**********************************************************************
443 * MDI_MenuModifyItem
444 */
445BOOL Win32MDIChildWindow::menuModifyItem()
446{
447 Win32MDIClientWindow *client = (Win32MDIClientWindow *)getParent();
448 char buffer[128];
449 UINT n = sprintf(buffer, "%d ", getWindowId() - client->getFirstChildId() + 1);
450 BOOL bRet = 0;
451
452 if( !client->getMDIMenu() )
453 {
454 return FALSE;
455 }
456
457 if (getWindowNameA()) lstrcpynA(buffer + n, getWindowNameA(), sizeof(buffer) - n );
458
459 n = GetMenuState(client->getMDIMenu(), getWindowId() ,MF_BYCOMMAND);
460 bRet = ModifyMenuA(client->getMDIMenu() , getWindowId(),
461 MF_BYCOMMAND | MF_STRING, getWindowId(), buffer );
462 CheckMenuItem(client->getMDIMenu(), getWindowId() , n & MF_CHECKED);
463
464 return bRet;
465}
466
467/**********************************************************************
468 * MDI_MenuDeleteItem
469 */
470BOOL Win32MDIChildWindow::menuDeleteItem()
471{
472 Win32MDIClientWindow *client = (Win32MDIClientWindow *)getParent();
473 char buffer[128];
474 UINT index = 0,id,n;
475 BOOL retvalue;
476
477 if( !client->getNrOfChildren() ||
478 !client->getMDIMenu())
479 {
480 return FALSE;
481 }
482
483 id = getWindowId();
484 DeleteMenu(client->getMDIMenu(),id,MF_BYCOMMAND);
485
486 /* walk the rest of MDI children to prevent gaps in the id
487 * sequence and in the menu child list */
488
489 for( index = id+1; index <= client->getNrOfChildren() +
490 client->getFirstChildId(); index++ )
491 {
492 Win32MDIChildWindow *tmpWnd = client->getChildByID(index);
493 if( !tmpWnd )
494 {
495 dprintf(("no window for id=%i\n",index));
496 continue;
497 }
498
499 /* set correct id */
500 tmpWnd->setWindowId(tmpWnd->getWindowId()-1);
501
502 n = sprintf(buffer, "%d ",index - client->getFirstChildId());
503 if (tmpWnd->getWindowNameA())
504 lstrcpynA(buffer + n, tmpWnd->getWindowNameA(), sizeof(buffer) - n );
505
506 /* change menu */
507 ModifyMenuA(client->getMDIMenu(), index ,MF_BYCOMMAND | MF_STRING,
508 index - 1 , buffer );
509 }
510 return TRUE;
511}
512/**********************************************************************
513 * MDI_CalcDefaultChildPos
514 *
515 * It seems that the default height is about 2/3 of the client rect
516 */
517void Win32MDIChildWindow::calcDefaultChildPos(Win32MDIClientWindow *client, WORD n, LPPOINT lpPos, INT delta)
518{
519 INT nstagger;
520 RECT rect = *client->getClientRect();
521 INT spacing = GetSystemMetrics(SM_CYCAPTION) +
522 GetSystemMetrics(SM_CYFRAME) - 1;
523
524 if( rect.bottom - rect.top - delta >= spacing )
525 rect.bottom -= delta;
526
527 nstagger = (rect.bottom - rect.top)/(3 * spacing);
528 lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
529 lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
530 lpPos[0].x = lpPos[0].y = spacing * (n%(nstagger+1));
531}
532
533/**********************************************************************
534 * MDI_ChildGetMinMaxInfo
535 *
536 * Note: The rule here is that client rect of the maximized MDI child
537 * is equal to the client rect of the MDI client window.
538 */
539void Win32MDIChildWindow::childGetMinMaxInfo(MINMAXINFO* lpMinMax )
540{
541 Win32MDIClientWindow *client = (Win32MDIClientWindow *)getParent();
542 RECT rect = *client->getClientRect();
543
544 if(client->getParent() == NULL) {
545 dprintf(("Win32MDIChildWindow::childGetMinMaxInfo:: client parent == NULL!!"));
546 return;
547 }
548 MapWindowPoints(client->getParent()->getWindowHandle(), client->getWindowHandle(), (LPPOINT)&rect, 2);
549
550 AdjustWindowRectEx( &rect, getStyle(), 0, getExStyle());
551
552 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
553 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
554
555 lpMinMax->ptMaxPosition.x = rect.left;
556 lpMinMax->ptMaxPosition.y = rect.top;
557}
558
559//******************************************************************************
560//******************************************************************************
561
Note: See TracBrowser for help on using the repository browser.