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 (GetWindowLongPtrW( ci->child[i], GWLP_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 SetWindowLongPtrW(ci->child[i], GWLP_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);
529 MDI_SwitchActiveChild(ci, next);
531 ci->hwndActiveChild = 0; /* nothing to activate */
534 for (i = 0; i < ci->nActiveChildren; i++)
536 if (ci->child[i] == child)
538 HWND *new_child = HeapAlloc(GetProcessHeap(), 0, (ci->nActiveChildren - 1) * sizeof(HWND));
539 memcpy(new_child, ci->child, i * sizeof(HWND));
540 if (i + 1 < ci->nActiveChildren)
541 memcpy(new_child + i, ci->child + i + 1, (ci->nActiveChildren - i - 1) * sizeof(HWND));
542 HeapFree(GetProcessHeap(), 0, ci->child);
543 ci->child = new_child;
545 ci->nActiveChildren--;
552 MDI_PostUpdate(GetParent(child), ci, SB_BOTH+1);
553 DestroyWindow(child);
556 TRACE("child destroyed - %p\n", child);
561 /**********************************************************************
564 * Called in response to WM_CHILDACTIVATE
566 static LONG MDI_ChildActivate( HWND client, HWND child )
568 MDICLIENTINFO *clientInfo;
569 HWND prevActiveWnd, frame;
570 BOOL isActiveFrameWnd;
572 clientInfo = get_client_info( client );
574 if (clientInfo->hwndActiveChild == child) return 0;
576 TRACE("%p\n", child);
578 frame = GetParent(client);
579 isActiveFrameWnd = (GetActiveWindow() == frame);
580 prevActiveWnd = clientInfo->hwndActiveChild;
582 /* deactivate prev. active child */
585 SendMessageW( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
586 SendMessageW( prevActiveWnd, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child);
589 clientInfo->hwndActiveChild = child;
591 MDI_RefreshMenu(clientInfo);
593 if( isActiveFrameWnd )
595 SendMessageW( child, WM_NCACTIVATE, TRUE, 0L);
599 SendMessageW( child, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child );
603 /* -------------------- MDI client window functions ------------------- */
605 /**********************************************************************
606 * CreateMDIMenuBitmap
608 static HBITMAP CreateMDIMenuBitmap(void)
610 HDC hDCSrc = CreateCompatibleDC(0);
611 HDC hDCDest = CreateCompatibleDC(hDCSrc);
612 HBITMAP hbClose = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_OLD_CLOSE) );
614 HBITMAP hobjSrc, hobjDest;
616 hobjSrc = SelectObject(hDCSrc, hbClose);
617 hbCopy = CreateCompatibleBitmap(hDCSrc,GetSystemMetrics(SM_CXSIZE),GetSystemMetrics(SM_CYSIZE));
618 hobjDest = SelectObject(hDCDest, hbCopy);
620 BitBlt(hDCDest, 0, 0, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE),
621 hDCSrc, GetSystemMetrics(SM_CXSIZE), 0, SRCCOPY);
623 SelectObject(hDCSrc, hobjSrc);
624 DeleteObject(hbClose);
627 hobjSrc = SelectObject( hDCDest, GetStockObject(BLACK_PEN) );
629 MoveToEx( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, 0, NULL );
630 LineTo( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, GetSystemMetrics(SM_CYSIZE) - 1);
632 SelectObject(hDCDest, hobjSrc );
633 SelectObject(hDCDest, hobjDest);
639 /**********************************************************************
642 static LONG MDICascade( HWND client, MDICLIENTINFO *ci )
645 BOOL has_icons = FALSE;
648 if (IsZoomed(ci->hwndActiveChild))
649 SendMessageA(client, WM_MDIRESTORE, (WPARAM)ci->hwndActiveChild, 0);
651 if (ci->nActiveChildren == 0) return 0;
653 if (!(win_array = WIN_ListChildren( client ))) return 0;
655 /* remove all the windows we don't want */
656 for (i = total = 0; win_array[i]; i++)
658 if (!IsWindowVisible( win_array[i] )) continue;
659 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows */
660 if (IsIconic( win_array[i] ))
665 win_array[total++] = win_array[i];
667 win_array[total] = 0;
671 INT delta = 0, n = 0, i;
673 if (has_icons) delta = GetSystemMetrics(SM_CYICONSPACING) + GetSystemMetrics(SM_CYICON);
675 /* walk the list (backwards) and move windows */
676 for (i = total - 1; i >= 0; i--)
678 TRACE("move %p to (%ld,%ld) size [%ld,%ld]\n",
679 win_array[i], pos[0].x, pos[0].y, pos[1].x, pos[1].y);
681 MDI_CalcDefaultChildPos(client, n++, pos, delta);
682 SetWindowPos( win_array[i], 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
683 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
686 HeapFree( GetProcessHeap(), 0, win_array );
688 if (has_icons) ArrangeIconicWindows( client );
692 /**********************************************************************
695 static void MDITile( HWND client, MDICLIENTINFO *ci, WPARAM wParam )
699 BOOL has_icons = FALSE;
701 if (IsZoomed(ci->hwndActiveChild))
702 SendMessageA(client, WM_MDIRESTORE, (WPARAM)ci->hwndActiveChild, 0);
704 if (ci->nActiveChildren == 0) return;
706 if (!(win_array = WIN_ListChildren( client ))) return;
708 /* remove all the windows we don't want */
709 for (i = total = 0; win_array[i]; i++)
711 if (!IsWindowVisible( win_array[i] )) continue;
712 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows (icon titles) */
713 if (IsIconic( win_array[i] ))
718 if ((wParam & MDITILE_SKIPDISABLED) && !IsWindowEnabled( win_array[i] )) continue;
719 win_array[total++] = win_array[i];
721 win_array[total] = 0;
723 TRACE("%u windows to tile\n", total);
727 HWND *pWnd = win_array;
729 int x, y, xsize, ysize;
730 int rows, columns, r, c, i;
732 GetClientRect(client,&rect);
733 rows = (int) sqrt((double)total);
734 columns = total / rows;
736 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
739 rows = columns; /* exchange r and c */
745 y = rect.bottom - 2 * GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
746 rect.bottom = ( y - GetSystemMetrics(SM_CYICON) < rect.top )? rect.bottom: y;
749 ysize = rect.bottom / rows;
750 xsize = rect.right / columns;
752 for (x = i = 0, c = 1; c <= columns && *pWnd; c++)
757 ysize = rect.bottom / rows;
761 for (r = 1; r <= rows && *pWnd; r++, i++)
763 SetWindowPos(*pWnd, 0, x, y, xsize, ysize,
764 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
771 HeapFree( GetProcessHeap(), 0, win_array );
772 if (has_icons) ArrangeIconicWindows( client );
775 /* ----------------------- Frame window ---------------------------- */
778 /**********************************************************************
779 * MDI_AugmentFrameMenu
781 static BOOL MDI_AugmentFrameMenu( HWND frame, HWND hChild )
783 HMENU menu = GetMenu( frame );
785 HBITMAP hSysMenuBitmap = 0;
790 TRACE("frame %p,child %p\n",frame,hChild);
792 if( !menu ) return 0;
794 /* if the system buttons already exist do not add them again */
795 nItems = GetMenuItemCount(menu) - 1;
796 iId = GetMenuItemID(menu,nItems) ;
797 if (iId == SC_RESTORE || iId == SC_CLOSE)
800 /* create a copy of sysmenu popup and insert it into frame menu bar */
801 if (!(hSysPopup = GetSystemMenu(hChild, FALSE)))
804 AppendMenuA(menu,MF_HELP | MF_BITMAP,
805 SC_MINIMIZE, (LPSTR)(DWORD)HBMMENU_MBAR_MINIMIZE ) ;
806 AppendMenuA(menu,MF_HELP | MF_BITMAP,
807 SC_RESTORE, (LPSTR)(DWORD)HBMMENU_MBAR_RESTORE );
809 AppendMenuA(menu,MF_HELP | MF_BITMAP,
810 SC_CLOSE, (LPSTR)(DWORD)HBMMENU_MBAR_CLOSE );
812 /* The system menu is replaced by the child icon */
813 hIcon = (HICON)GetClassLongW(hChild, GCL_HICONSM);
815 hIcon = (HICON)GetClassLongW(hChild, GCL_HICON);
817 hIcon = LoadImageW(0, MAKEINTRESOURCEW(IDI_WINLOGO), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
821 HBITMAP hBitmap, hOldBitmap;
823 HDC hdc = GetDC(hChild);
828 cx = GetSystemMetrics(SM_CXSMICON);
829 cy = GetSystemMetrics(SM_CYSMICON);
830 hMemDC = CreateCompatibleDC(hdc);
831 hBitmap = CreateCompatibleBitmap(hdc, cx, cy);
832 hOldBitmap = SelectObject(hMemDC, hBitmap);
833 SetMapMode(hMemDC, MM_TEXT);
834 hBrush = CreateSolidBrush(GetSysColor(COLOR_MENU));
835 DrawIconEx(hMemDC, 0, 0, hIcon, cx, cy, 0, hBrush, DI_NORMAL);
836 SelectObject (hMemDC, hOldBitmap);
837 DeleteObject(hBrush);
839 ReleaseDC(hChild, hdc);
840 hSysMenuBitmap = hBitmap;
844 if( !InsertMenuA(menu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
845 (UINT_PTR)hSysPopup, (LPSTR)hSysMenuBitmap))
847 TRACE("not inserted\n");
848 DestroyMenu(hSysPopup);
852 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
853 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
854 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
855 SetMenuDefaultItem(hSysPopup, SC_CLOSE, FALSE);
863 /**********************************************************************
864 * MDI_RestoreFrameMenu
866 static BOOL MDI_RestoreFrameMenu( HWND frame, HWND hChild )
868 MENUITEMINFOW menuInfo;
869 HMENU menu = GetMenu( frame );
870 INT nItems = GetMenuItemCount(menu) - 1;
871 UINT iId = GetMenuItemID(menu,nItems) ;
873 TRACE("frame %p,child %p,nIt=%d,iId=%d\n",frame,hChild,nItems,iId);
875 /* if there is no system buttons then nothing to do */
876 if(!(iId == SC_RESTORE || iId == SC_CLOSE) )
880 * Remove the system menu, If that menu is the icon of the window
881 * as it is in win95, we have to delete the bitmap.
883 memset(&menuInfo, 0, sizeof(menuInfo));
884 menuInfo.cbSize = sizeof(menuInfo);
885 menuInfo.fMask = MIIM_DATA | MIIM_TYPE;
887 GetMenuItemInfoW(menu,
892 RemoveMenu(menu,0,MF_BYPOSITION);
894 if ( (menuInfo.fType & MFT_BITMAP) &&
895 (LOWORD(menuInfo.dwTypeData)!=0) &&
896 (LOWORD(menuInfo.dwTypeData)!=HBITMAP_16(hBmpClose)) )
898 DeleteObject(HBITMAP_32(LOWORD(menuInfo.dwTypeData)));
902 DeleteMenu(menu, SC_CLOSE, MF_BYCOMMAND);
904 DeleteMenu(menu, SC_RESTORE, MF_BYCOMMAND);
906 DeleteMenu(menu, SC_MINIMIZE, MF_BYCOMMAND);
914 /**********************************************************************
915 * MDI_UpdateFrameText
917 * used when child window is maximized/restored
919 * Note: lpTitle can be NULL
921 static void MDI_UpdateFrameText( HWND frame, HWND hClient, LPCWSTR lpTitle )
923 WCHAR lpBuffer[MDI_MAXTITLELENGTH+1];
924 MDICLIENTINFO *ci = get_client_info( hClient );
926 TRACE("frameText %s\n", debugstr_w(lpTitle));
930 if (!lpTitle && !ci->frameTitle) /* first time around, get title from the frame window */
932 GetWindowTextW( frame, lpBuffer, sizeof(lpBuffer)/sizeof(WCHAR) );
936 /* store new "default" title if lpTitle is not NULL */
939 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
940 if ((ci->frameTitle = HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle)+1)*sizeof(WCHAR))))
941 strcpyW( ci->frameTitle, lpTitle );
946 if (IsZoomed(ci->hwndActiveChild) && IsWindowVisible(ci->hwndActiveChild))
948 /* combine frame title and child title if possible */
950 static const WCHAR lpBracket[] = {' ','-',' ','[',0};
951 static const WCHAR lpBracket2[] = {']',0};
952 int i_frame_text_length = strlenW(ci->frameTitle);
954 lstrcpynW( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
956 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
958 strcatW( lpBuffer, lpBracket );
959 if (GetWindowTextW( ci->hwndActiveChild, lpBuffer + i_frame_text_length + 4,
960 MDI_MAXTITLELENGTH - i_frame_text_length - 5 ))
961 strcatW( lpBuffer, lpBracket2 );
963 lpBuffer[i_frame_text_length] = 0; /* remove bracket */
968 lstrcpynW(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH+1 );
974 DefWindowProcW( frame, WM_SETTEXT, 0, (LPARAM)lpBuffer );
978 /* ----------------------------- Interface ---------------------------- */
981 /**********************************************************************
982 * MDIClientWndProc_common
984 static LRESULT MDIClientWndProc_common( HWND hwnd, UINT message,
985 WPARAM wParam, LPARAM lParam, BOOL unicode )
989 TRACE("%p %04x (%s) %08x %08lx\n", hwnd, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
991 if (!(ci = get_client_info( hwnd ))) return 0;
997 /* Since we are using only cs->lpCreateParams, we can safely
998 * cast to LPCREATESTRUCTA here */
999 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
1000 WND *wndPtr = WIN_GetPtr( hwnd );
1002 wndPtr->flags |= WIN_ISMDICLIENT;
1004 /* Translation layer doesn't know what's in the cs->lpCreateParams
1005 * so we have to keep track of what environment we're in. */
1007 if( wndPtr->flags & WIN_ISWIN32 )
1009 LPCLIENTCREATESTRUCT ccs = cs->lpCreateParams;
1010 ci->hWindowMenu = ccs->hWindowMenu;
1011 ci->idFirstChild = ccs->idFirstChild;
1015 LPCLIENTCREATESTRUCT16 ccs = MapSL((SEGPTR)cs->lpCreateParams);
1016 ci->hWindowMenu = HMENU_32(ccs->hWindowMenu);
1017 ci->idFirstChild = ccs->idFirstChild;
1019 WIN_ReleasePtr( wndPtr );
1022 ci->nActiveChildren = 0;
1023 ci->nTotalCreated = 0;
1024 ci->frameTitle = NULL;
1026 ci->hFrameMenu = GetMenu(cs->hwndParent);
1028 if (!hBmpClose) hBmpClose = CreateMDIMenuBitmap();
1030 TRACE("Client created: hwnd %p, Window menu %p, idFirst = %u\n",
1031 hwnd, ci->hWindowMenu, ci->idFirstChild );
1037 if( IsZoomed(ci->hwndActiveChild) )
1038 MDI_RestoreFrameMenu(GetParent(hwnd), ci->hwndActiveChild);
1040 ci->nActiveChildren = 0;
1041 MDI_RefreshMenu(ci);
1043 if (ci->child) HeapFree( GetProcessHeap(), 0, ci->child );
1044 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1049 case WM_MDIACTIVATE:
1051 MDI_SwitchActiveChild( ci, (HWND)wParam );
1056 return MDICascade(hwnd, ci);
1063 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)lParam;
1064 return (LRESULT)CreateWindowExW(WS_EX_MDICHILD, csW->szClass,
1065 csW->szTitle, csW->style,
1066 csW->x, csW->y, csW->cx, csW->cy,
1067 hwnd, 0, csW->hOwner,
1068 (LPVOID)csW->lParam);
1072 MDICREATESTRUCTA *csA = (MDICREATESTRUCTA *)lParam;
1073 return (LRESULT)CreateWindowExA(WS_EX_MDICHILD, csA->szClass,
1074 csA->szTitle, csA->style,
1075 csA->x, csA->y, csA->cx, csA->cy,
1076 hwnd, 0, csA->hOwner,
1077 (LPVOID)csA->lParam);
1083 return MDIDestroyChild( hwnd, ci, WIN_GetFullHandle( (HWND)wParam ), TRUE );
1085 case WM_MDIGETACTIVE:
1086 if (lParam) *(BOOL *)lParam = IsZoomed(ci->hwndActiveChild);
1087 return (LRESULT)ci->hwndActiveChild;
1089 case WM_MDIICONARRANGE:
1090 ci->mdiFlags |= MDIF_NEEDUPDATE;
1091 ArrangeIconicWindows( hwnd );
1092 ci->sbRecalc = SB_BOTH+1;
1093 SendMessageW( hwnd, WM_MDICALCCHILDSCROLL, 0, 0 );
1096 case WM_MDIMAXIMIZE:
1097 ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1100 case WM_MDINEXT: /* lParam != 0 means previous window */
1102 HWND next = MDI_GetWindow( ci, WIN_GetFullHandle( (HWND)wParam ), !lParam, 0 );
1103 MDI_SwitchActiveChild( ci, next );
1108 SendMessageW( (HWND)wParam, WM_SYSCOMMAND, SC_RESTORE, 0);
1112 return MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1114 case WM_MDIREFRESHMENU:
1115 return MDI_RefreshMenu( ci );
1118 ci->mdiFlags |= MDIF_NEEDUPDATE;
1119 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1120 MDITile( hwnd, ci, wParam );
1121 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1126 ci->mdiFlags |= MDIF_NEEDUPDATE;
1127 ScrollChildren( hwnd, message, wParam, lParam );
1128 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1132 if (ci->hwndActiveChild && !IsIconic( ci->hwndActiveChild ))
1133 SetFocus( ci->hwndActiveChild );
1137 if( ci->hwndActiveChild )
1138 SendMessageW(ci->hwndActiveChild, message, wParam, lParam);
1141 case WM_PARENTNOTIFY:
1142 switch (LOWORD(wParam))
1145 if (GetWindowLongW((HWND)lParam, GWL_EXSTYLE) & WS_EX_MDICHILD)
1147 ci->nTotalCreated++;
1148 ci->nActiveChildren++;
1151 ci->child = HeapAlloc(GetProcessHeap(), 0, sizeof(HWND));
1153 ci->child = HeapReAlloc(GetProcessHeap(), 0, ci->child, sizeof(HWND) * ci->nActiveChildren);
1155 TRACE("Adding MDI child %p, # of children %d\n",
1156 (HWND)lParam, ci->nActiveChildren);
1158 ci->child[ci->nActiveChildren - 1] = (HWND)lParam;
1162 case WM_LBUTTONDOWN:
1166 pt.x = (short)LOWORD(lParam);
1167 pt.y = (short)HIWORD(lParam);
1168 child = ChildWindowFromPoint(hwnd, pt);
1170 TRACE("notification from %p (%li,%li)\n",child,pt.x,pt.y);
1172 if( child && child != hwnd && child != ci->hwndActiveChild )
1173 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1180 if( IsWindow(ci->hwndActiveChild) && IsZoomed(ci->hwndActiveChild) &&
1181 IsWindowVisible(ci->hwndActiveChild) )
1187 rect.right = LOWORD(lParam);
1188 rect.bottom = HIWORD(lParam);
1190 AdjustWindowRectEx(&rect, GetWindowLongA(ci->hwndActiveChild, GWL_STYLE),
1191 0, GetWindowLongA(ci->hwndActiveChild, GWL_EXSTYLE) );
1192 MoveWindow(ci->hwndActiveChild, rect.left, rect.top,
1193 rect.right - rect.left, rect.bottom - rect.top, 1);
1196 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1200 case WM_MDICALCCHILDSCROLL:
1201 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1203 CalcChildScroll(hwnd, ci->sbRecalc-1);
1205 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1209 return unicode ? DefWindowProcW( hwnd, message, wParam, lParam ) :
1210 DefWindowProcA( hwnd, message, wParam, lParam );
1213 /***********************************************************************
1216 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1218 if (!IsWindow(hwnd)) return 0;
1219 return MDIClientWndProc_common( hwnd, message, wParam, lParam, FALSE );
1222 /***********************************************************************
1225 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1227 if (!IsWindow(hwnd)) return 0;
1228 return MDIClientWndProc_common( hwnd, message, wParam, lParam, TRUE );
1231 /***********************************************************************
1232 * DefFrameProcA (USER32.@)
1234 LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1235 UINT message, WPARAM wParam, LPARAM lParam)
1243 DWORD len = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0 );
1244 LPWSTR text = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1245 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, text, len );
1246 MDI_UpdateFrameText( hwnd, hwndMDIClient, text );
1247 HeapFree( GetProcessHeap(), 0, text );
1249 return 1; /* success. FIXME: check text length */
1256 return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1259 return DefWindowProcA(hwnd, message, wParam, lParam);
1263 /***********************************************************************
1264 * DefFrameProcW (USER32.@)
1266 LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1267 UINT message, WPARAM wParam, LPARAM lParam)
1269 MDICLIENTINFO *ci = get_client_info( hwndMDIClient );
1271 TRACE("%p %p %04x (%s) %08x %08lx\n", hwnd, hwndMDIClient, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1279 WORD id = LOWORD(wParam);
1280 /* check for possible syscommands for maximized MDI child */
1281 if (id < ci->idFirstChild || id >= ci->idFirstChild + ci->nActiveChildren)
1283 if( (id - 0xf000) & 0xf00f ) break;
1284 if( !IsZoomed(ci->hwndActiveChild) ) break;
1295 return SendMessageW( ci->hwndActiveChild, WM_SYSCOMMAND,
1302 if (id - ci->idFirstChild == MDI_MOREWINDOWSLIMIT)
1303 /* User chose "More Windows..." */
1304 childHwnd = MDI_MoreWindowsDialog(hwndMDIClient);
1306 /* User chose one of the windows listed in the "Windows" menu */
1307 childHwnd = MDI_GetChildByID(hwndMDIClient, id, ci);
1310 SendMessageW( hwndMDIClient, WM_MDIACTIVATE, (WPARAM)childHwnd, 0 );
1316 SendMessageW(hwndMDIClient, message, wParam, lParam);
1320 MDI_UpdateFrameText( hwnd, hwndMDIClient, (LPWSTR)lParam );
1321 return 1; /* success. FIXME: check text length */
1324 SetFocus(hwndMDIClient);
1328 MoveWindow(hwndMDIClient, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
1333 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1335 if (!IsIconic(hwnd) && ci->hwndActiveChild && !IsZoomed(ci->hwndActiveChild))
1337 /* control menu is between the frame system menu and
1338 * the first entry of menu bar */
1339 WND *wndPtr = WIN_GetPtr(hwnd);
1341 if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1342 (wParam == VK_RIGHT && GetSubMenu(wndPtr->hSysMenu, 0) == next_menu->hmenuIn) )
1344 WIN_ReleasePtr(wndPtr);
1345 wndPtr = WIN_GetPtr(ci->hwndActiveChild);
1346 next_menu->hmenuNext = GetSubMenu(wndPtr->hSysMenu, 0);
1347 next_menu->hwndNext = ci->hwndActiveChild;
1349 WIN_ReleasePtr(wndPtr);
1356 return DefWindowProcW( hwnd, message, wParam, lParam );
1359 /***********************************************************************
1360 * DefMDIChildProcA (USER32.@)
1362 LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1363 WPARAM wParam, LPARAM lParam )
1365 HWND client = GetParent(hwnd);
1366 MDICLIENTINFO *ci = get_client_info( client );
1368 TRACE("%p %04x (%s) %08x %08lx\n", hwnd, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1370 hwnd = WIN_GetFullHandle( hwnd );
1371 if (!ci) return DefWindowProcA( hwnd, message, wParam, lParam );
1376 DefWindowProcA(hwnd, message, wParam, lParam);
1377 if( ci->hwndActiveChild == hwnd && IsZoomed(ci->hwndActiveChild) )
1378 MDI_UpdateFrameText( GetParent(client), client, NULL );
1379 return 1; /* success. FIXME: check text length */
1381 case WM_GETMINMAXINFO:
1385 case WM_CHILDACTIVATE:
1393 return DefMDIChildProcW( hwnd, message, wParam, lParam );
1395 return DefWindowProcA(hwnd, message, wParam, lParam);
1399 /***********************************************************************
1400 * DefMDIChildProcW (USER32.@)
1402 LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1403 WPARAM wParam, LPARAM lParam )
1405 HWND client = GetParent(hwnd);
1406 MDICLIENTINFO *ci = get_client_info( client );
1408 TRACE("%p %04x (%s) %08x %08lx\n", hwnd, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1410 hwnd = WIN_GetFullHandle( hwnd );
1411 if (!ci) return DefWindowProcW( hwnd, message, wParam, lParam );
1416 DefWindowProcW(hwnd, message, wParam, lParam);
1417 if( ci->hwndActiveChild == hwnd && IsZoomed(ci->hwndActiveChild) )
1418 MDI_UpdateFrameText( GetParent(client), client, NULL );
1419 return 1; /* success. FIXME: check text length */
1421 case WM_GETMINMAXINFO:
1422 MDI_ChildGetMinMaxInfo( client, hwnd, (MINMAXINFO *)lParam );
1426 return 0x00010000; /* MDI children don't have menu bars */
1429 SendMessageW( client, WM_MDIDESTROY, (WPARAM)hwnd, 0 );
1432 case WM_CHILDACTIVATE:
1433 MDI_ChildActivate( client, hwnd );
1440 if( ci->hwndActiveChild == hwnd && IsZoomed(ci->hwndActiveChild))
1447 if (ci->hwndActiveChild == hwnd && IsZoomed(ci->hwndActiveChild))
1448 return SendMessageW( GetParent(client), message, wParam, lParam);
1451 SendMessageW( client, WM_MDINEXT, 0, 0);
1454 SendMessageW( client, WM_MDINEXT, 0, 1);
1461 if (IsZoomed(ci->hwndActiveChild)) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1462 else MDI_PostUpdate(client, ci, SB_BOTH+1);
1466 if( hwnd == ci->hwndActiveChild )
1468 if( wParam == SIZE_MAXIMIZED )
1470 TRACE("maximizing child %p\n", hwnd );
1472 MDI_AugmentFrameMenu( GetParent(client), hwnd );
1475 MDI_RestoreFrameMenu( GetParent(client), hwnd );
1478 MDI_UpdateFrameText( GetParent(client), client, NULL );
1479 MDI_RefreshMenu(ci);
1480 MDI_PostUpdate(client, ci, SB_BOTH+1);
1485 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1486 HWND parent = GetParent(client);
1488 if( wParam == VK_LEFT ) /* switch to frame system menu */
1490 WND *wndPtr = WIN_GetPtr( parent );
1491 next_menu->hmenuNext = GetSubMenu( wndPtr->hSysMenu, 0 );
1492 WIN_ReleasePtr( wndPtr );
1494 if( wParam == VK_RIGHT ) /* to frame menu bar */
1496 next_menu->hmenuNext = GetMenu(parent);
1498 next_menu->hwndNext = parent;
1505 SendMessageW( hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (DWORD)VK_SPACE);
1511 /* Remove itself from the Window menu */
1512 MDI_RefreshMenu(ci);
1515 return DefWindowProcW(hwnd, message, wParam, lParam);
1518 /**********************************************************************
1519 * CreateMDIWindowA (USER32.@) Creates a MDI child
1522 * Success: Handle to created window
1525 HWND WINAPI CreateMDIWindowA(
1526 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1527 LPCSTR lpWindowName, /* [in] Pointer to window name */
1528 DWORD dwStyle, /* [in] Window style */
1529 INT X, /* [in] Horizontal position of window */
1530 INT Y, /* [in] Vertical position of window */
1531 INT nWidth, /* [in] Width of window */
1532 INT nHeight, /* [in] Height of window */
1533 HWND hWndParent, /* [in] Handle to parent window */
1534 HINSTANCE hInstance, /* [in] Handle to application instance */
1535 LPARAM lParam) /* [in] Application-defined value */
1537 TRACE("(%s,%s,%08lx,%d,%d,%d,%d,%p,%p,%08lx)\n",
1538 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1539 nWidth,nHeight,hWndParent,hInstance,lParam);
1541 return CreateWindowExA(WS_EX_MDICHILD, lpClassName, lpWindowName,
1542 dwStyle, X, Y, nWidth, nHeight, hWndParent,
1543 0, hInstance, (LPVOID)lParam);
1546 /***********************************************************************
1547 * CreateMDIWindowW (USER32.@) Creates a MDI child
1550 * Success: Handle to created window
1553 HWND WINAPI CreateMDIWindowW(
1554 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1555 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1556 DWORD dwStyle, /* [in] Window style */
1557 INT X, /* [in] Horizontal position of window */
1558 INT Y, /* [in] Vertical position of window */
1559 INT nWidth, /* [in] Width of window */
1560 INT nHeight, /* [in] Height of window */
1561 HWND hWndParent, /* [in] Handle to parent window */
1562 HINSTANCE hInstance, /* [in] Handle to application instance */
1563 LPARAM lParam) /* [in] Application-defined value */
1565 TRACE("(%s,%s,%08lx,%d,%d,%d,%d,%p,%p,%08lx)\n",
1566 debugstr_w(lpClassName), debugstr_w(lpWindowName), dwStyle, X, Y,
1567 nWidth, nHeight, hWndParent, hInstance, lParam);
1569 return CreateWindowExW(WS_EX_MDICHILD, lpClassName, lpWindowName,
1570 dwStyle, X, Y, nWidth, nHeight, hWndParent,
1571 0, hInstance, (LPVOID)lParam);
1574 /**********************************************************************
1575 * TranslateMDISysAccel (USER32.@)
1577 BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1579 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1581 MDICLIENTINFO *ci = get_client_info( hwndClient );
1584 if (!ci || !IsWindowEnabled(ci->hwndActiveChild)) return 0;
1586 /* translate if the Ctrl key is down and Alt not. */
1588 if( (GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
1590 switch( msg->wParam )
1594 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 ) ? SC_NEXTWINDOW : SC_PREVWINDOW;
1603 TRACE("wParam = %04x\n", wParam);
1604 SendMessageW(ci->hwndActiveChild, WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
1608 return 0; /* failure */
1611 /***********************************************************************
1612 * CalcChildScroll (USER32.@)
1614 void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
1617 RECT childRect, clientRect;
1620 GetClientRect( hwnd, &clientRect );
1621 SetRectEmpty( &childRect );
1623 if ((list = WIN_ListChildren( hwnd )))
1626 for (i = 0; list[i]; i++)
1628 DWORD style = GetWindowLongW( list[i], GWL_STYLE );
1629 if (style & WS_MAXIMIZE)
1631 HeapFree( GetProcessHeap(), 0, list );
1632 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1635 if (style & WS_VISIBLE)
1637 WND *pWnd = WIN_FindWndPtr( list[i] );
1638 UnionRect( &childRect, &pWnd->rectWindow, &childRect );
1639 WIN_ReleaseWndPtr( pWnd );
1642 HeapFree( GetProcessHeap(), 0, list );
1644 UnionRect( &childRect, &clientRect, &childRect );
1646 /* set common info values */
1647 info.cbSize = sizeof(info);
1648 info.fMask = SIF_POS | SIF_RANGE;
1650 /* set the specific */
1655 info.nMin = childRect.left;
1656 info.nMax = childRect.right - clientRect.right;
1657 info.nPos = clientRect.left - childRect.left;
1658 SetScrollInfo(hwnd, scroll, &info, TRUE);
1659 if (scroll == SB_HORZ) break;
1662 info.nMin = childRect.top;
1663 info.nMax = childRect.bottom - clientRect.bottom;
1664 info.nPos = clientRect.top - childRect.top;
1665 SetScrollInfo(hwnd, scroll, &info, TRUE);
1671 /***********************************************************************
1672 * ScrollChildren (USER32.@)
1674 void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
1678 INT curPos, length, minPos, maxPos, shift;
1681 GetClientRect( hWnd, &rect );
1686 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
1687 curPos = GetScrollPos(hWnd,SB_HORZ);
1688 length = (rect.right - rect.left) / 2;
1689 shift = GetSystemMetrics(SM_CYHSCROLL);
1692 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
1693 curPos = GetScrollPos(hWnd,SB_VERT);
1694 length = (rect.bottom - rect.top) / 2;
1695 shift = GetSystemMetrics(SM_CXVSCROLL);
1704 newPos = curPos - shift;
1707 newPos = curPos + shift;
1710 newPos = curPos - length;
1713 newPos = curPos + length;
1716 case SB_THUMBPOSITION:
1717 newPos = LOWORD(lParam);
1730 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
1734 if( newPos > maxPos )
1737 if( newPos < minPos )
1740 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
1742 if( uMsg == WM_VSCROLL )
1743 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
1744 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
1746 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
1747 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
1751 /******************************************************************************
1752 * CascadeWindows (USER32.@) Cascades MDI child windows
1755 * Success: Number of cascaded windows.
1759 CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
1760 UINT cKids, const HWND *lpKids)
1762 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
1767 /******************************************************************************
1768 * TileWindows (USER32.@) Tiles MDI child windows
1771 * Success: Number of tiled windows.
1775 TileWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
1776 UINT cKids, const HWND *lpKids)
1778 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
1782 /************************************************************************
1783 * "More Windows..." functionality
1786 /* MDI_MoreWindowsDlgProc
1788 * This function will process the messages sent to the "More Windows..."
1790 * Return values: 0 = cancel pressed
1791 * HWND = ok pressed or double-click in the list...
1795 static INT_PTR WINAPI MDI_MoreWindowsDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
1804 MDICLIENTINFO *ci = get_client_info( (HWND)lParam );
1805 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
1807 for (i = 0; i < ci->nActiveChildren; i++)
1809 WCHAR buffer[MDI_MAXTITLELENGTH];
1811 if (!InternalGetWindowText( ci->child[i], buffer, sizeof(buffer)/sizeof(WCHAR) ))
1813 SendMessageW(hListBox, LB_ADDSTRING, 0, (LPARAM)buffer );
1814 SendMessageW(hListBox, LB_SETITEMDATA, i, (LPARAM)ci->child[i] );
1815 length = strlenW(buffer); /* FIXME: should use GetTextExtentPoint */
1816 if (length > widest)
1819 /* Make sure the horizontal scrollbar scrolls ok */
1820 SendMessageW(hListBox, LB_SETHORIZONTALEXTENT, widest * 6, 0);
1822 /* Set the current selection */
1823 SendMessageW(hListBox, LB_SETCURSEL, MDI_MOREWINDOWSLIMIT, 0);
1828 switch (LOWORD(wParam))
1831 if (HIWORD(wParam) != LBN_DBLCLK) break;
1835 /* windows are sorted by menu ID, so we must return the
1836 * window associated to the given id
1838 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
1839 UINT index = SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
1840 LRESULT res = SendMessageW(hListBox, LB_GETITEMDATA, index, 0);
1841 EndDialog(hDlg, res);
1855 * MDI_MoreWindowsDialog
1857 * Prompts the user with a listbox containing the opened
1858 * documents. The user can then choose a windows and click
1859 * on OK to set the current window to the one selected, or
1860 * CANCEL to cancel. The function returns a handle to the
1864 static HWND MDI_MoreWindowsDialog(HWND hwnd)
1870 hRes = FindResourceA(user32_module, "MDI_MOREWINDOWS", (LPSTR)RT_DIALOG);
1875 hDlgTmpl = LoadResource(user32_module, hRes );
1880 template = LockResource( hDlgTmpl );
1885 return (HWND) DialogBoxIndirectParamA(user32_module,
1886 (LPDLGTEMPLATEA) template,
1887 hwnd, MDI_MoreWindowsDlgProc, (LPARAM) hwnd);