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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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.
94 #include "wine/winuser16.h"
95 #include "wine/unicode.h"
97 #include "nonclient.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 UINT nActiveChildren;
121 HWND hwndActiveChild;
122 HWND *child; /* array of tracked children */
129 UINT sbRecalc; /* SB_xxx flags for scrollbar fixup */
132 static HBITMAP hBmpClose = 0;
134 /* ----------------- declarations ----------------- */
135 static void MDI_UpdateFrameText( HWND, HWND, LPCWSTR);
136 static BOOL MDI_AugmentFrameMenu( HWND, HWND );
137 static BOOL MDI_RestoreFrameMenu( HWND, HWND );
138 static LONG MDI_ChildActivate( HWND, HWND );
139 static LRESULT MDI_RefreshMenu(MDICLIENTINFO *);
141 static HWND MDI_MoreWindowsDialog(HWND);
142 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
143 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
145 /* -------- Miscellaneous service functions ----------
149 static HWND MDI_GetChildByID(HWND hwnd, UINT id, MDICLIENTINFO *ci)
153 for (i = 0; ci->nActiveChildren; i++)
155 if (GetWindowLongW( ci->child[i], GWL_ID ) == id)
161 static void MDI_PostUpdate(HWND hwnd, MDICLIENTINFO* ci, WORD recalc)
163 if( !(ci->mdiFlags & MDIF_NEEDUPDATE) )
165 ci->mdiFlags |= MDIF_NEEDUPDATE;
166 PostMessageA( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
168 ci->sbRecalc = recalc;
172 /*********************************************************************
173 * MDIClient class descriptor
175 const struct builtin_class_descr MDICLIENT_builtin_class =
177 "MDIClient", /* name */
179 MDIClientWndProcA, /* procA */
180 MDIClientWndProcW, /* procW */
181 sizeof(MDICLIENTINFO), /* extra */
182 IDC_ARROW, /* cursor */
183 (HBRUSH)(COLOR_APPWORKSPACE+1) /* brush */
187 static MDICLIENTINFO *get_client_info( HWND client )
189 MDICLIENTINFO *ret = NULL;
190 WND *win = WIN_GetPtr( client );
193 if (win == WND_OTHER_PROCESS)
195 ERR( "client %p belongs to other process\n", client );
198 if (win->cbWndExtra < sizeof(MDICLIENTINFO)) WARN( "%p is not an MDI client\n", client );
199 else ret = (MDICLIENTINFO *)win->wExtra;
200 WIN_ReleasePtr( win );
205 /**********************************************************************
208 * returns "activateable" child different from the current or zero
210 static HWND MDI_GetWindow(MDICLIENTINFO *clientInfo, HWND hWnd, BOOL bNext,
217 dwStyleMask |= WS_DISABLED | WS_VISIBLE;
218 if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
220 if (!(list = WIN_ListChildren( GetParent(hWnd) ))) return 0;
222 /* start from next after hWnd */
223 while (list[i] && list[i] != hWnd) i++;
226 for ( ; list[i]; i++)
228 if (GetWindow( list[i], GW_OWNER )) continue;
229 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
231 if (bNext) goto found;
233 /* now restart from the beginning */
234 for (i = 0; list[i] && list[i] != hWnd; i++)
236 if (GetWindow( list[i], GW_OWNER )) continue;
237 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
239 if (bNext) goto found;
242 HeapFree( GetProcessHeap(), 0, list );
246 /**********************************************************************
247 * MDI_CalcDefaultChildPos
249 * It seems that the default height is about 2/3 of the client rect
251 void MDI_CalcDefaultChildPos( HWND hwndClient, INT total, LPPOINT lpPos, INT delta )
255 INT spacing = GetSystemMetrics(SM_CYCAPTION) +
256 GetSystemMetrics(SM_CYFRAME) - 1;
260 MDICLIENTINFO *ci = get_client_info(hwndClient);
261 total = ci ? ci->nTotalCreated : 0;
264 GetClientRect( hwndClient, &rect );
265 if( rect.bottom - rect.top - delta >= spacing )
266 rect.bottom -= delta;
268 nstagger = (rect.bottom - rect.top)/(3 * spacing);
269 lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
270 lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
271 lpPos[0].x = lpPos[0].y = spacing * (total%(nstagger+1));
274 /**********************************************************************
277 static LRESULT MDISetMenu( HWND hwnd, HMENU hmenuFrame,
281 HWND hwndFrame = GetParent(hwnd);
283 TRACE("%p %p %p\n", hwnd, hmenuFrame, hmenuWindow);
285 if (hmenuFrame && !IsMenu(hmenuFrame))
287 WARN("hmenuFrame is not a menu handle\n");
291 if (hmenuWindow && !IsMenu(hmenuWindow))
293 WARN("hmenuWindow is not a menu handle\n");
297 if (!(ci = get_client_info( hwnd ))) return 0;
301 if (hmenuFrame == ci->hFrameMenu) return (LRESULT)hmenuFrame;
303 if( IsZoomed(ci->hwndActiveChild) && hmenuFrame != ci->hFrameMenu )
304 MDI_RestoreFrameMenu( hwndFrame, ci->hwndActiveChild );
307 if( hmenuWindow && hmenuWindow != ci->hWindowMenu )
309 /* delete menu items from ci->hWindowMenu
310 * and add them to hmenuWindow */
311 /* Agent newsreader calls this function with ci->hWindowMenu == NULL */
312 if( ci->hWindowMenu && ci->nActiveChildren )
314 UINT nActiveChildren_old = ci->nActiveChildren;
316 /* Remove all items from old Window menu */
317 ci->nActiveChildren = 0;
320 ci->hWindowMenu = hmenuWindow;
322 /* Add items to the new Window menu */
323 ci->nActiveChildren = nActiveChildren_old;
327 ci->hWindowMenu = hmenuWindow;
332 SetMenu(hwndFrame, hmenuFrame);
333 if( hmenuFrame != ci->hFrameMenu )
335 HMENU oldFrameMenu = ci->hFrameMenu;
337 ci->hFrameMenu = hmenuFrame;
338 if( IsZoomed(ci->hwndActiveChild) )
339 MDI_AugmentFrameMenu( hwndFrame, ci->hwndActiveChild );
341 return (LRESULT)oldFrameMenu;
346 /* SetMenu() may already have been called, meaning that this window
347 * already has its menu. But they may have done a SetMenu() on
348 * an MDI window, and called MDISetMenu() after the fact, meaning
349 * that the "if" to this "else" wouldn't catch the need to
350 * augment the frame menu.
352 if( IsZoomed(ci->hwndActiveChild) )
353 MDI_AugmentFrameMenu( hwndFrame, ci->hwndActiveChild );
359 /**********************************************************************
362 static LRESULT MDI_RefreshMenu(MDICLIENTINFO *ci)
364 UINT i, count, visible, id;
365 WCHAR buf[MDI_MAXTITLELENGTH];
367 TRACE("children %u, window menu %p\n", ci->nActiveChildren, ci->hWindowMenu);
369 if (!ci->hWindowMenu)
372 if (!IsMenu(ci->hWindowMenu))
374 WARN("Window menu handle %p is no more valid\n", ci->hWindowMenu);
378 /* Windows finds the last separator in the menu, and if after it
379 * there is a menu item with MDI magic ID removes all existing
380 * menu items after it, and then adds visible MDI children.
382 count = GetMenuItemCount(ci->hWindowMenu);
383 for (i = 0; i < count; i++)
387 memset(&mii, 0, sizeof(mii));
388 mii.cbSize = sizeof(mii);
389 mii.fMask = MIIM_TYPE;
390 if (GetMenuItemInfoW(ci->hWindowMenu, i, TRUE, &mii))
392 if (mii.fType & MF_SEPARATOR)
394 /* Windows checks only ID of the menu item */
395 memset(&mii, 0, sizeof(mii));
396 mii.cbSize = sizeof(mii);
398 if (GetMenuItemInfoW(ci->hWindowMenu, i + 1, TRUE, &mii))
400 if (mii.wID == ci->idFirstChild)
402 TRACE("removing %u items including separator\n", count - i);
403 while (RemoveMenu(ci->hWindowMenu, i, MF_BYPOSITION))
414 for (i = 0; i < ci->nActiveChildren; i++)
416 if (GetWindowLongW(ci->child[i], GWL_STYLE) & WS_VISIBLE)
418 id = ci->idFirstChild + visible;
420 if (visible == MDI_MOREWINDOWSLIMIT)
422 LoadStringW(user32_module, IDS_MDI_MOREWINDOWS, buf, sizeof(buf)/sizeof(WCHAR));
423 AppendMenuW(ci->hWindowMenu, MF_STRING, id, buf);
428 /* Visio expects that separator has id 0 */
429 AppendMenuW(ci->hWindowMenu, MF_SEPARATOR, 0, NULL);
433 SetWindowLongW(ci->child[i], GWL_ID, id);
436 buf[1] = '0' + visible;
438 InternalGetWindowText(ci->child[i], buf + 3, sizeof(buf)/sizeof(WCHAR) - 3);
439 TRACE("Adding %p, id %u %s\n", ci->child[i], id, debugstr_w(buf));
440 AppendMenuW(ci->hWindowMenu, MF_STRING, id, buf);
442 if (ci->child[i] == ci->hwndActiveChild)
443 CheckMenuItem(ci->hWindowMenu, id, MF_CHECKED);
446 TRACE("MDI child %p is not visible, skipping\n", ci->child[i]);
449 return (LRESULT)ci->hFrameMenu;
453 /* ------------------ MDI child window functions ---------------------- */
455 /**********************************************************************
456 * MDI_ChildGetMinMaxInfo
458 * Note: The rule here is that client rect of the maximized MDI child
459 * is equal to the client rect of the MDI client window.
461 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
465 GetClientRect( client, &rect );
466 AdjustWindowRectEx( &rect, GetWindowLongW( hwnd, GWL_STYLE ),
467 0, GetWindowLongW( hwnd, GWL_EXSTYLE ));
469 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
470 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
472 lpMinMax->ptMaxPosition.x = rect.left;
473 lpMinMax->ptMaxPosition.y = rect.top;
475 TRACE("max rect (%ld,%ld - %ld, %ld)\n",
476 rect.left,rect.top,rect.right,rect.bottom);
479 /**********************************************************************
480 * MDI_SwitchActiveChild
482 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
485 static void MDI_SwitchActiveChild( MDICLIENTINFO *ci, HWND hwndTo )
489 hwndPrev = ci->hwndActiveChild;
491 TRACE("from %p, to %p\n", hwndPrev, hwndTo);
493 if ( hwndTo != hwndPrev )
495 BOOL was_zoomed = IsZoomed(hwndPrev);
499 /* restore old MDI child */
500 SendMessageW( hwndPrev, WM_SETREDRAW, FALSE, 0 );
501 ShowWindow( hwndPrev, SW_RESTORE );
502 SendMessageW( hwndPrev, WM_SETREDRAW, TRUE, 0 );
504 /* activate new MDI child */
505 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
506 /* maximize new MDI child */
507 ShowWindow( hwndTo, SW_MAXIMIZE );
509 /* activate new MDI child */
510 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
515 /**********************************************************************
518 static LRESULT MDIDestroyChild( HWND parent, MDICLIENTINFO *ci,
519 HWND child, BOOL flagDestroy )
523 TRACE("# of managed children %u\n", ci->nActiveChildren);
525 if( child == ci->hwndActiveChild )
527 HWND next = MDI_GetWindow(ci, child, TRUE, 0);
528 MDI_SwitchActiveChild(ci, next);
531 for (i = 0; i < ci->nActiveChildren; i++)
533 if (ci->child[i] == child)
535 HWND *new_child = HeapAlloc(GetProcessHeap(), 0, (ci->nActiveChildren - 1) * sizeof(HWND));
536 memcpy(new_child, ci->child, i * sizeof(HWND));
537 if (i + 1 < ci->nActiveChildren)
538 memcpy(new_child + i, ci->child + i + 1, (ci->nActiveChildren - i - 1) * sizeof(HWND));
539 HeapFree(GetProcessHeap(), 0, ci->child);
540 ci->child = new_child;
542 ci->nActiveChildren--;
549 MDI_PostUpdate(GetParent(child), ci, SB_BOTH+1);
550 DestroyWindow(child);
553 TRACE("child destroyed - %p\n", child);
558 /**********************************************************************
561 * Called in response to WM_CHILDACTIVATE
563 static LONG MDI_ChildActivate( HWND client, HWND child )
565 MDICLIENTINFO *clientInfo;
566 HWND prevActiveWnd, frame;
567 BOOL isActiveFrameWnd;
569 clientInfo = get_client_info( client );
571 if (clientInfo->hwndActiveChild == child) return 0;
573 TRACE("%p\n", child);
575 frame = GetParent(client);
576 isActiveFrameWnd = (GetActiveWindow() == frame);
577 prevActiveWnd = clientInfo->hwndActiveChild;
579 /* deactivate prev. active child */
582 SendMessageW( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
583 SendMessageW( prevActiveWnd, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child);
586 clientInfo->hwndActiveChild = child;
588 MDI_RefreshMenu(clientInfo);
590 if( isActiveFrameWnd )
592 SendMessageW( child, WM_NCACTIVATE, TRUE, 0L);
596 SendMessageW( child, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child );
600 /* -------------------- MDI client window functions ------------------- */
602 /**********************************************************************
603 * CreateMDIMenuBitmap
605 static HBITMAP CreateMDIMenuBitmap(void)
607 HDC hDCSrc = CreateCompatibleDC(0);
608 HDC hDCDest = CreateCompatibleDC(hDCSrc);
609 HBITMAP hbClose = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_OLD_CLOSE) );
611 HBITMAP hobjSrc, hobjDest;
613 hobjSrc = SelectObject(hDCSrc, hbClose);
614 hbCopy = CreateCompatibleBitmap(hDCSrc,GetSystemMetrics(SM_CXSIZE),GetSystemMetrics(SM_CYSIZE));
615 hobjDest = SelectObject(hDCDest, hbCopy);
617 BitBlt(hDCDest, 0, 0, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE),
618 hDCSrc, GetSystemMetrics(SM_CXSIZE), 0, SRCCOPY);
620 SelectObject(hDCSrc, hobjSrc);
621 DeleteObject(hbClose);
624 hobjSrc = SelectObject( hDCDest, GetStockObject(BLACK_PEN) );
626 MoveToEx( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, 0, NULL );
627 LineTo( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, GetSystemMetrics(SM_CYSIZE) - 1);
629 SelectObject(hDCDest, hobjSrc );
630 SelectObject(hDCDest, hobjDest);
636 /**********************************************************************
639 static LONG MDICascade( HWND client, MDICLIENTINFO *ci )
642 BOOL has_icons = FALSE;
645 if (IsZoomed(ci->hwndActiveChild))
646 SendMessageA(client, WM_MDIRESTORE, (WPARAM)ci->hwndActiveChild, 0);
648 if (ci->nActiveChildren == 0) return 0;
650 if (!(win_array = WIN_ListChildren( client ))) return 0;
652 /* remove all the windows we don't want */
653 for (i = total = 0; win_array[i]; i++)
655 if (!IsWindowVisible( win_array[i] )) continue;
656 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows */
657 if (IsIconic( win_array[i] ))
662 win_array[total++] = win_array[i];
664 win_array[total] = 0;
668 INT delta = 0, n = 0, i;
670 if (has_icons) delta = GetSystemMetrics(SM_CYICONSPACING) + GetSystemMetrics(SM_CYICON);
672 /* walk the list (backwards) and move windows */
673 for (i = total - 1; i >= 0; i--)
675 TRACE("move %p to (%ld,%ld) size [%ld,%ld]\n",
676 win_array[i], pos[0].x, pos[0].y, pos[1].x, pos[1].y);
678 MDI_CalcDefaultChildPos(client, n++, pos, delta);
679 SetWindowPos( win_array[i], 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
680 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
683 HeapFree( GetProcessHeap(), 0, win_array );
685 if (has_icons) ArrangeIconicWindows( client );
689 /**********************************************************************
692 static void MDITile( HWND client, MDICLIENTINFO *ci, WPARAM wParam )
696 BOOL has_icons = FALSE;
698 if (IsZoomed(ci->hwndActiveChild))
699 SendMessageA(client, WM_MDIRESTORE, (WPARAM)ci->hwndActiveChild, 0);
701 if (ci->nActiveChildren == 0) return;
703 if (!(win_array = WIN_ListChildren( client ))) return;
705 /* remove all the windows we don't want */
706 for (i = total = 0; win_array[i]; i++)
708 if (!IsWindowVisible( win_array[i] )) continue;
709 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows (icon titles) */
710 if (IsIconic( win_array[i] ))
715 if ((wParam & MDITILE_SKIPDISABLED) && !IsWindowEnabled( win_array[i] )) continue;
716 win_array[total++] = win_array[i];
718 win_array[total] = 0;
720 TRACE("%u windows to tile\n", total);
724 HWND *pWnd = win_array;
726 int x, y, xsize, ysize;
727 int rows, columns, r, c, i;
729 GetClientRect(client,&rect);
730 rows = (int) sqrt((double)total);
731 columns = total / rows;
733 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
736 rows = columns; /* exchange r and c */
742 y = rect.bottom - 2 * GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
743 rect.bottom = ( y - GetSystemMetrics(SM_CYICON) < rect.top )? rect.bottom: y;
746 ysize = rect.bottom / rows;
747 xsize = rect.right / columns;
749 for (x = i = 0, c = 1; c <= columns && *pWnd; c++)
754 ysize = rect.bottom / rows;
758 for (r = 1; r <= rows && *pWnd; r++, i++)
760 SetWindowPos(*pWnd, 0, x, y, xsize, ysize,
761 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
768 HeapFree( GetProcessHeap(), 0, win_array );
769 if (has_icons) ArrangeIconicWindows( client );
772 /* ----------------------- Frame window ---------------------------- */
775 /**********************************************************************
776 * MDI_AugmentFrameMenu
778 static BOOL MDI_AugmentFrameMenu( HWND frame, HWND hChild )
780 HMENU menu = GetMenu( frame );
782 HBITMAP hSysMenuBitmap = 0;
787 TRACE("frame %p,child %p\n",frame,hChild);
789 if( !menu ) return 0;
791 /* if the system buttons already exist do not add them again */
792 nItems = GetMenuItemCount(menu) - 1;
793 iId = GetMenuItemID(menu,nItems) ;
794 if (iId == SC_RESTORE || iId == SC_CLOSE)
797 /* create a copy of sysmenu popup and insert it into frame menu bar */
798 if (!(hSysPopup = GetSystemMenu(hChild, FALSE)))
801 AppendMenuA(menu,MF_HELP | MF_BITMAP,
802 SC_MINIMIZE, (LPSTR)(DWORD)HBMMENU_MBAR_MINIMIZE ) ;
803 AppendMenuA(menu,MF_HELP | MF_BITMAP,
804 SC_RESTORE, (LPSTR)(DWORD)HBMMENU_MBAR_RESTORE );
806 AppendMenuA(menu,MF_HELP | MF_BITMAP,
807 SC_CLOSE, (LPSTR)(DWORD)HBMMENU_MBAR_CLOSE );
809 /* The system menu is replaced by the child icon */
810 hIcon = (HICON)GetClassLongW(hChild, GCL_HICONSM);
812 hIcon = (HICON)GetClassLongW(hChild, GCL_HICON);
814 hIcon = LoadImageW(0, MAKEINTRESOURCEW(IDI_WINLOGO), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
818 HBITMAP hBitmap, hOldBitmap;
820 HDC hdc = GetDC(hChild);
825 cx = GetSystemMetrics(SM_CXSMICON);
826 cy = GetSystemMetrics(SM_CYSMICON);
827 hMemDC = CreateCompatibleDC(hdc);
828 hBitmap = CreateCompatibleBitmap(hdc, cx, cy);
829 hOldBitmap = SelectObject(hMemDC, hBitmap);
830 SetMapMode(hMemDC, MM_TEXT);
831 hBrush = CreateSolidBrush(GetSysColor(COLOR_MENU));
832 DrawIconEx(hMemDC, 0, 0, hIcon, cx, cy, 0, hBrush, DI_NORMAL);
833 SelectObject (hMemDC, hOldBitmap);
834 DeleteObject(hBrush);
836 ReleaseDC(hChild, hdc);
837 hSysMenuBitmap = hBitmap;
841 if( !InsertMenuA(menu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
842 (UINT_PTR)hSysPopup, (LPSTR)hSysMenuBitmap))
844 TRACE("not inserted\n");
845 DestroyMenu(hSysPopup);
849 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
850 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
851 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
852 SetMenuDefaultItem(hSysPopup, SC_CLOSE, FALSE);
860 /**********************************************************************
861 * MDI_RestoreFrameMenu
863 static BOOL MDI_RestoreFrameMenu( HWND frame, HWND hChild )
865 MENUITEMINFOW menuInfo;
866 HMENU menu = GetMenu( frame );
867 INT nItems = GetMenuItemCount(menu) - 1;
868 UINT iId = GetMenuItemID(menu,nItems) ;
870 TRACE("frame %p,child %p,nIt=%d,iId=%d\n",frame,hChild,nItems,iId);
872 /* if there is no system buttons then nothing to do */
873 if(!(iId == SC_RESTORE || iId == SC_CLOSE) )
877 * Remove the system menu, If that menu is the icon of the window
878 * as it is in win95, we have to delete the bitmap.
880 memset(&menuInfo, 0, sizeof(menuInfo));
881 menuInfo.cbSize = sizeof(menuInfo);
882 menuInfo.fMask = MIIM_DATA | MIIM_TYPE;
884 GetMenuItemInfoW(menu,
889 RemoveMenu(menu,0,MF_BYPOSITION);
891 if ( (menuInfo.fType & MFT_BITMAP) &&
892 (LOWORD(menuInfo.dwTypeData)!=0) &&
893 (LOWORD(menuInfo.dwTypeData)!=HBITMAP_16(hBmpClose)) )
895 DeleteObject(HBITMAP_32(LOWORD(menuInfo.dwTypeData)));
899 DeleteMenu(menu, SC_CLOSE, MF_BYCOMMAND);
901 DeleteMenu(menu, SC_RESTORE, MF_BYCOMMAND);
903 DeleteMenu(menu, SC_MINIMIZE, MF_BYCOMMAND);
911 /**********************************************************************
912 * MDI_UpdateFrameText
914 * used when child window is maximized/restored
916 * Note: lpTitle can be NULL
918 static void MDI_UpdateFrameText( HWND frame, HWND hClient, LPCWSTR lpTitle )
920 WCHAR lpBuffer[MDI_MAXTITLELENGTH+1];
921 MDICLIENTINFO *ci = get_client_info( hClient );
923 TRACE("frameText %s\n", debugstr_w(lpTitle));
927 if (!lpTitle && !ci->frameTitle) /* first time around, get title from the frame window */
929 GetWindowTextW( frame, lpBuffer, sizeof(lpBuffer)/sizeof(WCHAR) );
933 /* store new "default" title if lpTitle is not NULL */
936 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
937 if ((ci->frameTitle = HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle)+1)*sizeof(WCHAR))))
938 strcpyW( ci->frameTitle, lpTitle );
943 if (IsZoomed(ci->hwndActiveChild) && IsWindowVisible(ci->hwndActiveChild))
945 /* combine frame title and child title if possible */
947 static const WCHAR lpBracket[] = {' ','-',' ','[',0};
948 static const WCHAR lpBracket2[] = {']',0};
949 int i_frame_text_length = strlenW(ci->frameTitle);
951 lstrcpynW( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
953 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
955 strcatW( lpBuffer, lpBracket );
956 if (GetWindowTextW( ci->hwndActiveChild, lpBuffer + i_frame_text_length + 4,
957 MDI_MAXTITLELENGTH - i_frame_text_length - 5 ))
958 strcatW( lpBuffer, lpBracket2 );
960 lpBuffer[i_frame_text_length] = 0; /* remove bracket */
965 lstrcpynW(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH+1 );
971 DefWindowProcW( frame, WM_SETTEXT, 0, (LPARAM)lpBuffer );
975 /* ----------------------------- Interface ---------------------------- */
978 /**********************************************************************
979 * MDIClientWndProc_common
981 static LRESULT MDIClientWndProc_common( HWND hwnd, UINT message,
982 WPARAM wParam, LPARAM lParam, BOOL unicode )
986 TRACE("%p %04x (%s) %08x %08lx\n", hwnd, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
988 if (!(ci = get_client_info( hwnd ))) return 0;
994 /* Since we are using only cs->lpCreateParams, we can safely
995 * cast to LPCREATESTRUCTA here */
996 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
997 WND *wndPtr = WIN_GetPtr( hwnd );
999 wndPtr->flags |= WIN_ISMDICLIENT;
1001 /* Translation layer doesn't know what's in the cs->lpCreateParams
1002 * so we have to keep track of what environment we're in. */
1004 if( wndPtr->flags & WIN_ISWIN32 )
1006 LPCLIENTCREATESTRUCT ccs = cs->lpCreateParams;
1007 ci->hWindowMenu = ccs->hWindowMenu;
1008 ci->idFirstChild = ccs->idFirstChild;
1012 LPCLIENTCREATESTRUCT16 ccs = MapSL((SEGPTR)cs->lpCreateParams);
1013 ci->hWindowMenu = HMENU_32(ccs->hWindowMenu);
1014 ci->idFirstChild = ccs->idFirstChild;
1016 WIN_ReleasePtr( wndPtr );
1019 ci->nActiveChildren = 0;
1020 ci->nTotalCreated = 0;
1021 ci->frameTitle = NULL;
1023 ci->hFrameMenu = GetMenu(cs->hwndParent);
1025 if (!hBmpClose) hBmpClose = CreateMDIMenuBitmap();
1027 TRACE("Client created: hwnd %p, Window menu %p, idFirst = %u\n",
1028 hwnd, ci->hWindowMenu, ci->idFirstChild );
1034 if( IsZoomed(ci->hwndActiveChild) )
1035 MDI_RestoreFrameMenu(GetParent(hwnd), ci->hwndActiveChild);
1037 ci->nActiveChildren = 0;
1038 MDI_RefreshMenu(ci);
1040 if (ci->child) HeapFree( GetProcessHeap(), 0, ci->child );
1041 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1046 case WM_MDIACTIVATE:
1048 MDI_SwitchActiveChild( ci, (HWND)wParam );
1053 return MDICascade(hwnd, ci);
1060 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)lParam;
1061 return (LRESULT)CreateWindowExW(WS_EX_MDICHILD, csW->szClass,
1062 csW->szTitle, csW->style,
1063 csW->x, csW->y, csW->cx, csW->cy,
1064 hwnd, 0, csW->hOwner,
1065 (LPVOID)csW->lParam);
1069 MDICREATESTRUCTA *csA = (MDICREATESTRUCTA *)lParam;
1070 return (LRESULT)CreateWindowExA(WS_EX_MDICHILD, csA->szClass,
1071 csA->szTitle, csA->style,
1072 csA->x, csA->y, csA->cx, csA->cy,
1073 hwnd, 0, csA->hOwner,
1074 (LPVOID)csA->lParam);
1080 return MDIDestroyChild( hwnd, ci, WIN_GetFullHandle( (HWND)wParam ), TRUE );
1082 case WM_MDIGETACTIVE:
1083 if (lParam) *(BOOL *)lParam = IsZoomed(ci->hwndActiveChild);
1084 return (LRESULT)ci->hwndActiveChild;
1086 case WM_MDIICONARRANGE:
1087 ci->mdiFlags |= MDIF_NEEDUPDATE;
1088 ArrangeIconicWindows( hwnd );
1089 ci->sbRecalc = SB_BOTH+1;
1090 SendMessageW( hwnd, WM_MDICALCCHILDSCROLL, 0, 0 );
1093 case WM_MDIMAXIMIZE:
1094 ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1097 case WM_MDINEXT: /* lParam != 0 means previous window */
1099 HWND next = MDI_GetWindow( ci, WIN_GetFullHandle( (HWND)wParam ), !lParam, 0 );
1100 MDI_SwitchActiveChild( ci, next );
1105 SendMessageW( (HWND)wParam, WM_SYSCOMMAND, SC_RESTORE, 0);
1109 return MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1111 case WM_MDIREFRESHMENU:
1112 return MDI_RefreshMenu( ci );
1115 ci->mdiFlags |= MDIF_NEEDUPDATE;
1116 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1117 MDITile( hwnd, ci, wParam );
1118 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1123 ci->mdiFlags |= MDIF_NEEDUPDATE;
1124 ScrollChildren( hwnd, message, wParam, lParam );
1125 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1129 if (ci->hwndActiveChild && !IsIconic( ci->hwndActiveChild ))
1130 SetFocus( ci->hwndActiveChild );
1134 if( ci->hwndActiveChild )
1135 SendMessageW(ci->hwndActiveChild, message, wParam, lParam);
1138 case WM_PARENTNOTIFY:
1139 switch (LOWORD(wParam))
1142 if (GetWindowLongW((HWND)lParam, GWL_EXSTYLE) & WS_EX_MDICHILD)
1144 ci->nTotalCreated++;
1145 ci->nActiveChildren++;
1148 ci->child = HeapAlloc(GetProcessHeap(), 0, sizeof(HWND));
1150 ci->child = HeapReAlloc(GetProcessHeap(), 0, ci->child, sizeof(HWND) * ci->nActiveChildren);
1152 TRACE("Adding MDI child %p, # of children %d\n",
1153 (HWND)lParam, ci->nActiveChildren);
1155 ci->child[ci->nActiveChildren - 1] = (HWND)lParam;
1159 case WM_LBUTTONDOWN:
1163 pt.x = (short)LOWORD(lParam);
1164 pt.y = (short)HIWORD(lParam);
1165 child = ChildWindowFromPoint(hwnd, pt);
1167 TRACE("notification from %p (%li,%li)\n",child,pt.x,pt.y);
1169 if( child && child != hwnd && child != ci->hwndActiveChild )
1170 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1177 if( IsWindow(ci->hwndActiveChild) && IsZoomed(ci->hwndActiveChild) &&
1178 IsWindowVisible(ci->hwndActiveChild) )
1184 rect.right = LOWORD(lParam);
1185 rect.bottom = HIWORD(lParam);
1187 AdjustWindowRectEx(&rect, GetWindowLongA(ci->hwndActiveChild, GWL_STYLE),
1188 0, GetWindowLongA(ci->hwndActiveChild, GWL_EXSTYLE) );
1189 MoveWindow(ci->hwndActiveChild, rect.left, rect.top,
1190 rect.right - rect.left, rect.bottom - rect.top, 1);
1193 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1197 case WM_MDICALCCHILDSCROLL:
1198 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1200 CalcChildScroll(hwnd, ci->sbRecalc-1);
1202 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1206 return unicode ? DefWindowProcW( hwnd, message, wParam, lParam ) :
1207 DefWindowProcA( hwnd, message, wParam, lParam );
1210 /***********************************************************************
1213 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1215 if (!IsWindow(hwnd)) return 0;
1216 return MDIClientWndProc_common( hwnd, message, wParam, lParam, FALSE );
1219 /***********************************************************************
1222 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1224 if (!IsWindow(hwnd)) return 0;
1225 return MDIClientWndProc_common( hwnd, message, wParam, lParam, TRUE );
1228 /***********************************************************************
1229 * DefFrameProcA (USER32.@)
1231 LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1232 UINT message, WPARAM wParam, LPARAM lParam)
1240 DWORD len = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0 );
1241 LPWSTR text = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1242 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, text, len );
1243 MDI_UpdateFrameText( hwnd, hwndMDIClient, text );
1244 HeapFree( GetProcessHeap(), 0, text );
1246 return 1; /* success. FIXME: check text length */
1253 return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1256 return DefWindowProcA(hwnd, message, wParam, lParam);
1260 /***********************************************************************
1261 * DefFrameProcW (USER32.@)
1263 LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1264 UINT message, WPARAM wParam, LPARAM lParam)
1266 MDICLIENTINFO *ci = get_client_info( hwndMDIClient );
1268 TRACE("%p %p %04x (%s) %08x %08lx\n", hwnd, hwndMDIClient, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1276 WORD id = LOWORD(wParam);
1277 /* check for possible syscommands for maximized MDI child */
1278 if (id < ci->idFirstChild || id >= ci->idFirstChild + ci->nActiveChildren)
1280 if( (id - 0xf000) & 0xf00f ) break;
1281 if( !IsZoomed(ci->hwndActiveChild) ) break;
1292 return SendMessageW( ci->hwndActiveChild, WM_SYSCOMMAND,
1299 if (id - ci->idFirstChild == MDI_MOREWINDOWSLIMIT)
1300 /* User chose "More Windows..." */
1301 childHwnd = MDI_MoreWindowsDialog(hwndMDIClient);
1303 /* User chose one of the windows listed in the "Windows" menu */
1304 childHwnd = MDI_GetChildByID(hwndMDIClient, id, ci);
1307 SendMessageW( hwndMDIClient, WM_MDIACTIVATE, (WPARAM)childHwnd, 0 );
1313 SendMessageW(hwndMDIClient, message, wParam, lParam);
1317 MDI_UpdateFrameText( hwnd, hwndMDIClient, (LPWSTR)lParam );
1318 return 1; /* success. FIXME: check text length */
1321 SetFocus(hwndMDIClient);
1325 MoveWindow(hwndMDIClient, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
1330 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1332 if (!IsIconic(hwnd) && ci->hwndActiveChild && !IsZoomed(ci->hwndActiveChild))
1334 /* control menu is between the frame system menu and
1335 * the first entry of menu bar */
1336 WND *wndPtr = WIN_GetPtr(hwnd);
1338 if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1339 (wParam == VK_RIGHT && GetSubMenu(wndPtr->hSysMenu, 0) == next_menu->hmenuIn) )
1341 WIN_ReleasePtr(wndPtr);
1342 wndPtr = WIN_GetPtr(ci->hwndActiveChild);
1343 next_menu->hmenuNext = GetSubMenu(wndPtr->hSysMenu, 0);
1344 next_menu->hwndNext = ci->hwndActiveChild;
1346 WIN_ReleasePtr(wndPtr);
1353 return DefWindowProcW( hwnd, message, wParam, lParam );
1356 /***********************************************************************
1357 * DefMDIChildProcA (USER32.@)
1359 LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1360 WPARAM wParam, LPARAM lParam )
1362 HWND client = GetParent(hwnd);
1363 MDICLIENTINFO *ci = get_client_info( client );
1365 TRACE("%p %04x (%s) %08x %08lx\n", hwnd, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1367 hwnd = WIN_GetFullHandle( hwnd );
1368 if (!ci) return DefWindowProcA( hwnd, message, wParam, lParam );
1373 DefWindowProcA(hwnd, message, wParam, lParam);
1374 if( ci->hwndActiveChild == hwnd && IsZoomed(ci->hwndActiveChild) )
1375 MDI_UpdateFrameText( GetParent(client), client, NULL );
1376 return 1; /* success. FIXME: check text length */
1378 case WM_GETMINMAXINFO:
1382 case WM_CHILDACTIVATE:
1390 return DefMDIChildProcW( hwnd, message, wParam, lParam );
1392 return DefWindowProcA(hwnd, message, wParam, lParam);
1396 /***********************************************************************
1397 * DefMDIChildProcW (USER32.@)
1399 LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1400 WPARAM wParam, LPARAM lParam )
1402 HWND client = GetParent(hwnd);
1403 MDICLIENTINFO *ci = get_client_info( client );
1405 TRACE("%p %04x (%s) %08x %08lx\n", hwnd, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1407 hwnd = WIN_GetFullHandle( hwnd );
1408 if (!ci) return DefWindowProcW( hwnd, message, wParam, lParam );
1413 DefWindowProcW(hwnd, message, wParam, lParam);
1414 if( ci->hwndActiveChild == hwnd && IsZoomed(ci->hwndActiveChild) )
1415 MDI_UpdateFrameText( GetParent(client), client, NULL );
1416 return 1; /* success. FIXME: check text length */
1418 case WM_GETMINMAXINFO:
1419 MDI_ChildGetMinMaxInfo( client, hwnd, (MINMAXINFO *)lParam );
1423 return 0x00010000; /* MDI children don't have menu bars */
1426 SendMessageW( client, WM_MDIDESTROY, (WPARAM)hwnd, 0 );
1429 case WM_CHILDACTIVATE:
1430 MDI_ChildActivate( client, hwnd );
1437 if( ci->hwndActiveChild == hwnd && IsZoomed(ci->hwndActiveChild))
1444 if (ci->hwndActiveChild == hwnd && IsZoomed(ci->hwndActiveChild))
1445 return SendMessageW( GetParent(client), message, wParam, lParam);
1448 SendMessageW( client, WM_MDINEXT, 0, 0);
1451 SendMessageW( client, WM_MDINEXT, 0, 1);
1458 if (IsZoomed(ci->hwndActiveChild)) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1459 else MDI_PostUpdate(client, ci, SB_BOTH+1);
1463 if( hwnd == ci->hwndActiveChild )
1465 if( wParam == SIZE_MAXIMIZED )
1467 TRACE("maximizing child %p\n", hwnd );
1469 MDI_AugmentFrameMenu( GetParent(client), hwnd );
1472 MDI_RestoreFrameMenu( GetParent(client), hwnd );
1475 MDI_UpdateFrameText( GetParent(client), client, NULL );
1476 MDI_RefreshMenu(ci);
1477 MDI_PostUpdate(client, ci, SB_BOTH+1);
1482 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1483 HWND parent = GetParent(client);
1485 if( wParam == VK_LEFT ) /* switch to frame system menu */
1487 WND *wndPtr = WIN_GetPtr( parent );
1488 next_menu->hmenuNext = GetSubMenu( wndPtr->hSysMenu, 0 );
1489 WIN_ReleasePtr( wndPtr );
1491 if( wParam == VK_RIGHT ) /* to frame menu bar */
1493 next_menu->hmenuNext = GetMenu(parent);
1495 next_menu->hwndNext = parent;
1502 SendMessageW( hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (DWORD)VK_SPACE);
1508 /* Remove itself from the Window menu */
1509 MDI_RefreshMenu(ci);
1512 return DefWindowProcW(hwnd, message, wParam, lParam);
1515 /**********************************************************************
1516 * CreateMDIWindowA (USER32.@) Creates a MDI child
1519 * Success: Handle to created window
1522 HWND WINAPI CreateMDIWindowA(
1523 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1524 LPCSTR lpWindowName, /* [in] Pointer to window name */
1525 DWORD dwStyle, /* [in] Window style */
1526 INT X, /* [in] Horizontal position of window */
1527 INT Y, /* [in] Vertical position of window */
1528 INT nWidth, /* [in] Width of window */
1529 INT nHeight, /* [in] Height of window */
1530 HWND hWndParent, /* [in] Handle to parent window */
1531 HINSTANCE hInstance, /* [in] Handle to application instance */
1532 LPARAM lParam) /* [in] Application-defined value */
1534 TRACE("(%s,%s,%08lx,%d,%d,%d,%d,%p,%p,%08lx)\n",
1535 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1536 nWidth,nHeight,hWndParent,hInstance,lParam);
1538 return CreateWindowExA(WS_EX_MDICHILD, lpClassName, lpWindowName,
1539 dwStyle, X, Y, nWidth, nHeight, hWndParent,
1540 0, hInstance, (LPVOID)lParam);
1543 /***********************************************************************
1544 * CreateMDIWindowW (USER32.@) Creates a MDI child
1547 * Success: Handle to created window
1550 HWND WINAPI CreateMDIWindowW(
1551 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1552 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1553 DWORD dwStyle, /* [in] Window style */
1554 INT X, /* [in] Horizontal position of window */
1555 INT Y, /* [in] Vertical position of window */
1556 INT nWidth, /* [in] Width of window */
1557 INT nHeight, /* [in] Height of window */
1558 HWND hWndParent, /* [in] Handle to parent window */
1559 HINSTANCE hInstance, /* [in] Handle to application instance */
1560 LPARAM lParam) /* [in] Application-defined value */
1562 TRACE("(%s,%s,%08lx,%d,%d,%d,%d,%p,%p,%08lx)\n",
1563 debugstr_w(lpClassName), debugstr_w(lpWindowName), dwStyle, X, Y,
1564 nWidth, nHeight, hWndParent, hInstance, lParam);
1566 return CreateWindowExW(WS_EX_MDICHILD, lpClassName, lpWindowName,
1567 dwStyle, X, Y, nWidth, nHeight, hWndParent,
1568 0, hInstance, (LPVOID)lParam);
1571 /**********************************************************************
1572 * TranslateMDISysAccel (USER32.@)
1574 BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1576 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1578 MDICLIENTINFO *ci = get_client_info( hwndClient );
1581 if (!ci || !IsWindowEnabled(ci->hwndActiveChild)) return 0;
1583 /* translate if the Ctrl key is down and Alt not. */
1585 if( (GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
1587 switch( msg->wParam )
1591 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 ) ? SC_NEXTWINDOW : SC_PREVWINDOW;
1600 TRACE("wParam = %04x\n", wParam);
1601 SendMessageW(ci->hwndActiveChild, WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
1605 return 0; /* failure */
1608 /***********************************************************************
1609 * CalcChildScroll (USER32.@)
1611 void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
1614 RECT childRect, clientRect;
1617 GetClientRect( hwnd, &clientRect );
1618 SetRectEmpty( &childRect );
1620 if ((list = WIN_ListChildren( hwnd )))
1623 for (i = 0; list[i]; i++)
1625 DWORD style = GetWindowLongW( list[i], GWL_STYLE );
1626 if (style & WS_MAXIMIZE)
1628 HeapFree( GetProcessHeap(), 0, list );
1629 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1632 if (style & WS_VISIBLE)
1634 WND *pWnd = WIN_FindWndPtr( list[i] );
1635 UnionRect( &childRect, &pWnd->rectWindow, &childRect );
1636 WIN_ReleaseWndPtr( pWnd );
1639 HeapFree( GetProcessHeap(), 0, list );
1641 UnionRect( &childRect, &clientRect, &childRect );
1643 /* set common info values */
1644 info.cbSize = sizeof(info);
1645 info.fMask = SIF_POS | SIF_RANGE;
1647 /* set the specific */
1652 info.nMin = childRect.left;
1653 info.nMax = childRect.right - clientRect.right;
1654 info.nPos = clientRect.left - childRect.left;
1655 SetScrollInfo(hwnd, scroll, &info, TRUE);
1656 if (scroll == SB_HORZ) break;
1659 info.nMin = childRect.top;
1660 info.nMax = childRect.bottom - clientRect.bottom;
1661 info.nPos = clientRect.top - childRect.top;
1662 SetScrollInfo(hwnd, scroll, &info, TRUE);
1668 /***********************************************************************
1669 * ScrollChildren (USER32.@)
1671 void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
1675 INT curPos, length, minPos, maxPos, shift;
1678 GetClientRect( hWnd, &rect );
1683 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
1684 curPos = GetScrollPos(hWnd,SB_HORZ);
1685 length = (rect.right - rect.left) / 2;
1686 shift = GetSystemMetrics(SM_CYHSCROLL);
1689 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
1690 curPos = GetScrollPos(hWnd,SB_VERT);
1691 length = (rect.bottom - rect.top) / 2;
1692 shift = GetSystemMetrics(SM_CXVSCROLL);
1701 newPos = curPos - shift;
1704 newPos = curPos + shift;
1707 newPos = curPos - length;
1710 newPos = curPos + length;
1713 case SB_THUMBPOSITION:
1714 newPos = LOWORD(lParam);
1727 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
1731 if( newPos > maxPos )
1734 if( newPos < minPos )
1737 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
1739 if( uMsg == WM_VSCROLL )
1740 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
1741 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
1743 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
1744 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
1748 /******************************************************************************
1749 * CascadeWindows (USER32.@) Cascades MDI child windows
1752 * Success: Number of cascaded windows.
1756 CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
1757 UINT cKids, const HWND *lpKids)
1759 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
1764 /******************************************************************************
1765 * TileWindows (USER32.@) Tiles MDI child windows
1768 * Success: Number of tiled windows.
1772 TileWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
1773 UINT cKids, const HWND *lpKids)
1775 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
1779 /************************************************************************
1780 * "More Windows..." functionality
1783 /* MDI_MoreWindowsDlgProc
1785 * This function will process the messages sent to the "More Windows..."
1787 * Return values: 0 = cancel pressed
1788 * HWND = ok pressed or double-click in the list...
1792 static INT_PTR WINAPI MDI_MoreWindowsDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
1801 MDICLIENTINFO *ci = get_client_info( (HWND)lParam );
1802 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
1804 for (i = 0; i < ci->nActiveChildren; i++)
1806 WCHAR buffer[MDI_MAXTITLELENGTH];
1808 if (!InternalGetWindowText( ci->child[i], buffer, sizeof(buffer)/sizeof(WCHAR) ))
1810 SendMessageW(hListBox, LB_ADDSTRING, 0, (LPARAM)buffer );
1811 SendMessageW(hListBox, LB_SETITEMDATA, i, (LPARAM)ci->child[i] );
1812 length = strlenW(buffer); /* FIXME: should use GetTextExtentPoint */
1813 if (length > widest)
1816 /* Make sure the horizontal scrollbar scrolls ok */
1817 SendMessageW(hListBox, LB_SETHORIZONTALEXTENT, widest * 6, 0);
1819 /* Set the current selection */
1820 SendMessageW(hListBox, LB_SETCURSEL, MDI_MOREWINDOWSLIMIT, 0);
1825 switch (LOWORD(wParam))
1828 if (HIWORD(wParam) != LBN_DBLCLK) break;
1832 /* windows are sorted by menu ID, so we must return the
1833 * window associated to the given id
1835 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
1836 UINT index = SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
1837 LRESULT res = SendMessageW(hListBox, LB_GETITEMDATA, index, 0);
1838 EndDialog(hDlg, res);
1852 * MDI_MoreWindowsDialog
1854 * Prompts the user with a listbox containing the opened
1855 * documents. The user can then choose a windows and click
1856 * on OK to set the current window to the one selected, or
1857 * CANCEL to cancel. The function returns a handle to the
1861 static HWND MDI_MoreWindowsDialog(HWND hwnd)
1867 hRes = FindResourceA(user32_module, "MDI_MOREWINDOWS", (LPSTR)RT_DIALOG);
1872 hDlgTmpl = LoadResource(user32_module, hRes );
1877 template = LockResource( hDlgTmpl );
1882 return (HWND) DialogBoxIndirectParamA(user32_module,
1883 (LPDLGTEMPLATEA) template,
1884 hwnd, MDI_MoreWindowsDlgProc, (LPARAM) hwnd);