]> git.saurik.com Git - wxWidgets.git/blame - samples/docvwmdi/docview.cpp
fix VC warning about incorrect dll linkage of wxDataViewSelection
[wxWidgets.git] / samples / docvwmdi / docview.cpp
CommitLineData
2108f33a
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: docview.cpp
3// Purpose: Document/view demo
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6aa89a22 8// Copyright: (c) Julian Smart
2f6c54eb 9// Licence: wxWindows license
2108f33a
JS
10/////////////////////////////////////////////////////////////////////////////
11
2108f33a 12/*
be5a51fb 13 * Purpose: Document/view architecture demo for wxWidgets class library - MDI
2108f33a
JS
14 */
15
16
17// For compilers that support precompilation, includes "wx/wx.h".
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
21#pragma hdrstop
22#endif
23
24#ifndef WX_PRECOMP
25#include "wx/wx.h"
26#endif
27
e4b19d9b 28#if !wxUSE_DOC_VIEW_ARCHITECTURE
ad813b00 29#error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
2108f33a
JS
30#endif
31
feea7c52
VZ
32#if !wxUSE_MDI_ARCHITECTURE
33#error You must set wxUSE_MDI_ARCHITECTURE to 1 in setup.h!
34#endif
35
2108f33a
JS
36#include "docview.h"
37#include "doc.h"
38#include "view.h"
39
c67daf87 40MyFrame *frame = (MyFrame *) NULL;
2108f33a
JS
41
42IMPLEMENT_APP(MyApp)
43
44MyApp::MyApp(void)
45{
c67daf87 46 m_docManager = (wxDocManager *) NULL;
2108f33a
JS
47}
48
49bool MyApp::OnInit(void)
50{
51 //// Create a document manager
52 m_docManager = new wxDocManager;
53
54 //// Create a template relating drawing documents to their views
8325937e 55 (void) new wxDocTemplate((wxDocManager *) m_docManager, _T("Drawing"), _T("*.drw"), _T(""), _T("drw"), _T("Drawing Doc"), _T("Drawing View"),
2108f33a
JS
56 CLASSINFO(DrawingDocument), CLASSINFO(DrawingView));
57
58 //// Create a template relating text documents to their views
8325937e 59 (void) new wxDocTemplate(m_docManager, _T("Text"), _T("*.txt"), _T(""), _T("txt"), _T("Text Doc"), _T("Text View"),
2108f33a
JS
60 CLASSINFO(TextEditDocument), CLASSINFO(TextEditView));
61
62 //// Create the main frame window
1dbb34ec 63 frame = new MyFrame((wxDocManager *) m_docManager, (wxFrame *) NULL,
8325937e 64 _T("DocView Demo"), wxPoint(0, 0), wxSize(500, 400),
1dbb34ec 65 wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE);
2108f33a
JS
66
67 //// Give it an icon (this is ignored in MDI mode: uses resources)
68#ifdef __WXMSW__
8325937e 69 frame->SetIcon(wxIcon(_T("doc")));
2108f33a
JS
70#endif
71#ifdef __X__
8325937e 72 frame->SetIcon(wxIcon(_T("doc.xbm")));
2108f33a
JS
73#endif
74
75 //// Make a menubar
76 wxMenu *file_menu = new wxMenu;
c67daf87 77 wxMenu *edit_menu = (wxMenu *) NULL;
2108f33a 78
8325937e
MB
79 file_menu->Append(wxID_NEW, _T("&New...\tCtrl-N"));
80 file_menu->Append(wxID_OPEN, _T("&Open...\tCtrl-X"));
2108f33a
JS
81
82 file_menu->AppendSeparator();
8325937e 83 file_menu->Append(wxID_EXIT, _T("E&xit\tAlt-X"));
2108f33a
JS
84
85 // A nice touch: a history of files visited. Use this menu.
86 m_docManager->FileHistoryUseMenu(file_menu);
87
88 wxMenu *help_menu = new wxMenu;
8325937e 89 help_menu->Append(DOCVIEW_ABOUT, _T("&About\tF1"));
2108f33a
JS
90
91 wxMenuBar *menu_bar = new wxMenuBar;
92
8325937e 93 menu_bar->Append(file_menu, _T("&File"));
2108f33a 94 if (edit_menu)
8325937e
MB
95 menu_bar->Append(edit_menu, _T("&Edit"));
96 menu_bar->Append(help_menu, _T("&Help"));
2108f33a 97
8eabf559
DE
98#ifdef __WXMAC__
99 wxMenuBar::MacSetCommonMenuBar(menu_bar);
100#endif //def __WXMAC__
2108f33a
JS
101 //// Associate the menu bar with the frame
102 frame->SetMenuBar(menu_bar);
103
104 frame->Centre(wxBOTH);
8eabf559 105#ifndef __WXMAC__
691d944f 106 frame->Show(true);
8eabf559 107#endif //ndef __WXMAC__
2108f33a
JS
108
109 SetTopWindow(frame);
691d944f 110 return true;
2108f33a
JS
111}
112
113int MyApp::OnExit(void)
114{
115 delete m_docManager;
116 return 0;
117}
118
119/*
120 * Centralised code for creating a document frame.
121 * Called from view.cpp, when a view is created.
122 */
123
9746a2ba 124wxMDIChildFrame *MyApp::CreateChildFrame(wxDocument *doc, wxView *view, bool isCanvas)
2108f33a
JS
125{
126 //// Make a child frame
1dbb34ec 127 wxDocMDIChildFrame *subframe =
691d944f 128 new wxDocMDIChildFrame(doc, view, GetMainFrame(), wxID_ANY, _T("Child Frame"),
1dbb34ec
VZ
129 wxPoint(10, 10), wxSize(300, 300),
130 wxDEFAULT_FRAME_STYLE |
131 wxNO_FULL_REPAINT_ON_RESIZE);
2108f33a
JS
132
133#ifdef __WXMSW__
8325937e 134 subframe->SetIcon(wxString(isCanvas ? _T("chart") : _T("notepad")));
2108f33a
JS
135#endif
136#ifdef __X__
8325937e 137 subframe->SetIcon(wxIcon(_T("doc.xbm")));
2108f33a
JS
138#endif
139
140 //// Make a menubar
141 wxMenu *file_menu = new wxMenu;
142
8325937e
MB
143 file_menu->Append(wxID_NEW, _T("&New..."));
144 file_menu->Append(wxID_OPEN, _T("&Open..."));
145 file_menu->Append(wxID_CLOSE, _T("&Close"));
146 file_menu->Append(wxID_SAVE, _T("&Save"));
147 file_menu->Append(wxID_SAVEAS, _T("Save &As..."));
2108f33a
JS
148
149 if (isCanvas)
150 {
151 file_menu->AppendSeparator();
8325937e
MB
152 file_menu->Append(wxID_PRINT, _T("&Print..."));
153 file_menu->Append(wxID_PRINT_SETUP, _T("Print &Setup..."));
154 file_menu->Append(wxID_PREVIEW, _T("Print Pre&view"));
2108f33a
JS
155 }
156
157 file_menu->AppendSeparator();
8325937e 158 file_menu->Append(wxID_EXIT, _T("E&xit"));
2108f33a 159
c67daf87 160 wxMenu *edit_menu = (wxMenu *) NULL;
2108f33a
JS
161
162 if (isCanvas)
163 {
164 edit_menu = new wxMenu;
8325937e
MB
165 edit_menu->Append(wxID_UNDO, _T("&Undo"));
166 edit_menu->Append(wxID_REDO, _T("&Redo"));
2108f33a 167 edit_menu->AppendSeparator();
8325937e 168 edit_menu->Append(DOCVIEW_CUT, _T("&Cut last segment"));
2108f33a
JS
169
170 doc->GetCommandProcessor()->SetEditMenu(edit_menu);
171 }
172
173 wxMenu *help_menu = new wxMenu;
8325937e 174 help_menu->Append(DOCVIEW_ABOUT, _T("&About"));
2108f33a
JS
175
176 wxMenuBar *menu_bar = new wxMenuBar;
177
8325937e 178 menu_bar->Append(file_menu, _T("&File"));
2108f33a 179 if (isCanvas)
8325937e
MB
180 menu_bar->Append(edit_menu, _T("&Edit"));
181 menu_bar->Append(help_menu, _T("&Help"));
2108f33a
JS
182
183 //// Associate the menu bar with the frame
184 subframe->SetMenuBar(menu_bar);
185
186 return subframe;
187}
188
189/*
190 * This is the top-level window of the application.
191 */
192
193IMPLEMENT_CLASS(MyFrame, wxDocMDIParentFrame)
194BEGIN_EVENT_TABLE(MyFrame, wxDocMDIParentFrame)
195 EVT_MENU(DOCVIEW_ABOUT, MyFrame::OnAbout)
196END_EVENT_TABLE()
197
198MyFrame::MyFrame(wxDocManager *manager, wxFrame *frame, const wxString& title,
199 const wxPoint& pos, const wxSize& size, long type):
691d944f 200 wxDocMDIParentFrame(manager, frame, wxID_ANY, title, pos, size, type, _T("myFrame"))
2108f33a 201{
c67daf87 202 editMenu = (wxMenu *) NULL;
2108f33a
JS
203}
204
205void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
206{
8325937e 207 (void)wxMessageBox(_T("DocView Demo\nAuthor: Julian Smart\nUsage: docview.exe"), _T("About DocView"));
2108f33a
JS
208}
209
210// Creates a canvas. Called from view.cpp when a new drawing
211// view is created.
b9f933ab 212MyCanvas *MyFrame::CreateCanvas(wxView *view, wxMDIChildFrame *parent)
2108f33a
JS
213{
214 int width, height;
215 parent->GetClientSize(&width, &height);
216
217 // Non-retained canvas
218 MyCanvas *canvas = new MyCanvas(view, parent, wxPoint(0, 0), wxSize(width, height), 0);
219 canvas->SetCursor(wxCursor(wxCURSOR_PENCIL));
220
221 // Give it scrollbars
222 canvas->SetScrollbars(20, 20, 50, 50);
223
224 return canvas;
225}
226
227MyFrame *GetMainFrame(void)
228{
229 return frame;
230}
231