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.
92 #include "wine/unicode.h"
94 #include "nonclient.h"
98 #include "wine/debug.h"
101 WINE_DEFAULT_DEBUG_CHANNEL(mdi
);
103 #define MDI_MAXLISTLENGTH 0x40
104 #define MDI_MAXTITLELENGTH 0xa1
106 #define MDI_NOFRAMEREPAINT 0
107 #define MDI_REPAINTFRAMENOW 1
108 #define MDI_REPAINTFRAME 2
110 #define WM_MDICALCCHILDSCROLL 0x10ac /* this is exactly what Windows uses */
112 /* "More Windows..." definitions */
113 #define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
114 option will appear under the Windows menu */
115 #define MDI_IDC_LISTBOX 100
116 #define MDI_IDS_MOREWINDOWS 13
118 #define MDIF_NEEDUPDATE 0x0001
122 UINT nActiveChildren
;
123 HWND hwndChildMaximized
;
124 HWND hwndActiveChild
;
130 UINT sbRecalc
; /* SB_xxx flags for scrollbar fixup */
133 static HBITMAP hBmpClose
= 0;
135 /* ----------------- declarations ----------------- */
136 static void MDI_UpdateFrameText( HWND
, HWND
, BOOL
, LPCWSTR
);
137 static BOOL
MDI_AugmentFrameMenu( HWND
, HWND
);
138 static BOOL
MDI_RestoreFrameMenu( HWND
, HWND
);
139 static LONG
MDI_ChildActivate( HWND
, HWND
);
141 static HWND
MDI_MoreWindowsDialog(HWND
);
142 static void MDI_SwapMenuItems(HWND
, UINT
, UINT
);
143 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
144 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
146 /* -------- Miscellaneous service functions ----------
150 static HWND
MDI_GetChildByID(HWND hwnd
, UINT id
)
156 if (!(win_array
= WIN_ListChildren( hwnd
))) return 0;
157 for (i
= 0; win_array
[i
]; i
++)
159 if (GetWindowLongA( win_array
[i
], GWL_ID
) == id
) break;
162 HeapFree( GetProcessHeap(), 0, win_array
);
166 static void MDI_PostUpdate(HWND hwnd
, MDICLIENTINFO
* ci
, WORD recalc
)
168 if( !(ci
->mdiFlags
& MDIF_NEEDUPDATE
) )
170 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
171 PostMessageA( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0);
173 ci
->sbRecalc
= recalc
;
177 /*********************************************************************
178 * MDIClient class descriptor
180 const struct builtin_class_descr MDICLIENT_builtin_class
=
182 "MDIClient", /* name */
183 CS_GLOBALCLASS
, /* style */
184 MDIClientWndProcA
, /* procA */
185 MDIClientWndProcW
, /* procW */
186 sizeof(MDICLIENTINFO
), /* extra */
187 IDC_ARROWA
, /* cursor */
188 COLOR_APPWORKSPACE
+1 /* brush */
192 static MDICLIENTINFO
*get_client_info( HWND client
)
194 MDICLIENTINFO
*ret
= NULL
;
195 WND
*win
= WIN_GetPtr( client
);
198 if (win
== WND_OTHER_PROCESS
)
200 ERR( "client %x belongs to other process\n", client
);
203 if (win
->cbWndExtra
< sizeof(MDICLIENTINFO
)) WARN( "%x is not an MDI client\n", client
);
204 else ret
= (MDICLIENTINFO
*)win
->wExtra
;
205 WIN_ReleasePtr( win
);
210 /**********************************************************************
213 static void MDI_MenuModifyItem( HWND client
, HWND hWndChild
)
215 MDICLIENTINFO
*clientInfo
= get_client_info( client
);
219 if (!clientInfo
|| !clientInfo
->hWindowMenu
) return;
221 id
= GetWindowLongA( hWndChild
, GWL_ID
);
222 if (id
>= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
) return;
224 buffer
[1] = '1' + id
- clientInfo
->idFirstChild
;
226 GetWindowTextW( hWndChild
, buffer
+ 3, sizeof(buffer
)/sizeof(WCHAR
) - 3 );
228 n
= GetMenuState(clientInfo
->hWindowMenu
, id
, MF_BYCOMMAND
);
229 ModifyMenuW(clientInfo
->hWindowMenu
, id
, MF_BYCOMMAND
| MF_STRING
, id
, buffer
);
230 CheckMenuItem(clientInfo
->hWindowMenu
, id
, n
& MF_CHECKED
);
233 /**********************************************************************
236 static BOOL
MDI_MenuDeleteItem( HWND client
, HWND hWndChild
)
239 static const WCHAR format
[] = {'&','%','d',' ',0};
240 MDICLIENTINFO
*clientInfo
= get_client_info( client
);
243 if( !clientInfo
->nActiveChildren
|| !clientInfo
->hWindowMenu
)
246 id
= GetWindowLongA( hWndChild
, GWL_ID
);
247 DeleteMenu(clientInfo
->hWindowMenu
,id
,MF_BYCOMMAND
);
249 /* walk the rest of MDI children to prevent gaps in the id
250 * sequence and in the menu child list */
252 for( index
= id
+1; index
<= clientInfo
->nActiveChildren
+
253 clientInfo
->idFirstChild
; index
++ )
255 HWND hwnd
= MDI_GetChildByID(client
,index
);
258 TRACE("no window for id=%i\n",index
);
263 SetWindowLongW( hwnd
, GWL_ID
, GetWindowLongW( hwnd
, GWL_ID
) - 1 );
265 n
= wsprintfW(buffer
, format
,index
- clientInfo
->idFirstChild
);
266 GetWindowTextW( hwnd
, buffer
+ n
, sizeof(buffer
)/sizeof(WCHAR
) - n
);
268 /* change menu if the current child is to be shown in the
271 if (index
<= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
)
272 ModifyMenuW(clientInfo
->hWindowMenu
,index
,MF_BYCOMMAND
| MF_STRING
,
273 index
- 1 , buffer
);
276 /* We must restore the "More Windows..." option if there are enough children
278 if (clientInfo
->nActiveChildren
- 1 > MDI_MOREWINDOWSLIMIT
)
281 LoadStringW(GetModuleHandleA("USER32"), MDI_IDS_MOREWINDOWS
, szTmp
, sizeof(szTmp
)/sizeof(szTmp
[0]));
282 AppendMenuW(clientInfo
->hWindowMenu
, MF_STRING
, clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
, szTmp
);
287 /**********************************************************************
290 * returns "activateable" child different from the current or zero
292 static HWND
MDI_GetWindow(MDICLIENTINFO
*clientInfo
, HWND hWnd
, BOOL bNext
,
299 dwStyleMask
|= WS_DISABLED
| WS_VISIBLE
;
300 if( !hWnd
) hWnd
= clientInfo
->hwndActiveChild
;
302 if (!(list
= WIN_ListChildren( GetParent(hWnd
) ))) return 0;
304 /* start from next after hWnd */
305 while (list
[i
] && list
[i
] != hWnd
) i
++;
308 for ( ; list
[i
]; i
++)
310 if (GetWindow( list
[i
], GW_OWNER
)) continue;
311 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
313 if (bNext
) goto found
;
315 /* now restart from the beginning */
316 for (i
= 0; list
[i
] && list
[i
] != hWnd
; i
++)
318 if (GetWindow( list
[i
], GW_OWNER
)) continue;
319 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
321 if (bNext
) goto found
;
324 HeapFree( GetProcessHeap(), 0, list
);
328 /**********************************************************************
329 * MDI_CalcDefaultChildPos
331 * It seems that the default height is about 2/3 of the client rect
333 static void MDI_CalcDefaultChildPos( HWND hwnd
, WORD n
, LPPOINT lpPos
, INT delta
)
337 INT spacing
= GetSystemMetrics(SM_CYCAPTION
) +
338 GetSystemMetrics(SM_CYFRAME
) - 1;
340 GetClientRect( hwnd
, &rect
);
341 if( rect
.bottom
- rect
.top
- delta
>= spacing
)
342 rect
.bottom
-= delta
;
344 nstagger
= (rect
.bottom
- rect
.top
)/(3 * spacing
);
345 lpPos
[1].x
= (rect
.right
- rect
.left
- nstagger
* spacing
);
346 lpPos
[1].y
= (rect
.bottom
- rect
.top
- nstagger
* spacing
);
347 lpPos
[0].x
= lpPos
[0].y
= spacing
* (n
%(nstagger
+1));
350 /**********************************************************************
353 static LRESULT
MDISetMenu( HWND hwnd
, HMENU hmenuFrame
,
357 HWND hwndFrame
= GetParent(hwnd
);
358 HMENU oldFrameMenu
= GetMenu(hwndFrame
);
360 TRACE("%04x %04x %04x\n",
361 hwnd
, hmenuFrame
, hmenuWindow
);
363 if (hmenuFrame
&& !IsMenu(hmenuFrame
))
365 WARN("hmenuFrame is not a menu handle\n");
369 if (hmenuWindow
&& !IsMenu(hmenuWindow
))
371 WARN("hmenuWindow is not a menu handle\n");
375 if (!(ci
= get_client_info( hwnd
))) return 0;
377 if( ci
->hwndChildMaximized
&& hmenuFrame
&& hmenuFrame
!=oldFrameMenu
)
378 MDI_RestoreFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
380 if( hmenuWindow
&& ci
->hWindowMenu
&& hmenuWindow
!=ci
->hWindowMenu
)
382 /* delete menu items from ci->hWindowMenu
383 * and add them to hmenuWindow */
385 INT i
= GetMenuItemCount(ci
->hWindowMenu
) - 1;
386 INT pos
= GetMenuItemCount(hmenuWindow
) + 1;
388 AppendMenuA( hmenuWindow
, MF_SEPARATOR
, 0, NULL
);
390 if( ci
->nActiveChildren
)
393 LPWSTR buffer
= NULL
;
395 INT nbWindowsMenuItems
; /* num of documents shown + "More Windows..." if present */
397 if (ci
->nActiveChildren
<= MDI_MOREWINDOWSLIMIT
)
398 nbWindowsMenuItems
= ci
->nActiveChildren
;
400 nbWindowsMenuItems
= MDI_MOREWINDOWSLIMIT
+ 1;
402 j
= i
- nbWindowsMenuItems
+ 1;
404 for( ; i
>= j
; i
-- )
406 memset(&mii
, 0, sizeof(mii
));
407 mii
.cbSize
= sizeof(mii
);
408 mii
.fMask
= MIIM_CHECKMARKS
| MIIM_DATA
| MIIM_ID
| MIIM_STATE
409 | MIIM_SUBMENU
| MIIM_TYPE
| MIIM_BITMAP
;
411 GetMenuItemInfoW(ci
->hWindowMenu
, i
, TRUE
, &mii
);
412 if(mii
.cch
) { /* Menu is MFT_STRING */
413 mii
.cch
++; /* add room for '\0' */
414 buffer
= HeapAlloc(GetProcessHeap(), 0,
415 mii
.cch
* sizeof(WCHAR
));
416 mii
.dwTypeData
= buffer
;
417 GetMenuItemInfoW(ci
->hWindowMenu
, i
, TRUE
, &mii
);
419 DeleteMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
420 InsertMenuItemW(hmenuWindow
, pos
, TRUE
, &mii
);
422 HeapFree(GetProcessHeap(), 0, buffer
);
428 /* remove separator */
429 DeleteMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
431 ci
->hWindowMenu
= hmenuWindow
;
436 SetMenu(hwndFrame
, hmenuFrame
);
437 if( hmenuFrame
!=oldFrameMenu
)
439 if( ci
->hwndChildMaximized
)
440 MDI_AugmentFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
446 HMENU menu
= GetMenu( GetParent(hwnd
) );
447 INT nItems
= GetMenuItemCount(menu
) - 1;
448 UINT iId
= GetMenuItemID(menu
,nItems
) ;
450 if( !(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
452 /* SetMenu() may already have been called, meaning that this window
453 * already has its menu. But they may have done a SetMenu() on
454 * an MDI window, and called MDISetMenu() after the fact, meaning
455 * that the "if" to this "else" wouldn't catch the need to
456 * augment the frame menu.
458 if( ci
->hwndChildMaximized
)
459 MDI_AugmentFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
465 /**********************************************************************
468 static LRESULT
MDIRefreshMenu( HWND hwnd
, HMENU hmenuFrame
,
471 HWND hwndFrame
= GetParent(hwnd
);
472 HMENU oldFrameMenu
= GetMenu(hwndFrame
);
474 TRACE("%04x %04x %04x\n",
475 hwnd
, hmenuFrame
, hmenuWindow
);
477 FIXME("partially function stub\n");
483 /* ------------------ MDI child window functions ---------------------- */
486 /**********************************************************************
489 static HWND
MDICreateChild( HWND parent
, MDICLIENTINFO
*ci
,
490 LPMDICREATESTRUCTA cs
, BOOL unicode
)
493 DWORD style
= cs
->style
| (WS_CHILD
| WS_CLIPSIBLINGS
);
494 HWND hwnd
, hwndMax
= 0;
495 UINT wIDmenu
= ci
->idFirstChild
+ ci
->nActiveChildren
;
497 static const WCHAR lpstrDef
[] = {'j','u','n','k','!',0};
499 TRACE("origin %i,%i - dim %i,%i, style %08lx\n",
500 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, cs
->style
);
501 /* calculate placement */
502 MDI_CalcDefaultChildPos(parent
, ci
->nTotalCreated
++, pos
, 0);
504 if (cs
->cx
== CW_USEDEFAULT
|| cs
->cx
== CW_USEDEFAULT16
|| !cs
->cx
) cs
->cx
= pos
[1].x
;
505 if (cs
->cy
== CW_USEDEFAULT
|| cs
->cy
== CW_USEDEFAULT16
|| !cs
->cy
) cs
->cy
= pos
[1].y
;
507 if (cs
->x
== CW_USEDEFAULT
|| cs
->x
== CW_USEDEFAULT16
)
513 /* restore current maximized child */
514 if( (style
& WS_VISIBLE
) && ci
->hwndChildMaximized
)
516 TRACE("Restoring current maximized child %04x\n", ci
->hwndChildMaximized
);
517 if( style
& WS_MAXIMIZE
)
518 SendMessageW(parent
, WM_SETREDRAW
, FALSE
, 0L);
519 hwndMax
= ci
->hwndChildMaximized
;
520 ShowWindow( hwndMax
, SW_SHOWNOACTIVATE
);
521 if( style
& WS_MAXIMIZE
)
522 SendMessageW(parent
, WM_SETREDRAW
, TRUE
, 0L);
525 if (ci
->nActiveChildren
<= MDI_MOREWINDOWSLIMIT
)
526 /* this menu is needed to set a check mark in MDI_ChildActivate */
527 if (ci
->hWindowMenu
!= 0)
528 AppendMenuW(ci
->hWindowMenu
, MF_STRING
, wIDmenu
, lpstrDef
);
530 ci
->nActiveChildren
++;
532 /* fix window style */
533 wndParent
= WIN_FindWndPtr( parent
);
534 if( !(wndParent
->dwStyle
& MDIS_ALLCHILDSTYLES
) )
536 TRACE("MDIS_ALLCHILDSTYLES is missing, fixing window style\n");
537 style
&= (WS_CHILD
| WS_CLIPSIBLINGS
| WS_MINIMIZE
| WS_MAXIMIZE
|
538 WS_CLIPCHILDREN
| WS_DISABLED
| WS_VSCROLL
| WS_HSCROLL
);
539 style
|= (WS_VISIBLE
| WS_OVERLAPPEDWINDOW
);
542 if( wndParent
->flags
& WIN_ISWIN32
)
544 WIN_ReleaseWndPtr( wndParent
);
547 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)cs
;
548 hwnd
= CreateWindowW( csW
->szClass
, csW
->szTitle
, style
,
549 csW
->x
, csW
->y
, csW
->cx
, csW
->cy
, parent
,
550 (HMENU
)wIDmenu
, csW
->hOwner
, csW
);
553 hwnd
= CreateWindowA( cs
->szClass
, cs
->szTitle
, style
,
554 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, parent
,
555 (HMENU
)wIDmenu
, cs
->hOwner
, cs
);
559 MDICREATESTRUCT16 cs16
;
560 SEGPTR title
, cls
, seg_cs16
;
562 WIN_ReleaseWndPtr( wndParent
);
563 STRUCT32_MDICREATESTRUCT32Ato16( cs
, &cs16
);
564 cs16
.szTitle
= title
= MapLS( cs
->szTitle
);
565 cs16
.szClass
= cls
= MapLS( cs
->szClass
);
566 seg_cs16
= MapLS( &cs16
);
567 hwnd
= WIN_Handle32( CreateWindow16( cs
->szClass
, cs
->szTitle
, style
,
568 cs16
.x
, cs16
.y
, cs16
.cx
, cs16
.cy
,
569 HWND_16(parent
), (HMENU
)wIDmenu
,
570 cs16
.hOwner
, (LPVOID
)seg_cs16
));
576 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
580 /* All MDI child windows have the WS_EX_MDICHILD style */
581 SetWindowLongW( hwnd
, GWL_EXSTYLE
, GetWindowLongW( hwnd
, GWL_EXSTYLE
) | WS_EX_MDICHILD
);
583 /* If we have more than 9 windows, we must insert the new one at the
584 * 9th position in order to see it in the "Windows" menu
586 if (ci
->nActiveChildren
> MDI_MOREWINDOWSLIMIT
)
587 MDI_SwapMenuItems( parent
, GetWindowLongW( hwnd
, GWL_ID
),
588 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1);
590 MDI_MenuModifyItem(parent
, hwnd
);
592 /* Have we hit the "More Windows..." limit? If so, we must
593 * add a "More Windows..." option
595 if (ci
->nActiveChildren
== MDI_MOREWINDOWSLIMIT
+ 1)
598 LoadStringW(GetModuleHandleA("USER32"), MDI_IDS_MOREWINDOWS
, szTmp
, sizeof(szTmp
)/sizeof(szTmp
[0]));
600 ModifyMenuW(ci
->hWindowMenu
,
601 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
,
602 MF_BYCOMMAND
| MF_STRING
,
603 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
,
607 if( IsIconic(hwnd
) && ci
->hwndActiveChild
)
609 TRACE("Minimizing created MDI child %04x\n", hwnd
);
610 ShowWindow( hwnd
, SW_SHOWMINNOACTIVE
);
614 /* WS_VISIBLE is clear if a) the MDI client has
615 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
616 * MDICreateStruct. If so the created window is not shown nor
619 if (IsWindowVisible(hwnd
)) ShowWindow(hwnd
, SW_SHOW
);
621 TRACE("created child - %04x\n",hwnd
);
625 ci
->nActiveChildren
--;
626 DeleteMenu(ci
->hWindowMenu
,wIDmenu
,MF_BYCOMMAND
);
627 if( IsWindow(hwndMax
) )
628 ShowWindow(hwndMax
, SW_SHOWMAXIMIZED
);
634 /**********************************************************************
635 * MDI_ChildGetMinMaxInfo
637 * Note: The rule here is that client rect of the maximized MDI child
638 * is equal to the client rect of the MDI client window.
640 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
644 GetClientRect( client
, &rect
);
645 AdjustWindowRectEx( &rect
, GetWindowLongW( hwnd
, GWL_STYLE
),
646 0, GetWindowLongW( hwnd
, GWL_EXSTYLE
));
648 lpMinMax
->ptMaxSize
.x
= rect
.right
-= rect
.left
;
649 lpMinMax
->ptMaxSize
.y
= rect
.bottom
-= rect
.top
;
651 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
652 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
654 TRACE("max rect (%i,%i - %i, %i)\n",
655 rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
658 /**********************************************************************
659 * MDI_SwitchActiveChild
661 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
664 static void MDI_SwitchActiveChild( HWND clientHwnd
, HWND childHwnd
,
669 MDICLIENTINFO
*ci
= get_client_info( clientHwnd
);
671 hwndTo
= MDI_GetWindow(ci
, childHwnd
, bNextWindow
, 0);
673 TRACE("from %04x, to %04x\n",childHwnd
,hwndTo
);
675 if ( !hwndTo
) return; /* no window to switch to */
677 hwndPrev
= ci
->hwndActiveChild
;
679 if ( hwndTo
!= hwndPrev
)
681 SetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0,
682 SWP_NOMOVE
| SWP_NOSIZE
);
684 if( bNextWindow
&& hwndPrev
)
685 SetWindowPos( hwndPrev
, HWND_BOTTOM
, 0, 0, 0, 0,
686 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
691 /**********************************************************************
694 static LRESULT
MDIDestroyChild( HWND parent
, MDICLIENTINFO
*ci
,
695 HWND child
, BOOL flagDestroy
)
697 if( child
== ci
->hwndActiveChild
)
699 MDI_SwitchActiveChild(parent
, child
, TRUE
);
701 if( child
== ci
->hwndActiveChild
)
703 ShowWindow( child
, SW_HIDE
);
704 if( child
== ci
->hwndChildMaximized
)
706 HWND frame
= GetParent(parent
);
707 MDI_RestoreFrameMenu( frame
, child
);
708 ci
->hwndChildMaximized
= 0;
709 MDI_UpdateFrameText( frame
, parent
, TRUE
, NULL
);
712 MDI_ChildActivate(parent
, 0);
716 MDI_MenuDeleteItem(parent
, child
);
718 ci
->nActiveChildren
--;
720 TRACE("child destroyed - %04x\n",child
);
724 MDI_PostUpdate(GetParent(child
), ci
, SB_BOTH
+1);
725 DestroyWindow(child
);
731 /**********************************************************************
734 * Note: hWndChild is NULL when last child is being destroyed
736 static LONG
MDI_ChildActivate( HWND client
, HWND child
)
738 MDICLIENTINFO
*clientInfo
= get_client_info( client
);
739 HWND prevActiveWnd
= clientInfo
->hwndActiveChild
;
740 BOOL isActiveFrameWnd
;
742 if (child
&& (!IsWindowEnabled( child
))) return 0;
744 /* Don't activate if it is already active. Might happen
745 since ShowWindow DOES activate MDI children */
746 if (clientInfo
->hwndActiveChild
== child
) return 0;
748 TRACE("%04x\n", child
);
750 isActiveFrameWnd
= (GetActiveWindow() == GetParent(client
));
752 /* deactivate prev. active child */
755 SetWindowLongA( prevActiveWnd
, GWL_STYLE
,
756 GetWindowLongA( prevActiveWnd
, GWL_STYLE
) | WS_SYSMENU
);
757 SendMessageA( prevActiveWnd
, WM_NCACTIVATE
, FALSE
, 0L );
758 SendMessageA( prevActiveWnd
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
759 /* uncheck menu item */
760 if( clientInfo
->hWindowMenu
)
762 UINT prevID
= GetWindowLongA( prevActiveWnd
, GWL_ID
);
764 if (prevID
- clientInfo
->idFirstChild
< MDI_MOREWINDOWSLIMIT
)
765 CheckMenuItem( clientInfo
->hWindowMenu
, prevID
, 0);
767 CheckMenuItem( clientInfo
->hWindowMenu
,
768 clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1, 0);
773 if (clientInfo
->hwndChildMaximized
&& clientInfo
->hwndChildMaximized
!= child
)
777 clientInfo
->hwndActiveChild
= child
;
778 ShowWindow( child
, SW_SHOWMAXIMIZED
);
780 else ShowWindow( clientInfo
->hwndActiveChild
, SW_SHOWNORMAL
);
783 clientInfo
->hwndActiveChild
= child
;
785 /* check if we have any children left */
788 if( isActiveFrameWnd
)
793 /* check menu item */
794 if( clientInfo
->hWindowMenu
)
796 UINT id
= GetWindowLongA( child
, GWL_ID
);
797 /* The window to be activated must be displayed in the "Windows" menu */
798 if (id
>= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
)
800 MDI_SwapMenuItems( GetParent(child
),
801 id
, clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1);
802 id
= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1;
803 MDI_MenuModifyItem( GetParent(child
), child
);
806 CheckMenuItem(clientInfo
->hWindowMenu
, id
, MF_CHECKED
);
808 /* bring active child to the top */
809 SetWindowPos( child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
811 if( isActiveFrameWnd
)
813 SendMessageA( child
, WM_NCACTIVATE
, TRUE
, 0L);
814 if( GetFocus() == client
)
815 SendMessageA( client
, WM_SETFOCUS
, (WPARAM
)client
, 0L );
819 SendMessageA( child
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
823 /* -------------------- MDI client window functions ------------------- */
825 /**********************************************************************
826 * CreateMDIMenuBitmap
828 static HBITMAP
CreateMDIMenuBitmap(void)
830 HDC hDCSrc
= CreateCompatibleDC(0);
831 HDC hDCDest
= CreateCompatibleDC(hDCSrc
);
832 HBITMAP hbClose
= LoadBitmapW(0, MAKEINTRESOURCEW(OBM_OLD_CLOSE
) );
834 HBITMAP hobjSrc
, hobjDest
;
836 hobjSrc
= SelectObject(hDCSrc
, hbClose
);
837 hbCopy
= CreateCompatibleBitmap(hDCSrc
,GetSystemMetrics(SM_CXSIZE
),GetSystemMetrics(SM_CYSIZE
));
838 hobjDest
= SelectObject(hDCDest
, hbCopy
);
840 BitBlt(hDCDest
, 0, 0, GetSystemMetrics(SM_CXSIZE
), GetSystemMetrics(SM_CYSIZE
),
841 hDCSrc
, GetSystemMetrics(SM_CXSIZE
), 0, SRCCOPY
);
843 SelectObject(hDCSrc
, hobjSrc
);
844 DeleteObject(hbClose
);
847 hobjSrc
= SelectObject( hDCDest
, GetStockObject(BLACK_PEN
) );
849 MoveToEx( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, 0, NULL
);
850 LineTo( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, GetSystemMetrics(SM_CYSIZE
) - 1);
852 SelectObject(hDCDest
, hobjSrc
);
853 SelectObject(hDCDest
, hobjDest
);
859 /**********************************************************************
862 static LONG
MDICascade( HWND client
, MDICLIENTINFO
*ci
)
865 BOOL has_icons
= FALSE
;
868 if (ci
->hwndChildMaximized
)
869 SendMessageA( client
, WM_MDIRESTORE
,
870 (WPARAM
)ci
->hwndChildMaximized
, 0);
872 if (ci
->nActiveChildren
== 0) return 0;
874 if (!(win_array
= WIN_ListChildren( client
))) return 0;
876 /* remove all the windows we don't want */
877 for (i
= total
= 0; win_array
[i
]; i
++)
879 if (!IsWindowVisible( win_array
[i
] )) continue;
880 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows */
881 if (IsIconic( win_array
[i
] ))
886 win_array
[total
++] = win_array
[i
];
888 win_array
[total
] = 0;
892 INT delta
= 0, n
= 0, i
;
894 if (has_icons
) delta
= GetSystemMetrics(SM_CYICONSPACING
) + GetSystemMetrics(SM_CYICON
);
896 /* walk the list (backwards) and move windows */
897 for (i
= total
- 1; i
>= 0; i
--)
899 TRACE("move %04x to (%ld,%ld) size [%ld,%ld]\n",
900 win_array
[i
], pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
);
902 MDI_CalcDefaultChildPos(client
, n
++, pos
, delta
);
903 SetWindowPos( win_array
[i
], 0, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
,
904 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
907 HeapFree( GetProcessHeap(), 0, win_array
);
909 if (has_icons
) ArrangeIconicWindows( client
);
913 /**********************************************************************
916 static void MDITile( HWND client
, MDICLIENTINFO
*ci
, WPARAM wParam
)
920 BOOL has_icons
= FALSE
;
922 if (ci
->hwndChildMaximized
)
923 SendMessageA( client
, WM_MDIRESTORE
, (WPARAM
)ci
->hwndChildMaximized
, 0);
925 if (ci
->nActiveChildren
== 0) return;
927 if (!(win_array
= WIN_ListChildren( client
))) return;
929 /* remove all the windows we don't want */
930 for (i
= total
= 0; win_array
[i
]; i
++)
932 if (!IsWindowVisible( win_array
[i
] )) continue;
933 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows (icon titles) */
934 if (IsIconic( win_array
[i
] ))
939 if ((wParam
& MDITILE_SKIPDISABLED
) && !IsWindowEnabled( win_array
[i
] )) continue;
940 win_array
[total
++] = win_array
[i
];
942 win_array
[total
] = 0;
944 TRACE("%u windows to tile\n", total
);
948 HWND
*pWnd
= win_array
;
950 int x
, y
, xsize
, ysize
;
951 int rows
, columns
, r
, c
, i
;
953 GetClientRect(client
,&rect
);
954 rows
= (int) sqrt((double)total
);
955 columns
= total
/ rows
;
957 if( wParam
& MDITILE_HORIZONTAL
) /* version >= 3.1 */
960 rows
= columns
; /* exchange r and c */
966 y
= rect
.bottom
- 2 * GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
967 rect
.bottom
= ( y
- GetSystemMetrics(SM_CYICON
) < rect
.top
)? rect
.bottom
: y
;
970 ysize
= rect
.bottom
/ rows
;
971 xsize
= rect
.right
/ columns
;
973 for (x
= i
= 0, c
= 1; c
<= columns
&& *pWnd
; c
++)
978 ysize
= rect
.bottom
/ rows
;
982 for (r
= 1; r
<= rows
&& *pWnd
; r
++, i
++)
984 SetWindowPos(*pWnd
, 0, x
, y
, xsize
, ysize
,
985 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
992 HeapFree( GetProcessHeap(), 0, win_array
);
993 if (has_icons
) ArrangeIconicWindows( client
);
996 /* ----------------------- Frame window ---------------------------- */
999 /**********************************************************************
1000 * MDI_AugmentFrameMenu
1002 static BOOL
MDI_AugmentFrameMenu( HWND frame
, HWND hChild
)
1004 HMENU menu
= GetMenu( frame
);
1005 WND
* child
= WIN_FindWndPtr(hChild
);
1006 HMENU hSysPopup
= 0;
1007 HBITMAP hSysMenuBitmap
= 0;
1009 TRACE("frame %04x,child %04x\n",frame
,hChild
);
1011 if( !menu
|| !child
->hSysMenu
)
1013 WIN_ReleaseWndPtr(child
);
1016 WIN_ReleaseWndPtr(child
);
1018 /* create a copy of sysmenu popup and insert it into frame menu bar */
1020 if (!(hSysPopup
= LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU")))
1023 AppendMenuA(menu
,MF_HELP
| MF_BITMAP
,
1024 SC_MINIMIZE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_MINIMIZE
) ;
1025 AppendMenuA(menu
,MF_HELP
| MF_BITMAP
,
1026 SC_RESTORE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_RESTORE
);
1028 /* In Win 95 look, the system menu is replaced by the child icon */
1030 if(TWEAK_WineLook
> WIN31_LOOK
)
1032 HICON hIcon
= (HICON
)GetClassLongA(hChild
, GCL_HICONSM
);
1034 hIcon
= (HICON
)GetClassLongA(hChild
, GCL_HICON
);
1038 HBITMAP hBitmap
, hOldBitmap
;
1040 HDC hdc
= GetDC(hChild
);
1045 cx
= GetSystemMetrics(SM_CXSMICON
);
1046 cy
= GetSystemMetrics(SM_CYSMICON
);
1047 hMemDC
= CreateCompatibleDC(hdc
);
1048 hBitmap
= CreateCompatibleBitmap(hdc
, cx
, cy
);
1049 hOldBitmap
= SelectObject(hMemDC
, hBitmap
);
1050 SetMapMode(hMemDC
, MM_TEXT
);
1051 hBrush
= CreateSolidBrush(GetSysColor(COLOR_MENU
));
1052 DrawIconEx(hMemDC
, 0, 0, hIcon
, cx
, cy
, 0, hBrush
, DI_NORMAL
);
1053 SelectObject (hMemDC
, hOldBitmap
);
1054 DeleteObject(hBrush
);
1056 ReleaseDC(hChild
, hdc
);
1057 hSysMenuBitmap
= hBitmap
;
1062 hSysMenuBitmap
= hBmpClose
;
1064 if( !InsertMenuA(menu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
1065 hSysPopup
, (LPSTR
)(DWORD
)hSysMenuBitmap
))
1067 TRACE("not inserted\n");
1068 DestroyMenu(hSysPopup
);
1072 /* The close button is only present in Win 95 look */
1073 if(TWEAK_WineLook
> WIN31_LOOK
)
1075 AppendMenuA(menu
,MF_HELP
| MF_BITMAP
,
1076 SC_CLOSE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_CLOSE
);
1079 EnableMenuItem(hSysPopup
, SC_SIZE
, MF_BYCOMMAND
| MF_GRAYED
);
1080 EnableMenuItem(hSysPopup
, SC_MOVE
, MF_BYCOMMAND
| MF_GRAYED
);
1081 EnableMenuItem(hSysPopup
, SC_MAXIMIZE
, MF_BYCOMMAND
| MF_GRAYED
);
1082 SetMenuDefaultItem(hSysPopup
, SC_CLOSE
, FALSE
);
1090 /**********************************************************************
1091 * MDI_RestoreFrameMenu
1093 static BOOL
MDI_RestoreFrameMenu( HWND frame
, HWND hChild
)
1095 MENUITEMINFOW menuInfo
;
1096 HMENU menu
= GetMenu( frame
);
1097 INT nItems
= GetMenuItemCount(menu
) - 1;
1098 UINT iId
= GetMenuItemID(menu
,nItems
) ;
1100 TRACE("frame %04x,child %04x,nIt=%d,iId=%d\n",frame
,hChild
,nItems
,iId
);
1102 if(!(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
1106 * Remove the system menu, If that menu is the icon of the window
1107 * as it is in win95, we have to delete the bitmap.
1109 memset(&menuInfo
, 0, sizeof(menuInfo
));
1110 menuInfo
.cbSize
= sizeof(menuInfo
);
1111 menuInfo
.fMask
= MIIM_DATA
| MIIM_TYPE
;
1113 GetMenuItemInfoW(menu
,
1118 RemoveMenu(menu
,0,MF_BYPOSITION
);
1120 if ( (menuInfo
.fType
& MFT_BITMAP
) &&
1121 (LOWORD(menuInfo
.dwTypeData
)!=0) &&
1122 (LOWORD(menuInfo
.dwTypeData
)!=hBmpClose
) )
1124 DeleteObject((HBITMAP
)LOWORD(menuInfo
.dwTypeData
));
1127 if(TWEAK_WineLook
> WIN31_LOOK
)
1130 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
1133 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
1135 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
1143 /**********************************************************************
1144 * MDI_UpdateFrameText
1146 * used when child window is maximized/restored
1148 * Note: lpTitle can be NULL
1150 static void MDI_UpdateFrameText( HWND frame
, HWND hClient
,
1151 BOOL repaint
, LPCWSTR lpTitle
)
1153 WCHAR lpBuffer
[MDI_MAXTITLELENGTH
+1];
1154 MDICLIENTINFO
*ci
= get_client_info( hClient
);
1156 TRACE("repaint %i, frameText %s\n", repaint
, debugstr_w(lpTitle
));
1160 if (!lpTitle
&& !ci
->frameTitle
) /* first time around, get title from the frame window */
1162 GetWindowTextW( frame
, lpBuffer
, sizeof(lpBuffer
)/sizeof(WCHAR
) );
1166 /* store new "default" title if lpTitle is not NULL */
1169 if (ci
->frameTitle
) HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1170 if ((ci
->frameTitle
= HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle
)+1)*sizeof(WCHAR
))))
1171 strcpyW( ci
->frameTitle
, lpTitle
);
1176 if (ci
->hwndChildMaximized
)
1178 /* combine frame title and child title if possible */
1180 static const WCHAR lpBracket
[] = {' ','-',' ','[',0};
1181 static const WCHAR lpBracket2
[] = {']',0};
1182 int i_frame_text_length
= strlenW(ci
->frameTitle
);
1184 lstrcpynW( lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
1186 if( i_frame_text_length
+ 6 < MDI_MAXTITLELENGTH
)
1188 strcatW( lpBuffer
, lpBracket
);
1189 if (GetWindowTextW( ci
->hwndChildMaximized
, lpBuffer
+ i_frame_text_length
+ 4,
1190 MDI_MAXTITLELENGTH
- i_frame_text_length
- 5 ))
1191 strcatW( lpBuffer
, lpBracket2
);
1193 lpBuffer
[i_frame_text_length
] = 0; /* remove bracket */
1198 lstrcpynW(lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
+1 );
1204 DefWindowProcW( frame
, WM_SETTEXT
, 0, (LPARAM
)lpBuffer
);
1205 if( repaint
== MDI_REPAINTFRAME
)
1206 SetWindowPos( frame
, 0,0,0,0,0, SWP_FRAMECHANGED
|
1207 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
1211 /* ----------------------------- Interface ---------------------------- */
1214 /**********************************************************************
1215 * MDIClientWndProc_common
1217 static LRESULT
MDIClientWndProc_common( HWND hwnd
, UINT message
,
1218 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1222 if (!(ci
= get_client_info( hwnd
))) return 0;
1229 /* Since we are using only cs->lpCreateParams, we can safely
1230 * cast to LPCREATESTRUCTA here */
1231 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
1232 WND
*wndPtr
= WIN_GetPtr( hwnd
);
1234 /* Translation layer doesn't know what's in the cs->lpCreateParams
1235 * so we have to keep track of what environment we're in. */
1237 if( wndPtr
->flags
& WIN_ISWIN32
)
1239 #define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1240 ci
->hWindowMenu
= ccs
->hWindowMenu
;
1241 ci
->idFirstChild
= ccs
->idFirstChild
;
1246 LPCLIENTCREATESTRUCT16 ccs
= MapSL((SEGPTR
)cs
->lpCreateParams
);
1247 ci
->hWindowMenu
= ccs
->hWindowMenu
;
1248 ci
->idFirstChild
= ccs
->idFirstChild
;
1250 WIN_ReleasePtr( wndPtr
);
1252 ci
->hwndChildMaximized
= 0;
1253 ci
->nActiveChildren
= 0;
1254 ci
->nTotalCreated
= 0;
1255 ci
->frameTitle
= NULL
;
1257 SetWindowLongW( hwnd
, GWL_STYLE
, GetWindowLongW(hwnd
,GWL_STYLE
) | WS_CLIPCHILDREN
);
1259 if (!hBmpClose
) hBmpClose
= CreateMDIMenuBitmap();
1261 if (ci
->hWindowMenu
!= 0)
1262 AppendMenuW( ci
->hWindowMenu
, MF_SEPARATOR
, 0, NULL
);
1264 GetClientRect( GetParent(hwnd
), &rect
);
1265 MoveWindow( hwnd
, 0, 0, rect
.right
, rect
.bottom
, FALSE
);
1267 MDI_UpdateFrameText( GetParent(hwnd
), hwnd
, MDI_NOFRAMEREPAINT
, NULL
);
1269 TRACE("Client created - hwnd = %04x, idFirst = %u\n",
1270 hwnd
, ci
->idFirstChild
);
1277 if( ci
->hwndChildMaximized
)
1278 MDI_RestoreFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
1279 if((ci
->hWindowMenu
!= 0) &&
1280 (nItems
= GetMenuItemCount(ci
->hWindowMenu
)) > 0)
1282 ci
->idFirstChild
= nItems
- 1;
1283 ci
->nActiveChildren
++; /* to delete a separator */
1284 while( ci
->nActiveChildren
-- )
1285 DeleteMenu(ci
->hWindowMenu
,MF_BYPOSITION
,ci
->idFirstChild
--);
1287 if (ci
->frameTitle
) HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1291 case WM_MDIACTIVATE
:
1292 if( ci
->hwndActiveChild
!= (HWND
)wParam
)
1293 SetWindowPos((HWND
)wParam
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1297 return MDICascade(hwnd
, ci
);
1301 return (LRESULT
)MDICreateChild( hwnd
, ci
, (MDICREATESTRUCTA
*)lParam
, unicode
);
1305 return MDIDestroyChild( hwnd
, ci
, WIN_GetFullHandle( (HWND
)wParam
), TRUE
);
1307 case WM_MDIGETACTIVE
:
1308 if (lParam
) *(BOOL
*)lParam
= (ci
->hwndChildMaximized
!= 0);
1309 return (LRESULT
)ci
->hwndActiveChild
;
1311 case WM_MDIICONARRANGE
:
1312 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1313 ArrangeIconicWindows( hwnd
);
1314 ci
->sbRecalc
= SB_BOTH
+1;
1315 SendMessageW( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0 );
1318 case WM_MDIMAXIMIZE
:
1319 ShowWindow( (HWND
)wParam
, SW_MAXIMIZE
);
1322 case WM_MDINEXT
: /* lParam != 0 means previous window */
1323 MDI_SwitchActiveChild( hwnd
, WIN_GetFullHandle( (HWND
)wParam
), !lParam
);
1327 SendMessageW( (HWND
)wParam
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
1331 return MDISetMenu( hwnd
, (HMENU
)wParam
, (HMENU
)lParam
);
1333 case WM_MDIREFRESHMENU
:
1334 return MDIRefreshMenu( hwnd
, (HMENU
)wParam
, (HMENU
)lParam
);
1337 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1338 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
1339 MDITile( hwnd
, ci
, wParam
);
1340 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1345 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1346 ScrollChildren( hwnd
, message
, wParam
, lParam
);
1347 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1351 if (ci
->hwndActiveChild
&& !IsIconic( ci
->hwndActiveChild
))
1352 SetFocus( ci
->hwndActiveChild
);
1356 if( ci
->hwndActiveChild
)
1357 SendMessageW(ci
->hwndActiveChild
, message
, wParam
, lParam
);
1360 case WM_PARENTNOTIFY
:
1361 if (LOWORD(wParam
) == WM_LBUTTONDOWN
)
1365 pt
.x
= SLOWORD(lParam
);
1366 pt
.y
= SHIWORD(lParam
);
1367 child
= ChildWindowFromPoint(hwnd
, pt
);
1369 TRACE("notification from %04x (%li,%li)\n",child
,pt
.x
,pt
.y
);
1371 if( child
&& child
!= hwnd
&& child
!= ci
->hwndActiveChild
)
1372 SetWindowPos(child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1377 if( IsWindow(ci
->hwndChildMaximized
) )
1383 rect
.right
= LOWORD(lParam
);
1384 rect
.bottom
= HIWORD(lParam
);
1386 AdjustWindowRectEx(&rect
, GetWindowLongA(ci
->hwndChildMaximized
,GWL_STYLE
),
1387 0, GetWindowLongA(ci
->hwndChildMaximized
,GWL_EXSTYLE
) );
1388 MoveWindow(ci
->hwndChildMaximized
, rect
.left
, rect
.top
,
1389 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 1);
1392 MDI_PostUpdate(hwnd
, ci
, SB_BOTH
+1);
1396 case WM_MDICALCCHILDSCROLL
:
1397 if( (ci
->mdiFlags
& MDIF_NEEDUPDATE
) && ci
->sbRecalc
)
1399 CalcChildScroll(hwnd
, ci
->sbRecalc
-1);
1401 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1405 return unicode
? DefWindowProcW( hwnd
, message
, wParam
, lParam
) :
1406 DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1409 /***********************************************************************
1412 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1414 if (!IsWindow(hwnd
)) return 0;
1415 return MDIClientWndProc_common( hwnd
, message
, wParam
, lParam
, FALSE
);
1418 /***********************************************************************
1421 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1423 if (!IsWindow(hwnd
)) return 0;
1424 return MDIClientWndProc_common( hwnd
, message
, wParam
, lParam
, TRUE
);
1427 /***********************************************************************
1428 * DefFrameProc (USER.445)
1430 LRESULT WINAPI
DefFrameProc16( HWND16 hwnd
, HWND16 hwndMDIClient
,
1431 UINT16 message
, WPARAM16 wParam
, LPARAM lParam
)
1436 lParam
= (LPARAM
)MapSL(lParam
);
1442 return DefFrameProcA( WIN_Handle32(hwnd
), WIN_Handle32(hwndMDIClient
),
1443 message
, wParam
, lParam
);
1447 MDINEXTMENU next_menu
;
1448 DefFrameProcW( WIN_Handle32(hwnd
), WIN_Handle32(hwndMDIClient
),
1449 message
, wParam
, (LPARAM
)&next_menu
);
1450 return MAKELONG( next_menu
.hmenuNext
, HWND_16(next_menu
.hwndNext
) );
1453 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1458 /***********************************************************************
1459 * DefFrameProcA (USER32.@)
1461 LRESULT WINAPI
DefFrameProcA( HWND hwnd
, HWND hwndMDIClient
,
1462 UINT message
, WPARAM wParam
, LPARAM lParam
)
1470 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, NULL
, 0 );
1471 LPWSTR text
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1472 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, text
, len
);
1473 MDI_UpdateFrameText(hwnd
, hwndMDIClient
, MDI_REPAINTFRAME
, text
);
1474 HeapFree( GetProcessHeap(), 0, text
);
1476 return 1; /* success. FIXME: check text length */
1483 return DefFrameProcW( hwnd
, hwndMDIClient
, message
, wParam
, lParam
);
1486 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1490 /***********************************************************************
1491 * DefFrameProcW (USER32.@)
1493 LRESULT WINAPI
DefFrameProcW( HWND hwnd
, HWND hwndMDIClient
,
1494 UINT message
, WPARAM wParam
, LPARAM lParam
)
1496 MDICLIENTINFO
*ci
= get_client_info( hwndMDIClient
);
1504 WORD id
= LOWORD(wParam
);
1505 /* check for possible syscommands for maximized MDI child */
1506 if (id
< ci
->idFirstChild
|| id
>= ci
->idFirstChild
+ ci
->nActiveChildren
)
1508 if( (id
- 0xf000) & 0xf00f ) break;
1509 if( !ci
->hwndChildMaximized
) break;
1520 return SendMessageW( ci
->hwndChildMaximized
, WM_SYSCOMMAND
,
1527 if (id
- ci
->idFirstChild
== MDI_MOREWINDOWSLIMIT
)
1528 /* User chose "More Windows..." */
1529 childHwnd
= MDI_MoreWindowsDialog(hwndMDIClient
);
1531 /* User chose one of the windows listed in the "Windows" menu */
1532 childHwnd
= MDI_GetChildByID(hwndMDIClient
,id
);
1535 SendMessageW( hwndMDIClient
, WM_MDIACTIVATE
, (WPARAM
)childHwnd
, 0 );
1541 SendMessageW(hwndMDIClient
, message
, wParam
, lParam
);
1545 MDI_UpdateFrameText(hwnd
, hwndMDIClient
, MDI_REPAINTFRAME
, (LPWSTR
)lParam
);
1546 return 1; /* success. FIXME: check text length */
1549 SetFocus(hwndMDIClient
);
1553 MoveWindow(hwndMDIClient
, 0, 0, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1558 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1560 if (!IsIconic(hwnd
) && ci
->hwndActiveChild
&& !ci
->hwndChildMaximized
)
1562 /* control menu is between the frame system menu and
1563 * the first entry of menu bar */
1564 WND
*wndPtr
= WIN_GetPtr(hwnd
);
1566 if( (wParam
== VK_LEFT
&& GetMenu(hwnd
) == next_menu
->hmenuIn
) ||
1567 (wParam
== VK_RIGHT
&& GetSubMenu(wndPtr
->hSysMenu
, 0) == next_menu
->hmenuIn
) )
1569 WIN_ReleasePtr(wndPtr
);
1570 wndPtr
= WIN_GetPtr(ci
->hwndActiveChild
);
1571 next_menu
->hmenuNext
= GetSubMenu(wndPtr
->hSysMenu
, 0);
1572 next_menu
->hwndNext
= ci
->hwndActiveChild
;
1574 WIN_ReleasePtr(wndPtr
);
1581 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1585 /***********************************************************************
1586 * DefMDIChildProc (USER.447)
1588 LRESULT WINAPI
DefMDIChildProc16( HWND16 hwnd
, UINT16 message
,
1589 WPARAM16 wParam
, LPARAM lParam
)
1594 return DefMDIChildProcA( WIN_Handle32(hwnd
), message
, wParam
, (LPARAM
)MapSL(lParam
) );
1598 case WM_CHILDACTIVATE
:
1603 return DefMDIChildProcW( WIN_Handle32(hwnd
), message
, wParam
, lParam
);
1604 case WM_GETMINMAXINFO
:
1606 MINMAXINFO16
*mmi16
= (MINMAXINFO16
*)MapSL(lParam
);
1608 STRUCT32_MINMAXINFO16to32( mmi16
, &mmi
);
1609 DefMDIChildProcW( WIN_Handle32(hwnd
), message
, wParam
, (LPARAM
)&mmi
);
1610 STRUCT32_MINMAXINFO32to16( &mmi
, mmi16
);
1615 MDINEXTMENU next_menu
;
1616 DefMDIChildProcW( WIN_Handle32(hwnd
), message
, wParam
, (LPARAM
)&next_menu
);
1617 return MAKELONG( next_menu
.hmenuNext
, HWND_16(next_menu
.hwndNext
) );
1620 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1625 /***********************************************************************
1626 * DefMDIChildProcA (USER32.@)
1628 LRESULT WINAPI
DefMDIChildProcA( HWND hwnd
, UINT message
,
1629 WPARAM wParam
, LPARAM lParam
)
1631 HWND client
= GetParent(hwnd
);
1632 MDICLIENTINFO
*ci
= get_client_info( client
);
1634 hwnd
= WIN_GetFullHandle( hwnd
);
1635 if (!ci
) return DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1640 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1641 MDI_MenuModifyItem( client
, hwnd
);
1642 if( ci
->hwndChildMaximized
== hwnd
)
1643 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1644 return 1; /* success. FIXME: check text length */
1646 case WM_GETMINMAXINFO
:
1650 case WM_CHILDACTIVATE
:
1656 return DefMDIChildProcW( hwnd
, message
, wParam
, lParam
);
1658 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1662 /***********************************************************************
1663 * DefMDIChildProcW (USER32.@)
1665 LRESULT WINAPI
DefMDIChildProcW( HWND hwnd
, UINT message
,
1666 WPARAM wParam
, LPARAM lParam
)
1668 HWND client
= GetParent(hwnd
);
1669 MDICLIENTINFO
*ci
= get_client_info( client
);
1671 hwnd
= WIN_GetFullHandle( hwnd
);
1672 if (!ci
) return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1677 DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1678 MDI_MenuModifyItem( client
, hwnd
);
1679 if( ci
->hwndChildMaximized
== hwnd
)
1680 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1681 return 1; /* success. FIXME: check text length */
1683 case WM_GETMINMAXINFO
:
1684 MDI_ChildGetMinMaxInfo( client
, hwnd
, (MINMAXINFO
*)lParam
);
1688 return 0x00010000; /* MDI children don't have menu bars */
1691 SendMessageW( client
, WM_MDIDESTROY
, (WPARAM
)hwnd
, 0 );
1695 if (ci
->hwndActiveChild
!= hwnd
) MDI_ChildActivate( client
, hwnd
);
1698 case WM_CHILDACTIVATE
:
1699 MDI_ChildActivate( client
, hwnd
);
1706 if( ci
->hwndChildMaximized
== hwnd
) return 0;
1710 SetWindowLongA( hwnd
, GWL_STYLE
,
1711 GetWindowLongA( hwnd
, GWL_STYLE
) | WS_SYSMENU
);
1714 if (ci
->hwndChildMaximized
== hwnd
)
1715 return SendMessageW( GetParent(client
), message
, wParam
, lParam
);
1716 SetWindowLongW( hwnd
, GWL_STYLE
,
1717 GetWindowLongW( hwnd
, GWL_STYLE
) & ~WS_SYSMENU
);
1720 SendMessageW( client
, WM_MDINEXT
, 0, 0);
1723 SendMessageW( client
, WM_MDINEXT
, 0, 1);
1729 if( ci
->hwndChildMaximized
) ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1730 else MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1734 if( ci
->hwndActiveChild
== hwnd
&& wParam
!= SIZE_MAXIMIZED
)
1736 ci
->hwndChildMaximized
= 0;
1737 MDI_RestoreFrameMenu( GetParent(client
), hwnd
);
1738 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1741 if( wParam
== SIZE_MAXIMIZED
)
1743 HWND hMaxChild
= ci
->hwndChildMaximized
;
1745 if( hMaxChild
== hwnd
) break;
1748 SendMessageW( hMaxChild
, WM_SETREDRAW
, FALSE
, 0 );
1749 MDI_RestoreFrameMenu( GetParent(client
), hMaxChild
);
1750 ShowWindow( hMaxChild
, SW_SHOWNOACTIVATE
);
1751 SendMessageW( hMaxChild
, WM_SETREDRAW
, TRUE
, 0 );
1753 TRACE("maximizing child %04x\n", hwnd
);
1755 /* keep track of the maximized window. */
1756 ci
->hwndChildMaximized
= hwnd
; /* !!! */
1758 /* The maximized window should also be the active window */
1759 MDI_ChildActivate( client
, hwnd
);
1760 MDI_AugmentFrameMenu( GetParent(client
), hwnd
);
1761 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1764 if( wParam
== SIZE_MINIMIZED
)
1766 HWND switchTo
= MDI_GetWindow(ci
, hwnd
, TRUE
, WS_MINIMIZE
);
1768 if (switchTo
) SendMessageW( switchTo
, WM_CHILDACTIVATE
, 0, 0);
1770 MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1775 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1776 HWND parent
= GetParent(client
);
1778 if( wParam
== VK_LEFT
) /* switch to frame system menu */
1780 WND
*wndPtr
= WIN_GetPtr( parent
);
1781 next_menu
->hmenuNext
= GetSubMenu( wndPtr
->hSysMenu
, 0 );
1782 WIN_ReleasePtr( wndPtr
);
1784 if( wParam
== VK_RIGHT
) /* to frame menu bar */
1786 next_menu
->hmenuNext
= GetMenu(parent
);
1788 next_menu
->hwndNext
= parent
;
1795 SendMessageW( hwnd
, WM_SYSCOMMAND
, (WPARAM
)SC_KEYMENU
, (DWORD
)VK_SPACE
);
1800 return DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1803 /**********************************************************************
1804 * CreateMDIWindowA (USER32.@) Creates a MDI child
1807 * Success: Handle to created window
1810 HWND WINAPI
CreateMDIWindowA(
1811 LPCSTR lpClassName
, /* [in] Pointer to registered child class name */
1812 LPCSTR lpWindowName
, /* [in] Pointer to window name */
1813 DWORD dwStyle
, /* [in] Window style */
1814 INT X
, /* [in] Horizontal position of window */
1815 INT Y
, /* [in] Vertical position of window */
1816 INT nWidth
, /* [in] Width of window */
1817 INT nHeight
, /* [in] Height of window */
1818 HWND hWndParent
, /* [in] Handle to parent window */
1819 HINSTANCE hInstance
, /* [in] Handle to application instance */
1820 LPARAM lParam
) /* [in] Application-defined value */
1822 MDICLIENTINFO
*pCi
= get_client_info( hWndParent
);
1823 MDICREATESTRUCTA cs
;
1825 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
1826 debugstr_a(lpClassName
),debugstr_a(lpWindowName
),dwStyle
,X
,Y
,
1827 nWidth
,nHeight
,hWndParent
,hInstance
,lParam
);
1831 ERR("bad hwnd for MDI-client: %04x\n", hWndParent
);
1834 cs
.szClass
=lpClassName
;
1835 cs
.szTitle
=lpWindowName
;
1836 cs
.hOwner
=hInstance
;
1844 return MDICreateChild(hWndParent
, pCi
, &cs
, FALSE
);
1847 /***********************************************************************
1848 * CreateMDIWindowW (USER32.@) Creates a MDI child
1851 * Success: Handle to created window
1854 HWND WINAPI
CreateMDIWindowW(
1855 LPCWSTR lpClassName
, /* [in] Pointer to registered child class name */
1856 LPCWSTR lpWindowName
, /* [in] Pointer to window name */
1857 DWORD dwStyle
, /* [in] Window style */
1858 INT X
, /* [in] Horizontal position of window */
1859 INT Y
, /* [in] Vertical position of window */
1860 INT nWidth
, /* [in] Width of window */
1861 INT nHeight
, /* [in] Height of window */
1862 HWND hWndParent
, /* [in] Handle to parent window */
1863 HINSTANCE hInstance
, /* [in] Handle to application instance */
1864 LPARAM lParam
) /* [in] Application-defined value */
1866 MDICLIENTINFO
*pCi
= get_client_info( hWndParent
);
1867 MDICREATESTRUCTW cs
;
1869 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
1870 debugstr_w(lpClassName
), debugstr_w(lpWindowName
), dwStyle
, X
, Y
,
1871 nWidth
, nHeight
, hWndParent
, hInstance
, lParam
);
1875 ERR("bad hwnd for MDI-client: %04x\n", hWndParent
);
1878 cs
.szClass
= lpClassName
;
1879 cs
.szTitle
= lpWindowName
;
1880 cs
.hOwner
= hInstance
;
1888 return MDICreateChild(hWndParent
, pCi
, (MDICREATESTRUCTA
*)&cs
, TRUE
);
1891 /**********************************************************************
1892 * TranslateMDISysAccel (USER32.@)
1894 BOOL WINAPI
TranslateMDISysAccel( HWND hwndClient
, LPMSG msg
)
1896 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
)
1898 MDICLIENTINFO
*ci
= get_client_info( hwndClient
);
1901 if (!ci
|| !IsWindowEnabled(ci
->hwndActiveChild
)) return 0;
1903 /* translate if the Ctrl key is down and Alt not. */
1905 if( (GetKeyState(VK_CONTROL
) & 0x8000) && !(GetKeyState(VK_MENU
) & 0x8000))
1907 switch( msg
->wParam
)
1911 wParam
= ( GetKeyState(VK_SHIFT
) & 0x8000 ) ? SC_NEXTWINDOW
: SC_PREVWINDOW
;
1920 TRACE("wParam = %04x\n", wParam
);
1921 SendMessageW(ci
->hwndActiveChild
, WM_SYSCOMMAND
, wParam
, (LPARAM
)msg
->wParam
);
1925 return 0; /* failure */
1928 /***********************************************************************
1929 * CalcChildScroll (USER32.@)
1931 void WINAPI
CalcChildScroll( HWND hwnd
, INT scroll
)
1934 RECT childRect
, clientRect
;
1937 GetClientRect( hwnd
, &clientRect
);
1938 SetRectEmpty( &childRect
);
1940 if ((list
= WIN_ListChildren( hwnd
)))
1943 for (i
= 0; list
[i
]; i
++)
1945 DWORD style
= GetWindowLongW( list
[i
], GWL_STYLE
);
1946 if (style
& WS_MAXIMIZE
)
1948 HeapFree( GetProcessHeap(), 0, list
);
1949 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
1952 if (style
& WS_VISIBLE
)
1954 WND
*pWnd
= WIN_FindWndPtr( list
[i
] );
1955 UnionRect( &childRect
, &pWnd
->rectWindow
, &childRect
);
1956 WIN_ReleaseWndPtr( pWnd
);
1959 HeapFree( GetProcessHeap(), 0, list
);
1961 UnionRect( &childRect
, &clientRect
, &childRect
);
1963 /* set common info values */
1964 info
.cbSize
= sizeof(info
);
1965 info
.fMask
= SIF_POS
| SIF_RANGE
;
1967 /* set the specific */
1972 info
.nMin
= childRect
.left
;
1973 info
.nMax
= childRect
.right
- clientRect
.right
;
1974 info
.nPos
= clientRect
.left
- childRect
.left
;
1975 SetScrollInfo(hwnd
, scroll
, &info
, TRUE
);
1976 if (scroll
== SB_HORZ
) break;
1979 info
.nMin
= childRect
.top
;
1980 info
.nMax
= childRect
.bottom
- clientRect
.bottom
;
1981 info
.nPos
= clientRect
.top
- childRect
.top
;
1982 SetScrollInfo(hwnd
, scroll
, &info
, TRUE
);
1988 /***********************************************************************
1989 * ScrollChildren (USER32.@)
1991 void WINAPI
ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
,
1995 INT curPos
, length
, minPos
, maxPos
, shift
;
1998 GetClientRect( hWnd
, &rect
);
2003 GetScrollRange(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
2004 curPos
= GetScrollPos(hWnd
,SB_HORZ
);
2005 length
= (rect
.right
- rect
.left
) / 2;
2006 shift
= GetSystemMetrics(SM_CYHSCROLL
);
2009 GetScrollRange(hWnd
,SB_VERT
,&minPos
,&maxPos
);
2010 curPos
= GetScrollPos(hWnd
,SB_VERT
);
2011 length
= (rect
.bottom
- rect
.top
) / 2;
2012 shift
= GetSystemMetrics(SM_CXVSCROLL
);
2021 newPos
= curPos
- shift
;
2024 newPos
= curPos
+ shift
;
2027 newPos
= curPos
- length
;
2030 newPos
= curPos
+ length
;
2033 case SB_THUMBPOSITION
:
2034 newPos
= LOWORD(lParam
);
2047 CalcChildScroll(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
2051 if( newPos
> maxPos
)
2054 if( newPos
< minPos
)
2057 SetScrollPos(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
2059 if( uMsg
== WM_VSCROLL
)
2060 ScrollWindowEx(hWnd
,0 ,curPos
- newPos
, NULL
, NULL
, 0, NULL
,
2061 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
2063 ScrollWindowEx(hWnd
,curPos
- newPos
, 0, NULL
, NULL
, 0, NULL
,
2064 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
2068 /******************************************************************************
2069 * CascadeWindows (USER32.@) Cascades MDI child windows
2072 * Success: Number of cascaded windows.
2076 CascadeWindows (HWND hwndParent
, UINT wFlags
, const LPRECT lpRect
,
2077 UINT cKids
, const HWND
*lpKids
)
2079 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2080 hwndParent
, wFlags
, cKids
);
2086 /******************************************************************************
2087 * TileWindows (USER32.@) Tiles MDI child windows
2090 * Success: Number of tiled windows.
2094 TileWindows (HWND hwndParent
, UINT wFlags
, const LPRECT lpRect
,
2095 UINT cKids
, const HWND
*lpKids
)
2097 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2098 hwndParent
, wFlags
, cKids
);
2103 /************************************************************************
2104 * "More Windows..." functionality
2107 /* MDI_MoreWindowsDlgProc
2109 * This function will process the messages sent to the "More Windows..."
2111 * Return values: 0 = cancel pressed
2112 * HWND = ok pressed or double-click in the list...
2116 static BOOL WINAPI
MDI_MoreWindowsDlgProc (HWND hDlg
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
2125 MDICLIENTINFO
*ci
= get_client_info( (HWND
)lParam
);
2126 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2127 HWND
*list
, *sorted_list
;
2129 if (!(list
= WIN_ListChildren( (HWND
)lParam
))) return TRUE
;
2130 if (!(sorted_list
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
2131 sizeof(HWND
) * ci
->nActiveChildren
)))
2133 HeapFree( GetProcessHeap(), 0, list
);
2137 /* Fill the list, sorted by id... */
2138 for (i
= 0; list
[i
]; i
++)
2140 UINT id
= GetWindowLongW( list
[i
], GWL_ID
) - ci
->idFirstChild
;
2141 if (id
< ci
->nActiveChildren
) sorted_list
[id
] = list
[i
];
2143 HeapFree( GetProcessHeap(), 0, list
);
2145 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
2149 if (!GetWindowTextW( sorted_list
[i
], buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
2151 SendMessageW(hListBox
, LB_ADDSTRING
, 0, (LPARAM
)buffer
);
2152 SendMessageW(hListBox
, LB_SETITEMDATA
, i
, (LPARAM
)sorted_list
[i
] );
2153 length
= strlenW(buffer
); /* FIXME: should use GetTextExtentPoint */
2154 if (length
> widest
)
2157 /* Make sure the horizontal scrollbar scrolls ok */
2158 SendMessageW(hListBox
, LB_SETHORIZONTALEXTENT
, widest
* 6, 0);
2160 /* Set the current selection */
2161 SendMessageW(hListBox
, LB_SETCURSEL
, MDI_MOREWINDOWSLIMIT
, 0);
2166 switch (LOWORD(wParam
))
2169 if (HIWORD(wParam
) != LBN_DBLCLK
) break;
2173 /* windows are sorted by menu ID, so we must return the
2174 * window associated to the given id
2176 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2177 UINT index
= SendMessageW(hListBox
, LB_GETCURSEL
, 0, 0);
2178 LRESULT res
= SendMessageW(hListBox
, LB_GETITEMDATA
, index
, 0);
2179 EndDialog(hDlg
, res
);
2193 * MDI_MoreWindowsDialog
2195 * Prompts the user with a listbox containing the opened
2196 * documents. The user can then choose a windows and click
2197 * on OK to set the current window to the one selected, or
2198 * CANCEL to cancel. The function returns a handle to the
2202 static HWND
MDI_MoreWindowsDialog(HWND hwnd
)
2208 hRes
= FindResourceA(GetModuleHandleA("USER32"), "MDI_MOREWINDOWS", RT_DIALOGA
);
2213 hDlgTmpl
= LoadResource(GetModuleHandleA("USER32"), hRes
);
2218 template = LockResource( hDlgTmpl
);
2223 return (HWND
) DialogBoxIndirectParamA(GetModuleHandleA("USER32"),
2224 (LPDLGTEMPLATEA
) template,
2225 hwnd
, MDI_MoreWindowsDlgProc
, (LPARAM
) hwnd
);
2232 * Will swap the menu IDs for the given 2 positions.
2233 * pos1 and pos2 are menu IDs
2238 static void MDI_SwapMenuItems(HWND parent
, UINT pos1
, UINT pos2
)
2243 if (!(list
= WIN_ListChildren( parent
))) return;
2244 for (i
= 0; list
[i
]; i
++)
2246 UINT id
= GetWindowLongW( list
[i
], GWL_ID
);
2247 if (id
== pos1
) SetWindowLongW( list
[i
], GWL_ID
, pos2
);
2248 else if (id
== pos2
) SetWindowLongW( list
[i
], GWL_ID
, pos1
);
2250 HeapFree( GetProcessHeap(), 0, list
);