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.
23 #include "nonclient.h"
29 #include "sysmetrics.h"
34 static HBITMAP16 hBmpClose
= 0;
35 static HBITMAP16 hBmpRestore
= 0;
37 DWORD
SCROLL_SetNCSbState(WND
*,int,int,int,int,int,int);
39 /* ----------------- declarations ----------------- */
40 void MDI_UpdateFrameText(WND
*, HWND
, BOOL
, LPCSTR
);
41 BOOL
MDI_AugmentFrameMenu(MDICLIENTINFO
*, WND
*, HWND
);
42 BOOL
MDI_RestoreFrameMenu(WND
*, HWND
);
44 static LONG
MDI_ChildActivate(WND
* ,HWND
);
46 /* -------- Miscellaneous service functions ----------
51 static HWND
MDI_GetChildByID(WND
* wndPtr
,int id
)
53 for (wndPtr
= wndPtr
->child
; wndPtr
; wndPtr
= wndPtr
->next
)
54 if (wndPtr
->wIDmenu
== id
) return wndPtr
->hwndSelf
;
58 static void MDI_PostUpdate(HWND hwnd
, MDICLIENTINFO
* ci
, WORD recalc
)
60 if( !ci
->sbNeedUpdate
)
62 ci
->sbNeedUpdate
= TRUE
;
63 PostMessage( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0);
65 ci
->sbRecalc
= recalc
;
68 /**********************************************************************
71 #ifdef SUPERFLUOUS_FUNCTIONS
72 static BOOL
MDI_MenuAppendItem(WND
*clientWnd
, HWND hWndChild
)
75 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
76 WND
*wndPtr
= WIN_FindWndPtr(hWndChild
);
77 int n
= sprintf(buffer
, "%d ",
78 clientInfo
->nActiveChildren
);
80 if( !clientInfo
->hWindowMenu
) return 0;
82 if (wndPtr
->text
) strncpy(buffer
+ n
, wndPtr
->text
, sizeof(buffer
) - n
- 1);
83 return AppendMenu32A( clientInfo
->hWindowMenu
, MF_STRING
,
84 wndPtr
->wIDmenu
, buffer
);
88 /**********************************************************************
91 static BOOL
MDI_MenuModifyItem(WND
* clientWnd
, HWND hWndChild
)
94 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
95 WND
*wndPtr
= WIN_FindWndPtr(hWndChild
);
96 UINT n
= sprintf(buffer
, "%d ",
97 wndPtr
->wIDmenu
- clientInfo
->idFirstChild
+ 1);
100 if( !clientInfo
->hWindowMenu
) return 0;
102 if (wndPtr
->text
) lstrcpyn32A(buffer
+ n
, wndPtr
->text
, sizeof(buffer
) - n
);
104 n
= GetMenuState(clientInfo
->hWindowMenu
,wndPtr
->wIDmenu
,MF_BYCOMMAND
);
105 bRet
= ModifyMenu32A(clientInfo
->hWindowMenu
, wndPtr
->wIDmenu
,
106 MF_BYCOMMAND
| MF_STRING
, wndPtr
->wIDmenu
, buffer
);
107 CheckMenuItem(clientInfo
->hWindowMenu
,wndPtr
->wIDmenu
, n
& MF_CHECKED
);
111 /**********************************************************************
114 static BOOL
MDI_MenuDeleteItem(WND
* clientWnd
, HWND hWndChild
)
117 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
118 WND
*wndPtr
= WIN_FindWndPtr(hWndChild
);
121 if( !clientInfo
->nActiveChildren
||
122 !clientInfo
->hWindowMenu
) return 0;
124 id
= wndPtr
->wIDmenu
;
125 DeleteMenu(clientInfo
->hWindowMenu
,id
,MF_BYCOMMAND
);
127 /* walk the rest of MDI children to prevent gaps in the id
128 * sequence and in the menu child list */
130 for( index
= id
+1; index
<= clientInfo
->nActiveChildren
+
131 clientInfo
->idFirstChild
; index
++ )
133 wndPtr
= WIN_FindWndPtr(MDI_GetChildByID(clientWnd
,index
));
136 dprintf_mdi(stddeb
,"MDIMenuDeleteItem: no window for id=%i\n",index
);
143 n
= sprintf(buffer
, "%d ",index
- clientInfo
->idFirstChild
);
145 lstrcpyn32A(buffer
+ n
, wndPtr
->text
, sizeof(buffer
) - n
);
148 ModifyMenu32A(clientInfo
->hWindowMenu
,index
,MF_BYCOMMAND
| MF_STRING
,
149 index
- 1 , buffer
);
154 /**********************************************************************
157 * returns "activateable" child or zero
159 HWND
MDI_GetWindow(WND
*clientWnd
, HWND hWnd
, WORD wTo
)
161 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
162 WND
*wndPtr
, *pWnd
, *pWndLast
;
164 if( !hWnd
) hWnd
= clientInfo
->hwndActiveChild
;
166 if( !(wndPtr
= WIN_FindWndPtr(hWnd
)) ) return 0;
173 if (!pWnd
) pWnd
= wndPtr
->parent
->child
;
174 if (pWnd
== wndPtr
) /* not found */
176 if (!wTo
|| !pWndLast
) return 0;
180 /* we are not interested in owned popups */
182 (pWnd
->dwStyle
& WS_VISIBLE
) &&
183 !(pWnd
->dwStyle
& WS_DISABLED
)) /* found one */
189 return pWndLast
? pWndLast
->hwndSelf
: 0;
192 /**********************************************************************
193 * MDI_CalcDefaultChildPos
195 * It seems that default height is 2/3 of client rect
197 void MDI_CalcDefaultChildPos(WND
* w
, WORD n
, LPPOINT16 lpPos
, INT delta
)
199 RECT16 rect
= w
->rectClient
;
200 INT spacing
= GetSystemMetrics(SM_CYCAPTION
) + GetSystemMetrics(SM_CYFRAME
) - 1;
203 if( rect
.bottom
- rect
.top
- delta
>= spacing
)
204 rect
.bottom
-= delta
;
206 nstagger
= (rect
.bottom
- rect
.top
)/(3*spacing
);
207 lpPos
[1].x
= (rect
.right
- rect
.left
- nstagger
*spacing
);
208 lpPos
[1].y
= (rect
.bottom
- rect
.top
- nstagger
*spacing
);
209 lpPos
[0].x
= lpPos
[0].y
= spacing
*(n
%(nstagger
+1));
212 /**********************************************************************
215 HMENU16
MDISetMenu(HWND hwnd
, BOOL fRefresh
, HMENU16 hmenuFrame
,
218 WND
*w
= WIN_FindWndPtr(hwnd
);
221 dprintf_mdi(stddeb
, "WM_MDISETMENU: %04x %04x %04x %04x\n",
222 hwnd
, fRefresh
, hmenuFrame
, hmenuWindow
);
224 ci
= (MDICLIENTINFO
*) w
->wExtra
;
228 HWND hwndFrame
= GetParent16(hwnd
);
229 HMENU16 oldFrameMenu
= GetMenu(hwndFrame
);
231 if( ci
->hwndChildMaximized
&& hmenuFrame
&& hmenuFrame
!=oldFrameMenu
)
232 MDI_RestoreFrameMenu(w
->parent
, ci
->hwndChildMaximized
);
234 if( hmenuWindow
&& hmenuWindow
!=ci
->hWindowMenu
)
236 /* delete menu items from ci->hWindowMenu
237 * and add them to hmenuWindow */
239 INT i
= GetMenuItemCount(ci
->hWindowMenu
) - 1;
240 INT pos
= GetMenuItemCount(hmenuWindow
) + 1;
242 AppendMenu32A( hmenuWindow
, MF_SEPARATOR
, 0, NULL
);
244 if( ci
->nActiveChildren
)
246 INT j
= i
- ci
->nActiveChildren
+ 1;
250 for( ; i
>= j
; i
-- )
252 id
= GetMenuItemID(ci
->hWindowMenu
,i
);
253 state
= GetMenuState(ci
->hWindowMenu
,i
,MF_BYPOSITION
);
255 GetMenuString(ci
->hWindowMenu
, i
, buffer
, 100, MF_BYPOSITION
);
257 DeleteMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
258 InsertMenu32A(hmenuWindow
, pos
, MF_BYPOSITION
| MF_STRING
,
260 CheckMenuItem(hmenuWindow
,pos
, MF_BYPOSITION
| (state
& MF_CHECKED
));
264 /* remove separator */
265 DeleteMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
267 ci
->hWindowMenu
= hmenuWindow
;
270 if( hmenuFrame
&& hmenuFrame
!=oldFrameMenu
)
272 SetMenu(hwndFrame
, hmenuFrame
);
273 if( ci
->hwndChildMaximized
)
274 MDI_AugmentFrameMenu(ci
, w
->parent
, ci
->hwndChildMaximized
);
282 /**********************************************************************
285 WORD
MDIIconArrange(HWND parent
)
287 return ArrangeIconicWindows(parent
); /* Any reason why the */
288 /* existing icon arrange */
289 /* can't be used here? */
294 /* ------------------ MDI child window functions ---------------------- */
297 /**********************************************************************
300 HWND
MDICreateChild(WND
*w
, MDICLIENTINFO
*ci
, HWND parent
, LPARAM lParam
)
303 MDICREATESTRUCT16
*cs
= (MDICREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
304 DWORD style
= cs
->style
| (WS_CHILD
| WS_CLIPSIBLINGS
);
305 HWND hwnd
, hwndMax
= 0;
306 WORD wIDmenu
= ci
->idFirstChild
+ ci
->nActiveChildren
;
307 char lpstrDef
[]="junk!";
310 * Create child window
314 dprintf_mdi(stdnimp
,"MDICreateChild: origin %i,%i - dim %i,%i, style %08x\n",
315 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, (unsigned)cs
->style
);
316 /* calculate placement */
317 MDI_CalcDefaultChildPos(w
, ci
->nTotalCreated
++, pos
, 0);
319 if( cs
->cx
== CW_USEDEFAULT16
|| !cs
->cx
)
321 if( cs
->cy
== CW_USEDEFAULT16
|| !cs
->cy
)
324 if( cs
->x
== CW_USEDEFAULT16
)
330 /* restore current maximized child */
331 if( style
& WS_VISIBLE
&& ci
->hwndChildMaximized
)
333 if( style
& WS_MAXIMIZE
)
334 SendMessage16(w
->hwndSelf
, WM_SETREDRAW
, FALSE
, 0L );
335 hwndMax
= ci
->hwndChildMaximized
;
336 ShowWindow( hwndMax
, SW_SHOWNOACTIVATE
);
337 if( style
& WS_MAXIMIZE
)
338 SendMessage16(w
->hwndSelf
, WM_SETREDRAW
, TRUE
, 0L );
341 /* this menu is needed to set a check mark in MDI_ChildActivate */
342 AppendMenu32A(ci
->hWindowMenu
,MF_STRING
,wIDmenu
, lpstrDef
);
344 ci
->nActiveChildren
++;
346 /* fix window style */
347 if( !(w
->dwStyle
& MDIS_ALLCHILDSTYLES
) )
349 style
&= (WS_CHILD
| WS_CLIPSIBLINGS
| WS_MINIMIZE
| WS_MAXIMIZE
|
350 WS_CLIPCHILDREN
| WS_DISABLED
| WS_VSCROLL
| WS_HSCROLL
);
351 style
|= (WS_VISIBLE
| WS_OVERLAPPEDWINDOW
);
354 hwnd
= CreateWindow16( (LPCSTR
)PTR_SEG_TO_LIN(cs
->szClass
),
355 (LPCSTR
)PTR_SEG_TO_LIN(cs
->szTitle
), style
,
356 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, parent
,
357 (HMENU16
)wIDmenu
, w
->hInstance
,
360 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
364 WND
* wnd
= WIN_FindWndPtr( hwnd
);
366 MDI_MenuModifyItem(w
,hwnd
);
367 if( wnd
->dwStyle
& WS_MINIMIZE
&& ci
->hwndActiveChild
)
368 ShowWindow( hwnd
, SW_SHOWMINNOACTIVE
);
371 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
);
373 /* Set maximized state here in case hwnd didn't receive WM_SIZE
374 * during CreateWindow - bad!
377 if( wnd
->dwStyle
& WS_MAXIMIZE
&& !ci
->hwndChildMaximized
)
379 ci
->hwndChildMaximized
= wnd
->hwndSelf
;
380 MDI_AugmentFrameMenu( ci
, w
->parent
, hwnd
);
381 MDI_UpdateFrameText( w
->parent
, ci
->self
, MDI_REPAINTFRAME
, NULL
);
384 dprintf_mdi(stddeb
, "MDICreateChild: created child - %04x\n",hwnd
);
388 ci
->nActiveChildren
--;
389 DeleteMenu(ci
->hWindowMenu
,wIDmenu
,MF_BYCOMMAND
);
390 if( IsWindow(hwndMax
) )
391 ShowWindow(hwndMax
, SW_SHOWMAXIMIZED
);
397 /**********************************************************************
398 * MDI_ChildGetMinMaxInfo
400 void MDI_ChildGetMinMaxInfo(WND
* clientWnd
, HWND hwnd
, MINMAXINFO16
* lpMinMax
)
402 WND
* childWnd
= WIN_FindWndPtr(hwnd
);
403 RECT16 rect
= clientWnd
->rectClient
;
405 MapWindowPoints16(clientWnd
->parent
->hwndSelf
,
406 ((MDICLIENTINFO
*)clientWnd
->wExtra
)->self
, (LPPOINT16
)&rect
, 2);
407 AdjustWindowRectEx16( &rect
, childWnd
->dwStyle
, 0, childWnd
->dwExStyle
);
409 lpMinMax
->ptMaxSize
.x
= rect
.right
-= rect
.left
;
410 lpMinMax
->ptMaxSize
.y
= rect
.bottom
-= rect
.top
;
412 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
413 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
415 dprintf_mdi(stddeb
,"\tChildMinMaxInfo: max rect (%i,%i - %i, %i)\n",
416 rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
420 /**********************************************************************
421 * MDI_SwitchActiveChild
423 * Notes: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
426 * wTo is basically lParam of WM_MDINEXT message or explicit
429 void MDI_SwitchActiveChild(HWND clientHwnd
, HWND childHwnd
, BOOL wTo
)
431 WND
*w
= WIN_FindWndPtr(clientHwnd
);
436 hwndTo
= MDI_GetWindow(w
,childHwnd
,(WORD
)wTo
);
438 ci
= (MDICLIENTINFO
*) w
->wExtra
;
440 dprintf_mdi(stddeb
, "MDI_SwitchActiveChild: from %04x, to %04x\n",childHwnd
,hwndTo
);
442 if ( !hwndTo
) return;
444 hwndPrev
= ci
->hwndActiveChild
;
446 if ( hwndTo
!= hwndPrev
)
450 if( ci
->hwndChildMaximized
)
453 w
->dwStyle
&= ~WS_VISIBLE
;
456 SetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0,
457 SWP_NOMOVE
| SWP_NOSIZE
);
458 if( !wTo
&& hwndPrev
)
460 SetWindowPos( hwndPrev
, HWND_BOTTOM
, 0, 0, 0, 0,
461 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
465 ShowWindow( clientHwnd
, SW_SHOW
);
470 /**********************************************************************
473 HWND
MDIDestroyChild(WND
*w_parent
, MDICLIENTINFO
*ci
, HWND parent
,
474 HWND child
, BOOL flagDestroy
)
476 WND
*childPtr
= WIN_FindWndPtr(child
);
480 if( child
== ci
->hwndActiveChild
)
482 MDI_SwitchActiveChild(parent
,child
,0);
484 if( child
== ci
->hwndActiveChild
)
486 ShowWindow( child
, SW_HIDE
);
487 if( child
== ci
->hwndChildMaximized
)
489 MDI_RestoreFrameMenu(w_parent
->parent
, child
);
490 ci
->hwndChildMaximized
= 0;
491 MDI_UpdateFrameText(w_parent
->parent
,parent
,TRUE
,NULL
);
494 MDI_ChildActivate(w_parent
,0);
496 MDI_MenuDeleteItem(w_parent
, child
);
499 ci
->nActiveChildren
--;
501 dprintf_mdi(stddeb
,"MDIDestroyChild: child destroyed - %04x\n",child
);
505 MDI_PostUpdate(GetParent16(child
), ci
, SB_BOTH
+1);
506 DestroyWindow(child
);
514 /**********************************************************************
517 * Note: hWndChild is NULL when last child is being destroyed
519 LONG
MDI_ChildActivate(WND
*clientPtr
, HWND hWndChild
)
521 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientPtr
->wExtra
;
522 HWND prevActiveWnd
= clientInfo
->hwndActiveChild
;
523 WND
*wndPtr
= WIN_FindWndPtr( hWndChild
);
524 WND
*wndPrev
= WIN_FindWndPtr( prevActiveWnd
);
525 BOOL isActiveFrameWnd
= 0;
527 if( hWndChild
== prevActiveWnd
) return 0L;
530 if( wndPtr
->dwStyle
& WS_DISABLED
) return 0L;
532 dprintf_mdi(stddeb
,"MDI_ChildActivate: %04x\n", hWndChild
);
534 if( GetActiveWindow() == clientPtr
->parent
->hwndSelf
)
535 isActiveFrameWnd
= TRUE
;
537 /* deactivate prev. active child */
540 wndPrev
->dwStyle
|= WS_SYSMENU
;
541 SendMessage16( prevActiveWnd
, WM_NCACTIVATE
, FALSE
, 0L );
544 SendMessage32A( prevActiveWnd
, WM_MDIACTIVATE
, (WPARAM32
)prevActiveWnd
,
548 SendMessage16( prevActiveWnd
, WM_MDIACTIVATE
, FALSE
,
549 MAKELONG(hWndChild
,prevActiveWnd
));
551 /* uncheck menu item */
552 if( clientInfo
->hWindowMenu
)
553 CheckMenuItem( clientInfo
->hWindowMenu
,
554 wndPrev
->wIDmenu
, 0);
558 if( clientInfo
->hwndChildMaximized
)
559 if( clientInfo
->hwndChildMaximized
!= hWndChild
)
562 clientInfo
->hwndActiveChild
= hWndChild
;
563 ShowWindow( hWndChild
, SW_SHOWMAXIMIZED
);
566 ShowWindow( clientInfo
->hwndActiveChild
,
569 clientInfo
->hwndActiveChild
= hWndChild
;
571 /* check if we have any children left */
574 if( isActiveFrameWnd
)
575 SetFocus32( clientInfo
->self
);
579 /* check menu item */
580 if( clientInfo
->hWindowMenu
)
581 CheckMenuItem( clientInfo
->hWindowMenu
,
582 wndPtr
->wIDmenu
, MF_CHECKED
);
584 /* bring active child to the top */
585 SetWindowPos( hWndChild
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
587 if( isActiveFrameWnd
)
589 SendMessage16( hWndChild
, WM_NCACTIVATE
, TRUE
, 0L);
590 if( GetFocus32() == clientInfo
->self
)
591 SendMessage16( clientInfo
->self
, WM_SETFOCUS
,
592 (WPARAM16
)clientInfo
->self
, 0L );
594 SetFocus32( clientInfo
->self
);
598 SendMessage32A( hWndChild
, WM_MDIACTIVATE
, (WPARAM32
)hWndChild
,
599 (LPARAM
)prevActiveWnd
);
601 SendMessage16( hWndChild
, WM_MDIACTIVATE
, TRUE
,
602 MAKELONG(hWndChild
,prevActiveWnd
));
608 /**********************************************************************
611 * iTotal returns number of children available for tiling or cascading
613 MDIWCL
* MDI_BuildWCL(WND
* clientWnd
, INT16
* iTotal
)
615 MDIWCL
*listTop
,*listNext
;
618 if (!(listTop
= (MDIWCL
*)malloc( sizeof(MDIWCL
) ))) return NULL
;
620 listTop
->hChild
= clientWnd
->child
? clientWnd
->child
->hwndSelf
: 0;
621 listTop
->prev
= NULL
;
624 /* build linked list from top child to bottom */
626 childWnd
= WIN_FindWndPtr( listTop
->hChild
);
627 while( childWnd
&& childWnd
->next
)
629 listNext
= (MDIWCL
*)xmalloc(sizeof(MDIWCL
));
631 if( (childWnd
->dwStyle
& WS_DISABLED
) ||
632 (childWnd
->dwStyle
& WS_MINIMIZE
) ||
633 !(childWnd
->dwStyle
& WS_VISIBLE
) )
639 listNext
->hChild
= childWnd
->next
->hwndSelf
;
640 listNext
->prev
= listTop
;
644 childWnd
= childWnd
->next
;
647 if( (childWnd
->dwStyle
& WS_DISABLED
) ||
648 (childWnd
->dwStyle
& WS_MINIMIZE
) ||
649 !(childWnd
->dwStyle
& WS_VISIBLE
) )
659 /* -------------------- MDI client window functions ------------------- */
661 /**********************************************************************
662 * CreateMDIMenuBitmap
664 HBITMAP16
CreateMDIMenuBitmap(void)
666 HDC32 hDCSrc
= CreateCompatibleDC32(0);
667 HDC32 hDCDest
= CreateCompatibleDC32(hDCSrc
);
668 HBITMAP16 hbClose
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_CLOSE
) );
669 HBITMAP16 hbCopy
,hb_src
,hb_dest
;
671 hb_src
= SelectObject32(hDCSrc
,hbClose
);
672 hbCopy
= CreateCompatibleBitmap(hDCSrc
,SYSMETRICS_CXSIZE
, SYSMETRICS_CYSIZE
);
673 hb_dest
= SelectObject32(hDCDest
,hbCopy
);
675 BitBlt32(hDCDest
, 0, 0, SYSMETRICS_CXSIZE
, SYSMETRICS_CYSIZE
,
676 hDCSrc
, SYSMETRICS_CXSIZE
, 0, SRCCOPY
);
678 SelectObject32(hDCSrc
,hb_src
);
679 SelectObject32(hDCDest
,hb_dest
);
681 DeleteObject32(hbClose
);
689 /**********************************************************************
692 LONG
MDICascade(WND
* clientWnd
, MDICLIENTINFO
*ci
)
694 MDIWCL
*listTop
,*listPrev
;
695 INT16 delta
= 0,iToPosition
= 0, n
= 0;
698 if (ci
->hwndChildMaximized
)
699 ShowWindow( ci
->hwndChildMaximized
, SW_NORMAL
);
701 if (ci
->nActiveChildren
== 0) return 0;
703 if (!(listTop
= MDI_BuildWCL(clientWnd
,&iToPosition
))) return 0;
705 if( iToPosition
< ci
->nActiveChildren
)
706 delta
= 2 * SYSMETRICS_CYICONSPACING
+ SYSMETRICS_CYICON
;
708 /* walk list and move windows */
711 dprintf_mdi(stddeb
, "MDICascade: move %04x to (%d,%d) size [%d,%d]\n",
712 listTop
->hChild
, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
);
714 if( listTop
->hChild
)
716 MDI_CalcDefaultChildPos(clientWnd
, n
++, pos
, delta
);
717 SetWindowPos(listTop
->hChild
, 0, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
,
718 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
721 listPrev
= listTop
->prev
;
726 if( iToPosition
< ci
->nActiveChildren
)
727 ArrangeIconicWindows( clientWnd
->hwndSelf
);
732 /**********************************************************************
736 LONG
MDITile(WND
* wndClient
, MDICLIENTINFO
*ci
,WORD wParam
)
738 MDIWCL
*listTop
,*listPrev
;
745 INT16 iToPosition
= 0;
747 if (ci
->hwndChildMaximized
)
748 ShowWindow(ci
->hwndChildMaximized
, SW_NORMAL
);
750 if (ci
->nActiveChildren
== 0) return 0;
752 listTop
= MDI_BuildWCL(wndClient
, &iToPosition
);
754 dprintf_mdi(stddeb
,"MDITile: %i windows to tile\n",iToPosition
);
756 if( !listTop
) return 0;
761 rect
= wndClient
->rectClient
;
762 rows
= (int) sqrt((double) iToPosition
);
763 columns
= iToPosition
/ rows
;
765 if (wParam
== MDITILE_HORIZONTAL
) /* version >= 3.1 */
768 rows
=columns
; /* exchange r and c */
773 if( iToPosition
!= ci
->nActiveChildren
)
775 y
= rect
.bottom
- 2 * SYSMETRICS_CYICONSPACING
- SYSMETRICS_CYICON
;
776 rect
.bottom
= ( y
- SYSMETRICS_CYICON
< rect
.top
)? rect
.bottom
: y
;
779 ysize
= rect
.bottom
/ rows
;
780 xsize
= rect
.right
/ columns
;
785 for (c
= 1; c
<= columns
; c
++)
789 rows
= iToPosition
- i
;
790 ysize
= rect
.bottom
/ rows
;
794 for (r
= 1; r
<= rows
; r
++, i
++)
796 /* shouldn't happen but... */
800 /* skip iconized childs from tiling */
801 while (!listTop
->hChild
)
803 listPrev
= listTop
->prev
;
807 SetWindowPos(listTop
->hChild
, 0, x
, y
, xsize
, ysize
,
808 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
810 listPrev
= listTop
->prev
;
818 /* free the rest if any */
821 listPrev
= listTop
->prev
;
826 if (iToPosition
< ci
->nActiveChildren
)
827 ArrangeIconicWindows( wndClient
->hwndSelf
);
832 /* ----------------------- Frame window ---------------------------- */
835 /**********************************************************************
836 * MDI_AugmentFrameMenu
838 BOOL
MDI_AugmentFrameMenu(MDICLIENTINFO
* ci
, WND
*frame
, HWND hChild
)
840 WND
* child
= WIN_FindWndPtr(hChild
);
842 HMENU16 hSysPopup
= 0;
844 dprintf_mdi(stddeb
,"MDI_AugmentFrameMenu: frame %p,child %04x\n",frame
,hChild
);
846 if( !frame
->wIDmenu
|| !child
->hSysMenu
) return 0;
848 /* create a copy of sysmenu popup and insert it into frame menu bar */
850 if (!(handle
= SYSRES_LoadResource( SYSRES_MENU_SYSMENU
))) return 0;
851 hSysPopup
= LoadMenuIndirect16( GlobalLock16( handle
) );
852 SYSRES_FreeResource( handle
);
854 dprintf_mdi(stddeb
,"\t\tgot popup %04x\n in sysmenu %04x",hSysPopup
,child
->hSysMenu
);
856 if( !InsertMenu32A(frame
->wIDmenu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
857 hSysPopup
, (LPSTR
)(DWORD
)hBmpClose
))
858 { DestroyMenu(hSysPopup
); return 0; }
860 if( !AppendMenu32A(frame
->wIDmenu
,MF_HELP
| MF_BITMAP
,
861 SC_RESTORE
, (LPSTR
)(DWORD
)hBmpRestore
))
863 RemoveMenu(frame
->wIDmenu
,0,MF_BYPOSITION
);
867 EnableMenuItem(hSysPopup
, SC_SIZE
, MF_BYCOMMAND
| MF_GRAYED
);
868 EnableMenuItem(hSysPopup
, SC_MOVE
, MF_BYCOMMAND
| MF_GRAYED
);
869 EnableMenuItem(hSysPopup
, SC_MAXIMIZE
, MF_BYCOMMAND
| MF_GRAYED
);
872 DrawMenuBar(frame
->hwndSelf
);
877 /**********************************************************************
878 * MDI_RestoreFrameMenu
880 BOOL
MDI_RestoreFrameMenu( WND
*frameWnd
, HWND hChild
)
882 INT nItems
= GetMenuItemCount(frameWnd
->wIDmenu
) - 1;
884 dprintf_mdi(stddeb
,"MDI_RestoreFrameMenu: for child %04x\n",hChild
);
886 if( GetMenuItemID(frameWnd
->wIDmenu
,nItems
) != SC_RESTORE
)
890 RemoveMenu(frameWnd
->wIDmenu
,0,MF_BYPOSITION
);
891 DeleteMenu(frameWnd
->wIDmenu
,nItems
-1,MF_BYPOSITION
);
893 DrawMenuBar(frameWnd
->hwndSelf
);
898 /**********************************************************************
899 * MDI_UpdateFrameText
901 * used when child window is maximized/restored
903 * Note: lpTitle can be NULL
905 void MDI_UpdateFrameText(WND
*frameWnd
, HWND hClient
, BOOL repaint
, LPCSTR lpTitle
)
907 char lpBuffer
[MDI_MAXTITLELENGTH
+1];
908 WND
* clientWnd
= WIN_FindWndPtr(hClient
);
910 MDICLIENTINFO
*ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
912 dprintf_mdi(stddeb
, "MDI: repaint %i, frameText %s\n", repaint
, (lpTitle
)?lpTitle
:"NULL");
914 /* store new "default" title if lpTitle is not NULL */
917 if (ci
->frameTitle
) HeapFree( SystemHeap
, 0, ci
->frameTitle
);
918 ci
->frameTitle
= HEAP_strdupA( SystemHeap
, 0, lpTitle
);
923 WND
* childWnd
= WIN_FindWndPtr( ci
->hwndChildMaximized
);
925 if( childWnd
&& childWnd
->text
)
927 /* combine frame title and child title if possible */
929 LPCSTR lpBracket
= " - [";
930 int i_frame_text_length
= strlen(ci
->frameTitle
);
931 int i_child_text_length
= strlen(childWnd
->text
);
933 lstrcpyn32A( lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
935 if( i_frame_text_length
+ 6 < MDI_MAXTITLELENGTH
)
937 strcat( lpBuffer
, lpBracket
);
939 if( i_frame_text_length
+ i_child_text_length
+ 6 < MDI_MAXTITLELENGTH
)
941 strcat( lpBuffer
, childWnd
->text
);
942 strcat( lpBuffer
, "]" );
946 lstrcpyn32A( lpBuffer
+ i_frame_text_length
+ 4,
948 MDI_MAXTITLELENGTH
- i_frame_text_length
- 5 );
949 strcat( lpBuffer
, "]" );
955 strncpy(lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
956 lpBuffer
[MDI_MAXTITLELENGTH
]='\0';
962 DEFWND_SetText( frameWnd
, lpBuffer
);
963 if( repaint
== MDI_REPAINTFRAME
)
964 SetWindowPos(frameWnd
->hwndSelf
, 0,0,0,0,0, SWP_FRAMECHANGED
|
965 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
969 /* ----------------------------- Interface ---------------------------- */
972 /**********************************************************************
975 * This function is the handler for all MDI requests.
977 LRESULT
MDIClientWndProc(HWND hwnd
, UINT message
, WPARAM16 wParam
, LPARAM lParam
)
980 LPCLIENTCREATESTRUCT16 ccs
;
983 WND
*w
= WIN_FindWndPtr(hwnd
);
984 WND
*frameWnd
= w
->parent
;
987 ci
= (MDICLIENTINFO
*) w
->wExtra
;
992 cs
= (LPCREATESTRUCT16
) PTR_SEG_TO_LIN(lParam
);
993 ccs
= (LPCLIENTCREATESTRUCT16
) PTR_SEG_TO_LIN(cs
->lpCreateParams
);
995 ci
->hWindowMenu
= ccs
->hWindowMenu
;
996 ci
->idFirstChild
= ccs
->idFirstChild
;
997 ci
->hwndChildMaximized
= 0;
998 ci
->nActiveChildren
= 0;
999 ci
->nTotalCreated
= 0;
1000 ci
->frameTitle
= NULL
;
1001 ci
->sbNeedUpdate
= 0;
1003 w
->dwStyle
|= WS_CLIPCHILDREN
;
1007 hBmpClose
= CreateMDIMenuBitmap();
1008 hBmpRestore
= LoadBitmap16( 0, MAKEINTRESOURCE(OBM_RESTORE
) );
1010 MDI_UpdateFrameText(frameWnd
, hwnd
, MDI_NOFRAMEREPAINT
,frameWnd
->text
);
1012 AppendMenu32A( ccs
->hWindowMenu
, MF_SEPARATOR
, 0, NULL
);
1014 GetClientRect16(frameWnd
->hwndSelf
, &rect
);
1015 NC_HandleNCCalcSize( w
, &rect
);
1016 w
->rectClient
= rect
;
1018 dprintf_mdi(stddeb
,"MDI: Client created - hwnd = %04x, idFirst = %u\n",hwnd
,ci
->idFirstChild
);
1023 if( ci
->hwndChildMaximized
) MDI_RestoreFrameMenu(w
, frameWnd
->hwndSelf
);
1024 if((nItems
= GetMenuItemCount(ci
->hWindowMenu
)) > 0) {
1025 ci
->idFirstChild
= nItems
- 1;
1026 ci
->nActiveChildren
++; /* to delete a separator */
1027 while( ci
->nActiveChildren
-- )
1028 DeleteMenu(ci
->hWindowMenu
,MF_BYPOSITION
,ci
->idFirstChild
--);
1032 case WM_MDIACTIVATE
:
1033 if( ci
->hwndActiveChild
!= (HWND
)wParam
)
1034 SetWindowPos((HWND
)wParam
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1038 return MDICascade(w
, ci
);
1041 return (LONG
)MDICreateChild(w
, ci
, hwnd
, lParam
);
1044 return (LONG
)MDIDestroyChild(w
, ci
, hwnd
, (HWND
)wParam
, TRUE
);
1046 case WM_MDIGETACTIVE
:
1047 return ((LONG
) ci
->hwndActiveChild
|
1048 ((LONG
) (ci
->hwndChildMaximized
>0) << 16));
1050 case WM_MDIICONARRANGE
:
1051 ci
->sbNeedUpdate
= TRUE
;
1052 MDIIconArrange(hwnd
);
1053 ci
->sbRecalc
= SB_BOTH
+1;
1054 SendMessage16(hwnd
,WM_MDICALCCHILDSCROLL
,0,0L);
1057 case WM_MDIMAXIMIZE
:
1058 ShowWindow((HWND
)wParam
, SW_MAXIMIZE
);
1062 MDI_SwitchActiveChild(hwnd
, (HWND
)wParam
, (lParam
)?1:0);
1066 ShowWindow( (HWND
)wParam
, SW_NORMAL
);
1071 return (LRESULT
)MDISetMenu(hwnd
, FALSE
, (HMENU16
)wParam
, (HMENU16
)lParam
);
1073 return (LRESULT
)MDISetMenu(hwnd
, wParam
, LOWORD(lParam
), HIWORD(lParam
));
1077 ci
->sbNeedUpdate
= TRUE
;
1078 ShowScrollBar32(hwnd
,SB_BOTH
,FALSE
);
1079 MDITile(w
, ci
,wParam
);
1080 ci
->sbNeedUpdate
= FALSE
;
1085 ci
->sbNeedUpdate
= TRUE
;
1086 ScrollChildren(hwnd
,message
,wParam
,lParam
);
1087 ci
->sbNeedUpdate
= FALSE
;
1091 if( ci
->hwndActiveChild
)
1093 w
= WIN_FindWndPtr( ci
->hwndActiveChild
);
1094 if( !(w
->dwStyle
& WS_MINIMIZE
) )
1095 SetFocus32( ci
->hwndActiveChild
);
1100 if( ci
->hwndActiveChild
)
1101 SendMessage16(ci
->hwndActiveChild
, message
, wParam
, lParam
);
1104 case WM_PARENTNOTIFY
:
1105 if( wParam
== WM_LBUTTONDOWN
)
1107 POINT16 pt
= MAKEPOINT16(lParam
);
1108 HWND child
= ChildWindowFromPoint16(hwnd
, pt
);
1110 dprintf_mdi(stddeb
,"MDIClient: notification from %04x (%i,%i)\n",child
,pt
.x
,pt
.y
);
1112 if( child
&& child
!= hwnd
)
1114 WND
* wnd
= WIN_FindWndPtr( child
);
1116 /* if we got owned popup */
1117 if( wnd
->owner
) child
= wnd
->owner
->hwndSelf
;
1119 if( child
!= ci
->hwndActiveChild
)
1120 SetWindowPos(child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1126 if( ci
->hwndChildMaximized
)
1128 WND
* child
= WIN_FindWndPtr(ci
->hwndChildMaximized
);
1129 RECT16 rect
= { 0, 0, LOWORD(lParam
), HIWORD(lParam
) };
1131 AdjustWindowRectEx16(&rect
, child
->dwStyle
, 0, child
->dwExStyle
);
1132 MoveWindow(ci
->hwndChildMaximized
, rect
.left
, rect
.top
,
1133 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 1);
1136 MDI_PostUpdate(hwnd
, ci
, SB_BOTH
+1);
1140 case WM_MDICALCCHILDSCROLL
:
1141 if( ci
->sbNeedUpdate
)
1144 CalcChildScroll(hwnd
, ci
->sbRecalc
-1);
1145 ci
->sbRecalc
= ci
->sbNeedUpdate
= 0;
1150 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1154 /***********************************************************************
1155 * DefFrameProc16 (USER.445)
1157 LRESULT
DefFrameProc16( HWND16 hwnd
, HWND16 hwndMDIClient
, UINT16 message
,
1158 WPARAM16 wParam
, LPARAM lParam
)
1169 wndPtr
= WIN_FindWndPtr(hwndMDIClient
);
1170 ci
= (MDICLIENTINFO
*)wndPtr
->wExtra
;
1172 /* check for possible syscommands for maximized MDI child */
1174 if( wParam
< ci
->idFirstChild
||
1175 wParam
>= ci
->idFirstChild
+ ci
->nActiveChildren
)
1177 if( (wParam
- 0xF000) & 0xF00F ) break;
1188 if( ci
->hwndChildMaximized
)
1189 return SendMessage16( ci
->hwndChildMaximized
, WM_SYSCOMMAND
,
1195 childHwnd
= MDI_GetChildByID( WIN_FindWndPtr(hwndMDIClient
),
1198 SendMessage16(hwndMDIClient
, WM_MDIACTIVATE
,
1199 (WPARAM16
)childHwnd
, 0L);
1204 SendMessage16(hwndMDIClient
, message
, wParam
, lParam
);
1208 MDI_UpdateFrameText(WIN_FindWndPtr(hwnd
), hwndMDIClient
,
1210 (LPCSTR
)PTR_SEG_TO_LIN(lParam
));
1214 SetFocus32(hwndMDIClient
);
1218 MoveWindow(hwndMDIClient
, 0, 0,
1219 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1224 wndPtr
= WIN_FindWndPtr(hwndMDIClient
);
1225 ci
= (MDICLIENTINFO
*)wndPtr
->wExtra
;
1227 if( !(wndPtr
->parent
->dwStyle
& WS_MINIMIZE
)
1228 && ci
->hwndActiveChild
&& !ci
->hwndChildMaximized
)
1230 /* control menu is between the frame system menu and
1231 * the first entry of menu bar */
1233 if( wParam
== VK_LEFT
)
1234 { if( wndPtr
->parent
->wIDmenu
!= LOWORD(lParam
) ) break; }
1235 else if( wParam
== VK_RIGHT
)
1236 { if( GetSystemMenu( wndPtr
->parent
->hwndSelf
, 0)
1237 != LOWORD(lParam
) ) break; }
1240 return MAKELONG( GetSystemMenu(ci
->hwndActiveChild
, 0),
1241 ci
->hwndActiveChild
);
1247 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1251 /***********************************************************************
1252 * DefFrameProc32A (USER32.121)
1254 LRESULT
DefFrameProc32A( HWND32 hwnd
, HWND32 hwndMDIClient
, UINT32 message
,
1255 WPARAM32 wParam
, LPARAM lParam
)
1262 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1264 MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ) );
1267 SendMessage32A(hwndMDIClient
, message
, wParam
, lParam
);
1271 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1272 wParam
, (LPARAM
)PTR_SEG_TO_LIN(lParam
) );
1276 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1281 return DefWindowProc32A(hwnd
, message
, wParam
, lParam
);
1285 /***********************************************************************
1286 * DefFrameProc32W (USER32.122)
1288 LRESULT
DefFrameProc32W( HWND32 hwnd
, HWND32 hwndMDIClient
, UINT32 message
,
1289 WPARAM32 wParam
, LPARAM lParam
)
1296 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1298 MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ) );
1301 SendMessage32W(hwndMDIClient
, message
, wParam
, lParam
);
1305 /* FIXME: Unicode */
1306 return DefFrameProc32A( hwnd
, hwndMDIClient
, message
,
1311 return DefFrameProc32A( hwnd
, hwndMDIClient
, message
,
1316 return DefWindowProc32W( hwnd
, message
, wParam
, lParam
);
1320 /***********************************************************************
1321 * DefMDIChildProc16 (USER.447)
1323 LRESULT
DefMDIChildProc16( HWND16 hwnd
, UINT16 message
,
1324 WPARAM16 wParam
, LPARAM lParam
)
1329 clientWnd
= WIN_FindWndPtr(GetParent16(hwnd
));
1330 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1335 DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1336 MDI_MenuModifyItem(clientWnd
,hwnd
);
1337 if( ci
->hwndChildMaximized
== hwnd
)
1338 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1339 MDI_REPAINTFRAME
, NULL
);
1343 SendMessage16(ci
->self
,WM_MDIDESTROY
,(WPARAM16
)hwnd
,0L);
1347 if( ci
->hwndActiveChild
!= hwnd
)
1348 MDI_ChildActivate(clientWnd
, hwnd
);
1351 case WM_CHILDACTIVATE
:
1352 MDI_ChildActivate(clientWnd
, hwnd
);
1356 dprintf_mdi(stddeb
,"DefMDIChildProc: WM_NCPAINT for %04x, active %04x\n",
1357 hwnd
, ci
->hwndActiveChild
);
1364 if( ci
->hwndChildMaximized
== hwnd
) return 0;
1368 WIN_FindWndPtr(hwnd
)->dwStyle
|= WS_SYSMENU
;
1371 if( ci
->hwndChildMaximized
== hwnd
)
1372 return SendMessage16( clientWnd
->parent
->hwndSelf
,
1373 message
, wParam
, lParam
);
1374 WIN_FindWndPtr(hwnd
)->dwStyle
&= ~WS_SYSMENU
;
1377 SendMessage16( ci
->self
, WM_MDINEXT
, 0, 0);
1380 SendMessage16( ci
->self
, WM_MDINEXT
, 0, 1);
1385 case WM_GETMINMAXINFO
:
1386 MDI_ChildGetMinMaxInfo(clientWnd
, hwnd
, (MINMAXINFO16
*) PTR_SEG_TO_LIN(lParam
));
1390 if( ci
->hwndChildMaximized
)
1391 ci
->sbNeedUpdate
= 0;
1393 MDI_PostUpdate(clientWnd
->hwndSelf
, ci
, SB_BOTH
+1);
1399 if( ci
->hwndActiveChild
== hwnd
&& wParam
!= SIZE_MAXIMIZED
)
1401 ci
->hwndChildMaximized
= 0;
1403 MDI_RestoreFrameMenu( clientWnd
->parent
, hwnd
);
1404 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1405 MDI_REPAINTFRAME
, NULL
);
1408 if( wParam
== SIZE_MAXIMIZED
)
1410 HWND hMaxChild
= ci
->hwndChildMaximized
;
1412 if( hMaxChild
== hwnd
) break;
1416 SendMessage16( hMaxChild
, WM_SETREDRAW
, FALSE
, 0L );
1418 MDI_RestoreFrameMenu( clientWnd
->parent
, hMaxChild
);
1419 ShowWindow( hMaxChild
, SW_SHOWNOACTIVATE
);
1421 SendMessage16( hMaxChild
, WM_SETREDRAW
, TRUE
, 0L );
1424 dprintf_mdi(stddeb
,"\tMDI: maximizing child %04x\n", hwnd
);
1426 ci
->hwndChildMaximized
= hwnd
; /* !!! */
1428 MDI_AugmentFrameMenu( ci
, clientWnd
->parent
, hwnd
);
1429 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1430 MDI_REPAINTFRAME
, NULL
);
1433 if( wParam
== SIZE_MINIMIZED
)
1435 HWND switchTo
= MDI_GetWindow(clientWnd
, hwnd
, 0);
1438 SendMessage16( switchTo
, WM_CHILDACTIVATE
, 0, 0L);
1441 MDI_PostUpdate(clientWnd
->hwndSelf
, ci
, SB_BOTH
+1);
1446 /* MDI children don't have menu bars */
1447 PostMessage( clientWnd
->parent
->hwndSelf
, WM_SYSCOMMAND
,
1448 (WPARAM16
)SC_KEYMENU
, (LPARAM
)wParam
);
1453 if( wParam
== VK_LEFT
) /* switch to frame system menu */
1454 return MAKELONG( GetSystemMenu(clientWnd
->parent
->hwndSelf
, 0),
1455 clientWnd
->parent
->hwndSelf
);
1456 if( wParam
== VK_RIGHT
) /* to frame menu bar */
1457 return MAKELONG( clientWnd
->parent
->wIDmenu
,
1458 clientWnd
->parent
->hwndSelf
);
1463 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1467 /***********************************************************************
1468 * DefMDIChildProc32A (USER32.123)
1470 LRESULT
DefMDIChildProc32A( HWND32 hwnd
, UINT32 message
,
1471 WPARAM32 wParam
, LPARAM lParam
)
1476 clientWnd
= WIN_FindWndPtr(GetParent16(hwnd
));
1477 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1482 DefWindowProc32A(hwnd
, message
, wParam
, lParam
);
1483 MDI_MenuModifyItem(clientWnd
,hwnd
);
1484 if( ci
->hwndChildMaximized
== hwnd
)
1485 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1486 MDI_REPAINTFRAME
, NULL
);
1489 case WM_GETMINMAXINFO
:
1492 STRUCT32_MINMAXINFO32to16( (MINMAXINFO32
*)lParam
, &mmi
);
1493 MDI_ChildGetMinMaxInfo( clientWnd
, hwnd
, &mmi
);
1494 STRUCT32_MINMAXINFO16to32( &mmi
, (MINMAXINFO32
*)lParam
);
1500 /* MDI children don't have menu bars */
1501 PostMessage( clientWnd
->parent
->hwndSelf
, WM_SYSCOMMAND
,
1502 (WPARAM16
)SC_KEYMENU
, (LPARAM
)LOWORD(wParam
) );
1507 case WM_CHILDACTIVATE
:
1513 return DefMDIChildProc16( hwnd
, message
, (WPARAM16
)wParam
, lParam
);
1515 return DefWindowProc32A(hwnd
, message
, wParam
, lParam
);
1519 /***********************************************************************
1520 * DefMDIChildProc32W (USER32.124)
1522 LRESULT
DefMDIChildProc32W( HWND32 hwnd
, UINT32 message
,
1523 WPARAM32 wParam
, LPARAM lParam
)
1528 clientWnd
= WIN_FindWndPtr(GetParent16(hwnd
));
1529 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1534 DefWindowProc32W(hwnd
, message
, wParam
, lParam
);
1535 MDI_MenuModifyItem(clientWnd
,hwnd
);
1536 if( ci
->hwndChildMaximized
== hwnd
)
1537 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1538 MDI_REPAINTFRAME
, NULL
);
1541 case WM_GETMINMAXINFO
:
1545 case WM_CHILDACTIVATE
:
1551 return DefMDIChildProc32A( hwnd
, message
, (WPARAM16
)wParam
, lParam
);
1553 return DefWindowProc32W(hwnd
, message
, wParam
, lParam
);
1557 /**********************************************************************
1558 * TranslateMDISysAccel (USER.451)
1561 BOOL
TranslateMDISysAccel(HWND hwndClient
, LPMSG16 msg
)
1563 WND
* clientWnd
= WIN_FindWndPtr( hwndClient
);
1565 MDICLIENTINFO
*ci
= NULL
;
1566 WPARAM16 wParam
= 0;
1568 if( (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) || !clientWnd
)
1571 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1572 wnd
= WIN_FindWndPtr(ci
->hwndActiveChild
);
1574 if( !wnd
) return 0;
1576 if( wnd
->dwStyle
& WS_DISABLED
) return 0;
1578 if ((GetKeyState(VK_CONTROL
) & 0x8000) && !(GetKeyState(VK_MENU
) & 0x8000))
1579 switch( msg
->wParam
)
1583 wParam
= ( GetKeyState(VK_SHIFT
) & 0x8000 )? SC_NEXTWINDOW
: SC_PREVWINDOW
;
1594 dprintf_mdi(stddeb
,"TranslateMDISysAccel: wParam = %04x\n", wParam
);
1596 SendMessage16(ci
->hwndActiveChild
,WM_SYSCOMMAND
, wParam
, (LPARAM
)msg
->wParam
);
1601 /***********************************************************************
1602 * CalcChildScroll (USER.462)
1604 void CalcChildScroll( HWND hwnd
, WORD scroll
)
1606 RECT16 childRect
, clientRect
;
1607 INT vmin
, vmax
, hmin
, hmax
, vpos
, hpos
;
1608 BOOL noscroll
= FALSE
;
1611 if (!(Wnd
= pWnd
= WIN_FindWndPtr( hwnd
))) return;
1612 GetClientRect16( hwnd
, &clientRect
);
1613 SetRectEmpty16( &childRect
);
1615 for ( pWnd
= pWnd
->child
; pWnd
; pWnd
= pWnd
->next
)
1617 UnionRect16( &childRect
, &pWnd
->rectWindow
, &childRect
);
1618 if( pWnd
->dwStyle
& WS_MAXIMIZE
)
1621 UnionRect16( &childRect
, &clientRect
, &childRect
);
1623 /* jump through the hoops to prevent excessive flashing
1626 hmin
= childRect
.left
; hmax
= childRect
.right
- clientRect
.right
;
1627 hpos
= clientRect
.left
- childRect
.left
;
1628 vmin
= childRect
.top
; vmax
= childRect
.bottom
- clientRect
.bottom
;
1629 vpos
= clientRect
.top
- childRect
.top
;
1632 ShowScrollBar32(hwnd
, SB_BOTH
, FALSE
);
1637 vpos
= hpos
; vmin
= hmin
; vmax
= hmax
;
1639 SetScrollPos32(hwnd
, scroll
, vpos
, FALSE
);
1640 SetScrollRange32(hwnd
, scroll
, vmin
, vmax
, TRUE
);
1643 SCROLL_SetNCSbState( Wnd
, vmin
, vmax
, vpos
,
1645 SetWindowPos(hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
1646 | SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
1650 /***********************************************************************
1651 * ScrollChildren (USER.463)
1653 void ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM16 wParam
, LPARAM lParam
)
1655 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
1663 if( !wndPtr
) return;
1665 if( uMsg
== WM_HSCROLL
)
1667 GetScrollRange32(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
1668 curPos
= GetScrollPos32(hWnd
,SB_HORZ
);
1669 length
= (wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
)/2;
1670 shift
= SYSMETRICS_CYHSCROLL
;
1672 else if( uMsg
== WM_VSCROLL
)
1674 GetScrollRange32(hWnd
,SB_VERT
,&minPos
,&maxPos
);
1675 curPos
= GetScrollPos32(hWnd
,SB_VERT
);
1676 length
= (wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
)/2;
1677 shift
= SYSMETRICS_CXVSCROLL
;
1684 newPos
= curPos
- shift
;
1687 newPos
= curPos
+ shift
;
1690 newPos
= curPos
- length
;
1693 newPos
= curPos
+ length
;
1696 case SB_THUMBPOSITION
:
1697 newPos
= LOWORD(lParam
);
1710 CalcChildScroll(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
1714 if( newPos
> maxPos
)
1716 else if( newPos
< minPos
)
1719 SetScrollPos32(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
1721 if( uMsg
== WM_VSCROLL
)
1722 ScrollWindow32(hWnd
,0 ,curPos
- newPos
, NULL
, NULL
);
1724 ScrollWindow32(hWnd
,curPos
- newPos
, 0, NULL
, NULL
);