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