3 * Copyright 1994, Bob Amstadt
6 * This file contains routines to support MDI features.
8 * Notes: Windows keeps ID of MDI menu item in the wIDenu field
9 * of corresponding MDI child.
11 * Basic child activation routine is MDI_ChildActivate and
12 * SetWindowPos(childHwnd,...) implicitly calls it if SWP_NOACTIVATE i
22 #include "nonclient.h"
26 #include "sysmetrics.h"
30 void ScrollChildren(HWND
, UINT
, WPARAM
, LPARAM
);
31 void CalcChildScroll(HWND
, WORD
);
33 /* ----------------- declarations ----------------- */
35 static LONG
MDI_ChildActivate(WND
* ,HWND
);
37 /* -------- Miscellaneous service functions ----------
42 static HWND
MDI_GetChildByID(WND
* mdiClient
,int id
)
44 HWND hWnd
= mdiClient
->hwndChild
;
45 WND
* wndPtr
= WIN_FindWndPtr( hWnd
);
47 if( !wndPtr
) return 0;
51 if( wndPtr
->wIDmenu
== id
) return hWnd
;
52 wndPtr
= WIN_FindWndPtr(hWnd
= wndPtr
->hwndNext
);
58 /**********************************************************************
61 static BOOL
MDI_MenuAppendItem(WND
*clientWnd
, HWND hWndChild
)
64 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
65 WND
*wndPtr
= WIN_FindWndPtr(hWndChild
);
66 LPSTR lpWndText
= (LPSTR
) USER_HEAP_LIN_ADDR(wndPtr
->hText
);
67 int n
= sprintf(buffer
, "%d ",
68 clientInfo
->nActiveChildren
);
70 if( !clientInfo
->hWindowMenu
) return 0;
73 strncpy(buffer
+ n
, lpWndText
, sizeof(buffer
) - n
- 1);
74 return AppendMenu(clientInfo
->hWindowMenu
,MF_STRING
,
75 wndPtr
->wIDmenu
,(LPSTR
)buffer
);
78 /**********************************************************************
81 static BOOL
MDI_MenuModifyItem(WND
* clientWnd
, HWND hWndChild
)
84 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
85 WND
*wndPtr
= WIN_FindWndPtr(hWndChild
);
86 LPSTR lpWndText
= (LPSTR
) USER_HEAP_LIN_ADDR(wndPtr
->hText
);
87 UINT n
= sprintf(buffer
, "%d ",
88 wndPtr
->wIDmenu
- clientInfo
->idFirstChild
+ 1);
91 if( !clientInfo
->hWindowMenu
) return 0;
94 strncpy(buffer
+ n
, lpWndText
, sizeof(buffer
) - n
- 1);
96 n
= GetMenuState(clientInfo
->hWindowMenu
,wndPtr
->wIDmenu
,MF_BYCOMMAND
);
97 bRet
= ModifyMenu(clientInfo
->hWindowMenu
, wndPtr
->wIDmenu
,
98 MF_BYCOMMAND
| MF_STRING
, wndPtr
->wIDmenu
,(LPSTR
)buffer
);
99 CheckMenuItem(clientInfo
->hWindowMenu
,wndPtr
->wIDmenu
, n
& MF_CHECKED
);
103 /**********************************************************************
106 static BOOL
MDI_MenuDeleteItem(WND
* clientWnd
, HWND hWndChild
)
109 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
110 WND
*wndPtr
= WIN_FindWndPtr(hWndChild
);
114 if( !clientInfo
->nActiveChildren
||
115 !clientInfo
->hWindowMenu
) return 0;
117 id
= wndPtr
->wIDmenu
;
118 DeleteMenu(clientInfo
->hWindowMenu
,id
,MF_BYCOMMAND
);
120 /* walk the rest of MDI children to prevent gaps in the id
121 * sequence and in the menu child list
124 for( index
= id
+1; index
<= clientInfo
->nActiveChildren
+
125 clientInfo
->idFirstChild
; index
++ )
127 wndPtr
= WIN_FindWndPtr(MDI_GetChildByID(clientWnd
,index
));
130 dprintf_mdi(stddeb
,"MDIMenuDeleteItem: no window for id=%i\n",index
);
137 n
= sprintf(buffer
, "%d ",index
- clientInfo
->idFirstChild
);
138 lpWndText
= (LPSTR
) USER_HEAP_LIN_ADDR(wndPtr
->hText
);
141 strncpy(buffer
+ n
, lpWndText
, sizeof(buffer
) - n
- 1);
144 ModifyMenu(clientInfo
->hWindowMenu
,index
,MF_BYCOMMAND
| MF_STRING
,
145 index
- 1 ,(LPSTR
)buffer
);
150 /**********************************************************************
153 * returns "activateable" child or zero
155 HWND
MDI_GetWindow(WND
*clientWnd
, HWND hWnd
, WORD wTo
)
158 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientWnd
->wExtra
;
161 if( !hWnd
) hWnd
= clientInfo
->hwndActiveChild
;
163 if( !(wndPtr
= WIN_FindWndPtr(hWnd
)) ) return 0;
166 wTo
= wTo
? GW_HWNDPREV
: GW_HWNDNEXT
;
170 if( clientWnd
->hwndChild
== hWndNext
&& wTo
== GW_HWNDPREV
)
171 hWndNext
= GetWindow( hWndNext
, GW_HWNDLAST
);
172 else if( wndPtr
->hwndNext
== 0 && wTo
== GW_HWNDNEXT
)
173 hWndNext
= clientWnd
->hwndChild
;
175 hWndNext
= GetWindow( hWndNext
, wTo
);
177 wndPtr
= WIN_FindWndPtr( hWndNext
);
179 if( (wndPtr
->dwStyle
& WS_VISIBLE
) &&
180 !(wndPtr
->dwStyle
& WS_DISABLED
) )
183 /* check if all windows were iterated through */
184 if( hWndNext
== hWnd
) break;
187 return ( hWnd
== hWndNext
)? 0 : hWndNext
;
191 /**********************************************************************
193 * FIXME: This is not complete.
195 HMENU
MDISetMenu(HWND hwnd
, BOOL fRefresh
, HMENU hmenuFrame
, HMENU hmenuWindow
)
197 dprintf_mdi(stddeb
, "WM_MDISETMENU: "NPFMT
" %04x "NPFMT
" "NPFMT
"\n", hwnd
, fRefresh
, hmenuFrame
, hmenuWindow
);
199 HWND hwndFrame
= GetParent(hwnd
);
200 HMENU oldFrameMenu
= GetMenu(hwndFrame
);
201 SetMenu(hwndFrame
, hmenuFrame
);
207 /**********************************************************************
210 WORD
MDIIconArrange(HWND parent
)
212 return ArrangeIconicWindows(parent
); /* Any reason why the */
213 /* existing icon arrange */
214 /* can't be used here? */
218 /**********************************************************************
221 HWND
MDICreateChild(WND
*w
, MDICLIENTINFO
*ci
, HWND parent
, LPARAM lParam
)
223 MDICREATESTRUCT
*cs
= (MDICREATESTRUCT
*)PTR_SEG_TO_LIN(lParam
);
225 WORD wIDmenu
= ci
->idFirstChild
+ ci
->nActiveChildren
;
230 * Create child window
232 cs
->style
&= (WS_MINIMIZE
| WS_MAXIMIZE
| WS_HSCROLL
| WS_VSCROLL
);
234 /* The child windows should probably */
235 /* stagger, shouldn't they? -DRP */
236 spacing
= GetSystemMetrics(SM_CYCAPTION
) + GetSystemMetrics(SM_CYFRAME
);
237 cs
->x
= ci
->nActiveChildren
* spacing
;
238 cs
->y
= ci
->nActiveChildren
* spacing
;
240 /* this menu is needed to set a check mark in MDI_ChildActivate */
241 AppendMenu(ci
->hWindowMenu
,MF_STRING
,wIDmenu
, (LPSTR
)&chDef
);
243 hwnd
= CreateWindow( cs
->szClass
, cs
->szTitle
,
244 WS_CHILD
| WS_BORDER
| WS_CAPTION
| WS_CLIPSIBLINGS
|
245 WS_MAXIMIZEBOX
| WS_MINIMIZEBOX
| WS_SYSMENU
|
246 WS_THICKFRAME
| WS_VISIBLE
| cs
->style
,
247 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, parent
,
248 (HMENU
) wIDmenu
, w
->hInstance
, (SEGPTR
)lParam
);
252 ci
->nActiveChildren
++;
253 MDI_MenuModifyItem(w
,hwnd
);
255 /* FIXME: at this point NC area of hwnd stays inactive */
258 DeleteMenu(ci
->hWindowMenu
,wIDmenu
,MF_BYCOMMAND
);
263 /**********************************************************************
264 * MDI_SwitchActiveChild
266 * Notes: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
269 * Ideally consecutive SetWindowPos should be replaced by
270 * BeginDeferWindowPos/EndDeferWindowPos but currently it doesn't
273 * wTo is basically lParam of WM_MDINEXT message
275 void MDI_SwitchActiveChild(HWND clientHwnd
, HWND childHwnd
, WORD wTo
)
277 WND
*w
= WIN_FindWndPtr(clientHwnd
);
278 HWND hwndTo
= MDI_GetWindow(w
,childHwnd
,wTo
);
283 ci
= (MDICLIENTINFO
*) w
->wExtra
;
285 dprintf_mdi(stddeb
, "MDI_SwitchActiveChild: "NPFMT
", %i\n",childHwnd
,wTo
);
287 if ( !childHwnd
|| !hwndTo
) return;
289 hwndPrev
= ci
->hwndActiveChild
;
291 if ( hwndTo
!= hwndPrev
)
293 if (ci
->flagChildMaximized
)
295 RECT rectOldRestore
, rect
;
297 w
= WIN_FindWndPtr(hwndTo
);
299 /* save old window dimensions */
300 rectOldRestore
= ci
->rectRestore
;
301 GetWindowRect(hwndTo
, &ci
->rectRestore
);
303 rect
.top
= (ci
->rectMaximize
.top
-
304 (w
->rectClient
.top
- w
->rectWindow
.top
));
305 rect
.bottom
= (ci
->rectMaximize
.bottom
+
306 (w
->rectWindow
.bottom
- w
->rectClient
.bottom
));
307 rect
.left
= (ci
->rectMaximize
.left
-
308 (w
->rectClient
.left
- w
->rectWindow
.left
));
309 rect
.right
= (ci
->rectMaximize
.right
+
310 (w
->rectWindow
.right
- w
->rectClient
.right
));
311 w
->dwStyle
|= WS_MAXIMIZE
;
314 ci
->flagChildMaximized
= childHwnd
; /* prevent maximization
315 * in MDI_ChildActivate
318 SetWindowPos( hwndTo
, HWND_TOP
, rect
.left
, rect
.top
,
319 rect
.right
- rect
.left
+ 1,
320 rect
.bottom
- rect
.top
+ 1, 0);
322 SendMessage( hwndTo
, WM_SIZE
, SIZE_MAXIMIZED
,
323 MAKELONG(w
->rectClient
.right
-w
->rectClient
.left
,
324 w
->rectClient
.bottom
-w
->rectClient
.top
));
326 w
= WIN_FindWndPtr(hwndPrev
);
330 w
->dwStyle
&= ~WS_MAXIMIZE
;
332 /* push hwndPrev to the bottom if needed */
334 SetWindowPos(hwndPrev
, HWND_BOTTOM
,
335 rectOldRestore
.left
, rectOldRestore
.top
,
336 rectOldRestore
.right
- rectOldRestore
.left
+ 1,
337 rectOldRestore
.bottom
- rectOldRestore
.top
+ 1,
343 SetWindowPos( hwndTo
, HWND_TOP
, 0, 0, 0, 0,
344 SWP_NOMOVE
| SWP_NOSIZE
);
345 if( !wTo
&& hwndPrev
)
347 SetWindowPos( hwndPrev
, HWND_BOTTOM
, 0, 0, 0, 0,
348 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
356 /**********************************************************************
359 HWND
MDIDestroyChild(WND
*w_parent
, MDICLIENTINFO
*ci
, HWND parent
,
360 HWND child
, BOOL flagDestroy
)
362 WND
*childPtr
= WIN_FindWndPtr(child
);
366 if( child
== ci
->hwndActiveChild
)
368 MDI_SwitchActiveChild(parent
,child
,0);
370 if( child
== ci
->hwndActiveChild
)
371 MDI_ChildActivate(w_parent
,0);
373 MDI_MenuDeleteItem(w_parent
, child
);
376 ci
->nActiveChildren
--;
378 if( ci
->flagChildMaximized
== child
)
379 ci
->flagChildMaximized
= 1;
383 DestroyWindow(child
);
384 PostMessage(parent
,WM_MDICALCCHILDSCROLL
,0,0L);
385 ci
->sbRecalc
|= (SB_BOTH
+1);
393 /**********************************************************************
396 LONG
MDIMaximizeChild(HWND parent
, HWND child
, MDICLIENTINFO
*ci
)
399 WND
*w
= WIN_FindWndPtr(child
);
402 if( !SendMessage( child
, WM_QUERYOPEN
, 0, 0L) )
405 ci
->rectRestore
= w
->rectWindow
;
407 rect
.top
= (ci
->rectMaximize
.top
-
408 (w
->rectClient
.top
- w
->rectWindow
.top
));
409 rect
.bottom
= (ci
->rectMaximize
.bottom
+
410 (w
->rectWindow
.bottom
- w
->rectClient
.bottom
));
411 rect
.left
= (ci
->rectMaximize
.left
-
412 (w
->rectClient
.left
- w
->rectWindow
.left
));
413 rect
.right
= (ci
->rectMaximize
.right
+
414 (w
->rectWindow
.right
- w
->rectClient
.right
));
415 w
->dwStyle
|= WS_MAXIMIZE
;
417 SetWindowPos(child
, 0, rect
.left
, rect
.top
,
418 rect
.right
- rect
.left
+ 1, rect
.bottom
- rect
.top
+ 1, 0);
420 ci
->flagChildMaximized
= child
;
422 SendMessage(child
, WM_SIZE
, SIZE_MAXIMIZED
,
423 MAKELONG(w
->rectClient
.right
-w
->rectClient
.left
,
424 w
->rectClient
.bottom
-w
->rectClient
.top
));
426 SendMessage(GetParent(parent
), WM_NCPAINT
, 0, 0);
431 /**********************************************************************
434 LONG
MDIRestoreChild(HWND parent
, MDICLIENTINFO
*ci
)
438 hWnd
= ci
->hwndActiveChild
;
440 dprintf_mdi(stddeb
,"MDIRestoreChild: restore "NPFMT
"\n", hWnd
);
442 ci
->flagChildMaximized
= FALSE
;
444 ShowWindow(hWnd
, SW_RESTORE
); /* display the window */
446 hWnd
= GetParent(parent
);
448 SendMessage(hWnd
,WM_NCPAINT
, 0, 0);
453 /**********************************************************************
456 * Note: hWndChild is NULL when last child is being destroyed
458 LONG
MDI_ChildActivate(WND
*clientPtr
, HWND hWndChild
)
460 MDICLIENTINFO
*clientInfo
= (MDICLIENTINFO
*)clientPtr
->wExtra
;
461 HWND prevActiveWnd
= clientInfo
->hwndActiveChild
;
462 WND
*wndPtr
= WIN_FindWndPtr( hWndChild
);
463 WND
*wndPrev
= WIN_FindWndPtr( prevActiveWnd
);
464 BOOL isActiveFrameWnd
= 0;
466 if( hWndChild
== prevActiveWnd
) return 0L;
469 if( wndPtr
->dwStyle
& WS_DISABLED
) return 0L;
471 dprintf_mdi(stddeb
,"MDI_ChildActivate: "NPFMT
"\n", hWndChild
);
473 if( GetActiveWindow() == clientPtr
->hwndParent
)
474 isActiveFrameWnd
= TRUE
;
476 /* deactivate prev. active child */
479 SendMessage( prevActiveWnd
, WM_NCACTIVATE
, FALSE
, 0L );
480 SendMessage( prevActiveWnd
, WM_MDIACTIVATE
, FALSE
,
481 MAKELONG(hWndChild
,prevActiveWnd
));
482 /* uncheck menu item */
483 if( clientInfo
->hWindowMenu
)
484 CheckMenuItem( clientInfo
->hWindowMenu
,
485 wndPrev
->wIDmenu
, 0);
489 if( clientInfo
->flagChildMaximized
)
490 if( clientInfo
->flagChildMaximized
!= hWndChild
)
493 clientInfo
->hwndActiveChild
= hWndChild
;
494 MDIMaximizeChild(GetParent(hWndChild
),hWndChild
,clientInfo
);
497 clientInfo
->hwndActiveChild
= hWndChild
;
499 /* check if we have any children left */
502 if( isActiveFrameWnd
)
503 SetFocus( GetParent(hWndChild
) );
507 /* check menu item */
508 if( clientInfo
->hWindowMenu
)
509 CheckMenuItem( clientInfo
->hWindowMenu
,
510 wndPtr
->wIDmenu
, MF_CHECKED
);
512 /* bring active child to the top */
513 SetWindowPos( hWndChild
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
515 if( isActiveFrameWnd
)
517 SendMessage( hWndChild
, WM_NCACTIVATE
, TRUE
, 0L);
518 if( GetFocus() == GetParent(hWndChild
) )
519 SendMessage( GetParent(hWndChild
), WM_SETFOCUS
,
520 GetParent(hWndChild
), 0L );
522 SetFocus( GetParent(hWndChild
) );
525 SendMessage( hWndChild
, WM_MDIACTIVATE
, TRUE
,
526 MAKELONG(prevActiveWnd
,hWndChild
) );
531 /**********************************************************************
534 * iTotal returns number of children available for tiling or cascading
536 MDIWCL
* MDI_BuildWCL(WND
* clientWnd
, int* iTotal
)
538 MDIWCL
*listTop
,*listNext
;
541 if (!(listTop
= (MDIWCL
*)malloc( sizeof(MDIWCL
) ))) return NULL
;
543 listTop
->hChild
= clientWnd
->hwndChild
;
544 listTop
->prev
= NULL
;
547 /* build linked list from top child to bottom */
549 childWnd
= WIN_FindWndPtr( listTop
->hChild
);
550 while( childWnd
&& childWnd
->hwndNext
)
552 listNext
= (MDIWCL
*)malloc(sizeof(MDIWCL
));
556 /* quit gracefully */
557 listNext
= listTop
->prev
;
560 listNext
= listTop
->prev
;
564 fprintf(stdnimp
,"MDICascade: allocation failed\n");
568 if( (childWnd
->dwStyle
& WS_DISABLED
) ||
569 (childWnd
->dwStyle
& WS_MINIMIZE
) ||
570 !(childWnd
->dwStyle
& WS_VISIBLE
) )
576 listNext
->hChild
= childWnd
->hwndNext
;
577 listNext
->prev
= listTop
;
581 childWnd
= WIN_FindWndPtr( childWnd
->hwndNext
);
584 if( (childWnd
->dwStyle
& WS_DISABLED
) ||
585 (childWnd
->dwStyle
& WS_MINIMIZE
) ||
586 !(childWnd
->dwStyle
& WS_VISIBLE
) )
595 /**********************************************************************
598 LONG
MDICascade(HWND parent
, MDICLIENTINFO
*ci
)
601 MDIWCL
*listTop
,*listPrev
;
603 int spacing
, xsize
, ysize
;
607 if (ci
->flagChildMaximized
)
608 MDIRestoreChild(parent
, ci
);
610 if (ci
->nActiveChildren
== 0) return 0;
612 GetClientRect(parent
, &rect
);
613 spacing
= GetSystemMetrics(SM_CYCAPTION
) + GetSystemMetrics(SM_CYFRAME
);
614 ysize
= rect
.bottom
- 8 * spacing
;
615 xsize
= rect
.right
- 8 * spacing
;
618 "MDICascade: Client wnd at (%ld,%ld) - (%ld,%ld), spacing %d\n",
619 (LONG
)rect
.left
, (LONG
)rect
.top
, (LONG
)rect
.right
, (LONG
)rect
.bottom
,
622 clientWnd
= WIN_FindWndPtr( parent
);
624 listTop
= MDI_BuildWCL(clientWnd
,&iToPosition
);
626 if( !listTop
) return 0;
631 /* walk list and move windows */
634 dprintf_mdi(stddeb
, "MDICascade: move "NPFMT
" to (%d,%d) size [%d,%d]\n",
635 listTop
->hChild
, x
, y
, xsize
, ysize
);
637 if( listTop
->hChild
)
639 SetWindowPos(listTop
->hChild
, 0, x
, y
, xsize
, ysize
,
640 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
646 listPrev
= listTop
->prev
;
654 /**********************************************************************
658 LONG
MDITile(HWND parent
, MDICLIENTINFO
*ci
)
660 WND
*wndClient
= WIN_FindWndPtr(parent
);
661 MDIWCL
*listTop
,*listPrev
;
670 if (ci
->flagChildMaximized
)
671 MDIRestoreChild(parent
, ci
);
673 if (ci
->nActiveChildren
== 0) return 0;
675 listTop
= MDI_BuildWCL(wndClient
, &iToPosition
);
677 dprintf_mdi(stddeb
,"MDITile: %i windows to tile\n",iToPosition
);
679 if( !listTop
) return 0;
681 GetClientRect(parent
, &rect
);
683 rows
= (int) sqrt((double) iToPosition
);
684 columns
= iToPosition
/ rows
;
687 if( iToPosition
!= ci
->nActiveChildren
)
689 y
= rect
.bottom
- 2 * SYSMETRICS_CYICONSPACING
- SYSMETRICS_CYICON
;
690 rect
.bottom
= ( y
- SYSMETRICS_CYICON
< rect
.top
)? rect
.bottom
: y
;
693 ysize
= rect
.bottom
/ rows
;
694 xsize
= rect
.right
/ columns
;
699 for (c
= 1; c
<= columns
; c
++)
703 rows
= iToPosition
- i
;
704 ysize
= rect
.bottom
/ rows
;
708 for (r
= 1; r
<= rows
; r
++, i
++)
710 /* shouldn't happen but... */
714 if( listTop
->hChild
)
716 SetWindowPos(listTop
->hChild
, 0, x
, y
, xsize
, ysize
,
717 SWP_DRAWFRAME
| SWP_NOACTIVATE
| SWP_NOZORDER
);
721 listPrev
= listTop
->prev
;
729 /* free the rest if any */
731 listPrev
= listTop
->prev
;
733 listTop
= listPrev
; }
738 /**********************************************************************
741 BOOL
MDIHandleLButton(HWND hwndFrame
, HWND hwndClient
,
742 WORD wParam
, LONG lParam
)
749 w
= WIN_FindWndPtr(hwndClient
);
750 ci
= (MDICLIENTINFO
*) w
->wExtra
;
752 if (wParam
== HTMENU
&& ci
->flagChildMaximized
)
756 NC_GetInsideRect(hwndFrame
, &rect
);
757 if (x
< rect
.left
+ SYSMETRICS_CXSIZE
)
759 SendMessage(ci
->hwndActiveChild
, WM_SYSCOMMAND
,
763 else if (x
>= rect
.right
- SYSMETRICS_CXSIZE
)
765 SendMessage(ci
->hwndActiveChild
, WM_SYSCOMMAND
,
774 /**********************************************************************
777 LONG
MDIPaintMaximized(HWND hwndFrame
, HWND hwndClient
, WORD message
,
778 WORD wParam
, LONG lParam
)
780 static HBITMAP hbitmapClose
= 0;
781 static HBITMAP hbitmapMaximized
= 0;
787 WND
*wndPtr
= WIN_FindWndPtr(hwndFrame
);
789 w
= WIN_FindWndPtr(hwndClient
);
790 ci
= (MDICLIENTINFO
*) w
->wExtra
;
792 dprintf_mdi(stddeb
, "MDIPaintMaximized: frame "NPFMT
", client "NPFMT
793 ", max flag %d, menu %04x\n", hwndFrame
, hwndClient
,
794 ci
->flagChildMaximized
, wndPtr
? wndPtr
->wIDmenu
: 0);
796 if (ci
->flagChildMaximized
&& wndPtr
&& wndPtr
->wIDmenu
!= 0)
798 NC_DoNCPaint(hwndFrame
, wParam
, TRUE
);
800 hdc
= GetDCEx(hwndFrame
, 0, DCX_CACHE
| DCX_WINDOW
);
803 hdcMem
= CreateCompatibleDC(hdc
);
805 if (hbitmapClose
== 0)
807 hbitmapClose
= LoadBitmap(0, MAKEINTRESOURCE(OBM_OLD_CLOSE
));
808 hbitmapMaximized
= LoadBitmap(0, MAKEINTRESOURCE(OBM_RESTORE
));
812 "MDIPaintMaximized: hdcMem "NPFMT
", close bitmap "NPFMT
", "
813 "maximized bitmap "NPFMT
"\n",
814 hdcMem
, hbitmapClose
, hbitmapMaximized
);
816 NC_GetInsideRect(hwndFrame
, &rect
);
817 rect
.top
+= (wndPtr
->dwStyle
& WS_CAPTION
) ? SYSMETRICS_CYSIZE
+ 1 : 0;
818 SelectObject(hdcMem
, hbitmapClose
);
819 BitBlt(hdc
, rect
.left
, rect
.top
+ 1,
820 SYSMETRICS_CXSIZE
, SYSMETRICS_CYSIZE
,
821 hdcMem
, 1, 1, SRCCOPY
);
823 NC_GetInsideRect(hwndFrame
, &rect
);
824 rect
.top
+= (wndPtr
->dwStyle
& WS_CAPTION
) ? SYSMETRICS_CYSIZE
+ 1 : 0;
825 rect
.left
= rect
.right
- SYSMETRICS_CXSIZE
;
826 SelectObject(hdcMem
, hbitmapMaximized
);
827 BitBlt(hdc
, rect
.left
, rect
.top
+ 1,
828 SYSMETRICS_CXSIZE
, SYSMETRICS_CYSIZE
,
829 hdcMem
, 1, 1, SRCCOPY
);
831 NC_GetInsideRect(hwndFrame
, &rect
);
832 rect
.top
+= (wndPtr
->dwStyle
& WS_CAPTION
) ? SYSMETRICS_CYSIZE
+ 1 : 0;
833 rect
.left
+= SYSMETRICS_CXSIZE
;
834 rect
.right
-= SYSMETRICS_CXSIZE
;
835 rect
.bottom
= rect
.top
+ SYSMETRICS_CYMENU
;
837 MENU_DrawMenuBar(hdc
, &rect
, hwndFrame
, FALSE
);
840 ReleaseDC(hwndFrame
, hdc
);
843 return DefWindowProc(hwndFrame
, message
, wParam
, lParam
);
848 /**********************************************************************
851 * This function is the handler for all MDI requests.
853 LRESULT
MDIClientWndProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
856 LPCLIENTCREATESTRUCT ccs
;
860 w
= WIN_FindWndPtr(hwnd
);
861 ci
= (MDICLIENTINFO
*) w
->wExtra
;
866 cs
= (LPCREATESTRUCT
) PTR_SEG_TO_LIN(lParam
);
867 ccs
= (LPCLIENTCREATESTRUCT
) PTR_SEG_TO_LIN(cs
->lpCreateParams
);
868 ci
->hWindowMenu
= ccs
->hWindowMenu
;
869 ci
->idFirstChild
= ccs
->idFirstChild
;
870 ci
->flagChildMaximized
= FALSE
;
873 w
->dwStyle
|= WS_CLIPCHILDREN
;
875 AppendMenu(ccs
->hWindowMenu
,MF_SEPARATOR
,0,NULL
);
877 GetClientRect(w
->hwndParent
, &ci
->rectMaximize
);
878 MoveWindow(hwnd
, 0, 0,
879 ci
->rectMaximize
.right
, ci
->rectMaximize
.bottom
, 1);
884 SetWindowPos(wParam
,0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
888 return MDICascade(hwnd
, ci
);
891 return (LONG
)MDICreateChild(w
, ci
, hwnd
, lParam
);
894 return MDIDestroyChild(w
, ci
, hwnd
, wParam
, TRUE
);
896 case WM_MDIGETACTIVE
:
897 return ((LONG
) ci
->hwndActiveChild
|
898 ((LONG
) (ci
->flagChildMaximized
>0) << 16));
900 case WM_MDIICONARRANGE
:
902 MDIIconArrange(hwnd
);
904 SendMessage(hwnd
,WM_MDICALCCHILDSCROLL
,0,0L);
908 return MDIMaximizeChild(hwnd
, wParam
, ci
);
911 MDI_SwitchActiveChild(hwnd
, (HWND
)wParam
, lParam
);
915 return MDIRestoreChild(hwnd
, ci
);
918 return MDISetMenu(hwnd
, wParam
, LOWORD(lParam
), HIWORD(lParam
));
922 ShowScrollBar(hwnd
,SB_BOTH
,FALSE
);
930 ScrollChildren(hwnd
,message
,wParam
,lParam
);
935 if( ci
->hwndActiveChild
)
937 w
= WIN_FindWndPtr( ci
->hwndActiveChild
);
938 if( !(w
->dwStyle
& WS_MINIMIZE
) )
939 SetFocus( ci
->hwndActiveChild
);
944 if( ci
->hwndActiveChild
)
945 SendMessage(ci
->hwndActiveChild
, message
, wParam
, lParam
);
948 case WM_PARENTNOTIFY
:
949 if (wParam
== WM_LBUTTONDOWN
)
950 SetWindowPos(ci
->hwndHitTest
, 0,0,0,0,0, SWP_NOSIZE
| SWP_NOMOVE
);
954 GetClientRect(w
->hwndParent
, &ci
->rectMaximize
);
955 if( !ci
->hwndActiveChild
)
957 PostMessage(hwnd
,WM_MDICALCCHILDSCROLL
,0,0L);
958 ci
->sbRecalc
|= (SB_BOTH
+1);
962 case WM_MDICALCCHILDSCROLL
:
966 CalcChildScroll(hwnd
, ci
->sbRecalc
-1);
972 return DefWindowProc(hwnd
, message
, wParam
, lParam
);
975 /**********************************************************************
976 * DefFrameProc (USER.445)
979 LRESULT
DefFrameProc(HWND hwnd
, HWND hwndMDIClient
, UINT message
,
980 WPARAM wParam
, LPARAM lParam
)
989 childHwnd
= MDI_GetChildByID( WIN_FindWndPtr(hwndMDIClient
),
992 SendMessage(hwndMDIClient
, WM_MDIACTIVATE
, childHwnd
, 0L);
995 case WM_NCLBUTTONDOWN
:
996 if (MDIHandleLButton(hwnd
, hwndMDIClient
, wParam
, lParam
))
1001 SendMessage(hwndMDIClient
, message
, wParam
, lParam
);
1002 return MDIPaintMaximized(hwnd
, hwndMDIClient
,
1003 message
, wParam
, lParam
);
1006 return MDIPaintMaximized(hwnd
, hwndMDIClient
,
1007 message
, wParam
, lParam
);
1010 SetFocus(hwndMDIClient
);
1014 MoveWindow(hwndMDIClient
, 0, 0,
1015 LOWORD(lParam
), HIWORD(lParam
), TRUE
);
1020 return DefWindowProc(hwnd
, message
, wParam
, lParam
);
1023 /**********************************************************************
1024 * DefMDIChildProc (USER.447)
1028 LONG
DefMDIChildProc(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1030 LONG
DefMDIChildProc(HWND hwnd
, WORD message
, WORD wParam
, LONG lParam
)
1036 clientWnd
= WIN_FindWndPtr(GetParent(hwnd
));
1037 ci
= (MDICLIENTINFO
*) clientWnd
->wExtra
;
1042 ci
->hwndHitTest
= hwnd
;
1046 DefWindowProc(hwnd
, message
, wParam
, lParam
);
1047 MDI_MenuModifyItem(clientWnd
,hwnd
);
1051 SendMessage(GetParent(hwnd
),WM_MDIDESTROY
,hwnd
,0L);
1055 if( ci
->hwndActiveChild
!= hwnd
)
1056 MDI_ChildActivate(clientWnd
, hwnd
);
1059 case WM_CHILDACTIVATE
:
1060 MDI_ChildActivate(clientWnd
, hwnd
);
1064 dprintf_mdi(stddeb
,"DefMDIChildProc: WM_NCPAINT for "NPFMT
", active "NPFMT
"\n",
1065 hwnd
, ci
->hwndActiveChild
);
1072 return SendMessage(GetParent(hwnd
), WM_MDIMAXIMIZE
, (WPARAM
)hwnd
, 0);
1075 return SendMessage(GetParent(hwnd
), WM_MDIRESTORE
, (WPARAM
)hwnd
, 0);
1079 /* should also handle following messages */
1080 case WM_GETMINMAXINFO
:
1081 /* should return rect of MDI client
1082 * so that normal ShowWindow will be able to handle
1083 * actions that are handled by MDIMaximize and MDIRestore */
1088 PostMessage(GetParent(hwnd
),WM_MDICALCCHILDSCROLL
,0,0L);
1089 ci
->sbRecalc
|= (SB_BOTH
+1);
1093 if( IsChild( GetActiveWindow(), GetParent(hwnd
)) )
1094 SendMessage(clientWnd
->hwndChild
,WM_CHILDACTIVATE
,0,0L);
1097 PostMessage(GetParent(hwnd
),WM_MDICALCCHILDSCROLL
,0,0L);
1098 ci
->sbRecalc
|= (SB_BOTH
+1);
1104 /* set current menu to child system menu */
1109 return DefWindowProc(hwnd
, message
, wParam
, lParam
);
1112 /**********************************************************************
1113 * TranslateMDISysAccel (USER.451)
1116 BOOL
TranslateMDISysAccel(HWND hwndClient
, LPMSG msg
)
1122 /***********************************************************************
1123 * CalcChildScroll (USER.462)
1125 void CalcChildScroll( HWND hwnd
, WORD scroll
)
1127 RECT childRect
, clientRect
;
1130 GetClientRect( hwnd
, &clientRect
);
1131 SetRectEmpty( &childRect
);
1132 hwndChild
= GetWindow( hwnd
, GW_CHILD
);
1135 WND
*wndPtr
= WIN_FindWndPtr( hwndChild
);
1136 UnionRect( &childRect
, &wndPtr
->rectWindow
, &childRect
);
1137 hwndChild
= wndPtr
->hwndNext
;
1139 UnionRect( &childRect
, &clientRect
, &childRect
);
1141 if ((scroll
== SB_HORZ
) || (scroll
== SB_BOTH
))
1143 SetScrollRange( hwnd
, SB_HORZ
, childRect
.left
,
1144 childRect
.right
- clientRect
.right
, FALSE
);
1145 SetScrollPos( hwnd
, SB_HORZ
, clientRect
.left
- childRect
.left
, TRUE
);
1147 if ((scroll
== SB_VERT
) || (scroll
== SB_BOTH
))
1149 SetScrollRange( hwnd
, SB_VERT
, childRect
.top
,
1150 childRect
.bottom
- clientRect
.bottom
, FALSE
);
1151 SetScrollPos( hwnd
, SB_HORZ
, clientRect
.top
- childRect
.top
, TRUE
);
1155 /***********************************************************************
1156 * ScrollChildren (USER.463)
1158 void ScrollChildren(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1160 WND
*wndPtr
= WIN_FindWndPtr(hWnd
);
1168 if( !wndPtr
) return;
1170 if( uMsg
== WM_HSCROLL
)
1172 GetScrollRange(hWnd
,SB_HORZ
,&minPos
,&maxPos
);
1173 curPos
= GetScrollPos(hWnd
,SB_HORZ
);
1174 length
= (wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
)/2;
1175 shift
= SYSMETRICS_CYHSCROLL
;
1177 else if( uMsg
== WM_VSCROLL
)
1179 GetScrollRange(hWnd
,SB_VERT
,&minPos
,&maxPos
);
1180 curPos
= GetScrollPos(hWnd
,SB_VERT
);
1181 length
= (wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
)/2;
1182 shift
= SYSMETRICS_CXVSCROLL
;
1189 newPos
= curPos
- shift
;
1192 newPos
= curPos
+ shift
;
1195 newPos
= curPos
- length
;
1198 newPos
= curPos
+ length
;
1201 case SB_THUMBPOSITION
:
1202 newPos
= LOWORD(lParam
);
1215 CalcChildScroll(hWnd
,(uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
);
1219 if( newPos
> maxPos
)
1221 else if( newPos
< minPos
)
1224 SetScrollPos(hWnd
, (uMsg
== WM_VSCROLL
)?SB_VERT
:SB_HORZ
, newPos
, TRUE
);
1226 if( uMsg
== WM_VSCROLL
)
1227 ScrollWindow(hWnd
,0 ,curPos
- newPos
, NULL
, NULL
);
1229 ScrollWindow(hWnd
,curPos
- newPos
, 0, NULL
, NULL
);