]>
Commit | Line | Data |
---|---|---|
f449ef69 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: ogledit.cpp | |
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 | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | // #pragma implementation | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include <wx/wxprec.h> | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include <wx/wx.h> | |
25 | #endif | |
26 | ||
27 | #if !USE_DOC_VIEW_ARCHITECTURE | |
28 | #error You must set USE_DOC_VIEW_ARCHITECTURE to 1 in wx_setup.h! | |
29 | #endif | |
30 | ||
31 | #include "ogledit.h" | |
32 | #include "palette.h" | |
33 | #include "doc.h" | |
34 | #include "view.h" | |
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 | ||
f449ef69 JS |
40 | MyApp::MyApp(void) |
41 | { | |
42 | frame = NULL; | |
43 | } | |
44 | ||
45 | // The `main program' equivalent, creating the windows and returning the | |
46 | // main frame | |
47 | bool MyApp::OnInit(void) | |
48 | { | |
49 | wxOGLInitialize(); | |
50 | ||
51 | //// Create a document manager | |
52 | wxDocManager *myDocManager = new wxDocManager; | |
53 | ||
54 | //// Create a template relating drawing documents to their views | |
55 | (void) new wxDocTemplate(myDocManager, "Diagram", "*.dia", "", "dia", "Diagram Doc", "Diagram View", | |
56 | CLASSINFO(DiagramDocument), CLASSINFO(DiagramView)); | |
57 | ||
58 | // If we've only got one window, we only get to edit | |
59 | // one document at a time. | |
60 | myDocManager->SetMaxDocsOpen(1); | |
61 | ||
62 | //// Create the main frame window | |
63 | frame = new MyFrame(myDocManager, NULL, "OGLEdit Demo", wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE); | |
64 | ||
65 | //// Give it an icon | |
66 | #ifdef __WXMSW__ | |
67 | frame->SetIcon(wxIcon("ogl_icn")); | |
68 | #endif | |
69 | #ifdef __X__ | |
70 | frame->SetIcon(wxIcon("ogl.xbm")); | |
71 | #endif | |
72 | ||
73 | //// Make a menubar | |
74 | wxMenu *file_menu = new wxMenu; | |
75 | wxMenu *edit_menu = NULL; | |
76 | ||
77 | file_menu->Append(wxID_NEW, "&New..."); | |
78 | file_menu->Append(wxID_OPEN, "&Open..."); | |
79 | ||
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"); | |
87 | ||
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"); | |
96 | ||
97 | frame->editMenu = edit_menu; | |
98 | ||
99 | file_menu->AppendSeparator(); | |
100 | file_menu->Append(wxID_EXIT, "E&xit"); | |
101 | ||
102 | // A nice touch: a history of files visited. Use this menu. | |
103 | myDocManager->FileHistoryUseMenu(file_menu); | |
104 | ||
105 | wxMenu *help_menu = new wxMenu; | |
106 | help_menu->Append(OGLEDIT_ABOUT, "&About"); | |
107 | ||
108 | wxMenuBar *menu_bar = new wxMenuBar; | |
109 | ||
110 | menu_bar->Append(file_menu, "&File"); | |
111 | if (edit_menu) | |
112 | menu_bar->Append(edit_menu, "&Edit"); | |
113 | menu_bar->Append(help_menu, "&Help"); | |
114 | ||
115 | frame->canvas = frame->CreateCanvas(NULL, frame); | |
34138703 | 116 | frame->palette = wxGetApp().CreatePalette(frame); |
f449ef69 JS |
117 | myDocManager->CreateDocument("", wxDOC_NEW); |
118 | ||
119 | //// Associate the menu bar with the frame | |
120 | frame->SetMenuBar(menu_bar); | |
121 | ||
122 | frame->CreateStatusBar(1); | |
123 | ||
124 | frame->Centre(wxBOTH); | |
125 | frame->Show(TRUE); | |
126 | ||
127 | return TRUE; | |
128 | } | |
129 | ||
130 | /* | |
131 | * This is the top-level window of the application. | |
132 | */ | |
133 | ||
134 | IMPLEMENT_CLASS(MyFrame, wxDocParentFrame) | |
135 | ||
136 | BEGIN_EVENT_TABLE(MyFrame, wxDocParentFrame) | |
137 | EVT_MENU(OGLEDIT_ABOUT, MyFrame::OnAbout) | |
138 | EVT_SIZE(MyFrame::OnSize) | |
139 | END_EVENT_TABLE() | |
140 | ||
141 | MyFrame::MyFrame(wxDocManager *manager, wxFrame *frame, const wxString& title, | |
142 | const wxPoint& pos, const wxSize& size, long type): | |
143 | wxDocParentFrame(manager, frame, -1, title, pos, size, type) | |
144 | { | |
145 | canvas = NULL; | |
146 | palette = NULL; | |
147 | editMenu = NULL; | |
148 | } | |
149 | ||
150 | void MyFrame::OnSize(wxSizeEvent& event) | |
151 | { | |
152 | if (canvas && palette) | |
153 | { | |
154 | int cw, ch; | |
155 | GetClientSize(&cw, &ch); | |
156 | int paletteX = 0; | |
157 | int paletteY = 0; | |
158 | int paletteW = 30; | |
159 | int paletteH = ch; | |
160 | int canvasX = paletteX + paletteW; | |
161 | int canvasY = 0; | |
162 | int canvasW = cw - paletteW; | |
163 | int canvasH = ch; | |
164 | ||
165 | palette->SetSize(paletteX, paletteY, paletteW, paletteH); | |
166 | canvas->SetSize(canvasX, canvasY, canvasW, canvasH); | |
167 | } | |
168 | } | |
169 | ||
170 | bool MyFrame::OnClose(void) | |
171 | { | |
172 | if (wxDocParentFrame::OnClose()) | |
173 | { | |
174 | wxOGLCleanUp(); | |
175 | return TRUE; | |
176 | } | |
177 | else | |
178 | return FALSE; | |
179 | } | |
180 | ||
181 | // Intercept menu commands | |
182 | void MyFrame::OnAbout(wxCommandEvent& event) | |
183 | { | |
184 | (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"); | |
185 | } | |
186 | ||
187 | // Creates a canvas. Called by OnInit as a child of the main window | |
188 | MyCanvas *MyFrame::CreateCanvas(wxView *view, wxFrame *parent) | |
189 | { | |
190 | int width, height; | |
191 | parent->GetClientSize(&width, &height); | |
192 | ||
193 | // Non-retained canvas | |
194 | MyCanvas *canvas = new MyCanvas(view, parent, -1, wxPoint(0, 0), wxSize(width, height), 0); | |
195 | wxCursor *cursor = new wxCursor(wxCURSOR_HAND); | |
196 | canvas->SetCursor(cursor); | |
197 | ||
198 | // Give it scrollbars | |
199 | canvas->SetScrollbars(20, 20, 50, 50); | |
200 | ||
201 | return canvas; | |
202 | } | |
203 | ||
204 | MyFrame *GetMainFrame(void) | |
205 | { | |
34138703 | 206 | return wxGetApp().frame; |
f449ef69 JS |
207 | } |
208 |