1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: OGLEdit sample app
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 // #pragma implementation
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #if !wxUSE_DOC_VIEW_ARCHITECTURE
28 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in wx_setup.h!
36 #if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
40 // A macro needed for some compilers (AIX) that need 'main' to be defined
41 // in the application itself.
50 // The `main program' equivalent, creating the windows and returning the
52 bool MyApp::OnInit(void)
56 //// Create a document manager
57 myDocManager
= new wxDocManager
;
59 //// Create a template relating drawing documents to their views
60 (void) new wxDocTemplate(myDocManager
, _T("Diagram"), _T("*.dia"), wxEmptyString
, _T("dia"), _T("Diagram Doc"), _T("Diagram View"),
61 CLASSINFO(DiagramDocument
), CLASSINFO(DiagramView
));
63 // If we've only got one window, we only get to edit
64 // one document at a time.
65 myDocManager
->SetMaxDocsOpen(1);
67 //// Create the main frame window
68 frame
= new MyFrame(myDocManager
, NULL
, _T("OGLEdit Demo"), wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE
);
71 frame
->SetIcon(wxICON(ogl
));
74 wxMenu
*file_menu
= new wxMenu
;
76 file_menu
->Append(wxID_NEW
, _T("&New..."));
77 file_menu
->Append(wxID_OPEN
, _T("&Open..."));
79 file_menu
->Append(wxID_CLOSE
, _T("&Close"));
80 file_menu
->Append(wxID_SAVE
, _T("&Save"));
81 file_menu
->Append(wxID_SAVEAS
, _T("Save &As..."));
82 file_menu
->AppendSeparator();
83 file_menu
->Append(wxID_PRINT
, _T("&Print..."));
84 file_menu
->Append(wxID_PRINT_SETUP
, _T("Print &Setup..."));
85 file_menu
->Append(wxID_PREVIEW
, _T("Print Pre&view"));
87 wxMenu
*edit_menu
= new wxMenu
;
88 edit_menu
->Append(wxID_UNDO
, _T("&Undo"));
89 edit_menu
->Append(wxID_REDO
, _T("&Redo"));
90 edit_menu
->AppendSeparator();
91 edit_menu
->Append(wxID_CUT
, _T("&Cut"));
92 edit_menu
->AppendSeparator();
93 edit_menu
->Append(OGLEDIT_CHANGE_BACKGROUND_COLOUR
, _T("Change &background colour"));
94 edit_menu
->Append(OGLEDIT_EDIT_LABEL
, _T("Edit &label"));
96 frame
->editMenu
= edit_menu
;
98 file_menu
->AppendSeparator();
99 file_menu
->Append(wxID_EXIT
, _T("E&xit"));
101 // A nice touch: a history of files visited. Use this menu.
102 myDocManager
->FileHistoryUseMenu(file_menu
);
104 wxMenu
*help_menu
= new wxMenu
;
105 help_menu
->Append(OGLEDIT_ABOUT
, _T("&About"));
107 wxMenuBar
*menu_bar
= new wxMenuBar
;
109 menu_bar
->Append(file_menu
, _T("&File"));
111 menu_bar
->Append(edit_menu
, _T("&Edit"));
112 menu_bar
->Append(help_menu
, _T("&Help"));
114 frame
->canvas
= frame
->CreateCanvas(NULL
, frame
);
115 frame
->palette
= wxGetApp().CreatePalette(frame
);
116 myDocManager
->CreateDocument(wxEmptyString
, wxDOC_NEW
);
118 //// Associate the menu bar with the frame
119 frame
->SetMenuBar(menu_bar
);
122 frame
->CreateStatusBar(1);
123 #endif // wxUSE_STATUSBAR
125 frame
->Centre(wxBOTH
);
131 int MyApp::OnExit(void)
139 * This is the top-level window of the application.
142 IMPLEMENT_CLASS(MyFrame
, wxDocParentFrame
)
144 BEGIN_EVENT_TABLE(MyFrame
, wxDocParentFrame
)
145 EVT_MENU(OGLEDIT_ABOUT
, MyFrame::OnAbout
)
146 EVT_SIZE(MyFrame::OnSize
)
147 EVT_CLOSE(MyFrame::OnCloseWindow
)
150 MyFrame::MyFrame(wxDocManager
*manager
, wxFrame
*frame
, const wxString
& title
,
151 const wxPoint
& pos
, const wxSize
& size
, long type
):
152 wxDocParentFrame(manager
, frame
, wxID_ANY
, title
, pos
, size
, type
)
159 void MyFrame::OnSize(wxSizeEvent
& event
)
161 if (canvas
&& palette
)
164 GetClientSize(&cw
, &ch
);
169 int canvasX
= paletteX
+ paletteW
;
171 int canvasW
= cw
- paletteW
;
174 palette
->SetSize(paletteX
, paletteY
, paletteW
, paletteH
);
175 canvas
->SetSize(canvasX
, canvasY
, canvasW
, canvasH
);
180 void MyFrame::OnCloseWindow(wxCloseEvent
& event
)
182 wxDocParentFrame::OnCloseWindow(event
);
183 if (!event
.GetVeto())
189 // Intercept menu commands
190 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
192 (void)wxMessageBox(_T("OGLEdit Demo\nTo draw a shape, select a shape on the toolbar and left-click on the canvas.\nTo draw a line, right-drag between shapes.\nFor further details, see the OGL manual.\n (c) Julian Smart 1996"), _T("About OGLEdit"));
195 // Creates a canvas. Called by OnInit as a child of the main window
196 MyCanvas
*MyFrame::CreateCanvas(wxView
*view
, wxFrame
*parent
)
199 parent
->GetClientSize(&width
, &height
);
201 // Non-retained canvas
202 MyCanvas
*canvas
= new MyCanvas(view
, parent
, wxID_ANY
, wxPoint(0, 0), wxSize(width
, height
), 0);
203 canvas
->SetCursor(wxCursor(wxCURSOR_HAND
));
205 // Give it scrollbars
206 canvas
->SetScrollbars(20, 20, 50, 50);
211 MyFrame
*GetMainFrame(void)
213 return wxGetApp().frame
;