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

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

removed unnecessary changes

File size: 72.8 KB
Line 
1/* MDI.C
2 *
3 * Copyright 1994, Bob Amstadt
4 * 1995,1996 Alex Korobka
5 *
6 * This file contains routines to support MDI (Multiple Document
7 * Interface) features .
8 *
9 * Notes: Fairly complete implementation.
10 * Also, Excel and WinWord do _not_ use MDI so if you're trying
11 * to fix them look elsewhere.
12 *
13 * Notes on how the "More Windows..." is implemented:
14 *
15 * When we have more than 9 opened windows, a "More Windows..."
16 * option appears in the "Windows" menu. Each child window has
17 * a WND* associated with it, accesible via the children list of
18 * the parent window. This WND* has a wIDmenu member, which reflects
19 * the position of the child in the window list. For example, with
20 * 9 child windows, we could have the following pattern:
21 *
22 *
23 *
24 * Name of the child window pWndChild->wIDmenu
25 * Doc1 5000
26 * Doc2 5001
27 * Doc3 5002
28 * Doc4 5003
29 * Doc5 5004
30 * Doc6 5005
31 * Doc7 5006
32 * Doc8 5007
33 * Doc9 5008
34 *
35 *
36 * The "Windows" menu, as the "More windows..." dialog, are constructed
37 * in this order. If we add a child, we would have the following list:
38 *
39 *
40 * Name of the child window pWndChild->wIDmenu
41 * Doc1 5000
42 * Doc2 5001
43 * Doc3 5002
44 * Doc4 5003
45 * Doc5 5004
46 * Doc6 5005
47 * Doc7 5006
48 * Doc8 5007
49 * Doc9 5008
50 * Doc10 5009
51 *
52 * But only 5000 to 5008 would be displayed in the "Windows" menu. We want
53 * the last created child to be in the menu, so we swap the last child with
54 * the 9th... Doc9 will be accessible via the "More Windows..." option.
55 *
56 * Doc1 5000
57 * Doc2 5001
58 * Doc3 5002
59 * Doc4 5003
60 * Doc5 5004
61 * Doc6 5005
62 * Doc7 5006
63 * Doc8 5007
64 * Doc9 5009
65 * Doc10 5008
66 *
67 */
68
69#include <stdlib.h>
70#include <stdio.h>
71#include <string.h>
72#include <math.h>
73
74#include "windef.h"
75#include "winbase.h"
76#include "wingdi.h"
77#include "winuser.h"
78#include "wine/unicode.h"
79#include "win.h"
80#include "heap.h"
81#include "controls.h"
82#include "user.h"
83#ifndef __WIN32OS2__
84#include "nonclient.h"
85#include "struct32.h"
86#endif
87#include "debugtools.h"
88#include "dlgs.h"
89
90#ifdef __WIN32OS2__
91#include <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 LPWSTR text = HEAP_strdupAtoW( GetProcessHeap(), 0, (LPSTR)lParam );
1524 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, text );
1525 HeapFree( GetProcessHeap(), 0, text );
1526 }
1527 return 1; /* success. FIXME: check text length */
1528
1529 case WM_COMMAND:
1530 case WM_NCACTIVATE:
1531 case WM_NEXTMENU:
1532 case WM_SETFOCUS:
1533 case WM_SIZE:
1534 return DefFrameProcW( hwnd, hwndMDIClient, message, wParam, lParam );
1535 }
1536 }
1537 return DefWindowProcA(hwnd, message, wParam, lParam);
1538}
1539
1540
1541/***********************************************************************
1542 * DefFrameProcW (USER32.@)
1543 */
1544LRESULT WINAPI DefFrameProcW( HWND hwnd, HWND hwndMDIClient,
1545 UINT message, WPARAM wParam, LPARAM lParam)
1546{
1547 MDICLIENTINFO *ci = get_client_info( hwndMDIClient );
1548
1549 if (ci)
1550 {
1551 switch (message)
1552 {
1553 case WM_COMMAND:
1554 {
1555 WORD id = LOWORD(wParam);
1556 /* check for possible syscommands for maximized MDI child */
1557 if (id < ci->idFirstChild || id >= ci->idFirstChild + ci->nActiveChildren)
1558 {
1559 if( (id - 0xf000) & 0xf00f ) break;
1560 if( !ci->hwndChildMaximized ) break;
1561 switch( id )
1562 {
1563 case SC_SIZE:
1564 case SC_MOVE:
1565 case SC_MINIMIZE:
1566 case SC_MAXIMIZE:
1567 case SC_NEXTWINDOW:
1568 case SC_PREVWINDOW:
1569 case SC_CLOSE:
1570 case SC_RESTORE:
1571 return SendMessageW( ci->hwndChildMaximized, WM_SYSCOMMAND,
1572 wParam, lParam);
1573 }
1574 }
1575 else
1576 {
1577 HWND childHwnd;
1578 if (id - ci->idFirstChild == MDI_MOREWINDOWSLIMIT)
1579 /* User chose "More Windows..." */
1580 childHwnd = MDI_MoreWindowsDialog(hwndMDIClient);
1581 else
1582 /* User chose one of the windows listed in the "Windows" menu */
1583 childHwnd = MDI_GetChildByID(hwndMDIClient,id);
1584
1585 if( childHwnd )
1586 SendMessageW( hwndMDIClient, WM_MDIACTIVATE, (WPARAM)childHwnd, 0 );
1587 }
1588 }
1589 break;
1590
1591 case WM_NCACTIVATE:
1592 SendMessageW(hwndMDIClient, message, wParam, lParam);
1593 break;
1594
1595 case WM_SETTEXT:
1596 MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, (LPWSTR)lParam );
1597 return 1; /* success. FIXME: check text length */
1598
1599 case WM_SETFOCUS:
1600 SetFocus(hwndMDIClient);
1601 break;
1602
1603 case WM_SIZE:
1604 MoveWindow(hwndMDIClient, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
1605 break;
1606
1607 case WM_NEXTMENU:
1608 {
1609 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1610
1611 if (!IsIconic(hwnd) && ci->hwndActiveChild && !ci->hwndChildMaximized)
1612 {
1613 /* control menu is between the frame system menu and
1614 * the first entry of menu bar */
1615#ifdef __WIN32OS2__
1616 if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1617 (wParam == VK_RIGHT && GetSubMenu(getSysMenu(hwnd), 0) == next_menu->hmenuIn) )
1618 {
1619 next_menu->hmenuNext = GetSubMenu(getSysMenu(ci->hwndActiveChild), 0);
1620 next_menu->hwndNext = ci->hwndActiveChild;
1621 }
1622#else
1623
1624 WND *wndPtr = WIN_FindWndPtr(hwnd);
1625
1626 if( (wParam == VK_LEFT && GetMenu(hwnd) == next_menu->hmenuIn) ||
1627 (wParam == VK_RIGHT && GetSubMenu(wndPtr->hSysMenu, 0) == next_menu->hmenuIn) )
1628 {
1629 WIN_ReleaseWndPtr(wndPtr);
1630 wndPtr = WIN_FindWndPtr(ci->hwndActiveChild);
1631 next_menu->hmenuNext = GetSubMenu(wndPtr->hSysMenu, 0);
1632 next_menu->hwndNext = ci->hwndActiveChild;
1633 WIN_ReleaseWndPtr(wndPtr);
1634 }
1635#endif
1636 }
1637 return 0;
1638 }
1639 }
1640 }
1641
1642 return DefWindowProcW( hwnd, message, wParam, lParam );
1643}
1644
1645
1646#ifndef __WIN32OS2__
1647/***********************************************************************
1648 * DefMDIChildProc (USER.447)
1649 */
1650LRESULT WINAPI DefMDIChildProc16( HWND16 hwnd, UINT16 message,
1651 WPARAM16 wParam, LPARAM lParam )
1652{
1653 switch (message)
1654 {
1655 case WM_SETTEXT:
1656 return DefMDIChildProcA( WIN_Handle32(hwnd), message, wParam, (LPARAM)MapSL(lParam) );
1657 case WM_MENUCHAR:
1658 case WM_CLOSE:
1659 case WM_SETFOCUS:
1660 case WM_CHILDACTIVATE:
1661 case WM_SYSCOMMAND:
1662 case WM_SETVISIBLE:
1663 case WM_SIZE:
1664 case WM_SYSCHAR:
1665 return DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, lParam );
1666 case WM_GETMINMAXINFO:
1667 {
1668 MINMAXINFO16 *mmi16 = (MINMAXINFO16 *)MapSL(lParam);
1669 MINMAXINFO mmi;
1670 STRUCT32_MINMAXINFO16to32( mmi16, &mmi );
1671 DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, (LPARAM)&mmi );
1672 STRUCT32_MINMAXINFO32to16( &mmi, mmi16 );
1673 return 0;
1674 }
1675 case WM_NEXTMENU:
1676 {
1677 MDINEXTMENU next_menu;
1678 DefMDIChildProcW( WIN_Handle32(hwnd), message, wParam, (LPARAM)&next_menu );
1679 return MAKELONG( next_menu.hmenuNext, next_menu.hwndNext );
1680 }
1681 default:
1682 return DefWindowProc16(hwnd, message, wParam, lParam);
1683 }
1684}
1685#endif
1686
1687/***********************************************************************
1688 * DefMDIChildProcA (USER32.@)
1689 */
1690LRESULT WINAPI DefMDIChildProcA( HWND hwnd, UINT message,
1691 WPARAM wParam, LPARAM lParam )
1692{
1693 HWND client = GetParent(hwnd);
1694 MDICLIENTINFO *ci = get_client_info( client );
1695
1696 hwnd = WIN_GetFullHandle( hwnd );
1697 if (!ci) return DefWindowProcA( hwnd, message, wParam, lParam );
1698
1699 switch (message)
1700 {
1701 case WM_SETTEXT:
1702 DefWindowProcA(hwnd, message, wParam, lParam);
1703 MDI_MenuModifyItem( client, hwnd );
1704 if( ci->hwndChildMaximized == hwnd )
1705 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1706 return 1; /* success. FIXME: check text length */
1707
1708 case WM_GETMINMAXINFO:
1709 case WM_MENUCHAR:
1710 case WM_CLOSE:
1711 case WM_SETFOCUS:
1712 case WM_CHILDACTIVATE:
1713 case WM_SYSCOMMAND:
1714 case WM_SETVISIBLE:
1715 case WM_SIZE:
1716 case WM_NEXTMENU:
1717 case WM_SYSCHAR:
1718 return DefMDIChildProcW( hwnd, message, wParam, lParam );
1719 }
1720 return DefWindowProcA(hwnd, message, wParam, lParam);
1721}
1722
1723
1724/***********************************************************************
1725 * DefMDIChildProcW (USER32.@)
1726 */
1727LRESULT WINAPI DefMDIChildProcW( HWND hwnd, UINT message,
1728 WPARAM wParam, LPARAM lParam )
1729{
1730 HWND client = GetParent(hwnd);
1731 MDICLIENTINFO *ci = get_client_info( client );
1732
1733 hwnd = WIN_GetFullHandle( hwnd );
1734 if (!ci) return DefWindowProcW( hwnd, message, wParam, lParam );
1735
1736 switch (message)
1737 {
1738 case WM_SETTEXT:
1739 DefWindowProcW(hwnd, message, wParam, lParam);
1740 MDI_MenuModifyItem( client, hwnd );
1741 if( ci->hwndChildMaximized == hwnd )
1742 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1743 return 1; /* success. FIXME: check text length */
1744
1745 case WM_GETMINMAXINFO:
1746 MDI_ChildGetMinMaxInfo( client, hwnd, (MINMAXINFO *)lParam );
1747 return 0;
1748
1749 case WM_MENUCHAR:
1750 return 0x00010000; /* MDI children don't have menu bars */
1751
1752 case WM_CLOSE:
1753 SendMessageW( client, WM_MDIDESTROY, (WPARAM)hwnd, 0 );
1754 return 0;
1755
1756 case WM_SETFOCUS:
1757 if (ci->hwndActiveChild != hwnd) MDI_ChildActivate( client, hwnd );
1758 break;
1759
1760 case WM_CHILDACTIVATE:
1761 MDI_ChildActivate( client, hwnd );
1762 return 0;
1763
1764 case WM_SYSCOMMAND:
1765 switch( wParam )
1766 {
1767 case SC_MOVE:
1768 if( ci->hwndChildMaximized == hwnd) return 0;
1769 break;
1770 case SC_RESTORE:
1771 case SC_MINIMIZE:
1772 SetWindowLongA( hwnd, GWL_STYLE,
1773 GetWindowLongA( hwnd, GWL_STYLE ) | WS_SYSMENU );
1774 break;
1775 case SC_MAXIMIZE:
1776 if (ci->hwndChildMaximized == hwnd)
1777 return SendMessageW( GetParent(client), message, wParam, lParam);
1778 SetWindowLongW( hwnd, GWL_STYLE,
1779 GetWindowLongW( hwnd, GWL_STYLE ) & ~WS_SYSMENU );
1780 break;
1781 case SC_NEXTWINDOW:
1782 SendMessageW( client, WM_MDINEXT, 0, 0);
1783 return 0;
1784 case SC_PREVWINDOW:
1785 SendMessageW( client, WM_MDINEXT, 0, 1);
1786 return 0;
1787 }
1788 break;
1789
1790 case WM_SETVISIBLE:
1791 if( ci->hwndChildMaximized) ci->mdiFlags &= ~MDIF_NEEDUPDATE;
1792 else MDI_PostUpdate(client, ci, SB_BOTH+1);
1793 break;
1794
1795 case WM_SIZE:
1796 if( ci->hwndActiveChild == hwnd && wParam != SIZE_MAXIMIZED )
1797 {
1798 ci->hwndChildMaximized = 0;
1799 MDI_RestoreFrameMenu( GetParent(client), hwnd );
1800 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1801 }
1802
1803 if( wParam == SIZE_MAXIMIZED )
1804 {
1805 HWND hMaxChild = ci->hwndChildMaximized;
1806
1807 if( hMaxChild == hwnd ) break;
1808 if( hMaxChild)
1809 {
1810 SendMessageW( hMaxChild, WM_SETREDRAW, FALSE, 0 );
1811 MDI_RestoreFrameMenu( GetParent(client), hMaxChild );
1812 ShowWindow( hMaxChild, SW_SHOWNOACTIVATE );
1813 SendMessageW( hMaxChild, WM_SETREDRAW, TRUE, 0 );
1814 }
1815 TRACE("maximizing child %04x\n", hwnd );
1816
1817 /* keep track of the maximized window. */
1818 ci->hwndChildMaximized = hwnd; /* !!! */
1819
1820 /* The maximized window should also be the active window */
1821 MDI_ChildActivate( client, hwnd );
1822 MDI_AugmentFrameMenu( GetParent(client), hwnd );
1823 MDI_UpdateFrameText( GetParent(client), client, MDI_REPAINTFRAME, NULL );
1824 }
1825
1826 if( wParam == SIZE_MINIMIZED )
1827 {
1828 HWND switchTo = MDI_GetWindow(ci, hwnd, TRUE, WS_MINIMIZE);
1829
1830 if (switchTo) SendMessageW( switchTo, WM_CHILDACTIVATE, 0, 0);
1831 }
1832 MDI_PostUpdate(client, ci, SB_BOTH+1);
1833 break;
1834
1835 case WM_NEXTMENU:
1836 {
1837 MDINEXTMENU *next_menu = (MDINEXTMENU *)lParam;
1838 HWND parent = GetParent(client);
1839
1840 if( wParam == VK_LEFT ) /* switch to frame system menu */
1841 {
1842#ifdef __WIN32OS2__
1843 next_menu->hmenuNext = GetSubMenu( getSysMenu(parent), 0 );
1844#else
1845 WND *wndPtr = WIN_FindWndPtr( parent );
1846 next_menu->hmenuNext = GetSubMenu( wndPtr->hSysMenu, 0 );
1847 WIN_ReleaseWndPtr( wndPtr );
1848#endif
1849 }
1850 if( wParam == VK_RIGHT ) /* to frame menu bar */
1851 {
1852 next_menu->hmenuNext = GetMenu(parent);
1853 }
1854 next_menu->hwndNext = parent;
1855 return 0;
1856 }
1857
1858 case WM_SYSCHAR:
1859 if (wParam == '-')
1860 {
1861 SendMessageW( hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (DWORD)VK_SPACE);
1862 return 0;
1863 }
1864 break;
1865 }
1866 return DefWindowProcW(hwnd, message, wParam, lParam);
1867}
1868
1869/**********************************************************************
1870 * CreateMDIWindowA (USER32.@) Creates a MDI child
1871 *
1872 * RETURNS
1873 * Success: Handle to created window
1874 * Failure: NULL
1875 */
1876HWND WINAPI CreateMDIWindowA(
1877 LPCSTR lpClassName, /* [in] Pointer to registered child class name */
1878 LPCSTR lpWindowName, /* [in] Pointer to window name */
1879 DWORD dwStyle, /* [in] Window style */
1880 INT X, /* [in] Horizontal position of window */
1881 INT Y, /* [in] Vertical position of window */
1882 INT nWidth, /* [in] Width of window */
1883 INT nHeight, /* [in] Height of window */
1884 HWND hWndParent, /* [in] Handle to parent window */
1885 HINSTANCE hInstance, /* [in] Handle to application instance */
1886 LPARAM lParam) /* [in] Application-defined value */
1887{
1888 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1889 MDICREATESTRUCTA cs;
1890
1891 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
1892 debugstr_a(lpClassName),debugstr_a(lpWindowName),dwStyle,X,Y,
1893 nWidth,nHeight,hWndParent,hInstance,lParam);
1894
1895 if (!pCi)
1896 {
1897 ERR("bad hwnd for MDI-client: %04x\n", hWndParent);
1898 return 0;
1899 }
1900 cs.szClass=lpClassName;
1901 cs.szTitle=lpWindowName;
1902 cs.hOwner=hInstance;
1903 cs.x=X;
1904 cs.y=Y;
1905 cs.cx=nWidth;
1906 cs.cy=nHeight;
1907 cs.style=dwStyle;
1908 cs.lParam=lParam;
1909
1910 return MDICreateChild(hWndParent, pCi, &cs, FALSE);
1911}
1912
1913/***********************************************************************
1914 * CreateMDIWindowW (USER32.@) Creates a MDI child
1915 *
1916 * RETURNS
1917 * Success: Handle to created window
1918 * Failure: NULL
1919 */
1920HWND WINAPI CreateMDIWindowW(
1921 LPCWSTR lpClassName, /* [in] Pointer to registered child class name */
1922 LPCWSTR lpWindowName, /* [in] Pointer to window name */
1923 DWORD dwStyle, /* [in] Window style */
1924 INT X, /* [in] Horizontal position of window */
1925 INT Y, /* [in] Vertical position of window */
1926 INT nWidth, /* [in] Width of window */
1927 INT nHeight, /* [in] Height of window */
1928 HWND hWndParent, /* [in] Handle to parent window */
1929 HINSTANCE hInstance, /* [in] Handle to application instance */
1930 LPARAM lParam) /* [in] Application-defined value */
1931{
1932 MDICLIENTINFO *pCi = get_client_info( hWndParent );
1933 MDICREATESTRUCTW cs;
1934
1935 TRACE("(%s,%s,%ld,%d,%d,%d,%d,%x,%d,%ld)\n",
1936 debugstr_w(lpClassName), debugstr_w(lpWindowName), dwStyle, X, Y,
1937 nWidth, nHeight, hWndParent, hInstance, lParam);
1938
1939 if (!pCi)
1940 {
1941 ERR("bad hwnd for MDI-client: %04x\n", hWndParent);
1942 return 0;
1943 }
1944 cs.szClass = lpClassName;
1945 cs.szTitle = lpWindowName;
1946 cs.hOwner = hInstance;
1947 cs.x = X;
1948 cs.y = Y;
1949 cs.cx = nWidth;
1950 cs.cy = nHeight;
1951 cs.style = dwStyle;
1952 cs.lParam = lParam;
1953
1954 return MDICreateChild(hWndParent, pCi, (MDICREATESTRUCTA *)&cs, TRUE);
1955}
1956
1957#ifndef __WIN32OS2__
1958/**********************************************************************
1959 * TranslateMDISysAccel (USER.451)
1960 */
1961BOOL16 WINAPI TranslateMDISysAccel16( HWND16 hwndClient, LPMSG16 msg )
1962{
1963 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1964 {
1965 MSG msg32;
1966 msg32.hwnd = msg->hwnd;
1967 msg32.message = msg->message;
1968 msg32.wParam = msg->wParam;
1969 msg32.lParam = msg->lParam;
1970 /* MDICLIENTINFO is still the same for win32 and win16 ... */
1971 return TranslateMDISysAccel(hwndClient, &msg32);
1972 }
1973 return 0;
1974}
1975#endif
1976
1977/**********************************************************************
1978 * TranslateMDISysAccel (USER32.@)
1979 */
1980BOOL WINAPI TranslateMDISysAccel( HWND hwndClient, LPMSG msg )
1981{
1982 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1983 {
1984 MDICLIENTINFO *ci = get_client_info( hwndClient );
1985 WPARAM wParam = 0;
1986
1987 if (!ci || !IsWindowEnabled(ci->hwndActiveChild)) return 0;
1988
1989 /* translate if the Ctrl key is down and Alt not. */
1990
1991 if( (GetKeyState(VK_CONTROL) & 0x8000) && !(GetKeyState(VK_MENU) & 0x8000))
1992 {
1993 switch( msg->wParam )
1994 {
1995 case VK_F6:
1996 case VK_TAB:
1997 wParam = ( GetKeyState(VK_SHIFT) & 0x8000 ) ? SC_NEXTWINDOW : SC_PREVWINDOW;
1998 break;
1999 case VK_F4:
2000 case VK_RBUTTON:
2001 wParam = SC_CLOSE;
2002 break;
2003 default:
2004 return 0;
2005 }
2006 TRACE("wParam = %04x\n", wParam);
2007 SendMessageW(ci->hwndActiveChild, WM_SYSCOMMAND, wParam, (LPARAM)msg->wParam);
2008 return 1;
2009 }
2010 }
2011 return 0; /* failure */
2012}
2013
2014#ifndef __WIN32OS2__
2015/***********************************************************************
2016 * CalcChildScroll (USER.462)
2017 */
2018void WINAPI CalcChildScroll16( HWND16 hwnd, WORD scroll )
2019{
2020 return CalcChildScroll( hwnd, scroll );
2021}
2022#endif
2023
2024/***********************************************************************
2025 * CalcChildScroll (USER32.@)
2026 */
2027void WINAPI CalcChildScroll( HWND hwnd, INT scroll )
2028{
2029 SCROLLINFO info;
2030 RECT childRect, clientRect;
2031 INT vmin, vmax, hmin, hmax, vpos, hpos;
2032 HWND *list;
2033
2034 GetClientRect( hwnd, &clientRect );
2035 SetRectEmpty( &childRect );
2036
2037 if ((list = WIN_ListChildren( hwnd )))
2038 {
2039 int i;
2040 for (i = 0; list[i]; i++)
2041 {
2042 DWORD style = GetWindowLongW( list[i], GWL_STYLE );
2043 if (style & WS_MAXIMIZE)
2044 {
2045 HeapFree( GetProcessHeap(), 0, list );
2046 ShowScrollBar( hwnd, SB_BOTH, FALSE );
2047 return;
2048 }
2049 if (style & WS_VISIBLE)
2050 {
2051#ifdef __WIN32OS2__
2052 RECT rect;
2053 GetWindowRectParent(list[i], &rect);
2054 UnionRect( &childRect, &rect, &childRect );
2055#else
2056 WND *pWnd = WIN_FindWndPtr( list[i] );
2057 UnionRect( &childRect, &pWnd->rectWindow, &childRect );
2058 WIN_ReleaseWndPtr( pWnd );
2059#endif
2060 }
2061 }
2062 HeapFree( GetProcessHeap(), 0, list );
2063 }
2064 UnionRect( &childRect, &clientRect, &childRect );
2065
2066 hmin = childRect.left;
2067 hmax = childRect.right - clientRect.right;
2068 hpos = clientRect.left - childRect.left;
2069 vmin = childRect.top;
2070 vmax = childRect.bottom - clientRect.bottom;
2071 vpos = clientRect.top - childRect.top;
2072
2073 switch( scroll )
2074 {
2075 case SB_HORZ:
2076 vpos = hpos; vmin = hmin; vmax = hmax;
2077 case SB_VERT:
2078 info.cbSize = sizeof(info);
2079 info.nMax = vmax; info.nMin = vmin; info.nPos = vpos;
2080 info.fMask = SIF_POS | SIF_RANGE;
2081 SetScrollInfo(hwnd, scroll, &info, TRUE);
2082 break;
2083 case SB_BOTH:
2084 SCROLL_SetNCSbState( hwnd, vmin, vmax, vpos,
2085 hmin, hmax, hpos);
2086 }
2087}
2088
2089
2090#ifndef __WIN32OS2__
2091/***********************************************************************
2092 * ScrollChildren (USER.463)
2093 */
2094void WINAPI ScrollChildren16(HWND16 hWnd, UINT16 uMsg, WPARAM16 wParam, LPARAM lParam)
2095{
2096 ScrollChildren( hWnd, uMsg, wParam, lParam );
2097}
2098#endif
2099
2100/***********************************************************************
2101 * ScrollChildren (USER32.@)
2102 */
2103void WINAPI ScrollChildren(HWND hWnd, UINT uMsg, WPARAM wParam,
2104 LPARAM lParam)
2105{
2106 INT newPos = -1;
2107 INT curPos, length, minPos, maxPos, shift;
2108 RECT rect;
2109
2110 GetClientRect( hWnd, &rect );
2111
2112 switch(uMsg)
2113 {
2114 case WM_HSCROLL:
2115 GetScrollRange(hWnd,SB_HORZ,&minPos,&maxPos);
2116 curPos = GetScrollPos(hWnd,SB_HORZ);
2117 length = (rect.right - rect.left) / 2;
2118 shift = GetSystemMetrics(SM_CYHSCROLL);
2119 break;
2120 case WM_VSCROLL:
2121 GetScrollRange(hWnd,SB_VERT,&minPos,&maxPos);
2122 curPos = GetScrollPos(hWnd,SB_VERT);
2123 length = (rect.bottom - rect.top) / 2;
2124 shift = GetSystemMetrics(SM_CXVSCROLL);
2125 break;
2126 default:
2127 return;
2128 }
2129
2130 switch( wParam )
2131 {
2132 case SB_LINEUP:
2133 newPos = curPos - shift;
2134 break;
2135 case SB_LINEDOWN:
2136 newPos = curPos + shift;
2137 break;
2138 case SB_PAGEUP:
2139 newPos = curPos - length;
2140 break;
2141 case SB_PAGEDOWN:
2142 newPos = curPos + length;
2143 break;
2144
2145 case SB_THUMBPOSITION:
2146 newPos = LOWORD(lParam);
2147 break;
2148
2149 case SB_THUMBTRACK:
2150 return;
2151
2152 case SB_TOP:
2153 newPos = minPos;
2154 break;
2155 case SB_BOTTOM:
2156 newPos = maxPos;
2157 break;
2158 case SB_ENDSCROLL:
2159 CalcChildScroll(hWnd,(uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ);
2160 return;
2161 }
2162
2163 if( newPos > maxPos )
2164 newPos = maxPos;
2165 else
2166 if( newPos < minPos )
2167 newPos = minPos;
2168
2169 SetScrollPos(hWnd, (uMsg == WM_VSCROLL)?SB_VERT:SB_HORZ , newPos, TRUE);
2170
2171 if( uMsg == WM_VSCROLL )
2172 ScrollWindowEx(hWnd ,0 ,curPos - newPos, NULL, NULL, 0, NULL,
2173 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2174 else
2175 ScrollWindowEx(hWnd ,curPos - newPos, 0, NULL, NULL, 0, NULL,
2176 SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN );
2177}
2178
2179
2180/******************************************************************************
2181 * CascadeWindows (USER32.@) Cascades MDI child windows
2182 *
2183 * RETURNS
2184 * Success: Number of cascaded windows.
2185 * Failure: 0
2186 */
2187WORD WINAPI
2188CascadeWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2189 UINT cKids, const HWND *lpKids)
2190{
2191 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2192 hwndParent, wFlags, cKids);
2193
2194 return 0;
2195}
2196
2197
2198/******************************************************************************
2199 * TileWindows (USER32.@) Tiles MDI child windows
2200 *
2201 * RETURNS
2202 * Success: Number of tiled windows.
2203 * Failure: 0
2204 */
2205WORD WINAPI
2206TileWindows (HWND hwndParent, UINT wFlags, const LPRECT lpRect,
2207 UINT cKids, const HWND *lpKids)
2208{
2209 FIXME("(0x%08x,0x%08x,...,%u,...): stub\n",
2210 hwndParent, wFlags, cKids);
2211
2212 return 0;
2213}
2214
2215/************************************************************************
2216 * "More Windows..." functionality
2217 */
2218
2219/* MDI_MoreWindowsDlgProc
2220 *
2221 * This function will process the messages sent to the "More Windows..."
2222 * dialog.
2223 * Return values: 0 = cancel pressed
2224 * HWND = ok pressed or double-click in the list...
2225 *
2226 */
2227
2228static BOOL WINAPI MDI_MoreWindowsDlgProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
2229{
2230 switch (iMsg)
2231 {
2232 case WM_INITDIALOG:
2233 {
2234 UINT widest = 0;
2235 UINT length;
2236 UINT i;
2237 MDICLIENTINFO *ci = get_client_info( (HWND)lParam );
2238 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2239 HWND *list, *sorted_list;
2240
2241 if (!(list = WIN_ListChildren( (HWND)lParam ))) return TRUE;
2242 if (!(sorted_list = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
2243 sizeof(HWND) * ci->nActiveChildren )))
2244 {
2245 HeapFree( GetProcessHeap(), 0, list );
2246 return FALSE;
2247 }
2248
2249 /* Fill the list, sorted by id... */
2250 for (i = 0; list[i]; i++)
2251 {
2252 UINT id = GetWindowLongW( list[i], GWL_ID ) - ci->idFirstChild;
2253 if (id < ci->nActiveChildren) sorted_list[id] = list[i];
2254 }
2255 HeapFree( GetProcessHeap(), 0, list );
2256
2257 for (i = 0; i < ci->nActiveChildren; i++)
2258 {
2259 WCHAR buffer[128];
2260
2261 if (!GetWindowTextW( sorted_list[i], buffer, sizeof(buffer)/sizeof(WCHAR) ))
2262 continue;
2263 SendMessageW(hListBox, LB_ADDSTRING, 0, (LPARAM)buffer );
2264 SendMessageW(hListBox, LB_SETITEMDATA, i, (LPARAM)sorted_list[i] );
2265 length = strlenW(buffer); /* FIXME: should use GetTextExtentPoint */
2266 if (length > widest)
2267 widest = length;
2268 }
2269 /* Make sure the horizontal scrollbar scrolls ok */
2270 SendMessageW(hListBox, LB_SETHORIZONTALEXTENT, widest * 6, 0);
2271
2272 /* Set the current selection */
2273 SendMessageW(hListBox, LB_SETCURSEL, MDI_MOREWINDOWSLIMIT, 0);
2274 return TRUE;
2275 }
2276
2277 case WM_COMMAND:
2278 switch (LOWORD(wParam))
2279 {
2280 default:
2281 if (HIWORD(wParam) != LBN_DBLCLK) break;
2282 /* fall through */
2283 case IDOK:
2284 {
2285 /* windows are sorted by menu ID, so we must return the
2286 * window associated to the given id
2287 */
2288 HWND hListBox = GetDlgItem(hDlg, MDI_IDC_LISTBOX);
2289 UINT index = SendMessageW(hListBox, LB_GETCURSEL, 0, 0);
2290 HWND hwnd = SendMessageW(hListBox, LB_GETITEMDATA, index, 0);
2291
2292 EndDialog(hDlg, hwnd);
2293 return TRUE;
2294 }
2295 case IDCANCEL:
2296 EndDialog(hDlg, 0);
2297 return TRUE;
2298 }
2299 break;
2300 }
2301 return FALSE;
2302}
2303
2304/*
2305 *
2306 * MDI_MoreWindowsDialog
2307 *
2308 * Prompts the user with a listbox containing the opened
2309 * documents. The user can then choose a windows and click
2310 * on OK to set the current window to the one selected, or
2311 * CANCEL to cancel. The function returns a handle to the
2312 * selected window.
2313 */
2314
2315static HWND MDI_MoreWindowsDialog(HWND hwnd)
2316{
2317 LPCVOID template;
2318 HRSRC hRes;
2319 HANDLE hDlgTmpl;
2320
2321 hRes = FindResourceA(GetModuleHandleA("USER32"), "MDI_MOREWINDOWS", RT_DIALOGA);
2322
2323 if (hRes == 0)
2324 return 0;
2325
2326 hDlgTmpl = LoadResource(GetModuleHandleA("USER32"), hRes );
2327
2328 if (hDlgTmpl == 0)
2329 return 0;
2330
2331 template = LockResource( hDlgTmpl );
2332
2333 if (template == 0)
2334 return 0;
2335
2336 return (HWND) DialogBoxIndirectParamA(GetModuleHandleA("USER32"),
2337 (LPDLGTEMPLATEA) template,
2338 hwnd, MDI_MoreWindowsDlgProc, (LPARAM) hwnd);
2339}
2340
2341/*
2342 *
2343 * MDI_SwapMenuItems
2344 *
2345 * Will swap the menu IDs for the given 2 positions.
2346 * pos1 and pos2 are menu IDs
2347 *
2348 *
2349 */
2350
2351static void MDI_SwapMenuItems(HWND parent, UINT pos1, UINT pos2)
2352{
2353 HWND *list;
2354 int i;
2355
2356 if (!(list = WIN_ListChildren( parent ))) return;
2357 for (i = 0; list[i]; i++)
2358 {
2359 UINT id = GetWindowLongW( list[i], GWL_ID );
2360 if (id == pos1) SetWindowLongW( list[i], GWL_ID, pos2 );
2361 else if (id == pos2) SetWindowLongW( list[i], GWL_ID, pos1 );
2362 }
2363 HeapFree( GetProcessHeap(), 0, list );
2364}
2365
2366#ifdef __WIN32OS2__
2367
2368#define MDICLIENTCLASSNAMEA "MDICLIENT"
2369#define MDICLIENTCLASSNAMEW L"MDICLIENT"
2370
2371//******************************************************************************
2372//******************************************************************************
2373BOOL MDICLIENT_Register()
2374{
2375 WNDCLASSA wndClass;
2376
2377//SvL: Don't check this now
2378// if (GlobalFindAtomA(MDICLIENTCLASSNAMEA)) return FALSE;
2379
2380 ZeroMemory(&wndClass,sizeof(WNDCLASSA));
2381 wndClass.style = CS_GLOBALCLASS;
2382 wndClass.lpfnWndProc = (WNDPROC)MDIClientWndProcA;
2383 wndClass.cbClsExtra = 0;
2384 wndClass.cbWndExtra = 0;
2385 wndClass.hCursor = LoadCursorA(0,IDC_ARROWA);;
2386 wndClass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
2387 wndClass.lpszClassName = MDICLIENTCLASSNAMEA;
2388
2389 return RegisterClassA(&wndClass);
2390}
2391//******************************************************************************
2392//******************************************************************************
2393BOOL MDICLIENT_Unregister()
2394{
2395 if (GlobalFindAtomA(MDICLIENTCLASSNAMEA))
2396 return UnregisterClassA(MDICLIENTCLASSNAMEA,(HINSTANCE)NULL);
2397 else return FALSE;
2398}
2399//******************************************************************************
2400//******************************************************************************
2401#endif
Note: See TracBrowser for help on using the repository browser.