]> git.saurik.com Git - wxWidgets.git/blob - src/common/docmdi.cpp
menu sample added
[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 #if wxUSE_MDI_ARCHITECTURE && wxUSE_DOC_VIEW_ARCHITECTURE
24
25 #include "wx/docmdi.h"
26
27 /*
28 * Docview MDI parent frame
29 */
30
31 IMPLEMENT_CLASS(wxDocMDIParentFrame, wxMDIParentFrame)
32
33 BEGIN_EVENT_TABLE(wxDocMDIParentFrame, wxMDIParentFrame)
34 EVT_MENU(wxID_EXIT, wxDocMDIParentFrame::OnExit)
35 EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, wxDocMDIParentFrame::OnMRUFile)
36 EVT_CLOSE(wxDocMDIParentFrame::OnCloseWindow)
37 END_EVENT_TABLE()
38
39 wxDocMDIParentFrame::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
46 void wxDocMDIParentFrame::OnExit(wxCommandEvent& WXUNUSED(event))
47 {
48 Close();
49 }
50
51 void wxDocMDIParentFrame::OnMRUFile(wxCommandEvent& event)
52 {
53 wxString f(m_docManager->GetHistoryFile(event.GetSelection() - wxID_FILE1));
54 if (f != wxT(""))
55 (void)m_docManager->CreateDocument(f, wxDOC_SILENT);
56 }
57
58 // Extend event processing to search the view's event table
59 bool 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
68 void wxDocMDIParentFrame::OnCloseWindow(wxCloseEvent& event)
69 {
70 if (m_docManager->Clear(!event.CanVeto()))
71 {
72 this->Destroy();
73 }
74 else
75 event.Veto();
76 }
77
78
79 /*
80 * Default document child frame for MDI children
81 */
82
83 IMPLEMENT_CLASS(wxDocMDIChildFrame, wxMDIChildFrame)
84
85 BEGIN_EVENT_TABLE(wxDocMDIChildFrame, wxMDIChildFrame)
86 EVT_ACTIVATE(wxDocMDIChildFrame::OnActivate)
87 EVT_CLOSE(wxDocMDIChildFrame::OnCloseWindow)
88 END_EVENT_TABLE()
89
90 wxDocMDIChildFrame::wxDocMDIChildFrame(wxDocument *doc, wxView *view, wxMDIParentFrame *frame, wxWindowID id,
91 const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name):
92 wxMDIChildFrame(frame, id, title, pos, size, style, name)
93 {
94 m_childDocument = doc;
95 m_childView = view;
96 if (view)
97 view->SetFrame(this);
98 }
99
100 wxDocMDIChildFrame::~wxDocMDIChildFrame(void)
101 {
102 m_childView = (wxView *) NULL;
103 }
104
105 // Extend event processing to search the view's event table
106 bool wxDocMDIChildFrame::ProcessEvent(wxEvent& event)
107 {
108 if ( !m_childView || ! m_childView->ProcessEvent(event) )
109 {
110 // Only hand up to the parent if it's a menu command
111 if (!event.IsKindOf(CLASSINFO(wxCommandEvent)) || !GetParent() || !GetParent()->ProcessEvent(event))
112 return wxEvtHandler::ProcessEvent(event);
113 else
114 return TRUE;
115 }
116 else
117 return TRUE;
118 }
119
120 void wxDocMDIChildFrame::OnActivate(wxActivateEvent& event)
121 {
122 wxMDIChildFrame::OnActivate(event);
123
124 if (event.GetActive() && m_childView)
125 m_childView->Activate(event.GetActive());
126 }
127
128 void wxDocMDIChildFrame::OnCloseWindow(wxCloseEvent& event)
129 {
130 // Close view but don't delete the frame while doing so!
131 // ...since it will be deleted by wxWindows if we return TRUE.
132 if (m_childView)
133 {
134 bool ans = FALSE;
135 if (!event.CanVeto())
136 ans = TRUE; // Must delete.
137 else
138 ans = m_childView->Close(FALSE); // FALSE means don't delete associated window
139
140 if (ans)
141 {
142 m_childView->Activate(FALSE);
143 delete m_childView;
144 m_childView = (wxView *) NULL;
145 m_childDocument = (wxDocument *) NULL;
146
147 this->Destroy();
148 }
149 else
150 event.Veto();
151 }
152 else
153 event.Veto();
154 }
155
156 #endif
157 // wxUSE_DOC_VIEW_ARCHITECTURE
158