]>
git.saurik.com Git - wxWidgets.git/blob - src/common/docmdi.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Frame classes for MDI document/view applications
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"
19 #if wxUSE_MDI_ARCHITECTURE
21 #include "wx/docmdi.h"
24 * Docview MDI parent frame
27 IMPLEMENT_CLASS(wxDocMDIParentFrame
, wxMDIParentFrame
)
29 BEGIN_EVENT_TABLE(wxDocMDIParentFrame
, wxMDIParentFrame
)
30 EVT_MENU(wxID_EXIT
, wxDocMDIParentFrame::OnExit
)
31 EVT_MENU_RANGE(wxID_FILE1
, wxID_FILE9
, wxDocMDIParentFrame::OnMRUFile
)
32 EVT_CLOSE(wxDocMDIParentFrame::OnCloseWindow
)
35 wxDocMDIParentFrame::wxDocMDIParentFrame()
40 wxDocMDIParentFrame::wxDocMDIParentFrame(wxDocManager
*manager
, wxFrame
*frame
, wxWindowID id
, const wxString
& title
,
41 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
)
44 Create(manager
, frame
, id
, title
, pos
, size
, style
, name
);
47 bool wxDocMDIParentFrame::Create(wxDocManager
*manager
, wxFrame
*frame
, wxWindowID id
, const wxString
& title
,
48 const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
)
50 m_docManager
= manager
;
51 return wxMDIParentFrame::Create(frame
, id
, title
, pos
, size
, style
, name
);
54 void wxDocMDIParentFrame::OnExit(wxCommandEvent
& WXUNUSED(event
))
59 void wxDocMDIParentFrame::Init()
64 void wxDocMDIParentFrame::OnMRUFile(wxCommandEvent
& event
)
66 wxString
f(m_docManager
->GetHistoryFile(event
.GetId() - wxID_FILE1
));
68 (void)m_docManager
->CreateDocument(f
, wxDOC_SILENT
);
71 // Extend event processing to search the view's event table
72 bool wxDocMDIParentFrame::ProcessEvent(wxEvent
& event
)
74 // Try the document manager, then do default processing
75 if (!m_docManager
|| !m_docManager
->ProcessEvent(event
))
76 return wxEvtHandler::ProcessEvent(event
);
81 void wxDocMDIParentFrame::OnCloseWindow(wxCloseEvent
& event
)
83 if (m_docManager
->Clear(!event
.CanVeto()))
93 * Default document child frame for MDI children
96 IMPLEMENT_CLASS(wxDocMDIChildFrame
, wxMDIChildFrame
)
98 BEGIN_EVENT_TABLE(wxDocMDIChildFrame
, wxMDIChildFrame
)
99 EVT_ACTIVATE(wxDocMDIChildFrame::OnActivate
)
100 EVT_CLOSE(wxDocMDIChildFrame::OnCloseWindow
)
103 void wxDocMDIChildFrame::Init()
105 m_childDocument
= (wxDocument
*) NULL
;
106 m_childView
= (wxView
*) NULL
;
109 wxDocMDIChildFrame::wxDocMDIChildFrame()
114 wxDocMDIChildFrame::wxDocMDIChildFrame(wxDocument
*doc
, wxView
*view
, wxMDIParentFrame
*frame
, wxWindowID id
,
115 const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
)
118 Create(doc
, view
, frame
, id
, title
, pos
, size
, style
, name
);
121 bool wxDocMDIChildFrame::Create(wxDocument
*doc
, wxView
*view
, wxMDIParentFrame
*frame
, wxWindowID id
,
122 const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
, long style
, const wxString
& name
)
124 m_childDocument
= doc
;
126 if (wxMDIChildFrame::Create(frame
, id
, title
, pos
, size
, style
, name
))
129 view
->SetFrame(this);
136 wxDocMDIChildFrame::~wxDocMDIChildFrame(void)
138 m_childView
= (wxView
*) NULL
;
141 // Extend event processing to search the view's event table
142 bool wxDocMDIChildFrame::ProcessEvent(wxEvent
& event
)
144 static wxEvent
*ActiveEvent
= NULL
;
146 // Break recursion loops
147 if (ActiveEvent
== &event
)
150 ActiveEvent
= &event
;
153 if ( !m_childView
|| ! m_childView
->ProcessEvent(event
) )
155 // Only hand up to the parent if it's a menu command
156 if (!event
.IsKindOf(CLASSINFO(wxCommandEvent
)) || !GetParent() || !GetParent()->ProcessEvent(event
))
157 ret
= wxEvtHandler::ProcessEvent(event
);
168 void wxDocMDIChildFrame::OnActivate(wxActivateEvent
& event
)
170 wxMDIChildFrame::OnActivate(event
);
172 if (event
.GetActive() && m_childView
)
173 m_childView
->Activate(event
.GetActive());
176 void wxDocMDIChildFrame::OnCloseWindow(wxCloseEvent
& event
)
178 // Close view but don't delete the frame while doing so!
179 // ...since it will be deleted by wxWidgets if we return true.
182 bool ans
= event
.CanVeto()
183 ? m_childView
->Close(false) // false means don't delete associated window
184 : true; // Must delete.
188 m_childView
->Activate(false);
190 m_childView
= (wxView
*) NULL
;
191 m_childDocument
= (wxDocument
*) NULL
;
203 // wxUSE_DOC_VIEW_ARCHITECTURE