3 * Copyright 1994, Bob Amstadt
4 * 1995,1996 Alex Korobka
6 * This file contains routines to support MDI features.
8 * Notes: Fairly complete implementation. Any volunteers for
9 * "More windows..." stuff?
11 * Also, Excel and WinWord do _not_ use MDI so if you're trying
12 * to fix them look elsewhere.
22 #include "nonclient.h"
28 #include "sysmetrics.h"
31 #define MDIF_NEEDUPDATE 0x0001
33 static HBITMAP16 hBmpClose
= 0;
34 static HBITMAP16 hBmpRestore
= 0;
36 DWORD
SCROLL_SetNCSbState(WND
*,int,int,int,int,int,int);
38 /* ----------------- declarations ----------------- */
39 static void MDI_UpdateFrameText(WND
*, HWND32
, BOOL32
, LPCSTR
);
40 static BOOL32
MDI_AugmentFrameMenu(MDICLIENTINFO
*, WND
*, HWND32
);
41 static BOOL32
MDI_RestoreFrameMenu(WND
*, HWND32
);
43 static LONG
MDI_ChildActivate( WND
*, HWND32
);
45 /* -------- Miscellaneous service functions ----------
50 static HWND32
MDI_GetChildByID(WND
* wndPtr
, INT32 id
)
52 for (wndPtr
= wndPtr
->child
; wndPtr
; wndPtr
= wndPtr
->next
)
53 if (wndPtr
->wIDmenu
== id
) return wndPtr
->hwndSelf
;
57 static void MDI_PostUpdate(HWND32 hwnd
, MDICLIENTINFO
* ci
, WORD recalc
)
59 if( !(ci
->mdiFlags
& MDIF_NEEDUPDATE
) )
61 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
62 PostMessage32A( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0);
64 ci
->sbRecalc
= recalc
;
67 /**********************************************************************
70 static BOOL32
MDI_MenuModifyItem(WND
* clientWnd
, HWND32 hWndChild
)
73 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
74 WND
*wndPtr
= WIN_FindWndPtr(hWndChild
);
75 UINT32 n
= sprintf(buffer
, "%d ",
76 wndPtr
->wIDmenu
- clientInfo
->idFirstChild
+ 1);
79 if( !clientInfo
->hWindowMenu
) return 0;
81 if (wndPtr
->text
) lstrcpyn32A(buffer
+ n
, wndPtr
->text
, sizeof(buffer
) - n
);
83 n
= GetMenuState32(clientInfo
->hWindowMenu
,wndPtr
->wIDmenu
,MF_BYCOMMAND
);
84 bRet
= ModifyMenu32A(clientInfo
->hWindowMenu
, wndPtr
->wIDmenu
,
85 MF_BYCOMMAND
| MF_STRING
, wndPtr
->wIDmenu
, buffer
);
86 CheckMenuItem32(clientInfo
->hWindowMenu
,wndPtr
->wIDmenu
, n
& MF_CHECKED
);
90 /**********************************************************************
93 static BOOL32
MDI_MenuDeleteItem(WND
* clientWnd
, HWND32 hWndChild
)
96 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
97 WND
*wndPtr
= WIN_FindWndPtr(hWndChild
);
98 UINT32 index
= 0,id
,n
;
100 if( !clientInfo
->nActiveChildren
||
101 !clientInfo
->hWindowMenu
) return 0;
103 id
= wndPtr
->wIDmenu
;
104 DeleteMenu32(clientInfo
->hWindowMenu
,id
,MF_BYCOMMAND
);
106 /* walk the rest of MDI children to prevent gaps in the id
107 * sequence and in the menu child list */
109 for( index
= id
+1; index
<= clientInfo
->nActiveChildren
+
110 clientInfo
->idFirstChild
; index
++ )
112 wndPtr
= WIN_FindWndPtr(MDI_GetChildByID(clientWnd
,index
));
115 TRACE(mdi
,"no window for id=%i\n",index
);
122 n
= sprintf(buffer
, "%d ",index
- clientInfo
->idFirstChild
);
124 lstrcpyn32A(buffer
+ n
, wndPtr
->text
, sizeof(buffer
) - n
);
127 ModifyMenu32A(clientInfo
->hWindowMenu
,index
,MF_BYCOMMAND
| MF_STRING
,
128 index
- 1 , buffer
);
133 /**********************************************************************
136 * returns "activateable" child different from the current or zero
138 static HWND32
MDI_GetWindow(WND
*clientWnd
, HWND32 hWnd
, BOOL32 bNext
,
141 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
142 WND
*wndPtr
, *pWnd
, *pWndLast
= NULL
;
144 dwStyleMask
|= WS_DISABLED
| WS_VISIBLE
;
145 if( !hWnd
) hWnd
= clientInfo
->hwndActiveChild
;
147 if( !(wndPtr
= WIN_FindWndPtr(hWnd
)) ) return 0;
149 for ( pWnd
= wndPtr
->next
; ; pWnd
= pWnd
->next
)
151 if (!pWnd
) pWnd
= wndPtr
->parent
->child
;
153 if ( pWnd
== wndPtr
) break; /* went full circle */
155 if (!pWnd
->owner
&& (pWnd
->dwStyle
& dwStyleMask
) == WS_VISIBLE
)
161 return pWndLast
? pWndLast
->hwndSelf
: 0;
164 /**********************************************************************
165 * MDI_CalcDefaultChildPos
167 * It seems that the default height is about 2/3 of the client rect
169 static void MDI_CalcDefaultChildPos( WND
* w
, WORD n
, LPPOINT32 lpPos
,
173 RECT32 rect
= w
->rectClient
;
174 INT32 spacing
= GetSystemMetrics32(SM_CYCAPTION
) +
175 GetSystemMetrics32(SM_CYFRAME
) - 1;
177 if( rect
.bottom
- rect
.top
- delta
>= spacing
)
178 rect
.bottom
-= delta
;
180 nstagger
= (rect
.bottom
- rect
.top
)/(3 * spacing
);
181 lpPos
[1].x
= (rect
.right
- rect
.left
- nstagger
* spacing
);
182 lpPos
[1].y
= (rect
.bottom
- rect
.top
- nstagger
* spacing
);
183 lpPos
[0].x
= lpPos
[0].y
= spacing
* (n
%(nstagger
+1));
186 /**********************************************************************
189 static LRESULT
MDISetMenu( HWND32 hwnd
, HMENU32 hmenuFrame
,
192 WND
*w
= WIN_FindWndPtr(hwnd
);
194 HWND32 hwndFrame
= GetParent32(hwnd
);
195 HMENU32 oldFrameMenu
= GetMenu32(hwndFrame
);
197 TRACE(mdi
, "%04x %04x %04x\n",
198 hwnd
, hmenuFrame
, hmenuWindow
);
200 ci
= (MDICLIENTINFO
*) w
->wExtra
;
202 if( ci
->hwndChildMaximized
&& hmenuFrame
&& hmenuFrame
!=oldFrameMenu
)
203 MDI_RestoreFrameMenu(w
->parent
, ci
->hwndChildMaximized
);
205 if( hmenuWindow
&& hmenuWindow
!=ci
->hWindowMenu
)
207 /* delete menu items from ci->hWindowMenu
208 * and add them to hmenuWindow */
210 INT32 i
= GetMenuItemCount32(ci
->hWindowMenu
) - 1;
211 INT32 pos
= GetMenuItemCount32(hmenuWindow
) + 1;
213 AppendMenu32A( hmenuWindow
, MF_SEPARATOR
, 0, NULL
);
215 if( ci
->nActiveChildren
)
217 INT32 j
= i
- ci
->nActiveChildren
+ 1;
221 for( ; i
>= j
; i
-- )
223 id
= GetMenuItemID32(ci
->hWindowMenu
,i
);
224 state
= GetMenuState32(ci
->hWindowMenu
,i
,MF_BYPOSITION
);
226 GetMenuString32A(ci
->hWindowMenu
, i
, buffer
, 100, MF_BYPOSITION
);
228 DeleteMenu32(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
229 InsertMenu32A(hmenuWindow
, pos
, MF_BYPOSITION
| MF_STRING
,
231 CheckMenuItem32(hmenuWindow
,pos
, MF_BYPOSITION
| (state
& MF_CHECKED
));
235 /* remove separator */
236 DeleteMenu32(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
238 ci
->hWindowMenu
= hmenuWindow
;
241 if( hmenuFrame
&& hmenuFrame
!=oldFrameMenu
)
243 SetMenu32(hwndFrame
, hmenuFrame
);
244 if( ci
->hwndChildMaximized
)
245 MDI_AugmentFrameMenu(ci
, w
->parent
, ci
->hwndChildMaximized
);
252 /* ------------------ MDI child window functions ---------------------- */
255 /**********************************************************************
258 static HWND32
MDICreateChild( WND
*w
, MDICLIENTINFO
*ci
, HWND32 parent
,
259 LPMDICREATESTRUCT32A cs
)
262 DWORD style
= cs
->style
| (WS_CHILD
| WS_CLIPSIBLINGS
);
263 HWND32 hwnd
, hwndMax
= 0;
264 WORD wIDmenu
= ci
->idFirstChild
+ ci
->nActiveChildren
;
265 char lpstrDef
[]="junk!";
267 TRACE(mdi
, "origin %i,%i - dim %i,%i, style %08x\n",
268 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, (unsigned)cs
->style
);
269 /* calculate placement */
270 MDI_CalcDefaultChildPos(w
, ci
->nTotalCreated
++, pos
, 0);
272 if (cs
->cx
== CW_USEDEFAULT32
|| !cs
->cx
) cs
->cx
= pos
[1].x
;
273 if (cs
->cy
== CW_USEDEFAULT32
|| !cs
->cy
) cs
->cy
= pos
[1].y
;
275 if( cs
->x
== CW_USEDEFAULT32
)
281 /* restore current maximized child */
282 if( style
& WS_VISIBLE
&& ci
->hwndChildMaximized
)
284 if( style
& WS_MAXIMIZE
)
285 SendMessage32A(w
->hwndSelf
, WM_SETREDRAW
, FALSE
, 0L );
286 hwndMax
= ci
->hwndChildMaximized
;
287 ShowWindow32( hwndMax
, SW_SHOWNOACTIVATE
);
288 if( style
& WS_MAXIMIZE
)
289 SendMessage32A(w
->hwndSelf
, WM_SETREDRAW
, TRUE
, 0L );
292 /* this menu is needed to set a check mark in MDI_ChildActivate */
293 AppendMenu32A(ci
->hWindowMenu
,MF_STRING
,wIDmenu
, lpstrDef
);
295 ci
->nActiveChildren
++;
297 /* fix window style */
298 if( !(w
->dwStyle
& MDIS_ALLCHILDSTYLES
) )
300 style
&= (WS_CHILD
| WS_CLIPSIBLINGS
| WS_MINIMIZE
| WS_MAXIMIZE
|
301 WS_CLIPCHILDREN
| WS_DISABLED
| WS_VSCROLL
| WS_HSCROLL
);
302 style
|= (WS_VISIBLE
| WS_OVERLAPPEDWINDOW
);
305 if( w
->flags
& WIN_ISWIN32
)
307 hwnd
= CreateWindow32A( cs
->szClass
, cs
->szTitle
, style
,
308 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, parent
,
309 (HMENU16
)wIDmenu
, cs
->hOwner
, cs
);
313 MDICREATESTRUCT16
*cs16
;
316 cs16
= SEGPTR_NEW(MDICREATESTRUCT16
);
317 STRUCT32_MDICREATESTRUCT32Ato16( cs
, cs16
);
318 title
= SEGPTR_STRDUP( cs
->szTitle
);
319 cls
= SEGPTR_STRDUP( cs
->szClass
);
320 cs16
->szTitle
= SEGPTR_GET(title
);
321 cs16
->szClass
= SEGPTR_GET(cls
);
323 hwnd
= CreateWindow16( cs
->szClass
, cs
->szTitle
, style
,
324 cs16
->x
, cs16
->y
, cs16
->cx
, cs16
->cy
, parent
,
325 (HMENU32
)wIDmenu
, cs16
->hOwner
,
326 (LPVOID
)SEGPTR_GET(cs16
) );
327 SEGPTR_FREE( title
);
332 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
336 WND
* wnd
= WIN_FindWndPtr( hwnd
);
338 MDI_MenuModifyItem(w
,hwnd
);
339 if( wnd
->dwStyle
& WS_MINIMIZE
&& ci
->hwndActiveChild
)
340 ShowWindow32( hwnd
, SW_SHOWMINNOACTIVE
);
343 SetWindowPos32( hwnd
, 0, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
);
345 /* Set maximized state here in case hwnd didn't receive WM_SIZE
346 * during CreateWindow - bad!
349 if((wnd
->dwStyle
& WS_MAXIMIZE
) && !ci
->hwndChildMaximized
)
351 ci
->hwndChildMaximized
= wnd
->hwndSelf
;
352 MDI_AugmentFrameMenu( ci
, w
->parent
, hwnd
);
353 MDI_UpdateFrameText( w
->parent
, ci
->self
, MDI_REPAINTFRAME
, NULL
);
356 TRACE(mdi
, "created child - %04x\n",hwnd
);
360 ci
->nActiveChildren
--;
361 DeleteMenu32(ci
->hWindowMenu
,wIDmenu
,MF_BYCOMMAND
);
362 if( IsWindow32(hwndMax
) )
363 ShowWindow32(hwndMax
, SW_SHOWMAXIMIZED
);
369 /**********************************************************************
370 * MDI_ChildGetMinMaxInfo
372 * Note: The rule here is that client rect of the maximized MDI child
373 * is equal to the client rect of the MDI client window.
375 static void MDI_ChildGetMinMaxInfo( WND
* clientWnd
, HWND32 hwnd
,
376 MINMAXINFO16
* lpMinMax
)
378 WND
* childWnd
= WIN_FindWndPtr(hwnd
);
379 RECT32 rect
= clientWnd
->rectClient
;
381 MapWindowPoints32( clientWnd
->parent
->hwndSelf
,
382 ((MDICLIENTINFO
*)clientWnd
->wExtra
)->self
, (LPPOINT32
)&rect
, 2);
383 AdjustWindowRectEx32( &rect
, childWnd
->dwStyle
, 0, childWnd
->dwExStyle
);
385 lpMinMax
->ptMaxSize
.x
= rect
.right
-= rect
.left
;
386 lpMinMax
->ptMaxSize
.y
= rect
.bottom
-= rect
.top
;
388 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
389 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
391 TRACE(mdi
,"max rect (%i,%i - %i, %i)\n",
392 rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
395 /**********************************************************************
396 * MDI_SwitchActiveChild
398 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
401 static void MDI_SwitchActiveChild( HWND32 clientHwnd
, HWND32 childHwnd
,
404 WND
*w
= WIN_FindWndPtr(clientHwnd
);
409 hwndTo
= MDI_GetWindow(w
, childHwnd
, bNextWindow
, 0);
411 ci
= (MDICLIENTINFO
*) w
->wExtra
;
413 TRACE(mdi
, "from %04x, to %04x\n",childHwnd
,hwndTo
);
415 if ( !hwndTo
) return; /* no window to switch to */
417 hwndPrev
= ci
->hwndActiveChild
;
419 if ( hwndTo
!= hwndPrev
)
421 BOOL32 bOptimize
= 0;
423 if( ci
->hwndChildMaximized
)
426 w
->dwStyle
&= ~WS_VISIBLE
;
429 SetWindowPos32( hwndTo
, HWND_TOP
, 0, 0, 0, 0,
430 SWP_NOMOVE
| SWP_NOSIZE
);
432 if( bNextWindow
&& hwndPrev
)
433 SetWindowPos32( hwndPrev
, HWND_BOTTOM
, 0, 0, 0, 0,
434 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
436 ShowWindow32( clientHwnd
, SW_SHOW
);
441 /**********************************************************************
444 static LRESULT
MDIDestroyChild( WND
*w_parent
, MDICLIENTINFO
*ci
,
445 HWND32 parent
, HWND32 child
,
448 WND
*childPtr
= WIN_FindWndPtr(child
);
452 if( child
== ci
->hwndActiveChild
)
454 MDI_SwitchActiveChild(parent
, child
, TRUE
);
456 if( child
== ci
->hwndActiveChild
)
458 ShowWindow32( child
, SW_HIDE
);
459 if( child
== ci
->hwndChildMaximized
)
461 MDI_RestoreFrameMenu(w_parent
->parent
, child
);
462 ci
->hwndChildMaximized
= 0;
463 MDI_UpdateFrameText(w_parent
->parent
,parent
,TRUE
,NULL
);
466 MDI_ChildActivate(w_parent
, 0);
468 MDI_MenuDeleteItem(w_parent
, child
);
471 ci
->nActiveChildren
--;
473 TRACE(mdi
,"child destroyed - %04x\n",child
);
477 MDI_PostUpdate(GetParent32(child
), ci
, SB_BOTH
+1);
478 DestroyWindow32(child
);
486 /**********************************************************************
489 * Note: hWndChild is NULL when last child is being destroyed
491 static LONG
MDI_ChildActivate( WND
*clientPtr
, HWND32 hWndChild
)
493 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientPtr
->wExtra
;
494 HWND32 prevActiveWnd
= clientInfo
->hwndActiveChild
;
495 WND
*wndPtr
= WIN_FindWndPtr( hWndChild
);
496 WND
*wndPrev
= WIN_FindWndPtr( prevActiveWnd
);
497 BOOL32 isActiveFrameWnd
= 0;
499 if( hWndChild
== prevActiveWnd
) return 0L;
502 if( wndPtr
->dwStyle
& WS_DISABLED
) return 0L;
504 TRACE(mdi
,"%04x\n", hWndChild
);
506 if( GetActiveWindow32() == clientPtr
->parent
->hwndSelf
)
507 isActiveFrameWnd
= TRUE
;
509 /* deactivate prev. active child */
512 wndPrev
->dwStyle
|= WS_SYSMENU
;
513 SendMessage32A( prevActiveWnd
, WM_NCACTIVATE
, FALSE
, 0L );
514 SendMessage32A( prevActiveWnd
, WM_MDIACTIVATE
, (WPARAM32
)prevActiveWnd
,
516 /* uncheck menu item */
517 if( clientInfo
->hWindowMenu
)
518 CheckMenuItem32( clientInfo
->hWindowMenu
,
519 wndPrev
->wIDmenu
, 0);
523 if( clientInfo
->hwndChildMaximized
)
524 if( clientInfo
->hwndChildMaximized
!= hWndChild
)
527 clientInfo
->hwndActiveChild
= hWndChild
;
528 ShowWindow32( hWndChild
, SW_SHOWMAXIMIZED
);
531 ShowWindow32( clientInfo
->hwndActiveChild
, SW_SHOWNORMAL
);
533 clientInfo
->hwndActiveChild
= hWndChild
;
535 /* check if we have any children left */
538 if( isActiveFrameWnd
)
539 SetFocus32( clientInfo
->self
);
543 /* check menu item */
544 if( clientInfo
->hWindowMenu
)
545 CheckMenuItem32( clientInfo
->hWindowMenu
,
546 wndPtr
->wIDmenu
, MF_CHECKED
);
548 /* bring active child to the top */
549 SetWindowPos32( hWndChild
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
551 if( isActiveFrameWnd
)
553 SendMessage32A( hWndChild
, WM_NCACTIVATE
, TRUE
, 0L);
554 if( GetFocus32() == clientInfo
->self
)
555 SendMessage32A( clientInfo
->self
, WM_SETFOCUS
,
556 (WPARAM32
)clientInfo
->self
, 0L );
558 SetFocus32( clientInfo
->self
);
560 SendMessage32A( hWndChild
, WM_MDIACTIVATE
, (WPARAM32
)prevActiveWnd
,
565 /* -------------------- MDI client window functions ------------------- */
567 /**********************************************************************
568 * CreateMDIMenuBitmap
570 static HBITMAP16
CreateMDIMenuBitmap(void)
572 HDC32 hDCSrc
= CreateCompatibleDC32(0);
573 HDC32 hDCDest
= CreateCompatibleDC32(hDCSrc
);
574 HBITMAP16 hbClose
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_CLOSE
) );
576 HANDLE16 hobjSrc
, hobjDest
;
578 hobjSrc
= SelectObject32(hDCSrc
, hbClose
);
579 hbCopy
= CreateCompatibleBitmap32(hDCSrc
,SYSMETRICS_CXSIZE
,SYSMETRICS_CYSIZE
);
580 hobjDest
= SelectObject32(hDCDest
, hbCopy
);
582 BitBlt32(hDCDest
, 0, 0, SYSMETRICS_CXSIZE
, SYSMETRICS_CYSIZE
,
583 hDCSrc
, SYSMETRICS_CXSIZE
, 0, SRCCOPY
);
585 SelectObject32(hDCSrc
, hobjSrc
);
586 DeleteObject32(hbClose
);
589 hobjSrc
= SelectObject32( hDCDest
, GetStockObject32(BLACK_PEN
) );
591 MoveToEx32( hDCDest
, SYSMETRICS_CXSIZE
- 1, 0, NULL
);
592 LineTo32( hDCDest
, SYSMETRICS_CXSIZE
- 1, SYSMETRICS_CYSIZE
- 1);
594 SelectObject32(hDCDest
, hobjSrc
);
595 SelectObject32(hDCDest
, hobjDest
);
601 /**********************************************************************
604 static LONG
MDICascade(WND
* clientWnd
, MDICLIENTINFO
*ci
)
609 if (ci
->hwndChildMaximized
)
610 ShowWindow16( ci
->hwndChildMaximized
, SW_NORMAL
);
612 if (ci
->nActiveChildren
== 0) return 0;
614 if ((ppWnd
= WIN_BuildWinArray(clientWnd
, BWA_SKIPHIDDEN
| BWA_SKIPOWNED
|
615 BWA_SKIPICONIC
, &total
)))
617 WND
** heapPtr
= ppWnd
;
620 INT32 delta
= 0, n
= 0;
622 if( total
< ci
->nActiveChildren
)
623 delta
= SYSMETRICS_CYICONSPACING
+ SYSMETRICS_CYICON
;
625 /* walk the list and move windows */
628 TRACE(mdi
, "move %04x to (%d,%d) size [%d,%d]\n",
629 (*ppWnd
)->hwndSelf
, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
);
631 MDI_CalcDefaultChildPos(clientWnd
, n
++, pos
, delta
);
632 SetWindowPos32( (*ppWnd
)->hwndSelf
, 0, pos
[0].x
, pos
[0].y
,
634 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
638 HeapFree( SystemHeap
, 0, heapPtr
);
641 if( total
< ci
->nActiveChildren
)
642 ArrangeIconicWindows32( clientWnd
->hwndSelf
);
646 /**********************************************************************
649 static void MDITile( WND
* wndClient
, MDICLIENTINFO
*ci
, WPARAM32 wParam
)
654 if (ci
->hwndChildMaximized
)
655 ShowWindow32(ci
->hwndChildMaximized
, SW_NORMAL
);
657 if (ci
->nActiveChildren
== 0) return;
659 ppWnd
= WIN_BuildWinArray(wndClient
, BWA_SKIPHIDDEN
| BWA_SKIPOWNED
| BWA_SKIPICONIC
|
660 ((wParam
& MDITILE_SKIPDISABLED
)? BWA_SKIPDISABLED
: 0), &total
);
662 TRACE(mdi
,"%u windows to tile\n", total
);
666 WND
** heapPtr
= ppWnd
;
671 int x
, y
, xsize
, ysize
;
672 int rows
, columns
, r
, c
, i
;
674 rect
= wndClient
->rectClient
;
675 rows
= (int) sqrt((double)total
);
676 columns
= total
/ rows
;
678 if( wParam
& MDITILE_HORIZONTAL
) /* version >= 3.1 */
681 rows
= columns
; /* exchange r and c */
685 if( total
!= ci
->nActiveChildren
)
687 y
= rect
.bottom
- 2 * SYSMETRICS_CYICONSPACING
- SYSMETRICS_CYICON
;
688 rect
.bottom
= ( y
- SYSMETRICS_CYICON
< rect
.top
)? rect
.bottom
: y
;
691 ysize
= rect
.bottom
/ rows
;
692 xsize
= rect
.right
/ columns
;
694 for (x
= i
= 0, c
= 1; c
<= columns
&& *ppWnd
; c
++)
699 ysize
= rect
.bottom
/ rows
;
703 for (r
= 1; r
<= rows
&& *ppWnd
; r
++, i
++)
705 SetWindowPos32((*ppWnd
)->hwndSelf
, 0, x
, y
, xsize
, ysize
,
706 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
713 HeapFree( SystemHeap
, 0, heapPtr
);
716 if( total
< ci
->nActiveChildren
) ArrangeIconicWindows32( wndClient
->hwndSelf
);
719 /* ----------------------- Frame window ---------------------------- */
722 /**********************************************************************
723 * MDI_AugmentFrameMenu
725 static BOOL32
MDI_AugmentFrameMenu( MDICLIENTINFO
* ci
, WND
*frame
,
728 WND
* child
= WIN_FindWndPtr(hChild
);
729 HMENU32 hSysPopup
= 0;
731 TRACE(mdi
,"frame %p,child %04x\n",frame
,hChild
);
733 if( !frame
->wIDmenu
|| !child
->hSysMenu
) return 0;
735 /* create a copy of sysmenu popup and insert it into frame menu bar */
737 if (!(hSysPopup
= LoadMenuIndirect32A(SYSRES_GetResPtr(SYSRES_MENU_SYSMENU
))))
740 TRACE(mdi
,"\tgot popup %04x in sysmenu %04x\n",
741 hSysPopup
, child
->hSysMenu
);
743 if( !InsertMenu32A(frame
->wIDmenu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
744 hSysPopup
, (LPSTR
)(DWORD
)hBmpClose
))
746 DestroyMenu32(hSysPopup
);
750 if( !AppendMenu32A(frame
->wIDmenu
,MF_HELP
| MF_BITMAP
,
751 SC_RESTORE
, (LPSTR
)(DWORD
)hBmpRestore
))
753 RemoveMenu32(frame
->wIDmenu
,0,MF_BYPOSITION
);
757 EnableMenuItem32(hSysPopup
, SC_SIZE
, MF_BYCOMMAND
| MF_GRAYED
);
758 EnableMenuItem32(hSysPopup
, SC_MOVE
, MF_BYCOMMAND
| MF_GRAYED
);
759 EnableMenuItem32(hSysPopup
, SC_MAXIMIZE
, MF_BYCOMMAND
| MF_GRAYED
);
762 DrawMenuBar32(frame
->hwndSelf
);
767 /**********************************************************************
768 * MDI_RestoreFrameMenu
770 static BOOL32
MDI_RestoreFrameMenu( WND
*frameWnd
, HWND32 hChild
)
772 INT32 nItems
= GetMenuItemCount32(frameWnd
->wIDmenu
) - 1;
774 TRACE(mdi
,"for child %04x\n",hChild
);
776 if( GetMenuItemID32(frameWnd
->wIDmenu
,nItems
) != SC_RESTORE
)
779 RemoveMenu32(frameWnd
->wIDmenu
,0,MF_BYPOSITION
);
780 DeleteMenu32(frameWnd
->wIDmenu
,nItems
-1,MF_BYPOSITION
);
782 DrawMenuBar32(frameWnd
->hwndSelf
);
787 /**********************************************************************
788 * MDI_UpdateFrameText
790 * used when child window is maximized/restored
792 * Note: lpTitle can be NULL
794 static void MDI_UpdateFrameText( WND
*frameWnd
, HWND32 hClient
,
795 BOOL32 repaint
, LPCSTR lpTitle
)
797 char lpBuffer
[MDI_MAXTITLELENGTH
+1];
798 WND
* clientWnd
= WIN_FindWndPtr(hClient
);
799 MDICLIENTINFO
*ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
801 TRACE(mdi
, "repaint %i, frameText %s\n", repaint
, (lpTitle
)?lpTitle
:"NULL");
809 /* store new "default" title if lpTitle is not NULL */
812 if (ci
->frameTitle
) HeapFree( SystemHeap
, 0, ci
->frameTitle
);
813 ci
->frameTitle
= HEAP_strdupA( SystemHeap
, 0, lpTitle
);
818 WND
* childWnd
= WIN_FindWndPtr( ci
->hwndChildMaximized
);
820 if( childWnd
&& childWnd
->text
)
822 /* combine frame title and child title if possible */
824 LPCSTR lpBracket
= " - [";
825 int i_frame_text_length
= strlen(ci
->frameTitle
);
826 int i_child_text_length
= strlen(childWnd
->text
);
828 lstrcpyn32A( lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
830 if( i_frame_text_length
+ 6 < MDI_MAXTITLELENGTH
)
832 strcat( lpBuffer
, lpBracket
);
834 if( i_frame_text_length
+ i_child_text_length
+ 6 < MDI_MAXTITLELENGTH
)
836 strcat( lpBuffer
, childWnd
->text
);
837 strcat( lpBuffer
, "]" );
841 lstrcpyn32A( lpBuffer
+ i_frame_text_length
+ 4,
842 childWnd
->text
, MDI_MAXTITLELENGTH
- i_frame_text_length
- 5 );
843 strcat( lpBuffer
, "]" );
849 strncpy(lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
850 lpBuffer
[MDI_MAXTITLELENGTH
]='\0';
856 DEFWND_SetText( frameWnd
, lpBuffer
);
857 if( repaint
== MDI_REPAINTFRAME
)
858 SetWindowPos32( frameWnd
->hwndSelf
, 0,0,0,0,0, SWP_FRAMECHANGED
|
859 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
863 /* ----------------------------- Interface ---------------------------- */
866 /**********************************************************************
869 * This function handles all MDI requests.
871 LRESULT WINAPI
MDIClientWndProc( HWND32 hwnd
, UINT32 message
, WPARAM32 wParam
,
874 LPCREATESTRUCT32A cs
;
877 WND
*w
= WIN_FindWndPtr(hwnd
);
878 WND
*frameWnd
= w
->parent
;
881 ci
= (MDICLIENTINFO
*) w
->wExtra
;
887 cs
= (LPCREATESTRUCT32A
)lParam
;
889 /* Translation layer doesn't know what's in the cs->lpCreateParams
890 * so we have to keep track of what environment we're in. */
892 if( w
->flags
& WIN_ISWIN32
)
894 #define ccs ((LPCLIENTCREATESTRUCT32)cs->lpCreateParams)
895 ci
->hWindowMenu
= ccs
->hWindowMenu
;
896 ci
->idFirstChild
= ccs
->idFirstChild
;
901 LPCLIENTCREATESTRUCT16 ccs
= (LPCLIENTCREATESTRUCT16
)
902 PTR_SEG_TO_LIN(cs
->lpCreateParams
);
903 ci
->hWindowMenu
= ccs
->hWindowMenu
;
904 ci
->idFirstChild
= ccs
->idFirstChild
;
907 ci
->hwndChildMaximized
= 0;
908 ci
->nActiveChildren
= 0;
909 ci
->nTotalCreated
= 0;
910 ci
->frameTitle
= NULL
;
913 w
->dwStyle
|= WS_CLIPCHILDREN
;
917 hBmpClose
= CreateMDIMenuBitmap();
918 hBmpRestore
= LoadBitmap16( 0, MAKEINTRESOURCE(OBM_RESTORE
) );
920 MDI_UpdateFrameText(frameWnd
, hwnd
, MDI_NOFRAMEREPAINT
,frameWnd
->text
);
922 AppendMenu32A( ci
->hWindowMenu
, MF_SEPARATOR
, 0, NULL
);
924 GetClientRect32(frameWnd
->hwndSelf
, &rect
);
925 NC_HandleNCCalcSize( w
, &rect
);
926 w
->rectClient
= rect
;
928 TRACE(mdi
,"Client created - hwnd = %04x, idFirst = %u\n",
929 hwnd
, ci
->idFirstChild
);
934 if( ci
->hwndChildMaximized
) MDI_RestoreFrameMenu(w
, frameWnd
->hwndSelf
);
935 if((nItems
= GetMenuItemCount32(ci
->hWindowMenu
)) > 0)
937 ci
->idFirstChild
= nItems
- 1;
938 ci
->nActiveChildren
++; /* to delete a separator */
939 while( ci
->nActiveChildren
-- )
940 DeleteMenu32(ci
->hWindowMenu
,MF_BYPOSITION
,ci
->idFirstChild
--);
945 if( ci
->hwndActiveChild
!= (HWND32
)wParam
)
946 SetWindowPos32((HWND32
)wParam
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
950 return MDICascade(w
, ci
);
953 if (lParam
) return MDICreateChild( w
, ci
, hwnd
,
954 (MDICREATESTRUCT32A
*)lParam
);
958 return MDIDestroyChild( w
, ci
, hwnd
, (HWND32
)wParam
, TRUE
);
960 case WM_MDIGETACTIVE
:
961 if (lParam
) *(BOOL32
*)lParam
= (ci
->hwndChildMaximized
> 0);
962 return ci
->hwndActiveChild
;
964 case WM_MDIICONARRANGE
:
965 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
966 ArrangeIconicWindows32(hwnd
);
967 ci
->sbRecalc
= SB_BOTH
+1;
968 SendMessage32A(hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0L);
972 ShowWindow32( (HWND32
)wParam
, SW_MAXIMIZE
);
975 case WM_MDINEXT
: /* lParam != 0 means previous window */
976 MDI_SwitchActiveChild(hwnd
, (HWND32
)wParam
, (lParam
)? FALSE
: TRUE
);
980 ShowWindow32( (HWND32
)wParam
, SW_NORMAL
);
984 return MDISetMenu( hwnd
, (HMENU32
)wParam
, (HMENU32
)lParam
);
987 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
988 ShowScrollBar32(hwnd
,SB_BOTH
,FALSE
);
989 MDITile(w
, ci
, wParam
);
990 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
995 ci
->mdiFlags
|= MDIF_NEEDUPDATE
;
996 ScrollChildren32(hwnd
, message
, wParam
, lParam
);
997 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1001 if( ci
->hwndActiveChild
)
1003 w
= WIN_FindWndPtr( ci
->hwndActiveChild
);
1004 if( !(w
->dwStyle
& WS_MINIMIZE
) )
1005 SetFocus32( ci
->hwndActiveChild
);
1010 if( ci
->hwndActiveChild
)
1011 SendMessage32A(ci
->hwndActiveChild
, message
, wParam
, lParam
);
1014 case WM_PARENTNOTIFY
:
1015 if (LOWORD(wParam
) == WM_LBUTTONDOWN
)
1017 POINT16 pt
= MAKEPOINT16(lParam
);
1018 HWND16 child
= ChildWindowFromPoint16(hwnd
, pt
);
1020 TRACE(mdi
,"notification from %04x (%i,%i)\n",child
,pt
.x
,pt
.y
);
1022 if( child
&& child
!= hwnd
&& child
!= ci
->hwndActiveChild
)
1023 SetWindowPos32(child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1028 if( ci
->hwndChildMaximized
)
1030 WND
* child
= WIN_FindWndPtr(ci
->hwndChildMaximized
);
1031 RECT32 rect
= { 0, 0, LOWORD(lParam
), HIWORD(lParam
) };
1033 AdjustWindowRectEx32(&rect
, child
->dwStyle
, 0, child
->dwExStyle
);
1034 MoveWindow32(ci
->hwndChildMaximized
, rect
.left
, rect
.top
,
1035 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 1);
1038 MDI_PostUpdate(hwnd
, ci
, SB_BOTH
+1);
1042 case WM_MDICALCCHILDSCROLL
:
1043 if( (ci
->mdiFlags
& MDIF_NEEDUPDATE
) && ci
->sbRecalc
)
1045 CalcChildScroll(hwnd
, ci
->sbRecalc
-1);
1047 ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1052 return DefWindowProc32A( hwnd
, message
, wParam
, lParam
);
1056 /***********************************************************************
1057 * DefFrameProc16 (USER.445)
1059 LRESULT WINAPI
DefFrameProc16( HWND16 hwnd
, HWND16 hwndMDIClient
,
1060 UINT16 message
, WPARAM16 wParam
, LPARAM lParam
)
1071 wndPtr
= WIN_FindWndPtr(hwndMDIClient
);
1072 ci
= (MDICLIENTINFO
*)wndPtr
->wExtra
;
1074 /* check for possible syscommands for maximized MDI child */
1077 wParam
< ci
->idFirstChild
||
1078 wParam
>= ci
->idFirstChild
+ ci
->nActiveChildren
1080 if( (wParam
- 0xF000) & 0xF00F ) break;
1091 if( ci
->hwndChildMaximized
)
1092 return SendMessage16( ci
->hwndChildMaximized
, WM_SYSCOMMAND
,
1098 childHwnd
= MDI_GetChildByID( WIN_FindWndPtr(hwndMDIClient
),
1101 SendMessage16(hwndMDIClient
, WM_MDIACTIVATE
,
1102 (WPARAM16
)childHwnd
, 0L);
1107 SendMessage16(hwndMDIClient
, message
, wParam
, lParam
);
1111 MDI_UpdateFrameText(WIN_FindWndPtr(hwnd
), hwndMDIClient
,
1113 (LPCSTR
)PTR_SEG_TO_LIN(lParam
));
1117 SetFocus32(hwndMDIClient
);
1121 MoveWindow16(hwndMDIClient
, 0, 0,
1122 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1127 wndPtr
= WIN_FindWndPtr(hwndMDIClient
);
1128 ci
= (MDICLIENTINFO
*)wndPtr
->wExtra
;
1130 if( !(wndPtr
->parent
->dwStyle
& WS_MINIMIZE
)
1131 && ci
->hwndActiveChild
&& !ci
->hwndChildMaximized
)
1133 /* control menu is between the frame system menu and
1134 * the first entry of menu bar */
1136 if( (wParam
== VK_LEFT
&&
1137 wndPtr
->parent
->wIDmenu
== LOWORD(lParam
)) ||
1138 (wParam
== VK_RIGHT
&&
1139 GetSubMenu16(wndPtr
->parent
->hSysMenu
, 0) == LOWORD(lParam
)) )
1141 wndPtr
= WIN_FindWndPtr(ci
->hwndActiveChild
);
1142 return MAKELONG( GetSubMenu16(wndPtr
->hSysMenu
, 0),
1143 ci
->hwndActiveChild
);
1150 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1154 /***********************************************************************
1155 * DefFrameProc32A (USER32.121)
1157 LRESULT WINAPI
DefFrameProc32A( HWND32 hwnd
, HWND32 hwndMDIClient
,
1158 UINT32 message
, WPARAM32 wParam
, LPARAM lParam
)
1165 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1167 MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ) );
1170 SendMessage32A(hwndMDIClient
, message
, wParam
, lParam
);
1175 LPSTR segstr
= SEGPTR_STRDUP((LPSTR
)lParam
);
1177 ret
= DefFrameProc16(hwnd
, hwndMDIClient
, message
,
1178 wParam
, (LPARAM
)SEGPTR_GET(segstr
) );
1179 SEGPTR_FREE(segstr
);
1185 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1190 return DefWindowProc32A(hwnd
, message
, wParam
, lParam
);
1194 /***********************************************************************
1195 * DefFrameProc32W (USER32.122)
1197 LRESULT WINAPI
DefFrameProc32W( HWND32 hwnd
, HWND32 hwndMDIClient
,
1198 UINT32 message
, WPARAM32 wParam
, LPARAM lParam
)
1205 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1207 MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ) );
1210 SendMessage32W(hwndMDIClient
, message
, wParam
, lParam
);
1215 LPSTR txt
= HEAP_strdupWtoA(GetProcessHeap(),0,(LPWSTR
)lParam
);
1216 LRESULT ret
= DefFrameProc32A( hwnd
, hwndMDIClient
, message
,
1217 wParam
, (DWORD
)txt
);
1218 HeapFree(GetProcessHeap(),0,txt
);
1223 return DefFrameProc32A( hwnd
, hwndMDIClient
, message
,
1228 return DefWindowProc32W( hwnd
, message
, wParam
, lParam
);
1232 /***********************************************************************
1233 * DefMDIChildProc16 (USER.447)
1235 LRESULT WINAPI
DefMDIChildProc16( HWND16 hwnd
, UINT16 message
,
1236 WPARAM16 wParam
, LPARAM lParam
)
1241 clientWnd
= WIN_FindWndPtr(GetParent16(hwnd
));
1242 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1247 DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1248 MDI_MenuModifyItem(clientWnd
,hwnd
);
1249 if( ci
->hwndChildMaximized
== hwnd
)
1250 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1251 MDI_REPAINTFRAME
, NULL
);
1255 SendMessage16(ci
->self
,WM_MDIDESTROY
,(WPARAM16
)hwnd
,0L);
1259 if( ci
->hwndActiveChild
!= hwnd
)
1260 MDI_ChildActivate(clientWnd
, hwnd
);
1263 case WM_CHILDACTIVATE
:
1264 MDI_ChildActivate(clientWnd
, hwnd
);
1268 TRACE(mdi
,"WM_NCPAINT for %04x, active %04x\n",
1269 hwnd
, ci
->hwndActiveChild
);
1276 if( ci
->hwndChildMaximized
== hwnd
) return 0;
1280 WIN_FindWndPtr(hwnd
)->dwStyle
|= WS_SYSMENU
;
1283 if( ci
->hwndChildMaximized
== hwnd
)
1284 return SendMessage16( clientWnd
->parent
->hwndSelf
,
1285 message
, wParam
, lParam
);
1286 WIN_FindWndPtr(hwnd
)->dwStyle
&= ~WS_SYSMENU
;
1289 SendMessage16( ci
->self
, WM_MDINEXT
, 0, 0);
1292 SendMessage16( ci
->self
, WM_MDINEXT
, 0, 1);
1297 case WM_GETMINMAXINFO
:
1298 MDI_ChildGetMinMaxInfo(clientWnd
, hwnd
, (MINMAXINFO16
*) PTR_SEG_TO_LIN(lParam
));
1302 if( ci
->hwndChildMaximized
) ci
->mdiFlags
&= ~MDIF_NEEDUPDATE
;
1304 MDI_PostUpdate(clientWnd
->hwndSelf
, ci
, SB_BOTH
+1);
1310 if( ci
->hwndActiveChild
== hwnd
&& wParam
!= SIZE_MAXIMIZED
)
1312 ci
->hwndChildMaximized
= 0;
1314 MDI_RestoreFrameMenu( clientWnd
->parent
, hwnd
);
1315 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1316 MDI_REPAINTFRAME
, NULL
);
1319 if( wParam
== SIZE_MAXIMIZED
)
1321 HWND16 hMaxChild
= ci
->hwndChildMaximized
;
1323 if( hMaxChild
== hwnd
) break;
1327 SendMessage16( hMaxChild
, WM_SETREDRAW
, FALSE
, 0L );
1329 MDI_RestoreFrameMenu( clientWnd
->parent
, hMaxChild
);
1330 ShowWindow16( hMaxChild
, SW_SHOWNOACTIVATE
);
1332 SendMessage16( hMaxChild
, WM_SETREDRAW
, TRUE
, 0L );
1335 TRACE(mdi
,"maximizing child %04x\n", hwnd
);
1337 ci
->hwndChildMaximized
= hwnd
; /* !!! */
1339 MDI_AugmentFrameMenu( ci
, clientWnd
->parent
, hwnd
);
1340 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1341 MDI_REPAINTFRAME
, NULL
);
1344 if( wParam
== SIZE_MINIMIZED
)
1346 HWND16 switchTo
= MDI_GetWindow(clientWnd
, hwnd
, TRUE
, WS_MINIMIZE
);
1349 SendMessage16( switchTo
, WM_CHILDACTIVATE
, 0, 0L);
1352 MDI_PostUpdate(clientWnd
->hwndSelf
, ci
, SB_BOTH
+1);
1357 /* MDI children don't have menu bars */
1358 PostMessage16( clientWnd
->parent
->hwndSelf
, WM_SYSCOMMAND
,
1359 (WPARAM16
)SC_KEYMENU
, (LPARAM
)wParam
);
1364 if( wParam
== VK_LEFT
) /* switch to frame system menu */
1365 return MAKELONG( GetSubMenu16(clientWnd
->parent
->hSysMenu
, 0),
1366 clientWnd
->parent
->hwndSelf
);
1367 if( wParam
== VK_RIGHT
) /* to frame menu bar */
1368 return MAKELONG( clientWnd
->parent
->wIDmenu
,
1369 clientWnd
->parent
->hwndSelf
);
1374 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1378 /***********************************************************************
1379 * DefMDIChildProc32A (USER32.123)
1381 LRESULT WINAPI
DefMDIChildProc32A( HWND32 hwnd
, UINT32 message
,
1382 WPARAM32 wParam
, LPARAM lParam
)
1387 clientWnd
= WIN_FindWndPtr(GetParent16(hwnd
));
1388 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1393 DefWindowProc32A(hwnd
, message
, wParam
, lParam
);
1394 MDI_MenuModifyItem(clientWnd
,hwnd
);
1395 if( ci
->hwndChildMaximized
== hwnd
)
1396 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1397 MDI_REPAINTFRAME
, NULL
);
1400 case WM_GETMINMAXINFO
:
1403 STRUCT32_MINMAXINFO32to16( (MINMAXINFO32
*)lParam
, &mmi
);
1404 MDI_ChildGetMinMaxInfo( clientWnd
, hwnd
, &mmi
);
1405 STRUCT32_MINMAXINFO16to32( &mmi
, (MINMAXINFO32
*)lParam
);
1411 /* MDI children don't have menu bars */
1412 PostMessage16( clientWnd
->parent
->hwndSelf
, WM_SYSCOMMAND
,
1413 (WPARAM16
)SC_KEYMENU
, (LPARAM
)LOWORD(wParam
) );
1418 case WM_CHILDACTIVATE
:
1424 return DefMDIChildProc16( hwnd
, message
, (WPARAM16
)wParam
, lParam
);
1426 return DefWindowProc32A(hwnd
, message
, wParam
, lParam
);
1430 /***********************************************************************
1431 * DefMDIChildProc32W (USER32.124)
1433 LRESULT WINAPI
DefMDIChildProc32W( HWND32 hwnd
, UINT32 message
,
1434 WPARAM32 wParam
, LPARAM lParam
)
1439 clientWnd
= WIN_FindWndPtr(GetParent16(hwnd
));
1440 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1445 DefWindowProc32W(hwnd
, message
, wParam
, lParam
);
1446 MDI_MenuModifyItem(clientWnd
,hwnd
);
1447 if( ci
->hwndChildMaximized
== hwnd
)
1448 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1449 MDI_REPAINTFRAME
, NULL
);
1452 case WM_GETMINMAXINFO
:
1456 case WM_CHILDACTIVATE
:
1462 return DefMDIChildProc32A( hwnd
, message
, (WPARAM16
)wParam
, lParam
);
1464 return DefWindowProc32W(hwnd
, message
, wParam
, lParam
);
1468 /**********************************************************************
1469 * CreateMDIWindowA (USER32.78)
1472 /**********************************************************************
1473 * CreateMDIWindowW (USER32.79)
1476 /**********************************************************************
1477 * TranslateMDISysAccel32 (USER32.554)
1479 BOOL32 WINAPI
TranslateMDISysAccel32( HWND32 hwndClient
, LPMSG32 msg
)
1483 STRUCT32_MSG32to16(msg
,&msg16
);
1484 /* MDICLIENTINFO is still the same for win32 and win16 ... */
1485 return TranslateMDISysAccel16(hwndClient
,&msg16
);
1489 /**********************************************************************
1490 * TranslateMDISysAccel16 (USER.451)
1492 BOOL16 WINAPI
TranslateMDISysAccel16( HWND16 hwndClient
, LPMSG16 msg
)
1494 WND
* clientWnd
= WIN_FindWndPtr( hwndClient
);
1496 if( clientWnd
&& (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
))
1498 MDICLIENTINFO
*ci
= NULL
;
1501 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1502 wnd
= WIN_FindWndPtr(ci
->hwndActiveChild
);
1503 if( wnd
&& !(wnd
->dwStyle
& WS_DISABLED
) )
1505 WPARAM16 wParam
= 0;
1507 /* translate if the Ctrl key is down and Alt not. */
1509 if( (GetKeyState32(VK_CONTROL
) & 0x8000) &&
1510 !(GetKeyState32(VK_MENU
) & 0x8000))
1512 switch( msg
->wParam
)
1516 wParam
= ( GetKeyState32(VK_SHIFT
) & 0x8000 )
1517 ? SC_NEXTWINDOW
: SC_PREVWINDOW
;
1526 TRACE(mdi
,"wParam = %04x\n", wParam
);
1527 SendMessage16( ci
->hwndActiveChild
, WM_SYSCOMMAND
,
1528 wParam
, (LPARAM
)msg
->wParam
);
1533 return 0; /* failure */
1537 /***********************************************************************
1538 * CalcChildScroll (USER.462)
1540 void WINAPI
CalcChildScroll( HWND16 hwnd
, WORD scroll
)
1542 RECT32 childRect
, clientRect
;
1543 INT32 vmin
, vmax
, hmin
, hmax
, vpos
, hpos
;
1544 BOOL32 noscroll
= FALSE
;
1547 if (!(Wnd
= pWnd
= WIN_FindWndPtr( hwnd
))) return;
1548 GetClientRect32( hwnd
, &clientRect
);
1549 SetRectEmpty32( &childRect
);
1551 for ( pWnd
= pWnd
->child
; pWnd
; pWnd
= pWnd
->next
)
1553 UnionRect32( &childRect
, &pWnd
->rectWindow
, &childRect
);
1554 if( pWnd
->dwStyle
& WS_MAXIMIZE
)
1557 UnionRect32( &childRect
, &clientRect
, &childRect
);
1559 /* jump through the hoops to prevent excessive flashing
1562 hmin
= childRect
.left
; hmax
= childRect
.right
- clientRect
.right
;
1563 hpos
= clientRect
.left
- childRect
.left
;
1564 vmin
= childRect
.top
; vmax
= childRect
.bottom
- clientRect
.bottom
;
1565 vpos
= clientRect
.top
- childRect
.top
;
1568 ShowScrollBar32(hwnd
, SB_BOTH
, FALSE
);
1573 vpos
= hpos
; vmin
= hmin
; vmax
= hmax
;
1575 SetScrollPos32(hwnd
, scroll
, vpos
, FALSE
);
1576 SetScrollRange32(hwnd
, scroll
, vmin
, vmax
, TRUE
);
1579 SCROLL_SetNCSbState( Wnd
, vmin
, vmax
, vpos
,
1581 SetWindowPos32(hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
1582 | SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
1587 /***********************************************************************
1588 * ScrollChildren16 (USER.463)
1590 void WINAPI
ScrollChildren16(HWND16 hWnd
, UINT16 uMsg
, WPARAM16 wParam
, LPARAM lParam
)
1592 return ScrollChildren32( hWnd
, uMsg
, wParam
, lParam
);
1596 /***********************************************************************
1597 * ScrollChildren32 (USER32.447)
1599 void WINAPI
ScrollChildren32(HWND32 hWnd
, UINT32 uMsg
, WPARAM32 wParam
,
1602 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
1604 INT32 curPos
, length
, minPos
, maxPos
, shift
;
1606 if( !wndPtr
) return;
1608 if( uMsg
== WM_HSCROLL
)
1610 GetScrollRange32(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
1611 curPos
= GetScrollPos32(hWnd
,SB_HORZ
);
1612 length
= (wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
)/2;
1613 shift
= SYSMETRICS_CYHSCROLL
;
1615 else if( uMsg
== WM_VSCROLL
)
1617 GetScrollRange32(hWnd
,SB_VERT
,&minPos
,&maxPos
);
1618 curPos
= GetScrollPos32(hWnd
,SB_VERT
);
1619 length
= (wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
)/2;
1620 shift
= SYSMETRICS_CXVSCROLL
;
1627 newPos
= curPos
- shift
;
1630 newPos
= curPos
+ shift
;
1633 newPos
= curPos
- length
;
1636 newPos
= curPos
+ length
;
1639 case SB_THUMBPOSITION
:
1640 newPos
= LOWORD(lParam
);
1653 CalcChildScroll(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
1657 if( newPos
> maxPos
)
1660 if( newPos
< minPos
)
1663 SetScrollPos32(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
1665 if( uMsg
== WM_VSCROLL
)
1666 ScrollWindowEx32(hWnd
,0 ,curPos
- newPos
, NULL
, NULL
, 0, NULL
,
1667 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);
1669 ScrollWindowEx32(hWnd
,curPos
- newPos
, 0, NULL
, NULL
, 0, NULL
,
1670 SW_INVALIDATE
| SW_ERASE
| SW_SCROLLCHILDREN
);