]> git.saurik.com Git - wxWidgets.git/blame - samples/scroll/scroll.cpp
More tests for streams.
[wxWidgets.git] / samples / scroll / scroll.cpp
CommitLineData
fdd3ed7a
RR
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"
053f9cc1 22#include "wx/listctrl.h"
fdd3ed7a
RR
23
24// derived classes
25
26class MyFrame;
27class MyApp;
28
29// MyCanvas
30
31class MyCanvas: public wxScrolledWindow
32{
33public:
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
45class MyFrame: public wxFrame
46{
47public:
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
61class MyApp: public wxApp
62{
63public:
64 virtual bool OnInit();
65};
66
67// main program
68
69IMPLEMENT_APP(MyApp)
70
71// MyCanvas
72
73IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow)
74
75BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
76 EVT_PAINT(MyCanvas::OnPaint)
77END_EVENT_TABLE()
78
79MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
80 const wxPoint &pos, const wxSize &size )
de1c750f 81 : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER | wxTAB_TRAVERSAL )
fdd3ed7a 82{
fdd3ed7a
RR
83 wxString choices[] =
84 {
85 "This",
86 "is one of my",
87 "really",
88 "wonderful",
89 "examples."
90 };
91
eba0e4d4 92 (void) new wxButton( this, -1, "wxButton", wxPoint(10,10) );
eb082a08 93
eba0e4d4 94 (void) new wxTextCtrl( this, -1, "wxTextCtrl", wxPoint(10,50) );
eb082a08
RR
95
96 (void) new wxRadioButton( this, -1, "Disable", wxPoint(10,90) );
97
eba0e4d4 98 (void) new wxComboBox( this, -1, "This", wxPoint(10,130), wxDefaultSize, 5, choices );
fdd3ed7a 99
de1c750f 100 (void) new wxRadioBox( this, -1, "This", wxPoint(10,200), wxDefaultSize, 5, choices );
053f9cc1
RR
101
102 wxListCtrl *m_listCtrl = new wxListCtrl(
103 this, -1, wxPoint(200, 10), wxSize(180, 120),
00a39542 104 wxLC_REPORT | wxSUNKEN_BORDER | wxLC_SINGLE_SEL );
053f9cc1
RR
105
106 m_listCtrl->InsertColumn(0, "First", wxLIST_FORMAT_LEFT, 90);
107 m_listCtrl->InsertColumn(1, "Last", wxLIST_FORMAT_LEFT, 90);
108
109 for ( int i=0; i < 30; i++)
110 {
111 char buf[20];
112 sprintf(buf, "Item %d", i);
113 m_listCtrl->InsertItem(i, buf);
114 }
00a39542 115 m_listCtrl->SetItemState( 3, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
053f9cc1
RR
116
117 (void) new wxListBox( this, -1, wxPoint(200,180), wxSize(180,120), 5, choices, wxLB_ALWAYS_SB );
eb082a08 118
053f9cc1 119 SetBackgroundColour( "WHEAT" );
fdd3ed7a
RR
120}
121
122MyCanvas::~MyCanvas()
123{
124}
125
126void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
127{
128 wxPaintDC dc( this );
129 PrepareDC( dc );
130
7f539e8a 131 dc.DrawText( "Some text", 110, 10 );
fdd3ed7a
RR
132
133 dc.DrawRectangle( 50, 30, 200, 200 );
134}
135
136// MyFrame
137
138const int ID_QUIT = 108;
139const int ID_ABOUT = 109;
140
141IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
142
143BEGIN_EVENT_TABLE(MyFrame,wxFrame)
144 EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
145 EVT_MENU (ID_QUIT, MyFrame::OnQuit)
146END_EVENT_TABLE()
147
148MyFrame::MyFrame()
149 : wxFrame( (wxFrame *)NULL, -1, "wxScrolledWindow sample",
150 wxPoint(20,20), wxSize(470,360) )
151{
152 wxMenu *file_menu = new wxMenu();
153 file_menu->Append( ID_ABOUT, "&About..");
154 file_menu->Append( ID_QUIT, "E&xit\tAlt-X");
155
156 wxMenuBar *menu_bar = new wxMenuBar();
157 menu_bar->Append(file_menu, "&File");
158
159 SetMenuBar( menu_bar );
160
161 CreateStatusBar(2);
162 int widths[] = { -1, 100 };
163 SetStatusWidths( 2, widths );
164
165 m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) );
166 m_canvas->SetScrollbars( 10, 10, 50, 100 );
167}
168
169void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
170{
171 Close( TRUE );
172}
173
174void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
175{
176 (void)wxMessageBox( "wxScroll demo\n"
177 "Robert Roebling (c) 1998",
178 "About wxScroll Demo", wxICON_INFORMATION | wxOK );
179}
180
181//-----------------------------------------------------------------------------
182// MyApp
183//-----------------------------------------------------------------------------
184
185bool MyApp::OnInit()
186{
187 wxFrame *frame = new MyFrame();
188 frame->Show( TRUE );
189
190 return TRUE;
191}
192