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