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"
85 #include "debugtools.h"
88 DEFAULT_DEBUG_CHANNEL(mdi
);
90 #define MDI_MAXLISTLENGTH 0x40
91 #define MDI_MAXTITLELENGTH 0xa1
93 #define MDI_NOFRAMEREPAINT 0
94 #define MDI_REPAINTFRAMENOW 1
95 #define MDI_REPAINTFRAME 2
97 #define WM_MDICALCCHILDSCROLL 0x10ac /* this is exactly what Windows uses */
99 /* "More Windows..." definitions */
100 #define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
101 option will appear under the Windows menu */
102 #define MDI_IDC_LISTBOX 100
103 #define MDI_IDS_MOREWINDOWS 13
105 #define MDIF_NEEDUPDATE 0x0001
109 UINT nActiveChildren
;
110 HWND hwndChildMaximized
;
111 HWND hwndActiveChild
;
117 UINT sbRecalc
; /* SB_xxx flags for scrollbar fixup */
121 static HBITMAP16 hBmpClose
= 0;
122 static HBITMAP16 hBmpRestore
= 0;
124 /* ----------------- declarations ----------------- */
125 static void MDI_UpdateFrameText(WND
*, HWND
, BOOL
, LPCWSTR
);
126 static BOOL
MDI_AugmentFrameMenu(MDICLIENTINFO
*, WND
*, HWND
);
127 static BOOL
MDI_RestoreFrameMenu(WND
*, HWND
);
129 static LONG
MDI_ChildActivate( WND
*, HWND
);
131 static HWND
MDI_MoreWindowsDialog(WND
*);
132 static void MDI_SwapMenuItems(WND
*, UINT
, UINT
);
133 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
134 /* -------- Miscellaneous service functions ----------
139 static HWND
MDI_GetChildByID(WND
* wndPtr
, INT id
)
141 for (wndPtr
= wndPtr
->child
; wndPtr
; wndPtr
= wndPtr
->next
)
142 if (wndPtr
->wIDmenu
== id
) return wndPtr
->hwndSelf
;
146 static void MDI_PostUpdate(HWND hwnd
, MDICLIENTINFO
* ci
, WORD recalc
)
148 if( !(ci
->mdiFlags
& MDIF_NEEDUPDATE
) )
150 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
151 PostMessageA( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0);
153 ci
->sbRecalc
= recalc
;
157 /*********************************************************************
158 * MDIClient class descriptor
160 const struct builtin_class_descr MDICLIENT_builtin_class
=
162 "MDIClient", /* name */
163 CS_GLOBALCLASS
, /* style */
164 MDIClientWndProcA
, /* procA */
165 NULL
, /* procW (FIXME) */
166 sizeof(MDICLIENTINFO
), /* extra */
167 IDC_ARROWA
, /* cursor */
168 COLOR_APPWORKSPACE
+1 /* brush */
172 /**********************************************************************
175 static BOOL
MDI_MenuModifyItem(WND
* clientWnd
, HWND hWndChild
)
178 static const WCHAR format
[] = {'%','d',' ',0};
179 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
180 WND
*wndPtr
= WIN_FindWndPtr(hWndChild
);
181 UINT n
= wsprintfW(buffer
, format
,
182 wndPtr
->wIDmenu
- clientInfo
->idFirstChild
+ 1);
185 if( !clientInfo
->hWindowMenu
)
191 if (wndPtr
->text
) lstrcpynW(buffer
+ n
, wndPtr
->text
, sizeof(buffer
)/sizeof(WCHAR
) - n
);
193 n
= GetMenuState(clientInfo
->hWindowMenu
,wndPtr
->wIDmenu
,MF_BYCOMMAND
);
194 bRet
= ModifyMenuW(clientInfo
->hWindowMenu
, wndPtr
->wIDmenu
,
195 MF_BYCOMMAND
| MF_STRING
, wndPtr
->wIDmenu
, buffer
);
196 CheckMenuItem(clientInfo
->hWindowMenu
,wndPtr
->wIDmenu
, n
& MF_CHECKED
);
198 WIN_ReleaseWndPtr(wndPtr
);
202 /**********************************************************************
205 static BOOL
MDI_MenuDeleteItem(WND
* clientWnd
, HWND hWndChild
)
208 static const WCHAR format
[] = {'&','%','d',' ',0};
209 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
210 WND
*wndPtr
= WIN_FindWndPtr(hWndChild
);
214 if( !clientInfo
->nActiveChildren
||
215 !clientInfo
->hWindowMenu
)
221 id
= wndPtr
->wIDmenu
;
222 DeleteMenu(clientInfo
->hWindowMenu
,id
,MF_BYCOMMAND
);
224 /* walk the rest of MDI children to prevent gaps in the id
225 * sequence and in the menu child list */
227 for( index
= id
+1; index
<= clientInfo
->nActiveChildren
+
228 clientInfo
->idFirstChild
; index
++ )
230 WND
*tmpWnd
= WIN_FindWndPtr(MDI_GetChildByID(clientWnd
,index
));
233 TRACE("no window for id=%i\n",index
);
234 WIN_ReleaseWndPtr(tmpWnd
);
241 n
= wsprintfW(buffer
, format
,index
- clientInfo
->idFirstChild
);
243 lstrcpynW(buffer
+ n
, tmpWnd
->text
, sizeof(buffer
)/sizeof(WCHAR
) - n
);
245 /* change menu if the current child is to be shown in the
248 if (index
<= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
)
249 ModifyMenuW(clientInfo
->hWindowMenu
,index
,MF_BYCOMMAND
| MF_STRING
,
250 index
- 1 , buffer
);
251 WIN_ReleaseWndPtr(tmpWnd
);
254 /* We must restore the "More Windows..." option if there is enough child
256 if (clientInfo
->nActiveChildren
- 1 > MDI_MOREWINDOWSLIMIT
)
259 LoadStringA(GetModuleHandleA("USER32"), MDI_IDS_MOREWINDOWS
, szTmp
, 50);
261 AppendMenuA(clientInfo
->hWindowMenu
,MF_STRING
,clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
, szTmp
);
265 WIN_ReleaseWndPtr(wndPtr
);
269 /**********************************************************************
272 * returns "activateable" child different from the current or zero
274 static HWND
MDI_GetWindow(WND
*clientWnd
, HWND hWnd
, BOOL bNext
,
277 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
278 WND
*wndPtr
, *pWnd
, *pWndLast
= NULL
;
280 dwStyleMask
|= WS_DISABLED
| WS_VISIBLE
;
281 if( !hWnd
) hWnd
= clientInfo
->hwndActiveChild
;
283 if( !(wndPtr
= WIN_FindWndPtr(hWnd
)) ) return 0;
285 for ( pWnd
= WIN_LockWndPtr(wndPtr
->next
); ; WIN_UpdateWndPtr(&pWnd
,pWnd
->next
))
287 if (!pWnd
) WIN_UpdateWndPtr(&pWnd
,wndPtr
->parent
->child
);
289 if ( pWnd
== wndPtr
) break; /* went full circle */
291 if (!pWnd
->owner
&& (pWnd
->dwStyle
& dwStyleMask
) == WS_VISIBLE
)
297 WIN_ReleaseWndPtr(wndPtr
);
298 WIN_ReleaseWndPtr(pWnd
);
299 return pWndLast
? pWndLast
->hwndSelf
: 0;
302 /**********************************************************************
303 * MDI_CalcDefaultChildPos
305 * It seems that the default height is about 2/3 of the client rect
307 static void MDI_CalcDefaultChildPos( WND
* w
, WORD n
, LPPOINT lpPos
,
311 RECT rect
= w
->rectClient
;
312 INT spacing
= GetSystemMetrics(SM_CYCAPTION
) +
313 GetSystemMetrics(SM_CYFRAME
) - 1;
315 if( rect
.bottom
- rect
.top
- delta
>= spacing
)
316 rect
.bottom
-= delta
;
318 nstagger
= (rect
.bottom
- rect
.top
)/(3 * spacing
);
319 lpPos
[1].x
= (rect
.right
- rect
.left
- nstagger
* spacing
);
320 lpPos
[1].y
= (rect
.bottom
- rect
.top
- nstagger
* spacing
);
321 lpPos
[0].x
= lpPos
[0].y
= spacing
* (n
%(nstagger
+1));
324 /**********************************************************************
327 static LRESULT
MDISetMenu( HWND hwnd
, HMENU hmenuFrame
,
332 HWND hwndFrame
= GetParent(hwnd
);
333 HMENU oldFrameMenu
= GetMenu(hwndFrame
);
335 TRACE("%04x %04x %04x\n",
336 hwnd
, hmenuFrame
, hmenuWindow
);
338 if (hmenuFrame
&& !IsMenu(hmenuFrame
))
340 WARN("hmenuFrame is not a menu handle\n");
344 if (hmenuWindow
&& !IsMenu(hmenuWindow
))
346 WARN("hmenuWindow is not a menu handle\n");
350 w
= WIN_FindWndPtr(hwnd
);
351 ci
= (MDICLIENTINFO
*) w
->wExtra
;
353 if( ci
->hwndChildMaximized
&& hmenuFrame
&& hmenuFrame
!=oldFrameMenu
)
354 MDI_RestoreFrameMenu(w
->parent
, ci
->hwndChildMaximized
);
356 if( hmenuWindow
&& ci
->hWindowMenu
&& hmenuWindow
!=ci
->hWindowMenu
)
358 /* delete menu items from ci->hWindowMenu
359 * and add them to hmenuWindow */
361 INT i
= GetMenuItemCount(ci
->hWindowMenu
) - 1;
362 INT pos
= GetMenuItemCount(hmenuWindow
) + 1;
364 AppendMenuA( hmenuWindow
, MF_SEPARATOR
, 0, NULL
);
366 if( ci
->nActiveChildren
)
369 LPWSTR buffer
= NULL
;
371 INT nbWindowsMenuItems
; /* num of documents shown + "More Windows..." if present */
373 if (ci
->nActiveChildren
<= MDI_MOREWINDOWSLIMIT
)
374 nbWindowsMenuItems
= ci
->nActiveChildren
;
376 nbWindowsMenuItems
= MDI_MOREWINDOWSLIMIT
+ 1;
378 j
= i
- nbWindowsMenuItems
+ 1;
380 for( ; i
>= j
; i
-- )
382 memset(&mii
, 0, sizeof(mii
));
383 mii
.cbSize
= sizeof(mii
);
384 mii
.fMask
= MIIM_CHECKMARKS
| MIIM_DATA
| MIIM_ID
| MIIM_STATE
385 | MIIM_SUBMENU
| MIIM_TYPE
| MIIM_BITMAP
;
387 GetMenuItemInfoW(ci
->hWindowMenu
, i
, TRUE
, &mii
);
388 if(mii
.cch
) { /* Menu is MFT_STRING */
389 mii
.cch
++; /* add room for '\0' */
390 buffer
= HeapAlloc(GetProcessHeap(), 0,
391 mii
.cch
* sizeof(WCHAR
));
392 mii
.dwTypeData
= buffer
;
393 GetMenuItemInfoW(ci
->hWindowMenu
, i
, TRUE
, &mii
);
395 DeleteMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
396 InsertMenuItemW(hmenuWindow
, pos
, TRUE
, &mii
);
398 HeapFree(GetProcessHeap(), 0, buffer
);
404 /* remove separator */
405 DeleteMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
407 ci
->hWindowMenu
= hmenuWindow
;
412 SetMenu(hwndFrame
, hmenuFrame
);
413 if( hmenuFrame
!=oldFrameMenu
)
415 if( ci
->hwndChildMaximized
)
416 MDI_AugmentFrameMenu(ci
, w
->parent
, ci
->hwndChildMaximized
);
417 WIN_ReleaseWndPtr(w
);
423 INT nItems
= GetMenuItemCount(w
->parent
->wIDmenu
) - 1;
424 UINT iId
= GetMenuItemID(w
->parent
->wIDmenu
,nItems
) ;
426 if( !(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
428 /* SetMenu() may already have been called, meaning that this window
429 * already has its menu. But they may have done a SetMenu() on
430 * an MDI window, and called MDISetMenu() after the fact, meaning
431 * that the "if" to this "else" wouldn't catch the need to
432 * augment the frame menu.
434 if( ci
->hwndChildMaximized
)
435 MDI_AugmentFrameMenu(ci
, w
->parent
, ci
->hwndChildMaximized
);
438 WIN_ReleaseWndPtr(w
);
442 /**********************************************************************
445 static LRESULT
MDIRefreshMenu( HWND hwnd
, HMENU hmenuFrame
,
448 HWND hwndFrame
= GetParent(hwnd
);
449 HMENU oldFrameMenu
= GetMenu(hwndFrame
);
451 TRACE("%04x %04x %04x\n",
452 hwnd
, hmenuFrame
, hmenuWindow
);
454 FIXME("partially function stub\n");
460 /* ------------------ MDI child window functions ---------------------- */
463 /**********************************************************************
466 static HWND
MDICreateChild( WND
*w
, MDICLIENTINFO
*ci
, HWND parent
,
467 LPMDICREATESTRUCTA cs
)
470 DWORD style
= cs
->style
| (WS_CHILD
| WS_CLIPSIBLINGS
);
471 HWND hwnd
, hwndMax
= 0;
472 WORD wIDmenu
= ci
->idFirstChild
+ ci
->nActiveChildren
;
473 char lpstrDef
[]="junk!";
475 TRACE("origin %i,%i - dim %i,%i, style %08lx\n",
476 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, cs
->style
);
477 /* calculate placement */
478 MDI_CalcDefaultChildPos(w
, ci
->nTotalCreated
++, pos
, 0);
480 if (cs
->cx
== CW_USEDEFAULT
|| !cs
->cx
) cs
->cx
= pos
[1].x
;
481 if (cs
->cy
== CW_USEDEFAULT
|| !cs
->cy
) cs
->cy
= pos
[1].y
;
483 if( cs
->x
== CW_USEDEFAULT
)
489 /* restore current maximized child */
490 if( (style
& WS_VISIBLE
) && ci
->hwndChildMaximized
)
492 TRACE("Restoring current maximized child %04x\n", ci
->hwndChildMaximized
);
493 if( style
& WS_MAXIMIZE
)
494 SendMessageA(w
->hwndSelf
, WM_SETREDRAW
, FALSE
, 0L );
495 hwndMax
= ci
->hwndChildMaximized
;
496 ShowWindow( hwndMax
, SW_SHOWNOACTIVATE
);
497 if( style
& WS_MAXIMIZE
)
498 SendMessageA(w
->hwndSelf
, WM_SETREDRAW
, TRUE
, 0L );
501 if (ci
->nActiveChildren
<= MDI_MOREWINDOWSLIMIT
)
502 /* this menu is needed to set a check mark in MDI_ChildActivate */
503 if (ci
->hWindowMenu
!= 0)
504 AppendMenuA(ci
->hWindowMenu
,MF_STRING
,wIDmenu
, lpstrDef
);
506 ci
->nActiveChildren
++;
508 /* fix window style */
509 if( !(w
->dwStyle
& MDIS_ALLCHILDSTYLES
) )
511 TRACE("MDIS_ALLCHILDSTYLES is missing, fixing window style\n");
512 style
&= (WS_CHILD
| WS_CLIPSIBLINGS
| WS_MINIMIZE
| WS_MAXIMIZE
|
513 WS_CLIPCHILDREN
| WS_DISABLED
| WS_VSCROLL
| WS_HSCROLL
);
514 style
|= (WS_VISIBLE
| WS_OVERLAPPEDWINDOW
);
517 if( w
->flags
& WIN_ISWIN32
)
519 hwnd
= CreateWindowA( cs
->szClass
, cs
->szTitle
, style
,
520 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, parent
,
521 (HMENU
)wIDmenu
, cs
->hOwner
, cs
);
525 MDICREATESTRUCT16
*cs16
;
528 cs16
= SEGPTR_NEW(MDICREATESTRUCT16
);
529 STRUCT32_MDICREATESTRUCT32Ato16( cs
, cs16
);
530 title
= SEGPTR_STRDUP( cs
->szTitle
);
531 cls
= SEGPTR_STRDUP( cs
->szClass
);
532 cs16
->szTitle
= SEGPTR_GET(title
);
533 cs16
->szClass
= SEGPTR_GET(cls
);
535 hwnd
= CreateWindow16( cs
->szClass
, cs
->szTitle
, style
,
536 cs16
->x
, cs16
->y
, cs16
->cx
, cs16
->cy
, parent
,
537 (HMENU
)wIDmenu
, cs16
->hOwner
,
538 (LPVOID
)SEGPTR_GET(cs16
) );
539 SEGPTR_FREE( title
);
544 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
548 WND
* wnd
= WIN_FindWndPtr( hwnd
);
550 /* All MDI child windows have the WS_EX_MDICHILD style */
551 wnd
->dwExStyle
|= WS_EX_MDICHILD
;
553 /* If we have more than 9 windows, we must insert the new one at the
554 * 9th position in order to see it in the "Windows" menu
556 if (ci
->nActiveChildren
> MDI_MOREWINDOWSLIMIT
)
557 MDI_SwapMenuItems(wnd
->parent
, wnd
->wIDmenu
, ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1);
559 MDI_MenuModifyItem(w
,hwnd
);
561 /* Have we hit the "More Windows..." limit? If so, we must
562 * add a "More Windows..." option
564 if (ci
->nActiveChildren
== MDI_MOREWINDOWSLIMIT
+ 1)
567 LoadStringA(GetModuleHandleA("USER32"), MDI_IDS_MOREWINDOWS
, szTmp
, 50);
569 ModifyMenuA(ci
->hWindowMenu
,
570 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
,
571 MF_BYCOMMAND
| MF_STRING
,
572 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
,
576 if( (wnd
->dwStyle
& WS_MINIMIZE
) && ci
->hwndActiveChild
)
578 TRACE("Minimizing created MDI child %04x\n", hwnd
);
579 ShowWindow( hwnd
, SW_SHOWMINNOACTIVE
);
583 /* WS_VISIBLE is clear if a) the MDI client has
584 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
585 * MDICreateStruct. If so the created window is not shown nor
588 if(wnd
->dwStyle
& WS_VISIBLE
)
589 ShowWindow(hwnd
, SW_SHOW
);
591 WIN_ReleaseWndPtr(wnd
);
592 TRACE("created child - %04x\n",hwnd
);
596 ci
->nActiveChildren
--;
597 DeleteMenu(ci
->hWindowMenu
,wIDmenu
,MF_BYCOMMAND
);
598 if( IsWindow(hwndMax
) )
599 ShowWindow(hwndMax
, SW_SHOWMAXIMIZED
);
605 /**********************************************************************
606 * MDI_ChildGetMinMaxInfo
608 * Note: The rule here is that client rect of the maximized MDI child
609 * is equal to the client rect of the MDI client window.
611 static void MDI_ChildGetMinMaxInfo( WND
* clientWnd
, HWND hwnd
,
612 MINMAXINFO16
* lpMinMax
)
614 WND
* childWnd
= WIN_FindWndPtr(hwnd
);
615 RECT rect
= clientWnd
->rectClient
;
617 MapWindowPoints( clientWnd
->parent
->hwndSelf
,
618 ((MDICLIENTINFO
*)clientWnd
->wExtra
)->self
, (LPPOINT
)&rect
, 2);
619 AdjustWindowRectEx( &rect
, childWnd
->dwStyle
, 0, childWnd
->dwExStyle
);
621 lpMinMax
->ptMaxSize
.x
= rect
.right
-= rect
.left
;
622 lpMinMax
->ptMaxSize
.y
= rect
.bottom
-= rect
.top
;
624 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
625 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
627 WIN_ReleaseWndPtr(childWnd
);
629 TRACE("max rect (%i,%i - %i, %i)\n",
630 rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
634 /**********************************************************************
635 * MDI_SwitchActiveChild
637 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
640 static void MDI_SwitchActiveChild( HWND clientHwnd
, HWND childHwnd
,
643 WND
*w
= WIN_FindWndPtr(clientHwnd
);
648 hwndTo
= MDI_GetWindow(w
, childHwnd
, bNextWindow
, 0);
650 ci
= (MDICLIENTINFO
*) w
->wExtra
;
652 TRACE("from %04x, to %04x\n",childHwnd
,hwndTo
);
654 if ( !hwndTo
) goto END
; /* no window to switch to */
656 hwndPrev
= ci
->hwndActiveChild
;
658 if ( hwndTo
!= hwndPrev
)
662 if( ci
->hwndChildMaximized
)
665 w
->dwStyle
&= ~WS_VISIBLE
;
668 SetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0,
669 SWP_NOMOVE
| SWP_NOSIZE
);
671 if( bNextWindow
&& hwndPrev
)
672 SetWindowPos( hwndPrev
, HWND_BOTTOM
, 0, 0, 0, 0,
673 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
675 ShowWindow( clientHwnd
, SW_SHOW
);
678 WIN_ReleaseWndPtr(w
);
682 /**********************************************************************
685 static LRESULT
MDIDestroyChild( WND
*w_parent
, MDICLIENTINFO
*ci
,
686 HWND parent
, HWND child
,
689 WND
*childPtr
= WIN_FindWndPtr(child
);
693 if( child
== ci
->hwndActiveChild
)
695 MDI_SwitchActiveChild(parent
, child
, TRUE
);
697 if( child
== ci
->hwndActiveChild
)
699 ShowWindow( child
, SW_HIDE
);
700 if( child
== ci
->hwndChildMaximized
)
702 MDI_RestoreFrameMenu(w_parent
->parent
, child
);
703 ci
->hwndChildMaximized
= 0;
704 MDI_UpdateFrameText(w_parent
->parent
,parent
,TRUE
,NULL
);
707 MDI_ChildActivate(w_parent
, 0);
711 MDI_MenuDeleteItem(w_parent
, child
);
713 WIN_ReleaseWndPtr(childPtr
);
715 ci
->nActiveChildren
--;
717 TRACE("child destroyed - %04x\n",child
);
721 MDI_PostUpdate(GetParent(child
), ci
, SB_BOTH
+1);
722 DestroyWindow(child
);
730 /**********************************************************************
733 * Note: hWndChild is NULL when last child is being destroyed
735 static LONG
MDI_ChildActivate( WND
*clientPtr
, HWND hWndChild
)
737 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientPtr
->wExtra
;
738 HWND prevActiveWnd
= clientInfo
->hwndActiveChild
;
739 WND
*wndPtr
= WIN_FindWndPtr( hWndChild
);
740 WND
*wndPrev
= WIN_FindWndPtr( prevActiveWnd
);
741 BOOL isActiveFrameWnd
= 0;
746 if( wndPtr
->dwStyle
& WS_DISABLED
)
753 /* Don't activate if it is already active. Might happen
754 since ShowWindow DOES activate MDI children */
755 if (clientInfo
->hwndActiveChild
== hWndChild
)
761 TRACE("%04x\n", hWndChild
);
763 if( GetActiveWindow() == clientPtr
->parent
->hwndSelf
)
764 isActiveFrameWnd
= TRUE
;
766 /* deactivate prev. active child */
769 wndPrev
->dwStyle
|= WS_SYSMENU
;
770 SendMessageA( prevActiveWnd
, WM_NCACTIVATE
, FALSE
, 0L );
771 SendMessageA( prevActiveWnd
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
,
773 /* uncheck menu item */
774 if( clientInfo
->hWindowMenu
)
776 WORD wPrevID
= wndPrev
->wIDmenu
- clientInfo
->idFirstChild
;
778 if (wPrevID
< MDI_MOREWINDOWSLIMIT
)
779 CheckMenuItem( clientInfo
->hWindowMenu
,
780 wndPrev
->wIDmenu
, 0);
782 CheckMenuItem( clientInfo
->hWindowMenu
,
783 clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1, 0);
788 if( clientInfo
->hwndChildMaximized
)
790 if( clientInfo
->hwndChildMaximized
!= hWndChild
) {
792 clientInfo
->hwndActiveChild
= hWndChild
;
793 ShowWindow( hWndChild
, SW_SHOWMAXIMIZED
);
795 ShowWindow( clientInfo
->hwndActiveChild
, SW_SHOWNORMAL
);
799 clientInfo
->hwndActiveChild
= hWndChild
;
801 /* check if we have any children left */
804 if( isActiveFrameWnd
)
805 SetFocus( clientInfo
->self
);
810 /* check menu item */
811 if( clientInfo
->hWindowMenu
)
813 /* The window to be activated must be displayed in the "Windows" menu */
814 if (wndPtr
->wIDmenu
>= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
)
816 MDI_SwapMenuItems(wndPtr
->parent
, wndPtr
->wIDmenu
, clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1);
817 MDI_MenuModifyItem(wndPtr
->parent
,wndPtr
->hwndSelf
);
820 CheckMenuItem(clientInfo
->hWindowMenu
, wndPtr
->wIDmenu
, MF_CHECKED
);
822 /* bring active child to the top */
823 SetWindowPos( hWndChild
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
825 if( isActiveFrameWnd
)
827 SendMessageA( hWndChild
, WM_NCACTIVATE
, TRUE
, 0L);
828 if( GetFocus() == clientInfo
->self
)
829 SendMessageA( clientInfo
->self
, WM_SETFOCUS
,
830 (WPARAM
)clientInfo
->self
, 0L );
832 SetFocus( clientInfo
->self
);
834 SendMessageA( hWndChild
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
,
838 WIN_ReleaseWndPtr(wndPtr
);
839 WIN_ReleaseWndPtr(wndPrev
);
843 /* -------------------- MDI client window functions ------------------- */
845 /**********************************************************************
846 * CreateMDIMenuBitmap
848 static HBITMAP16
CreateMDIMenuBitmap(void)
850 HDC hDCSrc
= CreateCompatibleDC(0);
851 HDC hDCDest
= CreateCompatibleDC(hDCSrc
);
852 HBITMAP16 hbClose
= LoadBitmapA(0, MAKEINTRESOURCEA(OBM_CLOSE
) );
854 HANDLE16 hobjSrc
, hobjDest
;
856 hobjSrc
= SelectObject(hDCSrc
, hbClose
);
857 hbCopy
= CreateCompatibleBitmap(hDCSrc
,GetSystemMetrics(SM_CXSIZE
),GetSystemMetrics(SM_CYSIZE
));
858 hobjDest
= SelectObject(hDCDest
, hbCopy
);
860 BitBlt(hDCDest
, 0, 0, GetSystemMetrics(SM_CXSIZE
), GetSystemMetrics(SM_CYSIZE
),
861 hDCSrc
, GetSystemMetrics(SM_CXSIZE
), 0, SRCCOPY
);
863 SelectObject(hDCSrc
, hobjSrc
);
864 DeleteObject(hbClose
);
867 hobjSrc
= SelectObject( hDCDest
, GetStockObject(BLACK_PEN
) );
869 MoveToEx( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, 0, NULL
);
870 LineTo( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, GetSystemMetrics(SM_CYSIZE
) - 1);
872 SelectObject(hDCDest
, hobjSrc
);
873 SelectObject(hDCDest
, hobjDest
);
879 /**********************************************************************
882 static LONG
MDICascade(WND
* clientWnd
, MDICLIENTINFO
*ci
)
887 if (ci
->hwndChildMaximized
)
888 SendMessageA( clientWnd
->hwndSelf
, WM_MDIRESTORE
,
889 (WPARAM
)ci
->hwndChildMaximized
, 0);
891 if (ci
->nActiveChildren
== 0) return 0;
893 if ((ppWnd
= WIN_BuildWinArray(clientWnd
, BWA_SKIPHIDDEN
| BWA_SKIPOWNED
|
894 BWA_SKIPICONIC
, &total
)))
896 WND
** heapPtr
= ppWnd
;
899 INT delta
= 0, n
= 0;
901 if( total
< ci
->nActiveChildren
)
902 delta
= GetSystemMetrics(SM_CYICONSPACING
) +
903 GetSystemMetrics(SM_CYICON
);
905 /* walk the list (backwards) and move windows */
906 while (*ppWnd
) ppWnd
++;
907 while (ppWnd
!= heapPtr
)
910 TRACE("move %04x to (%ld,%ld) size [%ld,%ld]\n",
911 (*ppWnd
)->hwndSelf
, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
);
913 MDI_CalcDefaultChildPos(clientWnd
, n
++, pos
, delta
);
914 SetWindowPos( (*ppWnd
)->hwndSelf
, 0, pos
[0].x
, pos
[0].y
,
916 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
919 WIN_ReleaseWinArray(heapPtr
);
922 if( total
< ci
->nActiveChildren
)
923 ArrangeIconicWindows( clientWnd
->hwndSelf
);
927 /**********************************************************************
930 static void MDITile( WND
* wndClient
, MDICLIENTINFO
*ci
, WPARAM wParam
)
935 if (ci
->hwndChildMaximized
)
936 SendMessageA( wndClient
->hwndSelf
, WM_MDIRESTORE
,
937 (WPARAM
)ci
->hwndChildMaximized
, 0);
939 if (ci
->nActiveChildren
== 0) return;
941 ppWnd
= WIN_BuildWinArray(wndClient
, BWA_SKIPHIDDEN
| BWA_SKIPOWNED
| BWA_SKIPICONIC
|
942 ((wParam
& MDITILE_SKIPDISABLED
)? BWA_SKIPDISABLED
: 0), &total
);
944 TRACE("%u windows to tile\n", total
);
948 WND
** heapPtr
= ppWnd
;
953 int x
, y
, xsize
, ysize
;
954 int rows
, columns
, r
, c
, i
;
956 GetClientRect(wndClient
->hwndSelf
,&rect
);
957 rows
= (int) sqrt((double)total
);
958 columns
= total
/ rows
;
960 if( wParam
& MDITILE_HORIZONTAL
) /* version >= 3.1 */
963 rows
= columns
; /* exchange r and c */
967 if( total
!= ci
->nActiveChildren
)
969 y
= rect
.bottom
- 2 * GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
970 rect
.bottom
= ( y
- GetSystemMetrics(SM_CYICON
) < rect
.top
)? rect
.bottom
: y
;
973 ysize
= rect
.bottom
/ rows
;
974 xsize
= rect
.right
/ columns
;
976 for (x
= i
= 0, c
= 1; c
<= columns
&& *ppWnd
; c
++)
981 ysize
= rect
.bottom
/ rows
;
985 for (r
= 1; r
<= rows
&& *ppWnd
; r
++, i
++)
987 SetWindowPos((*ppWnd
)->hwndSelf
, 0, x
, y
, xsize
, ysize
,
988 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
995 WIN_ReleaseWinArray(heapPtr
);
998 if( total
< ci
->nActiveChildren
) ArrangeIconicWindows( wndClient
->hwndSelf
);
1001 /* ----------------------- Frame window ---------------------------- */
1004 /**********************************************************************
1005 * MDI_AugmentFrameMenu
1007 static BOOL
MDI_AugmentFrameMenu( MDICLIENTINFO
* ci
, WND
*frame
,
1010 WND
* child
= WIN_FindWndPtr(hChild
);
1011 HMENU hSysPopup
= 0;
1012 HBITMAP hSysMenuBitmap
= 0;
1014 TRACE("frame %p,child %04x\n",frame
,hChild
);
1016 if( !frame
->wIDmenu
|| !child
->hSysMenu
)
1018 WIN_ReleaseWndPtr(child
);
1021 WIN_ReleaseWndPtr(child
);
1023 /* create a copy of sysmenu popup and insert it into frame menu bar */
1025 if (!(hSysPopup
= LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU")))
1028 TRACE("\tgot popup %04x in sysmenu %04x\n",
1029 hSysPopup
, child
->hSysMenu
);
1031 AppendMenuA(frame
->wIDmenu
,MF_HELP
| MF_BITMAP
,
1032 SC_MINIMIZE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_MINIMIZE
) ;
1033 AppendMenuA(frame
->wIDmenu
,MF_HELP
| MF_BITMAP
,
1034 SC_RESTORE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_RESTORE
);
1036 /* In Win 95 look, the system menu is replaced by the child icon */
1038 if(TWEAK_WineLook
> WIN31_LOOK
)
1040 HICON hIcon
= GetClassLongA(hChild
, GCL_HICONSM
);
1042 hIcon
= GetClassLongA(hChild
, GCL_HICON
);
1046 HBITMAP hBitmap
, hOldBitmap
;
1048 HDC hdc
= GetDC(hChild
);
1053 cx
= GetSystemMetrics(SM_CXSMICON
);
1054 cy
= GetSystemMetrics(SM_CYSMICON
);
1055 hMemDC
= CreateCompatibleDC(hdc
);
1056 hBitmap
= CreateCompatibleBitmap(hdc
, cx
, cy
);
1057 hOldBitmap
= SelectObject(hMemDC
, hBitmap
);
1058 SetMapMode(hMemDC
, MM_TEXT
);
1059 hBrush
= CreateSolidBrush(GetSysColor(COLOR_MENU
));
1060 DrawIconEx(hMemDC
, 0, 0, hIcon
, cx
, cy
, 0, hBrush
, DI_NORMAL
);
1061 SelectObject (hMemDC
, hOldBitmap
);
1062 DeleteObject(hBrush
);
1064 ReleaseDC(hChild
, hdc
);
1065 hSysMenuBitmap
= hBitmap
;
1070 hSysMenuBitmap
= hBmpClose
;
1072 if( !InsertMenuA(frame
->wIDmenu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
1073 hSysPopup
, (LPSTR
)(DWORD
)hSysMenuBitmap
))
1075 TRACE("not inserted\n");
1076 DestroyMenu(hSysPopup
);
1080 /* The close button is only present in Win 95 look */
1081 if(TWEAK_WineLook
> WIN31_LOOK
)
1083 AppendMenuA(frame
->wIDmenu
,MF_HELP
| MF_BITMAP
,
1084 SC_CLOSE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_CLOSE
);
1087 EnableMenuItem(hSysPopup
, SC_SIZE
, MF_BYCOMMAND
| MF_GRAYED
);
1088 EnableMenuItem(hSysPopup
, SC_MOVE
, MF_BYCOMMAND
| MF_GRAYED
);
1089 EnableMenuItem(hSysPopup
, SC_MAXIMIZE
, MF_BYCOMMAND
| MF_GRAYED
);
1090 SetMenuDefaultItem(hSysPopup
, SC_CLOSE
, FALSE
);
1093 DrawMenuBar(frame
->hwndSelf
);
1098 /**********************************************************************
1099 * MDI_RestoreFrameMenu
1101 static BOOL
MDI_RestoreFrameMenu( WND
*frameWnd
, HWND hChild
)
1103 MENUITEMINFOW menuInfo
;
1104 INT nItems
= GetMenuItemCount(frameWnd
->wIDmenu
) - 1;
1105 UINT iId
= GetMenuItemID(frameWnd
->wIDmenu
,nItems
) ;
1107 TRACE("frameWnd %p,(%04x),child %04x,nIt=%d,iId=%d\n",
1108 frameWnd
,frameWnd
->hwndSelf
,hChild
,nItems
,iId
);
1110 if(!(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
1114 * Remove the system menu, If that menu is the icon of the window
1115 * as it is in win95, we have to delete the bitmap.
1117 memset(&menuInfo
, 0, sizeof(menuInfo
));
1118 menuInfo
.cbSize
= sizeof(menuInfo
);
1119 menuInfo
.fMask
= MIIM_DATA
| MIIM_TYPE
;
1121 GetMenuItemInfoW(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
);