]>
git.saurik.com Git - wxWidgets.git/blob - samples/docvwmdi/docview.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Document/view demo
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
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 wx_setup.h!
40 MyFrame
*frame
= (MyFrame
*) NULL
;
46 m_docManager
= (wxDocManager
*) NULL
;
49 bool MyApp::OnInit(void)
51 //// Create a document manager
52 m_docManager
= new wxDocManager
;
54 //// Create a template relating drawing documents to their views
55 (void) new wxDocTemplate((wxDocManager
*) m_docManager
, "Drawing", "*.drw", "", "drw", "Drawing Doc", "Drawing View",
56 CLASSINFO(DrawingDocument
), CLASSINFO(DrawingView
));
58 //// Create a template relating text documents to their views
59 (void) new wxDocTemplate(m_docManager
, "Text", "*.txt", "", "txt", "Text Doc", "Text View",
60 CLASSINFO(TextEditDocument
), CLASSINFO(TextEditView
));
62 //// Create the main frame window
63 frame
= new MyFrame((wxDocManager
*) m_docManager
, (wxFrame
*) NULL
, (const wxString
) "DocView Demo", wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE
);
65 //// Give it an icon (this is ignored in MDI mode: uses resources)
67 frame
->SetIcon(wxIcon("doc"));
70 frame
->SetIcon(wxIcon("doc.xbm"));
74 wxMenu
*file_menu
= new wxMenu
;
75 wxMenu
*edit_menu
= (wxMenu
*) NULL
;
77 file_menu
->Append(wxID_NEW
, "&New...");
78 file_menu
->Append(wxID_OPEN
, "&Open...");
80 file_menu
->AppendSeparator();
81 file_menu
->Append(wxID_EXIT
, "E&xit");
83 // A nice touch: a history of files visited. Use this menu.
84 m_docManager
->FileHistoryUseMenu(file_menu
);
86 wxMenu
*help_menu
= new wxMenu
;
87 help_menu
->Append(DOCVIEW_ABOUT
, "&About");
89 wxMenuBar
*menu_bar
= new wxMenuBar
;
91 menu_bar
->Append(file_menu
, "&File");
93 menu_bar
->Append(edit_menu
, "&Edit");
94 menu_bar
->Append(help_menu
, "&Help");
96 //// Associate the menu bar with the frame
97 frame
->SetMenuBar(menu_bar
);
99 frame
->Centre(wxBOTH
);
106 int MyApp::OnExit(void)
113 * Centralised code for creating a document frame.
114 * Called from view.cpp, when a view is created.
117 wxMDIChildFrame
*MyApp::CreateChildFrame(wxDocument
*doc
, wxView
*view
, bool isCanvas
)
119 //// Make a child frame
120 wxDocMDIChildFrame
*subframe
= new wxDocMDIChildFrame(doc
, view
, GetMainFrame(), -1, "Child Frame",
121 wxPoint(10, 10), wxSize(300, 300), wxDEFAULT_FRAME_STYLE
);
124 subframe
->SetIcon(wxString(isCanvas
? "chart" : "notepad"));
127 subframe
->SetIcon(wxIcon("doc.xbm"));
131 wxMenu
*file_menu
= new wxMenu
;
133 file_menu
->Append(wxID_NEW
, "&New...");
134 file_menu
->Append(wxID_OPEN
, "&Open...");
135 file_menu
->Append(wxID_CLOSE
, "&Close");
136 file_menu
->Append(wxID_SAVE
, "&Save");
137 file_menu
->Append(wxID_SAVEAS
, "Save &As...");
141 file_menu
->AppendSeparator();
142 file_menu
->Append(wxID_PRINT
, "&Print...");
143 file_menu
->Append(wxID_PRINT_SETUP
, "Print &Setup...");
144 file_menu
->Append(wxID_PREVIEW
, "Print Pre&view");
147 file_menu
->AppendSeparator();
148 file_menu
->Append(wxID_EXIT
, "E&xit");
150 wxMenu
*edit_menu
= (wxMenu
*) NULL
;
154 edit_menu
= new wxMenu
;
155 edit_menu
->Append(wxID_UNDO
, "&Undo");
156 edit_menu
->Append(wxID_REDO
, "&Redo");
157 edit_menu
->AppendSeparator();
158 edit_menu
->Append(DOCVIEW_CUT
, "&Cut last segment");
160 doc
->GetCommandProcessor()->SetEditMenu(edit_menu
);
163 wxMenu
*help_menu
= new wxMenu
;
164 help_menu
->Append(DOCVIEW_ABOUT
, "&About");
166 wxMenuBar
*menu_bar
= new wxMenuBar
;
168 menu_bar
->Append(file_menu
, "&File");
170 menu_bar
->Append(edit_menu
, "&Edit");
171 menu_bar
->Append(help_menu
, "&Help");
173 //// Associate the menu bar with the frame
174 subframe
->SetMenuBar(menu_bar
);
180 * This is the top-level window of the application.
183 IMPLEMENT_CLASS(MyFrame
, wxDocMDIParentFrame
)
184 BEGIN_EVENT_TABLE(MyFrame
, wxDocMDIParentFrame
)
185 EVT_MENU(DOCVIEW_ABOUT
, MyFrame::OnAbout
)
188 MyFrame::MyFrame(wxDocManager
*manager
, wxFrame
*frame
, const wxString
& title
,
189 const wxPoint
& pos
, const wxSize
& size
, long type
):
190 wxDocMDIParentFrame(manager
, frame
, -1, title
, pos
, size
, type
, "myFrame")
192 editMenu
= (wxMenu
*) NULL
;
195 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
) )
197 (void)wxMessageBox("DocView Demo\nAuthor: Julian Smart julian.smart@ukonline.co.uk\nUsage: docview.exe", "About DocView");
200 // Creates a canvas. Called from view.cpp when a new drawing
202 MyCanvas
*MyFrame::CreateCanvas(wxView
*view
, wxFrame
*parent
)
205 parent
->GetClientSize(&width
, &height
);
207 // Non-retained canvas
208 MyCanvas
*canvas
= new MyCanvas(view
, parent
, wxPoint(0, 0), wxSize(width
, height
), 0);
209 canvas
->SetCursor(wxCursor(wxCURSOR_PENCIL
));
211 // Give it scrollbars
212 canvas
->SetScrollbars(20, 20, 50, 50);
217 MyFrame
*GetMainFrame(void)