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 #pragma message disable nosimpint
24 #include <Xm/BulletinB.h>
27 #include <Xm/RowColumn.h>
28 #include <Xm/CascadeBG.h>
30 #include <Xm/PushBG.h>
31 #include <Xm/AtomMgr.h>
32 #include <Xm/Protocols.h>
34 #pragma message enable nosimpint
37 #include "wx/motif/private.h"
39 extern wxList wxModelessWindows
;
41 // Implemented in frame.cpp
42 extern void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
43 XmAnyCallbackStruct
*cbs
);
45 #define wxID_NOTEBOOK_CLIENT_AREA wxID_HIGHEST + 100
47 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
48 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
49 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxNotebook
)
51 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
52 EVT_SIZE(wxMDIParentFrame::OnSize
)
53 EVT_ACTIVATE(wxMDIParentFrame::OnActivate
)
54 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
55 EVT_MENU_HIGHLIGHT_ALL(wxMDIParentFrame::OnMenuHighlight
)
58 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxNotebook
)
59 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
60 EVT_NOTEBOOK_PAGE_CHANGED(wxID_NOTEBOOK_CLIENT_AREA
, wxMDIClientWindow::OnPageChanged
)
66 wxMDIParentFrame::wxMDIParentFrame()
68 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
69 m_activeChild
= (wxMDIChildFrame
*) NULL
;
70 m_activeMenuBar
= (wxMenuBar
*) NULL
;
73 bool wxMDIParentFrame::Create(wxWindow
*parent
,
75 const wxString
& title
,
81 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
82 m_activeChild
= (wxMDIChildFrame
*) NULL
;
83 m_activeMenuBar
= (wxMenuBar
*) NULL
;
85 bool success
= wxFrame::Create(parent
, id
, title
, pos
, size
, style
, name
);
88 // TODO: app cannot override OnCreateClient since
89 // wxMDIParentFrame::OnCreateClient will still be called
90 // (we're in the constructor). How to resolve?
92 m_clientWindow
= OnCreateClient();
94 // Uses own style for client style
95 m_clientWindow
->CreateClient(this, GetWindowStyleFlag());
98 GetClientSize(& w
, & h
);
99 m_clientWindow
->SetSize(0, 0, w
, h
);
106 wxMDIParentFrame::~wxMDIParentFrame()
108 // Make sure we delete the client window last of all
109 RemoveChild(m_clientWindow
);
113 delete m_clientWindow
;
114 m_clientWindow
= NULL
;
117 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
119 m_frameMenuBar
= menu_bar
;
121 SetChildMenuBar((wxMDIChildFrame
*) NULL
);
124 void wxMDIParentFrame::OnSize(wxSizeEvent
& WXUNUSED(event
))
126 #if wxUSE_CONSTRAINTS
133 GetClientSize(&width
, &height
);
135 if ( GetClientWindow() )
136 GetClientWindow()->SetSize(x
, y
, width
, height
);
139 void wxMDIParentFrame::DoGetClientSize(int *width
, int *height
) const
141 wxFrame::DoGetClientSize(width
, height
);
144 void wxMDIParentFrame::OnActivate(wxActivateEvent
& WXUNUSED(event
))
149 // Returns the active MDI child window
150 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
152 return m_activeChild
;
155 // Create the client window class (don't Create the window,
156 // just return a new class)
157 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
159 return new wxMDIClientWindow
;
162 // Set the child's menu into the parent frame
163 void wxMDIParentFrame::SetChildMenuBar(wxMDIChildFrame
* child
)
165 wxMenuBar
* oldMenuBar
= m_activeMenuBar
;
167 if (child
== (wxMDIChildFrame
*) NULL
) // No child: use parent frame
169 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar
))
171 // if (m_activeMenuBar)
172 // m_activeMenuBar->DestroyMenuBar();
174 m_activeMenuBar
= GetMenuBar();
175 m_activeMenuBar
->CreateMenuBar(this);
177 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
178 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
180 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
181 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
185 else if (child
->GetMenuBar() == (wxMenuBar
*) NULL
) // No child menu bar: use parent frame
187 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar
))
189 // if (m_activeMenuBar)
190 // m_activeMenuBar->DestroyMenuBar();
191 m_activeMenuBar
= GetMenuBar();
192 m_activeMenuBar
->CreateMenuBar(this);
194 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
195 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
197 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
198 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
201 else // The child has a menubar
203 if (child
->GetMenuBar() != m_activeMenuBar
)
205 // if (m_activeMenuBar)
206 // m_activeMenuBar->DestroyMenuBar();
208 m_activeMenuBar
= child
->GetMenuBar();
209 m_activeMenuBar
->CreateMenuBar(this);
211 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
212 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
214 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
215 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
220 // Redirect events to active child first
221 bool wxMDIParentFrame::ProcessEvent(wxEvent
& event
)
223 // Stops the same event being processed repeatedly
224 static wxEventType inEvent
= wxEVT_NULL
;
225 if (inEvent
== event
.GetEventType())
228 inEvent
= event
.GetEventType();
231 if (m_activeChild
&& event
.IsKindOf(CLASSINFO(wxCommandEvent
)))
233 res
= m_activeChild
->GetEventHandler()->ProcessEvent(event
);
237 res
= GetEventHandler()->wxEvtHandler::ProcessEvent(event
);
239 inEvent
= wxEVT_NULL
;
244 void wxMDIParentFrame::DoSetSize(int x
, int y
,
245 int width
, int height
,
248 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
251 void wxMDIParentFrame::DoSetClientSize(int width
, int height
)
253 wxWindow::DoSetClientSize(width
, height
);
256 // Responds to colour changes, and passes event on to children.
257 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
261 // Propagate the event to the non-top-level children
262 wxFrame::OnSysColourChanged(event
);
266 void wxMDIParentFrame::Cascade()
271 void wxMDIParentFrame::Tile()
276 void wxMDIParentFrame::ArrangeIcons()
281 void wxMDIParentFrame::ActivateNext()
286 void wxMDIParentFrame::ActivatePrevious()
291 // Default menu selection behaviour - display a help string
292 void wxMDIParentFrame::OnMenuHighlight(wxMenuEvent
& event
)
296 if (event
.GetMenuId() == -1)
300 wxMenuBar
*menuBar
= (wxMenuBar
*) NULL
;
301 if (GetActiveChild())
302 menuBar
= GetActiveChild()->GetMenuBar();
304 menuBar
= GetMenuBar();
307 wxString
helpString(menuBar
->GetHelpString(event
.GetMenuId()));
308 if (helpString
!= "")
309 SetStatusText(helpString
);
317 wxMDIChildFrame::wxMDIChildFrame()
319 m_mdiParentFrame
= (wxMDIParentFrame
*) NULL
;
322 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
324 const wxString
& title
,
328 const wxString
& name
)
331 SetWindowStyleFlag(style
);
333 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
334 m_foregroundColour
= *wxBLACK
;
335 m_font
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
340 m_windowId
= (int)NewControlId();
342 wxMDIClientWindow
* clientWindow
= parent
->GetClientWindow();
344 wxASSERT_MSG( (clientWindow
!= (wxWindow
*) NULL
), "Missing MDI client window.");
346 if (clientWindow
) clientWindow
->AddChild(this);
348 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
->GetEventHandler()->ProcessEvent(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);
388 SetCanAddEventHandler(TRUE
);
389 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
391 ChangeBackgroundColour();
393 XtManageChild((Widget
) m_mainWidget
);
397 clientWindow
->AddPage(this, title
, TRUE
);
398 clientWindow
->Refresh();
400 // Positions the toolbar and status bar -- but we don't have any.
403 wxModelessWindows
.Append(this);
408 wxMDIChildFrame::~wxMDIChildFrame()
411 XtRemoveEventHandler((Widget
) m_mainWidget
, ExposureMask
,FALSE
,
412 wxUniversalRepaintProc
, (XtPointer
) this);
414 if (GetMDIParentFrame())
416 wxMDIParentFrame
* parentFrame
= GetMDIParentFrame();
418 if (parentFrame
->GetActiveChild() == this)
419 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
420 wxMDIClientWindow
* clientWindow
= parentFrame
->GetClientWindow();
422 // Remove page if still there
423 if (clientWindow
->RemovePage(this))
424 clientWindow
->Refresh();
426 // Set the selection to the first remaining page
427 if (clientWindow
->GetPageCount() > 0)
429 wxMDIChildFrame
* child
= (wxMDIChildFrame
*) clientWindow
->GetPage(0);
430 parentFrame
->SetActiveChild(child
);
431 parentFrame
->SetChildMenuBar(child
);
435 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
436 parentFrame
->SetChildMenuBar((wxMDIChildFrame
*) NULL
);
442 // Implementation: intercept and act upon raise and lower commands.
443 void wxMDIChildFrame::OnRaise()
445 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
446 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
447 parentFrame
->SetActiveChild(this);
451 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
452 event
.SetEventObject( oldActiveChild
);
453 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
456 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, this->GetId());
457 event
.SetEventObject( this );
458 this->GetEventHandler()->ProcessEvent(event
);
461 void wxMDIChildFrame::OnLower()
463 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
464 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
466 if (oldActiveChild
== this)
468 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
469 event
.SetEventObject( oldActiveChild
);
470 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
472 // TODO: unfortunately we don't now know which is the top-most child,
473 // so make the active child NULL.
474 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
478 // Set the client size (i.e. leave the calculation of borders etc.
480 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
482 wxWindow::DoSetClientSize(width
, height
);
485 void wxMDIChildFrame::DoGetClientSize(int* width
, int* height
) const
487 wxWindow::DoGetSize(width
, height
);
490 void wxMDIChildFrame::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
492 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
495 void wxMDIChildFrame::DoGetSize(int* width
, int* height
) const
497 wxWindow::DoGetSize(width
, height
);
500 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
502 wxWindow::DoGetPosition(x
, y
);
505 bool wxMDIChildFrame::Show(bool show
)
507 m_visibleStatus
= show
; /* show-&-hide fix */
508 return wxWindow::Show(show
);
511 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menuBar
)
513 // Don't create the underlying menubar yet; need to recreate
514 // it every time the child is activated.
515 m_frameMenuBar
= menuBar
;
517 // We make the assumption that if you're setting the menubar,
518 // this is the currently active child.
519 GetMDIParentFrame()->SetChildMenuBar(this);
523 void wxMDIChildFrame::SetIcon(const wxIcon
& icon
)
528 // Not appropriate since there are no icons in
533 void wxMDIChildFrame::SetTitle(const wxString
& title
)
536 wxMDIClientWindow
* clientWindow
= GetMDIParentFrame()->GetClientWindow();
537 int pageNo
= clientWindow
->FindPagePosition(this);
539 clientWindow
->SetPageText(pageNo
, title
);
543 void wxMDIChildFrame::Maximize()
548 void wxMDIChildFrame::Iconize(bool WXUNUSED(iconize
))
553 bool wxMDIChildFrame::IsIconized() const
558 // Is it maximized? Always maximized under Motif, using the
559 // tabbed MDI implementation.
560 bool wxMDIChildFrame::IsMaximized(void) const
565 void wxMDIChildFrame::Restore()
570 void wxMDIChildFrame::Activate()
575 void wxMDIChildFrame::CaptureMouse()
577 wxWindow::CaptureMouse();
580 void wxMDIChildFrame::ReleaseMouse()
582 wxWindow::ReleaseMouse();
585 void wxMDIChildFrame::Raise()
590 void wxMDIChildFrame::Lower(void)
595 void wxMDIChildFrame::SetSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
), int WXUNUSED(maxW
), int WXUNUSED(maxH
), int WXUNUSED(incW
), int WXUNUSED(incH
))
601 wxMDIClientWindow::wxMDIClientWindow()
605 wxMDIClientWindow::~wxMDIClientWindow()
607 // By the time this destructor is called, the child frames will have been
608 // deleted and removed from the notebook/client window.
611 m_mainWidget
= (WXWidget
) 0;
614 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
616 SetWindowStyleFlag(style
);
618 // m_windowParent = parent;
619 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE);
621 bool success
= wxNotebook::Create(parent
, wxID_NOTEBOOK_CLIENT_AREA
, wxPoint(0, 0), wxSize(100, 100), 0);
624 wxFont
font(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
625 wxFont
selFont(10, wxSWISS
, wxNORMAL
, wxBOLD
);
626 GetTabView()->SetTabFont(font
);
627 GetTabView()->SetSelectedTabFont(selFont
);
628 GetTabView()->SetTabSize(120, 18);
629 GetTabView()->SetTabSelectionHeight(20);
636 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
638 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
641 void wxMDIClientWindow::DoSetClientSize(int width
, int height
)
643 wxWindow::DoSetClientSize(width
, height
);
646 void wxMDIClientWindow::DoGetClientSize(int *width
, int *height
) const
648 wxWindow::DoGetClientSize(width
, height
);
651 void wxMDIClientWindow::DoGetSize(int *width
, int *height
) const
653 wxWindow::DoGetSize(width
, height
);
656 void wxMDIClientWindow::DoGetPosition(int *x
, int *y
) const
658 wxWindow::DoGetPosition(x
, y
);
661 // Explicitly call default scroll behaviour
662 void wxMDIClientWindow::OnScroll(wxScrollEvent
& WXUNUSED(event
))
664 Default(); // Default processing
667 void wxMDIClientWindow::OnPageChanged(wxNotebookEvent
& event
)
669 // Notify child that it has been activated
670 if (event
.GetOldSelection() != -1)
672 wxMDIChildFrame
* oldChild
= (wxMDIChildFrame
*) GetPage(event
.GetOldSelection());
675 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldChild
->GetId());
676 event
.SetEventObject( oldChild
);
677 oldChild
->GetEventHandler()->ProcessEvent(event
);
680 if (event
.GetSelection() != -1)
682 wxMDIChildFrame
* activeChild
= (wxMDIChildFrame
*) GetPage(event
.GetSelection());
685 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, activeChild
->GetId());
686 event
.SetEventObject( activeChild
);
687 activeChild
->GetEventHandler()->ProcessEvent(event
);
689 if (activeChild
->GetMDIParentFrame())
691 activeChild
->GetMDIParentFrame()->SetActiveChild(activeChild
);
692 activeChild
->GetMDIParentFrame()->SetChildMenuBar(activeChild
);