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

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

sendmessage + hook updates + misc fixes

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