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