]> git.saurik.com Git - wxWidgets.git/blame - src/common/docmdi.cpp
fixes for harmless mingw32 warnings
[wxWidgets.git] / src / common / docmdi.cpp
CommitLineData
2108f33a
JS
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
65571936 9// Licence: wxWindows licence
2108f33a
JS
10/////////////////////////////////////////////////////////////////////////////
11
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
2108f33a
JS
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__
2df7be7f 20 #pragma hdrstop
2108f33a
JS
21#endif
22
e30285ab 23#if wxUSE_MDI_ARCHITECTURE
2108f33a 24
2108f33a
JS
25#include "wx/docmdi.h"
26
27/*
28 * Docview MDI parent frame
29 */
30
31IMPLEMENT_CLASS(wxDocMDIParentFrame, wxMDIParentFrame)
32
33BEGIN_EVENT_TABLE(wxDocMDIParentFrame, wxMDIParentFrame)
34 EVT_MENU(wxID_EXIT, wxDocMDIParentFrame::OnExit)
f7bd2698 35 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, wxDocMDIParentFrame::OnMRUFile)
387a3b02 36 EVT_CLOSE(wxDocMDIParentFrame::OnCloseWindow)
2108f33a
JS
37END_EVENT_TABLE()
38
f0003d29
JS
39wxDocMDIParentFrame::wxDocMDIParentFrame()
40{
41 Init();
42}
43
2108f33a 44wxDocMDIParentFrame::wxDocMDIParentFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title,
f0003d29
JS
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
51bool wxDocMDIParentFrame::Create(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title,
52 const wxPoint& pos, const wxSize& size, long style, const wxString& name)
2108f33a 53{
f0003d29
JS
54 m_docManager = manager;
55 return wxMDIParentFrame::Create(frame, id, title, pos, size, style, name);
2108f33a
JS
56}
57
58void wxDocMDIParentFrame::OnExit(wxCommandEvent& WXUNUSED(event))
59{
60 Close();
61}
62
f0003d29
JS
63void wxDocMDIParentFrame::Init()
64{
65 m_docManager = NULL;
66}
67
2108f33a
JS
68void wxDocMDIParentFrame::OnMRUFile(wxCommandEvent& event)
69{
afdefa8e 70 wxString f(m_docManager->GetHistoryFile(event.GetId() - wxID_FILE1));
223d09f6 71 if (f != wxT(""))
2108f33a
JS
72 (void)m_docManager->CreateDocument(f, wxDOC_SILENT);
73}
74
75// Extend event processing to search the view's event table
76bool 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
68379eaf 82 return true;
2108f33a
JS
83}
84
387a3b02 85void wxDocMDIParentFrame::OnCloseWindow(wxCloseEvent& event)
2108f33a 86{
387a3b02
JS
87 if (m_docManager->Clear(!event.CanVeto()))
88 {
89 this->Destroy();
90 }
91 else
92 event.Veto();
2108f33a
JS
93}
94
95
96/*
97 * Default document child frame for MDI children
98 */
99
100IMPLEMENT_CLASS(wxDocMDIChildFrame, wxMDIChildFrame)
101
102BEGIN_EVENT_TABLE(wxDocMDIChildFrame, wxMDIChildFrame)
103 EVT_ACTIVATE(wxDocMDIChildFrame::OnActivate)
387a3b02 104 EVT_CLOSE(wxDocMDIChildFrame::OnCloseWindow)
2108f33a
JS
105END_EVENT_TABLE()
106
75799719
VZ
107void wxDocMDIChildFrame::Init()
108{
109 m_childDocument = (wxDocument*) NULL;
110 m_childView = (wxView*) NULL;
111}
112
113wxDocMDIChildFrame::wxDocMDIChildFrame()
114{
115 Init();
116}
117
2108f33a 118wxDocMDIChildFrame::wxDocMDIChildFrame(wxDocument *doc, wxView *view, wxMDIParentFrame *frame, wxWindowID id,
75799719
VZ
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
125bool 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)
2108f33a 127{
f0003d29
JS
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);
68379eaf 134 return true;
75799719
VZ
135 }
136
68379eaf 137 return false;
2108f33a
JS
138}
139
140wxDocMDIChildFrame::~wxDocMDIChildFrame(void)
141{
68379eaf 142 m_childView = (wxView *) NULL;
2108f33a
JS
143}
144
145// Extend event processing to search the view's event table
146bool wxDocMDIChildFrame::ProcessEvent(wxEvent& event)
147{
377a219a
JS
148 static wxEvent *ActiveEvent = NULL;
149
150 // Break recursion loops
151 if (ActiveEvent == &event)
68379eaf 152 return false;
377a219a
JS
153
154 ActiveEvent = &event;
155
156 bool ret;
68379eaf 157 if ( !m_childView || ! m_childView->ProcessEvent(event) )
2108f33a
JS
158 {
159 // Only hand up to the parent if it's a menu command
160 if (!event.IsKindOf(CLASSINFO(wxCommandEvent)) || !GetParent() || !GetParent()->ProcessEvent(event))
377a219a 161 ret = wxEvtHandler::ProcessEvent(event);
2108f33a 162 else
68379eaf 163 ret = true;
2108f33a 164 }
68379eaf
WS
165 else
166 ret = true;
377a219a
JS
167
168 ActiveEvent = NULL;
169 return ret;
2108f33a
JS
170}
171
172void wxDocMDIChildFrame::OnActivate(wxActivateEvent& event)
173{
174 wxMDIChildFrame::OnActivate(event);
175
7f555861 176 if (event.GetActive() && m_childView)
2108f33a
JS
177 m_childView->Activate(event.GetActive());
178}
179
387a3b02 180void wxDocMDIChildFrame::OnCloseWindow(wxCloseEvent& event)
2108f33a
JS
181{
182 // Close view but don't delete the frame while doing so!
68379eaf 183 // ...since it will be deleted by wxWidgets if we return true.
2108f33a
JS
184 if (m_childView)
185 {
999836aa 186 bool ans = event.CanVeto()
68379eaf
WS
187 ? m_childView->Close(false) // false means don't delete associated window
188 : true; // Must delete.
387a3b02 189
2108f33a
JS
190 if (ans)
191 {
68379eaf 192 m_childView->Activate(false);
2108f33a 193 delete m_childView;
c67daf87
UR
194 m_childView = (wxView *) NULL;
195 m_childDocument = (wxDocument *) NULL;
387a3b02
JS
196
197 this->Destroy();
2108f33a 198 }
387a3b02
JS
199 else
200 event.Veto();
2108f33a 201 }
387a3b02
JS
202 else
203 event.Veto();
2108f33a
JS
204}
205
206#endif
47d67540 207 // wxUSE_DOC_VIEW_ARCHITECTURE
2108f33a 208