1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: MDI classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "mdi.h"
18 #include "wx/settings.h"
21 #include <Xm/BulletinB.h>
24 #include <Xm/RowColumn.h>
25 #include <Xm/CascadeBG.h>
27 #include <Xm/PushBG.h>
28 #include <Xm/AtomMgr.h>
29 #include <Xm/Protocols.h>
31 #include "wx/motif/private.h"
33 extern wxList wxModelessWindows
;
35 // Implemented in frame.cpp
36 extern void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
37 XmAnyCallbackStruct
*cbs
);
39 #define wxID_NOTEBOOK_CLIENT_AREA wxID_HIGHEST + 100
41 #if !USE_SHARED_LIBRARY
42 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
43 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
44 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxNotebook
)
46 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
47 EVT_SIZE(wxMDIParentFrame::OnSize
)
48 EVT_ACTIVATE(wxMDIParentFrame::OnActivate
)
49 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
50 EVT_MENU_HIGHLIGHT_ALL(wxMDIParentFrame::OnMenuHighlight
)
53 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxNotebook
)
54 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
55 EVT_NOTEBOOK_PAGE_CHANGED(wxID_NOTEBOOK_CLIENT_AREA
, wxMDIClientWindow::OnPageChanged
)
58 #endif // USE_SHARED_LIBRARY
62 wxMDIParentFrame::wxMDIParentFrame()
64 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
65 m_activeChild
= (wxMDIChildFrame
*) NULL
;
66 m_activeMenuBar
= (wxMenuBar
*) NULL
;
69 bool wxMDIParentFrame::Create(wxWindow
*parent
,
71 const wxString
& title
,
77 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
78 m_activeChild
= (wxMDIChildFrame
*) NULL
;
79 m_activeMenuBar
= (wxMenuBar
*) NULL
;
81 bool success
= wxFrame::Create(parent
, id
, title
, pos
, size
, style
, name
);
84 // TODO: app cannot override OnCreateClient since
85 // wxMDIParentFrame::OnCreateClient will still be called
86 // (we're in the constructor). How to resolve?
88 m_clientWindow
= OnCreateClient();
90 // Uses own style for client style
91 m_clientWindow
->CreateClient(this, GetWindowStyleFlag());
94 GetClientSize(& w
, & h
);
95 m_clientWindow
->SetSize(0, 0, w
, h
);
102 wxMDIParentFrame::~wxMDIParentFrame()
104 // Make sure we delete the client window last of all
105 RemoveChild(m_clientWindow
);
109 delete m_clientWindow
;
110 m_clientWindow
= NULL
;
113 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
115 m_frameMenuBar
= menu_bar
;
117 SetChildMenuBar((wxMDIChildFrame
*) NULL
);
120 void wxMDIParentFrame::OnSize(wxSizeEvent
& WXUNUSED(event
))
122 #if wxUSE_CONSTRAINTS
129 GetClientSize(&width
, &height
);
131 if ( GetClientWindow() )
132 GetClientWindow()->SetSize(x
, y
, width
, height
);
135 void wxMDIParentFrame::DoGetClientSize(int *width
, int *height
) const
137 wxFrame::DoGetClientSize(width
, height
);
140 void wxMDIParentFrame::OnActivate(wxActivateEvent
& WXUNUSED(event
))
145 // Returns the active MDI child window
146 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
148 return m_activeChild
;
151 // Create the client window class (don't Create the window,
152 // just return a new class)
153 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
155 return new wxMDIClientWindow
;
158 // Set the child's menu into the parent frame
159 void wxMDIParentFrame::SetChildMenuBar(wxMDIChildFrame
* child
)
161 wxMenuBar
* oldMenuBar
= m_activeMenuBar
;
163 if (child
== (wxMDIChildFrame
*) NULL
) // No child: use parent frame
165 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar
))
167 // if (m_activeMenuBar)
168 // m_activeMenuBar->DestroyMenuBar();
170 m_activeMenuBar
= GetMenuBar();
171 m_activeMenuBar
->CreateMenuBar(this);
173 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
174 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
176 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
177 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
181 else if (child
->GetMenuBar() == (wxMenuBar
*) NULL
) // No child menu bar: use parent frame
183 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar
))
185 // if (m_activeMenuBar)
186 // m_activeMenuBar->DestroyMenuBar();
187 m_activeMenuBar
= GetMenuBar();
188 m_activeMenuBar
->CreateMenuBar(this);
190 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
191 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
193 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
194 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
197 else // The child has a menubar
199 if (child
->GetMenuBar() != m_activeMenuBar
)
201 // if (m_activeMenuBar)
202 // m_activeMenuBar->DestroyMenuBar();
204 m_activeMenuBar
= child
->GetMenuBar();
205 m_activeMenuBar
->CreateMenuBar(this);
207 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
208 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
210 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
211 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
216 // Redirect events to active child first
217 bool wxMDIParentFrame::ProcessEvent(wxEvent
& event
)
219 // Stops the same event being processed repeatedly
220 static wxEventType inEvent
= wxEVT_NULL
;
221 if (inEvent
== event
.GetEventType())
224 inEvent
= event
.GetEventType();
227 if (m_activeChild
&& event
.IsKindOf(CLASSINFO(wxCommandEvent
)))
229 res
= m_activeChild
->GetEventHandler()->ProcessEvent(event
);
233 res
= GetEventHandler()->wxEvtHandler::ProcessEvent(event
);
235 inEvent
= wxEVT_NULL
;
240 void wxMDIParentFrame::DoSetSize(int x
, int y
,
241 int width
, int height
,
244 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
247 void wxMDIParentFrame::DoSetClientSize(int width
, int height
)
249 wxWindow::DoSetClientSize(width
, height
);
252 // Responds to colour changes, and passes event on to children.
253 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
257 // Propagate the event to the non-top-level children
258 wxFrame::OnSysColourChanged(event
);
262 void wxMDIParentFrame::Cascade()
267 void wxMDIParentFrame::Tile()
272 void wxMDIParentFrame::ArrangeIcons()
277 void wxMDIParentFrame::ActivateNext()
282 void wxMDIParentFrame::ActivatePrevious()
287 // Default menu selection behaviour - display a help string
288 void wxMDIParentFrame::OnMenuHighlight(wxMenuEvent
& event
)
292 if (event
.GetMenuId() == -1)
296 wxMenuBar
*menuBar
= (wxMenuBar
*) NULL
;
297 if (GetActiveChild())
298 menuBar
= GetActiveChild()->GetMenuBar();
300 menuBar
= GetMenuBar();
303 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
304 if (helpString
!= "")
305 SetStatusText(helpString
);
313 wxMDIChildFrame::wxMDIChildFrame()
315 m_mdiParentFrame
= (wxMDIParentFrame
*) NULL
;
318 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
320 const wxString
& title
,
324 const wxString
& name
)
327 SetWindowStyleFlag(style
);
329 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
330 m_foregroundColour
= *wxBLACK
;
331 m_font
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
336 m_windowId
= (int)NewControlId();
338 wxMDIClientWindow
* clientWindow
= parent
->GetClientWindow();
340 wxASSERT_MSG( (clientWindow
!= (wxWindow
*) NULL
), "Missing MDI client window.");
342 if (clientWindow
) clientWindow
->AddChild(this);
344 SetMDIParentFrame(parent
);
349 width
= 200; // TODO: give reasonable default
351 height
= 200; // TODO: give reasonable default
353 // We're deactivating the old child
354 wxMDIChildFrame
* oldActiveChild
= parent
->GetActiveChild();
357 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
358 event
.SetEventObject( oldActiveChild
);
359 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
362 // This is the currently active child
363 parent
->SetActiveChild((wxMDIChildFrame
*) this);
365 // This time we'll try a bog-standard bulletin board for
366 // the 'frame'. A main window doesn't seem to work.
368 m_mainWidget
= (WXWidget
) XtVaCreateWidget("client",
369 xmBulletinBoardWidgetClass
, (Widget
) clientWindow
->GetTopWidget(),
373 XmNrightAttachment, XmATTACH_FORM,
374 XmNleftAttachment, XmATTACH_FORM,
375 XmNtopAttachment, XmATTACH_FORM,
376 XmNbottomAttachment, XmATTACH_FORM,
378 XmNresizePolicy
, XmRESIZE_NONE
,
381 XtAddEventHandler((Widget
) m_mainWidget
, ExposureMask
,FALSE
,
382 wxUniversalRepaintProc
, (XtPointer
) this);
384 SetCanAddEventHandler(TRUE
);
385 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
387 ChangeBackgroundColour();
389 XtManageChild((Widget
) m_mainWidget
);
393 clientWindow
->AddPage(this, title
, TRUE
);
394 clientWindow
->Refresh();
396 // Positions the toolbar and status bar -- but we don't have any.
399 wxModelessWindows
.Append(this);
404 wxMDIChildFrame::~wxMDIChildFrame()
407 XtRemoveEventHandler((Widget
) m_mainWidget
, ExposureMask
,FALSE
,
408 wxUniversalRepaintProc
, (XtPointer
) this);
410 if (GetMDIParentFrame())
412 wxMDIParentFrame
* parentFrame
= GetMDIParentFrame();
414 if (parentFrame
->GetActiveChild() == this)
415 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
416 wxMDIClientWindow
* clientWindow
= parentFrame
->GetClientWindow();
418 // Remove page if still there
419 if (clientWindow
->RemovePage(this))
420 clientWindow
->Refresh();
422 // Set the selection to the first remaining page
423 if (clientWindow
->GetPageCount() > 0)
425 wxMDIChildFrame
* child
= (wxMDIChildFrame
*) clientWindow
->GetPage(0);
426 parentFrame
->SetActiveChild(child
);
427 parentFrame
->SetChildMenuBar(child
);
431 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
432 parentFrame
->SetChildMenuBar((wxMDIChildFrame
*) NULL
);
438 // Implementation: intercept and act upon raise and lower commands.
439 void wxMDIChildFrame::OnRaise()
441 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
442 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
443 parentFrame
->SetActiveChild(this);
447 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
448 event
.SetEventObject( oldActiveChild
);
449 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
452 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, this->GetId());
453 event
.SetEventObject( this );
454 this->GetEventHandler()->ProcessEvent(event
);
457 void wxMDIChildFrame::OnLower()
459 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
460 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
462 if (oldActiveChild
== this)
464 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
465 event
.SetEventObject( oldActiveChild
);
466 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
468 // TODO: unfortunately we don't now know which is the top-most child,
469 // so make the active child NULL.
470 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
474 // Set the client size (i.e. leave the calculation of borders etc.
476 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
478 wxWindow::DoSetClientSize(width
, height
);
481 void wxMDIChildFrame::DoGetClientSize(int* width
, int* height
) const
483 wxWindow::DoGetSize(width
, height
);
486 void wxMDIChildFrame::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
488 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
491 void wxMDIChildFrame::DoGetSize(int* width
, int* height
) const
493 wxWindow::DoGetSize(width
, height
);
496 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
498 wxWindow::DoGetPosition(x
, y
);
501 bool wxMDIChildFrame::Show(bool show
)
503 m_visibleStatus
= show
; /* show-&-hide fix */
504 return wxWindow::Show(show
);
507 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menuBar
)
509 // Don't create the underlying menubar yet; need to recreate
510 // it every time the child is activated.
511 m_frameMenuBar
= menuBar
;
513 // We make the assumption that if you're setting the menubar,
514 // this is the currently active child.
515 GetMDIParentFrame()->SetChildMenuBar(this);
519 void wxMDIChildFrame::SetIcon(const wxIcon
& icon
)
524 // Not appropriate since there are no icons in
529 void wxMDIChildFrame::SetTitle(const wxString
& title
)
532 wxMDIClientWindow
* clientWindow
= GetMDIParentFrame()->GetClientWindow();
533 int pageNo
= clientWindow
->FindPagePosition(this);
535 clientWindow
->SetPageText(pageNo
, title
);
539 void wxMDIChildFrame::Maximize()
544 void wxMDIChildFrame::Iconize(bool WXUNUSED(iconize
))
549 bool wxMDIChildFrame::IsIconized() const
554 // Is it maximized? Always maximized under Motif, using the
555 // tabbed MDI implementation.
556 bool wxMDIChildFrame::IsMaximized(void) const
561 void wxMDIChildFrame::Restore()
566 void wxMDIChildFrame::Activate()
571 void wxMDIChildFrame::CaptureMouse()
573 wxWindow::CaptureMouse();
576 void wxMDIChildFrame::ReleaseMouse()
578 wxWindow::ReleaseMouse();
581 void wxMDIChildFrame::Raise()
586 void wxMDIChildFrame::Lower(void)
591 void wxMDIChildFrame::SetSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
), int WXUNUSED(maxW
), int WXUNUSED(maxH
), int WXUNUSED(incW
), int WXUNUSED(incH
))
597 wxMDIClientWindow::wxMDIClientWindow()
601 wxMDIClientWindow::~wxMDIClientWindow()
603 // By the time this destructor is called, the child frames will have been
604 // deleted and removed from the notebook/client window.
607 m_mainWidget
= (WXWidget
) 0;
610 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
612 SetWindowStyleFlag(style
);
614 // m_windowParent = parent;
615 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE);
617 bool success
= wxNotebook::Create(parent
, wxID_NOTEBOOK_CLIENT_AREA
, wxPoint(0, 0), wxSize(100, 100), 0);
620 wxFont
font(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
621 wxFont
selFont(10, wxSWISS
, wxNORMAL
, wxBOLD
);
622 GetTabView()->SetTabFont(font
);
623 GetTabView()->SetSelectedTabFont(selFont
);
624 GetTabView()->SetTabSize(120, 18);
625 GetTabView()->SetTabSelectionHeight(20);
632 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
634 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
637 void wxMDIClientWindow::DoSetClientSize(int width
, int height
)
639 wxWindow::DoSetClientSize(width
, height
);
642 void wxMDIClientWindow::DoGetClientSize(int *width
, int *height
) const
644 wxWindow::DoGetClientSize(width
, height
);
647 void wxMDIClientWindow::DoGetSize(int *width
, int *height
) const
649 wxWindow::DoGetSize(width
, height
);
652 void wxMDIClientWindow::DoGetPosition(int *x
, int *y
) const
654 wxWindow::DoGetPosition(x
, y
);
657 // Explicitly call default scroll behaviour
658 void wxMDIClientWindow::OnScroll(wxScrollEvent
& WXUNUSED(event
))
660 Default(); // Default processing
663 void wxMDIClientWindow::OnPageChanged(wxNotebookEvent
& event
)
665 // Notify child that it has been activated
666 if (event
.GetOldSelection() != -1)
668 wxMDIChildFrame
* oldChild
= (wxMDIChildFrame
*) GetPage(event
.GetOldSelection());
671 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldChild
->GetId());
672 event
.SetEventObject( oldChild
);
673 oldChild
->GetEventHandler()->ProcessEvent(event
);
676 if (event
.GetSelection() != -1)
678 wxMDIChildFrame
* activeChild
= (wxMDIChildFrame
*) GetPage(event
.GetSelection());
681 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, activeChild
->GetId());
682 event
.SetEventObject( activeChild
);
683 activeChild
->GetEventHandler()->ProcessEvent(event
);
685 if (activeChild
->GetMDIParentFrame())
687 activeChild
->GetMDIParentFrame()->SetActiveChild(activeChild
);
688 activeChild
->GetMDIParentFrame()->SetChildMenuBar(activeChild
);