3 * Copyright 1994, Bob Amstadt
4 * 1995,1996 Alex Korobka
6 * This file contains routines to support MDI (Multiple Document
7 * Interface) features .
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * Notes: Fairly complete implementation.
24 * Also, Excel and WinWord do _not_ use MDI so if you're trying
25 * to fix them look elsewhere.
27 * Notes on how the "More Windows..." is implemented:
29 * When we have more than 9 opened windows, a "More Windows..."
30 * option appears in the "Windows" menu. Each child window has
31 * a WND* associated with it, accessible 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.
99 #include "user_private.h"
100 #include "wine/debug.h"
102 WINE_DEFAULT_DEBUG_CHANNEL(mdi
);
104 #define MDI_MAXTITLELENGTH 0xa1
106 #define WM_MDICALCCHILDSCROLL 0x003f /* this is exactly what Windows uses */
108 /* "More Windows..." definitions */
109 #define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
110 option will appear under the Windows menu */
111 #define MDI_IDC_LISTBOX 100
112 #define IDS_MDI_MOREWINDOWS 13
114 #define MDIF_NEEDUPDATE 0x0001
118 /* At some points, particularly when switching MDI children, active and
119 * maximized MDI children may be not the same window, so we need to track
121 * The only place where we switch to/from maximized state is DefMDIChildProc
122 * WM_SIZE/SIZE_MAXIMIZED handler. We get that notification only after the
123 * ShowWindow(SW_SHOWMAXIMIZED) request, therefore window is guaranteed to
124 * be visible at the time we get the notification, and it's safe to assume
125 * that hwndChildMaximized is always visible.
126 * If the app plays games with WS_VISIBLE, WS_MAXIMIZE or any other window
127 * states it must keep coherency with USER32 on its own. This is true for
131 UINT nActiveChildren
;
132 HWND hwndChildMaximized
;
133 HWND hwndActiveChild
;
134 HWND
*child
; /* array of tracked children */
141 UINT sbRecalc
; /* SB_xxx flags for scrollbar fixup */
144 static HBITMAP hBmpClose
= 0;
146 /* ----------------- declarations ----------------- */
147 static void MDI_UpdateFrameText( HWND
, HWND
, BOOL
, LPCWSTR
);
148 static BOOL
MDI_AugmentFrameMenu( HWND
, HWND
);
149 static BOOL
MDI_RestoreFrameMenu( HWND
, HWND
);
150 static LONG
MDI_ChildActivate( HWND
, HWND
);
151 static LRESULT
MDI_RefreshMenu(MDICLIENTINFO
*);
153 static HWND
MDI_MoreWindowsDialog(HWND
);
155 /* -------- Miscellaneous service functions ----------
159 static HWND
MDI_GetChildByID(HWND hwnd
, UINT id
, MDICLIENTINFO
*ci
)
163 for (i
= 0; ci
->nActiveChildren
; i
++)
165 if (GetWindowLongPtrW( ci
->child
[i
], GWLP_ID
) == id
)
171 static void MDI_PostUpdate(HWND hwnd
, MDICLIENTINFO
* ci
, WORD recalc
)
173 if( !(ci
->mdiFlags
& MDIF_NEEDUPDATE
) )
175 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
176 PostMessageA( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0);
178 ci
->sbRecalc
= recalc
;
182 /*********************************************************************
183 * MDIClient class descriptor
185 const struct builtin_class_descr MDICLIENT_builtin_class
=
187 L
"MDIClient", /* name */
189 WINPROC_MDICLIENT
, /* proc */
190 sizeof(MDICLIENTINFO
), /* extra */
191 IDC_ARROW
, /* cursor */
192 (HBRUSH
)(COLOR_APPWORKSPACE
+1) /* brush */
196 static MDICLIENTINFO
*get_client_info( HWND client
)
198 MDICLIENTINFO
*ret
= NULL
;
199 WND
*win
= WIN_GetPtr( client
);
202 if (win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
)
204 if (IsWindow(client
)) WARN( "client %p belongs to other process\n", client
);
207 if (win
->flags
& WIN_ISMDICLIENT
)
208 ret
= (MDICLIENTINFO
*)win
->wExtra
;
210 WARN( "%p is not an MDI client\n", client
);
211 WIN_ReleasePtr( win
);
216 static BOOL
is_close_enabled(HWND hwnd
, HMENU hSysMenu
)
218 if (GetClassLongW(hwnd
, GCL_STYLE
) & CS_NOCLOSE
) return FALSE
;
220 if (!hSysMenu
) hSysMenu
= GetSystemMenu(hwnd
, FALSE
);
223 UINT state
= GetMenuState(hSysMenu
, SC_CLOSE
, MF_BYCOMMAND
);
224 if (state
== 0xFFFFFFFF || (state
& (MF_DISABLED
| MF_GRAYED
)))
230 /**********************************************************************
233 * returns "activatable" child different from the current or zero
235 static HWND
MDI_GetWindow(MDICLIENTINFO
*clientInfo
, HWND hWnd
, BOOL bNext
,
242 dwStyleMask
|= WS_DISABLED
| WS_VISIBLE
;
243 if( !hWnd
) hWnd
= clientInfo
->hwndActiveChild
;
245 if (!(list
= WIN_ListChildren( GetParent(hWnd
) ))) return 0;
247 /* start from next after hWnd */
248 while (list
[i
] && list
[i
] != hWnd
) i
++;
251 for ( ; list
[i
]; i
++)
253 if (GetWindow( list
[i
], GW_OWNER
)) continue;
254 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
256 if (bNext
) goto found
;
258 /* now restart from the beginning */
259 for (i
= 0; list
[i
] && list
[i
] != hWnd
; i
++)
261 if (GetWindow( list
[i
], GW_OWNER
)) continue;
262 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
264 if (bNext
) goto found
;
267 HeapFree( GetProcessHeap(), 0, list
);
271 /**********************************************************************
272 * MDI_CalcDefaultChildPos
274 * It seems that the default height is about 2/3 of the client rect
276 void MDI_CalcDefaultChildPos( HWND hwndClient
, INT total
, LPPOINT lpPos
, INT delta
, UINT
*id
)
280 INT spacing
= GetSystemMetrics(SM_CYCAPTION
) + GetSystemMetrics(SM_CYFRAME
) - 1;
282 if (total
< 0) /* we are called from CreateWindow */
284 MDICLIENTINFO
*ci
= get_client_info(hwndClient
);
285 total
= ci
->nTotalCreated
;
286 *id
= ci
->idFirstChild
+ ci
->nActiveChildren
;
287 TRACE("MDI child id %04x\n", *id
);
290 GetClientRect( hwndClient
, &rect
);
291 if( rect
.bottom
- rect
.top
- delta
>= spacing
)
292 rect
.bottom
-= delta
;
294 nstagger
= (rect
.bottom
- rect
.top
)/(3 * spacing
);
295 lpPos
[1].x
= (rect
.right
- rect
.left
- nstagger
* spacing
);
296 lpPos
[1].y
= (rect
.bottom
- rect
.top
- nstagger
* spacing
);
297 lpPos
[0].x
= lpPos
[0].y
= spacing
* (total
%(nstagger
+1));
300 /**********************************************************************
303 static LRESULT
MDISetMenu( HWND hwnd
, HMENU hmenuFrame
,
307 HWND hwndFrame
= GetParent(hwnd
);
309 TRACE("%p, frame menu %p, window menu %p\n", hwnd
, hmenuFrame
, hmenuWindow
);
311 if (hmenuFrame
&& !IsMenu(hmenuFrame
))
313 WARN("hmenuFrame is not a menu handle\n");
317 if (hmenuWindow
&& !IsMenu(hmenuWindow
))
319 WARN("hmenuWindow is not a menu handle\n");
323 if (!(ci
= get_client_info( hwnd
))) return 0;
325 TRACE("old frame menu %p, old window menu %p\n", ci
->hFrameMenu
, ci
->hWindowMenu
);
329 if (hmenuFrame
== ci
->hFrameMenu
) return (LRESULT
)hmenuFrame
;
331 if (ci
->hwndChildMaximized
)
332 MDI_RestoreFrameMenu( hwndFrame
, ci
->hwndChildMaximized
);
335 if( hmenuWindow
&& hmenuWindow
!= ci
->hWindowMenu
)
337 /* delete menu items from ci->hWindowMenu
338 * and add them to hmenuWindow */
339 /* Agent newsreader calls this function with ci->hWindowMenu == NULL */
340 if( ci
->hWindowMenu
&& ci
->nActiveChildren
)
342 UINT nActiveChildren_old
= ci
->nActiveChildren
;
344 /* Remove all items from old Window menu */
345 ci
->nActiveChildren
= 0;
348 ci
->hWindowMenu
= hmenuWindow
;
350 /* Add items to the new Window menu */
351 ci
->nActiveChildren
= nActiveChildren_old
;
355 ci
->hWindowMenu
= hmenuWindow
;
360 SetMenu(hwndFrame
, hmenuFrame
);
361 if( hmenuFrame
!= ci
->hFrameMenu
)
363 HMENU oldFrameMenu
= ci
->hFrameMenu
;
365 ci
->hFrameMenu
= hmenuFrame
;
366 if (ci
->hwndChildMaximized
)
367 MDI_AugmentFrameMenu( hwndFrame
, ci
->hwndChildMaximized
);
369 return (LRESULT
)oldFrameMenu
;
376 /**********************************************************************
379 static LRESULT
MDI_RefreshMenu(MDICLIENTINFO
*ci
)
381 UINT i
, count
, visible
, id
;
382 WCHAR buf
[MDI_MAXTITLELENGTH
];
384 TRACE("children %u, window menu %p\n", ci
->nActiveChildren
, ci
->hWindowMenu
);
386 if (!ci
->hWindowMenu
)
389 if (!IsMenu(ci
->hWindowMenu
))
391 WARN("Window menu handle %p is no longer valid\n", ci
->hWindowMenu
);
395 /* Windows finds the last separator in the menu, and if after it
396 * there is a menu item with MDI magic ID removes all existing
397 * menu items after it, and then adds visible MDI children.
399 count
= GetMenuItemCount(ci
->hWindowMenu
);
400 for (i
= 0; i
< count
; i
++)
404 memset(&mii
, 0, sizeof(mii
));
405 mii
.cbSize
= sizeof(mii
);
406 mii
.fMask
= MIIM_TYPE
;
407 if (GetMenuItemInfoW(ci
->hWindowMenu
, i
, TRUE
, &mii
))
409 if (mii
.fType
& MF_SEPARATOR
)
411 /* Windows checks only ID of the menu item */
412 memset(&mii
, 0, sizeof(mii
));
413 mii
.cbSize
= sizeof(mii
);
415 if (GetMenuItemInfoW(ci
->hWindowMenu
, i
+ 1, TRUE
, &mii
))
417 if (mii
.wID
== ci
->idFirstChild
)
419 TRACE("removing %u items including separator\n", count
- i
);
420 while (RemoveMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
))
431 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
433 if (GetWindowLongW(ci
->child
[i
], GWL_STYLE
) & WS_VISIBLE
)
435 id
= ci
->idFirstChild
+ visible
;
437 if (visible
== MDI_MOREWINDOWSLIMIT
)
439 LoadStringW(user32_module
, IDS_MDI_MOREWINDOWS
, buf
, ARRAY_SIZE(buf
));
440 AppendMenuW(ci
->hWindowMenu
, MF_STRING
, id
, buf
);
445 /* Visio expects that separator has id 0 */
446 AppendMenuW(ci
->hWindowMenu
, MF_SEPARATOR
, 0, NULL
);
450 SetWindowLongPtrW(ci
->child
[i
], GWLP_ID
, id
);
453 buf
[1] = '0' + visible
;
455 InternalGetWindowText(ci
->child
[i
], buf
+ 3, ARRAY_SIZE(buf
) - 3);
456 TRACE("Adding %p, id %u %s\n", ci
->child
[i
], id
, debugstr_w(buf
));
457 AppendMenuW(ci
->hWindowMenu
, MF_STRING
, id
, buf
);
459 if (ci
->child
[i
] == ci
->hwndActiveChild
)
460 CheckMenuItem(ci
->hWindowMenu
, id
, MF_CHECKED
);
463 TRACE("MDI child %p is not visible, skipping\n", ci
->child
[i
]);
466 return (LRESULT
)ci
->hFrameMenu
;
470 /* ------------------ MDI child window functions ---------------------- */
472 /**********************************************************************
473 * MDI_ChildGetMinMaxInfo
475 * Note: The rule here is that client rect of the maximized MDI child
476 * is equal to the client rect of the MDI client window.
478 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
482 GetClientRect( client
, &rect
);
483 AdjustWindowRectEx( &rect
, GetWindowLongW( hwnd
, GWL_STYLE
),
484 0, GetWindowLongW( hwnd
, GWL_EXSTYLE
));
486 lpMinMax
->ptMaxSize
.x
= rect
.right
-= rect
.left
;
487 lpMinMax
->ptMaxSize
.y
= rect
.bottom
-= rect
.top
;
489 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
490 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
492 TRACE("max rect %s\n", wine_dbgstr_rect(&rect
));
495 /**********************************************************************
496 * MDI_SwitchActiveChild
498 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
501 static void MDI_SwitchActiveChild( MDICLIENTINFO
*ci
, HWND hwndTo
, BOOL activate
)
505 hwndPrev
= ci
->hwndActiveChild
;
507 TRACE("from %p, to %p\n", hwndPrev
, hwndTo
);
509 if ( hwndTo
!= hwndPrev
)
511 BOOL was_zoomed
= IsZoomed(hwndPrev
);
515 /* restore old MDI child */
516 SendMessageW( hwndPrev
, WM_SETREDRAW
, FALSE
, 0 );
517 ShowWindow( hwndPrev
, SW_RESTORE
);
518 SendMessageW( hwndPrev
, WM_SETREDRAW
, TRUE
, 0 );
520 /* activate new MDI child */
521 SetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
);
522 /* maximize new MDI child */
523 ShowWindow( hwndTo
, SW_MAXIMIZE
);
525 /* activate new MDI child */
526 SetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
| (activate
? 0 : SWP_NOACTIVATE
) );
531 /**********************************************************************
534 static LRESULT
MDIDestroyChild( HWND client
, MDICLIENTINFO
*ci
,
535 HWND child
, BOOL flagDestroy
)
539 TRACE("# of managed children %u\n", ci
->nActiveChildren
);
541 if( child
== ci
->hwndActiveChild
)
543 HWND next
= MDI_GetWindow(ci
, child
, TRUE
, 0);
544 /* flagDestroy == 0 means we were called from WM_PARENTNOTIFY handler */
545 if (flagDestroy
&& next
)
546 MDI_SwitchActiveChild(ci
, next
, TRUE
);
549 ShowWindow(child
, SW_HIDE
);
550 if (child
== ci
->hwndChildMaximized
)
552 HWND frame
= GetParent(client
);
553 MDI_RestoreFrameMenu(frame
, child
);
554 ci
->hwndChildMaximized
= 0;
555 MDI_UpdateFrameText(frame
, client
, TRUE
, NULL
);
558 MDI_ChildActivate(client
, 0);
562 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
564 if (ci
->child
[i
] == child
)
566 HWND
*new_child
= HeapAlloc(GetProcessHeap(), 0, (ci
->nActiveChildren
- 1) * sizeof(HWND
));
567 memcpy(new_child
, ci
->child
, i
* sizeof(HWND
));
568 if (i
+ 1 < ci
->nActiveChildren
)
569 memcpy(new_child
+ i
, ci
->child
+ i
+ 1, (ci
->nActiveChildren
- i
- 1) * sizeof(HWND
));
570 HeapFree(GetProcessHeap(), 0, ci
->child
);
571 ci
->child
= new_child
;
573 ci
->nActiveChildren
--;
580 SendMessageW(client
, WM_MDIREFRESHMENU
, 0, 0);
581 MDI_PostUpdate(GetParent(child
), ci
, SB_BOTH
+1);
582 DestroyWindow(child
);
585 TRACE("child destroyed - %p\n", child
);
590 /**********************************************************************
593 * Called in response to WM_CHILDACTIVATE, or when last MDI child
594 * is being deactivated.
596 static LONG
MDI_ChildActivate( HWND client
, HWND child
)
598 MDICLIENTINFO
*clientInfo
;
599 HWND prevActiveWnd
, frame
;
600 BOOL isActiveFrameWnd
;
602 clientInfo
= get_client_info( client
);
604 if (clientInfo
->hwndActiveChild
== child
) return 0;
606 TRACE("%p\n", child
);
608 frame
= GetParent(client
);
609 isActiveFrameWnd
= (GetActiveWindow() == frame
);
610 prevActiveWnd
= clientInfo
->hwndActiveChild
;
612 /* deactivate prev. active child */
615 SendMessageW( prevActiveWnd
, WM_NCACTIVATE
, FALSE
, 0L );
616 SendMessageW( prevActiveWnd
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
619 MDI_SwitchActiveChild( clientInfo
, child
, FALSE
);
620 clientInfo
->hwndActiveChild
= child
;
622 MDI_RefreshMenu(clientInfo
);
624 if( isActiveFrameWnd
)
626 SendMessageW( child
, WM_NCACTIVATE
, TRUE
, 0L);
627 /* Let the client window manage focus for children, but if the focus
628 * is already on the client (for instance this is the 1st child) then
629 * SetFocus won't work. It appears that Windows sends WM_SETFOCUS
630 * manually in this case.
632 if (SetFocus(client
) == client
)
633 SendMessageW( client
, WM_SETFOCUS
, (WPARAM
)client
, 0 );
636 SendMessageW( child
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
640 /* -------------------- MDI client window functions ------------------- */
642 /**********************************************************************
643 * CreateMDIMenuBitmap
645 static HBITMAP
CreateMDIMenuBitmap(void)
647 HDC hDCSrc
= CreateCompatibleDC(0);
648 HDC hDCDest
= CreateCompatibleDC(hDCSrc
);
649 HBITMAP hbClose
= LoadBitmapW(0, MAKEINTRESOURCEW(OBM_OLD_CLOSE
) );
651 HBITMAP hobjSrc
, hobjDest
;
653 hobjSrc
= SelectObject(hDCSrc
, hbClose
);
654 hbCopy
= CreateCompatibleBitmap(hDCSrc
,GetSystemMetrics(SM_CXSIZE
),GetSystemMetrics(SM_CYSIZE
));
655 hobjDest
= SelectObject(hDCDest
, hbCopy
);
657 BitBlt(hDCDest
, 0, 0, GetSystemMetrics(SM_CXSIZE
), GetSystemMetrics(SM_CYSIZE
),
658 hDCSrc
, GetSystemMetrics(SM_CXSIZE
), 0, SRCCOPY
);
660 SelectObject(hDCSrc
, hobjSrc
);
661 DeleteObject(hbClose
);
664 hobjSrc
= SelectObject( hDCDest
, GetStockObject(BLACK_PEN
) );
666 MoveToEx( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, 0, NULL
);
667 LineTo( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, GetSystemMetrics(SM_CYSIZE
) - 1);
669 SelectObject(hDCDest
, hobjSrc
);
670 SelectObject(hDCDest
, hobjDest
);
676 /**********************************************************************
679 static LONG
MDICascade( HWND client
, MDICLIENTINFO
*ci
)
682 BOOL has_icons
= FALSE
;
685 if (ci
->hwndChildMaximized
)
686 SendMessageW(client
, WM_MDIRESTORE
, (WPARAM
)ci
->hwndChildMaximized
, 0);
688 if (ci
->nActiveChildren
== 0) return 0;
690 if (!(win_array
= WIN_ListChildren( client
))) return 0;
692 /* remove all the windows we don't want */
693 for (i
= total
= 0; win_array
[i
]; i
++)
695 if (!IsWindowVisible( win_array
[i
] )) continue;
696 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows */
697 if (IsIconic( win_array
[i
] ))
702 win_array
[total
++] = win_array
[i
];
704 win_array
[total
] = 0;
708 INT delta
= 0, n
= 0, i
;
710 if (has_icons
) delta
= GetSystemMetrics(SM_CYICONSPACING
) + GetSystemMetrics(SM_CYICON
);
712 /* walk the list (backwards) and move windows */
713 for (i
= total
- 1; i
>= 0; i
--)
716 LONG posOptions
= SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
;
718 MDI_CalcDefaultChildPos(client
, n
++, pos
, delta
, NULL
);
719 TRACE("move %p to (%d,%d) size [%d,%d]\n",
720 win_array
[i
], pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
);
721 style
= GetWindowLongW(win_array
[i
], GWL_STYLE
);
723 if (!(style
& WS_SIZEBOX
)) posOptions
|= SWP_NOSIZE
;
724 SetWindowPos( win_array
[i
], 0, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
,
728 HeapFree( GetProcessHeap(), 0, win_array
);
730 if (has_icons
) ArrangeIconicWindows( client
);
734 /**********************************************************************
737 static void MDITile( HWND client
, MDICLIENTINFO
*ci
, WPARAM wParam
)
741 BOOL has_icons
= FALSE
;
743 if (ci
->hwndChildMaximized
)
744 SendMessageW(client
, WM_MDIRESTORE
, (WPARAM
)ci
->hwndChildMaximized
, 0);
746 if (ci
->nActiveChildren
== 0) return;
748 if (!(win_array
= WIN_ListChildren( client
))) return;
750 /* remove all the windows we don't want */
751 for (i
= total
= 0; win_array
[i
]; i
++)
753 if (!IsWindowVisible( win_array
[i
] )) continue;
754 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows (icon titles) */
755 if (IsIconic( win_array
[i
] ))
760 if ((wParam
& MDITILE_SKIPDISABLED
) && !IsWindowEnabled( win_array
[i
] )) continue;
761 win_array
[total
++] = win_array
[i
];
763 win_array
[total
] = 0;
765 TRACE("%u windows to tile\n", total
);
769 HWND
*pWnd
= win_array
;
771 int x
, y
, xsize
, ysize
;
772 int rows
, columns
, r
, c
, i
;
774 GetClientRect(client
,&rect
);
775 rows
= (int) sqrt((double)total
);
776 columns
= total
/ rows
;
778 if( wParam
& MDITILE_HORIZONTAL
) /* version >= 3.1 */
781 rows
= columns
; /* exchange r and c */
787 y
= rect
.bottom
- 2 * GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
788 rect
.bottom
= ( y
- GetSystemMetrics(SM_CYICON
) < rect
.top
)? rect
.bottom
: y
;
791 ysize
= rect
.bottom
/ rows
;
792 xsize
= rect
.right
/ columns
;
794 for (x
= i
= 0, c
= 1; c
<= columns
&& *pWnd
; c
++)
799 ysize
= rect
.bottom
/ rows
;
803 for (r
= 1; r
<= rows
&& *pWnd
; r
++, i
++)
805 LONG posOptions
= SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
;
806 LONG style
= GetWindowLongW(win_array
[i
], GWL_STYLE
);
807 if (!(style
& WS_SIZEBOX
)) posOptions
|= SWP_NOSIZE
;
809 SetWindowPos(*pWnd
, 0, x
, y
, xsize
, ysize
, posOptions
);
816 HeapFree( GetProcessHeap(), 0, win_array
);
817 if (has_icons
) ArrangeIconicWindows( client
);
820 /* ----------------------- Frame window ---------------------------- */
823 /**********************************************************************
824 * MDI_AugmentFrameMenu
826 static BOOL
MDI_AugmentFrameMenu( HWND frame
, HWND hChild
)
828 HMENU menu
= GetMenu( frame
);
830 HBITMAP hSysMenuBitmap
= 0;
833 TRACE("frame %p,child %p\n",frame
,hChild
);
835 if (!menu
) return FALSE
;
837 /* create a copy of sysmenu popup and insert it into frame menu bar */
838 if (!(hSysPopup
= GetSystemMenu(hChild
, FALSE
)))
840 TRACE("child %p doesn't have a system menu\n", hChild
);
844 AppendMenuW(menu
, MF_HELP
| MF_BITMAP
,
845 SC_CLOSE
, is_close_enabled(hChild
, hSysPopup
) ?
846 (LPCWSTR
)HBMMENU_MBAR_CLOSE
: (LPCWSTR
)HBMMENU_MBAR_CLOSE_D
);
847 AppendMenuW(menu
, MF_HELP
| MF_BITMAP
,
848 SC_RESTORE
, (LPCWSTR
)HBMMENU_MBAR_RESTORE
);
849 AppendMenuW(menu
, MF_HELP
| MF_BITMAP
,
850 SC_MINIMIZE
, (LPCWSTR
)HBMMENU_MBAR_MINIMIZE
) ;
852 /* The system menu is replaced by the child icon */
853 hIcon
= (HICON
)SendMessageW(hChild
, WM_GETICON
, ICON_SMALL
, 0);
855 hIcon
= (HICON
)GetClassLongPtrW(hChild
, GCLP_HICONSM
);
857 hIcon
= (HICON
)SendMessageW(hChild
, WM_GETICON
, ICON_BIG
, 0);
859 hIcon
= (HICON
)GetClassLongPtrW(hChild
, GCLP_HICON
);
861 hIcon
= LoadImageW(0, (LPWSTR
)IDI_WINLOGO
, IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
),
862 GetSystemMetrics(SM_CYSMICON
), LR_DEFAULTCOLOR
);
866 HBITMAP hBitmap
, hOldBitmap
;
867 HDC hdc
= GetDC(hChild
);
872 cx
= GetSystemMetrics(SM_CXSMICON
);
873 cy
= GetSystemMetrics(SM_CYSMICON
);
874 hMemDC
= CreateCompatibleDC(hdc
);
875 hBitmap
= CreateCompatibleBitmap(hdc
, cx
, cy
);
876 hOldBitmap
= SelectObject(hMemDC
, hBitmap
);
877 SetMapMode(hMemDC
, MM_TEXT
);
878 DrawIconEx(hMemDC
, 0, 0, hIcon
, cx
, cy
, 0, GetSysColorBrush(COLOR_MENU
), DI_NORMAL
);
879 SelectObject (hMemDC
, hOldBitmap
);
881 ReleaseDC(hChild
, hdc
);
882 hSysMenuBitmap
= hBitmap
;
886 if( !InsertMenuA(menu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
887 (UINT_PTR
)hSysPopup
, (LPSTR
)hSysMenuBitmap
))
889 TRACE("not inserted\n");
890 DestroyMenu(hSysPopup
);
894 EnableMenuItem(hSysPopup
, SC_SIZE
, MF_BYCOMMAND
| MF_GRAYED
);
895 EnableMenuItem(hSysPopup
, SC_MOVE
, MF_BYCOMMAND
| MF_GRAYED
);
896 EnableMenuItem(hSysPopup
, SC_MAXIMIZE
, MF_BYCOMMAND
| MF_GRAYED
);
897 SetMenuDefaultItem(hSysPopup
, SC_CLOSE
, FALSE
);
905 /**********************************************************************
906 * MDI_RestoreFrameMenu
908 static BOOL
MDI_RestoreFrameMenu( HWND frame
, HWND hChild
)
910 MENUITEMINFOW menuInfo
;
911 HMENU menu
= GetMenu( frame
);
915 TRACE("frame %p, child %p\n", frame
, hChild
);
917 if (!menu
) return FALSE
;
919 /* if there is no system buttons then nothing to do */
920 nItems
= GetMenuItemCount(menu
) - 1;
921 iId
= GetMenuItemID(menu
, nItems
);
922 if ( !(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
926 * Remove the system menu, If that menu is the icon of the window
927 * as it is in win95, we have to delete the bitmap.
929 memset(&menuInfo
, 0, sizeof(menuInfo
));
930 menuInfo
.cbSize
= sizeof(menuInfo
);
931 menuInfo
.fMask
= MIIM_DATA
| MIIM_TYPE
;
933 GetMenuItemInfoW(menu
,
938 RemoveMenu(menu
,0,MF_BYPOSITION
);
940 if ( (menuInfo
.fType
& MFT_BITMAP
) &&
941 (LOWORD(menuInfo
.dwTypeData
)!=0) &&
942 (LOWORD(menuInfo
.dwTypeData
)!=HBITMAP_16(hBmpClose
)) )
944 DeleteObject(HBITMAP_32(LOWORD(menuInfo
.dwTypeData
)));
948 DeleteMenu(menu
, SC_CLOSE
, MF_BYCOMMAND
);
950 DeleteMenu(menu
, SC_RESTORE
, MF_BYCOMMAND
);
952 DeleteMenu(menu
, SC_MINIMIZE
, MF_BYCOMMAND
);
960 /**********************************************************************
961 * MDI_UpdateFrameText
963 * used when child window is maximized/restored
965 * Note: lpTitle can be NULL
967 static void MDI_UpdateFrameText( HWND frame
, HWND hClient
, BOOL repaint
, LPCWSTR lpTitle
)
969 WCHAR lpBuffer
[MDI_MAXTITLELENGTH
+1];
970 MDICLIENTINFO
*ci
= get_client_info( hClient
);
972 TRACE("frameText %s\n", debugstr_w(lpTitle
));
976 if (!lpTitle
&& !ci
->frameTitle
) /* first time around, get title from the frame window */
978 GetWindowTextW( frame
, lpBuffer
, ARRAY_SIZE( lpBuffer
));
982 /* store new "default" title if lpTitle is not NULL */
985 HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
986 if ((ci
->frameTitle
= HeapAlloc( GetProcessHeap(), 0, (lstrlenW(lpTitle
)+1)*sizeof(WCHAR
))))
987 lstrcpyW( ci
->frameTitle
, lpTitle
);
992 if (ci
->hwndChildMaximized
)
994 /* combine frame title and child title if possible */
995 int i_frame_text_length
= lstrlenW(ci
->frameTitle
);
997 lstrcpynW( lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
999 if( i_frame_text_length
+ 6 < MDI_MAXTITLELENGTH
)
1001 lstrcatW( lpBuffer
, L
" - [" );
1002 if (GetWindowTextW( ci
->hwndActiveChild
, lpBuffer
+ i_frame_text_length
+ 4,
1003 MDI_MAXTITLELENGTH
- i_frame_text_length
- 5 ))
1004 lstrcatW( lpBuffer
, L
"]" );
1006 lpBuffer
[i_frame_text_length
] = 0; /* remove bracket */
1011 lstrcpynW(lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
+1 );
1017 DefWindowProcW( frame
, WM_SETTEXT
, 0, (LPARAM
)lpBuffer
);
1020 SetWindowPos( frame
, 0,0,0,0,0, SWP_FRAMECHANGED
|
1021 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
1025 /* ----------------------------- Interface ---------------------------- */
1028 /**********************************************************************
1029 * MDIClientWndProc_common
1031 LRESULT
MDIClientWndProc_common( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1035 TRACE("%p %04x (%s) %08lx %08lx\n", hwnd
, message
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1037 if (!(ci
= get_client_info( hwnd
)))
1039 if (message
== WM_NCCREATE
) win_set_flags( hwnd
, WIN_ISMDICLIENT
, 0 );
1040 return unicode
? DefWindowProcW( hwnd
, message
, wParam
, lParam
) :
1041 DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1048 /* Since we are using only cs->lpCreateParams, we can safely
1049 * cast to LPCREATESTRUCTA here */
1050 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
1051 LPCLIENTCREATESTRUCT ccs
= cs
->lpCreateParams
;
1053 ci
->hWindowMenu
= ccs
->hWindowMenu
;
1054 ci
->idFirstChild
= ccs
->idFirstChild
;
1055 ci
->hwndChildMaximized
= 0;
1057 ci
->nActiveChildren
= 0;
1058 ci
->nTotalCreated
= 0;
1059 ci
->frameTitle
= NULL
;
1061 ci
->hFrameMenu
= GetMenu(cs
->hwndParent
);
1063 if (!hBmpClose
) hBmpClose
= CreateMDIMenuBitmap();
1065 TRACE("Client created: hwnd %p, Window menu %p, idFirst = %04x\n",
1066 hwnd
, ci
->hWindowMenu
, ci
->idFirstChild
);
1072 if( ci
->hwndChildMaximized
)
1073 MDI_RestoreFrameMenu(GetParent(hwnd
), ci
->hwndChildMaximized
);
1075 ci
->nActiveChildren
= 0;
1076 MDI_RefreshMenu(ci
);
1078 HeapFree( GetProcessHeap(), 0, ci
->child
);
1079 HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1084 case WM_MDIACTIVATE
:
1086 if( ci
->hwndActiveChild
!= (HWND
)wParam
)
1087 SetWindowPos((HWND
)wParam
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1092 return MDICascade(hwnd
, ci
);
1101 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)lParam
;
1102 child
= CreateWindowExW(WS_EX_MDICHILD
, csW
->szClass
,
1103 csW
->szTitle
, csW
->style
,
1104 csW
->x
, csW
->y
, csW
->cx
, csW
->cy
,
1105 hwnd
, 0, csW
->hOwner
,
1106 (LPVOID
)csW
->lParam
);
1110 MDICREATESTRUCTA
*csA
= (MDICREATESTRUCTA
*)lParam
;
1111 child
= CreateWindowExA(WS_EX_MDICHILD
, csA
->szClass
,
1112 csA
->szTitle
, csA
->style
,
1113 csA
->x
, csA
->y
, csA
->cx
, csA
->cy
,
1114 hwnd
, 0, csA
->hOwner
,
1115 (LPVOID
)csA
->lParam
);
1117 return (LRESULT
)child
;
1122 return MDIDestroyChild( hwnd
, ci
, WIN_GetFullHandle( (HWND
)wParam
), TRUE
);
1124 case WM_MDIGETACTIVE
:
1125 if (lParam
) *(BOOL
*)lParam
= IsZoomed(ci
->hwndActiveChild
);
1126 return (LRESULT
)ci
->hwndActiveChild
;
1128 case WM_MDIICONARRANGE
:
1129 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1130 ArrangeIconicWindows( hwnd
);
1131 ci
->sbRecalc
= SB_BOTH
+1;
1132 SendMessageW( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0 );
1135 case WM_MDIMAXIMIZE
:
1136 ShowWindow( (HWND
)wParam
, SW_MAXIMIZE
);
1139 case WM_MDINEXT
: /* lParam != 0 means previous window */
1141 HWND hwnd
= wParam
? WIN_GetFullHandle((HWND
)wParam
) : ci
->hwndActiveChild
;
1142 HWND next
= MDI_GetWindow( ci
, hwnd
, !lParam
, 0 );
1143 MDI_SwitchActiveChild( ci
, next
, TRUE
);
1145 SetWindowPos(hwnd
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
1150 ShowWindow( (HWND
)wParam
, SW_SHOWNORMAL
);
1154 return MDISetMenu( hwnd
, (HMENU
)wParam
, (HMENU
)lParam
);
1156 case WM_MDIREFRESHMENU
:
1157 return MDI_RefreshMenu( ci
);
1160 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1161 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
1162 MDITile( hwnd
, ci
, wParam
);
1163 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1168 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1169 ScrollChildren( hwnd
, message
, wParam
, lParam
);
1170 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1174 if (ci
->hwndActiveChild
&& !IsIconic( ci
->hwndActiveChild
))
1175 SetFocus( ci
->hwndActiveChild
);
1179 if( ci
->hwndActiveChild
)
1180 SendMessageW(ci
->hwndActiveChild
, message
, wParam
, lParam
);
1183 case WM_PARENTNOTIFY
:
1184 switch (LOWORD(wParam
))
1187 if (GetWindowLongW((HWND
)lParam
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1189 ci
->nTotalCreated
++;
1190 ci
->nActiveChildren
++;
1193 ci
->child
= HeapAlloc(GetProcessHeap(), 0, sizeof(HWND
));
1195 ci
->child
= HeapReAlloc(GetProcessHeap(), 0, ci
->child
, sizeof(HWND
) * ci
->nActiveChildren
);
1197 TRACE("Adding MDI child %p, # of children %d\n",
1198 (HWND
)lParam
, 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 (%i,%i)\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
);
1220 return MDIDestroyChild( hwnd
, ci
, WIN_GetFullHandle( (HWND
)lParam
), FALSE
);
1225 if( ci
->hwndActiveChild
&& IsZoomed(ci
->hwndActiveChild
) )
1229 SetRect(&rect
, 0, 0, LOWORD(lParam
), HIWORD(lParam
));
1230 AdjustWindowRectEx(&rect
, GetWindowLongA(ci
->hwndActiveChild
, GWL_STYLE
),
1231 0, GetWindowLongA(ci
->hwndActiveChild
, GWL_EXSTYLE
) );
1232 MoveWindow(ci
->hwndActiveChild
, rect
.left
, rect
.top
,
1233 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 1);
1236 MDI_PostUpdate(hwnd
, ci
, SB_BOTH
+1);
1240 case WM_MDICALCCHILDSCROLL
:
1241 if( (ci
->mdiFlags
& MDIF_NEEDUPDATE
) && ci
->sbRecalc
)
1243 CalcChildScroll(hwnd
, ci
->sbRecalc
-1);
1245 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1249 return unicode
? DefWindowProcW( hwnd
, message
, wParam
, lParam
) :
1250 DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1253 /***********************************************************************
1254 * DefFrameProcA (USER32.@)
1256 LRESULT WINAPI
DefFrameProcA( HWND hwnd
, HWND hwndMDIClient
,
1257 UINT message
, WPARAM wParam
, LPARAM lParam
)
1265 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, NULL
, 0 );
1266 LPWSTR text
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1267 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, text
, len
);
1268 MDI_UpdateFrameText( hwnd
, hwndMDIClient
, FALSE
, text
);
1269 HeapFree( GetProcessHeap(), 0, text
);
1271 return 1; /* success. FIXME: check text length */
1278 return DefFrameProcW( hwnd
, hwndMDIClient
, message
, wParam
, lParam
);
1281 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1285 /***********************************************************************
1286 * DefFrameProcW (USER32.@)
1288 LRESULT WINAPI
DefFrameProcW( HWND hwnd
, HWND hwndMDIClient
,
1289 UINT message
, WPARAM wParam
, LPARAM lParam
)
1291 MDICLIENTINFO
*ci
= get_client_info( hwndMDIClient
);
1293 TRACE("%p %p %04x (%s) %08lx %08lx\n", hwnd
, hwndMDIClient
, message
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1301 WORD id
= LOWORD(wParam
);
1302 /* check for possible syscommands for maximized MDI child */
1303 if (id
< ci
->idFirstChild
|| id
>= ci
->idFirstChild
+ ci
->nActiveChildren
)
1305 if( (id
- 0xf000) & 0xf00f ) break;
1306 if( !ci
->hwndChildMaximized
) break;
1310 if (!is_close_enabled(ci
->hwndActiveChild
, 0)) break;
1318 return SendMessageW( ci
->hwndChildMaximized
, WM_SYSCOMMAND
,
1325 if (id
- ci
->idFirstChild
== MDI_MOREWINDOWSLIMIT
)
1326 /* User chose "More Windows..." */
1327 childHwnd
= MDI_MoreWindowsDialog(hwndMDIClient
);
1329 /* User chose one of the windows listed in the "Windows" menu */
1330 childHwnd
= MDI_GetChildByID(hwndMDIClient
, id
, ci
);
1333 SendMessageW( hwndMDIClient
, WM_MDIACTIVATE
, (WPARAM
)childHwnd
, 0 );
1339 SendMessageW(hwndMDIClient
, message
, wParam
, lParam
);
1343 MDI_UpdateFrameText( hwnd
, hwndMDIClient
, FALSE
, (LPWSTR
)lParam
);
1344 return 1; /* success. FIXME: check text length */
1347 SetFocus(hwndMDIClient
);
1351 MoveWindow(hwndMDIClient
, 0, 0, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1356 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1358 if (!IsIconic(hwnd
) && ci
->hwndActiveChild
&& !IsZoomed(ci
->hwndActiveChild
))
1360 /* control menu is between the frame system menu and
1361 * the first entry of menu bar */
1362 WND
*wndPtr
= WIN_GetPtr(hwnd
);
1364 if( (wParam
== VK_LEFT
&& GetMenu(hwnd
) == next_menu
->hmenuIn
) ||
1365 (wParam
== VK_RIGHT
&& GetSubMenu(wndPtr
->hSysMenu
, 0) == next_menu
->hmenuIn
) )
1367 WIN_ReleasePtr(wndPtr
);
1368 wndPtr
= WIN_GetPtr(ci
->hwndActiveChild
);
1369 next_menu
->hmenuNext
= GetSubMenu(wndPtr
->hSysMenu
, 0);
1370 next_menu
->hwndNext
= ci
->hwndActiveChild
;
1372 WIN_ReleasePtr(wndPtr
);
1379 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1382 /***********************************************************************
1383 * DefMDIChildProcA (USER32.@)
1385 LRESULT WINAPI
DefMDIChildProcA( HWND hwnd
, UINT message
,
1386 WPARAM wParam
, LPARAM lParam
)
1388 HWND client
= GetParent(hwnd
);
1389 MDICLIENTINFO
*ci
= get_client_info( client
);
1391 TRACE("%p %04x (%s) %08lx %08lx\n", hwnd
, message
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1393 hwnd
= WIN_GetFullHandle( hwnd
);
1394 if (!ci
) return DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1399 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1400 if( ci
->hwndChildMaximized
== hwnd
)
1401 MDI_UpdateFrameText( GetParent(client
), client
, TRUE
, NULL
);
1402 return 1; /* success. FIXME: check text length */
1404 case WM_GETMINMAXINFO
:
1408 case WM_CHILDACTIVATE
:
1416 return DefMDIChildProcW( hwnd
, message
, wParam
, lParam
);
1418 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1422 /***********************************************************************
1423 * DefMDIChildProcW (USER32.@)
1425 LRESULT WINAPI
DefMDIChildProcW( HWND hwnd
, UINT message
,
1426 WPARAM wParam
, LPARAM lParam
)
1428 HWND client
= GetParent(hwnd
);
1429 MDICLIENTINFO
*ci
= get_client_info( client
);
1431 TRACE("%p %04x (%s) %08lx %08lx\n", hwnd
, message
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1433 hwnd
= WIN_GetFullHandle( hwnd
);
1434 if (!ci
) return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1439 DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1440 if( ci
->hwndChildMaximized
== hwnd
)
1441 MDI_UpdateFrameText( GetParent(client
), client
, TRUE
, NULL
);
1442 return 1; /* success. FIXME: check text length */
1444 case WM_GETMINMAXINFO
:
1445 MDI_ChildGetMinMaxInfo( client
, hwnd
, (MINMAXINFO
*)lParam
);
1449 return MAKELRESULT( 0, MNC_CLOSE
); /* MDI children don't have menu bars */
1452 SendMessageW( client
, WM_MDIDESTROY
, (WPARAM
)hwnd
, 0 );
1456 if (ci
->hwndActiveChild
!= hwnd
)
1457 MDI_ChildActivate( client
, hwnd
);
1460 case WM_CHILDACTIVATE
:
1461 if (IsWindowEnabled( hwnd
))
1462 MDI_ChildActivate( client
, hwnd
);
1466 switch (wParam
& 0xfff0)
1469 if( ci
->hwndChildMaximized
== hwnd
)
1476 if (ci
->hwndChildMaximized
== hwnd
)
1477 return SendMessageW( GetParent(client
), message
, wParam
, lParam
);
1480 SendMessageW( client
, WM_MDINEXT
, (WPARAM
)ci
->hwndActiveChild
, 0);
1483 SendMessageW( client
, WM_MDINEXT
, (WPARAM
)ci
->hwndActiveChild
, 1);
1490 if (ci
->hwndChildMaximized
) ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1491 else MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1495 /* This is the only place where we switch to/from maximized state */
1497 TRACE("current active %p, maximized %p\n", ci
->hwndActiveChild
, ci
->hwndChildMaximized
);
1499 if( ci
->hwndChildMaximized
== hwnd
&& wParam
!= SIZE_MAXIMIZED
)
1503 ci
->hwndChildMaximized
= 0;
1505 frame
= GetParent(client
);
1506 MDI_RestoreFrameMenu( frame
, hwnd
);
1507 MDI_UpdateFrameText( frame
, client
, TRUE
, NULL
);
1510 if( wParam
== SIZE_MAXIMIZED
)
1512 HWND frame
, hMaxChild
= ci
->hwndChildMaximized
;
1514 if( hMaxChild
== hwnd
) break;
1518 SendMessageW( hMaxChild
, WM_SETREDRAW
, FALSE
, 0 );
1520 MDI_RestoreFrameMenu( GetParent(client
), hMaxChild
);
1521 ShowWindow( hMaxChild
, SW_SHOWNOACTIVATE
);
1523 SendMessageW( hMaxChild
, WM_SETREDRAW
, TRUE
, 0 );
1526 TRACE("maximizing child %p\n", hwnd
);
1528 /* keep track of the maximized window. */
1529 ci
->hwndChildMaximized
= hwnd
; /* !!! */
1531 frame
= GetParent(client
);
1532 MDI_AugmentFrameMenu( frame
, hwnd
);
1533 MDI_UpdateFrameText( frame
, client
, TRUE
, NULL
);
1536 if( wParam
== SIZE_MINIMIZED
)
1538 HWND switchTo
= MDI_GetWindow( ci
, hwnd
, TRUE
, WS_MINIMIZE
);
1540 if (!switchTo
) switchTo
= hwnd
;
1541 SendMessageW( switchTo
, WM_CHILDACTIVATE
, 0, 0 );
1544 MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1549 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1550 HWND parent
= GetParent(client
);
1552 if( wParam
== VK_LEFT
) /* switch to frame system menu */
1554 WND
*wndPtr
= WIN_GetPtr( parent
);
1555 next_menu
->hmenuNext
= GetSubMenu( wndPtr
->hSysMenu
, 0 );
1556 WIN_ReleasePtr( wndPtr
);
1558 if( wParam
== VK_RIGHT
) /* to frame menu bar */
1560 next_menu
->hmenuNext
= GetMenu(parent
);
1562 next_menu
->hwndNext
= parent
;
1569 SendMessageW( hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, VK_SPACE
);
1575 /* Remove itself from the Window menu */
1576 MDI_RefreshMenu(ci
);
1579 return DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1582 /**********************************************************************
1583 * CreateMDIWindowA (USER32.@) Creates a MDI child
1586 * Success: Handle to created window
1589 HWND WINAPI
CreateMDIWindowA(
1590 LPCSTR lpClassName
, /* [in] Pointer to registered child class name */
1591 LPCSTR lpWindowName
, /* [in] Pointer to window name */
1592 DWORD dwStyle
, /* [in] Window style */
1593 INT X
, /* [in] Horizontal position of window */
1594 INT Y
, /* [in] Vertical position of window */
1595 INT nWidth
, /* [in] Width of window */
1596 INT nHeight
, /* [in] Height of window */
1597 HWND hWndParent
, /* [in] Handle to parent window */
1598 HINSTANCE hInstance
, /* [in] Handle to application instance */
1599 LPARAM lParam
) /* [in] Application-defined value */
1601 TRACE("(%s,%s,%08x,%d,%d,%d,%d,%p,%p,%08lx)\n",
1602 debugstr_a(lpClassName
),debugstr_a(lpWindowName
),dwStyle
,X
,Y
,
1603 nWidth
,nHeight
,hWndParent
,hInstance
,lParam
);
1605 return CreateWindowExA(WS_EX_MDICHILD
, lpClassName
, lpWindowName
,
1606 dwStyle
, X
, Y
, nWidth
, nHeight
, hWndParent
,
1607 0, hInstance
, (LPVOID
)lParam
);
1610 /***********************************************************************
1611 * CreateMDIWindowW (USER32.@) Creates a MDI child
1614 * Success: Handle to created window
1617 HWND WINAPI
CreateMDIWindowW(
1618 LPCWSTR lpClassName
, /* [in] Pointer to registered child class name */
1619 LPCWSTR lpWindowName
, /* [in] Pointer to window name */
1620 DWORD dwStyle
, /* [in] Window style */
1621 INT X
, /* [in] Horizontal position of window */
1622 INT Y
, /* [in] Vertical position of window */
1623 INT nWidth
, /* [in] Width of window */
1624 INT nHeight
, /* [in] Height of window */
1625 HWND hWndParent
, /* [in] Handle to parent window */
1626 HINSTANCE hInstance
, /* [in] Handle to application instance */
1627 LPARAM lParam
) /* [in] Application-defined value */
1629 TRACE("(%s,%s,%08x,%d,%d,%d,%d,%p,%p,%08lx)\n",
1630 debugstr_w(lpClassName
), debugstr_w(lpWindowName
), dwStyle
, X
, Y
,
1631 nWidth
, nHeight
, hWndParent
, hInstance
, lParam
);
1633 return CreateWindowExW(WS_EX_MDICHILD
, lpClassName
, lpWindowName
,
1634 dwStyle
, X
, Y
, nWidth
, nHeight
, hWndParent
,
1635 0, hInstance
, (LPVOID
)lParam
);
1638 /**********************************************************************
1639 * TranslateMDISysAccel (USER32.@)
1641 BOOL WINAPI
TranslateMDISysAccel( HWND hwndClient
, LPMSG msg
)
1643 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
)
1645 MDICLIENTINFO
*ci
= get_client_info( hwndClient
);
1648 if (!ci
|| !IsWindowEnabled(ci
->hwndActiveChild
)) return FALSE
;
1650 /* translate if the Ctrl key is down and Alt not. */
1652 if( (GetKeyState(VK_CONTROL
) & 0x8000) && !(GetKeyState(VK_MENU
) & 0x8000))
1654 switch( msg
->wParam
)
1658 wParam
= ( GetKeyState(VK_SHIFT
) & 0x8000 ) ? SC_NEXTWINDOW
: SC_PREVWINDOW
;
1662 if (is_close_enabled(ci
->hwndActiveChild
, 0))
1671 TRACE("wParam = %04lx\n", wParam
);
1672 SendMessageW(ci
->hwndActiveChild
, WM_SYSCOMMAND
, wParam
, msg
->wParam
);
1676 return FALSE
; /* failure */
1679 /***********************************************************************
1680 * CalcChildScroll (USER32.@)
1682 void WINAPI
CalcChildScroll( HWND hwnd
, INT scroll
)
1684 DPI_AWARENESS_CONTEXT context
;
1686 RECT childRect
, clientRect
;
1690 context
= SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hwnd
));
1692 GetClientRect( hwnd
, &clientRect
);
1693 SetRectEmpty( &childRect
);
1695 if ((list
= WIN_ListChildren( hwnd
)))
1698 for (i
= 0; list
[i
]; i
++)
1700 style
= GetWindowLongW( list
[i
], GWL_STYLE
);
1701 if (style
& WS_MAXIMIZE
)
1703 HeapFree( GetProcessHeap(), 0, list
);
1704 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
1707 if (style
& WS_VISIBLE
)
1710 WIN_GetRectangles( list
[i
], COORDS_PARENT
, &rect
, NULL
);
1711 UnionRect( &childRect
, &rect
, &childRect
);
1714 HeapFree( GetProcessHeap(), 0, list
);
1716 UnionRect( &childRect
, &clientRect
, &childRect
);
1718 /* set common info values */
1719 info
.cbSize
= sizeof(info
);
1720 info
.fMask
= SIF_POS
| SIF_RANGE
;
1722 /* set the specific values and apply but only if window style allows */
1723 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1728 if (style
& (WS_HSCROLL
| WS_VSCROLL
))
1730 info
.nMin
= childRect
.left
;
1731 info
.nMax
= childRect
.right
- clientRect
.right
;
1732 info
.nPos
= clientRect
.left
- childRect
.left
;
1733 SetScrollInfo(hwnd
, SB_HORZ
, &info
, TRUE
);
1735 if (scroll
== SB_HORZ
) break;
1738 if (style
& (WS_HSCROLL
| WS_VSCROLL
))
1740 info
.nMin
= childRect
.top
;
1741 info
.nMax
= childRect
.bottom
- clientRect
.bottom
;
1742 info
.nPos
= clientRect
.top
- childRect
.top
;
1743 SetScrollInfo(hwnd
, SB_VERT
, &info
, TRUE
);
1747 SetThreadDpiAwarenessContext( context
);
1751 /***********************************************************************
1752 * ScrollChildren (USER32.@)
1754 void WINAPI
ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
,
1757 DPI_AWARENESS_CONTEXT context
;
1759 INT curPos
, length
, minPos
, maxPos
, shift
;
1762 context
= SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hWnd
));
1763 GetClientRect( hWnd
, &rect
);
1768 GetScrollRange(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
1769 curPos
= GetScrollPos(hWnd
,SB_HORZ
);
1770 length
= (rect
.right
- rect
.left
) / 2;
1771 shift
= GetSystemMetrics(SM_CYHSCROLL
);
1774 GetScrollRange(hWnd
,SB_VERT
,&minPos
,&maxPos
);
1775 curPos
= GetScrollPos(hWnd
,SB_VERT
);
1776 length
= (rect
.bottom
- rect
.top
) / 2;
1777 shift
= GetSystemMetrics(SM_CXVSCROLL
);
1786 newPos
= curPos
- shift
;
1789 newPos
= curPos
+ shift
;
1792 newPos
= curPos
- length
;
1795 newPos
= curPos
+ length
;
1798 case SB_THUMBPOSITION
:
1799 newPos
= LOWORD(lParam
);
1812 CalcChildScroll(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
1816 if( newPos
> maxPos
)
1819 if( newPos
< minPos
)
1822 SetScrollPos(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
1824 if( uMsg
== WM_VSCROLL
)
1825 ScrollWindowEx(hWnd
,0 ,curPos
- newPos
, NULL
, NULL
, 0, NULL
,
1826 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
1828 ScrollWindowEx(hWnd
,curPos
- newPos
, 0, NULL
, NULL
, 0, NULL
,
1829 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
1831 SetThreadDpiAwarenessContext( context
);
1835 /******************************************************************************
1836 * CascadeWindows (USER32.@) Cascades MDI child windows
1839 * Success: Number of cascaded windows.
1843 CascadeWindows (HWND hwndParent
, UINT wFlags
, const RECT
*lpRect
,
1844 UINT cKids
, const HWND
*lpKids
)
1846 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
1851 /***********************************************************************
1852 * CascadeChildWindows (USER32.@)
1854 WORD WINAPI
CascadeChildWindows( HWND parent
, UINT flags
)
1856 return CascadeWindows( parent
, flags
, NULL
, 0, NULL
);
1860 /******************************************************************************
1861 * TileWindows (USER32.@) Tiles MDI child windows
1864 * Success: Number of tiled windows.
1868 TileWindows (HWND hwndParent
, UINT wFlags
, const RECT
*lpRect
,
1869 UINT cKids
, const HWND
*lpKids
)
1871 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
1876 /***********************************************************************
1877 * TileChildWindows (USER32.@)
1879 WORD WINAPI
TileChildWindows( HWND parent
, UINT flags
)
1881 return TileWindows( parent
, flags
, NULL
, 0, NULL
);
1885 /************************************************************************
1886 * "More Windows..." functionality
1889 /* MDI_MoreWindowsDlgProc
1891 * This function will process the messages sent to the "More Windows..."
1893 * Return values: 0 = cancel pressed
1894 * HWND = ok pressed or double-click in the list...
1898 static INT_PTR WINAPI
MDI_MoreWindowsDlgProc (HWND hDlg
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
1907 MDICLIENTINFO
*ci
= get_client_info( (HWND
)lParam
);
1908 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
1910 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
1912 WCHAR buffer
[MDI_MAXTITLELENGTH
];
1914 if (!InternalGetWindowText(ci
->child
[i
], buffer
, ARRAY_SIZE(buffer
)))
1916 SendMessageW(hListBox
, LB_ADDSTRING
, 0, (LPARAM
)buffer
);
1917 SendMessageW(hListBox
, LB_SETITEMDATA
, i
, (LPARAM
)ci
->child
[i
] );
1918 length
= lstrlenW(buffer
); /* FIXME: should use GetTextExtentPoint */
1919 if (length
> widest
)
1922 /* Make sure the horizontal scrollbar scrolls ok */
1923 SendMessageW(hListBox
, LB_SETHORIZONTALEXTENT
, widest
* 6, 0);
1925 /* Set the current selection */
1926 SendMessageW(hListBox
, LB_SETCURSEL
, MDI_MOREWINDOWSLIMIT
, 0);
1931 switch (LOWORD(wParam
))
1934 if (HIWORD(wParam
) != LBN_DBLCLK
) break;
1938 /* windows are sorted by menu ID, so we must return the
1939 * window associated to the given id
1941 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
1942 UINT index
= SendMessageW(hListBox
, LB_GETCURSEL
, 0, 0);
1943 LRESULT res
= SendMessageW(hListBox
, LB_GETITEMDATA
, index
, 0);
1944 EndDialog(hDlg
, res
);
1958 * MDI_MoreWindowsDialog
1960 * Prompts the user with a listbox containing the opened
1961 * documents. The user can then choose a windows and click
1962 * on OK to set the current window to the one selected, or
1963 * CANCEL to cancel. The function returns a handle to the
1967 static HWND
MDI_MoreWindowsDialog(HWND hwnd
)
1973 hRes
= FindResourceA(user32_module
, "MDI_MOREWINDOWS", (LPSTR
)RT_DIALOG
);
1978 hDlgTmpl
= LoadResource(user32_module
, hRes
);
1983 template = LockResource( hDlgTmpl
);
1988 return (HWND
) DialogBoxIndirectParamA(user32_module
, template, hwnd
,
1989 MDI_MoreWindowsDlgProc
, (LPARAM
) hwnd
);