Release 960717
[wine/multimedia.git] / windows / mdi.c
blob5f536919adcc761ae3ee9a51d3d60afa49a322c3
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 "xmalloc.h"
20 #include "windows.h"
21 #include "win.h"
22 #include "heap.h"
23 #include "nonclient.h"
24 #include "mdi.h"
25 #include "user.h"
26 #include "menu.h"
27 #include "resource.h"
28 #include "stackframe.h"
29 #include "struct32.h"
30 #include "sysmetrics.h"
31 #include "stddebug.h"
32 #include "debug.h"
35 static HBITMAP hBmpClose = 0;
36 static HBITMAP hBmpRestore = 0;
38 DWORD SCROLL_SetNCSbState(WND*,int,int,int,int,int,int);
40 /* ----------------- declarations ----------------- */
41 void MDI_UpdateFrameText(WND *, HWND, BOOL, LPCSTR);
42 BOOL MDI_AugmentFrameMenu(MDICLIENTINFO*, WND *, HWND);
43 BOOL MDI_RestoreFrameMenu(WND *, HWND);
45 void ScrollChildren(HWND , UINT , WPARAM , LPARAM );
46 void CalcChildScroll(HWND, WORD);
48 static LONG MDI_ChildActivate(WND* ,HWND );
50 /* -------- Miscellaneous service functions ----------
52 * MDI_GetChildByID
55 static HWND MDI_GetChildByID(WND* wndPtr,int id)
57 for (wndPtr = wndPtr->child; wndPtr; wndPtr = wndPtr->next)
58 if (wndPtr->wIDmenu == id) return wndPtr->hwndSelf;
59 return 0;
62 static void MDI_PostUpdate(HWND hwnd, MDICLIENTINFO* ci, WORD recalc)
64 if( !ci->sbNeedUpdate )
66 ci->sbNeedUpdate = TRUE;
67 PostMessage( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
69 ci->sbRecalc = recalc;
72 /**********************************************************************
73 * MDI_MenuAppendItem
75 #ifdef SUPERFLUOUS_FUNCTIONS
76 static BOOL MDI_MenuAppendItem(WND *clientWnd, HWND hWndChild)
78 char buffer[128];
79 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
80 WND *wndPtr = WIN_FindWndPtr(hWndChild);
81 int n = sprintf(buffer, "%d ",
82 clientInfo->nActiveChildren);
84 if( !clientInfo->hWindowMenu ) return 0;
86 if (wndPtr->text) strncpy(buffer + n, wndPtr->text, sizeof(buffer) - n - 1);
87 return AppendMenu32A( clientInfo->hWindowMenu, MF_STRING,
88 wndPtr->wIDmenu, buffer );
90 #endif
92 /**********************************************************************
93 * MDI_MenuModifyItem
95 static BOOL MDI_MenuModifyItem(WND* clientWnd, HWND hWndChild )
97 char buffer[128];
98 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
99 WND *wndPtr = WIN_FindWndPtr(hWndChild);
100 UINT n = sprintf(buffer, "%d ",
101 wndPtr->wIDmenu - clientInfo->idFirstChild + 1);
102 BOOL bRet = 0;
104 if( !clientInfo->hWindowMenu ) return 0;
106 if (wndPtr->text) lstrcpyn32A(buffer + n, wndPtr->text, sizeof(buffer) - n );
108 n = GetMenuState(clientInfo->hWindowMenu,wndPtr->wIDmenu ,MF_BYCOMMAND);
109 bRet = ModifyMenu32A(clientInfo->hWindowMenu , wndPtr->wIDmenu,
110 MF_BYCOMMAND | MF_STRING, wndPtr->wIDmenu, buffer );
111 CheckMenuItem(clientInfo->hWindowMenu ,wndPtr->wIDmenu , n & MF_CHECKED);
112 return bRet;
115 /**********************************************************************
116 * MDI_MenuDeleteItem
118 static BOOL MDI_MenuDeleteItem(WND* clientWnd, HWND hWndChild )
120 char buffer[128];
121 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
122 WND *wndPtr = WIN_FindWndPtr(hWndChild);
123 UINT index = 0,id,n;
125 if( !clientInfo->nActiveChildren ||
126 !clientInfo->hWindowMenu ) return 0;
128 id = wndPtr->wIDmenu;
129 DeleteMenu(clientInfo->hWindowMenu,id,MF_BYCOMMAND);
131 /* walk the rest of MDI children to prevent gaps in the id
132 * sequence and in the menu child list
135 for( index = id+1; index <= clientInfo->nActiveChildren +
136 clientInfo->idFirstChild; index++ )
138 wndPtr = WIN_FindWndPtr(MDI_GetChildByID(clientWnd,index));
139 if( !wndPtr )
141 dprintf_mdi(stddeb,"MDIMenuDeleteItem: no window for id=%i\n",index);
142 continue;
145 /* set correct id */
146 wndPtr->wIDmenu--;
148 n = sprintf(buffer, "%d ",index - clientInfo->idFirstChild);
149 if (wndPtr->text)
150 lstrcpyn32A(buffer + n, wndPtr->text, sizeof(buffer) - n );
152 /* change menu */
153 ModifyMenu32A(clientInfo->hWindowMenu ,index ,MF_BYCOMMAND | MF_STRING,
154 index - 1 , buffer );
156 return 1;
159 /**********************************************************************
160 * MDI_GetWindow
162 * returns "activateable" child or zero
164 HWND MDI_GetWindow(WND *clientWnd, HWND hWnd, WORD wTo )
166 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
167 WND *wndPtr, *pWnd, *pWndLast;
169 if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
171 if( !(wndPtr = WIN_FindWndPtr(hWnd)) ) return 0;
173 pWnd = wndPtr;
174 pWndLast = NULL;
175 for (;;)
177 pWnd = pWnd->next;
178 if (!pWnd) pWnd = wndPtr->parent->child;
179 if (pWnd == wndPtr) /* not found */
181 if (!wTo || !pWndLast) return 0;
182 break;
185 /* we are not interested in owned popups */
186 if ( !pWnd->owner &&
187 (pWnd->dwStyle & WS_VISIBLE) &&
188 !(pWnd->dwStyle & WS_DISABLED)) /* found one */
190 pWndLast = pWnd;
191 if (!wTo) break;
194 return pWndLast ? pWndLast->hwndSelf : 0;
197 /**********************************************************************
198 * MDI_CalcDefaultChildPos
200 * It seems that default height is 2/3 of client rect
202 void MDI_CalcDefaultChildPos(WND* w, WORD n, LPPOINT16 lpPos, INT delta)
204 RECT16 rect = w->rectClient;
205 INT spacing = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME) - 1;
206 INT nstagger;
208 if( rect.bottom - rect.top - delta >= spacing )
209 rect.bottom -= delta;
211 nstagger = (rect.bottom - rect.top)/(3*spacing);
212 lpPos[1].x = (rect.right - rect.left - nstagger*spacing);
213 lpPos[1].y = (rect.bottom - rect.top - nstagger*spacing);
214 lpPos[0].x = lpPos[0].y = spacing*(n%(nstagger+1));
217 /**********************************************************************
218 * MDISetMenu
220 HMENU MDISetMenu(HWND hwnd, BOOL fRefresh, HMENU hmenuFrame, HMENU hmenuWindow)
222 WND *w = WIN_FindWndPtr(hwnd);
223 MDICLIENTINFO *ci;
225 dprintf_mdi(stddeb, "WM_MDISETMENU: %04x %04x %04x %04x\n",
226 hwnd, fRefresh, hmenuFrame, hmenuWindow);
228 ci = (MDICLIENTINFO *) w->wExtra;
230 if (!fRefresh)
232 HWND hwndFrame = GetParent(hwnd);
233 HMENU oldFrameMenu = GetMenu(hwndFrame);
235 if( ci->hwndChildMaximized && hmenuFrame && hmenuFrame!=oldFrameMenu )
236 MDI_RestoreFrameMenu(w->parent, ci->hwndChildMaximized );
238 if( hmenuWindow && hmenuWindow!=ci->hWindowMenu )
240 /* delete menu items from ci->hWindowMenu
241 * and add them to hmenuWindow */
243 INT i = GetMenuItemCount(ci->hWindowMenu) - 1;
244 INT pos = GetMenuItemCount(hmenuWindow) + 1;
246 AppendMenu32A( hmenuWindow, MF_SEPARATOR, 0, NULL);
248 if( ci->nActiveChildren )
250 INT j = i - ci->nActiveChildren + 1;
251 char buffer[100];
252 UINT id,state;
254 for( ; i >= j ; i-- )
256 id = GetMenuItemID(ci->hWindowMenu,i );
257 state = GetMenuState(ci->hWindowMenu,i,MF_BYPOSITION);
259 GetMenuString(ci->hWindowMenu, i, buffer, 100, MF_BYPOSITION);
261 DeleteMenu(ci->hWindowMenu, i , MF_BYPOSITION);
262 InsertMenu32A(hmenuWindow, pos, MF_BYPOSITION | MF_STRING,
263 id, buffer);
264 CheckMenuItem(hmenuWindow ,pos , MF_BYPOSITION | (state & MF_CHECKED));
268 /* remove separator */
269 DeleteMenu(ci->hWindowMenu, i, MF_BYPOSITION);
271 ci->hWindowMenu = hmenuWindow;
274 if( hmenuFrame && hmenuFrame!=oldFrameMenu)
276 SetMenu(hwndFrame, hmenuFrame);
277 if( ci->hwndChildMaximized )
278 MDI_AugmentFrameMenu(ci, w->parent, ci->hwndChildMaximized );
279 return oldFrameMenu;
283 return 0;
286 /**********************************************************************
287 * MDIIconArrange
289 WORD MDIIconArrange(HWND parent)
291 return ArrangeIconicWindows(parent); /* Any reason why the */
292 /* existing icon arrange */
293 /* can't be used here? */
294 /* -DRP */
298 /* ------------------ MDI child window functions ---------------------- */
301 /**********************************************************************
302 * MDICreateChild
304 HWND MDICreateChild(WND *w, MDICLIENTINFO *ci, HWND parent, LPARAM lParam )
306 POINT16 pos[2];
307 MDICREATESTRUCT16 *cs = (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam);
308 DWORD style = cs->style | (WS_CHILD | WS_CLIPSIBLINGS);
309 HWND hwnd, hwndMax = 0;
310 WORD wIDmenu = ci->idFirstChild + ci->nActiveChildren;
311 char lpstrDef[]="junk!";
314 * Create child window
318 dprintf_mdi(stdnimp,"MDICreateChild: origin %i,%i - dim %i,%i, style %08x\n",
319 cs->x, cs->y, cs->cx, cs->cy, (unsigned)cs->style);
320 /* calculate placement */
321 MDI_CalcDefaultChildPos(w, ci->nTotalCreated++, pos, 0);
323 if( cs->cx == CW_USEDEFAULT16 || !cs->cx )
324 cs->cx = pos[1].x;
325 if( cs->cy == CW_USEDEFAULT16 || !cs->cy )
326 cs->cy = pos[1].y;
328 if( cs->x == CW_USEDEFAULT16 )
330 cs->x = pos[0].x;
331 cs->y = pos[0].y;
334 /* restore current maximized child */
335 if( style & WS_VISIBLE && ci->hwndChildMaximized )
337 if( style & WS_MAXIMIZE )
338 SendMessage16(w->hwndSelf, WM_SETREDRAW, FALSE, 0L );
339 hwndMax = ci->hwndChildMaximized;
340 ShowWindow( hwndMax, SW_SHOWNOACTIVATE );
341 if( style & WS_MAXIMIZE )
342 SendMessage16(w->hwndSelf, WM_SETREDRAW, TRUE, 0L );
345 /* this menu is needed to set a check mark in MDI_ChildActivate */
346 AppendMenu32A(ci->hWindowMenu ,MF_STRING ,wIDmenu, lpstrDef );
348 ci->nActiveChildren++;
350 /* fix window style */
351 if( !(w->dwStyle & MDIS_ALLCHILDSTYLES) )
353 style &= (WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZE | WS_MAXIMIZE |
354 WS_CLIPCHILDREN | WS_DISABLED | WS_VSCROLL | WS_HSCROLL );
355 style |= (WS_VISIBLE | WS_OVERLAPPEDWINDOW);
358 hwnd = CreateWindow16( (LPCSTR)PTR_SEG_TO_LIN(cs->szClass),
359 (LPCSTR)PTR_SEG_TO_LIN(cs->szTitle), style,
360 cs->x, cs->y, cs->cx, cs->cy, parent,
361 (HMENU)(DWORD)(WORD)wIDmenu, w->hInstance,
362 (LPVOID)lParam);
364 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
366 if (hwnd)
368 WND* wnd = WIN_FindWndPtr( hwnd );
370 MDI_MenuModifyItem(w ,hwnd);
371 if( wnd->dwStyle & WS_MINIMIZE && ci->hwndActiveChild )
372 ShowWindow( hwnd, SW_SHOWMINNOACTIVE );
373 else
375 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE );
376 if( wnd->dwStyle & WS_MAXIMIZE )
378 MDI_AugmentFrameMenu( ci, w->parent, hwnd );
379 MDI_UpdateFrameText( w->parent, ci->self, MDI_REPAINTFRAME, NULL );
382 dprintf_mdi(stddeb, "MDICreateChild: created child - %04x\n",hwnd);
384 else
386 ci->nActiveChildren--;
387 DeleteMenu(ci->hWindowMenu,wIDmenu,MF_BYCOMMAND);
388 if( IsWindow(hwndMax) )
389 ShowWindow(hwndMax, SW_SHOWMAXIMIZED);
392 return hwnd;
395 /**********************************************************************
396 * MDI_ChildGetMinMaxInfo
398 void MDI_ChildGetMinMaxInfo(WND* clientWnd, HWND hwnd, MINMAXINFO16* lpMinMax )
400 WND* childWnd = WIN_FindWndPtr(hwnd);
401 RECT16 rect = clientWnd->rectClient;
403 MapWindowPoints16(clientWnd->parent->hwndSelf,
404 ((MDICLIENTINFO*)clientWnd->wExtra)->self, (LPPOINT16)&rect, 2);
405 AdjustWindowRectEx16( &rect, childWnd->dwStyle, 0, childWnd->dwExStyle );
407 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
408 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
410 lpMinMax->ptMaxPosition.x = rect.left;
411 lpMinMax->ptMaxPosition.y = rect.top;
414 /**********************************************************************
415 * MDI_SwitchActiveChild
417 * Notes: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
418 * being activated
420 * wTo is basically lParam of WM_MDINEXT message or explicit
421 * window handle
423 void MDI_SwitchActiveChild(HWND clientHwnd, HWND childHwnd, BOOL wTo )
425 WND *w = WIN_FindWndPtr(clientHwnd);
426 HWND hwndTo = 0;
427 HWND hwndPrev = 0;
428 MDICLIENTINFO *ci;
430 hwndTo = MDI_GetWindow(w,childHwnd,(WORD)wTo);
432 ci = (MDICLIENTINFO *) w->wExtra;
434 dprintf_mdi(stddeb, "MDI_SwitchActiveChild: from %04x, to %04x\n",childHwnd,hwndTo);
436 if ( !hwndTo ) return;
438 hwndPrev = ci->hwndActiveChild;
440 if ( hwndTo != hwndPrev )
442 BOOL bOptimize = 0;
444 if( ci->hwndChildMaximized )
446 bOptimize = 1;
447 w->dwStyle &= ~WS_VISIBLE;
450 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0,
451 SWP_NOMOVE | SWP_NOSIZE );
452 if( !wTo && hwndPrev )
454 SetWindowPos( hwndPrev, HWND_BOTTOM, 0, 0, 0, 0,
455 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
458 if( bOptimize )
459 ShowWindow( clientHwnd, SW_SHOW );
464 /**********************************************************************
465 * MDIDestroyChild
467 HWND MDIDestroyChild(WND *w_parent, MDICLIENTINFO *ci, HWND parent,
468 HWND child, BOOL flagDestroy)
470 WND *childPtr = WIN_FindWndPtr(child);
472 if( childPtr )
474 if( child == ci->hwndActiveChild )
476 MDI_SwitchActiveChild(parent,child,0);
478 if( child == ci->hwndActiveChild )
480 ShowWindow( child, SW_HIDE);
481 if( child == ci->hwndChildMaximized )
483 MDI_RestoreFrameMenu(w_parent->parent, child);
484 ci->hwndChildMaximized = 0;
485 MDI_UpdateFrameText(w_parent->parent,parent,TRUE,NULL);
488 MDI_ChildActivate(w_parent,0);
490 MDI_MenuDeleteItem(w_parent, child);
493 ci->nActiveChildren--;
495 dprintf_mdi(stddeb,"MDIDestroyChild: child destroyed - %04x\n",child);
497 if (flagDestroy)
499 MDI_PostUpdate(GetParent(child), ci, SB_BOTH+1);
500 DestroyWindow(child);
504 return 0;
508 /**********************************************************************
509 * MDI_ChildActivate
511 * Note: hWndChild is NULL when last child is being destroyed
513 LONG MDI_ChildActivate(WND *clientPtr, HWND hWndChild)
515 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientPtr->wExtra;
516 HWND prevActiveWnd = clientInfo->hwndActiveChild;
517 WND *wndPtr = WIN_FindWndPtr( hWndChild );
518 WND *wndPrev = WIN_FindWndPtr( prevActiveWnd );
519 BOOL isActiveFrameWnd = 0;
521 if( hWndChild == prevActiveWnd ) return 0L;
523 if( wndPtr )
524 if( wndPtr->dwStyle & WS_DISABLED ) return 0L;
526 dprintf_mdi(stddeb,"MDI_ChildActivate: %04x\n", hWndChild);
528 if( GetActiveWindow() == clientPtr->parent->hwndSelf )
529 isActiveFrameWnd = TRUE;
531 /* deactivate prev. active child */
532 if( wndPrev )
534 SendMessage16( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
536 #ifdef WINELIB32
537 SendMessage32A( prevActiveWnd, WM_MDIACTIVATE, (WPARAM)prevActiveWnd,
538 (LPARAM)hWndChild);
539 #else
541 SendMessage16( prevActiveWnd, WM_MDIACTIVATE, FALSE,
542 MAKELONG(hWndChild,prevActiveWnd));
543 #endif
544 /* uncheck menu item */
545 if( clientInfo->hWindowMenu )
546 CheckMenuItem( clientInfo->hWindowMenu,
547 wndPrev->wIDmenu, 0);
550 /* set appearance */
551 if( clientInfo->hwndChildMaximized )
552 if( clientInfo->hwndChildMaximized != hWndChild )
553 if( hWndChild )
555 clientInfo->hwndActiveChild = hWndChild;
556 ShowWindow( hWndChild, SW_SHOWMAXIMIZED);
558 else
559 ShowWindow( clientInfo->hwndActiveChild,
560 SW_SHOWNORMAL );
562 clientInfo->hwndActiveChild = hWndChild;
564 /* check if we have any children left */
565 if( !hWndChild )
567 if( isActiveFrameWnd )
568 SetFocus( clientInfo->self );
569 return 0;
572 /* check menu item */
573 if( clientInfo->hWindowMenu )
574 CheckMenuItem( clientInfo->hWindowMenu,
575 wndPtr->wIDmenu, MF_CHECKED);
577 /* bring active child to the top */
578 SetWindowPos( hWndChild, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
580 if( isActiveFrameWnd )
582 SendMessage16( hWndChild, WM_NCACTIVATE, TRUE, 0L);
583 if( GetFocus() == clientInfo->self )
584 SendMessage16( clientInfo->self, WM_SETFOCUS,
585 (WPARAM)clientInfo->self, 0L );
586 else
587 SetFocus( clientInfo->self );
590 #ifdef WINELIB32
591 SendMessage32A( hWndChild, WM_MDIACTIVATE, (WPARAM)hWndChild,
592 (LPARAM)prevActiveWnd );
593 #else
594 SendMessage16( hWndChild, WM_MDIACTIVATE, TRUE,
595 MAKELONG(hWndChild,prevActiveWnd));
596 #endif
598 return 1;
601 /**********************************************************************
602 * MDI_BuildWCL
604 * iTotal returns number of children available for tiling or cascading
606 MDIWCL* MDI_BuildWCL(WND* clientWnd, INT16* iTotal)
608 MDIWCL *listTop,*listNext;
609 WND *childWnd;
611 if (!(listTop = (MDIWCL*)malloc( sizeof(MDIWCL) ))) return NULL;
613 listTop->hChild = clientWnd->child ? clientWnd->child->hwndSelf : 0;
614 listTop->prev = NULL;
615 *iTotal = 1;
617 /* build linked list from top child to bottom */
619 childWnd = WIN_FindWndPtr( listTop->hChild );
620 while( childWnd && childWnd->next )
622 listNext = (MDIWCL*)xmalloc(sizeof(MDIWCL));
624 if( (childWnd->dwStyle & WS_DISABLED) ||
625 (childWnd->dwStyle & WS_MINIMIZE) ||
626 !(childWnd->dwStyle & WS_VISIBLE) )
628 listTop->hChild = 0;
629 (*iTotal)--;
632 listNext->hChild = childWnd->next->hwndSelf;
633 listNext->prev = listTop;
634 listTop = listNext;
635 (*iTotal)++;
637 childWnd = childWnd->next;
640 if( (childWnd->dwStyle & WS_DISABLED) ||
641 (childWnd->dwStyle & WS_MINIMIZE) ||
642 !(childWnd->dwStyle & WS_VISIBLE) )
644 listTop->hChild = 0;
645 (*iTotal)--;
648 return listTop;
652 /* -------------------- MDI client window functions ------------------- */
654 /**********************************************************************
655 * CreateMDIMenuBitmap
657 HBITMAP CreateMDIMenuBitmap(void)
659 HDC hDCSrc = CreateCompatibleDC(0);
660 HDC hDCDest = CreateCompatibleDC(hDCSrc);
661 HBITMAP16 hbClose = LoadBitmap16(0, MAKEINTRESOURCE(OBM_CLOSE) );
662 HBITMAP16 hbCopy,hb_src,hb_dest;
664 hb_src = SelectObject(hDCSrc,hbClose);
665 hbCopy = CreateCompatibleBitmap(hDCSrc,SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE);
666 hb_dest = SelectObject(hDCDest,hbCopy);
668 BitBlt(hDCDest, 0, 0, SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE,
669 hDCSrc, SYSMETRICS_CXSIZE, 0, SRCCOPY);
671 SelectObject(hDCSrc,hb_src);
672 SelectObject(hDCDest,hb_dest);
674 DeleteObject(hbClose);
676 DeleteDC(hDCDest);
677 DeleteDC(hDCSrc);
679 return hbCopy;
682 /**********************************************************************
683 * MDICascade
685 LONG MDICascade(WND* clientWnd, MDICLIENTINFO *ci)
687 MDIWCL *listTop,*listPrev;
688 INT16 delta = 0,iToPosition = 0, n = 0;
689 POINT16 pos[2];
691 if (ci->hwndChildMaximized)
692 ShowWindow( ci->hwndChildMaximized, SW_NORMAL);
694 if (ci->nActiveChildren == 0) return 0;
696 if (!(listTop = MDI_BuildWCL(clientWnd,&iToPosition))) return 0;
698 if( iToPosition < ci->nActiveChildren )
699 delta = 2 * SYSMETRICS_CYICONSPACING + SYSMETRICS_CYICON;
701 /* walk list and move windows */
702 while ( listTop )
704 dprintf_mdi(stddeb, "MDICascade: move %04x to (%d,%d) size [%d,%d]\n",
705 listTop->hChild, pos[0].x, pos[0].y, pos[1].x, pos[1].y);
707 if( listTop->hChild )
709 MDI_CalcDefaultChildPos(clientWnd, n++, pos, delta);
710 SetWindowPos(listTop->hChild, 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
711 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
714 listPrev = listTop->prev;
715 free(listTop);
716 listTop = listPrev;
719 if( iToPosition < ci->nActiveChildren )
720 ArrangeIconicWindows( clientWnd->hwndSelf );
722 return 0;
725 /**********************************************************************
726 * MDITile
729 LONG MDITile(WND* wndClient, MDICLIENTINFO *ci,WORD wParam)
731 MDIWCL *listTop,*listPrev;
732 RECT16 rect;
733 int xsize, ysize;
734 int x, y;
735 int rows, columns;
736 int r, c;
737 int i;
738 INT16 iToPosition = 0;
740 if (ci->hwndChildMaximized)
741 ShowWindow(ci->hwndChildMaximized, SW_NORMAL);
743 if (ci->nActiveChildren == 0) return 0;
745 listTop = MDI_BuildWCL(wndClient, &iToPosition);
747 dprintf_mdi(stddeb,"MDITile: %i windows to tile\n",iToPosition);
749 if( !listTop ) return 0;
751 /* tile children */
752 if ( iToPosition )
754 rect = wndClient->rectClient;
755 rows = (int) sqrt((double) iToPosition);
756 columns = iToPosition / rows;
758 if (wParam == MDITILE_HORIZONTAL) /* version >= 3.1 */
760 i=rows;
761 rows=columns; /* exchange r and c */
762 columns=i;
765 /* hack */
766 if( iToPosition != ci->nActiveChildren)
768 y = rect.bottom - 2 * SYSMETRICS_CYICONSPACING - SYSMETRICS_CYICON;
769 rect.bottom = ( y - SYSMETRICS_CYICON < rect.top )? rect.bottom: y;
772 ysize = rect.bottom / rows;
773 xsize = rect.right / columns;
775 x = 0;
776 i = 0;
778 for (c = 1; c <= columns; c++)
780 if (c == columns)
782 rows = iToPosition - i;
783 ysize = rect.bottom / rows;
786 y = 0;
787 for (r = 1; r <= rows; r++, i++)
789 /* shouldn't happen but... */
790 if( !listTop )
791 break;
793 /* skip iconized childs from tiling */
794 while (!listTop->hChild)
796 listPrev = listTop->prev;
797 free(listTop);
798 listTop = listPrev;
800 SetWindowPos(listTop->hChild, 0, x, y, xsize, ysize,
801 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
802 y += ysize;
803 listPrev = listTop->prev;
804 free(listTop);
805 listTop = listPrev;
807 x += xsize;
811 /* free the rest if any */
812 while( listTop )
814 listPrev = listTop->prev;
815 free(listTop);
816 listTop = listPrev;
819 if (iToPosition < ci->nActiveChildren )
820 ArrangeIconicWindows( wndClient->hwndSelf );
822 return 0;
825 /* ----------------------- Frame window ---------------------------- */
828 /**********************************************************************
829 * MDI_AugmentFrameMenu
831 BOOL MDI_AugmentFrameMenu(MDICLIENTINFO* ci, WND *frame, HWND hChild)
833 WND* child = WIN_FindWndPtr(hChild);
834 HGLOBAL handle;
835 HMENU hSysPopup = 0;
837 dprintf_mdi(stddeb,"MDI_AugmentFrameMenu: frame %p,child %04x\n",frame,hChild);
839 if( !frame->wIDmenu || !child->hSysMenu ) return 0;
841 /* create a copy of sysmenu popup and insert it into frame menu bar */
843 if (!(handle = SYSRES_LoadResource( SYSRES_MENU_SYSMENU ))) return 0;
844 hSysPopup = LoadMenuIndirect16( GlobalLock16( handle ) );
845 SYSRES_FreeResource( handle );
847 dprintf_mdi(stddeb,"\t\tgot popup %04x\n in sysmenu %04x",hSysPopup,child->hSysMenu);
849 if( !InsertMenu32A(frame->wIDmenu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
850 hSysPopup, (LPSTR)(DWORD)hBmpClose ))
851 { DestroyMenu(hSysPopup); return 0; }
853 if( !AppendMenu32A(frame->wIDmenu,MF_HELP | MF_BITMAP,
854 SC_RESTORE, (LPSTR)(DWORD)hBmpRestore ))
856 RemoveMenu(frame->wIDmenu,0,MF_BYPOSITION);
857 return 0;
860 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
861 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
862 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
864 child->dwStyle &= ~WS_SYSMENU;
866 /* redraw menu */
867 DrawMenuBar(frame->hwndSelf);
869 return 1;
872 /**********************************************************************
873 * MDI_RestoreFrameMenu
875 BOOL MDI_RestoreFrameMenu( WND *frameWnd, HWND hChild)
877 WND* child = WIN_FindWndPtr(hChild);
878 INT nItems = GetMenuItemCount(frameWnd->wIDmenu) - 1;
880 dprintf_mdi(stddeb,"MDI_RestoreFrameMenu: for child %04x\n",hChild);
882 if( GetMenuItemID(frameWnd->wIDmenu,nItems) != SC_RESTORE )
883 return 0;
885 child->dwStyle |= WS_SYSMENU;
887 RemoveMenu(frameWnd->wIDmenu,0,MF_BYPOSITION);
888 DeleteMenu(frameWnd->wIDmenu,nItems-1,MF_BYPOSITION);
890 DrawMenuBar(frameWnd->hwndSelf);
892 return 1;
895 /**********************************************************************
896 * MDI_UpdateFrameText
898 * used when child window is maximized/restored
900 * Note: lpTitle can be NULL
902 void MDI_UpdateFrameText(WND *frameWnd, HWND hClient, BOOL repaint, LPCSTR lpTitle)
904 char lpBuffer[MDI_MAXTITLELENGTH+1];
905 WND* clientWnd = WIN_FindWndPtr(hClient);
907 MDICLIENTINFO *ci = (MDICLIENTINFO *) clientWnd->wExtra;
909 dprintf_mdi(stddeb, "MDI: repaint %i, frameText %s\n", repaint, (lpTitle)?lpTitle:"NULL");
911 /* store new "default" title if lpTitle is not NULL */
912 if (lpTitle)
914 if (ci->frameTitle) HeapFree( SystemHeap, 0, ci->frameTitle );
915 ci->frameTitle = HEAP_strdupA( SystemHeap, 0, lpTitle );
918 if (ci->frameTitle)
920 WND* childWnd = WIN_FindWndPtr( ci->hwndChildMaximized );
922 if( childWnd && childWnd->text )
924 /* combine frame title and child title if possible */
926 LPCSTR lpBracket = " - [";
927 int i_frame_text_length = strlen(ci->frameTitle);
928 int i_child_text_length = strlen(childWnd->text);
930 lstrcpyn32A( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
932 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
934 strcat( lpBuffer, lpBracket );
936 if( i_frame_text_length + i_child_text_length + 6 < MDI_MAXTITLELENGTH )
938 strcat( lpBuffer, childWnd->text );
939 strcat( lpBuffer, "]" );
941 else
943 lstrcpyn32A( lpBuffer + i_frame_text_length + 4,
944 childWnd->text,
945 MDI_MAXTITLELENGTH - i_frame_text_length - 5 );
946 strcat( lpBuffer, "]" );
950 else
952 strncpy(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH );
953 lpBuffer[MDI_MAXTITLELENGTH]='\0';
956 else
957 lpBuffer[0] = '\0';
959 DEFWND_SetText( frameWnd, lpBuffer );
960 if( repaint == MDI_REPAINTFRAME)
961 SetWindowPos(frameWnd->hwndSelf, 0,0,0,0,0, SWP_FRAMECHANGED |
962 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
966 /* ----------------------------- Interface ---------------------------- */
969 /**********************************************************************
970 * MDIClientWndProc
972 * This function is the handler for all MDI requests.
974 LRESULT MDIClientWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
976 LPCREATESTRUCT16 cs;
977 LPCLIENTCREATESTRUCT16 ccs;
978 MDICLIENTINFO *ci;
979 RECT16 rect;
980 WND *w = WIN_FindWndPtr(hwnd);
981 WND *frameWnd = w->parent;
983 ci = (MDICLIENTINFO *) w->wExtra;
985 switch (message)
987 case WM_CREATE:
988 cs = (LPCREATESTRUCT16) PTR_SEG_TO_LIN(lParam);
989 ccs = (LPCLIENTCREATESTRUCT16) PTR_SEG_TO_LIN(cs->lpCreateParams);
991 ci->hWindowMenu = ccs->hWindowMenu;
992 ci->idFirstChild = ccs->idFirstChild;
993 ci->hwndChildMaximized = 0;
994 ci->nActiveChildren = 0;
995 ci->nTotalCreated = 0;
996 ci->frameTitle = NULL;
997 ci->sbNeedUpdate = 0;
998 ci->self = hwnd;
999 w->dwStyle |= WS_CLIPCHILDREN;
1001 if (!hBmpClose)
1003 hBmpClose = CreateMDIMenuBitmap();
1004 hBmpRestore = LoadBitmap16( 0, MAKEINTRESOURCE(OBM_RESTORE) );
1006 MDI_UpdateFrameText(frameWnd, hwnd, MDI_NOFRAMEREPAINT,frameWnd->text);
1008 AppendMenu32A( ccs->hWindowMenu, MF_SEPARATOR, 0, NULL );
1010 GetClientRect16(frameWnd->hwndSelf, &rect);
1011 NC_HandleNCCalcSize( w, &rect );
1012 w->rectClient = rect;
1014 dprintf_mdi(stddeb,"MDI: Client created - hwnd = %04x, idFirst = %u\n",hwnd,ci->idFirstChild);
1016 return 0;
1018 case WM_DESTROY:
1019 if( ci->hwndChildMaximized ) MDI_RestoreFrameMenu(w, frameWnd->hwndSelf);
1020 ci->idFirstChild = GetMenuItemCount(ci->hWindowMenu) - 1;
1021 ci->nActiveChildren++; /* to delete a separator */
1023 while( ci->nActiveChildren-- )
1024 DeleteMenu(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
1026 return 0;
1028 case WM_MDIACTIVATE:
1029 if( ci->hwndActiveChild != (HWND)wParam )
1030 SetWindowPos((HWND)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1031 return 0;
1033 case WM_MDICASCADE:
1034 return MDICascade(w, ci);
1036 case WM_MDICREATE:
1037 return (LONG)MDICreateChild(w, ci, hwnd, lParam );
1039 case WM_MDIDESTROY:
1040 return (LONG)MDIDestroyChild(w, ci, hwnd, (HWND)wParam, TRUE);
1042 case WM_MDIGETACTIVE:
1043 return ((LONG) ci->hwndActiveChild |
1044 ((LONG) (ci->hwndChildMaximized>0) << 16));
1046 case WM_MDIICONARRANGE:
1047 ci->sbNeedUpdate = TRUE;
1048 MDIIconArrange(hwnd);
1049 ci->sbRecalc = SB_BOTH+1;
1050 SendMessage16(hwnd,WM_MDICALCCHILDSCROLL,0,0L);
1051 return 0;
1053 case WM_MDIMAXIMIZE:
1054 ShowWindow((HWND)wParam, SW_MAXIMIZE);
1055 return 0;
1057 case WM_MDINEXT:
1058 MDI_SwitchActiveChild(hwnd, (HWND)wParam, (lParam)?1:0);
1059 break;
1061 case WM_MDIRESTORE:
1062 ShowWindow( (HWND)wParam, SW_NORMAL);
1063 return 0;
1065 case WM_MDISETMENU:
1066 #ifdef WINELIB32
1067 return (LRESULT)MDISetMenu(hwnd, FALSE, (HMENU)wParam, (HMENU)lParam);
1068 #else
1069 return (LRESULT)MDISetMenu(hwnd, wParam, LOWORD(lParam), HIWORD(lParam));
1070 #endif
1072 case WM_MDITILE:
1073 ci->sbNeedUpdate = TRUE;
1074 ShowScrollBar(hwnd,SB_BOTH,FALSE);
1075 MDITile(w, ci,wParam);
1076 ci->sbNeedUpdate = FALSE;
1077 return 0;
1079 case WM_VSCROLL:
1080 case WM_HSCROLL:
1081 ci->sbNeedUpdate = TRUE;
1082 ScrollChildren(hwnd,message,wParam,lParam);
1083 ci->sbNeedUpdate = FALSE;
1084 return 0;
1086 case WM_SETFOCUS:
1087 if( ci->hwndActiveChild )
1089 w = WIN_FindWndPtr( ci->hwndActiveChild );
1090 if( !(w->dwStyle & WS_MINIMIZE) )
1091 SetFocus( ci->hwndActiveChild );
1093 return 0;
1095 case WM_NCACTIVATE:
1096 if( ci->hwndActiveChild )
1097 SendMessage16(ci->hwndActiveChild, message, wParam, lParam);
1098 break;
1100 case WM_PARENTNOTIFY:
1101 if( wParam == WM_LBUTTONDOWN )
1103 POINT16 pt = MAKEPOINT16(lParam);
1104 HWND child = ChildWindowFromPoint16(hwnd, pt);
1106 dprintf_mdi(stddeb,"MDIClient: notification from %04x (%i,%i)\n",child,pt.x,pt.y);
1108 if( child && child != hwnd )
1110 WND* wnd = WIN_FindWndPtr( child );
1112 /* if we got owned popup */
1113 if( wnd->owner ) child = wnd->owner->hwndSelf;
1115 if( child != ci->hwndActiveChild )
1116 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1119 return 0;
1121 case WM_SIZE:
1122 if( ci->hwndChildMaximized )
1124 WND* child = WIN_FindWndPtr(ci->hwndChildMaximized);
1125 RECT16 rect = { 0, 0, LOWORD(lParam), HIWORD(lParam) };
1127 AdjustWindowRectEx16(&rect, child->dwStyle, 0, child->dwExStyle);
1128 MoveWindow(ci->hwndChildMaximized, rect.left, rect.top,
1129 rect.right - rect.left, rect.bottom - rect.top, 1);
1131 else
1132 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1134 break;
1136 case WM_MDICALCCHILDSCROLL:
1137 if( ci->sbNeedUpdate )
1138 if( ci->sbRecalc )
1140 CalcChildScroll(hwnd, ci->sbRecalc-1);
1141 ci->sbRecalc = ci->sbNeedUpdate = 0;
1143 return 0;
1146 return DefWindowProc16(hwnd, message, wParam, lParam);
1150 /***********************************************************************
1151 * DefFrameProc16 (USER.445)
1153 LRESULT DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient, UINT16 message,
1154 WPARAM16 wParam, LPARAM lParam )
1156 HWND childHwnd;
1157 MDICLIENTINFO* ci;
1158 WND* wndPtr;
1160 if (hwndMDIClient)
1162 switch (message)
1164 case WM_COMMAND:
1165 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1166 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1168 /* check for possible syscommands for maximized MDI child */
1170 if( wParam < ci->idFirstChild ||
1171 wParam >= ci->idFirstChild + ci->nActiveChildren )
1173 if( (wParam - 0xF000) & 0xF00F ) break;
1174 switch( wParam )
1176 case SC_SIZE:
1177 case SC_MOVE:
1178 case SC_MINIMIZE:
1179 case SC_MAXIMIZE:
1180 case SC_NEXTWINDOW:
1181 case SC_PREVWINDOW:
1182 case SC_CLOSE:
1183 case SC_RESTORE:
1184 if( ci->hwndChildMaximized )
1185 return SendMessage16( ci->hwndChildMaximized, WM_SYSCOMMAND,
1186 wParam, lParam);
1189 else
1191 childHwnd = MDI_GetChildByID( WIN_FindWndPtr(hwndMDIClient),
1192 wParam );
1193 if( childHwnd )
1194 SendMessage16(hwndMDIClient, WM_MDIACTIVATE, (WPARAM)childHwnd , 0L);
1196 break;
1198 case WM_NCACTIVATE:
1199 SendMessage16(hwndMDIClient, message, wParam, lParam);
1200 break;
1202 case WM_SETTEXT:
1203 MDI_UpdateFrameText(WIN_FindWndPtr(hwnd), hwndMDIClient,
1204 MDI_REPAINTFRAME,
1205 (LPCSTR)PTR_SEG_TO_LIN(lParam));
1206 return 0;
1208 case WM_SETFOCUS:
1209 SetFocus(hwndMDIClient);
1210 break;
1212 case WM_SIZE:
1213 MoveWindow(hwndMDIClient, 0, 0,
1214 LOWORD(lParam), HIWORD(lParam), TRUE);
1215 break;
1219 return DefWindowProc16(hwnd, message, wParam, lParam);
1223 /***********************************************************************
1224 * DefFrameProc32A (USER32.121)
1226 LRESULT DefFrameProc32A( HWND32 hwnd, HWND32 hwndMDIClient, UINT32 message,
1227 WPARAM32 wParam, LPARAM lParam )
1229 if (hwndMDIClient)
1231 switch (message)
1233 case WM_COMMAND:
1234 return DefFrameProc16( hwnd, hwndMDIClient, message,
1235 (WPARAM16)wParam,
1236 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1238 case WM_NCACTIVATE:
1239 SendMessage32A(hwndMDIClient, message, wParam, lParam);
1240 break;
1242 case WM_SETTEXT:
1243 return DefFrameProc16( hwnd, hwndMDIClient, message,
1244 wParam, (LPARAM)PTR_SEG_TO_LIN(lParam) );
1246 case WM_SETFOCUS:
1247 case WM_SIZE:
1248 return DefFrameProc16( hwnd, hwndMDIClient, message,
1249 wParam, lParam );
1253 return DefWindowProc32A(hwnd, message, wParam, lParam);
1257 /***********************************************************************
1258 * DefFrameProc32W (USER32.122)
1260 LRESULT DefFrameProc32W( HWND32 hwnd, HWND32 hwndMDIClient, UINT32 message,
1261 WPARAM32 wParam, LPARAM lParam )
1263 if (hwndMDIClient)
1265 switch (message)
1267 case WM_COMMAND:
1268 return DefFrameProc16( hwnd, hwndMDIClient, message,
1269 (WPARAM16)wParam,
1270 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1272 case WM_NCACTIVATE:
1273 SendMessage32W(hwndMDIClient, message, wParam, lParam);
1274 break;
1276 case WM_SETTEXT:
1277 /* FIXME: Unicode */
1278 return DefFrameProc32A( hwnd, hwndMDIClient, message,
1279 wParam, lParam );
1281 case WM_SETFOCUS:
1282 case WM_SIZE:
1283 return DefFrameProc32A( hwnd, hwndMDIClient, message,
1284 wParam, lParam );
1288 return DefWindowProc32W( hwnd, message, wParam, lParam );
1292 /***********************************************************************
1293 * DefMDIChildProc16 (USER.447)
1295 LRESULT DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1296 WPARAM16 wParam, LPARAM lParam )
1298 MDICLIENTINFO *ci;
1299 WND *clientWnd;
1301 clientWnd = WIN_FindWndPtr(GetParent(hwnd));
1302 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1304 switch (message)
1306 case WM_SETTEXT:
1307 DefWindowProc16(hwnd, message, wParam, lParam);
1308 MDI_MenuModifyItem(clientWnd,hwnd);
1309 if( ci->hwndChildMaximized == hwnd )
1310 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1311 MDI_REPAINTFRAME, NULL );
1312 return 0;
1314 case WM_CLOSE:
1315 SendMessage16(ci->self,WM_MDIDESTROY,(WPARAM)hwnd,0L);
1316 return 0;
1318 case WM_SETFOCUS:
1319 if( ci->hwndActiveChild != hwnd )
1320 MDI_ChildActivate(clientWnd, hwnd);
1321 break;
1323 case WM_CHILDACTIVATE:
1324 MDI_ChildActivate(clientWnd, hwnd);
1325 return 0;
1327 case WM_NCPAINT:
1328 dprintf_mdi(stddeb,"DefMDIChildProc: WM_NCPAINT for %04x, active %04x\n",
1329 hwnd, ci->hwndActiveChild );
1330 break;
1332 case WM_SYSCOMMAND:
1333 switch( wParam )
1335 case SC_MOVE:
1336 if( ci->hwndChildMaximized == hwnd) return 0;
1337 break;
1338 case SC_MAXIMIZE:
1339 if( ci->hwndChildMaximized == hwnd)
1340 return SendMessage16( clientWnd->parent->hwndSelf,
1341 message, wParam, lParam);
1342 break;
1343 case SC_NEXTWINDOW:
1344 SendMessage16( ci->self, WM_MDINEXT, 0, 0);
1345 return 0;
1346 case SC_PREVWINDOW:
1347 SendMessage16( ci->self, WM_MDINEXT, 0, 1);
1348 return 0;
1350 break;
1352 case WM_GETMINMAXINFO:
1353 MDI_ChildGetMinMaxInfo(clientWnd, hwnd, (MINMAXINFO16*) PTR_SEG_TO_LIN(lParam));
1354 return 0;
1356 case WM_SETVISIBLE:
1357 if( ci->hwndChildMaximized)
1358 ci->sbNeedUpdate = 0;
1359 else
1360 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1361 break;
1363 case WM_SIZE:
1364 /* do not change */
1366 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1368 ci->hwndChildMaximized = 0;
1370 MDI_RestoreFrameMenu( clientWnd->parent, hwnd);
1371 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1372 MDI_REPAINTFRAME, NULL );
1375 if( wParam == SIZE_MAXIMIZED )
1377 HWND hMaxChild = ci->hwndChildMaximized;
1379 if( hMaxChild == hwnd ) break;
1381 if( hMaxChild)
1383 SendMessage16( hMaxChild, WM_SETREDRAW, FALSE, 0L );
1385 MDI_RestoreFrameMenu( clientWnd->parent, hMaxChild);
1386 ShowWindow( hMaxChild, SW_SHOWNOACTIVATE);
1388 SendMessage16( hMaxChild, WM_SETREDRAW, TRUE, 0L );
1391 dprintf_mdi(stddeb,"\tMDI: maximizing child %04x\n", hwnd );
1393 ci->hwndChildMaximized = hwnd; /* !!! */
1395 MDI_AugmentFrameMenu( ci, clientWnd->parent, hwnd);
1396 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1397 MDI_REPAINTFRAME, NULL );
1400 if( wParam == SIZE_MINIMIZED )
1402 HWND switchTo = MDI_GetWindow(clientWnd, hwnd, 0);
1404 if( switchTo )
1405 SendMessage16( switchTo, WM_CHILDACTIVATE, 0, 0L);
1408 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1409 break;
1411 case WM_MENUCHAR:
1413 /* MDI children don't have menus */
1414 PostMessage( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1415 (WPARAM)SC_KEYMENU, (LPARAM)wParam);
1416 return 0x00010000L;
1418 case WM_NEXTMENU:
1419 /* set current menu to child system menu */
1421 break;
1424 return DefWindowProc16(hwnd, message, wParam, lParam);
1428 /***********************************************************************
1429 * DefMDIChildProc32A (USER32.123)
1431 LRESULT DefMDIChildProc32A( HWND32 hwnd, UINT32 message,
1432 WPARAM32 wParam, LPARAM lParam )
1434 MDICLIENTINFO *ci;
1435 WND *clientWnd;
1437 clientWnd = WIN_FindWndPtr(GetParent(hwnd));
1438 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1440 switch (message)
1442 case WM_SETTEXT:
1443 DefWindowProc32A(hwnd, message, wParam, lParam);
1444 MDI_MenuModifyItem(clientWnd,hwnd);
1445 if( ci->hwndChildMaximized == hwnd )
1446 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1447 MDI_REPAINTFRAME, NULL );
1448 return 0;
1450 case WM_GETMINMAXINFO:
1452 MINMAXINFO16 mmi;
1453 STRUCT32_MINMAXINFO32to16( (MINMAXINFO32 *)lParam, &mmi );
1454 MDI_ChildGetMinMaxInfo( clientWnd, hwnd, &mmi );
1455 STRUCT32_MINMAXINFO16to32( &mmi, (MINMAXINFO32 *)lParam );
1457 return 0;
1459 case WM_MENUCHAR:
1461 /* MDI children don't have menus */
1462 PostMessage( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1463 (WPARAM)SC_KEYMENU, (LPARAM)LOWORD(wParam) );
1464 return 0x00010000L;
1466 case WM_CLOSE:
1467 case WM_SETFOCUS:
1468 case WM_CHILDACTIVATE:
1469 case WM_NCPAINT:
1470 case WM_SYSCOMMAND:
1471 case WM_SETVISIBLE:
1472 case WM_SIZE:
1473 case WM_NEXTMENU:
1474 return DefMDIChildProc16( hwnd, message, (WPARAM16)wParam, lParam );
1476 return DefWindowProc32A(hwnd, message, wParam, lParam);
1480 /***********************************************************************
1481 * DefMDIChildProc32W (USER32.124)
1483 LRESULT DefMDIChildProc32W( HWND32 hwnd, UINT32 message,
1484 WPARAM32 wParam, LPARAM lParam )
1486 MDICLIENTINFO *ci;
1487 WND *clientWnd;
1489 clientWnd = WIN_FindWndPtr(GetParent(hwnd));
1490 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1492 switch (message)
1494 case WM_SETTEXT:
1495 DefWindowProc32W(hwnd, message, wParam, lParam);
1496 MDI_MenuModifyItem(clientWnd,hwnd);
1497 if( ci->hwndChildMaximized == hwnd )
1498 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1499 MDI_REPAINTFRAME, NULL );
1500 return 0;
1502 case WM_GETMINMAXINFO:
1503 case WM_MENUCHAR:
1504 case WM_CLOSE:
1505 case WM_SETFOCUS:
1506 case WM_CHILDACTIVATE:
1507 case WM_NCPAINT:
1508 case WM_SYSCOMMAND:
1509 case WM_SETVISIBLE:
1510 case WM_SIZE:
1511 case WM_NEXTMENU:
1512 return DefMDIChildProc32A( hwnd, message, (WPARAM16)wParam, lParam );
1514 return DefWindowProc32W(hwnd, message, wParam, lParam);
1518 /**********************************************************************
1519 * TranslateMDISysAccel (USER.451)
1522 BOOL TranslateMDISysAccel(HWND hwndClient, LPMSG16 msg)
1524 WND* clientWnd = WIN_FindWndPtr( hwndClient);
1525 WND* wnd;
1526 MDICLIENTINFO *ci = NULL;
1527 WPARAM wParam = 0;
1529 if( (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) || !clientWnd )
1530 return 0;
1532 ci = (MDICLIENTINFO*) clientWnd->wExtra;
1533 wnd = WIN_FindWndPtr(ci->hwndActiveChild);
1535 if( !wnd ) return 0;
1537 if( wnd->dwStyle & WS_DISABLED ) return 0;
1539 if ((GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
1540 switch( msg->wParam )
1542 case VK_F6:
1543 case VK_SEPARATOR:
1544 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 )? SC_NEXTWINDOW: SC_PREVWINDOW;
1545 break;
1546 case VK_RBUTTON:
1547 wParam = SC_CLOSE;
1548 break;
1549 default:
1550 return 0;
1552 else
1553 return 0;
1555 dprintf_mdi(stddeb,"TranslateMDISysAccel: wParam = %04x\n", wParam);
1557 SendMessage16(ci->hwndActiveChild,WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
1558 return 1;
1562 /***********************************************************************
1563 * CalcChildScroll (USER.462)
1565 void CalcChildScroll( HWND hwnd, WORD scroll )
1567 RECT16 childRect, clientRect;
1568 INT vmin, vmax, hmin, hmax, vpos, hpos;
1569 BOOL noscroll = FALSE;
1570 WND *pWnd, *Wnd;
1572 if (!(Wnd = pWnd = WIN_FindWndPtr( hwnd ))) return;
1573 GetClientRect16( hwnd, &clientRect );
1574 SetRectEmpty16( &childRect );
1576 for ( pWnd = pWnd->child; pWnd; pWnd = pWnd->next )
1578 UnionRect16( &childRect, &pWnd->rectWindow, &childRect );
1579 if( pWnd->dwStyle & WS_MAXIMIZE )
1580 noscroll = TRUE;
1582 UnionRect16( &childRect, &clientRect, &childRect );
1584 /* jump through the hoops to prevent excessive flashing
1587 hmin = childRect.left; hmax = childRect.right - clientRect.right;
1588 hpos = clientRect.left - childRect.left;
1589 vmin = childRect.top; vmax = childRect.bottom - clientRect.bottom;
1590 vpos = clientRect.top - childRect.top;
1592 if( noscroll )
1593 ShowScrollBar(hwnd, SB_BOTH, FALSE);
1594 else
1595 switch( scroll )
1597 case SB_HORZ:
1598 vpos = hpos; vmin = hmin; vmax = hmax;
1599 case SB_VERT:
1600 SetScrollPos(hwnd, scroll, vpos, FALSE);
1601 SetScrollRange(hwnd, scroll, vmin, vmax, TRUE);
1602 break;
1603 case SB_BOTH:
1604 SCROLL_SetNCSbState( Wnd, vmin, vmax, vpos,
1605 hmin, hmax, hpos);
1606 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1607 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1611 /***********************************************************************
1612 * ScrollChildren (USER.463)
1614 void ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1616 WND *wndPtr = WIN_FindWndPtr(hWnd);
1617 short newPos=-1;
1618 short curPos;
1619 short length;
1620 INT16 minPos;
1621 INT16 maxPos;
1622 short shift;
1624 if( !wndPtr ) return;
1626 if( uMsg == WM_HSCROLL )
1628 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
1629 curPos = GetScrollPos(hWnd,SB_HORZ);
1630 length = (wndPtr->rectClient.right - wndPtr->rectClient.left)/2;
1631 shift = SYSMETRICS_CYHSCROLL;
1633 else if( uMsg == WM_VSCROLL )
1635 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
1636 curPos = GetScrollPos(hWnd,SB_VERT);
1637 length = (wndPtr->rectClient.bottom - wndPtr->rectClient.top)/2;
1638 shift = SYSMETRICS_CXVSCROLL;
1640 else return;
1642 switch( wParam )
1644 case SB_LINEUP:
1645 newPos = curPos - shift;
1646 break;
1647 case SB_LINEDOWN:
1648 newPos = curPos + shift;
1649 break;
1650 case SB_PAGEUP:
1651 newPos = curPos - length;
1652 break;
1653 case SB_PAGEDOWN:
1654 newPos = curPos + length;
1655 break;
1657 case SB_THUMBPOSITION:
1658 newPos = LOWORD(lParam);
1659 break;
1661 case SB_THUMBTRACK:
1662 return;
1664 case SB_TOP:
1665 newPos = minPos;
1666 break;
1667 case SB_BOTTOM:
1668 newPos = maxPos;
1669 break;
1670 case SB_ENDSCROLL:
1671 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
1672 return;
1675 if( newPos > maxPos )
1676 newPos = maxPos;
1677 else if( newPos < minPos )
1678 newPos = minPos;
1680 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
1682 if( uMsg == WM_VSCROLL )
1683 ScrollWindow(hWnd ,0 ,curPos - newPos, NULL, NULL);
1684 else
1685 ScrollWindow(hWnd ,curPos - newPos, 0, NULL, NULL);