Release 980329
[wine.git] / windows / mdi.c
blob739aa6628e0e263df3baa456408f76ecfed4cd28
1 /* MDI.C
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.
15 #include <stdlib.h>
16 #include <string.h>
17 #include <stdio.h>
18 #include <math.h>
19 #include "windows.h"
20 #include "win.h"
21 #include "heap.h"
22 #include "nonclient.h"
23 #include "mdi.h"
24 #include "user.h"
25 #include "menu.h"
26 #include "resource.h"
27 #include "struct32.h"
28 #include "sysmetrics.h"
29 #include "debug.h"
31 #define MDIF_NEEDUPDATE 0x0001
33 static HBITMAP16 hBmpClose = 0;
34 static HBITMAP16 hBmpRestore = 0;
36 DWORD SCROLL_SetNCSbState(WND*,int,int,int,int,int,int);
38 /* ----------------- declarations ----------------- */
39 static void MDI_UpdateFrameText(WND *, HWND32, BOOL32, LPCSTR);
40 static BOOL32 MDI_AugmentFrameMenu(MDICLIENTINFO*, WND *, HWND32);
41 static BOOL32 MDI_RestoreFrameMenu(WND *, HWND32);
43 static LONG MDI_ChildActivate( WND*, HWND32 );
45 /* -------- Miscellaneous service functions ----------
47 * MDI_GetChildByID
50 static HWND32 MDI_GetChildByID(WND* wndPtr, INT32 id)
52 for (wndPtr = wndPtr->child; wndPtr; wndPtr = wndPtr->next)
53 if (wndPtr->wIDmenu == id) return wndPtr->hwndSelf;
54 return 0;
57 static void MDI_PostUpdate(HWND32 hwnd, MDICLIENTINFO* ci, WORD recalc)
59 if( !(ci->mdiFlags & MDIF_NEEDUPDATE) )
61 ci->mdiFlags |= MDIF_NEEDUPDATE;
62 PostMessage32A( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
64 ci->sbRecalc = recalc;
67 /**********************************************************************
68 * MDI_MenuModifyItem
70 static BOOL32 MDI_MenuModifyItem(WND* clientWnd, HWND32 hWndChild )
72 char buffer[128];
73 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
74 WND *wndPtr = WIN_FindWndPtr(hWndChild);
75 UINT32 n = sprintf(buffer, "%d ",
76 wndPtr->wIDmenu - clientInfo->idFirstChild + 1);
77 BOOL32 bRet = 0;
79 if( !clientInfo->hWindowMenu ) return 0;
81 if (wndPtr->text) lstrcpyn32A(buffer + n, wndPtr->text, sizeof(buffer) - n );
83 n = GetMenuState32(clientInfo->hWindowMenu,wndPtr->wIDmenu ,MF_BYCOMMAND);
84 bRet = ModifyMenu32A(clientInfo->hWindowMenu , wndPtr->wIDmenu,
85 MF_BYCOMMAND | MF_STRING, wndPtr->wIDmenu, buffer );
86 CheckMenuItem32(clientInfo->hWindowMenu ,wndPtr->wIDmenu , n & MF_CHECKED);
87 return bRet;
90 /**********************************************************************
91 * MDI_MenuDeleteItem
93 static BOOL32 MDI_MenuDeleteItem(WND* clientWnd, HWND32 hWndChild )
95 char buffer[128];
96 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
97 WND *wndPtr = WIN_FindWndPtr(hWndChild);
98 UINT32 index = 0,id,n;
100 if( !clientInfo->nActiveChildren ||
101 !clientInfo->hWindowMenu ) return 0;
103 id = wndPtr->wIDmenu;
104 DeleteMenu32(clientInfo->hWindowMenu,id,MF_BYCOMMAND);
106 /* walk the rest of MDI children to prevent gaps in the id
107 * sequence and in the menu child list */
109 for( index = id+1; index <= clientInfo->nActiveChildren +
110 clientInfo->idFirstChild; index++ )
112 wndPtr = WIN_FindWndPtr(MDI_GetChildByID(clientWnd,index));
113 if( !wndPtr )
115 TRACE(mdi,"no window for id=%i\n",index);
116 continue;
119 /* set correct id */
120 wndPtr->wIDmenu--;
122 n = sprintf(buffer, "%d ",index - clientInfo->idFirstChild);
123 if (wndPtr->text)
124 lstrcpyn32A(buffer + n, wndPtr->text, sizeof(buffer) - n );
126 /* change menu */
127 ModifyMenu32A(clientInfo->hWindowMenu ,index ,MF_BYCOMMAND | MF_STRING,
128 index - 1 , buffer );
130 return 1;
133 /**********************************************************************
134 * MDI_GetWindow
136 * returns "activateable" child different from the current or zero
138 static HWND32 MDI_GetWindow(WND *clientWnd, HWND32 hWnd, BOOL32 bNext,
139 DWORD dwStyleMask )
141 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
142 WND *wndPtr, *pWnd, *pWndLast = NULL;
144 dwStyleMask |= WS_DISABLED | WS_VISIBLE;
145 if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
147 if( !(wndPtr = WIN_FindWndPtr(hWnd)) ) return 0;
149 for ( pWnd = wndPtr->next; ; pWnd = pWnd->next )
151 if (!pWnd ) pWnd = wndPtr->parent->child;
153 if ( pWnd == wndPtr ) break; /* went full circle */
155 if (!pWnd->owner && (pWnd->dwStyle & dwStyleMask) == WS_VISIBLE )
157 pWndLast = pWnd;
158 if ( bNext ) break;
161 return pWndLast ? pWndLast->hwndSelf : 0;
164 /**********************************************************************
165 * MDI_CalcDefaultChildPos
167 * It seems that the default height is about 2/3 of the client rect
169 static void MDI_CalcDefaultChildPos( WND* w, WORD n, LPPOINT32 lpPos,
170 INT32 delta)
172 INT32 nstagger;
173 RECT32 rect = w->rectClient;
174 INT32 spacing = GetSystemMetrics32(SM_CYCAPTION) +
175 GetSystemMetrics32(SM_CYFRAME) - 1;
177 if( rect.bottom - rect.top - delta >= spacing )
178 rect.bottom -= delta;
180 nstagger = (rect.bottom - rect.top)/(3 * spacing);
181 lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
182 lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
183 lpPos[0].x = lpPos[0].y = spacing * (n%(nstagger+1));
186 /**********************************************************************
187 * MDISetMenu
189 static LRESULT MDISetMenu( HWND32 hwnd, HMENU32 hmenuFrame,
190 HMENU32 hmenuWindow)
192 WND *w = WIN_FindWndPtr(hwnd);
193 MDICLIENTINFO *ci;
194 HWND32 hwndFrame = GetParent32(hwnd);
195 HMENU32 oldFrameMenu = GetMenu32(hwndFrame);
197 TRACE(mdi, "%04x %04x %04x\n",
198 hwnd, hmenuFrame, hmenuWindow);
200 ci = (MDICLIENTINFO *) w->wExtra;
202 if( ci->hwndChildMaximized && hmenuFrame && hmenuFrame!=oldFrameMenu )
203 MDI_RestoreFrameMenu(w->parent, ci->hwndChildMaximized );
205 if( hmenuWindow && hmenuWindow!=ci->hWindowMenu )
207 /* delete menu items from ci->hWindowMenu
208 * and add them to hmenuWindow */
210 INT32 i = GetMenuItemCount32(ci->hWindowMenu) - 1;
211 INT32 pos = GetMenuItemCount32(hmenuWindow) + 1;
213 AppendMenu32A( hmenuWindow, MF_SEPARATOR, 0, NULL);
215 if( ci->nActiveChildren )
217 INT32 j = i - ci->nActiveChildren + 1;
218 char buffer[100];
219 UINT32 id,state;
221 for( ; i >= j ; i-- )
223 id = GetMenuItemID32(ci->hWindowMenu,i );
224 state = GetMenuState32(ci->hWindowMenu,i,MF_BYPOSITION);
226 GetMenuString32A(ci->hWindowMenu, i, buffer, 100, MF_BYPOSITION);
228 DeleteMenu32(ci->hWindowMenu, i , MF_BYPOSITION);
229 InsertMenu32A(hmenuWindow, pos, MF_BYPOSITION | MF_STRING,
230 id, buffer);
231 CheckMenuItem32(hmenuWindow ,pos , MF_BYPOSITION | (state & MF_CHECKED));
235 /* remove separator */
236 DeleteMenu32(ci->hWindowMenu, i, MF_BYPOSITION);
238 ci->hWindowMenu = hmenuWindow;
241 if( hmenuFrame && hmenuFrame!=oldFrameMenu)
243 SetMenu32(hwndFrame, hmenuFrame);
244 if( ci->hwndChildMaximized )
245 MDI_AugmentFrameMenu(ci, w->parent, ci->hwndChildMaximized );
246 return oldFrameMenu;
248 return 0;
252 /* ------------------ MDI child window functions ---------------------- */
255 /**********************************************************************
256 * MDICreateChild
258 static HWND32 MDICreateChild( WND *w, MDICLIENTINFO *ci, HWND32 parent,
259 LPMDICREATESTRUCT32A cs )
261 POINT32 pos[2];
262 DWORD style = cs->style | (WS_CHILD | WS_CLIPSIBLINGS);
263 HWND32 hwnd, hwndMax = 0;
264 WORD wIDmenu = ci->idFirstChild + ci->nActiveChildren;
265 char lpstrDef[]="junk!";
267 TRACE(mdi, "origin %i,%i - dim %i,%i, style %08x\n",
268 cs->x, cs->y, cs->cx, cs->cy, (unsigned)cs->style);
269 /* calculate placement */
270 MDI_CalcDefaultChildPos(w, ci->nTotalCreated++, pos, 0);
272 if (cs->cx == CW_USEDEFAULT32 || !cs->cx) cs->cx = pos[1].x;
273 if (cs->cy == CW_USEDEFAULT32 || !cs->cy) cs->cy = pos[1].y;
275 if( cs->x == CW_USEDEFAULT32 )
277 cs->x = pos[0].x;
278 cs->y = pos[0].y;
281 /* restore current maximized child */
282 if( style & WS_VISIBLE && ci->hwndChildMaximized )
284 if( style & WS_MAXIMIZE )
285 SendMessage32A(w->hwndSelf, WM_SETREDRAW, FALSE, 0L );
286 hwndMax = ci->hwndChildMaximized;
287 ShowWindow32( hwndMax, SW_SHOWNOACTIVATE );
288 if( style & WS_MAXIMIZE )
289 SendMessage32A(w->hwndSelf, WM_SETREDRAW, TRUE, 0L );
292 /* this menu is needed to set a check mark in MDI_ChildActivate */
293 AppendMenu32A(ci->hWindowMenu ,MF_STRING ,wIDmenu, lpstrDef );
295 ci->nActiveChildren++;
297 /* fix window style */
298 if( !(w->dwStyle & MDIS_ALLCHILDSTYLES) )
300 style &= (WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZE | WS_MAXIMIZE |
301 WS_CLIPCHILDREN | WS_DISABLED | WS_VSCROLL | WS_HSCROLL );
302 style |= (WS_VISIBLE | WS_OVERLAPPEDWINDOW);
305 if( w->flags & WIN_ISWIN32 )
307 hwnd = CreateWindow32A( cs->szClass, cs->szTitle, style,
308 cs->x, cs->y, cs->cx, cs->cy, parent,
309 (HMENU16)wIDmenu, cs->hOwner, cs );
311 else
313 MDICREATESTRUCT16 *cs16;
314 LPSTR title, cls;
316 cs16 = SEGPTR_NEW(MDICREATESTRUCT16);
317 STRUCT32_MDICREATESTRUCT32Ato16( cs, cs16 );
318 title = SEGPTR_STRDUP( cs->szTitle );
319 cls = SEGPTR_STRDUP( cs->szClass );
320 cs16->szTitle = SEGPTR_GET(title);
321 cs16->szClass = SEGPTR_GET(cls);
323 hwnd = CreateWindow16( cs->szClass, cs->szTitle, style,
324 cs16->x, cs16->y, cs16->cx, cs16->cy, parent,
325 (HMENU32)wIDmenu, cs16->hOwner,
326 (LPVOID)SEGPTR_GET(cs16) );
327 SEGPTR_FREE( title );
328 SEGPTR_FREE( cls );
329 SEGPTR_FREE( cs16 );
332 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
334 if (hwnd)
336 WND* wnd = WIN_FindWndPtr( hwnd );
338 MDI_MenuModifyItem(w ,hwnd);
339 if( wnd->dwStyle & WS_MINIMIZE && ci->hwndActiveChild )
340 ShowWindow32( hwnd, SW_SHOWMINNOACTIVE );
341 else
343 SetWindowPos32( hwnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE );
345 /* Set maximized state here in case hwnd didn't receive WM_SIZE
346 * during CreateWindow - bad!
349 if((wnd->dwStyle & WS_MAXIMIZE) && !ci->hwndChildMaximized )
351 ci->hwndChildMaximized = wnd->hwndSelf;
352 MDI_AugmentFrameMenu( ci, w->parent, hwnd );
353 MDI_UpdateFrameText( w->parent, ci->self, MDI_REPAINTFRAME, NULL );
356 TRACE(mdi, "created child - %04x\n",hwnd);
358 else
360 ci->nActiveChildren--;
361 DeleteMenu32(ci->hWindowMenu,wIDmenu,MF_BYCOMMAND);
362 if( IsWindow32(hwndMax) )
363 ShowWindow32(hwndMax, SW_SHOWMAXIMIZED);
366 return hwnd;
369 /**********************************************************************
370 * MDI_ChildGetMinMaxInfo
372 * Note: The rule here is that client rect of the maximized MDI child
373 * is equal to the client rect of the MDI client window.
375 static void MDI_ChildGetMinMaxInfo( WND* clientWnd, HWND32 hwnd,
376 MINMAXINFO16* lpMinMax )
378 WND* childWnd = WIN_FindWndPtr(hwnd);
379 RECT32 rect = clientWnd->rectClient;
381 MapWindowPoints32( clientWnd->parent->hwndSelf,
382 ((MDICLIENTINFO*)clientWnd->wExtra)->self, (LPPOINT32)&rect, 2);
383 AdjustWindowRectEx32( &rect, childWnd->dwStyle, 0, childWnd->dwExStyle );
385 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
386 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
388 lpMinMax->ptMaxPosition.x = rect.left;
389 lpMinMax->ptMaxPosition.y = rect.top;
391 TRACE(mdi,"max rect (%i,%i - %i, %i)\n",
392 rect.left,rect.top,rect.right,rect.bottom);
395 /**********************************************************************
396 * MDI_SwitchActiveChild
398 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
399 * being activated
401 static void MDI_SwitchActiveChild( HWND32 clientHwnd, HWND32 childHwnd,
402 BOOL32 bNextWindow )
404 WND *w = WIN_FindWndPtr(clientHwnd);
405 HWND32 hwndTo = 0;
406 HWND32 hwndPrev = 0;
407 MDICLIENTINFO *ci;
409 hwndTo = MDI_GetWindow(w, childHwnd, bNextWindow, 0);
411 ci = (MDICLIENTINFO *) w->wExtra;
413 TRACE(mdi, "from %04x, to %04x\n",childHwnd,hwndTo);
415 if ( !hwndTo ) return; /* no window to switch to */
417 hwndPrev = ci->hwndActiveChild;
419 if ( hwndTo != hwndPrev )
421 BOOL32 bOptimize = 0;
423 if( ci->hwndChildMaximized )
425 bOptimize = 1;
426 w->dwStyle &= ~WS_VISIBLE;
429 SetWindowPos32( hwndTo, HWND_TOP, 0, 0, 0, 0,
430 SWP_NOMOVE | SWP_NOSIZE );
432 if( bNextWindow && hwndPrev )
433 SetWindowPos32( hwndPrev, HWND_BOTTOM, 0, 0, 0, 0,
434 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
435 if( bOptimize )
436 ShowWindow32( clientHwnd, SW_SHOW );
441 /**********************************************************************
442 * MDIDestroyChild
444 static LRESULT MDIDestroyChild( WND *w_parent, MDICLIENTINFO *ci,
445 HWND32 parent, HWND32 child,
446 BOOL32 flagDestroy )
448 WND *childPtr = WIN_FindWndPtr(child);
450 if( childPtr )
452 if( child == ci->hwndActiveChild )
454 MDI_SwitchActiveChild(parent, child, TRUE);
456 if( child == ci->hwndActiveChild )
458 ShowWindow32( child, SW_HIDE);
459 if( child == ci->hwndChildMaximized )
461 MDI_RestoreFrameMenu(w_parent->parent, child);
462 ci->hwndChildMaximized = 0;
463 MDI_UpdateFrameText(w_parent->parent,parent,TRUE,NULL);
466 MDI_ChildActivate(w_parent, 0);
468 MDI_MenuDeleteItem(w_parent, child);
471 ci->nActiveChildren--;
473 TRACE(mdi,"child destroyed - %04x\n",child);
475 if (flagDestroy)
477 MDI_PostUpdate(GetParent32(child), ci, SB_BOTH+1);
478 DestroyWindow32(child);
482 return 0;
486 /**********************************************************************
487 * MDI_ChildActivate
489 * Note: hWndChild is NULL when last child is being destroyed
491 static LONG MDI_ChildActivate( WND *clientPtr, HWND32 hWndChild )
493 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientPtr->wExtra;
494 HWND32 prevActiveWnd = clientInfo->hwndActiveChild;
495 WND *wndPtr = WIN_FindWndPtr( hWndChild );
496 WND *wndPrev = WIN_FindWndPtr( prevActiveWnd );
497 BOOL32 isActiveFrameWnd = 0;
499 if( hWndChild == prevActiveWnd ) return 0L;
501 if( wndPtr )
502 if( wndPtr->dwStyle & WS_DISABLED ) return 0L;
504 TRACE(mdi,"%04x\n", hWndChild);
506 if( GetActiveWindow32() == clientPtr->parent->hwndSelf )
507 isActiveFrameWnd = TRUE;
509 /* deactivate prev. active child */
510 if( wndPrev )
512 wndPrev->dwStyle |= WS_SYSMENU;
513 SendMessage32A( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
514 SendMessage32A( prevActiveWnd, WM_MDIACTIVATE, (WPARAM32)prevActiveWnd,
515 (LPARAM)hWndChild);
516 /* uncheck menu item */
517 if( clientInfo->hWindowMenu )
518 CheckMenuItem32( clientInfo->hWindowMenu,
519 wndPrev->wIDmenu, 0);
522 /* set appearance */
523 if( clientInfo->hwndChildMaximized )
524 if( clientInfo->hwndChildMaximized != hWndChild )
525 if( hWndChild )
527 clientInfo->hwndActiveChild = hWndChild;
528 ShowWindow32( hWndChild, SW_SHOWMAXIMIZED);
530 else
531 ShowWindow32( clientInfo->hwndActiveChild, SW_SHOWNORMAL );
533 clientInfo->hwndActiveChild = hWndChild;
535 /* check if we have any children left */
536 if( !hWndChild )
538 if( isActiveFrameWnd )
539 SetFocus32( clientInfo->self );
540 return 0;
543 /* check menu item */
544 if( clientInfo->hWindowMenu )
545 CheckMenuItem32( clientInfo->hWindowMenu,
546 wndPtr->wIDmenu, MF_CHECKED);
548 /* bring active child to the top */
549 SetWindowPos32( hWndChild, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
551 if( isActiveFrameWnd )
553 SendMessage32A( hWndChild, WM_NCACTIVATE, TRUE, 0L);
554 if( GetFocus32() == clientInfo->self )
555 SendMessage32A( clientInfo->self, WM_SETFOCUS,
556 (WPARAM32)clientInfo->self, 0L );
557 else
558 SetFocus32( clientInfo->self );
560 SendMessage32A( hWndChild, WM_MDIACTIVATE, (WPARAM32)prevActiveWnd,
561 (LPARAM)hWndChild );
562 return 1;
565 /* -------------------- MDI client window functions ------------------- */
567 /**********************************************************************
568 * CreateMDIMenuBitmap
570 static HBITMAP16 CreateMDIMenuBitmap(void)
572 HDC32 hDCSrc = CreateCompatibleDC32(0);
573 HDC32 hDCDest = CreateCompatibleDC32(hDCSrc);
574 HBITMAP16 hbClose = LoadBitmap16(0, MAKEINTRESOURCE(OBM_CLOSE) );
575 HBITMAP16 hbCopy;
576 HANDLE16 hobjSrc, hobjDest;
578 hobjSrc = SelectObject32(hDCSrc, hbClose);
579 hbCopy = CreateCompatibleBitmap32(hDCSrc,SYSMETRICS_CXSIZE,SYSMETRICS_CYSIZE);
580 hobjDest = SelectObject32(hDCDest, hbCopy);
582 BitBlt32(hDCDest, 0, 0, SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE,
583 hDCSrc, SYSMETRICS_CXSIZE, 0, SRCCOPY);
585 SelectObject32(hDCSrc, hobjSrc);
586 DeleteObject32(hbClose);
587 DeleteDC32(hDCSrc);
589 hobjSrc = SelectObject32( hDCDest, GetStockObject32(BLACK_PEN) );
591 MoveToEx32( hDCDest, SYSMETRICS_CXSIZE - 1, 0, NULL );
592 LineTo32( hDCDest, SYSMETRICS_CXSIZE - 1, SYSMETRICS_CYSIZE - 1);
594 SelectObject32(hDCDest, hobjSrc );
595 SelectObject32(hDCDest, hobjDest);
596 DeleteDC32(hDCDest);
598 return hbCopy;
601 /**********************************************************************
602 * MDICascade
604 static LONG MDICascade(WND* clientWnd, MDICLIENTINFO *ci)
606 WND** ppWnd;
607 UINT32 total;
609 if (ci->hwndChildMaximized)
610 ShowWindow16( ci->hwndChildMaximized, SW_NORMAL);
612 if (ci->nActiveChildren == 0) return 0;
614 if ((ppWnd = WIN_BuildWinArray(clientWnd, BWA_SKIPHIDDEN | BWA_SKIPOWNED |
615 BWA_SKIPICONIC, &total)))
617 WND** heapPtr = ppWnd;
618 if( total )
620 INT32 delta = 0, n = 0;
621 POINT32 pos[2];
622 if( total < ci->nActiveChildren )
623 delta = SYSMETRICS_CYICONSPACING + SYSMETRICS_CYICON;
625 /* walk the list and move windows */
626 while ( *ppWnd )
628 TRACE(mdi, "move %04x to (%d,%d) size [%d,%d]\n",
629 (*ppWnd)->hwndSelf, pos[0].x, pos[0].y, pos[1].x, pos[1].y);
631 MDI_CalcDefaultChildPos(clientWnd, n++, pos, delta);
632 SetWindowPos32( (*ppWnd)->hwndSelf, 0, pos[0].x, pos[0].y,
633 pos[1].x, pos[1].y,
634 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
635 ppWnd++;
638 HeapFree( SystemHeap, 0, heapPtr );
641 if( total < ci->nActiveChildren )
642 ArrangeIconicWindows32( clientWnd->hwndSelf );
643 return 0;
646 /**********************************************************************
647 * MDITile
649 static void MDITile( WND* wndClient, MDICLIENTINFO *ci, WPARAM32 wParam )
651 WND** ppWnd;
652 UINT32 total = 0;
654 if (ci->hwndChildMaximized)
655 ShowWindow32(ci->hwndChildMaximized, SW_NORMAL);
657 if (ci->nActiveChildren == 0) return;
659 ppWnd = WIN_BuildWinArray(wndClient, BWA_SKIPHIDDEN | BWA_SKIPOWNED | BWA_SKIPICONIC |
660 ((wParam & MDITILE_SKIPDISABLED)? BWA_SKIPDISABLED : 0), &total );
662 TRACE(mdi,"%u windows to tile\n", total);
664 if( ppWnd )
666 WND** heapPtr = ppWnd;
668 if( total )
670 RECT32 rect;
671 int x, y, xsize, ysize;
672 int rows, columns, r, c, i;
674 rect = wndClient->rectClient;
675 rows = (int) sqrt((double)total);
676 columns = total / rows;
678 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
680 i = rows;
681 rows = columns; /* exchange r and c */
682 columns = i;
685 if( total != ci->nActiveChildren)
687 y = rect.bottom - 2 * SYSMETRICS_CYICONSPACING - SYSMETRICS_CYICON;
688 rect.bottom = ( y - SYSMETRICS_CYICON < rect.top )? rect.bottom: y;
691 ysize = rect.bottom / rows;
692 xsize = rect.right / columns;
694 for (x = i = 0, c = 1; c <= columns && *ppWnd; c++)
696 if (c == columns)
698 rows = total - i;
699 ysize = rect.bottom / rows;
702 y = 0;
703 for (r = 1; r <= rows && *ppWnd; r++, i++)
705 SetWindowPos32((*ppWnd)->hwndSelf, 0, x, y, xsize, ysize,
706 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
707 y += ysize;
708 ppWnd++;
710 x += xsize;
713 HeapFree( SystemHeap, 0, heapPtr );
716 if( total < ci->nActiveChildren ) ArrangeIconicWindows32( wndClient->hwndSelf );
719 /* ----------------------- Frame window ---------------------------- */
722 /**********************************************************************
723 * MDI_AugmentFrameMenu
725 static BOOL32 MDI_AugmentFrameMenu( MDICLIENTINFO* ci, WND *frame,
726 HWND32 hChild )
728 WND* child = WIN_FindWndPtr(hChild);
729 HMENU32 hSysPopup = 0;
731 TRACE(mdi,"frame %p,child %04x\n",frame,hChild);
733 if( !frame->wIDmenu || !child->hSysMenu ) return 0;
735 /* create a copy of sysmenu popup and insert it into frame menu bar */
737 if (!(hSysPopup = LoadMenuIndirect32A(SYSRES_GetResPtr(SYSRES_MENU_SYSMENU))))
738 return 0;
740 TRACE(mdi,"\tgot popup %04x in sysmenu %04x\n",
741 hSysPopup, child->hSysMenu);
743 if( !InsertMenu32A(frame->wIDmenu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
744 hSysPopup, (LPSTR)(DWORD)hBmpClose ))
746 DestroyMenu32(hSysPopup);
747 return 0;
750 if( !AppendMenu32A(frame->wIDmenu,MF_HELP | MF_BITMAP,
751 SC_RESTORE, (LPSTR)(DWORD)hBmpRestore ))
753 RemoveMenu32(frame->wIDmenu,0,MF_BYPOSITION);
754 return 0;
757 EnableMenuItem32(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
758 EnableMenuItem32(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
759 EnableMenuItem32(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
761 /* redraw menu */
762 DrawMenuBar32(frame->hwndSelf);
764 return 1;
767 /**********************************************************************
768 * MDI_RestoreFrameMenu
770 static BOOL32 MDI_RestoreFrameMenu( WND *frameWnd, HWND32 hChild )
772 INT32 nItems = GetMenuItemCount32(frameWnd->wIDmenu) - 1;
774 TRACE(mdi,"for child %04x\n",hChild);
776 if( GetMenuItemID32(frameWnd->wIDmenu,nItems) != SC_RESTORE )
777 return 0;
779 RemoveMenu32(frameWnd->wIDmenu,0,MF_BYPOSITION);
780 DeleteMenu32(frameWnd->wIDmenu,nItems-1,MF_BYPOSITION);
782 DrawMenuBar32(frameWnd->hwndSelf);
784 return 1;
787 /**********************************************************************
788 * MDI_UpdateFrameText
790 * used when child window is maximized/restored
792 * Note: lpTitle can be NULL
794 static void MDI_UpdateFrameText( WND *frameWnd, HWND32 hClient,
795 BOOL32 repaint, LPCSTR lpTitle )
797 char lpBuffer[MDI_MAXTITLELENGTH+1];
798 WND* clientWnd = WIN_FindWndPtr(hClient);
799 MDICLIENTINFO *ci = (MDICLIENTINFO *) clientWnd->wExtra;
801 TRACE(mdi, "repaint %i, frameText %s\n", repaint, (lpTitle)?lpTitle:"NULL");
803 if (!clientWnd)
804 return;
806 if (!ci)
807 return;
809 /* store new "default" title if lpTitle is not NULL */
810 if (lpTitle)
812 if (ci->frameTitle) HeapFree( SystemHeap, 0, ci->frameTitle );
813 ci->frameTitle = HEAP_strdupA( SystemHeap, 0, lpTitle );
816 if (ci->frameTitle)
818 WND* childWnd = WIN_FindWndPtr( ci->hwndChildMaximized );
820 if( childWnd && childWnd->text )
822 /* combine frame title and child title if possible */
824 LPCSTR lpBracket = " - [";
825 int i_frame_text_length = strlen(ci->frameTitle);
826 int i_child_text_length = strlen(childWnd->text);
828 lstrcpyn32A( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
830 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
832 strcat( lpBuffer, lpBracket );
834 if( i_frame_text_length + i_child_text_length + 6 < MDI_MAXTITLELENGTH )
836 strcat( lpBuffer, childWnd->text );
837 strcat( lpBuffer, "]" );
839 else
841 lstrcpyn32A( lpBuffer + i_frame_text_length + 4,
842 childWnd->text, MDI_MAXTITLELENGTH - i_frame_text_length - 5 );
843 strcat( lpBuffer, "]" );
847 else
849 strncpy(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH );
850 lpBuffer[MDI_MAXTITLELENGTH]='\0';
853 else
854 lpBuffer[0] = '\0';
856 DEFWND_SetText( frameWnd, lpBuffer );
857 if( repaint == MDI_REPAINTFRAME)
858 SetWindowPos32( frameWnd->hwndSelf, 0,0,0,0,0, SWP_FRAMECHANGED |
859 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
863 /* ----------------------------- Interface ---------------------------- */
866 /**********************************************************************
867 * MDIClientWndProc
869 * This function handles all MDI requests.
871 LRESULT WINAPI MDIClientWndProc( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
872 LPARAM lParam )
874 LPCREATESTRUCT32A cs;
875 MDICLIENTINFO *ci;
876 RECT32 rect;
877 WND *w = WIN_FindWndPtr(hwnd);
878 WND *frameWnd = w->parent;
879 INT32 nItems;
881 ci = (MDICLIENTINFO *) w->wExtra;
883 switch (message)
885 case WM_CREATE:
887 cs = (LPCREATESTRUCT32A)lParam;
889 /* Translation layer doesn't know what's in the cs->lpCreateParams
890 * so we have to keep track of what environment we're in. */
892 if( w->flags & WIN_ISWIN32 )
894 #define ccs ((LPCLIENTCREATESTRUCT32)cs->lpCreateParams)
895 ci->hWindowMenu = ccs->hWindowMenu;
896 ci->idFirstChild = ccs->idFirstChild;
897 #undef ccs
899 else
901 LPCLIENTCREATESTRUCT16 ccs = (LPCLIENTCREATESTRUCT16)
902 PTR_SEG_TO_LIN(cs->lpCreateParams);
903 ci->hWindowMenu = ccs->hWindowMenu;
904 ci->idFirstChild = ccs->idFirstChild;
907 ci->hwndChildMaximized = 0;
908 ci->nActiveChildren = 0;
909 ci->nTotalCreated = 0;
910 ci->frameTitle = NULL;
911 ci->mdiFlags = 0;
912 ci->self = hwnd;
913 w->dwStyle |= WS_CLIPCHILDREN;
915 if (!hBmpClose)
917 hBmpClose = CreateMDIMenuBitmap();
918 hBmpRestore = LoadBitmap16( 0, MAKEINTRESOURCE(OBM_RESTORE) );
920 MDI_UpdateFrameText(frameWnd, hwnd, MDI_NOFRAMEREPAINT,frameWnd->text);
922 AppendMenu32A( ci->hWindowMenu, MF_SEPARATOR, 0, NULL );
924 GetClientRect32(frameWnd->hwndSelf, &rect);
925 NC_HandleNCCalcSize( w, &rect );
926 w->rectClient = rect;
928 TRACE(mdi,"Client created - hwnd = %04x, idFirst = %u\n",
929 hwnd, ci->idFirstChild );
931 return 0;
933 case WM_DESTROY:
934 if( ci->hwndChildMaximized ) MDI_RestoreFrameMenu(w, frameWnd->hwndSelf);
935 if((nItems = GetMenuItemCount32(ci->hWindowMenu)) > 0)
937 ci->idFirstChild = nItems - 1;
938 ci->nActiveChildren++; /* to delete a separator */
939 while( ci->nActiveChildren-- )
940 DeleteMenu32(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
942 return 0;
944 case WM_MDIACTIVATE:
945 if( ci->hwndActiveChild != (HWND32)wParam )
946 SetWindowPos32((HWND32)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
947 return 0;
949 case WM_MDICASCADE:
950 return MDICascade(w, ci);
952 case WM_MDICREATE:
953 if (lParam) return MDICreateChild( w, ci, hwnd,
954 (MDICREATESTRUCT32A*)lParam );
955 return 0;
957 case WM_MDIDESTROY:
958 return MDIDestroyChild( w, ci, hwnd, (HWND32)wParam, TRUE );
960 case WM_MDIGETACTIVE:
961 if (lParam) *(BOOL32 *)lParam = (ci->hwndChildMaximized > 0);
962 return ci->hwndActiveChild;
964 case WM_MDIICONARRANGE:
965 ci->mdiFlags |= MDIF_NEEDUPDATE;
966 ArrangeIconicWindows32(hwnd);
967 ci->sbRecalc = SB_BOTH+1;
968 SendMessage32A(hwnd, WM_MDICALCCHILDSCROLL, 0, 0L);
969 return 0;
971 case WM_MDIMAXIMIZE:
972 ShowWindow32( (HWND32)wParam, SW_MAXIMIZE );
973 return 0;
975 case WM_MDINEXT: /* lParam != 0 means previous window */
976 MDI_SwitchActiveChild(hwnd, (HWND32)wParam, (lParam)? FALSE : TRUE );
977 break;
979 case WM_MDIRESTORE:
980 ShowWindow32( (HWND32)wParam, SW_NORMAL);
981 return 0;
983 case WM_MDISETMENU:
984 return MDISetMenu( hwnd, (HMENU32)wParam, (HMENU32)lParam );
986 case WM_MDITILE:
987 ci->mdiFlags |= MDIF_NEEDUPDATE;
988 ShowScrollBar32(hwnd,SB_BOTH,FALSE);
989 MDITile(w, ci, wParam);
990 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
991 return 0;
993 case WM_VSCROLL:
994 case WM_HSCROLL:
995 ci->mdiFlags |= MDIF_NEEDUPDATE;
996 ScrollChildren32(hwnd, message, wParam, lParam);
997 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
998 return 0;
1000 case WM_SETFOCUS:
1001 if( ci->hwndActiveChild )
1003 w = WIN_FindWndPtr( ci->hwndActiveChild );
1004 if( !(w->dwStyle & WS_MINIMIZE) )
1005 SetFocus32( ci->hwndActiveChild );
1007 return 0;
1009 case WM_NCACTIVATE:
1010 if( ci->hwndActiveChild )
1011 SendMessage32A(ci->hwndActiveChild, message, wParam, lParam);
1012 break;
1014 case WM_PARENTNOTIFY:
1015 if (LOWORD(wParam) == WM_LBUTTONDOWN)
1017 POINT16 pt = MAKEPOINT16(lParam);
1018 HWND16 child = ChildWindowFromPoint16(hwnd, pt);
1020 TRACE(mdi,"notification from %04x (%i,%i)\n",child,pt.x,pt.y);
1022 if( child && child != hwnd && child != ci->hwndActiveChild )
1023 SetWindowPos32(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1025 return 0;
1027 case WM_SIZE:
1028 if( ci->hwndChildMaximized )
1030 WND* child = WIN_FindWndPtr(ci->hwndChildMaximized);
1031 RECT32 rect = { 0, 0, LOWORD(lParam), HIWORD(lParam) };
1033 AdjustWindowRectEx32(&rect, child->dwStyle, 0, child->dwExStyle);
1034 MoveWindow32(ci->hwndChildMaximized, rect.left, rect.top,
1035 rect.right - rect.left, rect.bottom - rect.top, 1);
1037 else
1038 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1040 break;
1042 case WM_MDICALCCHILDSCROLL:
1043 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1045 CalcChildScroll(hwnd, ci->sbRecalc-1);
1046 ci->sbRecalc = 0;
1047 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1049 return 0;
1052 return DefWindowProc32A( hwnd, message, wParam, lParam );
1056 /***********************************************************************
1057 * DefFrameProc16 (USER.445)
1059 LRESULT WINAPI DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient,
1060 UINT16 message, WPARAM16 wParam, LPARAM lParam )
1062 HWND16 childHwnd;
1063 MDICLIENTINFO* ci;
1064 WND* wndPtr;
1066 if (hwndMDIClient)
1068 switch (message)
1070 case WM_COMMAND:
1071 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1072 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1074 /* check for possible syscommands for maximized MDI child */
1076 if( ci && (
1077 wParam < ci->idFirstChild ||
1078 wParam >= ci->idFirstChild + ci->nActiveChildren
1080 if( (wParam - 0xF000) & 0xF00F ) break;
1081 switch( wParam )
1083 case SC_SIZE:
1084 case SC_MOVE:
1085 case SC_MINIMIZE:
1086 case SC_MAXIMIZE:
1087 case SC_NEXTWINDOW:
1088 case SC_PREVWINDOW:
1089 case SC_CLOSE:
1090 case SC_RESTORE:
1091 if( ci->hwndChildMaximized )
1092 return SendMessage16( ci->hwndChildMaximized, WM_SYSCOMMAND,
1093 wParam, lParam);
1096 else
1098 childHwnd = MDI_GetChildByID( WIN_FindWndPtr(hwndMDIClient),
1099 wParam );
1100 if( childHwnd )
1101 SendMessage16(hwndMDIClient, WM_MDIACTIVATE,
1102 (WPARAM16)childHwnd , 0L);
1104 break;
1106 case WM_NCACTIVATE:
1107 SendMessage16(hwndMDIClient, message, wParam, lParam);
1108 break;
1110 case WM_SETTEXT:
1111 MDI_UpdateFrameText(WIN_FindWndPtr(hwnd), hwndMDIClient,
1112 MDI_REPAINTFRAME,
1113 (LPCSTR)PTR_SEG_TO_LIN(lParam));
1114 return 0;
1116 case WM_SETFOCUS:
1117 SetFocus32(hwndMDIClient);
1118 break;
1120 case WM_SIZE:
1121 MoveWindow16(hwndMDIClient, 0, 0,
1122 LOWORD(lParam), HIWORD(lParam), TRUE);
1123 break;
1125 case WM_NEXTMENU:
1127 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1128 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1130 if( !(wndPtr->parent->dwStyle & WS_MINIMIZE)
1131 && ci->hwndActiveChild && !ci->hwndChildMaximized )
1133 /* control menu is between the frame system menu and
1134 * the first entry of menu bar */
1136 if( (wParam == VK_LEFT &&
1137 wndPtr->parent->wIDmenu == LOWORD(lParam)) ||
1138 (wParam == VK_RIGHT &&
1139 GetSubMenu16(wndPtr->parent->hSysMenu, 0) == LOWORD(lParam)) )
1141 wndPtr = WIN_FindWndPtr(ci->hwndActiveChild);
1142 return MAKELONG( GetSubMenu16(wndPtr->hSysMenu, 0),
1143 ci->hwndActiveChild);
1146 break;
1150 return DefWindowProc16(hwnd, message, wParam, lParam);
1154 /***********************************************************************
1155 * DefFrameProc32A (USER32.121)
1157 LRESULT WINAPI DefFrameProc32A( HWND32 hwnd, HWND32 hwndMDIClient,
1158 UINT32 message, WPARAM32 wParam, LPARAM lParam)
1160 if (hwndMDIClient)
1162 switch (message)
1164 case WM_COMMAND:
1165 return DefFrameProc16( hwnd, hwndMDIClient, message,
1166 (WPARAM16)wParam,
1167 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1169 case WM_NCACTIVATE:
1170 SendMessage32A(hwndMDIClient, message, wParam, lParam);
1171 break;
1173 case WM_SETTEXT: {
1174 LRESULT ret;
1175 LPSTR segstr = SEGPTR_STRDUP((LPSTR)lParam);
1177 ret = DefFrameProc16(hwnd, hwndMDIClient, message,
1178 wParam, (LPARAM)SEGPTR_GET(segstr) );
1179 SEGPTR_FREE(segstr);
1180 return ret;
1183 case WM_SETFOCUS:
1184 case WM_SIZE:
1185 return DefFrameProc16( hwnd, hwndMDIClient, message,
1186 wParam, lParam );
1190 return DefWindowProc32A(hwnd, message, wParam, lParam);
1194 /***********************************************************************
1195 * DefFrameProc32W (USER32.122)
1197 LRESULT WINAPI DefFrameProc32W( HWND32 hwnd, HWND32 hwndMDIClient,
1198 UINT32 message, WPARAM32 wParam, LPARAM lParam)
1200 if (hwndMDIClient)
1202 switch (message)
1204 case WM_COMMAND:
1205 return DefFrameProc16( hwnd, hwndMDIClient, message,
1206 (WPARAM16)wParam,
1207 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1209 case WM_NCACTIVATE:
1210 SendMessage32W(hwndMDIClient, message, wParam, lParam);
1211 break;
1213 case WM_SETTEXT:
1215 LPSTR txt = HEAP_strdupWtoA(GetProcessHeap(),0,(LPWSTR)lParam);
1216 LRESULT ret = DefFrameProc32A( hwnd, hwndMDIClient, message,
1217 wParam, (DWORD)txt );
1218 HeapFree(GetProcessHeap(),0,txt);
1219 return ret;
1221 case WM_SETFOCUS:
1222 case WM_SIZE:
1223 return DefFrameProc32A( hwnd, hwndMDIClient, message,
1224 wParam, lParam );
1228 return DefWindowProc32W( hwnd, message, wParam, lParam );
1232 /***********************************************************************
1233 * DefMDIChildProc16 (USER.447)
1235 LRESULT WINAPI DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1236 WPARAM16 wParam, LPARAM lParam )
1238 MDICLIENTINFO *ci;
1239 WND *clientWnd;
1241 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1242 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1244 switch (message)
1246 case WM_SETTEXT:
1247 DefWindowProc16(hwnd, message, wParam, lParam);
1248 MDI_MenuModifyItem(clientWnd,hwnd);
1249 if( ci->hwndChildMaximized == hwnd )
1250 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1251 MDI_REPAINTFRAME, NULL );
1252 return 0;
1254 case WM_CLOSE:
1255 SendMessage16(ci->self,WM_MDIDESTROY,(WPARAM16)hwnd,0L);
1256 return 0;
1258 case WM_SETFOCUS:
1259 if( ci->hwndActiveChild != hwnd )
1260 MDI_ChildActivate(clientWnd, hwnd);
1261 break;
1263 case WM_CHILDACTIVATE:
1264 MDI_ChildActivate(clientWnd, hwnd);
1265 return 0;
1267 case WM_NCPAINT:
1268 TRACE(mdi,"WM_NCPAINT for %04x, active %04x\n",
1269 hwnd, ci->hwndActiveChild );
1270 break;
1272 case WM_SYSCOMMAND:
1273 switch( wParam )
1275 case SC_MOVE:
1276 if( ci->hwndChildMaximized == hwnd) return 0;
1277 break;
1278 case SC_RESTORE:
1279 case SC_MINIMIZE:
1280 WIN_FindWndPtr(hwnd)->dwStyle |= WS_SYSMENU;
1281 break;
1282 case SC_MAXIMIZE:
1283 if( ci->hwndChildMaximized == hwnd)
1284 return SendMessage16( clientWnd->parent->hwndSelf,
1285 message, wParam, lParam);
1286 WIN_FindWndPtr(hwnd)->dwStyle &= ~WS_SYSMENU;
1287 break;
1288 case SC_NEXTWINDOW:
1289 SendMessage16( ci->self, WM_MDINEXT, 0, 0);
1290 return 0;
1291 case SC_PREVWINDOW:
1292 SendMessage16( ci->self, WM_MDINEXT, 0, 1);
1293 return 0;
1295 break;
1297 case WM_GETMINMAXINFO:
1298 MDI_ChildGetMinMaxInfo(clientWnd, hwnd, (MINMAXINFO16*) PTR_SEG_TO_LIN(lParam));
1299 return 0;
1301 case WM_SETVISIBLE:
1302 if( ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1303 else
1304 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1305 break;
1307 case WM_SIZE:
1308 /* do not change */
1310 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1312 ci->hwndChildMaximized = 0;
1314 MDI_RestoreFrameMenu( clientWnd->parent, hwnd);
1315 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1316 MDI_REPAINTFRAME, NULL );
1319 if( wParam == SIZE_MAXIMIZED )
1321 HWND16 hMaxChild = ci->hwndChildMaximized;
1323 if( hMaxChild == hwnd ) break;
1325 if( hMaxChild)
1327 SendMessage16( hMaxChild, WM_SETREDRAW, FALSE, 0L );
1329 MDI_RestoreFrameMenu( clientWnd->parent, hMaxChild);
1330 ShowWindow16( hMaxChild, SW_SHOWNOACTIVATE);
1332 SendMessage16( hMaxChild, WM_SETREDRAW, TRUE, 0L );
1335 TRACE(mdi,"maximizing child %04x\n", hwnd );
1337 ci->hwndChildMaximized = hwnd; /* !!! */
1339 MDI_AugmentFrameMenu( ci, clientWnd->parent, hwnd);
1340 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1341 MDI_REPAINTFRAME, NULL );
1344 if( wParam == SIZE_MINIMIZED )
1346 HWND16 switchTo = MDI_GetWindow(clientWnd, hwnd, TRUE, WS_MINIMIZE);
1348 if( switchTo )
1349 SendMessage16( switchTo, WM_CHILDACTIVATE, 0, 0L);
1352 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1353 break;
1355 case WM_MENUCHAR:
1357 /* MDI children don't have menu bars */
1358 PostMessage16( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1359 (WPARAM16)SC_KEYMENU, (LPARAM)wParam);
1360 return 0x00010000L;
1362 case WM_NEXTMENU:
1364 if( wParam == VK_LEFT ) /* switch to frame system menu */
1365 return MAKELONG( GetSubMenu16(clientWnd->parent->hSysMenu, 0),
1366 clientWnd->parent->hwndSelf );
1367 if( wParam == VK_RIGHT ) /* to frame menu bar */
1368 return MAKELONG( clientWnd->parent->wIDmenu,
1369 clientWnd->parent->hwndSelf );
1371 break;
1374 return DefWindowProc16(hwnd, message, wParam, lParam);
1378 /***********************************************************************
1379 * DefMDIChildProc32A (USER32.123)
1381 LRESULT WINAPI DefMDIChildProc32A( HWND32 hwnd, UINT32 message,
1382 WPARAM32 wParam, LPARAM lParam )
1384 MDICLIENTINFO *ci;
1385 WND *clientWnd;
1387 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1388 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1390 switch (message)
1392 case WM_SETTEXT:
1393 DefWindowProc32A(hwnd, message, wParam, lParam);
1394 MDI_MenuModifyItem(clientWnd,hwnd);
1395 if( ci->hwndChildMaximized == hwnd )
1396 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1397 MDI_REPAINTFRAME, NULL );
1398 return 0;
1400 case WM_GETMINMAXINFO:
1402 MINMAXINFO16 mmi;
1403 STRUCT32_MINMAXINFO32to16( (MINMAXINFO32 *)lParam, &mmi );
1404 MDI_ChildGetMinMaxInfo( clientWnd, hwnd, &mmi );
1405 STRUCT32_MINMAXINFO16to32( &mmi, (MINMAXINFO32 *)lParam );
1407 return 0;
1409 case WM_MENUCHAR:
1411 /* MDI children don't have menu bars */
1412 PostMessage16( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1413 (WPARAM16)SC_KEYMENU, (LPARAM)LOWORD(wParam) );
1414 return 0x00010000L;
1416 case WM_CLOSE:
1417 case WM_SETFOCUS:
1418 case WM_CHILDACTIVATE:
1419 case WM_NCPAINT:
1420 case WM_SYSCOMMAND:
1421 case WM_SETVISIBLE:
1422 case WM_SIZE:
1423 case WM_NEXTMENU:
1424 return DefMDIChildProc16( hwnd, message, (WPARAM16)wParam, lParam );
1426 return DefWindowProc32A(hwnd, message, wParam, lParam);
1430 /***********************************************************************
1431 * DefMDIChildProc32W (USER32.124)
1433 LRESULT WINAPI DefMDIChildProc32W( HWND32 hwnd, UINT32 message,
1434 WPARAM32 wParam, LPARAM lParam )
1436 MDICLIENTINFO *ci;
1437 WND *clientWnd;
1439 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1440 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1442 switch (message)
1444 case WM_SETTEXT:
1445 DefWindowProc32W(hwnd, message, wParam, lParam);
1446 MDI_MenuModifyItem(clientWnd,hwnd);
1447 if( ci->hwndChildMaximized == hwnd )
1448 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1449 MDI_REPAINTFRAME, NULL );
1450 return 0;
1452 case WM_GETMINMAXINFO:
1453 case WM_MENUCHAR:
1454 case WM_CLOSE:
1455 case WM_SETFOCUS:
1456 case WM_CHILDACTIVATE:
1457 case WM_NCPAINT:
1458 case WM_SYSCOMMAND:
1459 case WM_SETVISIBLE:
1460 case WM_SIZE:
1461 case WM_NEXTMENU:
1462 return DefMDIChildProc32A( hwnd, message, (WPARAM16)wParam, lParam );
1464 return DefWindowProc32W(hwnd, message, wParam, lParam);
1468 /**********************************************************************
1469 * CreateMDIWindowA (USER32.78)
1472 /**********************************************************************
1473 * CreateMDIWindowW (USER32.79)
1476 /**********************************************************************
1477 * TranslateMDISysAccel32 (USER32.554)
1479 BOOL32 WINAPI TranslateMDISysAccel32( HWND32 hwndClient, LPMSG32 msg )
1481 MSG16 msg16;
1483 STRUCT32_MSG32to16(msg,&msg16);
1484 /* MDICLIENTINFO is still the same for win32 and win16 ... */
1485 return TranslateMDISysAccel16(hwndClient,&msg16);
1489 /**********************************************************************
1490 * TranslateMDISysAccel16 (USER.451)
1492 BOOL16 WINAPI TranslateMDISysAccel16( HWND16 hwndClient, LPMSG16 msg )
1494 WND* clientWnd = WIN_FindWndPtr( hwndClient);
1496 if( clientWnd && (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN))
1498 MDICLIENTINFO *ci = NULL;
1499 WND* wnd;
1501 ci = (MDICLIENTINFO*) clientWnd->wExtra;
1502 wnd = WIN_FindWndPtr(ci->hwndActiveChild);
1503 if( wnd && !(wnd->dwStyle & WS_DISABLED) )
1505 WPARAM16 wParam = 0;
1507 /* translate if the Ctrl key is down and Alt not. */
1509 if( (GetKeyState32(VK_CONTROL) & 0x8000) &&
1510 !(GetKeyState32(VK_MENU) & 0x8000))
1512 switch( msg->wParam )
1514 case VK_F6:
1515 case VK_TAB:
1516 wParam = ( GetKeyState32(VK_SHIFT) & 0x8000 )
1517 ? SC_NEXTWINDOW : SC_PREVWINDOW;
1518 break;
1519 case VK_F4:
1520 case VK_RBUTTON:
1521 wParam = SC_CLOSE;
1522 break;
1523 default:
1524 return 0;
1526 TRACE(mdi,"wParam = %04x\n", wParam);
1527 SendMessage16( ci->hwndActiveChild, WM_SYSCOMMAND,
1528 wParam, (LPARAM)msg->wParam);
1529 return 1;
1533 return 0; /* failure */
1537 /***********************************************************************
1538 * CalcChildScroll (USER.462)
1540 void WINAPI CalcChildScroll( HWND16 hwnd, WORD scroll )
1542 RECT32 childRect, clientRect;
1543 INT32 vmin, vmax, hmin, hmax, vpos, hpos;
1544 BOOL32 noscroll = FALSE;
1545 WND *pWnd, *Wnd;
1547 if (!(Wnd = pWnd = WIN_FindWndPtr( hwnd ))) return;
1548 GetClientRect32( hwnd, &clientRect );
1549 SetRectEmpty32( &childRect );
1551 for ( pWnd = pWnd->child; pWnd; pWnd = pWnd->next )
1553 UnionRect32( &childRect, &pWnd->rectWindow, &childRect );
1554 if( pWnd->dwStyle & WS_MAXIMIZE )
1555 noscroll = TRUE;
1557 UnionRect32( &childRect, &clientRect, &childRect );
1559 /* jump through the hoops to prevent excessive flashing
1562 hmin = childRect.left; hmax = childRect.right - clientRect.right;
1563 hpos = clientRect.left - childRect.left;
1564 vmin = childRect.top; vmax = childRect.bottom - clientRect.bottom;
1565 vpos = clientRect.top - childRect.top;
1567 if( noscroll )
1568 ShowScrollBar32(hwnd, SB_BOTH, FALSE);
1569 else
1570 switch( scroll )
1572 case SB_HORZ:
1573 vpos = hpos; vmin = hmin; vmax = hmax;
1574 case SB_VERT:
1575 SetScrollPos32(hwnd, scroll, vpos, FALSE);
1576 SetScrollRange32(hwnd, scroll, vmin, vmax, TRUE);
1577 break;
1578 case SB_BOTH:
1579 SCROLL_SetNCSbState( Wnd, vmin, vmax, vpos,
1580 hmin, hmax, hpos);
1581 SetWindowPos32(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1582 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1587 /***********************************************************************
1588 * ScrollChildren16 (USER.463)
1590 void WINAPI ScrollChildren16(HWND16 hWnd, UINT16 uMsg, WPARAM16 wParam, LPARAM lParam)
1592 return ScrollChildren32( hWnd, uMsg, wParam, lParam );
1596 /***********************************************************************
1597 * ScrollChildren32 (USER32.447)
1599 void WINAPI ScrollChildren32(HWND32 hWnd, UINT32 uMsg, WPARAM32 wParam,
1600 LPARAM lParam)
1602 WND *wndPtr = WIN_FindWndPtr(hWnd);
1603 INT32 newPos = -1;
1604 INT32 curPos, length, minPos, maxPos, shift;
1606 if( !wndPtr ) return;
1608 if( uMsg == WM_HSCROLL )
1610 GetScrollRange32(hWnd,SB_HORZ,&minPos,&maxPos);
1611 curPos = GetScrollPos32(hWnd,SB_HORZ);
1612 length = (wndPtr->rectClient.right - wndPtr->rectClient.left)/2;
1613 shift = SYSMETRICS_CYHSCROLL;
1615 else if( uMsg == WM_VSCROLL )
1617 GetScrollRange32(hWnd,SB_VERT,&minPos,&maxPos);
1618 curPos = GetScrollPos32(hWnd,SB_VERT);
1619 length = (wndPtr->rectClient.bottom - wndPtr->rectClient.top)/2;
1620 shift = SYSMETRICS_CXVSCROLL;
1622 else return;
1624 switch( wParam )
1626 case SB_LINEUP:
1627 newPos = curPos - shift;
1628 break;
1629 case SB_LINEDOWN:
1630 newPos = curPos + shift;
1631 break;
1632 case SB_PAGEUP:
1633 newPos = curPos - length;
1634 break;
1635 case SB_PAGEDOWN:
1636 newPos = curPos + length;
1637 break;
1639 case SB_THUMBPOSITION:
1640 newPos = LOWORD(lParam);
1641 break;
1643 case SB_THUMBTRACK:
1644 return;
1646 case SB_TOP:
1647 newPos = minPos;
1648 break;
1649 case SB_BOTTOM:
1650 newPos = maxPos;
1651 break;
1652 case SB_ENDSCROLL:
1653 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
1654 return;
1657 if( newPos > maxPos )
1658 newPos = maxPos;
1659 else
1660 if( newPos < minPos )
1661 newPos = minPos;
1663 SetScrollPos32(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
1665 if( uMsg == WM_VSCROLL )
1666 ScrollWindowEx32(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
1667 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
1668 else
1669 ScrollWindowEx32(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
1670 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );