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