Added Russian translation.
[wine.git] / windows / mdi.c
blob365c9a0fb990ce8c3cdf5e4618897d03e4b152b9
1 /* MDI.C
3 * Copyright 1994, Bob Amstadt
4 * 1995,1996 Alex Korobka
6 * This file contains routines to support MDI (Multiple Document
7 * Interface) features .
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Notes: Fairly complete implementation.
24 * Also, Excel and WinWord do _not_ use MDI so if you're trying
25 * to fix them look elsewhere.
27 * Notes on how the "More Windows..." is implemented:
29 * When we have more than 9 opened windows, a "More Windows..."
30 * option appears in the "Windows" menu. Each child window has
31 * a WND* associated with it, accesible via the children list of
32 * the parent window. This WND* has a wIDmenu member, which reflects
33 * the position of the child in the window list. For example, with
34 * 9 child windows, we could have the following pattern:
38 * Name of the child window pWndChild->wIDmenu
39 * Doc1 5000
40 * Doc2 5001
41 * Doc3 5002
42 * Doc4 5003
43 * Doc5 5004
44 * Doc6 5005
45 * Doc7 5006
46 * Doc8 5007
47 * Doc9 5008
50 * The "Windows" menu, as the "More windows..." dialog, are constructed
51 * in this order. If we add a child, we would have the following list:
54 * Name of the child window pWndChild->wIDmenu
55 * Doc1 5000
56 * Doc2 5001
57 * Doc3 5002
58 * Doc4 5003
59 * Doc5 5004
60 * Doc6 5005
61 * Doc7 5006
62 * Doc8 5007
63 * Doc9 5008
64 * Doc10 5009
66 * But only 5000 to 5008 would be displayed in the "Windows" menu. We want
67 * the last created child to be in the menu, so we swap the last child with
68 * the 9th... Doc9 will be accessible via the "More Windows..." option.
70 * Doc1 5000
71 * Doc2 5001
72 * Doc3 5002
73 * Doc4 5003
74 * Doc5 5004
75 * Doc6 5005
76 * Doc7 5006
77 * Doc8 5007
78 * Doc9 5009
79 * Doc10 5008
83 #include <stdlib.h>
84 #include <stdarg.h>
85 #include <stdio.h>
86 #include <string.h>
87 #include <math.h>
89 #include "windef.h"
90 #include "winbase.h"
91 #include "wingdi.h"
92 #include "winuser.h"
93 #include "wownt32.h"
94 #include "wine/unicode.h"
95 #include "win.h"
96 #include "nonclient.h"
97 #include "controls.h"
98 #include "user.h"
99 #include "struct32.h"
100 #include "wine/debug.h"
101 #include "dlgs.h"
103 WINE_DEFAULT_DEBUG_CHANNEL(mdi);
105 #define MDI_MAXLISTLENGTH 0x40
106 #define MDI_MAXTITLELENGTH 0xa1
108 #define MDI_NOFRAMEREPAINT 0
109 #define MDI_REPAINTFRAMENOW 1
110 #define MDI_REPAINTFRAME 2
112 #define WM_MDICALCCHILDSCROLL 0x10ac /* this is exactly what Windows uses */
114 /* "More Windows..." definitions */
115 #define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
116 option will appear under the Windows menu */
117 #define MDI_IDC_LISTBOX 100
118 #define IDS_MDI_MOREWINDOWS 13
120 #define MDIF_NEEDUPDATE 0x0001
122 typedef struct
124 UINT nActiveChildren;
125 HWND hwndChildMaximized;
126 HWND hwndActiveChild;
127 HMENU hWindowMenu;
128 UINT idFirstChild;
129 LPWSTR frameTitle;
130 UINT nTotalCreated;
131 UINT mdiFlags;
132 UINT sbRecalc; /* SB_xxx flags for scrollbar fixup */
133 } MDICLIENTINFO;
135 static HBITMAP hBmpClose = 0;
137 /* ----------------- declarations ----------------- */
138 static void MDI_UpdateFrameText( HWND, HWND, BOOL, LPCWSTR);
139 static BOOL MDI_AugmentFrameMenu( HWND, HWND );
140 static BOOL MDI_RestoreFrameMenu( HWND, HWND );
141 static LONG MDI_ChildActivate( HWND, HWND );
143 static HWND MDI_MoreWindowsDialog(HWND);
144 static void MDI_SwapMenuItems(HWND, UINT, UINT);
145 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
146 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
148 /* -------- Miscellaneous service functions ----------
150 * MDI_GetChildByID
152 static HWND MDI_GetChildByID(HWND hwnd, UINT id)
154 HWND ret;
155 HWND *win_array;
156 int i;
158 if (!(win_array = WIN_ListChildren( hwnd ))) return 0;
159 for (i = 0; win_array[i]; i++)
161 if (GetWindowLongA( win_array[i], GWL_ID ) == id) break;
163 ret = win_array[i];
164 HeapFree( GetProcessHeap(), 0, win_array );
165 return ret;
168 static void MDI_PostUpdate(HWND hwnd, MDICLIENTINFO* ci, WORD recalc)
170 if( !(ci->mdiFlags & MDIF_NEEDUPDATE) )
172 ci->mdiFlags |= MDIF_NEEDUPDATE;
173 PostMessageA( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
175 ci->sbRecalc = recalc;
179 /*********************************************************************
180 * MDIClient class descriptor
182 const struct builtin_class_descr MDICLIENT_builtin_class =
184 "MDIClient", /* name */
185 CS_GLOBALCLASS, /* style */
186 MDIClientWndProcA, /* procA */
187 MDIClientWndProcW, /* procW */
188 sizeof(MDICLIENTINFO), /* extra */
189 IDC_ARROW, /* cursor */
190 (HBRUSH)(COLOR_APPWORKSPACE+1) /* brush */
194 static MDICLIENTINFO *get_client_info( HWND client )
196 MDICLIENTINFO *ret = NULL;
197 WND *win = WIN_GetPtr( client );
198 if (win)
200 if (win == WND_OTHER_PROCESS)
202 ERR( "client %p belongs to other process\n", client );
203 return NULL;
205 if (win->cbWndExtra < sizeof(MDICLIENTINFO)) WARN( "%p is not an MDI client\n", client );
206 else ret = (MDICLIENTINFO *)win->wExtra;
207 WIN_ReleasePtr( win );
209 return ret;
212 /**********************************************************************
213 * MDI_MenuModifyItem
215 static void MDI_MenuModifyItem( HWND client, HWND hWndChild )
217 MDICLIENTINFO *clientInfo = get_client_info( client );
218 WCHAR buffer[128];
219 UINT n, id;
221 if (!clientInfo || !clientInfo->hWindowMenu) return;
223 id = GetWindowLongA( hWndChild, GWL_ID );
224 if (id >= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT) return;
225 buffer[0] = '&';
226 buffer[1] = '1' + id - clientInfo->idFirstChild;
227 buffer[2] = ' ';
228 GetWindowTextW( hWndChild, buffer + 3, sizeof(buffer)/sizeof(WCHAR) - 3 );
230 n = GetMenuState(clientInfo->hWindowMenu, id, MF_BYCOMMAND);
231 ModifyMenuW(clientInfo->hWindowMenu, id, MF_BYCOMMAND | MF_STRING, id, buffer );
232 CheckMenuItem(clientInfo->hWindowMenu, id, n & MF_CHECKED);
235 /**********************************************************************
236 * MDI_MenuDeleteItem
238 static BOOL MDI_MenuDeleteItem( HWND client, HWND hWndChild )
240 WCHAR buffer[128];
241 static const WCHAR format[] = {'&','%','d',' ',0};
242 MDICLIENTINFO *clientInfo = get_client_info( client );
243 UINT index = 0,id,n;
245 if( !clientInfo->nActiveChildren || !clientInfo->hWindowMenu )
246 return FALSE;
248 id = GetWindowLongA( hWndChild, GWL_ID );
249 DeleteMenu(clientInfo->hWindowMenu,id,MF_BYCOMMAND);
251 /* walk the rest of MDI children to prevent gaps in the id
252 * sequence and in the menu child list */
254 for( index = id+1; index <= clientInfo->nActiveChildren +
255 clientInfo->idFirstChild; index++ )
257 HWND hwnd = MDI_GetChildByID(client,index);
258 if (!hwnd)
260 TRACE("no window for id=%i\n",index);
261 continue;
264 /* set correct id */
265 SetWindowLongW( hwnd, GWL_ID, GetWindowLongW( hwnd, GWL_ID ) - 1 );
267 n = wsprintfW(buffer, format ,index - clientInfo->idFirstChild);
268 GetWindowTextW( hwnd, buffer + n, sizeof(buffer)/sizeof(WCHAR) - n );
270 /* change menu if the current child is to be shown in the
271 * "Windows" menu
273 if (index <= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT)
274 ModifyMenuW(clientInfo->hWindowMenu ,index ,MF_BYCOMMAND | MF_STRING,
275 index - 1 , buffer );
278 /* We must restore the "More Windows..." option if there are enough children
280 if (clientInfo->nActiveChildren - 1 > MDI_MOREWINDOWSLIMIT)
282 WCHAR szTmp[50];
283 LoadStringW(GetModuleHandleA("USER32"), IDS_MDI_MOREWINDOWS, szTmp, sizeof(szTmp)/sizeof(szTmp[0]));
284 AppendMenuW(clientInfo->hWindowMenu, MF_STRING, clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT, szTmp);
286 return TRUE;
289 /**********************************************************************
290 * MDI_GetWindow
292 * returns "activateable" child different from the current or zero
294 static HWND MDI_GetWindow(MDICLIENTINFO *clientInfo, HWND hWnd, BOOL bNext,
295 DWORD dwStyleMask )
297 int i;
298 HWND *list;
299 HWND last = 0;
301 dwStyleMask |= WS_DISABLED | WS_VISIBLE;
302 if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
304 if (!(list = WIN_ListChildren( GetParent(hWnd) ))) return 0;
305 i = 0;
306 /* start from next after hWnd */
307 while (list[i] && list[i] != hWnd) i++;
308 if (list[i]) i++;
310 for ( ; list[i]; i++)
312 if (GetWindow( list[i], GW_OWNER )) continue;
313 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
314 last = list[i];
315 if (bNext) goto found;
317 /* now restart from the beginning */
318 for (i = 0; list[i] && list[i] != hWnd; i++)
320 if (GetWindow( list[i], GW_OWNER )) continue;
321 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
322 last = list[i];
323 if (bNext) goto found;
325 found:
326 HeapFree( GetProcessHeap(), 0, list );
327 return last;
330 /**********************************************************************
331 * MDI_CalcDefaultChildPos
333 * It seems that the default height is about 2/3 of the client rect
335 static void MDI_CalcDefaultChildPos( HWND hwnd, WORD n, LPPOINT lpPos, INT delta)
337 INT nstagger;
338 RECT rect;
339 INT spacing = GetSystemMetrics(SM_CYCAPTION) +
340 GetSystemMetrics(SM_CYFRAME) - 1;
342 GetClientRect( hwnd, &rect );
343 if( rect.bottom - rect.top - delta >= spacing )
344 rect.bottom -= delta;
346 nstagger = (rect.bottom - rect.top)/(3 * spacing);
347 lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
348 lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
349 lpPos[0].x = lpPos[0].y = spacing * (n%(nstagger+1));
352 /**********************************************************************
353 * MDISetMenu
355 static LRESULT MDISetMenu( HWND hwnd, HMENU hmenuFrame,
356 HMENU hmenuWindow)
358 MDICLIENTINFO *ci;
359 HWND hwndFrame = GetParent(hwnd);
360 HMENU oldFrameMenu = GetMenu(hwndFrame);
362 TRACE("%p %p %p\n", hwnd, hmenuFrame, hmenuWindow);
364 if (hmenuFrame && !IsMenu(hmenuFrame))
366 WARN("hmenuFrame is not a menu handle\n");
367 return 0L;
370 if (hmenuWindow && !IsMenu(hmenuWindow))
372 WARN("hmenuWindow is not a menu handle\n");
373 return 0L;
376 if (!(ci = get_client_info( hwnd ))) return 0;
378 if( ci->hwndChildMaximized && hmenuFrame && hmenuFrame!=oldFrameMenu )
379 MDI_RestoreFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
381 if( hmenuWindow && ci->hWindowMenu && hmenuWindow!=ci->hWindowMenu )
383 /* delete menu items from ci->hWindowMenu
384 * and add them to hmenuWindow */
386 INT i = GetMenuItemCount(ci->hWindowMenu) - 1;
387 INT pos = GetMenuItemCount(hmenuWindow) + 1;
389 AppendMenuA( hmenuWindow, MF_SEPARATOR, 0, NULL);
391 if( ci->nActiveChildren )
393 INT j;
394 LPWSTR buffer = NULL;
395 MENUITEMINFOW mii;
396 INT nbWindowsMenuItems; /* num of documents shown + "More Windows..." if present */
398 if (ci->nActiveChildren <= MDI_MOREWINDOWSLIMIT)
399 nbWindowsMenuItems = ci->nActiveChildren;
400 else
401 nbWindowsMenuItems = MDI_MOREWINDOWSLIMIT + 1;
403 j = i - nbWindowsMenuItems + 1;
405 for( ; i >= j ; i-- )
407 memset(&mii, 0, sizeof(mii));
408 mii.cbSize = sizeof(mii);
409 mii.fMask = MIIM_CHECKMARKS | MIIM_DATA | MIIM_ID | MIIM_STATE
410 | MIIM_SUBMENU | MIIM_TYPE | MIIM_BITMAP;
412 GetMenuItemInfoW(ci->hWindowMenu, i, TRUE, &mii);
413 if(mii.cch) { /* Menu is MFT_STRING */
414 mii.cch++; /* add room for '\0' */
415 buffer = HeapAlloc(GetProcessHeap(), 0,
416 mii.cch * sizeof(WCHAR));
417 mii.dwTypeData = buffer;
418 GetMenuItemInfoW(ci->hWindowMenu, i, TRUE, &mii);
420 DeleteMenu(ci->hWindowMenu, i, MF_BYPOSITION);
421 InsertMenuItemW(hmenuWindow, pos, TRUE, &mii);
422 if(buffer) {
423 HeapFree(GetProcessHeap(), 0, buffer);
424 buffer = NULL;
429 /* remove separator */
430 DeleteMenu(ci->hWindowMenu, i, MF_BYPOSITION);
432 ci->hWindowMenu = hmenuWindow;
435 if (hmenuFrame)
437 SetMenu(hwndFrame, hmenuFrame);
438 if( hmenuFrame!=oldFrameMenu )
440 if( ci->hwndChildMaximized )
441 MDI_AugmentFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
442 return (LRESULT)oldFrameMenu;
445 else
447 HMENU menu = GetMenu( GetParent(hwnd) );
448 INT nItems = GetMenuItemCount(menu) - 1;
449 UINT iId = GetMenuItemID(menu,nItems) ;
451 if( !(iId == SC_RESTORE || iId == SC_CLOSE) )
453 /* SetMenu() may already have been called, meaning that this window
454 * already has its menu. But they may have done a SetMenu() on
455 * an MDI window, and called MDISetMenu() after the fact, meaning
456 * that the "if" to this "else" wouldn't catch the need to
457 * augment the frame menu.
459 if( ci->hwndChildMaximized )
460 MDI_AugmentFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
463 return 0;
466 /**********************************************************************
467 * MDIRefreshMenu
469 static LRESULT MDIRefreshMenu( HWND hwnd, HMENU hmenuFrame,
470 HMENU hmenuWindow)
472 HWND hwndFrame = GetParent(hwnd);
473 HMENU oldFrameMenu = GetMenu(hwndFrame);
475 TRACE("%p %p %p\n", hwnd, hmenuFrame, hmenuWindow);
477 FIXME("partially function stub\n");
479 return (LRESULT)oldFrameMenu;
483 /* ------------------ MDI child window functions ---------------------- */
486 /**********************************************************************
487 * MDICreateChild
489 static HWND MDICreateChild( HWND parent, MDICLIENTINFO *ci,
490 LPMDICREATESTRUCTA cs, BOOL unicode )
492 POINT pos[2];
493 DWORD style = cs->style | (WS_CHILD | WS_CLIPSIBLINGS);
494 HWND hwnd, hwndMax = 0;
495 UINT wIDmenu = ci->idFirstChild + ci->nActiveChildren;
496 WND *wndParent;
497 static const WCHAR lpstrDef[] = {'j','u','n','k','!',0};
499 TRACE("origin %i,%i - dim %i,%i, style %08lx\n",
500 cs->x, cs->y, cs->cx, cs->cy, cs->style);
501 /* calculate placement */
502 MDI_CalcDefaultChildPos(parent, ci->nTotalCreated++, pos, 0);
504 if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16 || !cs->cx) cs->cx = pos[1].x;
505 if (cs->cy == CW_USEDEFAULT || cs->cy == CW_USEDEFAULT16 || !cs->cy) cs->cy = pos[1].y;
507 if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
509 cs->x = pos[0].x;
510 cs->y = pos[0].y;
513 /* restore current maximized child */
514 if( (style & WS_VISIBLE) && ci->hwndChildMaximized )
516 TRACE("Restoring current maximized child %p\n", ci->hwndChildMaximized);
517 if( style & WS_MAXIMIZE )
518 SendMessageW(parent, WM_SETREDRAW, FALSE, 0L);
519 hwndMax = ci->hwndChildMaximized;
520 ShowWindow( hwndMax, SW_SHOWNOACTIVATE );
521 if( style & WS_MAXIMIZE )
522 SendMessageW(parent, WM_SETREDRAW, TRUE, 0L);
525 if (ci->nActiveChildren <= MDI_MOREWINDOWSLIMIT)
526 /* this menu is needed to set a check mark in MDI_ChildActivate */
527 if (ci->hWindowMenu != 0)
528 AppendMenuW(ci->hWindowMenu, MF_STRING, wIDmenu, lpstrDef);
530 ci->nActiveChildren++;
532 /* fix window style */
533 wndParent = WIN_FindWndPtr( parent );
534 if( !(wndParent->dwStyle & MDIS_ALLCHILDSTYLES) )
536 TRACE("MDIS_ALLCHILDSTYLES is missing, fixing window style\n");
537 style &= (WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZE | WS_MAXIMIZE |
538 WS_CLIPCHILDREN | WS_DISABLED | WS_VSCROLL | WS_HSCROLL );
539 style |= (WS_VISIBLE | WS_OVERLAPPEDWINDOW);
542 if( wndParent->flags & WIN_ISWIN32 )
544 WIN_ReleaseWndPtr( wndParent );
545 if(unicode)
547 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)cs;
548 hwnd = CreateWindowW( csW->szClass, csW->szTitle, style,
549 csW->x, csW->y, csW->cx, csW->cy, parent,
550 (HMENU)wIDmenu, csW->hOwner, csW );
552 else
553 hwnd = CreateWindowA( cs->szClass, cs->szTitle, style,
554 cs->x, cs->y, cs->cx, cs->cy, parent,
555 (HMENU)wIDmenu, cs->hOwner, cs );
557 else
559 MDICREATESTRUCT16 cs16;
560 SEGPTR title, cls, seg_cs16;
562 WIN_ReleaseWndPtr( wndParent );
563 STRUCT32_MDICREATESTRUCT32Ato16( cs, &cs16 );
564 cs16.szTitle = title = MapLS( cs->szTitle );
565 cs16.szClass = cls = MapLS( cs->szClass );
566 seg_cs16 = MapLS( &cs16 );
567 hwnd = WIN_Handle32( CreateWindow16( cs->szClass, cs->szTitle, style,
568 cs16.x, cs16.y, cs16.cx, cs16.cy,
569 HWND_16(parent), (HMENU16)wIDmenu,
570 cs16.hOwner, (LPVOID)seg_cs16 ));
571 UnMapLS( seg_cs16 );
572 UnMapLS( title );
573 UnMapLS( cls );
576 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
578 if (hwnd)
580 /* All MDI child windows have the WS_EX_MDICHILD style */
581 SetWindowLongW( hwnd, GWL_EXSTYLE, GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_MDICHILD );
583 /* If we have more than 9 windows, we must insert the new one at the
584 * 9th position in order to see it in the "Windows" menu
586 if (ci->nActiveChildren > MDI_MOREWINDOWSLIMIT)
587 MDI_SwapMenuItems( parent, GetWindowLongW( hwnd, GWL_ID ),
588 ci->idFirstChild + MDI_MOREWINDOWSLIMIT - 1);
590 MDI_MenuModifyItem(parent, hwnd);
592 /* Have we hit the "More Windows..." limit? If so, we must
593 * add a "More Windows..." option
595 if (ci->nActiveChildren == MDI_MOREWINDOWSLIMIT + 1)
597 WCHAR szTmp[50];
598 LoadStringW(GetModuleHandleA("USER32"), IDS_MDI_MOREWINDOWS, szTmp, sizeof(szTmp)/sizeof(szTmp[0]));
600 ModifyMenuW(ci->hWindowMenu,
601 ci->idFirstChild + MDI_MOREWINDOWSLIMIT,
602 MF_BYCOMMAND | MF_STRING,
603 ci->idFirstChild + MDI_MOREWINDOWSLIMIT,
604 szTmp);
607 if( IsIconic(hwnd) && ci->hwndActiveChild )
609 TRACE("Minimizing created MDI child %p\n", hwnd);
610 ShowWindow( hwnd, SW_SHOWMINNOACTIVE );
612 else
614 /* WS_VISIBLE is clear if a) the MDI client has
615 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
616 * MDICreateStruct. If so the created window is not shown nor
617 * activated.
619 if (IsWindowVisible(hwnd)) ShowWindow(hwnd, SW_SHOW);
621 TRACE("created child - %p\n",hwnd);
623 else
625 ci->nActiveChildren--;
626 DeleteMenu(ci->hWindowMenu,wIDmenu,MF_BYCOMMAND);
627 if( IsWindow(hwndMax) )
628 ShowWindow(hwndMax, SW_SHOWMAXIMIZED);
631 return hwnd;
634 /**********************************************************************
635 * MDI_ChildGetMinMaxInfo
637 * Note: The rule here is that client rect of the maximized MDI child
638 * is equal to the client rect of the MDI client window.
640 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
642 RECT rect;
644 GetClientRect( client, &rect );
645 AdjustWindowRectEx( &rect, GetWindowLongW( hwnd, GWL_STYLE ),
646 0, GetWindowLongW( hwnd, GWL_EXSTYLE ));
648 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
649 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
651 lpMinMax->ptMaxPosition.x = rect.left;
652 lpMinMax->ptMaxPosition.y = rect.top;
654 TRACE("max rect (%ld,%ld - %ld, %ld)\n",
655 rect.left,rect.top,rect.right,rect.bottom);
658 /**********************************************************************
659 * MDI_SwitchActiveChild
661 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
662 * being activated
664 static void MDI_SwitchActiveChild( HWND clientHwnd, HWND childHwnd,
665 BOOL bNextWindow )
667 HWND hwndTo = 0;
668 HWND hwndPrev = 0;
669 MDICLIENTINFO *ci = get_client_info( clientHwnd );
671 hwndTo = MDI_GetWindow(ci, childHwnd, bNextWindow, 0);
673 TRACE("from %p, to %p\n",childHwnd,hwndTo);
675 if ( !hwndTo ) return; /* no window to switch to */
677 hwndPrev = ci->hwndActiveChild;
679 if ( hwndTo != hwndPrev )
681 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0,
682 SWP_NOMOVE | SWP_NOSIZE );
684 if( bNextWindow && hwndPrev )
685 SetWindowPos( hwndPrev, HWND_BOTTOM, 0, 0, 0, 0,
686 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
691 /**********************************************************************
692 * MDIDestroyChild
694 static LRESULT MDIDestroyChild( HWND parent, MDICLIENTINFO *ci,
695 HWND child, BOOL flagDestroy )
697 if( child == ci->hwndActiveChild )
699 MDI_SwitchActiveChild(parent, child, TRUE);
701 if( child == ci->hwndActiveChild )
703 ShowWindow( child, SW_HIDE);
704 if( child == ci->hwndChildMaximized )
706 HWND frame = GetParent(parent);
707 MDI_RestoreFrameMenu( frame, child );
708 ci->hwndChildMaximized = 0;
709 MDI_UpdateFrameText( frame, parent, TRUE, NULL);
712 MDI_ChildActivate(parent, 0);
716 MDI_MenuDeleteItem(parent, child);
718 ci->nActiveChildren--;
720 TRACE("child destroyed - %p\n",child);
722 if (flagDestroy)
724 MDI_PostUpdate(GetParent(child), ci, SB_BOTH+1);
725 DestroyWindow(child);
727 return 0;
731 /**********************************************************************
732 * MDI_ChildActivate
734 * Note: hWndChild is NULL when last child is being destroyed
736 static LONG MDI_ChildActivate( HWND client, HWND child )
738 MDICLIENTINFO *clientInfo = get_client_info( client );
739 HWND prevActiveWnd = clientInfo->hwndActiveChild;
740 BOOL isActiveFrameWnd;
742 if (child && (!IsWindowEnabled( child ))) return 0;
744 /* Don't activate if it is already active. Might happen
745 since ShowWindow DOES activate MDI children */
746 if (clientInfo->hwndActiveChild == child) return 0;
748 TRACE("%p\n", child);
750 isActiveFrameWnd = (GetActiveWindow() == GetParent(client));
752 /* deactivate prev. active child */
753 if(prevActiveWnd)
755 SetWindowLongA( prevActiveWnd, GWL_STYLE,
756 GetWindowLongA( prevActiveWnd, GWL_STYLE ) | WS_SYSMENU );
757 SendMessageA( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
758 SendMessageA( prevActiveWnd, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child);
759 /* uncheck menu item */
760 if( clientInfo->hWindowMenu )
762 UINT prevID = GetWindowLongA( prevActiveWnd, GWL_ID );
764 if (prevID - clientInfo->idFirstChild < MDI_MOREWINDOWSLIMIT)
765 CheckMenuItem( clientInfo->hWindowMenu, prevID, 0);
766 else
767 CheckMenuItem( clientInfo->hWindowMenu,
768 clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1, 0);
772 /* set appearance */
773 if (clientInfo->hwndChildMaximized && clientInfo->hwndChildMaximized != child)
775 INT cmd = SW_SHOWNORMAL;
777 if( child )
779 UINT state = GetMenuState(GetSystemMenu(child, FALSE), SC_MAXIMIZE, MF_BYCOMMAND);
780 if (state != 0xFFFFFFFF && (state & (MF_DISABLED | MF_GRAYED)))
781 SendMessageW(clientInfo->hwndChildMaximized, WM_SYSCOMMAND, SC_RESTORE, 0);
782 else
783 cmd = SW_SHOWMAXIMIZED;
785 clientInfo->hwndActiveChild = child;
788 ShowWindow( clientInfo->hwndActiveChild, cmd );
791 clientInfo->hwndActiveChild = child;
793 /* check if we have any children left */
794 if( !child )
796 if( isActiveFrameWnd )
797 SetFocus( client );
798 return 0;
801 /* check menu item */
802 if( clientInfo->hWindowMenu )
804 UINT id = GetWindowLongA( child, GWL_ID );
805 /* The window to be activated must be displayed in the "Windows" menu */
806 if (id >= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT)
808 MDI_SwapMenuItems( GetParent(child),
809 id, clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1);
810 id = clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1;
811 MDI_MenuModifyItem( GetParent(child), child );
814 CheckMenuItem(clientInfo->hWindowMenu, id, MF_CHECKED);
816 /* bring active child to the top */
817 SetWindowPos( child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
819 if( isActiveFrameWnd )
821 SendMessageA( child, WM_NCACTIVATE, TRUE, 0L);
822 if( GetFocus() == client )
823 SendMessageA( client, WM_SETFOCUS, (WPARAM)client, 0L );
824 else
825 SetFocus( client );
827 SendMessageA( child, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child );
828 return TRUE;
831 /* -------------------- MDI client window functions ------------------- */
833 /**********************************************************************
834 * CreateMDIMenuBitmap
836 static HBITMAP CreateMDIMenuBitmap(void)
838 HDC hDCSrc = CreateCompatibleDC(0);
839 HDC hDCDest = CreateCompatibleDC(hDCSrc);
840 HBITMAP hbClose = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_OLD_CLOSE) );
841 HBITMAP hbCopy;
842 HBITMAP hobjSrc, hobjDest;
844 hobjSrc = SelectObject(hDCSrc, hbClose);
845 hbCopy = CreateCompatibleBitmap(hDCSrc,GetSystemMetrics(SM_CXSIZE),GetSystemMetrics(SM_CYSIZE));
846 hobjDest = SelectObject(hDCDest, hbCopy);
848 BitBlt(hDCDest, 0, 0, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE),
849 hDCSrc, GetSystemMetrics(SM_CXSIZE), 0, SRCCOPY);
851 SelectObject(hDCSrc, hobjSrc);
852 DeleteObject(hbClose);
853 DeleteDC(hDCSrc);
855 hobjSrc = SelectObject( hDCDest, GetStockObject(BLACK_PEN) );
857 MoveToEx( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, 0, NULL );
858 LineTo( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, GetSystemMetrics(SM_CYSIZE) - 1);
860 SelectObject(hDCDest, hobjSrc );
861 SelectObject(hDCDest, hobjDest);
862 DeleteDC(hDCDest);
864 return hbCopy;
867 /**********************************************************************
868 * MDICascade
870 static LONG MDICascade( HWND client, MDICLIENTINFO *ci )
872 HWND *win_array;
873 BOOL has_icons = FALSE;
874 int i, total;
876 if (ci->hwndChildMaximized)
877 SendMessageA( client, WM_MDIRESTORE,
878 (WPARAM)ci->hwndChildMaximized, 0);
880 if (ci->nActiveChildren == 0) return 0;
882 if (!(win_array = WIN_ListChildren( client ))) return 0;
884 /* remove all the windows we don't want */
885 for (i = total = 0; win_array[i]; i++)
887 if (!IsWindowVisible( win_array[i] )) continue;
888 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows */
889 if (IsIconic( win_array[i] ))
891 has_icons = TRUE;
892 continue;
894 win_array[total++] = win_array[i];
896 win_array[total] = 0;
898 if (total)
900 INT delta = 0, n = 0, i;
901 POINT pos[2];
902 if (has_icons) delta = GetSystemMetrics(SM_CYICONSPACING) + GetSystemMetrics(SM_CYICON);
904 /* walk the list (backwards) and move windows */
905 for (i = total - 1; i >= 0; i--)
907 TRACE("move %p to (%ld,%ld) size [%ld,%ld]\n",
908 win_array[i], pos[0].x, pos[0].y, pos[1].x, pos[1].y);
910 MDI_CalcDefaultChildPos(client, n++, pos, delta);
911 SetWindowPos( win_array[i], 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
912 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
915 HeapFree( GetProcessHeap(), 0, win_array );
917 if (has_icons) ArrangeIconicWindows( client );
918 return 0;
921 /**********************************************************************
922 * MDITile
924 static void MDITile( HWND client, MDICLIENTINFO *ci, WPARAM wParam )
926 HWND *win_array;
927 int i, total;
928 BOOL has_icons = FALSE;
930 if (ci->hwndChildMaximized)
931 SendMessageA( client, WM_MDIRESTORE, (WPARAM)ci->hwndChildMaximized, 0);
933 if (ci->nActiveChildren == 0) return;
935 if (!(win_array = WIN_ListChildren( client ))) return;
937 /* remove all the windows we don't want */
938 for (i = total = 0; win_array[i]; i++)
940 if (!IsWindowVisible( win_array[i] )) continue;
941 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows (icon titles) */
942 if (IsIconic( win_array[i] ))
944 has_icons = TRUE;
945 continue;
947 if ((wParam & MDITILE_SKIPDISABLED) && !IsWindowEnabled( win_array[i] )) continue;
948 win_array[total++] = win_array[i];
950 win_array[total] = 0;
952 TRACE("%u windows to tile\n", total);
954 if (total)
956 HWND *pWnd = win_array;
957 RECT rect;
958 int x, y, xsize, ysize;
959 int rows, columns, r, c, i;
961 GetClientRect(client,&rect);
962 rows = (int) sqrt((double)total);
963 columns = total / rows;
965 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
967 i = rows;
968 rows = columns; /* exchange r and c */
969 columns = i;
972 if (has_icons)
974 y = rect.bottom - 2 * GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
975 rect.bottom = ( y - GetSystemMetrics(SM_CYICON) < rect.top )? rect.bottom: y;
978 ysize = rect.bottom / rows;
979 xsize = rect.right / columns;
981 for (x = i = 0, c = 1; c <= columns && *pWnd; c++)
983 if (c == columns)
985 rows = total - i;
986 ysize = rect.bottom / rows;
989 y = 0;
990 for (r = 1; r <= rows && *pWnd; r++, i++)
992 SetWindowPos(*pWnd, 0, x, y, xsize, ysize,
993 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
994 y += ysize;
995 pWnd++;
997 x += xsize;
1000 HeapFree( GetProcessHeap(), 0, win_array );
1001 if (has_icons) ArrangeIconicWindows( client );
1004 /* ----------------------- Frame window ---------------------------- */
1007 /**********************************************************************
1008 * MDI_AugmentFrameMenu
1010 static BOOL MDI_AugmentFrameMenu( HWND frame, HWND hChild )
1012 HMENU menu = GetMenu( frame );
1013 WND* child = WIN_FindWndPtr(hChild);
1014 HMENU hSysPopup = 0;
1015 HBITMAP hSysMenuBitmap = 0;
1017 TRACE("frame %p,child %p\n",frame,hChild);
1019 if( !menu || !child->hSysMenu )
1021 WIN_ReleaseWndPtr(child);
1022 return 0;
1024 WIN_ReleaseWndPtr(child);
1026 /* create a copy of sysmenu popup and insert it into frame menu bar */
1028 if (!(hSysPopup = LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU")))
1029 return 0;
1031 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1032 SC_MINIMIZE, (LPSTR)(DWORD)HBMMENU_MBAR_MINIMIZE ) ;
1033 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1034 SC_RESTORE, (LPSTR)(DWORD)HBMMENU_MBAR_RESTORE );
1036 /* In Win 95 look, the system menu is replaced by the child icon */
1038 if(TWEAK_WineLook > WIN31_LOOK)
1040 HICON hIcon = (HICON)GetClassLongA(hChild, GCL_HICONSM);
1041 if (!hIcon)
1042 hIcon = (HICON)GetClassLongA(hChild, GCL_HICON);
1043 if (hIcon)
1045 HDC hMemDC;
1046 HBITMAP hBitmap, hOldBitmap;
1047 HBRUSH hBrush;
1048 HDC hdc = GetDC(hChild);
1050 if (hdc)
1052 int cx, cy;
1053 cx = GetSystemMetrics(SM_CXSMICON);
1054 cy = GetSystemMetrics(SM_CYSMICON);
1055 hMemDC = CreateCompatibleDC(hdc);
1056 hBitmap = CreateCompatibleBitmap(hdc, cx, cy);
1057 hOldBitmap = SelectObject(hMemDC, hBitmap);
1058 SetMapMode(hMemDC, MM_TEXT);
1059 hBrush = CreateSolidBrush(GetSysColor(COLOR_MENU));
1060 DrawIconEx(hMemDC, 0, 0, hIcon, cx, cy, 0, hBrush, DI_NORMAL);
1061 SelectObject (hMemDC, hOldBitmap);
1062 DeleteObject(hBrush);
1063 DeleteDC(hMemDC);
1064 ReleaseDC(hChild, hdc);
1065 hSysMenuBitmap = hBitmap;
1069 else
1070 hSysMenuBitmap = hBmpClose;
1072 if( !InsertMenuA(menu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
1073 (UINT_PTR)hSysPopup, (LPSTR)hSysMenuBitmap))
1075 TRACE("not inserted\n");
1076 DestroyMenu(hSysPopup);
1077 return 0;
1080 /* The close button is only present in Win 95 look */
1081 if(TWEAK_WineLook > WIN31_LOOK)
1083 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1084 SC_CLOSE, (LPSTR)(DWORD)HBMMENU_MBAR_CLOSE );
1087 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
1088 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
1089 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
1090 SetMenuDefaultItem(hSysPopup, SC_CLOSE, FALSE);
1092 /* redraw menu */
1093 DrawMenuBar(frame);
1095 return 1;
1098 /**********************************************************************
1099 * MDI_RestoreFrameMenu
1101 static BOOL MDI_RestoreFrameMenu( HWND frame, HWND hChild )
1103 MENUITEMINFOW menuInfo;
1104 HMENU menu = GetMenu( frame );
1105 INT nItems = GetMenuItemCount(menu) - 1;
1106 UINT iId = GetMenuItemID(menu,nItems) ;
1108 TRACE("frame %p,child %p,nIt=%d,iId=%d\n",frame,hChild,nItems,iId);
1110 if(!(iId == SC_RESTORE || iId == SC_CLOSE) )
1111 return 0;
1114 * Remove the system menu, If that menu is the icon of the window
1115 * as it is in win95, we have to delete the bitmap.
1117 memset(&menuInfo, 0, sizeof(menuInfo));
1118 menuInfo.cbSize = sizeof(menuInfo);
1119 menuInfo.fMask = MIIM_DATA | MIIM_TYPE;
1121 GetMenuItemInfoW(menu,
1123 TRUE,
1124 &menuInfo);
1126 RemoveMenu(menu,0,MF_BYPOSITION);
1128 if ( (menuInfo.fType & MFT_BITMAP) &&
1129 (LOWORD(menuInfo.dwTypeData)!=0) &&
1130 (LOWORD(menuInfo.dwTypeData)!=HBITMAP_16(hBmpClose)) )
1132 DeleteObject(HBITMAP_32(LOWORD(menuInfo.dwTypeData)));
1135 if(TWEAK_WineLook > WIN31_LOOK)
1137 /* close */
1138 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1140 /* restore */
1141 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1142 /* minimize */
1143 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1145 DrawMenuBar(frame);
1147 return 1;
1151 /**********************************************************************
1152 * MDI_UpdateFrameText
1154 * used when child window is maximized/restored
1156 * Note: lpTitle can be NULL
1158 static void MDI_UpdateFrameText( HWND frame, HWND hClient,
1159 BOOL repaint, LPCWSTR lpTitle )
1161 WCHAR lpBuffer[MDI_MAXTITLELENGTH+1];
1162 MDICLIENTINFO *ci = get_client_info( hClient );
1164 TRACE("repaint %i, frameText %s\n", repaint, debugstr_w(lpTitle));
1166 if (!ci) return;
1168 if (!lpTitle && !ci->frameTitle) /* first time around, get title from the frame window */
1170 GetWindowTextW( frame, lpBuffer, sizeof(lpBuffer)/sizeof(WCHAR) );
1171 lpTitle = lpBuffer;
1174 /* store new "default" title if lpTitle is not NULL */
1175 if (lpTitle)
1177 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1178 if ((ci->frameTitle = HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle)+1)*sizeof(WCHAR))))
1179 strcpyW( ci->frameTitle, lpTitle );
1182 if (ci->frameTitle)
1184 if (ci->hwndChildMaximized)
1186 /* combine frame title and child title if possible */
1188 static const WCHAR lpBracket[] = {' ','-',' ','[',0};
1189 static const WCHAR lpBracket2[] = {']',0};
1190 int i_frame_text_length = strlenW(ci->frameTitle);
1192 lstrcpynW( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
1194 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
1196 strcatW( lpBuffer, lpBracket );
1197 if (GetWindowTextW( ci->hwndChildMaximized, lpBuffer + i_frame_text_length + 4,
1198 MDI_MAXTITLELENGTH - i_frame_text_length - 5 ))
1199 strcatW( lpBuffer, lpBracket2 );
1200 else
1201 lpBuffer[i_frame_text_length] = 0; /* remove bracket */
1204 else
1206 lstrcpynW(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH+1 );
1209 else
1210 lpBuffer[0] = '\0';
1212 DefWindowProcW( frame, WM_SETTEXT, 0, (LPARAM)lpBuffer );
1213 if( repaint == MDI_REPAINTFRAME)
1214 SetWindowPos( frame, 0,0,0,0,0, SWP_FRAMECHANGED |
1215 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
1219 /* ----------------------------- Interface ---------------------------- */
1222 /**********************************************************************
1223 * MDIClientWndProc_common
1225 static LRESULT MDIClientWndProc_common( HWND hwnd, UINT message,
1226 WPARAM wParam, LPARAM lParam, BOOL unicode )
1228 MDICLIENTINFO *ci;
1230 if (!(ci = get_client_info( hwnd ))) return 0;
1232 switch (message)
1234 case WM_CREATE:
1236 RECT rect;
1237 /* Since we are using only cs->lpCreateParams, we can safely
1238 * cast to LPCREATESTRUCTA here */
1239 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
1240 WND *wndPtr = WIN_GetPtr( hwnd );
1242 /* Translation layer doesn't know what's in the cs->lpCreateParams
1243 * so we have to keep track of what environment we're in. */
1245 if( wndPtr->flags & WIN_ISWIN32 )
1247 #define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1248 ci->hWindowMenu = ccs->hWindowMenu;
1249 ci->idFirstChild = ccs->idFirstChild;
1250 #undef ccs
1252 else
1254 LPCLIENTCREATESTRUCT16 ccs = MapSL((SEGPTR)cs->lpCreateParams);
1255 ci->hWindowMenu = HMENU_32(ccs->hWindowMenu);
1256 ci->idFirstChild = ccs->idFirstChild;
1258 WIN_ReleasePtr( wndPtr );
1260 ci->hwndChildMaximized = 0;
1261 ci->nActiveChildren = 0;
1262 ci->nTotalCreated = 0;
1263 ci->frameTitle = NULL;
1264 ci->mdiFlags = 0;
1265 SetWindowLongW( hwnd, GWL_STYLE, GetWindowLongW(hwnd,GWL_STYLE) | WS_CLIPCHILDREN );
1267 if (!hBmpClose) hBmpClose = CreateMDIMenuBitmap();
1269 if (ci->hWindowMenu != 0)
1270 AppendMenuW( ci->hWindowMenu, MF_SEPARATOR, 0, NULL );
1272 GetClientRect( GetParent(hwnd), &rect);
1273 MoveWindow( hwnd, 0, 0, rect.right, rect.bottom, FALSE );
1275 MDI_UpdateFrameText( GetParent(hwnd), hwnd, MDI_NOFRAMEREPAINT, NULL);
1277 TRACE("Client created - hwnd = %p, idFirst = %u\n", hwnd, ci->idFirstChild );
1278 return 0;
1281 case WM_DESTROY:
1283 INT nItems;
1284 if( ci->hwndChildMaximized )
1285 MDI_RestoreFrameMenu( GetParent(hwnd), ci->hwndChildMaximized);
1286 if((ci->hWindowMenu != 0) &&
1287 (nItems = GetMenuItemCount(ci->hWindowMenu)) > 0)
1289 ci->idFirstChild = nItems - 1;
1290 ci->nActiveChildren++; /* to delete a separator */
1291 while( ci->nActiveChildren-- )
1292 DeleteMenu(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
1294 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1295 return 0;
1298 case WM_MDIACTIVATE:
1299 if( ci->hwndActiveChild != (HWND)wParam )
1300 SetWindowPos((HWND)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
1301 return 0;
1303 case WM_MDICASCADE:
1304 return MDICascade(hwnd, ci);
1306 case WM_MDICREATE:
1307 if (lParam)
1308 return (LRESULT)MDICreateChild( hwnd, ci, (MDICREATESTRUCTA *)lParam, unicode );
1309 return 0;
1311 case WM_MDIDESTROY:
1312 return MDIDestroyChild( hwnd, ci, WIN_GetFullHandle( (HWND)wParam ), TRUE );
1314 case WM_MDIGETACTIVE:
1315 if (lParam) *(BOOL *)lParam = (ci->hwndChildMaximized != 0);
1316 return (LRESULT)ci->hwndActiveChild;
1318 case WM_MDIICONARRANGE:
1319 ci->mdiFlags |= MDIF_NEEDUPDATE;
1320 ArrangeIconicWindows( hwnd );
1321 ci->sbRecalc = SB_BOTH+1;
1322 SendMessageW( hwnd, WM_MDICALCCHILDSCROLL, 0, 0 );
1323 return 0;
1325 case WM_MDIMAXIMIZE:
1326 ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1327 return 0;
1329 case WM_MDINEXT: /* lParam != 0 means previous window */
1330 MDI_SwitchActiveChild( hwnd, WIN_GetFullHandle( (HWND)wParam ), !lParam );
1331 break;
1333 case WM_MDIRESTORE:
1334 SendMessageW( (HWND)wParam, WM_SYSCOMMAND, SC_RESTORE, 0);
1335 return 0;
1337 case WM_MDISETMENU:
1338 return MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1340 case WM_MDIREFRESHMENU:
1341 return MDIRefreshMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1343 case WM_MDITILE:
1344 ci->mdiFlags |= MDIF_NEEDUPDATE;
1345 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1346 MDITile( hwnd, ci, wParam );
1347 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1348 return 0;
1350 case WM_VSCROLL:
1351 case WM_HSCROLL:
1352 ci->mdiFlags |= MDIF_NEEDUPDATE;
1353 ScrollChildren( hwnd, message, wParam, lParam );
1354 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1355 return 0;
1357 case WM_SETFOCUS:
1358 if (ci->hwndActiveChild && !IsIconic( ci->hwndActiveChild ))
1359 SetFocus( ci->hwndActiveChild );
1360 return 0;
1362 case WM_NCACTIVATE:
1363 if( ci->hwndActiveChild )
1364 SendMessageW(ci->hwndActiveChild, message, wParam, lParam);
1365 break;
1367 case WM_PARENTNOTIFY:
1368 if (LOWORD(wParam) == WM_LBUTTONDOWN)
1370 HWND child;
1371 POINT pt;
1372 pt.x = (short)LOWORD(lParam);
1373 pt.y = (short)HIWORD(lParam);
1374 child = ChildWindowFromPoint(hwnd, pt);
1376 TRACE("notification from %p (%li,%li)\n",child,pt.x,pt.y);
1378 if( child && child != hwnd && child != ci->hwndActiveChild )
1379 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1381 return 0;
1383 case WM_SIZE:
1384 if( IsWindow(ci->hwndChildMaximized) )
1386 RECT rect;
1388 rect.left = 0;
1389 rect.top = 0;
1390 rect.right = LOWORD(lParam);
1391 rect.bottom = HIWORD(lParam);
1393 AdjustWindowRectEx(&rect, GetWindowLongA(ci->hwndChildMaximized,GWL_STYLE),
1394 0, GetWindowLongA(ci->hwndChildMaximized,GWL_EXSTYLE) );
1395 MoveWindow(ci->hwndChildMaximized, rect.left, rect.top,
1396 rect.right - rect.left, rect.bottom - rect.top, 1);
1398 else
1399 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1401 break;
1403 case WM_MDICALCCHILDSCROLL:
1404 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1406 CalcChildScroll(hwnd, ci->sbRecalc-1);
1407 ci->sbRecalc = 0;
1408 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1410 return 0;
1412 return unicode ? DefWindowProcW( hwnd, message, wParam, lParam ) :
1413 DefWindowProcA( hwnd, message, wParam, lParam );
1416 /***********************************************************************
1417 * MDIClientWndProcA
1419 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1421 if (!IsWindow(hwnd)) return 0;
1422 return MDIClientWndProc_common( hwnd, message, wParam, lParam, FALSE );
1425 /***********************************************************************
1426 * MDIClientWndProcW
1428 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1430 if (!IsWindow(hwnd)) return 0;
1431 return MDIClientWndProc_common( hwnd, message, wParam, lParam, TRUE );
1434 /***********************************************************************
1435 * DefFrameProc (USER.445)
1437 LRESULT WINAPI DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient,
1438 UINT16 message, WPARAM16 wParam, LPARAM lParam )
1440 switch (message)
1442 case WM_SETTEXT:
1443 lParam = (LPARAM)MapSL(lParam);
1444 /* fall through */
1445 case WM_COMMAND:
1446 case WM_NCACTIVATE:
1447 case WM_SETFOCUS:
1448 case WM_SIZE:
1449 return DefFrameProcA( WIN_Handle32(hwnd), WIN_Handle32(hwndMDIClient),
1450 message, wParam, lParam );
1452 case WM_NEXTMENU:
1454 MDINEXTMENU next_menu;
1455 DefFrameProcW( WIN_Handle32(hwnd), WIN_Handle32(hwndMDIClient),
1456 message, wParam, (LPARAM)&next_menu );
1457 return MAKELONG( HMENU_16(next_menu.hmenuNext), HWND_16(next_menu.hwndNext) );
1459 default:
1460 return DefWindowProc16(hwnd, message, wParam, lParam);
1465 /***********************************************************************
1466 * DefFrameProcA (USER32.@)
1468 LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1469 UINT message, WPARAM wParam, LPARAM lParam)
1471 if (hwndMDIClient)
1473 switch (message)
1475 case WM_SETTEXT:
1477 DWORD len = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0 );
1478 LPWSTR text = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1479 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, text, len );
1480 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, text );
1481 HeapFree( GetProcessHeap(), 0, text );
1483 return 1; /* success. FIXME: check text length */
1485 case WM_COMMAND:
1486 case WM_NCACTIVATE:
1487 case WM_NEXTMENU:
1488 case WM_SETFOCUS:
1489 case WM_SIZE:
1490 return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1493 return DefWindowProcA(hwnd, message, wParam, lParam);
1497 /***********************************************************************
1498 * DefFrameProcW (USER32.@)
1500 LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1501 UINT message, WPARAM wParam, LPARAM lParam)
1503 MDICLIENTINFO *ci = get_client_info( hwndMDIClient );
1505 if (ci)
1507 switch (message)
1509 case WM_COMMAND:
1511 WORD id = LOWORD(wParam);
1512 /* check for possible syscommands for maximized MDI child */
1513 if (id < ci->idFirstChild || id >= ci->idFirstChild + ci->nActiveChildren)
1515 if( (id - 0xf000) & 0xf00f ) break;
1516 if( !ci->hwndChildMaximized ) break;
1517 switch( id )
1519 case SC_SIZE:
1520 case SC_MOVE:
1521 case SC_MINIMIZE:
1522 case SC_MAXIMIZE:
1523 case SC_NEXTWINDOW:
1524 case SC_PREVWINDOW:
1525 case SC_CLOSE:
1526 case SC_RESTORE:
1527 return SendMessageW( ci->hwndChildMaximized, WM_SYSCOMMAND,
1528 wParam, lParam);
1531 else
1533 HWND childHwnd;
1534 if (id - ci->idFirstChild == MDI_MOREWINDOWSLIMIT)
1535 /* User chose "More Windows..." */
1536 childHwnd = MDI_MoreWindowsDialog(hwndMDIClient);
1537 else
1538 /* User chose one of the windows listed in the "Windows" menu */
1539 childHwnd = MDI_GetChildByID(hwndMDIClient,id);
1541 if( childHwnd )
1542 SendMessageW( hwndMDIClient, WM_MDIACTIVATE, (WPARAM)childHwnd, 0 );
1545 break;
1547 case WM_NCACTIVATE:
1548 SendMessageW(hwndMDIClient, message, wParam, lParam);
1549 break;
1551 case WM_SETTEXT:
1552 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, (LPWSTR)lParam );
1553 return 1; /* success. FIXME: check text length */
1555 case WM_SETFOCUS:
1556 SetFocus(hwndMDIClient);
1557 break;
1559 case WM_SIZE:
1560 MoveWindow(hwndMDIClient, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
1561 break;
1563 case WM_NEXTMENU:
1565 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1567 if (!IsIconic(hwnd) && ci->hwndActiveChild && !ci->hwndChildMaximized)
1569 /* control menu is between the frame system menu and
1570 * the first entry of menu bar */
1571 WND *wndPtr = WIN_GetPtr(hwnd);
1573 if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1574 (wParam == VK_RIGHT && GetSubMenu(wndPtr->hSysMenu, 0) == next_menu->hmenuIn) )
1576 WIN_ReleasePtr(wndPtr);
1577 wndPtr = WIN_GetPtr(ci->hwndActiveChild);
1578 next_menu->hmenuNext = GetSubMenu(wndPtr->hSysMenu, 0);
1579 next_menu->hwndNext = ci->hwndActiveChild;
1581 WIN_ReleasePtr(wndPtr);
1583 return 0;
1588 return DefWindowProcW( hwnd, message, wParam, lParam );
1592 /***********************************************************************
1593 * DefMDIChildProc (USER.447)
1595 LRESULT WINAPI DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1596 WPARAM16 wParam, LPARAM lParam )
1598 switch (message)
1600 case WM_SETTEXT:
1601 return DefMDIChildProcA( WIN_Handle32(hwnd), message, wParam, (LPARAM)MapSL(lParam) );
1602 case WM_MENUCHAR:
1603 case WM_CLOSE:
1604 case WM_SETFOCUS:
1605 case WM_CHILDACTIVATE:
1606 case WM_SYSCOMMAND:
1607 case WM_SETVISIBLE:
1608 case WM_SIZE:
1609 case WM_SYSCHAR:
1610 return DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, lParam );
1611 case WM_GETMINMAXINFO:
1613 MINMAXINFO16 *mmi16 = (MINMAXINFO16 *)MapSL(lParam);
1614 MINMAXINFO mmi;
1615 STRUCT32_MINMAXINFO16to32( mmi16, &mmi );
1616 DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, (LPARAM)&mmi );
1617 STRUCT32_MINMAXINFO32to16( &mmi, mmi16 );
1618 return 0;
1620 case WM_NEXTMENU:
1622 MDINEXTMENU next_menu;
1623 DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, (LPARAM)&next_menu );
1624 return MAKELONG( HMENU_16(next_menu.hmenuNext), HWND_16(next_menu.hwndNext) );
1626 default:
1627 return DefWindowProc16(hwnd, message, wParam, lParam);
1632 /***********************************************************************
1633 * DefMDIChildProcA (USER32.@)
1635 LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1636 WPARAM wParam, LPARAM lParam )
1638 HWND client = GetParent(hwnd);
1639 MDICLIENTINFO *ci = get_client_info( client );
1641 hwnd = WIN_GetFullHandle( hwnd );
1642 if (!ci) return DefWindowProcA( hwnd, message, wParam, lParam );
1644 switch (message)
1646 case WM_SETTEXT:
1647 DefWindowProcA(hwnd, message, wParam, lParam);
1648 MDI_MenuModifyItem( client, hwnd );
1649 if( ci->hwndChildMaximized == hwnd )
1650 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1651 return 1; /* success. FIXME: check text length */
1653 case WM_GETMINMAXINFO:
1654 case WM_MENUCHAR:
1655 case WM_CLOSE:
1656 case WM_SETFOCUS:
1657 case WM_CHILDACTIVATE:
1658 case WM_SYSCOMMAND:
1659 case WM_SETVISIBLE:
1660 case WM_SIZE:
1661 case WM_NEXTMENU:
1662 case WM_SYSCHAR:
1663 return DefMDIChildProcW( hwnd, message, wParam, lParam );
1665 return DefWindowProcA(hwnd, message, wParam, lParam);
1669 /***********************************************************************
1670 * DefMDIChildProcW (USER32.@)
1672 LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1673 WPARAM wParam, LPARAM lParam )
1675 HWND client = GetParent(hwnd);
1676 MDICLIENTINFO *ci = get_client_info( client );
1678 hwnd = WIN_GetFullHandle( hwnd );
1679 if (!ci) return DefWindowProcW( hwnd, message, wParam, lParam );
1681 switch (message)
1683 case WM_SETTEXT:
1684 DefWindowProcW(hwnd, message, wParam, lParam);
1685 MDI_MenuModifyItem( client, hwnd );
1686 if( ci->hwndChildMaximized == hwnd )
1687 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1688 return 1; /* success. FIXME: check text length */
1690 case WM_GETMINMAXINFO:
1691 MDI_ChildGetMinMaxInfo( client, hwnd, (MINMAXINFO *)lParam );
1692 return 0;
1694 case WM_MENUCHAR:
1695 return 0x00010000; /* MDI children don't have menu bars */
1697 case WM_CLOSE:
1698 SendMessageW( client, WM_MDIDESTROY, (WPARAM)hwnd, 0 );
1699 return 0;
1701 case WM_SETFOCUS:
1702 if (ci->hwndActiveChild != hwnd) MDI_ChildActivate( client, hwnd );
1703 break;
1705 case WM_CHILDACTIVATE:
1706 MDI_ChildActivate( client, hwnd );
1707 return 0;
1709 case WM_SYSCOMMAND:
1710 switch( wParam )
1712 case SC_MOVE:
1713 if( ci->hwndChildMaximized == hwnd) return 0;
1714 break;
1715 case SC_RESTORE:
1716 case SC_MINIMIZE:
1717 SetWindowLongW( hwnd, GWL_STYLE,
1718 GetWindowLongW( hwnd, GWL_STYLE ) | WS_SYSMENU );
1719 break;
1720 case SC_MAXIMIZE:
1721 if (ci->hwndChildMaximized == hwnd)
1722 return SendMessageW( GetParent(client), message, wParam, lParam);
1723 SetWindowLongW( hwnd, GWL_STYLE,
1724 GetWindowLongW( hwnd, GWL_STYLE ) & ~WS_SYSMENU );
1725 break;
1726 case SC_NEXTWINDOW:
1727 SendMessageW( client, WM_MDINEXT, 0, 0);
1728 return 0;
1729 case SC_PREVWINDOW:
1730 SendMessageW( client, WM_MDINEXT, 0, 1);
1731 return 0;
1733 break;
1735 case WM_SETVISIBLE:
1736 if( ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1737 else MDI_PostUpdate(client, ci, SB_BOTH+1);
1738 break;
1740 case WM_SIZE:
1741 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1743 ci->hwndChildMaximized = 0;
1744 MDI_RestoreFrameMenu( GetParent(client), hwnd );
1745 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1748 if( wParam == SIZE_MAXIMIZED )
1750 HWND hMaxChild = ci->hwndChildMaximized;
1752 if( hMaxChild == hwnd ) break;
1753 if( hMaxChild)
1755 SendMessageW( hMaxChild, WM_SETREDRAW, FALSE, 0 );
1756 MDI_RestoreFrameMenu( GetParent(client), hMaxChild );
1757 ShowWindow( hMaxChild, SW_SHOWNOACTIVATE );
1758 SendMessageW( hMaxChild, WM_SETREDRAW, TRUE, 0 );
1760 TRACE("maximizing child %p\n", hwnd );
1762 /* keep track of the maximized window. */
1763 ci->hwndChildMaximized = hwnd; /* !!! */
1765 /* The maximized window should also be the active window */
1766 MDI_ChildActivate( client, hwnd );
1767 MDI_AugmentFrameMenu( GetParent(client), hwnd );
1768 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1771 if( wParam == SIZE_MINIMIZED )
1773 HWND switchTo = MDI_GetWindow(ci, hwnd, TRUE, WS_MINIMIZE);
1775 if (switchTo) SendMessageW( switchTo, WM_CHILDACTIVATE, 0, 0);
1777 MDI_PostUpdate(client, ci, SB_BOTH+1);
1778 break;
1780 case WM_NEXTMENU:
1782 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1783 HWND parent = GetParent(client);
1785 if( wParam == VK_LEFT ) /* switch to frame system menu */
1787 WND *wndPtr = WIN_GetPtr( parent );
1788 next_menu->hmenuNext = GetSubMenu( wndPtr->hSysMenu, 0 );
1789 WIN_ReleasePtr( wndPtr );
1791 if( wParam == VK_RIGHT ) /* to frame menu bar */
1793 next_menu->hmenuNext = GetMenu(parent);
1795 next_menu->hwndNext = parent;
1796 return 0;
1799 case WM_SYSCHAR:
1800 if (wParam == '-')
1802 SendMessageW( hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (DWORD)VK_SPACE);
1803 return 0;
1805 break;
1807 return DefWindowProcW(hwnd, message, wParam, lParam);
1810 /**********************************************************************
1811 * CreateMDIWindowA (USER32.@) Creates a MDI child
1813 * RETURNS
1814 * Success: Handle to created window
1815 * Failure: NULL
1817 HWND WINAPI CreateMDIWindowA(
1818 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1819 LPCSTR lpWindowName, /* [in] Pointer to window name */
1820 DWORD dwStyle, /* [in] Window style */
1821 INT X, /* [in] Horizontal position of window */
1822 INT Y, /* [in] Vertical position of window */
1823 INT nWidth, /* [in] Width of window */
1824 INT nHeight, /* [in] Height of window */
1825 HWND hWndParent, /* [in] Handle to parent window */
1826 HINSTANCE hInstance, /* [in] Handle to application instance */
1827 LPARAM lParam) /* [in] Application-defined value */
1829 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1830 MDICREATESTRUCTA cs;
1832 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%p,%p,%ld)\n",
1833 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1834 nWidth,nHeight,hWndParent,hInstance,lParam);
1836 if (!pCi)
1838 ERR("bad hwnd for MDI-client: %p\n", hWndParent);
1839 return 0;
1841 cs.szClass=lpClassName;
1842 cs.szTitle=lpWindowName;
1843 cs.hOwner=hInstance;
1844 cs.x=X;
1845 cs.y=Y;
1846 cs.cx=nWidth;
1847 cs.cy=nHeight;
1848 cs.style=dwStyle;
1849 cs.lParam=lParam;
1851 return MDICreateChild(hWndParent, pCi, &cs, FALSE);
1854 /***********************************************************************
1855 * CreateMDIWindowW (USER32.@) Creates a MDI child
1857 * RETURNS
1858 * Success: Handle to created window
1859 * Failure: NULL
1861 HWND WINAPI CreateMDIWindowW(
1862 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1863 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1864 DWORD dwStyle, /* [in] Window style */
1865 INT X, /* [in] Horizontal position of window */
1866 INT Y, /* [in] Vertical position of window */
1867 INT nWidth, /* [in] Width of window */
1868 INT nHeight, /* [in] Height of window */
1869 HWND hWndParent, /* [in] Handle to parent window */
1870 HINSTANCE hInstance, /* [in] Handle to application instance */
1871 LPARAM lParam) /* [in] Application-defined value */
1873 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1874 MDICREATESTRUCTW cs;
1876 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%p,%p,%ld)\n",
1877 debugstr_w(lpClassName), debugstr_w(lpWindowName), dwStyle, X, Y,
1878 nWidth, nHeight, hWndParent, hInstance, lParam);
1880 if (!pCi)
1882 ERR("bad hwnd for MDI-client: %p\n", hWndParent);
1883 return 0;
1885 cs.szClass = lpClassName;
1886 cs.szTitle = lpWindowName;
1887 cs.hOwner = hInstance;
1888 cs.x = X;
1889 cs.y = Y;
1890 cs.cx = nWidth;
1891 cs.cy = nHeight;
1892 cs.style = dwStyle;
1893 cs.lParam = lParam;
1895 return MDICreateChild(hWndParent, pCi, (MDICREATESTRUCTA *)&cs, TRUE);
1898 /**********************************************************************
1899 * TranslateMDISysAccel (USER32.@)
1901 BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1903 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1905 MDICLIENTINFO *ci = get_client_info( hwndClient );
1906 WPARAM wParam = 0;
1908 if (!ci || !IsWindowEnabled(ci->hwndActiveChild)) return 0;
1910 /* translate if the Ctrl key is down and Alt not. */
1912 if( (GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
1914 switch( msg->wParam )
1916 case VK_F6:
1917 case VK_TAB:
1918 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 ) ? SC_NEXTWINDOW : SC_PREVWINDOW;
1919 break;
1920 case VK_F4:
1921 case VK_RBUTTON:
1922 wParam = SC_CLOSE;
1923 break;
1924 default:
1925 return 0;
1927 TRACE("wParam = %04x\n", wParam);
1928 SendMessageW(ci->hwndActiveChild, WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
1929 return 1;
1932 return 0; /* failure */
1935 /***********************************************************************
1936 * CalcChildScroll (USER32.@)
1938 void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
1940 SCROLLINFO info;
1941 RECT childRect, clientRect;
1942 HWND *list;
1944 GetClientRect( hwnd, &clientRect );
1945 SetRectEmpty( &childRect );
1947 if ((list = WIN_ListChildren( hwnd )))
1949 int i;
1950 for (i = 0; list[i]; i++)
1952 DWORD style = GetWindowLongW( list[i], GWL_STYLE );
1953 if (style & WS_MAXIMIZE)
1955 HeapFree( GetProcessHeap(), 0, list );
1956 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1957 return;
1959 if (style & WS_VISIBLE)
1961 WND *pWnd = WIN_FindWndPtr( list[i] );
1962 UnionRect( &childRect, &pWnd->rectWindow, &childRect );
1963 WIN_ReleaseWndPtr( pWnd );
1966 HeapFree( GetProcessHeap(), 0, list );
1968 UnionRect( &childRect, &clientRect, &childRect );
1970 /* set common info values */
1971 info.cbSize = sizeof(info);
1972 info.fMask = SIF_POS | SIF_RANGE;
1974 /* set the specific */
1975 switch( scroll )
1977 case SB_BOTH:
1978 case SB_HORZ:
1979 info.nMin = childRect.left;
1980 info.nMax = childRect.right - clientRect.right;
1981 info.nPos = clientRect.left - childRect.left;
1982 SetScrollInfo(hwnd, scroll, &info, TRUE);
1983 if (scroll == SB_HORZ) break;
1984 /* fall through */
1985 case SB_VERT:
1986 info.nMin = childRect.top;
1987 info.nMax = childRect.bottom - clientRect.bottom;
1988 info.nPos = clientRect.top - childRect.top;
1989 SetScrollInfo(hwnd, scroll, &info, TRUE);
1990 break;
1995 /***********************************************************************
1996 * ScrollChildren (USER32.@)
1998 void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
1999 LPARAM lParam)
2001 INT newPos = -1;
2002 INT curPos, length, minPos, maxPos, shift;
2003 RECT rect;
2005 GetClientRect( hWnd, &rect );
2007 switch(uMsg)
2009 case WM_HSCROLL:
2010 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
2011 curPos = GetScrollPos(hWnd,SB_HORZ);
2012 length = (rect.right - rect.left) / 2;
2013 shift = GetSystemMetrics(SM_CYHSCROLL);
2014 break;
2015 case WM_VSCROLL:
2016 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
2017 curPos = GetScrollPos(hWnd,SB_VERT);
2018 length = (rect.bottom - rect.top) / 2;
2019 shift = GetSystemMetrics(SM_CXVSCROLL);
2020 break;
2021 default:
2022 return;
2025 switch( wParam )
2027 case SB_LINEUP:
2028 newPos = curPos - shift;
2029 break;
2030 case SB_LINEDOWN:
2031 newPos = curPos + shift;
2032 break;
2033 case SB_PAGEUP:
2034 newPos = curPos - length;
2035 break;
2036 case SB_PAGEDOWN:
2037 newPos = curPos + length;
2038 break;
2040 case SB_THUMBPOSITION:
2041 newPos = LOWORD(lParam);
2042 break;
2044 case SB_THUMBTRACK:
2045 return;
2047 case SB_TOP:
2048 newPos = minPos;
2049 break;
2050 case SB_BOTTOM:
2051 newPos = maxPos;
2052 break;
2053 case SB_ENDSCROLL:
2054 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
2055 return;
2058 if( newPos > maxPos )
2059 newPos = maxPos;
2060 else
2061 if( newPos < minPos )
2062 newPos = minPos;
2064 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
2066 if( uMsg == WM_VSCROLL )
2067 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
2068 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2069 else
2070 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
2071 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2075 /******************************************************************************
2076 * CascadeWindows (USER32.@) Cascades MDI child windows
2078 * RETURNS
2079 * Success: Number of cascaded windows.
2080 * Failure: 0
2082 WORD WINAPI
2083 CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2084 UINT cKids, const HWND *lpKids)
2086 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
2087 return 0;
2091 /******************************************************************************
2092 * TileWindows (USER32.@) Tiles MDI child windows
2094 * RETURNS
2095 * Success: Number of tiled windows.
2096 * Failure: 0
2098 WORD WINAPI
2099 TileWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2100 UINT cKids, const HWND *lpKids)
2102 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
2103 return 0;
2106 /************************************************************************
2107 * "More Windows..." functionality
2110 /* MDI_MoreWindowsDlgProc
2112 * This function will process the messages sent to the "More Windows..."
2113 * dialog.
2114 * Return values: 0 = cancel pressed
2115 * HWND = ok pressed or double-click in the list...
2119 static INT_PTR WINAPI MDI_MoreWindowsDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
2121 switch (iMsg)
2123 case WM_INITDIALOG:
2125 UINT widest = 0;
2126 UINT length;
2127 UINT i;
2128 MDICLIENTINFO *ci = get_client_info( (HWND)lParam );
2129 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2130 HWND *list, *sorted_list;
2132 if (!(list = WIN_ListChildren( (HWND)lParam ))) return TRUE;
2133 if (!(sorted_list = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
2134 sizeof(HWND) * ci->nActiveChildren )))
2136 HeapFree( GetProcessHeap(), 0, list );
2137 return FALSE;
2140 /* Fill the list, sorted by id... */
2141 for (i = 0; list[i]; i++)
2143 UINT id = GetWindowLongW( list[i], GWL_ID ) - ci->idFirstChild;
2144 if (id < ci->nActiveChildren) sorted_list[id] = list[i];
2146 HeapFree( GetProcessHeap(), 0, list );
2148 for (i = 0; i < ci->nActiveChildren; i++)
2150 WCHAR buffer[128];
2152 if (!GetWindowTextW( sorted_list[i], buffer, sizeof(buffer)/sizeof(WCHAR) ))
2153 continue;
2154 SendMessageW(hListBox, LB_ADDSTRING, 0, (LPARAM)buffer );
2155 SendMessageW(hListBox, LB_SETITEMDATA, i, (LPARAM)sorted_list[i] );
2156 length = strlenW(buffer); /* FIXME: should use GetTextExtentPoint */
2157 if (length > widest)
2158 widest = length;
2160 /* Make sure the horizontal scrollbar scrolls ok */
2161 SendMessageW(hListBox, LB_SETHORIZONTALEXTENT, widest * 6, 0);
2163 /* Set the current selection */
2164 SendMessageW(hListBox, LB_SETCURSEL, MDI_MOREWINDOWSLIMIT, 0);
2165 return TRUE;
2168 case WM_COMMAND:
2169 switch (LOWORD(wParam))
2171 default:
2172 if (HIWORD(wParam) != LBN_DBLCLK) break;
2173 /* fall through */
2174 case IDOK:
2176 /* windows are sorted by menu ID, so we must return the
2177 * window associated to the given id
2179 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2180 UINT index = SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
2181 LRESULT res = SendMessageW(hListBox, LB_GETITEMDATA, index, 0);
2182 EndDialog(hDlg, res);
2183 return TRUE;
2185 case IDCANCEL:
2186 EndDialog(hDlg, 0);
2187 return TRUE;
2189 break;
2191 return FALSE;
2196 * MDI_MoreWindowsDialog
2198 * Prompts the user with a listbox containing the opened
2199 * documents. The user can then choose a windows and click
2200 * on OK to set the current window to the one selected, or
2201 * CANCEL to cancel. The function returns a handle to the
2202 * selected window.
2205 static HWND MDI_MoreWindowsDialog(HWND hwnd)
2207 LPCVOID template;
2208 HRSRC hRes;
2209 HANDLE hDlgTmpl;
2211 hRes = FindResourceA(GetModuleHandleA("USER32"), "MDI_MOREWINDOWS", (LPSTR)RT_DIALOG);
2213 if (hRes == 0)
2214 return 0;
2216 hDlgTmpl = LoadResource(GetModuleHandleA("USER32"), hRes );
2218 if (hDlgTmpl == 0)
2219 return 0;
2221 template = LockResource( hDlgTmpl );
2223 if (template == 0)
2224 return 0;
2226 return (HWND) DialogBoxIndirectParamA(GetModuleHandleA("USER32"),
2227 (LPDLGTEMPLATEA) template,
2228 hwnd, MDI_MoreWindowsDlgProc, (LPARAM) hwnd);
2233 * MDI_SwapMenuItems
2235 * Will swap the menu IDs for the given 2 positions.
2236 * pos1 and pos2 are menu IDs
2241 static void MDI_SwapMenuItems(HWND parent, UINT pos1, UINT pos2)
2243 HWND *list;
2244 int i;
2246 if (!(list = WIN_ListChildren( parent ))) return;
2247 for (i = 0; list[i]; i++)
2249 UINT id = GetWindowLongW( list[i], GWL_ID );
2250 if (id == pos1) SetWindowLongW( list[i], GWL_ID, pos2 );
2251 else if (id == pos2) SetWindowLongW( list[i], GWL_ID, pos1 );
2253 HeapFree( GetProcessHeap(), 0, list );