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
)
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::OnActivate(wxActivateEvent
& event
)
139 // Returns the active MDI child window
140 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
142 return m_activeChild
;
145 // Create the client window class (don't Create the window,
146 // just return a new class)
147 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
149 return new wxMDIClientWindow
;
152 // Set the child's menu into the parent frame
153 void wxMDIParentFrame::SetChildMenuBar(wxMDIChildFrame
* child
)
155 wxMenuBar
* oldMenuBar
= m_activeMenuBar
;
157 if (child
== (wxMDIChildFrame
*) NULL
) // No child: use parent frame
159 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar
))
161 // if (m_activeMenuBar)
162 // m_activeMenuBar->DestroyMenuBar();
164 m_activeMenuBar
= GetMenuBar();
165 m_activeMenuBar
->CreateMenuBar(this);
167 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
168 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
170 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
171 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
175 else if (child
->GetMenuBar() == (wxMenuBar
*) NULL
) // No child menu bar: use parent frame
177 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar
))
179 // if (m_activeMenuBar)
180 // m_activeMenuBar->DestroyMenuBar();
181 m_activeMenuBar
= GetMenuBar();
182 m_activeMenuBar
->CreateMenuBar(this);
184 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
185 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
187 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
188 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
191 else // The child has a menubar
193 if (child
->GetMenuBar() != m_activeMenuBar
)
195 // if (m_activeMenuBar)
196 // m_activeMenuBar->DestroyMenuBar();
198 m_activeMenuBar
= child
->GetMenuBar();
199 m_activeMenuBar
->CreateMenuBar(this);
201 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
202 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
204 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
205 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
210 // Redirect events to active child first
211 bool wxMDIParentFrame::ProcessEvent(wxEvent
& event
)
213 // Stops the same event being processed repeatedly
214 static wxEventType inEvent
= wxEVT_NULL
;
215 if (inEvent
== event
.GetEventType())
218 inEvent
= event
.GetEventType();
221 if (m_activeChild
&& event
.IsKindOf(CLASSINFO(wxCommandEvent
)))
223 res
= m_activeChild
->GetEventHandler()->ProcessEvent(event
);
227 res
= GetEventHandler()->wxEvtHandler::ProcessEvent(event
);
229 inEvent
= wxEVT_NULL
;
234 // Responds to colour changes, and passes event on to children.
235 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
239 // Propagate the event to the non-top-level children
240 wxFrame::OnSysColourChanged(event
);
244 void wxMDIParentFrame::Cascade()
249 void wxMDIParentFrame::Tile()
254 void wxMDIParentFrame::ArrangeIcons()
259 void wxMDIParentFrame::ActivateNext()
264 void wxMDIParentFrame::ActivatePrevious()
271 wxMDIChildFrame::wxMDIChildFrame()
273 m_mdiParentFrame
= (wxMDIParentFrame
*) NULL
;
276 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
278 const wxString
& title
,
282 const wxString
& name
)
286 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
287 m_foregroundColour
= *wxBLACK
;
288 m_windowFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
293 m_windowId
= (int)NewControlId();
295 wxMDIClientWindow
* clientWindow
= parent
->GetClientWindow();
297 wxASSERT_MSG( (clientWindow
!= (wxWindow
*) NULL
), "Missing MDI client window.");
299 if (clientWindow
) clientWindow
->AddChild(this);
301 SetMDIParentFrame(parent
);
303 int x
= pos
.x
; int y
= pos
.y
;
304 int width
= size
.x
; int height
= size
.y
;
306 width
= 200; // TODO: give reasonable default
308 height
= 200; // TODO: give reasonable default
310 // We're deactivating the old child
311 wxMDIChildFrame
* oldActiveChild
= parent
->GetActiveChild();
314 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
315 event
.SetEventObject( oldActiveChild
);
316 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
319 // This is the currently active child
320 parent
->SetActiveChild((wxMDIChildFrame
*) this);
322 // This time we'll try a bog-standard bulletin board for
323 // the 'frame'. A main window doesn't seem to work.
325 m_mainWidget
= (WXWidget
) XtVaCreateWidget("client",
326 xmBulletinBoardWidgetClass
, (Widget
) clientWindow
->GetTopWidget(),
330 XmNrightAttachment, XmATTACH_FORM,
331 XmNleftAttachment, XmATTACH_FORM,
332 XmNtopAttachment, XmATTACH_FORM,
333 XmNbottomAttachment, XmATTACH_FORM,
335 XmNresizePolicy
, XmRESIZE_NONE
,
338 XtAddEventHandler((Widget
) m_mainWidget
, ExposureMask
,FALSE
,
339 wxUniversalRepaintProc
, (XtPointer
) this);
341 SetCanAddEventHandler(TRUE
);
342 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
344 ChangeBackgroundColour();
346 XtManageChild((Widget
) m_mainWidget
);
350 clientWindow
->AddPage(this, title
, TRUE
);
351 clientWindow
->Refresh();
353 // Positions the toolbar and status bar -- but we don't have any.
356 wxModelessWindows
.Append(this);
361 wxMDIChildFrame::~wxMDIChildFrame()
364 XtRemoveEventHandler((Widget
) m_mainWidget
, ExposureMask
,FALSE
,
365 wxUniversalRepaintProc
, (XtPointer
) this);
367 if (GetMDIParentFrame())
369 wxMDIParentFrame
* parentFrame
= GetMDIParentFrame();
371 if (parentFrame
->GetActiveChild() == this)
372 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
373 wxMDIClientWindow
* clientWindow
= parentFrame
->GetClientWindow();
375 // Remove page if still there
376 if (clientWindow
->RemovePage(this))
377 clientWindow
->Refresh();
379 // Set the selection to the first remaining page
380 if (clientWindow
->GetPageCount() > 0)
382 wxMDIChildFrame
* child
= (wxMDIChildFrame
*) clientWindow
->GetPage(0);
383 parentFrame
->SetActiveChild(child
);
384 parentFrame
->SetChildMenuBar(child
);
388 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
389 parentFrame
->SetChildMenuBar((wxMDIChildFrame
*) NULL
);
395 // Implementation: intercept and act upon raise and lower commands.
396 void wxMDIChildFrame::OnRaise()
398 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
399 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
400 parentFrame
->SetActiveChild(this);
404 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
405 event
.SetEventObject( oldActiveChild
);
406 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
409 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, this->GetId());
410 event
.SetEventObject( this );
411 this->GetEventHandler()->ProcessEvent(event
);
414 void wxMDIChildFrame::OnLower()
416 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
417 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
419 if (oldActiveChild
== this)
421 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
422 event
.SetEventObject( oldActiveChild
);
423 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
425 // TODO: unfortunately we don't now know which is the top-most child,
426 // so make the active child NULL.
427 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
431 // Set the client size (i.e. leave the calculation of borders etc.
433 void wxMDIChildFrame::SetClientSize(int width
, int height
)
435 wxWindow::DoSetClientSize(width
, height
);
438 void wxMDIChildFrame::GetClientSize(int* width
, int* height
) const
440 wxWindow::GetSize(width
, height
);
443 void wxMDIChildFrame::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
445 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
448 void wxMDIChildFrame::GetSize(int* width
, int* height
) const
450 wxWindow::GetSize(width
, height
);
453 void wxMDIChildFrame::GetPosition(int *x
, int *y
) const
455 wxWindow::GetPosition(x
, y
);
458 bool wxMDIChildFrame::Show(bool show
)
460 m_visibleStatus
= show
; /* show-&-hide fix */
461 return wxWindow::Show(show
);
464 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menuBar
)
466 // Don't create the underlying menubar yet; need to recreate
467 // it every time the child is activated.
468 m_frameMenuBar
= menuBar
;
470 // We make the assumption that if you're setting the menubar,
471 // this is the currently active child.
472 GetMDIParentFrame()->SetChildMenuBar(this);
476 void wxMDIChildFrame::SetIcon(const wxIcon
& icon
)
481 // Not appropriate since there are no icons in
486 void wxMDIChildFrame::SetTitle(const wxString
& title
)
489 wxMDIClientWindow
* clientWindow
= GetMDIParentFrame()->GetClientWindow();
490 int pageNo
= clientWindow
->FindPagePosition(this);
492 clientWindow
->SetPageText(pageNo
, title
);
496 void wxMDIChildFrame::Maximize()
501 void wxMDIChildFrame::Iconize(bool iconize
)
506 bool wxMDIChildFrame::IsIconized() const
511 // Is it maximized? Always maximized under Motif, using the
512 // tabbed MDI implementation.
513 bool wxMDIChildFrame::IsMaximized(void) const
518 void wxMDIChildFrame::Restore()
523 void wxMDIChildFrame::Activate()
528 void wxMDIChildFrame::CaptureMouse()
530 wxWindow::CaptureMouse();
533 void wxMDIChildFrame::ReleaseMouse()
535 wxWindow::ReleaseMouse();
538 void wxMDIChildFrame::Raise()
543 void wxMDIChildFrame::Lower(void)
548 void wxMDIChildFrame::SetSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
), int WXUNUSED(maxW
), int WXUNUSED(maxH
), int WXUNUSED(incW
), int WXUNUSED(incH
))
554 wxMDIClientWindow::wxMDIClientWindow()
558 wxMDIClientWindow::~wxMDIClientWindow()
560 // By the time this destructor is called, the child frames will have been
561 // deleted and removed from the notebook/client window.
564 m_mainWidget
= (WXWidget
) 0;
567 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
569 // m_windowParent = parent;
570 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE);
572 bool success
= wxNotebook::Create(parent
, wxID_NOTEBOOK_CLIENT_AREA
, wxPoint(0, 0), wxSize(100, 100), 0);
575 wxFont
font(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
576 wxFont
selFont(10, wxSWISS
, wxNORMAL
, wxBOLD
);
577 GetTabView()->SetTabFont(font
);
578 GetTabView()->SetSelectedTabFont(selFont
);
579 GetTabView()->SetTabSize(120, 18);
580 GetTabView()->SetTabSelectionHeight(20);
587 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
589 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
592 void wxMDIClientWindow::DoSetClientSize(int width
, int height
)
594 wxWindow::DoSetClientSize(width
, height
);
597 void wxMDIClientWindow::GetClientSize(int *width
, int *height
) const
599 wxWindow::GetClientSize(width
, height
);
602 void wxMDIClientWindow::GetSize(int *width
, int *height
) const
604 wxWindow::GetSize(width
, height
);
607 void wxMDIClientWindow::GetPosition(int *x
, int *y
) const
609 wxWindow::GetPosition(x
, y
);
612 // Explicitly call default scroll behaviour
613 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
615 Default(); // Default processing
618 void wxMDIClientWindow::OnPageChanged(wxNotebookEvent
& event
)
620 // Notify child that it has been activated
621 if (event
.GetOldSelection() != -1)
623 wxMDIChildFrame
* oldChild
= (wxMDIChildFrame
*) GetPage(event
.GetOldSelection());
626 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldChild
->GetId());
627 event
.SetEventObject( oldChild
);
628 oldChild
->GetEventHandler()->ProcessEvent(event
);
631 if (event
.GetSelection() != -1)
633 wxMDIChildFrame
* activeChild
= (wxMDIChildFrame
*) GetPage(event
.GetSelection());
636 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, activeChild
->GetId());
637 event
.SetEventObject( activeChild
);
638 activeChild
->GetEventHandler()->ProcessEvent(event
);
640 if (activeChild
->GetMDIParentFrame())
642 activeChild
->GetMDIParentFrame()->SetActiveChild(activeChild
);
643 activeChild
->GetMDIParentFrame()->SetChildMenuBar(activeChild
);