]> git.saurik.com Git - wxWidgets.git/blob - utils/ogl/samples/ogledit/ogledit.cpp
Added missing OGL files; added defaults to wxDocMDIParentFrame; corrected
[wxWidgets.git] / utils / ogl / samples / ogledit / ogledit.cpp
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
40 // This statement initialises the whole application
41 MyApp myApp;
42
43 MyApp::MyApp(void)
44 {
45 frame = NULL;
46 }
47
48 // The `main program' equivalent, creating the windows and returning the
49 // main frame
50 bool MyApp::OnInit(void)
51 {
52 wxOGLInitialize();
53
54 //// Create a document manager
55 wxDocManager *myDocManager = new wxDocManager;
56
57 //// Create a template relating drawing documents to their views
58 (void) new wxDocTemplate(myDocManager, "Diagram", "*.dia", "", "dia", "Diagram Doc", "Diagram View",
59 CLASSINFO(DiagramDocument), CLASSINFO(DiagramView));
60
61 // If we've only got one window, we only get to edit
62 // one document at a time.
63 myDocManager->SetMaxDocsOpen(1);
64
65 //// Create the main frame window
66 frame = new MyFrame(myDocManager, NULL, "OGLEdit Demo", wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE);
67
68 //// Give it an icon
69 #ifdef __WXMSW__
70 frame->SetIcon(wxIcon("ogl_icn"));
71 #endif
72 #ifdef __X__
73 frame->SetIcon(wxIcon("ogl.xbm"));
74 #endif
75
76 //// Make a menubar
77 wxMenu *file_menu = new wxMenu;
78 wxMenu *edit_menu = NULL;
79
80 file_menu->Append(wxID_NEW, "&New...");
81 file_menu->Append(wxID_OPEN, "&Open...");
82
83 file_menu->Append(wxID_CLOSE, "&Close");
84 file_menu->Append(wxID_SAVE, "&Save");
85 file_menu->Append(wxID_SAVEAS, "Save &As...");
86 file_menu->AppendSeparator();
87 file_menu->Append(wxID_PRINT, "&Print...");
88 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
89 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
90
91 edit_menu = new wxMenu;
92 edit_menu->Append(wxID_UNDO, "&Undo");
93 edit_menu->Append(wxID_REDO, "&Redo");
94 edit_menu->AppendSeparator();
95 edit_menu->Append(OGLEDIT_CUT, "&Cut");
96 edit_menu->AppendSeparator();
97 edit_menu->Append(OGLEDIT_CHANGE_BACKGROUND_COLOUR, "Change &background colour");
98 edit_menu->Append(OGLEDIT_EDIT_LABEL, "Edit &label");
99
100 frame->editMenu = edit_menu;
101
102 file_menu->AppendSeparator();
103 file_menu->Append(wxID_EXIT, "E&xit");
104
105 // A nice touch: a history of files visited. Use this menu.
106 myDocManager->FileHistoryUseMenu(file_menu);
107
108 wxMenu *help_menu = new wxMenu;
109 help_menu->Append(OGLEDIT_ABOUT, "&About");
110
111 wxMenuBar *menu_bar = new wxMenuBar;
112
113 menu_bar->Append(file_menu, "&File");
114 if (edit_menu)
115 menu_bar->Append(edit_menu, "&Edit");
116 menu_bar->Append(help_menu, "&Help");
117
118 frame->canvas = frame->CreateCanvas(NULL, frame);
119 frame->palette = myApp.CreatePalette(frame);
120 myDocManager->CreateDocument("", wxDOC_NEW);
121
122 //// Associate the menu bar with the frame
123 frame->SetMenuBar(menu_bar);
124
125 frame->CreateStatusBar(1);
126
127 frame->Centre(wxBOTH);
128 frame->Show(TRUE);
129
130 return TRUE;
131 }
132
133 /*
134 * This is the top-level window of the application.
135 */
136
137 IMPLEMENT_CLASS(MyFrame, wxDocParentFrame)
138
139 BEGIN_EVENT_TABLE(MyFrame, wxDocParentFrame)
140 EVT_MENU(OGLEDIT_ABOUT, MyFrame::OnAbout)
141 EVT_SIZE(MyFrame::OnSize)
142 END_EVENT_TABLE()
143
144 MyFrame::MyFrame(wxDocManager *manager, wxFrame *frame, const wxString& title,
145 const wxPoint& pos, const wxSize& size, long type):
146 wxDocParentFrame(manager, frame, -1, title, pos, size, type)
147 {
148 canvas = NULL;
149 palette = NULL;
150 editMenu = NULL;
151 }
152
153 void MyFrame::OnSize(wxSizeEvent& event)
154 {
155 if (canvas && palette)
156 {
157 int cw, ch;
158 GetClientSize(&cw, &ch);
159 int paletteX = 0;
160 int paletteY = 0;
161 int paletteW = 30;
162 int paletteH = ch;
163 int canvasX = paletteX + paletteW;
164 int canvasY = 0;
165 int canvasW = cw - paletteW;
166 int canvasH = ch;
167
168 palette->SetSize(paletteX, paletteY, paletteW, paletteH);
169 canvas->SetSize(canvasX, canvasY, canvasW, canvasH);
170 }
171 }
172
173 bool MyFrame::OnClose(void)
174 {
175 if (wxDocParentFrame::OnClose())
176 {
177 wxOGLCleanUp();
178 return TRUE;
179 }
180 else
181 return FALSE;
182 }
183
184 // Intercept menu commands
185 void MyFrame::OnAbout(wxCommandEvent& event)
186 {
187 (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");
188 }
189
190 // Creates a canvas. Called by OnInit as a child of the main window
191 MyCanvas *MyFrame::CreateCanvas(wxView *view, wxFrame *parent)
192 {
193 int width, height;
194 parent->GetClientSize(&width, &height);
195
196 // Non-retained canvas
197 MyCanvas *canvas = new MyCanvas(view, parent, -1, wxPoint(0, 0), wxSize(width, height), 0);
198 wxCursor *cursor = new wxCursor(wxCURSOR_HAND);
199 canvas->SetCursor(cursor);
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 myApp.frame;
210 }
211