3 * Copyright 1994, Bob Amstadt
4 * 1995,1996 Alex Korobka
6 * This file contains routines to support MDI (Multiple Document
7 * Interface) features .
9 * Notes: Fairly complete implementation.
10 * Also, Excel and WinWord do _not_ use MDI so if you're trying
11 * to fix them look elsewhere.
13 * Notes on how the "More Windows..." is implemented:
15 * When we have more than 9 opened windows, a "More Windows..."
16 * option appears in the "Windows" menu. Each child window has
17 * a WND* associated with it, accesible via the children list of
18 * the parent window. This WND* has a wIDmenu member, which reflects
19 * the position of the child in the window list. For example, with
20 * 9 child windows, we could have the following pattern:
24 * Name of the child window pWndChild->wIDmenu
36 * The "Windows" menu, as the "More windows..." dialog, are constructed
37 * in this order. If we add a child, we would have the following list:
40 * Name of the child window pWndChild->wIDmenu
52 * But only 5000 to 5008 would be displayed in the "Windows" menu. We want
53 * the last created child to be in the menu, so we swap the last child with
54 * the 9th... Doc9 will be accessible via the "More Windows..." option.
78 #include "wine/unicode.h"
81 #include "nonclient.h"
85 #include "debugtools.h"
88 DEFAULT_DEBUG_CHANNEL(mdi);
90 #define MDI_MAXLISTLENGTH 0x40
91 #define MDI_MAXTITLELENGTH 0xa1
93 #define MDI_NOFRAMEREPAINT 0
94 #define MDI_REPAINTFRAMENOW 1
95 #define MDI_REPAINTFRAME 2
97 #define WM_MDICALCCHILDSCROLL 0x10ac /* this is exactly what Windows uses */
99 /* "More Windows..." definitions */
100 #define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
101 option will appear under the Windows menu */
102 #define MDI_IDC_LISTBOX 100
103 #define MDI_IDS_MOREWINDOWS 13
105 #define MDIF_NEEDUPDATE 0x0001
109 UINT nActiveChildren;
110 HWND hwndChildMaximized;
111 HWND hwndActiveChild;
117 UINT sbRecalc; /* SB_xxx flags for scrollbar fixup */
120 static HBITMAP hBmpClose = 0;
121 static HBITMAP hBmpRestore = 0;
123 /* ----------------- declarations ----------------- */
124 static void MDI_UpdateFrameText( HWND, HWND, BOOL, LPCWSTR);
125 static BOOL MDI_AugmentFrameMenu( HWND, HWND );
126 static BOOL MDI_RestoreFrameMenu( HWND, HWND );
127 static LONG MDI_ChildActivate( HWND, HWND );
129 static HWND MDI_MoreWindowsDialog(HWND);
130 static void MDI_SwapMenuItems(HWND, UINT, UINT);
131 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
132 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
134 /* -------- Miscellaneous service functions ----------
138 static HWND MDI_GetChildByID(HWND hwnd, UINT id)
144 if (!(win_array = WIN_ListChildren( hwnd ))) return 0;
145 for (i = 0; win_array[i]; i++)
147 if (GetWindowLongA( win_array[i], GWL_ID ) == id) break;
150 HeapFree( GetProcessHeap(), 0, win_array );
154 static void MDI_PostUpdate(HWND hwnd, MDICLIENTINFO* ci, WORD recalc)
156 if( !(ci->mdiFlags & MDIF_NEEDUPDATE) )
158 ci->mdiFlags |= MDIF_NEEDUPDATE;
159 PostMessageA( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
161 ci->sbRecalc = recalc;
165 /*********************************************************************
166 * MDIClient class descriptor
168 const struct builtin_class_descr MDICLIENT_builtin_class =
170 "MDIClient", /* name */
171 CS_GLOBALCLASS, /* style */
172 MDIClientWndProcA, /* procA */
173 MDIClientWndProcW, /* procW */
174 sizeof(MDICLIENTINFO), /* extra */
175 IDC_ARROWA, /* cursor */
176 COLOR_APPWORKSPACE+1 /* brush */
180 static MDICLIENTINFO *get_client_info( HWND client )
182 MDICLIENTINFO *ret = NULL;
183 WND *win = WIN_GetPtr( client );
186 if (win == WND_OTHER_PROCESS)
188 ERR( "client %x belongs to other process\n", client );
191 if (win->cbWndExtra < sizeof(MDICLIENTINFO)) WARN( "%x is not an MDI client\n", client );
192 else ret = (MDICLIENTINFO *)win->wExtra;
193 WIN_ReleasePtr( win );
198 /**********************************************************************
201 static void MDI_MenuModifyItem( HWND client, HWND hWndChild )
203 MDICLIENTINFO *clientInfo = get_client_info( client );
207 if (!clientInfo || !clientInfo->hWindowMenu) return;
209 id = GetWindowLongA( hWndChild, GWL_ID );
210 if (id >= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT) return;
212 buffer[1] = '1' + id - clientInfo->idFirstChild;
214 GetWindowTextW( hWndChild, buffer + 3, sizeof(buffer)/sizeof(WCHAR) - 3 );
216 n = GetMenuState(clientInfo->hWindowMenu, id, MF_BYCOMMAND);
217 ModifyMenuW(clientInfo->hWindowMenu, id, MF_BYCOMMAND | MF_STRING, id, buffer );
218 CheckMenuItem(clientInfo->hWindowMenu, id, n & MF_CHECKED);
221 /**********************************************************************
224 static BOOL MDI_MenuDeleteItem( HWND client, HWND hWndChild )
227 static const WCHAR format[] = {'&','%','d',' ',0};
228 MDICLIENTINFO *clientInfo = get_client_info( client );
231 if( !clientInfo->nActiveChildren || !clientInfo->hWindowMenu )
234 id = GetWindowLongA( hWndChild, GWL_ID );
235 DeleteMenu(clientInfo->hWindowMenu,id,MF_BYCOMMAND);
237 /* walk the rest of MDI children to prevent gaps in the id
238 * sequence and in the menu child list */
240 for( index = id+1; index <= clientInfo->nActiveChildren +
241 clientInfo->idFirstChild; index++ )
243 HWND hwnd = MDI_GetChildByID(client,index);
246 TRACE("no window for id=%i\n",index);
251 SetWindowLongW( hwnd, GWL_ID, GetWindowLongW( hwnd, GWL_ID ) - 1 );
253 n = wsprintfW(buffer, format ,index - clientInfo->idFirstChild);
254 GetWindowTextW( hwnd, buffer + n, sizeof(buffer)/sizeof(WCHAR) - n );
256 /* change menu if the current child is to be shown in the
259 if (index <= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT)
260 ModifyMenuW(clientInfo->hWindowMenu ,index ,MF_BYCOMMAND | MF_STRING,
261 index - 1 , buffer );
264 /* We must restore the "More Windows..." option if there are enough children
266 if (clientInfo->nActiveChildren - 1 > MDI_MOREWINDOWSLIMIT)
269 LoadStringW(GetModuleHandleA("USER32"), MDI_IDS_MOREWINDOWS, szTmp, sizeof(szTmp)/sizeof(szTmp[0]));
270 AppendMenuW(clientInfo->hWindowMenu, MF_STRING, clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT, szTmp);
275 /**********************************************************************
278 * returns "activateable" child different from the current or zero
280 static HWND MDI_GetWindow(MDICLIENTINFO *clientInfo, HWND hWnd, BOOL bNext,
287 dwStyleMask |= WS_DISABLED | WS_VISIBLE;
288 if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
290 if (!(list = WIN_ListChildren( GetParent(hWnd) ))) return 0;
292 /* start from next after hWnd */
293 while (list[i] && list[i] != hWnd) i++;
296 for ( ; list[i]; i++)
298 if (GetWindow( list[i], GW_OWNER )) continue;
299 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
301 if (bNext) goto found;
303 /* now restart from the beginning */
304 for (i = 0; list[i] && list[i] != hWnd; i++)
306 if (GetWindow( list[i], GW_OWNER )) continue;
307 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
309 if (bNext) goto found;
312 HeapFree( GetProcessHeap(), 0, list );
316 /**********************************************************************
317 * MDI_CalcDefaultChildPos
319 * It seems that the default height is about 2/3 of the client rect
321 static void MDI_CalcDefaultChildPos( HWND hwnd, WORD n, LPPOINT lpPos, INT delta)
325 INT spacing = GetSystemMetrics(SM_CYCAPTION) +
326 GetSystemMetrics(SM_CYFRAME) - 1;
328 GetClientRect( hwnd, &rect );
329 if( rect.bottom - rect.top - delta >= spacing )
330 rect.bottom -= delta;
332 nstagger = (rect.bottom - rect.top)/(3 * spacing);
333 lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
334 lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
335 lpPos[0].x = lpPos[0].y = spacing * (n%(nstagger+1));
338 /**********************************************************************
341 static LRESULT MDISetMenu( HWND hwnd, HMENU hmenuFrame,
345 HWND hwndFrame = GetParent(hwnd);
346 HMENU oldFrameMenu = GetMenu(hwndFrame);
348 TRACE("%04x %04x %04x\n",
349 hwnd, hmenuFrame, hmenuWindow);
351 if (hmenuFrame && !IsMenu(hmenuFrame))
353 WARN("hmenuFrame is not a menu handle\n");
357 if (hmenuWindow && !IsMenu(hmenuWindow))
359 WARN("hmenuWindow is not a menu handle\n");
363 if (!(ci = get_client_info( hwnd ))) return 0;
365 if( ci->hwndChildMaximized && hmenuFrame && hmenuFrame!=oldFrameMenu )
366 MDI_RestoreFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
368 if( hmenuWindow && ci->hWindowMenu && hmenuWindow!=ci->hWindowMenu )
370 /* delete menu items from ci->hWindowMenu
371 * and add them to hmenuWindow */
373 INT i = GetMenuItemCount(ci->hWindowMenu) - 1;
374 INT pos = GetMenuItemCount(hmenuWindow) + 1;
376 AppendMenuA( hmenuWindow, MF_SEPARATOR, 0, NULL);
378 if( ci->nActiveChildren )
381 LPWSTR buffer = NULL;
383 INT nbWindowsMenuItems; /* num of documents shown + "More Windows..." if present */
385 if (ci->nActiveChildren <= MDI_MOREWINDOWSLIMIT)
386 nbWindowsMenuItems = ci->nActiveChildren;
388 nbWindowsMenuItems = MDI_MOREWINDOWSLIMIT + 1;
390 j = i - nbWindowsMenuItems + 1;
392 for( ; i >= j ; i-- )
394 memset(&mii, 0, sizeof(mii));
395 mii.cbSize = sizeof(mii);
396 mii.fMask = MIIM_CHECKMARKS | MIIM_DATA | MIIM_ID | MIIM_STATE
397 | MIIM_SUBMENU | MIIM_TYPE | MIIM_BITMAP;
399 GetMenuItemInfoW(ci->hWindowMenu, i, TRUE, &mii);
400 if(mii.cch) { /* Menu is MFT_STRING */
401 mii.cch++; /* add room for '\0' */
402 buffer = HeapAlloc(GetProcessHeap(), 0,
403 mii.cch * sizeof(WCHAR));
404 mii.dwTypeData = buffer;
405 GetMenuItemInfoW(ci->hWindowMenu, i, TRUE, &mii);
407 DeleteMenu(ci->hWindowMenu, i, MF_BYPOSITION);
408 InsertMenuItemW(hmenuWindow, pos, TRUE, &mii);
410 HeapFree(GetProcessHeap(), 0, buffer);
416 /* remove separator */
417 DeleteMenu(ci->hWindowMenu, i, MF_BYPOSITION);
419 ci->hWindowMenu = hmenuWindow;
424 SetMenu(hwndFrame, hmenuFrame);
425 if( hmenuFrame!=oldFrameMenu )
427 if( ci->hwndChildMaximized )
428 MDI_AugmentFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
434 HMENU menu = GetMenu( GetParent(hwnd) );
435 INT nItems = GetMenuItemCount(menu) - 1;
436 UINT iId = GetMenuItemID(menu,nItems) ;
438 if( !(iId == SC_RESTORE || iId == SC_CLOSE) )
440 /* SetMenu() may already have been called, meaning that this window
441 * already has its menu. But they may have done a SetMenu() on
442 * an MDI window, and called MDISetMenu() after the fact, meaning
443 * that the "if" to this "else" wouldn't catch the need to
444 * augment the frame menu.
446 if( ci->hwndChildMaximized )
447 MDI_AugmentFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
453 /**********************************************************************
456 static LRESULT MDIRefreshMenu( HWND hwnd, HMENU hmenuFrame,
459 HWND hwndFrame = GetParent(hwnd);
460 HMENU oldFrameMenu = GetMenu(hwndFrame);
462 TRACE("%04x %04x %04x\n",
463 hwnd, hmenuFrame, hmenuWindow);
465 FIXME("partially function stub\n");
471 /* ------------------ MDI child window functions ---------------------- */
474 /**********************************************************************
477 static HWND MDICreateChild( HWND parent, MDICLIENTINFO *ci,
478 LPMDICREATESTRUCTA cs, BOOL unicode )
481 DWORD style = cs->style | (WS_CHILD | WS_CLIPSIBLINGS);
482 HWND hwnd, hwndMax = 0;
483 UINT wIDmenu = ci->idFirstChild + ci->nActiveChildren;
485 static const WCHAR lpstrDef[] = {'j','u','n','k','!',0};
487 TRACE("origin %i,%i - dim %i,%i, style %08lx\n",
488 cs->x, cs->y, cs->cx, cs->cy, cs->style);
489 /* calculate placement */
490 MDI_CalcDefaultChildPos(parent, ci->nTotalCreated++, pos, 0);
492 if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16 || !cs->cx) cs->cx = pos[1].x;
493 if (cs->cy == CW_USEDEFAULT || cs->cy == CW_USEDEFAULT16 || !cs->cy) cs->cy = pos[1].y;
495 if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
501 /* restore current maximized child */
502 if( (style & WS_VISIBLE) && ci->hwndChildMaximized )
504 TRACE("Restoring current maximized child %04x\n", ci->hwndChildMaximized);
505 if( style & WS_MAXIMIZE )
506 SendMessageW(parent, WM_SETREDRAW, FALSE, 0L);
507 hwndMax = ci->hwndChildMaximized;
508 ShowWindow( hwndMax, SW_SHOWNOACTIVATE );
509 if( style & WS_MAXIMIZE )
510 SendMessageW(parent, WM_SETREDRAW, TRUE, 0L);
513 if (ci->nActiveChildren <= MDI_MOREWINDOWSLIMIT)
514 /* this menu is needed to set a check mark in MDI_ChildActivate */
515 if (ci->hWindowMenu != 0)
516 AppendMenuW(ci->hWindowMenu, MF_STRING, wIDmenu, lpstrDef);
518 ci->nActiveChildren++;
520 /* fix window style */
521 wndParent = WIN_FindWndPtr( parent );
522 if( !(wndParent->dwStyle & MDIS_ALLCHILDSTYLES) )
524 TRACE("MDIS_ALLCHILDSTYLES is missing, fixing window style\n");
525 style &= (WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZE | WS_MAXIMIZE |
526 WS_CLIPCHILDREN | WS_DISABLED | WS_VSCROLL | WS_HSCROLL );
527 style |= (WS_VISIBLE | WS_OVERLAPPEDWINDOW);
530 if( wndParent->flags & WIN_ISWIN32 )
532 WIN_ReleaseWndPtr( wndParent );
535 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)cs;
536 hwnd = CreateWindowW( csW->szClass, csW->szTitle, style,
537 csW->x, csW->y, csW->cx, csW->cy, parent,
538 (HMENU)wIDmenu, csW->hOwner, csW );
541 hwnd = CreateWindowA( cs->szClass, cs->szTitle, style,
542 cs->x, cs->y, cs->cx, cs->cy, parent,
543 (HMENU)wIDmenu, cs->hOwner, cs );
547 MDICREATESTRUCT16 cs16;
548 SEGPTR title, cls, seg_cs16;
550 WIN_ReleaseWndPtr( wndParent );
551 STRUCT32_MDICREATESTRUCT32Ato16( cs, &cs16 );
552 cs16.szTitle = title = MapLS( cs->szTitle );
553 cs16.szClass = cls = MapLS( cs->szClass );
554 seg_cs16 = MapLS( &cs16 );
555 hwnd = WIN_Handle32( CreateWindow16( cs->szClass, cs->szTitle, style,
556 cs16.x, cs16.y, cs16.cx, cs16.cy,
557 WIN_Handle16(parent), (HMENU)wIDmenu,
558 cs16.hOwner, (LPVOID)seg_cs16 ));
564 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
568 /* All MDI child windows have the WS_EX_MDICHILD style */
569 SetWindowLongW( hwnd, GWL_EXSTYLE, GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_MDICHILD );
571 /* If we have more than 9 windows, we must insert the new one at the
572 * 9th position in order to see it in the "Windows" menu
574 if (ci->nActiveChildren > MDI_MOREWINDOWSLIMIT)
575 MDI_SwapMenuItems( parent, GetWindowLongW( hwnd, GWL_ID ),
576 ci->idFirstChild + MDI_MOREWINDOWSLIMIT - 1);
578 MDI_MenuModifyItem(parent, hwnd);
580 /* Have we hit the "More Windows..." limit? If so, we must
581 * add a "More Windows..." option
583 if (ci->nActiveChildren == MDI_MOREWINDOWSLIMIT + 1)
586 LoadStringW(GetModuleHandleA("USER32"), MDI_IDS_MOREWINDOWS, szTmp, sizeof(szTmp)/sizeof(szTmp[0]));
588 ModifyMenuW(ci->hWindowMenu,
589 ci->idFirstChild + MDI_MOREWINDOWSLIMIT,
590 MF_BYCOMMAND | MF_STRING,
591 ci->idFirstChild + MDI_MOREWINDOWSLIMIT,
595 if( IsIconic(hwnd) && ci->hwndActiveChild )
597 TRACE("Minimizing created MDI child %04x\n", hwnd);
598 ShowWindow( hwnd, SW_SHOWMINNOACTIVE );
602 /* WS_VISIBLE is clear if a) the MDI client has
603 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
604 * MDICreateStruct. If so the created window is not shown nor
607 if (IsWindowVisible(hwnd)) ShowWindow(hwnd, SW_SHOW);
609 TRACE("created child - %04x\n",hwnd);
613 ci->nActiveChildren--;
614 DeleteMenu(ci->hWindowMenu,wIDmenu,MF_BYCOMMAND);
615 if( IsWindow(hwndMax) )
616 ShowWindow(hwndMax, SW_SHOWMAXIMIZED);
622 /**********************************************************************
623 * MDI_ChildGetMinMaxInfo
625 * Note: The rule here is that client rect of the maximized MDI child
626 * is equal to the client rect of the MDI client window.
628 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
632 GetClientRect( client, &rect );
633 AdjustWindowRectEx( &rect, GetWindowLongW( hwnd, GWL_STYLE ),
634 0, GetWindowLongW( hwnd, GWL_EXSTYLE ));
636 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
637 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
639 lpMinMax->ptMaxPosition.x = rect.left;
640 lpMinMax->ptMaxPosition.y = rect.top;
642 TRACE("max rect (%i,%i - %i, %i)\n",
643 rect.left,rect.top,rect.right,rect.bottom);
646 /**********************************************************************
647 * MDI_SwitchActiveChild
649 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
652 static void MDI_SwitchActiveChild( HWND clientHwnd, HWND childHwnd,
657 MDICLIENTINFO *ci = get_client_info( clientHwnd );
659 hwndTo = MDI_GetWindow(ci, childHwnd, bNextWindow, 0);
661 TRACE("from %04x, to %04x\n",childHwnd,hwndTo);
663 if ( !hwndTo ) return; /* no window to switch to */
665 hwndPrev = ci->hwndActiveChild;
667 if ( hwndTo != hwndPrev )
669 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0,
670 SWP_NOMOVE | SWP_NOSIZE );
672 if( bNextWindow && hwndPrev )
673 SetWindowPos( hwndPrev, HWND_BOTTOM, 0, 0, 0, 0,
674 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
679 /**********************************************************************
682 static LRESULT MDIDestroyChild( HWND parent, MDICLIENTINFO *ci,
683 HWND child, BOOL flagDestroy )
685 if( child == ci->hwndActiveChild )
687 MDI_SwitchActiveChild(parent, child, TRUE);
689 if( child == ci->hwndActiveChild )
691 ShowWindow( child, SW_HIDE);
692 if( child == ci->hwndChildMaximized )
694 HWND frame = GetParent(parent);
695 MDI_RestoreFrameMenu( frame, child );
696 ci->hwndChildMaximized = 0;
697 MDI_UpdateFrameText( frame, parent, TRUE, NULL);
700 MDI_ChildActivate(parent, 0);
704 MDI_MenuDeleteItem(parent, child);
706 ci->nActiveChildren--;
708 TRACE("child destroyed - %04x\n",child);
712 MDI_PostUpdate(GetParent(child), ci, SB_BOTH+1);
713 DestroyWindow(child);
719 /**********************************************************************
722 * Note: hWndChild is NULL when last child is being destroyed
724 static LONG MDI_ChildActivate( HWND client, HWND child )
726 MDICLIENTINFO *clientInfo = get_client_info( client );
727 HWND prevActiveWnd = clientInfo->hwndActiveChild;
728 BOOL isActiveFrameWnd;
730 if (child && (!IsWindowEnabled( child ))) return 0;
732 /* Don't activate if it is already active. Might happen
733 since ShowWindow DOES activate MDI children */
734 if (clientInfo->hwndActiveChild == child) return 0;
736 TRACE("%04x\n", child);
738 isActiveFrameWnd = (GetActiveWindow() == GetParent(client));
740 /* deactivate prev. active child */
743 SetWindowLongA( prevActiveWnd, GWL_STYLE,
744 GetWindowLongA( prevActiveWnd, GWL_STYLE ) | WS_SYSMENU );
745 SendMessageA( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
746 SendMessageA( prevActiveWnd, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child);
747 /* uncheck menu item */
748 if( clientInfo->hWindowMenu )
750 UINT prevID = GetWindowLongA( prevActiveWnd, GWL_ID );
752 if (prevID - clientInfo->idFirstChild < MDI_MOREWINDOWSLIMIT)
753 CheckMenuItem( clientInfo->hWindowMenu, prevID, 0);
755 CheckMenuItem( clientInfo->hWindowMenu,
756 clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1, 0);
761 if (clientInfo->hwndChildMaximized && clientInfo->hwndChildMaximized != child)
765 clientInfo->hwndActiveChild = child;
766 ShowWindow( child, SW_SHOWMAXIMIZED);
768 else ShowWindow( clientInfo->hwndActiveChild, SW_SHOWNORMAL );
771 clientInfo->hwndActiveChild = child;
773 /* check if we have any children left */
776 if( isActiveFrameWnd )
781 /* check menu item */
782 if( clientInfo->hWindowMenu )
784 UINT id = GetWindowLongA( child, GWL_ID );
785 /* The window to be activated must be displayed in the "Windows" menu */
786 if (id >= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT)
788 MDI_SwapMenuItems( GetParent(child),
789 id, clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1);
790 id = clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1;
791 MDI_MenuModifyItem( GetParent(child), child );
794 CheckMenuItem(clientInfo->hWindowMenu, id, MF_CHECKED);
796 /* bring active child to the top */
797 SetWindowPos( child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
799 if( isActiveFrameWnd )
801 SendMessageA( child, WM_NCACTIVATE, TRUE, 0L);
802 if( GetFocus() == client )
803 SendMessageA( client, WM_SETFOCUS, (WPARAM)client, 0L );
807 SendMessageA( child, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child );
811 /* -------------------- MDI client window functions ------------------- */
813 /**********************************************************************
814 * CreateMDIMenuBitmap
816 static HBITMAP CreateMDIMenuBitmap(void)
818 HDC hDCSrc = CreateCompatibleDC(0);
819 HDC hDCDest = CreateCompatibleDC(hDCSrc);
820 HBITMAP hbClose = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_CLOSE) );
822 HBITMAP hobjSrc, hobjDest;
824 hobjSrc = SelectObject(hDCSrc, hbClose);
825 hbCopy = CreateCompatibleBitmap(hDCSrc,GetSystemMetrics(SM_CXSIZE),GetSystemMetrics(SM_CYSIZE));
826 hobjDest = SelectObject(hDCDest, hbCopy);
828 BitBlt(hDCDest, 0, 0, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE),
829 hDCSrc, GetSystemMetrics(SM_CXSIZE), 0, SRCCOPY);
831 SelectObject(hDCSrc, hobjSrc);
832 DeleteObject(hbClose);
835 hobjSrc = SelectObject( hDCDest, GetStockObject(BLACK_PEN) );
837 MoveToEx( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, 0, NULL );
838 LineTo( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, GetSystemMetrics(SM_CYSIZE) - 1);
840 SelectObject(hDCDest, hobjSrc );
841 SelectObject(hDCDest, hobjDest);
847 /**********************************************************************
850 static LONG MDICascade( HWND client, MDICLIENTINFO *ci )
853 BOOL has_icons = FALSE;
856 if (ci->hwndChildMaximized)
857 SendMessageA( client, WM_MDIRESTORE,
858 (WPARAM)ci->hwndChildMaximized, 0);
860 if (ci->nActiveChildren == 0) return 0;
862 if (!(win_array = WIN_ListChildren( client ))) return 0;
864 /* remove all the windows we don't want */
865 for (i = total = 0; win_array[i]; i++)
867 if (!IsWindowVisible( win_array[i] )) continue;
868 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows */
869 if (IsIconic( win_array[i] ))
874 win_array[total++] = win_array[i];
876 win_array[total] = 0;
880 INT delta = 0, n = 0, i;
882 if (has_icons) delta = GetSystemMetrics(SM_CYICONSPACING) + GetSystemMetrics(SM_CYICON);
884 /* walk the list (backwards) and move windows */
885 for (i = total - 1; i >= 0; i--)
887 TRACE("move %04x to (%ld,%ld) size [%ld,%ld]\n",
888 win_array[i], pos[0].x, pos[0].y, pos[1].x, pos[1].y);
890 MDI_CalcDefaultChildPos(client, n++, pos, delta);
891 SetWindowPos( win_array[i], 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
892 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
895 HeapFree( GetProcessHeap(), 0, win_array );
897 if (has_icons) ArrangeIconicWindows( client );
901 /**********************************************************************
904 static void MDITile( HWND client, MDICLIENTINFO *ci, WPARAM wParam )
908 BOOL has_icons = FALSE;
910 if (ci->hwndChildMaximized)
911 SendMessageA( client, WM_MDIRESTORE, (WPARAM)ci->hwndChildMaximized, 0);
913 if (ci->nActiveChildren == 0) return;
915 if (!(win_array = WIN_ListChildren( client ))) return;
917 /* remove all the windows we don't want */
918 for (i = total = 0; win_array[i]; i++)
920 if (!IsWindowVisible( win_array[i] )) continue;
921 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows (icon titles) */
922 if (IsIconic( win_array[i] ))
927 if ((wParam & MDITILE_SKIPDISABLED) && !IsWindowEnabled( win_array[i] )) continue;
928 win_array[total++] = win_array[i];
930 win_array[total] = 0;
932 TRACE("%u windows to tile\n", total);
936 HWND *pWnd = win_array;
938 int x, y, xsize, ysize;
939 int rows, columns, r, c, i;
941 GetClientRect(client,&rect);
942 rows = (int) sqrt((double)total);
943 columns = total / rows;
945 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
948 rows = columns; /* exchange r and c */
954 y = rect.bottom - 2 * GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
955 rect.bottom = ( y - GetSystemMetrics(SM_CYICON) < rect.top )? rect.bottom: y;
958 ysize = rect.bottom / rows;
959 xsize = rect.right / columns;
961 for (x = i = 0, c = 1; c <= columns && *pWnd; c++)
966 ysize = rect.bottom / rows;
970 for (r = 1; r <= rows && *pWnd; r++, i++)
972 SetWindowPos(*pWnd, 0, x, y, xsize, ysize,
973 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
980 HeapFree( GetProcessHeap(), 0, win_array );
981 if (has_icons) ArrangeIconicWindows( client );
984 /* ----------------------- Frame window ---------------------------- */
987 /**********************************************************************
988 * MDI_AugmentFrameMenu
990 static BOOL MDI_AugmentFrameMenu( HWND frame, HWND hChild )
992 HMENU menu = GetMenu( frame );
993 WND* child = WIN_FindWndPtr(hChild);
995 HBITMAP hSysMenuBitmap = 0;
997 TRACE("frame %04x,child %04x\n",frame,hChild);
999 if( !menu || !child->hSysMenu )
1001 WIN_ReleaseWndPtr(child);
1004 WIN_ReleaseWndPtr(child);
1006 /* create a copy of sysmenu popup and insert it into frame menu bar */
1008 if (!(hSysPopup = LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU")))
1011 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1012 SC_MINIMIZE, (LPSTR)(DWORD)HBMMENU_MBAR_MINIMIZE ) ;
1013 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1014 SC_RESTORE, (LPSTR)(DWORD)HBMMENU_MBAR_RESTORE );
1016 /* In Win 95 look, the system menu is replaced by the child icon */
1018 if(TWEAK_WineLook > WIN31_LOOK)
1020 HICON hIcon = GetClassLongA(hChild, GCL_HICONSM);
1022 hIcon = GetClassLongA(hChild, GCL_HICON);
1026 HBITMAP hBitmap, hOldBitmap;
1028 HDC hdc = GetDC(hChild);
1033 cx = GetSystemMetrics(SM_CXSMICON);
1034 cy = GetSystemMetrics(SM_CYSMICON);
1035 hMemDC = CreateCompatibleDC(hdc);
1036 hBitmap = CreateCompatibleBitmap(hdc, cx, cy);
1037 hOldBitmap = SelectObject(hMemDC, hBitmap);
1038 SetMapMode(hMemDC, MM_TEXT);
1039 hBrush = CreateSolidBrush(GetSysColor(COLOR_MENU));
1040 DrawIconEx(hMemDC, 0, 0, hIcon, cx, cy, 0, hBrush, DI_NORMAL);
1041 SelectObject (hMemDC, hOldBitmap);
1042 DeleteObject(hBrush);
1044 ReleaseDC(hChild, hdc);
1045 hSysMenuBitmap = hBitmap;
1050 hSysMenuBitmap = hBmpClose;
1052 if( !InsertMenuA(menu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
1053 hSysPopup, (LPSTR)(DWORD)hSysMenuBitmap))
1055 TRACE("not inserted\n");
1056 DestroyMenu(hSysPopup);
1060 /* The close button is only present in Win 95 look */
1061 if(TWEAK_WineLook > WIN31_LOOK)
1063 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1064 SC_CLOSE, (LPSTR)(DWORD)HBMMENU_MBAR_CLOSE );
1067 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
1068 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
1069 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
1070 SetMenuDefaultItem(hSysPopup, SC_CLOSE, FALSE);
1078 /**********************************************************************
1079 * MDI_RestoreFrameMenu
1081 static BOOL MDI_RestoreFrameMenu( HWND frame, HWND hChild )
1083 MENUITEMINFOW menuInfo;
1084 HMENU menu = GetMenu( frame );
1085 INT nItems = GetMenuItemCount(menu) - 1;
1086 UINT iId = GetMenuItemID(menu,nItems) ;
1088 TRACE("frame %04x,child %04x,nIt=%d,iId=%d\n",frame,hChild,nItems,iId);
1090 if(!(iId == SC_RESTORE || iId == SC_CLOSE) )
1094 * Remove the system menu, If that menu is the icon of the window
1095 * as it is in win95, we have to delete the bitmap.
1097 memset(&menuInfo, 0, sizeof(menuInfo));
1098 menuInfo.cbSize = sizeof(menuInfo);
1099 menuInfo.fMask = MIIM_DATA | MIIM_TYPE;
1101 GetMenuItemInfoW(menu,
1106 RemoveMenu(menu,0,MF_BYPOSITION);
1108 if ( (menuInfo.fType & MFT_BITMAP) &&
1109 (LOWORD(menuInfo.dwTypeData)!=0) &&
1110 (LOWORD(menuInfo.dwTypeData)!=hBmpClose) )
1112 DeleteObject((HBITMAP)LOWORD(menuInfo.dwTypeData));
1115 if(TWEAK_WineLook > WIN31_LOOK)
1118 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1121 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1123 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1131 /**********************************************************************
1132 * MDI_UpdateFrameText
1134 * used when child window is maximized/restored
1136 * Note: lpTitle can be NULL
1138 static void MDI_UpdateFrameText( HWND frame, HWND hClient,
1139 BOOL repaint, LPCWSTR lpTitle )
1141 WCHAR lpBuffer[MDI_MAXTITLELENGTH+1];
1142 MDICLIENTINFO *ci = get_client_info( hClient );
1144 TRACE("repaint %i, frameText %s\n", repaint, debugstr_w(lpTitle));
1148 if (!lpTitle && !ci->frameTitle) /* first time around, get title from the frame window */
1150 GetWindowTextW( frame, lpBuffer, sizeof(lpBuffer)/sizeof(WCHAR) );
1154 /* store new "default" title if lpTitle is not NULL */
1157 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1158 if ((ci->frameTitle = HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle)+1)*sizeof(WCHAR))))
1159 strcpyW( ci->frameTitle, lpTitle );
1164 if (ci->hwndChildMaximized)
1166 /* combine frame title and child title if possible */
1168 static const WCHAR lpBracket[] = {' ','-',' ','[',0};
1169 static const WCHAR lpBracket2[] = {']',0};
1170 int i_frame_text_length = strlenW(ci->frameTitle);
1172 lstrcpynW( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
1174 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
1176 strcatW( lpBuffer, lpBracket );
1177 if (GetWindowTextW( ci->hwndChildMaximized, lpBuffer + i_frame_text_length + 4,
1178 MDI_MAXTITLELENGTH - i_frame_text_length - 5 ))
1179 strcatW( lpBuffer, lpBracket2 );
1181 lpBuffer[i_frame_text_length] = 0; /* remove bracket */
1186 lstrcpynW(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH+1 );
1192 DefWindowProcW( frame, WM_SETTEXT, 0, (LPARAM)lpBuffer );
1193 if( repaint == MDI_REPAINTFRAME)
1194 SetWindowPos( frame, 0,0,0,0,0, SWP_FRAMECHANGED |
1195 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
1199 /* ----------------------------- Interface ---------------------------- */
1202 /**********************************************************************
1203 * MDIClientWndProc_common
1205 static LRESULT MDIClientWndProc_common( HWND hwnd, UINT message,
1206 WPARAM wParam, LPARAM lParam, BOOL unicode )
1210 if (!(ci = get_client_info( hwnd ))) return 0;
1217 /* Since we are using only cs->lpCreateParams, we can safely
1218 * cast to LPCREATESTRUCTA here */
1219 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
1220 WND *wndPtr = WIN_GetPtr( hwnd );
1222 /* Translation layer doesn't know what's in the cs->lpCreateParams
1223 * so we have to keep track of what environment we're in. */
1225 if( wndPtr->flags & WIN_ISWIN32 )
1227 #define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1228 ci->hWindowMenu = ccs->hWindowMenu;
1229 ci->idFirstChild = ccs->idFirstChild;
1234 LPCLIENTCREATESTRUCT16 ccs = MapSL((SEGPTR)cs->lpCreateParams);
1235 ci->hWindowMenu = ccs->hWindowMenu;
1236 ci->idFirstChild = ccs->idFirstChild;
1238 WIN_ReleasePtr( wndPtr );
1240 ci->hwndChildMaximized = 0;
1241 ci->nActiveChildren = 0;
1242 ci->nTotalCreated = 0;
1243 ci->frameTitle = NULL;
1245 SetWindowLongW( hwnd, GWL_STYLE, GetWindowLongW(hwnd,GWL_STYLE) | WS_CLIPCHILDREN );
1249 hBmpClose = CreateMDIMenuBitmap();
1250 hBmpRestore = LoadBitmapW( 0, MAKEINTRESOURCEW(OBM_RESTORE) );
1253 if (ci->hWindowMenu != 0)
1254 AppendMenuW( ci->hWindowMenu, MF_SEPARATOR, 0, NULL );
1256 GetClientRect( GetParent(hwnd), &rect);
1257 MoveWindow( hwnd, 0, 0, rect.right, rect.bottom, FALSE );
1259 MDI_UpdateFrameText( GetParent(hwnd), hwnd, MDI_NOFRAMEREPAINT, NULL);
1261 TRACE("Client created - hwnd = %04x, idFirst = %u\n",
1262 hwnd, ci->idFirstChild );
1269 if( ci->hwndChildMaximized )
1270 MDI_RestoreFrameMenu( GetParent(hwnd), ci->hwndChildMaximized);
1271 if((ci->hWindowMenu != 0) &&
1272 (nItems = GetMenuItemCount(ci->hWindowMenu)) > 0)
1274 ci->idFirstChild = nItems - 1;
1275 ci->nActiveChildren++; /* to delete a separator */
1276 while( ci->nActiveChildren-- )
1277 DeleteMenu(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
1279 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1283 case WM_MDIACTIVATE:
1284 if( ci->hwndActiveChild != (HWND)wParam )
1285 SetWindowPos((HWND)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
1289 return MDICascade(hwnd, ci);
1293 return (LRESULT)MDICreateChild( hwnd, ci, (MDICREATESTRUCTA *)lParam, unicode );
1297 return MDIDestroyChild( hwnd, ci, WIN_GetFullHandle( (HWND)wParam ), TRUE );
1299 case WM_MDIGETACTIVE:
1300 if (lParam) *(BOOL *)lParam = (ci->hwndChildMaximized != 0);
1301 return (LRESULT)ci->hwndActiveChild;
1303 case WM_MDIICONARRANGE:
1304 ci->mdiFlags |= MDIF_NEEDUPDATE;
1305 ArrangeIconicWindows( hwnd );
1306 ci->sbRecalc = SB_BOTH+1;
1307 SendMessageW( hwnd, WM_MDICALCCHILDSCROLL, 0, 0 );
1310 case WM_MDIMAXIMIZE:
1311 ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1314 case WM_MDINEXT: /* lParam != 0 means previous window */
1315 MDI_SwitchActiveChild( hwnd, WIN_GetFullHandle( (HWND)wParam ), !lParam );
1319 SendMessageW( (HWND)wParam, WM_SYSCOMMAND, SC_RESTORE, 0);
1323 return MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1325 case WM_MDIREFRESHMENU:
1326 return MDIRefreshMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1329 ci->mdiFlags |= MDIF_NEEDUPDATE;
1330 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1331 MDITile( hwnd, ci, wParam );
1332 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1337 ci->mdiFlags |= MDIF_NEEDUPDATE;
1338 ScrollChildren( hwnd, message, wParam, lParam );
1339 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1343 if (ci->hwndActiveChild && !IsIconic( ci->hwndActiveChild ))
1344 SetFocus( ci->hwndActiveChild );
1348 if( ci->hwndActiveChild )
1349 SendMessageW(ci->hwndActiveChild, message, wParam, lParam);
1352 case WM_PARENTNOTIFY:
1353 if (LOWORD(wParam) == WM_LBUTTONDOWN)
1357 pt.x = SLOWORD(lParam);
1358 pt.y = SHIWORD(lParam);
1359 child = ChildWindowFromPoint(hwnd, pt);
1361 TRACE("notification from %04x (%li,%li)\n",child,pt.x,pt.y);
1363 if( child && child != hwnd && child != ci->hwndActiveChild )
1364 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1369 if( IsWindow(ci->hwndChildMaximized) )
1375 rect.right = LOWORD(lParam);
1376 rect.bottom = HIWORD(lParam);
1378 AdjustWindowRectEx(&rect, GetWindowLongA(ci->hwndChildMaximized,GWL_STYLE),
1379 0, GetWindowLongA(ci->hwndChildMaximized,GWL_EXSTYLE) );
1380 MoveWindow(ci->hwndChildMaximized, rect.left, rect.top,
1381 rect.right - rect.left, rect.bottom - rect.top, 1);
1384 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1388 case WM_MDICALCCHILDSCROLL:
1389 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1391 CalcChildScroll(hwnd, ci->sbRecalc-1);
1393 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1397 return unicode ? DefWindowProcW( hwnd, message, wParam, lParam ) :
1398 DefWindowProcA( hwnd, message, wParam, lParam );
1401 /***********************************************************************
1404 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1406 if (!IsWindow(hwnd)) return 0;
1407 return MDIClientWndProc_common( hwnd, message, wParam, lParam, FALSE );
1410 /***********************************************************************
1413 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1415 if (!IsWindow(hwnd)) return 0;
1416 return MDIClientWndProc_common( hwnd, message, wParam, lParam, TRUE );
1419 /***********************************************************************
1420 * DefFrameProc (USER.445)
1422 LRESULT WINAPI DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient,
1423 UINT16 message, WPARAM16 wParam, LPARAM lParam )
1428 lParam = (LPARAM)MapSL(lParam);
1434 return DefFrameProcA( WIN_Handle32(hwnd), WIN_Handle32(hwndMDIClient),
1435 message, wParam, lParam );
1439 MDINEXTMENU next_menu;
1440 DefFrameProcW( WIN_Handle32(hwnd), WIN_Handle32(hwndMDIClient),
1441 message, wParam, (LPARAM)&next_menu );
1442 return MAKELONG( next_menu.hmenuNext, WIN_Handle16(next_menu.hwndNext) );
1445 return DefWindowProc16(hwnd, message, wParam, lParam);
1450 /***********************************************************************
1451 * DefFrameProcA (USER32.@)
1453 LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1454 UINT message, WPARAM wParam, LPARAM lParam)
1462 LPWSTR text = HEAP_strdupAtoW( GetProcessHeap(), 0, (LPSTR)lParam );
1463 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, text );
1464 HeapFree( GetProcessHeap(), 0, text );
1466 return 1; /* success. FIXME: check text length */
1473 return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1476 return DefWindowProcA(hwnd, message, wParam, lParam);
1480 /***********************************************************************
1481 * DefFrameProcW (USER32.@)
1483 LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1484 UINT message, WPARAM wParam, LPARAM lParam)
1486 MDICLIENTINFO *ci = get_client_info( hwndMDIClient );
1494 WORD id = LOWORD(wParam);
1495 /* check for possible syscommands for maximized MDI child */
1496 if (id < ci->idFirstChild || id >= ci->idFirstChild + ci->nActiveChildren)
1498 if( (id - 0xf000) & 0xf00f ) break;
1499 if( !ci->hwndChildMaximized ) break;
1510 return SendMessageW( ci->hwndChildMaximized, WM_SYSCOMMAND,
1517 if (id - ci->idFirstChild == MDI_MOREWINDOWSLIMIT)
1518 /* User chose "More Windows..." */
1519 childHwnd = MDI_MoreWindowsDialog(hwndMDIClient);
1521 /* User chose one of the windows listed in the "Windows" menu */
1522 childHwnd = MDI_GetChildByID(hwndMDIClient,id);
1525 SendMessageW( hwndMDIClient, WM_MDIACTIVATE, (WPARAM)childHwnd, 0 );
1531 SendMessageW(hwndMDIClient, message, wParam, lParam);
1535 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, (LPWSTR)lParam );
1536 return 1; /* success. FIXME: check text length */
1539 SetFocus(hwndMDIClient);
1543 MoveWindow(hwndMDIClient, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
1548 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1550 if (!IsIconic(hwnd) && ci->hwndActiveChild && !ci->hwndChildMaximized)
1552 /* control menu is between the frame system menu and
1553 * the first entry of menu bar */
1554 WND *wndPtr = WIN_GetPtr(hwnd);
1556 if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1557 (wParam == VK_RIGHT && GetSubMenu(wndPtr->hSysMenu, 0) == next_menu->hmenuIn) )
1559 WIN_ReleasePtr(wndPtr);
1560 wndPtr = WIN_GetPtr(ci->hwndActiveChild);
1561 next_menu->hmenuNext = GetSubMenu(wndPtr->hSysMenu, 0);
1562 next_menu->hwndNext = ci->hwndActiveChild;
1564 WIN_ReleasePtr(wndPtr);
1571 return DefWindowProcW( hwnd, message, wParam, lParam );
1575 /***********************************************************************
1576 * DefMDIChildProc (USER.447)
1578 LRESULT WINAPI DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1579 WPARAM16 wParam, LPARAM lParam )
1584 return DefMDIChildProcA( WIN_Handle32(hwnd), message, wParam, (LPARAM)MapSL(lParam) );
1588 case WM_CHILDACTIVATE:
1593 return DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, lParam );
1594 case WM_GETMINMAXINFO:
1596 MINMAXINFO16 *mmi16 = (MINMAXINFO16 *)MapSL(lParam);
1598 STRUCT32_MINMAXINFO16to32( mmi16, &mmi );
1599 DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, (LPARAM)&mmi );
1600 STRUCT32_MINMAXINFO32to16( &mmi, mmi16 );
1605 MDINEXTMENU next_menu;
1606 DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, (LPARAM)&next_menu );
1607 return MAKELONG( next_menu.hmenuNext, WIN_Handle16(next_menu.hwndNext) );
1610 return DefWindowProc16(hwnd, message, wParam, lParam);
1615 /***********************************************************************
1616 * DefMDIChildProcA (USER32.@)
1618 LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1619 WPARAM wParam, LPARAM lParam )
1621 HWND client = GetParent(hwnd);
1622 MDICLIENTINFO *ci = get_client_info( client );
1624 hwnd = WIN_GetFullHandle( hwnd );
1625 if (!ci) return DefWindowProcA( hwnd, message, wParam, lParam );
1630 DefWindowProcA(hwnd, message, wParam, lParam);
1631 MDI_MenuModifyItem( client, hwnd );
1632 if( ci->hwndChildMaximized == hwnd )
1633 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1634 return 1; /* success. FIXME: check text length */
1636 case WM_GETMINMAXINFO:
1640 case WM_CHILDACTIVATE:
1646 return DefMDIChildProcW( hwnd, message, wParam, lParam );
1648 return DefWindowProcA(hwnd, message, wParam, lParam);
1652 /***********************************************************************
1653 * DefMDIChildProcW (USER32.@)
1655 LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1656 WPARAM wParam, LPARAM lParam )
1658 HWND client = GetParent(hwnd);
1659 MDICLIENTINFO *ci = get_client_info( client );
1661 hwnd = WIN_GetFullHandle( hwnd );
1662 if (!ci) return DefWindowProcW( hwnd, message, wParam, lParam );
1667 DefWindowProcW(hwnd, message, wParam, lParam);
1668 MDI_MenuModifyItem( client, hwnd );
1669 if( ci->hwndChildMaximized == hwnd )
1670 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1671 return 1; /* success. FIXME: check text length */
1673 case WM_GETMINMAXINFO:
1674 MDI_ChildGetMinMaxInfo( client, hwnd, (MINMAXINFO *)lParam );
1678 return 0x00010000; /* MDI children don't have menu bars */
1681 SendMessageW( client, WM_MDIDESTROY, (WPARAM)hwnd, 0 );
1685 if (ci->hwndActiveChild != hwnd) MDI_ChildActivate( client, hwnd );
1688 case WM_CHILDACTIVATE:
1689 MDI_ChildActivate( client, hwnd );
1696 if( ci->hwndChildMaximized == hwnd) return 0;
1700 SetWindowLongA( hwnd, GWL_STYLE,
1701 GetWindowLongA( hwnd, GWL_STYLE ) | WS_SYSMENU );
1704 if (ci->hwndChildMaximized == hwnd)
1705 return SendMessageW( GetParent(client), message, wParam, lParam);
1706 SetWindowLongW( hwnd, GWL_STYLE,
1707 GetWindowLongW( hwnd, GWL_STYLE ) & ~WS_SYSMENU );
1710 SendMessageW( client, WM_MDINEXT, 0, 0);
1713 SendMessageW( client, WM_MDINEXT, 0, 1);
1719 if( ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1720 else MDI_PostUpdate(client, ci, SB_BOTH+1);
1724 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1726 ci->hwndChildMaximized = 0;
1727 MDI_RestoreFrameMenu( GetParent(client), hwnd );
1728 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1731 if( wParam == SIZE_MAXIMIZED )
1733 HWND hMaxChild = ci->hwndChildMaximized;
1735 if( hMaxChild == hwnd ) break;
1738 SendMessageW( hMaxChild, WM_SETREDRAW, FALSE, 0 );
1739 MDI_RestoreFrameMenu( GetParent(client), hMaxChild );
1740 ShowWindow( hMaxChild, SW_SHOWNOACTIVATE );
1741 SendMessageW( hMaxChild, WM_SETREDRAW, TRUE, 0 );
1743 TRACE("maximizing child %04x\n", hwnd );
1745 /* keep track of the maximized window. */
1746 ci->hwndChildMaximized = hwnd; /* !!! */
1748 /* The maximized window should also be the active window */
1749 MDI_ChildActivate( client, hwnd );
1750 MDI_AugmentFrameMenu( GetParent(client), hwnd );
1751 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1754 if( wParam == SIZE_MINIMIZED )
1756 HWND switchTo = MDI_GetWindow(ci, hwnd, TRUE, WS_MINIMIZE);
1758 if (switchTo) SendMessageW( switchTo, WM_CHILDACTIVATE, 0, 0);
1760 MDI_PostUpdate(client, ci, SB_BOTH+1);
1765 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1766 HWND parent = GetParent(client);
1768 if( wParam == VK_LEFT ) /* switch to frame system menu */
1770 WND *wndPtr = WIN_GetPtr( parent );
1771 next_menu->hmenuNext = GetSubMenu( wndPtr->hSysMenu, 0 );
1772 WIN_ReleasePtr( wndPtr );
1774 if( wParam == VK_RIGHT ) /* to frame menu bar */
1776 next_menu->hmenuNext = GetMenu(parent);
1778 next_menu->hwndNext = parent;
1785 SendMessageW( hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (DWORD)VK_SPACE);
1790 return DefWindowProcW(hwnd, message, wParam, lParam);
1793 /**********************************************************************
1794 * CreateMDIWindowA (USER32.@) Creates a MDI child
1797 * Success: Handle to created window
1800 HWND WINAPI CreateMDIWindowA(
1801 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1802 LPCSTR lpWindowName, /* [in] Pointer to window name */
1803 DWORD dwStyle, /* [in] Window style */
1804 INT X, /* [in] Horizontal position of window */
1805 INT Y, /* [in] Vertical position of window */
1806 INT nWidth, /* [in] Width of window */
1807 INT nHeight, /* [in] Height of window */
1808 HWND hWndParent, /* [in] Handle to parent window */
1809 HINSTANCE hInstance, /* [in] Handle to application instance */
1810 LPARAM lParam) /* [in] Application-defined value */
1812 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1813 MDICREATESTRUCTA cs;
1815 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
1816 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1817 nWidth,nHeight,hWndParent,hInstance,lParam);
1821 ERR("bad hwnd for MDI-client: %04x\n", hWndParent);
1824 cs.szClass=lpClassName;
1825 cs.szTitle=lpWindowName;
1826 cs.hOwner=hInstance;
1834 return MDICreateChild(hWndParent, pCi, &cs, FALSE);
1837 /***********************************************************************
1838 * CreateMDIWindowW (USER32.@) Creates a MDI child
1841 * Success: Handle to created window
1844 HWND WINAPI CreateMDIWindowW(
1845 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1846 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1847 DWORD dwStyle, /* [in] Window style */
1848 INT X, /* [in] Horizontal position of window */
1849 INT Y, /* [in] Vertical position of window */
1850 INT nWidth, /* [in] Width of window */
1851 INT nHeight, /* [in] Height of window */
1852 HWND hWndParent, /* [in] Handle to parent window */
1853 HINSTANCE hInstance, /* [in] Handle to application instance */
1854 LPARAM lParam) /* [in] Application-defined value */
1856 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1857 MDICREATESTRUCTW cs;
1859 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
1860 debugstr_w(lpClassName), debugstr_w(lpWindowName), dwStyle, X, Y,
1861 nWidth, nHeight, hWndParent, hInstance, lParam);
1865 ERR("bad hwnd for MDI-client: %04x\n", hWndParent);
1868 cs.szClass = lpClassName;
1869 cs.szTitle = lpWindowName;
1870 cs.hOwner = hInstance;
1878 return MDICreateChild(hWndParent, pCi, (MDICREATESTRUCTA *)&cs, TRUE);
1881 /**********************************************************************
1882 * TranslateMDISysAccel (USER32.@)
1884 BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1886 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1888 MDICLIENTINFO *ci = get_client_info( hwndClient );
1891 if (!ci || !IsWindowEnabled(ci->hwndActiveChild)) return 0;
1893 /* translate if the Ctrl key is down and Alt not. */
1895 if( (GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
1897 switch( msg->wParam )
1901 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 ) ? SC_NEXTWINDOW : SC_PREVWINDOW;
1910 TRACE("wParam = %04x\n", wParam);
1911 SendMessageW(ci->hwndActiveChild, WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
1915 return 0; /* failure */
1918 /***********************************************************************
1919 * CalcChildScroll (USER32.@)
1921 void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
1924 RECT childRect, clientRect;
1925 INT vmin, vmax, hmin, hmax, vpos, hpos;
1928 GetClientRect( hwnd, &clientRect );
1929 SetRectEmpty( &childRect );
1931 if ((list = WIN_ListChildren( hwnd )))
1934 for (i = 0; list[i]; i++)
1936 DWORD style = GetWindowLongW( list[i], GWL_STYLE );
1937 if (style & WS_MAXIMIZE)
1939 HeapFree( GetProcessHeap(), 0, list );
1940 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1943 if (style & WS_VISIBLE)
1945 WND *pWnd = WIN_FindWndPtr( list[i] );
1946 UnionRect( &childRect, &pWnd->rectWindow, &childRect );
1947 WIN_ReleaseWndPtr( pWnd );
1950 HeapFree( GetProcessHeap(), 0, list );
1952 UnionRect( &childRect, &clientRect, &childRect );
1954 hmin = childRect.left;
1955 hmax = childRect.right - clientRect.right;
1956 hpos = clientRect.left - childRect.left;
1957 vmin = childRect.top;
1958 vmax = childRect.bottom - clientRect.bottom;
1959 vpos = clientRect.top - childRect.top;
1964 vpos = hpos; vmin = hmin; vmax = hmax;
1966 info.cbSize = sizeof(info);
1967 info.nMax = vmax; info.nMin = vmin; info.nPos = vpos;
1968 info.fMask = SIF_POS | SIF_RANGE;
1969 SetScrollInfo(hwnd, scroll, &info, TRUE);
1972 SCROLL_SetNCSbState( hwnd, vmin, vmax, vpos,
1978 /***********************************************************************
1979 * ScrollChildren (USER32.@)
1981 void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
1985 INT curPos, length, minPos, maxPos, shift;
1988 GetClientRect( hWnd, &rect );
1993 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
1994 curPos = GetScrollPos(hWnd,SB_HORZ);
1995 length = (rect.right - rect.left) / 2;
1996 shift = GetSystemMetrics(SM_CYHSCROLL);
1999 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
2000 curPos = GetScrollPos(hWnd,SB_VERT);
2001 length = (rect.bottom - rect.top) / 2;
2002 shift = GetSystemMetrics(SM_CXVSCROLL);
2011 newPos = curPos - shift;
2014 newPos = curPos + shift;
2017 newPos = curPos - length;
2020 newPos = curPos + length;
2023 case SB_THUMBPOSITION:
2024 newPos = LOWORD(lParam);
2037 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
2041 if( newPos > maxPos )
2044 if( newPos < minPos )
2047 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
2049 if( uMsg == WM_VSCROLL )
2050 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
2051 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2053 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
2054 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2058 /******************************************************************************
2059 * CascadeWindows (USER32.@) Cascades MDI child windows
2062 * Success: Number of cascaded windows.
2066 CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2067 UINT cKids, const HWND *lpKids)
2069 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2070 hwndParent, wFlags, cKids);
2076 /******************************************************************************
2077 * TileWindows (USER32.@) Tiles MDI child windows
2080 * Success: Number of tiled windows.
2084 TileWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2085 UINT cKids, const HWND *lpKids)
2087 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2088 hwndParent, wFlags, cKids);
2093 /************************************************************************
2094 * "More Windows..." functionality
2097 /* MDI_MoreWindowsDlgProc
2099 * This function will process the messages sent to the "More Windows..."
2101 * Return values: 0 = cancel pressed
2102 * HWND = ok pressed or double-click in the list...
2106 static BOOL WINAPI MDI_MoreWindowsDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
2115 MDICLIENTINFO *ci = get_client_info( (HWND)lParam );
2116 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2117 HWND *list, *sorted_list;
2119 if (!(list = WIN_ListChildren( (HWND)lParam ))) return TRUE;
2120 if (!(sorted_list = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
2121 sizeof(HWND) * ci->nActiveChildren )))
2123 HeapFree( GetProcessHeap(), 0, list );
2127 /* Fill the list, sorted by id... */
2128 for (i = 0; list[i]; i++)
2130 UINT id = GetWindowLongW( list[i], GWL_ID ) - ci->idFirstChild;
2131 if (id < ci->nActiveChildren) sorted_list[id] = list[i];
2133 HeapFree( GetProcessHeap(), 0, list );
2135 for (i = 0; i < ci->nActiveChildren; i++)
2139 if (!GetWindowTextW( sorted_list[i], buffer, sizeof(buffer)/sizeof(WCHAR) ))
2141 SendMessageW(hListBox, LB_ADDSTRING, 0, (LPARAM)buffer );
2142 SendMessageW(hListBox, LB_SETITEMDATA, i, (LPARAM)sorted_list[i] );
2143 length = strlenW(buffer); /* FIXME: should use GetTextExtentPoint */
2144 if (length > widest)
2147 /* Make sure the horizontal scrollbar scrolls ok */
2148 SendMessageW(hListBox, LB_SETHORIZONTALEXTENT, widest * 6, 0);
2150 /* Set the current selection */
2151 SendMessageW(hListBox, LB_SETCURSEL, MDI_MOREWINDOWSLIMIT, 0);
2156 switch (LOWORD(wParam))
2159 if (HIWORD(wParam) != LBN_DBLCLK) break;
2163 /* windows are sorted by menu ID, so we must return the
2164 * window associated to the given id
2166 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2167 UINT index = SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
2168 LRESULT res = SendMessageW(hListBox, LB_GETITEMDATA, index, 0);
2169 EndDialog(hDlg, res);
2183 * MDI_MoreWindowsDialog
2185 * Prompts the user with a listbox containing the opened
2186 * documents. The user can then choose a windows and click
2187 * on OK to set the current window to the one selected, or
2188 * CANCEL to cancel. The function returns a handle to the
2192 static HWND MDI_MoreWindowsDialog(HWND hwnd)
2198 hRes = FindResourceA(GetModuleHandleA("USER32"), "MDI_MOREWINDOWS", RT_DIALOGA);
2203 hDlgTmpl = LoadResource(GetModuleHandleA("USER32"), hRes );
2208 template = LockResource( hDlgTmpl );
2213 return (HWND) DialogBoxIndirectParamA(GetModuleHandleA("USER32"),
2214 (LPDLGTEMPLATEA) template,
2215 hwnd, MDI_MoreWindowsDlgProc, (LPARAM) hwnd);
2222 * Will swap the menu IDs for the given 2 positions.
2223 * pos1 and pos2 are menu IDs
2228 static void MDI_SwapMenuItems(HWND parent, UINT pos1, UINT pos2)
2233 if (!(list = WIN_ListChildren( parent ))) return;
2234 for (i = 0; list[i]; i++)
2236 UINT id = GetWindowLongW( list[i], GWL_ID );
2237 if (id == pos1) SetWindowLongW( list[i], GWL_ID, pos2 );
2238 else if (id == pos2) SetWindowLongW( list[i], GWL_ID, pos1 );
2240 HeapFree( GetProcessHeap(), 0, list );