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.
21 #include "nonclient.h"
27 #include "sysmetrics.h"
30 #define MDIF_NEEDUPDATE 0x0001
32 static HBITMAP16 hBmpClose = 0;
33 static HBITMAP16 hBmpRestore = 0;
35 DWORD SCROLL_SetNCSbState(WND*,int,int,int,int,int,int);
37 /* ----------------- declarations ----------------- */
38 static void MDI_UpdateFrameText(WND *, HWND32, BOOL32, LPCSTR);
39 static BOOL32 MDI_AugmentFrameMenu(MDICLIENTINFO*, WND *, HWND32);
40 static BOOL32 MDI_RestoreFrameMenu(WND *, HWND32);
42 static LONG MDI_ChildActivate( WND*, HWND32 );
44 /* -------- Miscellaneous service functions ----------
49 static HWND32 MDI_GetChildByID(WND* wndPtr, INT32 id)
51 for (wndPtr = wndPtr->child; wndPtr; wndPtr = wndPtr->next)
52 if (wndPtr->wIDmenu == id) return wndPtr->hwndSelf;
56 static void MDI_PostUpdate(HWND32 hwnd, MDICLIENTINFO* ci, WORD recalc)
58 if( !(ci->mdiFlags & MDIF_NEEDUPDATE) )
60 ci->mdiFlags |= MDIF_NEEDUPDATE;
61 PostMessage32A( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
63 ci->sbRecalc = recalc;
66 /**********************************************************************
69 static BOOL32 MDI_MenuModifyItem(WND* clientWnd, HWND32 hWndChild )
72 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
73 WND *wndPtr = WIN_FindWndPtr(hWndChild);
74 UINT32 n = sprintf(buffer, "%d ",
75 wndPtr->wIDmenu - clientInfo->idFirstChild + 1);
78 if( !clientInfo->hWindowMenu ) return 0;
80 if (wndPtr->text) lstrcpyn32A(buffer + n, wndPtr->text, sizeof(buffer) - n );
82 n = GetMenuState32(clientInfo->hWindowMenu,wndPtr->wIDmenu ,MF_BYCOMMAND);
83 bRet = ModifyMenu32A(clientInfo->hWindowMenu , wndPtr->wIDmenu,
84 MF_BYCOMMAND | MF_STRING, wndPtr->wIDmenu, buffer );
85 CheckMenuItem32(clientInfo->hWindowMenu ,wndPtr->wIDmenu , n & MF_CHECKED);
89 /**********************************************************************
92 static BOOL32 MDI_MenuDeleteItem(WND* clientWnd, HWND32 hWndChild )
95 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
96 WND *wndPtr = WIN_FindWndPtr(hWndChild);
97 UINT32 index = 0,id,n;
99 if( !clientInfo->nActiveChildren ||
100 !clientInfo->hWindowMenu ) return 0;
102 id = wndPtr->wIDmenu;
103 DeleteMenu32(clientInfo->hWindowMenu,id,MF_BYCOMMAND);
105 /* walk the rest of MDI children to prevent gaps in the id
106 * sequence and in the menu child list */
108 for( index = id+1; index <= clientInfo->nActiveChildren +
109 clientInfo->idFirstChild; index++ )
111 wndPtr = WIN_FindWndPtr(MDI_GetChildByID(clientWnd,index));
114 TRACE(mdi,"no window for id=%i\n",index);
121 n = sprintf(buffer, "%d ",index - clientInfo->idFirstChild);
123 lstrcpyn32A(buffer + n, wndPtr->text, sizeof(buffer) - n );
126 ModifyMenu32A(clientInfo->hWindowMenu ,index ,MF_BYCOMMAND | MF_STRING,
127 index - 1 , buffer );
132 /**********************************************************************
135 * returns "activateable" child different from the current or zero
137 static HWND32 MDI_GetWindow(WND *clientWnd, HWND32 hWnd, BOOL32 bNext,
140 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
141 WND *wndPtr, *pWnd, *pWndLast = NULL;
143 dwStyleMask |= WS_DISABLED | WS_VISIBLE;
144 if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
146 if( !(wndPtr = WIN_FindWndPtr(hWnd)) ) return 0;
148 for ( pWnd = wndPtr->next; ; pWnd = pWnd->next )
150 if (!pWnd ) pWnd = wndPtr->parent->child;
152 if ( pWnd == wndPtr ) break; /* went full circle */
154 if (!pWnd->owner && (pWnd->dwStyle & dwStyleMask) == WS_VISIBLE )
160 return pWndLast ? pWndLast->hwndSelf : 0;
163 /**********************************************************************
164 * MDI_CalcDefaultChildPos
166 * It seems that the default height is about 2/3 of the client rect
168 static void MDI_CalcDefaultChildPos( WND* w, WORD n, LPPOINT32 lpPos,
172 RECT32 rect = w->rectClient;
173 INT32 spacing = GetSystemMetrics32(SM_CYCAPTION) +
174 GetSystemMetrics32(SM_CYFRAME) - 1;
176 if( rect.bottom - rect.top - delta >= spacing )
177 rect.bottom -= delta;
179 nstagger = (rect.bottom - rect.top)/(3 * spacing);
180 lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
181 lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
182 lpPos[0].x = lpPos[0].y = spacing * (n%(nstagger+1));
185 /**********************************************************************
188 static LRESULT MDISetMenu( HWND32 hwnd, HMENU32 hmenuFrame,
191 WND *w = WIN_FindWndPtr(hwnd);
193 HWND32 hwndFrame = GetParent32(hwnd);
194 HMENU32 oldFrameMenu = GetMenu32(hwndFrame);
196 TRACE(mdi, "%04x %04x %04x\n",
197 hwnd, hmenuFrame, hmenuWindow);
199 ci = (MDICLIENTINFO *) w->wExtra;
201 if( ci->hwndChildMaximized && hmenuFrame && hmenuFrame!=oldFrameMenu )
202 MDI_RestoreFrameMenu(w->parent, ci->hwndChildMaximized );
204 if( hmenuWindow && hmenuWindow!=ci->hWindowMenu )
206 /* delete menu items from ci->hWindowMenu
207 * and add them to hmenuWindow */
209 INT32 i = GetMenuItemCount32(ci->hWindowMenu) - 1;
210 INT32 pos = GetMenuItemCount32(hmenuWindow) + 1;
212 AppendMenu32A( hmenuWindow, MF_SEPARATOR, 0, NULL);
214 if( ci->nActiveChildren )
216 INT32 j = i - ci->nActiveChildren + 1;
220 for( ; i >= j ; i-- )
222 id = GetMenuItemID32(ci->hWindowMenu,i );
223 state = GetMenuState32(ci->hWindowMenu,i,MF_BYPOSITION);
225 GetMenuString32A(ci->hWindowMenu, i, buffer, 100, MF_BYPOSITION);
227 DeleteMenu32(ci->hWindowMenu, i , MF_BYPOSITION);
228 InsertMenu32A(hmenuWindow, pos, MF_BYPOSITION | MF_STRING,
230 CheckMenuItem32(hmenuWindow ,pos , MF_BYPOSITION | (state & MF_CHECKED));
234 /* remove separator */
235 DeleteMenu32(ci->hWindowMenu, i, MF_BYPOSITION);
237 ci->hWindowMenu = hmenuWindow;
240 if( hmenuFrame && hmenuFrame!=oldFrameMenu)
242 SetMenu32(hwndFrame, hmenuFrame);
243 if( ci->hwndChildMaximized )
244 MDI_AugmentFrameMenu(ci, w->parent, ci->hwndChildMaximized );
251 /* ------------------ MDI child window functions ---------------------- */
254 /**********************************************************************
257 static HWND32 MDICreateChild( WND *w, MDICLIENTINFO *ci, HWND32 parent,
258 LPMDICREATESTRUCT32A cs )
261 DWORD style = cs->style | (WS_CHILD | WS_CLIPSIBLINGS);
262 HWND32 hwnd, hwndMax = 0;
263 WORD wIDmenu = ci->idFirstChild + ci->nActiveChildren;
264 char lpstrDef[]="junk!";
266 TRACE(mdi, "origin %i,%i - dim %i,%i, style %08x\n",
267 cs->x, cs->y, cs->cx, cs->cy, (unsigned)cs->style);
268 /* calculate placement */
269 MDI_CalcDefaultChildPos(w, ci->nTotalCreated++, pos, 0);
271 if (cs->cx == CW_USEDEFAULT32 || !cs->cx) cs->cx = pos[1].x;
272 if (cs->cy == CW_USEDEFAULT32 || !cs->cy) cs->cy = pos[1].y;
274 if( cs->x == CW_USEDEFAULT32 )
280 /* restore current maximized child */
281 if( style & WS_VISIBLE && ci->hwndChildMaximized )
283 if( style & WS_MAXIMIZE )
284 SendMessage32A(w->hwndSelf, WM_SETREDRAW, FALSE, 0L );
285 hwndMax = ci->hwndChildMaximized;
286 ShowWindow32( hwndMax, SW_SHOWNOACTIVATE );
287 if( style & WS_MAXIMIZE )
288 SendMessage32A(w->hwndSelf, WM_SETREDRAW, TRUE, 0L );
291 /* this menu is needed to set a check mark in MDI_ChildActivate */
292 AppendMenu32A(ci->hWindowMenu ,MF_STRING ,wIDmenu, lpstrDef );
294 ci->nActiveChildren++;
296 /* fix window style */
297 if( !(w->dwStyle & MDIS_ALLCHILDSTYLES) )
299 style &= (WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZE | WS_MAXIMIZE |
300 WS_CLIPCHILDREN | WS_DISABLED | WS_VSCROLL | WS_HSCROLL );
301 style |= (WS_VISIBLE | WS_OVERLAPPEDWINDOW);
304 if( w->flags & WIN_ISWIN32 )
306 hwnd = CreateWindow32A( cs->szClass, cs->szTitle, style,
307 cs->x, cs->y, cs->cx, cs->cy, parent,
308 (HMENU16)wIDmenu, cs->hOwner, cs );
312 MDICREATESTRUCT16 *cs16;
315 cs16 = SEGPTR_NEW(MDICREATESTRUCT16);
316 STRUCT32_MDICREATESTRUCT32Ato16( cs, cs16 );
317 title = SEGPTR_STRDUP( cs->szTitle );
318 cls = SEGPTR_STRDUP( cs->szClass );
319 cs16->szTitle = SEGPTR_GET(title);
320 cs16->szClass = SEGPTR_GET(cls);
322 hwnd = CreateWindow16( cs->szClass, cs->szTitle, style,
323 cs16->x, cs16->y, cs16->cx, cs16->cy, parent,
324 (HMENU32)wIDmenu, cs16->hOwner,
325 (LPVOID)SEGPTR_GET(cs16) );
326 SEGPTR_FREE( title );
331 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
335 WND* wnd = WIN_FindWndPtr( hwnd );
337 MDI_MenuModifyItem(w ,hwnd);
338 if( wnd->dwStyle & WS_MINIMIZE && ci->hwndActiveChild )
339 ShowWindow32( hwnd, SW_SHOWMINNOACTIVE );
342 SetWindowPos32( hwnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE );
344 /* Set maximized state here in case hwnd didn't receive WM_SIZE
345 * during CreateWindow - bad!
348 if((wnd->dwStyle & WS_MAXIMIZE) && !ci->hwndChildMaximized )
350 ci->hwndChildMaximized = wnd->hwndSelf;
351 MDI_AugmentFrameMenu( ci, w->parent, hwnd );
352 MDI_UpdateFrameText( w->parent, ci->self, MDI_REPAINTFRAME, NULL );
355 TRACE(mdi, "created child - %04x\n",hwnd);
359 ci->nActiveChildren--;
360 DeleteMenu32(ci->hWindowMenu,wIDmenu,MF_BYCOMMAND);
361 if( IsWindow32(hwndMax) )
362 ShowWindow32(hwndMax, SW_SHOWMAXIMIZED);
368 /**********************************************************************
369 * MDI_ChildGetMinMaxInfo
371 * Note: The rule here is that client rect of the maximized MDI child
372 * is equal to the client rect of the MDI client window.
374 static void MDI_ChildGetMinMaxInfo( WND* clientWnd, HWND32 hwnd,
375 MINMAXINFO16* lpMinMax )
377 WND* childWnd = WIN_FindWndPtr(hwnd);
378 RECT32 rect = clientWnd->rectClient;
380 MapWindowPoints32( clientWnd->parent->hwndSelf,
381 ((MDICLIENTINFO*)clientWnd->wExtra)->self, (LPPOINT32)&rect, 2);
382 AdjustWindowRectEx32( &rect, childWnd->dwStyle, 0, childWnd->dwExStyle );
384 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
385 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
387 lpMinMax->ptMaxPosition.x = rect.left;
388 lpMinMax->ptMaxPosition.y = rect.top;
390 TRACE(mdi,"max rect (%i,%i - %i, %i)\n",
391 rect.left,rect.top,rect.right,rect.bottom);
394 /**********************************************************************
395 * MDI_SwitchActiveChild
397 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
400 static void MDI_SwitchActiveChild( HWND32 clientHwnd, HWND32 childHwnd,
403 WND *w = WIN_FindWndPtr(clientHwnd);
408 hwndTo = MDI_GetWindow(w, childHwnd, bNextWindow, 0);
410 ci = (MDICLIENTINFO *) w->wExtra;
412 TRACE(mdi, "from %04x, to %04x\n",childHwnd,hwndTo);
414 if ( !hwndTo ) return; /* no window to switch to */
416 hwndPrev = ci->hwndActiveChild;
418 if ( hwndTo != hwndPrev )
420 BOOL32 bOptimize = 0;
422 if( ci->hwndChildMaximized )
425 w->dwStyle &= ~WS_VISIBLE;
428 SetWindowPos32( hwndTo, HWND_TOP, 0, 0, 0, 0,
429 SWP_NOMOVE | SWP_NOSIZE );
431 if( bNextWindow && hwndPrev )
432 SetWindowPos32( hwndPrev, HWND_BOTTOM, 0, 0, 0, 0,
433 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
435 ShowWindow32( clientHwnd, SW_SHOW );
440 /**********************************************************************
443 static LRESULT MDIDestroyChild( WND *w_parent, MDICLIENTINFO *ci,
444 HWND32 parent, HWND32 child,
447 WND *childPtr = WIN_FindWndPtr(child);
451 if( child == ci->hwndActiveChild )
453 MDI_SwitchActiveChild(parent, child, TRUE);
455 if( child == ci->hwndActiveChild )
457 ShowWindow32( child, SW_HIDE);
458 if( child == ci->hwndChildMaximized )
460 MDI_RestoreFrameMenu(w_parent->parent, child);
461 ci->hwndChildMaximized = 0;
462 MDI_UpdateFrameText(w_parent->parent,parent,TRUE,NULL);
465 MDI_ChildActivate(w_parent, 0);
467 MDI_MenuDeleteItem(w_parent, child);
470 ci->nActiveChildren--;
472 TRACE(mdi,"child destroyed - %04x\n",child);
476 MDI_PostUpdate(GetParent32(child), ci, SB_BOTH+1);
477 DestroyWindow32(child);
485 /**********************************************************************
488 * Note: hWndChild is NULL when last child is being destroyed
490 static LONG MDI_ChildActivate( WND *clientPtr, HWND32 hWndChild )
492 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientPtr->wExtra;
493 HWND32 prevActiveWnd = clientInfo->hwndActiveChild;
494 WND *wndPtr = WIN_FindWndPtr( hWndChild );
495 WND *wndPrev = WIN_FindWndPtr( prevActiveWnd );
496 BOOL32 isActiveFrameWnd = 0;
498 if( hWndChild == prevActiveWnd ) return 0L;
501 if( wndPtr->dwStyle & WS_DISABLED ) return 0L;
503 TRACE(mdi,"%04x\n", hWndChild);
505 if( GetActiveWindow32() == clientPtr->parent->hwndSelf )
506 isActiveFrameWnd = TRUE;
508 /* deactivate prev. active child */
511 wndPrev->dwStyle |= WS_SYSMENU;
512 SendMessage32A( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
513 SendMessage32A( prevActiveWnd, WM_MDIACTIVATE, (WPARAM32)prevActiveWnd,
515 /* uncheck menu item */
516 if( clientInfo->hWindowMenu )
517 CheckMenuItem32( clientInfo->hWindowMenu,
518 wndPrev->wIDmenu, 0);
522 if( clientInfo->hwndChildMaximized )
523 if( clientInfo->hwndChildMaximized != hWndChild )
526 clientInfo->hwndActiveChild = hWndChild;
527 ShowWindow32( hWndChild, SW_SHOWMAXIMIZED);
530 ShowWindow32( clientInfo->hwndActiveChild, SW_SHOWNORMAL );
532 clientInfo->hwndActiveChild = hWndChild;
534 /* check if we have any children left */
537 if( isActiveFrameWnd )
538 SetFocus32( clientInfo->self );
542 /* check menu item */
543 if( clientInfo->hWindowMenu )
544 CheckMenuItem32( clientInfo->hWindowMenu,
545 wndPtr->wIDmenu, MF_CHECKED);
547 /* bring active child to the top */
548 SetWindowPos32( hWndChild, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
550 if( isActiveFrameWnd )
552 SendMessage32A( hWndChild, WM_NCACTIVATE, TRUE, 0L);
553 if( GetFocus32() == clientInfo->self )
554 SendMessage32A( clientInfo->self, WM_SETFOCUS,
555 (WPARAM32)clientInfo->self, 0L );
557 SetFocus32( clientInfo->self );
559 SendMessage32A( hWndChild, WM_MDIACTIVATE, (WPARAM32)prevActiveWnd,
564 /* -------------------- MDI client window functions ------------------- */
566 /**********************************************************************
567 * CreateMDIMenuBitmap
569 static HBITMAP16 CreateMDIMenuBitmap(void)
571 HDC32 hDCSrc = CreateCompatibleDC32(0);
572 HDC32 hDCDest = CreateCompatibleDC32(hDCSrc);
573 HBITMAP16 hbClose = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_CLOSE) );
575 HANDLE16 hobjSrc, hobjDest;
577 hobjSrc = SelectObject32(hDCSrc, hbClose);
578 hbCopy = CreateCompatibleBitmap32(hDCSrc,SYSMETRICS_CXSIZE,SYSMETRICS_CYSIZE);
579 hobjDest = SelectObject32(hDCDest, hbCopy);
581 BitBlt32(hDCDest, 0, 0, SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE,
582 hDCSrc, SYSMETRICS_CXSIZE, 0, SRCCOPY);
584 SelectObject32(hDCSrc, hobjSrc);
585 DeleteObject32(hbClose);
588 hobjSrc = SelectObject32( hDCDest, GetStockObject32(BLACK_PEN) );
590 MoveToEx32( hDCDest, SYSMETRICS_CXSIZE - 1, 0, NULL );
591 LineTo32( hDCDest, SYSMETRICS_CXSIZE - 1, SYSMETRICS_CYSIZE - 1);
593 SelectObject32(hDCDest, hobjSrc );
594 SelectObject32(hDCDest, hobjDest);
600 /**********************************************************************
603 static LONG MDICascade(WND* clientWnd, MDICLIENTINFO *ci)
608 if (ci->hwndChildMaximized)
609 ShowWindow16( ci->hwndChildMaximized, SW_NORMAL);
611 if (ci->nActiveChildren == 0) return 0;
613 if ((ppWnd = WIN_BuildWinArray(clientWnd, BWA_SKIPHIDDEN | BWA_SKIPOWNED |
614 BWA_SKIPICONIC, &total)))
616 WND** heapPtr = ppWnd;
619 INT32 delta = 0, n = 0;
621 if( total < ci->nActiveChildren )
622 delta = SYSMETRICS_CYICONSPACING + SYSMETRICS_CYICON;
624 /* walk the list and move windows */
627 TRACE(mdi, "move %04x to (%d,%d) size [%d,%d]\n",
628 (*ppWnd)->hwndSelf, pos[0].x, pos[0].y, pos[1].x, pos[1].y);
630 MDI_CalcDefaultChildPos(clientWnd, n++, pos, delta);
631 SetWindowPos32( (*ppWnd)->hwndSelf, 0, pos[0].x, pos[0].y,
633 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
637 HeapFree( SystemHeap, 0, heapPtr );
640 if( total < ci->nActiveChildren )
641 ArrangeIconicWindows32( clientWnd->hwndSelf );
645 /**********************************************************************
648 static void MDITile( WND* wndClient, MDICLIENTINFO *ci, WPARAM32 wParam )
653 if (ci->hwndChildMaximized)
654 ShowWindow32(ci->hwndChildMaximized, SW_NORMAL);
656 if (ci->nActiveChildren == 0) return;
658 ppWnd = WIN_BuildWinArray(wndClient, BWA_SKIPHIDDEN | BWA_SKIPOWNED | BWA_SKIPICONIC |
659 ((wParam & MDITILE_SKIPDISABLED)? BWA_SKIPDISABLED : 0), &total );
661 TRACE(mdi,"%u windows to tile\n", total);
665 WND** heapPtr = ppWnd;
670 int x, y, xsize, ysize;
671 int rows, columns, r, c, i;
673 rect = wndClient->rectClient;
674 rows = (int) sqrt((double)total);
675 columns = total / rows;
677 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
680 rows = columns; /* exchange r and c */
684 if( total != ci->nActiveChildren)
686 y = rect.bottom - 2 * SYSMETRICS_CYICONSPACING - SYSMETRICS_CYICON;
687 rect.bottom = ( y - SYSMETRICS_CYICON < rect.top )? rect.bottom: y;
690 ysize = rect.bottom / rows;
691 xsize = rect.right / columns;
693 for (x = i = 0, c = 1; c <= columns && *ppWnd; c++)
698 ysize = rect.bottom / rows;
702 for (r = 1; r <= rows && *ppWnd; r++, i++)
704 SetWindowPos32((*ppWnd)->hwndSelf, 0, x, y, xsize, ysize,
705 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
712 HeapFree( SystemHeap, 0, heapPtr );
715 if( total < ci->nActiveChildren ) ArrangeIconicWindows32( wndClient->hwndSelf );
718 /* ----------------------- Frame window ---------------------------- */
721 /**********************************************************************
722 * MDI_AugmentFrameMenu
724 static BOOL32 MDI_AugmentFrameMenu( MDICLIENTINFO* ci, WND *frame,
727 WND* child = WIN_FindWndPtr(hChild);
728 HMENU32 hSysPopup = 0;
730 TRACE(mdi,"frame %p,child %04x\n",frame,hChild);
732 if( !frame->wIDmenu || !child->hSysMenu ) return 0;
734 /* create a copy of sysmenu popup and insert it into frame menu bar */
736 if (!(hSysPopup = LoadMenuIndirect32A(SYSRES_GetResPtr(SYSRES_MENU_SYSMENU))))
739 TRACE(mdi,"\tgot popup %04x in sysmenu %04x\n",
740 hSysPopup, child->hSysMenu);
742 if( !InsertMenu32A(frame->wIDmenu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
743 hSysPopup, (LPSTR)(DWORD)hBmpClose ))
745 DestroyMenu32(hSysPopup);
749 if( !AppendMenu32A(frame->wIDmenu,MF_HELP | MF_BITMAP,
750 SC_RESTORE, (LPSTR)(DWORD)hBmpRestore ))
752 RemoveMenu32(frame->wIDmenu,0,MF_BYPOSITION);
756 EnableMenuItem32(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
757 EnableMenuItem32(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
758 EnableMenuItem32(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
761 DrawMenuBar32(frame->hwndSelf);
766 /**********************************************************************
767 * MDI_RestoreFrameMenu
769 static BOOL32 MDI_RestoreFrameMenu( WND *frameWnd, HWND32 hChild )
771 INT32 nItems = GetMenuItemCount32(frameWnd->wIDmenu) - 1;
773 TRACE(mdi,"for child %04x\n",hChild);
775 if( GetMenuItemID32(frameWnd->wIDmenu,nItems) != SC_RESTORE )
778 RemoveMenu32(frameWnd->wIDmenu,0,MF_BYPOSITION);
779 DeleteMenu32(frameWnd->wIDmenu,nItems-1,MF_BYPOSITION);
781 DrawMenuBar32(frameWnd->hwndSelf);
786 /**********************************************************************
787 * MDI_UpdateFrameText
789 * used when child window is maximized/restored
791 * Note: lpTitle can be NULL
793 static void MDI_UpdateFrameText( WND *frameWnd, HWND32 hClient,
794 BOOL32 repaint, LPCSTR lpTitle )
796 char lpBuffer[MDI_MAXTITLELENGTH+1];
797 WND* clientWnd = WIN_FindWndPtr(hClient);
798 MDICLIENTINFO *ci = (MDICLIENTINFO *) clientWnd->wExtra;
800 TRACE(mdi, "repaint %i, frameText %s\n", repaint, (lpTitle)?lpTitle:"NULL");
808 /* store new "default" title if lpTitle is not NULL */
811 if (ci->frameTitle) HeapFree( SystemHeap, 0, ci->frameTitle );
812 ci->frameTitle = HEAP_strdupA( SystemHeap, 0, lpTitle );
817 WND* childWnd = WIN_FindWndPtr( ci->hwndChildMaximized );
819 if( childWnd && childWnd->text )
821 /* combine frame title and child title if possible */
823 LPCSTR lpBracket = " - [";
824 int i_frame_text_length = strlen(ci->frameTitle);
825 int i_child_text_length = strlen(childWnd->text);
827 lstrcpyn32A( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
829 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
831 strcat( lpBuffer, lpBracket );
833 if( i_frame_text_length + i_child_text_length + 6 < MDI_MAXTITLELENGTH )
835 strcat( lpBuffer, childWnd->text );
836 strcat( lpBuffer, "]" );
840 lstrcpyn32A( lpBuffer + i_frame_text_length + 4,
841 childWnd->text, MDI_MAXTITLELENGTH - i_frame_text_length - 5 );
842 strcat( lpBuffer, "]" );
848 strncpy(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH );
849 lpBuffer[MDI_MAXTITLELENGTH]='\0';
855 DEFWND_SetText( frameWnd, lpBuffer );
856 if( repaint == MDI_REPAINTFRAME)
857 SetWindowPos32( frameWnd->hwndSelf, 0,0,0,0,0, SWP_FRAMECHANGED |
858 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
862 /* ----------------------------- Interface ---------------------------- */
865 /**********************************************************************
868 * This function handles all MDI requests.
870 LRESULT WINAPI MDIClientWndProc( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
873 LPCREATESTRUCT32A cs;
876 WND *w = WIN_FindWndPtr(hwnd);
877 WND *frameWnd = w->parent;
880 ci = (MDICLIENTINFO *) w->wExtra;
886 cs = (LPCREATESTRUCT32A)lParam;
888 /* Translation layer doesn't know what's in the cs->lpCreateParams
889 * so we have to keep track of what environment we're in. */
891 if( w->flags & WIN_ISWIN32 )
893 #define ccs ((LPCLIENTCREATESTRUCT32)cs->lpCreateParams)
894 ci->hWindowMenu = ccs->hWindowMenu;
895 ci->idFirstChild = ccs->idFirstChild;
900 LPCLIENTCREATESTRUCT16 ccs = (LPCLIENTCREATESTRUCT16)
901 PTR_SEG_TO_LIN(cs->lpCreateParams);
902 ci->hWindowMenu = ccs->hWindowMenu;
903 ci->idFirstChild = ccs->idFirstChild;
906 ci->hwndChildMaximized = 0;
907 ci->nActiveChildren = 0;
908 ci->nTotalCreated = 0;
909 ci->frameTitle = NULL;
912 w->dwStyle |= WS_CLIPCHILDREN;
916 hBmpClose = CreateMDIMenuBitmap();
917 hBmpRestore = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_RESTORE) );
919 MDI_UpdateFrameText(frameWnd, hwnd, MDI_NOFRAMEREPAINT,frameWnd->text);
921 AppendMenu32A( ci->hWindowMenu, MF_SEPARATOR, 0, NULL );
923 GetClientRect32(frameWnd->hwndSelf, &rect);
924 NC_HandleNCCalcSize( w, &rect );
925 w->rectClient = rect;
927 TRACE(mdi,"Client created - hwnd = %04x, idFirst = %u\n",
928 hwnd, ci->idFirstChild );
933 if( ci->hwndChildMaximized ) MDI_RestoreFrameMenu(w, frameWnd->hwndSelf);
934 if((nItems = GetMenuItemCount32(ci->hWindowMenu)) > 0)
936 ci->idFirstChild = nItems - 1;
937 ci->nActiveChildren++; /* to delete a separator */
938 while( ci->nActiveChildren-- )
939 DeleteMenu32(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
944 if( ci->hwndActiveChild != (HWND32)wParam )
945 SetWindowPos32((HWND32)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
949 return MDICascade(w, ci);
952 if (lParam) return MDICreateChild( w, ci, hwnd,
953 (MDICREATESTRUCT32A*)lParam );
957 return MDIDestroyChild( w, ci, hwnd, (HWND32)wParam, TRUE );
959 case WM_MDIGETACTIVE:
960 if (lParam) *(BOOL32 *)lParam = (ci->hwndChildMaximized > 0);
961 return ci->hwndActiveChild;
963 case WM_MDIICONARRANGE:
964 ci->mdiFlags |= MDIF_NEEDUPDATE;
965 ArrangeIconicWindows32(hwnd);
966 ci->sbRecalc = SB_BOTH+1;
967 SendMessage32A(hwnd, WM_MDICALCCHILDSCROLL, 0, 0L);
971 ShowWindow32( (HWND32)wParam, SW_MAXIMIZE );
974 case WM_MDINEXT: /* lParam != 0 means previous window */
975 MDI_SwitchActiveChild(hwnd, (HWND32)wParam, (lParam)? FALSE : TRUE );
979 ShowWindow32( (HWND32)wParam, SW_NORMAL);
983 return MDISetMenu( hwnd, (HMENU32)wParam, (HMENU32)lParam );
986 ci->mdiFlags |= MDIF_NEEDUPDATE;
987 ShowScrollBar32(hwnd,SB_BOTH,FALSE);
988 MDITile(w, ci, wParam);
989 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
994 ci->mdiFlags |= MDIF_NEEDUPDATE;
995 ScrollChildren32(hwnd, message, wParam, lParam);
996 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1000 if( ci->hwndActiveChild )
1002 w = WIN_FindWndPtr( ci->hwndActiveChild );
1003 if( !(w->dwStyle & WS_MINIMIZE) )
1004 SetFocus32( ci->hwndActiveChild );
1009 if( ci->hwndActiveChild )
1010 SendMessage32A(ci->hwndActiveChild, message, wParam, lParam);
1013 case WM_PARENTNOTIFY:
1014 if (LOWORD(wParam) == WM_LBUTTONDOWN)
1016 POINT16 pt = MAKEPOINT16(lParam);
1017 HWND16 child = ChildWindowFromPoint16(hwnd, pt);
1019 TRACE(mdi,"notification from %04x (%i,%i)\n",child,pt.x,pt.y);
1021 if( child && child != hwnd && child != ci->hwndActiveChild )
1022 SetWindowPos32(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1027 if( ci->hwndChildMaximized )
1029 WND* child = WIN_FindWndPtr(ci->hwndChildMaximized);
1030 RECT32 rect = { 0, 0, LOWORD(lParam), HIWORD(lParam) };
1032 AdjustWindowRectEx32(&rect, child->dwStyle, 0, child->dwExStyle);
1033 MoveWindow32(ci->hwndChildMaximized, rect.left, rect.top,
1034 rect.right - rect.left, rect.bottom - rect.top, 1);
1037 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1041 case WM_MDICALCCHILDSCROLL:
1042 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1044 CalcChildScroll(hwnd, ci->sbRecalc-1);
1046 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1051 return DefWindowProc32A( hwnd, message, wParam, lParam );
1055 /***********************************************************************
1056 * DefFrameProc16 (USER.445)
1058 LRESULT WINAPI DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient,
1059 UINT16 message, WPARAM16 wParam, LPARAM lParam )
1070 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1071 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1073 /* check for possible syscommands for maximized MDI child */
1076 wParam < ci->idFirstChild ||
1077 wParam >= ci->idFirstChild + ci->nActiveChildren
1079 if( (wParam - 0xF000) & 0xF00F ) break;
1090 if( ci->hwndChildMaximized )
1091 return SendMessage16( ci->hwndChildMaximized, WM_SYSCOMMAND,
1097 childHwnd = MDI_GetChildByID( WIN_FindWndPtr(hwndMDIClient),
1100 SendMessage16(hwndMDIClient, WM_MDIACTIVATE,
1101 (WPARAM16)childHwnd , 0L);
1106 SendMessage16(hwndMDIClient, message, wParam, lParam);
1110 MDI_UpdateFrameText(WIN_FindWndPtr(hwnd), hwndMDIClient,
1112 (LPCSTR)PTR_SEG_TO_LIN(lParam));
1116 SetFocus32(hwndMDIClient);
1120 MoveWindow16(hwndMDIClient, 0, 0,
1121 LOWORD(lParam), HIWORD(lParam), TRUE);
1126 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1127 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1129 if( !(wndPtr->parent->dwStyle & WS_MINIMIZE)
1130 && ci->hwndActiveChild && !ci->hwndChildMaximized )
1132 /* control menu is between the frame system menu and
1133 * the first entry of menu bar */
1135 if( (wParam == VK_LEFT &&
1136 wndPtr->parent->wIDmenu == LOWORD(lParam)) ||
1137 (wParam == VK_RIGHT &&
1138 GetSubMenu16(wndPtr->parent->hSysMenu, 0) == LOWORD(lParam)) )
1140 wndPtr = WIN_FindWndPtr(ci->hwndActiveChild);
1141 return MAKELONG( GetSubMenu16(wndPtr->hSysMenu, 0),
1142 ci->hwndActiveChild);
1149 return DefWindowProc16(hwnd, message, wParam, lParam);
1153 /***********************************************************************
1154 * DefFrameProc32A (USER32.122)
1156 LRESULT WINAPI DefFrameProc32A( HWND32 hwnd, HWND32 hwndMDIClient,
1157 UINT32 message, WPARAM32 wParam, LPARAM lParam)
1164 return DefFrameProc16( hwnd, hwndMDIClient, message,
1166 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1169 SendMessage32A(hwndMDIClient, message, wParam, lParam);
1174 LPSTR segstr = SEGPTR_STRDUP((LPSTR)lParam);
1176 ret = DefFrameProc16(hwnd, hwndMDIClient, message,
1177 wParam, (LPARAM)SEGPTR_GET(segstr) );
1178 SEGPTR_FREE(segstr);
1184 return DefFrameProc16( hwnd, hwndMDIClient, message,
1189 return DefWindowProc32A(hwnd, message, wParam, lParam);
1193 /***********************************************************************
1194 * DefFrameProc32W (USER32.123)
1196 LRESULT WINAPI DefFrameProc32W( HWND32 hwnd, HWND32 hwndMDIClient,
1197 UINT32 message, WPARAM32 wParam, LPARAM lParam)
1204 return DefFrameProc16( hwnd, hwndMDIClient, message,
1206 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1209 SendMessage32W(hwndMDIClient, message, wParam, lParam);
1214 LPSTR txt = HEAP_strdupWtoA(GetProcessHeap(),0,(LPWSTR)lParam);
1215 LRESULT ret = DefFrameProc32A( hwnd, hwndMDIClient, message,
1216 wParam, (DWORD)txt );
1217 HeapFree(GetProcessHeap(),0,txt);
1222 return DefFrameProc32A( hwnd, hwndMDIClient, message,
1227 return DefWindowProc32W( hwnd, message, wParam, lParam );
1231 /***********************************************************************
1232 * DefMDIChildProc16 (USER.447)
1234 LRESULT WINAPI DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1235 WPARAM16 wParam, LPARAM lParam )
1240 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1241 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1246 DefWindowProc16(hwnd, message, wParam, lParam);
1247 MDI_MenuModifyItem(clientWnd,hwnd);
1248 if( ci->hwndChildMaximized == hwnd )
1249 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1250 MDI_REPAINTFRAME, NULL );
1254 SendMessage16(ci->self,WM_MDIDESTROY,(WPARAM16)hwnd,0L);
1258 if( ci->hwndActiveChild != hwnd )
1259 MDI_ChildActivate(clientWnd, hwnd);
1262 case WM_CHILDACTIVATE:
1263 MDI_ChildActivate(clientWnd, hwnd);
1267 TRACE(mdi,"WM_NCPAINT for %04x, active %04x\n",
1268 hwnd, ci->hwndActiveChild );
1275 if( ci->hwndChildMaximized == hwnd) return 0;
1279 WIN_FindWndPtr(hwnd)->dwStyle |= WS_SYSMENU;
1282 if( ci->hwndChildMaximized == hwnd)
1283 return SendMessage16( clientWnd->parent->hwndSelf,
1284 message, wParam, lParam);
1285 WIN_FindWndPtr(hwnd)->dwStyle &= ~WS_SYSMENU;
1288 SendMessage16( ci->self, WM_MDINEXT, 0, 0);
1291 SendMessage16( ci->self, WM_MDINEXT, 0, 1);
1296 case WM_GETMINMAXINFO:
1297 MDI_ChildGetMinMaxInfo(clientWnd, hwnd, (MINMAXINFO16*) PTR_SEG_TO_LIN(lParam));
1301 if( ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1303 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1309 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1311 ci->hwndChildMaximized = 0;
1313 MDI_RestoreFrameMenu( clientWnd->parent, hwnd);
1314 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1315 MDI_REPAINTFRAME, NULL );
1318 if( wParam == SIZE_MAXIMIZED )
1320 HWND16 hMaxChild = ci->hwndChildMaximized;
1322 if( hMaxChild == hwnd ) break;
1326 SendMessage16( hMaxChild, WM_SETREDRAW, FALSE, 0L );
1328 MDI_RestoreFrameMenu( clientWnd->parent, hMaxChild);
1329 ShowWindow16( hMaxChild, SW_SHOWNOACTIVATE);
1331 SendMessage16( hMaxChild, WM_SETREDRAW, TRUE, 0L );
1334 TRACE(mdi,"maximizing child %04x\n", hwnd );
1336 ci->hwndChildMaximized = hwnd; /* !!! */
1338 MDI_AugmentFrameMenu( ci, clientWnd->parent, hwnd);
1339 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1340 MDI_REPAINTFRAME, NULL );
1343 if( wParam == SIZE_MINIMIZED )
1345 HWND16 switchTo = MDI_GetWindow(clientWnd, hwnd, TRUE, WS_MINIMIZE);
1348 SendMessage16( switchTo, WM_CHILDACTIVATE, 0, 0L);
1351 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1356 /* MDI children don't have menu bars */
1357 PostMessage16( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1358 (WPARAM16)SC_KEYMENU, (LPARAM)wParam);
1363 if( wParam == VK_LEFT ) /* switch to frame system menu */
1364 return MAKELONG( GetSubMenu16(clientWnd->parent->hSysMenu, 0),
1365 clientWnd->parent->hwndSelf );
1366 if( wParam == VK_RIGHT ) /* to frame menu bar */
1367 return MAKELONG( clientWnd->parent->wIDmenu,
1368 clientWnd->parent->hwndSelf );
1373 return DefWindowProc16(hwnd, message, wParam, lParam);
1377 /***********************************************************************
1378 * DefMDIChildProc32A (USER32.124)
1380 LRESULT WINAPI DefMDIChildProc32A( HWND32 hwnd, UINT32 message,
1381 WPARAM32 wParam, LPARAM lParam )
1386 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1387 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1392 DefWindowProc32A(hwnd, message, wParam, lParam);
1393 MDI_MenuModifyItem(clientWnd,hwnd);
1394 if( ci->hwndChildMaximized == hwnd )
1395 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1396 MDI_REPAINTFRAME, NULL );
1399 case WM_GETMINMAXINFO:
1402 STRUCT32_MINMAXINFO32to16( (MINMAXINFO32 *)lParam, &mmi );
1403 MDI_ChildGetMinMaxInfo( clientWnd, hwnd, &mmi );
1404 STRUCT32_MINMAXINFO16to32( &mmi, (MINMAXINFO32 *)lParam );
1410 /* MDI children don't have menu bars */
1411 PostMessage16( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1412 (WPARAM16)SC_KEYMENU, (LPARAM)LOWORD(wParam) );
1417 case WM_CHILDACTIVATE:
1423 return DefMDIChildProc16( hwnd, message, (WPARAM16)wParam, lParam );
1425 return DefWindowProc32A(hwnd, message, wParam, lParam);
1429 /***********************************************************************
1430 * DefMDIChildProc32W (USER32.125)
1432 LRESULT WINAPI DefMDIChildProc32W( HWND32 hwnd, UINT32 message,
1433 WPARAM32 wParam, LPARAM lParam )
1438 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1439 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1444 DefWindowProc32W(hwnd, message, wParam, lParam);
1445 MDI_MenuModifyItem(clientWnd,hwnd);
1446 if( ci->hwndChildMaximized == hwnd )
1447 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1448 MDI_REPAINTFRAME, NULL );
1451 case WM_GETMINMAXINFO:
1455 case WM_CHILDACTIVATE:
1461 return DefMDIChildProc32A( hwnd, message, (WPARAM16)wParam, lParam );
1463 return DefWindowProc32W(hwnd, message, wParam, lParam);
1467 /**********************************************************************
1468 * CreateMDIWindowA [USER32.79]
1470 HWND32 WINAPI CreateMDIWindowA(
1472 LPCSTR lpWindowName,
1479 HINSTANCE32 hInstance,
1482 FIXME(mdi, "(%s,%s,%ld,...): stub\n",debugstr_a(lpClassName),
1483 debugstr_a(lpWindowName),dwStyle);
1484 return (HWND32)NULL;
1488 /******************************************************************************
1489 * CreateMDIWindowW [USER32.80] Creates a MDI child window
1492 * Success: Handle to created window
1495 HWND32 WINAPI CreateMDIWindowW(
1496 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1497 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1498 DWORD dwStyle, /* [in] Window style */
1499 INT32 X, /* [in] Horizontal position of window */
1500 INT32 Y, /* [in] Vertical position of window */
1501 INT32 nWidth, /* [in] Width of window */
1502 INT32 nHeight, /* [in] Height of window */
1503 HWND32 hWndParent, /* [in] Handle to parent window */
1504 HINSTANCE32 hInstance, /* [in] Handle to application instance */
1505 LPARAM lParam) /* [in] Application-defined value */
1507 FIXME(mdi, "(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld): stub\n",
1508 debugstr_w(lpClassName),debugstr_w(lpWindowName),dwStyle,X,Y,
1509 nWidth,nHeight,hWndParent,hInstance,lParam);
1510 return (HWND32)NULL;
1514 /**********************************************************************
1515 * TranslateMDISysAccel32 (USER32.555)
1517 BOOL32 WINAPI TranslateMDISysAccel32( HWND32 hwndClient, LPMSG32 msg )
1521 STRUCT32_MSG32to16(msg,&msg16);
1522 /* MDICLIENTINFO is still the same for win32 and win16 ... */
1523 return TranslateMDISysAccel16(hwndClient,&msg16);
1527 /**********************************************************************
1528 * TranslateMDISysAccel16 (USER.451)
1530 BOOL16 WINAPI TranslateMDISysAccel16( HWND16 hwndClient, LPMSG16 msg )
1532 WND* clientWnd = WIN_FindWndPtr( hwndClient);
1534 if( clientWnd && (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN))
1536 MDICLIENTINFO *ci = NULL;
1539 ci = (MDICLIENTINFO*) clientWnd->wExtra;
1540 wnd = WIN_FindWndPtr(ci->hwndActiveChild);
1541 if( wnd && !(wnd->dwStyle & WS_DISABLED) )
1543 WPARAM16 wParam = 0;
1545 /* translate if the Ctrl key is down and Alt not. */
1547 if( (GetKeyState32(VK_CONTROL) & 0x8000) &&
1548 !(GetKeyState32(VK_MENU) & 0x8000))
1550 switch( msg->wParam )
1554 wParam = ( GetKeyState32(VK_SHIFT) & 0x8000 )
1555 ? SC_NEXTWINDOW : SC_PREVWINDOW;
1564 TRACE(mdi,"wParam = %04x\n", wParam);
1565 SendMessage16( ci->hwndActiveChild, WM_SYSCOMMAND,
1566 wParam, (LPARAM)msg->wParam);
1571 return 0; /* failure */
1575 /***********************************************************************
1576 * CalcChildScroll (USER.462)
1578 void WINAPI CalcChildScroll( HWND16 hwnd, WORD scroll )
1580 RECT32 childRect, clientRect;
1581 INT32 vmin, vmax, hmin, hmax, vpos, hpos;
1582 BOOL32 noscroll = FALSE;
1585 if (!(Wnd = pWnd = WIN_FindWndPtr( hwnd ))) return;
1586 GetClientRect32( hwnd, &clientRect );
1587 SetRectEmpty32( &childRect );
1589 for ( pWnd = pWnd->child; pWnd; pWnd = pWnd->next )
1591 UnionRect32( &childRect, &pWnd->rectWindow, &childRect );
1592 if( pWnd->dwStyle & WS_MAXIMIZE )
1595 UnionRect32( &childRect, &clientRect, &childRect );
1597 /* jump through the hoops to prevent excessive flashing
1600 hmin = childRect.left; hmax = childRect.right - clientRect.right;
1601 hpos = clientRect.left - childRect.left;
1602 vmin = childRect.top; vmax = childRect.bottom - clientRect.bottom;
1603 vpos = clientRect.top - childRect.top;
1606 ShowScrollBar32(hwnd, SB_BOTH, FALSE);
1611 vpos = hpos; vmin = hmin; vmax = hmax;
1613 SetScrollPos32(hwnd, scroll, vpos, FALSE);
1614 SetScrollRange32(hwnd, scroll, vmin, vmax, TRUE);
1617 SCROLL_SetNCSbState( Wnd, vmin, vmax, vpos,
1619 SetWindowPos32(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1620 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1625 /***********************************************************************
1626 * ScrollChildren16 (USER.463)
1628 void WINAPI ScrollChildren16(HWND16 hWnd, UINT16 uMsg, WPARAM16 wParam, LPARAM lParam)
1630 return ScrollChildren32( hWnd, uMsg, wParam, lParam );
1634 /***********************************************************************
1635 * ScrollChildren32 (USER32.448)
1637 void WINAPI ScrollChildren32(HWND32 hWnd, UINT32 uMsg, WPARAM32 wParam,
1640 WND *wndPtr = WIN_FindWndPtr(hWnd);
1642 INT32 curPos, length, minPos, maxPos, shift;
1644 if( !wndPtr ) return;
1646 if( uMsg == WM_HSCROLL )
1648 GetScrollRange32(hWnd,SB_HORZ,&minPos,&maxPos);
1649 curPos = GetScrollPos32(hWnd,SB_HORZ);
1650 length = (wndPtr->rectClient.right - wndPtr->rectClient.left)/2;
1651 shift = SYSMETRICS_CYHSCROLL;
1653 else if( uMsg == WM_VSCROLL )
1655 GetScrollRange32(hWnd,SB_VERT,&minPos,&maxPos);
1656 curPos = GetScrollPos32(hWnd,SB_VERT);
1657 length = (wndPtr->rectClient.bottom - wndPtr->rectClient.top)/2;
1658 shift = SYSMETRICS_CXVSCROLL;
1665 newPos = curPos - shift;
1668 newPos = curPos + shift;
1671 newPos = curPos - length;
1674 newPos = curPos + length;
1677 case SB_THUMBPOSITION:
1678 newPos = LOWORD(lParam);
1691 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
1695 if( newPos > maxPos )
1698 if( newPos < minPos )
1701 SetScrollPos32(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
1703 if( uMsg == WM_VSCROLL )
1704 ScrollWindowEx32(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
1705 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
1707 ScrollWindowEx32(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
1708 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
1712 /******************************************************************************
1713 * CascadeWindows [USER32.21] Cascades MDI child windows
1716 * Success: Number of cascaded windows.
1720 CascadeWindows (HWND32 hwndParent, UINT32 wFlags, const LPRECT32 lpRect,
1721 UINT32 cKids, const HWND32 *lpKids)
1723 FIXME (mdi, "(0x%08x,0x%08x,...,%u,...): stub\n",
1724 hwndParent, wFlags, cKids);
1730 /******************************************************************************
1731 * TileWindows [USER32.545] Tiles MDI child windows
1734 * Success: Number of tiled windows.
1738 TileWindows (HWND32 hwndParent, UINT32 wFlags, const LPRECT32 lpRect,
1739 UINT32 cKids, const HWND32 *lpKids)
1741 FIXME (mdi, "(0x%08x,0x%08x,...,%u,...): stub\n",
1742 hwndParent, wFlags, cKids);