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,
210 WND *w = WIN_FindWndPtr(hwnd);
212 HWND hwndFrame = GetParent(hwnd);
213 HMENU oldFrameMenu = GetMenu(hwndFrame);
215 TRACE("%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("%04x %04x %04x\n",
281 hwnd, hmenuFrame, hmenuWindow);
283 FIXME("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("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("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("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("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("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("%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,GetSystemMetrics(SM_CXSIZE),GetSystemMetrics(SM_CYSIZE));
656 hobjDest = SelectObject(hDCDest, hbCopy);
658 BitBlt(hDCDest, 0, 0, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE),
659 hDCSrc, GetSystemMetrics(SM_CXSIZE), 0, SRCCOPY);
661 SelectObject(hDCSrc, hobjSrc);
662 DeleteObject(hbClose);
665 hobjSrc = SelectObject( hDCDest, GetStockObject(BLACK_PEN) );
667 MoveToEx( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, 0, NULL );
668 LineTo( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, GetSystemMetrics(SM_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 = GetSystemMetrics(SM_CYICONSPACING) +
701 GetSystemMetrics(SM_CYICON);
703 /* walk the list (backwards) and move windows */
704 while (*ppWnd) ppWnd++;
705 while (ppWnd != heapPtr)
708 TRACE("move %04x to (%ld,%ld) size [%ld,%ld]\n",
709 (*ppWnd)->hwndSelf, pos[0].x, pos[0].y, pos[1].x, pos[1].y);
711 MDI_CalcDefaultChildPos(clientWnd, n++, pos, delta);
712 SetWindowPos( (*ppWnd)->hwndSelf, 0, pos[0].x, pos[0].y,
714 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
717 WIN_ReleaseWinArray(heapPtr);
720 if( total < ci->nActiveChildren )
721 ArrangeIconicWindows( clientWnd->hwndSelf );
725 /**********************************************************************
728 static void MDITile( WND* wndClient, MDICLIENTINFO *ci, WPARAM wParam )
733 if (ci->hwndChildMaximized)
734 SendMessageA( wndClient->hwndSelf, WM_MDIRESTORE,
735 (WPARAM)ci->hwndChildMaximized, 0);
737 if (ci->nActiveChildren == 0) return;
739 ppWnd = WIN_BuildWinArray(wndClient, BWA_SKIPHIDDEN | BWA_SKIPOWNED | BWA_SKIPICONIC |
740 ((wParam & MDITILE_SKIPDISABLED)? BWA_SKIPDISABLED : 0), &total );
742 TRACE("%u windows to tile\n", total);
746 WND** heapPtr = ppWnd;
751 int x, y, xsize, ysize;
752 int rows, columns, r, c, i;
754 GetClientRect(wndClient->hwndSelf,&rect);
755 rows = (int) sqrt((double)total);
756 columns = total / rows;
758 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
761 rows = columns; /* exchange r and c */
765 if( total != ci->nActiveChildren)
767 y = rect.bottom - 2 * GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
768 rect.bottom = ( y - GetSystemMetrics(SM_CYICON) < rect.top )? rect.bottom: y;
771 ysize = rect.bottom / rows;
772 xsize = rect.right / columns;
774 for (x = i = 0, c = 1; c <= columns && *ppWnd; c++)
779 ysize = rect.bottom / rows;
783 for (r = 1; r <= rows && *ppWnd; r++, i++)
785 SetWindowPos((*ppWnd)->hwndSelf, 0, x, y, xsize, ysize,
786 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
793 WIN_ReleaseWinArray(heapPtr);
796 if( total < ci->nActiveChildren ) ArrangeIconicWindows( wndClient->hwndSelf );
799 /* ----------------------- Frame window ---------------------------- */
802 /**********************************************************************
803 * MDI_AugmentFrameMenu
805 static BOOL MDI_AugmentFrameMenu( MDICLIENTINFO* ci, WND *frame,
808 WND* child = WIN_FindWndPtr(hChild);
810 HBITMAP hSysMenuBitmap = 0;
812 TRACE("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("\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 /* In Win 95 look, the system menu is replaced by the child icon */
836 if(TWEAK_WineLook > WIN31_LOOK)
838 HICON hIcon = GetClassLongA(hChild, GCL_HICONSM);
840 hIcon = GetClassLongA(hChild, GCL_HICON);
844 HBITMAP hBitmap, hOldBitmap;
846 HDC hdc = GetDC(hChild);
851 cx = GetSystemMetrics(SM_CXSMICON);
852 cy = GetSystemMetrics(SM_CYSMICON);
853 hMemDC = CreateCompatibleDC(hdc);
854 hBitmap = CreateCompatibleBitmap(hdc, cx, cy);
855 hOldBitmap = SelectObject(hMemDC, hBitmap);
856 SetMapMode(hMemDC, MM_TEXT);
857 hBrush = CreateSolidBrush(GetSysColor(COLOR_MENU));
858 DrawIconEx(hMemDC, 0, 0, hIcon, cx, cy, 0, hBrush, DI_NORMAL);
859 SelectObject (hMemDC, hOldBitmap);
860 DeleteObject(hBrush);
862 ReleaseDC(hChild, hdc);
863 hSysMenuBitmap = hBitmap;
868 hSysMenuBitmap = hBmpClose;
870 if( !InsertMenuA(frame->wIDmenu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
871 hSysPopup, (LPSTR)(DWORD)hSysMenuBitmap))
873 TRACE("not inserted\n");
874 DestroyMenu(hSysPopup);
878 /* The close button is only present in Win 95 look */
879 if(TWEAK_WineLook > WIN31_LOOK)
881 AppendMenuA(frame->wIDmenu,MF_HELP | MF_BITMAP,
882 SC_CLOSE, (LPSTR)(DWORD)HBMMENU_MBAR_CLOSE );
885 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
886 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
887 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
888 SetMenuDefaultItem(hSysPopup, SC_CLOSE, FALSE);
891 DrawMenuBar(frame->hwndSelf);
896 /**********************************************************************
897 * MDI_RestoreFrameMenu
899 static BOOL MDI_RestoreFrameMenu( WND *frameWnd, HWND hChild )
901 INT nItems = GetMenuItemCount(frameWnd->wIDmenu) - 1;
902 UINT iId = GetMenuItemID(frameWnd->wIDmenu,nItems) ;
904 TRACE("frameWnd %p,child %04x\n",frameWnd,hChild);
906 if(!(iId == SC_RESTORE || iId == SC_CLOSE) )
910 RemoveMenu(frameWnd->wIDmenu,0,MF_BYPOSITION);
912 if(TWEAK_WineLook > WIN31_LOOK)
915 DeleteMenu(frameWnd->wIDmenu,GetMenuItemCount(frameWnd->wIDmenu) - 1,MF_BYPOSITION);
918 DeleteMenu(frameWnd->wIDmenu,GetMenuItemCount(frameWnd->wIDmenu) - 1,MF_BYPOSITION);
920 DeleteMenu(frameWnd->wIDmenu,GetMenuItemCount(frameWnd->wIDmenu) - 1,MF_BYPOSITION);
922 DrawMenuBar(frameWnd->hwndSelf);
928 /**********************************************************************
929 * MDI_UpdateFrameText
931 * used when child window is maximized/restored
933 * Note: lpTitle can be NULL
935 static void MDI_UpdateFrameText( WND *frameWnd, HWND hClient,
936 BOOL repaint, LPCSTR lpTitle )
938 char lpBuffer[MDI_MAXTITLELENGTH+1];
939 WND* clientWnd = WIN_FindWndPtr(hClient);
940 MDICLIENTINFO *ci = (MDICLIENTINFO *) clientWnd->wExtra;
942 TRACE("repaint %i, frameText %s\n", repaint, (lpTitle)?lpTitle:"NULL");
949 WIN_ReleaseWndPtr(clientWnd);
953 /* store new "default" title if lpTitle is not NULL */
956 if (ci->frameTitle) HeapFree( SystemHeap, 0, ci->frameTitle );
957 ci->frameTitle = HEAP_strdupA( SystemHeap, 0, lpTitle );
962 WND* childWnd = WIN_FindWndPtr( ci->hwndChildMaximized );
964 if( childWnd && childWnd->text )
966 /* combine frame title and child title if possible */
968 LPCSTR lpBracket = " - [";
969 int i_frame_text_length = strlen(ci->frameTitle);
970 int i_child_text_length = strlen(childWnd->text);
972 lstrcpynA( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
974 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
976 strcat( lpBuffer, lpBracket );
978 if( i_frame_text_length + i_child_text_length + 6 < MDI_MAXTITLELENGTH )
980 strcat( lpBuffer, childWnd->text );
981 strcat( lpBuffer, "]" );
985 lstrcpynA( lpBuffer + i_frame_text_length + 4,
986 childWnd->text, MDI_MAXTITLELENGTH - i_frame_text_length - 5 );
987 strcat( lpBuffer, "]" );
993 strncpy(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH );
994 lpBuffer[MDI_MAXTITLELENGTH]='\0';
996 WIN_ReleaseWndPtr(childWnd);
1002 DEFWND_SetText( frameWnd, lpBuffer );
1003 if( repaint == MDI_REPAINTFRAME)
1004 SetWindowPos( frameWnd->hwndSelf, 0,0,0,0,0, SWP_FRAMECHANGED |
1005 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
1007 WIN_ReleaseWndPtr(clientWnd);
1012 /* ----------------------------- Interface ---------------------------- */
1015 /**********************************************************************
1018 * This function handles all MDI requests.
1020 LRESULT WINAPI MDIClientWndProc( HWND hwnd, UINT message, WPARAM wParam,
1026 WND *w = WIN_FindWndPtr(hwnd);
1027 WND *frameWnd = WIN_LockWndPtr(w->parent);
1031 ci = (MDICLIENTINFO *) w->wExtra;
1037 cs = (LPCREATESTRUCTA)lParam;
1039 /* Translation layer doesn't know what's in the cs->lpCreateParams
1040 * so we have to keep track of what environment we're in. */
1042 if( w->flags & WIN_ISWIN32 )
1044 #define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1045 ci->hWindowMenu = ccs->hWindowMenu;
1046 ci->idFirstChild = ccs->idFirstChild;
1051 LPCLIENTCREATESTRUCT16 ccs = (LPCLIENTCREATESTRUCT16)
1052 PTR_SEG_TO_LIN(cs->lpCreateParams);
1053 ci->hWindowMenu = ccs->hWindowMenu;
1054 ci->idFirstChild = ccs->idFirstChild;
1057 ci->hwndChildMaximized = 0;
1058 ci->nActiveChildren = 0;
1059 ci->nTotalCreated = 0;
1060 ci->frameTitle = NULL;
1063 w->dwStyle |= WS_CLIPCHILDREN;
1067 hBmpClose = CreateMDIMenuBitmap();
1068 hBmpRestore = LoadBitmap16( 0, MAKEINTRESOURCE16(OBM_RESTORE) );
1070 MDI_UpdateFrameText(frameWnd, hwnd, MDI_NOFRAMEREPAINT,frameWnd->text);
1072 AppendMenuA( ci->hWindowMenu, MF_SEPARATOR, 0, NULL );
1074 GetClientRect(frameWnd->hwndSelf, &rect);
1075 NC_HandleNCCalcSize( w, &rect );
1076 w->rectClient = rect;
1078 TRACE("Client created - hwnd = %04x, idFirst = %u\n",
1079 hwnd, ci->idFirstChild );
1085 if( ci->hwndChildMaximized ) MDI_RestoreFrameMenu(w, frameWnd->hwndSelf);
1086 if((nItems = GetMenuItemCount(ci->hWindowMenu)) > 0)
1088 ci->idFirstChild = nItems - 1;
1089 ci->nActiveChildren++; /* to delete a separator */
1090 while( ci->nActiveChildren-- )
1091 DeleteMenu(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
1096 case WM_MDIACTIVATE:
1097 if( ci->hwndActiveChild != (HWND)wParam )
1098 SetWindowPos((HWND)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
1103 retvalue = MDICascade(w, ci);
1107 if (lParam) retvalue = MDICreateChild( w, ci, hwnd,
1108 (MDICREATESTRUCTA*)lParam );
1113 retvalue = MDIDestroyChild( w, ci, hwnd, (HWND)wParam, TRUE );
1116 case WM_MDIGETACTIVE:
1117 if (lParam) *(BOOL *)lParam = (ci->hwndChildMaximized > 0);
1118 retvalue = ci->hwndActiveChild;
1121 case WM_MDIICONARRANGE:
1122 ci->mdiFlags |= MDIF_NEEDUPDATE;
1123 ArrangeIconicWindows(hwnd);
1124 ci->sbRecalc = SB_BOTH+1;
1125 SendMessageA(hwnd, WM_MDICALCCHILDSCROLL, 0, 0L);
1129 case WM_MDIMAXIMIZE:
1130 ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1134 case WM_MDINEXT: /* lParam != 0 means previous window */
1135 MDI_SwitchActiveChild(hwnd, (HWND)wParam, (lParam)? FALSE : TRUE );
1139 SendMessageA( (HWND)wParam, WM_SYSCOMMAND, SC_RESTORE, 0);
1144 retvalue = MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1146 case WM_MDIREFRESHMENU:
1147 retvalue = MDIRefreshMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1151 ci->mdiFlags |= MDIF_NEEDUPDATE;
1152 ShowScrollBar(hwnd,SB_BOTH,FALSE);
1153 MDITile(w, ci, wParam);
1154 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1160 ci->mdiFlags |= MDIF_NEEDUPDATE;
1161 ScrollChildren(hwnd, message, wParam, lParam);
1162 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1167 if( ci->hwndActiveChild )
1169 WND* pw = WIN_FindWndPtr( ci->hwndActiveChild );
1170 if( !(pw->dwStyle & WS_MINIMIZE) )
1171 SetFocus( ci->hwndActiveChild );
1172 WIN_ReleaseWndPtr(pw);
1178 if( ci->hwndActiveChild )
1179 SendMessageA(ci->hwndActiveChild, message, wParam, lParam);
1182 case WM_PARENTNOTIFY:
1183 if (LOWORD(wParam) == WM_LBUTTONDOWN)
1185 POINT16 pt = MAKEPOINT16(lParam);
1186 HWND16 child = ChildWindowFromPoint16(hwnd, pt);
1188 TRACE("notification from %04x (%i,%i)\n",child,pt.x,pt.y);
1190 if( child && child != hwnd && child != ci->hwndActiveChild )
1191 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1197 if( IsWindow(ci->hwndChildMaximized) )
1199 WND* child = WIN_FindWndPtr(ci->hwndChildMaximized);
1204 rect.right = LOWORD(lParam);
1205 rect.bottom = HIWORD(lParam);
1207 AdjustWindowRectEx(&rect, child->dwStyle, 0, child->dwExStyle);
1208 MoveWindow(ci->hwndChildMaximized, rect.left, rect.top,
1209 rect.right - rect.left, rect.bottom - rect.top, 1);
1210 WIN_ReleaseWndPtr(child);
1213 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1217 case WM_MDICALCCHILDSCROLL:
1218 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1220 CalcChildScroll16(hwnd, ci->sbRecalc-1);
1222 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1228 retvalue = DefWindowProcA( hwnd, message, wParam, lParam );
1230 WIN_ReleaseWndPtr(w);
1231 WIN_ReleaseWndPtr(frameWnd);
1236 /***********************************************************************
1237 * DefFrameProc16 (USER.445)
1239 LRESULT WINAPI DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient,
1240 UINT16 message, WPARAM16 wParam, LPARAM lParam )
1251 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1254 ERR("null wndPtr for mdi window hwndMDIClient=%04x\n",
1259 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1261 /* check for possible syscommands for maximized MDI child */
1262 WIN_ReleaseWndPtr(wndPtr);
1265 wParam < ci->idFirstChild ||
1266 wParam >= ci->idFirstChild + ci->nActiveChildren
1268 if( (wParam - 0xF000) & 0xF00F ) break;
1279 if( ci->hwndChildMaximized )
1280 return SendMessage16( ci->hwndChildMaximized, WM_SYSCOMMAND,
1286 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1287 childHwnd = MDI_GetChildByID(wndPtr,wParam );
1288 WIN_ReleaseWndPtr(wndPtr);
1291 SendMessage16(hwndMDIClient, WM_MDIACTIVATE,
1292 (WPARAM16)childHwnd , 0L);
1297 SendMessage16(hwndMDIClient, message, wParam, lParam);
1301 wndPtr = WIN_FindWndPtr(hwnd);
1302 MDI_UpdateFrameText(wndPtr, hwndMDIClient,
1304 (LPCSTR)PTR_SEG_TO_LIN(lParam));
1305 WIN_ReleaseWndPtr(wndPtr);
1309 SetFocus(hwndMDIClient);
1313 MoveWindow16(hwndMDIClient, 0, 0,
1314 LOWORD(lParam), HIWORD(lParam), TRUE);
1319 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1320 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1322 if( !(wndPtr->parent->dwStyle & WS_MINIMIZE)
1323 && ci->hwndActiveChild && !ci->hwndChildMaximized )
1325 /* control menu is between the frame system menu and
1326 * the first entry of menu bar */
1328 if( (wParam == VK_LEFT &&
1329 wndPtr->parent->wIDmenu == LOWORD(lParam)) ||
1330 (wParam == VK_RIGHT &&
1331 GetSubMenu16(wndPtr->parent->hSysMenu, 0) == LOWORD(lParam)) )
1334 WIN_ReleaseWndPtr(wndPtr);
1335 wndPtr = WIN_FindWndPtr(ci->hwndActiveChild);
1336 retvalue = MAKELONG( GetSubMenu16(wndPtr->hSysMenu, 0),
1337 ci->hwndActiveChild);
1338 WIN_ReleaseWndPtr(wndPtr);
1342 WIN_ReleaseWndPtr(wndPtr);
1347 return DefWindowProc16(hwnd, message, wParam, lParam);
1351 /***********************************************************************
1352 * DefFrameProc32A (USER32.122)
1354 LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1355 UINT message, WPARAM wParam, LPARAM lParam)
1362 return DefFrameProc16( hwnd, hwndMDIClient, message,
1364 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1367 SendMessageA(hwndMDIClient, message, wParam, lParam);
1372 LPSTR segstr = SEGPTR_STRDUP((LPSTR)lParam);
1374 ret = DefFrameProc16(hwnd, hwndMDIClient, message,
1375 wParam, (LPARAM)SEGPTR_GET(segstr) );
1376 SEGPTR_FREE(segstr);
1383 return DefFrameProc16( hwnd, hwndMDIClient, message,
1388 return DefWindowProcA(hwnd, message, wParam, lParam);
1392 /***********************************************************************
1393 * DefFrameProc32W (USER32.123)
1395 LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1396 UINT message, WPARAM wParam, LPARAM lParam)
1403 return DefFrameProc16( hwnd, hwndMDIClient, message,
1405 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1408 SendMessageW(hwndMDIClient, message, wParam, lParam);
1413 LPSTR txt = HEAP_strdupWtoA(GetProcessHeap(),0,(LPWSTR)lParam);
1414 LRESULT ret = DefFrameProcA( hwnd, hwndMDIClient, message,
1415 wParam, (DWORD)txt );
1416 HeapFree(GetProcessHeap(),0,txt);
1422 return DefFrameProcA( hwnd, hwndMDIClient, message,
1427 return DefWindowProcW( hwnd, message, wParam, lParam );
1431 /***********************************************************************
1432 * DefMDIChildProc16 (USER.447)
1434 LRESULT WINAPI DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1435 WPARAM16 wParam, LPARAM lParam )
1438 WND *clientWnd,*tmpWnd = 0;
1441 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1442 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1447 DefWindowProc16(hwnd, message, wParam, lParam);
1448 MDI_MenuModifyItem(clientWnd,hwnd);
1449 if( ci->hwndChildMaximized == hwnd )
1450 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1451 MDI_REPAINTFRAME, NULL );
1456 SendMessage16(ci->self,WM_MDIDESTROY,(WPARAM16)hwnd,0L);
1461 if( ci->hwndActiveChild != hwnd )
1462 MDI_ChildActivate(clientWnd, hwnd);
1465 case WM_CHILDACTIVATE:
1466 MDI_ChildActivate(clientWnd, hwnd);
1471 TRACE("WM_NCPAINT for %04x, active %04x\n",
1472 hwnd, ci->hwndActiveChild );
1479 if( ci->hwndChildMaximized == hwnd)
1487 tmpWnd = WIN_FindWndPtr(hwnd);
1488 tmpWnd->dwStyle |= WS_SYSMENU;
1489 WIN_ReleaseWndPtr(tmpWnd);
1492 if( ci->hwndChildMaximized == hwnd)
1494 retvalue = SendMessage16( clientWnd->parent->hwndSelf,
1495 message, wParam, lParam);
1498 tmpWnd = WIN_FindWndPtr(hwnd);
1499 tmpWnd->dwStyle &= ~WS_SYSMENU;
1500 WIN_ReleaseWndPtr(tmpWnd);
1503 SendMessage16( ci->self, WM_MDINEXT, 0, 0);
1507 SendMessage16( ci->self, WM_MDINEXT, 0, 1);
1513 case WM_GETMINMAXINFO:
1514 MDI_ChildGetMinMaxInfo(clientWnd, hwnd, (MINMAXINFO16*) PTR_SEG_TO_LIN(lParam));
1519 if( ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1521 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1527 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1529 ci->hwndChildMaximized = 0;
1531 MDI_RestoreFrameMenu( clientWnd->parent, hwnd);
1532 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1533 MDI_REPAINTFRAME, NULL );
1536 if( wParam == SIZE_MAXIMIZED )
1538 HWND16 hMaxChild = ci->hwndChildMaximized;
1540 if( hMaxChild == hwnd ) break;
1544 SendMessage16( hMaxChild, WM_SETREDRAW, FALSE, 0L );
1546 MDI_RestoreFrameMenu( clientWnd->parent, hMaxChild);
1547 ShowWindow16( hMaxChild, SW_SHOWNOACTIVATE);
1549 SendMessage16( hMaxChild, WM_SETREDRAW, TRUE, 0L );
1552 TRACE("maximizing child %04x\n", hwnd );
1554 ci->hwndChildMaximized = hwnd; /* !!! */
1555 ci->hwndActiveChild = hwnd;
1557 MDI_AugmentFrameMenu( ci, clientWnd->parent, hwnd);
1558 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1559 MDI_REPAINTFRAME, NULL );
1562 if( wParam == SIZE_MINIMIZED )
1564 HWND16 switchTo = MDI_GetWindow(clientWnd, hwnd, TRUE, WS_MINIMIZE);
1567 SendMessage16( switchTo, WM_CHILDACTIVATE, 0, 0L);
1570 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1575 /* MDI children don't have menu bars */
1576 PostMessage16( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1577 (WPARAM16)SC_KEYMENU, (LPARAM)wParam);
1578 retvalue = 0x00010000L;
1583 if( wParam == VK_LEFT ) /* switch to frame system menu */
1585 retvalue = MAKELONG( GetSubMenu16(clientWnd->parent->hSysMenu, 0),
1586 clientWnd->parent->hwndSelf );
1589 if( wParam == VK_RIGHT ) /* to frame menu bar */
1591 retvalue = MAKELONG( clientWnd->parent->wIDmenu,
1592 clientWnd->parent->hwndSelf );
1601 SendMessage16(hwnd,WM_SYSCOMMAND,
1602 (WPARAM16)SC_KEYMENU, (LPARAM)(DWORD)VK_SPACE);
1608 retvalue = DefWindowProc16(hwnd, message, wParam, lParam);
1610 WIN_ReleaseWndPtr(clientWnd);
1615 /***********************************************************************
1616 * DefMDIChildProc32A (USER32.124)
1618 LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1619 WPARAM wParam, LPARAM lParam )
1622 WND *clientWnd,*tmpWnd;
1625 tmpWnd = WIN_FindWndPtr(hwnd);
1626 clientWnd = WIN_FindWndPtr(tmpWnd->parent->hwndSelf);
1627 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1628 WIN_ReleaseWndPtr(tmpWnd);
1633 DefWindowProcA(hwnd, message, wParam, lParam);
1634 MDI_MenuModifyItem(clientWnd,hwnd);
1635 if( ci->hwndChildMaximized == hwnd )
1636 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1637 MDI_REPAINTFRAME, NULL );
1641 case WM_GETMINMAXINFO:
1644 STRUCT32_MINMAXINFO32to16( (MINMAXINFO *)lParam, &mmi );
1645 MDI_ChildGetMinMaxInfo( clientWnd, hwnd, &mmi );
1646 STRUCT32_MINMAXINFO16to32( &mmi, (MINMAXINFO *)lParam );
1653 /* MDI children don't have menu bars */
1654 PostMessage16( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1655 (WPARAM16)SC_KEYMENU, (LPARAM)LOWORD(wParam) );
1656 retvalue = 0x00010000L;
1661 case WM_CHILDACTIVATE:
1667 retvalue = DefMDIChildProc16( hwnd, message, (WPARAM16)wParam, lParam );
1673 SendMessageA(hwnd,WM_SYSCOMMAND,
1674 (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)VK_SPACE);
1679 retvalue = DefWindowProcA(hwnd, message, wParam, lParam);
1681 WIN_ReleaseWndPtr(clientWnd);
1686 /***********************************************************************
1687 * DefMDIChildProc32W (USER32.125)
1689 LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1690 WPARAM wParam, LPARAM lParam )
1696 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1697 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1702 DefWindowProcW(hwnd, message, wParam, lParam);
1703 MDI_MenuModifyItem(clientWnd,hwnd);
1704 if( ci->hwndChildMaximized == hwnd )
1705 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1706 MDI_REPAINTFRAME, NULL );
1710 case WM_GETMINMAXINFO:
1714 case WM_CHILDACTIVATE:
1720 retvalue = DefMDIChildProcA( hwnd, message, (WPARAM16)wParam, lParam );
1726 SendMessageW(hwnd,WM_SYSCOMMAND,
1727 (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)VK_SPACE);
1732 retvalue = DefWindowProcW(hwnd, message, wParam, lParam);
1734 WIN_ReleaseWndPtr(clientWnd);
1740 /**********************************************************************
1741 * CreateMDIWindowA [USER32.79] Creates a MDI child in new thread
1742 * FIXME: its in the same thread now
1745 * Success: Handle to created window
1748 HWND WINAPI CreateMDIWindowA(
1749 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1750 LPCSTR lpWindowName, /* [in] Pointer to window name */
1751 DWORD dwStyle, /* [in] Window style */
1752 INT X, /* [in] Horizontal position of window */
1753 INT Y, /* [in] Vertical position of window */
1754 INT nWidth, /* [in] Width of window */
1755 INT nHeight, /* [in] Height of window */
1756 HWND hWndParent, /* [in] Handle to parent window */
1757 HINSTANCE hInstance, /* [in] Handle to application instance */
1758 LPARAM lParam) /* [in] Application-defined value */
1760 WARN("is only single threaded!\n");
1761 return MDI_CreateMDIWindowA(lpClassName, lpWindowName, dwStyle, X, Y,
1762 nWidth, nHeight, hWndParent, hInstance, lParam);
1765 /**********************************************************************
1766 * MDI_CreateMDIWindowA
1767 * single threaded version of CreateMDIWindowA
1768 * called by CreateWindowEx32A
1770 HWND MDI_CreateMDIWindowA(
1772 LPCSTR lpWindowName,
1779 HINSTANCE hInstance,
1783 MDICREATESTRUCTA cs;
1784 WND *pWnd=WIN_FindWndPtr(hWndParent);
1787 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
1788 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1789 nWidth,nHeight,hWndParent,hInstance,lParam);
1792 ERR(" bad hwnd for MDI-client: %d\n",hWndParent);
1795 cs.szClass=lpClassName;
1796 cs.szTitle=lpWindowName;
1797 cs.hOwner=hInstance;
1805 pCi=(MDICLIENTINFO *)pWnd->wExtra;
1807 retvalue = MDICreateChild(pWnd,pCi,hWndParent,&cs);
1808 WIN_ReleaseWndPtr(pWnd);
1812 /***************************************
1813 * CreateMDIWindow32W [USER32.80] Creates a MDI child in new thread
1816 * Success: Handle to created window
1819 HWND WINAPI CreateMDIWindowW(
1820 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1821 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1822 DWORD dwStyle, /* [in] Window style */
1823 INT X, /* [in] Horizontal position of window */
1824 INT Y, /* [in] Vertical position of window */
1825 INT nWidth, /* [in] Width of window */
1826 INT nHeight, /* [in] Height of window */
1827 HWND hWndParent, /* [in] Handle to parent window */
1828 HINSTANCE hInstance, /* [in] Handle to application instance */
1829 LPARAM lParam) /* [in] Application-defined value */
1831 FIXME("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld): stub\n",
1832 debugstr_w(lpClassName),debugstr_w(lpWindowName),dwStyle,X,Y,
1833 nWidth,nHeight,hWndParent,hInstance,lParam);
1838 /******************************************************************************
1839 * CreateMDIWindow32W [USER32.80] Creates a MDI child window
1840 * single threaded version of CreateMDIWindow
1841 * called by CreateWindowEx32W().
1843 HWND MDI_CreateMDIWindowW(
1844 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1845 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1846 DWORD dwStyle, /* [in] Window style */
1847 INT X, /* [in] Horizontal position of window */
1848 INT Y, /* [in] Vertical position of window */
1849 INT nWidth, /* [in] Width of window */
1850 INT nHeight, /* [in] Height of window */
1851 HWND hWndParent, /* [in] Handle to parent window */
1852 HINSTANCE hInstance, /* [in] Handle to application instance */
1853 LPARAM lParam) /* [in] Application-defined value */
1855 FIXME("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld): stub\n",
1856 debugstr_w(lpClassName),debugstr_w(lpWindowName),dwStyle,X,Y,
1857 nWidth,nHeight,hWndParent,hInstance,lParam);
1862 /**********************************************************************
1863 * TranslateMDISysAccel32 (USER32.555)
1865 BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1869 STRUCT32_MSG32to16(msg,&msg16);
1870 /* MDICLIENTINFO is still the same for win32 and win16 ... */
1871 return TranslateMDISysAccel16(hwndClient,&msg16);
1875 /**********************************************************************
1876 * TranslateMDISysAccel16 (USER.451)
1878 BOOL16 WINAPI TranslateMDISysAccel16( HWND16 hwndClient, LPMSG16 msg )
1881 if( IsWindow(hwndClient) && (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN))
1883 MDICLIENTINFO *ci = NULL;
1885 WND *clientWnd = WIN_FindWndPtr(hwndClient);
1887 ci = (MDICLIENTINFO*) clientWnd->wExtra;
1888 wnd = ci->hwndActiveChild;
1890 WIN_ReleaseWndPtr(clientWnd);
1892 if( IsWindow(wnd) && !(GetWindowLongA(wnd,GWL_STYLE) & WS_DISABLED) )
1894 WPARAM16 wParam = 0;
1896 /* translate if the Ctrl key is down and Alt not. */
1898 if( (GetKeyState(VK_CONTROL) & 0x8000) &&
1899 !(GetKeyState(VK_MENU) & 0x8000))
1901 switch( msg->wParam )
1905 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 )
1906 ? SC_NEXTWINDOW : SC_PREVWINDOW;
1915 TRACE("wParam = %04x\n", wParam);
1916 SendMessage16( ci->hwndActiveChild, WM_SYSCOMMAND,
1917 wParam, (LPARAM)msg->wParam);
1922 return 0; /* failure */
1926 /***********************************************************************
1927 * CalcChildScroll (USER.462)
1929 void WINAPI CalcChildScroll16( HWND16 hwnd, WORD scroll )
1932 RECT childRect, clientRect;
1933 INT vmin, vmax, hmin, hmax, vpos, hpos;
1936 if (!(pWnd = WIN_FindWndPtr( hwnd ))) return;
1937 Wnd = WIN_FindWndPtr(hwnd);
1938 GetClientRect( hwnd, &clientRect );
1939 SetRectEmpty( &childRect );
1941 for ( WIN_UpdateWndPtr(&pWnd,pWnd->child); pWnd; WIN_UpdateWndPtr(&pWnd,pWnd->next))
1943 if( pWnd->dwStyle & WS_MAXIMIZE )
1945 ShowScrollBar(hwnd, SB_BOTH, FALSE);
1946 WIN_ReleaseWndPtr(pWnd);
1947 WIN_ReleaseWndPtr(Wnd);
1950 UnionRect( &childRect, &pWnd->rectWindow, &childRect );
1952 WIN_ReleaseWndPtr(pWnd);
1953 UnionRect( &childRect, &clientRect, &childRect );
1955 hmin = childRect.left; hmax = childRect.right - clientRect.right;
1956 hpos = clientRect.left - childRect.left;
1957 vmin = childRect.top; vmax = childRect.bottom - clientRect.bottom;
1958 vpos = clientRect.top - childRect.top;
1963 vpos = hpos; vmin = hmin; vmax = hmax;
1965 info.cbSize = sizeof(info);
1966 info.nMax = vmax; info.nMin = vmin; info.nPos = vpos;
1967 info.fMask = SIF_POS | SIF_RANGE;
1968 SetScrollInfo(hwnd, scroll, &info, TRUE);
1971 SCROLL_SetNCSbState( Wnd, vmin, vmax, vpos,
1974 WIN_ReleaseWndPtr(Wnd);
1978 /***********************************************************************
1979 * ScrollChildren16 (USER.463)
1981 void WINAPI ScrollChildren16(HWND16 hWnd, UINT16 uMsg, WPARAM16 wParam, LPARAM lParam)
1983 ScrollChildren( hWnd, uMsg, wParam, lParam );
1987 /***********************************************************************
1988 * ScrollChildren32 (USER32.448)
1990 void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
1993 WND *wndPtr = WIN_FindWndPtr(hWnd);
1995 INT curPos, length, minPos, maxPos, shift;
1997 if( !wndPtr ) return;
1999 if( uMsg == WM_HSCROLL )
2001 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
2002 curPos = GetScrollPos(hWnd,SB_HORZ);
2003 length = (wndPtr->rectClient.right - wndPtr->rectClient.left)/2;
2004 shift = GetSystemMetrics(SM_CYHSCROLL);
2006 else if( uMsg == WM_VSCROLL )
2008 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
2009 curPos = GetScrollPos(hWnd,SB_VERT);
2010 length = (wndPtr->rectClient.bottom - wndPtr->rectClient.top)/2;
2011 shift = GetSystemMetrics(SM_CXVSCROLL);
2015 WIN_ReleaseWndPtr(wndPtr);
2019 WIN_ReleaseWndPtr(wndPtr);
2023 newPos = curPos - shift;
2026 newPos = curPos + shift;
2029 newPos = curPos - length;
2032 newPos = curPos + length;
2035 case SB_THUMBPOSITION:
2036 newPos = LOWORD(lParam);
2049 CalcChildScroll16(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
2053 if( newPos > maxPos )
2056 if( newPos < minPos )
2059 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
2061 if( uMsg == WM_VSCROLL )
2062 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
2063 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2065 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
2066 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2070 /******************************************************************************
2071 * CascadeWindows [USER32.21] Cascades MDI child windows
2074 * Success: Number of cascaded windows.
2078 CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2079 UINT cKids, const HWND *lpKids)
2081 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2082 hwndParent, wFlags, cKids);
2088 /******************************************************************************
2089 * TileWindows [USER32.545] Tiles MDI child windows
2092 * Success: Number of tiled windows.
2096 TileWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2097 UINT cKids, const HWND *lpKids)
2099 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2100 hwndParent, wFlags, cKids);