source: trunk/src/user32/mdi.c@ 10367

Last change on this file since 10367 was 9523, checked in by sandervl, 23 years ago

removed obsolete files

File size: 71.8 KB
Line 
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 * Notes: Fairly complete implementation.
10 * Also, Excel and WinWord do _not_ use MDI so if you're trying
11 * to fix them look elsewhere.
12 *
13 * Notes on how the "More Windows..." is implemented:
14 *
15 * When we have more than 9 opened windows, a "More Windows..."
16 * option appears in the "Windows" menu. Each child window has
17 * a WND* associated with it, accesible via the children list of
18 * the parent window. This WND* has a wIDmenu member, which reflects
19 * the position of the child in the window list. For example, with
20 * 9 child windows, we could have the following pattern:
21 *
22 *
23 *
24 * Name of the child window pWndChild->wIDmenu
25 * Doc1 5000
26 * Doc2 5001
27 * Doc3 5002
28 * Doc4 5003
29 * Doc5 5004
30 * Doc6 5005
31 * Doc7 5006
32 * Doc8 5007
33 * Doc9 5008
34 *
35 *
36 * The "Windows" menu, as the "More windows..." dialog, are constructed
37 * in this order. If we add a child, we would have the following list:
38 *
39 *
40 * Name of the child window pWndChild->wIDmenu
41 * Doc1 5000
42 * Doc2 5001
43 * Doc3 5002
44 * Doc4 5003
45 * Doc5 5004
46 * Doc6 5005
47 * Doc7 5006
48 * Doc8 5007
49 * Doc9 5008
50 * Doc10 5009
51 *
52 * But only 5000 to 5008 would be displayed in the "Windows" menu. We want
53 * the last created child to be in the menu, so we swap the last child with
54 * the 9th... Doc9 will be accessible via the "More Windows..." option.
55 *
56 * Doc1 5000
57 * Doc2 5001
58 * Doc3 5002
59 * Doc4 5003
60 * Doc5 5004
61 * Doc6 5005
62 * Doc7 5006
63 * Doc8 5007
64 * Doc9 5009
65 * Doc10 5008
66 *
67 */
68
69#include <stdlib.h>
70#include <stdio.h>
71#include <string.h>
72#include <math.h>
73
74#include "windef.h"
75#include "winbase.h"
76#include "wingdi.h"
77#include "winuser.h"
78#include "wine/unicode.h"
79#include "win.h"
80#include "heap.h"
81#include "controls.h"
82#include "user.h"
83#ifndef __WIN32OS2__
84#include "nonclient.h"
85#include "struct32.h"
86#endif
87#include "debugtools.h"
88#include "dlgs.h"
89
90#ifdef __WIN32OS2__
91#include "pmwindow.h"
92#include <heapstring.h>
93
94#include "ctrlconf.h"
95#endif
96
97DEFAULT_DEBUG_CHANNEL(mdi);
98
99#ifdef __WIN32OS2__
100#include "mdi.h"
101#include <win32wmisc.h>
102#else
103#define MDI_MAXLISTLENGTH 0x40
104#define MDI_MAXTITLELENGTH 0xa1
105
106#define MDI_NOFRAMEREPAINT 0
107#define MDI_REPAINTFRAMENOW 1
108#define MDI_REPAINTFRAME 2
109
110#define WM_MDICALCCHILDSCROLL 0x10ac /* this is exactly what Windows uses */
111
112/* "More Windows..." definitions */
113#define MDI_MOREWINDOWSLIMIT 9 /* after this number of windows, a "More Windows..."
114 option will appear under the Windows menu */
115#define MDI_IDC_LISTBOX 100
116#define MDI_IDS_MOREWINDOWS 13
117
118#define MDIF_NEEDUPDATE 0x0001
119
120typedef struct
121{
122 UINT nActiveChildren;
123 HWND hwndChildMaximized;
124 HWND hwndActiveChild;
125 HMENU hWindowMenu;
126 UINT idFirstChild;
127 LPWSTR frameTitle;
128 UINT nTotalCreated;
129 UINT mdiFlags;
130 UINT sbRecalc; /* SB_xxx flags for scrollbar fixup */
131} MDICLIENTINFO;
132#endif
133
134static HBITMAP hBmpClose = 0;
135static HBITMAP hBmpRestore = 0;
136
137/* ----------------- declarations ----------------- */
138static void MDI_UpdateFrameText( HWND, HWND, BOOL, LPCWSTR);
139static BOOL MDI_AugmentFrameMenu( HWND, HWND );
140static BOOL MDI_RestoreFrameMenu( HWND, HWND );
141static LONG MDI_ChildActivate( HWND, HWND );
142
143static HWND MDI_MoreWindowsDialog(HWND);
144static void MDI_SwapMenuItems(HWND, UINT, UINT);
145static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
146static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
147
148/* -------- Miscellaneous service functions ----------
149 *
150 * MDI_GetChildByID
151 */
152static HWND MDI_GetChildByID(HWND hwnd, UINT id)
153{
154 HWND ret;
155 HWND *win_array;
156 int i;
157
158 if (!(win_array = WIN_ListChildren( hwnd ))) return 0;
159 for (i = 0; win_array[i]; i++)
160 {
161 if (GetWindowLongA( win_array[i], GWL_ID ) == id) break;
162 }
163 ret = win_array[i];
164 HeapFree( GetProcessHeap(), 0, win_array );
165 return ret;
166}
167
168static void MDI_PostUpdate(HWND hwnd, MDICLIENTINFO* ci, WORD recalc)
169{
170 if( !(ci->mdiFlags & MDIF_NEEDUPDATE) )
171 {
172 ci->mdiFlags |= MDIF_NEEDUPDATE;
173 PostMessageA( hwnd, WM_MDICALCCHILDSCROLL, 0, 0);
174 }
175 ci->sbRecalc = recalc;
176}
177
178
179/*********************************************************************
180 * MDIClient class descriptor
181 */
182const struct builtin_class_descr MDICLIENT_builtin_class =
183{
184 "MDIClient", /* name */
185 CS_GLOBALCLASS, /* style */
186 MDIClientWndProcA, /* procA */
187 MDIClientWndProcW, /* procW */
188 sizeof(MDICLIENTINFO), /* extra */
189 IDC_ARROWA, /* cursor */
190 COLOR_APPWORKSPACE+1 /* brush */
191};
192
193#ifndef __WIN32OS2__
194static MDICLIENTINFO *get_client_info( HWND client )
195{
196 MDICLIENTINFO *ret = NULL;
197 WND *win = WIN_FindWndPtr( client );
198 if (win)
199 {
200 if (win->cbWndExtra < sizeof(MDICLIENTINFO)) WARN( "%x is not an MDI client\n", client );
201 else ret = (MDICLIENTINFO *)win->wExtra;
202 WIN_ReleaseWndPtr( win );
203 }
204 return ret;
205}
206
207#endif
208
209/**********************************************************************
210 * MDI_MenuModifyItem
211 */
212static void MDI_MenuModifyItem( HWND client, HWND hWndChild )
213{
214 MDICLIENTINFO *clientInfo = get_client_info( client );
215 WCHAR buffer[128];
216 UINT n, id;
217
218 if (!clientInfo || !clientInfo->hWindowMenu) return;
219
220 id = GetWindowLongA( hWndChild, GWL_ID );
221 if (id >= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT) return;
222 buffer[0] = '&';
223 buffer[1] = '1' + id - clientInfo->idFirstChild;
224 buffer[2] = ' ';
225 GetWindowTextW( hWndChild, buffer + 3, sizeof(buffer)/sizeof(WCHAR) - 3 );
226
227 n = GetMenuState(clientInfo->hWindowMenu, id, MF_BYCOMMAND);
228 ModifyMenuW(clientInfo->hWindowMenu, id, MF_BYCOMMAND | MF_STRING, id, buffer );
229 CheckMenuItem(clientInfo->hWindowMenu, id, n & MF_CHECKED);
230}
231
232/**********************************************************************
233 * MDI_MenuDeleteItem
234 */
235static BOOL MDI_MenuDeleteItem( HWND client, HWND hWndChild )
236{
237 WCHAR buffer[128];
238 static const WCHAR format[] = {'&','%','d',' ',0};
239 MDICLIENTINFO *clientInfo = get_client_info( client );
240 UINT index = 0,id,n;
241
242 if( !clientInfo->nActiveChildren || !clientInfo->hWindowMenu )
243 return FALSE;
244
245 id = GetWindowLongA( hWndChild, GWL_ID );
246 DeleteMenu(clientInfo->hWindowMenu,id,MF_BYCOMMAND);
247
248 /* walk the rest of MDI children to prevent gaps in the id
249 * sequence and in the menu child list */
250
251 for( index = id+1; index <= clientInfo->nActiveChildren +
252 clientInfo->idFirstChild; index++ )
253 {
254 HWND hwnd = MDI_GetChildByID(client,index);
255 if (!hwnd)
256 {
257 TRACE("no window for id=%i\n",index);
258 continue;
259 }
260
261 /* set correct id */
262 SetWindowLongW( hwnd, GWL_ID, GetWindowLongW( hwnd, GWL_ID ) - 1 );
263
264 n = wsprintfW(buffer, format ,index - clientInfo->idFirstChild);
265 GetWindowTextW( hwnd, buffer + n, sizeof(buffer)/sizeof(WCHAR) - n );
266
267 /* change menu if the current child is to be shown in the
268 * "Windows" menu
269 */
270 if (index <= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT)
271 ModifyMenuW(clientInfo->hWindowMenu ,index ,MF_BYCOMMAND | MF_STRING,
272 index - 1 , buffer );
273 }
274
275 /* We must restore the "More Windows..." option if there are enough children
276 */
277 if (clientInfo->nActiveChildren - 1 > MDI_MOREWINDOWSLIMIT)
278 {
279 WCHAR szTmp[50];
280 LoadStringW(GetModuleHandleA("USER32"), MDI_IDS_MOREWINDOWS, szTmp, sizeof(szTmp)/sizeof(szTmp[0]));
281 AppendMenuW(clientInfo->hWindowMenu, MF_STRING, clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT, szTmp);
282 }
283 return TRUE;
284}
285
286/**********************************************************************
287 * MDI_GetWindow
288 *
289 * returns "activateable" child different from the current or zero
290 */
291static HWND MDI_GetWindow(MDICLIENTINFO *clientInfo, HWND hWnd, BOOL bNext,
292 DWORD dwStyleMask )
293{
294 int i;
295 HWND *list;
296 HWND last = 0;
297
298 dwStyleMask |= WS_DISABLED | WS_VISIBLE;
299 if( !hWnd ) hWnd = clientInfo->hwndActiveChild;
300
301 if (!(list = WIN_ListChildren( GetParent(hWnd) ))) return 0;
302 i = 0;
303 /* start from next after hWnd */
304 while (list[i] && list[i] != hWnd) i++;
305 if (list[i]) i++;
306
307 for ( ; list[i]; i++)
308 {
309 if (GetWindow( list[i], GW_OWNER )) continue;
310 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
311 last = list[i];
312 if (bNext) goto found;
313 }
314 /* now restart from the beginning */
315 for (i = 0; list[i] && list[i] != hWnd; i++)
316 {
317 if (GetWindow( list[i], GW_OWNER )) continue;
318 if ((GetWindowLongW( list[i], GWL_STYLE ) & dwStyleMask) != WS_VISIBLE) continue;
319 last = list[i];
320 if (bNext) goto found;
321 }
322 found:
323 HeapFree( GetProcessHeap(), 0, list );
324 return last;
325}
326
327/**********************************************************************
328 * MDI_CalcDefaultChildPos
329 *
330 * It seems that the default height is about 2/3 of the client rect
331 */
332static void MDI_CalcDefaultChildPos( HWND hwnd, WORD n, LPPOINT lpPos, INT delta)
333{
334 INT nstagger;
335 RECT rect;
336 INT spacing = GetSystemMetrics(SM_CYCAPTION) +
337 GetSystemMetrics(SM_CYFRAME) - 1;
338
339 GetClientRect( hwnd, &rect );
340 if( rect.bottom - rect.top - delta >= spacing )
341 rect.bottom -= delta;
342
343 nstagger = (rect.bottom - rect.top)/(3 * spacing);
344 lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
345 lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
346 lpPos[0].x = lpPos[0].y = spacing * (n%(nstagger+1));
347}
348
349/**********************************************************************
350 * MDISetMenu
351 */
352static LRESULT MDISetMenu( HWND hwnd, HMENU hmenuFrame,
353 HMENU hmenuWindow)
354{
355 MDICLIENTINFO *ci;
356 HWND hwndFrame = GetParent(hwnd);
357 HMENU oldFrameMenu = GetMenu(hwndFrame);
358
359 TRACE("%04x %04x %04x\n",
360 hwnd, hmenuFrame, hmenuWindow);
361
362 if (hmenuFrame && !IsMenu(hmenuFrame))
363 {
364 WARN("hmenuFrame is not a menu handle\n");
365 return 0L;
366 }
367
368 if (hmenuWindow && !IsMenu(hmenuWindow))
369 {
370 WARN("hmenuWindow is not a menu handle\n");
371 return 0L;
372 }
373
374 if (!(ci = get_client_info( hwnd ))) return 0;
375
376 if( ci->hwndChildMaximized && hmenuFrame && hmenuFrame!=oldFrameMenu )
377 MDI_RestoreFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
378
379 if( hmenuWindow && ci->hWindowMenu && hmenuWindow!=ci->hWindowMenu )
380 {
381 /* delete menu items from ci->hWindowMenu
382 * and add them to hmenuWindow */
383
384 INT i = GetMenuItemCount(ci->hWindowMenu) - 1;
385 INT pos = GetMenuItemCount(hmenuWindow) + 1;
386
387 AppendMenuA( hmenuWindow, MF_SEPARATOR, 0, NULL);
388
389 if( ci->nActiveChildren )
390 {
391 INT j;
392 LPWSTR buffer = NULL;
393 MENUITEMINFOW mii;
394 INT nbWindowsMenuItems; /* num of documents shown + "More Windows..." if present */
395
396 if (ci->nActiveChildren <= MDI_MOREWINDOWSLIMIT)
397 nbWindowsMenuItems = ci->nActiveChildren;
398 else
399 nbWindowsMenuItems = MDI_MOREWINDOWSLIMIT + 1;
400
401 j = i - nbWindowsMenuItems + 1;
402
403 for( ; i >= j ; i-- )
404 {
405 memset(&mii, 0, sizeof(mii));
406 mii.cbSize = sizeof(mii);
407 mii.fMask = MIIM_CHECKMARKS | MIIM_DATA | MIIM_ID | MIIM_STATE
408 | MIIM_SUBMENU | MIIM_TYPE | MIIM_BITMAP;
409
410 GetMenuItemInfoW(ci->hWindowMenu, i, TRUE, &mii);
411 if(mii.cch) { /* Menu is MFT_STRING */
412 mii.cch++; /* add room for '\0' */
413 buffer = HeapAlloc(GetProcessHeap(), 0,
414 mii.cch * sizeof(WCHAR));
415 mii.dwTypeData = buffer;
416 GetMenuItemInfoW(ci->hWindowMenu, i, TRUE, &mii);
417 }
418 DeleteMenu(ci->hWindowMenu, i, MF_BYPOSITION);
419 InsertMenuItemW(hmenuWindow, pos, TRUE, &mii);
420 if(buffer) {
421 HeapFree(GetProcessHeap(), 0, buffer);
422 buffer = NULL;
423 }
424 }
425 }
426
427 /* remove separator */
428 DeleteMenu(ci->hWindowMenu, i, MF_BYPOSITION);
429
430 ci->hWindowMenu = hmenuWindow;
431 }
432
433 if (hmenuFrame)
434 {
435 SetMenu(hwndFrame, hmenuFrame);
436 if( hmenuFrame!=oldFrameMenu )
437 {
438 if( ci->hwndChildMaximized )
439 MDI_AugmentFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
440 return oldFrameMenu;
441 }
442 }
443 else
444 {
445 HMENU menu = GetMenu( GetParent(hwnd) );
446 INT nItems = GetMenuItemCount(menu) - 1;
447 UINT iId = GetMenuItemID(menu,nItems) ;
448
449 if( !(iId == SC_RESTORE || iId == SC_CLOSE) )
450 {
451 /* SetMenu() may already have been called, meaning that this window
452 * already has its menu. But they may have done a SetMenu() on
453 * an MDI window, and called MDISetMenu() after the fact, meaning
454 * that the "if" to this "else" wouldn't catch the need to
455 * augment the frame menu.
456 */
457 if( ci->hwndChildMaximized )
458 MDI_AugmentFrameMenu( GetParent(hwnd), ci->hwndChildMaximized );
459 }
460 }
461 return 0;
462}
463
464/**********************************************************************
465 * MDIRefreshMenu
466 */
467static LRESULT MDIRefreshMenu( HWND hwnd, HMENU hmenuFrame,
468 HMENU hmenuWindow)
469{
470 HWND hwndFrame = GetParent(hwnd);
471 HMENU oldFrameMenu = GetMenu(hwndFrame);
472
473 TRACE("%04x %04x %04x\n",
474 hwnd, hmenuFrame, hmenuWindow);
475
476 FIXME("partially function stub\n");
477
478 return oldFrameMenu;
479}
480
481
482/* ------------------ MDI child window functions ---------------------- */
483
484
485/**********************************************************************
486 * MDICreateChild
487 */
488static HWND MDICreateChild( HWND parent, MDICLIENTINFO *ci,
489 LPMDICREATESTRUCTA cs, BOOL unicode )
490{
491 POINT pos[2];
492 DWORD style = cs->style | (WS_CHILD | WS_CLIPSIBLINGS);
493 HWND hwnd, hwndMax = 0;
494 UINT wIDmenu = ci->idFirstChild + ci->nActiveChildren;
495#ifndef __WIN32OS2__
496 WND *wndParent;
497#endif
498 static const WCHAR lpstrDef[] = {'j','u','n','k','!',0};
499
500 TRACE("origin %i,%i - dim %i,%i, style %08lx\n",
501 cs->x, cs->y, cs->cx, cs->cy, cs->style);
502 /* calculate placement */
503 MDI_CalcDefaultChildPos(parent, ci->nTotalCreated++, pos, 0);
504
505 if (cs->cx == CW_USEDEFAULT || !cs->cx) cs->cx = pos[1].x;
506 if (cs->cy == CW_USEDEFAULT || !cs->cy) cs->cy = pos[1].y;
507
508 if( cs->x == CW_USEDEFAULT )
509 {
510 cs->x = pos[0].x;
511 cs->y = pos[0].y;
512 }
513
514 /* restore current maximized child */
515 if( (style & WS_VISIBLE) && ci->hwndChildMaximized )
516 {
517 TRACE("Restoring current maximized child %04x\n", ci->hwndChildMaximized);
518 if( style & WS_MAXIMIZE )
519 SendMessageW(parent, WM_SETREDRAW, FALSE, 0L);
520 hwndMax = ci->hwndChildMaximized;
521 ShowWindow( hwndMax, SW_SHOWNOACTIVATE );
522 if( style & WS_MAXIMIZE )
523 SendMessageW(parent, WM_SETREDRAW, TRUE, 0L);
524 }
525
526 if (ci->nActiveChildren <= MDI_MOREWINDOWSLIMIT)
527 /* this menu is needed to set a check mark in MDI_ChildActivate */
528 if (ci->hWindowMenu != 0)
529 AppendMenuW(ci->hWindowMenu, MF_STRING, wIDmenu, lpstrDef);
530
531 ci->nActiveChildren++;
532
533 /* fix window style */
534#ifdef __WIN32OS2__
535 if( !(GetWindowLongA(parent, GWL_STYLE) & MDIS_ALLCHILDSTYLES) )
536#else
537 wndParent = WIN_FindWndPtr( parent );
538 if( !(wndParent->dwStyle & MDIS_ALLCHILDSTYLES) )
539#endif
540 {
541 TRACE("MDIS_ALLCHILDSTYLES is missing, fixing window style\n");
542 style &= (WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZE | WS_MAXIMIZE |
543 WS_CLIPCHILDREN | WS_DISABLED | WS_VSCROLL | WS_HSCROLL );
544 style |= (WS_VISIBLE | WS_OVERLAPPEDWINDOW);
545 }
546
547#ifndef __WIN32OS2__
548 if( wndParent->flags & WIN_ISWIN32 )
549 {
550 WIN_ReleaseWndPtr( wndParent );
551#endif
552 if(unicode)
553 {
554 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)cs;
555 hwnd = CreateWindowW( csW->szClass, csW->szTitle, style,
556 csW->x, csW->y, csW->cx, csW->cy, parent,
557 (HMENU)wIDmenu, csW->hOwner, csW );
558 }
559 else
560 hwnd = CreateWindowA( cs->szClass, cs->szTitle, style,
561 cs->x, cs->y, cs->cx, cs->cy, parent,
562 (HMENU)wIDmenu, cs->hOwner, cs );
563#ifndef __WIN32OS2__
564 }
565 else
566 {
567 MDICREATESTRUCT16 *cs16;
568 LPSTR title, cls;
569
570 WIN_ReleaseWndPtr( wndParent );
571 cs16 = SEGPTR_NEW(MDICREATESTRUCT16);
572 STRUCT32_MDICREATESTRUCT32Ato16( cs, cs16 );
573 title = SEGPTR_STRDUP( cs->szTitle );
574 cls = SEGPTR_STRDUP( cs->szClass );
575 cs16->szTitle = SEGPTR_GET(title);
576 cs16->szClass = SEGPTR_GET(cls);
577
578 hwnd = CreateWindow16( cs->szClass, cs->szTitle, style,
579 cs16->x, cs16->y, cs16->cx, cs16->cy, parent,
580 (HMENU)wIDmenu, cs16->hOwner,
581 (LPVOID)SEGPTR_GET(cs16) );
582 SEGPTR_FREE( title );
583 SEGPTR_FREE( cls );
584 SEGPTR_FREE( cs16 );
585 }
586#endif
587 /* MDI windows are WS_CHILD so they won't be activated by CreateWindow */
588
589 if (hwnd)
590 {
591 /* All MDI child windows have the WS_EX_MDICHILD style */
592 SetWindowLongW( hwnd, GWL_EXSTYLE, GetWindowLongW( hwnd, GWL_EXSTYLE ) | WS_EX_MDICHILD );
593
594 /* If we have more than 9 windows, we must insert the new one at the
595 * 9th position in order to see it in the "Windows" menu
596 */
597 if (ci->nActiveChildren > MDI_MOREWINDOWSLIMIT)
598 MDI_SwapMenuItems( parent, GetWindowLongW( hwnd, GWL_ID ),
599 ci->idFirstChild + MDI_MOREWINDOWSLIMIT - 1);
600
601 MDI_MenuModifyItem(parent, hwnd);
602
603 /* Have we hit the "More Windows..." limit? If so, we must
604 * add a "More Windows..." option
605 */
606 if (ci->nActiveChildren == MDI_MOREWINDOWSLIMIT + 1)
607 {
608 WCHAR szTmp[50];
609 LoadStringW(GetModuleHandleA("USER32"), MDI_IDS_MOREWINDOWS, szTmp, sizeof(szTmp)/sizeof(szTmp[0]));
610
611 ModifyMenuW(ci->hWindowMenu,
612 ci->idFirstChild + MDI_MOREWINDOWSLIMIT,
613 MF_BYCOMMAND | MF_STRING,
614 ci->idFirstChild + MDI_MOREWINDOWSLIMIT,
615 szTmp);
616 }
617
618 if( IsIconic(hwnd) && ci->hwndActiveChild )
619 {
620 TRACE("Minimizing created MDI child %04x\n", hwnd);
621 ShowWindow( hwnd, SW_SHOWMINNOACTIVE );
622 }
623 else
624 {
625 /* WS_VISIBLE is clear if a) the MDI client has
626 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
627 * MDICreateStruct. If so the created window is not shown nor
628 * activated.
629 */
630 if (IsWindowVisible(hwnd)) ShowWindow(hwnd, SW_SHOW);
631 }
632 TRACE("created child - %04x\n",hwnd);
633 }
634 else
635 {
636 ci->nActiveChildren--;
637 DeleteMenu(ci->hWindowMenu,wIDmenu,MF_BYCOMMAND);
638 if( IsWindow(hwndMax) )
639 ShowWindow(hwndMax, SW_SHOWMAXIMIZED);
640 }
641
642 return hwnd;
643}
644
645/**********************************************************************
646 * MDI_ChildGetMinMaxInfo
647 *
648 * Note: The rule here is that client rect of the maximized MDI child
649 * is equal to the client rect of the MDI client window.
650 */
651static void MDI_ChildGetMinMaxInfo( HWND client, HWND hwnd, MINMAXINFO* lpMinMax )
652{
653 RECT rect;
654
655 GetClientRect( client, &rect );
656 AdjustWindowRectEx( &rect, GetWindowLongW( hwnd, GWL_STYLE ),
657 0, GetWindowLongW( hwnd, GWL_EXSTYLE ));
658
659 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
660 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
661
662 lpMinMax->ptMaxPosition.x = rect.left;
663 lpMinMax->ptMaxPosition.y = rect.top;
664
665 TRACE("max rect (%i,%i - %i, %i)\n",
666 rect.left,rect.top,rect.right,rect.bottom);
667}
668
669/**********************************************************************
670 * MDI_SwitchActiveChild
671 *
672 * Note: SetWindowPos sends WM_CHILDACTIVATE to the child window that is
673 * being activated
674 */
675static void MDI_SwitchActiveChild( HWND clientHwnd, HWND childHwnd,
676 BOOL bNextWindow )
677{
678 HWND hwndTo = 0;
679 HWND hwndPrev = 0;
680 MDICLIENTINFO *ci = get_client_info( clientHwnd );
681
682 hwndTo = MDI_GetWindow(ci, childHwnd, bNextWindow, 0);
683
684 TRACE("from %04x, to %04x\n",childHwnd,hwndTo);
685
686 if ( !hwndTo ) return; /* no window to switch to */
687
688 hwndPrev = ci->hwndActiveChild;
689
690 if ( hwndTo != hwndPrev )
691 {
692 SetWindowPos( hwndTo, HWND_TOP, 0, 0, 0, 0,
693 SWP_NOMOVE | SWP_NOSIZE );
694
695 if( bNextWindow && hwndPrev )
696 SetWindowPos( hwndPrev, HWND_BOTTOM, 0, 0, 0, 0,
697 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
698 }
699}
700
701
702/**********************************************************************
703 * MDIDestroyChild
704 */
705static LRESULT MDIDestroyChild( HWND parent, MDICLIENTINFO *ci,
706 HWND child, BOOL flagDestroy )
707{
708 if( child == ci->hwndActiveChild )
709 {
710 MDI_SwitchActiveChild(parent, child, TRUE);
711
712 if( child == ci->hwndActiveChild )
713 {
714 ShowWindow( child, SW_HIDE);
715 if( child == ci->hwndChildMaximized )
716 {
717 HWND frame = GetParent(parent);
718 MDI_RestoreFrameMenu( frame, child );
719 ci->hwndChildMaximized = 0;
720 MDI_UpdateFrameText( frame, parent, TRUE, NULL);
721 }
722
723 MDI_ChildActivate(parent, 0);
724 }
725 }
726
727 MDI_MenuDeleteItem(parent, child);
728
729 ci->nActiveChildren--;
730
731 TRACE("child destroyed - %04x\n",child);
732
733 if (flagDestroy)
734 {
735 MDI_PostUpdate(GetParent(child), ci, SB_BOTH+1);
736 DestroyWindow(child);
737 }
738 return 0;
739}
740
741
742/**********************************************************************
743 * MDI_ChildActivate
744 *
745 * Note: hWndChild is NULL when last child is being destroyed
746 */
747static LONG MDI_ChildActivate( HWND client, HWND child )
748{
749 MDICLIENTINFO *clientInfo = get_client_info( client );
750 HWND prevActiveWnd = clientInfo->hwndActiveChild;
751 BOOL isActiveFrameWnd;
752
753#ifdef __WIN32OS2__
754 if (!IsWindowEnabled( child )) {
755 clientInfo->hwndActiveChild = 0;
756 return 0;
757 }
758#else
759 if (!IsWindowEnabled( child )) return 0;
760#endif
761
762 /* Don't activate if it is already active. Might happen
763 since ShowWindow DOES activate MDI children */
764 if (clientInfo->hwndActiveChild == child) return 0;
765
766 TRACE("%04x\n", child);
767
768 isActiveFrameWnd = (GetActiveWindow() == GetParent(client));
769
770 /* deactivate prev. active child */
771 if(prevActiveWnd)
772 {
773 SetWindowLongA( prevActiveWnd, GWL_STYLE,
774 GetWindowLongA( prevActiveWnd, GWL_STYLE ) | WS_SYSMENU );
775 SendMessageA( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
776 SendMessageA( prevActiveWnd, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child);
777 /* uncheck menu item */
778 if( clientInfo->hWindowMenu )
779 {
780 UINT prevID = GetWindowLongA( prevActiveWnd, GWL_ID );
781
782 if (prevID - clientInfo->idFirstChild < MDI_MOREWINDOWSLIMIT)
783 CheckMenuItem( clientInfo->hWindowMenu, prevID, 0);
784 else
785 CheckMenuItem( clientInfo->hWindowMenu,
786 clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1, 0);
787 }
788 }
789
790 /* set appearance */
791 if (clientInfo->hwndChildMaximized && clientInfo->hwndChildMaximized != child)
792 {
793 if( child )
794 {
795 clientInfo->hwndActiveChild = child;
796 ShowWindow( child, SW_SHOWMAXIMIZED);
797 }
798 else ShowWindow( clientInfo->hwndActiveChild, SW_SHOWNORMAL );
799 }
800
801 clientInfo->hwndActiveChild = child;
802
803 /* check if we have any children left */
804 if( !child )
805 {
806 if( isActiveFrameWnd )
807 SetFocus( client );
808 return 0;
809 }
810
811 /* check menu item */
812 if( clientInfo->hWindowMenu )
813 {
814 UINT id = GetWindowLongA( child, GWL_ID );
815 /* The window to be activated must be displayed in the "Windows" menu */
816 if (id >= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT)
817 {
818 MDI_SwapMenuItems( GetParent(child),
819 id, clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1);
820 id = clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1;
821 MDI_MenuModifyItem( GetParent(child), child );
822 }
823
824 CheckMenuItem(clientInfo->hWindowMenu, id, MF_CHECKED);
825 }
826 /* bring active child to the top */
827 SetWindowPos( child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
828
829 if( isActiveFrameWnd )
830 {
831 SendMessageA( child, WM_NCACTIVATE, TRUE, 0L);
832 if( GetFocus() == client )
833 SendMessageA( client, WM_SETFOCUS, (WPARAM)client, 0L );
834 else
835 SetFocus( client );
836 }
837 SendMessageA( child, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child );
838 return TRUE;
839}
840
841/* -------------------- MDI client window functions ------------------- */
842
843/**********************************************************************
844 * CreateMDIMenuBitmap
845 */
846static HBITMAP CreateMDIMenuBitmap(void)
847{
848 HDC hDCSrc = CreateCompatibleDC(0);
849 HDC hDCDest = CreateCompatibleDC(hDCSrc);
850 HBITMAP hbClose = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_CLOSE) );
851 HBITMAP hbCopy;
852 HBITMAP hobjSrc, hobjDest;
853
854 hobjSrc = SelectObject(hDCSrc, hbClose);
855 hbCopy = CreateCompatibleBitmap(hDCSrc,GetSystemMetrics(SM_CXSIZE),GetSystemMetrics(SM_CYSIZE));
856 hobjDest = SelectObject(hDCDest, hbCopy);
857
858 BitBlt(hDCDest, 0, 0, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE),
859 hDCSrc, GetSystemMetrics(SM_CXSIZE), 0, SRCCOPY);
860
861 SelectObject(hDCSrc, hobjSrc);
862 DeleteObject(hbClose);
863 DeleteDC(hDCSrc);
864
865 hobjSrc = SelectObject( hDCDest, GetStockObject(BLACK_PEN) );
866
867 MoveToEx( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, 0, NULL );
868 LineTo( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, GetSystemMetrics(SM_CYSIZE) - 1);
869
870 SelectObject(hDCDest, hobjSrc );
871 SelectObject(hDCDest, hobjDest);
872 DeleteDC(hDCDest);
873
874 return hbCopy;
875}
876
877/**********************************************************************
878 * MDICascade
879 */
880static LONG MDICascade( HWND client, MDICLIENTINFO *ci )
881{
882 HWND *win_array;
883 BOOL has_icons = FALSE;
884 int i, total;
885
886 if (ci->hwndChildMaximized)
887 SendMessageA( client, WM_MDIRESTORE,
888 (WPARAM)ci->hwndChildMaximized, 0);
889
890 if (ci->nActiveChildren == 0) return 0;
891
892 if (!(win_array = WIN_ListChildren( client ))) return 0;
893
894 /* remove all the windows we don't want */
895 for (i = total = 0; win_array[i]; i++)
896 {
897 if (!IsWindowVisible( win_array[i] )) continue;
898 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows */
899 if (IsIconic( win_array[i] ))
900 {
901 has_icons = TRUE;
902 continue;
903 }
904 win_array[total++] = win_array[i];
905 }
906 win_array[total] = 0;
907
908 if (total)
909 {
910 INT delta = 0, n = 0, i;
911 POINT pos[2];
912 if (has_icons) delta = GetSystemMetrics(SM_CYICONSPACING) + GetSystemMetrics(SM_CYICON);
913
914 /* walk the list (backwards) and move windows */
915 for (i = total - 1; i >= 0; i--)
916 {
917 TRACE("move %04x to (%ld,%ld) size [%ld,%ld]\n",
918 win_array[i], pos[0].x, pos[0].y, pos[1].x, pos[1].y);
919
920 MDI_CalcDefaultChildPos(client, n++, pos, delta);
921 SetWindowPos( win_array[i], 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
922 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
923 }
924 }
925 HeapFree( GetProcessHeap(), 0, win_array );
926
927 if (has_icons) ArrangeIconicWindows( client );
928 return 0;
929}
930
931/**********************************************************************
932 * MDITile
933 */
934static void MDITile( HWND client, MDICLIENTINFO *ci, WPARAM wParam )
935{
936 HWND *win_array;
937 int i, total;
938 BOOL has_icons = FALSE;
939
940 if (ci->hwndChildMaximized)
941 SendMessageA( client, WM_MDIRESTORE, (WPARAM)ci->hwndChildMaximized, 0);
942
943 if (ci->nActiveChildren == 0) return;
944
945 if (!(win_array = WIN_ListChildren( client ))) return;
946
947 /* remove all the windows we don't want */
948 for (i = total = 0; win_array[i]; i++)
949 {
950 if (!IsWindowVisible( win_array[i] )) continue;
951 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows (icon titles) */
952 if (IsIconic( win_array[i] ))
953 {
954 has_icons = TRUE;
955 continue;
956 }
957 if ((wParam & MDITILE_SKIPDISABLED) && !IsWindowEnabled( win_array[i] )) continue;
958 win_array[total++] = win_array[i];
959 }
960 win_array[total] = 0;
961
962 TRACE("%u windows to tile\n", total);
963
964 if (total)
965 {
966 HWND *pWnd = win_array;
967 RECT rect;
968 int x, y, xsize, ysize;
969 int rows, columns, r, c, i;
970
971 GetClientRect(client,&rect);
972 rows = (int) sqrt((double)total);
973 columns = total / rows;
974
975 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
976 {
977 i = rows;
978 rows = columns; /* exchange r and c */
979 columns = i;
980 }
981
982 if (has_icons)
983 {
984 y = rect.bottom - 2 * GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
985 rect.bottom = ( y - GetSystemMetrics(SM_CYICON) < rect.top )? rect.bottom: y;
986 }
987
988 ysize = rect.bottom / rows;
989 xsize = rect.right / columns;
990
991 for (x = i = 0, c = 1; c <= columns && *pWnd; c++)
992 {
993 if (c == columns)
994 {
995 rows = total - i;
996 ysize = rect.bottom / rows;
997 }
998
999 y = 0;
1000 for (r = 1; r <= rows && *pWnd; r++, i++)
1001 {
1002 SetWindowPos(*pWnd, 0, x, y, xsize, ysize,
1003 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
1004 y += ysize;
1005 pWnd++;
1006 }
1007 x += xsize;
1008 }
1009 }
1010 HeapFree( GetProcessHeap(), 0, win_array );
1011 if (has_icons) ArrangeIconicWindows( client );
1012}
1013
1014/* ----------------------- Frame window ---------------------------- */
1015
1016
1017/**********************************************************************
1018 * MDI_AugmentFrameMenu
1019 */
1020static BOOL MDI_AugmentFrameMenu( HWND frame, HWND hChild )
1021{
1022 HMENU menu = GetMenu( frame );
1023#ifndef __WIN32OS2__
1024 WND* child = WIN_FindWndPtr(hChild);
1025#endif
1026 HMENU hSysPopup = 0;
1027 HBITMAP hSysMenuBitmap = 0;
1028
1029 TRACE("frame %04x,child %04x\n",frame,hChild);
1030
1031#ifdef __WIN32OS2__
1032 if( !menu || !getSysMenu(hChild) )
1033 {
1034 return 0;
1035 }
1036#else
1037 if( !menu || !child->hSysMenu )
1038 {
1039 WIN_ReleaseWndPtr(child);
1040 return 0;
1041 }
1042 WIN_ReleaseWndPtr(child);
1043#endif
1044
1045 /* create a copy of sysmenu popup and insert it into frame menu bar */
1046
1047 if (!(hSysPopup = LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU")))
1048 return 0;
1049
1050#ifdef __WIN32OS2__
1051 if(fOS2Look)
1052 {//different order for OS2 GUI mode
1053 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1054 SC_CLOSE, (LPSTR)(DWORD)HBMMENU_MBAR_CLOSE );
1055 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1056 SC_MINIMIZE, (LPSTR)(DWORD)HBMMENU_MBAR_MINIMIZE ) ;
1057 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1058 SC_RESTORE, (LPSTR)(DWORD)HBMMENU_MBAR_RESTORE );
1059 }
1060 else {
1061#endif
1062 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1063 SC_MINIMIZE, (LPSTR)(DWORD)HBMMENU_MBAR_MINIMIZE ) ;
1064 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1065 SC_RESTORE, (LPSTR)(DWORD)HBMMENU_MBAR_RESTORE );
1066#ifdef __WIN32OS2__
1067 }
1068#endif
1069 /* In Win 95 look, the system menu is replaced by the child icon */
1070
1071#ifndef __WIN32OS2__
1072 if(TWEAK_WineLook > WIN31_LOOK)
1073#endif
1074 {
1075 HICON hIcon = GetClassLongA(hChild, GCL_HICONSM);
1076 if (!hIcon)
1077 hIcon = GetClassLongA(hChild, GCL_HICON);
1078 if (hIcon)
1079 {
1080 HDC hMemDC;
1081 HBITMAP hBitmap, hOldBitmap;
1082 HBRUSH hBrush;
1083 HDC hdc = GetDC(hChild);
1084
1085 if (hdc)
1086 {
1087 int cx, cy;
1088 cx = GetSystemMetrics(SM_CXSMICON);
1089 cy = GetSystemMetrics(SM_CYSMICON);
1090 hMemDC = CreateCompatibleDC(hdc);
1091 hBitmap = CreateCompatibleBitmap(hdc, cx, cy);
1092 hOldBitmap = SelectObject(hMemDC, hBitmap);
1093 SetMapMode(hMemDC, MM_TEXT);
1094 hBrush = CreateSolidBrush(GetSysColor(COLOR_MENU));
1095 DrawIconEx(hMemDC, 0, 0, hIcon, cx, cy, 0, hBrush, DI_NORMAL);
1096 SelectObject (hMemDC, hOldBitmap);
1097 DeleteObject(hBrush);
1098 DeleteDC(hMemDC);
1099 ReleaseDC(hChild, hdc);
1100 hSysMenuBitmap = hBitmap;
1101 }
1102 }
1103 }
1104#ifndef __WIN32OS2__
1105 else
1106 hSysMenuBitmap = hBmpClose;
1107#endif
1108
1109 if( !InsertMenuA(menu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
1110 hSysPopup, (LPSTR)(DWORD)hSysMenuBitmap))
1111 {
1112 TRACE("not inserted\n");
1113 DestroyMenu(hSysPopup);
1114 return 0;
1115 }
1116
1117 /* The close button is only present in Win 95 look */
1118#ifdef __WIN32OS2__
1119 if(!fOS2Look)
1120#else
1121 if(TWEAK_WineLook > WIN31_LOOK)
1122#endif
1123 {
1124 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1125 SC_CLOSE, (LPSTR)(DWORD)HBMMENU_MBAR_CLOSE );
1126 }
1127
1128 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
1129 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
1130 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
1131 SetMenuDefaultItem(hSysPopup, SC_CLOSE, FALSE);
1132
1133 /* redraw menu */
1134 DrawMenuBar(frame);
1135
1136 return 1;
1137}
1138
1139/**********************************************************************
1140 * MDI_RestoreFrameMenu
1141 */
1142static BOOL MDI_RestoreFrameMenu( HWND frame, HWND hChild )
1143{
1144 MENUITEMINFOW menuInfo;
1145 HMENU menu = GetMenu( frame );
1146 INT nItems = GetMenuItemCount(menu) - 1;
1147 UINT iId = GetMenuItemID(menu,nItems) ;
1148
1149 TRACE("frame %04x,child %04x,nIt=%d,iId=%d\n",frame,hChild,nItems,iId);
1150
1151 if(!(iId == SC_RESTORE || iId == SC_CLOSE) )
1152 return 0;
1153
1154 /*
1155 * Remove the system menu, If that menu is the icon of the window
1156 * as it is in win95, we have to delete the bitmap.
1157 */
1158 memset(&menuInfo, 0, sizeof(menuInfo));
1159 menuInfo.cbSize = sizeof(menuInfo);
1160 menuInfo.fMask = MIIM_DATA | MIIM_TYPE;
1161
1162 GetMenuItemInfoW(menu,
1163 0,
1164 TRUE,
1165 &menuInfo);
1166
1167 RemoveMenu(menu,0,MF_BYPOSITION);
1168
1169 if ( (menuInfo.fType & MFT_BITMAP) &&
1170 (LOWORD(menuInfo.dwTypeData)!=0) &&
1171 (LOWORD(menuInfo.dwTypeData)!=hBmpClose) )
1172 {
1173 DeleteObject((HBITMAP)LOWORD(menuInfo.dwTypeData));
1174 }
1175
1176#ifndef __WIN32OS2__
1177 if(TWEAK_WineLook > WIN31_LOOK)
1178 {
1179#endif
1180 /* close */
1181 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1182#ifndef __WIN32OS2__
1183 }
1184#endif
1185 /* restore */
1186 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1187 /* minimize */
1188 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1189
1190 DrawMenuBar(frame);
1191
1192 return 1;
1193}
1194
1195
1196/**********************************************************************
1197 * MDI_UpdateFrameText
1198 *
1199 * used when child window is maximized/restored
1200 *
1201 * Note: lpTitle can be NULL
1202 */
1203static void MDI_UpdateFrameText( HWND frame, HWND hClient,
1204 BOOL repaint, LPCWSTR lpTitle )
1205{
1206 WCHAR lpBuffer[MDI_MAXTITLELENGTH+1];
1207 MDICLIENTINFO *ci = get_client_info( hClient );
1208
1209 TRACE("repaint %i, frameText %s\n", repaint, debugstr_w(lpTitle));
1210
1211 if (!ci) return;
1212
1213 if (!lpTitle && !ci->frameTitle) /* first time around, get title from the frame window */
1214 {
1215 GetWindowTextW( frame, lpBuffer, sizeof(lpBuffer)/sizeof(WCHAR) );
1216 lpTitle = lpBuffer;
1217 }
1218
1219 /* store new "default" title if lpTitle is not NULL */
1220 if (lpTitle)
1221 {
1222 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1223 if ((ci->frameTitle = HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle)+1)*sizeof(WCHAR))))
1224 strcpyW( ci->frameTitle, lpTitle );
1225 }
1226
1227 if (ci->frameTitle)
1228 {
1229 if (ci->hwndChildMaximized)
1230 {
1231 /* combine frame title and child title if possible */
1232
1233 static const WCHAR lpBracket[] = {' ','-',' ','[',0};
1234 static const WCHAR lpBracket2[] = {']',0};
1235 int i_frame_text_length = strlenW(ci->frameTitle);
1236
1237 lstrcpynW( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
1238
1239 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
1240 {
1241 strcatW( lpBuffer, lpBracket );
1242 if (GetWindowTextW( ci->hwndChildMaximized, lpBuffer + i_frame_text_length + 4,
1243 MDI_MAXTITLELENGTH - i_frame_text_length - 5 ))
1244 strcatW( lpBuffer, lpBracket2 );
1245 else
1246 lpBuffer[i_frame_text_length] = 0; /* remove bracket */
1247 }
1248 }
1249 else
1250 {
1251 lstrcpynW(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH+1 );
1252 }
1253 }
1254 else
1255 lpBuffer[0] = '\0';
1256
1257 DefWindowProcW( frame, WM_SETTEXT, 0, (LPARAM)lpBuffer );
1258 if( repaint == MDI_REPAINTFRAME)
1259 SetWindowPos( frame, 0,0,0,0,0, SWP_FRAMECHANGED |
1260 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
1261}
1262
1263
1264/* ----------------------------- Interface ---------------------------- */
1265
1266
1267/**********************************************************************
1268 * MDIClientWndProc_common
1269 */
1270static LRESULT MDIClientWndProc_common( HWND hwnd, UINT message,
1271 WPARAM wParam, LPARAM lParam, BOOL unicode )
1272{
1273 MDICLIENTINFO *ci;
1274
1275 if (!(ci = get_client_info( hwnd ))) return 0;
1276
1277 switch (message)
1278 {
1279 case WM_CREATE:
1280 {
1281 RECT rect;
1282 /* Since we are using only cs->lpCreateParams, we can safely
1283 * cast to LPCREATESTRUCTA here */
1284 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
1285#ifndef __WIN32OS2__
1286 WND *wndPtr = WIN_FindWndPtr( hwnd );
1287
1288 /* Translation layer doesn't know what's in the cs->lpCreateParams
1289 * so we have to keep track of what environment we're in. */
1290
1291 if( wndPtr->flags & WIN_ISWIN32 )
1292 {
1293#endif
1294#define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1295 ci->hWindowMenu = ccs->hWindowMenu;
1296 ci->idFirstChild = ccs->idFirstChild;
1297#undef ccs
1298#ifndef __WIN32OS2__
1299 }
1300 else
1301 {
1302 LPCLIENTCREATESTRUCT16 ccs = MapSL((SEGPTR)cs->lpCreateParams);
1303 ci->hWindowMenu = ccs->hWindowMenu;
1304 ci->idFirstChild = ccs->idFirstChild;
1305 }
1306 WIN_ReleaseWndPtr( wndPtr );
1307#endif
1308
1309 ci->hwndChildMaximized = 0;
1310 ci->nActiveChildren = 0;
1311 ci->nTotalCreated = 0;
1312 ci->frameTitle = NULL;
1313 ci->mdiFlags = 0;
1314 SetWindowLongW( hwnd, GWL_STYLE, GetWindowLongW(hwnd,GWL_STYLE) | WS_CLIPCHILDREN );
1315
1316 if (!hBmpClose)
1317 {
1318 hBmpClose = CreateMDIMenuBitmap();
1319 hBmpRestore = LoadBitmapW( 0, MAKEINTRESOURCEW(OBM_RESTORE) );
1320 }
1321
1322 if (ci->hWindowMenu != 0)
1323 AppendMenuW( ci->hWindowMenu, MF_SEPARATOR, 0, NULL );
1324
1325 GetClientRect( GetParent(hwnd), &rect);
1326 MoveWindow( hwnd, 0, 0, rect.right, rect.bottom, FALSE );
1327
1328 MDI_UpdateFrameText( GetParent(hwnd), hwnd, MDI_NOFRAMEREPAINT, NULL);
1329
1330 TRACE("Client created - hwnd = %04x, idFirst = %u\n",
1331 hwnd, ci->idFirstChild );
1332 return 0;
1333 }
1334
1335 case WM_DESTROY:
1336 {
1337 INT nItems;
1338 if( ci->hwndChildMaximized )
1339 MDI_RestoreFrameMenu( GetParent(hwnd), ci->hwndChildMaximized);
1340 if((ci->hWindowMenu != 0) &&
1341 (nItems = GetMenuItemCount(ci->hWindowMenu)) > 0)
1342 {
1343 ci->idFirstChild = nItems - 1;
1344 ci->nActiveChildren++; /* to delete a separator */
1345 while( ci->nActiveChildren-- )
1346 DeleteMenu(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
1347 }
1348 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1349 return 0;
1350 }
1351
1352 case WM_MDIACTIVATE:
1353 if( ci->hwndActiveChild != (HWND)wParam )
1354 SetWindowPos((HWND)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
1355 return 0;
1356
1357 case WM_MDICASCADE:
1358 return MDICascade(hwnd, ci);
1359
1360 case WM_MDICREATE:
1361 if (lParam) return MDICreateChild( hwnd, ci,
1362 (MDICREATESTRUCTA *)lParam, unicode );
1363 else return 0;
1364
1365 case WM_MDIDESTROY:
1366 return MDIDestroyChild( hwnd, ci, WIN_GetFullHandle( (HWND)wParam ), TRUE );
1367
1368 case WM_MDIGETACTIVE:
1369 if (lParam) *(BOOL *)lParam = (ci->hwndChildMaximized != 0);
1370 return ci->hwndActiveChild;
1371
1372 case WM_MDIICONARRANGE:
1373 ci->mdiFlags |= MDIF_NEEDUPDATE;
1374 ArrangeIconicWindows( hwnd );
1375 ci->sbRecalc = SB_BOTH+1;
1376 SendMessageW( hwnd, WM_MDICALCCHILDSCROLL, 0, 0 );
1377 return 0;
1378
1379 case WM_MDIMAXIMIZE:
1380 ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1381 return 0;
1382
1383 case WM_MDINEXT: /* lParam != 0 means previous window */
1384 MDI_SwitchActiveChild( hwnd, WIN_GetFullHandle( (HWND)wParam ), !lParam );
1385 break;
1386
1387 case WM_MDIRESTORE:
1388 SendMessageW( (HWND)wParam, WM_SYSCOMMAND, SC_RESTORE, 0);
1389 return 0;
1390
1391 case WM_MDISETMENU:
1392 return MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1393
1394 case WM_MDIREFRESHMENU:
1395 return MDIRefreshMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1396
1397 case WM_MDITILE:
1398 ci->mdiFlags |= MDIF_NEEDUPDATE;
1399 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1400 MDITile( hwnd, ci, wParam );
1401 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1402 return 0;
1403
1404 case WM_VSCROLL:
1405 case WM_HSCROLL:
1406 ci->mdiFlags |= MDIF_NEEDUPDATE;
1407 ScrollChildren( hwnd, message, wParam, lParam );
1408 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1409 return 0;
1410
1411 case WM_SETFOCUS:
1412 if (ci->hwndActiveChild && !IsIconic( ci->hwndActiveChild ))
1413 SetFocus( ci->hwndActiveChild );
1414 return 0;
1415
1416 case WM_NCACTIVATE:
1417 if( ci->hwndActiveChild )
1418 SendMessageW(ci->hwndActiveChild, message, wParam, lParam);
1419 break;
1420
1421 case WM_PARENTNOTIFY:
1422 if (LOWORD(wParam) == WM_LBUTTONDOWN)
1423 {
1424 HWND child;
1425 POINT pt;
1426 pt.x = SLOWORD(lParam);
1427 pt.y = SHIWORD(lParam);
1428 child = ChildWindowFromPoint(hwnd, pt);
1429
1430 TRACE("notification from %04x (%li,%li)\n",child,pt.x,pt.y);
1431
1432 if( child && child != hwnd && child != ci->hwndActiveChild )
1433 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1434 }
1435 return 0;
1436
1437 case WM_SIZE:
1438 if( IsWindow(ci->hwndChildMaximized) )
1439 {
1440 RECT rect;
1441
1442 rect.left = 0;
1443 rect.top = 0;
1444 rect.right = LOWORD(lParam);
1445 rect.bottom = HIWORD(lParam);
1446
1447 AdjustWindowRectEx(&rect, GetWindowLongA(ci->hwndChildMaximized,GWL_STYLE),
1448 0, GetWindowLongA(ci->hwndChildMaximized,GWL_EXSTYLE) );
1449 MoveWindow(ci->hwndChildMaximized, rect.left, rect.top,
1450 rect.right - rect.left, rect.bottom - rect.top, 1);
1451 }
1452 else
1453 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1454
1455 break;
1456
1457 case WM_MDICALCCHILDSCROLL:
1458 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1459 {
1460 CalcChildScroll(hwnd, ci->sbRecalc-1);
1461 ci->sbRecalc = 0;
1462 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1463 }
1464 return 0;
1465 }
1466 return unicode ? DefWindowProcW( hwnd, message, wParam, lParam ) :
1467 DefWindowProcA( hwnd, message, wParam, lParam );
1468}
1469
1470/***********************************************************************
1471 * MDIClientWndProcA
1472 */
1473#ifdef __WIN32OS2__
1474 LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1475#else
1476static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1477#endif
1478{
1479 if (!IsWindow(hwnd)) return 0;
1480 return MDIClientWndProc_common( hwnd, message, wParam, lParam, FALSE );
1481}
1482
1483/***********************************************************************
1484 * MDIClientWndProcW
1485 */
1486static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1487{
1488 if (!IsWindow(hwnd)) return 0;
1489 return MDIClientWndProc_common( hwnd, message, wParam, lParam, TRUE );
1490}
1491
1492#ifndef __WIN32OS2__
1493/***********************************************************************
1494 * DefFrameProc (USER.445)
1495 */
1496LRESULT WINAPI DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient,
1497 UINT16 message, WPARAM16 wParam, LPARAM lParam )
1498{
1499 switch (message)
1500 {
1501 case WM_SETTEXT:
1502 return DefFrameProcA( hwnd, hwndMDIClient, message, wParam, (LPARAM)MapSL(lParam) );
1503
1504 case WM_COMMAND:
1505 case WM_NCACTIVATE:
1506 case WM_SETFOCUS:
1507 case WM_SIZE:
1508 return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1509
1510 case WM_NEXTMENU:
1511 {
1512 MDINEXTMENU next_menu;
1513 DefFrameProcW( hwnd, hwndMDIClient, message, wParam, (LPARAM)&next_menu );
1514 return MAKELONG( next_menu.hmenuNext, next_menu.hwndNext );
1515 }
1516 default:
1517 return DefWindowProc16(hwnd, message, wParam, lParam);
1518 }
1519}
1520#endif
1521
1522/***********************************************************************
1523 * DefFrameProcA (USER32.@)
1524 */
1525LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1526 UINT message, WPARAM wParam, LPARAM lParam)
1527{
1528 if (hwndMDIClient)
1529 {
1530 switch (message)
1531 {
1532 case WM_SETTEXT:
1533 {
1534 LPWSTR text = HEAP_strdupAtoW( GetProcessHeap(), 0, (LPSTR)lParam );
1535 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, text );
1536 HeapFree( GetProcessHeap(), 0, text );
1537 }
1538 return 1; /* success. FIXME: check text length */
1539
1540 case WM_COMMAND:
1541 case WM_NCACTIVATE:
1542 case WM_NEXTMENU:
1543 case WM_SETFOCUS:
1544 case WM_SIZE:
1545 return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1546 }
1547 }
1548 return DefWindowProcA(hwnd, message, wParam, lParam);
1549}
1550
1551
1552/***********************************************************************
1553 * DefFrameProcW (USER32.@)
1554 */
1555LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1556 UINT message, WPARAM wParam, LPARAM lParam)
1557{
1558 MDICLIENTINFO *ci = get_client_info( hwndMDIClient );
1559
1560 if (ci)
1561 {
1562 switch (message)
1563 {
1564 case WM_COMMAND:
1565 {
1566 WORD id = LOWORD(wParam);
1567 /* check for possible syscommands for maximized MDI child */
1568 if (id < ci->idFirstChild || id >= ci->idFirstChild + ci->nActiveChildren)
1569 {
1570 if( (id - 0xf000) & 0xf00f ) break;
1571 if( !ci->hwndChildMaximized ) break;
1572 switch( id )
1573 {
1574 case SC_SIZE:
1575 case SC_MOVE:
1576 case SC_MINIMIZE:
1577 case SC_MAXIMIZE:
1578 case SC_NEXTWINDOW:
1579 case SC_PREVWINDOW:
1580 case SC_CLOSE:
1581 case SC_RESTORE:
1582 return SendMessageW( ci->hwndChildMaximized, WM_SYSCOMMAND,
1583 wParam, lParam);
1584 }
1585 }
1586 else
1587 {
1588 HWND childHwnd;
1589 if (id - ci->idFirstChild == MDI_MOREWINDOWSLIMIT)
1590 /* User chose "More Windows..." */
1591 childHwnd = MDI_MoreWindowsDialog(hwndMDIClient);
1592 else
1593 /* User chose one of the windows listed in the "Windows" menu */
1594 childHwnd = MDI_GetChildByID(hwndMDIClient,id);
1595
1596 if( childHwnd )
1597 SendMessageW( hwndMDIClient, WM_MDIACTIVATE, (WPARAM)childHwnd, 0 );
1598 }
1599 }
1600 break;
1601
1602 case WM_NCACTIVATE:
1603 SendMessageW(hwndMDIClient, message, wParam, lParam);
1604 break;
1605
1606 case WM_SETTEXT:
1607 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, (LPWSTR)lParam );
1608 return 1; /* success. FIXME: check text length */
1609
1610 case WM_SETFOCUS:
1611 SetFocus(hwndMDIClient);
1612 break;
1613
1614 case WM_SIZE:
1615 MoveWindow(hwndMDIClient, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
1616 break;
1617
1618 case WM_NEXTMENU:
1619 {
1620 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1621
1622 if (!IsIconic(hwnd) && ci->hwndActiveChild && !ci->hwndChildMaximized)
1623 {
1624 /* control menu is between the frame system menu and
1625 * the first entry of menu bar */
1626#ifdef __WIN32OS2__
1627 if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1628 (wParam == VK_RIGHT && GetSubMenu(getSysMenu(hwnd), 0) == next_menu->hmenuIn) )
1629 {
1630 next_menu->hmenuNext = GetSubMenu(getSysMenu(ci->hwndActiveChild), 0);
1631 next_menu->hwndNext = ci->hwndActiveChild;
1632 }
1633#else
1634
1635 WND *wndPtr = WIN_FindWndPtr(hwnd);
1636
1637 if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1638 (wParam == VK_RIGHT && GetSubMenu(wndPtr->hSysMenu, 0) == next_menu->hmenuIn) )
1639 {
1640 WIN_ReleaseWndPtr(wndPtr);
1641 wndPtr = WIN_FindWndPtr(ci->hwndActiveChild);
1642 next_menu->hmenuNext = GetSubMenu(wndPtr->hSysMenu, 0);
1643 next_menu->hwndNext = ci->hwndActiveChild;
1644 WIN_ReleaseWndPtr(wndPtr);
1645 }
1646#endif
1647 }
1648 return 0;
1649 }
1650 }
1651 }
1652
1653 return DefWindowProcW( hwnd, message, wParam, lParam );
1654}
1655
1656
1657#ifndef __WIN32OS2__
1658/***********************************************************************
1659 * DefMDIChildProc (USER.447)
1660 */
1661LRESULT WINAPI DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1662 WPARAM16 wParam, LPARAM lParam )
1663{
1664 switch (message)
1665 {
1666 case WM_SETTEXT:
1667 return DefMDIChildProcA( WIN_Handle32(hwnd), message, wParam, (LPARAM)MapSL(lParam) );
1668 case WM_MENUCHAR:
1669 case WM_CLOSE:
1670 case WM_SETFOCUS:
1671 case WM_CHILDACTIVATE:
1672 case WM_SYSCOMMAND:
1673 case WM_SETVISIBLE:
1674 case WM_SIZE:
1675 case WM_SYSCHAR:
1676 return DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, lParam );
1677 case WM_GETMINMAXINFO:
1678 {
1679 MINMAXINFO16 *mmi16 = (MINMAXINFO16 *)MapSL(lParam);
1680 MINMAXINFO mmi;
1681 STRUCT32_MINMAXINFO16to32( mmi16, &mmi );
1682 DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, (LPARAM)&mmi );
1683 STRUCT32_MINMAXINFO32to16( &mmi, mmi16 );
1684 return 0;
1685 }
1686 case WM_NEXTMENU:
1687 {
1688 MDINEXTMENU next_menu;
1689 DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, (LPARAM)&next_menu );
1690 return MAKELONG( next_menu.hmenuNext, next_menu.hwndNext );
1691 }
1692 default:
1693 return DefWindowProc16(hwnd, message, wParam, lParam);
1694 }
1695}
1696#endif
1697
1698/***********************************************************************
1699 * DefMDIChildProcA (USER32.@)
1700 */
1701LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1702 WPARAM wParam, LPARAM lParam )
1703{
1704 HWND client = GetParent(hwnd);
1705 MDICLIENTINFO *ci = get_client_info( client );
1706
1707 hwnd = WIN_GetFullHandle( hwnd );
1708 if (!ci) return DefWindowProcA( hwnd, message, wParam, lParam );
1709
1710 switch (message)
1711 {
1712 case WM_SETTEXT:
1713 DefWindowProcA(hwnd, message, wParam, lParam);
1714 MDI_MenuModifyItem( client, hwnd );
1715 if( ci->hwndChildMaximized == hwnd )
1716 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1717 return 1; /* success. FIXME: check text length */
1718
1719 case WM_GETMINMAXINFO:
1720 case WM_MENUCHAR:
1721 case WM_CLOSE:
1722 case WM_SETFOCUS:
1723 case WM_CHILDACTIVATE:
1724 case WM_SYSCOMMAND:
1725 case WM_SETVISIBLE:
1726 case WM_SIZE:
1727 case WM_NEXTMENU:
1728 case WM_SYSCHAR:
1729 return DefMDIChildProcW( hwnd, message, wParam, lParam );
1730 }
1731 return DefWindowProcA(hwnd, message, wParam, lParam);
1732}
1733
1734
1735/***********************************************************************
1736 * DefMDIChildProcW (USER32.@)
1737 */
1738LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1739 WPARAM wParam, LPARAM lParam )
1740{
1741 HWND client = GetParent(hwnd);
1742 MDICLIENTINFO *ci = get_client_info( client );
1743
1744 hwnd = WIN_GetFullHandle( hwnd );
1745 if (!ci) return DefWindowProcW( hwnd, message, wParam, lParam );
1746
1747 switch (message)
1748 {
1749 case WM_SETTEXT:
1750 DefWindowProcW(hwnd, message, wParam, lParam);
1751 MDI_MenuModifyItem( client, hwnd );
1752 if( ci->hwndChildMaximized == hwnd )
1753 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1754 return 1; /* success. FIXME: check text length */
1755
1756 case WM_GETMINMAXINFO:
1757 MDI_ChildGetMinMaxInfo( client, hwnd, (MINMAXINFO *)lParam );
1758 return 0;
1759
1760 case WM_MENUCHAR:
1761 return 0x00010000; /* MDI children don't have menu bars */
1762
1763 case WM_CLOSE:
1764 SendMessageW( client, WM_MDIDESTROY, (WPARAM)hwnd, 0 );
1765 return 0;
1766
1767 case WM_SETFOCUS:
1768 if (ci->hwndActiveChild != hwnd) MDI_ChildActivate( client, hwnd );
1769 break;
1770
1771 case WM_CHILDACTIVATE:
1772 MDI_ChildActivate( client, hwnd );
1773 return 0;
1774
1775 case WM_SYSCOMMAND:
1776 switch( wParam )
1777 {
1778 case SC_MOVE:
1779 if( ci->hwndChildMaximized == hwnd) return 0;
1780 break;
1781 case SC_RESTORE:
1782 case SC_MINIMIZE:
1783 SetWindowLongA( hwnd, GWL_STYLE,
1784 GetWindowLongA( hwnd, GWL_STYLE ) | WS_SYSMENU );
1785 break;
1786 case SC_MAXIMIZE:
1787 if (ci->hwndChildMaximized == hwnd)
1788 return SendMessageW( GetParent(client), message, wParam, lParam);
1789 SetWindowLongW( hwnd, GWL_STYLE,
1790 GetWindowLongW( hwnd, GWL_STYLE ) & ~WS_SYSMENU );
1791 break;
1792 case SC_NEXTWINDOW:
1793 SendMessageW( client, WM_MDINEXT, 0, 0);
1794 return 0;
1795 case SC_PREVWINDOW:
1796 SendMessageW( client, WM_MDINEXT, 0, 1);
1797 return 0;
1798 }
1799 break;
1800
1801 case WM_SETVISIBLE:
1802 if( ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1803 else MDI_PostUpdate(client, ci, SB_BOTH+1);
1804 break;
1805
1806 case WM_SIZE:
1807 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1808 {
1809 ci->hwndChildMaximized = 0;
1810 MDI_RestoreFrameMenu( GetParent(client), hwnd );
1811 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1812 }
1813
1814 if( wParam == SIZE_MAXIMIZED )
1815 {
1816 HWND hMaxChild = ci->hwndChildMaximized;
1817
1818 if( hMaxChild == hwnd ) break;
1819 if( hMaxChild)
1820 {
1821 SendMessageW( hMaxChild, WM_SETREDRAW, FALSE, 0 );
1822 MDI_RestoreFrameMenu( GetParent(client), hMaxChild );
1823 ShowWindow( hMaxChild, SW_SHOWNOACTIVATE );
1824 SendMessageW( hMaxChild, WM_SETREDRAW, TRUE, 0 );
1825 }
1826 TRACE("maximizing child %04x\n", hwnd );
1827
1828 /* keep track of the maximized window. */
1829 ci->hwndChildMaximized = hwnd; /* !!! */
1830
1831 /* The maximized window should also be the active window */
1832 MDI_ChildActivate( client, hwnd );
1833 MDI_AugmentFrameMenu( GetParent(client), hwnd );
1834 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1835 }
1836
1837 if( wParam == SIZE_MINIMIZED )
1838 {
1839 HWND switchTo = MDI_GetWindow(ci, hwnd, TRUE, WS_MINIMIZE);
1840
1841 if (switchTo) SendMessageW( switchTo, WM_CHILDACTIVATE, 0, 0);
1842 }
1843 MDI_PostUpdate(client, ci, SB_BOTH+1);
1844 break;
1845
1846 case WM_NEXTMENU:
1847 {
1848 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1849 HWND parent = GetParent(client);
1850
1851 if( wParam == VK_LEFT ) /* switch to frame system menu */
1852 {
1853#ifdef __WIN32OS2__
1854 next_menu->hmenuNext = GetSubMenu( getSysMenu(parent), 0 );
1855#else
1856 WND *wndPtr = WIN_FindWndPtr( parent );
1857 next_menu->hmenuNext = GetSubMenu( wndPtr->hSysMenu, 0 );
1858 WIN_ReleaseWndPtr( wndPtr );
1859#endif
1860 }
1861 if( wParam == VK_RIGHT ) /* to frame menu bar */
1862 {
1863 next_menu->hmenuNext = GetMenu(parent);
1864 }
1865 next_menu->hwndNext = parent;
1866 return 0;
1867 }
1868
1869 case WM_SYSCHAR:
1870 if (wParam == '-')
1871 {
1872 SendMessageW( hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (DWORD)VK_SPACE);
1873 return 0;
1874 }
1875 break;
1876 }
1877 return DefWindowProcW(hwnd, message, wParam, lParam);
1878}
1879
1880/**********************************************************************
1881 * CreateMDIWindowA (USER32.@) Creates a MDI child
1882 *
1883 * RETURNS
1884 * Success: Handle to created window
1885 * Failure: NULL
1886 */
1887HWND WINAPI CreateMDIWindowA(
1888 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1889 LPCSTR lpWindowName, /* [in] Pointer to window name */
1890 DWORD dwStyle, /* [in] Window style */
1891 INT X, /* [in] Horizontal position of window */
1892 INT Y, /* [in] Vertical position of window */
1893 INT nWidth, /* [in] Width of window */
1894 INT nHeight, /* [in] Height of window */
1895 HWND hWndParent, /* [in] Handle to parent window */
1896 HINSTANCE hInstance, /* [in] Handle to application instance */
1897 LPARAM lParam) /* [in] Application-defined value */
1898{
1899 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1900 MDICREATESTRUCTA cs;
1901
1902 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
1903 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1904 nWidth,nHeight,hWndParent,hInstance,lParam);
1905
1906 if (!pCi)
1907 {
1908 ERR("bad hwnd for MDI-client: %04x\n", hWndParent);
1909 return 0;
1910 }
1911 cs.szClass=lpClassName;
1912 cs.szTitle=lpWindowName;
1913 cs.hOwner=hInstance;
1914 cs.x=X;
1915 cs.y=Y;
1916 cs.cx=nWidth;
1917 cs.cy=nHeight;
1918 cs.style=dwStyle;
1919 cs.lParam=lParam;
1920
1921 return MDICreateChild(hWndParent, pCi, &cs, FALSE);
1922}
1923
1924/***********************************************************************
1925 * CreateMDIWindowW (USER32.@) Creates a MDI child
1926 *
1927 * RETURNS
1928 * Success: Handle to created window
1929 * Failure: NULL
1930 */
1931HWND WINAPI CreateMDIWindowW(
1932 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1933 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1934 DWORD dwStyle, /* [in] Window style */
1935 INT X, /* [in] Horizontal position of window */
1936 INT Y, /* [in] Vertical position of window */
1937 INT nWidth, /* [in] Width of window */
1938 INT nHeight, /* [in] Height of window */
1939 HWND hWndParent, /* [in] Handle to parent window */
1940 HINSTANCE hInstance, /* [in] Handle to application instance */
1941 LPARAM lParam) /* [in] Application-defined value */
1942{
1943 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1944 MDICREATESTRUCTW cs;
1945
1946 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
1947 debugstr_w(lpClassName), debugstr_w(lpWindowName), dwStyle, X, Y,
1948 nWidth, nHeight, hWndParent, hInstance, lParam);
1949
1950 if (!pCi)
1951 {
1952 ERR("bad hwnd for MDI-client: %04x\n", hWndParent);
1953 return 0;
1954 }
1955 cs.szClass = lpClassName;
1956 cs.szTitle = lpWindowName;
1957 cs.hOwner = hInstance;
1958 cs.x = X;
1959 cs.y = Y;
1960 cs.cx = nWidth;
1961 cs.cy = nHeight;
1962 cs.style = dwStyle;
1963 cs.lParam = lParam;
1964
1965 return MDICreateChild(hWndParent, pCi, (MDICREATESTRUCTA *)&cs, TRUE);
1966}
1967
1968#ifndef __WIN32OS2__
1969/**********************************************************************
1970 * TranslateMDISysAccel (USER.451)
1971 */
1972BOOL16 WINAPI TranslateMDISysAccel16( HWND16 hwndClient, LPMSG16 msg )
1973{
1974 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1975 {
1976 MSG msg32;
1977 msg32.hwnd = msg->hwnd;
1978 msg32.message = msg->message;
1979 msg32.wParam = msg->wParam;
1980 msg32.lParam = msg->lParam;
1981 /* MDICLIENTINFO is still the same for win32 and win16 ... */
1982 return TranslateMDISysAccel(hwndClient, &msg32);
1983 }
1984 return 0;
1985}
1986#endif
1987
1988/**********************************************************************
1989 * TranslateMDISysAccel (USER32.@)
1990 */
1991BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1992{
1993 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1994 {
1995 MDICLIENTINFO *ci = get_client_info( hwndClient );
1996 WPARAM wParam = 0;
1997
1998 if (!ci || !IsWindowEnabled(ci->hwndActiveChild)) return 0;
1999
2000 /* translate if the Ctrl key is down and Alt not. */
2001
2002 if( (GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
2003 {
2004 switch( msg->wParam )
2005 {
2006 case VK_F6:
2007 case VK_TAB:
2008 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 ) ? SC_NEXTWINDOW : SC_PREVWINDOW;
2009 break;
2010 case VK_F4:
2011 case VK_RBUTTON:
2012 wParam = SC_CLOSE;
2013 break;
2014 default:
2015 return 0;
2016 }
2017 TRACE("wParam = %04x\n", wParam);
2018 SendMessageW(ci->hwndActiveChild, WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
2019 return 1;
2020 }
2021 }
2022 return 0; /* failure */
2023}
2024
2025#ifndef __WIN32OS2__
2026/***********************************************************************
2027 * CalcChildScroll (USER.462)
2028 */
2029void WINAPI CalcChildScroll16( HWND16 hwnd, WORD scroll )
2030{
2031 return CalcChildScroll( hwnd, scroll );
2032}
2033#endif
2034
2035/***********************************************************************
2036 * CalcChildScroll (USER32.@)
2037 */
2038void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
2039{
2040 SCROLLINFO info;
2041 RECT childRect, clientRect;
2042 INT vmin, vmax, hmin, hmax, vpos, hpos;
2043 HWND *list;
2044
2045 GetClientRect( hwnd, &clientRect );
2046 SetRectEmpty( &childRect );
2047
2048 if ((list = WIN_ListChildren( hwnd )))
2049 {
2050 int i;
2051 for (i = 0; list[i]; i++)
2052 {
2053 DWORD style = GetWindowLongW( list[i], GWL_STYLE );
2054 if (style & WS_MAXIMIZE)
2055 {
2056 HeapFree( GetProcessHeap(), 0, list );
2057 ShowScrollBar( hwnd, SB_BOTH, FALSE );
2058 return;
2059 }
2060 if (style & WS_VISIBLE)
2061 {
2062#ifdef __WIN32OS2__
2063 RECT rect;
2064 GetWindowRectParent(list[i], &rect);
2065 UnionRect( &childRect, &rect, &childRect );
2066#else
2067 WND *pWnd = WIN_FindWndPtr( list[i] );
2068 UnionRect( &childRect, &pWnd->rectWindow, &childRect );
2069 WIN_ReleaseWndPtr( pWnd );
2070#endif
2071 }
2072 }
2073 HeapFree( GetProcessHeap(), 0, list );
2074 }
2075 UnionRect( &childRect, &clientRect, &childRect );
2076
2077 hmin = childRect.left;
2078 hmax = childRect.right - clientRect.right;
2079 hpos = clientRect.left - childRect.left;
2080 vmin = childRect.top;
2081 vmax = childRect.bottom - clientRect.bottom;
2082 vpos = clientRect.top - childRect.top;
2083
2084 switch( scroll )
2085 {
2086 case SB_HORZ:
2087 vpos = hpos; vmin = hmin; vmax = hmax;
2088 case SB_VERT:
2089 info.cbSize = sizeof(info);
2090 info.nMax = vmax; info.nMin = vmin; info.nPos = vpos;
2091 info.fMask = SIF_POS | SIF_RANGE;
2092 SetScrollInfo(hwnd, scroll, &info, TRUE);
2093 break;
2094 case SB_BOTH:
2095 SCROLL_SetNCSbState( hwnd, vmin, vmax, vpos,
2096 hmin, hmax, hpos);
2097 }
2098}
2099
2100
2101#ifndef __WIN32OS2__
2102/***********************************************************************
2103 * ScrollChildren (USER.463)
2104 */
2105void WINAPI ScrollChildren16(HWND16 hWnd, UINT16 uMsg, WPARAM16 wParam, LPARAM lParam)
2106{
2107 ScrollChildren( hWnd, uMsg, wParam, lParam );
2108}
2109#endif
2110
2111/***********************************************************************
2112 * ScrollChildren (USER32.@)
2113 */
2114void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
2115 LPARAM lParam)
2116{
2117 INT newPos = -1;
2118 INT curPos, length, minPos, maxPos, shift;
2119 RECT rect;
2120
2121 GetClientRect( hWnd, &rect );
2122
2123 switch(uMsg)
2124 {
2125 case WM_HSCROLL:
2126 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
2127 curPos = GetScrollPos(hWnd,SB_HORZ);
2128 length = (rect.right - rect.left) / 2;
2129 shift = GetSystemMetrics(SM_CYHSCROLL);
2130 break;
2131 case WM_VSCROLL:
2132 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
2133 curPos = GetScrollPos(hWnd,SB_VERT);
2134 length = (rect.bottom - rect.top) / 2;
2135 shift = GetSystemMetrics(SM_CXVSCROLL);
2136 break;
2137 default:
2138 return;
2139 }
2140
2141 switch( wParam )
2142 {
2143 case SB_LINEUP:
2144 newPos = curPos - shift;
2145 break;
2146 case SB_LINEDOWN:
2147 newPos = curPos + shift;
2148 break;
2149 case SB_PAGEUP:
2150 newPos = curPos - length;
2151 break;
2152 case SB_PAGEDOWN:
2153 newPos = curPos + length;
2154 break;
2155
2156 case SB_THUMBPOSITION:
2157 newPos = LOWORD(lParam);
2158 break;
2159
2160 case SB_THUMBTRACK:
2161 return;
2162
2163 case SB_TOP:
2164 newPos = minPos;
2165 break;
2166 case SB_BOTTOM:
2167 newPos = maxPos;
2168 break;
2169 case SB_ENDSCROLL:
2170 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
2171 return;
2172 }
2173
2174 if( newPos > maxPos )
2175 newPos = maxPos;
2176 else
2177 if( newPos < minPos )
2178 newPos = minPos;
2179
2180 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
2181
2182 if( uMsg == WM_VSCROLL )
2183 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
2184 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2185 else
2186 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
2187 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2188}
2189
2190
2191/******************************************************************************
2192 * CascadeWindows (USER32.@) Cascades MDI child windows
2193 *
2194 * RETURNS
2195 * Success: Number of cascaded windows.
2196 * Failure: 0
2197 */
2198WORD WINAPI
2199CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2200 UINT cKids, const HWND *lpKids)
2201{
2202 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2203 hwndParent, wFlags, cKids);
2204
2205 return 0;
2206}
2207
2208
2209/******************************************************************************
2210 * TileWindows (USER32.@) Tiles MDI child windows
2211 *
2212 * RETURNS
2213 * Success: Number of tiled windows.
2214 * Failure: 0
2215 */
2216WORD WINAPI
2217TileWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2218 UINT cKids, const HWND *lpKids)
2219{
2220 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2221 hwndParent, wFlags, cKids);
2222
2223 return 0;
2224}
2225
2226/************************************************************************
2227 * "More Windows..." functionality
2228 */
2229
2230/* MDI_MoreWindowsDlgProc
2231 *
2232 * This function will process the messages sent to the "More Windows..."
2233 * dialog.
2234 * Return values: 0 = cancel pressed
2235 * HWND = ok pressed or double-click in the list...
2236 *
2237 */
2238
2239static BOOL WINAPI MDI_MoreWindowsDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
2240{
2241 switch (iMsg)
2242 {
2243 case WM_INITDIALOG:
2244 {
2245 UINT widest = 0;
2246 UINT length;
2247 UINT i;
2248 MDICLIENTINFO *ci = get_client_info( (HWND)lParam );
2249 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2250 HWND *list, *sorted_list;
2251
2252 if (!(list = WIN_ListChildren( (HWND)lParam ))) return TRUE;
2253 if (!(sorted_list = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
2254 sizeof(HWND) * ci->nActiveChildren )))
2255 {
2256 HeapFree( GetProcessHeap(), 0, list );
2257 return FALSE;
2258 }
2259
2260 /* Fill the list, sorted by id... */
2261 for (i = 0; list[i]; i++)
2262 {
2263 UINT id = GetWindowLongW( list[i], GWL_ID ) - ci->idFirstChild;
2264 if (id < ci->nActiveChildren) sorted_list[id] = list[i];
2265 }
2266 HeapFree( GetProcessHeap(), 0, list );
2267
2268 for (i = 0; i < ci->nActiveChildren; i++)
2269 {
2270 WCHAR buffer[128];
2271
2272 if (!GetWindowTextW( sorted_list[i], buffer, sizeof(buffer)/sizeof(WCHAR) ))
2273 continue;
2274 SendMessageW(hListBox, LB_ADDSTRING, 0, (LPARAM)buffer );
2275 SendMessageW(hListBox, LB_SETITEMDATA, i, (LPARAM)sorted_list[i] );
2276 length = strlenW(buffer); /* FIXME: should use GetTextExtentPoint */
2277 if (length > widest)
2278 widest = length;
2279 }
2280 /* Make sure the horizontal scrollbar scrolls ok */
2281 SendMessageW(hListBox, LB_SETHORIZONTALEXTENT, widest * 6, 0);
2282
2283 /* Set the current selection */
2284 SendMessageW(hListBox, LB_SETCURSEL, MDI_MOREWINDOWSLIMIT, 0);
2285 return TRUE;
2286 }
2287
2288 case WM_COMMAND:
2289 switch (LOWORD(wParam))
2290 {
2291 default:
2292 if (HIWORD(wParam) != LBN_DBLCLK) break;
2293 /* fall through */
2294 case IDOK:
2295 {
2296 /* windows are sorted by menu ID, so we must return the
2297 * window associated to the given id
2298 */
2299 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2300 UINT index = SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
2301 HWND hwnd = SendMessageW(hListBox, LB_GETITEMDATA, index, 0);
2302
2303 EndDialog(hDlg, hwnd);
2304 return TRUE;
2305 }
2306 case IDCANCEL:
2307 EndDialog(hDlg, 0);
2308 return TRUE;
2309 }
2310 break;
2311 }
2312 return FALSE;
2313}
2314
2315/*
2316 *
2317 * MDI_MoreWindowsDialog
2318 *
2319 * Prompts the user with a listbox containing the opened
2320 * documents. The user can then choose a windows and click
2321 * on OK to set the current window to the one selected, or
2322 * CANCEL to cancel. The function returns a handle to the
2323 * selected window.
2324 */
2325
2326static HWND MDI_MoreWindowsDialog(HWND hwnd)
2327{
2328 LPCVOID template;
2329 HRSRC hRes;
2330 HANDLE hDlgTmpl;
2331
2332 hRes = FindResourceA(GetModuleHandleA("USER32"), "MDI_MOREWINDOWS", RT_DIALOGA);
2333
2334 if (hRes == 0)
2335 return 0;
2336
2337 hDlgTmpl = LoadResource(GetModuleHandleA("USER32"), hRes );
2338
2339 if (hDlgTmpl == 0)
2340 return 0;
2341
2342 template = LockResource( hDlgTmpl );
2343
2344 if (template == 0)
2345 return 0;
2346
2347 return (HWND) DialogBoxIndirectParamA(GetModuleHandleA("USER32"),
2348 (LPDLGTEMPLATEA) template,
2349 hwnd, MDI_MoreWindowsDlgProc, (LPARAM) hwnd);
2350}
2351
2352/*
2353 *
2354 * MDI_SwapMenuItems
2355 *
2356 * Will swap the menu IDs for the given 2 positions.
2357 * pos1 and pos2 are menu IDs
2358 *
2359 *
2360 */
2361
2362static void MDI_SwapMenuItems(HWND parent, UINT pos1, UINT pos2)
2363{
2364 HWND *list;
2365 int i;
2366
2367 if (!(list = WIN_ListChildren( parent ))) return;
2368 for (i = 0; list[i]; i++)
2369 {
2370 UINT id = GetWindowLongW( list[i], GWL_ID );
2371 if (id == pos1) SetWindowLongW( list[i], GWL_ID, pos2 );
2372 else if (id == pos2) SetWindowLongW( list[i], GWL_ID, pos1 );
2373 }
2374 HeapFree( GetProcessHeap(), 0, list );
2375}
2376
Note: See TracBrowser for help on using the repository browser.