3 * Copyright 1994, Bob Amstadt
4 * 1995,1996 Alex Korobka
6 * This file contains routines to support MDI (Multiple Document
7 * Interface) features .
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * Notes: Fairly complete implementation.
24 * Also, Excel and WinWord do _not_ use MDI so if you're trying
25 * to fix them look elsewhere.
27 * Notes on how the "More Windows..." is implemented:
29 * When we have more than 9 opened windows, a "More Windows..."
30 * option appears in the "Windows" menu. Each child window has
31 * a WND* associated with it, accesible via the children list of
32 * the parent window. This WND* has a wIDmenu member, which reflects
33 * the position of the child in the window list. For example, with
34 * 9 child windows, we could have the following pattern:
38 * Name of the child window pWndChild->wIDmenu
50 * The "Windows" menu, as the "More windows..." dialog, are constructed
51 * in this order. If we add a child, we would have the following list:
54 * Name of the child window pWndChild->wIDmenu
66 * But only 5000 to 5008 would be displayed in the "Windows" menu. We want
67 * the last created child to be in the menu, so we swap the last child with
68 * the 9th... Doc9 will be accessible via the "More Windows..." option.
96 #include "wine/winuser16.h"
97 #include "wine/unicode.h"
100 #include "user_private.h"
101 #include "wine/debug.h"
104 WINE_DEFAULT_DEBUG_CHANNEL(mdi);
106 #define MDI_MAXTITLELENGTH 0xa1
108 #define WM_MDICALCCHILDSCROLL 0x10ac /* this is exactly what Windows uses */
110 /* "More Windows..." definitions */
111 #define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
112 option will appear under the Windows menu */
113 #define MDI_IDC_LISTBOX 100
114 #define IDS_MDI_MOREWINDOWS 13
116 #define MDIF_NEEDUPDATE 0x0001
120 /* At some points, particularly when switching MDI children, active and
121 * maximized MDI children may be not the same window, so we need to track
124 UINT nActiveChildren;
125 HWND hwndChildMaximized;
126 HWND hwndActiveChild;
127 HWND *child; /* array of tracked children */
134 UINT sbRecalc; /* SB_xxx flags for scrollbar fixup */
137 static HBITMAP hBmpClose = 0;
139 /* ----------------- declarations ----------------- */
140 static void MDI_UpdateFrameText( HWND, HWND, BOOL, LPCWSTR);
141 static BOOL MDI_AugmentFrameMenu( HWND, HWND );
142 static BOOL MDI_RestoreFrameMenu( HWND, HWND );
143 static LONG MDI_ChildActivate( HWND, HWND );
144 static LRESULT MDI_RefreshMenu(MDICLIENTINFO *);
146 static HWND MDI_MoreWindowsDialog(HWND);
147 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
148 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
150 /* -------- Miscellaneous service functions ----------
154 static HWND MDI_GetChildByID(HWND hwnd, UINT id, MDICLIENTINFO *ci)
158 for (i = 0; ci->nActiveChildren; i++)
160 if (GetWindowLongPtrW( ci->child[i], GWLP_ID ) == id)
166 static void MDI_PostUpdate(HWND hwnd, MDICLIENTINFO* ci, WORD recalc)
168 if( !(ci->mdiFlags & MDIF_NEEDUPDATE) )
170 ci->mdiFlags |= MDIF_NEEDUPDATE;
171 PostMessageA( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
173 ci->sbRecalc = recalc;
177 /*********************************************************************
178 * MDIClient class descriptor
180 const struct builtin_class_descr MDICLIENT_builtin_class =
182 "MDIClient", /* name */
184 MDIClientWndProcA, /* procA */
185 MDIClientWndProcW, /* procW */
186 sizeof(MDICLIENTINFO), /* extra */
187 IDC_ARROW, /* cursor */
188 (HBRUSH)(COLOR_APPWORKSPACE+1) /* brush */
192 static MDICLIENTINFO *get_client_info( HWND client )
194 MDICLIENTINFO *ret = NULL;
195 WND *win = WIN_GetPtr( client );
198 if (win == WND_OTHER_PROCESS)
200 if (IsWindow(client)) ERR( "client %p belongs to other process\n", client );
203 if (win->cbWndExtra < sizeof(MDICLIENTINFO)) WARN( "%p is not an MDI client\n", client );
204 else ret = (MDICLIENTINFO *)win->wExtra;
205 WIN_ReleasePtr( win );
210 static BOOL is_close_enabled(HWND hwnd, HMENU hSysMenu)
212 if (GetClassLongW(hwnd, GCL_STYLE) & CS_NOCLOSE) return FALSE;
214 if (!hSysMenu) hSysMenu = GetSystemMenu(hwnd, FALSE);
217 UINT state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
218 if (state == 0xFFFFFFFF || (state & (MF_DISABLED | MF_GRAYED)))
224 /**********************************************************************
227 * returns "activatable" child different from the current or zero
229 static HWND MDI_GetWindow(MDICLIENTINFO *clientInfo, HWND hWnd, BOOL bNext,
236 dwStyleMask |= WS_DISABLED | WS_VISIBLE;
237 if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
239 if (!(list = WIN_ListChildren( GetParent(hWnd) ))) return 0;
241 /* start from next after hWnd */
242 while (list[i] && list[i] != hWnd) i++;
245 for ( ; list[i]; i++)
247 if (GetWindow( list[i], GW_OWNER )) continue;
248 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
250 if (bNext) goto found;
252 /* now restart from the beginning */
253 for (i = 0; list[i] && list[i] != hWnd; i++)
255 if (GetWindow( list[i], GW_OWNER )) continue;
256 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
258 if (bNext) goto found;
261 HeapFree( GetProcessHeap(), 0, list );
265 /**********************************************************************
266 * MDI_CalcDefaultChildPos
268 * It seems that the default height is about 2/3 of the client rect
270 void MDI_CalcDefaultChildPos( HWND hwndClient, INT total, LPPOINT lpPos, INT delta, UINT *id )
274 INT spacing = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME) - 1;
276 if (total < 0) /* we are called from CreateWindow */
278 MDICLIENTINFO *ci = get_client_info(hwndClient);
279 total = ci ? ci->nTotalCreated : 0;
280 *id = ci->idFirstChild + ci->nActiveChildren;
281 TRACE("MDI child id %04x\n", *id);
284 GetClientRect( hwndClient, &rect );
285 if( rect.bottom - rect.top - delta >= spacing )
286 rect.bottom -= delta;
288 nstagger = (rect.bottom - rect.top)/(3 * spacing);
289 lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
290 lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
291 lpPos[0].x = lpPos[0].y = spacing * (total%(nstagger+1));
294 /**********************************************************************
297 static LRESULT MDISetMenu( HWND hwnd, HMENU hmenuFrame,
301 HWND hwndFrame = GetParent(hwnd);
303 TRACE("%p %p %p\n", hwnd, hmenuFrame, hmenuWindow);
305 if (hmenuFrame && !IsMenu(hmenuFrame))
307 WARN("hmenuFrame is not a menu handle\n");
311 if (hmenuWindow && !IsMenu(hmenuWindow))
313 WARN("hmenuWindow is not a menu handle\n");
317 if (!(ci = get_client_info( hwnd ))) return 0;
321 if (hmenuFrame == ci->hFrameMenu) return (LRESULT)hmenuFrame;
323 if (IsZoomed(ci->hwndActiveChild))
324 MDI_RestoreFrameMenu( hwndFrame, ci->hwndActiveChild );
327 if( hmenuWindow && hmenuWindow != ci->hWindowMenu )
329 /* delete menu items from ci->hWindowMenu
330 * and add them to hmenuWindow */
331 /* Agent newsreader calls this function with ci->hWindowMenu == NULL */
332 if( ci->hWindowMenu && ci->nActiveChildren )
334 UINT nActiveChildren_old = ci->nActiveChildren;
336 /* Remove all items from old Window menu */
337 ci->nActiveChildren = 0;
340 ci->hWindowMenu = hmenuWindow;
342 /* Add items to the new Window menu */
343 ci->nActiveChildren = nActiveChildren_old;
347 ci->hWindowMenu = hmenuWindow;
352 SetMenu(hwndFrame, hmenuFrame);
353 if( hmenuFrame != ci->hFrameMenu )
355 HMENU oldFrameMenu = ci->hFrameMenu;
357 ci->hFrameMenu = hmenuFrame;
358 if (IsZoomed(ci->hwndActiveChild) && (GetWindowLongW(ci->hwndActiveChild, GWL_STYLE) & WS_VISIBLE))
359 MDI_AugmentFrameMenu( hwndFrame, ci->hwndActiveChild );
361 return (LRESULT)oldFrameMenu;
366 /* SetMenu() may already have been called, meaning that this window
367 * already has its menu. But they may have done a SetMenu() on
368 * an MDI window, and called MDISetMenu() after the fact, meaning
369 * that the "if" to this "else" wouldn't catch the need to
370 * augment the frame menu.
372 if( IsZoomed(ci->hwndActiveChild) )
373 MDI_AugmentFrameMenu( hwndFrame, ci->hwndActiveChild );
379 /**********************************************************************
382 static LRESULT MDI_RefreshMenu(MDICLIENTINFO *ci)
384 UINT i, count, visible, id;
385 WCHAR buf[MDI_MAXTITLELENGTH];
387 TRACE("children %u, window menu %p\n", ci->nActiveChildren, ci->hWindowMenu);
389 if (!ci->hWindowMenu)
392 if (!IsMenu(ci->hWindowMenu))
394 WARN("Window menu handle %p is no more valid\n", ci->hWindowMenu);
398 /* Windows finds the last separator in the menu, and if after it
399 * there is a menu item with MDI magic ID removes all existing
400 * menu items after it, and then adds visible MDI children.
402 count = GetMenuItemCount(ci->hWindowMenu);
403 for (i = 0; i < count; i++)
407 memset(&mii, 0, sizeof(mii));
408 mii.cbSize = sizeof(mii);
409 mii.fMask = MIIM_TYPE;
410 if (GetMenuItemInfoW(ci->hWindowMenu, i, TRUE, &mii))
412 if (mii.fType & MF_SEPARATOR)
414 /* Windows checks only ID of the menu item */
415 memset(&mii, 0, sizeof(mii));
416 mii.cbSize = sizeof(mii);
418 if (GetMenuItemInfoW(ci->hWindowMenu, i + 1, TRUE, &mii))
420 if (mii.wID == ci->idFirstChild)
422 TRACE("removing %u items including separator\n", count - i);
423 while (RemoveMenu(ci->hWindowMenu, i, MF_BYPOSITION))
434 for (i = 0; i < ci->nActiveChildren; i++)
436 if (GetWindowLongW(ci->child[i], GWL_STYLE) & WS_VISIBLE)
438 id = ci->idFirstChild + visible;
440 if (visible == MDI_MOREWINDOWSLIMIT)
442 LoadStringW(user32_module, IDS_MDI_MOREWINDOWS, buf, sizeof(buf)/sizeof(WCHAR));
443 AppendMenuW(ci->hWindowMenu, MF_STRING, id, buf);
448 /* Visio expects that separator has id 0 */
449 AppendMenuW(ci->hWindowMenu, MF_SEPARATOR, 0, NULL);
453 SetWindowLongPtrW(ci->child[i], GWLP_ID, id);
456 buf[1] = '0' + visible;
458 InternalGetWindowText(ci->child[i], buf + 3, sizeof(buf)/sizeof(WCHAR) - 3);
459 TRACE("Adding %p, id %u %s\n", ci->child[i], id, debugstr_w(buf));
460 AppendMenuW(ci->hWindowMenu, MF_STRING, id, buf);
462 if (ci->child[i] == ci->hwndActiveChild)
463 CheckMenuItem(ci->hWindowMenu, id, MF_CHECKED);
466 TRACE("MDI child %p is not visible, skipping\n", ci->child[i]);
469 return (LRESULT)ci->hFrameMenu;
473 /* ------------------ MDI child window functions ---------------------- */
475 /**********************************************************************
476 * MDI_ChildGetMinMaxInfo
478 * Note: The rule here is that client rect of the maximized MDI child
479 * is equal to the client rect of the MDI client window.
481 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
485 GetClientRect( client, &rect );
486 AdjustWindowRectEx( &rect, GetWindowLongW( hwnd, GWL_STYLE ),
487 0, GetWindowLongW( hwnd, GWL_EXSTYLE ));
489 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
490 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
492 lpMinMax->ptMaxPosition.x = rect.left;
493 lpMinMax->ptMaxPosition.y = rect.top;
495 TRACE("max rect (%d,%d - %d, %d)\n",
496 rect.left,rect.top,rect.right,rect.bottom);
499 /**********************************************************************
500 * MDI_SwitchActiveChild
502 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
505 static void MDI_SwitchActiveChild( MDICLIENTINFO *ci, HWND hwndTo, BOOL activate )
509 hwndPrev = ci->hwndActiveChild;
511 TRACE("from %p, to %p\n", hwndPrev, hwndTo);
513 if ( hwndTo != hwndPrev )
515 BOOL was_zoomed = IsZoomed(hwndPrev);
519 /* restore old MDI child */
520 SendMessageW( hwndPrev, WM_SETREDRAW, FALSE, 0 );
521 ShowWindow( hwndPrev, SW_RESTORE );
522 SendMessageW( hwndPrev, WM_SETREDRAW, TRUE, 0 );
524 /* activate new MDI child */
525 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
526 /* maximize new MDI child */
527 ShowWindow( hwndTo, SW_MAXIMIZE );
529 /* activate new MDI child */
530 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | (activate ? 0 : SWP_NOACTIVATE) );
535 /**********************************************************************
538 static LRESULT MDIDestroyChild( HWND client, MDICLIENTINFO *ci,
539 HWND child, BOOL flagDestroy )
543 TRACE("# of managed children %u\n", ci->nActiveChildren);
545 if( child == ci->hwndActiveChild )
547 HWND next = MDI_GetWindow(ci, child, TRUE, 0);
548 /* flagDestroy == 0 means we were called from WM_PARENTNOTIFY handler */
549 if (flagDestroy && next)
550 MDI_SwitchActiveChild(ci, next, TRUE);
553 ShowWindow(child, SW_HIDE);
554 if (child == ci->hwndChildMaximized)
556 HWND frame = GetParent(client);
557 MDI_RestoreFrameMenu(frame, child);
558 ci->hwndChildMaximized = 0;
559 MDI_UpdateFrameText(frame, client, TRUE, NULL);
561 if (flagDestroy) ci->hwndActiveChild = 0;
565 for (i = 0; i < ci->nActiveChildren; i++)
567 if (ci->child[i] == child)
569 HWND *new_child = HeapAlloc(GetProcessHeap(), 0, (ci->nActiveChildren - 1) * sizeof(HWND));
570 memcpy(new_child, ci->child, i * sizeof(HWND));
571 if (i + 1 < ci->nActiveChildren)
572 memcpy(new_child + i, ci->child + i + 1, (ci->nActiveChildren - i - 1) * sizeof(HWND));
573 HeapFree(GetProcessHeap(), 0, ci->child);
574 ci->child = new_child;
576 ci->nActiveChildren--;
583 SendMessageW(client, WM_MDIREFRESHMENU, 0, 0);
584 MDI_PostUpdate(GetParent(child), ci, SB_BOTH+1);
585 DestroyWindow(child);
588 TRACE("child destroyed - %p\n", child);
593 /**********************************************************************
596 * Called in response to WM_CHILDACTIVATE, or when last MDI child
597 * is being deactivated.
599 static LONG MDI_ChildActivate( HWND client, HWND child )
601 MDICLIENTINFO *clientInfo;
602 HWND prevActiveWnd, frame;
603 BOOL isActiveFrameWnd;
605 clientInfo = get_client_info( client );
607 if (clientInfo->hwndActiveChild == child) return 0;
609 TRACE("%p\n", child);
611 frame = GetParent(client);
612 isActiveFrameWnd = (GetActiveWindow() == frame);
613 prevActiveWnd = clientInfo->hwndActiveChild;
615 /* deactivate prev. active child */
618 SendMessageW( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
619 SendMessageW( prevActiveWnd, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child);
622 MDI_SwitchActiveChild( clientInfo, child, FALSE );
623 clientInfo->hwndActiveChild = child;
625 MDI_RefreshMenu(clientInfo);
627 if( isActiveFrameWnd )
629 SendMessageW( child, WM_NCACTIVATE, TRUE, 0L);
630 /* Let the client window manage focus for children, but if the focus
631 * is already on the client (for instance this is the 1st child) then
632 * SetFocus won't work. It appears that Windows sends WM_SETFOCUS
633 * manually in this case.
635 if (SetFocus(client) == client)
636 SendMessageW( client, WM_SETFOCUS, (WPARAM)client, 0 );
639 SendMessageW( child, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child );
643 /* -------------------- MDI client window functions ------------------- */
645 /**********************************************************************
646 * CreateMDIMenuBitmap
648 static HBITMAP CreateMDIMenuBitmap(void)
650 HDC hDCSrc = CreateCompatibleDC(0);
651 HDC hDCDest = CreateCompatibleDC(hDCSrc);
652 HBITMAP hbClose = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_OLD_CLOSE) );
654 HBITMAP hobjSrc, hobjDest;
656 hobjSrc = SelectObject(hDCSrc, hbClose);
657 hbCopy = CreateCompatibleBitmap(hDCSrc,GetSystemMetrics(SM_CXSIZE),GetSystemMetrics(SM_CYSIZE));
658 hobjDest = SelectObject(hDCDest, hbCopy);
660 BitBlt(hDCDest, 0, 0, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE),
661 hDCSrc, GetSystemMetrics(SM_CXSIZE), 0, SRCCOPY);
663 SelectObject(hDCSrc, hobjSrc);
664 DeleteObject(hbClose);
667 hobjSrc = SelectObject( hDCDest, GetStockObject(BLACK_PEN) );
669 MoveToEx( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, 0, NULL );
670 LineTo( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, GetSystemMetrics(SM_CYSIZE) - 1);
672 SelectObject(hDCDest, hobjSrc );
673 SelectObject(hDCDest, hobjDest);
679 /**********************************************************************
682 static LONG MDICascade( HWND client, MDICLIENTINFO *ci )
685 BOOL has_icons = FALSE;
688 if (IsZoomed(ci->hwndActiveChild))
689 SendMessageW(client, WM_MDIRESTORE, (WPARAM)ci->hwndActiveChild, 0);
691 if (ci->nActiveChildren == 0) return 0;
693 if (!(win_array = WIN_ListChildren( client ))) return 0;
695 /* remove all the windows we don't want */
696 for (i = total = 0; win_array[i]; i++)
698 if (!IsWindowVisible( win_array[i] )) continue;
699 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows */
700 if (IsIconic( win_array[i] ))
705 win_array[total++] = win_array[i];
707 win_array[total] = 0;
711 INT delta = 0, n = 0, i;
713 if (has_icons) delta = GetSystemMetrics(SM_CYICONSPACING) + GetSystemMetrics(SM_CYICON);
715 /* walk the list (backwards) and move windows */
716 for (i = total - 1; i >= 0; i--)
718 TRACE("move %p to (%d,%d) size [%d,%d]\n",
719 win_array[i], pos[0].x, pos[0].y, pos[1].x, pos[1].y);
721 MDI_CalcDefaultChildPos(client, n++, pos, delta, NULL);
722 SetWindowPos( win_array[i], 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
723 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
726 HeapFree( GetProcessHeap(), 0, win_array );
728 if (has_icons) ArrangeIconicWindows( client );
732 /**********************************************************************
735 static void MDITile( HWND client, MDICLIENTINFO *ci, WPARAM wParam )
739 BOOL has_icons = FALSE;
741 if (IsZoomed(ci->hwndActiveChild))
742 SendMessageW(client, WM_MDIRESTORE, (WPARAM)ci->hwndActiveChild, 0);
744 if (ci->nActiveChildren == 0) return;
746 if (!(win_array = WIN_ListChildren( client ))) return;
748 /* remove all the windows we don't want */
749 for (i = total = 0; win_array[i]; i++)
751 if (!IsWindowVisible( win_array[i] )) continue;
752 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows (icon titles) */
753 if (IsIconic( win_array[i] ))
758 if ((wParam & MDITILE_SKIPDISABLED) && !IsWindowEnabled( win_array[i] )) continue;
759 win_array[total++] = win_array[i];
761 win_array[total] = 0;
763 TRACE("%u windows to tile\n", total);
767 HWND *pWnd = win_array;
769 int x, y, xsize, ysize;
770 int rows, columns, r, c, i;
772 GetClientRect(client,&rect);
773 rows = (int) sqrt((double)total);
774 columns = total / rows;
776 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
779 rows = columns; /* exchange r and c */
785 y = rect.bottom - 2 * GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
786 rect.bottom = ( y - GetSystemMetrics(SM_CYICON) < rect.top )? rect.bottom: y;
789 ysize = rect.bottom / rows;
790 xsize = rect.right / columns;
792 for (x = i = 0, c = 1; c <= columns && *pWnd; c++)
797 ysize = rect.bottom / rows;
801 for (r = 1; r <= rows && *pWnd; r++, i++)
803 SetWindowPos(*pWnd, 0, x, y, xsize, ysize,
804 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
811 HeapFree( GetProcessHeap(), 0, win_array );
812 if (has_icons) ArrangeIconicWindows( client );
815 /* ----------------------- Frame window ---------------------------- */
818 /**********************************************************************
819 * MDI_AugmentFrameMenu
821 static BOOL MDI_AugmentFrameMenu( HWND frame, HWND hChild )
823 HMENU menu = GetMenu( frame );
825 HBITMAP hSysMenuBitmap = 0;
828 TRACE("frame %p,child %p\n",frame,hChild);
830 if( !menu ) return 0;
832 /* create a copy of sysmenu popup and insert it into frame menu bar */
833 if (!(hSysPopup = GetSystemMenu(hChild, FALSE)))
835 TRACE("child %p doesn't have a system menu\n", hChild);
839 AppendMenuW(menu, MF_HELP | MF_BITMAP,
840 SC_MINIMIZE, (LPCWSTR)HBMMENU_MBAR_MINIMIZE ) ;
841 AppendMenuW(menu, MF_HELP | MF_BITMAP,
842 SC_RESTORE, (LPCWSTR)HBMMENU_MBAR_RESTORE );
843 AppendMenuW(menu, MF_HELP | MF_BITMAP,
844 SC_CLOSE, is_close_enabled(hChild, hSysPopup) ?
845 (LPCWSTR)HBMMENU_MBAR_CLOSE : (LPCWSTR)HBMMENU_MBAR_CLOSE_D );
847 /* The system menu is replaced by the child icon */
848 hIcon = (HICON)GetClassLongPtrW(hChild, GCLP_HICONSM);
850 hIcon = (HICON)GetClassLongPtrW(hChild, GCLP_HICON);
852 hIcon = LoadImageW(0, MAKEINTRESOURCEW(IDI_WINLOGO), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
856 HBITMAP hBitmap, hOldBitmap;
858 HDC hdc = GetDC(hChild);
863 cx = GetSystemMetrics(SM_CXSMICON);
864 cy = GetSystemMetrics(SM_CYSMICON);
865 hMemDC = CreateCompatibleDC(hdc);
866 hBitmap = CreateCompatibleBitmap(hdc, cx, cy);
867 hOldBitmap = SelectObject(hMemDC, hBitmap);
868 SetMapMode(hMemDC, MM_TEXT);
869 hBrush = CreateSolidBrush(GetSysColor(COLOR_MENU));
870 DrawIconEx(hMemDC, 0, 0, hIcon, cx, cy, 0, hBrush, DI_NORMAL);
871 SelectObject (hMemDC, hOldBitmap);
872 DeleteObject(hBrush);
874 ReleaseDC(hChild, hdc);
875 hSysMenuBitmap = hBitmap;
879 if( !InsertMenuA(menu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
880 (UINT_PTR)hSysPopup, (LPSTR)hSysMenuBitmap))
882 TRACE("not inserted\n");
883 DestroyMenu(hSysPopup);
887 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
888 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
889 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
890 SetMenuDefaultItem(hSysPopup, SC_CLOSE, FALSE);
898 /**********************************************************************
899 * MDI_RestoreFrameMenu
901 static BOOL MDI_RestoreFrameMenu( HWND frame, HWND hChild )
903 MENUITEMINFOW menuInfo;
904 HMENU menu = GetMenu( frame );
906 TRACE("frame %p, child %p\n", frame, hChild);
908 if( !menu ) return 0;
911 * Remove the system menu, If that menu is the icon of the window
912 * as it is in win95, we have to delete the bitmap.
914 memset(&menuInfo, 0, sizeof(menuInfo));
915 menuInfo.cbSize = sizeof(menuInfo);
916 menuInfo.fMask = MIIM_DATA | MIIM_TYPE;
918 GetMenuItemInfoW(menu,
923 RemoveMenu(menu,0,MF_BYPOSITION);
925 if ( (menuInfo.fType & MFT_BITMAP) &&
926 (LOWORD(menuInfo.dwTypeData)!=0) &&
927 (LOWORD(menuInfo.dwTypeData)!=HBITMAP_16(hBmpClose)) )
929 DeleteObject(HBITMAP_32(LOWORD(menuInfo.dwTypeData)));
933 DeleteMenu(menu, SC_CLOSE, MF_BYCOMMAND);
935 DeleteMenu(menu, SC_RESTORE, MF_BYCOMMAND);
937 DeleteMenu(menu, SC_MINIMIZE, MF_BYCOMMAND);
945 /**********************************************************************
946 * MDI_UpdateFrameText
948 * used when child window is maximized/restored
950 * Note: lpTitle can be NULL
952 static void MDI_UpdateFrameText( HWND frame, HWND hClient, BOOL repaint, LPCWSTR lpTitle )
954 WCHAR lpBuffer[MDI_MAXTITLELENGTH+1];
955 MDICLIENTINFO *ci = get_client_info( hClient );
957 TRACE("frameText %s\n", debugstr_w(lpTitle));
961 if (!lpTitle && !ci->frameTitle) /* first time around, get title from the frame window */
963 GetWindowTextW( frame, lpBuffer, sizeof(lpBuffer)/sizeof(WCHAR) );
967 /* store new "default" title if lpTitle is not NULL */
970 HeapFree( GetProcessHeap(), 0, ci->frameTitle );
971 if ((ci->frameTitle = HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle)+1)*sizeof(WCHAR))))
972 strcpyW( ci->frameTitle, lpTitle );
977 if (IsZoomed(ci->hwndActiveChild) && IsWindowVisible(ci->hwndActiveChild))
979 /* combine frame title and child title if possible */
981 static const WCHAR lpBracket[] = {' ','-',' ','[',0};
982 static const WCHAR lpBracket2[] = {']',0};
983 int i_frame_text_length = strlenW(ci->frameTitle);
985 lstrcpynW( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
987 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
989 strcatW( lpBuffer, lpBracket );
990 if (GetWindowTextW( ci->hwndActiveChild, lpBuffer + i_frame_text_length + 4,
991 MDI_MAXTITLELENGTH - i_frame_text_length - 5 ))
992 strcatW( lpBuffer, lpBracket2 );
994 lpBuffer[i_frame_text_length] = 0; /* remove bracket */
999 lstrcpynW(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH+1 );
1005 DefWindowProcW( frame, WM_SETTEXT, 0, (LPARAM)lpBuffer );
1008 SetWindowPos( frame, 0,0,0,0,0, SWP_FRAMECHANGED |
1009 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
1013 /* ----------------------------- Interface ---------------------------- */
1016 /**********************************************************************
1017 * MDIClientWndProc_common
1019 static LRESULT MDIClientWndProc_common( HWND hwnd, UINT message,
1020 WPARAM wParam, LPARAM lParam, BOOL unicode )
1024 TRACE("%p %04x (%s) %08x %08lx\n", hwnd, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1026 if (!(ci = get_client_info( hwnd ))) return 0;
1032 /* Since we are using only cs->lpCreateParams, we can safely
1033 * cast to LPCREATESTRUCTA here */
1034 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
1035 WND *wndPtr = WIN_GetPtr( hwnd );
1037 wndPtr->flags |= WIN_ISMDICLIENT;
1039 /* Translation layer doesn't know what's in the cs->lpCreateParams
1040 * so we have to keep track of what environment we're in. */
1042 if( wndPtr->flags & WIN_ISWIN32 )
1044 LPCLIENTCREATESTRUCT ccs = cs->lpCreateParams;
1045 ci->hWindowMenu = ccs->hWindowMenu;
1046 ci->idFirstChild = ccs->idFirstChild;
1050 LPCLIENTCREATESTRUCT16 ccs = MapSL((SEGPTR)cs->lpCreateParams);
1051 ci->hWindowMenu = HMENU_32(ccs->hWindowMenu);
1052 ci->idFirstChild = ccs->idFirstChild;
1054 WIN_ReleasePtr( wndPtr );
1056 ci->hwndChildMaximized = 0;
1058 ci->nActiveChildren = 0;
1059 ci->nTotalCreated = 0;
1060 ci->frameTitle = NULL;
1062 ci->hFrameMenu = GetMenu(cs->hwndParent);
1064 if (!hBmpClose) hBmpClose = CreateMDIMenuBitmap();
1066 TRACE("Client created: hwnd %p, Window menu %p, idFirst = %04x\n",
1067 hwnd, ci->hWindowMenu, ci->idFirstChild );
1073 if( ci->hwndChildMaximized )
1074 MDI_RestoreFrameMenu(GetParent(hwnd), ci->hwndChildMaximized);
1076 ci->nActiveChildren = 0;
1077 MDI_RefreshMenu(ci);
1079 HeapFree( GetProcessHeap(), 0, ci->child );
1080 HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1085 case WM_MDIACTIVATE:
1087 if( ci->hwndActiveChild != (HWND)wParam )
1088 SetWindowPos((HWND)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
1093 return MDICascade(hwnd, ci);
1102 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)lParam;
1103 child = CreateWindowExW(WS_EX_MDICHILD, csW->szClass,
1104 csW->szTitle, csW->style,
1105 csW->x, csW->y, csW->cx, csW->cy,
1106 hwnd, 0, csW->hOwner,
1107 (LPVOID)csW->lParam);
1111 MDICREATESTRUCTA *csA = (MDICREATESTRUCTA *)lParam;
1112 child = CreateWindowExA(WS_EX_MDICHILD, csA->szClass,
1113 csA->szTitle, csA->style,
1114 csA->x, csA->y, csA->cx, csA->cy,
1115 hwnd, 0, csA->hOwner,
1116 (LPVOID)csA->lParam);
1119 if (IsZoomed(ci->hwndActiveChild))
1121 MDI_AugmentFrameMenu(GetParent(hwnd), child);
1122 MDI_UpdateFrameText(GetParent(hwnd), hwnd, TRUE, NULL);
1124 return (LRESULT)child;
1129 return MDIDestroyChild( hwnd, ci, WIN_GetFullHandle( (HWND)wParam ), TRUE );
1131 case WM_MDIGETACTIVE:
1132 if (lParam) *(BOOL *)lParam = IsZoomed(ci->hwndActiveChild);
1133 return (LRESULT)ci->hwndActiveChild;
1135 case WM_MDIICONARRANGE:
1136 ci->mdiFlags |= MDIF_NEEDUPDATE;
1137 ArrangeIconicWindows( hwnd );
1138 ci->sbRecalc = SB_BOTH+1;
1139 SendMessageW( hwnd, WM_MDICALCCHILDSCROLL, 0, 0 );
1142 case WM_MDIMAXIMIZE:
1143 ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1146 case WM_MDINEXT: /* lParam != 0 means previous window */
1148 HWND next = MDI_GetWindow( ci, WIN_GetFullHandle( (HWND)wParam ), !lParam, 0 );
1149 MDI_SwitchActiveChild( ci, next, TRUE );
1154 ShowWindow( (HWND)wParam, SW_SHOWNORMAL );
1158 return MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1160 case WM_MDIREFRESHMENU:
1161 return MDI_RefreshMenu( ci );
1164 ci->mdiFlags |= MDIF_NEEDUPDATE;
1165 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1166 MDITile( hwnd, ci, wParam );
1167 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1172 ci->mdiFlags |= MDIF_NEEDUPDATE;
1173 ScrollChildren( hwnd, message, wParam, lParam );
1174 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1178 if (ci->hwndActiveChild && !IsIconic( ci->hwndActiveChild ))
1179 SetFocus( ci->hwndActiveChild );
1183 if( ci->hwndActiveChild )
1184 SendMessageW(ci->hwndActiveChild, message, wParam, lParam);
1187 case WM_PARENTNOTIFY:
1188 switch (LOWORD(wParam))
1191 if (GetWindowLongW((HWND)lParam, GWL_EXSTYLE) & WS_EX_MDICHILD)
1193 ci->nTotalCreated++;
1194 ci->nActiveChildren++;
1197 ci->child = HeapAlloc(GetProcessHeap(), 0, sizeof(HWND));
1199 ci->child = HeapReAlloc(GetProcessHeap(), 0, ci->child, sizeof(HWND) * ci->nActiveChildren);
1201 TRACE("Adding MDI child %p, # of children %d\n",
1202 (HWND)lParam, ci->nActiveChildren);
1204 ci->child[ci->nActiveChildren - 1] = (HWND)lParam;
1208 case WM_LBUTTONDOWN:
1212 pt.x = (short)LOWORD(lParam);
1213 pt.y = (short)HIWORD(lParam);
1214 child = ChildWindowFromPoint(hwnd, pt);
1216 TRACE("notification from %p (%i,%i)\n",child,pt.x,pt.y);
1218 if( child && child != hwnd && child != ci->hwndActiveChild )
1219 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1224 return MDIDestroyChild( hwnd, ci, WIN_GetFullHandle( (HWND)lParam ), FALSE );
1229 if( IsWindow(ci->hwndActiveChild) && IsZoomed(ci->hwndActiveChild) &&
1230 (GetWindowLongW(ci->hwndActiveChild, GWL_STYLE) & WS_VISIBLE) )
1236 rect.right = LOWORD(lParam);
1237 rect.bottom = HIWORD(lParam);
1239 AdjustWindowRectEx(&rect, GetWindowLongA(ci->hwndActiveChild, GWL_STYLE),
1240 0, GetWindowLongA(ci->hwndActiveChild, GWL_EXSTYLE) );
1241 MoveWindow(ci->hwndActiveChild, rect.left, rect.top,
1242 rect.right - rect.left, rect.bottom - rect.top, 1);
1245 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1249 case WM_MDICALCCHILDSCROLL:
1250 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1252 CalcChildScroll(hwnd, ci->sbRecalc-1);
1254 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1258 return unicode ? DefWindowProcW( hwnd, message, wParam, lParam ) :
1259 DefWindowProcA( hwnd, message, wParam, lParam );
1262 /***********************************************************************
1265 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1267 if (!IsWindow(hwnd)) return 0;
1268 return MDIClientWndProc_common( hwnd, message, wParam, lParam, FALSE );
1271 /***********************************************************************
1274 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1276 if (!IsWindow(hwnd)) return 0;
1277 return MDIClientWndProc_common( hwnd, message, wParam, lParam, TRUE );
1280 /***********************************************************************
1281 * DefFrameProcA (USER32.@)
1283 LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1284 UINT message, WPARAM wParam, LPARAM lParam)
1292 DWORD len = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0 );
1293 LPWSTR text = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1294 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, text, len );
1295 MDI_UpdateFrameText( hwnd, hwndMDIClient, FALSE, text );
1296 HeapFree( GetProcessHeap(), 0, text );
1298 return 1; /* success. FIXME: check text length */
1305 return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1308 return DefWindowProcA(hwnd, message, wParam, lParam);
1312 /***********************************************************************
1313 * DefFrameProcW (USER32.@)
1315 LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1316 UINT message, WPARAM wParam, LPARAM lParam)
1318 MDICLIENTINFO *ci = get_client_info( hwndMDIClient );
1320 TRACE("%p %p %04x (%s) %08x %08lx\n", hwnd, hwndMDIClient, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1328 WORD id = LOWORD(wParam);
1329 /* check for possible syscommands for maximized MDI child */
1330 if (id < ci->idFirstChild || id >= ci->idFirstChild + ci->nActiveChildren)
1332 if( (id - 0xf000) & 0xf00f ) break;
1333 if( !ci->hwndChildMaximized ) break;
1337 if (!is_close_enabled(ci->hwndActiveChild, 0)) break;
1345 return SendMessageW( ci->hwndChildMaximized, WM_SYSCOMMAND,
1352 if (id - ci->idFirstChild == MDI_MOREWINDOWSLIMIT)
1353 /* User chose "More Windows..." */
1354 childHwnd = MDI_MoreWindowsDialog(hwndMDIClient);
1356 /* User chose one of the windows listed in the "Windows" menu */
1357 childHwnd = MDI_GetChildByID(hwndMDIClient, id, ci);
1360 SendMessageW( hwndMDIClient, WM_MDIACTIVATE, (WPARAM)childHwnd, 0 );
1366 SendMessageW(hwndMDIClient, message, wParam, lParam);
1370 MDI_UpdateFrameText( hwnd, hwndMDIClient, FALSE, (LPWSTR)lParam );
1371 return 1; /* success. FIXME: check text length */
1374 SetFocus(hwndMDIClient);
1378 MoveWindow(hwndMDIClient, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
1383 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1385 if (!IsIconic(hwnd) && ci->hwndActiveChild && !IsZoomed(ci->hwndActiveChild))
1387 /* control menu is between the frame system menu and
1388 * the first entry of menu bar */
1389 WND *wndPtr = WIN_GetPtr(hwnd);
1391 if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1392 (wParam == VK_RIGHT && GetSubMenu(wndPtr->hSysMenu, 0) == next_menu->hmenuIn) )
1394 WIN_ReleasePtr(wndPtr);
1395 wndPtr = WIN_GetPtr(ci->hwndActiveChild);
1396 next_menu->hmenuNext = GetSubMenu(wndPtr->hSysMenu, 0);
1397 next_menu->hwndNext = ci->hwndActiveChild;
1399 WIN_ReleasePtr(wndPtr);
1406 return DefWindowProcW( hwnd, message, wParam, lParam );
1409 /***********************************************************************
1410 * DefMDIChildProcA (USER32.@)
1412 LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1413 WPARAM wParam, LPARAM lParam )
1415 HWND client = GetParent(hwnd);
1416 MDICLIENTINFO *ci = get_client_info( client );
1418 TRACE("%p %04x (%s) %08x %08lx\n", hwnd, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1420 hwnd = WIN_GetFullHandle( hwnd );
1421 if (!ci) return DefWindowProcA( hwnd, message, wParam, lParam );
1426 DefWindowProcA(hwnd, message, wParam, lParam);
1427 if( ci->hwndChildMaximized == hwnd )
1428 MDI_UpdateFrameText( GetParent(client), client, TRUE, NULL );
1429 return 1; /* success. FIXME: check text length */
1431 case WM_GETMINMAXINFO:
1435 case WM_CHILDACTIVATE:
1443 return DefMDIChildProcW( hwnd, message, wParam, lParam );
1445 return DefWindowProcA(hwnd, message, wParam, lParam);
1449 /***********************************************************************
1450 * DefMDIChildProcW (USER32.@)
1452 LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1453 WPARAM wParam, LPARAM lParam )
1455 HWND client = GetParent(hwnd);
1456 MDICLIENTINFO *ci = get_client_info( client );
1458 TRACE("%p %04x (%s) %08x %08lx\n", hwnd, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1460 hwnd = WIN_GetFullHandle( hwnd );
1461 if (!ci) return DefWindowProcW( hwnd, message, wParam, lParam );
1466 DefWindowProcW(hwnd, message, wParam, lParam);
1467 if( ci->hwndChildMaximized == hwnd )
1468 MDI_UpdateFrameText( GetParent(client), client, TRUE, NULL );
1469 return 1; /* success. FIXME: check text length */
1471 case WM_GETMINMAXINFO:
1472 MDI_ChildGetMinMaxInfo( client, hwnd, (MINMAXINFO *)lParam );
1476 return 0x00010000; /* MDI children don't have menu bars */
1479 SendMessageW( client, WM_MDIDESTROY, (WPARAM)hwnd, 0 );
1482 case WM_CHILDACTIVATE:
1483 MDI_ChildActivate( client, hwnd );
1490 if( ci->hwndActiveChild == hwnd && IsZoomed(ci->hwndActiveChild))
1497 if (ci->hwndChildMaximized == hwnd)
1498 return SendMessageW( GetParent(client), message, wParam, lParam);
1501 SendMessageW( client, WM_MDINEXT, 0, 0);
1504 SendMessageW( client, WM_MDINEXT, 0, 1);
1511 if (IsZoomed(ci->hwndActiveChild)) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1512 else MDI_PostUpdate(client, ci, SB_BOTH+1);
1516 TRACE("current active %p, maximized %p\n", ci->hwndActiveChild, ci->hwndChildMaximized);
1518 if( ci->hwndChildMaximized == hwnd && wParam != SIZE_MAXIMIZED )
1522 frame = GetParent(client);
1523 MDI_RestoreFrameMenu( frame, hwnd );
1524 MDI_UpdateFrameText( frame, client, FALSE, NULL );
1526 ci->hwndChildMaximized = 0;
1528 MDI_RefreshMenu(ci);
1529 MDI_PostUpdate(client, ci, SB_BOTH+1);
1532 if( wParam == SIZE_MAXIMIZED )
1534 HWND frame, hMaxChild = ci->hwndChildMaximized;
1536 if( hMaxChild == hwnd ) break;
1539 SendMessageW( hMaxChild, WM_SETREDRAW, FALSE, 0 );
1540 MDI_RestoreFrameMenu( GetParent(client), hMaxChild );
1541 ShowWindow( hMaxChild, SW_SHOWNOACTIVATE );
1542 SendMessageW( hMaxChild, WM_SETREDRAW, TRUE, 0 );
1545 TRACE("maximizing child %p\n", hwnd );
1547 /* keep track of the maximized window. */
1548 ci->hwndChildMaximized = hwnd; /* !!! */
1550 frame = GetParent(client);
1551 MDI_AugmentFrameMenu( frame, hwnd );
1552 MDI_UpdateFrameText( frame, client, TRUE, NULL );
1554 MDI_RefreshMenu(ci);
1555 MDI_PostUpdate(client, ci, SB_BOTH+1);
1561 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1562 HWND parent = GetParent(client);
1564 if( wParam == VK_LEFT ) /* switch to frame system menu */
1566 WND *wndPtr = WIN_GetPtr( parent );
1567 next_menu->hmenuNext = GetSubMenu( wndPtr->hSysMenu, 0 );
1568 WIN_ReleasePtr( wndPtr );
1570 if( wParam == VK_RIGHT ) /* to frame menu bar */
1572 next_menu->hmenuNext = GetMenu(parent);
1574 next_menu->hwndNext = parent;
1581 SendMessageW( hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (DWORD)VK_SPACE);
1587 /* Remove itself from the Window menu */
1588 MDI_RefreshMenu(ci);
1591 return DefWindowProcW(hwnd, message, wParam, lParam);
1594 /**********************************************************************
1595 * CreateMDIWindowA (USER32.@) Creates a MDI child
1598 * Success: Handle to created window
1601 HWND WINAPI CreateMDIWindowA(
1602 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1603 LPCSTR lpWindowName, /* [in] Pointer to window name */
1604 DWORD dwStyle, /* [in] Window style */
1605 INT X, /* [in] Horizontal position of window */
1606 INT Y, /* [in] Vertical position of window */
1607 INT nWidth, /* [in] Width of window */
1608 INT nHeight, /* [in] Height of window */
1609 HWND hWndParent, /* [in] Handle to parent window */
1610 HINSTANCE hInstance, /* [in] Handle to application instance */
1611 LPARAM lParam) /* [in] Application-defined value */
1613 TRACE("(%s,%s,%08x,%d,%d,%d,%d,%p,%p,%08lx)\n",
1614 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1615 nWidth,nHeight,hWndParent,hInstance,lParam);
1617 return CreateWindowExA(WS_EX_MDICHILD, lpClassName, lpWindowName,
1618 dwStyle, X, Y, nWidth, nHeight, hWndParent,
1619 0, hInstance, (LPVOID)lParam);
1622 /***********************************************************************
1623 * CreateMDIWindowW (USER32.@) Creates a MDI child
1626 * Success: Handle to created window
1629 HWND WINAPI CreateMDIWindowW(
1630 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1631 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1632 DWORD dwStyle, /* [in] Window style */
1633 INT X, /* [in] Horizontal position of window */
1634 INT Y, /* [in] Vertical position of window */
1635 INT nWidth, /* [in] Width of window */
1636 INT nHeight, /* [in] Height of window */
1637 HWND hWndParent, /* [in] Handle to parent window */
1638 HINSTANCE hInstance, /* [in] Handle to application instance */
1639 LPARAM lParam) /* [in] Application-defined value */
1641 TRACE("(%s,%s,%08x,%d,%d,%d,%d,%p,%p,%08lx)\n",
1642 debugstr_w(lpClassName), debugstr_w(lpWindowName), dwStyle, X, Y,
1643 nWidth, nHeight, hWndParent, hInstance, lParam);
1645 return CreateWindowExW(WS_EX_MDICHILD, lpClassName, lpWindowName,
1646 dwStyle, X, Y, nWidth, nHeight, hWndParent,
1647 0, hInstance, (LPVOID)lParam);
1650 /**********************************************************************
1651 * TranslateMDISysAccel (USER32.@)
1653 BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1655 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1657 MDICLIENTINFO *ci = get_client_info( hwndClient );
1660 if (!ci || !IsWindowEnabled(ci->hwndActiveChild)) return 0;
1662 /* translate if the Ctrl key is down and Alt not. */
1664 if( (GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
1666 switch( msg->wParam )
1670 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 ) ? SC_NEXTWINDOW : SC_PREVWINDOW;
1674 if (is_close_enabled(ci->hwndActiveChild, 0))
1683 TRACE("wParam = %04x\n", wParam);
1684 SendMessageW(ci->hwndActiveChild, WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
1688 return 0; /* failure */
1691 /***********************************************************************
1692 * CalcChildScroll (USER32.@)
1694 void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
1697 RECT childRect, clientRect;
1700 GetClientRect( hwnd, &clientRect );
1701 SetRectEmpty( &childRect );
1703 if ((list = WIN_ListChildren( hwnd )))
1706 for (i = 0; list[i]; i++)
1708 DWORD style = GetWindowLongW( list[i], GWL_STYLE );
1709 if (style & WS_MAXIMIZE)
1711 HeapFree( GetProcessHeap(), 0, list );
1712 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1715 if (style & WS_VISIBLE)
1718 GetWindowRect( list[i], &rect );
1719 UnionRect( &childRect, &rect, &childRect );
1722 HeapFree( GetProcessHeap(), 0, list );
1724 MapWindowPoints( 0, hwnd, (POINT *)&childRect, 2 );
1725 UnionRect( &childRect, &clientRect, &childRect );
1727 /* set common info values */
1728 info.cbSize = sizeof(info);
1729 info.fMask = SIF_POS | SIF_RANGE;
1731 /* set the specific */
1736 info.nMin = childRect.left;
1737 info.nMax = childRect.right - clientRect.right;
1738 info.nPos = clientRect.left - childRect.left;
1739 SetScrollInfo(hwnd, SB_HORZ, &info, TRUE);
1740 if (scroll == SB_HORZ) break;
1743 info.nMin = childRect.top;
1744 info.nMax = childRect.bottom - clientRect.bottom;
1745 info.nPos = clientRect.top - childRect.top;
1746 SetScrollInfo(hwnd, SB_VERT, &info, TRUE);
1752 /***********************************************************************
1753 * ScrollChildren (USER32.@)
1755 void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
1759 INT curPos, length, minPos, maxPos, shift;
1762 GetClientRect( hWnd, &rect );
1767 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
1768 curPos = GetScrollPos(hWnd,SB_HORZ);
1769 length = (rect.right - rect.left) / 2;
1770 shift = GetSystemMetrics(SM_CYHSCROLL);
1773 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
1774 curPos = GetScrollPos(hWnd,SB_VERT);
1775 length = (rect.bottom - rect.top) / 2;
1776 shift = GetSystemMetrics(SM_CXVSCROLL);
1785 newPos = curPos - shift;
1788 newPos = curPos + shift;
1791 newPos = curPos - length;
1794 newPos = curPos + length;
1797 case SB_THUMBPOSITION:
1798 newPos = LOWORD(lParam);
1811 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
1815 if( newPos > maxPos )
1818 if( newPos < minPos )
1821 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
1823 if( uMsg == WM_VSCROLL )
1824 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
1825 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
1827 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
1828 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
1832 /******************************************************************************
1833 * CascadeWindows (USER32.@) Cascades MDI child windows
1836 * Success: Number of cascaded windows.
1840 CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
1841 UINT cKids, const HWND *lpKids)
1843 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
1848 /******************************************************************************
1849 * TileWindows (USER32.@) Tiles MDI child windows
1852 * Success: Number of tiled windows.
1856 TileWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
1857 UINT cKids, const HWND *lpKids)
1859 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
1863 /************************************************************************
1864 * "More Windows..." functionality
1867 /* MDI_MoreWindowsDlgProc
1869 * This function will process the messages sent to the "More Windows..."
1871 * Return values: 0 = cancel pressed
1872 * HWND = ok pressed or double-click in the list...
1876 static INT_PTR WINAPI MDI_MoreWindowsDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
1885 MDICLIENTINFO *ci = get_client_info( (HWND)lParam );
1886 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
1888 for (i = 0; i < ci->nActiveChildren; i++)
1890 WCHAR buffer[MDI_MAXTITLELENGTH];
1892 if (!InternalGetWindowText( ci->child[i], buffer, sizeof(buffer)/sizeof(WCHAR) ))
1894 SendMessageW(hListBox, LB_ADDSTRING, 0, (LPARAM)buffer );
1895 SendMessageW(hListBox, LB_SETITEMDATA, i, (LPARAM)ci->child[i] );
1896 length = strlenW(buffer); /* FIXME: should use GetTextExtentPoint */
1897 if (length > widest)
1900 /* Make sure the horizontal scrollbar scrolls ok */
1901 SendMessageW(hListBox, LB_SETHORIZONTALEXTENT, widest * 6, 0);
1903 /* Set the current selection */
1904 SendMessageW(hListBox, LB_SETCURSEL, MDI_MOREWINDOWSLIMIT, 0);
1909 switch (LOWORD(wParam))
1912 if (HIWORD(wParam) != LBN_DBLCLK) break;
1916 /* windows are sorted by menu ID, so we must return the
1917 * window associated to the given id
1919 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
1920 UINT index = SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
1921 LRESULT res = SendMessageW(hListBox, LB_GETITEMDATA, index, 0);
1922 EndDialog(hDlg, res);
1936 * MDI_MoreWindowsDialog
1938 * Prompts the user with a listbox containing the opened
1939 * documents. The user can then choose a windows and click
1940 * on OK to set the current window to the one selected, or
1941 * CANCEL to cancel. The function returns a handle to the
1945 static HWND MDI_MoreWindowsDialog(HWND hwnd)
1951 hRes = FindResourceA(user32_module, "MDI_MOREWINDOWS", (LPSTR)RT_DIALOG);
1956 hDlgTmpl = LoadResource(user32_module, hRes );
1961 template = LockResource( hDlgTmpl );
1966 return (HWND) DialogBoxIndirectParamA(user32_module,
1967 (const DLGTEMPLATE*) template,
1968 hwnd, MDI_MoreWindowsDlgProc, (LPARAM) hwnd);