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 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
396 ChangeBackgroundColour();
398 XtManageChild((Widget
) m_mainWidget
);
402 clientWindow
->AddPage(this, title
, TRUE
);
403 clientWindow
->Refresh();
405 // Positions the toolbar and status bar -- but we don't have any.
408 wxModelessWindows
.Append(this);
413 wxMDIChildFrame::~wxMDIChildFrame()
416 XtRemoveEventHandler((Widget
) m_mainWidget
, ExposureMask
,FALSE
,
417 wxUniversalRepaintProc
, (XtPointer
) this);
419 if (GetMDIParentFrame())
421 wxMDIParentFrame
* parentFrame
= GetMDIParentFrame();
423 if (parentFrame
->GetActiveChild() == this)
424 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
425 wxMDIClientWindow
* clientWindow
= parentFrame
->GetClientWindow();
427 // Remove page if still there
429 int i
= clientWindow
->FindPage(this);
433 clientWindow
->RemovePage(i
);
434 clientWindow
->Refresh();
438 // Set the selection to the first remaining page
439 if (clientWindow
->GetPageCount() > 0)
441 wxMDIChildFrame
* child
= (wxMDIChildFrame
*) clientWindow
->GetPage(0);
442 parentFrame
->SetActiveChild(child
);
443 parentFrame
->SetChildMenuBar(child
);
447 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
448 parentFrame
->SetChildMenuBar((wxMDIChildFrame
*) NULL
);
454 // Implementation: intercept and act upon raise and lower commands.
455 void wxMDIChildFrame::OnRaise()
457 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
458 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
459 parentFrame
->SetActiveChild(this);
463 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
464 event
.SetEventObject( oldActiveChild
);
465 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
468 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, this->GetId());
469 event
.SetEventObject( this );
470 this->GetEventHandler()->ProcessEvent(event
);
473 void wxMDIChildFrame::OnLower()
475 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
476 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
478 if (oldActiveChild
== this)
480 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
481 event
.SetEventObject( oldActiveChild
);
482 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
484 // TODO: unfortunately we don't now know which is the top-most child,
485 // so make the active child NULL.
486 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
490 // Set the client size (i.e. leave the calculation of borders etc.
492 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
494 wxWindow::DoSetClientSize(width
, height
);
497 void wxMDIChildFrame::DoGetClientSize(int* width
, int* height
) const
499 wxWindow::DoGetSize(width
, height
);
502 void wxMDIChildFrame::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
504 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
507 void wxMDIChildFrame::DoGetSize(int* width
, int* height
) const
509 wxWindow::DoGetSize(width
, height
);
512 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
514 wxWindow::DoGetPosition(x
, y
);
517 bool wxMDIChildFrame::Show(bool show
)
519 SetVisibleStatus( show
);
520 return wxWindow::Show(show
);
523 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menuBar
)
525 // Don't create the underlying menubar yet; need to recreate
526 // it every time the child is activated.
527 m_frameMenuBar
= menuBar
;
529 // We make the assumption that if you're setting the menubar,
530 // this is the currently active child.
531 GetMDIParentFrame()->SetChildMenuBar(this);
535 void wxMDIChildFrame::SetIcon(const wxIcon
& icon
)
537 m_icons
= wxIconBundle( icon
);
541 // Not appropriate since there are no icons in
546 void wxMDIChildFrame::SetIcons(const wxIconBundle
& icons
)
551 void wxMDIChildFrame::SetTitle(const wxString
& title
)
553 wxTopLevelWindow::SetTitle( title
);
554 wxMDIClientWindow
* clientWindow
= GetMDIParentFrame()->GetClientWindow();
556 // Remove page if still there
558 int i
= clientWindow
->FindPage(this);
561 clientWindow
->SetPageText(i
, title
);
566 void wxMDIChildFrame::Maximize()
571 void wxMDIChildFrame::Iconize(bool WXUNUSED(iconize
))
576 bool wxMDIChildFrame::IsIconized() const
581 // Is it maximized? Always maximized under Motif, using the
582 // tabbed MDI implementation.
583 bool wxMDIChildFrame::IsMaximized(void) const
588 void wxMDIChildFrame::Restore()
593 void wxMDIChildFrame::Activate()
598 void wxMDIChildFrame::CaptureMouse()
600 wxWindow::CaptureMouse();
603 void wxMDIChildFrame::ReleaseMouse()
605 wxWindow::ReleaseMouse();
608 void wxMDIChildFrame::Raise()
613 void wxMDIChildFrame::Lower(void)
618 void wxMDIChildFrame::SetSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
), int WXUNUSED(maxW
), int WXUNUSED(maxH
), int WXUNUSED(incW
), int WXUNUSED(incH
))
624 wxMDIClientWindow::wxMDIClientWindow()
628 wxMDIClientWindow::~wxMDIClientWindow()
630 // By the time this destructor is called, the child frames will have been
631 // deleted and removed from the notebook/client window.
634 m_mainWidget
= (WXWidget
) 0;
637 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
639 SetWindowStyleFlag(style
);
641 // m_windowParent = parent;
642 // m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
644 bool success
= wxNotebook::Create(parent
, wxID_NOTEBOOK_CLIENT_AREA
, wxPoint(0, 0), wxSize(100, 100), 0);
647 wxFont
font(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
655 int wxMDIClientWindow::FindPage(const wxNotebookPage
* page
)
657 for (int i
= GetPageCount() - 1; i
>= 0; --i
)
659 if (GetPage(i
) == page
)
666 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
668 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
671 void wxMDIClientWindow::DoSetClientSize(int width
, int height
)
673 wxWindow::DoSetClientSize(width
, height
);
676 void wxMDIClientWindow::DoGetClientSize(int *width
, int *height
) const
678 wxWindow::DoGetClientSize(width
, height
);
681 void wxMDIClientWindow::DoGetSize(int *width
, int *height
) const
683 wxWindow::DoGetSize(width
, height
);
686 void wxMDIClientWindow::DoGetPosition(int *x
, int *y
) const
688 wxWindow::DoGetPosition(x
, y
);
691 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
693 // Default(); // Default processing: OBSOLETE FUNCTION
697 void wxMDIClientWindow::OnPageChanged(wxNotebookEvent
& event
)
699 // Notify child that it has been activated
700 if (event
.GetOldSelection() != -1)
702 wxMDIChildFrame
* oldChild
= (wxMDIChildFrame
*) GetPage(event
.GetOldSelection());
705 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldChild
->GetId());
706 event
.SetEventObject( oldChild
);
707 oldChild
->GetEventHandler()->ProcessEvent(event
);
710 if (event
.GetSelection() != -1)
712 wxMDIChildFrame
* activeChild
= (wxMDIChildFrame
*) GetPage(event
.GetSelection());
715 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, activeChild
->GetId());
716 event
.SetEventObject( activeChild
);
717 activeChild
->GetEventHandler()->ProcessEvent(event
);
719 if (activeChild
->GetMDIParentFrame())
721 activeChild
->GetMDIParentFrame()->SetActiveChild(activeChild
);
722 activeChild
->GetMDIParentFrame()->SetChildMenuBar(activeChild
);