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"
29 #include "debugtools.h"
31 DEFAULT_DEBUG_CHANNEL(mdi)
33 #define MDIF_NEEDUPDATE 0x0001
35 static HBITMAP16 hBmpClose = 0;
36 static HBITMAP16 hBmpRestore = 0;
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("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,
212 HWND hwndFrame = GetParent(hwnd);
213 HMENU oldFrameMenu = GetMenu(hwndFrame);
215 TRACE("%04x %04x %04x\n",
216 hwnd, hmenuFrame, hmenuWindow);
218 if (hmenuFrame && !IsMenu(hmenuFrame))
220 WARN("hmenuFrame is not a menu handle\n");
224 if (hmenuWindow && !IsMenu(hmenuWindow))
226 WARN("hmenuWindow is not a menu handle\n");
230 w = WIN_FindWndPtr(hwnd);
231 ci = (MDICLIENTINFO *) w->wExtra;
233 if( ci->hwndChildMaximized && hmenuFrame && hmenuFrame!=oldFrameMenu )
234 MDI_RestoreFrameMenu(w->parent, ci->hwndChildMaximized );
236 if( hmenuWindow && hmenuWindow!=ci->hWindowMenu )
238 /* delete menu items from ci->hWindowMenu
239 * and add them to hmenuWindow */
241 INT i = GetMenuItemCount(ci->hWindowMenu) - 1;
242 INT pos = GetMenuItemCount(hmenuWindow) + 1;
244 AppendMenuA( hmenuWindow, MF_SEPARATOR, 0, NULL);
246 if( ci->nActiveChildren )
248 INT j = i - ci->nActiveChildren + 1;
252 for( ; i >= j ; i-- )
254 id = GetMenuItemID(ci->hWindowMenu,i );
255 state = GetMenuState(ci->hWindowMenu,i,MF_BYPOSITION);
257 GetMenuStringA(ci->hWindowMenu, i, buffer, 100, MF_BYPOSITION);
259 DeleteMenu(ci->hWindowMenu, i , MF_BYPOSITION);
260 InsertMenuA(hmenuWindow, pos, MF_BYPOSITION | MF_STRING,
262 CheckMenuItem(hmenuWindow ,pos , MF_BYPOSITION | (state & MF_CHECKED));
266 /* remove separator */
267 DeleteMenu(ci->hWindowMenu, i, MF_BYPOSITION);
269 ci->hWindowMenu = hmenuWindow;
272 if( hmenuFrame && hmenuFrame!=oldFrameMenu)
274 SetMenu(hwndFrame, hmenuFrame);
275 if( ci->hwndChildMaximized )
276 MDI_AugmentFrameMenu(ci, w->parent, ci->hwndChildMaximized );
277 WIN_ReleaseWndPtr(w);
280 WIN_ReleaseWndPtr(w);
284 /**********************************************************************
287 static LRESULT MDIRefreshMenu( HWND hwnd, HMENU hmenuFrame,
290 HWND hwndFrame = GetParent(hwnd);
291 HMENU oldFrameMenu = GetMenu(hwndFrame);
293 TRACE("%04x %04x %04x\n",
294 hwnd, hmenuFrame, hmenuWindow);
296 FIXME("partially function stub\n");
302 /* ------------------ MDI child window functions ---------------------- */
305 /**********************************************************************
308 static HWND MDICreateChild( WND *w, MDICLIENTINFO *ci, HWND parent,
309 LPMDICREATESTRUCTA cs )
312 DWORD style = cs->style | (WS_CHILD | WS_CLIPSIBLINGS);
313 HWND hwnd, hwndMax = 0;
314 WORD wIDmenu = ci->idFirstChild + ci->nActiveChildren;
315 char lpstrDef[]="junk!";
317 TRACE("origin %i,%i - dim %i,%i, style %08x\n",
318 cs->x, cs->y, cs->cx, cs->cy, (unsigned)cs->style);
319 /* calculate placement */
320 MDI_CalcDefaultChildPos(w, ci->nTotalCreated++, pos, 0);
322 if (cs->cx == CW_USEDEFAULT || !cs->cx) cs->cx = pos[1].x;
323 if (cs->cy == CW_USEDEFAULT || !cs->cy) cs->cy = pos[1].y;
325 if( cs->x == CW_USEDEFAULT )
331 /* restore current maximized child */
332 if( style & WS_VISIBLE && ci->hwndChildMaximized )
334 if( style & WS_MAXIMIZE )
335 SendMessageA(w->hwndSelf, WM_SETREDRAW, FALSE, 0L );
336 hwndMax = ci->hwndChildMaximized;
337 ShowWindow( hwndMax, SW_SHOWNOACTIVATE );
338 if( style & WS_MAXIMIZE )
339 SendMessageA(w->hwndSelf, WM_SETREDRAW, TRUE, 0L );
342 /* this menu is needed to set a check mark in MDI_ChildActivate */
343 AppendMenuA(ci->hWindowMenu ,MF_STRING ,wIDmenu, lpstrDef );
345 ci->nActiveChildren++;
347 /* fix window style */
348 if( !(w->dwStyle & MDIS_ALLCHILDSTYLES) )
350 style &= (WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZE | WS_MAXIMIZE |
351 WS_CLIPCHILDREN | WS_DISABLED | WS_VSCROLL | WS_HSCROLL );
352 style |= (WS_VISIBLE | WS_OVERLAPPEDWINDOW);
355 if( w->flags & WIN_ISWIN32 )
357 hwnd = CreateWindowA( cs->szClass, cs->szTitle, style,
358 cs->x, cs->y, cs->cx, cs->cy, parent,
359 (HMENU16)wIDmenu, cs->hOwner, cs );
363 MDICREATESTRUCT16 *cs16;
366 cs16 = SEGPTR_NEW(MDICREATESTRUCT16);
367 STRUCT32_MDICREATESTRUCT32Ato16( cs, cs16 );
368 title = SEGPTR_STRDUP( cs->szTitle );
369 cls = SEGPTR_STRDUP( cs->szClass );
370 cs16->szTitle = SEGPTR_GET(title);
371 cs16->szClass = SEGPTR_GET(cls);
373 hwnd = CreateWindow16( cs->szClass, cs->szTitle, style,
374 cs16->x, cs16->y, cs16->cx, cs16->cy, parent,
375 (HMENU)wIDmenu, cs16->hOwner,
376 (LPVOID)SEGPTR_GET(cs16) );
377 SEGPTR_FREE( title );
382 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
386 WND* wnd = WIN_FindWndPtr( hwnd );
388 /* All MDI child windows have the WS_EX_MDICHILD style */
389 wnd->dwExStyle |= WS_EX_MDICHILD;
391 MDI_MenuModifyItem(w ,hwnd);
392 if( wnd->dwStyle & WS_MINIMIZE && ci->hwndActiveChild )
393 ShowWindow( hwnd, SW_SHOWMINNOACTIVE );
396 /* WS_VISIBLE is clear if a) the MDI client has
397 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
398 * MDICreateStruct. If so the created window is not shown nor
401 int showflag=wnd->dwStyle & WS_VISIBLE;
402 /* clear visible flag, otherwise SetWindoPos32 ignores
403 * the SWP_SHOWWINDOW command.
405 wnd->dwStyle &= ~WS_VISIBLE;
407 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE );
409 /* Set maximized state here in case hwnd didn't receive WM_SIZE
410 * during CreateWindow - bad!
413 if((wnd->dwStyle & WS_MAXIMIZE) && !ci->hwndChildMaximized )
415 ci->hwndChildMaximized = wnd->hwndSelf;
416 MDI_AugmentFrameMenu( ci, w->parent, hwnd );
417 MDI_UpdateFrameText( w->parent, ci->self, MDI_REPAINTFRAME, NULL );
420 /* needed, harmless ? */
421 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE );
424 WIN_ReleaseWndPtr(wnd);
425 TRACE("created child - %04x\n",hwnd);
429 ci->nActiveChildren--;
430 DeleteMenu(ci->hWindowMenu,wIDmenu,MF_BYCOMMAND);
431 if( IsWindow(hwndMax) )
432 ShowWindow(hwndMax, SW_SHOWMAXIMIZED);
438 /**********************************************************************
439 * MDI_ChildGetMinMaxInfo
441 * Note: The rule here is that client rect of the maximized MDI child
442 * is equal to the client rect of the MDI client window.
444 static void MDI_ChildGetMinMaxInfo( WND* clientWnd, HWND hwnd,
445 MINMAXINFO16* lpMinMax )
447 WND* childWnd = WIN_FindWndPtr(hwnd);
448 RECT rect = clientWnd->rectClient;
450 MapWindowPoints( clientWnd->parent->hwndSelf,
451 ((MDICLIENTINFO*)clientWnd->wExtra)->self, (LPPOINT)&rect, 2);
452 AdjustWindowRectEx( &rect, childWnd->dwStyle, 0, childWnd->dwExStyle );
454 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
455 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
457 lpMinMax->ptMaxPosition.x = rect.left;
458 lpMinMax->ptMaxPosition.y = rect.top;
460 WIN_ReleaseWndPtr(childWnd);
462 TRACE("max rect (%i,%i - %i, %i)\n",
463 rect.left,rect.top,rect.right,rect.bottom);
467 /**********************************************************************
468 * MDI_SwitchActiveChild
470 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
473 static void MDI_SwitchActiveChild( HWND clientHwnd, HWND childHwnd,
476 WND *w = WIN_FindWndPtr(clientHwnd);
481 hwndTo = MDI_GetWindow(w, childHwnd, bNextWindow, 0);
483 ci = (MDICLIENTINFO *) w->wExtra;
485 TRACE("from %04x, to %04x\n",childHwnd,hwndTo);
487 if ( !hwndTo ) goto END; /* no window to switch to */
489 hwndPrev = ci->hwndActiveChild;
491 if ( hwndTo != hwndPrev )
495 if( ci->hwndChildMaximized )
498 w->dwStyle &= ~WS_VISIBLE;
501 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0,
502 SWP_NOMOVE | SWP_NOSIZE );
504 if( bNextWindow && hwndPrev )
505 SetWindowPos( hwndPrev, HWND_BOTTOM, 0, 0, 0, 0,
506 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
508 ShowWindow( clientHwnd, SW_SHOW );
511 WIN_ReleaseWndPtr(w);
515 /**********************************************************************
518 static LRESULT MDIDestroyChild( WND *w_parent, MDICLIENTINFO *ci,
519 HWND parent, HWND child,
522 WND *childPtr = WIN_FindWndPtr(child);
526 if( child == ci->hwndActiveChild )
528 MDI_SwitchActiveChild(parent, child, TRUE);
530 if( child == ci->hwndActiveChild )
532 ShowWindow( child, SW_HIDE);
533 if( child == ci->hwndChildMaximized )
535 MDI_RestoreFrameMenu(w_parent->parent, child);
536 ci->hwndChildMaximized = 0;
537 MDI_UpdateFrameText(w_parent->parent,parent,TRUE,NULL);
540 MDI_ChildActivate(w_parent, 0);
543 MDI_MenuDeleteItem(w_parent, child);
545 WIN_ReleaseWndPtr(childPtr);
547 ci->nActiveChildren--;
549 TRACE("child destroyed - %04x\n",child);
553 MDI_PostUpdate(GetParent(child), ci, SB_BOTH+1);
554 DestroyWindow(child);
562 /**********************************************************************
565 * Note: hWndChild is NULL when last child is being destroyed
567 static LONG MDI_ChildActivate( WND *clientPtr, HWND hWndChild )
569 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientPtr->wExtra;
570 HWND prevActiveWnd = clientInfo->hwndActiveChild;
571 WND *wndPtr = WIN_FindWndPtr( hWndChild );
572 WND *wndPrev = WIN_FindWndPtr( prevActiveWnd );
573 BOOL isActiveFrameWnd = 0;
578 if( wndPtr->dwStyle & WS_DISABLED )
585 TRACE("%04x\n", hWndChild);
587 if( GetActiveWindow() == clientPtr->parent->hwndSelf )
588 isActiveFrameWnd = TRUE;
590 /* deactivate prev. active child */
593 wndPrev->dwStyle |= WS_SYSMENU;
594 SendMessageA( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
595 SendMessageA( prevActiveWnd, WM_MDIACTIVATE, (WPARAM)prevActiveWnd,
597 /* uncheck menu item */
598 if( clientInfo->hWindowMenu )
599 CheckMenuItem( clientInfo->hWindowMenu,
600 wndPrev->wIDmenu, 0);
604 if( clientInfo->hwndChildMaximized )
606 if( clientInfo->hwndChildMaximized != hWndChild ) {
608 clientInfo->hwndActiveChild = hWndChild;
609 ShowWindow( hWndChild, SW_SHOWMAXIMIZED);
611 ShowWindow( clientInfo->hwndActiveChild, SW_SHOWNORMAL );
615 clientInfo->hwndActiveChild = hWndChild;
617 /* check if we have any children left */
620 if( isActiveFrameWnd )
621 SetFocus( clientInfo->self );
626 /* check menu item */
627 if( clientInfo->hWindowMenu )
628 CheckMenuItem( clientInfo->hWindowMenu,
629 wndPtr->wIDmenu, MF_CHECKED);
631 /* bring active child to the top */
632 SetWindowPos( hWndChild, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
634 if( isActiveFrameWnd )
636 SendMessageA( hWndChild, WM_NCACTIVATE, TRUE, 0L);
637 if( GetFocus() == clientInfo->self )
638 SendMessageA( clientInfo->self, WM_SETFOCUS,
639 (WPARAM)clientInfo->self, 0L );
641 SetFocus( clientInfo->self );
643 SendMessageA( hWndChild, WM_MDIACTIVATE, (WPARAM)prevActiveWnd,
647 WIN_ReleaseWndPtr(wndPtr);
648 WIN_ReleaseWndPtr(wndPrev);
652 /* -------------------- MDI client window functions ------------------- */
654 /**********************************************************************
655 * CreateMDIMenuBitmap
657 static HBITMAP16 CreateMDIMenuBitmap(void)
659 HDC hDCSrc = CreateCompatibleDC(0);
660 HDC hDCDest = CreateCompatibleDC(hDCSrc);
661 HBITMAP16 hbClose = LoadBitmap16(0, MAKEINTRESOURCE16(OBM_CLOSE) );
663 HANDLE16 hobjSrc, hobjDest;
665 hobjSrc = SelectObject(hDCSrc, hbClose);
666 hbCopy = CreateCompatibleBitmap(hDCSrc,GetSystemMetrics(SM_CXSIZE),GetSystemMetrics(SM_CYSIZE));
667 hobjDest = SelectObject(hDCDest, hbCopy);
669 BitBlt(hDCDest, 0, 0, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE),
670 hDCSrc, GetSystemMetrics(SM_CXSIZE), 0, SRCCOPY);
672 SelectObject(hDCSrc, hobjSrc);
673 DeleteObject(hbClose);
676 hobjSrc = SelectObject( hDCDest, GetStockObject(BLACK_PEN) );
678 MoveToEx( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, 0, NULL );
679 LineTo( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, GetSystemMetrics(SM_CYSIZE) - 1);
681 SelectObject(hDCDest, hobjSrc );
682 SelectObject(hDCDest, hobjDest);
688 /**********************************************************************
691 static LONG MDICascade(WND* clientWnd, MDICLIENTINFO *ci)
696 if (ci->hwndChildMaximized)
697 SendMessageA( clientWnd->hwndSelf, WM_MDIRESTORE,
698 (WPARAM)ci->hwndChildMaximized, 0);
700 if (ci->nActiveChildren == 0) return 0;
702 if ((ppWnd = WIN_BuildWinArray(clientWnd, BWA_SKIPHIDDEN | BWA_SKIPOWNED |
703 BWA_SKIPICONIC, &total)))
705 WND** heapPtr = ppWnd;
708 INT delta = 0, n = 0;
710 if( total < ci->nActiveChildren )
711 delta = GetSystemMetrics(SM_CYICONSPACING) +
712 GetSystemMetrics(SM_CYICON);
714 /* walk the list (backwards) and move windows */
715 while (*ppWnd) ppWnd++;
716 while (ppWnd != heapPtr)
719 TRACE("move %04x to (%ld,%ld) size [%ld,%ld]\n",
720 (*ppWnd)->hwndSelf, pos[0].x, pos[0].y, pos[1].x, pos[1].y);
722 MDI_CalcDefaultChildPos(clientWnd, n++, pos, delta);
723 SetWindowPos( (*ppWnd)->hwndSelf, 0, pos[0].x, pos[0].y,
725 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
728 WIN_ReleaseWinArray(heapPtr);
731 if( total < ci->nActiveChildren )
732 ArrangeIconicWindows( clientWnd->hwndSelf );
736 /**********************************************************************
739 static void MDITile( WND* wndClient, MDICLIENTINFO *ci, WPARAM wParam )
744 if (ci->hwndChildMaximized)
745 SendMessageA( wndClient->hwndSelf, WM_MDIRESTORE,
746 (WPARAM)ci->hwndChildMaximized, 0);
748 if (ci->nActiveChildren == 0) return;
750 ppWnd = WIN_BuildWinArray(wndClient, BWA_SKIPHIDDEN | BWA_SKIPOWNED | BWA_SKIPICONIC |
751 ((wParam & MDITILE_SKIPDISABLED)? BWA_SKIPDISABLED : 0), &total );
753 TRACE("%u windows to tile\n", total);
757 WND** heapPtr = ppWnd;
762 int x, y, xsize, ysize;
763 int rows, columns, r, c, i;
765 GetClientRect(wndClient->hwndSelf,&rect);
766 rows = (int) sqrt((double)total);
767 columns = total / rows;
769 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
772 rows = columns; /* exchange r and c */
776 if( total != ci->nActiveChildren)
778 y = rect.bottom - 2 * GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
779 rect.bottom = ( y - GetSystemMetrics(SM_CYICON) < rect.top )? rect.bottom: y;
782 ysize = rect.bottom / rows;
783 xsize = rect.right / columns;
785 for (x = i = 0, c = 1; c <= columns && *ppWnd; c++)
790 ysize = rect.bottom / rows;
794 for (r = 1; r <= rows && *ppWnd; r++, i++)
796 SetWindowPos((*ppWnd)->hwndSelf, 0, x, y, xsize, ysize,
797 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
804 WIN_ReleaseWinArray(heapPtr);
807 if( total < ci->nActiveChildren ) ArrangeIconicWindows( wndClient->hwndSelf );
810 /* ----------------------- Frame window ---------------------------- */
813 /**********************************************************************
814 * MDI_AugmentFrameMenu
816 static BOOL MDI_AugmentFrameMenu( MDICLIENTINFO* ci, WND *frame,
819 WND* child = WIN_FindWndPtr(hChild);
821 HBITMAP hSysMenuBitmap = 0;
823 TRACE("frame %p,child %04x\n",frame,hChild);
825 if( !frame->wIDmenu || !child->hSysMenu )
827 WIN_ReleaseWndPtr(child);
830 WIN_ReleaseWndPtr(child);
832 /* create a copy of sysmenu popup and insert it into frame menu bar */
834 if (!(hSysPopup = LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU")))
837 TRACE("\tgot popup %04x in sysmenu %04x\n",
838 hSysPopup, child->hSysMenu);
840 AppendMenuA(frame->wIDmenu,MF_HELP | MF_BITMAP,
841 SC_MINIMIZE, (LPSTR)(DWORD)HBMMENU_MBAR_MINIMIZE ) ;
842 AppendMenuA(frame->wIDmenu,MF_HELP | MF_BITMAP,
843 SC_RESTORE, (LPSTR)(DWORD)HBMMENU_MBAR_RESTORE );
845 /* In Win 95 look, the system menu is replaced by the child icon */
847 if(TWEAK_WineLook > WIN31_LOOK)
849 HICON hIcon = GetClassLongA(hChild, GCL_HICONSM);
851 hIcon = GetClassLongA(hChild, GCL_HICON);
855 HBITMAP hBitmap, hOldBitmap;
857 HDC hdc = GetDC(hChild);
862 cx = GetSystemMetrics(SM_CXSMICON);
863 cy = GetSystemMetrics(SM_CYSMICON);
864 hMemDC = CreateCompatibleDC(hdc);
865 hBitmap = CreateCompatibleBitmap(hdc, cx, cy);
866 hOldBitmap = SelectObject(hMemDC, hBitmap);
867 SetMapMode(hMemDC, MM_TEXT);
868 hBrush = CreateSolidBrush(GetSysColor(COLOR_MENU));
869 DrawIconEx(hMemDC, 0, 0, hIcon, cx, cy, 0, hBrush, DI_NORMAL);
870 SelectObject (hMemDC, hOldBitmap);
871 DeleteObject(hBrush);
873 ReleaseDC(hChild, hdc);
874 hSysMenuBitmap = hBitmap;
879 hSysMenuBitmap = hBmpClose;
881 if( !InsertMenuA(frame->wIDmenu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
882 hSysPopup, (LPSTR)(DWORD)hSysMenuBitmap))
884 TRACE("not inserted\n");
885 DestroyMenu(hSysPopup);
889 /* The close button is only present in Win 95 look */
890 if(TWEAK_WineLook > WIN31_LOOK)
892 AppendMenuA(frame->wIDmenu,MF_HELP | MF_BITMAP,
893 SC_CLOSE, (LPSTR)(DWORD)HBMMENU_MBAR_CLOSE );
896 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
897 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
898 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
899 SetMenuDefaultItem(hSysPopup, SC_CLOSE, FALSE);
902 DrawMenuBar(frame->hwndSelf);
907 /**********************************************************************
908 * MDI_RestoreFrameMenu
910 static BOOL MDI_RestoreFrameMenu( WND *frameWnd, HWND hChild )
912 MENUITEMINFOA menuInfo;
913 INT nItems = GetMenuItemCount(frameWnd->wIDmenu) - 1;
914 UINT iId = GetMenuItemID(frameWnd->wIDmenu,nItems) ;
916 TRACE("frameWnd %p,child %04x\n",frameWnd,hChild);
918 if(!(iId == SC_RESTORE || iId == SC_CLOSE) )
922 * Remove the system menu, If that menu is the icon of the window
923 * as it is in win95, we have to delete the bitmap.
925 menuInfo.cbSize = sizeof(MENUITEMINFOA);
926 menuInfo.fMask = MIIM_DATA | MIIM_TYPE;
928 GetMenuItemInfoA(frameWnd->wIDmenu,
933 RemoveMenu(frameWnd->wIDmenu,0,MF_BYPOSITION);
935 if ( (menuInfo.fType & MFT_BITMAP) &&
936 (LOWORD(menuInfo.dwTypeData)!=0) &&
937 (LOWORD(menuInfo.dwTypeData)!=hBmpClose) )
939 DeleteObject((HBITMAP)LOWORD(menuInfo.dwTypeData));
942 if(TWEAK_WineLook > WIN31_LOOK)
945 DeleteMenu(frameWnd->wIDmenu,GetMenuItemCount(frameWnd->wIDmenu) - 1,MF_BYPOSITION);
948 DeleteMenu(frameWnd->wIDmenu,GetMenuItemCount(frameWnd->wIDmenu) - 1,MF_BYPOSITION);
950 DeleteMenu(frameWnd->wIDmenu,GetMenuItemCount(frameWnd->wIDmenu) - 1,MF_BYPOSITION);
952 DrawMenuBar(frameWnd->hwndSelf);
958 /**********************************************************************
959 * MDI_UpdateFrameText
961 * used when child window is maximized/restored
963 * Note: lpTitle can be NULL
965 static void MDI_UpdateFrameText( WND *frameWnd, HWND hClient,
966 BOOL repaint, LPCSTR lpTitle )
968 char lpBuffer[MDI_MAXTITLELENGTH+1];
969 WND* clientWnd = WIN_FindWndPtr(hClient);
970 MDICLIENTINFO *ci = (MDICLIENTINFO *) clientWnd->wExtra;
972 TRACE("repaint %i, frameText %s\n", repaint, (lpTitle)?lpTitle:"NULL");
979 WIN_ReleaseWndPtr(clientWnd);
983 /* store new "default" title if lpTitle is not NULL */
986 if (ci->frameTitle) HeapFree( SystemHeap, 0, ci->frameTitle );
987 ci->frameTitle = HEAP_strdupA( SystemHeap, 0, lpTitle );
992 WND* childWnd = WIN_FindWndPtr( ci->hwndChildMaximized );
994 if( childWnd && childWnd->text )
996 /* combine frame title and child title if possible */
998 LPCSTR lpBracket = " - [";
999 int i_frame_text_length = strlen(ci->frameTitle);
1000 int i_child_text_length = strlen(childWnd->text);
1002 lstrcpynA( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
1004 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
1006 strcat( lpBuffer, lpBracket );
1008 if( i_frame_text_length + i_child_text_length + 6 < MDI_MAXTITLELENGTH )
1010 strcat( lpBuffer, childWnd->text );
1011 strcat( lpBuffer, "]" );
1015 lstrcpynA( lpBuffer + i_frame_text_length + 4,
1016 childWnd->text, MDI_MAXTITLELENGTH - i_frame_text_length - 5 );
1017 strcat( lpBuffer, "]" );
1023 strncpy(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH );
1024 lpBuffer[MDI_MAXTITLELENGTH]='\0';
1026 WIN_ReleaseWndPtr(childWnd);
1032 DEFWND_SetText( frameWnd, lpBuffer );
1033 if( repaint == MDI_REPAINTFRAME)
1034 SetWindowPos( frameWnd->hwndSelf, 0,0,0,0,0, SWP_FRAMECHANGED |
1035 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
1037 WIN_ReleaseWndPtr(clientWnd);
1042 /* ----------------------------- Interface ---------------------------- */
1045 /**********************************************************************
1048 * This function handles all MDI requests.
1050 LRESULT WINAPI MDIClientWndProc( HWND hwnd, UINT message, WPARAM wParam,
1060 if ( ( w = WIN_FindWndPtr(hwnd) ) == NULL )
1063 if ( ( frameWnd = WIN_LockWndPtr(w->parent) ) == NULL ) {
1064 WIN_ReleaseWndPtr(w);
1068 ci = (MDICLIENTINFO *) w->wExtra;
1074 cs = (LPCREATESTRUCTA)lParam;
1076 /* Translation layer doesn't know what's in the cs->lpCreateParams
1077 * so we have to keep track of what environment we're in. */
1079 if( w->flags & WIN_ISWIN32 )
1081 #define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1082 ci->hWindowMenu = ccs->hWindowMenu;
1083 ci->idFirstChild = ccs->idFirstChild;
1088 LPCLIENTCREATESTRUCT16 ccs = (LPCLIENTCREATESTRUCT16)
1089 PTR_SEG_TO_LIN(cs->lpCreateParams);
1090 ci->hWindowMenu = ccs->hWindowMenu;
1091 ci->idFirstChild = ccs->idFirstChild;
1094 ci->hwndChildMaximized = 0;
1095 ci->nActiveChildren = 0;
1096 ci->nTotalCreated = 0;
1097 ci->frameTitle = NULL;
1100 w->dwStyle |= WS_CLIPCHILDREN;
1104 hBmpClose = CreateMDIMenuBitmap();
1105 hBmpRestore = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_RESTORE) );
1107 MDI_UpdateFrameText(frameWnd, hwnd, MDI_NOFRAMEREPAINT,frameWnd->text);
1109 AppendMenuA( ci->hWindowMenu, MF_SEPARATOR, 0, NULL );
1111 GetClientRect(frameWnd->hwndSelf, &rect);
1112 NC_HandleNCCalcSize( w, &rect );
1113 w->rectClient = rect;
1115 TRACE("Client created - hwnd = %04x, idFirst = %u\n",
1116 hwnd, ci->idFirstChild );
1122 if( ci->hwndChildMaximized ) MDI_RestoreFrameMenu(w, frameWnd->hwndSelf);
1123 if((nItems = GetMenuItemCount(ci->hWindowMenu)) > 0)
1125 ci->idFirstChild = nItems - 1;
1126 ci->nActiveChildren++; /* to delete a separator */
1127 while( ci->nActiveChildren-- )
1128 DeleteMenu(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
1133 case WM_MDIACTIVATE:
1134 if( ci->hwndActiveChild != (HWND)wParam )
1135 SetWindowPos((HWND)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
1140 retvalue = MDICascade(w, ci);
1144 if (lParam) retvalue = MDICreateChild( w, ci, hwnd,
1145 (MDICREATESTRUCTA*)lParam );
1150 retvalue = MDIDestroyChild( w, ci, hwnd, (HWND)wParam, TRUE );
1153 case WM_MDIGETACTIVE:
1154 if (lParam) *(BOOL *)lParam = (ci->hwndChildMaximized > 0);
1155 retvalue = ci->hwndActiveChild;
1158 case WM_MDIICONARRANGE:
1159 ci->mdiFlags |= MDIF_NEEDUPDATE;
1160 ArrangeIconicWindows(hwnd);
1161 ci->sbRecalc = SB_BOTH+1;
1162 SendMessageA(hwnd, WM_MDICALCCHILDSCROLL, 0, 0L);
1166 case WM_MDIMAXIMIZE:
1167 ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1171 case WM_MDINEXT: /* lParam != 0 means previous window */
1172 MDI_SwitchActiveChild(hwnd, (HWND)wParam, (lParam)? FALSE : TRUE );
1176 SendMessageA( (HWND)wParam, WM_SYSCOMMAND, SC_RESTORE, 0);
1181 retvalue = MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1183 case WM_MDIREFRESHMENU:
1184 retvalue = MDIRefreshMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1188 ci->mdiFlags |= MDIF_NEEDUPDATE;
1189 ShowScrollBar(hwnd,SB_BOTH,FALSE);
1190 MDITile(w, ci, wParam);
1191 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1197 ci->mdiFlags |= MDIF_NEEDUPDATE;
1198 ScrollChildren(hwnd, message, wParam, lParam);
1199 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1204 if( ci->hwndActiveChild )
1206 WND* pw = WIN_FindWndPtr( ci->hwndActiveChild );
1207 if( !(pw->dwStyle & WS_MINIMIZE) )
1208 SetFocus( ci->hwndActiveChild );
1209 WIN_ReleaseWndPtr(pw);
1215 if( ci->hwndActiveChild )
1216 SendMessageA(ci->hwndActiveChild, message, wParam, lParam);
1219 case WM_PARENTNOTIFY:
1220 if (LOWORD(wParam) == WM_LBUTTONDOWN)
1222 POINT16 pt = MAKEPOINT16(lParam);
1223 HWND16 child = ChildWindowFromPoint16(hwnd, pt);
1225 TRACE("notification from %04x (%i,%i)\n",child,pt.x,pt.y);
1227 if( child && child != hwnd && child != ci->hwndActiveChild )
1228 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1234 if( IsWindow(ci->hwndChildMaximized) )
1236 WND* child = WIN_FindWndPtr(ci->hwndChildMaximized);
1241 rect.right = LOWORD(lParam);
1242 rect.bottom = HIWORD(lParam);
1244 AdjustWindowRectEx(&rect, child->dwStyle, 0, child->dwExStyle);
1245 MoveWindow(ci->hwndChildMaximized, rect.left, rect.top,
1246 rect.right - rect.left, rect.bottom - rect.top, 1);
1247 WIN_ReleaseWndPtr(child);
1250 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1254 case WM_MDICALCCHILDSCROLL:
1255 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1257 CalcChildScroll16(hwnd, ci->sbRecalc-1);
1259 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1265 retvalue = DefWindowProcA( hwnd, message, wParam, lParam );
1267 WIN_ReleaseWndPtr(w);
1268 WIN_ReleaseWndPtr(frameWnd);
1273 /***********************************************************************
1274 * DefFrameProc16 (USER.445)
1276 LRESULT WINAPI DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient,
1277 UINT16 message, WPARAM16 wParam, LPARAM lParam )
1288 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1291 ERR("null wndPtr for mdi window hwndMDIClient=%04x\n",
1296 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1298 /* check for possible syscommands for maximized MDI child */
1299 WIN_ReleaseWndPtr(wndPtr);
1302 wParam < ci->idFirstChild ||
1303 wParam >= ci->idFirstChild + ci->nActiveChildren
1305 if( (wParam - 0xF000) & 0xF00F ) break;
1316 if( ci->hwndChildMaximized )
1317 return SendMessage16( ci->hwndChildMaximized, WM_SYSCOMMAND,
1323 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1324 childHwnd = MDI_GetChildByID(wndPtr,wParam );
1325 WIN_ReleaseWndPtr(wndPtr);
1328 SendMessage16(hwndMDIClient, WM_MDIACTIVATE,
1329 (WPARAM16)childHwnd , 0L);
1334 SendMessage16(hwndMDIClient, message, wParam, lParam);
1338 wndPtr = WIN_FindWndPtr(hwnd);
1339 MDI_UpdateFrameText(wndPtr, hwndMDIClient,
1341 (LPCSTR)PTR_SEG_TO_LIN(lParam));
1342 WIN_ReleaseWndPtr(wndPtr);
1346 SetFocus(hwndMDIClient);
1350 MoveWindow16(hwndMDIClient, 0, 0,
1351 LOWORD(lParam), HIWORD(lParam), TRUE);
1356 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1357 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1359 if( !(wndPtr->parent->dwStyle & WS_MINIMIZE)
1360 && ci->hwndActiveChild && !ci->hwndChildMaximized )
1362 /* control menu is between the frame system menu and
1363 * the first entry of menu bar */
1365 if( (wParam == VK_LEFT &&
1366 wndPtr->parent->wIDmenu == LOWORD(lParam)) ||
1367 (wParam == VK_RIGHT &&
1368 GetSubMenu16(wndPtr->parent->hSysMenu, 0) == LOWORD(lParam)) )
1371 WIN_ReleaseWndPtr(wndPtr);
1372 wndPtr = WIN_FindWndPtr(ci->hwndActiveChild);
1373 retvalue = MAKELONG( GetSubMenu16(wndPtr->hSysMenu, 0),
1374 ci->hwndActiveChild);
1375 WIN_ReleaseWndPtr(wndPtr);
1379 WIN_ReleaseWndPtr(wndPtr);
1384 return DefWindowProc16(hwnd, message, wParam, lParam);
1388 /***********************************************************************
1389 * DefFrameProc32A (USER32.122)
1391 LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1392 UINT message, WPARAM wParam, LPARAM lParam)
1399 return DefFrameProc16( hwnd, hwndMDIClient, message,
1401 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1404 SendMessageA(hwndMDIClient, message, wParam, lParam);
1409 LPSTR segstr = SEGPTR_STRDUP((LPSTR)lParam);
1411 ret = DefFrameProc16(hwnd, hwndMDIClient, message,
1412 wParam, (LPARAM)SEGPTR_GET(segstr) );
1413 SEGPTR_FREE(segstr);
1420 return DefFrameProc16( hwnd, hwndMDIClient, message,
1425 return DefWindowProcA(hwnd, message, wParam, lParam);
1429 /***********************************************************************
1430 * DefFrameProc32W (USER32.123)
1432 LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1433 UINT message, WPARAM wParam, LPARAM lParam)
1440 return DefFrameProc16( hwnd, hwndMDIClient, message,
1442 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1445 SendMessageW(hwndMDIClient, message, wParam, lParam);
1450 LPSTR txt = HEAP_strdupWtoA(GetProcessHeap(),0,(LPWSTR)lParam);
1451 LRESULT ret = DefFrameProcA( hwnd, hwndMDIClient, message,
1452 wParam, (DWORD)txt );
1453 HeapFree(GetProcessHeap(),0,txt);
1459 return DefFrameProcA( hwnd, hwndMDIClient, message,
1464 return DefWindowProcW( hwnd, message, wParam, lParam );
1468 /***********************************************************************
1469 * DefMDIChildProc16 (USER.447)
1471 LRESULT WINAPI DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1472 WPARAM16 wParam, LPARAM lParam )
1475 WND *clientWnd,*tmpWnd = 0;
1478 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1479 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1484 DefWindowProc16(hwnd, message, wParam, lParam);
1485 MDI_MenuModifyItem(clientWnd,hwnd);
1486 if( ci->hwndChildMaximized == hwnd )
1487 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1488 MDI_REPAINTFRAME, NULL );
1493 SendMessage16(ci->self,WM_MDIDESTROY,(WPARAM16)hwnd,0L);
1498 if( ci->hwndActiveChild != hwnd )
1499 MDI_ChildActivate(clientWnd, hwnd);
1502 case WM_CHILDACTIVATE:
1503 MDI_ChildActivate(clientWnd, hwnd);
1508 TRACE("WM_NCPAINT for %04x, active %04x\n",
1509 hwnd, ci->hwndActiveChild );
1516 if( ci->hwndChildMaximized == hwnd)
1524 tmpWnd = WIN_FindWndPtr(hwnd);
1525 tmpWnd->dwStyle |= WS_SYSMENU;
1526 WIN_ReleaseWndPtr(tmpWnd);
1529 if( ci->hwndChildMaximized == hwnd)
1531 retvalue = SendMessage16( clientWnd->parent->hwndSelf,
1532 message, wParam, lParam);
1535 tmpWnd = WIN_FindWndPtr(hwnd);
1536 tmpWnd->dwStyle &= ~WS_SYSMENU;
1537 WIN_ReleaseWndPtr(tmpWnd);
1540 SendMessage16( ci->self, WM_MDINEXT, 0, 0);
1544 SendMessage16( ci->self, WM_MDINEXT, 0, 1);
1550 case WM_GETMINMAXINFO:
1551 MDI_ChildGetMinMaxInfo(clientWnd, hwnd, (MINMAXINFO16*) PTR_SEG_TO_LIN(lParam));
1556 if( ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1558 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1564 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1566 ci->hwndChildMaximized = 0;
1568 MDI_RestoreFrameMenu( clientWnd->parent, hwnd);
1569 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1570 MDI_REPAINTFRAME, NULL );
1573 if( wParam == SIZE_MAXIMIZED )
1575 HWND16 hMaxChild = ci->hwndChildMaximized;
1577 if( hMaxChild == hwnd ) break;
1581 SendMessage16( hMaxChild, WM_SETREDRAW, FALSE, 0L );
1583 MDI_RestoreFrameMenu( clientWnd->parent, hMaxChild);
1584 ShowWindow16( hMaxChild, SW_SHOWNOACTIVATE);
1586 SendMessage16( hMaxChild, WM_SETREDRAW, TRUE, 0L );
1589 TRACE("maximizing child %04x\n", hwnd );
1591 ci->hwndChildMaximized = hwnd; /* !!! */
1592 ci->hwndActiveChild = hwnd;
1594 MDI_AugmentFrameMenu( ci, clientWnd->parent, hwnd);
1595 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1596 MDI_REPAINTFRAME, NULL );
1599 if( wParam == SIZE_MINIMIZED )
1601 HWND16 switchTo = MDI_GetWindow(clientWnd, hwnd, TRUE, WS_MINIMIZE);
1604 SendMessage16( switchTo, WM_CHILDACTIVATE, 0, 0L);
1607 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1612 /* MDI children don't have menu bars */
1613 PostMessage16( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1614 (WPARAM16)SC_KEYMENU, (LPARAM)wParam);
1615 retvalue = 0x00010000L;
1620 if( wParam == VK_LEFT ) /* switch to frame system menu */
1622 retvalue = MAKELONG( GetSubMenu16(clientWnd->parent->hSysMenu, 0),
1623 clientWnd->parent->hwndSelf );
1626 if( wParam == VK_RIGHT ) /* to frame menu bar */
1628 retvalue = MAKELONG( clientWnd->parent->wIDmenu,
1629 clientWnd->parent->hwndSelf );
1638 SendMessage16(hwnd,WM_SYSCOMMAND,
1639 (WPARAM16)SC_KEYMENU, (LPARAM)(DWORD)VK_SPACE);
1645 retvalue = DefWindowProc16(hwnd, message, wParam, lParam);
1647 WIN_ReleaseWndPtr(clientWnd);
1652 /***********************************************************************
1653 * DefMDIChildProc32A (USER32.124)
1655 LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1656 WPARAM wParam, LPARAM lParam )
1659 WND *clientWnd,*tmpWnd;
1662 tmpWnd = WIN_FindWndPtr(hwnd);
1663 clientWnd = WIN_FindWndPtr(tmpWnd->parent->hwndSelf);
1664 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1665 WIN_ReleaseWndPtr(tmpWnd);
1670 DefWindowProcA(hwnd, message, wParam, lParam);
1671 MDI_MenuModifyItem(clientWnd,hwnd);
1672 if( ci->hwndChildMaximized == hwnd )
1673 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1674 MDI_REPAINTFRAME, NULL );
1678 case WM_GETMINMAXINFO:
1681 STRUCT32_MINMAXINFO32to16( (MINMAXINFO *)lParam, &mmi );
1682 MDI_ChildGetMinMaxInfo( clientWnd, hwnd, &mmi );
1683 STRUCT32_MINMAXINFO16to32( &mmi, (MINMAXINFO *)lParam );
1690 /* MDI children don't have menu bars */
1691 PostMessage16( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1692 (WPARAM16)SC_KEYMENU, (LPARAM)LOWORD(wParam) );
1693 retvalue = 0x00010000L;
1698 case WM_CHILDACTIVATE:
1704 retvalue = DefMDIChildProc16( hwnd, message, (WPARAM16)wParam, lParam );
1710 SendMessageA(hwnd,WM_SYSCOMMAND,
1711 (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)VK_SPACE);
1716 retvalue = DefWindowProcA(hwnd, message, wParam, lParam);
1718 WIN_ReleaseWndPtr(clientWnd);
1723 /***********************************************************************
1724 * DefMDIChildProc32W (USER32.125)
1726 LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1727 WPARAM wParam, LPARAM lParam )
1733 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1734 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1739 DefWindowProcW(hwnd, message, wParam, lParam);
1740 MDI_MenuModifyItem(clientWnd,hwnd);
1741 if( ci->hwndChildMaximized == hwnd )
1742 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1743 MDI_REPAINTFRAME, NULL );
1747 case WM_GETMINMAXINFO:
1751 case WM_CHILDACTIVATE:
1757 retvalue = DefMDIChildProcA( hwnd, message, (WPARAM16)wParam, lParam );
1763 SendMessageW(hwnd,WM_SYSCOMMAND,
1764 (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)VK_SPACE);
1769 retvalue = DefWindowProcW(hwnd, message, wParam, lParam);
1771 WIN_ReleaseWndPtr(clientWnd);
1777 /**********************************************************************
1778 * CreateMDIWindowA [USER32.79] Creates a MDI child in new thread
1779 * FIXME: its in the same thread now
1782 * Success: Handle to created window
1785 HWND WINAPI CreateMDIWindowA(
1786 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1787 LPCSTR lpWindowName, /* [in] Pointer to window name */
1788 DWORD dwStyle, /* [in] Window style */
1789 INT X, /* [in] Horizontal position of window */
1790 INT Y, /* [in] Vertical position of window */
1791 INT nWidth, /* [in] Width of window */
1792 INT nHeight, /* [in] Height of window */
1793 HWND hWndParent, /* [in] Handle to parent window */
1794 HINSTANCE hInstance, /* [in] Handle to application instance */
1795 LPARAM lParam) /* [in] Application-defined value */
1797 WARN("is only single threaded!\n");
1798 return MDI_CreateMDIWindowA(lpClassName, lpWindowName, dwStyle, X, Y,
1799 nWidth, nHeight, hWndParent, hInstance, lParam);
1802 /**********************************************************************
1803 * MDI_CreateMDIWindowA
1804 * single threaded version of CreateMDIWindowA
1805 * called by CreateWindowEx32A
1807 HWND MDI_CreateMDIWindowA(
1809 LPCSTR lpWindowName,
1816 HINSTANCE hInstance,
1820 MDICREATESTRUCTA cs;
1821 WND *pWnd=WIN_FindWndPtr(hWndParent);
1824 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
1825 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1826 nWidth,nHeight,hWndParent,hInstance,lParam);
1829 ERR(" bad hwnd for MDI-client: %d\n",hWndParent);
1832 cs.szClass=lpClassName;
1833 cs.szTitle=lpWindowName;
1834 cs.hOwner=hInstance;
1842 pCi=(MDICLIENTINFO *)pWnd->wExtra;
1844 retvalue = MDICreateChild(pWnd,pCi,hWndParent,&cs);
1845 WIN_ReleaseWndPtr(pWnd);
1849 /***************************************
1850 * CreateMDIWindow32W [USER32.80] Creates a MDI child in new thread
1853 * Success: Handle to created window
1856 HWND WINAPI CreateMDIWindowW(
1857 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1858 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1859 DWORD dwStyle, /* [in] Window style */
1860 INT X, /* [in] Horizontal position of window */
1861 INT Y, /* [in] Vertical position of window */
1862 INT nWidth, /* [in] Width of window */
1863 INT nHeight, /* [in] Height of window */
1864 HWND hWndParent, /* [in] Handle to parent window */
1865 HINSTANCE hInstance, /* [in] Handle to application instance */
1866 LPARAM lParam) /* [in] Application-defined value */
1868 FIXME("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld): stub\n",
1869 debugstr_w(lpClassName),debugstr_w(lpWindowName),dwStyle,X,Y,
1870 nWidth,nHeight,hWndParent,hInstance,lParam);
1875 /******************************************************************************
1876 * CreateMDIWindow32W [USER32.80] Creates a MDI child window
1877 * single threaded version of CreateMDIWindow
1878 * called by CreateWindowEx32W().
1880 HWND MDI_CreateMDIWindowW(
1881 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1882 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1883 DWORD dwStyle, /* [in] Window style */
1884 INT X, /* [in] Horizontal position of window */
1885 INT Y, /* [in] Vertical position of window */
1886 INT nWidth, /* [in] Width of window */
1887 INT nHeight, /* [in] Height of window */
1888 HWND hWndParent, /* [in] Handle to parent window */
1889 HINSTANCE hInstance, /* [in] Handle to application instance */
1890 LPARAM lParam) /* [in] Application-defined value */
1892 FIXME("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld): stub\n",
1893 debugstr_w(lpClassName),debugstr_w(lpWindowName),dwStyle,X,Y,
1894 nWidth,nHeight,hWndParent,hInstance,lParam);
1899 /**********************************************************************
1900 * TranslateMDISysAccel32 (USER32.555)
1902 BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1906 STRUCT32_MSG32to16(msg,&msg16);
1907 /* MDICLIENTINFO is still the same for win32 and win16 ... */
1908 return TranslateMDISysAccel16(hwndClient,&msg16);
1912 /**********************************************************************
1913 * TranslateMDISysAccel16 (USER.451)
1915 BOOL16 WINAPI TranslateMDISysAccel16( HWND16 hwndClient, LPMSG16 msg )
1918 if( IsWindow(hwndClient) && (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN))
1920 MDICLIENTINFO *ci = NULL;
1922 WND *clientWnd = WIN_FindWndPtr(hwndClient);
1924 ci = (MDICLIENTINFO*) clientWnd->wExtra;
1925 wnd = ci->hwndActiveChild;
1927 WIN_ReleaseWndPtr(clientWnd);
1929 if( IsWindow(wnd) && !(GetWindowLongA(wnd,GWL_STYLE) & WS_DISABLED) )
1931 WPARAM16 wParam = 0;
1933 /* translate if the Ctrl key is down and Alt not. */
1935 if( (GetKeyState(VK_CONTROL) & 0x8000) &&
1936 !(GetKeyState(VK_MENU) & 0x8000))
1938 switch( msg->wParam )
1942 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 )
1943 ? SC_NEXTWINDOW : SC_PREVWINDOW;
1952 TRACE("wParam = %04x\n", wParam);
1953 SendMessage16( ci->hwndActiveChild, WM_SYSCOMMAND,
1954 wParam, (LPARAM)msg->wParam);
1959 return 0; /* failure */
1963 /***********************************************************************
1964 * CalcChildScroll (USER.462)
1966 void WINAPI CalcChildScroll16( HWND16 hwnd, WORD scroll )
1969 RECT childRect, clientRect;
1970 INT vmin, vmax, hmin, hmax, vpos, hpos;
1973 if (!(pWnd = WIN_FindWndPtr( hwnd ))) return;
1974 Wnd = WIN_FindWndPtr(hwnd);
1975 GetClientRect( hwnd, &clientRect );
1976 SetRectEmpty( &childRect );
1978 for ( WIN_UpdateWndPtr(&pWnd,pWnd->child); pWnd; WIN_UpdateWndPtr(&pWnd,pWnd->next))
1980 if( pWnd->dwStyle & WS_MAXIMIZE )
1982 ShowScrollBar(hwnd, SB_BOTH, FALSE);
1983 WIN_ReleaseWndPtr(pWnd);
1984 WIN_ReleaseWndPtr(Wnd);
1987 UnionRect( &childRect, &pWnd->rectWindow, &childRect );
1989 WIN_ReleaseWndPtr(pWnd);
1990 UnionRect( &childRect, &clientRect, &childRect );
1992 hmin = childRect.left; hmax = childRect.right - clientRect.right;
1993 hpos = clientRect.left - childRect.left;
1994 vmin = childRect.top; vmax = childRect.bottom - clientRect.bottom;
1995 vpos = clientRect.top - childRect.top;
2000 vpos = hpos; vmin = hmin; vmax = hmax;
2002 info.cbSize = sizeof(info);
2003 info.nMax = vmax; info.nMin = vmin; info.nPos = vpos;
2004 info.fMask = SIF_POS | SIF_RANGE;
2005 SetScrollInfo(hwnd, scroll, &info, TRUE);
2008 SCROLL_SetNCSbState( Wnd, vmin, vmax, vpos,
2011 WIN_ReleaseWndPtr(Wnd);
2015 /***********************************************************************
2016 * ScrollChildren16 (USER.463)
2018 void WINAPI ScrollChildren16(HWND16 hWnd, UINT16 uMsg, WPARAM16 wParam, LPARAM lParam)
2020 ScrollChildren( hWnd, uMsg, wParam, lParam );
2024 /***********************************************************************
2025 * ScrollChildren32 (USER32.448)
2027 void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
2030 WND *wndPtr = WIN_FindWndPtr(hWnd);
2032 INT curPos, length, minPos, maxPos, shift;
2034 if( !wndPtr ) return;
2036 if( uMsg == WM_HSCROLL )
2038 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
2039 curPos = GetScrollPos(hWnd,SB_HORZ);
2040 length = (wndPtr->rectClient.right - wndPtr->rectClient.left)/2;
2041 shift = GetSystemMetrics(SM_CYHSCROLL);
2043 else if( uMsg == WM_VSCROLL )
2045 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
2046 curPos = GetScrollPos(hWnd,SB_VERT);
2047 length = (wndPtr->rectClient.bottom - wndPtr->rectClient.top)/2;
2048 shift = GetSystemMetrics(SM_CXVSCROLL);
2052 WIN_ReleaseWndPtr(wndPtr);
2056 WIN_ReleaseWndPtr(wndPtr);
2060 newPos = curPos - shift;
2063 newPos = curPos + shift;
2066 newPos = curPos - length;
2069 newPos = curPos + length;
2072 case SB_THUMBPOSITION:
2073 newPos = LOWORD(lParam);
2086 CalcChildScroll16(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
2090 if( newPos > maxPos )
2093 if( newPos < minPos )
2096 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
2098 if( uMsg == WM_VSCROLL )
2099 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
2100 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2102 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
2103 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2107 /******************************************************************************
2108 * CascadeWindows [USER32.21] Cascades MDI child windows
2111 * Success: Number of cascaded windows.
2115 CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2116 UINT cKids, const HWND *lpKids)
2118 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2119 hwndParent, wFlags, cKids);
2125 /******************************************************************************
2126 * TileWindows [USER32.545] Tiles MDI child windows
2129 * Success: Number of tiled windows.
2133 TileWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2134 UINT cKids, const HWND *lpKids)
2136 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2137 hwndParent, wFlags, cKids);