1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: MDI classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "mdi.h"
17 #define XtDisplay XTDISPLAY
18 #define XtWindow XTWINDOW
24 #include "wx/settings.h"
27 #pragma message disable nosimpint
30 #include <Xm/BulletinB.h>
33 #include <Xm/RowColumn.h>
34 #include <Xm/CascadeBG.h>
36 #include <Xm/PushBG.h>
37 #include <Xm/AtomMgr.h>
38 #include <Xm/Protocols.h>
40 #pragma message enable nosimpint
43 #include "wx/motif/private.h"
45 extern wxList wxModelessWindows
;
47 // Implemented in frame.cpp
48 extern void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
49 XmAnyCallbackStruct
*cbs
);
51 #define wxID_NOTEBOOK_CLIENT_AREA wxID_HIGHEST + 100
53 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
54 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
55 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxNotebook
)
57 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
58 EVT_SIZE(wxMDIParentFrame::OnSize
)
59 EVT_ACTIVATE(wxMDIParentFrame::OnActivate
)
60 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
61 EVT_MENU_HIGHLIGHT_ALL(wxMDIParentFrame::OnMenuHighlight
)
64 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxNotebook
)
65 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
66 EVT_NOTEBOOK_PAGE_CHANGED(wxID_NOTEBOOK_CLIENT_AREA
, wxMDIClientWindow::OnPageChanged
)
72 wxMDIParentFrame::wxMDIParentFrame()
74 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
75 m_activeChild
= (wxMDIChildFrame
*) NULL
;
76 m_activeMenuBar
= (wxMenuBar
*) NULL
;
79 bool wxMDIParentFrame::Create(wxWindow
*parent
,
81 const wxString
& title
,
87 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
88 m_activeChild
= (wxMDIChildFrame
*) NULL
;
89 m_activeMenuBar
= (wxMenuBar
*) NULL
;
91 bool success
= wxFrame::Create(parent
, id
, title
, pos
, size
, style
, name
);
94 // TODO: app cannot override OnCreateClient since
95 // wxMDIParentFrame::OnCreateClient will still be called
96 // (we're in the constructor). How to resolve?
98 m_clientWindow
= OnCreateClient();
100 // Uses own style for client style
101 m_clientWindow
->CreateClient(this, GetWindowStyleFlag());
104 GetClientSize(& w
, & h
);
105 m_clientWindow
->SetSize(0, 0, w
, h
);
112 wxMDIParentFrame::~wxMDIParentFrame()
114 // Make sure we delete the client window last of all
115 RemoveChild(m_clientWindow
);
119 delete m_clientWindow
;
120 m_clientWindow
= NULL
;
123 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
125 m_frameMenuBar
= menu_bar
;
127 SetChildMenuBar((wxMDIChildFrame
*) NULL
);
130 void wxMDIParentFrame::OnSize(wxSizeEvent
& WXUNUSED(event
))
132 #if wxUSE_CONSTRAINTS
139 GetClientSize(&width
, &height
);
141 if ( GetClientWindow() )
142 GetClientWindow()->SetSize(x
, y
, width
, height
);
145 void wxMDIParentFrame::DoGetClientSize(int *width
, int *height
) const
147 wxFrame::DoGetClientSize(width
, height
);
150 void wxMDIParentFrame::OnActivate(wxActivateEvent
& WXUNUSED(event
))
155 // Returns the active MDI child window
156 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
158 return m_activeChild
;
161 // Create the client window class (don't Create the window,
162 // just return a new class)
163 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
165 return new wxMDIClientWindow
;
168 // Set the child's menu into the parent frame
169 void wxMDIParentFrame::SetChildMenuBar(wxMDIChildFrame
* child
)
171 wxMenuBar
* oldMenuBar
= m_activeMenuBar
;
173 if (child
== (wxMDIChildFrame
*) NULL
) // No child: use parent frame
175 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar
))
177 // if (m_activeMenuBar)
178 // m_activeMenuBar->DestroyMenuBar();
180 m_activeMenuBar
= GetMenuBar();
181 m_activeMenuBar
->CreateMenuBar(this);
183 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
184 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
186 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
187 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
191 else if (child
->GetMenuBar() == (wxMenuBar
*) NULL
) // No child menu bar: use parent frame
193 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar
))
195 // if (m_activeMenuBar)
196 // m_activeMenuBar->DestroyMenuBar();
197 m_activeMenuBar
= GetMenuBar();
198 m_activeMenuBar
->CreateMenuBar(this);
200 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
201 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
203 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
204 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
207 else // The child has a menubar
209 if (child
->GetMenuBar() != m_activeMenuBar
)
211 // if (m_activeMenuBar)
212 // m_activeMenuBar->DestroyMenuBar();
214 m_activeMenuBar
= child
->GetMenuBar();
215 m_activeMenuBar
->CreateMenuBar(this);
217 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
218 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
220 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
221 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
226 // Redirect events to active child first
227 bool wxMDIParentFrame::ProcessEvent(wxEvent
& event
)
229 // Stops the same event being processed repeatedly
230 static wxEventType inEvent
= wxEVT_NULL
;
231 if (inEvent
== event
.GetEventType())
234 inEvent
= event
.GetEventType();
237 if (m_activeChild
&& event
.IsKindOf(CLASSINFO(wxCommandEvent
)))
239 res
= m_activeChild
->GetEventHandler()->ProcessEvent(event
);
243 res
= GetEventHandler()->wxEvtHandler::ProcessEvent(event
);
245 inEvent
= wxEVT_NULL
;
250 void wxMDIParentFrame::DoSetSize(int x
, int y
,
251 int width
, int height
,
254 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
257 void wxMDIParentFrame::DoSetClientSize(int width
, int height
)
259 wxWindow::DoSetClientSize(width
, height
);
262 // Responds to colour changes, and passes event on to children.
263 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
267 // Propagate the event to the non-top-level children
268 wxFrame::OnSysColourChanged(event
);
272 void wxMDIParentFrame::Cascade()
277 void wxMDIParentFrame::Tile()
282 void wxMDIParentFrame::ArrangeIcons()
287 void wxMDIParentFrame::ActivateNext()
292 void wxMDIParentFrame::ActivatePrevious()
297 // Default menu selection behaviour - display a help string
298 void wxMDIParentFrame::OnMenuHighlight(wxMenuEvent
& event
)
302 if (event
.GetMenuId() == -1)
306 wxMenuBar
*menuBar
= (wxMenuBar
*) NULL
;
307 if (GetActiveChild())
308 menuBar
= GetActiveChild()->GetMenuBar();
310 menuBar
= GetMenuBar();
313 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
314 if (helpString
!= "")
315 SetStatusText(helpString
);
323 wxMDIChildFrame::wxMDIChildFrame()
325 m_mdiParentFrame
= (wxMDIParentFrame
*) NULL
;
328 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
330 const wxString
& title
,
334 const wxString
& name
)
337 SetWindowStyleFlag(style
);
339 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
340 m_foregroundColour
= *wxBLACK
;
341 m_font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
346 m_windowId
= (int)NewControlId();
348 wxMDIClientWindow
* clientWindow
= parent
->GetClientWindow();
350 wxASSERT_MSG( (clientWindow
!= (wxWindow
*) NULL
), "Missing MDI client window.");
352 if (clientWindow
) clientWindow
->AddChild(this);
354 SetMDIParentFrame(parent
);
359 width
= 200; // TODO: give reasonable default
361 height
= 200; // TODO: give reasonable default
363 // We're deactivating the old child
364 wxMDIChildFrame
* oldActiveChild
= parent
->GetActiveChild();
367 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
368 event
.SetEventObject( oldActiveChild
);
369 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
372 // This is the currently active child
373 parent
->SetActiveChild((wxMDIChildFrame
*) this);
375 // This time we'll try a bog-standard bulletin board for
376 // the 'frame'. A main window doesn't seem to work.
378 m_mainWidget
= (WXWidget
) XtVaCreateWidget("client",
379 xmBulletinBoardWidgetClass
, (Widget
) clientWindow
->GetTopWidget(),
383 XmNrightAttachment, XmATTACH_FORM,
384 XmNleftAttachment, XmATTACH_FORM,
385 XmNtopAttachment, XmATTACH_FORM,
386 XmNbottomAttachment, XmATTACH_FORM,
388 XmNresizePolicy
, XmRESIZE_NONE
,
391 XtAddEventHandler((Widget
) m_mainWidget
, ExposureMask
,FALSE
,
392 wxUniversalRepaintProc
, (XtPointer
) this);
394 SetCanAddEventHandler(TRUE
);
395 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
397 ChangeBackgroundColour();
399 XtManageChild((Widget
) m_mainWidget
);
403 clientWindow
->AddPage(this, title
, TRUE
);
404 clientWindow
->Refresh();
406 // Positions the toolbar and status bar -- but we don't have any.
409 wxModelessWindows
.Append(this);
414 wxMDIChildFrame::~wxMDIChildFrame()
417 XtRemoveEventHandler((Widget
) m_mainWidget
, ExposureMask
,FALSE
,
418 wxUniversalRepaintProc
, (XtPointer
) this);
420 if (GetMDIParentFrame())
422 wxMDIParentFrame
* parentFrame
= GetMDIParentFrame();
424 if (parentFrame
->GetActiveChild() == this)
425 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
426 wxMDIClientWindow
* clientWindow
= parentFrame
->GetClientWindow();
428 // Remove page if still there
429 if (clientWindow
->RemovePage(this))
430 clientWindow
->Refresh();
432 // Set the selection to the first remaining page
433 if (clientWindow
->GetPageCount() > 0)
435 wxMDIChildFrame
* child
= (wxMDIChildFrame
*) clientWindow
->GetPage(0);
436 parentFrame
->SetActiveChild(child
);
437 parentFrame
->SetChildMenuBar(child
);
441 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
442 parentFrame
->SetChildMenuBar((wxMDIChildFrame
*) NULL
);
448 // Implementation: intercept and act upon raise and lower commands.
449 void wxMDIChildFrame::OnRaise()
451 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
452 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
453 parentFrame
->SetActiveChild(this);
457 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
458 event
.SetEventObject( oldActiveChild
);
459 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
462 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, this->GetId());
463 event
.SetEventObject( this );
464 this->GetEventHandler()->ProcessEvent(event
);
467 void wxMDIChildFrame::OnLower()
469 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
470 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
472 if (oldActiveChild
== this)
474 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
475 event
.SetEventObject( oldActiveChild
);
476 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
478 // TODO: unfortunately we don't now know which is the top-most child,
479 // so make the active child NULL.
480 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
484 // Set the client size (i.e. leave the calculation of borders etc.
486 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
488 wxWindow::DoSetClientSize(width
, height
);
491 void wxMDIChildFrame::DoGetClientSize(int* width
, int* height
) const
493 wxWindow::DoGetSize(width
, height
);
496 void wxMDIChildFrame::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
498 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
501 void wxMDIChildFrame::DoGetSize(int* width
, int* height
) const
503 wxWindow::DoGetSize(width
, height
);
506 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
508 wxWindow::DoGetPosition(x
, y
);
511 bool wxMDIChildFrame::Show(bool show
)
513 SetVisibleStatus( show
);
514 return wxWindow::Show(show
);
517 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menuBar
)
519 // Don't create the underlying menubar yet; need to recreate
520 // it every time the child is activated.
521 m_frameMenuBar
= menuBar
;
523 // We make the assumption that if you're setting the menubar,
524 // this is the currently active child.
525 GetMDIParentFrame()->SetChildMenuBar(this);
529 void wxMDIChildFrame::SetIcon(const wxIcon
& icon
)
531 m_icons
= wxIconBundle( icon
);
535 // Not appropriate since there are no icons in
540 void wxMDIChildFrame::SetIcons(const wxIconBundle
& icons
)
545 void wxMDIChildFrame::SetTitle(const wxString
& title
)
547 wxTopLevelWindow::SetTitle( title
);
548 wxMDIClientWindow
* clientWindow
= GetMDIParentFrame()->GetClientWindow();
549 int pageNo
= clientWindow
->FindPagePosition(this);
551 clientWindow
->SetPageText(pageNo
, title
);
555 void wxMDIChildFrame::Maximize()
560 void wxMDIChildFrame::Iconize(bool WXUNUSED(iconize
))
565 bool wxMDIChildFrame::IsIconized() const
570 // Is it maximized? Always maximized under Motif, using the
571 // tabbed MDI implementation.
572 bool wxMDIChildFrame::IsMaximized(void) const
577 void wxMDIChildFrame::Restore()
582 void wxMDIChildFrame::Activate()
587 void wxMDIChildFrame::CaptureMouse()
589 wxWindow::CaptureMouse();
592 void wxMDIChildFrame::ReleaseMouse()
594 wxWindow::ReleaseMouse();
597 void wxMDIChildFrame::Raise()
602 void wxMDIChildFrame::Lower(void)
607 void wxMDIChildFrame::SetSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
), int WXUNUSED(maxW
), int WXUNUSED(maxH
), int WXUNUSED(incW
), int WXUNUSED(incH
))
613 wxMDIClientWindow::wxMDIClientWindow()
617 wxMDIClientWindow::~wxMDIClientWindow()
619 // By the time this destructor is called, the child frames will have been
620 // deleted and removed from the notebook/client window.
623 m_mainWidget
= (WXWidget
) 0;
626 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
628 SetWindowStyleFlag(style
);
630 // m_windowParent = parent;
631 // m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
633 bool success
= wxNotebook::Create(parent
, wxID_NOTEBOOK_CLIENT_AREA
, wxPoint(0, 0), wxSize(100, 100), 0);
636 wxFont
font(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
637 wxFont
selFont(10, wxSWISS
, wxNORMAL
, wxBOLD
);
638 GetTabView()->SetTabFont(font
);
639 GetTabView()->SetSelectedTabFont(selFont
);
640 GetTabView()->SetTabSize(120, 18);
641 GetTabView()->SetTabSelectionHeight(20);
648 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
650 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
653 void wxMDIClientWindow::DoSetClientSize(int width
, int height
)
655 wxWindow::DoSetClientSize(width
, height
);
658 void wxMDIClientWindow::DoGetClientSize(int *width
, int *height
) const
660 wxWindow::DoGetClientSize(width
, height
);
663 void wxMDIClientWindow::DoGetSize(int *width
, int *height
) const
665 wxWindow::DoGetSize(width
, height
);
668 void wxMDIClientWindow::DoGetPosition(int *x
, int *y
) const
670 wxWindow::DoGetPosition(x
, y
);
673 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
675 // Default(); // Default processing: OBSOLETE FUNCTION
679 void wxMDIClientWindow::OnPageChanged(wxNotebookEvent
& event
)
681 // Notify child that it has been activated
682 if (event
.GetOldSelection() != -1)
684 wxMDIChildFrame
* oldChild
= (wxMDIChildFrame
*) GetPage(event
.GetOldSelection());
687 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldChild
->GetId());
688 event
.SetEventObject( oldChild
);
689 oldChild
->GetEventHandler()->ProcessEvent(event
);
692 if (event
.GetSelection() != -1)
694 wxMDIChildFrame
* activeChild
= (wxMDIChildFrame
*) GetPage(event
.GetSelection());
697 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, activeChild
->GetId());
698 event
.SetEventObject( activeChild
);
699 activeChild
->GetEventHandler()->ProcessEvent(event
);
701 if (activeChild
->GetMDIParentFrame())
703 activeChild
->GetMDIParentFrame()->SetActiveChild(activeChild
);
704 activeChild
->GetMDIParentFrame()->SetChildMenuBar(activeChild
);