]> git.saurik.com Git - wxWidgets.git/blame - src/common/docmdi.cpp
fix for always terminating intermediate UniChar String for 4 bytes wchar_t
[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
3f4a0c5b 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
39wxDocMDIParentFrame::wxDocMDIParentFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title,
40 const wxPoint& pos, const wxSize& size, long style, const wxString& name):
41 wxMDIParentFrame(frame, id, title, pos, size, style, name)
42{
43 m_docManager = manager;
44}
45
46void wxDocMDIParentFrame::OnExit(wxCommandEvent& WXUNUSED(event))
47{
48 Close();
49}
50
51void wxDocMDIParentFrame::OnMRUFile(wxCommandEvent& event)
52{
afdefa8e 53 wxString f(m_docManager->GetHistoryFile(event.GetId() - wxID_FILE1));
223d09f6 54 if (f != wxT(""))
2108f33a
JS
55 (void)m_docManager->CreateDocument(f, wxDOC_SILENT);
56}
57
58// Extend event processing to search the view's event table
59bool wxDocMDIParentFrame::ProcessEvent(wxEvent& event)
60{
61 // Try the document manager, then do default processing
62 if (!m_docManager || !m_docManager->ProcessEvent(event))
63 return wxEvtHandler::ProcessEvent(event);
64 else
65 return TRUE;
66}
67
387a3b02 68void wxDocMDIParentFrame::OnCloseWindow(wxCloseEvent& event)
2108f33a 69{
387a3b02
JS
70 if (m_docManager->Clear(!event.CanVeto()))
71 {
72 this->Destroy();
73 }
74 else
75 event.Veto();
2108f33a
JS
76}
77
78
79/*
80 * Default document child frame for MDI children
81 */
82
83IMPLEMENT_CLASS(wxDocMDIChildFrame, wxMDIChildFrame)
84
85BEGIN_EVENT_TABLE(wxDocMDIChildFrame, wxMDIChildFrame)
86 EVT_ACTIVATE(wxDocMDIChildFrame::OnActivate)
387a3b02 87 EVT_CLOSE(wxDocMDIChildFrame::OnCloseWindow)
2108f33a
JS
88END_EVENT_TABLE()
89
75799719
VZ
90void wxDocMDIChildFrame::Init()
91{
92 m_childDocument = (wxDocument*) NULL;
93 m_childView = (wxView*) NULL;
94}
95
96wxDocMDIChildFrame::wxDocMDIChildFrame()
97{
98 Init();
99}
100
2108f33a 101wxDocMDIChildFrame::wxDocMDIChildFrame(wxDocument *doc, wxView *view, wxMDIParentFrame *frame, wxWindowID id,
75799719
VZ
102 const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
103{
104 Init();
105 Create(doc, view, frame, id, title, pos, size, style, name);
106}
107
108bool wxDocMDIChildFrame::Create(wxDocument *doc, wxView *view, wxMDIParentFrame *frame, wxWindowID id,
109 const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
2108f33a
JS
110{
111 m_childDocument = doc;
112 m_childView = view;
75799719 113 if (wxMDIChildFrame::Create(frame, id, title, pos, size, style, name)) {
2108f33a
JS
114 if (view)
115 view->SetFrame(this);
75799719
VZ
116 return TRUE;
117 }
118
119 return FALSE;
2108f33a
JS
120}
121
122wxDocMDIChildFrame::~wxDocMDIChildFrame(void)
123{
c67daf87 124 m_childView = (wxView *) NULL;
2108f33a
JS
125}
126
127// Extend event processing to search the view's event table
128bool wxDocMDIChildFrame::ProcessEvent(wxEvent& event)
129{
377a219a
JS
130 static wxEvent *ActiveEvent = NULL;
131
132 // Break recursion loops
133 if (ActiveEvent == &event)
d62144c9 134 return FALSE;
377a219a
JS
135
136 ActiveEvent = &event;
137
138 bool ret;
2108f33a
JS
139 if ( !m_childView || ! m_childView->ProcessEvent(event) )
140 {
141 // Only hand up to the parent if it's a menu command
142 if (!event.IsKindOf(CLASSINFO(wxCommandEvent)) || !GetParent() || !GetParent()->ProcessEvent(event))
377a219a 143 ret = wxEvtHandler::ProcessEvent(event);
2108f33a 144 else
377a219a 145 ret = TRUE;
2108f33a
JS
146 }
147 else
377a219a
JS
148 ret = TRUE;
149
150 ActiveEvent = NULL;
151 return ret;
2108f33a
JS
152}
153
154void wxDocMDIChildFrame::OnActivate(wxActivateEvent& event)
155{
156 wxMDIChildFrame::OnActivate(event);
157
7f555861 158 if (event.GetActive() && m_childView)
2108f33a
JS
159 m_childView->Activate(event.GetActive());
160}
161
387a3b02 162void wxDocMDIChildFrame::OnCloseWindow(wxCloseEvent& event)
2108f33a
JS
163{
164 // Close view but don't delete the frame while doing so!
165 // ...since it will be deleted by wxWindows if we return TRUE.
166 if (m_childView)
167 {
999836aa
VZ
168 bool ans = event.CanVeto()
169 ? m_childView->Close(FALSE) // FALSE means don't delete associated window
170 : TRUE; // Must delete.
387a3b02 171
2108f33a
JS
172 if (ans)
173 {
174 m_childView->Activate(FALSE);
175 delete m_childView;
c67daf87
UR
176 m_childView = (wxView *) NULL;
177 m_childDocument = (wxDocument *) NULL;
387a3b02
JS
178
179 this->Destroy();
2108f33a 180 }
387a3b02
JS
181 else
182 event.Veto();
2108f33a 183 }
387a3b02
JS
184 else
185 event.Veto();
2108f33a
JS
186}
187
188#endif
47d67540 189 // wxUSE_DOC_VIEW_ARCHITECTURE
2108f33a 190