2000-03-03 06:25:10 -05:00
/////////////////////////////////////////////////////////////////////////////
// Name: ogledit.cpp
// Purpose: OGLEdit sample app
// Author: Julian Smart
// Modified by:
// Created: 12/07/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
# ifdef __GNUG__
// #pragma implementation
# endif
// For compilers that support precompilation, includes "wx.h".
2001-10-30 08:33:34 -05:00
# include "wx/wxprec.h"
2000-03-03 06:25:10 -05:00
# ifdef __BORLANDC__
# pragma hdrstop
# endif
# ifndef WX_PRECOMP
# include <wx/wx.h>
# endif
# if !wxUSE_DOC_VIEW_ARCHITECTURE
# error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in wx_setup.h!
# endif
# include "ogledit.h"
# include "palette.h"
# include "doc.h"
# include "view.h"
2002-03-21 05:32:18 -05:00
# if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
2000-03-03 06:25:10 -05:00
# include "ogl.xpm"
# endif
// A macro needed for some compilers (AIX) that need 'main' to be defined
// in the application itself.
IMPLEMENT_APP ( MyApp )
MyApp : : MyApp ( void )
{
frame = NULL ;
myDocManager = NULL ;
}
// The `main program' equivalent, creating the windows and returning the
// main frame
bool MyApp : : OnInit ( void )
{
wxOGLInitialize ( ) ;
//// Create a document manager
myDocManager = new wxDocManager ;
//// Create a template relating drawing documents to their views
2003-08-21 05:05:56 -04:00
( void ) new wxDocTemplate ( myDocManager , _T ( " Diagram " ) , _T ( " *.dia " ) , wxEmptyString , _T ( " dia " ) , _T ( " Diagram Doc " ) , _T ( " Diagram View " ) ,
2000-03-03 06:25:10 -05:00
CLASSINFO ( DiagramDocument ) , CLASSINFO ( DiagramView ) ) ;
// If we've only got one window, we only get to edit
// one document at a time.
myDocManager - > SetMaxDocsOpen ( 1 ) ;
//// Create the main frame window
2003-08-21 05:05:56 -04:00
frame = new MyFrame ( myDocManager , NULL , _T ( " OGLEdit Demo " ) , wxPoint ( 0 , 0 ) , wxSize ( 500 , 400 ) , wxDEFAULT_FRAME_STYLE ) ;
2000-03-03 06:25:10 -05:00
//// Give it an icon
frame - > SetIcon ( wxICON ( ogl ) ) ;
//// Make a menubar
wxMenu * file_menu = new wxMenu ;
wxMenu * edit_menu = NULL ;
2003-08-21 05:05:56 -04:00
file_menu - > Append ( wxID_NEW , _T ( " &New... " ) ) ;
file_menu - > Append ( wxID_OPEN , _T ( " &Open... " ) ) ;
2000-03-03 06:25:10 -05:00
2003-08-21 05:05:56 -04:00
file_menu - > Append ( wxID_CLOSE , _T ( " &Close " ) ) ;
file_menu - > Append ( wxID_SAVE , _T ( " &Save " ) ) ;
file_menu - > Append ( wxID_SAVEAS , _T ( " Save &As... " ) ) ;
2000-03-03 06:25:10 -05:00
file_menu - > AppendSeparator ( ) ;
2003-08-21 05:05:56 -04:00
file_menu - > Append ( wxID_PRINT , _T ( " &Print... " ) ) ;
file_menu - > Append ( wxID_PRINT_SETUP , _T ( " Print &Setup... " ) ) ;
file_menu - > Append ( wxID_PREVIEW , _T ( " Print Pre&view " ) ) ;
2000-03-03 06:25:10 -05:00
edit_menu = new wxMenu ;
2003-08-21 05:05:56 -04:00
edit_menu - > Append ( wxID_UNDO , _T ( " &Undo " ) ) ;
edit_menu - > Append ( wxID_REDO , _T ( " &Redo " ) ) ;
2000-03-03 06:25:10 -05:00
edit_menu - > AppendSeparator ( ) ;
2003-08-21 05:05:56 -04:00
edit_menu - > Append ( OGLEDIT_CUT , _T ( " &Cut " ) ) ;
2000-03-03 06:25:10 -05:00
edit_menu - > AppendSeparator ( ) ;
2003-08-21 05:05:56 -04:00
edit_menu - > Append ( OGLEDIT_CHANGE_BACKGROUND_COLOUR , _T ( " Change &background colour " ) ) ;
edit_menu - > Append ( OGLEDIT_EDIT_LABEL , _T ( " Edit &label " ) ) ;
2000-03-03 06:25:10 -05:00
frame - > editMenu = edit_menu ;
file_menu - > AppendSeparator ( ) ;
2003-08-21 05:05:56 -04:00
file_menu - > Append ( wxID_EXIT , _T ( " E&xit " ) ) ;
2000-03-03 06:25:10 -05:00
// A nice touch: a history of files visited. Use this menu.
myDocManager - > FileHistoryUseMenu ( file_menu ) ;
wxMenu * help_menu = new wxMenu ;
2003-08-21 05:05:56 -04:00
help_menu - > Append ( OGLEDIT_ABOUT , _T ( " &About " ) ) ;
2000-03-03 06:25:10 -05:00
wxMenuBar * menu_bar = new wxMenuBar ;
2003-08-21 05:05:56 -04:00
menu_bar - > Append ( file_menu , _T ( " &File " ) ) ;
2000-03-03 06:25:10 -05:00
if ( edit_menu )
2003-08-21 05:05:56 -04:00
menu_bar - > Append ( edit_menu , _T ( " &Edit " ) ) ;
menu_bar - > Append ( help_menu , _T ( " &Help " ) ) ;
2000-03-03 06:25:10 -05:00
frame - > canvas = frame - > CreateCanvas ( NULL , frame ) ;
frame - > palette = wxGetApp ( ) . CreatePalette ( frame ) ;
2003-08-21 05:05:56 -04:00
myDocManager - > CreateDocument ( wxEmptyString , wxDOC_NEW ) ;
2000-03-03 06:25:10 -05:00
//// Associate the menu bar with the frame
frame - > SetMenuBar ( menu_bar ) ;
frame - > CreateStatusBar ( 1 ) ;
frame - > Centre ( wxBOTH ) ;
frame - > Show ( TRUE ) ;
return TRUE ;
}
int MyApp : : OnExit ( void )
{
wxOGLCleanUp ( ) ;
delete myDocManager ;
return 0 ;
}
/*
* This is the top - level window of the application .
*/
IMPLEMENT_CLASS ( MyFrame , wxDocParentFrame )
BEGIN_EVENT_TABLE ( MyFrame , wxDocParentFrame )
EVT_MENU ( OGLEDIT_ABOUT , MyFrame : : OnAbout )
EVT_SIZE ( MyFrame : : OnSize )
EVT_CLOSE ( MyFrame : : OnCloseWindow )
END_EVENT_TABLE ( )
MyFrame : : MyFrame ( wxDocManager * manager , wxFrame * frame , const wxString & title ,
const wxPoint & pos , const wxSize & size , long type ) :
wxDocParentFrame ( manager , frame , - 1 , title , pos , size , type )
{
canvas = NULL ;
palette = NULL ;
editMenu = NULL ;
}
2003-08-21 05:05:56 -04:00
void MyFrame : : OnSize ( wxSizeEvent & WXUNUSED ( event ) )
2000-03-03 06:25:10 -05:00
{
if ( canvas & & palette )
{
int cw , ch ;
GetClientSize ( & cw , & ch ) ;
int paletteX = 0 ;
int paletteY = 0 ;
int paletteW = 30 ;
int paletteH = ch ;
int canvasX = paletteX + paletteW ;
int canvasY = 0 ;
int canvasW = cw - paletteW ;
int canvasH = ch ;
palette - > SetSize ( paletteX , paletteY , paletteW , paletteH ) ;
canvas - > SetSize ( canvasX , canvasY , canvasW , canvasH ) ;
}
}
void MyFrame : : OnCloseWindow ( wxCloseEvent & event )
{
wxDocParentFrame : : OnCloseWindow ( event ) ;
if ( ! event . GetVeto ( ) )
{
wxOGLCleanUp ( ) ;
}
}
// Intercept menu commands
2003-08-21 05:05:56 -04:00
void MyFrame : : OnAbout ( wxCommandEvent & WXUNUSED ( event ) )
2000-03-03 06:25:10 -05:00
{
2003-08-21 05:05:56 -04:00
( void ) wxMessageBox ( _T ( " OGLEdit Demo \n To draw a shape, select a shape on the toolbar and left-click on the canvas. \n To draw a line, right-drag between shapes. \n For further details, see the OGL manual. \n (c) Julian Smart 1996 " ) , _T ( " About OGLEdit " ) ) ;
2000-03-03 06:25:10 -05:00
}
// Creates a canvas. Called by OnInit as a child of the main window
MyCanvas * MyFrame : : CreateCanvas ( wxView * view , wxFrame * parent )
{
int width , height ;
parent - > GetClientSize ( & width , & height ) ;
// Non-retained canvas
MyCanvas * canvas = new MyCanvas ( view , parent , - 1 , wxPoint ( 0 , 0 ) , wxSize ( width , height ) , 0 ) ;
canvas - > SetCursor ( wxCursor ( wxCURSOR_HAND ) ) ;
// Give it scrollbars
canvas - > SetScrollbars ( 20 , 20 , 50 , 50 ) ;
return canvas ;
}
MyFrame * GetMainFrame ( void )
{
return wxGetApp ( ) . frame ;
}