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"
31 DEFAULT_DEBUG_CHANNEL(mdi)
33 #define MDIF_NEEDUPDATE 0x0001
35 static HBITMAP16 hBmpClose = 0;
36 static HBITMAP16 hBmpRestore = 0;
38 INT SCROLL_SetNCSbState(WND*,int,int,int,int,int,int);
40 /* ----------------- declarations ----------------- */
41 static void MDI_UpdateFrameText(WND *, HWND, BOOL, LPCSTR);
42 static BOOL MDI_AugmentFrameMenu(MDICLIENTINFO*, WND *, HWND);
43 static BOOL MDI_RestoreFrameMenu(WND *, HWND);
45 static LONG MDI_ChildActivate( WND*, HWND );
47 /* -------- Miscellaneous service functions ----------
52 static HWND MDI_GetChildByID(WND* wndPtr, INT id)
54 for (wndPtr = wndPtr->child; wndPtr; wndPtr = wndPtr->next)
55 if (wndPtr->wIDmenu == id) return wndPtr->hwndSelf;
59 static void MDI_PostUpdate(HWND hwnd, MDICLIENTINFO* ci, WORD recalc)
61 if( !(ci->mdiFlags & MDIF_NEEDUPDATE) )
63 ci->mdiFlags |= MDIF_NEEDUPDATE;
64 PostMessageA( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
66 ci->sbRecalc = recalc;
69 /**********************************************************************
72 static BOOL MDI_MenuModifyItem(WND* clientWnd, HWND hWndChild )
75 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
76 WND *wndPtr = WIN_FindWndPtr(hWndChild);
77 UINT n = sprintf(buffer, "%d ",
78 wndPtr->wIDmenu - clientInfo->idFirstChild + 1);
81 if( !clientInfo->hWindowMenu )
87 if (wndPtr->text) lstrcpynA(buffer + n, wndPtr->text, sizeof(buffer) - n );
89 n = GetMenuState(clientInfo->hWindowMenu,wndPtr->wIDmenu ,MF_BYCOMMAND);
90 bRet = ModifyMenuA(clientInfo->hWindowMenu , wndPtr->wIDmenu,
91 MF_BYCOMMAND | MF_STRING, wndPtr->wIDmenu, buffer );
92 CheckMenuItem(clientInfo->hWindowMenu ,wndPtr->wIDmenu , n & MF_CHECKED);
94 WIN_ReleaseWndPtr(wndPtr);
98 /**********************************************************************
101 static BOOL MDI_MenuDeleteItem(WND* clientWnd, HWND hWndChild )
104 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
105 WND *wndPtr = WIN_FindWndPtr(hWndChild);
109 if( !clientInfo->nActiveChildren ||
110 !clientInfo->hWindowMenu )
116 id = wndPtr->wIDmenu;
117 DeleteMenu(clientInfo->hWindowMenu,id,MF_BYCOMMAND);
119 /* walk the rest of MDI children to prevent gaps in the id
120 * sequence and in the menu child list */
122 for( index = id+1; index <= clientInfo->nActiveChildren +
123 clientInfo->idFirstChild; index++ )
125 WND *tmpWnd = WIN_FindWndPtr(MDI_GetChildByID(clientWnd,index));
128 TRACE(mdi,"no window for id=%i\n",index);
129 WIN_ReleaseWndPtr(tmpWnd);
136 n = sprintf(buffer, "%d ",index - clientInfo->idFirstChild);
138 lstrcpynA(buffer + n, tmpWnd->text, sizeof(buffer) - n );
141 ModifyMenuA(clientInfo->hWindowMenu ,index ,MF_BYCOMMAND | MF_STRING,
142 index - 1 , buffer );
143 WIN_ReleaseWndPtr(tmpWnd);
147 WIN_ReleaseWndPtr(wndPtr);
151 /**********************************************************************
154 * returns "activateable" child different from the current or zero
156 static HWND MDI_GetWindow(WND *clientWnd, HWND hWnd, BOOL bNext,
159 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
160 WND *wndPtr, *pWnd, *pWndLast = NULL;
162 dwStyleMask |= WS_DISABLED | WS_VISIBLE;
163 if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
165 if( !(wndPtr = WIN_FindWndPtr(hWnd)) ) return 0;
167 for ( pWnd = WIN_LockWndPtr(wndPtr->next); ; WIN_UpdateWndPtr(&pWnd,pWnd->next))
169 if (!pWnd ) WIN_UpdateWndPtr(&pWnd,wndPtr->parent->child);
171 if ( pWnd == wndPtr ) break; /* went full circle */
173 if (!pWnd->owner && (pWnd->dwStyle & dwStyleMask) == WS_VISIBLE )
179 WIN_ReleaseWndPtr(wndPtr);
180 WIN_ReleaseWndPtr(pWnd);
181 return pWndLast ? pWndLast->hwndSelf : 0;
184 /**********************************************************************
185 * MDI_CalcDefaultChildPos
187 * It seems that the default height is about 2/3 of the client rect
189 static void MDI_CalcDefaultChildPos( WND* w, WORD n, LPPOINT lpPos,
193 RECT rect = w->rectClient;
194 INT spacing = GetSystemMetrics(SM_CYCAPTION) +
195 GetSystemMetrics(SM_CYFRAME) - 1;
197 if( rect.bottom - rect.top - delta >= spacing )
198 rect.bottom -= delta;
200 nstagger = (rect.bottom - rect.top)/(3 * spacing);
201 lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
202 lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
203 lpPos[0].x = lpPos[0].y = spacing * (n%(nstagger+1));
206 /**********************************************************************
209 static LRESULT MDISetMenu( HWND hwnd, HMENU hmenuFrame,
212 WND *w = WIN_FindWndPtr(hwnd);
214 HWND hwndFrame = GetParent(hwnd);
215 HMENU oldFrameMenu = GetMenu(hwndFrame);
217 TRACE(mdi, "%04x %04x %04x\n",
218 hwnd, hmenuFrame, hmenuWindow);
220 ci = (MDICLIENTINFO *) w->wExtra;
222 if( ci->hwndChildMaximized && hmenuFrame && hmenuFrame!=oldFrameMenu )
223 MDI_RestoreFrameMenu(w->parent, ci->hwndChildMaximized );
225 if( hmenuWindow && hmenuWindow!=ci->hWindowMenu )
227 /* delete menu items from ci->hWindowMenu
228 * and add them to hmenuWindow */
230 INT i = GetMenuItemCount(ci->hWindowMenu) - 1;
231 INT pos = GetMenuItemCount(hmenuWindow) + 1;
233 AppendMenuA( hmenuWindow, MF_SEPARATOR, 0, NULL);
235 if( ci->nActiveChildren )
237 INT j = i - ci->nActiveChildren + 1;
241 for( ; i >= j ; i-- )
243 id = GetMenuItemID(ci->hWindowMenu,i );
244 state = GetMenuState(ci->hWindowMenu,i,MF_BYPOSITION);
246 GetMenuStringA(ci->hWindowMenu, i, buffer, 100, MF_BYPOSITION);
248 DeleteMenu(ci->hWindowMenu, i , MF_BYPOSITION);
249 InsertMenuA(hmenuWindow, pos, MF_BYPOSITION | MF_STRING,
251 CheckMenuItem(hmenuWindow ,pos , MF_BYPOSITION | (state & MF_CHECKED));
255 /* remove separator */
256 DeleteMenu(ci->hWindowMenu, i, MF_BYPOSITION);
258 ci->hWindowMenu = hmenuWindow;
261 if( hmenuFrame && hmenuFrame!=oldFrameMenu)
263 SetMenu(hwndFrame, hmenuFrame);
264 if( ci->hwndChildMaximized )
265 MDI_AugmentFrameMenu(ci, w->parent, ci->hwndChildMaximized );
266 WIN_ReleaseWndPtr(w);
269 WIN_ReleaseWndPtr(w);
273 /**********************************************************************
276 static LRESULT MDIRefreshMenu( HWND hwnd, HMENU hmenuFrame,
279 HWND hwndFrame = GetParent(hwnd);
280 HMENU oldFrameMenu = GetMenu(hwndFrame);
282 TRACE(mdi, "%04x %04x %04x\n",
283 hwnd, hmenuFrame, hmenuWindow);
285 FIXME(mdi,"partially function stub\n");
291 /* ------------------ MDI child window functions ---------------------- */
294 /**********************************************************************
297 static HWND MDICreateChild( WND *w, MDICLIENTINFO *ci, HWND parent,
298 LPMDICREATESTRUCTA cs )
301 DWORD style = cs->style | (WS_CHILD | WS_CLIPSIBLINGS);
302 HWND hwnd, hwndMax = 0;
303 WORD wIDmenu = ci->idFirstChild + ci->nActiveChildren;
304 char lpstrDef[]="junk!";
306 TRACE(mdi, "origin %i,%i - dim %i,%i, style %08x\n",
307 cs->x, cs->y, cs->cx, cs->cy, (unsigned)cs->style);
308 /* calculate placement */
309 MDI_CalcDefaultChildPos(w, ci->nTotalCreated++, pos, 0);
311 if (cs->cx == CW_USEDEFAULT || !cs->cx) cs->cx = pos[1].x;
312 if (cs->cy == CW_USEDEFAULT || !cs->cy) cs->cy = pos[1].y;
314 if( cs->x == CW_USEDEFAULT )
320 /* restore current maximized child */
321 if( style & WS_VISIBLE && ci->hwndChildMaximized )
323 if( style & WS_MAXIMIZE )
324 SendMessageA(w->hwndSelf, WM_SETREDRAW, FALSE, 0L );
325 hwndMax = ci->hwndChildMaximized;
326 ShowWindow( hwndMax, SW_SHOWNOACTIVATE );
327 if( style & WS_MAXIMIZE )
328 SendMessageA(w->hwndSelf, WM_SETREDRAW, TRUE, 0L );
331 /* this menu is needed to set a check mark in MDI_ChildActivate */
332 AppendMenuA(ci->hWindowMenu ,MF_STRING ,wIDmenu, lpstrDef );
334 ci->nActiveChildren++;
336 /* fix window style */
337 if( !(w->dwStyle & MDIS_ALLCHILDSTYLES) )
339 style &= (WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZE | WS_MAXIMIZE |
340 WS_CLIPCHILDREN | WS_DISABLED | WS_VSCROLL | WS_HSCROLL );
341 style |= (WS_VISIBLE | WS_OVERLAPPEDWINDOW);
344 if( w->flags & WIN_ISWIN32 )
346 hwnd = CreateWindowA( cs->szClass, cs->szTitle, style,
347 cs->x, cs->y, cs->cx, cs->cy, parent,
348 (HMENU16)wIDmenu, cs->hOwner, cs );
352 MDICREATESTRUCT16 *cs16;
355 cs16 = SEGPTR_NEW(MDICREATESTRUCT16);
356 STRUCT32_MDICREATESTRUCT32Ato16( cs, cs16 );
357 title = SEGPTR_STRDUP( cs->szTitle );
358 cls = SEGPTR_STRDUP( cs->szClass );
359 cs16->szTitle = SEGPTR_GET(title);
360 cs16->szClass = SEGPTR_GET(cls);
362 hwnd = CreateWindow16( cs->szClass, cs->szTitle, style,
363 cs16->x, cs16->y, cs16->cx, cs16->cy, parent,
364 (HMENU)wIDmenu, cs16->hOwner,
365 (LPVOID)SEGPTR_GET(cs16) );
366 SEGPTR_FREE( title );
371 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
375 WND* wnd = WIN_FindWndPtr( hwnd );
377 MDI_MenuModifyItem(w ,hwnd);
378 if( wnd->dwStyle & WS_MINIMIZE && ci->hwndActiveChild )
379 ShowWindow( hwnd, SW_SHOWMINNOACTIVE );
382 /* WS_VISIBLE is clear if a) the MDI client has
383 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
384 * MDICreateStruct. If so the created window is not shown nor
387 int showflag=wnd->dwStyle & WS_VISIBLE;
388 /* clear visible flag, otherwise SetWindoPos32 ignores
389 * the SWP_SHOWWINDOW command.
391 wnd->dwStyle &= ~WS_VISIBLE;
393 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE );
395 /* Set maximized state here in case hwnd didn't receive WM_SIZE
396 * during CreateWindow - bad!
399 if((wnd->dwStyle & WS_MAXIMIZE) && !ci->hwndChildMaximized )
401 ci->hwndChildMaximized = wnd->hwndSelf;
402 MDI_AugmentFrameMenu( ci, w->parent, hwnd );
403 MDI_UpdateFrameText( w->parent, ci->self, MDI_REPAINTFRAME, NULL );
406 /* needed, harmless ? */
407 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE );
410 WIN_ReleaseWndPtr(wnd);
411 TRACE(mdi, "created child - %04x\n",hwnd);
415 ci->nActiveChildren--;
416 DeleteMenu(ci->hWindowMenu,wIDmenu,MF_BYCOMMAND);
417 if( IsWindow(hwndMax) )
418 ShowWindow(hwndMax, SW_SHOWMAXIMIZED);
424 /**********************************************************************
425 * MDI_ChildGetMinMaxInfo
427 * Note: The rule here is that client rect of the maximized MDI child
428 * is equal to the client rect of the MDI client window.
430 static void MDI_ChildGetMinMaxInfo( WND* clientWnd, HWND hwnd,
431 MINMAXINFO16* lpMinMax )
433 WND* childWnd = WIN_FindWndPtr(hwnd);
434 RECT rect = clientWnd->rectClient;
436 MapWindowPoints( clientWnd->parent->hwndSelf,
437 ((MDICLIENTINFO*)clientWnd->wExtra)->self, (LPPOINT)&rect, 2);
438 AdjustWindowRectEx( &rect, childWnd->dwStyle, 0, childWnd->dwExStyle );
440 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
441 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
443 lpMinMax->ptMaxPosition.x = rect.left;
444 lpMinMax->ptMaxPosition.y = rect.top;
446 WIN_ReleaseWndPtr(childWnd);
448 TRACE(mdi,"max rect (%i,%i - %i, %i)\n",
449 rect.left,rect.top,rect.right,rect.bottom);
453 /**********************************************************************
454 * MDI_SwitchActiveChild
456 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
459 static void MDI_SwitchActiveChild( HWND clientHwnd, HWND childHwnd,
462 WND *w = WIN_FindWndPtr(clientHwnd);
467 hwndTo = MDI_GetWindow(w, childHwnd, bNextWindow, 0);
469 ci = (MDICLIENTINFO *) w->wExtra;
471 TRACE(mdi, "from %04x, to %04x\n",childHwnd,hwndTo);
473 if ( !hwndTo ) goto END; /* no window to switch to */
475 hwndPrev = ci->hwndActiveChild;
477 if ( hwndTo != hwndPrev )
481 if( ci->hwndChildMaximized )
484 w->dwStyle &= ~WS_VISIBLE;
487 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0,
488 SWP_NOMOVE | SWP_NOSIZE );
490 if( bNextWindow && hwndPrev )
491 SetWindowPos( hwndPrev, HWND_BOTTOM, 0, 0, 0, 0,
492 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
494 ShowWindow( clientHwnd, SW_SHOW );
497 WIN_ReleaseWndPtr(w);
501 /**********************************************************************
504 static LRESULT MDIDestroyChild( WND *w_parent, MDICLIENTINFO *ci,
505 HWND parent, HWND child,
508 WND *childPtr = WIN_FindWndPtr(child);
512 if( child == ci->hwndActiveChild )
514 MDI_SwitchActiveChild(parent, child, TRUE);
516 if( child == ci->hwndActiveChild )
518 ShowWindow( child, SW_HIDE);
519 if( child == ci->hwndChildMaximized )
521 MDI_RestoreFrameMenu(w_parent->parent, child);
522 ci->hwndChildMaximized = 0;
523 MDI_UpdateFrameText(w_parent->parent,parent,TRUE,NULL);
526 MDI_ChildActivate(w_parent, 0);
528 MDI_MenuDeleteItem(w_parent, child);
530 WIN_ReleaseWndPtr(childPtr);
532 ci->nActiveChildren--;
534 TRACE(mdi,"child destroyed - %04x\n",child);
538 MDI_PostUpdate(GetParent(child), ci, SB_BOTH+1);
539 DestroyWindow(child);
547 /**********************************************************************
550 * Note: hWndChild is NULL when last child is being destroyed
552 static LONG MDI_ChildActivate( WND *clientPtr, HWND hWndChild )
554 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientPtr->wExtra;
555 HWND prevActiveWnd = clientInfo->hwndActiveChild;
556 WND *wndPtr = WIN_FindWndPtr( hWndChild );
557 WND *wndPrev = WIN_FindWndPtr( prevActiveWnd );
558 BOOL isActiveFrameWnd = 0;
561 if( hWndChild == prevActiveWnd )
569 if( wndPtr->dwStyle & WS_DISABLED )
576 TRACE(mdi,"%04x\n", hWndChild);
578 if( GetActiveWindow() == clientPtr->parent->hwndSelf )
579 isActiveFrameWnd = TRUE;
581 /* deactivate prev. active child */
584 wndPrev->dwStyle |= WS_SYSMENU;
585 SendMessageA( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
586 SendMessageA( prevActiveWnd, WM_MDIACTIVATE, (WPARAM)prevActiveWnd,
588 /* uncheck menu item */
589 if( clientInfo->hWindowMenu )
590 CheckMenuItem( clientInfo->hWindowMenu,
591 wndPrev->wIDmenu, 0);
595 if( clientInfo->hwndChildMaximized )
597 if( clientInfo->hwndChildMaximized != hWndChild ) {
599 clientInfo->hwndActiveChild = hWndChild;
600 ShowWindow( hWndChild, SW_SHOWMAXIMIZED);
602 ShowWindow( clientInfo->hwndActiveChild, SW_SHOWNORMAL );
606 clientInfo->hwndActiveChild = hWndChild;
608 /* check if we have any children left */
611 if( isActiveFrameWnd )
612 SetFocus( clientInfo->self );
617 /* check menu item */
618 if( clientInfo->hWindowMenu )
619 CheckMenuItem( clientInfo->hWindowMenu,
620 wndPtr->wIDmenu, MF_CHECKED);
622 /* bring active child to the top */
623 SetWindowPos( hWndChild, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
625 if( isActiveFrameWnd )
627 SendMessageA( hWndChild, WM_NCACTIVATE, TRUE, 0L);
628 if( GetFocus() == clientInfo->self )
629 SendMessageA( clientInfo->self, WM_SETFOCUS,
630 (WPARAM)clientInfo->self, 0L );
632 SetFocus( clientInfo->self );
634 SendMessageA( hWndChild, WM_MDIACTIVATE, (WPARAM)prevActiveWnd,
638 WIN_ReleaseWndPtr(wndPtr);
639 WIN_ReleaseWndPtr(wndPrev);
643 /* -------------------- MDI client window functions ------------------- */
645 /**********************************************************************
646 * CreateMDIMenuBitmap
648 static HBITMAP16 CreateMDIMenuBitmap(void)
650 HDC hDCSrc = CreateCompatibleDC(0);
651 HDC hDCDest = CreateCompatibleDC(hDCSrc);
652 HBITMAP16 hbClose = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_CLOSE) );
654 HANDLE16 hobjSrc, hobjDest;
656 hobjSrc = SelectObject(hDCSrc, hbClose);
657 hbCopy = CreateCompatibleBitmap(hDCSrc,SYSMETRICS_CXSIZE,SYSMETRICS_CYSIZE);
658 hobjDest = SelectObject(hDCDest, hbCopy);
660 BitBlt(hDCDest, 0, 0, SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE,
661 hDCSrc, SYSMETRICS_CXSIZE, 0, SRCCOPY);
663 SelectObject(hDCSrc, hobjSrc);
664 DeleteObject(hbClose);
667 hobjSrc = SelectObject( hDCDest, GetStockObject(BLACK_PEN) );
669 MoveToEx( hDCDest, SYSMETRICS_CXSIZE - 1, 0, NULL );
670 LineTo( hDCDest, SYSMETRICS_CXSIZE - 1, SYSMETRICS_CYSIZE - 1);
672 SelectObject(hDCDest, hobjSrc );
673 SelectObject(hDCDest, hobjDest);
679 /**********************************************************************
682 static LONG MDICascade(WND* clientWnd, MDICLIENTINFO *ci)
687 if (ci->hwndChildMaximized)
688 SendMessageA( clientWnd->hwndSelf, WM_MDIRESTORE,
689 (WPARAM)ci->hwndChildMaximized, 0);
691 if (ci->nActiveChildren == 0) return 0;
693 if ((ppWnd = WIN_BuildWinArray(clientWnd, BWA_SKIPHIDDEN | BWA_SKIPOWNED |
694 BWA_SKIPICONIC, &total)))
696 WND** heapPtr = ppWnd;
699 INT delta = 0, n = 0;
701 if( total < ci->nActiveChildren )
702 delta = SYSMETRICS_CYICONSPACING + SYSMETRICS_CYICON;
704 /* walk the list (backwards) and move windows */
705 while (*ppWnd) ppWnd++;
706 while (ppWnd != heapPtr)
709 TRACE(mdi, "move %04x to (%ld,%ld) size [%ld,%ld]\n",
710 (*ppWnd)->hwndSelf, pos[0].x, pos[0].y, pos[1].x, pos[1].y);
712 MDI_CalcDefaultChildPos(clientWnd, n++, pos, delta);
713 SetWindowPos( (*ppWnd)->hwndSelf, 0, pos[0].x, pos[0].y,
715 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
718 WIN_ReleaseWinArray(heapPtr);
721 if( total < ci->nActiveChildren )
722 ArrangeIconicWindows( clientWnd->hwndSelf );
726 /**********************************************************************
729 static void MDITile( WND* wndClient, MDICLIENTINFO *ci, WPARAM wParam )
734 if (ci->hwndChildMaximized)
735 SendMessageA( wndClient->hwndSelf, WM_MDIRESTORE,
736 (WPARAM)ci->hwndChildMaximized, 0);
738 if (ci->nActiveChildren == 0) return;
740 ppWnd = WIN_BuildWinArray(wndClient, BWA_SKIPHIDDEN | BWA_SKIPOWNED | BWA_SKIPICONIC |
741 ((wParam & MDITILE_SKIPDISABLED)? BWA_SKIPDISABLED : 0), &total );
743 TRACE(mdi,"%u windows to tile\n", total);
747 WND** heapPtr = ppWnd;
752 int x, y, xsize, ysize;
753 int rows, columns, r, c, i;
755 rect = wndClient->rectClient;
756 rows = (int) sqrt((double)total);
757 columns = total / rows;
759 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
762 rows = columns; /* exchange r and c */
766 if( total != ci->nActiveChildren)
768 y = rect.bottom - 2 * SYSMETRICS_CYICONSPACING - SYSMETRICS_CYICON;
769 rect.bottom = ( y - SYSMETRICS_CYICON < rect.top )? rect.bottom: y;
772 ysize = rect.bottom / rows;
773 xsize = rect.right / columns;
775 for (x = i = 0, c = 1; c <= columns && *ppWnd; c++)
780 ysize = rect.bottom / rows;
784 for (r = 1; r <= rows && *ppWnd; r++, i++)
786 SetWindowPos((*ppWnd)->hwndSelf, 0, x, y, xsize, ysize,
787 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
794 WIN_ReleaseWinArray(heapPtr);
797 if( total < ci->nActiveChildren ) ArrangeIconicWindows( wndClient->hwndSelf );
800 /* ----------------------- Frame window ---------------------------- */
803 /**********************************************************************
804 * MDI_AugmentFrameMenu
806 static BOOL MDI_AugmentFrameMenu( MDICLIENTINFO* ci, WND *frame,
809 WND* child = WIN_FindWndPtr(hChild);
812 TRACE(mdi,"frame %p,child %04x\n",frame,hChild);
814 if( !frame->wIDmenu || !child->hSysMenu )
816 WIN_ReleaseWndPtr(child);
819 WIN_ReleaseWndPtr(child);
821 /* create a copy of sysmenu popup and insert it into frame menu bar */
823 if (!(hSysPopup = LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU")))
826 TRACE(mdi,"\tgot popup %04x in sysmenu %04x\n",
827 hSysPopup, child->hSysMenu);
829 AppendMenuA(frame->wIDmenu,MF_HELP | MF_BITMAP,
830 SC_MINIMIZE, (LPSTR)(DWORD)HBMMENU_MBAR_MINIMIZE ) ;
831 AppendMenuA(frame->wIDmenu,MF_HELP | MF_BITMAP,
832 SC_RESTORE, (LPSTR)(DWORD)HBMMENU_MBAR_RESTORE );
834 if( !InsertMenuA(frame->wIDmenu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
835 hSysPopup, (LPSTR)(DWORD)hBmpClose ))
837 TRACE(mdi,"not inserted\n");
838 DestroyMenu(hSysPopup);
842 /* The close button is only present in Win 95 look */
843 if(TWEAK_WineLook > WIN31_LOOK)
845 AppendMenuA(frame->wIDmenu,MF_HELP | MF_BITMAP,
846 SC_CLOSE, (LPSTR)(DWORD)HBMMENU_MBAR_CLOSE );
849 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
850 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
851 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
854 DrawMenuBar(frame->hwndSelf);
859 /**********************************************************************
860 * MDI_RestoreFrameMenu
862 static BOOL MDI_RestoreFrameMenu( WND *frameWnd, HWND hChild )
864 INT nItems = GetMenuItemCount(frameWnd->wIDmenu) - 1;
865 UINT iId = GetMenuItemID(frameWnd->wIDmenu,nItems) ;
867 TRACE(mdi,"frameWnd %p,child %04x\n",frameWnd,hChild);
869 if(!(iId == SC_RESTORE || iId == SC_CLOSE) )
873 RemoveMenu(frameWnd->wIDmenu,0,MF_BYPOSITION);
875 if(TWEAK_WineLook > WIN31_LOOK)
878 DeleteMenu(frameWnd->wIDmenu,GetMenuItemCount(frameWnd->wIDmenu) - 1,MF_BYPOSITION);
881 DeleteMenu(frameWnd->wIDmenu,GetMenuItemCount(frameWnd->wIDmenu) - 1,MF_BYPOSITION);
883 DeleteMenu(frameWnd->wIDmenu,GetMenuItemCount(frameWnd->wIDmenu) - 1,MF_BYPOSITION);
885 DrawMenuBar(frameWnd->hwndSelf);
891 /**********************************************************************
892 * MDI_UpdateFrameText
894 * used when child window is maximized/restored
896 * Note: lpTitle can be NULL
898 static void MDI_UpdateFrameText( WND *frameWnd, HWND hClient,
899 BOOL repaint, LPCSTR lpTitle )
901 char lpBuffer[MDI_MAXTITLELENGTH+1];
902 WND* clientWnd = WIN_FindWndPtr(hClient);
903 MDICLIENTINFO *ci = (MDICLIENTINFO *) clientWnd->wExtra;
905 TRACE(mdi, "repaint %i, frameText %s\n", repaint, (lpTitle)?lpTitle:"NULL");
912 WIN_ReleaseWndPtr(clientWnd);
916 /* store new "default" title if lpTitle is not NULL */
919 if (ci->frameTitle) HeapFree( SystemHeap, 0, ci->frameTitle );
920 ci->frameTitle = HEAP_strdupA( SystemHeap, 0, lpTitle );
925 WND* childWnd = WIN_FindWndPtr( ci->hwndChildMaximized );
927 if( childWnd && childWnd->text )
929 /* combine frame title and child title if possible */
931 LPCSTR lpBracket = " - [";
932 int i_frame_text_length = strlen(ci->frameTitle);
933 int i_child_text_length = strlen(childWnd->text);
935 lstrcpynA( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
937 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
939 strcat( lpBuffer, lpBracket );
941 if( i_frame_text_length + i_child_text_length + 6 < MDI_MAXTITLELENGTH )
943 strcat( lpBuffer, childWnd->text );
944 strcat( lpBuffer, "]" );
948 lstrcpynA( lpBuffer + i_frame_text_length + 4,
949 childWnd->text, MDI_MAXTITLELENGTH - i_frame_text_length - 5 );
950 strcat( lpBuffer, "]" );
956 strncpy(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH );
957 lpBuffer[MDI_MAXTITLELENGTH]='\0';
959 WIN_ReleaseWndPtr(childWnd);
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 );
970 WIN_ReleaseWndPtr(clientWnd);
975 /* ----------------------------- Interface ---------------------------- */
978 /**********************************************************************
981 * This function handles all MDI requests.
983 LRESULT WINAPI MDIClientWndProc( HWND hwnd, UINT message, WPARAM wParam,
989 WND *w = WIN_FindWndPtr(hwnd);
990 WND *frameWnd = WIN_LockWndPtr(w->parent);
994 ci = (MDICLIENTINFO *) w->wExtra;
1000 cs = (LPCREATESTRUCTA)lParam;
1002 /* Translation layer doesn't know what's in the cs->lpCreateParams
1003 * so we have to keep track of what environment we're in. */
1005 if( w->flags & WIN_ISWIN32 )
1007 #define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1008 ci->hWindowMenu = ccs->hWindowMenu;
1009 ci->idFirstChild = ccs->idFirstChild;
1014 LPCLIENTCREATESTRUCT16 ccs = (LPCLIENTCREATESTRUCT16)
1015 PTR_SEG_TO_LIN(cs->lpCreateParams);
1016 ci->hWindowMenu = ccs->hWindowMenu;
1017 ci->idFirstChild = ccs->idFirstChild;
1020 ci->hwndChildMaximized = 0;
1021 ci->nActiveChildren = 0;
1022 ci->nTotalCreated = 0;
1023 ci->frameTitle = NULL;
1026 w->dwStyle |= WS_CLIPCHILDREN;
1030 hBmpClose = CreateMDIMenuBitmap();
1031 hBmpRestore = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_RESTORE) );
1033 MDI_UpdateFrameText(frameWnd, hwnd, MDI_NOFRAMEREPAINT,frameWnd->text);
1035 AppendMenuA( ci->hWindowMenu, MF_SEPARATOR, 0, NULL );
1037 GetClientRect(frameWnd->hwndSelf, &rect);
1038 NC_HandleNCCalcSize( w, &rect );
1039 w->rectClient = rect;
1041 TRACE(mdi,"Client created - hwnd = %04x, idFirst = %u\n",
1042 hwnd, ci->idFirstChild );
1048 if( ci->hwndChildMaximized ) MDI_RestoreFrameMenu(w, frameWnd->hwndSelf);
1049 if((nItems = GetMenuItemCount(ci->hWindowMenu)) > 0)
1051 ci->idFirstChild = nItems - 1;
1052 ci->nActiveChildren++; /* to delete a separator */
1053 while( ci->nActiveChildren-- )
1054 DeleteMenu(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
1059 case WM_MDIACTIVATE:
1060 if( ci->hwndActiveChild != (HWND)wParam )
1061 SetWindowPos((HWND)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
1066 retvalue = MDICascade(w, ci);
1070 if (lParam) retvalue = MDICreateChild( w, ci, hwnd,
1071 (MDICREATESTRUCTA*)lParam );
1076 retvalue = MDIDestroyChild( w, ci, hwnd, (HWND)wParam, TRUE );
1079 case WM_MDIGETACTIVE:
1080 if (lParam) *(BOOL *)lParam = (ci->hwndChildMaximized > 0);
1081 retvalue = ci->hwndActiveChild;
1084 case WM_MDIICONARRANGE:
1085 ci->mdiFlags |= MDIF_NEEDUPDATE;
1086 ArrangeIconicWindows(hwnd);
1087 ci->sbRecalc = SB_BOTH+1;
1088 SendMessageA(hwnd, WM_MDICALCCHILDSCROLL, 0, 0L);
1092 case WM_MDIMAXIMIZE:
1093 ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1097 case WM_MDINEXT: /* lParam != 0 means previous window */
1098 MDI_SwitchActiveChild(hwnd, (HWND)wParam, (lParam)? FALSE : TRUE );
1102 SendMessageA( (HWND)wParam, WM_SYSCOMMAND, SC_RESTORE, 0);
1107 retvalue = MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1109 case WM_MDIREFRESHMENU:
1110 retvalue = MDIRefreshMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1114 ci->mdiFlags |= MDIF_NEEDUPDATE;
1115 ShowScrollBar(hwnd,SB_BOTH,FALSE);
1116 MDITile(w, ci, wParam);
1117 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1123 ci->mdiFlags |= MDIF_NEEDUPDATE;
1124 ScrollChildren(hwnd, message, wParam, lParam);
1125 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1130 if( ci->hwndActiveChild )
1132 WND* pw = WIN_FindWndPtr( ci->hwndActiveChild );
1133 if( !(pw->dwStyle & WS_MINIMIZE) )
1134 SetFocus( ci->hwndActiveChild );
1135 WIN_ReleaseWndPtr(pw);
1141 if( ci->hwndActiveChild )
1142 SendMessageA(ci->hwndActiveChild, message, wParam, lParam);
1145 case WM_PARENTNOTIFY:
1146 if (LOWORD(wParam) == WM_LBUTTONDOWN)
1148 POINT16 pt = MAKEPOINT16(lParam);
1149 HWND16 child = ChildWindowFromPoint16(hwnd, pt);
1151 TRACE(mdi,"notification from %04x (%i,%i)\n",child,pt.x,pt.y);
1153 if( child && child != hwnd && child != ci->hwndActiveChild )
1154 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1160 if( IsWindow(ci->hwndChildMaximized) )
1162 WND* child = WIN_FindWndPtr(ci->hwndChildMaximized);
1167 rect.right = LOWORD(lParam);
1168 rect.bottom = HIWORD(lParam);
1170 AdjustWindowRectEx(&rect, child->dwStyle, 0, child->dwExStyle);
1171 MoveWindow(ci->hwndChildMaximized, rect.left, rect.top,
1172 rect.right - rect.left, rect.bottom - rect.top, 1);
1173 WIN_ReleaseWndPtr(child);
1176 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1180 case WM_MDICALCCHILDSCROLL:
1181 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1183 CalcChildScroll16(hwnd, ci->sbRecalc-1);
1185 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1191 retvalue = DefWindowProcA( hwnd, message, wParam, lParam );
1193 WIN_ReleaseWndPtr(w);
1194 WIN_ReleaseWndPtr(frameWnd);
1199 /***********************************************************************
1200 * DefFrameProc16 (USER.445)
1202 LRESULT WINAPI DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient,
1203 UINT16 message, WPARAM16 wParam, LPARAM lParam )
1214 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1217 ERR(mdi,"null wndPtr for mdi window hwndMDIClient=%04x\n",
1222 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1224 /* check for possible syscommands for maximized MDI child */
1225 WIN_ReleaseWndPtr(wndPtr);
1228 wParam < ci->idFirstChild ||
1229 wParam >= ci->idFirstChild + ci->nActiveChildren
1231 if( (wParam - 0xF000) & 0xF00F ) break;
1242 if( ci->hwndChildMaximized )
1243 return SendMessage16( ci->hwndChildMaximized, WM_SYSCOMMAND,
1249 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1250 childHwnd = MDI_GetChildByID(wndPtr,wParam );
1251 WIN_ReleaseWndPtr(wndPtr);
1254 SendMessage16(hwndMDIClient, WM_MDIACTIVATE,
1255 (WPARAM16)childHwnd , 0L);
1260 SendMessage16(hwndMDIClient, message, wParam, lParam);
1264 wndPtr = WIN_FindWndPtr(hwnd);
1265 MDI_UpdateFrameText(wndPtr, hwndMDIClient,
1267 (LPCSTR)PTR_SEG_TO_LIN(lParam));
1268 WIN_ReleaseWndPtr(wndPtr);
1272 SetFocus(hwndMDIClient);
1276 MoveWindow16(hwndMDIClient, 0, 0,
1277 LOWORD(lParam), HIWORD(lParam), TRUE);
1282 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1283 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1285 if( !(wndPtr->parent->dwStyle & WS_MINIMIZE)
1286 && ci->hwndActiveChild && !ci->hwndChildMaximized )
1288 /* control menu is between the frame system menu and
1289 * the first entry of menu bar */
1291 if( (wParam == VK_LEFT &&
1292 wndPtr->parent->wIDmenu == LOWORD(lParam)) ||
1293 (wParam == VK_RIGHT &&
1294 GetSubMenu16(wndPtr->parent->hSysMenu, 0) == LOWORD(lParam)) )
1297 WIN_ReleaseWndPtr(wndPtr);
1298 wndPtr = WIN_FindWndPtr(ci->hwndActiveChild);
1299 retvalue = MAKELONG( GetSubMenu16(wndPtr->hSysMenu, 0),
1300 ci->hwndActiveChild);
1301 WIN_ReleaseWndPtr(wndPtr);
1305 WIN_ReleaseWndPtr(wndPtr);
1310 return DefWindowProc16(hwnd, message, wParam, lParam);
1314 /***********************************************************************
1315 * DefFrameProc32A (USER32.122)
1317 LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1318 UINT message, WPARAM wParam, LPARAM lParam)
1325 return DefFrameProc16( hwnd, hwndMDIClient, message,
1327 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1330 SendMessageA(hwndMDIClient, message, wParam, lParam);
1335 LPSTR segstr = SEGPTR_STRDUP((LPSTR)lParam);
1337 ret = DefFrameProc16(hwnd, hwndMDIClient, message,
1338 wParam, (LPARAM)SEGPTR_GET(segstr) );
1339 SEGPTR_FREE(segstr);
1346 return DefFrameProc16( hwnd, hwndMDIClient, message,
1351 return DefWindowProcA(hwnd, message, wParam, lParam);
1355 /***********************************************************************
1356 * DefFrameProc32W (USER32.123)
1358 LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1359 UINT message, WPARAM wParam, LPARAM lParam)
1366 return DefFrameProc16( hwnd, hwndMDIClient, message,
1368 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1371 SendMessageW(hwndMDIClient, message, wParam, lParam);
1376 LPSTR txt = HEAP_strdupWtoA(GetProcessHeap(),0,(LPWSTR)lParam);
1377 LRESULT ret = DefFrameProcA( hwnd, hwndMDIClient, message,
1378 wParam, (DWORD)txt );
1379 HeapFree(GetProcessHeap(),0,txt);
1385 return DefFrameProcA( hwnd, hwndMDIClient, message,
1390 return DefWindowProcW( hwnd, message, wParam, lParam );
1394 /***********************************************************************
1395 * DefMDIChildProc16 (USER.447)
1397 LRESULT WINAPI DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1398 WPARAM16 wParam, LPARAM lParam )
1401 WND *clientWnd,*tmpWnd = 0;
1404 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1405 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1410 DefWindowProc16(hwnd, message, wParam, lParam);
1411 MDI_MenuModifyItem(clientWnd,hwnd);
1412 if( ci->hwndChildMaximized == hwnd )
1413 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1414 MDI_REPAINTFRAME, NULL );
1419 SendMessage16(ci->self,WM_MDIDESTROY,(WPARAM16)hwnd,0L);
1424 if( ci->hwndActiveChild != hwnd )
1425 MDI_ChildActivate(clientWnd, hwnd);
1428 case WM_CHILDACTIVATE:
1429 MDI_ChildActivate(clientWnd, hwnd);
1434 TRACE(mdi,"WM_NCPAINT for %04x, active %04x\n",
1435 hwnd, ci->hwndActiveChild );
1442 if( ci->hwndChildMaximized == hwnd)
1450 tmpWnd = WIN_FindWndPtr(hwnd);
1451 tmpWnd->dwStyle |= WS_SYSMENU;
1452 WIN_ReleaseWndPtr(tmpWnd);
1455 if( ci->hwndChildMaximized == hwnd)
1457 retvalue = SendMessage16( clientWnd->parent->hwndSelf,
1458 message, wParam, lParam);
1461 tmpWnd = WIN_FindWndPtr(hwnd);
1462 tmpWnd->dwStyle &= ~WS_SYSMENU;
1463 WIN_ReleaseWndPtr(tmpWnd);
1466 SendMessage16( ci->self, WM_MDINEXT, 0, 0);
1470 SendMessage16( ci->self, WM_MDINEXT, 0, 1);
1476 case WM_GETMINMAXINFO:
1477 MDI_ChildGetMinMaxInfo(clientWnd, hwnd, (MINMAXINFO16*) PTR_SEG_TO_LIN(lParam));
1482 if( ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1484 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1490 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1492 ci->hwndChildMaximized = 0;
1494 MDI_RestoreFrameMenu( clientWnd->parent, hwnd);
1495 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1496 MDI_REPAINTFRAME, NULL );
1499 if( wParam == SIZE_MAXIMIZED )
1501 HWND16 hMaxChild = ci->hwndChildMaximized;
1503 if( hMaxChild == hwnd ) break;
1507 SendMessage16( hMaxChild, WM_SETREDRAW, FALSE, 0L );
1509 MDI_RestoreFrameMenu( clientWnd->parent, hMaxChild);
1510 ShowWindow16( hMaxChild, SW_SHOWNOACTIVATE);
1512 SendMessage16( hMaxChild, WM_SETREDRAW, TRUE, 0L );
1515 TRACE(mdi,"maximizing child %04x\n", hwnd );
1517 ci->hwndChildMaximized = hwnd; /* !!! */
1518 ci->hwndActiveChild = hwnd;
1520 MDI_AugmentFrameMenu( ci, clientWnd->parent, hwnd);
1521 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1522 MDI_REPAINTFRAME, NULL );
1525 if( wParam == SIZE_MINIMIZED )
1527 HWND16 switchTo = MDI_GetWindow(clientWnd, hwnd, TRUE, WS_MINIMIZE);
1530 SendMessage16( switchTo, WM_CHILDACTIVATE, 0, 0L);
1533 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1538 /* MDI children don't have menu bars */
1539 PostMessage16( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1540 (WPARAM16)SC_KEYMENU, (LPARAM)wParam);
1541 retvalue = 0x00010000L;
1546 if( wParam == VK_LEFT ) /* switch to frame system menu */
1548 retvalue = MAKELONG( GetSubMenu16(clientWnd->parent->hSysMenu, 0),
1549 clientWnd->parent->hwndSelf );
1552 if( wParam == VK_RIGHT ) /* to frame menu bar */
1554 retvalue = MAKELONG( clientWnd->parent->wIDmenu,
1555 clientWnd->parent->hwndSelf );
1564 SendMessage16(hwnd,WM_SYSCOMMAND,
1565 (WPARAM16)SC_KEYMENU, (LPARAM)(DWORD)VK_SPACE);
1571 retvalue = DefWindowProc16(hwnd, message, wParam, lParam);
1573 WIN_ReleaseWndPtr(clientWnd);
1578 /***********************************************************************
1579 * DefMDIChildProc32A (USER32.124)
1581 LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1582 WPARAM wParam, LPARAM lParam )
1585 WND *clientWnd,*tmpWnd;
1588 tmpWnd = WIN_FindWndPtr(hwnd);
1589 clientWnd = WIN_FindWndPtr(tmpWnd->parent->hwndSelf);
1590 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1591 WIN_ReleaseWndPtr(tmpWnd);
1596 DefWindowProcA(hwnd, message, wParam, lParam);
1597 MDI_MenuModifyItem(clientWnd,hwnd);
1598 if( ci->hwndChildMaximized == hwnd )
1599 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1600 MDI_REPAINTFRAME, NULL );
1604 case WM_GETMINMAXINFO:
1607 STRUCT32_MINMAXINFO32to16( (MINMAXINFO *)lParam, &mmi );
1608 MDI_ChildGetMinMaxInfo( clientWnd, hwnd, &mmi );
1609 STRUCT32_MINMAXINFO16to32( &mmi, (MINMAXINFO *)lParam );
1616 /* MDI children don't have menu bars */
1617 PostMessage16( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1618 (WPARAM16)SC_KEYMENU, (LPARAM)LOWORD(wParam) );
1619 retvalue = 0x00010000L;
1624 case WM_CHILDACTIVATE:
1630 retvalue = DefMDIChildProc16( hwnd, message, (WPARAM16)wParam, lParam );
1636 SendMessageA(hwnd,WM_SYSCOMMAND,
1637 (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)VK_SPACE);
1642 retvalue = DefWindowProcA(hwnd, message, wParam, lParam);
1644 WIN_ReleaseWndPtr(clientWnd);
1649 /***********************************************************************
1650 * DefMDIChildProc32W (USER32.125)
1652 LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1653 WPARAM wParam, LPARAM lParam )
1659 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1660 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1665 DefWindowProcW(hwnd, message, wParam, lParam);
1666 MDI_MenuModifyItem(clientWnd,hwnd);
1667 if( ci->hwndChildMaximized == hwnd )
1668 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1669 MDI_REPAINTFRAME, NULL );
1673 case WM_GETMINMAXINFO:
1677 case WM_CHILDACTIVATE:
1683 retvalue = DefMDIChildProcA( hwnd, message, (WPARAM16)wParam, lParam );
1689 SendMessageW(hwnd,WM_SYSCOMMAND,
1690 (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)VK_SPACE);
1695 retvalue = DefWindowProcW(hwnd, message, wParam, lParam);
1697 WIN_ReleaseWndPtr(clientWnd);
1703 /**********************************************************************
1704 * CreateMDIWindowA [USER32.79] Creates a MDI child in new thread
1705 * FIXME: its in the same thread now
1708 * Success: Handle to created window
1711 HWND WINAPI CreateMDIWindowA(
1712 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1713 LPCSTR lpWindowName, /* [in] Pointer to window name */
1714 DWORD dwStyle, /* [in] Window style */
1715 INT X, /* [in] Horizontal position of window */
1716 INT Y, /* [in] Vertical position of window */
1717 INT nWidth, /* [in] Width of window */
1718 INT nHeight, /* [in] Height of window */
1719 HWND hWndParent, /* [in] Handle to parent window */
1720 HINSTANCE hInstance, /* [in] Handle to application instance */
1721 LPARAM lParam) /* [in] Application-defined value */
1723 WARN(mdi,"is only single threaded!\n");
1724 return MDI_CreateMDIWindowA(lpClassName, lpWindowName, dwStyle, X, Y,
1725 nWidth, nHeight, hWndParent, hInstance, lParam);
1728 /**********************************************************************
1729 * MDI_CreateMDIWindowA
1730 * single threaded version of CreateMDIWindowA
1731 * called by CreateWindowEx32A
1733 HWND MDI_CreateMDIWindowA(
1735 LPCSTR lpWindowName,
1742 HINSTANCE hInstance,
1746 MDICREATESTRUCTA cs;
1747 WND *pWnd=WIN_FindWndPtr(hWndParent);
1750 TRACE(mdi, "(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
1751 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1752 nWidth,nHeight,hWndParent,hInstance,lParam);
1755 ERR(mdi," bad hwnd for MDI-client: %d\n",hWndParent);
1758 cs.szClass=lpClassName;
1759 cs.szTitle=lpWindowName;
1760 cs.hOwner=hInstance;
1768 pCi=(MDICLIENTINFO *)pWnd->wExtra;
1770 retvalue = MDICreateChild(pWnd,pCi,hWndParent,&cs);
1771 WIN_ReleaseWndPtr(pWnd);
1775 /***************************************
1776 * CreateMDIWindow32W [USER32.80] Creates a MDI child in new thread
1779 * Success: Handle to created window
1782 HWND WINAPI CreateMDIWindowW(
1783 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1784 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1785 DWORD dwStyle, /* [in] Window style */
1786 INT X, /* [in] Horizontal position of window */
1787 INT Y, /* [in] Vertical position of window */
1788 INT nWidth, /* [in] Width of window */
1789 INT nHeight, /* [in] Height of window */
1790 HWND hWndParent, /* [in] Handle to parent window */
1791 HINSTANCE hInstance, /* [in] Handle to application instance */
1792 LPARAM lParam) /* [in] Application-defined value */
1794 FIXME(mdi, "(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld): stub\n",
1795 debugstr_w(lpClassName),debugstr_w(lpWindowName),dwStyle,X,Y,
1796 nWidth,nHeight,hWndParent,hInstance,lParam);
1801 /******************************************************************************
1802 * CreateMDIWindow32W [USER32.80] Creates a MDI child window
1803 * single threaded version of CreateMDIWindow
1804 * called by CreateWindowEx32W().
1806 HWND MDI_CreateMDIWindowW(
1807 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1808 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1809 DWORD dwStyle, /* [in] Window style */
1810 INT X, /* [in] Horizontal position of window */
1811 INT Y, /* [in] Vertical position of window */
1812 INT nWidth, /* [in] Width of window */
1813 INT nHeight, /* [in] Height of window */
1814 HWND hWndParent, /* [in] Handle to parent window */
1815 HINSTANCE hInstance, /* [in] Handle to application instance */
1816 LPARAM lParam) /* [in] Application-defined value */
1818 FIXME(mdi, "(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld): stub\n",
1819 debugstr_w(lpClassName),debugstr_w(lpWindowName),dwStyle,X,Y,
1820 nWidth,nHeight,hWndParent,hInstance,lParam);
1825 /**********************************************************************
1826 * TranslateMDISysAccel32 (USER32.555)
1828 BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1832 STRUCT32_MSG32to16(msg,&msg16);
1833 /* MDICLIENTINFO is still the same for win32 and win16 ... */
1834 return TranslateMDISysAccel16(hwndClient,&msg16);
1838 /**********************************************************************
1839 * TranslateMDISysAccel16 (USER.451)
1841 BOOL16 WINAPI TranslateMDISysAccel16( HWND16 hwndClient, LPMSG16 msg )
1843 WND* clientWnd = WIN_FindWndPtr( hwndClient);
1845 if( clientWnd && (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN))
1847 MDICLIENTINFO *ci = NULL;
1850 ci = (MDICLIENTINFO*) clientWnd->wExtra;
1851 WIN_ReleaseWndPtr(clientWnd);
1852 wnd = WIN_FindWndPtr(ci->hwndActiveChild);
1853 if( wnd && !(wnd->dwStyle & WS_DISABLED) )
1855 WPARAM16 wParam = 0;
1857 WIN_ReleaseWndPtr(wnd);
1858 /* translate if the Ctrl key is down and Alt not. */
1860 if( (GetKeyState(VK_CONTROL) & 0x8000) &&
1861 !(GetKeyState(VK_MENU) & 0x8000))
1863 switch( msg->wParam )
1867 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 )
1868 ? SC_NEXTWINDOW : SC_PREVWINDOW;
1877 TRACE(mdi,"wParam = %04x\n", wParam);
1878 SendMessage16( ci->hwndActiveChild, WM_SYSCOMMAND,
1879 wParam, (LPARAM)msg->wParam);
1883 WIN_ReleaseWndPtr(wnd);
1885 WIN_ReleaseWndPtr(clientWnd);
1886 return 0; /* failure */
1890 /***********************************************************************
1891 * CalcChildScroll (USER.462)
1893 void WINAPI CalcChildScroll16( HWND16 hwnd, WORD scroll )
1896 RECT childRect, clientRect;
1897 INT vmin, vmax, hmin, hmax, vpos, hpos;
1900 if (!(pWnd = WIN_FindWndPtr( hwnd ))) return;
1901 Wnd = WIN_FindWndPtr(hwnd);
1902 GetClientRect( hwnd, &clientRect );
1903 SetRectEmpty( &childRect );
1905 for ( WIN_UpdateWndPtr(&pWnd,pWnd->child); pWnd; WIN_UpdateWndPtr(&pWnd,pWnd->next))
1907 if( pWnd->dwStyle & WS_MAXIMIZE )
1909 ShowScrollBar(hwnd, SB_BOTH, FALSE);
1910 WIN_ReleaseWndPtr(pWnd);
1911 WIN_ReleaseWndPtr(Wnd);
1914 UnionRect( &childRect, &pWnd->rectWindow, &childRect );
1916 WIN_ReleaseWndPtr(pWnd);
1917 UnionRect( &childRect, &clientRect, &childRect );
1919 hmin = childRect.left; hmax = childRect.right - clientRect.right;
1920 hpos = clientRect.left - childRect.left;
1921 vmin = childRect.top; vmax = childRect.bottom - clientRect.bottom;
1922 vpos = clientRect.top - childRect.top;
1927 vpos = hpos; vmin = hmin; vmax = hmax;
1929 info.cbSize = sizeof(info);
1930 info.nMax = vmax; info.nMin = vmin; info.nPos = vpos;
1931 info.fMask = SIF_POS | SIF_RANGE;
1932 SetScrollInfo(hwnd, scroll, &info, TRUE);
1935 SCROLL_SetNCSbState( Wnd, vmin, vmax, vpos,
1938 WIN_ReleaseWndPtr(Wnd);
1942 /***********************************************************************
1943 * ScrollChildren16 (USER.463)
1945 void WINAPI ScrollChildren16(HWND16 hWnd, UINT16 uMsg, WPARAM16 wParam, LPARAM lParam)
1947 ScrollChildren( hWnd, uMsg, wParam, lParam );
1951 /***********************************************************************
1952 * ScrollChildren32 (USER32.448)
1954 void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
1957 WND *wndPtr = WIN_FindWndPtr(hWnd);
1959 INT curPos, length, minPos, maxPos, shift;
1961 if( !wndPtr ) return;
1963 if( uMsg == WM_HSCROLL )
1965 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
1966 curPos = GetScrollPos(hWnd,SB_HORZ);
1967 length = (wndPtr->rectClient.right - wndPtr->rectClient.left)/2;
1968 shift = SYSMETRICS_CYHSCROLL;
1970 else if( uMsg == WM_VSCROLL )
1972 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
1973 curPos = GetScrollPos(hWnd,SB_VERT);
1974 length = (wndPtr->rectClient.bottom - wndPtr->rectClient.top)/2;
1975 shift = SYSMETRICS_CXVSCROLL;
1979 WIN_ReleaseWndPtr(wndPtr);
1983 WIN_ReleaseWndPtr(wndPtr);
1987 newPos = curPos - shift;
1990 newPos = curPos + shift;
1993 newPos = curPos - length;
1996 newPos = curPos + length;
1999 case SB_THUMBPOSITION:
2000 newPos = LOWORD(lParam);
2013 CalcChildScroll16(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
2017 if( newPos > maxPos )
2020 if( newPos < minPos )
2023 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
2025 if( uMsg == WM_VSCROLL )
2026 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
2027 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2029 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
2030 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2034 /******************************************************************************
2035 * CascadeWindows [USER32.21] Cascades MDI child windows
2038 * Success: Number of cascaded windows.
2042 CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2043 UINT cKids, const HWND *lpKids)
2045 FIXME (mdi, "(0x%08x,0x%08x,...,%u,...): stub\n",
2046 hwndParent, wFlags, cKids);
2052 /******************************************************************************
2053 * TileWindows [USER32.545] Tiles MDI child windows
2056 * Success: Number of tiled windows.
2060 TileWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2061 UINT cKids, const HWND *lpKids)
2063 FIXME (mdi, "(0x%08x,0x%08x,...,%u,...): stub\n",
2064 hwndParent, wFlags, cKids);