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

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

class changes

File size: 17.5 KB
Line 
1/* $Id: win32wmdichild.cpp,v 1.7 1999-10-24 22:56:10 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#include "heapshared.h"
42
43
44//******************************************************************************
45//******************************************************************************
46Win32MDIChildWindow::Win32MDIChildWindow(CREATESTRUCTA *lpCreateStructA, ATOM classAtom, BOOL isUnicode)
47 : Win32BaseWindow(OBJTYPE_WINDOW)
48{
49 this->isUnicode = isUnicode;
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,(WPARAM16)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 SendMessageA(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 SendMessageW(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(), 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 if (!(classAtom = (client->IsUnicode() ? GlobalFindAtomW((LPWSTR)cs->szClass) :
351 GlobalFindAtomA(cs->szClass))))
352
353 {
354 if (!HIWORD(cs->szClass))
355 {
356 if(!client->IsUnicode())
357 {
358 sprintf(tmpClassA,"#%d", (int) className);
359 classAtom = GlobalFindAtomA(tmpClassA);
360 className = tmpClassA;
361 }
362 else
363 {
364 sprintf(tmpClassA,"#%d", (int) className);
365 AsciiToUnicode(tmpClassA, tmpClassW);
366 classAtom = GlobalFindAtomW(tmpClassW);
367 className = (LPSTR)tmpClassW;
368 }
369 }
370 if (!classAtom)
371 {
372 if (!HIWORD(cs->szClass)) {
373 dprintf(("createChild: bad class name %04x\n", LOWORD(className)));
374 }
375 else dprintf(("createChild: bad class name '%s'\n", tmpClassA ));
376
377 SetLastError(ERROR_INVALID_PARAMETER);
378 return 0;
379 }
380 }
381 createstruct.lpszClass = className;
382
383 newchild = new Win32MDIChildWindow(&createstruct, classAtom, client->IsUnicode());
384
385 if(newchild && GetLastError() == 0)
386 {
387 newchild->menuModifyItem();
388
389 if( newchild->getStyle() & WS_MINIMIZE && client->getActiveChild()) {
390 newchild->ShowWindow(SW_SHOWMINNOACTIVE);
391 }
392 else
393 {
394 /* WS_VISIBLE is clear if a) the MDI client has
395 * MDIS_ALLCHILDSTYLES style and 2) the flag is cleared in the
396 * MDICreateStruct. If so the created window is not shown nor
397 * activated.
398 */
399 int showflag = newchild->getStyle() & WS_VISIBLE;
400 /* clear visible flag, otherwise SetWindoPos32 ignores
401 * the SWP_SHOWWINDOW command.
402 */
403//SvL: Not here. This causes problems in OS/2
404// newchild->SetWindowLongA(GWL_STYLE, showflag & ~WS_VISIBLE);
405 if(showflag){
406 newchild->SetWindowPos(0, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE );
407
408 /* Set maximized state here in case hwnd didn't receive WM_SIZE
409 * during CreateWindow - bad!
410 */
411
412 if((newchild->getStyle() & WS_MAXIMIZE) && !client->getMaximizedChild() )
413 {
414 client->setMaximizedChild(newchild);
415#if 0
416 MDI_AugmentFrameMenu( ci, w->parent, newchild->getWindowHandle() );
417#endif
418 client->updateFrameText(MDI_REPAINTFRAME, NULL );
419 }
420 }
421 else
422 /* needed, harmless ? */
423 newchild->SetWindowPos(0, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE );
424
425 }
426 }
427 else
428 {
429 client->decNrActiveChildren();
430 DeleteMenu(client->getMDIMenu(), wIDmenu,MF_BYCOMMAND);
431
432 maximizedChild = client->getMaximizedChild();
433 if( maximizedChild && maximizedChild->IsWindow() )
434 maximizedChild->ShowWindow(SW_SHOWMAXIMIZED);
435
436 dprintf(("MDI child creation failed!!"));
437 return 0;
438 }
439 return newchild->getWindowHandle();
440}
441/**********************************************************************
442 * MDI_MenuModifyItem
443 */
444BOOL Win32MDIChildWindow::menuModifyItem()
445{
446 Win32MDIClientWindow *client = (Win32MDIClientWindow *)getParent();
447 char buffer[128];
448 UINT n = sprintf(buffer, "%d ", getWindowId() - client->getFirstChildId() + 1);
449 BOOL bRet = 0;
450
451 if( !client->getMDIMenu() )
452 {
453 return FALSE;
454 }
455
456 if (getWindowNameA()) lstrcpynA(buffer + n, getWindowNameA(), sizeof(buffer) - n );
457
458 n = GetMenuState(client->getMDIMenu(), getWindowId() ,MF_BYCOMMAND);
459 bRet = ModifyMenuA(client->getMDIMenu() , getWindowId(),
460 MF_BYCOMMAND | MF_STRING, getWindowId(), buffer );
461 CheckMenuItem(client->getMDIMenu(), getWindowId() , n & MF_CHECKED);
462
463 return bRet;
464}
465
466/**********************************************************************
467 * MDI_MenuDeleteItem
468 */
469BOOL Win32MDIChildWindow::menuDeleteItem()
470{
471 Win32MDIClientWindow *client = (Win32MDIClientWindow *)getParent();
472 char buffer[128];
473 UINT index = 0,id,n;
474 BOOL retvalue;
475
476 if( !client->getNrOfChildren() ||
477 !client->getMDIMenu())
478 {
479 return FALSE;
480 }
481
482 id = getWindowId();
483 DeleteMenu(client->getMDIMenu(),id,MF_BYCOMMAND);
484
485 /* walk the rest of MDI children to prevent gaps in the id
486 * sequence and in the menu child list */
487
488 for( index = id+1; index <= client->getNrOfChildren() +
489 client->getFirstChildId(); index++ )
490 {
491 Win32MDIChildWindow *tmpWnd = client->getChildByID(index);
492 if( !tmpWnd )
493 {
494 dprintf(("no window for id=%i\n",index));
495 continue;
496 }
497
498 /* set correct id */
499 tmpWnd->setWindowId(tmpWnd->getWindowId()-1);
500
501 n = sprintf(buffer, "%d ",index - client->getFirstChildId());
502 if (tmpWnd->getWindowNameA())
503 lstrcpynA(buffer + n, tmpWnd->getWindowNameA(), sizeof(buffer) - n );
504
505 /* change menu */
506 ModifyMenuA(client->getMDIMenu(), index ,MF_BYCOMMAND | MF_STRING,
507 index - 1 , buffer );
508 }
509 return TRUE;
510}
511/**********************************************************************
512 * MDI_CalcDefaultChildPos
513 *
514 * It seems that the default height is about 2/3 of the client rect
515 */
516void Win32MDIChildWindow::calcDefaultChildPos(Win32MDIClientWindow *client, WORD n, LPPOINT lpPos, INT delta)
517{
518 INT nstagger;
519 RECT rect = *client->getClientRect();
520 INT spacing = GetSystemMetrics(SM_CYCAPTION) +
521 GetSystemMetrics(SM_CYFRAME) - 1;
522
523 if( rect.bottom - rect.top - delta >= spacing )
524 rect.bottom -= delta;
525
526 nstagger = (rect.bottom - rect.top)/(3 * spacing);
527 lpPos[1].x = (rect.right - rect.left - nstagger * spacing);
528 lpPos[1].y = (rect.bottom - rect.top - nstagger * spacing);
529 lpPos[0].x = lpPos[0].y = spacing * (n%(nstagger+1));
530}
531
532/**********************************************************************
533 * MDI_ChildGetMinMaxInfo
534 *
535 * Note: The rule here is that client rect of the maximized MDI child
536 * is equal to the client rect of the MDI client window.
537 */
538void Win32MDIChildWindow::childGetMinMaxInfo(MINMAXINFO* lpMinMax )
539{
540 Win32MDIClientWindow *client = (Win32MDIClientWindow *)getParent();
541 RECT rect = *client->getClientRect();
542
543 if(client->getParent() == NULL) {
544 dprintf(("Win32MDIChildWindow::childGetMinMaxInfo:: client parent == NULL!!"));
545 return;
546 }
547 MapWindowPoints(client->getParent()->getWindowHandle(), client->getWindowHandle(), (LPPOINT)&rect, 2);
548
549 AdjustWindowRectEx( &rect, getStyle(), 0, getExStyle());
550
551 lpMinMax->ptMaxSize.x = rect.right -= rect.left;
552 lpMinMax->ptMaxSize.y = rect.bottom -= rect.top;
553
554 lpMinMax->ptMaxPosition.x = rect.left;
555 lpMinMax->ptMaxPosition.y = rect.top;
556}
557
558//******************************************************************************
559//******************************************************************************
560
Note: See TracBrowser for help on using the repository browser.