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"
98 #include "user_private.h"
99 #include "wine/debug.h"
102 WINE_DEFAULT_DEBUG_CHANNEL(mdi);
104 #define MDI_MAXTITLELENGTH 0xa1
106 #define WM_MDICALCCHILDSCROLL 0x10ac /* this is exactly what Windows uses */
108 /* "More Windows..." definitions */
109 #define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
110 option will appear under the Windows menu */
111 #define MDI_IDC_LISTBOX 100
112 #define IDS_MDI_MOREWINDOWS 13
114 #define MDIF_NEEDUPDATE 0x0001
118 UINT nActiveChildren;
119 HWND hwndActiveChild;
120 HWND *child; /* array of tracked children */
127 UINT sbRecalc; /* SB_xxx flags for scrollbar fixup */
130 static HBITMAP hBmpClose = 0;
132 /* ----------------- declarations ----------------- */
133 static void MDI_UpdateFrameText( HWND, HWND, LPCWSTR);
134 static BOOL MDI_AugmentFrameMenu( HWND, HWND );
135 static BOOL MDI_RestoreFrameMenu( HWND, HWND );
136 static LONG MDI_ChildActivate( HWND, HWND );
137 static LRESULT MDI_RefreshMenu(MDICLIENTINFO *);
139 static HWND MDI_MoreWindowsDialog(HWND);
140 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
141 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
143 /* -------- Miscellaneous service functions ----------
147 static HWND MDI_GetChildByID(HWND hwnd, UINT id, MDICLIENTINFO *ci)
151 for (i = 0; ci->nActiveChildren; i++)
153 if (GetWindowLongPtrW( ci->child[i], GWLP_ID ) == id)
159 static void MDI_PostUpdate(HWND hwnd, MDICLIENTINFO* ci, WORD recalc)
161 if( !(ci->mdiFlags & MDIF_NEEDUPDATE) )
163 ci->mdiFlags |= MDIF_NEEDUPDATE;
164 PostMessageA( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
166 ci->sbRecalc = recalc;
170 /*********************************************************************
171 * MDIClient class descriptor
173 const struct builtin_class_descr MDICLIENT_builtin_class =
175 "MDIClient", /* name */
177 MDIClientWndProcA, /* procA */
178 MDIClientWndProcW, /* procW */
179 sizeof(MDICLIENTINFO), /* extra */
180 IDC_ARROW, /* cursor */
181 (HBRUSH)(COLOR_APPWORKSPACE+1) /* brush */
185 static MDICLIENTINFO *get_client_info( HWND client )
187 MDICLIENTINFO *ret = NULL;
188 WND *win = WIN_GetPtr( client );
191 if (win == WND_OTHER_PROCESS)
193 if (IsWindow(client)) ERR( "client %p belongs to other process\n", client );
196 if (win->cbWndExtra < sizeof(MDICLIENTINFO)) WARN( "%p is not an MDI client\n", client );
197 else ret = (MDICLIENTINFO *)win->wExtra;
198 WIN_ReleasePtr( win );
203 static BOOL is_close_enabled(HWND hwnd, HMENU hSysMenu)
205 if (GetClassLongW(hwnd, GCL_STYLE) & CS_NOCLOSE) return FALSE;
207 if (!hSysMenu) hSysMenu = GetSystemMenu(hwnd, FALSE);
210 UINT state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
211 if (state == 0xFFFFFFFF || (state & (MF_DISABLED | MF_GRAYED)))
217 /**********************************************************************
220 * returns "activateable" child different from the current or zero
222 static HWND MDI_GetWindow(MDICLIENTINFO *clientInfo, HWND hWnd, BOOL bNext,
229 dwStyleMask |= WS_DISABLED | WS_VISIBLE;
230 if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
232 if (!(list = WIN_ListChildren( GetParent(hWnd) ))) return 0;
234 /* start from next after hWnd */
235 while (list[i] && list[i] != hWnd) i++;
238 for ( ; list[i]; i++)
240 if (GetWindow( list[i], GW_OWNER )) continue;
241 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
243 if (bNext) goto found;
245 /* now restart from the beginning */
246 for (i = 0; list[i] && list[i] != hWnd; i++)
248 if (GetWindow( list[i], GW_OWNER )) continue;
249 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
251 if (bNext) goto found;
254 HeapFree( GetProcessHeap(), 0, list );
258 /**********************************************************************
259 * MDI_CalcDefaultChildPos
261 * It seems that the default height is about 2/3 of the client rect
263 void MDI_CalcDefaultChildPos( HWND hwndClient, INT total, LPPOINT lpPos, INT delta, UINT *id )
267 INT spacing = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME) - 1;
269 if (total < 0) /* we are called from CreateWindow */
271 MDICLIENTINFO *ci = get_client_info(hwndClient);
272 total = ci ? ci->nTotalCreated : 0;
273 *id = ci->idFirstChild + ci->nActiveChildren;
274 TRACE("MDI child id %04x\n", *id);
277 GetClientRect( hwndClient, &rect );
278 if( rect.bottom - rect.top - delta >= spacing )
279 rect.bottom -= delta;
281 nstagger = (rect.bottom - rect.top)/(3 * spacing);
282 lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
283 lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
284 lpPos[0].x = lpPos[0].y = spacing * (total%(nstagger+1));
287 /**********************************************************************
290 static LRESULT MDISetMenu( HWND hwnd, HMENU hmenuFrame,
294 HWND hwndFrame = GetParent(hwnd);
296 TRACE("%p %p %p\n", hwnd, hmenuFrame, hmenuWindow);
298 if (hmenuFrame && !IsMenu(hmenuFrame))
300 WARN("hmenuFrame is not a menu handle\n");
304 if (hmenuWindow && !IsMenu(hmenuWindow))
306 WARN("hmenuWindow is not a menu handle\n");
310 if (!(ci = get_client_info( hwnd ))) return 0;
314 if (hmenuFrame == ci->hFrameMenu) return (LRESULT)hmenuFrame;
316 if (IsZoomed(ci->hwndActiveChild))
317 MDI_RestoreFrameMenu( hwndFrame, ci->hwndActiveChild );
320 if( hmenuWindow && hmenuWindow != ci->hWindowMenu )
322 /* delete menu items from ci->hWindowMenu
323 * and add them to hmenuWindow */
324 /* Agent newsreader calls this function with ci->hWindowMenu == NULL */
325 if( ci->hWindowMenu && ci->nActiveChildren )
327 UINT nActiveChildren_old = ci->nActiveChildren;
329 /* Remove all items from old Window menu */
330 ci->nActiveChildren = 0;
333 ci->hWindowMenu = hmenuWindow;
335 /* Add items to the new Window menu */
336 ci->nActiveChildren = nActiveChildren_old;
340 ci->hWindowMenu = hmenuWindow;
345 SetMenu(hwndFrame, hmenuFrame);
346 if( hmenuFrame != ci->hFrameMenu )
348 HMENU oldFrameMenu = ci->hFrameMenu;
350 ci->hFrameMenu = hmenuFrame;
351 if (IsZoomed(ci->hwndActiveChild) && (GetWindowLongW(ci->hwndActiveChild, GWL_STYLE) & WS_VISIBLE))
352 MDI_AugmentFrameMenu( hwndFrame, ci->hwndActiveChild );
354 return (LRESULT)oldFrameMenu;
359 /* SetMenu() may already have been called, meaning that this window
360 * already has its menu. But they may have done a SetMenu() on
361 * an MDI window, and called MDISetMenu() after the fact, meaning
362 * that the "if" to this "else" wouldn't catch the need to
363 * augment the frame menu.
365 if( IsZoomed(ci->hwndActiveChild) )
366 MDI_AugmentFrameMenu( hwndFrame, ci->hwndActiveChild );
372 /**********************************************************************
375 static LRESULT MDI_RefreshMenu(MDICLIENTINFO *ci)
377 UINT i, count, visible, id;
378 WCHAR buf[MDI_MAXTITLELENGTH];
380 TRACE("children %u, window menu %p\n", ci->nActiveChildren, ci->hWindowMenu);
382 if (!ci->hWindowMenu)
385 if (!IsMenu(ci->hWindowMenu))
387 WARN("Window menu handle %p is no more valid\n", ci->hWindowMenu);
391 /* Windows finds the last separator in the menu, and if after it
392 * there is a menu item with MDI magic ID removes all existing
393 * menu items after it, and then adds visible MDI children.
395 count = GetMenuItemCount(ci->hWindowMenu);
396 for (i = 0; i < count; i++)
400 memset(&mii, 0, sizeof(mii));
401 mii.cbSize = sizeof(mii);
402 mii.fMask = MIIM_TYPE;
403 if (GetMenuItemInfoW(ci->hWindowMenu, i, TRUE, &mii))
405 if (mii.fType & MF_SEPARATOR)
407 /* Windows checks only ID of the menu item */
408 memset(&mii, 0, sizeof(mii));
409 mii.cbSize = sizeof(mii);
411 if (GetMenuItemInfoW(ci->hWindowMenu, i + 1, TRUE, &mii))
413 if (mii.wID == ci->idFirstChild)
415 TRACE("removing %u items including separator\n", count - i);
416 while (RemoveMenu(ci->hWindowMenu, i, MF_BYPOSITION))
427 for (i = 0; i < ci->nActiveChildren; i++)
429 if (GetWindowLongW(ci->child[i], GWL_STYLE) & WS_VISIBLE)
431 id = ci->idFirstChild + visible;
433 if (visible == MDI_MOREWINDOWSLIMIT)
435 LoadStringW(user32_module, IDS_MDI_MOREWINDOWS, buf, sizeof(buf)/sizeof(WCHAR));
436 AppendMenuW(ci->hWindowMenu, MF_STRING, id, buf);
441 /* Visio expects that separator has id 0 */
442 AppendMenuW(ci->hWindowMenu, MF_SEPARATOR, 0, NULL);
446 SetWindowLongPtrW(ci->child[i], GWLP_ID, id);
449 buf[1] = '0' + visible;
451 InternalGetWindowText(ci->child[i], buf + 3, sizeof(buf)/sizeof(WCHAR) - 3);
452 TRACE("Adding %p, id %u %s\n", ci->child[i], id, debugstr_w(buf));
453 AppendMenuW(ci->hWindowMenu, MF_STRING, id, buf);
455 if (ci->child[i] == ci->hwndActiveChild)
456 CheckMenuItem(ci->hWindowMenu, id, MF_CHECKED);
459 TRACE("MDI child %p is not visible, skipping\n", ci->child[i]);
462 return (LRESULT)ci->hFrameMenu;
466 /* ------------------ MDI child window functions ---------------------- */
468 /**********************************************************************
469 * MDI_ChildGetMinMaxInfo
471 * Note: The rule here is that client rect of the maximized MDI child
472 * is equal to the client rect of the MDI client window.
474 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
478 GetClientRect( client, &rect );
479 AdjustWindowRectEx( &rect, GetWindowLongW( hwnd, GWL_STYLE ),
480 0, GetWindowLongW( hwnd, GWL_EXSTYLE ));
482 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
483 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
485 lpMinMax->ptMaxPosition.x = rect.left;
486 lpMinMax->ptMaxPosition.y = rect.top;
488 TRACE("max rect (%ld,%ld - %ld, %ld)\n",
489 rect.left,rect.top,rect.right,rect.bottom);
492 /**********************************************************************
493 * MDI_SwitchActiveChild
495 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
498 static void MDI_SwitchActiveChild( MDICLIENTINFO *ci, HWND hwndTo, BOOL activate )
502 hwndPrev = ci->hwndActiveChild;
504 TRACE("from %p, to %p\n", hwndPrev, hwndTo);
506 if ( hwndTo != hwndPrev )
508 BOOL was_zoomed = IsZoomed(hwndPrev);
512 /* restore old MDI child */
513 SendMessageW( hwndPrev, WM_SETREDRAW, FALSE, 0 );
514 ShowWindow( hwndPrev, SW_RESTORE );
515 SendMessageW( hwndPrev, WM_SETREDRAW, TRUE, 0 );
517 /* activate new MDI child */
518 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
519 /* maximize new MDI child */
520 ShowWindow( hwndTo, SW_MAXIMIZE );
522 /* activate new MDI child */
523 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | (activate ? 0 : SWP_NOACTIVATE) );
528 /**********************************************************************
531 static LRESULT MDIDestroyChild( HWND client, MDICLIENTINFO *ci,
532 HWND child, BOOL flagDestroy )
536 TRACE("# of managed children %u\n", ci->nActiveChildren);
538 if( child == ci->hwndActiveChild )
540 HWND next = MDI_GetWindow(ci, child, TRUE, 0);
542 MDI_SwitchActiveChild(ci, next, TRUE);
545 ShowWindow(child, SW_HIDE);
548 MDI_RestoreFrameMenu(GetParent(client), child);
549 MDI_UpdateFrameText(GetParent(client), client, NULL);
551 MDI_ChildActivate(client, 0);
555 for (i = 0; i < ci->nActiveChildren; i++)
557 if (ci->child[i] == child)
559 HWND *new_child = HeapAlloc(GetProcessHeap(), 0, (ci->nActiveChildren - 1) * sizeof(HWND));
560 memcpy(new_child, ci->child, i * sizeof(HWND));
561 if (i + 1 < ci->nActiveChildren)
562 memcpy(new_child + i, ci->child + i + 1, (ci->nActiveChildren - i - 1) * sizeof(HWND));
563 HeapFree(GetProcessHeap(), 0, ci->child);
564 ci->child = new_child;
566 ci->nActiveChildren--;
571 SendMessageW(client, WM_MDIREFRESHMENU, 0, 0);
575 MDI_PostUpdate(GetParent(child), ci, SB_BOTH+1);
576 DestroyWindow(child);
579 TRACE("child destroyed - %p\n", child);
584 /**********************************************************************
587 * Called in response to WM_CHILDACTIVATE, or when last MDI child
588 * is being deactivated.
590 static LONG MDI_ChildActivate( HWND client, HWND child )
592 MDICLIENTINFO *clientInfo;
593 HWND prevActiveWnd, frame;
594 BOOL isActiveFrameWnd;
596 clientInfo = get_client_info( client );
598 if (clientInfo->hwndActiveChild == child) return 0;
600 TRACE("%p\n", child);
602 frame = GetParent(client);
603 isActiveFrameWnd = (GetActiveWindow() == frame);
604 prevActiveWnd = clientInfo->hwndActiveChild;
606 /* deactivate prev. active child */
609 SendMessageW( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
610 SendMessageW( prevActiveWnd, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child);
613 MDI_SwitchActiveChild( clientInfo, child, FALSE );
614 clientInfo->hwndActiveChild = child;
616 MDI_RefreshMenu(clientInfo);
618 if( isActiveFrameWnd )
620 SendMessageW( child, WM_NCACTIVATE, TRUE, 0L);
624 SendMessageW( child, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child );
628 /* -------------------- MDI client window functions ------------------- */
630 /**********************************************************************
631 * CreateMDIMenuBitmap
633 static HBITMAP CreateMDIMenuBitmap(void)
635 HDC hDCSrc = CreateCompatibleDC(0);
636 HDC hDCDest = CreateCompatibleDC(hDCSrc);
637 HBITMAP hbClose = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_OLD_CLOSE) );
639 HBITMAP hobjSrc, hobjDest;
641 hobjSrc = SelectObject(hDCSrc, hbClose);
642 hbCopy = CreateCompatibleBitmap(hDCSrc,GetSystemMetrics(SM_CXSIZE),GetSystemMetrics(SM_CYSIZE));
643 hobjDest = SelectObject(hDCDest, hbCopy);
645 BitBlt(hDCDest, 0, 0, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE),
646 hDCSrc, GetSystemMetrics(SM_CXSIZE), 0, SRCCOPY);
648 SelectObject(hDCSrc, hobjSrc);
649 DeleteObject(hbClose);
652 hobjSrc = SelectObject( hDCDest, GetStockObject(BLACK_PEN) );
654 MoveToEx( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, 0, NULL );
655 LineTo( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, GetSystemMetrics(SM_CYSIZE) - 1);
657 SelectObject(hDCDest, hobjSrc );
658 SelectObject(hDCDest, hobjDest);
664 /**********************************************************************
667 static LONG MDICascade( HWND client, MDICLIENTINFO *ci )
670 BOOL has_icons = FALSE;
673 if (IsZoomed(ci->hwndActiveChild))
674 SendMessageA(client, WM_MDIRESTORE, (WPARAM)ci->hwndActiveChild, 0);
676 if (ci->nActiveChildren == 0) return 0;
678 if (!(win_array = WIN_ListChildren( client ))) return 0;
680 /* remove all the windows we don't want */
681 for (i = total = 0; win_array[i]; i++)
683 if (!IsWindowVisible( win_array[i] )) continue;
684 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows */
685 if (IsIconic( win_array[i] ))
690 win_array[total++] = win_array[i];
692 win_array[total] = 0;
696 INT delta = 0, n = 0, i;
698 if (has_icons) delta = GetSystemMetrics(SM_CYICONSPACING) + GetSystemMetrics(SM_CYICON);
700 /* walk the list (backwards) and move windows */
701 for (i = total - 1; i >= 0; i--)
703 TRACE("move %p to (%ld,%ld) size [%ld,%ld]\n",
704 win_array[i], pos[0].x, pos[0].y, pos[1].x, pos[1].y);
706 MDI_CalcDefaultChildPos(client, n++, pos, delta, NULL);
707 SetWindowPos( win_array[i], 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
708 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
711 HeapFree( GetProcessHeap(), 0, win_array );
713 if (has_icons) ArrangeIconicWindows( client );
717 /**********************************************************************
720 static void MDITile( HWND client, MDICLIENTINFO *ci, WPARAM wParam )
724 BOOL has_icons = FALSE;
726 if (IsZoomed(ci->hwndActiveChild))
727 SendMessageA(client, WM_MDIRESTORE, (WPARAM)ci->hwndActiveChild, 0);
729 if (ci->nActiveChildren == 0) return;
731 if (!(win_array = WIN_ListChildren( client ))) return;
733 /* remove all the windows we don't want */
734 for (i = total = 0; win_array[i]; i++)
736 if (!IsWindowVisible( win_array[i] )) continue;
737 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows (icon titles) */
738 if (IsIconic( win_array[i] ))
743 if ((wParam & MDITILE_SKIPDISABLED) && !IsWindowEnabled( win_array[i] )) continue;
744 win_array[total++] = win_array[i];
746 win_array[total] = 0;
748 TRACE("%u windows to tile\n", total);
752 HWND *pWnd = win_array;
754 int x, y, xsize, ysize;
755 int rows, columns, r, c, i;
757 GetClientRect(client,&rect);
758 rows = (int) sqrt((double)total);
759 columns = total / rows;
761 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
764 rows = columns; /* exchange r and c */
770 y = rect.bottom - 2 * GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
771 rect.bottom = ( y - GetSystemMetrics(SM_CYICON) < rect.top )? rect.bottom: y;
774 ysize = rect.bottom / rows;
775 xsize = rect.right / columns;
777 for (x = i = 0, c = 1; c <= columns && *pWnd; c++)
782 ysize = rect.bottom / rows;
786 for (r = 1; r <= rows && *pWnd; r++, i++)
788 SetWindowPos(*pWnd, 0, x, y, xsize, ysize,
789 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
796 HeapFree( GetProcessHeap(), 0, win_array );
797 if (has_icons) ArrangeIconicWindows( client );
800 /* ----------------------- Frame window ---------------------------- */
803 /**********************************************************************
804 * MDI_AugmentFrameMenu
806 static BOOL MDI_AugmentFrameMenu( HWND frame, HWND hChild )
808 HMENU menu = GetMenu( frame );
810 HBITMAP hSysMenuBitmap = 0;
815 TRACE("frame %p,child %p\n",frame,hChild);
817 if( !menu ) return 0;
819 /* if the system buttons already exist do not add them again */
820 nItems = GetMenuItemCount(menu) - 1;
821 iId = GetMenuItemID(menu,nItems) ;
822 if (iId == SC_RESTORE || iId == SC_CLOSE)
825 /* create a copy of sysmenu popup and insert it into frame menu bar */
826 if (!(hSysPopup = GetSystemMenu(hChild, FALSE)))
829 AppendMenuW(menu, MF_HELP | MF_BITMAP,
830 SC_MINIMIZE, (LPCWSTR)HBMMENU_MBAR_MINIMIZE ) ;
831 AppendMenuW(menu, MF_HELP | MF_BITMAP,
832 SC_RESTORE, (LPCWSTR)HBMMENU_MBAR_RESTORE );
833 AppendMenuW(menu, MF_HELP | MF_BITMAP,
834 SC_CLOSE, is_close_enabled(hChild, hSysPopup) ?
835 (LPCWSTR)HBMMENU_MBAR_CLOSE : (LPCWSTR)HBMMENU_MBAR_CLOSE_D );
837 /* The system menu is replaced by the child icon */
838 hIcon = (HICON)GetClassLongPtrW(hChild, GCLP_HICONSM);
840 hIcon = (HICON)GetClassLongPtrW(hChild, GCLP_HICON);
842 hIcon = LoadImageW(0, MAKEINTRESOURCEW(IDI_WINLOGO), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
846 HBITMAP hBitmap, hOldBitmap;
848 HDC hdc = GetDC(hChild);
853 cx = GetSystemMetrics(SM_CXSMICON);
854 cy = GetSystemMetrics(SM_CYSMICON);
855 hMemDC = CreateCompatibleDC(hdc);
856 hBitmap = CreateCompatibleBitmap(hdc, cx, cy);
857 hOldBitmap = SelectObject(hMemDC, hBitmap);
858 SetMapMode(hMemDC, MM_TEXT);
859 hBrush = CreateSolidBrush(GetSysColor(COLOR_MENU));
860 DrawIconEx(hMemDC, 0, 0, hIcon, cx, cy, 0, hBrush, DI_NORMAL);
861 SelectObject (hMemDC, hOldBitmap);
862 DeleteObject(hBrush);
864 ReleaseDC(hChild, hdc);
865 hSysMenuBitmap = hBitmap;
869 if( !InsertMenuA(menu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
870 (UINT_PTR)hSysPopup, (LPSTR)hSysMenuBitmap))
872 TRACE("not inserted\n");
873 DestroyMenu(hSysPopup);
877 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
878 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
879 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
880 SetMenuDefaultItem(hSysPopup, SC_CLOSE, FALSE);
888 /**********************************************************************
889 * MDI_RestoreFrameMenu
891 static BOOL MDI_RestoreFrameMenu( HWND frame, HWND hChild )
893 MENUITEMINFOW menuInfo;
894 HMENU menu = GetMenu( frame );
895 INT nItems = GetMenuItemCount(menu) - 1;
896 UINT iId = GetMenuItemID(menu,nItems) ;
898 TRACE("frame %p,child %p,nIt=%d,iId=%d\n",frame,hChild,nItems,iId);
900 if( !menu ) return 0;
902 /* if there is no system buttons then nothing to do */
903 if(!(iId == SC_RESTORE || iId == SC_CLOSE) )
907 * Remove the system menu, If that menu is the icon of the window
908 * as it is in win95, we have to delete the bitmap.
910 memset(&menuInfo, 0, sizeof(menuInfo));
911 menuInfo.cbSize = sizeof(menuInfo);
912 menuInfo.fMask = MIIM_DATA | MIIM_TYPE;
914 GetMenuItemInfoW(menu,
919 RemoveMenu(menu,0,MF_BYPOSITION);
921 if ( (menuInfo.fType & MFT_BITMAP) &&
922 (LOWORD(menuInfo.dwTypeData)!=0) &&
923 (LOWORD(menuInfo.dwTypeData)!=HBITMAP_16(hBmpClose)) )
925 DeleteObject(HBITMAP_32(LOWORD(menuInfo.dwTypeData)));
929 DeleteMenu(menu, SC_CLOSE, MF_BYCOMMAND);
931 DeleteMenu(menu, SC_RESTORE, MF_BYCOMMAND);
933 DeleteMenu(menu, SC_MINIMIZE, MF_BYCOMMAND);
941 /**********************************************************************
942 * MDI_UpdateFrameText
944 * used when child window is maximized/restored
946 * Note: lpTitle can be NULL
948 static void MDI_UpdateFrameText( HWND frame, HWND hClient, LPCWSTR lpTitle )
950 WCHAR lpBuffer[MDI_MAXTITLELENGTH+1];
951 MDICLIENTINFO *ci = get_client_info( hClient );
953 TRACE("frameText %s\n", debugstr_w(lpTitle));
957 if (!lpTitle && !ci->frameTitle) /* first time around, get title from the frame window */
959 GetWindowTextW( frame, lpBuffer, sizeof(lpBuffer)/sizeof(WCHAR) );
963 /* store new "default" title if lpTitle is not NULL */
966 HeapFree( GetProcessHeap(), 0, ci->frameTitle );
967 if ((ci->frameTitle = HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle)+1)*sizeof(WCHAR))))
968 strcpyW( ci->frameTitle, lpTitle );
973 if (IsZoomed(ci->hwndActiveChild) && IsWindowVisible(ci->hwndActiveChild))
975 /* combine frame title and child title if possible */
977 static const WCHAR lpBracket[] = {' ','-',' ','[',0};
978 static const WCHAR lpBracket2[] = {']',0};
979 int i_frame_text_length = strlenW(ci->frameTitle);
981 lstrcpynW( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
983 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
985 strcatW( lpBuffer, lpBracket );
986 if (GetWindowTextW( ci->hwndActiveChild, lpBuffer + i_frame_text_length + 4,
987 MDI_MAXTITLELENGTH - i_frame_text_length - 5 ))
988 strcatW( lpBuffer, lpBracket2 );
990 lpBuffer[i_frame_text_length] = 0; /* remove bracket */
995 lstrcpynW(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH+1 );
1001 DefWindowProcW( frame, WM_SETTEXT, 0, (LPARAM)lpBuffer );
1005 /* ----------------------------- Interface ---------------------------- */
1008 /**********************************************************************
1009 * MDIClientWndProc_common
1011 static LRESULT MDIClientWndProc_common( HWND hwnd, UINT message,
1012 WPARAM wParam, LPARAM lParam, BOOL unicode )
1016 TRACE("%p %04x (%s) %08x %08lx\n", hwnd, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1018 if (!(ci = get_client_info( hwnd ))) return 0;
1024 /* Since we are using only cs->lpCreateParams, we can safely
1025 * cast to LPCREATESTRUCTA here */
1026 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
1027 WND *wndPtr = WIN_GetPtr( hwnd );
1029 wndPtr->flags |= WIN_ISMDICLIENT;
1031 /* Translation layer doesn't know what's in the cs->lpCreateParams
1032 * so we have to keep track of what environment we're in. */
1034 if( wndPtr->flags & WIN_ISWIN32 )
1036 LPCLIENTCREATESTRUCT ccs = cs->lpCreateParams;
1037 ci->hWindowMenu = ccs->hWindowMenu;
1038 ci->idFirstChild = ccs->idFirstChild;
1042 LPCLIENTCREATESTRUCT16 ccs = MapSL((SEGPTR)cs->lpCreateParams);
1043 ci->hWindowMenu = HMENU_32(ccs->hWindowMenu);
1044 ci->idFirstChild = ccs->idFirstChild;
1046 WIN_ReleasePtr( wndPtr );
1049 ci->nActiveChildren = 0;
1050 ci->nTotalCreated = 0;
1051 ci->frameTitle = NULL;
1053 ci->hFrameMenu = GetMenu(cs->hwndParent);
1055 if (!hBmpClose) hBmpClose = CreateMDIMenuBitmap();
1057 TRACE("Client created: hwnd %p, Window menu %p, idFirst = %04x\n",
1058 hwnd, ci->hWindowMenu, ci->idFirstChild );
1064 if( IsZoomed(ci->hwndActiveChild) )
1065 MDI_RestoreFrameMenu(GetParent(hwnd), ci->hwndActiveChild);
1067 ci->nActiveChildren = 0;
1068 MDI_RefreshMenu(ci);
1070 HeapFree( GetProcessHeap(), 0, ci->child );
1071 HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1076 case WM_MDIACTIVATE:
1078 MDI_SwitchActiveChild( ci, (HWND)wParam, TRUE );
1083 return MDICascade(hwnd, ci);
1092 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)lParam;
1093 child = CreateWindowExW(WS_EX_MDICHILD, csW->szClass,
1094 csW->szTitle, csW->style,
1095 csW->x, csW->y, csW->cx, csW->cy,
1096 hwnd, 0, csW->hOwner,
1097 (LPVOID)csW->lParam);
1101 MDICREATESTRUCTA *csA = (MDICREATESTRUCTA *)lParam;
1102 child = CreateWindowExA(WS_EX_MDICHILD, csA->szClass,
1103 csA->szTitle, csA->style,
1104 csA->x, csA->y, csA->cx, csA->cy,
1105 hwnd, 0, csA->hOwner,
1106 (LPVOID)csA->lParam);
1109 if (IsZoomed(ci->hwndActiveChild))
1111 MDI_AugmentFrameMenu(GetParent(hwnd), child);
1112 MDI_UpdateFrameText(GetParent(hwnd), hwnd, NULL);
1114 return (LRESULT)child;
1119 return MDIDestroyChild( hwnd, ci, WIN_GetFullHandle( (HWND)wParam ), TRUE );
1121 case WM_MDIGETACTIVE:
1122 if (lParam) *(BOOL *)lParam = IsZoomed(ci->hwndActiveChild);
1123 return (LRESULT)ci->hwndActiveChild;
1125 case WM_MDIICONARRANGE:
1126 ci->mdiFlags |= MDIF_NEEDUPDATE;
1127 ArrangeIconicWindows( hwnd );
1128 ci->sbRecalc = SB_BOTH+1;
1129 SendMessageW( hwnd, WM_MDICALCCHILDSCROLL, 0, 0 );
1132 case WM_MDIMAXIMIZE:
1133 ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1136 case WM_MDINEXT: /* lParam != 0 means previous window */
1138 HWND next = MDI_GetWindow( ci, WIN_GetFullHandle( (HWND)wParam ), !lParam, 0 );
1139 MDI_SwitchActiveChild( ci, next, TRUE );
1144 SendMessageW( (HWND)wParam, WM_SYSCOMMAND, SC_RESTORE, 0);
1148 return MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1150 case WM_MDIREFRESHMENU:
1151 return MDI_RefreshMenu( ci );
1154 ci->mdiFlags |= MDIF_NEEDUPDATE;
1155 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1156 MDITile( hwnd, ci, wParam );
1157 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1162 ci->mdiFlags |= MDIF_NEEDUPDATE;
1163 ScrollChildren( hwnd, message, wParam, lParam );
1164 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1168 if (ci->hwndActiveChild && !IsIconic( ci->hwndActiveChild ))
1169 SetFocus( ci->hwndActiveChild );
1173 if( ci->hwndActiveChild )
1174 SendMessageW(ci->hwndActiveChild, message, wParam, lParam);
1177 case WM_PARENTNOTIFY:
1178 switch (LOWORD(wParam))
1181 if (GetWindowLongW((HWND)lParam, GWL_EXSTYLE) & WS_EX_MDICHILD)
1183 ci->nTotalCreated++;
1184 ci->nActiveChildren++;
1187 ci->child = HeapAlloc(GetProcessHeap(), 0, sizeof(HWND));
1189 ci->child = HeapReAlloc(GetProcessHeap(), 0, ci->child, sizeof(HWND) * ci->nActiveChildren);
1191 TRACE("Adding MDI child %p, # of children %d\n",
1192 (HWND)lParam, ci->nActiveChildren);
1194 ci->child[ci->nActiveChildren - 1] = (HWND)lParam;
1198 case WM_LBUTTONDOWN:
1202 pt.x = (short)LOWORD(lParam);
1203 pt.y = (short)HIWORD(lParam);
1204 child = ChildWindowFromPoint(hwnd, pt);
1206 TRACE("notification from %p (%li,%li)\n",child,pt.x,pt.y);
1208 if( child && child != hwnd && child != ci->hwndActiveChild )
1209 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1216 if( IsWindow(ci->hwndActiveChild) && IsZoomed(ci->hwndActiveChild) &&
1217 (GetWindowLongW(ci->hwndActiveChild, GWL_STYLE) & WS_VISIBLE) )
1223 rect.right = LOWORD(lParam);
1224 rect.bottom = HIWORD(lParam);
1226 AdjustWindowRectEx(&rect, GetWindowLongA(ci->hwndActiveChild, GWL_STYLE),
1227 0, GetWindowLongA(ci->hwndActiveChild, GWL_EXSTYLE) );
1228 MoveWindow(ci->hwndActiveChild, rect.left, rect.top,
1229 rect.right - rect.left, rect.bottom - rect.top, 1);
1232 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1236 case WM_MDICALCCHILDSCROLL:
1237 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1239 CalcChildScroll(hwnd, ci->sbRecalc-1);
1241 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1245 return unicode ? DefWindowProcW( hwnd, message, wParam, lParam ) :
1246 DefWindowProcA( hwnd, message, wParam, lParam );
1249 /***********************************************************************
1252 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1254 if (!IsWindow(hwnd)) return 0;
1255 return MDIClientWndProc_common( hwnd, message, wParam, lParam, FALSE );
1258 /***********************************************************************
1261 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1263 if (!IsWindow(hwnd)) return 0;
1264 return MDIClientWndProc_common( hwnd, message, wParam, lParam, TRUE );
1267 /***********************************************************************
1268 * DefFrameProcA (USER32.@)
1270 LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1271 UINT message, WPARAM wParam, LPARAM lParam)
1279 DWORD len = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0 );
1280 LPWSTR text = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1281 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, text, len );
1282 MDI_UpdateFrameText( hwnd, hwndMDIClient, text );
1283 HeapFree( GetProcessHeap(), 0, text );
1285 return 1; /* success. FIXME: check text length */
1292 return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1295 return DefWindowProcA(hwnd, message, wParam, lParam);
1299 /***********************************************************************
1300 * DefFrameProcW (USER32.@)
1302 LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1303 UINT message, WPARAM wParam, LPARAM lParam)
1305 MDICLIENTINFO *ci = get_client_info( hwndMDIClient );
1307 TRACE("%p %p %04x (%s) %08x %08lx\n", hwnd, hwndMDIClient, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1315 WORD id = LOWORD(wParam);
1316 /* check for possible syscommands for maximized MDI child */
1317 if (id < ci->idFirstChild || id >= ci->idFirstChild + ci->nActiveChildren)
1319 if( (id - 0xf000) & 0xf00f ) break;
1320 if( !IsZoomed(ci->hwndActiveChild) ) break;
1324 if (!is_close_enabled(ci->hwndActiveChild, 0)) break;
1332 return SendMessageW( ci->hwndActiveChild, WM_SYSCOMMAND,
1339 if (id - ci->idFirstChild == MDI_MOREWINDOWSLIMIT)
1340 /* User chose "More Windows..." */
1341 childHwnd = MDI_MoreWindowsDialog(hwndMDIClient);
1343 /* User chose one of the windows listed in the "Windows" menu */
1344 childHwnd = MDI_GetChildByID(hwndMDIClient, id, ci);
1347 SendMessageW( hwndMDIClient, WM_MDIACTIVATE, (WPARAM)childHwnd, 0 );
1353 SendMessageW(hwndMDIClient, message, wParam, lParam);
1357 MDI_UpdateFrameText( hwnd, hwndMDIClient, (LPWSTR)lParam );
1358 return 1; /* success. FIXME: check text length */
1361 SetFocus(hwndMDIClient);
1365 MoveWindow(hwndMDIClient, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
1370 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1372 if (!IsIconic(hwnd) && ci->hwndActiveChild && !IsZoomed(ci->hwndActiveChild))
1374 /* control menu is between the frame system menu and
1375 * the first entry of menu bar */
1376 WND *wndPtr = WIN_GetPtr(hwnd);
1378 if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1379 (wParam == VK_RIGHT && GetSubMenu(wndPtr->hSysMenu, 0) == next_menu->hmenuIn) )
1381 WIN_ReleasePtr(wndPtr);
1382 wndPtr = WIN_GetPtr(ci->hwndActiveChild);
1383 next_menu->hmenuNext = GetSubMenu(wndPtr->hSysMenu, 0);
1384 next_menu->hwndNext = ci->hwndActiveChild;
1386 WIN_ReleasePtr(wndPtr);
1393 return DefWindowProcW( hwnd, message, wParam, lParam );
1396 /***********************************************************************
1397 * DefMDIChildProcA (USER32.@)
1399 LRESULT WINAPI DefMDIChildProcA( 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 DefWindowProcA( hwnd, message, wParam, lParam );
1413 DefWindowProcA(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:
1422 case WM_CHILDACTIVATE:
1430 return DefMDIChildProcW( hwnd, message, wParam, lParam );
1432 return DefWindowProcA(hwnd, message, wParam, lParam);
1436 /***********************************************************************
1437 * DefMDIChildProcW (USER32.@)
1439 LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1440 WPARAM wParam, LPARAM lParam )
1442 HWND client = GetParent(hwnd);
1443 MDICLIENTINFO *ci = get_client_info( client );
1445 TRACE("%p %04x (%s) %08x %08lx\n", hwnd, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1447 hwnd = WIN_GetFullHandle( hwnd );
1448 if (!ci) return DefWindowProcW( hwnd, message, wParam, lParam );
1453 DefWindowProcW(hwnd, message, wParam, lParam);
1454 if( ci->hwndActiveChild == hwnd && IsZoomed(ci->hwndActiveChild) )
1455 MDI_UpdateFrameText( GetParent(client), client, NULL );
1456 return 1; /* success. FIXME: check text length */
1458 case WM_GETMINMAXINFO:
1459 MDI_ChildGetMinMaxInfo( client, hwnd, (MINMAXINFO *)lParam );
1463 return 0x00010000; /* MDI children don't have menu bars */
1466 SendMessageW( client, WM_MDIDESTROY, (WPARAM)hwnd, 0 );
1469 case WM_CHILDACTIVATE:
1470 MDI_ChildActivate( client, hwnd );
1477 if( ci->hwndActiveChild == hwnd && IsZoomed(ci->hwndActiveChild))
1484 if (ci->hwndActiveChild == hwnd && IsZoomed(ci->hwndActiveChild))
1485 return SendMessageW( GetParent(client), message, wParam, lParam);
1488 SendMessageW( client, WM_MDINEXT, 0, 0);
1491 SendMessageW( client, WM_MDINEXT, 0, 1);
1498 if (IsZoomed(ci->hwndActiveChild)) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1499 else MDI_PostUpdate(client, ci, SB_BOTH+1);
1503 if( hwnd == ci->hwndActiveChild )
1505 if( wParam == SIZE_MAXIMIZED )
1507 TRACE("maximizing child %p\n", hwnd );
1509 MDI_AugmentFrameMenu( GetParent(client), hwnd );
1512 MDI_RestoreFrameMenu( GetParent(client), hwnd );
1515 MDI_UpdateFrameText( GetParent(client), client, NULL );
1516 MDI_RefreshMenu(ci);
1517 MDI_PostUpdate(client, ci, SB_BOTH+1);
1522 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1523 HWND parent = GetParent(client);
1525 if( wParam == VK_LEFT ) /* switch to frame system menu */
1527 WND *wndPtr = WIN_GetPtr( parent );
1528 next_menu->hmenuNext = GetSubMenu( wndPtr->hSysMenu, 0 );
1529 WIN_ReleasePtr( wndPtr );
1531 if( wParam == VK_RIGHT ) /* to frame menu bar */
1533 next_menu->hmenuNext = GetMenu(parent);
1535 next_menu->hwndNext = parent;
1542 SendMessageW( hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (DWORD)VK_SPACE);
1548 /* Remove itself from the Window menu */
1549 MDI_RefreshMenu(ci);
1552 return DefWindowProcW(hwnd, message, wParam, lParam);
1555 /**********************************************************************
1556 * CreateMDIWindowA (USER32.@) Creates a MDI child
1559 * Success: Handle to created window
1562 HWND WINAPI CreateMDIWindowA(
1563 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1564 LPCSTR lpWindowName, /* [in] Pointer to window name */
1565 DWORD dwStyle, /* [in] Window style */
1566 INT X, /* [in] Horizontal position of window */
1567 INT Y, /* [in] Vertical position of window */
1568 INT nWidth, /* [in] Width of window */
1569 INT nHeight, /* [in] Height of window */
1570 HWND hWndParent, /* [in] Handle to parent window */
1571 HINSTANCE hInstance, /* [in] Handle to application instance */
1572 LPARAM lParam) /* [in] Application-defined value */
1574 TRACE("(%s,%s,%08lx,%d,%d,%d,%d,%p,%p,%08lx)\n",
1575 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1576 nWidth,nHeight,hWndParent,hInstance,lParam);
1578 return CreateWindowExA(WS_EX_MDICHILD, lpClassName, lpWindowName,
1579 dwStyle, X, Y, nWidth, nHeight, hWndParent,
1580 0, hInstance, (LPVOID)lParam);
1583 /***********************************************************************
1584 * CreateMDIWindowW (USER32.@) Creates a MDI child
1587 * Success: Handle to created window
1590 HWND WINAPI CreateMDIWindowW(
1591 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1592 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1593 DWORD dwStyle, /* [in] Window style */
1594 INT X, /* [in] Horizontal position of window */
1595 INT Y, /* [in] Vertical position of window */
1596 INT nWidth, /* [in] Width of window */
1597 INT nHeight, /* [in] Height of window */
1598 HWND hWndParent, /* [in] Handle to parent window */
1599 HINSTANCE hInstance, /* [in] Handle to application instance */
1600 LPARAM lParam) /* [in] Application-defined value */
1602 TRACE("(%s,%s,%08lx,%d,%d,%d,%d,%p,%p,%08lx)\n",
1603 debugstr_w(lpClassName), debugstr_w(lpWindowName), dwStyle, X, Y,
1604 nWidth, nHeight, hWndParent, hInstance, lParam);
1606 return CreateWindowExW(WS_EX_MDICHILD, lpClassName, lpWindowName,
1607 dwStyle, X, Y, nWidth, nHeight, hWndParent,
1608 0, hInstance, (LPVOID)lParam);
1611 /**********************************************************************
1612 * TranslateMDISysAccel (USER32.@)
1614 BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1616 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1618 MDICLIENTINFO *ci = get_client_info( hwndClient );
1621 if (!ci || !IsWindowEnabled(ci->hwndActiveChild)) return 0;
1623 /* translate if the Ctrl key is down and Alt not. */
1625 if( (GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
1627 switch( msg->wParam )
1631 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 ) ? SC_NEXTWINDOW : SC_PREVWINDOW;
1635 if (is_close_enabled(ci->hwndActiveChild, 0))
1644 TRACE("wParam = %04x\n", wParam);
1645 SendMessageW(ci->hwndActiveChild, WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
1649 return 0; /* failure */
1652 /***********************************************************************
1653 * CalcChildScroll (USER32.@)
1655 void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
1658 RECT childRect, clientRect;
1661 GetClientRect( hwnd, &clientRect );
1662 SetRectEmpty( &childRect );
1664 if ((list = WIN_ListChildren( hwnd )))
1667 for (i = 0; list[i]; i++)
1669 DWORD style = GetWindowLongW( list[i], GWL_STYLE );
1670 if (style & WS_MAXIMIZE)
1672 HeapFree( GetProcessHeap(), 0, list );
1673 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1676 if (style & WS_VISIBLE)
1679 GetWindowRect( list[i], &rect );
1680 UnionRect( &childRect, &rect, &childRect );
1683 HeapFree( GetProcessHeap(), 0, list );
1685 MapWindowPoints( 0, hwnd, (POINT *)&childRect, 2 );
1686 UnionRect( &childRect, &clientRect, &childRect );
1688 /* set common info values */
1689 info.cbSize = sizeof(info);
1690 info.fMask = SIF_POS | SIF_RANGE;
1692 /* set the specific */
1697 info.nMin = childRect.left;
1698 info.nMax = childRect.right - clientRect.right;
1699 info.nPos = clientRect.left - childRect.left;
1700 SetScrollInfo(hwnd, SB_HORZ, &info, TRUE);
1701 if (scroll == SB_HORZ) break;
1704 info.nMin = childRect.top;
1705 info.nMax = childRect.bottom - clientRect.bottom;
1706 info.nPos = clientRect.top - childRect.top;
1707 SetScrollInfo(hwnd, SB_VERT, &info, TRUE);
1713 /***********************************************************************
1714 * ScrollChildren (USER32.@)
1716 void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
1720 INT curPos, length, minPos, maxPos, shift;
1723 GetClientRect( hWnd, &rect );
1728 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
1729 curPos = GetScrollPos(hWnd,SB_HORZ);
1730 length = (rect.right - rect.left) / 2;
1731 shift = GetSystemMetrics(SM_CYHSCROLL);
1734 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
1735 curPos = GetScrollPos(hWnd,SB_VERT);
1736 length = (rect.bottom - rect.top) / 2;
1737 shift = GetSystemMetrics(SM_CXVSCROLL);
1746 newPos = curPos - shift;
1749 newPos = curPos + shift;
1752 newPos = curPos - length;
1755 newPos = curPos + length;
1758 case SB_THUMBPOSITION:
1759 newPos = LOWORD(lParam);
1772 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
1776 if( newPos > maxPos )
1779 if( newPos < minPos )
1782 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
1784 if( uMsg == WM_VSCROLL )
1785 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
1786 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
1788 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
1789 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
1793 /******************************************************************************
1794 * CascadeWindows (USER32.@) Cascades MDI child windows
1797 * Success: Number of cascaded windows.
1801 CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
1802 UINT cKids, const HWND *lpKids)
1804 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
1809 /******************************************************************************
1810 * TileWindows (USER32.@) Tiles MDI child windows
1813 * Success: Number of tiled windows.
1817 TileWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
1818 UINT cKids, const HWND *lpKids)
1820 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
1824 /************************************************************************
1825 * "More Windows..." functionality
1828 /* MDI_MoreWindowsDlgProc
1830 * This function will process the messages sent to the "More Windows..."
1832 * Return values: 0 = cancel pressed
1833 * HWND = ok pressed or double-click in the list...
1837 static INT_PTR WINAPI MDI_MoreWindowsDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
1846 MDICLIENTINFO *ci = get_client_info( (HWND)lParam );
1847 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
1849 for (i = 0; i < ci->nActiveChildren; i++)
1851 WCHAR buffer[MDI_MAXTITLELENGTH];
1853 if (!InternalGetWindowText( ci->child[i], buffer, sizeof(buffer)/sizeof(WCHAR) ))
1855 SendMessageW(hListBox, LB_ADDSTRING, 0, (LPARAM)buffer );
1856 SendMessageW(hListBox, LB_SETITEMDATA, i, (LPARAM)ci->child[i] );
1857 length = strlenW(buffer); /* FIXME: should use GetTextExtentPoint */
1858 if (length > widest)
1861 /* Make sure the horizontal scrollbar scrolls ok */
1862 SendMessageW(hListBox, LB_SETHORIZONTALEXTENT, widest * 6, 0);
1864 /* Set the current selection */
1865 SendMessageW(hListBox, LB_SETCURSEL, MDI_MOREWINDOWSLIMIT, 0);
1870 switch (LOWORD(wParam))
1873 if (HIWORD(wParam) != LBN_DBLCLK) break;
1877 /* windows are sorted by menu ID, so we must return the
1878 * window associated to the given id
1880 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
1881 UINT index = SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
1882 LRESULT res = SendMessageW(hListBox, LB_GETITEMDATA, index, 0);
1883 EndDialog(hDlg, res);
1897 * MDI_MoreWindowsDialog
1899 * Prompts the user with a listbox containing the opened
1900 * documents. The user can then choose a windows and click
1901 * on OK to set the current window to the one selected, or
1902 * CANCEL to cancel. The function returns a handle to the
1906 static HWND MDI_MoreWindowsDialog(HWND hwnd)
1912 hRes = FindResourceA(user32_module, "MDI_MOREWINDOWS", (LPSTR)RT_DIALOG);
1917 hDlgTmpl = LoadResource(user32_module, hRes );
1922 template = LockResource( hDlgTmpl );
1927 return (HWND) DialogBoxIndirectParamA(user32_module,
1928 (const DLGTEMPLATE*) template,
1929 hwnd, MDI_MoreWindowsDlgProc, (LPARAM) hwnd);