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
)
52 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxNotebook
)
53 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
54 EVT_NOTEBOOK_PAGE_CHANGED(wxID_NOTEBOOK_CLIENT_AREA
, wxMDIClientWindow::OnPageChanged
)
57 #endif // USE_SHARED_LIBRARY
61 wxMDIParentFrame::wxMDIParentFrame()
63 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
64 m_activeChild
= (wxMDIChildFrame
*) NULL
;
65 m_activeMenuBar
= (wxMenuBar
*) NULL
;
68 bool wxMDIParentFrame::Create(wxWindow
*parent
,
70 const wxString
& title
,
76 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
77 m_activeChild
= (wxMDIChildFrame
*) NULL
;
78 m_activeMenuBar
= (wxMenuBar
*) NULL
;
80 bool success
= wxFrame::Create(parent
, id
, title
, pos
, size
, style
, name
);
83 // TODO: app cannot override OnCreateClient since
84 // wxMDIParentFrame::OnCreateClient will still be called
85 // (we're in the constructor). How to resolve?
87 m_clientWindow
= OnCreateClient();
89 // Uses own style for client style
90 m_clientWindow
->CreateClient(this, GetWindowStyleFlag());
93 GetClientSize(& w
, & h
);
94 m_clientWindow
->SetSize(0, 0, w
, h
);
101 wxMDIParentFrame::~wxMDIParentFrame()
103 // Make sure we delete the client window last of all
104 RemoveChild(m_clientWindow
);
108 delete m_clientWindow
;
109 m_clientWindow
= NULL
;
112 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
114 m_frameMenuBar
= menu_bar
;
116 SetChildMenuBar((wxMDIChildFrame
*) NULL
);
119 void wxMDIParentFrame::OnSize(wxSizeEvent
& WXUNUSED(event
))
121 #if wxUSE_CONSTRAINTS
128 GetClientSize(&width
, &height
);
130 if ( GetClientWindow() )
131 GetClientWindow()->SetSize(x
, y
, width
, height
);
134 void wxMDIParentFrame::GetClientSize(int *width
, int *height
) const
136 wxFrame::GetClientSize(width
, height
);
139 void wxMDIParentFrame::OnActivate(wxActivateEvent
& WXUNUSED(event
))
144 // Returns the active MDI child window
145 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
147 return m_activeChild
;
150 // Create the client window class (don't Create the window,
151 // just return a new class)
152 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
154 return new wxMDIClientWindow
;
157 // Set the child's menu into the parent frame
158 void wxMDIParentFrame::SetChildMenuBar(wxMDIChildFrame
* child
)
160 wxMenuBar
* oldMenuBar
= m_activeMenuBar
;
162 if (child
== (wxMDIChildFrame
*) NULL
) // No child: use parent frame
164 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar
))
166 // if (m_activeMenuBar)
167 // m_activeMenuBar->DestroyMenuBar();
169 m_activeMenuBar
= GetMenuBar();
170 m_activeMenuBar
->CreateMenuBar(this);
172 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
173 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
175 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
176 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
180 else if (child
->GetMenuBar() == (wxMenuBar
*) NULL
) // No child menu bar: use parent frame
182 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar
))
184 // if (m_activeMenuBar)
185 // m_activeMenuBar->DestroyMenuBar();
186 m_activeMenuBar
= GetMenuBar();
187 m_activeMenuBar
->CreateMenuBar(this);
189 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
190 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
192 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
193 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
196 else // The child has a menubar
198 if (child
->GetMenuBar() != m_activeMenuBar
)
200 // if (m_activeMenuBar)
201 // m_activeMenuBar->DestroyMenuBar();
203 m_activeMenuBar
= child
->GetMenuBar();
204 m_activeMenuBar
->CreateMenuBar(this);
206 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
207 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
209 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
210 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
215 // Redirect events to active child first
216 bool wxMDIParentFrame::ProcessEvent(wxEvent
& event
)
218 // Stops the same event being processed repeatedly
219 static wxEventType inEvent
= wxEVT_NULL
;
220 if (inEvent
== event
.GetEventType())
223 inEvent
= event
.GetEventType();
226 if (m_activeChild
&& event
.IsKindOf(CLASSINFO(wxCommandEvent
)))
228 res
= m_activeChild
->GetEventHandler()->ProcessEvent(event
);
232 res
= GetEventHandler()->wxEvtHandler::ProcessEvent(event
);
234 inEvent
= wxEVT_NULL
;
239 void wxMDIParentFrame::DoSetSize(int x
, int y
,
240 int width
, int height
,
243 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
246 void wxMDIParentFrame::DoSetClientSize(int width
, int height
)
248 wxWindow::DoSetClientSize(width
, height
);
251 // Responds to colour changes, and passes event on to children.
252 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
256 // Propagate the event to the non-top-level children
257 wxFrame::OnSysColourChanged(event
);
261 void wxMDIParentFrame::Cascade()
266 void wxMDIParentFrame::Tile()
271 void wxMDIParentFrame::ArrangeIcons()
276 void wxMDIParentFrame::ActivateNext()
281 void wxMDIParentFrame::ActivatePrevious()
288 wxMDIChildFrame::wxMDIChildFrame()
290 m_mdiParentFrame
= (wxMDIParentFrame
*) NULL
;
293 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
295 const wxString
& title
,
299 const wxString
& name
)
302 SetWindowStyleFlag(style
);
304 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
305 m_foregroundColour
= *wxBLACK
;
306 m_font
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
311 m_windowId
= (int)NewControlId();
313 wxMDIClientWindow
* clientWindow
= parent
->GetClientWindow();
315 wxASSERT_MSG( (clientWindow
!= (wxWindow
*) NULL
), "Missing MDI client window.");
317 if (clientWindow
) clientWindow
->AddChild(this);
319 SetMDIParentFrame(parent
);
324 width
= 200; // TODO: give reasonable default
326 height
= 200; // TODO: give reasonable default
328 // We're deactivating the old child
329 wxMDIChildFrame
* oldActiveChild
= parent
->GetActiveChild();
332 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
333 event
.SetEventObject( oldActiveChild
);
334 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
337 // This is the currently active child
338 parent
->SetActiveChild((wxMDIChildFrame
*) this);
340 // This time we'll try a bog-standard bulletin board for
341 // the 'frame'. A main window doesn't seem to work.
343 m_mainWidget
= (WXWidget
) XtVaCreateWidget("client",
344 xmBulletinBoardWidgetClass
, (Widget
) clientWindow
->GetTopWidget(),
348 XmNrightAttachment, XmATTACH_FORM,
349 XmNleftAttachment, XmATTACH_FORM,
350 XmNtopAttachment, XmATTACH_FORM,
351 XmNbottomAttachment, XmATTACH_FORM,
353 XmNresizePolicy
, XmRESIZE_NONE
,
356 XtAddEventHandler((Widget
) m_mainWidget
, ExposureMask
,FALSE
,
357 wxUniversalRepaintProc
, (XtPointer
) this);
359 SetCanAddEventHandler(TRUE
);
360 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
362 ChangeBackgroundColour();
364 XtManageChild((Widget
) m_mainWidget
);
368 clientWindow
->AddPage(this, title
, TRUE
);
369 clientWindow
->Refresh();
371 // Positions the toolbar and status bar -- but we don't have any.
374 wxModelessWindows
.Append(this);
379 wxMDIChildFrame::~wxMDIChildFrame()
382 XtRemoveEventHandler((Widget
) m_mainWidget
, ExposureMask
,FALSE
,
383 wxUniversalRepaintProc
, (XtPointer
) this);
385 if (GetMDIParentFrame())
387 wxMDIParentFrame
* parentFrame
= GetMDIParentFrame();
389 if (parentFrame
->GetActiveChild() == this)
390 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
391 wxMDIClientWindow
* clientWindow
= parentFrame
->GetClientWindow();
393 // Remove page if still there
394 if (clientWindow
->RemovePage(this))
395 clientWindow
->Refresh();
397 // Set the selection to the first remaining page
398 if (clientWindow
->GetPageCount() > 0)
400 wxMDIChildFrame
* child
= (wxMDIChildFrame
*) clientWindow
->GetPage(0);
401 parentFrame
->SetActiveChild(child
);
402 parentFrame
->SetChildMenuBar(child
);
406 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
407 parentFrame
->SetChildMenuBar((wxMDIChildFrame
*) NULL
);
413 // Implementation: intercept and act upon raise and lower commands.
414 void wxMDIChildFrame::OnRaise()
416 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
417 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
418 parentFrame
->SetActiveChild(this);
422 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
423 event
.SetEventObject( oldActiveChild
);
424 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
427 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, this->GetId());
428 event
.SetEventObject( this );
429 this->GetEventHandler()->ProcessEvent(event
);
432 void wxMDIChildFrame::OnLower()
434 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
435 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
437 if (oldActiveChild
== this)
439 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
440 event
.SetEventObject( oldActiveChild
);
441 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
443 // TODO: unfortunately we don't now know which is the top-most child,
444 // so make the active child NULL.
445 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
449 // Set the client size (i.e. leave the calculation of borders etc.
451 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
453 wxWindow::DoSetClientSize(width
, height
);
456 void wxMDIChildFrame::GetClientSize(int* width
, int* height
) const
458 wxWindow::GetSize(width
, height
);
461 void wxMDIChildFrame::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
463 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
466 void wxMDIChildFrame::GetSize(int* width
, int* height
) const
468 wxWindow::GetSize(width
, height
);
471 void wxMDIChildFrame::GetPosition(int *x
, int *y
) const
473 wxWindow::GetPosition(x
, y
);
476 bool wxMDIChildFrame::Show(bool show
)
478 m_visibleStatus
= show
; /* show-&-hide fix */
479 return wxWindow::Show(show
);
482 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menuBar
)
484 // Don't create the underlying menubar yet; need to recreate
485 // it every time the child is activated.
486 m_frameMenuBar
= menuBar
;
488 // We make the assumption that if you're setting the menubar,
489 // this is the currently active child.
490 GetMDIParentFrame()->SetChildMenuBar(this);
494 void wxMDIChildFrame::SetIcon(const wxIcon
& icon
)
499 // Not appropriate since there are no icons in
504 void wxMDIChildFrame::SetTitle(const wxString
& title
)
507 wxMDIClientWindow
* clientWindow
= GetMDIParentFrame()->GetClientWindow();
508 int pageNo
= clientWindow
->FindPagePosition(this);
510 clientWindow
->SetPageText(pageNo
, title
);
514 void wxMDIChildFrame::Maximize()
519 void wxMDIChildFrame::Iconize(bool WXUNUSED(iconize
))
524 bool wxMDIChildFrame::IsIconized() const
529 // Is it maximized? Always maximized under Motif, using the
530 // tabbed MDI implementation.
531 bool wxMDIChildFrame::IsMaximized(void) const
536 void wxMDIChildFrame::Restore()
541 void wxMDIChildFrame::Activate()
546 void wxMDIChildFrame::CaptureMouse()
548 wxWindow::CaptureMouse();
551 void wxMDIChildFrame::ReleaseMouse()
553 wxWindow::ReleaseMouse();
556 void wxMDIChildFrame::Raise()
561 void wxMDIChildFrame::Lower(void)
566 void wxMDIChildFrame::SetSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
), int WXUNUSED(maxW
), int WXUNUSED(maxH
), int WXUNUSED(incW
), int WXUNUSED(incH
))
572 wxMDIClientWindow::wxMDIClientWindow()
576 wxMDIClientWindow::~wxMDIClientWindow()
578 // By the time this destructor is called, the child frames will have been
579 // deleted and removed from the notebook/client window.
582 m_mainWidget
= (WXWidget
) 0;
585 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
587 SetWindowStyleFlag(style
);
589 // m_windowParent = parent;
590 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE);
592 bool success
= wxNotebook::Create(parent
, wxID_NOTEBOOK_CLIENT_AREA
, wxPoint(0, 0), wxSize(100, 100), 0);
595 wxFont
font(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
596 wxFont
selFont(10, wxSWISS
, wxNORMAL
, wxBOLD
);
597 GetTabView()->SetTabFont(font
);
598 GetTabView()->SetSelectedTabFont(selFont
);
599 GetTabView()->SetTabSize(120, 18);
600 GetTabView()->SetTabSelectionHeight(20);
607 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
609 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
612 void wxMDIClientWindow::DoSetClientSize(int width
, int height
)
614 wxWindow::DoSetClientSize(width
, height
);
617 void wxMDIClientWindow::GetClientSize(int *width
, int *height
) const
619 wxWindow::GetClientSize(width
, height
);
622 void wxMDIClientWindow::GetSize(int *width
, int *height
) const
624 wxWindow::GetSize(width
, height
);
627 void wxMDIClientWindow::GetPosition(int *x
, int *y
) const
629 wxWindow::GetPosition(x
, y
);
632 // Explicitly call default scroll behaviour
633 void wxMDIClientWindow::OnScroll(wxScrollEvent
& WXUNUSED(event
))
635 Default(); // Default processing
638 void wxMDIClientWindow::OnPageChanged(wxNotebookEvent
& event
)
640 // Notify child that it has been activated
641 if (event
.GetOldSelection() != -1)
643 wxMDIChildFrame
* oldChild
= (wxMDIChildFrame
*) GetPage(event
.GetOldSelection());
646 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldChild
->GetId());
647 event
.SetEventObject( oldChild
);
648 oldChild
->GetEventHandler()->ProcessEvent(event
);
651 if (event
.GetSelection() != -1)
653 wxMDIChildFrame
* activeChild
= (wxMDIChildFrame
*) GetPage(event
.GetSelection());
656 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, activeChild
->GetId());
657 event
.SetEventObject( activeChild
);
658 activeChild
->GetEventHandler()->ProcessEvent(event
);
660 if (activeChild
->GetMDIParentFrame())
662 activeChild
->GetMDIParentFrame()->SetActiveChild(activeChild
);
663 activeChild
->GetMDIParentFrame()->SetChildMenuBar(activeChild
);