The [windows] section is in win.ini not in ~/.wine/config.
[wine.git] / windows / mdi.c
blobe0fd58fc3d3990560bad4c878eb2085d995f2ffd
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 * Notes: Fairly complete implementation.
10 * Also, Excel and WinWord do _not_ use MDI so if you're trying
11 * to fix them look elsewhere.
13 * Notes on how the "More Windows..." is implemented:
15 * When we have more than 9 opened windows, a "More Windows..."
16 * option appears in the "Windows" menu. Each child window has
17 * a WND* associated with it, accesible via the children list of
18 * the parent window. This WND* has a wIDmenu member, which reflects
19 * the position of the child in the window list. For example, with
20 * 9 child windows, we could have the following pattern:
24 * Name of the child window pWndChild->wIDmenu
25 * Doc1 5000
26 * Doc2 5001
27 * Doc3 5002
28 * Doc4 5003
29 * Doc5 5004
30 * Doc6 5005
31 * Doc7 5006
32 * Doc8 5007
33 * Doc9 5008
36 * The "Windows" menu, as the "More windows..." dialog, are constructed
37 * in this order. If we add a child, we would have the following list:
40 * Name of the child window pWndChild->wIDmenu
41 * Doc1 5000
42 * Doc2 5001
43 * Doc3 5002
44 * Doc4 5003
45 * Doc5 5004
46 * Doc6 5005
47 * Doc7 5006
48 * Doc8 5007
49 * Doc9 5008
50 * Doc10 5009
52 * But only 5000 to 5008 would be displayed in the "Windows" menu. We want
53 * the last created child to be in the menu, so we swap the last child with
54 * the 9th... Doc9 will be accessible via the "More Windows..." option.
56 * Doc1 5000
57 * Doc2 5001
58 * Doc3 5002
59 * Doc4 5003
60 * Doc5 5004
61 * Doc6 5005
62 * Doc7 5006
63 * Doc8 5007
64 * Doc9 5009
65 * Doc10 5008
69 #include <stdlib.h>
70 #include <stdio.h>
71 #include <string.h>
72 #include <math.h>
74 #include "windef.h"
75 #include "winbase.h"
76 #include "wingdi.h"
77 #include "winuser.h"
78 #include "wine/unicode.h"
79 #include "win.h"
80 #include "heap.h"
81 #include "nonclient.h"
82 #include "controls.h"
83 #include "user.h"
84 #include "struct32.h"
85 #include "debugtools.h"
86 #include "dlgs.h"
88 DEFAULT_DEBUG_CHANNEL(mdi);
90 #define MDI_MAXLISTLENGTH 0x40
91 #define MDI_MAXTITLELENGTH 0xa1
93 #define MDI_NOFRAMEREPAINT 0
94 #define MDI_REPAINTFRAMENOW 1
95 #define MDI_REPAINTFRAME 2
97 #define WM_MDICALCCHILDSCROLL 0x10ac /* this is exactly what Windows uses */
99 /* "More Windows..." definitions */
100 #define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
101 option will appear under the Windows menu */
102 #define MDI_IDC_LISTBOX 100
103 #define MDI_IDS_MOREWINDOWS 13
105 #define MDIF_NEEDUPDATE 0x0001
107 typedef struct
109 UINT nActiveChildren;
110 HWND hwndChildMaximized;
111 HWND hwndActiveChild;
112 HMENU hWindowMenu;
113 UINT idFirstChild;
114 LPWSTR frameTitle;
115 UINT nTotalCreated;
116 UINT mdiFlags;
117 UINT sbRecalc; /* SB_xxx flags for scrollbar fixup */
118 } MDICLIENTINFO;
120 static HBITMAP hBmpClose = 0;
121 static HBITMAP hBmpRestore = 0;
123 /* ----------------- declarations ----------------- */
124 static void MDI_UpdateFrameText( HWND, HWND, BOOL, LPCWSTR);
125 static BOOL MDI_AugmentFrameMenu( HWND, HWND );
126 static BOOL MDI_RestoreFrameMenu( HWND, HWND );
127 static LONG MDI_ChildActivate( HWND, HWND );
129 static HWND MDI_MoreWindowsDialog(HWND);
130 static void MDI_SwapMenuItems(HWND, UINT, UINT);
131 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
132 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
134 /* -------- Miscellaneous service functions ----------
136 * MDI_GetChildByID
138 static HWND MDI_GetChildByID(HWND hwnd, UINT id)
140 HWND ret;
141 HWND *win_array;
142 int i;
144 if (!(win_array = WIN_ListChildren( hwnd ))) return 0;
145 for (i = 0; win_array[i]; i++)
147 if (GetWindowLongA( win_array[i], GWL_ID ) == id) break;
149 ret = win_array[i];
150 HeapFree( GetProcessHeap(), 0, win_array );
151 return ret;
154 static void MDI_PostUpdate(HWND hwnd, MDICLIENTINFO* ci, WORD recalc)
156 if( !(ci->mdiFlags & MDIF_NEEDUPDATE) )
158 ci->mdiFlags |= MDIF_NEEDUPDATE;
159 PostMessageA( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
161 ci->sbRecalc = recalc;
165 /*********************************************************************
166 * MDIClient class descriptor
168 const struct builtin_class_descr MDICLIENT_builtin_class =
170 "MDIClient", /* name */
171 CS_GLOBALCLASS, /* style */
172 MDIClientWndProcA, /* procA */
173 MDIClientWndProcW, /* procW */
174 sizeof(MDICLIENTINFO), /* extra */
175 IDC_ARROWA, /* cursor */
176 COLOR_APPWORKSPACE+1 /* brush */
180 static MDICLIENTINFO *get_client_info( HWND client )
182 MDICLIENTINFO *ret = NULL;
183 WND *win = WIN_FindWndPtr( client );
184 if (win)
186 if (win->cbWndExtra < sizeof(MDICLIENTINFO)) WARN( "%x is not an MDI client\n", client );
187 else ret = (MDICLIENTINFO *)win->wExtra;
188 WIN_ReleaseWndPtr( win );
190 return ret;
193 /**********************************************************************
194 * MDI_MenuModifyItem
196 static void MDI_MenuModifyItem( HWND client, HWND hWndChild )
198 MDICLIENTINFO *clientInfo = get_client_info( client );
199 WCHAR buffer[128];
200 UINT n, id;
202 if (!clientInfo || !clientInfo->hWindowMenu) return;
204 id = GetWindowLongA( hWndChild, GWL_ID );
205 if (id >= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT) return;
206 buffer[0] = '&';
207 buffer[1] = '1' + id - clientInfo->idFirstChild;
208 buffer[2] = ' ';
209 GetWindowTextW( hWndChild, buffer + 3, sizeof(buffer)/sizeof(WCHAR) - 3 );
211 n = GetMenuState(clientInfo->hWindowMenu, id, MF_BYCOMMAND);
212 ModifyMenuW(clientInfo->hWindowMenu, id, MF_BYCOMMAND | MF_STRING, id, buffer );
213 CheckMenuItem(clientInfo->hWindowMenu, id, n & MF_CHECKED);
216 /**********************************************************************
217 * MDI_MenuDeleteItem
219 static BOOL MDI_MenuDeleteItem( HWND client, HWND hWndChild )
221 WCHAR buffer[128];
222 static const WCHAR format[] = {'&','%','d',' ',0};
223 MDICLIENTINFO *clientInfo = get_client_info( client );
224 UINT index = 0,id,n;
226 if( !clientInfo->nActiveChildren || !clientInfo->hWindowMenu )
227 return FALSE;
229 id = GetWindowLongA( hWndChild, GWL_ID );
230 DeleteMenu(clientInfo->hWindowMenu,id,MF_BYCOMMAND);
232 /* walk the rest of MDI children to prevent gaps in the id
233 * sequence and in the menu child list */
235 for( index = id+1; index <= clientInfo->nActiveChildren +
236 clientInfo->idFirstChild; index++ )
238 HWND hwnd = MDI_GetChildByID(client,index);
239 if (!hwnd)
241 TRACE("no window for id=%i\n",index);
242 continue;
245 /* set correct id */
246 SetWindowLongW( hwnd, GWL_ID, GetWindowLongW( hwnd, GWL_ID ) - 1 );
248 n = wsprintfW(buffer, format ,index - clientInfo->idFirstChild);
249 GetWindowTextW( hwnd, buffer + n, sizeof(buffer)/sizeof(WCHAR) - n );
251 /* change menu if the current child is to be shown in the
252 * "Windows" menu
254 if (index <= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT)
255 ModifyMenuW(clientInfo->hWindowMenu ,index ,MF_BYCOMMAND | MF_STRING,
256 index - 1 , buffer );
259 /* We must restore the "More Windows..." option if there are enough children
261 if (clientInfo->nActiveChildren - 1 > MDI_MOREWINDOWSLIMIT)
263 WCHAR szTmp[50];
264 LoadStringW(GetModuleHandleA("USER32"), MDI_IDS_MOREWINDOWS, szTmp, sizeof(szTmp)/sizeof(szTmp[0]));
265 AppendMenuW(clientInfo->hWindowMenu, MF_STRING, clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT, szTmp);
267 return TRUE;
270 /**********************************************************************
271 * MDI_GetWindow
273 * returns "activateable" child different from the current or zero
275 static HWND MDI_GetWindow(MDICLIENTINFO *clientInfo, HWND hWnd, BOOL bNext,
276 DWORD dwStyleMask )
278 int i;
279 HWND *list;
280 HWND last = 0;
282 dwStyleMask |= WS_DISABLED | WS_VISIBLE;
283 if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
285 if (!(list = WIN_ListChildren( GetParent(hWnd) ))) return 0;
286 i = 0;
287 /* start from next after hWnd */
288 while (list[i] && list[i] != hWnd) i++;
289 if (list[i]) i++;
291 for ( ; list[i]; i++)
293 if (GetWindow( list[i], GW_OWNER )) continue;
294 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
295 last = list[i];
296 if (bNext) goto found;
298 /* now restart from the beginning */
299 for (i = 0; list[i] && list[i] != hWnd; i++)
301 if (GetWindow( list[i], GW_OWNER )) continue;
302 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
303 last = list[i];
304 if (bNext) goto found;
306 found:
307 HeapFree( GetProcessHeap(), 0, list );
308 return last;
311 /**********************************************************************
312 * MDI_CalcDefaultChildPos
314 * It seems that the default height is about 2/3 of the client rect
316 static void MDI_CalcDefaultChildPos( HWND hwnd, WORD n, LPPOINT lpPos, INT delta)
318 INT nstagger;
319 RECT rect;
320 INT spacing = GetSystemMetrics(SM_CYCAPTION) +
321 GetSystemMetrics(SM_CYFRAME) - 1;
323 GetClientRect( hwnd, &rect );
324 if( rect.bottom - rect.top - delta >= spacing )
325 rect.bottom -= delta;
327 nstagger = (rect.bottom - rect.top)/(3 * spacing);
328 lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
329 lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
330 lpPos[0].x = lpPos[0].y = spacing * (n%(nstagger+1));
333 /**********************************************************************
334 * MDISetMenu
336 static LRESULT MDISetMenu( HWND hwnd, HMENU hmenuFrame,
337 HMENU hmenuWindow)
339 MDICLIENTINFO *ci;
340 HWND hwndFrame = GetParent(hwnd);
341 HMENU oldFrameMenu = GetMenu(hwndFrame);
343 TRACE("%04x %04x %04x\n",
344 hwnd, hmenuFrame, hmenuWindow);
346 if (hmenuFrame && !IsMenu(hmenuFrame))
348 WARN("hmenuFrame is not a menu handle\n");
349 return 0L;
352 if (hmenuWindow && !IsMenu(hmenuWindow))
354 WARN("hmenuWindow is not a menu handle\n");
355 return 0L;
358 if (!(ci = get_client_info( hwnd ))) return 0;
360 if( ci->hwndChildMaximized && hmenuFrame && hmenuFrame!=oldFrameMenu )
361 MDI_RestoreFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
363 if( hmenuWindow && ci->hWindowMenu && hmenuWindow!=ci->hWindowMenu )
365 /* delete menu items from ci->hWindowMenu
366 * and add them to hmenuWindow */
368 INT i = GetMenuItemCount(ci->hWindowMenu) - 1;
369 INT pos = GetMenuItemCount(hmenuWindow) + 1;
371 AppendMenuA( hmenuWindow, MF_SEPARATOR, 0, NULL);
373 if( ci->nActiveChildren )
375 INT j;
376 LPWSTR buffer = NULL;
377 MENUITEMINFOW mii;
378 INT nbWindowsMenuItems; /* num of documents shown + "More Windows..." if present */
380 if (ci->nActiveChildren <= MDI_MOREWINDOWSLIMIT)
381 nbWindowsMenuItems = ci->nActiveChildren;
382 else
383 nbWindowsMenuItems = MDI_MOREWINDOWSLIMIT + 1;
385 j = i - nbWindowsMenuItems + 1;
387 for( ; i >= j ; i-- )
389 memset(&mii, 0, sizeof(mii));
390 mii.cbSize = sizeof(mii);
391 mii.fMask = MIIM_CHECKMARKS | MIIM_DATA | MIIM_ID | MIIM_STATE
392 | MIIM_SUBMENU | MIIM_TYPE | MIIM_BITMAP;
394 GetMenuItemInfoW(ci->hWindowMenu, i, TRUE, &mii);
395 if(mii.cch) { /* Menu is MFT_STRING */
396 mii.cch++; /* add room for '\0' */
397 buffer = HeapAlloc(GetProcessHeap(), 0,
398 mii.cch * sizeof(WCHAR));
399 mii.dwTypeData = buffer;
400 GetMenuItemInfoW(ci->hWindowMenu, i, TRUE, &mii);
402 DeleteMenu(ci->hWindowMenu, i, MF_BYPOSITION);
403 InsertMenuItemW(hmenuWindow, pos, TRUE, &mii);
404 if(buffer) {
405 HeapFree(GetProcessHeap(), 0, buffer);
406 buffer = NULL;
411 /* remove separator */
412 DeleteMenu(ci->hWindowMenu, i, MF_BYPOSITION);
414 ci->hWindowMenu = hmenuWindow;
417 if (hmenuFrame)
419 SetMenu(hwndFrame, hmenuFrame);
420 if( hmenuFrame!=oldFrameMenu )
422 if( ci->hwndChildMaximized )
423 MDI_AugmentFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
424 return oldFrameMenu;
427 else
429 HMENU menu = GetMenu( GetParent(hwnd) );
430 INT nItems = GetMenuItemCount(menu) - 1;
431 UINT iId = GetMenuItemID(menu,nItems) ;
433 if( !(iId == SC_RESTORE || iId == SC_CLOSE) )
435 /* SetMenu() may already have been called, meaning that this window
436 * already has its menu. But they may have done a SetMenu() on
437 * an MDI window, and called MDISetMenu() after the fact, meaning
438 * that the "if" to this "else" wouldn't catch the need to
439 * augment the frame menu.
441 if( ci->hwndChildMaximized )
442 MDI_AugmentFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
445 return 0;
448 /**********************************************************************
449 * MDIRefreshMenu
451 static LRESULT MDIRefreshMenu( HWND hwnd, HMENU hmenuFrame,
452 HMENU hmenuWindow)
454 HWND hwndFrame = GetParent(hwnd);
455 HMENU oldFrameMenu = GetMenu(hwndFrame);
457 TRACE("%04x %04x %04x\n",
458 hwnd, hmenuFrame, hmenuWindow);
460 FIXME("partially function stub\n");
462 return oldFrameMenu;
466 /* ------------------ MDI child window functions ---------------------- */
469 /**********************************************************************
470 * MDICreateChild
472 static HWND MDICreateChild( HWND parent, MDICLIENTINFO *ci,
473 LPMDICREATESTRUCTA cs, BOOL unicode )
475 POINT pos[2];
476 DWORD style = cs->style | (WS_CHILD | WS_CLIPSIBLINGS);
477 HWND hwnd, hwndMax = 0;
478 UINT wIDmenu = ci->idFirstChild + ci->nActiveChildren;
479 WND *wndParent;
480 static const WCHAR lpstrDef[] = {'j','u','n','k','!',0};
482 TRACE("origin %i,%i - dim %i,%i, style %08lx\n",
483 cs->x, cs->y, cs->cx, cs->cy, cs->style);
484 /* calculate placement */
485 MDI_CalcDefaultChildPos(parent, ci->nTotalCreated++, pos, 0);
487 if (cs->cx == CW_USEDEFAULT || !cs->cx) cs->cx = pos[1].x;
488 if (cs->cy == CW_USEDEFAULT || !cs->cy) cs->cy = pos[1].y;
490 if( cs->x == CW_USEDEFAULT )
492 cs->x = pos[0].x;
493 cs->y = pos[0].y;
496 /* restore current maximized child */
497 if( (style & WS_VISIBLE) && ci->hwndChildMaximized )
499 TRACE("Restoring current maximized child %04x\n", ci->hwndChildMaximized);
500 if( style & WS_MAXIMIZE )
501 SendMessageW(parent, WM_SETREDRAW, FALSE, 0L);
502 hwndMax = ci->hwndChildMaximized;
503 ShowWindow( hwndMax, SW_SHOWNOACTIVATE );
504 if( style & WS_MAXIMIZE )
505 SendMessageW(parent, WM_SETREDRAW, TRUE, 0L);
508 if (ci->nActiveChildren <= MDI_MOREWINDOWSLIMIT)
509 /* this menu is needed to set a check mark in MDI_ChildActivate */
510 if (ci->hWindowMenu != 0)
511 AppendMenuW(ci->hWindowMenu, MF_STRING, wIDmenu, lpstrDef);
513 ci->nActiveChildren++;
515 /* fix window style */
516 wndParent = WIN_FindWndPtr( parent );
517 if( !(wndParent->dwStyle & MDIS_ALLCHILDSTYLES) )
519 TRACE("MDIS_ALLCHILDSTYLES is missing, fixing window style\n");
520 style &= (WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZE | WS_MAXIMIZE |
521 WS_CLIPCHILDREN | WS_DISABLED | WS_VSCROLL | WS_HSCROLL );
522 style |= (WS_VISIBLE | WS_OVERLAPPEDWINDOW);
525 if( wndParent->flags & WIN_ISWIN32 )
527 WIN_ReleaseWndPtr( wndParent );
528 if(unicode)
530 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)cs;
531 hwnd = CreateWindowW( csW->szClass, csW->szTitle, style,
532 csW->x, csW->y, csW->cx, csW->cy, parent,
533 (HMENU)wIDmenu, csW->hOwner, csW );
535 else
536 hwnd = CreateWindowA( cs->szClass, cs->szTitle, style,
537 cs->x, cs->y, cs->cx, cs->cy, parent,
538 (HMENU)wIDmenu, cs->hOwner, cs );
540 else
542 MDICREATESTRUCT16 *cs16;
543 LPSTR title, cls;
545 WIN_ReleaseWndPtr( wndParent );
546 cs16 = SEGPTR_NEW(MDICREATESTRUCT16);
547 STRUCT32_MDICREATESTRUCT32Ato16( cs, cs16 );
548 title = SEGPTR_STRDUP( cs->szTitle );
549 cls = SEGPTR_STRDUP( cs->szClass );
550 cs16->szTitle = SEGPTR_GET(title);
551 cs16->szClass = SEGPTR_GET(cls);
553 hwnd = CreateWindow16( cs->szClass, cs->szTitle, style,
554 cs16->x, cs16->y, cs16->cx, cs16->cy, parent,
555 (HMENU)wIDmenu, cs16->hOwner,
556 (LPVOID)SEGPTR_GET(cs16) );
557 SEGPTR_FREE( title );
558 SEGPTR_FREE( cls );
559 SEGPTR_FREE( cs16 );
562 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
564 if (hwnd)
566 /* All MDI child windows have the WS_EX_MDICHILD style */
567 SetWindowLongW( hwnd, GWL_EXSTYLE, GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_MDICHILD );
569 /* If we have more than 9 windows, we must insert the new one at the
570 * 9th position in order to see it in the "Windows" menu
572 if (ci->nActiveChildren > MDI_MOREWINDOWSLIMIT)
573 MDI_SwapMenuItems( parent, GetWindowLongW( hwnd, GWL_ID ),
574 ci->idFirstChild + MDI_MOREWINDOWSLIMIT - 1);
576 MDI_MenuModifyItem(parent, hwnd);
578 /* Have we hit the "More Windows..." limit? If so, we must
579 * add a "More Windows..." option
581 if (ci->nActiveChildren == MDI_MOREWINDOWSLIMIT + 1)
583 WCHAR szTmp[50];
584 LoadStringW(GetModuleHandleA("USER32"), MDI_IDS_MOREWINDOWS, szTmp, sizeof(szTmp)/sizeof(szTmp[0]));
586 ModifyMenuW(ci->hWindowMenu,
587 ci->idFirstChild + MDI_MOREWINDOWSLIMIT,
588 MF_BYCOMMAND | MF_STRING,
589 ci->idFirstChild + MDI_MOREWINDOWSLIMIT,
590 szTmp);
593 if( IsIconic(hwnd) && ci->hwndActiveChild )
595 TRACE("Minimizing created MDI child %04x\n", hwnd);
596 ShowWindow( hwnd, SW_SHOWMINNOACTIVE );
598 else
600 /* WS_VISIBLE is clear if a) the MDI client has
601 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
602 * MDICreateStruct. If so the created window is not shown nor
603 * activated.
605 if (IsWindowVisible(hwnd)) ShowWindow(hwnd, SW_SHOW);
607 TRACE("created child - %04x\n",hwnd);
609 else
611 ci->nActiveChildren--;
612 DeleteMenu(ci->hWindowMenu,wIDmenu,MF_BYCOMMAND);
613 if( IsWindow(hwndMax) )
614 ShowWindow(hwndMax, SW_SHOWMAXIMIZED);
617 return hwnd;
620 /**********************************************************************
621 * MDI_ChildGetMinMaxInfo
623 * Note: The rule here is that client rect of the maximized MDI child
624 * is equal to the client rect of the MDI client window.
626 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
628 RECT rect;
630 GetClientRect( client, &rect );
631 AdjustWindowRectEx( &rect, GetWindowLongW( hwnd, GWL_STYLE ),
632 0, GetWindowLongW( hwnd, GWL_EXSTYLE ));
634 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
635 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
637 lpMinMax->ptMaxPosition.x = rect.left;
638 lpMinMax->ptMaxPosition.y = rect.top;
640 TRACE("max rect (%i,%i - %i, %i)\n",
641 rect.left,rect.top,rect.right,rect.bottom);
644 /**********************************************************************
645 * MDI_SwitchActiveChild
647 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
648 * being activated
650 static void MDI_SwitchActiveChild( HWND clientHwnd, HWND childHwnd,
651 BOOL bNextWindow )
653 HWND hwndTo = 0;
654 HWND hwndPrev = 0;
655 MDICLIENTINFO *ci = get_client_info( clientHwnd );
657 hwndTo = MDI_GetWindow(ci, childHwnd, bNextWindow, 0);
659 TRACE("from %04x, to %04x\n",childHwnd,hwndTo);
661 if ( !hwndTo ) return; /* no window to switch to */
663 hwndPrev = ci->hwndActiveChild;
665 if ( hwndTo != hwndPrev )
667 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0,
668 SWP_NOMOVE | SWP_NOSIZE );
670 if( bNextWindow && hwndPrev )
671 SetWindowPos( hwndPrev, HWND_BOTTOM, 0, 0, 0, 0,
672 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
677 /**********************************************************************
678 * MDIDestroyChild
680 static LRESULT MDIDestroyChild( HWND parent, MDICLIENTINFO *ci,
681 HWND child, BOOL flagDestroy )
683 if( child == ci->hwndActiveChild )
685 MDI_SwitchActiveChild(parent, child, TRUE);
687 if( child == ci->hwndActiveChild )
689 ShowWindow( child, SW_HIDE);
690 if( child == ci->hwndChildMaximized )
692 HWND frame = GetParent(parent);
693 MDI_RestoreFrameMenu( frame, child );
694 ci->hwndChildMaximized = 0;
695 MDI_UpdateFrameText( frame, parent, TRUE, NULL);
698 MDI_ChildActivate(parent, 0);
702 MDI_MenuDeleteItem(parent, child);
704 ci->nActiveChildren--;
706 TRACE("child destroyed - %04x\n",child);
708 if (flagDestroy)
710 MDI_PostUpdate(GetParent(child), ci, SB_BOTH+1);
711 DestroyWindow(child);
713 return 0;
717 /**********************************************************************
718 * MDI_ChildActivate
720 * Note: hWndChild is NULL when last child is being destroyed
722 static LONG MDI_ChildActivate( HWND client, HWND child )
724 MDICLIENTINFO *clientInfo = get_client_info( client );
725 HWND prevActiveWnd = clientInfo->hwndActiveChild;
726 BOOL isActiveFrameWnd;
728 if (!IsWindowEnabled( child )) return 0;
730 /* Don't activate if it is already active. Might happen
731 since ShowWindow DOES activate MDI children */
732 if (clientInfo->hwndActiveChild == child) return 0;
734 TRACE("%04x\n", child);
736 isActiveFrameWnd = (GetActiveWindow() == GetParent(client));
738 /* deactivate prev. active child */
739 if(prevActiveWnd)
741 SetWindowLongA( prevActiveWnd, GWL_STYLE,
742 GetWindowLongA( prevActiveWnd, GWL_STYLE ) | WS_SYSMENU );
743 SendMessageA( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
744 SendMessageA( prevActiveWnd, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child);
745 /* uncheck menu item */
746 if( clientInfo->hWindowMenu )
748 UINT prevID = GetWindowLongA( prevActiveWnd, GWL_ID );
750 if (prevID - clientInfo->idFirstChild < MDI_MOREWINDOWSLIMIT)
751 CheckMenuItem( clientInfo->hWindowMenu, prevID, 0);
752 else
753 CheckMenuItem( clientInfo->hWindowMenu,
754 clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1, 0);
758 /* set appearance */
759 if (clientInfo->hwndChildMaximized && clientInfo->hwndChildMaximized != child)
761 if( child )
763 clientInfo->hwndActiveChild = child;
764 ShowWindow( child, SW_SHOWMAXIMIZED);
766 else ShowWindow( clientInfo->hwndActiveChild, SW_SHOWNORMAL );
769 clientInfo->hwndActiveChild = child;
771 /* check if we have any children left */
772 if( !child )
774 if( isActiveFrameWnd )
775 SetFocus( client );
776 return 0;
779 /* check menu item */
780 if( clientInfo->hWindowMenu )
782 UINT id = GetWindowLongA( child, GWL_ID );
783 /* The window to be activated must be displayed in the "Windows" menu */
784 if (id >= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT)
786 MDI_SwapMenuItems( GetParent(child),
787 id, clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1);
788 id = clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1;
789 MDI_MenuModifyItem( GetParent(child), child );
792 CheckMenuItem(clientInfo->hWindowMenu, id, MF_CHECKED);
794 /* bring active child to the top */
795 SetWindowPos( child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
797 if( isActiveFrameWnd )
799 SendMessageA( child, WM_NCACTIVATE, TRUE, 0L);
800 if( GetFocus() == client )
801 SendMessageA( client, WM_SETFOCUS, (WPARAM)client, 0L );
802 else
803 SetFocus( client );
805 SendMessageA( child, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child );
806 return TRUE;
809 /* -------------------- MDI client window functions ------------------- */
811 /**********************************************************************
812 * CreateMDIMenuBitmap
814 static HBITMAP CreateMDIMenuBitmap(void)
816 HDC hDCSrc = CreateCompatibleDC(0);
817 HDC hDCDest = CreateCompatibleDC(hDCSrc);
818 HBITMAP hbClose = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_CLOSE) );
819 HBITMAP hbCopy;
820 HBITMAP hobjSrc, hobjDest;
822 hobjSrc = SelectObject(hDCSrc, hbClose);
823 hbCopy = CreateCompatibleBitmap(hDCSrc,GetSystemMetrics(SM_CXSIZE),GetSystemMetrics(SM_CYSIZE));
824 hobjDest = SelectObject(hDCDest, hbCopy);
826 BitBlt(hDCDest, 0, 0, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE),
827 hDCSrc, GetSystemMetrics(SM_CXSIZE), 0, SRCCOPY);
829 SelectObject(hDCSrc, hobjSrc);
830 DeleteObject(hbClose);
831 DeleteDC(hDCSrc);
833 hobjSrc = SelectObject( hDCDest, GetStockObject(BLACK_PEN) );
835 MoveToEx( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, 0, NULL );
836 LineTo( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, GetSystemMetrics(SM_CYSIZE) - 1);
838 SelectObject(hDCDest, hobjSrc );
839 SelectObject(hDCDest, hobjDest);
840 DeleteDC(hDCDest);
842 return hbCopy;
845 /**********************************************************************
846 * MDICascade
848 static LONG MDICascade( HWND client, MDICLIENTINFO *ci )
850 HWND *win_array;
851 BOOL has_icons = FALSE;
852 int i, total;
854 if (ci->hwndChildMaximized)
855 SendMessageA( client, WM_MDIRESTORE,
856 (WPARAM)ci->hwndChildMaximized, 0);
858 if (ci->nActiveChildren == 0) return 0;
860 if (!(win_array = WIN_ListChildren( client ))) return 0;
862 /* remove all the windows we don't want */
863 for (i = total = 0; win_array[i]; i++)
865 if (!IsWindowVisible( win_array[i] )) continue;
866 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows */
867 if (IsIconic( win_array[i] ))
869 has_icons = TRUE;
870 continue;
872 win_array[total++] = win_array[i];
874 win_array[total] = 0;
876 if (total)
878 INT delta = 0, n = 0, i;
879 POINT pos[2];
880 if (has_icons) delta = GetSystemMetrics(SM_CYICONSPACING) + GetSystemMetrics(SM_CYICON);
882 /* walk the list (backwards) and move windows */
883 for (i = total - 1; i >= 0; i--)
885 TRACE("move %04x to (%ld,%ld) size [%ld,%ld]\n",
886 win_array[i], pos[0].x, pos[0].y, pos[1].x, pos[1].y);
888 MDI_CalcDefaultChildPos(client, n++, pos, delta);
889 SetWindowPos( win_array[i], 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
890 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
893 HeapFree( GetProcessHeap(), 0, win_array );
895 if (has_icons) ArrangeIconicWindows( client );
896 return 0;
899 /**********************************************************************
900 * MDITile
902 static void MDITile( HWND client, MDICLIENTINFO *ci, WPARAM wParam )
904 HWND *win_array;
905 int i, total;
906 BOOL has_icons = FALSE;
908 if (ci->hwndChildMaximized)
909 SendMessageA( client, WM_MDIRESTORE, (WPARAM)ci->hwndChildMaximized, 0);
911 if (ci->nActiveChildren == 0) return;
913 if (!(win_array = WIN_ListChildren( client ))) return;
915 /* remove all the windows we don't want */
916 for (i = total = 0; win_array[i]; i++)
918 if (!IsWindowVisible( win_array[i] )) continue;
919 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows (icon titles) */
920 if (IsIconic( win_array[i] ))
922 has_icons = TRUE;
923 continue;
925 if ((wParam & MDITILE_SKIPDISABLED) && !IsWindowEnabled( win_array[i] )) continue;
926 win_array[total++] = win_array[i];
928 win_array[total] = 0;
930 TRACE("%u windows to tile\n", total);
932 if (total)
934 HWND *pWnd = win_array;
935 RECT rect;
936 int x, y, xsize, ysize;
937 int rows, columns, r, c, i;
939 GetClientRect(client,&rect);
940 rows = (int) sqrt((double)total);
941 columns = total / rows;
943 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
945 i = rows;
946 rows = columns; /* exchange r and c */
947 columns = i;
950 if (has_icons)
952 y = rect.bottom - 2 * GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
953 rect.bottom = ( y - GetSystemMetrics(SM_CYICON) < rect.top )? rect.bottom: y;
956 ysize = rect.bottom / rows;
957 xsize = rect.right / columns;
959 for (x = i = 0, c = 1; c <= columns && *pWnd; c++)
961 if (c == columns)
963 rows = total - i;
964 ysize = rect.bottom / rows;
967 y = 0;
968 for (r = 1; r <= rows && *pWnd; r++, i++)
970 SetWindowPos(*pWnd, 0, x, y, xsize, ysize,
971 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
972 y += ysize;
973 pWnd++;
975 x += xsize;
978 HeapFree( GetProcessHeap(), 0, win_array );
979 if (has_icons) ArrangeIconicWindows( client );
982 /* ----------------------- Frame window ---------------------------- */
985 /**********************************************************************
986 * MDI_AugmentFrameMenu
988 static BOOL MDI_AugmentFrameMenu( HWND frame, HWND hChild )
990 HMENU menu = GetMenu( frame );
991 WND* child = WIN_FindWndPtr(hChild);
992 HMENU hSysPopup = 0;
993 HBITMAP hSysMenuBitmap = 0;
995 TRACE("frame %04x,child %04x\n",frame,hChild);
997 if( !menu || !child->hSysMenu )
999 WIN_ReleaseWndPtr(child);
1000 return 0;
1002 WIN_ReleaseWndPtr(child);
1004 /* create a copy of sysmenu popup and insert it into frame menu bar */
1006 if (!(hSysPopup = LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU")))
1007 return 0;
1009 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1010 SC_MINIMIZE, (LPSTR)(DWORD)HBMMENU_MBAR_MINIMIZE ) ;
1011 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1012 SC_RESTORE, (LPSTR)(DWORD)HBMMENU_MBAR_RESTORE );
1014 /* In Win 95 look, the system menu is replaced by the child icon */
1016 if(TWEAK_WineLook > WIN31_LOOK)
1018 HICON hIcon = GetClassLongA(hChild, GCL_HICONSM);
1019 if (!hIcon)
1020 hIcon = GetClassLongA(hChild, GCL_HICON);
1021 if (hIcon)
1023 HDC hMemDC;
1024 HBITMAP hBitmap, hOldBitmap;
1025 HBRUSH hBrush;
1026 HDC hdc = GetDC(hChild);
1028 if (hdc)
1030 int cx, cy;
1031 cx = GetSystemMetrics(SM_CXSMICON);
1032 cy = GetSystemMetrics(SM_CYSMICON);
1033 hMemDC = CreateCompatibleDC(hdc);
1034 hBitmap = CreateCompatibleBitmap(hdc, cx, cy);
1035 hOldBitmap = SelectObject(hMemDC, hBitmap);
1036 SetMapMode(hMemDC, MM_TEXT);
1037 hBrush = CreateSolidBrush(GetSysColor(COLOR_MENU));
1038 DrawIconEx(hMemDC, 0, 0, hIcon, cx, cy, 0, hBrush, DI_NORMAL);
1039 SelectObject (hMemDC, hOldBitmap);
1040 DeleteObject(hBrush);
1041 DeleteDC(hMemDC);
1042 ReleaseDC(hChild, hdc);
1043 hSysMenuBitmap = hBitmap;
1047 else
1048 hSysMenuBitmap = hBmpClose;
1050 if( !InsertMenuA(menu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
1051 hSysPopup, (LPSTR)(DWORD)hSysMenuBitmap))
1053 TRACE("not inserted\n");
1054 DestroyMenu(hSysPopup);
1055 return 0;
1058 /* The close button is only present in Win 95 look */
1059 if(TWEAK_WineLook > WIN31_LOOK)
1061 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1062 SC_CLOSE, (LPSTR)(DWORD)HBMMENU_MBAR_CLOSE );
1065 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
1066 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
1067 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
1068 SetMenuDefaultItem(hSysPopup, SC_CLOSE, FALSE);
1070 /* redraw menu */
1071 DrawMenuBar(frame);
1073 return 1;
1076 /**********************************************************************
1077 * MDI_RestoreFrameMenu
1079 static BOOL MDI_RestoreFrameMenu( HWND frame, HWND hChild )
1081 MENUITEMINFOW menuInfo;
1082 HMENU menu = GetMenu( frame );
1083 INT nItems = GetMenuItemCount(menu) - 1;
1084 UINT iId = GetMenuItemID(menu,nItems) ;
1086 TRACE("frame %04x,child %04x,nIt=%d,iId=%d\n",frame,hChild,nItems,iId);
1088 if(!(iId == SC_RESTORE || iId == SC_CLOSE) )
1089 return 0;
1092 * Remove the system menu, If that menu is the icon of the window
1093 * as it is in win95, we have to delete the bitmap.
1095 memset(&menuInfo, 0, sizeof(menuInfo));
1096 menuInfo.cbSize = sizeof(menuInfo);
1097 menuInfo.fMask = MIIM_DATA | MIIM_TYPE;
1099 GetMenuItemInfoW(menu,
1101 TRUE,
1102 &menuInfo);
1104 RemoveMenu(menu,0,MF_BYPOSITION);
1106 if ( (menuInfo.fType & MFT_BITMAP) &&
1107 (LOWORD(menuInfo.dwTypeData)!=0) &&
1108 (LOWORD(menuInfo.dwTypeData)!=hBmpClose) )
1110 DeleteObject((HBITMAP)LOWORD(menuInfo.dwTypeData));
1113 if(TWEAK_WineLook > WIN31_LOOK)
1115 /* close */
1116 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1118 /* restore */
1119 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1120 /* minimize */
1121 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1123 DrawMenuBar(frame);
1125 return 1;
1129 /**********************************************************************
1130 * MDI_UpdateFrameText
1132 * used when child window is maximized/restored
1134 * Note: lpTitle can be NULL
1136 static void MDI_UpdateFrameText( HWND frame, HWND hClient,
1137 BOOL repaint, LPCWSTR lpTitle )
1139 WCHAR lpBuffer[MDI_MAXTITLELENGTH+1];
1140 MDICLIENTINFO *ci = get_client_info( hClient );
1142 TRACE("repaint %i, frameText %s\n", repaint, debugstr_w(lpTitle));
1144 if (!ci) return;
1146 if (!lpTitle && !ci->frameTitle) /* first time around, get title from the frame window */
1148 GetWindowTextW( frame, lpBuffer, sizeof(lpBuffer)/sizeof(WCHAR) );
1149 lpTitle = lpBuffer;
1152 /* store new "default" title if lpTitle is not NULL */
1153 if (lpTitle)
1155 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1156 if ((ci->frameTitle = HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle)+1)*sizeof(WCHAR))))
1157 strcpyW( ci->frameTitle, lpTitle );
1160 if (ci->frameTitle)
1162 if (ci->hwndChildMaximized)
1164 /* combine frame title and child title if possible */
1166 static const WCHAR lpBracket[] = {' ','-',' ','[',0};
1167 static const WCHAR lpBracket2[] = {']',0};
1168 int i_frame_text_length = strlenW(ci->frameTitle);
1170 lstrcpynW( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
1172 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
1174 strcatW( lpBuffer, lpBracket );
1175 if (GetWindowTextW( ci->hwndChildMaximized, lpBuffer + i_frame_text_length + 4,
1176 MDI_MAXTITLELENGTH - i_frame_text_length - 5 ))
1177 strcatW( lpBuffer, lpBracket2 );
1178 else
1179 lpBuffer[i_frame_text_length] = 0; /* remove bracket */
1182 else
1184 lstrcpynW(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH+1 );
1187 else
1188 lpBuffer[0] = '\0';
1190 DefWindowProcW( frame, WM_SETTEXT, 0, (LPARAM)lpBuffer );
1191 if( repaint == MDI_REPAINTFRAME)
1192 SetWindowPos( frame, 0,0,0,0,0, SWP_FRAMECHANGED |
1193 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
1197 /* ----------------------------- Interface ---------------------------- */
1200 /**********************************************************************
1201 * MDIClientWndProc_common
1203 static LRESULT MDIClientWndProc_common( HWND hwnd, UINT message,
1204 WPARAM wParam, LPARAM lParam, BOOL unicode )
1206 MDICLIENTINFO *ci;
1208 if (!(ci = get_client_info( hwnd ))) return 0;
1210 switch (message)
1212 case WM_CREATE:
1214 RECT rect;
1215 /* Since we are using only cs->lpCreateParams, we can safely
1216 * cast to LPCREATESTRUCTA here */
1217 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
1218 WND *wndPtr = WIN_FindWndPtr( hwnd );
1220 /* Translation layer doesn't know what's in the cs->lpCreateParams
1221 * so we have to keep track of what environment we're in. */
1223 if( wndPtr->flags & WIN_ISWIN32 )
1225 #define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1226 ci->hWindowMenu = ccs->hWindowMenu;
1227 ci->idFirstChild = ccs->idFirstChild;
1228 #undef ccs
1230 else
1232 LPCLIENTCREATESTRUCT16 ccs = MapSL((SEGPTR)cs->lpCreateParams);
1233 ci->hWindowMenu = ccs->hWindowMenu;
1234 ci->idFirstChild = ccs->idFirstChild;
1236 WIN_ReleaseWndPtr( wndPtr );
1238 ci->hwndChildMaximized = 0;
1239 ci->nActiveChildren = 0;
1240 ci->nTotalCreated = 0;
1241 ci->frameTitle = NULL;
1242 ci->mdiFlags = 0;
1243 SetWindowLongW( hwnd, GWL_STYLE, GetWindowLongW(hwnd,GWL_STYLE) | WS_CLIPCHILDREN );
1245 if (!hBmpClose)
1247 hBmpClose = CreateMDIMenuBitmap();
1248 hBmpRestore = LoadBitmapW( 0, MAKEINTRESOURCEW(OBM_RESTORE) );
1251 if (ci->hWindowMenu != 0)
1252 AppendMenuW( ci->hWindowMenu, MF_SEPARATOR, 0, NULL );
1254 GetClientRect( GetParent(hwnd), &rect);
1255 MoveWindow( hwnd, 0, 0, rect.right, rect.bottom, FALSE );
1257 MDI_UpdateFrameText( GetParent(hwnd), hwnd, MDI_NOFRAMEREPAINT, NULL);
1259 TRACE("Client created - hwnd = %04x, idFirst = %u\n",
1260 hwnd, ci->idFirstChild );
1261 return 0;
1264 case WM_DESTROY:
1266 INT nItems;
1267 if( ci->hwndChildMaximized )
1268 MDI_RestoreFrameMenu( GetParent(hwnd), ci->hwndChildMaximized);
1269 if((ci->hWindowMenu != 0) &&
1270 (nItems = GetMenuItemCount(ci->hWindowMenu)) > 0)
1272 ci->idFirstChild = nItems - 1;
1273 ci->nActiveChildren++; /* to delete a separator */
1274 while( ci->nActiveChildren-- )
1275 DeleteMenu(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
1277 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1278 return 0;
1281 case WM_MDIACTIVATE:
1282 if( ci->hwndActiveChild != (HWND)wParam )
1283 SetWindowPos((HWND)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
1284 return 0;
1286 case WM_MDICASCADE:
1287 return MDICascade(hwnd, ci);
1289 case WM_MDICREATE:
1290 if (lParam) return MDICreateChild( hwnd, ci,
1291 (MDICREATESTRUCTA *)lParam, unicode );
1292 else return 0;
1294 case WM_MDIDESTROY:
1295 return MDIDestroyChild( hwnd, ci, (HWND)wParam, TRUE );
1297 case WM_MDIGETACTIVE:
1298 if (lParam) *(BOOL *)lParam = (ci->hwndChildMaximized > 0);
1299 return ci->hwndActiveChild;
1301 case WM_MDIICONARRANGE:
1302 ci->mdiFlags |= MDIF_NEEDUPDATE;
1303 ArrangeIconicWindows( hwnd );
1304 ci->sbRecalc = SB_BOTH+1;
1305 SendMessageW( hwnd, WM_MDICALCCHILDSCROLL, 0, 0 );
1306 return 0;
1308 case WM_MDIMAXIMIZE:
1309 ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1310 return 0;
1312 case WM_MDINEXT: /* lParam != 0 means previous window */
1313 MDI_SwitchActiveChild( hwnd, (HWND)wParam, !lParam );
1314 break;
1316 case WM_MDIRESTORE:
1317 SendMessageW( (HWND)wParam, WM_SYSCOMMAND, SC_RESTORE, 0);
1318 return 0;
1320 case WM_MDISETMENU:
1321 return MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1323 case WM_MDIREFRESHMENU:
1324 return MDIRefreshMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1326 case WM_MDITILE:
1327 ci->mdiFlags |= MDIF_NEEDUPDATE;
1328 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1329 MDITile( hwnd, ci, wParam );
1330 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1331 return 0;
1333 case WM_VSCROLL:
1334 case WM_HSCROLL:
1335 ci->mdiFlags |= MDIF_NEEDUPDATE;
1336 ScrollChildren( hwnd, message, wParam, lParam );
1337 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1338 return 0;
1340 case WM_SETFOCUS:
1341 if (ci->hwndActiveChild && !IsIconic( ci->hwndActiveChild ))
1342 SetFocus( ci->hwndActiveChild );
1343 return 0;
1345 case WM_NCACTIVATE:
1346 if( ci->hwndActiveChild )
1347 SendMessageW(ci->hwndActiveChild, message, wParam, lParam);
1348 break;
1350 case WM_PARENTNOTIFY:
1351 if (LOWORD(wParam) == WM_LBUTTONDOWN)
1353 HWND child;
1354 POINT pt;
1355 pt.x = SLOWORD(lParam);
1356 pt.y = SHIWORD(lParam);
1357 child = ChildWindowFromPoint(hwnd, pt);
1359 TRACE("notification from %04x (%li,%li)\n",child,pt.x,pt.y);
1361 if( child && child != hwnd && child != ci->hwndActiveChild )
1362 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1364 return 0;
1366 case WM_SIZE:
1367 if( IsWindow(ci->hwndChildMaximized) )
1369 RECT rect;
1371 rect.left = 0;
1372 rect.top = 0;
1373 rect.right = LOWORD(lParam);
1374 rect.bottom = HIWORD(lParam);
1376 AdjustWindowRectEx(&rect, GetWindowLongA(ci->hwndChildMaximized,GWL_STYLE),
1377 0, GetWindowLongA(ci->hwndChildMaximized,GWL_EXSTYLE) );
1378 MoveWindow(ci->hwndChildMaximized, rect.left, rect.top,
1379 rect.right - rect.left, rect.bottom - rect.top, 1);
1381 else
1382 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1384 break;
1386 case WM_MDICALCCHILDSCROLL:
1387 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1389 CalcChildScroll(hwnd, ci->sbRecalc-1);
1390 ci->sbRecalc = 0;
1391 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1393 return 0;
1395 return unicode ? DefWindowProcW( hwnd, message, wParam, lParam ) :
1396 DefWindowProcA( hwnd, message, wParam, lParam );
1399 /***********************************************************************
1400 * MDIClientWndProcA
1402 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1404 if (!IsWindow(hwnd)) return 0;
1405 return MDIClientWndProc_common( hwnd, message, wParam, lParam, FALSE );
1408 /***********************************************************************
1409 * MDIClientWndProcW
1411 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1413 if (!IsWindow(hwnd)) return 0;
1414 return MDIClientWndProc_common( hwnd, message, wParam, lParam, TRUE );
1417 /***********************************************************************
1418 * DefFrameProc (USER.445)
1420 LRESULT WINAPI DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient,
1421 UINT16 message, WPARAM16 wParam, LPARAM lParam )
1423 switch (message)
1425 case WM_SETTEXT:
1426 return DefFrameProcA( hwnd, hwndMDIClient, message, wParam, (LPARAM)MapSL(lParam) );
1428 case WM_COMMAND:
1429 case WM_NCACTIVATE:
1430 case WM_SETFOCUS:
1431 case WM_SIZE:
1432 return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1434 case WM_NEXTMENU:
1436 MDINEXTMENU next_menu;
1437 DefFrameProcW( hwnd, hwndMDIClient, message, wParam, (LPARAM)&next_menu );
1438 return MAKELONG( next_menu.hmenuNext, next_menu.hwndNext );
1440 default:
1441 return DefWindowProc16(hwnd, message, wParam, lParam);
1446 /***********************************************************************
1447 * DefFrameProcA (USER32.@)
1449 LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1450 UINT message, WPARAM wParam, LPARAM lParam)
1452 if (hwndMDIClient)
1454 switch (message)
1456 case WM_SETTEXT:
1458 LPWSTR text = HEAP_strdupAtoW( GetProcessHeap(), 0, (LPSTR)lParam );
1459 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, text );
1460 HeapFree( GetProcessHeap(), 0, text );
1462 return 1; /* success. FIXME: check text length */
1464 case WM_COMMAND:
1465 case WM_NCACTIVATE:
1466 case WM_NEXTMENU:
1467 case WM_SETFOCUS:
1468 case WM_SIZE:
1469 return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1472 return DefWindowProcA(hwnd, message, wParam, lParam);
1476 /***********************************************************************
1477 * DefFrameProcW (USER32.@)
1479 LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1480 UINT message, WPARAM wParam, LPARAM lParam)
1482 MDICLIENTINFO *ci = get_client_info( hwndMDIClient );
1484 if (ci)
1486 switch (message)
1488 case WM_COMMAND:
1490 WORD id = LOWORD(wParam);
1491 /* check for possible syscommands for maximized MDI child */
1492 if (id < ci->idFirstChild || id >= ci->idFirstChild + ci->nActiveChildren)
1494 if( (id - 0xf000) & 0xf00f ) break;
1495 if( !ci->hwndChildMaximized ) break;
1496 switch( id )
1498 case SC_SIZE:
1499 case SC_MOVE:
1500 case SC_MINIMIZE:
1501 case SC_MAXIMIZE:
1502 case SC_NEXTWINDOW:
1503 case SC_PREVWINDOW:
1504 case SC_CLOSE:
1505 case SC_RESTORE:
1506 return SendMessageW( ci->hwndChildMaximized, WM_SYSCOMMAND,
1507 wParam, lParam);
1510 else
1512 HWND childHwnd;
1513 if (id - ci->idFirstChild == MDI_MOREWINDOWSLIMIT)
1514 /* User chose "More Windows..." */
1515 childHwnd = MDI_MoreWindowsDialog(hwndMDIClient);
1516 else
1517 /* User chose one of the windows listed in the "Windows" menu */
1518 childHwnd = MDI_GetChildByID(hwndMDIClient,id);
1520 if( childHwnd )
1521 SendMessageW( hwndMDIClient, WM_MDIACTIVATE, (WPARAM)childHwnd, 0 );
1524 break;
1526 case WM_NCACTIVATE:
1527 SendMessageW(hwndMDIClient, message, wParam, lParam);
1528 break;
1530 case WM_SETTEXT:
1531 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, (LPWSTR)lParam );
1532 return 1; /* success. FIXME: check text length */
1534 case WM_SETFOCUS:
1535 SetFocus(hwndMDIClient);
1536 break;
1538 case WM_SIZE:
1539 MoveWindow(hwndMDIClient, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
1540 break;
1542 case WM_NEXTMENU:
1544 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1546 if (!IsIconic(hwnd) && ci->hwndActiveChild && !ci->hwndChildMaximized)
1548 /* control menu is between the frame system menu and
1549 * the first entry of menu bar */
1550 WND *wndPtr = WIN_FindWndPtr(hwnd);
1552 if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1553 (wParam == VK_RIGHT && GetSubMenu(wndPtr->hSysMenu, 0) == next_menu->hmenuIn) )
1555 WIN_ReleaseWndPtr(wndPtr);
1556 wndPtr = WIN_FindWndPtr(ci->hwndActiveChild);
1557 next_menu->hmenuNext = GetSubMenu(wndPtr->hSysMenu, 0);
1558 next_menu->hwndNext = ci->hwndActiveChild;
1559 WIN_ReleaseWndPtr(wndPtr);
1562 return 0;
1567 return DefWindowProcW( hwnd, message, wParam, lParam );
1571 /***********************************************************************
1572 * DefMDIChildProc (USER.447)
1574 LRESULT WINAPI DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1575 WPARAM16 wParam, LPARAM lParam )
1577 switch (message)
1579 case WM_SETTEXT:
1580 return DefMDIChildProcA( hwnd, message, wParam, (LPARAM)MapSL(lParam) );
1581 case WM_MENUCHAR:
1582 case WM_CLOSE:
1583 case WM_SETFOCUS:
1584 case WM_CHILDACTIVATE:
1585 case WM_SYSCOMMAND:
1586 case WM_SETVISIBLE:
1587 case WM_SIZE:
1588 case WM_SYSCHAR:
1589 return DefMDIChildProcW( hwnd, message, wParam, lParam );
1590 case WM_GETMINMAXINFO:
1592 MINMAXINFO16 *mmi16 = (MINMAXINFO16 *)MapSL(lParam);
1593 MINMAXINFO mmi;
1594 STRUCT32_MINMAXINFO16to32( mmi16, &mmi );
1595 DefMDIChildProcW( hwnd, message, wParam, (LPARAM)&mmi );
1596 STRUCT32_MINMAXINFO32to16( &mmi, mmi16 );
1597 return 0;
1599 case WM_NEXTMENU:
1601 MDINEXTMENU next_menu;
1602 DefMDIChildProcW( hwnd, message, wParam, (LPARAM)&next_menu );
1603 return MAKELONG( next_menu.hmenuNext, next_menu.hwndNext );
1605 default:
1606 return DefWindowProc16(hwnd, message, wParam, lParam);
1611 /***********************************************************************
1612 * DefMDIChildProcA (USER32.@)
1614 LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1615 WPARAM wParam, LPARAM lParam )
1617 HWND client = GetParent(hwnd);
1618 MDICLIENTINFO *ci = get_client_info( client );
1620 if (!ci) return DefWindowProcA( hwnd, message, wParam, lParam );
1622 switch (message)
1624 case WM_SETTEXT:
1625 DefWindowProcA(hwnd, message, wParam, lParam);
1626 MDI_MenuModifyItem( client, hwnd );
1627 if( ci->hwndChildMaximized == hwnd )
1628 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1629 return 1; /* success. FIXME: check text length */
1631 case WM_GETMINMAXINFO:
1632 case WM_MENUCHAR:
1633 case WM_CLOSE:
1634 case WM_SETFOCUS:
1635 case WM_CHILDACTIVATE:
1636 case WM_SYSCOMMAND:
1637 case WM_SETVISIBLE:
1638 case WM_SIZE:
1639 case WM_NEXTMENU:
1640 case WM_SYSCHAR:
1641 return DefMDIChildProcW( hwnd, message, wParam, lParam );
1643 return DefWindowProcA(hwnd, message, wParam, lParam);
1647 /***********************************************************************
1648 * DefMDIChildProcW (USER32.@)
1650 LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1651 WPARAM wParam, LPARAM lParam )
1653 HWND client = GetParent(hwnd);
1654 MDICLIENTINFO *ci = get_client_info( client );
1656 if (!ci) return DefWindowProcW( hwnd, message, wParam, lParam );
1658 switch (message)
1660 case WM_SETTEXT:
1661 DefWindowProcW(hwnd, message, wParam, lParam);
1662 MDI_MenuModifyItem( client, hwnd );
1663 if( ci->hwndChildMaximized == hwnd )
1664 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1665 return 1; /* success. FIXME: check text length */
1667 case WM_GETMINMAXINFO:
1668 MDI_ChildGetMinMaxInfo( client, hwnd, (MINMAXINFO *)lParam );
1669 return 0;
1671 case WM_MENUCHAR:
1672 return 0x00010000; /* MDI children don't have menu bars */
1674 case WM_CLOSE:
1675 SendMessageW( client, WM_MDIDESTROY, (WPARAM)hwnd, 0 );
1676 return 0;
1678 case WM_SETFOCUS:
1679 if (ci->hwndActiveChild != hwnd) MDI_ChildActivate( client, hwnd );
1680 break;
1682 case WM_CHILDACTIVATE:
1683 MDI_ChildActivate( client, hwnd );
1684 return 0;
1686 case WM_SYSCOMMAND:
1687 switch( wParam )
1689 case SC_MOVE:
1690 if( ci->hwndChildMaximized == hwnd) return 0;
1691 break;
1692 case SC_RESTORE:
1693 case SC_MINIMIZE:
1694 SetWindowLongA( hwnd, GWL_STYLE,
1695 GetWindowLongA( hwnd, GWL_STYLE ) | WS_SYSMENU );
1696 break;
1697 case SC_MAXIMIZE:
1698 if (ci->hwndChildMaximized == hwnd)
1699 return SendMessageW( GetParent(client), message, wParam, lParam);
1700 SetWindowLongW( hwnd, GWL_STYLE,
1701 GetWindowLongW( hwnd, GWL_STYLE ) & ~WS_SYSMENU );
1702 break;
1703 case SC_NEXTWINDOW:
1704 SendMessageW( client, WM_MDINEXT, 0, 0);
1705 return 0;
1706 case SC_PREVWINDOW:
1707 SendMessageW( client, WM_MDINEXT, 0, 1);
1708 return 0;
1710 break;
1712 case WM_SETVISIBLE:
1713 if( ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1714 else MDI_PostUpdate(client, ci, SB_BOTH+1);
1715 break;
1717 case WM_SIZE:
1718 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1720 ci->hwndChildMaximized = 0;
1721 MDI_RestoreFrameMenu( GetParent(client), hwnd );
1722 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1725 if( wParam == SIZE_MAXIMIZED )
1727 HWND hMaxChild = ci->hwndChildMaximized;
1729 if( hMaxChild == hwnd ) break;
1730 if( hMaxChild)
1732 SendMessageW( hMaxChild, WM_SETREDRAW, FALSE, 0 );
1733 MDI_RestoreFrameMenu( GetParent(client), hMaxChild );
1734 ShowWindow( hMaxChild, SW_SHOWNOACTIVATE );
1735 SendMessageW( hMaxChild, WM_SETREDRAW, TRUE, 0 );
1737 TRACE("maximizing child %04x\n", hwnd );
1739 /* keep track of the maximized window. */
1740 ci->hwndChildMaximized = hwnd; /* !!! */
1742 /* The maximized window should also be the active window */
1743 MDI_ChildActivate( client, hwnd );
1744 MDI_AugmentFrameMenu( GetParent(client), hwnd );
1745 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1748 if( wParam == SIZE_MINIMIZED )
1750 HWND switchTo = MDI_GetWindow(ci, hwnd, TRUE, WS_MINIMIZE);
1752 if (switchTo) SendMessageW( switchTo, WM_CHILDACTIVATE, 0, 0);
1754 MDI_PostUpdate(client, ci, SB_BOTH+1);
1755 break;
1757 case WM_NEXTMENU:
1759 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1760 HWND parent = GetParent(client);
1762 if( wParam == VK_LEFT ) /* switch to frame system menu */
1764 WND *wndPtr = WIN_FindWndPtr( parent );
1765 next_menu->hmenuNext = GetSubMenu( wndPtr->hSysMenu, 0 );
1766 WIN_ReleaseWndPtr( wndPtr );
1768 if( wParam == VK_RIGHT ) /* to frame menu bar */
1770 next_menu->hmenuNext = GetMenu(parent);
1772 next_menu->hwndNext = parent;
1773 return 0;
1776 case WM_SYSCHAR:
1777 if (wParam == '-')
1779 SendMessageW( hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (DWORD)VK_SPACE);
1780 return 0;
1782 break;
1784 return DefWindowProcW(hwnd, message, wParam, lParam);
1787 /**********************************************************************
1788 * CreateMDIWindowA (USER32.@) Creates a MDI child
1790 * RETURNS
1791 * Success: Handle to created window
1792 * Failure: NULL
1794 HWND WINAPI CreateMDIWindowA(
1795 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1796 LPCSTR lpWindowName, /* [in] Pointer to window name */
1797 DWORD dwStyle, /* [in] Window style */
1798 INT X, /* [in] Horizontal position of window */
1799 INT Y, /* [in] Vertical position of window */
1800 INT nWidth, /* [in] Width of window */
1801 INT nHeight, /* [in] Height of window */
1802 HWND hWndParent, /* [in] Handle to parent window */
1803 HINSTANCE hInstance, /* [in] Handle to application instance */
1804 LPARAM lParam) /* [in] Application-defined value */
1806 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1807 MDICREATESTRUCTA cs;
1809 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
1810 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1811 nWidth,nHeight,hWndParent,hInstance,lParam);
1813 if (!pCi)
1815 ERR("bad hwnd for MDI-client: %04x\n", hWndParent);
1816 return 0;
1818 cs.szClass=lpClassName;
1819 cs.szTitle=lpWindowName;
1820 cs.hOwner=hInstance;
1821 cs.x=X;
1822 cs.y=Y;
1823 cs.cx=nWidth;
1824 cs.cy=nHeight;
1825 cs.style=dwStyle;
1826 cs.lParam=lParam;
1828 return MDICreateChild(hWndParent, pCi, &cs, FALSE);
1831 /***********************************************************************
1832 * CreateMDIWindowW (USER32.@) Creates a MDI child
1834 * RETURNS
1835 * Success: Handle to created window
1836 * Failure: NULL
1838 HWND WINAPI CreateMDIWindowW(
1839 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1840 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1841 DWORD dwStyle, /* [in] Window style */
1842 INT X, /* [in] Horizontal position of window */
1843 INT Y, /* [in] Vertical position of window */
1844 INT nWidth, /* [in] Width of window */
1845 INT nHeight, /* [in] Height of window */
1846 HWND hWndParent, /* [in] Handle to parent window */
1847 HINSTANCE hInstance, /* [in] Handle to application instance */
1848 LPARAM lParam) /* [in] Application-defined value */
1850 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1851 MDICREATESTRUCTW cs;
1853 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
1854 debugstr_w(lpClassName), debugstr_w(lpWindowName), dwStyle, X, Y,
1855 nWidth, nHeight, hWndParent, hInstance, lParam);
1857 if (!pCi)
1859 ERR("bad hwnd for MDI-client: %04x\n", hWndParent);
1860 return 0;
1862 cs.szClass = lpClassName;
1863 cs.szTitle = lpWindowName;
1864 cs.hOwner = hInstance;
1865 cs.x = X;
1866 cs.y = Y;
1867 cs.cx = nWidth;
1868 cs.cy = nHeight;
1869 cs.style = dwStyle;
1870 cs.lParam = lParam;
1872 return MDICreateChild(hWndParent, pCi, (MDICREATESTRUCTA *)&cs, TRUE);
1875 /**********************************************************************
1876 * TranslateMDISysAccel (USER.451)
1878 BOOL16 WINAPI TranslateMDISysAccel16( HWND16 hwndClient, LPMSG16 msg )
1880 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1882 MSG msg32;
1883 msg32.hwnd = msg->hwnd;
1884 msg32.message = msg->message;
1885 msg32.wParam = msg->wParam;
1886 msg32.lParam = msg->lParam;
1887 /* MDICLIENTINFO is still the same for win32 and win16 ... */
1888 return TranslateMDISysAccel(hwndClient, &msg32);
1890 return 0;
1893 /**********************************************************************
1894 * TranslateMDISysAccel (USER32.@)
1896 BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1898 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1900 MDICLIENTINFO *ci = get_client_info( hwndClient );
1901 WPARAM wParam = 0;
1903 if (!ci || !IsWindowEnabled(ci->hwndActiveChild)) return 0;
1905 /* translate if the Ctrl key is down and Alt not. */
1907 if( (GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
1909 switch( msg->wParam )
1911 case VK_F6:
1912 case VK_TAB:
1913 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 ) ? SC_NEXTWINDOW : SC_PREVWINDOW;
1914 break;
1915 case VK_F4:
1916 case VK_RBUTTON:
1917 wParam = SC_CLOSE;
1918 break;
1919 default:
1920 return 0;
1922 TRACE("wParam = %04x\n", wParam);
1923 SendMessageW(ci->hwndActiveChild, WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
1924 return 1;
1927 return 0; /* failure */
1930 /***********************************************************************
1931 * CalcChildScroll (USER.462)
1933 void WINAPI CalcChildScroll16( HWND16 hwnd, WORD scroll )
1935 return CalcChildScroll( hwnd, scroll );
1938 /***********************************************************************
1939 * CalcChildScroll (USER32.@)
1941 void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
1943 SCROLLINFO info;
1944 RECT childRect, clientRect;
1945 INT vmin, vmax, hmin, hmax, vpos, hpos;
1946 HWND *list;
1948 GetClientRect( hwnd, &clientRect );
1949 SetRectEmpty( &childRect );
1951 if ((list = WIN_ListChildren( hwnd )))
1953 int i;
1954 for (i = 0; list[i]; i++)
1956 DWORD style = GetWindowLongW( list[i], GWL_STYLE );
1957 if (style & WS_MAXIMIZE)
1959 HeapFree( GetProcessHeap(), 0, list );
1960 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1961 return;
1963 if (style & WS_VISIBLE)
1965 WND *pWnd = WIN_FindWndPtr( list[i] );
1966 UnionRect( &childRect, &pWnd->rectWindow, &childRect );
1967 WIN_ReleaseWndPtr( pWnd );
1970 HeapFree( GetProcessHeap(), 0, list );
1972 UnionRect( &childRect, &clientRect, &childRect );
1974 hmin = childRect.left;
1975 hmax = childRect.right - clientRect.right;
1976 hpos = clientRect.left - childRect.left;
1977 vmin = childRect.top;
1978 vmax = childRect.bottom - clientRect.bottom;
1979 vpos = clientRect.top - childRect.top;
1981 switch( scroll )
1983 case SB_HORZ:
1984 vpos = hpos; vmin = hmin; vmax = hmax;
1985 case SB_VERT:
1986 info.cbSize = sizeof(info);
1987 info.nMax = vmax; info.nMin = vmin; info.nPos = vpos;
1988 info.fMask = SIF_POS | SIF_RANGE;
1989 SetScrollInfo(hwnd, scroll, &info, TRUE);
1990 break;
1991 case SB_BOTH:
1992 SCROLL_SetNCSbState( hwnd, vmin, vmax, vpos,
1993 hmin, hmax, hpos);
1998 /***********************************************************************
1999 * ScrollChildren (USER.463)
2001 void WINAPI ScrollChildren16(HWND16 hWnd, UINT16 uMsg, WPARAM16 wParam, LPARAM lParam)
2003 ScrollChildren( hWnd, uMsg, wParam, lParam );
2007 /***********************************************************************
2008 * ScrollChildren (USER32.@)
2010 void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
2011 LPARAM lParam)
2013 INT newPos = -1;
2014 INT curPos, length, minPos, maxPos, shift;
2015 RECT rect;
2017 GetClientRect( hWnd, &rect );
2019 switch(uMsg)
2021 case WM_HSCROLL:
2022 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
2023 curPos = GetScrollPos(hWnd,SB_HORZ);
2024 length = (rect.right - rect.left) / 2;
2025 shift = GetSystemMetrics(SM_CYHSCROLL);
2026 break;
2027 case WM_VSCROLL:
2028 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
2029 curPos = GetScrollPos(hWnd,SB_VERT);
2030 length = (rect.bottom - rect.top) / 2;
2031 shift = GetSystemMetrics(SM_CXVSCROLL);
2032 break;
2033 default:
2034 return;
2037 switch( wParam )
2039 case SB_LINEUP:
2040 newPos = curPos - shift;
2041 break;
2042 case SB_LINEDOWN:
2043 newPos = curPos + shift;
2044 break;
2045 case SB_PAGEUP:
2046 newPos = curPos - length;
2047 break;
2048 case SB_PAGEDOWN:
2049 newPos = curPos + length;
2050 break;
2052 case SB_THUMBPOSITION:
2053 newPos = LOWORD(lParam);
2054 break;
2056 case SB_THUMBTRACK:
2057 return;
2059 case SB_TOP:
2060 newPos = minPos;
2061 break;
2062 case SB_BOTTOM:
2063 newPos = maxPos;
2064 break;
2065 case SB_ENDSCROLL:
2066 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
2067 return;
2070 if( newPos > maxPos )
2071 newPos = maxPos;
2072 else
2073 if( newPos < minPos )
2074 newPos = minPos;
2076 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
2078 if( uMsg == WM_VSCROLL )
2079 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
2080 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2081 else
2082 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
2083 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2087 /******************************************************************************
2088 * CascadeWindows (USER32.@) Cascades MDI child windows
2090 * RETURNS
2091 * Success: Number of cascaded windows.
2092 * Failure: 0
2094 WORD WINAPI
2095 CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2096 UINT cKids, const HWND *lpKids)
2098 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2099 hwndParent, wFlags, cKids);
2101 return 0;
2105 /******************************************************************************
2106 * TileWindows (USER32.@) Tiles MDI child windows
2108 * RETURNS
2109 * Success: Number of tiled windows.
2110 * Failure: 0
2112 WORD WINAPI
2113 TileWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2114 UINT cKids, const HWND *lpKids)
2116 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2117 hwndParent, wFlags, cKids);
2119 return 0;
2122 /************************************************************************
2123 * "More Windows..." functionality
2126 /* MDI_MoreWindowsDlgProc
2128 * This function will process the messages sent to the "More Windows..."
2129 * dialog.
2130 * Return values: 0 = cancel pressed
2131 * HWND = ok pressed or double-click in the list...
2135 static BOOL WINAPI MDI_MoreWindowsDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
2137 switch (iMsg)
2139 case WM_INITDIALOG:
2141 UINT widest = 0;
2142 UINT length;
2143 UINT i;
2144 MDICLIENTINFO *ci = get_client_info( (HWND)lParam );
2145 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2146 HWND *list, *sorted_list;
2148 if (!(list = WIN_ListChildren( (HWND)lParam ))) return TRUE;
2149 if (!(sorted_list = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
2150 sizeof(HWND) * ci->nActiveChildren )))
2152 HeapFree( GetProcessHeap(), 0, list );
2153 return FALSE;
2156 /* Fill the list, sorted by id... */
2157 for (i = 0; list[i]; i++)
2159 UINT id = GetWindowLongW( list[i], GWL_ID ) - ci->idFirstChild;
2160 if (id < ci->nActiveChildren) sorted_list[id] = list[i];
2162 HeapFree( GetProcessHeap(), 0, list );
2164 for (i = 0; i < ci->nActiveChildren; i++)
2166 WCHAR buffer[128];
2168 if (!GetWindowTextW( sorted_list[i], buffer, sizeof(buffer)/sizeof(WCHAR) ))
2169 continue;
2170 SendMessageW(hListBox, LB_ADDSTRING, 0, (LPARAM)buffer );
2171 SendMessageW(hListBox, LB_SETITEMDATA, i, (LPARAM)sorted_list[i] );
2172 length = strlenW(buffer); /* FIXME: should use GetTextExtentPoint */
2173 if (length > widest)
2174 widest = length;
2176 /* Make sure the horizontal scrollbar scrolls ok */
2177 SendMessageW(hListBox, LB_SETHORIZONTALEXTENT, widest * 6, 0);
2179 /* Set the current selection */
2180 SendMessageW(hListBox, LB_SETCURSEL, MDI_MOREWINDOWSLIMIT, 0);
2181 return TRUE;
2184 case WM_COMMAND:
2185 switch (LOWORD(wParam))
2187 default:
2188 if (HIWORD(wParam) != LBN_DBLCLK) break;
2189 /* fall through */
2190 case IDOK:
2192 /* windows are sorted by menu ID, so we must return the
2193 * window associated to the given id
2195 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2196 UINT index = SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
2197 HWND hwnd = SendMessageW(hListBox, LB_GETITEMDATA, index, 0);
2199 EndDialog(hDlg, hwnd);
2200 return TRUE;
2202 case IDCANCEL:
2203 EndDialog(hDlg, 0);
2204 return TRUE;
2206 break;
2208 return FALSE;
2213 * MDI_MoreWindowsDialog
2215 * Prompts the user with a listbox containing the opened
2216 * documents. The user can then choose a windows and click
2217 * on OK to set the current window to the one selected, or
2218 * CANCEL to cancel. The function returns a handle to the
2219 * selected window.
2222 static HWND MDI_MoreWindowsDialog(HWND hwnd)
2224 LPCVOID template;
2225 HRSRC hRes;
2226 HANDLE hDlgTmpl;
2228 hRes = FindResourceA(GetModuleHandleA("USER32"), "MDI_MOREWINDOWS", RT_DIALOGA);
2230 if (hRes == 0)
2231 return 0;
2233 hDlgTmpl = LoadResource(GetModuleHandleA("USER32"), hRes );
2235 if (hDlgTmpl == 0)
2236 return 0;
2238 template = LockResource( hDlgTmpl );
2240 if (template == 0)
2241 return 0;
2243 return (HWND) DialogBoxIndirectParamA(GetModuleHandleA("USER32"),
2244 (LPDLGTEMPLATEA) template,
2245 hwnd, MDI_MoreWindowsDlgProc, (LPARAM) hwnd);
2250 * MDI_SwapMenuItems
2252 * Will swap the menu IDs for the given 2 positions.
2253 * pos1 and pos2 are menu IDs
2258 static void MDI_SwapMenuItems(HWND parent, UINT pos1, UINT pos2)
2260 HWND *list;
2261 int i;
2263 if (!(list = WIN_ListChildren( parent ))) return;
2264 for (i = 0; list[i]; i++)
2266 UINT id = GetWindowLongW( list[i], GWL_ID );
2267 if (id == pos1) SetWindowLongW( list[i], GWL_ID, pos2 );
2268 else if (id == pos2) SetWindowLongW( list[i], GWL_ID, pos1 );
2270 HeapFree( GetProcessHeap(), 0, list );