]> git.saurik.com Git - wxWidgets.git/blob - src/common/docmdi.cpp
* Fixed two memory leaks.
[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 #ifdef __GNUG__
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 #ifndef WX_PRECOMP
24 #include "wx/defs.h"
25 #endif
26
27 #if USE_DOC_VIEW_ARCHITECTURE
28
29 #ifndef WX_PRECOMP
30 #include "wx/wx.h"
31 #endif
32
33 #include "wx/docmdi.h"
34
35 /*
36 * Docview MDI parent frame
37 */
38
39 IMPLEMENT_CLASS(wxDocMDIParentFrame, wxMDIParentFrame)
40
41 BEGIN_EVENT_TABLE(wxDocMDIParentFrame, wxMDIParentFrame)
42 EVT_MENU(wxID_EXIT, wxDocMDIParentFrame::OnExit)
43 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, wxDocMDIParentFrame::OnMRUFile)
44 END_EVENT_TABLE()
45
46 wxDocMDIParentFrame::wxDocMDIParentFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title,
47 const wxPoint& pos, const wxSize& size, long style, const wxString& name):
48 wxMDIParentFrame(frame, id, title, pos, size, style, name)
49 {
50 m_docManager = manager;
51 }
52
53 void wxDocMDIParentFrame::OnExit(wxCommandEvent& WXUNUSED(event))
54 {
55 Close();
56 }
57
58 void wxDocMDIParentFrame::OnMRUFile(wxCommandEvent& event)
59 {
60 wxString f(m_docManager->GetHistoryFile(event.GetSelection() - wxID_FILE1));
61 if (f != "")
62 (void)m_docManager->CreateDocument(f, wxDOC_SILENT);
63 }
64
65 // Extend event processing to search the view's event table
66 bool wxDocMDIParentFrame::ProcessEvent(wxEvent& event)
67 {
68 // Try the document manager, then do default processing
69 if (!m_docManager || !m_docManager->ProcessEvent(event))
70 return wxEvtHandler::ProcessEvent(event);
71 else
72 return TRUE;
73 }
74
75 // Define the behaviour for the frame closing
76 // - must delete all frames except for the main one.
77 bool wxDocMDIParentFrame::OnClose(void)
78 {
79 return m_docManager->Clear(FALSE);
80 }
81
82
83 /*
84 * Default document child frame for MDI children
85 */
86
87 IMPLEMENT_CLASS(wxDocMDIChildFrame, wxMDIChildFrame)
88
89 BEGIN_EVENT_TABLE(wxDocMDIChildFrame, wxMDIChildFrame)
90 EVT_ACTIVATE(wxDocMDIChildFrame::OnActivate)
91 END_EVENT_TABLE()
92
93 wxDocMDIChildFrame::wxDocMDIChildFrame(wxDocument *doc, wxView *view, wxMDIParentFrame *frame, wxWindowID id,
94 const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name):
95 wxMDIChildFrame(frame, id, title, pos, size, style, name)
96 {
97 m_childDocument = doc;
98 m_childView = view;
99 if (view)
100 view->SetFrame(this);
101 }
102
103 wxDocMDIChildFrame::~wxDocMDIChildFrame(void)
104 {
105 m_childView = (wxView *) NULL;
106 }
107
108 // Extend event processing to search the view's event table
109 bool wxDocMDIChildFrame::ProcessEvent(wxEvent& event)
110 {
111 if (m_childView)
112 m_childView->Activate(TRUE);
113
114 if ( !m_childView || ! m_childView->ProcessEvent(event) )
115 {
116 // Only hand up to the parent if it's a menu command
117 if (!event.IsKindOf(CLASSINFO(wxCommandEvent)) || !GetParent() || !GetParent()->ProcessEvent(event))
118 return wxEvtHandler::ProcessEvent(event);
119 else
120 return TRUE;
121 }
122 else
123 return TRUE;
124 }
125
126 void wxDocMDIChildFrame::OnActivate(wxActivateEvent& event)
127 {
128 wxMDIChildFrame::OnActivate(event);
129
130 if (m_childView)
131 m_childView->Activate(event.GetActive());
132 }
133
134 bool wxDocMDIChildFrame::OnClose(void)
135 {
136 // Close view but don't delete the frame while doing so!
137 // ...since it will be deleted by wxWindows if we return TRUE.
138 if (m_childView)
139 {
140 bool ans = m_childView->Close(FALSE); // FALSE means don't delete associated window
141 if (ans)
142 {
143 m_childView->Activate(FALSE);
144 delete m_childView;
145 m_childView = (wxView *) NULL;
146 m_childDocument = (wxDocument *) NULL;
147 }
148
149 return ans;
150 }
151 else return TRUE;
152 }
153
154 #endif
155 // USE_DOC_VIEW_ARCHITECTURE
156