1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/mdi.cpp
3 // Purpose: MDI classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
20 #include "wx/settings.h"
24 #pragma message disable nosimpint
27 #include <Xm/BulletinB.h>
30 #include <Xm/RowColumn.h>
31 #include <Xm/CascadeBG.h>
33 #include <Xm/PushBG.h>
34 #include <Xm/AtomMgr.h>
35 #include <Xm/Protocols.h>
37 #pragma message enable nosimpint
40 #include "wx/motif/private.h"
42 extern wxList wxModelessWindows
;
44 // Implemented in frame.cpp
45 extern void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
46 XmAnyCallbackStruct
*cbs
);
48 #define wxID_NOTEBOOK_CLIENT_AREA wxID_HIGHEST + 100
50 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
51 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
52 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxNotebook
)
54 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
55 EVT_SIZE(wxMDIParentFrame::OnSize
)
56 EVT_ACTIVATE(wxMDIParentFrame::OnActivate
)
57 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
58 EVT_MENU_HIGHLIGHT_ALL(wxMDIParentFrame::OnMenuHighlight
)
61 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxNotebook
)
62 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
63 EVT_NOTEBOOK_PAGE_CHANGED(wxID_NOTEBOOK_CLIENT_AREA
, wxMDIClientWindow::OnPageChanged
)
69 wxMDIParentFrame::wxMDIParentFrame()
71 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
72 m_activeChild
= (wxMDIChildFrame
*) NULL
;
73 m_activeMenuBar
= (wxMenuBar
*) NULL
;
76 bool wxMDIParentFrame::Create(wxWindow
*parent
,
78 const wxString
& title
,
84 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
85 m_activeChild
= (wxMDIChildFrame
*) NULL
;
86 m_activeMenuBar
= (wxMenuBar
*) NULL
;
88 bool success
= wxFrame::Create(parent
, id
, title
, pos
, size
, style
, name
);
91 // TODO: app cannot override OnCreateClient since
92 // wxMDIParentFrame::OnCreateClient will still be called
93 // (we're in the constructor). How to resolve?
95 m_clientWindow
= OnCreateClient();
97 // Uses own style for client style
98 m_clientWindow
->CreateClient(this, GetWindowStyleFlag());
101 GetClientSize(& w
, & h
);
102 m_clientWindow
->SetSize(0, 0, w
, h
);
109 wxMDIParentFrame::~wxMDIParentFrame()
111 // Make sure we delete the client window last of all
112 RemoveChild(m_clientWindow
);
116 delete m_clientWindow
;
117 m_clientWindow
= NULL
;
120 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
122 m_frameMenuBar
= menu_bar
;
124 SetChildMenuBar((wxMDIChildFrame
*) NULL
);
127 void wxMDIParentFrame::OnSize(wxSizeEvent
& WXUNUSED(event
))
129 #if wxUSE_CONSTRAINTS
136 GetClientSize(&width
, &height
);
138 if ( GetClientWindow() )
139 GetClientWindow()->SetSize(x
, y
, width
, height
);
142 void wxMDIParentFrame::DoGetClientSize(int *width
, int *height
) const
144 wxFrame::DoGetClientSize(width
, height
);
147 void wxMDIParentFrame::OnActivate(wxActivateEvent
& WXUNUSED(event
))
152 // Returns the active MDI child window
153 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
155 return m_activeChild
;
158 // Create the client window class (don't Create the window,
159 // just return a new class)
160 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
162 return new wxMDIClientWindow
;
165 // Set the child's menu into the parent frame
166 void wxMDIParentFrame::SetChildMenuBar(wxMDIChildFrame
* child
)
168 wxMenuBar
* oldMenuBar
= m_activeMenuBar
;
170 if (child
== (wxMDIChildFrame
*) NULL
) // No child: use parent frame
172 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar
))
174 // if (m_activeMenuBar)
175 // m_activeMenuBar->DestroyMenuBar();
177 m_activeMenuBar
= GetMenuBar();
178 m_activeMenuBar
->CreateMenuBar(this);
180 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
181 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
183 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
184 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
188 else if (child
->GetMenuBar() == (wxMenuBar
*) NULL
) // No child menu bar: use parent frame
190 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar
))
192 // if (m_activeMenuBar)
193 // m_activeMenuBar->DestroyMenuBar();
194 m_activeMenuBar
= GetMenuBar();
195 m_activeMenuBar
->CreateMenuBar(this);
197 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
198 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
200 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
201 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
204 else // The child has a menubar
206 if (child
->GetMenuBar() != m_activeMenuBar
)
208 // if (m_activeMenuBar)
209 // m_activeMenuBar->DestroyMenuBar();
211 m_activeMenuBar
= child
->GetMenuBar();
212 m_activeMenuBar
->CreateMenuBar(this);
214 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
215 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
217 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
218 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
223 // Redirect events to active child first
224 bool wxMDIParentFrame::ProcessEvent(wxEvent
& event
)
226 // Stops the same event being processed repeatedly
227 static wxEventType inEvent
= wxEVT_NULL
;
228 if (inEvent
== event
.GetEventType())
231 inEvent
= event
.GetEventType();
234 if (m_activeChild
&& event
.IsKindOf(CLASSINFO(wxCommandEvent
)))
236 res
= m_activeChild
->HandleWindowEvent(event
);
240 res
= GetEventHandler()->wxEvtHandler::ProcessEvent(event
);
242 inEvent
= wxEVT_NULL
;
247 void wxMDIParentFrame::DoSetSize(int x
, int y
,
248 int width
, int height
,
251 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
254 void wxMDIParentFrame::DoSetClientSize(int width
, int height
)
256 wxWindow::DoSetClientSize(width
, height
);
259 // Responds to colour changes, and passes event on to children.
260 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
264 // Propagate the event to the non-top-level children
265 wxFrame::OnSysColourChanged(event
);
269 void wxMDIParentFrame::Cascade()
274 void wxMDIParentFrame::Tile(wxOrientation
WXUNUSED(orient
))
279 void wxMDIParentFrame::ArrangeIcons()
284 void wxMDIParentFrame::ActivateNext()
289 void wxMDIParentFrame::ActivatePrevious()
294 // Default menu selection behaviour - display a help string
295 void wxMDIParentFrame::OnMenuHighlight(wxMenuEvent
& event
)
299 if (event
.GetMenuId() == -1)
300 SetStatusText(wxEmptyString
);
303 wxMenuBar
*menuBar
= (wxMenuBar
*) NULL
;
304 if (GetActiveChild())
305 menuBar
= GetActiveChild()->GetMenuBar();
307 menuBar
= GetMenuBar();
310 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
311 if (!helpString
.empty())
312 SetStatusText(helpString
);
320 wxMDIChildFrame::wxMDIChildFrame()
322 m_mdiParentFrame
= (wxMDIParentFrame
*) NULL
;
325 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
327 const wxString
& title
,
331 const wxString
& name
)
334 SetWindowStyleFlag(style
);
339 m_windowId
= (int)NewControlId();
341 wxMDIClientWindow
* clientWindow
= parent
->GetClientWindow();
343 wxCHECK_MSG( clientWindow
, false, "Missing MDI client window." );
345 clientWindow
->AddChild(this);
347 SetMDIParentFrame(parent
);
353 width
= 200; // TODO: give reasonable default
355 height
= 200; // TODO: give reasonable default
357 // We're deactivating the old child
358 wxMDIChildFrame
* oldActiveChild
= parent
->GetActiveChild();
361 wxActivateEvent
event(wxEVT_ACTIVATE
, false, oldActiveChild
->GetId());
362 event
.SetEventObject( oldActiveChild
);
363 oldActiveChild
->HandleWindowEvent(event
);
366 // This is the currently active child
367 parent
->SetActiveChild((wxMDIChildFrame
*) this);
369 // This time we'll try a bog-standard bulletin board for
370 // the 'frame'. A main window doesn't seem to work.
372 m_mainWidget
= (WXWidget
) XtVaCreateWidget("client",
373 xmBulletinBoardWidgetClass
, (Widget
) clientWindow
->GetTopWidget(),
377 XmNrightAttachment, XmATTACH_FORM,
378 XmNleftAttachment, XmATTACH_FORM,
379 XmNtopAttachment, XmATTACH_FORM,
380 XmNbottomAttachment, XmATTACH_FORM,
382 XmNresizePolicy
, XmRESIZE_NONE
,
385 XtAddEventHandler((Widget
) m_mainWidget
, ExposureMask
,False
,
386 wxUniversalRepaintProc
, (XtPointer
) this);
389 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
391 XtManageChild((Widget
) m_mainWidget
);
395 clientWindow
->AddPage(this, title
, true);
396 clientWindow
->Refresh();
398 // Positions the toolbar and status bar -- but we don't have any.
401 wxModelessWindows
.Append(this);
406 wxMDIChildFrame::~wxMDIChildFrame()
409 XtRemoveEventHandler((Widget
) m_mainWidget
, ExposureMask
,False
,
410 wxUniversalRepaintProc
, (XtPointer
) this);
412 if (GetMDIParentFrame())
414 wxMDIParentFrame
* parentFrame
= GetMDIParentFrame();
416 if (parentFrame
->GetActiveChild() == this)
417 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
418 wxMDIClientWindow
* clientWindow
= parentFrame
->GetClientWindow();
420 // Remove page if still there
422 int i
= clientWindow
->FindPage(this);
426 clientWindow
->RemovePage(i
);
427 clientWindow
->Refresh();
431 // Set the selection to the first remaining page
432 if (clientWindow
->GetPageCount() > 0)
434 wxMDIChildFrame
* child
= (wxMDIChildFrame
*) clientWindow
->GetPage(0);
435 parentFrame
->SetActiveChild(child
);
436 parentFrame
->SetChildMenuBar(child
);
440 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
441 parentFrame
->SetChildMenuBar((wxMDIChildFrame
*) NULL
);
447 // Implementation: intercept and act upon raise and lower commands.
448 void wxMDIChildFrame::OnRaise()
450 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
451 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
452 parentFrame
->SetActiveChild(this);
456 wxActivateEvent
event(wxEVT_ACTIVATE
, false, oldActiveChild
->GetId());
457 event
.SetEventObject( oldActiveChild
);
458 oldActiveChild
->HandleWindowEvent(event
);
461 wxActivateEvent
event(wxEVT_ACTIVATE
, true, this->GetId());
462 event
.SetEventObject( this );
463 this->HandleWindowEvent(event
);
466 void wxMDIChildFrame::OnLower()
468 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
469 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
471 if (oldActiveChild
== this)
473 wxActivateEvent
event(wxEVT_ACTIVATE
, false, oldActiveChild
->GetId());
474 event
.SetEventObject( oldActiveChild
);
475 oldActiveChild
->HandleWindowEvent(event
);
477 // TODO: unfortunately we don't now know which is the top-most child,
478 // so make the active child NULL.
479 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
483 // Set the client size (i.e. leave the calculation of borders etc.
485 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
487 wxWindow::DoSetClientSize(width
, height
);
490 void wxMDIChildFrame::DoGetClientSize(int* width
, int* height
) const
492 wxWindow::DoGetSize(width
, height
);
495 void wxMDIChildFrame::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
497 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
500 void wxMDIChildFrame::DoGetSize(int* width
, int* height
) const
502 wxWindow::DoGetSize(width
, height
);
505 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
507 wxWindow::DoGetPosition(x
, y
);
510 bool wxMDIChildFrame::Show(bool show
)
512 SetVisibleStatus( show
);
513 return wxWindow::Show(show
);
516 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menuBar
)
518 // Don't create the underlying menubar yet; need to recreate
519 // it every time the child is activated.
520 m_frameMenuBar
= menuBar
;
522 // We make the assumption that if you're setting the menubar,
523 // this is the currently active child.
524 GetMDIParentFrame()->SetChildMenuBar(this);
528 void wxMDIChildFrame::SetIcon(const wxIcon
& icon
)
530 m_icons
= wxIconBundle( icon
);
534 // Not appropriate since there are no icons in
539 void wxMDIChildFrame::SetIcons(const wxIconBundle
& icons
)
544 void wxMDIChildFrame::SetTitle(const wxString
& title
)
546 wxTopLevelWindow::SetTitle( title
);
547 wxMDIClientWindow
* clientWindow
= GetMDIParentFrame()->GetClientWindow();
549 // Remove page if still there
551 int i
= clientWindow
->FindPage(this);
554 clientWindow
->SetPageText(i
, title
);
559 void wxMDIChildFrame::Maximize()
564 void wxMDIChildFrame::Iconize(bool WXUNUSED(iconize
))
569 bool wxMDIChildFrame::IsIconized() const
574 // Is it maximized? Always maximized under Motif, using the
575 // tabbed MDI implementation.
576 bool wxMDIChildFrame::IsMaximized(void) const
581 void wxMDIChildFrame::Restore()
586 void wxMDIChildFrame::Activate()
591 void wxMDIChildFrame::CaptureMouse()
593 wxWindow::CaptureMouse();
596 void wxMDIChildFrame::ReleaseMouse()
598 wxWindow::ReleaseMouse();
601 void wxMDIChildFrame::Raise()
606 void wxMDIChildFrame::Lower(void)
611 void wxMDIChildFrame::DoSetSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
), int WXUNUSED(maxW
), int WXUNUSED(maxH
), int WXUNUSED(incW
), int WXUNUSED(incH
))
617 wxMDIClientWindow::wxMDIClientWindow()
621 wxMDIClientWindow::~wxMDIClientWindow()
623 // By the time this destructor is called, the child frames will have been
624 // deleted and removed from the notebook/client window.
627 m_mainWidget
= (WXWidget
) 0;
630 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
632 SetWindowStyleFlag(style
);
634 bool success
= wxNotebook::Create(parent
, wxID_NOTEBOOK_CLIENT_AREA
, wxPoint(0, 0), wxSize(100, 100), 0);
643 int wxMDIClientWindow::FindPage(const wxNotebookPage
* page
)
645 for (int i
= GetPageCount() - 1; i
>= 0; --i
)
647 if (GetPage(i
) == page
)
654 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
656 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
659 void wxMDIClientWindow::DoSetClientSize(int width
, int height
)
661 wxWindow::DoSetClientSize(width
, height
);
664 void wxMDIClientWindow::DoGetClientSize(int *width
, int *height
) const
666 wxWindow::DoGetClientSize(width
, height
);
669 void wxMDIClientWindow::DoGetSize(int *width
, int *height
) const
671 wxWindow::DoGetSize(width
, height
);
674 void wxMDIClientWindow::DoGetPosition(int *x
, int *y
) const
676 wxWindow::DoGetPosition(x
, y
);
679 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
681 // Default(); // Default processing: OBSOLETE FUNCTION
685 void wxMDIClientWindow::OnPageChanged(wxBookCtrlEvent
& event
)
687 // Notify child that it has been activated
688 if (event
.GetOldSelection() != -1)
690 wxMDIChildFrame
* oldChild
= (wxMDIChildFrame
*) GetPage(event
.GetOldSelection());
693 wxActivateEvent
event(wxEVT_ACTIVATE
, false, oldChild
->GetId());
694 event
.SetEventObject( oldChild
);
695 oldChild
->HandleWindowEvent(event
);
698 if (event
.GetSelection() != -1)
700 wxMDIChildFrame
* activeChild
= (wxMDIChildFrame
*) GetPage(event
.GetSelection());
703 wxActivateEvent
event(wxEVT_ACTIVATE
, true, activeChild
->GetId());
704 event
.SetEventObject( activeChild
);
705 activeChild
->HandleWindowEvent(event
);
707 if (activeChild
->GetMDIParentFrame())
709 activeChild
->GetMDIParentFrame()->SetActiveChild(activeChild
);
710 activeChild
->GetMDIParentFrame()->SetChildMenuBar(activeChild
);