1 /////////////////////////////////////////////////////////////////////////////
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"
16 #define XtDisplay XTDISPLAY
17 #define XtWindow XTWINDOW
22 #include "wx/settings.h"
26 #pragma message disable nosimpint
29 #include <Xm/BulletinB.h>
32 #include <Xm/RowColumn.h>
33 #include <Xm/CascadeBG.h>
35 #include <Xm/PushBG.h>
36 #include <Xm/AtomMgr.h>
37 #include <Xm/Protocols.h>
39 #pragma message enable nosimpint
42 #include "wx/motif/private.h"
44 extern wxList wxModelessWindows
;
46 // Implemented in frame.cpp
47 extern void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
48 XmAnyCallbackStruct
*cbs
);
50 #define wxID_NOTEBOOK_CLIENT_AREA wxID_HIGHEST + 100
52 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
53 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
54 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxNotebook
)
56 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
57 EVT_SIZE(wxMDIParentFrame::OnSize
)
58 EVT_ACTIVATE(wxMDIParentFrame::OnActivate
)
59 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
60 EVT_MENU_HIGHLIGHT_ALL(wxMDIParentFrame::OnMenuHighlight
)
63 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxNotebook
)
64 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
65 EVT_NOTEBOOK_PAGE_CHANGED(wxID_NOTEBOOK_CLIENT_AREA
, wxMDIClientWindow::OnPageChanged
)
71 wxMDIParentFrame::wxMDIParentFrame()
73 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
74 m_activeChild
= (wxMDIChildFrame
*) NULL
;
75 m_activeMenuBar
= (wxMenuBar
*) NULL
;
78 bool wxMDIParentFrame::Create(wxWindow
*parent
,
80 const wxString
& title
,
86 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
87 m_activeChild
= (wxMDIChildFrame
*) NULL
;
88 m_activeMenuBar
= (wxMenuBar
*) NULL
;
90 bool success
= wxFrame::Create(parent
, id
, title
, pos
, size
, style
, name
);
93 // TODO: app cannot override OnCreateClient since
94 // wxMDIParentFrame::OnCreateClient will still be called
95 // (we're in the constructor). How to resolve?
97 m_clientWindow
= OnCreateClient();
99 // Uses own style for client style
100 m_clientWindow
->CreateClient(this, GetWindowStyleFlag());
103 GetClientSize(& w
, & h
);
104 m_clientWindow
->SetSize(0, 0, w
, h
);
111 wxMDIParentFrame::~wxMDIParentFrame()
113 // Make sure we delete the client window last of all
114 RemoveChild(m_clientWindow
);
118 delete m_clientWindow
;
119 m_clientWindow
= NULL
;
122 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
124 m_frameMenuBar
= menu_bar
;
126 SetChildMenuBar((wxMDIChildFrame
*) NULL
);
129 void wxMDIParentFrame::OnSize(wxSizeEvent
& WXUNUSED(event
))
131 #if wxUSE_CONSTRAINTS
138 GetClientSize(&width
, &height
);
140 if ( GetClientWindow() )
141 GetClientWindow()->SetSize(x
, y
, width
, height
);
144 void wxMDIParentFrame::DoGetClientSize(int *width
, int *height
) const
146 wxFrame::DoGetClientSize(width
, height
);
149 void wxMDIParentFrame::OnActivate(wxActivateEvent
& WXUNUSED(event
))
154 // Returns the active MDI child window
155 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
157 return m_activeChild
;
160 // Create the client window class (don't Create the window,
161 // just return a new class)
162 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
164 return new wxMDIClientWindow
;
167 // Set the child's menu into the parent frame
168 void wxMDIParentFrame::SetChildMenuBar(wxMDIChildFrame
* child
)
170 wxMenuBar
* oldMenuBar
= m_activeMenuBar
;
172 if (child
== (wxMDIChildFrame
*) NULL
) // No child: use parent frame
174 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar
))
176 // if (m_activeMenuBar)
177 // m_activeMenuBar->DestroyMenuBar();
179 m_activeMenuBar
= GetMenuBar();
180 m_activeMenuBar
->CreateMenuBar(this);
182 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
183 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
185 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
186 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
190 else if (child
->GetMenuBar() == (wxMenuBar
*) NULL
) // No child menu bar: use parent frame
192 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar
))
194 // if (m_activeMenuBar)
195 // m_activeMenuBar->DestroyMenuBar();
196 m_activeMenuBar
= GetMenuBar();
197 m_activeMenuBar
->CreateMenuBar(this);
199 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
200 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
202 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
203 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
206 else // The child has a menubar
208 if (child
->GetMenuBar() != m_activeMenuBar
)
210 // if (m_activeMenuBar)
211 // m_activeMenuBar->DestroyMenuBar();
213 m_activeMenuBar
= child
->GetMenuBar();
214 m_activeMenuBar
->CreateMenuBar(this);
216 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
217 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
219 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
220 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
225 // Redirect events to active child first
226 bool wxMDIParentFrame::ProcessEvent(wxEvent
& event
)
228 // Stops the same event being processed repeatedly
229 static wxEventType inEvent
= wxEVT_NULL
;
230 if (inEvent
== event
.GetEventType())
233 inEvent
= event
.GetEventType();
236 if (m_activeChild
&& event
.IsKindOf(CLASSINFO(wxCommandEvent
)))
238 res
= m_activeChild
->GetEventHandler()->ProcessEvent(event
);
242 res
= GetEventHandler()->wxEvtHandler::ProcessEvent(event
);
244 inEvent
= wxEVT_NULL
;
249 void wxMDIParentFrame::DoSetSize(int x
, int y
,
250 int width
, int height
,
253 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
256 void wxMDIParentFrame::DoSetClientSize(int width
, int height
)
258 wxWindow::DoSetClientSize(width
, height
);
261 // Responds to colour changes, and passes event on to children.
262 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
266 // Propagate the event to the non-top-level children
267 wxFrame::OnSysColourChanged(event
);
271 void wxMDIParentFrame::Cascade()
276 void wxMDIParentFrame::Tile(wxOrientation
WXUNUSED(orient
))
281 void wxMDIParentFrame::ArrangeIcons()
286 void wxMDIParentFrame::ActivateNext()
291 void wxMDIParentFrame::ActivatePrevious()
296 // Default menu selection behaviour - display a help string
297 void wxMDIParentFrame::OnMenuHighlight(wxMenuEvent
& event
)
301 if (event
.GetMenuId() == -1)
305 wxMenuBar
*menuBar
= (wxMenuBar
*) NULL
;
306 if (GetActiveChild())
307 menuBar
= GetActiveChild()->GetMenuBar();
309 menuBar
= GetMenuBar();
312 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
313 if (helpString
!= "")
314 SetStatusText(helpString
);
322 wxMDIChildFrame::wxMDIChildFrame()
324 m_mdiParentFrame
= (wxMDIParentFrame
*) NULL
;
327 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
329 const wxString
& title
,
333 const wxString
& name
)
336 SetWindowStyleFlag(style
);
338 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
339 m_foregroundColour
= *wxBLACK
;
340 m_font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
345 m_windowId
= (int)NewControlId();
347 wxMDIClientWindow
* clientWindow
= parent
->GetClientWindow();
349 wxASSERT_MSG( (clientWindow
!= (wxWindow
*) NULL
), "Missing MDI client window.");
351 if (clientWindow
) clientWindow
->AddChild(this);
353 SetMDIParentFrame(parent
);
358 width
= 200; // TODO: give reasonable default
360 height
= 200; // TODO: give reasonable default
362 // We're deactivating the old child
363 wxMDIChildFrame
* oldActiveChild
= parent
->GetActiveChild();
366 wxActivateEvent
event(wxEVT_ACTIVATE
, false, oldActiveChild
->GetId());
367 event
.SetEventObject( oldActiveChild
);
368 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
371 // This is the currently active child
372 parent
->SetActiveChild((wxMDIChildFrame
*) this);
374 // This time we'll try a bog-standard bulletin board for
375 // the 'frame'. A main window doesn't seem to work.
377 m_mainWidget
= (WXWidget
) XtVaCreateWidget("client",
378 xmBulletinBoardWidgetClass
, (Widget
) clientWindow
->GetTopWidget(),
382 XmNrightAttachment, XmATTACH_FORM,
383 XmNleftAttachment, XmATTACH_FORM,
384 XmNtopAttachment, XmATTACH_FORM,
385 XmNbottomAttachment, XmATTACH_FORM,
387 XmNresizePolicy
, XmRESIZE_NONE
,
390 XtAddEventHandler((Widget
) m_mainWidget
, ExposureMask
,False
,
391 wxUniversalRepaintProc
, (XtPointer
) this);
393 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
395 ChangeBackgroundColour();
397 XtManageChild((Widget
) m_mainWidget
);
401 clientWindow
->AddPage(this, title
, true);
402 clientWindow
->Refresh();
404 // Positions the toolbar and status bar -- but we don't have any.
407 wxModelessWindows
.Append(this);
412 wxMDIChildFrame::~wxMDIChildFrame()
415 XtRemoveEventHandler((Widget
) m_mainWidget
, ExposureMask
,False
,
416 wxUniversalRepaintProc
, (XtPointer
) this);
418 if (GetMDIParentFrame())
420 wxMDIParentFrame
* parentFrame
= GetMDIParentFrame();
422 if (parentFrame
->GetActiveChild() == this)
423 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
424 wxMDIClientWindow
* clientWindow
= parentFrame
->GetClientWindow();
426 // Remove page if still there
428 int i
= clientWindow
->FindPage(this);
432 clientWindow
->RemovePage(i
);
433 clientWindow
->Refresh();
437 // Set the selection to the first remaining page
438 if (clientWindow
->GetPageCount() > 0)
440 wxMDIChildFrame
* child
= (wxMDIChildFrame
*) clientWindow
->GetPage(0);
441 parentFrame
->SetActiveChild(child
);
442 parentFrame
->SetChildMenuBar(child
);
446 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
447 parentFrame
->SetChildMenuBar((wxMDIChildFrame
*) NULL
);
453 // Implementation: intercept and act upon raise and lower commands.
454 void wxMDIChildFrame::OnRaise()
456 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
457 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
458 parentFrame
->SetActiveChild(this);
462 wxActivateEvent
event(wxEVT_ACTIVATE
, false, oldActiveChild
->GetId());
463 event
.SetEventObject( oldActiveChild
);
464 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
467 wxActivateEvent
event(wxEVT_ACTIVATE
, true, this->GetId());
468 event
.SetEventObject( this );
469 this->GetEventHandler()->ProcessEvent(event
);
472 void wxMDIChildFrame::OnLower()
474 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
475 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
477 if (oldActiveChild
== this)
479 wxActivateEvent
event(wxEVT_ACTIVATE
, false, oldActiveChild
->GetId());
480 event
.SetEventObject( oldActiveChild
);
481 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
483 // TODO: unfortunately we don't now know which is the top-most child,
484 // so make the active child NULL.
485 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
489 // Set the client size (i.e. leave the calculation of borders etc.
491 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
493 wxWindow::DoSetClientSize(width
, height
);
496 void wxMDIChildFrame::DoGetClientSize(int* width
, int* height
) const
498 wxWindow::DoGetSize(width
, height
);
501 void wxMDIChildFrame::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
503 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
506 void wxMDIChildFrame::DoGetSize(int* width
, int* height
) const
508 wxWindow::DoGetSize(width
, height
);
511 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
513 wxWindow::DoGetPosition(x
, y
);
516 bool wxMDIChildFrame::Show(bool show
)
518 SetVisibleStatus( show
);
519 return wxWindow::Show(show
);
522 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menuBar
)
524 // Don't create the underlying menubar yet; need to recreate
525 // it every time the child is activated.
526 m_frameMenuBar
= menuBar
;
528 // We make the assumption that if you're setting the menubar,
529 // this is the currently active child.
530 GetMDIParentFrame()->SetChildMenuBar(this);
534 void wxMDIChildFrame::SetIcon(const wxIcon
& icon
)
536 m_icons
= wxIconBundle( icon
);
540 // Not appropriate since there are no icons in
545 void wxMDIChildFrame::SetIcons(const wxIconBundle
& icons
)
550 void wxMDIChildFrame::SetTitle(const wxString
& title
)
552 wxTopLevelWindow::SetTitle( title
);
553 wxMDIClientWindow
* clientWindow
= GetMDIParentFrame()->GetClientWindow();
555 // Remove page if still there
557 int i
= clientWindow
->FindPage(this);
560 clientWindow
->SetPageText(i
, title
);
565 void wxMDIChildFrame::Maximize()
570 void wxMDIChildFrame::Iconize(bool WXUNUSED(iconize
))
575 bool wxMDIChildFrame::IsIconized() const
580 // Is it maximized? Always maximized under Motif, using the
581 // tabbed MDI implementation.
582 bool wxMDIChildFrame::IsMaximized(void) const
587 void wxMDIChildFrame::Restore()
592 void wxMDIChildFrame::Activate()
597 void wxMDIChildFrame::CaptureMouse()
599 wxWindow::CaptureMouse();
602 void wxMDIChildFrame::ReleaseMouse()
604 wxWindow::ReleaseMouse();
607 void wxMDIChildFrame::Raise()
612 void wxMDIChildFrame::Lower(void)
617 void wxMDIChildFrame::DoSetSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
), int WXUNUSED(maxW
), int WXUNUSED(maxH
), int WXUNUSED(incW
), int WXUNUSED(incH
))
623 wxMDIClientWindow::wxMDIClientWindow()
627 wxMDIClientWindow::~wxMDIClientWindow()
629 // By the time this destructor is called, the child frames will have been
630 // deleted and removed from the notebook/client window.
633 m_mainWidget
= (WXWidget
) 0;
636 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
638 SetWindowStyleFlag(style
);
640 // m_windowParent = parent;
641 // m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
643 bool success
= wxNotebook::Create(parent
, wxID_NOTEBOOK_CLIENT_AREA
, wxPoint(0, 0), wxSize(100, 100), 0);
646 wxFont
font(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
654 int wxMDIClientWindow::FindPage(const wxNotebookPage
* page
)
656 for (int i
= GetPageCount() - 1; i
>= 0; --i
)
658 if (GetPage(i
) == page
)
665 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
667 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
670 void wxMDIClientWindow::DoSetClientSize(int width
, int height
)
672 wxWindow::DoSetClientSize(width
, height
);
675 void wxMDIClientWindow::DoGetClientSize(int *width
, int *height
) const
677 wxWindow::DoGetClientSize(width
, height
);
680 void wxMDIClientWindow::DoGetSize(int *width
, int *height
) const
682 wxWindow::DoGetSize(width
, height
);
685 void wxMDIClientWindow::DoGetPosition(int *x
, int *y
) const
687 wxWindow::DoGetPosition(x
, y
);
690 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
692 // Default(); // Default processing: OBSOLETE FUNCTION
696 void wxMDIClientWindow::OnPageChanged(wxNotebookEvent
& event
)
698 // Notify child that it has been activated
699 if (event
.GetOldSelection() != -1)
701 wxMDIChildFrame
* oldChild
= (wxMDIChildFrame
*) GetPage(event
.GetOldSelection());
704 wxActivateEvent
event(wxEVT_ACTIVATE
, false, oldChild
->GetId());
705 event
.SetEventObject( oldChild
);
706 oldChild
->GetEventHandler()->ProcessEvent(event
);
709 if (event
.GetSelection() != -1)
711 wxMDIChildFrame
* activeChild
= (wxMDIChildFrame
*) GetPage(event
.GetSelection());
714 wxActivateEvent
event(wxEVT_ACTIVATE
, true, activeChild
->GetId());
715 event
.SetEventObject( activeChild
);
716 activeChild
->GetEventHandler()->ProcessEvent(event
);
718 if (activeChild
->GetMDIParentFrame())
720 activeChild
->GetMDIParentFrame()->SetActiveChild(activeChild
);
721 activeChild
->GetMDIParentFrame()->SetChildMenuBar(activeChild
);