1999-05-05 06:25:38 -04:00
|
|
|
/*
|
|
|
|
* Program: scroll
|
|
|
|
*
|
|
|
|
* Author: Robert Roebling
|
|
|
|
*
|
|
|
|
* Copyright: (C) 1998, Robert Roebling
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/image.h"
|
1999-05-26 05:03:25 -04:00
|
|
|
#include "wx/listctrl.h"
|
1999-10-08 16:09:32 -04:00
|
|
|
#include "wx/sizer.h"
|
|
|
|
#include "wx/log.h"
|
|
|
|
|
1999-05-05 06:25:38 -04:00
|
|
|
|
|
|
|
// derived classes
|
|
|
|
|
|
|
|
class MyFrame;
|
|
|
|
class MyApp;
|
|
|
|
|
|
|
|
// MyCanvas
|
|
|
|
|
|
|
|
class MyCanvas: public wxScrolledWindow
|
|
|
|
{
|
|
|
|
public:
|
2001-07-09 18:54:26 -04:00
|
|
|
MyCanvas() {}
|
1999-05-05 06:25:38 -04:00
|
|
|
MyCanvas( wxWindow *parent, wxWindowID, const wxPoint &pos, const wxSize &size );
|
|
|
|
~MyCanvas();
|
|
|
|
void OnPaint( wxPaintEvent &event );
|
1999-10-09 05:06:35 -04:00
|
|
|
void OnQueryPosition( wxCommandEvent &event );
|
1999-10-08 16:09:32 -04:00
|
|
|
void OnAddButton( wxCommandEvent &event );
|
|
|
|
void OnDeleteButton( wxCommandEvent &event );
|
|
|
|
void OnMoveButton( wxCommandEvent &event );
|
|
|
|
void OnScrollWin( wxCommandEvent &event );
|
1999-10-10 14:42:43 -04:00
|
|
|
void OnMouseDown( wxMouseEvent &event );
|
1999-10-08 16:09:32 -04:00
|
|
|
|
|
|
|
wxButton *m_button;
|
1999-05-05 06:25:38 -04:00
|
|
|
|
|
|
|
DECLARE_DYNAMIC_CLASS(MyCanvas)
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
2001-07-09 18:54:26 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyScrolledWindow classes: examples of wxScrolledWindow usage
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// base class for both of them
|
|
|
|
class MyScrolledWindowBase : public wxScrolledWindow
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyScrolledWindowBase(wxWindow *parent) : wxScrolledWindow(parent)
|
|
|
|
{
|
|
|
|
m_nLines = 100;
|
|
|
|
|
|
|
|
InitScrollbars();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// set the scrollbar params
|
|
|
|
void InitScrollbars();
|
|
|
|
|
|
|
|
// the height of one line on screen
|
|
|
|
wxCoord m_hLine;
|
|
|
|
|
|
|
|
// the number of lines we draw
|
|
|
|
size_t m_nLines;
|
|
|
|
};
|
|
|
|
|
|
|
|
// this class does "stupid" redrawing - it redraws everything each time
|
|
|
|
class MyScrolledWindowDumb : public MyScrolledWindowBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyScrolledWindowDumb(wxWindow *parent) : MyScrolledWindowBase(parent) { }
|
|
|
|
|
|
|
|
virtual void OnDraw(wxDC& dc);
|
|
|
|
};
|
|
|
|
|
|
|
|
// this class does "smart" redrawing - only redraws the lines which must be
|
|
|
|
// redrawn
|
|
|
|
class MyScrolledWindowSmart : public MyScrolledWindowBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyScrolledWindowSmart(wxWindow *parent) : MyScrolledWindowBase(parent) { }
|
|
|
|
|
|
|
|
virtual void OnDraw(wxDC& dc);
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
1999-05-05 06:25:38 -04:00
|
|
|
// MyFrame
|
2001-07-09 18:54:26 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
1999-05-05 06:25:38 -04:00
|
|
|
|
|
|
|
class MyFrame: public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyFrame();
|
|
|
|
|
|
|
|
void OnAbout( wxCommandEvent &event );
|
|
|
|
void OnQuit( wxCommandEvent &event );
|
2000-02-22 17:39:55 -05:00
|
|
|
void OnDeleteAll( wxCommandEvent &event );
|
|
|
|
void OnInsertNew( wxCommandEvent &event );
|
1999-05-05 06:25:38 -04:00
|
|
|
|
|
|
|
MyCanvas *m_canvas;
|
1999-10-08 16:09:32 -04:00
|
|
|
wxTextCtrl *m_log;
|
1999-05-05 06:25:38 -04:00
|
|
|
|
|
|
|
DECLARE_DYNAMIC_CLASS(MyFrame)
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
// MyApp
|
|
|
|
|
|
|
|
class MyApp: public wxApp
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool OnInit();
|
|
|
|
};
|
|
|
|
|
|
|
|
// main program
|
|
|
|
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
1999-10-08 16:09:32 -04:00
|
|
|
// ids
|
|
|
|
|
|
|
|
#define ID_ADDBUTTON 1
|
|
|
|
#define ID_DELBUTTON 2
|
|
|
|
#define ID_MOVEBUTTON 3
|
|
|
|
#define ID_SCROLLWIN 4
|
1999-10-09 05:06:35 -04:00
|
|
|
#define ID_QUERYPOS 5
|
1999-10-08 16:09:32 -04:00
|
|
|
|
|
|
|
#define ID_NEWBUTTON 10
|
|
|
|
|
1999-05-05 06:25:38 -04:00
|
|
|
// MyCanvas
|
|
|
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow)
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
1999-10-09 05:06:35 -04:00
|
|
|
EVT_PAINT( MyCanvas::OnPaint)
|
1999-10-19 11:12:11 -04:00
|
|
|
EVT_MOUSE_EVENTS( MyCanvas::OnMouseDown)
|
1999-10-09 05:06:35 -04:00
|
|
|
EVT_BUTTON( ID_QUERYPOS, MyCanvas::OnQueryPosition)
|
1999-10-08 16:09:32 -04:00
|
|
|
EVT_BUTTON( ID_ADDBUTTON, MyCanvas::OnAddButton)
|
|
|
|
EVT_BUTTON( ID_DELBUTTON, MyCanvas::OnDeleteButton)
|
|
|
|
EVT_BUTTON( ID_MOVEBUTTON, MyCanvas::OnMoveButton)
|
|
|
|
EVT_BUTTON( ID_SCROLLWIN, MyCanvas::OnScrollWin)
|
1999-05-05 06:25:38 -04:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
|
|
|
|
const wxPoint &pos, const wxSize &size )
|
1999-09-30 18:13:45 -04:00
|
|
|
: wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER | wxTAB_TRAVERSAL, "test canvas" )
|
1999-05-05 06:25:38 -04:00
|
|
|
{
|
1999-10-08 16:09:32 -04:00
|
|
|
(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) );
|
|
|
|
|
2001-05-15 15:53:48 -04:00
|
|
|
#if 0
|
|
|
|
|
1999-05-05 06:25:38 -04:00
|
|
|
wxString choices[] =
|
|
|
|
{
|
|
|
|
"This",
|
|
|
|
"is one of my",
|
|
|
|
"really",
|
|
|
|
"wonderful",
|
|
|
|
"examples."
|
|
|
|
};
|
2001-05-15 15:53:48 -04:00
|
|
|
|
1999-10-09 05:06:35 -04:00
|
|
|
m_button = new wxButton( this, ID_QUERYPOS, "Query position", wxPoint(10,110) );
|
2001-05-15 15:53:48 -04:00
|
|
|
|
1999-10-11 06:48:43 -04:00
|
|
|
(void) new wxTextCtrl( this, -1, "wxTextCtrl", wxPoint(10,150), wxSize(80,-1) );
|
2001-05-15 15:53:48 -04:00
|
|
|
|
1999-10-08 16:09:32 -04:00
|
|
|
(void) new wxRadioButton( this, -1, "Disable", wxPoint(10,190) );
|
2001-05-15 15:53:48 -04:00
|
|
|
|
1999-10-08 16:09:32 -04:00
|
|
|
(void) new wxComboBox( this, -1, "This", wxPoint(10,230), wxDefaultSize, 5, choices );
|
2001-05-15 15:53:48 -04:00
|
|
|
|
1999-10-08 16:09:32 -04:00
|
|
|
(void) new wxRadioBox( this, -1, "This", wxPoint(10,310), wxDefaultSize, 5, choices, 2, wxRA_SPECIFY_COLS );
|
1999-05-26 05:03:25 -04:00
|
|
|
|
1999-10-08 16:09:32 -04:00
|
|
|
(void) new wxRadioBox( this, -1, "This", wxPoint(10,440), wxDefaultSize, 5, choices, 2, wxRA_SPECIFY_ROWS );
|
1999-07-26 15:03:53 -04:00
|
|
|
|
1999-10-08 16:09:32 -04:00
|
|
|
wxListCtrl *m_listCtrl = new wxListCtrl(
|
2001-07-09 18:54:26 -04:00
|
|
|
this, -1, wxPoint(200, 110), wxSize(180, 120),
|
|
|
|
wxLC_REPORT | wxSIMPLE_BORDER | wxLC_SINGLE_SEL );
|
1999-05-26 05:03:25 -04:00
|
|
|
|
1999-10-08 16:09:32 -04:00
|
|
|
m_listCtrl->InsertColumn(0, "First", wxLIST_FORMAT_LEFT, 90);
|
|
|
|
m_listCtrl->InsertColumn(1, "Last", wxLIST_FORMAT_LEFT, 90);
|
1999-05-26 05:03:25 -04:00
|
|
|
|
1999-10-08 16:09:32 -04:00
|
|
|
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 );
|
1999-05-26 05:03:25 -04:00
|
|
|
|
1999-10-08 16:09:32 -04:00
|
|
|
(void) new wxListBox( this, -1, wxPoint(260,280), wxSize(120,120), 5, choices, wxLB_ALWAYS_SB );
|
1999-09-30 18:13:45 -04:00
|
|
|
|
2001-05-15 15:53:48 -04:00
|
|
|
#endif
|
|
|
|
|
2001-07-09 18:54:26 -04:00
|
|
|
wxPanel *test = new wxPanel( this, -1, wxPoint(10, 110), wxSize(130,50), wxSIMPLE_BORDER | wxTAB_TRAVERSAL );
|
2001-11-22 04:11:33 -05:00
|
|
|
test->SetBackgroundColour( wxT("WHEAT") );
|
2001-05-15 15:53:48 -04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
1999-10-08 16:09:32 -04:00
|
|
|
wxButton *test2 = new wxButton( test, -1, "Hallo", wxPoint(10,10) );
|
2001-05-15 15:53:48 -04:00
|
|
|
|
1999-10-31 05:22:26 -05:00
|
|
|
test = new wxPanel( this, -1, wxPoint(160, 530), wxSize(130,120), wxSUNKEN_BORDER | wxTAB_TRAVERSAL );
|
2001-11-22 04:11:33 -05:00
|
|
|
test->SetBackgroundColour( wxT("WHEAT") );
|
1999-10-08 16:09:32 -04:00
|
|
|
test->SetCursor( wxCursor( wxCURSOR_NO_ENTRY ) );
|
|
|
|
test2 = new wxButton( test, -1, "Hallo", wxPoint(10,10) );
|
|
|
|
test2->SetCursor( wxCursor( wxCURSOR_PENCIL ) );
|
2001-05-15 15:53:48 -04:00
|
|
|
|
1999-10-31 05:22:26 -05:00
|
|
|
test = new wxPanel( this, -1, wxPoint(310, 530), wxSize(130,120), wxRAISED_BORDER | wxTAB_TRAVERSAL );
|
2001-11-22 04:11:33 -05:00
|
|
|
test->SetBackgroundColour( wxT("WHEAT") );
|
1999-10-08 16:09:32 -04:00
|
|
|
test->SetCursor( wxCursor( wxCURSOR_PENCIL ) );
|
|
|
|
test2 = new wxButton( test, -1, "Hallo", wxPoint(10,10) );
|
|
|
|
test2->SetCursor( wxCursor( wxCURSOR_NO_ENTRY ) );
|
1999-09-30 18:13:45 -04:00
|
|
|
|
2001-05-15 15:53:48 -04:00
|
|
|
#endif
|
|
|
|
|
2001-11-22 04:11:33 -05:00
|
|
|
SetBackgroundColour( wxT("BLUE") );
|
2001-05-15 15:53:48 -04:00
|
|
|
|
1999-10-08 16:09:32 -04:00
|
|
|
SetCursor( wxCursor( wxCURSOR_IBEAM ) );
|
1999-05-05 06:25:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
MyCanvas::~MyCanvas()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-10-10 14:42:43 -04:00
|
|
|
void MyCanvas::OnMouseDown( wxMouseEvent &event )
|
|
|
|
{
|
1999-10-19 11:12:11 -04:00
|
|
|
if (event.LeftDown())
|
|
|
|
{
|
|
|
|
wxPoint pt( event.GetPosition() );
|
|
|
|
int x,y;
|
|
|
|
CalcUnscrolledPosition( pt.x, pt.y, &x, &y );
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogMessage( wxT("Mouse down event at: %d %d, scrolled: %d %d"), pt.x, pt.y, x, y );
|
2000-07-15 15:51:35 -04:00
|
|
|
|
|
|
|
if ( !event.LeftIsDown() )
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogMessage( wxT("Error: LeftIsDown() should be TRUE if for LeftDown()") );
|
1999-10-19 11:12:11 -04:00
|
|
|
}
|
1999-10-10 14:42:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
wxPaintDC dc( this );
|
|
|
|
PrepareDC( dc );
|
|
|
|
|
|
|
|
dc.DrawText( "Press mouse button to test calculations!", 160, 50 );
|
|
|
|
|
|
|
|
dc.DrawText( "Some text", 140, 140 );
|
2001-05-15 15:53:48 -04:00
|
|
|
|
1999-10-10 14:42:43 -04:00
|
|
|
dc.DrawRectangle( 100, 160, 200, 200 );
|
|
|
|
}
|
|
|
|
|
1999-10-09 05:06:35 -04:00
|
|
|
void MyCanvas::OnQueryPosition( wxCommandEvent &WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
wxPoint pt( m_button->GetPosition() );
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogMessage( wxT("Position of \"Query position\" is %d %d"), pt.x, pt.y );
|
1999-10-10 14:42:43 -04:00
|
|
|
pt = ClientToScreen( pt );
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogMessage( wxT("Position of \"Query position\" on screen is %d %d"), pt.x, pt.y );
|
1999-10-09 05:06:35 -04:00
|
|
|
}
|
|
|
|
|
1999-10-08 16:09:32 -04:00
|
|
|
void MyCanvas::OnAddButton( wxCommandEvent &WXUNUSED(event) )
|
|
|
|
{
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogMessage( wxT("Inserting button at position 10,70...") );
|
1999-10-10 14:42:43 -04:00
|
|
|
wxButton *button = new wxButton( this, ID_NEWBUTTON, "new button", wxPoint(10,70), wxSize(80,25) );
|
|
|
|
wxPoint pt( button->GetPosition() );
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogMessage( wxT("-> Position after inserting %d %d"), pt.x, pt.y );
|
1999-10-08 16:09:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyCanvas::OnDeleteButton( wxCommandEvent &event )
|
|
|
|
{
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogMessage( wxT("Deleting button inserted with \"Add button\"...") );
|
1999-10-08 16:09:32 -04:00
|
|
|
wxWindow *win = FindWindow( ID_NEWBUTTON );
|
|
|
|
if (win)
|
|
|
|
win->Destroy();
|
|
|
|
else
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogMessage( wxT("-> No window with id = ID_NEWBUTTON found.") );
|
1999-10-08 16:09:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyCanvas::OnMoveButton( wxCommandEvent &event )
|
|
|
|
{
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogMessage( wxT("Moving button 10 pixels downward..") );
|
1999-10-08 16:09:32 -04:00
|
|
|
wxWindow *win = FindWindow( event.GetId() );
|
1999-10-10 14:42:43 -04:00
|
|
|
wxPoint pt( win->GetPosition() );
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogMessage( wxT("-> Position before move is %d %d"), pt.x, pt.y );
|
1999-10-10 14:42:43 -04:00
|
|
|
win->Move( -1, pt.y + 10 );
|
|
|
|
pt = win->GetPosition();
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogMessage( wxT("-> Position after move is %d %d"), pt.x, pt.y );
|
1999-10-08 16:09:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyCanvas::OnScrollWin( wxCommandEvent &WXUNUSED(event) )
|
|
|
|
{
|
2001-09-21 16:21:44 -04:00
|
|
|
wxLogMessage( wxT("Scrolling 2 units up.\nThe white square and the controls should move equally!") );
|
1999-10-08 16:09:32 -04:00
|
|
|
int x,y;
|
2001-07-22 13:09:23 -04:00
|
|
|
GetViewStart( &x, &y );
|
1999-10-08 16:09:32 -04:00
|
|
|
Scroll( -1, y+2 );
|
|
|
|
}
|
|
|
|
|
1999-05-05 06:25:38 -04:00
|
|
|
// MyFrame
|
|
|
|
|
|
|
|
const int ID_QUIT = 108;
|
|
|
|
const int ID_ABOUT = 109;
|
2000-02-22 17:39:55 -05:00
|
|
|
const int ID_DELETE_ALL = 110;
|
|
|
|
const int ID_INSERT_NEW = 111;
|
1999-05-05 06:25:38 -04:00
|
|
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyFrame,wxFrame)
|
2000-02-22 17:39:55 -05:00
|
|
|
EVT_MENU (ID_DELETE_ALL, MyFrame::OnDeleteAll)
|
|
|
|
EVT_MENU (ID_INSERT_NEW, MyFrame::OnInsertNew)
|
1999-05-05 06:25:38 -04:00
|
|
|
EVT_MENU (ID_ABOUT, MyFrame::OnAbout)
|
|
|
|
EVT_MENU (ID_QUIT, MyFrame::OnQuit)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
MyFrame::MyFrame()
|
|
|
|
: wxFrame( (wxFrame *)NULL, -1, "wxScrolledWindow sample",
|
1999-10-08 16:09:32 -04:00
|
|
|
wxPoint(20,20), wxSize(470,500) )
|
1999-05-05 06:25:38 -04:00
|
|
|
{
|
1999-10-08 16:09:32 -04:00
|
|
|
wxMenu *file_menu = new wxMenu();
|
2000-02-22 17:39:55 -05:00
|
|
|
file_menu->Append( ID_DELETE_ALL, "Delete all");
|
|
|
|
file_menu->Append( ID_INSERT_NEW, "Insert new");
|
1999-10-08 16:09:32 -04:00
|
|
|
file_menu->Append( ID_ABOUT, "&About..");
|
|
|
|
file_menu->Append( ID_QUIT, "E&xit\tAlt-X");
|
1999-05-05 06:25:38 -04:00
|
|
|
|
1999-10-08 16:09:32 -04:00
|
|
|
wxMenuBar *menu_bar = new wxMenuBar();
|
|
|
|
menu_bar->Append(file_menu, "&File");
|
1999-05-05 06:25:38 -04:00
|
|
|
|
1999-10-08 16:09:32 -04:00
|
|
|
SetMenuBar( menu_bar );
|
1999-05-05 06:25:38 -04:00
|
|
|
|
1999-10-08 16:09:32 -04:00
|
|
|
CreateStatusBar(2);
|
|
|
|
int widths[] = { -1, 100 };
|
|
|
|
SetStatusWidths( 2, widths );
|
1999-05-05 06:25:38 -04:00
|
|
|
|
1999-10-08 16:09:32 -04:00
|
|
|
m_canvas = new MyCanvas( this, -1, wxPoint(0,0), wxSize(100,100) );
|
|
|
|
m_canvas->SetScrollbars( 10, 10, 50, 100 );
|
2001-07-09 18:54:26 -04:00
|
|
|
|
1999-10-08 16:09:32 -04:00
|
|
|
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
|
2001-05-15 15:53:48 -04:00
|
|
|
|
1999-10-08 16:09:32 -04:00
|
|
|
topsizer->Add( m_canvas, 1, wxEXPAND );
|
2001-07-09 18:54:26 -04:00
|
|
|
|
|
|
|
wxSizer *sizerBtm = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
sizerBtm->Add( new MyScrolledWindowDumb(this), 1, wxEXPAND );
|
|
|
|
sizerBtm->Add( new MyScrolledWindowSmart(this), 1, wxEXPAND );
|
|
|
|
topsizer->Add( sizerBtm, 1, wxEXPAND );
|
1999-10-08 16:09:32 -04:00
|
|
|
|
|
|
|
SetAutoLayout( TRUE );
|
|
|
|
SetSizer( topsizer );
|
1999-05-05 06:25:38 -04:00
|
|
|
}
|
|
|
|
|
2000-02-22 17:39:55 -05:00
|
|
|
void MyFrame::OnDeleteAll( wxCommandEvent &WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
m_canvas->DestroyChildren();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnInsertNew( wxCommandEvent &WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
(void)new wxButton( m_canvas, -1, "Hello", wxPoint(100,100) );
|
|
|
|
}
|
|
|
|
|
1999-05-05 06:25:38 -04:00
|
|
|
void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
Close( TRUE );
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
(void)wxMessageBox( "wxScroll demo\n"
|
|
|
|
"Robert Roebling (c) 1998",
|
|
|
|
"About wxScroll Demo", wxICON_INFORMATION | wxOK );
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// MyApp
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
|
|
|
wxFrame *frame = new MyFrame();
|
|
|
|
frame->Show( TRUE );
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2001-07-09 18:54:26 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// MyScrolledWindowXXX
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void MyScrolledWindowBase::InitScrollbars()
|
|
|
|
{
|
|
|
|
wxClientDC dc(this);
|
|
|
|
dc.GetTextExtent(_T("Line 17"), NULL, &m_hLine);
|
|
|
|
|
|
|
|
// no horz scrolling
|
|
|
|
SetScrollbars(0, m_hLine, 0, m_nLines + 1, 0, 0, TRUE /* no refresh */);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyScrolledWindowDumb::OnDraw(wxDC& dc)
|
|
|
|
{
|
|
|
|
// this is useful to see which lines are redrawn
|
|
|
|
static size_t s_redrawCount = 0;
|
|
|
|
dc.SetTextForeground(s_redrawCount++ % 2 ? *wxRED : *wxBLUE);
|
|
|
|
|
|
|
|
wxCoord y = 0;
|
|
|
|
for ( size_t line = 0; line < m_nLines; line++ )
|
|
|
|
{
|
|
|
|
wxCoord yPhys;
|
|
|
|
CalcScrolledPosition(0, y, NULL, &yPhys);
|
|
|
|
|
|
|
|
dc.DrawText(wxString::Format(_T("Line %u (logical %d, physical %d)"),
|
|
|
|
line, y, yPhys), 0, y);
|
|
|
|
y += m_hLine;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyScrolledWindowSmart::OnDraw(wxDC& dc)
|
|
|
|
{
|
|
|
|
// this is useful to see which lines are redrawn
|
|
|
|
static size_t s_redrawCount = 0;
|
|
|
|
dc.SetTextForeground(s_redrawCount++ % 2 ? *wxRED : *wxBLUE);
|
|
|
|
|
|
|
|
// update region is always in device coords, translate to logical ones
|
|
|
|
wxRect rectUpdate = GetUpdateRegion().GetBox();
|
|
|
|
CalcUnscrolledPosition(rectUpdate.x, rectUpdate.y,
|
|
|
|
&rectUpdate.x, &rectUpdate.y);
|
|
|
|
|
|
|
|
size_t lineFrom = rectUpdate.y / m_hLine,
|
|
|
|
lineTo = rectUpdate.GetBottom() / m_hLine;
|
|
|
|
|
|
|
|
if ( lineTo > m_nLines - 1)
|
|
|
|
lineTo = m_nLines - 1;
|
|
|
|
|
|
|
|
wxCoord y = lineFrom*m_hLine;
|
|
|
|
for ( size_t line = lineFrom; line <= lineTo; line++ )
|
|
|
|
{
|
|
|
|
wxCoord yPhys;
|
|
|
|
CalcScrolledPosition(0, y, NULL, &yPhys);
|
|
|
|
|
|
|
|
dc.DrawText(wxString::Format(_T("Line %u (logical %d, physical %d)"),
|
|
|
|
line, y, yPhys), 0, y);
|
|
|
|
y += m_hLine;
|
|
|
|
}
|
|
|
|
}
|