]> git.saurik.com Git - wxWidgets.git/blob - src/msw/mdi.cpp
somehow log target wasn't being created automatically anymore. Restored.
[wxWidgets.git] / src / msw / mdi.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: mdi.cpp
3 // Purpose: MDI classes
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "mdi.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/setup.h"
25 #include "wx/frame.h"
26 #include "wx/menu.h"
27 #include "wx/app.h"
28 #include "wx/utils.h"
29 #include "wx/dialog.h"
30 #include "wx/statusbr.h"
31 #include "wx/settings.h"
32 #endif
33
34 #include "wx/mdi.h"
35 #include "wx/msw/private.h"
36
37 #if USE_NATIVE_STATUSBAR
38 #include <wx/msw/statbr95.h>
39 #endif
40
41 #include <string.h>
42
43 extern wxList wxModelessWindows;
44 extern wxMenu *wxCurrentPopupMenu;
45
46 #define IDM_WINDOWTILE 4001
47 #define IDM_WINDOWCASCADE 4002
48 #define IDM_WINDOWICONS 4003
49 #define IDM_WINDOWNEXT 4004
50 // This range gives a maximum of 500
51 // MDI children. Should be enough :-)
52 #define wxFIRST_MDI_CHILD 4100
53 #define wxLAST_MDI_CHILD 4600
54
55 // Status border dimensions
56 #define wxTHICK_LINE_BORDER 3
57 #define wxTHICK_LINE_WIDTH 1
58
59 extern char wxMDIFrameClassName[];
60 extern char wxMDIChildFrameClassName[];
61 extern wxWindow *wxWndHook;
62
63 #if !USE_SHARED_LIBRARY
64 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame)
65 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame)
66 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow)
67
68 BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame)
69 EVT_SIZE(wxMDIParentFrame::OnSize)
70 EVT_ACTIVATE(wxMDIParentFrame::OnActivate)
71 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged)
72 END_EVENT_TABLE()
73
74 BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow)
75 EVT_SCROLL(wxMDIClientWindow::OnScroll)
76 END_EVENT_TABLE()
77
78 #endif
79
80 wxMDIParentFrame::wxMDIParentFrame(void)
81 {
82 m_clientWindow = NULL;
83 m_currentChild = NULL;
84 m_windowMenu = 0;
85 m_parentFrameActive = TRUE;
86 }
87
88 bool wxMDIParentFrame::Create(wxWindow *parent,
89 wxWindowID id,
90 const wxString& title,
91 const wxPoint& pos,
92 const wxSize& size,
93 long style,
94 const wxString& name)
95 {
96 m_defaultIcon = (WXHICON) (wxSTD_MDIPARENTFRAME_ICON ? wxSTD_MDIPARENTFRAME_ICON : wxDEFAULT_MDIPARENTFRAME_ICON);
97
98 m_clientWindow = NULL;
99 m_currentChild = NULL;
100 m_windowMenu = 0;
101 m_parentFrameActive = TRUE;
102
103 if (!parent)
104 wxTopLevelWindows.Append(this);
105
106 SetName(name);
107 m_windowStyle = style;
108
109 if (parent) parent->AddChild(this);
110
111 if ( id > -1 )
112 m_windowId = id;
113 else
114 m_windowId = (int)NewControlId();
115
116 int x = pos.x;
117 int y = pos.y;
118 int width = size.x;
119 int height = size.y;
120
121 m_windowMenu = (WXHMENU) ::LoadMenu(wxGetInstance(), "wxWindowMenu");
122
123 #if WXDEBUG > 1
124 wxDebugMsg("Loaded m_windowMenu %d\n", m_windowMenu);
125 #endif
126
127 DWORD msflags = WS_OVERLAPPED ;
128 if (style & wxMINIMIZE_BOX)
129 msflags |= WS_MINIMIZEBOX;
130 if (style & wxMAXIMIZE_BOX)
131 msflags |= WS_MAXIMIZEBOX;
132 if (style & wxTHICK_FRAME)
133 msflags |= WS_THICKFRAME;
134 if (style & wxSYSTEM_MENU)
135 msflags |= WS_SYSMENU;
136 if ((style & wxMINIMIZE) || (style & wxICONIZE))
137 msflags |= WS_MINIMIZE;
138 if (style & wxMAXIMIZE)
139 msflags |= WS_MAXIMIZE;
140 if (style & wxCAPTION)
141 msflags |= WS_CAPTION;
142
143 // Adding WS_CLIPCHILDREN causes children not to be properly
144 // drawn when first displaying them.
145 // if (style & wxCLIP_CHILDREN)
146 // msflags |= WS_CLIPCHILDREN;
147
148 wxWindow::MSWCreate(m_windowId, parent, wxMDIFrameClassName, this, title, x, y, width, height,
149 msflags);
150
151 wxModelessWindows.Append(this);
152
153 return TRUE;
154 }
155
156 wxMDIParentFrame::~wxMDIParentFrame(void)
157 {
158 DestroyChildren();
159
160 DestroyMenu((HMENU) m_windowMenu); // Destroy dummy "Window" menu
161 m_windowMenu = 0;
162
163 if (m_clientWindow->MSWGetOldWndProc())
164 m_clientWindow->UnsubclassWin();
165
166 m_clientWindow->m_hWnd = 0;
167 delete m_clientWindow;
168 }
169
170 // Get size *available for subwindows* i.e. excluding menu bar.
171 void wxMDIParentFrame::GetClientSize(int *x, int *y) const
172 {
173 RECT rect;
174 GetClientRect((HWND) GetHWND(), &rect);
175
176 int cwidth = rect.right;
177 int cheight = rect.bottom;
178
179 if ( GetStatusBar() )
180 {
181 int sw, sh;
182 GetStatusBar()->GetSize(&sw, &sh);
183 cheight -= sh;
184 }
185
186 wxPoint pt(GetClientAreaOrigin());
187 cheight -= pt.y;
188 cwidth -= pt.x;
189
190 *x = cwidth;
191 *y = cheight;
192 }
193
194 void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar)
195 {
196 if (!menu_bar)
197 {
198 m_frameMenuBar = NULL;
199 return;
200 }
201
202 if (menu_bar->m_menuBarFrame)
203 return;
204
205 int i;
206 HMENU menu = CreateMenu();
207
208 for (i = 0; i < menu_bar->m_menuCount; i ++)
209 {
210 HMENU popup = (HMENU)menu_bar->m_menus[i]->m_hMenu;
211 //
212 // After looking Bounds Checker result, it seems that all
213 // menus must be individually destroyed. So, don't reset m_hMenu,
214 // to allow ~wxMenu to do the job.
215 //
216 menu_bar->m_menus[i]->m_savehMenu = (WXHMENU) popup;
217 // Uncommenting for the moment... JACS
218 menu_bar->m_menus[i]->m_hMenu = (WXHMENU) NULL;
219 AppendMenu(menu, MF_POPUP | MF_STRING, (UINT)popup, menu_bar->m_titles[i]);
220 }
221
222 menu_bar->m_hMenu = (WXHMENU)menu;
223 if (m_frameMenuBar)
224 delete m_frameMenuBar;
225
226 this->m_hMenu = (WXHMENU) menu;
227
228 // MDI parent-specific code follows
229
230 HMENU subMenu = GetSubMenu((HMENU) m_windowMenu, 0);
231
232 // Try to insert Window menu in front of Help, otherwise append it.
233 int N = GetMenuItemCount(menu);
234 bool success = FALSE;
235 for (i = 0; i < N; i++)
236 {
237 char buf[100];
238 int chars = GetMenuString(menu, i, buf, 100, MF_BYPOSITION);
239 if ((chars > 0) && (strcmp(buf, "&Help") == 0 ||
240 strcmp(buf, "Help") == 0))
241 {
242 success = TRUE;
243 InsertMenu(menu, i, MF_BYPOSITION | MF_POPUP | MF_STRING,
244 (UINT)subMenu, "&Window");
245 break;
246 }
247 }
248 if (!success)
249 AppendMenu(menu, MF_POPUP,
250 (UINT)subMenu,
251 "&Window");
252 m_parentFrameActive = TRUE;
253 #ifdef __WIN32__
254 SendMessage((HWND) GetClientWindow()->GetHWND(), WM_MDISETMENU,
255 (WPARAM)menu,
256 (LPARAM)subMenu);
257 #else
258 SendMessage((HWND) GetClientWindow()->GetHWND(), WM_MDISETMENU, 0,
259 MAKELPARAM(menu, subMenu));
260 #endif
261 DrawMenuBar((HWND) GetHWND());
262
263 m_frameMenuBar = menu_bar;
264 menu_bar->m_menuBarFrame = this;
265 }
266
267 void wxMDIParentFrame::OnSize(wxSizeEvent& event)
268 {
269 #if USE_CONSTRAINTS
270 if (GetAutoLayout())
271 Layout();
272 #endif
273 int x = 0;
274 int y = 0;
275 int width, height;
276 GetClientSize(&width, &height);
277
278 if ( GetClientWindow() )
279 GetClientWindow()->SetSize(x, y, width, height);
280
281 /* Already done in MSWOnSize
282 // forward WM_SIZE to status bar control
283 #if USE_NATIVE_STATUSBAR
284 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
285 ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
286 #endif
287 */
288
289 }
290
291 void wxMDIParentFrame::OnActivate(wxActivateEvent& event)
292 {
293 // Do nothing
294 }
295
296 #if WXWIN_COMPATIBILITY
297 /*
298 void wxMDIParentFrame::OldOnSize(int x, int y)
299 {
300 #if WXWIN_COMPATIBILITY == 1
301 wxSizeEvent event(wxSize(x, y), m_windowId);
302 event.SetEventObject( this );
303 GetEventHandler()->ProcessEvent(event);
304 #else
305
306 #if USE_CONSTRAINTS
307 if (GetAutoLayout())
308 Layout();
309 #endif
310 int x = 0;
311 int y = 0;
312 int width, height;
313 GetClientSize(&width, &height);
314 if ( GetToolBar() )
315 {
316 int wt, ht;
317 GetToolBar()->GetSize(&wt, &ht);
318 height -= ht;
319 y += ht;
320 }
321
322 if ( GetClientWindow() )
323 GetClientWindow()->SetSize(x, y, width, height);
324
325 #endif
326 }
327
328 // Default activation behaviour - nothing.
329 // Default activation behaviour - override dedault wxFrame behaviour
330 void wxMDIParentFrame::OldOnActivate(bool flag)
331 {
332 #if WXWIN_COMPATIBILITY == 1
333 wxActivateEvent event(wxEVT_ACTIVATE, flag, m_windowId);
334 event.SetEventObject( this );
335 GetEventHandler()->ProcessEvent(event);
336 #else
337 #endif
338 }
339 */
340
341 #endif
342
343 // Returns the active MDI child window
344 wxMDIChildFrame *wxMDIParentFrame::GetActiveChild(void) const
345 {
346 // HWND hWnd = (HWND)LOWORD(SendMessage((HWND) GetClientWindow()->GetHWND(), WM_MDIGETACTIVE, 0, 0L));
347 HWND hWnd = (HWND)SendMessage((HWND) GetClientWindow()->GetHWND(), WM_MDIGETACTIVE, 0, 0L);
348 if (hWnd == 0)
349 return NULL;
350 else
351 return (wxMDIChildFrame *)wxFindWinFromHandle((WXHWND) hWnd);
352 }
353
354 // Create the client window class (don't Create the window,
355 // just return a new class)
356 wxMDIClientWindow *wxMDIParentFrame::OnCreateClient(void)
357 {
358 return new wxMDIClientWindow ;
359 }
360
361 // Responds to colour changes, and passes event on to children.
362 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
363 {
364 if ( m_clientWindow )
365 {
366 m_clientWindow->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
367 m_clientWindow->Refresh();
368 }
369 /*
370 if ( m_frameToolBar )
371 {
372 wxSysColourChangedEvent event2;
373 event2.eventObject = m_frameToolBar;
374 m_frameToolBar->GetEventHandler()->ProcessEvent(event2);
375 }
376 */
377
378 // Propagate the event to the non-top-level children
379 wxFrame::OnSysColourChanged(event);
380 }
381
382 // MDI operations
383 void wxMDIParentFrame::Cascade(void)
384 {
385 ::SendMessage( (HWND) GetClientWindow()->GetHWND(), WM_MDICASCADE, 0, 0);
386 }
387
388 void wxMDIParentFrame::Tile(void)
389 {
390 ::SendMessage( (HWND) GetClientWindow()->GetHWND(), WM_MDITILE, MDITILE_HORIZONTAL, 0);
391 }
392
393 void wxMDIParentFrame::ArrangeIcons(void)
394 {
395 ::SendMessage( (HWND) GetClientWindow()->GetHWND(), WM_MDIICONARRANGE, 0, 0);
396 }
397
398 void wxMDIParentFrame::ActivateNext(void)
399 {
400 ::SendMessage( (HWND) GetClientWindow()->GetHWND(), WM_MDINEXT, 0, 0);
401 }
402
403 void wxMDIParentFrame::ActivatePrevious(void)
404 {
405 ::SendMessage( (HWND) GetClientWindow()->GetHWND(), WM_MDINEXT, 0, 1);
406 }
407
408
409 /*
410 // Returns a style for the client window - usually 0
411 // or, for example, wxHSCROLL | wxVSCROLL
412 long wxMDIParentFrame::GetClientStyle(void) const
413 {
414 return wxHSCROLL | wxVSCROLL ;
415 }
416 */
417
418 bool wxMDIParentFrame::MSWOnDestroy(void)
419 {
420 return FALSE;
421 }
422
423 void wxMDIParentFrame::MSWOnCreate(WXLPCREATESTRUCT WXUNUSED(cs))
424 {
425 m_clientWindow = OnCreateClient();
426 // Uses own style for client style
427 m_clientWindow->CreateClient(this, GetWindowStyleFlag());
428 }
429
430 void wxMDIParentFrame::MSWOnSize(int x, int y, WXUINT id)
431 {
432 switch (id)
433 {
434 case SIZEFULLSCREEN:
435 case SIZENORMAL:
436 m_iconized = FALSE;
437 break;
438 case SIZEICONIC:
439 m_iconized = TRUE;
440 break;
441 }
442
443 if (!m_iconized)
444 {
445 // forward WM_SIZE to status bar control
446 #if USE_NATIVE_STATUSBAR
447 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
448 {
449 wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId());
450 event.SetEventObject( m_frameStatusBar );
451
452 ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
453 }
454 #endif
455
456 PositionStatusBar();
457 PositionToolBar();
458
459 wxSizeEvent event(wxSize(x, y), m_windowId);
460 event.SetEventObject( this );
461 if (!GetEventHandler()->ProcessEvent(event))
462 Default();
463 }
464 }
465
466 bool wxMDIParentFrame::MSWOnActivate(int state, bool minimized, WXHWND activate)
467 {
468 wxWindow::MSWOnActivate(state, minimized, activate);
469
470 // If this window is an MDI parent, we must also send an OnActivate message
471 // to the current child.
472 if ((m_currentChild != NULL) && ((state == WA_ACTIVE) || (state == WA_CLICKACTIVE)))
473 {
474 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_currentChild->GetId());
475 event.SetEventObject( m_currentChild );
476 m_currentChild->GetEventHandler()->ProcessEvent(event);
477 }
478 return 0;
479 }
480
481 bool wxMDIParentFrame::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control)
482 {
483 // if (cmd == 0) // Why did I do this test?
484 {
485 // In case it's e.g. a toolbar.
486 wxWindow *win = wxFindWinFromHandle(control);
487 if (win)
488 return win->MSWCommand(cmd, id);
489
490 /*
491 if (wxCurrentPopupMenu)
492 {
493 wxMenu *popupMenu = wxCurrentPopupMenu;
494 wxCurrentPopupMenu = NULL;
495 if (!popupMenu->MSWCommand(cmd, id))
496 return TRUE;
497 }
498 */
499
500 switch (id)
501 {
502 case IDM_WINDOWCASCADE:
503 SendMessage((HWND) GetClientWindow()->GetHWND(), WM_MDICASCADE, MDITILE_SKIPDISABLED, 0);
504 return TRUE;
505 case IDM_WINDOWTILE:
506 SendMessage((HWND) GetClientWindow()->GetHWND(), WM_MDITILE, MDITILE_HORIZONTAL, 0);
507 return TRUE;
508 case IDM_WINDOWICONS:
509 SendMessage((HWND) GetClientWindow()->GetHWND(), WM_MDIICONARRANGE, 0, 0);
510 return TRUE;
511 case IDM_WINDOWNEXT:
512 SendMessage((HWND) GetClientWindow()->GetHWND(), WM_MDINEXT, 0, 0);
513 return TRUE;
514 default:
515 break;
516 }
517 if (id >= 0xF000)
518 {
519 #if WXDEBUG > 1
520 wxDebugMsg("wxMDIFrame::OnCommand %d: system command: calling default window proc\n", GetHWND());
521 #endif
522 return FALSE; // Get WndProc to call default proc
523 }
524
525 if (m_parentFrameActive && (id < wxFIRST_MDI_CHILD || id > wxLAST_MDI_CHILD))
526 {
527 ProcessCommand(id);
528 return TRUE;
529 }
530 else if (m_currentChild && (id < wxFIRST_MDI_CHILD || id > wxLAST_MDI_CHILD))
531 {
532 #if WXDEBUG > 1
533 wxDebugMsg("wxMDIFrame::MSWOnCommand %d: calling child OnCommand\n", GetHWND());
534 #endif
535 return m_currentChild->MSWOnCommand(id, cmd, control);
536 }
537 }
538 if (id >= wxFIRST_MDI_CHILD && id <= wxLAST_MDI_CHILD)
539 {
540 wxNode* node = GetChildren()->First();
541 while (node)
542 {
543 wxWindow* child = (wxWindow*) node->Data();
544 if (child->GetHWND())
545 {
546 #ifdef __WIN32__
547 long childId = GetWindowLong((HWND) child->GetHWND(), GWL_ID);
548 #else
549 long childId = GetWindowWord((HWND) child->GetHWND(), GWW_ID);
550 #endif
551 if (childId == id)
552 {
553 ::SendMessage( (HWND) GetClientWindow()->GetHWND(), WM_MDIACTIVATE, (WPARAM) (HWND) child->GetHWND(), 0);
554 return TRUE;
555 }
556 }
557 node = node->Next();
558 }
559 /*
560 wxWindow* child = FindItem(id);
561 if (child)
562 {
563 ::SendMessage( (HWND) GetClientWindow()->GetHWND(), WM_MDIACTIVATE, (WPARAM) (HWND) child->GetHWND(), 0);
564 return TRUE;
565 }
566 */
567 }
568
569 return FALSE;
570 }
571
572 void wxMDIParentFrame::MSWOnMenuHighlight(WXWORD nItem, WXWORD nFlags, WXHMENU hSysMenu)
573 {
574 if (m_parentFrameActive)
575 {
576 if (nFlags == 0xFFFF && hSysMenu == (WXHMENU) NULL)
577 {
578 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, -1);
579 event.SetEventObject( this );
580 GetEventHandler()->ProcessEvent(event);
581 }
582 else if (nFlags != MF_SEPARATOR)
583 {
584 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, nItem);
585 event.SetEventObject( this );
586 GetEventHandler()->ProcessEvent(event);
587 }
588 }
589 else if (m_currentChild)
590 {
591 m_currentChild->MSWOnMenuHighlight(nItem, nFlags, hSysMenu);
592 }
593 }
594
595 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
596 {
597 WXHWND clientWnd;
598 if ( GetClientWindow() )
599 clientWnd = GetClientWindow()->GetHWND();
600 else
601 clientWnd = 0;
602
603 return DefFrameProc((HWND) GetHWND(), (HWND) clientWnd, message, wParam, lParam);
604 }
605
606 bool wxMDIParentFrame::MSWProcessMessage(WXMSG* msg)
607 {
608 MSG *pMsg = (MSG *)msg;
609
610 if ((m_currentChild != (wxWindow *)NULL) && (m_currentChild->GetHWND() != (WXHWND) NULL) && m_currentChild->MSWProcessMessage(msg))
611 return TRUE;
612
613 return FALSE;
614 }
615
616 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG* msg)
617 {
618 MSG *pMsg = (MSG *)msg;
619
620 if ((m_currentChild != (wxWindow *)NULL) && (m_currentChild->GetHWND() != (WXHWND) NULL) && m_currentChild->MSWTranslateMessage(msg))
621 return TRUE;
622
623 if (m_acceleratorTable.Ok() &&
624 ::TranslateAccelerator((HWND) GetHWND(), (HACCEL) m_acceleratorTable.GetHACCEL(), pMsg))
625 return TRUE;
626
627 if (pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN)
628 {
629 if (::TranslateMDISysAccel((HWND) GetClientWindow()->GetHWND(), pMsg))
630 return TRUE;
631 }
632
633 return FALSE;
634 }
635
636
637 bool wxMDIParentFrame::MSWOnEraseBkgnd(WXHDC WXUNUSED(pDC))
638 {
639 return TRUE;
640 }
641
642 extern wxWindow *wxWndHook;
643 extern wxList *wxWinHandleList;
644
645 wxMDIChildFrame::wxMDIChildFrame(void)
646 {
647 // m_active = FALSE;
648 }
649
650 bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
651 wxWindowID id,
652 const wxString& title,
653 const wxPoint& pos,
654 const wxSize& size,
655 long style,
656 const wxString& name)
657 {
658 m_defaultIcon = (WXHICON) (wxSTD_MDICHILDFRAME_ICON ? wxSTD_MDICHILDFRAME_ICON : wxDEFAULT_MDICHILDFRAME_ICON);
659
660 SetName(name);
661
662 if ( id > -1 )
663 m_windowId = id;
664 else
665 m_windowId = (int)NewControlId();
666
667 if (parent) parent->AddChild(this);
668
669 wxWndHook = this;
670
671 int x = pos.x;
672 int y = pos.y;
673 int width = size.x;
674 int height = size.y;
675
676 MDICREATESTRUCT mcs;
677
678 mcs.szClass = wxMDIChildFrameClassName;
679 mcs.szTitle = title;
680 mcs.hOwner = wxGetInstance();
681 if (x > -1) mcs.x = x;
682 else mcs.x = CW_USEDEFAULT;
683
684 if (y > -1) mcs.y = y;
685 else mcs.y = CW_USEDEFAULT;
686
687 if (width > -1) mcs.cx = width;
688 else mcs.cx = CW_USEDEFAULT;
689
690 if (height > -1) mcs.cy = height;
691 else mcs.cy = CW_USEDEFAULT;
692
693 DWORD msflags = WS_OVERLAPPED | WS_CLIPCHILDREN ;
694 if (style & wxMINIMIZE_BOX)
695 msflags |= WS_MINIMIZEBOX;
696 if (style & wxMAXIMIZE_BOX)
697 msflags |= WS_MAXIMIZEBOX;
698 if (style & wxTHICK_FRAME)
699 msflags |= WS_THICKFRAME;
700 if (style & wxSYSTEM_MENU)
701 msflags |= WS_SYSMENU;
702 if ((style & wxMINIMIZE) || (style & wxICONIZE))
703 msflags |= WS_MINIMIZE;
704 if (style & wxMAXIMIZE)
705 msflags |= WS_MAXIMIZE;
706 if (style & wxCAPTION)
707 msflags |= WS_CAPTION;
708
709 mcs.style = msflags;
710
711 mcs.lParam = 0;
712
713 DWORD Return = SendMessage((HWND) parent->GetClientWindow()->GetHWND(),
714 WM_MDICREATE, 0, (LONG)(LPSTR)&mcs);
715
716 //handle = (HWND)LOWORD(Return);
717 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
718 m_hWnd = (WXHWND)Return;
719
720 // This gets reassigned so can't be stored
721 // m_windowId = GetWindowLong((HWND) m_hWnd, GWL_ID);
722
723 wxWndHook = NULL;
724 wxWinHandleList->Append((long)GetHWND(), this);
725
726 SetWindowLong((HWND) GetHWND(), 0, (long)this);
727
728 wxModelessWindows.Append(this);
729 return TRUE;
730 }
731
732 wxMDIChildFrame::~wxMDIChildFrame(void)
733 {
734 MSWDestroyWindow();
735
736 ResetWindowStyle(NULL);
737 }
738
739 // Set the client size (i.e. leave the calculation of borders etc.
740 // to wxWindows)
741 void wxMDIChildFrame::SetClientSize(int width, int height)
742 {
743 HWND hWnd = (HWND) GetHWND();
744
745 RECT rect;
746 GetClientRect(hWnd, &rect);
747
748 RECT rect2;
749 GetWindowRect(hWnd, &rect2);
750
751 // Find the difference between the entire window (title bar and all)
752 // and the client area; add this to the new client size to move the
753 // window
754 int actual_width = rect2.right - rect2.left - rect.right + width;
755 int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
756
757 if (GetStatusBar())
758 {
759 int sx, sy;
760 GetStatusBar()->GetSize(&sx, &sy);
761 actual_height += sy;
762 }
763
764 POINT point;
765 point.x = rect2.left;
766 point.y = rect2.top;
767
768 // If there's an MDI parent, must subtract the parent's top left corner
769 // since MoveWindow moves relative to the parent
770 wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent();
771 ::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point);
772
773 MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE);
774
775 wxSizeEvent event(wxSize(width, height), m_windowId);
776 event.SetEventObject( this );
777 GetEventHandler()->ProcessEvent(event);
778 }
779
780 void wxMDIChildFrame::GetPosition(int *x, int *y) const
781 {
782 RECT rect;
783 GetWindowRect((HWND) GetHWND(), &rect);
784 POINT point;
785 point.x = rect.left;
786 point.y = rect.top;
787
788 // Since we now have the absolute screen coords,
789 // if there's a parent we must subtract its top left corner
790 wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent();
791 ::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point);
792
793 *x = point.x;
794 *y = point.y;
795 }
796
797 void wxMDIChildFrame::SetMenuBar(wxMenuBar *menu_bar)
798 {
799 if (!menu_bar)
800 {
801 m_frameMenuBar = NULL;
802 return;
803 }
804
805 if (menu_bar->m_menuBarFrame)
806 return;
807
808 int i;
809 HMENU menu = CreateMenu();
810
811 for (i = 0; i < menu_bar->m_menuCount; i ++)
812 {
813 HMENU popup = (HMENU)menu_bar->m_menus[i]->m_hMenu;
814 //
815 // After looking Bounds Checker result, it seems that all
816 // menus must be individually destroyed. So, don't reset m_hMenu,
817 // to allow ~wxMenu to do the job.
818 //
819 menu_bar->m_menus[i]->m_savehMenu = (WXHMENU) popup;
820 // Uncommenting for the moment... JACS
821 menu_bar->m_menus[i]->m_hMenu = 0;
822 ::AppendMenu((HMENU) menu, MF_POPUP | MF_STRING, (UINT)popup, menu_bar->m_titles[i]);
823 }
824
825 menu_bar->m_hMenu = (WXHMENU)menu;
826 if (m_frameMenuBar)
827 delete m_frameMenuBar;
828
829 this->m_hMenu = (WXHMENU) menu;
830
831 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
832
833 parent->m_parentFrameActive = FALSE;
834 HMENU subMenu = GetSubMenu((HMENU) parent->GetWindowMenu(), 0);
835
836 // Try to insert Window menu in front of Help, otherwise append it.
837 int N = GetMenuItemCount(menu);
838 bool success = FALSE;
839 for (i = 0; i < N; i++)
840 {
841 char buf[100];
842 int chars = GetMenuString(menu, i, buf, 100, MF_BYPOSITION);
843 if ((chars > 0) && (strcmp(buf, "&Help") == 0 ||
844 strcmp(buf, "Help") == 0))
845 {
846 success = TRUE;
847 InsertMenu(menu, i, MF_BYPOSITION | MF_POPUP | MF_STRING,
848 (UINT)subMenu, "&Window");
849 break;
850 }
851 }
852 if (!success)
853 AppendMenu(menu, MF_POPUP,
854 (UINT)subMenu,
855 "&Window");
856 #ifdef __WIN32__
857 SendMessage((HWND) parent->GetClientWindow()->GetHWND(), WM_MDISETMENU,
858 (WPARAM)menu,
859 (LPARAM)subMenu);
860 #else
861 SendMessage((HWND) parent->GetClientWindow()->GetHWND(), WM_MDISETMENU, 0,
862 MAKELPARAM(menu, subMenu));
863 #endif
864
865 DrawMenuBar((HWND) parent->GetHWND());
866 m_frameMenuBar = menu_bar;
867 menu_bar->m_menuBarFrame = this;
868 }
869
870 // MDI operations
871 void wxMDIChildFrame::Maximize(void)
872 {
873 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
874 if ( parent && parent->GetClientWindow() )
875 ::SendMessage( (HWND) parent->GetClientWindow()->GetHWND(), WM_MDIMAXIMIZE, (WPARAM) (HWND) GetHWND(), 0);
876 }
877
878 void wxMDIChildFrame::Restore(void)
879 {
880 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
881 if ( parent && parent->GetClientWindow() )
882 ::SendMessage( (HWND) parent->GetClientWindow()->GetHWND(), WM_MDIRESTORE, (WPARAM) (HWND) GetHWND(), 0);
883 }
884
885 void wxMDIChildFrame::Activate(void)
886 {
887 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
888 if ( parent && parent->GetClientWindow() )
889 ::SendMessage( (HWND) parent->GetClientWindow()->GetHWND(), WM_MDIACTIVATE, (WPARAM) (HWND) GetHWND(), 0);
890 }
891
892 static HWND invalidHandle = 0;
893 void wxMDIChildFrame::MSWOnSize(int x, int y, WXUINT id)
894 {
895 if (!GetHWND()) return;
896
897 if (invalidHandle == (HWND) GetHWND())
898 {
899 #if WXDEBUG > 1
900 wxDebugMsg("wxMDIChildFrame::OnSize %d: invalid, so returning.\n", GetHWND());
901 #endif
902 return;
903 }
904
905 (void)MSWDefWindowProc(m_lastMsg, m_lastWParam, m_lastLParam);
906
907 switch (id)
908 {
909 case SIZEFULLSCREEN:
910 case SIZENORMAL:
911 m_iconized = FALSE;
912 break;
913 case SIZEICONIC:
914 m_iconized = TRUE;
915 break;
916 }
917
918 if (!m_iconized)
919 {
920 // forward WM_SIZE to status bar control
921 #if USE_NATIVE_STATUSBAR
922 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
923 {
924 wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId());
925 event.SetEventObject( m_frameStatusBar );
926
927 ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
928 }
929 #endif
930
931 PositionStatusBar();
932 PositionToolBar();
933
934 wxWindow::MSWOnSize(x, y, id);
935 }
936 }
937
938 bool wxMDIChildFrame::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control)
939 {
940 #if WXDEBUG > 1
941 wxDebugMsg("wxMDIChildFrame::MSWOnCommand %d\n", GetHWND());
942 #endif
943 // if ((cmd == 0) && GetHWND())
944 if (GetHWND())
945 {
946 // In case it's e.g. a toolbar.
947 wxWindow *win = wxFindWinFromHandle(control);
948 if (win)
949 return win->MSWCommand(cmd, id);
950
951 if (wxCurrentPopupMenu)
952 {
953 wxMenu *popupMenu = wxCurrentPopupMenu;
954 wxCurrentPopupMenu = NULL;
955 if (popupMenu->MSWCommand(cmd, id))
956 return TRUE;
957 }
958
959 if (GetMenuBar() && GetMenuBar()->FindItemForId(id))
960 {
961 ProcessCommand(id);
962 return TRUE;
963 }
964 else
965 return FALSE;
966 return TRUE;
967 }
968 else
969 return FALSE;
970 }
971
972 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message, WXUINT wParam, WXLPARAM lParam)
973 {
974 if (GetHWND())
975 return DefMDIChildProc((HWND) GetHWND(), (UINT) message, (WPARAM) wParam, (LPARAM) lParam);
976 else return 0;
977 }
978
979 bool wxMDIChildFrame::MSWProcessMessage(WXMSG *msg)
980 {
981 return FALSE;
982 }
983
984 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG* msg)
985 {
986 MSG *pMsg = (MSG *)msg;
987 if (m_acceleratorTable.Ok())
988 {
989 wxFrame *parent = (wxFrame *)GetParent();
990 HWND parent_hwnd = (HWND) parent->GetHWND();
991 return (::TranslateAccelerator(parent_hwnd, (HACCEL) m_acceleratorTable.GetHACCEL(), pMsg) != 0);
992 }
993
994 return FALSE;
995 }
996
997 long wxMDIChildFrame::MSWOnMDIActivate(long activate, WXHWND WXUNUSED(one), WXHWND WXUNUSED(two))
998 {
999 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
1000 HMENU parent_menu = (HMENU) parent->GetWinMenu();
1001 #if WXDEBUG > 1
1002 wxDebugMsg("Parent menu is %d\n", parent_menu);
1003 #endif
1004 HMENU child_menu = (HMENU) GetWinMenu();
1005 #if WXDEBUG > 1
1006 wxDebugMsg("Child menu is %d\n", child_menu);
1007 #endif
1008
1009 if (activate)
1010 {
1011 // m_active = TRUE;
1012 parent->m_currentChild = this;
1013 if (child_menu)
1014 {
1015 parent->m_parentFrameActive = FALSE;
1016 HMENU subMenu = GetSubMenu((HMENU) parent->GetWindowMenu(), 0);
1017 #if WXDEBUG > 1
1018 wxDebugMsg("Window submenu is %d\n", subMenu);
1019 #endif
1020 // HMENU subMenu = 0;
1021 #ifdef __WIN32__
1022 ::SendMessage((HWND) parent->GetClientWindow()->GetHWND(), WM_MDISETMENU,
1023 (WPARAM)child_menu,
1024 (LPARAM)subMenu);
1025 #else
1026 ::SendMessage((HWND) parent->GetClientWindow()->GetHWND(), WM_MDISETMENU, 0,
1027 MAKELONG(child_menu, subMenu));
1028 #endif
1029
1030 ::DrawMenuBar((HWND) parent->GetHWND());
1031 }
1032 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId);
1033 event.SetEventObject( this );
1034 GetEventHandler()->ProcessEvent(event);
1035 }
1036 else
1037 {
1038 if (parent->m_currentChild == this)
1039 parent->m_currentChild = NULL;
1040
1041 wxActivateEvent event(wxEVT_ACTIVATE, FALSE, m_windowId);
1042 event.SetEventObject( this );
1043 GetEventHandler()->ProcessEvent(event);
1044
1045 // m_active = FALSE;
1046 if (parent_menu)
1047 {
1048 parent->m_parentFrameActive = TRUE;
1049 HMENU subMenu = GetSubMenu((HMENU) parent->GetWindowMenu(), 0);
1050 #if WXDEBUG > 1
1051 wxDebugMsg("Window submenu is %d\n", subMenu);
1052 #endif
1053 // HMENU subMenu = 0;
1054 #ifdef __WIN32__
1055 ::SendMessage((HWND) parent->GetClientWindow()->GetHWND(), WM_MDISETMENU,
1056 (WPARAM)parent_menu,
1057 (LPARAM)subMenu);
1058 #else
1059 ::SendMessage((HWND) parent->GetClientWindow()->GetHWND(), WM_MDISETMENU, 0,
1060 MAKELONG(parent_menu, subMenu));
1061 #endif
1062
1063 ::DrawMenuBar((HWND) parent->GetHWND());
1064 }
1065 }
1066 bool flag = (activate != 0);
1067 wxActivateEvent event(wxEVT_ACTIVATE, flag, m_windowId);
1068 event.SetEventObject( this );
1069 GetEventHandler()->ProcessEvent(event);
1070
1071 #if WXDEBUG > 1
1072 wxDebugMsg("Finished (de)activating\n");
1073 #endif
1074 return 0;
1075 }
1076
1077 void wxMDIChildFrame::MSWDestroyWindow(void)
1078 {
1079 MSWDetachWindowMenu();
1080 invalidHandle = (HWND) GetHWND();
1081
1082 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
1083
1084 // Must make sure this handle is invalidated (set to NULL)
1085 // since all sorts of things could happen after the
1086 // child client is destroyed, but before the wxFrame is
1087 // destroyed.
1088
1089 HWND oldHandle = (HWND)GetHWND();
1090 #if WXDEBUG > 1
1091 wxDebugMsg("*** About to DestroyWindow MDI child %d\n", oldHandle);
1092 #endif
1093 #ifdef __WIN32__
1094 SendMessage((HWND) parent->GetClientWindow()->GetHWND(), WM_MDIDESTROY, (WPARAM)oldHandle, (LPARAM)0);
1095 #else
1096 SendMessage((HWND) parent->GetClientWindow()->GetHWND(), WM_MDIDESTROY, (HWND)oldHandle, 0);
1097 #endif
1098 #if WXDEBUG > 1
1099 wxDebugMsg("*** Finished DestroyWindow MDI child %d\n", oldHandle);
1100 #endif
1101 invalidHandle = 0;
1102
1103 if (m_hMenu)
1104 {
1105 ::DestroyMenu((HMENU) m_hMenu);
1106 m_hMenu = 0;
1107 }
1108 m_hWnd = 0;
1109 }
1110
1111 // Change the client window's extended style so we don't
1112 // get a client edge style when a child is maximised (a double
1113 // border looks silly.)
1114 bool wxMDIChildFrame::ResetWindowStyle(void *vrect)
1115 {
1116 #if defined(__WIN95__)
1117 RECT *rect = (RECT *)vrect;
1118 wxMDIParentFrame* pFrameWnd = (wxMDIParentFrame *)GetParent();
1119 wxMDIChildFrame* pChild = pFrameWnd->GetActiveChild();
1120 if (!pChild || (pChild == this))
1121 {
1122 DWORD dwStyle = ::GetWindowLong((HWND) pFrameWnd->GetClientWindow()->GetHWND(), GWL_EXSTYLE);
1123 DWORD dwThisStyle = ::GetWindowLong((HWND) GetHWND(), GWL_STYLE);
1124 DWORD dwNewStyle = dwStyle;
1125 if (pChild != NULL && (dwThisStyle & WS_MAXIMIZE))
1126 dwNewStyle &= ~(WS_EX_CLIENTEDGE);
1127 else
1128 dwNewStyle |= WS_EX_CLIENTEDGE;
1129
1130 if (dwStyle != dwNewStyle)
1131 {
1132 ::RedrawWindow((HWND) pFrameWnd->GetClientWindow()->GetHWND(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN);
1133 ::SetWindowLong((HWND) pFrameWnd->GetClientWindow()->GetHWND(), GWL_EXSTYLE, dwNewStyle);
1134 ::SetWindowPos((HWND) pFrameWnd->GetClientWindow()->GetHWND(), NULL, 0, 0, 0, 0,
1135 SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOCOPYBITS);
1136 if (rect)
1137 ::GetClientRect((HWND) pFrameWnd->GetClientWindow()->GetHWND(), rect);
1138 return TRUE;
1139 }
1140 }
1141 return FALSE;
1142 #else
1143 return FALSE;
1144 #endif
1145 }
1146
1147 void wxMDIChildFrame::MSWOnWindowPosChanging(void *pos)
1148 {
1149 WINDOWPOS *lpPos = (WINDOWPOS *)pos;
1150 #if defined(__WIN95__)
1151 if (!(lpPos->flags & SWP_NOSIZE))
1152 {
1153 RECT rectClient;
1154 DWORD dwExStyle = ::GetWindowLong((HWND) GetHWND(), GWL_EXSTYLE);
1155 DWORD dwStyle = ::GetWindowLong((HWND) GetHWND(), GWL_STYLE);
1156 if (ResetWindowStyle((void *) & rectClient) && (dwStyle & WS_MAXIMIZE))
1157 {
1158 ::AdjustWindowRectEx(&rectClient, dwStyle, FALSE, dwExStyle);
1159 lpPos->x = rectClient.left;
1160 lpPos->y = rectClient.top;
1161 lpPos->cx = rectClient.right - rectClient.left;
1162 lpPos->cy = rectClient.bottom - rectClient.top;
1163 }
1164 wxMDIParentFrame* pFrameWnd = (wxMDIParentFrame *)GetParent();
1165 if (pFrameWnd && pFrameWnd->GetToolBar())
1166 {
1167 pFrameWnd->GetToolBar()->Refresh();
1168 }
1169 }
1170 #endif
1171 Default();
1172 }
1173
1174 // Client window
1175 wxMDIClientWindow::wxMDIClientWindow(void)
1176 {
1177 m_scrollX = 0;
1178 m_scrollY = 0;
1179 }
1180
1181 wxMDIClientWindow::~wxMDIClientWindow(void)
1182 {
1183 }
1184
1185 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style)
1186 {
1187 m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE);
1188
1189 CLIENTCREATESTRUCT ccs;
1190 m_windowStyle = style;
1191 m_windowParent = parent;
1192
1193 ccs.hWindowMenu = (HMENU) parent->GetWindowMenu();
1194 ccs.idFirstChild = wxFIRST_MDI_CHILD;
1195
1196 DWORD msStyle = WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN ;
1197 if ( parent->GetWindowStyleFlag() & wxHSCROLL )
1198 msStyle |= WS_HSCROLL;
1199 if ( parent->GetWindowStyleFlag() & wxVSCROLL )
1200 msStyle |= WS_VSCROLL ;
1201
1202 #if defined(__WIN95__)
1203 DWORD exStyle = WS_EX_CLIENTEDGE;
1204 #else
1205 DWORD exStyle = 0;
1206 #endif
1207
1208 wxWndHook = this;
1209 m_hWnd = (WXHWND) ::CreateWindowEx(exStyle, "mdiclient", NULL,
1210 msStyle, 0, 0, 0, 0, (HWND) parent->GetHWND(), NULL,
1211 wxGetInstance(), (LPSTR)(LPCLIENTCREATESTRUCT)&ccs);
1212 SubclassWin(m_hWnd);
1213 wxWndHook = NULL;
1214
1215 return (m_hWnd != 0) ;
1216 }
1217
1218 // Window procedure: here for debugging purposes
1219 long wxMDIClientWindow::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
1220 {
1221 return wxWindow::MSWWindowProc(nMsg, wParam, lParam);
1222 // return MSWDefWindowProc(nMsg, wParam, lParam);
1223 }
1224
1225 long wxMDIClientWindow::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
1226 {
1227 if ( MSWGetOldWndProc() != 0)
1228 return ::CallWindowProc(CASTWNDPROC MSWGetOldWndProc(), (HWND) GetHWND(), (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam);
1229 else
1230 return ::DefWindowProc((HWND) m_hWnd, (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam);
1231 }
1232
1233 // Explicitly call default scroll behaviour
1234 void wxMDIClientWindow::OnScroll(wxScrollEvent& event)
1235 {
1236 // Note: for client windows, the scroll position is not set in
1237 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1238 // scroll position we're at.
1239 // This makes it hard to paint patterns or bitmaps in the background,
1240 // and have the client area scrollable as well.
1241
1242 if ( event.GetOrientation() == wxHORIZONTAL )
1243 m_scrollX = event.GetPosition(); // Always returns zero!
1244 else
1245 m_scrollY = event.GetPosition(); // Always returns zero!
1246
1247 Default();
1248 }
1249
1250 // Should hand the message to the default proc
1251 long wxMDIClientWindow::MSWOnMDIActivate(long bActivate, WXHWND, WXHWND)
1252 {
1253 return Default();
1254 }
1255