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 // Get size *available for subwindows* i.e. excluding menu bar.
113 void wxMDIParentFrame::GetClientSize(int *x
, int *y
) const
115 wxFrame::GetClientSize(x
, y
);
118 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
120 m_frameMenuBar
= menu_bar
;
122 SetChildMenuBar((wxMDIChildFrame
*) NULL
);
125 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
127 #if wxUSE_CONSTRAINTS
134 GetClientSize(&width
, &height
);
136 if ( GetClientWindow() )
137 GetClientWindow()->SetSize(x
, y
, width
, height
);
140 void wxMDIParentFrame::OnActivate(wxActivateEvent
& event
)
145 // Returns the active MDI child window
146 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
148 return m_activeChild
;
151 // Create the client window class (don't Create the window,
152 // just return a new class)
153 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
155 return new wxMDIClientWindow
;
158 // Set the child's menu into the parent frame
159 void wxMDIParentFrame::SetChildMenuBar(wxMDIChildFrame
* child
)
161 wxMenuBar
* oldMenuBar
= m_activeMenuBar
;
163 if (child
== (wxMDIChildFrame
*) NULL
) // No child: use parent frame
165 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar
))
167 // if (m_activeMenuBar)
168 // m_activeMenuBar->DestroyMenuBar();
170 m_activeMenuBar
= GetMenuBar();
171 m_activeMenuBar
->CreateMenuBar(this);
173 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
174 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
176 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
177 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
181 else if (child
->GetMenuBar() == (wxMenuBar
*) NULL
) // No child menu bar: use parent frame
183 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar
))
185 // if (m_activeMenuBar)
186 // m_activeMenuBar->DestroyMenuBar();
187 m_activeMenuBar
= GetMenuBar();
188 m_activeMenuBar
->CreateMenuBar(this);
190 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
191 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
193 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
194 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
197 else // The child has a menubar
199 if (child
->GetMenuBar() != m_activeMenuBar
)
201 // if (m_activeMenuBar)
202 // m_activeMenuBar->DestroyMenuBar();
204 m_activeMenuBar
= child
->GetMenuBar();
205 m_activeMenuBar
->CreateMenuBar(this);
207 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
208 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
210 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
211 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
216 // Redirect events to active child first
217 bool wxMDIParentFrame::ProcessEvent(wxEvent
& event
)
219 // Stops the same event being processed repeatedly
220 static wxEventType inEvent
= wxEVT_NULL
;
221 if (inEvent
== event
.GetEventType())
224 inEvent
= event
.GetEventType();
227 if (m_activeChild
&& event
.IsKindOf(CLASSINFO(wxCommandEvent
)))
229 res
= m_activeChild
->GetEventHandler()->ProcessEvent(event
);
233 res
= GetEventHandler()->wxEvtHandler::ProcessEvent(event
);
235 inEvent
= wxEVT_NULL
;
240 // Responds to colour changes, and passes event on to children.
241 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
245 // Propagate the event to the non-top-level children
246 wxFrame::OnSysColourChanged(event
);
250 void wxMDIParentFrame::Cascade()
255 void wxMDIParentFrame::Tile()
260 void wxMDIParentFrame::ArrangeIcons()
265 void wxMDIParentFrame::ActivateNext()
270 void wxMDIParentFrame::ActivatePrevious()
277 wxMDIChildFrame::wxMDIChildFrame()
279 m_mdiParentFrame
= (wxMDIParentFrame
*) NULL
;
282 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
284 const wxString
& title
,
288 const wxString
& name
)
292 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
293 m_foregroundColour
= *wxBLACK
;
294 m_windowFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
299 m_windowId
= (int)NewControlId();
301 wxMDIClientWindow
* clientWindow
= parent
->GetClientWindow();
303 wxASSERT_MSG( (clientWindow
!= (wxWindow
*) NULL
), "Missing MDI client window.");
305 if (clientWindow
) clientWindow
->AddChild(this);
307 SetMDIParentFrame(parent
);
309 int x
= pos
.x
; int y
= pos
.y
;
310 int width
= size
.x
; int height
= size
.y
;
312 width
= 200; // TODO: give reasonable default
314 height
= 200; // TODO: give reasonable default
316 // We're deactivating the old child
317 wxMDIChildFrame
* oldActiveChild
= parent
->GetActiveChild();
320 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
321 event
.SetEventObject( oldActiveChild
);
322 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
325 // This is the currently active child
326 parent
->SetActiveChild((wxMDIChildFrame
*) this);
328 // This time we'll try a bog-standard bulletin board for
329 // the 'frame'. A main window doesn't seem to work.
331 m_mainWidget
= (WXWidget
) XtVaCreateWidget("client",
332 xmBulletinBoardWidgetClass
, (Widget
) clientWindow
->GetTopWidget(),
336 XmNrightAttachment, XmATTACH_FORM,
337 XmNleftAttachment, XmATTACH_FORM,
338 XmNtopAttachment, XmATTACH_FORM,
339 XmNbottomAttachment, XmATTACH_FORM,
341 XmNresizePolicy
, XmRESIZE_NONE
,
344 SetCanAddEventHandler(TRUE
);
345 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
347 ChangeBackgroundColour();
349 XtManageChild((Widget
) m_mainWidget
);
353 clientWindow
->AddPage(this, title
, TRUE
);
354 clientWindow
->Refresh();
356 // Positions the toolbar and status bar -- but we don't have any.
359 wxModelessWindows
.Append(this);
364 wxMDIChildFrame::~wxMDIChildFrame()
366 if (GetMDIParentFrame())
368 wxMDIParentFrame
* parentFrame
= GetMDIParentFrame();
370 if (parentFrame
->GetActiveChild() == this)
371 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
372 wxMDIClientWindow
* clientWindow
= parentFrame
->GetClientWindow();
374 // Remove page if still there
375 if (clientWindow
->RemovePage(this))
376 clientWindow
->Refresh();
378 // Set the selection to the first remaining page
379 if (clientWindow
->GetPageCount() > 0)
381 wxMDIChildFrame
* child
= (wxMDIChildFrame
*) clientWindow
->GetPage(0);
382 parentFrame
->SetActiveChild(child
);
383 parentFrame
->SetChildMenuBar(child
);
387 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
388 parentFrame
->SetChildMenuBar((wxMDIChildFrame
*) NULL
);
394 // Implementation: intercept and act upon raise and lower commands.
395 void wxMDIChildFrame::OnRaise()
397 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
398 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
399 parentFrame
->SetActiveChild(this);
403 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
404 event
.SetEventObject( oldActiveChild
);
405 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
408 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, this->GetId());
409 event
.SetEventObject( this );
410 this->GetEventHandler()->ProcessEvent(event
);
413 void wxMDIChildFrame::OnLower()
415 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
416 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
418 if (oldActiveChild
== this)
420 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
421 event
.SetEventObject( oldActiveChild
);
422 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
424 // TODO: unfortunately we don't now know which is the top-most child,
425 // so make the active child NULL.
426 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
430 // Set the client size (i.e. leave the calculation of borders etc.
432 void wxMDIChildFrame::SetClientSize(int width
, int height
)
434 wxWindow::SetClientSize(width
, height
);
437 void wxMDIChildFrame::GetClientSize(int* width
, int* height
) const
439 wxWindow::GetSize(width
, height
);
442 void wxMDIChildFrame::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
444 wxWindow::SetSize(x
, y
, width
, height
, sizeFlags
);
447 void wxMDIChildFrame::GetSize(int* width
, int* height
) const
449 wxWindow::GetSize(width
, height
);
452 void wxMDIChildFrame::GetPosition(int *x
, int *y
) const
454 wxWindow::GetPosition(x
, y
);
457 bool wxMDIChildFrame::Show(bool show
)
459 m_visibleStatus
= show
; /* show-&-hide fix */
460 return wxWindow::Show(show
);
463 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menuBar
)
465 // Don't create the underlying menubar yet; need to recreate
466 // it every time the child is activated.
467 m_frameMenuBar
= menuBar
;
469 // We make the assumption that if you're setting the menubar,
470 // this is the currently active child.
471 GetMDIParentFrame()->SetChildMenuBar(this);
475 void wxMDIChildFrame::SetIcon(const wxIcon
& icon
)
480 // Not appropriate since there are no icons in
485 void wxMDIChildFrame::SetTitle(const wxString
& title
)
488 wxMDIClientWindow
* clientWindow
= GetMDIParentFrame()->GetClientWindow();
489 int pageNo
= clientWindow
->FindPagePosition(this);
491 clientWindow
->SetPageText(pageNo
, title
);
495 void wxMDIChildFrame::Maximize()
500 void wxMDIChildFrame::Iconize(bool iconize
)
505 bool wxMDIChildFrame::IsIconized() const
510 // Is it maximized? Always maximized under Motif, using the
511 // tabbed MDI implementation.
512 bool wxMDIChildFrame::IsMaximized(void) const
517 void wxMDIChildFrame::Restore()
522 void wxMDIChildFrame::Activate()
527 void wxMDIChildFrame::CaptureMouse()
529 wxWindow::CaptureMouse();
532 void wxMDIChildFrame::ReleaseMouse()
534 wxWindow::ReleaseMouse();
537 void wxMDIChildFrame::Raise()
542 void wxMDIChildFrame::Lower(void)
547 void wxMDIChildFrame::SetSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
), int WXUNUSED(maxW
), int WXUNUSED(maxH
), int WXUNUSED(incW
), int WXUNUSED(incH
))
553 wxMDIClientWindow::wxMDIClientWindow()
557 wxMDIClientWindow::~wxMDIClientWindow()
559 // By the time this destructor is called, the child frames will have been
560 // deleted and removed from the notebook/client window.
563 m_mainWidget
= (WXWidget
) 0;
566 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
568 // m_windowParent = parent;
569 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE);
571 bool success
= wxNotebook::Create(parent
, wxID_NOTEBOOK_CLIENT_AREA
, wxPoint(0, 0), wxSize(100, 100), 0);
574 wxFont
font(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
575 wxFont
selFont(10, wxSWISS
, wxNORMAL
, wxBOLD
);
576 GetTabView()->SetTabFont(font
);
577 GetTabView()->SetSelectedTabFont(selFont
);
578 GetTabView()->SetTabSize(120, 18);
579 GetTabView()->SetTabSelectionHeight(20);
586 void wxMDIClientWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
588 wxWindow::SetSize(x
, y
, width
, height
, sizeFlags
);
591 void wxMDIClientWindow::SetClientSize(int width
, int height
)
593 wxWindow::SetClientSize(width
, height
);
596 void wxMDIClientWindow::GetClientSize(int *width
, int *height
) const
598 wxWindow::GetClientSize(width
, height
);
601 void wxMDIClientWindow::GetSize(int *width
, int *height
) const
603 wxWindow::GetSize(width
, height
);
606 void wxMDIClientWindow::GetPosition(int *x
, int *y
) const
608 wxWindow::GetPosition(x
, y
);
611 // Explicitly call default scroll behaviour
612 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
614 Default(); // Default processing
617 void wxMDIClientWindow::OnPageChanged(wxNotebookEvent
& event
)
619 // Notify child that it has been activated
620 if (event
.GetOldSelection() != -1)
622 wxMDIChildFrame
* oldChild
= (wxMDIChildFrame
*) GetPage(event
.GetOldSelection());
625 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldChild
->GetId());
626 event
.SetEventObject( oldChild
);
627 oldChild
->GetEventHandler()->ProcessEvent(event
);
630 if (event
.GetSelection() != -1)
632 wxMDIChildFrame
* activeChild
= (wxMDIChildFrame
*) GetPage(event
.GetSelection());
635 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, activeChild
->GetId());
636 event
.SetEventObject( activeChild
);
637 activeChild
->GetEventHandler()->ProcessEvent(event
);
639 if (activeChild
->GetMDIParentFrame())
641 activeChild
->GetMDIParentFrame()->SetActiveChild(activeChild
);
642 activeChild
->GetMDIParentFrame()->SetChildMenuBar(activeChild
);