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

Last change on this file since 9462 was 9437, checked in by sandervl, 23 years ago

CopyBitmap fix + use PM bitmaps for standard user32 frame buttons in OS/2 GUI mode

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