]> git.saurik.com Git - wxWidgets.git/blob - samples/scroll/scroll.cpp
labels respect alignment now even with GTK 1.2
[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
23 // derived classes
24
25 class MyFrame;
26 class MyApp;
27
28 // MyCanvas
29
30 class MyCanvas: public wxScrolledWindow
31 {
32 public:
33 MyCanvas() {};
34 MyCanvas( wxWindow *parent, wxWindowID, const wxPoint &pos, const wxSize &size );
35 ~MyCanvas();
36 void OnPaint( wxPaintEvent &event );
37
38 DECLARE_DYNAMIC_CLASS(MyCanvas)
39 DECLARE_EVENT_TABLE()
40 };
41
42 // MyFrame
43
44 class MyFrame: public wxFrame
45 {
46 public:
47 MyFrame();
48
49 void OnAbout( wxCommandEvent &event );
50 void OnQuit( wxCommandEvent &event );
51
52 MyCanvas *m_canvas;
53
54 DECLARE_DYNAMIC_CLASS(MyFrame)
55 DECLARE_EVENT_TABLE()
56 };
57
58 // MyApp
59
60 class MyApp: public wxApp
61 {
62 public:
63 virtual bool OnInit();
64 };
65
66 // main program
67
68 IMPLEMENT_APP(MyApp)
69
70 // MyCanvas
71
72 IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow)
73
74 BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
75 EVT_PAINT(MyCanvas::OnPaint)
76 END_EVENT_TABLE()
77
78 MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
79 const wxPoint &pos, const wxSize &size )
80 : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER | wxTAB_TRAVERSAL )
81 {
82
83 SetBackgroundColour( *wxWHITE );
84
85 (void) new wxButton( this, -1, "wxButton", wxPoint(10,10) );
86
87 (void) new wxTextCtrl( this, -1, "wxTextCtrl", wxPoint(10,50) );
88
89 (void) new wxRadioButton( this, -1, "Disable", wxPoint(10,90) );
90
91 wxString choices[] =
92 {
93 "This",
94 "is one of my",
95 "really",
96 "wonderful",
97 "examples."
98 };
99
100 (void) new wxComboBox( this, -1, "This", wxPoint(10,130), wxDefaultSize, 5, choices );
101
102 (void) new wxRadioBox( this, -1, "This", wxPoint(10,200), wxDefaultSize, 5, choices );
103 }
104
105 MyCanvas::~MyCanvas()
106 {
107 }
108
109 void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
110 {
111 return;
112
113 wxPaintDC dc( this );
114 PrepareDC( dc );
115
116 dc.DrawText( "Some text", 10, 10 );
117
118 dc.DrawRectangle( 50, 30, 200, 200 );
119 }
120
121 // MyFrame
122
123 const int ID_QUIT = 108;
124 const int ID_ABOUT = 109;
125
126 IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
127
128 BEGIN_EVENT_TABLE(MyFrame,wxFrame)
129 EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
130 EVT_MENU (ID_QUIT, MyFrame::OnQuit)
131 END_EVENT_TABLE()
132
133 MyFrame::MyFrame()
134 : wxFrame( (wxFrame *)NULL, -1, "wxScrolledWindow sample",
135 wxPoint(20,20), wxSize(470,360) )
136 {
137 wxMenu *file_menu = new wxMenu();
138 file_menu->Append( ID_ABOUT, "&About..");
139 file_menu->Append( ID_QUIT, "E&xit\tAlt-X");
140
141 wxMenuBar *menu_bar = new wxMenuBar();
142 menu_bar->Append(file_menu, "&File");
143
144 SetMenuBar( menu_bar );
145
146 CreateStatusBar(2);
147 int widths[] = { -1, 100 };
148 SetStatusWidths( 2, widths );
149
150 m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) );
151 m_canvas->SetScrollbars( 10, 10, 50, 100 );
152 }
153
154 void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
155 {
156 Close( TRUE );
157 }
158
159 void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
160 {
161 (void)wxMessageBox( "wxScroll demo\n"
162 "Robert Roebling (c) 1998",
163 "About wxScroll Demo", wxICON_INFORMATION | wxOK );
164 }
165
166 //-----------------------------------------------------------------------------
167 // MyApp
168 //-----------------------------------------------------------------------------
169
170 bool MyApp::OnInit()
171 {
172 wxFrame *frame = new MyFrame();
173 frame->Show( TRUE );
174
175 return TRUE;
176 }
177