Release 970509
[wine/multimedia.git] / windows / mdi.c
blobe08e08db6a15e415eb0e8ce98e4f3bc828ed31ce
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 HBITMAP16 hBmpClose = 0;
35 static HBITMAP16 hBmpRestore = 0;
37 DWORD SCROLL_SetNCSbState(WND*,int,int,int,int,int,int);
39 /* ----------------- declarations ----------------- */
40 static void MDI_UpdateFrameText(WND *, HWND16, BOOL32, LPCSTR);
41 static BOOL32 MDI_AugmentFrameMenu(MDICLIENTINFO*, WND *, HWND16);
42 static BOOL32 MDI_RestoreFrameMenu(WND *, HWND16);
44 static LONG MDI_ChildActivate(WND* ,HWND16 );
46 /* -------- Miscellaneous service functions ----------
48 * MDI_GetChildByID
51 static HWND16 MDI_GetChildByID(WND* wndPtr,int id)
53 for (wndPtr = wndPtr->child; wndPtr; wndPtr = wndPtr->next)
54 if (wndPtr->wIDmenu == id) return wndPtr->hwndSelf;
55 return 0;
58 static void MDI_PostUpdate(HWND16 hwnd, MDICLIENTINFO* ci, WORD recalc)
60 if( !ci->sbNeedUpdate )
62 ci->sbNeedUpdate = TRUE;
63 PostMessage16( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
65 ci->sbRecalc = recalc;
68 /**********************************************************************
69 * MDI_MenuAppendItem
71 #ifdef SUPERFLUOUS_FUNCTIONS
72 static BOOL32 MDI_MenuAppendItem(WND *clientWnd, HWND16 hWndChild)
74 char buffer[128];
75 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
76 WND *wndPtr = WIN_FindWndPtr(hWndChild);
77 int n = sprintf(buffer, "%d ",
78 clientInfo->nActiveChildren);
80 if( !clientInfo->hWindowMenu ) return 0;
82 if (wndPtr->text) strncpy(buffer + n, wndPtr->text, sizeof(buffer) - n - 1);
83 return AppendMenu32A( clientInfo->hWindowMenu, MF_STRING,
84 wndPtr->wIDmenu, buffer );
86 #endif
88 /**********************************************************************
89 * MDI_MenuModifyItem
91 static BOOL32 MDI_MenuModifyItem(WND* clientWnd, HWND16 hWndChild )
93 char buffer[128];
94 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
95 WND *wndPtr = WIN_FindWndPtr(hWndChild);
96 UINT32 n = sprintf(buffer, "%d ",
97 wndPtr->wIDmenu - clientInfo->idFirstChild + 1);
98 BOOL32 bRet = 0;
100 if( !clientInfo->hWindowMenu ) return 0;
102 if (wndPtr->text) lstrcpyn32A(buffer + n, wndPtr->text, sizeof(buffer) - n );
104 n = GetMenuState32(clientInfo->hWindowMenu,wndPtr->wIDmenu ,MF_BYCOMMAND);
105 bRet = ModifyMenu32A(clientInfo->hWindowMenu , wndPtr->wIDmenu,
106 MF_BYCOMMAND | MF_STRING, wndPtr->wIDmenu, buffer );
107 CheckMenuItem32(clientInfo->hWindowMenu ,wndPtr->wIDmenu , n & MF_CHECKED);
108 return bRet;
111 /**********************************************************************
112 * MDI_MenuDeleteItem
114 static BOOL32 MDI_MenuDeleteItem(WND* clientWnd, HWND16 hWndChild )
116 char buffer[128];
117 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
118 WND *wndPtr = WIN_FindWndPtr(hWndChild);
119 UINT32 index = 0,id,n;
121 if( !clientInfo->nActiveChildren ||
122 !clientInfo->hWindowMenu ) return 0;
124 id = wndPtr->wIDmenu;
125 DeleteMenu32(clientInfo->hWindowMenu,id,MF_BYCOMMAND);
127 /* walk the rest of MDI children to prevent gaps in the id
128 * sequence and in the menu child list */
130 for( index = id+1; index <= clientInfo->nActiveChildren +
131 clientInfo->idFirstChild; index++ )
133 wndPtr = WIN_FindWndPtr(MDI_GetChildByID(clientWnd,index));
134 if( !wndPtr )
136 dprintf_mdi(stddeb,"MDIMenuDeleteItem: no window for id=%i\n",index);
137 continue;
140 /* set correct id */
141 wndPtr->wIDmenu--;
143 n = sprintf(buffer, "%d ",index - clientInfo->idFirstChild);
144 if (wndPtr->text)
145 lstrcpyn32A(buffer + n, wndPtr->text, sizeof(buffer) - n );
147 /* change menu */
148 ModifyMenu32A(clientInfo->hWindowMenu ,index ,MF_BYCOMMAND | MF_STRING,
149 index - 1 , buffer );
151 return 1;
154 /**********************************************************************
155 * MDI_GetWindow
157 * returns "activateable" child or zero
159 static HWND16 MDI_GetWindow(WND *clientWnd, HWND16 hWnd, WORD wTo )
161 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
162 WND *wndPtr, *pWnd, *pWndLast;
164 if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
166 if( !(wndPtr = WIN_FindWndPtr(hWnd)) ) return 0;
168 pWnd = wndPtr;
169 pWndLast = NULL;
170 for (;;)
172 pWnd = pWnd->next;
173 if (!pWnd) pWnd = wndPtr->parent->child;
174 if (pWnd == wndPtr) /* not found */
176 if (!wTo || !pWndLast) return 0;
177 break;
180 /* we are not interested in owned popups */
181 if ( !pWnd->owner &&
182 (pWnd->dwStyle & WS_VISIBLE) &&
183 !(pWnd->dwStyle & WS_DISABLED)) /* found one */
185 pWndLast = pWnd;
186 if (!wTo) break;
189 return pWndLast ? pWndLast->hwndSelf : 0;
192 /**********************************************************************
193 * MDI_CalcDefaultChildPos
195 * It seems that default height is 2/3 of client rect
197 static void MDI_CalcDefaultChildPos( WND* w, WORD n, LPPOINT16 lpPos,
198 INT32 delta)
200 RECT16 rect = w->rectClient;
201 INT32 spacing = GetSystemMetrics32(SM_CYCAPTION) +
202 GetSystemMetrics32(SM_CYFRAME) - 1;
203 INT32 nstagger;
205 if( rect.bottom - rect.top - delta >= spacing )
206 rect.bottom -= delta;
208 nstagger = (rect.bottom - rect.top)/(3*spacing);
209 lpPos[1].x = (rect.right - rect.left - nstagger*spacing);
210 lpPos[1].y = (rect.bottom - rect.top - nstagger*spacing);
211 lpPos[0].x = lpPos[0].y = spacing*(n%(nstagger+1));
214 /**********************************************************************
215 * MDISetMenu
217 static HMENU16 MDISetMenu(HWND16 hwnd, BOOL32 fRefresh, HMENU16 hmenuFrame,
218 HMENU16 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 HWND16 hwndFrame = GetParent16(hwnd);
231 HMENU32 oldFrameMenu = GetMenu32(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 INT32 i = GetMenuItemCount32(ci->hWindowMenu) - 1;
242 INT32 pos = GetMenuItemCount32(hmenuWindow) + 1;
244 AppendMenu32A( hmenuWindow, MF_SEPARATOR, 0, NULL);
246 if( ci->nActiveChildren )
248 INT32 j = i - ci->nActiveChildren + 1;
249 char buffer[100];
250 UINT32 id,state;
252 for( ; i >= j ; i-- )
254 id = GetMenuItemID32(ci->hWindowMenu,i );
255 state = GetMenuState32(ci->hWindowMenu,i,MF_BYPOSITION);
257 GetMenuString32A(ci->hWindowMenu, i, buffer, 100, MF_BYPOSITION);
259 DeleteMenu32(ci->hWindowMenu, i , MF_BYPOSITION);
260 InsertMenu32A(hmenuWindow, pos, MF_BYPOSITION | MF_STRING,
261 id, buffer);
262 CheckMenuItem32(hmenuWindow ,pos , MF_BYPOSITION | (state & MF_CHECKED));
266 /* remove separator */
267 DeleteMenu32(ci->hWindowMenu, i, MF_BYPOSITION);
269 ci->hWindowMenu = hmenuWindow;
272 if( hmenuFrame && hmenuFrame!=oldFrameMenu)
274 SetMenu32(hwndFrame, hmenuFrame);
275 if( ci->hwndChildMaximized )
276 MDI_AugmentFrameMenu(ci, w->parent, ci->hwndChildMaximized );
277 return oldFrameMenu;
281 return 0;
284 /**********************************************************************
285 * MDIIconArrange
287 static WORD MDIIconArrange(HWND16 parent)
289 return ArrangeIconicWindows16(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 static HWND16 MDICreateChild( WND *w, MDICLIENTINFO *ci, HWND16 parent,
303 LPMDICREATESTRUCT16 cs, LPARAM lParam )
305 POINT16 pos[2];
306 DWORD style = cs->style | (WS_CHILD | WS_CLIPSIBLINGS);
307 HWND16 hwnd, hwndMax = 0;
308 WORD wIDmenu = ci->idFirstChild + ci->nActiveChildren;
309 char lpstrDef[]="junk!";
311 dprintf_mdi(stdnimp,"MDICreateChild: origin %i,%i - dim %i,%i, style %08x\n",
312 cs->x, cs->y, cs->cx, cs->cy, (unsigned)cs->style);
313 /* calculate placement */
314 MDI_CalcDefaultChildPos(w, ci->nTotalCreated++, pos, 0);
316 if( cs->cx == CW_USEDEFAULT16 || !cs->cx )
317 cs->cx = pos[1].x;
318 if( cs->cy == CW_USEDEFAULT16 || !cs->cy )
319 cs->cy = pos[1].y;
321 if( cs->x == CW_USEDEFAULT16 )
323 cs->x = pos[0].x;
324 cs->y = pos[0].y;
327 /* restore current maximized child */
328 if( style & WS_VISIBLE && ci->hwndChildMaximized )
330 if( style & WS_MAXIMIZE )
331 SendMessage16(w->hwndSelf, WM_SETREDRAW, FALSE, 0L );
332 hwndMax = ci->hwndChildMaximized;
333 ShowWindow16( hwndMax, SW_SHOWNOACTIVATE );
334 if( style & WS_MAXIMIZE )
335 SendMessage16(w->hwndSelf, WM_SETREDRAW, TRUE, 0L );
338 /* this menu is needed to set a check mark in MDI_ChildActivate */
339 AppendMenu32A(ci->hWindowMenu ,MF_STRING ,wIDmenu, lpstrDef );
341 ci->nActiveChildren++;
343 /* fix window style */
344 if( !(w->dwStyle & MDIS_ALLCHILDSTYLES) )
346 style &= (WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZE | WS_MAXIMIZE |
347 WS_CLIPCHILDREN | WS_DISABLED | WS_VSCROLL | WS_HSCROLL );
348 style |= (WS_VISIBLE | WS_OVERLAPPEDWINDOW);
351 hwnd = CreateWindow16( (LPCSTR)PTR_SEG_TO_LIN(cs->szClass),
352 (LPCSTR)PTR_SEG_TO_LIN(cs->szTitle), style,
353 cs->x, cs->y, cs->cx, cs->cy, parent,
354 (HMENU16)wIDmenu, w->hInstance,
355 (LPVOID)lParam);
357 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
359 if (hwnd)
361 WND* wnd = WIN_FindWndPtr( hwnd );
363 MDI_MenuModifyItem(w ,hwnd);
364 if( wnd->dwStyle & WS_MINIMIZE && ci->hwndActiveChild )
365 ShowWindow16( hwnd, SW_SHOWMINNOACTIVE );
366 else
368 SetWindowPos32( hwnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE );
370 /* Set maximized state here in case hwnd didn't receive WM_SIZE
371 * during CreateWindow - bad!
374 if( wnd->dwStyle & WS_MAXIMIZE && !ci->hwndChildMaximized )
376 ci->hwndChildMaximized = wnd->hwndSelf;
377 MDI_AugmentFrameMenu( ci, w->parent, hwnd );
378 MDI_UpdateFrameText( w->parent, ci->self, MDI_REPAINTFRAME, NULL );
381 dprintf_mdi(stddeb, "MDICreateChild: created child - %04x\n",hwnd);
383 else
385 ci->nActiveChildren--;
386 DeleteMenu32(ci->hWindowMenu,wIDmenu,MF_BYCOMMAND);
387 if( IsWindow32(hwndMax) )
388 ShowWindow32(hwndMax, SW_SHOWMAXIMIZED);
391 return hwnd;
394 /**********************************************************************
395 * MDI_ChildGetMinMaxInfo
397 static void MDI_ChildGetMinMaxInfo( WND* clientWnd, HWND16 hwnd,
398 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;
413 dprintf_mdi(stddeb,"\tChildMinMaxInfo: max rect (%i,%i - %i, %i)\n",
414 rect.left,rect.top,rect.right,rect.bottom);
418 /**********************************************************************
419 * MDI_SwitchActiveChild
421 * Notes: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
422 * being activated
424 * wTo is basically lParam of WM_MDINEXT message or explicit
425 * window handle
427 static void MDI_SwitchActiveChild( HWND16 clientHwnd, HWND16 childHwnd,
428 BOOL32 wTo )
430 WND *w = WIN_FindWndPtr(clientHwnd);
431 HWND16 hwndTo = 0;
432 HWND16 hwndPrev = 0;
433 MDICLIENTINFO *ci;
435 hwndTo = MDI_GetWindow(w,childHwnd,(WORD)wTo);
437 ci = (MDICLIENTINFO *) w->wExtra;
439 dprintf_mdi(stddeb, "MDI_SwitchActiveChild: from %04x, to %04x\n",childHwnd,hwndTo);
441 if ( !hwndTo ) return;
443 hwndPrev = ci->hwndActiveChild;
445 if ( hwndTo != hwndPrev )
447 BOOL32 bOptimize = 0;
449 if( ci->hwndChildMaximized )
451 bOptimize = 1;
452 w->dwStyle &= ~WS_VISIBLE;
455 SetWindowPos32( hwndTo, HWND_TOP, 0, 0, 0, 0,
456 SWP_NOMOVE | SWP_NOSIZE );
457 if( !wTo && hwndPrev )
459 SetWindowPos32( hwndPrev, HWND_BOTTOM, 0, 0, 0, 0,
460 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
463 if( bOptimize )
464 ShowWindow16( clientHwnd, SW_SHOW );
469 /**********************************************************************
470 * MDIDestroyChild
472 static HWND16 MDIDestroyChild( WND *w_parent, MDICLIENTINFO *ci, HWND16 parent,
473 HWND16 child, BOOL32 flagDestroy )
475 WND *childPtr = WIN_FindWndPtr(child);
477 if( childPtr )
479 if( child == ci->hwndActiveChild )
481 MDI_SwitchActiveChild(parent,child,0);
483 if( child == ci->hwndActiveChild )
485 ShowWindow16( child, SW_HIDE);
486 if( child == ci->hwndChildMaximized )
488 MDI_RestoreFrameMenu(w_parent->parent, child);
489 ci->hwndChildMaximized = 0;
490 MDI_UpdateFrameText(w_parent->parent,parent,TRUE,NULL);
493 MDI_ChildActivate(w_parent,0);
495 MDI_MenuDeleteItem(w_parent, child);
498 ci->nActiveChildren--;
500 dprintf_mdi(stddeb,"MDIDestroyChild: child destroyed - %04x\n",child);
502 if (flagDestroy)
504 MDI_PostUpdate(GetParent16(child), ci, SB_BOTH+1);
505 DestroyWindow32(child);
509 return 0;
513 /**********************************************************************
514 * MDI_ChildActivate
516 * Note: hWndChild is NULL when last child is being destroyed
518 static LONG MDI_ChildActivate( WND *clientPtr, HWND16 hWndChild )
520 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientPtr->wExtra;
521 HWND16 prevActiveWnd = clientInfo->hwndActiveChild;
522 WND *wndPtr = WIN_FindWndPtr( hWndChild );
523 WND *wndPrev = WIN_FindWndPtr( prevActiveWnd );
524 BOOL32 isActiveFrameWnd = 0;
526 if( hWndChild == prevActiveWnd ) return 0L;
528 if( wndPtr )
529 if( wndPtr->dwStyle & WS_DISABLED ) return 0L;
531 dprintf_mdi(stddeb,"MDI_ChildActivate: %04x\n", hWndChild);
533 if( GetActiveWindow32() == clientPtr->parent->hwndSelf )
534 isActiveFrameWnd = TRUE;
536 /* deactivate prev. active child */
537 if( wndPrev )
539 wndPrev->dwStyle |= WS_SYSMENU;
540 SendMessage16( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
542 #ifdef WINELIB32
543 SendMessage32A( prevActiveWnd, WM_MDIACTIVATE, (WPARAM32)prevActiveWnd,
544 (LPARAM)hWndChild);
545 #else
547 SendMessage16( prevActiveWnd, WM_MDIACTIVATE, FALSE,
548 MAKELONG(hWndChild,prevActiveWnd));
549 #endif
550 /* uncheck menu item */
551 if( clientInfo->hWindowMenu )
552 CheckMenuItem32( clientInfo->hWindowMenu,
553 wndPrev->wIDmenu, 0);
556 /* set appearance */
557 if( clientInfo->hwndChildMaximized )
558 if( clientInfo->hwndChildMaximized != hWndChild )
559 if( hWndChild )
561 clientInfo->hwndActiveChild = hWndChild;
562 ShowWindow16( hWndChild, SW_SHOWMAXIMIZED);
564 else
565 ShowWindow16( clientInfo->hwndActiveChild,
566 SW_SHOWNORMAL );
568 clientInfo->hwndActiveChild = hWndChild;
570 /* check if we have any children left */
571 if( !hWndChild )
573 if( isActiveFrameWnd )
574 SetFocus32( clientInfo->self );
575 return 0;
578 /* check menu item */
579 if( clientInfo->hWindowMenu )
580 CheckMenuItem32( clientInfo->hWindowMenu,
581 wndPtr->wIDmenu, MF_CHECKED);
583 /* bring active child to the top */
584 SetWindowPos32( hWndChild, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
586 if( isActiveFrameWnd )
588 SendMessage16( hWndChild, WM_NCACTIVATE, TRUE, 0L);
589 if( GetFocus32() == clientInfo->self )
590 SendMessage16( clientInfo->self, WM_SETFOCUS,
591 (WPARAM16)clientInfo->self, 0L );
592 else
593 SetFocus32( clientInfo->self );
596 #ifdef WINELIB32
597 SendMessage32A( hWndChild, WM_MDIACTIVATE, (WPARAM32)hWndChild,
598 (LPARAM)prevActiveWnd );
599 #else
600 SendMessage16( hWndChild, WM_MDIACTIVATE, TRUE,
601 MAKELONG(hWndChild,prevActiveWnd));
602 #endif
604 return 1;
607 /**********************************************************************
608 * MDI_BuildWCL
610 * iTotal returns number of children available for tiling or cascading
612 static MDIWCL* MDI_BuildWCL(WND* clientWnd, UINT16* iTotal)
614 MDIWCL *listTop,*listNext;
615 WND *childWnd;
617 if (!(listTop = (MDIWCL*)malloc( sizeof(MDIWCL) ))) return NULL;
619 listTop->hChild = clientWnd->child ? clientWnd->child->hwndSelf : 0;
620 listTop->prev = NULL;
621 *iTotal = 1;
623 /* build linked list from top child to bottom */
625 childWnd = WIN_FindWndPtr( listTop->hChild );
626 while( childWnd && childWnd->next )
628 listNext = (MDIWCL*)xmalloc(sizeof(MDIWCL));
630 /* FIXME: pay attention to MDITILE_SKIPDISABLED
631 * when WIN_ISWIN32 is set.
633 if( (childWnd->dwStyle & WS_DISABLED) ||
634 (childWnd->dwStyle & WS_MINIMIZE) ||
635 !(childWnd->dwStyle & WS_VISIBLE) )
637 listTop->hChild = 0;
638 (*iTotal)--;
641 listNext->hChild = childWnd->next->hwndSelf;
642 listNext->prev = listTop;
643 listTop = listNext;
644 (*iTotal)++;
646 childWnd = childWnd->next;
649 if( (childWnd->dwStyle & WS_DISABLED) ||
650 (childWnd->dwStyle & WS_MINIMIZE) ||
651 !(childWnd->dwStyle & WS_VISIBLE) )
653 listTop->hChild = 0;
654 (*iTotal)--;
657 return listTop;
661 /* -------------------- MDI client window functions ------------------- */
663 /**********************************************************************
664 * CreateMDIMenuBitmap
666 static HBITMAP16 CreateMDIMenuBitmap(void)
668 HDC32 hDCSrc = CreateCompatibleDC32(0);
669 HDC32 hDCDest = CreateCompatibleDC32(hDCSrc);
670 HBITMAP16 hbClose = LoadBitmap16(0, MAKEINTRESOURCE(OBM_CLOSE) );
671 HBITMAP16 hbCopy,hb_src,hb_dest;
673 hb_src = SelectObject32(hDCSrc,hbClose);
674 hbCopy = CreateCompatibleBitmap32(hDCSrc,SYSMETRICS_CXSIZE,SYSMETRICS_CYSIZE);
675 hb_dest = SelectObject32(hDCDest,hbCopy);
677 BitBlt32(hDCDest, 0, 0, SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE,
678 hDCSrc, SYSMETRICS_CXSIZE, 0, SRCCOPY);
680 SelectObject32(hDCSrc,hb_src);
681 SelectObject32(hDCDest,hb_dest);
683 DeleteObject32(hbClose);
685 DeleteDC32(hDCDest);
686 DeleteDC32(hDCSrc);
688 return hbCopy;
691 /**********************************************************************
692 * MDICascade
694 static LONG MDICascade(WND* clientWnd, MDICLIENTINFO *ci)
696 MDIWCL *listTop,*listPrev;
697 INT16 delta = 0, n = 0;
698 UINT16 iToPosition = 0;
699 POINT16 pos[2];
701 if (ci->hwndChildMaximized)
702 ShowWindow16( 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 SetWindowPos32(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 ArrangeIconicWindows32( clientWnd->hwndSelf );
732 return 0;
735 /**********************************************************************
736 * MDITile
739 static 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 UINT16 iToPosition = 0;
750 if (ci->hwndChildMaximized)
751 ShowWindow16(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 SetWindowPos32(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 ArrangeIconicWindows32( wndClient->hwndSelf );
832 return 0;
835 /* ----------------------- Frame window ---------------------------- */
838 /**********************************************************************
839 * MDI_AugmentFrameMenu
841 static BOOL32 MDI_AugmentFrameMenu( MDICLIENTINFO* ci, WND *frame,
842 HWND16 hChild )
844 WND* child = WIN_FindWndPtr(hChild);
845 HMENU16 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 (!(hSysPopup = LoadMenuIndirect32A(SYSRES_GetResPtr(SYSRES_MENU_SYSMENU))))
854 return 0;
856 dprintf_mdi(stddeb,"\t\tgot popup %04x\n in sysmenu %04x",hSysPopup,child->hSysMenu);
858 if( !InsertMenu32A(frame->wIDmenu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
859 hSysPopup, (LPSTR)(DWORD)hBmpClose ))
860 { DestroyMenu32(hSysPopup); return 0; }
862 if( !AppendMenu32A(frame->wIDmenu,MF_HELP | MF_BITMAP,
863 SC_RESTORE, (LPSTR)(DWORD)hBmpRestore ))
865 RemoveMenu32(frame->wIDmenu,0,MF_BYPOSITION);
866 return 0;
869 EnableMenuItem32(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
870 EnableMenuItem32(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
871 EnableMenuItem32(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
873 /* redraw menu */
874 DrawMenuBar32(frame->hwndSelf);
876 return 1;
879 /**********************************************************************
880 * MDI_RestoreFrameMenu
882 static BOOL32 MDI_RestoreFrameMenu( WND *frameWnd, HWND16 hChild )
884 INT32 nItems = GetMenuItemCount32(frameWnd->wIDmenu) - 1;
886 dprintf_mdi(stddeb,"MDI_RestoreFrameMenu: for child %04x\n",hChild);
888 if( GetMenuItemID32(frameWnd->wIDmenu,nItems) != SC_RESTORE )
889 return 0;
892 RemoveMenu32(frameWnd->wIDmenu,0,MF_BYPOSITION);
893 DeleteMenu32(frameWnd->wIDmenu,nItems-1,MF_BYPOSITION);
895 DrawMenuBar32(frameWnd->hwndSelf);
897 return 1;
900 /**********************************************************************
901 * MDI_UpdateFrameText
903 * used when child window is maximized/restored
905 * Note: lpTitle can be NULL
907 static void MDI_UpdateFrameText( WND *frameWnd, HWND16 hClient,
908 BOOL32 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 SetWindowPos32(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(HWND16 hwnd, UINT16 message, WPARAM16 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;
988 INT32 nItems;
990 ci = (MDICLIENTINFO *) w->wExtra;
992 switch (message)
994 case WM_CREATE:
996 cs = (LPCREATESTRUCT16) PTR_SEG_TO_LIN(lParam);
998 /* Translation layer doesn't know what's in the cs->lpCreateParams
999 * so we have to keep track of what environment we're in. */
1001 if( w->flags & WIN_ISWIN32 )
1002 ccs = (LPCLIENTCREATESTRUCT16) cs->lpCreateParams;
1003 else
1004 ccs = (LPCLIENTCREATESTRUCT16) PTR_SEG_TO_LIN(cs->lpCreateParams);
1006 ci->hWindowMenu = ccs->hWindowMenu;
1007 ci->idFirstChild = ccs->idFirstChild;
1008 ci->hwndChildMaximized = 0;
1009 ci->nActiveChildren = 0;
1010 ci->nTotalCreated = 0;
1011 ci->frameTitle = NULL;
1012 ci->sbNeedUpdate = 0;
1013 ci->self = hwnd;
1014 w->dwStyle |= WS_CLIPCHILDREN;
1016 if (!hBmpClose)
1018 hBmpClose = CreateMDIMenuBitmap();
1019 hBmpRestore = LoadBitmap16( 0, MAKEINTRESOURCE(OBM_RESTORE) );
1021 MDI_UpdateFrameText(frameWnd, hwnd, MDI_NOFRAMEREPAINT,frameWnd->text);
1023 AppendMenu32A( ccs->hWindowMenu, MF_SEPARATOR, 0, NULL );
1025 GetClientRect16(frameWnd->hwndSelf, &rect);
1026 NC_HandleNCCalcSize( w, &rect );
1027 w->rectClient = rect;
1029 dprintf_mdi(stddeb,"MDI: Client created - hwnd = %04x, idFirst = %u\n",hwnd,ci->idFirstChild);
1031 return 0;
1033 case WM_DESTROY:
1034 if( ci->hwndChildMaximized ) MDI_RestoreFrameMenu(w, frameWnd->hwndSelf);
1035 if((nItems = GetMenuItemCount32(ci->hWindowMenu)) > 0) {
1036 ci->idFirstChild = nItems - 1;
1037 ci->nActiveChildren++; /* to delete a separator */
1038 while( ci->nActiveChildren-- )
1039 DeleteMenu32(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
1041 return 0;
1043 case WM_MDIACTIVATE:
1044 if( ci->hwndActiveChild != (HWND16)wParam )
1045 SetWindowPos32((HWND32)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1046 return 0;
1048 case WM_MDICASCADE:
1049 return MDICascade(w, ci);
1051 case WM_MDICREATE:
1052 if( lParam )
1054 MDICREATESTRUCT16* cs = (MDICREATESTRUCT16*) PTR_SEG_TO_LIN(lParam);
1055 return (LONG)MDICreateChild(w, ci, hwnd, cs, lParam );
1057 return 0;
1059 case WM_MDIDESTROY:
1060 return (LONG)MDIDestroyChild(w, ci, hwnd, (HWND32)wParam, TRUE);
1062 case WM_MDIGETACTIVE:
1063 return ((LONG) ci->hwndActiveChild |
1064 ((LONG) (ci->hwndChildMaximized>0) << 16));
1066 case WM_MDIICONARRANGE:
1067 ci->sbNeedUpdate = TRUE;
1068 MDIIconArrange(hwnd);
1069 ci->sbRecalc = SB_BOTH+1;
1070 SendMessage16(hwnd,WM_MDICALCCHILDSCROLL,0,0L);
1071 return 0;
1073 case WM_MDIMAXIMIZE:
1074 ShowWindow16((HWND16)wParam, SW_MAXIMIZE);
1075 return 0;
1077 case WM_MDINEXT:
1078 MDI_SwitchActiveChild(hwnd, (HWND16)wParam, (lParam)?1:0);
1079 break;
1081 case WM_MDIRESTORE:
1082 ShowWindow16( (HWND16)wParam, SW_NORMAL);
1083 return 0;
1085 case WM_MDISETMENU:
1086 #ifdef WINELIB32
1087 return (LRESULT)MDISetMenu(hwnd, FALSE, (HMENU16)wParam, (HMENU16)lParam);
1088 #else
1089 return (LRESULT)MDISetMenu(hwnd, wParam, LOWORD(lParam), HIWORD(lParam));
1090 #endif
1092 case WM_MDITILE:
1093 ci->sbNeedUpdate = TRUE;
1094 ShowScrollBar32(hwnd,SB_BOTH,FALSE);
1095 MDITile(w, ci,wParam);
1096 ci->sbNeedUpdate = FALSE;
1097 return 0;
1099 case WM_VSCROLL:
1100 case WM_HSCROLL:
1101 ci->sbNeedUpdate = TRUE;
1102 ScrollChildren32(hwnd,message,wParam,lParam);
1103 ci->sbNeedUpdate = FALSE;
1104 return 0;
1106 case WM_SETFOCUS:
1107 if( ci->hwndActiveChild )
1109 w = WIN_FindWndPtr( ci->hwndActiveChild );
1110 if( !(w->dwStyle & WS_MINIMIZE) )
1111 SetFocus32( ci->hwndActiveChild );
1113 return 0;
1115 case WM_NCACTIVATE:
1116 if( ci->hwndActiveChild )
1117 SendMessage16(ci->hwndActiveChild, message, wParam, lParam);
1118 break;
1120 case WM_PARENTNOTIFY:
1121 if( wParam == WM_LBUTTONDOWN )
1123 POINT16 pt = MAKEPOINT16(lParam);
1124 HWND16 child = ChildWindowFromPoint16(hwnd, pt);
1126 dprintf_mdi(stddeb,"MDIClient: notification from %04x (%i,%i)\n",child,pt.x,pt.y);
1128 if( child && child != hwnd &&
1129 child != ci->hwndActiveChild )
1130 SetWindowPos32(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1132 return 0;
1134 case WM_SIZE:
1135 if( ci->hwndChildMaximized )
1137 WND* child = WIN_FindWndPtr(ci->hwndChildMaximized);
1138 RECT16 rect = { 0, 0, LOWORD(lParam), HIWORD(lParam) };
1140 AdjustWindowRectEx16(&rect, child->dwStyle, 0, child->dwExStyle);
1141 MoveWindow16(ci->hwndChildMaximized, rect.left, rect.top,
1142 rect.right - rect.left, rect.bottom - rect.top, 1);
1144 else
1145 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1147 break;
1149 case WM_MDICALCCHILDSCROLL:
1150 if( ci->sbNeedUpdate )
1151 if( ci->sbRecalc )
1153 CalcChildScroll(hwnd, ci->sbRecalc-1);
1154 ci->sbRecalc = ci->sbNeedUpdate = 0;
1156 return 0;
1159 return DefWindowProc16(hwnd, message, wParam, lParam);
1163 /***********************************************************************
1164 * DefFrameProc16 (USER.445)
1166 LRESULT DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient, UINT16 message,
1167 WPARAM16 wParam, LPARAM lParam )
1169 HWND16 childHwnd;
1170 MDICLIENTINFO* ci;
1171 WND* wndPtr;
1173 if (hwndMDIClient)
1175 switch (message)
1177 case WM_COMMAND:
1178 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1179 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1181 /* check for possible syscommands for maximized MDI child */
1183 if( ci && (
1184 wParam < ci->idFirstChild ||
1185 wParam >= ci->idFirstChild + ci->nActiveChildren
1187 if( (wParam - 0xF000) & 0xF00F ) break;
1188 switch( wParam )
1190 case SC_SIZE:
1191 case SC_MOVE:
1192 case SC_MINIMIZE:
1193 case SC_MAXIMIZE:
1194 case SC_NEXTWINDOW:
1195 case SC_PREVWINDOW:
1196 case SC_CLOSE:
1197 case SC_RESTORE:
1198 if( ci->hwndChildMaximized )
1199 return SendMessage16( ci->hwndChildMaximized, WM_SYSCOMMAND,
1200 wParam, lParam);
1203 else
1205 childHwnd = MDI_GetChildByID( WIN_FindWndPtr(hwndMDIClient),
1206 wParam );
1207 if( childHwnd )
1208 SendMessage16(hwndMDIClient, WM_MDIACTIVATE,
1209 (WPARAM16)childHwnd , 0L);
1211 break;
1213 case WM_NCACTIVATE:
1214 SendMessage16(hwndMDIClient, message, wParam, lParam);
1215 break;
1217 case WM_SETTEXT:
1218 MDI_UpdateFrameText(WIN_FindWndPtr(hwnd), hwndMDIClient,
1219 MDI_REPAINTFRAME,
1220 (LPCSTR)PTR_SEG_TO_LIN(lParam));
1221 return 0;
1223 case WM_SETFOCUS:
1224 SetFocus32(hwndMDIClient);
1225 break;
1227 case WM_SIZE:
1228 MoveWindow16(hwndMDIClient, 0, 0,
1229 LOWORD(lParam), HIWORD(lParam), TRUE);
1230 break;
1232 case WM_NEXTMENU:
1234 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1235 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1237 if( !(wndPtr->parent->dwStyle & WS_MINIMIZE)
1238 && ci->hwndActiveChild && !ci->hwndChildMaximized )
1240 /* control menu is between the frame system menu and
1241 * the first entry of menu bar */
1243 if( wParam == VK_LEFT )
1244 { if( wndPtr->parent->wIDmenu != LOWORD(lParam) ) break; }
1245 else if( wParam == VK_RIGHT )
1246 { if( GetSystemMenu16( wndPtr->parent->hwndSelf, 0)
1247 != LOWORD(lParam) ) break; }
1248 else break;
1250 return MAKELONG( GetSystemMenu16(ci->hwndActiveChild, 0),
1251 ci->hwndActiveChild );
1253 break;
1257 return DefWindowProc16(hwnd, message, wParam, lParam);
1261 /***********************************************************************
1262 * DefFrameProc32A (USER32.121)
1264 LRESULT DefFrameProc32A( HWND32 hwnd, HWND32 hwndMDIClient, UINT32 message,
1265 WPARAM32 wParam, LPARAM lParam )
1267 if (hwndMDIClient)
1269 switch (message)
1271 case WM_COMMAND:
1272 return DefFrameProc16( hwnd, hwndMDIClient, message,
1273 (WPARAM16)wParam,
1274 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1276 case WM_NCACTIVATE:
1277 SendMessage32A(hwndMDIClient, message, wParam, lParam);
1278 break;
1280 case WM_SETTEXT: {
1281 LRESULT ret;
1282 LPSTR segstr = SEGPTR_STRDUP((LPSTR)lParam);
1284 ret = DefFrameProc16(hwnd, hwndMDIClient, message,
1285 wParam, (LPARAM)SEGPTR_GET(segstr) );
1286 SEGPTR_FREE(segstr);
1287 return ret;
1290 case WM_SETFOCUS:
1291 case WM_SIZE:
1292 return DefFrameProc16( hwnd, hwndMDIClient, message,
1293 wParam, lParam );
1297 return DefWindowProc32A(hwnd, message, wParam, lParam);
1301 /***********************************************************************
1302 * DefFrameProc32W (USER32.122)
1304 LRESULT DefFrameProc32W( HWND32 hwnd, HWND32 hwndMDIClient, UINT32 message,
1305 WPARAM32 wParam, LPARAM lParam )
1307 if (hwndMDIClient)
1309 switch (message)
1311 case WM_COMMAND:
1312 return DefFrameProc16( hwnd, hwndMDIClient, message,
1313 (WPARAM16)wParam,
1314 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1316 case WM_NCACTIVATE:
1317 SendMessage32W(hwndMDIClient, message, wParam, lParam);
1318 break;
1320 case WM_SETTEXT: {
1321 LPSTR txt = HEAP_strdupWtoA(GetProcessHeap(),0,(LPWSTR)lParam);
1322 LRESULT ret = DefFrameProc32A( hwnd, hwndMDIClient, message,
1323 wParam, (DWORD)txt );
1324 HeapFree(GetProcessHeap(),0,txt);
1325 return ret;
1327 case WM_SETFOCUS:
1328 case WM_SIZE:
1329 return DefFrameProc32A( hwnd, hwndMDIClient, message,
1330 wParam, lParam );
1334 return DefWindowProc32W( hwnd, message, wParam, lParam );
1338 /***********************************************************************
1339 * DefMDIChildProc16 (USER.447)
1341 LRESULT DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1342 WPARAM16 wParam, LPARAM lParam )
1344 MDICLIENTINFO *ci;
1345 WND *clientWnd;
1347 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1348 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1350 switch (message)
1352 case WM_SETTEXT:
1353 DefWindowProc16(hwnd, message, wParam, lParam);
1354 MDI_MenuModifyItem(clientWnd,hwnd);
1355 if( ci->hwndChildMaximized == hwnd )
1356 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1357 MDI_REPAINTFRAME, NULL );
1358 return 0;
1360 case WM_CLOSE:
1361 SendMessage16(ci->self,WM_MDIDESTROY,(WPARAM16)hwnd,0L);
1362 return 0;
1364 case WM_SETFOCUS:
1365 if( ci->hwndActiveChild != hwnd )
1366 MDI_ChildActivate(clientWnd, hwnd);
1367 break;
1369 case WM_CHILDACTIVATE:
1370 MDI_ChildActivate(clientWnd, hwnd);
1371 return 0;
1373 case WM_NCPAINT:
1374 dprintf_mdi(stddeb,"DefMDIChildProc: WM_NCPAINT for %04x, active %04x\n",
1375 hwnd, ci->hwndActiveChild );
1376 break;
1378 case WM_SYSCOMMAND:
1379 switch( wParam )
1381 case SC_MOVE:
1382 if( ci->hwndChildMaximized == hwnd) return 0;
1383 break;
1384 case SC_RESTORE:
1385 case SC_MINIMIZE:
1386 WIN_FindWndPtr(hwnd)->dwStyle |= WS_SYSMENU;
1387 break;
1388 case SC_MAXIMIZE:
1389 if( ci->hwndChildMaximized == hwnd)
1390 return SendMessage16( clientWnd->parent->hwndSelf,
1391 message, wParam, lParam);
1392 WIN_FindWndPtr(hwnd)->dwStyle &= ~WS_SYSMENU;
1393 break;
1394 case SC_NEXTWINDOW:
1395 SendMessage16( ci->self, WM_MDINEXT, 0, 0);
1396 return 0;
1397 case SC_PREVWINDOW:
1398 SendMessage16( ci->self, WM_MDINEXT, 0, 1);
1399 return 0;
1401 break;
1403 case WM_GETMINMAXINFO:
1404 MDI_ChildGetMinMaxInfo(clientWnd, hwnd, (MINMAXINFO16*) PTR_SEG_TO_LIN(lParam));
1405 return 0;
1407 case WM_SETVISIBLE:
1408 if( ci->hwndChildMaximized)
1409 ci->sbNeedUpdate = 0;
1410 else
1411 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1412 break;
1414 case WM_SIZE:
1415 /* do not change */
1417 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1419 ci->hwndChildMaximized = 0;
1421 MDI_RestoreFrameMenu( clientWnd->parent, hwnd);
1422 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1423 MDI_REPAINTFRAME, NULL );
1426 if( wParam == SIZE_MAXIMIZED )
1428 HWND16 hMaxChild = ci->hwndChildMaximized;
1430 if( hMaxChild == hwnd ) break;
1432 if( hMaxChild)
1434 SendMessage16( hMaxChild, WM_SETREDRAW, FALSE, 0L );
1436 MDI_RestoreFrameMenu( clientWnd->parent, hMaxChild);
1437 ShowWindow16( hMaxChild, SW_SHOWNOACTIVATE);
1439 SendMessage16( hMaxChild, WM_SETREDRAW, TRUE, 0L );
1442 dprintf_mdi(stddeb,"\tMDI: maximizing child %04x\n", hwnd );
1444 ci->hwndChildMaximized = hwnd; /* !!! */
1446 MDI_AugmentFrameMenu( ci, clientWnd->parent, hwnd);
1447 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1448 MDI_REPAINTFRAME, NULL );
1451 if( wParam == SIZE_MINIMIZED )
1453 HWND16 switchTo = MDI_GetWindow(clientWnd, hwnd, 0);
1455 if( switchTo )
1456 SendMessage16( switchTo, WM_CHILDACTIVATE, 0, 0L);
1459 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1460 break;
1462 case WM_MENUCHAR:
1464 /* MDI children don't have menu bars */
1465 PostMessage16( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1466 (WPARAM16)SC_KEYMENU, (LPARAM)wParam);
1467 return 0x00010000L;
1469 case WM_NEXTMENU:
1471 if( wParam == VK_LEFT ) /* switch to frame system menu */
1472 return MAKELONG( GetSystemMenu16(clientWnd->parent->hwndSelf, 0),
1473 clientWnd->parent->hwndSelf );
1474 if( wParam == VK_RIGHT ) /* to frame menu bar */
1475 return MAKELONG( clientWnd->parent->wIDmenu,
1476 clientWnd->parent->hwndSelf );
1478 break;
1481 return DefWindowProc16(hwnd, message, wParam, lParam);
1485 /***********************************************************************
1486 * DefMDIChildProc32A (USER32.123)
1488 LRESULT DefMDIChildProc32A( HWND32 hwnd, UINT32 message,
1489 WPARAM32 wParam, LPARAM lParam )
1491 MDICLIENTINFO *ci;
1492 WND *clientWnd;
1494 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1495 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1497 switch (message)
1499 case WM_SETTEXT:
1500 DefWindowProc32A(hwnd, message, wParam, lParam);
1501 MDI_MenuModifyItem(clientWnd,hwnd);
1502 if( ci->hwndChildMaximized == hwnd )
1503 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1504 MDI_REPAINTFRAME, NULL );
1505 return 0;
1507 case WM_GETMINMAXINFO:
1509 MINMAXINFO16 mmi;
1510 STRUCT32_MINMAXINFO32to16( (MINMAXINFO32 *)lParam, &mmi );
1511 MDI_ChildGetMinMaxInfo( clientWnd, hwnd, &mmi );
1512 STRUCT32_MINMAXINFO16to32( &mmi, (MINMAXINFO32 *)lParam );
1514 return 0;
1516 case WM_MENUCHAR:
1518 /* MDI children don't have menu bars */
1519 PostMessage16( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1520 (WPARAM16)SC_KEYMENU, (LPARAM)LOWORD(wParam) );
1521 return 0x00010000L;
1523 case WM_CLOSE:
1524 case WM_SETFOCUS:
1525 case WM_CHILDACTIVATE:
1526 case WM_NCPAINT:
1527 case WM_SYSCOMMAND:
1528 case WM_SETVISIBLE:
1529 case WM_SIZE:
1530 case WM_NEXTMENU:
1531 return DefMDIChildProc16( hwnd, message, (WPARAM16)wParam, lParam );
1533 return DefWindowProc32A(hwnd, message, wParam, lParam);
1537 /***********************************************************************
1538 * DefMDIChildProc32W (USER32.124)
1540 LRESULT DefMDIChildProc32W( HWND32 hwnd, UINT32 message,
1541 WPARAM32 wParam, LPARAM lParam )
1543 MDICLIENTINFO *ci;
1544 WND *clientWnd;
1546 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1547 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1549 switch (message)
1551 case WM_SETTEXT:
1552 DefWindowProc32W(hwnd, message, wParam, lParam);
1553 MDI_MenuModifyItem(clientWnd,hwnd);
1554 if( ci->hwndChildMaximized == hwnd )
1555 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1556 MDI_REPAINTFRAME, NULL );
1557 return 0;
1559 case WM_GETMINMAXINFO:
1560 case WM_MENUCHAR:
1561 case WM_CLOSE:
1562 case WM_SETFOCUS:
1563 case WM_CHILDACTIVATE:
1564 case WM_NCPAINT:
1565 case WM_SYSCOMMAND:
1566 case WM_SETVISIBLE:
1567 case WM_SIZE:
1568 case WM_NEXTMENU:
1569 return DefMDIChildProc32A( hwnd, message, (WPARAM16)wParam, lParam );
1571 return DefWindowProc32W(hwnd, message, wParam, lParam);
1575 /**********************************************************************
1576 * CreateMDIWindowA (USER32.78)
1579 /**********************************************************************
1580 * CreateMDIWindowW (USER32.79)
1583 /**********************************************************************
1584 * TranslateMDISysAccel32 (USER32.554)
1586 BOOL32 TranslateMDISysAccel32( HWND32 hwndClient, LPMSG32 msg )
1588 MSG16 msg16;
1590 STRUCT32_MSG32to16(msg,&msg16);
1591 /* MDICLIENTINFO is still the same for win32 and win16 ... */
1592 return TranslateMDISysAccel16(hwndClient,&msg16);
1596 /**********************************************************************
1597 * TranslateMDISysAccel16 (USER.451)
1599 BOOL16 TranslateMDISysAccel16( HWND16 hwndClient, LPMSG16 msg )
1601 WND* clientWnd = WIN_FindWndPtr( hwndClient);
1602 WND* wnd;
1603 MDICLIENTINFO *ci = NULL;
1604 WPARAM16 wParam = 0;
1606 if( (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) || !clientWnd )
1607 return 0;
1609 ci = (MDICLIENTINFO*) clientWnd->wExtra;
1610 wnd = WIN_FindWndPtr(ci->hwndActiveChild);
1612 if( !wnd ) return 0;
1614 if( wnd->dwStyle & WS_DISABLED ) return 0;
1616 if ((GetKeyState32(VK_CONTROL) & 0x8000) && !(GetKeyState32(VK_MENU) & 0x8000))
1617 switch( msg->wParam )
1619 case VK_F6:
1620 case VK_SEPARATOR:
1621 wParam = ( GetKeyState32(VK_SHIFT) & 0x8000 )? SC_NEXTWINDOW: SC_PREVWINDOW;
1622 break;
1623 case VK_F4:
1624 case VK_RBUTTON:
1625 wParam = SC_CLOSE;
1626 break;
1627 default:
1628 return 0;
1630 else
1631 return 0;
1633 dprintf_mdi(stddeb,"TranslateMDISysAccel: wParam = %04x\n", wParam);
1635 SendMessage16(ci->hwndActiveChild,WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
1636 return 1;
1640 /***********************************************************************
1641 * CalcChildScroll (USER.462)
1643 void CalcChildScroll( HWND16 hwnd, WORD scroll )
1645 RECT16 childRect, clientRect;
1646 INT32 vmin, vmax, hmin, hmax, vpos, hpos;
1647 BOOL32 noscroll = FALSE;
1648 WND *pWnd, *Wnd;
1650 if (!(Wnd = pWnd = WIN_FindWndPtr( hwnd ))) return;
1651 GetClientRect16( hwnd, &clientRect );
1652 SetRectEmpty16( &childRect );
1654 for ( pWnd = pWnd->child; pWnd; pWnd = pWnd->next )
1656 UnionRect16( &childRect, &pWnd->rectWindow, &childRect );
1657 if( pWnd->dwStyle & WS_MAXIMIZE )
1658 noscroll = TRUE;
1660 UnionRect16( &childRect, &clientRect, &childRect );
1662 /* jump through the hoops to prevent excessive flashing
1665 hmin = childRect.left; hmax = childRect.right - clientRect.right;
1666 hpos = clientRect.left - childRect.left;
1667 vmin = childRect.top; vmax = childRect.bottom - clientRect.bottom;
1668 vpos = clientRect.top - childRect.top;
1670 if( noscroll )
1671 ShowScrollBar32(hwnd, SB_BOTH, FALSE);
1672 else
1673 switch( scroll )
1675 case SB_HORZ:
1676 vpos = hpos; vmin = hmin; vmax = hmax;
1677 case SB_VERT:
1678 SetScrollPos32(hwnd, scroll, vpos, FALSE);
1679 SetScrollRange32(hwnd, scroll, vmin, vmax, TRUE);
1680 break;
1681 case SB_BOTH:
1682 SCROLL_SetNCSbState( Wnd, vmin, vmax, vpos,
1683 hmin, hmax, hpos);
1684 SetWindowPos32(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1685 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1690 /***********************************************************************
1691 * ScrollChildren16 (USER.463)
1693 void ScrollChildren16(HWND16 hWnd, UINT16 uMsg, WPARAM16 wParam, LPARAM lParam)
1695 return ScrollChildren32( hWnd, uMsg, wParam, lParam );
1699 /***********************************************************************
1700 * ScrollChildren32 (USER32.447)
1702 void ScrollChildren32(HWND32 hWnd, UINT32 uMsg, WPARAM32 wParam, LPARAM lParam)
1704 WND *wndPtr = WIN_FindWndPtr(hWnd);
1705 INT32 newPos = -1;
1706 INT32 curPos, length, minPos, maxPos, shift;
1708 if( !wndPtr ) return;
1710 if( uMsg == WM_HSCROLL )
1712 GetScrollRange32(hWnd,SB_HORZ,&minPos,&maxPos);
1713 curPos = GetScrollPos32(hWnd,SB_HORZ);
1714 length = (wndPtr->rectClient.right - wndPtr->rectClient.left)/2;
1715 shift = SYSMETRICS_CYHSCROLL;
1717 else if( uMsg == WM_VSCROLL )
1719 GetScrollRange32(hWnd,SB_VERT,&minPos,&maxPos);
1720 curPos = GetScrollPos32(hWnd,SB_VERT);
1721 length = (wndPtr->rectClient.bottom - wndPtr->rectClient.top)/2;
1722 shift = SYSMETRICS_CXVSCROLL;
1724 else return;
1726 switch( wParam )
1728 case SB_LINEUP:
1729 newPos = curPos - shift;
1730 break;
1731 case SB_LINEDOWN:
1732 newPos = curPos + shift;
1733 break;
1734 case SB_PAGEUP:
1735 newPos = curPos - length;
1736 break;
1737 case SB_PAGEDOWN:
1738 newPos = curPos + length;
1739 break;
1741 case SB_THUMBPOSITION:
1742 newPos = LOWORD(lParam);
1743 break;
1745 case SB_THUMBTRACK:
1746 return;
1748 case SB_TOP:
1749 newPos = minPos;
1750 break;
1751 case SB_BOTTOM:
1752 newPos = maxPos;
1753 break;
1754 case SB_ENDSCROLL:
1755 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
1756 return;
1759 if( newPos > maxPos )
1760 newPos = maxPos;
1761 else if( newPos < minPos )
1762 newPos = minPos;
1764 SetScrollPos32(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
1766 if( uMsg == WM_VSCROLL )
1767 ScrollWindow32(hWnd ,0 ,curPos - newPos, NULL, NULL);
1768 else
1769 ScrollWindow32(hWnd ,curPos - newPos, 0, NULL, NULL);