]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/canvas/simple/simple.cpp
declare the wx2os2PenStyle helper in the header.
[wxWidgets.git] / contrib / samples / canvas / simple / simple.cpp
CommitLineData
f9032263
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: simple.cpp
3// Author: XX
4// Created: XX/XX/XX
5// Copyright:
6/////////////////////////////////////////////////////////////////////////////
7
8#ifdef __GNUG__
9 #pragma implementation "simple.cpp"
10#endif
11
12// For compilers that support precompilation
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
19// Include private headers
20#include "simple.h"
21
22// Include icon header
23#if defined(__WXGTK__) || defined(__WXMOTIF__)
24 #include "mondrian.xpm"
25#endif
26
27// Include image
28#include "smile.xpm"
29
30// WDR: class implementations
31
32//------------------------------------------------------------------------------
33// MyFrame
34//------------------------------------------------------------------------------
35
36// WDR: event table for MyFrame
37
38BEGIN_EVENT_TABLE(MyFrame,wxFrame)
39 EVT_MENU(ID_QUIT, MyFrame::OnQuit)
40 EVT_CLOSE(MyFrame::OnCloseWindow)
41END_EVENT_TABLE()
42
43MyFrame::MyFrame( wxWindow *parent, wxWindowID id, const wxString &title,
44 const wxPoint &position, const wxSize& size, long style ) :
45 wxFrame( parent, id, title, position, size, style )
46{
47 CreateMyMenuBar();
48
49 CreateStatusBar(1);
f03b31e8 50 SetStatusText( "Welcome to wxCanvas sample!" );
f9032263
RR
51
52 SetIcon(wxICON(mondrian));
53
f03b31e8 54 // Create wxCanvasAdmin and wxCanvas.
f9032263
RR
55 m_admin = new wxCanvasAdmin;
56 wxCanvas *canvas = new wxCanvas( m_admin, this, -1 );
f03b31e8 57
8636c073 58 canvas->SetScrollbars( 10, 10, 40, 40 );
f03b31e8
RR
59
60 // The wxCanvasAdmin need to know about all Admin wxCanvas objects.
f9032263 61 m_admin->Append( canvas );
f03b31e8
RR
62
63 // One wxCanvas is the active one (current rendering and current
64 // world coordinates).
f9032263
RR
65 m_admin->SetActive( canvas );
66
f03b31e8 67 // One object group is the root in every canvas.
f9032263
RR
68 wxCanvasObjectGroup *root = new wxCanvasObjectGroup(0,0);
69 root->DeleteContents( TRUE );
70
f03b31e8 71 // Bunch of rects and images.
f9032263
RR
72 wxBitmap bitmap( smile_xpm );
73 wxImage image( bitmap );
74
75 m_smile1 = new wxCanvasImage( image, 0,70,32,32 );
76 root->Append( m_smile1 );
77
8636c073
RR
78 wxCanvasRect *rect = new wxCanvasRect( 20,20,100,100 );
79 rect->SetBrush( *wxRED_BRUSH );
80 root->Append( rect );
81
82/*
f9032263
RR
83 int i;
84 for (i = 10; i < 300; i+=10)
85 {
86 wxCanvasRect *r = new wxCanvasRect( i,50,3,140 );
87 r->SetBrush( *wxRED_BRUSH );
88 root->Append( r );
89 }
8636c073 90*/
f9032263
RR
91
92 m_smile2 = new wxCanvasImage( image, 0,110,32,32 );
93 root->Append( m_smile2 );
94
8636c073 95/*
f9032263
RR
96 for (i = 15; i < 300; i+=10)
97 {
98 wxCanvasRect *r = new wxCanvasRect( i,50,3,140 );
99 r->SetBrush( *wxRED_BRUSH );
100 root->Append( r );
101 }
8636c073 102*/
f9032263 103
f03b31e8
RR
104 // This will call all object and children recursivly so
105 // all know what their wxCanvasAdmin is. Call at the end.
106 root->SetAdmin( m_admin );
107
108 // One object group is the root object.
f9032263
RR
109 canvas->SetRoot( root );
110}
111
112void MyFrame::CreateMyMenuBar()
113{
114 wxMenu *file_menu = new wxMenu;
115 file_menu->Append( ID_QUIT, "Quit...", "Quit program" );
116
117 wxMenuBar *menu_bar = new wxMenuBar();
118 menu_bar->Append( file_menu, "File" );
119
120 SetMenuBar( menu_bar );
121}
122
123// WDR: handler implementations for MyFrame
124
125void MyFrame::OnQuit( wxCommandEvent &event )
126{
127 Close( TRUE );
128}
129
130void MyFrame::OnCloseWindow( wxCloseEvent &event )
131{
132 // if ! saved changes -> return
133
134 Destroy();
135}
136
137//------------------------------------------------------------------------------
138// MyApp
139//------------------------------------------------------------------------------
140
141IMPLEMENT_APP(MyApp)
142
143MyApp::MyApp()
144{
145}
146
147bool MyApp::OnInit()
148{
149 MyFrame *frame = new MyFrame( NULL, -1, "SuperApp", wxPoint(20,20), wxSize(500,340) );
150 frame->Show( TRUE );
151
152 return TRUE;
153}
154
155int MyApp::OnExit()
156{
157 return 0;
158}
159