]>
Commit | Line | Data |
---|---|---|
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 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
13 | #pragma implementation "docmdi.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #if wxUSE_MDI_ARCHITECTURE | |
24 | ||
25 | #include "wx/docmdi.h" | |
26 | ||
27 | /* | |
28 | * Docview MDI parent frame | |
29 | */ | |
30 | ||
31 | IMPLEMENT_CLASS(wxDocMDIParentFrame, wxMDIParentFrame) | |
32 | ||
33 | BEGIN_EVENT_TABLE(wxDocMDIParentFrame, wxMDIParentFrame) | |
34 | EVT_MENU(wxID_EXIT, wxDocMDIParentFrame::OnExit) | |
35 | EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, wxDocMDIParentFrame::OnMRUFile) | |
36 | EVT_CLOSE(wxDocMDIParentFrame::OnCloseWindow) | |
37 | END_EVENT_TABLE() | |
38 | ||
39 | wxDocMDIParentFrame::wxDocMDIParentFrame() | |
40 | { | |
41 | Init(); | |
42 | } | |
43 | ||
44 | wxDocMDIParentFrame::wxDocMDIParentFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, | |
45 | const wxPoint& pos, const wxSize& size, long style, const wxString& name) | |
46 | { | |
47 | Init(); | |
48 | Create(manager, frame, id, title, pos, size, style, name); | |
49 | } | |
50 | ||
51 | bool wxDocMDIParentFrame::Create(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title, | |
52 | const wxPoint& pos, const wxSize& size, long style, const wxString& name) | |
53 | { | |
54 | m_docManager = manager; | |
55 | return wxMDIParentFrame::Create(frame, id, title, pos, size, style, name); | |
56 | } | |
57 | ||
58 | void wxDocMDIParentFrame::OnExit(wxCommandEvent& WXUNUSED(event)) | |
59 | { | |
60 | Close(); | |
61 | } | |
62 | ||
63 | void wxDocMDIParentFrame::Init() | |
64 | { | |
65 | m_docManager = NULL; | |
66 | } | |
67 | ||
68 | void wxDocMDIParentFrame::OnMRUFile(wxCommandEvent& event) | |
69 | { | |
70 | wxString f(m_docManager->GetHistoryFile(event.GetId() - wxID_FILE1)); | |
71 | if (f != wxT("")) | |
72 | (void)m_docManager->CreateDocument(f, wxDOC_SILENT); | |
73 | } | |
74 | ||
75 | // Extend event processing to search the view's event table | |
76 | bool wxDocMDIParentFrame::ProcessEvent(wxEvent& event) | |
77 | { | |
78 | // Try the document manager, then do default processing | |
79 | if (!m_docManager || !m_docManager->ProcessEvent(event)) | |
80 | return wxEvtHandler::ProcessEvent(event); | |
81 | else | |
82 | return true; | |
83 | } | |
84 | ||
85 | void wxDocMDIParentFrame::OnCloseWindow(wxCloseEvent& event) | |
86 | { | |
87 | if (m_docManager->Clear(!event.CanVeto())) | |
88 | { | |
89 | this->Destroy(); | |
90 | } | |
91 | else | |
92 | event.Veto(); | |
93 | } | |
94 | ||
95 | ||
96 | /* | |
97 | * Default document child frame for MDI children | |
98 | */ | |
99 | ||
100 | IMPLEMENT_CLASS(wxDocMDIChildFrame, wxMDIChildFrame) | |
101 | ||
102 | BEGIN_EVENT_TABLE(wxDocMDIChildFrame, wxMDIChildFrame) | |
103 | EVT_ACTIVATE(wxDocMDIChildFrame::OnActivate) | |
104 | EVT_CLOSE(wxDocMDIChildFrame::OnCloseWindow) | |
105 | END_EVENT_TABLE() | |
106 | ||
107 | void wxDocMDIChildFrame::Init() | |
108 | { | |
109 | m_childDocument = (wxDocument*) NULL; | |
110 | m_childView = (wxView*) NULL; | |
111 | } | |
112 | ||
113 | wxDocMDIChildFrame::wxDocMDIChildFrame() | |
114 | { | |
115 | Init(); | |
116 | } | |
117 | ||
118 | wxDocMDIChildFrame::wxDocMDIChildFrame(wxDocument *doc, wxView *view, wxMDIParentFrame *frame, wxWindowID id, | |
119 | const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name) | |
120 | { | |
121 | Init(); | |
122 | Create(doc, view, frame, id, title, pos, size, style, name); | |
123 | } | |
124 | ||
125 | bool wxDocMDIChildFrame::Create(wxDocument *doc, wxView *view, wxMDIParentFrame *frame, wxWindowID id, | |
126 | const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name) | |
127 | { | |
128 | m_childDocument = doc; | |
129 | m_childView = view; | |
130 | if (wxMDIChildFrame::Create(frame, id, title, pos, size, style, name)) | |
131 | { | |
132 | if (view) | |
133 | view->SetFrame(this); | |
134 | return true; | |
135 | } | |
136 | ||
137 | return false; | |
138 | } | |
139 | ||
140 | wxDocMDIChildFrame::~wxDocMDIChildFrame(void) | |
141 | { | |
142 | m_childView = (wxView *) NULL; | |
143 | } | |
144 | ||
145 | // Extend event processing to search the view's event table | |
146 | bool wxDocMDIChildFrame::ProcessEvent(wxEvent& event) | |
147 | { | |
148 | static wxEvent *ActiveEvent = NULL; | |
149 | ||
150 | // Break recursion loops | |
151 | if (ActiveEvent == &event) | |
152 | return false; | |
153 | ||
154 | ActiveEvent = &event; | |
155 | ||
156 | bool ret; | |
157 | if ( !m_childView || ! m_childView->ProcessEvent(event) ) | |
158 | { | |
159 | // Only hand up to the parent if it's a menu command | |
160 | if (!event.IsKindOf(CLASSINFO(wxCommandEvent)) || !GetParent() || !GetParent()->ProcessEvent(event)) | |
161 | ret = wxEvtHandler::ProcessEvent(event); | |
162 | else | |
163 | ret = true; | |
164 | } | |
165 | else | |
166 | ret = true; | |
167 | ||
168 | ActiveEvent = NULL; | |
169 | return ret; | |
170 | } | |
171 | ||
172 | void wxDocMDIChildFrame::OnActivate(wxActivateEvent& event) | |
173 | { | |
174 | wxMDIChildFrame::OnActivate(event); | |
175 | ||
176 | if (event.GetActive() && m_childView) | |
177 | m_childView->Activate(event.GetActive()); | |
178 | } | |
179 | ||
180 | void wxDocMDIChildFrame::OnCloseWindow(wxCloseEvent& event) | |
181 | { | |
182 | // Close view but don't delete the frame while doing so! | |
183 | // ...since it will be deleted by wxWidgets if we return true. | |
184 | if (m_childView) | |
185 | { | |
186 | bool ans = event.CanVeto() | |
187 | ? m_childView->Close(false) // false means don't delete associated window | |
188 | : true; // Must delete. | |
189 | ||
190 | if (ans) | |
191 | { | |
192 | m_childView->Activate(false); | |
193 | delete m_childView; | |
194 | m_childView = (wxView *) NULL; | |
195 | m_childDocument = (wxDocument *) NULL; | |
196 | ||
197 | this->Destroy(); | |
198 | } | |
199 | else | |
200 | event.Veto(); | |
201 | } | |
202 | else | |
203 | event.Veto(); | |
204 | } | |
205 | ||
206 | #endif | |
207 | // wxUSE_DOC_VIEW_ARCHITECTURE | |
208 |