1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Document/view demo
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 * Purpose: Document/view architecture demo for wxWidgets class library - MDI
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
28 #if !wxUSE_DOC_VIEW_ARCHITECTURE
29 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
32 #if !wxUSE_MDI_ARCHITECTURE
33 #error You must set wxUSE_MDI_ARCHITECTURE to 1 in setup.h!
39 #include "wx/stockitem.h"
41 static MyFrame
* frame
= NULL
;
50 bool MyApp::OnInit(void)
52 if ( !wxApp::OnInit() )
54 //// Create a document manager
55 SetAppName(wxT("DocView Demo"));
57 //// Create a document manager
58 m_docManager
= new wxDocManager
;
60 //// Create a template relating drawing documents to their views
61 new wxDocTemplate(m_docManager
, wxT("Drawing"), wxT("*.drw"), wxT(""), wxT("drw"), wxT("Drawing Doc"), wxT("Drawing View"),
62 CLASSINFO(DrawingDocument
), CLASSINFO(DrawingView
));
64 //// Create a template relating text documents to their views
65 new wxDocTemplate(m_docManager
, wxT("Text"), wxT("*.txt"), wxT(""), wxT("txt"), wxT("Text Doc"), wxT("Text View"),
66 CLASSINFO(TextEditDocument
), CLASSINFO(TextEditView
));
68 //// Create the main frame window
69 frame
= new MyFrame(m_docManager
, NULL
,
70 GetAppDisplayName(), wxPoint(0, 0), wxSize(500, 400),
71 wxDEFAULT_FRAME_STYLE
| wxNO_FULL_REPAINT_ON_RESIZE
);
73 //// Give it an icon (this is ignored in MDI mode: uses resources)
75 frame
->SetIcon(wxIcon(wxT("doc")));
79 wxMenu
*file_menu
= new wxMenu
;
80 wxMenu
*edit_menu
= NULL
;
82 file_menu
->Append(wxID_NEW
);
83 file_menu
->Append(wxID_OPEN
);
85 file_menu
->AppendSeparator();
86 file_menu
->Append(wxID_EXIT
);
88 // A nice touch: a history of files visited. Use this menu.
89 m_docManager
->FileHistoryUseMenu(file_menu
);
91 wxMenu
*help_menu
= new wxMenu
;
92 help_menu
->Append(DOCVIEW_ABOUT
);
94 wxMenuBar
*menu_bar
= new wxMenuBar
;
96 menu_bar
->Append(file_menu
, wxGetStockLabel(wxID_FILE
));
98 menu_bar
->Append(edit_menu
, wxGetStockLabel(wxID_EDIT
));
99 menu_bar
->Append(help_menu
, wxGetStockLabel(wxID_HELP
));
102 wxMenuBar::MacSetCommonMenuBar(menu_bar
);
103 #endif //def __WXMAC__
104 //// Associate the menu bar with the frame
105 frame
->SetMenuBar(menu_bar
);
107 frame
->Centre(wxBOTH
);
110 #endif //ndef __WXMAC__
116 int MyApp::OnExit(void)
118 wxDELETE(m_docManager
)
123 * Centralised code for creating a document frame.
124 * Called from view.cpp, when a view is created.
127 wxMDIChildFrame
*MyApp::CreateChildFrame(wxDocument
*doc
, wxView
*view
, bool isCanvas
)
129 //// Make a child frame
130 wxDocMDIChildFrame
*subframe
=
131 new wxDocMDIChildFrame(doc
, view
, GetMainFrame(), wxID_ANY
, wxT("Child Frame"),
132 wxPoint(10, 10), wxSize(300, 300),
133 wxDEFAULT_FRAME_STYLE
|
134 wxNO_FULL_REPAINT_ON_RESIZE
);
137 subframe
->SetIcon(wxString(isCanvas
? wxT("chart") : wxT("notepad")));
140 subframe
->SetIcon(wxIcon(wxT("doc.xbm")));
144 wxMenu
*file_menu
= new wxMenu
;
146 file_menu
->Append(wxID_NEW
);
147 file_menu
->Append(wxID_OPEN
);
148 file_menu
->Append(wxID_CLOSE
);
149 file_menu
->Append(wxID_SAVE
);
150 file_menu
->Append(wxID_SAVEAS
);
154 file_menu
->AppendSeparator();
155 file_menu
->Append(wxID_PRINT
);
156 file_menu
->Append(wxID_PRINT_SETUP
, wxT("Print &Setup..."));
157 file_menu
->Append(wxID_PREVIEW
);
160 file_menu
->AppendSeparator();
161 file_menu
->Append(wxID_EXIT
);
163 wxMenu
*edit_menu
= new wxMenu
;
166 edit_menu
->Append(wxID_UNDO
);
167 edit_menu
->Append(wxID_REDO
);
168 edit_menu
->AppendSeparator();
169 edit_menu
->Append(DOCVIEW_CUT
, wxT("&Cut last segment"));
171 doc
->GetCommandProcessor()->SetEditMenu(edit_menu
);
175 edit_menu
->Append(wxID_COPY
);
176 edit_menu
->Append(wxID_PASTE
);
177 edit_menu
->Append(wxID_SELECTALL
);
179 wxMenu
*help_menu
= new wxMenu
;
180 help_menu
->Append(DOCVIEW_ABOUT
);
182 wxMenuBar
*menu_bar
= new wxMenuBar
;
184 menu_bar
->Append(file_menu
, wxGetStockLabel(wxID_FILE
));
185 menu_bar
->Append(edit_menu
, wxGetStockLabel(wxID_EDIT
));
186 menu_bar
->Append(help_menu
, wxGetStockLabel(wxID_HELP
));
188 //// Associate the menu bar with the frame
189 subframe
->SetMenuBar(menu_bar
);
195 * This is the top-level window of the application.
198 IMPLEMENT_CLASS(MyFrame
, wxDocMDIParentFrame
)
199 BEGIN_EVENT_TABLE(MyFrame
, wxDocMDIParentFrame
)
200 EVT_MENU(DOCVIEW_ABOUT
, MyFrame::OnAbout
)
203 MyFrame::MyFrame(wxDocManager
*manager
, wxFrame
*frame
, const wxString
& title
,
204 const wxPoint
& pos
, const wxSize
& size
, long type
):
205 wxDocMDIParentFrame(manager
, frame
, wxID_ANY
, title
, pos
, size
, type
, wxT("myFrame"))
210 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
212 wxMessageBox(wxT("DocView Demo\nAuthor: Julian Smart\nUsage: docview.exe"), wxT("About DocView"));
214 Better, but brings in adv lib
215 wxAboutDialogInfo info;
216 info.SetName(wxTheApp->GetAppDisplayName());
217 info.AddDeveloper(wxT("Julian Smart"));
222 // Creates a canvas. Called from view.cpp when a new drawing
224 MyCanvas
* MyFrame::CreateCanvas(DrawingView
* view
, wxMDIChildFrame
* parent
)
226 wxSize size
= parent
->GetClientSize();
228 // Non-retained canvas
229 MyCanvas
*canvas
= new MyCanvas(view
, parent
, wxPoint(0, 0), size
, 0);
230 canvas
->SetCursor(wxCursor(wxCURSOR_PENCIL
));
232 // Give it scrollbars
233 canvas
->SetScrollbars(20, 20, 50, 50);
238 MyFrame
* GetMainFrame()