Removed -noimport on functions that are forwards to ntdll.
[wine/multimedia.git] / windows / mdi.c
blob31150a8781a1290772189e30c0ea7b8688a257e4
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 <stdio.h>
85 #include <string.h>
86 #include <math.h>
88 #include "windef.h"
89 #include "winbase.h"
90 #include "wingdi.h"
91 #include "winuser.h"
92 #include "wownt32.h"
93 #include "wine/unicode.h"
94 #include "win.h"
95 #include "nonclient.h"
96 #include "controls.h"
97 #include "user.h"
98 #include "struct32.h"
99 #include "wine/debug.h"
100 #include "dlgs.h"
102 WINE_DEFAULT_DEBUG_CHANNEL(mdi);
104 #define MDI_MAXLISTLENGTH 0x40
105 #define MDI_MAXTITLELENGTH 0xa1
107 #define MDI_NOFRAMEREPAINT 0
108 #define MDI_REPAINTFRAMENOW 1
109 #define MDI_REPAINTFRAME 2
111 #define WM_MDICALCCHILDSCROLL 0x10ac /* this is exactly what Windows uses */
113 /* "More Windows..." definitions */
114 #define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
115 option will appear under the Windows menu */
116 #define MDI_IDC_LISTBOX 100
117 #define IDS_MDI_MOREWINDOWS 13
119 #define MDIF_NEEDUPDATE 0x0001
121 typedef struct
123 UINT nActiveChildren;
124 HWND hwndChildMaximized;
125 HWND hwndActiveChild;
126 HMENU hWindowMenu;
127 UINT idFirstChild;
128 LPWSTR frameTitle;
129 UINT nTotalCreated;
130 UINT mdiFlags;
131 UINT sbRecalc; /* SB_xxx flags for scrollbar fixup */
132 } MDICLIENTINFO;
134 static HBITMAP hBmpClose = 0;
136 /* ----------------- declarations ----------------- */
137 static void MDI_UpdateFrameText( HWND, HWND, BOOL, LPCWSTR);
138 static BOOL MDI_AugmentFrameMenu( HWND, HWND );
139 static BOOL MDI_RestoreFrameMenu( HWND, HWND );
140 static LONG MDI_ChildActivate( HWND, HWND );
142 static HWND MDI_MoreWindowsDialog(HWND);
143 static void MDI_SwapMenuItems(HWND, UINT, UINT);
144 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
145 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
147 /* -------- Miscellaneous service functions ----------
149 * MDI_GetChildByID
151 static HWND MDI_GetChildByID(HWND hwnd, UINT id)
153 HWND ret;
154 HWND *win_array;
155 int i;
157 if (!(win_array = WIN_ListChildren( hwnd ))) return 0;
158 for (i = 0; win_array[i]; i++)
160 if (GetWindowLongA( win_array[i], GWL_ID ) == id) break;
162 ret = win_array[i];
163 HeapFree( GetProcessHeap(), 0, win_array );
164 return ret;
167 static void MDI_PostUpdate(HWND hwnd, MDICLIENTINFO* ci, WORD recalc)
169 if( !(ci->mdiFlags & MDIF_NEEDUPDATE) )
171 ci->mdiFlags |= MDIF_NEEDUPDATE;
172 PostMessageA( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
174 ci->sbRecalc = recalc;
178 /*********************************************************************
179 * MDIClient class descriptor
181 const struct builtin_class_descr MDICLIENT_builtin_class =
183 "MDIClient", /* name */
184 CS_GLOBALCLASS, /* style */
185 MDIClientWndProcA, /* procA */
186 MDIClientWndProcW, /* procW */
187 sizeof(MDICLIENTINFO), /* extra */
188 IDC_ARROWA, /* cursor */
189 (HBRUSH)(COLOR_APPWORKSPACE+1) /* brush */
193 static MDICLIENTINFO *get_client_info( HWND client )
195 MDICLIENTINFO *ret = NULL;
196 WND *win = WIN_GetPtr( client );
197 if (win)
199 if (win == WND_OTHER_PROCESS)
201 ERR( "client %x belongs to other process\n", client );
202 return NULL;
204 if (win->cbWndExtra < sizeof(MDICLIENTINFO)) WARN( "%x is not an MDI client\n", client );
205 else ret = (MDICLIENTINFO *)win->wExtra;
206 WIN_ReleasePtr( win );
208 return ret;
211 /**********************************************************************
212 * MDI_MenuModifyItem
214 static void MDI_MenuModifyItem( HWND client, HWND hWndChild )
216 MDICLIENTINFO *clientInfo = get_client_info( client );
217 WCHAR buffer[128];
218 UINT n, id;
220 if (!clientInfo || !clientInfo->hWindowMenu) return;
222 id = GetWindowLongA( hWndChild, GWL_ID );
223 if (id >= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT) return;
224 buffer[0] = '&';
225 buffer[1] = '1' + id - clientInfo->idFirstChild;
226 buffer[2] = ' ';
227 GetWindowTextW( hWndChild, buffer + 3, sizeof(buffer)/sizeof(WCHAR) - 3 );
229 n = GetMenuState(clientInfo->hWindowMenu, id, MF_BYCOMMAND);
230 ModifyMenuW(clientInfo->hWindowMenu, id, MF_BYCOMMAND | MF_STRING, id, buffer );
231 CheckMenuItem(clientInfo->hWindowMenu, id, n & MF_CHECKED);
234 /**********************************************************************
235 * MDI_MenuDeleteItem
237 static BOOL MDI_MenuDeleteItem( HWND client, HWND hWndChild )
239 WCHAR buffer[128];
240 static const WCHAR format[] = {'&','%','d',' ',0};
241 MDICLIENTINFO *clientInfo = get_client_info( client );
242 UINT index = 0,id,n;
244 if( !clientInfo->nActiveChildren || !clientInfo->hWindowMenu )
245 return FALSE;
247 id = GetWindowLongA( hWndChild, GWL_ID );
248 DeleteMenu(clientInfo->hWindowMenu,id,MF_BYCOMMAND);
250 /* walk the rest of MDI children to prevent gaps in the id
251 * sequence and in the menu child list */
253 for( index = id+1; index <= clientInfo->nActiveChildren +
254 clientInfo->idFirstChild; index++ )
256 HWND hwnd = MDI_GetChildByID(client,index);
257 if (!hwnd)
259 TRACE("no window for id=%i\n",index);
260 continue;
263 /* set correct id */
264 SetWindowLongW( hwnd, GWL_ID, GetWindowLongW( hwnd, GWL_ID ) - 1 );
266 n = wsprintfW(buffer, format ,index - clientInfo->idFirstChild);
267 GetWindowTextW( hwnd, buffer + n, sizeof(buffer)/sizeof(WCHAR) - n );
269 /* change menu if the current child is to be shown in the
270 * "Windows" menu
272 if (index <= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT)
273 ModifyMenuW(clientInfo->hWindowMenu ,index ,MF_BYCOMMAND | MF_STRING,
274 index - 1 , buffer );
277 /* We must restore the "More Windows..." option if there are enough children
279 if (clientInfo->nActiveChildren - 1 > MDI_MOREWINDOWSLIMIT)
281 WCHAR szTmp[50];
282 LoadStringW(GetModuleHandleA("USER32"), IDS_MDI_MOREWINDOWS, szTmp, sizeof(szTmp)/sizeof(szTmp[0]));
283 AppendMenuW(clientInfo->hWindowMenu, MF_STRING, clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT, szTmp);
285 return TRUE;
288 /**********************************************************************
289 * MDI_GetWindow
291 * returns "activateable" child different from the current or zero
293 static HWND MDI_GetWindow(MDICLIENTINFO *clientInfo, HWND hWnd, BOOL bNext,
294 DWORD dwStyleMask )
296 int i;
297 HWND *list;
298 HWND last = 0;
300 dwStyleMask |= WS_DISABLED | WS_VISIBLE;
301 if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
303 if (!(list = WIN_ListChildren( GetParent(hWnd) ))) return 0;
304 i = 0;
305 /* start from next after hWnd */
306 while (list[i] && list[i] != hWnd) i++;
307 if (list[i]) i++;
309 for ( ; list[i]; i++)
311 if (GetWindow( list[i], GW_OWNER )) continue;
312 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
313 last = list[i];
314 if (bNext) goto found;
316 /* now restart from the beginning */
317 for (i = 0; list[i] && list[i] != hWnd; i++)
319 if (GetWindow( list[i], GW_OWNER )) continue;
320 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
321 last = list[i];
322 if (bNext) goto found;
324 found:
325 HeapFree( GetProcessHeap(), 0, list );
326 return last;
329 /**********************************************************************
330 * MDI_CalcDefaultChildPos
332 * It seems that the default height is about 2/3 of the client rect
334 static void MDI_CalcDefaultChildPos( HWND hwnd, WORD n, LPPOINT lpPos, INT delta)
336 INT nstagger;
337 RECT rect;
338 INT spacing = GetSystemMetrics(SM_CYCAPTION) +
339 GetSystemMetrics(SM_CYFRAME) - 1;
341 GetClientRect( hwnd, &rect );
342 if( rect.bottom - rect.top - delta >= spacing )
343 rect.bottom -= delta;
345 nstagger = (rect.bottom - rect.top)/(3 * spacing);
346 lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
347 lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
348 lpPos[0].x = lpPos[0].y = spacing * (n%(nstagger+1));
351 /**********************************************************************
352 * MDISetMenu
354 static LRESULT MDISetMenu( HWND hwnd, HMENU hmenuFrame,
355 HMENU hmenuWindow)
357 MDICLIENTINFO *ci;
358 HWND hwndFrame = GetParent(hwnd);
359 HMENU oldFrameMenu = GetMenu(hwndFrame);
361 TRACE("%04x %04x %04x\n",
362 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("%04x %04x %04x\n",
476 hwnd, hmenuFrame, hmenuWindow);
478 FIXME("partially function stub\n");
480 return (LRESULT)oldFrameMenu;
484 /* ------------------ MDI child window functions ---------------------- */
487 /**********************************************************************
488 * MDICreateChild
490 static HWND MDICreateChild( HWND parent, MDICLIENTINFO *ci,
491 LPMDICREATESTRUCTA cs, BOOL unicode )
493 POINT pos[2];
494 DWORD style = cs->style | (WS_CHILD | WS_CLIPSIBLINGS);
495 HWND hwnd, hwndMax = 0;
496 UINT wIDmenu = ci->idFirstChild + ci->nActiveChildren;
497 WND *wndParent;
498 static const WCHAR lpstrDef[] = {'j','u','n','k','!',0};
500 TRACE("origin %i,%i - dim %i,%i, style %08lx\n",
501 cs->x, cs->y, cs->cx, cs->cy, cs->style);
502 /* calculate placement */
503 MDI_CalcDefaultChildPos(parent, ci->nTotalCreated++, pos, 0);
505 if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16 || !cs->cx) cs->cx = pos[1].x;
506 if (cs->cy == CW_USEDEFAULT || cs->cy == CW_USEDEFAULT16 || !cs->cy) cs->cy = pos[1].y;
508 if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
510 cs->x = pos[0].x;
511 cs->y = pos[0].y;
514 /* restore current maximized child */
515 if( (style & WS_VISIBLE) && ci->hwndChildMaximized )
517 TRACE("Restoring current maximized child %04x\n", ci->hwndChildMaximized);
518 if( style & WS_MAXIMIZE )
519 SendMessageW(parent, WM_SETREDRAW, FALSE, 0L);
520 hwndMax = ci->hwndChildMaximized;
521 ShowWindow( hwndMax, SW_SHOWNOACTIVATE );
522 if( style & WS_MAXIMIZE )
523 SendMessageW(parent, WM_SETREDRAW, TRUE, 0L);
526 if (ci->nActiveChildren <= MDI_MOREWINDOWSLIMIT)
527 /* this menu is needed to set a check mark in MDI_ChildActivate */
528 if (ci->hWindowMenu != 0)
529 AppendMenuW(ci->hWindowMenu, MF_STRING, wIDmenu, lpstrDef);
531 ci->nActiveChildren++;
533 /* fix window style */
534 wndParent = WIN_FindWndPtr( parent );
535 if( !(wndParent->dwStyle & MDIS_ALLCHILDSTYLES) )
537 TRACE("MDIS_ALLCHILDSTYLES is missing, fixing window style\n");
538 style &= (WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZE | WS_MAXIMIZE |
539 WS_CLIPCHILDREN | WS_DISABLED | WS_VSCROLL | WS_HSCROLL );
540 style |= (WS_VISIBLE | WS_OVERLAPPEDWINDOW);
543 if( wndParent->flags & WIN_ISWIN32 )
545 WIN_ReleaseWndPtr( wndParent );
546 if(unicode)
548 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)cs;
549 hwnd = CreateWindowW( csW->szClass, csW->szTitle, style,
550 csW->x, csW->y, csW->cx, csW->cy, parent,
551 (HMENU)wIDmenu, csW->hOwner, csW );
553 else
554 hwnd = CreateWindowA( cs->szClass, cs->szTitle, style,
555 cs->x, cs->y, cs->cx, cs->cy, parent,
556 (HMENU)wIDmenu, cs->hOwner, cs );
558 else
560 MDICREATESTRUCT16 cs16;
561 SEGPTR title, cls, seg_cs16;
563 WIN_ReleaseWndPtr( wndParent );
564 STRUCT32_MDICREATESTRUCT32Ato16( cs, &cs16 );
565 cs16.szTitle = title = MapLS( cs->szTitle );
566 cs16.szClass = cls = MapLS( cs->szClass );
567 seg_cs16 = MapLS( &cs16 );
568 hwnd = WIN_Handle32( CreateWindow16( cs->szClass, cs->szTitle, style,
569 cs16.x, cs16.y, cs16.cx, cs16.cy,
570 HWND_16(parent), (HMENU)wIDmenu,
571 cs16.hOwner, (LPVOID)seg_cs16 ));
572 UnMapLS( seg_cs16 );
573 UnMapLS( title );
574 UnMapLS( cls );
577 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
579 if (hwnd)
581 /* All MDI child windows have the WS_EX_MDICHILD style */
582 SetWindowLongW( hwnd, GWL_EXSTYLE, GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_MDICHILD );
584 /* If we have more than 9 windows, we must insert the new one at the
585 * 9th position in order to see it in the "Windows" menu
587 if (ci->nActiveChildren > MDI_MOREWINDOWSLIMIT)
588 MDI_SwapMenuItems( parent, GetWindowLongW( hwnd, GWL_ID ),
589 ci->idFirstChild + MDI_MOREWINDOWSLIMIT - 1);
591 MDI_MenuModifyItem(parent, hwnd);
593 /* Have we hit the "More Windows..." limit? If so, we must
594 * add a "More Windows..." option
596 if (ci->nActiveChildren == MDI_MOREWINDOWSLIMIT + 1)
598 WCHAR szTmp[50];
599 LoadStringW(GetModuleHandleA("USER32"), IDS_MDI_MOREWINDOWS, szTmp, sizeof(szTmp)/sizeof(szTmp[0]));
601 ModifyMenuW(ci->hWindowMenu,
602 ci->idFirstChild + MDI_MOREWINDOWSLIMIT,
603 MF_BYCOMMAND | MF_STRING,
604 ci->idFirstChild + MDI_MOREWINDOWSLIMIT,
605 szTmp);
608 if( IsIconic(hwnd) && ci->hwndActiveChild )
610 TRACE("Minimizing created MDI child %04x\n", hwnd);
611 ShowWindow( hwnd, SW_SHOWMINNOACTIVE );
613 else
615 /* WS_VISIBLE is clear if a) the MDI client has
616 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
617 * MDICreateStruct. If so the created window is not shown nor
618 * activated.
620 if (IsWindowVisible(hwnd)) ShowWindow(hwnd, SW_SHOW);
622 TRACE("created child - %04x\n",hwnd);
624 else
626 ci->nActiveChildren--;
627 DeleteMenu(ci->hWindowMenu,wIDmenu,MF_BYCOMMAND);
628 if( IsWindow(hwndMax) )
629 ShowWindow(hwndMax, SW_SHOWMAXIMIZED);
632 return hwnd;
635 /**********************************************************************
636 * MDI_ChildGetMinMaxInfo
638 * Note: The rule here is that client rect of the maximized MDI child
639 * is equal to the client rect of the MDI client window.
641 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
643 RECT rect;
645 GetClientRect( client, &rect );
646 AdjustWindowRectEx( &rect, GetWindowLongW( hwnd, GWL_STYLE ),
647 0, GetWindowLongW( hwnd, GWL_EXSTYLE ));
649 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
650 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
652 lpMinMax->ptMaxPosition.x = rect.left;
653 lpMinMax->ptMaxPosition.y = rect.top;
655 TRACE("max rect (%i,%i - %i, %i)\n",
656 rect.left,rect.top,rect.right,rect.bottom);
659 /**********************************************************************
660 * MDI_SwitchActiveChild
662 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
663 * being activated
665 static void MDI_SwitchActiveChild( HWND clientHwnd, HWND childHwnd,
666 BOOL bNextWindow )
668 HWND hwndTo = 0;
669 HWND hwndPrev = 0;
670 MDICLIENTINFO *ci = get_client_info( clientHwnd );
672 hwndTo = MDI_GetWindow(ci, childHwnd, bNextWindow, 0);
674 TRACE("from %04x, to %04x\n",childHwnd,hwndTo);
676 if ( !hwndTo ) return; /* no window to switch to */
678 hwndPrev = ci->hwndActiveChild;
680 if ( hwndTo != hwndPrev )
682 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0,
683 SWP_NOMOVE | SWP_NOSIZE );
685 if( bNextWindow && hwndPrev )
686 SetWindowPos( hwndPrev, HWND_BOTTOM, 0, 0, 0, 0,
687 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
692 /**********************************************************************
693 * MDIDestroyChild
695 static LRESULT MDIDestroyChild( HWND parent, MDICLIENTINFO *ci,
696 HWND child, BOOL flagDestroy )
698 if( child == ci->hwndActiveChild )
700 MDI_SwitchActiveChild(parent, child, TRUE);
702 if( child == ci->hwndActiveChild )
704 ShowWindow( child, SW_HIDE);
705 if( child == ci->hwndChildMaximized )
707 HWND frame = GetParent(parent);
708 MDI_RestoreFrameMenu( frame, child );
709 ci->hwndChildMaximized = 0;
710 MDI_UpdateFrameText( frame, parent, TRUE, NULL);
713 MDI_ChildActivate(parent, 0);
717 MDI_MenuDeleteItem(parent, child);
719 ci->nActiveChildren--;
721 TRACE("child destroyed - %04x\n",child);
723 if (flagDestroy)
725 MDI_PostUpdate(GetParent(child), ci, SB_BOTH+1);
726 DestroyWindow(child);
728 return 0;
732 /**********************************************************************
733 * MDI_ChildActivate
735 * Note: hWndChild is NULL when last child is being destroyed
737 static LONG MDI_ChildActivate( HWND client, HWND child )
739 MDICLIENTINFO *clientInfo = get_client_info( client );
740 HWND prevActiveWnd = clientInfo->hwndActiveChild;
741 BOOL isActiveFrameWnd;
743 if (child && (!IsWindowEnabled( child ))) return 0;
745 /* Don't activate if it is already active. Might happen
746 since ShowWindow DOES activate MDI children */
747 if (clientInfo->hwndActiveChild == child) return 0;
749 TRACE("%04x\n", child);
751 isActiveFrameWnd = (GetActiveWindow() == GetParent(client));
753 /* deactivate prev. active child */
754 if(prevActiveWnd)
756 SetWindowLongA( prevActiveWnd, GWL_STYLE,
757 GetWindowLongA( prevActiveWnd, GWL_STYLE ) | WS_SYSMENU );
758 SendMessageA( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
759 SendMessageA( prevActiveWnd, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child);
760 /* uncheck menu item */
761 if( clientInfo->hWindowMenu )
763 UINT prevID = GetWindowLongA( prevActiveWnd, GWL_ID );
765 if (prevID - clientInfo->idFirstChild < MDI_MOREWINDOWSLIMIT)
766 CheckMenuItem( clientInfo->hWindowMenu, prevID, 0);
767 else
768 CheckMenuItem( clientInfo->hWindowMenu,
769 clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1, 0);
773 /* set appearance */
774 if (clientInfo->hwndChildMaximized && clientInfo->hwndChildMaximized != child)
776 if( child )
778 clientInfo->hwndActiveChild = child;
779 ShowWindow( child, SW_SHOWMAXIMIZED);
781 else ShowWindow( clientInfo->hwndActiveChild, SW_SHOWNORMAL );
784 clientInfo->hwndActiveChild = child;
786 /* check if we have any children left */
787 if( !child )
789 if( isActiveFrameWnd )
790 SetFocus( client );
791 return 0;
794 /* check menu item */
795 if( clientInfo->hWindowMenu )
797 UINT id = GetWindowLongA( child, GWL_ID );
798 /* The window to be activated must be displayed in the "Windows" menu */
799 if (id >= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT)
801 MDI_SwapMenuItems( GetParent(child),
802 id, clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1);
803 id = clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1;
804 MDI_MenuModifyItem( GetParent(child), child );
807 CheckMenuItem(clientInfo->hWindowMenu, id, MF_CHECKED);
809 /* bring active child to the top */
810 SetWindowPos( child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
812 if( isActiveFrameWnd )
814 SendMessageA( child, WM_NCACTIVATE, TRUE, 0L);
815 if( GetFocus() == client )
816 SendMessageA( client, WM_SETFOCUS, (WPARAM)client, 0L );
817 else
818 SetFocus( client );
820 SendMessageA( child, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child );
821 return TRUE;
824 /* -------------------- MDI client window functions ------------------- */
826 /**********************************************************************
827 * CreateMDIMenuBitmap
829 static HBITMAP CreateMDIMenuBitmap(void)
831 HDC hDCSrc = CreateCompatibleDC(0);
832 HDC hDCDest = CreateCompatibleDC(hDCSrc);
833 HBITMAP hbClose = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_OLD_CLOSE) );
834 HBITMAP hbCopy;
835 HBITMAP hobjSrc, hobjDest;
837 hobjSrc = SelectObject(hDCSrc, hbClose);
838 hbCopy = CreateCompatibleBitmap(hDCSrc,GetSystemMetrics(SM_CXSIZE),GetSystemMetrics(SM_CYSIZE));
839 hobjDest = SelectObject(hDCDest, hbCopy);
841 BitBlt(hDCDest, 0, 0, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE),
842 hDCSrc, GetSystemMetrics(SM_CXSIZE), 0, SRCCOPY);
844 SelectObject(hDCSrc, hobjSrc);
845 DeleteObject(hbClose);
846 DeleteDC(hDCSrc);
848 hobjSrc = SelectObject( hDCDest, GetStockObject(BLACK_PEN) );
850 MoveToEx( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, 0, NULL );
851 LineTo( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, GetSystemMetrics(SM_CYSIZE) - 1);
853 SelectObject(hDCDest, hobjSrc );
854 SelectObject(hDCDest, hobjDest);
855 DeleteDC(hDCDest);
857 return hbCopy;
860 /**********************************************************************
861 * MDICascade
863 static LONG MDICascade( HWND client, MDICLIENTINFO *ci )
865 HWND *win_array;
866 BOOL has_icons = FALSE;
867 int i, total;
869 if (ci->hwndChildMaximized)
870 SendMessageA( client, WM_MDIRESTORE,
871 (WPARAM)ci->hwndChildMaximized, 0);
873 if (ci->nActiveChildren == 0) return 0;
875 if (!(win_array = WIN_ListChildren( client ))) return 0;
877 /* remove all the windows we don't want */
878 for (i = total = 0; win_array[i]; i++)
880 if (!IsWindowVisible( win_array[i] )) continue;
881 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows */
882 if (IsIconic( win_array[i] ))
884 has_icons = TRUE;
885 continue;
887 win_array[total++] = win_array[i];
889 win_array[total] = 0;
891 if (total)
893 INT delta = 0, n = 0, i;
894 POINT pos[2];
895 if (has_icons) delta = GetSystemMetrics(SM_CYICONSPACING) + GetSystemMetrics(SM_CYICON);
897 /* walk the list (backwards) and move windows */
898 for (i = total - 1; i >= 0; i--)
900 TRACE("move %04x to (%ld,%ld) size [%ld,%ld]\n",
901 win_array[i], pos[0].x, pos[0].y, pos[1].x, pos[1].y);
903 MDI_CalcDefaultChildPos(client, n++, pos, delta);
904 SetWindowPos( win_array[i], 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
905 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
908 HeapFree( GetProcessHeap(), 0, win_array );
910 if (has_icons) ArrangeIconicWindows( client );
911 return 0;
914 /**********************************************************************
915 * MDITile
917 static void MDITile( HWND client, MDICLIENTINFO *ci, WPARAM wParam )
919 HWND *win_array;
920 int i, total;
921 BOOL has_icons = FALSE;
923 if (ci->hwndChildMaximized)
924 SendMessageA( client, WM_MDIRESTORE, (WPARAM)ci->hwndChildMaximized, 0);
926 if (ci->nActiveChildren == 0) return;
928 if (!(win_array = WIN_ListChildren( client ))) return;
930 /* remove all the windows we don't want */
931 for (i = total = 0; win_array[i]; i++)
933 if (!IsWindowVisible( win_array[i] )) continue;
934 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows (icon titles) */
935 if (IsIconic( win_array[i] ))
937 has_icons = TRUE;
938 continue;
940 if ((wParam & MDITILE_SKIPDISABLED) && !IsWindowEnabled( win_array[i] )) continue;
941 win_array[total++] = win_array[i];
943 win_array[total] = 0;
945 TRACE("%u windows to tile\n", total);
947 if (total)
949 HWND *pWnd = win_array;
950 RECT rect;
951 int x, y, xsize, ysize;
952 int rows, columns, r, c, i;
954 GetClientRect(client,&rect);
955 rows = (int) sqrt((double)total);
956 columns = total / rows;
958 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
960 i = rows;
961 rows = columns; /* exchange r and c */
962 columns = i;
965 if (has_icons)
967 y = rect.bottom - 2 * GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
968 rect.bottom = ( y - GetSystemMetrics(SM_CYICON) < rect.top )? rect.bottom: y;
971 ysize = rect.bottom / rows;
972 xsize = rect.right / columns;
974 for (x = i = 0, c = 1; c <= columns && *pWnd; c++)
976 if (c == columns)
978 rows = total - i;
979 ysize = rect.bottom / rows;
982 y = 0;
983 for (r = 1; r <= rows && *pWnd; r++, i++)
985 SetWindowPos(*pWnd, 0, x, y, xsize, ysize,
986 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
987 y += ysize;
988 pWnd++;
990 x += xsize;
993 HeapFree( GetProcessHeap(), 0, win_array );
994 if (has_icons) ArrangeIconicWindows( client );
997 /* ----------------------- Frame window ---------------------------- */
1000 /**********************************************************************
1001 * MDI_AugmentFrameMenu
1003 static BOOL MDI_AugmentFrameMenu( HWND frame, HWND hChild )
1005 HMENU menu = GetMenu( frame );
1006 WND* child = WIN_FindWndPtr(hChild);
1007 HMENU hSysPopup = 0;
1008 HBITMAP hSysMenuBitmap = 0;
1010 TRACE("frame %04x,child %04x\n",frame,hChild);
1012 if( !menu || !child->hSysMenu )
1014 WIN_ReleaseWndPtr(child);
1015 return 0;
1017 WIN_ReleaseWndPtr(child);
1019 /* create a copy of sysmenu popup and insert it into frame menu bar */
1021 if (!(hSysPopup = LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU")))
1022 return 0;
1024 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1025 SC_MINIMIZE, (LPSTR)(DWORD)HBMMENU_MBAR_MINIMIZE ) ;
1026 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1027 SC_RESTORE, (LPSTR)(DWORD)HBMMENU_MBAR_RESTORE );
1029 /* In Win 95 look, the system menu is replaced by the child icon */
1031 if(TWEAK_WineLook > WIN31_LOOK)
1033 HICON hIcon = (HICON)GetClassLongA(hChild, GCL_HICONSM);
1034 if (!hIcon)
1035 hIcon = (HICON)GetClassLongA(hChild, GCL_HICON);
1036 if (hIcon)
1038 HDC hMemDC;
1039 HBITMAP hBitmap, hOldBitmap;
1040 HBRUSH hBrush;
1041 HDC hdc = GetDC(hChild);
1043 if (hdc)
1045 int cx, cy;
1046 cx = GetSystemMetrics(SM_CXSMICON);
1047 cy = GetSystemMetrics(SM_CYSMICON);
1048 hMemDC = CreateCompatibleDC(hdc);
1049 hBitmap = CreateCompatibleBitmap(hdc, cx, cy);
1050 hOldBitmap = SelectObject(hMemDC, hBitmap);
1051 SetMapMode(hMemDC, MM_TEXT);
1052 hBrush = CreateSolidBrush(GetSysColor(COLOR_MENU));
1053 DrawIconEx(hMemDC, 0, 0, hIcon, cx, cy, 0, hBrush, DI_NORMAL);
1054 SelectObject (hMemDC, hOldBitmap);
1055 DeleteObject(hBrush);
1056 DeleteDC(hMemDC);
1057 ReleaseDC(hChild, hdc);
1058 hSysMenuBitmap = hBitmap;
1062 else
1063 hSysMenuBitmap = hBmpClose;
1065 if( !InsertMenuA(menu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
1066 hSysPopup, (LPSTR)(DWORD)hSysMenuBitmap))
1068 TRACE("not inserted\n");
1069 DestroyMenu(hSysPopup);
1070 return 0;
1073 /* The close button is only present in Win 95 look */
1074 if(TWEAK_WineLook > WIN31_LOOK)
1076 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1077 SC_CLOSE, (LPSTR)(DWORD)HBMMENU_MBAR_CLOSE );
1080 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
1081 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
1082 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
1083 SetMenuDefaultItem(hSysPopup, SC_CLOSE, FALSE);
1085 /* redraw menu */
1086 DrawMenuBar(frame);
1088 return 1;
1091 /**********************************************************************
1092 * MDI_RestoreFrameMenu
1094 static BOOL MDI_RestoreFrameMenu( HWND frame, HWND hChild )
1096 MENUITEMINFOW menuInfo;
1097 HMENU menu = GetMenu( frame );
1098 INT nItems = GetMenuItemCount(menu) - 1;
1099 UINT iId = GetMenuItemID(menu,nItems) ;
1101 TRACE("frame %04x,child %04x,nIt=%d,iId=%d\n",frame,hChild,nItems,iId);
1103 if(!(iId == SC_RESTORE || iId == SC_CLOSE) )
1104 return 0;
1107 * Remove the system menu, If that menu is the icon of the window
1108 * as it is in win95, we have to delete the bitmap.
1110 memset(&menuInfo, 0, sizeof(menuInfo));
1111 menuInfo.cbSize = sizeof(menuInfo);
1112 menuInfo.fMask = MIIM_DATA | MIIM_TYPE;
1114 GetMenuItemInfoW(menu,
1116 TRUE,
1117 &menuInfo);
1119 RemoveMenu(menu,0,MF_BYPOSITION);
1121 if ( (menuInfo.fType & MFT_BITMAP) &&
1122 (LOWORD(menuInfo.dwTypeData)!=0) &&
1123 (LOWORD(menuInfo.dwTypeData)!=hBmpClose) )
1125 DeleteObject((HBITMAP)LOWORD(menuInfo.dwTypeData));
1128 if(TWEAK_WineLook > WIN31_LOOK)
1130 /* close */
1131 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1133 /* restore */
1134 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1135 /* minimize */
1136 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1138 DrawMenuBar(frame);
1140 return 1;
1144 /**********************************************************************
1145 * MDI_UpdateFrameText
1147 * used when child window is maximized/restored
1149 * Note: lpTitle can be NULL
1151 static void MDI_UpdateFrameText( HWND frame, HWND hClient,
1152 BOOL repaint, LPCWSTR lpTitle )
1154 WCHAR lpBuffer[MDI_MAXTITLELENGTH+1];
1155 MDICLIENTINFO *ci = get_client_info( hClient );
1157 TRACE("repaint %i, frameText %s\n", repaint, debugstr_w(lpTitle));
1159 if (!ci) return;
1161 if (!lpTitle && !ci->frameTitle) /* first time around, get title from the frame window */
1163 GetWindowTextW( frame, lpBuffer, sizeof(lpBuffer)/sizeof(WCHAR) );
1164 lpTitle = lpBuffer;
1167 /* store new "default" title if lpTitle is not NULL */
1168 if (lpTitle)
1170 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1171 if ((ci->frameTitle = HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle)+1)*sizeof(WCHAR))))
1172 strcpyW( ci->frameTitle, lpTitle );
1175 if (ci->frameTitle)
1177 if (ci->hwndChildMaximized)
1179 /* combine frame title and child title if possible */
1181 static const WCHAR lpBracket[] = {' ','-',' ','[',0};
1182 static const WCHAR lpBracket2[] = {']',0};
1183 int i_frame_text_length = strlenW(ci->frameTitle);
1185 lstrcpynW( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
1187 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
1189 strcatW( lpBuffer, lpBracket );
1190 if (GetWindowTextW( ci->hwndChildMaximized, lpBuffer + i_frame_text_length + 4,
1191 MDI_MAXTITLELENGTH - i_frame_text_length - 5 ))
1192 strcatW( lpBuffer, lpBracket2 );
1193 else
1194 lpBuffer[i_frame_text_length] = 0; /* remove bracket */
1197 else
1199 lstrcpynW(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH+1 );
1202 else
1203 lpBuffer[0] = '\0';
1205 DefWindowProcW( frame, WM_SETTEXT, 0, (LPARAM)lpBuffer );
1206 if( repaint == MDI_REPAINTFRAME)
1207 SetWindowPos( frame, 0,0,0,0,0, SWP_FRAMECHANGED |
1208 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
1212 /* ----------------------------- Interface ---------------------------- */
1215 /**********************************************************************
1216 * MDIClientWndProc_common
1218 static LRESULT MDIClientWndProc_common( HWND hwnd, UINT message,
1219 WPARAM wParam, LPARAM lParam, BOOL unicode )
1221 MDICLIENTINFO *ci;
1223 if (!(ci = get_client_info( hwnd ))) return 0;
1225 switch (message)
1227 case WM_CREATE:
1229 RECT rect;
1230 /* Since we are using only cs->lpCreateParams, we can safely
1231 * cast to LPCREATESTRUCTA here */
1232 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
1233 WND *wndPtr = WIN_GetPtr( hwnd );
1235 /* Translation layer doesn't know what's in the cs->lpCreateParams
1236 * so we have to keep track of what environment we're in. */
1238 if( wndPtr->flags & WIN_ISWIN32 )
1240 #define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1241 ci->hWindowMenu = ccs->hWindowMenu;
1242 ci->idFirstChild = ccs->idFirstChild;
1243 #undef ccs
1245 else
1247 LPCLIENTCREATESTRUCT16 ccs = MapSL((SEGPTR)cs->lpCreateParams);
1248 ci->hWindowMenu = ccs->hWindowMenu;
1249 ci->idFirstChild = ccs->idFirstChild;
1251 WIN_ReleasePtr( wndPtr );
1253 ci->hwndChildMaximized = 0;
1254 ci->nActiveChildren = 0;
1255 ci->nTotalCreated = 0;
1256 ci->frameTitle = NULL;
1257 ci->mdiFlags = 0;
1258 SetWindowLongW( hwnd, GWL_STYLE, GetWindowLongW(hwnd,GWL_STYLE) | WS_CLIPCHILDREN );
1260 if (!hBmpClose) hBmpClose = CreateMDIMenuBitmap();
1262 if (ci->hWindowMenu != 0)
1263 AppendMenuW( ci->hWindowMenu, MF_SEPARATOR, 0, NULL );
1265 GetClientRect( GetParent(hwnd), &rect);
1266 MoveWindow( hwnd, 0, 0, rect.right, rect.bottom, FALSE );
1268 MDI_UpdateFrameText( GetParent(hwnd), hwnd, MDI_NOFRAMEREPAINT, NULL);
1270 TRACE("Client created - hwnd = %04x, idFirst = %u\n",
1271 hwnd, ci->idFirstChild );
1272 return 0;
1275 case WM_DESTROY:
1277 INT nItems;
1278 if( ci->hwndChildMaximized )
1279 MDI_RestoreFrameMenu( GetParent(hwnd), ci->hwndChildMaximized);
1280 if((ci->hWindowMenu != 0) &&
1281 (nItems = GetMenuItemCount(ci->hWindowMenu)) > 0)
1283 ci->idFirstChild = nItems - 1;
1284 ci->nActiveChildren++; /* to delete a separator */
1285 while( ci->nActiveChildren-- )
1286 DeleteMenu(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
1288 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1289 return 0;
1292 case WM_MDIACTIVATE:
1293 if( ci->hwndActiveChild != (HWND)wParam )
1294 SetWindowPos((HWND)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
1295 return 0;
1297 case WM_MDICASCADE:
1298 return MDICascade(hwnd, ci);
1300 case WM_MDICREATE:
1301 if (lParam)
1302 return (LRESULT)MDICreateChild( hwnd, ci, (MDICREATESTRUCTA *)lParam, unicode );
1303 return 0;
1305 case WM_MDIDESTROY:
1306 return MDIDestroyChild( hwnd, ci, WIN_GetFullHandle( (HWND)wParam ), TRUE );
1308 case WM_MDIGETACTIVE:
1309 if (lParam) *(BOOL *)lParam = (ci->hwndChildMaximized != 0);
1310 return (LRESULT)ci->hwndActiveChild;
1312 case WM_MDIICONARRANGE:
1313 ci->mdiFlags |= MDIF_NEEDUPDATE;
1314 ArrangeIconicWindows( hwnd );
1315 ci->sbRecalc = SB_BOTH+1;
1316 SendMessageW( hwnd, WM_MDICALCCHILDSCROLL, 0, 0 );
1317 return 0;
1319 case WM_MDIMAXIMIZE:
1320 ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1321 return 0;
1323 case WM_MDINEXT: /* lParam != 0 means previous window */
1324 MDI_SwitchActiveChild( hwnd, WIN_GetFullHandle( (HWND)wParam ), !lParam );
1325 break;
1327 case WM_MDIRESTORE:
1328 SendMessageW( (HWND)wParam, WM_SYSCOMMAND, SC_RESTORE, 0);
1329 return 0;
1331 case WM_MDISETMENU:
1332 return MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1334 case WM_MDIREFRESHMENU:
1335 return MDIRefreshMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1337 case WM_MDITILE:
1338 ci->mdiFlags |= MDIF_NEEDUPDATE;
1339 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1340 MDITile( hwnd, ci, wParam );
1341 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1342 return 0;
1344 case WM_VSCROLL:
1345 case WM_HSCROLL:
1346 ci->mdiFlags |= MDIF_NEEDUPDATE;
1347 ScrollChildren( hwnd, message, wParam, lParam );
1348 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1349 return 0;
1351 case WM_SETFOCUS:
1352 if (ci->hwndActiveChild && !IsIconic( ci->hwndActiveChild ))
1353 SetFocus( ci->hwndActiveChild );
1354 return 0;
1356 case WM_NCACTIVATE:
1357 if( ci->hwndActiveChild )
1358 SendMessageW(ci->hwndActiveChild, message, wParam, lParam);
1359 break;
1361 case WM_PARENTNOTIFY:
1362 if (LOWORD(wParam) == WM_LBUTTONDOWN)
1364 HWND child;
1365 POINT pt;
1366 pt.x = SLOWORD(lParam);
1367 pt.y = SHIWORD(lParam);
1368 child = ChildWindowFromPoint(hwnd, pt);
1370 TRACE("notification from %04x (%li,%li)\n",child,pt.x,pt.y);
1372 if( child && child != hwnd && child != ci->hwndActiveChild )
1373 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1375 return 0;
1377 case WM_SIZE:
1378 if( IsWindow(ci->hwndChildMaximized) )
1380 RECT rect;
1382 rect.left = 0;
1383 rect.top = 0;
1384 rect.right = LOWORD(lParam);
1385 rect.bottom = HIWORD(lParam);
1387 AdjustWindowRectEx(&rect, GetWindowLongA(ci->hwndChildMaximized,GWL_STYLE),
1388 0, GetWindowLongA(ci->hwndChildMaximized,GWL_EXSTYLE) );
1389 MoveWindow(ci->hwndChildMaximized, rect.left, rect.top,
1390 rect.right - rect.left, rect.bottom - rect.top, 1);
1392 else
1393 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1395 break;
1397 case WM_MDICALCCHILDSCROLL:
1398 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1400 CalcChildScroll(hwnd, ci->sbRecalc-1);
1401 ci->sbRecalc = 0;
1402 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1404 return 0;
1406 return unicode ? DefWindowProcW( hwnd, message, wParam, lParam ) :
1407 DefWindowProcA( hwnd, message, wParam, lParam );
1410 /***********************************************************************
1411 * MDIClientWndProcA
1413 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1415 if (!IsWindow(hwnd)) return 0;
1416 return MDIClientWndProc_common( hwnd, message, wParam, lParam, FALSE );
1419 /***********************************************************************
1420 * MDIClientWndProcW
1422 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1424 if (!IsWindow(hwnd)) return 0;
1425 return MDIClientWndProc_common( hwnd, message, wParam, lParam, TRUE );
1428 /***********************************************************************
1429 * DefFrameProc (USER.445)
1431 LRESULT WINAPI DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient,
1432 UINT16 message, WPARAM16 wParam, LPARAM lParam )
1434 switch (message)
1436 case WM_SETTEXT:
1437 lParam = (LPARAM)MapSL(lParam);
1438 /* fall through */
1439 case WM_COMMAND:
1440 case WM_NCACTIVATE:
1441 case WM_SETFOCUS:
1442 case WM_SIZE:
1443 return DefFrameProcA( WIN_Handle32(hwnd), WIN_Handle32(hwndMDIClient),
1444 message, wParam, lParam );
1446 case WM_NEXTMENU:
1448 MDINEXTMENU next_menu;
1449 DefFrameProcW( WIN_Handle32(hwnd), WIN_Handle32(hwndMDIClient),
1450 message, wParam, (LPARAM)&next_menu );
1451 return MAKELONG( next_menu.hmenuNext, HWND_16(next_menu.hwndNext) );
1453 default:
1454 return DefWindowProc16(hwnd, message, wParam, lParam);
1459 /***********************************************************************
1460 * DefFrameProcA (USER32.@)
1462 LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1463 UINT message, WPARAM wParam, LPARAM lParam)
1465 if (hwndMDIClient)
1467 switch (message)
1469 case WM_SETTEXT:
1471 DWORD len = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0 );
1472 LPWSTR text = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1473 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, text, len );
1474 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, text );
1475 HeapFree( GetProcessHeap(), 0, text );
1477 return 1; /* success. FIXME: check text length */
1479 case WM_COMMAND:
1480 case WM_NCACTIVATE:
1481 case WM_NEXTMENU:
1482 case WM_SETFOCUS:
1483 case WM_SIZE:
1484 return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1487 return DefWindowProcA(hwnd, message, wParam, lParam);
1491 /***********************************************************************
1492 * DefFrameProcW (USER32.@)
1494 LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1495 UINT message, WPARAM wParam, LPARAM lParam)
1497 MDICLIENTINFO *ci = get_client_info( hwndMDIClient );
1499 if (ci)
1501 switch (message)
1503 case WM_COMMAND:
1505 WORD id = LOWORD(wParam);
1506 /* check for possible syscommands for maximized MDI child */
1507 if (id < ci->idFirstChild || id >= ci->idFirstChild + ci->nActiveChildren)
1509 if( (id - 0xf000) & 0xf00f ) break;
1510 if( !ci->hwndChildMaximized ) break;
1511 switch( id )
1513 case SC_SIZE:
1514 case SC_MOVE:
1515 case SC_MINIMIZE:
1516 case SC_MAXIMIZE:
1517 case SC_NEXTWINDOW:
1518 case SC_PREVWINDOW:
1519 case SC_CLOSE:
1520 case SC_RESTORE:
1521 return SendMessageW( ci->hwndChildMaximized, WM_SYSCOMMAND,
1522 wParam, lParam);
1525 else
1527 HWND childHwnd;
1528 if (id - ci->idFirstChild == MDI_MOREWINDOWSLIMIT)
1529 /* User chose "More Windows..." */
1530 childHwnd = MDI_MoreWindowsDialog(hwndMDIClient);
1531 else
1532 /* User chose one of the windows listed in the "Windows" menu */
1533 childHwnd = MDI_GetChildByID(hwndMDIClient,id);
1535 if( childHwnd )
1536 SendMessageW( hwndMDIClient, WM_MDIACTIVATE, (WPARAM)childHwnd, 0 );
1539 break;
1541 case WM_NCACTIVATE:
1542 SendMessageW(hwndMDIClient, message, wParam, lParam);
1543 break;
1545 case WM_SETTEXT:
1546 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, (LPWSTR)lParam );
1547 return 1; /* success. FIXME: check text length */
1549 case WM_SETFOCUS:
1550 SetFocus(hwndMDIClient);
1551 break;
1553 case WM_SIZE:
1554 MoveWindow(hwndMDIClient, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
1555 break;
1557 case WM_NEXTMENU:
1559 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1561 if (!IsIconic(hwnd) && ci->hwndActiveChild && !ci->hwndChildMaximized)
1563 /* control menu is between the frame system menu and
1564 * the first entry of menu bar */
1565 WND *wndPtr = WIN_GetPtr(hwnd);
1567 if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1568 (wParam == VK_RIGHT && GetSubMenu(wndPtr->hSysMenu, 0) == next_menu->hmenuIn) )
1570 WIN_ReleasePtr(wndPtr);
1571 wndPtr = WIN_GetPtr(ci->hwndActiveChild);
1572 next_menu->hmenuNext = GetSubMenu(wndPtr->hSysMenu, 0);
1573 next_menu->hwndNext = ci->hwndActiveChild;
1575 WIN_ReleasePtr(wndPtr);
1577 return 0;
1582 return DefWindowProcW( hwnd, message, wParam, lParam );
1586 /***********************************************************************
1587 * DefMDIChildProc (USER.447)
1589 LRESULT WINAPI DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1590 WPARAM16 wParam, LPARAM lParam )
1592 switch (message)
1594 case WM_SETTEXT:
1595 return DefMDIChildProcA( WIN_Handle32(hwnd), message, wParam, (LPARAM)MapSL(lParam) );
1596 case WM_MENUCHAR:
1597 case WM_CLOSE:
1598 case WM_SETFOCUS:
1599 case WM_CHILDACTIVATE:
1600 case WM_SYSCOMMAND:
1601 case WM_SETVISIBLE:
1602 case WM_SIZE:
1603 case WM_SYSCHAR:
1604 return DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, lParam );
1605 case WM_GETMINMAXINFO:
1607 MINMAXINFO16 *mmi16 = (MINMAXINFO16 *)MapSL(lParam);
1608 MINMAXINFO mmi;
1609 STRUCT32_MINMAXINFO16to32( mmi16, &mmi );
1610 DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, (LPARAM)&mmi );
1611 STRUCT32_MINMAXINFO32to16( &mmi, mmi16 );
1612 return 0;
1614 case WM_NEXTMENU:
1616 MDINEXTMENU next_menu;
1617 DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, (LPARAM)&next_menu );
1618 return MAKELONG( next_menu.hmenuNext, HWND_16(next_menu.hwndNext) );
1620 default:
1621 return DefWindowProc16(hwnd, message, wParam, lParam);
1626 /***********************************************************************
1627 * DefMDIChildProcA (USER32.@)
1629 LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1630 WPARAM wParam, LPARAM lParam )
1632 HWND client = GetParent(hwnd);
1633 MDICLIENTINFO *ci = get_client_info( client );
1635 hwnd = WIN_GetFullHandle( hwnd );
1636 if (!ci) return DefWindowProcA( hwnd, message, wParam, lParam );
1638 switch (message)
1640 case WM_SETTEXT:
1641 DefWindowProcA(hwnd, message, wParam, lParam);
1642 MDI_MenuModifyItem( client, hwnd );
1643 if( ci->hwndChildMaximized == hwnd )
1644 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1645 return 1; /* success. FIXME: check text length */
1647 case WM_GETMINMAXINFO:
1648 case WM_MENUCHAR:
1649 case WM_CLOSE:
1650 case WM_SETFOCUS:
1651 case WM_CHILDACTIVATE:
1652 case WM_SYSCOMMAND:
1653 case WM_SETVISIBLE:
1654 case WM_SIZE:
1655 case WM_NEXTMENU:
1656 case WM_SYSCHAR:
1657 return DefMDIChildProcW( hwnd, message, wParam, lParam );
1659 return DefWindowProcA(hwnd, message, wParam, lParam);
1663 /***********************************************************************
1664 * DefMDIChildProcW (USER32.@)
1666 LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1667 WPARAM wParam, LPARAM lParam )
1669 HWND client = GetParent(hwnd);
1670 MDICLIENTINFO *ci = get_client_info( client );
1672 hwnd = WIN_GetFullHandle( hwnd );
1673 if (!ci) return DefWindowProcW( hwnd, message, wParam, lParam );
1675 switch (message)
1677 case WM_SETTEXT:
1678 DefWindowProcW(hwnd, message, wParam, lParam);
1679 MDI_MenuModifyItem( client, hwnd );
1680 if( ci->hwndChildMaximized == hwnd )
1681 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1682 return 1; /* success. FIXME: check text length */
1684 case WM_GETMINMAXINFO:
1685 MDI_ChildGetMinMaxInfo( client, hwnd, (MINMAXINFO *)lParam );
1686 return 0;
1688 case WM_MENUCHAR:
1689 return 0x00010000; /* MDI children don't have menu bars */
1691 case WM_CLOSE:
1692 SendMessageW( client, WM_MDIDESTROY, (WPARAM)hwnd, 0 );
1693 return 0;
1695 case WM_SETFOCUS:
1696 if (ci->hwndActiveChild != hwnd) MDI_ChildActivate( client, hwnd );
1697 break;
1699 case WM_CHILDACTIVATE:
1700 MDI_ChildActivate( client, hwnd );
1701 return 0;
1703 case WM_SYSCOMMAND:
1704 switch( wParam )
1706 case SC_MOVE:
1707 if( ci->hwndChildMaximized == hwnd) return 0;
1708 break;
1709 case SC_RESTORE:
1710 case SC_MINIMIZE:
1711 SetWindowLongA( hwnd, GWL_STYLE,
1712 GetWindowLongA( hwnd, GWL_STYLE ) | WS_SYSMENU );
1713 break;
1714 case SC_MAXIMIZE:
1715 if (ci->hwndChildMaximized == hwnd)
1716 return SendMessageW( GetParent(client), message, wParam, lParam);
1717 SetWindowLongW( hwnd, GWL_STYLE,
1718 GetWindowLongW( hwnd, GWL_STYLE ) & ~WS_SYSMENU );
1719 break;
1720 case SC_NEXTWINDOW:
1721 SendMessageW( client, WM_MDINEXT, 0, 0);
1722 return 0;
1723 case SC_PREVWINDOW:
1724 SendMessageW( client, WM_MDINEXT, 0, 1);
1725 return 0;
1727 break;
1729 case WM_SETVISIBLE:
1730 if( ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1731 else MDI_PostUpdate(client, ci, SB_BOTH+1);
1732 break;
1734 case WM_SIZE:
1735 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1737 ci->hwndChildMaximized = 0;
1738 MDI_RestoreFrameMenu( GetParent(client), hwnd );
1739 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1742 if( wParam == SIZE_MAXIMIZED )
1744 HWND hMaxChild = ci->hwndChildMaximized;
1746 if( hMaxChild == hwnd ) break;
1747 if( hMaxChild)
1749 SendMessageW( hMaxChild, WM_SETREDRAW, FALSE, 0 );
1750 MDI_RestoreFrameMenu( GetParent(client), hMaxChild );
1751 ShowWindow( hMaxChild, SW_SHOWNOACTIVATE );
1752 SendMessageW( hMaxChild, WM_SETREDRAW, TRUE, 0 );
1754 TRACE("maximizing child %04x\n", hwnd );
1756 /* keep track of the maximized window. */
1757 ci->hwndChildMaximized = hwnd; /* !!! */
1759 /* The maximized window should also be the active window */
1760 MDI_ChildActivate( client, hwnd );
1761 MDI_AugmentFrameMenu( GetParent(client), hwnd );
1762 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1765 if( wParam == SIZE_MINIMIZED )
1767 HWND switchTo = MDI_GetWindow(ci, hwnd, TRUE, WS_MINIMIZE);
1769 if (switchTo) SendMessageW( switchTo, WM_CHILDACTIVATE, 0, 0);
1771 MDI_PostUpdate(client, ci, SB_BOTH+1);
1772 break;
1774 case WM_NEXTMENU:
1776 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1777 HWND parent = GetParent(client);
1779 if( wParam == VK_LEFT ) /* switch to frame system menu */
1781 WND *wndPtr = WIN_GetPtr( parent );
1782 next_menu->hmenuNext = GetSubMenu( wndPtr->hSysMenu, 0 );
1783 WIN_ReleasePtr( wndPtr );
1785 if( wParam == VK_RIGHT ) /* to frame menu bar */
1787 next_menu->hmenuNext = GetMenu(parent);
1789 next_menu->hwndNext = parent;
1790 return 0;
1793 case WM_SYSCHAR:
1794 if (wParam == '-')
1796 SendMessageW( hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (DWORD)VK_SPACE);
1797 return 0;
1799 break;
1801 return DefWindowProcW(hwnd, message, wParam, lParam);
1804 /**********************************************************************
1805 * CreateMDIWindowA (USER32.@) Creates a MDI child
1807 * RETURNS
1808 * Success: Handle to created window
1809 * Failure: NULL
1811 HWND WINAPI CreateMDIWindowA(
1812 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1813 LPCSTR lpWindowName, /* [in] Pointer to window name */
1814 DWORD dwStyle, /* [in] Window style */
1815 INT X, /* [in] Horizontal position of window */
1816 INT Y, /* [in] Vertical position of window */
1817 INT nWidth, /* [in] Width of window */
1818 INT nHeight, /* [in] Height of window */
1819 HWND hWndParent, /* [in] Handle to parent window */
1820 HINSTANCE hInstance, /* [in] Handle to application instance */
1821 LPARAM lParam) /* [in] Application-defined value */
1823 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1824 MDICREATESTRUCTA cs;
1826 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
1827 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1828 nWidth,nHeight,hWndParent,hInstance,lParam);
1830 if (!pCi)
1832 ERR("bad hwnd for MDI-client: %04x\n", hWndParent);
1833 return 0;
1835 cs.szClass=lpClassName;
1836 cs.szTitle=lpWindowName;
1837 cs.hOwner=hInstance;
1838 cs.x=X;
1839 cs.y=Y;
1840 cs.cx=nWidth;
1841 cs.cy=nHeight;
1842 cs.style=dwStyle;
1843 cs.lParam=lParam;
1845 return MDICreateChild(hWndParent, pCi, &cs, FALSE);
1848 /***********************************************************************
1849 * CreateMDIWindowW (USER32.@) Creates a MDI child
1851 * RETURNS
1852 * Success: Handle to created window
1853 * Failure: NULL
1855 HWND WINAPI CreateMDIWindowW(
1856 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1857 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1858 DWORD dwStyle, /* [in] Window style */
1859 INT X, /* [in] Horizontal position of window */
1860 INT Y, /* [in] Vertical position of window */
1861 INT nWidth, /* [in] Width of window */
1862 INT nHeight, /* [in] Height of window */
1863 HWND hWndParent, /* [in] Handle to parent window */
1864 HINSTANCE hInstance, /* [in] Handle to application instance */
1865 LPARAM lParam) /* [in] Application-defined value */
1867 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1868 MDICREATESTRUCTW cs;
1870 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
1871 debugstr_w(lpClassName), debugstr_w(lpWindowName), dwStyle, X, Y,
1872 nWidth, nHeight, hWndParent, hInstance, lParam);
1874 if (!pCi)
1876 ERR("bad hwnd for MDI-client: %04x\n", hWndParent);
1877 return 0;
1879 cs.szClass = lpClassName;
1880 cs.szTitle = lpWindowName;
1881 cs.hOwner = hInstance;
1882 cs.x = X;
1883 cs.y = Y;
1884 cs.cx = nWidth;
1885 cs.cy = nHeight;
1886 cs.style = dwStyle;
1887 cs.lParam = lParam;
1889 return MDICreateChild(hWndParent, pCi, (MDICREATESTRUCTA *)&cs, TRUE);
1892 /**********************************************************************
1893 * TranslateMDISysAccel (USER32.@)
1895 BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1897 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1899 MDICLIENTINFO *ci = get_client_info( hwndClient );
1900 WPARAM wParam = 0;
1902 if (!ci || !IsWindowEnabled(ci->hwndActiveChild)) return 0;
1904 /* translate if the Ctrl key is down and Alt not. */
1906 if( (GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
1908 switch( msg->wParam )
1910 case VK_F6:
1911 case VK_TAB:
1912 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 ) ? SC_NEXTWINDOW : SC_PREVWINDOW;
1913 break;
1914 case VK_F4:
1915 case VK_RBUTTON:
1916 wParam = SC_CLOSE;
1917 break;
1918 default:
1919 return 0;
1921 TRACE("wParam = %04x\n", wParam);
1922 SendMessageW(ci->hwndActiveChild, WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
1923 return 1;
1926 return 0; /* failure */
1929 /***********************************************************************
1930 * CalcChildScroll (USER32.@)
1932 void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
1934 SCROLLINFO info;
1935 RECT childRect, clientRect;
1936 HWND *list;
1938 GetClientRect( hwnd, &clientRect );
1939 SetRectEmpty( &childRect );
1941 if ((list = WIN_ListChildren( hwnd )))
1943 int i;
1944 for (i = 0; list[i]; i++)
1946 DWORD style = GetWindowLongW( list[i], GWL_STYLE );
1947 if (style & WS_MAXIMIZE)
1949 HeapFree( GetProcessHeap(), 0, list );
1950 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1951 return;
1953 if (style & WS_VISIBLE)
1955 WND *pWnd = WIN_FindWndPtr( list[i] );
1956 UnionRect( &childRect, &pWnd->rectWindow, &childRect );
1957 WIN_ReleaseWndPtr( pWnd );
1960 HeapFree( GetProcessHeap(), 0, list );
1962 UnionRect( &childRect, &clientRect, &childRect );
1964 /* set common info values */
1965 info.cbSize = sizeof(info);
1966 info.fMask = SIF_POS | SIF_RANGE;
1968 /* set the specific */
1969 switch( scroll )
1971 case SB_BOTH:
1972 case SB_HORZ:
1973 info.nMin = childRect.left;
1974 info.nMax = childRect.right - clientRect.right;
1975 info.nPos = clientRect.left - childRect.left;
1976 SetScrollInfo(hwnd, scroll, &info, TRUE);
1977 if (scroll == SB_HORZ) break;
1978 /* fall through */
1979 case SB_VERT:
1980 info.nMin = childRect.top;
1981 info.nMax = childRect.bottom - clientRect.bottom;
1982 info.nPos = clientRect.top - childRect.top;
1983 SetScrollInfo(hwnd, scroll, &info, TRUE);
1984 break;
1989 /***********************************************************************
1990 * ScrollChildren (USER32.@)
1992 void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
1993 LPARAM lParam)
1995 INT newPos = -1;
1996 INT curPos, length, minPos, maxPos, shift;
1997 RECT rect;
1999 GetClientRect( hWnd, &rect );
2001 switch(uMsg)
2003 case WM_HSCROLL:
2004 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
2005 curPos = GetScrollPos(hWnd,SB_HORZ);
2006 length = (rect.right - rect.left) / 2;
2007 shift = GetSystemMetrics(SM_CYHSCROLL);
2008 break;
2009 case WM_VSCROLL:
2010 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
2011 curPos = GetScrollPos(hWnd,SB_VERT);
2012 length = (rect.bottom - rect.top) / 2;
2013 shift = GetSystemMetrics(SM_CXVSCROLL);
2014 break;
2015 default:
2016 return;
2019 switch( wParam )
2021 case SB_LINEUP:
2022 newPos = curPos - shift;
2023 break;
2024 case SB_LINEDOWN:
2025 newPos = curPos + shift;
2026 break;
2027 case SB_PAGEUP:
2028 newPos = curPos - length;
2029 break;
2030 case SB_PAGEDOWN:
2031 newPos = curPos + length;
2032 break;
2034 case SB_THUMBPOSITION:
2035 newPos = LOWORD(lParam);
2036 break;
2038 case SB_THUMBTRACK:
2039 return;
2041 case SB_TOP:
2042 newPos = minPos;
2043 break;
2044 case SB_BOTTOM:
2045 newPos = maxPos;
2046 break;
2047 case SB_ENDSCROLL:
2048 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
2049 return;
2052 if( newPos > maxPos )
2053 newPos = maxPos;
2054 else
2055 if( newPos < minPos )
2056 newPos = minPos;
2058 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
2060 if( uMsg == WM_VSCROLL )
2061 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
2062 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2063 else
2064 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
2065 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2069 /******************************************************************************
2070 * CascadeWindows (USER32.@) Cascades MDI child windows
2072 * RETURNS
2073 * Success: Number of cascaded windows.
2074 * Failure: 0
2076 WORD WINAPI
2077 CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2078 UINT cKids, const HWND *lpKids)
2080 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2081 hwndParent, wFlags, cKids);
2083 return 0;
2087 /******************************************************************************
2088 * TileWindows (USER32.@) Tiles MDI child windows
2090 * RETURNS
2091 * Success: Number of tiled windows.
2092 * Failure: 0
2094 WORD WINAPI
2095 TileWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2096 UINT cKids, const HWND *lpKids)
2098 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2099 hwndParent, wFlags, cKids);
2101 return 0;
2104 /************************************************************************
2105 * "More Windows..." functionality
2108 /* MDI_MoreWindowsDlgProc
2110 * This function will process the messages sent to the "More Windows..."
2111 * dialog.
2112 * Return values: 0 = cancel pressed
2113 * HWND = ok pressed or double-click in the list...
2117 static INT_PTR WINAPI MDI_MoreWindowsDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
2119 switch (iMsg)
2121 case WM_INITDIALOG:
2123 UINT widest = 0;
2124 UINT length;
2125 UINT i;
2126 MDICLIENTINFO *ci = get_client_info( (HWND)lParam );
2127 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2128 HWND *list, *sorted_list;
2130 if (!(list = WIN_ListChildren( (HWND)lParam ))) return TRUE;
2131 if (!(sorted_list = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
2132 sizeof(HWND) * ci->nActiveChildren )))
2134 HeapFree( GetProcessHeap(), 0, list );
2135 return FALSE;
2138 /* Fill the list, sorted by id... */
2139 for (i = 0; list[i]; i++)
2141 UINT id = GetWindowLongW( list[i], GWL_ID ) - ci->idFirstChild;
2142 if (id < ci->nActiveChildren) sorted_list[id] = list[i];
2144 HeapFree( GetProcessHeap(), 0, list );
2146 for (i = 0; i < ci->nActiveChildren; i++)
2148 WCHAR buffer[128];
2150 if (!GetWindowTextW( sorted_list[i], buffer, sizeof(buffer)/sizeof(WCHAR) ))
2151 continue;
2152 SendMessageW(hListBox, LB_ADDSTRING, 0, (LPARAM)buffer );
2153 SendMessageW(hListBox, LB_SETITEMDATA, i, (LPARAM)sorted_list[i] );
2154 length = strlenW(buffer); /* FIXME: should use GetTextExtentPoint */
2155 if (length > widest)
2156 widest = length;
2158 /* Make sure the horizontal scrollbar scrolls ok */
2159 SendMessageW(hListBox, LB_SETHORIZONTALEXTENT, widest * 6, 0);
2161 /* Set the current selection */
2162 SendMessageW(hListBox, LB_SETCURSEL, MDI_MOREWINDOWSLIMIT, 0);
2163 return TRUE;
2166 case WM_COMMAND:
2167 switch (LOWORD(wParam))
2169 default:
2170 if (HIWORD(wParam) != LBN_DBLCLK) break;
2171 /* fall through */
2172 case IDOK:
2174 /* windows are sorted by menu ID, so we must return the
2175 * window associated to the given id
2177 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2178 UINT index = SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
2179 LRESULT res = SendMessageW(hListBox, LB_GETITEMDATA, index, 0);
2180 EndDialog(hDlg, res);
2181 return TRUE;
2183 case IDCANCEL:
2184 EndDialog(hDlg, 0);
2185 return TRUE;
2187 break;
2189 return FALSE;
2194 * MDI_MoreWindowsDialog
2196 * Prompts the user with a listbox containing the opened
2197 * documents. The user can then choose a windows and click
2198 * on OK to set the current window to the one selected, or
2199 * CANCEL to cancel. The function returns a handle to the
2200 * selected window.
2203 static HWND MDI_MoreWindowsDialog(HWND hwnd)
2205 LPCVOID template;
2206 HRSRC hRes;
2207 HANDLE hDlgTmpl;
2209 hRes = FindResourceA(GetModuleHandleA("USER32"), "MDI_MOREWINDOWS", RT_DIALOGA);
2211 if (hRes == 0)
2212 return 0;
2214 hDlgTmpl = LoadResource(GetModuleHandleA("USER32"), hRes );
2216 if (hDlgTmpl == 0)
2217 return 0;
2219 template = LockResource( hDlgTmpl );
2221 if (template == 0)
2222 return 0;
2224 return (HWND) DialogBoxIndirectParamA(GetModuleHandleA("USER32"),
2225 (LPDLGTEMPLATEA) template,
2226 hwnd, MDI_MoreWindowsDlgProc, (LPARAM) hwnd);
2231 * MDI_SwapMenuItems
2233 * Will swap the menu IDs for the given 2 positions.
2234 * pos1 and pos2 are menu IDs
2239 static void MDI_SwapMenuItems(HWND parent, UINT pos1, UINT pos2)
2241 HWND *list;
2242 int i;
2244 if (!(list = WIN_ListChildren( parent ))) return;
2245 for (i = 0; list[i]; i++)
2247 UINT id = GetWindowLongW( list[i], GWL_ID );
2248 if (id == pos1) SetWindowLongW( list[i], GWL_ID, pos2 );
2249 else if (id == pos2) SetWindowLongW( list[i], GWL_ID, pos1 );
2251 HeapFree( GetProcessHeap(), 0, list );