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 (ci->hwndChildMaximized)
324 MDI_RestoreFrameMenu( hwndFrame, ci->hwndChildMaximized );
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 (ci->hwndChildMaximized && (GetWindowLongW(ci->hwndChildMaximized, GWL_STYLE) & WS_VISIBLE))
359 MDI_AugmentFrameMenu( hwndFrame, ci->hwndChildMaximized );
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( ci->hwndChildMaximized )
373 MDI_AugmentFrameMenu( hwndFrame, ci->hwndChildMaximized );
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 (ci->hwndChildMaximized)
689 SendMessageW(client, WM_MDIRESTORE, (WPARAM)ci->hwndChildMaximized, 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 (ci->hwndChildMaximized)
742 SendMessageW(client, WM_MDIRESTORE, (WPARAM)ci->hwndChildMaximized, 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 (ci->hwndChildMaximized && (GetWindowLongW(ci->hwndChildMaximized, GWL_STYLE) & WS_VISIBLE))
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);
1118 return (LRESULT)child;
1123 return MDIDestroyChild( hwnd, ci, WIN_GetFullHandle( (HWND)wParam ), TRUE );
1125 case WM_MDIGETACTIVE:
1126 if (lParam) *(BOOL *)lParam = IsZoomed(ci->hwndActiveChild);
1127 return (LRESULT)ci->hwndActiveChild;
1129 case WM_MDIICONARRANGE:
1130 ci->mdiFlags |= MDIF_NEEDUPDATE;
1131 ArrangeIconicWindows( hwnd );
1132 ci->sbRecalc = SB_BOTH+1;
1133 SendMessageW( hwnd, WM_MDICALCCHILDSCROLL, 0, 0 );
1136 case WM_MDIMAXIMIZE:
1137 ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1140 case WM_MDINEXT: /* lParam != 0 means previous window */
1142 HWND next = MDI_GetWindow( ci, WIN_GetFullHandle( (HWND)wParam ), !lParam, 0 );
1143 MDI_SwitchActiveChild( ci, next, TRUE );
1148 ShowWindow( (HWND)wParam, SW_SHOWNORMAL );
1152 return MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1154 case WM_MDIREFRESHMENU:
1155 return MDI_RefreshMenu( ci );
1158 ci->mdiFlags |= MDIF_NEEDUPDATE;
1159 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1160 MDITile( hwnd, ci, wParam );
1161 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1166 ci->mdiFlags |= MDIF_NEEDUPDATE;
1167 ScrollChildren( hwnd, message, wParam, lParam );
1168 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1172 if (ci->hwndActiveChild && !IsIconic( ci->hwndActiveChild ))
1173 SetFocus( ci->hwndActiveChild );
1177 if( ci->hwndActiveChild )
1178 SendMessageW(ci->hwndActiveChild, message, wParam, lParam);
1181 case WM_PARENTNOTIFY:
1182 switch (LOWORD(wParam))
1185 if (GetWindowLongW((HWND)lParam, GWL_EXSTYLE) & WS_EX_MDICHILD)
1187 ci->nTotalCreated++;
1188 ci->nActiveChildren++;
1191 ci->child = HeapAlloc(GetProcessHeap(), 0, sizeof(HWND));
1193 ci->child = HeapReAlloc(GetProcessHeap(), 0, ci->child, sizeof(HWND) * ci->nActiveChildren);
1195 TRACE("Adding MDI child %p, # of children %d\n",
1196 (HWND)lParam, ci->nActiveChildren);
1198 ci->child[ci->nActiveChildren - 1] = (HWND)lParam;
1202 case WM_LBUTTONDOWN:
1206 pt.x = (short)LOWORD(lParam);
1207 pt.y = (short)HIWORD(lParam);
1208 child = ChildWindowFromPoint(hwnd, pt);
1210 TRACE("notification from %p (%i,%i)\n",child,pt.x,pt.y);
1212 if( child && child != hwnd && child != ci->hwndActiveChild )
1213 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1218 return MDIDestroyChild( hwnd, ci, WIN_GetFullHandle( (HWND)lParam ), FALSE );
1223 if( IsWindow(ci->hwndActiveChild) && IsZoomed(ci->hwndActiveChild) &&
1224 (GetWindowLongW(ci->hwndActiveChild, GWL_STYLE) & WS_VISIBLE) )
1230 rect.right = LOWORD(lParam);
1231 rect.bottom = HIWORD(lParam);
1233 AdjustWindowRectEx(&rect, GetWindowLongA(ci->hwndActiveChild, GWL_STYLE),
1234 0, GetWindowLongA(ci->hwndActiveChild, GWL_EXSTYLE) );
1235 MoveWindow(ci->hwndActiveChild, rect.left, rect.top,
1236 rect.right - rect.left, rect.bottom - rect.top, 1);
1239 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1243 case WM_MDICALCCHILDSCROLL:
1244 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1246 CalcChildScroll(hwnd, ci->sbRecalc-1);
1248 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1252 return unicode ? DefWindowProcW( hwnd, message, wParam, lParam ) :
1253 DefWindowProcA( hwnd, message, wParam, lParam );
1256 /***********************************************************************
1259 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1261 if (!IsWindow(hwnd)) return 0;
1262 return MDIClientWndProc_common( hwnd, message, wParam, lParam, FALSE );
1265 /***********************************************************************
1268 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1270 if (!IsWindow(hwnd)) return 0;
1271 return MDIClientWndProc_common( hwnd, message, wParam, lParam, TRUE );
1274 /***********************************************************************
1275 * DefFrameProcA (USER32.@)
1277 LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1278 UINT message, WPARAM wParam, LPARAM lParam)
1286 DWORD len = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0 );
1287 LPWSTR text = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1288 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, text, len );
1289 MDI_UpdateFrameText( hwnd, hwndMDIClient, FALSE, text );
1290 HeapFree( GetProcessHeap(), 0, text );
1292 return 1; /* success. FIXME: check text length */
1299 return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1302 return DefWindowProcA(hwnd, message, wParam, lParam);
1306 /***********************************************************************
1307 * DefFrameProcW (USER32.@)
1309 LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1310 UINT message, WPARAM wParam, LPARAM lParam)
1312 MDICLIENTINFO *ci = get_client_info( hwndMDIClient );
1314 TRACE("%p %p %04x (%s) %08x %08lx\n", hwnd, hwndMDIClient, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1322 WORD id = LOWORD(wParam);
1323 /* check for possible syscommands for maximized MDI child */
1324 if (id < ci->idFirstChild || id >= ci->idFirstChild + ci->nActiveChildren)
1326 if( (id - 0xf000) & 0xf00f ) break;
1327 if( !ci->hwndChildMaximized ) break;
1331 if (!is_close_enabled(ci->hwndActiveChild, 0)) break;
1339 return SendMessageW( ci->hwndChildMaximized, WM_SYSCOMMAND,
1346 if (id - ci->idFirstChild == MDI_MOREWINDOWSLIMIT)
1347 /* User chose "More Windows..." */
1348 childHwnd = MDI_MoreWindowsDialog(hwndMDIClient);
1350 /* User chose one of the windows listed in the "Windows" menu */
1351 childHwnd = MDI_GetChildByID(hwndMDIClient, id, ci);
1354 SendMessageW( hwndMDIClient, WM_MDIACTIVATE, (WPARAM)childHwnd, 0 );
1360 SendMessageW(hwndMDIClient, message, wParam, lParam);
1364 MDI_UpdateFrameText( hwnd, hwndMDIClient, FALSE, (LPWSTR)lParam );
1365 return 1; /* success. FIXME: check text length */
1368 SetFocus(hwndMDIClient);
1372 MoveWindow(hwndMDIClient, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
1377 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1379 if (!IsIconic(hwnd) && ci->hwndActiveChild && !IsZoomed(ci->hwndActiveChild))
1381 /* control menu is between the frame system menu and
1382 * the first entry of menu bar */
1383 WND *wndPtr = WIN_GetPtr(hwnd);
1385 if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1386 (wParam == VK_RIGHT && GetSubMenu(wndPtr->hSysMenu, 0) == next_menu->hmenuIn) )
1388 WIN_ReleasePtr(wndPtr);
1389 wndPtr = WIN_GetPtr(ci->hwndActiveChild);
1390 next_menu->hmenuNext = GetSubMenu(wndPtr->hSysMenu, 0);
1391 next_menu->hwndNext = ci->hwndActiveChild;
1393 WIN_ReleasePtr(wndPtr);
1400 return DefWindowProcW( hwnd, message, wParam, lParam );
1403 /***********************************************************************
1404 * DefMDIChildProcA (USER32.@)
1406 LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1407 WPARAM wParam, LPARAM lParam )
1409 HWND client = GetParent(hwnd);
1410 MDICLIENTINFO *ci = get_client_info( client );
1412 TRACE("%p %04x (%s) %08x %08lx\n", hwnd, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1414 hwnd = WIN_GetFullHandle( hwnd );
1415 if (!ci) return DefWindowProcA( hwnd, message, wParam, lParam );
1420 DefWindowProcA(hwnd, message, wParam, lParam);
1421 if( ci->hwndChildMaximized == hwnd )
1422 MDI_UpdateFrameText( GetParent(client), client, TRUE, NULL );
1423 return 1; /* success. FIXME: check text length */
1425 case WM_GETMINMAXINFO:
1429 case WM_CHILDACTIVATE:
1437 return DefMDIChildProcW( hwnd, message, wParam, lParam );
1439 return DefWindowProcA(hwnd, message, wParam, lParam);
1443 /***********************************************************************
1444 * DefMDIChildProcW (USER32.@)
1446 LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1447 WPARAM wParam, LPARAM lParam )
1449 HWND client = GetParent(hwnd);
1450 MDICLIENTINFO *ci = get_client_info( client );
1452 TRACE("%p %04x (%s) %08x %08lx\n", hwnd, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1454 hwnd = WIN_GetFullHandle( hwnd );
1455 if (!ci) return DefWindowProcW( hwnd, message, wParam, lParam );
1460 DefWindowProcW(hwnd, message, wParam, lParam);
1461 if( ci->hwndChildMaximized == hwnd )
1462 MDI_UpdateFrameText( GetParent(client), client, TRUE, NULL );
1463 return 1; /* success. FIXME: check text length */
1465 case WM_GETMINMAXINFO:
1466 MDI_ChildGetMinMaxInfo( client, hwnd, (MINMAXINFO *)lParam );
1470 return 0x00010000; /* MDI children don't have menu bars */
1473 SendMessageW( client, WM_MDIDESTROY, (WPARAM)hwnd, 0 );
1476 case WM_CHILDACTIVATE:
1477 MDI_ChildActivate( client, hwnd );
1484 if( ci->hwndChildMaximized == hwnd )
1491 if (ci->hwndChildMaximized == hwnd)
1492 return SendMessageW( GetParent(client), message, wParam, lParam);
1495 SendMessageW( client, WM_MDINEXT, 0, 0);
1498 SendMessageW( client, WM_MDINEXT, 0, 1);
1505 if (ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1506 else MDI_PostUpdate(client, ci, SB_BOTH+1);
1511 TRACE("current active %p, maximized %p\n", ci->hwndActiveChild, ci->hwndChildMaximized);
1513 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1517 ci->hwndChildMaximized = 0;
1519 frame = GetParent(client);
1520 MDI_RestoreFrameMenu( frame, hwnd );
1521 MDI_UpdateFrameText( frame, client, FALSE, NULL );
1524 if( wParam == SIZE_MAXIMIZED )
1526 HWND frame, hMaxChild = ci->hwndChildMaximized;
1528 if( hMaxChild == hwnd ) break;
1532 SendMessageW( hMaxChild, WM_SETREDRAW, FALSE, 0 );
1534 MDI_RestoreFrameMenu( GetParent(client), hMaxChild );
1535 ShowWindow( hMaxChild, SW_SHOWNOACTIVATE );
1537 SendMessageW( hMaxChild, WM_SETREDRAW, TRUE, 0 );
1540 TRACE("maximizing child %p\n", hwnd );
1542 /* keep track of the maximized window. */
1543 ci->hwndChildMaximized = hwnd; /* !!! */
1545 frame = GetParent(client);
1546 MDI_AugmentFrameMenu( frame, hwnd );
1547 MDI_UpdateFrameText( frame, client, TRUE, NULL );
1550 if( wParam == SIZE_MINIMIZED )
1552 HWND switchTo = MDI_GetWindow( ci, hwnd, TRUE, WS_MINIMIZE );
1555 SendMessageW( switchTo, WM_CHILDACTIVATE, 0, 0 );
1558 MDI_PostUpdate(client, ci, SB_BOTH+1);
1563 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1564 HWND parent = GetParent(client);
1566 if( wParam == VK_LEFT ) /* switch to frame system menu */
1568 WND *wndPtr = WIN_GetPtr( parent );
1569 next_menu->hmenuNext = GetSubMenu( wndPtr->hSysMenu, 0 );
1570 WIN_ReleasePtr( wndPtr );
1572 if( wParam == VK_RIGHT ) /* to frame menu bar */
1574 next_menu->hmenuNext = GetMenu(parent);
1576 next_menu->hwndNext = parent;
1583 SendMessageW( hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (DWORD)VK_SPACE);
1589 /* Remove itself from the Window menu */
1590 MDI_RefreshMenu(ci);
1593 return DefWindowProcW(hwnd, message, wParam, lParam);
1596 /**********************************************************************
1597 * CreateMDIWindowA (USER32.@) Creates a MDI child
1600 * Success: Handle to created window
1603 HWND WINAPI CreateMDIWindowA(
1604 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1605 LPCSTR lpWindowName, /* [in] Pointer to window name */
1606 DWORD dwStyle, /* [in] Window style */
1607 INT X, /* [in] Horizontal position of window */
1608 INT Y, /* [in] Vertical position of window */
1609 INT nWidth, /* [in] Width of window */
1610 INT nHeight, /* [in] Height of window */
1611 HWND hWndParent, /* [in] Handle to parent window */
1612 HINSTANCE hInstance, /* [in] Handle to application instance */
1613 LPARAM lParam) /* [in] Application-defined value */
1615 TRACE("(%s,%s,%08x,%d,%d,%d,%d,%p,%p,%08lx)\n",
1616 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1617 nWidth,nHeight,hWndParent,hInstance,lParam);
1619 return CreateWindowExA(WS_EX_MDICHILD, lpClassName, lpWindowName,
1620 dwStyle, X, Y, nWidth, nHeight, hWndParent,
1621 0, hInstance, (LPVOID)lParam);
1624 /***********************************************************************
1625 * CreateMDIWindowW (USER32.@) Creates a MDI child
1628 * Success: Handle to created window
1631 HWND WINAPI CreateMDIWindowW(
1632 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1633 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1634 DWORD dwStyle, /* [in] Window style */
1635 INT X, /* [in] Horizontal position of window */
1636 INT Y, /* [in] Vertical position of window */
1637 INT nWidth, /* [in] Width of window */
1638 INT nHeight, /* [in] Height of window */
1639 HWND hWndParent, /* [in] Handle to parent window */
1640 HINSTANCE hInstance, /* [in] Handle to application instance */
1641 LPARAM lParam) /* [in] Application-defined value */
1643 TRACE("(%s,%s,%08x,%d,%d,%d,%d,%p,%p,%08lx)\n",
1644 debugstr_w(lpClassName), debugstr_w(lpWindowName), dwStyle, X, Y,
1645 nWidth, nHeight, hWndParent, hInstance, lParam);
1647 return CreateWindowExW(WS_EX_MDICHILD, lpClassName, lpWindowName,
1648 dwStyle, X, Y, nWidth, nHeight, hWndParent,
1649 0, hInstance, (LPVOID)lParam);
1652 /**********************************************************************
1653 * TranslateMDISysAccel (USER32.@)
1655 BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1657 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1659 MDICLIENTINFO *ci = get_client_info( hwndClient );
1662 if (!ci || !IsWindowEnabled(ci->hwndActiveChild)) return 0;
1664 /* translate if the Ctrl key is down and Alt not. */
1666 if( (GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
1668 switch( msg->wParam )
1672 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 ) ? SC_NEXTWINDOW : SC_PREVWINDOW;
1676 if (is_close_enabled(ci->hwndActiveChild, 0))
1685 TRACE("wParam = %04x\n", wParam);
1686 SendMessageW(ci->hwndActiveChild, WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
1690 return 0; /* failure */
1693 /***********************************************************************
1694 * CalcChildScroll (USER32.@)
1696 void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
1699 RECT childRect, clientRect;
1702 GetClientRect( hwnd, &clientRect );
1703 SetRectEmpty( &childRect );
1705 if ((list = WIN_ListChildren( hwnd )))
1708 for (i = 0; list[i]; i++)
1710 DWORD style = GetWindowLongW( list[i], GWL_STYLE );
1711 if (style & WS_MAXIMIZE)
1713 HeapFree( GetProcessHeap(), 0, list );
1714 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1717 if (style & WS_VISIBLE)
1720 GetWindowRect( list[i], &rect );
1721 UnionRect( &childRect, &rect, &childRect );
1724 HeapFree( GetProcessHeap(), 0, list );
1726 MapWindowPoints( 0, hwnd, (POINT *)&childRect, 2 );
1727 UnionRect( &childRect, &clientRect, &childRect );
1729 /* set common info values */
1730 info.cbSize = sizeof(info);
1731 info.fMask = SIF_POS | SIF_RANGE;
1733 /* set the specific */
1738 info.nMin = childRect.left;
1739 info.nMax = childRect.right - clientRect.right;
1740 info.nPos = clientRect.left - childRect.left;
1741 SetScrollInfo(hwnd, SB_HORZ, &info, TRUE);
1742 if (scroll == SB_HORZ) break;
1745 info.nMin = childRect.top;
1746 info.nMax = childRect.bottom - clientRect.bottom;
1747 info.nPos = clientRect.top - childRect.top;
1748 SetScrollInfo(hwnd, SB_VERT, &info, TRUE);
1754 /***********************************************************************
1755 * ScrollChildren (USER32.@)
1757 void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
1761 INT curPos, length, minPos, maxPos, shift;
1764 GetClientRect( hWnd, &rect );
1769 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
1770 curPos = GetScrollPos(hWnd,SB_HORZ);
1771 length = (rect.right - rect.left) / 2;
1772 shift = GetSystemMetrics(SM_CYHSCROLL);
1775 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
1776 curPos = GetScrollPos(hWnd,SB_VERT);
1777 length = (rect.bottom - rect.top) / 2;
1778 shift = GetSystemMetrics(SM_CXVSCROLL);
1787 newPos = curPos - shift;
1790 newPos = curPos + shift;
1793 newPos = curPos - length;
1796 newPos = curPos + length;
1799 case SB_THUMBPOSITION:
1800 newPos = LOWORD(lParam);
1813 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
1817 if( newPos > maxPos )
1820 if( newPos < minPos )
1823 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
1825 if( uMsg == WM_VSCROLL )
1826 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
1827 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
1829 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
1830 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
1834 /******************************************************************************
1835 * CascadeWindows (USER32.@) Cascades MDI child windows
1838 * Success: Number of cascaded windows.
1842 CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
1843 UINT cKids, const HWND *lpKids)
1845 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
1850 /******************************************************************************
1851 * TileWindows (USER32.@) Tiles MDI child windows
1854 * Success: Number of tiled windows.
1858 TileWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
1859 UINT cKids, const HWND *lpKids)
1861 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
1865 /************************************************************************
1866 * "More Windows..." functionality
1869 /* MDI_MoreWindowsDlgProc
1871 * This function will process the messages sent to the "More Windows..."
1873 * Return values: 0 = cancel pressed
1874 * HWND = ok pressed or double-click in the list...
1878 static INT_PTR WINAPI MDI_MoreWindowsDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
1887 MDICLIENTINFO *ci = get_client_info( (HWND)lParam );
1888 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
1890 for (i = 0; i < ci->nActiveChildren; i++)
1892 WCHAR buffer[MDI_MAXTITLELENGTH];
1894 if (!InternalGetWindowText( ci->child[i], buffer, sizeof(buffer)/sizeof(WCHAR) ))
1896 SendMessageW(hListBox, LB_ADDSTRING, 0, (LPARAM)buffer );
1897 SendMessageW(hListBox, LB_SETITEMDATA, i, (LPARAM)ci->child[i] );
1898 length = strlenW(buffer); /* FIXME: should use GetTextExtentPoint */
1899 if (length > widest)
1902 /* Make sure the horizontal scrollbar scrolls ok */
1903 SendMessageW(hListBox, LB_SETHORIZONTALEXTENT, widest * 6, 0);
1905 /* Set the current selection */
1906 SendMessageW(hListBox, LB_SETCURSEL, MDI_MOREWINDOWSLIMIT, 0);
1911 switch (LOWORD(wParam))
1914 if (HIWORD(wParam) != LBN_DBLCLK) break;
1918 /* windows are sorted by menu ID, so we must return the
1919 * window associated to the given id
1921 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
1922 UINT index = SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
1923 LRESULT res = SendMessageW(hListBox, LB_GETITEMDATA, index, 0);
1924 EndDialog(hDlg, res);
1938 * MDI_MoreWindowsDialog
1940 * Prompts the user with a listbox containing the opened
1941 * documents. The user can then choose a windows and click
1942 * on OK to set the current window to the one selected, or
1943 * CANCEL to cancel. The function returns a handle to the
1947 static HWND MDI_MoreWindowsDialog(HWND hwnd)
1953 hRes = FindResourceA(user32_module, "MDI_MOREWINDOWS", (LPSTR)RT_DIALOG);
1958 hDlgTmpl = LoadResource(user32_module, hRes );
1963 template = LockResource( hDlgTmpl );
1968 return (HWND) DialogBoxIndirectParamA(user32_module,
1969 (const DLGTEMPLATE*) template,
1970 hwnd, MDI_MoreWindowsDlgProc, (LPARAM) hwnd);