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