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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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.
96 #include "wine/unicode.h"
99 #include "nonclient.h"
100 #include "controls.h"
102 #include "struct32.h"
104 #include "user32/regcontrol.h"
107 #include "wine/debug.h"
110 WINE_DEFAULT_DEBUG_CHANNEL(mdi
);
112 #define MDI_MAXLISTLENGTH 0x40
113 #define MDI_MAXTITLELENGTH 0xa1
115 #define MDI_NOFRAMEREPAINT 0
116 #define MDI_REPAINTFRAMENOW 1
117 #define MDI_REPAINTFRAME 2
119 #define WM_MDICALCCHILDSCROLL 0x10ac /* this is exactly what Windows uses */
121 /* "More Windows..." definitions */
122 #define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
123 option will appear under the Windows menu */
124 #define MDI_IDC_LISTBOX 100
125 #define IDS_MDI_MOREWINDOWS 13
127 #define MDIF_NEEDUPDATE 0x0001
131 UINT nActiveChildren
;
132 HWND hwndChildMaximized
;
133 HWND hwndActiveChild
;
139 UINT sbRecalc
; /* SB_xxx flags for scrollbar fixup */
142 static HBITMAP hBmpClose
= 0;
144 /* ----------------- declarations ----------------- */
145 static void MDI_UpdateFrameText( HWND
, HWND
, BOOL
, LPCWSTR
);
146 static BOOL
MDI_AugmentFrameMenu( HWND
, HWND
);
147 static BOOL
MDI_RestoreFrameMenu( HWND
, HWND
);
148 static LONG
MDI_ChildActivate( HWND
, HWND
);
150 static HWND
MDI_MoreWindowsDialog(HWND
);
151 static void MDI_SwapMenuItems(HWND
, UINT
, UINT
);
152 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
153 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
156 void WINAPI
ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
157 void WINAPI
CalcChildScroll(HWND hwnd
, INT scroll
);
159 BOOL CALLBACK
MDI_GetChildByID_EnumProc (HWND hwnd
, LPARAM lParam
)
161 DWORD
*control
= (DWORD
*)lParam
;
162 if(*control
== GetWindowLongW( hwnd
, GWL_ID
))
164 *control
= (DWORD
)hwnd
;
171 /* -------- Miscellaneous service functions ----------
175 static HWND
MDI_GetChildByID(HWND hwnd
, UINT id
)
179 if (hwnd
&& !EnumChildWindows(hwnd
, (ENUMWINDOWSPROC
)&MDI_GetChildByID_EnumProc
, (LPARAM
)&Control
))
181 return (HWND
)Control
;
189 if (!(win_array
= WIN_ListChildren( hwnd
))) return 0;
190 for (i
= 0; win_array
[i
]; i
++)
192 if (GetWindowLongA( win_array
[i
], GWL_ID
) == id
) break;
195 HeapFree( GetProcessHeap(), 0, win_array
);
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 MDIClientWndProcW
, /* procW */
219 MDIClientWndProcA
, /* procA */
220 sizeof(MDICLIENTINFO
*), /* extra */
221 IDC_ARROW
, /* cursor */
222 (HBRUSH
)(COLOR_APPWORKSPACE
+1) /* brush */
226 static MDICLIENTINFO
*get_client_info( HWND client
)
229 return (MDICLIENTINFO
*)GetWindowLongPtr(client
, 0);
231 MDICLIENTINFO
*ret
= NULL
;
232 WND
*win
= WIN_GetPtr( client
);
235 if (win
== WND_OTHER_PROCESS
)
237 ERR( "client %p belongs to other process\n", client
);
240 if (win
->cbWndExtra
< sizeof(MDICLIENTINFO
)) WARN( "%p is not an MDI client\n", client
);
241 else ret
= (MDICLIENTINFO
*)win
->wExtra
;
242 WIN_ReleasePtr( win
);
248 /**********************************************************************
251 static void MDI_MenuModifyItem( HWND client
, HWND hWndChild
)
253 MDICLIENTINFO
*clientInfo
= get_client_info( client
);
257 if (!clientInfo
|| !clientInfo
->hWindowMenu
) return;
259 id
= GetWindowLongA( hWndChild
, GWL_ID
);
260 if (id
>= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
) return;
262 buffer
[1] = '1' + id
- clientInfo
->idFirstChild
;
264 GetWindowTextW( hWndChild
, buffer
+ 3, sizeof(buffer
)/sizeof(WCHAR
) - 3 );
266 n
= GetMenuState(clientInfo
->hWindowMenu
, id
, MF_BYCOMMAND
);
267 ModifyMenuW(clientInfo
->hWindowMenu
, id
, MF_BYCOMMAND
| MF_STRING
, id
, buffer
);
268 CheckMenuItem(clientInfo
->hWindowMenu
, id
, n
& MF_CHECKED
);
271 /**********************************************************************
274 static BOOL
MDI_MenuDeleteItem( HWND client
, HWND hWndChild
)
277 static const WCHAR format
[] = {'&','%','d',' ',0};
278 MDICLIENTINFO
*clientInfo
= get_client_info( client
);
281 if( !clientInfo
->nActiveChildren
|| !clientInfo
->hWindowMenu
)
284 id
= GetWindowLongA( hWndChild
, GWL_ID
);
285 DeleteMenu(clientInfo
->hWindowMenu
,id
,MF_BYCOMMAND
);
287 /* walk the rest of MDI children to prevent gaps in the id
288 * sequence and in the menu child list */
290 for( index
= id
+1; index
<= clientInfo
->nActiveChildren
+
291 clientInfo
->idFirstChild
; index
++ )
293 HWND hwnd
= MDI_GetChildByID(client
,index
);
296 TRACE("no window for id=%i\n",index
);
301 SetWindowLongW( hwnd
, GWL_ID
, GetWindowLongW( hwnd
, GWL_ID
) - 1 );
303 n
= wsprintfW(buffer
, format
,index
- clientInfo
->idFirstChild
);
304 GetWindowTextW( hwnd
, buffer
+ n
, sizeof(buffer
)/sizeof(WCHAR
) - n
);
306 /* change menu if the current child is to be shown in the
309 if (index
<= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
)
310 ModifyMenuW(clientInfo
->hWindowMenu
,index
,MF_BYCOMMAND
| MF_STRING
,
311 index
- 1 , buffer
);
314 /* We must restore the "More Windows..." option if there are enough children
316 if (clientInfo
->nActiveChildren
- 1 > MDI_MOREWINDOWSLIMIT
)
319 LoadStringW(GetModuleHandleA("USER32"), IDS_MDI_MOREWINDOWS
, szTmp
, sizeof(szTmp
)/sizeof(szTmp
[0]));
320 AppendMenuW(clientInfo
->hWindowMenu
, MF_STRING
, clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
, szTmp
);
325 /**********************************************************************
328 * returns "activateable" child different from the current or zero
330 static HWND
MDI_GetWindow(MDICLIENTINFO
*clientInfo
, HWND hWnd
, BOOL bNext
,
341 dwStyleMask
|= WS_DISABLED
| WS_VISIBLE
;
342 if( !hWnd
) hWnd
= clientInfo
->hwndActiveChild
;
344 if (!(list
= WIN_ListChildren( GetParent(hWnd
) ))) return 0;
346 /* start from next after hWnd */
347 while (list
[i
] && list
[i
] != hWnd
) i
++;
350 for ( ; list
[i
]; i
++)
352 if (GetWindow( list
[i
], GW_OWNER
)) continue;
353 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
355 if (bNext
) goto found
;
357 /* now restart from the beginning */
358 for (i
= 0; list
[i
] && list
[i
] != hWnd
; i
++)
360 if (GetWindow( list
[i
], GW_OWNER
)) continue;
361 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
363 if (bNext
) goto found
;
366 HeapFree( GetProcessHeap(), 0, list
);
371 /**********************************************************************
372 * MDI_CalcDefaultChildPos
374 * It seems that the default height is about 2/3 of the client rect
376 static void MDI_CalcDefaultChildPos( HWND hwnd
, WORD n
, LPPOINT lpPos
, INT delta
)
380 INT spacing
= GetSystemMetrics(SM_CYCAPTION
) +
381 GetSystemMetrics(SM_CYFRAME
) - 1;
383 GetClientRect( hwnd
, &rect
);
384 if( rect
.bottom
- rect
.top
- delta
>= spacing
)
385 rect
.bottom
-= delta
;
387 nstagger
= (rect
.bottom
- rect
.top
)/(3 * spacing
);
388 lpPos
[1].x
= (rect
.right
- rect
.left
- nstagger
* spacing
);
389 lpPos
[1].y
= (rect
.bottom
- rect
.top
- nstagger
* spacing
);
390 lpPos
[0].x
= lpPos
[0].y
= spacing
* (n
%(nstagger
+1));
393 /**********************************************************************
396 static LRESULT
MDISetMenu( HWND hwnd
, HMENU hmenuFrame
,
400 HWND hwndFrame
= GetParent(hwnd
);
401 HMENU oldFrameMenu
= GetMenu(hwndFrame
);
403 TRACE("%p %p %p\n", hwnd
, hmenuFrame
, hmenuWindow
);
405 if (hmenuFrame
&& !IsMenu(hmenuFrame
))
407 WARN("hmenuFrame is not a menu handle\n");
411 if (hmenuWindow
&& !IsMenu(hmenuWindow
))
413 WARN("hmenuWindow is not a menu handle\n");
417 if (!(ci
= get_client_info( hwnd
))) return 0;
419 if( ci
->hwndChildMaximized
&& hmenuFrame
&& hmenuFrame
!=oldFrameMenu
)
420 MDI_RestoreFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
422 if( hmenuWindow
&& hmenuWindow
!= ci
->hWindowMenu
)
424 /* delete menu items from ci->hWindowMenu
425 * and add them to hmenuWindow */
426 /* Agent newsreader calls this function with ci->hWindowMenu == NULL */
427 if( ci
->hWindowMenu
&& ci
->nActiveChildren
)
430 LPWSTR buffer
= NULL
;
432 INT nbWindowsMenuItems
; /* num of documents shown + "More Windows..." if present */
433 INT i
= GetMenuItemCount(ci
->hWindowMenu
) - 1;
434 INT pos
= GetMenuItemCount(hmenuWindow
) + 1;
436 AppendMenuA( hmenuWindow
, MF_SEPARATOR
, 0, NULL
);
438 if (ci
->nActiveChildren
<= MDI_MOREWINDOWSLIMIT
)
439 nbWindowsMenuItems
= ci
->nActiveChildren
;
441 nbWindowsMenuItems
= MDI_MOREWINDOWSLIMIT
+ 1;
443 j
= i
- nbWindowsMenuItems
+ 1;
445 for( ; i
>= j
; i
-- )
447 memset(&mii
, 0, sizeof(mii
));
448 mii
.cbSize
= sizeof(mii
);
449 mii
.fMask
= MIIM_CHECKMARKS
| MIIM_DATA
| MIIM_ID
| MIIM_STATE
450 | MIIM_SUBMENU
| MIIM_TYPE
| MIIM_BITMAP
;
452 GetMenuItemInfoW(ci
->hWindowMenu
, i
, TRUE
, &mii
);
453 if(mii
.cch
) { /* Menu is MFT_STRING */
454 mii
.cch
++; /* add room for '\0' */
455 buffer
= HeapAlloc(GetProcessHeap(), 0,
456 mii
.cch
* sizeof(WCHAR
));
457 mii
.dwTypeData
= buffer
;
458 GetMenuItemInfoW(ci
->hWindowMenu
, i
, TRUE
, &mii
);
460 DeleteMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
461 InsertMenuItemW(hmenuWindow
, pos
, TRUE
, &mii
);
463 HeapFree(GetProcessHeap(), 0, buffer
);
467 /* remove separator */
468 DeleteMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
470 ci
->hWindowMenu
= hmenuWindow
;
475 SetMenu(hwndFrame
, hmenuFrame
);
476 if( hmenuFrame
!=oldFrameMenu
)
478 if( ci
->hwndChildMaximized
)
479 MDI_AugmentFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
480 return (LRESULT
)oldFrameMenu
;
485 HMENU menu
= GetMenu( GetParent(hwnd
) );
486 INT nItems
= GetMenuItemCount(menu
) - 1;
487 UINT iId
= GetMenuItemID(menu
,nItems
) ;
489 if( !(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
491 /* SetMenu() may already have been called, meaning that this window
492 * already has its menu. But they may have done a SetMenu() on
493 * an MDI window, and called MDISetMenu() after the fact, meaning
494 * that the "if" to this "else" wouldn't catch the need to
495 * augment the frame menu.
497 if( ci
->hwndChildMaximized
)
498 MDI_AugmentFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
504 /**********************************************************************
507 static LRESULT
MDIRefreshMenu( HWND hwnd
, HMENU hmenuFrame
,
510 HWND hwndFrame
= GetParent(hwnd
);
511 HMENU oldFrameMenu
= GetMenu(hwndFrame
);
513 TRACE("%p %p %p\n", hwnd
, hmenuFrame
, hmenuWindow
);
515 FIXME("partially function stub\n");
517 return (LRESULT
)oldFrameMenu
;
521 /* ------------------ MDI child window functions ---------------------- */
524 /**********************************************************************
527 static HWND
MDICreateChild( HWND parent
, MDICLIENTINFO
*ci
,
528 LPMDICREATESTRUCTA cs
, BOOL unicode
)
531 DWORD style
= cs
->style
| (WS_CHILD
| WS_CLIPSIBLINGS
);
532 HWND hwnd
, hwndMax
= 0;
533 UINT wIDmenu
= ci
->idFirstChild
+ ci
->nActiveChildren
;
537 static const WCHAR lpstrDef
[] = {'j','u','n','k','!',0};
539 TRACE("origin %i,%i - dim %i,%i, style %08lx\n",
540 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, cs
->style
);
541 /* calculate placement */
542 MDI_CalcDefaultChildPos(parent
, ci
->nTotalCreated
++, pos
, 0);
545 if (cs
->cx
== CW_USEDEFAULT
|| cs
->cx
== CW_USEDEFAULT16
|| !cs
->cx
) cs
->cx
= pos
[1].x
;
546 if (cs
->cy
== CW_USEDEFAULT
|| cs
->cy
== CW_USEDEFAULT16
|| !cs
->cy
) cs
->cy
= pos
[1].y
;
548 if (cs
->x
== CW_USEDEFAULT
|| cs
->x
== CW_USEDEFAULT16
)
550 if (cs
->cx
== CW_USEDEFAULT
|| !cs
->cx
) cs
->cx
= pos
[1].x
;
551 if (cs
->cy
== CW_USEDEFAULT
|| !cs
->cy
) cs
->cy
= pos
[1].y
;
553 if (cs
->x
== CW_USEDEFAULT
)
560 /* restore current maximized child */
561 if( (style
& WS_VISIBLE
) && ci
->hwndChildMaximized
)
563 TRACE("Restoring current maximized child %p\n", ci
->hwndChildMaximized
);
564 if( style
& WS_MAXIMIZE
)
565 SendMessageW(parent
, WM_SETREDRAW
, FALSE
, 0L);
566 hwndMax
= ci
->hwndChildMaximized
;
567 ShowWindow( hwndMax
, SW_SHOWNOACTIVATE
);
568 if( style
& WS_MAXIMIZE
)
569 SendMessageW(parent
, WM_SETREDRAW
, TRUE
, 0L);
572 if (ci
->nActiveChildren
<= MDI_MOREWINDOWSLIMIT
)
573 /* this menu is needed to set a check mark in MDI_ChildActivate */
574 if (ci
->hWindowMenu
!= 0)
575 AppendMenuW(ci
->hWindowMenu
, MF_STRING
, wIDmenu
, lpstrDef
);
577 ci
->nActiveChildren
++;
579 /* fix window style */
581 wndParent
= WIN_FindWndPtr( parent
);
582 if( !(wndParent
->dwStyle
& MDIS_ALLCHILDSTYLES
) )
584 if( !(GetWindowLong(parent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
) )
587 TRACE("MDIS_ALLCHILDSTYLES is missing, fixing window style\n");
588 style
&= (WS_CHILD
| WS_CLIPSIBLINGS
| WS_MINIMIZE
| WS_MAXIMIZE
|
589 WS_CLIPCHILDREN
| WS_DISABLED
| WS_VSCROLL
| WS_HSCROLL
);
590 style
|= (WS_VISIBLE
| WS_OVERLAPPEDWINDOW
);
594 if( wndParent
->flags
& WIN_ISWIN32
)
598 WIN_ReleaseWndPtr( wndParent
);
602 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)cs
;
603 hwnd
= CreateWindowW( csW
->szClass
, csW
->szTitle
, style
,
604 csW
->x
, csW
->y
, csW
->cx
, csW
->cy
, parent
,
605 (HMENU
)wIDmenu
, csW
->hOwner
, csW
);
608 hwnd
= CreateWindowA( cs
->szClass
, cs
->szTitle
, style
,
609 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, parent
,
610 (HMENU
)wIDmenu
, cs
->hOwner
, cs
);
615 MDICREATESTRUCT16 cs16
;
616 SEGPTR title
, cls
, seg_cs16
;
618 WIN_ReleaseWndPtr( wndParent
);
619 STRUCT32_MDICREATESTRUCT32Ato16( cs
, &cs16
);
620 cs16
.szTitle
= title
= MapLS( cs
->szTitle
);
621 cs16
.szClass
= cls
= MapLS( cs
->szClass
);
622 seg_cs16
= MapLS( &cs16
);
623 hwnd
= WIN_Handle32( CreateWindow16( cs
->szClass
, cs
->szTitle
, style
,
624 cs16
.x
, cs16
.y
, cs16
.cx
, cs16
.cy
,
625 HWND_16(parent
), (HMENU16
)wIDmenu
,
626 cs16
.hOwner
, (LPVOID
)seg_cs16
));
633 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
637 /* All MDI child windows have the WS_EX_MDICHILD style */
638 SetWindowLongW( hwnd
, GWL_EXSTYLE
, GetWindowLongW( hwnd
, GWL_EXSTYLE
) | WS_EX_MDICHILD
);
640 /* If we have more than 9 windows, we must insert the new one at the
641 * 9th position in order to see it in the "Windows" menu
643 if (ci
->nActiveChildren
> MDI_MOREWINDOWSLIMIT
)
644 MDI_SwapMenuItems( parent
, GetWindowLongW( hwnd
, GWL_ID
),
645 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1);
647 MDI_MenuModifyItem(parent
, hwnd
);
649 /* Have we hit the "More Windows..." limit? If so, we must
650 * add a "More Windows..." option
652 if (ci
->nActiveChildren
== MDI_MOREWINDOWSLIMIT
+ 1)
655 LoadStringW(GetModuleHandleA("USER32"), IDS_MDI_MOREWINDOWS
, szTmp
, sizeof(szTmp
)/sizeof(szTmp
[0]));
657 ModifyMenuW(ci
->hWindowMenu
,
658 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
,
659 MF_BYCOMMAND
| MF_STRING
,
660 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
,
664 if( IsIconic(hwnd
) && ci
->hwndActiveChild
)
666 TRACE("Minimizing created MDI child %p\n", hwnd
);
667 ShowWindow( hwnd
, SW_SHOWMINNOACTIVE
);
671 /* WS_VISIBLE is clear if a) the MDI client has
672 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
673 * MDICreateStruct. If so the created window is not shown nor
676 if (IsWindowVisible(hwnd
)) ShowWindow(hwnd
, SW_SHOW
);
678 TRACE("created child - %p\n",hwnd
);
682 ci
->nActiveChildren
--;
683 DeleteMenu(ci
->hWindowMenu
,wIDmenu
,MF_BYCOMMAND
);
684 if( IsWindow(hwndMax
) )
685 ShowWindow(hwndMax
, SW_SHOWMAXIMIZED
);
691 /**********************************************************************
692 * MDI_ChildGetMinMaxInfo
694 * Note: The rule here is that client rect of the maximized MDI child
695 * is equal to the client rect of the MDI client window.
697 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
701 GetClientRect( client
, &rect
);
702 AdjustWindowRectEx( &rect
, GetWindowLongW( hwnd
, GWL_STYLE
),
703 0, GetWindowLongW( hwnd
, GWL_EXSTYLE
));
705 lpMinMax
->ptMaxSize
.x
= rect
.right
-= rect
.left
;
706 lpMinMax
->ptMaxSize
.y
= rect
.bottom
-= rect
.top
;
708 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
709 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
711 TRACE("max rect (%ld,%ld - %ld, %ld)\n",
712 rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
715 /**********************************************************************
716 * MDI_SwitchActiveChild
718 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
721 static void MDI_SwitchActiveChild( HWND clientHwnd
, HWND childHwnd
,
726 MDICLIENTINFO
*ci
= get_client_info( clientHwnd
);
728 hwndTo
= MDI_GetWindow(ci
, childHwnd
, bNextWindow
, 0);
730 TRACE("from %p, to %p\n",childHwnd
,hwndTo
);
732 if ( !hwndTo
) return; /* no window to switch to */
734 hwndPrev
= ci
->hwndActiveChild
;
736 if ( hwndTo
!= hwndPrev
)
738 SetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0,
739 SWP_NOMOVE
| SWP_NOSIZE
);
741 if( bNextWindow
&& hwndPrev
)
742 SetWindowPos( hwndPrev
, HWND_BOTTOM
, 0, 0, 0, 0,
743 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
748 /**********************************************************************
751 static LRESULT
MDIDestroyChild( HWND parent
, MDICLIENTINFO
*ci
,
752 HWND child
, BOOL flagDestroy
)
754 if( child
== ci
->hwndActiveChild
)
756 MDI_SwitchActiveChild(parent
, child
, TRUE
);
758 if( child
== ci
->hwndActiveChild
)
760 ShowWindow( child
, SW_HIDE
);
761 if( child
== ci
->hwndChildMaximized
)
763 HWND frame
= GetParent(parent
);
764 MDI_RestoreFrameMenu( frame
, child
);
765 ci
->hwndChildMaximized
= 0;
766 MDI_UpdateFrameText( frame
, parent
, TRUE
, NULL
);
769 MDI_ChildActivate(parent
, 0);
773 MDI_MenuDeleteItem(parent
, child
);
775 ci
->nActiveChildren
--;
777 TRACE("child destroyed - %p\n",child
);
781 MDI_PostUpdate(GetParent(child
), ci
, SB_BOTH
+1);
782 DestroyWindow(child
);
788 /**********************************************************************
791 * Note: hWndChild is NULL when last child is being destroyed
793 static LONG
MDI_ChildActivate( HWND client
, HWND child
)
795 MDICLIENTINFO
*clientInfo
= get_client_info( client
);
796 HWND prevActiveWnd
= clientInfo
->hwndActiveChild
;
797 BOOL isActiveFrameWnd
;
799 if (child
&& (!IsWindowEnabled( child
))) return 0;
801 /* Don't activate if it is already active. Might happen
802 since ShowWindow DOES activate MDI children */
803 if (clientInfo
->hwndActiveChild
== child
) return 0;
805 TRACE("%p\n", child
);
807 isActiveFrameWnd
= (GetActiveWindow() == GetParent(client
));
809 /* deactivate prev. active child */
812 SetWindowLongA( prevActiveWnd
, GWL_STYLE
,
813 GetWindowLongA( prevActiveWnd
, GWL_STYLE
) | WS_SYSMENU
);
814 SendMessageA( prevActiveWnd
, WM_NCACTIVATE
, FALSE
, 0L );
815 SendMessageA( prevActiveWnd
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
816 /* uncheck menu item */
817 if( clientInfo
->hWindowMenu
)
819 UINT prevID
= GetWindowLongA( prevActiveWnd
, GWL_ID
);
821 if (prevID
- clientInfo
->idFirstChild
< MDI_MOREWINDOWSLIMIT
)
822 CheckMenuItem( clientInfo
->hWindowMenu
, prevID
, 0);
824 CheckMenuItem( clientInfo
->hWindowMenu
,
825 clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1, 0);
830 if (clientInfo
->hwndChildMaximized
&& clientInfo
->hwndChildMaximized
!= child
)
832 INT cmd
= SW_SHOWNORMAL
;
836 UINT state
= GetMenuState(GetSystemMenu(child
, FALSE
), SC_MAXIMIZE
, MF_BYCOMMAND
);
837 if (state
!= 0xFFFFFFFF && (state
& (MF_DISABLED
| MF_GRAYED
)))
838 SendMessageW(clientInfo
->hwndChildMaximized
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
840 cmd
= SW_SHOWMAXIMIZED
;
842 clientInfo
->hwndActiveChild
= child
;
845 ShowWindow( clientInfo
->hwndActiveChild
, cmd
);
848 clientInfo
->hwndActiveChild
= child
;
850 /* check if we have any children left */
853 if( isActiveFrameWnd
)
858 /* check menu item */
859 if( clientInfo
->hWindowMenu
)
861 UINT id
= GetWindowLongA( child
, GWL_ID
);
862 /* The window to be activated must be displayed in the "Windows" menu */
863 if (id
>= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
)
865 MDI_SwapMenuItems( GetParent(child
),
866 id
, clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1);
867 id
= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1;
868 MDI_MenuModifyItem( GetParent(child
), child
);
871 CheckMenuItem(clientInfo
->hWindowMenu
, id
, MF_CHECKED
);
873 /* bring active child to the top */
874 SetWindowPos( child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
876 if( isActiveFrameWnd
)
878 SendMessageA( child
, WM_NCACTIVATE
, TRUE
, 0L);
879 if( GetFocus() == client
)
880 SendMessageA( client
, WM_SETFOCUS
, (WPARAM
)client
, 0L );
884 SendMessageA( child
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
888 /* -------------------- MDI client window functions ------------------- */
890 /**********************************************************************
891 * CreateMDIMenuBitmap
893 static HBITMAP
CreateMDIMenuBitmap(void)
895 HDC hDCSrc
= CreateCompatibleDC(0);
896 HDC hDCDest
= CreateCompatibleDC(hDCSrc
);
897 HBITMAP hbClose
= LoadBitmapW(0, MAKEINTRESOURCEW(OBM_CLOSE
) );
899 HBITMAP hobjSrc
, hobjDest
;
901 hobjSrc
= SelectObject(hDCSrc
, hbClose
);
902 hbCopy
= CreateCompatibleBitmap(hDCSrc
,GetSystemMetrics(SM_CXSIZE
),GetSystemMetrics(SM_CYSIZE
));
903 hobjDest
= SelectObject(hDCDest
, hbCopy
);
905 BitBlt(hDCDest
, 0, 0, GetSystemMetrics(SM_CXSIZE
), GetSystemMetrics(SM_CYSIZE
),
906 hDCSrc
, GetSystemMetrics(SM_CXSIZE
), 0, SRCCOPY
);
908 SelectObject(hDCSrc
, hobjSrc
);
909 DeleteObject(hbClose
);
912 hobjSrc
= SelectObject( hDCDest
, GetStockObject(BLACK_PEN
) );
914 MoveToEx( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, 0, NULL
);
915 LineTo( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, GetSystemMetrics(SM_CYSIZE
) - 1);
917 SelectObject(hDCDest
, hobjSrc
);
918 SelectObject(hDCDest
, hobjDest
);
924 /**********************************************************************
927 static LONG
MDICascade( HWND client
, MDICLIENTINFO
*ci
)
934 BOOL has_icons
= FALSE
;
937 if (ci
->hwndChildMaximized
)
938 SendMessageA( client
, WM_MDIRESTORE
,
939 (WPARAM
)ci
->hwndChildMaximized
, 0);
941 if (ci
->nActiveChildren
== 0) return 0;
943 if (!(win_array
= WIN_ListChildren( client
))) return 0;
945 /* remove all the windows we don't want */
946 for (i
= total
= 0; win_array
[i
]; i
++)
948 if (!IsWindowVisible( win_array
[i
] )) continue;
949 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows */
950 if (IsIconic( win_array
[i
] ))
955 win_array
[total
++] = win_array
[i
];
957 win_array
[total
] = 0;
961 INT delta
= 0, n
= 0, i
;
963 if (has_icons
) delta
= GetSystemMetrics(SM_CYICONSPACING
) + GetSystemMetrics(SM_CYICON
);
965 /* walk the list (backwards) and move windows */
966 for (i
= total
- 1; i
>= 0; i
--)
968 TRACE("move %p to (%ld,%ld) size [%ld,%ld]\n",
969 win_array
[i
], pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
);
971 MDI_CalcDefaultChildPos(client
, n
++, pos
, delta
);
972 SetWindowPos( win_array
[i
], 0, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
,
973 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
976 HeapFree( GetProcessHeap(), 0, win_array
);
978 if (has_icons
) ArrangeIconicWindows( client
);
983 /**********************************************************************
986 static void MDITile( HWND client
, MDICLIENTINFO
*ci
, WPARAM wParam
)
994 BOOL has_icons
= FALSE
;
996 if (ci
->hwndChildMaximized
)
997 SendMessageA( client
, WM_MDIRESTORE
, (WPARAM
)ci
->hwndChildMaximized
, 0);
999 if (ci
->nActiveChildren
== 0) return;
1001 if (!(win_array
= WIN_ListChildren( client
))) return;
1003 /* remove all the windows we don't want */
1004 for (i
= total
= 0; win_array
[i
]; i
++)
1006 if (!IsWindowVisible( win_array
[i
] )) continue;
1007 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows (icon titles) */
1008 if (IsIconic( win_array
[i
] ))
1013 if ((wParam
& MDITILE_SKIPDISABLED
) && !IsWindowEnabled( win_array
[i
] )) continue;
1014 win_array
[total
++] = win_array
[i
];
1016 win_array
[total
] = 0;
1018 TRACE("%u windows to tile\n", total
);
1022 HWND
*pWnd
= win_array
;
1024 int x
, y
, xsize
, ysize
;
1025 int rows
, columns
, r
, c
, i
;
1027 GetClientRect(client
,&rect
);
1028 rows
= (int) sqrt((double)total
);
1029 columns
= total
/ rows
;
1031 if( wParam
& MDITILE_HORIZONTAL
) /* version >= 3.1 */
1034 rows
= columns
; /* exchange r and c */
1040 y
= rect
.bottom
- 2 * GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
1041 rect
.bottom
= ( y
- GetSystemMetrics(SM_CYICON
) < rect
.top
)? rect
.bottom
: y
;
1044 ysize
= rect
.bottom
/ rows
;
1045 xsize
= rect
.right
/ columns
;
1047 for (x
= i
= 0, c
= 1; c
<= columns
&& *pWnd
; c
++)
1052 ysize
= rect
.bottom
/ rows
;
1056 for (r
= 1; r
<= rows
&& *pWnd
; r
++, i
++)
1058 SetWindowPos(*pWnd
, 0, x
, y
, xsize
, ysize
,
1059 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
1066 HeapFree( GetProcessHeap(), 0, win_array
);
1067 if (has_icons
) ArrangeIconicWindows( client
);
1071 /* ----------------------- Frame window ---------------------------- */
1074 /**********************************************************************
1075 * MDI_AugmentFrameMenu
1077 static BOOL
MDI_AugmentFrameMenu( HWND frame
, HWND hChild
)
1079 HMENU menu
= GetMenu( frame
);
1081 WND
* child
= WIN_FindWndPtr(hChild
);
1083 HMENU hSysPopup
= 0;
1084 HBITMAP hSysMenuBitmap
= 0;
1086 TRACE("frame %p,child %p\n",frame
,hChild
);
1089 if( !menu
|| !child
->hSysMenu
)
1091 WIN_ReleaseWndPtr(child
);
1094 WIN_ReleaseWndPtr(child
);
1096 if( !menu
|| !GetSystemMenu(hChild
, FALSE
) )
1102 /* create a copy of sysmenu popup and insert it into frame menu bar */
1104 if (!(hSysPopup
= LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU")))
1107 AppendMenuA(menu
,MF_HELP
| MF_BITMAP
,
1108 SC_MINIMIZE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_MINIMIZE
) ;
1109 AppendMenuA(menu
,MF_HELP
| MF_BITMAP
,
1110 SC_RESTORE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_RESTORE
);
1112 /* In Win 95 look, the system menu is replaced by the child icon */
1114 if(TWEAK_WineLook
> WIN31_LOOK
)
1117 HICON hIcon
= (HICON
)GetClassLongA(hChild
, GCL_HICONSM
);
1119 hIcon
= (HICON
)GetClassLongA(hChild
, GCL_HICON
);
1123 HBITMAP hBitmap
, hOldBitmap
;
1125 HDC hdc
= GetDC(hChild
);
1130 cx
= GetSystemMetrics(SM_CXSMICON
);
1131 cy
= GetSystemMetrics(SM_CYSMICON
);
1132 hMemDC
= CreateCompatibleDC(hdc
);
1133 hBitmap
= CreateCompatibleBitmap(hdc
, cx
, cy
);
1134 hOldBitmap
= SelectObject(hMemDC
, hBitmap
);
1135 SetMapMode(hMemDC
, MM_TEXT
);
1136 hBrush
= CreateSolidBrush(GetSysColor(COLOR_MENU
));
1137 DrawIconEx(hMemDC
, 0, 0, hIcon
, cx
, cy
, 0, hBrush
, DI_NORMAL
);
1138 SelectObject (hMemDC
, hOldBitmap
);
1139 DeleteObject(hBrush
);
1141 ReleaseDC(hChild
, hdc
);
1142 hSysMenuBitmap
= hBitmap
;
1148 hSysMenuBitmap
= hBmpClose
;
1151 if( !InsertMenuA(menu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
1152 (UINT_PTR
)hSysPopup
, (LPSTR
)hSysMenuBitmap
))
1154 TRACE("not inserted\n");
1155 DestroyMenu(hSysPopup
);
1159 /* The close button is only present in Win 95 look */
1161 if(TWEAK_WineLook
> WIN31_LOOK
)
1164 AppendMenuA(menu
,MF_HELP
| MF_BITMAP
,
1165 SC_CLOSE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_CLOSE
);
1168 EnableMenuItem(hSysPopup
, SC_SIZE
, MF_BYCOMMAND
| MF_GRAYED
);
1169 EnableMenuItem(hSysPopup
, SC_MOVE
, MF_BYCOMMAND
| MF_GRAYED
);
1170 EnableMenuItem(hSysPopup
, SC_MAXIMIZE
, MF_BYCOMMAND
| MF_GRAYED
);
1171 SetMenuDefaultItem(hSysPopup
, SC_CLOSE
, FALSE
);
1179 /**********************************************************************
1180 * MDI_RestoreFrameMenu
1182 static BOOL
MDI_RestoreFrameMenu( HWND frame
, HWND hChild
)
1184 MENUITEMINFOW menuInfo
;
1185 HMENU menu
= GetMenu( frame
);
1186 INT nItems
= GetMenuItemCount(menu
) - 1;
1187 UINT iId
= GetMenuItemID(menu
,nItems
) ;
1189 TRACE("frame %p,child %p,nIt=%d,iId=%d\n",frame
,hChild
,nItems
,iId
);
1191 if(!(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
1195 * Remove the system menu, If that menu is the icon of the window
1196 * as it is in win95, we have to delete the bitmap.
1198 memset(&menuInfo
, 0, sizeof(menuInfo
));
1199 menuInfo
.cbSize
= sizeof(menuInfo
);
1200 menuInfo
.fMask
= MIIM_DATA
| MIIM_TYPE
;
1202 GetMenuItemInfoW(menu
,
1207 RemoveMenu(menu
,0,MF_BYPOSITION
);
1210 if ( (menuInfo
.fType
& MFT_BITMAP
) &&
1211 (LOWORD(menuInfo
.dwTypeData
)!=0) &&
1212 (LOWORD(menuInfo
.dwTypeData
)!=HBITMAP_16(hBmpClose
)) )
1214 DeleteObject(HBITMAP_32(LOWORD(menuInfo
.dwTypeData
)));
1217 if ( (menuInfo
.fType
& MFT_BITMAP
) &&
1218 (LOWORD(menuInfo
.dwTypeData
)!=0))
1220 DeleteObject((HBITMAP
)(LOWORD(menuInfo
.dwTypeData
) & 0x50000));
1225 if(TWEAK_WineLook
> WIN31_LOOK
)
1229 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
1232 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
1234 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
1242 /**********************************************************************
1243 * MDI_UpdateFrameText
1245 * used when child window is maximized/restored
1247 * Note: lpTitle can be NULL
1249 static void MDI_UpdateFrameText( HWND frame
, HWND hClient
,
1250 BOOL repaint
, LPCWSTR lpTitle
)
1252 WCHAR lpBuffer
[MDI_MAXTITLELENGTH
+1];
1253 MDICLIENTINFO
*ci
= get_client_info( hClient
);
1255 TRACE("repaint %i, frameText %s\n", repaint
, debugstr_w(lpTitle
));
1259 if (!lpTitle
&& !ci
->frameTitle
) /* first time around, get title from the frame window */
1261 GetWindowTextW( frame
, lpBuffer
, sizeof(lpBuffer
)/sizeof(WCHAR
) );
1265 /* store new "default" title if lpTitle is not NULL */
1268 if (ci
->frameTitle
) HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1269 if ((ci
->frameTitle
= HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle
)+1)*sizeof(WCHAR
))))
1270 strcpyW( ci
->frameTitle
, lpTitle
);
1275 if (ci
->hwndChildMaximized
)
1277 /* combine frame title and child title if possible */
1279 static const WCHAR lpBracket
[] = {' ','-',' ','[',0};
1280 static const WCHAR lpBracket2
[] = {']',0};
1281 int i_frame_text_length
= strlenW(ci
->frameTitle
);
1283 lstrcpynW( lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
1285 if( i_frame_text_length
+ 6 < MDI_MAXTITLELENGTH
)
1287 strcatW( lpBuffer
, lpBracket
);
1288 if (GetWindowTextW( ci
->hwndChildMaximized
, lpBuffer
+ i_frame_text_length
+ 4,
1289 MDI_MAXTITLELENGTH
- i_frame_text_length
- 5 ))
1290 strcatW( lpBuffer
, lpBracket2
);
1292 lpBuffer
[i_frame_text_length
] = 0; /* remove bracket */
1297 lstrcpynW(lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
+1 );
1303 DefWindowProcW( frame
, WM_SETTEXT
, 0, (LPARAM
)lpBuffer
);
1304 if( repaint
== MDI_REPAINTFRAME
)
1305 SetWindowPos( frame
, 0,0,0,0,0, SWP_FRAMECHANGED
|
1306 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
1310 /* ----------------------------- Interface ---------------------------- */
1313 /**********************************************************************
1314 * MDIClientWndProc_common
1316 static LRESULT
MDIClientWndProc_common( HWND hwnd
, UINT message
,
1317 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1319 MDICLIENTINFO
*ci
= NULL
;
1321 if (WM_NCCREATE
!= message
&& WM_CREATE
!= message
1322 && NULL
== (ci
= get_client_info(hwnd
)))
1331 if (!(ci
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ci
))))
1333 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)ci
);
1340 /* Since we are using only cs->lpCreateParams, we can safely
1341 * cast to LPCREATESTRUCTA here */
1342 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
1344 WND
*wndPtr
= WIN_GetPtr( hwnd
);
1346 ci
= HeapAlloc(GetProcessHeap(), 0, sizeof(MDICLIENTINFO
));
1351 SetWindowLongPtr(hwnd
, 0, (LONG_PTR
) ci
);
1353 /* Translation layer doesn't know what's in the cs->lpCreateParams
1354 * so we have to keep track of what environment we're in. */
1357 if( wndPtr
->flags
& WIN_ISWIN32
)
1360 #define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1361 ci
->hWindowMenu
= ccs
->hWindowMenu
;
1362 ci
->idFirstChild
= ccs
->idFirstChild
;
1368 LPCLIENTCREATESTRUCT16 ccs
= MapSL((SEGPTR
)cs
->lpCreateParams
);
1369 ci
->hWindowMenu
= HMENU_32(ccs
->hWindowMenu
);
1370 ci
->idFirstChild
= ccs
->idFirstChild
;
1372 WIN_ReleasePtr( wndPtr
);
1375 ci
->hwndChildMaximized
= 0;
1376 ci
->nActiveChildren
= 0;
1377 ci
->nTotalCreated
= 0;
1378 ci
->frameTitle
= NULL
;
1380 SetWindowLongW( hwnd
, GWL_STYLE
, GetWindowLongW(hwnd
,GWL_STYLE
) | WS_CLIPCHILDREN
);
1382 if (!hBmpClose
) hBmpClose
= CreateMDIMenuBitmap();
1384 if (ci
->hWindowMenu
!= 0)
1385 AppendMenuW( ci
->hWindowMenu
, MF_SEPARATOR
, 0, NULL
);
1387 GetClientRect( GetParent(hwnd
), &rect
);
1388 MoveWindow( hwnd
, 0, 0, rect
.right
, rect
.bottom
, FALSE
);
1390 MDI_UpdateFrameText( GetParent(hwnd
), hwnd
, MDI_NOFRAMEREPAINT
, NULL
);
1392 TRACE("Client created - hwnd = %p, idFirst = %u\n", hwnd
, ci
->idFirstChild
);
1399 if( ci
->hwndChildMaximized
)
1400 MDI_RestoreFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
1401 if((ci
->hWindowMenu
!= 0) &&
1402 (nItems
= GetMenuItemCount(ci
->hWindowMenu
)) > 0)
1404 ci
->idFirstChild
= nItems
- 1;
1405 ci
->nActiveChildren
++; /* to delete a separator */
1406 while( ci
->nActiveChildren
-- )
1407 DeleteMenu(ci
->hWindowMenu
,MF_BYPOSITION
,ci
->idFirstChild
--);
1409 if (ci
->frameTitle
) HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1411 HeapFree( GetProcessHeap(), 0, ci
);
1412 SetWindowLongPtrW( hwnd
, 0, 0 );
1417 case WM_MDIACTIVATE
:
1418 if( ci
->hwndActiveChild
!= (HWND
)wParam
)
1419 SetWindowPos((HWND
)wParam
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1423 return MDICascade(hwnd
, ci
);
1427 return (LRESULT
)MDICreateChild( hwnd
, ci
, (MDICREATESTRUCTA
*)lParam
, unicode
);
1432 return MDIDestroyChild( hwnd
, ci
, WIN_GetFullHandle( (HWND
)wParam
), TRUE
);
1434 return MDIDestroyChild( hwnd
, ci
, (HWND
)wParam
, TRUE
);
1437 case WM_MDIGETACTIVE
:
1438 if (lParam
) *(BOOL
*)lParam
= (ci
->hwndChildMaximized
!= 0);
1439 return (LRESULT
)ci
->hwndActiveChild
;
1441 case WM_MDIICONARRANGE
:
1442 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1443 ArrangeIconicWindows( hwnd
);
1444 ci
->sbRecalc
= SB_BOTH
+1;
1445 SendMessageW( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0 );
1448 case WM_MDIMAXIMIZE
:
1449 ShowWindow( (HWND
)wParam
, SW_MAXIMIZE
);
1452 case WM_MDINEXT
: /* lParam != 0 means previous window */
1454 MDI_SwitchActiveChild( hwnd
, WIN_GetFullHandle( (HWND
)wParam
), !lParam
);
1456 MDI_SwitchActiveChild( hwnd
, (HWND
)wParam
, !lParam
);
1461 SendMessageW( (HWND
)wParam
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
1465 return MDISetMenu( hwnd
, (HMENU
)wParam
, (HMENU
)lParam
);
1467 case WM_MDIREFRESHMENU
:
1468 return MDIRefreshMenu( hwnd
, (HMENU
)wParam
, (HMENU
)lParam
);
1471 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1472 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
1473 MDITile( hwnd
, ci
, wParam
);
1474 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1479 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1480 ScrollChildren( hwnd
, message
, wParam
, lParam
);
1481 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1485 if (ci
->hwndActiveChild
&& !IsIconic( ci
->hwndActiveChild
))
1486 SetFocus( ci
->hwndActiveChild
);
1490 if( ci
->hwndActiveChild
)
1491 SendMessageW(ci
->hwndActiveChild
, message
, wParam
, lParam
);
1494 case WM_PARENTNOTIFY
:
1495 if (LOWORD(wParam
) == WM_LBUTTONDOWN
)
1499 pt
.x
= (short)LOWORD(lParam
);
1500 pt
.y
= (short)HIWORD(lParam
);
1501 child
= ChildWindowFromPoint(hwnd
, pt
);
1503 TRACE("notification from %p (%li,%li)\n",child
,pt
.x
,pt
.y
);
1505 if( child
&& child
!= hwnd
&& child
!= ci
->hwndActiveChild
)
1506 SetWindowPos(child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1511 if( IsWindow(ci
->hwndChildMaximized
) )
1517 rect
.right
= LOWORD(lParam
);
1518 rect
.bottom
= HIWORD(lParam
);
1520 AdjustWindowRectEx(&rect
, GetWindowLongA(ci
->hwndChildMaximized
,GWL_STYLE
),
1521 0, GetWindowLongA(ci
->hwndChildMaximized
,GWL_EXSTYLE
) );
1522 MoveWindow(ci
->hwndChildMaximized
, rect
.left
, rect
.top
,
1523 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 1);
1526 MDI_PostUpdate(hwnd
, ci
, SB_BOTH
+1);
1530 case WM_MDICALCCHILDSCROLL
:
1531 if( (ci
->mdiFlags
& MDIF_NEEDUPDATE
) && ci
->sbRecalc
)
1533 CalcChildScroll(hwnd
, ci
->sbRecalc
-1);
1535 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1539 return unicode
? DefWindowProcW( hwnd
, message
, wParam
, lParam
) :
1540 DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1543 /***********************************************************************
1546 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1548 if (!IsWindow(hwnd
)) return 0;
1549 return MDIClientWndProc_common( hwnd
, message
, wParam
, lParam
, FALSE
);
1552 /***********************************************************************
1555 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1557 if (!IsWindow(hwnd
)) return 0;
1558 return MDIClientWndProc_common( hwnd
, message
, wParam
, lParam
, TRUE
);
1562 /***********************************************************************
1563 * DefFrameProc (USER.445)
1565 LRESULT WINAPI
DefFrameProc16( HWND16 hwnd
, HWND16 hwndMDIClient
,
1566 UINT16 message
, WPARAM16 wParam
, LPARAM lParam
)
1571 lParam
= (LPARAM
)MapSL(lParam
);
1577 return DefFrameProcA( WIN_Handle32(hwnd
), WIN_Handle32(hwndMDIClient
),
1578 message
, wParam
, lParam
);
1582 MDINEXTMENU next_menu
;
1583 DefFrameProcW( WIN_Handle32(hwnd
), WIN_Handle32(hwndMDIClient
),
1584 message
, wParam
, (LPARAM
)&next_menu
);
1585 return MAKELONG( HMENU_16(next_menu
.hmenuNext
), HWND_16(next_menu
.hwndNext
) );
1588 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1593 /***********************************************************************
1594 * DefFrameProcA (USER32.@)
1596 LRESULT WINAPI
DefFrameProcA( HWND hwnd
, HWND hwndMDIClient
,
1597 UINT message
, WPARAM wParam
, LPARAM lParam
)
1605 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, NULL
, 0 );
1606 LPWSTR text
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1607 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, text
, len
);
1608 MDI_UpdateFrameText(hwnd
, hwndMDIClient
, MDI_REPAINTFRAME
, text
);
1609 HeapFree( GetProcessHeap(), 0, text
);
1611 return 1; /* success. FIXME: check text length */
1618 return DefFrameProcW( hwnd
, hwndMDIClient
, message
, wParam
, lParam
);
1621 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1625 /***********************************************************************
1626 * DefFrameProcW (USER32.@)
1628 LRESULT WINAPI
DefFrameProcW( HWND hwnd
, HWND hwndMDIClient
,
1629 UINT message
, WPARAM wParam
, LPARAM lParam
)
1631 MDICLIENTINFO
*ci
= get_client_info( hwndMDIClient
);
1639 WORD id
= LOWORD(wParam
);
1640 /* check for possible syscommands for maximized MDI child */
1641 if (id
< ci
->idFirstChild
|| id
>= ci
->idFirstChild
+ ci
->nActiveChildren
)
1643 if( (id
- 0xf000) & 0xf00f ) break;
1644 if( !ci
->hwndChildMaximized
) break;
1655 return SendMessageW( ci
->hwndChildMaximized
, WM_SYSCOMMAND
,
1662 if (id
- ci
->idFirstChild
== MDI_MOREWINDOWSLIMIT
)
1663 /* User chose "More Windows..." */
1664 childHwnd
= MDI_MoreWindowsDialog(hwndMDIClient
);
1666 /* User chose one of the windows listed in the "Windows" menu */
1667 childHwnd
= MDI_GetChildByID(hwndMDIClient
,id
);
1670 SendMessageW( hwndMDIClient
, WM_MDIACTIVATE
, (WPARAM
)childHwnd
, 0 );
1676 SendMessageW(hwndMDIClient
, message
, wParam
, lParam
);
1680 MDI_UpdateFrameText(hwnd
, hwndMDIClient
, MDI_REPAINTFRAME
, (LPWSTR
)lParam
);
1681 return 1; /* success. FIXME: check text length */
1684 SetFocus(hwndMDIClient
);
1688 MoveWindow(hwndMDIClient
, 0, 0, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1695 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1697 if (!IsIconic(hwnd
) && ci
->hwndActiveChild
&& !ci
->hwndChildMaximized
)
1699 /* control menu is between the frame system menu and
1700 * the first entry of menu bar */
1701 WND
*wndPtr
= WIN_GetPtr(hwnd
);
1703 if( (wParam
== VK_LEFT
&& GetMenu(hwnd
) == next_menu
->hmenuIn
) ||
1704 (wParam
== VK_RIGHT
&& GetSubMenu(wndPtr
->hSysMenu
, 0) == next_menu
->hmenuIn
) )
1706 WIN_ReleasePtr(wndPtr
);
1707 wndPtr
= WIN_GetPtr(ci
->hwndActiveChild
);
1708 next_menu
->hmenuNext
= GetSubMenu(wndPtr
->hSysMenu
, 0);
1709 next_menu
->hwndNext
= ci
->hwndActiveChild
;
1711 WIN_ReleasePtr(wndPtr
);
1719 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1724 /***********************************************************************
1725 * DefMDIChildProc (USER.447)
1727 LRESULT WINAPI
DefMDIChildProc16( HWND16 hwnd
, UINT16 message
,
1728 WPARAM16 wParam
, LPARAM lParam
)
1733 return DefMDIChildProcA( WIN_Handle32(hwnd
), message
, wParam
, (LPARAM
)MapSL(lParam
) );
1737 case WM_CHILDACTIVATE
:
1742 return DefMDIChildProcW( WIN_Handle32(hwnd
), message
, wParam
, lParam
);
1743 case WM_GETMINMAXINFO
:
1745 MINMAXINFO16
*mmi16
= (MINMAXINFO16
*)MapSL(lParam
);
1747 STRUCT32_MINMAXINFO16to32( mmi16
, &mmi
);
1748 DefMDIChildProcW( WIN_Handle32(hwnd
), message
, wParam
, (LPARAM
)&mmi
);
1749 STRUCT32_MINMAXINFO32to16( &mmi
, mmi16
);
1754 MDINEXTMENU next_menu
;
1755 DefMDIChildProcW( WIN_Handle32(hwnd
), message
, wParam
, (LPARAM
)&next_menu
);
1756 return MAKELONG( HMENU_16(next_menu
.hmenuNext
), HWND_16(next_menu
.hwndNext
) );
1759 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1765 /***********************************************************************
1766 * DefMDIChildProcA (USER32.@)
1768 LRESULT WINAPI
DefMDIChildProcA( HWND hwnd
, UINT message
,
1769 WPARAM wParam
, LPARAM lParam
)
1771 HWND client
= GetParent(hwnd
);
1772 MDICLIENTINFO
*ci
= get_client_info( client
);
1775 hwnd
= WIN_GetFullHandle( hwnd
);
1777 if (!ci
) return DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1782 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1783 MDI_MenuModifyItem( client
, hwnd
);
1784 if( ci
->hwndChildMaximized
== hwnd
)
1785 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1786 return 1; /* success. FIXME: check text length */
1788 case WM_GETMINMAXINFO
:
1792 case WM_CHILDACTIVATE
:
1801 return DefMDIChildProcW( hwnd
, message
, wParam
, lParam
);
1803 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1807 /***********************************************************************
1808 * DefMDIChildProcW (USER32.@)
1810 LRESULT WINAPI
DefMDIChildProcW( HWND hwnd
, UINT message
,
1811 WPARAM wParam
, LPARAM lParam
)
1813 HWND client
= GetParent(hwnd
);
1814 MDICLIENTINFO
*ci
= get_client_info( client
);
1817 hwnd
= WIN_GetFullHandle( hwnd
);
1819 if (!ci
) return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1824 DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1825 MDI_MenuModifyItem( client
, hwnd
);
1826 if( ci
->hwndChildMaximized
== hwnd
)
1827 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1828 return 1; /* success. FIXME: check text length */
1830 case WM_GETMINMAXINFO
:
1831 MDI_ChildGetMinMaxInfo( client
, hwnd
, (MINMAXINFO
*)lParam
);
1835 return 0x00010000; /* MDI children don't have menu bars */
1838 SendMessageW( client
, WM_MDIDESTROY
, (WPARAM
)hwnd
, 0 );
1842 if (ci
->hwndActiveChild
!= hwnd
) MDI_ChildActivate( client
, hwnd
);
1845 case WM_CHILDACTIVATE
:
1846 MDI_ChildActivate( client
, hwnd
);
1853 if( ci
->hwndChildMaximized
== hwnd
) return 0;
1857 SetWindowLongW( hwnd
, GWL_STYLE
,
1858 GetWindowLongW( hwnd
, GWL_STYLE
) | WS_SYSMENU
);
1861 if (ci
->hwndChildMaximized
== hwnd
)
1862 return SendMessageW( GetParent(client
), message
, wParam
, lParam
);
1863 SetWindowLongW( hwnd
, GWL_STYLE
,
1864 GetWindowLongW( hwnd
, GWL_STYLE
) & ~WS_SYSMENU
);
1867 SendMessageW( client
, WM_MDINEXT
, 0, 0);
1870 SendMessageW( client
, WM_MDINEXT
, 0, 1);
1878 if( ci
->hwndChildMaximized
) ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1879 else MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1884 if( ci
->hwndActiveChild
== hwnd
&& wParam
!= SIZE_MAXIMIZED
)
1886 ci
->hwndChildMaximized
= 0;
1887 MDI_RestoreFrameMenu( GetParent(client
), hwnd
);
1888 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1891 if( wParam
== SIZE_MAXIMIZED
)
1893 HWND hMaxChild
= ci
->hwndChildMaximized
;
1895 if( hMaxChild
== hwnd
) break;
1898 SendMessageW( hMaxChild
, WM_SETREDRAW
, FALSE
, 0 );
1899 MDI_RestoreFrameMenu( GetParent(client
), hMaxChild
);
1900 ShowWindow( hMaxChild
, SW_SHOWNOACTIVATE
);
1901 SendMessageW( hMaxChild
, WM_SETREDRAW
, TRUE
, 0 );
1903 TRACE("maximizing child %p\n", hwnd
);
1905 /* keep track of the maximized window. */
1906 ci
->hwndChildMaximized
= hwnd
; /* !!! */
1908 /* The maximized window should also be the active window */
1909 MDI_ChildActivate( client
, hwnd
);
1910 MDI_AugmentFrameMenu( GetParent(client
), hwnd
);
1911 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1914 if( wParam
== SIZE_MINIMIZED
)
1916 HWND switchTo
= MDI_GetWindow(ci
, hwnd
, TRUE
, WS_MINIMIZE
);
1918 if (switchTo
) SendMessageW( switchTo
, WM_CHILDACTIVATE
, 0, 0);
1920 MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1927 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1928 HWND parent
= GetParent(client
);
1930 if( wParam
== VK_LEFT
) /* switch to frame system menu */
1932 WND
*wndPtr
= WIN_GetPtr( parent
);
1933 next_menu
->hmenuNext
= GetSubMenu( wndPtr
->hSysMenu
, 0 );
1934 WIN_ReleasePtr( wndPtr
);
1936 if( wParam
== VK_RIGHT
) /* to frame menu bar */
1938 next_menu
->hmenuNext
= GetMenu(parent
);
1940 next_menu
->hwndNext
= parent
;
1948 SendMessageW( hwnd
, WM_SYSCOMMAND
, (WPARAM
)SC_KEYMENU
, (DWORD
)VK_SPACE
);
1953 return DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1956 /**********************************************************************
1957 * CreateMDIWindowA (USER32.@) Creates a MDI child
1960 * Success: Handle to created window
1963 HWND WINAPI
CreateMDIWindowA(
1964 LPCSTR lpClassName
, /* [in] Pointer to registered child class name */
1965 LPCSTR lpWindowName
, /* [in] Pointer to window name */
1966 DWORD dwStyle
, /* [in] Window style */
1967 INT X
, /* [in] Horizontal position of window */
1968 INT Y
, /* [in] Vertical position of window */
1969 INT nWidth
, /* [in] Width of window */
1970 INT nHeight
, /* [in] Height of window */
1971 HWND hWndParent
, /* [in] Handle to parent window */
1972 HINSTANCE hInstance
, /* [in] Handle to application instance */
1973 LPARAM lParam
) /* [in] Application-defined value */
1975 MDICLIENTINFO
*pCi
= get_client_info( hWndParent
);
1976 MDICREATESTRUCTA cs
;
1978 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%p,%p,%ld)\n",
1979 debugstr_a(lpClassName
),debugstr_a(lpWindowName
),dwStyle
,X
,Y
,
1980 nWidth
,nHeight
,hWndParent
,hInstance
,lParam
);
1984 ERR("bad hwnd for MDI-client: %p\n", hWndParent
);
1987 cs
.szClass
=lpClassName
;
1988 cs
.szTitle
=lpWindowName
;
1989 cs
.hOwner
=hInstance
;
1997 return MDICreateChild(hWndParent
, pCi
, &cs
, FALSE
);
2000 /***********************************************************************
2001 * CreateMDIWindowW (USER32.@) Creates a MDI child
2004 * Success: Handle to created window
2007 HWND WINAPI
CreateMDIWindowW(
2008 LPCWSTR lpClassName
, /* [in] Pointer to registered child class name */
2009 LPCWSTR lpWindowName
, /* [in] Pointer to window name */
2010 DWORD dwStyle
, /* [in] Window style */
2011 INT X
, /* [in] Horizontal position of window */
2012 INT Y
, /* [in] Vertical position of window */
2013 INT nWidth
, /* [in] Width of window */
2014 INT nHeight
, /* [in] Height of window */
2015 HWND hWndParent
, /* [in] Handle to parent window */
2016 HINSTANCE hInstance
, /* [in] Handle to application instance */
2017 LPARAM lParam
) /* [in] Application-defined value */
2019 MDICLIENTINFO
*pCi
= get_client_info( hWndParent
);
2020 MDICREATESTRUCTW cs
;
2022 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%p,%p,%ld)\n",
2023 debugstr_w(lpClassName
), debugstr_w(lpWindowName
), dwStyle
, X
, Y
,
2024 nWidth
, nHeight
, hWndParent
, hInstance
, lParam
);
2028 ERR("bad hwnd for MDI-client: %p\n", hWndParent
);
2031 cs
.szClass
= lpClassName
;
2032 cs
.szTitle
= lpWindowName
;
2033 cs
.hOwner
= hInstance
;
2041 return MDICreateChild(hWndParent
, pCi
, (MDICREATESTRUCTA
*)&cs
, TRUE
);
2044 /**********************************************************************
2045 * TranslateMDISysAccel (USER32.@)
2047 BOOL WINAPI
TranslateMDISysAccel( HWND hwndClient
, LPMSG msg
)
2049 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
)
2051 MDICLIENTINFO
*ci
= get_client_info( hwndClient
);
2054 if (!ci
|| !IsWindowEnabled(ci
->hwndActiveChild
)) return 0;
2056 /* translate if the Ctrl key is down and Alt not. */
2058 if( (GetKeyState(VK_CONTROL
) & 0x8000) && !(GetKeyState(VK_MENU
) & 0x8000))
2060 switch( msg
->wParam
)
2064 wParam
= ( GetKeyState(VK_SHIFT
) & 0x8000 ) ? SC_NEXTWINDOW
: SC_PREVWINDOW
;
2073 TRACE("wParam = %04x\n", wParam
);
2074 SendMessageW(ci
->hwndActiveChild
, WM_SYSCOMMAND
, wParam
, (LPARAM
)msg
->wParam
);
2078 return 0; /* failure */
2081 /***********************************************************************
2082 * CalcChildScroll (USER32.@)
2084 void WINAPI
CalcChildScroll( HWND hwnd
, INT scroll
)
2087 RECT childRect
, clientRect
;
2094 GetClientRect( hwnd
, &clientRect
);
2095 SetRectEmpty( &childRect
);
2098 if ((list
= WIN_ListChildren( hwnd
)))
2101 for (i
= 0; list
[i
]; i
++)
2103 DWORD style
= GetWindowLongW( list
[i
], GWL_STYLE
);
2104 if (style
& WS_MAXIMIZE
)
2106 HeapFree( GetProcessHeap(), 0, list
);
2107 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
2110 if (style
& WS_VISIBLE
)
2112 WND
*pWnd
= WIN_FindWndPtr( list
[i
] );
2113 UnionRect( &childRect
, &pWnd
->rectWindow
, &childRect
);
2114 WIN_ReleaseWndPtr( pWnd
);
2117 HeapFree( GetProcessHeap(), 0, list
);
2120 hWndCurrent
= GetWindow(hwnd
, GW_CHILD
);
2121 while (hWndCurrent
!= NULL
)
2123 DWORD style
= GetWindowLongW( hWndCurrent
, GWL_STYLE
);
2124 if (style
& WS_MAXIMIZE
)
2126 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
2129 if (style
& WS_VISIBLE
)
2133 GetWindowRect( hWndCurrent
, &WindowRect
);
2134 UnionRect( &childRect
, &WindowRect
, &childRect
);
2136 hWndCurrent
= GetWindow(hWndCurrent
, GW_HWNDNEXT
);
2139 UnionRect( &childRect
, &clientRect
, &childRect
);
2141 /* set common info values */
2142 info
.cbSize
= sizeof(info
);
2143 info
.fMask
= SIF_POS
| SIF_RANGE
;
2145 /* set the specific */
2150 info
.nMin
= childRect
.left
;
2151 info
.nMax
= childRect
.right
- clientRect
.right
;
2152 info
.nPos
= clientRect
.left
- childRect
.left
;
2153 SetScrollInfo(hwnd
, scroll
, &info
, TRUE
);
2154 if (scroll
== SB_HORZ
) break;
2157 info
.nMin
= childRect
.top
;
2158 info
.nMax
= childRect
.bottom
- clientRect
.bottom
;
2159 info
.nPos
= clientRect
.top
- childRect
.top
;
2160 SetScrollInfo(hwnd
, scroll
, &info
, TRUE
);
2166 /***********************************************************************
2167 * ScrollChildren (USER32.@)
2169 void WINAPI
ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
,
2173 INT curPos
, length
, minPos
, maxPos
, shift
;
2176 GetClientRect( hWnd
, &rect
);
2181 GetScrollRange(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
2182 curPos
= GetScrollPos(hWnd
,SB_HORZ
);
2183 length
= (rect
.right
- rect
.left
) / 2;
2184 shift
= GetSystemMetrics(SM_CYHSCROLL
);
2187 GetScrollRange(hWnd
,SB_VERT
,&minPos
,&maxPos
);
2188 curPos
= GetScrollPos(hWnd
,SB_VERT
);
2189 length
= (rect
.bottom
- rect
.top
) / 2;
2190 shift
= GetSystemMetrics(SM_CXVSCROLL
);
2199 newPos
= curPos
- shift
;
2202 newPos
= curPos
+ shift
;
2205 newPos
= curPos
- length
;
2208 newPos
= curPos
+ length
;
2211 case SB_THUMBPOSITION
:
2212 newPos
= LOWORD(lParam
);
2225 CalcChildScroll(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
2229 if( newPos
> maxPos
)
2232 if( newPos
< minPos
)
2235 SetScrollPos(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
2237 if( uMsg
== WM_VSCROLL
)
2238 ScrollWindowEx(hWnd
,0 ,curPos
- newPos
, NULL
, NULL
, 0, NULL
,
2239 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
2241 ScrollWindowEx(hWnd
,curPos
- newPos
, 0, NULL
, NULL
, 0, NULL
,
2242 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
2246 /******************************************************************************
2247 * CascadeWindows (USER32.@) Cascades MDI child windows
2250 * Success: Number of cascaded windows.
2254 CascadeWindows (HWND hwndParent
, UINT wFlags
, LPCRECT lpRect
,
2255 UINT cKids
, const HWND
*lpKids
)
2257 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
2262 /******************************************************************************
2263 * TileWindows (USER32.@) Tiles MDI child windows
2266 * Success: Number of tiled windows.
2270 TileWindows (HWND hwndParent
, UINT wFlags
, LPCRECT lpRect
,
2271 UINT cKids
, const HWND
*lpKids
)
2273 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
2277 /************************************************************************
2278 * "More Windows..." functionality
2281 /* MDI_MoreWindowsDlgProc
2283 * This function will process the messages sent to the "More Windows..."
2285 * Return values: 0 = cancel pressed
2286 * HWND = ok pressed or double-click in the list...
2290 static INT_PTR WINAPI
MDI_MoreWindowsDlgProc (HWND hDlg
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
2303 MDICLIENTINFO
*ci
= get_client_info( (HWND
)lParam
);
2304 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2305 HWND
*list
, *sorted_list
;
2307 if (!(list
= WIN_ListChildren( (HWND
)lParam
))) return TRUE
;
2308 if (!(sorted_list
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
2309 sizeof(HWND
) * ci
->nActiveChildren
)))
2311 HeapFree( GetProcessHeap(), 0, list
);
2315 /* Fill the list, sorted by id... */
2316 for (i
= 0; list
[i
]; i
++)
2318 UINT id
= GetWindowLongW( list
[i
], GWL_ID
) - ci
->idFirstChild
;
2319 if (id
< ci
->nActiveChildren
) sorted_list
[id
] = list
[i
];
2321 HeapFree( GetProcessHeap(), 0, list
);
2323 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
2327 if (!GetWindowTextW( sorted_list
[i
], buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
2329 SendMessageW(hListBox
, LB_ADDSTRING
, 0, (LPARAM
)buffer
);
2330 SendMessageW(hListBox
, LB_SETITEMDATA
, i
, (LPARAM
)sorted_list
[i
] );
2331 length
= strlenW(buffer
); /* FIXME: should use GetTextExtentPoint */
2332 if (length
> widest
)
2335 /* Make sure the horizontal scrollbar scrolls ok */
2336 SendMessageW(hListBox
, LB_SETHORIZONTALEXTENT
, widest
* 6, 0);
2338 /* Set the current selection */
2339 SendMessageW(hListBox
, LB_SETCURSEL
, MDI_MOREWINDOWSLIMIT
, 0);
2345 switch (LOWORD(wParam
))
2348 if (HIWORD(wParam
) != LBN_DBLCLK
) break;
2352 /* windows are sorted by menu ID, so we must return the
2353 * window associated to the given id
2355 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2356 UINT index
= SendMessageW(hListBox
, LB_GETCURSEL
, 0, 0);
2357 LRESULT res
= SendMessageW(hListBox
, LB_GETITEMDATA
, index
, 0);
2358 EndDialog(hDlg
, res
);
2372 * MDI_MoreWindowsDialog
2374 * Prompts the user with a listbox containing the opened
2375 * documents. The user can then choose a windows and click
2376 * on OK to set the current window to the one selected, or
2377 * CANCEL to cancel. The function returns a handle to the
2381 static HWND
MDI_MoreWindowsDialog(HWND hwnd
)
2387 hRes
= FindResourceA(GetModuleHandleA("USER32"), "MDI_MOREWINDOWS", (LPSTR
)RT_DIALOG
);
2392 hDlgTmpl
= LoadResource(GetModuleHandleA("USER32"), hRes
);
2397 template = LockResource( hDlgTmpl
);
2402 return (HWND
) DialogBoxIndirectParamA(GetModuleHandleA("USER32"),
2403 (LPDLGTEMPLATE
) template,
2404 hwnd
, MDI_MoreWindowsDlgProc
, (LPARAM
) hwnd
);
2411 * Will swap the menu IDs for the given 2 positions.
2412 * pos1 and pos2 are menu IDs
2417 static void MDI_SwapMenuItems(HWND parent
, UINT pos1
, UINT pos2
)
2424 if (!(list
= WIN_ListChildren( parent
))) return;
2425 for (i
= 0; list
[i
]; i
++)
2427 UINT id
= GetWindowLongW( list
[i
], GWL_ID
);
2428 if (id
== pos1
) SetWindowLongW( list
[i
], GWL_ID
, pos2
);
2429 else if (id
== pos2
) SetWindowLongW( list
[i
], GWL_ID
, pos1
);
2431 HeapFree( GetProcessHeap(), 0, list
);