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

Last change on this file since 2803 was 2803, checked in by sandervl, 26 years ago

Added new logging feature

File size: 16.1 KB
Line 
1/* $Id: win32wmdichild.cpp,v 1.22 2000-02-16 14:28:24 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 AppendMenuA(client->getMDIMenu(), MF_STRING ,wIDmenu, lpstrDef );
298
299 client->incNrActiveChildren();
300
301 /* fix window style */
302 if( !(client->getStyle() & MDIS_ALLCHILDSTYLES) )
303 {
304 style &= (WS_CHILD | WS_CLIPSIBLINGS | WS_MINIMIZE | WS_MAXIMIZE |
305 WS_CLIPCHILDREN | WS_DISABLED | WS_VSCROLL | WS_HSCROLL );
306 style |= (WS_VISIBLE | WS_OVERLAPPEDWINDOW);
307 }
308
309 createstruct.lpszName = cs->szTitle;
310 createstruct.style = style;
311 createstruct.dwExStyle = 0;
312 createstruct.x = cs->x;
313 createstruct.y = cs->y;
314 createstruct.cx = cs->cx;
315 createstruct.cy = cs->cy;
316 createstruct.hInstance = cs->hOwner;
317 createstruct.hMenu = wIDmenu;
318 createstruct.hwndParent= client->getWindowHandle();
319 createstruct.lpCreateParams = (LPVOID)cs;
320
321 className = (LPSTR)cs->szClass;
322 /* Find the class atom */
323 classAtom = GlobalFindAtomA(cs->szClass);
324 if(classAtom == 0)
325 {
326 if (!HIWORD(cs->szClass))
327 {
328 sprintf(tmpClassA,"#%d", (int) className);
329 classAtom = GlobalFindAtomA(tmpClassA);
330 className = tmpClassA;
331 }
332 if (!classAtom)
333 {
334 if (!HIWORD(cs->szClass)) {
335 dprintf(("createChild: bad class name %04x\n", LOWORD(className)));
336 }
337 else dprintf(("createChild: bad class name '%s'\n", tmpClassA ));
338
339 SetLastError(ERROR_INVALID_PARAMETER);
340 return 0;
341 }
342 }
343 createstruct.lpszClass = className;
344
345 newchild = new Win32MDIChildWindow(&createstruct, classAtom, FALSE);
346
347 if(newchild && GetLastError() == 0)
348 {
349 newchild->menuModifyItem();
350
351 if( newchild->getStyle() & WS_MINIMIZE && client->getActiveChild()) {
352 newchild->ShowWindow(SW_SHOWMINNOACTIVE);
353 }
354 else
355 {
356 /* WS_VISIBLE is clear if a) the MDI client has
357 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
358 * MDICreateStruct. If so the created window is not shown nor
359 * activated.
360 */
361 int showflag = newchild->getStyle() & WS_VISIBLE;
362 /* clear visible flag, otherwise SetWindoPos32 ignores
363 * the SWP_SHOWWINDOW command.
364 */
365 newchild->SetWindowLongA(GWL_STYLE, newchild->getStyle() & ~WS_VISIBLE);
366 if(showflag){
367 newchild->SetWindowPos(0, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE );
368
369 /* Set maximized state here in case hwnd didn't receive WM_SIZE
370 * during CreateWindow - bad!
371 */
372
373 if((newchild->getStyle() & WS_MAXIMIZE) && !client->getMaximizedChild() )
374 {
375 client->setMaximizedChild(newchild);
376
377 client->augmentFrameMenu(newchild);
378
379 client->updateFrameText(MDI_REPAINTFRAME, NULL );
380 }
381 }
382 else
383 /* needed, harmless ? */
384 newchild->SetWindowPos(0, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE );
385
386 }
387 }
388 else
389 {
390 client->decNrActiveChildren();
391 DeleteMenu(client->getMDIMenu(), wIDmenu,MF_BYCOMMAND);
392
393 maximizedChild = client->getMaximizedChild();
394 if( maximizedChild && maximizedChild->IsWindow() )
395 maximizedChild->ShowWindow(SW_SHOWMAXIMIZED);
396
397 dprintf(("MDI child creation failed!!"));
398 return 0;
399 }
400 return newchild->getWindowHandle();
401}
402/**********************************************************************
403 * MDI_MenuModifyItem
404 */
405BOOL Win32MDIChildWindow::menuModifyItem()
406{
407 Win32MDIClientWindow *client = (Win32MDIClientWindow *)getParent();
408 char buffer[128];
409 UINT id = getWindowId()-client->getFirstChildId()+1;
410 UINT n = sprintf(buffer,(id > 9) ? "%d":"&%d ",id);
411 BOOL bRet = 0;
412
413 if( !client->getMDIMenu() )
414 {
415 return FALSE;
416 }
417
418 if (getWindowNameA()) lstrcpynA(buffer + n, getWindowNameA(), sizeof(buffer) - n );
419
420 n = GetMenuState(client->getMDIMenu(), getWindowId() ,MF_BYCOMMAND);
421 bRet = ModifyMenuA(client->getMDIMenu() , getWindowId(),
422 MF_BYCOMMAND | MF_STRING, getWindowId(), buffer );
423 CheckMenuItem(client->getMDIMenu(), getWindowId() , n & MF_CHECKED);
424
425 return bRet;
426}
427
428/**********************************************************************
429 * MDI_MenuDeleteItem
430 */
431BOOL Win32MDIChildWindow::menuDeleteItem()
432{
433 Win32MDIClientWindow *client = (Win32MDIClientWindow *)getParent();
434 char buffer[128];
435 UINT index = 0,id,n;
436 BOOL retvalue;
437
438 if( !client->getNrOfChildren() ||
439 !client->getMDIMenu())
440 {
441 return FALSE;
442 }
443
444 id = getWindowId();
445 DeleteMenu(client->getMDIMenu(),id,MF_BYCOMMAND);
446
447 /* walk the rest of MDI children to prevent gaps in the id
448 * sequence and in the menu child list */
449
450 for( index = id+1; index <= client->getNrOfChildren() +
451 client->getFirstChildId(); index++ )
452 {
453 Win32MDIChildWindow *tmpWnd = client->getChildByID(index);
454 if( !tmpWnd )
455 {
456 dprintf(("no window for id=%i\n",index));
457 continue;
458 }
459
460 /* set correct id */
461 tmpWnd->setWindowId(tmpWnd->getWindowId()-1);
462
463 n = sprintf(buffer, "%d ",index - client->getFirstChildId());
464 if (tmpWnd->getWindowNameA())
465 lstrcpynA(buffer + n, tmpWnd->getWindowNameA(), sizeof(buffer) - n );
466
467 /* change menu */
468 ModifyMenuA(client->getMDIMenu(), index ,MF_BYCOMMAND | MF_STRING,
469 index - 1 , buffer );
470 }
471 return TRUE;
472}
473/**********************************************************************
474 * MDI_CalcDefaultChildPos
475 *
476 * It seems that the default height is about 2/3 of the client rect
477 */
478void Win32MDIChildWindow::calcDefaultChildPos(Win32MDIClientWindow *client, WORD n, LPPOINT lpPos, INT delta)
479{
480 INT nstagger;
481 RECT rect;
482 INT spacing = GetSystemMetrics(SM_CYCAPTION) +
483 GetSystemMetrics(SM_CYFRAME) - 1;
484
485 client->getClientRect(&rect);
486 if( rect.bottom - rect.top - delta >= spacing )
487 rect.bottom -= delta;
488
489 nstagger = (rect.bottom - rect.top)/(3 * spacing);
490 lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
491 lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
492 lpPos[0].x = lpPos[0].y = spacing * (n%(nstagger+1));
493}
494
495/**********************************************************************
496 * MDI_ChildGetMinMaxInfo
497 *
498 * Note: The rule here is that client rect of the maximized MDI child
499 * is equal to the client rect of the MDI client window.
500 */
501void Win32MDIChildWindow::childGetMinMaxInfo(MINMAXINFO* lpMinMax )
502{
503 Win32MDIClientWindow *client = (Win32MDIClientWindow *)getParent();
504 RECT rect;
505
506 if(client == NULL) {
507 dprintf(("Win32MDIChildWindow::childGetMinMaxInfo:: client == NULL!!"));
508 return;
509 }
510
511 client->getClientRect(&rect);
512 if(client->getParent() == NULL) {
513 dprintf(("Win32MDIChildWindow::childGetMinMaxInfo:: client parent == NULL!!"));
514 return;
515 }
516 MapWindowPoints(client->getParent()->getWindowHandle(), client->getWindowHandle(), (LPPOINT)&rect, 2);
517
518 AdjustWindowRectEx( &rect, getStyle(), 0, getExStyle());
519
520 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
521 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
522
523 lpMinMax->ptMaxPosition.x = rect.left;
524 lpMinMax->ptMaxPosition.y = rect.top;
525}
526
527//******************************************************************************
528//******************************************************************************
529
Note: See TracBrowser for help on using the repository browser.