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

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

misc changes

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