]>
Commit | Line | Data |
---|---|---|
1fc25a89 | 1 | ///////////////////////////////////////////////////////////////////////////// |
f4ec6bd2 | 2 | // Name: contrib/samples/ogl/ogledit/ogledit.cpp |
1fc25a89 JS |
3 | // Purpose: OGLEdit sample app |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 12/07/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
2ba06d5a | 9 | // Licence: wxWindows licence |
1fc25a89 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
1fc25a89 | 12 | // For compilers that support precompilation, includes "wx.h". |
92a19c2e | 13 | #include "wx/wxprec.h" |
1fc25a89 JS |
14 | |
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
19 | #ifndef WX_PRECOMP | |
f4ec6bd2 | 20 | #include "wx/wx.h" |
1fc25a89 JS |
21 | #endif |
22 | ||
23 | #if !wxUSE_DOC_VIEW_ARCHITECTURE | |
24 | #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in wx_setup.h! | |
25 | #endif | |
26 | ||
27 | #include "ogledit.h" | |
28 | #include "palette.h" | |
29 | #include "doc.h" | |
30 | #include "view.h" | |
31 | ||
4219b5e7 WS |
32 | #ifndef __WXMSW__ |
33 | #include "ogl.xpm" | |
1fc25a89 JS |
34 | #endif |
35 | ||
36 | // A macro needed for some compilers (AIX) that need 'main' to be defined | |
37 | // in the application itself. | |
38 | IMPLEMENT_APP(MyApp) | |
39 | ||
40 | MyApp::MyApp(void) | |
41 | { | |
42 | frame = NULL; | |
43 | myDocManager= NULL; | |
44 | } | |
45 | ||
46 | // The `main program' equivalent, creating the windows and returning the | |
47 | // main frame | |
48 | bool MyApp::OnInit(void) | |
49 | { | |
50 | wxOGLInitialize(); | |
cecdcad1 | 51 | |
1fc25a89 JS |
52 | //// Create a document manager |
53 | myDocManager = new wxDocManager; | |
54 | ||
55 | //// Create a template relating drawing documents to their views | |
1484b5cc | 56 | (void) new wxDocTemplate(myDocManager, _T("Diagram"), _T("*.dia"), wxEmptyString, _T("dia"), _T("Diagram Doc"), _T("Diagram View"), |
1fc25a89 JS |
57 | CLASSINFO(DiagramDocument), CLASSINFO(DiagramView)); |
58 | ||
59 | // If we've only got one window, we only get to edit | |
60 | // one document at a time. | |
61 | myDocManager->SetMaxDocsOpen(1); | |
62 | ||
63 | //// Create the main frame window | |
1484b5cc | 64 | frame = new MyFrame(myDocManager, NULL, _T("OGLEdit Demo"), wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE); |
1fc25a89 JS |
65 | |
66 | //// Give it an icon | |
67 | frame->SetIcon(wxICON(ogl)); | |
68 | ||
69 | //// Make a menubar | |
70 | wxMenu *file_menu = new wxMenu; | |
1fc25a89 | 71 | |
1484b5cc VS |
72 | file_menu->Append(wxID_NEW, _T("&New...")); |
73 | file_menu->Append(wxID_OPEN, _T("&Open...")); | |
1fc25a89 | 74 | |
1484b5cc VS |
75 | file_menu->Append(wxID_CLOSE, _T("&Close")); |
76 | file_menu->Append(wxID_SAVE, _T("&Save")); | |
77 | file_menu->Append(wxID_SAVEAS, _T("Save &As...")); | |
1fc25a89 | 78 | file_menu->AppendSeparator(); |
1484b5cc VS |
79 | file_menu->Append(wxID_PRINT, _T("&Print...")); |
80 | file_menu->Append(wxID_PRINT_SETUP, _T("Print &Setup...")); | |
81 | file_menu->Append(wxID_PREVIEW, _T("Print Pre&view")); | |
1fc25a89 | 82 | |
8552e6f0 | 83 | wxMenu *edit_menu = new wxMenu; |
1484b5cc VS |
84 | edit_menu->Append(wxID_UNDO, _T("&Undo")); |
85 | edit_menu->Append(wxID_REDO, _T("&Redo")); | |
1fc25a89 | 86 | edit_menu->AppendSeparator(); |
cecdcad1 | 87 | edit_menu->Append(wxID_CUT, _T("&Cut")); |
1fc25a89 | 88 | edit_menu->AppendSeparator(); |
1484b5cc VS |
89 | edit_menu->Append(OGLEDIT_CHANGE_BACKGROUND_COLOUR, _T("Change &background colour")); |
90 | edit_menu->Append(OGLEDIT_EDIT_LABEL, _T("Edit &label")); | |
1fc25a89 JS |
91 | |
92 | frame->editMenu = edit_menu; | |
cecdcad1 | 93 | |
1fc25a89 | 94 | file_menu->AppendSeparator(); |
1484b5cc | 95 | file_menu->Append(wxID_EXIT, _T("E&xit")); |
1fc25a89 JS |
96 | |
97 | // A nice touch: a history of files visited. Use this menu. | |
98 | myDocManager->FileHistoryUseMenu(file_menu); | |
99 | ||
100 | wxMenu *help_menu = new wxMenu; | |
1484b5cc | 101 | help_menu->Append(OGLEDIT_ABOUT, _T("&About")); |
1fc25a89 JS |
102 | |
103 | wxMenuBar *menu_bar = new wxMenuBar; | |
104 | ||
1484b5cc | 105 | menu_bar->Append(file_menu, _T("&File")); |
1fc25a89 | 106 | if (edit_menu) |
1484b5cc VS |
107 | menu_bar->Append(edit_menu, _T("&Edit")); |
108 | menu_bar->Append(help_menu, _T("&Help")); | |
1fc25a89 JS |
109 | |
110 | frame->canvas = frame->CreateCanvas(NULL, frame); | |
111 | frame->palette = wxGetApp().CreatePalette(frame); | |
1484b5cc | 112 | myDocManager->CreateDocument(wxEmptyString, wxDOC_NEW); |
1fc25a89 JS |
113 | |
114 | //// Associate the menu bar with the frame | |
115 | frame->SetMenuBar(menu_bar); | |
116 | ||
d96cdd4a | 117 | #if wxUSE_STATUSBAR |
1fc25a89 | 118 | frame->CreateStatusBar(1); |
d96cdd4a | 119 | #endif // wxUSE_STATUSBAR |
1fc25a89 JS |
120 | |
121 | frame->Centre(wxBOTH); | |
2ba06d5a | 122 | frame->Show(true); |
1fc25a89 | 123 | |
2ba06d5a | 124 | return true; |
1fc25a89 JS |
125 | } |
126 | ||
127 | int MyApp::OnExit(void) | |
128 | { | |
129 | wxOGLCleanUp(); | |
130 | delete myDocManager; | |
131 | return 0; | |
132 | } | |
133 | ||
134 | /* | |
135 | * This is the top-level window of the application. | |
136 | */ | |
137 | ||
138 | IMPLEMENT_CLASS(MyFrame, wxDocParentFrame) | |
139 | ||
140 | BEGIN_EVENT_TABLE(MyFrame, wxDocParentFrame) | |
141 | EVT_MENU(OGLEDIT_ABOUT, MyFrame::OnAbout) | |
142 | EVT_SIZE(MyFrame::OnSize) | |
143 | EVT_CLOSE(MyFrame::OnCloseWindow) | |
144 | END_EVENT_TABLE() | |
145 | ||
146 | MyFrame::MyFrame(wxDocManager *manager, wxFrame *frame, const wxString& title, | |
147 | const wxPoint& pos, const wxSize& size, long type): | |
2ba06d5a | 148 | wxDocParentFrame(manager, frame, wxID_ANY, title, pos, size, type) |
1fc25a89 JS |
149 | { |
150 | canvas = NULL; | |
151 | palette = NULL; | |
152 | editMenu = NULL; | |
153 | } | |
154 | ||
83ae4c61 | 155 | void MyFrame::OnSize(wxSizeEvent& event) |
1fc25a89 JS |
156 | { |
157 | if (canvas && palette) | |
158 | { | |
159 | int cw, ch; | |
160 | GetClientSize(&cw, &ch); | |
161 | int paletteX = 0; | |
162 | int paletteY = 0; | |
163 | int paletteW = 30; | |
164 | int paletteH = ch; | |
165 | int canvasX = paletteX + paletteW; | |
166 | int canvasY = 0; | |
167 | int canvasW = cw - paletteW; | |
168 | int canvasH = ch; | |
cecdcad1 | 169 | |
1fc25a89 JS |
170 | palette->SetSize(paletteX, paletteY, paletteW, paletteH); |
171 | canvas->SetSize(canvasX, canvasY, canvasW, canvasH); | |
172 | } | |
83ae4c61 | 173 | event.Skip(); |
1fc25a89 JS |
174 | } |
175 | ||
176 | void MyFrame::OnCloseWindow(wxCloseEvent& event) | |
177 | { | |
178 | wxDocParentFrame::OnCloseWindow(event); | |
179 | if (!event.GetVeto()) | |
180 | { | |
181 | wxOGLCleanUp(); | |
182 | } | |
183 | } | |
184 | ||
185 | // Intercept menu commands | |
1484b5cc | 186 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
1fc25a89 | 187 | { |
1484b5cc | 188 | (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")); |
1fc25a89 JS |
189 | } |
190 | ||
191 | // Creates a canvas. Called by OnInit as a child of the main window | |
192 | MyCanvas *MyFrame::CreateCanvas(wxView *view, wxFrame *parent) | |
193 | { | |
194 | int width, height; | |
195 | parent->GetClientSize(&width, &height); | |
196 | ||
197 | // Non-retained canvas | |
2ba06d5a | 198 | MyCanvas *canvas = new MyCanvas(view, parent, wxID_ANY, wxPoint(0, 0), wxSize(width, height), 0); |
1fc25a89 JS |
199 | canvas->SetCursor(wxCursor(wxCURSOR_HAND)); |
200 | ||
201 | // Give it scrollbars | |
202 | canvas->SetScrollbars(20, 20, 50, 50); | |
203 | ||
204 | return canvas; | |
205 | } | |
206 | ||
207 | MyFrame *GetMainFrame(void) | |
208 | { | |
209 | return wxGetApp().frame; | |
210 | } |