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 UINT nActiveChildren
;
104 HWND hwndActiveChild
;
105 HWND
*child
; /* array of tracked children */
112 UINT sbRecalc
; /* SB_xxx flags for scrollbar fixup */
113 HBITMAP hBmpClose
; /* ReactOS modification */
116 //static HBITMAP hBmpClose = 0;
118 /* ----------------- declarations ----------------- */
119 static void MDI_UpdateFrameText( HWND
, HWND
, LPCWSTR
);
120 static BOOL
MDI_AugmentFrameMenu( HWND
, HWND
);
121 static BOOL
MDI_RestoreFrameMenu( HWND
, HWND
, HBITMAP
);
122 static LONG
MDI_ChildActivate( HWND
, HWND
);
123 static LRESULT
MDI_RefreshMenu(MDICLIENTINFO
*);
125 static HWND
MDI_MoreWindowsDialog(HWND
);
126 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
127 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
129 HWND
* WIN_ListChildren (HWND hWndparent
)
137 Status
= NtUserBuildHwndList ( NULL
, hWndparent
, FALSE
, 0, 0, NULL
, &dwCount
);
139 if ( !NT_SUCCESS( Status
) )
142 /* allocate buffer to receive HWND handles */
143 hHeap
= GetProcessHeap();
145 pHwnd
= HeapAlloc ( hHeap
, 0, sizeof(HWND
)*(dwCount
+1) );
148 SetLastError ( ERROR_NOT_ENOUGH_MEMORY
);
152 /* now call kernel again to fill the buffer this time */
153 Status
= NtUserBuildHwndList (NULL
, hWndparent
, FALSE
, 0, 0, pHwnd
, &dwCount
);
155 if ( !NT_SUCCESS( Status
) )
158 HeapFree ( hHeap
, 0, pHwnd
);
162 pHwnd
[dwCount
] = (HWND
) 0;
168 void WINAPI
ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
169 void WINAPI
CalcChildScroll(HWND hwnd
, INT scroll
);
172 /* -------- Miscellaneous service functions ----------
176 static HWND
MDI_GetChildByID(HWND hwnd
, UINT id
, MDICLIENTINFO
*ci
)
180 for (i
= 0; ci
->nActiveChildren
; i
++)
182 if (GetWindowLongPtrW( ci
->child
[i
], GWLP_ID
) == id
)
188 static void MDI_PostUpdate(HWND hwnd
, MDICLIENTINFO
* ci
, WORD recalc
)
190 if( !(ci
->mdiFlags
& MDIF_NEEDUPDATE
) )
192 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
193 PostMessageA( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0);
195 ci
->sbRecalc
= recalc
;
199 /*********************************************************************
200 * MDIClient class descriptor
202 const struct builtin_class_descr MDICLIENT_builtin_class
=
204 L
"MDIClient", /* name */
206 MDIClientWndProcW
, /* procW */
207 MDIClientWndProcA
, /* procA */
208 sizeof(MDICLIENTINFO
), /* extra */
209 IDC_ARROW
, /* cursor */
210 (HBRUSH
)(COLOR_APPWORKSPACE
+1) /* brush */
214 static MDICLIENTINFO
*get_client_info( HWND client
)
217 return (MDICLIENTINFO
*)GetWindowLongPtr(client
, 0);
219 MDICLIENTINFO
*ret
= NULL
;
220 WND
*win
= WIN_GetPtr( client
);
223 if (win
== WND_OTHER_PROCESS
)
225 if (IsWindow(client
)) ERR( "client %p belongs to other process\n", client
);
228 if (win
->cbWndExtra
< sizeof(MDICLIENTINFO
)) WARN( "%p is not an MDI client\n", client
);
229 else ret
= (MDICLIENTINFO
*)win
->wExtra
;
230 WIN_ReleasePtr( win
);
236 static BOOL
is_close_enabled(HWND hwnd
, HMENU hSysMenu
)
238 if (GetClassLongW(hwnd
, GCL_STYLE
) & CS_NOCLOSE
) return FALSE
;
240 if (!hSysMenu
) hSysMenu
= GetSystemMenu(hwnd
, FALSE
);
243 UINT state
= GetMenuState(hSysMenu
, SC_CLOSE
, MF_BYCOMMAND
);
244 if (state
== 0xFFFFFFFF || (state
& (MF_DISABLED
| MF_GRAYED
)))
251 /**********************************************************************
254 * returns "activateable" child different from the current or zero
256 static HWND
MDI_GetWindow(MDICLIENTINFO
*clientInfo
, HWND hWnd
, BOOL bNext
,
263 dwStyleMask
|= WS_DISABLED
| WS_VISIBLE
;
264 if( !hWnd
) hWnd
= clientInfo
->hwndActiveChild
;
266 if (!(list
= WIN_ListChildren( GetParent(hWnd
) ))) return 0;
268 /* start from next after hWnd */
269 while (list
[i
] && list
[i
] != hWnd
) i
++;
272 for ( ; list
[i
]; i
++)
274 if (GetWindow( list
[i
], GW_OWNER
)) continue;
275 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
277 if (bNext
) goto found
;
279 /* now restart from the beginning */
280 for (i
= 0; list
[i
] && list
[i
] != hWnd
; i
++)
282 if (GetWindow( list
[i
], GW_OWNER
)) continue;
283 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
285 if (bNext
) goto found
;
288 HeapFree( GetProcessHeap(), 0, list
);
292 /**********************************************************************
293 * MDI_CalcDefaultChildPos
295 * It seems that the default height is about 2/3 of the client rect
297 void MDI_CalcDefaultChildPos( HWND hwndClient
, INT total
, LPPOINT lpPos
, INT delta
, UINT
*id
)
301 INT spacing
= GetSystemMetrics(SM_CYCAPTION
) + GetSystemMetrics(SM_CYFRAME
) - 1;
303 if (total
< 0) /* we are called from CreateWindow */
305 MDICLIENTINFO
*ci
= get_client_info(hwndClient
);
306 total
= ci
? ci
->nTotalCreated
: 0;
307 *id
= ci
? ci
->idFirstChild
+ ci
->nActiveChildren
: 0;
308 TRACE("MDI child id %04x\n", *id
);
311 GetClientRect( hwndClient
, &rect
);
312 if( rect
.bottom
- rect
.top
- delta
>= spacing
)
313 rect
.bottom
-= delta
;
315 nstagger
= (rect
.bottom
- rect
.top
)/(3 * spacing
);
316 lpPos
[1].x
= (rect
.right
- rect
.left
- nstagger
* spacing
);
317 lpPos
[1].y
= (rect
.bottom
- rect
.top
- nstagger
* spacing
);
318 lpPos
[0].x
= lpPos
[0].y
= spacing
* (total
%(nstagger
+1));
321 /**********************************************************************
324 static LRESULT
MDISetMenu( HWND hwnd
, HMENU hmenuFrame
,
328 HWND hwndFrame
= GetParent(hwnd
);
330 TRACE("%p %p %p\n", hwnd
, hmenuFrame
, hmenuWindow
);
332 if (hmenuFrame
&& !IsMenu(hmenuFrame
))
334 WARN("hmenuFrame is not a menu handle\n");
338 if (hmenuWindow
&& !IsMenu(hmenuWindow
))
340 WARN("hmenuWindow is not a menu handle\n");
344 if (!(ci
= get_client_info( hwnd
))) return 0;
348 if (hmenuFrame
== ci
->hFrameMenu
) return (LRESULT
)hmenuFrame
;
350 if (IsZoomed(ci
->hwndActiveChild
))
351 MDI_RestoreFrameMenu( hwndFrame
, ci
->hwndActiveChild
, ci
->hBmpClose
);
354 if( hmenuWindow
&& hmenuWindow
!= ci
->hWindowMenu
)
356 /* delete menu items from ci->hWindowMenu
357 * and add them to hmenuWindow */
358 /* Agent newsreader calls this function with ci->hWindowMenu == NULL */
359 if( ci
->hWindowMenu
&& ci
->nActiveChildren
)
361 UINT nActiveChildren_old
= ci
->nActiveChildren
;
363 /* Remove all items from old Window menu */
364 ci
->nActiveChildren
= 0;
367 ci
->hWindowMenu
= hmenuWindow
;
369 /* Add items to the new Window menu */
370 ci
->nActiveChildren
= nActiveChildren_old
;
374 ci
->hWindowMenu
= hmenuWindow
;
379 SetMenu(hwndFrame
, hmenuFrame
);
380 if( hmenuFrame
!= ci
->hFrameMenu
)
382 HMENU oldFrameMenu
= ci
->hFrameMenu
;
384 ci
->hFrameMenu
= hmenuFrame
;
385 if (IsZoomed(ci
->hwndActiveChild
) && (GetWindowLongW(ci
->hwndActiveChild
, GWL_STYLE
) & WS_VISIBLE
))
386 MDI_AugmentFrameMenu( hwndFrame
, ci
->hwndActiveChild
);
388 return (LRESULT
)oldFrameMenu
;
393 /* SetMenu() may already have been called, meaning that this window
394 * already has its menu. But they may have done a SetMenu() on
395 * an MDI window, and called MDISetMenu() after the fact, meaning
396 * that the "if" to this "else" wouldn't catch the need to
397 * augment the frame menu.
399 if( IsZoomed(ci
->hwndActiveChild
) )
400 MDI_AugmentFrameMenu( hwndFrame
, ci
->hwndActiveChild
);
406 /**********************************************************************
409 static LRESULT
MDI_RefreshMenu(MDICLIENTINFO
*ci
)
411 UINT i
, count
, visible
, id
;
412 WCHAR buf
[MDI_MAXTITLELENGTH
];
414 TRACE("children %u, window menu %p\n", ci
->nActiveChildren
, ci
->hWindowMenu
);
416 if (!ci
->hWindowMenu
)
419 if (!IsMenu(ci
->hWindowMenu
))
421 WARN("Window menu handle %p is no more valid\n", ci
->hWindowMenu
);
425 /* Windows finds the last separator in the menu, and if after it
426 * there is a menu item with MDI magic ID removes all existing
427 * menu items after it, and then adds visible MDI children.
429 count
= GetMenuItemCount(ci
->hWindowMenu
);
430 for (i
= 0; i
< count
; i
++)
434 memset(&mii
, 0, sizeof(mii
));
435 mii
.cbSize
= sizeof(mii
);
436 mii
.fMask
= MIIM_TYPE
;
437 if (GetMenuItemInfoW(ci
->hWindowMenu
, i
, TRUE
, &mii
))
439 if (mii
.fType
& MF_SEPARATOR
)
441 /* Windows checks only ID of the menu item */
442 memset(&mii
, 0, sizeof(mii
));
443 mii
.cbSize
= sizeof(mii
);
445 if (GetMenuItemInfoW(ci
->hWindowMenu
, i
+ 1, TRUE
, &mii
))
447 if (mii
.wID
== ci
->idFirstChild
)
449 TRACE("removing %u items including separator\n", count
- i
);
450 while (NtUserRemoveMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
))
461 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
463 if (GetWindowLongW(ci
->child
[i
], GWL_STYLE
) & WS_VISIBLE
)
465 id
= ci
->idFirstChild
+ visible
;
467 if (visible
== MDI_MOREWINDOWSLIMIT
)
469 LoadStringW(User32Instance
, IDS_MDI_MOREWINDOWS
, buf
, sizeof(buf
)/sizeof(WCHAR
));
470 AppendMenuW(ci
->hWindowMenu
, MF_STRING
, id
, buf
);
475 /* Visio expects that separator has id 0 */
476 AppendMenuW(ci
->hWindowMenu
, MF_SEPARATOR
, 0, NULL
);
480 SetWindowLongPtrW(ci
->child
[i
], GWLP_ID
, id
);
483 buf
[1] = '0' + visible
;
485 InternalGetWindowText(ci
->child
[i
], buf
+ 3, sizeof(buf
)/sizeof(WCHAR
) - 3);
486 TRACE("Adding %p, id %u %s\n", ci
->child
[i
], id
, debugstr_w(buf
));
487 AppendMenuW(ci
->hWindowMenu
, MF_STRING
, id
, buf
);
489 if (ci
->child
[i
] == ci
->hwndActiveChild
)
490 CheckMenuItem(ci
->hWindowMenu
, id
, MF_CHECKED
);
493 TRACE("MDI child %p is not visible, skipping\n", ci
->child
[i
]);
496 return (LRESULT
)ci
->hFrameMenu
;
500 /* ------------------ MDI child window functions ---------------------- */
502 /**********************************************************************
503 * MDI_ChildGetMinMaxInfo
505 * Note: The rule here is that client rect of the maximized MDI child
506 * is equal to the client rect of the MDI client window.
508 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
512 GetClientRect( client
, &rect
);
513 AdjustWindowRectEx( &rect
, GetWindowLongW( hwnd
, GWL_STYLE
),
514 0, GetWindowLongW( hwnd
, GWL_EXSTYLE
));
516 lpMinMax
->ptMaxSize
.x
= rect
.right
-= rect
.left
;
517 lpMinMax
->ptMaxSize
.y
= rect
.bottom
-= rect
.top
;
519 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
520 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
522 TRACE("max rect (%ld,%ld - %ld, %ld)\n",
523 rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
526 /**********************************************************************
527 * MDI_SwitchActiveChild
529 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
532 static void MDI_SwitchActiveChild( MDICLIENTINFO
*ci
, HWND hwndTo
, BOOL activate
)
536 hwndPrev
= ci
->hwndActiveChild
;
538 TRACE("from %p, to %p\n", hwndPrev
, hwndTo
);
540 if ( hwndTo
!= hwndPrev
)
542 BOOL was_zoomed
= IsZoomed(hwndPrev
);
546 /* restore old MDI child */
547 SendMessageW( hwndPrev
, WM_SETREDRAW
, FALSE
, 0 );
548 NtUserShowWindow( hwndPrev
, SW_RESTORE
);
549 SendMessageW( hwndPrev
, WM_SETREDRAW
, TRUE
, 0 );
551 /* activate new MDI child */
552 NtUserSetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
);
553 /* maximize new MDI child */
554 NtUserShowWindow( hwndTo
, SW_MAXIMIZE
);
556 /* activate new MDI child */
557 NtUserSetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
| (activate
? 0 : SWP_NOACTIVATE
) );
562 /**********************************************************************
565 static LRESULT
MDIDestroyChild( HWND client
, MDICLIENTINFO
*ci
,
566 HWND child
, BOOL flagDestroy
)
570 TRACE("# of managed children %u\n", ci
->nActiveChildren
);
572 if( child
== ci
->hwndActiveChild
)
574 HWND next
= MDI_GetWindow(ci
, child
, TRUE
, 0);
576 MDI_SwitchActiveChild(ci
, next
, TRUE
);
579 NtUserShowWindow(child
, SW_HIDE
);
582 MDI_RestoreFrameMenu(GetParent(client
), child
, ci
->hBmpClose
);
583 MDI_UpdateFrameText(GetParent(client
), client
, NULL
);
585 MDI_ChildActivate(client
, 0);
589 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
591 if (ci
->child
[i
] == child
)
593 HWND
*new_child
= HeapAlloc(GetProcessHeap(), 0, (ci
->nActiveChildren
- 1) * sizeof(HWND
));
594 if (new_child
!= NULL
)
596 memcpy(new_child
, ci
->child
, i
* sizeof(HWND
));
597 if (i
+ 1 < ci
->nActiveChildren
)
598 memcpy(new_child
+ i
, ci
->child
+ i
+ 1, (ci
->nActiveChildren
- i
- 1) * sizeof(HWND
));
599 HeapFree(GetProcessHeap(), 0, ci
->child
);
600 ci
->child
= new_child
;
605 for (c
= i
; c
< ci
->nActiveChildren
- 1; c
++)
607 ci
->child
[c
] = ci
->child
[c
+1];
611 ci
->nActiveChildren
--;
616 SendMessageW(client
, WM_MDIREFRESHMENU
, 0, 0);
620 MDI_PostUpdate(GetParent(child
), ci
, SB_BOTH
+1);
621 NtUserDestroyWindow(child
);
624 TRACE("child destroyed - %p\n", child
);
629 /**********************************************************************
632 * Called in response to WM_CHILDACTIVATE, or when last MDI child
633 * is being deactivated.
635 static LONG
MDI_ChildActivate( HWND client
, HWND child
)
637 MDICLIENTINFO
*clientInfo
;
638 HWND prevActiveWnd
, frame
;
639 BOOL isActiveFrameWnd
;
641 clientInfo
= get_client_info( client
);
643 if (clientInfo
->hwndActiveChild
== child
) return 0;
645 TRACE("%p\n", child
);
647 frame
= GetParent(client
);
648 isActiveFrameWnd
= (GetActiveWindow() == frame
);
649 prevActiveWnd
= clientInfo
->hwndActiveChild
;
651 /* deactivate prev. active child */
654 SendMessageW( prevActiveWnd
, WM_NCACTIVATE
, FALSE
, 0L );
655 SendMessageW( prevActiveWnd
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
658 MDI_SwitchActiveChild( clientInfo
, child
, FALSE
);
659 clientInfo
->hwndActiveChild
= child
;
661 MDI_RefreshMenu(clientInfo
);
663 if( isActiveFrameWnd
)
665 SendMessageW( child
, WM_NCACTIVATE
, TRUE
, 0L);
666 NtUserSetFocus( client
);
669 SendMessageW( child
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
673 /* -------------------- MDI client window functions ------------------- */
675 /**********************************************************************
676 * CreateMDIMenuBitmap
678 static HBITMAP
CreateMDIMenuBitmap(void)
680 HDC hDCSrc
= CreateCompatibleDC(0);
681 HDC hDCDest
= CreateCompatibleDC(hDCSrc
);
682 HBITMAP hbClose
= LoadBitmapW(0, MAKEINTRESOURCEW(OBM_OLD_CLOSE
) );
684 HBITMAP hobjSrc
, hobjDest
;
686 hobjSrc
= SelectObject(hDCSrc
, hbClose
);
687 hbCopy
= CreateCompatibleBitmap(hDCSrc
,GetSystemMetrics(SM_CXSIZE
),GetSystemMetrics(SM_CYSIZE
));
688 hobjDest
= SelectObject(hDCDest
, hbCopy
);
690 BitBlt(hDCDest
, 0, 0, GetSystemMetrics(SM_CXSIZE
), GetSystemMetrics(SM_CYSIZE
),
691 hDCSrc
, GetSystemMetrics(SM_CXSIZE
), 0, SRCCOPY
);
693 SelectObject(hDCSrc
, hobjSrc
);
694 DeleteObject(hbClose
);
697 hobjSrc
= SelectObject( hDCDest
, GetStockObject(BLACK_PEN
) );
699 MoveToEx( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, 0, NULL
);
700 LineTo( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, GetSystemMetrics(SM_CYSIZE
) - 1);
702 SelectObject(hDCDest
, hobjSrc
);
703 SelectObject(hDCDest
, hobjDest
);
709 /**********************************************************************
712 static LONG
MDICascade( HWND client
, MDICLIENTINFO
*ci
)
715 BOOL has_icons
= FALSE
;
718 if (IsZoomed(ci
->hwndActiveChild
))
719 SendMessageW(client
, WM_MDIRESTORE
, (WPARAM
)ci
->hwndActiveChild
, 0);
721 if (ci
->nActiveChildren
== 0) return 0;
723 if (!(win_array
= WIN_ListChildren( client
))) return 0;
725 /* remove all the windows we don't want */
726 for (i
= total
= 0; win_array
[i
]; i
++)
728 if (!IsWindowVisible( win_array
[i
] )) continue;
729 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows */
730 if (IsIconic( win_array
[i
] ))
735 win_array
[total
++] = win_array
[i
];
737 win_array
[total
] = 0;
741 INT delta
= 0, n
= 0, i
;
743 if (has_icons
) delta
= GetSystemMetrics(SM_CYICONSPACING
) + GetSystemMetrics(SM_CYICON
);
745 /* walk the list (backwards) and move windows */
746 for (i
= total
- 1; i
>= 0; i
--)
748 MDI_CalcDefaultChildPos(client
, n
++, pos
, delta
, NULL
);
750 TRACE("move %p to (%ld,%ld) size [%ld,%ld]\n",
751 win_array
[i
], pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
);
753 NtUserSetWindowPos( win_array
[i
], 0, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
,
754 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
757 HeapFree( GetProcessHeap(), 0, win_array
);
759 if (has_icons
) ArrangeIconicWindows( client
);
763 /**********************************************************************
766 static void MDITile( HWND client
, MDICLIENTINFO
*ci
, WPARAM wParam
)
770 BOOL has_icons
= FALSE
;
772 if (IsZoomed(ci
->hwndActiveChild
))
773 SendMessageW(client
, WM_MDIRESTORE
, (WPARAM
)ci
->hwndActiveChild
, 0);
775 if (ci
->nActiveChildren
== 0) return;
777 if (!(win_array
= WIN_ListChildren( client
))) return;
779 /* remove all the windows we don't want */
780 for (i
= total
= 0; win_array
[i
]; i
++)
782 if (!IsWindowVisible( win_array
[i
] )) continue;
783 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows (icon titles) */
784 if (IsIconic( win_array
[i
] ))
789 if ((wParam
& MDITILE_SKIPDISABLED
) && !IsWindowEnabled( win_array
[i
] )) continue;
790 win_array
[total
++] = win_array
[i
];
792 win_array
[total
] = 0;
794 TRACE("%u windows to tile\n", total
);
798 HWND
*pWnd
= win_array
;
800 int x
, y
, xsize
, ysize
;
801 int rows
, columns
, r
, c
, i
;
803 GetClientRect(client
,&rect
);
804 rows
= (int) sqrt((double)total
);
805 columns
= total
/ rows
;
807 if( wParam
& MDITILE_HORIZONTAL
) /* version >= 3.1 */
810 rows
= columns
; /* exchange r and c */
816 y
= rect
.bottom
- 2 * GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
817 rect
.bottom
= ( y
- GetSystemMetrics(SM_CYICON
) < rect
.top
)? rect
.bottom
: y
;
820 ysize
= rect
.bottom
/ rows
;
821 xsize
= rect
.right
/ columns
;
823 for (x
= i
= 0, c
= 1; c
<= columns
&& *pWnd
; c
++)
828 ysize
= rect
.bottom
/ rows
;
832 for (r
= 1; r
<= rows
&& *pWnd
; r
++, i
++)
834 NtUserSetWindowPos(*pWnd
, 0, x
, y
, xsize
, ysize
,
835 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
842 HeapFree( GetProcessHeap(), 0, win_array
);
843 if (has_icons
) ArrangeIconicWindows( client
);
846 /* ----------------------- Frame window ---------------------------- */
849 /**********************************************************************
850 * MDI_AugmentFrameMenu
852 static BOOL
MDI_AugmentFrameMenu( HWND frame
, HWND hChild
)
854 HMENU menu
= GetMenu( frame
);
856 HBITMAP hSysMenuBitmap
= 0;
861 TRACE("frame %p,child %p\n",frame
,hChild
);
863 if( !menu
) return 0;
865 /* if the system buttons already exist do not add them again */
866 nItems
= GetMenuItemCount(menu
) - 1;
867 iId
= GetMenuItemID(menu
,nItems
) ;
868 if (iId
== SC_RESTORE
|| iId
== SC_CLOSE
)
871 /* create a copy of sysmenu popup and insert it into frame menu bar */
872 if (!(hSysPopup
= GetSystemMenu(hChild
, FALSE
)))
875 AppendMenuW(menu
, MF_HELP
| MF_BITMAP
,
876 SC_MINIMIZE
, (LPCWSTR
)HBMMENU_MBAR_MINIMIZE
) ;
877 AppendMenuW(menu
, MF_HELP
| MF_BITMAP
,
878 SC_RESTORE
, (LPCWSTR
)HBMMENU_MBAR_RESTORE
);
879 AppendMenuW(menu
, MF_HELP
| MF_BITMAP
,
880 SC_CLOSE
, is_close_enabled(hChild
, hSysPopup
) ?
881 (LPCWSTR
)HBMMENU_MBAR_CLOSE
: (LPCWSTR
)HBMMENU_MBAR_CLOSE_D
);
883 /* The system menu is replaced by the child icon */
884 hIcon
= (HICON
)GetClassLongPtrW(hChild
, GCLP_HICONSM
);
886 hIcon
= (HICON
)GetClassLongPtrW(hChild
, GCLP_HICON
);
888 hIcon
= LoadIconW(NULL
, IDI_APPLICATION
);
892 HBITMAP hBitmap
, hOldBitmap
;
894 HDC hdc
= NtUserGetDC(hChild
);
899 cx
= GetSystemMetrics(SM_CXSMICON
);
900 cy
= GetSystemMetrics(SM_CYSMICON
);
901 hMemDC
= CreateCompatibleDC(hdc
);
902 hBitmap
= CreateCompatibleBitmap(hdc
, cx
, cy
);
903 hOldBitmap
= SelectObject(hMemDC
, hBitmap
);
904 SetMapMode(hMemDC
, MM_TEXT
);
905 hBrush
= CreateSolidBrush(GetSysColor(COLOR_MENU
));
906 DrawIconEx(hMemDC
, 0, 0, hIcon
, cx
, cy
, 0, hBrush
, DI_NORMAL
);
907 SelectObject (hMemDC
, hOldBitmap
);
908 DeleteObject(hBrush
);
910 ReleaseDC(hChild
, hdc
);
911 hSysMenuBitmap
= hBitmap
;
915 if( !InsertMenuA(menu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
916 (UINT_PTR
)hSysPopup
, (LPSTR
)hSysMenuBitmap
))
918 TRACE("not inserted\n");
919 NtUserDestroyMenu(hSysPopup
);
923 EnableMenuItem(hSysPopup
, SC_SIZE
, MF_BYCOMMAND
| MF_GRAYED
);
924 EnableMenuItem(hSysPopup
, SC_MOVE
, MF_BYCOMMAND
| MF_GRAYED
);
925 EnableMenuItem(hSysPopup
, SC_MAXIMIZE
, MF_BYCOMMAND
| MF_GRAYED
);
926 NtUserSetMenuDefaultItem(hSysPopup
, SC_CLOSE
, FALSE
);
934 /**********************************************************************
935 * MDI_RestoreFrameMenu
937 static BOOL
MDI_RestoreFrameMenu( HWND frame
, HWND hChild
, HBITMAP hBmpClose
)
939 MENUITEMINFOW menuInfo
;
940 HMENU menu
= GetMenu( frame
);
941 INT nItems
= GetMenuItemCount(menu
) - 1;
942 UINT iId
= GetMenuItemID(menu
,nItems
) ;
944 TRACE("frame %p,child %p,nIt=%d,iId=%d\n",frame
,hChild
,nItems
,iId
);
946 if( !menu
) return 0;
948 /* if there is no system buttons then nothing to do */
949 if(!(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
953 * Remove the system menu, If that menu is the icon of the window
954 * as it is in win95, we have to delete the bitmap.
956 memset(&menuInfo
, 0, sizeof(menuInfo
));
957 menuInfo
.cbSize
= sizeof(menuInfo
);
958 menuInfo
.fMask
= MIIM_DATA
| MIIM_TYPE
| MIIM_BITMAP
;
960 GetMenuItemInfoW(menu
,
965 NtUserRemoveMenu(menu
,0,MF_BYPOSITION
);
967 if ( (menuInfo
.fType
& MFT_BITMAP
) &&
968 (menuInfo
.dwTypeData
!= 0) &&
969 (menuInfo
.dwTypeData
!= (LPWSTR
)hBmpClose
) )
971 DeleteObject(menuInfo
.dwTypeData
);
974 if ( menuInfo
.hbmpItem
!= 0 )
975 DeleteObject(menuInfo
.hbmpItem
);
978 NtUserDeleteMenu(menu
, SC_CLOSE
, MF_BYCOMMAND
);
980 NtUserDeleteMenu(menu
, SC_RESTORE
, MF_BYCOMMAND
);
982 NtUserDeleteMenu(menu
, SC_MINIMIZE
, MF_BYCOMMAND
);
990 /**********************************************************************
991 * MDI_UpdateFrameText
993 * used when child window is maximized/restored
995 * Note: lpTitle can be NULL
997 static void MDI_UpdateFrameText( HWND frame
, HWND hClient
, LPCWSTR lpTitle
)
999 WCHAR lpBuffer
[MDI_MAXTITLELENGTH
+1];
1000 MDICLIENTINFO
*ci
= get_client_info( hClient
);
1002 TRACE("frameText %s\n", debugstr_w(lpTitle
));
1006 if (!lpTitle
&& !ci
->frameTitle
) /* first time around, get title from the frame window */
1008 GetWindowTextW( frame
, lpBuffer
, sizeof(lpBuffer
)/sizeof(WCHAR
) );
1012 /* store new "default" title if lpTitle is not NULL */
1015 HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1016 if ((ci
->frameTitle
= HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle
)+1)*sizeof(WCHAR
))))
1017 strcpyW( ci
->frameTitle
, lpTitle
);
1022 if (IsZoomed(ci
->hwndActiveChild
) && IsWindowVisible(ci
->hwndActiveChild
))
1024 /* combine frame title and child title if possible */
1026 static const WCHAR lpBracket
[] = {' ','-',' ','[',0};
1027 static const WCHAR lpBracket2
[] = {']',0};
1028 int i_frame_text_length
= strlenW(ci
->frameTitle
);
1030 lstrcpynW( lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
1032 if( i_frame_text_length
+ 6 < MDI_MAXTITLELENGTH
)
1034 strcatW( lpBuffer
, lpBracket
);
1035 if (GetWindowTextW( ci
->hwndActiveChild
, lpBuffer
+ i_frame_text_length
+ 4,
1036 MDI_MAXTITLELENGTH
- i_frame_text_length
- 5 ))
1037 strcatW( lpBuffer
, lpBracket2
);
1039 lpBuffer
[i_frame_text_length
] = 0; /* remove bracket */
1044 lstrcpynW(lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
+1 );
1050 DefWindowProcW( frame
, WM_SETTEXT
, 0, (LPARAM
)lpBuffer
);
1054 /* ----------------------------- Interface ---------------------------- */
1057 /**********************************************************************
1058 * MDIClientWndProc_common
1060 static LRESULT
MDIClientWndProc_common( HWND hwnd
, UINT message
,
1061 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1063 MDICLIENTINFO
*ci
= NULL
;
1065 TRACE("%p %04x (%s) %08lx %08lx\n", hwnd
, message
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1067 if (WM_NCCREATE
!= message
&& NULL
== (ci
= get_client_info(hwnd
)))
1073 if (!(ci
= get_client_info( hwnd
))) return 0;
1080 if (!(ci
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ci
))))
1082 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)ci
);
1089 /* Since we are using only cs->lpCreateParams, we can safely
1090 * cast to LPCREATESTRUCTA here */
1091 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
1093 WND
*wndPtr
= WIN_GetPtr( hwnd
);
1095 wndPtr
->flags
|= WIN_ISMDICLIENT
;
1097 /* Translation layer doesn't know what's in the cs->lpCreateParams
1098 * so we have to keep track of what environment we're in. */
1101 if( wndPtr
->flags
& WIN_ISWIN32
)
1104 LPCLIENTCREATESTRUCT ccs
= (LPCLIENTCREATESTRUCT
)cs
->lpCreateParams
;
1105 ci
->hWindowMenu
= ccs
->hWindowMenu
;
1106 ci
->idFirstChild
= ccs
->idFirstChild
;
1111 LPCLIENTCREATESTRUCT16 ccs
= MapSL((SEGPTR
)cs
->lpCreateParams
);
1112 ci
->hWindowMenu
= HMENU_32(ccs
->hWindowMenu
);
1113 ci
->idFirstChild
= ccs
->idFirstChild
;
1115 WIN_ReleasePtr( wndPtr
);
1118 ci
->nActiveChildren
= 0;
1119 ci
->nTotalCreated
= 0;
1120 ci
->frameTitle
= NULL
;
1122 ci
->hFrameMenu
= GetMenu(cs
->hwndParent
);
1124 if (!ci
->hBmpClose
) ci
->hBmpClose
= CreateMDIMenuBitmap();
1126 TRACE("Client created: hwnd %p, Window menu %p, idFirst = %04x\n",
1127 hwnd
, ci
->hWindowMenu
, ci
->idFirstChild
);
1133 if( IsZoomed(ci
->hwndActiveChild
) )
1134 MDI_RestoreFrameMenu(GetParent(hwnd
), ci
->hwndActiveChild
, ci
->hBmpClose
);
1136 ci
->nActiveChildren
= 0;
1137 MDI_RefreshMenu(ci
);
1139 HeapFree( GetProcessHeap(), 0, ci
->child
);
1140 HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1142 HeapFree( GetProcessHeap(), 0, ci
);
1143 SetWindowLongPtrW( hwnd
, 0, 0 );
1148 case WM_MDIACTIVATE
:
1150 MDI_SwitchActiveChild( ci
, (HWND
)wParam
, TRUE
);
1155 return MDICascade(hwnd
, ci
);
1164 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)lParam
;
1165 child
= CreateWindowExW(WS_EX_MDICHILD
, csW
->szClass
,
1166 csW
->szTitle
, csW
->style
,
1167 csW
->x
, csW
->y
, csW
->cx
, csW
->cy
,
1168 hwnd
, 0, csW
->hOwner
,
1169 (LPVOID
)csW
->lParam
);
1173 MDICREATESTRUCTA
*csA
= (MDICREATESTRUCTA
*)lParam
;
1174 child
= CreateWindowExA(WS_EX_MDICHILD
, csA
->szClass
,
1175 csA
->szTitle
, csA
->style
,
1176 csA
->x
, csA
->y
, csA
->cx
, csA
->cy
,
1177 hwnd
, 0, csA
->hOwner
,
1178 (LPVOID
)csA
->lParam
);
1181 if (IsZoomed(ci
->hwndActiveChild
))
1183 MDI_AugmentFrameMenu(GetParent(hwnd
), child
);
1184 MDI_UpdateFrameText(GetParent(hwnd
), hwnd
, NULL
);
1186 return (LRESULT
)child
;
1192 return MDIDestroyChild( hwnd
, ci
, WIN_GetFullHandle( (HWND
)wParam
), TRUE
);
1194 return MDIDestroyChild( hwnd
, ci
, (HWND
)wParam
, TRUE
);
1196 case WM_MDIGETACTIVE
:
1197 if (lParam
) *(BOOL
*)lParam
= IsZoomed(ci
->hwndActiveChild
);
1198 return (LRESULT
)ci
->hwndActiveChild
;
1200 case WM_MDIICONARRANGE
:
1201 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1202 ArrangeIconicWindows( hwnd
);
1203 ci
->sbRecalc
= SB_BOTH
+1;
1204 SendMessageW( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0 );
1207 case WM_MDIMAXIMIZE
:
1208 NtUserShowWindow( (HWND
)wParam
, SW_MAXIMIZE
);
1211 case WM_MDINEXT
: /* lParam != 0 means previous window */
1214 HWND next
= MDI_GetWindow( ci
, WIN_GetFullHandle( (HWND
)wParam
), !lParam
, 0 );
1216 HWND next
= MDI_GetWindow( ci
, (HWND
)wParam
, !lParam
, 0 );
1218 MDI_SwitchActiveChild( ci
, next
, TRUE
);
1223 SendMessageW( (HWND
)wParam
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
1227 return MDISetMenu( hwnd
, (HMENU
)wParam
, (HMENU
)lParam
);
1229 case WM_MDIREFRESHMENU
:
1230 return MDI_RefreshMenu( ci
);
1233 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1234 NtUserShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
1235 MDITile( hwnd
, ci
, wParam
);
1236 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1241 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1242 ScrollChildren( hwnd
, message
, wParam
, lParam
);
1243 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1247 if (ci
->hwndActiveChild
&& !IsIconic( ci
->hwndActiveChild
))
1248 NtUserSetFocus( ci
->hwndActiveChild
);
1252 if( ci
->hwndActiveChild
)
1253 SendMessageW(ci
->hwndActiveChild
, message
, wParam
, lParam
);
1256 case WM_PARENTNOTIFY
:
1257 switch (LOWORD(wParam
))
1260 if (GetWindowLongW((HWND
)lParam
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1263 ci
->child
= HeapAlloc(GetProcessHeap(), 0, sizeof(HWND
));
1265 ci
->child
= HeapReAlloc(GetProcessHeap(), 0, ci
->child
, sizeof(HWND
) * (ci
->nActiveChildren
+ 1));
1267 if (ci
->child
!= NULL
)
1269 ci
->child
[ci
->nActiveChildren
] = (HWND
)lParam
;
1270 ci
->nTotalCreated
++;
1271 ci
->nActiveChildren
++;
1276 case WM_LBUTTONDOWN
:
1280 pt
.x
= (short)LOWORD(lParam
);
1281 pt
.y
= (short)HIWORD(lParam
);
1282 child
= ChildWindowFromPoint(hwnd
, pt
);
1284 TRACE("notification from %p (%li,%li)\n",child
,pt
.x
,pt
.y
);
1286 if( child
&& child
!= hwnd
&& child
!= ci
->hwndActiveChild
)
1287 NtUserSetWindowPos(child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1294 if( IsWindow(ci
->hwndActiveChild
) && IsZoomed(ci
->hwndActiveChild
) &&
1295 (GetWindowLongW(ci
->hwndActiveChild
, GWL_STYLE
) & WS_VISIBLE
) )
1301 rect
.right
= LOWORD(lParam
);
1302 rect
.bottom
= HIWORD(lParam
);
1304 AdjustWindowRectEx(&rect
, GetWindowLongA(ci
->hwndActiveChild
, GWL_STYLE
),
1305 0, GetWindowLongA(ci
->hwndActiveChild
, GWL_EXSTYLE
) );
1306 NtUserMoveWindow(ci
->hwndActiveChild
, rect
.left
, rect
.top
,
1307 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 1);
1310 MDI_PostUpdate(hwnd
, ci
, SB_BOTH
+1);
1314 case WM_MDICALCCHILDSCROLL
:
1315 if( (ci
->mdiFlags
& MDIF_NEEDUPDATE
) && ci
->sbRecalc
)
1317 CalcChildScroll(hwnd
, ci
->sbRecalc
-1);
1319 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1323 return unicode
? DefWindowProcW( hwnd
, message
, wParam
, lParam
) :
1324 DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1327 /***********************************************************************
1330 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1332 if (!IsWindow(hwnd
)) return 0;
1333 return MDIClientWndProc_common( hwnd
, message
, wParam
, lParam
, FALSE
);
1336 /***********************************************************************
1339 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1341 if (!IsWindow(hwnd
)) return 0;
1342 return MDIClientWndProc_common( hwnd
, message
, wParam
, lParam
, TRUE
);
1345 /***********************************************************************
1346 * DefFrameProcA (USER32.@)
1348 LRESULT WINAPI
DefFrameProcA( HWND hwnd
, HWND hwndMDIClient
,
1349 UINT message
, WPARAM wParam
, LPARAM lParam
)
1357 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, NULL
, 0 );
1358 LPWSTR text
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1361 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, text
, len
);
1362 MDI_UpdateFrameText( hwnd
, hwndMDIClient
, text
);
1363 HeapFree( GetProcessHeap(), 0, text
);
1365 return 1; /* success. FIXME: check text length */
1372 return DefFrameProcW( hwnd
, hwndMDIClient
, message
, wParam
, lParam
);
1375 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1379 /***********************************************************************
1380 * DefFrameProcW (USER32.@)
1382 LRESULT WINAPI
DefFrameProcW( HWND hwnd
, HWND hwndMDIClient
,
1383 UINT message
, WPARAM wParam
, LPARAM lParam
)
1385 MDICLIENTINFO
*ci
= get_client_info( hwndMDIClient
);
1387 TRACE("%p %p %04x (%s) %08lx %08lx\n", hwnd
, hwndMDIClient
, message
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1395 WORD id
= LOWORD(wParam
);
1396 /* check for possible syscommands for maximized MDI child */
1397 if (id
< ci
->idFirstChild
|| id
>= ci
->idFirstChild
+ ci
->nActiveChildren
)
1399 if( (id
- 0xf000) & 0xf00f ) break;
1400 if( !IsZoomed(ci
->hwndActiveChild
) ) break;
1404 if (!is_close_enabled(ci
->hwndActiveChild
, 0)) break;
1412 return SendMessageW( ci
->hwndActiveChild
, WM_SYSCOMMAND
,
1419 if (id
- ci
->idFirstChild
== MDI_MOREWINDOWSLIMIT
)
1420 /* User chose "More Windows..." */
1421 childHwnd
= MDI_MoreWindowsDialog(hwndMDIClient
);
1423 /* User chose one of the windows listed in the "Windows" menu */
1424 childHwnd
= MDI_GetChildByID(hwndMDIClient
, id
, ci
);
1427 SendMessageW( hwndMDIClient
, WM_MDIACTIVATE
, (WPARAM
)childHwnd
, 0 );
1433 SendMessageW(hwndMDIClient
, message
, wParam
, lParam
);
1437 MDI_UpdateFrameText( hwnd
, hwndMDIClient
, (LPWSTR
)lParam
);
1438 return 1; /* success. FIXME: check text length */
1441 NtUserSetFocus(hwndMDIClient
);
1445 NtUserMoveWindow(hwndMDIClient
, 0, 0, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1450 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1452 if (!IsIconic(hwnd
) && ci
->hwndActiveChild
&& !IsZoomed(ci
->hwndActiveChild
))
1454 /* control menu is between the frame system menu and
1455 * the first entry of menu bar */
1456 // WND *wndPtr = WIN_GetPtr(hwnd);
1458 if( (wParam
== VK_LEFT
&& GetMenu(hwnd
) == next_menu
->hmenuIn
) ||
1459 (wParam
== VK_RIGHT
&& GetSubMenu(GetMenu(hwnd
), 0) == next_menu
->hmenuIn
) )
1461 // WIN_ReleasePtr(wndPtr);
1462 // wndPtr = WIN_GetPtr(ci->hwndActiveChild);
1463 next_menu
->hmenuNext
= GetSubMenu(GetMenu(ci
->hwndActiveChild
), 0);
1464 next_menu
->hwndNext
= ci
->hwndActiveChild
;
1466 // WIN_ReleasePtr(wndPtr);
1473 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1476 /***********************************************************************
1477 * DefMDIChildProcA (USER32.@)
1479 LRESULT WINAPI
DefMDIChildProcA( HWND hwnd
, UINT message
,
1480 WPARAM wParam
, LPARAM lParam
)
1482 HWND client
= GetParent(hwnd
);
1483 MDICLIENTINFO
*ci
= get_client_info( client
);
1485 TRACE("%p %04x (%s) %08lx %08lx\n", hwnd
, message
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1487 hwnd
= WIN_GetFullHandle( hwnd
);
1489 if (!ci
) return DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1494 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1495 if( ci
->hwndActiveChild
== hwnd
&& IsZoomed(ci
->hwndActiveChild
) )
1496 MDI_UpdateFrameText( GetParent(client
), client
, NULL
);
1497 return 1; /* success. FIXME: check text length */
1499 case WM_GETMINMAXINFO
:
1503 case WM_CHILDACTIVATE
:
1513 return DefMDIChildProcW( hwnd
, message
, wParam
, lParam
);
1515 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1519 /***********************************************************************
1520 * DefMDIChildProcW (USER32.@)
1522 LRESULT WINAPI
DefMDIChildProcW( HWND hwnd
, UINT message
,
1523 WPARAM wParam
, LPARAM lParam
)
1525 HWND client
= GetParent(hwnd
);
1526 MDICLIENTINFO
*ci
= get_client_info( client
);
1528 TRACE("%p %04x (%s) %08lx %08lx\n", hwnd
, message
, SPY_GetMsgName(message
, hwnd
), wParam
, lParam
);
1530 hwnd
= WIN_GetFullHandle( hwnd
);
1532 if (!ci
) return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1537 DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1538 if( ci
->hwndActiveChild
== hwnd
&& IsZoomed(ci
->hwndActiveChild
) )
1539 MDI_UpdateFrameText( GetParent(client
), client
, NULL
);
1540 return 1; /* success. FIXME: check text length */
1542 case WM_GETMINMAXINFO
:
1543 MDI_ChildGetMinMaxInfo( client
, hwnd
, (MINMAXINFO
*)lParam
);
1547 return 0x00010000; /* MDI children don't have menu bars */
1550 SendMessageW( client
, WM_MDIDESTROY
, (WPARAM
)hwnd
, 0 );
1553 case WM_CHILDACTIVATE
:
1554 MDI_ChildActivate( client
, hwnd
);
1561 if( ci
->hwndActiveChild
== hwnd
&& IsZoomed(ci
->hwndActiveChild
))
1568 if (ci
->hwndActiveChild
== hwnd
&& IsZoomed(ci
->hwndActiveChild
))
1569 return SendMessageW( GetParent(client
), message
, wParam
, lParam
);
1572 SendMessageW( client
, WM_MDINEXT
, 0, 0);
1575 SendMessageW( client
, WM_MDINEXT
, 0, 1);
1584 if (IsZoomed(ci
->hwndActiveChild
)) ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1585 else MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1589 if( hwnd
== ci
->hwndActiveChild
)
1591 if( wParam
== SIZE_MAXIMIZED
)
1593 TRACE("maximizing child %p\n", hwnd
);
1595 MDI_AugmentFrameMenu( GetParent(client
), hwnd
);
1598 MDI_RestoreFrameMenu( GetParent(client
), hwnd
, ci
->hBmpClose
);
1601 MDI_UpdateFrameText( GetParent(client
), client
, NULL
);
1602 MDI_RefreshMenu(ci
);
1603 MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1608 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1609 HWND parent
= GetParent(client
);
1611 if( wParam
== VK_LEFT
) /* switch to frame system menu */
1613 // WND *wndPtr = WIN_GetPtr( parent );
1614 next_menu
->hmenuNext
= GetSubMenu( GetMenu(parent
), 0 );
1615 // WIN_ReleasePtr( wndPtr );
1617 if( wParam
== VK_RIGHT
) /* to frame menu bar */
1619 next_menu
->hmenuNext
= GetMenu(parent
);
1621 next_menu
->hwndNext
= parent
;
1628 SendMessageW( hwnd
, WM_SYSCOMMAND
, (WPARAM
)SC_KEYMENU
, (DWORD
)VK_SPACE
);
1634 /* Remove itself from the Window menu */
1635 MDI_RefreshMenu(ci
);
1638 return DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1641 /**********************************************************************
1642 * CreateMDIWindowA (USER32.@) Creates a MDI child
1645 * Success: Handle to created window
1648 HWND WINAPI
CreateMDIWindowA(
1649 LPCSTR lpClassName
, /* [in] Pointer to registered child class name */
1650 LPCSTR lpWindowName
, /* [in] Pointer to window name */
1651 DWORD dwStyle
, /* [in] Window style */
1652 INT X
, /* [in] Horizontal position of window */
1653 INT Y
, /* [in] Vertical position of window */
1654 INT nWidth
, /* [in] Width of window */
1655 INT nHeight
, /* [in] Height of window */
1656 HWND hWndParent
, /* [in] Handle to parent window */
1657 HINSTANCE hInstance
, /* [in] Handle to application instance */
1658 LPARAM lParam
) /* [in] Application-defined value */
1660 TRACE("(%s,%s,%08lx,%d,%d,%d,%d,%p,%p,%08lx)\n",
1661 debugstr_a(lpClassName
),debugstr_a(lpWindowName
),dwStyle
,X
,Y
,
1662 nWidth
,nHeight
,hWndParent
,hInstance
,lParam
);
1664 return CreateWindowExA(WS_EX_MDICHILD
, lpClassName
, lpWindowName
,
1665 dwStyle
, X
, Y
, nWidth
, nHeight
, hWndParent
,
1666 0, hInstance
, (LPVOID
)lParam
);
1669 /***********************************************************************
1670 * CreateMDIWindowW (USER32.@) Creates a MDI child
1673 * Success: Handle to created window
1676 HWND WINAPI
CreateMDIWindowW(
1677 LPCWSTR lpClassName
, /* [in] Pointer to registered child class name */
1678 LPCWSTR lpWindowName
, /* [in] Pointer to window name */
1679 DWORD dwStyle
, /* [in] Window style */
1680 INT X
, /* [in] Horizontal position of window */
1681 INT Y
, /* [in] Vertical position of window */
1682 INT nWidth
, /* [in] Width of window */
1683 INT nHeight
, /* [in] Height of window */
1684 HWND hWndParent
, /* [in] Handle to parent window */
1685 HINSTANCE hInstance
, /* [in] Handle to application instance */
1686 LPARAM lParam
) /* [in] Application-defined value */
1688 TRACE("(%s,%s,%08lx,%d,%d,%d,%d,%p,%p,%08lx)\n",
1689 debugstr_w(lpClassName
), debugstr_w(lpWindowName
), dwStyle
, X
, Y
,
1690 nWidth
, nHeight
, hWndParent
, hInstance
, lParam
);
1692 return CreateWindowExW(WS_EX_MDICHILD
, lpClassName
, lpWindowName
,
1693 dwStyle
, X
, Y
, nWidth
, nHeight
, hWndParent
,
1694 0, hInstance
, (LPVOID
)lParam
);
1697 /**********************************************************************
1698 * TranslateMDISysAccel (USER32.@)
1700 BOOL WINAPI
TranslateMDISysAccel( HWND hwndClient
, LPMSG msg
)
1702 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
)
1704 MDICLIENTINFO
*ci
= get_client_info( hwndClient
);
1707 if (!ci
|| !IsWindowEnabled(ci
->hwndActiveChild
)) return 0;
1709 /* translate if the Ctrl key is down and Alt not. */
1711 if( (GetKeyState(VK_CONTROL
) & 0x8000) && !(GetKeyState(VK_MENU
) & 0x8000))
1713 switch( msg
->wParam
)
1717 wParam
= ( GetKeyState(VK_SHIFT
) & 0x8000 ) ? SC_NEXTWINDOW
: SC_PREVWINDOW
;
1721 if (is_close_enabled(ci
->hwndActiveChild
, 0))
1730 TRACE("wParam = %04lx\n", wParam
);
1731 SendMessageW(ci
->hwndActiveChild
, WM_SYSCOMMAND
, wParam
, (LPARAM
)msg
->wParam
);
1735 return 0; /* failure */
1738 /***********************************************************************
1739 * CalcChildScroll (USER32.@)
1741 void WINAPI
CalcChildScroll( HWND hwnd
, INT scroll
)
1744 RECT childRect
, clientRect
;
1746 WINDOWINFO WindowInfo
;
1748 GetClientRect( hwnd
, &clientRect
);
1749 SetRectEmpty( &childRect
);
1751 /* The rectangle returned by GetClientRect always has 0,0 as top left
1752 * because it is in client coordinates. The rectangles returned by
1753 * GetWindowRect are in screen coordinates to make this complicated.
1755 * Apparently (in ReactOS at least) the rcClient returned by GetWindowInfo
1756 * is in screen coordinates too.
1758 WindowInfo
.cbSize
= sizeof(WindowInfo
);
1759 if (!GetWindowInfo(hwnd
, &WindowInfo
))
1761 ERR("Can't get window info\n");
1765 if ((list
= WIN_ListChildren( hwnd
)))
1768 for (i
= 0; list
[i
]; i
++)
1770 DWORD style
= GetWindowLongW( list
[i
], GWL_STYLE
);
1771 if (style
& WS_MAXIMIZE
)
1773 HeapFree( GetProcessHeap(), 0, list
);
1774 NtUserShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
1777 if (style
& WS_VISIBLE
)
1780 GetWindowRect( list
[i
], &rect
);
1781 OffsetRect(&rect
, -WindowInfo
.rcClient
.left
,
1782 -WindowInfo
.rcClient
.top
);
1783 UnionRect( &childRect
, &rect
, &childRect
);
1786 HeapFree( GetProcessHeap(), 0, list
);
1788 MapWindowPoints( 0, hwnd
, (POINT
*)&childRect
, 2 );
1789 UnionRect( &childRect
, &clientRect
, &childRect
);
1791 /* set common info values */
1792 info
.cbSize
= sizeof(info
);
1793 info
.fMask
= SIF_POS
| SIF_RANGE
| SIF_PAGE
;
1795 /* set the specific */
1796 /* Note how we set nPos to 0 because we scroll the clients instead of
1797 * the window, and we set nPage to 1 bigger than the clientRect because
1798 * otherwise the scrollbar never disables. This causes a somewhat ugly
1799 * effect though while scrolling.
1805 info
.nMin
= childRect
.left
;
1806 info
.nMax
= childRect
.right
;
1808 info
.nPage
= 1 + clientRect
.right
- clientRect
.left
;
1809 SetScrollInfo(hwnd
, SB_HORZ
, &info
, TRUE
);
1810 if (scroll
== SB_HORZ
) break;
1813 info
.nMin
= childRect
.top
;
1814 info
.nMax
= childRect
.bottom
;
1816 info
.nPage
= 1 + clientRect
.bottom
- clientRect
.top
;
1817 SetScrollInfo(hwnd
, SB_VERT
, &info
, TRUE
);
1823 /***********************************************************************
1824 * ScrollChildren (USER32.@)
1826 void WINAPI
ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
,
1830 INT curPos
, length
, minPos
, maxPos
, shift
;
1833 GetClientRect( hWnd
, &rect
);
1838 GetScrollRange(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
1839 curPos
= GetScrollPos(hWnd
,SB_HORZ
);
1840 length
= (rect
.right
- rect
.left
) / 2;
1841 shift
= GetSystemMetrics(SM_CYHSCROLL
);
1844 GetScrollRange(hWnd
,SB_VERT
,&minPos
,&maxPos
);
1845 curPos
= GetScrollPos(hWnd
,SB_VERT
);
1846 length
= (rect
.bottom
- rect
.top
) / 2;
1847 shift
= GetSystemMetrics(SM_CXVSCROLL
);
1856 newPos
= curPos
- shift
;
1859 newPos
= curPos
+ shift
;
1862 newPos
= curPos
- length
;
1865 newPos
= curPos
+ length
;
1868 case SB_THUMBPOSITION
:
1869 newPos
= LOWORD(lParam
);
1882 CalcChildScroll(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
1886 if( newPos
> maxPos
)
1889 if( newPos
< minPos
)
1892 SetScrollPos(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
1894 if( uMsg
== WM_VSCROLL
)
1895 ScrollWindowEx(hWnd
,0 ,curPos
- newPos
, NULL
, NULL
, 0, NULL
,
1896 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
1898 ScrollWindowEx(hWnd
,curPos
- newPos
, 0, NULL
, NULL
, 0, NULL
,
1899 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
1903 /******************************************************************************
1904 * CascadeWindows (USER32.@) Cascades MDI child windows
1907 * Success: Number of cascaded windows.
1911 CascadeWindows (HWND hwndParent
, UINT wFlags
, LPCRECT lpRect
,
1912 UINT cKids
, const HWND
*lpKids
)
1914 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
1919 /******************************************************************************
1920 * TileWindows (USER32.@) Tiles MDI child windows
1923 * Success: Number of tiled windows.
1927 TileWindows (HWND hwndParent
, UINT wFlags
, LPCRECT lpRect
,
1928 UINT cKids
, const HWND
*lpKids
)
1930 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
1934 /************************************************************************
1935 * "More Windows..." functionality
1938 /* MDI_MoreWindowsDlgProc
1940 * This function will process the messages sent to the "More Windows..."
1942 * Return values: 0 = cancel pressed
1943 * HWND = ok pressed or double-click in the list...
1947 static INT_PTR WINAPI
MDI_MoreWindowsDlgProc (HWND hDlg
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
1956 MDICLIENTINFO
*ci
= get_client_info( (HWND
)lParam
);
1957 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
1959 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
1961 WCHAR buffer
[MDI_MAXTITLELENGTH
];
1963 if (!InternalGetWindowText( ci
->child
[i
], buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
1965 SendMessageW(hListBox
, LB_ADDSTRING
, 0, (LPARAM
)buffer
);
1966 SendMessageW(hListBox
, LB_SETITEMDATA
, i
, (LPARAM
)ci
->child
[i
] );
1967 length
= strlenW(buffer
); /* FIXME: should use GetTextExtentPoint */
1968 if (length
> widest
)
1971 /* Make sure the horizontal scrollbar scrolls ok */
1972 SendMessageW(hListBox
, LB_SETHORIZONTALEXTENT
, widest
* 6, 0);
1974 /* Set the current selection */
1975 SendMessageW(hListBox
, LB_SETCURSEL
, MDI_MOREWINDOWSLIMIT
, 0);
1980 switch (LOWORD(wParam
))
1983 if (HIWORD(wParam
) != LBN_DBLCLK
) break;
1987 /* windows are sorted by menu ID, so we must return the
1988 * window associated to the given id
1990 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
1991 UINT index
= SendMessageW(hListBox
, LB_GETCURSEL
, 0, 0);
1992 LRESULT res
= SendMessageW(hListBox
, LB_GETITEMDATA
, index
, 0);
1993 EndDialog(hDlg
, res
);
2007 * MDI_MoreWindowsDialog
2009 * Prompts the user with a listbox containing the opened
2010 * documents. The user can then choose a windows and click
2011 * on OK to set the current window to the one selected, or
2012 * CANCEL to cancel. The function returns a handle to the
2016 static HWND
MDI_MoreWindowsDialog(HWND hwnd
)
2022 hRes
= FindResourceA(User32Instance
, "MDI_MOREWINDOWS", (LPSTR
)RT_DIALOG
);
2027 hDlgTmpl
= LoadResource(User32Instance
, hRes
);
2032 template = LockResource( hDlgTmpl
);
2037 return (HWND
) DialogBoxIndirectParamA(User32Instance
,
2038 (const DLGTEMPLATE
*) template,
2039 hwnd
, MDI_MoreWindowsDlgProc
, (LPARAM
) hwnd
);