source: trunk/src/user32/win32wmdichild.cpp@ 3603

Last change on this file since 3603 was 3603, checked in by sandervl, 25 years ago

experimental WM_NCHITTEST generation (disabled) + MDI fixes

File size: 16.5 KB
Line 
1/* $Id: win32wmdichild.cpp,v 1.23 2000-05-24 19:30:08 sandervl Exp $ */
2/*
3 * Win32 MDI Child Window Class for OS/2
4 *
5 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
6 *
7 * Based on Wine (windows\mdi.c) (990815)
8 *
9 * Copyright 1994, Bob Amstadt
10 * 1995,1996 Alex Korobka
11 * Copyright 1993, 1994 Alexandre Julliard
12 *
13 *
14 *
15 * TODO: See #if 0's
16 *
17 * Project Odin Software License can be found in LICENSE.TXT
18 *
19 */
20#include <os2win.h>
21#include <win.h>
22#include <stdlib.h>
23#include <stdio.h>
24#include <string.h>
25#include <stdarg.h>
26#include <assert.h>
27#include <misc.h>
28#include <heapstring.h>
29#include <win32wnd.h>
30#include <win32wmdiclient.h>
31#include <win32wmdichild.h>
32#include <spy.h>
33#include "wndmsg.h"
34#include <oslibwin.h>
35#include <oslibutil.h>
36#include <oslibgdi.h>
37#include <oslibres.h>
38#include "oslibdos.h"
39#include <winres.h>
40#include "syscolor.h"
41#include "win32wndhandle.h"
42
43#define DBG_LOCALLOG DBG_win32wmdichild
44#include "dbglocal.h"
45
46//******************************************************************************
47//******************************************************************************
48Win32MDIChildWindow::Win32MDIChildWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL fUnicode)
49 : Win32BaseWindow(OBJTYPE_WINDOW)
50{
51 isUnicode = fUnicode;
52 CreateWindowExA(lpCreateStructA, classAtom);
53}
54//******************************************************************************
55//******************************************************************************
56Win32MDIChildWindow::~Win32MDIChildWindow()
57{
58}
59//******************************************************************************
60//******************************************************************************
61BOOL Win32MDIChildWindow::isMDIChild()
62{
63 return TRUE;
64}
65//******************************************************************************
66//******************************************************************************
67LRESULT Win32MDIChildWindow::DefMDIChildProcA(UINT Msg, WPARAM wParam, LPARAM lParam)
68{
69 Win32MDIClientWindow *client = (Win32MDIClientWindow *)getParent();
70
71 switch (Msg)
72 {
73 case WM_SETTEXT:
74 DefWindowProcA(Msg, wParam, lParam);
75 menuModifyItem();
76 if( client->getMaximizedChild() == this )
77 client->updateFrameText(MDI_REPAINTFRAME, NULL);
78 return 0;
79
80 case WM_GETMINMAXINFO:
81 {
82 childGetMinMaxInfo((MINMAXINFO *)lParam);
83 return 0;
84 }
85
86 case WM_MENUCHAR:
87 /* MDI children don't have menu bars */
88 PostMessageA(client->getWindowHandle(), WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)LOWORD(wParam) );
89 return 0x00010000L;
90
91 case WM_CLOSE:
92 client->SendMessageA(WM_MDIDESTROY,(WPARAM)getWindowHandle(), 0L);
93 return 0;
94
95 case WM_SETFOCUS:
96 if(client->getActiveChild() != this )
97 client->childActivate(this);
98 break;
99
100 case WM_CHILDACTIVATE:
101 client->childActivate(this);
102 return 0;
103
104 case WM_NCPAINT:
105 break;
106
107 case WM_SYSCOMMAND:
108 switch( wParam )
109 {
110 case SC_MOVE:
111 if( client->getMaximizedChild() == this)
112 {
113 return 0;
114 }
115 break;
116 case SC_RESTORE:
117 case SC_MINIMIZE:
118 setStyle(getStyle() | WS_SYSMENU);
119 break;
120
121 case SC_MAXIMIZE:
122 if( client->getMaximizedChild() == this)
123 {
124 return client->SendMessageA(Msg, wParam, lParam);
125 }
126 setStyle(getStyle() & ~WS_SYSMENU);
127 break;
128
129 case SC_NEXTWINDOW:
130 client->SendMessageA(WM_MDINEXT, 0, 0);
131 return 0;
132
133 case SC_PREVWINDOW: //WM_MDINEXT??
134 client->SendMessageA(WM_MDINEXT, 0, 0);
135 return 0;
136 }
137 break;
138
139 case WM_SETVISIBLE:
140 if( client->getMaximizedChild()) {
141 client->setMdiFlags(client->getMdiFlags() & ~MDIF_NEEDUPDATE);
142 }
143 else client->postUpdate(SB_BOTH+1);
144 break;
145
146 case WM_SIZE:
147 /* do not change */
148 if( client->getActiveChild() == this && wParam != SIZE_MAXIMIZED )
149 {
150 client->setMaximizedChild(NULL);
151 client->restoreFrameMenu(this);
152 client->updateFrameText(MDI_REPAINTFRAME, NULL );
153 }
154
155 if( wParam == SIZE_MAXIMIZED )
156 {
157 Win32MDIChildWindow *maxChild = client->getMaximizedChild();
158
159 if( maxChild == this ) break;
160
161 if( maxChild)
162 {
163 maxChild->SendMessageA(WM_SETREDRAW, FALSE, 0L );
164 client->restoreFrameMenu(maxChild);
165 maxChild->ShowWindow(SW_SHOWNOACTIVATE);
166
167 maxChild->SendMessageA(WM_SETREDRAW, TRUE, 0L );
168 }
169
170 client->setMaximizedChild(this);
171 client->setActiveChild(this);
172
173 client->augmentFrameMenu(this);
174
175 client->updateFrameText(MDI_REPAINTFRAME, NULL );
176 }
177
178 if( wParam == SIZE_MINIMIZED )
179 {
180 Win32MDIChildWindow *switchTo = client->getWindow(this, TRUE, WS_MINIMIZE);
181
182 if( switchTo )
183 switchTo->SendMessageA(WM_CHILDACTIVATE, 0, 0L);
184 }
185
186 client->postUpdate(SB_BOTH+1);
187 break;
188
189#if 0
190 case WM_NEXTMENU:
191 if( wParam == VK_LEFT ) /* switch to frame system menu */
192 {
193 return MAKELONG( GetSubMenu(clientWnd->parent->hSysMenu, 0),
194 clientWnd->parent->hwndSelf );
195 goto END;
196 }
197 if( wParam == VK_RIGHT ) /* to frame menu bar */
198 {
199 retvalue = MAKELONG( clientWnd->parent->wIDmenu,
200 clientWnd->parent->hwndSelf );
201 goto END;
202 }
203#endif
204 case WM_SYSCHAR:
205 if (wParam == '-')
206 {
207 SendInternalMessageA(WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)(DWORD)VK_SPACE);
208 return 0;
209 }
210 }
211 return DefWindowProcA(Msg, wParam, lParam);
212}
213//******************************************************************************
214//******************************************************************************
215LRESULT Win32MDIChildWindow::DefMDIChildProcW(UINT Msg, WPARAM wParam, LPARAM lParam)
216{
217 Win32MDIClientWindow *client = (Win32MDIClientWindow *)getParent();
218
219 switch (Msg)
220 {
221 case WM_SETTEXT:
222 DefWindowProcW(Msg, wParam, lParam);
223 menuModifyItem();
224 if( client->getMaximizedChild() == this )
225 client->updateFrameText(MDI_REPAINTFRAME, NULL );
226
227 return 0;
228
229 case WM_GETMINMAXINFO:
230 case WM_MENUCHAR:
231 case WM_CLOSE:
232 case WM_SETFOCUS:
233 case WM_CHILDACTIVATE:
234 case WM_NCPAINT:
235 case WM_SYSCOMMAND:
236 case WM_SETVISIBLE:
237 case WM_SIZE:
238 case WM_NEXTMENU:
239 return DefMDIChildProcA(Msg, wParam, lParam );
240
241 case WM_SYSCHAR:
242 if (wParam == '-')
243 {
244 SendInternalMessageW(WM_SYSCOMMAND, SC_KEYMENU, (LPARAM)(DWORD)VK_SPACE);
245 return 0;
246 }
247 break;
248 }
249 return DefWindowProcW(Msg, wParam, lParam);
250}
251/**********************************************************************
252 * MDICreateChild
253 */
254HWND Win32MDIChildWindow::createChild(Win32MDIClientWindow *client, LPMDICREATESTRUCTA cs )
255{
256 POINT pos[2];
257 DWORD style = cs->style | (WS_CHILD | WS_CLIPSIBLINGS);
258 WORD wIDmenu = client->getFirstChildId() + client->getNrOfChildren();
259 char lpstrDef[]="junk!";
260 Win32MDIChildWindow *maximizedChild, *newchild;
261 CREATESTRUCTA createstruct;
262 ATOM classAtom;
263 char tmpClassA[20] = "";
264 WCHAR tmpClassW[20];
265 LPSTR className;
266
267 dprintf(("Win32MDIChildWindow::createChild %i,%i - dim %i,%i, style %08x\n",
268 cs->x, cs->y, cs->cx, cs->cy, (unsigned)cs->style));
269
270 /* calculate placement */
271 calcDefaultChildPos(client, client->incTotalCreated()-1, pos, 0);
272
273 if (cs->cx == CW_USEDEFAULT || !cs->cx) cs->cx = pos[1].x;
274 if (cs->cy == CW_USEDEFAULT || !cs->cy) cs->cy = pos[1].y;
275
276 if( cs->x == CW_USEDEFAULT )
277 {
278 cs->x = pos[0].x;
279 cs->y = pos[0].y;
280 }
281
282 /* restore current maximized child */
283 if( style & WS_VISIBLE && client->getMaximizedChild() )
284 {
285 if( style & WS_MAXIMIZE )
286 client->SendMessageA(WM_SETREDRAW, FALSE, 0L );
287
288 maximizedChild = client->getMaximizedChild();
289
290 maximizedChild->ShowWindow( SW_SHOWNOACTIVATE );
291
292 if( style & WS_MAXIMIZE )
293 client->SendMessageA(WM_SETREDRAW, TRUE, 0L );
294 }
295
296 /* this menu is needed to set a check mark in MDI_ChildActivate */
297 if(client->getMDIMenu())
298 AppendMenuA(client->getMDIMenu(), MF_STRING ,wIDmenu, lpstrDef );
299
300 client->incNrActiveChildren();
301
302 /* fix window style */
303 if( !(client->getStyle() & MDIS_ALLCHILDSTYLES) )
304 {
305 style &= (WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZE | WS_MAXIMIZE |
306 WS_CLIPCHILDREN | WS_DISABLED | WS_VSCROLL | WS_HSCROLL );
307 style |= (WS_VISIBLE | WS_OVERLAPPEDWINDOW);
308 }
309
310 createstruct.lpszName = cs->szTitle;
311 createstruct.style = style;
312 createstruct.dwExStyle = 0;
313 createstruct.x = cs->x;
314 createstruct.y = cs->y;
315 createstruct.cx = cs->cx;
316 createstruct.cy = cs->cy;
317 createstruct.hInstance = cs->hOwner;
318 createstruct.hMenu = wIDmenu;
319 createstruct.hwndParent= client->getWindowHandle();
320 createstruct.lpCreateParams = (LPVOID)cs;
321
322 className = (LPSTR)cs->szClass;
323 /* Find the class atom */
324 classAtom = GlobalFindAtomA(cs->szClass);
325 if(classAtom == 0)
326 {
327 if (!HIWORD(cs->szClass))
328 {
329 sprintf(tmpClassA,"#%d", (int) className);
330 classAtom = GlobalFindAtomA(tmpClassA);
331 className = tmpClassA;
332 }
333 if (!classAtom)
334 {
335 if (!HIWORD(cs->szClass)) {
336 dprintf(("createChild: bad class name %04x\n", LOWORD(className)));
337 }
338 else dprintf(("createChild: bad class name '%s'\n", tmpClassA ));
339
340 SetLastError(ERROR_INVALID_PARAMETER);
341 return 0;
342 }
343 }
344 createstruct.lpszClass = className;
345
346 newchild = new Win32MDIChildWindow(&createstruct, classAtom, FALSE);
347
348 if(newchild && GetLastError() == 0)
349 {
350 /* All MDI child windows have the WS_EX_MDICHILD style */
351 newchild->setExStyle(newchild->getExStyle() | WS_EX_MDICHILD);
352
353 newchild->menuModifyItem();
354
355 if( newchild->getStyle() & WS_MINIMIZE && client->getActiveChild()) {
356 newchild->ShowWindow(SW_SHOWMINNOACTIVE);
357 }
358 else
359 {
360 /* WS_VISIBLE is clear if a) the MDI client has
361 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
362 * MDICreateStruct. If so the created window is not shown nor
363 * activated.
364 */
365 int showflag = newchild->getStyle() & WS_VISIBLE;
366 /* clear visible flag, otherwise SetWindoPos32 ignores
367 * the SWP_SHOWWINDOW command.
368 */
369 newchild->setStyle(newchild->getStyle() & ~WS_VISIBLE);
370
371 if(showflag){
372 dprintf(("newchild->SetWindowPos active window %x", GetActiveWindow()));
373 newchild->SetWindowPos(HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE );
374 dprintf(("newchild->SetWindowPos active window %x", GetActiveWindow()));
375
376 /* Set maximized state here in case hwnd didn't receive WM_SIZE
377 * during CreateWindow - bad!
378 */
379
380 if((newchild->getStyle() & WS_MAXIMIZE) && !client->getMaximizedChild() )
381 {
382 client->setMaximizedChild(newchild);
383
384 client->augmentFrameMenu(newchild);
385
386 client->updateFrameText(MDI_REPAINTFRAME, NULL );
387 }
388 }
389 else
390 /* needed, harmless ? */
391 newchild->SetWindowPos(HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE );
392
393 }
394 }
395 else
396 {
397 client->decNrActiveChildren();
398 if(client->getMDIMenu()) {
399 DeleteMenu(client->getMDIMenu(), wIDmenu,MF_BYCOMMAND);
400 }
401
402 maximizedChild = client->getMaximizedChild();
403 if( maximizedChild && maximizedChild->IsWindow() )
404 maximizedChild->ShowWindow(SW_SHOWMAXIMIZED);
405
406 dprintf(("MDI child creation failed!!"));
407 return 0;
408 }
409 return newchild->getWindowHandle();
410}
411/**********************************************************************
412 * MDI_MenuModifyItem
413 */
414BOOL Win32MDIChildWindow::menuModifyItem()
415{
416 Win32MDIClientWindow *client = (Win32MDIClientWindow *)getParent();
417 char buffer[128];
418 UINT id = getWindowId()-client->getFirstChildId()+1;
419 UINT n = sprintf(buffer,(id > 9) ? "%d":"&%d ",id);
420 BOOL bRet = 0;
421
422 if( !client->getMDIMenu() )
423 {
424 return FALSE;
425 }
426
427 if (getWindowNameA()) lstrcpynA(buffer + n, getWindowNameA(), sizeof(buffer) - n );
428
429 n = GetMenuState(client->getMDIMenu(), getWindowId() ,MF_BYCOMMAND);
430 bRet = ModifyMenuA(client->getMDIMenu() , getWindowId(),
431 MF_BYCOMMAND | MF_STRING, getWindowId(), buffer );
432 CheckMenuItem(client->getMDIMenu(), getWindowId() , n & MF_CHECKED);
433
434 return bRet;
435}
436
437/**********************************************************************
438 * MDI_MenuDeleteItem
439 */
440BOOL Win32MDIChildWindow::menuDeleteItem()
441{
442 Win32MDIClientWindow *client = (Win32MDIClientWindow *)getParent();
443 char buffer[128];
444 UINT index = 0,id,n;
445 BOOL retvalue;
446
447 if( !client->getNrOfChildren() ||
448 !client->getMDIMenu())
449 {
450 return FALSE;
451 }
452
453 id = getWindowId();
454 DeleteMenu(client->getMDIMenu(),id,MF_BYCOMMAND);
455
456 /* walk the rest of MDI children to prevent gaps in the id
457 * sequence and in the menu child list */
458
459 for( index = id+1; index <= client->getNrOfChildren() +
460 client->getFirstChildId(); index++ )
461 {
462 Win32MDIChildWindow *tmpWnd = client->getChildByID(index);
463 if( !tmpWnd )
464 {
465 dprintf(("no window for id=%i\n",index));
466 continue;
467 }
468
469 /* set correct id */
470 tmpWnd->setWindowId(tmpWnd->getWindowId()-1);
471
472 n = sprintf(buffer, "%d ",index - client->getFirstChildId());
473 if (tmpWnd->getWindowNameA())
474 lstrcpynA(buffer + n, tmpWnd->getWindowNameA(), sizeof(buffer) - n );
475
476 /* change menu */
477 ModifyMenuA(client->getMDIMenu(), index ,MF_BYCOMMAND | MF_STRING,
478 index - 1 , buffer );
479 }
480 return TRUE;
481}
482/**********************************************************************
483 * MDI_CalcDefaultChildPos
484 *
485 * It seems that the default height is about 2/3 of the client rect
486 */
487void Win32MDIChildWindow::calcDefaultChildPos(Win32MDIClientWindow *client, WORD n, LPPOINT lpPos, INT delta)
488{
489 INT nstagger;
490 RECT rect;
491 INT spacing = GetSystemMetrics(SM_CYCAPTION) +
492 GetSystemMetrics(SM_CYFRAME) - 1;
493
494 client->getClientRect(&rect);
495 if( rect.bottom - rect.top - delta >= spacing )
496 rect.bottom -= delta;
497
498 nstagger = (rect.bottom - rect.top)/(3 * spacing);
499 lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
500 lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
501 lpPos[0].x = lpPos[0].y = spacing * (n%(nstagger+1));
502}
503
504/**********************************************************************
505 * MDI_ChildGetMinMaxInfo
506 *
507 * Note: The rule here is that client rect of the maximized MDI child
508 * is equal to the client rect of the MDI client window.
509 */
510void Win32MDIChildWindow::childGetMinMaxInfo(MINMAXINFO* lpMinMax )
511{
512 Win32MDIClientWindow *client = (Win32MDIClientWindow *)getParent();
513 RECT rect;
514
515 if(client == NULL) {
516 dprintf(("Win32MDIChildWindow::childGetMinMaxInfo:: client == NULL!!"));
517 return;
518 }
519
520 client->getClientRect(&rect);
521 if(client->getParent() == NULL) {
522 dprintf(("Win32MDIChildWindow::childGetMinMaxInfo:: client parent == NULL!!"));
523 return;
524 }
525 MapWindowPoints(client->getParent()->getWindowHandle(), client->getWindowHandle(), (LPPOINT)&rect, 2);
526
527 AdjustWindowRectEx( &rect, getStyle(), 0, getExStyle());
528
529 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
530 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
531
532 lpMinMax->ptMaxPosition.x = rect.left;
533 lpMinMax->ptMaxPosition.y = rect.top;
534}
535
536//******************************************************************************
537//******************************************************************************
538
Note: See TracBrowser for help on using the repository browser.