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

Last change on this file since 7337 was 7337, checked in by phaller, 24 years ago

replaced heap alloc by stack alloc

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