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 HBITMAP hBmpClose
= 0;
122 static HBITMAP hBmpRestore
= 0;
124 /* ----------------- declarations ----------------- */
125 static void MDI_UpdateFrameText(WND
*, HWND
, BOOL
, LPCWSTR
);
126 static BOOL
MDI_AugmentFrameMenu(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 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
136 /* -------- Miscellaneous service functions ----------
140 static HWND
MDI_GetChildByID(WND
* wndPtr
, UINT 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 MDIClientWndProcW
, /* procW */
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 LoadStringW(GetModuleHandleA("USER32"), MDI_IDS_MOREWINDOWS
, szTmp
, sizeof(szTmp
)/sizeof(szTmp
[0]));
261 AppendMenuW(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( 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( 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
*wndParent
, MDICLIENTINFO
*ci
,
467 LPMDICREATESTRUCTA cs
, BOOL unicode
)
470 DWORD style
= cs
->style
| (WS_CHILD
| WS_CLIPSIBLINGS
);
471 HWND hwnd
, hwndMax
= 0;
472 WORD wIDmenu
= ci
->idFirstChild
+ ci
->nActiveChildren
;
473 static const WCHAR lpstrDef
[] = {'j','u','n','k','!',0};
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(wndParent
, 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 SendMessageW(wndParent
->hwndSelf
, WM_SETREDRAW
, FALSE
, 0L);
495 hwndMax
= ci
->hwndChildMaximized
;
496 ShowWindow( hwndMax
, SW_SHOWNOACTIVATE
);
497 if( style
& WS_MAXIMIZE
)
498 SendMessageW(wndParent
->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 AppendMenuW(ci
->hWindowMenu
, MF_STRING
, wIDmenu
, lpstrDef
);
506 ci
->nActiveChildren
++;
508 /* fix window style */
509 if( !(wndParent
->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( wndParent
->flags
& WIN_ISWIN32
)
521 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)cs
;
522 hwnd
= CreateWindowW( csW
->szClass
, csW
->szTitle
, style
,
523 csW
->x
, csW
->y
, csW
->cx
, csW
->cy
, wndParent
->hwndSelf
,
524 (HMENU
)wIDmenu
, csW
->hOwner
, csW
);
527 hwnd
= CreateWindowA( cs
->szClass
, cs
->szTitle
, style
,
528 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, wndParent
->hwndSelf
,
529 (HMENU
)wIDmenu
, cs
->hOwner
, cs
);
533 MDICREATESTRUCT16
*cs16
;
536 cs16
= SEGPTR_NEW(MDICREATESTRUCT16
);
537 STRUCT32_MDICREATESTRUCT32Ato16( cs
, cs16
);
538 title
= SEGPTR_STRDUP( cs
->szTitle
);
539 cls
= SEGPTR_STRDUP( cs
->szClass
);
540 cs16
->szTitle
= SEGPTR_GET(title
);
541 cs16
->szClass
= SEGPTR_GET(cls
);
543 hwnd
= CreateWindow16( cs
->szClass
, cs
->szTitle
, style
,
544 cs16
->x
, cs16
->y
, cs16
->cx
, cs16
->cy
, wndParent
->hwndSelf
,
545 (HMENU
)wIDmenu
, cs16
->hOwner
,
546 (LPVOID
)SEGPTR_GET(cs16
) );
547 SEGPTR_FREE( title
);
552 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
556 WND
* wnd
= WIN_FindWndPtr( hwnd
);
558 /* All MDI child windows have the WS_EX_MDICHILD style */
559 wnd
->dwExStyle
|= WS_EX_MDICHILD
;
561 /* If we have more than 9 windows, we must insert the new one at the
562 * 9th position in order to see it in the "Windows" menu
564 if (ci
->nActiveChildren
> MDI_MOREWINDOWSLIMIT
)
565 MDI_SwapMenuItems(wnd
->parent
, wnd
->wIDmenu
, ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1);
567 MDI_MenuModifyItem(wndParent
, hwnd
);
569 /* Have we hit the "More Windows..." limit? If so, we must
570 * add a "More Windows..." option
572 if (ci
->nActiveChildren
== MDI_MOREWINDOWSLIMIT
+ 1)
575 LoadStringW(GetModuleHandleA("USER32"), MDI_IDS_MOREWINDOWS
, szTmp
, sizeof(szTmp
)/sizeof(szTmp
[0]));
577 ModifyMenuW(ci
->hWindowMenu
,
578 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
,
579 MF_BYCOMMAND
| MF_STRING
,
580 ci
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
,
584 if( (wnd
->dwStyle
& WS_MINIMIZE
) && ci
->hwndActiveChild
)
586 TRACE("Minimizing created MDI child %04x\n", hwnd
);
587 ShowWindow( hwnd
, SW_SHOWMINNOACTIVE
);
591 /* WS_VISIBLE is clear if a) the MDI client has
592 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
593 * MDICreateStruct. If so the created window is not shown nor
596 if(wnd
->dwStyle
& WS_VISIBLE
)
597 ShowWindow(hwnd
, SW_SHOW
);
599 WIN_ReleaseWndPtr(wnd
);
600 TRACE("created child - %04x\n",hwnd
);
604 ci
->nActiveChildren
--;
605 DeleteMenu(ci
->hWindowMenu
,wIDmenu
,MF_BYCOMMAND
);
606 if( IsWindow(hwndMax
) )
607 ShowWindow(hwndMax
, SW_SHOWMAXIMIZED
);
613 /**********************************************************************
614 * MDI_ChildGetMinMaxInfo
616 * Note: The rule here is that client rect of the maximized MDI child
617 * is equal to the client rect of the MDI client window.
619 static void MDI_ChildGetMinMaxInfo( WND
* clientWnd
, HWND hwnd
,
620 MINMAXINFO
* lpMinMax
)
622 WND
* childWnd
= WIN_FindWndPtr(hwnd
);
623 RECT rect
= clientWnd
->rectClient
;
625 MapWindowPoints( clientWnd
->parent
->hwndSelf
,
626 ((MDICLIENTINFO
*)clientWnd
->wExtra
)->self
, (LPPOINT
)&rect
, 2);
627 AdjustWindowRectEx( &rect
, childWnd
->dwStyle
, 0, childWnd
->dwExStyle
);
629 lpMinMax
->ptMaxSize
.x
= rect
.right
-= rect
.left
;
630 lpMinMax
->ptMaxSize
.y
= rect
.bottom
-= rect
.top
;
632 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
633 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
635 WIN_ReleaseWndPtr(childWnd
);
637 TRACE("max rect (%i,%i - %i, %i)\n",
638 rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
642 /**********************************************************************
643 * MDI_SwitchActiveChild
645 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
648 static void MDI_SwitchActiveChild( HWND clientHwnd
, HWND childHwnd
,
651 WND
*w
= WIN_FindWndPtr(clientHwnd
);
656 hwndTo
= MDI_GetWindow(w
, childHwnd
, bNextWindow
, 0);
658 ci
= (MDICLIENTINFO
*) w
->wExtra
;
660 TRACE("from %04x, to %04x\n",childHwnd
,hwndTo
);
662 if ( !hwndTo
) goto END
; /* no window to switch to */
664 hwndPrev
= ci
->hwndActiveChild
;
666 if ( hwndTo
!= hwndPrev
)
670 if( ci
->hwndChildMaximized
)
673 w
->dwStyle
&= ~WS_VISIBLE
;
676 SetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0,
677 SWP_NOMOVE
| SWP_NOSIZE
);
679 if( bNextWindow
&& hwndPrev
)
680 SetWindowPos( hwndPrev
, HWND_BOTTOM
, 0, 0, 0, 0,
681 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
683 ShowWindow( clientHwnd
, SW_SHOW
);
686 WIN_ReleaseWndPtr(w
);
690 /**********************************************************************
693 static LRESULT
MDIDestroyChild( WND
*w_parent
, MDICLIENTINFO
*ci
,
694 HWND child
, BOOL flagDestroy
)
696 WND
*childPtr
= WIN_FindWndPtr(child
);
700 if( child
== ci
->hwndActiveChild
)
702 MDI_SwitchActiveChild(w_parent
->hwndSelf
, child
, TRUE
);
704 if( child
== ci
->hwndActiveChild
)
706 ShowWindow( child
, SW_HIDE
);
707 if( child
== ci
->hwndChildMaximized
)
709 MDI_RestoreFrameMenu(w_parent
->parent
, child
);
710 ci
->hwndChildMaximized
= 0;
711 MDI_UpdateFrameText(w_parent
->parent
, w_parent
->hwndSelf
, TRUE
, NULL
);
714 MDI_ChildActivate(w_parent
, 0);
718 MDI_MenuDeleteItem(w_parent
, child
);
720 WIN_ReleaseWndPtr(childPtr
);
722 ci
->nActiveChildren
--;
724 TRACE("child destroyed - %04x\n",child
);
728 MDI_PostUpdate(GetParent(child
), ci
, SB_BOTH
+1);
729 DestroyWindow(child
);
737 /**********************************************************************
740 * Note: hWndChild is NULL when last child is being destroyed
742 static LONG
MDI_ChildActivate( WND
*clientPtr
, HWND hWndChild
)
744 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientPtr
->wExtra
;
745 HWND prevActiveWnd
= clientInfo
->hwndActiveChild
;
746 WND
*wndPtr
= WIN_FindWndPtr( hWndChild
);
747 WND
*wndPrev
= WIN_FindWndPtr( prevActiveWnd
);
748 BOOL isActiveFrameWnd
= 0;
753 if( wndPtr
->dwStyle
& WS_DISABLED
)
760 /* Don't activate if it is already active. Might happen
761 since ShowWindow DOES activate MDI children */
762 if (clientInfo
->hwndActiveChild
== hWndChild
)
768 TRACE("%04x\n", hWndChild
);
770 if( GetActiveWindow() == clientPtr
->parent
->hwndSelf
)
771 isActiveFrameWnd
= TRUE
;
773 /* deactivate prev. active child */
776 wndPrev
->dwStyle
|= WS_SYSMENU
;
777 SendMessageA( prevActiveWnd
, WM_NCACTIVATE
, FALSE
, 0L );
778 SendMessageA( prevActiveWnd
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
,
780 /* uncheck menu item */
781 if( clientInfo
->hWindowMenu
)
783 WORD wPrevID
= wndPrev
->wIDmenu
- clientInfo
->idFirstChild
;
785 if (wPrevID
< MDI_MOREWINDOWSLIMIT
)
786 CheckMenuItem( clientInfo
->hWindowMenu
,
787 wndPrev
->wIDmenu
, 0);
789 CheckMenuItem( clientInfo
->hWindowMenu
,
790 clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1, 0);
795 if( clientInfo
->hwndChildMaximized
)
797 if( clientInfo
->hwndChildMaximized
!= hWndChild
) {
799 clientInfo
->hwndActiveChild
= hWndChild
;
800 ShowWindow( hWndChild
, SW_SHOWMAXIMIZED
);
802 ShowWindow( clientInfo
->hwndActiveChild
, SW_SHOWNORMAL
);
806 clientInfo
->hwndActiveChild
= hWndChild
;
808 /* check if we have any children left */
811 if( isActiveFrameWnd
)
812 SetFocus( clientInfo
->self
);
817 /* check menu item */
818 if( clientInfo
->hWindowMenu
)
820 /* The window to be activated must be displayed in the "Windows" menu */
821 if (wndPtr
->wIDmenu
>= clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
)
823 MDI_SwapMenuItems(wndPtr
->parent
, wndPtr
->wIDmenu
, clientInfo
->idFirstChild
+ MDI_MOREWINDOWSLIMIT
- 1);
824 MDI_MenuModifyItem(wndPtr
->parent
,wndPtr
->hwndSelf
);
827 CheckMenuItem(clientInfo
->hWindowMenu
, wndPtr
->wIDmenu
, MF_CHECKED
);
829 /* bring active child to the top */
830 SetWindowPos( hWndChild
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
832 if( isActiveFrameWnd
)
834 SendMessageA( hWndChild
, WM_NCACTIVATE
, TRUE
, 0L);
835 if( GetFocus() == clientInfo
->self
)
836 SendMessageA( clientInfo
->self
, WM_SETFOCUS
,
837 (WPARAM
)clientInfo
->self
, 0L );
839 SetFocus( clientInfo
->self
);
841 SendMessageA( hWndChild
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
,
845 WIN_ReleaseWndPtr(wndPtr
);
846 WIN_ReleaseWndPtr(wndPrev
);
850 /* -------------------- MDI client window functions ------------------- */
852 /**********************************************************************
853 * CreateMDIMenuBitmap
855 static HBITMAP
CreateMDIMenuBitmap(void)
857 HDC hDCSrc
= CreateCompatibleDC(0);
858 HDC hDCDest
= CreateCompatibleDC(hDCSrc
);
859 HBITMAP hbClose
= LoadBitmapW(0, MAKEINTRESOURCEW(OBM_CLOSE
) );
861 HBITMAP hobjSrc
, hobjDest
;
863 hobjSrc
= SelectObject(hDCSrc
, hbClose
);
864 hbCopy
= CreateCompatibleBitmap(hDCSrc
,GetSystemMetrics(SM_CXSIZE
),GetSystemMetrics(SM_CYSIZE
));
865 hobjDest
= SelectObject(hDCDest
, hbCopy
);
867 BitBlt(hDCDest
, 0, 0, GetSystemMetrics(SM_CXSIZE
), GetSystemMetrics(SM_CYSIZE
),
868 hDCSrc
, GetSystemMetrics(SM_CXSIZE
), 0, SRCCOPY
);
870 SelectObject(hDCSrc
, hobjSrc
);
871 DeleteObject(hbClose
);
874 hobjSrc
= SelectObject( hDCDest
, GetStockObject(BLACK_PEN
) );
876 MoveToEx( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, 0, NULL
);
877 LineTo( hDCDest
, GetSystemMetrics(SM_CXSIZE
) - 1, GetSystemMetrics(SM_CYSIZE
) - 1);
879 SelectObject(hDCDest
, hobjSrc
);
880 SelectObject(hDCDest
, hobjDest
);
886 /**********************************************************************
889 static LONG
MDICascade(WND
* clientWnd
, MDICLIENTINFO
*ci
)
894 if (ci
->hwndChildMaximized
)
895 SendMessageA( clientWnd
->hwndSelf
, WM_MDIRESTORE
,
896 (WPARAM
)ci
->hwndChildMaximized
, 0);
898 if (ci
->nActiveChildren
== 0) return 0;
900 if ((ppWnd
= WIN_BuildWinArray(clientWnd
, BWA_SKIPHIDDEN
| BWA_SKIPOWNED
|
901 BWA_SKIPICONIC
, &total
)))
903 WND
** heapPtr
= ppWnd
;
906 INT delta
= 0, n
= 0;
908 if( total
< ci
->nActiveChildren
)
909 delta
= GetSystemMetrics(SM_CYICONSPACING
) +
910 GetSystemMetrics(SM_CYICON
);
912 /* walk the list (backwards) and move windows */
913 while (*ppWnd
) ppWnd
++;
914 while (ppWnd
!= heapPtr
)
917 TRACE("move %04x to (%ld,%ld) size [%ld,%ld]\n",
918 (*ppWnd
)->hwndSelf
, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
);
920 MDI_CalcDefaultChildPos(clientWnd
, n
++, pos
, delta
);
921 SetWindowPos( (*ppWnd
)->hwndSelf
, 0, pos
[0].x
, pos
[0].y
,
923 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
926 WIN_ReleaseWinArray(heapPtr
);
929 if( total
< ci
->nActiveChildren
)
930 ArrangeIconicWindows( clientWnd
->hwndSelf
);
934 /**********************************************************************
937 static void MDITile( WND
* wndClient
, MDICLIENTINFO
*ci
, WPARAM wParam
)
942 if (ci
->hwndChildMaximized
)
943 SendMessageA( wndClient
->hwndSelf
, WM_MDIRESTORE
,
944 (WPARAM
)ci
->hwndChildMaximized
, 0);
946 if (ci
->nActiveChildren
== 0) return;
948 ppWnd
= WIN_BuildWinArray(wndClient
, BWA_SKIPHIDDEN
| BWA_SKIPOWNED
| BWA_SKIPICONIC
|
949 ((wParam
& MDITILE_SKIPDISABLED
)? BWA_SKIPDISABLED
: 0), &total
);
951 TRACE("%u windows to tile\n", total
);
955 WND
** heapPtr
= ppWnd
;
960 int x
, y
, xsize
, ysize
;
961 int rows
, columns
, r
, c
, i
;
963 GetClientRect(wndClient
->hwndSelf
,&rect
);
964 rows
= (int) sqrt((double)total
);
965 columns
= total
/ rows
;
967 if( wParam
& MDITILE_HORIZONTAL
) /* version >= 3.1 */
970 rows
= columns
; /* exchange r and c */
974 if( total
!= ci
->nActiveChildren
)
976 y
= rect
.bottom
- 2 * GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
977 rect
.bottom
= ( y
- GetSystemMetrics(SM_CYICON
) < rect
.top
)? rect
.bottom
: y
;
980 ysize
= rect
.bottom
/ rows
;
981 xsize
= rect
.right
/ columns
;
983 for (x
= i
= 0, c
= 1; c
<= columns
&& *ppWnd
; c
++)
988 ysize
= rect
.bottom
/ rows
;
992 for (r
= 1; r
<= rows
&& *ppWnd
; r
++, i
++)
994 SetWindowPos((*ppWnd
)->hwndSelf
, 0, x
, y
, xsize
, ysize
,
995 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
1002 WIN_ReleaseWinArray(heapPtr
);
1005 if( total
< ci
->nActiveChildren
) ArrangeIconicWindows( wndClient
->hwndSelf
);
1008 /* ----------------------- Frame window ---------------------------- */
1011 /**********************************************************************
1012 * MDI_AugmentFrameMenu
1014 static BOOL
MDI_AugmentFrameMenu( WND
*frame
, HWND hChild
)
1016 WND
* child
= WIN_FindWndPtr(hChild
);
1017 HMENU hSysPopup
= 0;
1018 HBITMAP hSysMenuBitmap
= 0;
1020 TRACE("frame %p,child %04x\n",frame
,hChild
);
1022 if( !frame
->wIDmenu
|| !child
->hSysMenu
)
1024 WIN_ReleaseWndPtr(child
);
1027 WIN_ReleaseWndPtr(child
);
1029 /* create a copy of sysmenu popup and insert it into frame menu bar */
1031 if (!(hSysPopup
= LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU")))
1034 TRACE("\tgot popup %04x in sysmenu %04x\n",
1035 hSysPopup
, child
->hSysMenu
);
1037 AppendMenuA(frame
->wIDmenu
,MF_HELP
| MF_BITMAP
,
1038 SC_MINIMIZE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_MINIMIZE
) ;
1039 AppendMenuA(frame
->wIDmenu
,MF_HELP
| MF_BITMAP
,
1040 SC_RESTORE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_RESTORE
);
1042 /* In Win 95 look, the system menu is replaced by the child icon */
1044 if(TWEAK_WineLook
> WIN31_LOOK
)
1046 HICON hIcon
= GetClassLongA(hChild
, GCL_HICONSM
);
1048 hIcon
= GetClassLongA(hChild
, GCL_HICON
);
1052 HBITMAP hBitmap
, hOldBitmap
;
1054 HDC hdc
= GetDC(hChild
);
1059 cx
= GetSystemMetrics(SM_CXSMICON
);
1060 cy
= GetSystemMetrics(SM_CYSMICON
);
1061 hMemDC
= CreateCompatibleDC(hdc
);
1062 hBitmap
= CreateCompatibleBitmap(hdc
, cx
, cy
);
1063 hOldBitmap
= SelectObject(hMemDC
, hBitmap
);
1064 SetMapMode(hMemDC
, MM_TEXT
);
1065 hBrush
= CreateSolidBrush(GetSysColor(COLOR_MENU
));
1066 DrawIconEx(hMemDC
, 0, 0, hIcon
, cx
, cy
, 0, hBrush
, DI_NORMAL
);
1067 SelectObject (hMemDC
, hOldBitmap
);
1068 DeleteObject(hBrush
);
1070 ReleaseDC(hChild
, hdc
);
1071 hSysMenuBitmap
= hBitmap
;
1076 hSysMenuBitmap
= hBmpClose
;
1078 if( !InsertMenuA(frame
->wIDmenu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
1079 hSysPopup
, (LPSTR
)(DWORD
)hSysMenuBitmap
))
1081 TRACE("not inserted\n");
1082 DestroyMenu(hSysPopup
);
1086 /* The close button is only present in Win 95 look */
1087 if(TWEAK_WineLook
> WIN31_LOOK
)
1089 AppendMenuA(frame
->wIDmenu
,MF_HELP
| MF_BITMAP
,
1090 SC_CLOSE
, (LPSTR
)(DWORD
)HBMMENU_MBAR_CLOSE
);
1093 EnableMenuItem(hSysPopup
, SC_SIZE
, MF_BYCOMMAND
| MF_GRAYED
);
1094 EnableMenuItem(hSysPopup
, SC_MOVE
, MF_BYCOMMAND
| MF_GRAYED
);
1095 EnableMenuItem(hSysPopup
, SC_MAXIMIZE
, MF_BYCOMMAND
| MF_GRAYED
);
1096 SetMenuDefaultItem(hSysPopup
, SC_CLOSE
, FALSE
);
1099 DrawMenuBar(frame
->hwndSelf
);
1104 /**********************************************************************
1105 * MDI_RestoreFrameMenu
1107 static BOOL
MDI_RestoreFrameMenu( WND
*frameWnd
, HWND hChild
)
1109 MENUITEMINFOW menuInfo
;
1110 INT nItems
= GetMenuItemCount(frameWnd
->wIDmenu
) - 1;
1111 UINT iId
= GetMenuItemID(frameWnd
->wIDmenu
,nItems
) ;
1113 TRACE("frameWnd %p,(%04x),child %04x,nIt=%d,iId=%d\n",
1114 frameWnd
,frameWnd
->hwndSelf
,hChild
,nItems
,iId
);
1116 if(!(iId
== SC_RESTORE
|| iId
== SC_CLOSE
) )
1120 * Remove the system menu, If that menu is the icon of the window
1121 * as it is in win95, we have to delete the bitmap.
1123 memset(&menuInfo
, 0, sizeof(menuInfo
));
1124 menuInfo
.cbSize
= sizeof(menuInfo
);
1125 menuInfo
.fMask
= MIIM_DATA
| MIIM_TYPE
;
1127 GetMenuItemInfoW(frameWnd
->wIDmenu
,
1132 RemoveMenu(frameWnd
->wIDmenu
,0,MF_BYPOSITION
);
1134 if ( (menuInfo
.fType
& MFT_BITMAP
) &&
1135 (LOWORD(menuInfo
.dwTypeData
)!=0) &&
1136 (LOWORD(menuInfo
.dwTypeData
)!=hBmpClose
) )
1138 DeleteObject((HBITMAP
)LOWORD(menuInfo
.dwTypeData
));
1141 if(TWEAK_WineLook
> WIN31_LOOK
)
1144 DeleteMenu(frameWnd
->wIDmenu
,GetMenuItemCount(frameWnd
->wIDmenu
) - 1,MF_BYPOSITION
);
1147 DeleteMenu(frameWnd
->wIDmenu
,GetMenuItemCount(frameWnd
->wIDmenu
) - 1,MF_BYPOSITION
);
1149 DeleteMenu(frameWnd
->wIDmenu
,GetMenuItemCount(frameWnd
->wIDmenu
) - 1,MF_BYPOSITION
);
1151 DrawMenuBar(frameWnd
->hwndSelf
);
1157 /**********************************************************************
1158 * MDI_UpdateFrameText
1160 * used when child window is maximized/restored
1162 * Note: lpTitle can be NULL
1164 static void MDI_UpdateFrameText( WND
*frameWnd
, HWND hClient
,
1165 BOOL repaint
, LPCWSTR lpTitle
)
1167 WCHAR lpBuffer
[MDI_MAXTITLELENGTH
+1];
1168 WND
* clientWnd
= WIN_FindWndPtr(hClient
);
1169 MDICLIENTINFO
*ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1171 TRACE("repaint %i, frameText %s\n", repaint
, (lpTitle
)?debugstr_w(lpTitle
):"NULL");
1178 WIN_ReleaseWndPtr(clientWnd
);
1182 /* store new "default" title if lpTitle is not NULL */
1185 if (ci
->frameTitle
) HeapFree( GetProcessHeap(), 0, ci
->frameTitle
);
1186 ci
->frameTitle
= HEAP_strdupW( GetProcessHeap(), 0, lpTitle
);
1191 WND
* childWnd
= WIN_FindWndPtr( ci
->hwndChildMaximized
);
1193 if( childWnd
&& childWnd
->text
)
1195 /* combine frame title and child title if possible */
1197 static const WCHAR lpBracket
[] = {' ','-',' ','[',0};
1198 static const WCHAR lpBracket2
[] = {']',0};
1199 int i_frame_text_length
= strlenW(ci
->frameTitle
);
1200 int i_child_text_length
= strlenW(childWnd
->text
);
1202 lstrcpynW( lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
1204 if( i_frame_text_length
+ 6 < MDI_MAXTITLELENGTH
)
1206 strcatW( lpBuffer
, lpBracket
);
1208 if( i_frame_text_length
+ i_child_text_length
+ 6 < MDI_MAXTITLELENGTH
)
1210 strcatW( lpBuffer
, childWnd
->text
);
1211 strcatW( lpBuffer
, lpBracket2
);
1215 lstrcpynW( lpBuffer
+ i_frame_text_length
+ 4,
1216 childWnd
->text
, MDI_MAXTITLELENGTH
- i_frame_text_length
- 5 );
1217 strcatW( lpBuffer
, lpBracket2
);
1223 lstrcpynW(lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
+1 );
1225 WIN_ReleaseWndPtr(childWnd
);
1231 DEFWND_SetTextW( frameWnd
, lpBuffer
);
1232 if( repaint
== MDI_REPAINTFRAME
)
1233 SetWindowPos( frameWnd
->hwndSelf
, 0,0,0,0,0, SWP_FRAMECHANGED
|
1234 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
1236 WIN_ReleaseWndPtr(clientWnd
);
1241 /* ----------------------------- Interface ---------------------------- */
1244 /**********************************************************************
1245 * MDIClientWndProc_locked
1247 static LRESULT WINAPI
MDIClientWndProc_locked( WND
*wndPtr
, UINT message
,
1248 WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
1256 LRESULT (WINAPI
*pSendMessage
)(HWND
, UINT
, WPARAM
, LPARAM
);
1258 pSendMessage
= unicode
? SendMessageW
: SendMessageA
;
1263 if ( ( frameWnd
= WIN_LockWndPtr(wndPtr
->parent
) ) == NULL
)
1266 ci
= (MDICLIENTINFO
*) wndPtr
->wExtra
;
1271 /* Since we are using only cs->lpCreateParams, we can safely
1272 * cast to LPCREATESTRUCTA here */
1273 cs
= (LPCREATESTRUCTA
)lParam
;
1275 /* Translation layer doesn't know what's in the cs->lpCreateParams
1276 * so we have to keep track of what environment we're in. */
1278 if( wndPtr
->flags
& WIN_ISWIN32
)
1280 #define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1281 ci
->hWindowMenu
= ccs
->hWindowMenu
;
1282 ci
->idFirstChild
= ccs
->idFirstChild
;
1287 LPCLIENTCREATESTRUCT16 ccs
= MapSL((SEGPTR
)cs
->lpCreateParams
);
1288 ci
->hWindowMenu
= ccs
->hWindowMenu
;
1289 ci
->idFirstChild
= ccs
->idFirstChild
;
1292 ci
->hwndChildMaximized
= 0;
1293 ci
->nActiveChildren
= 0;
1294 ci
->nTotalCreated
= 0;
1295 ci
->frameTitle
= NULL
;
1297 ci
->self
= wndPtr
->hwndSelf
;
1298 wndPtr
->dwStyle
|= WS_CLIPCHILDREN
;
1302 hBmpClose
= CreateMDIMenuBitmap();
1303 hBmpRestore
= LoadBitmapW( 0, MAKEINTRESOURCEW(OBM_RESTORE
) );
1305 MDI_UpdateFrameText(frameWnd
, wndPtr
->hwndSelf
, MDI_NOFRAMEREPAINT
, frameWnd
->text
);
1307 if (ci
->hWindowMenu
!= 0)
1308 AppendMenuW( ci
->hWindowMenu
, MF_SEPARATOR
, 0, NULL
);
1310 GetClientRect(frameWnd
->hwndSelf
, &rect
);
1311 NC_HandleNCCalcSize( wndPtr
, &rect
);
1312 wndPtr
->rectClient
= rect
;
1314 TRACE("Client created - hwnd = %04x, idFirst = %u\n",
1315 wndPtr
->hwndSelf
, ci
->idFirstChild
);
1321 if( ci
->hwndChildMaximized
)
1322 MDI_RestoreFrameMenu(wndPtr
->parent
, ci
->hwndChildMaximized
);
1323 if((ci
->hWindowMenu
!= 0) &&
1324 (nItems
= GetMenuItemCount(ci
->hWindowMenu
)) > 0)
1326 ci
->idFirstChild
= nItems
- 1;
1327 ci
->nActiveChildren
++; /* to delete a separator */
1328 while( ci
->nActiveChildren
-- )
1329 DeleteMenu(ci
->hWindowMenu
,MF_BYPOSITION
,ci
->idFirstChild
--);
1334 case WM_MDIACTIVATE
:
1335 if( ci
->hwndActiveChild
!= (HWND
)wParam
)
1336 SetWindowPos((HWND
)wParam
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1341 retvalue
= MDICascade(wndPtr
, ci
);
1345 if (lParam
) retvalue
= MDICreateChild( wndPtr
, ci
,
1346 (MDICREATESTRUCTA
*)lParam
, unicode
);
1351 retvalue
= MDIDestroyChild( wndPtr
, ci
, (HWND
)wParam
, TRUE
);
1354 case WM_MDIGETACTIVE
:
1355 if (lParam
) *(BOOL
*)lParam
= (ci
->hwndChildMaximized
> 0);
1356 retvalue
= ci
->hwndActiveChild
;
1359 case WM_MDIICONARRANGE
:
1360 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1361 ArrangeIconicWindows(wndPtr
->hwndSelf
);
1362 ci
->sbRecalc
= SB_BOTH
+1;
1363 pSendMessage(wndPtr
->hwndSelf
, WM_MDICALCCHILDSCROLL
, 0, 0L);
1367 case WM_MDIMAXIMIZE
:
1368 ShowWindow( (HWND
)wParam
, SW_MAXIMIZE
);
1372 case WM_MDINEXT
: /* lParam != 0 means previous window */
1373 MDI_SwitchActiveChild(wndPtr
->hwndSelf
, (HWND
)wParam
, (lParam
)? FALSE
: TRUE
);
1377 pSendMessage( (HWND
)wParam
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
1382 retvalue
= MDISetMenu( wndPtr
->hwndSelf
, (HMENU
)wParam
, (HMENU
)lParam
);
1385 case WM_MDIREFRESHMENU
:
1386 retvalue
= MDIRefreshMenu( wndPtr
->hwndSelf
, (HMENU
)wParam
, (HMENU
)lParam
);
1390 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1391 ShowScrollBar(wndPtr
->hwndSelf
, SB_BOTH
, FALSE
);
1392 MDITile(wndPtr
, ci
, wParam
);
1393 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1399 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
1400 ScrollChildren(wndPtr
->hwndSelf
, message
, wParam
, lParam
);
1401 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1406 if( ci
->hwndActiveChild
)
1408 WND
* pw
= WIN_FindWndPtr( ci
->hwndActiveChild
);
1409 if( !(pw
->dwStyle
& WS_MINIMIZE
) )
1410 SetFocus( pw
->hwndSelf
);
1411 WIN_ReleaseWndPtr(pw
);
1417 if( ci
->hwndActiveChild
)
1418 pSendMessage(ci
->hwndActiveChild
, message
, wParam
, lParam
);
1421 case WM_PARENTNOTIFY
:
1422 if (LOWORD(wParam
) == WM_LBUTTONDOWN
)
1426 pt
.x
= SLOWORD(lParam
);
1427 pt
.y
= SHIWORD(lParam
);
1428 child
= ChildWindowFromPoint(wndPtr
->hwndSelf
, pt
);
1430 TRACE("notification from %04x (%li,%li)\n",child
,pt
.x
,pt
.y
);
1432 if( child
&& child
!= wndPtr
->hwndSelf
&& child
!= ci
->hwndActiveChild
)
1433 SetWindowPos(child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1439 if( IsWindow(ci
->hwndChildMaximized
) )
1441 WND
* child
= WIN_FindWndPtr(ci
->hwndChildMaximized
);
1446 rect
.right
= LOWORD(lParam
);
1447 rect
.bottom
= HIWORD(lParam
);
1449 AdjustWindowRectEx(&rect
, child
->dwStyle
, 0, child
->dwExStyle
);
1450 MoveWindow(ci
->hwndChildMaximized
, rect
.left
, rect
.top
,
1451 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 1);
1452 WIN_ReleaseWndPtr(child
);
1455 MDI_PostUpdate(wndPtr
->hwndSelf
, ci
, SB_BOTH
+1);
1459 case WM_MDICALCCHILDSCROLL
:
1460 if( (ci
->mdiFlags
& MDIF_NEEDUPDATE
) && ci
->sbRecalc
)
1462 CalcChildScroll(wndPtr
->hwndSelf
, ci
->sbRecalc
-1);
1464 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1470 retvalue
= unicode
? DefWindowProcW( wndPtr
->hwndSelf
, message
, wParam
, lParam
) :
1471 DefWindowProcA( wndPtr
->hwndSelf
, message
, wParam
, lParam
);
1473 WIN_ReleaseWndPtr(frameWnd
);
1477 /***********************************************************************
1480 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1483 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1485 res
= MDIClientWndProc_locked(wndPtr
, message
, wParam
, lParam
, FALSE
);
1487 WIN_ReleaseWndPtr(wndPtr
);
1491 /***********************************************************************
1494 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1497 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1499 res
= MDIClientWndProc_locked(wndPtr
, message
, wParam
, lParam
, TRUE
);
1501 WIN_ReleaseWndPtr(wndPtr
);
1505 /***********************************************************************
1506 * DefFrameProc (USER.445)
1508 LRESULT WINAPI
DefFrameProc16( HWND16 hwnd
, HWND16 hwndMDIClient
,
1509 UINT16 message
, WPARAM16 wParam
, LPARAM lParam
)
1520 wndPtr
= WIN_FindWndPtr(hwndMDIClient
);
1523 ERR("null wndPtr for mdi window hwndMDIClient=%04x\n",
1528 ci
= (MDICLIENTINFO
*)wndPtr
->wExtra
;
1530 /* check for possible syscommands for maximized MDI child */
1531 WIN_ReleaseWndPtr(wndPtr
);
1534 wParam
< ci
->idFirstChild
||
1535 wParam
>= ci
->idFirstChild
+ ci
->nActiveChildren
1537 if( (wParam
- 0xF000) & 0xF00F ) break;
1548 if( ci
->hwndChildMaximized
)
1549 return SendMessage16( ci
->hwndChildMaximized
, WM_SYSCOMMAND
,
1555 wndPtr
= WIN_FindWndPtr(hwndMDIClient
);
1556 ci
= (MDICLIENTINFO
*)wndPtr
->wExtra
;
1558 if (wParam
- ci
->idFirstChild
== MDI_MOREWINDOWSLIMIT
)
1559 /* User chose "More Windows..." */
1560 childHwnd
= MDI_MoreWindowsDialog(wndPtr
);
1562 /* User chose one of the windows listed in the "Windows" menu */
1563 childHwnd
= MDI_GetChildByID(wndPtr
,wParam
);
1565 WIN_ReleaseWndPtr(wndPtr
);
1567 SendMessage16(hwndMDIClient
, WM_MDIACTIVATE
,
1568 (WPARAM16
)childHwnd
, 0L);
1573 SendMessage16(hwndMDIClient
, message
, wParam
, lParam
);
1578 LPWSTR text
= HEAP_strdupAtoW( GetProcessHeap(), 0, MapSL(lParam
) );
1579 wndPtr
= WIN_FindWndPtr(hwnd
);
1580 MDI_UpdateFrameText(wndPtr
, hwndMDIClient
,
1581 MDI_REPAINTFRAME
, text
);
1582 WIN_ReleaseWndPtr(wndPtr
);
1583 HeapFree( GetProcessHeap(), 0, text
);
1585 return 1; /* success. FIXME: check text length */
1588 SetFocus(hwndMDIClient
);
1592 MoveWindow16(hwndMDIClient
, 0, 0,
1593 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1598 wndPtr
= WIN_FindWndPtr(hwndMDIClient
);
1599 ci
= (MDICLIENTINFO
*)wndPtr
->wExtra
;
1601 if( !(wndPtr
->parent
->dwStyle
& WS_MINIMIZE
)
1602 && ci
->hwndActiveChild
&& !ci
->hwndChildMaximized
)
1604 /* control menu is between the frame system menu and
1605 * the first entry of menu bar */
1607 if( (wParam
== VK_LEFT
&&
1608 wndPtr
->parent
->wIDmenu
== LOWORD(lParam
)) ||
1609 (wParam
== VK_RIGHT
&&
1610 GetSubMenu16(wndPtr
->parent
->hSysMenu
, 0) == LOWORD(lParam
)) )
1613 WIN_ReleaseWndPtr(wndPtr
);
1614 wndPtr
= WIN_FindWndPtr(ci
->hwndActiveChild
);
1615 retvalue
= MAKELONG( GetSubMenu16(wndPtr
->hSysMenu
, 0),
1616 ci
->hwndActiveChild
);
1617 WIN_ReleaseWndPtr(wndPtr
);
1621 WIN_ReleaseWndPtr(wndPtr
);
1626 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1630 /***********************************************************************
1631 * DefFrameProcA (USER32.@)
1633 LRESULT WINAPI
DefFrameProcA( HWND hwnd
, HWND hwndMDIClient
,
1634 UINT message
, WPARAM wParam
, LPARAM lParam
)
1641 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1643 MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ) );
1646 SendMessageA(hwndMDIClient
, message
, wParam
, lParam
);
1651 LPSTR segstr
= SEGPTR_STRDUP((LPSTR
)lParam
);
1653 ret
= DefFrameProc16(hwnd
, hwndMDIClient
, message
,
1654 wParam
, (LPARAM
)SEGPTR_GET(segstr
) );
1655 SEGPTR_FREE(segstr
);
1662 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1667 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1671 /***********************************************************************
1672 * DefFrameProcW (USER32.@)
1674 LRESULT WINAPI
DefFrameProcW( HWND hwnd
, HWND hwndMDIClient
,
1675 UINT message
, WPARAM wParam
, LPARAM lParam
)
1682 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1684 MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ) );
1687 SendMessageW(hwndMDIClient
, message
, wParam
, lParam
);
1692 LPSTR txt
= HEAP_strdupWtoA(GetProcessHeap(),0,(LPWSTR
)lParam
);
1693 LRESULT ret
= DefFrameProcA( hwnd
, hwndMDIClient
, message
,
1694 wParam
, (DWORD
)txt
);
1695 HeapFree(GetProcessHeap(),0,txt
);
1701 return DefFrameProcA( hwnd
, hwndMDIClient
, message
,
1706 return DefWindowProcW( hwnd
, message
, wParam
, lParam
);
1710 /***********************************************************************
1711 * DefMDIChildProc (USER.447)
1713 LRESULT WINAPI
DefMDIChildProc16( HWND16 hwnd
, UINT16 message
,
1714 WPARAM16 wParam
, LPARAM lParam
)
1717 WND
*clientWnd
,*tmpWnd
= 0;
1720 tmpWnd
= WIN_FindWndPtr(hwnd
);
1721 if (!tmpWnd
) return 0;
1722 clientWnd
= WIN_FindWndPtr(tmpWnd
->parent
->hwndSelf
);
1723 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1724 WIN_ReleaseWndPtr(tmpWnd
);
1727 if (clientWnd
->cbWndExtra
< sizeof(MDICLIENTINFO
))
1729 WARN("called on non-MDI child window %x\n", hwnd
);
1730 WIN_ReleaseWndPtr(clientWnd
);
1731 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1737 DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1738 MDI_MenuModifyItem(clientWnd
,hwnd
);
1739 if( ci
->hwndChildMaximized
== hwnd
)
1740 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1741 MDI_REPAINTFRAME
, NULL
);
1742 retvalue
= 1; /* success. FIXME: check text length */
1746 SendMessage16(ci
->self
,WM_MDIDESTROY
,(WPARAM16
)hwnd
,0L);
1751 if( ci
->hwndActiveChild
!= hwnd
)
1752 MDI_ChildActivate(clientWnd
, hwnd
);
1755 case WM_CHILDACTIVATE
:
1756 MDI_ChildActivate(clientWnd
, hwnd
);
1761 TRACE("WM_NCPAINT for %04x, active %04x\n",
1762 hwnd
, ci
->hwndActiveChild
);
1769 if( ci
->hwndChildMaximized
== hwnd
)
1777 tmpWnd
= WIN_FindWndPtr(hwnd
);
1778 tmpWnd
->dwStyle
|= WS_SYSMENU
;
1779 WIN_ReleaseWndPtr(tmpWnd
);
1782 if( ci
->hwndChildMaximized
== hwnd
)
1784 retvalue
= SendMessage16( clientWnd
->parent
->hwndSelf
,
1785 message
, wParam
, lParam
);
1788 tmpWnd
= WIN_FindWndPtr(hwnd
);
1789 tmpWnd
->dwStyle
&= ~WS_SYSMENU
;
1790 WIN_ReleaseWndPtr(tmpWnd
);
1793 SendMessage16( ci
->self
, WM_MDINEXT
, 0, 0);
1797 SendMessage16( ci
->self
, WM_MDINEXT
, 0, 1);
1803 case WM_GETMINMAXINFO
:
1805 MINMAXINFO16
*mmi16
= (MINMAXINFO16
*)MapSL(lParam
);
1807 STRUCT32_MINMAXINFO16to32( mmi16
, &mmi
);
1808 MDI_ChildGetMinMaxInfo( clientWnd
, hwnd
, &mmi
);
1809 STRUCT32_MINMAXINFO32to16( &mmi
, mmi16
);
1815 if( ci
->hwndChildMaximized
) ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1817 MDI_PostUpdate(clientWnd
->hwndSelf
, ci
, SB_BOTH
+1);
1823 if( ci
->hwndActiveChild
== hwnd
&& wParam
!= SIZE_MAXIMIZED
)
1825 ci
->hwndChildMaximized
= 0;
1827 MDI_RestoreFrameMenu( clientWnd
->parent
, hwnd
);
1828 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1829 MDI_REPAINTFRAME
, NULL
);
1832 if( wParam
== SIZE_MAXIMIZED
)
1834 HWND16 hMaxChild
= ci
->hwndChildMaximized
;
1836 if( hMaxChild
== hwnd
) break;
1840 SendMessage16( hMaxChild
, WM_SETREDRAW
, FALSE
, 0L );
1842 MDI_RestoreFrameMenu( clientWnd
->parent
, hMaxChild
);
1843 ShowWindow16( hMaxChild
, SW_SHOWNOACTIVATE
);
1845 SendMessage16( hMaxChild
, WM_SETREDRAW
, TRUE
, 0L );
1848 TRACE("maximizing child %04x\n", hwnd
);
1851 * Keep track of the maximized window.
1853 ci
->hwndChildMaximized
= hwnd
; /* !!! */
1856 * The maximized window should also be the active window
1858 MDI_ChildActivate(clientWnd
, hwnd
);
1860 MDI_AugmentFrameMenu( clientWnd
->parent
, hwnd
);
1861 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1862 MDI_REPAINTFRAME
, NULL
);
1865 if( wParam
== SIZE_MINIMIZED
)
1867 HWND16 switchTo
= MDI_GetWindow(clientWnd
, hwnd
, TRUE
, WS_MINIMIZE
);
1870 SendMessage16( switchTo
, WM_CHILDACTIVATE
, 0, 0L);
1873 MDI_PostUpdate(clientWnd
->hwndSelf
, ci
, SB_BOTH
+1);
1878 /* MDI children don't have menu bars */
1879 retvalue
= 0x00010000L
;
1884 if( wParam
== VK_LEFT
) /* switch to frame system menu */
1886 retvalue
= MAKELONG( GetSubMenu16(clientWnd
->parent
->hSysMenu
, 0),
1887 clientWnd
->parent
->hwndSelf
);
1890 if( wParam
== VK_RIGHT
) /* to frame menu bar */
1892 retvalue
= MAKELONG( clientWnd
->parent
->wIDmenu
,
1893 clientWnd
->parent
->hwndSelf
);
1902 SendMessage16(hwnd
,WM_SYSCOMMAND
,
1903 (WPARAM16
)SC_KEYMENU
, (LPARAM
)(DWORD
)VK_SPACE
);
1909 retvalue
= DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1911 WIN_ReleaseWndPtr(clientWnd
);
1916 /***********************************************************************
1917 * DefMDIChildProcA (USER32.@)
1919 LRESULT WINAPI
DefMDIChildProcA( HWND hwnd
, UINT message
,
1920 WPARAM wParam
, LPARAM lParam
)
1923 WND
*clientWnd
,*tmpWnd
;
1926 tmpWnd
= WIN_FindWndPtr(hwnd
);
1927 if (!tmpWnd
) return 0;
1928 clientWnd
= WIN_FindWndPtr(tmpWnd
->parent
->hwndSelf
);
1929 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1930 WIN_ReleaseWndPtr(tmpWnd
);
1933 if (clientWnd
->cbWndExtra
< sizeof(MDICLIENTINFO
))
1935 WARN("called on non-MDI child window %x\n", hwnd
);
1936 WIN_ReleaseWndPtr(clientWnd
);
1937 return DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1943 DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1944 MDI_MenuModifyItem(clientWnd
,hwnd
);
1945 if( ci
->hwndChildMaximized
== hwnd
)
1946 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1947 MDI_REPAINTFRAME
, NULL
);
1948 retvalue
= 1; /* success. FIXME: check text length */
1951 case WM_GETMINMAXINFO
:
1952 MDI_ChildGetMinMaxInfo( clientWnd
, hwnd
, (MINMAXINFO
*)lParam
);
1958 /* MDI children don't have menu bars */
1959 retvalue
= 0x00010000L
;
1964 case WM_CHILDACTIVATE
:
1970 retvalue
= DefMDIChildProc16( hwnd
, message
, (WPARAM16
)wParam
, lParam
);
1976 SendMessageA(hwnd
,WM_SYSCOMMAND
,
1977 (WPARAM
)SC_KEYMENU
, (LPARAM
)(DWORD
)VK_SPACE
);
1982 retvalue
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
1984 WIN_ReleaseWndPtr(clientWnd
);
1989 /***********************************************************************
1990 * DefMDIChildProcW (USER32.@)
1992 LRESULT WINAPI
DefMDIChildProcW( HWND hwnd
, UINT message
,
1993 WPARAM wParam
, LPARAM lParam
)
1996 WND
*clientWnd
,*tmpWnd
;
1999 tmpWnd
= WIN_FindWndPtr(hwnd
);
2000 if (!tmpWnd
) return 0;
2001 clientWnd
= WIN_FindWndPtr(tmpWnd
->parent
->hwndSelf
);
2002 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
2003 WIN_ReleaseWndPtr(tmpWnd
);
2006 if (clientWnd
->cbWndExtra
< sizeof(MDICLIENTINFO
))
2008 WARN("called on non-MDI child window %x\n", hwnd
);
2009 WIN_ReleaseWndPtr(clientWnd
);
2010 return DefWindowProcW(hwnd
, message
, wParam
, lParam
);
2016 DefWindowProcW(hwnd
, message
, wParam
, lParam
);
2017 MDI_MenuModifyItem(clientWnd
,hwnd
);
2018 if( ci
->hwndChildMaximized
== hwnd
)
2019 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
2020 MDI_REPAINTFRAME
, NULL
);
2021 retvalue
= 1; /* success. FIXME: check text length */
2024 case WM_GETMINMAXINFO
:
2028 case WM_CHILDACTIVATE
:
2034 retvalue
= DefMDIChildProcA( hwnd
, message
, (WPARAM16
)wParam
, lParam
);
2040 SendMessageW(hwnd
,WM_SYSCOMMAND
,
2041 (WPARAM
)SC_KEYMENU
, (LPARAM
)(DWORD
)VK_SPACE
);
2046 retvalue
= DefWindowProcW(hwnd
, message
, wParam
, lParam
);
2048 WIN_ReleaseWndPtr(clientWnd
);
2053 /**********************************************************************
2054 * CreateMDIWindowA (USER32.@) Creates a MDI child
2057 * Success: Handle to created window
2060 HWND WINAPI
CreateMDIWindowA(
2061 LPCSTR lpClassName
, /* [in] Pointer to registered child class name */
2062 LPCSTR lpWindowName
, /* [in] Pointer to window name */
2063 DWORD dwStyle
, /* [in] Window style */
2064 INT X
, /* [in] Horizontal position of window */
2065 INT Y
, /* [in] Vertical position of window */
2066 INT nWidth
, /* [in] Width of window */
2067 INT nHeight
, /* [in] Height of window */
2068 HWND hWndParent
, /* [in] Handle to parent window */
2069 HINSTANCE hInstance
, /* [in] Handle to application instance */
2070 LPARAM lParam
) /* [in] Application-defined value */
2073 MDICREATESTRUCTA cs
;
2074 WND
*pWndParent
= WIN_FindWndPtr(hWndParent
);
2077 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
2078 debugstr_a(lpClassName
),debugstr_a(lpWindowName
),dwStyle
,X
,Y
,
2079 nWidth
,nHeight
,hWndParent
,hInstance
,lParam
);
2083 ERR("bad hwnd for MDI-client: %04x\n", hWndParent
);
2086 cs
.szClass
=lpClassName
;
2087 cs
.szTitle
=lpWindowName
;
2088 cs
.hOwner
=hInstance
;
2096 pCi
= (MDICLIENTINFO
*)pWndParent
->wExtra
;
2098 retvalue
= MDICreateChild(pWndParent
, pCi
, &cs
, FALSE
);
2099 WIN_ReleaseWndPtr(pWndParent
);
2103 /***********************************************************************
2104 * CreateMDIWindowW (USER32.@) Creates a MDI child
2107 * Success: Handle to created window
2110 HWND WINAPI
CreateMDIWindowW(
2111 LPCWSTR lpClassName
, /* [in] Pointer to registered child class name */
2112 LPCWSTR lpWindowName
, /* [in] Pointer to window name */
2113 DWORD dwStyle
, /* [in] Window style */
2114 INT X
, /* [in] Horizontal position of window */
2115 INT Y
, /* [in] Vertical position of window */
2116 INT nWidth
, /* [in] Width of window */
2117 INT nHeight
, /* [in] Height of window */
2118 HWND hWndParent
, /* [in] Handle to parent window */
2119 HINSTANCE hInstance
, /* [in] Handle to application instance */
2120 LPARAM lParam
) /* [in] Application-defined value */
2123 MDICREATESTRUCTW cs
;
2124 WND
*pWndParent
= WIN_FindWndPtr(hWndParent
);
2127 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
2128 debugstr_w(lpClassName
), debugstr_w(lpWindowName
), dwStyle
, X
, Y
,
2129 nWidth
, nHeight
, hWndParent
, hInstance
, lParam
);
2133 ERR("bad hwnd for MDI-client: %04x\n", hWndParent
);
2136 cs
.szClass
= lpClassName
;
2137 cs
.szTitle
= lpWindowName
;
2138 cs
.hOwner
= hInstance
;
2146 pCi
= (MDICLIENTINFO
*)pWndParent
->wExtra
;
2148 retvalue
= MDICreateChild(pWndParent
, pCi
, (MDICREATESTRUCTA
*)&cs
, TRUE
);
2149 WIN_ReleaseWndPtr(pWndParent
);
2153 /**********************************************************************
2154 * TranslateMDISysAccel (USER.451)
2156 BOOL16 WINAPI
TranslateMDISysAccel16( HWND16 hwndClient
, LPMSG16 msg
)
2160 STRUCT32_MSG16to32(msg
, &msg32
);
2161 /* MDICLIENTINFO is still the same for win32 and win16 ... */
2162 return TranslateMDISysAccel(hwndClient
, &msg32
);
2165 /**********************************************************************
2166 * TranslateMDISysAccel (USER32.@)
2168 BOOL WINAPI
TranslateMDISysAccel( HWND hwndClient
, LPMSG msg
)
2171 if( IsWindow(hwndClient
) && (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
))
2173 MDICLIENTINFO
*ci
= NULL
;
2175 WND
*clientWnd
= WIN_FindWndPtr(hwndClient
);
2177 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
2178 wnd
= ci
->hwndActiveChild
;
2180 WIN_ReleaseWndPtr(clientWnd
);
2182 if( IsWindow(wnd
) && !(GetWindowLongW(wnd
, GWL_STYLE
) & WS_DISABLED
) )
2186 /* translate if the Ctrl key is down and Alt not. */
2188 if( (GetKeyState(VK_CONTROL
) & 0x8000) &&
2189 !(GetKeyState(VK_MENU
) & 0x8000))
2191 switch( msg
->wParam
)
2195 wParam
= ( GetKeyState(VK_SHIFT
) & 0x8000 )
2196 ? SC_NEXTWINDOW
: SC_PREVWINDOW
;
2205 TRACE("wParam = %04x\n", wParam
);
2206 SendMessageW(wnd
, WM_SYSCOMMAND
, wParam
, (LPARAM
)msg
->wParam
);
2211 return 0; /* failure */
2214 /***********************************************************************
2215 * CalcChildScroll (USER.462)
2217 void WINAPI
CalcChildScroll16( HWND16 hwnd
, WORD scroll
)
2219 return CalcChildScroll( hwnd
, scroll
);
2222 /***********************************************************************
2223 * CalcChildScroll (USER32.@)
2225 void WINAPI
CalcChildScroll( HWND hwnd
, INT scroll
)
2228 RECT childRect
, clientRect
;
2229 INT vmin
, vmax
, hmin
, hmax
, vpos
, hpos
;
2232 if (!(pWnd
= WIN_FindWndPtr( hwnd
))) return;
2233 Wnd
= WIN_FindWndPtr(hwnd
);
2234 GetClientRect( hwnd
, &clientRect
);
2235 SetRectEmpty( &childRect
);
2237 for ( WIN_UpdateWndPtr(&pWnd
,pWnd
->child
); pWnd
; WIN_UpdateWndPtr(&pWnd
,pWnd
->next
))
2239 if( pWnd
->dwStyle
& WS_MAXIMIZE
)
2241 ShowScrollBar(hwnd
, SB_BOTH
, FALSE
);
2242 WIN_ReleaseWndPtr(pWnd
);
2243 WIN_ReleaseWndPtr(Wnd
);
2246 if( pWnd
->dwStyle
& WS_VISIBLE
)
2247 UnionRect( &childRect
, &pWnd
->rectWindow
, &childRect
);
2249 WIN_ReleaseWndPtr(pWnd
);
2250 UnionRect( &childRect
, &clientRect
, &childRect
);
2252 hmin
= childRect
.left
; hmax
= childRect
.right
- clientRect
.right
;
2253 hpos
= clientRect
.left
- childRect
.left
;
2254 vmin
= childRect
.top
; vmax
= childRect
.bottom
- clientRect
.bottom
;
2255 vpos
= clientRect
.top
- childRect
.top
;
2260 vpos
= hpos
; vmin
= hmin
; vmax
= hmax
;
2262 info
.cbSize
= sizeof(info
);
2263 info
.nMax
= vmax
; info
.nMin
= vmin
; info
.nPos
= vpos
;
2264 info
.fMask
= SIF_POS
| SIF_RANGE
;
2265 SetScrollInfo(hwnd
, scroll
, &info
, TRUE
);
2268 SCROLL_SetNCSbState( Wnd
, vmin
, vmax
, vpos
,
2271 WIN_ReleaseWndPtr(Wnd
);
2275 /***********************************************************************
2276 * ScrollChildren (USER.463)
2278 void WINAPI
ScrollChildren16(HWND16 hWnd
, UINT16 uMsg
, WPARAM16 wParam
, LPARAM lParam
)
2280 ScrollChildren( hWnd
, uMsg
, wParam
, lParam
);
2284 /***********************************************************************
2285 * ScrollChildren (USER32.@)
2287 void WINAPI
ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
,
2290 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
2292 INT curPos
, length
, minPos
, maxPos
, shift
;
2294 if( !wndPtr
) return;
2296 if( uMsg
== WM_HSCROLL
)
2298 GetScrollRange(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
2299 curPos
= GetScrollPos(hWnd
,SB_HORZ
);
2300 length
= (wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
)/2;
2301 shift
= GetSystemMetrics(SM_CYHSCROLL
);
2303 else if( uMsg
== WM_VSCROLL
)
2305 GetScrollRange(hWnd
,SB_VERT
,&minPos
,&maxPos
);
2306 curPos
= GetScrollPos(hWnd
,SB_VERT
);
2307 length
= (wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
)/2;
2308 shift
= GetSystemMetrics(SM_CXVSCROLL
);
2312 WIN_ReleaseWndPtr(wndPtr
);
2316 WIN_ReleaseWndPtr(wndPtr
);
2320 newPos
= curPos
- shift
;
2323 newPos
= curPos
+ shift
;
2326 newPos
= curPos
- length
;
2329 newPos
= curPos
+ length
;
2332 case SB_THUMBPOSITION
:
2333 newPos
= LOWORD(lParam
);
2346 CalcChildScroll16(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
2350 if( newPos
> maxPos
)
2353 if( newPos
< minPos
)
2356 SetScrollPos(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
2358 if( uMsg
== WM_VSCROLL
)
2359 ScrollWindowEx(hWnd
,0 ,curPos
- newPos
, NULL
, NULL
, 0, NULL
,
2360 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
2362 ScrollWindowEx(hWnd
,curPos
- newPos
, 0, NULL
, NULL
, 0, NULL
,
2363 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
2367 /******************************************************************************
2368 * CascadeWindows (USER32.@) Cascades MDI child windows
2371 * Success: Number of cascaded windows.
2375 CascadeWindows (HWND hwndParent
, UINT wFlags
, const LPRECT lpRect
,
2376 UINT cKids
, const HWND
*lpKids
)
2378 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2379 hwndParent
, wFlags
, cKids
);
2385 /******************************************************************************
2386 * TileWindows (USER32.@) Tiles MDI child windows
2389 * Success: Number of tiled windows.
2393 TileWindows (HWND hwndParent
, UINT wFlags
, const LPRECT lpRect
,
2394 UINT cKids
, const HWND
*lpKids
)
2396 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2397 hwndParent
, wFlags
, cKids
);
2402 /************************************************************************
2403 * "More Windows..." functionality
2406 /* MDI_MoreWindowsDlgProc
2408 * This function will process the messages sent to the "More Windows..."
2410 * Return values: 0 = cancel pressed
2411 * HWND = ok pressed or double-click in the list...
2415 static BOOL WINAPI
MDI_MoreWindowsDlgProc (HWND hDlg
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
2425 WND
*pParentWnd
= (WND
*)lParam
;
2426 MDICLIENTINFO
*ci
= (MDICLIENTINFO
*)pParentWnd
->wExtra
;
2427 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2429 /* Fill the list, sorted by id... */
2430 for (i
= 0; i
< ci
->nActiveChildren
; i
++)
2433 /* Find the window with the current ID */
2434 for (pWnd
= WIN_LockWndPtr(pParentWnd
->child
); pWnd
; WIN_UpdateWndPtr(&pWnd
, pWnd
->next
))
2435 if (pWnd
->wIDmenu
== ci
->idFirstChild
+ i
)
2438 SendMessageW(hListBox
, LB_ADDSTRING
, 0, (LPARAM
) pWnd
->text
);
2439 SendMessageW(hListBox
, LB_SETITEMDATA
, i
, (LPARAM
) pWnd
);
2440 length
= strlenW(pWnd
->text
);
2441 WIN_ReleaseWndPtr(pWnd
);
2443 if (length
> widest
)
2446 /* Make sure the horizontal scrollbar scrolls ok */
2447 SendMessageW(hListBox
, LB_SETHORIZONTALEXTENT
, widest
* 6, 0);
2449 /* Set the current selection */
2450 SendMessageW(hListBox
, LB_SETCURSEL
, MDI_MOREWINDOWSLIMIT
, 0);
2455 switch (LOWORD(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
= SendMessageW(hListBox
, LB_GETCURSEL
, 0, 0);
2464 WND
*pWnd
= (WND
*)SendMessageW(hListBox
, LB_GETITEMDATA
, index
, 0);
2466 EndDialog(hDlg
, pWnd
->hwndSelf
);
2474 switch (HIWORD(wParam
))
2478 /* windows are sorted by menu ID, so we must return the
2479 * window associated to the given id
2481 HWND hListBox
= GetDlgItem(hDlg
, MDI_IDC_LISTBOX
);
2482 UINT index
= SendMessageW(hListBox
, LB_GETCURSEL
, 0, 0);
2483 WND
*pWnd
= (WND
*)SendMessageW(hListBox
, LB_GETITEMDATA
, index
, 0);
2485 EndDialog(hDlg
, pWnd
->hwndSelf
);
2498 * MDI_MoreWindowsDialog
2500 * Prompts the user with a listbox containing the opened
2501 * documents. The user can then choose a windows and click
2502 * on OK to set the current window to the one selected, or
2503 * CANCEL to cancel. The function returns a handle to the
2507 static HWND
MDI_MoreWindowsDialog(WND
* wndPtr
)
2513 hRes
= FindResourceA(GetModuleHandleA("USER32"), "MDI_MOREWINDOWS", RT_DIALOGA
);
2518 hDlgTmpl
= LoadResource(GetModuleHandleA("USER32"), hRes
);
2523 template = LockResource( hDlgTmpl
);
2528 return (HWND
) DialogBoxIndirectParamA(GetModuleHandleA("USER32"),
2529 (LPDLGTEMPLATEA
) template,
2531 (DLGPROC
) MDI_MoreWindowsDlgProc
,
2539 * Will swap the menu IDs for the given 2 positions.
2540 * pos1 and pos2 are menu IDs
2545 static void MDI_SwapMenuItems(WND
*parentWnd
, UINT pos1
, UINT pos2
)
2549 for (pWnd
= WIN_LockWndPtr(parentWnd
->child
); pWnd
; WIN_UpdateWndPtr(&pWnd
,pWnd
->next
))
2551 if (pWnd
->wIDmenu
== pos1
)
2552 pWnd
->wIDmenu
= pos2
;
2554 if (pWnd
->wIDmenu
== pos2
)
2555 pWnd
->wIDmenu
= pos1
;
2558 WIN_ReleaseWndPtr(pWnd
);