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.
88 WINE_DEFAULT_DEBUG_CHANNEL(mdi
);
90 #define MDI_MAXLISTLENGTH 0x40
91 #define MDI_MAXTITLELENGTH 0xa1
93 #define MDI_NOFRAMEREPAINT 0
94 #define MDI_REPAINTFRAMENOW 1
95 #define MDI_REPAINTFRAME 2
97 #define WM_MDICALCCHILDSCROLL 0x10ac /* this is exactly what Windows uses */
99 /* "More Windows..." definitions */
100 #define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
101 option will appear under the Windows menu */
102 #define MDI_IDC_LISTBOX 100
103 #define IDS_MDI_MOREWINDOWS 13
105 #define MDIF_NEEDUPDATE 0x0001
109 UINT nActiveChildren
;
110 HWND hwndChildMaximized
;
111 HWND hwndActiveChild
;
117 UINT sbRecalc
; /* SB_xxx flags for scrollbar fixup */
120 static HBITMAP hBmpClose
= 0;
122 /* ----------------- declarations ----------------- */
123 static void MDI_UpdateFrameText( HWND
, HWND
, BOOL
, LPCWSTR
);
124 static BOOL
MDI_AugmentFrameMenu( HWND
, HWND
);
125 static BOOL
MDI_RestoreFrameMenu( HWND
, HWND
);
126 static LONG
MDI_ChildActivate( HWND
, HWND
);
128 static HWND
MDI_MoreWindowsDialog(HWND
);
129 static void MDI_SwapMenuItems(HWND
, UINT
, UINT
);
130 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
131 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
135 HWND
* WIN_ListChildren (HWND hWndparent
)
144 dwCount
= NtUserBuildHwndList ( NULL
, hWndparent
, FALSE
, 0, 0, NULL
, 0 );
146 if ( !dwCount
|| GetLastError() )
149 /* allocate buffer to receive HWND handles */
150 hHeap
= GetProcessHeap();
152 pHwnd
= HeapAlloc ( hHeap
, 0, sizeof(HWND
)*(dwCount
+1) );
155 SetLastError ( ERROR_NOT_ENOUGH_MEMORY
);
159 /* now call kernel again to fill the buffer this time */
160 dwCount
= NtUserBuildHwndList (NULL
, hWndparent
, FALSE
, 0, 0, pHwnd
, dwCount
);
162 if ( !dwCount
|| GetLastError() )
165 HeapFree ( hHeap
, 0, pHwnd
);
175 void WINAPI
ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
176 void WINAPI
CalcChildScroll(HWND hwnd
, INT scroll
);
178 BOOL CALLBACK
MDI_GetChildByID_EnumProc (HWND hwnd
, LPARAM lParam
)
180 DWORD
*control
= (DWORD
*)lParam
;
181 if(*control
== GetWindowLongW( hwnd
, GWL_ID
))
183 *control
= (DWORD
)hwnd
;
190 /* -------- Miscellaneous service functions ----------
194 static HWND
MDI_GetChildByID(HWND hwnd
, UINT id
)
198 if (hwnd
&& !EnumChildWindows(hwnd
, (WNDENUMPROC
)&MDI_GetChildByID_EnumProc
, (LPARAM
)&Control
))
200 return (HWND
)Control
;
208 if (!(win_array
= WIN_ListChildren( hwnd
))) return 0;
209 for (i
= 0; win_array
[i
]; i
++)
211 if (GetWindowLongA( win_array
[i
], GWL_ID
) == id
) break;
214 HeapFree( GetProcessHeap(), 0, win_array
);
219 static void MDI_PostUpdate(HWND hwnd
, MDICLIENTINFO
* ci
, WORD recalc
)
221 if( !(ci
->mdiFlags
& MDIF_NEEDUPDATE
) )
223 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
224 PostMessageA( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0);
226 ci
->sbRecalc
= recalc
;
230 /*********************************************************************
231 * MDIClient class descriptor
233 const struct builtin_class_descr MDICLIENT_builtin_class
=
235 L
"MDIClient", /* name */
237 MDIClientWndProcW
, /* procW */
238 MDIClientWndProcA
, /* procA */
239 sizeof(MDICLIENTINFO
*), /* extra */
240 IDC_ARROW
, /* cursor */
241 (HBRUSH
)(COLOR_APPWORKSPACE
+1) /* brush */
245 static MDICLIENTINFO
*get_client_info( HWND client
)
248 return (MDICLIENTINFO
*)GetWindowLongPtr(client
, 0);
250 MDICLIENTINFO
*ret
= NULL
;
251 WND
*win
= WIN_GetPtr( client
);
254 if (win
== WND_OTHER_PROCESS
)
256 ERR( "client %p belongs to other process\n", client
);
259 if (win
->cbWndExtra
< sizeof(MDICLIENTINFO
)) WARN( "%p is not an MDI client\n", client
);
260 else ret
= (MDICLIENTINFO
*)win
->wExtra
;
261 WIN_ReleasePtr( win
);
267 static BOOL
is_close_enabled(HWND hwnd
, HMENU hSysMenu
)
269 if (GetClassLongW(hwnd
, GCL_STYLE
) & CS_NOCLOSE
) return FALSE
;
271 if (!hSysMenu
) hSysMenu
= GetSystemMenu(hwnd
, FALSE
);
274 UINT state
= GetMenuState(hSysMenu
, SC_CLOSE
, MF_BYCOMMAND
);
275 if (state
== 0xFFFFFFFF || (state
& (MF_DISABLED
| MF_GRAYED
)))
281 /**********************************************************************
284 static void MDI_MenuModifyItem( HWND client
, HWND hWndChild
)
286 MDICLIENTINFO
*clientInfo
= get_client_info( client
);
290 if (!clientInfo
|| !clientInfo
->hWindowMenu
) return;
292 id
= GetWindowLongA( hWndChild
, GWL_ID
);
293 if (id
>= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
) return;
295 buffer
[1] = '1' + id
- clientInfo
->idFirstChild
;
297 GetWindowTextW( hWndChild
, buffer
+ 3, sizeof(buffer
)/sizeof(WCHAR
) - 3 );
299 n
= GetMenuState(clientInfo
->hWindowMenu
, id
, MF_BYCOMMAND
);
300 ModifyMenuW(clientInfo
->hWindowMenu
, id
, MF_BYCOMMAND
| MF_STRING
, id
, buffer
);
301 CheckMenuItem(clientInfo
->hWindowMenu
, id
, n
& MF_CHECKED
);
304 /**********************************************************************
307 static BOOL
MDI_MenuDeleteItem( HWND client
, HWND hWndChild
)
310 static const WCHAR format
[] = {'&','%','d',' ',0};
311 MDICLIENTINFO
*clientInfo
= get_client_info( client
);
314 if( !clientInfo
->nActiveChildren
|| !clientInfo
->hWindowMenu
)
317 id
= GetWindowLongA( hWndChild
, GWL_ID
);
318 DeleteMenu(clientInfo
->hWindowMenu
,id
,MF_BYCOMMAND
);
320 /* walk the rest of MDI children to prevent gaps in the id
321 * sequence and in the menu child list */
323 for( index
= id
+1; index
<= clientInfo
->nActiveChildren
+
324 clientInfo
->idFirstChild
; index
++ )
326 HWND hwnd
= MDI_GetChildByID(client
,index
);
329 TRACE("no window for id=%i\n",index
);
334 SetWindowLongW( hwnd
, GWL_ID
, GetWindowLongW( hwnd
, GWL_ID
) - 1 );
336 n
= wsprintfW(buffer
, format
,index
- clientInfo
->idFirstChild
);
337 GetWindowTextW( hwnd
, buffer
+ n
, sizeof(buffer
)/sizeof(WCHAR
) - n
);
339 /* change menu if the current child is to be shown in the
342 if (index
<= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
)
343 ModifyMenuW(clientInfo
->hWindowMenu
,index
,MF_BYCOMMAND
| MF_STRING
,
344 index
- 1 , buffer
);
347 /* We must restore the "More Windows..." option if there are enough children
349 if (clientInfo
->nActiveChildren
- 1 > MDI_MOREWINDOWSLIMIT
)
352 LoadStringW(User32Instance
, IDS_MDI_MOREWINDOWS
, szTmp
, sizeof(szTmp
)/sizeof(szTmp
[0]));
353 AppendMenuW(clientInfo
->hWindowMenu
, MF_STRING
, clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
, szTmp
);
358 /**********************************************************************
361 * returns "activateable" child different from the current or zero
363 static HWND
MDI_GetWindow(MDICLIENTINFO
*clientInfo
, HWND hWnd
, BOOL bNext
,
370 dwStyleMask
|= WS_DISABLED
| WS_VISIBLE
;
371 if( !hWnd
) hWnd
= clientInfo
->hwndActiveChild
;
373 if (!(list
= WIN_ListChildren( GetParent(hWnd
) ))) return 0;
375 /* start from next after hWnd */
376 while (list
[i
] && list
[i
] != hWnd
) i
++;
379 for ( ; list
[i
]; i
++)
381 if (GetWindow( list
[i
], GW_OWNER
)) continue;
382 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
384 if (bNext
) goto found
;
386 /* now restart from the beginning */
387 for (i
= 0; list
[i
] && list
[i
] != hWnd
; i
++)
389 if (GetWindow( list
[i
], GW_OWNER
)) continue;
390 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
392 if (bNext
) goto found
;
395 HeapFree( GetProcessHeap(), 0, list
);
399 /**********************************************************************
400 * MDI_CalcDefaultChildPos
402 * It seems that the default height is about 2/3 of the client rect
404 static void MDI_CalcDefaultChildPos( HWND hwnd
, WORD n
, LPPOINT lpPos
, INT delta
)
408 INT spacing
= GetSystemMetrics(SM_CYCAPTION
) +
409 GetSystemMetrics(SM_CYFRAME
) - 1;
411 GetClientRect( hwnd
, &rect
);
412 if( rect
.bottom
- rect
.top
- delta
>= spacing
)
413 rect
.bottom
-= delta
;
415 nstagger
= (rect
.bottom
- rect
.top
)/(3 * spacing
);
416 lpPos
[1].x
= (rect
.right
- rect
.left
- nstagger
* spacing
);
417 lpPos
[1].y
= (rect
.bottom
- rect
.top
- nstagger
* spacing
);
418 lpPos
[0].x
= lpPos
[0].y
= spacing
* (n
%(nstagger
+1));
421 /**********************************************************************
424 static LRESULT
MDISetMenu( HWND hwnd
, HMENU hmenuFrame
,
428 HWND hwndFrame
= GetParent(hwnd
);
429 HMENU oldFrameMenu
= GetMenu(hwndFrame
);
431 TRACE("%p %p %p\n", hwnd
, hmenuFrame
, hmenuWindow
);
433 if (hmenuFrame
&& !IsMenu(hmenuFrame
))
435 WARN("hmenuFrame is not a menu handle\n");
439 if (hmenuWindow
&& !IsMenu(hmenuWindow
))
441 WARN("hmenuWindow is not a menu handle\n");
445 if (!(ci
= get_client_info( hwnd
))) return 0;
447 if( ci
->hwndChildMaximized
&& hmenuFrame
&& hmenuFrame
!=oldFrameMenu
)
448 MDI_RestoreFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
450 if( hmenuWindow
&& hmenuWindow
!= ci
->hWindowMenu
)
452 /* delete menu items from ci->hWindowMenu
453 * and add them to hmenuWindow */
454 /* Agent newsreader calls this function with ci->hWindowMenu == NULL */
455 if( ci
->hWindowMenu
&& ci
->nActiveChildren
)
458 LPWSTR buffer
= NULL
;
460 INT nbWindowsMenuItems
; /* num of documents shown + "More Windows..." if present */
461 INT i
= GetMenuItemCount(ci
->hWindowMenu
) - 1;
462 INT pos
= GetMenuItemCount(hmenuWindow
) + 1;
464 AppendMenuA( hmenuWindow
, MF_SEPARATOR
, 0, NULL
);
466 if (ci
->nActiveChildren
<= MDI_MOREWINDOWSLIMIT
)
467 nbWindowsMenuItems
= ci
->nActiveChildren
;
469 nbWindowsMenuItems
= MDI_MOREWINDOWSLIMIT
+ 1;
471 j
= i
- nbWindowsMenuItems
+ 1;
473 for( ; i
>= j
; i
-- )
475 memset(&mii
, 0, sizeof(mii
));
476 mii
.cbSize
= sizeof(mii
);
477 mii
.fMask
= MIIM_CHECKMARKS
| MIIM_DATA
| MIIM_ID
| MIIM_STATE
478 | MIIM_SUBMENU
| MIIM_TYPE
| MIIM_BITMAP
;
480 GetMenuItemInfoW(ci
->hWindowMenu
, i
, TRUE
, &mii
);
481 if(mii
.cch
) { /* Menu is MFT_STRING */
482 mii
.cch
++; /* add room for '\0' */
483 buffer
= HeapAlloc(GetProcessHeap(), 0,
484 mii
.cch
* sizeof(WCHAR
));
485 mii
.dwTypeData
= buffer
;
486 GetMenuItemInfoW(ci
->hWindowMenu
, i
, TRUE
, &mii
);
488 DeleteMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
489 InsertMenuItemW(hmenuWindow
, pos
, TRUE
, &mii
);
491 HeapFree(GetProcessHeap(), 0, buffer
);
495 /* remove separator */
496 DeleteMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
498 ci
->hWindowMenu
= hmenuWindow
;
503 SetMenu(hwndFrame
, hmenuFrame
);
504 if( hmenuFrame
!=oldFrameMenu
)
506 if( ci
->hwndChildMaximized
)
507 MDI_AugmentFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
508 return (LRESULT
)oldFrameMenu
;
513 HMENU menu
= GetMenu( GetParent(hwnd
) );
514 INT nItems
= GetMenuItemCount(menu
) - 1;
515 UINT iId
= GetMenuItemID(menu
,nItems
) ;
517 if( !(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
519 /* SetMenu() may already have been called, meaning that this window
520 * already has its menu. But they may have done a SetMenu() on
521 * an MDI window, and called MDISetMenu() after the fact, meaning
522 * that the "if" to this "else" wouldn't catch the need to
523 * augment the frame menu.
525 if( ci
->hwndChildMaximized
)
526 MDI_AugmentFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
532 /**********************************************************************
535 static LRESULT
MDIRefreshMenu( HWND hwnd
, HMENU hmenuFrame
,
538 HWND hwndFrame
= GetParent(hwnd
);
539 HMENU oldFrameMenu
= GetMenu(hwndFrame
);
541 TRACE("%p %p %p\n", hwnd
, hmenuFrame
, hmenuWindow
);
543 FIXME("partially function stub\n");
545 return (LRESULT
)oldFrameMenu
;
549 /* ------------------ MDI child window functions ---------------------- */
552 /**********************************************************************
555 static HWND
MDICreateChild( HWND parent
, MDICLIENTINFO
*ci
,
556 LPMDICREATESTRUCTA cs
, BOOL unicode
)
559 DWORD style
= cs
->style
| (WS_CHILD
| WS_CLIPSIBLINGS
);
560 HWND hwnd
, hwndMax
= 0;
561 UINT wIDmenu
= ci
->idFirstChild
+ ci
->nActiveChildren
;
565 static const WCHAR lpstrDef
[] = {'j','u','n','k','!',0};
567 TRACE("origin %i,%i - dim %i,%i, style %08lx\n",
568 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, cs
->style
);
569 /* calculate placement */
570 MDI_CalcDefaultChildPos(parent
, ci
->nTotalCreated
++, pos
, 0);
573 if (cs
->cx
== CW_USEDEFAULT
|| cs
->cx
== CW_USEDEFAULT16
|| !cs
->cx
) cs
->cx
= pos
[1].x
;
574 if (cs
->cy
== CW_USEDEFAULT
|| cs
->cy
== CW_USEDEFAULT16
|| !cs
->cy
) cs
->cy
= pos
[1].y
;
576 if (cs
->x
== CW_USEDEFAULT
|| cs
->x
== CW_USEDEFAULT16
)
578 if (cs
->cx
== CW_USEDEFAULT
|| !cs
->cx
) cs
->cx
= pos
[1].x
;
579 if (cs
->cy
== CW_USEDEFAULT
|| !cs
->cy
) cs
->cy
= pos
[1].y
;
581 if (cs
->x
== CW_USEDEFAULT
)
588 /* restore current maximized child */
589 if( (style
& WS_VISIBLE
) && ci
->hwndChildMaximized
)
591 TRACE("Restoring current maximized child %p\n", ci
->hwndChildMaximized
);
592 if( style
& WS_MAXIMIZE
)
593 SendMessageW(parent
, WM_SETREDRAW
, FALSE
, 0L);
594 hwndMax
= ci
->hwndChildMaximized
;
595 ShowWindow( hwndMax
, SW_SHOWNOACTIVATE
);
596 if( style
& WS_MAXIMIZE
)
597 SendMessageW(parent
, WM_SETREDRAW
, TRUE
, 0L);
600 if (ci
->nActiveChildren
<= MDI_MOREWINDOWSLIMIT
)
601 /* this menu is needed to set a check mark in MDI_ChildActivate */
602 if (ci
->hWindowMenu
!= 0)
603 AppendMenuW(ci
->hWindowMenu
, MF_STRING
, wIDmenu
, lpstrDef
);
605 ci
->nActiveChildren
++;
607 /* fix window style */
609 wndParent
= WIN_FindWndPtr( parent
);
610 if( !(wndParent
->dwStyle
& MDIS_ALLCHILDSTYLES
) )
612 if( !(GetWindowLong(parent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
) )
615 TRACE("MDIS_ALLCHILDSTYLES is missing, fixing window style\n");
616 style
&= (WS_CHILD
| WS_CLIPSIBLINGS
| WS_MINIMIZE
| WS_MAXIMIZE
|
617 WS_CLIPCHILDREN
| WS_DISABLED
| WS_VSCROLL
| WS_HSCROLL
);
618 style
|= (WS_VISIBLE
| WS_OVERLAPPEDWINDOW
);
622 if( wndParent
->flags
& WIN_ISWIN32
)
626 WIN_ReleaseWndPtr( wndParent
);
630 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)cs
;
631 hwnd
= CreateWindowW( csW
->szClass
, csW
->szTitle
, style
,
632 csW
->x
, csW
->y
, csW
->cx
, csW
->cy
, parent
,
633 (HMENU
)wIDmenu
, csW
->hOwner
, csW
);
636 hwnd
= CreateWindowA( cs
->szClass
, cs
->szTitle
, style
,
637 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, parent
,
638 (HMENU
)wIDmenu
, cs
->hOwner
, cs
);
643 MDICREATESTRUCT16 cs16
;
644 SEGPTR title
, cls
, seg_cs16
;
646 WIN_ReleaseWndPtr( wndParent
);
647 STRUCT32_MDICREATESTRUCT32Ato16( cs
, &cs16
);
648 cs16
.szTitle
= title
= MapLS( cs
->szTitle
);
649 cs16
.szClass
= cls
= MapLS( cs
->szClass
);
650 seg_cs16
= MapLS( &cs16
);
651 hwnd
= WIN_Handle32( CreateWindow16( cs
->szClass
, cs
->szTitle
, style
,
652 cs16
.x
, cs16
.y
, cs16
.cx
, cs16
.cy
,
653 HWND_16(parent
), (HMENU16
)wIDmenu
,
654 cs16
.hOwner
, (LPVOID
)seg_cs16
));
661 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
665 /* All MDI child windows have the WS_EX_MDICHILD style */
666 SetWindowLongW( hwnd
, GWL_EXSTYLE
, GetWindowLongW( hwnd
, GWL_EXSTYLE
) | WS_EX_MDICHILD
);
668 /* If we have more than 9 windows, we must insert the new one at the
669 * 9th position in order to see it in the "Windows" menu
671 if (ci
->nActiveChildren
> MDI_MOREWINDOWSLIMIT
)
672 MDI_SwapMenuItems( parent
, GetWindowLongW( hwnd
, GWL_ID
),
673 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1);
675 MDI_MenuModifyItem(parent
, hwnd
);
677 /* Have we hit the "More Windows..." limit? If so, we must
678 * add a "More Windows..." option
680 if (ci
->nActiveChildren
== MDI_MOREWINDOWSLIMIT
+ 1)
683 LoadStringW(User32Instance
, IDS_MDI_MOREWINDOWS
, szTmp
, sizeof(szTmp
)/sizeof(szTmp
[0]));
685 ModifyMenuW(ci
->hWindowMenu
,
686 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
,
687 MF_BYCOMMAND
| MF_STRING
,
688 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
,
692 if( IsIconic(hwnd
) && ci
->hwndActiveChild
)
694 TRACE("Minimizing created MDI child %p\n", hwnd
);
695 ShowWindow( hwnd
, SW_SHOWMINNOACTIVE
);
699 /* WS_VISIBLE is clear if a) the MDI client has
700 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
701 * MDICreateStruct. If so the created window is not shown nor
704 if (IsWindowVisible(hwnd
)) ShowWindow(hwnd
, SW_SHOW
);
706 TRACE("created child - %p\n",hwnd
);
710 ci
->nActiveChildren
--;
711 DeleteMenu(ci
->hWindowMenu
,wIDmenu
,MF_BYCOMMAND
);
712 if( IsWindow(hwndMax
) )
713 ShowWindow(hwndMax
, SW_SHOWMAXIMIZED
);
719 /**********************************************************************
720 * MDI_ChildGetMinMaxInfo
722 * Note: The rule here is that client rect of the maximized MDI child
723 * is equal to the client rect of the MDI client window.
725 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
729 GetClientRect( client
, &rect
);
730 AdjustWindowRectEx( &rect
, GetWindowLongW( hwnd
, GWL_STYLE
),
731 0, GetWindowLongW( hwnd
, GWL_EXSTYLE
));
733 lpMinMax
->ptMaxSize
.x
= rect
.right
-= rect
.left
;
734 lpMinMax
->ptMaxSize
.y
= rect
.bottom
-= rect
.top
;
736 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
737 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
739 TRACE("max rect (%ld,%ld - %ld, %ld)\n",
740 rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
743 /**********************************************************************
744 * MDI_SwitchActiveChild
746 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
749 static void MDI_SwitchActiveChild( HWND clientHwnd
, HWND childHwnd
,
754 MDICLIENTINFO
*ci
= get_client_info( clientHwnd
);
756 hwndTo
= MDI_GetWindow(ci
, childHwnd
, bNextWindow
, 0);
758 TRACE("from %p, to %p\n",childHwnd
,hwndTo
);
760 if ( !hwndTo
) return; /* no window to switch to */
762 hwndPrev
= ci
->hwndActiveChild
;
764 if ( hwndTo
!= hwndPrev
)
766 SetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0,
767 SWP_NOMOVE
| SWP_NOSIZE
);
769 if( bNextWindow
&& hwndPrev
)
770 SetWindowPos( hwndPrev
, HWND_BOTTOM
, 0, 0, 0, 0,
771 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
776 /**********************************************************************
779 static LRESULT
MDIDestroyChild( HWND parent
, MDICLIENTINFO
*ci
,
780 HWND child
, BOOL flagDestroy
)
782 if( child
== ci
->hwndActiveChild
)
784 MDI_SwitchActiveChild(parent
, child
, TRUE
);
786 if( child
== ci
->hwndActiveChild
)
788 ShowWindow( child
, SW_HIDE
);
789 if( child
== ci
->hwndChildMaximized
)
791 HWND frame
= GetParent(parent
);
792 MDI_RestoreFrameMenu( frame
, child
);
793 ci
->hwndChildMaximized
= 0;
794 MDI_UpdateFrameText( frame
, parent
, TRUE
, NULL
);
797 MDI_ChildActivate(parent
, 0);
801 MDI_MenuDeleteItem(parent
, child
);
803 ci
->nActiveChildren
--;
805 TRACE("child destroyed - %p\n",child
);
809 MDI_PostUpdate(GetParent(child
), ci
, SB_BOTH
+1);
810 DestroyWindow(child
);
816 /**********************************************************************
819 * Note: hWndChild is NULL when last child is being destroyed
821 static LONG
MDI_ChildActivate( HWND client
, HWND child
)
823 MDICLIENTINFO
*clientInfo
= get_client_info( client
);
824 HWND prevActiveWnd
= clientInfo
->hwndActiveChild
;
825 BOOL isActiveFrameWnd
;
827 if (child
&& (!IsWindowEnabled( child
))) return 0;
829 /* Don't activate if it is already active. Might happen
830 since ShowWindow DOES activate MDI children */
831 if (clientInfo
->hwndActiveChild
== child
) return 0;
833 TRACE("%p\n", child
);
835 isActiveFrameWnd
= (GetActiveWindow() == GetParent(client
));
837 /* deactivate prev. active child */
840 SetWindowLongA( prevActiveWnd
, GWL_STYLE
,
841 GetWindowLongA( prevActiveWnd
, GWL_STYLE
) | WS_SYSMENU
);
842 SendMessageA( prevActiveWnd
, WM_NCACTIVATE
, FALSE
, 0L );
843 SendMessageA( prevActiveWnd
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
844 /* uncheck menu item */
845 if( clientInfo
->hWindowMenu
)
847 UINT prevID
= GetWindowLongA( prevActiveWnd
, GWL_ID
);
849 if (prevID
- clientInfo
->idFirstChild
< MDI_MOREWINDOWSLIMIT
)
850 CheckMenuItem( clientInfo
->hWindowMenu
, prevID
, 0);
852 CheckMenuItem( clientInfo
->hWindowMenu
,
853 clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1, 0);
858 if (clientInfo
->hwndChildMaximized
&& clientInfo
->hwndChildMaximized
!= child
)
860 INT cmd
= SW_SHOWNORMAL
;
864 UINT state
= GetMenuState(GetSystemMenu(child
, FALSE
), SC_MAXIMIZE
, MF_BYCOMMAND
);
865 if (state
!= 0xFFFFFFFF && (state
& (MF_DISABLED
| MF_GRAYED
)))
866 SendMessageW(clientInfo
->hwndChildMaximized
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
868 cmd
= SW_SHOWMAXIMIZED
;
870 clientInfo
->hwndActiveChild
= child
;
873 ShowWindow( clientInfo
->hwndActiveChild
, cmd
);
876 clientInfo
->hwndActiveChild
= child
;
878 /* check if we have any children left */
881 if( isActiveFrameWnd
)
886 /* check menu item */
887 if( clientInfo
->hWindowMenu
)
889 UINT id
= GetWindowLongA( child
, GWL_ID
);
890 /* The window to be activated must be displayed in the "Windows" menu */
891 if (id
>= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
)
893 MDI_SwapMenuItems( GetParent(child
),
894 id
, clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1);
895 id
= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1;
896 MDI_MenuModifyItem( GetParent(child
), child
);
899 CheckMenuItem(clientInfo
->hWindowMenu
, id
, MF_CHECKED
);
901 /* bring active child to the top */
902 SetWindowPos( child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
904 if( isActiveFrameWnd
)
906 SendMessageA( child
, WM_NCACTIVATE
, TRUE
, 0L);
907 if( GetFocus() == client
)
908 SendMessageA( client
, WM_SETFOCUS
, (WPARAM
)client
, 0L );
912 SendMessageA( child
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
916 /* -------------------- MDI client window functions ------------------- */
918 /**********************************************************************
919 * CreateMDIMenuBitmap
921 static HBITMAP
CreateMDIMenuBitmap(void)
923 HDC hDCSrc
= CreateCompatibleDC(0);
924 HDC hDCDest
= CreateCompatibleDC(hDCSrc
);
925 HBITMAP hbClose
= LoadBitmapW(0, MAKEINTRESOURCEW(OBM_CLOSE
) );
927 HBITMAP hobjSrc
, hobjDest
;
929 hobjSrc
= SelectObject(hDCSrc
, hbClose
);
930 hbCopy
= CreateCompatibleBitmap(hDCSrc
,GetSystemMetrics(SM_CXSIZE
),GetSystemMetrics(SM_CYSIZE
));
931 hobjDest
= SelectObject(hDCDest
, hbCopy
);
933 BitBlt(hDCDest
, 0, 0, GetSystemMetrics(SM_CXSIZE
), GetSystemMetrics(SM_CYSIZE
),
934 hDCSrc
, GetSystemMetrics(SM_CXSIZE
), 0, SRCCOPY
);
936 SelectObject(hDCSrc
, hobjSrc
);
937 DeleteObject(hbClose
);
940 hobjSrc
= SelectObject( hDCDest
, GetStockObject(BLACK_PEN
) );
942 MoveToEx( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, 0, NULL
);
943 LineTo( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, GetSystemMetrics(SM_CYSIZE
) - 1);
945 SelectObject(hDCDest
, hobjSrc
);
946 SelectObject(hDCDest
, hobjDest
);
955 /**********************************************************************
958 static LONG
MDICascade( HWND client
, MDICLIENTINFO
*ci
)
961 BOOL has_icons
= FALSE
;
964 DbgPrint("MDICascade\n");
966 if (ci
->hwndChildMaximized
)
967 SendMessageA( client
, WM_MDIRESTORE
,
968 (WPARAM
)ci
->hwndChildMaximized
, 0);
970 if (ci
->nActiveChildren
== 0) return 0;
972 if (!(win_array
= WIN_ListChildren( client
))) return 0;
974 /* remove all the windows we don't want */
975 for (i
= total
= 0; win_array
[i
]; i
++)
977 if (!IsWindowVisible( win_array
[i
] )) continue;
978 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows */
979 if (IsIconic( win_array
[i
] ))
984 win_array
[total
++] = win_array
[i
];
986 win_array
[total
] = 0;
990 INT delta
= 0, n
= 0, i
;
992 if (has_icons
) delta
= GetSystemMetrics(SM_CYICONSPACING
) + GetSystemMetrics(SM_CYICON
);
994 /* walk the list (backwards) and move windows */
995 for (i
= total
- 1; i
>= 0; i
--)
997 TRACE("move %p to (%ld,%ld) size [%ld,%ld]\n",
998 win_array
[i
], pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
);
1000 MDI_CalcDefaultChildPos(client
, n
++, pos
, delta
);
1001 SetWindowPos( win_array
[i
], 0, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
,
1002 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
1005 HeapFree( GetProcessHeap(), 0, win_array
);
1007 if (has_icons
) ArrangeIconicWindows( client
);
1011 /**********************************************************************
1014 static void MDITile( HWND client
, MDICLIENTINFO
*ci
, WPARAM wParam
)
1018 BOOL has_icons
= FALSE
;
1020 DbgPrint("MDITile\n");
1022 if (ci
->hwndChildMaximized
)
1023 SendMessageA( client
, WM_MDIRESTORE
, (WPARAM
)ci
->hwndChildMaximized
, 0);
1025 if (ci
->nActiveChildren
== 0) return;
1027 if (!(win_array
= WIN_ListChildren( client
))) return;
1029 /* remove all the windows we don't want */
1030 for (i
= total
= 0; win_array
[i
]; i
++)
1032 if (!IsWindowVisible( win_array
[i
] )) continue;
1033 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows (icon titles) */
1034 if (IsIconic( win_array
[i
] ))
1039 if ((wParam
& MDITILE_SKIPDISABLED
) && !IsWindowEnabled( win_array
[i
] )) continue;
1040 win_array
[total
++] = win_array
[i
];
1042 win_array
[total
] = 0;
1044 TRACE("%u windows to tile\n", total
);
1048 HWND
*pWnd
= win_array
;
1050 int x
, y
, xsize
, ysize
;
1051 int rows
, columns
, r
, c
, i
;
1053 GetClientRect(client
,&rect
);
1054 rows
= (int) sqrt((double)total
);
1055 columns
= total
/ rows
;
1057 if( wParam
& MDITILE_HORIZONTAL
) /* version >= 3.1 */
1060 rows
= columns
; /* exchange r and c */
1066 y
= rect
.bottom
- 2 * GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
1067 rect
.bottom
= ( y
- GetSystemMetrics(SM_CYICON
) < rect
.top
)? rect
.bottom
: y
;
1070 ysize
= rect
.bottom
/ rows
;
1071 xsize
= rect
.right
/ columns
;
1073 for (x
= i
= 0, c
= 1; c
<= columns
&& *pWnd
; c
++)
1078 ysize
= rect
.bottom
/ rows
;
1082 for (r
= 1; r
<= rows
&& *pWnd
; r
++, i
++)
1084 SetWindowPos(*pWnd
, 0, x
, y
, xsize
, ysize
,
1085 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
1092 HeapFree( GetProcessHeap(), 0, win_array
);
1093 if (has_icons
) ArrangeIconicWindows( client
);
1096 /* ----------------------- Frame window ---------------------------- */
1099 /**********************************************************************
1100 * MDI_AugmentFrameMenu
1102 static BOOL
MDI_AugmentFrameMenu( HWND frame
, HWND hChild
)
1104 HMENU menu
= GetMenu( frame
);
1105 HMENU hSysPopup
= 0;
1106 HBITMAP hSysMenuBitmap
= 0;
1111 TRACE("frame %p,child %p\n",frame
,hChild
);
1113 if( !menu
) return 0;
1115 /* if the system buttons already exist do not add them again */
1116 nItems
= GetMenuItemCount(menu
) - 1;
1117 iId
= GetMenuItemID(menu
,nItems
) ;
1118 if (iId
== SC_RESTORE
|| iId
== SC_CLOSE
)
1121 /* create a copy of sysmenu popup and insert it into frame menu bar */
1122 if (!(hSysPopup
= GetSystemMenu(hChild
, FALSE
)))
1125 AppendMenuW(menu
, MF_HELP
| MF_BITMAP
,
1126 SC_MINIMIZE
, (LPCWSTR
)HBMMENU_MBAR_MINIMIZE
) ;
1127 AppendMenuW(menu
, MF_HELP
| MF_BITMAP
,
1128 SC_RESTORE
, (LPCWSTR
)HBMMENU_MBAR_RESTORE
);
1129 AppendMenuW(menu
, MF_HELP
| MF_BITMAP
,
1130 SC_CLOSE
, is_close_enabled(hChild
, hSysPopup
) ?
1131 (LPCWSTR
)HBMMENU_MBAR_CLOSE
: (LPCWSTR
)HBMMENU_MBAR_CLOSE_D
);
1133 /* The system menu is replaced by the child icon */
1134 hIcon
= (HICON
)GetClassLongW(hChild
, GCL_HICONSM
);
1136 hIcon
= (HICON
)GetClassLongW(hChild
, GCL_HICON
);
1138 hIcon
= LoadIconW(NULL
, IDI_APPLICATION
);
1142 HBITMAP hBitmap
, hOldBitmap
;
1144 HDC hdc
= GetDC(hChild
);
1149 cx
= GetSystemMetrics(SM_CXSMICON
);
1150 cy
= GetSystemMetrics(SM_CYSMICON
);
1151 hMemDC
= CreateCompatibleDC(hdc
);
1152 hBitmap
= CreateCompatibleBitmap(hdc
, cx
, cy
);
1153 hOldBitmap
= SelectObject(hMemDC
, hBitmap
);
1154 SetMapMode(hMemDC
, MM_TEXT
);
1155 hBrush
= CreateSolidBrush(GetSysColor(COLOR_MENU
));
1156 DrawIconEx(hMemDC
, 0, 0, hIcon
, cx
, cy
, 0, hBrush
, DI_NORMAL
);
1157 SelectObject (hMemDC
, hOldBitmap
);
1158 DeleteObject(hBrush
);
1160 ReleaseDC(hChild
, hdc
);
1161 hSysMenuBitmap
= hBitmap
;
1165 if( !InsertMenuA(menu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
1166 (UINT_PTR
)hSysPopup
, (LPSTR
)hSysMenuBitmap
))
1168 TRACE("not inserted\n");
1169 DestroyMenu(hSysPopup
);
1173 EnableMenuItem(hSysPopup
, SC_SIZE
, MF_BYCOMMAND
| MF_GRAYED
);
1174 EnableMenuItem(hSysPopup
, SC_MOVE
, MF_BYCOMMAND
| MF_GRAYED
);
1175 EnableMenuItem(hSysPopup
, SC_MAXIMIZE
, MF_BYCOMMAND
| MF_GRAYED
);
1176 SetMenuDefaultItem(hSysPopup
, SC_CLOSE
, FALSE
);
1184 /**********************************************************************
1185 * MDI_RestoreFrameMenu
1187 static BOOL
MDI_RestoreFrameMenu( HWND frame
, HWND hChild
)
1189 MENUITEMINFOW menuInfo
;
1190 HMENU menu
= GetMenu( frame
);
1191 INT nItems
= GetMenuItemCount(menu
) - 1;
1192 UINT iId
= GetMenuItemID(menu
,nItems
) ;
1194 TRACE("frame %p,child %p,nIt=%d,iId=%d\n",frame
,hChild
,nItems
,iId
);
1196 if(!(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
1200 * Remove the system menu, If that menu is the icon of the window
1201 * as it is in win95, we have to delete the bitmap.
1203 memset(&menuInfo
, 0, sizeof(menuInfo
));
1204 menuInfo
.cbSize
= sizeof(menuInfo
);
1205 menuInfo
.fMask
= MIIM_DATA
| MIIM_TYPE
| MIIM_BITMAP
;
1207 GetMenuItemInfoW(menu
,
1212 RemoveMenu(menu
,0,MF_BYPOSITION
);
1214 if ( menuInfo
.hbmpItem
!= 0 )
1215 DeleteObject(menuInfo
.hbmpItem
);
1218 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
1220 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
1222 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
1230 /**********************************************************************
1231 * MDI_UpdateFrameText
1233 * used when child window is maximized/restored
1235 * Note: lpTitle can be NULL
1237 static void MDI_UpdateFrameText( HWND frame
, HWND hClient
,
1238 BOOL repaint
, LPCWSTR lpTitle
)
1240 WCHAR lpBuffer
[MDI_MAXTITLELENGTH
+1];
1241 MDICLIENTINFO
*ci
= get_client_info( hClient
);
1243 TRACE("repaint %i, frameText %s\n", repaint
, debugstr_w(lpTitle
));
1247 if (!lpTitle
&& !ci
->frameTitle
) /* first time around, get title from the frame window */
1249 GetWindowTextW( frame
, lpBuffer
, sizeof(lpBuffer
)/sizeof(WCHAR
) );
1253 /* store new "default" title if lpTitle is not NULL */
1256 if (ci
->frameTitle
) HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1257 if ((ci
->frameTitle
= HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle
)+1)*sizeof(WCHAR
))))
1258 strcpyW( ci
->frameTitle
, lpTitle
);
1263 if (ci
->hwndChildMaximized
)
1265 /* combine frame title and child title if possible */
1267 static const WCHAR lpBracket
[] = {' ','-',' ','[',0};
1268 static const WCHAR lpBracket2
[] = {']',0};
1269 int i_frame_text_length
= strlenW(ci
->frameTitle
);
1271 lstrcpynW( lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
1273 if( i_frame_text_length
+ 6 < MDI_MAXTITLELENGTH
)
1275 strcatW( lpBuffer
, lpBracket
);
1276 if (GetWindowTextW( ci
->hwndChildMaximized
, lpBuffer
+ i_frame_text_length
+ 4,
1277 MDI_MAXTITLELENGTH
- i_frame_text_length
- 5 ))
1278 strcatW( lpBuffer
, lpBracket2
);
1280 lpBuffer
[i_frame_text_length
] = 0; /* remove bracket */
1285 lstrcpynW(lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
+1 );
1291 DefWindowProcW( frame
, WM_SETTEXT
, 0, (LPARAM
)lpBuffer
);
1292 if( repaint
== MDI_REPAINTFRAME
)
1293 SetWindowPos( frame
, 0,0,0,0,0, SWP_FRAMECHANGED
|
1294 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
1298 /* ----------------------------- Interface ---------------------------- */
1301 /**********************************************************************
1302 * MDIClientWndProc_common
1304 static LRESULT
MDIClientWndProc_common( HWND hwnd
, UINT message
,
1305 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1307 MDICLIENTINFO
*ci
= NULL
;
1309 if (WM_NCCREATE
!= message
1310 && NULL
== (ci
= get_client_info(hwnd
)))
1319 if (!(ci
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ci
))))
1321 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)ci
);
1328 /* Since we are using only cs->lpCreateParams, we can safely
1329 * cast to LPCREATESTRUCTA here */
1330 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
1332 WND
*wndPtr
= WIN_GetPtr( hwnd
);
1335 /* Translation layer doesn't know what's in the cs->lpCreateParams
1336 * so we have to keep track of what environment we're in. */
1339 if( wndPtr
->flags
& WIN_ISWIN32
)
1342 #define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1343 ci
->hWindowMenu
= ccs
->hWindowMenu
;
1344 ci
->idFirstChild
= ccs
->idFirstChild
;
1350 LPCLIENTCREATESTRUCT16 ccs
= MapSL((SEGPTR
)cs
->lpCreateParams
);
1351 ci
->hWindowMenu
= HMENU_32(ccs
->hWindowMenu
);
1352 ci
->idFirstChild
= ccs
->idFirstChild
;
1354 WIN_ReleasePtr( wndPtr
);
1357 ci
->hwndChildMaximized
= 0;
1358 ci
->nActiveChildren
= 0;
1359 ci
->nTotalCreated
= 0;
1360 ci
->frameTitle
= NULL
;
1362 SetWindowLongW( hwnd
, GWL_STYLE
, GetWindowLongW(hwnd
,GWL_STYLE
) | WS_CLIPCHILDREN
);
1364 if (!hBmpClose
) hBmpClose
= CreateMDIMenuBitmap();
1366 if (ci
->hWindowMenu
!= 0)
1367 AppendMenuW( ci
->hWindowMenu
, MF_SEPARATOR
, 0, NULL
);
1369 GetClientRect( GetParent(hwnd
), &rect
);
1370 MoveWindow( hwnd
, 0, 0, rect
.right
, rect
.bottom
, FALSE
);
1372 MDI_UpdateFrameText( GetParent(hwnd
), hwnd
, MDI_NOFRAMEREPAINT
, NULL
);
1374 TRACE("Client created - hwnd = %p, idFirst = %u\n", hwnd
, ci
->idFirstChild
);
1381 if( ci
->hwndChildMaximized
)
1382 MDI_RestoreFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
1383 if((ci
->hWindowMenu
!= 0) &&
1384 (nItems
= GetMenuItemCount(ci
->hWindowMenu
)) > 0)
1386 ci
->idFirstChild
= nItems
- 1;
1387 ci
->nActiveChildren
++; /* to delete a separator */
1388 while( ci
->nActiveChildren
-- )
1389 DeleteMenu(ci
->hWindowMenu
,MF_BYPOSITION
,ci
->idFirstChild
--);
1391 if (ci
->frameTitle
) HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1393 HeapFree( GetProcessHeap(), 0, ci
);
1394 SetWindowLongPtrW( hwnd
, 0, 0 );
1399 case WM_MDIACTIVATE
:
1400 if( ci
->hwndActiveChild
!= (HWND
)wParam
)
1401 SetWindowPos((HWND
)wParam
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1405 return MDICascade(hwnd
, ci
);
1409 return (LRESULT
)MDICreateChild( hwnd
, ci
, (MDICREATESTRUCTA
*)lParam
, unicode
);
1414 return MDIDestroyChild( hwnd
, ci
, WIN_GetFullHandle( (HWND
)wParam
), TRUE
);
1416 return MDIDestroyChild( hwnd
, ci
, (HWND
)wParam
, TRUE
);
1419 case WM_MDIGETACTIVE
:
1420 if (lParam
) *(BOOL
*)lParam
= (ci
->hwndChildMaximized
!= 0);
1421 return (LRESULT
)ci
->hwndActiveChild
;
1423 case WM_MDIICONARRANGE
:
1424 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1425 ArrangeIconicWindows( hwnd
);
1426 ci
->sbRecalc
= SB_BOTH
+1;
1427 SendMessageW( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0 );
1430 case WM_MDIMAXIMIZE
:
1431 ShowWindow( (HWND
)wParam
, SW_MAXIMIZE
);
1434 case WM_MDINEXT
: /* lParam != 0 means previous window */
1436 MDI_SwitchActiveChild( hwnd
, WIN_GetFullHandle( (HWND
)wParam
), !lParam
);
1438 MDI_SwitchActiveChild( hwnd
, (HWND
)wParam
, !lParam
);
1443 SendMessageW( (HWND
)wParam
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
1447 return MDISetMenu( hwnd
, (HMENU
)wParam
, (HMENU
)lParam
);
1449 case WM_MDIREFRESHMENU
:
1450 return MDIRefreshMenu( hwnd
, (HMENU
)wParam
, (HMENU
)lParam
);
1453 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1454 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
1455 MDITile( hwnd
, ci
, wParam
);
1456 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1461 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1462 ScrollChildren( hwnd
, message
, wParam
, lParam
);
1463 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1467 if (ci
->hwndActiveChild
&& !IsIconic( ci
->hwndActiveChild
))
1468 SetFocus( ci
->hwndActiveChild
);
1472 if( ci
->hwndActiveChild
)
1473 SendMessageW(ci
->hwndActiveChild
, message
, wParam
, lParam
);
1476 case WM_PARENTNOTIFY
:
1477 if (LOWORD(wParam
) == WM_LBUTTONDOWN
)
1481 pt
.x
= (short)LOWORD(lParam
);
1482 pt
.y
= (short)HIWORD(lParam
);
1483 child
= ChildWindowFromPoint(hwnd
, pt
);
1485 TRACE("notification from %p (%li,%li)\n",child
,pt
.x
,pt
.y
);
1487 if( child
&& child
!= hwnd
&& child
!= ci
->hwndActiveChild
)
1488 SetWindowPos(child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1493 if( IsWindow(ci
->hwndChildMaximized
) )
1499 rect
.right
= LOWORD(lParam
);
1500 rect
.bottom
= HIWORD(lParam
);
1502 AdjustWindowRectEx(&rect
, GetWindowLongA(ci
->hwndChildMaximized
,GWL_STYLE
),
1503 0, GetWindowLongA(ci
->hwndChildMaximized
,GWL_EXSTYLE
) );
1504 MoveWindow(ci
->hwndChildMaximized
, rect
.left
, rect
.top
,
1505 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 1);
1508 MDI_PostUpdate(hwnd
, ci
, SB_BOTH
+1);
1512 case WM_MDICALCCHILDSCROLL
:
1513 if( (ci
->mdiFlags
& MDIF_NEEDUPDATE
) && ci
->sbRecalc
)
1515 CalcChildScroll(hwnd
, ci
->sbRecalc
-1);
1517 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1521 return unicode
? DefWindowProcW( hwnd
, message
, wParam
, lParam
) :
1522 DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1525 /***********************************************************************
1528 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1530 if (!IsWindow(hwnd
)) return 0;
1531 return MDIClientWndProc_common( hwnd
, message
, wParam
, lParam
, FALSE
);
1534 /***********************************************************************
1537 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1539 if (!IsWindow(hwnd
)) return 0;
1540 return MDIClientWndProc_common( hwnd
, message
, wParam
, lParam
, TRUE
);
1544 /***********************************************************************
1545 * DefFrameProc (USER.445)
1547 LRESULT WINAPI
DefFrameProc16( HWND16 hwnd
, HWND16 hwndMDIClient
,
1548 UINT16 message
, WPARAM16 wParam
, LPARAM lParam
)
1553 lParam
= (LPARAM
)MapSL(lParam
);
1559 return DefFrameProcA( WIN_Handle32(hwnd
), WIN_Handle32(hwndMDIClient
),
1560 message
, wParam
, lParam
);
1564 MDINEXTMENU next_menu
;
1565 DefFrameProcW( WIN_Handle32(hwnd
), WIN_Handle32(hwndMDIClient
),
1566 message
, wParam
, (LPARAM
)&next_menu
);
1567 return MAKELONG( HMENU_16(next_menu
.hmenuNext
), HWND_16(next_menu
.hwndNext
) );
1570 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1575 /***********************************************************************
1576 * DefFrameProcA (USER32.@)
1578 LRESULT WINAPI
DefFrameProcA( HWND hwnd
, HWND hwndMDIClient
,
1579 UINT message
, WPARAM wParam
, LPARAM lParam
)
1587 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, NULL
, 0 );
1588 LPWSTR text
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1589 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, text
, len
);
1590 MDI_UpdateFrameText(hwnd
, hwndMDIClient
, MDI_REPAINTFRAME
, text
);
1591 HeapFree( GetProcessHeap(), 0, text
);
1593 return 1; /* success. FIXME: check text length */
1600 return DefFrameProcW( hwnd
, hwndMDIClient
, message
, wParam
, lParam
);
1603 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1607 /***********************************************************************
1608 * DefFrameProcW (USER32.@)
1610 LRESULT WINAPI
DefFrameProcW( HWND hwnd
, HWND hwndMDIClient
,
1611 UINT message
, WPARAM wParam
, LPARAM lParam
)
1613 MDICLIENTINFO
*ci
= get_client_info( hwndMDIClient
);
1621 WORD id
= LOWORD(wParam
);
1622 /* check for possible syscommands for maximized MDI child */
1623 if (id
< ci
->idFirstChild
|| id
>= ci
->idFirstChild
+ ci
->nActiveChildren
)
1625 if( (id
- 0xf000) & 0xf00f ) break;
1626 if( !ci
->hwndChildMaximized
) break;
1630 if (!is_close_enabled(ci
->hwndActiveChild
, 0)) break;
1638 return SendMessageW( ci
->hwndChildMaximized
, WM_SYSCOMMAND
,
1645 if (id
- ci
->idFirstChild
== MDI_MOREWINDOWSLIMIT
)
1646 /* User chose "More Windows..." */
1647 childHwnd
= MDI_MoreWindowsDialog(hwndMDIClient
);
1649 /* User chose one of the windows listed in the "Windows" menu */
1650 childHwnd
= MDI_GetChildByID(hwndMDIClient
,id
);
1653 SendMessageW( hwndMDIClient
, WM_MDIACTIVATE
, (WPARAM
)childHwnd
, 0 );
1659 SendMessageW(hwndMDIClient
, message
, wParam
, lParam
);
1663 MDI_UpdateFrameText(hwnd
, hwndMDIClient
, MDI_REPAINTFRAME
, (LPWSTR
)lParam
);
1664 return 1; /* success. FIXME: check text length */
1667 SetFocus(hwndMDIClient
);
1671 MoveWindow(hwndMDIClient
, 0, 0, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1678 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1680 if (!IsIconic(hwnd
) && ci
->hwndActiveChild
&& !ci
->hwndChildMaximized
)
1682 /* control menu is between the frame system menu and
1683 * the first entry of menu bar */
1684 WND
*wndPtr
= WIN_GetPtr(hwnd
);
1686 if( (wParam
== VK_LEFT
&& GetMenu(hwnd
) == next_menu
->hmenuIn
) ||
1687 (wParam
== VK_RIGHT
&& GetSubMenu(wndPtr
->hSysMenu
, 0) == next_menu
->hmenuIn
) )
1689 WIN_ReleasePtr(wndPtr
);
1690 wndPtr
= WIN_GetPtr(ci
->hwndActiveChild
);
1691 next_menu
->hmenuNext
= GetSubMenu(wndPtr
->hSysMenu
, 0);
1692 next_menu
->hwndNext
= ci
->hwndActiveChild
;
1694 WIN_ReleasePtr(wndPtr
);
1702 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1707 /***********************************************************************
1708 * DefMDIChildProc (USER.447)
1710 LRESULT WINAPI
DefMDIChildProc16( HWND16 hwnd
, UINT16 message
,
1711 WPARAM16 wParam
, LPARAM lParam
)
1716 return DefMDIChildProcA( WIN_Handle32(hwnd
), message
, wParam
, (LPARAM
)MapSL(lParam
) );
1720 case WM_CHILDACTIVATE
:
1725 return DefMDIChildProcW( WIN_Handle32(hwnd
), message
, wParam
, lParam
);
1726 case WM_GETMINMAXINFO
:
1728 MINMAXINFO16
*mmi16
= (MINMAXINFO16
*)MapSL(lParam
);
1730 STRUCT32_MINMAXINFO16to32( mmi16
, &mmi
);
1731 DefMDIChildProcW( WIN_Handle32(hwnd
), message
, wParam
, (LPARAM
)&mmi
);
1732 STRUCT32_MINMAXINFO32to16( &mmi
, mmi16
);
1737 MDINEXTMENU next_menu
;
1738 DefMDIChildProcW( WIN_Handle32(hwnd
), message
, wParam
, (LPARAM
)&next_menu
);
1739 return MAKELONG( HMENU_16(next_menu
.hmenuNext
), HWND_16(next_menu
.hwndNext
) );
1742 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1748 /***********************************************************************
1749 * DefMDIChildProcA (USER32.@)
1751 LRESULT WINAPI
DefMDIChildProcA( HWND hwnd
, UINT message
,
1752 WPARAM wParam
, LPARAM lParam
)
1754 HWND client
= GetParent(hwnd
);
1755 MDICLIENTINFO
*ci
= get_client_info( client
);
1758 hwnd
= WIN_GetFullHandle( hwnd
);
1760 if (!ci
) return DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1765 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1766 MDI_MenuModifyItem( client
, hwnd
);
1767 if( ci
->hwndChildMaximized
== hwnd
)
1768 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1769 return 1; /* success. FIXME: check text length */
1771 case WM_GETMINMAXINFO
:
1775 case WM_CHILDACTIVATE
:
1784 return DefMDIChildProcW( hwnd
, message
, wParam
, lParam
);
1786 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1790 /***********************************************************************
1791 * DefMDIChildProcW (USER32.@)
1793 LRESULT WINAPI
DefMDIChildProcW( HWND hwnd
, UINT message
,
1794 WPARAM wParam
, LPARAM lParam
)
1796 HWND client
= GetParent(hwnd
);
1797 MDICLIENTINFO
*ci
= get_client_info( client
);
1800 hwnd
= WIN_GetFullHandle( hwnd
);
1802 if (!ci
) return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1807 DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1808 MDI_MenuModifyItem( client
, hwnd
);
1809 if( ci
->hwndChildMaximized
== hwnd
)
1810 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1811 return 1; /* success. FIXME: check text length */
1813 case WM_GETMINMAXINFO
:
1814 MDI_ChildGetMinMaxInfo( client
, hwnd
, (MINMAXINFO
*)lParam
);
1818 return 0x00010000; /* MDI children don't have menu bars */
1821 SendMessageW( client
, WM_MDIDESTROY
, (WPARAM
)hwnd
, 0 );
1825 if (ci
->hwndActiveChild
!= hwnd
) MDI_ChildActivate( client
, hwnd
);
1828 case WM_CHILDACTIVATE
:
1829 MDI_ChildActivate( client
, hwnd
);
1836 if( ci
->hwndChildMaximized
== hwnd
) return 0;
1840 SetWindowLongW( hwnd
, GWL_STYLE
,
1841 GetWindowLongW( hwnd
, GWL_STYLE
) | WS_SYSMENU
);
1844 if (ci
->hwndChildMaximized
== hwnd
)
1845 return SendMessageW( GetParent(client
), message
, wParam
, lParam
);
1846 SetWindowLongW( hwnd
, GWL_STYLE
,
1847 GetWindowLongW( hwnd
, GWL_STYLE
) & ~WS_SYSMENU
);
1850 SendMessageW( client
, WM_MDINEXT
, 0, 0);
1853 SendMessageW( client
, WM_MDINEXT
, 0, 1);
1862 if( ci
->hwndChildMaximized
) ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1863 else MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1867 if( ci
->hwndActiveChild
== hwnd
&& wParam
!= SIZE_MAXIMIZED
)
1869 ci
->hwndChildMaximized
= 0;
1870 MDI_RestoreFrameMenu( GetParent(client
), hwnd
);
1871 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1874 if( wParam
== SIZE_MAXIMIZED
)
1876 HWND hMaxChild
= ci
->hwndChildMaximized
;
1878 if( hMaxChild
== hwnd
) break;
1881 SendMessageW( hMaxChild
, WM_SETREDRAW
, FALSE
, 0 );
1882 MDI_RestoreFrameMenu( GetParent(client
), hMaxChild
);
1883 ShowWindow( hMaxChild
, SW_SHOWNOACTIVATE
);
1884 SendMessageW( hMaxChild
, WM_SETREDRAW
, TRUE
, 0 );
1886 TRACE("maximizing child %p\n", hwnd
);
1888 /* keep track of the maximized window. */
1889 ci
->hwndChildMaximized
= hwnd
; /* !!! */
1891 /* The maximized window should also be the active window */
1892 MDI_ChildActivate( client
, hwnd
);
1893 MDI_AugmentFrameMenu( GetParent(client
), hwnd
);
1894 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1897 if( wParam
== SIZE_MINIMIZED
)
1899 HWND switchTo
= MDI_GetWindow(ci
, hwnd
, TRUE
, WS_MINIMIZE
);
1901 if (switchTo
) SendMessageW( switchTo
, WM_CHILDACTIVATE
, 0, 0);
1903 MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1910 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1911 HWND parent
= GetParent(client
);
1913 if( wParam
== VK_LEFT
) /* switch to frame system menu */
1915 WND
*wndPtr
= WIN_GetPtr( parent
);
1916 next_menu
->hmenuNext
= GetSubMenu( wndPtr
->hSysMenu
, 0 );
1917 WIN_ReleasePtr( wndPtr
);
1919 if( wParam
== VK_RIGHT
) /* to frame menu bar */
1921 next_menu
->hmenuNext
= GetMenu(parent
);
1923 next_menu
->hwndNext
= parent
;
1931 SendMessageW( hwnd
, WM_SYSCOMMAND
, (WPARAM
)SC_KEYMENU
, (DWORD
)VK_SPACE
);
1936 return DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1939 /**********************************************************************
1940 * CreateMDIWindowA (USER32.@) Creates a MDI child
1943 * Success: Handle to created window
1946 HWND WINAPI
CreateMDIWindowA(
1947 LPCSTR lpClassName
, /* [in] Pointer to registered child class name */
1948 LPCSTR lpWindowName
, /* [in] Pointer to window name */
1949 DWORD dwStyle
, /* [in] Window style */
1950 INT X
, /* [in] Horizontal position of window */
1951 INT Y
, /* [in] Vertical position of window */
1952 INT nWidth
, /* [in] Width of window */
1953 INT nHeight
, /* [in] Height of window */
1954 HWND hWndParent
, /* [in] Handle to parent window */
1955 HINSTANCE hInstance
, /* [in] Handle to application instance */
1956 LPARAM lParam
) /* [in] Application-defined value */
1958 MDICLIENTINFO
*pCi
= get_client_info( hWndParent
);
1959 MDICREATESTRUCTA cs
;
1961 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%p,%p,%ld)\n",
1962 debugstr_a(lpClassName
),debugstr_a(lpWindowName
),dwStyle
,X
,Y
,
1963 nWidth
,nHeight
,hWndParent
,hInstance
,lParam
);
1967 ERR("bad hwnd for MDI-client: %p\n", hWndParent
);
1970 cs
.szClass
=lpClassName
;
1971 cs
.szTitle
=lpWindowName
;
1972 cs
.hOwner
=hInstance
;
1980 return MDICreateChild(hWndParent
, pCi
, &cs
, FALSE
);
1983 /***********************************************************************
1984 * CreateMDIWindowW (USER32.@) Creates a MDI child
1987 * Success: Handle to created window
1990 HWND WINAPI
CreateMDIWindowW(
1991 LPCWSTR lpClassName
, /* [in] Pointer to registered child class name */
1992 LPCWSTR lpWindowName
, /* [in] Pointer to window name */
1993 DWORD dwStyle
, /* [in] Window style */
1994 INT X
, /* [in] Horizontal position of window */
1995 INT Y
, /* [in] Vertical position of window */
1996 INT nWidth
, /* [in] Width of window */
1997 INT nHeight
, /* [in] Height of window */
1998 HWND hWndParent
, /* [in] Handle to parent window */
1999 HINSTANCE hInstance
, /* [in] Handle to application instance */
2000 LPARAM lParam
) /* [in] Application-defined value */
2002 MDICLIENTINFO
*pCi
= get_client_info( hWndParent
);
2003 MDICREATESTRUCTW cs
;
2005 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%p,%p,%ld)\n",
2006 debugstr_w(lpClassName
), debugstr_w(lpWindowName
), dwStyle
, X
, Y
,
2007 nWidth
, nHeight
, hWndParent
, hInstance
, lParam
);
2011 ERR("bad hwnd for MDI-client: %p\n", hWndParent
);
2014 cs
.szClass
= lpClassName
;
2015 cs
.szTitle
= lpWindowName
;
2016 cs
.hOwner
= hInstance
;
2024 return MDICreateChild(hWndParent
, pCi
, (MDICREATESTRUCTA
*)&cs
, TRUE
);
2027 /**********************************************************************
2028 * TranslateMDISysAccel (USER32.@)
2030 BOOL WINAPI
TranslateMDISysAccel( HWND hwndClient
, LPMSG msg
)
2032 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
)
2034 MDICLIENTINFO
*ci
= get_client_info( hwndClient
);
2037 if (!ci
|| !IsWindowEnabled(ci
->hwndActiveChild
)) return 0;
2039 /* translate if the Ctrl key is down and Alt not. */
2041 if( (GetKeyState(VK_CONTROL
) & 0x8000) && !(GetKeyState(VK_MENU
) & 0x8000))
2043 switch( msg
->wParam
)
2047 wParam
= ( GetKeyState(VK_SHIFT
) & 0x8000 ) ? SC_NEXTWINDOW
: SC_PREVWINDOW
;
2051 if (is_close_enabled(ci
->hwndActiveChild
, 0))
2060 TRACE("wParam = %04x\n", wParam
);
2061 SendMessageW(ci
->hwndActiveChild
, WM_SYSCOMMAND
, wParam
, (LPARAM
)msg
->wParam
);
2065 return 0; /* failure */
2068 /***********************************************************************
2069 * CalcChildScroll (USER32.@)
2071 void WINAPI
CalcChildScroll( HWND hwnd
, INT scroll
)
2074 RECT childRect
, clientRect
;
2078 WINDOWINFO WindowInfo
;
2081 /* The rectangle returned by GetClientRect always has 0,0 as top left
2082 * because it is in client coordinates. The rectangles returned by
2083 * GetWindowRect are in screen coordinates to make this complicated.
2085 * Apparently (in ReactOS at least) the rcClient returned by GetWindowInfo
2086 * is in screen coordinates too.
2089 GetClientRect( hwnd
, &clientRect
);
2090 SetRectEmpty( &childRect
);
2093 if ((list
= WIN_ListChildren( hwnd
)))
2096 for (i
= 0; list
[i
]; i
++)
2098 DWORD style
= GetWindowLongW( list
[i
], GWL_STYLE
);
2099 if (style
& WS_MAXIMIZE
)
2101 HeapFree( GetProcessHeap(), 0, list
);
2102 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
2105 if (style
& WS_VISIBLE
)
2107 WND
*pWnd
= WIN_FindWndPtr( list
[i
] );
2108 UnionRect( &childRect
, &pWnd
->rectWindow
, &childRect
);
2109 WIN_ReleaseWndPtr( pWnd
);
2112 HeapFree( GetProcessHeap(), 0, list
);
2115 WindowInfo
.cbSize
= sizeof(WindowInfo
);
2116 if (!GetWindowInfo(hwnd
, &WindowInfo
))
2118 ERR("Can't get window info\n");
2122 hWndCurrent
= GetWindow(hwnd
, GW_CHILD
);
2123 while (hWndCurrent
!= NULL
)
2125 DWORD style
= GetWindowLongW( hWndCurrent
, GWL_STYLE
);
2126 if (style
& WS_MAXIMIZE
)
2128 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
2131 if (style
& WS_VISIBLE
)
2135 GetWindowRect( hWndCurrent
, &WindowRect
);
2136 OffsetRect(&WindowRect
,
2137 -WindowInfo
.rcClient
.left
,
2138 -WindowInfo
.rcClient
.top
);
2139 UnionRect( &childRect
, &WindowRect
, &childRect
);
2141 hWndCurrent
= GetWindow(hWndCurrent
, GW_HWNDNEXT
);
2144 UnionRect( &childRect
, &clientRect
, &childRect
);
2146 /* set common info values */
2147 info
.cbSize
= sizeof(info
);
2148 info
.fMask
= SIF_POS
| SIF_RANGE
| SIF_PAGE
;
2150 /* set the specific scrollbars*/
2151 /* Note how we set nPos to 0 because we scroll the clients instead of
2152 * the window, and we set nPage to 1 bigger than the clientRect because
2153 * otherwise the scrollbar never disables. This causes a somewhat ugly
2154 * effect though while scrolling.
2160 info
.nMin
= childRect
.left
;
2161 info
.nMax
= childRect
.right
;
2163 info
.nPage
= 1 + clientRect
.right
- clientRect
.left
;
2164 SetScrollInfo(hwnd
, SB_HORZ
, &info
, TRUE
);
2165 if (scroll
== SB_HORZ
) break;
2168 info
.nMin
= childRect
.top
;
2169 info
.nMax
= childRect
.bottom
;
2171 info
.nPage
= 1 + clientRect
.bottom
- clientRect
.top
;
2172 SetScrollInfo(hwnd
, SB_VERT
, &info
, TRUE
);
2178 /***********************************************************************
2179 * ScrollChildren (USER32.@)
2181 void WINAPI
ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
,
2185 INT curPos
, length
, minPos
, maxPos
, shift
;
2188 GetClientRect( hWnd
, &rect
);
2193 GetScrollRange(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
2194 curPos
= GetScrollPos(hWnd
,SB_HORZ
);
2195 length
= (rect
.right
- rect
.left
) / 2;
2196 shift
= GetSystemMetrics(SM_CYHSCROLL
);
2199 GetScrollRange(hWnd
,SB_VERT
,&minPos
,&maxPos
);
2200 curPos
= GetScrollPos(hWnd
,SB_VERT
);
2201 length
= (rect
.bottom
- rect
.top
) / 2;
2202 shift
= GetSystemMetrics(SM_CXVSCROLL
);
2211 newPos
= curPos
- shift
;
2214 newPos
= curPos
+ shift
;
2217 newPos
= curPos
- length
;
2220 newPos
= curPos
+ length
;
2223 case SB_THUMBPOSITION
:
2224 newPos
= LOWORD(lParam
);
2237 CalcChildScroll(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
2241 if( newPos
> maxPos
)
2244 if( newPos
< minPos
)
2247 SetScrollPos(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
2249 if( uMsg
== WM_VSCROLL
)
2250 ScrollWindowEx(hWnd
,0 ,curPos
- newPos
, NULL
, NULL
, 0, NULL
,
2251 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
2253 ScrollWindowEx(hWnd
,curPos
- newPos
, 0, NULL
, NULL
, 0, NULL
,
2254 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
2258 /******************************************************************************
2259 * CascadeWindows (USER32.@) Cascades MDI child windows
2262 * Success: Number of cascaded windows.
2266 CascadeWindows (HWND hwndParent
, UINT wFlags
, LPCRECT lpRect
,
2267 UINT cKids
, const HWND
*lpKids
)
2269 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
2274 /******************************************************************************
2275 * TileWindows (USER32.@) Tiles MDI child windows
2278 * Success: Number of tiled windows.
2282 TileWindows (HWND hwndParent
, UINT wFlags
, LPCRECT lpRect
,
2283 UINT cKids
, const HWND
*lpKids
)
2285 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
2289 /************************************************************************
2290 * "More Windows..." functionality
2293 /* MDI_MoreWindowsDlgProc
2295 * This function will process the messages sent to the "More Windows..."
2297 * Return values: 0 = cancel pressed
2298 * HWND = ok pressed or double-click in the list...
2302 static INT_PTR WINAPI
MDI_MoreWindowsDlgProc (HWND hDlg
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
2311 MDICLIENTINFO
*ci
= get_client_info( (HWND
)lParam
);
2312 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2313 HWND
*list
, *sorted_list
;
2315 if (!(list
= WIN_ListChildren( (HWND
)lParam
))) return TRUE
;
2316 if (!(sorted_list
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
2317 sizeof(HWND
) * ci
->nActiveChildren
)))
2319 HeapFree( GetProcessHeap(), 0, list
);
2323 /* Fill the list, sorted by id... */
2324 for (i
= 0; list
[i
]; i
++)
2326 UINT id
= GetWindowLongW( list
[i
], GWL_ID
) - ci
->idFirstChild
;
2327 if (id
< ci
->nActiveChildren
) sorted_list
[id
] = list
[i
];
2329 HeapFree( GetProcessHeap(), 0, list
);
2331 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
2335 if (!GetWindowTextW( sorted_list
[i
], buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
2337 SendMessageW(hListBox
, LB_ADDSTRING
, 0, (LPARAM
)buffer
);
2338 SendMessageW(hListBox
, LB_SETITEMDATA
, i
, (LPARAM
)sorted_list
[i
] );
2339 length
= strlenW(buffer
); /* FIXME: should use GetTextExtentPoint */
2340 if (length
> widest
)
2343 /* Make sure the horizontal scrollbar scrolls ok */
2344 SendMessageW(hListBox
, LB_SETHORIZONTALEXTENT
, widest
* 6, 0);
2346 /* Set the current selection */
2347 SendMessageW(hListBox
, LB_SETCURSEL
, MDI_MOREWINDOWSLIMIT
, 0);
2352 switch (LOWORD(wParam
))
2355 if (HIWORD(wParam
) != LBN_DBLCLK
) break;
2359 /* windows are sorted by menu ID, so we must return the
2360 * window associated to the given id
2362 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2363 UINT index
= SendMessageW(hListBox
, LB_GETCURSEL
, 0, 0);
2364 LRESULT res
= SendMessageW(hListBox
, LB_GETITEMDATA
, index
, 0);
2365 EndDialog(hDlg
, res
);
2379 * MDI_MoreWindowsDialog
2381 * Prompts the user with a listbox containing the opened
2382 * documents. The user can then choose a windows and click
2383 * on OK to set the current window to the one selected, or
2384 * CANCEL to cancel. The function returns a handle to the
2388 static HWND
MDI_MoreWindowsDialog(HWND hwnd
)
2394 hRes
= FindResourceA(User32Instance
, "MDI_MOREWINDOWS", (LPSTR
)RT_DIALOG
);
2399 hDlgTmpl
= LoadResource(User32Instance
, hRes
);
2404 template = LockResource( hDlgTmpl
);
2409 return (HWND
) DialogBoxIndirectParamA(User32Instance
,
2410 (LPDLGTEMPLATE
) template,
2411 hwnd
, MDI_MoreWindowsDlgProc
, (LPARAM
) hwnd
);
2418 * Will swap the menu IDs for the given 2 positions.
2419 * pos1 and pos2 are menu IDs
2424 static void MDI_SwapMenuItems(HWND parent
, UINT pos1
, UINT pos2
)
2429 if (!(list
= WIN_ListChildren( parent
))) return;
2430 for (i
= 0; list
[i
]; i
++)
2432 UINT id
= GetWindowLongW( list
[i
], GWL_ID
);
2433 if (id
== pos1
) SetWindowLongW( list
[i
], GWL_ID
, pos2
);
2434 else if (id
== pos2
) SetWindowLongW( list
[i
], GWL_ID
, pos1
);
2436 HeapFree( GetProcessHeap(), 0, list
);