USE_xxx constants renamed to wxUSE_xxx. This is an incompatible change, you
[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 wxUSE_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 || ! m_childView->ProcessEvent(event) )
112 {
113 // Only hand up to the parent if it's a menu command
114 if (!event.IsKindOf(CLASSINFO(wxCommandEvent)) || !GetParent() || !GetParent()->ProcessEvent(event))
115 return wxEvtHandler::ProcessEvent(event);
116 else
117 return TRUE;
118 }
119 else
120 return TRUE;
121 }
122
123 void wxDocMDIChildFrame::OnActivate(wxActivateEvent& event)
124 {
125 wxMDIChildFrame::OnActivate(event);
126
127 if (event.GetActive() && m_childView)
128 m_childView->Activate(event.GetActive());
129 }
130
131 bool wxDocMDIChildFrame::OnClose(void)
132 {
133 // Close view but don't delete the frame while doing so!
134 // ...since it will be deleted by wxWindows if we return TRUE.
135 if (m_childView)
136 {
137 bool ans = m_childView->Close(FALSE); // FALSE means don't delete associated window
138 if (ans)
139 {
140 m_childView->Activate(FALSE);
141 delete m_childView;
142 m_childView = (wxView *) NULL;
143 m_childDocument = (wxDocument *) NULL;
144 }
145
146 return ans;
147 }
148 else return TRUE;
149 }
150
151 #endif
152 // wxUSE_DOC_VIEW_ARCHITECTURE
153