1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: MDI classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "mdi.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
20 #define XtDisplay XTDISPLAY
21 #define XtWindow XTWINDOW
26 #include "wx/settings.h"
30 #pragma message disable nosimpint
33 #include <Xm/BulletinB.h>
36 #include <Xm/RowColumn.h>
37 #include <Xm/CascadeBG.h>
39 #include <Xm/PushBG.h>
40 #include <Xm/AtomMgr.h>
41 #include <Xm/Protocols.h>
43 #pragma message enable nosimpint
46 #include "wx/motif/private.h"
48 extern wxList wxModelessWindows
;
50 // Implemented in frame.cpp
51 extern void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
52 XmAnyCallbackStruct
*cbs
);
54 #define wxID_NOTEBOOK_CLIENT_AREA wxID_HIGHEST + 100
56 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
57 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
58 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxNotebook
)
60 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
61 EVT_SIZE(wxMDIParentFrame::OnSize
)
62 EVT_ACTIVATE(wxMDIParentFrame::OnActivate
)
63 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
64 EVT_MENU_HIGHLIGHT_ALL(wxMDIParentFrame::OnMenuHighlight
)
67 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxNotebook
)
68 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
69 EVT_NOTEBOOK_PAGE_CHANGED(wxID_NOTEBOOK_CLIENT_AREA
, wxMDIClientWindow::OnPageChanged
)
75 wxMDIParentFrame::wxMDIParentFrame()
77 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
78 m_activeChild
= (wxMDIChildFrame
*) NULL
;
79 m_activeMenuBar
= (wxMenuBar
*) NULL
;
82 bool wxMDIParentFrame::Create(wxWindow
*parent
,
84 const wxString
& title
,
90 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
91 m_activeChild
= (wxMDIChildFrame
*) NULL
;
92 m_activeMenuBar
= (wxMenuBar
*) NULL
;
94 bool success
= wxFrame::Create(parent
, id
, title
, pos
, size
, style
, name
);
97 // TODO: app cannot override OnCreateClient since
98 // wxMDIParentFrame::OnCreateClient will still be called
99 // (we're in the constructor). How to resolve?
101 m_clientWindow
= OnCreateClient();
103 // Uses own style for client style
104 m_clientWindow
->CreateClient(this, GetWindowStyleFlag());
107 GetClientSize(& w
, & h
);
108 m_clientWindow
->SetSize(0, 0, w
, h
);
115 wxMDIParentFrame::~wxMDIParentFrame()
117 // Make sure we delete the client window last of all
118 RemoveChild(m_clientWindow
);
122 delete m_clientWindow
;
123 m_clientWindow
= NULL
;
126 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
128 m_frameMenuBar
= menu_bar
;
130 SetChildMenuBar((wxMDIChildFrame
*) NULL
);
133 void wxMDIParentFrame::OnSize(wxSizeEvent
& WXUNUSED(event
))
135 #if wxUSE_CONSTRAINTS
142 GetClientSize(&width
, &height
);
144 if ( GetClientWindow() )
145 GetClientWindow()->SetSize(x
, y
, width
, height
);
148 void wxMDIParentFrame::DoGetClientSize(int *width
, int *height
) const
150 wxFrame::DoGetClientSize(width
, height
);
153 void wxMDIParentFrame::OnActivate(wxActivateEvent
& WXUNUSED(event
))
158 // Returns the active MDI child window
159 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
161 return m_activeChild
;
164 // Create the client window class (don't Create the window,
165 // just return a new class)
166 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
168 return new wxMDIClientWindow
;
171 // Set the child's menu into the parent frame
172 void wxMDIParentFrame::SetChildMenuBar(wxMDIChildFrame
* child
)
174 wxMenuBar
* oldMenuBar
= m_activeMenuBar
;
176 if (child
== (wxMDIChildFrame
*) NULL
) // No child: use parent frame
178 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar
))
180 // if (m_activeMenuBar)
181 // m_activeMenuBar->DestroyMenuBar();
183 m_activeMenuBar
= GetMenuBar();
184 m_activeMenuBar
->CreateMenuBar(this);
186 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
187 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
189 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
190 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
194 else if (child
->GetMenuBar() == (wxMenuBar
*) NULL
) // No child menu bar: use parent frame
196 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar
))
198 // if (m_activeMenuBar)
199 // m_activeMenuBar->DestroyMenuBar();
200 m_activeMenuBar
= GetMenuBar();
201 m_activeMenuBar
->CreateMenuBar(this);
203 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
204 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
206 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
207 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
210 else // The child has a menubar
212 if (child
->GetMenuBar() != m_activeMenuBar
)
214 // if (m_activeMenuBar)
215 // m_activeMenuBar->DestroyMenuBar();
217 m_activeMenuBar
= child
->GetMenuBar();
218 m_activeMenuBar
->CreateMenuBar(this);
220 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
221 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
223 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
224 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
229 // Redirect events to active child first
230 bool wxMDIParentFrame::ProcessEvent(wxEvent
& event
)
232 // Stops the same event being processed repeatedly
233 static wxEventType inEvent
= wxEVT_NULL
;
234 if (inEvent
== event
.GetEventType())
237 inEvent
= event
.GetEventType();
240 if (m_activeChild
&& event
.IsKindOf(CLASSINFO(wxCommandEvent
)))
242 res
= m_activeChild
->GetEventHandler()->ProcessEvent(event
);
246 res
= GetEventHandler()->wxEvtHandler::ProcessEvent(event
);
248 inEvent
= wxEVT_NULL
;
253 void wxMDIParentFrame::DoSetSize(int x
, int y
,
254 int width
, int height
,
257 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
260 void wxMDIParentFrame::DoSetClientSize(int width
, int height
)
262 wxWindow::DoSetClientSize(width
, height
);
265 // Responds to colour changes, and passes event on to children.
266 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
270 // Propagate the event to the non-top-level children
271 wxFrame::OnSysColourChanged(event
);
275 void wxMDIParentFrame::Cascade()
280 void wxMDIParentFrame::Tile()
285 void wxMDIParentFrame::ArrangeIcons()
290 void wxMDIParentFrame::ActivateNext()
295 void wxMDIParentFrame::ActivatePrevious()
300 // Default menu selection behaviour - display a help string
301 void wxMDIParentFrame::OnMenuHighlight(wxMenuEvent
& event
)
305 if (event
.GetMenuId() == -1)
309 wxMenuBar
*menuBar
= (wxMenuBar
*) NULL
;
310 if (GetActiveChild())
311 menuBar
= GetActiveChild()->GetMenuBar();
313 menuBar
= GetMenuBar();
316 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
317 if (helpString
!= "")
318 SetStatusText(helpString
);
326 wxMDIChildFrame::wxMDIChildFrame()
328 m_mdiParentFrame
= (wxMDIParentFrame
*) NULL
;
331 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
333 const wxString
& title
,
337 const wxString
& name
)
340 SetWindowStyleFlag(style
);
342 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
343 m_foregroundColour
= *wxBLACK
;
344 m_font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
349 m_windowId
= (int)NewControlId();
351 wxMDIClientWindow
* clientWindow
= parent
->GetClientWindow();
353 wxASSERT_MSG( (clientWindow
!= (wxWindow
*) NULL
), "Missing MDI client window.");
355 if (clientWindow
) clientWindow
->AddChild(this);
357 SetMDIParentFrame(parent
);
362 width
= 200; // TODO: give reasonable default
364 height
= 200; // TODO: give reasonable default
366 // We're deactivating the old child
367 wxMDIChildFrame
* oldActiveChild
= parent
->GetActiveChild();
370 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
371 event
.SetEventObject( oldActiveChild
);
372 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
375 // This is the currently active child
376 parent
->SetActiveChild((wxMDIChildFrame
*) this);
378 // This time we'll try a bog-standard bulletin board for
379 // the 'frame'. A main window doesn't seem to work.
381 m_mainWidget
= (WXWidget
) XtVaCreateWidget("client",
382 xmBulletinBoardWidgetClass
, (Widget
) clientWindow
->GetTopWidget(),
386 XmNrightAttachment, XmATTACH_FORM,
387 XmNleftAttachment, XmATTACH_FORM,
388 XmNtopAttachment, XmATTACH_FORM,
389 XmNbottomAttachment, XmATTACH_FORM,
391 XmNresizePolicy
, XmRESIZE_NONE
,
394 XtAddEventHandler((Widget
) m_mainWidget
, ExposureMask
,FALSE
,
395 wxUniversalRepaintProc
, (XtPointer
) this);
397 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
399 ChangeBackgroundColour();
401 XtManageChild((Widget
) m_mainWidget
);
405 clientWindow
->AddPage(this, title
, TRUE
);
406 clientWindow
->Refresh();
408 // Positions the toolbar and status bar -- but we don't have any.
411 wxModelessWindows
.Append(this);
416 wxMDIChildFrame::~wxMDIChildFrame()
419 XtRemoveEventHandler((Widget
) m_mainWidget
, ExposureMask
,FALSE
,
420 wxUniversalRepaintProc
, (XtPointer
) this);
422 if (GetMDIParentFrame())
424 wxMDIParentFrame
* parentFrame
= GetMDIParentFrame();
426 if (parentFrame
->GetActiveChild() == this)
427 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
428 wxMDIClientWindow
* clientWindow
= parentFrame
->GetClientWindow();
430 // Remove page if still there
432 int i
= clientWindow
->FindPage(this);
436 clientWindow
->RemovePage(i
);
437 clientWindow
->Refresh();
441 // Set the selection to the first remaining page
442 if (clientWindow
->GetPageCount() > 0)
444 wxMDIChildFrame
* child
= (wxMDIChildFrame
*) clientWindow
->GetPage(0);
445 parentFrame
->SetActiveChild(child
);
446 parentFrame
->SetChildMenuBar(child
);
450 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
451 parentFrame
->SetChildMenuBar((wxMDIChildFrame
*) NULL
);
457 // Implementation: intercept and act upon raise and lower commands.
458 void wxMDIChildFrame::OnRaise()
460 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
461 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
462 parentFrame
->SetActiveChild(this);
466 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
467 event
.SetEventObject( oldActiveChild
);
468 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
471 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, this->GetId());
472 event
.SetEventObject( this );
473 this->GetEventHandler()->ProcessEvent(event
);
476 void wxMDIChildFrame::OnLower()
478 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
479 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
481 if (oldActiveChild
== this)
483 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
484 event
.SetEventObject( oldActiveChild
);
485 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
487 // TODO: unfortunately we don't now know which is the top-most child,
488 // so make the active child NULL.
489 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
493 // Set the client size (i.e. leave the calculation of borders etc.
495 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
497 wxWindow::DoSetClientSize(width
, height
);
500 void wxMDIChildFrame::DoGetClientSize(int* width
, int* height
) const
502 wxWindow::DoGetSize(width
, height
);
505 void wxMDIChildFrame::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
507 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
510 void wxMDIChildFrame::DoGetSize(int* width
, int* height
) const
512 wxWindow::DoGetSize(width
, height
);
515 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
517 wxWindow::DoGetPosition(x
, y
);
520 bool wxMDIChildFrame::Show(bool show
)
522 SetVisibleStatus( show
);
523 return wxWindow::Show(show
);
526 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menuBar
)
528 // Don't create the underlying menubar yet; need to recreate
529 // it every time the child is activated.
530 m_frameMenuBar
= menuBar
;
532 // We make the assumption that if you're setting the menubar,
533 // this is the currently active child.
534 GetMDIParentFrame()->SetChildMenuBar(this);
538 void wxMDIChildFrame::SetIcon(const wxIcon
& icon
)
540 m_icons
= wxIconBundle( icon
);
544 // Not appropriate since there are no icons in
549 void wxMDIChildFrame::SetIcons(const wxIconBundle
& icons
)
554 void wxMDIChildFrame::SetTitle(const wxString
& title
)
556 wxTopLevelWindow::SetTitle( title
);
557 wxMDIClientWindow
* clientWindow
= GetMDIParentFrame()->GetClientWindow();
559 // Remove page if still there
561 int i
= clientWindow
->FindPage(this);
564 clientWindow
->SetPageText(i
, title
);
569 void wxMDIChildFrame::Maximize()
574 void wxMDIChildFrame::Iconize(bool WXUNUSED(iconize
))
579 bool wxMDIChildFrame::IsIconized() const
584 // Is it maximized? Always maximized under Motif, using the
585 // tabbed MDI implementation.
586 bool wxMDIChildFrame::IsMaximized(void) const
591 void wxMDIChildFrame::Restore()
596 void wxMDIChildFrame::Activate()
601 void wxMDIChildFrame::CaptureMouse()
603 wxWindow::CaptureMouse();
606 void wxMDIChildFrame::ReleaseMouse()
608 wxWindow::ReleaseMouse();
611 void wxMDIChildFrame::Raise()
616 void wxMDIChildFrame::Lower(void)
621 void wxMDIChildFrame::DoSetSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
), int WXUNUSED(maxW
), int WXUNUSED(maxH
), int WXUNUSED(incW
), int WXUNUSED(incH
))
627 wxMDIClientWindow::wxMDIClientWindow()
631 wxMDIClientWindow::~wxMDIClientWindow()
633 // By the time this destructor is called, the child frames will have been
634 // deleted and removed from the notebook/client window.
637 m_mainWidget
= (WXWidget
) 0;
640 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
642 SetWindowStyleFlag(style
);
644 // m_windowParent = parent;
645 // m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
647 bool success
= wxNotebook::Create(parent
, wxID_NOTEBOOK_CLIENT_AREA
, wxPoint(0, 0), wxSize(100, 100), 0);
650 wxFont
font(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
658 int wxMDIClientWindow::FindPage(const wxNotebookPage
* page
)
660 for (int i
= GetPageCount() - 1; i
>= 0; --i
)
662 if (GetPage(i
) == page
)
669 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
671 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
674 void wxMDIClientWindow::DoSetClientSize(int width
, int height
)
676 wxWindow::DoSetClientSize(width
, height
);
679 void wxMDIClientWindow::DoGetClientSize(int *width
, int *height
) const
681 wxWindow::DoGetClientSize(width
, height
);
684 void wxMDIClientWindow::DoGetSize(int *width
, int *height
) const
686 wxWindow::DoGetSize(width
, height
);
689 void wxMDIClientWindow::DoGetPosition(int *x
, int *y
) const
691 wxWindow::DoGetPosition(x
, y
);
694 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
696 // Default(); // Default processing: OBSOLETE FUNCTION
700 void wxMDIClientWindow::OnPageChanged(wxNotebookEvent
& event
)
702 // Notify child that it has been activated
703 if (event
.GetOldSelection() != -1)
705 wxMDIChildFrame
* oldChild
= (wxMDIChildFrame
*) GetPage(event
.GetOldSelection());
708 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldChild
->GetId());
709 event
.SetEventObject( oldChild
);
710 oldChild
->GetEventHandler()->ProcessEvent(event
);
713 if (event
.GetSelection() != -1)
715 wxMDIChildFrame
* activeChild
= (wxMDIChildFrame
*) GetPage(event
.GetSelection());
718 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, activeChild
->GetId());
719 event
.SetEventObject( activeChild
);
720 activeChild
->GetEventHandler()->ProcessEvent(event
);
722 if (activeChild
->GetMDIParentFrame())
724 activeChild
->GetMDIParentFrame()->SetActiveChild(activeChild
);
725 activeChild
->GetMDIParentFrame()->SetChildMenuBar(activeChild
);