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 #define MDIF_NEEDUPDATE 0x0001
33 static HBITMAP16 hBmpClose = 0;
34 static HBITMAP16 hBmpRestore = 0;
36 INT SCROLL_SetNCSbState(WND*,int,int,int,int,int,int);
38 /* ----------------- declarations ----------------- */
39 static void MDI_UpdateFrameText(WND *, HWND, BOOL, LPCSTR);
40 static BOOL MDI_AugmentFrameMenu(MDICLIENTINFO*, WND *, HWND);
41 static BOOL MDI_RestoreFrameMenu(WND *, HWND);
43 static LONG MDI_ChildActivate( WND*, HWND );
45 /* -------- Miscellaneous service functions ----------
50 static HWND MDI_GetChildByID(WND* wndPtr, INT id)
52 for (wndPtr = wndPtr->child; wndPtr; wndPtr = wndPtr->next)
53 if (wndPtr->wIDmenu == id) return wndPtr->hwndSelf;
57 static void MDI_PostUpdate(HWND hwnd, MDICLIENTINFO* ci, WORD recalc)
59 if( !(ci->mdiFlags & MDIF_NEEDUPDATE) )
61 ci->mdiFlags |= MDIF_NEEDUPDATE;
62 PostMessageA( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
64 ci->sbRecalc = recalc;
67 /**********************************************************************
70 static BOOL MDI_MenuModifyItem(WND* clientWnd, HWND hWndChild )
73 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
74 WND *wndPtr = WIN_FindWndPtr(hWndChild);
75 UINT n = sprintf(buffer, "%d ",
76 wndPtr->wIDmenu - clientInfo->idFirstChild + 1);
79 if( !clientInfo->hWindowMenu )
85 if (wndPtr->text) lstrcpynA(buffer + n, wndPtr->text, sizeof(buffer) - n );
87 n = GetMenuState(clientInfo->hWindowMenu,wndPtr->wIDmenu ,MF_BYCOMMAND);
88 bRet = ModifyMenuA(clientInfo->hWindowMenu , wndPtr->wIDmenu,
89 MF_BYCOMMAND | MF_STRING, wndPtr->wIDmenu, buffer );
90 CheckMenuItem(clientInfo->hWindowMenu ,wndPtr->wIDmenu , n & MF_CHECKED);
92 WIN_ReleaseWndPtr(wndPtr);
96 /**********************************************************************
99 static BOOL MDI_MenuDeleteItem(WND* clientWnd, HWND hWndChild )
102 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
103 WND *wndPtr = WIN_FindWndPtr(hWndChild);
107 if( !clientInfo->nActiveChildren ||
108 !clientInfo->hWindowMenu )
114 id = wndPtr->wIDmenu;
115 DeleteMenu(clientInfo->hWindowMenu,id,MF_BYCOMMAND);
117 /* walk the rest of MDI children to prevent gaps in the id
118 * sequence and in the menu child list */
120 for( index = id+1; index <= clientInfo->nActiveChildren +
121 clientInfo->idFirstChild; index++ )
123 WND *tmpWnd = WIN_FindWndPtr(MDI_GetChildByID(clientWnd,index));
126 TRACE(mdi,"no window for id=%i\n",index);
127 WIN_ReleaseWndPtr(tmpWnd);
134 n = sprintf(buffer, "%d ",index - clientInfo->idFirstChild);
136 lstrcpynA(buffer + n, tmpWnd->text, sizeof(buffer) - n );
139 ModifyMenuA(clientInfo->hWindowMenu ,index ,MF_BYCOMMAND | MF_STRING,
140 index - 1 , buffer );
141 WIN_ReleaseWndPtr(tmpWnd);
145 WIN_ReleaseWndPtr(wndPtr);
149 /**********************************************************************
152 * returns "activateable" child different from the current or zero
154 static HWND MDI_GetWindow(WND *clientWnd, HWND hWnd, BOOL bNext,
157 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
158 WND *wndPtr, *pWnd, *pWndLast = NULL;
160 dwStyleMask |= WS_DISABLED | WS_VISIBLE;
161 if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
163 if( !(wndPtr = WIN_FindWndPtr(hWnd)) ) return 0;
165 for ( pWnd = WIN_LockWndPtr(wndPtr->next); ; WIN_UpdateWndPtr(&pWnd,pWnd->next))
167 if (!pWnd ) WIN_UpdateWndPtr(&pWnd,wndPtr->parent->child);
169 if ( pWnd == wndPtr ) break; /* went full circle */
171 if (!pWnd->owner && (pWnd->dwStyle & dwStyleMask) == WS_VISIBLE )
177 WIN_ReleaseWndPtr(wndPtr);
178 WIN_ReleaseWndPtr(pWnd);
179 return pWndLast ? pWndLast->hwndSelf : 0;
182 /**********************************************************************
183 * MDI_CalcDefaultChildPos
185 * It seems that the default height is about 2/3 of the client rect
187 static void MDI_CalcDefaultChildPos( WND* w, WORD n, LPPOINT lpPos,
191 RECT rect = w->rectClient;
192 INT spacing = GetSystemMetrics(SM_CYCAPTION) +
193 GetSystemMetrics(SM_CYFRAME) - 1;
195 if( rect.bottom - rect.top - delta >= spacing )
196 rect.bottom -= delta;
198 nstagger = (rect.bottom - rect.top)/(3 * spacing);
199 lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
200 lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
201 lpPos[0].x = lpPos[0].y = spacing * (n%(nstagger+1));
204 /**********************************************************************
207 static LRESULT MDISetMenu( HWND hwnd, HMENU hmenuFrame,
210 WND *w = WIN_FindWndPtr(hwnd);
212 HWND hwndFrame = GetParent(hwnd);
213 HMENU oldFrameMenu = GetMenu(hwndFrame);
215 TRACE(mdi, "%04x %04x %04x\n",
216 hwnd, hmenuFrame, hmenuWindow);
218 ci = (MDICLIENTINFO *) w->wExtra;
220 if( ci->hwndChildMaximized && hmenuFrame && hmenuFrame!=oldFrameMenu )
221 MDI_RestoreFrameMenu(w->parent, ci->hwndChildMaximized );
223 if( hmenuWindow && hmenuWindow!=ci->hWindowMenu )
225 /* delete menu items from ci->hWindowMenu
226 * and add them to hmenuWindow */
228 INT i = GetMenuItemCount(ci->hWindowMenu) - 1;
229 INT pos = GetMenuItemCount(hmenuWindow) + 1;
231 AppendMenuA( hmenuWindow, MF_SEPARATOR, 0, NULL);
233 if( ci->nActiveChildren )
235 INT j = i - ci->nActiveChildren + 1;
239 for( ; i >= j ; i-- )
241 id = GetMenuItemID(ci->hWindowMenu,i );
242 state = GetMenuState(ci->hWindowMenu,i,MF_BYPOSITION);
244 GetMenuStringA(ci->hWindowMenu, i, buffer, 100, MF_BYPOSITION);
246 DeleteMenu(ci->hWindowMenu, i , MF_BYPOSITION);
247 InsertMenuA(hmenuWindow, pos, MF_BYPOSITION | MF_STRING,
249 CheckMenuItem(hmenuWindow ,pos , MF_BYPOSITION | (state & MF_CHECKED));
253 /* remove separator */
254 DeleteMenu(ci->hWindowMenu, i, MF_BYPOSITION);
256 ci->hWindowMenu = hmenuWindow;
259 if( hmenuFrame && hmenuFrame!=oldFrameMenu)
261 SetMenu(hwndFrame, hmenuFrame);
262 if( ci->hwndChildMaximized )
263 MDI_AugmentFrameMenu(ci, w->parent, ci->hwndChildMaximized );
264 WIN_ReleaseWndPtr(w);
267 WIN_ReleaseWndPtr(w);
271 /**********************************************************************
274 static LRESULT MDIRefreshMenu( HWND hwnd, HMENU hmenuFrame,
277 HWND hwndFrame = GetParent(hwnd);
278 HMENU oldFrameMenu = GetMenu(hwndFrame);
280 TRACE(mdi, "%04x %04x %04x\n",
281 hwnd, hmenuFrame, hmenuWindow);
283 FIXME(mdi,"partially function stub\n");
289 /* ------------------ MDI child window functions ---------------------- */
292 /**********************************************************************
295 static HWND MDICreateChild( WND *w, MDICLIENTINFO *ci, HWND parent,
296 LPMDICREATESTRUCTA cs )
299 DWORD style = cs->style | (WS_CHILD | WS_CLIPSIBLINGS);
300 HWND hwnd, hwndMax = 0;
301 WORD wIDmenu = ci->idFirstChild + ci->nActiveChildren;
302 char lpstrDef[]="junk!";
304 TRACE(mdi, "origin %i,%i - dim %i,%i, style %08x\n",
305 cs->x, cs->y, cs->cx, cs->cy, (unsigned)cs->style);
306 /* calculate placement */
307 MDI_CalcDefaultChildPos(w, ci->nTotalCreated++, pos, 0);
309 if (cs->cx == CW_USEDEFAULT || !cs->cx) cs->cx = pos[1].x;
310 if (cs->cy == CW_USEDEFAULT || !cs->cy) cs->cy = pos[1].y;
312 if( cs->x == CW_USEDEFAULT )
318 /* restore current maximized child */
319 if( style & WS_VISIBLE && ci->hwndChildMaximized )
321 if( style & WS_MAXIMIZE )
322 SendMessageA(w->hwndSelf, WM_SETREDRAW, FALSE, 0L );
323 hwndMax = ci->hwndChildMaximized;
324 ShowWindow( hwndMax, SW_SHOWNOACTIVATE );
325 if( style & WS_MAXIMIZE )
326 SendMessageA(w->hwndSelf, WM_SETREDRAW, TRUE, 0L );
329 /* this menu is needed to set a check mark in MDI_ChildActivate */
330 AppendMenuA(ci->hWindowMenu ,MF_STRING ,wIDmenu, lpstrDef );
332 ci->nActiveChildren++;
334 /* fix window style */
335 if( !(w->dwStyle & MDIS_ALLCHILDSTYLES) )
337 style &= (WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZE | WS_MAXIMIZE |
338 WS_CLIPCHILDREN | WS_DISABLED | WS_VSCROLL | WS_HSCROLL );
339 style |= (WS_VISIBLE | WS_OVERLAPPEDWINDOW);
342 if( w->flags & WIN_ISWIN32 )
344 hwnd = CreateWindowA( cs->szClass, cs->szTitle, style,
345 cs->x, cs->y, cs->cx, cs->cy, parent,
346 (HMENU16)wIDmenu, cs->hOwner, cs );
350 MDICREATESTRUCT16 *cs16;
353 cs16 = SEGPTR_NEW(MDICREATESTRUCT16);
354 STRUCT32_MDICREATESTRUCT32Ato16( cs, cs16 );
355 title = SEGPTR_STRDUP( cs->szTitle );
356 cls = SEGPTR_STRDUP( cs->szClass );
357 cs16->szTitle = SEGPTR_GET(title);
358 cs16->szClass = SEGPTR_GET(cls);
360 hwnd = CreateWindow16( cs->szClass, cs->szTitle, style,
361 cs16->x, cs16->y, cs16->cx, cs16->cy, parent,
362 (HMENU)wIDmenu, cs16->hOwner,
363 (LPVOID)SEGPTR_GET(cs16) );
364 SEGPTR_FREE( title );
369 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
373 WND* wnd = WIN_FindWndPtr( hwnd );
375 MDI_MenuModifyItem(w ,hwnd);
376 if( wnd->dwStyle & WS_MINIMIZE && ci->hwndActiveChild )
377 ShowWindow( hwnd, SW_SHOWMINNOACTIVE );
380 /* WS_VISIBLE is clear if a) the MDI client has
381 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
382 * MDICreateStruct. If so the created window is not shown nor
385 int showflag=wnd->dwStyle & WS_VISIBLE;
386 /* clear visible flag, otherwise SetWindoPos32 ignores
387 * the SWP_SHOWWINDOW command.
389 wnd->dwStyle &= ~WS_VISIBLE;
391 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE );
393 /* Set maximized state here in case hwnd didn't receive WM_SIZE
394 * during CreateWindow - bad!
397 if((wnd->dwStyle & WS_MAXIMIZE) && !ci->hwndChildMaximized )
399 ci->hwndChildMaximized = wnd->hwndSelf;
400 MDI_AugmentFrameMenu( ci, w->parent, hwnd );
401 MDI_UpdateFrameText( w->parent, ci->self, MDI_REPAINTFRAME, NULL );
404 /* needed, harmless ? */
405 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE );
408 WIN_ReleaseWndPtr(wnd);
409 TRACE(mdi, "created child - %04x\n",hwnd);
413 ci->nActiveChildren--;
414 DeleteMenu(ci->hWindowMenu,wIDmenu,MF_BYCOMMAND);
415 if( IsWindow(hwndMax) )
416 ShowWindow(hwndMax, SW_SHOWMAXIMIZED);
422 /**********************************************************************
423 * MDI_ChildGetMinMaxInfo
425 * Note: The rule here is that client rect of the maximized MDI child
426 * is equal to the client rect of the MDI client window.
428 static void MDI_ChildGetMinMaxInfo( WND* clientWnd, HWND hwnd,
429 MINMAXINFO16* lpMinMax )
431 WND* childWnd = WIN_FindWndPtr(hwnd);
432 RECT rect = clientWnd->rectClient;
434 MapWindowPoints( clientWnd->parent->hwndSelf,
435 ((MDICLIENTINFO*)clientWnd->wExtra)->self, (LPPOINT)&rect, 2);
436 AdjustWindowRectEx( &rect, childWnd->dwStyle, 0, childWnd->dwExStyle );
438 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
439 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
441 lpMinMax->ptMaxPosition.x = rect.left;
442 lpMinMax->ptMaxPosition.y = rect.top;
444 WIN_ReleaseWndPtr(childWnd);
446 TRACE(mdi,"max rect (%i,%i - %i, %i)\n",
447 rect.left,rect.top,rect.right,rect.bottom);
451 /**********************************************************************
452 * MDI_SwitchActiveChild
454 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
457 static void MDI_SwitchActiveChild( HWND clientHwnd, HWND childHwnd,
460 WND *w = WIN_FindWndPtr(clientHwnd);
465 hwndTo = MDI_GetWindow(w, childHwnd, bNextWindow, 0);
467 ci = (MDICLIENTINFO *) w->wExtra;
469 TRACE(mdi, "from %04x, to %04x\n",childHwnd,hwndTo);
471 if ( !hwndTo ) goto END; /* no window to switch to */
473 hwndPrev = ci->hwndActiveChild;
475 if ( hwndTo != hwndPrev )
479 if( ci->hwndChildMaximized )
482 w->dwStyle &= ~WS_VISIBLE;
485 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0,
486 SWP_NOMOVE | SWP_NOSIZE );
488 if( bNextWindow && hwndPrev )
489 SetWindowPos( hwndPrev, HWND_BOTTOM, 0, 0, 0, 0,
490 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
492 ShowWindow( clientHwnd, SW_SHOW );
495 WIN_ReleaseWndPtr(w);
499 /**********************************************************************
502 static LRESULT MDIDestroyChild( WND *w_parent, MDICLIENTINFO *ci,
503 HWND parent, HWND child,
506 WND *childPtr = WIN_FindWndPtr(child);
510 if( child == ci->hwndActiveChild )
512 MDI_SwitchActiveChild(parent, child, TRUE);
514 if( child == ci->hwndActiveChild )
516 ShowWindow( child, SW_HIDE);
517 if( child == ci->hwndChildMaximized )
519 MDI_RestoreFrameMenu(w_parent->parent, child);
520 ci->hwndChildMaximized = 0;
521 MDI_UpdateFrameText(w_parent->parent,parent,TRUE,NULL);
524 MDI_ChildActivate(w_parent, 0);
526 MDI_MenuDeleteItem(w_parent, child);
528 WIN_ReleaseWndPtr(childPtr);
530 ci->nActiveChildren--;
532 TRACE(mdi,"child destroyed - %04x\n",child);
536 MDI_PostUpdate(GetParent(child), ci, SB_BOTH+1);
537 DestroyWindow(child);
545 /**********************************************************************
548 * Note: hWndChild is NULL when last child is being destroyed
550 static LONG MDI_ChildActivate( WND *clientPtr, HWND hWndChild )
552 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientPtr->wExtra;
553 HWND prevActiveWnd = clientInfo->hwndActiveChild;
554 WND *wndPtr = WIN_FindWndPtr( hWndChild );
555 WND *wndPrev = WIN_FindWndPtr( prevActiveWnd );
556 BOOL isActiveFrameWnd = 0;
559 if( hWndChild == prevActiveWnd )
567 if( wndPtr->dwStyle & WS_DISABLED )
574 TRACE(mdi,"%04x\n", hWndChild);
576 if( GetActiveWindow() == clientPtr->parent->hwndSelf )
577 isActiveFrameWnd = TRUE;
579 /* deactivate prev. active child */
582 wndPrev->dwStyle |= WS_SYSMENU;
583 SendMessageA( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
584 SendMessageA( prevActiveWnd, WM_MDIACTIVATE, (WPARAM)prevActiveWnd,
586 /* uncheck menu item */
587 if( clientInfo->hWindowMenu )
588 CheckMenuItem( clientInfo->hWindowMenu,
589 wndPrev->wIDmenu, 0);
593 if( clientInfo->hwndChildMaximized )
595 if( clientInfo->hwndChildMaximized != hWndChild ) {
597 clientInfo->hwndActiveChild = hWndChild;
598 ShowWindow( hWndChild, SW_SHOWMAXIMIZED);
600 ShowWindow( clientInfo->hwndActiveChild, SW_SHOWNORMAL );
604 clientInfo->hwndActiveChild = hWndChild;
606 /* check if we have any children left */
609 if( isActiveFrameWnd )
610 SetFocus( clientInfo->self );
615 /* check menu item */
616 if( clientInfo->hWindowMenu )
617 CheckMenuItem( clientInfo->hWindowMenu,
618 wndPtr->wIDmenu, MF_CHECKED);
620 /* bring active child to the top */
621 SetWindowPos( hWndChild, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
623 if( isActiveFrameWnd )
625 SendMessageA( hWndChild, WM_NCACTIVATE, TRUE, 0L);
626 if( GetFocus() == clientInfo->self )
627 SendMessageA( clientInfo->self, WM_SETFOCUS,
628 (WPARAM)clientInfo->self, 0L );
630 SetFocus( clientInfo->self );
632 SendMessageA( hWndChild, WM_MDIACTIVATE, (WPARAM)prevActiveWnd,
636 WIN_ReleaseWndPtr(wndPtr);
637 WIN_ReleaseWndPtr(wndPrev);
641 /* -------------------- MDI client window functions ------------------- */
643 /**********************************************************************
644 * CreateMDIMenuBitmap
646 static HBITMAP16 CreateMDIMenuBitmap(void)
648 HDC hDCSrc = CreateCompatibleDC(0);
649 HDC hDCDest = CreateCompatibleDC(hDCSrc);
650 HBITMAP16 hbClose = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_CLOSE) );
652 HANDLE16 hobjSrc, hobjDest;
654 hobjSrc = SelectObject(hDCSrc, hbClose);
655 hbCopy = CreateCompatibleBitmap(hDCSrc,SYSMETRICS_CXSIZE,SYSMETRICS_CYSIZE);
656 hobjDest = SelectObject(hDCDest, hbCopy);
658 BitBlt(hDCDest, 0, 0, SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE,
659 hDCSrc, SYSMETRICS_CXSIZE, 0, SRCCOPY);
661 SelectObject(hDCSrc, hobjSrc);
662 DeleteObject(hbClose);
665 hobjSrc = SelectObject( hDCDest, GetStockObject(BLACK_PEN) );
667 MoveToEx( hDCDest, SYSMETRICS_CXSIZE - 1, 0, NULL );
668 LineTo( hDCDest, SYSMETRICS_CXSIZE - 1, SYSMETRICS_CYSIZE - 1);
670 SelectObject(hDCDest, hobjSrc );
671 SelectObject(hDCDest, hobjDest);
677 /**********************************************************************
680 static LONG MDICascade(WND* clientWnd, MDICLIENTINFO *ci)
685 if (ci->hwndChildMaximized)
686 SendMessageA( clientWnd->hwndSelf, WM_MDIRESTORE,
687 (WPARAM)ci->hwndChildMaximized, 0);
689 if (ci->nActiveChildren == 0) return 0;
691 if ((ppWnd = WIN_BuildWinArray(clientWnd, BWA_SKIPHIDDEN | BWA_SKIPOWNED |
692 BWA_SKIPICONIC, &total)))
694 WND** heapPtr = ppWnd;
697 INT delta = 0, n = 0;
699 if( total < ci->nActiveChildren )
700 delta = SYSMETRICS_CYICONSPACING + SYSMETRICS_CYICON;
702 /* walk the list (backwards) and move windows */
703 while (*ppWnd) ppWnd++;
704 while (ppWnd != heapPtr)
707 TRACE(mdi, "move %04x to (%ld,%ld) size [%ld,%ld]\n",
708 (*ppWnd)->hwndSelf, pos[0].x, pos[0].y, pos[1].x, pos[1].y);
710 MDI_CalcDefaultChildPos(clientWnd, n++, pos, delta);
711 SetWindowPos( (*ppWnd)->hwndSelf, 0, pos[0].x, pos[0].y,
713 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
716 WIN_ReleaseWinArray(heapPtr);
719 if( total < ci->nActiveChildren )
720 ArrangeIconicWindows( clientWnd->hwndSelf );
724 /**********************************************************************
727 static void MDITile( WND* wndClient, MDICLIENTINFO *ci, WPARAM wParam )
732 if (ci->hwndChildMaximized)
733 SendMessageA( wndClient->hwndSelf, WM_MDIRESTORE,
734 (WPARAM)ci->hwndChildMaximized, 0);
736 if (ci->nActiveChildren == 0) return;
738 ppWnd = WIN_BuildWinArray(wndClient, BWA_SKIPHIDDEN | BWA_SKIPOWNED | BWA_SKIPICONIC |
739 ((wParam & MDITILE_SKIPDISABLED)? BWA_SKIPDISABLED : 0), &total );
741 TRACE(mdi,"%u windows to tile\n", total);
745 WND** heapPtr = ppWnd;
750 int x, y, xsize, ysize;
751 int rows, columns, r, c, i;
753 rect = wndClient->rectClient;
754 rows = (int) sqrt((double)total);
755 columns = total / rows;
757 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
760 rows = columns; /* exchange r and c */
764 if( total != ci->nActiveChildren)
766 y = rect.bottom - 2 * SYSMETRICS_CYICONSPACING - SYSMETRICS_CYICON;
767 rect.bottom = ( y - SYSMETRICS_CYICON < rect.top )? rect.bottom: y;
770 ysize = rect.bottom / rows;
771 xsize = rect.right / columns;
773 for (x = i = 0, c = 1; c <= columns && *ppWnd; c++)
778 ysize = rect.bottom / rows;
782 for (r = 1; r <= rows && *ppWnd; r++, i++)
784 SetWindowPos((*ppWnd)->hwndSelf, 0, x, y, xsize, ysize,
785 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
792 WIN_ReleaseWinArray(heapPtr);
795 if( total < ci->nActiveChildren ) ArrangeIconicWindows( wndClient->hwndSelf );
798 /* ----------------------- Frame window ---------------------------- */
801 /**********************************************************************
802 * MDI_AugmentFrameMenu
804 static BOOL MDI_AugmentFrameMenu( MDICLIENTINFO* ci, WND *frame,
807 WND* child = WIN_FindWndPtr(hChild);
810 TRACE(mdi,"frame %p,child %04x\n",frame,hChild);
812 if( !frame->wIDmenu || !child->hSysMenu )
814 WIN_ReleaseWndPtr(child);
817 WIN_ReleaseWndPtr(child);
819 /* create a copy of sysmenu popup and insert it into frame menu bar */
821 if (!(hSysPopup = LoadMenuIndirectA(SYSRES_GetResPtr(SYSRES_MENU_SYSMENU))))
824 TRACE(mdi,"\tgot popup %04x in sysmenu %04x\n",
825 hSysPopup, child->hSysMenu);
827 AppendMenuA(frame->wIDmenu,MF_HELP | MF_BITMAP,
828 SC_MINIMIZE, (LPSTR)(DWORD)MAGIC_REDUCE ) ;
829 AppendMenuA(frame->wIDmenu,MF_HELP | MF_BITMAP,
830 SC_RESTORE, (LPSTR)(DWORD)MAGIC_RESTORE );
832 if( !InsertMenuA(frame->wIDmenu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
833 hSysPopup, (LPSTR)(DWORD)hBmpClose ))
835 TRACE(mdi,"not inserted\n");
836 DestroyMenu(hSysPopup);
840 // The close button is only present in Win 95 look
841 if(TWEAK_WineLook > WIN31_LOOK)
843 AppendMenuA(frame->wIDmenu,MF_HELP | MF_BITMAP,
844 SC_CLOSE, (LPSTR)(DWORD)MAGIC_CLOSE );
847 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
848 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
849 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
852 DrawMenuBar(frame->hwndSelf);
857 /**********************************************************************
858 * MDI_RestoreFrameMenu
860 static BOOL MDI_RestoreFrameMenu( WND *frameWnd, HWND hChild )
862 INT nItems = GetMenuItemCount(frameWnd->wIDmenu) - 1;
863 UINT iId = GetMenuItemID(frameWnd->wIDmenu,nItems) ;
865 TRACE(mdi,"frameWnd %p,child %04x\n",frameWnd,hChild);
867 if(!(iId == SC_RESTORE || iId == SC_CLOSE) )
871 RemoveMenu(frameWnd->wIDmenu,0,MF_BYPOSITION);
873 if(TWEAK_WineLook > WIN31_LOOK)
876 DeleteMenu(frameWnd->wIDmenu,GetMenuItemCount(frameWnd->wIDmenu) - 1,MF_BYPOSITION);
879 DeleteMenu(frameWnd->wIDmenu,GetMenuItemCount(frameWnd->wIDmenu) - 1,MF_BYPOSITION);
881 DeleteMenu(frameWnd->wIDmenu,GetMenuItemCount(frameWnd->wIDmenu) - 1,MF_BYPOSITION);
883 DrawMenuBar(frameWnd->hwndSelf);
889 /**********************************************************************
890 * MDI_UpdateFrameText
892 * used when child window is maximized/restored
894 * Note: lpTitle can be NULL
896 static void MDI_UpdateFrameText( WND *frameWnd, HWND hClient,
897 BOOL repaint, LPCSTR lpTitle )
899 char lpBuffer[MDI_MAXTITLELENGTH+1];
900 WND* clientWnd = WIN_FindWndPtr(hClient);
901 MDICLIENTINFO *ci = (MDICLIENTINFO *) clientWnd->wExtra;
903 TRACE(mdi, "repaint %i, frameText %s\n", repaint, (lpTitle)?lpTitle:"NULL");
910 WIN_ReleaseWndPtr(clientWnd);
914 /* store new "default" title if lpTitle is not NULL */
917 if (ci->frameTitle) HeapFree( SystemHeap, 0, ci->frameTitle );
918 ci->frameTitle = HEAP_strdupA( SystemHeap, 0, lpTitle );
923 WND* childWnd = WIN_FindWndPtr( ci->hwndChildMaximized );
925 if( childWnd && childWnd->text )
927 /* combine frame title and child title if possible */
929 LPCSTR lpBracket = " - [";
930 int i_frame_text_length = strlen(ci->frameTitle);
931 int i_child_text_length = strlen(childWnd->text);
933 lstrcpynA( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
935 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
937 strcat( lpBuffer, lpBracket );
939 if( i_frame_text_length + i_child_text_length + 6 < MDI_MAXTITLELENGTH )
941 strcat( lpBuffer, childWnd->text );
942 strcat( lpBuffer, "]" );
946 lstrcpynA( lpBuffer + i_frame_text_length + 4,
947 childWnd->text, MDI_MAXTITLELENGTH - i_frame_text_length - 5 );
948 strcat( lpBuffer, "]" );
954 strncpy(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH );
955 lpBuffer[MDI_MAXTITLELENGTH]='\0';
957 WIN_ReleaseWndPtr(childWnd);
963 DEFWND_SetText( frameWnd, lpBuffer );
964 if( repaint == MDI_REPAINTFRAME)
965 SetWindowPos( frameWnd->hwndSelf, 0,0,0,0,0, SWP_FRAMECHANGED |
966 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
968 WIN_ReleaseWndPtr(clientWnd);
973 /* ----------------------------- Interface ---------------------------- */
976 /**********************************************************************
979 * This function handles all MDI requests.
981 LRESULT WINAPI MDIClientWndProc( HWND hwnd, UINT message, WPARAM wParam,
987 WND *w = WIN_FindWndPtr(hwnd);
988 WND *frameWnd = WIN_LockWndPtr(w->parent);
992 ci = (MDICLIENTINFO *) w->wExtra;
998 cs = (LPCREATESTRUCTA)lParam;
1000 /* Translation layer doesn't know what's in the cs->lpCreateParams
1001 * so we have to keep track of what environment we're in. */
1003 if( w->flags & WIN_ISWIN32 )
1005 #define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1006 ci->hWindowMenu = ccs->hWindowMenu;
1007 ci->idFirstChild = ccs->idFirstChild;
1012 LPCLIENTCREATESTRUCT16 ccs = (LPCLIENTCREATESTRUCT16)
1013 PTR_SEG_TO_LIN(cs->lpCreateParams);
1014 ci->hWindowMenu = ccs->hWindowMenu;
1015 ci->idFirstChild = ccs->idFirstChild;
1018 ci->hwndChildMaximized = 0;
1019 ci->nActiveChildren = 0;
1020 ci->nTotalCreated = 0;
1021 ci->frameTitle = NULL;
1024 w->dwStyle |= WS_CLIPCHILDREN;
1028 hBmpClose = CreateMDIMenuBitmap();
1029 hBmpRestore = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_RESTORE) );
1031 MDI_UpdateFrameText(frameWnd, hwnd, MDI_NOFRAMEREPAINT,frameWnd->text);
1033 AppendMenuA( ci->hWindowMenu, MF_SEPARATOR, 0, NULL );
1035 GetClientRect(frameWnd->hwndSelf, &rect);
1036 NC_HandleNCCalcSize( w, &rect );
1037 w->rectClient = rect;
1039 TRACE(mdi,"Client created - hwnd = %04x, idFirst = %u\n",
1040 hwnd, ci->idFirstChild );
1046 if( ci->hwndChildMaximized ) MDI_RestoreFrameMenu(w, frameWnd->hwndSelf);
1047 if((nItems = GetMenuItemCount(ci->hWindowMenu)) > 0)
1049 ci->idFirstChild = nItems - 1;
1050 ci->nActiveChildren++; /* to delete a separator */
1051 while( ci->nActiveChildren-- )
1052 DeleteMenu(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
1057 case WM_MDIACTIVATE:
1058 if( ci->hwndActiveChild != (HWND)wParam )
1059 SetWindowPos((HWND)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
1064 retvalue = MDICascade(w, ci);
1068 if (lParam) retvalue = MDICreateChild( w, ci, hwnd,
1069 (MDICREATESTRUCTA*)lParam );
1074 retvalue = MDIDestroyChild( w, ci, hwnd, (HWND)wParam, TRUE );
1077 case WM_MDIGETACTIVE:
1078 if (lParam) *(BOOL *)lParam = (ci->hwndChildMaximized > 0);
1079 retvalue = ci->hwndActiveChild;
1082 case WM_MDIICONARRANGE:
1083 ci->mdiFlags |= MDIF_NEEDUPDATE;
1084 ArrangeIconicWindows(hwnd);
1085 ci->sbRecalc = SB_BOTH+1;
1086 SendMessageA(hwnd, WM_MDICALCCHILDSCROLL, 0, 0L);
1090 case WM_MDIMAXIMIZE:
1091 ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1095 case WM_MDINEXT: /* lParam != 0 means previous window */
1096 MDI_SwitchActiveChild(hwnd, (HWND)wParam, (lParam)? FALSE : TRUE );
1100 SendMessageA( (HWND)wParam, WM_SYSCOMMAND, SC_RESTORE, 0);
1105 retvalue = MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1107 case WM_MDIREFRESHMENU:
1108 retvalue = MDIRefreshMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1112 ci->mdiFlags |= MDIF_NEEDUPDATE;
1113 ShowScrollBar(hwnd,SB_BOTH,FALSE);
1114 MDITile(w, ci, wParam);
1115 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1121 ci->mdiFlags |= MDIF_NEEDUPDATE;
1122 ScrollChildren(hwnd, message, wParam, lParam);
1123 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1128 if( ci->hwndActiveChild )
1130 w = WIN_FindWndPtr( ci->hwndActiveChild );
1131 if( !(w->dwStyle & WS_MINIMIZE) )
1132 SetFocus( ci->hwndActiveChild );
1138 if( ci->hwndActiveChild )
1139 SendMessageA(ci->hwndActiveChild, message, wParam, lParam);
1142 case WM_PARENTNOTIFY:
1143 if (LOWORD(wParam) == WM_LBUTTONDOWN)
1145 POINT16 pt = MAKEPOINT16(lParam);
1146 HWND16 child = ChildWindowFromPoint16(hwnd, pt);
1148 TRACE(mdi,"notification from %04x (%i,%i)\n",child,pt.x,pt.y);
1150 if( child && child != hwnd && child != ci->hwndActiveChild )
1151 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1157 if( IsWindow(ci->hwndChildMaximized) )
1159 WND* child = WIN_FindWndPtr(ci->hwndChildMaximized);
1160 RECT rect = { 0, 0, LOWORD(lParam), HIWORD(lParam) };
1162 AdjustWindowRectEx(&rect, child->dwStyle, 0, child->dwExStyle);
1163 MoveWindow(ci->hwndChildMaximized, rect.left, rect.top,
1164 rect.right - rect.left, rect.bottom - rect.top, 1);
1165 WIN_ReleaseWndPtr(child);
1168 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1172 case WM_MDICALCCHILDSCROLL:
1173 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1175 CalcChildScroll16(hwnd, ci->sbRecalc-1);
1177 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1183 retvalue = DefWindowProcA( hwnd, message, wParam, lParam );
1185 WIN_ReleaseWndPtr(w);
1186 WIN_ReleaseWndPtr(frameWnd);
1191 /***********************************************************************
1192 * DefFrameProc16 (USER.445)
1194 LRESULT WINAPI DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient,
1195 UINT16 message, WPARAM16 wParam, LPARAM lParam )
1206 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1209 ERR(mdi,"null wndPtr for mdi window hwndMDIClient=%04x\n",
1214 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1216 /* check for possible syscommands for maximized MDI child */
1217 WIN_ReleaseWndPtr(wndPtr);
1220 wParam < ci->idFirstChild ||
1221 wParam >= ci->idFirstChild + ci->nActiveChildren
1223 if( (wParam - 0xF000) & 0xF00F ) break;
1234 if( ci->hwndChildMaximized )
1235 return SendMessage16( ci->hwndChildMaximized, WM_SYSCOMMAND,
1241 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1242 childHwnd = MDI_GetChildByID(wndPtr,wParam );
1243 WIN_ReleaseWndPtr(wndPtr);
1246 SendMessage16(hwndMDIClient, WM_MDIACTIVATE,
1247 (WPARAM16)childHwnd , 0L);
1252 SendMessage16(hwndMDIClient, message, wParam, lParam);
1256 wndPtr = WIN_FindWndPtr(hwnd);
1257 MDI_UpdateFrameText(wndPtr, hwndMDIClient,
1259 (LPCSTR)PTR_SEG_TO_LIN(lParam));
1260 WIN_ReleaseWndPtr(wndPtr);
1264 SetFocus(hwndMDIClient);
1268 MoveWindow16(hwndMDIClient, 0, 0,
1269 LOWORD(lParam), HIWORD(lParam), TRUE);
1274 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1275 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1277 if( !(wndPtr->parent->dwStyle & WS_MINIMIZE)
1278 && ci->hwndActiveChild && !ci->hwndChildMaximized )
1280 /* control menu is between the frame system menu and
1281 * the first entry of menu bar */
1283 if( (wParam == VK_LEFT &&
1284 wndPtr->parent->wIDmenu == LOWORD(lParam)) ||
1285 (wParam == VK_RIGHT &&
1286 GetSubMenu16(wndPtr->parent->hSysMenu, 0) == LOWORD(lParam)) )
1289 WIN_ReleaseWndPtr(wndPtr);
1290 wndPtr = WIN_FindWndPtr(ci->hwndActiveChild);
1291 retvalue = MAKELONG( GetSubMenu16(wndPtr->hSysMenu, 0),
1292 ci->hwndActiveChild);
1293 WIN_ReleaseWndPtr(wndPtr);
1297 WIN_ReleaseWndPtr(wndPtr);
1302 return DefWindowProc16(hwnd, message, wParam, lParam);
1306 /***********************************************************************
1307 * DefFrameProc32A (USER32.122)
1309 LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1310 UINT message, WPARAM wParam, LPARAM lParam)
1317 return DefFrameProc16( hwnd, hwndMDIClient, message,
1319 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1322 SendMessageA(hwndMDIClient, message, wParam, lParam);
1327 LPSTR segstr = SEGPTR_STRDUP((LPSTR)lParam);
1329 ret = DefFrameProc16(hwnd, hwndMDIClient, message,
1330 wParam, (LPARAM)SEGPTR_GET(segstr) );
1331 SEGPTR_FREE(segstr);
1338 return DefFrameProc16( hwnd, hwndMDIClient, message,
1343 return DefWindowProcA(hwnd, message, wParam, lParam);
1347 /***********************************************************************
1348 * DefFrameProc32W (USER32.123)
1350 LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1351 UINT message, WPARAM wParam, LPARAM lParam)
1358 return DefFrameProc16( hwnd, hwndMDIClient, message,
1360 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1363 SendMessageW(hwndMDIClient, message, wParam, lParam);
1368 LPSTR txt = HEAP_strdupWtoA(GetProcessHeap(),0,(LPWSTR)lParam);
1369 LRESULT ret = DefFrameProcA( hwnd, hwndMDIClient, message,
1370 wParam, (DWORD)txt );
1371 HeapFree(GetProcessHeap(),0,txt);
1377 return DefFrameProcA( hwnd, hwndMDIClient, message,
1382 return DefWindowProcW( hwnd, message, wParam, lParam );
1386 /***********************************************************************
1387 * DefMDIChildProc16 (USER.447)
1389 LRESULT WINAPI DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1390 WPARAM16 wParam, LPARAM lParam )
1393 WND *clientWnd,*tmpWnd = 0;
1396 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1397 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1402 DefWindowProc16(hwnd, message, wParam, lParam);
1403 MDI_MenuModifyItem(clientWnd,hwnd);
1404 if( ci->hwndChildMaximized == hwnd )
1405 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1406 MDI_REPAINTFRAME, NULL );
1411 SendMessage16(ci->self,WM_MDIDESTROY,(WPARAM16)hwnd,0L);
1416 if( ci->hwndActiveChild != hwnd )
1417 MDI_ChildActivate(clientWnd, hwnd);
1420 case WM_CHILDACTIVATE:
1421 MDI_ChildActivate(clientWnd, hwnd);
1426 TRACE(mdi,"WM_NCPAINT for %04x, active %04x\n",
1427 hwnd, ci->hwndActiveChild );
1434 if( ci->hwndChildMaximized == hwnd)
1442 tmpWnd = WIN_FindWndPtr(hwnd);
1443 tmpWnd->dwStyle |= WS_SYSMENU;
1444 WIN_ReleaseWndPtr(tmpWnd);
1447 if( ci->hwndChildMaximized == hwnd)
1449 retvalue = SendMessage16( clientWnd->parent->hwndSelf,
1450 message, wParam, lParam);
1453 tmpWnd = WIN_FindWndPtr(hwnd);
1454 tmpWnd->dwStyle &= ~WS_SYSMENU;
1455 WIN_ReleaseWndPtr(tmpWnd);
1458 SendMessage16( ci->self, WM_MDINEXT, 0, 0);
1462 SendMessage16( ci->self, WM_MDINEXT, 0, 1);
1468 case WM_GETMINMAXINFO:
1469 MDI_ChildGetMinMaxInfo(clientWnd, hwnd, (MINMAXINFO16*) PTR_SEG_TO_LIN(lParam));
1474 if( ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1476 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1482 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1484 ci->hwndChildMaximized = 0;
1486 MDI_RestoreFrameMenu( clientWnd->parent, hwnd);
1487 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1488 MDI_REPAINTFRAME, NULL );
1491 if( wParam == SIZE_MAXIMIZED )
1493 HWND16 hMaxChild = ci->hwndChildMaximized;
1495 if( hMaxChild == hwnd ) break;
1499 SendMessage16( hMaxChild, WM_SETREDRAW, FALSE, 0L );
1501 MDI_RestoreFrameMenu( clientWnd->parent, hMaxChild);
1502 ShowWindow16( hMaxChild, SW_SHOWNOACTIVATE);
1504 SendMessage16( hMaxChild, WM_SETREDRAW, TRUE, 0L );
1507 TRACE(mdi,"maximizing child %04x\n", hwnd );
1509 ci->hwndChildMaximized = hwnd; /* !!! */
1510 ci->hwndActiveChild = hwnd;
1512 MDI_AugmentFrameMenu( ci, clientWnd->parent, hwnd);
1513 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1514 MDI_REPAINTFRAME, NULL );
1517 if( wParam == SIZE_MINIMIZED )
1519 HWND16 switchTo = MDI_GetWindow(clientWnd, hwnd, TRUE, WS_MINIMIZE);
1522 SendMessage16( switchTo, WM_CHILDACTIVATE, 0, 0L);
1525 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1530 /* MDI children don't have menu bars */
1531 PostMessage16( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1532 (WPARAM16)SC_KEYMENU, (LPARAM)wParam);
1533 retvalue = 0x00010000L;
1538 if( wParam == VK_LEFT ) /* switch to frame system menu */
1540 retvalue = MAKELONG( GetSubMenu16(clientWnd->parent->hSysMenu, 0),
1541 clientWnd->parent->hwndSelf );
1544 if( wParam == VK_RIGHT ) /* to frame menu bar */
1546 retvalue = MAKELONG( clientWnd->parent->wIDmenu,
1547 clientWnd->parent->hwndSelf );
1556 SendMessage16(hwnd,WM_SYSCOMMAND,
1557 (WPARAM16)SC_KEYMENU, (LPARAM)(DWORD)VK_SPACE);
1563 retvalue = DefWindowProc16(hwnd, message, wParam, lParam);
1565 WIN_ReleaseWndPtr(clientWnd);
1570 /***********************************************************************
1571 * DefMDIChildProc32A (USER32.124)
1573 LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1574 WPARAM wParam, LPARAM lParam )
1577 WND *clientWnd,*tmpWnd;
1580 tmpWnd = WIN_FindWndPtr(hwnd);
1581 clientWnd = WIN_FindWndPtr(tmpWnd->parent->hwndSelf);
1582 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1583 WIN_ReleaseWndPtr(tmpWnd);
1588 DefWindowProcA(hwnd, message, wParam, lParam);
1589 MDI_MenuModifyItem(clientWnd,hwnd);
1590 if( ci->hwndChildMaximized == hwnd )
1591 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1592 MDI_REPAINTFRAME, NULL );
1596 case WM_GETMINMAXINFO:
1599 STRUCT32_MINMAXINFO32to16( (MINMAXINFO *)lParam, &mmi );
1600 MDI_ChildGetMinMaxInfo( clientWnd, hwnd, &mmi );
1601 STRUCT32_MINMAXINFO16to32( &mmi, (MINMAXINFO *)lParam );
1608 /* MDI children don't have menu bars */
1609 PostMessage16( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1610 (WPARAM16)SC_KEYMENU, (LPARAM)LOWORD(wParam) );
1611 retvalue = 0x00010000L;
1616 case WM_CHILDACTIVATE:
1622 retvalue = DefMDIChildProc16( hwnd, message, (WPARAM16)wParam, lParam );
1628 SendMessageA(hwnd,WM_SYSCOMMAND,
1629 (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)VK_SPACE);
1634 retvalue = DefWindowProcA(hwnd, message, wParam, lParam);
1636 WIN_ReleaseWndPtr(clientWnd);
1641 /***********************************************************************
1642 * DefMDIChildProc32W (USER32.125)
1644 LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1645 WPARAM wParam, LPARAM lParam )
1651 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1652 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1657 DefWindowProcW(hwnd, message, wParam, lParam);
1658 MDI_MenuModifyItem(clientWnd,hwnd);
1659 if( ci->hwndChildMaximized == hwnd )
1660 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1661 MDI_REPAINTFRAME, NULL );
1665 case WM_GETMINMAXINFO:
1669 case WM_CHILDACTIVATE:
1675 retvalue = DefMDIChildProcA( hwnd, message, (WPARAM16)wParam, lParam );
1681 SendMessageW(hwnd,WM_SYSCOMMAND,
1682 (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)VK_SPACE);
1687 retvalue = DefWindowProcW(hwnd, message, wParam, lParam);
1689 WIN_ReleaseWndPtr(clientWnd);
1695 /**********************************************************************
1696 * CreateMDIWindowA [USER32.79] Creates a MDI child in new thread
1697 * FIXME: its in the same thread now
1700 * Success: Handle to created window
1703 HWND WINAPI CreateMDIWindowA(
1704 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1705 LPCSTR lpWindowName, /* [in] Pointer to window name */
1706 DWORD dwStyle, /* [in] Window style */
1707 INT X, /* [in] Horizontal position of window */
1708 INT Y, /* [in] Vertical position of window */
1709 INT nWidth, /* [in] Width of window */
1710 INT nHeight, /* [in] Height of window */
1711 HWND hWndParent, /* [in] Handle to parent window */
1712 HINSTANCE hInstance, /* [in] Handle to application instance */
1713 LPARAM lParam) /* [in] Application-defined value */
1715 WARN(mdi,"is only single threaded!\n");
1716 return MDI_CreateMDIWindowA(lpClassName, lpWindowName, dwStyle, X, Y,
1717 nWidth, nHeight, hWndParent, hInstance, lParam);
1720 /**********************************************************************
1721 * MDI_CreateMDIWindowA
1722 * single threaded version of CreateMDIWindowA
1723 * called by CreateWindowEx32A
1725 HWND MDI_CreateMDIWindowA(
1727 LPCSTR lpWindowName,
1734 HINSTANCE hInstance,
1738 MDICREATESTRUCTA cs;
1739 WND *pWnd=WIN_FindWndPtr(hWndParent);
1742 TRACE(mdi, "(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
1743 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1744 nWidth,nHeight,hWndParent,hInstance,lParam);
1747 ERR(mdi," bad hwnd for MDI-client: %d\n",hWndParent);
1750 cs.szClass=lpClassName;
1751 cs.szTitle=lpWindowName;
1752 cs.hOwner=hInstance;
1760 pCi=(MDICLIENTINFO *)pWnd->wExtra;
1762 retvalue = MDICreateChild(pWnd,pCi,hWndParent,&cs);
1763 WIN_ReleaseWndPtr(pWnd);
1767 /***************************************
1768 * CreateMDIWindow32W [USER32.80] Creates a MDI child in new thread
1771 * Success: Handle to created window
1774 HWND WINAPI CreateMDIWindowW(
1775 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1776 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1777 DWORD dwStyle, /* [in] Window style */
1778 INT X, /* [in] Horizontal position of window */
1779 INT Y, /* [in] Vertical position of window */
1780 INT nWidth, /* [in] Width of window */
1781 INT nHeight, /* [in] Height of window */
1782 HWND hWndParent, /* [in] Handle to parent window */
1783 HINSTANCE hInstance, /* [in] Handle to application instance */
1784 LPARAM lParam) /* [in] Application-defined value */
1786 FIXME(mdi, "(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld): stub\n",
1787 debugstr_w(lpClassName),debugstr_w(lpWindowName),dwStyle,X,Y,
1788 nWidth,nHeight,hWndParent,hInstance,lParam);
1793 /******************************************************************************
1794 * CreateMDIWindow32W [USER32.80] Creates a MDI child window
1795 * single threaded version of CreateMDIWindow
1796 * called by CreateWindowEx32W().
1798 HWND MDI_CreateMDIWindowW(
1799 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1800 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1801 DWORD dwStyle, /* [in] Window style */
1802 INT X, /* [in] Horizontal position of window */
1803 INT Y, /* [in] Vertical position of window */
1804 INT nWidth, /* [in] Width of window */
1805 INT nHeight, /* [in] Height of window */
1806 HWND hWndParent, /* [in] Handle to parent window */
1807 HINSTANCE hInstance, /* [in] Handle to application instance */
1808 LPARAM lParam) /* [in] Application-defined value */
1810 FIXME(mdi, "(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld): stub\n",
1811 debugstr_w(lpClassName),debugstr_w(lpWindowName),dwStyle,X,Y,
1812 nWidth,nHeight,hWndParent,hInstance,lParam);
1817 /**********************************************************************
1818 * TranslateMDISysAccel32 (USER32.555)
1820 BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1824 STRUCT32_MSG32to16(msg,&msg16);
1825 /* MDICLIENTINFO is still the same for win32 and win16 ... */
1826 return TranslateMDISysAccel16(hwndClient,&msg16);
1830 /**********************************************************************
1831 * TranslateMDISysAccel16 (USER.451)
1833 BOOL16 WINAPI TranslateMDISysAccel16( HWND16 hwndClient, LPMSG16 msg )
1835 WND* clientWnd = WIN_FindWndPtr( hwndClient);
1837 if( clientWnd && (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN))
1839 MDICLIENTINFO *ci = NULL;
1842 ci = (MDICLIENTINFO*) clientWnd->wExtra;
1843 WIN_ReleaseWndPtr(clientWnd);
1844 wnd = WIN_FindWndPtr(ci->hwndActiveChild);
1845 if( wnd && !(wnd->dwStyle & WS_DISABLED) )
1847 WPARAM16 wParam = 0;
1849 WIN_ReleaseWndPtr(wnd);
1850 /* translate if the Ctrl key is down and Alt not. */
1852 if( (GetKeyState(VK_CONTROL) & 0x8000) &&
1853 !(GetKeyState(VK_MENU) & 0x8000))
1855 switch( msg->wParam )
1859 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 )
1860 ? SC_NEXTWINDOW : SC_PREVWINDOW;
1869 TRACE(mdi,"wParam = %04x\n", wParam);
1870 SendMessage16( ci->hwndActiveChild, WM_SYSCOMMAND,
1871 wParam, (LPARAM)msg->wParam);
1875 WIN_ReleaseWndPtr(wnd);
1877 WIN_ReleaseWndPtr(clientWnd);
1878 return 0; /* failure */
1882 /***********************************************************************
1883 * CalcChildScroll (USER.462)
1885 void WINAPI CalcChildScroll16( HWND16 hwnd, WORD scroll )
1888 RECT childRect, clientRect;
1889 INT vmin, vmax, hmin, hmax, vpos, hpos;
1892 if (!(pWnd = WIN_FindWndPtr( hwnd ))) return;
1893 Wnd = WIN_FindWndPtr(hwnd);
1894 GetClientRect( hwnd, &clientRect );
1895 SetRectEmpty( &childRect );
1897 for ( WIN_UpdateWndPtr(&pWnd,pWnd->child); pWnd; WIN_UpdateWndPtr(&pWnd,pWnd->next))
1899 if( pWnd->dwStyle & WS_MAXIMIZE )
1901 ShowScrollBar(hwnd, SB_BOTH, FALSE);
1902 WIN_ReleaseWndPtr(pWnd);
1903 WIN_ReleaseWndPtr(Wnd);
1906 UnionRect( &childRect, &pWnd->rectWindow, &childRect );
1908 WIN_ReleaseWndPtr(pWnd);
1909 UnionRect( &childRect, &clientRect, &childRect );
1911 hmin = childRect.left; hmax = childRect.right - clientRect.right;
1912 hpos = clientRect.left - childRect.left;
1913 vmin = childRect.top; vmax = childRect.bottom - clientRect.bottom;
1914 vpos = clientRect.top - childRect.top;
1919 vpos = hpos; vmin = hmin; vmax = hmax;
1921 info.cbSize = sizeof(info);
1922 info.nMax = vmax; info.nMin = vmin; info.nPos = vpos;
1923 info.fMask = SIF_POS | SIF_RANGE;
1924 SetScrollInfo(hwnd, scroll, &info, TRUE);
1927 SCROLL_SetNCSbState( Wnd, vmin, vmax, vpos,
1930 WIN_ReleaseWndPtr(Wnd);
1934 /***********************************************************************
1935 * ScrollChildren16 (USER.463)
1937 void WINAPI ScrollChildren16(HWND16 hWnd, UINT16 uMsg, WPARAM16 wParam, LPARAM lParam)
1939 return ScrollChildren( hWnd, uMsg, wParam, lParam );
1943 /***********************************************************************
1944 * ScrollChildren32 (USER32.448)
1946 void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
1949 WND *wndPtr = WIN_FindWndPtr(hWnd);
1951 INT curPos, length, minPos, maxPos, shift;
1953 if( !wndPtr ) return;
1955 if( uMsg == WM_HSCROLL )
1957 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
1958 curPos = GetScrollPos(hWnd,SB_HORZ);
1959 length = (wndPtr->rectClient.right - wndPtr->rectClient.left)/2;
1960 shift = SYSMETRICS_CYHSCROLL;
1962 else if( uMsg == WM_VSCROLL )
1964 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
1965 curPos = GetScrollPos(hWnd,SB_VERT);
1966 length = (wndPtr->rectClient.bottom - wndPtr->rectClient.top)/2;
1967 shift = SYSMETRICS_CXVSCROLL;
1971 WIN_ReleaseWndPtr(wndPtr);
1975 WIN_ReleaseWndPtr(wndPtr);
1979 newPos = curPos - shift;
1982 newPos = curPos + shift;
1985 newPos = curPos - length;
1988 newPos = curPos + length;
1991 case SB_THUMBPOSITION:
1992 newPos = LOWORD(lParam);
2005 CalcChildScroll16(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
2009 if( newPos > maxPos )
2012 if( newPos < minPos )
2015 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
2017 if( uMsg == WM_VSCROLL )
2018 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
2019 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2021 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
2022 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2026 /******************************************************************************
2027 * CascadeWindows [USER32.21] Cascades MDI child windows
2030 * Success: Number of cascaded windows.
2034 CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2035 UINT cKids, const HWND *lpKids)
2037 FIXME (mdi, "(0x%08x,0x%08x,...,%u,...): stub\n",
2038 hwndParent, wFlags, cKids);
2044 /******************************************************************************
2045 * TileWindows [USER32.545] Tiles MDI child windows
2048 * Success: Number of tiled windows.
2052 TileWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2053 UINT cKids, const HWND *lpKids)
2055 FIXME (mdi, "(0x%08x,0x%08x,...,%u,...): stub\n",
2056 hwndParent, wFlags, cKids);