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/DrawingA.h>
29 #include <Xm/AtomMgr.h>
30 #include <Xm/Protocols.h>
32 #include "wx/motif/private.h"
34 extern wxList wxModelessWindows
;
36 // Implemented in frame.cpp
37 extern void wxFrameFocusProc(Widget workArea
, XtPointer clientData
,
38 XmAnyCallbackStruct
*cbs
);
41 extern void wxCanvasRepaintProc (Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
42 extern void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
44 #define wxID_NOTEBOOK_CLIENT_AREA wxID_HIGHEST + 100
46 #if !USE_SHARED_LIBRARY
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
)
57 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxNotebook
)
58 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
59 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 // Get size *available for subwindows* i.e. excluding menu bar.
118 void wxMDIParentFrame::GetClientSize(int *x
, int *y
) const
120 wxFrame::GetClientSize(x
, y
);
123 void wxMDIParentFrame::SetMenuBar(wxMenuBar
*menu_bar
)
125 m_frameMenuBar
= menu_bar
;
127 SetChildMenuBar((wxMDIChildFrame
*) NULL
);
130 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
132 #if wxUSE_CONSTRAINTS
139 GetClientSize(&width
, &height
);
141 if ( GetClientWindow() )
142 GetClientWindow()->SetSize(x
, y
, width
, height
);
145 void wxMDIParentFrame::OnActivate(wxActivateEvent
& event
)
150 // Returns the active MDI child window
151 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
153 return m_activeChild
;
156 // Create the client window class (don't Create the window,
157 // just return a new class)
158 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
160 return new wxMDIClientWindow
;
163 // Set the child's menu into the parent frame
164 void wxMDIParentFrame::SetChildMenuBar(wxMDIChildFrame
* child
)
166 wxMenuBar
* oldMenuBar
= m_activeMenuBar
;
168 if (child
== (wxMDIChildFrame
*) NULL
) // No child: use parent frame
170 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar
))
172 // if (m_activeMenuBar)
173 // m_activeMenuBar->DestroyMenuBar();
175 m_activeMenuBar
= GetMenuBar();
176 m_activeMenuBar
->CreateMenuBar(this);
178 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
179 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
181 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
182 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
186 else if (child
->GetMenuBar() == (wxMenuBar
*) NULL
) // No child menu bar: use parent frame
188 if (GetMenuBar() && (GetMenuBar() != m_activeMenuBar
))
190 // if (m_activeMenuBar)
191 // m_activeMenuBar->DestroyMenuBar();
192 m_activeMenuBar
= GetMenuBar();
193 m_activeMenuBar
->CreateMenuBar(this);
195 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
196 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
198 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
199 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
202 else // The child has a menubar
204 if (child
->GetMenuBar() != m_activeMenuBar
)
206 // if (m_activeMenuBar)
207 // m_activeMenuBar->DestroyMenuBar();
209 m_activeMenuBar
= child
->GetMenuBar();
210 m_activeMenuBar
->CreateMenuBar(this);
212 if (oldMenuBar && XtIsManaged((Widget) oldMenuBar->GetMainWidget()))
213 XtUnmanageChild((Widget) oldMenuBar->GetMainWidget());
215 if (oldMenuBar
&& oldMenuBar
->GetMainWidget())
216 XtUnmapWidget((Widget
) oldMenuBar
->GetMainWidget());
221 // Redirect events to active child first
222 bool wxMDIParentFrame::ProcessEvent(wxEvent
& event
)
224 // Stops the same event being processed repeatedly
225 static wxEventType inEvent
= wxEVT_NULL
;
226 if (inEvent
== event
.GetEventType())
229 inEvent
= event
.GetEventType();
232 if (m_activeChild
&& event
.IsKindOf(CLASSINFO(wxCommandEvent
)))
234 res
= m_activeChild
->GetEventHandler()->ProcessEvent(event
);
238 res
= GetEventHandler()->wxEvtHandler::ProcessEvent(event
);
240 inEvent
= wxEVT_NULL
;
245 // Responds to colour changes, and passes event on to children.
246 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
250 // Propagate the event to the non-top-level children
251 wxFrame::OnSysColourChanged(event
);
255 void wxMDIParentFrame::Cascade()
260 void wxMDIParentFrame::Tile()
265 void wxMDIParentFrame::ArrangeIcons()
270 void wxMDIParentFrame::ActivateNext()
275 void wxMDIParentFrame::ActivatePrevious()
282 wxMDIChildFrame::wxMDIChildFrame()
284 m_mdiParentFrame
= (wxMDIParentFrame
*) NULL
;
287 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
289 const wxString
& title
,
293 const wxString
& name
)
297 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
298 m_foregroundColour
= *wxBLACK
;
299 m_windowFont
= wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
304 m_windowId
= (int)NewControlId();
306 wxMDIClientWindow
* clientWindow
= parent
->GetClientWindow();
308 wxASSERT_MSG( (clientWindow
!= (wxWindow
*) NULL
), "Missing MDI client window.");
310 if (clientWindow
) clientWindow
->AddChild(this);
312 SetMDIParentFrame(parent
);
314 int x
= pos
.x
; int y
= pos
.y
;
315 int width
= size
.x
; int height
= size
.y
;
317 width
= 200; // TODO: give reasonable default
319 height
= 200; // TODO: give reasonable default
321 // We're deactivating the old child
322 wxMDIChildFrame
* oldActiveChild
= parent
->GetActiveChild();
325 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
326 event
.SetEventObject( oldActiveChild
);
327 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
330 // This is the currently active child
331 parent
->SetActiveChild((wxMDIChildFrame
*) this);
333 // This time we'll try a bog-standard bulletin board for
334 // the 'frame'. A main window doesn't seem to work.
336 m_mainWidget
= (WXWidget
) XtVaCreateWidget("client",
337 xmBulletinBoardWidgetClass
, (Widget
) clientWindow
->GetTopWidget(),
341 XmNrightAttachment, XmATTACH_FORM,
342 XmNleftAttachment, XmATTACH_FORM,
343 XmNtopAttachment, XmATTACH_FORM,
344 XmNbottomAttachment, XmATTACH_FORM,
346 XmNresizePolicy
, XmRESIZE_NONE
,
349 XtAddCallback ((Widget
) m_mainWidget
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
351 SetCanAddEventHandler(TRUE
);
352 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
354 ChangeBackgroundColour();
356 XtManageChild((Widget
) m_mainWidget
);
360 clientWindow
->AddPage(this, title
, TRUE
);
361 clientWindow
->Refresh();
363 // Positions the toolbar and status bar -- but we don't have any.
366 wxModelessWindows
.Append(this);
371 wxMDIChildFrame::~wxMDIChildFrame()
373 XtRemoveCallback ((Widget
) m_mainWidget
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
375 if (GetMDIParentFrame())
377 wxMDIParentFrame
* parentFrame
= GetMDIParentFrame();
379 if (parentFrame
->GetActiveChild() == this)
380 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
381 wxMDIClientWindow
* clientWindow
= parentFrame
->GetClientWindow();
383 // Remove page if still there
384 if (clientWindow
->RemovePage(this))
385 clientWindow
->Refresh();
387 // Set the selection to the first remaining page
388 if (clientWindow
->GetPageCount() > 0)
390 wxMDIChildFrame
* child
= (wxMDIChildFrame
*) clientWindow
->GetPage(0);
391 parentFrame
->SetActiveChild(child
);
392 parentFrame
->SetChildMenuBar(child
);
396 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
397 parentFrame
->SetChildMenuBar((wxMDIChildFrame
*) NULL
);
403 // Implementation: intercept and act upon raise and lower commands.
404 void wxMDIChildFrame::OnRaise()
406 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
407 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
408 parentFrame
->SetActiveChild(this);
412 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
413 event
.SetEventObject( oldActiveChild
);
414 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
417 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, this->GetId());
418 event
.SetEventObject( this );
419 this->GetEventHandler()->ProcessEvent(event
);
422 void wxMDIChildFrame::OnLower()
424 wxMDIParentFrame
* parentFrame
= (wxMDIParentFrame
*) GetParent() ;
425 wxMDIChildFrame
* oldActiveChild
= parentFrame
->GetActiveChild();
427 if (oldActiveChild
== this)
429 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldActiveChild
->GetId());
430 event
.SetEventObject( oldActiveChild
);
431 oldActiveChild
->GetEventHandler()->ProcessEvent(event
);
433 // TODO: unfortunately we don't now know which is the top-most child,
434 // so make the active child NULL.
435 parentFrame
->SetActiveChild((wxMDIChildFrame
*) NULL
);
439 // Set the client size (i.e. leave the calculation of borders etc.
441 void wxMDIChildFrame::SetClientSize(int width
, int height
)
443 wxWindow::SetClientSize(width
, height
);
446 void wxMDIChildFrame::GetClientSize(int* width
, int* height
) const
448 wxWindow::GetSize(width
, height
);
451 void wxMDIChildFrame::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
453 wxWindow::SetSize(x
, y
, width
, height
, sizeFlags
);
456 void wxMDIChildFrame::GetSize(int* width
, int* height
) const
458 wxWindow::GetSize(width
, height
);
461 void wxMDIChildFrame::GetPosition(int *x
, int *y
) const
463 wxWindow::GetPosition(x
, y
);
466 bool wxMDIChildFrame::Show(bool show
)
468 m_visibleStatus
= show
; /* show-&-hide fix */
469 return wxWindow::Show(show
);
472 void wxMDIChildFrame::SetMenuBar(wxMenuBar
*menuBar
)
474 // Don't create the underlying menubar yet; need to recreate
475 // it every time the child is activated.
476 m_frameMenuBar
= menuBar
;
478 // We make the assumption that if you're setting the menubar,
479 // this is the currently active child.
480 GetMDIParentFrame()->SetChildMenuBar(this);
484 void wxMDIChildFrame::SetIcon(const wxIcon
& icon
)
489 // Not appropriate since there are no icons in
494 void wxMDIChildFrame::SetTitle(const wxString
& title
)
497 wxMDIClientWindow
* clientWindow
= GetMDIParentFrame()->GetClientWindow();
498 int pageNo
= clientWindow
->FindPagePosition(this);
500 clientWindow
->SetPageText(pageNo
, title
);
504 void wxMDIChildFrame::Maximize()
509 void wxMDIChildFrame::Iconize(bool iconize
)
514 bool wxMDIChildFrame::IsIconized() const
519 // Is it maximized? Always maximized under Motif, using the
520 // tabbed MDI implementation.
521 bool wxMDIChildFrame::IsMaximized(void) const
526 void wxMDIChildFrame::Restore()
531 void wxMDIChildFrame::Activate()
536 void wxMDIChildFrame::CaptureMouse()
538 wxWindow::CaptureMouse();
541 void wxMDIChildFrame::ReleaseMouse()
543 wxWindow::ReleaseMouse();
546 void wxMDIChildFrame::Raise()
551 void wxMDIChildFrame::Lower(void)
556 void wxMDIChildFrame::SetSizeHints(int WXUNUSED(minW
), int WXUNUSED(minH
), int WXUNUSED(maxW
), int WXUNUSED(maxH
), int WXUNUSED(incW
), int WXUNUSED(incH
))
562 wxMDIClientWindow::wxMDIClientWindow()
566 wxMDIClientWindow::~wxMDIClientWindow()
568 // By the time this destructor is called, the child frames will have been
569 // deleted and removed from the notebook/client window.
572 m_mainWidget
= (WXWidget
) 0;
575 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
577 // m_windowParent = parent;
578 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE);
580 bool success
= wxNotebook::Create(parent
, wxID_NOTEBOOK_CLIENT_AREA
, wxPoint(0, 0), wxSize(100, 100), 0);
583 wxFont
font(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
584 wxFont
selFont(10, wxSWISS
, wxNORMAL
, wxBOLD
);
585 GetTabView()->SetTabFont(font
);
586 GetTabView()->SetSelectedTabFont(selFont
);
587 GetTabView()->SetTabSize(120, 18);
588 GetTabView()->SetTabSelectionHeight(20);
595 void wxMDIClientWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
597 wxWindow::SetSize(x
, y
, width
, height
, sizeFlags
);
600 void wxMDIClientWindow::SetClientSize(int width
, int height
)
602 wxWindow::SetClientSize(width
, height
);
605 void wxMDIClientWindow::GetClientSize(int *width
, int *height
) const
607 wxWindow::GetClientSize(width
, height
);
610 void wxMDIClientWindow::GetSize(int *width
, int *height
) const
612 wxWindow::GetSize(width
, height
);
615 void wxMDIClientWindow::GetPosition(int *x
, int *y
) const
617 wxWindow::GetPosition(x
, y
);
620 // Explicitly call default scroll behaviour
621 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
623 Default(); // Default processing
626 void wxMDIClientWindow::OnPageChanged(wxNotebookEvent
& event
)
628 // Notify child that it has been activated
629 if (event
.GetOldSelection() != -1)
631 wxMDIChildFrame
* oldChild
= (wxMDIChildFrame
*) GetPage(event
.GetOldSelection());
634 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, oldChild
->GetId());
635 event
.SetEventObject( oldChild
);
636 oldChild
->GetEventHandler()->ProcessEvent(event
);
639 if (event
.GetSelection() != -1)
641 wxMDIChildFrame
* activeChild
= (wxMDIChildFrame
*) GetPage(event
.GetSelection());
644 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, activeChild
->GetId());
645 event
.SetEventObject( activeChild
);
646 activeChild
->GetEventHandler()->ProcessEvent(event
);
648 if (activeChild
->GetMDIParentFrame())
650 activeChild
->GetMDIParentFrame()->SetActiveChild(activeChild
);
651 activeChild
->GetMDIParentFrame()->SetChildMenuBar(activeChild
);