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 HBITMAP hBmpClose
= 0;
35 static HBITMAP 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 void ScrollChildren(HWND
, UINT
, WPARAM
, LPARAM
);
45 void CalcChildScroll(HWND
, WORD
);
47 static LONG
MDI_ChildActivate(WND
* ,HWND
);
49 /* -------- Miscellaneous service functions ----------
54 static HWND
MDI_GetChildByID(WND
* wndPtr
,int id
)
56 for (wndPtr
= wndPtr
->child
; wndPtr
; wndPtr
= wndPtr
->next
)
57 if (wndPtr
->wIDmenu
== id
) return wndPtr
->hwndSelf
;
61 static void MDI_PostUpdate(HWND hwnd
, MDICLIENTINFO
* ci
, WORD recalc
)
63 if( !ci
->sbNeedUpdate
)
65 ci
->sbNeedUpdate
= TRUE
;
66 PostMessage( hwnd
, WM_MDICALCCHILDSCROLL
, 0, 0);
68 ci
->sbRecalc
= recalc
;
71 /**********************************************************************
74 #ifdef SUPERFLUOUS_FUNCTIONS
75 static BOOL
MDI_MenuAppendItem(WND
*clientWnd
, HWND hWndChild
)
78 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
79 WND
*wndPtr
= WIN_FindWndPtr(hWndChild
);
80 int n
= sprintf(buffer
, "%d ",
81 clientInfo
->nActiveChildren
);
83 if( !clientInfo
->hWindowMenu
) return 0;
85 if (wndPtr
->text
) strncpy(buffer
+ n
, wndPtr
->text
, sizeof(buffer
) - n
- 1);
86 return AppendMenu32A( clientInfo
->hWindowMenu
, MF_STRING
,
87 wndPtr
->wIDmenu
, buffer
);
91 /**********************************************************************
94 static BOOL
MDI_MenuModifyItem(WND
* clientWnd
, HWND hWndChild
)
97 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
98 WND
*wndPtr
= WIN_FindWndPtr(hWndChild
);
99 UINT n
= sprintf(buffer
, "%d ",
100 wndPtr
->wIDmenu
- clientInfo
->idFirstChild
+ 1);
103 if( !clientInfo
->hWindowMenu
) return 0;
105 if (wndPtr
->text
) lstrcpyn32A(buffer
+ n
, wndPtr
->text
, sizeof(buffer
) - n
);
107 n
= GetMenuState(clientInfo
->hWindowMenu
,wndPtr
->wIDmenu
,MF_BYCOMMAND
);
108 bRet
= ModifyMenu32A(clientInfo
->hWindowMenu
, wndPtr
->wIDmenu
,
109 MF_BYCOMMAND
| MF_STRING
, wndPtr
->wIDmenu
, buffer
);
110 CheckMenuItem(clientInfo
->hWindowMenu
,wndPtr
->wIDmenu
, n
& MF_CHECKED
);
114 /**********************************************************************
117 static BOOL
MDI_MenuDeleteItem(WND
* clientWnd
, HWND hWndChild
)
120 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
121 WND
*wndPtr
= WIN_FindWndPtr(hWndChild
);
124 if( !clientInfo
->nActiveChildren
||
125 !clientInfo
->hWindowMenu
) return 0;
127 id
= wndPtr
->wIDmenu
;
128 DeleteMenu(clientInfo
->hWindowMenu
,id
,MF_BYCOMMAND
);
130 /* walk the rest of MDI children to prevent gaps in the id
131 * sequence and in the menu child list */
133 for( index
= id
+1; index
<= clientInfo
->nActiveChildren
+
134 clientInfo
->idFirstChild
; index
++ )
136 wndPtr
= WIN_FindWndPtr(MDI_GetChildByID(clientWnd
,index
));
139 dprintf_mdi(stddeb
,"MDIMenuDeleteItem: no window for id=%i\n",index
);
146 n
= sprintf(buffer
, "%d ",index
- clientInfo
->idFirstChild
);
148 lstrcpyn32A(buffer
+ n
, wndPtr
->text
, sizeof(buffer
) - n
);
151 ModifyMenu32A(clientInfo
->hWindowMenu
,index
,MF_BYCOMMAND
| MF_STRING
,
152 index
- 1 , buffer
);
157 /**********************************************************************
160 * returns "activateable" child or zero
162 HWND
MDI_GetWindow(WND
*clientWnd
, HWND hWnd
, WORD wTo
)
164 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
165 WND
*wndPtr
, *pWnd
, *pWndLast
;
167 if( !hWnd
) hWnd
= clientInfo
->hwndActiveChild
;
169 if( !(wndPtr
= WIN_FindWndPtr(hWnd
)) ) return 0;
176 if (!pWnd
) pWnd
= wndPtr
->parent
->child
;
177 if (pWnd
== wndPtr
) /* not found */
179 if (!wTo
|| !pWndLast
) return 0;
183 /* we are not interested in owned popups */
185 (pWnd
->dwStyle
& WS_VISIBLE
) &&
186 !(pWnd
->dwStyle
& WS_DISABLED
)) /* found one */
192 return pWndLast
? pWndLast
->hwndSelf
: 0;
195 /**********************************************************************
196 * MDI_CalcDefaultChildPos
198 * It seems that default height is 2/3 of client rect
200 void MDI_CalcDefaultChildPos(WND
* w
, WORD n
, LPPOINT16 lpPos
, INT delta
)
202 RECT16 rect
= w
->rectClient
;
203 INT spacing
= GetSystemMetrics(SM_CYCAPTION
) + GetSystemMetrics(SM_CYFRAME
) - 1;
206 if( rect
.bottom
- rect
.top
- delta
>= spacing
)
207 rect
.bottom
-= delta
;
209 nstagger
= (rect
.bottom
- rect
.top
)/(3*spacing
);
210 lpPos
[1].x
= (rect
.right
- rect
.left
- nstagger
*spacing
);
211 lpPos
[1].y
= (rect
.bottom
- rect
.top
- nstagger
*spacing
);
212 lpPos
[0].x
= lpPos
[0].y
= spacing
*(n
%(nstagger
+1));
215 /**********************************************************************
218 HMENU
MDISetMenu(HWND hwnd
, BOOL fRefresh
, HMENU hmenuFrame
, HMENU hmenuWindow
)
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 HWND hwndFrame
= GetParent16(hwnd
);
231 HMENU oldFrameMenu
= GetMenu(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 INT i
= GetMenuItemCount(ci
->hWindowMenu
) - 1;
242 INT pos
= GetMenuItemCount(hmenuWindow
) + 1;
244 AppendMenu32A( hmenuWindow
, MF_SEPARATOR
, 0, NULL
);
246 if( ci
->nActiveChildren
)
248 INT j
= i
- ci
->nActiveChildren
+ 1;
252 for( ; i
>= j
; i
-- )
254 id
= GetMenuItemID(ci
->hWindowMenu
,i
);
255 state
= GetMenuState(ci
->hWindowMenu
,i
,MF_BYPOSITION
);
257 GetMenuString(ci
->hWindowMenu
, i
, buffer
, 100, MF_BYPOSITION
);
259 DeleteMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
260 InsertMenu32A(hmenuWindow
, pos
, MF_BYPOSITION
| MF_STRING
,
262 CheckMenuItem(hmenuWindow
,pos
, MF_BYPOSITION
| (state
& MF_CHECKED
));
266 /* remove separator */
267 DeleteMenu(ci
->hWindowMenu
, i
, MF_BYPOSITION
);
269 ci
->hWindowMenu
= hmenuWindow
;
272 if( hmenuFrame
&& hmenuFrame
!=oldFrameMenu
)
274 SetMenu(hwndFrame
, hmenuFrame
);
275 if( ci
->hwndChildMaximized
)
276 MDI_AugmentFrameMenu(ci
, w
->parent
, ci
->hwndChildMaximized
);
284 /**********************************************************************
287 WORD
MDIIconArrange(HWND parent
)
289 return ArrangeIconicWindows(parent
); /* Any reason why the */
290 /* existing icon arrange */
291 /* can't be used here? */
296 /* ------------------ MDI child window functions ---------------------- */
299 /**********************************************************************
302 HWND
MDICreateChild(WND
*w
, MDICLIENTINFO
*ci
, HWND parent
, LPARAM lParam
)
305 MDICREATESTRUCT16
*cs
= (MDICREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
306 DWORD style
= cs
->style
| (WS_CHILD
| WS_CLIPSIBLINGS
);
307 HWND hwnd
, hwndMax
= 0;
308 WORD wIDmenu
= ci
->idFirstChild
+ ci
->nActiveChildren
;
309 char lpstrDef
[]="junk!";
312 * Create child window
316 dprintf_mdi(stdnimp
,"MDICreateChild: origin %i,%i - dim %i,%i, style %08x\n",
317 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, (unsigned)cs
->style
);
318 /* calculate placement */
319 MDI_CalcDefaultChildPos(w
, ci
->nTotalCreated
++, pos
, 0);
321 if( cs
->cx
== CW_USEDEFAULT16
|| !cs
->cx
)
323 if( cs
->cy
== CW_USEDEFAULT16
|| !cs
->cy
)
326 if( cs
->x
== CW_USEDEFAULT16
)
332 /* restore current maximized child */
333 if( style
& WS_VISIBLE
&& ci
->hwndChildMaximized
)
335 if( style
& WS_MAXIMIZE
)
336 SendMessage16(w
->hwndSelf
, WM_SETREDRAW
, FALSE
, 0L );
337 hwndMax
= ci
->hwndChildMaximized
;
338 ShowWindow( hwndMax
, SW_SHOWNOACTIVATE
);
339 if( style
& WS_MAXIMIZE
)
340 SendMessage16(w
->hwndSelf
, WM_SETREDRAW
, TRUE
, 0L );
343 /* this menu is needed to set a check mark in MDI_ChildActivate */
344 AppendMenu32A(ci
->hWindowMenu
,MF_STRING
,wIDmenu
, lpstrDef
);
346 ci
->nActiveChildren
++;
348 /* fix window style */
349 if( !(w
->dwStyle
& MDIS_ALLCHILDSTYLES
) )
351 style
&= (WS_CHILD
| WS_CLIPSIBLINGS
| WS_MINIMIZE
| WS_MAXIMIZE
|
352 WS_CLIPCHILDREN
| WS_DISABLED
| WS_VSCROLL
| WS_HSCROLL
);
353 style
|= (WS_VISIBLE
| WS_OVERLAPPEDWINDOW
);
356 hwnd
= CreateWindow16( (LPCSTR
)PTR_SEG_TO_LIN(cs
->szClass
),
357 (LPCSTR
)PTR_SEG_TO_LIN(cs
->szTitle
), style
,
358 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, parent
,
359 (HMENU
)(DWORD
)(WORD
)wIDmenu
, w
->hInstance
,
362 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
366 WND
* wnd
= WIN_FindWndPtr( hwnd
);
368 MDI_MenuModifyItem(w
,hwnd
);
369 if( wnd
->dwStyle
& WS_MINIMIZE
&& ci
->hwndActiveChild
)
370 ShowWindow( hwnd
, SW_SHOWMINNOACTIVE
);
373 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
);
375 /* Set maximized state here in case hwnd didn't receive WM_SIZE
376 * during CreateWindow - bad!
379 if( wnd
->dwStyle
& WS_MAXIMIZE
&& !ci
->hwndChildMaximized
)
381 ci
->hwndChildMaximized
= wnd
->hwndSelf
;
382 MDI_AugmentFrameMenu( ci
, w
->parent
, hwnd
);
383 MDI_UpdateFrameText( w
->parent
, ci
->self
, MDI_REPAINTFRAME
, NULL
);
386 dprintf_mdi(stddeb
, "MDICreateChild: created child - %04x\n",hwnd
);
390 ci
->nActiveChildren
--;
391 DeleteMenu(ci
->hWindowMenu
,wIDmenu
,MF_BYCOMMAND
);
392 if( IsWindow(hwndMax
) )
393 ShowWindow(hwndMax
, SW_SHOWMAXIMIZED
);
399 /**********************************************************************
400 * MDI_ChildGetMinMaxInfo
402 void MDI_ChildGetMinMaxInfo(WND
* clientWnd
, HWND hwnd
, MINMAXINFO16
* lpMinMax
)
404 WND
* childWnd
= WIN_FindWndPtr(hwnd
);
405 RECT16 rect
= clientWnd
->rectClient
;
407 MapWindowPoints16(clientWnd
->parent
->hwndSelf
,
408 ((MDICLIENTINFO
*)clientWnd
->wExtra
)->self
, (LPPOINT16
)&rect
, 2);
409 AdjustWindowRectEx16( &rect
, childWnd
->dwStyle
& ~(WS_VSCROLL
| WS_HSCROLL
),
410 0, childWnd
->dwExStyle
);
412 lpMinMax
->ptMaxSize
.x
= rect
.right
-= rect
.left
;
413 lpMinMax
->ptMaxSize
.y
= rect
.bottom
-= rect
.top
;
415 lpMinMax
->ptMaxPosition
.x
= rect
.left
;
416 lpMinMax
->ptMaxPosition
.y
= rect
.top
;
418 dprintf_mdi(stddeb
,"\tChildMinMaxInfo: max rect (%i,%i - %i, %i)\n",
419 rect
.left
,rect
.top
,rect
.right
,rect
.bottom
);
423 /**********************************************************************
424 * MDI_SwitchActiveChild
426 * Notes: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
429 * wTo is basically lParam of WM_MDINEXT message or explicit
432 void MDI_SwitchActiveChild(HWND clientHwnd
, HWND childHwnd
, BOOL wTo
)
434 WND
*w
= WIN_FindWndPtr(clientHwnd
);
439 hwndTo
= MDI_GetWindow(w
,childHwnd
,(WORD
)wTo
);
441 ci
= (MDICLIENTINFO
*) w
->wExtra
;
443 dprintf_mdi(stddeb
, "MDI_SwitchActiveChild: from %04x, to %04x\n",childHwnd
,hwndTo
);
445 if ( !hwndTo
) return;
447 hwndPrev
= ci
->hwndActiveChild
;
449 if ( hwndTo
!= hwndPrev
)
453 if( ci
->hwndChildMaximized
)
456 w
->dwStyle
&= ~WS_VISIBLE
;
459 SetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0,
460 SWP_NOMOVE
| SWP_NOSIZE
);
461 if( !wTo
&& hwndPrev
)
463 SetWindowPos( hwndPrev
, HWND_BOTTOM
, 0, 0, 0, 0,
464 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
468 ShowWindow( clientHwnd
, SW_SHOW
);
473 /**********************************************************************
476 HWND
MDIDestroyChild(WND
*w_parent
, MDICLIENTINFO
*ci
, HWND parent
,
477 HWND child
, BOOL flagDestroy
)
479 WND
*childPtr
= WIN_FindWndPtr(child
);
483 if( child
== ci
->hwndActiveChild
)
485 MDI_SwitchActiveChild(parent
,child
,0);
487 if( child
== ci
->hwndActiveChild
)
489 ShowWindow( child
, SW_HIDE
);
490 if( child
== ci
->hwndChildMaximized
)
492 MDI_RestoreFrameMenu(w_parent
->parent
, child
);
493 ci
->hwndChildMaximized
= 0;
494 MDI_UpdateFrameText(w_parent
->parent
,parent
,TRUE
,NULL
);
497 MDI_ChildActivate(w_parent
,0);
499 MDI_MenuDeleteItem(w_parent
, child
);
502 ci
->nActiveChildren
--;
504 dprintf_mdi(stddeb
,"MDIDestroyChild: child destroyed - %04x\n",child
);
508 MDI_PostUpdate(GetParent16(child
), ci
, SB_BOTH
+1);
509 DestroyWindow(child
);
517 /**********************************************************************
520 * Note: hWndChild is NULL when last child is being destroyed
522 LONG
MDI_ChildActivate(WND
*clientPtr
, HWND hWndChild
)
524 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientPtr
->wExtra
;
525 HWND prevActiveWnd
= clientInfo
->hwndActiveChild
;
526 WND
*wndPtr
= WIN_FindWndPtr( hWndChild
);
527 WND
*wndPrev
= WIN_FindWndPtr( prevActiveWnd
);
528 BOOL isActiveFrameWnd
= 0;
530 if( hWndChild
== prevActiveWnd
) return 0L;
533 if( wndPtr
->dwStyle
& WS_DISABLED
) return 0L;
535 dprintf_mdi(stddeb
,"MDI_ChildActivate: %04x\n", hWndChild
);
537 if( GetActiveWindow() == clientPtr
->parent
->hwndSelf
)
538 isActiveFrameWnd
= TRUE
;
540 /* deactivate prev. active child */
543 wndPrev
->dwStyle
|= WS_SYSMENU
;
544 SendMessage16( prevActiveWnd
, WM_NCACTIVATE
, FALSE
, 0L );
547 SendMessage32A( prevActiveWnd
, WM_MDIACTIVATE
, (WPARAM
)prevActiveWnd
,
551 SendMessage16( prevActiveWnd
, WM_MDIACTIVATE
, FALSE
,
552 MAKELONG(hWndChild
,prevActiveWnd
));
554 /* uncheck menu item */
555 if( clientInfo
->hWindowMenu
)
556 CheckMenuItem( clientInfo
->hWindowMenu
,
557 wndPrev
->wIDmenu
, 0);
561 if( clientInfo
->hwndChildMaximized
)
562 if( clientInfo
->hwndChildMaximized
!= hWndChild
)
565 clientInfo
->hwndActiveChild
= hWndChild
;
566 ShowWindow( hWndChild
, SW_SHOWMAXIMIZED
);
569 ShowWindow( clientInfo
->hwndActiveChild
,
572 clientInfo
->hwndActiveChild
= hWndChild
;
574 /* check if we have any children left */
577 if( isActiveFrameWnd
)
578 SetFocus32( clientInfo
->self
);
582 /* check menu item */
583 if( clientInfo
->hWindowMenu
)
584 CheckMenuItem( clientInfo
->hWindowMenu
,
585 wndPtr
->wIDmenu
, MF_CHECKED
);
587 /* bring active child to the top */
588 SetWindowPos( hWndChild
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
590 if( isActiveFrameWnd
)
592 SendMessage16( hWndChild
, WM_NCACTIVATE
, TRUE
, 0L);
593 if( GetFocus32() == clientInfo
->self
)
594 SendMessage16( clientInfo
->self
, WM_SETFOCUS
,
595 (WPARAM
)clientInfo
->self
, 0L );
597 SetFocus32( clientInfo
->self
);
601 SendMessage32A( hWndChild
, WM_MDIACTIVATE
, (WPARAM
)hWndChild
,
602 (LPARAM
)prevActiveWnd
);
604 SendMessage16( hWndChild
, WM_MDIACTIVATE
, TRUE
,
605 MAKELONG(hWndChild
,prevActiveWnd
));
611 /**********************************************************************
614 * iTotal returns number of children available for tiling or cascading
616 MDIWCL
* MDI_BuildWCL(WND
* clientWnd
, INT16
* iTotal
)
618 MDIWCL
*listTop
,*listNext
;
621 if (!(listTop
= (MDIWCL
*)malloc( sizeof(MDIWCL
) ))) return NULL
;
623 listTop
->hChild
= clientWnd
->child
? clientWnd
->child
->hwndSelf
: 0;
624 listTop
->prev
= NULL
;
627 /* build linked list from top child to bottom */
629 childWnd
= WIN_FindWndPtr( listTop
->hChild
);
630 while( childWnd
&& childWnd
->next
)
632 listNext
= (MDIWCL
*)xmalloc(sizeof(MDIWCL
));
634 if( (childWnd
->dwStyle
& WS_DISABLED
) ||
635 (childWnd
->dwStyle
& WS_MINIMIZE
) ||
636 !(childWnd
->dwStyle
& WS_VISIBLE
) )
642 listNext
->hChild
= childWnd
->next
->hwndSelf
;
643 listNext
->prev
= listTop
;
647 childWnd
= childWnd
->next
;
650 if( (childWnd
->dwStyle
& WS_DISABLED
) ||
651 (childWnd
->dwStyle
& WS_MINIMIZE
) ||
652 !(childWnd
->dwStyle
& WS_VISIBLE
) )
662 /* -------------------- MDI client window functions ------------------- */
664 /**********************************************************************
665 * CreateMDIMenuBitmap
667 HBITMAP
CreateMDIMenuBitmap(void)
669 HDC hDCSrc
= CreateCompatibleDC(0);
670 HDC hDCDest
= CreateCompatibleDC(hDCSrc
);
671 HBITMAP16 hbClose
= LoadBitmap16(0, MAKEINTRESOURCE(OBM_CLOSE
) );
672 HBITMAP16 hbCopy
,hb_src
,hb_dest
;
674 hb_src
= SelectObject(hDCSrc
,hbClose
);
675 hbCopy
= CreateCompatibleBitmap(hDCSrc
,SYSMETRICS_CXSIZE
, SYSMETRICS_CYSIZE
);
676 hb_dest
= SelectObject(hDCDest
,hbCopy
);
678 BitBlt(hDCDest
, 0, 0, SYSMETRICS_CXSIZE
, SYSMETRICS_CYSIZE
,
679 hDCSrc
, SYSMETRICS_CXSIZE
, 0, SRCCOPY
);
681 SelectObject(hDCSrc
,hb_src
);
682 SelectObject(hDCDest
,hb_dest
);
684 DeleteObject(hbClose
);
692 /**********************************************************************
695 LONG
MDICascade(WND
* clientWnd
, MDICLIENTINFO
*ci
)
697 MDIWCL
*listTop
,*listPrev
;
698 INT16 delta
= 0,iToPosition
= 0, n
= 0;
701 if (ci
->hwndChildMaximized
)
702 ShowWindow( 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 SetWindowPos(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 ArrangeIconicWindows( clientWnd
->hwndSelf
);
735 /**********************************************************************
739 LONG
MDITile(WND
* wndClient
, MDICLIENTINFO
*ci
,WORD wParam
)
741 MDIWCL
*listTop
,*listPrev
;
748 INT16 iToPosition
= 0;
750 if (ci
->hwndChildMaximized
)
751 ShowWindow(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 SetWindowPos(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 ArrangeIconicWindows( wndClient
->hwndSelf
);
835 /* ----------------------- Frame window ---------------------------- */
838 /**********************************************************************
839 * MDI_AugmentFrameMenu
841 BOOL
MDI_AugmentFrameMenu(MDICLIENTINFO
* ci
, WND
*frame
, HWND hChild
)
843 WND
* child
= WIN_FindWndPtr(hChild
);
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 (!(handle
= SYSRES_LoadResource( SYSRES_MENU_SYSMENU
))) return 0;
854 hSysPopup
= LoadMenuIndirect16( GlobalLock16( handle
) );
855 SYSRES_FreeResource( handle
);
857 dprintf_mdi(stddeb
,"\t\tgot popup %04x\n in sysmenu %04x",hSysPopup
,child
->hSysMenu
);
859 if( !InsertMenu32A(frame
->wIDmenu
,0,MF_BYPOSITION
| MF_BITMAP
| MF_POPUP
,
860 hSysPopup
, (LPSTR
)(DWORD
)hBmpClose
))
861 { DestroyMenu(hSysPopup
); return 0; }
863 if( !AppendMenu32A(frame
->wIDmenu
,MF_HELP
| MF_BITMAP
,
864 SC_RESTORE
, (LPSTR
)(DWORD
)hBmpRestore
))
866 RemoveMenu(frame
->wIDmenu
,0,MF_BYPOSITION
);
870 EnableMenuItem(hSysPopup
, SC_SIZE
, MF_BYCOMMAND
| MF_GRAYED
);
871 EnableMenuItem(hSysPopup
, SC_MOVE
, MF_BYCOMMAND
| MF_GRAYED
);
872 EnableMenuItem(hSysPopup
, SC_MAXIMIZE
, MF_BYCOMMAND
| MF_GRAYED
);
875 DrawMenuBar(frame
->hwndSelf
);
880 /**********************************************************************
881 * MDI_RestoreFrameMenu
883 BOOL
MDI_RestoreFrameMenu( WND
*frameWnd
, HWND hChild
)
885 INT nItems
= GetMenuItemCount(frameWnd
->wIDmenu
) - 1;
887 dprintf_mdi(stddeb
,"MDI_RestoreFrameMenu: for child %04x\n",hChild
);
889 if( GetMenuItemID(frameWnd
->wIDmenu
,nItems
) != SC_RESTORE
)
893 RemoveMenu(frameWnd
->wIDmenu
,0,MF_BYPOSITION
);
894 DeleteMenu(frameWnd
->wIDmenu
,nItems
-1,MF_BYPOSITION
);
896 DrawMenuBar(frameWnd
->hwndSelf
);
901 /**********************************************************************
902 * MDI_UpdateFrameText
904 * used when child window is maximized/restored
906 * Note: lpTitle can be NULL
908 void MDI_UpdateFrameText(WND
*frameWnd
, HWND hClient
, BOOL 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 SetWindowPos(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(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
983 LPCLIENTCREATESTRUCT16 ccs
;
986 WND
*w
= WIN_FindWndPtr(hwnd
);
987 WND
*frameWnd
= w
->parent
;
989 ci
= (MDICLIENTINFO
*) w
->wExtra
;
994 cs
= (LPCREATESTRUCT16
) PTR_SEG_TO_LIN(lParam
);
995 ccs
= (LPCLIENTCREATESTRUCT16
) PTR_SEG_TO_LIN(cs
->lpCreateParams
);
997 ci
->hWindowMenu
= ccs
->hWindowMenu
;
998 ci
->idFirstChild
= ccs
->idFirstChild
;
999 ci
->hwndChildMaximized
= 0;
1000 ci
->nActiveChildren
= 0;
1001 ci
->nTotalCreated
= 0;
1002 ci
->frameTitle
= NULL
;
1003 ci
->sbNeedUpdate
= 0;
1005 w
->dwStyle
|= WS_CLIPCHILDREN
;
1009 hBmpClose
= CreateMDIMenuBitmap();
1010 hBmpRestore
= LoadBitmap16( 0, MAKEINTRESOURCE(OBM_RESTORE
) );
1012 MDI_UpdateFrameText(frameWnd
, hwnd
, MDI_NOFRAMEREPAINT
,frameWnd
->text
);
1014 AppendMenu32A( ccs
->hWindowMenu
, MF_SEPARATOR
, 0, NULL
);
1016 GetClientRect16(frameWnd
->hwndSelf
, &rect
);
1017 NC_HandleNCCalcSize( w
, &rect
);
1018 w
->rectClient
= rect
;
1020 dprintf_mdi(stddeb
,"MDI: Client created - hwnd = %04x, idFirst = %u\n",hwnd
,ci
->idFirstChild
);
1025 if( ci
->hwndChildMaximized
) MDI_RestoreFrameMenu(w
, frameWnd
->hwndSelf
);
1026 ci
->idFirstChild
= GetMenuItemCount(ci
->hWindowMenu
) - 1;
1027 ci
->nActiveChildren
++; /* to delete a separator */
1029 while( ci
->nActiveChildren
-- )
1030 DeleteMenu(ci
->hWindowMenu
,MF_BYPOSITION
,ci
->idFirstChild
--);
1034 case WM_MDIACTIVATE
:
1035 if( ci
->hwndActiveChild
!= (HWND
)wParam
)
1036 SetWindowPos((HWND
)wParam
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1040 return MDICascade(w
, ci
);
1043 return (LONG
)MDICreateChild(w
, ci
, hwnd
, lParam
);
1046 return (LONG
)MDIDestroyChild(w
, ci
, hwnd
, (HWND
)wParam
, TRUE
);
1048 case WM_MDIGETACTIVE
:
1049 return ((LONG
) ci
->hwndActiveChild
|
1050 ((LONG
) (ci
->hwndChildMaximized
>0) << 16));
1052 case WM_MDIICONARRANGE
:
1053 ci
->sbNeedUpdate
= TRUE
;
1054 MDIIconArrange(hwnd
);
1055 ci
->sbRecalc
= SB_BOTH
+1;
1056 SendMessage16(hwnd
,WM_MDICALCCHILDSCROLL
,0,0L);
1059 case WM_MDIMAXIMIZE
:
1060 ShowWindow((HWND
)wParam
, SW_MAXIMIZE
);
1064 MDI_SwitchActiveChild(hwnd
, (HWND
)wParam
, (lParam
)?1:0);
1068 ShowWindow( (HWND
)wParam
, SW_NORMAL
);
1073 return (LRESULT
)MDISetMenu(hwnd
, FALSE
, (HMENU
)wParam
, (HMENU
)lParam
);
1075 return (LRESULT
)MDISetMenu(hwnd
, wParam
, LOWORD(lParam
), HIWORD(lParam
));
1079 ci
->sbNeedUpdate
= TRUE
;
1080 ShowScrollBar32(hwnd
,SB_BOTH
,FALSE
);
1081 MDITile(w
, ci
,wParam
);
1082 ci
->sbNeedUpdate
= FALSE
;
1087 ci
->sbNeedUpdate
= TRUE
;
1088 ScrollChildren(hwnd
,message
,wParam
,lParam
);
1089 ci
->sbNeedUpdate
= FALSE
;
1093 if( ci
->hwndActiveChild
)
1095 w
= WIN_FindWndPtr( ci
->hwndActiveChild
);
1096 if( !(w
->dwStyle
& WS_MINIMIZE
) )
1097 SetFocus32( ci
->hwndActiveChild
);
1102 if( ci
->hwndActiveChild
)
1103 SendMessage16(ci
->hwndActiveChild
, message
, wParam
, lParam
);
1106 case WM_PARENTNOTIFY
:
1107 if( wParam
== WM_LBUTTONDOWN
)
1109 POINT16 pt
= MAKEPOINT16(lParam
);
1110 HWND child
= ChildWindowFromPoint16(hwnd
, pt
);
1112 dprintf_mdi(stddeb
,"MDIClient: notification from %04x (%i,%i)\n",child
,pt
.x
,pt
.y
);
1114 if( child
&& child
!= hwnd
)
1116 WND
* wnd
= WIN_FindWndPtr( child
);
1118 /* if we got owned popup */
1119 if( wnd
->owner
) child
= wnd
->owner
->hwndSelf
;
1121 if( child
!= ci
->hwndActiveChild
)
1122 SetWindowPos(child
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
1128 if( ci
->hwndChildMaximized
)
1130 WND
* child
= WIN_FindWndPtr(ci
->hwndChildMaximized
);
1131 RECT16 rect
= { 0, 0, LOWORD(lParam
), HIWORD(lParam
) };
1133 AdjustWindowRectEx16(&rect
, child
->dwStyle
, 0, child
->dwExStyle
);
1134 MoveWindow(ci
->hwndChildMaximized
, rect
.left
, rect
.top
,
1135 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
, 1);
1138 MDI_PostUpdate(hwnd
, ci
, SB_BOTH
+1);
1142 case WM_MDICALCCHILDSCROLL
:
1143 if( ci
->sbNeedUpdate
)
1146 CalcChildScroll(hwnd
, ci
->sbRecalc
-1);
1147 ci
->sbRecalc
= ci
->sbNeedUpdate
= 0;
1152 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1156 /***********************************************************************
1157 * DefFrameProc16 (USER.445)
1159 LRESULT
DefFrameProc16( HWND16 hwnd
, HWND16 hwndMDIClient
, UINT16 message
,
1160 WPARAM16 wParam
, LPARAM lParam
)
1171 wndPtr
= WIN_FindWndPtr(hwndMDIClient
);
1172 ci
= (MDICLIENTINFO
*)wndPtr
->wExtra
;
1174 /* check for possible syscommands for maximized MDI child */
1176 if( wParam
< ci
->idFirstChild
||
1177 wParam
>= ci
->idFirstChild
+ ci
->nActiveChildren
)
1179 if( (wParam
- 0xF000) & 0xF00F ) break;
1190 if( ci
->hwndChildMaximized
)
1191 return SendMessage16( ci
->hwndChildMaximized
, WM_SYSCOMMAND
,
1197 childHwnd
= MDI_GetChildByID( WIN_FindWndPtr(hwndMDIClient
),
1200 SendMessage16(hwndMDIClient
, WM_MDIACTIVATE
, (WPARAM
)childHwnd
, 0L);
1205 SendMessage16(hwndMDIClient
, message
, wParam
, lParam
);
1209 MDI_UpdateFrameText(WIN_FindWndPtr(hwnd
), hwndMDIClient
,
1211 (LPCSTR
)PTR_SEG_TO_LIN(lParam
));
1215 SetFocus32(hwndMDIClient
);
1219 MoveWindow(hwndMDIClient
, 0, 0,
1220 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1225 wndPtr
= WIN_FindWndPtr(hwndMDIClient
);
1226 ci
= (MDICLIENTINFO
*)wndPtr
->wExtra
;
1228 if( !(wndPtr
->parent
->dwStyle
& WS_MINIMIZE
)
1229 && ci
->hwndActiveChild
&& !ci
->hwndChildMaximized
)
1231 /* control menu is between the frame system menu and
1232 * the first entry of menu bar */
1234 if( wParam
== VK_LEFT
)
1235 { if( wndPtr
->parent
->wIDmenu
!= LOWORD(lParam
) ) break; }
1236 else if( wParam
== VK_RIGHT
)
1237 { if( GetSystemMenu( wndPtr
->parent
->hwndSelf
, 0)
1238 != LOWORD(lParam
) ) break; }
1241 return MAKELONG( GetSystemMenu(ci
->hwndActiveChild
, 0),
1242 ci
->hwndActiveChild
);
1248 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1252 /***********************************************************************
1253 * DefFrameProc32A (USER32.121)
1255 LRESULT
DefFrameProc32A( HWND32 hwnd
, HWND32 hwndMDIClient
, UINT32 message
,
1256 WPARAM32 wParam
, LPARAM lParam
)
1263 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1265 MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ) );
1268 SendMessage32A(hwndMDIClient
, message
, wParam
, lParam
);
1272 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1273 wParam
, (LPARAM
)PTR_SEG_TO_LIN(lParam
) );
1277 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1282 return DefWindowProc32A(hwnd
, message
, wParam
, lParam
);
1286 /***********************************************************************
1287 * DefFrameProc32W (USER32.122)
1289 LRESULT
DefFrameProc32W( HWND32 hwnd
, HWND32 hwndMDIClient
, UINT32 message
,
1290 WPARAM32 wParam
, LPARAM lParam
)
1297 return DefFrameProc16( hwnd
, hwndMDIClient
, message
,
1299 MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ) );
1302 SendMessage32W(hwndMDIClient
, message
, wParam
, lParam
);
1306 /* FIXME: Unicode */
1307 return DefFrameProc32A( hwnd
, hwndMDIClient
, message
,
1312 return DefFrameProc32A( hwnd
, hwndMDIClient
, message
,
1317 return DefWindowProc32W( hwnd
, message
, wParam
, lParam
);
1321 /***********************************************************************
1322 * DefMDIChildProc16 (USER.447)
1324 LRESULT
DefMDIChildProc16( HWND16 hwnd
, UINT16 message
,
1325 WPARAM16 wParam
, LPARAM lParam
)
1330 clientWnd
= WIN_FindWndPtr(GetParent16(hwnd
));
1331 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1336 DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1337 MDI_MenuModifyItem(clientWnd
,hwnd
);
1338 if( ci
->hwndChildMaximized
== hwnd
)
1339 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1340 MDI_REPAINTFRAME
, NULL
);
1344 SendMessage16(ci
->self
,WM_MDIDESTROY
,(WPARAM
)hwnd
,0L);
1348 if( ci
->hwndActiveChild
!= hwnd
)
1349 MDI_ChildActivate(clientWnd
, hwnd
);
1352 case WM_CHILDACTIVATE
:
1353 MDI_ChildActivate(clientWnd
, hwnd
);
1357 dprintf_mdi(stddeb
,"DefMDIChildProc: WM_NCPAINT for %04x, active %04x\n",
1358 hwnd
, ci
->hwndActiveChild
);
1365 if( ci
->hwndChildMaximized
== hwnd
) return 0;
1369 WIN_FindWndPtr(hwnd
)->dwStyle
|= WS_SYSMENU
;
1372 if( ci
->hwndChildMaximized
== hwnd
)
1373 return SendMessage16( clientWnd
->parent
->hwndSelf
,
1374 message
, wParam
, lParam
);
1375 WIN_FindWndPtr(hwnd
)->dwStyle
&= ~WS_SYSMENU
;
1378 SendMessage16( ci
->self
, WM_MDINEXT
, 0, 0);
1381 SendMessage16( ci
->self
, WM_MDINEXT
, 0, 1);
1386 case WM_GETMINMAXINFO
:
1387 MDI_ChildGetMinMaxInfo(clientWnd
, hwnd
, (MINMAXINFO16
*) PTR_SEG_TO_LIN(lParam
));
1391 if( ci
->hwndChildMaximized
)
1392 ci
->sbNeedUpdate
= 0;
1394 MDI_PostUpdate(clientWnd
->hwndSelf
, ci
, SB_BOTH
+1);
1400 if( ci
->hwndActiveChild
== hwnd
&& wParam
!= SIZE_MAXIMIZED
)
1402 ci
->hwndChildMaximized
= 0;
1404 MDI_RestoreFrameMenu( clientWnd
->parent
, hwnd
);
1405 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1406 MDI_REPAINTFRAME
, NULL
);
1409 if( wParam
== SIZE_MAXIMIZED
)
1411 HWND hMaxChild
= ci
->hwndChildMaximized
;
1413 if( hMaxChild
== hwnd
) break;
1417 SendMessage16( hMaxChild
, WM_SETREDRAW
, FALSE
, 0L );
1419 MDI_RestoreFrameMenu( clientWnd
->parent
, hMaxChild
);
1420 ShowWindow( hMaxChild
, SW_SHOWNOACTIVATE
);
1422 SendMessage16( hMaxChild
, WM_SETREDRAW
, TRUE
, 0L );
1425 dprintf_mdi(stddeb
,"\tMDI: maximizing child %04x\n", hwnd
);
1427 ci
->hwndChildMaximized
= hwnd
; /* !!! */
1429 MDI_AugmentFrameMenu( ci
, clientWnd
->parent
, hwnd
);
1430 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1431 MDI_REPAINTFRAME
, NULL
);
1434 if( wParam
== SIZE_MINIMIZED
)
1436 HWND switchTo
= MDI_GetWindow(clientWnd
, hwnd
, 0);
1439 SendMessage16( switchTo
, WM_CHILDACTIVATE
, 0, 0L);
1442 MDI_PostUpdate(clientWnd
->hwndSelf
, ci
, SB_BOTH
+1);
1447 /* MDI children don't have menu bars */
1448 PostMessage( clientWnd
->parent
->hwndSelf
, WM_SYSCOMMAND
,
1449 (WPARAM
)SC_KEYMENU
, (LPARAM
)wParam
);
1454 if( wParam
== VK_LEFT
) /* switch to frame system menu */
1455 return MAKELONG( GetSystemMenu(clientWnd
->parent
->hwndSelf
, 0),
1456 clientWnd
->parent
->hwndSelf
);
1457 if( wParam
== VK_RIGHT
) /* to frame menu bar */
1458 return MAKELONG( clientWnd
->parent
->wIDmenu
,
1459 clientWnd
->parent
->hwndSelf
);
1464 return DefWindowProc16(hwnd
, message
, wParam
, lParam
);
1468 /***********************************************************************
1469 * DefMDIChildProc32A (USER32.123)
1471 LRESULT
DefMDIChildProc32A( HWND32 hwnd
, UINT32 message
,
1472 WPARAM32 wParam
, LPARAM lParam
)
1477 clientWnd
= WIN_FindWndPtr(GetParent16(hwnd
));
1478 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1483 DefWindowProc32A(hwnd
, message
, wParam
, lParam
);
1484 MDI_MenuModifyItem(clientWnd
,hwnd
);
1485 if( ci
->hwndChildMaximized
== hwnd
)
1486 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1487 MDI_REPAINTFRAME
, NULL
);
1490 case WM_GETMINMAXINFO
:
1493 STRUCT32_MINMAXINFO32to16( (MINMAXINFO32
*)lParam
, &mmi
);
1494 MDI_ChildGetMinMaxInfo( clientWnd
, hwnd
, &mmi
);
1495 STRUCT32_MINMAXINFO16to32( &mmi
, (MINMAXINFO32
*)lParam
);
1501 /* MDI children don't have menu bars */
1502 PostMessage( clientWnd
->parent
->hwndSelf
, WM_SYSCOMMAND
,
1503 (WPARAM
)SC_KEYMENU
, (LPARAM
)LOWORD(wParam
) );
1508 case WM_CHILDACTIVATE
:
1514 return DefMDIChildProc16( hwnd
, message
, (WPARAM16
)wParam
, lParam
);
1516 return DefWindowProc32A(hwnd
, message
, wParam
, lParam
);
1520 /***********************************************************************
1521 * DefMDIChildProc32W (USER32.124)
1523 LRESULT
DefMDIChildProc32W( HWND32 hwnd
, UINT32 message
,
1524 WPARAM32 wParam
, LPARAM lParam
)
1529 clientWnd
= WIN_FindWndPtr(GetParent16(hwnd
));
1530 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1535 DefWindowProc32W(hwnd
, message
, wParam
, lParam
);
1536 MDI_MenuModifyItem(clientWnd
,hwnd
);
1537 if( ci
->hwndChildMaximized
== hwnd
)
1538 MDI_UpdateFrameText( clientWnd
->parent
, ci
->self
,
1539 MDI_REPAINTFRAME
, NULL
);
1542 case WM_GETMINMAXINFO
:
1546 case WM_CHILDACTIVATE
:
1552 return DefMDIChildProc32A( hwnd
, message
, (WPARAM16
)wParam
, lParam
);
1554 return DefWindowProc32W(hwnd
, message
, wParam
, lParam
);
1558 /**********************************************************************
1559 * TranslateMDISysAccel (USER.451)
1562 BOOL
TranslateMDISysAccel(HWND hwndClient
, LPMSG16 msg
)
1564 WND
* clientWnd
= WIN_FindWndPtr( hwndClient
);
1566 MDICLIENTINFO
*ci
= NULL
;
1569 if( (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) || !clientWnd
)
1572 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1573 wnd
= WIN_FindWndPtr(ci
->hwndActiveChild
);
1575 if( !wnd
) return 0;
1577 if( wnd
->dwStyle
& WS_DISABLED
) return 0;
1579 if ((GetKeyState(VK_CONTROL
) & 0x8000) && !(GetKeyState(VK_MENU
) & 0x8000))
1580 switch( msg
->wParam
)
1584 wParam
= ( GetKeyState(VK_SHIFT
) & 0x8000 )? SC_NEXTWINDOW
: SC_PREVWINDOW
;
1595 dprintf_mdi(stddeb
,"TranslateMDISysAccel: wParam = %04x\n", wParam
);
1597 SendMessage16(ci
->hwndActiveChild
,WM_SYSCOMMAND
, wParam
, (LPARAM
)msg
->wParam
);
1602 /***********************************************************************
1603 * CalcChildScroll (USER.462)
1605 void CalcChildScroll( HWND hwnd
, WORD scroll
)
1607 RECT16 childRect
, clientRect
;
1608 INT vmin
, vmax
, hmin
, hmax
, vpos
, hpos
;
1609 BOOL noscroll
= FALSE
;
1612 if (!(Wnd
= pWnd
= WIN_FindWndPtr( hwnd
))) return;
1613 GetClientRect16( hwnd
, &clientRect
);
1614 SetRectEmpty16( &childRect
);
1616 for ( pWnd
= pWnd
->child
; pWnd
; pWnd
= pWnd
->next
)
1618 UnionRect16( &childRect
, &pWnd
->rectWindow
, &childRect
);
1619 if( pWnd
->dwStyle
& WS_MAXIMIZE
)
1622 UnionRect16( &childRect
, &clientRect
, &childRect
);
1624 /* jump through the hoops to prevent excessive flashing
1627 hmin
= childRect
.left
; hmax
= childRect
.right
- clientRect
.right
;
1628 hpos
= clientRect
.left
- childRect
.left
;
1629 vmin
= childRect
.top
; vmax
= childRect
.bottom
- clientRect
.bottom
;
1630 vpos
= clientRect
.top
- childRect
.top
;
1633 ShowScrollBar32(hwnd
, SB_BOTH
, FALSE
);
1638 vpos
= hpos
; vmin
= hmin
; vmax
= hmax
;
1640 SetScrollPos32(hwnd
, scroll
, vpos
, FALSE
);
1641 SetScrollRange32(hwnd
, scroll
, vmin
, vmax
, TRUE
);
1644 SCROLL_SetNCSbState( Wnd
, vmin
, vmax
, vpos
,
1646 SetWindowPos(hwnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
1647 | SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
1651 /***********************************************************************
1652 * ScrollChildren (USER.463)
1654 void ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1656 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
1664 if( !wndPtr
) return;
1666 if( uMsg
== WM_HSCROLL
)
1668 GetScrollRange32(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
1669 curPos
= GetScrollPos32(hWnd
,SB_HORZ
);
1670 length
= (wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
)/2;
1671 shift
= SYSMETRICS_CYHSCROLL
;
1673 else if( uMsg
== WM_VSCROLL
)
1675 GetScrollRange32(hWnd
,SB_VERT
,&minPos
,&maxPos
);
1676 curPos
= GetScrollPos32(hWnd
,SB_VERT
);
1677 length
= (wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
)/2;
1678 shift
= SYSMETRICS_CXVSCROLL
;
1685 newPos
= curPos
- shift
;
1688 newPos
= curPos
+ shift
;
1691 newPos
= curPos
- length
;
1694 newPos
= curPos
+ length
;
1697 case SB_THUMBPOSITION
:
1698 newPos
= LOWORD(lParam
);
1711 CalcChildScroll(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
1715 if( newPos
> maxPos
)
1717 else if( newPos
< minPos
)
1720 SetScrollPos32(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
1722 if( uMsg
== WM_VSCROLL
)
1723 ScrollWindow(hWnd
,0 ,curPos
- newPos
, NULL
, NULL
);
1725 ScrollWindow(hWnd
,curPos
- newPos
, 0, NULL
, NULL
);