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.
94 #include "wine/unicode.h"
96 #include "nonclient.h"
100 #include "wine/debug.h"
103 WINE_DEFAULT_DEBUG_CHANNEL(mdi
);
105 #define MDI_MAXLISTLENGTH 0x40
106 #define MDI_MAXTITLELENGTH 0xa1
108 #define MDI_NOFRAMEREPAINT 0
109 #define MDI_REPAINTFRAMENOW 1
110 #define MDI_REPAINTFRAME 2
112 #define WM_MDICALCCHILDSCROLL 0x10ac /* this is exactly what Windows uses */
114 /* "More Windows..." definitions */
115 #define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
116 option will appear under the Windows menu */
117 #define MDI_IDC_LISTBOX 100
118 #define IDS_MDI_MOREWINDOWS 13
120 #define MDIF_NEEDUPDATE 0x0001
124 UINT nActiveChildren
;
125 HWND hwndChildMaximized
;
126 HWND hwndActiveChild
;
132 UINT sbRecalc
; /* SB_xxx flags for scrollbar fixup */
135 static HBITMAP hBmpClose
= 0;
137 /* ----------------- declarations ----------------- */
138 static void MDI_UpdateFrameText( HWND
, HWND
, BOOL
, LPCWSTR
);
139 static BOOL
MDI_AugmentFrameMenu( HWND
, HWND
);
140 static BOOL
MDI_RestoreFrameMenu( HWND
, HWND
);
141 static LONG
MDI_ChildActivate( HWND
, HWND
);
143 static HWND
MDI_MoreWindowsDialog(HWND
);
144 static void MDI_SwapMenuItems(HWND
, UINT
, UINT
);
145 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
146 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
148 /* -------- Miscellaneous service functions ----------
152 static HWND
MDI_GetChildByID(HWND hwnd
, UINT id
)
158 if (!(win_array
= WIN_ListChildren( hwnd
))) return 0;
159 for (i
= 0; win_array
[i
]; i
++)
161 if (GetWindowLongA( win_array
[i
], GWL_ID
) == id
) break;
164 HeapFree( GetProcessHeap(), 0, win_array
);
168 static void MDI_PostUpdate(HWND hwnd
, MDICLIENTINFO
* ci
, WORD recalc
)
170 if( !(ci
->mdiFlags
& MDIF_NEEDUPDATE
) )
172 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
173 PostMessageA( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0);
175 ci
->sbRecalc
= recalc
;
179 /*********************************************************************
180 * MDIClient class descriptor
182 const struct builtin_class_descr MDICLIENT_builtin_class
=
184 "MDIClient", /* name */
186 MDIClientWndProcA
, /* procA */
187 MDIClientWndProcW
, /* procW */
188 sizeof(MDICLIENTINFO
), /* extra */
189 IDC_ARROW
, /* cursor */
190 (HBRUSH
)(COLOR_APPWORKSPACE
+1) /* brush */
194 static MDICLIENTINFO
*get_client_info( HWND client
)
196 MDICLIENTINFO
*ret
= NULL
;
197 WND
*win
= WIN_GetPtr( client
);
200 if (win
== WND_OTHER_PROCESS
)
202 ERR( "client %p belongs to other process\n", client
);
205 if (win
->cbWndExtra
< sizeof(MDICLIENTINFO
)) WARN( "%p is not an MDI client\n", client
);
206 else ret
= (MDICLIENTINFO
*)win
->wExtra
;
207 WIN_ReleasePtr( win
);
212 /**********************************************************************
215 static void MDI_MenuModifyItem( HWND client
, HWND hWndChild
)
217 MDICLIENTINFO
*clientInfo
= get_client_info( client
);
221 if (!clientInfo
|| !clientInfo
->hWindowMenu
) return;
223 id
= GetWindowLongA( hWndChild
, GWL_ID
);
224 if (id
>= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
) return;
226 buffer
[1] = '1' + id
- clientInfo
->idFirstChild
;
228 GetWindowTextW( hWndChild
, buffer
+ 3, sizeof(buffer
)/sizeof(WCHAR
) - 3 );
230 n
= GetMenuState(clientInfo
->hWindowMenu
, id
, MF_BYCOMMAND
);
231 ModifyMenuW(clientInfo
->hWindowMenu
, id
, MF_BYCOMMAND
| MF_STRING
, id
, buffer
);
232 CheckMenuItem(clientInfo
->hWindowMenu
, id
, n
& MF_CHECKED
);
235 /**********************************************************************
238 static BOOL
MDI_MenuDeleteItem( HWND client
, HWND hWndChild
)
241 static const WCHAR format
[] = {'&','%','d',' ',0};
242 MDICLIENTINFO
*clientInfo
= get_client_info( client
);
245 if( !clientInfo
->nActiveChildren
|| !clientInfo
->hWindowMenu
)
248 id
= GetWindowLongA( hWndChild
, GWL_ID
);
249 DeleteMenu(clientInfo
->hWindowMenu
,id
,MF_BYCOMMAND
);
251 /* walk the rest of MDI children to prevent gaps in the id
252 * sequence and in the menu child list */
254 for( index
= id
+1; index
<= clientInfo
->nActiveChildren
+
255 clientInfo
->idFirstChild
; index
++ )
257 HWND hwnd
= MDI_GetChildByID(client
,index
);
260 TRACE("no window for id=%i\n",index
);
265 SetWindowLongW( hwnd
, GWL_ID
, GetWindowLongW( hwnd
, GWL_ID
) - 1 );
267 n
= wsprintfW(buffer
, format
,index
- clientInfo
->idFirstChild
);
268 GetWindowTextW( hwnd
, buffer
+ n
, sizeof(buffer
)/sizeof(WCHAR
) - n
);
270 /* change menu if the current child is to be shown in the
273 if (index
<= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
)
274 ModifyMenuW(clientInfo
->hWindowMenu
,index
,MF_BYCOMMAND
| MF_STRING
,
275 index
- 1 , buffer
);
278 /* We must restore the "More Windows..." option if there are enough children
280 if (clientInfo
->nActiveChildren
- 1 > MDI_MOREWINDOWSLIMIT
)
283 LoadStringW(GetModuleHandleA("USER32"), IDS_MDI_MOREWINDOWS
, szTmp
, sizeof(szTmp
)/sizeof(szTmp
[0]));
284 AppendMenuW(clientInfo
->hWindowMenu
, MF_STRING
, clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
, szTmp
);
289 /**********************************************************************
292 * returns "activateable" child different from the current or zero
294 static HWND
MDI_GetWindow(MDICLIENTINFO
*clientInfo
, HWND hWnd
, BOOL bNext
,
301 dwStyleMask
|= WS_DISABLED
| WS_VISIBLE
;
302 if( !hWnd
) hWnd
= clientInfo
->hwndActiveChild
;
304 if (!(list
= WIN_ListChildren( GetParent(hWnd
) ))) return 0;
306 /* start from next after hWnd */
307 while (list
[i
] && list
[i
] != hWnd
) i
++;
310 for ( ; list
[i
]; i
++)
312 if (GetWindow( list
[i
], GW_OWNER
)) continue;
313 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
315 if (bNext
) goto found
;
317 /* now restart from the beginning */
318 for (i
= 0; list
[i
] && list
[i
] != hWnd
; i
++)
320 if (GetWindow( list
[i
], GW_OWNER
)) continue;
321 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & dwStyleMask
) != WS_VISIBLE
) continue;
323 if (bNext
) goto found
;
326 HeapFree( GetProcessHeap(), 0, list
);
330 /**********************************************************************
331 * MDI_CalcDefaultChildPos
333 * It seems that the default height is about 2/3 of the client rect
335 static void MDI_CalcDefaultChildPos( HWND hwnd
, WORD n
, LPPOINT lpPos
, INT delta
)
339 INT spacing
= GetSystemMetrics(SM_CYCAPTION
) +
340 GetSystemMetrics(SM_CYFRAME
) - 1;
342 GetClientRect( hwnd
, &rect
);
343 if( rect
.bottom
- rect
.top
- delta
>= spacing
)
344 rect
.bottom
-= delta
;
346 nstagger
= (rect
.bottom
- rect
.top
)/(3 * spacing
);
347 lpPos
[1].x
= (rect
.right
- rect
.left
- nstagger
* spacing
);
348 lpPos
[1].y
= (rect
.bottom
- rect
.top
- nstagger
* spacing
);
349 lpPos
[0].x
= lpPos
[0].y
= spacing
* (n
%(nstagger
+1));
352 /**********************************************************************
355 static LRESULT
MDISetMenu( HWND hwnd
, HMENU hmenuFrame
,
359 HWND hwndFrame
= GetParent(hwnd
);
360 HMENU oldFrameMenu
= GetMenu(hwndFrame
);
362 TRACE("%p %p %p\n", hwnd
, hmenuFrame
, hmenuWindow
);
364 if (hmenuFrame
&& !IsMenu(hmenuFrame
))
366 WARN("hmenuFrame is not a menu handle\n");
370 if (hmenuWindow
&& !IsMenu(hmenuWindow
))
372 WARN("hmenuWindow is not a menu handle\n");
376 if (!(ci
= get_client_info( hwnd
))) return 0;
378 if( ci
->hwndChildMaximized
&& hmenuFrame
&& hmenuFrame
!=oldFrameMenu
)
379 MDI_RestoreFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
381 if( hmenuWindow
&& hmenuWindow
!= ci
->hWindowMenu
)
383 /* delete menu items from ci->hWindowMenu
384 * and add them to hmenuWindow */
385 /* Agent newsreader calls this function with ci->hWindowMenu == NULL */
386 if( ci
->hWindowMenu
&& ci
->nActiveChildren
)
389 LPWSTR buffer
= NULL
;
391 INT nbWindowsMenuItems
; /* num of documents shown + "More Windows..." if present */
392 INT i
= GetMenuItemCount(ci
->hWindowMenu
) - 1;
393 INT pos
= GetMenuItemCount(hmenuWindow
) + 1;
395 AppendMenuA( hmenuWindow
, MF_SEPARATOR
, 0, NULL
);
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
);
426 /* remove separator */
427 DeleteMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
429 ci
->hWindowMenu
= hmenuWindow
;
434 SetMenu(hwndFrame
, hmenuFrame
);
435 if( hmenuFrame
!=oldFrameMenu
)
437 if( ci
->hwndChildMaximized
)
438 MDI_AugmentFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
439 return (LRESULT
)oldFrameMenu
;
444 HMENU menu
= GetMenu( GetParent(hwnd
) );
445 INT nItems
= GetMenuItemCount(menu
) - 1;
446 UINT iId
= GetMenuItemID(menu
,nItems
) ;
448 if( !(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
450 /* SetMenu() may already have been called, meaning that this window
451 * already has its menu. But they may have done a SetMenu() on
452 * an MDI window, and called MDISetMenu() after the fact, meaning
453 * that the "if" to this "else" wouldn't catch the need to
454 * augment the frame menu.
456 if( ci
->hwndChildMaximized
)
457 MDI_AugmentFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
463 /**********************************************************************
466 static LRESULT
MDIRefreshMenu( HWND hwnd
, HMENU hmenuFrame
,
469 HWND hwndFrame
= GetParent(hwnd
);
470 HMENU oldFrameMenu
= GetMenu(hwndFrame
);
472 TRACE("%p %p %p\n", hwnd
, hmenuFrame
, hmenuWindow
);
474 FIXME("partially function stub\n");
476 return (LRESULT
)oldFrameMenu
;
480 /* ------------------ MDI child window functions ---------------------- */
483 /**********************************************************************
486 static HWND
MDICreateChild( HWND parent
, MDICLIENTINFO
*ci
,
487 LPMDICREATESTRUCTA cs
, BOOL unicode
)
490 DWORD style
= cs
->style
| (WS_CHILD
| WS_CLIPSIBLINGS
);
491 HWND hwnd
, hwndMax
= 0;
492 UINT wIDmenu
= ci
->idFirstChild
+ ci
->nActiveChildren
;
494 static const WCHAR lpstrDef
[] = {'j','u','n','k','!',0};
496 TRACE("origin %i,%i - dim %i,%i, style %08lx\n",
497 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, cs
->style
);
498 /* calculate placement */
499 MDI_CalcDefaultChildPos(parent
, ci
->nTotalCreated
++, pos
, 0);
501 if (cs
->cx
== CW_USEDEFAULT
|| cs
->cx
== CW_USEDEFAULT16
|| !cs
->cx
) cs
->cx
= pos
[1].x
;
502 if (cs
->cy
== CW_USEDEFAULT
|| cs
->cy
== CW_USEDEFAULT16
|| !cs
->cy
) cs
->cy
= pos
[1].y
;
504 if (cs
->x
== CW_USEDEFAULT
|| cs
->x
== CW_USEDEFAULT16
)
510 /* restore current maximized child */
511 if( (style
& WS_VISIBLE
) && ci
->hwndChildMaximized
)
513 TRACE("Restoring current maximized child %p\n", ci
->hwndChildMaximized
);
514 if( style
& WS_MAXIMIZE
)
515 SendMessageW(parent
, WM_SETREDRAW
, FALSE
, 0L);
516 hwndMax
= ci
->hwndChildMaximized
;
517 ShowWindow( hwndMax
, SW_SHOWNOACTIVATE
);
518 if( style
& WS_MAXIMIZE
)
519 SendMessageW(parent
, WM_SETREDRAW
, TRUE
, 0L);
522 if (ci
->nActiveChildren
<= MDI_MOREWINDOWSLIMIT
)
523 /* this menu is needed to set a check mark in MDI_ChildActivate */
524 if (ci
->hWindowMenu
!= 0)
525 AppendMenuW(ci
->hWindowMenu
, MF_STRING
, wIDmenu
, lpstrDef
);
527 ci
->nActiveChildren
++;
529 /* fix window style */
530 wndParent
= WIN_FindWndPtr( parent
);
531 if( !(wndParent
->dwStyle
& MDIS_ALLCHILDSTYLES
) )
533 TRACE("MDIS_ALLCHILDSTYLES is missing, fixing window style\n");
534 style
&= (WS_CHILD
| WS_CLIPSIBLINGS
| WS_MINIMIZE
| WS_MAXIMIZE
|
535 WS_CLIPCHILDREN
| WS_DISABLED
| WS_VSCROLL
| WS_HSCROLL
);
536 style
|= (WS_VISIBLE
| WS_OVERLAPPEDWINDOW
);
539 if( wndParent
->flags
& WIN_ISWIN32
)
541 WIN_ReleaseWndPtr( wndParent
);
542 /* FIXME: CreateWindowEx must be called with WS_EX_MDICHILD set, but
543 * it requires to move MDI specific child creation to CreateWindowEx
544 * and do child tracking in MDICLIENT using WM_PARENTNOTIFY.
548 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)cs
;
549 hwnd
= CreateWindowExW( 0, csW
->szClass
, csW
->szTitle
, style
,
550 csW
->x
, csW
->y
, csW
->cx
, csW
->cy
, parent
,
551 (HMENU
)wIDmenu
, csW
->hOwner
, csW
);
554 hwnd
= CreateWindowExA( 0, cs
->szClass
, cs
->szTitle
, style
,
555 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, parent
,
556 (HMENU
)wIDmenu
, cs
->hOwner
, cs
);
560 MDICREATESTRUCT16 cs16
;
561 SEGPTR title
, cls
, seg_cs16
;
563 WIN_ReleaseWndPtr( wndParent
);
564 STRUCT32_MDICREATESTRUCT32Ato16( cs
, &cs16
);
565 cs16
.szTitle
= title
= MapLS( cs
->szTitle
);
566 cs16
.szClass
= cls
= MapLS( cs
->szClass
);
567 seg_cs16
= MapLS( &cs16
);
568 hwnd
= WIN_Handle32( CreateWindowEx16( 0, cs
->szClass
, cs
->szTitle
, style
,
569 cs16
.x
, cs16
.y
, cs16
.cx
, cs16
.cy
,
570 HWND_16(parent
), (HMENU16
)wIDmenu
,
571 cs16
.hOwner
, (LPVOID
)seg_cs16
));
577 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
581 /* All MDI child windows have the WS_EX_MDICHILD style */
582 SetWindowLongW( hwnd
, GWL_EXSTYLE
, GetWindowLongW( hwnd
, GWL_EXSTYLE
) | WS_EX_MDICHILD
);
584 /* If we have more than 9 windows, we must insert the new one at the
585 * 9th position in order to see it in the "Windows" menu
587 if (ci
->nActiveChildren
> MDI_MOREWINDOWSLIMIT
)
588 MDI_SwapMenuItems( parent
, GetWindowLongW( hwnd
, GWL_ID
),
589 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1);
591 MDI_MenuModifyItem(parent
, hwnd
);
593 /* Have we hit the "More Windows..." limit? If so, we must
594 * add a "More Windows..." option
596 if (ci
->nActiveChildren
== MDI_MOREWINDOWSLIMIT
+ 1)
599 LoadStringW(GetModuleHandleA("USER32"), IDS_MDI_MOREWINDOWS
, szTmp
, sizeof(szTmp
)/sizeof(szTmp
[0]));
601 ModifyMenuW(ci
->hWindowMenu
,
602 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
,
603 MF_BYCOMMAND
| MF_STRING
,
604 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
,
608 if( IsIconic(hwnd
) && ci
->hwndActiveChild
)
610 TRACE("Minimizing created MDI child %p\n", hwnd
);
611 ShowWindow( hwnd
, SW_SHOWMINNOACTIVE
);
615 /* WS_VISIBLE is clear if a) the MDI client has
616 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
617 * MDICreateStruct. If so the created window is not shown nor
620 if (IsWindowVisible(hwnd
)) ShowWindow(hwnd
, SW_SHOW
);
622 TRACE("created child - %p\n",hwnd
);
626 ci
->nActiveChildren
--;
627 DeleteMenu(ci
->hWindowMenu
,wIDmenu
,MF_BYCOMMAND
);
628 if( IsWindow(hwndMax
) )
629 ShowWindow(hwndMax
, SW_SHOWMAXIMIZED
);
635 /**********************************************************************
636 * MDI_ChildGetMinMaxInfo
638 * Note: The rule here is that client rect of the maximized MDI child
639 * is equal to the client rect of the MDI client window.
641 static void MDI_ChildGetMinMaxInfo( HWND client
, HWND hwnd
, MINMAXINFO
* lpMinMax
)
645 GetClientRect( client
, &rect
);
646 AdjustWindowRectEx( &rect
, GetWindowLongW( hwnd
, GWL_STYLE
),
647 0, GetWindowLongW( hwnd
, GWL_EXSTYLE
));
649 lpMinMax
->ptMaxSize
.x
= rect
.right
-= rect
.left
;
650 lpMinMax
->ptMaxSize
.y
= rect
.bottom
-= rect
.top
;
652 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
653 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
655 TRACE("max rect (%ld,%ld - %ld, %ld)\n",
656 rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
659 /**********************************************************************
660 * MDI_SwitchActiveChild
662 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
665 static void MDI_SwitchActiveChild( HWND clientHwnd
, HWND childHwnd
,
670 MDICLIENTINFO
*ci
= get_client_info( clientHwnd
);
672 hwndTo
= MDI_GetWindow(ci
, childHwnd
, bNextWindow
, 0);
674 TRACE("from %p, to %p\n",childHwnd
,hwndTo
);
676 if ( !hwndTo
) return; /* no window to switch to */
678 hwndPrev
= ci
->hwndActiveChild
;
680 if ( hwndTo
!= hwndPrev
)
682 SetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0,
683 SWP_NOMOVE
| SWP_NOSIZE
);
685 if( bNextWindow
&& hwndPrev
)
686 SetWindowPos( hwndPrev
, HWND_BOTTOM
, 0, 0, 0, 0,
687 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
692 /**********************************************************************
695 static LRESULT
MDIDestroyChild( HWND parent
, MDICLIENTINFO
*ci
,
696 HWND child
, BOOL flagDestroy
)
698 if( child
== ci
->hwndActiveChild
)
700 MDI_SwitchActiveChild(parent
, child
, TRUE
);
702 if( child
== ci
->hwndActiveChild
)
704 ShowWindow( child
, SW_HIDE
);
705 if( child
== ci
->hwndChildMaximized
)
707 HWND frame
= GetParent(parent
);
708 MDI_RestoreFrameMenu( frame
, child
);
709 ci
->hwndChildMaximized
= 0;
710 MDI_UpdateFrameText( frame
, parent
, TRUE
, NULL
);
713 MDI_ChildActivate(parent
, 0);
717 MDI_MenuDeleteItem(parent
, child
);
719 ci
->nActiveChildren
--;
721 TRACE("child destroyed - %p\n",child
);
725 MDI_PostUpdate(GetParent(child
), ci
, SB_BOTH
+1);
726 DestroyWindow(child
);
732 /**********************************************************************
735 * Note: hWndChild is NULL when last child is being destroyed
737 static LONG
MDI_ChildActivate( HWND client
, HWND child
)
739 MDICLIENTINFO
*clientInfo
= get_client_info( client
);
740 HWND prevActiveWnd
= clientInfo
->hwndActiveChild
;
741 BOOL isActiveFrameWnd
;
743 if (child
&& (!IsWindowEnabled( child
))) return 0;
745 /* Don't activate if it is already active. Might happen
746 since ShowWindow DOES activate MDI children */
747 if (clientInfo
->hwndActiveChild
== child
) return 0;
749 TRACE("%p\n", child
);
751 isActiveFrameWnd
= (GetActiveWindow() == GetParent(client
));
753 /* deactivate prev. active child */
756 SetWindowLongA( prevActiveWnd
, GWL_STYLE
,
757 GetWindowLongA( prevActiveWnd
, GWL_STYLE
) | WS_SYSMENU
);
758 SendMessageA( prevActiveWnd
, WM_NCACTIVATE
, FALSE
, 0L );
759 SendMessageA( prevActiveWnd
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
760 /* uncheck menu item */
761 if( clientInfo
->hWindowMenu
)
763 UINT prevID
= GetWindowLongA( prevActiveWnd
, GWL_ID
);
765 if (prevID
- clientInfo
->idFirstChild
< MDI_MOREWINDOWSLIMIT
)
766 CheckMenuItem( clientInfo
->hWindowMenu
, prevID
, 0);
768 CheckMenuItem( clientInfo
->hWindowMenu
,
769 clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1, 0);
774 if (clientInfo
->hwndChildMaximized
&& clientInfo
->hwndChildMaximized
!= child
)
776 INT cmd
= SW_SHOWNORMAL
;
780 UINT state
= GetMenuState(GetSystemMenu(child
, FALSE
), SC_MAXIMIZE
, MF_BYCOMMAND
);
781 if (state
!= 0xFFFFFFFF && (state
& (MF_DISABLED
| MF_GRAYED
)))
782 SendMessageW(clientInfo
->hwndChildMaximized
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
784 cmd
= SW_SHOWMAXIMIZED
;
786 clientInfo
->hwndActiveChild
= child
;
789 ShowWindow( clientInfo
->hwndActiveChild
, cmd
);
792 clientInfo
->hwndActiveChild
= child
;
794 /* check if we have any children left */
797 if( isActiveFrameWnd
)
802 /* check menu item */
803 if( clientInfo
->hWindowMenu
)
805 UINT id
= GetWindowLongA( child
, GWL_ID
);
806 /* The window to be activated must be displayed in the "Windows" menu */
807 if (id
>= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
)
809 MDI_SwapMenuItems( GetParent(child
),
810 id
, clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1);
811 id
= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1;
812 MDI_MenuModifyItem( GetParent(child
), child
);
815 CheckMenuItem(clientInfo
->hWindowMenu
, id
, MF_CHECKED
);
817 /* bring active child to the top */
818 SetWindowPos( child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
820 if( isActiveFrameWnd
)
822 SendMessageA( child
, WM_NCACTIVATE
, TRUE
, 0L);
823 if( GetFocus() == client
)
824 SendMessageA( client
, WM_SETFOCUS
, (WPARAM
)client
, 0L );
828 SendMessageA( child
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
, (LPARAM
)child
);
832 /* -------------------- MDI client window functions ------------------- */
834 /**********************************************************************
835 * CreateMDIMenuBitmap
837 static HBITMAP
CreateMDIMenuBitmap(void)
839 HDC hDCSrc
= CreateCompatibleDC(0);
840 HDC hDCDest
= CreateCompatibleDC(hDCSrc
);
841 HBITMAP hbClose
= LoadBitmapW(0, MAKEINTRESOURCEW(OBM_OLD_CLOSE
) );
843 HBITMAP hobjSrc
, hobjDest
;
845 hobjSrc
= SelectObject(hDCSrc
, hbClose
);
846 hbCopy
= CreateCompatibleBitmap(hDCSrc
,GetSystemMetrics(SM_CXSIZE
),GetSystemMetrics(SM_CYSIZE
));
847 hobjDest
= SelectObject(hDCDest
, hbCopy
);
849 BitBlt(hDCDest
, 0, 0, GetSystemMetrics(SM_CXSIZE
), GetSystemMetrics(SM_CYSIZE
),
850 hDCSrc
, GetSystemMetrics(SM_CXSIZE
), 0, SRCCOPY
);
852 SelectObject(hDCSrc
, hobjSrc
);
853 DeleteObject(hbClose
);
856 hobjSrc
= SelectObject( hDCDest
, GetStockObject(BLACK_PEN
) );
858 MoveToEx( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, 0, NULL
);
859 LineTo( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, GetSystemMetrics(SM_CYSIZE
) - 1);
861 SelectObject(hDCDest
, hobjSrc
);
862 SelectObject(hDCDest
, hobjDest
);
868 /**********************************************************************
871 static LONG
MDICascade( HWND client
, MDICLIENTINFO
*ci
)
874 BOOL has_icons
= FALSE
;
877 if (ci
->hwndChildMaximized
)
878 SendMessageA( client
, WM_MDIRESTORE
,
879 (WPARAM
)ci
->hwndChildMaximized
, 0);
881 if (ci
->nActiveChildren
== 0) return 0;
883 if (!(win_array
= WIN_ListChildren( client
))) return 0;
885 /* remove all the windows we don't want */
886 for (i
= total
= 0; win_array
[i
]; i
++)
888 if (!IsWindowVisible( win_array
[i
] )) continue;
889 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows */
890 if (IsIconic( win_array
[i
] ))
895 win_array
[total
++] = win_array
[i
];
897 win_array
[total
] = 0;
901 INT delta
= 0, n
= 0, i
;
903 if (has_icons
) delta
= GetSystemMetrics(SM_CYICONSPACING
) + GetSystemMetrics(SM_CYICON
);
905 /* walk the list (backwards) and move windows */
906 for (i
= total
- 1; i
>= 0; i
--)
908 TRACE("move %p to (%ld,%ld) size [%ld,%ld]\n",
909 win_array
[i
], pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
);
911 MDI_CalcDefaultChildPos(client
, n
++, pos
, delta
);
912 SetWindowPos( win_array
[i
], 0, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
,
913 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
916 HeapFree( GetProcessHeap(), 0, win_array
);
918 if (has_icons
) ArrangeIconicWindows( client
);
922 /**********************************************************************
925 static void MDITile( HWND client
, MDICLIENTINFO
*ci
, WPARAM wParam
)
929 BOOL has_icons
= FALSE
;
931 if (ci
->hwndChildMaximized
)
932 SendMessageA( client
, WM_MDIRESTORE
, (WPARAM
)ci
->hwndChildMaximized
, 0);
934 if (ci
->nActiveChildren
== 0) return;
936 if (!(win_array
= WIN_ListChildren( client
))) return;
938 /* remove all the windows we don't want */
939 for (i
= total
= 0; win_array
[i
]; i
++)
941 if (!IsWindowVisible( win_array
[i
] )) continue;
942 if (GetWindow( win_array
[i
], GW_OWNER
)) continue; /* skip owned windows (icon titles) */
943 if (IsIconic( win_array
[i
] ))
948 if ((wParam
& MDITILE_SKIPDISABLED
) && !IsWindowEnabled( win_array
[i
] )) continue;
949 win_array
[total
++] = win_array
[i
];
951 win_array
[total
] = 0;
953 TRACE("%u windows to tile\n", total
);
957 HWND
*pWnd
= win_array
;
959 int x
, y
, xsize
, ysize
;
960 int rows
, columns
, r
, c
, i
;
962 GetClientRect(client
,&rect
);
963 rows
= (int) sqrt((double)total
);
964 columns
= total
/ rows
;
966 if( wParam
& MDITILE_HORIZONTAL
) /* version >= 3.1 */
969 rows
= columns
; /* exchange r and c */
975 y
= rect
.bottom
- 2 * GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
976 rect
.bottom
= ( y
- GetSystemMetrics(SM_CYICON
) < rect
.top
)? rect
.bottom
: y
;
979 ysize
= rect
.bottom
/ rows
;
980 xsize
= rect
.right
/ columns
;
982 for (x
= i
= 0, c
= 1; c
<= columns
&& *pWnd
; c
++)
987 ysize
= rect
.bottom
/ rows
;
991 for (r
= 1; r
<= rows
&& *pWnd
; r
++, i
++)
993 SetWindowPos(*pWnd
, 0, x
, y
, xsize
, ysize
,
994 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
1001 HeapFree( GetProcessHeap(), 0, win_array
);
1002 if (has_icons
) ArrangeIconicWindows( client
);
1005 /* ----------------------- Frame window ---------------------------- */
1008 /**********************************************************************
1009 * MDI_AugmentFrameMenu
1011 static BOOL
MDI_AugmentFrameMenu( HWND frame
, HWND hChild
)
1013 HMENU menu
= GetMenu( frame
);
1014 WND
* child
= WIN_FindWndPtr(hChild
);
1015 HMENU hSysPopup
= 0;
1016 HBITMAP hSysMenuBitmap
= 0;
1018 TRACE("frame %p,child %p\n",frame
,hChild
);
1020 if( !menu
|| !child
->hSysMenu
)
1022 WIN_ReleaseWndPtr(child
);
1025 WIN_ReleaseWndPtr(child
);
1027 /* create a copy of sysmenu popup and insert it into frame menu bar */
1029 if (!(hSysPopup
= LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU")))
1032 AppendMenuA(menu
,MF_HELP
| MF_BITMAP
,
1033 SC_MINIMIZE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_MINIMIZE
) ;
1034 AppendMenuA(menu
,MF_HELP
| MF_BITMAP
,
1035 SC_RESTORE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_RESTORE
);
1037 /* In Win 95 look, the system menu is replaced by the child icon */
1039 if(TWEAK_WineLook
> WIN31_LOOK
)
1041 HICON hIcon
= (HICON
)GetClassLongA(hChild
, GCL_HICONSM
);
1043 hIcon
= (HICON
)GetClassLongA(hChild
, GCL_HICON
);
1047 HBITMAP hBitmap
, hOldBitmap
;
1049 HDC hdc
= GetDC(hChild
);
1054 cx
= GetSystemMetrics(SM_CXSMICON
);
1055 cy
= GetSystemMetrics(SM_CYSMICON
);
1056 hMemDC
= CreateCompatibleDC(hdc
);
1057 hBitmap
= CreateCompatibleBitmap(hdc
, cx
, cy
);
1058 hOldBitmap
= SelectObject(hMemDC
, hBitmap
);
1059 SetMapMode(hMemDC
, MM_TEXT
);
1060 hBrush
= CreateSolidBrush(GetSysColor(COLOR_MENU
));
1061 DrawIconEx(hMemDC
, 0, 0, hIcon
, cx
, cy
, 0, hBrush
, DI_NORMAL
);
1062 SelectObject (hMemDC
, hOldBitmap
);
1063 DeleteObject(hBrush
);
1065 ReleaseDC(hChild
, hdc
);
1066 hSysMenuBitmap
= hBitmap
;
1071 hSysMenuBitmap
= hBmpClose
;
1073 if( !InsertMenuA(menu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
1074 (UINT_PTR
)hSysPopup
, (LPSTR
)hSysMenuBitmap
))
1076 TRACE("not inserted\n");
1077 DestroyMenu(hSysPopup
);
1081 /* The close button is only present in Win 95 look */
1082 if(TWEAK_WineLook
> WIN31_LOOK
)
1084 AppendMenuA(menu
,MF_HELP
| MF_BITMAP
,
1085 SC_CLOSE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_CLOSE
);
1088 EnableMenuItem(hSysPopup
, SC_SIZE
, MF_BYCOMMAND
| MF_GRAYED
);
1089 EnableMenuItem(hSysPopup
, SC_MOVE
, MF_BYCOMMAND
| MF_GRAYED
);
1090 EnableMenuItem(hSysPopup
, SC_MAXIMIZE
, MF_BYCOMMAND
| MF_GRAYED
);
1091 SetMenuDefaultItem(hSysPopup
, SC_CLOSE
, FALSE
);
1099 /**********************************************************************
1100 * MDI_RestoreFrameMenu
1102 static BOOL
MDI_RestoreFrameMenu( HWND frame
, HWND hChild
)
1104 MENUITEMINFOW menuInfo
;
1105 HMENU menu
= GetMenu( frame
);
1106 INT nItems
= GetMenuItemCount(menu
) - 1;
1107 UINT iId
= GetMenuItemID(menu
,nItems
) ;
1109 TRACE("frame %p,child %p,nIt=%d,iId=%d\n",frame
,hChild
,nItems
,iId
);
1111 if(!(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
1115 * Remove the system menu, If that menu is the icon of the window
1116 * as it is in win95, we have to delete the bitmap.
1118 memset(&menuInfo
, 0, sizeof(menuInfo
));
1119 menuInfo
.cbSize
= sizeof(menuInfo
);
1120 menuInfo
.fMask
= MIIM_DATA
| MIIM_TYPE
;
1122 GetMenuItemInfoW(menu
,
1127 RemoveMenu(menu
,0,MF_BYPOSITION
);
1129 if ( (menuInfo
.fType
& MFT_BITMAP
) &&
1130 (LOWORD(menuInfo
.dwTypeData
)!=0) &&
1131 (LOWORD(menuInfo
.dwTypeData
)!=HBITMAP_16(hBmpClose
)) )
1133 DeleteObject(HBITMAP_32(LOWORD(menuInfo
.dwTypeData
)));
1136 if(TWEAK_WineLook
> WIN31_LOOK
)
1139 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
1142 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
1144 DeleteMenu(menu
,GetMenuItemCount(menu
) - 1,MF_BYPOSITION
);
1152 /**********************************************************************
1153 * MDI_UpdateFrameText
1155 * used when child window is maximized/restored
1157 * Note: lpTitle can be NULL
1159 static void MDI_UpdateFrameText( HWND frame
, HWND hClient
,
1160 BOOL repaint
, LPCWSTR lpTitle
)
1162 WCHAR lpBuffer
[MDI_MAXTITLELENGTH
+1];
1163 MDICLIENTINFO
*ci
= get_client_info( hClient
);
1165 TRACE("repaint %i, frameText %s\n", repaint
, debugstr_w(lpTitle
));
1169 if (!lpTitle
&& !ci
->frameTitle
) /* first time around, get title from the frame window */
1171 GetWindowTextW( frame
, lpBuffer
, sizeof(lpBuffer
)/sizeof(WCHAR
) );
1175 /* store new "default" title if lpTitle is not NULL */
1178 if (ci
->frameTitle
) HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1179 if ((ci
->frameTitle
= HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle
)+1)*sizeof(WCHAR
))))
1180 strcpyW( ci
->frameTitle
, lpTitle
);
1185 if (ci
->hwndChildMaximized
)
1187 /* combine frame title and child title if possible */
1189 static const WCHAR lpBracket
[] = {' ','-',' ','[',0};
1190 static const WCHAR lpBracket2
[] = {']',0};
1191 int i_frame_text_length
= strlenW(ci
->frameTitle
);
1193 lstrcpynW( lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
1195 if( i_frame_text_length
+ 6 < MDI_MAXTITLELENGTH
)
1197 strcatW( lpBuffer
, lpBracket
);
1198 if (GetWindowTextW( ci
->hwndChildMaximized
, lpBuffer
+ i_frame_text_length
+ 4,
1199 MDI_MAXTITLELENGTH
- i_frame_text_length
- 5 ))
1200 strcatW( lpBuffer
, lpBracket2
);
1202 lpBuffer
[i_frame_text_length
] = 0; /* remove bracket */
1207 lstrcpynW(lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
+1 );
1213 DefWindowProcW( frame
, WM_SETTEXT
, 0, (LPARAM
)lpBuffer
);
1214 if( repaint
== MDI_REPAINTFRAME
)
1215 SetWindowPos( frame
, 0,0,0,0,0, SWP_FRAMECHANGED
|
1216 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
1220 /* ----------------------------- Interface ---------------------------- */
1223 /**********************************************************************
1224 * MDIClientWndProc_common
1226 static LRESULT
MDIClientWndProc_common( HWND hwnd
, UINT message
,
1227 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1231 if (!(ci
= get_client_info( hwnd
))) return 0;
1238 /* Since we are using only cs->lpCreateParams, we can safely
1239 * cast to LPCREATESTRUCTA here */
1240 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
1241 WND
*wndPtr
= WIN_GetPtr( hwnd
);
1243 /* Translation layer doesn't know what's in the cs->lpCreateParams
1244 * so we have to keep track of what environment we're in. */
1246 if( wndPtr
->flags
& WIN_ISWIN32
)
1248 #define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1249 ci
->hWindowMenu
= ccs
->hWindowMenu
;
1250 ci
->idFirstChild
= ccs
->idFirstChild
;
1255 LPCLIENTCREATESTRUCT16 ccs
= MapSL((SEGPTR
)cs
->lpCreateParams
);
1256 ci
->hWindowMenu
= HMENU_32(ccs
->hWindowMenu
);
1257 ci
->idFirstChild
= ccs
->idFirstChild
;
1259 WIN_ReleasePtr( wndPtr
);
1261 ci
->hwndChildMaximized
= 0;
1262 ci
->nActiveChildren
= 0;
1263 ci
->nTotalCreated
= 0;
1264 ci
->frameTitle
= NULL
;
1266 SetWindowLongW( hwnd
, GWL_STYLE
, GetWindowLongW(hwnd
,GWL_STYLE
) | WS_CLIPCHILDREN
);
1268 if (!hBmpClose
) hBmpClose
= CreateMDIMenuBitmap();
1270 if (ci
->hWindowMenu
!= 0)
1271 AppendMenuW( ci
->hWindowMenu
, MF_SEPARATOR
, 0, NULL
);
1273 GetClientRect( GetParent(hwnd
), &rect
);
1274 MoveWindow( hwnd
, 0, 0, rect
.right
, rect
.bottom
, FALSE
);
1276 MDI_UpdateFrameText( GetParent(hwnd
), hwnd
, MDI_NOFRAMEREPAINT
, NULL
);
1278 TRACE("Client created - hwnd = %p, idFirst = %u\n", hwnd
, ci
->idFirstChild
);
1285 if( ci
->hwndChildMaximized
)
1286 MDI_RestoreFrameMenu( GetParent(hwnd
), ci
->hwndChildMaximized
);
1287 if((ci
->hWindowMenu
!= 0) &&
1288 (nItems
= GetMenuItemCount(ci
->hWindowMenu
)) > 0)
1290 ci
->idFirstChild
= nItems
- 1;
1291 ci
->nActiveChildren
++; /* to delete a separator */
1292 while( ci
->nActiveChildren
-- )
1293 DeleteMenu(ci
->hWindowMenu
,MF_BYPOSITION
,ci
->idFirstChild
--);
1295 if (ci
->frameTitle
) HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1299 case WM_MDIACTIVATE
:
1300 if( ci
->hwndActiveChild
!= (HWND
)wParam
)
1301 SetWindowPos((HWND
)wParam
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1305 return MDICascade(hwnd
, ci
);
1309 return (LRESULT
)MDICreateChild( hwnd
, ci
, (MDICREATESTRUCTA
*)lParam
, unicode
);
1313 return MDIDestroyChild( hwnd
, ci
, WIN_GetFullHandle( (HWND
)wParam
), TRUE
);
1315 case WM_MDIGETACTIVE
:
1316 if (lParam
) *(BOOL
*)lParam
= (ci
->hwndChildMaximized
!= 0);
1317 return (LRESULT
)ci
->hwndActiveChild
;
1319 case WM_MDIICONARRANGE
:
1320 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1321 ArrangeIconicWindows( hwnd
);
1322 ci
->sbRecalc
= SB_BOTH
+1;
1323 SendMessageW( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0 );
1326 case WM_MDIMAXIMIZE
:
1327 ShowWindow( (HWND
)wParam
, SW_MAXIMIZE
);
1330 case WM_MDINEXT
: /* lParam != 0 means previous window */
1331 MDI_SwitchActiveChild( hwnd
, WIN_GetFullHandle( (HWND
)wParam
), !lParam
);
1335 SendMessageW( (HWND
)wParam
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
1339 return MDISetMenu( hwnd
, (HMENU
)wParam
, (HMENU
)lParam
);
1341 case WM_MDIREFRESHMENU
:
1342 return MDIRefreshMenu( hwnd
, (HMENU
)wParam
, (HMENU
)lParam
);
1345 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1346 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
1347 MDITile( hwnd
, ci
, wParam
);
1348 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1353 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1354 ScrollChildren( hwnd
, message
, wParam
, lParam
);
1355 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1359 if (ci
->hwndActiveChild
&& !IsIconic( ci
->hwndActiveChild
))
1360 SetFocus( ci
->hwndActiveChild
);
1364 if( ci
->hwndActiveChild
)
1365 SendMessageW(ci
->hwndActiveChild
, message
, wParam
, lParam
);
1368 case WM_PARENTNOTIFY
:
1369 if (LOWORD(wParam
) == WM_LBUTTONDOWN
)
1373 pt
.x
= (short)LOWORD(lParam
);
1374 pt
.y
= (short)HIWORD(lParam
);
1375 child
= ChildWindowFromPoint(hwnd
, pt
);
1377 TRACE("notification from %p (%li,%li)\n",child
,pt
.x
,pt
.y
);
1379 if( child
&& child
!= hwnd
&& child
!= ci
->hwndActiveChild
)
1380 SetWindowPos(child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1385 if( IsWindow(ci
->hwndChildMaximized
) )
1391 rect
.right
= LOWORD(lParam
);
1392 rect
.bottom
= HIWORD(lParam
);
1394 AdjustWindowRectEx(&rect
, GetWindowLongA(ci
->hwndChildMaximized
,GWL_STYLE
),
1395 0, GetWindowLongA(ci
->hwndChildMaximized
,GWL_EXSTYLE
) );
1396 MoveWindow(ci
->hwndChildMaximized
, rect
.left
, rect
.top
,
1397 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 1);
1400 MDI_PostUpdate(hwnd
, ci
, SB_BOTH
+1);
1404 case WM_MDICALCCHILDSCROLL
:
1405 if( (ci
->mdiFlags
& MDIF_NEEDUPDATE
) && ci
->sbRecalc
)
1407 CalcChildScroll(hwnd
, ci
->sbRecalc
-1);
1409 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1413 return unicode
? DefWindowProcW( hwnd
, message
, wParam
, lParam
) :
1414 DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1417 /***********************************************************************
1420 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1422 if (!IsWindow(hwnd
)) return 0;
1423 return MDIClientWndProc_common( hwnd
, message
, wParam
, lParam
, FALSE
);
1426 /***********************************************************************
1429 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1431 if (!IsWindow(hwnd
)) return 0;
1432 return MDIClientWndProc_common( hwnd
, message
, wParam
, lParam
, TRUE
);
1435 /***********************************************************************
1436 * DefFrameProcA (USER32.@)
1438 LRESULT WINAPI
DefFrameProcA( HWND hwnd
, HWND hwndMDIClient
,
1439 UINT message
, WPARAM wParam
, LPARAM lParam
)
1447 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, NULL
, 0 );
1448 LPWSTR text
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1449 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, text
, len
);
1450 MDI_UpdateFrameText(hwnd
, hwndMDIClient
, MDI_REPAINTFRAME
, text
);
1451 HeapFree( GetProcessHeap(), 0, text
);
1453 return 1; /* success. FIXME: check text length */
1460 return DefFrameProcW( hwnd
, hwndMDIClient
, message
, wParam
, lParam
);
1463 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1467 /***********************************************************************
1468 * DefFrameProcW (USER32.@)
1470 LRESULT WINAPI
DefFrameProcW( HWND hwnd
, HWND hwndMDIClient
,
1471 UINT message
, WPARAM wParam
, LPARAM lParam
)
1473 MDICLIENTINFO
*ci
= get_client_info( hwndMDIClient
);
1481 WORD id
= LOWORD(wParam
);
1482 /* check for possible syscommands for maximized MDI child */
1483 if (id
< ci
->idFirstChild
|| id
>= ci
->idFirstChild
+ ci
->nActiveChildren
)
1485 if( (id
- 0xf000) & 0xf00f ) break;
1486 if( !ci
->hwndChildMaximized
) break;
1497 return SendMessageW( ci
->hwndChildMaximized
, WM_SYSCOMMAND
,
1504 if (id
- ci
->idFirstChild
== MDI_MOREWINDOWSLIMIT
)
1505 /* User chose "More Windows..." */
1506 childHwnd
= MDI_MoreWindowsDialog(hwndMDIClient
);
1508 /* User chose one of the windows listed in the "Windows" menu */
1509 childHwnd
= MDI_GetChildByID(hwndMDIClient
,id
);
1512 SendMessageW( hwndMDIClient
, WM_MDIACTIVATE
, (WPARAM
)childHwnd
, 0 );
1518 SendMessageW(hwndMDIClient
, message
, wParam
, lParam
);
1522 MDI_UpdateFrameText(hwnd
, hwndMDIClient
, MDI_REPAINTFRAME
, (LPWSTR
)lParam
);
1523 return 1; /* success. FIXME: check text length */
1526 SetFocus(hwndMDIClient
);
1530 MoveWindow(hwndMDIClient
, 0, 0, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1535 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1537 if (!IsIconic(hwnd
) && ci
->hwndActiveChild
&& !ci
->hwndChildMaximized
)
1539 /* control menu is between the frame system menu and
1540 * the first entry of menu bar */
1541 WND
*wndPtr
= WIN_GetPtr(hwnd
);
1543 if( (wParam
== VK_LEFT
&& GetMenu(hwnd
) == next_menu
->hmenuIn
) ||
1544 (wParam
== VK_RIGHT
&& GetSubMenu(wndPtr
->hSysMenu
, 0) == next_menu
->hmenuIn
) )
1546 WIN_ReleasePtr(wndPtr
);
1547 wndPtr
= WIN_GetPtr(ci
->hwndActiveChild
);
1548 next_menu
->hmenuNext
= GetSubMenu(wndPtr
->hSysMenu
, 0);
1549 next_menu
->hwndNext
= ci
->hwndActiveChild
;
1551 WIN_ReleasePtr(wndPtr
);
1558 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1561 /***********************************************************************
1562 * DefMDIChildProcA (USER32.@)
1564 LRESULT WINAPI
DefMDIChildProcA( HWND hwnd
, UINT message
,
1565 WPARAM wParam
, LPARAM lParam
)
1567 HWND client
= GetParent(hwnd
);
1568 MDICLIENTINFO
*ci
= get_client_info( client
);
1570 hwnd
= WIN_GetFullHandle( hwnd
);
1571 if (!ci
) return DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1576 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1577 MDI_MenuModifyItem( client
, hwnd
);
1578 if( ci
->hwndChildMaximized
== hwnd
)
1579 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1580 return 1; /* success. FIXME: check text length */
1582 case WM_GETMINMAXINFO
:
1586 case WM_CHILDACTIVATE
:
1592 return DefMDIChildProcW( hwnd
, message
, wParam
, lParam
);
1594 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1598 /***********************************************************************
1599 * DefMDIChildProcW (USER32.@)
1601 LRESULT WINAPI
DefMDIChildProcW( HWND hwnd
, UINT message
,
1602 WPARAM wParam
, LPARAM lParam
)
1604 HWND client
= GetParent(hwnd
);
1605 MDICLIENTINFO
*ci
= get_client_info( client
);
1607 hwnd
= WIN_GetFullHandle( hwnd
);
1608 if (!ci
) return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1613 DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1614 MDI_MenuModifyItem( client
, hwnd
);
1615 if( ci
->hwndChildMaximized
== hwnd
)
1616 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1617 return 1; /* success. FIXME: check text length */
1619 case WM_GETMINMAXINFO
:
1620 MDI_ChildGetMinMaxInfo( client
, hwnd
, (MINMAXINFO
*)lParam
);
1624 return 0x00010000; /* MDI children don't have menu bars */
1627 SendMessageW( client
, WM_MDIDESTROY
, (WPARAM
)hwnd
, 0 );
1631 if (ci
->hwndActiveChild
!= hwnd
) MDI_ChildActivate( client
, hwnd
);
1634 case WM_CHILDACTIVATE
:
1635 MDI_ChildActivate( client
, hwnd
);
1642 if( ci
->hwndChildMaximized
== hwnd
) return 0;
1646 SetWindowLongW( hwnd
, GWL_STYLE
,
1647 GetWindowLongW( hwnd
, GWL_STYLE
) | WS_SYSMENU
);
1650 if (ci
->hwndChildMaximized
== hwnd
)
1651 return SendMessageW( GetParent(client
), message
, wParam
, lParam
);
1652 SetWindowLongW( hwnd
, GWL_STYLE
,
1653 GetWindowLongW( hwnd
, GWL_STYLE
) & ~WS_SYSMENU
);
1656 SendMessageW( client
, WM_MDINEXT
, 0, 0);
1659 SendMessageW( client
, WM_MDINEXT
, 0, 1);
1665 if( ci
->hwndChildMaximized
) ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1666 else MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1670 if( ci
->hwndActiveChild
== hwnd
&& wParam
!= SIZE_MAXIMIZED
)
1672 ci
->hwndChildMaximized
= 0;
1673 MDI_RestoreFrameMenu( GetParent(client
), hwnd
);
1674 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1677 if( wParam
== SIZE_MAXIMIZED
)
1679 HWND hMaxChild
= ci
->hwndChildMaximized
;
1681 if( hMaxChild
== hwnd
) break;
1684 SendMessageW( hMaxChild
, WM_SETREDRAW
, FALSE
, 0 );
1685 MDI_RestoreFrameMenu( GetParent(client
), hMaxChild
);
1686 ShowWindow( hMaxChild
, SW_SHOWNOACTIVATE
);
1687 SendMessageW( hMaxChild
, WM_SETREDRAW
, TRUE
, 0 );
1689 TRACE("maximizing child %p\n", hwnd
);
1691 /* keep track of the maximized window. */
1692 ci
->hwndChildMaximized
= hwnd
; /* !!! */
1694 /* The maximized window should also be the active window */
1695 MDI_ChildActivate( client
, hwnd
);
1696 MDI_AugmentFrameMenu( GetParent(client
), hwnd
);
1697 MDI_UpdateFrameText( GetParent(client
), client
, MDI_REPAINTFRAME
, NULL
);
1700 if( wParam
== SIZE_MINIMIZED
)
1702 HWND switchTo
= MDI_GetWindow(ci
, hwnd
, TRUE
, WS_MINIMIZE
);
1704 if (switchTo
) SendMessageW( switchTo
, WM_CHILDACTIVATE
, 0, 0);
1706 MDI_PostUpdate(client
, ci
, SB_BOTH
+1);
1711 MDINEXTMENU
*next_menu
= (MDINEXTMENU
*)lParam
;
1712 HWND parent
= GetParent(client
);
1714 if( wParam
== VK_LEFT
) /* switch to frame system menu */
1716 WND
*wndPtr
= WIN_GetPtr( parent
);
1717 next_menu
->hmenuNext
= GetSubMenu( wndPtr
->hSysMenu
, 0 );
1718 WIN_ReleasePtr( wndPtr
);
1720 if( wParam
== VK_RIGHT
) /* to frame menu bar */
1722 next_menu
->hmenuNext
= GetMenu(parent
);
1724 next_menu
->hwndNext
= parent
;
1731 SendMessageW( hwnd
, WM_SYSCOMMAND
, (WPARAM
)SC_KEYMENU
, (DWORD
)VK_SPACE
);
1736 return DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1739 /**********************************************************************
1740 * CreateMDIWindowA (USER32.@) Creates a MDI child
1743 * Success: Handle to created window
1746 HWND WINAPI
CreateMDIWindowA(
1747 LPCSTR lpClassName
, /* [in] Pointer to registered child class name */
1748 LPCSTR lpWindowName
, /* [in] Pointer to window name */
1749 DWORD dwStyle
, /* [in] Window style */
1750 INT X
, /* [in] Horizontal position of window */
1751 INT Y
, /* [in] Vertical position of window */
1752 INT nWidth
, /* [in] Width of window */
1753 INT nHeight
, /* [in] Height of window */
1754 HWND hWndParent
, /* [in] Handle to parent window */
1755 HINSTANCE hInstance
, /* [in] Handle to application instance */
1756 LPARAM lParam
) /* [in] Application-defined value */
1758 MDICLIENTINFO
*pCi
= get_client_info( hWndParent
);
1759 MDICREATESTRUCTA cs
;
1761 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%p,%p,%ld)\n",
1762 debugstr_a(lpClassName
),debugstr_a(lpWindowName
),dwStyle
,X
,Y
,
1763 nWidth
,nHeight
,hWndParent
,hInstance
,lParam
);
1767 ERR("bad hwnd for MDI-client: %p\n", hWndParent
);
1770 cs
.szClass
=lpClassName
;
1771 cs
.szTitle
=lpWindowName
;
1772 cs
.hOwner
=hInstance
;
1780 return MDICreateChild(hWndParent
, pCi
, &cs
, FALSE
);
1783 /***********************************************************************
1784 * CreateMDIWindowW (USER32.@) Creates a MDI child
1787 * Success: Handle to created window
1790 HWND WINAPI
CreateMDIWindowW(
1791 LPCWSTR lpClassName
, /* [in] Pointer to registered child class name */
1792 LPCWSTR lpWindowName
, /* [in] Pointer to window name */
1793 DWORD dwStyle
, /* [in] Window style */
1794 INT X
, /* [in] Horizontal position of window */
1795 INT Y
, /* [in] Vertical position of window */
1796 INT nWidth
, /* [in] Width of window */
1797 INT nHeight
, /* [in] Height of window */
1798 HWND hWndParent
, /* [in] Handle to parent window */
1799 HINSTANCE hInstance
, /* [in] Handle to application instance */
1800 LPARAM lParam
) /* [in] Application-defined value */
1802 MDICLIENTINFO
*pCi
= get_client_info( hWndParent
);
1803 MDICREATESTRUCTW cs
;
1805 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%p,%p,%ld)\n",
1806 debugstr_w(lpClassName
), debugstr_w(lpWindowName
), dwStyle
, X
, Y
,
1807 nWidth
, nHeight
, hWndParent
, hInstance
, lParam
);
1811 ERR("bad hwnd for MDI-client: %p\n", hWndParent
);
1814 cs
.szClass
= lpClassName
;
1815 cs
.szTitle
= lpWindowName
;
1816 cs
.hOwner
= hInstance
;
1824 return MDICreateChild(hWndParent
, pCi
, (MDICREATESTRUCTA
*)&cs
, TRUE
);
1827 /**********************************************************************
1828 * TranslateMDISysAccel (USER32.@)
1830 BOOL WINAPI
TranslateMDISysAccel( HWND hwndClient
, LPMSG msg
)
1832 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
)
1834 MDICLIENTINFO
*ci
= get_client_info( hwndClient
);
1837 if (!ci
|| !IsWindowEnabled(ci
->hwndActiveChild
)) return 0;
1839 /* translate if the Ctrl key is down and Alt not. */
1841 if( (GetKeyState(VK_CONTROL
) & 0x8000) && !(GetKeyState(VK_MENU
) & 0x8000))
1843 switch( msg
->wParam
)
1847 wParam
= ( GetKeyState(VK_SHIFT
) & 0x8000 ) ? SC_NEXTWINDOW
: SC_PREVWINDOW
;
1856 TRACE("wParam = %04x\n", wParam
);
1857 SendMessageW(ci
->hwndActiveChild
, WM_SYSCOMMAND
, wParam
, (LPARAM
)msg
->wParam
);
1861 return 0; /* failure */
1864 /***********************************************************************
1865 * CalcChildScroll (USER32.@)
1867 void WINAPI
CalcChildScroll( HWND hwnd
, INT scroll
)
1870 RECT childRect
, clientRect
;
1873 GetClientRect( hwnd
, &clientRect
);
1874 SetRectEmpty( &childRect
);
1876 if ((list
= WIN_ListChildren( hwnd
)))
1879 for (i
= 0; list
[i
]; i
++)
1881 DWORD style
= GetWindowLongW( list
[i
], GWL_STYLE
);
1882 if (style
& WS_MAXIMIZE
)
1884 HeapFree( GetProcessHeap(), 0, list
);
1885 ShowScrollBar( hwnd
, SB_BOTH
, FALSE
);
1888 if (style
& WS_VISIBLE
)
1890 WND
*pWnd
= WIN_FindWndPtr( list
[i
] );
1891 UnionRect( &childRect
, &pWnd
->rectWindow
, &childRect
);
1892 WIN_ReleaseWndPtr( pWnd
);
1895 HeapFree( GetProcessHeap(), 0, list
);
1897 UnionRect( &childRect
, &clientRect
, &childRect
);
1899 /* set common info values */
1900 info
.cbSize
= sizeof(info
);
1901 info
.fMask
= SIF_POS
| SIF_RANGE
;
1903 /* set the specific */
1908 info
.nMin
= childRect
.left
;
1909 info
.nMax
= childRect
.right
- clientRect
.right
;
1910 info
.nPos
= clientRect
.left
- childRect
.left
;
1911 SetScrollInfo(hwnd
, scroll
, &info
, TRUE
);
1912 if (scroll
== SB_HORZ
) break;
1915 info
.nMin
= childRect
.top
;
1916 info
.nMax
= childRect
.bottom
- clientRect
.bottom
;
1917 info
.nPos
= clientRect
.top
- childRect
.top
;
1918 SetScrollInfo(hwnd
, scroll
, &info
, TRUE
);
1924 /***********************************************************************
1925 * ScrollChildren (USER32.@)
1927 void WINAPI
ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
,
1931 INT curPos
, length
, minPos
, maxPos
, shift
;
1934 GetClientRect( hWnd
, &rect
);
1939 GetScrollRange(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
1940 curPos
= GetScrollPos(hWnd
,SB_HORZ
);
1941 length
= (rect
.right
- rect
.left
) / 2;
1942 shift
= GetSystemMetrics(SM_CYHSCROLL
);
1945 GetScrollRange(hWnd
,SB_VERT
,&minPos
,&maxPos
);
1946 curPos
= GetScrollPos(hWnd
,SB_VERT
);
1947 length
= (rect
.bottom
- rect
.top
) / 2;
1948 shift
= GetSystemMetrics(SM_CXVSCROLL
);
1957 newPos
= curPos
- shift
;
1960 newPos
= curPos
+ shift
;
1963 newPos
= curPos
- length
;
1966 newPos
= curPos
+ length
;
1969 case SB_THUMBPOSITION
:
1970 newPos
= LOWORD(lParam
);
1983 CalcChildScroll(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
1987 if( newPos
> maxPos
)
1990 if( newPos
< minPos
)
1993 SetScrollPos(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
1995 if( uMsg
== WM_VSCROLL
)
1996 ScrollWindowEx(hWnd
,0 ,curPos
- newPos
, NULL
, NULL
, 0, NULL
,
1997 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
1999 ScrollWindowEx(hWnd
,curPos
- newPos
, 0, NULL
, NULL
, 0, NULL
,
2000 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
2004 /******************************************************************************
2005 * CascadeWindows (USER32.@) Cascades MDI child windows
2008 * Success: Number of cascaded windows.
2012 CascadeWindows (HWND hwndParent
, UINT wFlags
, const LPRECT lpRect
,
2013 UINT cKids
, const HWND
*lpKids
)
2015 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
2020 /******************************************************************************
2021 * TileWindows (USER32.@) Tiles MDI child windows
2024 * Success: Number of tiled windows.
2028 TileWindows (HWND hwndParent
, UINT wFlags
, const LPRECT lpRect
,
2029 UINT cKids
, const HWND
*lpKids
)
2031 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent
, wFlags
, cKids
);
2035 /************************************************************************
2036 * "More Windows..." functionality
2039 /* MDI_MoreWindowsDlgProc
2041 * This function will process the messages sent to the "More Windows..."
2043 * Return values: 0 = cancel pressed
2044 * HWND = ok pressed or double-click in the list...
2048 static INT_PTR WINAPI
MDI_MoreWindowsDlgProc (HWND hDlg
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
2057 MDICLIENTINFO
*ci
= get_client_info( (HWND
)lParam
);
2058 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2059 HWND
*list
, *sorted_list
;
2061 if (!(list
= WIN_ListChildren( (HWND
)lParam
))) return TRUE
;
2062 if (!(sorted_list
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
2063 sizeof(HWND
) * ci
->nActiveChildren
)))
2065 HeapFree( GetProcessHeap(), 0, list
);
2069 /* Fill the list, sorted by id... */
2070 for (i
= 0; list
[i
]; i
++)
2072 UINT id
= GetWindowLongW( list
[i
], GWL_ID
) - ci
->idFirstChild
;
2073 if (id
< ci
->nActiveChildren
) sorted_list
[id
] = list
[i
];
2075 HeapFree( GetProcessHeap(), 0, list
);
2077 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
2081 if (!GetWindowTextW( sorted_list
[i
], buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
2083 SendMessageW(hListBox
, LB_ADDSTRING
, 0, (LPARAM
)buffer
);
2084 SendMessageW(hListBox
, LB_SETITEMDATA
, i
, (LPARAM
)sorted_list
[i
] );
2085 length
= strlenW(buffer
); /* FIXME: should use GetTextExtentPoint */
2086 if (length
> widest
)
2089 /* Make sure the horizontal scrollbar scrolls ok */
2090 SendMessageW(hListBox
, LB_SETHORIZONTALEXTENT
, widest
* 6, 0);
2092 /* Set the current selection */
2093 SendMessageW(hListBox
, LB_SETCURSEL
, MDI_MOREWINDOWSLIMIT
, 0);
2098 switch (LOWORD(wParam
))
2101 if (HIWORD(wParam
) != LBN_DBLCLK
) break;
2105 /* windows are sorted by menu ID, so we must return the
2106 * window associated to the given id
2108 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2109 UINT index
= SendMessageW(hListBox
, LB_GETCURSEL
, 0, 0);
2110 LRESULT res
= SendMessageW(hListBox
, LB_GETITEMDATA
, index
, 0);
2111 EndDialog(hDlg
, res
);
2125 * MDI_MoreWindowsDialog
2127 * Prompts the user with a listbox containing the opened
2128 * documents. The user can then choose a windows and click
2129 * on OK to set the current window to the one selected, or
2130 * CANCEL to cancel. The function returns a handle to the
2134 static HWND
MDI_MoreWindowsDialog(HWND hwnd
)
2140 hRes
= FindResourceA(GetModuleHandleA("USER32"), "MDI_MOREWINDOWS", (LPSTR
)RT_DIALOG
);
2145 hDlgTmpl
= LoadResource(GetModuleHandleA("USER32"), hRes
);
2150 template = LockResource( hDlgTmpl
);
2155 return (HWND
) DialogBoxIndirectParamA(GetModuleHandleA("USER32"),
2156 (LPDLGTEMPLATEA
) template,
2157 hwnd
, MDI_MoreWindowsDlgProc
, (LPARAM
) hwnd
);
2164 * Will swap the menu IDs for the given 2 positions.
2165 * pos1 and pos2 are menu IDs
2170 static void MDI_SwapMenuItems(HWND parent
, UINT pos1
, UINT pos2
)
2175 if (!(list
= WIN_ListChildren( parent
))) return;
2176 for (i
= 0; list
[i
]; i
++)
2178 UINT id
= GetWindowLongW( list
[i
], GWL_ID
);
2179 if (id
== pos1
) SetWindowLongW( list
[i
], GWL_ID
, pos2
);
2180 else if (id
== pos2
) SetWindowLongW( list
[i
], GWL_ID
, pos1
);
2182 HeapFree( GetProcessHeap(), 0, list
);