]> git.saurik.com Git - wxWidgets.git/blob - src/common/docmdi.cpp
Added test for long long type. (Really trivial, see setup.h: SIZEOF_xxx)
[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 wxUSE_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 EVT_CLOSE(wxDocMDIParentFrame::OnCloseWindow)
45 END_EVENT_TABLE()
46
47 wxDocMDIParentFrame::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
54 void wxDocMDIParentFrame::OnExit(wxCommandEvent& WXUNUSED(event))
55 {
56 Close();
57 }
58
59 void 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
67 bool 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
76 void wxDocMDIParentFrame::OnCloseWindow(wxCloseEvent& event)
77 {
78 if (m_docManager->Clear(!event.CanVeto()))
79 {
80 this->Destroy();
81 }
82 else
83 event.Veto();
84 }
85
86
87 /*
88 * Default document child frame for MDI children
89 */
90
91 IMPLEMENT_CLASS(wxDocMDIChildFrame, wxMDIChildFrame)
92
93 BEGIN_EVENT_TABLE(wxDocMDIChildFrame, wxMDIChildFrame)
94 EVT_ACTIVATE(wxDocMDIChildFrame::OnActivate)
95 EVT_CLOSE(wxDocMDIChildFrame::OnCloseWindow)
96 END_EVENT_TABLE()
97
98 wxDocMDIChildFrame::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
108 wxDocMDIChildFrame::~wxDocMDIChildFrame(void)
109 {
110 m_childView = (wxView *) NULL;
111 }
112
113 // Extend event processing to search the view's event table
114 bool wxDocMDIChildFrame::ProcessEvent(wxEvent& event)
115 {
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
128 void wxDocMDIChildFrame::OnActivate(wxActivateEvent& event)
129 {
130 wxMDIChildFrame::OnActivate(event);
131
132 if (event.GetActive() && m_childView)
133 m_childView->Activate(event.GetActive());
134 }
135
136 void wxDocMDIChildFrame::OnCloseWindow(wxCloseEvent& event)
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 {
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
148 if (ans)
149 {
150 m_childView->Activate(FALSE);
151 delete m_childView;
152 m_childView = (wxView *) NULL;
153 m_childDocument = (wxDocument *) NULL;
154
155 this->Destroy();
156 }
157 else
158 event.Veto();
159 }
160 else
161 event.Veto();
162 }
163
164 #endif
165 // wxUSE_DOC_VIEW_ARCHITECTURE
166