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

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

MDI changes + WM_INITMENU support added + disabled experimental support for CS_PARENTDC style

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