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_MAXTITLELENGTH 0xa1
107 #define WM_MDICALCCHILDSCROLL 0x10ac /* this is exactly what Windows uses */
109 /* "More Windows..." definitions */
110 #define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
111 option will appear under the Windows menu */
112 #define MDI_IDC_LISTBOX 100
113 #define IDS_MDI_MOREWINDOWS 13
115 #define MDIF_NEEDUPDATE 0x0001
119 UINT nActiveChildren
;
120 HWND hwndActiveChild
;
121 HWND
*child
; /* array of tracked children */
128 UINT sbRecalc
; /* SB_xxx flags for scrollbar fixup */
131 static HBITMAP hBmpClose
= 0;
133 /* ----------------- declarations ----------------- */
134 static void MDI_UpdateFrameText( HWND
, HWND
, BOOL
, LPCWSTR
);
135 static BOOL
MDI_AugmentFrameMenu( HWND
, HWND
);
136 static BOOL
MDI_RestoreFrameMenu( HWND
, HWND
);
137 static LONG
MDI_ChildActivate( HWND
, HWND
);
138 static LRESULT
MDI_RefreshMenu(MDICLIENTINFO
*);
140 static HWND
MDI_MoreWindowsDialog(HWND
);
141 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
142 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
144 /* -------- Miscellaneous service functions ----------
148 static HWND
MDI_GetChildByID(HWND hwnd
, UINT id
, MDICLIENTINFO
*ci
)
152 for (i
= 0; ci
->nActiveChildren
; i
++)
154 if (GetWindowLongW( ci
->child
[i
], GWL_ID
) == id
)
160 static void MDI_PostUpdate(HWND hwnd
, MDICLIENTINFO
* ci
, WORD recalc
)
162 if( !(ci
->mdiFlags
& MDIF_NEEDUPDATE
) )
164 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
165 PostMessageA( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0);
167 ci
->sbRecalc
= recalc
;
171 /*********************************************************************
172 * MDIClient class descriptor
174 const struct builtin_class_descr MDICLIENT_builtin_class
=
176 "MDIClient", /* name */
178 MDIClientWndProcA
, /* procA */
179 MDIClientWndProcW
, /* procW */
180 sizeof(MDICLIENTINFO
), /* extra */
181 IDC_ARROW
, /* cursor */
182 (HBRUSH
)(COLOR_APPWORKSPACE
+1) /* brush */
186 static MDICLIENTINFO
*get_client_info( HWND client
)
188 MDICLIENTINFO
*ret
= NULL
;
189 WND
*win
= WIN_GetPtr( client
);
192 if (win
== WND_OTHER_PROCESS
)
194 ERR( "client %p belongs to other process\n", client
);
197 if (win
->cbWndExtra
< sizeof(MDICLIENTINFO
)) WARN( "%p is not an MDI client\n", client
);
198 else ret
= (MDICLIENTINFO
*)win
->wExtra
;
199 WIN_ReleasePtr( win
);
204 /**********************************************************************
207 * returns "activateable" child different from the current or zero
209 static HWND
MDI_GetWindow(MDICLIENTINFO
*clientInfo
, HWND hWnd
, BOOL bNext
,
216 dwStyleMask
|= WS_DISABLED
| WS_VISIBLE
;
217 if( !hWnd
) hWnd
= clientInfo
->hwndActiveChild
;
219 if (!(list
= WIN_ListChildren( GetParent(hWnd
) ))) return 0;
221 /* start from next after hWnd */
222 while (list
[i
] && list
[i
] != hWnd
) i
++;
225 for ( ; list
[i
]; i
++)
227 if (GetWindow( list
[i
], GW_OWNER
)) continue;
228 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
230 if (bNext
) goto found
;
232 /* now restart from the beginning */
233 for (i
= 0; list
[i
] && list
[i
] != hWnd
; i
++)
235 if (GetWindow( list
[i
], GW_OWNER
)) continue;
236 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
238 if (bNext
) goto found
;
241 HeapFree( GetProcessHeap(), 0, list
);
245 /**********************************************************************
246 * MDI_CalcDefaultChildPos
248 * It seems that the default height is about 2/3 of the client rect
250 void MDI_CalcDefaultChildPos( HWND hwndClient
, INT total
, LPPOINT lpPos
, INT delta
)
254 INT spacing
= GetSystemMetrics(SM_CYCAPTION
) +
255 GetSystemMetrics(SM_CYFRAME
) - 1;
259 MDICLIENTINFO
*ci
= get_client_info(hwndClient
);
260 total
= ci
? ci
->nTotalCreated
: 0;
263 GetClientRect( hwndClient
, &rect
);
264 if( rect
.bottom
- rect
.top
- delta
>= spacing
)
265 rect
.bottom
-= delta
;
267 nstagger
= (rect
.bottom
- rect
.top
)/(3 * spacing
);
268 lpPos
[1].x
= (rect
.right
- rect
.left
- nstagger
* spacing
);
269 lpPos
[1].y
= (rect
.bottom
- rect
.top
- nstagger
* spacing
);
270 lpPos
[0].x
= lpPos
[0].y
= spacing
* (total
%(nstagger
+1));
273 /**********************************************************************
276 static LRESULT
MDISetMenu( HWND hwnd
, HMENU hmenuFrame
,
280 HWND hwndFrame
= GetParent(hwnd
);
282 TRACE("%p %p %p\n", hwnd
, hmenuFrame
, hmenuWindow
);
284 if (hmenuFrame
&& !IsMenu(hmenuFrame
))
286 WARN("hmenuFrame is not a menu handle\n");
290 if (hmenuWindow
&& !IsMenu(hmenuWindow
))
292 WARN("hmenuWindow is not a menu handle\n");
296 if (!(ci
= get_client_info( hwnd
))) return 0;
298 if( IsZoomed(ci
->hwndActiveChild
) && hmenuFrame
&& hmenuFrame
!= ci
->hFrameMenu
)
299 MDI_RestoreFrameMenu( hwndFrame
, ci
->hwndActiveChild
);
301 if( hmenuWindow
&& hmenuWindow
!= ci
->hWindowMenu
)
303 /* delete menu items from ci->hWindowMenu
304 * and add them to hmenuWindow */
305 /* Agent newsreader calls this function with ci->hWindowMenu == NULL */
306 if( ci
->hWindowMenu
&& ci
->nActiveChildren
)
308 UINT nActiveChildren_old
= ci
->nActiveChildren
;
310 /* Remove all items from old Window menu */
311 ci
->nActiveChildren
= 0;
314 ci
->hWindowMenu
= hmenuWindow
;
316 /* Add items to the new Window menu */
317 ci
->nActiveChildren
= nActiveChildren_old
;
318 AppendMenuW(hmenuWindow
, MF_SEPARATOR
, 0, NULL
);
322 ci
->hWindowMenu
= hmenuWindow
;
327 SetMenu(hwndFrame
, hmenuFrame
);
328 if( hmenuFrame
!= ci
->hFrameMenu
)
330 HMENU oldFrameMenu
= ci
->hFrameMenu
;
332 ci
->hFrameMenu
= hmenuFrame
;
333 if( IsZoomed(ci
->hwndActiveChild
) )
334 MDI_AugmentFrameMenu( hwndFrame
, ci
->hwndActiveChild
);
336 return (LRESULT
)oldFrameMenu
;
341 /* SetMenu() may already have been called, meaning that this window
342 * already has its menu. But they may have done a SetMenu() on
343 * an MDI window, and called MDISetMenu() after the fact, meaning
344 * that the "if" to this "else" wouldn't catch the need to
345 * augment the frame menu.
347 if( IsZoomed(ci
->hwndActiveChild
) )
348 MDI_AugmentFrameMenu( hwndFrame
, ci
->hwndActiveChild
);
354 /**********************************************************************
357 static LRESULT
MDI_RefreshMenu(MDICLIENTINFO
*ci
)
359 UINT i
, count
, visible
, separator_pos
;
360 WCHAR buf
[MDI_MAXTITLELENGTH
];
362 TRACE("children %u, window menu %p\n", ci
->nActiveChildren
, ci
->hWindowMenu
);
364 if (!ci
->hWindowMenu
)
367 if (!IsMenu(ci
->hWindowMenu
))
369 WARN("Window menu handle %p is no more valid\n", ci
->hWindowMenu
);
373 /* Windows finds the last separator in the menu, removes all existing
374 * menu items after it, and then adds visible MDI children.
377 count
= GetMenuItemCount(ci
->hWindowMenu
);
378 for (i
= 0; i
< count
; i
++)
382 memset(&mii
, 0, sizeof(mii
));
383 mii
.cbSize
= sizeof(mii
);
384 mii
.fMask
= MIIM_TYPE
;
385 GetMenuItemInfoW(ci
->hWindowMenu
, i
, TRUE
, &mii
);
387 if (mii
.fType
& MFT_SEPARATOR
)
391 for (i
= separator_pos
+ 1; i
< count
; i
++)
392 RemoveMenu(ci
->hWindowMenu
, separator_pos
+ 1, MF_BYPOSITION
);
395 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
397 UINT id
= ci
->idFirstChild
+ i
;
399 if (visible
== MDI_MOREWINDOWSLIMIT
)
401 LoadStringW(user32_module
, IDS_MDI_MOREWINDOWS
, buf
, sizeof(buf
)/sizeof(WCHAR
));
402 AppendMenuW(ci
->hWindowMenu
, MF_STRING
, id
, buf
);
406 if (GetWindowLongW(ci
->child
[i
], GWL_STYLE
) & WS_VISIBLE
)
408 if (!visible
&& !separator_pos
)
409 /* Visio expects that separator has id 0 */
410 AppendMenuW(ci
->hWindowMenu
, MF_SEPARATOR
, 0, NULL
);
414 SetWindowLongW(ci
->child
[i
], GWL_ID
, id
);
417 buf
[1] = '0' + visible
;
419 InternalGetWindowText(ci
->child
[i
], buf
+ 3, sizeof(buf
)/sizeof(WCHAR
) - 3);
420 TRACE("Adding %p, id %u %s\n", ci
->child
[i
], id
, debugstr_w(buf
));
421 AppendMenuW(ci
->hWindowMenu
, MF_STRING
, id
, buf
);
423 if (ci
->child
[i
] == ci
->hwndActiveChild
)
424 CheckMenuItem(ci
->hWindowMenu
, id
, MF_CHECKED
);
427 TRACE("MDI child %p is not visible, skipping\n", ci
->child
[i
]);
430 return (LRESULT
)ci
->hFrameMenu
;
434 /* ------------------ MDI child window functions ---------------------- */
436 /**********************************************************************
437 * MDI_ChildGetMinMaxInfo
439 * Note: The rule here is that client rect of the maximized MDI child
440 * is equal to the client rect of the MDI client window.
442 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
446 GetClientRect( client
, &rect
);
447 AdjustWindowRectEx( &rect
, GetWindowLongW( hwnd
, GWL_STYLE
),
448 0, GetWindowLongW( hwnd
, GWL_EXSTYLE
));
450 lpMinMax
->ptMaxSize
.x
= rect
.right
-= rect
.left
;
451 lpMinMax
->ptMaxSize
.y
= rect
.bottom
-= rect
.top
;
453 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
454 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
456 TRACE("max rect (%ld,%ld - %ld, %ld)\n",
457 rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
460 /**********************************************************************
461 * MDI_SwitchActiveChild
463 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
466 static void MDI_SwitchActiveChild( HWND clientHwnd
, HWND childHwnd
,
471 MDICLIENTINFO
*ci
= get_client_info( clientHwnd
);
473 hwndTo
= MDI_GetWindow(ci
, childHwnd
, bNextWindow
, 0);
474 hwndPrev
= ci
->hwndActiveChild
;
476 TRACE("from %p, to %p\n",childHwnd
,hwndTo
);
478 if ( !hwndTo
) return; /* no window to switch to */
480 if ( hwndTo
!= hwndPrev
)
482 SetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0,
483 SWP_NOMOVE
| SWP_NOSIZE
);
485 if( bNextWindow
&& hwndPrev
)
486 SetWindowPos( hwndPrev
, HWND_BOTTOM
, 0, 0, 0, 0,
487 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
492 /**********************************************************************
495 static LRESULT
MDIDestroyChild( HWND parent
, MDICLIENTINFO
*ci
,
496 HWND child
, BOOL flagDestroy
)
500 TRACE("# of managed children %u\n", ci
->nActiveChildren
);
502 if( child
== ci
->hwndActiveChild
)
504 MDI_SwitchActiveChild(parent
, child
, TRUE
);
506 if( child
== ci
->hwndActiveChild
)
508 ShowWindow( child
, SW_HIDE
);
509 if( child
== ci
->hwndActiveChild
&& IsZoomed(ci
->hwndActiveChild
) )
511 HWND frame
= GetParent(parent
);
512 MDI_RestoreFrameMenu( frame
, child
);
513 MDI_UpdateFrameText( frame
, parent
, TRUE
, NULL
);
516 MDI_ChildActivate(parent
, 0);
520 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
522 if (ci
->child
[i
] == child
)
524 HWND
*new_child
= HeapAlloc(GetProcessHeap(), 0, (ci
->nActiveChildren
- 1) * sizeof(HWND
));
525 memcpy(new_child
, ci
->child
, i
* sizeof(HWND
));
526 if (i
+ 1 < ci
->nActiveChildren
)
527 memcpy(new_child
+ i
, ci
->child
+ i
+ 1, (ci
->nActiveChildren
- i
- 1) * sizeof(HWND
));
528 HeapFree(GetProcessHeap(), 0, ci
->child
);
529 ci
->child
= new_child
;
531 ci
->nActiveChildren
--;
538 MDI_PostUpdate(GetParent(child
), ci
, SB_BOTH
+1);
539 DestroyWindow(child
);
542 TRACE("child destroyed - %p\n", child
);
547 /**********************************************************************
550 * Note: hWndChild is NULL when last child is being destroyed
552 static LONG
MDI_ChildActivate( HWND client
, HWND child
)
554 MDICLIENTINFO
*clientInfo
;
556 BOOL isActiveFrameWnd
;
558 if (child
&& (!IsWindowEnabled( child
))) return 0;
560 clientInfo
= get_client_info( client
);
562 /* Don't activate if it is already active. Might happen
563 since ShowWindow DOES activate MDI children */
564 if (clientInfo
->hwndActiveChild
== child
)
567 TRACE("%p\n", child
);
569 isActiveFrameWnd
= (GetActiveWindow() == GetParent(client
));
570 prevActiveWnd
= clientInfo
->hwndActiveChild
;
572 /* deactivate prev. active child */
575 SetWindowLongW( prevActiveWnd
, GWL_STYLE
,
576 GetWindowLongW( prevActiveWnd
, GWL_STYLE
) | WS_SYSMENU
);
577 SendMessageW( prevActiveWnd
, WM_NCACTIVATE
, FALSE
, 0L );
578 SendMessageW( prevActiveWnd
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
582 if (IsZoomed(clientInfo
->hwndActiveChild
) && clientInfo
->hwndActiveChild
!= child
)
584 INT cmd
= SW_SHOWNORMAL
;
588 HMENU hSysMenu
= GetSystemMenu(child
, FALSE
);
591 state
= GetMenuState(hSysMenu
, SC_MAXIMIZE
, MF_BYCOMMAND
);
592 if (state
!= 0xFFFFFFFF && !(state
& (MF_DISABLED
| MF_GRAYED
)))
594 SendMessageW(clientInfo
->hwndActiveChild
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
595 cmd
= SW_SHOWMAXIMIZED
;
598 clientInfo
->hwndActiveChild
= child
;
601 ShowWindow( clientInfo
->hwndActiveChild
, cmd
);
604 clientInfo
->hwndActiveChild
= child
;
606 /* check if we have any children left */
609 if( isActiveFrameWnd
)
614 MDI_RefreshMenu(clientInfo
);
616 /* bring active child to the top */
617 SetWindowPos( child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
619 if( isActiveFrameWnd
)
621 SendMessageA( child
, WM_NCACTIVATE
, TRUE
, 0L);
622 if( GetFocus() == client
)
623 SendMessageA( client
, WM_SETFOCUS
, (WPARAM
)client
, 0L );
627 SendMessageA( child
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
631 /* -------------------- MDI client window functions ------------------- */
633 /**********************************************************************
634 * CreateMDIMenuBitmap
636 static HBITMAP
CreateMDIMenuBitmap(void)
638 HDC hDCSrc
= CreateCompatibleDC(0);
639 HDC hDCDest
= CreateCompatibleDC(hDCSrc
);
640 HBITMAP hbClose
= LoadBitmapW(0, MAKEINTRESOURCEW(OBM_OLD_CLOSE
) );
642 HBITMAP hobjSrc
, hobjDest
;
644 hobjSrc
= SelectObject(hDCSrc
, hbClose
);
645 hbCopy
= CreateCompatibleBitmap(hDCSrc
,GetSystemMetrics(SM_CXSIZE
),GetSystemMetrics(SM_CYSIZE
));
646 hobjDest
= SelectObject(hDCDest
, hbCopy
);
648 BitBlt(hDCDest
, 0, 0, GetSystemMetrics(SM_CXSIZE
), GetSystemMetrics(SM_CYSIZE
),
649 hDCSrc
, GetSystemMetrics(SM_CXSIZE
), 0, SRCCOPY
);
651 SelectObject(hDCSrc
, hobjSrc
);
652 DeleteObject(hbClose
);
655 hobjSrc
= SelectObject( hDCDest
, GetStockObject(BLACK_PEN
) );
657 MoveToEx( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, 0, NULL
);
658 LineTo( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, GetSystemMetrics(SM_CYSIZE
) - 1);
660 SelectObject(hDCDest
, hobjSrc
);
661 SelectObject(hDCDest
, hobjDest
);
667 /**********************************************************************
670 static LONG
MDICascade( HWND client
, MDICLIENTINFO
*ci
)
673 BOOL has_icons
= FALSE
;
676 if (IsZoomed(ci
->hwndActiveChild
))
677 SendMessageA(client
, WM_MDIRESTORE
, (WPARAM
)ci
->hwndActiveChild
, 0);
679 if (ci
->nActiveChildren
== 0) return 0;
681 if (!(win_array
= WIN_ListChildren( client
))) return 0;
683 /* remove all the windows we don't want */
684 for (i
= total
= 0; win_array
[i
]; i
++)
686 if (!IsWindowVisible( win_array
[i
] )) continue;
687 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows */
688 if (IsIconic( win_array
[i
] ))
693 win_array
[total
++] = win_array
[i
];
695 win_array
[total
] = 0;
699 INT delta
= 0, n
= 0, i
;
701 if (has_icons
) delta
= GetSystemMetrics(SM_CYICONSPACING
) + GetSystemMetrics(SM_CYICON
);
703 /* walk the list (backwards) and move windows */
704 for (i
= total
- 1; i
>= 0; i
--)
706 TRACE("move %p to (%ld,%ld) size [%ld,%ld]\n",
707 win_array
[i
], pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
);
709 MDI_CalcDefaultChildPos(client
, n
++, pos
, delta
);
710 SetWindowPos( win_array
[i
], 0, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
,
711 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
714 HeapFree( GetProcessHeap(), 0, win_array
);
716 if (has_icons
) ArrangeIconicWindows( client
);
720 /**********************************************************************
723 static void MDITile( HWND client
, MDICLIENTINFO
*ci
, WPARAM wParam
)
727 BOOL has_icons
= FALSE
;
729 if (IsZoomed(ci
->hwndActiveChild
))
730 SendMessageA(client
, WM_MDIRESTORE
, (WPARAM
)ci
->hwndActiveChild
, 0);
732 if (ci
->nActiveChildren
== 0) return;
734 if (!(win_array
= WIN_ListChildren( client
))) return;
736 /* remove all the windows we don't want */
737 for (i
= total
= 0; win_array
[i
]; i
++)
739 if (!IsWindowVisible( win_array
[i
] )) continue;
740 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows (icon titles) */
741 if (IsIconic( win_array
[i
] ))
746 if ((wParam
& MDITILE_SKIPDISABLED
) && !IsWindowEnabled( win_array
[i
] )) continue;
747 win_array
[total
++] = win_array
[i
];
749 win_array
[total
] = 0;
751 TRACE("%u windows to tile\n", total
);
755 HWND
*pWnd
= win_array
;
757 int x
, y
, xsize
, ysize
;
758 int rows
, columns
, r
, c
, i
;
760 GetClientRect(client
,&rect
);
761 rows
= (int) sqrt((double)total
);
762 columns
= total
/ rows
;
764 if( wParam
& MDITILE_HORIZONTAL
) /* version >= 3.1 */
767 rows
= columns
; /* exchange r and c */
773 y
= rect
.bottom
- 2 * GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
774 rect
.bottom
= ( y
- GetSystemMetrics(SM_CYICON
) < rect
.top
)? rect
.bottom
: y
;
777 ysize
= rect
.bottom
/ rows
;
778 xsize
= rect
.right
/ columns
;
780 for (x
= i
= 0, c
= 1; c
<= columns
&& *pWnd
; c
++)
785 ysize
= rect
.bottom
/ rows
;
789 for (r
= 1; r
<= rows
&& *pWnd
; r
++, i
++)
791 SetWindowPos(*pWnd
, 0, x
, y
, xsize
, ysize
,
792 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
799 HeapFree( GetProcessHeap(), 0, win_array
);
800 if (has_icons
) ArrangeIconicWindows( client
);
803 /* ----------------------- Frame window ---------------------------- */
806 /**********************************************************************
807 * MDI_AugmentFrameMenu
809 static BOOL
MDI_AugmentFrameMenu( HWND frame
, HWND hChild
)
811 HMENU menu
= GetMenu( frame
);
813 HBITMAP hSysMenuBitmap
= 0;
817 TRACE("frame %p,child %p\n",frame
,hChild
);
819 if( !menu
) return 0;
821 /* if the system buttons already exist do not add them again */
822 nItems
= GetMenuItemCount(menu
) - 1;
823 iId
= GetMenuItemID(menu
,nItems
) ;
824 if (iId
== SC_RESTORE
|| iId
== SC_CLOSE
)
827 /* create a copy of sysmenu popup and insert it into frame menu bar */
828 if (!(hSysPopup
= GetSystemMenu(hChild
, FALSE
)))
831 AppendMenuA(menu
,MF_HELP
| MF_BITMAP
,
832 SC_MINIMIZE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_MINIMIZE
) ;
833 AppendMenuA(menu
,MF_HELP
| MF_BITMAP
,
834 SC_RESTORE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_RESTORE
);
836 /* The close button is only present in Win 95 look */
837 if(TWEAK_WineLook
> WIN31_LOOK
)
839 AppendMenuA(menu
,MF_HELP
| MF_BITMAP
,
840 SC_CLOSE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_CLOSE
);
843 /* In Win 95 look, the system menu is replaced by the child icon */
845 if(TWEAK_WineLook
> WIN31_LOOK
)
847 HICON hIcon
= (HICON
)GetClassLongW(hChild
, GCL_HICONSM
);
849 hIcon
= (HICON
)GetClassLongW(hChild
, GCL_HICON
);
851 hIcon
= LoadImageW(0, MAKEINTRESOURCEW(IDI_WINLOGO
), IMAGE_ICON
, 0, 0, LR_DEFAULTCOLOR
);
855 HBITMAP hBitmap
, hOldBitmap
;
857 HDC hdc
= GetDC(hChild
);
862 cx
= GetSystemMetrics(SM_CXSMICON
);
863 cy
= GetSystemMetrics(SM_CYSMICON
);
864 hMemDC
= CreateCompatibleDC(hdc
);
865 hBitmap
= CreateCompatibleBitmap(hdc
, cx
, cy
);
866 hOldBitmap
= SelectObject(hMemDC
, hBitmap
);
867 SetMapMode(hMemDC
, MM_TEXT
);
868 hBrush
= CreateSolidBrush(GetSysColor(COLOR_MENU
));
869 DrawIconEx(hMemDC
, 0, 0, hIcon
, cx
, cy
, 0, hBrush
, DI_NORMAL
);
870 SelectObject (hMemDC
, hOldBitmap
);
871 DeleteObject(hBrush
);
873 ReleaseDC(hChild
, hdc
);
874 hSysMenuBitmap
= hBitmap
;
879 hSysMenuBitmap
= hBmpClose
;
881 if( !InsertMenuA(menu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
882 (UINT_PTR
)hSysPopup
, (LPSTR
)hSysMenuBitmap
))
884 TRACE("not inserted\n");
885 DestroyMenu(hSysPopup
);
889 EnableMenuItem(hSysPopup
, SC_SIZE
, MF_BYCOMMAND
| MF_GRAYED
);
890 EnableMenuItem(hSysPopup
, SC_MOVE
, MF_BYCOMMAND
| MF_GRAYED
);
891 EnableMenuItem(hSysPopup
, SC_MAXIMIZE
, MF_BYCOMMAND
| MF_GRAYED
);
892 SetMenuDefaultItem(hSysPopup
, SC_CLOSE
, FALSE
);
900 /**********************************************************************
901 * MDI_RestoreFrameMenu
903 static BOOL
MDI_RestoreFrameMenu( HWND frame
, HWND hChild
)
905 MENUITEMINFOW menuInfo
;
906 HMENU menu
= GetMenu( frame
);
907 INT nItems
= GetMenuItemCount(menu
) - 1;
908 UINT iId
= GetMenuItemID(menu
,nItems
) ;
910 TRACE("frame %p,child %p,nIt=%d,iId=%d\n",frame
,hChild
,nItems
,iId
);
912 /* if there is no system buttons then nothing to do */
913 if(!(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
917 * Remove the system menu, If that menu is the icon of the window
918 * as it is in win95, we have to delete the bitmap.
920 memset(&menuInfo
, 0, sizeof(menuInfo
));
921 menuInfo
.cbSize
= sizeof(menuInfo
);
922 menuInfo
.fMask
= MIIM_DATA
| MIIM_TYPE
;
924 GetMenuItemInfoW(menu
,
929 RemoveMenu(menu
,0,MF_BYPOSITION
);
931 if ( (menuInfo
.fType
& MFT_BITMAP
) &&
932 (LOWORD(menuInfo
.dwTypeData
)!=0) &&
933 (LOWORD(menuInfo
.dwTypeData
)!=HBITMAP_16(hBmpClose
)) )
935 DeleteObject(HBITMAP_32(LOWORD(menuInfo
.dwTypeData
)));
938 if(TWEAK_WineLook
> WIN31_LOOK
)
941 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
944 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
946 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
954 /**********************************************************************
955 * MDI_UpdateFrameText
957 * used when child window is maximized/restored
959 * Note: lpTitle can be NULL
961 static void MDI_UpdateFrameText( HWND frame
, HWND hClient
,
962 BOOL repaint
, LPCWSTR lpTitle
)
964 WCHAR lpBuffer
[MDI_MAXTITLELENGTH
+1];
965 MDICLIENTINFO
*ci
= get_client_info( hClient
);
967 TRACE("repaint %i, frameText %s\n", repaint
, debugstr_w(lpTitle
));
971 if (!lpTitle
&& !ci
->frameTitle
) /* first time around, get title from the frame window */
973 GetWindowTextW( frame
, lpBuffer
, sizeof(lpBuffer
)/sizeof(WCHAR
) );
977 /* store new "default" title if lpTitle is not NULL */
980 if (ci
->frameTitle
) HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
981 if ((ci
->frameTitle
= HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle
)+1)*sizeof(WCHAR
))))
982 strcpyW( ci
->frameTitle
, lpTitle
);
987 if (IsZoomed(ci
->hwndActiveChild
) && IsWindowVisible(ci
->hwndActiveChild
))
989 /* combine frame title and child title if possible */
991 static const WCHAR lpBracket
[] = {' ','-',' ','[',0};
992 static const WCHAR lpBracket2
[] = {']',0};
993 int i_frame_text_length
= strlenW(ci
->frameTitle
);
995 lstrcpynW( lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
997 if( i_frame_text_length
+ 6 < MDI_MAXTITLELENGTH
)
999 strcatW( lpBuffer
, lpBracket
);
1000 if (GetWindowTextW( ci
->hwndActiveChild
, lpBuffer
+ i_frame_text_length
+ 4,
1001 MDI_MAXTITLELENGTH
- i_frame_text_length
- 5 ))
1002 strcatW( lpBuffer
, lpBracket2
);
1004 lpBuffer
[i_frame_text_length
] = 0; /* remove bracket */
1009 lstrcpynW(lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
+1 );
1015 DefWindowProcW( frame
, WM_SETTEXT
, 0, (LPARAM
)lpBuffer
);
1017 SetWindowPos( frame
, 0,0,0,0,0, SWP_FRAMECHANGED
|
1018 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
1022 /* ----------------------------- Interface ---------------------------- */
1025 /**********************************************************************
1026 * MDIClientWndProc_common
1028 static LRESULT
MDIClientWndProc_common( HWND hwnd
, UINT message
,
1029 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1033 TRACE("%p %04x %08x %08lx\n", hwnd
, message
, wParam
, lParam
);
1035 if (!(ci
= get_client_info( hwnd
))) return 0;
1041 /* Since we are using only cs->lpCreateParams, we can safely
1042 * cast to LPCREATESTRUCTA here */
1043 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
1044 WND
*wndPtr
= WIN_GetPtr( hwnd
);
1046 wndPtr
->flags
|= WIN_ISMDICLIENT
;
1048 /* Translation layer doesn't know what's in the cs->lpCreateParams
1049 * so we have to keep track of what environment we're in. */
1051 if( wndPtr
->flags
& WIN_ISWIN32
)
1053 LPCLIENTCREATESTRUCT ccs
= cs
->lpCreateParams
;
1054 ci
->hWindowMenu
= ccs
->hWindowMenu
;
1055 ci
->idFirstChild
= ccs
->idFirstChild
;
1059 LPCLIENTCREATESTRUCT16 ccs
= MapSL((SEGPTR
)cs
->lpCreateParams
);
1060 ci
->hWindowMenu
= HMENU_32(ccs
->hWindowMenu
);
1061 ci
->idFirstChild
= ccs
->idFirstChild
;
1063 WIN_ReleasePtr( wndPtr
);
1066 ci
->nActiveChildren
= 0;
1067 ci
->nTotalCreated
= 0;
1068 ci
->frameTitle
= NULL
;
1070 ci
->hFrameMenu
= GetMenu(cs
->hwndParent
);
1072 if (!hBmpClose
) hBmpClose
= CreateMDIMenuBitmap();
1074 TRACE("Client created - hwnd = %p, idFirst = %u\n", hwnd
, ci
->idFirstChild
);
1080 if( IsZoomed(ci
->hwndActiveChild
) )
1081 MDI_RestoreFrameMenu(GetParent(hwnd
), ci
->hwndActiveChild
);
1083 ci
->nActiveChildren
= 0;
1084 MDI_RefreshMenu(ci
);
1086 if (ci
->child
) HeapFree( GetProcessHeap(), 0, ci
->child
);
1087 if (ci
->frameTitle
) HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1092 case WM_MDIACTIVATE
:
1096 hwndActive
= ci
->hwndActiveChild
;
1098 if( hwndActive
!= (HWND
)wParam
)
1099 SetWindowPos((HWND
)wParam
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1104 return MDICascade(hwnd
, ci
);
1111 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)lParam
;
1112 return (LRESULT
)CreateWindowExW(WS_EX_MDICHILD
, csW
->szClass
,
1113 csW
->szTitle
, csW
->style
,
1114 csW
->x
, csW
->y
, csW
->cx
, csW
->cy
,
1115 hwnd
, 0, csW
->hOwner
,
1116 (LPVOID
)csW
->lParam
);
1120 MDICREATESTRUCTA
*csA
= (MDICREATESTRUCTA
*)lParam
;
1121 return (LRESULT
)CreateWindowExA(WS_EX_MDICHILD
, csA
->szClass
,
1122 csA
->szTitle
, csA
->style
,
1123 csA
->x
, csA
->y
, csA
->cx
, csA
->cy
,
1124 hwnd
, 0, csA
->hOwner
,
1125 (LPVOID
)csA
->lParam
);
1131 return MDIDestroyChild( hwnd
, ci
, WIN_GetFullHandle( (HWND
)wParam
), TRUE
);
1133 case WM_MDIGETACTIVE
:
1134 if (lParam
) *(BOOL
*)lParam
= IsZoomed(ci
->hwndActiveChild
);
1135 return (LRESULT
)ci
->hwndActiveChild
;
1137 case WM_MDIICONARRANGE
:
1138 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1139 ArrangeIconicWindows( hwnd
);
1140 ci
->sbRecalc
= SB_BOTH
+1;
1141 SendMessageW( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0 );
1144 case WM_MDIMAXIMIZE
:
1145 ShowWindow( (HWND
)wParam
, SW_MAXIMIZE
);
1148 case WM_MDINEXT
: /* lParam != 0 means previous window */
1149 MDI_SwitchActiveChild( hwnd
, WIN_GetFullHandle( (HWND
)wParam
), !lParam
);
1153 SendMessageW( (HWND
)wParam
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
1157 return MDISetMenu( hwnd
, (HMENU
)wParam
, (HMENU
)lParam
);
1159 case WM_MDIREFRESHMENU
:
1160 return MDI_RefreshMenu( ci
);
1163 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1164 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
1165 MDITile( hwnd
, ci
, wParam
);
1166 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1171 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1172 ScrollChildren( hwnd
, message
, wParam
, lParam
);
1173 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1177 if (ci
->hwndActiveChild
&& !IsIconic( ci
->hwndActiveChild
))
1178 SetFocus( ci
->hwndActiveChild
);
1182 if( ci
->hwndActiveChild
)
1183 SendMessageW(ci
->hwndActiveChild
, message
, wParam
, lParam
);
1186 case WM_PARENTNOTIFY
:
1187 switch (LOWORD(wParam
))
1190 if (GetWindowLongW((HWND
)lParam
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1192 ci
->nTotalCreated
++;
1193 ci
->nActiveChildren
++;
1196 ci
->child
= HeapAlloc(GetProcessHeap(), 0, sizeof(HWND
));
1198 ci
->child
= HeapReAlloc(GetProcessHeap(), 0, ci
->child
, sizeof(HWND
) * ci
->nActiveChildren
);
1200 ci
->child
[ci
->nActiveChildren
- 1] = (HWND
)lParam
;
1204 case WM_LBUTTONDOWN
:
1208 pt
.x
= (short)LOWORD(lParam
);
1209 pt
.y
= (short)HIWORD(lParam
);
1210 child
= ChildWindowFromPoint(hwnd
, pt
);
1212 TRACE("notification from %p (%li,%li)\n",child
,pt
.x
,pt
.y
);
1214 if( child
&& child
!= hwnd
&& child
!= ci
->hwndActiveChild
)
1215 SetWindowPos(child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1222 if( IsWindow(ci
->hwndActiveChild
) && IsZoomed(ci
->hwndActiveChild
) &&
1223 IsWindowVisible(ci
->hwndActiveChild
) )
1229 rect
.right
= LOWORD(lParam
);
1230 rect
.bottom
= HIWORD(lParam
);
1232 AdjustWindowRectEx(&rect
, GetWindowLongA(ci
->hwndActiveChild
, GWL_STYLE
),
1233 0, GetWindowLongA(ci
->hwndActiveChild
, GWL_EXSTYLE
) );
1234 MoveWindow(ci
->hwndActiveChild
, rect
.left
, rect
.top
,
1235 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 1);
1238 MDI_PostUpdate(hwnd
, ci
, SB_BOTH
+1);
1242 case WM_MDICALCCHILDSCROLL
:
1243 if( (ci
->mdiFlags
& MDIF_NEEDUPDATE
) && ci
->sbRecalc
)
1245 CalcChildScroll(hwnd
, ci
->sbRecalc
-1);
1247 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1251 return unicode
? DefWindowProcW( hwnd
, message
, wParam
, lParam
) :
1252 DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1255 /***********************************************************************
1258 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1260 if (!IsWindow(hwnd
)) return 0;
1261 return MDIClientWndProc_common( hwnd
, message
, wParam
, lParam
, FALSE
);
1264 /***********************************************************************
1267 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1269 if (!IsWindow(hwnd
)) return 0;
1270 return MDIClientWndProc_common( hwnd
, message
, wParam
, lParam
, TRUE
);
1273 /***********************************************************************
1274 * DefFrameProcA (USER32.@)
1276 LRESULT WINAPI
DefFrameProcA( HWND hwnd
, HWND hwndMDIClient
,
1277 UINT message
, WPARAM wParam
, LPARAM lParam
)
1285 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, NULL
, 0 );
1286 LPWSTR text
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1287 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, text
, len
);
1288 MDI_UpdateFrameText(hwnd
, hwndMDIClient
, TRUE
, text
);
1289 HeapFree( GetProcessHeap(), 0, text
);
1291 return 1; /* success. FIXME: check text length */
1298 return DefFrameProcW( hwnd
, hwndMDIClient
, message
, wParam
, lParam
);
1301 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1305 /***********************************************************************
1306 * DefFrameProcW (USER32.@)
1308 LRESULT WINAPI
DefFrameProcW( HWND hwnd
, HWND hwndMDIClient
,
1309 UINT message
, WPARAM wParam
, LPARAM lParam
)
1311 MDICLIENTINFO
*ci
= get_client_info( hwndMDIClient
);
1313 TRACE("%p %p %04x %08x %08lx\n", hwnd
, hwndMDIClient
, message
, wParam
, lParam
);
1321 WORD id
= LOWORD(wParam
);
1322 /* check for possible syscommands for maximized MDI child */
1323 if (id
< ci
->idFirstChild
|| id
>= ci
->idFirstChild
+ ci
->nActiveChildren
)
1325 if( (id
- 0xf000) & 0xf00f ) break;
1326 if( !IsZoomed(ci
->hwndActiveChild
) ) break;
1337 return SendMessageW( ci
->hwndActiveChild
, WM_SYSCOMMAND
,
1344 if (id
- ci
->idFirstChild
== MDI_MOREWINDOWSLIMIT
)
1345 /* User chose "More Windows..." */
1346 childHwnd
= MDI_MoreWindowsDialog(hwndMDIClient
);
1348 /* User chose one of the windows listed in the "Windows" menu */
1349 childHwnd
= MDI_GetChildByID(hwndMDIClient
, id
, ci
);
1352 SendMessageW( hwndMDIClient
, WM_MDIACTIVATE
, (WPARAM
)childHwnd
, 0 );
1358 SendMessageW(hwndMDIClient
, message
, wParam
, lParam
);
1362 MDI_UpdateFrameText(hwnd
, hwndMDIClient
, TRUE
, (LPWSTR
)lParam
);
1363 return 1; /* success. FIXME: check text length */
1366 SetFocus(hwndMDIClient
);
1370 MoveWindow(hwndMDIClient
, 0, 0, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1375 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1377 if (!IsIconic(hwnd
) && ci
->hwndActiveChild
&& !IsZoomed(ci
->hwndActiveChild
))
1379 /* control menu is between the frame system menu and
1380 * the first entry of menu bar */
1381 WND
*wndPtr
= WIN_GetPtr(hwnd
);
1383 if( (wParam
== VK_LEFT
&& GetMenu(hwnd
) == next_menu
->hmenuIn
) ||
1384 (wParam
== VK_RIGHT
&& GetSubMenu(wndPtr
->hSysMenu
, 0) == next_menu
->hmenuIn
) )
1386 WIN_ReleasePtr(wndPtr
);
1387 wndPtr
= WIN_GetPtr(ci
->hwndActiveChild
);
1388 next_menu
->hmenuNext
= GetSubMenu(wndPtr
->hSysMenu
, 0);
1389 next_menu
->hwndNext
= ci
->hwndActiveChild
;
1391 WIN_ReleasePtr(wndPtr
);
1398 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1401 /***********************************************************************
1402 * DefMDIChildProcA (USER32.@)
1404 LRESULT WINAPI
DefMDIChildProcA( HWND hwnd
, UINT message
,
1405 WPARAM wParam
, LPARAM lParam
)
1407 HWND client
= GetParent(hwnd
);
1408 MDICLIENTINFO
*ci
= get_client_info( client
);
1410 TRACE("%p %04x %08x %08lx\n", hwnd
, message
, wParam
, lParam
);
1412 hwnd
= WIN_GetFullHandle( hwnd
);
1413 if (!ci
) return DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1418 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1419 if( ci
->hwndActiveChild
== hwnd
&& IsZoomed(ci
->hwndActiveChild
) )
1420 MDI_UpdateFrameText( GetParent(client
), client
, TRUE
, NULL
);
1421 return 1; /* success. FIXME: check text length */
1423 case WM_GETMINMAXINFO
:
1427 case WM_CHILDACTIVATE
:
1433 return DefMDIChildProcW( hwnd
, message
, wParam
, lParam
);
1435 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1439 /***********************************************************************
1440 * DefMDIChildProcW (USER32.@)
1442 LRESULT WINAPI
DefMDIChildProcW( HWND hwnd
, UINT message
,
1443 WPARAM wParam
, LPARAM lParam
)
1445 HWND client
= GetParent(hwnd
);
1446 MDICLIENTINFO
*ci
= get_client_info( client
);
1448 TRACE("%p %04x %08x %08lx\n", hwnd
, message
, wParam
, lParam
);
1450 hwnd
= WIN_GetFullHandle( hwnd
);
1451 if (!ci
) return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1456 DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1457 if( ci
->hwndActiveChild
== hwnd
&& IsZoomed(ci
->hwndActiveChild
) )
1458 MDI_UpdateFrameText( GetParent(client
), client
, TRUE
, NULL
);
1459 return 1; /* success. FIXME: check text length */
1461 case WM_GETMINMAXINFO
:
1462 MDI_ChildGetMinMaxInfo( client
, hwnd
, (MINMAXINFO
*)lParam
);
1466 return 0x00010000; /* MDI children don't have menu bars */
1469 SendMessageW( client
, WM_MDIDESTROY
, (WPARAM
)hwnd
, 0 );
1473 if (ci
->hwndActiveChild
!= hwnd
) MDI_ChildActivate( client
, hwnd
);
1476 case WM_CHILDACTIVATE
:
1477 MDI_ChildActivate( client
, hwnd
);
1484 if( ci
->hwndActiveChild
== hwnd
&& IsZoomed(ci
->hwndActiveChild
))
1489 SetWindowLongW( hwnd
, GWL_STYLE
,
1490 GetWindowLongW( hwnd
, GWL_STYLE
) | WS_SYSMENU
);
1493 if (ci
->hwndActiveChild
== hwnd
&& IsZoomed(ci
->hwndActiveChild
))
1494 return SendMessageW( GetParent(client
), message
, wParam
, lParam
);
1495 SetWindowLongW( hwnd
, GWL_STYLE
,
1496 GetWindowLongW( hwnd
, GWL_STYLE
) & ~WS_SYSMENU
);
1499 SendMessageW( client
, WM_MDINEXT
, 0, 0);
1502 SendMessageW( client
, WM_MDINEXT
, 0, 1);
1508 if (IsZoomed(ci
->hwndActiveChild
)) ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1509 else MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1513 if (wParam
== SIZE_MAXIMIZED
&& !IsWindowVisible(hwnd
))
1514 wParam
= SIZE_RESTORED
;
1516 if( hwnd
== ci
->hwndActiveChild
&& wParam
!= SIZE_MAXIMIZED
)
1518 MDI_RestoreFrameMenu( GetParent(client
), hwnd
);
1519 MDI_UpdateFrameText( GetParent(client
), client
, TRUE
, NULL
);
1522 if( wParam
== SIZE_MAXIMIZED
)
1524 TRACE("maximizing child %p\n", hwnd
);
1526 MDI_AugmentFrameMenu( GetParent(client
), hwnd
);
1527 MDI_UpdateFrameText( GetParent(client
), client
, TRUE
, NULL
);
1530 if( wParam
== SIZE_MINIMIZED
)
1532 HWND switchTo
= MDI_GetWindow(ci
, hwnd
, TRUE
, WS_MINIMIZE
);
1534 if (switchTo
) SendMessageW( switchTo
, WM_CHILDACTIVATE
, 0, 0);
1536 MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1541 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1542 HWND parent
= GetParent(client
);
1544 if( wParam
== VK_LEFT
) /* switch to frame system menu */
1546 WND
*wndPtr
= WIN_GetPtr( parent
);
1547 next_menu
->hmenuNext
= GetSubMenu( wndPtr
->hSysMenu
, 0 );
1548 WIN_ReleasePtr( wndPtr
);
1550 if( wParam
== VK_RIGHT
) /* to frame menu bar */
1552 next_menu
->hmenuNext
= GetMenu(parent
);
1554 next_menu
->hwndNext
= parent
;
1561 SendMessageW( hwnd
, WM_SYSCOMMAND
, (WPARAM
)SC_KEYMENU
, (DWORD
)VK_SPACE
);
1566 return DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1569 /**********************************************************************
1570 * CreateMDIWindowA (USER32.@) Creates a MDI child
1573 * Success: Handle to created window
1576 HWND WINAPI
CreateMDIWindowA(
1577 LPCSTR lpClassName
, /* [in] Pointer to registered child class name */
1578 LPCSTR lpWindowName
, /* [in] Pointer to window name */
1579 DWORD dwStyle
, /* [in] Window style */
1580 INT X
, /* [in] Horizontal position of window */
1581 INT Y
, /* [in] Vertical position of window */
1582 INT nWidth
, /* [in] Width of window */
1583 INT nHeight
, /* [in] Height of window */
1584 HWND hWndParent
, /* [in] Handle to parent window */
1585 HINSTANCE hInstance
, /* [in] Handle to application instance */
1586 LPARAM lParam
) /* [in] Application-defined value */
1588 TRACE("(%s,%s,%08lx,%d,%d,%d,%d,%p,%p,%08lx)\n",
1589 debugstr_a(lpClassName
),debugstr_a(lpWindowName
),dwStyle
,X
,Y
,
1590 nWidth
,nHeight
,hWndParent
,hInstance
,lParam
);
1592 return CreateWindowExA(WS_EX_MDICHILD
, lpClassName
, lpWindowName
,
1593 dwStyle
, X
, Y
, nWidth
, nHeight
, hWndParent
,
1594 0, hInstance
, (LPVOID
)lParam
);
1597 /***********************************************************************
1598 * CreateMDIWindowW (USER32.@) Creates a MDI child
1601 * Success: Handle to created window
1604 HWND WINAPI
CreateMDIWindowW(
1605 LPCWSTR lpClassName
, /* [in] Pointer to registered child class name */
1606 LPCWSTR lpWindowName
, /* [in] Pointer to window name */
1607 DWORD dwStyle
, /* [in] Window style */
1608 INT X
, /* [in] Horizontal position of window */
1609 INT Y
, /* [in] Vertical position of window */
1610 INT nWidth
, /* [in] Width of window */
1611 INT nHeight
, /* [in] Height of window */
1612 HWND hWndParent
, /* [in] Handle to parent window */
1613 HINSTANCE hInstance
, /* [in] Handle to application instance */
1614 LPARAM lParam
) /* [in] Application-defined value */
1616 TRACE("(%s,%s,%08lx,%d,%d,%d,%d,%p,%p,%08lx)\n",
1617 debugstr_w(lpClassName
), debugstr_w(lpWindowName
), dwStyle
, X
, Y
,
1618 nWidth
, nHeight
, hWndParent
, hInstance
, lParam
);
1620 return CreateWindowExW(WS_EX_MDICHILD
, lpClassName
, lpWindowName
,
1621 dwStyle
, X
, Y
, nWidth
, nHeight
, hWndParent
,
1622 0, hInstance
, (LPVOID
)lParam
);
1625 /**********************************************************************
1626 * TranslateMDISysAccel (USER32.@)
1628 BOOL WINAPI
TranslateMDISysAccel( HWND hwndClient
, LPMSG msg
)
1630 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
)
1632 MDICLIENTINFO
*ci
= get_client_info( hwndClient
);
1635 if (!ci
|| !IsWindowEnabled(ci
->hwndActiveChild
)) return 0;
1637 /* translate if the Ctrl key is down and Alt not. */
1639 if( (GetKeyState(VK_CONTROL
) & 0x8000) && !(GetKeyState(VK_MENU
) & 0x8000))
1641 switch( msg
->wParam
)
1645 wParam
= ( GetKeyState(VK_SHIFT
) & 0x8000 ) ? SC_NEXTWINDOW
: SC_PREVWINDOW
;
1654 TRACE("wParam = %04x\n", wParam
);
1655 SendMessageW(ci
->hwndActiveChild
, WM_SYSCOMMAND
, wParam
, (LPARAM
)msg
->wParam
);
1659 return 0; /* failure */
1662 /***********************************************************************
1663 * CalcChildScroll (USER32.@)
1665 void WINAPI
CalcChildScroll( HWND hwnd
, INT scroll
)
1668 RECT childRect
, clientRect
;
1671 GetClientRect( hwnd
, &clientRect
);
1672 SetRectEmpty( &childRect
);
1674 if ((list
= WIN_ListChildren( hwnd
)))
1677 for (i
= 0; list
[i
]; i
++)
1679 DWORD style
= GetWindowLongW( list
[i
], GWL_STYLE
);
1680 if (style
& WS_MAXIMIZE
)
1682 HeapFree( GetProcessHeap(), 0, list
);
1683 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
1686 if (style
& WS_VISIBLE
)
1688 WND
*pWnd
= WIN_FindWndPtr( list
[i
] );
1689 UnionRect( &childRect
, &pWnd
->rectWindow
, &childRect
);
1690 WIN_ReleaseWndPtr( pWnd
);
1693 HeapFree( GetProcessHeap(), 0, list
);
1695 UnionRect( &childRect
, &clientRect
, &childRect
);
1697 /* set common info values */
1698 info
.cbSize
= sizeof(info
);
1699 info
.fMask
= SIF_POS
| SIF_RANGE
;
1701 /* set the specific */
1706 info
.nMin
= childRect
.left
;
1707 info
.nMax
= childRect
.right
- clientRect
.right
;
1708 info
.nPos
= clientRect
.left
- childRect
.left
;
1709 SetScrollInfo(hwnd
, scroll
, &info
, TRUE
);
1710 if (scroll
== SB_HORZ
) break;
1713 info
.nMin
= childRect
.top
;
1714 info
.nMax
= childRect
.bottom
- clientRect
.bottom
;
1715 info
.nPos
= clientRect
.top
- childRect
.top
;
1716 SetScrollInfo(hwnd
, scroll
, &info
, TRUE
);
1722 /***********************************************************************
1723 * ScrollChildren (USER32.@)
1725 void WINAPI
ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
,
1729 INT curPos
, length
, minPos
, maxPos
, shift
;
1732 GetClientRect( hWnd
, &rect
);
1737 GetScrollRange(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
1738 curPos
= GetScrollPos(hWnd
,SB_HORZ
);
1739 length
= (rect
.right
- rect
.left
) / 2;
1740 shift
= GetSystemMetrics(SM_CYHSCROLL
);
1743 GetScrollRange(hWnd
,SB_VERT
,&minPos
,&maxPos
);
1744 curPos
= GetScrollPos(hWnd
,SB_VERT
);
1745 length
= (rect
.bottom
- rect
.top
) / 2;
1746 shift
= GetSystemMetrics(SM_CXVSCROLL
);
1755 newPos
= curPos
- shift
;
1758 newPos
= curPos
+ shift
;
1761 newPos
= curPos
- length
;
1764 newPos
= curPos
+ length
;
1767 case SB_THUMBPOSITION
:
1768 newPos
= LOWORD(lParam
);
1781 CalcChildScroll(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
1785 if( newPos
> maxPos
)
1788 if( newPos
< minPos
)
1791 SetScrollPos(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
1793 if( uMsg
== WM_VSCROLL
)
1794 ScrollWindowEx(hWnd
,0 ,curPos
- newPos
, NULL
, NULL
, 0, NULL
,
1795 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
1797 ScrollWindowEx(hWnd
,curPos
- newPos
, 0, NULL
, NULL
, 0, NULL
,
1798 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
1802 /******************************************************************************
1803 * CascadeWindows (USER32.@) Cascades MDI child windows
1806 * Success: Number of cascaded windows.
1810 CascadeWindows (HWND hwndParent
, UINT wFlags
, const LPRECT lpRect
,
1811 UINT cKids
, const HWND
*lpKids
)
1813 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
1818 /******************************************************************************
1819 * TileWindows (USER32.@) Tiles MDI child windows
1822 * Success: Number of tiled windows.
1826 TileWindows (HWND hwndParent
, UINT wFlags
, const LPRECT lpRect
,
1827 UINT cKids
, const HWND
*lpKids
)
1829 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
1833 /************************************************************************
1834 * "More Windows..." functionality
1837 /* MDI_MoreWindowsDlgProc
1839 * This function will process the messages sent to the "More Windows..."
1841 * Return values: 0 = cancel pressed
1842 * HWND = ok pressed or double-click in the list...
1846 static INT_PTR WINAPI
MDI_MoreWindowsDlgProc (HWND hDlg
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
1855 MDICLIENTINFO
*ci
= get_client_info( (HWND
)lParam
);
1856 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
1858 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
1860 WCHAR buffer
[MDI_MAXTITLELENGTH
];
1862 if (!InternalGetWindowText( ci
->child
[i
], buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
1864 SendMessageW(hListBox
, LB_ADDSTRING
, 0, (LPARAM
)buffer
);
1865 SendMessageW(hListBox
, LB_SETITEMDATA
, i
, (LPARAM
)ci
->child
[i
] );
1866 length
= strlenW(buffer
); /* FIXME: should use GetTextExtentPoint */
1867 if (length
> widest
)
1870 /* Make sure the horizontal scrollbar scrolls ok */
1871 SendMessageW(hListBox
, LB_SETHORIZONTALEXTENT
, widest
* 6, 0);
1873 /* Set the current selection */
1874 SendMessageW(hListBox
, LB_SETCURSEL
, MDI_MOREWINDOWSLIMIT
, 0);
1879 switch (LOWORD(wParam
))
1882 if (HIWORD(wParam
) != LBN_DBLCLK
) break;
1886 /* windows are sorted by menu ID, so we must return the
1887 * window associated to the given id
1889 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
1890 UINT index
= SendMessageW(hListBox
, LB_GETCURSEL
, 0, 0);
1891 LRESULT res
= SendMessageW(hListBox
, LB_GETITEMDATA
, index
, 0);
1892 EndDialog(hDlg
, res
);
1906 * MDI_MoreWindowsDialog
1908 * Prompts the user with a listbox containing the opened
1909 * documents. The user can then choose a windows and click
1910 * on OK to set the current window to the one selected, or
1911 * CANCEL to cancel. The function returns a handle to the
1915 static HWND
MDI_MoreWindowsDialog(HWND hwnd
)
1921 hRes
= FindResourceA(user32_module
, "MDI_MOREWINDOWS", (LPSTR
)RT_DIALOG
);
1926 hDlgTmpl
= LoadResource(user32_module
, hRes
);
1931 template = LockResource( hDlgTmpl
);
1936 return (HWND
) DialogBoxIndirectParamA(user32_module
,
1937 (LPDLGTEMPLATEA
) template,
1938 hwnd
, MDI_MoreWindowsDlgProc
, (LPARAM
) hwnd
);