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
, UINT16
* 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, n
= 0;
698 UINT16 iToPosition
= 0;
701 if (ci
->hwndChildMaximized
)
702 ShowWindow16( ci
->hwndChildMaximized
, SW_NORMAL
);
704 if (ci
->nActiveChildren
== 0) return 0;
706 if (!(listTop
= MDI_BuildWCL(clientWnd
,&iToPosition
))) return 0;
708 if( iToPosition
< ci
->nActiveChildren
)
709 delta
= 2 * SYSMETRICS_CYICONSPACING
+ SYSMETRICS_CYICON
;
711 /* walk list and move windows */
714 dprintf_mdi(stddeb
, "MDICascade: move %04x to (%d,%d) size [%d,%d]\n",
715 listTop
->hChild
, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
);
717 if( listTop
->hChild
)
719 MDI_CalcDefaultChildPos(clientWnd
, n
++, pos
, delta
);
720 SetWindowPos32(listTop
->hChild
, 0, pos
[0].x
, pos
[0].y
, pos
[1].x
, pos
[1].y
,
721 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
724 listPrev
= listTop
->prev
;
729 if( iToPosition
< ci
->nActiveChildren
)
730 ArrangeIconicWindows32( clientWnd
->hwndSelf
);
735 /**********************************************************************
739 static LONG
MDITile(WND
* wndClient
, MDICLIENTINFO
*ci
,WORD wParam
)
741 MDIWCL
*listTop
,*listPrev
;
748 UINT16 iToPosition
= 0;
750 if (ci
->hwndChildMaximized
)
751 ShowWindow16(ci
->hwndChildMaximized
, SW_NORMAL
);
753 if (ci
->nActiveChildren
== 0) return 0;
755 listTop
= MDI_BuildWCL(wndClient
, &iToPosition
);
757 dprintf_mdi(stddeb
,"MDITile: %i windows to tile\n",iToPosition
);
759 if( !listTop
) return 0;
764 rect
= wndClient
->rectClient
;
765 rows
= (int) sqrt((double) iToPosition
);
766 columns
= iToPosition
/ rows
;
768 if (wParam
== MDITILE_HORIZONTAL
) /* version >= 3.1 */
771 rows
=columns
; /* exchange r and c */
776 if( iToPosition
!= ci
->nActiveChildren
)
778 y
= rect
.bottom
- 2 * SYSMETRICS_CYICONSPACING
- SYSMETRICS_CYICON
;
779 rect
.bottom
= ( y
- SYSMETRICS_CYICON
< rect
.top
)? rect
.bottom
: y
;
782 ysize
= rect
.bottom
/ rows
;
783 xsize
= rect
.right
/ columns
;
788 for (c
= 1; c
<= columns
; c
++)
792 rows
= iToPosition
- i
;
793 ysize
= rect
.bottom
/ rows
;
797 for (r
= 1; r
<= rows
; r
++, i
++)
799 /* shouldn't happen but... */
803 /* skip iconized childs from tiling */
804 while (!listTop
->hChild
)
806 listPrev
= listTop
->prev
;
810 SetWindowPos32(listTop
->hChild
, 0, x
, y
, xsize
, ysize
,
811 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
813 listPrev
= listTop
->prev
;
821 /* free the rest if any */
824 listPrev
= listTop
->prev
;
829 if (iToPosition
< ci
->nActiveChildren
)
830 ArrangeIconicWindows32( wndClient
->hwndSelf
);
835 /* ----------------------- Frame window ---------------------------- */
838 /**********************************************************************
839 * MDI_AugmentFrameMenu
841 static BOOL32
MDI_AugmentFrameMenu( MDICLIENTINFO
* ci
, WND
*frame
,
844 WND
* child
= WIN_FindWndPtr(hChild
);
845 HMENU16 hSysPopup
= 0;
847 dprintf_mdi(stddeb
,"MDI_AugmentFrameMenu: frame %p,child %04x\n",frame
,hChild
);
849 if( !frame
->wIDmenu
|| !child
->hSysMenu
) return 0;
851 /* create a copy of sysmenu popup and insert it into frame menu bar */
853 if (!(hSysPopup
= LoadMenuIndirect32A(SYSRES_GetResPtr(SYSRES_MENU_SYSMENU
))))
856 dprintf_mdi(stddeb
,"\t\tgot popup %04x\n in sysmenu %04x",hSysPopup
,child
->hSysMenu
);
858 if( !InsertMenu32A(frame
->wIDmenu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
859 hSysPopup
, (LPSTR
)(DWORD
)hBmpClose
))
860 { DestroyMenu32(hSysPopup
); return 0; }
862 if( !AppendMenu32A(frame
->wIDmenu
,MF_HELP
| MF_BITMAP
,
863 SC_RESTORE
, (LPSTR
)(DWORD
)hBmpRestore
))
865 RemoveMenu32(frame
->wIDmenu
,0,MF_BYPOSITION
);
869 EnableMenuItem32(hSysPopup
, SC_SIZE
, MF_BYCOMMAND
| MF_GRAYED
);
870 EnableMenuItem32(hSysPopup
, SC_MOVE
, MF_BYCOMMAND
| MF_GRAYED
);
871 EnableMenuItem32(hSysPopup
, SC_MAXIMIZE
, MF_BYCOMMAND
| MF_GRAYED
);
874 DrawMenuBar32(frame
->hwndSelf
);
879 /**********************************************************************
880 * MDI_RestoreFrameMenu
882 static BOOL32
MDI_RestoreFrameMenu( WND
*frameWnd
, HWND16 hChild
)
884 INT32 nItems
= GetMenuItemCount32(frameWnd
->wIDmenu
) - 1;
886 dprintf_mdi(stddeb
,"MDI_RestoreFrameMenu: for child %04x\n",hChild
);
888 if( GetMenuItemID32(frameWnd
->wIDmenu
,nItems
) != SC_RESTORE
)
892 RemoveMenu32(frameWnd
->wIDmenu
,0,MF_BYPOSITION
);
893 DeleteMenu32(frameWnd
->wIDmenu
,nItems
-1,MF_BYPOSITION
);
895 DrawMenuBar32(frameWnd
->hwndSelf
);
900 /**********************************************************************
901 * MDI_UpdateFrameText
903 * used when child window is maximized/restored
905 * Note: lpTitle can be NULL
907 static void MDI_UpdateFrameText( WND
*frameWnd
, HWND16 hClient
,
908 BOOL32 repaint
, LPCSTR lpTitle
)
910 char lpBuffer
[MDI_MAXTITLELENGTH
+1];
911 WND
* clientWnd
= WIN_FindWndPtr(hClient
);
913 MDICLIENTINFO
*ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
915 dprintf_mdi(stddeb
, "MDI: repaint %i, frameText %s\n", repaint
, (lpTitle
)?lpTitle
:"NULL");
917 /* store new "default" title if lpTitle is not NULL */
920 if (ci
->frameTitle
) HeapFree( SystemHeap
, 0, ci
->frameTitle
);
921 ci
->frameTitle
= HEAP_strdupA( SystemHeap
, 0, lpTitle
);
926 WND
* childWnd
= WIN_FindWndPtr( ci
->hwndChildMaximized
);
928 if( childWnd
&& childWnd
->text
)
930 /* combine frame title and child title if possible */
932 LPCSTR lpBracket
= " - [";
933 int i_frame_text_length
= strlen(ci
->frameTitle
);
934 int i_child_text_length
= strlen(childWnd
->text
);
936 lstrcpyn32A( lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
938 if( i_frame_text_length
+ 6 < MDI_MAXTITLELENGTH
)
940 strcat( lpBuffer
, lpBracket
);
942 if( i_frame_text_length
+ i_child_text_length
+ 6 < MDI_MAXTITLELENGTH
)
944 strcat( lpBuffer
, childWnd
->text
);
945 strcat( lpBuffer
, "]" );
949 lstrcpyn32A( lpBuffer
+ i_frame_text_length
+ 4,
951 MDI_MAXTITLELENGTH
- i_frame_text_length
- 5 );
952 strcat( lpBuffer
, "]" );
958 strncpy(lpBuffer
, ci
->frameTitle
, MDI_MAXTITLELENGTH
);
959 lpBuffer
[MDI_MAXTITLELENGTH
]='\0';
965 DEFWND_SetText( frameWnd
, lpBuffer
);
966 if( repaint
== MDI_REPAINTFRAME
)
967 SetWindowPos32(frameWnd
->hwndSelf
, 0,0,0,0,0, SWP_FRAMECHANGED
|
968 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
972 /* ----------------------------- Interface ---------------------------- */
975 /**********************************************************************
978 * This function is the handler for all MDI requests.
980 LRESULT
MDIClientWndProc(HWND16 hwnd
, UINT16 message
, WPARAM16 wParam
, LPARAM lParam
)
983 LPCLIENTCREATESTRUCT16 ccs
;
986 WND
*w
= WIN_FindWndPtr(hwnd
);
987 WND
*frameWnd
= w
->parent
;
990 ci
= (MDICLIENTINFO
*) w
->wExtra
;
996 cs
= (LPCREATESTRUCT16
) PTR_SEG_TO_LIN(lParam
);
998 /* Translation layer doesn't know what's in the cs->lpCreateParams
999 * so we have to keep track of what environment we're in. */
1001 if( w
->flags
& WIN_ISWIN32
)
1002 ccs
= (LPCLIENTCREATESTRUCT16
) cs
->lpCreateParams
;
1004 ccs
= (LPCLIENTCREATESTRUCT16
) PTR_SEG_TO_LIN(cs
->lpCreateParams
);
1006 ci
->hWindowMenu
= ccs
->hWindowMenu
;
1007 ci
->idFirstChild
= ccs
->idFirstChild
;
1008 ci
->hwndChildMaximized
= 0;
1009 ci
->nActiveChildren
= 0;
1010 ci
->nTotalCreated
= 0;
1011 ci
->frameTitle
= NULL
;
1012 ci
->sbNeedUpdate
= 0;
1014 w
->dwStyle
|= WS_CLIPCHILDREN
;
1018 hBmpClose
= CreateMDIMenuBitmap();
1019 hBmpRestore
= LoadBitmap16( 0, MAKEINTRESOURCE(OBM_RESTORE
) );
1021 MDI_UpdateFrameText(frameWnd
, hwnd
, MDI_NOFRAMEREPAINT
,frameWnd
->text
);
1023 AppendMenu32A( ccs
->hWindowMenu
, MF_SEPARATOR
, 0, NULL
);
1025 GetClientRect16(frameWnd
->hwndSelf
, &rect
);
1026 NC_HandleNCCalcSize( w
, &rect
);
1027 w
->rectClient
= rect
;
1029 dprintf_mdi(stddeb
,"MDI: Client created - hwnd = %04x, idFirst = %u\n",hwnd
,ci
->idFirstChild
);
1034 if( ci
->hwndChildMaximized
) MDI_RestoreFrameMenu(w
, frameWnd
->hwndSelf
);
1035 if((nItems
= GetMenuItemCount32(ci
->hWindowMenu
)) > 0) {
1036 ci
->idFirstChild
= nItems
- 1;
1037 ci
->nActiveChildren
++; /* to delete a separator */
1038 while( ci
->nActiveChildren
-- )
1039 DeleteMenu32(ci
->hWindowMenu
,MF_BYPOSITION
,ci
->idFirstChild
--);
1043 case WM_MDIACTIVATE
:
1044 if( ci
->hwndActiveChild
!= (HWND16
)wParam
)
1045 SetWindowPos32((HWND32
)wParam
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1049 return MDICascade(w
, ci
);
1054 MDICREATESTRUCT16
* cs
= (MDICREATESTRUCT16
*) PTR_SEG_TO_LIN(lParam
);
1055 return (LONG
)MDICreateChild(w
, ci
, hwnd
, cs
, lParam
);
1060 return (LONG
)MDIDestroyChild(w
, ci
, hwnd
, (HWND32
)wParam
, TRUE
);
1062 case WM_MDIGETACTIVE
:
1063 return ((LONG
) ci
->hwndActiveChild
|
1064 ((LONG
) (ci
->hwndChildMaximized
>0) << 16));
1066 case WM_MDIICONARRANGE
:
1067 ci
->sbNeedUpdate
= TRUE
;
1068 MDIIconArrange(hwnd
);
1069 ci
->sbRecalc
= SB_BOTH
+1;
1070 SendMessage16(hwnd
,WM_MDICALCCHILDSCROLL
,0,0L);
1073 case WM_MDIMAXIMIZE
:
1074 ShowWindow16((HWND16
)wParam
, SW_MAXIMIZE
);
1078 MDI_SwitchActiveChild(hwnd
, (HWND16
)wParam
, (lParam
)?1:0);
1082 ShowWindow16( (HWND16
)wParam
, SW_NORMAL
);
1087 return (LRESULT
)MDISetMenu(hwnd
, FALSE
, (HMENU16
)wParam
, (HMENU16
)lParam
);
1089 return (LRESULT
)MDISetMenu(hwnd
, wParam
, LOWORD(lParam
), HIWORD(lParam
));
1093 ci
->sbNeedUpdate
= TRUE
;
1094 ShowScrollBar32(hwnd
,SB_BOTH
,FALSE
);
1095 MDITile(w
, ci
,wParam
);
1096 ci
->sbNeedUpdate
= FALSE
;
1101 ci
->sbNeedUpdate
= TRUE
;
1102 ScrollChildren32(hwnd
,message
,wParam
,lParam
);
1103 ci
->sbNeedUpdate
= FALSE
;
1107 if( ci
->hwndActiveChild
)
1109 w
= WIN_FindWndPtr( ci
->hwndActiveChild
);
1110 if( !(w
->dwStyle
& WS_MINIMIZE
) )
1111 SetFocus32( ci
->hwndActiveChild
);
1116 if( ci
->hwndActiveChild
)
1117 SendMessage16(ci
->hwndActiveChild
, message
, wParam
, lParam
);
1120 case WM_PARENTNOTIFY
:
1121 if( wParam
== WM_LBUTTONDOWN
)
1123 POINT16 pt
= MAKEPOINT16(lParam
);
1124 HWND16 child
= ChildWindowFromPoint16(hwnd
, pt
);
1126 dprintf_mdi(stddeb
,"MDIClient: notification from %04x (%i,%i)\n",child
,pt
.x
,pt
.y
);
1128 if( child
&& child
!= hwnd
&&
1129 child
!= ci
->hwndActiveChild
)
1130 SetWindowPos32(child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1135 if( ci
->hwndChildMaximized
)
1137 WND
* child
= WIN_FindWndPtr(ci
->hwndChildMaximized
);
1138 RECT16 rect
= { 0, 0, LOWORD(lParam
), HIWORD(lParam
) };
1140 AdjustWindowRectEx16(&rect
, child
->dwStyle
, 0, child
->dwExStyle
);
1141 MoveWindow16(ci
->hwndChildMaximized
, rect
.left
, rect
.top
,
1142 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 1);
1145 MDI_PostUpdate(hwnd
, ci
, SB_BOTH
+1);
1149 case WM_MDICALCCHILDSCROLL
:
1150 if( ci
->sbNeedUpdate
)
1153 CalcChildScroll(hwnd
, ci
->sbRecalc
-1);
1154 ci
->sbRecalc
= ci
->sbNeedUpdate
= 0;
1159 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1163 /***********************************************************************
1164 * DefFrameProc16 (USER.445)
1166 LRESULT
DefFrameProc16( HWND16 hwnd
, HWND16 hwndMDIClient
, UINT16 message
,
1167 WPARAM16 wParam
, LPARAM lParam
)
1178 wndPtr
= WIN_FindWndPtr(hwndMDIClient
);
1179 ci
= (MDICLIENTINFO
*)wndPtr
->wExtra
;
1181 /* check for possible syscommands for maximized MDI child */
1184 wParam
< ci
->idFirstChild
||
1185 wParam
>= ci
->idFirstChild
+ ci
->nActiveChildren
1187 if( (wParam
- 0xF000) & 0xF00F ) break;
1198 if( ci
->hwndChildMaximized
)
1199 return SendMessage16( ci
->hwndChildMaximized
, WM_SYSCOMMAND
,
1205 childHwnd
= MDI_GetChildByID( WIN_FindWndPtr(hwndMDIClient
),
1208 SendMessage16(hwndMDIClient
, WM_MDIACTIVATE
,
1209 (WPARAM16
)childHwnd
, 0L);
1214 SendMessage16(hwndMDIClient
, message
, wParam
, lParam
);
1218 MDI_UpdateFrameText(WIN_FindWndPtr(hwnd
), hwndMDIClient
,
1220 (LPCSTR
)PTR_SEG_TO_LIN(lParam
));
1224 SetFocus32(hwndMDIClient
);
1228 MoveWindow16(hwndMDIClient
, 0, 0,
1229 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1234 wndPtr
= WIN_FindWndPtr(hwndMDIClient
);
1235 ci
= (MDICLIENTINFO
*)wndPtr
->wExtra
;
1237 if( !(wndPtr
->parent
->dwStyle
& WS_MINIMIZE
)
1238 && ci
->hwndActiveChild
&& !ci
->hwndChildMaximized
)
1240 /* control menu is between the frame system menu and
1241 * the first entry of menu bar */
1243 if( wParam
== VK_LEFT
)
1244 { if( wndPtr
->parent
->wIDmenu
!= LOWORD(lParam
) ) break; }
1245 else if( wParam
== VK_RIGHT
)
1246 { if( GetSystemMenu16( wndPtr
->parent
->hwndSelf
, 0)
1247 != LOWORD(lParam
) ) break; }
1250 return MAKELONG( GetSystemMenu16(ci
->hwndActiveChild
, 0),
1251 ci
->hwndActiveChild
);
1257 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1261 /***********************************************************************
1262 * DefFrameProc32A (USER32.121)
1264 LRESULT
DefFrameProc32A( HWND32 hwnd
, HWND32 hwndMDIClient
, UINT32 message
,
1265 WPARAM32 wParam
, LPARAM lParam
)
1272 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1274 MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ) );
1277 SendMessage32A(hwndMDIClient
, message
, wParam
, lParam
);
1282 LPSTR segstr
= SEGPTR_STRDUP((LPSTR
)lParam
);
1284 ret
= DefFrameProc16(hwnd
, hwndMDIClient
, message
,
1285 wParam
, (LPARAM
)SEGPTR_GET(segstr
) );
1286 SEGPTR_FREE(segstr
);
1292 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1297 return DefWindowProc32A(hwnd
, message
, wParam
, lParam
);
1301 /***********************************************************************
1302 * DefFrameProc32W (USER32.122)
1304 LRESULT
DefFrameProc32W( HWND32 hwnd
, HWND32 hwndMDIClient
, UINT32 message
,
1305 WPARAM32 wParam
, LPARAM lParam
)
1312 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1314 MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ) );
1317 SendMessage32W(hwndMDIClient
, message
, wParam
, lParam
);
1321 LPSTR txt
= HEAP_strdupWtoA(GetProcessHeap(),0,(LPWSTR
)lParam
);
1322 LRESULT ret
= DefFrameProc32A( hwnd
, hwndMDIClient
, message
,
1323 wParam
, (DWORD
)txt
);
1324 HeapFree(GetProcessHeap(),0,txt
);
1329 return DefFrameProc32A( hwnd
, hwndMDIClient
, message
,
1334 return DefWindowProc32W( hwnd
, message
, wParam
, lParam
);
1338 /***********************************************************************
1339 * DefMDIChildProc16 (USER.447)
1341 LRESULT
DefMDIChildProc16( HWND16 hwnd
, UINT16 message
,
1342 WPARAM16 wParam
, LPARAM lParam
)
1347 clientWnd
= WIN_FindWndPtr(GetParent16(hwnd
));
1348 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1353 DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1354 MDI_MenuModifyItem(clientWnd
,hwnd
);
1355 if( ci
->hwndChildMaximized
== hwnd
)
1356 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1357 MDI_REPAINTFRAME
, NULL
);
1361 SendMessage16(ci
->self
,WM_MDIDESTROY
,(WPARAM16
)hwnd
,0L);
1365 if( ci
->hwndActiveChild
!= hwnd
)
1366 MDI_ChildActivate(clientWnd
, hwnd
);
1369 case WM_CHILDACTIVATE
:
1370 MDI_ChildActivate(clientWnd
, hwnd
);
1374 dprintf_mdi(stddeb
,"DefMDIChildProc: WM_NCPAINT for %04x, active %04x\n",
1375 hwnd
, ci
->hwndActiveChild
);
1382 if( ci
->hwndChildMaximized
== hwnd
) return 0;
1386 WIN_FindWndPtr(hwnd
)->dwStyle
|= WS_SYSMENU
;
1389 if( ci
->hwndChildMaximized
== hwnd
)
1390 return SendMessage16( clientWnd
->parent
->hwndSelf
,
1391 message
, wParam
, lParam
);
1392 WIN_FindWndPtr(hwnd
)->dwStyle
&= ~WS_SYSMENU
;
1395 SendMessage16( ci
->self
, WM_MDINEXT
, 0, 0);
1398 SendMessage16( ci
->self
, WM_MDINEXT
, 0, 1);
1403 case WM_GETMINMAXINFO
:
1404 MDI_ChildGetMinMaxInfo(clientWnd
, hwnd
, (MINMAXINFO16
*) PTR_SEG_TO_LIN(lParam
));
1408 if( ci
->hwndChildMaximized
)
1409 ci
->sbNeedUpdate
= 0;
1411 MDI_PostUpdate(clientWnd
->hwndSelf
, ci
, SB_BOTH
+1);
1417 if( ci
->hwndActiveChild
== hwnd
&& wParam
!= SIZE_MAXIMIZED
)
1419 ci
->hwndChildMaximized
= 0;
1421 MDI_RestoreFrameMenu( clientWnd
->parent
, hwnd
);
1422 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1423 MDI_REPAINTFRAME
, NULL
);
1426 if( wParam
== SIZE_MAXIMIZED
)
1428 HWND16 hMaxChild
= ci
->hwndChildMaximized
;
1430 if( hMaxChild
== hwnd
) break;
1434 SendMessage16( hMaxChild
, WM_SETREDRAW
, FALSE
, 0L );
1436 MDI_RestoreFrameMenu( clientWnd
->parent
, hMaxChild
);
1437 ShowWindow16( hMaxChild
, SW_SHOWNOACTIVATE
);
1439 SendMessage16( hMaxChild
, WM_SETREDRAW
, TRUE
, 0L );
1442 dprintf_mdi(stddeb
,"\tMDI: maximizing child %04x\n", hwnd
);
1444 ci
->hwndChildMaximized
= hwnd
; /* !!! */
1446 MDI_AugmentFrameMenu( ci
, clientWnd
->parent
, hwnd
);
1447 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1448 MDI_REPAINTFRAME
, NULL
);
1451 if( wParam
== SIZE_MINIMIZED
)
1453 HWND16 switchTo
= MDI_GetWindow(clientWnd
, hwnd
, 0);
1456 SendMessage16( switchTo
, WM_CHILDACTIVATE
, 0, 0L);
1459 MDI_PostUpdate(clientWnd
->hwndSelf
, ci
, SB_BOTH
+1);
1464 /* MDI children don't have menu bars */
1465 PostMessage16( clientWnd
->parent
->hwndSelf
, WM_SYSCOMMAND
,
1466 (WPARAM16
)SC_KEYMENU
, (LPARAM
)wParam
);
1471 if( wParam
== VK_LEFT
) /* switch to frame system menu */
1472 return MAKELONG( GetSystemMenu16(clientWnd
->parent
->hwndSelf
, 0),
1473 clientWnd
->parent
->hwndSelf
);
1474 if( wParam
== VK_RIGHT
) /* to frame menu bar */
1475 return MAKELONG( clientWnd
->parent
->wIDmenu
,
1476 clientWnd
->parent
->hwndSelf
);
1481 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1485 /***********************************************************************
1486 * DefMDIChildProc32A (USER32.123)
1488 LRESULT
DefMDIChildProc32A( HWND32 hwnd
, UINT32 message
,
1489 WPARAM32 wParam
, LPARAM lParam
)
1494 clientWnd
= WIN_FindWndPtr(GetParent16(hwnd
));
1495 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1500 DefWindowProc32A(hwnd
, message
, wParam
, lParam
);
1501 MDI_MenuModifyItem(clientWnd
,hwnd
);
1502 if( ci
->hwndChildMaximized
== hwnd
)
1503 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1504 MDI_REPAINTFRAME
, NULL
);
1507 case WM_GETMINMAXINFO
:
1510 STRUCT32_MINMAXINFO32to16( (MINMAXINFO32
*)lParam
, &mmi
);
1511 MDI_ChildGetMinMaxInfo( clientWnd
, hwnd
, &mmi
);
1512 STRUCT32_MINMAXINFO16to32( &mmi
, (MINMAXINFO32
*)lParam
);
1518 /* MDI children don't have menu bars */
1519 PostMessage16( clientWnd
->parent
->hwndSelf
, WM_SYSCOMMAND
,
1520 (WPARAM16
)SC_KEYMENU
, (LPARAM
)LOWORD(wParam
) );
1525 case WM_CHILDACTIVATE
:
1531 return DefMDIChildProc16( hwnd
, message
, (WPARAM16
)wParam
, lParam
);
1533 return DefWindowProc32A(hwnd
, message
, wParam
, lParam
);
1537 /***********************************************************************
1538 * DefMDIChildProc32W (USER32.124)
1540 LRESULT
DefMDIChildProc32W( HWND32 hwnd
, UINT32 message
,
1541 WPARAM32 wParam
, LPARAM lParam
)
1546 clientWnd
= WIN_FindWndPtr(GetParent16(hwnd
));
1547 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1552 DefWindowProc32W(hwnd
, message
, wParam
, lParam
);
1553 MDI_MenuModifyItem(clientWnd
,hwnd
);
1554 if( ci
->hwndChildMaximized
== hwnd
)
1555 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1556 MDI_REPAINTFRAME
, NULL
);
1559 case WM_GETMINMAXINFO
:
1563 case WM_CHILDACTIVATE
:
1569 return DefMDIChildProc32A( hwnd
, message
, (WPARAM16
)wParam
, lParam
);
1571 return DefWindowProc32W(hwnd
, message
, wParam
, lParam
);
1575 /**********************************************************************
1576 * CreateMDIWindowA (USER32.78)
1579 /**********************************************************************
1580 * CreateMDIWindowW (USER32.79)
1583 /**********************************************************************
1584 * TranslateMDISysAccel32 (USER32.554)
1586 BOOL32
TranslateMDISysAccel32( HWND32 hwndClient
, LPMSG32 msg
)
1590 STRUCT32_MSG32to16(msg
,&msg16
);
1591 /* MDICLIENTINFO is still the same for win32 and win16 ... */
1592 return TranslateMDISysAccel16(hwndClient
,&msg16
);
1596 /**********************************************************************
1597 * TranslateMDISysAccel16 (USER.451)
1599 BOOL16
TranslateMDISysAccel16( HWND16 hwndClient
, LPMSG16 msg
)
1601 WND
* clientWnd
= WIN_FindWndPtr( hwndClient
);
1603 MDICLIENTINFO
*ci
= NULL
;
1604 WPARAM16 wParam
= 0;
1606 if( (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) || !clientWnd
)
1609 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1610 wnd
= WIN_FindWndPtr(ci
->hwndActiveChild
);
1612 if( !wnd
) return 0;
1614 if( wnd
->dwStyle
& WS_DISABLED
) return 0;
1616 if ((GetKeyState32(VK_CONTROL
) & 0x8000) && !(GetKeyState32(VK_MENU
) & 0x8000))
1617 switch( msg
->wParam
)
1621 wParam
= ( GetKeyState32(VK_SHIFT
) & 0x8000 )? SC_NEXTWINDOW
: SC_PREVWINDOW
;
1633 dprintf_mdi(stddeb
,"TranslateMDISysAccel: wParam = %04x\n", wParam
);
1635 SendMessage16(ci
->hwndActiveChild
,WM_SYSCOMMAND
, wParam
, (LPARAM
)msg
->wParam
);
1640 /***********************************************************************
1641 * CalcChildScroll (USER.462)
1643 void CalcChildScroll( HWND16 hwnd
, WORD scroll
)
1645 RECT16 childRect
, clientRect
;
1646 INT32 vmin
, vmax
, hmin
, hmax
, vpos
, hpos
;
1647 BOOL32 noscroll
= FALSE
;
1650 if (!(Wnd
= pWnd
= WIN_FindWndPtr( hwnd
))) return;
1651 GetClientRect16( hwnd
, &clientRect
);
1652 SetRectEmpty16( &childRect
);
1654 for ( pWnd
= pWnd
->child
; pWnd
; pWnd
= pWnd
->next
)
1656 UnionRect16( &childRect
, &pWnd
->rectWindow
, &childRect
);
1657 if( pWnd
->dwStyle
& WS_MAXIMIZE
)
1660 UnionRect16( &childRect
, &clientRect
, &childRect
);
1662 /* jump through the hoops to prevent excessive flashing
1665 hmin
= childRect
.left
; hmax
= childRect
.right
- clientRect
.right
;
1666 hpos
= clientRect
.left
- childRect
.left
;
1667 vmin
= childRect
.top
; vmax
= childRect
.bottom
- clientRect
.bottom
;
1668 vpos
= clientRect
.top
- childRect
.top
;
1671 ShowScrollBar32(hwnd
, SB_BOTH
, FALSE
);
1676 vpos
= hpos
; vmin
= hmin
; vmax
= hmax
;
1678 SetScrollPos32(hwnd
, scroll
, vpos
, FALSE
);
1679 SetScrollRange32(hwnd
, scroll
, vmin
, vmax
, TRUE
);
1682 SCROLL_SetNCSbState( Wnd
, vmin
, vmax
, vpos
,
1684 SetWindowPos32(hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
1685 | SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
1690 /***********************************************************************
1691 * ScrollChildren16 (USER.463)
1693 void ScrollChildren16(HWND16 hWnd
, UINT16 uMsg
, WPARAM16 wParam
, LPARAM lParam
)
1695 return ScrollChildren32( hWnd
, uMsg
, wParam
, lParam
);
1699 /***********************************************************************
1700 * ScrollChildren32 (USER32.447)
1702 void ScrollChildren32(HWND32 hWnd
, UINT32 uMsg
, WPARAM32 wParam
, LPARAM lParam
)
1704 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
1706 INT32 curPos
, length
, minPos
, maxPos
, shift
;
1708 if( !wndPtr
) return;
1710 if( uMsg
== WM_HSCROLL
)
1712 GetScrollRange32(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
1713 curPos
= GetScrollPos32(hWnd
,SB_HORZ
);
1714 length
= (wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
)/2;
1715 shift
= SYSMETRICS_CYHSCROLL
;
1717 else if( uMsg
== WM_VSCROLL
)
1719 GetScrollRange32(hWnd
,SB_VERT
,&minPos
,&maxPos
);
1720 curPos
= GetScrollPos32(hWnd
,SB_VERT
);
1721 length
= (wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
)/2;
1722 shift
= SYSMETRICS_CXVSCROLL
;
1729 newPos
= curPos
- shift
;
1732 newPos
= curPos
+ shift
;
1735 newPos
= curPos
- length
;
1738 newPos
= curPos
+ length
;
1741 case SB_THUMBPOSITION
:
1742 newPos
= LOWORD(lParam
);
1755 CalcChildScroll(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
1759 if( newPos
> maxPos
)
1761 else if( newPos
< minPos
)
1764 SetScrollPos32(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
1766 if( uMsg
== WM_VSCROLL
)
1767 ScrollWindow32(hWnd
,0 ,curPos
- newPos
, NULL
, NULL
);
1769 ScrollWindow32(hWnd
,curPos
- newPos
, 0, NULL
, NULL
);