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 );
542 /* FIXME: CreateWindowEx must be called with WS_EX_MDICHILD set, but
543 * it requires to move MDI specific child creation to CreateWindowEx
544 * and do child tracking in MDICLIENT using WM_PARENTNOTIFY.
548 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)cs;
549 hwnd = CreateWindowExW( 0, csW->szClass, csW->szTitle, style,
550 csW->x, csW->y, csW->cx, csW->cy, parent,
551 (HMENU)wIDmenu, csW->hOwner, csW );
554 hwnd = CreateWindowExA( 0, cs->szClass, cs->szTitle, style,
555 cs->x, cs->y, cs->cx, cs->cy, parent,
556 (HMENU)wIDmenu, cs->hOwner, cs );
560 MDICREATESTRUCT16 cs16;
561 SEGPTR title, cls, seg_cs16;
563 WIN_ReleaseWndPtr( wndParent );
564 STRUCT32_MDICREATESTRUCT32Ato16( cs, &cs16 );
565 cs16.szTitle = title = MapLS( cs->szTitle );
566 cs16.szClass = cls = MapLS( cs->szClass );
567 seg_cs16 = MapLS( &cs16 );
568 hwnd = WIN_Handle32( CreateWindowEx16( 0, cs->szClass, cs->szTitle, style,
569 cs16.x, cs16.y, cs16.cx, cs16.cy,
570 HWND_16(parent), (HMENU16)wIDmenu,
571 cs16.hOwner, (LPVOID)seg_cs16 ));
577 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
581 /* All MDI child windows have the WS_EX_MDICHILD style */
582 SetWindowLongW( hwnd, GWL_EXSTYLE, GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_MDICHILD );
584 /* If we have more than 9 windows, we must insert the new one at the
585 * 9th position in order to see it in the "Windows" menu
587 if (ci->nActiveChildren > MDI_MOREWINDOWSLIMIT)
588 MDI_SwapMenuItems( parent, GetWindowLongW( hwnd, GWL_ID ),
589 ci->idFirstChild + MDI_MOREWINDOWSLIMIT - 1);
591 MDI_MenuModifyItem(parent, hwnd);
593 /* Have we hit the "More Windows..." limit? If so, we must
594 * add a "More Windows..." option
596 if (ci->nActiveChildren == MDI_MOREWINDOWSLIMIT + 1)
599 LoadStringW(GetModuleHandleA("USER32"), IDS_MDI_MOREWINDOWS, szTmp, sizeof(szTmp)/sizeof(szTmp[0]));
601 ModifyMenuW(ci->hWindowMenu,
602 ci->idFirstChild + MDI_MOREWINDOWSLIMIT,
603 MF_BYCOMMAND | MF_STRING,
604 ci->idFirstChild + MDI_MOREWINDOWSLIMIT,
608 if( IsIconic(hwnd) && ci->hwndActiveChild )
610 TRACE("Minimizing created MDI child %p\n", hwnd);
611 ShowWindow( hwnd, SW_SHOWMINNOACTIVE );
615 /* WS_VISIBLE is clear if a) the MDI client has
616 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
617 * MDICreateStruct. If so the created window is not shown nor
620 if (IsWindowVisible(hwnd)) ShowWindow(hwnd, SW_SHOW);
622 TRACE("created child - %p\n",hwnd);
626 ci->nActiveChildren--;
627 DeleteMenu(ci->hWindowMenu,wIDmenu,MF_BYCOMMAND);
628 if( IsWindow(hwndMax) )
629 ShowWindow(hwndMax, SW_SHOWMAXIMIZED);
635 /**********************************************************************
636 * MDI_ChildGetMinMaxInfo
638 * Note: The rule here is that client rect of the maximized MDI child
639 * is equal to the client rect of the MDI client window.
641 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
645 GetClientRect( client, &rect );
646 AdjustWindowRectEx( &rect, GetWindowLongW( hwnd, GWL_STYLE ),
647 0, GetWindowLongW( hwnd, GWL_EXSTYLE ));
649 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
650 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
652 lpMinMax->ptMaxPosition.x = rect.left;
653 lpMinMax->ptMaxPosition.y = rect.top;
655 TRACE("max rect (%ld,%ld - %ld, %ld)\n",
656 rect.left,rect.top,rect.right,rect.bottom);
659 /**********************************************************************
660 * MDI_SwitchActiveChild
662 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
665 static void MDI_SwitchActiveChild( HWND clientHwnd, HWND childHwnd,
670 MDICLIENTINFO *ci = get_client_info( clientHwnd );
672 hwndTo = MDI_GetWindow(ci, childHwnd, bNextWindow, 0);
674 TRACE("from %p, to %p\n",childHwnd,hwndTo);
676 if ( !hwndTo ) return; /* no window to switch to */
678 hwndPrev = ci->hwndActiveChild;
680 if ( hwndTo != hwndPrev )
682 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0,
683 SWP_NOMOVE | SWP_NOSIZE );
685 if( bNextWindow && hwndPrev )
686 SetWindowPos( hwndPrev, HWND_BOTTOM, 0, 0, 0, 0,
687 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
692 /**********************************************************************
695 static LRESULT MDIDestroyChild( HWND parent, MDICLIENTINFO *ci,
696 HWND child, BOOL flagDestroy )
698 if( child == ci->hwndActiveChild )
700 MDI_SwitchActiveChild(parent, child, TRUE);
702 if( child == ci->hwndActiveChild )
704 ShowWindow( child, SW_HIDE);
705 if( child == ci->hwndChildMaximized )
707 HWND frame = GetParent(parent);
708 MDI_RestoreFrameMenu( frame, child );
709 ci->hwndChildMaximized = 0;
710 MDI_UpdateFrameText( frame, parent, TRUE, NULL);
713 MDI_ChildActivate(parent, 0);
717 MDI_MenuDeleteItem(parent, child);
719 ci->nActiveChildren--;
721 TRACE("child destroyed - %p\n",child);
725 MDI_PostUpdate(GetParent(child), ci, SB_BOTH+1);
726 DestroyWindow(child);
732 /**********************************************************************
735 * Note: hWndChild is NULL when last child is being destroyed
737 static LONG MDI_ChildActivate( HWND client, HWND child )
739 MDICLIENTINFO *clientInfo = get_client_info( client );
740 HWND prevActiveWnd = clientInfo->hwndActiveChild;
741 BOOL isActiveFrameWnd;
743 if (child && (!IsWindowEnabled( child ))) return 0;
745 /* Don't activate if it is already active. Might happen
746 since ShowWindow DOES activate MDI children */
747 if (clientInfo->hwndActiveChild == child) return 0;
749 TRACE("%p\n", child);
751 isActiveFrameWnd = (GetActiveWindow() == GetParent(client));
753 /* deactivate prev. active child */
756 SetWindowLongA( prevActiveWnd, GWL_STYLE,
757 GetWindowLongA( prevActiveWnd, GWL_STYLE ) | WS_SYSMENU );
758 SendMessageA( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
759 SendMessageA( prevActiveWnd, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child);
760 /* uncheck menu item */
761 if( clientInfo->hWindowMenu )
763 UINT prevID = GetWindowLongA( prevActiveWnd, GWL_ID );
765 if (prevID - clientInfo->idFirstChild < MDI_MOREWINDOWSLIMIT)
766 CheckMenuItem( clientInfo->hWindowMenu, prevID, 0);
768 CheckMenuItem( clientInfo->hWindowMenu,
769 clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1, 0);
774 if (clientInfo->hwndChildMaximized && clientInfo->hwndChildMaximized != child)
776 INT cmd = SW_SHOWNORMAL;
780 UINT state = GetMenuState(GetSystemMenu(child, FALSE), SC_MAXIMIZE, MF_BYCOMMAND);
781 if (state != 0xFFFFFFFF && (state & (MF_DISABLED | MF_GRAYED)))
782 SendMessageW(clientInfo->hwndChildMaximized, WM_SYSCOMMAND, SC_RESTORE, 0);
784 cmd = SW_SHOWMAXIMIZED;
786 clientInfo->hwndActiveChild = child;
789 ShowWindow( clientInfo->hwndActiveChild, cmd );
792 clientInfo->hwndActiveChild = child;
794 /* check if we have any children left */
797 if( isActiveFrameWnd )
802 /* check menu item */
803 if( clientInfo->hWindowMenu )
805 UINT id = GetWindowLongA( child, GWL_ID );
806 /* The window to be activated must be displayed in the "Windows" menu */
807 if (id >= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT)
809 MDI_SwapMenuItems( GetParent(child),
810 id, clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1);
811 id = clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1;
812 MDI_MenuModifyItem( GetParent(child), child );
815 CheckMenuItem(clientInfo->hWindowMenu, id, MF_CHECKED);
817 /* bring active child to the top */
818 SetWindowPos( child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
820 if( isActiveFrameWnd )
822 SendMessageA( child, WM_NCACTIVATE, TRUE, 0L);
823 if( GetFocus() == client )
824 SendMessageA( client, WM_SETFOCUS, (WPARAM)client, 0L );
828 SendMessageA( child, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child );
832 /* -------------------- MDI client window functions ------------------- */
834 /**********************************************************************
835 * CreateMDIMenuBitmap
837 static HBITMAP CreateMDIMenuBitmap(void)
839 HDC hDCSrc = CreateCompatibleDC(0);
840 HDC hDCDest = CreateCompatibleDC(hDCSrc);
841 HBITMAP hbClose = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_OLD_CLOSE) );
843 HBITMAP hobjSrc, hobjDest;
845 hobjSrc = SelectObject(hDCSrc, hbClose);
846 hbCopy = CreateCompatibleBitmap(hDCSrc,GetSystemMetrics(SM_CXSIZE),GetSystemMetrics(SM_CYSIZE));
847 hobjDest = SelectObject(hDCDest, hbCopy);
849 BitBlt(hDCDest, 0, 0, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE),
850 hDCSrc, GetSystemMetrics(SM_CXSIZE), 0, SRCCOPY);
852 SelectObject(hDCSrc, hobjSrc);
853 DeleteObject(hbClose);
856 hobjSrc = SelectObject( hDCDest, GetStockObject(BLACK_PEN) );
858 MoveToEx( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, 0, NULL );
859 LineTo( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, GetSystemMetrics(SM_CYSIZE) - 1);
861 SelectObject(hDCDest, hobjSrc );
862 SelectObject(hDCDest, hobjDest);
868 /**********************************************************************
871 static LONG MDICascade( HWND client, MDICLIENTINFO *ci )
874 BOOL has_icons = FALSE;
877 if (ci->hwndChildMaximized)
878 SendMessageA( client, WM_MDIRESTORE,
879 (WPARAM)ci->hwndChildMaximized, 0);
881 if (ci->nActiveChildren == 0) return 0;
883 if (!(win_array = WIN_ListChildren( client ))) return 0;
885 /* remove all the windows we don't want */
886 for (i = total = 0; win_array[i]; i++)
888 if (!IsWindowVisible( win_array[i] )) continue;
889 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows */
890 if (IsIconic( win_array[i] ))
895 win_array[total++] = win_array[i];
897 win_array[total] = 0;
901 INT delta = 0, n = 0, i;
903 if (has_icons) delta = GetSystemMetrics(SM_CYICONSPACING) + GetSystemMetrics(SM_CYICON);
905 /* walk the list (backwards) and move windows */
906 for (i = total - 1; i >= 0; i--)
908 TRACE("move %p to (%ld,%ld) size [%ld,%ld]\n",
909 win_array[i], pos[0].x, pos[0].y, pos[1].x, pos[1].y);
911 MDI_CalcDefaultChildPos(client, n++, pos, delta);
912 SetWindowPos( win_array[i], 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
913 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
916 HeapFree( GetProcessHeap(), 0, win_array );
918 if (has_icons) ArrangeIconicWindows( client );
922 /**********************************************************************
925 static void MDITile( HWND client, MDICLIENTINFO *ci, WPARAM wParam )
929 BOOL has_icons = FALSE;
931 if (ci->hwndChildMaximized)
932 SendMessageA( client, WM_MDIRESTORE, (WPARAM)ci->hwndChildMaximized, 0);
934 if (ci->nActiveChildren == 0) return;
936 if (!(win_array = WIN_ListChildren( client ))) return;
938 /* remove all the windows we don't want */
939 for (i = total = 0; win_array[i]; i++)
941 if (!IsWindowVisible( win_array[i] )) continue;
942 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows (icon titles) */
943 if (IsIconic( win_array[i] ))
948 if ((wParam & MDITILE_SKIPDISABLED) && !IsWindowEnabled( win_array[i] )) continue;
949 win_array[total++] = win_array[i];
951 win_array[total] = 0;
953 TRACE("%u windows to tile\n", total);
957 HWND *pWnd = win_array;
959 int x, y, xsize, ysize;
960 int rows, columns, r, c, i;
962 GetClientRect(client,&rect);
963 rows = (int) sqrt((double)total);
964 columns = total / rows;
966 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
969 rows = columns; /* exchange r and c */
975 y = rect.bottom - 2 * GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
976 rect.bottom = ( y - GetSystemMetrics(SM_CYICON) < rect.top )? rect.bottom: y;
979 ysize = rect.bottom / rows;
980 xsize = rect.right / columns;
982 for (x = i = 0, c = 1; c <= columns && *pWnd; c++)
987 ysize = rect.bottom / rows;
991 for (r = 1; r <= rows && *pWnd; r++, i++)
993 SetWindowPos(*pWnd, 0, x, y, xsize, ysize,
994 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
1001 HeapFree( GetProcessHeap(), 0, win_array );
1002 if (has_icons) ArrangeIconicWindows( client );
1005 /* ----------------------- Frame window ---------------------------- */
1008 /**********************************************************************
1009 * MDI_AugmentFrameMenu
1011 static BOOL MDI_AugmentFrameMenu( HWND frame, HWND hChild )
1013 HMENU menu = GetMenu( frame );
1014 WND* child = WIN_FindWndPtr(hChild);
1015 HMENU hSysPopup = 0;
1016 HBITMAP hSysMenuBitmap = 0;
1018 TRACE("frame %p,child %p\n",frame,hChild);
1020 if( !menu || !child->hSysMenu )
1022 WIN_ReleaseWndPtr(child);
1025 WIN_ReleaseWndPtr(child);
1027 /* create a copy of sysmenu popup and insert it into frame menu bar */
1029 if (!(hSysPopup = LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU")))
1032 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1033 SC_MINIMIZE, (LPSTR)(DWORD)HBMMENU_MBAR_MINIMIZE ) ;
1034 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1035 SC_RESTORE, (LPSTR)(DWORD)HBMMENU_MBAR_RESTORE );
1037 /* In Win 95 look, the system menu is replaced by the child icon */
1039 if(TWEAK_WineLook > WIN31_LOOK)
1041 HICON hIcon = (HICON)GetClassLongA(hChild, GCL_HICONSM);
1043 hIcon = (HICON)GetClassLongA(hChild, GCL_HICON);
1047 HBITMAP hBitmap, hOldBitmap;
1049 HDC hdc = GetDC(hChild);
1054 cx = GetSystemMetrics(SM_CXSMICON);
1055 cy = GetSystemMetrics(SM_CYSMICON);
1056 hMemDC = CreateCompatibleDC(hdc);
1057 hBitmap = CreateCompatibleBitmap(hdc, cx, cy);
1058 hOldBitmap = SelectObject(hMemDC, hBitmap);
1059 SetMapMode(hMemDC, MM_TEXT);
1060 hBrush = CreateSolidBrush(GetSysColor(COLOR_MENU));
1061 DrawIconEx(hMemDC, 0, 0, hIcon, cx, cy, 0, hBrush, DI_NORMAL);
1062 SelectObject (hMemDC, hOldBitmap);
1063 DeleteObject(hBrush);
1065 ReleaseDC(hChild, hdc);
1066 hSysMenuBitmap = hBitmap;
1071 hSysMenuBitmap = hBmpClose;
1073 if( !InsertMenuA(menu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
1074 (UINT_PTR)hSysPopup, (LPSTR)hSysMenuBitmap))
1076 TRACE("not inserted\n");
1077 DestroyMenu(hSysPopup);
1081 /* The close button is only present in Win 95 look */
1082 if(TWEAK_WineLook > WIN31_LOOK)
1084 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1085 SC_CLOSE, (LPSTR)(DWORD)HBMMENU_MBAR_CLOSE );
1088 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
1089 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
1090 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
1091 SetMenuDefaultItem(hSysPopup, SC_CLOSE, FALSE);
1099 /**********************************************************************
1100 * MDI_RestoreFrameMenu
1102 static BOOL MDI_RestoreFrameMenu( HWND frame, HWND hChild )
1104 MENUITEMINFOW menuInfo;
1105 HMENU menu = GetMenu( frame );
1106 INT nItems = GetMenuItemCount(menu) - 1;
1107 UINT iId = GetMenuItemID(menu,nItems) ;
1109 TRACE("frame %p,child %p,nIt=%d,iId=%d\n",frame,hChild,nItems,iId);
1111 if(!(iId == SC_RESTORE || iId == SC_CLOSE) )
1115 * Remove the system menu, If that menu is the icon of the window
1116 * as it is in win95, we have to delete the bitmap.
1118 memset(&menuInfo, 0, sizeof(menuInfo));
1119 menuInfo.cbSize = sizeof(menuInfo);
1120 menuInfo.fMask = MIIM_DATA | MIIM_TYPE;
1122 GetMenuItemInfoW(menu,
1127 RemoveMenu(menu,0,MF_BYPOSITION);
1129 if ( (menuInfo.fType & MFT_BITMAP) &&
1130 (LOWORD(menuInfo.dwTypeData)!=0) &&
1131 (LOWORD(menuInfo.dwTypeData)!=HBITMAP_16(hBmpClose)) )
1133 DeleteObject(HBITMAP_32(LOWORD(menuInfo.dwTypeData)));
1136 if(TWEAK_WineLook > WIN31_LOOK)
1139 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1142 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1144 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1152 /**********************************************************************
1153 * MDI_UpdateFrameText
1155 * used when child window is maximized/restored
1157 * Note: lpTitle can be NULL
1159 static void MDI_UpdateFrameText( HWND frame, HWND hClient,
1160 BOOL repaint, LPCWSTR lpTitle )
1162 WCHAR lpBuffer[MDI_MAXTITLELENGTH+1];
1163 MDICLIENTINFO *ci = get_client_info( hClient );
1165 TRACE("repaint %i, frameText %s\n", repaint, debugstr_w(lpTitle));
1169 if (!lpTitle && !ci->frameTitle) /* first time around, get title from the frame window */
1171 GetWindowTextW( frame, lpBuffer, sizeof(lpBuffer)/sizeof(WCHAR) );
1175 /* store new "default" title if lpTitle is not NULL */
1178 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1179 if ((ci->frameTitle = HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle)+1)*sizeof(WCHAR))))
1180 strcpyW( ci->frameTitle, lpTitle );
1185 if (ci->hwndChildMaximized)
1187 /* combine frame title and child title if possible */
1189 static const WCHAR lpBracket[] = {' ','-',' ','[',0};
1190 static const WCHAR lpBracket2[] = {']',0};
1191 int i_frame_text_length = strlenW(ci->frameTitle);
1193 lstrcpynW( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
1195 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
1197 strcatW( lpBuffer, lpBracket );
1198 if (GetWindowTextW( ci->hwndChildMaximized, lpBuffer + i_frame_text_length + 4,
1199 MDI_MAXTITLELENGTH - i_frame_text_length - 5 ))
1200 strcatW( lpBuffer, lpBracket2 );
1202 lpBuffer[i_frame_text_length] = 0; /* remove bracket */
1207 lstrcpynW(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH+1 );
1213 DefWindowProcW( frame, WM_SETTEXT, 0, (LPARAM)lpBuffer );
1214 if( repaint == MDI_REPAINTFRAME)
1215 SetWindowPos( frame, 0,0,0,0,0, SWP_FRAMECHANGED |
1216 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
1220 /* ----------------------------- Interface ---------------------------- */
1223 /**********************************************************************
1224 * MDIClientWndProc_common
1226 static LRESULT MDIClientWndProc_common( HWND hwnd, UINT message,
1227 WPARAM wParam, LPARAM lParam, BOOL unicode )
1231 if (!(ci = get_client_info( hwnd ))) return 0;
1238 /* Since we are using only cs->lpCreateParams, we can safely
1239 * cast to LPCREATESTRUCTA here */
1240 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
1241 WND *wndPtr = WIN_GetPtr( hwnd );
1243 /* Translation layer doesn't know what's in the cs->lpCreateParams
1244 * so we have to keep track of what environment we're in. */
1246 if( wndPtr->flags & WIN_ISWIN32 )
1248 #define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1249 ci->hWindowMenu = ccs->hWindowMenu;
1250 ci->idFirstChild = ccs->idFirstChild;
1255 LPCLIENTCREATESTRUCT16 ccs = MapSL((SEGPTR)cs->lpCreateParams);
1256 ci->hWindowMenu = HMENU_32(ccs->hWindowMenu);
1257 ci->idFirstChild = ccs->idFirstChild;
1259 WIN_ReleasePtr( wndPtr );
1261 ci->hwndChildMaximized = 0;
1262 ci->nActiveChildren = 0;
1263 ci->nTotalCreated = 0;
1264 ci->frameTitle = NULL;
1266 SetWindowLongW( hwnd, GWL_STYLE, GetWindowLongW(hwnd,GWL_STYLE) | WS_CLIPCHILDREN );
1268 if (!hBmpClose) hBmpClose = CreateMDIMenuBitmap();
1270 if (ci->hWindowMenu != 0)
1271 AppendMenuW( ci->hWindowMenu, MF_SEPARATOR, 0, NULL );
1273 GetClientRect( GetParent(hwnd), &rect);
1274 MoveWindow( hwnd, 0, 0, rect.right, rect.bottom, FALSE );
1276 MDI_UpdateFrameText( GetParent(hwnd), hwnd, MDI_NOFRAMEREPAINT, NULL);
1278 TRACE("Client created - hwnd = %p, idFirst = %u\n", hwnd, ci->idFirstChild );
1285 if( ci->hwndChildMaximized )
1286 MDI_RestoreFrameMenu( GetParent(hwnd), ci->hwndChildMaximized);
1287 if((ci->hWindowMenu != 0) &&
1288 (nItems = GetMenuItemCount(ci->hWindowMenu)) > 0)
1290 ci->idFirstChild = nItems - 1;
1291 ci->nActiveChildren++; /* to delete a separator */
1292 while( ci->nActiveChildren-- )
1293 DeleteMenu(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
1295 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1299 case WM_MDIACTIVATE:
1300 if( ci->hwndActiveChild != (HWND)wParam )
1301 SetWindowPos((HWND)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
1305 return MDICascade(hwnd, ci);
1309 return (LRESULT)MDICreateChild( hwnd, ci, (MDICREATESTRUCTA *)lParam, unicode );
1313 return MDIDestroyChild( hwnd, ci, WIN_GetFullHandle( (HWND)wParam ), TRUE );
1315 case WM_MDIGETACTIVE:
1316 if (lParam) *(BOOL *)lParam = (ci->hwndChildMaximized != 0);
1317 return (LRESULT)ci->hwndActiveChild;
1319 case WM_MDIICONARRANGE:
1320 ci->mdiFlags |= MDIF_NEEDUPDATE;
1321 ArrangeIconicWindows( hwnd );
1322 ci->sbRecalc = SB_BOTH+1;
1323 SendMessageW( hwnd, WM_MDICALCCHILDSCROLL, 0, 0 );
1326 case WM_MDIMAXIMIZE:
1327 ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1330 case WM_MDINEXT: /* lParam != 0 means previous window */
1331 MDI_SwitchActiveChild( hwnd, WIN_GetFullHandle( (HWND)wParam ), !lParam );
1335 SendMessageW( (HWND)wParam, WM_SYSCOMMAND, SC_RESTORE, 0);
1339 return MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1341 case WM_MDIREFRESHMENU:
1342 return MDIRefreshMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1345 ci->mdiFlags |= MDIF_NEEDUPDATE;
1346 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1347 MDITile( hwnd, ci, wParam );
1348 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1353 ci->mdiFlags |= MDIF_NEEDUPDATE;
1354 ScrollChildren( hwnd, message, wParam, lParam );
1355 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1359 if (ci->hwndActiveChild && !IsIconic( ci->hwndActiveChild ))
1360 SetFocus( ci->hwndActiveChild );
1364 if( ci->hwndActiveChild )
1365 SendMessageW(ci->hwndActiveChild, message, wParam, lParam);
1368 case WM_PARENTNOTIFY:
1369 if (LOWORD(wParam) == WM_LBUTTONDOWN)
1373 pt.x = (short)LOWORD(lParam);
1374 pt.y = (short)HIWORD(lParam);
1375 child = ChildWindowFromPoint(hwnd, pt);
1377 TRACE("notification from %p (%li,%li)\n",child,pt.x,pt.y);
1379 if( child && child != hwnd && child != ci->hwndActiveChild )
1380 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1385 if( IsWindow(ci->hwndChildMaximized) )
1391 rect.right = LOWORD(lParam);
1392 rect.bottom = HIWORD(lParam);
1394 AdjustWindowRectEx(&rect, GetWindowLongA(ci->hwndChildMaximized,GWL_STYLE),
1395 0, GetWindowLongA(ci->hwndChildMaximized,GWL_EXSTYLE) );
1396 MoveWindow(ci->hwndChildMaximized, rect.left, rect.top,
1397 rect.right - rect.left, rect.bottom - rect.top, 1);
1400 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1404 case WM_MDICALCCHILDSCROLL:
1405 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1407 CalcChildScroll(hwnd, ci->sbRecalc-1);
1409 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1413 return unicode ? DefWindowProcW( hwnd, message, wParam, lParam ) :
1414 DefWindowProcA( hwnd, message, wParam, lParam );
1417 /***********************************************************************
1420 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1422 if (!IsWindow(hwnd)) return 0;
1423 return MDIClientWndProc_common( hwnd, message, wParam, lParam, FALSE );
1426 /***********************************************************************
1429 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1431 if (!IsWindow(hwnd)) return 0;
1432 return MDIClientWndProc_common( hwnd, message, wParam, lParam, TRUE );
1435 /***********************************************************************
1436 * DefFrameProc (USER.445)
1438 LRESULT WINAPI DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient,
1439 UINT16 message, WPARAM16 wParam, LPARAM lParam )
1444 lParam = (LPARAM)MapSL(lParam);
1450 return DefFrameProcA( WIN_Handle32(hwnd), WIN_Handle32(hwndMDIClient),
1451 message, wParam, lParam );
1455 MDINEXTMENU next_menu;
1456 DefFrameProcW( WIN_Handle32(hwnd), WIN_Handle32(hwndMDIClient),
1457 message, wParam, (LPARAM)&next_menu );
1458 return MAKELONG( HMENU_16(next_menu.hmenuNext), HWND_16(next_menu.hwndNext) );
1461 return DefWindowProc16(hwnd, message, wParam, lParam);
1466 /***********************************************************************
1467 * DefFrameProcA (USER32.@)
1469 LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1470 UINT message, WPARAM wParam, LPARAM lParam)
1478 DWORD len = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0 );
1479 LPWSTR text = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1480 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, text, len );
1481 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, text );
1482 HeapFree( GetProcessHeap(), 0, text );
1484 return 1; /* success. FIXME: check text length */
1491 return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1494 return DefWindowProcA(hwnd, message, wParam, lParam);
1498 /***********************************************************************
1499 * DefFrameProcW (USER32.@)
1501 LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1502 UINT message, WPARAM wParam, LPARAM lParam)
1504 MDICLIENTINFO *ci = get_client_info( hwndMDIClient );
1512 WORD id = LOWORD(wParam);
1513 /* check for possible syscommands for maximized MDI child */
1514 if (id < ci->idFirstChild || id >= ci->idFirstChild + ci->nActiveChildren)
1516 if( (id - 0xf000) & 0xf00f ) break;
1517 if( !ci->hwndChildMaximized ) break;
1528 return SendMessageW( ci->hwndChildMaximized, WM_SYSCOMMAND,
1535 if (id - ci->idFirstChild == MDI_MOREWINDOWSLIMIT)
1536 /* User chose "More Windows..." */
1537 childHwnd = MDI_MoreWindowsDialog(hwndMDIClient);
1539 /* User chose one of the windows listed in the "Windows" menu */
1540 childHwnd = MDI_GetChildByID(hwndMDIClient,id);
1543 SendMessageW( hwndMDIClient, WM_MDIACTIVATE, (WPARAM)childHwnd, 0 );
1549 SendMessageW(hwndMDIClient, message, wParam, lParam);
1553 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, (LPWSTR)lParam );
1554 return 1; /* success. FIXME: check text length */
1557 SetFocus(hwndMDIClient);
1561 MoveWindow(hwndMDIClient, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
1566 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1568 if (!IsIconic(hwnd) && ci->hwndActiveChild && !ci->hwndChildMaximized)
1570 /* control menu is between the frame system menu and
1571 * the first entry of menu bar */
1572 WND *wndPtr = WIN_GetPtr(hwnd);
1574 if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1575 (wParam == VK_RIGHT && GetSubMenu(wndPtr->hSysMenu, 0) == next_menu->hmenuIn) )
1577 WIN_ReleasePtr(wndPtr);
1578 wndPtr = WIN_GetPtr(ci->hwndActiveChild);
1579 next_menu->hmenuNext = GetSubMenu(wndPtr->hSysMenu, 0);
1580 next_menu->hwndNext = ci->hwndActiveChild;
1582 WIN_ReleasePtr(wndPtr);
1589 return DefWindowProcW( hwnd, message, wParam, lParam );
1593 /***********************************************************************
1594 * DefMDIChildProc (USER.447)
1596 LRESULT WINAPI DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1597 WPARAM16 wParam, LPARAM lParam )
1602 return DefMDIChildProcA( WIN_Handle32(hwnd), message, wParam, (LPARAM)MapSL(lParam) );
1606 case WM_CHILDACTIVATE:
1611 return DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, lParam );
1612 case WM_GETMINMAXINFO:
1614 MINMAXINFO16 *mmi16 = (MINMAXINFO16 *)MapSL(lParam);
1616 STRUCT32_MINMAXINFO16to32( mmi16, &mmi );
1617 DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, (LPARAM)&mmi );
1618 STRUCT32_MINMAXINFO32to16( &mmi, mmi16 );
1623 MDINEXTMENU next_menu;
1624 DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, (LPARAM)&next_menu );
1625 return MAKELONG( HMENU_16(next_menu.hmenuNext), HWND_16(next_menu.hwndNext) );
1628 return DefWindowProc16(hwnd, message, wParam, lParam);
1633 /***********************************************************************
1634 * DefMDIChildProcA (USER32.@)
1636 LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1637 WPARAM wParam, LPARAM lParam )
1639 HWND client = GetParent(hwnd);
1640 MDICLIENTINFO *ci = get_client_info( client );
1642 hwnd = WIN_GetFullHandle( hwnd );
1643 if (!ci) return DefWindowProcA( hwnd, message, wParam, lParam );
1648 DefWindowProcA(hwnd, message, wParam, lParam);
1649 MDI_MenuModifyItem( client, hwnd );
1650 if( ci->hwndChildMaximized == hwnd )
1651 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1652 return 1; /* success. FIXME: check text length */
1654 case WM_GETMINMAXINFO:
1658 case WM_CHILDACTIVATE:
1664 return DefMDIChildProcW( hwnd, message, wParam, lParam );
1666 return DefWindowProcA(hwnd, message, wParam, lParam);
1670 /***********************************************************************
1671 * DefMDIChildProcW (USER32.@)
1673 LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1674 WPARAM wParam, LPARAM lParam )
1676 HWND client = GetParent(hwnd);
1677 MDICLIENTINFO *ci = get_client_info( client );
1679 hwnd = WIN_GetFullHandle( hwnd );
1680 if (!ci) return DefWindowProcW( hwnd, message, wParam, lParam );
1685 DefWindowProcW(hwnd, message, wParam, lParam);
1686 MDI_MenuModifyItem( client, hwnd );
1687 if( ci->hwndChildMaximized == hwnd )
1688 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1689 return 1; /* success. FIXME: check text length */
1691 case WM_GETMINMAXINFO:
1692 MDI_ChildGetMinMaxInfo( client, hwnd, (MINMAXINFO *)lParam );
1696 return 0x00010000; /* MDI children don't have menu bars */
1699 SendMessageW( client, WM_MDIDESTROY, (WPARAM)hwnd, 0 );
1703 if (ci->hwndActiveChild != hwnd) MDI_ChildActivate( client, hwnd );
1706 case WM_CHILDACTIVATE:
1707 MDI_ChildActivate( client, hwnd );
1714 if( ci->hwndChildMaximized == hwnd) return 0;
1718 SetWindowLongW( hwnd, GWL_STYLE,
1719 GetWindowLongW( hwnd, GWL_STYLE ) | WS_SYSMENU );
1722 if (ci->hwndChildMaximized == hwnd)
1723 return SendMessageW( GetParent(client), message, wParam, lParam);
1724 SetWindowLongW( hwnd, GWL_STYLE,
1725 GetWindowLongW( hwnd, GWL_STYLE ) & ~WS_SYSMENU );
1728 SendMessageW( client, WM_MDINEXT, 0, 0);
1731 SendMessageW( client, WM_MDINEXT, 0, 1);
1737 if( ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1738 else MDI_PostUpdate(client, ci, SB_BOTH+1);
1742 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1744 ci->hwndChildMaximized = 0;
1745 MDI_RestoreFrameMenu( GetParent(client), hwnd );
1746 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1749 if( wParam == SIZE_MAXIMIZED )
1751 HWND hMaxChild = ci->hwndChildMaximized;
1753 if( hMaxChild == hwnd ) break;
1756 SendMessageW( hMaxChild, WM_SETREDRAW, FALSE, 0 );
1757 MDI_RestoreFrameMenu( GetParent(client), hMaxChild );
1758 ShowWindow( hMaxChild, SW_SHOWNOACTIVATE );
1759 SendMessageW( hMaxChild, WM_SETREDRAW, TRUE, 0 );
1761 TRACE("maximizing child %p\n", hwnd );
1763 /* keep track of the maximized window. */
1764 ci->hwndChildMaximized = hwnd; /* !!! */
1766 /* The maximized window should also be the active window */
1767 MDI_ChildActivate( client, hwnd );
1768 MDI_AugmentFrameMenu( GetParent(client), hwnd );
1769 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1772 if( wParam == SIZE_MINIMIZED )
1774 HWND switchTo = MDI_GetWindow(ci, hwnd, TRUE, WS_MINIMIZE);
1776 if (switchTo) SendMessageW( switchTo, WM_CHILDACTIVATE, 0, 0);
1778 MDI_PostUpdate(client, ci, SB_BOTH+1);
1783 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1784 HWND parent = GetParent(client);
1786 if( wParam == VK_LEFT ) /* switch to frame system menu */
1788 WND *wndPtr = WIN_GetPtr( parent );
1789 next_menu->hmenuNext = GetSubMenu( wndPtr->hSysMenu, 0 );
1790 WIN_ReleasePtr( wndPtr );
1792 if( wParam == VK_RIGHT ) /* to frame menu bar */
1794 next_menu->hmenuNext = GetMenu(parent);
1796 next_menu->hwndNext = parent;
1803 SendMessageW( hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (DWORD)VK_SPACE);
1808 return DefWindowProcW(hwnd, message, wParam, lParam);
1811 /**********************************************************************
1812 * CreateMDIWindowA (USER32.@) Creates a MDI child
1815 * Success: Handle to created window
1818 HWND WINAPI CreateMDIWindowA(
1819 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1820 LPCSTR lpWindowName, /* [in] Pointer to window name */
1821 DWORD dwStyle, /* [in] Window style */
1822 INT X, /* [in] Horizontal position of window */
1823 INT Y, /* [in] Vertical position of window */
1824 INT nWidth, /* [in] Width of window */
1825 INT nHeight, /* [in] Height of window */
1826 HWND hWndParent, /* [in] Handle to parent window */
1827 HINSTANCE hInstance, /* [in] Handle to application instance */
1828 LPARAM lParam) /* [in] Application-defined value */
1830 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1831 MDICREATESTRUCTA cs;
1833 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%p,%p,%ld)\n",
1834 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1835 nWidth,nHeight,hWndParent,hInstance,lParam);
1839 ERR("bad hwnd for MDI-client: %p\n", hWndParent);
1842 cs.szClass=lpClassName;
1843 cs.szTitle=lpWindowName;
1844 cs.hOwner=hInstance;
1852 return MDICreateChild(hWndParent, pCi, &cs, FALSE);
1855 /***********************************************************************
1856 * CreateMDIWindowW (USER32.@) Creates a MDI child
1859 * Success: Handle to created window
1862 HWND WINAPI CreateMDIWindowW(
1863 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1864 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1865 DWORD dwStyle, /* [in] Window style */
1866 INT X, /* [in] Horizontal position of window */
1867 INT Y, /* [in] Vertical position of window */
1868 INT nWidth, /* [in] Width of window */
1869 INT nHeight, /* [in] Height of window */
1870 HWND hWndParent, /* [in] Handle to parent window */
1871 HINSTANCE hInstance, /* [in] Handle to application instance */
1872 LPARAM lParam) /* [in] Application-defined value */
1874 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1875 MDICREATESTRUCTW cs;
1877 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%p,%p,%ld)\n",
1878 debugstr_w(lpClassName), debugstr_w(lpWindowName), dwStyle, X, Y,
1879 nWidth, nHeight, hWndParent, hInstance, lParam);
1883 ERR("bad hwnd for MDI-client: %p\n", hWndParent);
1886 cs.szClass = lpClassName;
1887 cs.szTitle = lpWindowName;
1888 cs.hOwner = hInstance;
1896 return MDICreateChild(hWndParent, pCi, (MDICREATESTRUCTA *)&cs, TRUE);
1899 /**********************************************************************
1900 * TranslateMDISysAccel (USER32.@)
1902 BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1904 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1906 MDICLIENTINFO *ci = get_client_info( hwndClient );
1909 if (!ci || !IsWindowEnabled(ci->hwndActiveChild)) return 0;
1911 /* translate if the Ctrl key is down and Alt not. */
1913 if( (GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
1915 switch( msg->wParam )
1919 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 ) ? SC_NEXTWINDOW : SC_PREVWINDOW;
1928 TRACE("wParam = %04x\n", wParam);
1929 SendMessageW(ci->hwndActiveChild, WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
1933 return 0; /* failure */
1936 /***********************************************************************
1937 * CalcChildScroll (USER32.@)
1939 void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
1942 RECT childRect, clientRect;
1945 GetClientRect( hwnd, &clientRect );
1946 SetRectEmpty( &childRect );
1948 if ((list = WIN_ListChildren( hwnd )))
1951 for (i = 0; list[i]; i++)
1953 DWORD style = GetWindowLongW( list[i], GWL_STYLE );
1954 if (style & WS_MAXIMIZE)
1956 HeapFree( GetProcessHeap(), 0, list );
1957 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1960 if (style & WS_VISIBLE)
1962 WND *pWnd = WIN_FindWndPtr( list[i] );
1963 UnionRect( &childRect, &pWnd->rectWindow, &childRect );
1964 WIN_ReleaseWndPtr( pWnd );
1967 HeapFree( GetProcessHeap(), 0, list );
1969 UnionRect( &childRect, &clientRect, &childRect );
1971 /* set common info values */
1972 info.cbSize = sizeof(info);
1973 info.fMask = SIF_POS | SIF_RANGE;
1975 /* set the specific */
1980 info.nMin = childRect.left;
1981 info.nMax = childRect.right - clientRect.right;
1982 info.nPos = clientRect.left - childRect.left;
1983 SetScrollInfo(hwnd, scroll, &info, TRUE);
1984 if (scroll == SB_HORZ) break;
1987 info.nMin = childRect.top;
1988 info.nMax = childRect.bottom - clientRect.bottom;
1989 info.nPos = clientRect.top - childRect.top;
1990 SetScrollInfo(hwnd, scroll, &info, TRUE);
1996 /***********************************************************************
1997 * ScrollChildren (USER32.@)
1999 void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
2003 INT curPos, length, minPos, maxPos, shift;
2006 GetClientRect( hWnd, &rect );
2011 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
2012 curPos = GetScrollPos(hWnd,SB_HORZ);
2013 length = (rect.right - rect.left) / 2;
2014 shift = GetSystemMetrics(SM_CYHSCROLL);
2017 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
2018 curPos = GetScrollPos(hWnd,SB_VERT);
2019 length = (rect.bottom - rect.top) / 2;
2020 shift = GetSystemMetrics(SM_CXVSCROLL);
2029 newPos = curPos - shift;
2032 newPos = curPos + shift;
2035 newPos = curPos - length;
2038 newPos = curPos + length;
2041 case SB_THUMBPOSITION:
2042 newPos = LOWORD(lParam);
2055 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
2059 if( newPos > maxPos )
2062 if( newPos < minPos )
2065 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
2067 if( uMsg == WM_VSCROLL )
2068 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
2069 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2071 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
2072 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2076 /******************************************************************************
2077 * CascadeWindows (USER32.@) Cascades MDI child windows
2080 * Success: Number of cascaded windows.
2084 CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2085 UINT cKids, const HWND *lpKids)
2087 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
2092 /******************************************************************************
2093 * TileWindows (USER32.@) Tiles MDI child windows
2096 * Success: Number of tiled windows.
2100 TileWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2101 UINT cKids, const HWND *lpKids)
2103 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
2107 /************************************************************************
2108 * "More Windows..." functionality
2111 /* MDI_MoreWindowsDlgProc
2113 * This function will process the messages sent to the "More Windows..."
2115 * Return values: 0 = cancel pressed
2116 * HWND = ok pressed or double-click in the list...
2120 static INT_PTR WINAPI MDI_MoreWindowsDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
2129 MDICLIENTINFO *ci = get_client_info( (HWND)lParam );
2130 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2131 HWND *list, *sorted_list;
2133 if (!(list = WIN_ListChildren( (HWND)lParam ))) return TRUE;
2134 if (!(sorted_list = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
2135 sizeof(HWND) * ci->nActiveChildren )))
2137 HeapFree( GetProcessHeap(), 0, list );
2141 /* Fill the list, sorted by id... */
2142 for (i = 0; list[i]; i++)
2144 UINT id = GetWindowLongW( list[i], GWL_ID ) - ci->idFirstChild;
2145 if (id < ci->nActiveChildren) sorted_list[id] = list[i];
2147 HeapFree( GetProcessHeap(), 0, list );
2149 for (i = 0; i < ci->nActiveChildren; i++)
2153 if (!GetWindowTextW( sorted_list[i], buffer, sizeof(buffer)/sizeof(WCHAR) ))
2155 SendMessageW(hListBox, LB_ADDSTRING, 0, (LPARAM)buffer );
2156 SendMessageW(hListBox, LB_SETITEMDATA, i, (LPARAM)sorted_list[i] );
2157 length = strlenW(buffer); /* FIXME: should use GetTextExtentPoint */
2158 if (length > widest)
2161 /* Make sure the horizontal scrollbar scrolls ok */
2162 SendMessageW(hListBox, LB_SETHORIZONTALEXTENT, widest * 6, 0);
2164 /* Set the current selection */
2165 SendMessageW(hListBox, LB_SETCURSEL, MDI_MOREWINDOWSLIMIT, 0);
2170 switch (LOWORD(wParam))
2173 if (HIWORD(wParam) != LBN_DBLCLK) break;
2177 /* windows are sorted by menu ID, so we must return the
2178 * window associated to the given id
2180 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2181 UINT index = SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
2182 LRESULT res = SendMessageW(hListBox, LB_GETITEMDATA, index, 0);
2183 EndDialog(hDlg, res);
2197 * MDI_MoreWindowsDialog
2199 * Prompts the user with a listbox containing the opened
2200 * documents. The user can then choose a windows and click
2201 * on OK to set the current window to the one selected, or
2202 * CANCEL to cancel. The function returns a handle to the
2206 static HWND MDI_MoreWindowsDialog(HWND hwnd)
2212 hRes = FindResourceA(GetModuleHandleA("USER32"), "MDI_MOREWINDOWS", (LPSTR)RT_DIALOG);
2217 hDlgTmpl = LoadResource(GetModuleHandleA("USER32"), hRes );
2222 template = LockResource( hDlgTmpl );
2227 return (HWND) DialogBoxIndirectParamA(GetModuleHandleA("USER32"),
2228 (LPDLGTEMPLATEA) template,
2229 hwnd, MDI_MoreWindowsDlgProc, (LPARAM) hwnd);
2236 * Will swap the menu IDs for the given 2 positions.
2237 * pos1 and pos2 are menu IDs
2242 static void MDI_SwapMenuItems(HWND parent, UINT pos1, UINT pos2)
2247 if (!(list = WIN_ListChildren( parent ))) return;
2248 for (i = 0; list[i]; i++)
2250 UINT id = GetWindowLongW( list[i], GWL_ID );
2251 if (id == pos1) SetWindowLongW( list[i], GWL_ID, pos2 );
2252 else if (id == pos2) SetWindowLongW( list[i], GWL_ID, pos1 );
2254 HeapFree( GetProcessHeap(), 0, list );