New scrolling code.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3897 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
1999-10-08 20:09:32 +00:00
parent 2136a764e5
commit ed673c6a48
12 changed files with 2058 additions and 890 deletions

View File

@@ -20,6 +20,9 @@
#include "wx/image.h"
#include "wx/listctrl.h"
#include "wx/sizer.h"
#include "wx/log.h"
// derived classes
@@ -35,6 +38,12 @@ public:
MyCanvas( wxWindow *parent, wxWindowID, const wxPoint &pos, const wxSize &size );
~MyCanvas();
void OnPaint( wxPaintEvent &event );
void OnAddButton( wxCommandEvent &event );
void OnDeleteButton( wxCommandEvent &event );
void OnMoveButton( wxCommandEvent &event );
void OnScrollWin( wxCommandEvent &event );
wxButton *m_button;
DECLARE_DYNAMIC_CLASS(MyCanvas)
DECLARE_EVENT_TABLE()
@@ -51,6 +60,7 @@ public:
void OnQuit( wxCommandEvent &event );
MyCanvas *m_canvas;
wxTextCtrl *m_log;
DECLARE_DYNAMIC_CLASS(MyFrame)
DECLARE_EVENT_TABLE()
@@ -68,18 +78,36 @@ public:
IMPLEMENT_APP(MyApp)
// ids
#define ID_ADDBUTTON 1
#define ID_DELBUTTON 2
#define ID_MOVEBUTTON 3
#define ID_SCROLLWIN 4
#define ID_NEWBUTTON 10
// MyCanvas
IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow)
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
// EVT_PAINT(MyCanvas::OnPaint)
EVT_PAINT( MyCanvas::OnPaint)
EVT_BUTTON( ID_ADDBUTTON, MyCanvas::OnAddButton)
EVT_BUTTON( ID_DELBUTTON, MyCanvas::OnDeleteButton)
EVT_BUTTON( ID_MOVEBUTTON, MyCanvas::OnMoveButton)
EVT_BUTTON( ID_SCROLLWIN, MyCanvas::OnScrollWin)
END_EVENT_TABLE()
MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
const wxPoint &pos, const wxSize &size )
: wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER | wxTAB_TRAVERSAL, "test canvas" )
{
(void) new wxButton( this, ID_ADDBUTTON, "add button", wxPoint(10,10) );
(void) new wxButton( this, ID_DELBUTTON, "del button", wxPoint(10,40) );
(void) new wxButton( this, ID_MOVEBUTTON, "move button", wxPoint(150,10) );
(void) new wxButton( this, ID_SCROLLWIN, "scroll win", wxPoint(250,10) );
wxString choices[] =
{
"This",
@@ -89,68 +117,99 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
"examples."
};
(void) new wxButton( this, -1, "wxButton", wxPoint(10,10) );
m_button = new wxButton( this, -1, "wxButton", wxPoint(10,110) );
(void) new wxTextCtrl( this, -1, "wxTextCtrl", wxPoint(10,50) );
(void) new wxTextCtrl( this, -1, "wxTextCtrl", wxPoint(10,150) );
(void) new wxRadioButton( this, -1, "Disable", wxPoint(10,90) );
(void) new wxRadioButton( this, -1, "Disable", wxPoint(10,190) );
(void) new wxComboBox( this, -1, "This", wxPoint(10,130), wxDefaultSize, 5, choices );
(void) new wxComboBox( this, -1, "This", wxPoint(10,230), wxDefaultSize, 5, choices );
(void) new wxRadioBox( this, -1, "This", wxPoint(10,200), wxDefaultSize, 5, choices, 2, wxRA_SPECIFY_COLS );
(void) new wxRadioBox( this, -1, "This", wxPoint(10,310), wxDefaultSize, 5, choices, 2, wxRA_SPECIFY_COLS );
(void) new wxRadioBox( this, -1, "This", wxPoint(10,300), wxDefaultSize, 5, choices, 2, wxRA_SPECIFY_ROWS );
(void) new wxRadioBox( this, -1, "This", wxPoint(10,440), wxDefaultSize, 5, choices, 2, wxRA_SPECIFY_ROWS );
wxListCtrl *m_listCtrl = new wxListCtrl(
this, -1, wxPoint(200, 10), wxSize(180, 120),
wxListCtrl *m_listCtrl = new wxListCtrl(
this, -1, wxPoint(200, 110), wxSize(180, 120),
wxLC_REPORT | wxSIMPLE_BORDER | wxLC_SINGLE_SEL );
m_listCtrl->InsertColumn(0, "First", wxLIST_FORMAT_LEFT, 90);
m_listCtrl->InsertColumn(1, "Last", wxLIST_FORMAT_LEFT, 90);
m_listCtrl->InsertColumn(0, "First", wxLIST_FORMAT_LEFT, 90);
m_listCtrl->InsertColumn(1, "Last", wxLIST_FORMAT_LEFT, 90);
for ( int i=0; i < 30; i++)
{
char buf[20];
sprintf(buf, "Item %d", i);
m_listCtrl->InsertItem(i, buf);
}
m_listCtrl->SetItemState( 3, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
for ( int i=0; i < 30; i++)
{
char buf[20];
sprintf(buf, "Item %d", i);
m_listCtrl->InsertItem(i, buf);
}
m_listCtrl->SetItemState( 3, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
(void) new wxListBox( this, -1, wxPoint(200,180), wxSize(180,120), 5, choices, wxLB_ALWAYS_SB );
(void) new wxListBox( this, -1, wxPoint(260,280), wxSize(120,120), 5, choices, wxLB_ALWAYS_SB );
wxWindow *test = new wxWindow( this, -1, wxPoint(10, 400), wxSize(130,120), wxSIMPLE_BORDER | wxTAB_TRAVERSAL );
test->SetBackgroundColour( "WHEAT" );
wxButton *test2 = new wxButton( test, -1, "Hallo", wxPoint(10,10) );
wxWindow *test = new wxWindow( this, -1, wxPoint(10, 530), wxSize(130,120), wxSIMPLE_BORDER | wxTAB_TRAVERSAL );
test->SetBackgroundColour( "WHEAT" );
wxButton *test2 = new wxButton( test, -1, "Hallo", wxPoint(10,10) );
test = new wxWindow( this, -1, wxPoint(160, 400), wxSize(130,120), wxSUNKEN_BORDER | wxTAB_TRAVERSAL );
test->SetBackgroundColour( "WHEAT" );
test->SetCursor( wxCursor( wxCURSOR_NO_ENTRY ) );
test2 = new wxButton( test, -1, "Hallo", wxPoint(10,10) );
test2->SetCursor( wxCursor( wxCURSOR_PENCIL ) );
test = new wxWindow( this, -1, wxPoint(160, 530), wxSize(130,120), wxSUNKEN_BORDER | wxTAB_TRAVERSAL );
test->SetBackgroundColour( "WHEAT" );
test->SetCursor( wxCursor( wxCURSOR_NO_ENTRY ) );
test2 = new wxButton( test, -1, "Hallo", wxPoint(10,10) );
test2->SetCursor( wxCursor( wxCURSOR_PENCIL ) );
test = new wxWindow( this, -1, wxPoint(310, 400), wxSize(130,120), wxRAISED_BORDER | wxTAB_TRAVERSAL );
test->SetBackgroundColour( "WHEAT" );
test->SetCursor( wxCursor( wxCURSOR_PENCIL ) );
test2 = new wxButton( test, -1, "Hallo", wxPoint(10,10) );
test2->SetCursor( wxCursor( wxCURSOR_NO_ENTRY ) );
test = new wxWindow( this, -1, wxPoint(310, 530), wxSize(130,120), wxRAISED_BORDER | wxTAB_TRAVERSAL );
test->SetBackgroundColour( "WHEAT" );
test->SetCursor( wxCursor( wxCURSOR_PENCIL ) );
test2 = new wxButton( test, -1, "Hallo", wxPoint(10,10) );
test2->SetCursor( wxCursor( wxCURSOR_NO_ENTRY ) );
SetBackgroundColour( "WHEAT" );
SetBackgroundColour( "WHEAT" );
SetCursor( wxCursor( wxCURSOR_IBEAM ) );
SetCursor( wxCursor( wxCURSOR_IBEAM ) );
}
MyCanvas::~MyCanvas()
{
}
void MyCanvas::OnAddButton( wxCommandEvent &WXUNUSED(event) )
{
wxLogMessage( "Inserting button at position 50,50" );
(void) new wxButton( this, ID_NEWBUTTON, "new button", wxPoint(50,50) );
}
void MyCanvas::OnDeleteButton( wxCommandEvent &event )
{
wxLogMessage( "deleting button inserted with ""add button""" );
wxWindow *win = FindWindow( ID_NEWBUTTON );
if (win)
win->Destroy();
else
wxLogMessage( "-> No window with id = ID_NEWBUTTON found." );
}
void MyCanvas::OnMoveButton( wxCommandEvent &event )
{
wxLogMessage( "Moving button 10 pixels downward.." );
wxWindow *win = FindWindow( event.GetId() );
win->Move( -1, win->GetPosition().y + 10 );
}
void MyCanvas::OnScrollWin( wxCommandEvent &WXUNUSED(event) )
{
wxLogMessage( "Scrolling 2 units up.\nThe white square and the controls should move equally!" );
int x,y;
ViewStart( &x, &y );
Scroll( -1, y+2 );
}
void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
{
wxPaintDC dc( this );
PrepareDC( dc );
wxPaintDC dc( this );
PrepareDC( dc );
dc.DrawText( "Some text", 110, 10 );
dc.DrawText( "Some text", 140, 140 );
dc.DrawRectangle( 50, 30, 200, 200 );
dc.DrawRectangle( 100, 160, 200, 200 );
}
// MyFrame
@@ -167,23 +226,35 @@ END_EVENT_TABLE()
MyFrame::MyFrame()
: wxFrame( (wxFrame *)NULL, -1, "wxScrolledWindow sample",
wxPoint(20,20), wxSize(470,360) )
wxPoint(20,20), wxSize(470,500) )
{
wxMenu *file_menu = new wxMenu();
file_menu->Append( ID_ABOUT, "&About..");
file_menu->Append( ID_QUIT, "E&xit\tAlt-X");
wxMenu *file_menu = new wxMenu();
file_menu->Append( ID_ABOUT, "&About..");
file_menu->Append( ID_QUIT, "E&xit\tAlt-X");
wxMenuBar *menu_bar = new wxMenuBar();
menu_bar->Append(file_menu, "&File");
wxMenuBar *menu_bar = new wxMenuBar();
menu_bar->Append(file_menu, "&File");
SetMenuBar( menu_bar );
SetMenuBar( menu_bar );
CreateStatusBar(2);
int widths[] = { -1, 100 };
SetStatusWidths( 2, widths );
CreateStatusBar(2);
int widths[] = { -1, 100 };
SetStatusWidths( 2, widths );
m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(10,10) );
m_canvas->SetScrollbars( 10, 10, 50, 100 );
m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(100,100) );
m_canvas->SetScrollbars( 10, 10, 50, 100 );
m_log = new wxTextCtrl( this, -1, "This is the log window.\n", wxPoint(0,0), wxSize(100,100), wxTE_MULTILINE );
wxLog *old_log = wxLog::SetActiveTarget( new wxLogTextCtrl( m_log ) );
delete old_log;
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
topsizer->Add( m_canvas, 1, wxEXPAND );
topsizer->Add( m_log, 0, wxEXPAND );
SetAutoLayout( TRUE );
SetSizer( topsizer );
}
void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )