]>
git.saurik.com Git - wxWidgets.git/blob - samples/scroll/scroll.cpp
67c936293b51791c9c69e54839368a7bc742b2c5
4 * Author: Robert Roebling
6 * Copyright: (C) 1998, Robert Roebling
10 // For compilers that support precompilation, includes "wx/wx.h".
11 #include "wx/wxprec.h"
22 #include "wx/listctrl.h"
34 class MyCanvas
: public wxScrolledWindow
38 MyCanvas( wxWindow
*parent
, wxWindowID
, const wxPoint
&pos
, const wxSize
&size
);
40 void OnPaint( wxPaintEvent
&event
);
41 void OnAddButton( wxCommandEvent
&event
);
42 void OnDeleteButton( wxCommandEvent
&event
);
43 void OnMoveButton( wxCommandEvent
&event
);
44 void OnScrollWin( wxCommandEvent
&event
);
48 DECLARE_DYNAMIC_CLASS(MyCanvas
)
54 class MyFrame
: public wxFrame
59 void OnAbout( wxCommandEvent
&event
);
60 void OnQuit( wxCommandEvent
&event
);
65 DECLARE_DYNAMIC_CLASS(MyFrame
)
71 class MyApp
: public wxApp
74 virtual bool OnInit();
83 #define ID_ADDBUTTON 1
84 #define ID_DELBUTTON 2
85 #define ID_MOVEBUTTON 3
86 #define ID_SCROLLWIN 4
88 #define ID_NEWBUTTON 10
92 IMPLEMENT_DYNAMIC_CLASS(MyCanvas
, wxScrolledWindow
)
94 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
95 EVT_PAINT( MyCanvas::OnPaint
)
96 EVT_BUTTON( ID_ADDBUTTON
, MyCanvas::OnAddButton
)
97 EVT_BUTTON( ID_DELBUTTON
, MyCanvas::OnDeleteButton
)
98 EVT_BUTTON( ID_MOVEBUTTON
, MyCanvas::OnMoveButton
)
99 EVT_BUTTON( ID_SCROLLWIN
, MyCanvas::OnScrollWin
)
102 MyCanvas::MyCanvas( wxWindow
*parent
, wxWindowID id
,
103 const wxPoint
&pos
, const wxSize
&size
)
104 : wxScrolledWindow( parent
, id
, pos
, size
, wxSUNKEN_BORDER
| wxTAB_TRAVERSAL
, "test canvas" )
106 (void) new wxButton( this, ID_ADDBUTTON
, "add button", wxPoint(10,10) );
107 (void) new wxButton( this, ID_DELBUTTON
, "del button", wxPoint(10,40) );
108 (void) new wxButton( this, ID_MOVEBUTTON
, "move button", wxPoint(150,10) );
109 (void) new wxButton( this, ID_SCROLLWIN
, "scroll win", wxPoint(250,10) );
120 m_button
= new wxButton( this, -1, "wxButton", wxPoint(10,110) );
122 (void) new wxTextCtrl( this, -1, "wxTextCtrl", wxPoint(10,150) );
124 (void) new wxRadioButton( this, -1, "Disable", wxPoint(10,190) );
126 (void) new wxComboBox( this, -1, "This", wxPoint(10,230), wxDefaultSize
, 5, choices
);
128 (void) new wxRadioBox( this, -1, "This", wxPoint(10,310), wxDefaultSize
, 5, choices
, 2, wxRA_SPECIFY_COLS
);
130 (void) new wxRadioBox( this, -1, "This", wxPoint(10,440), wxDefaultSize
, 5, choices
, 2, wxRA_SPECIFY_ROWS
);
132 wxListCtrl
*m_listCtrl
= new wxListCtrl(
133 this, -1, wxPoint(200, 110), wxSize(180, 120),
134 wxLC_REPORT
| wxSIMPLE_BORDER
| wxLC_SINGLE_SEL
);
136 m_listCtrl
->InsertColumn(0, "First", wxLIST_FORMAT_LEFT
, 90);
137 m_listCtrl
->InsertColumn(1, "Last", wxLIST_FORMAT_LEFT
, 90);
139 for ( int i
=0; i
< 30; i
++)
142 sprintf(buf
, "Item %d", i
);
143 m_listCtrl
->InsertItem(i
, buf
);
145 m_listCtrl
->SetItemState( 3, wxLIST_STATE_SELECTED
, wxLIST_STATE_SELECTED
);
147 (void) new wxListBox( this, -1, wxPoint(260,280), wxSize(120,120), 5, choices
, wxLB_ALWAYS_SB
);
149 wxWindow
*test
= new wxWindow( this, -1, wxPoint(10, 530), wxSize(130,120), wxSIMPLE_BORDER
| wxTAB_TRAVERSAL
);
150 test
->SetBackgroundColour( "WHEAT" );
151 wxButton
*test2
= new wxButton( test
, -1, "Hallo", wxPoint(10,10) );
153 test
= new wxWindow( this, -1, wxPoint(160, 530), wxSize(130,120), wxSUNKEN_BORDER
| wxTAB_TRAVERSAL
);
154 test
->SetBackgroundColour( "WHEAT" );
155 test
->SetCursor( wxCursor( wxCURSOR_NO_ENTRY
) );
156 test2
= new wxButton( test
, -1, "Hallo", wxPoint(10,10) );
157 test2
->SetCursor( wxCursor( wxCURSOR_PENCIL
) );
159 test
= new wxWindow( this, -1, wxPoint(310, 530), wxSize(130,120), wxRAISED_BORDER
| wxTAB_TRAVERSAL
);
160 test
->SetBackgroundColour( "WHEAT" );
161 test
->SetCursor( wxCursor( wxCURSOR_PENCIL
) );
162 test2
= new wxButton( test
, -1, "Hallo", wxPoint(10,10) );
163 test2
->SetCursor( wxCursor( wxCURSOR_NO_ENTRY
) );
165 SetBackgroundColour( "WHEAT" );
167 SetCursor( wxCursor( wxCURSOR_IBEAM
) );
170 MyCanvas::~MyCanvas()
174 void MyCanvas::OnAddButton( wxCommandEvent
&WXUNUSED(event
) )
176 wxLogMessage( "Inserting button at position 50,50" );
177 (void) new wxButton( this, ID_NEWBUTTON
, "new button", wxPoint(50,50) );
180 void MyCanvas::OnDeleteButton( wxCommandEvent
&event
)
182 wxLogMessage( "deleting button inserted with ""add button""" );
183 wxWindow
*win
= FindWindow( ID_NEWBUTTON
);
187 wxLogMessage( "-> No window with id = ID_NEWBUTTON found." );
190 void MyCanvas::OnMoveButton( wxCommandEvent
&event
)
192 wxLogMessage( "Moving button 10 pixels downward.." );
193 wxWindow
*win
= FindWindow( event
.GetId() );
194 win
->Move( -1, win
->GetPosition().y
+ 10 );
197 void MyCanvas::OnScrollWin( wxCommandEvent
&WXUNUSED(event
) )
199 wxLogMessage( "Scrolling 2 units up.\nThe white square and the controls should move equally!" );
205 void MyCanvas::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
207 wxPaintDC
dc( this );
210 dc
.DrawText( "Some text", 140, 140 );
212 dc
.DrawRectangle( 100, 160, 200, 200 );
217 const int ID_QUIT
= 108;
218 const int ID_ABOUT
= 109;
220 IMPLEMENT_DYNAMIC_CLASS( MyFrame
, wxFrame
)
222 BEGIN_EVENT_TABLE(MyFrame
,wxFrame
)
223 EVT_MENU (ID_ABOUT
, MyFrame::OnAbout
)
224 EVT_MENU (ID_QUIT
, MyFrame::OnQuit
)
228 : wxFrame( (wxFrame
*)NULL
, -1, "wxScrolledWindow sample",
229 wxPoint(20,20), wxSize(470,500) )
231 wxMenu
*file_menu
= new wxMenu();
232 file_menu
->Append( ID_ABOUT
, "&About..");
233 file_menu
->Append( ID_QUIT
, "E&xit\tAlt-X");
235 wxMenuBar
*menu_bar
= new wxMenuBar();
236 menu_bar
->Append(file_menu
, "&File");
238 SetMenuBar( menu_bar
);
241 int widths
[] = { -1, 100 };
242 SetStatusWidths( 2, widths
);
244 m_canvas
= new MyCanvas( this, -1, wxPoint(0,0), wxSize(100,100) );
245 m_canvas
->SetScrollbars( 10, 10, 50, 100 );
247 m_log
= new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE
);
248 wxLog
*old_log
= wxLog::SetActiveTarget( new wxLogTextCtrl( m_log
) );
251 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
253 topsizer
->Add( m_canvas
, 1, wxEXPAND
);
254 topsizer
->Add( m_log
, 0, wxEXPAND
);
256 SetAutoLayout( TRUE
);
257 SetSizer( topsizer
);
260 void MyFrame::OnQuit( wxCommandEvent
&WXUNUSED(event
) )
265 void MyFrame::OnAbout( wxCommandEvent
&WXUNUSED(event
) )
267 (void)wxMessageBox( "wxScroll demo\n"
268 "Robert Roebling (c) 1998",
269 "About wxScroll Demo", wxICON_INFORMATION
| wxOK
);
272 //-----------------------------------------------------------------------------
274 //-----------------------------------------------------------------------------
278 wxFrame
*frame
= new MyFrame();