Release 960928
[wine/multimedia.git] / windows / mdi.c
blob40b0d4d35089c17d127e13ad8edf5842f321ca24
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 "struct32.h"
29 #include "sysmetrics.h"
30 #include "stddebug.h"
31 #include "debug.h"
34 static HBITMAP hBmpClose = 0;
35 static HBITMAP hBmpRestore = 0;
37 DWORD SCROLL_SetNCSbState(WND*,int,int,int,int,int,int);
39 /* ----------------- declarations ----------------- */
40 void MDI_UpdateFrameText(WND *, HWND, BOOL, LPCSTR);
41 BOOL MDI_AugmentFrameMenu(MDICLIENTINFO*, WND *, HWND);
42 BOOL MDI_RestoreFrameMenu(WND *, HWND);
44 void ScrollChildren(HWND , UINT , WPARAM , LPARAM );
45 void CalcChildScroll(HWND, WORD);
47 static LONG MDI_ChildActivate(WND* ,HWND );
49 /* -------- Miscellaneous service functions ----------
51 * MDI_GetChildByID
54 static HWND MDI_GetChildByID(WND* wndPtr,int id)
56 for (wndPtr = wndPtr->child; wndPtr; wndPtr = wndPtr->next)
57 if (wndPtr->wIDmenu == id) return wndPtr->hwndSelf;
58 return 0;
61 static void MDI_PostUpdate(HWND hwnd, MDICLIENTINFO* ci, WORD recalc)
63 if( !ci->sbNeedUpdate )
65 ci->sbNeedUpdate = TRUE;
66 PostMessage( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
68 ci->sbRecalc = recalc;
71 /**********************************************************************
72 * MDI_MenuAppendItem
74 #ifdef SUPERFLUOUS_FUNCTIONS
75 static BOOL MDI_MenuAppendItem(WND *clientWnd, HWND hWndChild)
77 char buffer[128];
78 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
79 WND *wndPtr = WIN_FindWndPtr(hWndChild);
80 int n = sprintf(buffer, "%d ",
81 clientInfo->nActiveChildren);
83 if( !clientInfo->hWindowMenu ) return 0;
85 if (wndPtr->text) strncpy(buffer + n, wndPtr->text, sizeof(buffer) - n - 1);
86 return AppendMenu32A( clientInfo->hWindowMenu, MF_STRING,
87 wndPtr->wIDmenu, buffer );
89 #endif
91 /**********************************************************************
92 * MDI_MenuModifyItem
94 static BOOL MDI_MenuModifyItem(WND* clientWnd, HWND hWndChild )
96 char buffer[128];
97 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
98 WND *wndPtr = WIN_FindWndPtr(hWndChild);
99 UINT n = sprintf(buffer, "%d ",
100 wndPtr->wIDmenu - clientInfo->idFirstChild + 1);
101 BOOL bRet = 0;
103 if( !clientInfo->hWindowMenu ) return 0;
105 if (wndPtr->text) lstrcpyn32A(buffer + n, wndPtr->text, sizeof(buffer) - n );
107 n = GetMenuState(clientInfo->hWindowMenu,wndPtr->wIDmenu ,MF_BYCOMMAND);
108 bRet = ModifyMenu32A(clientInfo->hWindowMenu , wndPtr->wIDmenu,
109 MF_BYCOMMAND | MF_STRING, wndPtr->wIDmenu, buffer );
110 CheckMenuItem(clientInfo->hWindowMenu ,wndPtr->wIDmenu , n & MF_CHECKED);
111 return bRet;
114 /**********************************************************************
115 * MDI_MenuDeleteItem
117 static BOOL MDI_MenuDeleteItem(WND* clientWnd, HWND hWndChild )
119 char buffer[128];
120 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
121 WND *wndPtr = WIN_FindWndPtr(hWndChild);
122 UINT index = 0,id,n;
124 if( !clientInfo->nActiveChildren ||
125 !clientInfo->hWindowMenu ) return 0;
127 id = wndPtr->wIDmenu;
128 DeleteMenu(clientInfo->hWindowMenu,id,MF_BYCOMMAND);
130 /* walk the rest of MDI children to prevent gaps in the id
131 * sequence and in the menu child list */
133 for( index = id+1; index <= clientInfo->nActiveChildren +
134 clientInfo->idFirstChild; index++ )
136 wndPtr = WIN_FindWndPtr(MDI_GetChildByID(clientWnd,index));
137 if( !wndPtr )
139 dprintf_mdi(stddeb,"MDIMenuDeleteItem: no window for id=%i\n",index);
140 continue;
143 /* set correct id */
144 wndPtr->wIDmenu--;
146 n = sprintf(buffer, "%d ",index - clientInfo->idFirstChild);
147 if (wndPtr->text)
148 lstrcpyn32A(buffer + n, wndPtr->text, sizeof(buffer) - n );
150 /* change menu */
151 ModifyMenu32A(clientInfo->hWindowMenu ,index ,MF_BYCOMMAND | MF_STRING,
152 index - 1 , buffer );
154 return 1;
157 /**********************************************************************
158 * MDI_GetWindow
160 * returns "activateable" child or zero
162 HWND MDI_GetWindow(WND *clientWnd, HWND hWnd, WORD wTo )
164 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
165 WND *wndPtr, *pWnd, *pWndLast;
167 if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
169 if( !(wndPtr = WIN_FindWndPtr(hWnd)) ) return 0;
171 pWnd = wndPtr;
172 pWndLast = NULL;
173 for (;;)
175 pWnd = pWnd->next;
176 if (!pWnd) pWnd = wndPtr->parent->child;
177 if (pWnd == wndPtr) /* not found */
179 if (!wTo || !pWndLast) return 0;
180 break;
183 /* we are not interested in owned popups */
184 if ( !pWnd->owner &&
185 (pWnd->dwStyle & WS_VISIBLE) &&
186 !(pWnd->dwStyle & WS_DISABLED)) /* found one */
188 pWndLast = pWnd;
189 if (!wTo) break;
192 return pWndLast ? pWndLast->hwndSelf : 0;
195 /**********************************************************************
196 * MDI_CalcDefaultChildPos
198 * It seems that default height is 2/3 of client rect
200 void MDI_CalcDefaultChildPos(WND* w, WORD n, LPPOINT16 lpPos, INT delta)
202 RECT16 rect = w->rectClient;
203 INT spacing = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME) - 1;
204 INT nstagger;
206 if( rect.bottom - rect.top - delta >= spacing )
207 rect.bottom -= delta;
209 nstagger = (rect.bottom - rect.top)/(3*spacing);
210 lpPos[1].x = (rect.right - rect.left - nstagger*spacing);
211 lpPos[1].y = (rect.bottom - rect.top - nstagger*spacing);
212 lpPos[0].x = lpPos[0].y = spacing*(n%(nstagger+1));
215 /**********************************************************************
216 * MDISetMenu
218 HMENU MDISetMenu(HWND hwnd, BOOL fRefresh, HMENU hmenuFrame, HMENU hmenuWindow)
220 WND *w = WIN_FindWndPtr(hwnd);
221 MDICLIENTINFO *ci;
223 dprintf_mdi(stddeb, "WM_MDISETMENU: %04x %04x %04x %04x\n",
224 hwnd, fRefresh, hmenuFrame, hmenuWindow);
226 ci = (MDICLIENTINFO *) w->wExtra;
228 if (!fRefresh)
230 HWND hwndFrame = GetParent16(hwnd);
231 HMENU oldFrameMenu = GetMenu(hwndFrame);
233 if( ci->hwndChildMaximized && hmenuFrame && hmenuFrame!=oldFrameMenu )
234 MDI_RestoreFrameMenu(w->parent, ci->hwndChildMaximized );
236 if( hmenuWindow && hmenuWindow!=ci->hWindowMenu )
238 /* delete menu items from ci->hWindowMenu
239 * and add them to hmenuWindow */
241 INT i = GetMenuItemCount(ci->hWindowMenu) - 1;
242 INT pos = GetMenuItemCount(hmenuWindow) + 1;
244 AppendMenu32A( hmenuWindow, MF_SEPARATOR, 0, NULL);
246 if( ci->nActiveChildren )
248 INT j = i - ci->nActiveChildren + 1;
249 char buffer[100];
250 UINT id,state;
252 for( ; i >= j ; i-- )
254 id = GetMenuItemID(ci->hWindowMenu,i );
255 state = GetMenuState(ci->hWindowMenu,i,MF_BYPOSITION);
257 GetMenuString(ci->hWindowMenu, i, buffer, 100, MF_BYPOSITION);
259 DeleteMenu(ci->hWindowMenu, i , MF_BYPOSITION);
260 InsertMenu32A(hmenuWindow, pos, MF_BYPOSITION | MF_STRING,
261 id, buffer);
262 CheckMenuItem(hmenuWindow ,pos , MF_BYPOSITION | (state & MF_CHECKED));
266 /* remove separator */
267 DeleteMenu(ci->hWindowMenu, i, MF_BYPOSITION);
269 ci->hWindowMenu = hmenuWindow;
272 if( hmenuFrame && hmenuFrame!=oldFrameMenu)
274 SetMenu(hwndFrame, hmenuFrame);
275 if( ci->hwndChildMaximized )
276 MDI_AugmentFrameMenu(ci, w->parent, ci->hwndChildMaximized );
277 return oldFrameMenu;
281 return 0;
284 /**********************************************************************
285 * MDIIconArrange
287 WORD MDIIconArrange(HWND parent)
289 return ArrangeIconicWindows(parent); /* Any reason why the */
290 /* existing icon arrange */
291 /* can't be used here? */
292 /* -DRP */
296 /* ------------------ MDI child window functions ---------------------- */
299 /**********************************************************************
300 * MDICreateChild
302 HWND MDICreateChild(WND *w, MDICLIENTINFO *ci, HWND parent, LPARAM lParam )
304 POINT16 pos[2];
305 MDICREATESTRUCT16 *cs = (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam);
306 DWORD style = cs->style | (WS_CHILD | WS_CLIPSIBLINGS);
307 HWND hwnd, hwndMax = 0;
308 WORD wIDmenu = ci->idFirstChild + ci->nActiveChildren;
309 char lpstrDef[]="junk!";
312 * Create child window
316 dprintf_mdi(stdnimp,"MDICreateChild: origin %i,%i - dim %i,%i, style %08x\n",
317 cs->x, cs->y, cs->cx, cs->cy, (unsigned)cs->style);
318 /* calculate placement */
319 MDI_CalcDefaultChildPos(w, ci->nTotalCreated++, pos, 0);
321 if( cs->cx == CW_USEDEFAULT16 || !cs->cx )
322 cs->cx = pos[1].x;
323 if( cs->cy == CW_USEDEFAULT16 || !cs->cy )
324 cs->cy = pos[1].y;
326 if( cs->x == CW_USEDEFAULT16 )
328 cs->x = pos[0].x;
329 cs->y = pos[0].y;
332 /* restore current maximized child */
333 if( style & WS_VISIBLE && ci->hwndChildMaximized )
335 if( style & WS_MAXIMIZE )
336 SendMessage16(w->hwndSelf, WM_SETREDRAW, FALSE, 0L );
337 hwndMax = ci->hwndChildMaximized;
338 ShowWindow( hwndMax, SW_SHOWNOACTIVATE );
339 if( style & WS_MAXIMIZE )
340 SendMessage16(w->hwndSelf, WM_SETREDRAW, TRUE, 0L );
343 /* this menu is needed to set a check mark in MDI_ChildActivate */
344 AppendMenu32A(ci->hWindowMenu ,MF_STRING ,wIDmenu, lpstrDef );
346 ci->nActiveChildren++;
348 /* fix window style */
349 if( !(w->dwStyle & MDIS_ALLCHILDSTYLES) )
351 style &= (WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZE | WS_MAXIMIZE |
352 WS_CLIPCHILDREN | WS_DISABLED | WS_VSCROLL | WS_HSCROLL );
353 style |= (WS_VISIBLE | WS_OVERLAPPEDWINDOW);
356 hwnd = CreateWindow16( (LPCSTR)PTR_SEG_TO_LIN(cs->szClass),
357 (LPCSTR)PTR_SEG_TO_LIN(cs->szTitle), style,
358 cs->x, cs->y, cs->cx, cs->cy, parent,
359 (HMENU)(DWORD)(WORD)wIDmenu, w->hInstance,
360 (LPVOID)lParam);
362 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
364 if (hwnd)
366 WND* wnd = WIN_FindWndPtr( hwnd );
368 MDI_MenuModifyItem(w ,hwnd);
369 if( wnd->dwStyle & WS_MINIMIZE && ci->hwndActiveChild )
370 ShowWindow( hwnd, SW_SHOWMINNOACTIVE );
371 else
373 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE );
375 /* Set maximized state here in case hwnd didn't receive WM_SIZE
376 * during CreateWindow - bad!
379 if( wnd->dwStyle & WS_MAXIMIZE && !ci->hwndChildMaximized )
381 ci->hwndChildMaximized = wnd->hwndSelf;
382 MDI_AugmentFrameMenu( ci, w->parent, hwnd );
383 MDI_UpdateFrameText( w->parent, ci->self, MDI_REPAINTFRAME, NULL );
386 dprintf_mdi(stddeb, "MDICreateChild: created child - %04x\n",hwnd);
388 else
390 ci->nActiveChildren--;
391 DeleteMenu(ci->hWindowMenu,wIDmenu,MF_BYCOMMAND);
392 if( IsWindow(hwndMax) )
393 ShowWindow(hwndMax, SW_SHOWMAXIMIZED);
396 return hwnd;
399 /**********************************************************************
400 * MDI_ChildGetMinMaxInfo
402 void MDI_ChildGetMinMaxInfo(WND* clientWnd, HWND hwnd, MINMAXINFO16* lpMinMax )
404 WND* childWnd = WIN_FindWndPtr(hwnd);
405 RECT16 rect = clientWnd->rectClient;
407 MapWindowPoints16(clientWnd->parent->hwndSelf,
408 ((MDICLIENTINFO*)clientWnd->wExtra)->self, (LPPOINT16)&rect, 2);
409 AdjustWindowRectEx16( &rect, childWnd->dwStyle & ~(WS_VSCROLL | WS_HSCROLL),
410 0, childWnd->dwExStyle );
412 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
413 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
415 lpMinMax->ptMaxPosition.x = rect.left;
416 lpMinMax->ptMaxPosition.y = rect.top;
418 dprintf_mdi(stddeb,"\tChildMinMaxInfo: max rect (%i,%i - %i, %i)\n",
419 rect.left,rect.top,rect.right,rect.bottom);
423 /**********************************************************************
424 * MDI_SwitchActiveChild
426 * Notes: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
427 * being activated
429 * wTo is basically lParam of WM_MDINEXT message or explicit
430 * window handle
432 void MDI_SwitchActiveChild(HWND clientHwnd, HWND childHwnd, BOOL wTo )
434 WND *w = WIN_FindWndPtr(clientHwnd);
435 HWND hwndTo = 0;
436 HWND hwndPrev = 0;
437 MDICLIENTINFO *ci;
439 hwndTo = MDI_GetWindow(w,childHwnd,(WORD)wTo);
441 ci = (MDICLIENTINFO *) w->wExtra;
443 dprintf_mdi(stddeb, "MDI_SwitchActiveChild: from %04x, to %04x\n",childHwnd,hwndTo);
445 if ( !hwndTo ) return;
447 hwndPrev = ci->hwndActiveChild;
449 if ( hwndTo != hwndPrev )
451 BOOL bOptimize = 0;
453 if( ci->hwndChildMaximized )
455 bOptimize = 1;
456 w->dwStyle &= ~WS_VISIBLE;
459 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0,
460 SWP_NOMOVE | SWP_NOSIZE );
461 if( !wTo && hwndPrev )
463 SetWindowPos( hwndPrev, HWND_BOTTOM, 0, 0, 0, 0,
464 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
467 if( bOptimize )
468 ShowWindow( clientHwnd, SW_SHOW );
473 /**********************************************************************
474 * MDIDestroyChild
476 HWND MDIDestroyChild(WND *w_parent, MDICLIENTINFO *ci, HWND parent,
477 HWND child, BOOL flagDestroy)
479 WND *childPtr = WIN_FindWndPtr(child);
481 if( childPtr )
483 if( child == ci->hwndActiveChild )
485 MDI_SwitchActiveChild(parent,child,0);
487 if( child == ci->hwndActiveChild )
489 ShowWindow( child, SW_HIDE);
490 if( child == ci->hwndChildMaximized )
492 MDI_RestoreFrameMenu(w_parent->parent, child);
493 ci->hwndChildMaximized = 0;
494 MDI_UpdateFrameText(w_parent->parent,parent,TRUE,NULL);
497 MDI_ChildActivate(w_parent,0);
499 MDI_MenuDeleteItem(w_parent, child);
502 ci->nActiveChildren--;
504 dprintf_mdi(stddeb,"MDIDestroyChild: child destroyed - %04x\n",child);
506 if (flagDestroy)
508 MDI_PostUpdate(GetParent16(child), ci, SB_BOTH+1);
509 DestroyWindow(child);
513 return 0;
517 /**********************************************************************
518 * MDI_ChildActivate
520 * Note: hWndChild is NULL when last child is being destroyed
522 LONG MDI_ChildActivate(WND *clientPtr, HWND hWndChild)
524 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientPtr->wExtra;
525 HWND prevActiveWnd = clientInfo->hwndActiveChild;
526 WND *wndPtr = WIN_FindWndPtr( hWndChild );
527 WND *wndPrev = WIN_FindWndPtr( prevActiveWnd );
528 BOOL isActiveFrameWnd = 0;
530 if( hWndChild == prevActiveWnd ) return 0L;
532 if( wndPtr )
533 if( wndPtr->dwStyle & WS_DISABLED ) return 0L;
535 dprintf_mdi(stddeb,"MDI_ChildActivate: %04x\n", hWndChild);
537 if( GetActiveWindow() == clientPtr->parent->hwndSelf )
538 isActiveFrameWnd = TRUE;
540 /* deactivate prev. active child */
541 if( wndPrev )
543 wndPrev->dwStyle |= WS_SYSMENU;
544 SendMessage16( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
546 #ifdef WINELIB32
547 SendMessage32A( prevActiveWnd, WM_MDIACTIVATE, (WPARAM)prevActiveWnd,
548 (LPARAM)hWndChild);
549 #else
551 SendMessage16( prevActiveWnd, WM_MDIACTIVATE, FALSE,
552 MAKELONG(hWndChild,prevActiveWnd));
553 #endif
554 /* uncheck menu item */
555 if( clientInfo->hWindowMenu )
556 CheckMenuItem( clientInfo->hWindowMenu,
557 wndPrev->wIDmenu, 0);
560 /* set appearance */
561 if( clientInfo->hwndChildMaximized )
562 if( clientInfo->hwndChildMaximized != hWndChild )
563 if( hWndChild )
565 clientInfo->hwndActiveChild = hWndChild;
566 ShowWindow( hWndChild, SW_SHOWMAXIMIZED);
568 else
569 ShowWindow( clientInfo->hwndActiveChild,
570 SW_SHOWNORMAL );
572 clientInfo->hwndActiveChild = hWndChild;
574 /* check if we have any children left */
575 if( !hWndChild )
577 if( isActiveFrameWnd )
578 SetFocus32( clientInfo->self );
579 return 0;
582 /* check menu item */
583 if( clientInfo->hWindowMenu )
584 CheckMenuItem( clientInfo->hWindowMenu,
585 wndPtr->wIDmenu, MF_CHECKED);
587 /* bring active child to the top */
588 SetWindowPos( hWndChild, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
590 if( isActiveFrameWnd )
592 SendMessage16( hWndChild, WM_NCACTIVATE, TRUE, 0L);
593 if( GetFocus32() == clientInfo->self )
594 SendMessage16( clientInfo->self, WM_SETFOCUS,
595 (WPARAM)clientInfo->self, 0L );
596 else
597 SetFocus32( clientInfo->self );
600 #ifdef WINELIB32
601 SendMessage32A( hWndChild, WM_MDIACTIVATE, (WPARAM)hWndChild,
602 (LPARAM)prevActiveWnd );
603 #else
604 SendMessage16( hWndChild, WM_MDIACTIVATE, TRUE,
605 MAKELONG(hWndChild,prevActiveWnd));
606 #endif
608 return 1;
611 /**********************************************************************
612 * MDI_BuildWCL
614 * iTotal returns number of children available for tiling or cascading
616 MDIWCL* MDI_BuildWCL(WND* clientWnd, INT16* iTotal)
618 MDIWCL *listTop,*listNext;
619 WND *childWnd;
621 if (!(listTop = (MDIWCL*)malloc( sizeof(MDIWCL) ))) return NULL;
623 listTop->hChild = clientWnd->child ? clientWnd->child->hwndSelf : 0;
624 listTop->prev = NULL;
625 *iTotal = 1;
627 /* build linked list from top child to bottom */
629 childWnd = WIN_FindWndPtr( listTop->hChild );
630 while( childWnd && childWnd->next )
632 listNext = (MDIWCL*)xmalloc(sizeof(MDIWCL));
634 if( (childWnd->dwStyle & WS_DISABLED) ||
635 (childWnd->dwStyle & WS_MINIMIZE) ||
636 !(childWnd->dwStyle & WS_VISIBLE) )
638 listTop->hChild = 0;
639 (*iTotal)--;
642 listNext->hChild = childWnd->next->hwndSelf;
643 listNext->prev = listTop;
644 listTop = listNext;
645 (*iTotal)++;
647 childWnd = childWnd->next;
650 if( (childWnd->dwStyle & WS_DISABLED) ||
651 (childWnd->dwStyle & WS_MINIMIZE) ||
652 !(childWnd->dwStyle & WS_VISIBLE) )
654 listTop->hChild = 0;
655 (*iTotal)--;
658 return listTop;
662 /* -------------------- MDI client window functions ------------------- */
664 /**********************************************************************
665 * CreateMDIMenuBitmap
667 HBITMAP CreateMDIMenuBitmap(void)
669 HDC hDCSrc = CreateCompatibleDC(0);
670 HDC hDCDest = CreateCompatibleDC(hDCSrc);
671 HBITMAP16 hbClose = LoadBitmap16(0, MAKEINTRESOURCE(OBM_CLOSE) );
672 HBITMAP16 hbCopy,hb_src,hb_dest;
674 hb_src = SelectObject(hDCSrc,hbClose);
675 hbCopy = CreateCompatibleBitmap(hDCSrc,SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE);
676 hb_dest = SelectObject(hDCDest,hbCopy);
678 BitBlt(hDCDest, 0, 0, SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE,
679 hDCSrc, SYSMETRICS_CXSIZE, 0, SRCCOPY);
681 SelectObject(hDCSrc,hb_src);
682 SelectObject(hDCDest,hb_dest);
684 DeleteObject(hbClose);
686 DeleteDC(hDCDest);
687 DeleteDC(hDCSrc);
689 return hbCopy;
692 /**********************************************************************
693 * MDICascade
695 LONG MDICascade(WND* clientWnd, MDICLIENTINFO *ci)
697 MDIWCL *listTop,*listPrev;
698 INT16 delta = 0,iToPosition = 0, n = 0;
699 POINT16 pos[2];
701 if (ci->hwndChildMaximized)
702 ShowWindow( ci->hwndChildMaximized, SW_NORMAL);
704 if (ci->nActiveChildren == 0) return 0;
706 if (!(listTop = MDI_BuildWCL(clientWnd,&iToPosition))) return 0;
708 if( iToPosition < ci->nActiveChildren )
709 delta = 2 * SYSMETRICS_CYICONSPACING + SYSMETRICS_CYICON;
711 /* walk list and move windows */
712 while ( listTop )
714 dprintf_mdi(stddeb, "MDICascade: move %04x to (%d,%d) size [%d,%d]\n",
715 listTop->hChild, pos[0].x, pos[0].y, pos[1].x, pos[1].y);
717 if( listTop->hChild )
719 MDI_CalcDefaultChildPos(clientWnd, n++, pos, delta);
720 SetWindowPos(listTop->hChild, 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
721 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
724 listPrev = listTop->prev;
725 free(listTop);
726 listTop = listPrev;
729 if( iToPosition < ci->nActiveChildren )
730 ArrangeIconicWindows( clientWnd->hwndSelf );
732 return 0;
735 /**********************************************************************
736 * MDITile
739 LONG MDITile(WND* wndClient, MDICLIENTINFO *ci,WORD wParam)
741 MDIWCL *listTop,*listPrev;
742 RECT16 rect;
743 int xsize, ysize;
744 int x, y;
745 int rows, columns;
746 int r, c;
747 int i;
748 INT16 iToPosition = 0;
750 if (ci->hwndChildMaximized)
751 ShowWindow(ci->hwndChildMaximized, SW_NORMAL);
753 if (ci->nActiveChildren == 0) return 0;
755 listTop = MDI_BuildWCL(wndClient, &iToPosition);
757 dprintf_mdi(stddeb,"MDITile: %i windows to tile\n",iToPosition);
759 if( !listTop ) return 0;
761 /* tile children */
762 if ( iToPosition )
764 rect = wndClient->rectClient;
765 rows = (int) sqrt((double) iToPosition);
766 columns = iToPosition / rows;
768 if (wParam == MDITILE_HORIZONTAL) /* version >= 3.1 */
770 i=rows;
771 rows=columns; /* exchange r and c */
772 columns=i;
775 /* hack */
776 if( iToPosition != ci->nActiveChildren)
778 y = rect.bottom - 2 * SYSMETRICS_CYICONSPACING - SYSMETRICS_CYICON;
779 rect.bottom = ( y - SYSMETRICS_CYICON < rect.top )? rect.bottom: y;
782 ysize = rect.bottom / rows;
783 xsize = rect.right / columns;
785 x = 0;
786 i = 0;
788 for (c = 1; c <= columns; c++)
790 if (c == columns)
792 rows = iToPosition - i;
793 ysize = rect.bottom / rows;
796 y = 0;
797 for (r = 1; r <= rows; r++, i++)
799 /* shouldn't happen but... */
800 if( !listTop )
801 break;
803 /* skip iconized childs from tiling */
804 while (!listTop->hChild)
806 listPrev = listTop->prev;
807 free(listTop);
808 listTop = listPrev;
810 SetWindowPos(listTop->hChild, 0, x, y, xsize, ysize,
811 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
812 y += ysize;
813 listPrev = listTop->prev;
814 free(listTop);
815 listTop = listPrev;
817 x += xsize;
821 /* free the rest if any */
822 while( listTop )
824 listPrev = listTop->prev;
825 free(listTop);
826 listTop = listPrev;
829 if (iToPosition < ci->nActiveChildren )
830 ArrangeIconicWindows( wndClient->hwndSelf );
832 return 0;
835 /* ----------------------- Frame window ---------------------------- */
838 /**********************************************************************
839 * MDI_AugmentFrameMenu
841 BOOL MDI_AugmentFrameMenu(MDICLIENTINFO* ci, WND *frame, HWND hChild)
843 WND* child = WIN_FindWndPtr(hChild);
844 HGLOBAL16 handle;
845 HMENU hSysPopup = 0;
847 dprintf_mdi(stddeb,"MDI_AugmentFrameMenu: frame %p,child %04x\n",frame,hChild);
849 if( !frame->wIDmenu || !child->hSysMenu ) return 0;
851 /* create a copy of sysmenu popup and insert it into frame menu bar */
853 if (!(handle = SYSRES_LoadResource( SYSRES_MENU_SYSMENU ))) return 0;
854 hSysPopup = LoadMenuIndirect16( GlobalLock16( handle ) );
855 SYSRES_FreeResource( handle );
857 dprintf_mdi(stddeb,"\t\tgot popup %04x\n in sysmenu %04x",hSysPopup,child->hSysMenu);
859 if( !InsertMenu32A(frame->wIDmenu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
860 hSysPopup, (LPSTR)(DWORD)hBmpClose ))
861 { DestroyMenu(hSysPopup); return 0; }
863 if( !AppendMenu32A(frame->wIDmenu,MF_HELP | MF_BITMAP,
864 SC_RESTORE, (LPSTR)(DWORD)hBmpRestore ))
866 RemoveMenu(frame->wIDmenu,0,MF_BYPOSITION);
867 return 0;
870 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
871 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
872 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
874 /* redraw menu */
875 DrawMenuBar(frame->hwndSelf);
877 return 1;
880 /**********************************************************************
881 * MDI_RestoreFrameMenu
883 BOOL MDI_RestoreFrameMenu( WND *frameWnd, HWND hChild)
885 INT nItems = GetMenuItemCount(frameWnd->wIDmenu) - 1;
887 dprintf_mdi(stddeb,"MDI_RestoreFrameMenu: for child %04x\n",hChild);
889 if( GetMenuItemID(frameWnd->wIDmenu,nItems) != SC_RESTORE )
890 return 0;
893 RemoveMenu(frameWnd->wIDmenu,0,MF_BYPOSITION);
894 DeleteMenu(frameWnd->wIDmenu,nItems-1,MF_BYPOSITION);
896 DrawMenuBar(frameWnd->hwndSelf);
898 return 1;
901 /**********************************************************************
902 * MDI_UpdateFrameText
904 * used when child window is maximized/restored
906 * Note: lpTitle can be NULL
908 void MDI_UpdateFrameText(WND *frameWnd, HWND hClient, BOOL repaint, LPCSTR lpTitle)
910 char lpBuffer[MDI_MAXTITLELENGTH+1];
911 WND* clientWnd = WIN_FindWndPtr(hClient);
913 MDICLIENTINFO *ci = (MDICLIENTINFO *) clientWnd->wExtra;
915 dprintf_mdi(stddeb, "MDI: repaint %i, frameText %s\n", repaint, (lpTitle)?lpTitle:"NULL");
917 /* store new "default" title if lpTitle is not NULL */
918 if (lpTitle)
920 if (ci->frameTitle) HeapFree( SystemHeap, 0, ci->frameTitle );
921 ci->frameTitle = HEAP_strdupA( SystemHeap, 0, lpTitle );
924 if (ci->frameTitle)
926 WND* childWnd = WIN_FindWndPtr( ci->hwndChildMaximized );
928 if( childWnd && childWnd->text )
930 /* combine frame title and child title if possible */
932 LPCSTR lpBracket = " - [";
933 int i_frame_text_length = strlen(ci->frameTitle);
934 int i_child_text_length = strlen(childWnd->text);
936 lstrcpyn32A( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
938 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
940 strcat( lpBuffer, lpBracket );
942 if( i_frame_text_length + i_child_text_length + 6 < MDI_MAXTITLELENGTH )
944 strcat( lpBuffer, childWnd->text );
945 strcat( lpBuffer, "]" );
947 else
949 lstrcpyn32A( lpBuffer + i_frame_text_length + 4,
950 childWnd->text,
951 MDI_MAXTITLELENGTH - i_frame_text_length - 5 );
952 strcat( lpBuffer, "]" );
956 else
958 strncpy(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH );
959 lpBuffer[MDI_MAXTITLELENGTH]='\0';
962 else
963 lpBuffer[0] = '\0';
965 DEFWND_SetText( frameWnd, lpBuffer );
966 if( repaint == MDI_REPAINTFRAME)
967 SetWindowPos(frameWnd->hwndSelf, 0,0,0,0,0, SWP_FRAMECHANGED |
968 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
972 /* ----------------------------- Interface ---------------------------- */
975 /**********************************************************************
976 * MDIClientWndProc
978 * This function is the handler for all MDI requests.
980 LRESULT MDIClientWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
982 LPCREATESTRUCT16 cs;
983 LPCLIENTCREATESTRUCT16 ccs;
984 MDICLIENTINFO *ci;
985 RECT16 rect;
986 WND *w = WIN_FindWndPtr(hwnd);
987 WND *frameWnd = w->parent;
989 ci = (MDICLIENTINFO *) w->wExtra;
991 switch (message)
993 case WM_CREATE:
994 cs = (LPCREATESTRUCT16) PTR_SEG_TO_LIN(lParam);
995 ccs = (LPCLIENTCREATESTRUCT16) PTR_SEG_TO_LIN(cs->lpCreateParams);
997 ci->hWindowMenu = ccs->hWindowMenu;
998 ci->idFirstChild = ccs->idFirstChild;
999 ci->hwndChildMaximized = 0;
1000 ci->nActiveChildren = 0;
1001 ci->nTotalCreated = 0;
1002 ci->frameTitle = NULL;
1003 ci->sbNeedUpdate = 0;
1004 ci->self = hwnd;
1005 w->dwStyle |= WS_CLIPCHILDREN;
1007 if (!hBmpClose)
1009 hBmpClose = CreateMDIMenuBitmap();
1010 hBmpRestore = LoadBitmap16( 0, MAKEINTRESOURCE(OBM_RESTORE) );
1012 MDI_UpdateFrameText(frameWnd, hwnd, MDI_NOFRAMEREPAINT,frameWnd->text);
1014 AppendMenu32A( ccs->hWindowMenu, MF_SEPARATOR, 0, NULL );
1016 GetClientRect16(frameWnd->hwndSelf, &rect);
1017 NC_HandleNCCalcSize( w, &rect );
1018 w->rectClient = rect;
1020 dprintf_mdi(stddeb,"MDI: Client created - hwnd = %04x, idFirst = %u\n",hwnd,ci->idFirstChild);
1022 return 0;
1024 case WM_DESTROY:
1025 if( ci->hwndChildMaximized ) MDI_RestoreFrameMenu(w, frameWnd->hwndSelf);
1026 ci->idFirstChild = GetMenuItemCount(ci->hWindowMenu) - 1;
1027 ci->nActiveChildren++; /* to delete a separator */
1029 while( ci->nActiveChildren-- )
1030 DeleteMenu(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
1032 return 0;
1034 case WM_MDIACTIVATE:
1035 if( ci->hwndActiveChild != (HWND)wParam )
1036 SetWindowPos((HWND)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1037 return 0;
1039 case WM_MDICASCADE:
1040 return MDICascade(w, ci);
1042 case WM_MDICREATE:
1043 return (LONG)MDICreateChild(w, ci, hwnd, lParam );
1045 case WM_MDIDESTROY:
1046 return (LONG)MDIDestroyChild(w, ci, hwnd, (HWND)wParam, TRUE);
1048 case WM_MDIGETACTIVE:
1049 return ((LONG) ci->hwndActiveChild |
1050 ((LONG) (ci->hwndChildMaximized>0) << 16));
1052 case WM_MDIICONARRANGE:
1053 ci->sbNeedUpdate = TRUE;
1054 MDIIconArrange(hwnd);
1055 ci->sbRecalc = SB_BOTH+1;
1056 SendMessage16(hwnd,WM_MDICALCCHILDSCROLL,0,0L);
1057 return 0;
1059 case WM_MDIMAXIMIZE:
1060 ShowWindow((HWND)wParam, SW_MAXIMIZE);
1061 return 0;
1063 case WM_MDINEXT:
1064 MDI_SwitchActiveChild(hwnd, (HWND)wParam, (lParam)?1:0);
1065 break;
1067 case WM_MDIRESTORE:
1068 ShowWindow( (HWND)wParam, SW_NORMAL);
1069 return 0;
1071 case WM_MDISETMENU:
1072 #ifdef WINELIB32
1073 return (LRESULT)MDISetMenu(hwnd, FALSE, (HMENU)wParam, (HMENU)lParam);
1074 #else
1075 return (LRESULT)MDISetMenu(hwnd, wParam, LOWORD(lParam), HIWORD(lParam));
1076 #endif
1078 case WM_MDITILE:
1079 ci->sbNeedUpdate = TRUE;
1080 ShowScrollBar32(hwnd,SB_BOTH,FALSE);
1081 MDITile(w, ci,wParam);
1082 ci->sbNeedUpdate = FALSE;
1083 return 0;
1085 case WM_VSCROLL:
1086 case WM_HSCROLL:
1087 ci->sbNeedUpdate = TRUE;
1088 ScrollChildren(hwnd,message,wParam,lParam);
1089 ci->sbNeedUpdate = FALSE;
1090 return 0;
1092 case WM_SETFOCUS:
1093 if( ci->hwndActiveChild )
1095 w = WIN_FindWndPtr( ci->hwndActiveChild );
1096 if( !(w->dwStyle & WS_MINIMIZE) )
1097 SetFocus32( ci->hwndActiveChild );
1099 return 0;
1101 case WM_NCACTIVATE:
1102 if( ci->hwndActiveChild )
1103 SendMessage16(ci->hwndActiveChild, message, wParam, lParam);
1104 break;
1106 case WM_PARENTNOTIFY:
1107 if( wParam == WM_LBUTTONDOWN )
1109 POINT16 pt = MAKEPOINT16(lParam);
1110 HWND child = ChildWindowFromPoint16(hwnd, pt);
1112 dprintf_mdi(stddeb,"MDIClient: notification from %04x (%i,%i)\n",child,pt.x,pt.y);
1114 if( child && child != hwnd )
1116 WND* wnd = WIN_FindWndPtr( child );
1118 /* if we got owned popup */
1119 if( wnd->owner ) child = wnd->owner->hwndSelf;
1121 if( child != ci->hwndActiveChild )
1122 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1125 return 0;
1127 case WM_SIZE:
1128 if( ci->hwndChildMaximized )
1130 WND* child = WIN_FindWndPtr(ci->hwndChildMaximized);
1131 RECT16 rect = { 0, 0, LOWORD(lParam), HIWORD(lParam) };
1133 AdjustWindowRectEx16(&rect, child->dwStyle, 0, child->dwExStyle);
1134 MoveWindow(ci->hwndChildMaximized, rect.left, rect.top,
1135 rect.right - rect.left, rect.bottom - rect.top, 1);
1137 else
1138 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1140 break;
1142 case WM_MDICALCCHILDSCROLL:
1143 if( ci->sbNeedUpdate )
1144 if( ci->sbRecalc )
1146 CalcChildScroll(hwnd, ci->sbRecalc-1);
1147 ci->sbRecalc = ci->sbNeedUpdate = 0;
1149 return 0;
1152 return DefWindowProc16(hwnd, message, wParam, lParam);
1156 /***********************************************************************
1157 * DefFrameProc16 (USER.445)
1159 LRESULT DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient, UINT16 message,
1160 WPARAM16 wParam, LPARAM lParam )
1162 HWND childHwnd;
1163 MDICLIENTINFO* ci;
1164 WND* wndPtr;
1166 if (hwndMDIClient)
1168 switch (message)
1170 case WM_COMMAND:
1171 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1172 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1174 /* check for possible syscommands for maximized MDI child */
1176 if( wParam < ci->idFirstChild ||
1177 wParam >= ci->idFirstChild + ci->nActiveChildren )
1179 if( (wParam - 0xF000) & 0xF00F ) break;
1180 switch( wParam )
1182 case SC_SIZE:
1183 case SC_MOVE:
1184 case SC_MINIMIZE:
1185 case SC_MAXIMIZE:
1186 case SC_NEXTWINDOW:
1187 case SC_PREVWINDOW:
1188 case SC_CLOSE:
1189 case SC_RESTORE:
1190 if( ci->hwndChildMaximized )
1191 return SendMessage16( ci->hwndChildMaximized, WM_SYSCOMMAND,
1192 wParam, lParam);
1195 else
1197 childHwnd = MDI_GetChildByID( WIN_FindWndPtr(hwndMDIClient),
1198 wParam );
1199 if( childHwnd )
1200 SendMessage16(hwndMDIClient, WM_MDIACTIVATE, (WPARAM)childHwnd , 0L);
1202 break;
1204 case WM_NCACTIVATE:
1205 SendMessage16(hwndMDIClient, message, wParam, lParam);
1206 break;
1208 case WM_SETTEXT:
1209 MDI_UpdateFrameText(WIN_FindWndPtr(hwnd), hwndMDIClient,
1210 MDI_REPAINTFRAME,
1211 (LPCSTR)PTR_SEG_TO_LIN(lParam));
1212 return 0;
1214 case WM_SETFOCUS:
1215 SetFocus32(hwndMDIClient);
1216 break;
1218 case WM_SIZE:
1219 MoveWindow(hwndMDIClient, 0, 0,
1220 LOWORD(lParam), HIWORD(lParam), TRUE);
1221 break;
1223 case WM_NEXTMENU:
1225 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1226 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1228 if( !(wndPtr->parent->dwStyle & WS_MINIMIZE)
1229 && ci->hwndActiveChild && !ci->hwndChildMaximized )
1231 /* control menu is between the frame system menu and
1232 * the first entry of menu bar */
1234 if( wParam == VK_LEFT )
1235 { if( wndPtr->parent->wIDmenu != LOWORD(lParam) ) break; }
1236 else if( wParam == VK_RIGHT )
1237 { if( GetSystemMenu( wndPtr->parent->hwndSelf, 0)
1238 != LOWORD(lParam) ) break; }
1239 else break;
1241 return MAKELONG( GetSystemMenu(ci->hwndActiveChild, 0),
1242 ci->hwndActiveChild );
1244 break;
1248 return DefWindowProc16(hwnd, message, wParam, lParam);
1252 /***********************************************************************
1253 * DefFrameProc32A (USER32.121)
1255 LRESULT DefFrameProc32A( HWND32 hwnd, HWND32 hwndMDIClient, UINT32 message,
1256 WPARAM32 wParam, LPARAM lParam )
1258 if (hwndMDIClient)
1260 switch (message)
1262 case WM_COMMAND:
1263 return DefFrameProc16( hwnd, hwndMDIClient, message,
1264 (WPARAM16)wParam,
1265 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1267 case WM_NCACTIVATE:
1268 SendMessage32A(hwndMDIClient, message, wParam, lParam);
1269 break;
1271 case WM_SETTEXT:
1272 return DefFrameProc16( hwnd, hwndMDIClient, message,
1273 wParam, (LPARAM)PTR_SEG_TO_LIN(lParam) );
1275 case WM_SETFOCUS:
1276 case WM_SIZE:
1277 return DefFrameProc16( hwnd, hwndMDIClient, message,
1278 wParam, lParam );
1282 return DefWindowProc32A(hwnd, message, wParam, lParam);
1286 /***********************************************************************
1287 * DefFrameProc32W (USER32.122)
1289 LRESULT DefFrameProc32W( HWND32 hwnd, HWND32 hwndMDIClient, UINT32 message,
1290 WPARAM32 wParam, LPARAM lParam )
1292 if (hwndMDIClient)
1294 switch (message)
1296 case WM_COMMAND:
1297 return DefFrameProc16( hwnd, hwndMDIClient, message,
1298 (WPARAM16)wParam,
1299 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1301 case WM_NCACTIVATE:
1302 SendMessage32W(hwndMDIClient, message, wParam, lParam);
1303 break;
1305 case WM_SETTEXT:
1306 /* FIXME: Unicode */
1307 return DefFrameProc32A( hwnd, hwndMDIClient, message,
1308 wParam, lParam );
1310 case WM_SETFOCUS:
1311 case WM_SIZE:
1312 return DefFrameProc32A( hwnd, hwndMDIClient, message,
1313 wParam, lParam );
1317 return DefWindowProc32W( hwnd, message, wParam, lParam );
1321 /***********************************************************************
1322 * DefMDIChildProc16 (USER.447)
1324 LRESULT DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1325 WPARAM16 wParam, LPARAM lParam )
1327 MDICLIENTINFO *ci;
1328 WND *clientWnd;
1330 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1331 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1333 switch (message)
1335 case WM_SETTEXT:
1336 DefWindowProc16(hwnd, message, wParam, lParam);
1337 MDI_MenuModifyItem(clientWnd,hwnd);
1338 if( ci->hwndChildMaximized == hwnd )
1339 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1340 MDI_REPAINTFRAME, NULL );
1341 return 0;
1343 case WM_CLOSE:
1344 SendMessage16(ci->self,WM_MDIDESTROY,(WPARAM)hwnd,0L);
1345 return 0;
1347 case WM_SETFOCUS:
1348 if( ci->hwndActiveChild != hwnd )
1349 MDI_ChildActivate(clientWnd, hwnd);
1350 break;
1352 case WM_CHILDACTIVATE:
1353 MDI_ChildActivate(clientWnd, hwnd);
1354 return 0;
1356 case WM_NCPAINT:
1357 dprintf_mdi(stddeb,"DefMDIChildProc: WM_NCPAINT for %04x, active %04x\n",
1358 hwnd, ci->hwndActiveChild );
1359 break;
1361 case WM_SYSCOMMAND:
1362 switch( wParam )
1364 case SC_MOVE:
1365 if( ci->hwndChildMaximized == hwnd) return 0;
1366 break;
1367 case SC_RESTORE:
1368 case SC_MINIMIZE:
1369 WIN_FindWndPtr(hwnd)->dwStyle |= WS_SYSMENU;
1370 break;
1371 case SC_MAXIMIZE:
1372 if( ci->hwndChildMaximized == hwnd)
1373 return SendMessage16( clientWnd->parent->hwndSelf,
1374 message, wParam, lParam);
1375 WIN_FindWndPtr(hwnd)->dwStyle &= ~WS_SYSMENU;
1376 break;
1377 case SC_NEXTWINDOW:
1378 SendMessage16( ci->self, WM_MDINEXT, 0, 0);
1379 return 0;
1380 case SC_PREVWINDOW:
1381 SendMessage16( ci->self, WM_MDINEXT, 0, 1);
1382 return 0;
1384 break;
1386 case WM_GETMINMAXINFO:
1387 MDI_ChildGetMinMaxInfo(clientWnd, hwnd, (MINMAXINFO16*) PTR_SEG_TO_LIN(lParam));
1388 return 0;
1390 case WM_SETVISIBLE:
1391 if( ci->hwndChildMaximized)
1392 ci->sbNeedUpdate = 0;
1393 else
1394 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1395 break;
1397 case WM_SIZE:
1398 /* do not change */
1400 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1402 ci->hwndChildMaximized = 0;
1404 MDI_RestoreFrameMenu( clientWnd->parent, hwnd);
1405 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1406 MDI_REPAINTFRAME, NULL );
1409 if( wParam == SIZE_MAXIMIZED )
1411 HWND hMaxChild = ci->hwndChildMaximized;
1413 if( hMaxChild == hwnd ) break;
1415 if( hMaxChild)
1417 SendMessage16( hMaxChild, WM_SETREDRAW, FALSE, 0L );
1419 MDI_RestoreFrameMenu( clientWnd->parent, hMaxChild);
1420 ShowWindow( hMaxChild, SW_SHOWNOACTIVATE);
1422 SendMessage16( hMaxChild, WM_SETREDRAW, TRUE, 0L );
1425 dprintf_mdi(stddeb,"\tMDI: maximizing child %04x\n", hwnd );
1427 ci->hwndChildMaximized = hwnd; /* !!! */
1429 MDI_AugmentFrameMenu( ci, clientWnd->parent, hwnd);
1430 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1431 MDI_REPAINTFRAME, NULL );
1434 if( wParam == SIZE_MINIMIZED )
1436 HWND switchTo = MDI_GetWindow(clientWnd, hwnd, 0);
1438 if( switchTo )
1439 SendMessage16( switchTo, WM_CHILDACTIVATE, 0, 0L);
1442 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1443 break;
1445 case WM_MENUCHAR:
1447 /* MDI children don't have menu bars */
1448 PostMessage( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1449 (WPARAM)SC_KEYMENU, (LPARAM)wParam);
1450 return 0x00010000L;
1452 case WM_NEXTMENU:
1454 if( wParam == VK_LEFT ) /* switch to frame system menu */
1455 return MAKELONG( GetSystemMenu(clientWnd->parent->hwndSelf, 0),
1456 clientWnd->parent->hwndSelf );
1457 if( wParam == VK_RIGHT ) /* to frame menu bar */
1458 return MAKELONG( clientWnd->parent->wIDmenu,
1459 clientWnd->parent->hwndSelf );
1461 break;
1464 return DefWindowProc16(hwnd, message, wParam, lParam);
1468 /***********************************************************************
1469 * DefMDIChildProc32A (USER32.123)
1471 LRESULT DefMDIChildProc32A( HWND32 hwnd, UINT32 message,
1472 WPARAM32 wParam, LPARAM lParam )
1474 MDICLIENTINFO *ci;
1475 WND *clientWnd;
1477 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1478 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1480 switch (message)
1482 case WM_SETTEXT:
1483 DefWindowProc32A(hwnd, message, wParam, lParam);
1484 MDI_MenuModifyItem(clientWnd,hwnd);
1485 if( ci->hwndChildMaximized == hwnd )
1486 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1487 MDI_REPAINTFRAME, NULL );
1488 return 0;
1490 case WM_GETMINMAXINFO:
1492 MINMAXINFO16 mmi;
1493 STRUCT32_MINMAXINFO32to16( (MINMAXINFO32 *)lParam, &mmi );
1494 MDI_ChildGetMinMaxInfo( clientWnd, hwnd, &mmi );
1495 STRUCT32_MINMAXINFO16to32( &mmi, (MINMAXINFO32 *)lParam );
1497 return 0;
1499 case WM_MENUCHAR:
1501 /* MDI children don't have menu bars */
1502 PostMessage( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1503 (WPARAM)SC_KEYMENU, (LPARAM)LOWORD(wParam) );
1504 return 0x00010000L;
1506 case WM_CLOSE:
1507 case WM_SETFOCUS:
1508 case WM_CHILDACTIVATE:
1509 case WM_NCPAINT:
1510 case WM_SYSCOMMAND:
1511 case WM_SETVISIBLE:
1512 case WM_SIZE:
1513 case WM_NEXTMENU:
1514 return DefMDIChildProc16( hwnd, message, (WPARAM16)wParam, lParam );
1516 return DefWindowProc32A(hwnd, message, wParam, lParam);
1520 /***********************************************************************
1521 * DefMDIChildProc32W (USER32.124)
1523 LRESULT DefMDIChildProc32W( HWND32 hwnd, UINT32 message,
1524 WPARAM32 wParam, LPARAM lParam )
1526 MDICLIENTINFO *ci;
1527 WND *clientWnd;
1529 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1530 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1532 switch (message)
1534 case WM_SETTEXT:
1535 DefWindowProc32W(hwnd, message, wParam, lParam);
1536 MDI_MenuModifyItem(clientWnd,hwnd);
1537 if( ci->hwndChildMaximized == hwnd )
1538 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1539 MDI_REPAINTFRAME, NULL );
1540 return 0;
1542 case WM_GETMINMAXINFO:
1543 case WM_MENUCHAR:
1544 case WM_CLOSE:
1545 case WM_SETFOCUS:
1546 case WM_CHILDACTIVATE:
1547 case WM_NCPAINT:
1548 case WM_SYSCOMMAND:
1549 case WM_SETVISIBLE:
1550 case WM_SIZE:
1551 case WM_NEXTMENU:
1552 return DefMDIChildProc32A( hwnd, message, (WPARAM16)wParam, lParam );
1554 return DefWindowProc32W(hwnd, message, wParam, lParam);
1558 /**********************************************************************
1559 * TranslateMDISysAccel (USER.451)
1562 BOOL TranslateMDISysAccel(HWND hwndClient, LPMSG16 msg)
1564 WND* clientWnd = WIN_FindWndPtr( hwndClient);
1565 WND* wnd;
1566 MDICLIENTINFO *ci = NULL;
1567 WPARAM wParam = 0;
1569 if( (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) || !clientWnd )
1570 return 0;
1572 ci = (MDICLIENTINFO*) clientWnd->wExtra;
1573 wnd = WIN_FindWndPtr(ci->hwndActiveChild);
1575 if( !wnd ) return 0;
1577 if( wnd->dwStyle & WS_DISABLED ) return 0;
1579 if ((GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
1580 switch( msg->wParam )
1582 case VK_F6:
1583 case VK_SEPARATOR:
1584 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 )? SC_NEXTWINDOW: SC_PREVWINDOW;
1585 break;
1586 case VK_RBUTTON:
1587 wParam = SC_CLOSE;
1588 break;
1589 default:
1590 return 0;
1592 else
1593 return 0;
1595 dprintf_mdi(stddeb,"TranslateMDISysAccel: wParam = %04x\n", wParam);
1597 SendMessage16(ci->hwndActiveChild,WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
1598 return 1;
1602 /***********************************************************************
1603 * CalcChildScroll (USER.462)
1605 void CalcChildScroll( HWND hwnd, WORD scroll )
1607 RECT16 childRect, clientRect;
1608 INT vmin, vmax, hmin, hmax, vpos, hpos;
1609 BOOL noscroll = FALSE;
1610 WND *pWnd, *Wnd;
1612 if (!(Wnd = pWnd = WIN_FindWndPtr( hwnd ))) return;
1613 GetClientRect16( hwnd, &clientRect );
1614 SetRectEmpty16( &childRect );
1616 for ( pWnd = pWnd->child; pWnd; pWnd = pWnd->next )
1618 UnionRect16( &childRect, &pWnd->rectWindow, &childRect );
1619 if( pWnd->dwStyle & WS_MAXIMIZE )
1620 noscroll = TRUE;
1622 UnionRect16( &childRect, &clientRect, &childRect );
1624 /* jump through the hoops to prevent excessive flashing
1627 hmin = childRect.left; hmax = childRect.right - clientRect.right;
1628 hpos = clientRect.left - childRect.left;
1629 vmin = childRect.top; vmax = childRect.bottom - clientRect.bottom;
1630 vpos = clientRect.top - childRect.top;
1632 if( noscroll )
1633 ShowScrollBar32(hwnd, SB_BOTH, FALSE);
1634 else
1635 switch( scroll )
1637 case SB_HORZ:
1638 vpos = hpos; vmin = hmin; vmax = hmax;
1639 case SB_VERT:
1640 SetScrollPos32(hwnd, scroll, vpos, FALSE);
1641 SetScrollRange32(hwnd, scroll, vmin, vmax, TRUE);
1642 break;
1643 case SB_BOTH:
1644 SCROLL_SetNCSbState( Wnd, vmin, vmax, vpos,
1645 hmin, hmax, hpos);
1646 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1647 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1651 /***********************************************************************
1652 * ScrollChildren (USER.463)
1654 void ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1656 WND *wndPtr = WIN_FindWndPtr(hWnd);
1657 short newPos=-1;
1658 short curPos;
1659 short length;
1660 INT32 minPos;
1661 INT32 maxPos;
1662 short shift;
1664 if( !wndPtr ) return;
1666 if( uMsg == WM_HSCROLL )
1668 GetScrollRange32(hWnd,SB_HORZ,&minPos,&maxPos);
1669 curPos = GetScrollPos32(hWnd,SB_HORZ);
1670 length = (wndPtr->rectClient.right - wndPtr->rectClient.left)/2;
1671 shift = SYSMETRICS_CYHSCROLL;
1673 else if( uMsg == WM_VSCROLL )
1675 GetScrollRange32(hWnd,SB_VERT,&minPos,&maxPos);
1676 curPos = GetScrollPos32(hWnd,SB_VERT);
1677 length = (wndPtr->rectClient.bottom - wndPtr->rectClient.top)/2;
1678 shift = SYSMETRICS_CXVSCROLL;
1680 else return;
1682 switch( wParam )
1684 case SB_LINEUP:
1685 newPos = curPos - shift;
1686 break;
1687 case SB_LINEDOWN:
1688 newPos = curPos + shift;
1689 break;
1690 case SB_PAGEUP:
1691 newPos = curPos - length;
1692 break;
1693 case SB_PAGEDOWN:
1694 newPos = curPos + length;
1695 break;
1697 case SB_THUMBPOSITION:
1698 newPos = LOWORD(lParam);
1699 break;
1701 case SB_THUMBTRACK:
1702 return;
1704 case SB_TOP:
1705 newPos = minPos;
1706 break;
1707 case SB_BOTTOM:
1708 newPos = maxPos;
1709 break;
1710 case SB_ENDSCROLL:
1711 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
1712 return;
1715 if( newPos > maxPos )
1716 newPos = maxPos;
1717 else if( newPos < minPos )
1718 newPos = minPos;
1720 SetScrollPos32(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
1722 if( uMsg == WM_VSCROLL )
1723 ScrollWindow(hWnd ,0 ,curPos - newPos, NULL, NULL);
1724 else
1725 ScrollWindow(hWnd ,curPos - newPos, 0, NULL, NULL);