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
= GetMenuState32(clientInfo
->hWindowMenu
,wndPtr
->wIDmenu
,MF_BYCOMMAND
);
105 bRet
= ModifyMenu32A(clientInfo
->hWindowMenu
, wndPtr
->wIDmenu
,
106 MF_BYCOMMAND
| MF_STRING
, wndPtr
->wIDmenu
, buffer
);
107 CheckMenuItem32(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 DeleteMenu32(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 HMENU32 oldFrameMenu
= GetMenu32(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 INT32 i
= GetMenuItemCount32(ci
->hWindowMenu
) - 1;
240 INT32 pos
= GetMenuItemCount32(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
= GetMenuItemID32(ci
->hWindowMenu
,i
);
253 state
= GetMenuState32(ci
->hWindowMenu
,i
,MF_BYPOSITION
);
255 GetMenuString32A(ci
->hWindowMenu
, i
, buffer
, 100, MF_BYPOSITION
);
257 DeleteMenu32(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
258 InsertMenu32A(hmenuWindow
, pos
, MF_BYPOSITION
| MF_STRING
,
260 CheckMenuItem32(hmenuWindow
,pos
, MF_BYPOSITION
| (state
& MF_CHECKED
));
264 /* remove separator */
265 DeleteMenu32(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
267 ci
->hWindowMenu
= hmenuWindow
;
270 if( hmenuFrame
&& hmenuFrame
!=oldFrameMenu
)
272 SetMenu32(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 DeleteMenu32(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 CheckMenuItem32( 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 CheckMenuItem32( 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
);
841 HMENU16 hSysPopup
= 0;
843 dprintf_mdi(stddeb
,"MDI_AugmentFrameMenu: frame %p,child %04x\n",frame
,hChild
);
845 if( !frame
->wIDmenu
|| !child
->hSysMenu
) return 0;
847 /* create a copy of sysmenu popup and insert it into frame menu bar */
849 if (!(hSysPopup
= LoadMenuIndirect32A(SYSRES_GetResPtr(SYSRES_MENU_SYSMENU
))))
852 dprintf_mdi(stddeb
,"\t\tgot popup %04x\n in sysmenu %04x",hSysPopup
,child
->hSysMenu
);
854 if( !InsertMenu32A(frame
->wIDmenu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
855 hSysPopup
, (LPSTR
)(DWORD
)hBmpClose
))
856 { DestroyMenu32(hSysPopup
); return 0; }
858 if( !AppendMenu32A(frame
->wIDmenu
,MF_HELP
| MF_BITMAP
,
859 SC_RESTORE
, (LPSTR
)(DWORD
)hBmpRestore
))
861 RemoveMenu32(frame
->wIDmenu
,0,MF_BYPOSITION
);
865 EnableMenuItem32(hSysPopup
, SC_SIZE
, MF_BYCOMMAND
| MF_GRAYED
);
866 EnableMenuItem32(hSysPopup
, SC_MOVE
, MF_BYCOMMAND
| MF_GRAYED
);
867 EnableMenuItem32(hSysPopup
, SC_MAXIMIZE
, MF_BYCOMMAND
| MF_GRAYED
);
870 DrawMenuBar32(frame
->hwndSelf
);
875 /**********************************************************************
876 * MDI_RestoreFrameMenu
878 BOOL
MDI_RestoreFrameMenu( WND
*frameWnd
, HWND hChild
)
880 INT32 nItems
= GetMenuItemCount32(frameWnd
->wIDmenu
) - 1;
882 dprintf_mdi(stddeb
,"MDI_RestoreFrameMenu: for child %04x\n",hChild
);
884 if( GetMenuItemID32(frameWnd
->wIDmenu
,nItems
) != SC_RESTORE
)
888 RemoveMenu32(frameWnd
->wIDmenu
,0,MF_BYPOSITION
);
889 DeleteMenu32(frameWnd
->wIDmenu
,nItems
-1,MF_BYPOSITION
);
891 DrawMenuBar32(frameWnd
->hwndSelf
);
896 /**********************************************************************
897 * MDI_UpdateFrameText
899 * used when child window is maximized/restored
901 * Note: lpTitle can be NULL
903 void MDI_UpdateFrameText(WND
*frameWnd
, HWND hClient
, BOOL repaint
, LPCSTR lpTitle
)
905 char lpBuffer
[MDI_MAXTITLELENGTH
+1];
906 WND
* clientWnd
= WIN_FindWndPtr(hClient
);
908 MDICLIENTINFO
*ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
910 dprintf_mdi(stddeb
, "MDI: repaint %i, frameText %s\n", repaint
, (lpTitle
)?lpTitle
:"NULL");
912 /* store new "default" title if lpTitle is not NULL */
915 if (ci
->frameTitle
) HeapFree( SystemHeap
, 0, ci
->frameTitle
);
916 ci
->frameTitle
= HEAP_strdupA( SystemHeap
, 0, lpTitle
);
921 WND
* childWnd
= WIN_FindWndPtr( ci
->hwndChildMaximized
);
923 if( childWnd
&& childWnd
->text
)
925 /* combine frame title and child title if possible */
927 LPCSTR lpBracket
= " - [";
928 int i_frame_text_length
= strlen(ci
->frameTitle
);
929 int i_child_text_length
= strlen(childWnd
->text
);
931 lstrcpyn32A( lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
933 if( i_frame_text_length
+ 6 < MDI_MAXTITLELENGTH
)
935 strcat( lpBuffer
, lpBracket
);
937 if( i_frame_text_length
+ i_child_text_length
+ 6 < MDI_MAXTITLELENGTH
)
939 strcat( lpBuffer
, childWnd
->text
);
940 strcat( lpBuffer
, "]" );
944 lstrcpyn32A( lpBuffer
+ i_frame_text_length
+ 4,
946 MDI_MAXTITLELENGTH
- i_frame_text_length
- 5 );
947 strcat( lpBuffer
, "]" );
953 strncpy(lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
954 lpBuffer
[MDI_MAXTITLELENGTH
]='\0';
960 DEFWND_SetText( frameWnd
, lpBuffer
);
961 if( repaint
== MDI_REPAINTFRAME
)
962 SetWindowPos(frameWnd
->hwndSelf
, 0,0,0,0,0, SWP_FRAMECHANGED
|
963 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
967 /* ----------------------------- Interface ---------------------------- */
970 /**********************************************************************
973 * This function is the handler for all MDI requests.
975 LRESULT
MDIClientWndProc(HWND hwnd
, UINT message
, WPARAM16 wParam
, LPARAM lParam
)
978 LPCLIENTCREATESTRUCT16 ccs
;
981 WND
*w
= WIN_FindWndPtr(hwnd
);
982 WND
*frameWnd
= w
->parent
;
985 ci
= (MDICLIENTINFO
*) w
->wExtra
;
990 cs
= (LPCREATESTRUCT16
) PTR_SEG_TO_LIN(lParam
);
991 ccs
= (LPCLIENTCREATESTRUCT16
) PTR_SEG_TO_LIN(cs
->lpCreateParams
);
993 ci
->hWindowMenu
= ccs
->hWindowMenu
;
994 ci
->idFirstChild
= ccs
->idFirstChild
;
995 ci
->hwndChildMaximized
= 0;
996 ci
->nActiveChildren
= 0;
997 ci
->nTotalCreated
= 0;
998 ci
->frameTitle
= NULL
;
999 ci
->sbNeedUpdate
= 0;
1001 w
->dwStyle
|= WS_CLIPCHILDREN
;
1005 hBmpClose
= CreateMDIMenuBitmap();
1006 hBmpRestore
= LoadBitmap16( 0, MAKEINTRESOURCE(OBM_RESTORE
) );
1008 MDI_UpdateFrameText(frameWnd
, hwnd
, MDI_NOFRAMEREPAINT
,frameWnd
->text
);
1010 AppendMenu32A( ccs
->hWindowMenu
, MF_SEPARATOR
, 0, NULL
);
1012 GetClientRect16(frameWnd
->hwndSelf
, &rect
);
1013 NC_HandleNCCalcSize( w
, &rect
);
1014 w
->rectClient
= rect
;
1016 dprintf_mdi(stddeb
,"MDI: Client created - hwnd = %04x, idFirst = %u\n",hwnd
,ci
->idFirstChild
);
1021 if( ci
->hwndChildMaximized
) MDI_RestoreFrameMenu(w
, frameWnd
->hwndSelf
);
1022 if((nItems
= GetMenuItemCount32(ci
->hWindowMenu
)) > 0) {
1023 ci
->idFirstChild
= nItems
- 1;
1024 ci
->nActiveChildren
++; /* to delete a separator */
1025 while( ci
->nActiveChildren
-- )
1026 DeleteMenu32(ci
->hWindowMenu
,MF_BYPOSITION
,ci
->idFirstChild
--);
1030 case WM_MDIACTIVATE
:
1031 if( ci
->hwndActiveChild
!= (HWND
)wParam
)
1032 SetWindowPos((HWND
)wParam
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1036 return MDICascade(w
, ci
);
1039 return (LONG
)MDICreateChild(w
, ci
, hwnd
, lParam
);
1042 return (LONG
)MDIDestroyChild(w
, ci
, hwnd
, (HWND
)wParam
, TRUE
);
1044 case WM_MDIGETACTIVE
:
1045 return ((LONG
) ci
->hwndActiveChild
|
1046 ((LONG
) (ci
->hwndChildMaximized
>0) << 16));
1048 case WM_MDIICONARRANGE
:
1049 ci
->sbNeedUpdate
= TRUE
;
1050 MDIIconArrange(hwnd
);
1051 ci
->sbRecalc
= SB_BOTH
+1;
1052 SendMessage16(hwnd
,WM_MDICALCCHILDSCROLL
,0,0L);
1055 case WM_MDIMAXIMIZE
:
1056 ShowWindow((HWND
)wParam
, SW_MAXIMIZE
);
1060 MDI_SwitchActiveChild(hwnd
, (HWND
)wParam
, (lParam
)?1:0);
1064 ShowWindow( (HWND
)wParam
, SW_NORMAL
);
1069 return (LRESULT
)MDISetMenu(hwnd
, FALSE
, (HMENU16
)wParam
, (HMENU16
)lParam
);
1071 return (LRESULT
)MDISetMenu(hwnd
, wParam
, LOWORD(lParam
), HIWORD(lParam
));
1075 ci
->sbNeedUpdate
= TRUE
;
1076 ShowScrollBar32(hwnd
,SB_BOTH
,FALSE
);
1077 MDITile(w
, ci
,wParam
);
1078 ci
->sbNeedUpdate
= FALSE
;
1083 ci
->sbNeedUpdate
= TRUE
;
1084 ScrollChildren(hwnd
,message
,wParam
,lParam
);
1085 ci
->sbNeedUpdate
= FALSE
;
1089 if( ci
->hwndActiveChild
)
1091 w
= WIN_FindWndPtr( ci
->hwndActiveChild
);
1092 if( !(w
->dwStyle
& WS_MINIMIZE
) )
1093 SetFocus32( ci
->hwndActiveChild
);
1098 if( ci
->hwndActiveChild
)
1099 SendMessage16(ci
->hwndActiveChild
, message
, wParam
, lParam
);
1102 case WM_PARENTNOTIFY
:
1103 if( wParam
== WM_LBUTTONDOWN
)
1105 POINT16 pt
= MAKEPOINT16(lParam
);
1106 HWND child
= ChildWindowFromPoint16(hwnd
, pt
);
1108 dprintf_mdi(stddeb
,"MDIClient: notification from %04x (%i,%i)\n",child
,pt
.x
,pt
.y
);
1110 if( child
&& child
!= hwnd
)
1112 WND
* wnd
= WIN_FindWndPtr( child
);
1114 /* if we got owned popup */
1115 if( wnd
->owner
) child
= wnd
->owner
->hwndSelf
;
1117 if( child
!= ci
->hwndActiveChild
)
1118 SetWindowPos(child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1124 if( ci
->hwndChildMaximized
)
1126 WND
* child
= WIN_FindWndPtr(ci
->hwndChildMaximized
);
1127 RECT16 rect
= { 0, 0, LOWORD(lParam
), HIWORD(lParam
) };
1129 AdjustWindowRectEx16(&rect
, child
->dwStyle
, 0, child
->dwExStyle
);
1130 MoveWindow(ci
->hwndChildMaximized
, rect
.left
, rect
.top
,
1131 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 1);
1134 MDI_PostUpdate(hwnd
, ci
, SB_BOTH
+1);
1138 case WM_MDICALCCHILDSCROLL
:
1139 if( ci
->sbNeedUpdate
)
1142 CalcChildScroll(hwnd
, ci
->sbRecalc
-1);
1143 ci
->sbRecalc
= ci
->sbNeedUpdate
= 0;
1148 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1152 /***********************************************************************
1153 * DefFrameProc16 (USER.445)
1155 LRESULT
DefFrameProc16( HWND16 hwnd
, HWND16 hwndMDIClient
, UINT16 message
,
1156 WPARAM16 wParam
, LPARAM lParam
)
1167 wndPtr
= WIN_FindWndPtr(hwndMDIClient
);
1168 ci
= (MDICLIENTINFO
*)wndPtr
->wExtra
;
1170 /* check for possible syscommands for maximized MDI child */
1172 if( wParam
< ci
->idFirstChild
||
1173 wParam
>= ci
->idFirstChild
+ ci
->nActiveChildren
)
1175 if( (wParam
- 0xF000) & 0xF00F ) break;
1186 if( ci
->hwndChildMaximized
)
1187 return SendMessage16( ci
->hwndChildMaximized
, WM_SYSCOMMAND
,
1193 childHwnd
= MDI_GetChildByID( WIN_FindWndPtr(hwndMDIClient
),
1196 SendMessage16(hwndMDIClient
, WM_MDIACTIVATE
,
1197 (WPARAM16
)childHwnd
, 0L);
1202 SendMessage16(hwndMDIClient
, message
, wParam
, lParam
);
1206 MDI_UpdateFrameText(WIN_FindWndPtr(hwnd
), hwndMDIClient
,
1208 (LPCSTR
)PTR_SEG_TO_LIN(lParam
));
1212 SetFocus32(hwndMDIClient
);
1216 MoveWindow(hwndMDIClient
, 0, 0,
1217 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1222 wndPtr
= WIN_FindWndPtr(hwndMDIClient
);
1223 ci
= (MDICLIENTINFO
*)wndPtr
->wExtra
;
1225 if( !(wndPtr
->parent
->dwStyle
& WS_MINIMIZE
)
1226 && ci
->hwndActiveChild
&& !ci
->hwndChildMaximized
)
1228 /* control menu is between the frame system menu and
1229 * the first entry of menu bar */
1231 if( wParam
== VK_LEFT
)
1232 { if( wndPtr
->parent
->wIDmenu
!= LOWORD(lParam
) ) break; }
1233 else if( wParam
== VK_RIGHT
)
1234 { if( GetSystemMenu16( wndPtr
->parent
->hwndSelf
, 0)
1235 != LOWORD(lParam
) ) break; }
1238 return MAKELONG( GetSystemMenu16(ci
->hwndActiveChild
, 0),
1239 ci
->hwndActiveChild
);
1245 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1249 /***********************************************************************
1250 * DefFrameProc32A (USER32.121)
1252 LRESULT
DefFrameProc32A( HWND32 hwnd
, HWND32 hwndMDIClient
, UINT32 message
,
1253 WPARAM32 wParam
, LPARAM lParam
)
1260 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1262 MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ) );
1265 SendMessage32A(hwndMDIClient
, message
, wParam
, lParam
);
1269 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1270 wParam
, (LPARAM
)PTR_SEG_TO_LIN(lParam
) );
1274 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1279 return DefWindowProc32A(hwnd
, message
, wParam
, lParam
);
1283 /***********************************************************************
1284 * DefFrameProc32W (USER32.122)
1286 LRESULT
DefFrameProc32W( HWND32 hwnd
, HWND32 hwndMDIClient
, UINT32 message
,
1287 WPARAM32 wParam
, LPARAM lParam
)
1294 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1296 MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ) );
1299 SendMessage32W(hwndMDIClient
, message
, wParam
, lParam
);
1303 /* FIXME: Unicode */
1304 return DefFrameProc32A( hwnd
, hwndMDIClient
, message
,
1309 return DefFrameProc32A( hwnd
, hwndMDIClient
, message
,
1314 return DefWindowProc32W( hwnd
, message
, wParam
, lParam
);
1318 /***********************************************************************
1319 * DefMDIChildProc16 (USER.447)
1321 LRESULT
DefMDIChildProc16( HWND16 hwnd
, UINT16 message
,
1322 WPARAM16 wParam
, LPARAM lParam
)
1327 clientWnd
= WIN_FindWndPtr(GetParent16(hwnd
));
1328 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1333 DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1334 MDI_MenuModifyItem(clientWnd
,hwnd
);
1335 if( ci
->hwndChildMaximized
== hwnd
)
1336 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1337 MDI_REPAINTFRAME
, NULL
);
1341 SendMessage16(ci
->self
,WM_MDIDESTROY
,(WPARAM16
)hwnd
,0L);
1345 if( ci
->hwndActiveChild
!= hwnd
)
1346 MDI_ChildActivate(clientWnd
, hwnd
);
1349 case WM_CHILDACTIVATE
:
1350 MDI_ChildActivate(clientWnd
, hwnd
);
1354 dprintf_mdi(stddeb
,"DefMDIChildProc: WM_NCPAINT for %04x, active %04x\n",
1355 hwnd
, ci
->hwndActiveChild
);
1362 if( ci
->hwndChildMaximized
== hwnd
) return 0;
1366 WIN_FindWndPtr(hwnd
)->dwStyle
|= WS_SYSMENU
;
1369 if( ci
->hwndChildMaximized
== hwnd
)
1370 return SendMessage16( clientWnd
->parent
->hwndSelf
,
1371 message
, wParam
, lParam
);
1372 WIN_FindWndPtr(hwnd
)->dwStyle
&= ~WS_SYSMENU
;
1375 SendMessage16( ci
->self
, WM_MDINEXT
, 0, 0);
1378 SendMessage16( ci
->self
, WM_MDINEXT
, 0, 1);
1383 case WM_GETMINMAXINFO
:
1384 MDI_ChildGetMinMaxInfo(clientWnd
, hwnd
, (MINMAXINFO16
*) PTR_SEG_TO_LIN(lParam
));
1388 if( ci
->hwndChildMaximized
)
1389 ci
->sbNeedUpdate
= 0;
1391 MDI_PostUpdate(clientWnd
->hwndSelf
, ci
, SB_BOTH
+1);
1397 if( ci
->hwndActiveChild
== hwnd
&& wParam
!= SIZE_MAXIMIZED
)
1399 ci
->hwndChildMaximized
= 0;
1401 MDI_RestoreFrameMenu( clientWnd
->parent
, hwnd
);
1402 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1403 MDI_REPAINTFRAME
, NULL
);
1406 if( wParam
== SIZE_MAXIMIZED
)
1408 HWND hMaxChild
= ci
->hwndChildMaximized
;
1410 if( hMaxChild
== hwnd
) break;
1414 SendMessage16( hMaxChild
, WM_SETREDRAW
, FALSE
, 0L );
1416 MDI_RestoreFrameMenu( clientWnd
->parent
, hMaxChild
);
1417 ShowWindow( hMaxChild
, SW_SHOWNOACTIVATE
);
1419 SendMessage16( hMaxChild
, WM_SETREDRAW
, TRUE
, 0L );
1422 dprintf_mdi(stddeb
,"\tMDI: maximizing child %04x\n", hwnd
);
1424 ci
->hwndChildMaximized
= hwnd
; /* !!! */
1426 MDI_AugmentFrameMenu( ci
, clientWnd
->parent
, hwnd
);
1427 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1428 MDI_REPAINTFRAME
, NULL
);
1431 if( wParam
== SIZE_MINIMIZED
)
1433 HWND switchTo
= MDI_GetWindow(clientWnd
, hwnd
, 0);
1436 SendMessage16( switchTo
, WM_CHILDACTIVATE
, 0, 0L);
1439 MDI_PostUpdate(clientWnd
->hwndSelf
, ci
, SB_BOTH
+1);
1444 /* MDI children don't have menu bars */
1445 PostMessage( clientWnd
->parent
->hwndSelf
, WM_SYSCOMMAND
,
1446 (WPARAM16
)SC_KEYMENU
, (LPARAM
)wParam
);
1451 if( wParam
== VK_LEFT
) /* switch to frame system menu */
1452 return MAKELONG( GetSystemMenu16(clientWnd
->parent
->hwndSelf
, 0),
1453 clientWnd
->parent
->hwndSelf
);
1454 if( wParam
== VK_RIGHT
) /* to frame menu bar */
1455 return MAKELONG( clientWnd
->parent
->wIDmenu
,
1456 clientWnd
->parent
->hwndSelf
);
1461 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1465 /***********************************************************************
1466 * DefMDIChildProc32A (USER32.123)
1468 LRESULT
DefMDIChildProc32A( HWND32 hwnd
, UINT32 message
,
1469 WPARAM32 wParam
, LPARAM lParam
)
1474 clientWnd
= WIN_FindWndPtr(GetParent16(hwnd
));
1475 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1480 DefWindowProc32A(hwnd
, message
, wParam
, lParam
);
1481 MDI_MenuModifyItem(clientWnd
,hwnd
);
1482 if( ci
->hwndChildMaximized
== hwnd
)
1483 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1484 MDI_REPAINTFRAME
, NULL
);
1487 case WM_GETMINMAXINFO
:
1490 STRUCT32_MINMAXINFO32to16( (MINMAXINFO32
*)lParam
, &mmi
);
1491 MDI_ChildGetMinMaxInfo( clientWnd
, hwnd
, &mmi
);
1492 STRUCT32_MINMAXINFO16to32( &mmi
, (MINMAXINFO32
*)lParam
);
1498 /* MDI children don't have menu bars */
1499 PostMessage( clientWnd
->parent
->hwndSelf
, WM_SYSCOMMAND
,
1500 (WPARAM16
)SC_KEYMENU
, (LPARAM
)LOWORD(wParam
) );
1505 case WM_CHILDACTIVATE
:
1511 return DefMDIChildProc16( hwnd
, message
, (WPARAM16
)wParam
, lParam
);
1513 return DefWindowProc32A(hwnd
, message
, wParam
, lParam
);
1517 /***********************************************************************
1518 * DefMDIChildProc32W (USER32.124)
1520 LRESULT
DefMDIChildProc32W( HWND32 hwnd
, UINT32 message
,
1521 WPARAM32 wParam
, LPARAM lParam
)
1526 clientWnd
= WIN_FindWndPtr(GetParent16(hwnd
));
1527 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1532 DefWindowProc32W(hwnd
, message
, wParam
, lParam
);
1533 MDI_MenuModifyItem(clientWnd
,hwnd
);
1534 if( ci
->hwndChildMaximized
== hwnd
)
1535 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1536 MDI_REPAINTFRAME
, NULL
);
1539 case WM_GETMINMAXINFO
:
1543 case WM_CHILDACTIVATE
:
1549 return DefMDIChildProc32A( hwnd
, message
, (WPARAM16
)wParam
, lParam
);
1551 return DefWindowProc32W(hwnd
, message
, wParam
, lParam
);
1555 /**********************************************************************
1556 * TranslateMDISysAccel (USER.451)
1559 BOOL
TranslateMDISysAccel(HWND hwndClient
, LPMSG16 msg
)
1561 WND
* clientWnd
= WIN_FindWndPtr( hwndClient
);
1563 MDICLIENTINFO
*ci
= NULL
;
1564 WPARAM16 wParam
= 0;
1566 if( (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) || !clientWnd
)
1569 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1570 wnd
= WIN_FindWndPtr(ci
->hwndActiveChild
);
1572 if( !wnd
) return 0;
1574 if( wnd
->dwStyle
& WS_DISABLED
) return 0;
1576 if ((GetKeyState(VK_CONTROL
) & 0x8000) && !(GetKeyState(VK_MENU
) & 0x8000))
1577 switch( msg
->wParam
)
1581 wParam
= ( GetKeyState(VK_SHIFT
) & 0x8000 )? SC_NEXTWINDOW
: SC_PREVWINDOW
;
1592 dprintf_mdi(stddeb
,"TranslateMDISysAccel: wParam = %04x\n", wParam
);
1594 SendMessage16(ci
->hwndActiveChild
,WM_SYSCOMMAND
, wParam
, (LPARAM
)msg
->wParam
);
1599 /***********************************************************************
1600 * CalcChildScroll (USER.462)
1602 void CalcChildScroll( HWND hwnd
, WORD scroll
)
1604 RECT16 childRect
, clientRect
;
1605 INT vmin
, vmax
, hmin
, hmax
, vpos
, hpos
;
1606 BOOL noscroll
= FALSE
;
1609 if (!(Wnd
= pWnd
= WIN_FindWndPtr( hwnd
))) return;
1610 GetClientRect16( hwnd
, &clientRect
);
1611 SetRectEmpty16( &childRect
);
1613 for ( pWnd
= pWnd
->child
; pWnd
; pWnd
= pWnd
->next
)
1615 UnionRect16( &childRect
, &pWnd
->rectWindow
, &childRect
);
1616 if( pWnd
->dwStyle
& WS_MAXIMIZE
)
1619 UnionRect16( &childRect
, &clientRect
, &childRect
);
1621 /* jump through the hoops to prevent excessive flashing
1624 hmin
= childRect
.left
; hmax
= childRect
.right
- clientRect
.right
;
1625 hpos
= clientRect
.left
- childRect
.left
;
1626 vmin
= childRect
.top
; vmax
= childRect
.bottom
- clientRect
.bottom
;
1627 vpos
= clientRect
.top
- childRect
.top
;
1630 ShowScrollBar32(hwnd
, SB_BOTH
, FALSE
);
1635 vpos
= hpos
; vmin
= hmin
; vmax
= hmax
;
1637 SetScrollPos32(hwnd
, scroll
, vpos
, FALSE
);
1638 SetScrollRange32(hwnd
, scroll
, vmin
, vmax
, TRUE
);
1641 SCROLL_SetNCSbState( Wnd
, vmin
, vmax
, vpos
,
1643 SetWindowPos(hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
1644 | SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
1648 /***********************************************************************
1649 * ScrollChildren (USER.463)
1651 void ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM16 wParam
, LPARAM lParam
)
1653 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
1661 if( !wndPtr
) return;
1663 if( uMsg
== WM_HSCROLL
)
1665 GetScrollRange32(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
1666 curPos
= GetScrollPos32(hWnd
,SB_HORZ
);
1667 length
= (wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
)/2;
1668 shift
= SYSMETRICS_CYHSCROLL
;
1670 else if( uMsg
== WM_VSCROLL
)
1672 GetScrollRange32(hWnd
,SB_VERT
,&minPos
,&maxPos
);
1673 curPos
= GetScrollPos32(hWnd
,SB_VERT
);
1674 length
= (wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
)/2;
1675 shift
= SYSMETRICS_CXVSCROLL
;
1682 newPos
= curPos
- shift
;
1685 newPos
= curPos
+ shift
;
1688 newPos
= curPos
- length
;
1691 newPos
= curPos
+ length
;
1694 case SB_THUMBPOSITION
:
1695 newPos
= LOWORD(lParam
);
1708 CalcChildScroll(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
1712 if( newPos
> maxPos
)
1714 else if( newPos
< minPos
)
1717 SetScrollPos32(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
1719 if( uMsg
== WM_VSCROLL
)
1720 ScrollWindow32(hWnd
,0 ,curPos
- newPos
, NULL
, NULL
);
1722 ScrollWindow32(hWnd
,curPos
- newPos
, 0, NULL
, NULL
);