- Added f8 (history retrieval from partial command) support
[wine/multimedia.git] / windows / mdi.c
blob7d961743ce0a0c9ff334c38f123ecf3492c178f3
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 "wine/unicode.h"
93 #include "win.h"
94 #include "nonclient.h"
95 #include "controls.h"
96 #include "user.h"
97 #include "struct32.h"
98 #include "wine/debug.h"
99 #include "dlgs.h"
101 WINE_DEFAULT_DEBUG_CHANNEL(mdi);
103 #define MDI_MAXLISTLENGTH 0x40
104 #define MDI_MAXTITLELENGTH 0xa1
106 #define MDI_NOFRAMEREPAINT 0
107 #define MDI_REPAINTFRAMENOW 1
108 #define MDI_REPAINTFRAME 2
110 #define WM_MDICALCCHILDSCROLL 0x10ac /* this is exactly what Windows uses */
112 /* "More Windows..." definitions */
113 #define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
114 option will appear under the Windows menu */
115 #define MDI_IDC_LISTBOX 100
116 #define MDI_IDS_MOREWINDOWS 13
118 #define MDIF_NEEDUPDATE 0x0001
120 typedef struct
122 UINT nActiveChildren;
123 HWND hwndChildMaximized;
124 HWND hwndActiveChild;
125 HMENU hWindowMenu;
126 UINT idFirstChild;
127 LPWSTR frameTitle;
128 UINT nTotalCreated;
129 UINT mdiFlags;
130 UINT sbRecalc; /* SB_xxx flags for scrollbar fixup */
131 } MDICLIENTINFO;
133 static HBITMAP hBmpClose = 0;
135 /* ----------------- declarations ----------------- */
136 static void MDI_UpdateFrameText( HWND, HWND, BOOL, LPCWSTR);
137 static BOOL MDI_AugmentFrameMenu( HWND, HWND );
138 static BOOL MDI_RestoreFrameMenu( HWND, HWND );
139 static LONG MDI_ChildActivate( HWND, HWND );
141 static HWND MDI_MoreWindowsDialog(HWND);
142 static void MDI_SwapMenuItems(HWND, UINT, UINT);
143 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
144 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
146 /* -------- Miscellaneous service functions ----------
148 * MDI_GetChildByID
150 static HWND MDI_GetChildByID(HWND hwnd, UINT id)
152 HWND ret;
153 HWND *win_array;
154 int i;
156 if (!(win_array = WIN_ListChildren( hwnd ))) return 0;
157 for (i = 0; win_array[i]; i++)
159 if (GetWindowLongA( win_array[i], GWL_ID ) == id) break;
161 ret = win_array[i];
162 HeapFree( GetProcessHeap(), 0, win_array );
163 return ret;
166 static void MDI_PostUpdate(HWND hwnd, MDICLIENTINFO* ci, WORD recalc)
168 if( !(ci->mdiFlags & MDIF_NEEDUPDATE) )
170 ci->mdiFlags |= MDIF_NEEDUPDATE;
171 PostMessageA( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
173 ci->sbRecalc = recalc;
177 /*********************************************************************
178 * MDIClient class descriptor
180 const struct builtin_class_descr MDICLIENT_builtin_class =
182 "MDIClient", /* name */
183 CS_GLOBALCLASS, /* style */
184 MDIClientWndProcA, /* procA */
185 MDIClientWndProcW, /* procW */
186 sizeof(MDICLIENTINFO), /* extra */
187 IDC_ARROWA, /* cursor */
188 COLOR_APPWORKSPACE+1 /* brush */
192 static MDICLIENTINFO *get_client_info( HWND client )
194 MDICLIENTINFO *ret = NULL;
195 WND *win = WIN_GetPtr( client );
196 if (win)
198 if (win == WND_OTHER_PROCESS)
200 ERR( "client %x belongs to other process\n", client );
201 return NULL;
203 if (win->cbWndExtra < sizeof(MDICLIENTINFO)) WARN( "%x is not an MDI client\n", client );
204 else ret = (MDICLIENTINFO *)win->wExtra;
205 WIN_ReleasePtr( win );
207 return ret;
210 /**********************************************************************
211 * MDI_MenuModifyItem
213 static void MDI_MenuModifyItem( HWND client, HWND hWndChild )
215 MDICLIENTINFO *clientInfo = get_client_info( client );
216 WCHAR buffer[128];
217 UINT n, id;
219 if (!clientInfo || !clientInfo->hWindowMenu) return;
221 id = GetWindowLongA( hWndChild, GWL_ID );
222 if (id >= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT) return;
223 buffer[0] = '&';
224 buffer[1] = '1' + id - clientInfo->idFirstChild;
225 buffer[2] = ' ';
226 GetWindowTextW( hWndChild, buffer + 3, sizeof(buffer)/sizeof(WCHAR) - 3 );
228 n = GetMenuState(clientInfo->hWindowMenu, id, MF_BYCOMMAND);
229 ModifyMenuW(clientInfo->hWindowMenu, id, MF_BYCOMMAND | MF_STRING, id, buffer );
230 CheckMenuItem(clientInfo->hWindowMenu, id, n & MF_CHECKED);
233 /**********************************************************************
234 * MDI_MenuDeleteItem
236 static BOOL MDI_MenuDeleteItem( HWND client, HWND hWndChild )
238 WCHAR buffer[128];
239 static const WCHAR format[] = {'&','%','d',' ',0};
240 MDICLIENTINFO *clientInfo = get_client_info( client );
241 UINT index = 0,id,n;
243 if( !clientInfo->nActiveChildren || !clientInfo->hWindowMenu )
244 return FALSE;
246 id = GetWindowLongA( hWndChild, GWL_ID );
247 DeleteMenu(clientInfo->hWindowMenu,id,MF_BYCOMMAND);
249 /* walk the rest of MDI children to prevent gaps in the id
250 * sequence and in the menu child list */
252 for( index = id+1; index <= clientInfo->nActiveChildren +
253 clientInfo->idFirstChild; index++ )
255 HWND hwnd = MDI_GetChildByID(client,index);
256 if (!hwnd)
258 TRACE("no window for id=%i\n",index);
259 continue;
262 /* set correct id */
263 SetWindowLongW( hwnd, GWL_ID, GetWindowLongW( hwnd, GWL_ID ) - 1 );
265 n = wsprintfW(buffer, format ,index - clientInfo->idFirstChild);
266 GetWindowTextW( hwnd, buffer + n, sizeof(buffer)/sizeof(WCHAR) - n );
268 /* change menu if the current child is to be shown in the
269 * "Windows" menu
271 if (index <= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT)
272 ModifyMenuW(clientInfo->hWindowMenu ,index ,MF_BYCOMMAND | MF_STRING,
273 index - 1 , buffer );
276 /* We must restore the "More Windows..." option if there are enough children
278 if (clientInfo->nActiveChildren - 1 > MDI_MOREWINDOWSLIMIT)
280 WCHAR szTmp[50];
281 LoadStringW(GetModuleHandleA("USER32"), MDI_IDS_MOREWINDOWS, szTmp, sizeof(szTmp)/sizeof(szTmp[0]));
282 AppendMenuW(clientInfo->hWindowMenu, MF_STRING, clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT, szTmp);
284 return TRUE;
287 /**********************************************************************
288 * MDI_GetWindow
290 * returns "activateable" child different from the current or zero
292 static HWND MDI_GetWindow(MDICLIENTINFO *clientInfo, HWND hWnd, BOOL bNext,
293 DWORD dwStyleMask )
295 int i;
296 HWND *list;
297 HWND last = 0;
299 dwStyleMask |= WS_DISABLED | WS_VISIBLE;
300 if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
302 if (!(list = WIN_ListChildren( GetParent(hWnd) ))) return 0;
303 i = 0;
304 /* start from next after hWnd */
305 while (list[i] && list[i] != hWnd) i++;
306 if (list[i]) i++;
308 for ( ; list[i]; i++)
310 if (GetWindow( list[i], GW_OWNER )) continue;
311 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
312 last = list[i];
313 if (bNext) goto found;
315 /* now restart from the beginning */
316 for (i = 0; list[i] && list[i] != hWnd; i++)
318 if (GetWindow( list[i], GW_OWNER )) continue;
319 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
320 last = list[i];
321 if (bNext) goto found;
323 found:
324 HeapFree( GetProcessHeap(), 0, list );
325 return last;
328 /**********************************************************************
329 * MDI_CalcDefaultChildPos
331 * It seems that the default height is about 2/3 of the client rect
333 static void MDI_CalcDefaultChildPos( HWND hwnd, WORD n, LPPOINT lpPos, INT delta)
335 INT nstagger;
336 RECT rect;
337 INT spacing = GetSystemMetrics(SM_CYCAPTION) +
338 GetSystemMetrics(SM_CYFRAME) - 1;
340 GetClientRect( hwnd, &rect );
341 if( rect.bottom - rect.top - delta >= spacing )
342 rect.bottom -= delta;
344 nstagger = (rect.bottom - rect.top)/(3 * spacing);
345 lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
346 lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
347 lpPos[0].x = lpPos[0].y = spacing * (n%(nstagger+1));
350 /**********************************************************************
351 * MDISetMenu
353 static LRESULT MDISetMenu( HWND hwnd, HMENU hmenuFrame,
354 HMENU hmenuWindow)
356 MDICLIENTINFO *ci;
357 HWND hwndFrame = GetParent(hwnd);
358 HMENU oldFrameMenu = GetMenu(hwndFrame);
360 TRACE("%04x %04x %04x\n",
361 hwnd, hmenuFrame, hmenuWindow);
363 if (hmenuFrame && !IsMenu(hmenuFrame))
365 WARN("hmenuFrame is not a menu handle\n");
366 return 0L;
369 if (hmenuWindow && !IsMenu(hmenuWindow))
371 WARN("hmenuWindow is not a menu handle\n");
372 return 0L;
375 if (!(ci = get_client_info( hwnd ))) return 0;
377 if( ci->hwndChildMaximized && hmenuFrame && hmenuFrame!=oldFrameMenu )
378 MDI_RestoreFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
380 if( hmenuWindow && ci->hWindowMenu && hmenuWindow!=ci->hWindowMenu )
382 /* delete menu items from ci->hWindowMenu
383 * and add them to hmenuWindow */
385 INT i = GetMenuItemCount(ci->hWindowMenu) - 1;
386 INT pos = GetMenuItemCount(hmenuWindow) + 1;
388 AppendMenuA( hmenuWindow, MF_SEPARATOR, 0, NULL);
390 if( ci->nActiveChildren )
392 INT j;
393 LPWSTR buffer = NULL;
394 MENUITEMINFOW mii;
395 INT nbWindowsMenuItems; /* num of documents shown + "More Windows..." if present */
397 if (ci->nActiveChildren <= MDI_MOREWINDOWSLIMIT)
398 nbWindowsMenuItems = ci->nActiveChildren;
399 else
400 nbWindowsMenuItems = MDI_MOREWINDOWSLIMIT + 1;
402 j = i - nbWindowsMenuItems + 1;
404 for( ; i >= j ; i-- )
406 memset(&mii, 0, sizeof(mii));
407 mii.cbSize = sizeof(mii);
408 mii.fMask = MIIM_CHECKMARKS | MIIM_DATA | MIIM_ID | MIIM_STATE
409 | MIIM_SUBMENU | MIIM_TYPE | MIIM_BITMAP;
411 GetMenuItemInfoW(ci->hWindowMenu, i, TRUE, &mii);
412 if(mii.cch) { /* Menu is MFT_STRING */
413 mii.cch++; /* add room for '\0' */
414 buffer = HeapAlloc(GetProcessHeap(), 0,
415 mii.cch * sizeof(WCHAR));
416 mii.dwTypeData = buffer;
417 GetMenuItemInfoW(ci->hWindowMenu, i, TRUE, &mii);
419 DeleteMenu(ci->hWindowMenu, i, MF_BYPOSITION);
420 InsertMenuItemW(hmenuWindow, pos, TRUE, &mii);
421 if(buffer) {
422 HeapFree(GetProcessHeap(), 0, buffer);
423 buffer = NULL;
428 /* remove separator */
429 DeleteMenu(ci->hWindowMenu, i, MF_BYPOSITION);
431 ci->hWindowMenu = hmenuWindow;
434 if (hmenuFrame)
436 SetMenu(hwndFrame, hmenuFrame);
437 if( hmenuFrame!=oldFrameMenu )
439 if( ci->hwndChildMaximized )
440 MDI_AugmentFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
441 return oldFrameMenu;
444 else
446 HMENU menu = GetMenu( GetParent(hwnd) );
447 INT nItems = GetMenuItemCount(menu) - 1;
448 UINT iId = GetMenuItemID(menu,nItems) ;
450 if( !(iId == SC_RESTORE || iId == SC_CLOSE) )
452 /* SetMenu() may already have been called, meaning that this window
453 * already has its menu. But they may have done a SetMenu() on
454 * an MDI window, and called MDISetMenu() after the fact, meaning
455 * that the "if" to this "else" wouldn't catch the need to
456 * augment the frame menu.
458 if( ci->hwndChildMaximized )
459 MDI_AugmentFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
462 return 0;
465 /**********************************************************************
466 * MDIRefreshMenu
468 static LRESULT MDIRefreshMenu( HWND hwnd, HMENU hmenuFrame,
469 HMENU hmenuWindow)
471 HWND hwndFrame = GetParent(hwnd);
472 HMENU oldFrameMenu = GetMenu(hwndFrame);
474 TRACE("%04x %04x %04x\n",
475 hwnd, hmenuFrame, hmenuWindow);
477 FIXME("partially function stub\n");
479 return 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 %04x\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 WIN_Handle16(parent), (HMENU)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"), MDI_IDS_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 %04x\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 - %04x\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 (%i,%i - %i, %i)\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 %04x, to %04x\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 - %04x\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("%04x\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 if( child )
777 clientInfo->hwndActiveChild = child;
778 ShowWindow( child, SW_SHOWMAXIMIZED);
780 else ShowWindow( clientInfo->hwndActiveChild, SW_SHOWNORMAL );
783 clientInfo->hwndActiveChild = child;
785 /* check if we have any children left */
786 if( !child )
788 if( isActiveFrameWnd )
789 SetFocus( client );
790 return 0;
793 /* check menu item */
794 if( clientInfo->hWindowMenu )
796 UINT id = GetWindowLongA( child, GWL_ID );
797 /* The window to be activated must be displayed in the "Windows" menu */
798 if (id >= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT)
800 MDI_SwapMenuItems( GetParent(child),
801 id, clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1);
802 id = clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1;
803 MDI_MenuModifyItem( GetParent(child), child );
806 CheckMenuItem(clientInfo->hWindowMenu, id, MF_CHECKED);
808 /* bring active child to the top */
809 SetWindowPos( child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
811 if( isActiveFrameWnd )
813 SendMessageA( child, WM_NCACTIVATE, TRUE, 0L);
814 if( GetFocus() == client )
815 SendMessageA( client, WM_SETFOCUS, (WPARAM)client, 0L );
816 else
817 SetFocus( client );
819 SendMessageA( child, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child );
820 return TRUE;
823 /* -------------------- MDI client window functions ------------------- */
825 /**********************************************************************
826 * CreateMDIMenuBitmap
828 static HBITMAP CreateMDIMenuBitmap(void)
830 HDC hDCSrc = CreateCompatibleDC(0);
831 HDC hDCDest = CreateCompatibleDC(hDCSrc);
832 HBITMAP hbClose = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_OLD_CLOSE) );
833 HBITMAP hbCopy;
834 HBITMAP hobjSrc, hobjDest;
836 hobjSrc = SelectObject(hDCSrc, hbClose);
837 hbCopy = CreateCompatibleBitmap(hDCSrc,GetSystemMetrics(SM_CXSIZE),GetSystemMetrics(SM_CYSIZE));
838 hobjDest = SelectObject(hDCDest, hbCopy);
840 BitBlt(hDCDest, 0, 0, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE),
841 hDCSrc, GetSystemMetrics(SM_CXSIZE), 0, SRCCOPY);
843 SelectObject(hDCSrc, hobjSrc);
844 DeleteObject(hbClose);
845 DeleteDC(hDCSrc);
847 hobjSrc = SelectObject( hDCDest, GetStockObject(BLACK_PEN) );
849 MoveToEx( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, 0, NULL );
850 LineTo( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, GetSystemMetrics(SM_CYSIZE) - 1);
852 SelectObject(hDCDest, hobjSrc );
853 SelectObject(hDCDest, hobjDest);
854 DeleteDC(hDCDest);
856 return hbCopy;
859 /**********************************************************************
860 * MDICascade
862 static LONG MDICascade( HWND client, MDICLIENTINFO *ci )
864 HWND *win_array;
865 BOOL has_icons = FALSE;
866 int i, total;
868 if (ci->hwndChildMaximized)
869 SendMessageA( client, WM_MDIRESTORE,
870 (WPARAM)ci->hwndChildMaximized, 0);
872 if (ci->nActiveChildren == 0) return 0;
874 if (!(win_array = WIN_ListChildren( client ))) return 0;
876 /* remove all the windows we don't want */
877 for (i = total = 0; win_array[i]; i++)
879 if (!IsWindowVisible( win_array[i] )) continue;
880 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows */
881 if (IsIconic( win_array[i] ))
883 has_icons = TRUE;
884 continue;
886 win_array[total++] = win_array[i];
888 win_array[total] = 0;
890 if (total)
892 INT delta = 0, n = 0, i;
893 POINT pos[2];
894 if (has_icons) delta = GetSystemMetrics(SM_CYICONSPACING) + GetSystemMetrics(SM_CYICON);
896 /* walk the list (backwards) and move windows */
897 for (i = total - 1; i >= 0; i--)
899 TRACE("move %04x to (%ld,%ld) size [%ld,%ld]\n",
900 win_array[i], pos[0].x, pos[0].y, pos[1].x, pos[1].y);
902 MDI_CalcDefaultChildPos(client, n++, pos, delta);
903 SetWindowPos( win_array[i], 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
904 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
907 HeapFree( GetProcessHeap(), 0, win_array );
909 if (has_icons) ArrangeIconicWindows( client );
910 return 0;
913 /**********************************************************************
914 * MDITile
916 static void MDITile( HWND client, MDICLIENTINFO *ci, WPARAM wParam )
918 HWND *win_array;
919 int i, total;
920 BOOL has_icons = FALSE;
922 if (ci->hwndChildMaximized)
923 SendMessageA( client, WM_MDIRESTORE, (WPARAM)ci->hwndChildMaximized, 0);
925 if (ci->nActiveChildren == 0) return;
927 if (!(win_array = WIN_ListChildren( client ))) return;
929 /* remove all the windows we don't want */
930 for (i = total = 0; win_array[i]; i++)
932 if (!IsWindowVisible( win_array[i] )) continue;
933 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows (icon titles) */
934 if (IsIconic( win_array[i] ))
936 has_icons = TRUE;
937 continue;
939 if ((wParam & MDITILE_SKIPDISABLED) && !IsWindowEnabled( win_array[i] )) continue;
940 win_array[total++] = win_array[i];
942 win_array[total] = 0;
944 TRACE("%u windows to tile\n", total);
946 if (total)
948 HWND *pWnd = win_array;
949 RECT rect;
950 int x, y, xsize, ysize;
951 int rows, columns, r, c, i;
953 GetClientRect(client,&rect);
954 rows = (int) sqrt((double)total);
955 columns = total / rows;
957 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
959 i = rows;
960 rows = columns; /* exchange r and c */
961 columns = i;
964 if (has_icons)
966 y = rect.bottom - 2 * GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
967 rect.bottom = ( y - GetSystemMetrics(SM_CYICON) < rect.top )? rect.bottom: y;
970 ysize = rect.bottom / rows;
971 xsize = rect.right / columns;
973 for (x = i = 0, c = 1; c <= columns && *pWnd; c++)
975 if (c == columns)
977 rows = total - i;
978 ysize = rect.bottom / rows;
981 y = 0;
982 for (r = 1; r <= rows && *pWnd; r++, i++)
984 SetWindowPos(*pWnd, 0, x, y, xsize, ysize,
985 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
986 y += ysize;
987 pWnd++;
989 x += xsize;
992 HeapFree( GetProcessHeap(), 0, win_array );
993 if (has_icons) ArrangeIconicWindows( client );
996 /* ----------------------- Frame window ---------------------------- */
999 /**********************************************************************
1000 * MDI_AugmentFrameMenu
1002 static BOOL MDI_AugmentFrameMenu( HWND frame, HWND hChild )
1004 HMENU menu = GetMenu( frame );
1005 WND* child = WIN_FindWndPtr(hChild);
1006 HMENU hSysPopup = 0;
1007 HBITMAP hSysMenuBitmap = 0;
1009 TRACE("frame %04x,child %04x\n",frame,hChild);
1011 if( !menu || !child->hSysMenu )
1013 WIN_ReleaseWndPtr(child);
1014 return 0;
1016 WIN_ReleaseWndPtr(child);
1018 /* create a copy of sysmenu popup and insert it into frame menu bar */
1020 if (!(hSysPopup = LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU")))
1021 return 0;
1023 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1024 SC_MINIMIZE, (LPSTR)(DWORD)HBMMENU_MBAR_MINIMIZE ) ;
1025 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1026 SC_RESTORE, (LPSTR)(DWORD)HBMMENU_MBAR_RESTORE );
1028 /* In Win 95 look, the system menu is replaced by the child icon */
1030 if(TWEAK_WineLook > WIN31_LOOK)
1032 HICON hIcon = GetClassLongA(hChild, GCL_HICONSM);
1033 if (!hIcon)
1034 hIcon = GetClassLongA(hChild, GCL_HICON);
1035 if (hIcon)
1037 HDC hMemDC;
1038 HBITMAP hBitmap, hOldBitmap;
1039 HBRUSH hBrush;
1040 HDC hdc = GetDC(hChild);
1042 if (hdc)
1044 int cx, cy;
1045 cx = GetSystemMetrics(SM_CXSMICON);
1046 cy = GetSystemMetrics(SM_CYSMICON);
1047 hMemDC = CreateCompatibleDC(hdc);
1048 hBitmap = CreateCompatibleBitmap(hdc, cx, cy);
1049 hOldBitmap = SelectObject(hMemDC, hBitmap);
1050 SetMapMode(hMemDC, MM_TEXT);
1051 hBrush = CreateSolidBrush(GetSysColor(COLOR_MENU));
1052 DrawIconEx(hMemDC, 0, 0, hIcon, cx, cy, 0, hBrush, DI_NORMAL);
1053 SelectObject (hMemDC, hOldBitmap);
1054 DeleteObject(hBrush);
1055 DeleteDC(hMemDC);
1056 ReleaseDC(hChild, hdc);
1057 hSysMenuBitmap = hBitmap;
1061 else
1062 hSysMenuBitmap = hBmpClose;
1064 if( !InsertMenuA(menu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
1065 hSysPopup, (LPSTR)(DWORD)hSysMenuBitmap))
1067 TRACE("not inserted\n");
1068 DestroyMenu(hSysPopup);
1069 return 0;
1072 /* The close button is only present in Win 95 look */
1073 if(TWEAK_WineLook > WIN31_LOOK)
1075 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1076 SC_CLOSE, (LPSTR)(DWORD)HBMMENU_MBAR_CLOSE );
1079 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
1080 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
1081 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
1082 SetMenuDefaultItem(hSysPopup, SC_CLOSE, FALSE);
1084 /* redraw menu */
1085 DrawMenuBar(frame);
1087 return 1;
1090 /**********************************************************************
1091 * MDI_RestoreFrameMenu
1093 static BOOL MDI_RestoreFrameMenu( HWND frame, HWND hChild )
1095 MENUITEMINFOW menuInfo;
1096 HMENU menu = GetMenu( frame );
1097 INT nItems = GetMenuItemCount(menu) - 1;
1098 UINT iId = GetMenuItemID(menu,nItems) ;
1100 TRACE("frame %04x,child %04x,nIt=%d,iId=%d\n",frame,hChild,nItems,iId);
1102 if(!(iId == SC_RESTORE || iId == SC_CLOSE) )
1103 return 0;
1106 * Remove the system menu, If that menu is the icon of the window
1107 * as it is in win95, we have to delete the bitmap.
1109 memset(&menuInfo, 0, sizeof(menuInfo));
1110 menuInfo.cbSize = sizeof(menuInfo);
1111 menuInfo.fMask = MIIM_DATA | MIIM_TYPE;
1113 GetMenuItemInfoW(menu,
1115 TRUE,
1116 &menuInfo);
1118 RemoveMenu(menu,0,MF_BYPOSITION);
1120 if ( (menuInfo.fType & MFT_BITMAP) &&
1121 (LOWORD(menuInfo.dwTypeData)!=0) &&
1122 (LOWORD(menuInfo.dwTypeData)!=hBmpClose) )
1124 DeleteObject((HBITMAP)LOWORD(menuInfo.dwTypeData));
1127 if(TWEAK_WineLook > WIN31_LOOK)
1129 /* close */
1130 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1132 /* restore */
1133 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1134 /* minimize */
1135 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1137 DrawMenuBar(frame);
1139 return 1;
1143 /**********************************************************************
1144 * MDI_UpdateFrameText
1146 * used when child window is maximized/restored
1148 * Note: lpTitle can be NULL
1150 static void MDI_UpdateFrameText( HWND frame, HWND hClient,
1151 BOOL repaint, LPCWSTR lpTitle )
1153 WCHAR lpBuffer[MDI_MAXTITLELENGTH+1];
1154 MDICLIENTINFO *ci = get_client_info( hClient );
1156 TRACE("repaint %i, frameText %s\n", repaint, debugstr_w(lpTitle));
1158 if (!ci) return;
1160 if (!lpTitle && !ci->frameTitle) /* first time around, get title from the frame window */
1162 GetWindowTextW( frame, lpBuffer, sizeof(lpBuffer)/sizeof(WCHAR) );
1163 lpTitle = lpBuffer;
1166 /* store new "default" title if lpTitle is not NULL */
1167 if (lpTitle)
1169 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1170 if ((ci->frameTitle = HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle)+1)*sizeof(WCHAR))))
1171 strcpyW( ci->frameTitle, lpTitle );
1174 if (ci->frameTitle)
1176 if (ci->hwndChildMaximized)
1178 /* combine frame title and child title if possible */
1180 static const WCHAR lpBracket[] = {' ','-',' ','[',0};
1181 static const WCHAR lpBracket2[] = {']',0};
1182 int i_frame_text_length = strlenW(ci->frameTitle);
1184 lstrcpynW( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
1186 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
1188 strcatW( lpBuffer, lpBracket );
1189 if (GetWindowTextW( ci->hwndChildMaximized, lpBuffer + i_frame_text_length + 4,
1190 MDI_MAXTITLELENGTH - i_frame_text_length - 5 ))
1191 strcatW( lpBuffer, lpBracket2 );
1192 else
1193 lpBuffer[i_frame_text_length] = 0; /* remove bracket */
1196 else
1198 lstrcpynW(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH+1 );
1201 else
1202 lpBuffer[0] = '\0';
1204 DefWindowProcW( frame, WM_SETTEXT, 0, (LPARAM)lpBuffer );
1205 if( repaint == MDI_REPAINTFRAME)
1206 SetWindowPos( frame, 0,0,0,0,0, SWP_FRAMECHANGED |
1207 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
1211 /* ----------------------------- Interface ---------------------------- */
1214 /**********************************************************************
1215 * MDIClientWndProc_common
1217 static LRESULT MDIClientWndProc_common( HWND hwnd, UINT message,
1218 WPARAM wParam, LPARAM lParam, BOOL unicode )
1220 MDICLIENTINFO *ci;
1222 if (!(ci = get_client_info( hwnd ))) return 0;
1224 switch (message)
1226 case WM_CREATE:
1228 RECT rect;
1229 /* Since we are using only cs->lpCreateParams, we can safely
1230 * cast to LPCREATESTRUCTA here */
1231 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
1232 WND *wndPtr = WIN_GetPtr( hwnd );
1234 /* Translation layer doesn't know what's in the cs->lpCreateParams
1235 * so we have to keep track of what environment we're in. */
1237 if( wndPtr->flags & WIN_ISWIN32 )
1239 #define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1240 ci->hWindowMenu = ccs->hWindowMenu;
1241 ci->idFirstChild = ccs->idFirstChild;
1242 #undef ccs
1244 else
1246 LPCLIENTCREATESTRUCT16 ccs = MapSL((SEGPTR)cs->lpCreateParams);
1247 ci->hWindowMenu = ccs->hWindowMenu;
1248 ci->idFirstChild = ccs->idFirstChild;
1250 WIN_ReleasePtr( wndPtr );
1252 ci->hwndChildMaximized = 0;
1253 ci->nActiveChildren = 0;
1254 ci->nTotalCreated = 0;
1255 ci->frameTitle = NULL;
1256 ci->mdiFlags = 0;
1257 SetWindowLongW( hwnd, GWL_STYLE, GetWindowLongW(hwnd,GWL_STYLE) | WS_CLIPCHILDREN );
1259 if (!hBmpClose) hBmpClose = CreateMDIMenuBitmap();
1261 if (ci->hWindowMenu != 0)
1262 AppendMenuW( ci->hWindowMenu, MF_SEPARATOR, 0, NULL );
1264 GetClientRect( GetParent(hwnd), &rect);
1265 MoveWindow( hwnd, 0, 0, rect.right, rect.bottom, FALSE );
1267 MDI_UpdateFrameText( GetParent(hwnd), hwnd, MDI_NOFRAMEREPAINT, NULL);
1269 TRACE("Client created - hwnd = %04x, idFirst = %u\n",
1270 hwnd, ci->idFirstChild );
1271 return 0;
1274 case WM_DESTROY:
1276 INT nItems;
1277 if( ci->hwndChildMaximized )
1278 MDI_RestoreFrameMenu( GetParent(hwnd), ci->hwndChildMaximized);
1279 if((ci->hWindowMenu != 0) &&
1280 (nItems = GetMenuItemCount(ci->hWindowMenu)) > 0)
1282 ci->idFirstChild = nItems - 1;
1283 ci->nActiveChildren++; /* to delete a separator */
1284 while( ci->nActiveChildren-- )
1285 DeleteMenu(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
1287 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1288 return 0;
1291 case WM_MDIACTIVATE:
1292 if( ci->hwndActiveChild != (HWND)wParam )
1293 SetWindowPos((HWND)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
1294 return 0;
1296 case WM_MDICASCADE:
1297 return MDICascade(hwnd, ci);
1299 case WM_MDICREATE:
1300 if (lParam)
1301 return (LRESULT)MDICreateChild( hwnd, ci, (MDICREATESTRUCTA *)lParam, unicode );
1302 return 0;
1304 case WM_MDIDESTROY:
1305 return MDIDestroyChild( hwnd, ci, WIN_GetFullHandle( (HWND)wParam ), TRUE );
1307 case WM_MDIGETACTIVE:
1308 if (lParam) *(BOOL *)lParam = (ci->hwndChildMaximized != 0);
1309 return (LRESULT)ci->hwndActiveChild;
1311 case WM_MDIICONARRANGE:
1312 ci->mdiFlags |= MDIF_NEEDUPDATE;
1313 ArrangeIconicWindows( hwnd );
1314 ci->sbRecalc = SB_BOTH+1;
1315 SendMessageW( hwnd, WM_MDICALCCHILDSCROLL, 0, 0 );
1316 return 0;
1318 case WM_MDIMAXIMIZE:
1319 ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1320 return 0;
1322 case WM_MDINEXT: /* lParam != 0 means previous window */
1323 MDI_SwitchActiveChild( hwnd, WIN_GetFullHandle( (HWND)wParam ), !lParam );
1324 break;
1326 case WM_MDIRESTORE:
1327 SendMessageW( (HWND)wParam, WM_SYSCOMMAND, SC_RESTORE, 0);
1328 return 0;
1330 case WM_MDISETMENU:
1331 return MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1333 case WM_MDIREFRESHMENU:
1334 return MDIRefreshMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1336 case WM_MDITILE:
1337 ci->mdiFlags |= MDIF_NEEDUPDATE;
1338 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1339 MDITile( hwnd, ci, wParam );
1340 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1341 return 0;
1343 case WM_VSCROLL:
1344 case WM_HSCROLL:
1345 ci->mdiFlags |= MDIF_NEEDUPDATE;
1346 ScrollChildren( hwnd, message, wParam, lParam );
1347 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1348 return 0;
1350 case WM_SETFOCUS:
1351 if (ci->hwndActiveChild && !IsIconic( ci->hwndActiveChild ))
1352 SetFocus( ci->hwndActiveChild );
1353 return 0;
1355 case WM_NCACTIVATE:
1356 if( ci->hwndActiveChild )
1357 SendMessageW(ci->hwndActiveChild, message, wParam, lParam);
1358 break;
1360 case WM_PARENTNOTIFY:
1361 if (LOWORD(wParam) == WM_LBUTTONDOWN)
1363 HWND child;
1364 POINT pt;
1365 pt.x = SLOWORD(lParam);
1366 pt.y = SHIWORD(lParam);
1367 child = ChildWindowFromPoint(hwnd, pt);
1369 TRACE("notification from %04x (%li,%li)\n",child,pt.x,pt.y);
1371 if( child && child != hwnd && child != ci->hwndActiveChild )
1372 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1374 return 0;
1376 case WM_SIZE:
1377 if( IsWindow(ci->hwndChildMaximized) )
1379 RECT rect;
1381 rect.left = 0;
1382 rect.top = 0;
1383 rect.right = LOWORD(lParam);
1384 rect.bottom = HIWORD(lParam);
1386 AdjustWindowRectEx(&rect, GetWindowLongA(ci->hwndChildMaximized,GWL_STYLE),
1387 0, GetWindowLongA(ci->hwndChildMaximized,GWL_EXSTYLE) );
1388 MoveWindow(ci->hwndChildMaximized, rect.left, rect.top,
1389 rect.right - rect.left, rect.bottom - rect.top, 1);
1391 else
1392 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1394 break;
1396 case WM_MDICALCCHILDSCROLL:
1397 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1399 CalcChildScroll(hwnd, ci->sbRecalc-1);
1400 ci->sbRecalc = 0;
1401 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1403 return 0;
1405 return unicode ? DefWindowProcW( hwnd, message, wParam, lParam ) :
1406 DefWindowProcA( hwnd, message, wParam, lParam );
1409 /***********************************************************************
1410 * MDIClientWndProcA
1412 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1414 if (!IsWindow(hwnd)) return 0;
1415 return MDIClientWndProc_common( hwnd, message, wParam, lParam, FALSE );
1418 /***********************************************************************
1419 * MDIClientWndProcW
1421 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1423 if (!IsWindow(hwnd)) return 0;
1424 return MDIClientWndProc_common( hwnd, message, wParam, lParam, TRUE );
1427 /***********************************************************************
1428 * DefFrameProc (USER.445)
1430 LRESULT WINAPI DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient,
1431 UINT16 message, WPARAM16 wParam, LPARAM lParam )
1433 switch (message)
1435 case WM_SETTEXT:
1436 lParam = (LPARAM)MapSL(lParam);
1437 /* fall through */
1438 case WM_COMMAND:
1439 case WM_NCACTIVATE:
1440 case WM_SETFOCUS:
1441 case WM_SIZE:
1442 return DefFrameProcA( WIN_Handle32(hwnd), WIN_Handle32(hwndMDIClient),
1443 message, wParam, lParam );
1445 case WM_NEXTMENU:
1447 MDINEXTMENU next_menu;
1448 DefFrameProcW( WIN_Handle32(hwnd), WIN_Handle32(hwndMDIClient),
1449 message, wParam, (LPARAM)&next_menu );
1450 return MAKELONG( next_menu.hmenuNext, WIN_Handle16(next_menu.hwndNext) );
1452 default:
1453 return DefWindowProc16(hwnd, message, wParam, lParam);
1458 /***********************************************************************
1459 * DefFrameProcA (USER32.@)
1461 LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1462 UINT message, WPARAM wParam, LPARAM lParam)
1464 if (hwndMDIClient)
1466 switch (message)
1468 case WM_SETTEXT:
1470 DWORD len = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0 );
1471 LPWSTR text = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1472 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, text, len );
1473 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, text );
1474 HeapFree( GetProcessHeap(), 0, text );
1476 return 1; /* success. FIXME: check text length */
1478 case WM_COMMAND:
1479 case WM_NCACTIVATE:
1480 case WM_NEXTMENU:
1481 case WM_SETFOCUS:
1482 case WM_SIZE:
1483 return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1486 return DefWindowProcA(hwnd, message, wParam, lParam);
1490 /***********************************************************************
1491 * DefFrameProcW (USER32.@)
1493 LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1494 UINT message, WPARAM wParam, LPARAM lParam)
1496 MDICLIENTINFO *ci = get_client_info( hwndMDIClient );
1498 if (ci)
1500 switch (message)
1502 case WM_COMMAND:
1504 WORD id = LOWORD(wParam);
1505 /* check for possible syscommands for maximized MDI child */
1506 if (id < ci->idFirstChild || id >= ci->idFirstChild + ci->nActiveChildren)
1508 if( (id - 0xf000) & 0xf00f ) break;
1509 if( !ci->hwndChildMaximized ) break;
1510 switch( id )
1512 case SC_SIZE:
1513 case SC_MOVE:
1514 case SC_MINIMIZE:
1515 case SC_MAXIMIZE:
1516 case SC_NEXTWINDOW:
1517 case SC_PREVWINDOW:
1518 case SC_CLOSE:
1519 case SC_RESTORE:
1520 return SendMessageW( ci->hwndChildMaximized, WM_SYSCOMMAND,
1521 wParam, lParam);
1524 else
1526 HWND childHwnd;
1527 if (id - ci->idFirstChild == MDI_MOREWINDOWSLIMIT)
1528 /* User chose "More Windows..." */
1529 childHwnd = MDI_MoreWindowsDialog(hwndMDIClient);
1530 else
1531 /* User chose one of the windows listed in the "Windows" menu */
1532 childHwnd = MDI_GetChildByID(hwndMDIClient,id);
1534 if( childHwnd )
1535 SendMessageW( hwndMDIClient, WM_MDIACTIVATE, (WPARAM)childHwnd, 0 );
1538 break;
1540 case WM_NCACTIVATE:
1541 SendMessageW(hwndMDIClient, message, wParam, lParam);
1542 break;
1544 case WM_SETTEXT:
1545 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, (LPWSTR)lParam );
1546 return 1; /* success. FIXME: check text length */
1548 case WM_SETFOCUS:
1549 SetFocus(hwndMDIClient);
1550 break;
1552 case WM_SIZE:
1553 MoveWindow(hwndMDIClient, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
1554 break;
1556 case WM_NEXTMENU:
1558 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1560 if (!IsIconic(hwnd) && ci->hwndActiveChild && !ci->hwndChildMaximized)
1562 /* control menu is between the frame system menu and
1563 * the first entry of menu bar */
1564 WND *wndPtr = WIN_GetPtr(hwnd);
1566 if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1567 (wParam == VK_RIGHT && GetSubMenu(wndPtr->hSysMenu, 0) == next_menu->hmenuIn) )
1569 WIN_ReleasePtr(wndPtr);
1570 wndPtr = WIN_GetPtr(ci->hwndActiveChild);
1571 next_menu->hmenuNext = GetSubMenu(wndPtr->hSysMenu, 0);
1572 next_menu->hwndNext = ci->hwndActiveChild;
1574 WIN_ReleasePtr(wndPtr);
1576 return 0;
1581 return DefWindowProcW( hwnd, message, wParam, lParam );
1585 /***********************************************************************
1586 * DefMDIChildProc (USER.447)
1588 LRESULT WINAPI DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1589 WPARAM16 wParam, LPARAM lParam )
1591 switch (message)
1593 case WM_SETTEXT:
1594 return DefMDIChildProcA( WIN_Handle32(hwnd), message, wParam, (LPARAM)MapSL(lParam) );
1595 case WM_MENUCHAR:
1596 case WM_CLOSE:
1597 case WM_SETFOCUS:
1598 case WM_CHILDACTIVATE:
1599 case WM_SYSCOMMAND:
1600 case WM_SETVISIBLE:
1601 case WM_SIZE:
1602 case WM_SYSCHAR:
1603 return DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, lParam );
1604 case WM_GETMINMAXINFO:
1606 MINMAXINFO16 *mmi16 = (MINMAXINFO16 *)MapSL(lParam);
1607 MINMAXINFO mmi;
1608 STRUCT32_MINMAXINFO16to32( mmi16, &mmi );
1609 DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, (LPARAM)&mmi );
1610 STRUCT32_MINMAXINFO32to16( &mmi, mmi16 );
1611 return 0;
1613 case WM_NEXTMENU:
1615 MDINEXTMENU next_menu;
1616 DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, (LPARAM)&next_menu );
1617 return MAKELONG( next_menu.hmenuNext, WIN_Handle16(next_menu.hwndNext) );
1619 default:
1620 return DefWindowProc16(hwnd, message, wParam, lParam);
1625 /***********************************************************************
1626 * DefMDIChildProcA (USER32.@)
1628 LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1629 WPARAM wParam, LPARAM lParam )
1631 HWND client = GetParent(hwnd);
1632 MDICLIENTINFO *ci = get_client_info( client );
1634 hwnd = WIN_GetFullHandle( hwnd );
1635 if (!ci) return DefWindowProcA( hwnd, message, wParam, lParam );
1637 switch (message)
1639 case WM_SETTEXT:
1640 DefWindowProcA(hwnd, message, wParam, lParam);
1641 MDI_MenuModifyItem( client, hwnd );
1642 if( ci->hwndChildMaximized == hwnd )
1643 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1644 return 1; /* success. FIXME: check text length */
1646 case WM_GETMINMAXINFO:
1647 case WM_MENUCHAR:
1648 case WM_CLOSE:
1649 case WM_SETFOCUS:
1650 case WM_CHILDACTIVATE:
1651 case WM_SYSCOMMAND:
1652 case WM_SETVISIBLE:
1653 case WM_SIZE:
1654 case WM_NEXTMENU:
1655 case WM_SYSCHAR:
1656 return DefMDIChildProcW( hwnd, message, wParam, lParam );
1658 return DefWindowProcA(hwnd, message, wParam, lParam);
1662 /***********************************************************************
1663 * DefMDIChildProcW (USER32.@)
1665 LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1666 WPARAM wParam, LPARAM lParam )
1668 HWND client = GetParent(hwnd);
1669 MDICLIENTINFO *ci = get_client_info( client );
1671 hwnd = WIN_GetFullHandle( hwnd );
1672 if (!ci) return DefWindowProcW( hwnd, message, wParam, lParam );
1674 switch (message)
1676 case WM_SETTEXT:
1677 DefWindowProcW(hwnd, message, wParam, lParam);
1678 MDI_MenuModifyItem( client, hwnd );
1679 if( ci->hwndChildMaximized == hwnd )
1680 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1681 return 1; /* success. FIXME: check text length */
1683 case WM_GETMINMAXINFO:
1684 MDI_ChildGetMinMaxInfo( client, hwnd, (MINMAXINFO *)lParam );
1685 return 0;
1687 case WM_MENUCHAR:
1688 return 0x00010000; /* MDI children don't have menu bars */
1690 case WM_CLOSE:
1691 SendMessageW( client, WM_MDIDESTROY, (WPARAM)hwnd, 0 );
1692 return 0;
1694 case WM_SETFOCUS:
1695 if (ci->hwndActiveChild != hwnd) MDI_ChildActivate( client, hwnd );
1696 break;
1698 case WM_CHILDACTIVATE:
1699 MDI_ChildActivate( client, hwnd );
1700 return 0;
1702 case WM_SYSCOMMAND:
1703 switch( wParam )
1705 case SC_MOVE:
1706 if( ci->hwndChildMaximized == hwnd) return 0;
1707 break;
1708 case SC_RESTORE:
1709 case SC_MINIMIZE:
1710 SetWindowLongA( hwnd, GWL_STYLE,
1711 GetWindowLongA( hwnd, GWL_STYLE ) | WS_SYSMENU );
1712 break;
1713 case SC_MAXIMIZE:
1714 if (ci->hwndChildMaximized == hwnd)
1715 return SendMessageW( GetParent(client), message, wParam, lParam);
1716 SetWindowLongW( hwnd, GWL_STYLE,
1717 GetWindowLongW( hwnd, GWL_STYLE ) & ~WS_SYSMENU );
1718 break;
1719 case SC_NEXTWINDOW:
1720 SendMessageW( client, WM_MDINEXT, 0, 0);
1721 return 0;
1722 case SC_PREVWINDOW:
1723 SendMessageW( client, WM_MDINEXT, 0, 1);
1724 return 0;
1726 break;
1728 case WM_SETVISIBLE:
1729 if( ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1730 else MDI_PostUpdate(client, ci, SB_BOTH+1);
1731 break;
1733 case WM_SIZE:
1734 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1736 ci->hwndChildMaximized = 0;
1737 MDI_RestoreFrameMenu( GetParent(client), hwnd );
1738 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1741 if( wParam == SIZE_MAXIMIZED )
1743 HWND hMaxChild = ci->hwndChildMaximized;
1745 if( hMaxChild == hwnd ) break;
1746 if( hMaxChild)
1748 SendMessageW( hMaxChild, WM_SETREDRAW, FALSE, 0 );
1749 MDI_RestoreFrameMenu( GetParent(client), hMaxChild );
1750 ShowWindow( hMaxChild, SW_SHOWNOACTIVATE );
1751 SendMessageW( hMaxChild, WM_SETREDRAW, TRUE, 0 );
1753 TRACE("maximizing child %04x\n", hwnd );
1755 /* keep track of the maximized window. */
1756 ci->hwndChildMaximized = hwnd; /* !!! */
1758 /* The maximized window should also be the active window */
1759 MDI_ChildActivate( client, hwnd );
1760 MDI_AugmentFrameMenu( GetParent(client), hwnd );
1761 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1764 if( wParam == SIZE_MINIMIZED )
1766 HWND switchTo = MDI_GetWindow(ci, hwnd, TRUE, WS_MINIMIZE);
1768 if (switchTo) SendMessageW( switchTo, WM_CHILDACTIVATE, 0, 0);
1770 MDI_PostUpdate(client, ci, SB_BOTH+1);
1771 break;
1773 case WM_NEXTMENU:
1775 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1776 HWND parent = GetParent(client);
1778 if( wParam == VK_LEFT ) /* switch to frame system menu */
1780 WND *wndPtr = WIN_GetPtr( parent );
1781 next_menu->hmenuNext = GetSubMenu( wndPtr->hSysMenu, 0 );
1782 WIN_ReleasePtr( wndPtr );
1784 if( wParam == VK_RIGHT ) /* to frame menu bar */
1786 next_menu->hmenuNext = GetMenu(parent);
1788 next_menu->hwndNext = parent;
1789 return 0;
1792 case WM_SYSCHAR:
1793 if (wParam == '-')
1795 SendMessageW( hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (DWORD)VK_SPACE);
1796 return 0;
1798 break;
1800 return DefWindowProcW(hwnd, message, wParam, lParam);
1803 /**********************************************************************
1804 * CreateMDIWindowA (USER32.@) Creates a MDI child
1806 * RETURNS
1807 * Success: Handle to created window
1808 * Failure: NULL
1810 HWND WINAPI CreateMDIWindowA(
1811 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1812 LPCSTR lpWindowName, /* [in] Pointer to window name */
1813 DWORD dwStyle, /* [in] Window style */
1814 INT X, /* [in] Horizontal position of window */
1815 INT Y, /* [in] Vertical position of window */
1816 INT nWidth, /* [in] Width of window */
1817 INT nHeight, /* [in] Height of window */
1818 HWND hWndParent, /* [in] Handle to parent window */
1819 HINSTANCE hInstance, /* [in] Handle to application instance */
1820 LPARAM lParam) /* [in] Application-defined value */
1822 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1823 MDICREATESTRUCTA cs;
1825 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
1826 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1827 nWidth,nHeight,hWndParent,hInstance,lParam);
1829 if (!pCi)
1831 ERR("bad hwnd for MDI-client: %04x\n", hWndParent);
1832 return 0;
1834 cs.szClass=lpClassName;
1835 cs.szTitle=lpWindowName;
1836 cs.hOwner=hInstance;
1837 cs.x=X;
1838 cs.y=Y;
1839 cs.cx=nWidth;
1840 cs.cy=nHeight;
1841 cs.style=dwStyle;
1842 cs.lParam=lParam;
1844 return MDICreateChild(hWndParent, pCi, &cs, FALSE);
1847 /***********************************************************************
1848 * CreateMDIWindowW (USER32.@) Creates a MDI child
1850 * RETURNS
1851 * Success: Handle to created window
1852 * Failure: NULL
1854 HWND WINAPI CreateMDIWindowW(
1855 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1856 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1857 DWORD dwStyle, /* [in] Window style */
1858 INT X, /* [in] Horizontal position of window */
1859 INT Y, /* [in] Vertical position of window */
1860 INT nWidth, /* [in] Width of window */
1861 INT nHeight, /* [in] Height of window */
1862 HWND hWndParent, /* [in] Handle to parent window */
1863 HINSTANCE hInstance, /* [in] Handle to application instance */
1864 LPARAM lParam) /* [in] Application-defined value */
1866 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1867 MDICREATESTRUCTW cs;
1869 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
1870 debugstr_w(lpClassName), debugstr_w(lpWindowName), dwStyle, X, Y,
1871 nWidth, nHeight, hWndParent, hInstance, lParam);
1873 if (!pCi)
1875 ERR("bad hwnd for MDI-client: %04x\n", hWndParent);
1876 return 0;
1878 cs.szClass = lpClassName;
1879 cs.szTitle = lpWindowName;
1880 cs.hOwner = hInstance;
1881 cs.x = X;
1882 cs.y = Y;
1883 cs.cx = nWidth;
1884 cs.cy = nHeight;
1885 cs.style = dwStyle;
1886 cs.lParam = lParam;
1888 return MDICreateChild(hWndParent, pCi, (MDICREATESTRUCTA *)&cs, TRUE);
1891 /**********************************************************************
1892 * TranslateMDISysAccel (USER32.@)
1894 BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1896 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1898 MDICLIENTINFO *ci = get_client_info( hwndClient );
1899 WPARAM wParam = 0;
1901 if (!ci || !IsWindowEnabled(ci->hwndActiveChild)) return 0;
1903 /* translate if the Ctrl key is down and Alt not. */
1905 if( (GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
1907 switch( msg->wParam )
1909 case VK_F6:
1910 case VK_TAB:
1911 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 ) ? SC_NEXTWINDOW : SC_PREVWINDOW;
1912 break;
1913 case VK_F4:
1914 case VK_RBUTTON:
1915 wParam = SC_CLOSE;
1916 break;
1917 default:
1918 return 0;
1920 TRACE("wParam = %04x\n", wParam);
1921 SendMessageW(ci->hwndActiveChild, WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
1922 return 1;
1925 return 0; /* failure */
1928 /***********************************************************************
1929 * CalcChildScroll (USER32.@)
1931 void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
1933 SCROLLINFO info;
1934 RECT childRect, clientRect;
1935 INT vmin, vmax, hmin, hmax, vpos, hpos;
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 hmin = childRect.left;
1965 hmax = childRect.right - clientRect.right;
1966 hpos = clientRect.left - childRect.left;
1967 vmin = childRect.top;
1968 vmax = childRect.bottom - clientRect.bottom;
1969 vpos = clientRect.top - childRect.top;
1971 switch( scroll )
1973 case SB_HORZ:
1974 vpos = hpos; vmin = hmin; vmax = hmax;
1975 case SB_VERT:
1976 info.cbSize = sizeof(info);
1977 info.nMax = vmax; info.nMin = vmin; info.nPos = vpos;
1978 info.fMask = SIF_POS | SIF_RANGE;
1979 SetScrollInfo(hwnd, scroll, &info, TRUE);
1980 break;
1981 case SB_BOTH:
1982 SCROLL_SetNCSbState( hwnd, vmin, vmax, vpos,
1983 hmin, hmax, hpos);
1988 /***********************************************************************
1989 * ScrollChildren (USER32.@)
1991 void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
1992 LPARAM lParam)
1994 INT newPos = -1;
1995 INT curPos, length, minPos, maxPos, shift;
1996 RECT rect;
1998 GetClientRect( hWnd, &rect );
2000 switch(uMsg)
2002 case WM_HSCROLL:
2003 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
2004 curPos = GetScrollPos(hWnd,SB_HORZ);
2005 length = (rect.right - rect.left) / 2;
2006 shift = GetSystemMetrics(SM_CYHSCROLL);
2007 break;
2008 case WM_VSCROLL:
2009 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
2010 curPos = GetScrollPos(hWnd,SB_VERT);
2011 length = (rect.bottom - rect.top) / 2;
2012 shift = GetSystemMetrics(SM_CXVSCROLL);
2013 break;
2014 default:
2015 return;
2018 switch( wParam )
2020 case SB_LINEUP:
2021 newPos = curPos - shift;
2022 break;
2023 case SB_LINEDOWN:
2024 newPos = curPos + shift;
2025 break;
2026 case SB_PAGEUP:
2027 newPos = curPos - length;
2028 break;
2029 case SB_PAGEDOWN:
2030 newPos = curPos + length;
2031 break;
2033 case SB_THUMBPOSITION:
2034 newPos = LOWORD(lParam);
2035 break;
2037 case SB_THUMBTRACK:
2038 return;
2040 case SB_TOP:
2041 newPos = minPos;
2042 break;
2043 case SB_BOTTOM:
2044 newPos = maxPos;
2045 break;
2046 case SB_ENDSCROLL:
2047 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
2048 return;
2051 if( newPos > maxPos )
2052 newPos = maxPos;
2053 else
2054 if( newPos < minPos )
2055 newPos = minPos;
2057 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
2059 if( uMsg == WM_VSCROLL )
2060 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
2061 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2062 else
2063 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
2064 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2068 /******************************************************************************
2069 * CascadeWindows (USER32.@) Cascades MDI child windows
2071 * RETURNS
2072 * Success: Number of cascaded windows.
2073 * Failure: 0
2075 WORD WINAPI
2076 CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2077 UINT cKids, const HWND *lpKids)
2079 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2080 hwndParent, wFlags, cKids);
2082 return 0;
2086 /******************************************************************************
2087 * TileWindows (USER32.@) Tiles MDI child windows
2089 * RETURNS
2090 * Success: Number of tiled windows.
2091 * Failure: 0
2093 WORD WINAPI
2094 TileWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2095 UINT cKids, const HWND *lpKids)
2097 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2098 hwndParent, wFlags, cKids);
2100 return 0;
2103 /************************************************************************
2104 * "More Windows..." functionality
2107 /* MDI_MoreWindowsDlgProc
2109 * This function will process the messages sent to the "More Windows..."
2110 * dialog.
2111 * Return values: 0 = cancel pressed
2112 * HWND = ok pressed or double-click in the list...
2116 static BOOL WINAPI MDI_MoreWindowsDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
2118 switch (iMsg)
2120 case WM_INITDIALOG:
2122 UINT widest = 0;
2123 UINT length;
2124 UINT i;
2125 MDICLIENTINFO *ci = get_client_info( (HWND)lParam );
2126 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2127 HWND *list, *sorted_list;
2129 if (!(list = WIN_ListChildren( (HWND)lParam ))) return TRUE;
2130 if (!(sorted_list = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
2131 sizeof(HWND) * ci->nActiveChildren )))
2133 HeapFree( GetProcessHeap(), 0, list );
2134 return FALSE;
2137 /* Fill the list, sorted by id... */
2138 for (i = 0; list[i]; i++)
2140 UINT id = GetWindowLongW( list[i], GWL_ID ) - ci->idFirstChild;
2141 if (id < ci->nActiveChildren) sorted_list[id] = list[i];
2143 HeapFree( GetProcessHeap(), 0, list );
2145 for (i = 0; i < ci->nActiveChildren; i++)
2147 WCHAR buffer[128];
2149 if (!GetWindowTextW( sorted_list[i], buffer, sizeof(buffer)/sizeof(WCHAR) ))
2150 continue;
2151 SendMessageW(hListBox, LB_ADDSTRING, 0, (LPARAM)buffer );
2152 SendMessageW(hListBox, LB_SETITEMDATA, i, (LPARAM)sorted_list[i] );
2153 length = strlenW(buffer); /* FIXME: should use GetTextExtentPoint */
2154 if (length > widest)
2155 widest = length;
2157 /* Make sure the horizontal scrollbar scrolls ok */
2158 SendMessageW(hListBox, LB_SETHORIZONTALEXTENT, widest * 6, 0);
2160 /* Set the current selection */
2161 SendMessageW(hListBox, LB_SETCURSEL, MDI_MOREWINDOWSLIMIT, 0);
2162 return TRUE;
2165 case WM_COMMAND:
2166 switch (LOWORD(wParam))
2168 default:
2169 if (HIWORD(wParam) != LBN_DBLCLK) break;
2170 /* fall through */
2171 case IDOK:
2173 /* windows are sorted by menu ID, so we must return the
2174 * window associated to the given id
2176 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2177 UINT index = SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
2178 LRESULT res = SendMessageW(hListBox, LB_GETITEMDATA, index, 0);
2179 EndDialog(hDlg, res);
2180 return TRUE;
2182 case IDCANCEL:
2183 EndDialog(hDlg, 0);
2184 return TRUE;
2186 break;
2188 return FALSE;
2193 * MDI_MoreWindowsDialog
2195 * Prompts the user with a listbox containing the opened
2196 * documents. The user can then choose a windows and click
2197 * on OK to set the current window to the one selected, or
2198 * CANCEL to cancel. The function returns a handle to the
2199 * selected window.
2202 static HWND MDI_MoreWindowsDialog(HWND hwnd)
2204 LPCVOID template;
2205 HRSRC hRes;
2206 HANDLE hDlgTmpl;
2208 hRes = FindResourceA(GetModuleHandleA("USER32"), "MDI_MOREWINDOWS", RT_DIALOGA);
2210 if (hRes == 0)
2211 return 0;
2213 hDlgTmpl = LoadResource(GetModuleHandleA("USER32"), hRes );
2215 if (hDlgTmpl == 0)
2216 return 0;
2218 template = LockResource( hDlgTmpl );
2220 if (template == 0)
2221 return 0;
2223 return (HWND) DialogBoxIndirectParamA(GetModuleHandleA("USER32"),
2224 (LPDLGTEMPLATEA) template,
2225 hwnd, MDI_MoreWindowsDlgProc, (LPARAM) hwnd);
2230 * MDI_SwapMenuItems
2232 * Will swap the menu IDs for the given 2 positions.
2233 * pos1 and pos2 are menu IDs
2238 static void MDI_SwapMenuItems(HWND parent, UINT pos1, UINT pos2)
2240 HWND *list;
2241 int i;
2243 if (!(list = WIN_ListChildren( parent ))) return;
2244 for (i = 0; list[i]; i++)
2246 UINT id = GetWindowLongW( list[i], GWL_ID );
2247 if (id == pos1) SetWindowLongW( list[i], GWL_ID, pos2 );
2248 else if (id == pos2) SetWindowLongW( list[i], GWL_ID, pos1 );
2250 HeapFree( GetProcessHeap(), 0, list );