]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/ogl/ogledit/ogledit.cpp
removed unneeded prototype
[wxWidgets.git] / contrib / samples / ogl / ogledit / ogledit.cpp
CommitLineData
1fc25a89
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".
92a19c2e 17#include "wx/wxprec.h"
1fc25a89
JS
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
618f2efa 36#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
1fc25a89
JS
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.
42IMPLEMENT_APP(MyApp)
43
44MyApp::MyApp(void)
45{
46 frame = NULL;
47 myDocManager= NULL;
48}
49
50// The `main program' equivalent, creating the windows and returning the
51// main frame
52bool MyApp::OnInit(void)
53{
54 wxOGLInitialize();
55
56 //// Create a document manager
57 myDocManager = new wxDocManager;
58
59 //// Create a template relating drawing documents to their views
1484b5cc 60 (void) new wxDocTemplate(myDocManager, _T("Diagram"), _T("*.dia"), wxEmptyString, _T("dia"), _T("Diagram Doc"), _T("Diagram View"),
1fc25a89
JS
61 CLASSINFO(DiagramDocument), CLASSINFO(DiagramView));
62
63 // If we've only got one window, we only get to edit
64 // one document at a time.
65 myDocManager->SetMaxDocsOpen(1);
66
67 //// Create the main frame window
1484b5cc 68 frame = new MyFrame(myDocManager, NULL, _T("OGLEdit Demo"), wxPoint(0, 0), wxSize(500, 400), wxDEFAULT_FRAME_STYLE);
1fc25a89
JS
69
70 //// Give it an icon
71 frame->SetIcon(wxICON(ogl));
72
73 //// Make a menubar
74 wxMenu *file_menu = new wxMenu;
1fc25a89 75
1484b5cc
VS
76 file_menu->Append(wxID_NEW, _T("&New..."));
77 file_menu->Append(wxID_OPEN, _T("&Open..."));
1fc25a89 78
1484b5cc
VS
79 file_menu->Append(wxID_CLOSE, _T("&Close"));
80 file_menu->Append(wxID_SAVE, _T("&Save"));
81 file_menu->Append(wxID_SAVEAS, _T("Save &As..."));
1fc25a89 82 file_menu->AppendSeparator();
1484b5cc
VS
83 file_menu->Append(wxID_PRINT, _T("&Print..."));
84 file_menu->Append(wxID_PRINT_SETUP, _T("Print &Setup..."));
85 file_menu->Append(wxID_PREVIEW, _T("Print Pre&view"));
1fc25a89 86
8552e6f0 87 wxMenu *edit_menu = new wxMenu;
1484b5cc
VS
88 edit_menu->Append(wxID_UNDO, _T("&Undo"));
89 edit_menu->Append(wxID_REDO, _T("&Redo"));
1fc25a89 90 edit_menu->AppendSeparator();
1484b5cc 91 edit_menu->Append(OGLEDIT_CUT, _T("&Cut"));
1fc25a89 92 edit_menu->AppendSeparator();
1484b5cc
VS
93 edit_menu->Append(OGLEDIT_CHANGE_BACKGROUND_COLOUR, _T("Change &background colour"));
94 edit_menu->Append(OGLEDIT_EDIT_LABEL, _T("Edit &label"));
1fc25a89
JS
95
96 frame->editMenu = edit_menu;
97
98 file_menu->AppendSeparator();
1484b5cc 99 file_menu->Append(wxID_EXIT, _T("E&xit"));
1fc25a89
JS
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;
1484b5cc 105 help_menu->Append(OGLEDIT_ABOUT, _T("&About"));
1fc25a89
JS
106
107 wxMenuBar *menu_bar = new wxMenuBar;
108
1484b5cc 109 menu_bar->Append(file_menu, _T("&File"));
1fc25a89 110 if (edit_menu)
1484b5cc
VS
111 menu_bar->Append(edit_menu, _T("&Edit"));
112 menu_bar->Append(help_menu, _T("&Help"));
1fc25a89
JS
113
114 frame->canvas = frame->CreateCanvas(NULL, frame);
115 frame->palette = wxGetApp().CreatePalette(frame);
1484b5cc 116 myDocManager->CreateDocument(wxEmptyString, wxDOC_NEW);
1fc25a89
JS
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
129int MyApp::OnExit(void)
130{
131 wxOGLCleanUp();
132 delete myDocManager;
133 return 0;
134}
135
136/*
137 * This is the top-level window of the application.
138 */
139
140IMPLEMENT_CLASS(MyFrame, wxDocParentFrame)
141
142BEGIN_EVENT_TABLE(MyFrame, wxDocParentFrame)
143 EVT_MENU(OGLEDIT_ABOUT, MyFrame::OnAbout)
144 EVT_SIZE(MyFrame::OnSize)
145 EVT_CLOSE(MyFrame::OnCloseWindow)
146END_EVENT_TABLE()
147
148MyFrame::MyFrame(wxDocManager *manager, wxFrame *frame, const wxString& title,
149 const wxPoint& pos, const wxSize& size, long type):
150 wxDocParentFrame(manager, frame, -1, title, pos, size, type)
151{
152 canvas = NULL;
153 palette = NULL;
154 editMenu = NULL;
155}
156
83ae4c61 157void MyFrame::OnSize(wxSizeEvent& event)
1fc25a89
JS
158{
159 if (canvas && palette)
160 {
161 int cw, ch;
162 GetClientSize(&cw, &ch);
163 int paletteX = 0;
164 int paletteY = 0;
165 int paletteW = 30;
166 int paletteH = ch;
167 int canvasX = paletteX + paletteW;
168 int canvasY = 0;
169 int canvasW = cw - paletteW;
170 int canvasH = ch;
171
172 palette->SetSize(paletteX, paletteY, paletteW, paletteH);
173 canvas->SetSize(canvasX, canvasY, canvasW, canvasH);
174 }
83ae4c61 175 event.Skip();
1fc25a89
JS
176}
177
178void MyFrame::OnCloseWindow(wxCloseEvent& event)
179{
180 wxDocParentFrame::OnCloseWindow(event);
181 if (!event.GetVeto())
182 {
183 wxOGLCleanUp();
184 }
185}
186
187// Intercept menu commands
1484b5cc 188void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
1fc25a89 189{
1484b5cc 190 (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
191}
192
193// Creates a canvas. Called by OnInit as a child of the main window
194MyCanvas *MyFrame::CreateCanvas(wxView *view, wxFrame *parent)
195{
196 int width, height;
197 parent->GetClientSize(&width, &height);
198
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));
202
203 // Give it scrollbars
204 canvas->SetScrollbars(20, 20, 50, 50);
205
206 return canvas;
207}
208
209MyFrame *GetMainFrame(void)
210{
211 return wxGetApp().frame;
212}
213