Next take at radioboxes
[wxWidgets.git] / samples / scroll / scroll.cpp
1 /*
2 * Program: scroll
3 *
4 * Author: Robert Roebling
5 *
6 * Copyright: (C) 1998, Robert Roebling
7 *
8 */
9
10 // For compilers that support precompilation, includes "wx/wx.h".
11 #include "wx/wxprec.h"
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 #ifndef WX_PRECOMP
18 #include "wx/wx.h"
19 #endif
20
21 #include "wx/image.h"
22 #include "wx/listctrl.h"
23
24 // derived classes
25
26 class MyFrame;
27 class MyApp;
28
29 // MyCanvas
30
31 class MyCanvas: public wxScrolledWindow
32 {
33 public:
34 MyCanvas() {};
35 MyCanvas( wxWindow *parent, wxWindowID, const wxPoint &pos, const wxSize &size );
36 ~MyCanvas();
37 void OnPaint( wxPaintEvent &event );
38
39 DECLARE_DYNAMIC_CLASS(MyCanvas)
40 DECLARE_EVENT_TABLE()
41 };
42
43 // MyFrame
44
45 class MyFrame: public wxFrame
46 {
47 public:
48 MyFrame();
49
50 void OnAbout( wxCommandEvent &event );
51 void OnQuit( wxCommandEvent &event );
52
53 MyCanvas *m_canvas;
54
55 DECLARE_DYNAMIC_CLASS(MyFrame)
56 DECLARE_EVENT_TABLE()
57 };
58
59 // MyApp
60
61 class MyApp: public wxApp
62 {
63 public:
64 virtual bool OnInit();
65 };
66
67 // main program
68
69 IMPLEMENT_APP(MyApp)
70
71 // MyCanvas
72
73 IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow)
74
75 BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
76 EVT_PAINT(MyCanvas::OnPaint)
77 END_EVENT_TABLE()
78
79 MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
80 const wxPoint &pos, const wxSize &size )
81 : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER | wxTAB_TRAVERSAL )
82 {
83 wxString choices[] =
84 {
85 "This",
86 "is one of my",
87 "really",
88 "wonderful",
89 "examples."
90 };
91
92 (void) new wxButton( this, -1, "wxButton", wxPoint(10,10) );
93
94 (void) new wxTextCtrl( this, -1, "wxTextCtrl", wxPoint(10,50) );
95
96 (void) new wxRadioButton( this, -1, "Disable", wxPoint(10,90) );
97
98 (void) new wxComboBox( this, -1, "This", wxPoint(10,130), wxDefaultSize, 5, choices );
99
100 (void) new wxRadioBox( this, -1, "This", wxPoint(10,200), wxDefaultSize, 5, choices, 2, wxRA_SPECIFY_COLS );
101
102 (void) new wxRadioBox( this, -1, "This", wxPoint(10,300), wxDefaultSize, 5, choices, 2, wxRA_SPECIFY_ROWS );
103
104 wxListCtrl *m_listCtrl = new wxListCtrl(
105 this, -1, wxPoint(200, 10), wxSize(180, 120),
106 wxLC_REPORT | wxSUNKEN_BORDER | wxLC_SINGLE_SEL );
107
108 m_listCtrl->InsertColumn(0, "First", wxLIST_FORMAT_LEFT, 90);
109 m_listCtrl->InsertColumn(1, "Last", wxLIST_FORMAT_LEFT, 90);
110
111 for ( int i=0; i < 30; i++)
112 {
113 char buf[20];
114 sprintf(buf, "Item %d", i);
115 m_listCtrl->InsertItem(i, buf);
116 }
117 m_listCtrl->SetItemState( 3, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
118
119 (void) new wxListBox( this, -1, wxPoint(200,180), wxSize(180,120), 5, choices, wxLB_ALWAYS_SB );
120
121 SetBackgroundColour( "WHEAT" );
122 }
123
124 MyCanvas::~MyCanvas()
125 {
126 }
127
128 void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
129 {
130 wxPaintDC dc( this );
131 PrepareDC( dc );
132
133 dc.DrawText( "Some text", 110, 10 );
134
135 dc.DrawRectangle( 50, 30, 200, 200 );
136 }
137
138 // MyFrame
139
140 const int ID_QUIT = 108;
141 const int ID_ABOUT = 109;
142
143 IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
144
145 BEGIN_EVENT_TABLE(MyFrame,wxFrame)
146 EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
147 EVT_MENU (ID_QUIT, MyFrame::OnQuit)
148 END_EVENT_TABLE()
149
150 MyFrame::MyFrame()
151 : wxFrame( (wxFrame *)NULL, -1, "wxScrolledWindow sample",
152 wxPoint(20,20), wxSize(470,360) )
153 {
154 wxMenu *file_menu = new wxMenu();
155 file_menu->Append( ID_ABOUT, "&About..");
156 file_menu->Append( ID_QUIT, "E&xit\tAlt-X");
157
158 wxMenuBar *menu_bar = new wxMenuBar();
159 menu_bar->Append(file_menu, "&File");
160
161 SetMenuBar( menu_bar );
162
163 CreateStatusBar(2);
164 int widths[] = { -1, 100 };
165 SetStatusWidths( 2, widths );
166
167 m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) );
168 m_canvas->SetScrollbars( 10, 10, 50, 100 );
169 }
170
171 void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
172 {
173 Close( TRUE );
174 }
175
176 void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
177 {
178 (void)wxMessageBox( "wxScroll demo\n"
179 "Robert Roebling (c) 1998",
180 "About wxScroll Demo", wxICON_INFORMATION | wxOK );
181 }
182
183 //-----------------------------------------------------------------------------
184 // MyApp
185 //-----------------------------------------------------------------------------
186
187 bool MyApp::OnInit()
188 {
189 wxFrame *frame = new MyFrame();
190 frame->Show( TRUE );
191
192 return TRUE;
193 }
194