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