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