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.
86 #include "user_private.h"
89 #include "wine/debug.h"
91 WINE_DEFAULT_DEBUG_CHANNEL(mdi
);
93 #define MDI_MAXTITLELENGTH 0xa1
95 #define WM_MDICALCCHILDSCROLL 0x003f /* this is exactly what Windows uses */
97 /* "More Windows..." definitions */
98 #define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
99 option will appear under the Windows menu */
100 #define MDI_IDC_LISTBOX 100
101 #define IDS_MDI_MOREWINDOWS 13
103 #define MDIF_NEEDUPDATE 0x0001
107 /* At some points, particularly when switching MDI children, active and
108 * maximized MDI children may be not the same window, so we need to track
110 * The only place where we switch to/from maximized state is DefMDIChildProc
111 * WM_SIZE/SIZE_MAXIMIZED handler. We get that notification only after the
112 * ShowWindow(SW_SHOWMAXIMIZED) request, therefore window is guaranteed to
113 * be visible at the time we get the notification, and it's safe to assume
114 * that hwndChildMaximized is always visible.
115 * If the app plays games with WS_VISIBLE, WS_MAXIMIZE or any other window
116 * states it must keep coherency with USER32 on its own. This is true for
119 UINT nActiveChildren
;
120 HWND hwndChildMaximized
;
121 HWND hwndActiveChild
;
122 HWND
*child
; /* array of tracked children */
129 UINT sbRecalc
; /* SB_xxx flags for scrollbar fixup */
132 static HBITMAP hBmpClose
= 0;
134 /* ----------------- declarations ----------------- */
135 static void MDI_UpdateFrameText( HWND
, HWND
, BOOL
, LPCWSTR
);
136 static BOOL
MDI_AugmentFrameMenu( HWND
, HWND
);
137 static BOOL
MDI_RestoreFrameMenu( HWND
, HWND
);
138 static LONG
MDI_ChildActivate( HWND
, HWND
);
139 static LRESULT
MDI_RefreshMenu(MDICLIENTINFO
*);
141 static HWND
MDI_MoreWindowsDialog(HWND
);
143 /* -------- Miscellaneous service functions ----------
147 static HWND
MDI_GetChildByID(HWND hwnd
, UINT id
, MDICLIENTINFO
*ci
)
151 for (i
= 0; ci
->nActiveChildren
; i
++)
153 if (GetWindowLongPtrW( ci
->child
[i
], GWLP_ID
) == id
)
159 static void MDI_PostUpdate(HWND hwnd
, MDICLIENTINFO
* ci
, WORD recalc
)
161 if( !(ci
->mdiFlags
& MDIF_NEEDUPDATE
) )
163 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
164 PostMessageA( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0);
166 ci
->sbRecalc
= recalc
;
170 static MDICLIENTINFO
*get_client_info( HWND client
)
172 return NtUserGetMDIClientInfo( client
);
175 static BOOL
is_close_enabled(HWND hwnd
, HMENU hSysMenu
)
177 if (GetClassLongW(hwnd
, GCL_STYLE
) & CS_NOCLOSE
) return FALSE
;
179 if (!hSysMenu
) hSysMenu
= NtUserGetSystemMenu( hwnd
, FALSE
);
182 UINT state
= GetMenuState(hSysMenu
, SC_CLOSE
, MF_BYCOMMAND
);
183 if (state
== 0xFFFFFFFF || (state
& (MF_DISABLED
| MF_GRAYED
)))
189 /**********************************************************************
192 * returns "activatable" child different from the current or zero
194 static HWND
MDI_GetWindow(MDICLIENTINFO
*clientInfo
, HWND hWnd
, BOOL bNext
,
201 dwStyleMask
|= WS_DISABLED
| WS_VISIBLE
;
202 if( !hWnd
) hWnd
= clientInfo
->hwndActiveChild
;
204 if (!(list
= WIN_ListChildren( GetParent(hWnd
) ))) return 0;
206 /* start from next after hWnd */
207 while (list
[i
] && list
[i
] != hWnd
) i
++;
210 for ( ; list
[i
]; i
++)
212 if (GetWindow( list
[i
], GW_OWNER
)) continue;
213 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
215 if (bNext
) goto found
;
217 /* now restart from the beginning */
218 for (i
= 0; list
[i
] && list
[i
] != hWnd
; i
++)
220 if (GetWindow( list
[i
], GW_OWNER
)) continue;
221 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
223 if (bNext
) goto found
;
226 HeapFree( GetProcessHeap(), 0, list
);
230 /**********************************************************************
231 * MDI_CalcDefaultChildPos
233 * It seems that the default height is about 2/3 of the client rect
235 void MDI_CalcDefaultChildPos( HWND hwndClient
, INT total
, LPPOINT lpPos
, INT delta
, UINT
*id
)
239 INT spacing
= GetSystemMetrics(SM_CYCAPTION
) + GetSystemMetrics(SM_CYFRAME
) - 1;
241 if (total
< 0) /* we are called from CreateWindow */
243 MDICLIENTINFO
*ci
= get_client_info(hwndClient
);
244 total
= ci
->nTotalCreated
;
245 *id
= ci
->idFirstChild
+ ci
->nActiveChildren
;
246 TRACE("MDI child id %04x\n", *id
);
249 GetClientRect( hwndClient
, &rect
);
250 if( rect
.bottom
- rect
.top
- delta
>= spacing
)
251 rect
.bottom
-= delta
;
253 nstagger
= (rect
.bottom
- rect
.top
)/(3 * spacing
);
254 lpPos
[1].x
= (rect
.right
- rect
.left
- nstagger
* spacing
);
255 lpPos
[1].y
= (rect
.bottom
- rect
.top
- nstagger
* spacing
);
256 lpPos
[0].x
= lpPos
[0].y
= spacing
* (total
%(nstagger
+1));
259 /**********************************************************************
262 static LRESULT
MDISetMenu( HWND hwnd
, HMENU hmenuFrame
,
266 HWND hwndFrame
= GetParent(hwnd
);
268 TRACE("%p, frame menu %p, window menu %p\n", hwnd
, hmenuFrame
, hmenuWindow
);
270 if (hmenuFrame
&& !IsMenu(hmenuFrame
))
272 WARN("hmenuFrame is not a menu handle\n");
276 if (hmenuWindow
&& !IsMenu(hmenuWindow
))
278 WARN("hmenuWindow is not a menu handle\n");
282 if (!(ci
= get_client_info( hwnd
))) return 0;
284 TRACE("old frame menu %p, old window menu %p\n", ci
->hFrameMenu
, ci
->hWindowMenu
);
288 if (hmenuFrame
== ci
->hFrameMenu
) return (LRESULT
)hmenuFrame
;
290 if (ci
->hwndChildMaximized
)
291 MDI_RestoreFrameMenu( hwndFrame
, ci
->hwndChildMaximized
);
294 if( hmenuWindow
&& hmenuWindow
!= ci
->hWindowMenu
)
296 /* delete menu items from ci->hWindowMenu
297 * and add them to hmenuWindow */
298 /* Agent newsreader calls this function with ci->hWindowMenu == NULL */
299 if( ci
->hWindowMenu
&& ci
->nActiveChildren
)
301 UINT nActiveChildren_old
= ci
->nActiveChildren
;
303 /* Remove all items from old Window menu */
304 ci
->nActiveChildren
= 0;
307 ci
->hWindowMenu
= hmenuWindow
;
309 /* Add items to the new Window menu */
310 ci
->nActiveChildren
= nActiveChildren_old
;
314 ci
->hWindowMenu
= hmenuWindow
;
319 NtUserSetMenu(hwndFrame
, hmenuFrame
);
320 if( hmenuFrame
!= ci
->hFrameMenu
)
322 HMENU oldFrameMenu
= ci
->hFrameMenu
;
324 ci
->hFrameMenu
= hmenuFrame
;
325 if (ci
->hwndChildMaximized
)
326 MDI_AugmentFrameMenu( hwndFrame
, ci
->hwndChildMaximized
);
328 return (LRESULT
)oldFrameMenu
;
335 /**********************************************************************
338 static LRESULT
MDI_RefreshMenu(MDICLIENTINFO
*ci
)
340 UINT i
, count
, visible
, id
;
341 WCHAR buf
[MDI_MAXTITLELENGTH
];
343 TRACE("children %u, window menu %p\n", ci
->nActiveChildren
, ci
->hWindowMenu
);
345 if (!ci
->hWindowMenu
)
348 if (!IsMenu(ci
->hWindowMenu
))
350 WARN("Window menu handle %p is no longer valid\n", ci
->hWindowMenu
);
354 /* Windows finds the last separator in the menu, and if after it
355 * there is a menu item with MDI magic ID removes all existing
356 * menu items after it, and then adds visible MDI children.
358 count
= GetMenuItemCount(ci
->hWindowMenu
);
359 for (i
= 0; i
< count
; i
++)
363 memset(&mii
, 0, sizeof(mii
));
364 mii
.cbSize
= sizeof(mii
);
365 mii
.fMask
= MIIM_TYPE
;
366 if (GetMenuItemInfoW(ci
->hWindowMenu
, i
, TRUE
, &mii
))
368 if (mii
.fType
& MF_SEPARATOR
)
370 /* Windows checks only ID of the menu item */
371 memset(&mii
, 0, sizeof(mii
));
372 mii
.cbSize
= sizeof(mii
);
374 if (GetMenuItemInfoW(ci
->hWindowMenu
, i
+ 1, TRUE
, &mii
))
376 if (mii
.wID
== ci
->idFirstChild
)
378 TRACE("removing %u items including separator\n", count
- i
);
379 while (NtUserRemoveMenu( ci
->hWindowMenu
, i
, MF_BYPOSITION
))
390 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
392 if (GetWindowLongW(ci
->child
[i
], GWL_STYLE
) & WS_VISIBLE
)
394 id
= ci
->idFirstChild
+ visible
;
396 if (visible
== MDI_MOREWINDOWSLIMIT
)
398 LoadStringW(user32_module
, IDS_MDI_MOREWINDOWS
, buf
, ARRAY_SIZE(buf
));
399 AppendMenuW(ci
->hWindowMenu
, MF_STRING
, id
, buf
);
404 /* Visio expects that separator has id 0 */
405 AppendMenuW(ci
->hWindowMenu
, MF_SEPARATOR
, 0, NULL
);
409 SetWindowLongPtrW(ci
->child
[i
], GWLP_ID
, id
);
412 buf
[1] = '0' + visible
;
414 NtUserInternalGetWindowText(ci
->child
[i
], buf
+ 3, ARRAY_SIZE(buf
) - 3);
415 TRACE("Adding %p, id %u %s\n", ci
->child
[i
], id
, debugstr_w(buf
));
416 AppendMenuW(ci
->hWindowMenu
, MF_STRING
, id
, buf
);
418 if (ci
->child
[i
] == ci
->hwndActiveChild
)
419 NtUserCheckMenuItem(ci
->hWindowMenu
, id
, MF_CHECKED
);
422 TRACE("MDI child %p is not visible, skipping\n", ci
->child
[i
]);
425 return (LRESULT
)ci
->hFrameMenu
;
429 /* ------------------ MDI child window functions ---------------------- */
431 /**********************************************************************
432 * MDI_ChildGetMinMaxInfo
434 * Note: The rule here is that client rect of the maximized MDI child
435 * is equal to the client rect of the MDI client window.
437 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
441 GetClientRect( client
, &rect
);
442 AdjustWindowRectEx( &rect
, GetWindowLongW( hwnd
, GWL_STYLE
),
443 0, GetWindowLongW( hwnd
, GWL_EXSTYLE
));
445 lpMinMax
->ptMaxSize
.x
= rect
.right
-= rect
.left
;
446 lpMinMax
->ptMaxSize
.y
= rect
.bottom
-= rect
.top
;
448 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
449 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
451 TRACE("max rect %s\n", wine_dbgstr_rect(&rect
));
454 /**********************************************************************
455 * MDI_SwitchActiveChild
457 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
460 static void MDI_SwitchActiveChild( MDICLIENTINFO
*ci
, HWND hwndTo
, BOOL activate
)
464 hwndPrev
= ci
->hwndActiveChild
;
466 TRACE("from %p, to %p\n", hwndPrev
, hwndTo
);
468 if ( hwndTo
!= hwndPrev
)
470 BOOL was_zoomed
= IsZoomed(hwndPrev
);
474 /* restore old MDI child */
475 SendMessageW( hwndPrev
, WM_SETREDRAW
, FALSE
, 0 );
476 NtUserShowWindow( hwndPrev
, SW_RESTORE
);
477 SendMessageW( hwndPrev
, WM_SETREDRAW
, TRUE
, 0 );
479 /* activate new MDI child */
480 NtUserSetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
);
481 /* maximize new MDI child */
482 NtUserShowWindow( hwndTo
, SW_MAXIMIZE
);
484 /* activate new MDI child */
485 NtUserSetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0,
486 SWP_NOMOVE
| SWP_NOSIZE
| (activate
? 0 : SWP_NOACTIVATE
) );
491 /**********************************************************************
494 static LRESULT
MDIDestroyChild( HWND client
, MDICLIENTINFO
*ci
,
495 HWND child
, BOOL flagDestroy
)
499 TRACE("# of managed children %u\n", ci
->nActiveChildren
);
501 if( child
== ci
->hwndActiveChild
)
503 HWND next
= MDI_GetWindow(ci
, child
, TRUE
, 0);
504 /* flagDestroy == 0 means we were called from WM_PARENTNOTIFY handler */
505 if (flagDestroy
&& next
)
506 MDI_SwitchActiveChild(ci
, next
, TRUE
);
509 NtUserShowWindow( child
, SW_HIDE
);
510 if (child
== ci
->hwndChildMaximized
)
512 HWND frame
= GetParent(client
);
513 MDI_RestoreFrameMenu(frame
, child
);
514 ci
->hwndChildMaximized
= 0;
515 MDI_UpdateFrameText(frame
, client
, TRUE
, NULL
);
518 MDI_ChildActivate(client
, 0);
522 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
524 if (ci
->child
[i
] == child
)
526 HWND
*new_child
= HeapAlloc(GetProcessHeap(), 0, (ci
->nActiveChildren
- 1) * sizeof(HWND
));
527 memcpy(new_child
, ci
->child
, i
* sizeof(HWND
));
528 if (i
+ 1 < ci
->nActiveChildren
)
529 memcpy(new_child
+ i
, ci
->child
+ i
+ 1, (ci
->nActiveChildren
- i
- 1) * sizeof(HWND
));
530 HeapFree(GetProcessHeap(), 0, ci
->child
);
531 ci
->child
= new_child
;
533 ci
->nActiveChildren
--;
540 SendMessageW(client
, WM_MDIREFRESHMENU
, 0, 0);
541 MDI_PostUpdate(GetParent(child
), ci
, SB_BOTH
+1);
542 NtUserDestroyWindow(child
);
545 TRACE("child destroyed - %p\n", child
);
550 /**********************************************************************
553 * Called in response to WM_CHILDACTIVATE, or when last MDI child
554 * is being deactivated.
556 static LONG
MDI_ChildActivate( HWND client
, HWND child
)
558 MDICLIENTINFO
*clientInfo
;
559 HWND prevActiveWnd
, frame
;
560 BOOL isActiveFrameWnd
;
562 clientInfo
= get_client_info( client
);
564 if (clientInfo
->hwndActiveChild
== child
) return 0;
566 TRACE("%p\n", child
);
568 frame
= GetParent(client
);
569 isActiveFrameWnd
= (GetActiveWindow() == frame
);
570 prevActiveWnd
= clientInfo
->hwndActiveChild
;
572 /* deactivate prev. active child */
575 SendMessageW( prevActiveWnd
, WM_NCACTIVATE
, FALSE
, 0L );
576 SendMessageW( prevActiveWnd
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
579 MDI_SwitchActiveChild( clientInfo
, child
, FALSE
);
580 clientInfo
->hwndActiveChild
= child
;
582 MDI_RefreshMenu(clientInfo
);
584 if( isActiveFrameWnd
)
586 SendMessageW( child
, WM_NCACTIVATE
, TRUE
, 0L);
587 /* Let the client window manage focus for children, but if the focus
588 * is already on the client (for instance this is the 1st child) then
589 * SetFocus won't work. It appears that Windows sends WM_SETFOCUS
590 * manually in this case.
592 if (NtUserSetFocus(client
) == client
)
593 SendMessageW( client
, WM_SETFOCUS
, (WPARAM
)client
, 0 );
596 SendMessageW( child
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
600 /* -------------------- MDI client window functions ------------------- */
602 /**********************************************************************
603 * CreateMDIMenuBitmap
605 static HBITMAP
CreateMDIMenuBitmap(void)
607 HDC hDCSrc
= CreateCompatibleDC(0);
608 HDC hDCDest
= CreateCompatibleDC(hDCSrc
);
609 HBITMAP hbClose
= LoadBitmapW(0, MAKEINTRESOURCEW(OBM_OLD_CLOSE
) );
611 HBITMAP hobjSrc
, hobjDest
;
613 hobjSrc
= SelectObject(hDCSrc
, hbClose
);
614 hbCopy
= CreateCompatibleBitmap(hDCSrc
,GetSystemMetrics(SM_CXSIZE
),GetSystemMetrics(SM_CYSIZE
));
615 hobjDest
= SelectObject(hDCDest
, hbCopy
);
617 BitBlt(hDCDest
, 0, 0, GetSystemMetrics(SM_CXSIZE
), GetSystemMetrics(SM_CYSIZE
),
618 hDCSrc
, GetSystemMetrics(SM_CXSIZE
), 0, SRCCOPY
);
620 SelectObject(hDCSrc
, hobjSrc
);
621 DeleteObject(hbClose
);
624 hobjSrc
= SelectObject( hDCDest
, GetStockObject(BLACK_PEN
) );
626 MoveToEx( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, 0, NULL
);
627 LineTo( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, GetSystemMetrics(SM_CYSIZE
) - 1);
629 SelectObject(hDCDest
, hobjSrc
);
630 SelectObject(hDCDest
, hobjDest
);
636 /**********************************************************************
639 static LONG
MDICascade( HWND client
, MDICLIENTINFO
*ci
)
642 BOOL has_icons
= FALSE
;
645 if (ci
->hwndChildMaximized
)
646 SendMessageW(client
, WM_MDIRESTORE
, (WPARAM
)ci
->hwndChildMaximized
, 0);
648 if (ci
->nActiveChildren
== 0) return 0;
650 if (!(win_array
= WIN_ListChildren( client
))) return 0;
652 /* remove all the windows we don't want */
653 for (i
= total
= 0; win_array
[i
]; i
++)
655 if (!IsWindowVisible( win_array
[i
] )) continue;
656 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows */
657 if (IsIconic( win_array
[i
] ))
662 win_array
[total
++] = win_array
[i
];
664 win_array
[total
] = 0;
668 INT delta
= 0, n
= 0, i
;
670 if (has_icons
) delta
= GetSystemMetrics(SM_CYICONSPACING
) + GetSystemMetrics(SM_CYICON
);
672 /* walk the list (backwards) and move windows */
673 for (i
= total
- 1; i
>= 0; i
--)
676 LONG posOptions
= SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
;
678 MDI_CalcDefaultChildPos(client
, n
++, pos
, delta
, NULL
);
679 TRACE("move %p to (%ld,%ld) size [%ld,%ld]\n",
680 win_array
[i
], pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
);
681 style
= GetWindowLongW(win_array
[i
], GWL_STYLE
);
683 if (!(style
& WS_SIZEBOX
)) posOptions
|= SWP_NOSIZE
;
684 NtUserSetWindowPos( win_array
[i
], 0, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
, posOptions
);
687 HeapFree( GetProcessHeap(), 0, win_array
);
689 if (has_icons
) ArrangeIconicWindows( client
);
693 /**********************************************************************
696 static void MDITile( HWND client
, MDICLIENTINFO
*ci
, WPARAM wParam
)
700 BOOL has_icons
= FALSE
;
702 if (ci
->hwndChildMaximized
)
703 SendMessageW(client
, WM_MDIRESTORE
, (WPARAM
)ci
->hwndChildMaximized
, 0);
705 if (ci
->nActiveChildren
== 0) return;
707 if (!(win_array
= WIN_ListChildren( client
))) return;
709 /* remove all the windows we don't want */
710 for (i
= total
= 0; win_array
[i
]; i
++)
712 if (!IsWindowVisible( win_array
[i
] )) continue;
713 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows (icon titles) */
714 if (IsIconic( win_array
[i
] ))
719 if ((wParam
& MDITILE_SKIPDISABLED
) && !IsWindowEnabled( win_array
[i
] )) continue;
720 win_array
[total
++] = win_array
[i
];
722 win_array
[total
] = 0;
724 TRACE("%u windows to tile\n", total
);
728 HWND
*pWnd
= win_array
;
730 int x
, y
, xsize
, ysize
;
731 int rows
, columns
, r
, c
, i
;
733 GetClientRect(client
,&rect
);
734 rows
= (int) sqrt((double)total
);
735 columns
= total
/ rows
;
737 if( wParam
& MDITILE_HORIZONTAL
) /* version >= 3.1 */
740 rows
= columns
; /* exchange r and c */
746 y
= rect
.bottom
- 2 * GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
747 rect
.bottom
= ( y
- GetSystemMetrics(SM_CYICON
) < rect
.top
)? rect
.bottom
: y
;
750 ysize
= rect
.bottom
/ rows
;
751 xsize
= rect
.right
/ columns
;
753 for (x
= i
= 0, c
= 1; c
<= columns
&& *pWnd
; c
++)
758 ysize
= rect
.bottom
/ rows
;
762 for (r
= 1; r
<= rows
&& *pWnd
; r
++, i
++)
764 LONG posOptions
= SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
;
765 LONG style
= GetWindowLongW(win_array
[i
], GWL_STYLE
);
766 if (!(style
& WS_SIZEBOX
)) posOptions
|= SWP_NOSIZE
;
768 NtUserSetWindowPos( *pWnd
, 0, x
, y
, xsize
, ysize
, posOptions
);
775 HeapFree( GetProcessHeap(), 0, win_array
);
776 if (has_icons
) ArrangeIconicWindows( client
);
779 /* ----------------------- Frame window ---------------------------- */
782 /**********************************************************************
783 * MDI_AugmentFrameMenu
785 static BOOL
MDI_AugmentFrameMenu( HWND frame
, HWND hChild
)
787 HMENU menu
= GetMenu( frame
);
789 HBITMAP hSysMenuBitmap
= 0;
792 TRACE("frame %p,child %p\n",frame
,hChild
);
794 if (!menu
) return FALSE
;
796 /* create a copy of sysmenu popup and insert it into frame menu bar */
797 if (!(hSysPopup
= NtUserGetSystemMenu( hChild
, FALSE
)))
799 TRACE("child %p doesn't have a system menu\n", hChild
);
803 AppendMenuW(menu
, MF_HELP
| MF_BITMAP
,
804 SC_CLOSE
, is_close_enabled(hChild
, hSysPopup
) ?
805 (LPCWSTR
)HBMMENU_MBAR_CLOSE
: (LPCWSTR
)HBMMENU_MBAR_CLOSE_D
);
806 AppendMenuW(menu
, MF_HELP
| MF_BITMAP
,
807 SC_RESTORE
, (LPCWSTR
)HBMMENU_MBAR_RESTORE
);
808 AppendMenuW(menu
, MF_HELP
| MF_BITMAP
,
809 SC_MINIMIZE
, (LPCWSTR
)HBMMENU_MBAR_MINIMIZE
) ;
811 /* The system menu is replaced by the child icon */
812 hIcon
= (HICON
)SendMessageW(hChild
, WM_GETICON
, ICON_SMALL
, 0);
814 hIcon
= (HICON
)GetClassLongPtrW(hChild
, GCLP_HICONSM
);
816 hIcon
= (HICON
)SendMessageW(hChild
, WM_GETICON
, ICON_BIG
, 0);
818 hIcon
= (HICON
)GetClassLongPtrW(hChild
, GCLP_HICON
);
820 hIcon
= LoadImageW(0, (LPWSTR
)IDI_WINLOGO
, IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
),
821 GetSystemMetrics(SM_CYSMICON
), LR_DEFAULTCOLOR
| LR_SHARED
);
825 HBITMAP hBitmap
, hOldBitmap
;
826 HDC hdc
= NtUserGetDC(hChild
);
831 cx
= GetSystemMetrics(SM_CXSMICON
);
832 cy
= GetSystemMetrics(SM_CYSMICON
);
833 hMemDC
= CreateCompatibleDC(hdc
);
834 hBitmap
= CreateCompatibleBitmap(hdc
, cx
, cy
);
835 hOldBitmap
= SelectObject(hMemDC
, hBitmap
);
836 SetMapMode(hMemDC
, MM_TEXT
);
837 NtUserDrawIconEx(hMemDC
, 0, 0, hIcon
, cx
, cy
, 0, GetSysColorBrush(COLOR_MENU
), DI_NORMAL
);
838 SelectObject (hMemDC
, hOldBitmap
);
840 NtUserReleaseDC( hChild
, hdc
);
841 hSysMenuBitmap
= hBitmap
;
845 if( !InsertMenuA(menu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
846 (UINT_PTR
)hSysPopup
, (LPSTR
)hSysMenuBitmap
))
848 TRACE("not inserted\n");
849 NtUserDestroyMenu( hSysPopup
);
853 NtUserEnableMenuItem(hSysPopup
, SC_SIZE
, MF_BYCOMMAND
| MF_GRAYED
);
854 NtUserEnableMenuItem(hSysPopup
, SC_MOVE
, MF_BYCOMMAND
| MF_GRAYED
);
855 NtUserEnableMenuItem(hSysPopup
, SC_MAXIMIZE
, MF_BYCOMMAND
| MF_GRAYED
);
856 NtUserSetMenuDefaultItem(hSysPopup
, SC_CLOSE
, FALSE
);
864 /**********************************************************************
865 * MDI_RestoreFrameMenu
867 static BOOL
MDI_RestoreFrameMenu( HWND frame
, HWND hChild
)
869 MENUITEMINFOW menuInfo
;
870 HMENU menu
= GetMenu( frame
);
874 TRACE("frame %p, child %p\n", frame
, hChild
);
876 if (!menu
) return FALSE
;
878 /* if there is no system buttons then nothing to do */
879 nItems
= GetMenuItemCount(menu
) - 1;
880 iId
= GetMenuItemID(menu
, nItems
);
881 if ( !(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
885 * Remove the system menu, If that menu is the icon of the window
886 * as it is in win95, we have to delete the bitmap.
888 memset(&menuInfo
, 0, sizeof(menuInfo
));
889 menuInfo
.cbSize
= sizeof(menuInfo
);
890 menuInfo
.fMask
= MIIM_DATA
| MIIM_TYPE
;
892 GetMenuItemInfoW(menu
,
897 NtUserRemoveMenu( menu
, 0, MF_BYPOSITION
);
899 if ( (menuInfo
.fType
& MFT_BITMAP
) &&
900 (LOWORD(menuInfo
.dwTypeData
)!=0) &&
901 (LOWORD(menuInfo
.dwTypeData
)!=HBITMAP_16(hBmpClose
)) )
903 DeleteObject(HBITMAP_32(LOWORD(menuInfo
.dwTypeData
)));
907 NtUserDeleteMenu( menu
, SC_CLOSE
, MF_BYCOMMAND
);
909 NtUserDeleteMenu( menu
, SC_RESTORE
, MF_BYCOMMAND
);
911 NtUserDeleteMenu( menu
, SC_MINIMIZE
, MF_BYCOMMAND
);
919 /**********************************************************************
920 * MDI_UpdateFrameText
922 * used when child window is maximized/restored
924 * Note: lpTitle can be NULL
926 static void MDI_UpdateFrameText( HWND frame
, HWND hClient
, BOOL repaint
, LPCWSTR lpTitle
)
928 WCHAR lpBuffer
[MDI_MAXTITLELENGTH
+1];
929 MDICLIENTINFO
*ci
= get_client_info( hClient
);
931 TRACE("frameText %s\n", debugstr_w(lpTitle
));
935 if (!lpTitle
&& !ci
->frameTitle
) /* first time around, get title from the frame window */
937 GetWindowTextW( frame
, lpBuffer
, ARRAY_SIZE( lpBuffer
));
941 /* store new "default" title if lpTitle is not NULL */
944 HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
945 if ((ci
->frameTitle
= HeapAlloc( GetProcessHeap(), 0, (lstrlenW(lpTitle
)+1)*sizeof(WCHAR
))))
946 lstrcpyW( ci
->frameTitle
, lpTitle
);
951 if (ci
->hwndChildMaximized
)
953 /* combine frame title and child title if possible */
954 int i_frame_text_length
= lstrlenW(ci
->frameTitle
);
956 lstrcpynW( lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
958 if( i_frame_text_length
+ 6 < MDI_MAXTITLELENGTH
)
960 lstrcatW( lpBuffer
, L
" - [" );
961 if (GetWindowTextW( ci
->hwndActiveChild
, lpBuffer
+ i_frame_text_length
+ 4,
962 MDI_MAXTITLELENGTH
- i_frame_text_length
- 5 ))
963 lstrcatW( lpBuffer
, L
"]" );
965 lpBuffer
[i_frame_text_length
] = 0; /* remove bracket */
970 lstrcpynW(lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
+1 );
976 DefWindowProcW( frame
, WM_SETTEXT
, 0, (LPARAM
)lpBuffer
);
979 NtUserSetWindowPos( frame
, 0,0,0,0,0, SWP_FRAMECHANGED
|
980 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
984 /* ----------------------------- Interface ---------------------------- */
987 /**********************************************************************
988 * MDIClientWndProc_common
990 LRESULT
MDIClientWndProc_common( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
994 TRACE("%p %04x (%s) %08Ix %08Ix\n", hwnd
, message
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
996 if (!(ci
= get_client_info( hwnd
)))
998 if (message
== WM_NCCREATE
)
1000 if (!(ci
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ci
) ))) return 0;
1001 NtUserSetMDIClientInfo( hwnd
, ci
);
1003 return unicode
? DefWindowProcW( hwnd
, message
, wParam
, lParam
) :
1004 DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1011 /* Since we are using only cs->lpCreateParams, we can safely
1012 * cast to LPCREATESTRUCTA here */
1013 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
1014 LPCLIENTCREATESTRUCT ccs
= cs
->lpCreateParams
;
1016 ci
->hWindowMenu
= ccs
->hWindowMenu
;
1017 ci
->idFirstChild
= ccs
->idFirstChild
;
1018 ci
->hwndChildMaximized
= 0;
1020 ci
->nActiveChildren
= 0;
1021 ci
->nTotalCreated
= 0;
1022 ci
->frameTitle
= NULL
;
1024 ci
->hFrameMenu
= GetMenu(cs
->hwndParent
);
1026 if (!hBmpClose
) hBmpClose
= CreateMDIMenuBitmap();
1028 TRACE("Client created: hwnd %p, Window menu %p, idFirst = %04x\n",
1029 hwnd
, ci
->hWindowMenu
, ci
->idFirstChild
);
1035 if( ci
->hwndChildMaximized
)
1036 MDI_RestoreFrameMenu(GetParent(hwnd
), ci
->hwndChildMaximized
);
1038 ci
->nActiveChildren
= 0;
1039 MDI_RefreshMenu(ci
);
1041 HeapFree( GetProcessHeap(), 0, ci
->child
);
1042 HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1043 HeapFree( GetProcessHeap(), 0, ci
);
1047 case WM_MDIACTIVATE
:
1049 if( ci
->hwndActiveChild
!= (HWND
)wParam
)
1050 NtUserSetWindowPos( (HWND
)wParam
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1055 return MDICascade(hwnd
, ci
);
1064 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)lParam
;
1065 child
= CreateWindowExW(WS_EX_MDICHILD
, csW
->szClass
,
1066 csW
->szTitle
, csW
->style
,
1067 csW
->x
, csW
->y
, csW
->cx
, csW
->cy
,
1068 hwnd
, 0, csW
->hOwner
,
1069 (LPVOID
)csW
->lParam
);
1073 MDICREATESTRUCTA
*csA
= (MDICREATESTRUCTA
*)lParam
;
1074 child
= CreateWindowExA(WS_EX_MDICHILD
, csA
->szClass
,
1075 csA
->szTitle
, csA
->style
,
1076 csA
->x
, csA
->y
, csA
->cx
, csA
->cy
,
1077 hwnd
, 0, csA
->hOwner
,
1078 (LPVOID
)csA
->lParam
);
1080 return (LRESULT
)child
;
1085 return MDIDestroyChild( hwnd
, ci
, WIN_GetFullHandle( (HWND
)wParam
), TRUE
);
1087 case WM_MDIGETACTIVE
:
1088 if (lParam
) *(BOOL
*)lParam
= IsZoomed(ci
->hwndActiveChild
);
1089 return (LRESULT
)ci
->hwndActiveChild
;
1091 case WM_MDIICONARRANGE
:
1092 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1093 ArrangeIconicWindows( hwnd
);
1094 ci
->sbRecalc
= SB_BOTH
+1;
1095 SendMessageW( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0 );
1098 case WM_MDIMAXIMIZE
:
1099 NtUserShowWindow( (HWND
)wParam
, SW_MAXIMIZE
);
1102 case WM_MDINEXT
: /* lParam != 0 means previous window */
1104 HWND hwnd
= wParam
? WIN_GetFullHandle((HWND
)wParam
) : ci
->hwndActiveChild
;
1105 HWND next
= MDI_GetWindow( ci
, hwnd
, !lParam
, 0 );
1106 MDI_SwitchActiveChild( ci
, next
, TRUE
);
1108 NtUserSetWindowPos( hwnd
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
1113 NtUserShowWindow( (HWND
)wParam
, SW_SHOWNORMAL
);
1117 return MDISetMenu( hwnd
, (HMENU
)wParam
, (HMENU
)lParam
);
1119 case WM_MDIREFRESHMENU
:
1120 return MDI_RefreshMenu( ci
);
1123 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1124 NtUserShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
1125 MDITile( hwnd
, ci
, wParam
);
1126 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1131 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1132 ScrollChildren( hwnd
, message
, wParam
, lParam
);
1133 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1137 if (ci
->hwndActiveChild
&& !IsIconic( ci
->hwndActiveChild
))
1138 NtUserSetFocus( ci
->hwndActiveChild
);
1142 if( ci
->hwndActiveChild
)
1143 SendMessageW(ci
->hwndActiveChild
, message
, wParam
, lParam
);
1146 case WM_PARENTNOTIFY
:
1147 switch (LOWORD(wParam
))
1150 if (GetWindowLongW((HWND
)lParam
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1152 ci
->nTotalCreated
++;
1153 ci
->nActiveChildren
++;
1156 ci
->child
= HeapAlloc(GetProcessHeap(), 0, sizeof(HWND
));
1158 ci
->child
= HeapReAlloc(GetProcessHeap(), 0, ci
->child
, sizeof(HWND
) * ci
->nActiveChildren
);
1160 TRACE("Adding MDI child %p, # of children %d\n",
1161 (HWND
)lParam
, ci
->nActiveChildren
);
1163 ci
->child
[ci
->nActiveChildren
- 1] = (HWND
)lParam
;
1167 case WM_LBUTTONDOWN
:
1171 pt
.x
= (short)LOWORD(lParam
);
1172 pt
.y
= (short)HIWORD(lParam
);
1173 child
= ChildWindowFromPoint(hwnd
, pt
);
1175 TRACE("notification from %p (%li,%li)\n",child
,pt
.x
,pt
.y
);
1177 if (child
&& child
!= hwnd
&& child
!= ci
->hwndActiveChild
)
1178 NtUserSetWindowPos( child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1183 return MDIDestroyChild( hwnd
, ci
, WIN_GetFullHandle( (HWND
)lParam
), FALSE
);
1188 if( ci
->hwndActiveChild
&& IsZoomed(ci
->hwndActiveChild
) )
1192 SetRect(&rect
, 0, 0, LOWORD(lParam
), HIWORD(lParam
));
1193 AdjustWindowRectEx(&rect
, GetWindowLongA(ci
->hwndActiveChild
, GWL_STYLE
),
1194 0, GetWindowLongA(ci
->hwndActiveChild
, GWL_EXSTYLE
) );
1195 NtUserMoveWindow( ci
->hwndActiveChild
, rect
.left
, rect
.top
,
1196 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 1 );
1199 MDI_PostUpdate(hwnd
, ci
, SB_BOTH
+1);
1203 case WM_MDICALCCHILDSCROLL
:
1204 if( (ci
->mdiFlags
& MDIF_NEEDUPDATE
) && ci
->sbRecalc
)
1206 CalcChildScroll(hwnd
, ci
->sbRecalc
-1);
1208 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1212 return unicode
? DefWindowProcW( hwnd
, message
, wParam
, lParam
) :
1213 DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1216 /***********************************************************************
1217 * DefFrameProcA (USER32.@)
1219 LRESULT WINAPI
DefFrameProcA( HWND hwnd
, HWND hwndMDIClient
,
1220 UINT message
, WPARAM wParam
, LPARAM lParam
)
1228 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, NULL
, 0 );
1229 LPWSTR text
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1230 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, text
, len
);
1231 MDI_UpdateFrameText( hwnd
, hwndMDIClient
, FALSE
, text
);
1232 HeapFree( GetProcessHeap(), 0, text
);
1234 return 1; /* success. FIXME: check text length */
1241 return DefFrameProcW( hwnd
, hwndMDIClient
, message
, wParam
, lParam
);
1244 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1248 /***********************************************************************
1249 * DefFrameProcW (USER32.@)
1251 LRESULT WINAPI
DefFrameProcW( HWND hwnd
, HWND hwndMDIClient
,
1252 UINT message
, WPARAM wParam
, LPARAM lParam
)
1254 MDICLIENTINFO
*ci
= get_client_info( hwndMDIClient
);
1256 TRACE("%p %p %04x (%s) %08Ix %08Ix\n", hwnd
, hwndMDIClient
, message
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1264 WORD id
= LOWORD(wParam
);
1265 /* check for possible syscommands for maximized MDI child */
1266 if (id
< ci
->idFirstChild
|| id
>= ci
->idFirstChild
+ ci
->nActiveChildren
)
1268 if( (id
- 0xf000) & 0xf00f ) break;
1269 if( !ci
->hwndChildMaximized
) break;
1273 if (!is_close_enabled(ci
->hwndActiveChild
, 0)) break;
1281 return SendMessageW( ci
->hwndChildMaximized
, WM_SYSCOMMAND
,
1288 if (id
- ci
->idFirstChild
== MDI_MOREWINDOWSLIMIT
)
1289 /* User chose "More Windows..." */
1290 childHwnd
= MDI_MoreWindowsDialog(hwndMDIClient
);
1292 /* User chose one of the windows listed in the "Windows" menu */
1293 childHwnd
= MDI_GetChildByID(hwndMDIClient
, id
, ci
);
1296 SendMessageW( hwndMDIClient
, WM_MDIACTIVATE
, (WPARAM
)childHwnd
, 0 );
1302 SendMessageW(hwndMDIClient
, message
, wParam
, lParam
);
1306 MDI_UpdateFrameText( hwnd
, hwndMDIClient
, FALSE
, (LPWSTR
)lParam
);
1307 return 1; /* success. FIXME: check text length */
1310 NtUserSetFocus( hwndMDIClient
);
1314 NtUserMoveWindow( hwndMDIClient
, 0, 0, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1319 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1321 if (!IsIconic(hwnd
) && ci
->hwndActiveChild
&& !IsZoomed(ci
->hwndActiveChild
))
1323 /* control menu is between the frame system menu and
1324 * the first entry of menu bar */
1325 if ((wParam
== VK_LEFT
&& GetMenu(hwnd
) == next_menu
->hmenuIn
) ||
1326 (wParam
== VK_RIGHT
&& NtUserGetWindowSysSubMenu( hwnd
) == next_menu
->hmenuIn
))
1328 next_menu
->hmenuNext
= NtUserGetWindowSysSubMenu( ci
->hwndActiveChild
);
1329 next_menu
->hwndNext
= ci
->hwndActiveChild
;
1337 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1340 /***********************************************************************
1341 * DefMDIChildProcA (USER32.@)
1343 LRESULT WINAPI
DefMDIChildProcA( HWND hwnd
, UINT message
,
1344 WPARAM wParam
, LPARAM lParam
)
1346 HWND client
= GetParent(hwnd
);
1347 MDICLIENTINFO
*ci
= get_client_info( client
);
1349 TRACE("%p %04x (%s) %08Ix %08Ix\n", hwnd
, message
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1351 hwnd
= WIN_GetFullHandle( hwnd
);
1352 if (!ci
) return DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1357 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1358 if( ci
->hwndChildMaximized
== hwnd
)
1359 MDI_UpdateFrameText( GetParent(client
), client
, TRUE
, NULL
);
1360 return 1; /* success. FIXME: check text length */
1362 case WM_GETMINMAXINFO
:
1366 case WM_CHILDACTIVATE
:
1374 return DefMDIChildProcW( hwnd
, message
, wParam
, lParam
);
1376 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1380 /***********************************************************************
1381 * DefMDIChildProcW (USER32.@)
1383 LRESULT WINAPI
DefMDIChildProcW( HWND hwnd
, UINT message
,
1384 WPARAM wParam
, LPARAM lParam
)
1386 HWND client
= GetParent(hwnd
);
1387 MDICLIENTINFO
*ci
= get_client_info( client
);
1389 TRACE("%p %04x (%s) %08Ix %08Ix\n", hwnd
, message
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1391 hwnd
= WIN_GetFullHandle( hwnd
);
1392 if (!ci
) return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1397 DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1398 if( ci
->hwndChildMaximized
== hwnd
)
1399 MDI_UpdateFrameText( GetParent(client
), client
, TRUE
, NULL
);
1400 return 1; /* success. FIXME: check text length */
1402 case WM_GETMINMAXINFO
:
1403 MDI_ChildGetMinMaxInfo( client
, hwnd
, (MINMAXINFO
*)lParam
);
1407 return MAKELRESULT( 0, MNC_CLOSE
); /* MDI children don't have menu bars */
1410 SendMessageW( client
, WM_MDIDESTROY
, (WPARAM
)hwnd
, 0 );
1414 if (ci
->hwndActiveChild
!= hwnd
)
1415 MDI_ChildActivate( client
, hwnd
);
1418 case WM_CHILDACTIVATE
:
1419 if (IsWindowEnabled( hwnd
))
1420 MDI_ChildActivate( client
, hwnd
);
1424 switch (wParam
& 0xfff0)
1427 if( ci
->hwndChildMaximized
== hwnd
)
1434 if (ci
->hwndChildMaximized
== hwnd
)
1435 return SendMessageW( GetParent(client
), message
, wParam
, lParam
);
1438 SendMessageW( client
, WM_MDINEXT
, (WPARAM
)ci
->hwndActiveChild
, 0);
1441 SendMessageW( client
, WM_MDINEXT
, (WPARAM
)ci
->hwndActiveChild
, 1);
1448 if (ci
->hwndChildMaximized
) ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1449 else MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1453 /* This is the only place where we switch to/from maximized state */
1455 TRACE("current active %p, maximized %p\n", ci
->hwndActiveChild
, ci
->hwndChildMaximized
);
1457 if( ci
->hwndChildMaximized
== hwnd
&& wParam
!= SIZE_MAXIMIZED
)
1461 ci
->hwndChildMaximized
= 0;
1463 frame
= GetParent(client
);
1464 MDI_RestoreFrameMenu( frame
, hwnd
);
1465 MDI_UpdateFrameText( frame
, client
, TRUE
, NULL
);
1468 if( wParam
== SIZE_MAXIMIZED
)
1470 HWND frame
, hMaxChild
= ci
->hwndChildMaximized
;
1472 if( hMaxChild
== hwnd
) break;
1476 SendMessageW( hMaxChild
, WM_SETREDRAW
, FALSE
, 0 );
1478 MDI_RestoreFrameMenu( GetParent(client
), hMaxChild
);
1479 NtUserShowWindow( hMaxChild
, SW_SHOWNOACTIVATE
);
1481 SendMessageW( hMaxChild
, WM_SETREDRAW
, TRUE
, 0 );
1484 TRACE("maximizing child %p\n", hwnd
);
1486 /* keep track of the maximized window. */
1487 ci
->hwndChildMaximized
= hwnd
; /* !!! */
1489 frame
= GetParent(client
);
1490 MDI_AugmentFrameMenu( frame
, hwnd
);
1491 MDI_UpdateFrameText( frame
, client
, TRUE
, NULL
);
1494 if( wParam
== SIZE_MINIMIZED
)
1496 HWND switchTo
= MDI_GetWindow( ci
, hwnd
, TRUE
, WS_MINIMIZE
);
1498 if (!switchTo
) switchTo
= hwnd
;
1499 SendMessageW( switchTo
, WM_CHILDACTIVATE
, 0, 0 );
1502 MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1507 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1508 HWND parent
= GetParent(client
);
1510 if( wParam
== VK_LEFT
) /* switch to frame system menu */
1512 next_menu
->hmenuNext
= NtUserGetWindowSysSubMenu( parent
);
1514 if( wParam
== VK_RIGHT
) /* to frame menu bar */
1516 next_menu
->hmenuNext
= GetMenu(parent
);
1518 next_menu
->hwndNext
= parent
;
1525 SendMessageW( hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, VK_SPACE
);
1531 /* Remove itself from the Window menu */
1532 MDI_RefreshMenu(ci
);
1535 return DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1538 /**********************************************************************
1539 * CreateMDIWindowA (USER32.@) Creates a MDI child
1542 * Success: Handle to created window
1545 HWND WINAPI
CreateMDIWindowA(
1546 LPCSTR lpClassName
, /* [in] Pointer to registered child class name */
1547 LPCSTR lpWindowName
, /* [in] Pointer to window name */
1548 DWORD dwStyle
, /* [in] Window style */
1549 INT X
, /* [in] Horizontal position of window */
1550 INT Y
, /* [in] Vertical position of window */
1551 INT nWidth
, /* [in] Width of window */
1552 INT nHeight
, /* [in] Height of window */
1553 HWND hWndParent
, /* [in] Handle to parent window */
1554 HINSTANCE hInstance
, /* [in] Handle to application instance */
1555 LPARAM lParam
) /* [in] Application-defined value */
1557 TRACE("(%s,%s,%08lx,%d,%d,%d,%d,%p,%p,%08Ix)\n",
1558 debugstr_a(lpClassName
),debugstr_a(lpWindowName
),dwStyle
,X
,Y
,
1559 nWidth
,nHeight
,hWndParent
,hInstance
,lParam
);
1561 return CreateWindowExA(WS_EX_MDICHILD
, lpClassName
, lpWindowName
,
1562 dwStyle
, X
, Y
, nWidth
, nHeight
, hWndParent
,
1563 0, hInstance
, (LPVOID
)lParam
);
1566 /***********************************************************************
1567 * CreateMDIWindowW (USER32.@) Creates a MDI child
1570 * Success: Handle to created window
1573 HWND WINAPI
CreateMDIWindowW(
1574 LPCWSTR lpClassName
, /* [in] Pointer to registered child class name */
1575 LPCWSTR lpWindowName
, /* [in] Pointer to window name */
1576 DWORD dwStyle
, /* [in] Window style */
1577 INT X
, /* [in] Horizontal position of window */
1578 INT Y
, /* [in] Vertical position of window */
1579 INT nWidth
, /* [in] Width of window */
1580 INT nHeight
, /* [in] Height of window */
1581 HWND hWndParent
, /* [in] Handle to parent window */
1582 HINSTANCE hInstance
, /* [in] Handle to application instance */
1583 LPARAM lParam
) /* [in] Application-defined value */
1585 TRACE("(%s,%s,%08lx,%d,%d,%d,%d,%p,%p,%08Ix)\n",
1586 debugstr_w(lpClassName
), debugstr_w(lpWindowName
), dwStyle
, X
, Y
,
1587 nWidth
, nHeight
, hWndParent
, hInstance
, lParam
);
1589 return CreateWindowExW(WS_EX_MDICHILD
, lpClassName
, lpWindowName
,
1590 dwStyle
, X
, Y
, nWidth
, nHeight
, hWndParent
,
1591 0, hInstance
, (LPVOID
)lParam
);
1594 /**********************************************************************
1595 * TranslateMDISysAccel (USER32.@)
1597 BOOL WINAPI
TranslateMDISysAccel( HWND hwndClient
, LPMSG msg
)
1599 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
)
1601 MDICLIENTINFO
*ci
= get_client_info( hwndClient
);
1604 if (!ci
|| !IsWindowEnabled(ci
->hwndActiveChild
)) return FALSE
;
1606 /* translate if the Ctrl key is down and Alt not. */
1608 if( (NtUserGetKeyState(VK_CONTROL
) & 0x8000) && !(NtUserGetKeyState(VK_MENU
) & 0x8000))
1610 switch( msg
->wParam
)
1614 wParam
= ( NtUserGetKeyState(VK_SHIFT
) & 0x8000 ) ? SC_NEXTWINDOW
: SC_PREVWINDOW
;
1618 if (is_close_enabled(ci
->hwndActiveChild
, 0))
1627 TRACE("wParam = %04Ix\n", wParam
);
1628 SendMessageW(ci
->hwndActiveChild
, WM_SYSCOMMAND
, wParam
, msg
->wParam
);
1632 return FALSE
; /* failure */
1635 /***********************************************************************
1636 * CalcChildScroll (USER32.@)
1638 void WINAPI
CalcChildScroll( HWND hwnd
, INT scroll
)
1640 DPI_AWARENESS_CONTEXT context
;
1642 RECT childRect
, clientRect
;
1646 context
= SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hwnd
));
1648 GetClientRect( hwnd
, &clientRect
);
1649 SetRectEmpty( &childRect
);
1651 if ((list
= WIN_ListChildren( hwnd
)))
1654 for (i
= 0; list
[i
]; i
++)
1656 style
= GetWindowLongW( list
[i
], GWL_STYLE
);
1657 if (style
& WS_MAXIMIZE
)
1659 HeapFree( GetProcessHeap(), 0, list
);
1660 NtUserShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
1663 if (style
& WS_VISIBLE
)
1666 NtUserGetChildRect( list
[i
], &rect
);
1667 UnionRect( &childRect
, &rect
, &childRect
);
1670 HeapFree( GetProcessHeap(), 0, list
);
1672 UnionRect( &childRect
, &clientRect
, &childRect
);
1674 /* set common info values */
1675 info
.cbSize
= sizeof(info
);
1676 info
.fMask
= SIF_POS
| SIF_RANGE
;
1678 /* set the specific values and apply but only if window style allows */
1679 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1684 if (style
& (WS_HSCROLL
| WS_VSCROLL
))
1686 info
.nMin
= childRect
.left
;
1687 info
.nMax
= childRect
.right
- clientRect
.right
;
1688 info
.nPos
= clientRect
.left
- childRect
.left
;
1689 NtUserSetScrollInfo(hwnd
, SB_HORZ
, &info
, TRUE
);
1691 if (scroll
== SB_HORZ
) break;
1694 if (style
& (WS_HSCROLL
| WS_VSCROLL
))
1696 info
.nMin
= childRect
.top
;
1697 info
.nMax
= childRect
.bottom
- clientRect
.bottom
;
1698 info
.nPos
= clientRect
.top
- childRect
.top
;
1699 NtUserSetScrollInfo(hwnd
, SB_VERT
, &info
, TRUE
);
1703 SetThreadDpiAwarenessContext( context
);
1707 /***********************************************************************
1708 * ScrollChildren (USER32.@)
1710 void WINAPI
ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
,
1713 DPI_AWARENESS_CONTEXT context
;
1715 INT curPos
, length
, minPos
, maxPos
, shift
;
1718 context
= SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hWnd
));
1719 GetClientRect( hWnd
, &rect
);
1724 GetScrollRange(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
1725 curPos
= GetScrollPos(hWnd
,SB_HORZ
);
1726 length
= (rect
.right
- rect
.left
) / 2;
1727 shift
= GetSystemMetrics(SM_CYHSCROLL
);
1730 GetScrollRange(hWnd
,SB_VERT
,&minPos
,&maxPos
);
1731 curPos
= GetScrollPos(hWnd
,SB_VERT
);
1732 length
= (rect
.bottom
- rect
.top
) / 2;
1733 shift
= GetSystemMetrics(SM_CXVSCROLL
);
1742 newPos
= curPos
- shift
;
1745 newPos
= curPos
+ shift
;
1748 newPos
= curPos
- length
;
1751 newPos
= curPos
+ length
;
1754 case SB_THUMBPOSITION
:
1755 newPos
= LOWORD(lParam
);
1768 CalcChildScroll(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
1772 if( newPos
> maxPos
)
1775 if( newPos
< minPos
)
1778 SetScrollPos(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
1780 if( uMsg
== WM_VSCROLL
)
1781 NtUserScrollWindowEx( hWnd
,0 ,curPos
- newPos
, NULL
, NULL
, 0, NULL
,
1782 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
1784 NtUserScrollWindowEx( hWnd
,curPos
- newPos
, 0, NULL
, NULL
, 0, NULL
,
1785 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
1787 SetThreadDpiAwarenessContext( context
);
1791 /******************************************************************************
1792 * CascadeWindows (USER32.@) Cascades MDI child windows
1795 * Success: Number of cascaded windows.
1799 CascadeWindows (HWND hwndParent
, UINT wFlags
, const RECT
*lpRect
,
1800 UINT cKids
, const HWND
*lpKids
)
1802 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
1807 /***********************************************************************
1808 * CascadeChildWindows (USER32.@)
1810 WORD WINAPI
CascadeChildWindows( HWND parent
, UINT flags
)
1812 return CascadeWindows( parent
, flags
, NULL
, 0, NULL
);
1816 /******************************************************************************
1817 * TileWindows (USER32.@) Tiles MDI child windows
1820 * Success: Number of tiled windows.
1824 TileWindows (HWND hwndParent
, UINT wFlags
, const RECT
*lpRect
,
1825 UINT cKids
, const HWND
*lpKids
)
1827 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
1832 /***********************************************************************
1833 * TileChildWindows (USER32.@)
1835 WORD WINAPI
TileChildWindows( HWND parent
, UINT flags
)
1837 return TileWindows( parent
, flags
, NULL
, 0, NULL
);
1841 /************************************************************************
1842 * "More Windows..." functionality
1845 /* MDI_MoreWindowsDlgProc
1847 * This function will process the messages sent to the "More Windows..."
1849 * Return values: 0 = cancel pressed
1850 * HWND = ok pressed or double-click in the list...
1854 static INT_PTR WINAPI
MDI_MoreWindowsDlgProc (HWND hDlg
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
1863 MDICLIENTINFO
*ci
= get_client_info( (HWND
)lParam
);
1864 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
1866 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
1868 WCHAR buffer
[MDI_MAXTITLELENGTH
];
1870 if (!NtUserInternalGetWindowText(ci
->child
[i
], buffer
, ARRAY_SIZE(buffer
)))
1872 SendMessageW(hListBox
, LB_ADDSTRING
, 0, (LPARAM
)buffer
);
1873 SendMessageW(hListBox
, LB_SETITEMDATA
, i
, (LPARAM
)ci
->child
[i
] );
1874 length
= lstrlenW(buffer
); /* FIXME: should use GetTextExtentPoint */
1875 if (length
> widest
)
1878 /* Make sure the horizontal scrollbar scrolls ok */
1879 SendMessageW(hListBox
, LB_SETHORIZONTALEXTENT
, widest
* 6, 0);
1881 /* Set the current selection */
1882 SendMessageW(hListBox
, LB_SETCURSEL
, MDI_MOREWINDOWSLIMIT
, 0);
1887 switch (LOWORD(wParam
))
1890 if (HIWORD(wParam
) != LBN_DBLCLK
) break;
1894 /* windows are sorted by menu ID, so we must return the
1895 * window associated to the given id
1897 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
1898 UINT index
= SendMessageW(hListBox
, LB_GETCURSEL
, 0, 0);
1899 LRESULT res
= SendMessageW(hListBox
, LB_GETITEMDATA
, index
, 0);
1900 EndDialog(hDlg
, res
);
1914 * MDI_MoreWindowsDialog
1916 * Prompts the user with a listbox containing the opened
1917 * documents. The user can then choose a windows and click
1918 * on OK to set the current window to the one selected, or
1919 * CANCEL to cancel. The function returns a handle to the
1923 static HWND
MDI_MoreWindowsDialog(HWND hwnd
)
1929 hRes
= FindResourceA(user32_module
, "MDI_MOREWINDOWS", (LPSTR
)RT_DIALOG
);
1934 hDlgTmpl
= LoadResource(user32_module
, hRes
);
1939 template = LockResource( hDlgTmpl
);
1944 return (HWND
) DialogBoxIndirectParamA(user32_module
, template, hwnd
,
1945 MDI_MoreWindowsDlgProc
, (LPARAM
) hwnd
);