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(__WXMOTIF__)
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
, "Diagram", "*.dia", "", "dia", "Diagram Doc", "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
, "OGLEdit Demo", wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE
);
71 frame
->SetIcon(wxICON(ogl
));
74 wxMenu
*file_menu
= new wxMenu
;
75 wxMenu
*edit_menu
= NULL
;
77 file_menu
->Append(wxID_NEW
, "&New...");
78 file_menu
->Append(wxID_OPEN
, "&Open...");
80 file_menu
->Append(wxID_CLOSE
, "&Close");
81 file_menu
->Append(wxID_SAVE
, "&Save");
82 file_menu
->Append(wxID_SAVEAS
, "Save &As...");
83 file_menu
->AppendSeparator();
84 file_menu
->Append(wxID_PRINT
, "&Print...");
85 file_menu
->Append(wxID_PRINT_SETUP
, "Print &Setup...");
86 file_menu
->Append(wxID_PREVIEW
, "Print Pre&view");
88 edit_menu
= new wxMenu
;
89 edit_menu
->Append(wxID_UNDO
, "&Undo");
90 edit_menu
->Append(wxID_REDO
, "&Redo");
91 edit_menu
->AppendSeparator();
92 edit_menu
->Append(OGLEDIT_CUT
, "&Cut");
93 edit_menu
->AppendSeparator();
94 edit_menu
->Append(OGLEDIT_CHANGE_BACKGROUND_COLOUR
, "Change &background colour");
95 edit_menu
->Append(OGLEDIT_EDIT_LABEL
, "Edit &label");
97 frame
->editMenu
= edit_menu
;
99 file_menu
->AppendSeparator();
100 file_menu
->Append(wxID_EXIT
, "E&xit");
102 // A nice touch: a history of files visited. Use this menu.
103 myDocManager
->FileHistoryUseMenu(file_menu
);
105 wxMenu
*help_menu
= new wxMenu
;
106 help_menu
->Append(OGLEDIT_ABOUT
, "&About");
108 wxMenuBar
*menu_bar
= new wxMenuBar
;
110 menu_bar
->Append(file_menu
, "&File");
112 menu_bar
->Append(edit_menu
, "&Edit");
113 menu_bar
->Append(help_menu
, "&Help");
115 frame
->canvas
= frame
->CreateCanvas(NULL
, frame
);
116 frame
->palette
= wxGetApp().CreatePalette(frame
);
117 myDocManager
->CreateDocument("", wxDOC_NEW
);
119 //// Associate the menu bar with the frame
120 frame
->SetMenuBar(menu_bar
);
122 frame
->CreateStatusBar(1);
124 frame
->Centre(wxBOTH
);
130 int MyApp::OnExit(void)
138 * This is the top-level window of the application.
141 IMPLEMENT_CLASS(MyFrame
, wxDocParentFrame
)
143 BEGIN_EVENT_TABLE(MyFrame
, wxDocParentFrame
)
144 EVT_MENU(OGLEDIT_ABOUT
, MyFrame::OnAbout
)
145 EVT_SIZE(MyFrame::OnSize
)
146 EVT_CLOSE(MyFrame::OnCloseWindow
)
149 MyFrame::MyFrame(wxDocManager
*manager
, wxFrame
*frame
, const wxString
& title
,
150 const wxPoint
& pos
, const wxSize
& size
, long type
):
151 wxDocParentFrame(manager
, frame
, -1, title
, pos
, size
, type
)
158 void MyFrame::OnSize(wxSizeEvent
& event
)
160 if (canvas
&& palette
)
163 GetClientSize(&cw
, &ch
);
168 int canvasX
= paletteX
+ paletteW
;
170 int canvasW
= cw
- paletteW
;
173 palette
->SetSize(paletteX
, paletteY
, paletteW
, paletteH
);
174 canvas
->SetSize(canvasX
, canvasY
, canvasW
, canvasH
);
178 void MyFrame::OnCloseWindow(wxCloseEvent
& event
)
180 wxDocParentFrame::OnCloseWindow(event
);
181 if (!event
.GetVeto())
187 // Intercept menu commands
188 void MyFrame::OnAbout(wxCommandEvent
& event
)
190 (void)wxMessageBox("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", "About OGLEdit");
193 // Creates a canvas. Called by OnInit as a child of the main window
194 MyCanvas
*MyFrame::CreateCanvas(wxView
*view
, wxFrame
*parent
)
197 parent
->GetClientSize(&width
, &height
);
199 // Non-retained canvas
200 MyCanvas
*canvas
= new MyCanvas(view
, parent
, -1, wxPoint(0, 0), wxSize(width
, height
), 0);
201 canvas
->SetCursor(wxCursor(wxCURSOR_HAND
));
203 // Give it scrollbars
204 canvas
->SetScrollbars(20, 20, 50, 50);
209 MyFrame
*GetMainFrame(void)
211 return wxGetApp().frame
;