Release 970629
[wine/wine-kai.git] / windows / mdi.c
blob581d091170e83c18b7a7083119ab616ea06b6501
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"
33 #define MDIF_NEEDUPDATE 0x0001
36 static HBITMAP16 hBmpClose = 0;
37 static HBITMAP16 hBmpRestore = 0;
39 DWORD SCROLL_SetNCSbState(WND*,int,int,int,int,int,int);
41 /* ----------------- declarations ----------------- */
42 static void MDI_UpdateFrameText(WND *, HWND16, BOOL32, LPCSTR);
43 static BOOL32 MDI_AugmentFrameMenu(MDICLIENTINFO*, WND *, HWND16);
44 static BOOL32 MDI_RestoreFrameMenu(WND *, HWND16);
46 static LONG MDI_ChildActivate(WND* ,HWND16 );
48 /* -------- Miscellaneous service functions ----------
50 * MDI_GetChildByID
53 static HWND16 MDI_GetChildByID(WND* wndPtr,int id)
55 for (wndPtr = wndPtr->child; wndPtr; wndPtr = wndPtr->next)
56 if (wndPtr->wIDmenu == id) return wndPtr->hwndSelf;
57 return 0;
60 static void MDI_PostUpdate(HWND16 hwnd, MDICLIENTINFO* ci, WORD recalc)
62 if( !(ci->mdiFlags & MDIF_NEEDUPDATE) )
64 ci->mdiFlags |= MDIF_NEEDUPDATE;
65 PostMessage16( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
67 ci->sbRecalc = recalc;
70 /**********************************************************************
71 * MDI_MenuAppendItem
73 #ifdef SUPERFLUOUS_FUNCTIONS
74 static BOOL32 MDI_MenuAppendItem(WND *clientWnd, HWND16 hWndChild)
76 char buffer[128];
77 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
78 WND *wndPtr = WIN_FindWndPtr(hWndChild);
79 int n = sprintf(buffer, "%d ",
80 clientInfo->nActiveChildren);
82 if( !clientInfo->hWindowMenu ) return 0;
84 if (wndPtr->text) strncpy(buffer + n, wndPtr->text, sizeof(buffer) - n - 1);
85 return AppendMenu32A( clientInfo->hWindowMenu, MF_STRING,
86 wndPtr->wIDmenu, buffer );
88 #endif
90 /**********************************************************************
91 * MDI_MenuModifyItem
93 static BOOL32 MDI_MenuModifyItem(WND* clientWnd, HWND16 hWndChild )
95 char buffer[128];
96 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
97 WND *wndPtr = WIN_FindWndPtr(hWndChild);
98 UINT32 n = sprintf(buffer, "%d ",
99 wndPtr->wIDmenu - clientInfo->idFirstChild + 1);
100 BOOL32 bRet = 0;
102 if( !clientInfo->hWindowMenu ) return 0;
104 if (wndPtr->text) lstrcpyn32A(buffer + n, wndPtr->text, sizeof(buffer) - n );
106 n = GetMenuState32(clientInfo->hWindowMenu,wndPtr->wIDmenu ,MF_BYCOMMAND);
107 bRet = ModifyMenu32A(clientInfo->hWindowMenu , wndPtr->wIDmenu,
108 MF_BYCOMMAND | MF_STRING, wndPtr->wIDmenu, buffer );
109 CheckMenuItem32(clientInfo->hWindowMenu ,wndPtr->wIDmenu , n & MF_CHECKED);
110 return bRet;
113 /**********************************************************************
114 * MDI_MenuDeleteItem
116 static BOOL32 MDI_MenuDeleteItem(WND* clientWnd, HWND16 hWndChild )
118 char buffer[128];
119 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
120 WND *wndPtr = WIN_FindWndPtr(hWndChild);
121 UINT32 index = 0,id,n;
123 if( !clientInfo->nActiveChildren ||
124 !clientInfo->hWindowMenu ) return 0;
126 id = wndPtr->wIDmenu;
127 DeleteMenu32(clientInfo->hWindowMenu,id,MF_BYCOMMAND);
129 /* walk the rest of MDI children to prevent gaps in the id
130 * sequence and in the menu child list */
132 for( index = id+1; index <= clientInfo->nActiveChildren +
133 clientInfo->idFirstChild; index++ )
135 wndPtr = WIN_FindWndPtr(MDI_GetChildByID(clientWnd,index));
136 if( !wndPtr )
138 dprintf_mdi(stddeb,"MDIMenuDeleteItem: no window for id=%i\n",index);
139 continue;
142 /* set correct id */
143 wndPtr->wIDmenu--;
145 n = sprintf(buffer, "%d ",index - clientInfo->idFirstChild);
146 if (wndPtr->text)
147 lstrcpyn32A(buffer + n, wndPtr->text, sizeof(buffer) - n );
149 /* change menu */
150 ModifyMenu32A(clientInfo->hWindowMenu ,index ,MF_BYCOMMAND | MF_STRING,
151 index - 1 , buffer );
153 return 1;
156 /**********************************************************************
157 * MDI_GetWindow
159 * returns "activateable" child or zero
161 static HWND16 MDI_GetWindow(WND *clientWnd, HWND16 hWnd, WORD wTo )
163 MDICLIENTINFO *clientInfo = (MDICLIENTINFO*)clientWnd->wExtra;
164 WND *wndPtr, *pWnd, *pWndLast;
166 if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
168 if( !(wndPtr = WIN_FindWndPtr(hWnd)) ) return 0;
170 pWnd = wndPtr;
171 pWndLast = NULL;
172 for (;;)
174 pWnd = pWnd->next;
175 if (!pWnd) pWnd = wndPtr->parent->child;
176 if (pWnd == wndPtr) /* not found */
178 if (!wTo || !pWndLast) return 0;
179 break;
182 if ( !pWnd->owner && (pWnd->dwStyle &
183 (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE )
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 /* -------------------- MDI client window functions ------------------- */
609 /**********************************************************************
610 * CreateMDIMenuBitmap
612 static HBITMAP16 CreateMDIMenuBitmap(void)
614 HDC32 hDCSrc = CreateCompatibleDC32(0);
615 HDC32 hDCDest = CreateCompatibleDC32(hDCSrc);
616 HBITMAP16 hbClose = LoadBitmap16(0, MAKEINTRESOURCE(OBM_CLOSE) );
617 HBITMAP16 hbCopy,hb_src,hb_dest;
619 hb_src = SelectObject32(hDCSrc,hbClose);
620 hbCopy = CreateCompatibleBitmap32(hDCSrc,SYSMETRICS_CXSIZE,SYSMETRICS_CYSIZE);
621 hb_dest = SelectObject32(hDCDest,hbCopy);
623 BitBlt32(hDCDest, 0, 0, SYSMETRICS_CXSIZE, SYSMETRICS_CYSIZE,
624 hDCSrc, SYSMETRICS_CXSIZE, 0, SRCCOPY);
626 SelectObject32(hDCSrc,hb_src);
627 SelectObject32(hDCDest,hb_dest);
629 DeleteObject32(hbClose);
631 DeleteDC32(hDCDest);
632 DeleteDC32(hDCSrc);
634 return hbCopy;
637 /**********************************************************************
638 * MDICascade
640 static LONG MDICascade(WND* clientWnd, MDICLIENTINFO *ci)
642 WND** ppWnd;
643 UINT32 total;
645 if (ci->hwndChildMaximized)
646 ShowWindow16( ci->hwndChildMaximized, SW_NORMAL);
648 if (ci->nActiveChildren == 0) return 0;
650 if ((ppWnd = WIN_BuildWinArray(clientWnd, BWA_SKIPHIDDEN | BWA_SKIPOWNED |
651 BWA_SKIPICONIC, &total)))
653 WND** heapPtr = ppWnd;
654 if( total )
656 INT16 delta = 0, n = 0;
657 POINT16 pos[2];
658 if( total < ci->nActiveChildren )
659 delta = SYSMETRICS_CYICONSPACING + SYSMETRICS_CYICON;
661 /* walk the list and move windows */
662 while ( *ppWnd )
664 dprintf_mdi(stddeb, "MDICascade: move %04x to (%d,%d) size [%d,%d]\n",
665 (*ppWnd)->hwndSelf, pos[0].x, pos[0].y, pos[1].x, pos[1].y);
667 MDI_CalcDefaultChildPos(clientWnd, n++, pos, delta);
668 SetWindowPos32((*ppWnd)->hwndSelf, 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
669 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
670 ppWnd++;
673 HeapFree( SystemHeap, 0, heapPtr );
676 if( total < ci->nActiveChildren ) ArrangeIconicWindows32( clientWnd->hwndSelf );
677 return 0;
680 /**********************************************************************
681 * MDITile
683 static LONG MDITile(WND* wndClient, MDICLIENTINFO *ci,WORD wParam)
685 WND** ppWnd;
686 UINT32 total = 0;
688 if (ci->hwndChildMaximized)
689 ShowWindow16(ci->hwndChildMaximized, SW_NORMAL);
691 if (ci->nActiveChildren == 0) return 0;
693 ppWnd = WIN_BuildWinArray(wndClient, BWA_SKIPHIDDEN | BWA_SKIPOWNED | BWA_SKIPICONIC |
694 ((wParam & MDITILE_SKIPDISABLED)? BWA_SKIPDISABLED : 0), &total );
696 dprintf_mdi(stddeb,"MDITile: %u windows to tile\n", total);
698 if( ppWnd )
700 WND** heapPtr = ppWnd;
702 if( total )
704 RECT16 rect;
705 int x, y, xsize, ysize;
706 int rows, columns, r, c, i;
708 rect = wndClient->rectClient;
709 rows = (int) sqrt((double)total);
710 columns = total / rows;
712 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
714 i = rows;
715 rows = columns; /* exchange r and c */
716 columns = i;
719 if( total != ci->nActiveChildren)
721 y = rect.bottom - 2 * SYSMETRICS_CYICONSPACING - SYSMETRICS_CYICON;
722 rect.bottom = ( y - SYSMETRICS_CYICON < rect.top )? rect.bottom: y;
725 ysize = rect.bottom / rows;
726 xsize = rect.right / columns;
728 for (x = i = 0, c = 1; c <= columns && *ppWnd; c++)
730 if (c == columns)
732 rows = total - i;
733 ysize = rect.bottom / rows;
736 y = 0;
737 for (r = 1; r <= rows && *ppWnd; r++, i++)
739 SetWindowPos32((*ppWnd)->hwndSelf, 0, x, y, xsize, ysize,
740 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
741 y += ysize;
742 ppWnd++;
744 x += xsize;
747 HeapFree( SystemHeap, 0, heapPtr );
750 if( total < ci->nActiveChildren ) ArrangeIconicWindows32( wndClient->hwndSelf );
751 return 0;
754 /* ----------------------- Frame window ---------------------------- */
757 /**********************************************************************
758 * MDI_AugmentFrameMenu
760 static BOOL32 MDI_AugmentFrameMenu( MDICLIENTINFO* ci, WND *frame,
761 HWND16 hChild )
763 WND* child = WIN_FindWndPtr(hChild);
764 HMENU16 hSysPopup = 0;
766 dprintf_mdi(stddeb,"MDI_AugmentFrameMenu: frame %p,child %04x\n",frame,hChild);
768 if( !frame->wIDmenu || !child->hSysMenu ) return 0;
770 /* create a copy of sysmenu popup and insert it into frame menu bar */
772 if (!(hSysPopup = LoadMenuIndirect32A(SYSRES_GetResPtr(SYSRES_MENU_SYSMENU))))
773 return 0;
775 dprintf_mdi(stddeb,"\t\tgot popup %04x\n in sysmenu %04x",hSysPopup,child->hSysMenu);
777 if( !InsertMenu32A(frame->wIDmenu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
778 hSysPopup, (LPSTR)(DWORD)hBmpClose ))
779 { DestroyMenu32(hSysPopup); return 0; }
781 if( !AppendMenu32A(frame->wIDmenu,MF_HELP | MF_BITMAP,
782 SC_RESTORE, (LPSTR)(DWORD)hBmpRestore ))
784 RemoveMenu32(frame->wIDmenu,0,MF_BYPOSITION);
785 return 0;
788 EnableMenuItem32(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
789 EnableMenuItem32(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
790 EnableMenuItem32(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
792 /* redraw menu */
793 DrawMenuBar32(frame->hwndSelf);
795 return 1;
798 /**********************************************************************
799 * MDI_RestoreFrameMenu
801 static BOOL32 MDI_RestoreFrameMenu( WND *frameWnd, HWND16 hChild )
803 INT32 nItems = GetMenuItemCount32(frameWnd->wIDmenu) - 1;
805 dprintf_mdi(stddeb,"MDI_RestoreFrameMenu: for child %04x\n",hChild);
807 if( GetMenuItemID32(frameWnd->wIDmenu,nItems) != SC_RESTORE )
808 return 0;
811 RemoveMenu32(frameWnd->wIDmenu,0,MF_BYPOSITION);
812 DeleteMenu32(frameWnd->wIDmenu,nItems-1,MF_BYPOSITION);
814 DrawMenuBar32(frameWnd->hwndSelf);
816 return 1;
819 /**********************************************************************
820 * MDI_UpdateFrameText
822 * used when child window is maximized/restored
824 * Note: lpTitle can be NULL
826 static void MDI_UpdateFrameText( WND *frameWnd, HWND16 hClient,
827 BOOL32 repaint, LPCSTR lpTitle )
829 char lpBuffer[MDI_MAXTITLELENGTH+1];
830 WND* clientWnd = WIN_FindWndPtr(hClient);
832 MDICLIENTINFO *ci = (MDICLIENTINFO *) clientWnd->wExtra;
834 dprintf_mdi(stddeb, "MDI: repaint %i, frameText %s\n", repaint, (lpTitle)?lpTitle:"NULL");
836 /* store new "default" title if lpTitle is not NULL */
837 if (lpTitle)
839 if (ci->frameTitle) HeapFree( SystemHeap, 0, ci->frameTitle );
840 ci->frameTitle = HEAP_strdupA( SystemHeap, 0, lpTitle );
843 if (ci->frameTitle)
845 WND* childWnd = WIN_FindWndPtr( ci->hwndChildMaximized );
847 if( childWnd && childWnd->text )
849 /* combine frame title and child title if possible */
851 LPCSTR lpBracket = " - [";
852 int i_frame_text_length = strlen(ci->frameTitle);
853 int i_child_text_length = strlen(childWnd->text);
855 lstrcpyn32A( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
857 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
859 strcat( lpBuffer, lpBracket );
861 if( i_frame_text_length + i_child_text_length + 6 < MDI_MAXTITLELENGTH )
863 strcat( lpBuffer, childWnd->text );
864 strcat( lpBuffer, "]" );
866 else
868 lstrcpyn32A( lpBuffer + i_frame_text_length + 4,
869 childWnd->text,
870 MDI_MAXTITLELENGTH - i_frame_text_length - 5 );
871 strcat( lpBuffer, "]" );
875 else
877 strncpy(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH );
878 lpBuffer[MDI_MAXTITLELENGTH]='\0';
881 else
882 lpBuffer[0] = '\0';
884 DEFWND_SetText( frameWnd, lpBuffer );
885 if( repaint == MDI_REPAINTFRAME)
886 SetWindowPos32(frameWnd->hwndSelf, 0,0,0,0,0, SWP_FRAMECHANGED |
887 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
891 /* ----------------------------- Interface ---------------------------- */
894 /**********************************************************************
895 * MDIClientWndProc
897 * This function is the handler for all MDI requests.
899 LRESULT MDIClientWndProc(HWND16 hwnd, UINT16 message, WPARAM16 wParam, LPARAM lParam)
901 LPCREATESTRUCT16 cs;
902 MDICLIENTINFO *ci;
903 RECT16 rect;
904 WND *w = WIN_FindWndPtr(hwnd);
905 WND *frameWnd = w->parent;
906 INT32 nItems;
908 ci = (MDICLIENTINFO *) w->wExtra;
910 switch (message)
912 case WM_CREATE:
914 cs = (LPCREATESTRUCT16) PTR_SEG_TO_LIN(lParam);
916 /* Translation layer doesn't know what's in the cs->lpCreateParams
917 * so we have to keep track of what environment we're in. */
919 if( w->flags & WIN_ISWIN32 )
921 #define ccs ((LPCLIENTCREATESTRUCT32)cs->lpCreateParams)
922 ci->hWindowMenu = ccs->hWindowMenu;
923 ci->idFirstChild = ccs->idFirstChild;
924 #undef ccs
926 else
928 LPCLIENTCREATESTRUCT16 ccs = (LPCLIENTCREATESTRUCT16)
929 PTR_SEG_TO_LIN(cs->lpCreateParams);
930 ci->hWindowMenu = ccs->hWindowMenu;
931 ci->idFirstChild = ccs->idFirstChild;
934 ci->hwndChildMaximized = 0;
935 ci->nActiveChildren = 0;
936 ci->nTotalCreated = 0;
937 ci->frameTitle = NULL;
938 ci->mdiFlags = 0;
939 ci->self = hwnd;
940 w->dwStyle |= WS_CLIPCHILDREN;
942 if (!hBmpClose)
944 hBmpClose = CreateMDIMenuBitmap();
945 hBmpRestore = LoadBitmap16( 0, MAKEINTRESOURCE(OBM_RESTORE) );
947 MDI_UpdateFrameText(frameWnd, hwnd, MDI_NOFRAMEREPAINT,frameWnd->text);
949 AppendMenu32A( ci->hWindowMenu, MF_SEPARATOR, 0, NULL );
951 GetClientRect16(frameWnd->hwndSelf, &rect);
952 NC_HandleNCCalcSize( w, &rect );
953 w->rectClient = rect;
955 dprintf_mdi(stddeb,"MDI: Client created - hwnd = %04x, idFirst = %u\n",hwnd,ci->idFirstChild);
957 return 0;
959 case WM_DESTROY:
960 if( ci->hwndChildMaximized ) MDI_RestoreFrameMenu(w, frameWnd->hwndSelf);
961 if((nItems = GetMenuItemCount32(ci->hWindowMenu)) > 0) {
962 ci->idFirstChild = nItems - 1;
963 ci->nActiveChildren++; /* to delete a separator */
964 while( ci->nActiveChildren-- )
965 DeleteMenu32(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
967 return 0;
969 case WM_MDIACTIVATE:
970 if( ci->hwndActiveChild != (HWND16)wParam )
971 SetWindowPos32((HWND32)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
972 return 0;
974 case WM_MDICASCADE:
975 return MDICascade(w, ci);
977 case WM_MDICREATE:
978 if( lParam )
980 MDICREATESTRUCT16* cs = (MDICREATESTRUCT16*) PTR_SEG_TO_LIN(lParam);
981 return (LONG)MDICreateChild(w, ci, hwnd, cs, lParam );
983 return 0;
985 case WM_MDIDESTROY:
986 return (LONG)MDIDestroyChild(w, ci, hwnd, (HWND32)wParam, TRUE);
988 case WM_MDIGETACTIVE:
989 return ((LONG) ci->hwndActiveChild |
990 ((LONG) (ci->hwndChildMaximized>0) << 16));
992 case WM_MDIICONARRANGE:
993 ci->mdiFlags |= MDIF_NEEDUPDATE;
994 MDIIconArrange(hwnd);
995 ci->sbRecalc = SB_BOTH+1;
996 SendMessage16(hwnd,WM_MDICALCCHILDSCROLL,0,0L);
997 return 0;
999 case WM_MDIMAXIMIZE:
1000 ShowWindow16((HWND16)wParam, SW_MAXIMIZE);
1001 return 0;
1003 case WM_MDINEXT:
1004 MDI_SwitchActiveChild(hwnd, (HWND16)wParam, (lParam)?1:0);
1005 break;
1007 case WM_MDIRESTORE:
1008 ShowWindow16( (HWND16)wParam, SW_NORMAL);
1009 return 0;
1011 case WM_MDISETMENU:
1012 #ifdef WINELIB32
1013 return (LRESULT)MDISetMenu(hwnd, FALSE, (HMENU16)wParam, (HMENU16)lParam);
1014 #else
1015 return (LRESULT)MDISetMenu(hwnd, wParam, LOWORD(lParam), HIWORD(lParam));
1016 #endif
1018 case WM_MDITILE:
1019 ci->mdiFlags |= MDIF_NEEDUPDATE;
1020 ShowScrollBar32(hwnd,SB_BOTH,FALSE);
1021 MDITile(w, ci,wParam);
1022 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1023 return 0;
1025 case WM_VSCROLL:
1026 case WM_HSCROLL:
1027 ci->mdiFlags |= MDIF_NEEDUPDATE;
1028 ScrollChildren32(hwnd,message,wParam,lParam);
1029 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1030 return 0;
1032 case WM_SETFOCUS:
1033 if( ci->hwndActiveChild )
1035 w = WIN_FindWndPtr( ci->hwndActiveChild );
1036 if( !(w->dwStyle & WS_MINIMIZE) )
1037 SetFocus32( ci->hwndActiveChild );
1039 return 0;
1041 case WM_NCACTIVATE:
1042 if( ci->hwndActiveChild )
1043 SendMessage16(ci->hwndActiveChild, message, wParam, lParam);
1044 break;
1046 case WM_PARENTNOTIFY:
1047 if( wParam == WM_LBUTTONDOWN )
1049 POINT16 pt = MAKEPOINT16(lParam);
1050 HWND16 child = ChildWindowFromPoint16(hwnd, pt);
1052 dprintf_mdi(stddeb,"MDIClient: notification from %04x (%i,%i)\n",child,pt.x,pt.y);
1054 if( child && child != hwnd &&
1055 child != ci->hwndActiveChild )
1056 SetWindowPos32(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1058 return 0;
1060 case WM_SIZE:
1061 if( ci->hwndChildMaximized )
1063 WND* child = WIN_FindWndPtr(ci->hwndChildMaximized);
1064 RECT16 rect = { 0, 0, LOWORD(lParam), HIWORD(lParam) };
1066 AdjustWindowRectEx16(&rect, child->dwStyle, 0, child->dwExStyle);
1067 MoveWindow16(ci->hwndChildMaximized, rect.left, rect.top,
1068 rect.right - rect.left, rect.bottom - rect.top, 1);
1070 else
1071 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1073 break;
1075 case WM_MDICALCCHILDSCROLL:
1076 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1078 CalcChildScroll(hwnd, ci->sbRecalc-1);
1079 ci->sbRecalc = 0;
1080 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1082 return 0;
1085 return DefWindowProc16(hwnd, message, wParam, lParam);
1089 /***********************************************************************
1090 * DefFrameProc16 (USER.445)
1092 LRESULT DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient, UINT16 message,
1093 WPARAM16 wParam, LPARAM lParam )
1095 HWND16 childHwnd;
1096 MDICLIENTINFO* ci;
1097 WND* wndPtr;
1099 if (hwndMDIClient)
1101 switch (message)
1103 case WM_COMMAND:
1104 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1105 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1107 /* check for possible syscommands for maximized MDI child */
1109 if( ci && (
1110 wParam < ci->idFirstChild ||
1111 wParam >= ci->idFirstChild + ci->nActiveChildren
1113 if( (wParam - 0xF000) & 0xF00F ) break;
1114 switch( wParam )
1116 case SC_SIZE:
1117 case SC_MOVE:
1118 case SC_MINIMIZE:
1119 case SC_MAXIMIZE:
1120 case SC_NEXTWINDOW:
1121 case SC_PREVWINDOW:
1122 case SC_CLOSE:
1123 case SC_RESTORE:
1124 if( ci->hwndChildMaximized )
1125 return SendMessage16( ci->hwndChildMaximized, WM_SYSCOMMAND,
1126 wParam, lParam);
1129 else
1131 childHwnd = MDI_GetChildByID( WIN_FindWndPtr(hwndMDIClient),
1132 wParam );
1133 if( childHwnd )
1134 SendMessage16(hwndMDIClient, WM_MDIACTIVATE,
1135 (WPARAM16)childHwnd , 0L);
1137 break;
1139 case WM_NCACTIVATE:
1140 SendMessage16(hwndMDIClient, message, wParam, lParam);
1141 break;
1143 case WM_SETTEXT:
1144 MDI_UpdateFrameText(WIN_FindWndPtr(hwnd), hwndMDIClient,
1145 MDI_REPAINTFRAME,
1146 (LPCSTR)PTR_SEG_TO_LIN(lParam));
1147 return 0;
1149 case WM_SETFOCUS:
1150 SetFocus32(hwndMDIClient);
1151 break;
1153 case WM_SIZE:
1154 MoveWindow16(hwndMDIClient, 0, 0,
1155 LOWORD(lParam), HIWORD(lParam), TRUE);
1156 break;
1158 case WM_NEXTMENU:
1160 wndPtr = WIN_FindWndPtr(hwndMDIClient);
1161 ci = (MDICLIENTINFO*)wndPtr->wExtra;
1163 if( !(wndPtr->parent->dwStyle & WS_MINIMIZE)
1164 && ci->hwndActiveChild && !ci->hwndChildMaximized )
1166 /* control menu is between the frame system menu and
1167 * the first entry of menu bar */
1169 if( (wParam == VK_LEFT &&
1170 wndPtr->parent->wIDmenu == LOWORD(lParam)) ||
1171 (wParam == VK_RIGHT &&
1172 GetSubMenu16(wndPtr->parent->hSysMenu, 0) == LOWORD(lParam)) )
1174 wndPtr = WIN_FindWndPtr(ci->hwndActiveChild);
1175 return MAKELONG( GetSubMenu16(wndPtr->hSysMenu, 0),
1176 ci->hwndActiveChild);
1179 break;
1183 return DefWindowProc16(hwnd, message, wParam, lParam);
1187 /***********************************************************************
1188 * DefFrameProc32A (USER32.121)
1190 LRESULT DefFrameProc32A( HWND32 hwnd, HWND32 hwndMDIClient, UINT32 message,
1191 WPARAM32 wParam, LPARAM lParam )
1193 if (hwndMDIClient)
1195 switch (message)
1197 case WM_COMMAND:
1198 return DefFrameProc16( hwnd, hwndMDIClient, message,
1199 (WPARAM16)wParam,
1200 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1202 case WM_NCACTIVATE:
1203 SendMessage32A(hwndMDIClient, message, wParam, lParam);
1204 break;
1206 case WM_SETTEXT: {
1207 LRESULT ret;
1208 LPSTR segstr = SEGPTR_STRDUP((LPSTR)lParam);
1210 ret = DefFrameProc16(hwnd, hwndMDIClient, message,
1211 wParam, (LPARAM)SEGPTR_GET(segstr) );
1212 SEGPTR_FREE(segstr);
1213 return ret;
1216 case WM_SETFOCUS:
1217 case WM_SIZE:
1218 return DefFrameProc16( hwnd, hwndMDIClient, message,
1219 wParam, lParam );
1223 return DefWindowProc32A(hwnd, message, wParam, lParam);
1227 /***********************************************************************
1228 * DefFrameProc32W (USER32.122)
1230 LRESULT DefFrameProc32W( HWND32 hwnd, HWND32 hwndMDIClient, UINT32 message,
1231 WPARAM32 wParam, LPARAM lParam )
1233 if (hwndMDIClient)
1235 switch (message)
1237 case WM_COMMAND:
1238 return DefFrameProc16( hwnd, hwndMDIClient, message,
1239 (WPARAM16)wParam,
1240 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ) );
1242 case WM_NCACTIVATE:
1243 SendMessage32W(hwndMDIClient, message, wParam, lParam);
1244 break;
1246 case WM_SETTEXT: {
1247 LPSTR txt = HEAP_strdupWtoA(GetProcessHeap(),0,(LPWSTR)lParam);
1248 LRESULT ret = DefFrameProc32A( hwnd, hwndMDIClient, message,
1249 wParam, (DWORD)txt );
1250 HeapFree(GetProcessHeap(),0,txt);
1251 return ret;
1253 case WM_SETFOCUS:
1254 case WM_SIZE:
1255 return DefFrameProc32A( hwnd, hwndMDIClient, message,
1256 wParam, lParam );
1260 return DefWindowProc32W( hwnd, message, wParam, lParam );
1264 /***********************************************************************
1265 * DefMDIChildProc16 (USER.447)
1267 LRESULT DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1268 WPARAM16 wParam, LPARAM lParam )
1270 MDICLIENTINFO *ci;
1271 WND *clientWnd;
1273 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1274 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1276 switch (message)
1278 case WM_SETTEXT:
1279 DefWindowProc16(hwnd, message, wParam, lParam);
1280 MDI_MenuModifyItem(clientWnd,hwnd);
1281 if( ci->hwndChildMaximized == hwnd )
1282 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1283 MDI_REPAINTFRAME, NULL );
1284 return 0;
1286 case WM_CLOSE:
1287 SendMessage16(ci->self,WM_MDIDESTROY,(WPARAM16)hwnd,0L);
1288 return 0;
1290 case WM_SETFOCUS:
1291 if( ci->hwndActiveChild != hwnd )
1292 MDI_ChildActivate(clientWnd, hwnd);
1293 break;
1295 case WM_CHILDACTIVATE:
1296 MDI_ChildActivate(clientWnd, hwnd);
1297 return 0;
1299 case WM_NCPAINT:
1300 dprintf_mdi(stddeb,"DefMDIChildProc: WM_NCPAINT for %04x, active %04x\n",
1301 hwnd, ci->hwndActiveChild );
1302 break;
1304 case WM_SYSCOMMAND:
1305 switch( wParam )
1307 case SC_MOVE:
1308 if( ci->hwndChildMaximized == hwnd) return 0;
1309 break;
1310 case SC_RESTORE:
1311 case SC_MINIMIZE:
1312 WIN_FindWndPtr(hwnd)->dwStyle |= WS_SYSMENU;
1313 break;
1314 case SC_MAXIMIZE:
1315 if( ci->hwndChildMaximized == hwnd)
1316 return SendMessage16( clientWnd->parent->hwndSelf,
1317 message, wParam, lParam);
1318 WIN_FindWndPtr(hwnd)->dwStyle &= ~WS_SYSMENU;
1319 break;
1320 case SC_NEXTWINDOW:
1321 SendMessage16( ci->self, WM_MDINEXT, 0, 0);
1322 return 0;
1323 case SC_PREVWINDOW:
1324 SendMessage16( ci->self, WM_MDINEXT, 0, 1);
1325 return 0;
1327 break;
1329 case WM_GETMINMAXINFO:
1330 MDI_ChildGetMinMaxInfo(clientWnd, hwnd, (MINMAXINFO16*) PTR_SEG_TO_LIN(lParam));
1331 return 0;
1333 case WM_SETVISIBLE:
1334 if( ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1335 else
1336 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1337 break;
1339 case WM_SIZE:
1340 /* do not change */
1342 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1344 ci->hwndChildMaximized = 0;
1346 MDI_RestoreFrameMenu( clientWnd->parent, hwnd);
1347 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1348 MDI_REPAINTFRAME, NULL );
1351 if( wParam == SIZE_MAXIMIZED )
1353 HWND16 hMaxChild = ci->hwndChildMaximized;
1355 if( hMaxChild == hwnd ) break;
1357 if( hMaxChild)
1359 SendMessage16( hMaxChild, WM_SETREDRAW, FALSE, 0L );
1361 MDI_RestoreFrameMenu( clientWnd->parent, hMaxChild);
1362 ShowWindow16( hMaxChild, SW_SHOWNOACTIVATE);
1364 SendMessage16( hMaxChild, WM_SETREDRAW, TRUE, 0L );
1367 dprintf_mdi(stddeb,"\tMDI: maximizing child %04x\n", hwnd );
1369 ci->hwndChildMaximized = hwnd; /* !!! */
1371 MDI_AugmentFrameMenu( ci, clientWnd->parent, hwnd);
1372 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1373 MDI_REPAINTFRAME, NULL );
1376 if( wParam == SIZE_MINIMIZED )
1378 HWND16 switchTo = MDI_GetWindow(clientWnd, hwnd, 0);
1380 if( switchTo )
1381 SendMessage16( switchTo, WM_CHILDACTIVATE, 0, 0L);
1384 MDI_PostUpdate(clientWnd->hwndSelf, ci, SB_BOTH+1);
1385 break;
1387 case WM_MENUCHAR:
1389 /* MDI children don't have menu bars */
1390 PostMessage16( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1391 (WPARAM16)SC_KEYMENU, (LPARAM)wParam);
1392 return 0x00010000L;
1394 case WM_NEXTMENU:
1396 if( wParam == VK_LEFT ) /* switch to frame system menu */
1397 return MAKELONG( GetSubMenu16(clientWnd->parent->hSysMenu, 0),
1398 clientWnd->parent->hwndSelf );
1399 if( wParam == VK_RIGHT ) /* to frame menu bar */
1400 return MAKELONG( clientWnd->parent->wIDmenu,
1401 clientWnd->parent->hwndSelf );
1403 break;
1406 return DefWindowProc16(hwnd, message, wParam, lParam);
1410 /***********************************************************************
1411 * DefMDIChildProc32A (USER32.123)
1413 LRESULT DefMDIChildProc32A( HWND32 hwnd, UINT32 message,
1414 WPARAM32 wParam, LPARAM lParam )
1416 MDICLIENTINFO *ci;
1417 WND *clientWnd;
1419 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1420 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1422 switch (message)
1424 case WM_SETTEXT:
1425 DefWindowProc32A(hwnd, message, wParam, lParam);
1426 MDI_MenuModifyItem(clientWnd,hwnd);
1427 if( ci->hwndChildMaximized == hwnd )
1428 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1429 MDI_REPAINTFRAME, NULL );
1430 return 0;
1432 case WM_GETMINMAXINFO:
1434 MINMAXINFO16 mmi;
1435 STRUCT32_MINMAXINFO32to16( (MINMAXINFO32 *)lParam, &mmi );
1436 MDI_ChildGetMinMaxInfo( clientWnd, hwnd, &mmi );
1437 STRUCT32_MINMAXINFO16to32( &mmi, (MINMAXINFO32 *)lParam );
1439 return 0;
1441 case WM_MENUCHAR:
1443 /* MDI children don't have menu bars */
1444 PostMessage16( clientWnd->parent->hwndSelf, WM_SYSCOMMAND,
1445 (WPARAM16)SC_KEYMENU, (LPARAM)LOWORD(wParam) );
1446 return 0x00010000L;
1448 case WM_CLOSE:
1449 case WM_SETFOCUS:
1450 case WM_CHILDACTIVATE:
1451 case WM_NCPAINT:
1452 case WM_SYSCOMMAND:
1453 case WM_SETVISIBLE:
1454 case WM_SIZE:
1455 case WM_NEXTMENU:
1456 return DefMDIChildProc16( hwnd, message, (WPARAM16)wParam, lParam );
1458 return DefWindowProc32A(hwnd, message, wParam, lParam);
1462 /***********************************************************************
1463 * DefMDIChildProc32W (USER32.124)
1465 LRESULT DefMDIChildProc32W( HWND32 hwnd, UINT32 message,
1466 WPARAM32 wParam, LPARAM lParam )
1468 MDICLIENTINFO *ci;
1469 WND *clientWnd;
1471 clientWnd = WIN_FindWndPtr(GetParent16(hwnd));
1472 ci = (MDICLIENTINFO *) clientWnd->wExtra;
1474 switch (message)
1476 case WM_SETTEXT:
1477 DefWindowProc32W(hwnd, message, wParam, lParam);
1478 MDI_MenuModifyItem(clientWnd,hwnd);
1479 if( ci->hwndChildMaximized == hwnd )
1480 MDI_UpdateFrameText( clientWnd->parent, ci->self,
1481 MDI_REPAINTFRAME, NULL );
1482 return 0;
1484 case WM_GETMINMAXINFO:
1485 case WM_MENUCHAR:
1486 case WM_CLOSE:
1487 case WM_SETFOCUS:
1488 case WM_CHILDACTIVATE:
1489 case WM_NCPAINT:
1490 case WM_SYSCOMMAND:
1491 case WM_SETVISIBLE:
1492 case WM_SIZE:
1493 case WM_NEXTMENU:
1494 return DefMDIChildProc32A( hwnd, message, (WPARAM16)wParam, lParam );
1496 return DefWindowProc32W(hwnd, message, wParam, lParam);
1500 /**********************************************************************
1501 * CreateMDIWindowA (USER32.78)
1504 /**********************************************************************
1505 * CreateMDIWindowW (USER32.79)
1508 /**********************************************************************
1509 * TranslateMDISysAccel32 (USER32.554)
1511 BOOL32 TranslateMDISysAccel32( HWND32 hwndClient, LPMSG32 msg )
1513 MSG16 msg16;
1515 STRUCT32_MSG32to16(msg,&msg16);
1516 /* MDICLIENTINFO is still the same for win32 and win16 ... */
1517 return TranslateMDISysAccel16(hwndClient,&msg16);
1521 /**********************************************************************
1522 * TranslateMDISysAccel16 (USER.451)
1524 BOOL16 TranslateMDISysAccel16( HWND16 hwndClient, LPMSG16 msg )
1526 WND* clientWnd = WIN_FindWndPtr( hwndClient);
1528 if( clientWnd && (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN))
1530 MDICLIENTINFO *ci = NULL;
1531 WND* wnd;
1533 ci = (MDICLIENTINFO*) clientWnd->wExtra;
1534 wnd = WIN_FindWndPtr(ci->hwndActiveChild);
1535 if( wnd && !(wnd->dwStyle & WS_DISABLED) )
1537 WPARAM16 wParam = 0;
1539 /* translate if the Ctrl key is down and Alt not. */
1541 if( (GetKeyState32(VK_CONTROL) & 0x8000) &&
1542 !(GetKeyState32(VK_MENU) & 0x8000))
1544 switch( msg->wParam )
1546 case VK_F6:
1547 case VK_SEPARATOR:
1548 wParam = ( GetKeyState32(VK_SHIFT) & 0x8000 )
1549 ? SC_NEXTWINDOW : SC_PREVWINDOW;
1550 break;
1551 case VK_F4:
1552 case VK_RBUTTON:
1553 wParam = SC_CLOSE;
1554 break;
1555 default:
1556 return 0;
1558 dprintf_mdi(stddeb,"TranslateMDISysAccel: wParam = %04x\n", wParam);
1559 SendMessage16( ci->hwndActiveChild, WM_SYSCOMMAND,
1560 wParam, (LPARAM)msg->wParam);
1561 return 1;
1565 return 0; /* failure */
1569 /***********************************************************************
1570 * CalcChildScroll (USER.462)
1572 void CalcChildScroll( HWND16 hwnd, WORD scroll )
1574 RECT16 childRect, clientRect;
1575 INT32 vmin, vmax, hmin, hmax, vpos, hpos;
1576 BOOL32 noscroll = FALSE;
1577 WND *pWnd, *Wnd;
1579 if (!(Wnd = pWnd = WIN_FindWndPtr( hwnd ))) return;
1580 GetClientRect16( hwnd, &clientRect );
1581 SetRectEmpty16( &childRect );
1583 for ( pWnd = pWnd->child; pWnd; pWnd = pWnd->next )
1585 UnionRect16( &childRect, &pWnd->rectWindow, &childRect );
1586 if( pWnd->dwStyle & WS_MAXIMIZE )
1587 noscroll = TRUE;
1589 UnionRect16( &childRect, &clientRect, &childRect );
1591 /* jump through the hoops to prevent excessive flashing
1594 hmin = childRect.left; hmax = childRect.right - clientRect.right;
1595 hpos = clientRect.left - childRect.left;
1596 vmin = childRect.top; vmax = childRect.bottom - clientRect.bottom;
1597 vpos = clientRect.top - childRect.top;
1599 if( noscroll )
1600 ShowScrollBar32(hwnd, SB_BOTH, FALSE);
1601 else
1602 switch( scroll )
1604 case SB_HORZ:
1605 vpos = hpos; vmin = hmin; vmax = hmax;
1606 case SB_VERT:
1607 SetScrollPos32(hwnd, scroll, vpos, FALSE);
1608 SetScrollRange32(hwnd, scroll, vmin, vmax, TRUE);
1609 break;
1610 case SB_BOTH:
1611 SCROLL_SetNCSbState( Wnd, vmin, vmax, vpos,
1612 hmin, hmax, hpos);
1613 SetWindowPos32(hwnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE
1614 | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED );
1619 /***********************************************************************
1620 * ScrollChildren16 (USER.463)
1622 void ScrollChildren16(HWND16 hWnd, UINT16 uMsg, WPARAM16 wParam, LPARAM lParam)
1624 return ScrollChildren32( hWnd, uMsg, wParam, lParam );
1628 /***********************************************************************
1629 * ScrollChildren32 (USER32.447)
1631 void ScrollChildren32(HWND32 hWnd, UINT32 uMsg, WPARAM32 wParam, LPARAM lParam)
1633 WND *wndPtr = WIN_FindWndPtr(hWnd);
1634 INT32 newPos = -1;
1635 INT32 curPos, length, minPos, maxPos, shift;
1637 if( !wndPtr ) return;
1639 if( uMsg == WM_HSCROLL )
1641 GetScrollRange32(hWnd,SB_HORZ,&minPos,&maxPos);
1642 curPos = GetScrollPos32(hWnd,SB_HORZ);
1643 length = (wndPtr->rectClient.right - wndPtr->rectClient.left)/2;
1644 shift = SYSMETRICS_CYHSCROLL;
1646 else if( uMsg == WM_VSCROLL )
1648 GetScrollRange32(hWnd,SB_VERT,&minPos,&maxPos);
1649 curPos = GetScrollPos32(hWnd,SB_VERT);
1650 length = (wndPtr->rectClient.bottom - wndPtr->rectClient.top)/2;
1651 shift = SYSMETRICS_CXVSCROLL;
1653 else return;
1655 switch( wParam )
1657 case SB_LINEUP:
1658 newPos = curPos - shift;
1659 break;
1660 case SB_LINEDOWN:
1661 newPos = curPos + shift;
1662 break;
1663 case SB_PAGEUP:
1664 newPos = curPos - length;
1665 break;
1666 case SB_PAGEDOWN:
1667 newPos = curPos + length;
1668 break;
1670 case SB_THUMBPOSITION:
1671 newPos = LOWORD(lParam);
1672 break;
1674 case SB_THUMBTRACK:
1675 return;
1677 case SB_TOP:
1678 newPos = minPos;
1679 break;
1680 case SB_BOTTOM:
1681 newPos = maxPos;
1682 break;
1683 case SB_ENDSCROLL:
1684 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
1685 return;
1688 if( newPos > maxPos )
1689 newPos = maxPos;
1690 else if( newPos < minPos )
1691 newPos = minPos;
1693 SetScrollPos32(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
1695 if( uMsg == WM_VSCROLL )
1696 ScrollWindow32(hWnd ,0 ,curPos - newPos, NULL, NULL);
1697 else
1698 ScrollWindow32(hWnd ,curPos - newPos, 0, NULL, NULL);