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 static void MDI_UpdateFrameText(WND
*, HWND16
, BOOL32
, LPCSTR
);
41 static BOOL32
MDI_AugmentFrameMenu(MDICLIENTINFO
*, WND
*, HWND16
);
42 static BOOL32
MDI_RestoreFrameMenu(WND
*, HWND16
);
44 static LONG
MDI_ChildActivate(WND
* ,HWND16
);
46 /* -------- Miscellaneous service functions ----------
51 static HWND16
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(HWND16 hwnd
, MDICLIENTINFO
* ci
, WORD recalc
)
60 if( !ci
->sbNeedUpdate
)
62 ci
->sbNeedUpdate
= TRUE
;
63 PostMessage16( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0);
65 ci
->sbRecalc
= recalc
;
68 /**********************************************************************
71 #ifdef SUPERFLUOUS_FUNCTIONS
72 static BOOL32
MDI_MenuAppendItem(WND
*clientWnd
, HWND16 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 BOOL32
MDI_MenuModifyItem(WND
* clientWnd
, HWND16 hWndChild
)
94 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
95 WND
*wndPtr
= WIN_FindWndPtr(hWndChild
);
96 UINT32 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 BOOL32
MDI_MenuDeleteItem(WND
* clientWnd
, HWND16 hWndChild
)
117 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
118 WND
*wndPtr
= WIN_FindWndPtr(hWndChild
);
119 UINT32 index
= 0,id
,n
;
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 static HWND16
MDI_GetWindow(WND
*clientWnd
, HWND16 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 static void MDI_CalcDefaultChildPos( WND
* w
, WORD n
, LPPOINT16 lpPos
,
200 RECT16 rect
= w
->rectClient
;
201 INT32 spacing
= GetSystemMetrics32(SM_CYCAPTION
) +
202 GetSystemMetrics32(SM_CYFRAME
) - 1;
205 if( rect
.bottom
- rect
.top
- delta
>= spacing
)
206 rect
.bottom
-= delta
;
208 nstagger
= (rect
.bottom
- rect
.top
)/(3*spacing
);
209 lpPos
[1].x
= (rect
.right
- rect
.left
- nstagger
*spacing
);
210 lpPos
[1].y
= (rect
.bottom
- rect
.top
- nstagger
*spacing
);
211 lpPos
[0].x
= lpPos
[0].y
= spacing
*(n
%(nstagger
+1));
214 /**********************************************************************
217 static HMENU16
MDISetMenu(HWND16 hwnd
, BOOL32 fRefresh
, HMENU16 hmenuFrame
,
220 WND
*w
= WIN_FindWndPtr(hwnd
);
223 dprintf_mdi(stddeb
, "WM_MDISETMENU: %04x %04x %04x %04x\n",
224 hwnd
, fRefresh
, hmenuFrame
, hmenuWindow
);
226 ci
= (MDICLIENTINFO
*) w
->wExtra
;
230 HWND16 hwndFrame
= GetParent16(hwnd
);
231 HMENU32 oldFrameMenu
= GetMenu32(hwndFrame
);
233 if( ci
->hwndChildMaximized
&& hmenuFrame
&& hmenuFrame
!=oldFrameMenu
)
234 MDI_RestoreFrameMenu(w
->parent
, ci
->hwndChildMaximized
);
236 if( hmenuWindow
&& hmenuWindow
!=ci
->hWindowMenu
)
238 /* delete menu items from ci->hWindowMenu
239 * and add them to hmenuWindow */
241 INT32 i
= GetMenuItemCount32(ci
->hWindowMenu
) - 1;
242 INT32 pos
= GetMenuItemCount32(hmenuWindow
) + 1;
244 AppendMenu32A( hmenuWindow
, MF_SEPARATOR
, 0, NULL
);
246 if( ci
->nActiveChildren
)
248 INT32 j
= i
- ci
->nActiveChildren
+ 1;
252 for( ; i
>= j
; i
-- )
254 id
= GetMenuItemID32(ci
->hWindowMenu
,i
);
255 state
= GetMenuState32(ci
->hWindowMenu
,i
,MF_BYPOSITION
);
257 GetMenuString32A(ci
->hWindowMenu
, i
, buffer
, 100, MF_BYPOSITION
);
259 DeleteMenu32(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
260 InsertMenu32A(hmenuWindow
, pos
, MF_BYPOSITION
| MF_STRING
,
262 CheckMenuItem32(hmenuWindow
,pos
, MF_BYPOSITION
| (state
& MF_CHECKED
));
266 /* remove separator */
267 DeleteMenu32(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
269 ci
->hWindowMenu
= hmenuWindow
;
272 if( hmenuFrame
&& hmenuFrame
!=oldFrameMenu
)
274 SetMenu32(hwndFrame
, hmenuFrame
);
275 if( ci
->hwndChildMaximized
)
276 MDI_AugmentFrameMenu(ci
, w
->parent
, ci
->hwndChildMaximized
);
284 /**********************************************************************
287 static WORD
MDIIconArrange(HWND16 parent
)
289 return ArrangeIconicWindows16(parent
); /* Any reason why the */
290 /* existing icon arrange */
291 /* can't be used here? */
296 /* ------------------ MDI child window functions ---------------------- */
299 /**********************************************************************
302 static HWND16
MDICreateChild( WND
*w
, MDICLIENTINFO
*ci
, HWND16 parent
,
303 LPMDICREATESTRUCT16 cs
, LPARAM lParam
)
306 DWORD style
= cs
->style
| (WS_CHILD
| WS_CLIPSIBLINGS
);
307 HWND16 hwnd
, hwndMax
= 0;
308 WORD wIDmenu
= ci
->idFirstChild
+ ci
->nActiveChildren
;
309 char lpstrDef
[]="junk!";
311 dprintf_mdi(stdnimp
,"MDICreateChild: origin %i,%i - dim %i,%i, style %08x\n",
312 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, (unsigned)cs
->style
);
313 /* calculate placement */
314 MDI_CalcDefaultChildPos(w
, ci
->nTotalCreated
++, pos
, 0);
316 if( cs
->cx
== CW_USEDEFAULT16
|| !cs
->cx
)
318 if( cs
->cy
== CW_USEDEFAULT16
|| !cs
->cy
)
321 if( cs
->x
== CW_USEDEFAULT16
)
327 /* restore current maximized child */
328 if( style
& WS_VISIBLE
&& ci
->hwndChildMaximized
)
330 if( style
& WS_MAXIMIZE
)
331 SendMessage16(w
->hwndSelf
, WM_SETREDRAW
, FALSE
, 0L );
332 hwndMax
= ci
->hwndChildMaximized
;
333 ShowWindow16( hwndMax
, SW_SHOWNOACTIVATE
);
334 if( style
& WS_MAXIMIZE
)
335 SendMessage16(w
->hwndSelf
, WM_SETREDRAW
, TRUE
, 0L );
338 /* this menu is needed to set a check mark in MDI_ChildActivate */
339 AppendMenu32A(ci
->hWindowMenu
,MF_STRING
,wIDmenu
, lpstrDef
);
341 ci
->nActiveChildren
++;
343 /* fix window style */
344 if( !(w
->dwStyle
& MDIS_ALLCHILDSTYLES
) )
346 style
&= (WS_CHILD
| WS_CLIPSIBLINGS
| WS_MINIMIZE
| WS_MAXIMIZE
|
347 WS_CLIPCHILDREN
| WS_DISABLED
| WS_VSCROLL
| WS_HSCROLL
);
348 style
|= (WS_VISIBLE
| WS_OVERLAPPEDWINDOW
);
351 hwnd
= CreateWindow16( (LPCSTR
)PTR_SEG_TO_LIN(cs
->szClass
),
352 (LPCSTR
)PTR_SEG_TO_LIN(cs
->szTitle
), style
,
353 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, parent
,
354 (HMENU16
)wIDmenu
, w
->hInstance
,
357 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
361 WND
* wnd
= WIN_FindWndPtr( hwnd
);
363 MDI_MenuModifyItem(w
,hwnd
);
364 if( wnd
->dwStyle
& WS_MINIMIZE
&& ci
->hwndActiveChild
)
365 ShowWindow16( hwnd
, SW_SHOWMINNOACTIVE
);
368 SetWindowPos32( hwnd
, 0, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
);
370 /* Set maximized state here in case hwnd didn't receive WM_SIZE
371 * during CreateWindow - bad!
374 if( wnd
->dwStyle
& WS_MAXIMIZE
&& !ci
->hwndChildMaximized
)
376 ci
->hwndChildMaximized
= wnd
->hwndSelf
;
377 MDI_AugmentFrameMenu( ci
, w
->parent
, hwnd
);
378 MDI_UpdateFrameText( w
->parent
, ci
->self
, MDI_REPAINTFRAME
, NULL
);
381 dprintf_mdi(stddeb
, "MDICreateChild: created child - %04x\n",hwnd
);
385 ci
->nActiveChildren
--;
386 DeleteMenu32(ci
->hWindowMenu
,wIDmenu
,MF_BYCOMMAND
);
387 if( IsWindow32(hwndMax
) )
388 ShowWindow32(hwndMax
, SW_SHOWMAXIMIZED
);
394 /**********************************************************************
395 * MDI_ChildGetMinMaxInfo
397 static void MDI_ChildGetMinMaxInfo( WND
* clientWnd
, HWND16 hwnd
,
398 MINMAXINFO16
* lpMinMax
)
400 WND
* childWnd
= WIN_FindWndPtr(hwnd
);
401 RECT16 rect
= clientWnd
->rectClient
;
403 MapWindowPoints16(clientWnd
->parent
->hwndSelf
,
404 ((MDICLIENTINFO
*)clientWnd
->wExtra
)->self
, (LPPOINT16
)&rect
, 2);
405 AdjustWindowRectEx16( &rect
, childWnd
->dwStyle
, 0, childWnd
->dwExStyle
);
407 lpMinMax
->ptMaxSize
.x
= rect
.right
-= rect
.left
;
408 lpMinMax
->ptMaxSize
.y
= rect
.bottom
-= rect
.top
;
410 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
411 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
413 dprintf_mdi(stddeb
,"\tChildMinMaxInfo: max rect (%i,%i - %i, %i)\n",
414 rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
418 /**********************************************************************
419 * MDI_SwitchActiveChild
421 * Notes: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
424 * wTo is basically lParam of WM_MDINEXT message or explicit
427 static void MDI_SwitchActiveChild( HWND16 clientHwnd
, HWND16 childHwnd
,
430 WND
*w
= WIN_FindWndPtr(clientHwnd
);
435 hwndTo
= MDI_GetWindow(w
,childHwnd
,(WORD
)wTo
);
437 ci
= (MDICLIENTINFO
*) w
->wExtra
;
439 dprintf_mdi(stddeb
, "MDI_SwitchActiveChild: from %04x, to %04x\n",childHwnd
,hwndTo
);
441 if ( !hwndTo
) return;
443 hwndPrev
= ci
->hwndActiveChild
;
445 if ( hwndTo
!= hwndPrev
)
447 BOOL32 bOptimize
= 0;
449 if( ci
->hwndChildMaximized
)
452 w
->dwStyle
&= ~WS_VISIBLE
;
455 SetWindowPos32( hwndTo
, HWND_TOP
, 0, 0, 0, 0,
456 SWP_NOMOVE
| SWP_NOSIZE
);
457 if( !wTo
&& hwndPrev
)
459 SetWindowPos32( hwndPrev
, HWND_BOTTOM
, 0, 0, 0, 0,
460 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
464 ShowWindow16( clientHwnd
, SW_SHOW
);
469 /**********************************************************************
472 static HWND16
MDIDestroyChild( WND
*w_parent
, MDICLIENTINFO
*ci
, HWND16 parent
,
473 HWND16 child
, BOOL32 flagDestroy
)
475 WND
*childPtr
= WIN_FindWndPtr(child
);
479 if( child
== ci
->hwndActiveChild
)
481 MDI_SwitchActiveChild(parent
,child
,0);
483 if( child
== ci
->hwndActiveChild
)
485 ShowWindow16( child
, SW_HIDE
);
486 if( child
== ci
->hwndChildMaximized
)
488 MDI_RestoreFrameMenu(w_parent
->parent
, child
);
489 ci
->hwndChildMaximized
= 0;
490 MDI_UpdateFrameText(w_parent
->parent
,parent
,TRUE
,NULL
);
493 MDI_ChildActivate(w_parent
,0);
495 MDI_MenuDeleteItem(w_parent
, child
);
498 ci
->nActiveChildren
--;
500 dprintf_mdi(stddeb
,"MDIDestroyChild: child destroyed - %04x\n",child
);
504 MDI_PostUpdate(GetParent16(child
), ci
, SB_BOTH
+1);
505 DestroyWindow32(child
);
513 /**********************************************************************
516 * Note: hWndChild is NULL when last child is being destroyed
518 static LONG
MDI_ChildActivate( WND
*clientPtr
, HWND16 hWndChild
)
520 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientPtr
->wExtra
;
521 HWND16 prevActiveWnd
= clientInfo
->hwndActiveChild
;
522 WND
*wndPtr
= WIN_FindWndPtr( hWndChild
);
523 WND
*wndPrev
= WIN_FindWndPtr( prevActiveWnd
);
524 BOOL32 isActiveFrameWnd
= 0;
526 if( hWndChild
== prevActiveWnd
) return 0L;
529 if( wndPtr
->dwStyle
& WS_DISABLED
) return 0L;
531 dprintf_mdi(stddeb
,"MDI_ChildActivate: %04x\n", hWndChild
);
533 if( GetActiveWindow32() == clientPtr
->parent
->hwndSelf
)
534 isActiveFrameWnd
= TRUE
;
536 /* deactivate prev. active child */
539 wndPrev
->dwStyle
|= WS_SYSMENU
;
540 SendMessage16( prevActiveWnd
, WM_NCACTIVATE
, FALSE
, 0L );
543 SendMessage32A( prevActiveWnd
, WM_MDIACTIVATE
, (WPARAM32
)prevActiveWnd
,
547 SendMessage16( prevActiveWnd
, WM_MDIACTIVATE
, FALSE
,
548 MAKELONG(hWndChild
,prevActiveWnd
));
550 /* uncheck menu item */
551 if( clientInfo
->hWindowMenu
)
552 CheckMenuItem32( clientInfo
->hWindowMenu
,
553 wndPrev
->wIDmenu
, 0);
557 if( clientInfo
->hwndChildMaximized
)
558 if( clientInfo
->hwndChildMaximized
!= hWndChild
)
561 clientInfo
->hwndActiveChild
= hWndChild
;
562 ShowWindow16( hWndChild
, SW_SHOWMAXIMIZED
);
565 ShowWindow16( clientInfo
->hwndActiveChild
,
568 clientInfo
->hwndActiveChild
= hWndChild
;
570 /* check if we have any children left */
573 if( isActiveFrameWnd
)
574 SetFocus32( clientInfo
->self
);
578 /* check menu item */
579 if( clientInfo
->hWindowMenu
)
580 CheckMenuItem32( clientInfo
->hWindowMenu
,
581 wndPtr
->wIDmenu
, MF_CHECKED
);
583 /* bring active child to the top */
584 SetWindowPos32( hWndChild
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
586 if( isActiveFrameWnd
)
588 SendMessage16( hWndChild
, WM_NCACTIVATE
, TRUE
, 0L);
589 if( GetFocus32() == clientInfo
->self
)
590 SendMessage16( clientInfo
->self
, WM_SETFOCUS
,
591 (WPARAM16
)clientInfo
->self
, 0L );
593 SetFocus32( clientInfo
->self
);
597 SendMessage32A( hWndChild
, WM_MDIACTIVATE
, (WPARAM32
)hWndChild
,
598 (LPARAM
)prevActiveWnd
);
600 SendMessage16( hWndChild
, WM_MDIACTIVATE
, TRUE
,
601 MAKELONG(hWndChild
,prevActiveWnd
));
607 /**********************************************************************
610 * iTotal returns number of children available for tiling or cascading
612 static MDIWCL
* MDI_BuildWCL(WND
* clientWnd
, INT16
* iTotal
)
614 MDIWCL
*listTop
,*listNext
;
617 if (!(listTop
= (MDIWCL
*)malloc( sizeof(MDIWCL
) ))) return NULL
;
619 listTop
->hChild
= clientWnd
->child
? clientWnd
->child
->hwndSelf
: 0;
620 listTop
->prev
= NULL
;
623 /* build linked list from top child to bottom */
625 childWnd
= WIN_FindWndPtr( listTop
->hChild
);
626 while( childWnd
&& childWnd
->next
)
628 listNext
= (MDIWCL
*)xmalloc(sizeof(MDIWCL
));
630 /* FIXME: pay attention to MDITILE_SKIPDISABLED
631 * when WIN_ISWIN32 is set.
633 if( (childWnd
->dwStyle
& WS_DISABLED
) ||
634 (childWnd
->dwStyle
& WS_MINIMIZE
) ||
635 !(childWnd
->dwStyle
& WS_VISIBLE
) )
641 listNext
->hChild
= childWnd
->next
->hwndSelf
;
642 listNext
->prev
= listTop
;
646 childWnd
= childWnd
->next
;
649 if( (childWnd
->dwStyle
& WS_DISABLED
) ||
650 (childWnd
->dwStyle
& WS_MINIMIZE
) ||
651 !(childWnd
->dwStyle
& WS_VISIBLE
) )
661 /* -------------------- MDI client window functions ------------------- */
663 /**********************************************************************
664 * CreateMDIMenuBitmap
666 static HBITMAP16
CreateMDIMenuBitmap(void)
668 HDC32 hDCSrc
= CreateCompatibleDC32(0);
669 HDC32 hDCDest
= CreateCompatibleDC32(hDCSrc
);
670 HBITMAP16 hbClose
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_CLOSE
) );
671 HBITMAP16 hbCopy
,hb_src
,hb_dest
;
673 hb_src
= SelectObject32(hDCSrc
,hbClose
);
674 hbCopy
= CreateCompatibleBitmap32(hDCSrc
,SYSMETRICS_CXSIZE
,SYSMETRICS_CYSIZE
);
675 hb_dest
= SelectObject32(hDCDest
,hbCopy
);
677 BitBlt32(hDCDest
, 0, 0, SYSMETRICS_CXSIZE
, SYSMETRICS_CYSIZE
,
678 hDCSrc
, SYSMETRICS_CXSIZE
, 0, SRCCOPY
);
680 SelectObject32(hDCSrc
,hb_src
);
681 SelectObject32(hDCDest
,hb_dest
);
683 DeleteObject32(hbClose
);
691 /**********************************************************************
694 static LONG
MDICascade(WND
* clientWnd
, MDICLIENTINFO
*ci
)
696 MDIWCL
*listTop
,*listPrev
;
697 INT16 delta
= 0,iToPosition
= 0, n
= 0;
700 if (ci
->hwndChildMaximized
)
701 ShowWindow16( ci
->hwndChildMaximized
, SW_NORMAL
);
703 if (ci
->nActiveChildren
== 0) return 0;
705 if (!(listTop
= MDI_BuildWCL(clientWnd
,&iToPosition
))) return 0;
707 if( iToPosition
< ci
->nActiveChildren
)
708 delta
= 2 * SYSMETRICS_CYICONSPACING
+ SYSMETRICS_CYICON
;
710 /* walk list and move windows */
713 dprintf_mdi(stddeb
, "MDICascade: move %04x to (%d,%d) size [%d,%d]\n",
714 listTop
->hChild
, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
);
716 if( listTop
->hChild
)
718 MDI_CalcDefaultChildPos(clientWnd
, n
++, pos
, delta
);
719 SetWindowPos32(listTop
->hChild
, 0, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
,
720 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
723 listPrev
= listTop
->prev
;
728 if( iToPosition
< ci
->nActiveChildren
)
729 ArrangeIconicWindows32( clientWnd
->hwndSelf
);
734 /**********************************************************************
738 static LONG
MDITile(WND
* wndClient
, MDICLIENTINFO
*ci
,WORD wParam
)
740 MDIWCL
*listTop
,*listPrev
;
747 INT16 iToPosition
= 0;
749 if (ci
->hwndChildMaximized
)
750 ShowWindow16(ci
->hwndChildMaximized
, SW_NORMAL
);
752 if (ci
->nActiveChildren
== 0) return 0;
754 listTop
= MDI_BuildWCL(wndClient
, &iToPosition
);
756 dprintf_mdi(stddeb
,"MDITile: %i windows to tile\n",iToPosition
);
758 if( !listTop
) return 0;
763 rect
= wndClient
->rectClient
;
764 rows
= (int) sqrt((double) iToPosition
);
765 columns
= iToPosition
/ rows
;
767 if (wParam
== MDITILE_HORIZONTAL
) /* version >= 3.1 */
770 rows
=columns
; /* exchange r and c */
775 if( iToPosition
!= ci
->nActiveChildren
)
777 y
= rect
.bottom
- 2 * SYSMETRICS_CYICONSPACING
- SYSMETRICS_CYICON
;
778 rect
.bottom
= ( y
- SYSMETRICS_CYICON
< rect
.top
)? rect
.bottom
: y
;
781 ysize
= rect
.bottom
/ rows
;
782 xsize
= rect
.right
/ columns
;
787 for (c
= 1; c
<= columns
; c
++)
791 rows
= iToPosition
- i
;
792 ysize
= rect
.bottom
/ rows
;
796 for (r
= 1; r
<= rows
; r
++, i
++)
798 /* shouldn't happen but... */
802 /* skip iconized childs from tiling */
803 while (!listTop
->hChild
)
805 listPrev
= listTop
->prev
;
809 SetWindowPos32(listTop
->hChild
, 0, x
, y
, xsize
, ysize
,
810 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
812 listPrev
= listTop
->prev
;
820 /* free the rest if any */
823 listPrev
= listTop
->prev
;
828 if (iToPosition
< ci
->nActiveChildren
)
829 ArrangeIconicWindows32( wndClient
->hwndSelf
);
834 /* ----------------------- Frame window ---------------------------- */
837 /**********************************************************************
838 * MDI_AugmentFrameMenu
840 static BOOL32
MDI_AugmentFrameMenu( MDICLIENTINFO
* ci
, WND
*frame
,
843 WND
* child
= WIN_FindWndPtr(hChild
);
844 HMENU16 hSysPopup
= 0;
846 dprintf_mdi(stddeb
,"MDI_AugmentFrameMenu: frame %p,child %04x\n",frame
,hChild
);
848 if( !frame
->wIDmenu
|| !child
->hSysMenu
) return 0;
850 /* create a copy of sysmenu popup and insert it into frame menu bar */
852 if (!(hSysPopup
= LoadMenuIndirect32A(SYSRES_GetResPtr(SYSRES_MENU_SYSMENU
))))
855 dprintf_mdi(stddeb
,"\t\tgot popup %04x\n in sysmenu %04x",hSysPopup
,child
->hSysMenu
);
857 if( !InsertMenu32A(frame
->wIDmenu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
858 hSysPopup
, (LPSTR
)(DWORD
)hBmpClose
))
859 { DestroyMenu32(hSysPopup
); return 0; }
861 if( !AppendMenu32A(frame
->wIDmenu
,MF_HELP
| MF_BITMAP
,
862 SC_RESTORE
, (LPSTR
)(DWORD
)hBmpRestore
))
864 RemoveMenu32(frame
->wIDmenu
,0,MF_BYPOSITION
);
868 EnableMenuItem32(hSysPopup
, SC_SIZE
, MF_BYCOMMAND
| MF_GRAYED
);
869 EnableMenuItem32(hSysPopup
, SC_MOVE
, MF_BYCOMMAND
| MF_GRAYED
);
870 EnableMenuItem32(hSysPopup
, SC_MAXIMIZE
, MF_BYCOMMAND
| MF_GRAYED
);
873 DrawMenuBar32(frame
->hwndSelf
);
878 /**********************************************************************
879 * MDI_RestoreFrameMenu
881 static BOOL32
MDI_RestoreFrameMenu( WND
*frameWnd
, HWND16 hChild
)
883 INT32 nItems
= GetMenuItemCount32(frameWnd
->wIDmenu
) - 1;
885 dprintf_mdi(stddeb
,"MDI_RestoreFrameMenu: for child %04x\n",hChild
);
887 if( GetMenuItemID32(frameWnd
->wIDmenu
,nItems
) != SC_RESTORE
)
891 RemoveMenu32(frameWnd
->wIDmenu
,0,MF_BYPOSITION
);
892 DeleteMenu32(frameWnd
->wIDmenu
,nItems
-1,MF_BYPOSITION
);
894 DrawMenuBar32(frameWnd
->hwndSelf
);
899 /**********************************************************************
900 * MDI_UpdateFrameText
902 * used when child window is maximized/restored
904 * Note: lpTitle can be NULL
906 static void MDI_UpdateFrameText( WND
*frameWnd
, HWND16 hClient
,
907 BOOL32 repaint
, LPCSTR lpTitle
)
909 char lpBuffer
[MDI_MAXTITLELENGTH
+1];
910 WND
* clientWnd
= WIN_FindWndPtr(hClient
);
912 MDICLIENTINFO
*ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
914 dprintf_mdi(stddeb
, "MDI: repaint %i, frameText %s\n", repaint
, (lpTitle
)?lpTitle
:"NULL");
916 /* store new "default" title if lpTitle is not NULL */
919 if (ci
->frameTitle
) HeapFree( SystemHeap
, 0, ci
->frameTitle
);
920 ci
->frameTitle
= HEAP_strdupA( SystemHeap
, 0, lpTitle
);
925 WND
* childWnd
= WIN_FindWndPtr( ci
->hwndChildMaximized
);
927 if( childWnd
&& childWnd
->text
)
929 /* combine frame title and child title if possible */
931 LPCSTR lpBracket
= " - [";
932 int i_frame_text_length
= strlen(ci
->frameTitle
);
933 int i_child_text_length
= strlen(childWnd
->text
);
935 lstrcpyn32A( lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
937 if( i_frame_text_length
+ 6 < MDI_MAXTITLELENGTH
)
939 strcat( lpBuffer
, lpBracket
);
941 if( i_frame_text_length
+ i_child_text_length
+ 6 < MDI_MAXTITLELENGTH
)
943 strcat( lpBuffer
, childWnd
->text
);
944 strcat( lpBuffer
, "]" );
948 lstrcpyn32A( lpBuffer
+ i_frame_text_length
+ 4,
950 MDI_MAXTITLELENGTH
- i_frame_text_length
- 5 );
951 strcat( lpBuffer
, "]" );
957 strncpy(lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
958 lpBuffer
[MDI_MAXTITLELENGTH
]='\0';
964 DEFWND_SetText( frameWnd
, lpBuffer
);
965 if( repaint
== MDI_REPAINTFRAME
)
966 SetWindowPos32(frameWnd
->hwndSelf
, 0,0,0,0,0, SWP_FRAMECHANGED
|
967 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
971 /* ----------------------------- Interface ---------------------------- */
974 /**********************************************************************
977 * This function is the handler for all MDI requests.
979 LRESULT
MDIClientWndProc(HWND16 hwnd
, UINT16 message
, WPARAM16 wParam
, LPARAM lParam
)
982 LPCLIENTCREATESTRUCT16 ccs
;
985 WND
*w
= WIN_FindWndPtr(hwnd
);
986 WND
*frameWnd
= w
->parent
;
989 ci
= (MDICLIENTINFO
*) w
->wExtra
;
995 cs
= (LPCREATESTRUCT16
) PTR_SEG_TO_LIN(lParam
);
997 /* Translation layer doesn't know what's in the cs->lpCreateParams
998 * so we have to keep track of what environment we're in. */
1000 if( w
->flags
& WIN_ISWIN32
)
1001 ccs
= (LPCLIENTCREATESTRUCT16
) cs
->lpCreateParams
;
1003 ccs
= (LPCLIENTCREATESTRUCT16
) PTR_SEG_TO_LIN(cs
->lpCreateParams
);
1005 ci
->hWindowMenu
= ccs
->hWindowMenu
;
1006 ci
->idFirstChild
= ccs
->idFirstChild
;
1007 ci
->hwndChildMaximized
= 0;
1008 ci
->nActiveChildren
= 0;
1009 ci
->nTotalCreated
= 0;
1010 ci
->frameTitle
= NULL
;
1011 ci
->sbNeedUpdate
= 0;
1013 w
->dwStyle
|= WS_CLIPCHILDREN
;
1017 hBmpClose
= CreateMDIMenuBitmap();
1018 hBmpRestore
= LoadBitmap16( 0, MAKEINTRESOURCE(OBM_RESTORE
) );
1020 MDI_UpdateFrameText(frameWnd
, hwnd
, MDI_NOFRAMEREPAINT
,frameWnd
->text
);
1022 AppendMenu32A( ccs
->hWindowMenu
, MF_SEPARATOR
, 0, NULL
);
1024 GetClientRect16(frameWnd
->hwndSelf
, &rect
);
1025 NC_HandleNCCalcSize( w
, &rect
);
1026 w
->rectClient
= rect
;
1028 dprintf_mdi(stddeb
,"MDI: Client created - hwnd = %04x, idFirst = %u\n",hwnd
,ci
->idFirstChild
);
1033 if( ci
->hwndChildMaximized
) MDI_RestoreFrameMenu(w
, frameWnd
->hwndSelf
);
1034 if((nItems
= GetMenuItemCount32(ci
->hWindowMenu
)) > 0) {
1035 ci
->idFirstChild
= nItems
- 1;
1036 ci
->nActiveChildren
++; /* to delete a separator */
1037 while( ci
->nActiveChildren
-- )
1038 DeleteMenu32(ci
->hWindowMenu
,MF_BYPOSITION
,ci
->idFirstChild
--);
1042 case WM_MDIACTIVATE
:
1043 if( ci
->hwndActiveChild
!= (HWND16
)wParam
)
1044 SetWindowPos32((HWND32
)wParam
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1048 return MDICascade(w
, ci
);
1053 MDICREATESTRUCT16
* cs
= (MDICREATESTRUCT16
*) PTR_SEG_TO_LIN(lParam
);
1054 return (LONG
)MDICreateChild(w
, ci
, hwnd
, cs
, lParam
);
1059 return (LONG
)MDIDestroyChild(w
, ci
, hwnd
, (HWND32
)wParam
, TRUE
);
1061 case WM_MDIGETACTIVE
:
1062 return ((LONG
) ci
->hwndActiveChild
|
1063 ((LONG
) (ci
->hwndChildMaximized
>0) << 16));
1065 case WM_MDIICONARRANGE
:
1066 ci
->sbNeedUpdate
= TRUE
;
1067 MDIIconArrange(hwnd
);
1068 ci
->sbRecalc
= SB_BOTH
+1;
1069 SendMessage16(hwnd
,WM_MDICALCCHILDSCROLL
,0,0L);
1072 case WM_MDIMAXIMIZE
:
1073 ShowWindow16((HWND16
)wParam
, SW_MAXIMIZE
);
1077 MDI_SwitchActiveChild(hwnd
, (HWND16
)wParam
, (lParam
)?1:0);
1081 ShowWindow16( (HWND16
)wParam
, SW_NORMAL
);
1086 return (LRESULT
)MDISetMenu(hwnd
, FALSE
, (HMENU16
)wParam
, (HMENU16
)lParam
);
1088 return (LRESULT
)MDISetMenu(hwnd
, wParam
, LOWORD(lParam
), HIWORD(lParam
));
1092 ci
->sbNeedUpdate
= TRUE
;
1093 ShowScrollBar32(hwnd
,SB_BOTH
,FALSE
);
1094 MDITile(w
, ci
,wParam
);
1095 ci
->sbNeedUpdate
= FALSE
;
1100 ci
->sbNeedUpdate
= TRUE
;
1101 ScrollChildren32(hwnd
,message
,wParam
,lParam
);
1102 ci
->sbNeedUpdate
= FALSE
;
1106 if( ci
->hwndActiveChild
)
1108 w
= WIN_FindWndPtr( ci
->hwndActiveChild
);
1109 if( !(w
->dwStyle
& WS_MINIMIZE
) )
1110 SetFocus32( ci
->hwndActiveChild
);
1115 if( ci
->hwndActiveChild
)
1116 SendMessage16(ci
->hwndActiveChild
, message
, wParam
, lParam
);
1119 case WM_PARENTNOTIFY
:
1120 if( wParam
== WM_LBUTTONDOWN
)
1122 POINT16 pt
= MAKEPOINT16(lParam
);
1123 HWND16 child
= ChildWindowFromPoint16(hwnd
, pt
);
1125 dprintf_mdi(stddeb
,"MDIClient: notification from %04x (%i,%i)\n",child
,pt
.x
,pt
.y
);
1127 if( child
&& child
!= hwnd
&&
1128 child
!= ci
->hwndActiveChild
)
1129 SetWindowPos32(child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1134 if( ci
->hwndChildMaximized
)
1136 WND
* child
= WIN_FindWndPtr(ci
->hwndChildMaximized
);
1137 RECT16 rect
= { 0, 0, LOWORD(lParam
), HIWORD(lParam
) };
1139 AdjustWindowRectEx16(&rect
, child
->dwStyle
, 0, child
->dwExStyle
);
1140 MoveWindow16(ci
->hwndChildMaximized
, rect
.left
, rect
.top
,
1141 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 1);
1144 MDI_PostUpdate(hwnd
, ci
, SB_BOTH
+1);
1148 case WM_MDICALCCHILDSCROLL
:
1149 if( ci
->sbNeedUpdate
)
1152 CalcChildScroll(hwnd
, ci
->sbRecalc
-1);
1153 ci
->sbRecalc
= ci
->sbNeedUpdate
= 0;
1158 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1162 /***********************************************************************
1163 * DefFrameProc16 (USER.445)
1165 LRESULT
DefFrameProc16( HWND16 hwnd
, HWND16 hwndMDIClient
, UINT16 message
,
1166 WPARAM16 wParam
, LPARAM lParam
)
1177 wndPtr
= WIN_FindWndPtr(hwndMDIClient
);
1178 ci
= (MDICLIENTINFO
*)wndPtr
->wExtra
;
1180 /* check for possible syscommands for maximized MDI child */
1183 wParam
< ci
->idFirstChild
||
1184 wParam
>= ci
->idFirstChild
+ ci
->nActiveChildren
1186 if( (wParam
- 0xF000) & 0xF00F ) break;
1197 if( ci
->hwndChildMaximized
)
1198 return SendMessage16( ci
->hwndChildMaximized
, WM_SYSCOMMAND
,
1204 childHwnd
= MDI_GetChildByID( WIN_FindWndPtr(hwndMDIClient
),
1207 SendMessage16(hwndMDIClient
, WM_MDIACTIVATE
,
1208 (WPARAM16
)childHwnd
, 0L);
1213 SendMessage16(hwndMDIClient
, message
, wParam
, lParam
);
1217 MDI_UpdateFrameText(WIN_FindWndPtr(hwnd
), hwndMDIClient
,
1219 (LPCSTR
)PTR_SEG_TO_LIN(lParam
));
1223 SetFocus32(hwndMDIClient
);
1227 MoveWindow16(hwndMDIClient
, 0, 0,
1228 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1233 wndPtr
= WIN_FindWndPtr(hwndMDIClient
);
1234 ci
= (MDICLIENTINFO
*)wndPtr
->wExtra
;
1236 if( !(wndPtr
->parent
->dwStyle
& WS_MINIMIZE
)
1237 && ci
->hwndActiveChild
&& !ci
->hwndChildMaximized
)
1239 /* control menu is between the frame system menu and
1240 * the first entry of menu bar */
1242 if( wParam
== VK_LEFT
)
1243 { if( wndPtr
->parent
->wIDmenu
!= LOWORD(lParam
) ) break; }
1244 else if( wParam
== VK_RIGHT
)
1245 { if( GetSystemMenu16( wndPtr
->parent
->hwndSelf
, 0)
1246 != LOWORD(lParam
) ) break; }
1249 return MAKELONG( GetSystemMenu16(ci
->hwndActiveChild
, 0),
1250 ci
->hwndActiveChild
);
1256 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1260 /***********************************************************************
1261 * DefFrameProc32A (USER32.121)
1263 LRESULT
DefFrameProc32A( HWND32 hwnd
, HWND32 hwndMDIClient
, UINT32 message
,
1264 WPARAM32 wParam
, LPARAM lParam
)
1271 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1273 MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ) );
1276 SendMessage32A(hwndMDIClient
, message
, wParam
, lParam
);
1281 LPSTR segstr
= SEGPTR_STRDUP((LPSTR
)lParam
);
1283 ret
= DefFrameProc16(hwnd
, hwndMDIClient
, message
,
1284 wParam
, (LPARAM
)SEGPTR_GET(segstr
) );
1285 SEGPTR_FREE(segstr
);
1291 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1296 return DefWindowProc32A(hwnd
, message
, wParam
, lParam
);
1300 /***********************************************************************
1301 * DefFrameProc32W (USER32.122)
1303 LRESULT
DefFrameProc32W( HWND32 hwnd
, HWND32 hwndMDIClient
, UINT32 message
,
1304 WPARAM32 wParam
, LPARAM lParam
)
1311 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1313 MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ) );
1316 SendMessage32W(hwndMDIClient
, message
, wParam
, lParam
);
1320 LPSTR txt
= HEAP_strdupWtoA(GetProcessHeap(),0,(LPWSTR
)lParam
);
1321 LRESULT ret
= DefFrameProc32A( hwnd
, hwndMDIClient
, message
,
1322 wParam
, (DWORD
)txt
);
1323 HeapFree(GetProcessHeap(),0,txt
);
1328 return DefFrameProc32A( hwnd
, hwndMDIClient
, message
,
1333 return DefWindowProc32W( hwnd
, message
, wParam
, lParam
);
1337 /***********************************************************************
1338 * DefMDIChildProc16 (USER.447)
1340 LRESULT
DefMDIChildProc16( HWND16 hwnd
, UINT16 message
,
1341 WPARAM16 wParam
, LPARAM lParam
)
1346 clientWnd
= WIN_FindWndPtr(GetParent16(hwnd
));
1347 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1352 DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1353 MDI_MenuModifyItem(clientWnd
,hwnd
);
1354 if( ci
->hwndChildMaximized
== hwnd
)
1355 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1356 MDI_REPAINTFRAME
, NULL
);
1360 SendMessage16(ci
->self
,WM_MDIDESTROY
,(WPARAM16
)hwnd
,0L);
1364 if( ci
->hwndActiveChild
!= hwnd
)
1365 MDI_ChildActivate(clientWnd
, hwnd
);
1368 case WM_CHILDACTIVATE
:
1369 MDI_ChildActivate(clientWnd
, hwnd
);
1373 dprintf_mdi(stddeb
,"DefMDIChildProc: WM_NCPAINT for %04x, active %04x\n",
1374 hwnd
, ci
->hwndActiveChild
);
1381 if( ci
->hwndChildMaximized
== hwnd
) return 0;
1385 WIN_FindWndPtr(hwnd
)->dwStyle
|= WS_SYSMENU
;
1388 if( ci
->hwndChildMaximized
== hwnd
)
1389 return SendMessage16( clientWnd
->parent
->hwndSelf
,
1390 message
, wParam
, lParam
);
1391 WIN_FindWndPtr(hwnd
)->dwStyle
&= ~WS_SYSMENU
;
1394 SendMessage16( ci
->self
, WM_MDINEXT
, 0, 0);
1397 SendMessage16( ci
->self
, WM_MDINEXT
, 0, 1);
1402 case WM_GETMINMAXINFO
:
1403 MDI_ChildGetMinMaxInfo(clientWnd
, hwnd
, (MINMAXINFO16
*) PTR_SEG_TO_LIN(lParam
));
1407 if( ci
->hwndChildMaximized
)
1408 ci
->sbNeedUpdate
= 0;
1410 MDI_PostUpdate(clientWnd
->hwndSelf
, ci
, SB_BOTH
+1);
1416 if( ci
->hwndActiveChild
== hwnd
&& wParam
!= SIZE_MAXIMIZED
)
1418 ci
->hwndChildMaximized
= 0;
1420 MDI_RestoreFrameMenu( clientWnd
->parent
, hwnd
);
1421 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1422 MDI_REPAINTFRAME
, NULL
);
1425 if( wParam
== SIZE_MAXIMIZED
)
1427 HWND16 hMaxChild
= ci
->hwndChildMaximized
;
1429 if( hMaxChild
== hwnd
) break;
1433 SendMessage16( hMaxChild
, WM_SETREDRAW
, FALSE
, 0L );
1435 MDI_RestoreFrameMenu( clientWnd
->parent
, hMaxChild
);
1436 ShowWindow16( hMaxChild
, SW_SHOWNOACTIVATE
);
1438 SendMessage16( hMaxChild
, WM_SETREDRAW
, TRUE
, 0L );
1441 dprintf_mdi(stddeb
,"\tMDI: maximizing child %04x\n", hwnd
);
1443 ci
->hwndChildMaximized
= hwnd
; /* !!! */
1445 MDI_AugmentFrameMenu( ci
, clientWnd
->parent
, hwnd
);
1446 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1447 MDI_REPAINTFRAME
, NULL
);
1450 if( wParam
== SIZE_MINIMIZED
)
1452 HWND16 switchTo
= MDI_GetWindow(clientWnd
, hwnd
, 0);
1455 SendMessage16( switchTo
, WM_CHILDACTIVATE
, 0, 0L);
1458 MDI_PostUpdate(clientWnd
->hwndSelf
, ci
, SB_BOTH
+1);
1463 /* MDI children don't have menu bars */
1464 PostMessage16( clientWnd
->parent
->hwndSelf
, WM_SYSCOMMAND
,
1465 (WPARAM16
)SC_KEYMENU
, (LPARAM
)wParam
);
1470 if( wParam
== VK_LEFT
) /* switch to frame system menu */
1471 return MAKELONG( GetSystemMenu16(clientWnd
->parent
->hwndSelf
, 0),
1472 clientWnd
->parent
->hwndSelf
);
1473 if( wParam
== VK_RIGHT
) /* to frame menu bar */
1474 return MAKELONG( clientWnd
->parent
->wIDmenu
,
1475 clientWnd
->parent
->hwndSelf
);
1480 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1484 /***********************************************************************
1485 * DefMDIChildProc32A (USER32.123)
1487 LRESULT
DefMDIChildProc32A( HWND32 hwnd
, UINT32 message
,
1488 WPARAM32 wParam
, LPARAM lParam
)
1493 clientWnd
= WIN_FindWndPtr(GetParent16(hwnd
));
1494 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1499 DefWindowProc32A(hwnd
, message
, wParam
, lParam
);
1500 MDI_MenuModifyItem(clientWnd
,hwnd
);
1501 if( ci
->hwndChildMaximized
== hwnd
)
1502 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1503 MDI_REPAINTFRAME
, NULL
);
1506 case WM_GETMINMAXINFO
:
1509 STRUCT32_MINMAXINFO32to16( (MINMAXINFO32
*)lParam
, &mmi
);
1510 MDI_ChildGetMinMaxInfo( clientWnd
, hwnd
, &mmi
);
1511 STRUCT32_MINMAXINFO16to32( &mmi
, (MINMAXINFO32
*)lParam
);
1517 /* MDI children don't have menu bars */
1518 PostMessage16( clientWnd
->parent
->hwndSelf
, WM_SYSCOMMAND
,
1519 (WPARAM16
)SC_KEYMENU
, (LPARAM
)LOWORD(wParam
) );
1524 case WM_CHILDACTIVATE
:
1530 return DefMDIChildProc16( hwnd
, message
, (WPARAM16
)wParam
, lParam
);
1532 return DefWindowProc32A(hwnd
, message
, wParam
, lParam
);
1536 /***********************************************************************
1537 * DefMDIChildProc32W (USER32.124)
1539 LRESULT
DefMDIChildProc32W( HWND32 hwnd
, UINT32 message
,
1540 WPARAM32 wParam
, LPARAM lParam
)
1545 clientWnd
= WIN_FindWndPtr(GetParent16(hwnd
));
1546 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1551 DefWindowProc32W(hwnd
, message
, wParam
, lParam
);
1552 MDI_MenuModifyItem(clientWnd
,hwnd
);
1553 if( ci
->hwndChildMaximized
== hwnd
)
1554 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1555 MDI_REPAINTFRAME
, NULL
);
1558 case WM_GETMINMAXINFO
:
1562 case WM_CHILDACTIVATE
:
1568 return DefMDIChildProc32A( hwnd
, message
, (WPARAM16
)wParam
, lParam
);
1570 return DefWindowProc32W(hwnd
, message
, wParam
, lParam
);
1574 /**********************************************************************
1575 * CreateMDIWindowA (USER32.78)
1578 /**********************************************************************
1579 * CreateMDIWindowW (USER32.79)
1582 /**********************************************************************
1583 * TranslateMDISysAccel32 (USER32.554)
1585 BOOL32
TranslateMDISysAccel32( HWND32 hwndClient
, LPMSG32 msg
)
1589 STRUCT32_MSG32to16(msg
,&msg16
);
1590 /* MDICLIENTINFO is still the same for win32 and win16 ... */
1591 return TranslateMDISysAccel16(hwndClient
,&msg16
);
1595 /**********************************************************************
1596 * TranslateMDISysAccel16 (USER.451)
1598 BOOL16
TranslateMDISysAccel16( HWND16 hwndClient
, LPMSG16 msg
)
1600 WND
* clientWnd
= WIN_FindWndPtr( hwndClient
);
1602 MDICLIENTINFO
*ci
= NULL
;
1603 WPARAM16 wParam
= 0;
1605 if( (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) || !clientWnd
)
1608 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1609 wnd
= WIN_FindWndPtr(ci
->hwndActiveChild
);
1611 if( !wnd
) return 0;
1613 if( wnd
->dwStyle
& WS_DISABLED
) return 0;
1615 if ((GetKeyState32(VK_CONTROL
) & 0x8000) && !(GetKeyState32(VK_MENU
) & 0x8000))
1616 switch( msg
->wParam
)
1620 wParam
= ( GetKeyState32(VK_SHIFT
) & 0x8000 )? SC_NEXTWINDOW
: SC_PREVWINDOW
;
1632 dprintf_mdi(stddeb
,"TranslateMDISysAccel: wParam = %04x\n", wParam
);
1634 SendMessage16(ci
->hwndActiveChild
,WM_SYSCOMMAND
, wParam
, (LPARAM
)msg
->wParam
);
1639 /***********************************************************************
1640 * CalcChildScroll (USER.462)
1642 void CalcChildScroll( HWND16 hwnd
, WORD scroll
)
1644 RECT16 childRect
, clientRect
;
1645 INT32 vmin
, vmax
, hmin
, hmax
, vpos
, hpos
;
1646 BOOL32 noscroll
= FALSE
;
1649 if (!(Wnd
= pWnd
= WIN_FindWndPtr( hwnd
))) return;
1650 GetClientRect16( hwnd
, &clientRect
);
1651 SetRectEmpty16( &childRect
);
1653 for ( pWnd
= pWnd
->child
; pWnd
; pWnd
= pWnd
->next
)
1655 UnionRect16( &childRect
, &pWnd
->rectWindow
, &childRect
);
1656 if( pWnd
->dwStyle
& WS_MAXIMIZE
)
1659 UnionRect16( &childRect
, &clientRect
, &childRect
);
1661 /* jump through the hoops to prevent excessive flashing
1664 hmin
= childRect
.left
; hmax
= childRect
.right
- clientRect
.right
;
1665 hpos
= clientRect
.left
- childRect
.left
;
1666 vmin
= childRect
.top
; vmax
= childRect
.bottom
- clientRect
.bottom
;
1667 vpos
= clientRect
.top
- childRect
.top
;
1670 ShowScrollBar32(hwnd
, SB_BOTH
, FALSE
);
1675 vpos
= hpos
; vmin
= hmin
; vmax
= hmax
;
1677 SetScrollPos32(hwnd
, scroll
, vpos
, FALSE
);
1678 SetScrollRange32(hwnd
, scroll
, vmin
, vmax
, TRUE
);
1681 SCROLL_SetNCSbState( Wnd
, vmin
, vmax
, vpos
,
1683 SetWindowPos32(hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
1684 | SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
1689 /***********************************************************************
1690 * ScrollChildren16 (USER.463)
1692 void ScrollChildren16(HWND16 hWnd
, UINT16 uMsg
, WPARAM16 wParam
, LPARAM lParam
)
1694 return ScrollChildren32( hWnd
, uMsg
, wParam
, lParam
);
1698 /***********************************************************************
1699 * ScrollChildren32 (USER32.447)
1701 void ScrollChildren32(HWND32 hWnd
, UINT32 uMsg
, WPARAM32 wParam
, LPARAM lParam
)
1703 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
1705 INT32 curPos
, length
, minPos
, maxPos
, shift
;
1707 if( !wndPtr
) return;
1709 if( uMsg
== WM_HSCROLL
)
1711 GetScrollRange32(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
1712 curPos
= GetScrollPos32(hWnd
,SB_HORZ
);
1713 length
= (wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
)/2;
1714 shift
= SYSMETRICS_CYHSCROLL
;
1716 else if( uMsg
== WM_VSCROLL
)
1718 GetScrollRange32(hWnd
,SB_VERT
,&minPos
,&maxPos
);
1719 curPos
= GetScrollPos32(hWnd
,SB_VERT
);
1720 length
= (wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
)/2;
1721 shift
= SYSMETRICS_CXVSCROLL
;
1728 newPos
= curPos
- shift
;
1731 newPos
= curPos
+ shift
;
1734 newPos
= curPos
- length
;
1737 newPos
= curPos
+ length
;
1740 case SB_THUMBPOSITION
:
1741 newPos
= LOWORD(lParam
);
1754 CalcChildScroll(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
1758 if( newPos
> maxPos
)
1760 else if( newPos
< minPos
)
1763 SetScrollPos32(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
1765 if( uMsg
== WM_VSCROLL
)
1766 ScrollWindow32(hWnd
,0 ,curPos
- newPos
, NULL
, NULL
);
1768 ScrollWindow32(hWnd
,curPos
- newPos
, 0, NULL
, NULL
);