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

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

MDI changes & fixes

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