~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/user32/mdi.c

Version: ~ [ wine-1.5.31 ] ~ [ wine-1.5.30 ] ~ [ wine-1.5.29 ] ~ [ wine-1.5.28 ] ~ [ wine-1.5.27 ] ~ [ wine-1.5.26 ] ~ [ wine-1.5.25 ] ~ [ wine-1.5.24 ] ~ [ wine-1.5.23 ] ~ [ wine-1.5.22 ] ~ [ wine-1.5.21 ] ~ [ wine-1.5.20 ] ~ [ wine-1.5.19 ] ~ [ wine-1.5.18 ] ~ [ wine-1.5.17 ] ~ [ wine-1.5.16 ] ~ [ wine-1.5.15 ] ~ [ wine-1.5.14 ] ~ [ wine-1.5.13 ] ~ [ wine-1.5.12 ] ~ [ wine-1.5.11 ] ~ [ wine-1.5.10 ] ~ [ wine-1.5.9 ] ~ [ wine-1.5.8 ] ~ [ wine-1.5.7 ] ~ [ wine-1.4.1 ] ~ [ wine-1.5.6 ] ~ [ wine-1.5.5 ] ~ [ wine-1.5.4 ] ~ [ wine-1.5.3 ] ~ [ wine-1.5.2 ] ~ [ wine-1.5.1 ] ~ [ wine-1.5.0 ] ~ [ wine-1.4 ] ~ [ wine-1.4-rc6 ] ~ [ wine-1.4-rc5 ] ~ [ wine-1.4-rc4 ] ~ [ wine-1.4-rc3 ] ~ [ wine-1.4-rc2 ] ~ [ wine-1.4-rc1 ] ~ [ wine-1.3.37 ] ~ [ wine-1.3.36 ] ~ [ wine-1.3.35 ] ~ [ wine-1.3.34 ] ~ [ wine-1.3.33 ] ~ [ wine-1.3.32 ] ~ [ wine-1.3.31 ] ~ [ wine-1.3.30 ] ~ [ wine-1.3.29 ] ~ [ wine-1.3.28 ] ~ [ wine-1.3.27 ] ~ [ wine-1.3.26 ] ~ [ wine-1.3.25 ] ~ [ wine-1.3.24 ] ~ [ wine-1.3.23 ] ~ [ wine-1.3.22 ] ~ [ wine-1.3.21 ] ~ [ wine-1.3.20 ] ~ [ wine-1.3.19 ] ~ [ wine-1.3.18 ] ~ [ wine-1.2.3 ] ~ [ wine-1.3.17 ] ~ [ wine-1.3.16 ] ~ [ wine-1.3.15 ] ~ [ wine-1.3.14 ] ~ [ wine-1.3.13 ] ~ [ wine-1.3.12 ] ~ [ wine-1.3.11 ] ~ [ wine-1.3.10 ] ~ [ wine-1.3.9 ] ~ [ wine-1.2.2 ] ~ [ wine-1.3.8 ] ~ [ wine-1.3.7 ] ~ [ wine-1.3.6 ] ~ [ wine-1.3.5 ] ~ [ wine-1.2.1 ] ~ [ wine-1.3.4 ] ~ [ wine-1.3.3 ] ~ [ wine-1.3.2 ] ~ [ wine-1.3.1 ] ~ [ wine-1.3.0 ] ~ [ wine-1.2 ] ~ [ wine-1.2-rc7 ] ~ [ wine-1.2-rc6 ] ~ [ wine-1.2-rc5 ] ~ [ wine-1.2-rc4 ] ~ [ wine-1.2-rc3 ] ~ [ wine-1.2-rc2 ] ~ [ wine-1.2-rc1 ] ~ [ wine-1.1.44 ] ~ [ wine-1.1.43 ] ~ [ wine-1.1.42 ] ~ [ wine-1.1.41 ] ~ [ wine-1.1.40 ] ~ [ wine-1.1.39 ] ~ [ wine-1.1.38 ] ~ [ wine-1.1.37 ] ~ [ wine-1.1.36 ] ~ [ wine-1.1.35 ] ~ [ wine-1.1.34 ] ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  1 /* MDI.C
  2  *
  3  * Copyright 1994, Bob Amstadt
  4  *           1995,1996 Alex Korobka
  5  *
  6  * This file contains routines to support MDI (Multiple Document
  7  * Interface) features .
  8  *
  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.
 13  *
 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.
 18  *
 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 22  *
 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.
 26  *
 27  * Notes on how the "More Windows..." is implemented:
 28  *
 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, accessible 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:
 35  *
 36  *
 37  *
 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
 48  *
 49  *
 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:
 52  *
 53  *
 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
 65  *
 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.
 69  *
 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
 80  *
 81  */
 82 
 83 #include <stdlib.h>
 84 #include <stdarg.h>
 85 #include <stdio.h>
 86 #include <string.h>
 87 #include <math.h>
 88 
 89 #define OEMRESOURCE
 90 
 91 #include "windef.h"
 92 #include "winbase.h"
 93 #include "wingdi.h"
 94 #include "winuser.h"
 95 #include "wownt32.h"
 96 #include "wine/winuser16.h"
 97 #include "wine/unicode.h"
 98 #include "win.h"
 99 #include "controls.h"
100 #include "user_private.h"
101 #include "wine/debug.h"
102 
103 WINE_DEFAULT_DEBUG_CHANNEL(mdi);
104 
105 #define MDI_MAXTITLELENGTH      0xa1
106 
107 #define WM_MDICALCCHILDSCROLL   0x10ac /* this is exactly what Windows uses */
108 
109 /* "More Windows..." definitions */
110 #define MDI_MOREWINDOWSLIMIT    9       /* after this number of windows, a "More Windows..."
111                                            option will appear under the Windows menu */
112 #define MDI_IDC_LISTBOX         100
113 #define IDS_MDI_MOREWINDOWS     13
114 
115 #define MDIF_NEEDUPDATE         0x0001
116 
117 typedef struct
118 {
119     /* At some points, particularly when switching MDI children, active and
120      * maximized MDI children may be not the same window, so we need to track
121      * them separately.
122      * The only place where we switch to/from maximized state is DefMDIChildProc
123      * WM_SIZE/SIZE_MAXIMIZED handler. We get that notification only after the
124      * ShowWindow(SW_SHOWMAXIMIZED) request, therefore window is guaranteed to
125      * be visible at the time we get the notification, and it's safe to assume
126      * that hwndChildMaximized is always visible.
127      * If the app plays games with WS_VISIBLE, WS_MAXIMIZE or any other window
128      * states it must keep coherency with USER32 on its own. This is true for
129      * Windows as well.
130      */
131     UINT      nActiveChildren;
132     HWND      hwndChildMaximized;
133     HWND      hwndActiveChild;
134     HWND      *child; /* array of tracked children */
135     HMENU     hFrameMenu;
136     HMENU     hWindowMenu;
137     UINT      idFirstChild;
138     LPWSTR    frameTitle;
139     UINT      nTotalCreated;
140     UINT      mdiFlags;
141     UINT      sbRecalc;   /* SB_xxx flags for scrollbar fixup */
142 } MDICLIENTINFO;
143 
144 static HBITMAP hBmpClose   = 0;
145 
146 /* ----------------- declarations ----------------- */
147 static void MDI_UpdateFrameText( HWND, HWND, BOOL, LPCWSTR);
148 static BOOL MDI_AugmentFrameMenu( HWND, HWND );
149 static BOOL MDI_RestoreFrameMenu( HWND, HWND );
150 static LONG MDI_ChildActivate( HWND, HWND );
151 static LRESULT MDI_RefreshMenu(MDICLIENTINFO *);
152 
153 static HWND MDI_MoreWindowsDialog(HWND);
154 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
155 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
156 
157 /* -------- Miscellaneous service functions ----------
158  *
159  *                      MDI_GetChildByID
160  */
161 static HWND MDI_GetChildByID(HWND hwnd, UINT id, MDICLIENTINFO *ci)
162 {
163     int i;
164 
165     for (i = 0; ci->nActiveChildren; i++)
166     {
167         if (GetWindowLongPtrW( ci->child[i], GWLP_ID ) == id)
168             return ci->child[i];
169     }
170     return 0;
171 }
172 
173 static void MDI_PostUpdate(HWND hwnd, MDICLIENTINFO* ci, WORD recalc)
174 {
175     if( !(ci->mdiFlags & MDIF_NEEDUPDATE) )
176     {
177         ci->mdiFlags |= MDIF_NEEDUPDATE;
178         PostMessageA( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
179     }
180     ci->sbRecalc = recalc;
181 }
182 
183 
184 /*********************************************************************
185  * MDIClient class descriptor
186  */
187 static const WCHAR mdiclientW[] = {'M','D','I','C','l','i','e','n','t',0};
188 const struct builtin_class_descr MDICLIENT_builtin_class =
189 {
190     mdiclientW,             /* name */
191     0,                      /* style */
192     MDIClientWndProcA,      /* procA */
193     MDIClientWndProcW,      /* procW */
194     sizeof(MDICLIENTINFO),  /* extra */
195     IDC_ARROW,              /* cursor */
196     (HBRUSH)(COLOR_APPWORKSPACE+1)    /* brush */
197 };
198 
199 
200 static MDICLIENTINFO *get_client_info( HWND client )
201 {
202     MDICLIENTINFO *ret = NULL;
203     WND *win = WIN_GetPtr( client );
204     if (win)
205     {
206         if (win == WND_OTHER_PROCESS || win == WND_DESKTOP)
207         {
208             if (IsWindow(client)) WARN( "client %p belongs to other process\n", client );
209             return NULL;
210         }
211         if (win->flags & WIN_ISMDICLIENT)
212             ret = (MDICLIENTINFO *)win->wExtra;
213         else
214             WARN( "%p is not an MDI client\n", client );
215         WIN_ReleasePtr( win );
216     }
217     return ret;
218 }
219 
220 static BOOL is_close_enabled(HWND hwnd, HMENU hSysMenu)
221 {
222     if (GetClassLongW(hwnd, GCL_STYLE) & CS_NOCLOSE) return FALSE;
223 
224     if (!hSysMenu) hSysMenu = GetSystemMenu(hwnd, FALSE);
225     if (hSysMenu)
226     {
227         UINT state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
228         if (state == 0xFFFFFFFF || (state & (MF_DISABLED | MF_GRAYED)))
229             return FALSE;
230     }
231     return TRUE;
232 }
233 
234 /**********************************************************************
235  *                      MDI_GetWindow
236  *
237  * returns "activatable" child different from the current or zero
238  */
239 static HWND MDI_GetWindow(MDICLIENTINFO *clientInfo, HWND hWnd, BOOL bNext,
240                             DWORD dwStyleMask )
241 {
242     int i;
243     HWND *list;
244     HWND last = 0;
245 
246     dwStyleMask |= WS_DISABLED | WS_VISIBLE;
247     if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
248 
249     if (!(list = WIN_ListChildren( GetParent(hWnd) ))) return 0;
250     i = 0;
251     /* start from next after hWnd */
252     while (list[i] && list[i] != hWnd) i++;
253     if (list[i]) i++;
254 
255     for ( ; list[i]; i++)
256     {
257         if (GetWindow( list[i], GW_OWNER )) continue;
258         if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
259         last = list[i];
260         if (bNext) goto found;
261     }
262     /* now restart from the beginning */
263     for (i = 0; list[i] && list[i] != hWnd; i++)
264     {
265         if (GetWindow( list[i], GW_OWNER )) continue;
266         if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
267         last = list[i];
268         if (bNext) goto found;
269     }
270  found:
271     HeapFree( GetProcessHeap(), 0, list );
272     return last;
273 }
274 
275 /**********************************************************************
276  *                      MDI_CalcDefaultChildPos
277  *
278  *  It seems that the default height is about 2/3 of the client rect
279  */
280 void MDI_CalcDefaultChildPos( HWND hwndClient, INT total, LPPOINT lpPos, INT delta, UINT *id )
281 {
282     INT  nstagger;
283     RECT rect;
284     INT spacing = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFRAME) - 1;
285 
286     if (total < 0) /* we are called from CreateWindow */
287     {
288         MDICLIENTINFO *ci = get_client_info(hwndClient);
289         total = ci ? ci->nTotalCreated : 0;
290         *id = ci->idFirstChild + ci->nActiveChildren;
291         TRACE("MDI child id %04x\n", *id);
292     }
293 
294     GetClientRect( hwndClient, &rect );
295     if( rect.bottom - rect.top - delta >= spacing )
296         rect.bottom -= delta;
297 
298     nstagger = (rect.bottom - rect.top)/(3 * spacing);
299     lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
300     lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
301     lpPos[0].x = lpPos[0].y = spacing * (total%(nstagger+1));
302 }
303 
304 /**********************************************************************
305  *            MDISetMenu
306  */
307 static LRESULT MDISetMenu( HWND hwnd, HMENU hmenuFrame,
308                            HMENU hmenuWindow)
309 {
310     MDICLIENTINFO *ci;
311     HWND hwndFrame = GetParent(hwnd);
312 
313     TRACE("%p, frame menu %p, window menu %p\n", hwnd, hmenuFrame, hmenuWindow);
314 
315     if (hmenuFrame && !IsMenu(hmenuFrame))
316     {
317         WARN("hmenuFrame is not a menu handle\n");
318         return 0L;
319     }
320 
321     if (hmenuWindow && !IsMenu(hmenuWindow))
322     {
323         WARN("hmenuWindow is not a menu handle\n");
324         return 0L;
325     }
326 
327     if (!(ci = get_client_info( hwnd ))) return 0;
328 
329     TRACE("old frame menu %p, old window menu %p\n", ci->hFrameMenu, ci->hWindowMenu);
330 
331     if (hmenuFrame)
332     {
333         if (hmenuFrame == ci->hFrameMenu) return (LRESULT)hmenuFrame;
334 
335         if (ci->hwndChildMaximized)
336             MDI_RestoreFrameMenu( hwndFrame, ci->hwndChildMaximized );
337     }
338 
339     if( hmenuWindow && hmenuWindow != ci->hWindowMenu )
340     {
341         /* delete menu items from ci->hWindowMenu
342          * and add them to hmenuWindow */
343         /* Agent newsreader calls this function with  ci->hWindowMenu == NULL */
344         if( ci->hWindowMenu && ci->nActiveChildren )
345         {
346             UINT nActiveChildren_old = ci->nActiveChildren;
347 
348             /* Remove all items from old Window menu */
349             ci->nActiveChildren = 0;
350             MDI_RefreshMenu(ci);
351 
352             ci->hWindowMenu = hmenuWindow;
353 
354             /* Add items to the new Window menu */
355             ci->nActiveChildren = nActiveChildren_old;
356             MDI_RefreshMenu(ci);
357         }
358         else
359             ci->hWindowMenu = hmenuWindow;
360     }
361 
362     if (hmenuFrame)
363     {
364         SetMenu(hwndFrame, hmenuFrame);
365         if( hmenuFrame != ci->hFrameMenu )
366         {
367             HMENU oldFrameMenu = ci->hFrameMenu;
368 
369             ci->hFrameMenu = hmenuFrame;
370             if (ci->hwndChildMaximized)
371                 MDI_AugmentFrameMenu( hwndFrame, ci->hwndChildMaximized );
372 
373             return (LRESULT)oldFrameMenu;
374         }
375     }
376     else
377     {
378         /* SetMenu() may already have been called, meaning that this window
379          * already has its menu. But they may have done a SetMenu() on
380          * an MDI window, and called MDISetMenu() after the fact, meaning
381          * that the "if" to this "else" wouldn't catch the need to
382          * augment the frame menu.
383          */
384         if( ci->hwndChildMaximized )
385             MDI_AugmentFrameMenu( hwndFrame, ci->hwndChildMaximized );
386     }
387 
388     return 0;
389 }
390 
391 /**********************************************************************
392  *            MDIRefreshMenu
393  */
394 static LRESULT MDI_RefreshMenu(MDICLIENTINFO *ci)
395 {
396     UINT i, count, visible, id;
397     WCHAR buf[MDI_MAXTITLELENGTH];
398 
399     TRACE("children %u, window menu %p\n", ci->nActiveChildren, ci->hWindowMenu);
400 
401     if (!ci->hWindowMenu)
402         return 0;
403 
404     if (!IsMenu(ci->hWindowMenu))
405     {
406         WARN("Window menu handle %p is no more valid\n", ci->hWindowMenu);
407         return 0;
408     }
409 
410     /* Windows finds the last separator in the menu, and if after it
411      * there is a menu item with MDI magic ID removes all existing
412      * menu items after it, and then adds visible MDI children.
413      */
414     count = GetMenuItemCount(ci->hWindowMenu);
415     for (i = 0; i < count; i++)
416     {
417         MENUITEMINFOW mii;
418 
419         memset(&mii, 0, sizeof(mii));
420         mii.cbSize = sizeof(mii);
421         mii.fMask  = MIIM_TYPE;
422         if (GetMenuItemInfoW(ci->hWindowMenu, i, TRUE, &mii))
423         {
424             if (mii.fType & MF_SEPARATOR)
425             {
426                 /* Windows checks only ID of the menu item */
427                 memset(&mii, 0, sizeof(mii));
428                 mii.cbSize = sizeof(mii);
429                 mii.fMask  = MIIM_ID;
430                 if (GetMenuItemInfoW(ci->hWindowMenu, i + 1, TRUE, &mii))
431                 {
432                     if (mii.wID == ci->idFirstChild)
433                     {
434                         TRACE("removing %u items including separator\n", count - i);
435                         while (RemoveMenu(ci->hWindowMenu, i, MF_BYPOSITION))
436                             /* nothing */;
437 
438                         break;
439                     }
440                 }
441             }
442         }
443     }
444 
445     visible = 0;
446     for (i = 0; i < ci->nActiveChildren; i++)
447     {
448         if (GetWindowLongW(ci->child[i], GWL_STYLE) & WS_VISIBLE)
449         {
450             id = ci->idFirstChild + visible;
451 
452             if (visible == MDI_MOREWINDOWSLIMIT)
453             {
454                 LoadStringW(user32_module, IDS_MDI_MOREWINDOWS, buf, sizeof(buf)/sizeof(WCHAR));
455                 AppendMenuW(ci->hWindowMenu, MF_STRING, id, buf);
456                 break;
457             }
458 
459             if (!visible)
460                 /* Visio expects that separator has id 0 */
461                 AppendMenuW(ci->hWindowMenu, MF_SEPARATOR, 0, NULL);
462 
463             visible++;
464 
465             SetWindowLongPtrW(ci->child[i], GWLP_ID, id);
466 
467             buf[0] = '&';
468             buf[1] = '' + visible;
469             buf[2] = ' ';
470             InternalGetWindowText(ci->child[i], buf + 3, sizeof(buf)/sizeof(WCHAR) - 3);
471             TRACE("Adding %p, id %u %s\n", ci->child[i], id, debugstr_w(buf));
472             AppendMenuW(ci->hWindowMenu, MF_STRING, id, buf);
473 
474             if (ci->child[i] == ci->hwndActiveChild)
475                 CheckMenuItem(ci->hWindowMenu, id, MF_CHECKED);
476         }
477         else
478             TRACE("MDI child %p is not visible, skipping\n", ci->child[i]);
479     }
480 
481     return (LRESULT)ci->hFrameMenu;
482 }
483 
484 
485 /* ------------------ MDI child window functions ---------------------- */
486 
487 /**********************************************************************
488  *                      MDI_ChildGetMinMaxInfo
489  *
490  * Note: The rule here is that client rect of the maximized MDI child
491  *       is equal to the client rect of the MDI client window.
492  */
493 static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
494 {
495     RECT rect;
496 
497     GetClientRect( client, &rect );
498     AdjustWindowRectEx( &rect, GetWindowLongW( hwnd, GWL_STYLE ),
499                         0, GetWindowLongW( hwnd, GWL_EXSTYLE ));
500 
501     lpMinMax->ptMaxSize.x = rect.right -= rect.left;
502     lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
503 
504     lpMinMax->ptMaxPosition.x = rect.left;
505     lpMinMax->ptMaxPosition.y = rect.top;
506 
507     TRACE("max rect (%d,%d - %d, %d)\n",
508                         rect.left,rect.top,rect.right,rect.bottom);
509 }
510 
511 /**********************************************************************
512  *                      MDI_SwitchActiveChild
513  *
514  * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
515  *       being activated
516  */
517 static void MDI_SwitchActiveChild( MDICLIENTINFO *ci, HWND hwndTo, BOOL activate )
518 {
519     HWND hwndPrev;
520 
521     hwndPrev = ci->hwndActiveChild;
522 
523     TRACE("from %p, to %p\n", hwndPrev, hwndTo);
524 
525     if ( hwndTo != hwndPrev )
526     {
527         BOOL was_zoomed = IsZoomed(hwndPrev);
528 
529         if (was_zoomed)
530         {
531             /* restore old MDI child */
532             SendMessageW( hwndPrev, WM_SETREDRAW, FALSE, 0 );
533             ShowWindow( hwndPrev, SW_RESTORE );
534             SendMessageW( hwndPrev, WM_SETREDRAW, TRUE, 0 );
535 
536             /* activate new MDI child */
537             SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
538             /* maximize new MDI child */
539             ShowWindow( hwndTo, SW_MAXIMIZE );
540         }
541         /* activate new MDI child */
542         SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | (activate ? 0 : SWP_NOACTIVATE) );
543     }
544 }
545 
546 
547 /**********************************************************************
548  *                                      MDIDestroyChild
549  */
550 static LRESULT MDIDestroyChild( HWND client, MDICLIENTINFO *ci,
551                                 HWND child, BOOL flagDestroy )
552 {
553     UINT i;
554 
555     TRACE("# of managed children %u\n", ci->nActiveChildren);
556 
557     if( child == ci->hwndActiveChild )
558     {
559         HWND next = MDI_GetWindow(ci, child, TRUE, 0);
560         /* flagDestroy == 0 means we were called from WM_PARENTNOTIFY handler */
561         if (flagDestroy && next)
562             MDI_SwitchActiveChild(ci, next, TRUE);
563         else
564         {
565             ShowWindow(child, SW_HIDE);
566             if (child == ci->hwndChildMaximized)
567             {
568                 HWND frame = GetParent(client);
569                 MDI_RestoreFrameMenu(frame, child);
570                 ci->hwndChildMaximized = 0;
571                 MDI_UpdateFrameText(frame, client, TRUE, NULL);
572             }
573             if (flagDestroy)
574                 MDI_ChildActivate(client, 0);
575         }
576     }
577 
578     for (i = 0; i < ci->nActiveChildren; i++)
579     {
580         if (ci->child[i] == child)
581         {
582             HWND *new_child = HeapAlloc(GetProcessHeap(), 0, (ci->nActiveChildren - 1) * sizeof(HWND));
583             memcpy(new_child, ci->child, i * sizeof(HWND));
584             if (i + 1 < ci->nActiveChildren)
585                 memcpy(new_child + i, ci->child + i + 1, (ci->nActiveChildren - i - 1) * sizeof(HWND));
586             HeapFree(GetProcessHeap(), 0, ci->child);
587             ci->child = new_child;
588 
589             ci->nActiveChildren--;
590             break;
591         }
592     }
593 
594     if (flagDestroy)
595     {
596         SendMessageW(client, WM_MDIREFRESHMENU, 0, 0);
597         MDI_PostUpdate(GetParent(child), ci, SB_BOTH+1);
598         DestroyWindow(child);
599     }
600 
601     TRACE("child destroyed - %p\n", child);
602     return 0;
603 }
604 
605 
606 /**********************************************************************
607  *                                      MDI_ChildActivate
608  *
609  * Called in response to WM_CHILDACTIVATE, or when last MDI child
610  * is being deactivated.
611  */
612 static LONG MDI_ChildActivate( HWND client, HWND child )
613 {
614     MDICLIENTINFO *clientInfo;
615     HWND prevActiveWnd, frame;
616     BOOL isActiveFrameWnd;
617 
618     clientInfo = get_client_info( client );
619 
620     if (clientInfo->hwndActiveChild == child) return 0;
621 
622     TRACE("%p\n", child);
623 
624     frame = GetParent(client);
625     isActiveFrameWnd = (GetActiveWindow() == frame);
626     prevActiveWnd = clientInfo->hwndActiveChild;
627 
628     /* deactivate prev. active child */
629     if(prevActiveWnd)
630     {
631         SendMessageW( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
632         SendMessageW( prevActiveWnd, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child);
633     }
634 
635     MDI_SwitchActiveChild( clientInfo, child, FALSE );
636     clientInfo->hwndActiveChild = child;
637 
638     MDI_RefreshMenu(clientInfo);
639 
640     if( isActiveFrameWnd )
641     {
642         SendMessageW( child, WM_NCACTIVATE, TRUE, 0L);
643         /* Let the client window manage focus for children, but if the focus
644          * is already on the client (for instance this is the 1st child) then
645          * SetFocus won't work. It appears that Windows sends WM_SETFOCUS
646          * manually in this case.
647          */
648         if (SetFocus(client) == client)
649             SendMessageW( client, WM_SETFOCUS, (WPARAM)client, 0 );
650     }
651 
652     SendMessageW( child, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child );
653     return TRUE;
654 }
655 
656 /* -------------------- MDI client window functions ------------------- */
657 
658 /**********************************************************************
659  *                              CreateMDIMenuBitmap
660  */
661 static HBITMAP CreateMDIMenuBitmap(void)
662 {
663  HDC            hDCSrc  = CreateCompatibleDC(0);
664  HDC            hDCDest = CreateCompatibleDC(hDCSrc);
665  HBITMAP        hbClose = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_OLD_CLOSE) );
666  HBITMAP        hbCopy;
667  HBITMAP        hobjSrc, hobjDest;
668 
669  hobjSrc = SelectObject(hDCSrc, hbClose);
670  hbCopy = CreateCompatibleBitmap(hDCSrc,GetSystemMetrics(SM_CXSIZE),GetSystemMetrics(SM_CYSIZE));
671  hobjDest = SelectObject(hDCDest, hbCopy);
672 
673  BitBlt(hDCDest, 0, 0, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE),
674           hDCSrc, GetSystemMetrics(SM_CXSIZE), 0, SRCCOPY);
675 
676  SelectObject(hDCSrc, hobjSrc);
677  DeleteObject(hbClose);
678  DeleteDC(hDCSrc);
679 
680  hobjSrc = SelectObject( hDCDest, GetStockObject(BLACK_PEN) );
681 
682  MoveToEx( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, 0, NULL );
683  LineTo( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, GetSystemMetrics(SM_CYSIZE) - 1);
684 
685  SelectObject(hDCDest, hobjSrc );
686  SelectObject(hDCDest, hobjDest);
687  DeleteDC(hDCDest);
688 
689  return hbCopy;
690 }
691 
692 /**********************************************************************
693  *                              MDICascade
694  */
695 static LONG MDICascade( HWND client, MDICLIENTINFO *ci )
696 {
697     HWND *win_array;
698     BOOL has_icons = FALSE;
699     int i, total;
700 
701     if (ci->hwndChildMaximized)
702         SendMessageW(client, WM_MDIRESTORE, (WPARAM)ci->hwndChildMaximized, 0);
703 
704     if (ci->nActiveChildren == 0) return 0;
705 
706     if (!(win_array = WIN_ListChildren( client ))) return 0;
707 
708     /* remove all the windows we don't want */
709     for (i = total = 0; win_array[i]; i++)
710     {
711         if (!IsWindowVisible( win_array[i] )) continue;
712         if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows */
713         if (IsIconic( win_array[i] ))
714         {
715             has_icons = TRUE;
716             continue;
717         }
718         win_array[total++] = win_array[i];
719     }
720     win_array[total] = 0;
721 
722     if (total)
723     {
724         INT delta = 0, n = 0, i;
725         POINT pos[2];
726         if (has_icons) delta = GetSystemMetrics(SM_CYICONSPACING) + GetSystemMetrics(SM_CYICON);
727 
728         /* walk the list (backwards) and move windows */
729         for (i = total - 1; i >= 0; i--)
730         {
731             LONG style;
732             LONG posOptions = SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER;
733 
734             MDI_CalcDefaultChildPos(client, n++, pos, delta, NULL);
735             TRACE("move %p to (%d,%d) size [%d,%d]\n",
736                   win_array[i], pos[0].x, pos[0].y, pos[1].x, pos[1].y);
737             style = GetWindowLongW(win_array[i], GWL_STYLE);
738 
739             if (!(style & WS_SIZEBOX)) posOptions |= SWP_NOSIZE;
740             SetWindowPos( win_array[i], 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
741                            posOptions);
742         }
743     }
744     HeapFree( GetProcessHeap(), 0, win_array );
745 
746     if (has_icons) ArrangeIconicWindows( client );
747     return 0;
748 }
749 
750 /**********************************************************************
751  *                                      MDITile
752  */
753 static void MDITile( HWND client, MDICLIENTINFO *ci, WPARAM wParam )
754 {
755     HWND *win_array;
756     int i, total;
757     BOOL has_icons = FALSE;
758 
759     if (ci->hwndChildMaximized)
760         SendMessageW(client, WM_MDIRESTORE, (WPARAM)ci->hwndChildMaximized, 0);
761 
762     if (ci->nActiveChildren == 0) return;
763 
764     if (!(win_array = WIN_ListChildren( client ))) return;
765 
766     /* remove all the windows we don't want */
767     for (i = total = 0; win_array[i]; i++)
768     {
769         if (!IsWindowVisible( win_array[i] )) continue;
770         if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows (icon titles) */
771         if (IsIconic( win_array[i] ))
772         {
773             has_icons = TRUE;
774             continue;
775         }
776         if ((wParam & MDITILE_SKIPDISABLED) && !IsWindowEnabled( win_array[i] )) continue;
777         win_array[total++] = win_array[i];
778     }
779     win_array[total] = 0;
780 
781     TRACE("%u windows to tile\n", total);
782 
783     if (total)
784     {
785         HWND *pWnd = win_array;
786         RECT rect;
787         int x, y, xsize, ysize;
788         int rows, columns, r, c, i;
789 
790         GetClientRect(client,&rect);
791         rows    = (int) sqrt((double)total);
792         columns = total / rows;
793 
794         if( wParam & MDITILE_HORIZONTAL )  /* version >= 3.1 */
795         {
796             i = rows;
797             rows = columns;  /* exchange r and c */
798             columns = i;
799         }
800 
801         if (has_icons)
802         {
803             y = rect.bottom - 2 * GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
804             rect.bottom = ( y - GetSystemMetrics(SM_CYICON) < rect.top )? rect.bottom: y;
805         }
806 
807         ysize   = rect.bottom / rows;
808         xsize   = rect.right  / columns;
809 
810         for (x = i = 0, c = 1; c <= columns && *pWnd; c++)
811         {
812             if (c == columns)
813             {
814                 rows  = total - i;
815                 ysize = rect.bottom / rows;
816             }
817 
818             y = 0;
819             for (r = 1; r <= rows && *pWnd; r++, i++)
820             {
821                 LONG posOptions = SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER;
822                 LONG style = GetWindowLongW(win_array[i], GWL_STYLE);
823                 if (!(style & WS_SIZEBOX)) posOptions |= SWP_NOSIZE;
824 
825                 SetWindowPos(*pWnd, 0, x, y, xsize, ysize, posOptions);
826                 y += ysize;
827                 pWnd++;
828             }
829             x += xsize;
830         }
831     }
832     HeapFree( GetProcessHeap(), 0, win_array );
833     if (has_icons) ArrangeIconicWindows( client );
834 }
835 
836 /* ----------------------- Frame window ---------------------------- */
837 
838 
839 /**********************************************************************
840  *                                      MDI_AugmentFrameMenu
841  */
842 static BOOL MDI_AugmentFrameMenu( HWND frame, HWND hChild )
843 {
844     HMENU menu = GetMenu( frame );
845     HMENU       hSysPopup = 0;
846     HBITMAP hSysMenuBitmap = 0;
847     HICON hIcon;
848 
849     TRACE("frame %p,child %p\n",frame,hChild);
850 
851     if( !menu ) return 0;
852 
853     /* create a copy of sysmenu popup and insert it into frame menu bar */
854     if (!(hSysPopup = GetSystemMenu(hChild, FALSE)))
855     {
856         TRACE("child %p doesn't have a system menu\n", hChild);
857         return 0;
858     }
859 
860     AppendMenuW(menu, MF_HELP | MF_BITMAP,
861                 SC_CLOSE, is_close_enabled(hChild, hSysPopup) ?
862                 (LPCWSTR)HBMMENU_MBAR_CLOSE : (LPCWSTR)HBMMENU_MBAR_CLOSE_D );
863     AppendMenuW(menu, MF_HELP | MF_BITMAP,
864                 SC_RESTORE, (LPCWSTR)HBMMENU_MBAR_RESTORE );
865     AppendMenuW(menu, MF_HELP | MF_BITMAP,
866                 SC_MINIMIZE, (LPCWSTR)HBMMENU_MBAR_MINIMIZE ) ;
867 
868     /* The system menu is replaced by the child icon */
869     hIcon = (HICON)SendMessageW(hChild, WM_GETICON, ICON_SMALL, 0);
870     if (!hIcon)
871         hIcon = (HICON)SendMessageW(hChild, WM_GETICON, ICON_BIG, 0);
872     if (!hIcon)
873         hIcon = LoadImageW(0, MAKEINTRESOURCEW(IDI_WINLOGO), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
874     if (hIcon)
875     {
876       HDC hMemDC;
877       HBITMAP hBitmap, hOldBitmap;
878       HBRUSH hBrush;
879       HDC hdc = GetDC(hChild);
880 
881       if (hdc)
882       {
883         int cx, cy;
884         cx = GetSystemMetrics(SM_CXSMICON);
885         cy = GetSystemMetrics(SM_CYSMICON);
886         hMemDC = CreateCompatibleDC(hdc);
887         hBitmap = CreateCompatibleBitmap(hdc, cx, cy);
888         hOldBitmap = SelectObject(hMemDC, hBitmap);
889         SetMapMode(hMemDC, MM_TEXT);
890         hBrush = CreateSolidBrush(GetSysColor(COLOR_MENU));
891         DrawIconEx(hMemDC, 0, 0, hIcon, cx, cy, 0, hBrush, DI_NORMAL);
892         SelectObject (hMemDC, hOldBitmap);
893         DeleteObject(hBrush);
894         DeleteDC(hMemDC);
895         ReleaseDC(hChild, hdc);
896         hSysMenuBitmap = hBitmap;
897       }
898     }
899 
900     if( !InsertMenuA(menu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
901                      (UINT_PTR)hSysPopup, (LPSTR)hSysMenuBitmap))
902     {
903         TRACE("not inserted\n");
904         DestroyMenu(hSysPopup);
905         return 0;
906     }
907 
908     EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
909     EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
910     EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
911     SetMenuDefaultItem(hSysPopup, SC_CLOSE, FALSE);
912 
913     /* redraw menu */
914     DrawMenuBar(frame);
915 
916     return 1;
917 }
918 
919 /**********************************************************************
920  *                                      MDI_RestoreFrameMenu
921  */
922 static BOOL MDI_RestoreFrameMenu( HWND frame, HWND hChild )
923 {
924     MENUITEMINFOW menuInfo;
925     HMENU menu = GetMenu( frame );
926     INT nItems;
927     UINT iId;
928 
929     TRACE("frame %p, child %p\n", frame, hChild);
930 
931     if( !menu ) return 0;
932 
933     /* if there is no system buttons then nothing to do */
934     nItems = GetMenuItemCount(menu) - 1;
935     iId = GetMenuItemID(menu, nItems);
936     if ( !(iId == SC_RESTORE || iId == SC_CLOSE) )
937         return 0;
938 
939     /*
940      * Remove the system menu, If that menu is the icon of the window
941      * as it is in win95, we have to delete the bitmap.
942      */
943     memset(&menuInfo, 0, sizeof(menuInfo));
944     menuInfo.cbSize = sizeof(menuInfo);
945     menuInfo.fMask  = MIIM_DATA | MIIM_TYPE;
946 
947     GetMenuItemInfoW(menu,
948                      0,
949                      TRUE,
950                      &menuInfo);
951 
952     RemoveMenu(menu,0,MF_BYPOSITION);
953 
954     if ( (menuInfo.fType & MFT_BITMAP)           &&
955          (LOWORD(menuInfo.dwTypeData)!=0)        &&
956          (LOWORD(menuInfo.dwTypeData)!=HBITMAP_16(hBmpClose)) )
957     {
958         DeleteObject(HBITMAP_32(LOWORD(menuInfo.dwTypeData)));
959     }
960 
961     /* close */
962     DeleteMenu(menu, SC_CLOSE, MF_BYCOMMAND);
963     /* restore */
964     DeleteMenu(menu, SC_RESTORE, MF_BYCOMMAND);
965     /* minimize */
966     DeleteMenu(menu, SC_MINIMIZE, MF_BYCOMMAND);
967 
968     DrawMenuBar(frame);
969 
970     return 1;
971 }
972 
973 
974 /**********************************************************************
975  *                                      MDI_UpdateFrameText
976  *
977  * used when child window is maximized/restored
978  *
979  * Note: lpTitle can be NULL
980  */
981 static void MDI_UpdateFrameText( HWND frame, HWND hClient, BOOL repaint, LPCWSTR lpTitle )
982 {
983     WCHAR   lpBuffer[MDI_MAXTITLELENGTH+1];
984     MDICLIENTINFO *ci = get_client_info( hClient );
985 
986     TRACE("frameText %s\n", debugstr_w(lpTitle));
987 
988     if (!ci) return;
989 
990     if (!lpTitle && !ci->frameTitle)  /* first time around, get title from the frame window */
991     {
992         GetWindowTextW( frame, lpBuffer, sizeof(lpBuffer)/sizeof(WCHAR) );
993         lpTitle = lpBuffer;
994     }
995 
996     /* store new "default" title if lpTitle is not NULL */
997     if (lpTitle)
998     {
999         HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1000         if ((ci->frameTitle = HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle)+1)*sizeof(WCHAR))))
1001             strcpyW( ci->frameTitle, lpTitle );
1002     }
1003 
1004     if (ci->frameTitle)
1005     {
1006         if (ci->hwndChildMaximized)
1007         {
1008             /* combine frame title and child title if possible */
1009 
1010             static const WCHAR lpBracket[]  = {' ','-',' ','[',0};
1011             static const WCHAR lpBracket2[]  = {']',0};
1012             int i_frame_text_length = strlenW(ci->frameTitle);
1013 
1014             lstrcpynW( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
1015 
1016             if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
1017             {
1018                 strcatW( lpBuffer, lpBracket );
1019                 if (GetWindowTextW( ci->hwndActiveChild, lpBuffer + i_frame_text_length + 4,
1020                                     MDI_MAXTITLELENGTH - i_frame_text_length - 5 ))
1021                     strcatW( lpBuffer, lpBracket2 );
1022                 else
1023                     lpBuffer[i_frame_text_length] = 0;  /* remove bracket */
1024             }
1025         }
1026         else
1027         {
1028             lstrcpynW(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH+1 );
1029         }
1030     }
1031     else
1032         lpBuffer[0] = '\0';
1033 
1034     DefWindowProcW( frame, WM_SETTEXT, 0, (LPARAM)lpBuffer );
1035 
1036     if (repaint)
1037         SetWindowPos( frame, 0,0,0,0,0, SWP_FRAMECHANGED |
1038                       SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
1039 }
1040 
1041 
1042 /* ----------------------------- Interface ---------------------------- */
1043 
1044 
1045 /**********************************************************************
1046  *              MDIClientWndProc_common
1047  */
1048 static LRESULT MDIClientWndProc_common( HWND hwnd, UINT message,
1049                                         WPARAM wParam, LPARAM lParam, BOOL unicode )
1050 {
1051     MDICLIENTINFO *ci;
1052 
1053     TRACE("%p %04x (%s) %08lx %08lx\n", hwnd, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1054 
1055     if (!(ci = get_client_info( hwnd )))
1056     {
1057         if (message == WM_NCCREATE)
1058         {
1059             WND *wndPtr = WIN_GetPtr( hwnd );
1060             wndPtr->flags |= WIN_ISMDICLIENT;
1061             WIN_ReleasePtr( wndPtr );
1062         }
1063         return unicode ? DefWindowProcW( hwnd, message, wParam, lParam ) :
1064                          DefWindowProcA( hwnd, message, wParam, lParam );
1065     }
1066 
1067     switch (message)
1068     {
1069       case WM_CREATE:
1070       {
1071           /* Since we are using only cs->lpCreateParams, we can safely
1072            * cast to LPCREATESTRUCTA here */
1073           LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
1074           WND *wndPtr = WIN_GetPtr( hwnd );
1075 
1076         /* Translation layer doesn't know what's in the cs->lpCreateParams
1077          * so we have to keep track of what environment we're in. */
1078 
1079         if( wndPtr->flags & WIN_ISWIN32 )
1080         {
1081             LPCLIENTCREATESTRUCT ccs = cs->lpCreateParams;
1082             ci->hWindowMenu     = ccs->hWindowMenu;
1083             ci->idFirstChild    = ccs->idFirstChild;
1084         }
1085         else
1086         {
1087             LPCLIENTCREATESTRUCT16 ccs = MapSL(PtrToUlong(cs->lpCreateParams));
1088             ci->hWindowMenu     = HMENU_32(ccs->hWindowMenu);
1089             ci->idFirstChild    = ccs->idFirstChild;
1090         }
1091         WIN_ReleasePtr( wndPtr );
1092 
1093         ci->hwndChildMaximized  = 0;
1094         ci->child = NULL;
1095         ci->nActiveChildren     = 0;
1096         ci->nTotalCreated       = 0;
1097         ci->frameTitle          = NULL;
1098         ci->mdiFlags            = 0;
1099         ci->hFrameMenu = GetMenu(cs->hwndParent);
1100 
1101         if (!hBmpClose) hBmpClose = CreateMDIMenuBitmap();
1102 
1103         TRACE("Client created: hwnd %p, Window menu %p, idFirst = %04x\n",
1104               hwnd, ci->hWindowMenu, ci->idFirstChild );
1105         return 0;
1106       }
1107 
1108       case WM_DESTROY:
1109       {
1110           if( ci->hwndChildMaximized )
1111               MDI_RestoreFrameMenu(GetParent(hwnd), ci->hwndChildMaximized);
1112 
1113           ci->nActiveChildren = 0;
1114           MDI_RefreshMenu(ci);
1115 
1116           HeapFree( GetProcessHeap(), 0, ci->child );
1117           HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1118 
1119           return 0;
1120       }
1121 
1122       case WM_MDIACTIVATE:
1123       {
1124         if( ci->hwndActiveChild != (HWND)wParam )
1125             SetWindowPos((HWND)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
1126         return 0;
1127       }
1128 
1129       case WM_MDICASCADE:
1130         return MDICascade(hwnd, ci);
1131 
1132       case WM_MDICREATE:
1133         if (lParam)
1134         {
1135             HWND child;
1136 
1137             if (unicode)
1138             {
1139                 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)lParam;
1140                 child = CreateWindowExW(WS_EX_MDICHILD, csW->szClass,
1141                                             csW->szTitle, csW->style,
1142                                             csW->x, csW->y, csW->cx, csW->cy,
1143                                             hwnd, 0, csW->hOwner,
1144                                             (LPVOID)csW->lParam);
1145             }
1146             else
1147             {
1148                 MDICREATESTRUCTA *csA = (MDICREATESTRUCTA *)lParam;
1149                 child = CreateWindowExA(WS_EX_MDICHILD, csA->szClass,
1150                                             csA->szTitle, csA->style,
1151                                             csA->x, csA->y, csA->cx, csA->cy,
1152                                             hwnd, 0, csA->hOwner,
1153                                             (LPVOID)csA->lParam);
1154             }
1155             return (LRESULT)child;
1156         }
1157         return 0;
1158 
1159       case WM_MDIDESTROY:
1160           return MDIDestroyChild( hwnd, ci, WIN_GetFullHandle( (HWND)wParam ), TRUE );
1161 
1162       case WM_MDIGETACTIVE:
1163           if (lParam) *(BOOL *)lParam = IsZoomed(ci->hwndActiveChild);
1164           return (LRESULT)ci->hwndActiveChild;
1165 
1166       case WM_MDIICONARRANGE:
1167         ci->mdiFlags |= MDIF_NEEDUPDATE;
1168         ArrangeIconicWindows( hwnd );
1169         ci->sbRecalc = SB_BOTH+1;
1170         SendMessageW( hwnd, WM_MDICALCCHILDSCROLL, 0, 0 );
1171         return 0;
1172 
1173       case WM_MDIMAXIMIZE:
1174         ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1175         return 0;
1176 
1177       case WM_MDINEXT: /* lParam != 0 means previous window */
1178       {
1179         HWND next = MDI_GetWindow( ci, WIN_GetFullHandle( (HWND)wParam ), !lParam, 0 );
1180         MDI_SwitchActiveChild( ci, next, TRUE );
1181         break;
1182       }
1183 
1184       case WM_MDIRESTORE:
1185         ShowWindow( (HWND)wParam, SW_SHOWNORMAL );
1186         return 0;
1187 
1188       case WM_MDISETMENU:
1189           return MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1190 
1191       case WM_MDIREFRESHMENU:
1192           return MDI_RefreshMenu( ci );
1193 
1194       case WM_MDITILE:
1195         ci->mdiFlags |= MDIF_NEEDUPDATE;
1196         ShowScrollBar( hwnd, SB_BOTH, FALSE );
1197         MDITile( hwnd, ci, wParam );
1198         ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1199         return 0;
1200 
1201       case WM_VSCROLL:
1202       case WM_HSCROLL:
1203         ci->mdiFlags |= MDIF_NEEDUPDATE;
1204         ScrollChildren( hwnd, message, wParam, lParam );
1205         ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1206         return 0;
1207 
1208       case WM_SETFOCUS:
1209           if (ci->hwndActiveChild && !IsIconic( ci->hwndActiveChild ))
1210               SetFocus( ci->hwndActiveChild );
1211           return 0;
1212 
1213       case WM_NCACTIVATE:
1214         if( ci->hwndActiveChild )
1215             SendMessageW(ci->hwndActiveChild, message, wParam, lParam);
1216         break;
1217 
1218       case WM_PARENTNOTIFY:
1219         switch (LOWORD(wParam))
1220         {
1221         case WM_CREATE:
1222             if (GetWindowLongW((HWND)lParam, GWL_EXSTYLE) & WS_EX_MDICHILD)
1223             {
1224                 ci->nTotalCreated++;
1225                 ci->nActiveChildren++;
1226 
1227                 if (!ci->child)
1228                     ci->child = HeapAlloc(GetProcessHeap(), 0, sizeof(HWND));
1229                 else
1230                     ci->child = HeapReAlloc(GetProcessHeap(), 0, ci->child, sizeof(HWND) * ci->nActiveChildren);
1231 
1232                 TRACE("Adding MDI child %p, # of children %d\n",
1233                       (HWND)lParam, ci->nActiveChildren);
1234 
1235                 ci->child[ci->nActiveChildren - 1] = (HWND)lParam;
1236             }
1237             break;
1238 
1239         case WM_LBUTTONDOWN:
1240             {
1241             HWND child;
1242             POINT pt;
1243             pt.x = (short)LOWORD(lParam);
1244             pt.y = (short)HIWORD(lParam);
1245             child = ChildWindowFromPoint(hwnd, pt);
1246 
1247             TRACE("notification from %p (%i,%i)\n",child,pt.x,pt.y);
1248 
1249             if( child && child != hwnd && child != ci->hwndActiveChild )
1250                 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1251             break;
1252             }
1253 
1254         case WM_DESTROY:
1255             return MDIDestroyChild( hwnd, ci, WIN_GetFullHandle( (HWND)lParam ), FALSE );
1256         }
1257         return 0;
1258 
1259       case WM_SIZE:
1260         if( ci->hwndChildMaximized )
1261         {
1262             RECT        rect;
1263 
1264             rect.left = 0;
1265             rect.top = 0;
1266             rect.right = LOWORD(lParam);
1267             rect.bottom = HIWORD(lParam);
1268 
1269             AdjustWindowRectEx( &rect, GetWindowLongA(ci->hwndChildMaximized, GWL_STYLE),
1270                                0, GetWindowLongA(ci->hwndChildMaximized, GWL_EXSTYLE) );
1271             MoveWindow( ci->hwndChildMaximized, rect.left, rect.top,
1272                          rect.right - rect.left, rect.bottom - rect.top, 1);
1273         }
1274         else
1275             MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1276 
1277         break;
1278 
1279       case WM_MDICALCCHILDSCROLL:
1280         if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1281         {
1282             CalcChildScroll(hwnd, ci->sbRecalc-1);
1283             ci->sbRecalc = 0;
1284             ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1285         }
1286         return 0;
1287     }
1288     return unicode ? DefWindowProcW( hwnd, message, wParam, lParam ) :
1289                      DefWindowProcA( hwnd, message, wParam, lParam );
1290 }
1291 
1292 /***********************************************************************
1293  *              MDIClientWndProcA
1294  */
1295 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1296 {
1297     if (!IsWindow(hwnd)) return 0;
1298     return MDIClientWndProc_common( hwnd, message, wParam, lParam, FALSE );
1299 }
1300 
1301 /***********************************************************************
1302  *              MDIClientWndProcW
1303  */
1304 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1305 {
1306     if (!IsWindow(hwnd)) return 0;
1307     return MDIClientWndProc_common( hwnd, message, wParam, lParam, TRUE );
1308 }
1309 
1310 /***********************************************************************
1311  *              DefFrameProcA (USER32.@)
1312  */
1313 LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1314                                 UINT message, WPARAM wParam, LPARAM lParam)
1315 {
1316     if (hwndMDIClient)
1317     {
1318         switch (message)
1319         {
1320         case WM_SETTEXT:
1321             {
1322                 DWORD len = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0 );
1323                 LPWSTR text = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1324                 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, text, len );
1325                 MDI_UpdateFrameText( hwnd, hwndMDIClient, FALSE, text );
1326                 HeapFree( GetProcessHeap(), 0, text );
1327             }
1328             return 1; /* success. FIXME: check text length */
1329 
1330         case WM_COMMAND:
1331         case WM_NCACTIVATE:
1332         case WM_NEXTMENU:
1333         case WM_SETFOCUS:
1334         case WM_SIZE:
1335             return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1336         }
1337     }
1338     return DefWindowProcA(hwnd, message, wParam, lParam);
1339 }
1340 
1341 
1342 /***********************************************************************
1343  *              DefFrameProcW (USER32.@)
1344  */
1345 LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1346                                 UINT message, WPARAM wParam, LPARAM lParam)
1347 {
1348     MDICLIENTINFO *ci = get_client_info( hwndMDIClient );
1349 
1350     TRACE("%p %p %04x (%s) %08lx %08lx\n", hwnd, hwndMDIClient, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1351 
1352     if (ci)
1353     {
1354         switch (message)
1355         {
1356         case WM_COMMAND:
1357             {
1358                 WORD id = LOWORD(wParam);
1359                 /* check for possible syscommands for maximized MDI child */
1360                 if (id <  ci->idFirstChild || id >= ci->idFirstChild + ci->nActiveChildren)
1361                 {
1362                     if( (id - 0xf000) & 0xf00f ) break;
1363                     if( !ci->hwndChildMaximized ) break;
1364                     switch( id )
1365                     {
1366                     case SC_CLOSE:
1367                         if (!is_close_enabled(ci->hwndActiveChild, 0)) break;
1368                     case SC_SIZE:
1369                     case SC_MOVE:
1370                     case SC_MINIMIZE:
1371                     case SC_MAXIMIZE:
1372                     case SC_NEXTWINDOW:
1373                     case SC_PREVWINDOW:
1374                     case SC_RESTORE:
1375                         return SendMessageW( ci->hwndChildMaximized, WM_SYSCOMMAND,
1376                                              wParam, lParam);
1377                     }
1378                 }
1379                 else
1380                 {
1381                     HWND childHwnd;
1382                     if (id - ci->idFirstChild == MDI_MOREWINDOWSLIMIT)
1383                         /* User chose "More Windows..." */
1384                         childHwnd = MDI_MoreWindowsDialog(hwndMDIClient);
1385                     else
1386                         /* User chose one of the windows listed in the "Windows" menu */
1387                         childHwnd = MDI_GetChildByID(hwndMDIClient, id, ci);
1388 
1389                     if( childHwnd )
1390                         SendMessageW( hwndMDIClient, WM_MDIACTIVATE, (WPARAM)childHwnd, 0 );
1391                 }
1392             }
1393             break;
1394 
1395         case WM_NCACTIVATE:
1396             SendMessageW(hwndMDIClient, message, wParam, lParam);
1397             break;
1398 
1399         case WM_SETTEXT:
1400             MDI_UpdateFrameText( hwnd, hwndMDIClient, FALSE, (LPWSTR)lParam );
1401             return 1; /* success. FIXME: check text length */
1402 
1403         case WM_SETFOCUS:
1404             SetFocus(hwndMDIClient);
1405             break;
1406 
1407         case WM_SIZE:
1408             MoveWindow(hwndMDIClient, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
1409             break;
1410 
1411         case WM_NEXTMENU:
1412             {
1413                 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1414 
1415                 if (!IsIconic(hwnd) && ci->hwndActiveChild && !IsZoomed(ci->hwndActiveChild))
1416                 {
1417                     /* control menu is between the frame system menu and
1418                      * the first entry of menu bar */
1419                     WND *wndPtr = WIN_GetPtr(hwnd);
1420 
1421                     if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1422                         (wParam == VK_RIGHT && GetSubMenu(wndPtr->hSysMenu, 0) == next_menu->hmenuIn) )
1423                     {
1424                         WIN_ReleasePtr(wndPtr);
1425                         wndPtr = WIN_GetPtr(ci->hwndActiveChild);
1426                         next_menu->hmenuNext = GetSubMenu(wndPtr->hSysMenu, 0);
1427                         next_menu->hwndNext = ci->hwndActiveChild;
1428                     }
1429                     WIN_ReleasePtr(wndPtr);
1430                 }
1431                 return 0;
1432             }
1433         }
1434     }
1435 
1436     return DefWindowProcW( hwnd, message, wParam, lParam );
1437 }
1438 
1439 /***********************************************************************
1440  *              DefMDIChildProcA (USER32.@)
1441  */
1442 LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1443                                    WPARAM wParam, LPARAM lParam )
1444 {
1445     HWND client = GetParent(hwnd);
1446     MDICLIENTINFO *ci = get_client_info( client );
1447 
1448     TRACE("%p %04x (%s) %08lx %08lx\n", hwnd, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1449 
1450     hwnd = WIN_GetFullHandle( hwnd );
1451     if (!ci) return DefWindowProcA( hwnd, message, wParam, lParam );
1452 
1453     switch (message)
1454     {
1455     case WM_SETTEXT:
1456         DefWindowProcA(hwnd, message, wParam, lParam);
1457         if( ci->hwndChildMaximized == hwnd )
1458             MDI_UpdateFrameText( GetParent(client), client, TRUE, NULL );
1459         return 1; /* success. FIXME: check text length */
1460 
1461     case WM_GETMINMAXINFO:
1462     case WM_MENUCHAR:
1463     case WM_CLOSE:
1464     case WM_SETFOCUS:
1465     case WM_CHILDACTIVATE:
1466     case WM_SYSCOMMAND:
1467     case WM_SHOWWINDOW:
1468     case WM_SETVISIBLE:
1469     case WM_SIZE:
1470     case WM_NEXTMENU:
1471     case WM_SYSCHAR:
1472     case WM_DESTROY:
1473         return DefMDIChildProcW( hwnd, message, wParam, lParam );
1474     }
1475     return DefWindowProcA(hwnd, message, wParam, lParam);
1476 }
1477 
1478 
1479 /***********************************************************************
1480  *              DefMDIChildProcW (USER32.@)
1481  */
1482 LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1483                                    WPARAM wParam, LPARAM lParam )
1484 {
1485     HWND client = GetParent(hwnd);
1486     MDICLIENTINFO *ci = get_client_info( client );
1487 
1488     TRACE("%p %04x (%s) %08lx %08lx\n", hwnd, message, SPY_GetMsgName(message, hwnd), wParam, lParam);
1489 
1490     hwnd = WIN_GetFullHandle( hwnd );
1491     if (!ci) return DefWindowProcW( hwnd, message, wParam, lParam );
1492 
1493     switch (message)
1494     {
1495     case WM_SETTEXT:
1496         DefWindowProcW(hwnd, message, wParam, lParam);
1497         if( ci->hwndChildMaximized == hwnd )
1498             MDI_UpdateFrameText( GetParent(client), client, TRUE, NULL );
1499         return 1; /* success. FIXME: check text length */
1500 
1501     case WM_GETMINMAXINFO:
1502         MDI_ChildGetMinMaxInfo( client, hwnd, (MINMAXINFO *)lParam );
1503         return 0;
1504 
1505     case WM_MENUCHAR:
1506         return 0x00010000; /* MDI children don't have menu bars */
1507 
1508     case WM_CLOSE:
1509         SendMessageW( client, WM_MDIDESTROY, (WPARAM)hwnd, 0 );
1510         return 0;
1511 
1512     case WM_SETFOCUS:
1513         if (ci->hwndActiveChild != hwnd)
1514             MDI_ChildActivate( client, hwnd );
1515         break;
1516 
1517     case WM_CHILDACTIVATE:
1518         MDI_ChildActivate( client, hwnd );
1519         return 0;
1520 
1521     case WM_SYSCOMMAND:
1522         switch (wParam & 0xfff0)
1523         {
1524         case SC_MOVE:
1525             if( ci->hwndChildMaximized == hwnd )
1526                 return 0;
1527             break;
1528         case SC_RESTORE:
1529         case SC_MINIMIZE:
1530             break;
1531         case SC_MAXIMIZE:
1532             if (ci->hwndChildMaximized == hwnd)
1533                 return SendMessageW( GetParent(client), message, wParam, lParam);
1534             break;
1535         case SC_NEXTWINDOW:
1536             SendMessageW( client, WM_MDINEXT, 0, 0);
1537             return 0;
1538         case SC_PREVWINDOW:
1539             SendMessageW( client, WM_MDINEXT, 0, 1);
1540             return 0;
1541         }
1542         break;
1543 
1544     case WM_SHOWWINDOW:
1545     case WM_SETVISIBLE:
1546         if (ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1547         else MDI_PostUpdate(client, ci, SB_BOTH+1);
1548         break;
1549 
1550     case WM_SIZE:
1551         /* This is the only place where we switch to/from maximized state */
1552         /* do not change */
1553         TRACE("current active %p, maximized %p\n", ci->hwndActiveChild, ci->hwndChildMaximized);
1554 
1555         if( ci->hwndChildMaximized == hwnd && wParam != SIZE_MAXIMIZED )
1556         {
1557             HWND frame;
1558 
1559             ci->hwndChildMaximized = 0;
1560 
1561             frame = GetParent(client);
1562             MDI_RestoreFrameMenu( frame, hwnd );
1563             MDI_UpdateFrameText( frame, client, TRUE, NULL );
1564         }
1565 
1566         if( wParam == SIZE_MAXIMIZED )
1567         {
1568             HWND frame, hMaxChild = ci->hwndChildMaximized;
1569 
1570             if( hMaxChild == hwnd ) break;
1571 
1572             if( hMaxChild)
1573             {
1574                 SendMessageW( hMaxChild, WM_SETREDRAW, FALSE, 0 );
1575 
1576                 MDI_RestoreFrameMenu( GetParent(client), hMaxChild );
1577                 ShowWindow( hMaxChild, SW_SHOWNOACTIVATE );
1578 
1579                 SendMessageW( hMaxChild, WM_SETREDRAW, TRUE, 0 );
1580             }
1581 
1582             TRACE("maximizing child %p\n", hwnd );
1583 
1584             /* keep track of the maximized window. */
1585             ci->hwndChildMaximized = hwnd; /* !!! */
1586 
1587             frame = GetParent(client);
1588             MDI_AugmentFrameMenu( frame, hwnd );
1589             MDI_UpdateFrameText( frame, client, TRUE, NULL );
1590         }
1591 
1592         if( wParam == SIZE_MINIMIZED )
1593         {
1594             HWND switchTo = MDI_GetWindow( ci, hwnd, TRUE, WS_MINIMIZE );
1595 
1596             if (!switchTo) switchTo = hwnd;
1597             SendMessageW( switchTo, WM_CHILDACTIVATE, 0, 0 );
1598         }
1599 
1600         MDI_PostUpdate(client, ci, SB_BOTH+1);
1601         break;
1602 
1603     case WM_NEXTMENU:
1604         {
1605             MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1606             HWND parent = GetParent(client);
1607 
1608             if( wParam == VK_LEFT )  /* switch to frame system menu */
1609             {
1610                 WND *wndPtr = WIN_GetPtr( parent );
1611                 next_menu->hmenuNext = GetSubMenu( wndPtr->hSysMenu, 0 );
1612                 WIN_ReleasePtr( wndPtr );
1613             }
1614             if( wParam == VK_RIGHT )  /* to frame menu bar */
1615             {
1616                 next_menu->hmenuNext = GetMenu(parent);
1617             }
1618             next_menu->hwndNext = parent;
1619             return 0;
1620         }
1621 
1622     case WM_SYSCHAR:
1623         if (wParam == '-')
1624         {
1625             SendMessageW( hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (DWORD)VK_SPACE);
1626             return 0;
1627         }
1628         break;
1629 
1630     case WM_DESTROY:
1631         /* Remove itself from the Window menu */
1632         MDI_RefreshMenu(ci);
1633         break;
1634     }
1635     return DefWindowProcW(hwnd, message, wParam, lParam);
1636 }
1637 
1638 /**********************************************************************
1639  *              CreateMDIWindowA (USER32.@) Creates a MDI child
1640  *
1641  * RETURNS
1642  *    Success: Handle to created window
1643  *    Failure: NULL
1644  */
1645 HWND WINAPI CreateMDIWindowA(
1646     LPCSTR lpClassName,    /* [in] Pointer to registered child class name */
1647     LPCSTR lpWindowName,   /* [in] Pointer to window name */
1648     DWORD dwStyle,         /* [in] Window style */
1649     INT X,               /* [in] Horizontal position of window */
1650     INT Y,               /* [in] Vertical position of window */
1651     INT nWidth,          /* [in] Width of window */
1652     INT nHeight,         /* [in] Height of window */
1653     HWND hWndParent,     /* [in] Handle to parent window */
1654     HINSTANCE hInstance, /* [in] Handle to application instance */
1655     LPARAM lParam)         /* [in] Application-defined value */
1656 {
1657     TRACE("(%s,%s,%08x,%d,%d,%d,%d,%p,%p,%08lx)\n",
1658           debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1659           nWidth,nHeight,hWndParent,hInstance,lParam);
1660 
1661     return CreateWindowExA(WS_EX_MDICHILD, lpClassName, lpWindowName,
1662                            dwStyle, X, Y, nWidth, nHeight, hWndParent,
1663                            0, hInstance, (LPVOID)lParam);
1664 }
1665 
1666 /***********************************************************************
1667  *              CreateMDIWindowW (USER32.@) Creates a MDI child
1668  *
1669  * RETURNS
1670  *    Success: Handle to created window
1671  *    Failure: NULL
1672  */
1673 HWND WINAPI CreateMDIWindowW(
1674     LPCWSTR lpClassName,    /* [in] Pointer to registered child class name */
1675     LPCWSTR lpWindowName,   /* [in] Pointer to window name */
1676     DWORD dwStyle,         /* [in] Window style */
1677     INT X,               /* [in] Horizontal position of window */
1678     INT Y,               /* [in] Vertical position of window */
1679     INT nWidth,          /* [in] Width of window */
1680     INT nHeight,         /* [in] Height of window */
1681     HWND hWndParent,     /* [in] Handle to parent window */
1682     HINSTANCE hInstance, /* [in] Handle to application instance */
1683     LPARAM lParam)         /* [in] Application-defined value */
1684 {
1685     TRACE("(%s,%s,%08x,%d,%d,%d,%d,%p,%p,%08lx)\n",
1686           debugstr_w(lpClassName), debugstr_w(lpWindowName), dwStyle, X, Y,
1687           nWidth, nHeight, hWndParent, hInstance, lParam);
1688 
1689     return CreateWindowExW(WS_EX_MDICHILD, lpClassName, lpWindowName,
1690                            dwStyle, X, Y, nWidth, nHeight, hWndParent,
1691                            0, hInstance, (LPVOID)lParam);
1692 }
1693 
1694 /**********************************************************************
1695  *              TranslateMDISysAccel (USER32.@)
1696  */
1697 BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1698 {
1699     if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1700     {
1701         MDICLIENTINFO *ci = get_client_info( hwndClient );
1702         WPARAM wParam = 0;
1703 
1704         if (!ci || !IsWindowEnabled(ci->hwndActiveChild)) return 0;
1705 
1706         /* translate if the Ctrl key is down and Alt not. */
1707 
1708         if( (GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
1709         {
1710             switch( msg->wParam )
1711             {
1712             case VK_F6:
1713             case VK_TAB:
1714                 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 ) ? SC_NEXTWINDOW : SC_PREVWINDOW;
1715                 break;
1716             case VK_F4:
1717             case VK_RBUTTON:
1718                 if (is_close_enabled(ci->hwndActiveChild, 0))
1719                 {
1720                     wParam = SC_CLOSE;
1721                     break;
1722                 }
1723                 /* fall through */
1724             default:
1725                 return 0;
1726             }
1727             TRACE("wParam = %04lx\n", wParam);
1728             SendMessageW(ci->hwndActiveChild, WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
1729             return 1;
1730         }
1731     }
1732     return 0; /* failure */
1733 }
1734 
1735 /***********************************************************************
1736  *              CalcChildScroll (USER32.@)
1737  */
1738 void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
1739 {
1740     SCROLLINFO info;
1741     RECT childRect, clientRect;
1742     HWND *list;
1743 
1744     GetClientRect( hwnd, &clientRect );
1745     SetRectEmpty( &childRect );
1746 
1747     if ((list = WIN_ListChildren( hwnd )))
1748     {
1749         int i;
1750         for (i = 0; list[i]; i++)
1751         {
1752             DWORD style = GetWindowLongW( list[i], GWL_STYLE );
1753             if (style & WS_MAXIMIZE)
1754             {
1755                 HeapFree( GetProcessHeap(), 0, list );
1756                 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1757                 return;
1758             }
1759             if (style & WS_VISIBLE)
1760             {
1761                 RECT rect;
1762                 GetWindowRect( list[i], &rect );
1763                 UnionRect( &childRect, &rect, &childRect );
1764             }
1765         }
1766         HeapFree( GetProcessHeap(), 0, list );
1767     }
1768     MapWindowPoints( 0, hwnd, (POINT *)&childRect, 2 );
1769     UnionRect( &childRect, &clientRect, &childRect );
1770 
1771     /* set common info values */
1772     info.cbSize = sizeof(info);
1773     info.fMask = SIF_POS | SIF_RANGE;
1774 
1775     /* set the specific */
1776     switch( scroll )
1777     {
1778         case SB_BOTH:
1779         case SB_HORZ:
1780                         info.nMin = childRect.left;
1781                         info.nMax = childRect.right - clientRect.right;
1782                         info.nPos = clientRect.left - childRect.left;
1783                         SetScrollInfo(hwnd, SB_HORZ, &info, TRUE);
1784                         if (scroll == SB_HORZ) break;
1785                         /* fall through */
1786         case SB_VERT:
1787                         info.nMin = childRect.top;
1788                         info.nMax = childRect.bottom - clientRect.bottom;
1789                         info.nPos = clientRect.top - childRect.top;
1790                         SetScrollInfo(hwnd, SB_VERT, &info, TRUE);
1791                         break;
1792     }
1793 }
1794 
1795 
1796 /***********************************************************************
1797  *              ScrollChildren (USER32.@)
1798  */
1799 void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
1800                              LPARAM lParam)
1801 {
1802     INT newPos = -1;
1803     INT curPos, length, minPos, maxPos, shift;
1804     RECT rect;
1805 
1806     GetClientRect( hWnd, &rect );
1807 
1808     switch(uMsg)
1809     {
1810     case WM_HSCROLL:
1811         GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
1812         curPos = GetScrollPos(hWnd,SB_HORZ);
1813         length = (rect.right - rect.left) / 2;
1814         shift = GetSystemMetrics(SM_CYHSCROLL);
1815         break;
1816     case WM_VSCROLL:
1817         GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
1818         curPos = GetScrollPos(hWnd,SB_VERT);
1819         length = (rect.bottom - rect.top) / 2;
1820         shift = GetSystemMetrics(SM_CXVSCROLL);
1821         break;
1822     default:
1823         return;
1824     }
1825 
1826     switch( wParam )
1827     {
1828         case SB_LINEUP:
1829                         newPos = curPos - shift;
1830                         break;
1831         case SB_LINEDOWN:
1832                         newPos = curPos + shift;
1833                         break;
1834         case SB_PAGEUP:
1835                         newPos = curPos - length;
1836                         break;
1837         case SB_PAGEDOWN:
1838                         newPos = curPos + length;
1839                         break;
1840 
1841         case SB_THUMBPOSITION:
1842                         newPos = LOWORD(lParam);
1843                         break;
1844 
1845         case SB_THUMBTRACK:
1846                         return;
1847 
1848         case SB_TOP:
1849                         newPos = minPos;
1850                         break;
1851         case SB_BOTTOM:
1852                         newPos = maxPos;
1853                         break;
1854         case SB_ENDSCROLL:
1855                         CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
1856                         return;
1857     }
1858 
1859     if( newPos > maxPos )
1860         newPos = maxPos;
1861     else
1862         if( newPos < minPos )
1863             newPos = minPos;
1864 
1865     SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
1866 
1867     if( uMsg == WM_VSCROLL )
1868         ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
1869                         SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
1870     else
1871         ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
1872                         SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
1873 }
1874 
1875 
1876 /******************************************************************************
1877  *              CascadeWindows (USER32.@) Cascades MDI child windows
1878  *
1879  * RETURNS
1880  *    Success: Number of cascaded windows.
1881  *    Failure: 0
1882  */
1883 WORD WINAPI
1884 CascadeWindows (HWND hwndParent, UINT wFlags, const RECT *lpRect,
1885                 UINT cKids, const HWND *lpKids)
1886 {
1887     FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
1888     return 0;
1889 }
1890 
1891 
1892 /***********************************************************************
1893  *              CascadeChildWindows (USER32.@)
1894  */
1895 WORD WINAPI CascadeChildWindows( HWND parent, UINT flags )
1896 {
1897     return CascadeWindows( parent, flags, NULL, 0, NULL );
1898 }
1899 
1900 
1901 /******************************************************************************
1902  *              TileWindows (USER32.@) Tiles MDI child windows
1903  *
1904  * RETURNS
1905  *    Success: Number of tiled windows.
1906  *    Failure: 0
1907  */
1908 WORD WINAPI
1909 TileWindows (HWND hwndParent, UINT wFlags, const RECT *lpRect,
1910              UINT cKids, const HWND *lpKids)
1911 {
1912     FIXME("(%p,0x%08x,...,%u,...): stub\n", hwndParent, wFlags, cKids);
1913     return 0;
1914 }
1915 
1916 
1917 /***********************************************************************
1918  *              TileChildWindows (USER32.@)
1919  */
1920 WORD WINAPI TileChildWindows( HWND parent, UINT flags )
1921 {
1922     return TileWindows( parent, flags, NULL, 0, NULL );
1923 }
1924 
1925 
1926 /************************************************************************
1927  *              "More Windows..." functionality
1928  */
1929 
1930 /*              MDI_MoreWindowsDlgProc
1931  *
1932  *    This function will process the messages sent to the "More Windows..."
1933  *    dialog.
1934  *    Return values:  0    = cancel pressed
1935  *                    HWND = ok pressed or double-click in the list...
1936  *
1937  */
1938 
1939 static INT_PTR WINAPI MDI_MoreWindowsDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
1940 {
1941     switch (iMsg)
1942     {
1943        case WM_INITDIALOG:
1944        {
1945            UINT widest       = 0;
1946            UINT length;
1947            UINT i;
1948            MDICLIENTINFO *ci = get_client_info( (HWND)lParam );
1949            HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
1950 
1951            for (i = 0; i < ci->nActiveChildren; i++)
1952            {
1953                WCHAR buffer[MDI_MAXTITLELENGTH];
1954 
1955                if (!InternalGetWindowText( ci->child[i], buffer, sizeof(buffer)/sizeof(WCHAR) ))
1956                    continue;
1957                SendMessageW(hListBox, LB_ADDSTRING, 0, (LPARAM)buffer );
1958                SendMessageW(hListBox, LB_SETITEMDATA, i, (LPARAM)ci->child[i] );
1959                length = strlenW(buffer);  /* FIXME: should use GetTextExtentPoint */
1960                if (length > widest)
1961                    widest = length;
1962            }
1963            /* Make sure the horizontal scrollbar scrolls ok */
1964            SendMessageW(hListBox, LB_SETHORIZONTALEXTENT, widest * 6, 0);
1965 
1966            /* Set the current selection */
1967            SendMessageW(hListBox, LB_SETCURSEL, MDI_MOREWINDOWSLIMIT, 0);
1968            return TRUE;
1969        }
1970 
1971        case WM_COMMAND:
1972            switch (LOWORD(wParam))
1973            {
1974                 default:
1975                     if (HIWORD(wParam) != LBN_DBLCLK) break;
1976                     /* fall through */
1977                 case IDOK:
1978                 {
1979                     /*  windows are sorted by menu ID, so we must return the
1980                      *  window associated to the given id
1981                      */
1982                     HWND hListBox     = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
1983                     UINT index        = SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
1984                     LRESULT res = SendMessageW(hListBox, LB_GETITEMDATA, index, 0);
1985                     EndDialog(hDlg, res);
1986                     return TRUE;
1987                 }
1988                 case IDCANCEL:
1989                     EndDialog(hDlg, 0);
1990                     return TRUE;
1991            }
1992            break;
1993     }
1994     return FALSE;
1995 }
1996 
1997 /*
1998  *
1999  *                      MDI_MoreWindowsDialog
2000  *
2001  *     Prompts the user with a listbox containing the opened
2002  *     documents. The user can then choose a windows and click
2003  *     on OK to set the current window to the one selected, or
2004  *     CANCEL to cancel. The function returns a handle to the
2005  *     selected window.
2006  */
2007 
2008 static HWND MDI_MoreWindowsDialog(HWND hwnd)
2009 {
2010     LPCVOID template;
2011     HRSRC hRes;
2012     HANDLE hDlgTmpl;
2013 
2014     hRes = FindResourceA(user32_module, "MDI_MOREWINDOWS", (LPSTR)RT_DIALOG);
2015 
2016     if (hRes == 0)
2017         return 0;
2018 
2019     hDlgTmpl = LoadResource(user32_module, hRes );
2020 
2021     if (hDlgTmpl == 0)
2022         return 0;
2023 
2024     template = LockResource( hDlgTmpl );
2025 
2026     if (template == 0)
2027         return 0;
2028 
2029     return (HWND) DialogBoxIndirectParamA(user32_module,
2030                                           (const DLGTEMPLATE*) template,
2031                                           hwnd, MDI_MoreWindowsDlgProc, (LPARAM) hwnd);
2032 }
2033 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.