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.
93 #include "wine/unicode.h"
94 #include "user32/regcontrol.h"
96 #include "wine/debug.h"
99 WINE_DEFAULT_DEBUG_CHANNEL(mdi
);
101 #define MDI_MAXLISTLENGTH 0x40
102 #define MDI_MAXTITLELENGTH 0xa1
104 #define MDI_NOFRAMEREPAINT 0
105 #define MDI_REPAINTFRAMENOW 1
106 #define MDI_REPAINTFRAME 2
108 #define WM_MDICALCCHILDSCROLL 0x10ac /* this is exactly what Windows uses */
110 /* "More Windows..." definitions */
111 #define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
112 option will appear under the Windows menu */
113 #define MDI_IDC_LISTBOX 100
114 #define IDS_MDI_MOREWINDOWS 13
116 #define MDIF_NEEDUPDATE 0x0001
120 UINT nActiveChildren
;
121 HWND hwndChildMaximized
;
122 HWND hwndActiveChild
;
128 UINT sbRecalc
; /* SB_xxx flags for scrollbar fixup */
131 static HBITMAP hBmpClose
= 0;
133 /* ----------------- declarations ----------------- */
134 static void MDI_UpdateFrameText( HWND
, HWND
, BOOL
, LPCWSTR
);
135 static BOOL
MDI_AugmentFrameMenu( HWND
, HWND
);
136 static BOOL
MDI_RestoreFrameMenu( HWND
, HWND
);
137 static LONG
MDI_ChildActivate( HWND
, HWND
);
139 static HWND
MDI_MoreWindowsDialog(HWND
);
140 static void MDI_SwapMenuItems(HWND
, UINT
, UINT
);
141 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
142 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
145 void WINAPI
ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
146 void WINAPI
CalcChildScroll(HWND hwnd
, INT scroll
);
148 BOOL CALLBACK
MDI_GetChildByID_EnumProc (HWND hwnd
, LPARAM lParam
)
150 DWORD
*control
= (DWORD
*)lParam
;
151 if(*control
== GetWindowLongW( hwnd
, GWL_ID
))
153 *control
= (DWORD
)hwnd
;
160 /* -------- Miscellaneous service functions ----------
164 static HWND
MDI_GetChildByID(HWND hwnd
, UINT id
)
168 if (hwnd
&& !EnumChildWindows(hwnd
, (ENUMWINDOWSPROC
)&MDI_GetChildByID_EnumProc
, (LPARAM
)&Control
))
170 return (HWND
)Control
;
178 if (!(win_array
= WIN_ListChildren( hwnd
))) return 0;
179 for (i
= 0; win_array
[i
]; i
++)
181 if (GetWindowLongA( win_array
[i
], GWL_ID
) == id
) break;
184 HeapFree( GetProcessHeap(), 0, win_array
);
189 static void MDI_PostUpdate(HWND hwnd
, MDICLIENTINFO
* ci
, WORD recalc
)
191 if( !(ci
->mdiFlags
& MDIF_NEEDUPDATE
) )
193 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
194 PostMessageA( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0);
196 ci
->sbRecalc
= recalc
;
200 /*********************************************************************
201 * MDIClient class descriptor
203 const struct builtin_class_descr MDICLIENT_builtin_class
=
205 L
"MDIClient", /* name */
207 MDIClientWndProcW
, /* procW */
208 MDIClientWndProcA
, /* procA */
209 sizeof(MDICLIENTINFO
*), /* extra */
210 IDC_ARROW
, /* cursor */
211 (HBRUSH
)(COLOR_APPWORKSPACE
+1) /* brush */
215 static MDICLIENTINFO
*get_client_info( HWND client
)
218 return (MDICLIENTINFO
*)GetWindowLongPtr(client
, 0);
220 MDICLIENTINFO
*ret
= NULL
;
221 WND
*win
= WIN_GetPtr( client
);
224 if (win
== WND_OTHER_PROCESS
)
226 ERR( "client %p belongs to other process\n", client
);
229 if (win
->cbWndExtra
< sizeof(MDICLIENTINFO
)) WARN( "%p is not an MDI client\n", client
);
230 else ret
= (MDICLIENTINFO
*)win
->wExtra
;
231 WIN_ReleasePtr( win
);
237 /**********************************************************************
240 static void MDI_MenuModifyItem( HWND client
, HWND hWndChild
)
242 MDICLIENTINFO
*clientInfo
= get_client_info( client
);
246 if (!clientInfo
|| !clientInfo
->hWindowMenu
) return;
248 id
= GetWindowLongA( hWndChild
, GWL_ID
);
249 if (id
>= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
) return;
251 buffer
[1] = '1' + id
- clientInfo
->idFirstChild
;
253 GetWindowTextW( hWndChild
, buffer
+ 3, sizeof(buffer
)/sizeof(WCHAR
) - 3 );
255 n
= GetMenuState(clientInfo
->hWindowMenu
, id
, MF_BYCOMMAND
);
256 ModifyMenuW(clientInfo
->hWindowMenu
, id
, MF_BYCOMMAND
| MF_STRING
, id
, buffer
);
257 CheckMenuItem(clientInfo
->hWindowMenu
, id
, n
& MF_CHECKED
);
260 /**********************************************************************
263 static BOOL
MDI_MenuDeleteItem( HWND client
, HWND hWndChild
)
266 static const WCHAR format
[] = {'&','%','d',' ',0};
267 MDICLIENTINFO
*clientInfo
= get_client_info( client
);
270 if( !clientInfo
->nActiveChildren
|| !clientInfo
->hWindowMenu
)
273 id
= GetWindowLongA( hWndChild
, GWL_ID
);
274 DeleteMenu(clientInfo
->hWindowMenu
,id
,MF_BYCOMMAND
);
276 /* walk the rest of MDI children to prevent gaps in the id
277 * sequence and in the menu child list */
279 for( index
= id
+1; index
<= clientInfo
->nActiveChildren
+
280 clientInfo
->idFirstChild
; index
++ )
282 HWND hwnd
= MDI_GetChildByID(client
,index
);
285 TRACE("no window for id=%i\n",index
);
290 SetWindowLongW( hwnd
, GWL_ID
, GetWindowLongW( hwnd
, GWL_ID
) - 1 );
292 n
= wsprintfW(buffer
, format
,index
- clientInfo
->idFirstChild
);
293 GetWindowTextW( hwnd
, buffer
+ n
, sizeof(buffer
)/sizeof(WCHAR
) - n
);
295 /* change menu if the current child is to be shown in the
298 if (index
<= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
)
299 ModifyMenuW(clientInfo
->hWindowMenu
,index
,MF_BYCOMMAND
| MF_STRING
,
300 index
- 1 , buffer
);
303 /* We must restore the "More Windows..." option if there are enough children
305 if (clientInfo
->nActiveChildren
- 1 > MDI_MOREWINDOWSLIMIT
)
308 LoadStringW(GetModuleHandleA("USER32"), IDS_MDI_MOREWINDOWS
, szTmp
, sizeof(szTmp
)/sizeof(szTmp
[0]));
309 AppendMenuW(clientInfo
->hWindowMenu
, MF_STRING
, clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
, szTmp
);
314 /**********************************************************************
317 * returns "activateable" child different from the current or zero
319 static HWND
MDI_GetWindow(MDICLIENTINFO
*clientInfo
, HWND hWnd
, BOOL bNext
,
330 dwStyleMask
|= WS_DISABLED
| WS_VISIBLE
;
331 if( !hWnd
) hWnd
= clientInfo
->hwndActiveChild
;
333 if (!(list
= WIN_ListChildren( GetParent(hWnd
) ))) return 0;
335 /* start from next after hWnd */
336 while (list
[i
] && list
[i
] != hWnd
) i
++;
339 for ( ; list
[i
]; i
++)
341 if (GetWindow( list
[i
], GW_OWNER
)) continue;
342 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
344 if (bNext
) goto found
;
346 /* now restart from the beginning */
347 for (i
= 0; list
[i
] && list
[i
] != hWnd
; i
++)
349 if (GetWindow( list
[i
], GW_OWNER
)) continue;
350 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
352 if (bNext
) goto found
;
355 HeapFree( GetProcessHeap(), 0, list
);
360 /**********************************************************************
361 * MDI_CalcDefaultChildPos
363 * It seems that the default height is about 2/3 of the client rect
365 static void MDI_CalcDefaultChildPos( HWND hwnd
, WORD n
, LPPOINT lpPos
, INT delta
)
369 INT spacing
= GetSystemMetrics(SM_CYCAPTION
) +
370 GetSystemMetrics(SM_CYFRAME
) - 1;
372 GetClientRect( hwnd
, &rect
);
373 if( rect
.bottom
- rect
.top
- delta
>= spacing
)
374 rect
.bottom
-= delta
;
376 nstagger
= (rect
.bottom
- rect
.top
)/(3 * spacing
);
377 lpPos
[1].x
= (rect
.right
- rect
.left
- nstagger
* spacing
);
378 lpPos
[1].y
= (rect
.bottom
- rect
.top
- nstagger
* spacing
);
379 lpPos
[0].x
= lpPos
[0].y
= spacing
* (n
%(nstagger
+1));
382 /**********************************************************************
385 static LRESULT
MDISetMenu( HWND hwnd
, HMENU hmenuFrame
,
389 HWND hwndFrame
= GetParent(hwnd
);
390 HMENU oldFrameMenu
= GetMenu(hwndFrame
);
392 TRACE("%p %p %p\n", hwnd
, hmenuFrame
, hmenuWindow
);
394 if (hmenuFrame
&& !IsMenu(hmenuFrame
))
396 WARN("hmenuFrame is not a menu handle\n");
400 if (hmenuWindow
&& !IsMenu(hmenuWindow
))
402 WARN("hmenuWindow is not a menu handle\n");
406 if (!(ci
= get_client_info( hwnd
))) return 0;
408 if( ci
->hwndChildMaximized
&& hmenuFrame
&& hmenuFrame
!=oldFrameMenu
)
409 MDI_RestoreFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
411 if( hmenuWindow
&& hmenuWindow
!= ci
->hWindowMenu
)
413 /* delete menu items from ci->hWindowMenu
414 * and add them to hmenuWindow */
415 /* Agent newsreader calls this function with ci->hWindowMenu == NULL */
416 if( ci
->hWindowMenu
&& ci
->nActiveChildren
)
419 LPWSTR buffer
= NULL
;
421 INT nbWindowsMenuItems
; /* num of documents shown + "More Windows..." if present */
422 INT i
= GetMenuItemCount(ci
->hWindowMenu
) - 1;
423 INT pos
= GetMenuItemCount(hmenuWindow
) + 1;
425 AppendMenuA( hmenuWindow
, MF_SEPARATOR
, 0, NULL
);
427 if (ci
->nActiveChildren
<= MDI_MOREWINDOWSLIMIT
)
428 nbWindowsMenuItems
= ci
->nActiveChildren
;
430 nbWindowsMenuItems
= MDI_MOREWINDOWSLIMIT
+ 1;
432 j
= i
- nbWindowsMenuItems
+ 1;
434 for( ; i
>= j
; i
-- )
436 memset(&mii
, 0, sizeof(mii
));
437 mii
.cbSize
= sizeof(mii
);
438 mii
.fMask
= MIIM_CHECKMARKS
| MIIM_DATA
| MIIM_ID
| MIIM_STATE
439 | MIIM_SUBMENU
| MIIM_TYPE
| MIIM_BITMAP
;
441 GetMenuItemInfoW(ci
->hWindowMenu
, i
, TRUE
, &mii
);
442 if(mii
.cch
) { /* Menu is MFT_STRING */
443 mii
.cch
++; /* add room for '\0' */
444 buffer
= HeapAlloc(GetProcessHeap(), 0,
445 mii
.cch
* sizeof(WCHAR
));
446 mii
.dwTypeData
= buffer
;
447 GetMenuItemInfoW(ci
->hWindowMenu
, i
, TRUE
, &mii
);
449 DeleteMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
450 InsertMenuItemW(hmenuWindow
, pos
, TRUE
, &mii
);
452 HeapFree(GetProcessHeap(), 0, buffer
);
456 /* remove separator */
457 DeleteMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
459 ci
->hWindowMenu
= hmenuWindow
;
464 SetMenu(hwndFrame
, hmenuFrame
);
465 if( hmenuFrame
!=oldFrameMenu
)
467 if( ci
->hwndChildMaximized
)
468 MDI_AugmentFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
469 return (LRESULT
)oldFrameMenu
;
474 HMENU menu
= GetMenu( GetParent(hwnd
) );
475 INT nItems
= GetMenuItemCount(menu
) - 1;
476 UINT iId
= GetMenuItemID(menu
,nItems
) ;
478 if( !(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
480 /* SetMenu() may already have been called, meaning that this window
481 * already has its menu. But they may have done a SetMenu() on
482 * an MDI window, and called MDISetMenu() after the fact, meaning
483 * that the "if" to this "else" wouldn't catch the need to
484 * augment the frame menu.
486 if( ci
->hwndChildMaximized
)
487 MDI_AugmentFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
493 /**********************************************************************
496 static LRESULT
MDIRefreshMenu( HWND hwnd
, HMENU hmenuFrame
,
499 HWND hwndFrame
= GetParent(hwnd
);
500 HMENU oldFrameMenu
= GetMenu(hwndFrame
);
502 TRACE("%p %p %p\n", hwnd
, hmenuFrame
, hmenuWindow
);
504 FIXME("partially function stub\n");
506 return (LRESULT
)oldFrameMenu
;
510 /* ------------------ MDI child window functions ---------------------- */
513 /**********************************************************************
516 static HWND
MDICreateChild( HWND parent
, MDICLIENTINFO
*ci
,
517 LPMDICREATESTRUCTA cs
, BOOL unicode
)
520 DWORD style
= cs
->style
| (WS_CHILD
| WS_CLIPSIBLINGS
);
521 HWND hwnd
, hwndMax
= 0;
522 UINT wIDmenu
= ci
->idFirstChild
+ ci
->nActiveChildren
;
526 static const WCHAR lpstrDef
[] = {'j','u','n','k','!',0};
528 TRACE("origin %i,%i - dim %i,%i, style %08lx\n",
529 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, cs
->style
);
530 /* calculate placement */
531 MDI_CalcDefaultChildPos(parent
, ci
->nTotalCreated
++, pos
, 0);
534 if (cs
->cx
== CW_USEDEFAULT
|| cs
->cx
== CW_USEDEFAULT16
|| !cs
->cx
) cs
->cx
= pos
[1].x
;
535 if (cs
->cy
== CW_USEDEFAULT
|| cs
->cy
== CW_USEDEFAULT16
|| !cs
->cy
) cs
->cy
= pos
[1].y
;
537 if (cs
->x
== CW_USEDEFAULT
|| cs
->x
== CW_USEDEFAULT16
)
539 if (cs
->cx
== CW_USEDEFAULT
|| !cs
->cx
) cs
->cx
= pos
[1].x
;
540 if (cs
->cy
== CW_USEDEFAULT
|| !cs
->cy
) cs
->cy
= pos
[1].y
;
542 if (cs
->x
== CW_USEDEFAULT
)
549 /* restore current maximized child */
550 if( (style
& WS_VISIBLE
) && ci
->hwndChildMaximized
)
552 TRACE("Restoring current maximized child %p\n", ci
->hwndChildMaximized
);
553 if( style
& WS_MAXIMIZE
)
554 SendMessageW(parent
, WM_SETREDRAW
, FALSE
, 0L);
555 hwndMax
= ci
->hwndChildMaximized
;
556 ShowWindow( hwndMax
, SW_SHOWNOACTIVATE
);
557 if( style
& WS_MAXIMIZE
)
558 SendMessageW(parent
, WM_SETREDRAW
, TRUE
, 0L);
561 if (ci
->nActiveChildren
<= MDI_MOREWINDOWSLIMIT
)
562 /* this menu is needed to set a check mark in MDI_ChildActivate */
563 if (ci
->hWindowMenu
!= 0)
564 AppendMenuW(ci
->hWindowMenu
, MF_STRING
, wIDmenu
, lpstrDef
);
566 ci
->nActiveChildren
++;
568 /* fix window style */
570 wndParent
= WIN_FindWndPtr( parent
);
571 if( !(wndParent
->dwStyle
& MDIS_ALLCHILDSTYLES
) )
573 if( !(GetWindowLong(parent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
) )
576 TRACE("MDIS_ALLCHILDSTYLES is missing, fixing window style\n");
577 style
&= (WS_CHILD
| WS_CLIPSIBLINGS
| WS_MINIMIZE
| WS_MAXIMIZE
|
578 WS_CLIPCHILDREN
| WS_DISABLED
| WS_VSCROLL
| WS_HSCROLL
);
579 style
|= (WS_VISIBLE
| WS_OVERLAPPEDWINDOW
);
583 if( wndParent
->flags
& WIN_ISWIN32
)
587 WIN_ReleaseWndPtr( wndParent
);
591 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)cs
;
592 hwnd
= CreateWindowW( csW
->szClass
, csW
->szTitle
, style
,
593 csW
->x
, csW
->y
, csW
->cx
, csW
->cy
, parent
,
594 (HMENU
)wIDmenu
, csW
->hOwner
, csW
);
597 hwnd
= CreateWindowA( cs
->szClass
, cs
->szTitle
, style
,
598 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, parent
,
599 (HMENU
)wIDmenu
, cs
->hOwner
, cs
);
604 MDICREATESTRUCT16 cs16
;
605 SEGPTR title
, cls
, seg_cs16
;
607 WIN_ReleaseWndPtr( wndParent
);
608 STRUCT32_MDICREATESTRUCT32Ato16( cs
, &cs16
);
609 cs16
.szTitle
= title
= MapLS( cs
->szTitle
);
610 cs16
.szClass
= cls
= MapLS( cs
->szClass
);
611 seg_cs16
= MapLS( &cs16
);
612 hwnd
= WIN_Handle32( CreateWindow16( cs
->szClass
, cs
->szTitle
, style
,
613 cs16
.x
, cs16
.y
, cs16
.cx
, cs16
.cy
,
614 HWND_16(parent
), (HMENU16
)wIDmenu
,
615 cs16
.hOwner
, (LPVOID
)seg_cs16
));
622 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
626 /* All MDI child windows have the WS_EX_MDICHILD style */
627 SetWindowLongW( hwnd
, GWL_EXSTYLE
, GetWindowLongW( hwnd
, GWL_EXSTYLE
) | WS_EX_MDICHILD
);
629 /* If we have more than 9 windows, we must insert the new one at the
630 * 9th position in order to see it in the "Windows" menu
632 if (ci
->nActiveChildren
> MDI_MOREWINDOWSLIMIT
)
633 MDI_SwapMenuItems( parent
, GetWindowLongW( hwnd
, GWL_ID
),
634 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1);
636 MDI_MenuModifyItem(parent
, hwnd
);
638 /* Have we hit the "More Windows..." limit? If so, we must
639 * add a "More Windows..." option
641 if (ci
->nActiveChildren
== MDI_MOREWINDOWSLIMIT
+ 1)
644 LoadStringW(GetModuleHandleA("USER32"), IDS_MDI_MOREWINDOWS
, szTmp
, sizeof(szTmp
)/sizeof(szTmp
[0]));
646 ModifyMenuW(ci
->hWindowMenu
,
647 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
,
648 MF_BYCOMMAND
| MF_STRING
,
649 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
,
653 if( IsIconic(hwnd
) && ci
->hwndActiveChild
)
655 TRACE("Minimizing created MDI child %p\n", hwnd
);
656 ShowWindow( hwnd
, SW_SHOWMINNOACTIVE
);
660 /* WS_VISIBLE is clear if a) the MDI client has
661 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
662 * MDICreateStruct. If so the created window is not shown nor
665 if (IsWindowVisible(hwnd
)) ShowWindow(hwnd
, SW_SHOW
);
667 TRACE("created child - %p\n",hwnd
);
671 ci
->nActiveChildren
--;
672 DeleteMenu(ci
->hWindowMenu
,wIDmenu
,MF_BYCOMMAND
);
673 if( IsWindow(hwndMax
) )
674 ShowWindow(hwndMax
, SW_SHOWMAXIMIZED
);
680 /**********************************************************************
681 * MDI_ChildGetMinMaxInfo
683 * Note: The rule here is that client rect of the maximized MDI child
684 * is equal to the client rect of the MDI client window.
686 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
690 GetClientRect( client
, &rect
);
691 AdjustWindowRectEx( &rect
, GetWindowLongW( hwnd
, GWL_STYLE
),
692 0, GetWindowLongW( hwnd
, GWL_EXSTYLE
));
694 lpMinMax
->ptMaxSize
.x
= rect
.right
-= rect
.left
;
695 lpMinMax
->ptMaxSize
.y
= rect
.bottom
-= rect
.top
;
697 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
698 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
700 TRACE("max rect (%ld,%ld - %ld, %ld)\n",
701 rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
704 /**********************************************************************
705 * MDI_SwitchActiveChild
707 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
710 static void MDI_SwitchActiveChild( HWND clientHwnd
, HWND childHwnd
,
715 MDICLIENTINFO
*ci
= get_client_info( clientHwnd
);
717 hwndTo
= MDI_GetWindow(ci
, childHwnd
, bNextWindow
, 0);
719 TRACE("from %p, to %p\n",childHwnd
,hwndTo
);
721 if ( !hwndTo
) return; /* no window to switch to */
723 hwndPrev
= ci
->hwndActiveChild
;
725 if ( hwndTo
!= hwndPrev
)
727 SetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0,
728 SWP_NOMOVE
| SWP_NOSIZE
);
730 if( bNextWindow
&& hwndPrev
)
731 SetWindowPos( hwndPrev
, HWND_BOTTOM
, 0, 0, 0, 0,
732 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
737 /**********************************************************************
740 static LRESULT
MDIDestroyChild( HWND parent
, MDICLIENTINFO
*ci
,
741 HWND child
, BOOL flagDestroy
)
743 if( child
== ci
->hwndActiveChild
)
745 MDI_SwitchActiveChild(parent
, child
, TRUE
);
747 if( child
== ci
->hwndActiveChild
)
749 ShowWindow( child
, SW_HIDE
);
750 if( child
== ci
->hwndChildMaximized
)
752 HWND frame
= GetParent(parent
);
753 MDI_RestoreFrameMenu( frame
, child
);
754 ci
->hwndChildMaximized
= 0;
755 MDI_UpdateFrameText( frame
, parent
, TRUE
, NULL
);
758 MDI_ChildActivate(parent
, 0);
762 MDI_MenuDeleteItem(parent
, child
);
764 ci
->nActiveChildren
--;
766 TRACE("child destroyed - %p\n",child
);
770 MDI_PostUpdate(GetParent(child
), ci
, SB_BOTH
+1);
771 DestroyWindow(child
);
777 /**********************************************************************
780 * Note: hWndChild is NULL when last child is being destroyed
782 static LONG
MDI_ChildActivate( HWND client
, HWND child
)
784 MDICLIENTINFO
*clientInfo
= get_client_info( client
);
785 HWND prevActiveWnd
= clientInfo
->hwndActiveChild
;
786 BOOL isActiveFrameWnd
;
788 if (child
&& (!IsWindowEnabled( child
))) return 0;
790 /* Don't activate if it is already active. Might happen
791 since ShowWindow DOES activate MDI children */
792 if (clientInfo
->hwndActiveChild
== child
) return 0;
794 TRACE("%p\n", child
);
796 isActiveFrameWnd
= (GetActiveWindow() == GetParent(client
));
798 /* deactivate prev. active child */
801 SetWindowLongA( prevActiveWnd
, GWL_STYLE
,
802 GetWindowLongA( prevActiveWnd
, GWL_STYLE
) | WS_SYSMENU
);
803 SendMessageA( prevActiveWnd
, WM_NCACTIVATE
, FALSE
, 0L );
804 SendMessageA( prevActiveWnd
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
805 /* uncheck menu item */
806 if( clientInfo
->hWindowMenu
)
808 UINT prevID
= GetWindowLongA( prevActiveWnd
, GWL_ID
);
810 if (prevID
- clientInfo
->idFirstChild
< MDI_MOREWINDOWSLIMIT
)
811 CheckMenuItem( clientInfo
->hWindowMenu
, prevID
, 0);
813 CheckMenuItem( clientInfo
->hWindowMenu
,
814 clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1, 0);
819 if (clientInfo
->hwndChildMaximized
&& clientInfo
->hwndChildMaximized
!= child
)
821 INT cmd
= SW_SHOWNORMAL
;
825 UINT state
= GetMenuState(GetSystemMenu(child
, FALSE
), SC_MAXIMIZE
, MF_BYCOMMAND
);
826 if (state
!= 0xFFFFFFFF && (state
& (MF_DISABLED
| MF_GRAYED
)))
827 SendMessageW(clientInfo
->hwndChildMaximized
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
829 cmd
= SW_SHOWMAXIMIZED
;
831 clientInfo
->hwndActiveChild
= child
;
834 ShowWindow( clientInfo
->hwndActiveChild
, cmd
);
837 clientInfo
->hwndActiveChild
= child
;
839 /* check if we have any children left */
842 if( isActiveFrameWnd
)
847 /* check menu item */
848 if( clientInfo
->hWindowMenu
)
850 UINT id
= GetWindowLongA( child
, GWL_ID
);
851 /* The window to be activated must be displayed in the "Windows" menu */
852 if (id
>= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
)
854 MDI_SwapMenuItems( GetParent(child
),
855 id
, clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1);
856 id
= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1;
857 MDI_MenuModifyItem( GetParent(child
), child
);
860 CheckMenuItem(clientInfo
->hWindowMenu
, id
, MF_CHECKED
);
862 /* bring active child to the top */
863 SetWindowPos( child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
865 if( isActiveFrameWnd
)
867 SendMessageA( child
, WM_NCACTIVATE
, TRUE
, 0L);
868 if( GetFocus() == client
)
869 SendMessageA( client
, WM_SETFOCUS
, (WPARAM
)client
, 0L );
873 SendMessageA( child
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
877 /* -------------------- MDI client window functions ------------------- */
879 /**********************************************************************
880 * CreateMDIMenuBitmap
882 static HBITMAP
CreateMDIMenuBitmap(void)
884 HDC hDCSrc
= CreateCompatibleDC(0);
885 HDC hDCDest
= CreateCompatibleDC(hDCSrc
);
886 HBITMAP hbClose
= LoadBitmapW(0, MAKEINTRESOURCEW(OBM_CLOSE
) );
888 HBITMAP hobjSrc
, hobjDest
;
890 hobjSrc
= SelectObject(hDCSrc
, hbClose
);
891 hbCopy
= CreateCompatibleBitmap(hDCSrc
,GetSystemMetrics(SM_CXSIZE
),GetSystemMetrics(SM_CYSIZE
));
892 hobjDest
= SelectObject(hDCDest
, hbCopy
);
894 BitBlt(hDCDest
, 0, 0, GetSystemMetrics(SM_CXSIZE
), GetSystemMetrics(SM_CYSIZE
),
895 hDCSrc
, GetSystemMetrics(SM_CXSIZE
), 0, SRCCOPY
);
897 SelectObject(hDCSrc
, hobjSrc
);
898 DeleteObject(hbClose
);
901 hobjSrc
= SelectObject( hDCDest
, GetStockObject(BLACK_PEN
) );
903 MoveToEx( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, 0, NULL
);
904 LineTo( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, GetSystemMetrics(SM_CYSIZE
) - 1);
906 SelectObject(hDCDest
, hobjSrc
);
907 SelectObject(hDCDest
, hobjDest
);
913 /**********************************************************************
916 static LONG
MDICascade( HWND client
, MDICLIENTINFO
*ci
)
923 BOOL has_icons
= FALSE
;
926 if (ci
->hwndChildMaximized
)
927 SendMessageA( client
, WM_MDIRESTORE
,
928 (WPARAM
)ci
->hwndChildMaximized
, 0);
930 if (ci
->nActiveChildren
== 0) return 0;
932 if (!(win_array
= WIN_ListChildren( client
))) return 0;
934 /* remove all the windows we don't want */
935 for (i
= total
= 0; win_array
[i
]; i
++)
937 if (!IsWindowVisible( win_array
[i
] )) continue;
938 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows */
939 if (IsIconic( win_array
[i
] ))
944 win_array
[total
++] = win_array
[i
];
946 win_array
[total
] = 0;
950 INT delta
= 0, n
= 0, i
;
952 if (has_icons
) delta
= GetSystemMetrics(SM_CYICONSPACING
) + GetSystemMetrics(SM_CYICON
);
954 /* walk the list (backwards) and move windows */
955 for (i
= total
- 1; i
>= 0; i
--)
957 TRACE("move %p to (%ld,%ld) size [%ld,%ld]\n",
958 win_array
[i
], pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
);
960 MDI_CalcDefaultChildPos(client
, n
++, pos
, delta
);
961 SetWindowPos( win_array
[i
], 0, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
,
962 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
965 HeapFree( GetProcessHeap(), 0, win_array
);
967 if (has_icons
) ArrangeIconicWindows( client
);
972 /**********************************************************************
975 static void MDITile( HWND client
, MDICLIENTINFO
*ci
, WPARAM wParam
)
983 BOOL has_icons
= FALSE
;
985 if (ci
->hwndChildMaximized
)
986 SendMessageA( client
, WM_MDIRESTORE
, (WPARAM
)ci
->hwndChildMaximized
, 0);
988 if (ci
->nActiveChildren
== 0) return;
990 if (!(win_array
= WIN_ListChildren( client
))) return;
992 /* remove all the windows we don't want */
993 for (i
= total
= 0; win_array
[i
]; i
++)
995 if (!IsWindowVisible( win_array
[i
] )) continue;
996 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows (icon titles) */
997 if (IsIconic( win_array
[i
] ))
1002 if ((wParam
& MDITILE_SKIPDISABLED
) && !IsWindowEnabled( win_array
[i
] )) continue;
1003 win_array
[total
++] = win_array
[i
];
1005 win_array
[total
] = 0;
1007 TRACE("%u windows to tile\n", total
);
1011 HWND
*pWnd
= win_array
;
1013 int x
, y
, xsize
, ysize
;
1014 int rows
, columns
, r
, c
, i
;
1016 GetClientRect(client
,&rect
);
1017 rows
= (int) sqrt((double)total
);
1018 columns
= total
/ rows
;
1020 if( wParam
& MDITILE_HORIZONTAL
) /* version >= 3.1 */
1023 rows
= columns
; /* exchange r and c */
1029 y
= rect
.bottom
- 2 * GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
1030 rect
.bottom
= ( y
- GetSystemMetrics(SM_CYICON
) < rect
.top
)? rect
.bottom
: y
;
1033 ysize
= rect
.bottom
/ rows
;
1034 xsize
= rect
.right
/ columns
;
1036 for (x
= i
= 0, c
= 1; c
<= columns
&& *pWnd
; c
++)
1041 ysize
= rect
.bottom
/ rows
;
1045 for (r
= 1; r
<= rows
&& *pWnd
; r
++, i
++)
1047 SetWindowPos(*pWnd
, 0, x
, y
, xsize
, ysize
,
1048 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
1055 HeapFree( GetProcessHeap(), 0, win_array
);
1056 if (has_icons
) ArrangeIconicWindows( client
);
1060 /* ----------------------- Frame window ---------------------------- */
1063 /**********************************************************************
1064 * MDI_AugmentFrameMenu
1066 static BOOL
MDI_AugmentFrameMenu( HWND frame
, HWND hChild
)
1068 HMENU menu
= GetMenu( frame
);
1069 HMENU hSysPopup
= 0;
1070 HBITMAP hSysMenuBitmap
= 0;
1075 TRACE("frame %p,child %p\n",frame
,hChild
);
1077 if( !menu
) return 0;
1079 /* if the system buttons already exist do not add them again */
1080 nItems
= GetMenuItemCount(menu
) - 1;
1081 iId
= GetMenuItemID(menu
,nItems
) ;
1082 if (iId
== SC_RESTORE
|| iId
== SC_CLOSE
)
1085 /* create a copy of sysmenu popup and insert it into frame menu bar */
1086 if (!(hSysPopup
= GetSystemMenu(hChild
, FALSE
)))
1089 AppendMenuA(menu
,MF_HELP
| MF_BITMAP
,
1090 SC_MINIMIZE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_MINIMIZE
) ;
1091 AppendMenuA(menu
,MF_HELP
| MF_BITMAP
,
1092 SC_RESTORE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_RESTORE
);
1094 AppendMenuA(menu
,MF_HELP
| MF_BITMAP
,
1095 SC_CLOSE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_CLOSE
);
1097 /* The system menu is replaced by the child icon */
1098 hIcon
= (HICON
)GetClassLongW(hChild
, GCL_HICONSM
);
1100 hIcon
= (HICON
)GetClassLongW(hChild
, GCL_HICON
);
1102 hIcon
= LoadIconW(NULL
, IDI_APPLICATION
);
1106 HBITMAP hBitmap
, hOldBitmap
;
1108 HDC hdc
= GetDC(hChild
);
1113 cx
= GetSystemMetrics(SM_CXSMICON
);
1114 cy
= GetSystemMetrics(SM_CYSMICON
);
1115 hMemDC
= CreateCompatibleDC(hdc
);
1116 hBitmap
= CreateCompatibleBitmap(hdc
, cx
, cy
);
1117 hOldBitmap
= SelectObject(hMemDC
, hBitmap
);
1118 SetMapMode(hMemDC
, MM_TEXT
);
1119 hBrush
= CreateSolidBrush(GetSysColor(COLOR_MENU
));
1120 DrawIconEx(hMemDC
, 0, 0, hIcon
, cx
, cy
, 0, hBrush
, DI_NORMAL
);
1121 SelectObject (hMemDC
, hOldBitmap
);
1122 DeleteObject(hBrush
);
1124 ReleaseDC(hChild
, hdc
);
1125 hSysMenuBitmap
= hBitmap
;
1129 if( !InsertMenuA(menu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
1130 (UINT_PTR
)hSysPopup
, (LPSTR
)hSysMenuBitmap
))
1132 TRACE("not inserted\n");
1133 DestroyMenu(hSysPopup
);
1137 EnableMenuItem(hSysPopup
, SC_SIZE
, MF_BYCOMMAND
| MF_GRAYED
);
1138 EnableMenuItem(hSysPopup
, SC_MOVE
, MF_BYCOMMAND
| MF_GRAYED
);
1139 EnableMenuItem(hSysPopup
, SC_MAXIMIZE
, MF_BYCOMMAND
| MF_GRAYED
);
1140 SetMenuDefaultItem(hSysPopup
, SC_CLOSE
, FALSE
);
1148 /**********************************************************************
1149 * MDI_RestoreFrameMenu
1151 static BOOL
MDI_RestoreFrameMenu( HWND frame
, HWND hChild
)
1153 MENUITEMINFOW menuInfo
;
1154 HMENU menu
= GetMenu( frame
);
1155 INT nItems
= GetMenuItemCount(menu
) - 1;
1156 UINT iId
= GetMenuItemID(menu
,nItems
) ;
1158 TRACE("frame %p,child %p,nIt=%d,iId=%d\n",frame
,hChild
,nItems
,iId
);
1160 if(!(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
1164 * Remove the system menu, If that menu is the icon of the window
1165 * as it is in win95, we have to delete the bitmap.
1167 memset(&menuInfo
, 0, sizeof(menuInfo
));
1168 menuInfo
.cbSize
= sizeof(menuInfo
);
1169 menuInfo
.fMask
= MIIM_DATA
| MIIM_TYPE
| MIIM_BITMAP
;
1171 GetMenuItemInfoW(menu
,
1176 RemoveMenu(menu
,0,MF_BYPOSITION
);
1178 if ( menuInfo
.hbmpItem
!= 0 )
1179 DeleteObject(menuInfo
.hbmpItem
);
1182 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
1184 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
1186 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
1194 /**********************************************************************
1195 * MDI_UpdateFrameText
1197 * used when child window is maximized/restored
1199 * Note: lpTitle can be NULL
1201 static void MDI_UpdateFrameText( HWND frame
, HWND hClient
,
1202 BOOL repaint
, LPCWSTR lpTitle
)
1204 WCHAR lpBuffer
[MDI_MAXTITLELENGTH
+1];
1205 MDICLIENTINFO
*ci
= get_client_info( hClient
);
1207 TRACE("repaint %i, frameText %s\n", repaint
, debugstr_w(lpTitle
));
1211 if (!lpTitle
&& !ci
->frameTitle
) /* first time around, get title from the frame window */
1213 GetWindowTextW( frame
, lpBuffer
, sizeof(lpBuffer
)/sizeof(WCHAR
) );
1217 /* store new "default" title if lpTitle is not NULL */
1220 if (ci
->frameTitle
) HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1221 if ((ci
->frameTitle
= HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle
)+1)*sizeof(WCHAR
))))
1222 strcpyW( ci
->frameTitle
, lpTitle
);
1227 if (ci
->hwndChildMaximized
)
1229 /* combine frame title and child title if possible */
1231 static const WCHAR lpBracket
[] = {' ','-',' ','[',0};
1232 static const WCHAR lpBracket2
[] = {']',0};
1233 int i_frame_text_length
= strlenW(ci
->frameTitle
);
1235 lstrcpynW( lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
1237 if( i_frame_text_length
+ 6 < MDI_MAXTITLELENGTH
)
1239 strcatW( lpBuffer
, lpBracket
);
1240 if (GetWindowTextW( ci
->hwndChildMaximized
, lpBuffer
+ i_frame_text_length
+ 4,
1241 MDI_MAXTITLELENGTH
- i_frame_text_length
- 5 ))
1242 strcatW( lpBuffer
, lpBracket2
);
1244 lpBuffer
[i_frame_text_length
] = 0; /* remove bracket */
1249 lstrcpynW(lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
+1 );
1255 DefWindowProcW( frame
, WM_SETTEXT
, 0, (LPARAM
)lpBuffer
);
1256 if( repaint
== MDI_REPAINTFRAME
)
1257 SetWindowPos( frame
, 0,0,0,0,0, SWP_FRAMECHANGED
|
1258 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
1262 /* ----------------------------- Interface ---------------------------- */
1265 /**********************************************************************
1266 * MDIClientWndProc_common
1268 static LRESULT
MDIClientWndProc_common( HWND hwnd
, UINT message
,
1269 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1271 MDICLIENTINFO
*ci
= NULL
;
1273 if (WM_NCCREATE
!= message
1274 && NULL
== (ci
= get_client_info(hwnd
)))
1283 if (!(ci
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ci
))))
1285 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)ci
);
1292 /* Since we are using only cs->lpCreateParams, we can safely
1293 * cast to LPCREATESTRUCTA here */
1294 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
1296 WND
*wndPtr
= WIN_GetPtr( hwnd
);
1299 /* Translation layer doesn't know what's in the cs->lpCreateParams
1300 * so we have to keep track of what environment we're in. */
1303 if( wndPtr
->flags
& WIN_ISWIN32
)
1306 #define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1307 ci
->hWindowMenu
= ccs
->hWindowMenu
;
1308 ci
->idFirstChild
= ccs
->idFirstChild
;
1314 LPCLIENTCREATESTRUCT16 ccs
= MapSL((SEGPTR
)cs
->lpCreateParams
);
1315 ci
->hWindowMenu
= HMENU_32(ccs
->hWindowMenu
);
1316 ci
->idFirstChild
= ccs
->idFirstChild
;
1318 WIN_ReleasePtr( wndPtr
);
1321 ci
->hwndChildMaximized
= 0;
1322 ci
->nActiveChildren
= 0;
1323 ci
->nTotalCreated
= 0;
1324 ci
->frameTitle
= NULL
;
1326 SetWindowLongW( hwnd
, GWL_STYLE
, GetWindowLongW(hwnd
,GWL_STYLE
) | WS_CLIPCHILDREN
);
1328 if (!hBmpClose
) hBmpClose
= CreateMDIMenuBitmap();
1330 if (ci
->hWindowMenu
!= 0)
1331 AppendMenuW( ci
->hWindowMenu
, MF_SEPARATOR
, 0, NULL
);
1333 GetClientRect( GetParent(hwnd
), &rect
);
1334 MoveWindow( hwnd
, 0, 0, rect
.right
, rect
.bottom
, FALSE
);
1336 MDI_UpdateFrameText( GetParent(hwnd
), hwnd
, MDI_NOFRAMEREPAINT
, NULL
);
1338 TRACE("Client created - hwnd = %p, idFirst = %u\n", hwnd
, ci
->idFirstChild
);
1345 if( ci
->hwndChildMaximized
)
1346 MDI_RestoreFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
1347 if((ci
->hWindowMenu
!= 0) &&
1348 (nItems
= GetMenuItemCount(ci
->hWindowMenu
)) > 0)
1350 ci
->idFirstChild
= nItems
- 1;
1351 ci
->nActiveChildren
++; /* to delete a separator */
1352 while( ci
->nActiveChildren
-- )
1353 DeleteMenu(ci
->hWindowMenu
,MF_BYPOSITION
,ci
->idFirstChild
--);
1355 if (ci
->frameTitle
) HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1357 HeapFree( GetProcessHeap(), 0, ci
);
1358 SetWindowLongPtrW( hwnd
, 0, 0 );
1363 case WM_MDIACTIVATE
:
1364 if( ci
->hwndActiveChild
!= (HWND
)wParam
)
1365 SetWindowPos((HWND
)wParam
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1369 return MDICascade(hwnd
, ci
);
1373 return (LRESULT
)MDICreateChild( hwnd
, ci
, (MDICREATESTRUCTA
*)lParam
, unicode
);
1378 return MDIDestroyChild( hwnd
, ci
, WIN_GetFullHandle( (HWND
)wParam
), TRUE
);
1380 return MDIDestroyChild( hwnd
, ci
, (HWND
)wParam
, TRUE
);
1383 case WM_MDIGETACTIVE
:
1384 if (lParam
) *(BOOL
*)lParam
= (ci
->hwndChildMaximized
!= 0);
1385 return (LRESULT
)ci
->hwndActiveChild
;
1387 case WM_MDIICONARRANGE
:
1388 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1389 ArrangeIconicWindows( hwnd
);
1390 ci
->sbRecalc
= SB_BOTH
+1;
1391 SendMessageW( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0 );
1394 case WM_MDIMAXIMIZE
:
1395 ShowWindow( (HWND
)wParam
, SW_MAXIMIZE
);
1398 case WM_MDINEXT
: /* lParam != 0 means previous window */
1400 MDI_SwitchActiveChild( hwnd
, WIN_GetFullHandle( (HWND
)wParam
), !lParam
);
1402 MDI_SwitchActiveChild( hwnd
, (HWND
)wParam
, !lParam
);
1407 SendMessageW( (HWND
)wParam
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
1411 return MDISetMenu( hwnd
, (HMENU
)wParam
, (HMENU
)lParam
);
1413 case WM_MDIREFRESHMENU
:
1414 return MDIRefreshMenu( hwnd
, (HMENU
)wParam
, (HMENU
)lParam
);
1417 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1418 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
1419 MDITile( hwnd
, ci
, wParam
);
1420 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1425 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1426 ScrollChildren( hwnd
, message
, wParam
, lParam
);
1427 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1431 if (ci
->hwndActiveChild
&& !IsIconic( ci
->hwndActiveChild
))
1432 SetFocus( ci
->hwndActiveChild
);
1436 if( ci
->hwndActiveChild
)
1437 SendMessageW(ci
->hwndActiveChild
, message
, wParam
, lParam
);
1440 case WM_PARENTNOTIFY
:
1441 if (LOWORD(wParam
) == WM_LBUTTONDOWN
)
1445 pt
.x
= (short)LOWORD(lParam
);
1446 pt
.y
= (short)HIWORD(lParam
);
1447 child
= ChildWindowFromPoint(hwnd
, pt
);
1449 TRACE("notification from %p (%li,%li)\n",child
,pt
.x
,pt
.y
);
1451 if( child
&& child
!= hwnd
&& child
!= ci
->hwndActiveChild
)
1452 SetWindowPos(child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1457 if( IsWindow(ci
->hwndChildMaximized
) )
1463 rect
.right
= LOWORD(lParam
);
1464 rect
.bottom
= HIWORD(lParam
);
1466 AdjustWindowRectEx(&rect
, GetWindowLongA(ci
->hwndChildMaximized
,GWL_STYLE
),
1467 0, GetWindowLongA(ci
->hwndChildMaximized
,GWL_EXSTYLE
) );
1468 MoveWindow(ci
->hwndChildMaximized
, rect
.left
, rect
.top
,
1469 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 1);
1472 MDI_PostUpdate(hwnd
, ci
, SB_BOTH
+1);
1476 case WM_MDICALCCHILDSCROLL
:
1477 if( (ci
->mdiFlags
& MDIF_NEEDUPDATE
) && ci
->sbRecalc
)
1479 CalcChildScroll(hwnd
, ci
->sbRecalc
-1);
1481 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1485 return unicode
? DefWindowProcW( hwnd
, message
, wParam
, lParam
) :
1486 DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1489 /***********************************************************************
1492 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1494 if (!IsWindow(hwnd
)) return 0;
1495 return MDIClientWndProc_common( hwnd
, message
, wParam
, lParam
, FALSE
);
1498 /***********************************************************************
1501 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1503 if (!IsWindow(hwnd
)) return 0;
1504 return MDIClientWndProc_common( hwnd
, message
, wParam
, lParam
, TRUE
);
1508 /***********************************************************************
1509 * DefFrameProc (USER.445)
1511 LRESULT WINAPI
DefFrameProc16( HWND16 hwnd
, HWND16 hwndMDIClient
,
1512 UINT16 message
, WPARAM16 wParam
, LPARAM lParam
)
1517 lParam
= (LPARAM
)MapSL(lParam
);
1523 return DefFrameProcA( WIN_Handle32(hwnd
), WIN_Handle32(hwndMDIClient
),
1524 message
, wParam
, lParam
);
1528 MDINEXTMENU next_menu
;
1529 DefFrameProcW( WIN_Handle32(hwnd
), WIN_Handle32(hwndMDIClient
),
1530 message
, wParam
, (LPARAM
)&next_menu
);
1531 return MAKELONG( HMENU_16(next_menu
.hmenuNext
), HWND_16(next_menu
.hwndNext
) );
1534 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1539 /***********************************************************************
1540 * DefFrameProcA (USER32.@)
1542 LRESULT WINAPI
DefFrameProcA( HWND hwnd
, HWND hwndMDIClient
,
1543 UINT message
, WPARAM wParam
, LPARAM lParam
)
1551 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, NULL
, 0 );
1552 LPWSTR text
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1553 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, text
, len
);
1554 MDI_UpdateFrameText(hwnd
, hwndMDIClient
, MDI_REPAINTFRAME
, text
);
1555 HeapFree( GetProcessHeap(), 0, text
);
1557 return 1; /* success. FIXME: check text length */
1564 return DefFrameProcW( hwnd
, hwndMDIClient
, message
, wParam
, lParam
);
1567 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1571 /***********************************************************************
1572 * DefFrameProcW (USER32.@)
1574 LRESULT WINAPI
DefFrameProcW( HWND hwnd
, HWND hwndMDIClient
,
1575 UINT message
, WPARAM wParam
, LPARAM lParam
)
1577 MDICLIENTINFO
*ci
= get_client_info( hwndMDIClient
);
1585 WORD id
= LOWORD(wParam
);
1586 /* check for possible syscommands for maximized MDI child */
1587 if (id
< ci
->idFirstChild
|| id
>= ci
->idFirstChild
+ ci
->nActiveChildren
)
1589 if( (id
- 0xf000) & 0xf00f ) break;
1590 if( !ci
->hwndChildMaximized
) break;
1601 return SendMessageW( ci
->hwndChildMaximized
, WM_SYSCOMMAND
,
1608 if (id
- ci
->idFirstChild
== MDI_MOREWINDOWSLIMIT
)
1609 /* User chose "More Windows..." */
1610 childHwnd
= MDI_MoreWindowsDialog(hwndMDIClient
);
1612 /* User chose one of the windows listed in the "Windows" menu */
1613 childHwnd
= MDI_GetChildByID(hwndMDIClient
,id
);
1616 SendMessageW( hwndMDIClient
, WM_MDIACTIVATE
, (WPARAM
)childHwnd
, 0 );
1622 SendMessageW(hwndMDIClient
, message
, wParam
, lParam
);
1626 MDI_UpdateFrameText(hwnd
, hwndMDIClient
, MDI_REPAINTFRAME
, (LPWSTR
)lParam
);
1627 return 1; /* success. FIXME: check text length */
1630 SetFocus(hwndMDIClient
);
1634 MoveWindow(hwndMDIClient
, 0, 0, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1641 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1643 if (!IsIconic(hwnd
) && ci
->hwndActiveChild
&& !ci
->hwndChildMaximized
)
1645 /* control menu is between the frame system menu and
1646 * the first entry of menu bar */
1647 WND
*wndPtr
= WIN_GetPtr(hwnd
);
1649 if( (wParam
== VK_LEFT
&& GetMenu(hwnd
) == next_menu
->hmenuIn
) ||
1650 (wParam
== VK_RIGHT
&& GetSubMenu(wndPtr
->hSysMenu
, 0) == next_menu
->hmenuIn
) )
1652 WIN_ReleasePtr(wndPtr
);
1653 wndPtr
= WIN_GetPtr(ci
->hwndActiveChild
);
1654 next_menu
->hmenuNext
= GetSubMenu(wndPtr
->hSysMenu
, 0);
1655 next_menu
->hwndNext
= ci
->hwndActiveChild
;
1657 WIN_ReleasePtr(wndPtr
);
1665 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1670 /***********************************************************************
1671 * DefMDIChildProc (USER.447)
1673 LRESULT WINAPI
DefMDIChildProc16( HWND16 hwnd
, UINT16 message
,
1674 WPARAM16 wParam
, LPARAM lParam
)
1679 return DefMDIChildProcA( WIN_Handle32(hwnd
), message
, wParam
, (LPARAM
)MapSL(lParam
) );
1683 case WM_CHILDACTIVATE
:
1688 return DefMDIChildProcW( WIN_Handle32(hwnd
), message
, wParam
, lParam
);
1689 case WM_GETMINMAXINFO
:
1691 MINMAXINFO16
*mmi16
= (MINMAXINFO16
*)MapSL(lParam
);
1693 STRUCT32_MINMAXINFO16to32( mmi16
, &mmi
);
1694 DefMDIChildProcW( WIN_Handle32(hwnd
), message
, wParam
, (LPARAM
)&mmi
);
1695 STRUCT32_MINMAXINFO32to16( &mmi
, mmi16
);
1700 MDINEXTMENU next_menu
;
1701 DefMDIChildProcW( WIN_Handle32(hwnd
), message
, wParam
, (LPARAM
)&next_menu
);
1702 return MAKELONG( HMENU_16(next_menu
.hmenuNext
), HWND_16(next_menu
.hwndNext
) );
1705 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1711 /***********************************************************************
1712 * DefMDIChildProcA (USER32.@)
1714 LRESULT WINAPI
DefMDIChildProcA( HWND hwnd
, UINT message
,
1715 WPARAM wParam
, LPARAM lParam
)
1717 HWND client
= GetParent(hwnd
);
1718 MDICLIENTINFO
*ci
= get_client_info( client
);
1721 hwnd
= WIN_GetFullHandle( hwnd
);
1723 if (!ci
) return DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1728 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1729 MDI_MenuModifyItem( client
, hwnd
);
1730 if( ci
->hwndChildMaximized
== hwnd
)
1731 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1732 return 1; /* success. FIXME: check text length */
1734 case WM_GETMINMAXINFO
:
1738 case WM_CHILDACTIVATE
:
1747 return DefMDIChildProcW( hwnd
, message
, wParam
, lParam
);
1749 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1753 /***********************************************************************
1754 * DefMDIChildProcW (USER32.@)
1756 LRESULT WINAPI
DefMDIChildProcW( HWND hwnd
, UINT message
,
1757 WPARAM wParam
, LPARAM lParam
)
1759 HWND client
= GetParent(hwnd
);
1760 MDICLIENTINFO
*ci
= get_client_info( client
);
1763 hwnd
= WIN_GetFullHandle( hwnd
);
1765 if (!ci
) return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1770 DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1771 MDI_MenuModifyItem( client
, hwnd
);
1772 if( ci
->hwndChildMaximized
== hwnd
)
1773 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1774 return 1; /* success. FIXME: check text length */
1776 case WM_GETMINMAXINFO
:
1777 MDI_ChildGetMinMaxInfo( client
, hwnd
, (MINMAXINFO
*)lParam
);
1781 return 0x00010000; /* MDI children don't have menu bars */
1784 SendMessageW( client
, WM_MDIDESTROY
, (WPARAM
)hwnd
, 0 );
1788 if (ci
->hwndActiveChild
!= hwnd
) MDI_ChildActivate( client
, hwnd
);
1791 case WM_CHILDACTIVATE
:
1792 MDI_ChildActivate( client
, hwnd
);
1799 if( ci
->hwndChildMaximized
== hwnd
) return 0;
1803 SetWindowLongW( hwnd
, GWL_STYLE
,
1804 GetWindowLongW( hwnd
, GWL_STYLE
) | WS_SYSMENU
);
1807 if (ci
->hwndChildMaximized
== hwnd
)
1808 return SendMessageW( GetParent(client
), message
, wParam
, lParam
);
1809 SetWindowLongW( hwnd
, GWL_STYLE
,
1810 GetWindowLongW( hwnd
, GWL_STYLE
) & ~WS_SYSMENU
);
1813 SendMessageW( client
, WM_MDINEXT
, 0, 0);
1816 SendMessageW( client
, WM_MDINEXT
, 0, 1);
1824 if( ci
->hwndChildMaximized
) ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1825 else MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1830 if( ci
->hwndActiveChild
== hwnd
&& wParam
!= SIZE_MAXIMIZED
)
1832 ci
->hwndChildMaximized
= 0;
1833 MDI_RestoreFrameMenu( GetParent(client
), hwnd
);
1834 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1837 if( wParam
== SIZE_MAXIMIZED
)
1839 HWND hMaxChild
= ci
->hwndChildMaximized
;
1841 if( hMaxChild
== hwnd
) break;
1844 SendMessageW( hMaxChild
, WM_SETREDRAW
, FALSE
, 0 );
1845 MDI_RestoreFrameMenu( GetParent(client
), hMaxChild
);
1846 ShowWindow( hMaxChild
, SW_SHOWNOACTIVATE
);
1847 SendMessageW( hMaxChild
, WM_SETREDRAW
, TRUE
, 0 );
1849 TRACE("maximizing child %p\n", hwnd
);
1851 /* keep track of the maximized window. */
1852 ci
->hwndChildMaximized
= hwnd
; /* !!! */
1854 /* The maximized window should also be the active window */
1855 MDI_ChildActivate( client
, hwnd
);
1856 MDI_AugmentFrameMenu( GetParent(client
), hwnd
);
1857 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1860 if( wParam
== SIZE_MINIMIZED
)
1862 HWND switchTo
= MDI_GetWindow(ci
, hwnd
, TRUE
, WS_MINIMIZE
);
1864 if (switchTo
) SendMessageW( switchTo
, WM_CHILDACTIVATE
, 0, 0);
1866 MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1873 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1874 HWND parent
= GetParent(client
);
1876 if( wParam
== VK_LEFT
) /* switch to frame system menu */
1878 WND
*wndPtr
= WIN_GetPtr( parent
);
1879 next_menu
->hmenuNext
= GetSubMenu( wndPtr
->hSysMenu
, 0 );
1880 WIN_ReleasePtr( wndPtr
);
1882 if( wParam
== VK_RIGHT
) /* to frame menu bar */
1884 next_menu
->hmenuNext
= GetMenu(parent
);
1886 next_menu
->hwndNext
= parent
;
1894 SendMessageW( hwnd
, WM_SYSCOMMAND
, (WPARAM
)SC_KEYMENU
, (DWORD
)VK_SPACE
);
1899 return DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1902 /**********************************************************************
1903 * CreateMDIWindowA (USER32.@) Creates a MDI child
1906 * Success: Handle to created window
1909 HWND WINAPI
CreateMDIWindowA(
1910 LPCSTR lpClassName
, /* [in] Pointer to registered child class name */
1911 LPCSTR lpWindowName
, /* [in] Pointer to window name */
1912 DWORD dwStyle
, /* [in] Window style */
1913 INT X
, /* [in] Horizontal position of window */
1914 INT Y
, /* [in] Vertical position of window */
1915 INT nWidth
, /* [in] Width of window */
1916 INT nHeight
, /* [in] Height of window */
1917 HWND hWndParent
, /* [in] Handle to parent window */
1918 HINSTANCE hInstance
, /* [in] Handle to application instance */
1919 LPARAM lParam
) /* [in] Application-defined value */
1921 MDICLIENTINFO
*pCi
= get_client_info( hWndParent
);
1922 MDICREATESTRUCTA cs
;
1924 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%p,%p,%ld)\n",
1925 debugstr_a(lpClassName
),debugstr_a(lpWindowName
),dwStyle
,X
,Y
,
1926 nWidth
,nHeight
,hWndParent
,hInstance
,lParam
);
1930 ERR("bad hwnd for MDI-client: %p\n", hWndParent
);
1933 cs
.szClass
=lpClassName
;
1934 cs
.szTitle
=lpWindowName
;
1935 cs
.hOwner
=hInstance
;
1943 return MDICreateChild(hWndParent
, pCi
, &cs
, FALSE
);
1946 /***********************************************************************
1947 * CreateMDIWindowW (USER32.@) Creates a MDI child
1950 * Success: Handle to created window
1953 HWND WINAPI
CreateMDIWindowW(
1954 LPCWSTR lpClassName
, /* [in] Pointer to registered child class name */
1955 LPCWSTR lpWindowName
, /* [in] Pointer to window name */
1956 DWORD dwStyle
, /* [in] Window style */
1957 INT X
, /* [in] Horizontal position of window */
1958 INT Y
, /* [in] Vertical position of window */
1959 INT nWidth
, /* [in] Width of window */
1960 INT nHeight
, /* [in] Height of window */
1961 HWND hWndParent
, /* [in] Handle to parent window */
1962 HINSTANCE hInstance
, /* [in] Handle to application instance */
1963 LPARAM lParam
) /* [in] Application-defined value */
1965 MDICLIENTINFO
*pCi
= get_client_info( hWndParent
);
1966 MDICREATESTRUCTW cs
;
1968 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%p,%p,%ld)\n",
1969 debugstr_w(lpClassName
), debugstr_w(lpWindowName
), dwStyle
, X
, Y
,
1970 nWidth
, nHeight
, hWndParent
, hInstance
, lParam
);
1974 ERR("bad hwnd for MDI-client: %p\n", hWndParent
);
1977 cs
.szClass
= lpClassName
;
1978 cs
.szTitle
= lpWindowName
;
1979 cs
.hOwner
= hInstance
;
1987 return MDICreateChild(hWndParent
, pCi
, (MDICREATESTRUCTA
*)&cs
, TRUE
);
1990 /**********************************************************************
1991 * TranslateMDISysAccel (USER32.@)
1993 BOOL WINAPI
TranslateMDISysAccel( HWND hwndClient
, LPMSG msg
)
1995 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
)
1997 MDICLIENTINFO
*ci
= get_client_info( hwndClient
);
2000 if (!ci
|| !IsWindowEnabled(ci
->hwndActiveChild
)) return 0;
2002 /* translate if the Ctrl key is down and Alt not. */
2004 if( (GetKeyState(VK_CONTROL
) & 0x8000) && !(GetKeyState(VK_MENU
) & 0x8000))
2006 switch( msg
->wParam
)
2010 wParam
= ( GetKeyState(VK_SHIFT
) & 0x8000 ) ? SC_NEXTWINDOW
: SC_PREVWINDOW
;
2019 TRACE("wParam = %04x\n", wParam
);
2020 SendMessageW(ci
->hwndActiveChild
, WM_SYSCOMMAND
, wParam
, (LPARAM
)msg
->wParam
);
2024 return 0; /* failure */
2027 /***********************************************************************
2028 * CalcChildScroll (USER32.@)
2030 void WINAPI
CalcChildScroll( HWND hwnd
, INT scroll
)
2033 RECT childRect
, clientRect
;
2040 GetClientRect( hwnd
, &clientRect
);
2041 SetRectEmpty( &childRect
);
2044 if ((list
= WIN_ListChildren( hwnd
)))
2047 for (i
= 0; list
[i
]; i
++)
2049 DWORD style
= GetWindowLongW( list
[i
], GWL_STYLE
);
2050 if (style
& WS_MAXIMIZE
)
2052 HeapFree( GetProcessHeap(), 0, list
);
2053 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
2056 if (style
& WS_VISIBLE
)
2058 WND
*pWnd
= WIN_FindWndPtr( list
[i
] );
2059 UnionRect( &childRect
, &pWnd
->rectWindow
, &childRect
);
2060 WIN_ReleaseWndPtr( pWnd
);
2063 HeapFree( GetProcessHeap(), 0, list
);
2066 hWndCurrent
= GetWindow(hwnd
, GW_CHILD
);
2067 while (hWndCurrent
!= NULL
)
2069 DWORD style
= GetWindowLongW( hWndCurrent
, GWL_STYLE
);
2070 if (style
& WS_MAXIMIZE
)
2072 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
2075 if (style
& WS_VISIBLE
)
2079 GetWindowRect( hWndCurrent
, &WindowRect
);
2080 UnionRect( &childRect
, &WindowRect
, &childRect
);
2082 hWndCurrent
= GetWindow(hWndCurrent
, GW_HWNDNEXT
);
2085 UnionRect( &childRect
, &clientRect
, &childRect
);
2087 /* set common info values */
2088 info
.cbSize
= sizeof(info
);
2089 info
.fMask
= SIF_POS
| SIF_RANGE
;
2091 /* set the specific */
2096 info
.nMin
= childRect
.left
;
2097 info
.nMax
= childRect
.right
- clientRect
.right
;
2098 info
.nPos
= clientRect
.left
- childRect
.left
;
2099 SetScrollInfo(hwnd
, SB_HORZ
, &info
, TRUE
);
2100 if (scroll
== SB_HORZ
) break;
2103 info
.nMin
= childRect
.top
;
2104 info
.nMax
= childRect
.bottom
- clientRect
.bottom
;
2105 info
.nPos
= clientRect
.top
- childRect
.top
;
2106 SetScrollInfo(hwnd
, SB_VERT
, &info
, TRUE
);
2112 /***********************************************************************
2113 * ScrollChildren (USER32.@)
2115 void WINAPI
ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
,
2119 INT curPos
, length
, minPos
, maxPos
, shift
;
2122 GetClientRect( hWnd
, &rect
);
2127 GetScrollRange(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
2128 curPos
= GetScrollPos(hWnd
,SB_HORZ
);
2129 length
= (rect
.right
- rect
.left
) / 2;
2130 shift
= GetSystemMetrics(SM_CYHSCROLL
);
2133 GetScrollRange(hWnd
,SB_VERT
,&minPos
,&maxPos
);
2134 curPos
= GetScrollPos(hWnd
,SB_VERT
);
2135 length
= (rect
.bottom
- rect
.top
) / 2;
2136 shift
= GetSystemMetrics(SM_CXVSCROLL
);
2145 newPos
= curPos
- shift
;
2148 newPos
= curPos
+ shift
;
2151 newPos
= curPos
- length
;
2154 newPos
= curPos
+ length
;
2157 case SB_THUMBPOSITION
:
2158 newPos
= LOWORD(lParam
);
2171 CalcChildScroll(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
2175 if( newPos
> maxPos
)
2178 if( newPos
< minPos
)
2181 SetScrollPos(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
2183 if( uMsg
== WM_VSCROLL
)
2184 ScrollWindowEx(hWnd
,0 ,curPos
- newPos
, NULL
, NULL
, 0, NULL
,
2185 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
2187 ScrollWindowEx(hWnd
,curPos
- newPos
, 0, NULL
, NULL
, 0, NULL
,
2188 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
2192 /******************************************************************************
2193 * CascadeWindows (USER32.@) Cascades MDI child windows
2196 * Success: Number of cascaded windows.
2200 CascadeWindows (HWND hwndParent
, UINT wFlags
, LPCRECT lpRect
,
2201 UINT cKids
, const HWND
*lpKids
)
2203 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
2208 /******************************************************************************
2209 * TileWindows (USER32.@) Tiles MDI child windows
2212 * Success: Number of tiled windows.
2216 TileWindows (HWND hwndParent
, UINT wFlags
, LPCRECT lpRect
,
2217 UINT cKids
, const HWND
*lpKids
)
2219 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
2223 /************************************************************************
2224 * "More Windows..." functionality
2227 /* MDI_MoreWindowsDlgProc
2229 * This function will process the messages sent to the "More Windows..."
2231 * Return values: 0 = cancel pressed
2232 * HWND = ok pressed or double-click in the list...
2236 static INT_PTR WINAPI
MDI_MoreWindowsDlgProc (HWND hDlg
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
2249 MDICLIENTINFO
*ci
= get_client_info( (HWND
)lParam
);
2250 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2251 HWND
*list
, *sorted_list
;
2253 if (!(list
= WIN_ListChildren( (HWND
)lParam
))) return TRUE
;
2254 if (!(sorted_list
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
2255 sizeof(HWND
) * ci
->nActiveChildren
)))
2257 HeapFree( GetProcessHeap(), 0, list
);
2261 /* Fill the list, sorted by id... */
2262 for (i
= 0; list
[i
]; i
++)
2264 UINT id
= GetWindowLongW( list
[i
], GWL_ID
) - ci
->idFirstChild
;
2265 if (id
< ci
->nActiveChildren
) sorted_list
[id
] = list
[i
];
2267 HeapFree( GetProcessHeap(), 0, list
);
2269 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
2273 if (!GetWindowTextW( sorted_list
[i
], buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
2275 SendMessageW(hListBox
, LB_ADDSTRING
, 0, (LPARAM
)buffer
);
2276 SendMessageW(hListBox
, LB_SETITEMDATA
, i
, (LPARAM
)sorted_list
[i
] );
2277 length
= strlenW(buffer
); /* FIXME: should use GetTextExtentPoint */
2278 if (length
> widest
)
2281 /* Make sure the horizontal scrollbar scrolls ok */
2282 SendMessageW(hListBox
, LB_SETHORIZONTALEXTENT
, widest
* 6, 0);
2284 /* Set the current selection */
2285 SendMessageW(hListBox
, LB_SETCURSEL
, MDI_MOREWINDOWSLIMIT
, 0);
2291 switch (LOWORD(wParam
))
2294 if (HIWORD(wParam
) != LBN_DBLCLK
) break;
2298 /* windows are sorted by menu ID, so we must return the
2299 * window associated to the given id
2301 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2302 UINT index
= SendMessageW(hListBox
, LB_GETCURSEL
, 0, 0);
2303 LRESULT res
= SendMessageW(hListBox
, LB_GETITEMDATA
, index
, 0);
2304 EndDialog(hDlg
, res
);
2318 * MDI_MoreWindowsDialog
2320 * Prompts the user with a listbox containing the opened
2321 * documents. The user can then choose a windows and click
2322 * on OK to set the current window to the one selected, or
2323 * CANCEL to cancel. The function returns a handle to the
2327 static HWND
MDI_MoreWindowsDialog(HWND hwnd
)
2333 hRes
= FindResourceA(GetModuleHandleA("USER32"), "MDI_MOREWINDOWS", (LPSTR
)RT_DIALOG
);
2338 hDlgTmpl
= LoadResource(GetModuleHandleA("USER32"), hRes
);
2343 template = LockResource( hDlgTmpl
);
2348 return (HWND
) DialogBoxIndirectParamA(GetModuleHandleA("USER32"),
2349 (LPDLGTEMPLATE
) template,
2350 hwnd
, MDI_MoreWindowsDlgProc
, (LPARAM
) hwnd
);
2357 * Will swap the menu IDs for the given 2 positions.
2358 * pos1 and pos2 are menu IDs
2363 static void MDI_SwapMenuItems(HWND parent
, UINT pos1
, UINT pos2
)
2370 if (!(list
= WIN_ListChildren( parent
))) return;
2371 for (i
= 0; list
[i
]; i
++)
2373 UINT id
= GetWindowLongW( list
[i
], GWL_ID
);
2374 if (id
== pos1
) SetWindowLongW( list
[i
], GWL_ID
, pos2
);
2375 else if (id
== pos2
) SetWindowLongW( list
[i
], GWL_ID
, pos1
);
2377 HeapFree( GetProcessHeap(), 0, list
);