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

Last change on this file since 6762 was 6762, checked in by sandervl, 24 years ago

ported the Wine MDI control + some menu fixes

File size: 72.7 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 if (!IsWindowEnabled( child )) return 0;
757
758 /* Don't activate if it is already active. Might happen
759 since ShowWindow DOES activate MDI children */
760 if (clientInfo->hwndActiveChild == child) return 0;
761
762 TRACE("%04x\n", child);
763
764 isActiveFrameWnd = (GetActiveWindow() == GetParent(client));
765
766 /* deactivate prev. active child */
767 if(prevActiveWnd)
768 {
769 SetWindowLongA( prevActiveWnd, GWL_STYLE,
770 GetWindowLongA( prevActiveWnd, GWL_STYLE ) | WS_SYSMENU );
771 SendMessageA( prevActiveWnd, WM_NCACTIVATE, FALSE, 0L );
772 SendMessageA( prevActiveWnd, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child);
773 /* uncheck menu item */
774 if( clientInfo->hWindowMenu )
775 {
776 UINT prevID = GetWindowLongA( prevActiveWnd, GWL_ID );
777
778 if (prevID - clientInfo->idFirstChild < MDI_MOREWINDOWSLIMIT)
779 CheckMenuItem( clientInfo->hWindowMenu, prevID, 0);
780 else
781 CheckMenuItem( clientInfo->hWindowMenu,
782 clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1, 0);
783 }
784 }
785
786 /* set appearance */
787 if (clientInfo->hwndChildMaximized && clientInfo->hwndChildMaximized != child)
788 {
789 if( child )
790 {
791 clientInfo->hwndActiveChild = child;
792 ShowWindow( child, SW_SHOWMAXIMIZED);
793 }
794 else ShowWindow( clientInfo->hwndActiveChild, SW_SHOWNORMAL );
795 }
796
797 clientInfo->hwndActiveChild = child;
798
799 /* check if we have any children left */
800 if( !child )
801 {
802 if( isActiveFrameWnd )
803 SetFocus( client );
804 return 0;
805 }
806
807 /* check menu item */
808 if( clientInfo->hWindowMenu )
809 {
810 UINT id = GetWindowLongA( child, GWL_ID );
811 /* The window to be activated must be displayed in the "Windows" menu */
812 if (id >= clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT)
813 {
814 MDI_SwapMenuItems( GetParent(child),
815 id, clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1);
816 id = clientInfo->idFirstChild + MDI_MOREWINDOWSLIMIT - 1;
817 MDI_MenuModifyItem( GetParent(child), child );
818 }
819
820 CheckMenuItem(clientInfo->hWindowMenu, id, MF_CHECKED);
821 }
822 /* bring active child to the top */
823 SetWindowPos( child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
824
825 if( isActiveFrameWnd )
826 {
827 SendMessageA( child, WM_NCACTIVATE, TRUE, 0L);
828 if( GetFocus() == client )
829 SendMessageA( client, WM_SETFOCUS, (WPARAM)client, 0L );
830 else
831 SetFocus( client );
832 }
833 SendMessageA( child, WM_MDIACTIVATE, (WPARAM)prevActiveWnd, (LPARAM)child );
834 return TRUE;
835}
836
837/* -------------------- MDI client window functions ------------------- */
838
839/**********************************************************************
840 * CreateMDIMenuBitmap
841 */
842static HBITMAP CreateMDIMenuBitmap(void)
843{
844 HDC hDCSrc = CreateCompatibleDC(0);
845 HDC hDCDest = CreateCompatibleDC(hDCSrc);
846 HBITMAP hbClose = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_CLOSE) );
847 HBITMAP hbCopy;
848 HBITMAP hobjSrc, hobjDest;
849
850 hobjSrc = SelectObject(hDCSrc, hbClose);
851 hbCopy = CreateCompatibleBitmap(hDCSrc,GetSystemMetrics(SM_CXSIZE),GetSystemMetrics(SM_CYSIZE));
852 hobjDest = SelectObject(hDCDest, hbCopy);
853
854 BitBlt(hDCDest, 0, 0, GetSystemMetrics(SM_CXSIZE), GetSystemMetrics(SM_CYSIZE),
855 hDCSrc, GetSystemMetrics(SM_CXSIZE), 0, SRCCOPY);
856
857 SelectObject(hDCSrc, hobjSrc);
858 DeleteObject(hbClose);
859 DeleteDC(hDCSrc);
860
861 hobjSrc = SelectObject( hDCDest, GetStockObject(BLACK_PEN) );
862
863 MoveToEx( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, 0, NULL );
864 LineTo( hDCDest, GetSystemMetrics(SM_CXSIZE) - 1, GetSystemMetrics(SM_CYSIZE) - 1);
865
866 SelectObject(hDCDest, hobjSrc );
867 SelectObject(hDCDest, hobjDest);
868 DeleteDC(hDCDest);
869
870 return hbCopy;
871}
872
873/**********************************************************************
874 * MDICascade
875 */
876static LONG MDICascade( HWND client, MDICLIENTINFO *ci )
877{
878 HWND *win_array;
879 BOOL has_icons = FALSE;
880 int i, total;
881
882 if (ci->hwndChildMaximized)
883 SendMessageA( client, WM_MDIRESTORE,
884 (WPARAM)ci->hwndChildMaximized, 0);
885
886 if (ci->nActiveChildren == 0) return 0;
887
888 if (!(win_array = WIN_ListChildren( client ))) return 0;
889
890 /* remove all the windows we don't want */
891 for (i = total = 0; win_array[i]; i++)
892 {
893 if (!IsWindowVisible( win_array[i] )) continue;
894 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows */
895 if (IsIconic( win_array[i] ))
896 {
897 has_icons = TRUE;
898 continue;
899 }
900 win_array[total++] = win_array[i];
901 }
902 win_array[total] = 0;
903
904 if (total)
905 {
906 INT delta = 0, n = 0, i;
907 POINT pos[2];
908 if (has_icons) delta = GetSystemMetrics(SM_CYICONSPACING) + GetSystemMetrics(SM_CYICON);
909
910 /* walk the list (backwards) and move windows */
911 for (i = total - 1; i >= 0; i--)
912 {
913 TRACE("move %04x to (%ld,%ld) size [%ld,%ld]\n",
914 win_array[i], pos[0].x, pos[0].y, pos[1].x, pos[1].y);
915
916 MDI_CalcDefaultChildPos(client, n++, pos, delta);
917 SetWindowPos( win_array[i], 0, pos[0].x, pos[0].y, pos[1].x, pos[1].y,
918 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
919 }
920 }
921 HeapFree( GetProcessHeap(), 0, win_array );
922
923 if (has_icons) ArrangeIconicWindows( client );
924 return 0;
925}
926
927/**********************************************************************
928 * MDITile
929 */
930static void MDITile( HWND client, MDICLIENTINFO *ci, WPARAM wParam )
931{
932 HWND *win_array;
933 int i, total;
934 BOOL has_icons = FALSE;
935
936 if (ci->hwndChildMaximized)
937 SendMessageA( client, WM_MDIRESTORE, (WPARAM)ci->hwndChildMaximized, 0);
938
939 if (ci->nActiveChildren == 0) return;
940
941 if (!(win_array = WIN_ListChildren( client ))) return;
942
943 /* remove all the windows we don't want */
944 for (i = total = 0; win_array[i]; i++)
945 {
946 if (!IsWindowVisible( win_array[i] )) continue;
947 if (GetWindow( win_array[i], GW_OWNER )) continue; /* skip owned windows (icon titles) */
948 if (IsIconic( win_array[i] ))
949 {
950 has_icons = TRUE;
951 continue;
952 }
953 if ((wParam & MDITILE_SKIPDISABLED) && !IsWindowEnabled( win_array[i] )) continue;
954 win_array[total++] = win_array[i];
955 }
956 win_array[total] = 0;
957
958 TRACE("%u windows to tile\n", total);
959
960 if (total)
961 {
962 HWND *pWnd = win_array;
963 RECT rect;
964 int x, y, xsize, ysize;
965 int rows, columns, r, c, i;
966
967 GetClientRect(client,&rect);
968 rows = (int) sqrt((double)total);
969 columns = total / rows;
970
971 if( wParam & MDITILE_HORIZONTAL ) /* version >= 3.1 */
972 {
973 i = rows;
974 rows = columns; /* exchange r and c */
975 columns = i;
976 }
977
978 if (has_icons)
979 {
980 y = rect.bottom - 2 * GetSystemMetrics(SM_CYICONSPACING) - GetSystemMetrics(SM_CYICON);
981 rect.bottom = ( y - GetSystemMetrics(SM_CYICON) < rect.top )? rect.bottom: y;
982 }
983
984 ysize = rect.bottom / rows;
985 xsize = rect.right / columns;
986
987 for (x = i = 0, c = 1; c <= columns && *pWnd; c++)
988 {
989 if (c == columns)
990 {
991 rows = total - i;
992 ysize = rect.bottom / rows;
993 }
994
995 y = 0;
996 for (r = 1; r <= rows && *pWnd; r++, i++)
997 {
998 SetWindowPos(*pWnd, 0, x, y, xsize, ysize,
999 SWP_DRAWFRAME | SWP_NOACTIVATE | SWP_NOZORDER);
1000 y += ysize;
1001 pWnd++;
1002 }
1003 x += xsize;
1004 }
1005 }
1006 HeapFree( GetProcessHeap(), 0, win_array );
1007 if (has_icons) ArrangeIconicWindows( client );
1008}
1009
1010/* ----------------------- Frame window ---------------------------- */
1011
1012
1013/**********************************************************************
1014 * MDI_AugmentFrameMenu
1015 */
1016static BOOL MDI_AugmentFrameMenu( HWND frame, HWND hChild )
1017{
1018 HMENU menu = GetMenu( frame );
1019#ifndef __WIN32OS2__
1020 WND* child = WIN_FindWndPtr(hChild);
1021#endif
1022 HMENU hSysPopup = 0;
1023 HBITMAP hSysMenuBitmap = 0;
1024
1025 TRACE("frame %04x,child %04x\n",frame,hChild);
1026
1027#ifdef __WIN32OS2__
1028 if( !menu || !getSysMenu(hChild) )
1029 {
1030 return 0;
1031 }
1032#else
1033 if( !menu || !child->hSysMenu )
1034 {
1035 WIN_ReleaseWndPtr(child);
1036 return 0;
1037 }
1038 WIN_ReleaseWndPtr(child);
1039#endif
1040
1041 /* create a copy of sysmenu popup and insert it into frame menu bar */
1042
1043 if (!(hSysPopup = LoadMenuA(GetModuleHandleA("USER32"), "SYSMENU")))
1044 return 0;
1045
1046 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1047 SC_MINIMIZE, (LPSTR)(DWORD)HBMMENU_MBAR_MINIMIZE ) ;
1048 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1049 SC_RESTORE, (LPSTR)(DWORD)HBMMENU_MBAR_RESTORE );
1050
1051 /* In Win 95 look, the system menu is replaced by the child icon */
1052
1053#ifndef __WIN32OS2__
1054 if(TWEAK_WineLook > WIN31_LOOK)
1055#endif
1056 {
1057 HICON hIcon = GetClassLongA(hChild, GCL_HICONSM);
1058 if (!hIcon)
1059 hIcon = GetClassLongA(hChild, GCL_HICON);
1060 if (hIcon)
1061 {
1062 HDC hMemDC;
1063 HBITMAP hBitmap, hOldBitmap;
1064 HBRUSH hBrush;
1065 HDC hdc = GetDC(hChild);
1066
1067 if (hdc)
1068 {
1069 int cx, cy;
1070 cx = GetSystemMetrics(SM_CXSMICON);
1071 cy = GetSystemMetrics(SM_CYSMICON);
1072 hMemDC = CreateCompatibleDC(hdc);
1073 hBitmap = CreateCompatibleBitmap(hdc, cx, cy);
1074 hOldBitmap = SelectObject(hMemDC, hBitmap);
1075 SetMapMode(hMemDC, MM_TEXT);
1076 hBrush = CreateSolidBrush(GetSysColor(COLOR_MENU));
1077 DrawIconEx(hMemDC, 0, 0, hIcon, cx, cy, 0, hBrush, DI_NORMAL);
1078 SelectObject (hMemDC, hOldBitmap);
1079 DeleteObject(hBrush);
1080 DeleteDC(hMemDC);
1081 ReleaseDC(hChild, hdc);
1082 hSysMenuBitmap = hBitmap;
1083 }
1084 }
1085 }
1086#ifndef __WIN32OS2__
1087 else
1088 hSysMenuBitmap = hBmpClose;
1089#endif
1090
1091 if( !InsertMenuA(menu,0,MF_BYPOSITION | MF_BITMAP | MF_POPUP,
1092 hSysPopup, (LPSTR)(DWORD)hSysMenuBitmap))
1093 {
1094 TRACE("not inserted\n");
1095 DestroyMenu(hSysPopup);
1096 return 0;
1097 }
1098
1099 /* The close button is only present in Win 95 look */
1100#ifndef __WIN32OS2__
1101 if(TWEAK_WineLook > WIN31_LOOK)
1102 {
1103#endif
1104 AppendMenuA(menu,MF_HELP | MF_BITMAP,
1105 SC_CLOSE, (LPSTR)(DWORD)HBMMENU_MBAR_CLOSE );
1106#ifndef __WIN32OS2__
1107 }
1108#endif
1109
1110 EnableMenuItem(hSysPopup, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
1111 EnableMenuItem(hSysPopup, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
1112 EnableMenuItem(hSysPopup, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
1113 SetMenuDefaultItem(hSysPopup, SC_CLOSE, FALSE);
1114
1115 /* redraw menu */
1116 DrawMenuBar(frame);
1117
1118 return 1;
1119}
1120
1121/**********************************************************************
1122 * MDI_RestoreFrameMenu
1123 */
1124static BOOL MDI_RestoreFrameMenu( HWND frame, HWND hChild )
1125{
1126 MENUITEMINFOW menuInfo;
1127 HMENU menu = GetMenu( frame );
1128 INT nItems = GetMenuItemCount(menu) - 1;
1129 UINT iId = GetMenuItemID(menu,nItems) ;
1130
1131 TRACE("frame %04x,child %04x,nIt=%d,iId=%d\n",frame,hChild,nItems,iId);
1132
1133 if(!(iId == SC_RESTORE || iId == SC_CLOSE) )
1134 return 0;
1135
1136 /*
1137 * Remove the system menu, If that menu is the icon of the window
1138 * as it is in win95, we have to delete the bitmap.
1139 */
1140 memset(&menuInfo, 0, sizeof(menuInfo));
1141 menuInfo.cbSize = sizeof(menuInfo);
1142 menuInfo.fMask = MIIM_DATA | MIIM_TYPE;
1143
1144 GetMenuItemInfoW(menu,
1145 0,
1146 TRUE,
1147 &menuInfo);
1148
1149 RemoveMenu(menu,0,MF_BYPOSITION);
1150
1151 if ( (menuInfo.fType & MFT_BITMAP) &&
1152 (LOWORD(menuInfo.dwTypeData)!=0) &&
1153 (LOWORD(menuInfo.dwTypeData)!=hBmpClose) )
1154 {
1155 DeleteObject((HBITMAP)LOWORD(menuInfo.dwTypeData));
1156 }
1157
1158#ifndef __WIN32OS2__
1159 if(TWEAK_WineLook > WIN31_LOOK)
1160 {
1161#endif
1162 /* close */
1163 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1164#ifndef __WIN32OS2__
1165 }
1166#endif
1167 /* restore */
1168 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1169 /* minimize */
1170 DeleteMenu(menu,GetMenuItemCount(menu) - 1,MF_BYPOSITION);
1171
1172 DrawMenuBar(frame);
1173
1174 return 1;
1175}
1176
1177
1178/**********************************************************************
1179 * MDI_UpdateFrameText
1180 *
1181 * used when child window is maximized/restored
1182 *
1183 * Note: lpTitle can be NULL
1184 */
1185static void MDI_UpdateFrameText( HWND frame, HWND hClient,
1186 BOOL repaint, LPCWSTR lpTitle )
1187{
1188 WCHAR lpBuffer[MDI_MAXTITLELENGTH+1];
1189 MDICLIENTINFO *ci = get_client_info( hClient );
1190
1191 TRACE("repaint %i, frameText %s\n", repaint, debugstr_w(lpTitle));
1192
1193 if (!ci) return;
1194
1195 if (!lpTitle && !ci->frameTitle) /* first time around, get title from the frame window */
1196 {
1197 GetWindowTextW( frame, lpBuffer, sizeof(lpBuffer)/sizeof(WCHAR) );
1198 lpTitle = lpBuffer;
1199 }
1200
1201 /* store new "default" title if lpTitle is not NULL */
1202 if (lpTitle)
1203 {
1204 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1205 if ((ci->frameTitle = HeapAlloc( GetProcessHeap(), 0, (strlenW(lpTitle)+1)*sizeof(WCHAR))))
1206 strcpyW( ci->frameTitle, lpTitle );
1207 }
1208
1209 if (ci->frameTitle)
1210 {
1211 if (ci->hwndChildMaximized)
1212 {
1213 /* combine frame title and child title if possible */
1214
1215 static const WCHAR lpBracket[] = {' ','-',' ','[',0};
1216 static const WCHAR lpBracket2[] = {']',0};
1217 int i_frame_text_length = strlenW(ci->frameTitle);
1218
1219 lstrcpynW( lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH);
1220
1221 if( i_frame_text_length + 6 < MDI_MAXTITLELENGTH )
1222 {
1223 strcatW( lpBuffer, lpBracket );
1224 if (GetWindowTextW( ci->hwndChildMaximized, lpBuffer + i_frame_text_length + 4,
1225 MDI_MAXTITLELENGTH - i_frame_text_length - 5 ))
1226 strcatW( lpBuffer, lpBracket2 );
1227 else
1228 lpBuffer[i_frame_text_length] = 0; /* remove bracket */
1229 }
1230 }
1231 else
1232 {
1233 lstrcpynW(lpBuffer, ci->frameTitle, MDI_MAXTITLELENGTH+1 );
1234 }
1235 }
1236 else
1237 lpBuffer[0] = '\0';
1238
1239 DefWindowProcW( frame, WM_SETTEXT, 0, (LPARAM)lpBuffer );
1240 if( repaint == MDI_REPAINTFRAME)
1241 SetWindowPos( frame, 0,0,0,0,0, SWP_FRAMECHANGED |
1242 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
1243}
1244
1245
1246/* ----------------------------- Interface ---------------------------- */
1247
1248
1249/**********************************************************************
1250 * MDIClientWndProc_common
1251 */
1252static LRESULT MDIClientWndProc_common( HWND hwnd, UINT message,
1253 WPARAM wParam, LPARAM lParam, BOOL unicode )
1254{
1255 MDICLIENTINFO *ci;
1256
1257 if (!(ci = get_client_info( hwnd ))) return 0;
1258
1259 switch (message)
1260 {
1261 case WM_CREATE:
1262 {
1263 RECT rect;
1264 /* Since we are using only cs->lpCreateParams, we can safely
1265 * cast to LPCREATESTRUCTA here */
1266 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
1267#ifndef __WIN32OS2__
1268 WND *wndPtr = WIN_FindWndPtr( hwnd );
1269
1270 /* Translation layer doesn't know what's in the cs->lpCreateParams
1271 * so we have to keep track of what environment we're in. */
1272
1273 if( wndPtr->flags & WIN_ISWIN32 )
1274 {
1275#endif
1276#define ccs ((LPCLIENTCREATESTRUCT)cs->lpCreateParams)
1277 ci->hWindowMenu = ccs->hWindowMenu;
1278 ci->idFirstChild = ccs->idFirstChild;
1279#undef ccs
1280#ifndef __WIN32OS2__
1281 }
1282 else
1283 {
1284 LPCLIENTCREATESTRUCT16 ccs = MapSL((SEGPTR)cs->lpCreateParams);
1285 ci->hWindowMenu = ccs->hWindowMenu;
1286 ci->idFirstChild = ccs->idFirstChild;
1287 }
1288 WIN_ReleaseWndPtr( wndPtr );
1289#endif
1290
1291 ci->hwndChildMaximized = 0;
1292 ci->nActiveChildren = 0;
1293 ci->nTotalCreated = 0;
1294 ci->frameTitle = NULL;
1295 ci->mdiFlags = 0;
1296 SetWindowLongW( hwnd, GWL_STYLE, GetWindowLongW(hwnd,GWL_STYLE) | WS_CLIPCHILDREN );
1297
1298 if (!hBmpClose)
1299 {
1300 hBmpClose = CreateMDIMenuBitmap();
1301 hBmpRestore = LoadBitmapW( 0, MAKEINTRESOURCEW(OBM_RESTORE) );
1302 }
1303
1304 if (ci->hWindowMenu != 0)
1305 AppendMenuW( ci->hWindowMenu, MF_SEPARATOR, 0, NULL );
1306
1307 GetClientRect( GetParent(hwnd), &rect);
1308 MoveWindow( hwnd, 0, 0, rect.right, rect.bottom, FALSE );
1309
1310 MDI_UpdateFrameText( GetParent(hwnd), hwnd, MDI_NOFRAMEREPAINT, NULL);
1311
1312 TRACE("Client created - hwnd = %04x, idFirst = %u\n",
1313 hwnd, ci->idFirstChild );
1314 return 0;
1315 }
1316
1317 case WM_DESTROY:
1318 {
1319 INT nItems;
1320 if( ci->hwndChildMaximized )
1321 MDI_RestoreFrameMenu( GetParent(hwnd), ci->hwndChildMaximized);
1322 if((ci->hWindowMenu != 0) &&
1323 (nItems = GetMenuItemCount(ci->hWindowMenu)) > 0)
1324 {
1325 ci->idFirstChild = nItems - 1;
1326 ci->nActiveChildren++; /* to delete a separator */
1327 while( ci->nActiveChildren-- )
1328 DeleteMenu(ci->hWindowMenu,MF_BYPOSITION,ci->idFirstChild--);
1329 }
1330 if (ci->frameTitle) HeapFree( GetProcessHeap(), 0, ci->frameTitle );
1331 return 0;
1332 }
1333
1334 case WM_MDIACTIVATE:
1335 if( ci->hwndActiveChild != (HWND)wParam )
1336 SetWindowPos((HWND)wParam, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE);
1337 return 0;
1338
1339 case WM_MDICASCADE:
1340 return MDICascade(hwnd, ci);
1341
1342 case WM_MDICREATE:
1343 if (lParam) return MDICreateChild( hwnd, ci,
1344 (MDICREATESTRUCTA *)lParam, unicode );
1345 else return 0;
1346
1347 case WM_MDIDESTROY:
1348 return MDIDestroyChild( hwnd, ci, WIN_GetFullHandle( (HWND)wParam ), TRUE );
1349
1350 case WM_MDIGETACTIVE:
1351 if (lParam) *(BOOL *)lParam = (ci->hwndChildMaximized != 0);
1352 return ci->hwndActiveChild;
1353
1354 case WM_MDIICONARRANGE:
1355 ci->mdiFlags |= MDIF_NEEDUPDATE;
1356 ArrangeIconicWindows( hwnd );
1357 ci->sbRecalc = SB_BOTH+1;
1358 SendMessageW( hwnd, WM_MDICALCCHILDSCROLL, 0, 0 );
1359 return 0;
1360
1361 case WM_MDIMAXIMIZE:
1362 ShowWindow( (HWND)wParam, SW_MAXIMIZE );
1363 return 0;
1364
1365 case WM_MDINEXT: /* lParam != 0 means previous window */
1366 MDI_SwitchActiveChild( hwnd, WIN_GetFullHandle( (HWND)wParam ), !lParam );
1367 break;
1368
1369 case WM_MDIRESTORE:
1370 SendMessageW( (HWND)wParam, WM_SYSCOMMAND, SC_RESTORE, 0);
1371 return 0;
1372
1373 case WM_MDISETMENU:
1374 return MDISetMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1375
1376 case WM_MDIREFRESHMENU:
1377 return MDIRefreshMenu( hwnd, (HMENU)wParam, (HMENU)lParam );
1378
1379 case WM_MDITILE:
1380 ci->mdiFlags |= MDIF_NEEDUPDATE;
1381 ShowScrollBar( hwnd, SB_BOTH, FALSE );
1382 MDITile( hwnd, ci, wParam );
1383 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1384 return 0;
1385
1386 case WM_VSCROLL:
1387 case WM_HSCROLL:
1388 ci->mdiFlags |= MDIF_NEEDUPDATE;
1389 ScrollChildren( hwnd, message, wParam, lParam );
1390 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1391 return 0;
1392
1393 case WM_SETFOCUS:
1394 if (ci->hwndActiveChild && !IsIconic( ci->hwndActiveChild ))
1395 SetFocus( ci->hwndActiveChild );
1396 return 0;
1397
1398 case WM_NCACTIVATE:
1399 if( ci->hwndActiveChild )
1400 SendMessageW(ci->hwndActiveChild, message, wParam, lParam);
1401 break;
1402
1403 case WM_PARENTNOTIFY:
1404 if (LOWORD(wParam) == WM_LBUTTONDOWN)
1405 {
1406 HWND child;
1407 POINT pt;
1408 pt.x = SLOWORD(lParam);
1409 pt.y = SHIWORD(lParam);
1410 child = ChildWindowFromPoint(hwnd, pt);
1411
1412 TRACE("notification from %04x (%li,%li)\n",child,pt.x,pt.y);
1413
1414 if( child && child != hwnd && child != ci->hwndActiveChild )
1415 SetWindowPos(child, 0,0,0,0,0, SWP_NOSIZE | SWP_NOMOVE );
1416 }
1417 return 0;
1418
1419 case WM_SIZE:
1420 if( IsWindow(ci->hwndChildMaximized) )
1421 {
1422 RECT rect;
1423
1424 rect.left = 0;
1425 rect.top = 0;
1426 rect.right = LOWORD(lParam);
1427 rect.bottom = HIWORD(lParam);
1428
1429 AdjustWindowRectEx(&rect, GetWindowLongA(ci->hwndChildMaximized,GWL_STYLE),
1430 0, GetWindowLongA(ci->hwndChildMaximized,GWL_EXSTYLE) );
1431 MoveWindow(ci->hwndChildMaximized, rect.left, rect.top,
1432 rect.right - rect.left, rect.bottom - rect.top, 1);
1433 }
1434 else
1435 MDI_PostUpdate(hwnd, ci, SB_BOTH+1);
1436
1437 break;
1438
1439 case WM_MDICALCCHILDSCROLL:
1440 if( (ci->mdiFlags & MDIF_NEEDUPDATE) && ci->sbRecalc )
1441 {
1442 CalcChildScroll(hwnd, ci->sbRecalc-1);
1443 ci->sbRecalc = 0;
1444 ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1445 }
1446 return 0;
1447 }
1448 return unicode ? DefWindowProcW( hwnd, message, wParam, lParam ) :
1449 DefWindowProcA( hwnd, message, wParam, lParam );
1450}
1451
1452/***********************************************************************
1453 * MDIClientWndProcA
1454 */
1455#ifdef __WIN32OS2__
1456 LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1457#else
1458static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1459#endif
1460{
1461 if (!IsWindow(hwnd)) return 0;
1462 return MDIClientWndProc_common( hwnd, message, wParam, lParam, FALSE );
1463}
1464
1465/***********************************************************************
1466 * MDIClientWndProcW
1467 */
1468static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1469{
1470 if (!IsWindow(hwnd)) return 0;
1471 return MDIClientWndProc_common( hwnd, message, wParam, lParam, TRUE );
1472}
1473
1474#ifndef __WIN32OS2__
1475/***********************************************************************
1476 * DefFrameProc (USER.445)
1477 */
1478LRESULT WINAPI DefFrameProc16( HWND16 hwnd, HWND16 hwndMDIClient,
1479 UINT16 message, WPARAM16 wParam, LPARAM lParam )
1480{
1481 switch (message)
1482 {
1483 case WM_SETTEXT:
1484 return DefFrameProcA( hwnd, hwndMDIClient, message, wParam, (LPARAM)MapSL(lParam) );
1485
1486 case WM_COMMAND:
1487 case WM_NCACTIVATE:
1488 case WM_SETFOCUS:
1489 case WM_SIZE:
1490 return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1491
1492 case WM_NEXTMENU:
1493 {
1494 MDINEXTMENU next_menu;
1495 DefFrameProcW( hwnd, hwndMDIClient, message, wParam, (LPARAM)&next_menu );
1496 return MAKELONG( next_menu.hmenuNext, next_menu.hwndNext );
1497 }
1498 default:
1499 return DefWindowProc16(hwnd, message, wParam, lParam);
1500 }
1501}
1502#endif
1503
1504/***********************************************************************
1505 * DefFrameProcA (USER32.@)
1506 */
1507LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient,
1508 UINT message, WPARAM wParam, LPARAM lParam)
1509{
1510 if (hwndMDIClient)
1511 {
1512 switch (message)
1513 {
1514 case WM_SETTEXT:
1515 {
1516 LPWSTR text = HEAP_strdupAtoW( GetProcessHeap(), 0, (LPSTR)lParam );
1517 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, text );
1518 HeapFree( GetProcessHeap(), 0, text );
1519 }
1520 return 1; /* success. FIXME: check text length */
1521
1522 case WM_COMMAND:
1523 case WM_NCACTIVATE:
1524 case WM_NEXTMENU:
1525 case WM_SETFOCUS:
1526 case WM_SIZE:
1527 return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1528 }
1529 }
1530 return DefWindowProcA(hwnd, message, wParam, lParam);
1531}
1532
1533
1534/***********************************************************************
1535 * DefFrameProcW (USER32.@)
1536 */
1537LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1538 UINT message, WPARAM wParam, LPARAM lParam)
1539{
1540 MDICLIENTINFO *ci = get_client_info( hwndMDIClient );
1541
1542 if (ci)
1543 {
1544 switch (message)
1545 {
1546 case WM_COMMAND:
1547 {
1548 WORD id = LOWORD(wParam);
1549 /* check for possible syscommands for maximized MDI child */
1550 if (id < ci->idFirstChild || id >= ci->idFirstChild + ci->nActiveChildren)
1551 {
1552 if( (id - 0xf000) & 0xf00f ) break;
1553 if( !ci->hwndChildMaximized ) break;
1554 switch( id )
1555 {
1556 case SC_SIZE:
1557 case SC_MOVE:
1558 case SC_MINIMIZE:
1559 case SC_MAXIMIZE:
1560 case SC_NEXTWINDOW:
1561 case SC_PREVWINDOW:
1562 case SC_CLOSE:
1563 case SC_RESTORE:
1564 return SendMessageW( ci->hwndChildMaximized, WM_SYSCOMMAND,
1565 wParam, lParam);
1566 }
1567 }
1568 else
1569 {
1570 HWND childHwnd;
1571 if (id - ci->idFirstChild == MDI_MOREWINDOWSLIMIT)
1572 /* User chose "More Windows..." */
1573 childHwnd = MDI_MoreWindowsDialog(hwndMDIClient);
1574 else
1575 /* User chose one of the windows listed in the "Windows" menu */
1576 childHwnd = MDI_GetChildByID(hwndMDIClient,id);
1577
1578 if( childHwnd )
1579 SendMessageW( hwndMDIClient, WM_MDIACTIVATE, (WPARAM)childHwnd, 0 );
1580 }
1581 }
1582 break;
1583
1584 case WM_NCACTIVATE:
1585 SendMessageW(hwndMDIClient, message, wParam, lParam);
1586 break;
1587
1588 case WM_SETTEXT:
1589 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, (LPWSTR)lParam );
1590 return 1; /* success. FIXME: check text length */
1591
1592 case WM_SETFOCUS:
1593 SetFocus(hwndMDIClient);
1594 break;
1595
1596 case WM_SIZE:
1597 MoveWindow(hwndMDIClient, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
1598 break;
1599
1600 case WM_NEXTMENU:
1601 {
1602 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1603
1604 if (!IsIconic(hwnd) && ci->hwndActiveChild && !ci->hwndChildMaximized)
1605 {
1606 /* control menu is between the frame system menu and
1607 * the first entry of menu bar */
1608#ifdef __WIN32OS2__
1609 if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1610 (wParam == VK_RIGHT && GetSubMenu(getSysMenu(hwnd), 0) == next_menu->hmenuIn) )
1611 {
1612 next_menu->hmenuNext = GetSubMenu(getSysMenu(ci->hwndActiveChild), 0);
1613 next_menu->hwndNext = ci->hwndActiveChild;
1614 }
1615#else
1616
1617 WND *wndPtr = WIN_FindWndPtr(hwnd);
1618
1619 if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1620 (wParam == VK_RIGHT && GetSubMenu(wndPtr->hSysMenu, 0) == next_menu->hmenuIn) )
1621 {
1622 WIN_ReleaseWndPtr(wndPtr);
1623 wndPtr = WIN_FindWndPtr(ci->hwndActiveChild);
1624 next_menu->hmenuNext = GetSubMenu(wndPtr->hSysMenu, 0);
1625 next_menu->hwndNext = ci->hwndActiveChild;
1626 WIN_ReleaseWndPtr(wndPtr);
1627 }
1628#endif
1629 }
1630 return 0;
1631 }
1632 }
1633 }
1634
1635 return DefWindowProcW( hwnd, message, wParam, lParam );
1636}
1637
1638
1639#ifndef __WIN32OS2__
1640/***********************************************************************
1641 * DefMDIChildProc (USER.447)
1642 */
1643LRESULT WINAPI DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1644 WPARAM16 wParam, LPARAM lParam )
1645{
1646 switch (message)
1647 {
1648 case WM_SETTEXT:
1649 return DefMDIChildProcA( WIN_Handle32(hwnd), message, wParam, (LPARAM)MapSL(lParam) );
1650 case WM_MENUCHAR:
1651 case WM_CLOSE:
1652 case WM_SETFOCUS:
1653 case WM_CHILDACTIVATE:
1654 case WM_SYSCOMMAND:
1655 case WM_SETVISIBLE:
1656 case WM_SIZE:
1657 case WM_SYSCHAR:
1658 return DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, lParam );
1659 case WM_GETMINMAXINFO:
1660 {
1661 MINMAXINFO16 *mmi16 = (MINMAXINFO16 *)MapSL(lParam);
1662 MINMAXINFO mmi;
1663 STRUCT32_MINMAXINFO16to32( mmi16, &mmi );
1664 DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, (LPARAM)&mmi );
1665 STRUCT32_MINMAXINFO32to16( &mmi, mmi16 );
1666 return 0;
1667 }
1668 case WM_NEXTMENU:
1669 {
1670 MDINEXTMENU next_menu;
1671 DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, (LPARAM)&next_menu );
1672 return MAKELONG( next_menu.hmenuNext, next_menu.hwndNext );
1673 }
1674 default:
1675 return DefWindowProc16(hwnd, message, wParam, lParam);
1676 }
1677}
1678#endif
1679
1680/***********************************************************************
1681 * DefMDIChildProcA (USER32.@)
1682 */
1683LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1684 WPARAM wParam, LPARAM lParam )
1685{
1686 HWND client = GetParent(hwnd);
1687 MDICLIENTINFO *ci = get_client_info( client );
1688
1689 hwnd = WIN_GetFullHandle( hwnd );
1690 if (!ci) return DefWindowProcA( hwnd, message, wParam, lParam );
1691
1692 switch (message)
1693 {
1694 case WM_SETTEXT:
1695 DefWindowProcA(hwnd, message, wParam, lParam);
1696 MDI_MenuModifyItem( client, hwnd );
1697 if( ci->hwndChildMaximized == hwnd )
1698 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1699 return 1; /* success. FIXME: check text length */
1700
1701 case WM_GETMINMAXINFO:
1702 case WM_MENUCHAR:
1703 case WM_CLOSE:
1704 case WM_SETFOCUS:
1705 case WM_CHILDACTIVATE:
1706 case WM_SYSCOMMAND:
1707 case WM_SETVISIBLE:
1708 case WM_SIZE:
1709 case WM_NEXTMENU:
1710 case WM_SYSCHAR:
1711 return DefMDIChildProcW( hwnd, message, wParam, lParam );
1712 }
1713 return DefWindowProcA(hwnd, message, wParam, lParam);
1714}
1715
1716
1717/***********************************************************************
1718 * DefMDIChildProcW (USER32.@)
1719 */
1720LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1721 WPARAM wParam, LPARAM lParam )
1722{
1723 HWND client = GetParent(hwnd);
1724 MDICLIENTINFO *ci = get_client_info( client );
1725
1726 hwnd = WIN_GetFullHandle( hwnd );
1727 if (!ci) return DefWindowProcW( hwnd, message, wParam, lParam );
1728
1729 switch (message)
1730 {
1731 case WM_SETTEXT:
1732 DefWindowProcW(hwnd, message, wParam, lParam);
1733 MDI_MenuModifyItem( client, hwnd );
1734 if( ci->hwndChildMaximized == hwnd )
1735 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1736 return 1; /* success. FIXME: check text length */
1737
1738 case WM_GETMINMAXINFO:
1739 MDI_ChildGetMinMaxInfo( client, hwnd, (MINMAXINFO *)lParam );
1740 return 0;
1741
1742 case WM_MENUCHAR:
1743 return 0x00010000; /* MDI children don't have menu bars */
1744
1745 case WM_CLOSE:
1746 SendMessageW( client, WM_MDIDESTROY, (WPARAM)hwnd, 0 );
1747 return 0;
1748
1749 case WM_SETFOCUS:
1750 if (ci->hwndActiveChild != hwnd) MDI_ChildActivate( client, hwnd );
1751 break;
1752
1753 case WM_CHILDACTIVATE:
1754 MDI_ChildActivate( client, hwnd );
1755 return 0;
1756
1757 case WM_SYSCOMMAND:
1758 switch( wParam )
1759 {
1760 case SC_MOVE:
1761 if( ci->hwndChildMaximized == hwnd) return 0;
1762 break;
1763 case SC_RESTORE:
1764 case SC_MINIMIZE:
1765 SetWindowLongA( hwnd, GWL_STYLE,
1766 GetWindowLongA( hwnd, GWL_STYLE ) | WS_SYSMENU );
1767 break;
1768 case SC_MAXIMIZE:
1769 if (ci->hwndChildMaximized == hwnd)
1770 return SendMessageW( GetParent(client), message, wParam, lParam);
1771 SetWindowLongW( hwnd, GWL_STYLE,
1772 GetWindowLongW( hwnd, GWL_STYLE ) & ~WS_SYSMENU );
1773 break;
1774 case SC_NEXTWINDOW:
1775 SendMessageW( client, WM_MDINEXT, 0, 0);
1776 return 0;
1777 case SC_PREVWINDOW:
1778 SendMessageW( client, WM_MDINEXT, 0, 1);
1779 return 0;
1780 }
1781 break;
1782
1783 case WM_SETVISIBLE:
1784 if( ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1785 else MDI_PostUpdate(client, ci, SB_BOTH+1);
1786 break;
1787
1788 case WM_SIZE:
1789 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1790 {
1791 ci->hwndChildMaximized = 0;
1792 MDI_RestoreFrameMenu( GetParent(client), hwnd );
1793 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1794 }
1795
1796 if( wParam == SIZE_MAXIMIZED )
1797 {
1798 HWND hMaxChild = ci->hwndChildMaximized;
1799
1800 if( hMaxChild == hwnd ) break;
1801 if( hMaxChild)
1802 {
1803 SendMessageW( hMaxChild, WM_SETREDRAW, FALSE, 0 );
1804 MDI_RestoreFrameMenu( GetParent(client), hMaxChild );
1805 ShowWindow( hMaxChild, SW_SHOWNOACTIVATE );
1806 SendMessageW( hMaxChild, WM_SETREDRAW, TRUE, 0 );
1807 }
1808 TRACE("maximizing child %04x\n", hwnd );
1809
1810 /* keep track of the maximized window. */
1811 ci->hwndChildMaximized = hwnd; /* !!! */
1812
1813 /* The maximized window should also be the active window */
1814 MDI_ChildActivate( client, hwnd );
1815 MDI_AugmentFrameMenu( GetParent(client), hwnd );
1816 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1817 }
1818
1819 if( wParam == SIZE_MINIMIZED )
1820 {
1821 HWND switchTo = MDI_GetWindow(ci, hwnd, TRUE, WS_MINIMIZE);
1822
1823 if (switchTo) SendMessageW( switchTo, WM_CHILDACTIVATE, 0, 0);
1824 }
1825 MDI_PostUpdate(client, ci, SB_BOTH+1);
1826 break;
1827
1828 case WM_NEXTMENU:
1829 {
1830 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1831 HWND parent = GetParent(client);
1832
1833 if( wParam == VK_LEFT ) /* switch to frame system menu */
1834 {
1835#ifdef __WIN32OS2__
1836 next_menu->hmenuNext = GetSubMenu( getSysMenu(parent), 0 );
1837#else
1838 WND *wndPtr = WIN_FindWndPtr( parent );
1839 next_menu->hmenuNext = GetSubMenu( wndPtr->hSysMenu, 0 );
1840 WIN_ReleaseWndPtr( wndPtr );
1841#endif
1842 }
1843 if( wParam == VK_RIGHT ) /* to frame menu bar */
1844 {
1845 next_menu->hmenuNext = GetMenu(parent);
1846 }
1847 next_menu->hwndNext = parent;
1848 return 0;
1849 }
1850
1851 case WM_SYSCHAR:
1852 if (wParam == '-')
1853 {
1854 SendMessageW( hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (DWORD)VK_SPACE);
1855 return 0;
1856 }
1857 break;
1858 }
1859 return DefWindowProcW(hwnd, message, wParam, lParam);
1860}
1861
1862/**********************************************************************
1863 * CreateMDIWindowA (USER32.@) Creates a MDI child
1864 *
1865 * RETURNS
1866 * Success: Handle to created window
1867 * Failure: NULL
1868 */
1869HWND WINAPI CreateMDIWindowA(
1870 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1871 LPCSTR lpWindowName, /* [in] Pointer to window name */
1872 DWORD dwStyle, /* [in] Window style */
1873 INT X, /* [in] Horizontal position of window */
1874 INT Y, /* [in] Vertical position of window */
1875 INT nWidth, /* [in] Width of window */
1876 INT nHeight, /* [in] Height of window */
1877 HWND hWndParent, /* [in] Handle to parent window */
1878 HINSTANCE hInstance, /* [in] Handle to application instance */
1879 LPARAM lParam) /* [in] Application-defined value */
1880{
1881 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1882 MDICREATESTRUCTA cs;
1883
1884 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
1885 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1886 nWidth,nHeight,hWndParent,hInstance,lParam);
1887
1888 if (!pCi)
1889 {
1890 ERR("bad hwnd for MDI-client: %04x\n", hWndParent);
1891 return 0;
1892 }
1893 cs.szClass=lpClassName;
1894 cs.szTitle=lpWindowName;
1895 cs.hOwner=hInstance;
1896 cs.x=X;
1897 cs.y=Y;
1898 cs.cx=nWidth;
1899 cs.cy=nHeight;
1900 cs.style=dwStyle;
1901 cs.lParam=lParam;
1902
1903 return MDICreateChild(hWndParent, pCi, &cs, FALSE);
1904}
1905
1906/***********************************************************************
1907 * CreateMDIWindowW (USER32.@) Creates a MDI child
1908 *
1909 * RETURNS
1910 * Success: Handle to created window
1911 * Failure: NULL
1912 */
1913HWND WINAPI CreateMDIWindowW(
1914 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1915 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1916 DWORD dwStyle, /* [in] Window style */
1917 INT X, /* [in] Horizontal position of window */
1918 INT Y, /* [in] Vertical position of window */
1919 INT nWidth, /* [in] Width of window */
1920 INT nHeight, /* [in] Height of window */
1921 HWND hWndParent, /* [in] Handle to parent window */
1922 HINSTANCE hInstance, /* [in] Handle to application instance */
1923 LPARAM lParam) /* [in] Application-defined value */
1924{
1925 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1926 MDICREATESTRUCTW cs;
1927
1928 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
1929 debugstr_w(lpClassName), debugstr_w(lpWindowName), dwStyle, X, Y,
1930 nWidth, nHeight, hWndParent, hInstance, lParam);
1931
1932 if (!pCi)
1933 {
1934 ERR("bad hwnd for MDI-client: %04x\n", hWndParent);
1935 return 0;
1936 }
1937 cs.szClass = lpClassName;
1938 cs.szTitle = lpWindowName;
1939 cs.hOwner = hInstance;
1940 cs.x = X;
1941 cs.y = Y;
1942 cs.cx = nWidth;
1943 cs.cy = nHeight;
1944 cs.style = dwStyle;
1945 cs.lParam = lParam;
1946
1947 return MDICreateChild(hWndParent, pCi, (MDICREATESTRUCTA *)&cs, TRUE);
1948}
1949
1950#ifndef __WIN32OS2__
1951/**********************************************************************
1952 * TranslateMDISysAccel (USER.451)
1953 */
1954BOOL16 WINAPI TranslateMDISysAccel16( HWND16 hwndClient, LPMSG16 msg )
1955{
1956 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1957 {
1958 MSG msg32;
1959 msg32.hwnd = msg->hwnd;
1960 msg32.message = msg->message;
1961 msg32.wParam = msg->wParam;
1962 msg32.lParam = msg->lParam;
1963 /* MDICLIENTINFO is still the same for win32 and win16 ... */
1964 return TranslateMDISysAccel(hwndClient, &msg32);
1965 }
1966 return 0;
1967}
1968#endif
1969
1970/**********************************************************************
1971 * TranslateMDISysAccel (USER32.@)
1972 */
1973BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1974{
1975 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1976 {
1977 MDICLIENTINFO *ci = get_client_info( hwndClient );
1978 WPARAM wParam = 0;
1979
1980 if (!ci || !IsWindowEnabled(ci->hwndActiveChild)) return 0;
1981
1982 /* translate if the Ctrl key is down and Alt not. */
1983
1984 if( (GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
1985 {
1986 switch( msg->wParam )
1987 {
1988 case VK_F6:
1989 case VK_TAB:
1990 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 ) ? SC_NEXTWINDOW : SC_PREVWINDOW;
1991 break;
1992 case VK_F4:
1993 case VK_RBUTTON:
1994 wParam = SC_CLOSE;
1995 break;
1996 default:
1997 return 0;
1998 }
1999 TRACE("wParam = %04x\n", wParam);
2000 SendMessageW(ci->hwndActiveChild, WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
2001 return 1;
2002 }
2003 }
2004 return 0; /* failure */
2005}
2006
2007#ifndef __WIN32OS2__
2008/***********************************************************************
2009 * CalcChildScroll (USER.462)
2010 */
2011void WINAPI CalcChildScroll16( HWND16 hwnd, WORD scroll )
2012{
2013 return CalcChildScroll( hwnd, scroll );
2014}
2015#endif
2016
2017/***********************************************************************
2018 * CalcChildScroll (USER32.@)
2019 */
2020void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
2021{
2022 SCROLLINFO info;
2023 RECT childRect, clientRect;
2024 INT vmin, vmax, hmin, hmax, vpos, hpos;
2025 HWND *list;
2026
2027 GetClientRect( hwnd, &clientRect );
2028 SetRectEmpty( &childRect );
2029
2030 if ((list = WIN_ListChildren( hwnd )))
2031 {
2032 int i;
2033 for (i = 0; list[i]; i++)
2034 {
2035 DWORD style = GetWindowLongW( list[i], GWL_STYLE );
2036 if (style & WS_MAXIMIZE)
2037 {
2038 HeapFree( GetProcessHeap(), 0, list );
2039 ShowScrollBar( hwnd, SB_BOTH, FALSE );
2040 return;
2041 }
2042 if (style & WS_VISIBLE)
2043 {
2044#ifdef __WIN32OS2__
2045 RECT rect;
2046 GetWindowRectParent(list[i], &rect);
2047 UnionRect( &childRect, &rect, &childRect );
2048#else
2049 WND *pWnd = WIN_FindWndPtr( list[i] );
2050 UnionRect( &childRect, &pWnd->rectWindow, &childRect );
2051 WIN_ReleaseWndPtr( pWnd );
2052#endif
2053 }
2054 }
2055 HeapFree( GetProcessHeap(), 0, list );
2056 }
2057 UnionRect( &childRect, &clientRect, &childRect );
2058
2059 hmin = childRect.left;
2060 hmax = childRect.right - clientRect.right;
2061 hpos = clientRect.left - childRect.left;
2062 vmin = childRect.top;
2063 vmax = childRect.bottom - clientRect.bottom;
2064 vpos = clientRect.top - childRect.top;
2065
2066 switch( scroll )
2067 {
2068 case SB_HORZ:
2069 vpos = hpos; vmin = hmin; vmax = hmax;
2070 case SB_VERT:
2071 info.cbSize = sizeof(info);
2072 info.nMax = vmax; info.nMin = vmin; info.nPos = vpos;
2073 info.fMask = SIF_POS | SIF_RANGE;
2074 SetScrollInfo(hwnd, scroll, &info, TRUE);
2075 break;
2076 case SB_BOTH:
2077 SCROLL_SetNCSbState( hwnd, vmin, vmax, vpos,
2078 hmin, hmax, hpos);
2079 }
2080}
2081
2082
2083#ifndef __WIN32OS2__
2084/***********************************************************************
2085 * ScrollChildren (USER.463)
2086 */
2087void WINAPI ScrollChildren16(HWND16 hWnd, UINT16 uMsg, WPARAM16 wParam, LPARAM lParam)
2088{
2089 ScrollChildren( hWnd, uMsg, wParam, lParam );
2090}
2091#endif
2092
2093/***********************************************************************
2094 * ScrollChildren (USER32.@)
2095 */
2096void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
2097 LPARAM lParam)
2098{
2099 INT newPos = -1;
2100 INT curPos, length, minPos, maxPos, shift;
2101 RECT rect;
2102
2103 GetClientRect( hWnd, &rect );
2104
2105 switch(uMsg)
2106 {
2107 case WM_HSCROLL:
2108 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
2109 curPos = GetScrollPos(hWnd,SB_HORZ);
2110 length = (rect.right - rect.left) / 2;
2111 shift = GetSystemMetrics(SM_CYHSCROLL);
2112 break;
2113 case WM_VSCROLL:
2114 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
2115 curPos = GetScrollPos(hWnd,SB_VERT);
2116 length = (rect.bottom - rect.top) / 2;
2117 shift = GetSystemMetrics(SM_CXVSCROLL);
2118 break;
2119 default:
2120 return;
2121 }
2122
2123 switch( wParam )
2124 {
2125 case SB_LINEUP:
2126 newPos = curPos - shift;
2127 break;
2128 case SB_LINEDOWN:
2129 newPos = curPos + shift;
2130 break;
2131 case SB_PAGEUP:
2132 newPos = curPos - length;
2133 break;
2134 case SB_PAGEDOWN:
2135 newPos = curPos + length;
2136 break;
2137
2138 case SB_THUMBPOSITION:
2139 newPos = LOWORD(lParam);
2140 break;
2141
2142 case SB_THUMBTRACK:
2143 return;
2144
2145 case SB_TOP:
2146 newPos = minPos;
2147 break;
2148 case SB_BOTTOM:
2149 newPos = maxPos;
2150 break;
2151 case SB_ENDSCROLL:
2152 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
2153 return;
2154 }
2155
2156 if( newPos > maxPos )
2157 newPos = maxPos;
2158 else
2159 if( newPos < minPos )
2160 newPos = minPos;
2161
2162 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
2163
2164 if( uMsg == WM_VSCROLL )
2165 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
2166 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2167 else
2168 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
2169 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2170}
2171
2172
2173/******************************************************************************
2174 * CascadeWindows (USER32.@) Cascades MDI child windows
2175 *
2176 * RETURNS
2177 * Success: Number of cascaded windows.
2178 * Failure: 0
2179 */
2180WORD WINAPI
2181CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2182 UINT cKids, const HWND *lpKids)
2183{
2184 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2185 hwndParent, wFlags, cKids);
2186
2187 return 0;
2188}
2189
2190
2191/******************************************************************************
2192 * TileWindows (USER32.@) Tiles MDI child windows
2193 *
2194 * RETURNS
2195 * Success: Number of tiled windows.
2196 * Failure: 0
2197 */
2198WORD WINAPI
2199TileWindows (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 * "More Windows..." functionality
2210 */
2211
2212/* MDI_MoreWindowsDlgProc
2213 *
2214 * This function will process the messages sent to the "More Windows..."
2215 * dialog.
2216 * Return values: 0 = cancel pressed
2217 * HWND = ok pressed or double-click in the list...
2218 *
2219 */
2220
2221static BOOL WINAPI MDI_MoreWindowsDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
2222{
2223 switch (iMsg)
2224 {
2225 case WM_INITDIALOG:
2226 {
2227 UINT widest = 0;
2228 UINT length;
2229 UINT i;
2230 MDICLIENTINFO *ci = get_client_info( (HWND)lParam );
2231 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2232 HWND *list, *sorted_list;
2233
2234 if (!(list = WIN_ListChildren( (HWND)lParam ))) return TRUE;
2235 if (!(sorted_list = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
2236 sizeof(HWND) * ci->nActiveChildren )))
2237 {
2238 HeapFree( GetProcessHeap(), 0, list );
2239 return FALSE;
2240 }
2241
2242 /* Fill the list, sorted by id... */
2243 for (i = 0; list[i]; i++)
2244 {
2245 UINT id = GetWindowLongW( list[i], GWL_ID ) - ci->idFirstChild;
2246 if (id < ci->nActiveChildren) sorted_list[id] = list[i];
2247 }
2248 HeapFree( GetProcessHeap(), 0, list );
2249
2250 for (i = 0; i < ci->nActiveChildren; i++)
2251 {
2252 WCHAR buffer[128];
2253
2254 if (!GetWindowTextW( sorted_list[i], buffer, sizeof(buffer)/sizeof(WCHAR) ))
2255 continue;
2256 SendMessageW(hListBox, LB_ADDSTRING, 0, (LPARAM)buffer );
2257 SendMessageW(hListBox, LB_SETITEMDATA, i, (LPARAM)sorted_list[i] );
2258 length = strlenW(buffer); /* FIXME: should use GetTextExtentPoint */
2259 if (length > widest)
2260 widest = length;
2261 }
2262 /* Make sure the horizontal scrollbar scrolls ok */
2263 SendMessageW(hListBox, LB_SETHORIZONTALEXTENT, widest * 6, 0);
2264
2265 /* Set the current selection */
2266 SendMessageW(hListBox, LB_SETCURSEL, MDI_MOREWINDOWSLIMIT, 0);
2267 return TRUE;
2268 }
2269
2270 case WM_COMMAND:
2271 switch (LOWORD(wParam))
2272 {
2273 default:
2274 if (HIWORD(wParam) != LBN_DBLCLK) break;
2275 /* fall through */
2276 case IDOK:
2277 {
2278 /* windows are sorted by menu ID, so we must return the
2279 * window associated to the given id
2280 */
2281 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2282 UINT index = SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
2283 HWND hwnd = SendMessageW(hListBox, LB_GETITEMDATA, index, 0);
2284
2285 EndDialog(hDlg, hwnd);
2286 return TRUE;
2287 }
2288 case IDCANCEL:
2289 EndDialog(hDlg, 0);
2290 return TRUE;
2291 }
2292 break;
2293 }
2294 return FALSE;
2295}
2296
2297/*
2298 *
2299 * MDI_MoreWindowsDialog
2300 *
2301 * Prompts the user with a listbox containing the opened
2302 * documents. The user can then choose a windows and click
2303 * on OK to set the current window to the one selected, or
2304 * CANCEL to cancel. The function returns a handle to the
2305 * selected window.
2306 */
2307
2308static HWND MDI_MoreWindowsDialog(HWND hwnd)
2309{
2310 LPCVOID template;
2311 HRSRC hRes;
2312 HANDLE hDlgTmpl;
2313
2314 hRes = FindResourceA(GetModuleHandleA("USER32"), "MDI_MOREWINDOWS", RT_DIALOGA);
2315
2316 if (hRes == 0)
2317 return 0;
2318
2319 hDlgTmpl = LoadResource(GetModuleHandleA("USER32"), hRes );
2320
2321 if (hDlgTmpl == 0)
2322 return 0;
2323
2324 template = LockResource( hDlgTmpl );
2325
2326 if (template == 0)
2327 return 0;
2328
2329 return (HWND) DialogBoxIndirectParamA(GetModuleHandleA("USER32"),
2330 (LPDLGTEMPLATEA) template,
2331 hwnd, MDI_MoreWindowsDlgProc, (LPARAM) hwnd);
2332}
2333
2334/*
2335 *
2336 * MDI_SwapMenuItems
2337 *
2338 * Will swap the menu IDs for the given 2 positions.
2339 * pos1 and pos2 are menu IDs
2340 *
2341 *
2342 */
2343
2344static void MDI_SwapMenuItems(HWND parent, UINT pos1, UINT pos2)
2345{
2346 HWND *list;
2347 int i;
2348
2349 if (!(list = WIN_ListChildren( parent ))) return;
2350 for (i = 0; list[i]; i++)
2351 {
2352 UINT id = GetWindowLongW( list[i], GWL_ID );
2353 if (id == pos1) SetWindowLongW( list[i], GWL_ID, pos2 );
2354 else if (id == pos2) SetWindowLongW( list[i], GWL_ID, pos1 );
2355 }
2356 HeapFree( GetProcessHeap(), 0, list );
2357}
2358
2359#ifdef __WIN32OS2__
2360
2361#define MDICLIENTCLASSNAMEA "MDICLIENT"
2362#define MDICLIENTCLASSNAMEW L"MDICLIENT"
2363
2364//******************************************************************************
2365//******************************************************************************
2366BOOL MDICLIENT_Register()
2367{
2368 WNDCLASSA wndClass;
2369
2370//SvL: Don't check this now
2371// if (GlobalFindAtomA(MDICLIENTCLASSNAMEA)) return FALSE;
2372
2373 ZeroMemory(&wndClass,sizeof(WNDCLASSA));
2374 wndClass.style = CS_GLOBALCLASS;
2375 wndClass.lpfnWndProc = (WNDPROC)MDIClientWndProcA;
2376 wndClass.cbClsExtra = 0;
2377 wndClass.cbWndExtra = 0;
2378 wndClass.hCursor = LoadCursorA(0,IDC_ARROWA);;
2379 wndClass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
2380 wndClass.lpszClassName = MDICLIENTCLASSNAMEA;
2381
2382 return RegisterClassA(&wndClass);
2383}
2384//******************************************************************************
2385//******************************************************************************
2386BOOL MDICLIENT_Unregister()
2387{
2388 if (GlobalFindAtomA(MDICLIENTCLASSNAMEA))
2389 return UnregisterClassA(MDICLIENTCLASSNAMEA,(HINSTANCE)NULL);
2390 else return FALSE;
2391}
2392//******************************************************************************
2393//******************************************************************************
2394#endif
Note: See TracBrowser for help on using the repository browser.