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
& 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 wxWindow::GetClientSize(width
, height
);
139 void wxMDIParentFrame::OnActivate(wxActivateEvent
& 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
)
303 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
304 m_foregroundColour
= *wxBLACK
;
305 m_windowFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
310 m_windowId
= (int)NewControlId();
312 wxMDIClientWindow
* clientWindow
= parent
->GetClientWindow();
314 wxASSERT_MSG( (clientWindow
!= (wxWindow
*) NULL
), "Missing MDI client window.");
316 if (clientWindow
) clientWindow
->AddChild(this);
318 SetMDIParentFrame(parent
);
320 int x
= pos
.x
; int y
= pos
.y
;
321 int width
= size
.x
; int height
= size
.y
;
323 width
= 200; // TODO: give reasonable default
325 height
= 200; // TODO: give reasonable default
327 // We're deactivating the old child
328 wxMDIChildFrame
* oldActiveChild
= parent
->GetActiveChild();
331 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
332 event
.SetEventObject( oldActiveChild
);
333 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
336 // This is the currently active child
337 parent
->SetActiveChild((wxMDIChildFrame
*) this);
339 // This time we'll try a bog-standard bulletin board for
340 // the 'frame'. A main window doesn't seem to work.
342 m_mainWidget
= (WXWidget
) XtVaCreateWidget("client",
343 xmBulletinBoardWidgetClass
, (Widget
) clientWindow
->GetTopWidget(),
347 XmNrightAttachment, XmATTACH_FORM,
348 XmNleftAttachment, XmATTACH_FORM,
349 XmNtopAttachment, XmATTACH_FORM,
350 XmNbottomAttachment, XmATTACH_FORM,
352 XmNresizePolicy
, XmRESIZE_NONE
,
355 XtAddEventHandler((Widget
) m_mainWidget
, ExposureMask
,FALSE
,
356 wxUniversalRepaintProc
, (XtPointer
) this);
358 SetCanAddEventHandler(TRUE
);
359 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
361 ChangeBackgroundColour();
363 XtManageChild((Widget
) m_mainWidget
);
367 clientWindow
->AddPage(this, title
, TRUE
);
368 clientWindow
->Refresh();
370 // Positions the toolbar and status bar -- but we don't have any.
373 wxModelessWindows
.Append(this);
378 wxMDIChildFrame::~wxMDIChildFrame()
381 XtRemoveEventHandler((Widget
) m_mainWidget
, ExposureMask
,FALSE
,
382 wxUniversalRepaintProc
, (XtPointer
) this);
384 if (GetMDIParentFrame())
386 wxMDIParentFrame
* parentFrame
= GetMDIParentFrame();
388 if (parentFrame
->GetActiveChild() == this)
389 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
390 wxMDIClientWindow
* clientWindow
= parentFrame
->GetClientWindow();
392 // Remove page if still there
393 if (clientWindow
->RemovePage(this))
394 clientWindow
->Refresh();
396 // Set the selection to the first remaining page
397 if (clientWindow
->GetPageCount() > 0)
399 wxMDIChildFrame
* child
= (wxMDIChildFrame
*) clientWindow
->GetPage(0);
400 parentFrame
->SetActiveChild(child
);
401 parentFrame
->SetChildMenuBar(child
);
405 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
406 parentFrame
->SetChildMenuBar((wxMDIChildFrame
*) NULL
);
412 // Implementation: intercept and act upon raise and lower commands.
413 void wxMDIChildFrame::OnRaise()
415 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
416 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
417 parentFrame
->SetActiveChild(this);
421 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
422 event
.SetEventObject( oldActiveChild
);
423 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
426 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, this->GetId());
427 event
.SetEventObject( this );
428 this->GetEventHandler()->ProcessEvent(event
);
431 void wxMDIChildFrame::OnLower()
433 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
434 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
436 if (oldActiveChild
== this)
438 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
439 event
.SetEventObject( oldActiveChild
);
440 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
442 // TODO: unfortunately we don't now know which is the top-most child,
443 // so make the active child NULL.
444 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
448 // Set the client size (i.e. leave the calculation of borders etc.
450 void wxMDIChildFrame::SetClientSize(int width
, int height
)
452 wxWindow::DoSetClientSize(width
, height
);
455 void wxMDIChildFrame::GetClientSize(int* width
, int* height
) const
457 wxWindow::GetSize(width
, height
);
460 void wxMDIChildFrame::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
462 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
465 void wxMDIChildFrame::GetSize(int* width
, int* height
) const
467 wxWindow::GetSize(width
, height
);
470 void wxMDIChildFrame::GetPosition(int *x
, int *y
) const
472 wxWindow::GetPosition(x
, y
);
475 bool wxMDIChildFrame::Show(bool show
)
477 m_visibleStatus
= show
; /* show-&-hide fix */
478 return wxWindow::Show(show
);
481 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menuBar
)
483 // Don't create the underlying menubar yet; need to recreate
484 // it every time the child is activated.
485 m_frameMenuBar
= menuBar
;
487 // We make the assumption that if you're setting the menubar,
488 // this is the currently active child.
489 GetMDIParentFrame()->SetChildMenuBar(this);
493 void wxMDIChildFrame::SetIcon(const wxIcon
& icon
)
498 // Not appropriate since there are no icons in
503 void wxMDIChildFrame::SetTitle(const wxString
& title
)
506 wxMDIClientWindow
* clientWindow
= GetMDIParentFrame()->GetClientWindow();
507 int pageNo
= clientWindow
->FindPagePosition(this);
509 clientWindow
->SetPageText(pageNo
, title
);
513 void wxMDIChildFrame::Maximize()
518 void wxMDIChildFrame::Iconize(bool iconize
)
523 bool wxMDIChildFrame::IsIconized() const
528 // Is it maximized? Always maximized under Motif, using the
529 // tabbed MDI implementation.
530 bool wxMDIChildFrame::IsMaximized(void) const
535 void wxMDIChildFrame::Restore()
540 void wxMDIChildFrame::Activate()
545 void wxMDIChildFrame::CaptureMouse()
547 wxWindow::CaptureMouse();
550 void wxMDIChildFrame::ReleaseMouse()
552 wxWindow::ReleaseMouse();
555 void wxMDIChildFrame::Raise()
560 void wxMDIChildFrame::Lower(void)
565 void wxMDIChildFrame::SetSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
), int WXUNUSED(maxW
), int WXUNUSED(maxH
), int WXUNUSED(incW
), int WXUNUSED(incH
))
571 wxMDIClientWindow::wxMDIClientWindow()
575 wxMDIClientWindow::~wxMDIClientWindow()
577 // By the time this destructor is called, the child frames will have been
578 // deleted and removed from the notebook/client window.
581 m_mainWidget
= (WXWidget
) 0;
584 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
586 // m_windowParent = parent;
587 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE);
589 bool success
= wxNotebook::Create(parent
, wxID_NOTEBOOK_CLIENT_AREA
, wxPoint(0, 0), wxSize(100, 100), 0);
592 wxFont
font(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
593 wxFont
selFont(10, wxSWISS
, wxNORMAL
, wxBOLD
);
594 GetTabView()->SetTabFont(font
);
595 GetTabView()->SetSelectedTabFont(selFont
);
596 GetTabView()->SetTabSize(120, 18);
597 GetTabView()->SetTabSelectionHeight(20);
604 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
606 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
609 void wxMDIClientWindow::DoSetClientSize(int width
, int height
)
611 wxWindow::DoSetClientSize(width
, height
);
614 void wxMDIClientWindow::GetClientSize(int *width
, int *height
) const
616 wxWindow::GetClientSize(width
, height
);
619 void wxMDIClientWindow::GetSize(int *width
, int *height
) const
621 wxWindow::GetSize(width
, height
);
624 void wxMDIClientWindow::GetPosition(int *x
, int *y
) const
626 wxWindow::GetPosition(x
, y
);
629 // Explicitly call default scroll behaviour
630 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
632 Default(); // Default processing
635 void wxMDIClientWindow::OnPageChanged(wxNotebookEvent
& event
)
637 // Notify child that it has been activated
638 if (event
.GetOldSelection() != -1)
640 wxMDIChildFrame
* oldChild
= (wxMDIChildFrame
*) GetPage(event
.GetOldSelection());
643 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldChild
->GetId());
644 event
.SetEventObject( oldChild
);
645 oldChild
->GetEventHandler()->ProcessEvent(event
);
648 if (event
.GetSelection() != -1)
650 wxMDIChildFrame
* activeChild
= (wxMDIChildFrame
*) GetPage(event
.GetSelection());
653 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, activeChild
->GetId());
654 event
.SetEventObject( activeChild
);
655 activeChild
->GetEventHandler()->ProcessEvent(event
);
657 if (activeChild
->GetMDIParentFrame())
659 activeChild
->GetMDIParentFrame()->SetActiveChild(activeChild
);
660 activeChild
->GetMDIParentFrame()->SetChildMenuBar(activeChild
);