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 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 if (IsWindow(client)) 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 static BOOL is_close_enabled(HWND hwnd, HMENU hSysMenu)
207 if (GetClassLongW(hwnd, GCL_STYLE) & CS_NOCLOSE) return FALSE;
209 if (!hSysMenu) hSysMenu = GetSystemMenu(hwnd, FALSE);
212 UINT state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
213 if (state == 0xFFFFFFFF || (state & (MF_DISABLED | MF_GRAYED)))
219 /**********************************************************************
222 * returns "activatable" child different from the current or zero
224 static HWND MDI_GetWindow(MDICLIENTINFO *clientInfo, HWND hWnd, BOOL bNext,
231 dwStyleMask |= WS_DISABLED | WS_VISIBLE;
232 if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
234 if (!(list = WIN_ListChildren( GetParent(hWnd) ))) return 0;
236 /* start from next after hWnd */
237 while (list[i] && list[i] != hWnd) i++;
240 for ( ; list[i]; i++)
242 if (GetWindow( list[i], GW_OWNER )) continue;
243 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
245 if (bNext) goto found;
247 /* now restart from the beginning */
248 for (i = 0; list[i] && list[i] != hWnd; i++)
250 if (GetWindow( list[i], GW_OWNER )) continue;
251 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
253 if (bNext) goto found;
256 HeapFree( GetProcessHeap(), 0, list );
260 /**********************************************************************
261 * MDI_CalcDefaultChildPos
263 * It seems that the default height is about 2/3 of the client rect
265 void MDI_CalcDefaultChildPos( HWND hwndClient, INT total, LPPOINT lpPos, INT delta, UINT *id )
269 INT spacing = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME) - 1;
271 if (total < 0) /* we are called from CreateWindow */
273 MDICLIENTINFO *ci = get_client_info(hwndClient);
274 total = ci ? ci->nTotalCreated : 0;
275 *id = ci->idFirstChild + ci->nActiveChildren;
276 TRACE("MDI child id %04x\n", *id);
279 GetClientRect( hwndClient, &rect );
280 if( rect.bottom - rect.top - delta >= spacing )
281 rect.bottom -= delta;
283 nstagger = (rect.bottom - rect.top)/(3 * spacing);
284 lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
285 lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
286 lpPos[0].x = lpPos[0].y = spacing * (total%(nstagger+1));
289 /**********************************************************************
292 static LRESULT MDISetMenu( HWND hwnd, HMENU hmenuFrame,
296 HWND hwndFrame = GetParent(hwnd);
298 TRACE("%p %p %p\n", hwnd, hmenuFrame, hmenuWindow);
300 if (hmenuFrame && !IsMenu(hmenuFrame))
302 WARN("hmenuFrame is not a menu handle\n");
306 if (hmenuWindow && !IsMenu(hmenuWindow))
308 WARN("hmenuWindow is not a menu handle\n");
312 if (!(ci = get_client_info( hwnd ))) return 0;
316 if (hmenuFrame == ci->hFrameMenu) return (LRESULT)hmenuFrame;
318 if (IsZoomed(ci->hwndActiveChild))
319 MDI_RestoreFrameMenu( hwndFrame, ci->hwndActiveChild );
322 if( hmenuWindow && hmenuWindow != ci->hWindowMenu )
324 /* delete menu items from ci->hWindowMenu
325 * and add them to hmenuWindow */
326 /* Agent newsreader calls this function with ci->hWindowMenu == NULL */
327 if( ci->hWindowMenu && ci->nActiveChildren )
329 UINT nActiveChildren_old = ci->nActiveChildren;
331 /* Remove all items from old Window menu */
332 ci->nActiveChildren = 0;
335 ci->hWindowMenu = hmenuWindow;
337 /* Add items to the new Window menu */
338 ci->nActiveChildren = nActiveChildren_old;
342 ci->hWindowMenu = hmenuWindow;
347 SetMenu(hwndFrame, hmenuFrame);
348 if( hmenuFrame != ci->hFrameMenu )
350 HMENU oldFrameMenu = ci->hFrameMenu;
352 ci->hFrameMenu = hmenuFrame;
353 if (IsZoomed(ci->hwndActiveChild) && (GetWindowLongW(ci->hwndActiveChild, GWL_STYLE) & WS_VISIBLE))
354 MDI_AugmentFrameMenu( hwndFrame, ci->hwndActiveChild );
356 return (LRESULT)oldFrameMenu;
361 /* SetMenu() may already have been called, meaning that this window
362 * already has its menu. But they may have done a SetMenu() on
363 * an MDI window, and called MDISetMenu() after the fact, meaning
364 * that the "if" to this "else" wouldn't catch the need to
365 * augment the frame menu.
367 if( IsZoomed(ci->hwndActiveChild) )
368 MDI_AugmentFrameMenu( hwndFrame, ci->hwndActiveChild );
374 /**********************************************************************
377 static LRESULT MDI_RefreshMenu(MDICLIENTINFO *ci)
379 UINT i, count, visible, id;
380 WCHAR buf[MDI_MAXTITLELENGTH];
382 TRACE("children %u, window menu %p\n", ci->nActiveChildren, ci->hWindowMenu);
384 if (!ci->hWindowMenu)
387 if (!IsMenu(ci->hWindowMenu))
389 WARN("Window menu handle %p is no more valid\n", ci->hWindowMenu);
393 /* Windows finds the last separator in the menu, and if after it
394 * there is a menu item with MDI magic ID removes all existing
395 * menu items after it, and then adds visible MDI children.
397 count = GetMenuItemCount(ci->hWindowMenu);
398 for (i = 0; i < count; i++)
402 memset(&mii, 0, sizeof(mii));
403 mii.cbSize = sizeof(mii);
404 mii.fMask = MIIM_TYPE;
405 if (GetMenuItemInfoW(ci->hWindowMenu, i, TRUE, &mii))
407 if (mii.fType & MF_SEPARATOR)
409 /* Windows checks only ID of the menu item */
410 memset(&mii, 0, sizeof(mii));
411 mii.cbSize = sizeof(mii);
413 if (GetMenuItemInfoW(ci->hWindowMenu, i + 1, TRUE, &mii))
415 if (mii.wID == ci->idFirstChild)
417 TRACE("removing %u items including separator\n", count - i);
418 while (RemoveMenu(ci->hWindowMenu, i, MF_BYPOSITION))
429 for (i = 0; i < ci->nActiveChildren; i++)
431 if (GetWindowLongW(ci->child[i], GWL_STYLE) & WS_VISIBLE)
433 id = ci->idFirstChild + visible;
435 if (visible == MDI_MOREWINDOWSLIMIT)
437 LoadStringW(user32_module, IDS_MDI_MOREWINDOWS, buf, sizeof(buf)/sizeof(WCHAR));
438 AppendMenuW(ci->hWindowMenu, MF_STRING, id, buf);
443 /* Visio expects that separator has id 0 */
444 AppendMenuW(ci->hWindowMenu, MF_SEPARATOR, 0, NULL);
448 SetWindowLongPtrW(ci->child[i], GWLP_ID, id);
451 buf[1] = '0' + visible;
453 InternalGetWindowText(ci->child[i], buf + 3, sizeof(buf)/sizeof(WCHAR) - 3);
454 TRACE("Adding %p, id %u %s\n", ci->child[i], id, debugstr_w(buf));
455 AppendMenuW(ci->hWindowMenu, MF_STRING, id, buf);
457 if (ci->child[i] == ci->hwndActiveChild)
458 CheckMenuItem(ci->hWindowMenu, id, MF_CHECKED);
461 TRACE("MDI child %p is not visible, skipping\n", ci->child[i]);
464 return (LRESULT)ci->hFrameMenu;
468 /* ------------------ MDI child window functions ---------------------- */
470 /**********************************************************************
471 * MDI_ChildGetMinMaxInfo
473 * Note: The rule here is that client rect of the maximized MDI child
474 * is equal to the client rect of the MDI client window.
476 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
480 GetClientRect( client, &rect );
481 AdjustWindowRectEx( &rect, GetWindowLongW( hwnd, GWL_STYLE ),
482 0, GetWindowLongW( hwnd, GWL_EXSTYLE ));
484 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
485 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
487 lpMinMax->ptMaxPosition.x = rect.left;
488 lpMinMax->ptMaxPosition.y = rect.top;
490 TRACE("max rect (%d,%d - %d, %d)\n",
491 rect.left,rect.top,rect.right,rect.bottom);
494 /**********************************************************************
495 * MDI_SwitchActiveChild
497 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
500 static void MDI_SwitchActiveChild( MDICLIENTINFO *ci, HWND hwndTo, BOOL activate )
504 hwndPrev = ci->hwndActiveChild;
506 TRACE("from %p, to %p\n", hwndPrev, hwndTo);
508 if ( hwndTo != hwndPrev )
510 BOOL was_zoomed = IsZoomed(hwndPrev);
514 /* restore old MDI child */
515 SendMessageW( hwndPrev, WM_SETREDRAW, FALSE, 0 );
516 ShowWindow( hwndPrev, SW_RESTORE );
517 SendMessageW( hwndPrev, WM_SETREDRAW, TRUE, 0 );
519 /* activate new MDI child */
520 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
521 /* maximize new MDI child */
522 ShowWindow( hwndTo, SW_MAXIMIZE );
524 /* activate new MDI child */
525 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | (activate ? 0 : SWP_NOACTIVATE) );
530 /**********************************************************************
533 static LRESULT MDIDestroyChild( HWND client, MDICLIENTINFO *ci,
534 HWND child, BOOL flagDestroy )
538 TRACE("# of managed children %u\n", ci->nActiveChildren);
540 if( child == ci->hwndActiveChild )
542 HWND next = MDI_GetWindow(ci, child, TRUE, 0);
544 MDI_SwitchActiveChild(ci, next, TRUE);
547 ShowWindow(child, SW_HIDE);
550 MDI_RestoreFrameMenu(GetParent(client), child);
551 MDI_UpdateFrameText(GetParent(client), client, NULL);
553 MDI_ChildActivate(client, 0);
557 for (i = 0; i < ci->nActiveChildren; i++)
559 if (ci->child[i] == child)
561 HWND *new_child = HeapAlloc(GetProcessHeap(), 0, (ci->nActiveChildren - 1) * sizeof(HWND));
562 memcpy(new_child, ci->child, i * sizeof(HWND));
563 if (i + 1 < ci->nActiveChildren)
564 memcpy(new_child + i, ci->child + i + 1, (ci->nActiveChildren - i - 1) * sizeof(HWND));
565 HeapFree(GetProcessHeap(), 0, ci->child);
566 ci->child = new_child;
568 ci->nActiveChildren--;
573 SendMessageW(client, WM_MDIREFRESHMENU, 0, 0);
577 MDI_PostUpdate(GetParent(child), ci, SB_BOTH+1);
578 DestroyWindow(child);
581 TRACE("child destroyed - %p\n", child);
586 /**********************************************************************
589 * Called in response to WM_CHILDACTIVATE, or when last MDI child
590 * is being deactivated.
592 static LONG MDI_ChildActivate( HWND client, HWND child )
594 MDICLIENTINFO *clientInfo;
595 HWND prevActiveWnd, frame;
596 BOOL isActiveFrameWnd;
598 clientInfo = get_client_info( client );
600 if (clientInfo->hwndActiveChild == child) return 0;
602 TRACE("%p\n", child);
604 frame = GetParent(client);
605 isActiveFrameWnd = (GetActiveWindow() == frame);
606 prevActiveWnd = clientInfo->hwndActiveChild;
608 /* deactivate prev. active child */
611 SendMessageW( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
612 SendMessageW( prevActiveWnd, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child);
615 MDI_SwitchActiveChild( clientInfo, child, FALSE );
616 clientInfo->hwndActiveChild = child;
618 MDI_RefreshMenu(clientInfo);
620 if( isActiveFrameWnd )
622 SendMessageW( child, WM_NCACTIVATE, TRUE, 0L);
623 /* Let the client window manage focus for children, but if the focus
624 * is already on the client (for instance this is the 1st child) then
625 * SetFocus won't work. It appears that Windows sends WM_SETFOCUS
626 * manually in this case.
628 if (SetFocus(client) == client)
629 SendMessageW( client, WM_SETFOCUS, (WPARAM)client, 0 );
632 SendMessageW( child, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child );
636 /* -------------------- MDI client window functions ------------------- */
638 /**********************************************************************
639 * CreateMDIMenuBitmap
641 static HBITMAP CreateMDIMenuBitmap(void)
643 HDC hDCSrc = CreateCompatibleDC(0);
644 HDC hDCDest = CreateCompatibleDC(hDCSrc);
645 HBITMAP hbClose = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_OLD_CLOSE) );
647 HBITMAP hobjSrc, hobjDest;
649 hobjSrc = SelectObject(hDCSrc, hbClose);
650 hbCopy = CreateCompatibleBitmap(hDCSrc,GetSystemMetrics(SM_CXSIZE),GetSystemMetrics(SM_CYSIZE));
651 hobjDest = SelectObject(hDCDest, hbCopy);
653 BitBlt(hDCDest, 0, 0, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE),
654 hDCSrc, GetSystemMetrics(SM_CXSIZE), 0, SRCCOPY);
656 SelectObject(hDCSrc, hobjSrc);
657 DeleteObject(hbClose);
660 hobjSrc = SelectObject( hDCDest, GetStockObject(BLACK_PEN) );
662 MoveToEx( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, 0, NULL );
663 LineTo( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, GetSystemMetrics(SM_CYSIZE) - 1);
665 SelectObject(hDCDest, hobjSrc );
666 SelectObject(hDCDest, hobjDest);
672 /**********************************************************************
675 static LONG MDICascade( HWND client, MDICLIENTINFO *ci )
678 BOOL has_icons = FALSE;
681 if (IsZoomed(ci->hwndActiveChild))
682 SendMessageW(client, WM_MDIRESTORE, (WPARAM)ci->hwndActiveChild, 0);
684 if (ci->nActiveChildren == 0) return 0;
686 if (!(win_array = WIN_ListChildren( client ))) return 0;
688 /* remove all the windows we don't want */
689 for (i = total = 0; win_array[i]; i++)
691 if (!IsWindowVisible( win_array[i] )) continue;
692 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows */
693 if (IsIconic( win_array[i] ))
698 win_array[total++] = win_array[i];
700 win_array[total] = 0;
704 INT delta = 0, n = 0, i;
706 if (has_icons) delta = GetSystemMetrics(SM_CYICONSPACING) + GetSystemMetrics(SM_CYICON);
708 /* walk the list (backwards) and move windows */
709 for (i = total - 1; i >= 0; i--)
711 TRACE("move %p to (%d,%d) size [%d,%d]\n",
712 win_array[i], pos[0].x, pos[0].y, pos[1].x, pos[1].y);
714 MDI_CalcDefaultChildPos(client, n++, pos, delta, NULL);
715 SetWindowPos( win_array[i], 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
716 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
719 HeapFree( GetProcessHeap(), 0, win_array );
721 if (has_icons) ArrangeIconicWindows( client );
725 /**********************************************************************
728 static void MDITile( HWND client, MDICLIENTINFO *ci, WPARAM wParam )
732 BOOL has_icons = FALSE;
734 if (IsZoomed(ci->hwndActiveChild))
735 SendMessageW(client, WM_MDIRESTORE, (WPARAM)ci->hwndActiveChild, 0);
737 if (ci->nActiveChildren == 0) return;
739 if (!(win_array = WIN_ListChildren( client ))) return;
741 /* remove all the windows we don't want */
742 for (i = total = 0; win_array[i]; i++)
744 if (!IsWindowVisible( win_array[i] )) continue;
745 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows (icon titles) */
746 if (IsIconic( win_array[i] ))
751 if ((wParam & MDITILE_SKIPDISABLED) && !IsWindowEnabled( win_array[i] )) continue;
752 win_array[total++] = win_array[i];
754 win_array[total] = 0;
756 TRACE("%u windows to tile\n", total);
760 HWND *pWnd = win_array;
762 int x, y, xsize, ysize;
763 int rows, columns, r, c, i;
765 GetClientRect(client,&rect);
766 rows = (int) sqrt((double)total);
767 columns = total / rows;
769 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
772 rows = columns; /* exchange r and c */
778 y = rect.bottom - 2 * GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
779 rect.bottom = ( y - GetSystemMetrics(SM_CYICON) < rect.top )? rect.bottom: y;
782 ysize = rect.bottom / rows;
783 xsize = rect.right / columns;
785 for (x = i = 0, c = 1; c <= columns && *pWnd; c++)
790 ysize = rect.bottom / rows;
794 for (r = 1; r <= rows && *pWnd; r++, i++)
796 SetWindowPos(*pWnd, 0, x, y, xsize, ysize,
797 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
804 HeapFree( GetProcessHeap(), 0, win_array );
805 if (has_icons) ArrangeIconicWindows( client );
808 /* ----------------------- Frame window ---------------------------- */
811 /**********************************************************************
812 * MDI_AugmentFrameMenu
814 static BOOL MDI_AugmentFrameMenu( HWND frame, HWND hChild )
816 HMENU menu = GetMenu( frame );
818 HBITMAP hSysMenuBitmap = 0;
823 TRACE("frame %p,child %p\n",frame,hChild);
825 if( !menu ) return 0;
827 /* if the system buttons already exist do not add them again */
828 nItems = GetMenuItemCount(menu) - 1;
829 iId = GetMenuItemID(menu,nItems) ;
830 if (iId == SC_RESTORE || iId == SC_CLOSE)
833 /* create a copy of sysmenu popup and insert it into frame menu bar */
834 if (!(hSysPopup = GetSystemMenu(hChild, FALSE)))
837 AppendMenuW(menu, MF_HELP | MF_BITMAP,
838 SC_MINIMIZE, (LPCWSTR)HBMMENU_MBAR_MINIMIZE ) ;
839 AppendMenuW(menu, MF_HELP | MF_BITMAP,
840 SC_RESTORE, (LPCWSTR)HBMMENU_MBAR_RESTORE );
841 AppendMenuW(menu, MF_HELP | MF_BITMAP,
842 SC_CLOSE, is_close_enabled(hChild, hSysPopup) ?
843 (LPCWSTR)HBMMENU_MBAR_CLOSE : (LPCWSTR)HBMMENU_MBAR_CLOSE_D );
845 /* The system menu is replaced by the child icon */
846 hIcon = (HICON)GetClassLongPtrW(hChild, GCLP_HICONSM);
848 hIcon = (HICON)GetClassLongPtrW(hChild, GCLP_HICON);
850 hIcon = LoadImageW(0, MAKEINTRESOURCEW(IDI_WINLOGO), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
854 HBITMAP hBitmap, hOldBitmap;
856 HDC hdc = GetDC(hChild);
861 cx = GetSystemMetrics(SM_CXSMICON);
862 cy = GetSystemMetrics(SM_CYSMICON);
863 hMemDC = CreateCompatibleDC(hdc);
864 hBitmap = CreateCompatibleBitmap(hdc, cx, cy);
865 hOldBitmap = SelectObject(hMemDC, hBitmap);
866 SetMapMode(hMemDC, MM_TEXT);
867 hBrush = CreateSolidBrush(GetSysColor(COLOR_MENU));
868 DrawIconEx(hMemDC, 0, 0, hIcon, cx, cy, 0, hBrush, DI_NORMAL);
869 SelectObject (hMemDC, hOldBitmap);
870 DeleteObject(hBrush);
872 ReleaseDC(hChild, hdc);
873 hSysMenuBitmap = hBitmap;
877 if( !InsertMenuA(menu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
878 (UINT_PTR)hSysPopup, (LPSTR)hSysMenuBitmap))
880 TRACE("not inserted\n");
881 DestroyMenu(hSysPopup);
885 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
886 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
887 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
888 SetMenuDefaultItem(hSysPopup, SC_CLOSE, FALSE);
896 /**********************************************************************
897 * MDI_RestoreFrameMenu
899 static BOOL MDI_RestoreFrameMenu( HWND frame, HWND hChild )
901 MENUITEMINFOW menuInfo;
902 HMENU menu = GetMenu( frame );
903 INT nItems = GetMenuItemCount(menu) - 1;
904 UINT iId = GetMenuItemID(menu,nItems) ;
906 TRACE("frame %p,child %p,nIt=%d,iId=%d\n",frame,hChild,nItems,iId);
908 if( !menu ) return 0;
910 /* if there is no system buttons then nothing to do */
911 if(!(iId == SC_RESTORE || iId == SC_CLOSE) )
915 * Remove the system menu, If that menu is the icon of the window
916 * as it is in win95, we have to delete the bitmap.
918 memset(&menuInfo, 0, sizeof(menuInfo));
919 menuInfo.cbSize = sizeof(menuInfo);
920 menuInfo.fMask = MIIM_DATA | MIIM_TYPE;
922 GetMenuItemInfoW(menu,
927 RemoveMenu(menu,0,MF_BYPOSITION);
929 if ( (menuInfo.fType & MFT_BITMAP) &&
930 (LOWORD(menuInfo.dwTypeData)!=0) &&
931 (LOWORD(menuInfo.dwTypeData)!=HBITMAP_16(hBmpClose)) )
933 DeleteObject(HBITMAP_32(LOWORD(menuInfo.dwTypeData)));
937 DeleteMenu(menu, SC_CLOSE, MF_BYCOMMAND);
939 DeleteMenu(menu, SC_RESTORE, MF_BYCOMMAND);
941 DeleteMenu(menu, SC_MINIMIZE, MF_BYCOMMAND);
949 /**********************************************************************
950 * MDI_UpdateFrameText
952 * used when child window is maximized/restored
954 * Note: lpTitle can be NULL
956 static void MDI_UpdateFrameText( HWND frame, HWND hClient, LPCWSTR lpTitle )
958 WCHAR lpBuffer[MDI_MAXTITLELENGTH+1];
959 MDICLIENTINFO *ci = get_client_info( hClient );
961 TRACE("frameText %s\n", debugstr_w(lpTitle));
965 if (!lpTitle && !ci->frameTitle) /* first time around, get title from the frame window */
967 GetWindowTextW( frame, lpBuffer, sizeof(lpBuffer)/sizeof(WCHAR) );
971 /* store new "default" title if lpTitle is not NULL */
974 HeapFree( GetProcessHeap(), 0, ci->frameTitle );
975 if ((ci->frameTitle = HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle)+1)*sizeof(WCHAR))))
976 strcpyW( ci->frameTitle, lpTitle );
981 if (IsZoomed(ci->hwndActiveChild) && IsWindowVisible(ci->hwndActiveChild))
983 /* combine frame title and child title if possible */
985 static const WCHAR lpBracket[] = {' ','-',' ','[',0};
986 static const WCHAR lpBracket2[] = {']',0};
987 int i_frame_text_length = strlenW(ci->frameTitle);
989 lstrcpynW( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
991 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
993 strcatW( lpBuffer, lpBracket );
994 if (GetWindowTextW( ci->hwndActiveChild, lpBuffer + i_frame_text_length + 4,
995 MDI_MAXTITLELENGTH - i_frame_text_length - 5 ))
996 strcatW( lpBuffer, lpBracket2 );
998 lpBuffer[i_frame_text_length] = 0; /* remove bracket */
1003 lstrcpynW(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH+1 );
1009 DefWindowProcW( frame, WM_SETTEXT, 0, (LPARAM)lpBuffer );
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 );
1057 ci->nActiveChildren = 0;
1058 ci->nTotalCreated = 0;
1059 ci->frameTitle = NULL;
1061 ci->hFrameMenu = GetMenu(cs->hwndParent);
1063 if (!hBmpClose) hBmpClose = CreateMDIMenuBitmap();
1065 TRACE("Client created: hwnd %p, Window menu %p, idFirst = %04x\n",
1066 hwnd, ci->hWindowMenu, ci->idFirstChild );
1072 if( IsZoomed(ci->hwndActiveChild) )
1073 MDI_RestoreFrameMenu(GetParent(hwnd), ci->hwndActiveChild);
1075 ci->nActiveChildren = 0;
1076 MDI_RefreshMenu(ci);
1078 HeapFree( GetProcessHeap(), 0, ci->child );
1079 HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1084 case WM_MDIACTIVATE:
1086 MDI_SwitchActiveChild( ci, (HWND)wParam, TRUE );
1091 return MDICascade(hwnd, ci);
1100 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)lParam;
1101 child = CreateWindowExW(WS_EX_MDICHILD, csW->szClass,
1102 csW->szTitle, csW->style,
1103 csW->x, csW->y, csW->cx, csW->cy,
1104 hwnd, 0, csW->hOwner,
1105 (LPVOID)csW->lParam);
1109 MDICREATESTRUCTA *csA = (MDICREATESTRUCTA *)lParam;
1110 child = CreateWindowExA(WS_EX_MDICHILD, csA->szClass,
1111 csA->szTitle, csA->style,
1112 csA->x, csA->y, csA->cx, csA->cy,
1113 hwnd, 0, csA->hOwner,
1114 (LPVOID)csA->lParam);
1117 if (IsZoomed(ci->hwndActiveChild))
1119 MDI_AugmentFrameMenu(GetParent(hwnd), child);
1120 MDI_UpdateFrameText(GetParent(hwnd), hwnd, NULL);
1122 return (LRESULT)child;
1127 return MDIDestroyChild( hwnd, ci, WIN_GetFullHandle( (HWND)wParam ), TRUE );
1129 case WM_MDIGETACTIVE:
1130 if (lParam) *(BOOL *)lParam = IsZoomed(ci->hwndActiveChild);
1131 return (LRESULT)ci->hwndActiveChild;
1133 case WM_MDIICONARRANGE:
1134 ci->mdiFlags |= MDIF_NEEDUPDATE;
1135 ArrangeIconicWindows( hwnd );
1136 ci->sbRecalc = SB_BOTH+1;
1137 SendMessageW( hwnd, WM_MDICALCCHILDSCROLL, 0, 0 );
1140 case WM_MDIMAXIMIZE:
1141 ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1144 case WM_MDINEXT: /* lParam != 0 means previous window */
1146 HWND next = MDI_GetWindow( ci, WIN_GetFullHandle( (HWND)wParam ), !lParam, 0 );
1147 MDI_SwitchActiveChild( ci, next, TRUE );
1152 SendMessageW( (HWND)wParam, WM_SYSCOMMAND, SC_RESTORE, 0);
1156 return MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1158 case WM_MDIREFRESHMENU:
1159 return MDI_RefreshMenu( ci );
1162 ci->mdiFlags |= MDIF_NEEDUPDATE;
1163 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1164 MDITile( hwnd, ci, wParam );
1165 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1170 ci->mdiFlags |= MDIF_NEEDUPDATE;
1171 ScrollChildren( hwnd, message, wParam, lParam );
1172 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1176 if (ci->hwndActiveChild && !IsIconic( ci->hwndActiveChild ))
1177 SetFocus( ci->hwndActiveChild );
1181 if( ci->hwndActiveChild )
1182 SendMessageW(ci->hwndActiveChild, message, wParam, lParam);
1185 case WM_PARENTNOTIFY:
1186 switch (LOWORD(wParam))
1189 if (GetWindowLongW((HWND)lParam, GWL_EXSTYLE) & WS_EX_MDICHILD)
1191 ci->nTotalCreated++;
1192 ci->nActiveChildren++;
1195 ci->child = HeapAlloc(GetProcessHeap(), 0, sizeof(HWND));
1197 ci->child = HeapReAlloc(GetProcessHeap(), 0, ci->child, sizeof(HWND) * ci->nActiveChildren);
1199 TRACE("Adding MDI child %p, # of children %d\n",
1200 (HWND)lParam, ci->nActiveChildren);
1202 ci->child[ci->nActiveChildren - 1] = (HWND)lParam;
1206 case WM_LBUTTONDOWN:
1210 pt.x = (short)LOWORD(lParam);
1211 pt.y = (short)HIWORD(lParam);
1212 child = ChildWindowFromPoint(hwnd, pt);
1214 TRACE("notification from %p (%i,%i)\n",child,pt.x,pt.y);
1216 if( child && child != hwnd && child != ci->hwndActiveChild )
1217 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1224 if( IsWindow(ci->hwndActiveChild) && IsZoomed(ci->hwndActiveChild) &&
1225 (GetWindowLongW(ci->hwndActiveChild, GWL_STYLE) & WS_VISIBLE) )
1231 rect.right = LOWORD(lParam);
1232 rect.bottom = HIWORD(lParam);
1234 AdjustWindowRectEx(&rect, GetWindowLongA(ci->hwndActiveChild, GWL_STYLE),
1235 0, GetWindowLongA(ci->hwndActiveChild, GWL_EXSTYLE) );
1236 MoveWindow(ci->hwndActiveChild, rect.left, rect.top,
1237 rect.right - rect.left, rect.bottom - rect.top, 1);
1240 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1244 case WM_MDICALCCHILDSCROLL:
1245 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1247 CalcChildScroll(hwnd, ci->sbRecalc-1);
1249 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1253 return unicode ? DefWindowProcW( hwnd, message, wParam, lParam ) :
1254 DefWindowProcA( hwnd, message, wParam, lParam );
1257 /***********************************************************************
1260 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1262 if (!IsWindow(hwnd)) return 0;
1263 return MDIClientWndProc_common( hwnd, message, wParam, lParam, FALSE );
1266 /***********************************************************************
1269 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1271 if (!IsWindow(hwnd)) return 0;
1272 return MDIClientWndProc_common( hwnd, message, wParam, lParam, TRUE );
1275 /***********************************************************************
1276 * DefFrameProcA (USER32.@)
1278 LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1279 UINT message, WPARAM wParam, LPARAM lParam)
1287 DWORD len = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0 );
1288 LPWSTR text = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1289 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, text, len );
1290 MDI_UpdateFrameText( hwnd, hwndMDIClient, text );
1291 HeapFree( GetProcessHeap(), 0, text );
1293 return 1; /* success. FIXME: check text length */
1300 return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1303 return DefWindowProcA(hwnd, message, wParam, lParam);
1307 /***********************************************************************
1308 * DefFrameProcW (USER32.@)
1310 LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1311 UINT message, WPARAM wParam, LPARAM lParam)
1313 MDICLIENTINFO *ci = get_client_info( hwndMDIClient );
1315 TRACE("%p %p %04x (%s) %08x %08lx\n", hwnd, hwndMDIClient, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1323 WORD id = LOWORD(wParam);
1324 /* check for possible syscommands for maximized MDI child */
1325 if (id < ci->idFirstChild || id >= ci->idFirstChild + ci->nActiveChildren)
1327 if( (id - 0xf000) & 0xf00f ) break;
1328 if( !IsZoomed(ci->hwndActiveChild) ) break;
1332 if (!is_close_enabled(ci->hwndActiveChild, 0)) break;
1340 return SendMessageW( ci->hwndActiveChild, WM_SYSCOMMAND,
1347 if (id - ci->idFirstChild == MDI_MOREWINDOWSLIMIT)
1348 /* User chose "More Windows..." */
1349 childHwnd = MDI_MoreWindowsDialog(hwndMDIClient);
1351 /* User chose one of the windows listed in the "Windows" menu */
1352 childHwnd = MDI_GetChildByID(hwndMDIClient, id, ci);
1355 SendMessageW( hwndMDIClient, WM_MDIACTIVATE, (WPARAM)childHwnd, 0 );
1361 SendMessageW(hwndMDIClient, message, wParam, lParam);
1365 MDI_UpdateFrameText( hwnd, hwndMDIClient, (LPWSTR)lParam );
1366 return 1; /* success. FIXME: check text length */
1369 SetFocus(hwndMDIClient);
1373 MoveWindow(hwndMDIClient, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
1378 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1380 if (!IsIconic(hwnd) && ci->hwndActiveChild && !IsZoomed(ci->hwndActiveChild))
1382 /* control menu is between the frame system menu and
1383 * the first entry of menu bar */
1384 WND *wndPtr = WIN_GetPtr(hwnd);
1386 if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1387 (wParam == VK_RIGHT && GetSubMenu(wndPtr->hSysMenu, 0) == next_menu->hmenuIn) )
1389 WIN_ReleasePtr(wndPtr);
1390 wndPtr = WIN_GetPtr(ci->hwndActiveChild);
1391 next_menu->hmenuNext = GetSubMenu(wndPtr->hSysMenu, 0);
1392 next_menu->hwndNext = ci->hwndActiveChild;
1394 WIN_ReleasePtr(wndPtr);
1401 return DefWindowProcW( hwnd, message, wParam, lParam );
1404 /***********************************************************************
1405 * DefMDIChildProcA (USER32.@)
1407 LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1408 WPARAM wParam, LPARAM lParam )
1410 HWND client = GetParent(hwnd);
1411 MDICLIENTINFO *ci = get_client_info( client );
1413 TRACE("%p %04x (%s) %08x %08lx\n", hwnd, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1415 hwnd = WIN_GetFullHandle( hwnd );
1416 if (!ci) return DefWindowProcA( hwnd, message, wParam, lParam );
1421 DefWindowProcA(hwnd, message, wParam, lParam);
1422 if( ci->hwndActiveChild == hwnd && IsZoomed(ci->hwndActiveChild) )
1423 MDI_UpdateFrameText( GetParent(client), client, NULL );
1424 return 1; /* success. FIXME: check text length */
1426 case WM_GETMINMAXINFO:
1430 case WM_CHILDACTIVATE:
1438 return DefMDIChildProcW( hwnd, message, wParam, lParam );
1440 return DefWindowProcA(hwnd, message, wParam, lParam);
1444 /***********************************************************************
1445 * DefMDIChildProcW (USER32.@)
1447 LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1448 WPARAM wParam, LPARAM lParam )
1450 HWND client = GetParent(hwnd);
1451 MDICLIENTINFO *ci = get_client_info( client );
1453 TRACE("%p %04x (%s) %08x %08lx\n", hwnd, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1455 hwnd = WIN_GetFullHandle( hwnd );
1456 if (!ci) return DefWindowProcW( hwnd, message, wParam, lParam );
1461 DefWindowProcW(hwnd, message, wParam, lParam);
1462 if( ci->hwndActiveChild == hwnd && IsZoomed(ci->hwndActiveChild) )
1463 MDI_UpdateFrameText( GetParent(client), client, NULL );
1464 return 1; /* success. FIXME: check text length */
1466 case WM_GETMINMAXINFO:
1467 MDI_ChildGetMinMaxInfo( client, hwnd, (MINMAXINFO *)lParam );
1471 return 0x00010000; /* MDI children don't have menu bars */
1474 SendMessageW( client, WM_MDIDESTROY, (WPARAM)hwnd, 0 );
1477 case WM_CHILDACTIVATE:
1478 MDI_ChildActivate( client, hwnd );
1485 if( ci->hwndActiveChild == hwnd && IsZoomed(ci->hwndActiveChild))
1492 if (ci->hwndActiveChild == hwnd && IsZoomed(ci->hwndActiveChild))
1493 return SendMessageW( GetParent(client), message, wParam, lParam);
1496 SendMessageW( client, WM_MDINEXT, 0, 0);
1499 SendMessageW( client, WM_MDINEXT, 0, 1);
1506 if (IsZoomed(ci->hwndActiveChild)) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1507 else MDI_PostUpdate(client, ci, SB_BOTH+1);
1511 if( hwnd == ci->hwndActiveChild )
1513 if( wParam == SIZE_MAXIMIZED )
1515 TRACE("maximizing child %p\n", hwnd );
1517 MDI_AugmentFrameMenu( GetParent(client), hwnd );
1520 MDI_RestoreFrameMenu( GetParent(client), hwnd );
1523 MDI_UpdateFrameText( GetParent(client), client, NULL );
1524 MDI_RefreshMenu(ci);
1525 MDI_PostUpdate(client, ci, SB_BOTH+1);
1530 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1531 HWND parent = GetParent(client);
1533 if( wParam == VK_LEFT ) /* switch to frame system menu */
1535 WND *wndPtr = WIN_GetPtr( parent );
1536 next_menu->hmenuNext = GetSubMenu( wndPtr->hSysMenu, 0 );
1537 WIN_ReleasePtr( wndPtr );
1539 if( wParam == VK_RIGHT ) /* to frame menu bar */
1541 next_menu->hmenuNext = GetMenu(parent);
1543 next_menu->hwndNext = parent;
1550 SendMessageW( hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (DWORD)VK_SPACE);
1556 /* Remove itself from the Window menu */
1557 MDI_RefreshMenu(ci);
1560 return DefWindowProcW(hwnd, message, wParam, lParam);
1563 /**********************************************************************
1564 * CreateMDIWindowA (USER32.@) Creates a MDI child
1567 * Success: Handle to created window
1570 HWND WINAPI CreateMDIWindowA(
1571 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1572 LPCSTR lpWindowName, /* [in] Pointer to window name */
1573 DWORD dwStyle, /* [in] Window style */
1574 INT X, /* [in] Horizontal position of window */
1575 INT Y, /* [in] Vertical position of window */
1576 INT nWidth, /* [in] Width of window */
1577 INT nHeight, /* [in] Height of window */
1578 HWND hWndParent, /* [in] Handle to parent window */
1579 HINSTANCE hInstance, /* [in] Handle to application instance */
1580 LPARAM lParam) /* [in] Application-defined value */
1582 TRACE("(%s,%s,%08x,%d,%d,%d,%d,%p,%p,%08lx)\n",
1583 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1584 nWidth,nHeight,hWndParent,hInstance,lParam);
1586 return CreateWindowExA(WS_EX_MDICHILD, lpClassName, lpWindowName,
1587 dwStyle, X, Y, nWidth, nHeight, hWndParent,
1588 0, hInstance, (LPVOID)lParam);
1591 /***********************************************************************
1592 * CreateMDIWindowW (USER32.@) Creates a MDI child
1595 * Success: Handle to created window
1598 HWND WINAPI CreateMDIWindowW(
1599 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1600 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1601 DWORD dwStyle, /* [in] Window style */
1602 INT X, /* [in] Horizontal position of window */
1603 INT Y, /* [in] Vertical position of window */
1604 INT nWidth, /* [in] Width of window */
1605 INT nHeight, /* [in] Height of window */
1606 HWND hWndParent, /* [in] Handle to parent window */
1607 HINSTANCE hInstance, /* [in] Handle to application instance */
1608 LPARAM lParam) /* [in] Application-defined value */
1610 TRACE("(%s,%s,%08x,%d,%d,%d,%d,%p,%p,%08lx)\n",
1611 debugstr_w(lpClassName), debugstr_w(lpWindowName), dwStyle, X, Y,
1612 nWidth, nHeight, hWndParent, hInstance, lParam);
1614 return CreateWindowExW(WS_EX_MDICHILD, lpClassName, lpWindowName,
1615 dwStyle, X, Y, nWidth, nHeight, hWndParent,
1616 0, hInstance, (LPVOID)lParam);
1619 /**********************************************************************
1620 * TranslateMDISysAccel (USER32.@)
1622 BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1624 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1626 MDICLIENTINFO *ci = get_client_info( hwndClient );
1629 if (!ci || !IsWindowEnabled(ci->hwndActiveChild)) return 0;
1631 /* translate if the Ctrl key is down and Alt not. */
1633 if( (GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
1635 switch( msg->wParam )
1639 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 ) ? SC_NEXTWINDOW : SC_PREVWINDOW;
1643 if (is_close_enabled(ci->hwndActiveChild, 0))
1652 TRACE("wParam = %04x\n", wParam);
1653 SendMessageW(ci->hwndActiveChild, WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
1657 return 0; /* failure */
1660 /***********************************************************************
1661 * CalcChildScroll (USER32.@)
1663 void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
1666 RECT childRect, clientRect;
1669 GetClientRect( hwnd, &clientRect );
1670 SetRectEmpty( &childRect );
1672 if ((list = WIN_ListChildren( hwnd )))
1675 for (i = 0; list[i]; i++)
1677 DWORD style = GetWindowLongW( list[i], GWL_STYLE );
1678 if (style & WS_MAXIMIZE)
1680 HeapFree( GetProcessHeap(), 0, list );
1681 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1684 if (style & WS_VISIBLE)
1687 GetWindowRect( list[i], &rect );
1688 UnionRect( &childRect, &rect, &childRect );
1691 HeapFree( GetProcessHeap(), 0, list );
1693 MapWindowPoints( 0, hwnd, (POINT *)&childRect, 2 );
1694 UnionRect( &childRect, &clientRect, &childRect );
1696 /* set common info values */
1697 info.cbSize = sizeof(info);
1698 info.fMask = SIF_POS | SIF_RANGE;
1700 /* set the specific */
1705 info.nMin = childRect.left;
1706 info.nMax = childRect.right - clientRect.right;
1707 info.nPos = clientRect.left - childRect.left;
1708 SetScrollInfo(hwnd, SB_HORZ, &info, TRUE);
1709 if (scroll == SB_HORZ) break;
1712 info.nMin = childRect.top;
1713 info.nMax = childRect.bottom - clientRect.bottom;
1714 info.nPos = clientRect.top - childRect.top;
1715 SetScrollInfo(hwnd, SB_VERT, &info, TRUE);
1721 /***********************************************************************
1722 * ScrollChildren (USER32.@)
1724 void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
1728 INT curPos, length, minPos, maxPos, shift;
1731 GetClientRect( hWnd, &rect );
1736 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
1737 curPos = GetScrollPos(hWnd,SB_HORZ);
1738 length = (rect.right - rect.left) / 2;
1739 shift = GetSystemMetrics(SM_CYHSCROLL);
1742 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
1743 curPos = GetScrollPos(hWnd,SB_VERT);
1744 length = (rect.bottom - rect.top) / 2;
1745 shift = GetSystemMetrics(SM_CXVSCROLL);
1754 newPos = curPos - shift;
1757 newPos = curPos + shift;
1760 newPos = curPos - length;
1763 newPos = curPos + length;
1766 case SB_THUMBPOSITION:
1767 newPos = LOWORD(lParam);
1780 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
1784 if( newPos > maxPos )
1787 if( newPos < minPos )
1790 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
1792 if( uMsg == WM_VSCROLL )
1793 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
1794 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
1796 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
1797 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
1801 /******************************************************************************
1802 * CascadeWindows (USER32.@) Cascades MDI child windows
1805 * Success: Number of cascaded windows.
1809 CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
1810 UINT cKids, const HWND *lpKids)
1812 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
1817 /******************************************************************************
1818 * TileWindows (USER32.@) Tiles MDI child windows
1821 * Success: Number of tiled windows.
1825 TileWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
1826 UINT cKids, const HWND *lpKids)
1828 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
1832 /************************************************************************
1833 * "More Windows..." functionality
1836 /* MDI_MoreWindowsDlgProc
1838 * This function will process the messages sent to the "More Windows..."
1840 * Return values: 0 = cancel pressed
1841 * HWND = ok pressed or double-click in the list...
1845 static INT_PTR WINAPI MDI_MoreWindowsDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
1854 MDICLIENTINFO *ci = get_client_info( (HWND)lParam );
1855 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
1857 for (i = 0; i < ci->nActiveChildren; i++)
1859 WCHAR buffer[MDI_MAXTITLELENGTH];
1861 if (!InternalGetWindowText( ci->child[i], buffer, sizeof(buffer)/sizeof(WCHAR) ))
1863 SendMessageW(hListBox, LB_ADDSTRING, 0, (LPARAM)buffer );
1864 SendMessageW(hListBox, LB_SETITEMDATA, i, (LPARAM)ci->child[i] );
1865 length = strlenW(buffer); /* FIXME: should use GetTextExtentPoint */
1866 if (length > widest)
1869 /* Make sure the horizontal scrollbar scrolls ok */
1870 SendMessageW(hListBox, LB_SETHORIZONTALEXTENT, widest * 6, 0);
1872 /* Set the current selection */
1873 SendMessageW(hListBox, LB_SETCURSEL, MDI_MOREWINDOWSLIMIT, 0);
1878 switch (LOWORD(wParam))
1881 if (HIWORD(wParam) != LBN_DBLCLK) break;
1885 /* windows are sorted by menu ID, so we must return the
1886 * window associated to the given id
1888 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
1889 UINT index = SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
1890 LRESULT res = SendMessageW(hListBox, LB_GETITEMDATA, index, 0);
1891 EndDialog(hDlg, res);
1905 * MDI_MoreWindowsDialog
1907 * Prompts the user with a listbox containing the opened
1908 * documents. The user can then choose a windows and click
1909 * on OK to set the current window to the one selected, or
1910 * CANCEL to cancel. The function returns a handle to the
1914 static HWND MDI_MoreWindowsDialog(HWND hwnd)
1920 hRes = FindResourceA(user32_module, "MDI_MOREWINDOWS", (LPSTR)RT_DIALOG);
1925 hDlgTmpl = LoadResource(user32_module, hRes );
1930 template = LockResource( hDlgTmpl );
1935 return (HWND) DialogBoxIndirectParamA(user32_module,
1936 (const DLGTEMPLATE*) template,
1937 hwnd, MDI_MoreWindowsDlgProc, (LPARAM) hwnd);