]> git.saurik.com Git - wxWidgets.git/blob - src/common/docmdi.cpp
applying patch, fixes #10523
[wxWidgets.git] / src / common / docmdi.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: docmdi.cpp
3 // Purpose: Frame classes for MDI document/view applications
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #if wxUSE_MDI_ARCHITECTURE
20
21 #include "wx/docmdi.h"
22
23 /*
24 * Docview MDI parent frame
25 */
26
27 IMPLEMENT_CLASS(wxDocMDIParentFrame, wxMDIParentFrame)
28
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)
33 END_EVENT_TABLE()
34
35 wxDocMDIParentFrame::wxDocMDIParentFrame()
36 {
37 Init();
38 }
39
40 wxDocMDIParentFrame::wxDocMDIParentFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title,
41 const wxPoint& pos, const wxSize& size, long style, const wxString& name)
42 {
43 Init();
44 Create(manager, frame, id, title, pos, size, style, name);
45 }
46
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)
49 {
50 m_docManager = manager;
51 return wxMDIParentFrame::Create(frame, id, title, pos, size, style, name);
52 }
53
54 void wxDocMDIParentFrame::OnExit(wxCommandEvent& WXUNUSED(event))
55 {
56 Close();
57 }
58
59 void wxDocMDIParentFrame::Init()
60 {
61 m_docManager = NULL;
62 }
63
64 void wxDocMDIParentFrame::OnMRUFile(wxCommandEvent& event)
65 {
66 wxString f(m_docManager->GetHistoryFile(event.GetId() - wxID_FILE1));
67 if (!f.empty())
68 (void)m_docManager->CreateDocument(f, wxDOC_SILENT);
69 }
70
71 bool wxDocMDIParentFrame::TryBefore(wxEvent& event)
72 {
73 if ( m_docManager && m_docManager->ProcessEventHere(event) )
74 return true;
75
76 return wxMDIParentFrame::TryBefore(event);
77 }
78
79 void wxDocMDIParentFrame::OnCloseWindow(wxCloseEvent& event)
80 {
81 if (m_docManager->Clear(!event.CanVeto()))
82 {
83 this->Destroy();
84 }
85 else
86 event.Veto();
87 }
88
89
90 /*
91 * Default document child frame for MDI children
92 */
93
94 IMPLEMENT_CLASS(wxDocMDIChildFrame, wxMDIChildFrame)
95
96 BEGIN_EVENT_TABLE(wxDocMDIChildFrame, wxMDIChildFrame)
97 EVT_ACTIVATE(wxDocMDIChildFrame::OnActivate)
98 EVT_CLOSE(wxDocMDIChildFrame::OnCloseWindow)
99 END_EVENT_TABLE()
100
101 void wxDocMDIChildFrame::Init()
102 {
103 m_childDocument = NULL;
104 m_childView = NULL;
105 }
106
107 wxDocMDIChildFrame::wxDocMDIChildFrame()
108 {
109 Init();
110 }
111
112 wxDocMDIChildFrame::wxDocMDIChildFrame(wxDocument *doc, wxView *view, wxMDIParentFrame *frame, wxWindowID id,
113 const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
114 {
115 Init();
116 Create(doc, view, frame, id, title, pos, size, style, name);
117 }
118
119 bool wxDocMDIChildFrame::Create(wxDocument *doc, wxView *view, wxMDIParentFrame *frame, wxWindowID id,
120 const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
121 {
122 m_childDocument = doc;
123 m_childView = view;
124 if (wxMDIChildFrame::Create(frame, id, title, pos, size, style, name))
125 {
126 if (view)
127 view->SetFrame(this);
128 return true;
129 }
130
131 return false;
132 }
133
134 wxDocMDIChildFrame::~wxDocMDIChildFrame(void)
135 {
136 m_childView = NULL;
137 }
138
139 bool wxDocMDIChildFrame::TryBefore(wxEvent& event)
140 {
141 if ( m_childView && m_childView->ProcessEventHere(event) )
142 return true;
143
144 return wxMDIChildFrame::TryBefore(event);
145 }
146
147 void wxDocMDIChildFrame::OnActivate(wxActivateEvent& event)
148 {
149 wxMDIChildFrame::OnActivate(event);
150
151 if (event.GetActive() && m_childView)
152 m_childView->Activate(event.GetActive());
153 }
154
155 void wxDocMDIChildFrame::OnCloseWindow(wxCloseEvent& event)
156 {
157 // Close view but don't delete the frame while doing so!
158 // ...since it will be deleted by wxWidgets if we return true.
159 if (m_childView)
160 {
161 bool ans = event.CanVeto()
162 ? m_childView->Close(false) // false means don't delete associated window
163 : true; // Must delete.
164
165 if (ans)
166 {
167 m_childView->Activate(false);
168 delete m_childView;
169 m_childView = NULL;
170 m_childDocument = NULL;
171
172 this->Destroy();
173 }
174 else
175 event.Veto();
176 }
177 else
178 event.Veto();
179 }
180
181 #endif
182 // wxUSE_DOC_VIEW_ARCHITECTURE
183