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, accesible via the children list of
32 * the parent window. This WND* has a wIDmenu member, which reflects
33 * the position of the child in the window list. For example, with
34 * 9 child windows, we could have the following pattern:
38 * Name of the child window pWndChild->wIDmenu
50 * The "Windows" menu, as the "More windows..." dialog, are constructed
51 * in this order. If we add a child, we would have the following list:
54 * Name of the child window pWndChild->wIDmenu
66 * But only 5000 to 5008 would be displayed in the "Windows" menu. We want
67 * the last created child to be in the menu, so we swap the last child with
68 * the 9th... Doc9 will be accessible via the "More Windows..." option.
85 #include <wine/debug.h>
87 WINE_DEFAULT_DEBUG_CHANNEL(mdi
);
89 #define MDI_MAXTITLELENGTH 0xa1
91 #define WM_MDICALCCHILDSCROLL 0x10ac /* this is exactly what Windows uses */
93 /* "More Windows..." definitions */
94 #define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
95 option will appear under the Windows menu */
96 #define MDI_IDC_LISTBOX 100
97 #define IDS_MDI_MOREWINDOWS 13
99 #define MDIF_NEEDUPDATE 0x0001
103 /* At some points, particularly when switching MDI children, active and
104 * maximized MDI children may be not the same window, so we need to track
106 * The only place where we switch to/from maximized state is DefMDIChildProc
107 * WM_SIZE/SIZE_MAXIMIZED handler. We get that notification only after the
108 * ShowWindow(SW_SHOWMAXIMIZED) request, therefore window is guaranteed to
109 * be visible at the time we get the notification, and it's safe to assume
110 * that hwndChildMaximized is always visible.
111 * If the app plays games with WS_VISIBLE, WS_MAXIMIZE or any other window
112 * states it must keep coherency with USER32 on its own. This is true for
115 UINT nActiveChildren
;
116 HWND hwndChildMaximized
;
117 HWND hwndActiveChild
;
118 HWND
*child
; /* array of tracked children */
125 UINT sbRecalc
; /* SB_xxx flags for scrollbar fixup */
126 HBITMAP hBmpClose
; /* ReactOS modification */
129 //static HBITMAP hBmpClose = 0;
131 /* ----------------- declarations ----------------- */
132 static void MDI_UpdateFrameText( HWND
, HWND
, BOOL
, LPCWSTR
);
133 static BOOL
MDI_AugmentFrameMenu( HWND
, HWND
);
134 static BOOL
MDI_RestoreFrameMenu( HWND
, HWND
, HBITMAP
);
135 static LONG
MDI_ChildActivate( HWND
, HWND
);
136 static LRESULT
MDI_RefreshMenu(MDICLIENTINFO
*);
138 static HWND
MDI_MoreWindowsDialog(HWND
);
140 HWND
* WIN_ListChildren (HWND hWndparent
)
148 Status
= NtUserBuildHwndList ( NULL
, hWndparent
, FALSE
, 0, 0, NULL
, &dwCount
);
150 if ( !NT_SUCCESS( Status
) )
153 /* allocate buffer to receive HWND handles */
154 hHeap
= GetProcessHeap();
156 pHwnd
= HeapAlloc ( hHeap
, 0, sizeof(HWND
)*(dwCount
+1) );
159 SetLastError ( ERROR_NOT_ENOUGH_MEMORY
);
163 /* now call kernel again to fill the buffer this time */
164 Status
= NtUserBuildHwndList (NULL
, hWndparent
, FALSE
, 0, 0, pHwnd
, &dwCount
);
166 if ( !NT_SUCCESS( Status
) )
169 HeapFree ( hHeap
, 0, pHwnd
);
173 pHwnd
[dwCount
] = (HWND
) 0;
179 void WINAPI
ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
180 void WINAPI
CalcChildScroll(HWND hwnd
, INT scroll
);
183 /* -------- Miscellaneous service functions ----------
187 static HWND
MDI_GetChildByID(HWND hwnd
, UINT id
, MDICLIENTINFO
*ci
)
191 for (i
= 0; ci
->nActiveChildren
; i
++)
193 if (GetWindowLongPtrW( ci
->child
[i
], GWLP_ID
) == id
)
199 static void MDI_PostUpdate(HWND hwnd
, MDICLIENTINFO
* ci
, WORD recalc
)
201 if( !(ci
->mdiFlags
& MDIF_NEEDUPDATE
) )
203 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
204 PostMessageA( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0);
206 ci
->sbRecalc
= recalc
;
210 /*********************************************************************
211 * MDIClient class descriptor
213 const struct builtin_class_descr MDICLIENT_builtin_class
=
215 L
"MDIClient", /* name */
217 MDIClientWndProcA
, /* procA */
218 MDIClientWndProcW
, /* procW */
219 sizeof(MDICLIENTINFO
), /* extra */
220 IDC_ARROW
, /* cursor */
221 (HBRUSH
)(COLOR_APPWORKSPACE
+1) /* brush */
225 static MDICLIENTINFO
*get_client_info( HWND client
)
228 return (MDICLIENTINFO
*)GetWindowLongPtr(client
, 0);
230 MDICLIENTINFO
*ret
= NULL
;
231 WND
*win
= WIN_GetPtr( client
);
234 if (win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
)
236 if (IsWindow(client
)) WARN( "client %p belongs to other process\n", client
);
239 if (win
->flags
& WIN_ISMDICLIENT
)
240 ret
= (MDICLIENTINFO
*)win
->wExtra
;
242 WARN( "%p is not an MDI client\n", client
);
243 WIN_ReleasePtr( win
);
249 static BOOL
is_close_enabled(HWND hwnd
, HMENU hSysMenu
)
251 if (GetClassLongPtrW(hwnd
, GCL_STYLE
) & CS_NOCLOSE
) return FALSE
;
253 if (!hSysMenu
) hSysMenu
= GetSystemMenu(hwnd
, FALSE
);
256 UINT state
= GetMenuState(hSysMenu
, SC_CLOSE
, MF_BYCOMMAND
);
257 if (state
== 0xFFFFFFFF || (state
& (MF_DISABLED
| MF_GRAYED
)))
263 /**********************************************************************
266 * returns "activateable" child different from the current or zero
268 static HWND
MDI_GetWindow(MDICLIENTINFO
*clientInfo
, HWND hWnd
, BOOL bNext
,
275 dwStyleMask
|= WS_DISABLED
| WS_VISIBLE
;
276 if( !hWnd
) hWnd
= clientInfo
->hwndActiveChild
;
278 if (!(list
= WIN_ListChildren( GetParent(hWnd
) ))) return 0;
280 /* start from next after hWnd */
281 while (list
[i
] && list
[i
] != hWnd
) i
++;
284 for ( ; list
[i
]; i
++)
286 if (GetWindow( list
[i
], GW_OWNER
)) continue;
287 if ((GetWindowLongPtrW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
289 if (bNext
) goto found
;
291 /* now restart from the beginning */
292 for (i
= 0; list
[i
] && list
[i
] != hWnd
; i
++)
294 if (GetWindow( list
[i
], GW_OWNER
)) continue;
295 if ((GetWindowLongPtrW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
297 if (bNext
) goto found
;
300 HeapFree( GetProcessHeap(), 0, list
);
304 /**********************************************************************
305 * MDI_CalcDefaultChildPos
307 * It seems that the default height is about 2/3 of the client rect
309 void MDI_CalcDefaultChildPos( HWND hwndClient
, INT total
, LPPOINT lpPos
, INT delta
, UINT
*id
)
313 INT spacing
= GetSystemMetrics(SM_CYCAPTION
) + GetSystemMetrics(SM_CYFRAME
) - 1;
315 if (total
< 0) /* we are called from CreateWindow */
317 MDICLIENTINFO
*ci
= get_client_info(hwndClient
);
318 total
= ci
? ci
->nTotalCreated
: 0; // Do not portsync wine
319 *id
= ci
? ci
->idFirstChild
+ ci
->nActiveChildren
: 0; // Do not portsync wine
320 TRACE("MDI child id %04x\n", *id
);
323 GetClientRect( hwndClient
, &rect
);
324 if( rect
.bottom
- rect
.top
- delta
>= spacing
)
325 rect
.bottom
-= delta
;
327 nstagger
= (rect
.bottom
- rect
.top
)/(3 * spacing
);
328 lpPos
[1].x
= (rect
.right
- rect
.left
- nstagger
* spacing
);
329 lpPos
[1].y
= (rect
.bottom
- rect
.top
- nstagger
* spacing
);
330 lpPos
[0].x
= lpPos
[0].y
= spacing
* (total
%(nstagger
+1));
333 /**********************************************************************
336 static LRESULT
MDISetMenu( HWND hwnd
, HMENU hmenuFrame
,
340 HWND hwndFrame
= GetParent(hwnd
);
342 TRACE("%p %p %p\n", hwnd
, hmenuFrame
, hmenuWindow
);
344 if (hmenuFrame
&& !IsMenu(hmenuFrame
))
346 WARN("hmenuFrame is not a menu handle\n");
350 if (hmenuWindow
&& !IsMenu(hmenuWindow
))
352 WARN("hmenuWindow is not a menu handle\n");
356 if (!(ci
= get_client_info( hwnd
))) return 0;
358 TRACE("old frame menu %p, old window menu %p\n", ci
->hFrameMenu
, ci
->hWindowMenu
);
362 if (hmenuFrame
== ci
->hFrameMenu
) return (LRESULT
)hmenuFrame
;
364 if (ci
->hwndChildMaximized
)
365 MDI_RestoreFrameMenu( hwndFrame
, ci
->hwndChildMaximized
, ci
->hBmpClose
);
368 if( hmenuWindow
&& hmenuWindow
!= ci
->hWindowMenu
)
370 /* delete menu items from ci->hWindowMenu
371 * and add them to hmenuWindow */
372 /* Agent newsreader calls this function with ci->hWindowMenu == NULL */
373 if( ci
->hWindowMenu
&& ci
->nActiveChildren
)
375 UINT nActiveChildren_old
= ci
->nActiveChildren
;
377 /* Remove all items from old Window menu */
378 ci
->nActiveChildren
= 0;
381 ci
->hWindowMenu
= hmenuWindow
;
383 /* Add items to the new Window menu */
384 ci
->nActiveChildren
= nActiveChildren_old
;
388 ci
->hWindowMenu
= hmenuWindow
;
393 SetMenu(hwndFrame
, hmenuFrame
);
394 if( hmenuFrame
!= ci
->hFrameMenu
)
396 HMENU oldFrameMenu
= ci
->hFrameMenu
;
398 ci
->hFrameMenu
= hmenuFrame
;
399 if (ci
->hwndChildMaximized
)
400 MDI_AugmentFrameMenu( hwndFrame
, ci
->hwndChildMaximized
);
402 return (LRESULT
)oldFrameMenu
;
407 /* SetMenu() may already have been called, meaning that this window
408 * already has its menu. But they may have done a SetMenu() on
409 * an MDI window, and called MDISetMenu() after the fact, meaning
410 * that the "if" to this "else" wouldn't catch the need to
411 * augment the frame menu.
413 if( ci
->hwndChildMaximized
)
414 MDI_AugmentFrameMenu( hwndFrame
, ci
->hwndChildMaximized
);
420 /**********************************************************************
423 static LRESULT
MDI_RefreshMenu(MDICLIENTINFO
*ci
)
425 UINT i
, count
, visible
, id
;
426 WCHAR buf
[MDI_MAXTITLELENGTH
];
428 TRACE("children %u, window menu %p\n", ci
->nActiveChildren
, ci
->hWindowMenu
);
430 if (!ci
->hWindowMenu
)
433 if (!IsMenu(ci
->hWindowMenu
))
435 WARN("Window menu handle %p is no more valid\n", ci
->hWindowMenu
);
439 /* Windows finds the last separator in the menu, and if after it
440 * there is a menu item with MDI magic ID removes all existing
441 * menu items after it, and then adds visible MDI children.
443 count
= GetMenuItemCount(ci
->hWindowMenu
);
444 for (i
= 0; i
< count
; i
++)
448 memset(&mii
, 0, sizeof(mii
));
449 mii
.cbSize
= sizeof(mii
);
450 mii
.fMask
= MIIM_TYPE
;
451 if (GetMenuItemInfoW(ci
->hWindowMenu
, i
, TRUE
, &mii
))
453 if (mii
.fType
& MF_SEPARATOR
)
455 /* Windows checks only ID of the menu item */
456 memset(&mii
, 0, sizeof(mii
));
457 mii
.cbSize
= sizeof(mii
);
459 if (GetMenuItemInfoW(ci
->hWindowMenu
, i
+ 1, TRUE
, &mii
))
461 if (mii
.wID
== ci
->idFirstChild
)
463 TRACE("removing %u items including separator\n", count
- i
);
464 while (RemoveMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
))
475 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
477 if (GetWindowLongPtrW(ci
->child
[i
], GWL_STYLE
) & WS_VISIBLE
)
479 id
= ci
->idFirstChild
+ visible
;
481 if (visible
== MDI_MOREWINDOWSLIMIT
)
483 LoadStringW(User32Instance
, IDS_MDI_MOREWINDOWS
, buf
, sizeof(buf
)/sizeof(WCHAR
));
484 AppendMenuW(ci
->hWindowMenu
, MF_STRING
, id
, buf
);
489 /* Visio expects that separator has id 0 */
490 AppendMenuW(ci
->hWindowMenu
, MF_SEPARATOR
, 0, NULL
);
494 SetWindowLongPtrW(ci
->child
[i
], GWLP_ID
, id
);
497 buf
[1] = '0' + visible
;
499 InternalGetWindowText(ci
->child
[i
], buf
+ 3, sizeof(buf
)/sizeof(WCHAR
) - 3);
500 TRACE("Adding %p, id %u %s\n", ci
->child
[i
], id
, debugstr_w(buf
));
501 AppendMenuW(ci
->hWindowMenu
, MF_STRING
, id
, buf
);
503 if (ci
->child
[i
] == ci
->hwndActiveChild
)
504 CheckMenuItem(ci
->hWindowMenu
, id
, MF_CHECKED
);
507 TRACE("MDI child %p is not visible, skipping\n", ci
->child
[i
]);
510 return (LRESULT
)ci
->hFrameMenu
;
514 /* ------------------ MDI child window functions ---------------------- */
516 /**********************************************************************
517 * MDI_ChildGetMinMaxInfo
519 * Note: The rule here is that client rect of the maximized MDI child
520 * is equal to the client rect of the MDI client window.
522 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
526 GetClientRect( client
, &rect
);
527 AdjustWindowRectEx( &rect
, GetWindowLongPtrW( hwnd
, GWL_STYLE
),
528 0, GetWindowLongPtrW( hwnd
, GWL_EXSTYLE
));
530 lpMinMax
->ptMaxSize
.x
= rect
.right
-= rect
.left
;
531 lpMinMax
->ptMaxSize
.y
= rect
.bottom
-= rect
.top
;
533 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
534 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
536 TRACE("max rect (%ld,%ld - %ld, %ld)\n",
537 rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
540 /**********************************************************************
541 * MDI_SwitchActiveChild
543 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
546 static void MDI_SwitchActiveChild( MDICLIENTINFO
*ci
, HWND hwndTo
, BOOL activate
)
550 hwndPrev
= ci
->hwndActiveChild
;
552 TRACE("from %p, to %p\n", hwndPrev
, hwndTo
);
554 if ( hwndTo
!= hwndPrev
)
556 BOOL was_zoomed
= IsZoomed(hwndPrev
);
560 /* restore old MDI child */
561 SendMessageW( hwndPrev
, WM_SETREDRAW
, FALSE
, 0 );
562 ShowWindow( hwndPrev
, SW_RESTORE
);
563 SendMessageW( hwndPrev
, WM_SETREDRAW
, TRUE
, 0 );
565 /* activate new MDI child */
566 SetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
);
567 /* maximize new MDI child */
568 ShowWindow( hwndTo
, SW_MAXIMIZE
);
570 /* activate new MDI child */
571 SetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
| (activate
? 0 : SWP_NOACTIVATE
) );
576 /**********************************************************************
579 static LRESULT
MDIDestroyChild( HWND client
, MDICLIENTINFO
*ci
,
580 HWND child
, BOOL flagDestroy
)
584 TRACE("# of managed children %u\n", ci
->nActiveChildren
);
586 if( child
== ci
->hwndActiveChild
)
588 HWND next
= MDI_GetWindow(ci
, child
, TRUE
, 0);
590 MDI_SwitchActiveChild(ci
, next
, TRUE
);
593 ShowWindow(child
, SW_HIDE
);
594 if (child
== ci
->hwndChildMaximized
)
596 HWND frame
= GetParent(client
);
597 MDI_RestoreFrameMenu(frame
, child
, ci
->hBmpClose
);
598 ci
->hwndChildMaximized
= 0;
599 MDI_UpdateFrameText(frame
, client
, TRUE
, NULL
);
602 MDI_ChildActivate(client
, 0);
606 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
608 if (ci
->child
[i
] == child
)
610 HWND
*new_child
= HeapAlloc(GetProcessHeap(), 0, (ci
->nActiveChildren
- 1) * sizeof(HWND
));
611 if (new_child
!= NULL
)
613 memcpy(new_child
, ci
->child
, i
* sizeof(HWND
));
614 if (i
+ 1 < ci
->nActiveChildren
)
615 memcpy(new_child
+ i
, ci
->child
+ i
+ 1, (ci
->nActiveChildren
- i
- 1) * sizeof(HWND
));
616 HeapFree(GetProcessHeap(), 0, ci
->child
);
617 ci
->child
= new_child
;
622 for (c
= i
; c
< ci
->nActiveChildren
- 1; c
++)
624 ci
->child
[c
] = ci
->child
[c
+1];
628 ci
->nActiveChildren
--;
635 SendMessageW(client
, WM_MDIREFRESHMENU
, 0, 0);
636 MDI_PostUpdate(GetParent(child
), ci
, SB_BOTH
+1);
637 DestroyWindow(child
);
640 TRACE("child destroyed - %p\n", child
);
645 /**********************************************************************
648 * Called in response to WM_CHILDACTIVATE, or when last MDI child
649 * is being deactivated.
651 static LONG
MDI_ChildActivate( HWND client
, HWND child
)
653 MDICLIENTINFO
*clientInfo
;
654 HWND prevActiveWnd
, frame
;
655 BOOL isActiveFrameWnd
;
657 clientInfo
= get_client_info( client
);
659 if (clientInfo
->hwndActiveChild
== child
) return 0;
661 TRACE("%p\n", child
);
663 frame
= GetParent(client
);
664 isActiveFrameWnd
= (GetActiveWindow() == frame
);
665 prevActiveWnd
= clientInfo
->hwndActiveChild
;
667 /* deactivate prev. active child */
670 SendMessageW( prevActiveWnd
, WM_NCACTIVATE
, FALSE
, 0L );
671 SendMessageW( prevActiveWnd
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
674 MDI_SwitchActiveChild( clientInfo
, child
, FALSE
);
675 clientInfo
->hwndActiveChild
= child
;
677 MDI_RefreshMenu(clientInfo
);
679 if( isActiveFrameWnd
)
681 SendMessageW( child
, WM_NCACTIVATE
, TRUE
, 0L);
682 /* Let the client window manage focus for children, but if the focus
683 * is already on the client (for instance this is the 1st child) then
684 * SetFocus won't work. It appears that Windows sends WM_SETFOCUS
685 * manually in this case.
687 if (SetFocus( client
) == client
)
688 SendMessageW( client
, WM_SETFOCUS
, (WPARAM
)client
, 0 );
691 SendMessageW( child
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
695 /* -------------------- MDI client window functions ------------------- */
697 /**********************************************************************
698 * CreateMDIMenuBitmap
700 static HBITMAP
CreateMDIMenuBitmap(void)
702 HDC hDCSrc
= CreateCompatibleDC(0);
703 HDC hDCDest
= CreateCompatibleDC(hDCSrc
);
704 HBITMAP hbClose
= LoadBitmapW(0, MAKEINTRESOURCEW(OBM_OLD_CLOSE
) );
706 HBITMAP hobjSrc
, hobjDest
;
708 hobjSrc
= SelectObject(hDCSrc
, hbClose
);
709 hbCopy
= CreateCompatibleBitmap(hDCSrc
,GetSystemMetrics(SM_CXSIZE
),GetSystemMetrics(SM_CYSIZE
));
710 hobjDest
= SelectObject(hDCDest
, hbCopy
);
712 BitBlt(hDCDest
, 0, 0, GetSystemMetrics(SM_CXSIZE
), GetSystemMetrics(SM_CYSIZE
),
713 hDCSrc
, GetSystemMetrics(SM_CXSIZE
), 0, SRCCOPY
);
715 SelectObject(hDCSrc
, hobjSrc
);
716 DeleteObject(hbClose
);
719 hobjSrc
= SelectObject( hDCDest
, GetStockObject(BLACK_PEN
) );
721 MoveToEx( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, 0, NULL
);
722 LineTo( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, GetSystemMetrics(SM_CYSIZE
) - 1);
724 SelectObject(hDCDest
, hobjSrc
);
725 SelectObject(hDCDest
, hobjDest
);
731 /**********************************************************************
734 static LONG
MDICascade( HWND client
, MDICLIENTINFO
*ci
)
737 BOOL has_icons
= FALSE
;
740 if (ci
->hwndChildMaximized
)
741 SendMessageW(client
, WM_MDIRESTORE
, (WPARAM
)ci
->hwndChildMaximized
, 0);
743 if (ci
->nActiveChildren
== 0) return 0;
745 if (!(win_array
= WIN_ListChildren( client
))) return 0;
747 /* remove all the windows we don't want */
748 for (i
= total
= 0; win_array
[i
]; i
++)
750 if (!IsWindowVisible( win_array
[i
] )) continue;
751 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows */
752 if (IsIconic( win_array
[i
] ))
757 win_array
[total
++] = win_array
[i
];
759 win_array
[total
] = 0;
763 INT delta
= 0, n
= 0, i
;
765 if (has_icons
) delta
= GetSystemMetrics(SM_CYICONSPACING
) + GetSystemMetrics(SM_CYICON
);
767 /* walk the list (backwards) and move windows */
768 for (i
= total
- 1; i
>= 0; i
--)
771 LONG posOptions
= SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
;
773 MDI_CalcDefaultChildPos(client
, n
++, pos
, delta
, NULL
);
774 TRACE("move %p to (%ld,%ld) size [%ld,%ld]\n",
775 win_array
[i
], pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
);
776 style
= GetWindowLongW(win_array
[i
], GWL_STYLE
);
778 if (!(style
& WS_SIZEBOX
)) posOptions
|= SWP_NOSIZE
;
779 SetWindowPos( win_array
[i
], 0, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
,
783 HeapFree( GetProcessHeap(), 0, win_array
);
785 if (has_icons
) ArrangeIconicWindows( client
);
789 /**********************************************************************
792 static void MDITile( HWND client
, MDICLIENTINFO
*ci
, WPARAM wParam
)
796 BOOL has_icons
= FALSE
;
798 if (ci
->hwndChildMaximized
)
799 SendMessageW(client
, WM_MDIRESTORE
, (WPARAM
)ci
->hwndChildMaximized
, 0);
801 if (ci
->nActiveChildren
== 0) return;
803 if (!(win_array
= WIN_ListChildren( client
))) return;
805 /* remove all the windows we don't want */
806 for (i
= total
= 0; win_array
[i
]; i
++)
808 if (!IsWindowVisible( win_array
[i
] )) continue;
809 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows (icon titles) */
810 if (IsIconic( win_array
[i
] ))
815 if ((wParam
& MDITILE_SKIPDISABLED
) && !IsWindowEnabled( win_array
[i
] )) continue;
816 win_array
[total
++] = win_array
[i
];
818 win_array
[total
] = 0;
820 TRACE("%u windows to tile\n", total
);
824 HWND
*pWnd
= win_array
;
826 int x
, y
, xsize
, ysize
;
827 int rows
, columns
, r
, c
, i
;
829 GetClientRect(client
,&rect
);
830 rows
= (int) sqrt((double)total
);
831 columns
= total
/ rows
;
833 if( wParam
& MDITILE_HORIZONTAL
) /* version >= 3.1 */
836 rows
= columns
; /* exchange r and c */
842 y
= rect
.bottom
- 2 * GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
843 rect
.bottom
= ( y
- GetSystemMetrics(SM_CYICON
) < rect
.top
)? rect
.bottom
: y
;
846 ysize
= rect
.bottom
/ rows
;
847 xsize
= rect
.right
/ columns
;
849 for (x
= i
= 0, c
= 1; c
<= columns
&& *pWnd
; c
++)
854 ysize
= rect
.bottom
/ rows
;
858 for (r
= 1; r
<= rows
&& *pWnd
; r
++, i
++)
860 LONG posOptions
= SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
;
861 LONG style
= GetWindowLongW(win_array
[i
], GWL_STYLE
);
862 if (!(style
& WS_SIZEBOX
)) posOptions
|= SWP_NOSIZE
;
864 SetWindowPos(*pWnd
, 0, x
, y
, xsize
, ysize
, posOptions
);
871 HeapFree( GetProcessHeap(), 0, win_array
);
872 if (has_icons
) ArrangeIconicWindows( client
);
875 /* ----------------------- Frame window ---------------------------- */
878 /**********************************************************************
879 * MDI_AugmentFrameMenu
881 static BOOL
MDI_AugmentFrameMenu( HWND frame
, HWND hChild
)
883 HMENU menu
= GetMenu( frame
);
885 HBITMAP hSysMenuBitmap
= 0;
890 TRACE("frame %p,child %p\n",frame
,hChild
);
892 if( !menu
) return 0;
894 /* if the system buttons already exist do not add them again */
895 nItems
= GetMenuItemCount(menu
) - 1;
896 iId
= GetMenuItemID(menu
,nItems
) ;
897 if (iId
== SC_RESTORE
|| iId
== SC_CLOSE
)
900 /* create a copy of sysmenu popup and insert it into frame menu bar */
901 if (!(hSysPopup
= GetSystemMenu(hChild
, FALSE
)))
903 TRACE("child %p doesn't have a system menu\n", hChild
);
907 AppendMenuW(menu
, MF_HELP
| MF_BITMAP
,
908 SC_MINIMIZE
, (LPCWSTR
)HBMMENU_MBAR_MINIMIZE
) ;
909 AppendMenuW(menu
, MF_HELP
| MF_BITMAP
,
910 SC_RESTORE
, (LPCWSTR
)HBMMENU_MBAR_RESTORE
);
911 AppendMenuW(menu
, MF_HELP
| MF_BITMAP
,
912 SC_CLOSE
, is_close_enabled(hChild
, hSysPopup
) ?
913 (LPCWSTR
)HBMMENU_MBAR_CLOSE
: (LPCWSTR
)HBMMENU_MBAR_CLOSE_D
);
915 /* The system menu is replaced by the child icon */
916 hIcon
= (HICON
)GetClassLongPtrW(hChild
, GCLP_HICONSM
);
918 hIcon
= (HICON
)GetClassLongPtrW(hChild
, GCLP_HICON
);
920 hIcon
= LoadIconW(NULL
, IDI_APPLICATION
);
925 HBITMAP hBitmap
, hOldBitmap
;
927 HDC hdc
= GetDC(hChild
);
932 cx
= GetSystemMetrics(SM_CXSMICON
);
933 cy
= GetSystemMetrics(SM_CYSMICON
);
934 hMemDC
= CreateCompatibleDC(hdc
);
935 hBitmap
= CreateCompatibleBitmap(hdc
, cx
, cy
);
936 hOldBitmap
= SelectObject(hMemDC
, hBitmap
);
937 SetMapMode(hMemDC
, MM_TEXT
);
938 hBrush
= CreateSolidBrush(GetSysColor(COLOR_MENU
));
939 DrawIconEx(hMemDC
, 0, 0, hIcon
, cx
, cy
, 0, hBrush
, DI_NORMAL
);
940 SelectObject (hMemDC
, hOldBitmap
);
941 DeleteObject(hBrush
);
943 ReleaseDC(hChild
, hdc
);
944 hSysMenuBitmap
= hBitmap
;
948 if( !InsertMenuA(menu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
949 (UINT_PTR
)hSysPopup
, (LPSTR
)hSysMenuBitmap
))
951 TRACE("not inserted\n");
952 DestroyMenu(hSysPopup
);
956 EnableMenuItem(hSysPopup
, SC_SIZE
, MF_BYCOMMAND
| MF_GRAYED
);
957 EnableMenuItem(hSysPopup
, SC_MOVE
, MF_BYCOMMAND
| MF_GRAYED
);
958 EnableMenuItem(hSysPopup
, SC_MAXIMIZE
, MF_BYCOMMAND
| MF_GRAYED
);
959 SetMenuDefaultItem(hSysPopup
, SC_CLOSE
, FALSE
);
967 /**********************************************************************
968 * MDI_RestoreFrameMenu
970 static BOOL
MDI_RestoreFrameMenu( HWND frame
, HWND hChild
, HBITMAP hBmpClose
)
972 MENUITEMINFOW menuInfo
;
973 HMENU menu
= GetMenu( frame
);
977 TRACE("frame %p,child %p\n",frame
, hChild
);
979 if( !menu
) return 0;
981 /* if there is no system buttons then nothing to do */
982 nItems
= GetMenuItemCount(menu
) - 1;
983 iId
= GetMenuItemID(menu
,nItems
) ;
984 if( !(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
988 * Remove the system menu, If that menu is the icon of the window
989 * as it is in win95, we have to delete the bitmap.
991 memset(&menuInfo
, 0, sizeof(menuInfo
));
992 menuInfo
.cbSize
= sizeof(menuInfo
);
993 menuInfo
.fMask
= MIIM_DATA
| MIIM_TYPE
| MIIM_BITMAP
;
995 GetMenuItemInfoW(menu
,
1000 RemoveMenu(menu
,0,MF_BYPOSITION
);
1002 if ( (menuInfo
.fType
& MFT_BITMAP
) &&
1003 (menuInfo
.dwTypeData
!= 0) &&
1004 (menuInfo
.dwTypeData
!= (LPWSTR
)hBmpClose
) )
1006 DeleteObject(menuInfo
.dwTypeData
);
1009 if ( menuInfo
.hbmpItem
!= 0 )
1010 DeleteObject(menuInfo
.hbmpItem
);
1013 DeleteMenu(menu
, SC_CLOSE
, MF_BYCOMMAND
);
1015 DeleteMenu(menu
, SC_RESTORE
, MF_BYCOMMAND
);
1017 DeleteMenu(menu
, SC_MINIMIZE
, MF_BYCOMMAND
);
1025 /**********************************************************************
1026 * MDI_UpdateFrameText
1028 * used when child window is maximized/restored
1030 * Note: lpTitle can be NULL
1032 static void MDI_UpdateFrameText( HWND frame
, HWND hClient
, BOOL repaint
, LPCWSTR lpTitle
)
1034 WCHAR lpBuffer
[MDI_MAXTITLELENGTH
+1];
1035 MDICLIENTINFO
*ci
= get_client_info( hClient
);
1037 TRACE("frameText %s\n", debugstr_w(lpTitle
));
1041 if (!lpTitle
&& !ci
->frameTitle
) /* first time around, get title from the frame window */
1043 GetWindowTextW( frame
, lpBuffer
, sizeof(lpBuffer
)/sizeof(WCHAR
) );
1047 /* store new "default" title if lpTitle is not NULL */
1050 HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1051 if ((ci
->frameTitle
= HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle
)+1)*sizeof(WCHAR
))))
1052 strcpyW( ci
->frameTitle
, lpTitle
);
1057 if (ci
->hwndChildMaximized
)
1059 /* combine frame title and child title if possible */
1061 static const WCHAR lpBracket
[] = {' ','-',' ','[',0};
1062 static const WCHAR lpBracket2
[] = {']',0};
1063 int i_frame_text_length
= strlenW(ci
->frameTitle
);
1065 lstrcpynW( lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
1067 if( i_frame_text_length
+ 6 < MDI_MAXTITLELENGTH
)
1069 strcatW( lpBuffer
, lpBracket
);
1070 if (GetWindowTextW( ci
->hwndActiveChild
, lpBuffer
+ i_frame_text_length
+ 4,
1071 MDI_MAXTITLELENGTH
- i_frame_text_length
- 5 ))
1072 strcatW( lpBuffer
, lpBracket2
);
1074 lpBuffer
[i_frame_text_length
] = 0; /* remove bracket */
1079 lstrcpynW(lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
+1 );
1085 DefWindowProcW( frame
, WM_SETTEXT
, 0, (LPARAM
)lpBuffer
);
1088 SetWindowPos( frame
, 0,0,0,0,0, SWP_FRAMECHANGED
|
1089 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
1093 /* ----------------------------- Interface ---------------------------- */
1096 /**********************************************************************
1097 * MDIClientWndProc_common
1099 LRESULT WINAPI
MDIClientWndProc_common( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1101 MDICLIENTINFO
*ci
= NULL
;
1103 TRACE("%p %04x (%s) %08lx %08lx\n", hwnd
, message
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1105 if (!(ci
= get_client_info(hwnd
)))
1107 if (message
== WM_NCCREATE
)
1110 if (!(ci
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ci
))))
1112 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)ci
);
1114 NtUserSetWindowFNID( hwnd
, FNID_MDICLIENT
); // wine uses WIN_ISMDICLIENT
1116 WND
*wndPtr
= WIN_GetPtr( hwnd
);
1117 wndPtr
->flags
|= WIN_ISMDICLIENT
;
1118 WIN_ReleasePtr( wndPtr
);
1121 return unicode
? DefWindowProcW( hwnd
, message
, wParam
, lParam
) :
1122 DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1129 /* Since we are using only cs->lpCreateParams, we can safely
1130 * cast to LPCREATESTRUCTA here */
1131 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
1132 LPCLIENTCREATESTRUCT ccs
= (LPCLIENTCREATESTRUCT
)cs
->lpCreateParams
;
1134 ci
->hWindowMenu
= ccs
->hWindowMenu
;
1135 ci
->idFirstChild
= ccs
->idFirstChild
;
1136 ci
->hwndChildMaximized
= 0;
1138 ci
->nActiveChildren
= 0;
1139 ci
->nTotalCreated
= 0;
1140 ci
->frameTitle
= NULL
;
1142 ci
->hFrameMenu
= GetMenu(cs
->hwndParent
);
1144 if (!ci
->hBmpClose
) ci
->hBmpClose
= CreateMDIMenuBitmap();
1146 TRACE("Client created: hwnd %p, Window menu %p, idFirst = %04x\n",
1147 hwnd
, ci
->hWindowMenu
, ci
->idFirstChild
);
1153 if( ci
->hwndChildMaximized
)
1154 MDI_RestoreFrameMenu(GetParent(hwnd
), ci
->hwndChildMaximized
, ci
->hBmpClose
);
1156 ci
->nActiveChildren
= 0;
1157 MDI_RefreshMenu(ci
);
1159 HeapFree( GetProcessHeap(), 0, ci
->child
);
1160 HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1162 HeapFree( GetProcessHeap(), 0, ci
);
1163 SetWindowLongPtrW( hwnd
, 0, 0 );
1171 NtUserSetWindowFNID(hwnd
, FNID_DESTROY
);
1176 case WM_MDIACTIVATE
:
1178 if( ci
->hwndActiveChild
!= (HWND
)wParam
)
1179 SetWindowPos((HWND
)wParam
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1184 return MDICascade(hwnd
, ci
);
1193 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)lParam
;
1194 child
= CreateWindowExW(WS_EX_MDICHILD
, csW
->szClass
,
1195 csW
->szTitle
, csW
->style
,
1196 csW
->x
, csW
->y
, csW
->cx
, csW
->cy
,
1197 hwnd
, 0, csW
->hOwner
,
1198 (LPVOID
)csW
->lParam
);
1202 MDICREATESTRUCTA
*csA
= (MDICREATESTRUCTA
*)lParam
;
1203 child
= CreateWindowExA(WS_EX_MDICHILD
, csA
->szClass
,
1204 csA
->szTitle
, csA
->style
,
1205 csA
->x
, csA
->y
, csA
->cx
, csA
->cy
,
1206 hwnd
, 0, csA
->hOwner
,
1207 (LPVOID
)csA
->lParam
);
1209 return (LRESULT
)child
;
1214 return MDIDestroyChild( hwnd
, ci
, (HWND
)wParam
, TRUE
);
1216 case WM_MDIGETACTIVE
:
1217 if (lParam
) *(BOOL
*)lParam
= IsZoomed(ci
->hwndActiveChild
);
1218 return (LRESULT
)ci
->hwndActiveChild
;
1220 case WM_MDIICONARRANGE
:
1221 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1222 ArrangeIconicWindows( hwnd
);
1223 ci
->sbRecalc
= SB_BOTH
+1;
1224 SendMessageW( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0 );
1227 case WM_MDIMAXIMIZE
:
1228 ShowWindow( (HWND
)wParam
, SW_MAXIMIZE
);
1231 case WM_MDINEXT
: /* lParam != 0 means previous window */
1233 HWND next
= MDI_GetWindow( ci
, (HWND
)wParam
, !lParam
, 0 );
1234 MDI_SwitchActiveChild( ci
, next
, TRUE
);
1239 ShowWindow( (HWND
)wParam
, SW_SHOWNORMAL
);
1243 return MDISetMenu( hwnd
, (HMENU
)wParam
, (HMENU
)lParam
);
1245 case WM_MDIREFRESHMENU
:
1246 return MDI_RefreshMenu( ci
);
1249 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1250 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
1251 MDITile( hwnd
, ci
, wParam
);
1252 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1257 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1258 ScrollChildren( hwnd
, message
, wParam
, lParam
);
1259 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1263 if (ci
->hwndActiveChild
&& !IsIconic( ci
->hwndActiveChild
))
1264 SetFocus( ci
->hwndActiveChild
);
1268 if( ci
->hwndActiveChild
)
1269 SendMessageW(ci
->hwndActiveChild
, message
, wParam
, lParam
);
1272 case WM_PARENTNOTIFY
:
1273 switch (LOWORD(wParam
))
1276 if (GetWindowLongPtrW((HWND
)lParam
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1278 // ReactOS See rev 33503
1280 ci
->child
= HeapAlloc(GetProcessHeap(), 0, sizeof(HWND
));
1282 ci
->child
= HeapReAlloc(GetProcessHeap(), 0, ci
->child
, sizeof(HWND
) * (ci
->nActiveChildren
+ 1));
1284 TRACE("Adding MDI child %p, # of children %d\n",
1285 (HWND
)lParam
, ci
->nActiveChildren
);
1287 if (ci
->child
!= NULL
)
1289 ci
->child
[ci
->nActiveChildren
] = (HWND
)lParam
;
1290 ci
->nTotalCreated
++;
1291 ci
->nActiveChildren
++;
1296 case WM_LBUTTONDOWN
:
1300 pt
.x
= (short)LOWORD(lParam
);
1301 pt
.y
= (short)HIWORD(lParam
);
1302 child
= ChildWindowFromPoint(hwnd
, pt
);
1304 TRACE("notification from %p (%li,%li)\n",child
,pt
.x
,pt
.y
);
1306 if( child
&& child
!= hwnd
&& child
!= ci
->hwndActiveChild
)
1307 SetWindowPos(child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1312 return MDIDestroyChild( hwnd
, ci
, WIN_GetFullHandle( (HWND
)lParam
), FALSE
);
1317 if( ci
->hwndActiveChild
&& IsZoomed(ci
->hwndActiveChild
) )
1323 rect
.right
= LOWORD(lParam
);
1324 rect
.bottom
= HIWORD(lParam
);
1325 AdjustWindowRectEx(&rect
, GetWindowLongPtrA(ci
->hwndActiveChild
, GWL_STYLE
),
1326 0, GetWindowLongPtrA(ci
->hwndActiveChild
, GWL_EXSTYLE
) );
1327 MoveWindow(ci
->hwndActiveChild
, rect
.left
, rect
.top
,
1328 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 1);
1331 MDI_PostUpdate(hwnd
, ci
, SB_BOTH
+1);
1335 case WM_MDICALCCHILDSCROLL
:
1336 if( (ci
->mdiFlags
& MDIF_NEEDUPDATE
) && ci
->sbRecalc
)
1338 CalcChildScroll(hwnd
, ci
->sbRecalc
-1);
1340 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1344 return unicode
? DefWindowProcW( hwnd
, message
, wParam
, lParam
) :
1345 DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1348 /***********************************************************************
1351 LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1353 if (!IsWindow(hwnd
)) return 0;
1354 return MDIClientWndProc_common( hwnd
, message
, wParam
, lParam
, FALSE
);
1357 /***********************************************************************
1360 LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1362 if (!IsWindow(hwnd
)) return 0;
1363 return MDIClientWndProc_common( hwnd
, message
, wParam
, lParam
, TRUE
);
1366 /***********************************************************************
1367 * DefFrameProcA (USER32.@)
1369 LRESULT WINAPI
DefFrameProcA( HWND hwnd
, HWND hwndMDIClient
,
1370 UINT message
, WPARAM wParam
, LPARAM lParam
)
1378 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, NULL
, 0 );
1379 LPWSTR text
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1382 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, text
, len
);
1383 MDI_UpdateFrameText( hwnd
, hwndMDIClient
, FALSE
, text
);
1384 HeapFree( GetProcessHeap(), 0, text
);
1386 return 1; /* success. FIXME: check text length */
1393 return DefFrameProcW( hwnd
, hwndMDIClient
, message
, wParam
, lParam
);
1396 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1400 /***********************************************************************
1401 * DefFrameProcW (USER32.@)
1403 LRESULT WINAPI
DefFrameProcW( HWND hwnd
, HWND hwndMDIClient
,
1404 UINT message
, WPARAM wParam
, LPARAM lParam
)
1406 MDICLIENTINFO
*ci
= get_client_info( hwndMDIClient
);
1408 TRACE("%p %p %04x (%s) %08lx %08lx\n", hwnd
, hwndMDIClient
, message
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1416 WORD id
= LOWORD(wParam
);
1417 /* check for possible syscommands for maximized MDI child */
1418 if (id
< ci
->idFirstChild
|| id
>= ci
->idFirstChild
+ ci
->nActiveChildren
)
1420 if( (id
- 0xf000) & 0xf00f ) break;
1421 if( !ci
->hwndChildMaximized
) break;
1425 if (!is_close_enabled(ci
->hwndActiveChild
, 0)) break;
1433 return SendMessageW( ci
->hwndActiveChild
, WM_SYSCOMMAND
,
1440 if (id
- ci
->idFirstChild
== MDI_MOREWINDOWSLIMIT
)
1441 /* User chose "More Windows..." */
1442 childHwnd
= MDI_MoreWindowsDialog(hwndMDIClient
);
1444 /* User chose one of the windows listed in the "Windows" menu */
1445 childHwnd
= MDI_GetChildByID(hwndMDIClient
, id
, ci
);
1448 SendMessageW( hwndMDIClient
, WM_MDIACTIVATE
, (WPARAM
)childHwnd
, 0 );
1454 SendMessageW(hwndMDIClient
, message
, wParam
, lParam
);
1458 MDI_UpdateFrameText( hwnd
, hwndMDIClient
, FALSE
, (LPWSTR
)lParam
);
1459 return 1; /* success. FIXME: check text length */
1462 SetFocus(hwndMDIClient
);
1466 MoveWindow(hwndMDIClient
, 0, 0, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1471 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1473 if (!IsIconic(hwnd
) && ci
->hwndActiveChild
&& !IsZoomed(ci
->hwndActiveChild
))
1475 /* control menu is between the frame system menu and
1476 * the first entry of menu bar */
1477 // WND *wndPtr = WIN_GetPtr(hwnd);
1479 if( (wParam
== VK_LEFT
&& GetMenu(hwnd
) == next_menu
->hmenuIn
) ||
1480 (wParam
== VK_RIGHT
&& GetSubMenu(GetMenu(hwnd
), 0) == next_menu
->hmenuIn
) )
1482 // WIN_ReleasePtr(wndPtr);
1483 // wndPtr = WIN_GetPtr(ci->hwndActiveChild);
1484 next_menu
->hmenuNext
= GetSubMenu(GetMenu(ci
->hwndActiveChild
), 0);
1485 next_menu
->hwndNext
= ci
->hwndActiveChild
;
1487 // WIN_ReleasePtr(wndPtr);
1494 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1497 /***********************************************************************
1498 * DefMDIChildProcA (USER32.@)
1500 LRESULT WINAPI
DefMDIChildProcA( HWND hwnd
, UINT message
,
1501 WPARAM wParam
, LPARAM lParam
)
1503 HWND client
= GetParent(hwnd
);
1504 MDICLIENTINFO
*ci
= get_client_info( client
);
1506 TRACE("%p %04x (%s) %08lx %08lx\n", hwnd
, message
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1507 hwnd
= WIN_GetFullHandle( hwnd
);
1508 if (!ci
) return DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1513 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1514 if( ci
->hwndChildMaximized
== hwnd
)
1515 MDI_UpdateFrameText( GetParent(client
), client
, TRUE
, NULL
);
1516 return 1; /* success. FIXME: check text length */
1518 case WM_GETMINMAXINFO
:
1522 case WM_CHILDACTIVATE
:
1532 return DefMDIChildProcW( hwnd
, message
, wParam
, lParam
);
1534 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1538 /***********************************************************************
1539 * DefMDIChildProcW (USER32.@)
1541 LRESULT WINAPI
DefMDIChildProcW( HWND hwnd
, UINT message
,
1542 WPARAM wParam
, LPARAM lParam
)
1544 HWND client
= GetParent(hwnd
);
1545 MDICLIENTINFO
*ci
= get_client_info( client
);
1547 TRACE("%p %04x (%s) %08lx %08lx\n", hwnd
, message
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1549 hwnd
= WIN_GetFullHandle( hwnd
);
1550 if (!ci
) return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1555 DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1556 if( ci
->hwndChildMaximized
== hwnd
)
1557 MDI_UpdateFrameText( GetParent(client
), client
, TRUE
, NULL
);
1558 return 1; /* success. FIXME: check text length */
1560 case WM_GETMINMAXINFO
:
1561 MDI_ChildGetMinMaxInfo( client
, hwnd
, (MINMAXINFO
*)lParam
);
1565 return 0x00010000; /* MDI children don't have menu bars */
1568 SendMessageW( client
, WM_MDIDESTROY
, (WPARAM
)hwnd
, 0 );
1572 if (ci
->hwndActiveChild
!= hwnd
)
1573 MDI_ChildActivate( client
, hwnd
);
1576 case WM_CHILDACTIVATE
:
1577 MDI_ChildActivate( client
, hwnd
);
1581 switch( wParam
& 0xfff0)
1584 if( ci
->hwndChildMaximized
== hwnd
)
1591 if (ci
->hwndChildMaximized
== hwnd
)
1592 return SendMessageW( GetParent(client
), message
, wParam
, lParam
);
1595 SendMessageW( client
, WM_MDINEXT
, 0, 0);
1598 SendMessageW( client
, WM_MDINEXT
, 0, 1);
1607 /*if (ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1608 else*/ MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1612 /* This is the only place where we switch to/from maximized state */
1614 TRACE("current active %p, maximized %p\n", ci
->hwndActiveChild
, ci
->hwndChildMaximized
);
1616 if( ci
->hwndChildMaximized
== hwnd
&& wParam
!= SIZE_MAXIMIZED
)
1620 ci
->hwndChildMaximized
= 0;
1622 frame
= GetParent(client
);
1623 MDI_RestoreFrameMenu( frame
, hwnd
, ci
->hBmpClose
);
1624 MDI_UpdateFrameText( frame
, client
, TRUE
, NULL
);
1627 if( wParam
== SIZE_MAXIMIZED
)
1629 HWND frame
, hMaxChild
= ci
->hwndChildMaximized
;
1631 if( hMaxChild
== hwnd
) break;
1635 SendMessageW( hMaxChild
, WM_SETREDRAW
, FALSE
, 0 );
1637 MDI_RestoreFrameMenu( GetParent(client
), hMaxChild
, ci
->hBmpClose
);
1638 ShowWindow( hMaxChild
, SW_SHOWNOACTIVATE
);
1640 SendMessageW( hMaxChild
, WM_SETREDRAW
, TRUE
, 0 );
1643 TRACE("maximizing child %p\n", hwnd
);
1645 /* keep track of the maximized window. */
1646 ci
->hwndChildMaximized
= hwnd
; /* !!! */
1648 frame
= GetParent(client
);
1649 MDI_AugmentFrameMenu( frame
, hwnd
);
1650 MDI_UpdateFrameText( frame
, client
, TRUE
, NULL
);
1653 if( wParam
== SIZE_MINIMIZED
)
1655 HWND switchTo
= MDI_GetWindow( ci
, hwnd
, TRUE
, WS_MINIMIZE
);
1657 if (!switchTo
) switchTo
= hwnd
;
1658 SendMessageW( switchTo
, WM_CHILDACTIVATE
, 0, 0 );
1661 MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1666 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1667 HWND parent
= GetParent(client
);
1669 if( wParam
== VK_LEFT
) /* switch to frame system menu */
1671 // WND *wndPtr = WIN_GetPtr( parent );
1672 next_menu
->hmenuNext
= GetSubMenu( GetMenu(parent
), 0 );
1673 // WIN_ReleasePtr( wndPtr );
1675 if( wParam
== VK_RIGHT
) /* to frame menu bar */
1677 next_menu
->hmenuNext
= GetMenu(parent
);
1679 next_menu
->hwndNext
= parent
;
1686 SendMessageW( hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, VK_SPACE
);
1692 /* Remove itself from the Window menu */
1693 MDI_RefreshMenu(ci
);
1696 return DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1699 /**********************************************************************
1700 * CreateMDIWindowA (USER32.@) Creates a MDI child
1703 * Success: Handle to created window
1706 HWND WINAPI
CreateMDIWindowA(
1707 LPCSTR lpClassName
, /* [in] Pointer to registered child class name */
1708 LPCSTR lpWindowName
, /* [in] Pointer to window name */
1709 DWORD dwStyle
, /* [in] Window style */
1710 INT X
, /* [in] Horizontal position of window */
1711 INT Y
, /* [in] Vertical position of window */
1712 INT nWidth
, /* [in] Width of window */
1713 INT nHeight
, /* [in] Height of window */
1714 HWND hWndParent
, /* [in] Handle to parent window */
1715 HINSTANCE hInstance
, /* [in] Handle to application instance */
1716 LPARAM lParam
) /* [in] Application-defined value */
1718 TRACE("(%s,%s,%08lx,%d,%d,%d,%d,%p,%p,%08lx)\n",
1719 debugstr_a(lpClassName
),debugstr_a(lpWindowName
),dwStyle
,X
,Y
,
1720 nWidth
,nHeight
,hWndParent
,hInstance
,lParam
);
1722 return CreateWindowExA(WS_EX_MDICHILD
, lpClassName
, lpWindowName
,
1723 dwStyle
, X
, Y
, nWidth
, nHeight
, hWndParent
,
1724 0, hInstance
, (LPVOID
)lParam
);
1727 /***********************************************************************
1728 * CreateMDIWindowW (USER32.@) Creates a MDI child
1731 * Success: Handle to created window
1734 HWND WINAPI
CreateMDIWindowW(
1735 LPCWSTR lpClassName
, /* [in] Pointer to registered child class name */
1736 LPCWSTR lpWindowName
, /* [in] Pointer to window name */
1737 DWORD dwStyle
, /* [in] Window style */
1738 INT X
, /* [in] Horizontal position of window */
1739 INT Y
, /* [in] Vertical position of window */
1740 INT nWidth
, /* [in] Width of window */
1741 INT nHeight
, /* [in] Height of window */
1742 HWND hWndParent
, /* [in] Handle to parent window */
1743 HINSTANCE hInstance
, /* [in] Handle to application instance */
1744 LPARAM lParam
) /* [in] Application-defined value */
1746 TRACE("(%s,%s,%08lx,%d,%d,%d,%d,%p,%p,%08lx)\n",
1747 debugstr_w(lpClassName
), debugstr_w(lpWindowName
), dwStyle
, X
, Y
,
1748 nWidth
, nHeight
, hWndParent
, hInstance
, lParam
);
1750 return CreateWindowExW(WS_EX_MDICHILD
, lpClassName
, lpWindowName
,
1751 dwStyle
, X
, Y
, nWidth
, nHeight
, hWndParent
,
1752 0, hInstance
, (LPVOID
)lParam
);
1755 /**********************************************************************
1756 * TranslateMDISysAccel (USER32.@)
1758 BOOL WINAPI
TranslateMDISysAccel( HWND hwndClient
, LPMSG msg
)
1760 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
)
1762 MDICLIENTINFO
*ci
= get_client_info( hwndClient
);
1765 if (!ci
|| !IsWindowEnabled(ci
->hwndActiveChild
)) return 0;
1767 /* translate if the Ctrl key is down and Alt not. */
1769 if( (GetKeyState(VK_CONTROL
) & 0x8000) && !(GetKeyState(VK_MENU
) & 0x8000))
1771 switch( msg
->wParam
)
1775 wParam
= ( GetKeyState(VK_SHIFT
) & 0x8000 ) ? SC_NEXTWINDOW
: SC_PREVWINDOW
;
1779 if (is_close_enabled(ci
->hwndActiveChild
, 0))
1788 TRACE("wParam = %04lx\n", wParam
);
1789 SendMessageW(ci
->hwndActiveChild
, WM_SYSCOMMAND
, wParam
, msg
->wParam
);
1793 return 0; /* failure */
1796 /***********************************************************************
1797 * CalcChildScroll (USER32.@)
1799 void WINAPI
CalcChildScroll( HWND hwnd
, INT scroll
)
1802 RECT childRect
, clientRect
;
1804 WINDOWINFO WindowInfo
;
1806 GetClientRect( hwnd
, &clientRect
);
1807 SetRectEmpty( &childRect
);
1809 /* The rectangle returned by GetClientRect always has 0,0 as top left
1810 * because it is in client coordinates. The rectangles returned by
1811 * GetWindowRect are in screen coordinates to make this complicated.
1813 * Apparently (in ReactOS at least) the rcClient returned by GetWindowInfo
1814 * is in screen coordinates too.
1816 WindowInfo
.cbSize
= sizeof(WindowInfo
);
1817 if (!GetWindowInfo(hwnd
, &WindowInfo
))
1819 ERR("Can't get window info\n");
1823 if ((list
= WIN_ListChildren( hwnd
)))
1826 for (i
= 0; list
[i
]; i
++)
1828 DWORD style
= GetWindowLongPtrW( list
[i
], GWL_STYLE
);
1829 if (style
& WS_MAXIMIZE
)
1831 HeapFree( GetProcessHeap(), 0, list
);
1832 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
1835 if (style
& WS_VISIBLE
)
1838 GetWindowRect( list
[i
], &rect
);
1839 OffsetRect(&rect
, -WindowInfo
.rcClient
.left
,
1840 -WindowInfo
.rcClient
.top
);
1841 UnionRect( &childRect
, &rect
, &childRect
);
1844 HeapFree( GetProcessHeap(), 0, list
);
1846 UnionRect( &childRect
, &clientRect
, &childRect
);
1848 /* set common info values */
1849 info
.cbSize
= sizeof(info
);
1850 info
.fMask
= SIF_POS
| SIF_RANGE
| SIF_PAGE
;
1852 /* set the specific */
1853 /* Note how we set nPos to 0 because we scroll the clients instead of
1854 * the window, and we set nPage to 1 bigger than the clientRect because
1855 * otherwise the scrollbar never disables. This causes a somewhat ugly
1856 * effect though while scrolling.
1862 info
.nMin
= childRect
.left
;
1863 info
.nMax
= childRect
.right
;
1865 info
.nPage
= 1 + clientRect
.right
- clientRect
.left
;
1866 SetScrollInfo(hwnd
, SB_HORZ
, &info
, TRUE
);
1867 if (scroll
== SB_HORZ
) break;
1870 info
.nMin
= childRect
.top
;
1871 info
.nMax
= childRect
.bottom
;
1873 info
.nPage
= 1 + clientRect
.bottom
- clientRect
.top
;
1874 SetScrollInfo(hwnd
, SB_VERT
, &info
, TRUE
);
1880 /***********************************************************************
1881 * ScrollChildren (USER32.@)
1883 void WINAPI
ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
,
1887 INT curPos
, length
, minPos
, maxPos
, shift
;
1890 GetClientRect( hWnd
, &rect
);
1895 GetScrollRange(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
1896 curPos
= GetScrollPos(hWnd
,SB_HORZ
);
1897 length
= (rect
.right
- rect
.left
) / 2;
1898 shift
= GetSystemMetrics(SM_CYHSCROLL
);
1901 GetScrollRange(hWnd
,SB_VERT
,&minPos
,&maxPos
);
1902 curPos
= GetScrollPos(hWnd
,SB_VERT
);
1903 length
= (rect
.bottom
- rect
.top
) / 2;
1904 shift
= GetSystemMetrics(SM_CXVSCROLL
);
1913 newPos
= curPos
- shift
;
1916 newPos
= curPos
+ shift
;
1919 newPos
= curPos
- length
;
1922 newPos
= curPos
+ length
;
1925 case SB_THUMBPOSITION
:
1926 newPos
= LOWORD(lParam
);
1939 CalcChildScroll(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
1943 if( newPos
> maxPos
)
1946 if( newPos
< minPos
)
1949 SetScrollPos(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
1951 if( uMsg
== WM_VSCROLL
)
1952 ScrollWindowEx(hWnd
,0 ,curPos
- newPos
, NULL
, NULL
, 0, NULL
,
1953 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
1955 ScrollWindowEx(hWnd
,curPos
- newPos
, 0, NULL
, NULL
, 0, NULL
,
1956 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
1960 /******************************************************************************
1961 * CascadeWindows (USER32.@) Cascades MDI child windows
1964 * Success: Number of cascaded windows.
1968 CascadeWindows (HWND hwndParent
, UINT wFlags
, LPCRECT lpRect
,
1969 UINT cKids
, const HWND
*lpKids
)
1971 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
1975 /***********************************************************************
1976 * CascadeChildWindows (USER32.@)
1978 WORD WINAPI
CascadeChildWindows( HWND parent
, UINT flags
)
1980 return CascadeWindows( parent
, flags
, NULL
, 0, NULL
);
1984 /******************************************************************************
1985 * TileWindows (USER32.@) Tiles MDI child windows
1988 * Success: Number of tiled windows.
1992 TileWindows (HWND hwndParent
, UINT wFlags
, LPCRECT lpRect
,
1993 UINT cKids
, const HWND
*lpKids
)
1995 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
1999 /***********************************************************************
2000 * TileChildWindows (USER32.@)
2002 WORD WINAPI
TileChildWindows( HWND parent
, UINT flags
)
2004 return TileWindows( parent
, flags
, NULL
, 0, NULL
);
2008 /************************************************************************
2009 * "More Windows..." functionality
2012 /* MDI_MoreWindowsDlgProc
2014 * This function will process the messages sent to the "More Windows..."
2016 * Return values: 0 = cancel pressed
2017 * HWND = ok pressed or double-click in the list...
2021 static INT_PTR WINAPI
MDI_MoreWindowsDlgProc (HWND hDlg
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
2030 MDICLIENTINFO
*ci
= get_client_info( (HWND
)lParam
);
2031 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2033 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
2035 WCHAR buffer
[MDI_MAXTITLELENGTH
];
2037 if (!InternalGetWindowText( ci
->child
[i
], buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
2039 SendMessageW(hListBox
, LB_ADDSTRING
, 0, (LPARAM
)buffer
);
2040 SendMessageW(hListBox
, LB_SETITEMDATA
, i
, (LPARAM
)ci
->child
[i
] );
2041 length
= strlenW(buffer
); /* FIXME: should use GetTextExtentPoint */
2042 if (length
> widest
)
2045 /* Make sure the horizontal scrollbar scrolls ok */
2046 SendMessageW(hListBox
, LB_SETHORIZONTALEXTENT
, widest
* 6, 0);
2048 /* Set the current selection */
2049 SendMessageW(hListBox
, LB_SETCURSEL
, MDI_MOREWINDOWSLIMIT
, 0);
2054 switch (LOWORD(wParam
))
2057 if (HIWORD(wParam
) != LBN_DBLCLK
) break;
2061 /* windows are sorted by menu ID, so we must return the
2062 * window associated to the given id
2064 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2065 UINT index
= SendMessageW(hListBox
, LB_GETCURSEL
, 0, 0);
2066 LRESULT res
= SendMessageW(hListBox
, LB_GETITEMDATA
, index
, 0);
2067 EndDialog(hDlg
, res
);
2081 * MDI_MoreWindowsDialog
2083 * Prompts the user with a listbox containing the opened
2084 * documents. The user can then choose a windows and click
2085 * on OK to set the current window to the one selected, or
2086 * CANCEL to cancel. The function returns a handle to the
2090 static HWND
MDI_MoreWindowsDialog(HWND hwnd
)
2096 hRes
= FindResourceA(User32Instance
, "MDI_MOREWINDOWS", (LPSTR
)RT_DIALOG
);
2101 hDlgTmpl
= LoadResource(User32Instance
, hRes
);
2106 template = LockResource( hDlgTmpl
);
2111 return (HWND
) DialogBoxIndirectParamA(User32Instance
, template, hwnd
,
2112 MDI_MoreWindowsDlgProc
, (LPARAM
) hwnd
);