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

Last change on this file since 2101 was 2101, checked in by cbratschi, 26 years ago

* empty log message *

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