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
=
217 L
"MDIClient", /* name */
218 CS_GLOBALCLASS
, /* style */
219 MDIClientWndProcW
, /* procW */
220 MDIClientWndProcA
, /* procA */
221 sizeof(MDICLIENTINFO
*), /* extra */
222 IDC_ARROW
, /* cursor */
223 (HBRUSH
)(COLOR_APPWORKSPACE
+1) /* brush */
225 "MDIClient", /* name */
226 CS_GLOBALCLASS
, /* style */
227 MDIClientWndProcW
, /* procW */
228 MDIClientWndProcA
, /* procA */
229 sizeof(MDICLIENTINFO
), /* extra */
230 IDC_ARROW
, /* cursor */
231 (HBRUSH
)(COLOR_APPWORKSPACE
+1) /* brush */
236 static MDICLIENTINFO
*get_client_info( HWND client
)
239 return (MDICLIENTINFO
*)GetWindowLongPtr(client
, 0);
241 MDICLIENTINFO
*ret
= NULL
;
242 WND
*win
= WIN_GetPtr( client
);
245 if (win
== WND_OTHER_PROCESS
)
247 ERR( "client %p belongs to other process\n", client
);
250 if (win
->cbWndExtra
< sizeof(MDICLIENTINFO
)) WARN( "%p is not an MDI client\n", client
);
251 else ret
= (MDICLIENTINFO
*)win
->wExtra
;
252 WIN_ReleasePtr( win
);
258 /**********************************************************************
261 static void MDI_MenuModifyItem( HWND client
, HWND hWndChild
)
263 MDICLIENTINFO
*clientInfo
= get_client_info( client
);
267 if (!clientInfo
|| !clientInfo
->hWindowMenu
) return;
269 id
= GetWindowLongA( hWndChild
, GWL_ID
);
270 if (id
>= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
) return;
272 buffer
[1] = '1' + id
- clientInfo
->idFirstChild
;
274 GetWindowTextW( hWndChild
, buffer
+ 3, sizeof(buffer
)/sizeof(WCHAR
) - 3 );
276 n
= GetMenuState(clientInfo
->hWindowMenu
, id
, MF_BYCOMMAND
);
277 ModifyMenuW(clientInfo
->hWindowMenu
, id
, MF_BYCOMMAND
| MF_STRING
, id
, buffer
);
278 CheckMenuItem(clientInfo
->hWindowMenu
, id
, n
& MF_CHECKED
);
281 /**********************************************************************
284 static BOOL
MDI_MenuDeleteItem( HWND client
, HWND hWndChild
)
287 static const WCHAR format
[] = {'&','%','d',' ',0};
288 MDICLIENTINFO
*clientInfo
= get_client_info( client
);
291 if( !clientInfo
->nActiveChildren
|| !clientInfo
->hWindowMenu
)
294 id
= GetWindowLongA( hWndChild
, GWL_ID
);
295 DeleteMenu(clientInfo
->hWindowMenu
,id
,MF_BYCOMMAND
);
297 /* walk the rest of MDI children to prevent gaps in the id
298 * sequence and in the menu child list */
300 for( index
= id
+1; index
<= clientInfo
->nActiveChildren
+
301 clientInfo
->idFirstChild
; index
++ )
303 HWND hwnd
= MDI_GetChildByID(client
,index
);
306 TRACE("no window for id=%i\n",index
);
311 SetWindowLongW( hwnd
, GWL_ID
, GetWindowLongW( hwnd
, GWL_ID
) - 1 );
313 n
= wsprintfW(buffer
, format
,index
- clientInfo
->idFirstChild
);
314 GetWindowTextW( hwnd
, buffer
+ n
, sizeof(buffer
)/sizeof(WCHAR
) - n
);
316 /* change menu if the current child is to be shown in the
319 if (index
<= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
)
320 ModifyMenuW(clientInfo
->hWindowMenu
,index
,MF_BYCOMMAND
| MF_STRING
,
321 index
- 1 , buffer
);
324 /* We must restore the "More Windows..." option if there are enough children
326 if (clientInfo
->nActiveChildren
- 1 > MDI_MOREWINDOWSLIMIT
)
329 LoadStringW(GetModuleHandleA("USER32"), IDS_MDI_MOREWINDOWS
, szTmp
, sizeof(szTmp
)/sizeof(szTmp
[0]));
330 AppendMenuW(clientInfo
->hWindowMenu
, MF_STRING
, clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
, szTmp
);
335 /**********************************************************************
338 * returns "activateable" child different from the current or zero
340 static HWND
MDI_GetWindow(MDICLIENTINFO
*clientInfo
, HWND hWnd
, BOOL bNext
,
351 dwStyleMask
|= WS_DISABLED
| WS_VISIBLE
;
352 if( !hWnd
) hWnd
= clientInfo
->hwndActiveChild
;
354 if (!(list
= WIN_ListChildren( GetParent(hWnd
) ))) return 0;
356 /* start from next after hWnd */
357 while (list
[i
] && list
[i
] != hWnd
) i
++;
360 for ( ; list
[i
]; i
++)
362 if (GetWindow( list
[i
], GW_OWNER
)) continue;
363 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
365 if (bNext
) goto found
;
367 /* now restart from the beginning */
368 for (i
= 0; list
[i
] && list
[i
] != hWnd
; i
++)
370 if (GetWindow( list
[i
], GW_OWNER
)) continue;
371 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
373 if (bNext
) goto found
;
376 HeapFree( GetProcessHeap(), 0, list
);
381 /**********************************************************************
382 * MDI_CalcDefaultChildPos
384 * It seems that the default height is about 2/3 of the client rect
386 static void MDI_CalcDefaultChildPos( HWND hwnd
, WORD n
, LPPOINT lpPos
, INT delta
)
390 INT spacing
= GetSystemMetrics(SM_CYCAPTION
) +
391 GetSystemMetrics(SM_CYFRAME
) - 1;
393 GetClientRect( hwnd
, &rect
);
394 if( rect
.bottom
- rect
.top
- delta
>= spacing
)
395 rect
.bottom
-= delta
;
397 nstagger
= (rect
.bottom
- rect
.top
)/(3 * spacing
);
398 lpPos
[1].x
= (rect
.right
- rect
.left
- nstagger
* spacing
);
399 lpPos
[1].y
= (rect
.bottom
- rect
.top
- nstagger
* spacing
);
400 lpPos
[0].x
= lpPos
[0].y
= spacing
* (n
%(nstagger
+1));
403 /**********************************************************************
406 static LRESULT
MDISetMenu( HWND hwnd
, HMENU hmenuFrame
,
410 HWND hwndFrame
= GetParent(hwnd
);
411 HMENU oldFrameMenu
= GetMenu(hwndFrame
);
413 TRACE("%p %p %p\n", hwnd
, hmenuFrame
, hmenuWindow
);
415 if (hmenuFrame
&& !IsMenu(hmenuFrame
))
417 WARN("hmenuFrame is not a menu handle\n");
421 if (hmenuWindow
&& !IsMenu(hmenuWindow
))
423 WARN("hmenuWindow is not a menu handle\n");
427 if (!(ci
= get_client_info( hwnd
))) return 0;
429 if( ci
->hwndChildMaximized
&& hmenuFrame
&& hmenuFrame
!=oldFrameMenu
)
430 MDI_RestoreFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
432 if( hmenuWindow
&& hmenuWindow
!= ci
->hWindowMenu
)
434 /* delete menu items from ci->hWindowMenu
435 * and add them to hmenuWindow */
436 /* Agent newsreader calls this function with ci->hWindowMenu == NULL */
437 if( ci
->hWindowMenu
&& ci
->nActiveChildren
)
440 LPWSTR buffer
= NULL
;
442 INT nbWindowsMenuItems
; /* num of documents shown + "More Windows..." if present */
443 INT i
= GetMenuItemCount(ci
->hWindowMenu
) - 1;
444 INT pos
= GetMenuItemCount(hmenuWindow
) + 1;
446 AppendMenuA( hmenuWindow
, MF_SEPARATOR
, 0, NULL
);
448 if (ci
->nActiveChildren
<= MDI_MOREWINDOWSLIMIT
)
449 nbWindowsMenuItems
= ci
->nActiveChildren
;
451 nbWindowsMenuItems
= MDI_MOREWINDOWSLIMIT
+ 1;
453 j
= i
- nbWindowsMenuItems
+ 1;
455 for( ; i
>= j
; i
-- )
457 memset(&mii
, 0, sizeof(mii
));
458 mii
.cbSize
= sizeof(mii
);
459 mii
.fMask
= MIIM_CHECKMARKS
| MIIM_DATA
| MIIM_ID
| MIIM_STATE
460 | MIIM_SUBMENU
| MIIM_TYPE
| MIIM_BITMAP
;
462 GetMenuItemInfoW(ci
->hWindowMenu
, i
, TRUE
, &mii
);
463 if(mii
.cch
) { /* Menu is MFT_STRING */
464 mii
.cch
++; /* add room for '\0' */
465 buffer
= HeapAlloc(GetProcessHeap(), 0,
466 mii
.cch
* sizeof(WCHAR
));
467 mii
.dwTypeData
= buffer
;
468 GetMenuItemInfoW(ci
->hWindowMenu
, i
, TRUE
, &mii
);
470 DeleteMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
471 InsertMenuItemW(hmenuWindow
, pos
, TRUE
, &mii
);
473 HeapFree(GetProcessHeap(), 0, buffer
);
477 /* remove separator */
478 DeleteMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
480 ci
->hWindowMenu
= hmenuWindow
;
485 SetMenu(hwndFrame
, hmenuFrame
);
486 if( hmenuFrame
!=oldFrameMenu
)
488 if( ci
->hwndChildMaximized
)
489 MDI_AugmentFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
490 return (LRESULT
)oldFrameMenu
;
495 HMENU menu
= GetMenu( GetParent(hwnd
) );
496 INT nItems
= GetMenuItemCount(menu
) - 1;
497 UINT iId
= GetMenuItemID(menu
,nItems
) ;
499 if( !(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
501 /* SetMenu() may already have been called, meaning that this window
502 * already has its menu. But they may have done a SetMenu() on
503 * an MDI window, and called MDISetMenu() after the fact, meaning
504 * that the "if" to this "else" wouldn't catch the need to
505 * augment the frame menu.
507 if( ci
->hwndChildMaximized
)
508 MDI_AugmentFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
514 /**********************************************************************
517 static LRESULT
MDIRefreshMenu( HWND hwnd
, HMENU hmenuFrame
,
520 HWND hwndFrame
= GetParent(hwnd
);
521 HMENU oldFrameMenu
= GetMenu(hwndFrame
);
523 TRACE("%p %p %p\n", hwnd
, hmenuFrame
, hmenuWindow
);
525 FIXME("partially function stub\n");
527 return (LRESULT
)oldFrameMenu
;
531 /* ------------------ MDI child window functions ---------------------- */
534 /**********************************************************************
537 static HWND
MDICreateChild( HWND parent
, MDICLIENTINFO
*ci
,
538 LPMDICREATESTRUCTA cs
, BOOL unicode
)
541 DWORD style
= cs
->style
| (WS_CHILD
| WS_CLIPSIBLINGS
);
542 HWND hwnd
, hwndMax
= 0;
543 UINT wIDmenu
= ci
->idFirstChild
+ ci
->nActiveChildren
;
547 static const WCHAR lpstrDef
[] = {'j','u','n','k','!',0};
549 TRACE("origin %i,%i - dim %i,%i, style %08lx\n",
550 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, cs
->style
);
551 /* calculate placement */
552 MDI_CalcDefaultChildPos(parent
, ci
->nTotalCreated
++, pos
, 0);
555 if (cs
->cx
== CW_USEDEFAULT
|| cs
->cx
== CW_USEDEFAULT16
|| !cs
->cx
) cs
->cx
= pos
[1].x
;
556 if (cs
->cy
== CW_USEDEFAULT
|| cs
->cy
== CW_USEDEFAULT16
|| !cs
->cy
) cs
->cy
= pos
[1].y
;
558 if (cs
->x
== CW_USEDEFAULT
|| cs
->x
== CW_USEDEFAULT16
)
560 if (cs
->cx
== CW_USEDEFAULT
|| !cs
->cx
) cs
->cx
= pos
[1].x
;
561 if (cs
->cy
== CW_USEDEFAULT
|| !cs
->cy
) cs
->cy
= pos
[1].y
;
563 if (cs
->x
== CW_USEDEFAULT
)
570 /* restore current maximized child */
571 if( (style
& WS_VISIBLE
) && ci
->hwndChildMaximized
)
573 TRACE("Restoring current maximized child %p\n", ci
->hwndChildMaximized
);
574 if( style
& WS_MAXIMIZE
)
575 SendMessageW(parent
, WM_SETREDRAW
, FALSE
, 0L);
576 hwndMax
= ci
->hwndChildMaximized
;
577 ShowWindow( hwndMax
, SW_SHOWNOACTIVATE
);
578 if( style
& WS_MAXIMIZE
)
579 SendMessageW(parent
, WM_SETREDRAW
, TRUE
, 0L);
582 if (ci
->nActiveChildren
<= MDI_MOREWINDOWSLIMIT
)
583 /* this menu is needed to set a check mark in MDI_ChildActivate */
584 if (ci
->hWindowMenu
!= 0)
585 AppendMenuW(ci
->hWindowMenu
, MF_STRING
, wIDmenu
, lpstrDef
);
587 ci
->nActiveChildren
++;
589 /* fix window style */
591 wndParent
= WIN_FindWndPtr( parent
);
592 if( !(wndParent
->dwStyle
& MDIS_ALLCHILDSTYLES
) )
594 if( !(GetWindowLong(parent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
) )
597 TRACE("MDIS_ALLCHILDSTYLES is missing, fixing window style\n");
598 style
&= (WS_CHILD
| WS_CLIPSIBLINGS
| WS_MINIMIZE
| WS_MAXIMIZE
|
599 WS_CLIPCHILDREN
| WS_DISABLED
| WS_VSCROLL
| WS_HSCROLL
);
600 style
|= (WS_VISIBLE
| WS_OVERLAPPEDWINDOW
);
604 if( wndParent
->flags
& WIN_ISWIN32
)
608 WIN_ReleaseWndPtr( wndParent
);
612 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)cs
;
613 hwnd
= CreateWindowW( csW
->szClass
, csW
->szTitle
, style
,
614 csW
->x
, csW
->y
, csW
->cx
, csW
->cy
, parent
,
615 (HMENU
)wIDmenu
, csW
->hOwner
, csW
);
618 hwnd
= CreateWindowA( cs
->szClass
, cs
->szTitle
, style
,
619 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, parent
,
620 (HMENU
)wIDmenu
, cs
->hOwner
, cs
);
625 MDICREATESTRUCT16 cs16
;
626 SEGPTR title
, cls
, seg_cs16
;
628 WIN_ReleaseWndPtr( wndParent
);
629 STRUCT32_MDICREATESTRUCT32Ato16( cs
, &cs16
);
630 cs16
.szTitle
= title
= MapLS( cs
->szTitle
);
631 cs16
.szClass
= cls
= MapLS( cs
->szClass
);
632 seg_cs16
= MapLS( &cs16
);
633 hwnd
= WIN_Handle32( CreateWindow16( cs
->szClass
, cs
->szTitle
, style
,
634 cs16
.x
, cs16
.y
, cs16
.cx
, cs16
.cy
,
635 HWND_16(parent
), (HMENU16
)wIDmenu
,
636 cs16
.hOwner
, (LPVOID
)seg_cs16
));
643 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
647 /* All MDI child windows have the WS_EX_MDICHILD style */
648 SetWindowLongW( hwnd
, GWL_EXSTYLE
, GetWindowLongW( hwnd
, GWL_EXSTYLE
) | WS_EX_MDICHILD
);
650 /* If we have more than 9 windows, we must insert the new one at the
651 * 9th position in order to see it in the "Windows" menu
653 if (ci
->nActiveChildren
> MDI_MOREWINDOWSLIMIT
)
654 MDI_SwapMenuItems( parent
, GetWindowLongW( hwnd
, GWL_ID
),
655 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1);
657 MDI_MenuModifyItem(parent
, hwnd
);
659 /* Have we hit the "More Windows..." limit? If so, we must
660 * add a "More Windows..." option
662 if (ci
->nActiveChildren
== MDI_MOREWINDOWSLIMIT
+ 1)
665 LoadStringW(GetModuleHandleA("USER32"), IDS_MDI_MOREWINDOWS
, szTmp
, sizeof(szTmp
)/sizeof(szTmp
[0]));
667 ModifyMenuW(ci
->hWindowMenu
,
668 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
,
669 MF_BYCOMMAND
| MF_STRING
,
670 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
,
674 if( IsIconic(hwnd
) && ci
->hwndActiveChild
)
676 TRACE("Minimizing created MDI child %p\n", hwnd
);
677 ShowWindow( hwnd
, SW_SHOWMINNOACTIVE
);
681 /* WS_VISIBLE is clear if a) the MDI client has
682 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
683 * MDICreateStruct. If so the created window is not shown nor
686 if (IsWindowVisible(hwnd
)) ShowWindow(hwnd
, SW_SHOW
);
688 TRACE("created child - %p\n",hwnd
);
692 ci
->nActiveChildren
--;
693 DeleteMenu(ci
->hWindowMenu
,wIDmenu
,MF_BYCOMMAND
);
694 if( IsWindow(hwndMax
) )
695 ShowWindow(hwndMax
, SW_SHOWMAXIMIZED
);
701 /**********************************************************************
702 * MDI_ChildGetMinMaxInfo
704 * Note: The rule here is that client rect of the maximized MDI child
705 * is equal to the client rect of the MDI client window.
707 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
711 GetClientRect( client
, &rect
);
712 AdjustWindowRectEx( &rect
, GetWindowLongW( hwnd
, GWL_STYLE
),
713 0, GetWindowLongW( hwnd
, GWL_EXSTYLE
));
715 lpMinMax
->ptMaxSize
.x
= rect
.right
-= rect
.left
;
716 lpMinMax
->ptMaxSize
.y
= rect
.bottom
-= rect
.top
;
718 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
719 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
721 TRACE("max rect (%ld,%ld - %ld, %ld)\n",
722 rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
725 /**********************************************************************
726 * MDI_SwitchActiveChild
728 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
731 static void MDI_SwitchActiveChild( HWND clientHwnd
, HWND childHwnd
,
736 MDICLIENTINFO
*ci
= get_client_info( clientHwnd
);
738 hwndTo
= MDI_GetWindow(ci
, childHwnd
, bNextWindow
, 0);
740 TRACE("from %p, to %p\n",childHwnd
,hwndTo
);
742 if ( !hwndTo
) return; /* no window to switch to */
744 hwndPrev
= ci
->hwndActiveChild
;
746 if ( hwndTo
!= hwndPrev
)
748 SetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0,
749 SWP_NOMOVE
| SWP_NOSIZE
);
751 if( bNextWindow
&& hwndPrev
)
752 SetWindowPos( hwndPrev
, HWND_BOTTOM
, 0, 0, 0, 0,
753 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
758 /**********************************************************************
761 static LRESULT
MDIDestroyChild( HWND parent
, MDICLIENTINFO
*ci
,
762 HWND child
, BOOL flagDestroy
)
764 if( child
== ci
->hwndActiveChild
)
766 MDI_SwitchActiveChild(parent
, child
, TRUE
);
768 if( child
== ci
->hwndActiveChild
)
770 ShowWindow( child
, SW_HIDE
);
771 if( child
== ci
->hwndChildMaximized
)
773 HWND frame
= GetParent(parent
);
774 MDI_RestoreFrameMenu( frame
, child
);
775 ci
->hwndChildMaximized
= 0;
776 MDI_UpdateFrameText( frame
, parent
, TRUE
, NULL
);
779 MDI_ChildActivate(parent
, 0);
783 MDI_MenuDeleteItem(parent
, child
);
785 ci
->nActiveChildren
--;
787 TRACE("child destroyed - %p\n",child
);
791 MDI_PostUpdate(GetParent(child
), ci
, SB_BOTH
+1);
792 DestroyWindow(child
);
798 /**********************************************************************
801 * Note: hWndChild is NULL when last child is being destroyed
803 static LONG
MDI_ChildActivate( HWND client
, HWND child
)
805 MDICLIENTINFO
*clientInfo
= get_client_info( client
);
806 HWND prevActiveWnd
= clientInfo
->hwndActiveChild
;
807 BOOL isActiveFrameWnd
;
809 if (child
&& (!IsWindowEnabled( child
))) return 0;
811 /* Don't activate if it is already active. Might happen
812 since ShowWindow DOES activate MDI children */
813 if (clientInfo
->hwndActiveChild
== child
) return 0;
815 TRACE("%p\n", child
);
817 isActiveFrameWnd
= (GetActiveWindow() == GetParent(client
));
819 /* deactivate prev. active child */
822 SetWindowLongA( prevActiveWnd
, GWL_STYLE
,
823 GetWindowLongA( prevActiveWnd
, GWL_STYLE
) | WS_SYSMENU
);
824 SendMessageA( prevActiveWnd
, WM_NCACTIVATE
, FALSE
, 0L );
825 SendMessageA( prevActiveWnd
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
826 /* uncheck menu item */
827 if( clientInfo
->hWindowMenu
)
829 UINT prevID
= GetWindowLongA( prevActiveWnd
, GWL_ID
);
831 if (prevID
- clientInfo
->idFirstChild
< MDI_MOREWINDOWSLIMIT
)
832 CheckMenuItem( clientInfo
->hWindowMenu
, prevID
, 0);
834 CheckMenuItem( clientInfo
->hWindowMenu
,
835 clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1, 0);
840 if (clientInfo
->hwndChildMaximized
&& clientInfo
->hwndChildMaximized
!= child
)
842 INT cmd
= SW_SHOWNORMAL
;
846 UINT state
= GetMenuState(GetSystemMenu(child
, FALSE
), SC_MAXIMIZE
, MF_BYCOMMAND
);
847 if (state
!= 0xFFFFFFFF && (state
& (MF_DISABLED
| MF_GRAYED
)))
848 SendMessageW(clientInfo
->hwndChildMaximized
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
850 cmd
= SW_SHOWMAXIMIZED
;
852 clientInfo
->hwndActiveChild
= child
;
855 ShowWindow( clientInfo
->hwndActiveChild
, cmd
);
858 clientInfo
->hwndActiveChild
= child
;
860 /* check if we have any children left */
863 if( isActiveFrameWnd
)
868 /* check menu item */
869 if( clientInfo
->hWindowMenu
)
871 UINT id
= GetWindowLongA( child
, GWL_ID
);
872 /* The window to be activated must be displayed in the "Windows" menu */
873 if (id
>= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
)
875 MDI_SwapMenuItems( GetParent(child
),
876 id
, clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1);
877 id
= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1;
878 MDI_MenuModifyItem( GetParent(child
), child
);
881 CheckMenuItem(clientInfo
->hWindowMenu
, id
, MF_CHECKED
);
883 /* bring active child to the top */
884 SetWindowPos( child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
886 if( isActiveFrameWnd
)
888 SendMessageA( child
, WM_NCACTIVATE
, TRUE
, 0L);
889 if( GetFocus() == client
)
890 SendMessageA( client
, WM_SETFOCUS
, (WPARAM
)client
, 0L );
894 SendMessageA( child
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
898 /* -------------------- MDI client window functions ------------------- */
900 /**********************************************************************
901 * CreateMDIMenuBitmap
903 static HBITMAP
CreateMDIMenuBitmap(void)
905 HDC hDCSrc
= CreateCompatibleDC(0);
906 HDC hDCDest
= CreateCompatibleDC(hDCSrc
);
907 HBITMAP hbClose
= LoadBitmapW(0, MAKEINTRESOURCEW(OBM_CLOSE
) );
909 HBITMAP hobjSrc
, hobjDest
;
911 hobjSrc
= SelectObject(hDCSrc
, hbClose
);
912 hbCopy
= CreateCompatibleBitmap(hDCSrc
,GetSystemMetrics(SM_CXSIZE
),GetSystemMetrics(SM_CYSIZE
));
913 hobjDest
= SelectObject(hDCDest
, hbCopy
);
915 BitBlt(hDCDest
, 0, 0, GetSystemMetrics(SM_CXSIZE
), GetSystemMetrics(SM_CYSIZE
),
916 hDCSrc
, GetSystemMetrics(SM_CXSIZE
), 0, SRCCOPY
);
918 SelectObject(hDCSrc
, hobjSrc
);
919 DeleteObject(hbClose
);
922 hobjSrc
= SelectObject( hDCDest
, GetStockObject(BLACK_PEN
) );
924 MoveToEx( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, 0, NULL
);
925 LineTo( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, GetSystemMetrics(SM_CYSIZE
) - 1);
927 SelectObject(hDCDest
, hobjSrc
);
928 SelectObject(hDCDest
, hobjDest
);
934 /**********************************************************************
937 static LONG
MDICascade( HWND client
, MDICLIENTINFO
*ci
)
944 BOOL has_icons
= FALSE
;
947 if (ci
->hwndChildMaximized
)
948 SendMessageA( client
, WM_MDIRESTORE
,
949 (WPARAM
)ci
->hwndChildMaximized
, 0);
951 if (ci
->nActiveChildren
== 0) return 0;
953 if (!(win_array
= WIN_ListChildren( client
))) return 0;
955 /* remove all the windows we don't want */
956 for (i
= total
= 0; win_array
[i
]; i
++)
958 if (!IsWindowVisible( win_array
[i
] )) continue;
959 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows */
960 if (IsIconic( win_array
[i
] ))
965 win_array
[total
++] = win_array
[i
];
967 win_array
[total
] = 0;
971 INT delta
= 0, n
= 0, i
;
973 if (has_icons
) delta
= GetSystemMetrics(SM_CYICONSPACING
) + GetSystemMetrics(SM_CYICON
);
975 /* walk the list (backwards) and move windows */
976 for (i
= total
- 1; i
>= 0; i
--)
978 TRACE("move %p to (%ld,%ld) size [%ld,%ld]\n",
979 win_array
[i
], pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
);
981 MDI_CalcDefaultChildPos(client
, n
++, pos
, delta
);
982 SetWindowPos( win_array
[i
], 0, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
,
983 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
986 HeapFree( GetProcessHeap(), 0, win_array
);
988 if (has_icons
) ArrangeIconicWindows( client
);
993 /**********************************************************************
996 static void MDITile( HWND client
, MDICLIENTINFO
*ci
, WPARAM wParam
)
1004 BOOL has_icons
= FALSE
;
1006 if (ci
->hwndChildMaximized
)
1007 SendMessageA( client
, WM_MDIRESTORE
, (WPARAM
)ci
->hwndChildMaximized
, 0);
1009 if (ci
->nActiveChildren
== 0) return;
1011 if (!(win_array
= WIN_ListChildren( client
))) return;
1013 /* remove all the windows we don't want */
1014 for (i
= total
= 0; win_array
[i
]; i
++)
1016 if (!IsWindowVisible( win_array
[i
] )) continue;
1017 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows (icon titles) */
1018 if (IsIconic( win_array
[i
] ))
1023 if ((wParam
& MDITILE_SKIPDISABLED
) && !IsWindowEnabled( win_array
[i
] )) continue;
1024 win_array
[total
++] = win_array
[i
];
1026 win_array
[total
] = 0;
1028 TRACE("%u windows to tile\n", total
);
1032 HWND
*pWnd
= win_array
;
1034 int x
, y
, xsize
, ysize
;
1035 int rows
, columns
, r
, c
, i
;
1037 GetClientRect(client
,&rect
);
1038 rows
= (int) sqrt((double)total
);
1039 columns
= total
/ rows
;
1041 if( wParam
& MDITILE_HORIZONTAL
) /* version >= 3.1 */
1044 rows
= columns
; /* exchange r and c */
1050 y
= rect
.bottom
- 2 * GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
1051 rect
.bottom
= ( y
- GetSystemMetrics(SM_CYICON
) < rect
.top
)? rect
.bottom
: y
;
1054 ysize
= rect
.bottom
/ rows
;
1055 xsize
= rect
.right
/ columns
;
1057 for (x
= i
= 0, c
= 1; c
<= columns
&& *pWnd
; c
++)
1062 ysize
= rect
.bottom
/ rows
;
1066 for (r
= 1; r
<= rows
&& *pWnd
; r
++, i
++)
1068 SetWindowPos(*pWnd
, 0, x
, y
, xsize
, ysize
,
1069 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
1076 HeapFree( GetProcessHeap(), 0, win_array
);
1077 if (has_icons
) ArrangeIconicWindows( client
);
1081 /* ----------------------- Frame window ---------------------------- */
1084 /**********************************************************************
1085 * MDI_AugmentFrameMenu
1087 static BOOL
MDI_AugmentFrameMenu( HWND frame
, HWND hChild
)
1089 HMENU menu
= GetMenu( frame
);
1091 WND
* child
= WIN_FindWndPtr(hChild
);
1093 HMENU hSysPopup
= 0;
1094 HBITMAP hSysMenuBitmap
= 0;
1096 TRACE("frame %p,child %p\n",frame
,hChild
);
1099 if( !menu
|| !child
->hSysMenu
)
1101 WIN_ReleaseWndPtr(child
);
1104 WIN_ReleaseWndPtr(child
);
1106 if( !menu
|| !GetSystemMenu(hChild
, FALSE
) )
1112 /* create a copy of sysmenu popup and insert it into frame menu bar */
1114 if (!(hSysPopup
= LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU")))
1117 AppendMenuA(menu
,MF_HELP
| MF_BITMAP
,
1118 SC_MINIMIZE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_MINIMIZE
) ;
1119 AppendMenuA(menu
,MF_HELP
| MF_BITMAP
,
1120 SC_RESTORE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_RESTORE
);
1122 /* In Win 95 look, the system menu is replaced by the child icon */
1124 if(TWEAK_WineLook
> WIN31_LOOK
)
1127 HICON hIcon
= (HICON
)GetClassLongA(hChild
, GCL_HICONSM
);
1129 hIcon
= (HICON
)GetClassLongA(hChild
, GCL_HICON
);
1133 HBITMAP hBitmap
, hOldBitmap
;
1135 HDC hdc
= GetDC(hChild
);
1140 cx
= GetSystemMetrics(SM_CXSMICON
);
1141 cy
= GetSystemMetrics(SM_CYSMICON
);
1142 hMemDC
= CreateCompatibleDC(hdc
);
1143 hBitmap
= CreateCompatibleBitmap(hdc
, cx
, cy
);
1144 hOldBitmap
= SelectObject(hMemDC
, hBitmap
);
1145 SetMapMode(hMemDC
, MM_TEXT
);
1146 hBrush
= CreateSolidBrush(GetSysColor(COLOR_MENU
));
1147 DrawIconEx(hMemDC
, 0, 0, hIcon
, cx
, cy
, 0, hBrush
, DI_NORMAL
);
1148 SelectObject (hMemDC
, hOldBitmap
);
1149 DeleteObject(hBrush
);
1151 ReleaseDC(hChild
, hdc
);
1152 hSysMenuBitmap
= hBitmap
;
1158 hSysMenuBitmap
= hBmpClose
;
1161 if( !InsertMenuA(menu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
1162 (UINT_PTR
)hSysPopup
, (LPSTR
)hSysMenuBitmap
))
1164 TRACE("not inserted\n");
1165 DestroyMenu(hSysPopup
);
1169 /* The close button is only present in Win 95 look */
1171 if(TWEAK_WineLook
> WIN31_LOOK
)
1174 AppendMenuA(menu
,MF_HELP
| MF_BITMAP
,
1175 SC_CLOSE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_CLOSE
);
1178 EnableMenuItem(hSysPopup
, SC_SIZE
, MF_BYCOMMAND
| MF_GRAYED
);
1179 EnableMenuItem(hSysPopup
, SC_MOVE
, MF_BYCOMMAND
| MF_GRAYED
);
1180 EnableMenuItem(hSysPopup
, SC_MAXIMIZE
, MF_BYCOMMAND
| MF_GRAYED
);
1181 SetMenuDefaultItem(hSysPopup
, SC_CLOSE
, FALSE
);
1189 /**********************************************************************
1190 * MDI_RestoreFrameMenu
1192 static BOOL
MDI_RestoreFrameMenu( HWND frame
, HWND hChild
)
1194 MENUITEMINFOW menuInfo
;
1195 HMENU menu
= GetMenu( frame
);
1196 INT nItems
= GetMenuItemCount(menu
) - 1;
1197 UINT iId
= GetMenuItemID(menu
,nItems
) ;
1199 TRACE("frame %p,child %p,nIt=%d,iId=%d\n",frame
,hChild
,nItems
,iId
);
1201 if(!(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
1205 * Remove the system menu, If that menu is the icon of the window
1206 * as it is in win95, we have to delete the bitmap.
1208 memset(&menuInfo
, 0, sizeof(menuInfo
));
1209 menuInfo
.cbSize
= sizeof(menuInfo
);
1210 menuInfo
.fMask
= MIIM_DATA
| MIIM_TYPE
;
1212 GetMenuItemInfoW(menu
,
1217 RemoveMenu(menu
,0,MF_BYPOSITION
);
1220 if ( (menuInfo
.fType
& MFT_BITMAP
) &&
1221 (LOWORD(menuInfo
.dwTypeData
)!=0) &&
1222 (LOWORD(menuInfo
.dwTypeData
)!=HBITMAP_16(hBmpClose
)) )
1224 DeleteObject(HBITMAP_32(LOWORD(menuInfo
.dwTypeData
)));
1227 if ( (menuInfo
.fType
& MFT_BITMAP
) &&
1228 (LOWORD(menuInfo
.dwTypeData
)!=0))
1230 DeleteObject((HBITMAP
)(LOWORD(menuInfo
.dwTypeData
) & 0x50000));
1235 if(TWEAK_WineLook
> WIN31_LOOK
)
1239 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
1242 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
1244 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
1252 /**********************************************************************
1253 * MDI_UpdateFrameText
1255 * used when child window is maximized/restored
1257 * Note: lpTitle can be NULL
1259 static void MDI_UpdateFrameText( HWND frame
, HWND hClient
,
1260 BOOL repaint
, LPCWSTR lpTitle
)
1262 WCHAR lpBuffer
[MDI_MAXTITLELENGTH
+1];
1263 MDICLIENTINFO
*ci
= get_client_info( hClient
);
1265 TRACE("repaint %i, frameText %s\n", repaint
, debugstr_w(lpTitle
));
1269 if (!lpTitle
&& !ci
->frameTitle
) /* first time around, get title from the frame window */
1271 GetWindowTextW( frame
, lpBuffer
, sizeof(lpBuffer
)/sizeof(WCHAR
) );
1275 /* store new "default" title if lpTitle is not NULL */
1278 if (ci
->frameTitle
) HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1279 if ((ci
->frameTitle
= HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle
)+1)*sizeof(WCHAR
))))
1280 strcpyW( ci
->frameTitle
, lpTitle
);
1285 if (ci
->hwndChildMaximized
)
1287 /* combine frame title and child title if possible */
1289 static const WCHAR lpBracket
[] = {' ','-',' ','[',0};
1290 static const WCHAR lpBracket2
[] = {']',0};
1291 int i_frame_text_length
= strlenW(ci
->frameTitle
);
1293 lstrcpynW( lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
1295 if( i_frame_text_length
+ 6 < MDI_MAXTITLELENGTH
)
1297 strcatW( lpBuffer
, lpBracket
);
1298 if (GetWindowTextW( ci
->hwndChildMaximized
, lpBuffer
+ i_frame_text_length
+ 4,
1299 MDI_MAXTITLELENGTH
- i_frame_text_length
- 5 ))
1300 strcatW( lpBuffer
, lpBracket2
);
1302 lpBuffer
[i_frame_text_length
] = 0; /* remove bracket */
1307 lstrcpynW(lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
+1 );
1313 DefWindowProcW( frame
, WM_SETTEXT
, 0, (LPARAM
)lpBuffer
);
1314 if( repaint
== MDI_REPAINTFRAME
)
1315 SetWindowPos( frame
, 0,0,0,0,0, SWP_FRAMECHANGED
|
1316 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
1320 /* ----------------------------- Interface ---------------------------- */
1323 /**********************************************************************
1324 * MDIClientWndProc_common
1326 static LRESULT
MDIClientWndProc_common( HWND hwnd
, UINT message
,
1327 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1331 if (WM_NCCREATE
!= message
&& WM_CREATE
!= message
1332 && NULL
== (ci
= get_client_info(hwnd
)))
1341 if (!(ci
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ci
))))
1343 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)ci
);
1350 /* Since we are using only cs->lpCreateParams, we can safely
1351 * cast to LPCREATESTRUCTA here */
1352 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
1354 WND
*wndPtr
= WIN_GetPtr( hwnd
);
1356 ci
= HeapAlloc(GetProcessHeap(), 0, sizeof(MDICLIENTINFO
));
1361 SetWindowLongPtr(hwnd
, 0, (LONG_PTR
) ci
);
1363 /* Translation layer doesn't know what's in the cs->lpCreateParams
1364 * so we have to keep track of what environment we're in. */
1367 if( wndPtr
->flags
& WIN_ISWIN32
)
1370 #define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1371 ci
->hWindowMenu
= ccs
->hWindowMenu
;
1372 ci
->idFirstChild
= ccs
->idFirstChild
;
1378 LPCLIENTCREATESTRUCT16 ccs
= MapSL((SEGPTR
)cs
->lpCreateParams
);
1379 ci
->hWindowMenu
= HMENU_32(ccs
->hWindowMenu
);
1380 ci
->idFirstChild
= ccs
->idFirstChild
;
1382 WIN_ReleasePtr( wndPtr
);
1385 ci
->hwndChildMaximized
= 0;
1386 ci
->nActiveChildren
= 0;
1387 ci
->nTotalCreated
= 0;
1388 ci
->frameTitle
= NULL
;
1390 SetWindowLongW( hwnd
, GWL_STYLE
, GetWindowLongW(hwnd
,GWL_STYLE
) | WS_CLIPCHILDREN
);
1392 if (!hBmpClose
) hBmpClose
= CreateMDIMenuBitmap();
1394 if (ci
->hWindowMenu
!= 0)
1395 AppendMenuW( ci
->hWindowMenu
, MF_SEPARATOR
, 0, NULL
);
1397 GetClientRect( GetParent(hwnd
), &rect
);
1398 MoveWindow( hwnd
, 0, 0, rect
.right
, rect
.bottom
, FALSE
);
1400 MDI_UpdateFrameText( GetParent(hwnd
), hwnd
, MDI_NOFRAMEREPAINT
, NULL
);
1402 TRACE("Client created - hwnd = %p, idFirst = %u\n", hwnd
, ci
->idFirstChild
);
1409 if( ci
->hwndChildMaximized
)
1410 MDI_RestoreFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
1411 if((ci
->hWindowMenu
!= 0) &&
1412 (nItems
= GetMenuItemCount(ci
->hWindowMenu
)) > 0)
1414 ci
->idFirstChild
= nItems
- 1;
1415 ci
->nActiveChildren
++; /* to delete a separator */
1416 while( ci
->nActiveChildren
-- )
1417 DeleteMenu(ci
->hWindowMenu
,MF_BYPOSITION
,ci
->idFirstChild
--);
1419 if (ci
->frameTitle
) HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1421 HeapFree( GetProcessHeap(), 0, ci
);
1422 SetWindowLongPtrW( hwnd
, 0, 0 );
1427 case WM_MDIACTIVATE
:
1428 if( ci
->hwndActiveChild
!= (HWND
)wParam
)
1429 SetWindowPos((HWND
)wParam
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1433 return MDICascade(hwnd
, ci
);
1437 return (LRESULT
)MDICreateChild( hwnd
, ci
, (MDICREATESTRUCTA
*)lParam
, unicode
);
1442 return MDIDestroyChild( hwnd
, ci
, WIN_GetFullHandle( (HWND
)wParam
), TRUE
);
1444 return MDIDestroyChild( hwnd
, ci
, (HWND
)wParam
, TRUE
);
1447 case WM_MDIGETACTIVE
:
1448 if (lParam
) *(BOOL
*)lParam
= (ci
->hwndChildMaximized
!= 0);
1449 return (LRESULT
)ci
->hwndActiveChild
;
1451 case WM_MDIICONARRANGE
:
1452 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1453 ArrangeIconicWindows( hwnd
);
1454 ci
->sbRecalc
= SB_BOTH
+1;
1455 SendMessageW( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0 );
1458 case WM_MDIMAXIMIZE
:
1459 ShowWindow( (HWND
)wParam
, SW_MAXIMIZE
);
1462 case WM_MDINEXT
: /* lParam != 0 means previous window */
1464 MDI_SwitchActiveChild( hwnd
, WIN_GetFullHandle( (HWND
)wParam
), !lParam
);
1466 MDI_SwitchActiveChild( hwnd
, (HWND
)wParam
, !lParam
);
1471 SendMessageW( (HWND
)wParam
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
1475 return MDISetMenu( hwnd
, (HMENU
)wParam
, (HMENU
)lParam
);
1477 case WM_MDIREFRESHMENU
:
1478 return MDIRefreshMenu( hwnd
, (HMENU
)wParam
, (HMENU
)lParam
);
1481 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1482 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
1483 MDITile( hwnd
, ci
, wParam
);
1484 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1489 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1490 ScrollChildren( hwnd
, message
, wParam
, lParam
);
1491 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1495 if (ci
->hwndActiveChild
&& !IsIconic( ci
->hwndActiveChild
))
1496 SetFocus( ci
->hwndActiveChild
);
1500 if( ci
->hwndActiveChild
)
1501 SendMessageW(ci
->hwndActiveChild
, message
, wParam
, lParam
);
1504 case WM_PARENTNOTIFY
:
1505 if (LOWORD(wParam
) == WM_LBUTTONDOWN
)
1509 pt
.x
= (short)LOWORD(lParam
);
1510 pt
.y
= (short)HIWORD(lParam
);
1511 child
= ChildWindowFromPoint(hwnd
, pt
);
1513 TRACE("notification from %p (%li,%li)\n",child
,pt
.x
,pt
.y
);
1515 if( child
&& child
!= hwnd
&& child
!= ci
->hwndActiveChild
)
1516 SetWindowPos(child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1521 if( IsWindow(ci
->hwndChildMaximized
) )
1527 rect
.right
= LOWORD(lParam
);
1528 rect
.bottom
= HIWORD(lParam
);
1530 AdjustWindowRectEx(&rect
, GetWindowLongA(ci
->hwndChildMaximized
,GWL_STYLE
),
1531 0, GetWindowLongA(ci
->hwndChildMaximized
,GWL_EXSTYLE
) );
1532 MoveWindow(ci
->hwndChildMaximized
, rect
.left
, rect
.top
,
1533 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 1);
1536 MDI_PostUpdate(hwnd
, ci
, SB_BOTH
+1);
1540 case WM_MDICALCCHILDSCROLL
:
1541 if( (ci
->mdiFlags
& MDIF_NEEDUPDATE
) && ci
->sbRecalc
)
1543 CalcChildScroll(hwnd
, ci
->sbRecalc
-1);
1545 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1549 return unicode
? DefWindowProcW( hwnd
, message
, wParam
, lParam
) :
1550 DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1553 /***********************************************************************
1556 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1558 if (!IsWindow(hwnd
)) return 0;
1559 return MDIClientWndProc_common( hwnd
, message
, wParam
, lParam
, FALSE
);
1562 /***********************************************************************
1565 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1567 if (!IsWindow(hwnd
)) return 0;
1568 return MDIClientWndProc_common( hwnd
, message
, wParam
, lParam
, TRUE
);
1572 /***********************************************************************
1573 * DefFrameProc (USER.445)
1575 LRESULT WINAPI
DefFrameProc16( HWND16 hwnd
, HWND16 hwndMDIClient
,
1576 UINT16 message
, WPARAM16 wParam
, LPARAM lParam
)
1581 lParam
= (LPARAM
)MapSL(lParam
);
1587 return DefFrameProcA( WIN_Handle32(hwnd
), WIN_Handle32(hwndMDIClient
),
1588 message
, wParam
, lParam
);
1592 MDINEXTMENU next_menu
;
1593 DefFrameProcW( WIN_Handle32(hwnd
), WIN_Handle32(hwndMDIClient
),
1594 message
, wParam
, (LPARAM
)&next_menu
);
1595 return MAKELONG( HMENU_16(next_menu
.hmenuNext
), HWND_16(next_menu
.hwndNext
) );
1598 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1603 /***********************************************************************
1604 * DefFrameProcA (USER32.@)
1606 LRESULT WINAPI
DefFrameProcA( HWND hwnd
, HWND hwndMDIClient
,
1607 UINT message
, WPARAM wParam
, LPARAM lParam
)
1615 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, NULL
, 0 );
1616 LPWSTR text
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1617 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, text
, len
);
1618 MDI_UpdateFrameText(hwnd
, hwndMDIClient
, MDI_REPAINTFRAME
, text
);
1619 HeapFree( GetProcessHeap(), 0, text
);
1621 return 1; /* success. FIXME: check text length */
1628 return DefFrameProcW( hwnd
, hwndMDIClient
, message
, wParam
, lParam
);
1631 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1635 /***********************************************************************
1636 * DefFrameProcW (USER32.@)
1638 LRESULT WINAPI
DefFrameProcW( HWND hwnd
, HWND hwndMDIClient
,
1639 UINT message
, WPARAM wParam
, LPARAM lParam
)
1641 MDICLIENTINFO
*ci
= get_client_info( hwndMDIClient
);
1649 WORD id
= LOWORD(wParam
);
1650 /* check for possible syscommands for maximized MDI child */
1651 if (id
< ci
->idFirstChild
|| id
>= ci
->idFirstChild
+ ci
->nActiveChildren
)
1653 if( (id
- 0xf000) & 0xf00f ) break;
1654 if( !ci
->hwndChildMaximized
) break;
1665 return SendMessageW( ci
->hwndChildMaximized
, WM_SYSCOMMAND
,
1672 if (id
- ci
->idFirstChild
== MDI_MOREWINDOWSLIMIT
)
1673 /* User chose "More Windows..." */
1674 childHwnd
= MDI_MoreWindowsDialog(hwndMDIClient
);
1676 /* User chose one of the windows listed in the "Windows" menu */
1677 childHwnd
= MDI_GetChildByID(hwndMDIClient
,id
);
1680 SendMessageW( hwndMDIClient
, WM_MDIACTIVATE
, (WPARAM
)childHwnd
, 0 );
1686 SendMessageW(hwndMDIClient
, message
, wParam
, lParam
);
1690 MDI_UpdateFrameText(hwnd
, hwndMDIClient
, MDI_REPAINTFRAME
, (LPWSTR
)lParam
);
1691 return 1; /* success. FIXME: check text length */
1694 SetFocus(hwndMDIClient
);
1698 MoveWindow(hwndMDIClient
, 0, 0, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1705 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1707 if (!IsIconic(hwnd
) && ci
->hwndActiveChild
&& !ci
->hwndChildMaximized
)
1709 /* control menu is between the frame system menu and
1710 * the first entry of menu bar */
1711 WND
*wndPtr
= WIN_GetPtr(hwnd
);
1713 if( (wParam
== VK_LEFT
&& GetMenu(hwnd
) == next_menu
->hmenuIn
) ||
1714 (wParam
== VK_RIGHT
&& GetSubMenu(wndPtr
->hSysMenu
, 0) == next_menu
->hmenuIn
) )
1716 WIN_ReleasePtr(wndPtr
);
1717 wndPtr
= WIN_GetPtr(ci
->hwndActiveChild
);
1718 next_menu
->hmenuNext
= GetSubMenu(wndPtr
->hSysMenu
, 0);
1719 next_menu
->hwndNext
= ci
->hwndActiveChild
;
1721 WIN_ReleasePtr(wndPtr
);
1729 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1734 /***********************************************************************
1735 * DefMDIChildProc (USER.447)
1737 LRESULT WINAPI
DefMDIChildProc16( HWND16 hwnd
, UINT16 message
,
1738 WPARAM16 wParam
, LPARAM lParam
)
1743 return DefMDIChildProcA( WIN_Handle32(hwnd
), message
, wParam
, (LPARAM
)MapSL(lParam
) );
1747 case WM_CHILDACTIVATE
:
1752 return DefMDIChildProcW( WIN_Handle32(hwnd
), message
, wParam
, lParam
);
1753 case WM_GETMINMAXINFO
:
1755 MINMAXINFO16
*mmi16
= (MINMAXINFO16
*)MapSL(lParam
);
1757 STRUCT32_MINMAXINFO16to32( mmi16
, &mmi
);
1758 DefMDIChildProcW( WIN_Handle32(hwnd
), message
, wParam
, (LPARAM
)&mmi
);
1759 STRUCT32_MINMAXINFO32to16( &mmi
, mmi16
);
1764 MDINEXTMENU next_menu
;
1765 DefMDIChildProcW( WIN_Handle32(hwnd
), message
, wParam
, (LPARAM
)&next_menu
);
1766 return MAKELONG( HMENU_16(next_menu
.hmenuNext
), HWND_16(next_menu
.hwndNext
) );
1769 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1775 /***********************************************************************
1776 * DefMDIChildProcA (USER32.@)
1778 LRESULT WINAPI
DefMDIChildProcA( HWND hwnd
, UINT message
,
1779 WPARAM wParam
, LPARAM lParam
)
1781 HWND client
= GetParent(hwnd
);
1782 MDICLIENTINFO
*ci
= get_client_info( client
);
1785 hwnd
= WIN_GetFullHandle( hwnd
);
1787 if (!ci
) return DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1792 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1793 MDI_MenuModifyItem( client
, hwnd
);
1794 if( ci
->hwndChildMaximized
== hwnd
)
1795 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1796 return 1; /* success. FIXME: check text length */
1798 case WM_GETMINMAXINFO
:
1802 case WM_CHILDACTIVATE
:
1811 return DefMDIChildProcW( hwnd
, message
, wParam
, lParam
);
1813 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1817 /***********************************************************************
1818 * DefMDIChildProcW (USER32.@)
1820 LRESULT WINAPI
DefMDIChildProcW( HWND hwnd
, UINT message
,
1821 WPARAM wParam
, LPARAM lParam
)
1823 HWND client
= GetParent(hwnd
);
1824 MDICLIENTINFO
*ci
= get_client_info( client
);
1827 hwnd
= WIN_GetFullHandle( hwnd
);
1829 if (!ci
) return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1834 DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1835 MDI_MenuModifyItem( client
, hwnd
);
1836 if( ci
->hwndChildMaximized
== hwnd
)
1837 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1838 return 1; /* success. FIXME: check text length */
1840 case WM_GETMINMAXINFO
:
1841 MDI_ChildGetMinMaxInfo( client
, hwnd
, (MINMAXINFO
*)lParam
);
1845 return 0x00010000; /* MDI children don't have menu bars */
1848 SendMessageW( client
, WM_MDIDESTROY
, (WPARAM
)hwnd
, 0 );
1852 if (ci
->hwndActiveChild
!= hwnd
) MDI_ChildActivate( client
, hwnd
);
1855 case WM_CHILDACTIVATE
:
1856 MDI_ChildActivate( client
, hwnd
);
1863 if( ci
->hwndChildMaximized
== hwnd
) return 0;
1867 SetWindowLongW( hwnd
, GWL_STYLE
,
1868 GetWindowLongW( hwnd
, GWL_STYLE
) | WS_SYSMENU
);
1871 if (ci
->hwndChildMaximized
== hwnd
)
1872 return SendMessageW( GetParent(client
), message
, wParam
, lParam
);
1873 SetWindowLongW( hwnd
, GWL_STYLE
,
1874 GetWindowLongW( hwnd
, GWL_STYLE
) & ~WS_SYSMENU
);
1877 SendMessageW( client
, WM_MDINEXT
, 0, 0);
1880 SendMessageW( client
, WM_MDINEXT
, 0, 1);
1888 if( ci
->hwndChildMaximized
) ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1889 else MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1894 if( ci
->hwndActiveChild
== hwnd
&& wParam
!= SIZE_MAXIMIZED
)
1896 ci
->hwndChildMaximized
= 0;
1897 MDI_RestoreFrameMenu( GetParent(client
), hwnd
);
1898 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1901 if( wParam
== SIZE_MAXIMIZED
)
1903 HWND hMaxChild
= ci
->hwndChildMaximized
;
1905 if( hMaxChild
== hwnd
) break;
1908 SendMessageW( hMaxChild
, WM_SETREDRAW
, FALSE
, 0 );
1909 MDI_RestoreFrameMenu( GetParent(client
), hMaxChild
);
1910 ShowWindow( hMaxChild
, SW_SHOWNOACTIVATE
);
1911 SendMessageW( hMaxChild
, WM_SETREDRAW
, TRUE
, 0 );
1913 TRACE("maximizing child %p\n", hwnd
);
1915 /* keep track of the maximized window. */
1916 ci
->hwndChildMaximized
= hwnd
; /* !!! */
1918 /* The maximized window should also be the active window */
1919 MDI_ChildActivate( client
, hwnd
);
1920 MDI_AugmentFrameMenu( GetParent(client
), hwnd
);
1921 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1924 if( wParam
== SIZE_MINIMIZED
)
1926 HWND switchTo
= MDI_GetWindow(ci
, hwnd
, TRUE
, WS_MINIMIZE
);
1928 if (switchTo
) SendMessageW( switchTo
, WM_CHILDACTIVATE
, 0, 0);
1930 MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1937 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1938 HWND parent
= GetParent(client
);
1940 if( wParam
== VK_LEFT
) /* switch to frame system menu */
1942 WND
*wndPtr
= WIN_GetPtr( parent
);
1943 next_menu
->hmenuNext
= GetSubMenu( wndPtr
->hSysMenu
, 0 );
1944 WIN_ReleasePtr( wndPtr
);
1946 if( wParam
== VK_RIGHT
) /* to frame menu bar */
1948 next_menu
->hmenuNext
= GetMenu(parent
);
1950 next_menu
->hwndNext
= parent
;
1958 SendMessageW( hwnd
, WM_SYSCOMMAND
, (WPARAM
)SC_KEYMENU
, (DWORD
)VK_SPACE
);
1963 return DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1966 /**********************************************************************
1967 * CreateMDIWindowA (USER32.@) Creates a MDI child
1970 * Success: Handle to created window
1973 HWND WINAPI
CreateMDIWindowA(
1974 LPCSTR lpClassName
, /* [in] Pointer to registered child class name */
1975 LPCSTR lpWindowName
, /* [in] Pointer to window name */
1976 DWORD dwStyle
, /* [in] Window style */
1977 INT X
, /* [in] Horizontal position of window */
1978 INT Y
, /* [in] Vertical position of window */
1979 INT nWidth
, /* [in] Width of window */
1980 INT nHeight
, /* [in] Height of window */
1981 HWND hWndParent
, /* [in] Handle to parent window */
1982 HINSTANCE hInstance
, /* [in] Handle to application instance */
1983 LPARAM lParam
) /* [in] Application-defined value */
1985 MDICLIENTINFO
*pCi
= get_client_info( hWndParent
);
1986 MDICREATESTRUCTA cs
;
1988 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%p,%p,%ld)\n",
1989 debugstr_a(lpClassName
),debugstr_a(lpWindowName
),dwStyle
,X
,Y
,
1990 nWidth
,nHeight
,hWndParent
,hInstance
,lParam
);
1994 ERR("bad hwnd for MDI-client: %p\n", hWndParent
);
1997 cs
.szClass
=lpClassName
;
1998 cs
.szTitle
=lpWindowName
;
1999 cs
.hOwner
=hInstance
;
2007 return MDICreateChild(hWndParent
, pCi
, &cs
, FALSE
);
2010 /***********************************************************************
2011 * CreateMDIWindowW (USER32.@) Creates a MDI child
2014 * Success: Handle to created window
2017 HWND WINAPI
CreateMDIWindowW(
2018 LPCWSTR lpClassName
, /* [in] Pointer to registered child class name */
2019 LPCWSTR lpWindowName
, /* [in] Pointer to window name */
2020 DWORD dwStyle
, /* [in] Window style */
2021 INT X
, /* [in] Horizontal position of window */
2022 INT Y
, /* [in] Vertical position of window */
2023 INT nWidth
, /* [in] Width of window */
2024 INT nHeight
, /* [in] Height of window */
2025 HWND hWndParent
, /* [in] Handle to parent window */
2026 HINSTANCE hInstance
, /* [in] Handle to application instance */
2027 LPARAM lParam
) /* [in] Application-defined value */
2029 MDICLIENTINFO
*pCi
= get_client_info( hWndParent
);
2030 MDICREATESTRUCTW cs
;
2032 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%p,%p,%ld)\n",
2033 debugstr_w(lpClassName
), debugstr_w(lpWindowName
), dwStyle
, X
, Y
,
2034 nWidth
, nHeight
, hWndParent
, hInstance
, lParam
);
2038 ERR("bad hwnd for MDI-client: %p\n", hWndParent
);
2041 cs
.szClass
= lpClassName
;
2042 cs
.szTitle
= lpWindowName
;
2043 cs
.hOwner
= hInstance
;
2051 return MDICreateChild(hWndParent
, pCi
, (MDICREATESTRUCTA
*)&cs
, TRUE
);
2054 /**********************************************************************
2055 * TranslateMDISysAccel (USER32.@)
2057 BOOL WINAPI
TranslateMDISysAccel( HWND hwndClient
, LPMSG msg
)
2059 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
)
2061 MDICLIENTINFO
*ci
= get_client_info( hwndClient
);
2064 if (!ci
|| !IsWindowEnabled(ci
->hwndActiveChild
)) return 0;
2066 /* translate if the Ctrl key is down and Alt not. */
2068 if( (GetKeyState(VK_CONTROL
) & 0x8000) && !(GetKeyState(VK_MENU
) & 0x8000))
2070 switch( msg
->wParam
)
2074 wParam
= ( GetKeyState(VK_SHIFT
) & 0x8000 ) ? SC_NEXTWINDOW
: SC_PREVWINDOW
;
2083 TRACE("wParam = %04x\n", wParam
);
2084 SendMessageW(ci
->hwndActiveChild
, WM_SYSCOMMAND
, wParam
, (LPARAM
)msg
->wParam
);
2088 return 0; /* failure */
2091 /***********************************************************************
2092 * CalcChildScroll (USER32.@)
2094 void WINAPI
CalcChildScroll( HWND hwnd
, INT scroll
)
2097 RECT childRect
, clientRect
;
2104 GetClientRect( hwnd
, &clientRect
);
2105 SetRectEmpty( &childRect
);
2108 if ((list
= WIN_ListChildren( hwnd
)))
2111 for (i
= 0; list
[i
]; i
++)
2113 DWORD style
= GetWindowLongW( list
[i
], GWL_STYLE
);
2114 if (style
& WS_MAXIMIZE
)
2116 HeapFree( GetProcessHeap(), 0, list
);
2117 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
2120 if (style
& WS_VISIBLE
)
2122 WND
*pWnd
= WIN_FindWndPtr( list
[i
] );
2123 UnionRect( &childRect
, &pWnd
->rectWindow
, &childRect
);
2124 WIN_ReleaseWndPtr( pWnd
);
2127 HeapFree( GetProcessHeap(), 0, list
);
2130 hWndCurrent
= GetWindow(hwnd
, GW_CHILD
);
2131 while (hWndCurrent
!= NULL
)
2133 DWORD style
= GetWindowLongW( hWndCurrent
, GWL_STYLE
);
2134 if (style
& WS_MAXIMIZE
)
2136 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
2139 if (style
& WS_VISIBLE
)
2143 GetWindowRect( hWndCurrent
, &WindowRect
);
2144 UnionRect( &childRect
, &WindowRect
, &childRect
);
2146 hWndCurrent
= GetWindow(hWndCurrent
, GW_HWNDNEXT
);
2149 UnionRect( &childRect
, &clientRect
, &childRect
);
2151 /* set common info values */
2152 info
.cbSize
= sizeof(info
);
2153 info
.fMask
= SIF_POS
| SIF_RANGE
;
2155 /* set the specific */
2160 info
.nMin
= childRect
.left
;
2161 info
.nMax
= childRect
.right
- clientRect
.right
;
2162 info
.nPos
= clientRect
.left
- childRect
.left
;
2163 SetScrollInfo(hwnd
, scroll
, &info
, TRUE
);
2164 if (scroll
== SB_HORZ
) break;
2167 info
.nMin
= childRect
.top
;
2168 info
.nMax
= childRect
.bottom
- clientRect
.bottom
;
2169 info
.nPos
= clientRect
.top
- childRect
.top
;
2170 SetScrollInfo(hwnd
, scroll
, &info
, TRUE
);
2176 /***********************************************************************
2177 * ScrollChildren (USER32.@)
2179 void WINAPI
ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
,
2183 INT curPos
, length
, minPos
, maxPos
, shift
;
2186 GetClientRect( hWnd
, &rect
);
2191 GetScrollRange(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
2192 curPos
= GetScrollPos(hWnd
,SB_HORZ
);
2193 length
= (rect
.right
- rect
.left
) / 2;
2194 shift
= GetSystemMetrics(SM_CYHSCROLL
);
2197 GetScrollRange(hWnd
,SB_VERT
,&minPos
,&maxPos
);
2198 curPos
= GetScrollPos(hWnd
,SB_VERT
);
2199 length
= (rect
.bottom
- rect
.top
) / 2;
2200 shift
= GetSystemMetrics(SM_CXVSCROLL
);
2209 newPos
= curPos
- shift
;
2212 newPos
= curPos
+ shift
;
2215 newPos
= curPos
- length
;
2218 newPos
= curPos
+ length
;
2221 case SB_THUMBPOSITION
:
2222 newPos
= LOWORD(lParam
);
2235 CalcChildScroll(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
2239 if( newPos
> maxPos
)
2242 if( newPos
< minPos
)
2245 SetScrollPos(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
2247 if( uMsg
== WM_VSCROLL
)
2248 ScrollWindowEx(hWnd
,0 ,curPos
- newPos
, NULL
, NULL
, 0, NULL
,
2249 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
2251 ScrollWindowEx(hWnd
,curPos
- newPos
, 0, NULL
, NULL
, 0, NULL
,
2252 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
2256 /******************************************************************************
2257 * CascadeWindows (USER32.@) Cascades MDI child windows
2260 * Success: Number of cascaded windows.
2264 CascadeWindows (HWND hwndParent
, UINT wFlags
, LPCRECT lpRect
,
2265 UINT cKids
, const HWND
*lpKids
)
2267 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
2272 /******************************************************************************
2273 * TileWindows (USER32.@) Tiles MDI child windows
2276 * Success: Number of tiled windows.
2280 TileWindows (HWND hwndParent
, UINT wFlags
, LPCRECT lpRect
,
2281 UINT cKids
, const HWND
*lpKids
)
2283 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
2287 /************************************************************************
2288 * "More Windows..." functionality
2291 /* MDI_MoreWindowsDlgProc
2293 * This function will process the messages sent to the "More Windows..."
2295 * Return values: 0 = cancel pressed
2296 * HWND = ok pressed or double-click in the list...
2300 static INT_PTR WINAPI
MDI_MoreWindowsDlgProc (HWND hDlg
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
2313 MDICLIENTINFO
*ci
= get_client_info( (HWND
)lParam
);
2314 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2315 HWND
*list
, *sorted_list
;
2317 if (!(list
= WIN_ListChildren( (HWND
)lParam
))) return TRUE
;
2318 if (!(sorted_list
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
2319 sizeof(HWND
) * ci
->nActiveChildren
)))
2321 HeapFree( GetProcessHeap(), 0, list
);
2325 /* Fill the list, sorted by id... */
2326 for (i
= 0; list
[i
]; i
++)
2328 UINT id
= GetWindowLongW( list
[i
], GWL_ID
) - ci
->idFirstChild
;
2329 if (id
< ci
->nActiveChildren
) sorted_list
[id
] = list
[i
];
2331 HeapFree( GetProcessHeap(), 0, list
);
2333 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
2337 if (!GetWindowTextW( sorted_list
[i
], buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
2339 SendMessageW(hListBox
, LB_ADDSTRING
, 0, (LPARAM
)buffer
);
2340 SendMessageW(hListBox
, LB_SETITEMDATA
, i
, (LPARAM
)sorted_list
[i
] );
2341 length
= strlenW(buffer
); /* FIXME: should use GetTextExtentPoint */
2342 if (length
> widest
)
2345 /* Make sure the horizontal scrollbar scrolls ok */
2346 SendMessageW(hListBox
, LB_SETHORIZONTALEXTENT
, widest
* 6, 0);
2348 /* Set the current selection */
2349 SendMessageW(hListBox
, LB_SETCURSEL
, MDI_MOREWINDOWSLIMIT
, 0);
2355 switch (LOWORD(wParam
))
2358 if (HIWORD(wParam
) != LBN_DBLCLK
) break;
2362 /* windows are sorted by menu ID, so we must return the
2363 * window associated to the given id
2365 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2366 UINT index
= SendMessageW(hListBox
, LB_GETCURSEL
, 0, 0);
2367 LRESULT res
= SendMessageW(hListBox
, LB_GETITEMDATA
, index
, 0);
2368 EndDialog(hDlg
, res
);
2382 * MDI_MoreWindowsDialog
2384 * Prompts the user with a listbox containing the opened
2385 * documents. The user can then choose a windows and click
2386 * on OK to set the current window to the one selected, or
2387 * CANCEL to cancel. The function returns a handle to the
2391 static HWND
MDI_MoreWindowsDialog(HWND hwnd
)
2397 hRes
= FindResourceA(GetModuleHandleA("USER32"), "MDI_MOREWINDOWS", (LPSTR
)RT_DIALOG
);
2402 hDlgTmpl
= LoadResource(GetModuleHandleA("USER32"), hRes
);
2407 template = LockResource( hDlgTmpl
);
2412 return (HWND
) DialogBoxIndirectParamA(GetModuleHandleA("USER32"),
2413 (LPDLGTEMPLATE
) template,
2414 hwnd
, MDI_MoreWindowsDlgProc
, (LPARAM
) hwnd
);
2421 * Will swap the menu IDs for the given 2 positions.
2422 * pos1 and pos2 are menu IDs
2427 static void MDI_SwapMenuItems(HWND parent
, UINT pos1
, UINT pos2
)
2434 if (!(list
= WIN_ListChildren( parent
))) return;
2435 for (i
= 0; list
[i
]; i
++)
2437 UINT id
= GetWindowLongW( list
[i
], GWL_ID
);
2438 if (id
== pos1
) SetWindowLongW( list
[i
], GWL_ID
, pos2
);
2439 else if (id
== pos2
) SetWindowLongW( list
[i
], GWL_ID
, pos1
);
2441 HeapFree( GetProcessHeap(), 0, list
);