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

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

set style + mdi child creation fixes

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