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
23 #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
430 int i
= clientWindow
->FindPage(this);
434 clientWindow
->RemovePage(i
);
435 clientWindow
->Refresh();
439 // Set the selection to the first remaining page
440 if (clientWindow
->GetPageCount() > 0)
442 wxMDIChildFrame
* child
= (wxMDIChildFrame
*) clientWindow
->GetPage(0);
443 parentFrame
->SetActiveChild(child
);
444 parentFrame
->SetChildMenuBar(child
);
448 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
449 parentFrame
->SetChildMenuBar((wxMDIChildFrame
*) NULL
);
455 // Implementation: intercept and act upon raise and lower commands.
456 void wxMDIChildFrame::OnRaise()
458 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
459 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
460 parentFrame
->SetActiveChild(this);
464 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
465 event
.SetEventObject( oldActiveChild
);
466 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
469 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, this->GetId());
470 event
.SetEventObject( this );
471 this->GetEventHandler()->ProcessEvent(event
);
474 void wxMDIChildFrame::OnLower()
476 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
477 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
479 if (oldActiveChild
== this)
481 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
482 event
.SetEventObject( oldActiveChild
);
483 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
485 // TODO: unfortunately we don't now know which is the top-most child,
486 // so make the active child NULL.
487 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
491 // Set the client size (i.e. leave the calculation of borders etc.
493 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
495 wxWindow::DoSetClientSize(width
, height
);
498 void wxMDIChildFrame::DoGetClientSize(int* width
, int* height
) const
500 wxWindow::DoGetSize(width
, height
);
503 void wxMDIChildFrame::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
505 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
508 void wxMDIChildFrame::DoGetSize(int* width
, int* height
) const
510 wxWindow::DoGetSize(width
, height
);
513 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
515 wxWindow::DoGetPosition(x
, y
);
518 bool wxMDIChildFrame::Show(bool show
)
520 SetVisibleStatus( show
);
521 return wxWindow::Show(show
);
524 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menuBar
)
526 // Don't create the underlying menubar yet; need to recreate
527 // it every time the child is activated.
528 m_frameMenuBar
= menuBar
;
530 // We make the assumption that if you're setting the menubar,
531 // this is the currently active child.
532 GetMDIParentFrame()->SetChildMenuBar(this);
536 void wxMDIChildFrame::SetIcon(const wxIcon
& icon
)
538 m_icons
= wxIconBundle( icon
);
542 // Not appropriate since there are no icons in
547 void wxMDIChildFrame::SetIcons(const wxIconBundle
& icons
)
552 void wxMDIChildFrame::SetTitle(const wxString
& title
)
554 wxTopLevelWindow::SetTitle( title
);
555 wxMDIClientWindow
* clientWindow
= GetMDIParentFrame()->GetClientWindow();
557 // Remove page if still there
559 int i
= clientWindow
->FindPage(this);
562 clientWindow
->SetPageText(i
, title
);
567 void wxMDIChildFrame::Maximize()
572 void wxMDIChildFrame::Iconize(bool WXUNUSED(iconize
))
577 bool wxMDIChildFrame::IsIconized() const
582 // Is it maximized? Always maximized under Motif, using the
583 // tabbed MDI implementation.
584 bool wxMDIChildFrame::IsMaximized(void) const
589 void wxMDIChildFrame::Restore()
594 void wxMDIChildFrame::Activate()
599 void wxMDIChildFrame::CaptureMouse()
601 wxWindow::CaptureMouse();
604 void wxMDIChildFrame::ReleaseMouse()
606 wxWindow::ReleaseMouse();
609 void wxMDIChildFrame::Raise()
614 void wxMDIChildFrame::Lower(void)
619 void wxMDIChildFrame::SetSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
), int WXUNUSED(maxW
), int WXUNUSED(maxH
), int WXUNUSED(incW
), int WXUNUSED(incH
))
625 wxMDIClientWindow::wxMDIClientWindow()
629 wxMDIClientWindow::~wxMDIClientWindow()
631 // By the time this destructor is called, the child frames will have been
632 // deleted and removed from the notebook/client window.
635 m_mainWidget
= (WXWidget
) 0;
638 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
640 SetWindowStyleFlag(style
);
642 // m_windowParent = parent;
643 // m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
645 bool success
= wxNotebook::Create(parent
, wxID_NOTEBOOK_CLIENT_AREA
, wxPoint(0, 0), wxSize(100, 100), 0);
648 wxFont
font(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
656 int wxMDIClientWindow::FindPage(const wxNotebookPage
* page
)
658 for (int i
= GetPageCount() - 1; i
>= 0; --i
)
660 if (GetPage(i
) == page
)
667 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
669 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
672 void wxMDIClientWindow::DoSetClientSize(int width
, int height
)
674 wxWindow::DoSetClientSize(width
, height
);
677 void wxMDIClientWindow::DoGetClientSize(int *width
, int *height
) const
679 wxWindow::DoGetClientSize(width
, height
);
682 void wxMDIClientWindow::DoGetSize(int *width
, int *height
) const
684 wxWindow::DoGetSize(width
, height
);
687 void wxMDIClientWindow::DoGetPosition(int *x
, int *y
) const
689 wxWindow::DoGetPosition(x
, y
);
692 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
694 // Default(); // Default processing: OBSOLETE FUNCTION
698 void wxMDIClientWindow::OnPageChanged(wxNotebookEvent
& event
)
700 // Notify child that it has been activated
701 if (event
.GetOldSelection() != -1)
703 wxMDIChildFrame
* oldChild
= (wxMDIChildFrame
*) GetPage(event
.GetOldSelection());
706 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldChild
->GetId());
707 event
.SetEventObject( oldChild
);
708 oldChild
->GetEventHandler()->ProcessEvent(event
);
711 if (event
.GetSelection() != -1)
713 wxMDIChildFrame
* activeChild
= (wxMDIChildFrame
*) GetPage(event
.GetSelection());
716 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, activeChild
->GetId());
717 event
.SetEventObject( activeChild
);
718 activeChild
->GetEventHandler()->ProcessEvent(event
);
720 if (activeChild
->GetMDIParentFrame())
722 activeChild
->GetMDIParentFrame()->SetActiveChild(activeChild
);
723 activeChild
->GetMDIParentFrame()->SetChildMenuBar(activeChild
);