]> git.saurik.com Git - wxWidgets.git/blob - src/common/docmdi.cpp
added wxLogWindow::GetFrame()
[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 }
106
107 // Extend event processing to search the view's event table
108 bool wxDocMDIChildFrame::ProcessEvent(wxEvent& event)
109 {
110 if (m_childView)
111 m_childView->Activate(TRUE);
112
113 if ( !m_childView || ! m_childView->ProcessEvent(event) )
114 {
115 // Only hand up to the parent if it's a menu command
116 if (!event.IsKindOf(CLASSINFO(wxCommandEvent)) || !GetParent() || !GetParent()->ProcessEvent(event))
117 return wxEvtHandler::ProcessEvent(event);
118 else
119 return TRUE;
120 }
121 else
122 return TRUE;
123 }
124
125 void wxDocMDIChildFrame::OnActivate(wxActivateEvent& event)
126 {
127 wxMDIChildFrame::OnActivate(event);
128
129 if (m_childView)
130 m_childView->Activate(event.GetActive());
131 }
132
133 bool wxDocMDIChildFrame::OnClose(void)
134 {
135 // Close view but don't delete the frame while doing so!
136 // ...since it will be deleted by wxWindows if we return TRUE.
137 if (m_childView)
138 {
139 bool ans = m_childView->Close(FALSE); // FALSE means don't delete associated window
140 if (ans)
141 {
142 m_childView->Activate(FALSE);
143 delete m_childView;
144 m_childView = NULL;
145 m_childDocument = NULL;
146 }
147
148 return ans;
149 }
150 else return TRUE;
151 }
152
153 #endif
154 // USE_DOC_VIEW_ARCHITECTURE
155