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.
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
116 UINT nActiveChildren
;
117 HWND hwndChildMaximized
;
118 HWND hwndActiveChild
;
119 HWND
*child
; /* array of tracked children */
126 UINT sbRecalc
; /* SB_xxx flags for scrollbar fixup */
127 HBITMAP hBmpClose
; /* ReactOS modification */
130 //static HBITMAP hBmpClose = 0;
132 /* ----------------- declarations ----------------- */
133 static void MDI_UpdateFrameText( HWND
, HWND
, BOOL
, LPCWSTR
);
134 static BOOL
MDI_AugmentFrameMenu( HWND
, HWND
);
135 static BOOL
MDI_RestoreFrameMenu( HWND
, HWND
, HBITMAP
);
136 static LONG
MDI_ChildActivate( HWND
, HWND
);
137 static LRESULT
MDI_RefreshMenu(MDICLIENTINFO
*);
139 static HWND
MDI_MoreWindowsDialog(HWND
);
141 HWND
* WIN_ListChildren (HWND hWndparent
)
149 Status
= NtUserBuildHwndList ( NULL
, hWndparent
, FALSE
, 0, 0, NULL
, &dwCount
);
151 if ( !NT_SUCCESS( Status
) )
154 /* allocate buffer to receive HWND handles */
155 hHeap
= GetProcessHeap();
157 pHwnd
= HeapAlloc ( hHeap
, 0, sizeof(HWND
)*(dwCount
+1) );
160 SetLastError ( ERROR_NOT_ENOUGH_MEMORY
);
164 /* now call kernel again to fill the buffer this time */
165 Status
= NtUserBuildHwndList (NULL
, hWndparent
, FALSE
, 0, 0, pHwnd
, &dwCount
);
167 if ( !NT_SUCCESS( Status
) )
170 HeapFree ( hHeap
, 0, pHwnd
);
174 pHwnd
[dwCount
] = (HWND
) 0;
180 void WINAPI
ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
181 void WINAPI
CalcChildScroll(HWND hwnd
, INT scroll
);
184 /* -------- Miscellaneous service functions ----------
188 static HWND
MDI_GetChildByID(HWND hwnd
, UINT id
, MDICLIENTINFO
*ci
)
192 for (i
= 0; ci
->nActiveChildren
; i
++)
194 if (GetWindowLongPtrW( ci
->child
[i
], GWLP_ID
) == id
)
200 static void MDI_PostUpdate(HWND hwnd
, MDICLIENTINFO
* ci
, WORD recalc
)
202 if( !(ci
->mdiFlags
& MDIF_NEEDUPDATE
) )
204 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
205 PostMessageA( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0);
207 ci
->sbRecalc
= recalc
;
211 /*********************************************************************
212 * MDIClient class descriptor
214 const struct builtin_class_descr MDICLIENT_builtin_class
=
216 L
"MDIClient", /* name */
218 MDIClientWndProcA
, /* procA */
219 MDIClientWndProcW
, /* procW */
220 sizeof(MDIWND
), /* extra */
221 IDC_ARROW
, /* cursor */
222 (HBRUSH
)(COLOR_APPWORKSPACE
+1) /* brush */
226 static MDICLIENTINFO
*get_client_info( HWND client
)
229 return (MDICLIENTINFO
*)GetWindowLongPtr(client
, GWLP_MDIWND
);
231 MDICLIENTINFO
*ret
= NULL
;
232 WND
*win
= WIN_GetPtr( client
);
235 if (win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
)
237 if (IsWindow(client
)) WARN( "client %p belongs to other process\n", client
);
240 if (win
->flags
& WIN_ISMDICLIENT
)
241 ret
= (MDICLIENTINFO
*)win
->wExtra
;
243 WARN( "%p is not an MDI client\n", client
);
244 WIN_ReleasePtr( win
);
250 static BOOL
is_close_enabled(HWND hwnd
, HMENU hSysMenu
)
252 if (GetClassLongPtrW(hwnd
, GCL_STYLE
) & CS_NOCLOSE
) return FALSE
;
254 if (!hSysMenu
) hSysMenu
= GetSystemMenu(hwnd
, FALSE
);
257 UINT state
= GetMenuState(hSysMenu
, SC_CLOSE
, MF_BYCOMMAND
);
258 if (state
== 0xFFFFFFFF || (state
& (MF_DISABLED
| MF_GRAYED
)))
264 /**********************************************************************
267 * returns "activatable" child different from the current or zero
269 static HWND
MDI_GetWindow(MDICLIENTINFO
*clientInfo
, HWND hWnd
, BOOL bNext
,
276 dwStyleMask
|= WS_DISABLED
| WS_VISIBLE
;
277 if( !hWnd
) hWnd
= clientInfo
->hwndActiveChild
;
279 if (!(list
= WIN_ListChildren( GetParent(hWnd
) ))) return 0;
281 /* start from next after hWnd */
282 while (list
[i
] && list
[i
] != hWnd
) i
++;
285 for ( ; list
[i
]; i
++)
287 if (GetWindow( list
[i
], GW_OWNER
)) continue;
288 if ((GetWindowLongPtrW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
290 if (bNext
) goto found
;
292 /* now restart from the beginning */
293 for (i
= 0; list
[i
] && list
[i
] != hWnd
; i
++)
295 if (GetWindow( list
[i
], GW_OWNER
)) continue;
296 if ((GetWindowLongPtrW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
298 if (bNext
) goto found
;
301 HeapFree( GetProcessHeap(), 0, list
);
305 /**********************************************************************
306 * MDI_CalcDefaultChildPos
308 * It seems that the default height is about 2/3 of the client rect
310 void MDI_CalcDefaultChildPos( HWND hwndClient
, INT total
, LPPOINT lpPos
, INT delta
, UINT
*id
)
314 INT spacing
= GetSystemMetrics(SM_CYCAPTION
) + GetSystemMetrics(SM_CYFRAME
) - 1;
316 if (total
< 0) /* we are called from CreateWindow */
318 MDICLIENTINFO
*ci
= get_client_info(hwndClient
);
319 total
= ci
? ci
->nTotalCreated
: 0; // Do not portsync wine
320 *id
= ci
? ci
->idFirstChild
+ ci
->nActiveChildren
: 0; // Do not portsync wine
321 TRACE("MDI child id %04x\n", *id
);
324 GetClientRect( hwndClient
, &rect
);
325 if( rect
.bottom
- rect
.top
- delta
>= spacing
)
326 rect
.bottom
-= delta
;
328 nstagger
= (rect
.bottom
- rect
.top
)/(3 * spacing
);
329 lpPos
[1].x
= (rect
.right
- rect
.left
- nstagger
* spacing
);
330 lpPos
[1].y
= (rect
.bottom
- rect
.top
- nstagger
* spacing
);
331 lpPos
[0].x
= lpPos
[0].y
= spacing
* (total
%(nstagger
+1));
334 /**********************************************************************
337 static LRESULT
MDISetMenu( HWND hwnd
, HMENU hmenuFrame
,
341 HWND hwndFrame
= GetParent(hwnd
);
343 TRACE("%p, frame menu %p, window menu %p\n", hwnd
, hmenuFrame
, hmenuWindow
);
345 if (hmenuFrame
&& !IsMenu(hmenuFrame
))
347 WARN("hmenuFrame is not a menu handle\n");
351 if (hmenuWindow
&& !IsMenu(hmenuWindow
))
353 WARN("hmenuWindow is not a menu handle\n");
357 if (!(ci
= get_client_info( hwnd
))) return 0;
359 TRACE("old frame menu %p, old window menu %p\n", ci
->hFrameMenu
, ci
->hWindowMenu
);
363 if (hmenuFrame
== ci
->hFrameMenu
) return (LRESULT
)hmenuFrame
;
365 if (ci
->hwndChildMaximized
)
366 MDI_RestoreFrameMenu( hwndFrame
, ci
->hwndChildMaximized
, ci
->hBmpClose
);
369 if( hmenuWindow
&& hmenuWindow
!= ci
->hWindowMenu
)
371 /* delete menu items from ci->hWindowMenu
372 * and add them to hmenuWindow */
373 /* Agent newsreader calls this function with ci->hWindowMenu == NULL */
374 if( ci
->hWindowMenu
&& ci
->nActiveChildren
)
376 UINT nActiveChildren_old
= ci
->nActiveChildren
;
378 /* Remove all items from old Window menu */
379 ci
->nActiveChildren
= 0;
382 ci
->hWindowMenu
= hmenuWindow
;
384 /* Add items to the new Window menu */
385 ci
->nActiveChildren
= nActiveChildren_old
;
389 ci
->hWindowMenu
= hmenuWindow
;
394 SetMenu(hwndFrame
, hmenuFrame
);
395 if( hmenuFrame
!= ci
->hFrameMenu
)
397 HMENU oldFrameMenu
= ci
->hFrameMenu
;
399 ci
->hFrameMenu
= hmenuFrame
;
400 if (ci
->hwndChildMaximized
)
401 MDI_AugmentFrameMenu( hwndFrame
, ci
->hwndChildMaximized
);
403 return (LRESULT
)oldFrameMenu
;
408 /* SetMenu() may already have been called, meaning that this window
409 * already has its menu. But they may have done a SetMenu() on
410 * an MDI window, and called MDISetMenu() after the fact, meaning
411 * that the "if" to this "else" wouldn't catch the need to
412 * augment the frame menu.
414 if( ci
->hwndChildMaximized
)
415 MDI_AugmentFrameMenu( hwndFrame
, ci
->hwndChildMaximized
);
421 /**********************************************************************
424 static LRESULT
MDI_RefreshMenu(MDICLIENTINFO
*ci
)
426 UINT i
, count
, visible
, id
;
427 WCHAR buf
[MDI_MAXTITLELENGTH
];
429 TRACE("children %u, window menu %p\n", ci
->nActiveChildren
, ci
->hWindowMenu
);
431 if (!ci
->hWindowMenu
)
434 if (!IsMenu(ci
->hWindowMenu
))
436 WARN("Window menu handle %p is no more valid\n", ci
->hWindowMenu
);
440 /* Windows finds the last separator in the menu, and if after it
441 * there is a menu item with MDI magic ID removes all existing
442 * menu items after it, and then adds visible MDI children.
444 count
= GetMenuItemCount(ci
->hWindowMenu
);
445 for (i
= 0; i
< count
; i
++)
449 memset(&mii
, 0, sizeof(mii
));
450 mii
.cbSize
= sizeof(mii
);
451 mii
.fMask
= MIIM_TYPE
;
452 if (GetMenuItemInfoW(ci
->hWindowMenu
, i
, TRUE
, &mii
))
454 if (mii
.fType
& MF_SEPARATOR
)
456 /* Windows checks only ID of the menu item */
457 memset(&mii
, 0, sizeof(mii
));
458 mii
.cbSize
= sizeof(mii
);
460 if (GetMenuItemInfoW(ci
->hWindowMenu
, i
+ 1, TRUE
, &mii
))
462 if (mii
.wID
== ci
->idFirstChild
)
464 TRACE("removing %u items including separator\n", count
- i
);
465 while (RemoveMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
))
476 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
478 if (GetWindowLongPtrW(ci
->child
[i
], GWL_STYLE
) & WS_VISIBLE
)
480 id
= ci
->idFirstChild
+ visible
;
482 if (visible
== MDI_MOREWINDOWSLIMIT
)
484 LoadStringW(User32Instance
, IDS_MDI_MOREWINDOWS
, buf
, sizeof(buf
)/sizeof(WCHAR
));
485 AppendMenuW(ci
->hWindowMenu
, MF_STRING
, id
, buf
);
490 /* Visio expects that separator has id 0 */
491 AppendMenuW(ci
->hWindowMenu
, MF_SEPARATOR
, 0, NULL
);
495 SetWindowLongPtrW(ci
->child
[i
], GWLP_ID
, id
);
498 buf
[1] = '0' + visible
;
500 InternalGetWindowText(ci
->child
[i
], buf
+ 3, sizeof(buf
)/sizeof(WCHAR
) - 3);
501 TRACE("Adding %p, id %u %s\n", ci
->child
[i
], id
, debugstr_w(buf
));
502 AppendMenuW(ci
->hWindowMenu
, MF_STRING
, id
, buf
);
504 if (ci
->child
[i
] == ci
->hwndActiveChild
)
505 CheckMenuItem(ci
->hWindowMenu
, id
, MF_CHECKED
);
508 TRACE("MDI child %p is not visible, skipping\n", ci
->child
[i
]);
511 return (LRESULT
)ci
->hFrameMenu
;
515 /* ------------------ MDI child window functions ---------------------- */
517 /**********************************************************************
518 * MDI_ChildGetMinMaxInfo
520 * Note: The rule here is that client rect of the maximized MDI child
521 * is equal to the client rect of the MDI client window.
523 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
527 GetClientRect( client
, &rect
);
528 AdjustWindowRectEx( &rect
, GetWindowLongPtrW( hwnd
, GWL_STYLE
),
529 0, GetWindowLongPtrW( hwnd
, GWL_EXSTYLE
));
531 lpMinMax
->ptMaxSize
.x
= rect
.right
-= rect
.left
;
532 lpMinMax
->ptMaxSize
.y
= rect
.bottom
-= rect
.top
;
534 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
535 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
537 TRACE("max rect (%ld,%ld - %ld, %ld)\n",
538 rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
541 /**********************************************************************
542 * MDI_SwitchActiveChild
544 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
547 static void MDI_SwitchActiveChild( MDICLIENTINFO
*ci
, HWND hwndTo
, BOOL activate
)
551 hwndPrev
= ci
->hwndActiveChild
;
553 TRACE("from %p, to %p\n", hwndPrev
, hwndTo
);
555 if ( hwndTo
!= hwndPrev
)
557 BOOL was_zoomed
= IsZoomed(hwndPrev
);
561 /* restore old MDI child */
562 SendMessageW( hwndPrev
, WM_SETREDRAW
, FALSE
, 0 );
563 ShowWindow( hwndPrev
, SW_RESTORE
);
564 SendMessageW( hwndPrev
, WM_SETREDRAW
, TRUE
, 0 );
566 /* activate new MDI child */
567 SetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
);
568 /* maximize new MDI child */
569 ShowWindow( hwndTo
, SW_MAXIMIZE
);
571 /* activate new MDI child */
572 SetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
| (activate
? 0 : SWP_NOACTIVATE
) );
577 /**********************************************************************
580 static LRESULT
MDIDestroyChild( HWND client
, MDICLIENTINFO
*ci
,
581 HWND child
, BOOL flagDestroy
)
585 TRACE("# of managed children %u\n", ci
->nActiveChildren
);
587 if( child
== ci
->hwndActiveChild
)
589 HWND next
= MDI_GetWindow(ci
, child
, TRUE
, 0);
591 MDI_SwitchActiveChild(ci
, next
, TRUE
);
594 ShowWindow(child
, SW_HIDE
);
595 if (child
== ci
->hwndChildMaximized
)
597 HWND frame
= GetParent(client
);
598 MDI_RestoreFrameMenu(frame
, child
, ci
->hBmpClose
);
599 ci
->hwndChildMaximized
= 0;
600 MDI_UpdateFrameText(frame
, client
, TRUE
, NULL
);
603 MDI_ChildActivate(client
, 0);
607 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
609 if (ci
->child
[i
] == child
)
611 HWND
*new_child
= HeapAlloc(GetProcessHeap(), 0, (ci
->nActiveChildren
- 1) * sizeof(HWND
));
612 if (new_child
!= NULL
)
614 memcpy(new_child
, ci
->child
, i
* sizeof(HWND
));
615 if (i
+ 1 < ci
->nActiveChildren
)
616 memcpy(new_child
+ i
, ci
->child
+ i
+ 1, (ci
->nActiveChildren
- i
- 1) * sizeof(HWND
));
617 HeapFree(GetProcessHeap(), 0, ci
->child
);
618 ci
->child
= new_child
;
623 for (c
= i
; c
< ci
->nActiveChildren
- 1; c
++)
625 ci
->child
[c
] = ci
->child
[c
+1];
629 ci
->nActiveChildren
--;
636 SendMessageW(client
, WM_MDIREFRESHMENU
, 0, 0);
637 MDI_PostUpdate(GetParent(child
), ci
, SB_BOTH
+1);
638 DestroyWindow(child
);
641 TRACE("child destroyed - %p\n", child
);
646 /**********************************************************************
649 * Called in response to WM_CHILDACTIVATE, or when last MDI child
650 * is being deactivated.
652 static LONG
MDI_ChildActivate( HWND client
, HWND child
)
654 MDICLIENTINFO
*clientInfo
;
655 HWND prevActiveWnd
, frame
;
656 BOOL isActiveFrameWnd
;
658 clientInfo
= get_client_info( client
);
660 if (clientInfo
->hwndActiveChild
== child
) return 0;
662 TRACE("%p\n", child
);
664 frame
= GetParent(client
);
665 isActiveFrameWnd
= (GetActiveWindow() == frame
);
666 prevActiveWnd
= clientInfo
->hwndActiveChild
;
668 /* deactivate prev. active child */
671 SendMessageW( prevActiveWnd
, WM_NCACTIVATE
, FALSE
, 0L );
672 SendMessageW( prevActiveWnd
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
675 MDI_SwitchActiveChild( clientInfo
, child
, FALSE
);
676 clientInfo
->hwndActiveChild
= child
;
678 MDI_RefreshMenu(clientInfo
);
680 if( isActiveFrameWnd
)
682 SendMessageW( child
, WM_NCACTIVATE
, TRUE
, 0L);
683 /* Let the client window manage focus for children, but if the focus
684 * is already on the client (for instance this is the 1st child) then
685 * SetFocus won't work. It appears that Windows sends WM_SETFOCUS
686 * manually in this case.
688 if (SetFocus(client
) == client
)
689 SendMessageW( client
, WM_SETFOCUS
, (WPARAM
)client
, 0 );
692 SendMessageW( child
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
696 /* -------------------- MDI client window functions ------------------- */
698 /**********************************************************************
699 * CreateMDIMenuBitmap
701 static HBITMAP
CreateMDIMenuBitmap(void)
703 HDC hDCSrc
= CreateCompatibleDC(0);
704 HDC hDCDest
= CreateCompatibleDC(hDCSrc
);
705 HBITMAP hbClose
= LoadBitmapW(0, MAKEINTRESOURCEW(OBM_OLD_CLOSE
) );
707 HBITMAP hobjSrc
, hobjDest
;
709 hobjSrc
= SelectObject(hDCSrc
, hbClose
);
710 hbCopy
= CreateCompatibleBitmap(hDCSrc
,GetSystemMetrics(SM_CXSIZE
),GetSystemMetrics(SM_CYSIZE
));
711 hobjDest
= SelectObject(hDCDest
, hbCopy
);
713 BitBlt(hDCDest
, 0, 0, GetSystemMetrics(SM_CXSIZE
), GetSystemMetrics(SM_CYSIZE
),
714 hDCSrc
, GetSystemMetrics(SM_CXSIZE
), 0, SRCCOPY
);
716 SelectObject(hDCSrc
, hobjSrc
);
717 DeleteObject(hbClose
);
720 hobjSrc
= SelectObject( hDCDest
, GetStockObject(BLACK_PEN
) );
722 MoveToEx( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, 0, NULL
);
723 LineTo( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, GetSystemMetrics(SM_CYSIZE
) - 1);
725 SelectObject(hDCDest
, hobjSrc
);
726 SelectObject(hDCDest
, hobjDest
);
732 /**********************************************************************
735 static LONG
MDICascade( HWND client
, MDICLIENTINFO
*ci
)
738 BOOL has_icons
= FALSE
;
741 if (ci
->hwndChildMaximized
)
742 SendMessageW(client
, WM_MDIRESTORE
, (WPARAM
)ci
->hwndChildMaximized
, 0);
744 if (ci
->nActiveChildren
== 0) return 0;
746 if (!(win_array
= WIN_ListChildren( client
))) return 0;
748 /* remove all the windows we don't want */
749 for (i
= total
= 0; win_array
[i
]; i
++)
751 if (!IsWindowVisible( win_array
[i
] )) continue;
752 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows */
753 if (IsIconic( win_array
[i
] ))
758 win_array
[total
++] = win_array
[i
];
760 win_array
[total
] = 0;
764 INT delta
= 0, n
= 0, i
;
766 if (has_icons
) delta
= GetSystemMetrics(SM_CYICONSPACING
) + GetSystemMetrics(SM_CYICON
);
768 /* walk the list (backwards) and move windows */
769 for (i
= total
- 1; i
>= 0; i
--)
772 LONG posOptions
= SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
;
774 MDI_CalcDefaultChildPos(client
, n
++, pos
, delta
, NULL
);
775 TRACE("move %p to (%ld,%ld) size [%ld,%ld]\n",
776 win_array
[i
], pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
);
777 style
= GetWindowLongW(win_array
[i
], GWL_STYLE
);
779 if (!(style
& WS_SIZEBOX
)) posOptions
|= SWP_NOSIZE
;
780 SetWindowPos( win_array
[i
], 0, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
,
784 HeapFree( GetProcessHeap(), 0, win_array
);
786 if (has_icons
) ArrangeIconicWindows( client
);
790 /**********************************************************************
793 static void MDITile( HWND client
, MDICLIENTINFO
*ci
, WPARAM wParam
)
796 int i
, total
, rows
, columns
;
797 BOOL has_icons
= FALSE
;
799 if (ci
->hwndChildMaximized
)
800 SendMessageW(client
, WM_MDIRESTORE
, (WPARAM
)ci
->hwndChildMaximized
, 0);
802 if (ci
->nActiveChildren
== 0) return;
804 if (!(win_array
= WIN_ListChildren( client
))) return;
806 /* remove all the windows we don't want */
807 for (i
= total
= rows
= 0; win_array
[i
]; i
++)
809 if (!IsWindowVisible( win_array
[i
] )) continue;
810 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows (icon titles) */
811 if (IsIconic( win_array
[i
] ))
816 if ((wParam
& MDITILE_SKIPDISABLED
) && !IsWindowEnabled( win_array
[i
] )) continue;
817 if(total
== (rows
* (rows
+ 2))) rows
++; /* total+1 == (rows+1)*(rows+1) */
818 win_array
[total
++] = win_array
[i
];
820 win_array
[total
] = 0;
822 TRACE("%u windows to tile\n", total
);
826 HWND
*pWnd
= win_array
;
828 int x
, y
, xsize
, ysize
;
831 GetClientRect(client
,&rect
);
832 columns
= total
/rows
;
833 //while(total < rows*columns) rows++;
835 if( wParam
& MDITILE_HORIZONTAL
) /* version >= 3.1 */
838 rows
= columns
; /* exchange r and c */
844 y
= rect
.bottom
- 2 * GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
845 rect
.bottom
= ( y
- GetSystemMetrics(SM_CYICON
) < rect
.top
)? rect
.bottom
: y
;
848 ysize
= rect
.bottom
/ rows
;
849 xsize
= rect
.right
/ columns
;
851 for (x
= i
= 0, c
= 1; c
<= columns
&& *pWnd
; c
++)
856 ysize
= rect
.bottom
/ rows
;
860 for (r
= 1; r
<= rows
&& *pWnd
; r
++, i
++)
862 LONG posOptions
= SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
;
863 LONG style
= GetWindowLongW(win_array
[i
], GWL_STYLE
);
864 if (!(style
& WS_SIZEBOX
)) posOptions
|= SWP_NOSIZE
;
866 SetWindowPos(*pWnd
, 0, x
, y
, xsize
, ysize
, posOptions
);
873 HeapFree( GetProcessHeap(), 0, win_array
);
874 if (has_icons
) ArrangeIconicWindows( client
);
877 /* ----------------------- Frame window ---------------------------- */
880 /**********************************************************************
881 * MDI_AugmentFrameMenu
883 static BOOL
MDI_AugmentFrameMenu( HWND frame
, HWND hChild
)
885 HMENU menu
= GetMenu( frame
);
887 HBITMAP hSysMenuBitmap
= 0;
892 TRACE("frame %p,child %p\n",frame
,hChild
);
894 if( !menu
) return FALSE
;
896 /* if the system buttons already exist do not add them again */
897 nItems
= GetMenuItemCount(menu
) - 1;
898 iId
= GetMenuItemID(menu
,nItems
) ;
899 if (iId
== SC_RESTORE
|| iId
== SC_CLOSE
)
901 ERR("system buttons already exist\n");
905 /* create a copy of sysmenu popup and insert it into frame menu bar */
906 if (!(hSysPopup
= GetSystemMenu(hChild
, FALSE
)))
908 TRACE("child %p doesn't have a system menu\n", hChild
);
912 AppendMenuW(menu
, MF_HELP
| MF_BITMAP
,
913 SC_CLOSE
, is_close_enabled(hChild
, hSysPopup
) ?
914 (LPCWSTR
)HBMMENU_MBAR_CLOSE
: (LPCWSTR
)HBMMENU_MBAR_CLOSE_D
);
915 AppendMenuW(menu
, MF_HELP
| MF_BITMAP
,
916 SC_RESTORE
, (LPCWSTR
)HBMMENU_MBAR_RESTORE
);
917 AppendMenuW(menu
, MF_HELP
| MF_BITMAP
,
918 SC_MINIMIZE
, (LPCWSTR
)HBMMENU_MBAR_MINIMIZE
) ;
920 /* The system menu is replaced by the child icon */
921 hIcon
= (HICON
)SendMessageW(hChild
, WM_GETICON
, ICON_SMALL
, 0);
923 hIcon
= (HICON
)GetClassLongPtrW(hChild
, GCLP_HICONSM
);
925 hIcon
= (HICON
)SendMessageW(hChild
, WM_GETICON
, ICON_BIG
, 0);
927 hIcon
= (HICON
)GetClassLongPtrW(hChild
, GCLP_HICON
);
929 hIcon
= LoadImageW(0, (LPWSTR
)IDI_WINLOGO
, IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
),
930 GetSystemMetrics(SM_CYSMICON
), LR_DEFAULTCOLOR
);
934 HBITMAP hBitmap
, hOldBitmap
;
936 HDC hdc
= GetDC(hChild
);
941 cx
= GetSystemMetrics(SM_CXSMICON
);
942 cy
= GetSystemMetrics(SM_CYSMICON
);
943 hMemDC
= CreateCompatibleDC(hdc
);
944 hBitmap
= CreateCompatibleBitmap(hdc
, cx
, cy
);
945 hOldBitmap
= SelectObject(hMemDC
, hBitmap
);
946 SetMapMode(hMemDC
, MM_TEXT
);
947 hBrush
= CreateSolidBrush(GetSysColor(COLOR_MENU
));
948 DrawIconEx(hMemDC
, 0, 0, hIcon
, cx
, cy
, 0, hBrush
, DI_NORMAL
);
949 SelectObject (hMemDC
, hOldBitmap
);
950 DeleteObject(hBrush
);
952 ReleaseDC(hChild
, hdc
);
953 hSysMenuBitmap
= hBitmap
;
957 if( !InsertMenuA(menu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
958 (UINT_PTR
)hSysPopup
, (LPSTR
)hSysMenuBitmap
))
960 TRACE("not inserted\n");
961 DestroyMenu(hSysPopup
);
965 EnableMenuItem(hSysPopup
, SC_SIZE
, MF_BYCOMMAND
| MF_GRAYED
);
966 EnableMenuItem(hSysPopup
, SC_MOVE
, MF_BYCOMMAND
| MF_GRAYED
);
967 EnableMenuItem(hSysPopup
, SC_MAXIMIZE
, MF_BYCOMMAND
| MF_GRAYED
);
968 SetMenuDefaultItem(hSysPopup
, SC_CLOSE
, FALSE
);
976 /**********************************************************************
977 * MDI_RestoreFrameMenu
979 static BOOL
MDI_RestoreFrameMenu( HWND frame
, HWND hChild
, HBITMAP hBmpClose
)
981 MENUITEMINFOW menuInfo
;
982 HMENU menu
= GetMenu( frame
);
986 TRACE("frame %p,child %p\n",frame
, hChild
);
988 if (!menu
) return FALSE
;
990 /* if there is no system buttons then nothing to do */
991 nItems
= GetMenuItemCount(menu
) - 1;
992 iId
= GetMenuItemID(menu
, nItems
);
993 if ( !(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
995 ERR("no system buttons then nothing to do\n");
1000 * Remove the system menu, If that menu is the icon of the window
1001 * as it is in win95, we have to delete the bitmap.
1003 memset(&menuInfo
, 0, sizeof(menuInfo
));
1004 menuInfo
.cbSize
= sizeof(menuInfo
);
1005 menuInfo
.fMask
= MIIM_DATA
| MIIM_TYPE
| MIIM_BITMAP
;
1007 GetMenuItemInfoW(menu
,
1012 RemoveMenu(menu
,0,MF_BYPOSITION
);
1014 if ( (menuInfo
.fType
& MFT_BITMAP
) &&
1015 (menuInfo
.dwTypeData
!= 0) &&
1016 (menuInfo
.dwTypeData
!= (LPWSTR
)hBmpClose
) )
1018 DeleteObject(menuInfo
.dwTypeData
);
1021 if ( menuInfo
.hbmpItem
!= 0 )
1022 DeleteObject(menuInfo
.hbmpItem
);
1025 DeleteMenu(menu
, SC_CLOSE
, MF_BYCOMMAND
);
1027 DeleteMenu(menu
, SC_RESTORE
, MF_BYCOMMAND
);
1029 DeleteMenu(menu
, SC_MINIMIZE
, MF_BYCOMMAND
);
1037 /**********************************************************************
1038 * MDI_UpdateFrameText
1040 * used when child window is maximized/restored
1042 * Note: lpTitle can be NULL
1044 static void MDI_UpdateFrameText( HWND frame
, HWND hClient
, BOOL repaint
, LPCWSTR lpTitle
)
1046 WCHAR lpBuffer
[MDI_MAXTITLELENGTH
+1];
1047 MDICLIENTINFO
*ci
= get_client_info( hClient
);
1049 TRACE("frameText %s\n", debugstr_w(lpTitle
));
1053 if (!lpTitle
&& !ci
->frameTitle
) /* first time around, get title from the frame window */
1055 GetWindowTextW( frame
, lpBuffer
, sizeof(lpBuffer
)/sizeof(WCHAR
) );
1059 /* store new "default" title if lpTitle is not NULL */
1062 HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1063 if ((ci
->frameTitle
= HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle
)+1)*sizeof(WCHAR
))))
1064 strcpyW( ci
->frameTitle
, lpTitle
);
1069 if (ci
->hwndChildMaximized
)
1071 /* combine frame title and child title if possible */
1073 static const WCHAR lpBracket
[] = {' ','-',' ','[',0};
1074 static const WCHAR lpBracket2
[] = {']',0};
1075 int i_frame_text_length
= strlenW(ci
->frameTitle
);
1077 lstrcpynW( lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
1079 if( i_frame_text_length
+ 6 < MDI_MAXTITLELENGTH
)
1081 strcatW( lpBuffer
, lpBracket
);
1082 if (GetWindowTextW( ci
->hwndActiveChild
, lpBuffer
+ i_frame_text_length
+ 4,
1083 MDI_MAXTITLELENGTH
- i_frame_text_length
- 5 ))
1084 strcatW( lpBuffer
, lpBracket2
);
1086 lpBuffer
[i_frame_text_length
] = 0; /* remove bracket */
1091 lstrcpynW(lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
+1 );
1097 DefWindowProcW( frame
, WM_SETTEXT
, 0, (LPARAM
)lpBuffer
);
1101 if (!NtUserCallTwoParam((DWORD_PTR
)frame
,DC_ACTIVE
,TWOPARAM_ROUTINE_REDRAWTITLE
))
1102 SetWindowPos( frame
, 0,0,0,0,0, SWP_FRAMECHANGED
|
1103 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
1108 /* ----------------------------- Interface ---------------------------- */
1111 /**********************************************************************
1112 * MDIClientWndProc_common
1114 LRESULT WINAPI
MDIClientWndProc_common( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1116 MDICLIENTINFO
*ci
= NULL
;
1118 TRACE("%p %04x (%s) %08lx %08lx\n", hwnd
, message
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1120 if (!(ci
= get_client_info( hwnd
)))
1122 if (message
== WM_NCCREATE
)
1125 if (!(ci
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ci
))))
1127 SetWindowLongPtrW( hwnd
, GWLP_MDIWND
, (LONG_PTR
)ci
);
1129 NtUserSetWindowFNID( hwnd
, FNID_MDICLIENT
); // wine uses WIN_ISMDICLIENT
1131 WND
*wndPtr
= WIN_GetPtr( hwnd
);
1132 wndPtr
->flags
|= WIN_ISMDICLIENT
;
1133 WIN_ReleasePtr( wndPtr
);
1136 return unicode
? DefWindowProcW( hwnd
, message
, wParam
, lParam
) :
1137 DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1144 /* Since we are using only cs->lpCreateParams, we can safely
1145 * cast to LPCREATESTRUCTA here */
1146 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
1147 LPCLIENTCREATESTRUCT ccs
= (LPCLIENTCREATESTRUCT
)cs
->lpCreateParams
;
1149 ci
->hWindowMenu
= ccs
->hWindowMenu
;
1150 ci
->idFirstChild
= ccs
->idFirstChild
;
1151 ci
->hwndChildMaximized
= 0;
1153 ci
->nActiveChildren
= 0;
1154 ci
->nTotalCreated
= 0;
1155 ci
->frameTitle
= NULL
;
1157 ci
->hFrameMenu
= GetMenu(cs
->hwndParent
);
1159 if (!ci
->hBmpClose
) ci
->hBmpClose
= CreateMDIMenuBitmap();
1161 TRACE("Client created: hwnd %p, Window menu %p, idFirst = %04x\n",
1162 hwnd
, ci
->hWindowMenu
, ci
->idFirstChild
);
1168 if( ci
->hwndChildMaximized
)
1169 MDI_RestoreFrameMenu(GetParent(hwnd
), ci
->hwndChildMaximized
, ci
->hBmpClose
);
1171 ci
->nActiveChildren
= 0;
1172 MDI_RefreshMenu(ci
);
1174 HeapFree( GetProcessHeap(), 0, ci
->child
);
1175 HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1177 HeapFree( GetProcessHeap(), 0, ci
);
1178 SetWindowLongPtrW( hwnd
, GWLP_MDIWND
, 0 );
1186 NtUserSetWindowFNID(hwnd
, FNID_DESTROY
);
1191 case WM_MDIACTIVATE
:
1193 if( ci
->hwndActiveChild
!= (HWND
)wParam
)
1194 SetWindowPos((HWND
)wParam
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1199 return MDICascade(hwnd
, ci
);
1208 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)lParam
;
1209 child
= CreateWindowExW(WS_EX_MDICHILD
, csW
->szClass
,
1210 csW
->szTitle
, csW
->style
,
1211 csW
->x
, csW
->y
, csW
->cx
, csW
->cy
,
1212 hwnd
, 0, csW
->hOwner
,
1213 (LPVOID
)csW
->lParam
);
1217 MDICREATESTRUCTA
*csA
= (MDICREATESTRUCTA
*)lParam
;
1218 child
= CreateWindowExA(WS_EX_MDICHILD
, csA
->szClass
,
1219 csA
->szTitle
, csA
->style
,
1220 csA
->x
, csA
->y
, csA
->cx
, csA
->cy
,
1221 hwnd
, 0, csA
->hOwner
,
1222 (LPVOID
)csA
->lParam
);
1224 return (LRESULT
)child
;
1229 return MDIDestroyChild( hwnd
, ci
, (HWND
)wParam
, TRUE
);
1231 case WM_MDIGETACTIVE
:
1232 if (lParam
) *(BOOL
*)lParam
= IsZoomed(ci
->hwndActiveChild
);
1233 return (LRESULT
)ci
->hwndActiveChild
;
1235 case WM_MDIICONARRANGE
:
1236 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1237 ArrangeIconicWindows( hwnd
);
1238 ci
->sbRecalc
= SB_BOTH
+1;
1239 SendMessageW( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0 );
1242 case WM_MDIMAXIMIZE
:
1243 ShowWindow( (HWND
)wParam
, SW_MAXIMIZE
);
1246 case WM_MDINEXT
: /* lParam != 0 means previous window */
1248 HWND hwnd
= wParam
? WIN_GetFullHandle((HWND
)wParam
) : ci
->hwndActiveChild
;
1249 HWND next
= MDI_GetWindow( ci
, hwnd
, !lParam
, 0 );
1250 MDI_SwitchActiveChild( ci
, next
, TRUE
);
1252 SetWindowPos(hwnd
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
1257 ShowWindow( (HWND
)wParam
, SW_SHOWNORMAL
);
1261 return MDISetMenu( hwnd
, (HMENU
)wParam
, (HMENU
)lParam
);
1263 case WM_MDIREFRESHMENU
:
1264 return MDI_RefreshMenu( ci
);
1267 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1268 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
1269 MDITile( hwnd
, ci
, wParam
);
1270 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1275 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1276 ScrollChildren( hwnd
, message
, wParam
, lParam
);
1277 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1281 if (ci
->hwndActiveChild
&& !IsIconic( ci
->hwndActiveChild
))
1282 SetFocus( ci
->hwndActiveChild
);
1286 if( ci
->hwndActiveChild
)
1287 SendMessageW(ci
->hwndActiveChild
, message
, wParam
, lParam
);
1290 case WM_PARENTNOTIFY
:
1291 switch (LOWORD(wParam
))
1294 if (GetWindowLongPtrW((HWND
)lParam
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1296 // ReactOS See rev 33503
1298 ci
->child
= HeapAlloc(GetProcessHeap(), 0, sizeof(HWND
));
1300 ci
->child
= HeapReAlloc(GetProcessHeap(), 0, ci
->child
, sizeof(HWND
) * (ci
->nActiveChildren
+ 1));
1302 TRACE("Adding MDI child %p, # of children %d\n",
1303 (HWND
)lParam
, ci
->nActiveChildren
);
1305 if (ci
->child
!= NULL
)
1307 ci
->child
[ci
->nActiveChildren
] = (HWND
)lParam
;
1308 ci
->nTotalCreated
++;
1309 ci
->nActiveChildren
++;
1314 case WM_LBUTTONDOWN
:
1318 pt
.x
= (short)LOWORD(lParam
);
1319 pt
.y
= (short)HIWORD(lParam
);
1320 child
= ChildWindowFromPoint(hwnd
, pt
);
1322 TRACE("notification from %p (%li,%li)\n",child
,pt
.x
,pt
.y
);
1324 if( child
&& child
!= hwnd
&& child
!= ci
->hwndActiveChild
)
1325 SetWindowPos(child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1330 return MDIDestroyChild( hwnd
, ci
, WIN_GetFullHandle( (HWND
)lParam
), FALSE
);
1335 if( ci
->hwndActiveChild
&& IsZoomed(ci
->hwndActiveChild
) )
1341 rect
.right
= LOWORD(lParam
);
1342 rect
.bottom
= HIWORD(lParam
);
1343 AdjustWindowRectEx(&rect
, GetWindowLongPtrA(ci
->hwndActiveChild
, GWL_STYLE
),
1344 0, GetWindowLongPtrA(ci
->hwndActiveChild
, GWL_EXSTYLE
) );
1345 MoveWindow(ci
->hwndActiveChild
, rect
.left
, rect
.top
,
1346 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 1);
1349 MDI_PostUpdate(hwnd
, ci
, SB_BOTH
+1);
1353 case WM_MDICALCCHILDSCROLL
:
1354 if( (ci
->mdiFlags
& MDIF_NEEDUPDATE
) && ci
->sbRecalc
)
1356 CalcChildScroll(hwnd
, ci
->sbRecalc
-1);
1358 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1362 return unicode
? DefWindowProcW( hwnd
, message
, wParam
, lParam
) :
1363 DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1366 /***********************************************************************
1369 LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1371 if (!IsWindow(hwnd
)) return 0;
1372 return MDIClientWndProc_common( hwnd
, message
, wParam
, lParam
, FALSE
);
1375 /***********************************************************************
1378 LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1380 if (!IsWindow(hwnd
)) return 0;
1381 return MDIClientWndProc_common( hwnd
, message
, wParam
, lParam
, TRUE
);
1384 /***********************************************************************
1385 * DefFrameProcA (USER32.@)
1387 LRESULT WINAPI
DefFrameProcA( HWND hwnd
, HWND hwndMDIClient
,
1388 UINT message
, WPARAM wParam
, LPARAM lParam
)
1396 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, NULL
, 0 );
1397 LPWSTR text
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1400 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, text
, len
);
1401 MDI_UpdateFrameText( hwnd
, hwndMDIClient
, FALSE
, text
);
1402 HeapFree( GetProcessHeap(), 0, text
);
1404 return 1; /* success. FIXME: check text length */
1411 return DefFrameProcW( hwnd
, hwndMDIClient
, message
, wParam
, lParam
);
1414 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1418 /***********************************************************************
1419 * DefFrameProcW (USER32.@)
1421 LRESULT WINAPI
DefFrameProcW( HWND hwnd
, HWND hwndMDIClient
,
1422 UINT message
, WPARAM wParam
, LPARAM lParam
)
1424 MDICLIENTINFO
*ci
= get_client_info( hwndMDIClient
);
1426 TRACE("%p %p %04x (%s) %08lx %08lx\n", hwnd
, hwndMDIClient
, message
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1434 WORD id
= LOWORD(wParam
);
1435 /* check for possible syscommands for maximized MDI child */
1436 if (id
< ci
->idFirstChild
|| id
>= ci
->idFirstChild
+ ci
->nActiveChildren
)
1438 if( (id
- 0xf000) & 0xf00f ) break;
1439 if( !ci
->hwndChildMaximized
) break;
1443 if (!is_close_enabled(ci
->hwndActiveChild
, 0)) break;
1451 return SendMessageW( ci
->hwndChildMaximized
, WM_SYSCOMMAND
,
1458 if (id
- ci
->idFirstChild
== MDI_MOREWINDOWSLIMIT
)
1459 /* User chose "More Windows..." */
1460 childHwnd
= MDI_MoreWindowsDialog(hwndMDIClient
);
1462 /* User chose one of the windows listed in the "Windows" menu */
1463 childHwnd
= MDI_GetChildByID(hwndMDIClient
, id
, ci
);
1466 SendMessageW( hwndMDIClient
, WM_MDIACTIVATE
, (WPARAM
)childHwnd
, 0 );
1472 SendMessageW(hwndMDIClient
, message
, wParam
, lParam
);
1476 MDI_UpdateFrameText( hwnd
, hwndMDIClient
, FALSE
, (LPWSTR
)lParam
);
1477 return 1; /* success. FIXME: check text length */
1480 SetFocus(hwndMDIClient
);
1484 MoveWindow(hwndMDIClient
, 0, 0, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1489 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1491 if (!IsIconic(hwnd
) && ci
->hwndActiveChild
&& !IsZoomed(ci
->hwndActiveChild
))
1493 /* control menu is between the frame system menu and
1494 * the first entry of menu bar */
1495 // WND *wndPtr = WIN_GetPtr(hwnd);
1497 if( (wParam
== VK_LEFT
&& GetMenu(hwnd
) == next_menu
->hmenuIn
) ||
1498 (wParam
== VK_RIGHT
&& GetSubMenu(GetMenu(hwnd
), 0) == next_menu
->hmenuIn
) )
1500 // WIN_ReleasePtr(wndPtr);
1501 // wndPtr = WIN_GetPtr(ci->hwndActiveChild);
1502 next_menu
->hmenuNext
= GetSubMenu(GetMenu(ci
->hwndActiveChild
), 0);
1503 next_menu
->hwndNext
= ci
->hwndActiveChild
;
1505 // WIN_ReleasePtr(wndPtr);
1512 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1515 /***********************************************************************
1516 * DefMDIChildProcA (USER32.@)
1518 LRESULT WINAPI
DefMDIChildProcA( HWND hwnd
, UINT message
,
1519 WPARAM wParam
, LPARAM lParam
)
1521 HWND client
= GetParent(hwnd
);
1522 MDICLIENTINFO
*ci
= get_client_info( client
);
1524 TRACE("%p %04x (%s) %08lx %08lx\n", hwnd
, message
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1526 hwnd
= WIN_GetFullHandle( hwnd
);
1527 if (!ci
) return DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1532 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1533 if( ci
->hwndChildMaximized
== hwnd
)
1534 MDI_UpdateFrameText( GetParent(client
), client
, TRUE
, NULL
);
1535 MDI_RefreshMenu( ci
);
1536 return 1; /* success. FIXME: check text length */
1538 case WM_GETMINMAXINFO
:
1542 case WM_CHILDACTIVATE
:
1550 return DefMDIChildProcW( hwnd
, message
, wParam
, lParam
);
1552 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1556 /***********************************************************************
1557 * DefMDIChildProcW (USER32.@)
1559 LRESULT WINAPI
DefMDIChildProcW( HWND hwnd
, UINT message
,
1560 WPARAM wParam
, LPARAM lParam
)
1562 HWND client
= GetParent(hwnd
);
1563 MDICLIENTINFO
*ci
= get_client_info( client
);
1565 TRACE("%p %04x (%s) %08lx %08lx\n", hwnd
, message
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1567 hwnd
= WIN_GetFullHandle( hwnd
);
1568 if (!ci
) return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1573 DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1574 if( ci
->hwndChildMaximized
== hwnd
)
1575 MDI_UpdateFrameText( GetParent(client
), client
, TRUE
, NULL
);
1576 MDI_RefreshMenu( ci
);
1577 return 1; /* success. FIXME: check text length */
1579 case WM_GETMINMAXINFO
:
1580 MDI_ChildGetMinMaxInfo( client
, hwnd
, (MINMAXINFO
*)lParam
);
1584 return MAKELRESULT( 0, MNC_CLOSE
); /* MDI children don't have menu bars */
1587 SendMessageW( client
, WM_MDIDESTROY
, (WPARAM
)hwnd
, 0 );
1591 if (ci
->hwndActiveChild
!= hwnd
)
1592 MDI_ChildActivate( client
, hwnd
);
1595 case WM_CHILDACTIVATE
:
1596 if (IsWindowEnabled( hwnd
))
1597 MDI_ChildActivate( client
, hwnd
);
1601 switch (wParam
& 0xfff0)
1604 if( ci
->hwndChildMaximized
== hwnd
)
1611 if (ci
->hwndChildMaximized
== hwnd
)
1612 return SendMessageW( GetParent(client
), message
, wParam
, lParam
);
1615 SendMessageW( client
, WM_MDINEXT
, (WPARAM
)ci
->hwndActiveChild
, 0);
1618 SendMessageW( client
, WM_MDINEXT
, (WPARAM
)ci
->hwndActiveChild
, 1);
1625 //// Commented out r57663
1626 /*if (ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1627 else*/ MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1631 /* This is the only place where we switch to/from maximized state */
1633 TRACE("current active %p, maximized %p\n", ci
->hwndActiveChild
, ci
->hwndChildMaximized
);
1635 if( ci
->hwndChildMaximized
== hwnd
&& wParam
!= SIZE_MAXIMIZED
)
1639 ci
->hwndChildMaximized
= 0;
1641 frame
= GetParent(client
);
1642 MDI_RestoreFrameMenu( frame
, hwnd
, ci
->hBmpClose
);
1643 MDI_UpdateFrameText( frame
, client
, TRUE
, NULL
);
1646 if( wParam
== SIZE_MAXIMIZED
)
1648 HWND frame
, hMaxChild
= ci
->hwndChildMaximized
;
1650 if( hMaxChild
== hwnd
) break;
1654 SendMessageW( hMaxChild
, WM_SETREDRAW
, FALSE
, 0 );
1656 MDI_RestoreFrameMenu( GetParent(client
), hMaxChild
, ci
->hBmpClose
);
1657 ShowWindow( hMaxChild
, SW_SHOWNOACTIVATE
);
1659 SendMessageW( hMaxChild
, WM_SETREDRAW
, TRUE
, 0 );
1662 TRACE("maximizing child %p\n", hwnd
);
1664 /* keep track of the maximized window. */
1665 ci
->hwndChildMaximized
= hwnd
; /* !!! */
1667 frame
= GetParent(client
);
1668 MDI_AugmentFrameMenu( frame
, hwnd
);
1669 MDI_UpdateFrameText( frame
, client
, TRUE
, NULL
);
1672 if( wParam
== SIZE_MINIMIZED
)
1674 HWND switchTo
= MDI_GetWindow( ci
, hwnd
, TRUE
, WS_MINIMIZE
);
1676 if (!switchTo
) switchTo
= hwnd
;
1677 SendMessageW( switchTo
, WM_CHILDACTIVATE
, 0, 0 );
1680 MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1685 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1686 HWND parent
= GetParent(client
);
1688 if( wParam
== VK_LEFT
) /* switch to frame system menu */
1690 // WND *wndPtr = WIN_GetPtr( parent );
1691 next_menu
->hmenuNext
= GetSubMenu( GetMenu(parent
), 0 );
1692 // WIN_ReleasePtr( wndPtr );
1694 if( wParam
== VK_RIGHT
) /* to frame menu bar */
1696 next_menu
->hmenuNext
= GetMenu(parent
);
1698 next_menu
->hwndNext
= parent
;
1705 SendMessageW( hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, VK_SPACE
);
1711 /* Remove itself from the Window menu */
1712 MDI_RefreshMenu(ci
);
1715 return DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1718 /**********************************************************************
1719 * CreateMDIWindowA (USER32.@) Creates a MDI child
1722 * Success: Handle to created window
1725 HWND WINAPI
CreateMDIWindowA(
1726 LPCSTR lpClassName
, /* [in] Pointer to registered child class name */
1727 LPCSTR lpWindowName
, /* [in] Pointer to window name */
1728 DWORD dwStyle
, /* [in] Window style */
1729 INT X
, /* [in] Horizontal position of window */
1730 INT Y
, /* [in] Vertical position of window */
1731 INT nWidth
, /* [in] Width of window */
1732 INT nHeight
, /* [in] Height of window */
1733 HWND hWndParent
, /* [in] Handle to parent window */
1734 HINSTANCE hInstance
, /* [in] Handle to application instance */
1735 LPARAM lParam
) /* [in] Application-defined value */
1737 TRACE("(%s,%s,%08lx,%d,%d,%d,%d,%p,%p,%08lx)\n",
1738 debugstr_a(lpClassName
),debugstr_a(lpWindowName
),dwStyle
,X
,Y
,
1739 nWidth
,nHeight
,hWndParent
,hInstance
,lParam
);
1741 return CreateWindowExA(WS_EX_MDICHILD
, lpClassName
, lpWindowName
,
1742 dwStyle
, X
, Y
, nWidth
, nHeight
, hWndParent
,
1743 0, hInstance
, (LPVOID
)lParam
);
1746 /***********************************************************************
1747 * CreateMDIWindowW (USER32.@) Creates a MDI child
1750 * Success: Handle to created window
1753 HWND WINAPI
CreateMDIWindowW(
1754 LPCWSTR lpClassName
, /* [in] Pointer to registered child class name */
1755 LPCWSTR lpWindowName
, /* [in] Pointer to window name */
1756 DWORD dwStyle
, /* [in] Window style */
1757 INT X
, /* [in] Horizontal position of window */
1758 INT Y
, /* [in] Vertical position of window */
1759 INT nWidth
, /* [in] Width of window */
1760 INT nHeight
, /* [in] Height of window */
1761 HWND hWndParent
, /* [in] Handle to parent window */
1762 HINSTANCE hInstance
, /* [in] Handle to application instance */
1763 LPARAM lParam
) /* [in] Application-defined value */
1765 TRACE("(%s,%s,%08lx,%d,%d,%d,%d,%p,%p,%08lx)\n",
1766 debugstr_w(lpClassName
), debugstr_w(lpWindowName
), dwStyle
, X
, Y
,
1767 nWidth
, nHeight
, hWndParent
, hInstance
, lParam
);
1769 return CreateWindowExW(WS_EX_MDICHILD
, lpClassName
, lpWindowName
,
1770 dwStyle
, X
, Y
, nWidth
, nHeight
, hWndParent
,
1771 0, hInstance
, (LPVOID
)lParam
);
1774 /**********************************************************************
1775 * TranslateMDISysAccel (USER32.@)
1777 BOOL WINAPI
TranslateMDISysAccel( HWND hwndClient
, LPMSG msg
)
1779 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
)
1781 MDICLIENTINFO
*ci
= get_client_info( hwndClient
);
1784 if (!ci
|| !IsWindowEnabled(ci
->hwndActiveChild
)) return 0;
1786 /* translate if the Ctrl key is down and Alt not. */
1788 if( (GetKeyState(VK_CONTROL
) & 0x8000) && !(GetKeyState(VK_MENU
) & 0x8000))
1790 switch( msg
->wParam
)
1794 wParam
= ( GetKeyState(VK_SHIFT
) & 0x8000 ) ? SC_NEXTWINDOW
: SC_PREVWINDOW
;
1798 if (is_close_enabled(ci
->hwndActiveChild
, 0))
1807 TRACE("wParam = %04lx\n", wParam
);
1808 SendMessageW(ci
->hwndActiveChild
, WM_SYSCOMMAND
, wParam
, msg
->wParam
);
1812 return FALSE
; /* failure */
1815 /***********************************************************************
1816 * CalcChildScroll (USER32.@)
1818 void WINAPI
CalcChildScroll( HWND hwnd
, INT scroll
)
1821 RECT childRect
, clientRect
;
1824 WINDOWINFO WindowInfo
;
1826 GetClientRect( hwnd
, &clientRect
);
1827 SetRectEmpty( &childRect
);
1829 /* The rectangle returned by GetClientRect always has 0,0 as top left
1830 * because it is in client coordinates. The rectangles returned by
1831 * GetWindowRect are in screen coordinates to make this complicated.
1833 * Apparently (in ReactOS at least) the rcClient returned by GetWindowInfo
1834 * is in screen coordinates too.
1836 WindowInfo
.cbSize
= sizeof(WindowInfo
);
1837 if (!GetWindowInfo(hwnd
, &WindowInfo
))
1839 ERR("Can't get window info\n");
1843 TRACE("CalcChildScroll 1\n");
1844 if ((list
= WIN_ListChildren( hwnd
)))
1847 for (i
= 0; list
[i
]; i
++)
1849 style
= GetWindowLongPtrW( list
[i
], GWL_STYLE
);
1850 if (style
& WS_MAXIMIZE
)
1852 HeapFree( GetProcessHeap(), 0, list
);
1853 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
1854 ERR("CalcChildScroll 2\n");
1857 if (style
& WS_VISIBLE
)
1860 GetWindowRect( list
[i
], &rect
);
1861 OffsetRect(&rect
, -WindowInfo
.rcClient
.left
,
1862 -WindowInfo
.rcClient
.top
);
1863 //WIN_GetRectangles( list[i], COORDS_PARENT, &rect, NULL );
1864 TRACE("CalcChildScroll L\n");
1865 UnionRect( &childRect
, &rect
, &childRect
);
1868 HeapFree( GetProcessHeap(), 0, list
);
1870 UnionRect( &childRect
, &clientRect
, &childRect
);
1871 TRACE("CalcChildScroll 3\n");
1872 /* set common info values */
1873 info
.cbSize
= sizeof(info
);
1874 info
.fMask
= SIF_POS
| SIF_RANGE
| SIF_PAGE
;
1876 /* set the specific values and apply but only if window style allows */
1877 /* Note how we set nPos to 0 because we scroll the clients instead of
1878 * the window, and we set nPage to 1 bigger than the clientRect because
1879 * otherwise the scrollbar never disables. This causes a somewhat ugly
1880 * effect though while scrolling.
1882 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1887 if (style
& (WS_HSCROLL
| WS_VSCROLL
))
1889 info
.nMin
= childRect
.left
;
1890 info
.nMax
= childRect
.right
;
1892 info
.nPage
= 1 + clientRect
.right
- clientRect
.left
;
1893 //info.nMax = childRect.right - clientRect.right;
1894 //info.nPos = clientRect.left - childRect.left;
1895 SetScrollInfo(hwnd
, SB_HORZ
, &info
, TRUE
);
1897 if (scroll
== SB_HORZ
) break;
1900 if (style
& (WS_HSCROLL
| WS_VSCROLL
))
1902 info
.nMin
= childRect
.top
;
1903 info
.nMax
= childRect
.bottom
;
1905 info
.nPage
= 1 + clientRect
.bottom
- clientRect
.top
;
1906 //info.nMax = childRect.bottom - clientRect.bottom;
1907 //info.nPos = clientRect.top - childRect.top;
1908 SetScrollInfo(hwnd
, SB_VERT
, &info
, TRUE
);
1915 /***********************************************************************
1916 * ScrollChildren (USER32.@)
1918 void WINAPI
ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
,
1922 INT curPos
, length
, minPos
, maxPos
, shift
;
1925 GetClientRect( hWnd
, &rect
);
1930 GetScrollRange(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
1931 curPos
= GetScrollPos(hWnd
,SB_HORZ
);
1932 length
= (rect
.right
- rect
.left
) / 2;
1933 shift
= GetSystemMetrics(SM_CYHSCROLL
);
1936 GetScrollRange(hWnd
,SB_VERT
,&minPos
,&maxPos
);
1937 curPos
= GetScrollPos(hWnd
,SB_VERT
);
1938 length
= (rect
.bottom
- rect
.top
) / 2;
1939 shift
= GetSystemMetrics(SM_CXVSCROLL
);
1948 newPos
= curPos
- shift
;
1951 newPos
= curPos
+ shift
;
1954 newPos
= curPos
- length
;
1957 newPos
= curPos
+ length
;
1960 case SB_THUMBPOSITION
:
1961 newPos
= LOWORD(lParam
);
1974 CalcChildScroll(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
1978 if( newPos
> maxPos
)
1981 if( newPos
< minPos
)
1984 SetScrollPos(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
1986 if( uMsg
== WM_VSCROLL
)
1987 ScrollWindowEx(hWnd
,0 ,curPos
- newPos
, NULL
, NULL
, 0, NULL
,
1988 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
1990 ScrollWindowEx(hWnd
,curPos
- newPos
, 0, NULL
, NULL
, 0, NULL
,
1991 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
1995 /******************************************************************************
1996 * CascadeWindows (USER32.@) Cascades MDI child windows
1999 * Success: Number of cascaded windows.
2003 CascadeWindows (HWND hwndParent
, UINT wFlags
, LPCRECT lpRect
,
2004 UINT cKids
, const HWND
*lpKids
)
2006 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
2011 /***********************************************************************
2012 * CascadeChildWindows (USER32.@)
2014 WORD WINAPI
CascadeChildWindows( HWND parent
, UINT flags
)
2016 return CascadeWindows( parent
, flags
, NULL
, 0, NULL
);
2020 /******************************************************************************
2021 * TileWindows (USER32.@) Tiles MDI child windows
2024 * Success: Number of tiled windows.
2028 TileWindows (HWND hwndParent
, UINT wFlags
, LPCRECT lpRect
,
2029 UINT cKids
, const HWND
*lpKids
)
2031 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
2036 /***********************************************************************
2037 * TileChildWindows (USER32.@)
2039 WORD WINAPI
TileChildWindows( HWND parent
, UINT flags
)
2041 return TileWindows( parent
, flags
, NULL
, 0, NULL
);
2045 /************************************************************************
2046 * "More Windows..." functionality
2049 /* MDI_MoreWindowsDlgProc
2051 * This function will process the messages sent to the "More Windows..."
2053 * Return values: 0 = cancel pressed
2054 * HWND = ok pressed or double-click in the list...
2058 static INT_PTR WINAPI
MDI_MoreWindowsDlgProc (HWND hDlg
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
2067 MDICLIENTINFO
*ci
= get_client_info( (HWND
)lParam
);
2068 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2070 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
2072 WCHAR buffer
[MDI_MAXTITLELENGTH
];
2074 if (!InternalGetWindowText( ci
->child
[i
], buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
2076 SendMessageW(hListBox
, LB_ADDSTRING
, 0, (LPARAM
)buffer
);
2077 SendMessageW(hListBox
, LB_SETITEMDATA
, i
, (LPARAM
)ci
->child
[i
] );
2078 length
= strlenW(buffer
); /* FIXME: should use GetTextExtentPoint */
2079 if (length
> widest
)
2082 /* Make sure the horizontal scrollbar scrolls ok */
2083 SendMessageW(hListBox
, LB_SETHORIZONTALEXTENT
, widest
* 6, 0);
2085 /* Set the current selection */
2086 SendMessageW(hListBox
, LB_SETCURSEL
, MDI_MOREWINDOWSLIMIT
, 0);
2091 switch (LOWORD(wParam
))
2094 if (HIWORD(wParam
) != LBN_DBLCLK
) break;
2098 /* windows are sorted by menu ID, so we must return the
2099 * window associated to the given id
2101 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2102 UINT index
= SendMessageW(hListBox
, LB_GETCURSEL
, 0, 0);
2103 LRESULT res
= SendMessageW(hListBox
, LB_GETITEMDATA
, index
, 0);
2104 EndDialog(hDlg
, res
);
2118 * MDI_MoreWindowsDialog
2120 * Prompts the user with a listbox containing the opened
2121 * documents. The user can then choose a windows and click
2122 * on OK to set the current window to the one selected, or
2123 * CANCEL to cancel. The function returns a handle to the
2127 static HWND
MDI_MoreWindowsDialog(HWND hwnd
)
2133 hRes
= FindResourceA(User32Instance
, "MDI_MOREWINDOWS", (LPSTR
)RT_DIALOG
);
2138 hDlgTmpl
= LoadResource(User32Instance
, hRes
);
2143 template = LockResource( hDlgTmpl
);
2148 return (HWND
) DialogBoxIndirectParamA(User32Instance
, template, hwnd
,
2149 MDI_MoreWindowsDlgProc
, (LPARAM
) hwnd
);