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/unicode.h"
96 #include "nonclient.h"
100 #include "wine/debug.h"
103 WINE_DEFAULT_DEBUG_CHANNEL(mdi);
105 #define MDI_MAXLISTLENGTH 0x40
106 #define MDI_MAXTITLELENGTH 0xa1
108 #define MDI_NOFRAMEREPAINT 0
109 #define MDI_REPAINTFRAMENOW 1
110 #define MDI_REPAINTFRAME 2
112 #define WM_MDICALCCHILDSCROLL 0x10ac /* this is exactly what Windows uses */
114 /* "More Windows..." definitions */
115 #define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
116 option will appear under the Windows menu */
117 #define MDI_IDC_LISTBOX 100
118 #define IDS_MDI_MOREWINDOWS 13
120 #define MDIF_NEEDUPDATE 0x0001
124 UINT nActiveChildren;
125 HWND hwndChildMaximized;
126 HWND hwndActiveChild;
132 UINT sbRecalc; /* SB_xxx flags for scrollbar fixup */
135 static HBITMAP hBmpClose = 0;
137 /* ----------------- declarations ----------------- */
138 static void MDI_UpdateFrameText( HWND, HWND, BOOL, LPCWSTR);
139 static BOOL MDI_AugmentFrameMenu( HWND, HWND );
140 static BOOL MDI_RestoreFrameMenu( HWND, HWND );
141 static LONG MDI_ChildActivate( HWND, HWND );
143 static HWND MDI_MoreWindowsDialog(HWND);
144 static void MDI_SwapMenuItems(HWND, UINT, UINT);
145 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
146 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
148 /* -------- Miscellaneous service functions ----------
152 static HWND MDI_GetChildByID(HWND hwnd, UINT id)
158 if (!(win_array = WIN_ListChildren( hwnd ))) return 0;
159 for (i = 0; win_array[i]; i++)
161 if (GetWindowLongA( win_array[i], GWL_ID ) == id) break;
164 HeapFree( GetProcessHeap(), 0, win_array );
168 static void MDI_PostUpdate(HWND hwnd, MDICLIENTINFO* ci, WORD recalc)
170 if( !(ci->mdiFlags & MDIF_NEEDUPDATE) )
172 ci->mdiFlags |= MDIF_NEEDUPDATE;
173 PostMessageA( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
175 ci->sbRecalc = recalc;
179 /*********************************************************************
180 * MDIClient class descriptor
182 const struct builtin_class_descr MDICLIENT_builtin_class =
184 "MDIClient", /* name */
186 MDIClientWndProcA, /* procA */
187 MDIClientWndProcW, /* procW */
188 sizeof(MDICLIENTINFO), /* extra */
189 IDC_ARROW, /* cursor */
190 (HBRUSH)(COLOR_APPWORKSPACE+1) /* brush */
194 static MDICLIENTINFO *get_client_info( HWND client )
196 MDICLIENTINFO *ret = NULL;
197 WND *win = WIN_GetPtr( client );
200 if (win == WND_OTHER_PROCESS)
202 ERR( "client %p belongs to other process\n", client );
205 if (win->cbWndExtra < sizeof(MDICLIENTINFO)) WARN( "%p is not an MDI client\n", client );
206 else ret = (MDICLIENTINFO *)win->wExtra;
207 WIN_ReleasePtr( win );
212 /**********************************************************************
215 static void MDI_MenuModifyItem( HWND client, HWND hWndChild )
217 MDICLIENTINFO *clientInfo = get_client_info( client );
221 if (!clientInfo || !clientInfo->hWindowMenu) return;
223 id = GetWindowLongA( hWndChild, GWL_ID );
224 if (id >= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT) return;
226 buffer[1] = '1' + id - clientInfo->idFirstChild;
228 GetWindowTextW( hWndChild, buffer + 3, sizeof(buffer)/sizeof(WCHAR) - 3 );
230 n = GetMenuState(clientInfo->hWindowMenu, id, MF_BYCOMMAND);
231 ModifyMenuW(clientInfo->hWindowMenu, id, MF_BYCOMMAND | MF_STRING, id, buffer );
232 CheckMenuItem(clientInfo->hWindowMenu, id, n & MF_CHECKED);
235 /**********************************************************************
238 static BOOL MDI_MenuDeleteItem( HWND client, HWND hWndChild )
241 static const WCHAR format[] = {'&','%','d',' ',0};
242 MDICLIENTINFO *clientInfo = get_client_info( client );
245 if( !clientInfo->nActiveChildren || !clientInfo->hWindowMenu )
248 id = GetWindowLongA( hWndChild, GWL_ID );
249 DeleteMenu(clientInfo->hWindowMenu,id,MF_BYCOMMAND);
251 /* walk the rest of MDI children to prevent gaps in the id
252 * sequence and in the menu child list */
254 for( index = id+1; index <= clientInfo->nActiveChildren +
255 clientInfo->idFirstChild; index++ )
257 HWND hwnd = MDI_GetChildByID(client,index);
260 TRACE("no window for id=%i\n",index);
265 SetWindowLongW( hwnd, GWL_ID, GetWindowLongW( hwnd, GWL_ID ) - 1 );
267 n = wsprintfW(buffer, format ,index - clientInfo->idFirstChild);
268 GetWindowTextW( hwnd, buffer + n, sizeof(buffer)/sizeof(WCHAR) - n );
270 /* change menu if the current child is to be shown in the
273 if (index <= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT)
274 ModifyMenuW(clientInfo->hWindowMenu ,index ,MF_BYCOMMAND | MF_STRING,
275 index - 1 , buffer );
278 /* We must restore the "More Windows..." option if there are enough children
280 if (clientInfo->nActiveChildren - 1 > MDI_MOREWINDOWSLIMIT)
283 LoadStringW(GetModuleHandleA("USER32"), IDS_MDI_MOREWINDOWS, szTmp, sizeof(szTmp)/sizeof(szTmp[0]));
284 AppendMenuW(clientInfo->hWindowMenu, MF_STRING, clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT, szTmp);
289 /**********************************************************************
292 * returns "activateable" child different from the current or zero
294 static HWND MDI_GetWindow(MDICLIENTINFO *clientInfo, HWND hWnd, BOOL bNext,
301 dwStyleMask |= WS_DISABLED | WS_VISIBLE;
302 if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
304 if (!(list = WIN_ListChildren( GetParent(hWnd) ))) return 0;
306 /* start from next after hWnd */
307 while (list[i] && list[i] != hWnd) i++;
310 for ( ; list[i]; i++)
312 if (GetWindow( list[i], GW_OWNER )) continue;
313 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
315 if (bNext) goto found;
317 /* now restart from the beginning */
318 for (i = 0; list[i] && list[i] != hWnd; i++)
320 if (GetWindow( list[i], GW_OWNER )) continue;
321 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
323 if (bNext) goto found;
326 HeapFree( GetProcessHeap(), 0, list );
330 /**********************************************************************
331 * MDI_CalcDefaultChildPos
333 * It seems that the default height is about 2/3 of the client rect
335 static void MDI_CalcDefaultChildPos( HWND hwnd, WORD n, LPPOINT lpPos, INT delta)
339 INT spacing = GetSystemMetrics(SM_CYCAPTION) +
340 GetSystemMetrics(SM_CYFRAME) - 1;
342 GetClientRect( hwnd, &rect );
343 if( rect.bottom - rect.top - delta >= spacing )
344 rect.bottom -= delta;
346 nstagger = (rect.bottom - rect.top)/(3 * spacing);
347 lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
348 lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
349 lpPos[0].x = lpPos[0].y = spacing * (n%(nstagger+1));
352 /**********************************************************************
355 static LRESULT MDISetMenu( HWND hwnd, HMENU hmenuFrame,
359 HWND hwndFrame = GetParent(hwnd);
360 HMENU oldFrameMenu = GetMenu(hwndFrame);
362 TRACE("%p %p %p\n", hwnd, hmenuFrame, hmenuWindow);
364 if (hmenuFrame && !IsMenu(hmenuFrame))
366 WARN("hmenuFrame is not a menu handle\n");
370 if (hmenuWindow && !IsMenu(hmenuWindow))
372 WARN("hmenuWindow is not a menu handle\n");
376 if (!(ci = get_client_info( hwnd ))) return 0;
378 if( ci->hwndChildMaximized && hmenuFrame && hmenuFrame!=oldFrameMenu )
379 MDI_RestoreFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
381 if( hmenuWindow && hmenuWindow != ci->hWindowMenu )
383 /* delete menu items from ci->hWindowMenu
384 * and add them to hmenuWindow */
385 /* Agent newsreader calls this function with ci->hWindowMenu == NULL */
386 if( ci->hWindowMenu && ci->nActiveChildren )
389 LPWSTR buffer = NULL;
391 INT nbWindowsMenuItems; /* num of documents shown + "More Windows..." if present */
392 INT i = GetMenuItemCount(ci->hWindowMenu) - 1;
393 INT pos = GetMenuItemCount(hmenuWindow) + 1;
395 AppendMenuA( hmenuWindow, MF_SEPARATOR, 0, NULL);
397 if (ci->nActiveChildren <= MDI_MOREWINDOWSLIMIT)
398 nbWindowsMenuItems = ci->nActiveChildren;
400 nbWindowsMenuItems = MDI_MOREWINDOWSLIMIT + 1;
402 j = i - nbWindowsMenuItems + 1;
404 for( ; i >= j ; i-- )
406 memset(&mii, 0, sizeof(mii));
407 mii.cbSize = sizeof(mii);
408 mii.fMask = MIIM_CHECKMARKS | MIIM_DATA | MIIM_ID | MIIM_STATE
409 | MIIM_SUBMENU | MIIM_TYPE | MIIM_BITMAP;
411 GetMenuItemInfoW(ci->hWindowMenu, i, TRUE, &mii);
412 if(mii.cch) { /* Menu is MFT_STRING */
413 mii.cch++; /* add room for '\0' */
414 buffer = HeapAlloc(GetProcessHeap(), 0,
415 mii.cch * sizeof(WCHAR));
416 mii.dwTypeData = buffer;
417 GetMenuItemInfoW(ci->hWindowMenu, i, TRUE, &mii);
419 DeleteMenu(ci->hWindowMenu, i, MF_BYPOSITION);
420 InsertMenuItemW(hmenuWindow, pos, TRUE, &mii);
422 HeapFree(GetProcessHeap(), 0, buffer);
426 /* remove separator */
427 DeleteMenu(ci->hWindowMenu, i, MF_BYPOSITION);
429 ci->hWindowMenu = hmenuWindow;
434 SetMenu(hwndFrame, hmenuFrame);
435 if( hmenuFrame!=oldFrameMenu )
437 if( ci->hwndChildMaximized )
438 MDI_AugmentFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
439 return (LRESULT)oldFrameMenu;
444 HMENU menu = GetMenu( GetParent(hwnd) );
445 INT nItems = GetMenuItemCount(menu) - 1;
446 UINT iId = GetMenuItemID(menu,nItems) ;
448 if( !(iId == SC_RESTORE || iId == SC_CLOSE) )
450 /* SetMenu() may already have been called, meaning that this window
451 * already has its menu. But they may have done a SetMenu() on
452 * an MDI window, and called MDISetMenu() after the fact, meaning
453 * that the "if" to this "else" wouldn't catch the need to
454 * augment the frame menu.
456 if( ci->hwndChildMaximized )
457 MDI_AugmentFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
463 /**********************************************************************
466 static LRESULT MDIRefreshMenu( HWND hwnd, HMENU hmenuFrame,
469 HWND hwndFrame = GetParent(hwnd);
470 HMENU oldFrameMenu = GetMenu(hwndFrame);
472 TRACE("%p %p %p\n", hwnd, hmenuFrame, hmenuWindow);
474 FIXME("partially function stub\n");
476 return (LRESULT)oldFrameMenu;
480 /* ------------------ MDI child window functions ---------------------- */
483 /**********************************************************************
486 static HWND MDICreateChild( HWND parent, MDICLIENTINFO *ci,
487 LPMDICREATESTRUCTA cs, BOOL unicode )
490 DWORD style = cs->style | (WS_CHILD | WS_CLIPSIBLINGS);
491 HWND hwnd, hwndMax = 0;
492 UINT wIDmenu = ci->idFirstChild + ci->nActiveChildren;
494 static const WCHAR lpstrDef[] = {'j','u','n','k','!',0};
496 TRACE("origin %i,%i - dim %i,%i, style %08lx\n",
497 cs->x, cs->y, cs->cx, cs->cy, cs->style);
498 /* calculate placement */
499 MDI_CalcDefaultChildPos(parent, ci->nTotalCreated++, pos, 0);
501 if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16 || !cs->cx) cs->cx = pos[1].x;
502 if (cs->cy == CW_USEDEFAULT || cs->cy == CW_USEDEFAULT16 || !cs->cy) cs->cy = pos[1].y;
504 if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
510 /* restore current maximized child */
511 if( (style & WS_VISIBLE) && ci->hwndChildMaximized )
513 TRACE("Restoring current maximized child %p\n", ci->hwndChildMaximized);
514 if( style & WS_MAXIMIZE )
515 SendMessageW(parent, WM_SETREDRAW, FALSE, 0L);
516 hwndMax = ci->hwndChildMaximized;
517 ShowWindow( hwndMax, SW_SHOWNOACTIVATE );
518 if( style & WS_MAXIMIZE )
519 SendMessageW(parent, WM_SETREDRAW, TRUE, 0L);
522 if (ci->nActiveChildren <= MDI_MOREWINDOWSLIMIT)
523 /* this menu is needed to set a check mark in MDI_ChildActivate */
524 if (ci->hWindowMenu != 0)
525 AppendMenuW(ci->hWindowMenu, MF_STRING, wIDmenu, lpstrDef);
527 ci->nActiveChildren++;
529 /* fix window style */
530 wndParent = WIN_FindWndPtr( parent );
531 if( !(wndParent->dwStyle & MDIS_ALLCHILDSTYLES) )
533 TRACE("MDIS_ALLCHILDSTYLES is missing, fixing window style\n");
534 style &= (WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZE | WS_MAXIMIZE |
535 WS_CLIPCHILDREN | WS_DISABLED | WS_VSCROLL | WS_HSCROLL );
536 style |= (WS_VISIBLE | WS_OVERLAPPEDWINDOW);
539 if( wndParent->flags & WIN_ISWIN32 )
541 WIN_ReleaseWndPtr( wndParent );
544 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)cs;
545 hwnd = CreateWindowW( csW->szClass, csW->szTitle, style,
546 csW->x, csW->y, csW->cx, csW->cy, parent,
547 (HMENU)wIDmenu, csW->hOwner, csW );
550 hwnd = CreateWindowA( cs->szClass, cs->szTitle, style,
551 cs->x, cs->y, cs->cx, cs->cy, parent,
552 (HMENU)wIDmenu, cs->hOwner, cs );
556 MDICREATESTRUCT16 cs16;
557 SEGPTR title, cls, seg_cs16;
559 WIN_ReleaseWndPtr( wndParent );
560 STRUCT32_MDICREATESTRUCT32Ato16( cs, &cs16 );
561 cs16.szTitle = title = MapLS( cs->szTitle );
562 cs16.szClass = cls = MapLS( cs->szClass );
563 seg_cs16 = MapLS( &cs16 );
564 hwnd = WIN_Handle32( CreateWindow16( cs->szClass, cs->szTitle, style,
565 cs16.x, cs16.y, cs16.cx, cs16.cy,
566 HWND_16(parent), (HMENU16)wIDmenu,
567 cs16.hOwner, (LPVOID)seg_cs16 ));
573 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
577 /* All MDI child windows have the WS_EX_MDICHILD style */
578 SetWindowLongW( hwnd, GWL_EXSTYLE, GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_MDICHILD );
580 /* If we have more than 9 windows, we must insert the new one at the
581 * 9th position in order to see it in the "Windows" menu
583 if (ci->nActiveChildren > MDI_MOREWINDOWSLIMIT)
584 MDI_SwapMenuItems( parent, GetWindowLongW( hwnd, GWL_ID ),
585 ci->idFirstChild + MDI_MOREWINDOWSLIMIT - 1);
587 MDI_MenuModifyItem(parent, hwnd);
589 /* Have we hit the "More Windows..." limit? If so, we must
590 * add a "More Windows..." option
592 if (ci->nActiveChildren == MDI_MOREWINDOWSLIMIT + 1)
595 LoadStringW(GetModuleHandleA("USER32"), IDS_MDI_MOREWINDOWS, szTmp, sizeof(szTmp)/sizeof(szTmp[0]));
597 ModifyMenuW(ci->hWindowMenu,
598 ci->idFirstChild + MDI_MOREWINDOWSLIMIT,
599 MF_BYCOMMAND | MF_STRING,
600 ci->idFirstChild + MDI_MOREWINDOWSLIMIT,
604 if( IsIconic(hwnd) && ci->hwndActiveChild )
606 TRACE("Minimizing created MDI child %p\n", hwnd);
607 ShowWindow( hwnd, SW_SHOWMINNOACTIVE );
611 /* WS_VISIBLE is clear if a) the MDI client has
612 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
613 * MDICreateStruct. If so the created window is not shown nor
616 if (IsWindowVisible(hwnd)) ShowWindow(hwnd, SW_SHOW);
618 TRACE("created child - %p\n",hwnd);
622 ci->nActiveChildren--;
623 DeleteMenu(ci->hWindowMenu,wIDmenu,MF_BYCOMMAND);
624 if( IsWindow(hwndMax) )
625 ShowWindow(hwndMax, SW_SHOWMAXIMIZED);
631 /**********************************************************************
632 * MDI_ChildGetMinMaxInfo
634 * Note: The rule here is that client rect of the maximized MDI child
635 * is equal to the client rect of the MDI client window.
637 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
641 GetClientRect( client, &rect );
642 AdjustWindowRectEx( &rect, GetWindowLongW( hwnd, GWL_STYLE ),
643 0, GetWindowLongW( hwnd, GWL_EXSTYLE ));
645 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
646 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
648 lpMinMax->ptMaxPosition.x = rect.left;
649 lpMinMax->ptMaxPosition.y = rect.top;
651 TRACE("max rect (%ld,%ld - %ld, %ld)\n",
652 rect.left,rect.top,rect.right,rect.bottom);
655 /**********************************************************************
656 * MDI_SwitchActiveChild
658 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
661 static void MDI_SwitchActiveChild( HWND clientHwnd, HWND childHwnd,
666 MDICLIENTINFO *ci = get_client_info( clientHwnd );
668 hwndTo = MDI_GetWindow(ci, childHwnd, bNextWindow, 0);
670 TRACE("from %p, to %p\n",childHwnd,hwndTo);
672 if ( !hwndTo ) return; /* no window to switch to */
674 hwndPrev = ci->hwndActiveChild;
676 if ( hwndTo != hwndPrev )
678 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0,
679 SWP_NOMOVE | SWP_NOSIZE );
681 if( bNextWindow && hwndPrev )
682 SetWindowPos( hwndPrev, HWND_BOTTOM, 0, 0, 0, 0,
683 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
688 /**********************************************************************
691 static LRESULT MDIDestroyChild( HWND parent, MDICLIENTINFO *ci,
692 HWND child, BOOL flagDestroy )
694 if( child == ci->hwndActiveChild )
696 MDI_SwitchActiveChild(parent, child, TRUE);
698 if( child == ci->hwndActiveChild )
700 ShowWindow( child, SW_HIDE);
701 if( child == ci->hwndChildMaximized )
703 HWND frame = GetParent(parent);
704 MDI_RestoreFrameMenu( frame, child );
705 ci->hwndChildMaximized = 0;
706 MDI_UpdateFrameText( frame, parent, TRUE, NULL);
709 MDI_ChildActivate(parent, 0);
713 MDI_MenuDeleteItem(parent, child);
715 ci->nActiveChildren--;
717 TRACE("child destroyed - %p\n",child);
721 MDI_PostUpdate(GetParent(child), ci, SB_BOTH+1);
722 DestroyWindow(child);
728 /**********************************************************************
731 * Note: hWndChild is NULL when last child is being destroyed
733 static LONG MDI_ChildActivate( HWND client, HWND child )
735 MDICLIENTINFO *clientInfo = get_client_info( client );
736 HWND prevActiveWnd = clientInfo->hwndActiveChild;
737 BOOL isActiveFrameWnd;
739 if (child && (!IsWindowEnabled( child ))) return 0;
741 /* Don't activate if it is already active. Might happen
742 since ShowWindow DOES activate MDI children */
743 if (clientInfo->hwndActiveChild == child) return 0;
745 TRACE("%p\n", child);
747 isActiveFrameWnd = (GetActiveWindow() == GetParent(client));
749 /* deactivate prev. active child */
752 SetWindowLongA( prevActiveWnd, GWL_STYLE,
753 GetWindowLongA( prevActiveWnd, GWL_STYLE ) | WS_SYSMENU );
754 SendMessageA( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
755 SendMessageA( prevActiveWnd, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child);
756 /* uncheck menu item */
757 if( clientInfo->hWindowMenu )
759 UINT prevID = GetWindowLongA( prevActiveWnd, GWL_ID );
761 if (prevID - clientInfo->idFirstChild < MDI_MOREWINDOWSLIMIT)
762 CheckMenuItem( clientInfo->hWindowMenu, prevID, 0);
764 CheckMenuItem( clientInfo->hWindowMenu,
765 clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1, 0);
770 if (clientInfo->hwndChildMaximized && clientInfo->hwndChildMaximized != child)
772 INT cmd = SW_SHOWNORMAL;
776 UINT state = GetMenuState(GetSystemMenu(child, FALSE), SC_MAXIMIZE, MF_BYCOMMAND);
777 if (state != 0xFFFFFFFF && (state & (MF_DISABLED | MF_GRAYED)))
778 SendMessageW(clientInfo->hwndChildMaximized, WM_SYSCOMMAND, SC_RESTORE, 0);
780 cmd = SW_SHOWMAXIMIZED;
782 clientInfo->hwndActiveChild = child;
785 ShowWindow( clientInfo->hwndActiveChild, cmd );
788 clientInfo->hwndActiveChild = child;
790 /* check if we have any children left */
793 if( isActiveFrameWnd )
798 /* check menu item */
799 if( clientInfo->hWindowMenu )
801 UINT id = GetWindowLongA( child, GWL_ID );
802 /* The window to be activated must be displayed in the "Windows" menu */
803 if (id >= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT)
805 MDI_SwapMenuItems( GetParent(child),
806 id, clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1);
807 id = clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1;
808 MDI_MenuModifyItem( GetParent(child), child );
811 CheckMenuItem(clientInfo->hWindowMenu, id, MF_CHECKED);
813 /* bring active child to the top */
814 SetWindowPos( child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
816 if( isActiveFrameWnd )
818 SendMessageA( child, WM_NCACTIVATE, TRUE, 0L);
819 if( GetFocus() == client )
820 SendMessageA( client, WM_SETFOCUS, (WPARAM)client, 0L );
824 SendMessageA( child, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child );
828 /* -------------------- MDI client window functions ------------------- */
830 /**********************************************************************
831 * CreateMDIMenuBitmap
833 static HBITMAP CreateMDIMenuBitmap(void)
835 HDC hDCSrc = CreateCompatibleDC(0);
836 HDC hDCDest = CreateCompatibleDC(hDCSrc);
837 HBITMAP hbClose = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_OLD_CLOSE) );
839 HBITMAP hobjSrc, hobjDest;
841 hobjSrc = SelectObject(hDCSrc, hbClose);
842 hbCopy = CreateCompatibleBitmap(hDCSrc,GetSystemMetrics(SM_CXSIZE),GetSystemMetrics(SM_CYSIZE));
843 hobjDest = SelectObject(hDCDest, hbCopy);
845 BitBlt(hDCDest, 0, 0, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE),
846 hDCSrc, GetSystemMetrics(SM_CXSIZE), 0, SRCCOPY);
848 SelectObject(hDCSrc, hobjSrc);
849 DeleteObject(hbClose);
852 hobjSrc = SelectObject( hDCDest, GetStockObject(BLACK_PEN) );
854 MoveToEx( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, 0, NULL );
855 LineTo( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, GetSystemMetrics(SM_CYSIZE) - 1);
857 SelectObject(hDCDest, hobjSrc );
858 SelectObject(hDCDest, hobjDest);
864 /**********************************************************************
867 static LONG MDICascade( HWND client, MDICLIENTINFO *ci )
870 BOOL has_icons = FALSE;
873 if (ci->hwndChildMaximized)
874 SendMessageA( client, WM_MDIRESTORE,
875 (WPARAM)ci->hwndChildMaximized, 0);
877 if (ci->nActiveChildren == 0) return 0;
879 if (!(win_array = WIN_ListChildren( client ))) return 0;
881 /* remove all the windows we don't want */
882 for (i = total = 0; win_array[i]; i++)
884 if (!IsWindowVisible( win_array[i] )) continue;
885 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows */
886 if (IsIconic( win_array[i] ))
891 win_array[total++] = win_array[i];
893 win_array[total] = 0;
897 INT delta = 0, n = 0, i;
899 if (has_icons) delta = GetSystemMetrics(SM_CYICONSPACING) + GetSystemMetrics(SM_CYICON);
901 /* walk the list (backwards) and move windows */
902 for (i = total - 1; i >= 0; i--)
904 TRACE("move %p to (%ld,%ld) size [%ld,%ld]\n",
905 win_array[i], pos[0].x, pos[0].y, pos[1].x, pos[1].y);
907 MDI_CalcDefaultChildPos(client, n++, pos, delta);
908 SetWindowPos( win_array[i], 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
909 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
912 HeapFree( GetProcessHeap(), 0, win_array );
914 if (has_icons) ArrangeIconicWindows( client );
918 /**********************************************************************
921 static void MDITile( HWND client, MDICLIENTINFO *ci, WPARAM wParam )
925 BOOL has_icons = FALSE;
927 if (ci->hwndChildMaximized)
928 SendMessageA( client, WM_MDIRESTORE, (WPARAM)ci->hwndChildMaximized, 0);
930 if (ci->nActiveChildren == 0) return;
932 if (!(win_array = WIN_ListChildren( client ))) return;
934 /* remove all the windows we don't want */
935 for (i = total = 0; win_array[i]; i++)
937 if (!IsWindowVisible( win_array[i] )) continue;
938 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows (icon titles) */
939 if (IsIconic( win_array[i] ))
944 if ((wParam & MDITILE_SKIPDISABLED) && !IsWindowEnabled( win_array[i] )) continue;
945 win_array[total++] = win_array[i];
947 win_array[total] = 0;
949 TRACE("%u windows to tile\n", total);
953 HWND *pWnd = win_array;
955 int x, y, xsize, ysize;
956 int rows, columns, r, c, i;
958 GetClientRect(client,&rect);
959 rows = (int) sqrt((double)total);
960 columns = total / rows;
962 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
965 rows = columns; /* exchange r and c */
971 y = rect.bottom - 2 * GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
972 rect.bottom = ( y - GetSystemMetrics(SM_CYICON) < rect.top )? rect.bottom: y;
975 ysize = rect.bottom / rows;
976 xsize = rect.right / columns;
978 for (x = i = 0, c = 1; c <= columns && *pWnd; c++)
983 ysize = rect.bottom / rows;
987 for (r = 1; r <= rows && *pWnd; r++, i++)
989 SetWindowPos(*pWnd, 0, x, y, xsize, ysize,
990 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
997 HeapFree( GetProcessHeap(), 0, win_array );
998 if (has_icons) ArrangeIconicWindows( client );
1001 /* ----------------------- Frame window ---------------------------- */
1004 /**********************************************************************
1005 * MDI_AugmentFrameMenu
1007 static BOOL MDI_AugmentFrameMenu( HWND frame, HWND hChild )
1009 HMENU menu = GetMenu( frame );
1010 WND* child = WIN_FindWndPtr(hChild);
1011 HMENU hSysPopup = 0;
1012 HBITMAP hSysMenuBitmap = 0;
1014 TRACE("frame %p,child %p\n",frame,hChild);
1016 if( !menu || !child->hSysMenu )
1018 WIN_ReleaseWndPtr(child);
1021 WIN_ReleaseWndPtr(child);
1023 /* create a copy of sysmenu popup and insert it into frame menu bar */
1025 if (!(hSysPopup = LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU")))
1028 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1029 SC_MINIMIZE, (LPSTR)(DWORD)HBMMENU_MBAR_MINIMIZE ) ;
1030 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1031 SC_RESTORE, (LPSTR)(DWORD)HBMMENU_MBAR_RESTORE );
1033 /* In Win 95 look, the system menu is replaced by the child icon */
1035 if(TWEAK_WineLook > WIN31_LOOK)
1037 HICON hIcon = (HICON)GetClassLongA(hChild, GCL_HICONSM);
1039 hIcon = (HICON)GetClassLongA(hChild, GCL_HICON);
1043 HBITMAP hBitmap, hOldBitmap;
1045 HDC hdc = GetDC(hChild);
1050 cx = GetSystemMetrics(SM_CXSMICON);
1051 cy = GetSystemMetrics(SM_CYSMICON);
1052 hMemDC = CreateCompatibleDC(hdc);
1053 hBitmap = CreateCompatibleBitmap(hdc, cx, cy);
1054 hOldBitmap = SelectObject(hMemDC, hBitmap);
1055 SetMapMode(hMemDC, MM_TEXT);
1056 hBrush = CreateSolidBrush(GetSysColor(COLOR_MENU));
1057 DrawIconEx(hMemDC, 0, 0, hIcon, cx, cy, 0, hBrush, DI_NORMAL);
1058 SelectObject (hMemDC, hOldBitmap);
1059 DeleteObject(hBrush);
1061 ReleaseDC(hChild, hdc);
1062 hSysMenuBitmap = hBitmap;
1067 hSysMenuBitmap = hBmpClose;
1069 if( !InsertMenuA(menu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
1070 (UINT_PTR)hSysPopup, (LPSTR)hSysMenuBitmap))
1072 TRACE("not inserted\n");
1073 DestroyMenu(hSysPopup);
1077 /* The close button is only present in Win 95 look */
1078 if(TWEAK_WineLook > WIN31_LOOK)
1080 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1081 SC_CLOSE, (LPSTR)(DWORD)HBMMENU_MBAR_CLOSE );
1084 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
1085 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
1086 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
1087 SetMenuDefaultItem(hSysPopup, SC_CLOSE, FALSE);
1095 /**********************************************************************
1096 * MDI_RestoreFrameMenu
1098 static BOOL MDI_RestoreFrameMenu( HWND frame, HWND hChild )
1100 MENUITEMINFOW menuInfo;
1101 HMENU menu = GetMenu( frame );
1102 INT nItems = GetMenuItemCount(menu) - 1;
1103 UINT iId = GetMenuItemID(menu,nItems) ;
1105 TRACE("frame %p,child %p,nIt=%d,iId=%d\n",frame,hChild,nItems,iId);
1107 if(!(iId == SC_RESTORE || iId == SC_CLOSE) )
1111 * Remove the system menu, If that menu is the icon of the window
1112 * as it is in win95, we have to delete the bitmap.
1114 memset(&menuInfo, 0, sizeof(menuInfo));
1115 menuInfo.cbSize = sizeof(menuInfo);
1116 menuInfo.fMask = MIIM_DATA | MIIM_TYPE;
1118 GetMenuItemInfoW(menu,
1123 RemoveMenu(menu,0,MF_BYPOSITION);
1125 if ( (menuInfo.fType & MFT_BITMAP) &&
1126 (LOWORD(menuInfo.dwTypeData)!=0) &&
1127 (LOWORD(menuInfo.dwTypeData)!=HBITMAP_16(hBmpClose)) )
1129 DeleteObject(HBITMAP_32(LOWORD(menuInfo.dwTypeData)));
1132 if(TWEAK_WineLook > WIN31_LOOK)
1135 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1138 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1140 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1148 /**********************************************************************
1149 * MDI_UpdateFrameText
1151 * used when child window is maximized/restored
1153 * Note: lpTitle can be NULL
1155 static void MDI_UpdateFrameText( HWND frame, HWND hClient,
1156 BOOL repaint, LPCWSTR lpTitle )
1158 WCHAR lpBuffer[MDI_MAXTITLELENGTH+1];
1159 MDICLIENTINFO *ci = get_client_info( hClient );
1161 TRACE("repaint %i, frameText %s\n", repaint, debugstr_w(lpTitle));
1165 if (!lpTitle && !ci->frameTitle) /* first time around, get title from the frame window */
1167 GetWindowTextW( frame, lpBuffer, sizeof(lpBuffer)/sizeof(WCHAR) );
1171 /* store new "default" title if lpTitle is not NULL */
1174 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1175 if ((ci->frameTitle = HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle)+1)*sizeof(WCHAR))))
1176 strcpyW( ci->frameTitle, lpTitle );
1181 if (ci->hwndChildMaximized)
1183 /* combine frame title and child title if possible */
1185 static const WCHAR lpBracket[] = {' ','-',' ','[',0};
1186 static const WCHAR lpBracket2[] = {']',0};
1187 int i_frame_text_length = strlenW(ci->frameTitle);
1189 lstrcpynW( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
1191 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
1193 strcatW( lpBuffer, lpBracket );
1194 if (GetWindowTextW( ci->hwndChildMaximized, lpBuffer + i_frame_text_length + 4,
1195 MDI_MAXTITLELENGTH - i_frame_text_length - 5 ))
1196 strcatW( lpBuffer, lpBracket2 );
1198 lpBuffer[i_frame_text_length] = 0; /* remove bracket */
1203 lstrcpynW(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH+1 );
1209 DefWindowProcW( frame, WM_SETTEXT, 0, (LPARAM)lpBuffer );
1210 if( repaint == MDI_REPAINTFRAME)
1211 SetWindowPos( frame, 0,0,0,0,0, SWP_FRAMECHANGED |
1212 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
1216 /* ----------------------------- Interface ---------------------------- */
1219 /**********************************************************************
1220 * MDIClientWndProc_common
1222 static LRESULT MDIClientWndProc_common( HWND hwnd, UINT message,
1223 WPARAM wParam, LPARAM lParam, BOOL unicode )
1227 if (!(ci = get_client_info( hwnd ))) return 0;
1234 /* Since we are using only cs->lpCreateParams, we can safely
1235 * cast to LPCREATESTRUCTA here */
1236 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
1237 WND *wndPtr = WIN_GetPtr( hwnd );
1239 /* Translation layer doesn't know what's in the cs->lpCreateParams
1240 * so we have to keep track of what environment we're in. */
1242 if( wndPtr->flags & WIN_ISWIN32 )
1244 #define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1245 ci->hWindowMenu = ccs->hWindowMenu;
1246 ci->idFirstChild = ccs->idFirstChild;
1251 LPCLIENTCREATESTRUCT16 ccs = MapSL((SEGPTR)cs->lpCreateParams);
1252 ci->hWindowMenu = HMENU_32(ccs->hWindowMenu);
1253 ci->idFirstChild = ccs->idFirstChild;
1255 WIN_ReleasePtr( wndPtr );
1257 ci->hwndChildMaximized = 0;
1258 ci->nActiveChildren = 0;
1259 ci->nTotalCreated = 0;
1260 ci->frameTitle = NULL;
1262 SetWindowLongW( hwnd, GWL_STYLE, GetWindowLongW(hwnd,GWL_STYLE) | WS_CLIPCHILDREN );
1264 if (!hBmpClose) hBmpClose = CreateMDIMenuBitmap();
1266 if (ci->hWindowMenu != 0)
1267 AppendMenuW( ci->hWindowMenu, MF_SEPARATOR, 0, NULL );
1269 GetClientRect( GetParent(hwnd), &rect);
1270 MoveWindow( hwnd, 0, 0, rect.right, rect.bottom, FALSE );
1272 MDI_UpdateFrameText( GetParent(hwnd), hwnd, MDI_NOFRAMEREPAINT, NULL);
1274 TRACE("Client created - hwnd = %p, idFirst = %u\n", hwnd, ci->idFirstChild );
1281 if( ci->hwndChildMaximized )
1282 MDI_RestoreFrameMenu( GetParent(hwnd), ci->hwndChildMaximized);
1283 if((ci->hWindowMenu != 0) &&
1284 (nItems = GetMenuItemCount(ci->hWindowMenu)) > 0)
1286 ci->idFirstChild = nItems - 1;
1287 ci->nActiveChildren++; /* to delete a separator */
1288 while( ci->nActiveChildren-- )
1289 DeleteMenu(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
1291 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1295 case WM_MDIACTIVATE:
1296 if( ci->hwndActiveChild != (HWND)wParam )
1297 SetWindowPos((HWND)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
1301 return MDICascade(hwnd, ci);
1305 return (LRESULT)MDICreateChild( hwnd, ci, (MDICREATESTRUCTA *)lParam, unicode );
1309 return MDIDestroyChild( hwnd, ci, WIN_GetFullHandle( (HWND)wParam ), TRUE );
1311 case WM_MDIGETACTIVE:
1312 if (lParam) *(BOOL *)lParam = (ci->hwndChildMaximized != 0);
1313 return (LRESULT)ci->hwndActiveChild;
1315 case WM_MDIICONARRANGE:
1316 ci->mdiFlags |= MDIF_NEEDUPDATE;
1317 ArrangeIconicWindows( hwnd );
1318 ci->sbRecalc = SB_BOTH+1;
1319 SendMessageW( hwnd, WM_MDICALCCHILDSCROLL, 0, 0 );
1322 case WM_MDIMAXIMIZE:
1323 ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1326 case WM_MDINEXT: /* lParam != 0 means previous window */
1327 MDI_SwitchActiveChild( hwnd, WIN_GetFullHandle( (HWND)wParam ), !lParam );
1331 SendMessageW( (HWND)wParam, WM_SYSCOMMAND, SC_RESTORE, 0);
1335 return MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1337 case WM_MDIREFRESHMENU:
1338 return MDIRefreshMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1341 ci->mdiFlags |= MDIF_NEEDUPDATE;
1342 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1343 MDITile( hwnd, ci, wParam );
1344 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1349 ci->mdiFlags |= MDIF_NEEDUPDATE;
1350 ScrollChildren( hwnd, message, wParam, lParam );
1351 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1355 if (ci->hwndActiveChild && !IsIconic( ci->hwndActiveChild ))
1356 SetFocus( ci->hwndActiveChild );
1360 if( ci->hwndActiveChild )
1361 SendMessageW(ci->hwndActiveChild, message, wParam, lParam);
1364 case WM_PARENTNOTIFY:
1365 if (LOWORD(wParam) == WM_LBUTTONDOWN)
1369 pt.x = (short)LOWORD(lParam);
1370 pt.y = (short)HIWORD(lParam);
1371 child = ChildWindowFromPoint(hwnd, pt);
1373 TRACE("notification from %p (%li,%li)\n",child,pt.x,pt.y);
1375 if( child && child != hwnd && child != ci->hwndActiveChild )
1376 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1381 if( IsWindow(ci->hwndChildMaximized) )
1387 rect.right = LOWORD(lParam);
1388 rect.bottom = HIWORD(lParam);
1390 AdjustWindowRectEx(&rect, GetWindowLongA(ci->hwndChildMaximized,GWL_STYLE),
1391 0, GetWindowLongA(ci->hwndChildMaximized,GWL_EXSTYLE) );
1392 MoveWindow(ci->hwndChildMaximized, rect.left, rect.top,
1393 rect.right - rect.left, rect.bottom - rect.top, 1);
1396 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1400 case WM_MDICALCCHILDSCROLL:
1401 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1403 CalcChildScroll(hwnd, ci->sbRecalc-1);
1405 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1409 return unicode ? DefWindowProcW( hwnd, message, wParam, lParam ) :
1410 DefWindowProcA( hwnd, message, wParam, lParam );
1413 /***********************************************************************
1416 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1418 if (!IsWindow(hwnd)) return 0;
1419 return MDIClientWndProc_common( hwnd, message, wParam, lParam, FALSE );
1422 /***********************************************************************
1425 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1427 if (!IsWindow(hwnd)) return 0;
1428 return MDIClientWndProc_common( hwnd, message, wParam, lParam, TRUE );
1431 /***********************************************************************
1432 * DefFrameProc (USER.445)
1434 LRESULT WINAPI DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient,
1435 UINT16 message, WPARAM16 wParam, LPARAM lParam )
1440 lParam = (LPARAM)MapSL(lParam);
1446 return DefFrameProcA( WIN_Handle32(hwnd), WIN_Handle32(hwndMDIClient),
1447 message, wParam, lParam );
1451 MDINEXTMENU next_menu;
1452 DefFrameProcW( WIN_Handle32(hwnd), WIN_Handle32(hwndMDIClient),
1453 message, wParam, (LPARAM)&next_menu );
1454 return MAKELONG( HMENU_16(next_menu.hmenuNext), HWND_16(next_menu.hwndNext) );
1457 return DefWindowProc16(hwnd, message, wParam, lParam);
1462 /***********************************************************************
1463 * DefFrameProcA (USER32.@)
1465 LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1466 UINT message, WPARAM wParam, LPARAM lParam)
1474 DWORD len = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0 );
1475 LPWSTR text = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1476 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, text, len );
1477 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, text );
1478 HeapFree( GetProcessHeap(), 0, text );
1480 return 1; /* success. FIXME: check text length */
1487 return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1490 return DefWindowProcA(hwnd, message, wParam, lParam);
1494 /***********************************************************************
1495 * DefFrameProcW (USER32.@)
1497 LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1498 UINT message, WPARAM wParam, LPARAM lParam)
1500 MDICLIENTINFO *ci = get_client_info( hwndMDIClient );
1508 WORD id = LOWORD(wParam);
1509 /* check for possible syscommands for maximized MDI child */
1510 if (id < ci->idFirstChild || id >= ci->idFirstChild + ci->nActiveChildren)
1512 if( (id - 0xf000) & 0xf00f ) break;
1513 if( !ci->hwndChildMaximized ) break;
1524 return SendMessageW( ci->hwndChildMaximized, WM_SYSCOMMAND,
1531 if (id - ci->idFirstChild == MDI_MOREWINDOWSLIMIT)
1532 /* User chose "More Windows..." */
1533 childHwnd = MDI_MoreWindowsDialog(hwndMDIClient);
1535 /* User chose one of the windows listed in the "Windows" menu */
1536 childHwnd = MDI_GetChildByID(hwndMDIClient,id);
1539 SendMessageW( hwndMDIClient, WM_MDIACTIVATE, (WPARAM)childHwnd, 0 );
1545 SendMessageW(hwndMDIClient, message, wParam, lParam);
1549 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, (LPWSTR)lParam );
1550 return 1; /* success. FIXME: check text length */
1553 SetFocus(hwndMDIClient);
1557 MoveWindow(hwndMDIClient, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
1562 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1564 if (!IsIconic(hwnd) && ci->hwndActiveChild && !ci->hwndChildMaximized)
1566 /* control menu is between the frame system menu and
1567 * the first entry of menu bar */
1568 WND *wndPtr = WIN_GetPtr(hwnd);
1570 if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1571 (wParam == VK_RIGHT && GetSubMenu(wndPtr->hSysMenu, 0) == next_menu->hmenuIn) )
1573 WIN_ReleasePtr(wndPtr);
1574 wndPtr = WIN_GetPtr(ci->hwndActiveChild);
1575 next_menu->hmenuNext = GetSubMenu(wndPtr->hSysMenu, 0);
1576 next_menu->hwndNext = ci->hwndActiveChild;
1578 WIN_ReleasePtr(wndPtr);
1585 return DefWindowProcW( hwnd, message, wParam, lParam );
1589 /***********************************************************************
1590 * DefMDIChildProc (USER.447)
1592 LRESULT WINAPI DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1593 WPARAM16 wParam, LPARAM lParam )
1598 return DefMDIChildProcA( WIN_Handle32(hwnd), message, wParam, (LPARAM)MapSL(lParam) );
1602 case WM_CHILDACTIVATE:
1607 return DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, lParam );
1608 case WM_GETMINMAXINFO:
1610 MINMAXINFO16 *mmi16 = (MINMAXINFO16 *)MapSL(lParam);
1612 STRUCT32_MINMAXINFO16to32( mmi16, &mmi );
1613 DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, (LPARAM)&mmi );
1614 STRUCT32_MINMAXINFO32to16( &mmi, mmi16 );
1619 MDINEXTMENU next_menu;
1620 DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, (LPARAM)&next_menu );
1621 return MAKELONG( HMENU_16(next_menu.hmenuNext), HWND_16(next_menu.hwndNext) );
1624 return DefWindowProc16(hwnd, message, wParam, lParam);
1629 /***********************************************************************
1630 * DefMDIChildProcA (USER32.@)
1632 LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1633 WPARAM wParam, LPARAM lParam )
1635 HWND client = GetParent(hwnd);
1636 MDICLIENTINFO *ci = get_client_info( client );
1638 hwnd = WIN_GetFullHandle( hwnd );
1639 if (!ci) return DefWindowProcA( hwnd, message, wParam, lParam );
1644 DefWindowProcA(hwnd, message, wParam, lParam);
1645 MDI_MenuModifyItem( client, hwnd );
1646 if( ci->hwndChildMaximized == hwnd )
1647 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1648 return 1; /* success. FIXME: check text length */
1650 case WM_GETMINMAXINFO:
1654 case WM_CHILDACTIVATE:
1660 return DefMDIChildProcW( hwnd, message, wParam, lParam );
1662 return DefWindowProcA(hwnd, message, wParam, lParam);
1666 /***********************************************************************
1667 * DefMDIChildProcW (USER32.@)
1669 LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1670 WPARAM wParam, LPARAM lParam )
1672 HWND client = GetParent(hwnd);
1673 MDICLIENTINFO *ci = get_client_info( client );
1675 hwnd = WIN_GetFullHandle( hwnd );
1676 if (!ci) return DefWindowProcW( hwnd, message, wParam, lParam );
1681 DefWindowProcW(hwnd, message, wParam, lParam);
1682 MDI_MenuModifyItem( client, hwnd );
1683 if( ci->hwndChildMaximized == hwnd )
1684 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1685 return 1; /* success. FIXME: check text length */
1687 case WM_GETMINMAXINFO:
1688 MDI_ChildGetMinMaxInfo( client, hwnd, (MINMAXINFO *)lParam );
1692 return 0x00010000; /* MDI children don't have menu bars */
1695 SendMessageW( client, WM_MDIDESTROY, (WPARAM)hwnd, 0 );
1699 if (ci->hwndActiveChild != hwnd) MDI_ChildActivate( client, hwnd );
1702 case WM_CHILDACTIVATE:
1703 MDI_ChildActivate( client, hwnd );
1710 if( ci->hwndChildMaximized == hwnd) return 0;
1714 SetWindowLongW( hwnd, GWL_STYLE,
1715 GetWindowLongW( hwnd, GWL_STYLE ) | WS_SYSMENU );
1718 if (ci->hwndChildMaximized == hwnd)
1719 return SendMessageW( GetParent(client), message, wParam, lParam);
1720 SetWindowLongW( hwnd, GWL_STYLE,
1721 GetWindowLongW( hwnd, GWL_STYLE ) & ~WS_SYSMENU );
1724 SendMessageW( client, WM_MDINEXT, 0, 0);
1727 SendMessageW( client, WM_MDINEXT, 0, 1);
1733 if( ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1734 else MDI_PostUpdate(client, ci, SB_BOTH+1);
1738 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1740 ci->hwndChildMaximized = 0;
1741 MDI_RestoreFrameMenu( GetParent(client), hwnd );
1742 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1745 if( wParam == SIZE_MAXIMIZED )
1747 HWND hMaxChild = ci->hwndChildMaximized;
1749 if( hMaxChild == hwnd ) break;
1752 SendMessageW( hMaxChild, WM_SETREDRAW, FALSE, 0 );
1753 MDI_RestoreFrameMenu( GetParent(client), hMaxChild );
1754 ShowWindow( hMaxChild, SW_SHOWNOACTIVATE );
1755 SendMessageW( hMaxChild, WM_SETREDRAW, TRUE, 0 );
1757 TRACE("maximizing child %p\n", hwnd );
1759 /* keep track of the maximized window. */
1760 ci->hwndChildMaximized = hwnd; /* !!! */
1762 /* The maximized window should also be the active window */
1763 MDI_ChildActivate( client, hwnd );
1764 MDI_AugmentFrameMenu( GetParent(client), hwnd );
1765 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1768 if( wParam == SIZE_MINIMIZED )
1770 HWND switchTo = MDI_GetWindow(ci, hwnd, TRUE, WS_MINIMIZE);
1772 if (switchTo) SendMessageW( switchTo, WM_CHILDACTIVATE, 0, 0);
1774 MDI_PostUpdate(client, ci, SB_BOTH+1);
1779 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1780 HWND parent = GetParent(client);
1782 if( wParam == VK_LEFT ) /* switch to frame system menu */
1784 WND *wndPtr = WIN_GetPtr( parent );
1785 next_menu->hmenuNext = GetSubMenu( wndPtr->hSysMenu, 0 );
1786 WIN_ReleasePtr( wndPtr );
1788 if( wParam == VK_RIGHT ) /* to frame menu bar */
1790 next_menu->hmenuNext = GetMenu(parent);
1792 next_menu->hwndNext = parent;
1799 SendMessageW( hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (DWORD)VK_SPACE);
1804 return DefWindowProcW(hwnd, message, wParam, lParam);
1807 /**********************************************************************
1808 * CreateMDIWindowA (USER32.@) Creates a MDI child
1811 * Success: Handle to created window
1814 HWND WINAPI CreateMDIWindowA(
1815 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1816 LPCSTR lpWindowName, /* [in] Pointer to window name */
1817 DWORD dwStyle, /* [in] Window style */
1818 INT X, /* [in] Horizontal position of window */
1819 INT Y, /* [in] Vertical position of window */
1820 INT nWidth, /* [in] Width of window */
1821 INT nHeight, /* [in] Height of window */
1822 HWND hWndParent, /* [in] Handle to parent window */
1823 HINSTANCE hInstance, /* [in] Handle to application instance */
1824 LPARAM lParam) /* [in] Application-defined value */
1826 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1827 MDICREATESTRUCTA cs;
1829 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%p,%p,%ld)\n",
1830 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1831 nWidth,nHeight,hWndParent,hInstance,lParam);
1835 ERR("bad hwnd for MDI-client: %p\n", hWndParent);
1838 cs.szClass=lpClassName;
1839 cs.szTitle=lpWindowName;
1840 cs.hOwner=hInstance;
1848 return MDICreateChild(hWndParent, pCi, &cs, FALSE);
1851 /***********************************************************************
1852 * CreateMDIWindowW (USER32.@) Creates a MDI child
1855 * Success: Handle to created window
1858 HWND WINAPI CreateMDIWindowW(
1859 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1860 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1861 DWORD dwStyle, /* [in] Window style */
1862 INT X, /* [in] Horizontal position of window */
1863 INT Y, /* [in] Vertical position of window */
1864 INT nWidth, /* [in] Width of window */
1865 INT nHeight, /* [in] Height of window */
1866 HWND hWndParent, /* [in] Handle to parent window */
1867 HINSTANCE hInstance, /* [in] Handle to application instance */
1868 LPARAM lParam) /* [in] Application-defined value */
1870 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1871 MDICREATESTRUCTW cs;
1873 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%p,%p,%ld)\n",
1874 debugstr_w(lpClassName), debugstr_w(lpWindowName), dwStyle, X, Y,
1875 nWidth, nHeight, hWndParent, hInstance, lParam);
1879 ERR("bad hwnd for MDI-client: %p\n", hWndParent);
1882 cs.szClass = lpClassName;
1883 cs.szTitle = lpWindowName;
1884 cs.hOwner = hInstance;
1892 return MDICreateChild(hWndParent, pCi, (MDICREATESTRUCTA *)&cs, TRUE);
1895 /**********************************************************************
1896 * TranslateMDISysAccel (USER32.@)
1898 BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1900 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1902 MDICLIENTINFO *ci = get_client_info( hwndClient );
1905 if (!ci || !IsWindowEnabled(ci->hwndActiveChild)) return 0;
1907 /* translate if the Ctrl key is down and Alt not. */
1909 if( (GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
1911 switch( msg->wParam )
1915 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 ) ? SC_NEXTWINDOW : SC_PREVWINDOW;
1924 TRACE("wParam = %04x\n", wParam);
1925 SendMessageW(ci->hwndActiveChild, WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
1929 return 0; /* failure */
1932 /***********************************************************************
1933 * CalcChildScroll (USER32.@)
1935 void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
1938 RECT childRect, clientRect;
1941 GetClientRect( hwnd, &clientRect );
1942 SetRectEmpty( &childRect );
1944 if ((list = WIN_ListChildren( hwnd )))
1947 for (i = 0; list[i]; i++)
1949 DWORD style = GetWindowLongW( list[i], GWL_STYLE );
1950 if (style & WS_MAXIMIZE)
1952 HeapFree( GetProcessHeap(), 0, list );
1953 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1956 if (style & WS_VISIBLE)
1958 WND *pWnd = WIN_FindWndPtr( list[i] );
1959 UnionRect( &childRect, &pWnd->rectWindow, &childRect );
1960 WIN_ReleaseWndPtr( pWnd );
1963 HeapFree( GetProcessHeap(), 0, list );
1965 UnionRect( &childRect, &clientRect, &childRect );
1967 /* set common info values */
1968 info.cbSize = sizeof(info);
1969 info.fMask = SIF_POS | SIF_RANGE;
1971 /* set the specific */
1976 info.nMin = childRect.left;
1977 info.nMax = childRect.right - clientRect.right;
1978 info.nPos = clientRect.left - childRect.left;
1979 SetScrollInfo(hwnd, scroll, &info, TRUE);
1980 if (scroll == SB_HORZ) break;
1983 info.nMin = childRect.top;
1984 info.nMax = childRect.bottom - clientRect.bottom;
1985 info.nPos = clientRect.top - childRect.top;
1986 SetScrollInfo(hwnd, scroll, &info, TRUE);
1992 /***********************************************************************
1993 * ScrollChildren (USER32.@)
1995 void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
1999 INT curPos, length, minPos, maxPos, shift;
2002 GetClientRect( hWnd, &rect );
2007 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
2008 curPos = GetScrollPos(hWnd,SB_HORZ);
2009 length = (rect.right - rect.left) / 2;
2010 shift = GetSystemMetrics(SM_CYHSCROLL);
2013 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
2014 curPos = GetScrollPos(hWnd,SB_VERT);
2015 length = (rect.bottom - rect.top) / 2;
2016 shift = GetSystemMetrics(SM_CXVSCROLL);
2025 newPos = curPos - shift;
2028 newPos = curPos + shift;
2031 newPos = curPos - length;
2034 newPos = curPos + length;
2037 case SB_THUMBPOSITION:
2038 newPos = LOWORD(lParam);
2051 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
2055 if( newPos > maxPos )
2058 if( newPos < minPos )
2061 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
2063 if( uMsg == WM_VSCROLL )
2064 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
2065 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2067 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
2068 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2072 /******************************************************************************
2073 * CascadeWindows (USER32.@) Cascades MDI child windows
2076 * Success: Number of cascaded windows.
2080 CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2081 UINT cKids, const HWND *lpKids)
2083 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
2088 /******************************************************************************
2089 * TileWindows (USER32.@) Tiles MDI child windows
2092 * Success: Number of tiled windows.
2096 TileWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2097 UINT cKids, const HWND *lpKids)
2099 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
2103 /************************************************************************
2104 * "More Windows..." functionality
2107 /* MDI_MoreWindowsDlgProc
2109 * This function will process the messages sent to the "More Windows..."
2111 * Return values: 0 = cancel pressed
2112 * HWND = ok pressed or double-click in the list...
2116 static INT_PTR WINAPI MDI_MoreWindowsDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
2125 MDICLIENTINFO *ci = get_client_info( (HWND)lParam );
2126 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2127 HWND *list, *sorted_list;
2129 if (!(list = WIN_ListChildren( (HWND)lParam ))) return TRUE;
2130 if (!(sorted_list = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
2131 sizeof(HWND) * ci->nActiveChildren )))
2133 HeapFree( GetProcessHeap(), 0, list );
2137 /* Fill the list, sorted by id... */
2138 for (i = 0; list[i]; i++)
2140 UINT id = GetWindowLongW( list[i], GWL_ID ) - ci->idFirstChild;
2141 if (id < ci->nActiveChildren) sorted_list[id] = list[i];
2143 HeapFree( GetProcessHeap(), 0, list );
2145 for (i = 0; i < ci->nActiveChildren; i++)
2149 if (!GetWindowTextW( sorted_list[i], buffer, sizeof(buffer)/sizeof(WCHAR) ))
2151 SendMessageW(hListBox, LB_ADDSTRING, 0, (LPARAM)buffer );
2152 SendMessageW(hListBox, LB_SETITEMDATA, i, (LPARAM)sorted_list[i] );
2153 length = strlenW(buffer); /* FIXME: should use GetTextExtentPoint */
2154 if (length > widest)
2157 /* Make sure the horizontal scrollbar scrolls ok */
2158 SendMessageW(hListBox, LB_SETHORIZONTALEXTENT, widest * 6, 0);
2160 /* Set the current selection */
2161 SendMessageW(hListBox, LB_SETCURSEL, MDI_MOREWINDOWSLIMIT, 0);
2166 switch (LOWORD(wParam))
2169 if (HIWORD(wParam) != LBN_DBLCLK) break;
2173 /* windows are sorted by menu ID, so we must return the
2174 * window associated to the given id
2176 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2177 UINT index = SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
2178 LRESULT res = SendMessageW(hListBox, LB_GETITEMDATA, index, 0);
2179 EndDialog(hDlg, res);
2193 * MDI_MoreWindowsDialog
2195 * Prompts the user with a listbox containing the opened
2196 * documents. The user can then choose a windows and click
2197 * on OK to set the current window to the one selected, or
2198 * CANCEL to cancel. The function returns a handle to the
2202 static HWND MDI_MoreWindowsDialog(HWND hwnd)
2208 hRes = FindResourceA(GetModuleHandleA("USER32"), "MDI_MOREWINDOWS", (LPSTR)RT_DIALOG);
2213 hDlgTmpl = LoadResource(GetModuleHandleA("USER32"), hRes );
2218 template = LockResource( hDlgTmpl );
2223 return (HWND) DialogBoxIndirectParamA(GetModuleHandleA("USER32"),
2224 (LPDLGTEMPLATEA) template,
2225 hwnd, MDI_MoreWindowsDlgProc, (LPARAM) hwnd);
2232 * Will swap the menu IDs for the given 2 positions.
2233 * pos1 and pos2 are menu IDs
2238 static void MDI_SwapMenuItems(HWND parent, UINT pos1, UINT pos2)
2243 if (!(list = WIN_ListChildren( parent ))) return;
2244 for (i = 0; list[i]; i++)
2246 UINT id = GetWindowLongW( list[i], GWL_ID );
2247 if (id == pos1) SetWindowLongW( list[i], GWL_ID, pos2 );
2248 else if (id == pos2) SetWindowLongW( list[i], GWL_ID, pos1 );
2250 HeapFree( GetProcessHeap(), 0, list );