3 * Copyright 1994, Bob Amstadt
4 * 1995,1996 Alex Korobka
6 * This file contains routines to support MDI (Multiple Document
7 * Interface) features .
9 * Notes: Fairly complete implementation.
10 * Also, Excel and WinWord do _not_ use MDI so if you're trying
11 * to fix them look elsewhere.
13 * Notes on how the "More Windows..." is implemented:
15 * When we have more than 9 opened windows, a "More Windows..."
16 * option appears in the "Windows" menu. Each child window has
17 * a WND* associated with it, accesible via the children list of
18 * the parent window. This WND* has a wIDmenu member, which reflects
19 * the position of the child in the window list. For example, with
20 * 9 child windows, we could have the following pattern:
24 * Name of the child window pWndChild->wIDmenu
36 * The "Windows" menu, as the "More windows..." dialog, are constructed
37 * in this order. If we add a child, we would have the following list:
40 * Name of the child window pWndChild->wIDmenu
52 * But only 5000 to 5008 would be displayed in the "Windows" menu. We want
53 * the last created child to be in the menu, so we swap the last child with
54 * the 9th... Doc9 will be accessible via the "More Windows..." option.
78 #include "wine/unicode.h"
81 #include "nonclient.h"
86 #include "debugtools.h"
89 DEFAULT_DEBUG_CHANNEL(mdi
);
91 #define MDI_MAXLISTLENGTH 0x40
92 #define MDI_MAXTITLELENGTH 0xa1
94 #define MDI_NOFRAMEREPAINT 0
95 #define MDI_REPAINTFRAMENOW 1
96 #define MDI_REPAINTFRAME 2
98 #define WM_MDICALCCHILDSCROLL 0x10ac /* this is exactly what Windows uses */
100 /* "More Windows..." definitions */
101 #define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
102 option will appear under the Windows menu */
103 #define MDI_IDC_LISTBOX 100
104 #define MDI_IDS_MOREWINDOWS 13
106 #define MDIF_NEEDUPDATE 0x0001
110 UINT nActiveChildren
;
111 HWND hwndChildMaximized
;
112 HWND hwndActiveChild
;
118 UINT sbRecalc
; /* SB_xxx flags for scrollbar fixup */
122 static HBITMAP16 hBmpClose
= 0;
123 static HBITMAP16 hBmpRestore
= 0;
125 /* ----------------- declarations ----------------- */
126 static void MDI_UpdateFrameText(WND
*, HWND
, BOOL
, LPCWSTR
);
127 static BOOL
MDI_AugmentFrameMenu(MDICLIENTINFO
*, WND
*, HWND
);
128 static BOOL
MDI_RestoreFrameMenu(WND
*, HWND
);
130 static LONG
MDI_ChildActivate( WND
*, HWND
);
132 static HWND
MDI_MoreWindowsDialog(WND
*);
133 static void MDI_SwapMenuItems(WND
*, UINT
, UINT
);
134 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
135 /* -------- Miscellaneous service functions ----------
140 static HWND
MDI_GetChildByID(WND
* wndPtr
, INT id
)
142 for (wndPtr
= wndPtr
->child
; wndPtr
; wndPtr
= wndPtr
->next
)
143 if (wndPtr
->wIDmenu
== id
) return wndPtr
->hwndSelf
;
147 static void MDI_PostUpdate(HWND hwnd
, MDICLIENTINFO
* ci
, WORD recalc
)
149 if( !(ci
->mdiFlags
& MDIF_NEEDUPDATE
) )
151 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
152 PostMessageA( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0);
154 ci
->sbRecalc
= recalc
;
158 /*********************************************************************
159 * MDIClient class descriptor
161 const struct builtin_class_descr MDICLIENT_builtin_class
=
163 "MDIClient", /* name */
164 CS_GLOBALCLASS
, /* style */
165 MDIClientWndProcA
, /* procA */
166 NULL
, /* procW (FIXME) */
167 sizeof(MDICLIENTINFO
), /* extra */
168 IDC_ARROWA
, /* cursor */
169 COLOR_APPWORKSPACE
+1 /* brush */
173 /**********************************************************************
176 static BOOL
MDI_MenuModifyItem(WND
* clientWnd
, HWND hWndChild
)
179 static const WCHAR format
[] = {'%','d',' ',0};
180 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
181 WND
*wndPtr
= WIN_FindWndPtr(hWndChild
);
182 UINT n
= wsprintfW(buffer
, format
,
183 wndPtr
->wIDmenu
- clientInfo
->idFirstChild
+ 1);
186 if( !clientInfo
->hWindowMenu
)
192 if (wndPtr
->text
) lstrcpynW(buffer
+ n
, wndPtr
->text
, sizeof(buffer
)/sizeof(WCHAR
) - n
);
194 n
= GetMenuState(clientInfo
->hWindowMenu
,wndPtr
->wIDmenu
,MF_BYCOMMAND
);
195 bRet
= ModifyMenuW(clientInfo
->hWindowMenu
, wndPtr
->wIDmenu
,
196 MF_BYCOMMAND
| MF_STRING
, wndPtr
->wIDmenu
, buffer
);
197 CheckMenuItem(clientInfo
->hWindowMenu
,wndPtr
->wIDmenu
, n
& MF_CHECKED
);
199 WIN_ReleaseWndPtr(wndPtr
);
203 /**********************************************************************
206 static BOOL
MDI_MenuDeleteItem(WND
* clientWnd
, HWND hWndChild
)
209 static const WCHAR format
[] = {'&','%','d',' ',0};
210 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
211 WND
*wndPtr
= WIN_FindWndPtr(hWndChild
);
215 if( !clientInfo
->nActiveChildren
||
216 !clientInfo
->hWindowMenu
)
222 id
= wndPtr
->wIDmenu
;
223 DeleteMenu(clientInfo
->hWindowMenu
,id
,MF_BYCOMMAND
);
225 /* walk the rest of MDI children to prevent gaps in the id
226 * sequence and in the menu child list */
228 for( index
= id
+1; index
<= clientInfo
->nActiveChildren
+
229 clientInfo
->idFirstChild
; index
++ )
231 WND
*tmpWnd
= WIN_FindWndPtr(MDI_GetChildByID(clientWnd
,index
));
234 TRACE("no window for id=%i\n",index
);
235 WIN_ReleaseWndPtr(tmpWnd
);
242 n
= wsprintfW(buffer
, format
,index
- clientInfo
->idFirstChild
);
244 lstrcpynW(buffer
+ n
, tmpWnd
->text
, sizeof(buffer
)/sizeof(WCHAR
) - n
);
246 /* change menu if the current child is to be shown in the
249 if (index
<= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
)
250 ModifyMenuW(clientInfo
->hWindowMenu
,index
,MF_BYCOMMAND
| MF_STRING
,
251 index
- 1 , buffer
);
252 WIN_ReleaseWndPtr(tmpWnd
);
255 /* We must restore the "More Windows..." option if there is enough child
257 if (clientInfo
->nActiveChildren
- 1 > MDI_MOREWINDOWSLIMIT
)
260 LoadStringA(GetModuleHandleA("USER32"), MDI_IDS_MOREWINDOWS
, szTmp
, 50);
262 AppendMenuA(clientInfo
->hWindowMenu
,MF_STRING
,clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
, szTmp
);
266 WIN_ReleaseWndPtr(wndPtr
);
270 /**********************************************************************
273 * returns "activateable" child different from the current or zero
275 static HWND
MDI_GetWindow(WND
*clientWnd
, HWND hWnd
, BOOL bNext
,
278 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
279 WND
*wndPtr
, *pWnd
, *pWndLast
= NULL
;
281 dwStyleMask
|= WS_DISABLED
| WS_VISIBLE
;
282 if( !hWnd
) hWnd
= clientInfo
->hwndActiveChild
;
284 if( !(wndPtr
= WIN_FindWndPtr(hWnd
)) ) return 0;
286 for ( pWnd
= WIN_LockWndPtr(wndPtr
->next
); ; WIN_UpdateWndPtr(&pWnd
,pWnd
->next
))
288 if (!pWnd
) WIN_UpdateWndPtr(&pWnd
,wndPtr
->parent
->child
);
290 if ( pWnd
== wndPtr
) break; /* went full circle */
292 if (!pWnd
->owner
&& (pWnd
->dwStyle
& dwStyleMask
) == WS_VISIBLE
)
298 WIN_ReleaseWndPtr(wndPtr
);
299 WIN_ReleaseWndPtr(pWnd
);
300 return pWndLast
? pWndLast
->hwndSelf
: 0;
303 /**********************************************************************
304 * MDI_CalcDefaultChildPos
306 * It seems that the default height is about 2/3 of the client rect
308 static void MDI_CalcDefaultChildPos( WND
* w
, WORD n
, LPPOINT lpPos
,
312 RECT rect
= w
->rectClient
;
313 INT spacing
= GetSystemMetrics(SM_CYCAPTION
) +
314 GetSystemMetrics(SM_CYFRAME
) - 1;
316 if( rect
.bottom
- rect
.top
- delta
>= spacing
)
317 rect
.bottom
-= delta
;
319 nstagger
= (rect
.bottom
- rect
.top
)/(3 * spacing
);
320 lpPos
[1].x
= (rect
.right
- rect
.left
- nstagger
* spacing
);
321 lpPos
[1].y
= (rect
.bottom
- rect
.top
- nstagger
* spacing
);
322 lpPos
[0].x
= lpPos
[0].y
= spacing
* (n
%(nstagger
+1));
325 /**********************************************************************
328 static LRESULT
MDISetMenu( HWND hwnd
, HMENU hmenuFrame
,
333 HWND hwndFrame
= GetParent(hwnd
);
334 HMENU oldFrameMenu
= GetMenu(hwndFrame
);
336 TRACE("%04x %04x %04x\n",
337 hwnd
, hmenuFrame
, hmenuWindow
);
339 if (hmenuFrame
&& !IsMenu(hmenuFrame
))
341 WARN("hmenuFrame is not a menu handle\n");
345 if (hmenuWindow
&& !IsMenu(hmenuWindow
))
347 WARN("hmenuWindow is not a menu handle\n");
351 w
= WIN_FindWndPtr(hwnd
);
352 ci
= (MDICLIENTINFO
*) w
->wExtra
;
354 if( ci
->hwndChildMaximized
&& hmenuFrame
&& hmenuFrame
!=oldFrameMenu
)
355 MDI_RestoreFrameMenu(w
->parent
, ci
->hwndChildMaximized
);
357 if( hmenuWindow
&& ci
->hWindowMenu
&& hmenuWindow
!=ci
->hWindowMenu
)
359 /* delete menu items from ci->hWindowMenu
360 * and add them to hmenuWindow */
362 INT i
= GetMenuItemCount(ci
->hWindowMenu
) - 1;
363 INT pos
= GetMenuItemCount(hmenuWindow
) + 1;
365 AppendMenuA( hmenuWindow
, MF_SEPARATOR
, 0, NULL
);
367 if( ci
->nActiveChildren
)
370 LPWSTR buffer
= NULL
;
372 INT nbWindowsMenuItems
; /* num of documents shown + "More Windows..." if present */
374 if (ci
->nActiveChildren
<= MDI_MOREWINDOWSLIMIT
)
375 nbWindowsMenuItems
= ci
->nActiveChildren
;
377 nbWindowsMenuItems
= MDI_MOREWINDOWSLIMIT
+ 1;
379 j
= i
- nbWindowsMenuItems
+ 1;
381 for( ; i
>= j
; i
-- )
383 memset(&mii
, 0, sizeof(mii
));
384 mii
.cbSize
= sizeof(mii
);
385 mii
.fMask
= MIIM_CHECKMARKS
| MIIM_DATA
| MIIM_ID
| MIIM_STATE
386 | MIIM_SUBMENU
| MIIM_TYPE
| MIIM_BITMAP
;
388 GetMenuItemInfoW(ci
->hWindowMenu
, i
, TRUE
, &mii
);
389 if(mii
.cch
) { /* Menu is MFT_STRING */
390 mii
.cch
++; /* add room for '\0' */
391 buffer
= HeapAlloc(GetProcessHeap(), 0,
392 mii
.cch
* sizeof(WCHAR
));
393 mii
.dwTypeData
= buffer
;
394 GetMenuItemInfoW(ci
->hWindowMenu
, i
, TRUE
, &mii
);
396 DeleteMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
397 InsertMenuItemW(hmenuWindow
, pos
, TRUE
, &mii
);
399 HeapFree(GetProcessHeap(), 0, buffer
);
405 /* remove separator */
406 DeleteMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
408 ci
->hWindowMenu
= hmenuWindow
;
413 SetMenu(hwndFrame
, hmenuFrame
);
414 if( hmenuFrame
!=oldFrameMenu
)
416 if( ci
->hwndChildMaximized
)
417 MDI_AugmentFrameMenu(ci
, w
->parent
, ci
->hwndChildMaximized
);
418 WIN_ReleaseWndPtr(w
);
424 INT nItems
= GetMenuItemCount(w
->parent
->wIDmenu
) - 1;
425 UINT iId
= GetMenuItemID(w
->parent
->wIDmenu
,nItems
) ;
427 if( !(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
429 /* SetMenu() may already have been called, meaning that this window
430 * already has its menu. But they may have done a SetMenu() on
431 * an MDI window, and called MDISetMenu() after the fact, meaning
432 * that the "if" to this "else" wouldn't catch the need to
433 * augment the frame menu.
435 if( ci
->hwndChildMaximized
)
436 MDI_AugmentFrameMenu(ci
, w
->parent
, ci
->hwndChildMaximized
);
439 WIN_ReleaseWndPtr(w
);
443 /**********************************************************************
446 static LRESULT
MDIRefreshMenu( HWND hwnd
, HMENU hmenuFrame
,
449 HWND hwndFrame
= GetParent(hwnd
);
450 HMENU oldFrameMenu
= GetMenu(hwndFrame
);
452 TRACE("%04x %04x %04x\n",
453 hwnd
, hmenuFrame
, hmenuWindow
);
455 FIXME("partially function stub\n");
461 /* ------------------ MDI child window functions ---------------------- */
464 /**********************************************************************
467 static HWND
MDICreateChild( WND
*w
, MDICLIENTINFO
*ci
, HWND parent
,
468 LPMDICREATESTRUCTA cs
)
471 DWORD style
= cs
->style
| (WS_CHILD
| WS_CLIPSIBLINGS
);
472 HWND hwnd
, hwndMax
= 0;
473 WORD wIDmenu
= ci
->idFirstChild
+ ci
->nActiveChildren
;
474 char lpstrDef
[]="junk!";
476 TRACE("origin %i,%i - dim %i,%i, style %08lx\n",
477 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, cs
->style
);
478 /* calculate placement */
479 MDI_CalcDefaultChildPos(w
, ci
->nTotalCreated
++, pos
, 0);
481 if (cs
->cx
== CW_USEDEFAULT
|| !cs
->cx
) cs
->cx
= pos
[1].x
;
482 if (cs
->cy
== CW_USEDEFAULT
|| !cs
->cy
) cs
->cy
= pos
[1].y
;
484 if( cs
->x
== CW_USEDEFAULT
)
490 /* restore current maximized child */
491 if( (style
& WS_VISIBLE
) && ci
->hwndChildMaximized
)
493 TRACE("Restoring current maximized child %04x\n", ci
->hwndChildMaximized
);
494 if( style
& WS_MAXIMIZE
)
495 SendMessageA(w
->hwndSelf
, WM_SETREDRAW
, FALSE
, 0L );
496 hwndMax
= ci
->hwndChildMaximized
;
497 ShowWindow( hwndMax
, SW_SHOWNOACTIVATE
);
498 if( style
& WS_MAXIMIZE
)
499 SendMessageA(w
->hwndSelf
, WM_SETREDRAW
, TRUE
, 0L );
502 if (ci
->nActiveChildren
<= MDI_MOREWINDOWSLIMIT
)
503 /* this menu is needed to set a check mark in MDI_ChildActivate */
504 if (ci
->hWindowMenu
!= 0)
505 AppendMenuA(ci
->hWindowMenu
,MF_STRING
,wIDmenu
, lpstrDef
);
507 ci
->nActiveChildren
++;
509 /* fix window style */
510 if( !(w
->dwStyle
& MDIS_ALLCHILDSTYLES
) )
512 TRACE("MDIS_ALLCHILDSTYLES is missing, fixing window style\n");
513 style
&= (WS_CHILD
| WS_CLIPSIBLINGS
| WS_MINIMIZE
| WS_MAXIMIZE
|
514 WS_CLIPCHILDREN
| WS_DISABLED
| WS_VSCROLL
| WS_HSCROLL
);
515 style
|= (WS_VISIBLE
| WS_OVERLAPPEDWINDOW
);
518 if( w
->flags
& WIN_ISWIN32
)
520 hwnd
= CreateWindowA( cs
->szClass
, cs
->szTitle
, style
,
521 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, parent
,
522 (HMENU
)wIDmenu
, cs
->hOwner
, cs
);
526 MDICREATESTRUCT16
*cs16
;
529 cs16
= SEGPTR_NEW(MDICREATESTRUCT16
);
530 STRUCT32_MDICREATESTRUCT32Ato16( cs
, cs16
);
531 title
= SEGPTR_STRDUP( cs
->szTitle
);
532 cls
= SEGPTR_STRDUP( cs
->szClass
);
533 cs16
->szTitle
= SEGPTR_GET(title
);
534 cs16
->szClass
= SEGPTR_GET(cls
);
536 hwnd
= CreateWindow16( cs
->szClass
, cs
->szTitle
, style
,
537 cs16
->x
, cs16
->y
, cs16
->cx
, cs16
->cy
, parent
,
538 (HMENU
)wIDmenu
, cs16
->hOwner
,
539 (LPVOID
)SEGPTR_GET(cs16
) );
540 SEGPTR_FREE( title
);
545 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
549 WND
* wnd
= WIN_FindWndPtr( hwnd
);
551 /* All MDI child windows have the WS_EX_MDICHILD style */
552 wnd
->dwExStyle
|= WS_EX_MDICHILD
;
554 /* If we have more than 9 windows, we must insert the new one at the
555 * 9th position in order to see it in the "Windows" menu
557 if (ci
->nActiveChildren
> MDI_MOREWINDOWSLIMIT
)
558 MDI_SwapMenuItems(wnd
->parent
, wnd
->wIDmenu
, ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1);
560 MDI_MenuModifyItem(w
,hwnd
);
562 /* Have we hit the "More Windows..." limit? If so, we must
563 * add a "More Windows..." option
565 if (ci
->nActiveChildren
== MDI_MOREWINDOWSLIMIT
+ 1)
568 LoadStringA(GetModuleHandleA("USER32"), MDI_IDS_MOREWINDOWS
, szTmp
, 50);
570 ModifyMenuA(ci
->hWindowMenu
,
571 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
,
572 MF_BYCOMMAND
| MF_STRING
,
573 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
,
577 if( (wnd
->dwStyle
& WS_MINIMIZE
) && ci
->hwndActiveChild
)
579 TRACE("Minimizing created MDI child %04x\n", hwnd
);
580 ShowWindow( hwnd
, SW_SHOWMINNOACTIVE
);
584 /* WS_VISIBLE is clear if a) the MDI client has
585 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
586 * MDICreateStruct. If so the created window is not shown nor
589 if(wnd
->dwStyle
& WS_VISIBLE
)
590 ShowWindow(hwnd
, SW_SHOW
);
592 WIN_ReleaseWndPtr(wnd
);
593 TRACE("created child - %04x\n",hwnd
);
597 ci
->nActiveChildren
--;
598 DeleteMenu(ci
->hWindowMenu
,wIDmenu
,MF_BYCOMMAND
);
599 if( IsWindow(hwndMax
) )
600 ShowWindow(hwndMax
, SW_SHOWMAXIMIZED
);
606 /**********************************************************************
607 * MDI_ChildGetMinMaxInfo
609 * Note: The rule here is that client rect of the maximized MDI child
610 * is equal to the client rect of the MDI client window.
612 static void MDI_ChildGetMinMaxInfo( WND
* clientWnd
, HWND hwnd
,
613 MINMAXINFO16
* lpMinMax
)
615 WND
* childWnd
= WIN_FindWndPtr(hwnd
);
616 RECT rect
= clientWnd
->rectClient
;
618 MapWindowPoints( clientWnd
->parent
->hwndSelf
,
619 ((MDICLIENTINFO
*)clientWnd
->wExtra
)->self
, (LPPOINT
)&rect
, 2);
620 AdjustWindowRectEx( &rect
, childWnd
->dwStyle
, 0, childWnd
->dwExStyle
);
622 lpMinMax
->ptMaxSize
.x
= rect
.right
-= rect
.left
;
623 lpMinMax
->ptMaxSize
.y
= rect
.bottom
-= rect
.top
;
625 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
626 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
628 WIN_ReleaseWndPtr(childWnd
);
630 TRACE("max rect (%i,%i - %i, %i)\n",
631 rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
635 /**********************************************************************
636 * MDI_SwitchActiveChild
638 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
641 static void MDI_SwitchActiveChild( HWND clientHwnd
, HWND childHwnd
,
644 WND
*w
= WIN_FindWndPtr(clientHwnd
);
649 hwndTo
= MDI_GetWindow(w
, childHwnd
, bNextWindow
, 0);
651 ci
= (MDICLIENTINFO
*) w
->wExtra
;
653 TRACE("from %04x, to %04x\n",childHwnd
,hwndTo
);
655 if ( !hwndTo
) goto END
; /* no window to switch to */
657 hwndPrev
= ci
->hwndActiveChild
;
659 if ( hwndTo
!= hwndPrev
)
663 if( ci
->hwndChildMaximized
)
666 w
->dwStyle
&= ~WS_VISIBLE
;
669 SetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0,
670 SWP_NOMOVE
| SWP_NOSIZE
);
672 if( bNextWindow
&& hwndPrev
)
673 SetWindowPos( hwndPrev
, HWND_BOTTOM
, 0, 0, 0, 0,
674 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
676 ShowWindow( clientHwnd
, SW_SHOW
);
679 WIN_ReleaseWndPtr(w
);
683 /**********************************************************************
686 static LRESULT
MDIDestroyChild( WND
*w_parent
, MDICLIENTINFO
*ci
,
687 HWND parent
, HWND child
,
690 WND
*childPtr
= WIN_FindWndPtr(child
);
694 if( child
== ci
->hwndActiveChild
)
696 MDI_SwitchActiveChild(parent
, child
, TRUE
);
698 if( child
== ci
->hwndActiveChild
)
700 ShowWindow( child
, SW_HIDE
);
701 if( child
== ci
->hwndChildMaximized
)
703 MDI_RestoreFrameMenu(w_parent
->parent
, child
);
704 ci
->hwndChildMaximized
= 0;
705 MDI_UpdateFrameText(w_parent
->parent
,parent
,TRUE
,NULL
);
708 MDI_ChildActivate(w_parent
, 0);
712 MDI_MenuDeleteItem(w_parent
, child
);
714 WIN_ReleaseWndPtr(childPtr
);
716 ci
->nActiveChildren
--;
718 TRACE("child destroyed - %04x\n",child
);
722 MDI_PostUpdate(GetParent(child
), ci
, SB_BOTH
+1);
723 DestroyWindow(child
);
731 /**********************************************************************
734 * Note: hWndChild is NULL when last child is being destroyed
736 static LONG
MDI_ChildActivate( WND
*clientPtr
, HWND hWndChild
)
738 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientPtr
->wExtra
;
739 HWND prevActiveWnd
= clientInfo
->hwndActiveChild
;
740 WND
*wndPtr
= WIN_FindWndPtr( hWndChild
);
741 WND
*wndPrev
= WIN_FindWndPtr( prevActiveWnd
);
742 BOOL isActiveFrameWnd
= 0;
747 if( wndPtr
->dwStyle
& WS_DISABLED
)
754 /* Don't activate if it is already active. Might happen
755 since ShowWindow DOES activate MDI children */
756 if (clientInfo
->hwndActiveChild
== hWndChild
)
762 TRACE("%04x\n", hWndChild
);
764 if( GetActiveWindow() == clientPtr
->parent
->hwndSelf
)
765 isActiveFrameWnd
= TRUE
;
767 /* deactivate prev. active child */
770 wndPrev
->dwStyle
|= WS_SYSMENU
;
771 SendMessageA( prevActiveWnd
, WM_NCACTIVATE
, FALSE
, 0L );
772 SendMessageA( prevActiveWnd
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
,
774 /* uncheck menu item */
775 if( clientInfo
->hWindowMenu
)
777 WORD wPrevID
= wndPrev
->wIDmenu
- clientInfo
->idFirstChild
;
779 if (wPrevID
< MDI_MOREWINDOWSLIMIT
)
780 CheckMenuItem( clientInfo
->hWindowMenu
,
781 wndPrev
->wIDmenu
, 0);
783 CheckMenuItem( clientInfo
->hWindowMenu
,
784 clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1, 0);
789 if( clientInfo
->hwndChildMaximized
)
791 if( clientInfo
->hwndChildMaximized
!= hWndChild
) {
793 clientInfo
->hwndActiveChild
= hWndChild
;
794 ShowWindow( hWndChild
, SW_SHOWMAXIMIZED
);
796 ShowWindow( clientInfo
->hwndActiveChild
, SW_SHOWNORMAL
);
800 clientInfo
->hwndActiveChild
= hWndChild
;
802 /* check if we have any children left */
805 if( isActiveFrameWnd
)
806 SetFocus( clientInfo
->self
);
811 /* check menu item */
812 if( clientInfo
->hWindowMenu
)
814 /* The window to be activated must be displayed in the "Windows" menu */
815 if (wndPtr
->wIDmenu
>= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
)
817 MDI_SwapMenuItems(wndPtr
->parent
, wndPtr
->wIDmenu
, clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1);
818 MDI_MenuModifyItem(wndPtr
->parent
,wndPtr
->hwndSelf
);
821 CheckMenuItem(clientInfo
->hWindowMenu
, wndPtr
->wIDmenu
, MF_CHECKED
);
823 /* bring active child to the top */
824 SetWindowPos( hWndChild
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
826 if( isActiveFrameWnd
)
828 SendMessageA( hWndChild
, WM_NCACTIVATE
, TRUE
, 0L);
829 if( GetFocus() == clientInfo
->self
)
830 SendMessageA( clientInfo
->self
, WM_SETFOCUS
,
831 (WPARAM
)clientInfo
->self
, 0L );
833 SetFocus( clientInfo
->self
);
835 SendMessageA( hWndChild
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
,
839 WIN_ReleaseWndPtr(wndPtr
);
840 WIN_ReleaseWndPtr(wndPrev
);
844 /* -------------------- MDI client window functions ------------------- */
846 /**********************************************************************
847 * CreateMDIMenuBitmap
849 static HBITMAP16
CreateMDIMenuBitmap(void)
851 HDC hDCSrc
= CreateCompatibleDC(0);
852 HDC hDCDest
= CreateCompatibleDC(hDCSrc
);
853 HBITMAP16 hbClose
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_CLOSE
) );
855 HANDLE16 hobjSrc
, hobjDest
;
857 hobjSrc
= SelectObject(hDCSrc
, hbClose
);
858 hbCopy
= CreateCompatibleBitmap(hDCSrc
,GetSystemMetrics(SM_CXSIZE
),GetSystemMetrics(SM_CYSIZE
));
859 hobjDest
= SelectObject(hDCDest
, hbCopy
);
861 BitBlt(hDCDest
, 0, 0, GetSystemMetrics(SM_CXSIZE
), GetSystemMetrics(SM_CYSIZE
),
862 hDCSrc
, GetSystemMetrics(SM_CXSIZE
), 0, SRCCOPY
);
864 SelectObject(hDCSrc
, hobjSrc
);
865 DeleteObject(hbClose
);
868 hobjSrc
= SelectObject( hDCDest
, GetStockObject(BLACK_PEN
) );
870 MoveToEx( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, 0, NULL
);
871 LineTo( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, GetSystemMetrics(SM_CYSIZE
) - 1);
873 SelectObject(hDCDest
, hobjSrc
);
874 SelectObject(hDCDest
, hobjDest
);
880 /**********************************************************************
883 static LONG
MDICascade(WND
* clientWnd
, MDICLIENTINFO
*ci
)
888 if (ci
->hwndChildMaximized
)
889 SendMessageA( clientWnd
->hwndSelf
, WM_MDIRESTORE
,
890 (WPARAM
)ci
->hwndChildMaximized
, 0);
892 if (ci
->nActiveChildren
== 0) return 0;
894 if ((ppWnd
= WIN_BuildWinArray(clientWnd
, BWA_SKIPHIDDEN
| BWA_SKIPOWNED
|
895 BWA_SKIPICONIC
, &total
)))
897 WND
** heapPtr
= ppWnd
;
900 INT delta
= 0, n
= 0;
902 if( total
< ci
->nActiveChildren
)
903 delta
= GetSystemMetrics(SM_CYICONSPACING
) +
904 GetSystemMetrics(SM_CYICON
);
906 /* walk the list (backwards) and move windows */
907 while (*ppWnd
) ppWnd
++;
908 while (ppWnd
!= heapPtr
)
911 TRACE("move %04x to (%ld,%ld) size [%ld,%ld]\n",
912 (*ppWnd
)->hwndSelf
, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
);
914 MDI_CalcDefaultChildPos(clientWnd
, n
++, pos
, delta
);
915 SetWindowPos( (*ppWnd
)->hwndSelf
, 0, pos
[0].x
, pos
[0].y
,
917 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
920 WIN_ReleaseWinArray(heapPtr
);
923 if( total
< ci
->nActiveChildren
)
924 ArrangeIconicWindows( clientWnd
->hwndSelf
);
928 /**********************************************************************
931 static void MDITile( WND
* wndClient
, MDICLIENTINFO
*ci
, WPARAM wParam
)
936 if (ci
->hwndChildMaximized
)
937 SendMessageA( wndClient
->hwndSelf
, WM_MDIRESTORE
,
938 (WPARAM
)ci
->hwndChildMaximized
, 0);
940 if (ci
->nActiveChildren
== 0) return;
942 ppWnd
= WIN_BuildWinArray(wndClient
, BWA_SKIPHIDDEN
| BWA_SKIPOWNED
| BWA_SKIPICONIC
|
943 ((wParam
& MDITILE_SKIPDISABLED
)? BWA_SKIPDISABLED
: 0), &total
);
945 TRACE("%u windows to tile\n", total
);
949 WND
** heapPtr
= ppWnd
;
954 int x
, y
, xsize
, ysize
;
955 int rows
, columns
, r
, c
, i
;
957 GetClientRect(wndClient
->hwndSelf
,&rect
);
958 rows
= (int) sqrt((double)total
);
959 columns
= total
/ rows
;
961 if( wParam
& MDITILE_HORIZONTAL
) /* version >= 3.1 */
964 rows
= columns
; /* exchange r and c */
968 if( total
!= ci
->nActiveChildren
)
970 y
= rect
.bottom
- 2 * GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
971 rect
.bottom
= ( y
- GetSystemMetrics(SM_CYICON
) < rect
.top
)? rect
.bottom
: y
;
974 ysize
= rect
.bottom
/ rows
;
975 xsize
= rect
.right
/ columns
;
977 for (x
= i
= 0, c
= 1; c
<= columns
&& *ppWnd
; c
++)
982 ysize
= rect
.bottom
/ rows
;
986 for (r
= 1; r
<= rows
&& *ppWnd
; r
++, i
++)
988 SetWindowPos((*ppWnd
)->hwndSelf
, 0, x
, y
, xsize
, ysize
,
989 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
996 WIN_ReleaseWinArray(heapPtr
);
999 if( total
< ci
->nActiveChildren
) ArrangeIconicWindows( wndClient
->hwndSelf
);
1002 /* ----------------------- Frame window ---------------------------- */
1005 /**********************************************************************
1006 * MDI_AugmentFrameMenu
1008 static BOOL
MDI_AugmentFrameMenu( MDICLIENTINFO
* ci
, WND
*frame
,
1011 WND
* child
= WIN_FindWndPtr(hChild
);
1012 HMENU hSysPopup
= 0;
1013 HBITMAP hSysMenuBitmap
= 0;
1015 TRACE("frame %p,child %04x\n",frame
,hChild
);
1017 if( !frame
->wIDmenu
|| !child
->hSysMenu
)
1019 WIN_ReleaseWndPtr(child
);
1022 WIN_ReleaseWndPtr(child
);
1024 /* create a copy of sysmenu popup and insert it into frame menu bar */
1026 if (!(hSysPopup
= LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU")))
1029 TRACE("\tgot popup %04x in sysmenu %04x\n",
1030 hSysPopup
, child
->hSysMenu
);
1032 AppendMenuA(frame
->wIDmenu
,MF_HELP
| MF_BITMAP
,
1033 SC_MINIMIZE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_MINIMIZE
) ;
1034 AppendMenuA(frame
->wIDmenu
,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
= GetClassLongA(hChild
, GCL_HICONSM
);
1043 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(frame
->wIDmenu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
1074 hSysPopup
, (LPSTR
)(DWORD
)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(frame
->wIDmenu
,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
);
1094 DrawMenuBar(frame
->hwndSelf
);
1099 /**********************************************************************
1100 * MDI_RestoreFrameMenu
1102 static BOOL
MDI_RestoreFrameMenu( WND
*frameWnd
, HWND hChild
)
1104 MENUITEMINFOA menuInfo
;
1105 INT nItems
= GetMenuItemCount(frameWnd
->wIDmenu
) - 1;
1106 UINT iId
= GetMenuItemID(frameWnd
->wIDmenu
,nItems
) ;
1108 TRACE("frameWnd %p,(%04x),child %04x,nIt=%d,iId=%d\n",
1109 frameWnd
,frameWnd
->hwndSelf
,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 menuInfo
.cbSize
= sizeof(MENUITEMINFOA
);
1119 menuInfo
.fMask
= MIIM_DATA
| MIIM_TYPE
;
1121 GetMenuItemInfoA(frameWnd
->wIDmenu
,
1126 RemoveMenu(frameWnd
->wIDmenu
,0,MF_BYPOSITION
);
1128 if ( (menuInfo
.fType
& MFT_BITMAP
) &&
1129 (LOWORD(menuInfo
.dwTypeData
)!=0) &&
1130 (LOWORD(menuInfo
.dwTypeData
)!=hBmpClose
) )
1132 DeleteObject((HBITMAP
)LOWORD(menuInfo
.dwTypeData
));
1135 if(TWEAK_WineLook
> WIN31_LOOK
)
1138 DeleteMenu(frameWnd
->wIDmenu
,GetMenuItemCount(frameWnd
->wIDmenu
) - 1,MF_BYPOSITION
);
1141 DeleteMenu(frameWnd
->wIDmenu
,GetMenuItemCount(frameWnd
->wIDmenu
) - 1,MF_BYPOSITION
);
1143 DeleteMenu(frameWnd
->wIDmenu
,GetMenuItemCount(frameWnd
->wIDmenu
) - 1,MF_BYPOSITION
);
1145 DrawMenuBar(frameWnd
->hwndSelf
);
1151 /**********************************************************************
1152 * MDI_UpdateFrameText
1154 * used when child window is maximized/restored
1156 * Note: lpTitle can be NULL
1158 static void MDI_UpdateFrameText( WND
*frameWnd
, HWND hClient
,
1159 BOOL repaint
, LPCWSTR lpTitle
)
1161 WCHAR lpBuffer
[MDI_MAXTITLELENGTH
+1];
1162 WND
* clientWnd
= WIN_FindWndPtr(hClient
);
1163 MDICLIENTINFO
*ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1165 TRACE("repaint %i, frameText %s\n", repaint
, (lpTitle
)?debugstr_w(lpTitle
):"NULL");
1172 WIN_ReleaseWndPtr(clientWnd
);
1176 /* store new "default" title if lpTitle is not NULL */
1179 if (ci
->frameTitle
) HeapFree( SystemHeap
, 0, ci
->frameTitle
);
1180 ci
->frameTitle
= HEAP_strdupW( SystemHeap
, 0, lpTitle
);
1185 WND
* childWnd
= WIN_FindWndPtr( ci
->hwndChildMaximized
);
1187 if( childWnd
&& childWnd
->text
)
1189 /* combine frame title and child title if possible */
1191 static const WCHAR lpBracket
[] = {' ','-',' ','[',0};
1192 static const WCHAR lpBracket2
[] = {']',0};
1193 int i_frame_text_length
= strlenW(ci
->frameTitle
);
1194 int i_child_text_length
= strlenW(childWnd
->text
);
1196 lstrcpynW( lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
1198 if( i_frame_text_length
+ 6 < MDI_MAXTITLELENGTH
)
1200 strcatW( lpBuffer
, lpBracket
);
1202 if( i_frame_text_length
+ i_child_text_length
+ 6 < MDI_MAXTITLELENGTH
)
1204 strcatW( lpBuffer
, childWnd
->text
);
1205 strcatW( lpBuffer
, lpBracket2
);
1209 lstrcpynW( lpBuffer
+ i_frame_text_length
+ 4,
1210 childWnd
->text
, MDI_MAXTITLELENGTH
- i_frame_text_length
- 5 );
1211 strcatW( lpBuffer
, lpBracket2
);
1217 lstrcpynW(lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
+1 );
1219 WIN_ReleaseWndPtr(childWnd
);
1225 DEFWND_SetTextW( frameWnd
, lpBuffer
);
1226 if( repaint
== MDI_REPAINTFRAME
)
1227 SetWindowPos( frameWnd
->hwndSelf
, 0,0,0,0,0, SWP_FRAMECHANGED
|
1228 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
1230 WIN_ReleaseWndPtr(clientWnd
);
1235 /* ----------------------------- Interface ---------------------------- */
1238 /**********************************************************************
1241 * This function handles all MDI requests.
1243 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1252 if ( ( w
= WIN_FindWndPtr(hwnd
) ) == NULL
)
1255 if ( ( frameWnd
= WIN_LockWndPtr(w
->parent
) ) == NULL
) {
1256 WIN_ReleaseWndPtr(w
);
1260 ci
= (MDICLIENTINFO
*) w
->wExtra
;
1266 cs
= (LPCREATESTRUCTA
)lParam
;
1268 /* Translation layer doesn't know what's in the cs->lpCreateParams
1269 * so we have to keep track of what environment we're in. */
1271 if( w
->flags
& WIN_ISWIN32
)
1273 #define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1274 ci
->hWindowMenu
= ccs
->hWindowMenu
;
1275 ci
->idFirstChild
= ccs
->idFirstChild
;
1280 LPCLIENTCREATESTRUCT16 ccs
= MapSL((SEGPTR
)cs
->lpCreateParams
);
1281 ci
->hWindowMenu
= ccs
->hWindowMenu
;
1282 ci
->idFirstChild
= ccs
->idFirstChild
;
1285 ci
->hwndChildMaximized
= 0;
1286 ci
->nActiveChildren
= 0;
1287 ci
->nTotalCreated
= 0;
1288 ci
->frameTitle
= NULL
;
1291 w
->dwStyle
|= WS_CLIPCHILDREN
;
1295 hBmpClose
= CreateMDIMenuBitmap();
1296 hBmpRestore
= LoadBitmapA( 0, MAKEINTRESOURCEA(OBM_RESTORE
) );
1298 MDI_UpdateFrameText(frameWnd
, hwnd
, MDI_NOFRAMEREPAINT
,frameWnd
->text
);
1300 if (ci
->hWindowMenu
!= 0)
1301 AppendMenuA( ci
->hWindowMenu
, MF_SEPARATOR
, 0, NULL
);
1303 GetClientRect(frameWnd
->hwndSelf
, &rect
);
1304 NC_HandleNCCalcSize( w
, &rect
);
1305 w
->rectClient
= rect
;
1307 TRACE("Client created - hwnd = %04x, idFirst = %u\n",
1308 hwnd
, ci
->idFirstChild
);
1314 if( ci
->hwndChildMaximized
)
1315 MDI_RestoreFrameMenu(w
->parent
, ci
->hwndChildMaximized
);
1316 if((ci
->hWindowMenu
!= 0) &&
1317 (nItems
= GetMenuItemCount(ci
->hWindowMenu
)) > 0)
1319 ci
->idFirstChild
= nItems
- 1;
1320 ci
->nActiveChildren
++; /* to delete a separator */
1321 while( ci
->nActiveChildren
-- )
1322 DeleteMenu(ci
->hWindowMenu
,MF_BYPOSITION
,ci
->idFirstChild
--);
1327 case WM_MDIACTIVATE
:
1328 if( ci
->hwndActiveChild
!= (HWND
)wParam
)
1329 SetWindowPos((HWND
)wParam
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1334 retvalue
= MDICascade(w
, ci
);
1338 if (lParam
) retvalue
= MDICreateChild( w
, ci
, hwnd
,
1339 (MDICREATESTRUCTA
*)lParam
);
1344 retvalue
= MDIDestroyChild( w
, ci
, hwnd
, (HWND
)wParam
, TRUE
);
1347 case WM_MDIGETACTIVE
:
1348 if (lParam
) *(BOOL
*)lParam
= (ci
->hwndChildMaximized
> 0);
1349 retvalue
= ci
->hwndActiveChild
;
1352 case WM_MDIICONARRANGE
:
1353 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1354 ArrangeIconicWindows(hwnd
);
1355 ci
->sbRecalc
= SB_BOTH
+1;
1356 SendMessageA(hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0L);
1360 case WM_MDIMAXIMIZE
:
1361 ShowWindow( (HWND
)wParam
, SW_MAXIMIZE
);
1365 case WM_MDINEXT
: /* lParam != 0 means previous window */
1366 MDI_SwitchActiveChild(hwnd
, (HWND
)wParam
, (lParam
)? FALSE
: TRUE
);
1370 SendMessageA( (HWND
)wParam
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
1375 retvalue
= MDISetMenu( hwnd
, (HMENU
)wParam
, (HMENU
)lParam
);
1377 case WM_MDIREFRESHMENU
:
1378 retvalue
= MDIRefreshMenu( hwnd
, (HMENU
)wParam
, (HMENU
)lParam
);
1382 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1383 ShowScrollBar(hwnd
,SB_BOTH
,FALSE
);
1384 MDITile(w
, ci
, wParam
);
1385 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1391 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1392 ScrollChildren(hwnd
, message
, wParam
, lParam
);
1393 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1398 if( ci
->hwndActiveChild
)
1400 WND
* pw
= WIN_FindWndPtr( ci
->hwndActiveChild
);
1401 if( !(pw
->dwStyle
& WS_MINIMIZE
) )
1402 SetFocus( ci
->hwndActiveChild
);
1403 WIN_ReleaseWndPtr(pw
);
1409 if( ci
->hwndActiveChild
)
1410 SendMessageA(ci
->hwndActiveChild
, message
, wParam
, lParam
);
1413 case WM_PARENTNOTIFY
:
1414 if (LOWORD(wParam
) == WM_LBUTTONDOWN
)
1418 pt
.x
= SLOWORD(lParam
);
1419 pt
.y
= SHIWORD(lParam
);
1420 child
= ChildWindowFromPoint(hwnd
, pt
);
1422 TRACE("notification from %04x (%li,%li)\n",child
,pt
.x
,pt
.y
);
1424 if( child
&& child
!= hwnd
&& child
!= ci
->hwndActiveChild
)
1425 SetWindowPos(child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1431 if( IsWindow(ci
->hwndChildMaximized
) )
1433 WND
* child
= WIN_FindWndPtr(ci
->hwndChildMaximized
);
1438 rect
.right
= LOWORD(lParam
);
1439 rect
.bottom
= HIWORD(lParam
);
1441 AdjustWindowRectEx(&rect
, child
->dwStyle
, 0, child
->dwExStyle
);
1442 MoveWindow(ci
->hwndChildMaximized
, rect
.left
, rect
.top
,
1443 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 1);
1444 WIN_ReleaseWndPtr(child
);
1447 MDI_PostUpdate(hwnd
, ci
, SB_BOTH
+1);
1451 case WM_MDICALCCHILDSCROLL
:
1452 if( (ci
->mdiFlags
& MDIF_NEEDUPDATE
) && ci
->sbRecalc
)
1454 CalcChildScroll16(hwnd
, ci
->sbRecalc
-1);
1456 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1462 retvalue
= DefWindowProcA( hwnd
, message
, wParam
, lParam
);
1464 WIN_ReleaseWndPtr(w
);
1465 WIN_ReleaseWndPtr(frameWnd
);
1470 /***********************************************************************
1471 * DefFrameProc (USER.445)
1473 LRESULT WINAPI
DefFrameProc16( HWND16 hwnd
, HWND16 hwndMDIClient
,
1474 UINT16 message
, WPARAM16 wParam
, LPARAM lParam
)
1485 wndPtr
= WIN_FindWndPtr(hwndMDIClient
);
1488 ERR("null wndPtr for mdi window hwndMDIClient=%04x\n",
1493 ci
= (MDICLIENTINFO
*)wndPtr
->wExtra
;
1495 /* check for possible syscommands for maximized MDI child */
1496 WIN_ReleaseWndPtr(wndPtr
);
1499 wParam
< ci
->idFirstChild
||
1500 wParam
>= ci
->idFirstChild
+ ci
->nActiveChildren
1502 if( (wParam
- 0xF000) & 0xF00F ) break;
1513 if( ci
->hwndChildMaximized
)
1514 return SendMessage16( ci
->hwndChildMaximized
, WM_SYSCOMMAND
,
1520 wndPtr
= WIN_FindWndPtr(hwndMDIClient
);
1521 ci
= (MDICLIENTINFO
*)wndPtr
->wExtra
;
1523 if (wParam
- ci
->idFirstChild
== MDI_MOREWINDOWSLIMIT
)
1524 /* User chose "More Windows..." */
1525 childHwnd
= MDI_MoreWindowsDialog(wndPtr
);
1527 /* User chose one of the windows listed in the "Windows" menu */
1528 childHwnd
= MDI_GetChildByID(wndPtr
,wParam
);
1530 WIN_ReleaseWndPtr(wndPtr
);
1532 SendMessage16(hwndMDIClient
, WM_MDIACTIVATE
,
1533 (WPARAM16
)childHwnd
, 0L);
1538 SendMessage16(hwndMDIClient
, message
, wParam
, lParam
);
1543 LPWSTR text
= HEAP_strdupAtoW( GetProcessHeap(), 0, MapSL(lParam
) );
1544 wndPtr
= WIN_FindWndPtr(hwnd
);
1545 MDI_UpdateFrameText(wndPtr
, hwndMDIClient
,
1546 MDI_REPAINTFRAME
, text
);
1547 WIN_ReleaseWndPtr(wndPtr
);
1548 HeapFree( GetProcessHeap(), 0, text
);
1550 return 1; /* success. FIXME: check text length */
1553 SetFocus(hwndMDIClient
);
1557 MoveWindow16(hwndMDIClient
, 0, 0,
1558 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1563 wndPtr
= WIN_FindWndPtr(hwndMDIClient
);
1564 ci
= (MDICLIENTINFO
*)wndPtr
->wExtra
;
1566 if( !(wndPtr
->parent
->dwStyle
& WS_MINIMIZE
)
1567 && ci
->hwndActiveChild
&& !ci
->hwndChildMaximized
)
1569 /* control menu is between the frame system menu and
1570 * the first entry of menu bar */
1572 if( (wParam
== VK_LEFT
&&
1573 wndPtr
->parent
->wIDmenu
== LOWORD(lParam
)) ||
1574 (wParam
== VK_RIGHT
&&
1575 GetSubMenu16(wndPtr
->parent
->hSysMenu
, 0) == LOWORD(lParam
)) )
1578 WIN_ReleaseWndPtr(wndPtr
);
1579 wndPtr
= WIN_FindWndPtr(ci
->hwndActiveChild
);
1580 retvalue
= MAKELONG( GetSubMenu16(wndPtr
->hSysMenu
, 0),
1581 ci
->hwndActiveChild
);
1582 WIN_ReleaseWndPtr(wndPtr
);
1586 WIN_ReleaseWndPtr(wndPtr
);
1591 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1595 /***********************************************************************
1596 * DefFrameProcA (USER32.@)
1598 LRESULT WINAPI
DefFrameProcA( HWND hwnd
, HWND hwndMDIClient
,
1599 UINT message
, WPARAM wParam
, LPARAM lParam
)
1606 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1608 MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ) );
1611 SendMessageA(hwndMDIClient
, message
, wParam
, lParam
);
1616 LPSTR segstr
= SEGPTR_STRDUP((LPSTR
)lParam
);
1618 ret
= DefFrameProc16(hwnd
, hwndMDIClient
, message
,
1619 wParam
, (LPARAM
)SEGPTR_GET(segstr
) );
1620 SEGPTR_FREE(segstr
);
1627 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1632 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1636 /***********************************************************************
1637 * DefFrameProcW (USER32.@)
1639 LRESULT WINAPI
DefFrameProcW( HWND hwnd
, HWND hwndMDIClient
,
1640 UINT message
, WPARAM wParam
, LPARAM lParam
)
1647 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1649 MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ) );
1652 SendMessageW(hwndMDIClient
, message
, wParam
, lParam
);
1657 LPSTR txt
= HEAP_strdupWtoA(GetProcessHeap(),0,(LPWSTR
)lParam
);
1658 LRESULT ret
= DefFrameProcA( hwnd
, hwndMDIClient
, message
,
1659 wParam
, (DWORD
)txt
);
1660 HeapFree(GetProcessHeap(),0,txt
);
1666 return DefFrameProcA( hwnd
, hwndMDIClient
, message
,
1671 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1675 /***********************************************************************
1676 * DefMDIChildProc (USER.447)
1678 LRESULT WINAPI
DefMDIChildProc16( HWND16 hwnd
, UINT16 message
,
1679 WPARAM16 wParam
, LPARAM lParam
)
1682 WND
*clientWnd
,*tmpWnd
= 0;
1685 tmpWnd
= WIN_FindWndPtr(hwnd
);
1686 if (!tmpWnd
) return 0;
1687 clientWnd
= WIN_FindWndPtr(tmpWnd
->parent
->hwndSelf
);
1688 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1689 WIN_ReleaseWndPtr(tmpWnd
);
1692 if (clientWnd
->cbWndExtra
< sizeof(MDICLIENTINFO
))
1694 WARN("called on non-MDI child window %x\n", hwnd
);
1695 WIN_ReleaseWndPtr(clientWnd
);
1696 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1702 DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1703 MDI_MenuModifyItem(clientWnd
,hwnd
);
1704 if( ci
->hwndChildMaximized
== hwnd
)
1705 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1706 MDI_REPAINTFRAME
, NULL
);
1707 retvalue
= 1; /* success. FIXME: check text length */
1711 SendMessage16(ci
->self
,WM_MDIDESTROY
,(WPARAM16
)hwnd
,0L);
1716 if( ci
->hwndActiveChild
!= hwnd
)
1717 MDI_ChildActivate(clientWnd
, hwnd
);
1720 case WM_CHILDACTIVATE
:
1721 MDI_ChildActivate(clientWnd
, hwnd
);
1726 TRACE("WM_NCPAINT for %04x, active %04x\n",
1727 hwnd
, ci
->hwndActiveChild
);
1734 if( ci
->hwndChildMaximized
== hwnd
)
1742 tmpWnd
= WIN_FindWndPtr(hwnd
);
1743 tmpWnd
->dwStyle
|= WS_SYSMENU
;
1744 WIN_ReleaseWndPtr(tmpWnd
);
1747 if( ci
->hwndChildMaximized
== hwnd
)
1749 retvalue
= SendMessage16( clientWnd
->parent
->hwndSelf
,
1750 message
, wParam
, lParam
);
1753 tmpWnd
= WIN_FindWndPtr(hwnd
);
1754 tmpWnd
->dwStyle
&= ~WS_SYSMENU
;
1755 WIN_ReleaseWndPtr(tmpWnd
);
1758 SendMessage16( ci
->self
, WM_MDINEXT
, 0, 0);
1762 SendMessage16( ci
->self
, WM_MDINEXT
, 0, 1);
1768 case WM_GETMINMAXINFO
:
1769 MDI_ChildGetMinMaxInfo(clientWnd
, hwnd
, MapSL(lParam
));
1774 if( ci
->hwndChildMaximized
) ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1776 MDI_PostUpdate(clientWnd
->hwndSelf
, ci
, SB_BOTH
+1);
1782 if( ci
->hwndActiveChild
== hwnd
&& wParam
!= SIZE_MAXIMIZED
)
1784 ci
->hwndChildMaximized
= 0;
1786 MDI_RestoreFrameMenu( clientWnd
->parent
, hwnd
);
1787 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1788 MDI_REPAINTFRAME
, NULL
);
1791 if( wParam
== SIZE_MAXIMIZED
)
1793 HWND16 hMaxChild
= ci
->hwndChildMaximized
;
1795 if( hMaxChild
== hwnd
) break;
1799 SendMessage16( hMaxChild
, WM_SETREDRAW
, FALSE
, 0L );
1801 MDI_RestoreFrameMenu( clientWnd
->parent
, hMaxChild
);
1802 ShowWindow16( hMaxChild
, SW_SHOWNOACTIVATE
);
1804 SendMessage16( hMaxChild
, WM_SETREDRAW
, TRUE
, 0L );
1807 TRACE("maximizing child %04x\n", hwnd
);
1810 * Keep track of the maximized window.
1812 ci
->hwndChildMaximized
= hwnd
; /* !!! */
1815 * The maximized window should also be the active window
1817 MDI_ChildActivate(clientWnd
, hwnd
);
1819 MDI_AugmentFrameMenu( ci
, clientWnd
->parent
, hwnd
);
1820 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1821 MDI_REPAINTFRAME
, NULL
);
1824 if( wParam
== SIZE_MINIMIZED
)
1826 HWND16 switchTo
= MDI_GetWindow(clientWnd
, hwnd
, TRUE
, WS_MINIMIZE
);
1829 SendMessage16( switchTo
, WM_CHILDACTIVATE
, 0, 0L);
1832 MDI_PostUpdate(clientWnd
->hwndSelf
, ci
, SB_BOTH
+1);
1837 /* MDI children don't have menu bars */
1838 retvalue
= 0x00010000L
;
1843 if( wParam
== VK_LEFT
) /* switch to frame system menu */
1845 retvalue
= MAKELONG( GetSubMenu16(clientWnd
->parent
->hSysMenu
, 0),
1846 clientWnd
->parent
->hwndSelf
);
1849 if( wParam
== VK_RIGHT
) /* to frame menu bar */
1851 retvalue
= MAKELONG( clientWnd
->parent
->wIDmenu
,
1852 clientWnd
->parent
->hwndSelf
);
1861 SendMessage16(hwnd
,WM_SYSCOMMAND
,
1862 (WPARAM16
)SC_KEYMENU
, (LPARAM
)(DWORD
)VK_SPACE
);
1868 retvalue
= DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1870 WIN_ReleaseWndPtr(clientWnd
);
1875 /***********************************************************************
1876 * DefMDIChildProcA (USER32.@)
1878 LRESULT WINAPI
DefMDIChildProcA( HWND hwnd
, UINT message
,
1879 WPARAM wParam
, LPARAM lParam
)
1882 WND
*clientWnd
,*tmpWnd
;
1885 tmpWnd
= WIN_FindWndPtr(hwnd
);
1886 if (!tmpWnd
) return 0;
1887 clientWnd
= WIN_FindWndPtr(tmpWnd
->parent
->hwndSelf
);
1888 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1889 WIN_ReleaseWndPtr(tmpWnd
);
1892 if (clientWnd
->cbWndExtra
< sizeof(MDICLIENTINFO
))
1894 WARN("called on non-MDI child window %x\n", hwnd
);
1895 WIN_ReleaseWndPtr(clientWnd
);
1896 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1902 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1903 MDI_MenuModifyItem(clientWnd
,hwnd
);
1904 if( ci
->hwndChildMaximized
== hwnd
)
1905 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1906 MDI_REPAINTFRAME
, NULL
);
1907 retvalue
= 1; /* success. FIXME: check text length */
1910 case WM_GETMINMAXINFO
:
1913 STRUCT32_MINMAXINFO32to16( (MINMAXINFO
*)lParam
, &mmi
);
1914 MDI_ChildGetMinMaxInfo( clientWnd
, hwnd
, &mmi
);
1915 STRUCT32_MINMAXINFO16to32( &mmi
, (MINMAXINFO
*)lParam
);
1922 /* MDI children don't have menu bars */
1923 retvalue
= 0x00010000L
;
1928 case WM_CHILDACTIVATE
:
1934 retvalue
= DefMDIChildProc16( hwnd
, message
, (WPARAM16
)wParam
, lParam
);
1940 SendMessageA(hwnd
,WM_SYSCOMMAND
,
1941 (WPARAM
)SC_KEYMENU
, (LPARAM
)(DWORD
)VK_SPACE
);
1946 retvalue
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1948 WIN_ReleaseWndPtr(clientWnd
);
1953 /***********************************************************************
1954 * DefMDIChildProcW (USER32.@)
1956 LRESULT WINAPI
DefMDIChildProcW( HWND hwnd
, UINT message
,
1957 WPARAM wParam
, LPARAM lParam
)
1960 WND
*clientWnd
,*tmpWnd
;
1963 tmpWnd
= WIN_FindWndPtr(hwnd
);
1964 if (!tmpWnd
) return 0;
1965 clientWnd
= WIN_FindWndPtr(tmpWnd
->parent
->hwndSelf
);
1966 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1967 WIN_ReleaseWndPtr(tmpWnd
);
1970 if (clientWnd
->cbWndExtra
< sizeof(MDICLIENTINFO
))
1972 WARN("called on non-MDI child window %x\n", hwnd
);
1973 WIN_ReleaseWndPtr(clientWnd
);
1974 return DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1980 DefWindowProcW(hwnd
, message
, wParam
, lParam
);
1981 MDI_MenuModifyItem(clientWnd
,hwnd
);
1982 if( ci
->hwndChildMaximized
== hwnd
)
1983 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1984 MDI_REPAINTFRAME
, NULL
);
1985 retvalue
= 1; /* success. FIXME: check text length */
1988 case WM_GETMINMAXINFO
:
1992 case WM_CHILDACTIVATE
:
1998 retvalue
= DefMDIChildProcA( hwnd
, message
, (WPARAM16
)wParam
, lParam
);
2004 SendMessageW(hwnd
,WM_SYSCOMMAND
,
2005 (WPARAM
)SC_KEYMENU
, (LPARAM
)(DWORD
)VK_SPACE
);
2010 retvalue
= DefWindowProcW(hwnd
, message
, wParam
, lParam
);
2012 WIN_ReleaseWndPtr(clientWnd
);
2018 /**********************************************************************
2019 * CreateMDIWindowA (USER32.@) Creates a MDI child in new thread
2020 * FIXME: its in the same thread now
2023 * Success: Handle to created window
2026 HWND WINAPI
CreateMDIWindowA(
2027 LPCSTR lpClassName
, /* [in] Pointer to registered child class name */
2028 LPCSTR lpWindowName
, /* [in] Pointer to window name */
2029 DWORD dwStyle
, /* [in] Window style */
2030 INT X
, /* [in] Horizontal position of window */
2031 INT Y
, /* [in] Vertical position of window */
2032 INT nWidth
, /* [in] Width of window */
2033 INT nHeight
, /* [in] Height of window */
2034 HWND hWndParent
, /* [in] Handle to parent window */
2035 HINSTANCE hInstance
, /* [in] Handle to application instance */
2036 LPARAM lParam
) /* [in] Application-defined value */
2038 WARN("is only single threaded!\n");
2039 return MDI_CreateMDIWindowA(lpClassName
, lpWindowName
, dwStyle
, X
, Y
,
2040 nWidth
, nHeight
, hWndParent
, hInstance
, lParam
);
2043 /**********************************************************************
2044 * MDI_CreateMDIWindowA
2045 * single threaded version of CreateMDIWindowA
2046 * called by CreateWindowExA
2048 HWND
MDI_CreateMDIWindowA(
2050 LPCSTR lpWindowName
,
2057 HINSTANCE hInstance
,
2061 MDICREATESTRUCTA cs
;
2062 WND
*pWnd
=WIN_FindWndPtr(hWndParent
);
2065 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
2066 debugstr_a(lpClassName
),debugstr_a(lpWindowName
),dwStyle
,X
,Y
,
2067 nWidth
,nHeight
,hWndParent
,hInstance
,lParam
);
2070 ERR(" bad hwnd for MDI-client: %d\n",hWndParent
);
2073 cs
.szClass
=lpClassName
;
2074 cs
.szTitle
=lpWindowName
;
2075 cs
.hOwner
=hInstance
;
2083 pCi
=(MDICLIENTINFO
*)pWnd
->wExtra
;
2085 retvalue
= MDICreateChild(pWnd
,pCi
,hWndParent
,&cs
);
2086 WIN_ReleaseWndPtr(pWnd
);
2090 /***********************************************************************
2091 * CreateMDIWindowW (USER32.@) Creates a MDI child in new thread
2094 * Success: Handle to created window
2097 HWND WINAPI
CreateMDIWindowW(
2098 LPCWSTR lpClassName
, /* [in] Pointer to registered child class name */
2099 LPCWSTR lpWindowName
, /* [in] Pointer to window name */
2100 DWORD dwStyle
, /* [in] Window style */
2101 INT X
, /* [in] Horizontal position of window */
2102 INT Y
, /* [in] Vertical position of window */
2103 INT nWidth
, /* [in] Width of window */
2104 INT nHeight
, /* [in] Height of window */
2105 HWND hWndParent
, /* [in] Handle to parent window */
2106 HINSTANCE hInstance
, /* [in] Handle to application instance */
2107 LPARAM lParam
) /* [in] Application-defined value */
2109 FIXME("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld): stub\n",
2110 debugstr_w(lpClassName
),debugstr_w(lpWindowName
),dwStyle
,X
,Y
,
2111 nWidth
,nHeight
,hWndParent
,hInstance
,lParam
);
2116 /******************************************************************************
2117 * CreateMDIWindowW (USER32.80) Creates a MDI child window
2118 * single threaded version of CreateMDIWindow
2119 * called by CreateWindowExW().
2121 HWND
MDI_CreateMDIWindowW(
2122 LPCWSTR lpClassName
, /* [in] Pointer to registered child class name */
2123 LPCWSTR lpWindowName
, /* [in] Pointer to window name */
2124 DWORD dwStyle
, /* [in] Window style */
2125 INT X
, /* [in] Horizontal position of window */
2126 INT Y
, /* [in] Vertical position of window */
2127 INT nWidth
, /* [in] Width of window */
2128 INT nHeight
, /* [in] Height of window */
2129 HWND hWndParent
, /* [in] Handle to parent window */
2130 HINSTANCE hInstance
, /* [in] Handle to application instance */
2131 LPARAM lParam
) /* [in] Application-defined value */
2133 FIXME("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld): stub\n",
2134 debugstr_w(lpClassName
),debugstr_w(lpWindowName
),dwStyle
,X
,Y
,
2135 nWidth
,nHeight
,hWndParent
,hInstance
,lParam
);
2140 /**********************************************************************
2141 * TranslateMDISysAccel (USER32.@)
2143 BOOL WINAPI
TranslateMDISysAccel( HWND hwndClient
, LPMSG msg
)
2147 STRUCT32_MSG32to16(msg
,&msg16
);
2148 /* MDICLIENTINFO is still the same for win32 and win16 ... */
2149 return TranslateMDISysAccel16(hwndClient
,&msg16
);
2153 /**********************************************************************
2154 * TranslateMDISysAccel (USER.451)
2156 BOOL16 WINAPI
TranslateMDISysAccel16( HWND16 hwndClient
, LPMSG16 msg
)
2159 if( IsWindow(hwndClient
) && (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
))
2161 MDICLIENTINFO
*ci
= NULL
;
2163 WND
*clientWnd
= WIN_FindWndPtr(hwndClient
);
2165 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
2166 wnd
= ci
->hwndActiveChild
;
2168 WIN_ReleaseWndPtr(clientWnd
);
2170 if( IsWindow(wnd
) && !(GetWindowLongA(wnd
,GWL_STYLE
) & WS_DISABLED
) )
2172 WPARAM16 wParam
= 0;
2174 /* translate if the Ctrl key is down and Alt not. */
2176 if( (GetKeyState(VK_CONTROL
) & 0x8000) &&
2177 !(GetKeyState(VK_MENU
) & 0x8000))
2179 switch( msg
->wParam
)
2183 wParam
= ( GetKeyState(VK_SHIFT
) & 0x8000 )
2184 ? SC_NEXTWINDOW
: SC_PREVWINDOW
;
2193 TRACE("wParam = %04x\n", wParam
);
2194 SendMessage16( ci
->hwndActiveChild
, WM_SYSCOMMAND
,
2195 wParam
, (LPARAM
)msg
->wParam
);
2200 return 0; /* failure */
2204 /***********************************************************************
2205 * CalcChildScroll (USER.462)
2207 void WINAPI
CalcChildScroll16( HWND16 hwnd
, WORD scroll
)
2210 RECT childRect
, clientRect
;
2211 INT vmin
, vmax
, hmin
, hmax
, vpos
, hpos
;
2214 if (!(pWnd
= WIN_FindWndPtr( hwnd
))) return;
2215 Wnd
= WIN_FindWndPtr(hwnd
);
2216 GetClientRect( hwnd
, &clientRect
);
2217 SetRectEmpty( &childRect
);
2219 for ( WIN_UpdateWndPtr(&pWnd
,pWnd
->child
); pWnd
; WIN_UpdateWndPtr(&pWnd
,pWnd
->next
))
2221 if( pWnd
->dwStyle
& WS_MAXIMIZE
)
2223 ShowScrollBar(hwnd
, SB_BOTH
, FALSE
);
2224 WIN_ReleaseWndPtr(pWnd
);
2225 WIN_ReleaseWndPtr(Wnd
);
2228 UnionRect( &childRect
, &pWnd
->rectWindow
, &childRect
);
2230 WIN_ReleaseWndPtr(pWnd
);
2231 UnionRect( &childRect
, &clientRect
, &childRect
);
2233 hmin
= childRect
.left
; hmax
= childRect
.right
- clientRect
.right
;
2234 hpos
= clientRect
.left
- childRect
.left
;
2235 vmin
= childRect
.top
; vmax
= childRect
.bottom
- clientRect
.bottom
;
2236 vpos
= clientRect
.top
- childRect
.top
;
2241 vpos
= hpos
; vmin
= hmin
; vmax
= hmax
;
2243 info
.cbSize
= sizeof(info
);
2244 info
.nMax
= vmax
; info
.nMin
= vmin
; info
.nPos
= vpos
;
2245 info
.fMask
= SIF_POS
| SIF_RANGE
;
2246 SetScrollInfo(hwnd
, scroll
, &info
, TRUE
);
2249 SCROLL_SetNCSbState( Wnd
, vmin
, vmax
, vpos
,
2252 WIN_ReleaseWndPtr(Wnd
);
2256 /***********************************************************************
2257 * ScrollChildren (USER.463)
2259 void WINAPI
ScrollChildren16(HWND16 hWnd
, UINT16 uMsg
, WPARAM16 wParam
, LPARAM lParam
)
2261 ScrollChildren( hWnd
, uMsg
, wParam
, lParam
);
2265 /***********************************************************************
2266 * ScrollChildren (USER32.@)
2268 void WINAPI
ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
,
2271 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
2273 INT curPos
, length
, minPos
, maxPos
, shift
;
2275 if( !wndPtr
) return;
2277 if( uMsg
== WM_HSCROLL
)
2279 GetScrollRange(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
2280 curPos
= GetScrollPos(hWnd
,SB_HORZ
);
2281 length
= (wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
)/2;
2282 shift
= GetSystemMetrics(SM_CYHSCROLL
);
2284 else if( uMsg
== WM_VSCROLL
)
2286 GetScrollRange(hWnd
,SB_VERT
,&minPos
,&maxPos
);
2287 curPos
= GetScrollPos(hWnd
,SB_VERT
);
2288 length
= (wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
)/2;
2289 shift
= GetSystemMetrics(SM_CXVSCROLL
);
2293 WIN_ReleaseWndPtr(wndPtr
);
2297 WIN_ReleaseWndPtr(wndPtr
);
2301 newPos
= curPos
- shift
;
2304 newPos
= curPos
+ shift
;
2307 newPos
= curPos
- length
;
2310 newPos
= curPos
+ length
;
2313 case SB_THUMBPOSITION
:
2314 newPos
= LOWORD(lParam
);
2327 CalcChildScroll16(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
2331 if( newPos
> maxPos
)
2334 if( newPos
< minPos
)
2337 SetScrollPos(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
2339 if( uMsg
== WM_VSCROLL
)
2340 ScrollWindowEx(hWnd
,0 ,curPos
- newPos
, NULL
, NULL
, 0, NULL
,
2341 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
2343 ScrollWindowEx(hWnd
,curPos
- newPos
, 0, NULL
, NULL
, 0, NULL
,
2344 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
2348 /******************************************************************************
2349 * CascadeWindows (USER32.@) Cascades MDI child windows
2352 * Success: Number of cascaded windows.
2356 CascadeWindows (HWND hwndParent
, UINT wFlags
, const LPRECT lpRect
,
2357 UINT cKids
, const HWND
*lpKids
)
2359 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2360 hwndParent
, wFlags
, cKids
);
2366 /******************************************************************************
2367 * TileWindows (USER32.@) Tiles MDI child windows
2370 * Success: Number of tiled windows.
2374 TileWindows (HWND hwndParent
, UINT wFlags
, const LPRECT lpRect
,
2375 UINT cKids
, const HWND
*lpKids
)
2377 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2378 hwndParent
, wFlags
, cKids
);
2383 /************************************************************************
2384 * "More Windows..." functionality
2387 /* MDI_MoreWindowsDlgProc
2389 * This function will process the messages sent to the "More Windows..."
2391 * Return values: 0 = cancel pressed
2392 * HWND = ok pressed or double-click in the list...
2396 static BOOL WINAPI
MDI_MoreWindowsDlgProc (HWND hDlg
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
2406 WND
*pParentWnd
= (WND
*)lParam
;
2407 MDICLIENTINFO
*ci
= (MDICLIENTINFO
*)pParentWnd
->wExtra
;
2408 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2410 /* Fill the list, sorted by id... */
2411 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
2414 /* Find the window with the current ID */
2415 for (pWnd
= WIN_LockWndPtr(pParentWnd
->child
); pWnd
; WIN_UpdateWndPtr(&pWnd
, pWnd
->next
))
2416 if (pWnd
->wIDmenu
== ci
->idFirstChild
+ i
)
2419 SendMessageW(hListBox
, LB_ADDSTRING
, 0, (LPARAM
) pWnd
->text
);
2420 SendMessageA(hListBox
, LB_SETITEMDATA
, i
, (LPARAM
) pWnd
);
2421 length
= strlenW(pWnd
->text
);
2422 WIN_ReleaseWndPtr(pWnd
);
2424 if (length
> widest
)
2427 /* Make sure the horizontal scrollbar scrolls ok */
2428 SendMessageA(hListBox
, LB_SETHORIZONTALEXTENT
, widest
* 6, 0);
2430 /* Set the current selection */
2431 SendMessageA(hListBox
, LB_SETCURSEL
, MDI_MOREWINDOWSLIMIT
, 0);
2436 switch (LOWORD(wParam
))
2440 /* windows are sorted by menu ID, so we must return the
2441 * window associated to the given id
2443 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2444 UINT index
= SendMessageA(hListBox
, LB_GETCURSEL
, 0, 0);
2445 WND
* pWnd
= (WND
*) SendMessageA(hListBox
, LB_GETITEMDATA
, index
, 0);
2447 EndDialog(hDlg
, pWnd
->hwndSelf
);
2455 switch (HIWORD(wParam
))
2459 /* windows are sorted by menu ID, so we must return the
2460 * window associated to the given id
2462 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2463 UINT index
= SendMessageA(hListBox
, LB_GETCURSEL
, 0, 0);
2464 WND
* pWnd
= (WND
*) SendMessageA(hListBox
, LB_GETITEMDATA
, index
, 0);
2466 EndDialog(hDlg
, pWnd
->hwndSelf
);
2479 * MDI_MoreWindowsDialog
2481 * Prompts the user with a listbox containing the opened
2482 * documents. The user can then choose a windows and click
2483 * on OK to set the current window to the one selected, or
2484 * CANCEL to cancel. The function returns a handle to the
2488 static HWND
MDI_MoreWindowsDialog(WND
* wndPtr
)
2494 hRes
= FindResourceA(GetModuleHandleA("USER32"), "MDI_MOREWINDOWS", RT_DIALOGA
);
2499 hDlgTmpl
= LoadResource(GetModuleHandleA("USER32"), hRes
);
2504 template = LockResource( hDlgTmpl
);
2509 return (HWND
) DialogBoxIndirectParamA(GetModuleHandleA("USER32"),
2510 (LPDLGTEMPLATEA
) template,
2512 (DLGPROC
) MDI_MoreWindowsDlgProc
,
2520 * Will swap the menu IDs for the given 2 positions.
2521 * pos1 and pos2 are menu IDs
2526 static void MDI_SwapMenuItems(WND
*parentWnd
, UINT pos1
, UINT pos2
)
2530 for (pWnd
= WIN_LockWndPtr(parentWnd
->child
); pWnd
; WIN_UpdateWndPtr(&pWnd
,pWnd
->next
))
2532 if (pWnd
->wIDmenu
== pos1
)
2533 pWnd
->wIDmenu
= pos2
;
2535 if (pWnd
->wIDmenu
== pos2
)
2536 pWnd
->wIDmenu
= pos1
;
2539 WIN_ReleaseWndPtr(pWnd
);