Release 970112
[wine/multimedia.git] / windows / mdi.c
blobf6e5bac130958280052d0531bef85f7530e513eb
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 void MDI_UpdateFrameText(WND *, HWND, BOOL, LPCSTR);
41 BOOL MDI_AugmentFrameMenu(MDICLIENTINFO*, WND *, HWND);
42 BOOL MDI_RestoreFrameMenu(WND *, HWND);
44 static LONG MDI_ChildActivate(WND* ,HWND );
46 /* -------- Miscellaneous service functions ----------
48 * MDI_GetChildByID
51 static HWND 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(HWND hwnd, MDICLIENTINFO* ci, WORD recalc)
60 if( !ci->sbNeedUpdate )
62 ci->sbNeedUpdate = TRUE;
63 PostMessage( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
65 ci->sbRecalc = recalc;
68 /**********************************************************************
69 * MDI_MenuAppendItem
71 #ifdef SUPERFLUOUS_FUNCTIONS
72 static BOOL MDI_MenuAppendItem(WND *clientWnd, HWND 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 BOOL MDI_MenuModifyItem(WND* clientWnd, HWND hWndChild )
93 char buffer[128];
94 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
95 WND *wndPtr = WIN_FindWndPtr(hWndChild);
96 UINT n = sprintf(buffer, "%d ",
97 wndPtr->wIDmenu - clientInfo->idFirstChild + 1);
98 BOOL 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 BOOL MDI_MenuDeleteItem(WND* clientWnd, HWND hWndChild )
116 char buffer[128];
117 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
118 WND *wndPtr = WIN_FindWndPtr(hWndChild);
119 UINT 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 HWND MDI_GetWindow(WND *clientWnd, HWND 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 void MDI_CalcDefaultChildPos(WND* w, WORD n, LPPOINT16 lpPos, INT delta)
199 RECT16 rect = w->rectClient;
200 INT spacing = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME) - 1;
201 INT nstagger;
203 if( rect.bottom - rect.top - delta >= spacing )
204 rect.bottom -= delta;
206 nstagger = (rect.bottom - rect.top)/(3*spacing);
207 lpPos[1].x = (rect.right - rect.left - nstagger*spacing);
208 lpPos[1].y = (rect.bottom - rect.top - nstagger*spacing);
209 lpPos[0].x = lpPos[0].y = spacing*(n%(nstagger+1));
212 /**********************************************************************
213 * MDISetMenu
215 HMENU16 MDISetMenu(HWND hwnd, BOOL fRefresh, HMENU16 hmenuFrame,
216 HMENU16 hmenuWindow)
218 WND *w = WIN_FindWndPtr(hwnd);
219 MDICLIENTINFO *ci;
221 dprintf_mdi(stddeb, "WM_MDISETMENU: %04x %04x %04x %04x\n",
222 hwnd, fRefresh, hmenuFrame, hmenuWindow);
224 ci = (MDICLIENTINFO *) w->wExtra;
226 if (!fRefresh)
228 HWND hwndFrame = GetParent16(hwnd);
229 HMENU32 oldFrameMenu = GetMenu32(hwndFrame);
231 if( ci->hwndChildMaximized && hmenuFrame && hmenuFrame!=oldFrameMenu )
232 MDI_RestoreFrameMenu(w->parent, ci->hwndChildMaximized );
234 if( hmenuWindow && hmenuWindow!=ci->hWindowMenu )
236 /* delete menu items from ci->hWindowMenu
237 * and add them to hmenuWindow */
239 INT32 i = GetMenuItemCount32(ci->hWindowMenu) - 1;
240 INT32 pos = GetMenuItemCount32(hmenuWindow) + 1;
242 AppendMenu32A( hmenuWindow, MF_SEPARATOR, 0, NULL);
244 if( ci->nActiveChildren )
246 INT j = i - ci->nActiveChildren + 1;
247 char buffer[100];
248 UINT id,state;
250 for( ; i >= j ; i-- )
252 id = GetMenuItemID32(ci->hWindowMenu,i );
253 state = GetMenuState32(ci->hWindowMenu,i,MF_BYPOSITION);
255 GetMenuString32A(ci->hWindowMenu, i, buffer, 100, MF_BYPOSITION);
257 DeleteMenu32(ci->hWindowMenu, i , MF_BYPOSITION);
258 InsertMenu32A(hmenuWindow, pos, MF_BYPOSITION | MF_STRING,
259 id, buffer);
260 CheckMenuItem32(hmenuWindow ,pos , MF_BYPOSITION | (state & MF_CHECKED));
264 /* remove separator */
265 DeleteMenu32(ci->hWindowMenu, i, MF_BYPOSITION);
267 ci->hWindowMenu = hmenuWindow;
270 if( hmenuFrame && hmenuFrame!=oldFrameMenu)
272 SetMenu32(hwndFrame, hmenuFrame);
273 if( ci->hwndChildMaximized )
274 MDI_AugmentFrameMenu(ci, w->parent, ci->hwndChildMaximized );
275 return oldFrameMenu;
279 return 0;
282 /**********************************************************************
283 * MDIIconArrange
285 WORD MDIIconArrange(HWND parent)
287 return ArrangeIconicWindows(parent); /* Any reason why the */
288 /* existing icon arrange */
289 /* can't be used here? */
290 /* -DRP */
294 /* ------------------ MDI child window functions ---------------------- */
297 /**********************************************************************
298 * MDICreateChild
300 HWND MDICreateChild(WND *w, MDICLIENTINFO *ci, HWND parent, LPARAM lParam )
302 POINT16 pos[2];
303 MDICREATESTRUCT16 *cs = (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam);
304 DWORD style = cs->style | (WS_CHILD | WS_CLIPSIBLINGS);
305 HWND hwnd, hwndMax = 0;
306 WORD wIDmenu = ci->idFirstChild + ci->nActiveChildren;
307 char lpstrDef[]="junk!";
310 * Create child window
314 dprintf_mdi(stdnimp,"MDICreateChild: origin %i,%i - dim %i,%i, style %08x\n",
315 cs->x, cs->y, cs->cx, cs->cy, (unsigned)cs->style);
316 /* calculate placement */
317 MDI_CalcDefaultChildPos(w, ci->nTotalCreated++, pos, 0);
319 if( cs->cx == CW_USEDEFAULT16 || !cs->cx )
320 cs->cx = pos[1].x;
321 if( cs->cy == CW_USEDEFAULT16 || !cs->cy )
322 cs->cy = pos[1].y;
324 if( cs->x == CW_USEDEFAULT16 )
326 cs->x = pos[0].x;
327 cs->y = pos[0].y;
330 /* restore current maximized child */
331 if( style & WS_VISIBLE && ci->hwndChildMaximized )
333 if( style & WS_MAXIMIZE )
334 SendMessage16(w->hwndSelf, WM_SETREDRAW, FALSE, 0L );
335 hwndMax = ci->hwndChildMaximized;
336 ShowWindow( hwndMax, SW_SHOWNOACTIVATE );
337 if( style & WS_MAXIMIZE )
338 SendMessage16(w->hwndSelf, WM_SETREDRAW, TRUE, 0L );
341 /* this menu is needed to set a check mark in MDI_ChildActivate */
342 AppendMenu32A(ci->hWindowMenu ,MF_STRING ,wIDmenu, lpstrDef );
344 ci->nActiveChildren++;
346 /* fix window style */
347 if( !(w->dwStyle & MDIS_ALLCHILDSTYLES) )
349 style &= (WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZE | WS_MAXIMIZE |
350 WS_CLIPCHILDREN | WS_DISABLED | WS_VSCROLL | WS_HSCROLL );
351 style |= (WS_VISIBLE | WS_OVERLAPPEDWINDOW);
354 hwnd = CreateWindow16( (LPCSTR)PTR_SEG_TO_LIN(cs->szClass),
355 (LPCSTR)PTR_SEG_TO_LIN(cs->szTitle), style,
356 cs->x, cs->y, cs->cx, cs->cy, parent,
357 (HMENU16)wIDmenu, w->hInstance,
358 (LPVOID)lParam);
360 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
362 if (hwnd)
364 WND* wnd = WIN_FindWndPtr( hwnd );
366 MDI_MenuModifyItem(w ,hwnd);
367 if( wnd->dwStyle & WS_MINIMIZE && ci->hwndActiveChild )
368 ShowWindow( hwnd, SW_SHOWMINNOACTIVE );
369 else
371 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE );
373 /* Set maximized state here in case hwnd didn't receive WM_SIZE
374 * during CreateWindow - bad!
377 if( wnd->dwStyle & WS_MAXIMIZE && !ci->hwndChildMaximized )
379 ci->hwndChildMaximized = wnd->hwndSelf;
380 MDI_AugmentFrameMenu( ci, w->parent, hwnd );
381 MDI_UpdateFrameText( w->parent, ci->self, MDI_REPAINTFRAME, NULL );
384 dprintf_mdi(stddeb, "MDICreateChild: created child - %04x\n",hwnd);
386 else
388 ci->nActiveChildren--;
389 DeleteMenu32(ci->hWindowMenu,wIDmenu,MF_BYCOMMAND);
390 if( IsWindow(hwndMax) )
391 ShowWindow(hwndMax, SW_SHOWMAXIMIZED);
394 return hwnd;
397 /**********************************************************************
398 * MDI_ChildGetMinMaxInfo
400 void MDI_ChildGetMinMaxInfo(WND* clientWnd, HWND hwnd, MINMAXINFO16* lpMinMax )
402 WND* childWnd = WIN_FindWndPtr(hwnd);
403 RECT16 rect = clientWnd->rectClient;
405 MapWindowPoints16(clientWnd->parent->hwndSelf,
406 ((MDICLIENTINFO*)clientWnd->wExtra)->self, (LPPOINT16)&rect, 2);
407 AdjustWindowRectEx16( &rect, childWnd->dwStyle, 0, childWnd->dwExStyle );
409 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
410 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
412 lpMinMax->ptMaxPosition.x = rect.left;
413 lpMinMax->ptMaxPosition.y = rect.top;
415 dprintf_mdi(stddeb,"\tChildMinMaxInfo: max rect (%i,%i - %i, %i)\n",
416 rect.left,rect.top,rect.right,rect.bottom);
420 /**********************************************************************
421 * MDI_SwitchActiveChild
423 * Notes: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
424 * being activated
426 * wTo is basically lParam of WM_MDINEXT message or explicit
427 * window handle
429 void MDI_SwitchActiveChild(HWND clientHwnd, HWND childHwnd, BOOL wTo )
431 WND *w = WIN_FindWndPtr(clientHwnd);
432 HWND hwndTo = 0;
433 HWND hwndPrev = 0;
434 MDICLIENTINFO *ci;
436 hwndTo = MDI_GetWindow(w,childHwnd,(WORD)wTo);
438 ci = (MDICLIENTINFO *) w->wExtra;
440 dprintf_mdi(stddeb, "MDI_SwitchActiveChild: from %04x, to %04x\n",childHwnd,hwndTo);
442 if ( !hwndTo ) return;
444 hwndPrev = ci->hwndActiveChild;
446 if ( hwndTo != hwndPrev )
448 BOOL bOptimize = 0;
450 if( ci->hwndChildMaximized )
452 bOptimize = 1;
453 w->dwStyle &= ~WS_VISIBLE;
456 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0,
457 SWP_NOMOVE | SWP_NOSIZE );
458 if( !wTo && hwndPrev )
460 SetWindowPos( hwndPrev, HWND_BOTTOM, 0, 0, 0, 0,
461 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
464 if( bOptimize )
465 ShowWindow( clientHwnd, SW_SHOW );
470 /**********************************************************************
471 * MDIDestroyChild
473 HWND MDIDestroyChild(WND *w_parent, MDICLIENTINFO *ci, HWND parent,
474 HWND child, BOOL flagDestroy)
476 WND *childPtr = WIN_FindWndPtr(child);
478 if( childPtr )
480 if( child == ci->hwndActiveChild )
482 MDI_SwitchActiveChild(parent,child,0);
484 if( child == ci->hwndActiveChild )
486 ShowWindow( child, SW_HIDE);
487 if( child == ci->hwndChildMaximized )
489 MDI_RestoreFrameMenu(w_parent->parent, child);
490 ci->hwndChildMaximized = 0;
491 MDI_UpdateFrameText(w_parent->parent,parent,TRUE,NULL);
494 MDI_ChildActivate(w_parent,0);
496 MDI_MenuDeleteItem(w_parent, child);
499 ci->nActiveChildren--;
501 dprintf_mdi(stddeb,"MDIDestroyChild: child destroyed - %04x\n",child);
503 if (flagDestroy)
505 MDI_PostUpdate(GetParent16(child), ci, SB_BOTH+1);
506 DestroyWindow(child);
510 return 0;
514 /**********************************************************************
515 * MDI_ChildActivate
517 * Note: hWndChild is NULL when last child is being destroyed
519 LONG MDI_ChildActivate(WND *clientPtr, HWND hWndChild)
521 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientPtr->wExtra;
522 HWND prevActiveWnd = clientInfo->hwndActiveChild;
523 WND *wndPtr = WIN_FindWndPtr( hWndChild );
524 WND *wndPrev = WIN_FindWndPtr( prevActiveWnd );
525 BOOL isActiveFrameWnd = 0;
527 if( hWndChild == prevActiveWnd ) return 0L;
529 if( wndPtr )
530 if( wndPtr->dwStyle & WS_DISABLED ) return 0L;
532 dprintf_mdi(stddeb,"MDI_ChildActivate: %04x\n", hWndChild);
534 if( GetActiveWindow() == clientPtr->parent->hwndSelf )
535 isActiveFrameWnd = TRUE;
537 /* deactivate prev. active child */
538 if( wndPrev )
540 wndPrev->dwStyle |= WS_SYSMENU;
541 SendMessage16( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
543 #ifdef WINELIB32
544 SendMessage32A( prevActiveWnd, WM_MDIACTIVATE, (WPARAM32)prevActiveWnd,
545 (LPARAM)hWndChild);
546 #else
548 SendMessage16( prevActiveWnd, WM_MDIACTIVATE, FALSE,
549 MAKELONG(hWndChild,prevActiveWnd));
550 #endif
551 /* uncheck menu item */
552 if( clientInfo->hWindowMenu )
553 CheckMenuItem32( clientInfo->hWindowMenu,
554 wndPrev->wIDmenu, 0);
557 /* set appearance */
558 if( clientInfo->hwndChildMaximized )
559 if( clientInfo->hwndChildMaximized != hWndChild )
560 if( hWndChild )
562 clientInfo->hwndActiveChild = hWndChild;
563 ShowWindow( hWndChild, SW_SHOWMAXIMIZED);
565 else
566 ShowWindow( clientInfo->hwndActiveChild,
567 SW_SHOWNORMAL );
569 clientInfo->hwndActiveChild = hWndChild;
571 /* check if we have any children left */
572 if( !hWndChild )
574 if( isActiveFrameWnd )
575 SetFocus32( clientInfo->self );
576 return 0;
579 /* check menu item */
580 if( clientInfo->hWindowMenu )
581 CheckMenuItem32( clientInfo->hWindowMenu,
582 wndPtr->wIDmenu, MF_CHECKED);
584 /* bring active child to the top */
585 SetWindowPos( hWndChild, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
587 if( isActiveFrameWnd )
589 SendMessage16( hWndChild, WM_NCACTIVATE, TRUE, 0L);
590 if( GetFocus32() == clientInfo->self )
591 SendMessage16( clientInfo->self, WM_SETFOCUS,
592 (WPARAM16)clientInfo->self, 0L );
593 else
594 SetFocus32( clientInfo->self );
597 #ifdef WINELIB32
598 SendMessage32A( hWndChild, WM_MDIACTIVATE, (WPARAM32)hWndChild,
599 (LPARAM)prevActiveWnd );
600 #else
601 SendMessage16( hWndChild, WM_MDIACTIVATE, TRUE,
602 MAKELONG(hWndChild,prevActiveWnd));
603 #endif
605 return 1;
608 /**********************************************************************
609 * MDI_BuildWCL
611 * iTotal returns number of children available for tiling or cascading
613 MDIWCL* MDI_BuildWCL(WND* clientWnd, INT16* iTotal)
615 MDIWCL *listTop,*listNext;
616 WND *childWnd;
618 if (!(listTop = (MDIWCL*)malloc( sizeof(MDIWCL) ))) return NULL;
620 listTop->hChild = clientWnd->child ? clientWnd->child->hwndSelf : 0;
621 listTop->prev = NULL;
622 *iTotal = 1;
624 /* build linked list from top child to bottom */
626 childWnd = WIN_FindWndPtr( listTop->hChild );
627 while( childWnd && childWnd->next )
629 listNext = (MDIWCL*)xmalloc(sizeof(MDIWCL));
631 if( (childWnd->dwStyle & WS_DISABLED) ||
632 (childWnd->dwStyle & WS_MINIMIZE) ||
633 !(childWnd->dwStyle & WS_VISIBLE) )
635 listTop->hChild = 0;
636 (*iTotal)--;
639 listNext->hChild = childWnd->next->hwndSelf;
640 listNext->prev = listTop;
641 listTop = listNext;
642 (*iTotal)++;
644 childWnd = childWnd->next;
647 if( (childWnd->dwStyle & WS_DISABLED) ||
648 (childWnd->dwStyle & WS_MINIMIZE) ||
649 !(childWnd->dwStyle & WS_VISIBLE) )
651 listTop->hChild = 0;
652 (*iTotal)--;
655 return listTop;
659 /* -------------------- MDI client window functions ------------------- */
661 /**********************************************************************
662 * CreateMDIMenuBitmap
664 HBITMAP16 CreateMDIMenuBitmap(void)
666 HDC32 hDCSrc = CreateCompatibleDC32(0);
667 HDC32 hDCDest = CreateCompatibleDC32(hDCSrc);
668 HBITMAP16 hbClose = LoadBitmap16(0, MAKEINTRESOURCE(OBM_CLOSE) );
669 HBITMAP16 hbCopy,hb_src,hb_dest;
671 hb_src = SelectObject32(hDCSrc,hbClose);
672 hbCopy = CreateCompatibleBitmap(hDCSrc,SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE);
673 hb_dest = SelectObject32(hDCDest,hbCopy);
675 BitBlt32(hDCDest, 0, 0, SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE,
676 hDCSrc, SYSMETRICS_CXSIZE, 0, SRCCOPY);
678 SelectObject32(hDCSrc,hb_src);
679 SelectObject32(hDCDest,hb_dest);
681 DeleteObject32(hbClose);
683 DeleteDC32(hDCDest);
684 DeleteDC32(hDCSrc);
686 return hbCopy;
689 /**********************************************************************
690 * MDICascade
692 LONG MDICascade(WND* clientWnd, MDICLIENTINFO *ci)
694 MDIWCL *listTop,*listPrev;
695 INT16 delta = 0,iToPosition = 0, n = 0;
696 POINT16 pos[2];
698 if (ci->hwndChildMaximized)
699 ShowWindow( ci->hwndChildMaximized, SW_NORMAL);
701 if (ci->nActiveChildren == 0) return 0;
703 if (!(listTop = MDI_BuildWCL(clientWnd,&iToPosition))) return 0;
705 if( iToPosition < ci->nActiveChildren )
706 delta = 2 * SYSMETRICS_CYICONSPACING + SYSMETRICS_CYICON;
708 /* walk list and move windows */
709 while ( listTop )
711 dprintf_mdi(stddeb, "MDICascade: move %04x to (%d,%d) size [%d,%d]\n",
712 listTop->hChild, pos[0].x, pos[0].y, pos[1].x, pos[1].y);
714 if( listTop->hChild )
716 MDI_CalcDefaultChildPos(clientWnd, n++, pos, delta);
717 SetWindowPos(listTop->hChild, 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
718 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
721 listPrev = listTop->prev;
722 free(listTop);
723 listTop = listPrev;
726 if( iToPosition < ci->nActiveChildren )
727 ArrangeIconicWindows( clientWnd->hwndSelf );
729 return 0;
732 /**********************************************************************
733 * MDITile
736 LONG MDITile(WND* wndClient, MDICLIENTINFO *ci,WORD wParam)
738 MDIWCL *listTop,*listPrev;
739 RECT16 rect;
740 int xsize, ysize;
741 int x, y;
742 int rows, columns;
743 int r, c;
744 int i;
745 INT16 iToPosition = 0;
747 if (ci->hwndChildMaximized)
748 ShowWindow(ci->hwndChildMaximized, SW_NORMAL);
750 if (ci->nActiveChildren == 0) return 0;
752 listTop = MDI_BuildWCL(wndClient, &iToPosition);
754 dprintf_mdi(stddeb,"MDITile: %i windows to tile\n",iToPosition);
756 if( !listTop ) return 0;
758 /* tile children */
759 if ( iToPosition )
761 rect = wndClient->rectClient;
762 rows = (int) sqrt((double) iToPosition);
763 columns = iToPosition / rows;
765 if (wParam == MDITILE_HORIZONTAL) /* version >= 3.1 */
767 i=rows;
768 rows=columns; /* exchange r and c */
769 columns=i;
772 /* hack */
773 if( iToPosition != ci->nActiveChildren)
775 y = rect.bottom - 2 * SYSMETRICS_CYICONSPACING - SYSMETRICS_CYICON;
776 rect.bottom = ( y - SYSMETRICS_CYICON < rect.top )? rect.bottom: y;
779 ysize = rect.bottom / rows;
780 xsize = rect.right / columns;
782 x = 0;
783 i = 0;
785 for (c = 1; c <= columns; c++)
787 if (c == columns)
789 rows = iToPosition - i;
790 ysize = rect.bottom / rows;
793 y = 0;
794 for (r = 1; r <= rows; r++, i++)
796 /* shouldn't happen but... */
797 if( !listTop )
798 break;
800 /* skip iconized childs from tiling */
801 while (!listTop->hChild)
803 listPrev = listTop->prev;
804 free(listTop);
805 listTop = listPrev;
807 SetWindowPos(listTop->hChild, 0, x, y, xsize, ysize,
808 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
809 y += ysize;
810 listPrev = listTop->prev;
811 free(listTop);
812 listTop = listPrev;
814 x += xsize;
818 /* free the rest if any */
819 while( listTop )
821 listPrev = listTop->prev;
822 free(listTop);
823 listTop = listPrev;
826 if (iToPosition < ci->nActiveChildren )
827 ArrangeIconicWindows( wndClient->hwndSelf );
829 return 0;
832 /* ----------------------- Frame window ---------------------------- */
835 /**********************************************************************
836 * MDI_AugmentFrameMenu
838 BOOL MDI_AugmentFrameMenu(MDICLIENTINFO* ci, WND *frame, HWND hChild)
840 WND* child = WIN_FindWndPtr(hChild);
841 HMENU16 hSysPopup = 0;
843 dprintf_mdi(stddeb,"MDI_AugmentFrameMenu: frame %p,child %04x\n",frame,hChild);
845 if( !frame->wIDmenu || !child->hSysMenu ) return 0;
847 /* create a copy of sysmenu popup and insert it into frame menu bar */
849 if (!(hSysPopup = LoadMenuIndirect32A(SYSRES_GetResPtr(SYSRES_MENU_SYSMENU))))
850 return 0;
852 dprintf_mdi(stddeb,"\t\tgot popup %04x\n in sysmenu %04x",hSysPopup,child->hSysMenu);
854 if( !InsertMenu32A(frame->wIDmenu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
855 hSysPopup, (LPSTR)(DWORD)hBmpClose ))
856 { DestroyMenu32(hSysPopup); return 0; }
858 if( !AppendMenu32A(frame->wIDmenu,MF_HELP | MF_BITMAP,
859 SC_RESTORE, (LPSTR)(DWORD)hBmpRestore ))
861 RemoveMenu32(frame->wIDmenu,0,MF_BYPOSITION);
862 return 0;
865 EnableMenuItem32(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
866 EnableMenuItem32(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
867 EnableMenuItem32(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
869 /* redraw menu */
870 DrawMenuBar32(frame->hwndSelf);
872 return 1;
875 /**********************************************************************
876 * MDI_RestoreFrameMenu
878 BOOL MDI_RestoreFrameMenu( WND *frameWnd, HWND hChild)
880 INT32 nItems = GetMenuItemCount32(frameWnd->wIDmenu) - 1;
882 dprintf_mdi(stddeb,"MDI_RestoreFrameMenu: for child %04x\n",hChild);
884 if( GetMenuItemID32(frameWnd->wIDmenu,nItems) != SC_RESTORE )
885 return 0;
888 RemoveMenu32(frameWnd->wIDmenu,0,MF_BYPOSITION);
889 DeleteMenu32(frameWnd->wIDmenu,nItems-1,MF_BYPOSITION);
891 DrawMenuBar32(frameWnd->hwndSelf);
893 return 1;
896 /**********************************************************************
897 * MDI_UpdateFrameText
899 * used when child window is maximized/restored
901 * Note: lpTitle can be NULL
903 void MDI_UpdateFrameText(WND *frameWnd, HWND hClient, BOOL repaint, LPCSTR lpTitle)
905 char lpBuffer[MDI_MAXTITLELENGTH+1];
906 WND* clientWnd = WIN_FindWndPtr(hClient);
908 MDICLIENTINFO *ci = (MDICLIENTINFO *) clientWnd->wExtra;
910 dprintf_mdi(stddeb, "MDI: repaint %i, frameText %s\n", repaint, (lpTitle)?lpTitle:"NULL");
912 /* store new "default" title if lpTitle is not NULL */
913 if (lpTitle)
915 if (ci->frameTitle) HeapFree( SystemHeap, 0, ci->frameTitle );
916 ci->frameTitle = HEAP_strdupA( SystemHeap, 0, lpTitle );
919 if (ci->frameTitle)
921 WND* childWnd = WIN_FindWndPtr( ci->hwndChildMaximized );
923 if( childWnd && childWnd->text )
925 /* combine frame title and child title if possible */
927 LPCSTR lpBracket = " - [";
928 int i_frame_text_length = strlen(ci->frameTitle);
929 int i_child_text_length = strlen(childWnd->text);
931 lstrcpyn32A( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
933 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
935 strcat( lpBuffer, lpBracket );
937 if( i_frame_text_length + i_child_text_length + 6 < MDI_MAXTITLELENGTH )
939 strcat( lpBuffer, childWnd->text );
940 strcat( lpBuffer, "]" );
942 else
944 lstrcpyn32A( lpBuffer + i_frame_text_length + 4,
945 childWnd->text,
946 MDI_MAXTITLELENGTH - i_frame_text_length - 5 );
947 strcat( lpBuffer, "]" );
951 else
953 strncpy(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH );
954 lpBuffer[MDI_MAXTITLELENGTH]='\0';
957 else
958 lpBuffer[0] = '\0';
960 DEFWND_SetText( frameWnd, lpBuffer );
961 if( repaint == MDI_REPAINTFRAME)
962 SetWindowPos(frameWnd->hwndSelf, 0,0,0,0,0, SWP_FRAMECHANGED |
963 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
967 /* ----------------------------- Interface ---------------------------- */
970 /**********************************************************************
971 * MDIClientWndProc
973 * This function is the handler for all MDI requests.
975 LRESULT MDIClientWndProc(HWND hwnd, UINT message, WPARAM16 wParam, LPARAM lParam)
977 LPCREATESTRUCT16 cs;
978 LPCLIENTCREATESTRUCT16 ccs;
979 MDICLIENTINFO *ci;
980 RECT16 rect;
981 WND *w = WIN_FindWndPtr(hwnd);
982 WND *frameWnd = w->parent;
983 INT nItems;
985 ci = (MDICLIENTINFO *) w->wExtra;
987 switch (message)
989 case WM_CREATE:
990 cs = (LPCREATESTRUCT16) PTR_SEG_TO_LIN(lParam);
991 ccs = (LPCLIENTCREATESTRUCT16) PTR_SEG_TO_LIN(cs->lpCreateParams);
993 ci->hWindowMenu = ccs->hWindowMenu;
994 ci->idFirstChild = ccs->idFirstChild;
995 ci->hwndChildMaximized = 0;
996 ci->nActiveChildren = 0;
997 ci->nTotalCreated = 0;
998 ci->frameTitle = NULL;
999 ci->sbNeedUpdate = 0;
1000 ci->self = hwnd;
1001 w->dwStyle |= WS_CLIPCHILDREN;
1003 if (!hBmpClose)
1005 hBmpClose = CreateMDIMenuBitmap();
1006 hBmpRestore = LoadBitmap16( 0, MAKEINTRESOURCE(OBM_RESTORE) );
1008 MDI_UpdateFrameText(frameWnd, hwnd, MDI_NOFRAMEREPAINT,frameWnd->text);
1010 AppendMenu32A( ccs->hWindowMenu, MF_SEPARATOR, 0, NULL );
1012 GetClientRect16(frameWnd->hwndSelf, &rect);
1013 NC_HandleNCCalcSize( w, &rect );
1014 w->rectClient = rect;
1016 dprintf_mdi(stddeb,"MDI: Client created - hwnd = %04x, idFirst = %u\n",hwnd,ci->idFirstChild);
1018 return 0;
1020 case WM_DESTROY:
1021 if( ci->hwndChildMaximized ) MDI_RestoreFrameMenu(w, frameWnd->hwndSelf);
1022 if((nItems = GetMenuItemCount32(ci->hWindowMenu)) > 0) {
1023 ci->idFirstChild = nItems - 1;
1024 ci->nActiveChildren++; /* to delete a separator */
1025 while( ci->nActiveChildren-- )
1026 DeleteMenu32(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
1028 return 0;
1030 case WM_MDIACTIVATE:
1031 if( ci->hwndActiveChild != (HWND)wParam )
1032 SetWindowPos((HWND)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1033 return 0;
1035 case WM_MDICASCADE:
1036 return MDICascade(w, ci);
1038 case WM_MDICREATE:
1039 return (LONG)MDICreateChild(w, ci, hwnd, lParam );
1041 case WM_MDIDESTROY:
1042 return (LONG)MDIDestroyChild(w, ci, hwnd, (HWND)wParam, TRUE);
1044 case WM_MDIGETACTIVE:
1045 return ((LONG) ci->hwndActiveChild |
1046 ((LONG) (ci->hwndChildMaximized>0) << 16));
1048 case WM_MDIICONARRANGE:
1049 ci->sbNeedUpdate = TRUE;
1050 MDIIconArrange(hwnd);
1051 ci->sbRecalc = SB_BOTH+1;
1052 SendMessage16(hwnd,WM_MDICALCCHILDSCROLL,0,0L);
1053 return 0;
1055 case WM_MDIMAXIMIZE:
1056 ShowWindow((HWND)wParam, SW_MAXIMIZE);
1057 return 0;
1059 case WM_MDINEXT:
1060 MDI_SwitchActiveChild(hwnd, (HWND)wParam, (lParam)?1:0);
1061 break;
1063 case WM_MDIRESTORE:
1064 ShowWindow( (HWND)wParam, SW_NORMAL);
1065 return 0;
1067 case WM_MDISETMENU:
1068 #ifdef WINELIB32
1069 return (LRESULT)MDISetMenu(hwnd, FALSE, (HMENU16)wParam, (HMENU16)lParam);
1070 #else
1071 return (LRESULT)MDISetMenu(hwnd, wParam, LOWORD(lParam), HIWORD(lParam));
1072 #endif
1074 case WM_MDITILE:
1075 ci->sbNeedUpdate = TRUE;
1076 ShowScrollBar32(hwnd,SB_BOTH,FALSE);
1077 MDITile(w, ci,wParam);
1078 ci->sbNeedUpdate = FALSE;
1079 return 0;
1081 case WM_VSCROLL:
1082 case WM_HSCROLL:
1083 ci->sbNeedUpdate = TRUE;
1084 ScrollChildren(hwnd,message,wParam,lParam);
1085 ci->sbNeedUpdate = FALSE;
1086 return 0;
1088 case WM_SETFOCUS:
1089 if( ci->hwndActiveChild )
1091 w = WIN_FindWndPtr( ci->hwndActiveChild );
1092 if( !(w->dwStyle & WS_MINIMIZE) )
1093 SetFocus32( ci->hwndActiveChild );
1095 return 0;
1097 case WM_NCACTIVATE:
1098 if( ci->hwndActiveChild )
1099 SendMessage16(ci->hwndActiveChild, message, wParam, lParam);
1100 break;
1102 case WM_PARENTNOTIFY:
1103 if( wParam == WM_LBUTTONDOWN )
1105 POINT16 pt = MAKEPOINT16(lParam);
1106 HWND child = ChildWindowFromPoint16(hwnd, pt);
1108 dprintf_mdi(stddeb,"MDIClient: notification from %04x (%i,%i)\n",child,pt.x,pt.y);
1110 if( child && child != hwnd )
1112 WND* wnd = WIN_FindWndPtr( child );
1114 /* if we got owned popup */
1115 if( wnd->owner ) child = wnd->owner->hwndSelf;
1117 if( child != ci->hwndActiveChild )
1118 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1121 return 0;
1123 case WM_SIZE:
1124 if( ci->hwndChildMaximized )
1126 WND* child = WIN_FindWndPtr(ci->hwndChildMaximized);
1127 RECT16 rect = { 0, 0, LOWORD(lParam), HIWORD(lParam) };
1129 AdjustWindowRectEx16(&rect, child->dwStyle, 0, child->dwExStyle);
1130 MoveWindow(ci->hwndChildMaximized, rect.left, rect.top,
1131 rect.right - rect.left, rect.bottom - rect.top, 1);
1133 else
1134 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1136 break;
1138 case WM_MDICALCCHILDSCROLL:
1139 if( ci->sbNeedUpdate )
1140 if( ci->sbRecalc )
1142 CalcChildScroll(hwnd, ci->sbRecalc-1);
1143 ci->sbRecalc = ci->sbNeedUpdate = 0;
1145 return 0;
1148 return DefWindowProc16(hwnd, message, wParam, lParam);
1152 /***********************************************************************
1153 * DefFrameProc16 (USER.445)
1155 LRESULT DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient, UINT16 message,
1156 WPARAM16 wParam, LPARAM lParam )
1158 HWND childHwnd;
1159 MDICLIENTINFO* ci;
1160 WND* wndPtr;
1162 if (hwndMDIClient)
1164 switch (message)
1166 case WM_COMMAND:
1167 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1168 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1170 /* check for possible syscommands for maximized MDI child */
1172 if( wParam < ci->idFirstChild ||
1173 wParam >= ci->idFirstChild + ci->nActiveChildren )
1175 if( (wParam - 0xF000) & 0xF00F ) break;
1176 switch( wParam )
1178 case SC_SIZE:
1179 case SC_MOVE:
1180 case SC_MINIMIZE:
1181 case SC_MAXIMIZE:
1182 case SC_NEXTWINDOW:
1183 case SC_PREVWINDOW:
1184 case SC_CLOSE:
1185 case SC_RESTORE:
1186 if( ci->hwndChildMaximized )
1187 return SendMessage16( ci->hwndChildMaximized, WM_SYSCOMMAND,
1188 wParam, lParam);
1191 else
1193 childHwnd = MDI_GetChildByID( WIN_FindWndPtr(hwndMDIClient),
1194 wParam );
1195 if( childHwnd )
1196 SendMessage16(hwndMDIClient, WM_MDIACTIVATE,
1197 (WPARAM16)childHwnd , 0L);
1199 break;
1201 case WM_NCACTIVATE:
1202 SendMessage16(hwndMDIClient, message, wParam, lParam);
1203 break;
1205 case WM_SETTEXT:
1206 MDI_UpdateFrameText(WIN_FindWndPtr(hwnd), hwndMDIClient,
1207 MDI_REPAINTFRAME,
1208 (LPCSTR)PTR_SEG_TO_LIN(lParam));
1209 return 0;
1211 case WM_SETFOCUS:
1212 SetFocus32(hwndMDIClient);
1213 break;
1215 case WM_SIZE:
1216 MoveWindow(hwndMDIClient, 0, 0,
1217 LOWORD(lParam), HIWORD(lParam), TRUE);
1218 break;
1220 case WM_NEXTMENU:
1222 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1223 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1225 if( !(wndPtr->parent->dwStyle & WS_MINIMIZE)
1226 && ci->hwndActiveChild && !ci->hwndChildMaximized )
1228 /* control menu is between the frame system menu and
1229 * the first entry of menu bar */
1231 if( wParam == VK_LEFT )
1232 { if( wndPtr->parent->wIDmenu != LOWORD(lParam) ) break; }
1233 else if( wParam == VK_RIGHT )
1234 { if( GetSystemMenu16( wndPtr->parent->hwndSelf, 0)
1235 != LOWORD(lParam) ) break; }
1236 else break;
1238 return MAKELONG( GetSystemMenu16(ci->hwndActiveChild, 0),
1239 ci->hwndActiveChild );
1241 break;
1245 return DefWindowProc16(hwnd, message, wParam, lParam);
1249 /***********************************************************************
1250 * DefFrameProc32A (USER32.121)
1252 LRESULT DefFrameProc32A( HWND32 hwnd, HWND32 hwndMDIClient, UINT32 message,
1253 WPARAM32 wParam, LPARAM lParam )
1255 if (hwndMDIClient)
1257 switch (message)
1259 case WM_COMMAND:
1260 return DefFrameProc16( hwnd, hwndMDIClient, message,
1261 (WPARAM16)wParam,
1262 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1264 case WM_NCACTIVATE:
1265 SendMessage32A(hwndMDIClient, message, wParam, lParam);
1266 break;
1268 case WM_SETTEXT:
1269 return DefFrameProc16( hwnd, hwndMDIClient, message,
1270 wParam, (LPARAM)PTR_SEG_TO_LIN(lParam) );
1272 case WM_SETFOCUS:
1273 case WM_SIZE:
1274 return DefFrameProc16( hwnd, hwndMDIClient, message,
1275 wParam, lParam );
1279 return DefWindowProc32A(hwnd, message, wParam, lParam);
1283 /***********************************************************************
1284 * DefFrameProc32W (USER32.122)
1286 LRESULT DefFrameProc32W( HWND32 hwnd, HWND32 hwndMDIClient, UINT32 message,
1287 WPARAM32 wParam, LPARAM lParam )
1289 if (hwndMDIClient)
1291 switch (message)
1293 case WM_COMMAND:
1294 return DefFrameProc16( hwnd, hwndMDIClient, message,
1295 (WPARAM16)wParam,
1296 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1298 case WM_NCACTIVATE:
1299 SendMessage32W(hwndMDIClient, message, wParam, lParam);
1300 break;
1302 case WM_SETTEXT:
1303 /* FIXME: Unicode */
1304 return DefFrameProc32A( hwnd, hwndMDIClient, message,
1305 wParam, lParam );
1307 case WM_SETFOCUS:
1308 case WM_SIZE:
1309 return DefFrameProc32A( hwnd, hwndMDIClient, message,
1310 wParam, lParam );
1314 return DefWindowProc32W( hwnd, message, wParam, lParam );
1318 /***********************************************************************
1319 * DefMDIChildProc16 (USER.447)
1321 LRESULT DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1322 WPARAM16 wParam, LPARAM lParam )
1324 MDICLIENTINFO *ci;
1325 WND *clientWnd;
1327 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1328 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1330 switch (message)
1332 case WM_SETTEXT:
1333 DefWindowProc16(hwnd, message, wParam, lParam);
1334 MDI_MenuModifyItem(clientWnd,hwnd);
1335 if( ci->hwndChildMaximized == hwnd )
1336 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1337 MDI_REPAINTFRAME, NULL );
1338 return 0;
1340 case WM_CLOSE:
1341 SendMessage16(ci->self,WM_MDIDESTROY,(WPARAM16)hwnd,0L);
1342 return 0;
1344 case WM_SETFOCUS:
1345 if( ci->hwndActiveChild != hwnd )
1346 MDI_ChildActivate(clientWnd, hwnd);
1347 break;
1349 case WM_CHILDACTIVATE:
1350 MDI_ChildActivate(clientWnd, hwnd);
1351 return 0;
1353 case WM_NCPAINT:
1354 dprintf_mdi(stddeb,"DefMDIChildProc: WM_NCPAINT for %04x, active %04x\n",
1355 hwnd, ci->hwndActiveChild );
1356 break;
1358 case WM_SYSCOMMAND:
1359 switch( wParam )
1361 case SC_MOVE:
1362 if( ci->hwndChildMaximized == hwnd) return 0;
1363 break;
1364 case SC_RESTORE:
1365 case SC_MINIMIZE:
1366 WIN_FindWndPtr(hwnd)->dwStyle |= WS_SYSMENU;
1367 break;
1368 case SC_MAXIMIZE:
1369 if( ci->hwndChildMaximized == hwnd)
1370 return SendMessage16( clientWnd->parent->hwndSelf,
1371 message, wParam, lParam);
1372 WIN_FindWndPtr(hwnd)->dwStyle &= ~WS_SYSMENU;
1373 break;
1374 case SC_NEXTWINDOW:
1375 SendMessage16( ci->self, WM_MDINEXT, 0, 0);
1376 return 0;
1377 case SC_PREVWINDOW:
1378 SendMessage16( ci->self, WM_MDINEXT, 0, 1);
1379 return 0;
1381 break;
1383 case WM_GETMINMAXINFO:
1384 MDI_ChildGetMinMaxInfo(clientWnd, hwnd, (MINMAXINFO16*) PTR_SEG_TO_LIN(lParam));
1385 return 0;
1387 case WM_SETVISIBLE:
1388 if( ci->hwndChildMaximized)
1389 ci->sbNeedUpdate = 0;
1390 else
1391 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1392 break;
1394 case WM_SIZE:
1395 /* do not change */
1397 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1399 ci->hwndChildMaximized = 0;
1401 MDI_RestoreFrameMenu( clientWnd->parent, hwnd);
1402 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1403 MDI_REPAINTFRAME, NULL );
1406 if( wParam == SIZE_MAXIMIZED )
1408 HWND hMaxChild = ci->hwndChildMaximized;
1410 if( hMaxChild == hwnd ) break;
1412 if( hMaxChild)
1414 SendMessage16( hMaxChild, WM_SETREDRAW, FALSE, 0L );
1416 MDI_RestoreFrameMenu( clientWnd->parent, hMaxChild);
1417 ShowWindow( hMaxChild, SW_SHOWNOACTIVATE);
1419 SendMessage16( hMaxChild, WM_SETREDRAW, TRUE, 0L );
1422 dprintf_mdi(stddeb,"\tMDI: maximizing child %04x\n", hwnd );
1424 ci->hwndChildMaximized = hwnd; /* !!! */
1426 MDI_AugmentFrameMenu( ci, clientWnd->parent, hwnd);
1427 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1428 MDI_REPAINTFRAME, NULL );
1431 if( wParam == SIZE_MINIMIZED )
1433 HWND switchTo = MDI_GetWindow(clientWnd, hwnd, 0);
1435 if( switchTo )
1436 SendMessage16( switchTo, WM_CHILDACTIVATE, 0, 0L);
1439 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1440 break;
1442 case WM_MENUCHAR:
1444 /* MDI children don't have menu bars */
1445 PostMessage( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1446 (WPARAM16)SC_KEYMENU, (LPARAM)wParam);
1447 return 0x00010000L;
1449 case WM_NEXTMENU:
1451 if( wParam == VK_LEFT ) /* switch to frame system menu */
1452 return MAKELONG( GetSystemMenu16(clientWnd->parent->hwndSelf, 0),
1453 clientWnd->parent->hwndSelf );
1454 if( wParam == VK_RIGHT ) /* to frame menu bar */
1455 return MAKELONG( clientWnd->parent->wIDmenu,
1456 clientWnd->parent->hwndSelf );
1458 break;
1461 return DefWindowProc16(hwnd, message, wParam, lParam);
1465 /***********************************************************************
1466 * DefMDIChildProc32A (USER32.123)
1468 LRESULT DefMDIChildProc32A( HWND32 hwnd, UINT32 message,
1469 WPARAM32 wParam, LPARAM lParam )
1471 MDICLIENTINFO *ci;
1472 WND *clientWnd;
1474 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1475 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1477 switch (message)
1479 case WM_SETTEXT:
1480 DefWindowProc32A(hwnd, message, wParam, lParam);
1481 MDI_MenuModifyItem(clientWnd,hwnd);
1482 if( ci->hwndChildMaximized == hwnd )
1483 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1484 MDI_REPAINTFRAME, NULL );
1485 return 0;
1487 case WM_GETMINMAXINFO:
1489 MINMAXINFO16 mmi;
1490 STRUCT32_MINMAXINFO32to16( (MINMAXINFO32 *)lParam, &mmi );
1491 MDI_ChildGetMinMaxInfo( clientWnd, hwnd, &mmi );
1492 STRUCT32_MINMAXINFO16to32( &mmi, (MINMAXINFO32 *)lParam );
1494 return 0;
1496 case WM_MENUCHAR:
1498 /* MDI children don't have menu bars */
1499 PostMessage( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1500 (WPARAM16)SC_KEYMENU, (LPARAM)LOWORD(wParam) );
1501 return 0x00010000L;
1503 case WM_CLOSE:
1504 case WM_SETFOCUS:
1505 case WM_CHILDACTIVATE:
1506 case WM_NCPAINT:
1507 case WM_SYSCOMMAND:
1508 case WM_SETVISIBLE:
1509 case WM_SIZE:
1510 case WM_NEXTMENU:
1511 return DefMDIChildProc16( hwnd, message, (WPARAM16)wParam, lParam );
1513 return DefWindowProc32A(hwnd, message, wParam, lParam);
1517 /***********************************************************************
1518 * DefMDIChildProc32W (USER32.124)
1520 LRESULT DefMDIChildProc32W( HWND32 hwnd, UINT32 message,
1521 WPARAM32 wParam, LPARAM lParam )
1523 MDICLIENTINFO *ci;
1524 WND *clientWnd;
1526 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1527 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1529 switch (message)
1531 case WM_SETTEXT:
1532 DefWindowProc32W(hwnd, message, wParam, lParam);
1533 MDI_MenuModifyItem(clientWnd,hwnd);
1534 if( ci->hwndChildMaximized == hwnd )
1535 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1536 MDI_REPAINTFRAME, NULL );
1537 return 0;
1539 case WM_GETMINMAXINFO:
1540 case WM_MENUCHAR:
1541 case WM_CLOSE:
1542 case WM_SETFOCUS:
1543 case WM_CHILDACTIVATE:
1544 case WM_NCPAINT:
1545 case WM_SYSCOMMAND:
1546 case WM_SETVISIBLE:
1547 case WM_SIZE:
1548 case WM_NEXTMENU:
1549 return DefMDIChildProc32A( hwnd, message, (WPARAM16)wParam, lParam );
1551 return DefWindowProc32W(hwnd, message, wParam, lParam);
1555 /**********************************************************************
1556 * TranslateMDISysAccel (USER.451)
1559 BOOL TranslateMDISysAccel(HWND hwndClient, LPMSG16 msg)
1561 WND* clientWnd = WIN_FindWndPtr( hwndClient);
1562 WND* wnd;
1563 MDICLIENTINFO *ci = NULL;
1564 WPARAM16 wParam = 0;
1566 if( (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) || !clientWnd )
1567 return 0;
1569 ci = (MDICLIENTINFO*) clientWnd->wExtra;
1570 wnd = WIN_FindWndPtr(ci->hwndActiveChild);
1572 if( !wnd ) return 0;
1574 if( wnd->dwStyle & WS_DISABLED ) return 0;
1576 if ((GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
1577 switch( msg->wParam )
1579 case VK_F6:
1580 case VK_SEPARATOR:
1581 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 )? SC_NEXTWINDOW: SC_PREVWINDOW;
1582 break;
1583 case VK_RBUTTON:
1584 wParam = SC_CLOSE;
1585 break;
1586 default:
1587 return 0;
1589 else
1590 return 0;
1592 dprintf_mdi(stddeb,"TranslateMDISysAccel: wParam = %04x\n", wParam);
1594 SendMessage16(ci->hwndActiveChild,WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
1595 return 1;
1599 /***********************************************************************
1600 * CalcChildScroll (USER.462)
1602 void CalcChildScroll( HWND hwnd, WORD scroll )
1604 RECT16 childRect, clientRect;
1605 INT vmin, vmax, hmin, hmax, vpos, hpos;
1606 BOOL noscroll = FALSE;
1607 WND *pWnd, *Wnd;
1609 if (!(Wnd = pWnd = WIN_FindWndPtr( hwnd ))) return;
1610 GetClientRect16( hwnd, &clientRect );
1611 SetRectEmpty16( &childRect );
1613 for ( pWnd = pWnd->child; pWnd; pWnd = pWnd->next )
1615 UnionRect16( &childRect, &pWnd->rectWindow, &childRect );
1616 if( pWnd->dwStyle & WS_MAXIMIZE )
1617 noscroll = TRUE;
1619 UnionRect16( &childRect, &clientRect, &childRect );
1621 /* jump through the hoops to prevent excessive flashing
1624 hmin = childRect.left; hmax = childRect.right - clientRect.right;
1625 hpos = clientRect.left - childRect.left;
1626 vmin = childRect.top; vmax = childRect.bottom - clientRect.bottom;
1627 vpos = clientRect.top - childRect.top;
1629 if( noscroll )
1630 ShowScrollBar32(hwnd, SB_BOTH, FALSE);
1631 else
1632 switch( scroll )
1634 case SB_HORZ:
1635 vpos = hpos; vmin = hmin; vmax = hmax;
1636 case SB_VERT:
1637 SetScrollPos32(hwnd, scroll, vpos, FALSE);
1638 SetScrollRange32(hwnd, scroll, vmin, vmax, TRUE);
1639 break;
1640 case SB_BOTH:
1641 SCROLL_SetNCSbState( Wnd, vmin, vmax, vpos,
1642 hmin, hmax, hpos);
1643 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1644 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1648 /***********************************************************************
1649 * ScrollChildren (USER.463)
1651 void ScrollChildren(HWND hWnd, UINT uMsg, WPARAM16 wParam, LPARAM lParam)
1653 WND *wndPtr = WIN_FindWndPtr(hWnd);
1654 short newPos=-1;
1655 short curPos;
1656 short length;
1657 INT32 minPos;
1658 INT32 maxPos;
1659 short shift;
1661 if( !wndPtr ) return;
1663 if( uMsg == WM_HSCROLL )
1665 GetScrollRange32(hWnd,SB_HORZ,&minPos,&maxPos);
1666 curPos = GetScrollPos32(hWnd,SB_HORZ);
1667 length = (wndPtr->rectClient.right - wndPtr->rectClient.left)/2;
1668 shift = SYSMETRICS_CYHSCROLL;
1670 else if( uMsg == WM_VSCROLL )
1672 GetScrollRange32(hWnd,SB_VERT,&minPos,&maxPos);
1673 curPos = GetScrollPos32(hWnd,SB_VERT);
1674 length = (wndPtr->rectClient.bottom - wndPtr->rectClient.top)/2;
1675 shift = SYSMETRICS_CXVSCROLL;
1677 else return;
1679 switch( wParam )
1681 case SB_LINEUP:
1682 newPos = curPos - shift;
1683 break;
1684 case SB_LINEDOWN:
1685 newPos = curPos + shift;
1686 break;
1687 case SB_PAGEUP:
1688 newPos = curPos - length;
1689 break;
1690 case SB_PAGEDOWN:
1691 newPos = curPos + length;
1692 break;
1694 case SB_THUMBPOSITION:
1695 newPos = LOWORD(lParam);
1696 break;
1698 case SB_THUMBTRACK:
1699 return;
1701 case SB_TOP:
1702 newPos = minPos;
1703 break;
1704 case SB_BOTTOM:
1705 newPos = maxPos;
1706 break;
1707 case SB_ENDSCROLL:
1708 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
1709 return;
1712 if( newPos > maxPos )
1713 newPos = maxPos;
1714 else if( newPos < minPos )
1715 newPos = minPos;
1717 SetScrollPos32(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
1719 if( uMsg == WM_VSCROLL )
1720 ScrollWindow32(hWnd ,0 ,curPos - newPos, NULL, NULL);
1721 else
1722 ScrollWindow32(hWnd ,curPos - newPos, 0, NULL, NULL);