1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Document/view demo
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 // #pragma implementation "docview.h"
17 * Purpose: Document/view architecture demo for wxWindows class library - MDI
21 // For compilers that support precompilation, includes "wx/wx.h".
22 #include "wx/wxprec.h"
32 #if !wxUSE_DOC_VIEW_ARCHITECTURE
33 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
36 #if !wxUSE_MDI_ARCHITECTURE
37 #error You must set wxUSE_MDI_ARCHITECTURE to 1 in setup.h!
44 MyFrame
*frame
= (MyFrame
*) NULL
;
50 m_docManager
= (wxDocManager
*) NULL
;
53 bool MyApp::OnInit(void)
55 //// Create a document manager
56 m_docManager
= new wxDocManager
;
58 //// Create a template relating drawing documents to their views
59 (void) new wxDocTemplate((wxDocManager
*) m_docManager
, _T("Drawing"), _T("*.drw"), _T(""), _T("drw"), _T("Drawing Doc"), _T("Drawing View"),
60 CLASSINFO(DrawingDocument
), CLASSINFO(DrawingView
));
62 //// Create a template relating text documents to their views
63 (void) new wxDocTemplate(m_docManager
, _T("Text"), _T("*.txt"), _T(""), _T("txt"), _T("Text Doc"), _T("Text View"),
64 CLASSINFO(TextEditDocument
), CLASSINFO(TextEditView
));
66 //// Create the main frame window
67 frame
= new MyFrame((wxDocManager
*) m_docManager
, (wxFrame
*) NULL
,
68 _T("DocView Demo"), wxPoint(0, 0), wxSize(500, 400),
69 wxDEFAULT_FRAME_STYLE
| wxNO_FULL_REPAINT_ON_RESIZE
);
71 //// Give it an icon (this is ignored in MDI mode: uses resources)
73 frame
->SetIcon(wxIcon(_T("doc")));
76 frame
->SetIcon(wxIcon(_T("doc.xbm")));
80 wxMenu
*file_menu
= new wxMenu
;
81 wxMenu
*edit_menu
= (wxMenu
*) NULL
;
83 file_menu
->Append(wxID_NEW
, _T("&New...\tCtrl-N"));
84 file_menu
->Append(wxID_OPEN
, _T("&Open...\tCtrl-X"));
86 file_menu
->AppendSeparator();
87 file_menu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
89 // A nice touch: a history of files visited. Use this menu.
90 m_docManager
->FileHistoryUseMenu(file_menu
);
92 wxMenu
*help_menu
= new wxMenu
;
93 help_menu
->Append(DOCVIEW_ABOUT
, _T("&About\tF1"));
95 wxMenuBar
*menu_bar
= new wxMenuBar
;
97 menu_bar
->Append(file_menu
, _T("&File"));
99 menu_bar
->Append(edit_menu
, _T("&Edit"));
100 menu_bar
->Append(help_menu
, _T("&Help"));
103 wxMenuBar::MacSetCommonMenuBar(menu_bar
);
104 #endif //def __WXMAC__
105 //// Associate the menu bar with the frame
106 frame
->SetMenuBar(menu_bar
);
108 frame
->Centre(wxBOTH
);
111 #endif //ndef __WXMAC__
117 int MyApp::OnExit(void)
124 * Centralised code for creating a document frame.
125 * Called from view.cpp, when a view is created.
128 wxMDIChildFrame
*MyApp::CreateChildFrame(wxDocument
*doc
, wxView
*view
, bool isCanvas
)
130 //// Make a child frame
131 wxDocMDIChildFrame
*subframe
=
132 new wxDocMDIChildFrame(doc
, view
, GetMainFrame(), -1, _T("Child Frame"),
133 wxPoint(10, 10), wxSize(300, 300),
134 wxDEFAULT_FRAME_STYLE
|
135 wxNO_FULL_REPAINT_ON_RESIZE
);
138 subframe
->SetIcon(wxString(isCanvas
? _T("chart") : _T("notepad")));
141 subframe
->SetIcon(wxIcon(_T("doc.xbm")));
145 wxMenu
*file_menu
= new wxMenu
;
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..."));
155 file_menu
->AppendSeparator();
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"));
161 file_menu
->AppendSeparator();
162 file_menu
->Append(wxID_EXIT
, _T("E&xit"));
164 wxMenu
*edit_menu
= (wxMenu
*) NULL
;
168 edit_menu
= new wxMenu
;
169 edit_menu
->Append(wxID_UNDO
, _T("&Undo"));
170 edit_menu
->Append(wxID_REDO
, _T("&Redo"));
171 edit_menu
->AppendSeparator();
172 edit_menu
->Append(DOCVIEW_CUT
, _T("&Cut last segment"));
174 doc
->GetCommandProcessor()->SetEditMenu(edit_menu
);
177 wxMenu
*help_menu
= new wxMenu
;
178 help_menu
->Append(DOCVIEW_ABOUT
, _T("&About"));
180 wxMenuBar
*menu_bar
= new wxMenuBar
;
182 menu_bar
->Append(file_menu
, _T("&File"));
184 menu_bar
->Append(edit_menu
, _T("&Edit"));
185 menu_bar
->Append(help_menu
, _T("&Help"));
187 //// Associate the menu bar with the frame
188 subframe
->SetMenuBar(menu_bar
);
194 * This is the top-level window of the application.
197 IMPLEMENT_CLASS(MyFrame
, wxDocMDIParentFrame
)
198 BEGIN_EVENT_TABLE(MyFrame
, wxDocMDIParentFrame
)
199 EVT_MENU(DOCVIEW_ABOUT
, MyFrame::OnAbout
)
202 MyFrame::MyFrame(wxDocManager
*manager
, wxFrame
*frame
, const wxString
& title
,
203 const wxPoint
& pos
, const wxSize
& size
, long type
):
204 wxDocMDIParentFrame(manager
, frame
, -1, title
, pos
, size
, type
, _T("myFrame"))
206 editMenu
= (wxMenu
*) NULL
;
209 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
211 (void)wxMessageBox(_T("DocView Demo\nAuthor: Julian Smart\nUsage: docview.exe"), _T("About DocView"));
214 // Creates a canvas. Called from view.cpp when a new drawing
216 MyCanvas
*MyFrame::CreateCanvas(wxView
*view
, wxMDIChildFrame
*parent
)
219 parent
->GetClientSize(&width
, &height
);
221 // Non-retained canvas
222 MyCanvas
*canvas
= new MyCanvas(view
, parent
, wxPoint(0, 0), wxSize(width
, height
), 0);
223 canvas
->SetCursor(wxCursor(wxCURSOR_PENCIL
));
225 // Give it scrollbars
226 canvas
->SetScrollbars(20, 20, 50, 50);
231 MyFrame
*GetMainFrame(void)