Improve error reporting.
[wine/wine64.git] / windows / mdi.c
blob19c3071989c76bc9e2f07dc1b5da7d815e48bd8e
1 /* MDI.C
3 * Copyright 1994, Bob Amstadt
4 * 1995,1996 Alex Korobka
6 * This file contains routines to support MDI (Multiple Document
7 * Interface) features .
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Notes: Fairly complete implementation.
24 * Also, Excel and WinWord do _not_ use MDI so if you're trying
25 * to fix them look elsewhere.
27 * Notes on how the "More Windows..." is implemented:
29 * When we have more than 9 opened windows, a "More Windows..."
30 * option appears in the "Windows" menu. Each child window has
31 * a WND* associated with it, accesible via the children list of
32 * the parent window. This WND* has a wIDmenu member, which reflects
33 * the position of the child in the window list. For example, with
34 * 9 child windows, we could have the following pattern:
38 * Name of the child window pWndChild->wIDmenu
39 * Doc1 5000
40 * Doc2 5001
41 * Doc3 5002
42 * Doc4 5003
43 * Doc5 5004
44 * Doc6 5005
45 * Doc7 5006
46 * Doc8 5007
47 * Doc9 5008
50 * The "Windows" menu, as the "More windows..." dialog, are constructed
51 * in this order. If we add a child, we would have the following list:
54 * Name of the child window pWndChild->wIDmenu
55 * Doc1 5000
56 * Doc2 5001
57 * Doc3 5002
58 * Doc4 5003
59 * Doc5 5004
60 * Doc6 5005
61 * Doc7 5006
62 * Doc8 5007
63 * Doc9 5008
64 * Doc10 5009
66 * But only 5000 to 5008 would be displayed in the "Windows" menu. We want
67 * the last created child to be in the menu, so we swap the last child with
68 * the 9th... Doc9 will be accessible via the "More Windows..." option.
70 * Doc1 5000
71 * Doc2 5001
72 * Doc3 5002
73 * Doc4 5003
74 * Doc5 5004
75 * Doc6 5005
76 * Doc7 5006
77 * Doc8 5007
78 * Doc9 5009
79 * Doc10 5008
83 #include <stdlib.h>
84 #include <stdarg.h>
85 #include <stdio.h>
86 #include <string.h>
87 #include <math.h>
89 #include "windef.h"
90 #include "winbase.h"
91 #include "wingdi.h"
92 #include "winuser.h"
93 #include "wownt32.h"
94 #include "wine/unicode.h"
95 #include "win.h"
96 #include "nonclient.h"
97 #include "controls.h"
98 #include "user.h"
99 #include "struct32.h"
100 #include "wine/debug.h"
101 #include "dlgs.h"
103 WINE_DEFAULT_DEBUG_CHANNEL(mdi);
105 #define MDI_MAXLISTLENGTH 0x40
106 #define MDI_MAXTITLELENGTH 0xa1
108 #define MDI_NOFRAMEREPAINT 0
109 #define MDI_REPAINTFRAMENOW 1
110 #define MDI_REPAINTFRAME 2
112 #define WM_MDICALCCHILDSCROLL 0x10ac /* this is exactly what Windows uses */
114 /* "More Windows..." definitions */
115 #define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
116 option will appear under the Windows menu */
117 #define MDI_IDC_LISTBOX 100
118 #define IDS_MDI_MOREWINDOWS 13
120 #define MDIF_NEEDUPDATE 0x0001
122 typedef struct
124 UINT nActiveChildren;
125 HWND hwndChildMaximized;
126 HWND hwndActiveChild;
127 HMENU hWindowMenu;
128 UINT idFirstChild;
129 LPWSTR frameTitle;
130 UINT nTotalCreated;
131 UINT mdiFlags;
132 UINT sbRecalc; /* SB_xxx flags for scrollbar fixup */
133 } MDICLIENTINFO;
135 static HBITMAP hBmpClose = 0;
137 /* ----------------- declarations ----------------- */
138 static void MDI_UpdateFrameText( HWND, HWND, BOOL, LPCWSTR);
139 static BOOL MDI_AugmentFrameMenu( HWND, HWND );
140 static BOOL MDI_RestoreFrameMenu( HWND, HWND );
141 static LONG MDI_ChildActivate( HWND, HWND );
143 static HWND MDI_MoreWindowsDialog(HWND);
144 static void MDI_SwapMenuItems(HWND, UINT, UINT);
145 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
146 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
148 /* -------- Miscellaneous service functions ----------
150 * MDI_GetChildByID
152 static HWND MDI_GetChildByID(HWND hwnd, UINT id)
154 HWND ret;
155 HWND *win_array;
156 int i;
158 if (!(win_array = WIN_ListChildren( hwnd ))) return 0;
159 for (i = 0; win_array[i]; i++)
161 if (GetWindowLongA( win_array[i], GWL_ID ) == id) break;
163 ret = win_array[i];
164 HeapFree( GetProcessHeap(), 0, win_array );
165 return ret;
168 static void MDI_PostUpdate(HWND hwnd, MDICLIENTINFO* ci, WORD recalc)
170 if( !(ci->mdiFlags & MDIF_NEEDUPDATE) )
172 ci->mdiFlags |= MDIF_NEEDUPDATE;
173 PostMessageA( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
175 ci->sbRecalc = recalc;
179 /*********************************************************************
180 * MDIClient class descriptor
182 const struct builtin_class_descr MDICLIENT_builtin_class =
184 "MDIClient", /* name */
185 0, /* style */
186 MDIClientWndProcA, /* procA */
187 MDIClientWndProcW, /* procW */
188 sizeof(MDICLIENTINFO), /* extra */
189 IDC_ARROW, /* cursor */
190 (HBRUSH)(COLOR_APPWORKSPACE+1) /* brush */
194 static MDICLIENTINFO *get_client_info( HWND client )
196 MDICLIENTINFO *ret = NULL;
197 WND *win = WIN_GetPtr( client );
198 if (win)
200 if (win == WND_OTHER_PROCESS)
202 ERR( "client %p belongs to other process\n", client );
203 return NULL;
205 if (win->cbWndExtra < sizeof(MDICLIENTINFO)) WARN( "%p is not an MDI client\n", client );
206 else ret = (MDICLIENTINFO *)win->wExtra;
207 WIN_ReleasePtr( win );
209 return ret;
212 /**********************************************************************
213 * MDI_MenuModifyItem
215 static void MDI_MenuModifyItem( HWND client, HWND hWndChild )
217 MDICLIENTINFO *clientInfo = get_client_info( client );
218 WCHAR buffer[128];
219 UINT n, id;
221 if (!clientInfo || !clientInfo->hWindowMenu) return;
223 id = GetWindowLongA( hWndChild, GWL_ID );
224 if (id >= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT) return;
225 buffer[0] = '&';
226 buffer[1] = '1' + id - clientInfo->idFirstChild;
227 buffer[2] = ' ';
228 GetWindowTextW( hWndChild, buffer + 3, sizeof(buffer)/sizeof(WCHAR) - 3 );
230 n = GetMenuState(clientInfo->hWindowMenu, id, MF_BYCOMMAND);
231 ModifyMenuW(clientInfo->hWindowMenu, id, MF_BYCOMMAND | MF_STRING, id, buffer );
232 CheckMenuItem(clientInfo->hWindowMenu, id, n & MF_CHECKED);
235 /**********************************************************************
236 * MDI_MenuDeleteItem
238 static BOOL MDI_MenuDeleteItem( HWND client, HWND hWndChild )
240 WCHAR buffer[128];
241 static const WCHAR format[] = {'&','%','d',' ',0};
242 MDICLIENTINFO *clientInfo = get_client_info( client );
243 UINT index = 0,id,n;
245 if( !clientInfo->nActiveChildren || !clientInfo->hWindowMenu )
246 return FALSE;
248 id = GetWindowLongA( hWndChild, GWL_ID );
249 DeleteMenu(clientInfo->hWindowMenu,id,MF_BYCOMMAND);
251 /* walk the rest of MDI children to prevent gaps in the id
252 * sequence and in the menu child list */
254 for( index = id+1; index <= clientInfo->nActiveChildren +
255 clientInfo->idFirstChild; index++ )
257 HWND hwnd = MDI_GetChildByID(client,index);
258 if (!hwnd)
260 TRACE("no window for id=%i\n",index);
261 continue;
264 /* set correct id */
265 SetWindowLongW( hwnd, GWL_ID, GetWindowLongW( hwnd, GWL_ID ) - 1 );
267 n = wsprintfW(buffer, format ,index - clientInfo->idFirstChild);
268 GetWindowTextW( hwnd, buffer + n, sizeof(buffer)/sizeof(WCHAR) - n );
270 /* change menu if the current child is to be shown in the
271 * "Windows" menu
273 if (index <= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT)
274 ModifyMenuW(clientInfo->hWindowMenu ,index ,MF_BYCOMMAND | MF_STRING,
275 index - 1 , buffer );
278 /* We must restore the "More Windows..." option if there are enough children
280 if (clientInfo->nActiveChildren - 1 > MDI_MOREWINDOWSLIMIT)
282 WCHAR szTmp[50];
283 LoadStringW(GetModuleHandleA("USER32"), IDS_MDI_MOREWINDOWS, szTmp, sizeof(szTmp)/sizeof(szTmp[0]));
284 AppendMenuW(clientInfo->hWindowMenu, MF_STRING, clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT, szTmp);
286 return TRUE;
289 /**********************************************************************
290 * MDI_GetWindow
292 * returns "activateable" child different from the current or zero
294 static HWND MDI_GetWindow(MDICLIENTINFO *clientInfo, HWND hWnd, BOOL bNext,
295 DWORD dwStyleMask )
297 int i;
298 HWND *list;
299 HWND last = 0;
301 dwStyleMask |= WS_DISABLED | WS_VISIBLE;
302 if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
304 if (!(list = WIN_ListChildren( GetParent(hWnd) ))) return 0;
305 i = 0;
306 /* start from next after hWnd */
307 while (list[i] && list[i] != hWnd) i++;
308 if (list[i]) i++;
310 for ( ; list[i]; i++)
312 if (GetWindow( list[i], GW_OWNER )) continue;
313 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
314 last = list[i];
315 if (bNext) goto found;
317 /* now restart from the beginning */
318 for (i = 0; list[i] && list[i] != hWnd; i++)
320 if (GetWindow( list[i], GW_OWNER )) continue;
321 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
322 last = list[i];
323 if (bNext) goto found;
325 found:
326 HeapFree( GetProcessHeap(), 0, list );
327 return last;
330 /**********************************************************************
331 * MDI_CalcDefaultChildPos
333 * It seems that the default height is about 2/3 of the client rect
335 static void MDI_CalcDefaultChildPos( HWND hwnd, WORD n, LPPOINT lpPos, INT delta)
337 INT nstagger;
338 RECT rect;
339 INT spacing = GetSystemMetrics(SM_CYCAPTION) +
340 GetSystemMetrics(SM_CYFRAME) - 1;
342 GetClientRect( hwnd, &rect );
343 if( rect.bottom - rect.top - delta >= spacing )
344 rect.bottom -= delta;
346 nstagger = (rect.bottom - rect.top)/(3 * spacing);
347 lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
348 lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
349 lpPos[0].x = lpPos[0].y = spacing * (n%(nstagger+1));
352 /**********************************************************************
353 * MDISetMenu
355 static LRESULT MDISetMenu( HWND hwnd, HMENU hmenuFrame,
356 HMENU hmenuWindow)
358 MDICLIENTINFO *ci;
359 HWND hwndFrame = GetParent(hwnd);
360 HMENU oldFrameMenu = GetMenu(hwndFrame);
362 TRACE("%p %p %p\n", hwnd, hmenuFrame, hmenuWindow);
364 if (hmenuFrame && !IsMenu(hmenuFrame))
366 WARN("hmenuFrame is not a menu handle\n");
367 return 0L;
370 if (hmenuWindow && !IsMenu(hmenuWindow))
372 WARN("hmenuWindow is not a menu handle\n");
373 return 0L;
376 if (!(ci = get_client_info( hwnd ))) return 0;
378 if( ci->hwndChildMaximized && hmenuFrame && hmenuFrame!=oldFrameMenu )
379 MDI_RestoreFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
381 if( hmenuWindow && hmenuWindow != ci->hWindowMenu )
383 /* delete menu items from ci->hWindowMenu
384 * and add them to hmenuWindow */
385 /* Agent newsreader calls this function with ci->hWindowMenu == NULL */
386 if( ci->hWindowMenu && ci->nActiveChildren )
388 INT j;
389 LPWSTR buffer = NULL;
390 MENUITEMINFOW mii;
391 INT nbWindowsMenuItems; /* num of documents shown + "More Windows..." if present */
392 INT i = GetMenuItemCount(ci->hWindowMenu) - 1;
393 INT pos = GetMenuItemCount(hmenuWindow) + 1;
395 AppendMenuA( hmenuWindow, MF_SEPARATOR, 0, NULL);
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;
426 /* remove separator */
427 DeleteMenu(ci->hWindowMenu, i, MF_BYPOSITION);
429 ci->hWindowMenu = hmenuWindow;
432 if (hmenuFrame)
434 SetMenu(hwndFrame, hmenuFrame);
435 if( hmenuFrame!=oldFrameMenu )
437 if( ci->hwndChildMaximized )
438 MDI_AugmentFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
439 return (LRESULT)oldFrameMenu;
442 else
444 HMENU menu = GetMenu( GetParent(hwnd) );
445 INT nItems = GetMenuItemCount(menu) - 1;
446 UINT iId = GetMenuItemID(menu,nItems) ;
448 if( !(iId == SC_RESTORE || iId == SC_CLOSE) )
450 /* SetMenu() may already have been called, meaning that this window
451 * already has its menu. But they may have done a SetMenu() on
452 * an MDI window, and called MDISetMenu() after the fact, meaning
453 * that the "if" to this "else" wouldn't catch the need to
454 * augment the frame menu.
456 if( ci->hwndChildMaximized )
457 MDI_AugmentFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
460 return 0;
463 /**********************************************************************
464 * MDIRefreshMenu
466 static LRESULT MDIRefreshMenu( HWND hwnd, HMENU hmenuFrame,
467 HMENU hmenuWindow)
469 HWND hwndFrame = GetParent(hwnd);
470 HMENU oldFrameMenu = GetMenu(hwndFrame);
472 TRACE("%p %p %p\n", hwnd, hmenuFrame, hmenuWindow);
474 FIXME("partially function stub\n");
476 return (LRESULT)oldFrameMenu;
480 /* ------------------ MDI child window functions ---------------------- */
483 /**********************************************************************
484 * MDICreateChild
486 static HWND MDICreateChild( HWND parent, MDICLIENTINFO *ci,
487 LPMDICREATESTRUCTA cs, BOOL unicode )
489 POINT pos[2];
490 DWORD style = cs->style | (WS_CHILD | WS_CLIPSIBLINGS);
491 HWND hwnd, hwndMax = 0;
492 UINT wIDmenu = ci->idFirstChild + ci->nActiveChildren;
493 WND *wndParent;
494 static const WCHAR lpstrDef[] = {'j','u','n','k','!',0};
496 TRACE("origin %i,%i - dim %i,%i, style %08lx\n",
497 cs->x, cs->y, cs->cx, cs->cy, cs->style);
498 /* calculate placement */
499 MDI_CalcDefaultChildPos(parent, ci->nTotalCreated++, pos, 0);
501 if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16 || !cs->cx) cs->cx = pos[1].x;
502 if (cs->cy == CW_USEDEFAULT || cs->cy == CW_USEDEFAULT16 || !cs->cy) cs->cy = pos[1].y;
504 if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
506 cs->x = pos[0].x;
507 cs->y = pos[0].y;
510 /* restore current maximized child */
511 if( (style & WS_VISIBLE) && ci->hwndChildMaximized )
513 TRACE("Restoring current maximized child %p\n", ci->hwndChildMaximized);
514 if( style & WS_MAXIMIZE )
515 SendMessageW(parent, WM_SETREDRAW, FALSE, 0L);
516 hwndMax = ci->hwndChildMaximized;
517 ShowWindow( hwndMax, SW_SHOWNOACTIVATE );
518 if( style & WS_MAXIMIZE )
519 SendMessageW(parent, WM_SETREDRAW, TRUE, 0L);
522 if (ci->nActiveChildren <= MDI_MOREWINDOWSLIMIT)
523 /* this menu is needed to set a check mark in MDI_ChildActivate */
524 if (ci->hWindowMenu != 0)
525 AppendMenuW(ci->hWindowMenu, MF_STRING, wIDmenu, lpstrDef);
527 ci->nActiveChildren++;
529 /* fix window style */
530 wndParent = WIN_FindWndPtr( parent );
531 if( !(wndParent->dwStyle & MDIS_ALLCHILDSTYLES) )
533 TRACE("MDIS_ALLCHILDSTYLES is missing, fixing window style\n");
534 style &= (WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZE | WS_MAXIMIZE |
535 WS_CLIPCHILDREN | WS_DISABLED | WS_VSCROLL | WS_HSCROLL );
536 style |= (WS_VISIBLE | WS_OVERLAPPEDWINDOW);
539 if( wndParent->flags & WIN_ISWIN32 )
541 WIN_ReleaseWndPtr( wndParent );
542 /* FIXME: CreateWindowEx must be called with WS_EX_MDICHILD set, but
543 * it requires to move MDI specific child creation to CreateWindowEx
544 * and do child tracking in MDICLIENT using WM_PARENTNOTIFY.
546 if(unicode)
548 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)cs;
549 hwnd = CreateWindowExW( 0, 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 = CreateWindowExA( 0, 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( CreateWindowEx16( 0, cs->szClass, cs->szTitle, style,
569 cs16.x, cs16.y, cs16.cx, cs16.cy,
570 HWND_16(parent), (HMENU16)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 %p\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 - %p\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 (%ld,%ld - %ld, %ld)\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 %p, to %p\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 - %p\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("%p\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 INT cmd = SW_SHOWNORMAL;
778 if( child )
780 UINT state = GetMenuState(GetSystemMenu(child, FALSE), SC_MAXIMIZE, MF_BYCOMMAND);
781 if (state != 0xFFFFFFFF && (state & (MF_DISABLED | MF_GRAYED)))
782 SendMessageW(clientInfo->hwndChildMaximized, WM_SYSCOMMAND, SC_RESTORE, 0);
783 else
784 cmd = SW_SHOWMAXIMIZED;
786 clientInfo->hwndActiveChild = child;
789 ShowWindow( clientInfo->hwndActiveChild, cmd );
792 clientInfo->hwndActiveChild = child;
794 /* check if we have any children left */
795 if( !child )
797 if( isActiveFrameWnd )
798 SetFocus( client );
799 return 0;
802 /* check menu item */
803 if( clientInfo->hWindowMenu )
805 UINT id = GetWindowLongA( child, GWL_ID );
806 /* The window to be activated must be displayed in the "Windows" menu */
807 if (id >= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT)
809 MDI_SwapMenuItems( GetParent(child),
810 id, clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1);
811 id = clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1;
812 MDI_MenuModifyItem( GetParent(child), child );
815 CheckMenuItem(clientInfo->hWindowMenu, id, MF_CHECKED);
817 /* bring active child to the top */
818 SetWindowPos( child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
820 if( isActiveFrameWnd )
822 SendMessageA( child, WM_NCACTIVATE, TRUE, 0L);
823 if( GetFocus() == client )
824 SendMessageA( client, WM_SETFOCUS, (WPARAM)client, 0L );
825 else
826 SetFocus( client );
828 SendMessageA( child, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child );
829 return TRUE;
832 /* -------------------- MDI client window functions ------------------- */
834 /**********************************************************************
835 * CreateMDIMenuBitmap
837 static HBITMAP CreateMDIMenuBitmap(void)
839 HDC hDCSrc = CreateCompatibleDC(0);
840 HDC hDCDest = CreateCompatibleDC(hDCSrc);
841 HBITMAP hbClose = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_OLD_CLOSE) );
842 HBITMAP hbCopy;
843 HBITMAP hobjSrc, hobjDest;
845 hobjSrc = SelectObject(hDCSrc, hbClose);
846 hbCopy = CreateCompatibleBitmap(hDCSrc,GetSystemMetrics(SM_CXSIZE),GetSystemMetrics(SM_CYSIZE));
847 hobjDest = SelectObject(hDCDest, hbCopy);
849 BitBlt(hDCDest, 0, 0, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE),
850 hDCSrc, GetSystemMetrics(SM_CXSIZE), 0, SRCCOPY);
852 SelectObject(hDCSrc, hobjSrc);
853 DeleteObject(hbClose);
854 DeleteDC(hDCSrc);
856 hobjSrc = SelectObject( hDCDest, GetStockObject(BLACK_PEN) );
858 MoveToEx( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, 0, NULL );
859 LineTo( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, GetSystemMetrics(SM_CYSIZE) - 1);
861 SelectObject(hDCDest, hobjSrc );
862 SelectObject(hDCDest, hobjDest);
863 DeleteDC(hDCDest);
865 return hbCopy;
868 /**********************************************************************
869 * MDICascade
871 static LONG MDICascade( HWND client, MDICLIENTINFO *ci )
873 HWND *win_array;
874 BOOL has_icons = FALSE;
875 int i, total;
877 if (ci->hwndChildMaximized)
878 SendMessageA( client, WM_MDIRESTORE,
879 (WPARAM)ci->hwndChildMaximized, 0);
881 if (ci->nActiveChildren == 0) return 0;
883 if (!(win_array = WIN_ListChildren( client ))) return 0;
885 /* remove all the windows we don't want */
886 for (i = total = 0; win_array[i]; i++)
888 if (!IsWindowVisible( win_array[i] )) continue;
889 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows */
890 if (IsIconic( win_array[i] ))
892 has_icons = TRUE;
893 continue;
895 win_array[total++] = win_array[i];
897 win_array[total] = 0;
899 if (total)
901 INT delta = 0, n = 0, i;
902 POINT pos[2];
903 if (has_icons) delta = GetSystemMetrics(SM_CYICONSPACING) + GetSystemMetrics(SM_CYICON);
905 /* walk the list (backwards) and move windows */
906 for (i = total - 1; i >= 0; i--)
908 TRACE("move %p to (%ld,%ld) size [%ld,%ld]\n",
909 win_array[i], pos[0].x, pos[0].y, pos[1].x, pos[1].y);
911 MDI_CalcDefaultChildPos(client, n++, pos, delta);
912 SetWindowPos( win_array[i], 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
913 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
916 HeapFree( GetProcessHeap(), 0, win_array );
918 if (has_icons) ArrangeIconicWindows( client );
919 return 0;
922 /**********************************************************************
923 * MDITile
925 static void MDITile( HWND client, MDICLIENTINFO *ci, WPARAM wParam )
927 HWND *win_array;
928 int i, total;
929 BOOL has_icons = FALSE;
931 if (ci->hwndChildMaximized)
932 SendMessageA( client, WM_MDIRESTORE, (WPARAM)ci->hwndChildMaximized, 0);
934 if (ci->nActiveChildren == 0) return;
936 if (!(win_array = WIN_ListChildren( client ))) return;
938 /* remove all the windows we don't want */
939 for (i = total = 0; win_array[i]; i++)
941 if (!IsWindowVisible( win_array[i] )) continue;
942 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows (icon titles) */
943 if (IsIconic( win_array[i] ))
945 has_icons = TRUE;
946 continue;
948 if ((wParam & MDITILE_SKIPDISABLED) && !IsWindowEnabled( win_array[i] )) continue;
949 win_array[total++] = win_array[i];
951 win_array[total] = 0;
953 TRACE("%u windows to tile\n", total);
955 if (total)
957 HWND *pWnd = win_array;
958 RECT rect;
959 int x, y, xsize, ysize;
960 int rows, columns, r, c, i;
962 GetClientRect(client,&rect);
963 rows = (int) sqrt((double)total);
964 columns = total / rows;
966 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
968 i = rows;
969 rows = columns; /* exchange r and c */
970 columns = i;
973 if (has_icons)
975 y = rect.bottom - 2 * GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
976 rect.bottom = ( y - GetSystemMetrics(SM_CYICON) < rect.top )? rect.bottom: y;
979 ysize = rect.bottom / rows;
980 xsize = rect.right / columns;
982 for (x = i = 0, c = 1; c <= columns && *pWnd; c++)
984 if (c == columns)
986 rows = total - i;
987 ysize = rect.bottom / rows;
990 y = 0;
991 for (r = 1; r <= rows && *pWnd; r++, i++)
993 SetWindowPos(*pWnd, 0, x, y, xsize, ysize,
994 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
995 y += ysize;
996 pWnd++;
998 x += xsize;
1001 HeapFree( GetProcessHeap(), 0, win_array );
1002 if (has_icons) ArrangeIconicWindows( client );
1005 /* ----------------------- Frame window ---------------------------- */
1008 /**********************************************************************
1009 * MDI_AugmentFrameMenu
1011 static BOOL MDI_AugmentFrameMenu( HWND frame, HWND hChild )
1013 HMENU menu = GetMenu( frame );
1014 WND* child = WIN_FindWndPtr(hChild);
1015 HMENU hSysPopup = 0;
1016 HBITMAP hSysMenuBitmap = 0;
1018 TRACE("frame %p,child %p\n",frame,hChild);
1020 if( !menu || !child->hSysMenu )
1022 WIN_ReleaseWndPtr(child);
1023 return 0;
1025 WIN_ReleaseWndPtr(child);
1027 /* create a copy of sysmenu popup and insert it into frame menu bar */
1029 if (!(hSysPopup = LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU")))
1030 return 0;
1032 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1033 SC_MINIMIZE, (LPSTR)(DWORD)HBMMENU_MBAR_MINIMIZE ) ;
1034 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1035 SC_RESTORE, (LPSTR)(DWORD)HBMMENU_MBAR_RESTORE );
1037 /* In Win 95 look, the system menu is replaced by the child icon */
1039 if(TWEAK_WineLook > WIN31_LOOK)
1041 HICON hIcon = (HICON)GetClassLongA(hChild, GCL_HICONSM);
1042 if (!hIcon)
1043 hIcon = (HICON)GetClassLongA(hChild, GCL_HICON);
1044 if (hIcon)
1046 HDC hMemDC;
1047 HBITMAP hBitmap, hOldBitmap;
1048 HBRUSH hBrush;
1049 HDC hdc = GetDC(hChild);
1051 if (hdc)
1053 int cx, cy;
1054 cx = GetSystemMetrics(SM_CXSMICON);
1055 cy = GetSystemMetrics(SM_CYSMICON);
1056 hMemDC = CreateCompatibleDC(hdc);
1057 hBitmap = CreateCompatibleBitmap(hdc, cx, cy);
1058 hOldBitmap = SelectObject(hMemDC, hBitmap);
1059 SetMapMode(hMemDC, MM_TEXT);
1060 hBrush = CreateSolidBrush(GetSysColor(COLOR_MENU));
1061 DrawIconEx(hMemDC, 0, 0, hIcon, cx, cy, 0, hBrush, DI_NORMAL);
1062 SelectObject (hMemDC, hOldBitmap);
1063 DeleteObject(hBrush);
1064 DeleteDC(hMemDC);
1065 ReleaseDC(hChild, hdc);
1066 hSysMenuBitmap = hBitmap;
1070 else
1071 hSysMenuBitmap = hBmpClose;
1073 if( !InsertMenuA(menu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
1074 (UINT_PTR)hSysPopup, (LPSTR)hSysMenuBitmap))
1076 TRACE("not inserted\n");
1077 DestroyMenu(hSysPopup);
1078 return 0;
1081 /* The close button is only present in Win 95 look */
1082 if(TWEAK_WineLook > WIN31_LOOK)
1084 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1085 SC_CLOSE, (LPSTR)(DWORD)HBMMENU_MBAR_CLOSE );
1088 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
1089 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
1090 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
1091 SetMenuDefaultItem(hSysPopup, SC_CLOSE, FALSE);
1093 /* redraw menu */
1094 DrawMenuBar(frame);
1096 return 1;
1099 /**********************************************************************
1100 * MDI_RestoreFrameMenu
1102 static BOOL MDI_RestoreFrameMenu( HWND frame, HWND hChild )
1104 MENUITEMINFOW menuInfo;
1105 HMENU menu = GetMenu( frame );
1106 INT nItems = GetMenuItemCount(menu) - 1;
1107 UINT iId = GetMenuItemID(menu,nItems) ;
1109 TRACE("frame %p,child %p,nIt=%d,iId=%d\n",frame,hChild,nItems,iId);
1111 if(!(iId == SC_RESTORE || iId == SC_CLOSE) )
1112 return 0;
1115 * Remove the system menu, If that menu is the icon of the window
1116 * as it is in win95, we have to delete the bitmap.
1118 memset(&menuInfo, 0, sizeof(menuInfo));
1119 menuInfo.cbSize = sizeof(menuInfo);
1120 menuInfo.fMask = MIIM_DATA | MIIM_TYPE;
1122 GetMenuItemInfoW(menu,
1124 TRUE,
1125 &menuInfo);
1127 RemoveMenu(menu,0,MF_BYPOSITION);
1129 if ( (menuInfo.fType & MFT_BITMAP) &&
1130 (LOWORD(menuInfo.dwTypeData)!=0) &&
1131 (LOWORD(menuInfo.dwTypeData)!=HBITMAP_16(hBmpClose)) )
1133 DeleteObject(HBITMAP_32(LOWORD(menuInfo.dwTypeData)));
1136 if(TWEAK_WineLook > WIN31_LOOK)
1138 /* close */
1139 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1141 /* restore */
1142 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1143 /* minimize */
1144 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1146 DrawMenuBar(frame);
1148 return 1;
1152 /**********************************************************************
1153 * MDI_UpdateFrameText
1155 * used when child window is maximized/restored
1157 * Note: lpTitle can be NULL
1159 static void MDI_UpdateFrameText( HWND frame, HWND hClient,
1160 BOOL repaint, LPCWSTR lpTitle )
1162 WCHAR lpBuffer[MDI_MAXTITLELENGTH+1];
1163 MDICLIENTINFO *ci = get_client_info( hClient );
1165 TRACE("repaint %i, frameText %s\n", repaint, debugstr_w(lpTitle));
1167 if (!ci) return;
1169 if (!lpTitle && !ci->frameTitle) /* first time around, get title from the frame window */
1171 GetWindowTextW( frame, lpBuffer, sizeof(lpBuffer)/sizeof(WCHAR) );
1172 lpTitle = lpBuffer;
1175 /* store new "default" title if lpTitle is not NULL */
1176 if (lpTitle)
1178 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1179 if ((ci->frameTitle = HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle)+1)*sizeof(WCHAR))))
1180 strcpyW( ci->frameTitle, lpTitle );
1183 if (ci->frameTitle)
1185 if (ci->hwndChildMaximized)
1187 /* combine frame title and child title if possible */
1189 static const WCHAR lpBracket[] = {' ','-',' ','[',0};
1190 static const WCHAR lpBracket2[] = {']',0};
1191 int i_frame_text_length = strlenW(ci->frameTitle);
1193 lstrcpynW( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
1195 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
1197 strcatW( lpBuffer, lpBracket );
1198 if (GetWindowTextW( ci->hwndChildMaximized, lpBuffer + i_frame_text_length + 4,
1199 MDI_MAXTITLELENGTH - i_frame_text_length - 5 ))
1200 strcatW( lpBuffer, lpBracket2 );
1201 else
1202 lpBuffer[i_frame_text_length] = 0; /* remove bracket */
1205 else
1207 lstrcpynW(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH+1 );
1210 else
1211 lpBuffer[0] = '\0';
1213 DefWindowProcW( frame, WM_SETTEXT, 0, (LPARAM)lpBuffer );
1214 if( repaint == MDI_REPAINTFRAME)
1215 SetWindowPos( frame, 0,0,0,0,0, SWP_FRAMECHANGED |
1216 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
1220 /* ----------------------------- Interface ---------------------------- */
1223 /**********************************************************************
1224 * MDIClientWndProc_common
1226 static LRESULT MDIClientWndProc_common( HWND hwnd, UINT message,
1227 WPARAM wParam, LPARAM lParam, BOOL unicode )
1229 MDICLIENTINFO *ci;
1231 if (!(ci = get_client_info( hwnd ))) return 0;
1233 switch (message)
1235 case WM_CREATE:
1237 RECT rect;
1238 /* Since we are using only cs->lpCreateParams, we can safely
1239 * cast to LPCREATESTRUCTA here */
1240 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
1241 WND *wndPtr = WIN_GetPtr( hwnd );
1243 /* Translation layer doesn't know what's in the cs->lpCreateParams
1244 * so we have to keep track of what environment we're in. */
1246 if( wndPtr->flags & WIN_ISWIN32 )
1248 #define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1249 ci->hWindowMenu = ccs->hWindowMenu;
1250 ci->idFirstChild = ccs->idFirstChild;
1251 #undef ccs
1253 else
1255 LPCLIENTCREATESTRUCT16 ccs = MapSL((SEGPTR)cs->lpCreateParams);
1256 ci->hWindowMenu = HMENU_32(ccs->hWindowMenu);
1257 ci->idFirstChild = ccs->idFirstChild;
1259 WIN_ReleasePtr( wndPtr );
1261 ci->hwndChildMaximized = 0;
1262 ci->nActiveChildren = 0;
1263 ci->nTotalCreated = 0;
1264 ci->frameTitle = NULL;
1265 ci->mdiFlags = 0;
1266 SetWindowLongW( hwnd, GWL_STYLE, GetWindowLongW(hwnd,GWL_STYLE) | WS_CLIPCHILDREN );
1268 if (!hBmpClose) hBmpClose = CreateMDIMenuBitmap();
1270 if (ci->hWindowMenu != 0)
1271 AppendMenuW( ci->hWindowMenu, MF_SEPARATOR, 0, NULL );
1273 GetClientRect( GetParent(hwnd), &rect);
1274 MoveWindow( hwnd, 0, 0, rect.right, rect.bottom, FALSE );
1276 MDI_UpdateFrameText( GetParent(hwnd), hwnd, MDI_NOFRAMEREPAINT, NULL);
1278 TRACE("Client created - hwnd = %p, idFirst = %u\n", hwnd, ci->idFirstChild );
1279 return 0;
1282 case WM_DESTROY:
1284 INT nItems;
1285 if( ci->hwndChildMaximized )
1286 MDI_RestoreFrameMenu( GetParent(hwnd), ci->hwndChildMaximized);
1287 if((ci->hWindowMenu != 0) &&
1288 (nItems = GetMenuItemCount(ci->hWindowMenu)) > 0)
1290 ci->idFirstChild = nItems - 1;
1291 ci->nActiveChildren++; /* to delete a separator */
1292 while( ci->nActiveChildren-- )
1293 DeleteMenu(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
1295 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1296 return 0;
1299 case WM_MDIACTIVATE:
1300 if( ci->hwndActiveChild != (HWND)wParam )
1301 SetWindowPos((HWND)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
1302 return 0;
1304 case WM_MDICASCADE:
1305 return MDICascade(hwnd, ci);
1307 case WM_MDICREATE:
1308 if (lParam)
1309 return (LRESULT)MDICreateChild( hwnd, ci, (MDICREATESTRUCTA *)lParam, unicode );
1310 return 0;
1312 case WM_MDIDESTROY:
1313 return MDIDestroyChild( hwnd, ci, WIN_GetFullHandle( (HWND)wParam ), TRUE );
1315 case WM_MDIGETACTIVE:
1316 if (lParam) *(BOOL *)lParam = (ci->hwndChildMaximized != 0);
1317 return (LRESULT)ci->hwndActiveChild;
1319 case WM_MDIICONARRANGE:
1320 ci->mdiFlags |= MDIF_NEEDUPDATE;
1321 ArrangeIconicWindows( hwnd );
1322 ci->sbRecalc = SB_BOTH+1;
1323 SendMessageW( hwnd, WM_MDICALCCHILDSCROLL, 0, 0 );
1324 return 0;
1326 case WM_MDIMAXIMIZE:
1327 ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1328 return 0;
1330 case WM_MDINEXT: /* lParam != 0 means previous window */
1331 MDI_SwitchActiveChild( hwnd, WIN_GetFullHandle( (HWND)wParam ), !lParam );
1332 break;
1334 case WM_MDIRESTORE:
1335 SendMessageW( (HWND)wParam, WM_SYSCOMMAND, SC_RESTORE, 0);
1336 return 0;
1338 case WM_MDISETMENU:
1339 return MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1341 case WM_MDIREFRESHMENU:
1342 return MDIRefreshMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1344 case WM_MDITILE:
1345 ci->mdiFlags |= MDIF_NEEDUPDATE;
1346 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1347 MDITile( hwnd, ci, wParam );
1348 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1349 return 0;
1351 case WM_VSCROLL:
1352 case WM_HSCROLL:
1353 ci->mdiFlags |= MDIF_NEEDUPDATE;
1354 ScrollChildren( hwnd, message, wParam, lParam );
1355 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1356 return 0;
1358 case WM_SETFOCUS:
1359 if (ci->hwndActiveChild && !IsIconic( ci->hwndActiveChild ))
1360 SetFocus( ci->hwndActiveChild );
1361 return 0;
1363 case WM_NCACTIVATE:
1364 if( ci->hwndActiveChild )
1365 SendMessageW(ci->hwndActiveChild, message, wParam, lParam);
1366 break;
1368 case WM_PARENTNOTIFY:
1369 if (LOWORD(wParam) == WM_LBUTTONDOWN)
1371 HWND child;
1372 POINT pt;
1373 pt.x = (short)LOWORD(lParam);
1374 pt.y = (short)HIWORD(lParam);
1375 child = ChildWindowFromPoint(hwnd, pt);
1377 TRACE("notification from %p (%li,%li)\n",child,pt.x,pt.y);
1379 if( child && child != hwnd && child != ci->hwndActiveChild )
1380 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1382 return 0;
1384 case WM_SIZE:
1385 if( IsWindow(ci->hwndChildMaximized) )
1387 RECT rect;
1389 rect.left = 0;
1390 rect.top = 0;
1391 rect.right = LOWORD(lParam);
1392 rect.bottom = HIWORD(lParam);
1394 AdjustWindowRectEx(&rect, GetWindowLongA(ci->hwndChildMaximized,GWL_STYLE),
1395 0, GetWindowLongA(ci->hwndChildMaximized,GWL_EXSTYLE) );
1396 MoveWindow(ci->hwndChildMaximized, rect.left, rect.top,
1397 rect.right - rect.left, rect.bottom - rect.top, 1);
1399 else
1400 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1402 break;
1404 case WM_MDICALCCHILDSCROLL:
1405 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1407 CalcChildScroll(hwnd, ci->sbRecalc-1);
1408 ci->sbRecalc = 0;
1409 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1411 return 0;
1413 return unicode ? DefWindowProcW( hwnd, message, wParam, lParam ) :
1414 DefWindowProcA( hwnd, message, wParam, lParam );
1417 /***********************************************************************
1418 * MDIClientWndProcA
1420 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1422 if (!IsWindow(hwnd)) return 0;
1423 return MDIClientWndProc_common( hwnd, message, wParam, lParam, FALSE );
1426 /***********************************************************************
1427 * MDIClientWndProcW
1429 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1431 if (!IsWindow(hwnd)) return 0;
1432 return MDIClientWndProc_common( hwnd, message, wParam, lParam, TRUE );
1435 /***********************************************************************
1436 * DefFrameProcA (USER32.@)
1438 LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1439 UINT message, WPARAM wParam, LPARAM lParam)
1441 if (hwndMDIClient)
1443 switch (message)
1445 case WM_SETTEXT:
1447 DWORD len = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0 );
1448 LPWSTR text = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1449 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, text, len );
1450 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, text );
1451 HeapFree( GetProcessHeap(), 0, text );
1453 return 1; /* success. FIXME: check text length */
1455 case WM_COMMAND:
1456 case WM_NCACTIVATE:
1457 case WM_NEXTMENU:
1458 case WM_SETFOCUS:
1459 case WM_SIZE:
1460 return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1463 return DefWindowProcA(hwnd, message, wParam, lParam);
1467 /***********************************************************************
1468 * DefFrameProcW (USER32.@)
1470 LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1471 UINT message, WPARAM wParam, LPARAM lParam)
1473 MDICLIENTINFO *ci = get_client_info( hwndMDIClient );
1475 if (ci)
1477 switch (message)
1479 case WM_COMMAND:
1481 WORD id = LOWORD(wParam);
1482 /* check for possible syscommands for maximized MDI child */
1483 if (id < ci->idFirstChild || id >= ci->idFirstChild + ci->nActiveChildren)
1485 if( (id - 0xf000) & 0xf00f ) break;
1486 if( !ci->hwndChildMaximized ) break;
1487 switch( id )
1489 case SC_SIZE:
1490 case SC_MOVE:
1491 case SC_MINIMIZE:
1492 case SC_MAXIMIZE:
1493 case SC_NEXTWINDOW:
1494 case SC_PREVWINDOW:
1495 case SC_CLOSE:
1496 case SC_RESTORE:
1497 return SendMessageW( ci->hwndChildMaximized, WM_SYSCOMMAND,
1498 wParam, lParam);
1501 else
1503 HWND childHwnd;
1504 if (id - ci->idFirstChild == MDI_MOREWINDOWSLIMIT)
1505 /* User chose "More Windows..." */
1506 childHwnd = MDI_MoreWindowsDialog(hwndMDIClient);
1507 else
1508 /* User chose one of the windows listed in the "Windows" menu */
1509 childHwnd = MDI_GetChildByID(hwndMDIClient,id);
1511 if( childHwnd )
1512 SendMessageW( hwndMDIClient, WM_MDIACTIVATE, (WPARAM)childHwnd, 0 );
1515 break;
1517 case WM_NCACTIVATE:
1518 SendMessageW(hwndMDIClient, message, wParam, lParam);
1519 break;
1521 case WM_SETTEXT:
1522 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, (LPWSTR)lParam );
1523 return 1; /* success. FIXME: check text length */
1525 case WM_SETFOCUS:
1526 SetFocus(hwndMDIClient);
1527 break;
1529 case WM_SIZE:
1530 MoveWindow(hwndMDIClient, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
1531 break;
1533 case WM_NEXTMENU:
1535 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1537 if (!IsIconic(hwnd) && ci->hwndActiveChild && !ci->hwndChildMaximized)
1539 /* control menu is between the frame system menu and
1540 * the first entry of menu bar */
1541 WND *wndPtr = WIN_GetPtr(hwnd);
1543 if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1544 (wParam == VK_RIGHT && GetSubMenu(wndPtr->hSysMenu, 0) == next_menu->hmenuIn) )
1546 WIN_ReleasePtr(wndPtr);
1547 wndPtr = WIN_GetPtr(ci->hwndActiveChild);
1548 next_menu->hmenuNext = GetSubMenu(wndPtr->hSysMenu, 0);
1549 next_menu->hwndNext = ci->hwndActiveChild;
1551 WIN_ReleasePtr(wndPtr);
1553 return 0;
1558 return DefWindowProcW( hwnd, message, wParam, lParam );
1561 /***********************************************************************
1562 * DefMDIChildProcA (USER32.@)
1564 LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1565 WPARAM wParam, LPARAM lParam )
1567 HWND client = GetParent(hwnd);
1568 MDICLIENTINFO *ci = get_client_info( client );
1570 hwnd = WIN_GetFullHandle( hwnd );
1571 if (!ci) return DefWindowProcA( hwnd, message, wParam, lParam );
1573 switch (message)
1575 case WM_SETTEXT:
1576 DefWindowProcA(hwnd, message, wParam, lParam);
1577 MDI_MenuModifyItem( client, hwnd );
1578 if( ci->hwndChildMaximized == hwnd )
1579 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1580 return 1; /* success. FIXME: check text length */
1582 case WM_GETMINMAXINFO:
1583 case WM_MENUCHAR:
1584 case WM_CLOSE:
1585 case WM_SETFOCUS:
1586 case WM_CHILDACTIVATE:
1587 case WM_SYSCOMMAND:
1588 case WM_SETVISIBLE:
1589 case WM_SIZE:
1590 case WM_NEXTMENU:
1591 case WM_SYSCHAR:
1592 return DefMDIChildProcW( hwnd, message, wParam, lParam );
1594 return DefWindowProcA(hwnd, message, wParam, lParam);
1598 /***********************************************************************
1599 * DefMDIChildProcW (USER32.@)
1601 LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1602 WPARAM wParam, LPARAM lParam )
1604 HWND client = GetParent(hwnd);
1605 MDICLIENTINFO *ci = get_client_info( client );
1607 hwnd = WIN_GetFullHandle( hwnd );
1608 if (!ci) return DefWindowProcW( hwnd, message, wParam, lParam );
1610 switch (message)
1612 case WM_SETTEXT:
1613 DefWindowProcW(hwnd, message, wParam, lParam);
1614 MDI_MenuModifyItem( client, hwnd );
1615 if( ci->hwndChildMaximized == hwnd )
1616 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1617 return 1; /* success. FIXME: check text length */
1619 case WM_GETMINMAXINFO:
1620 MDI_ChildGetMinMaxInfo( client, hwnd, (MINMAXINFO *)lParam );
1621 return 0;
1623 case WM_MENUCHAR:
1624 return 0x00010000; /* MDI children don't have menu bars */
1626 case WM_CLOSE:
1627 SendMessageW( client, WM_MDIDESTROY, (WPARAM)hwnd, 0 );
1628 return 0;
1630 case WM_SETFOCUS:
1631 if (ci->hwndActiveChild != hwnd) MDI_ChildActivate( client, hwnd );
1632 break;
1634 case WM_CHILDACTIVATE:
1635 MDI_ChildActivate( client, hwnd );
1636 return 0;
1638 case WM_SYSCOMMAND:
1639 switch( wParam )
1641 case SC_MOVE:
1642 if( ci->hwndChildMaximized == hwnd) return 0;
1643 break;
1644 case SC_RESTORE:
1645 case SC_MINIMIZE:
1646 SetWindowLongW( hwnd, GWL_STYLE,
1647 GetWindowLongW( hwnd, GWL_STYLE ) | WS_SYSMENU );
1648 break;
1649 case SC_MAXIMIZE:
1650 if (ci->hwndChildMaximized == hwnd)
1651 return SendMessageW( GetParent(client), message, wParam, lParam);
1652 SetWindowLongW( hwnd, GWL_STYLE,
1653 GetWindowLongW( hwnd, GWL_STYLE ) & ~WS_SYSMENU );
1654 break;
1655 case SC_NEXTWINDOW:
1656 SendMessageW( client, WM_MDINEXT, 0, 0);
1657 return 0;
1658 case SC_PREVWINDOW:
1659 SendMessageW( client, WM_MDINEXT, 0, 1);
1660 return 0;
1662 break;
1664 case WM_SETVISIBLE:
1665 if( ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1666 else MDI_PostUpdate(client, ci, SB_BOTH+1);
1667 break;
1669 case WM_SIZE:
1670 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1672 ci->hwndChildMaximized = 0;
1673 MDI_RestoreFrameMenu( GetParent(client), hwnd );
1674 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1677 if( wParam == SIZE_MAXIMIZED )
1679 HWND hMaxChild = ci->hwndChildMaximized;
1681 if( hMaxChild == hwnd ) break;
1682 if( hMaxChild)
1684 SendMessageW( hMaxChild, WM_SETREDRAW, FALSE, 0 );
1685 MDI_RestoreFrameMenu( GetParent(client), hMaxChild );
1686 ShowWindow( hMaxChild, SW_SHOWNOACTIVATE );
1687 SendMessageW( hMaxChild, WM_SETREDRAW, TRUE, 0 );
1689 TRACE("maximizing child %p\n", hwnd );
1691 /* keep track of the maximized window. */
1692 ci->hwndChildMaximized = hwnd; /* !!! */
1694 /* The maximized window should also be the active window */
1695 MDI_ChildActivate( client, hwnd );
1696 MDI_AugmentFrameMenu( GetParent(client), hwnd );
1697 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1700 if( wParam == SIZE_MINIMIZED )
1702 HWND switchTo = MDI_GetWindow(ci, hwnd, TRUE, WS_MINIMIZE);
1704 if (switchTo) SendMessageW( switchTo, WM_CHILDACTIVATE, 0, 0);
1706 MDI_PostUpdate(client, ci, SB_BOTH+1);
1707 break;
1709 case WM_NEXTMENU:
1711 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1712 HWND parent = GetParent(client);
1714 if( wParam == VK_LEFT ) /* switch to frame system menu */
1716 WND *wndPtr = WIN_GetPtr( parent );
1717 next_menu->hmenuNext = GetSubMenu( wndPtr->hSysMenu, 0 );
1718 WIN_ReleasePtr( wndPtr );
1720 if( wParam == VK_RIGHT ) /* to frame menu bar */
1722 next_menu->hmenuNext = GetMenu(parent);
1724 next_menu->hwndNext = parent;
1725 return 0;
1728 case WM_SYSCHAR:
1729 if (wParam == '-')
1731 SendMessageW( hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (DWORD)VK_SPACE);
1732 return 0;
1734 break;
1736 return DefWindowProcW(hwnd, message, wParam, lParam);
1739 /**********************************************************************
1740 * CreateMDIWindowA (USER32.@) Creates a MDI child
1742 * RETURNS
1743 * Success: Handle to created window
1744 * Failure: NULL
1746 HWND WINAPI CreateMDIWindowA(
1747 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1748 LPCSTR lpWindowName, /* [in] Pointer to window name */
1749 DWORD dwStyle, /* [in] Window style */
1750 INT X, /* [in] Horizontal position of window */
1751 INT Y, /* [in] Vertical position of window */
1752 INT nWidth, /* [in] Width of window */
1753 INT nHeight, /* [in] Height of window */
1754 HWND hWndParent, /* [in] Handle to parent window */
1755 HINSTANCE hInstance, /* [in] Handle to application instance */
1756 LPARAM lParam) /* [in] Application-defined value */
1758 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1759 MDICREATESTRUCTA cs;
1761 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%p,%p,%ld)\n",
1762 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1763 nWidth,nHeight,hWndParent,hInstance,lParam);
1765 if (!pCi)
1767 ERR("bad hwnd for MDI-client: %p\n", hWndParent);
1768 return 0;
1770 cs.szClass=lpClassName;
1771 cs.szTitle=lpWindowName;
1772 cs.hOwner=hInstance;
1773 cs.x=X;
1774 cs.y=Y;
1775 cs.cx=nWidth;
1776 cs.cy=nHeight;
1777 cs.style=dwStyle;
1778 cs.lParam=lParam;
1780 return MDICreateChild(hWndParent, pCi, &cs, FALSE);
1783 /***********************************************************************
1784 * CreateMDIWindowW (USER32.@) Creates a MDI child
1786 * RETURNS
1787 * Success: Handle to created window
1788 * Failure: NULL
1790 HWND WINAPI CreateMDIWindowW(
1791 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1792 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1793 DWORD dwStyle, /* [in] Window style */
1794 INT X, /* [in] Horizontal position of window */
1795 INT Y, /* [in] Vertical position of window */
1796 INT nWidth, /* [in] Width of window */
1797 INT nHeight, /* [in] Height of window */
1798 HWND hWndParent, /* [in] Handle to parent window */
1799 HINSTANCE hInstance, /* [in] Handle to application instance */
1800 LPARAM lParam) /* [in] Application-defined value */
1802 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1803 MDICREATESTRUCTW cs;
1805 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%p,%p,%ld)\n",
1806 debugstr_w(lpClassName), debugstr_w(lpWindowName), dwStyle, X, Y,
1807 nWidth, nHeight, hWndParent, hInstance, lParam);
1809 if (!pCi)
1811 ERR("bad hwnd for MDI-client: %p\n", hWndParent);
1812 return 0;
1814 cs.szClass = lpClassName;
1815 cs.szTitle = lpWindowName;
1816 cs.hOwner = hInstance;
1817 cs.x = X;
1818 cs.y = Y;
1819 cs.cx = nWidth;
1820 cs.cy = nHeight;
1821 cs.style = dwStyle;
1822 cs.lParam = lParam;
1824 return MDICreateChild(hWndParent, pCi, (MDICREATESTRUCTA *)&cs, TRUE);
1827 /**********************************************************************
1828 * TranslateMDISysAccel (USER32.@)
1830 BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1832 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1834 MDICLIENTINFO *ci = get_client_info( hwndClient );
1835 WPARAM wParam = 0;
1837 if (!ci || !IsWindowEnabled(ci->hwndActiveChild)) return 0;
1839 /* translate if the Ctrl key is down and Alt not. */
1841 if( (GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
1843 switch( msg->wParam )
1845 case VK_F6:
1846 case VK_TAB:
1847 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 ) ? SC_NEXTWINDOW : SC_PREVWINDOW;
1848 break;
1849 case VK_F4:
1850 case VK_RBUTTON:
1851 wParam = SC_CLOSE;
1852 break;
1853 default:
1854 return 0;
1856 TRACE("wParam = %04x\n", wParam);
1857 SendMessageW(ci->hwndActiveChild, WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
1858 return 1;
1861 return 0; /* failure */
1864 /***********************************************************************
1865 * CalcChildScroll (USER32.@)
1867 void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
1869 SCROLLINFO info;
1870 RECT childRect, clientRect;
1871 HWND *list;
1873 GetClientRect( hwnd, &clientRect );
1874 SetRectEmpty( &childRect );
1876 if ((list = WIN_ListChildren( hwnd )))
1878 int i;
1879 for (i = 0; list[i]; i++)
1881 DWORD style = GetWindowLongW( list[i], GWL_STYLE );
1882 if (style & WS_MAXIMIZE)
1884 HeapFree( GetProcessHeap(), 0, list );
1885 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1886 return;
1888 if (style & WS_VISIBLE)
1890 WND *pWnd = WIN_FindWndPtr( list[i] );
1891 UnionRect( &childRect, &pWnd->rectWindow, &childRect );
1892 WIN_ReleaseWndPtr( pWnd );
1895 HeapFree( GetProcessHeap(), 0, list );
1897 UnionRect( &childRect, &clientRect, &childRect );
1899 /* set common info values */
1900 info.cbSize = sizeof(info);
1901 info.fMask = SIF_POS | SIF_RANGE;
1903 /* set the specific */
1904 switch( scroll )
1906 case SB_BOTH:
1907 case SB_HORZ:
1908 info.nMin = childRect.left;
1909 info.nMax = childRect.right - clientRect.right;
1910 info.nPos = clientRect.left - childRect.left;
1911 SetScrollInfo(hwnd, scroll, &info, TRUE);
1912 if (scroll == SB_HORZ) break;
1913 /* fall through */
1914 case SB_VERT:
1915 info.nMin = childRect.top;
1916 info.nMax = childRect.bottom - clientRect.bottom;
1917 info.nPos = clientRect.top - childRect.top;
1918 SetScrollInfo(hwnd, scroll, &info, TRUE);
1919 break;
1924 /***********************************************************************
1925 * ScrollChildren (USER32.@)
1927 void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
1928 LPARAM lParam)
1930 INT newPos = -1;
1931 INT curPos, length, minPos, maxPos, shift;
1932 RECT rect;
1934 GetClientRect( hWnd, &rect );
1936 switch(uMsg)
1938 case WM_HSCROLL:
1939 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
1940 curPos = GetScrollPos(hWnd,SB_HORZ);
1941 length = (rect.right - rect.left) / 2;
1942 shift = GetSystemMetrics(SM_CYHSCROLL);
1943 break;
1944 case WM_VSCROLL:
1945 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
1946 curPos = GetScrollPos(hWnd,SB_VERT);
1947 length = (rect.bottom - rect.top) / 2;
1948 shift = GetSystemMetrics(SM_CXVSCROLL);
1949 break;
1950 default:
1951 return;
1954 switch( wParam )
1956 case SB_LINEUP:
1957 newPos = curPos - shift;
1958 break;
1959 case SB_LINEDOWN:
1960 newPos = curPos + shift;
1961 break;
1962 case SB_PAGEUP:
1963 newPos = curPos - length;
1964 break;
1965 case SB_PAGEDOWN:
1966 newPos = curPos + length;
1967 break;
1969 case SB_THUMBPOSITION:
1970 newPos = LOWORD(lParam);
1971 break;
1973 case SB_THUMBTRACK:
1974 return;
1976 case SB_TOP:
1977 newPos = minPos;
1978 break;
1979 case SB_BOTTOM:
1980 newPos = maxPos;
1981 break;
1982 case SB_ENDSCROLL:
1983 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
1984 return;
1987 if( newPos > maxPos )
1988 newPos = maxPos;
1989 else
1990 if( newPos < minPos )
1991 newPos = minPos;
1993 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
1995 if( uMsg == WM_VSCROLL )
1996 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
1997 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
1998 else
1999 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
2000 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2004 /******************************************************************************
2005 * CascadeWindows (USER32.@) Cascades MDI child windows
2007 * RETURNS
2008 * Success: Number of cascaded windows.
2009 * Failure: 0
2011 WORD WINAPI
2012 CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2013 UINT cKids, const HWND *lpKids)
2015 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
2016 return 0;
2020 /******************************************************************************
2021 * TileWindows (USER32.@) Tiles MDI child windows
2023 * RETURNS
2024 * Success: Number of tiled windows.
2025 * Failure: 0
2027 WORD WINAPI
2028 TileWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2029 UINT cKids, const HWND *lpKids)
2031 FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
2032 return 0;
2035 /************************************************************************
2036 * "More Windows..." functionality
2039 /* MDI_MoreWindowsDlgProc
2041 * This function will process the messages sent to the "More Windows..."
2042 * dialog.
2043 * Return values: 0 = cancel pressed
2044 * HWND = ok pressed or double-click in the list...
2048 static INT_PTR WINAPI MDI_MoreWindowsDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
2050 switch (iMsg)
2052 case WM_INITDIALOG:
2054 UINT widest = 0;
2055 UINT length;
2056 UINT i;
2057 MDICLIENTINFO *ci = get_client_info( (HWND)lParam );
2058 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2059 HWND *list, *sorted_list;
2061 if (!(list = WIN_ListChildren( (HWND)lParam ))) return TRUE;
2062 if (!(sorted_list = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
2063 sizeof(HWND) * ci->nActiveChildren )))
2065 HeapFree( GetProcessHeap(), 0, list );
2066 return FALSE;
2069 /* Fill the list, sorted by id... */
2070 for (i = 0; list[i]; i++)
2072 UINT id = GetWindowLongW( list[i], GWL_ID ) - ci->idFirstChild;
2073 if (id < ci->nActiveChildren) sorted_list[id] = list[i];
2075 HeapFree( GetProcessHeap(), 0, list );
2077 for (i = 0; i < ci->nActiveChildren; i++)
2079 WCHAR buffer[128];
2081 if (!GetWindowTextW( sorted_list[i], buffer, sizeof(buffer)/sizeof(WCHAR) ))
2082 continue;
2083 SendMessageW(hListBox, LB_ADDSTRING, 0, (LPARAM)buffer );
2084 SendMessageW(hListBox, LB_SETITEMDATA, i, (LPARAM)sorted_list[i] );
2085 length = strlenW(buffer); /* FIXME: should use GetTextExtentPoint */
2086 if (length > widest)
2087 widest = length;
2089 /* Make sure the horizontal scrollbar scrolls ok */
2090 SendMessageW(hListBox, LB_SETHORIZONTALEXTENT, widest * 6, 0);
2092 /* Set the current selection */
2093 SendMessageW(hListBox, LB_SETCURSEL, MDI_MOREWINDOWSLIMIT, 0);
2094 return TRUE;
2097 case WM_COMMAND:
2098 switch (LOWORD(wParam))
2100 default:
2101 if (HIWORD(wParam) != LBN_DBLCLK) break;
2102 /* fall through */
2103 case IDOK:
2105 /* windows are sorted by menu ID, so we must return the
2106 * window associated to the given id
2108 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2109 UINT index = SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
2110 LRESULT res = SendMessageW(hListBox, LB_GETITEMDATA, index, 0);
2111 EndDialog(hDlg, res);
2112 return TRUE;
2114 case IDCANCEL:
2115 EndDialog(hDlg, 0);
2116 return TRUE;
2118 break;
2120 return FALSE;
2125 * MDI_MoreWindowsDialog
2127 * Prompts the user with a listbox containing the opened
2128 * documents. The user can then choose a windows and click
2129 * on OK to set the current window to the one selected, or
2130 * CANCEL to cancel. The function returns a handle to the
2131 * selected window.
2134 static HWND MDI_MoreWindowsDialog(HWND hwnd)
2136 LPCVOID template;
2137 HRSRC hRes;
2138 HANDLE hDlgTmpl;
2140 hRes = FindResourceA(GetModuleHandleA("USER32"), "MDI_MOREWINDOWS", (LPSTR)RT_DIALOG);
2142 if (hRes == 0)
2143 return 0;
2145 hDlgTmpl = LoadResource(GetModuleHandleA("USER32"), hRes );
2147 if (hDlgTmpl == 0)
2148 return 0;
2150 template = LockResource( hDlgTmpl );
2152 if (template == 0)
2153 return 0;
2155 return (HWND) DialogBoxIndirectParamA(GetModuleHandleA("USER32"),
2156 (LPDLGTEMPLATEA) template,
2157 hwnd, MDI_MoreWindowsDlgProc, (LPARAM) hwnd);
2162 * MDI_SwapMenuItems
2164 * Will swap the menu IDs for the given 2 positions.
2165 * pos1 and pos2 are menu IDs
2170 static void MDI_SwapMenuItems(HWND parent, UINT pos1, UINT pos2)
2172 HWND *list;
2173 int i;
2175 if (!(list = WIN_ListChildren( parent ))) return;
2176 for (i = 0; list[i]; i++)
2178 UINT id = GetWindowLongW( list[i], GWL_ID );
2179 if (id == pos1) SetWindowLongW( list[i], GWL_ID, pos2 );
2180 else if (id == pos2) SetWindowLongW( list[i], GWL_ID, pos1 );
2182 HeapFree( GetProcessHeap(), 0, list );