reverted wxHVScrolledWindow patch (back to rev 1.10)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38728 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-04-14 22:03:07 +00:00
parent 5e888f8eef
commit 4c384a0b37

View File

@@ -2,7 +2,7 @@
// Name: samples/vscroll/vstest.cpp // Name: samples/vscroll/vstest.cpp
// Purpose: VScroll wxWidgets sample // Purpose: VScroll wxWidgets sample
// Author: Vadim Zeitlin // Author: Vadim Zeitlin
// Modified by: Brad Anderson // Modified by:
// Created: 04/01/98 // Created: 04/01/98
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org> // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
@@ -44,18 +44,12 @@
#include "../sample.xpm" #include "../sample.xpm"
#endif #endif
// ----------------------------------------------------------------------------
// definitions
// ----------------------------------------------------------------------------
#define MAX_LINES 200
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// private classes // private classes
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Define a new application type, each program should derive a class from wxApp // Define a new application type, each program should derive a class from wxApp
class VarScrollApp : public wxApp class VScrollApp : public wxApp
{ {
public: public:
// create our main window // create our main window
@@ -63,16 +57,14 @@ public:
}; };
// Define a new frame type: this is going to be our main frame // Define a new frame type: this is going to be our main frame
class VarScrollFrame : public wxFrame class VScrollFrame : public wxFrame
{ {
public: public:
// ctor // ctor
VarScrollFrame(); VScrollFrame();
// event handlers (these functions should _not_ be virtual) // event handlers (these functions should _not_ be virtual)
void OnQuit(wxCommandEvent& event); void OnQuit(wxCommandEvent& event);
void OnModeVScroll(wxCommandEvent& event);
void OnModeHVScroll(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event); void OnAbout(wxCommandEvent& event);
void OnSize(wxSizeEvent& event) void OnSize(wxSizeEvent& event)
@@ -92,9 +84,6 @@ public:
private: private:
// any class wishing to process wxWidgets events must use this macro // any class wishing to process wxWidgets events must use this macro
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
// either a wxVScrolledWindow or a wxHVScrolled window, depending on current mode
wxPanel *m_scrollWindow;
}; };
class VScrollWindow : public wxVScrolledWindow class VScrollWindow : public wxVScrolledWindow
@@ -104,12 +93,8 @@ public:
{ {
m_frame = frame; m_frame = frame;
SetLineCount(MAX_LINES); SetLineCount(200);
int i;
for ( i = 0; i < MAX_LINES; ++i )
m_heights[i] = rand()%25+16; // low: 15; high: 40
m_changed = true; m_changed = true;
} }
@@ -131,23 +116,21 @@ public:
{ {
wxPaintDC dc(this); wxPaintDC dc(this);
dc.SetPen(*wxBLACK_PEN); dc.SetPen(*wxBLACK_DASHED_PEN);
const size_t lineFirst = GetVisibleBegin(), const size_t lineFirst = GetFirstVisibleLine(),
lineLast = GetVisibleEnd(); lineLast = GetLastVisibleLine();
const wxCoord hText = dc.GetCharHeight(); const wxCoord hText = dc.GetCharHeight();
wxSize clientSize = GetClientSize();
wxCoord y = 0; wxCoord y = 0;
for ( size_t line = lineFirst; line < lineLast; line++ ) for ( size_t line = lineFirst; line <= lineLast; line++ )
{ {
dc.DrawLine(0, y, clientSize.GetWidth(), y); dc.DrawLine(0, y, 1000, y);
wxCoord hLine = OnGetLineHeight(line); wxCoord hLine = OnGetLineHeight(line);
dc.DrawText(wxString::Format(_T("Line %lu"), (unsigned long)line), dc.DrawText(wxString::Format(_T("Line %lu"), (unsigned long)line),
2, y + (hLine - hText) / 2); 0, y + (hLine - hText) / 2);
y += hLine; y += hLine;
dc.DrawLine(0, y, 1000, y); dc.DrawLine(0, y, 1000, y);
@@ -166,14 +149,12 @@ public:
{ {
wxASSERT( n < GetLineCount() ); wxASSERT( n < GetLineCount() );
return m_heights[n]; return n % 2 ? 15 : 30; // 15 + 2*n
} }
private: private:
wxFrame *m_frame; wxFrame *m_frame;
int m_heights[MAX_LINES];
bool m_changed; bool m_changed;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
@@ -185,126 +166,6 @@ BEGIN_EVENT_TABLE(VScrollWindow, wxVScrolledWindow)
EVT_SCROLLWIN(VScrollWindow::OnScroll) EVT_SCROLLWIN(VScrollWindow::OnScroll)
END_EVENT_TABLE() END_EVENT_TABLE()
class HVScrollWindow : public wxHVScrolledWindow
{
public:
HVScrollWindow(wxFrame *frame) : wxHVScrolledWindow(frame, wxID_ANY)
{
m_frame = frame;
SetRowColumnCounts(MAX_LINES, MAX_LINES);
int i;
for ( i = 0; i < MAX_LINES; ++i )
{
m_heights[i] = rand()%30+31; // low: 30; high: 60
m_widths[i] = rand()%30+61; // low: 60; high: 90
}
m_changed = true;
}
void OnIdle(wxIdleEvent&)
{
#if wxUSE_STATUSBAR
m_frame->SetStatusText(wxString::Format
(
_T("Page size = %d rows %d columns; pos = row: %d, column: %d; max = %d rows, %d columns"),
GetScrollThumb(wxVERTICAL),
GetScrollThumb(wxHORIZONTAL),
GetScrollPos(wxVERTICAL),
GetScrollPos(wxHORIZONTAL),
GetScrollRange(wxVERTICAL),
GetScrollRange(wxHORIZONTAL)
));
#endif // wxUSE_STATUSBAR
m_changed = false;
}
void OnPaint(wxPaintEvent&)
{
wxPaintDC dc(this);
dc.SetPen(*wxBLACK_PEN);
const size_t rowFirst = GetVisibleRowsBegin(),
rowLast = GetVisibleRowsEnd();
const size_t columnFirst = GetVisibleColumnsBegin(),
columnLast = GetVisibleColumnsEnd();
const wxCoord hText = dc.GetCharHeight();
wxSize clientSize = GetClientSize();
wxCoord y = 0;
wxCoord x = 0;
for ( size_t row = rowFirst; row < rowLast; row++ )
{
wxCoord rowHeight = OnGetRowHeight(row);
dc.DrawLine(0, y, clientSize.GetWidth(), y);
x = 0;
for ( size_t col = columnFirst; col < columnLast; col++ )
{
wxCoord colWidth = OnGetColumnWidth(col);
if ( row == rowFirst )
dc.DrawLine(x, 0, x, clientSize.GetHeight());
dc.DrawText(wxString::Format(_T("Row %lu"), (unsigned long)row),
x + 2, y + rowHeight / 2 - hText);
dc.DrawText(wxString::Format(_T("Col %lu"), (unsigned long)col),
x + 2, y + rowHeight / 2);
x += colWidth;
if ( row == rowFirst)
dc.DrawLine(x, 0, x, clientSize.GetHeight());
}
y += rowHeight;
dc.DrawLine(0, y, clientSize.GetWidth(), y);
}
}
void OnScroll(wxScrollWinEvent& event)
{
m_changed = true;
event.Skip();
}
virtual wxCoord OnGetRowHeight(size_t n) const
{
wxASSERT( n < GetRowCount() );
return m_heights[n];
}
virtual wxCoord OnGetColumnWidth(size_t n) const
{
wxASSERT( n < GetColumnCount() );
return m_widths[n];
}
private:
wxFrame *m_frame;
int m_heights[MAX_LINES];
int m_widths[MAX_LINES];
bool m_changed;
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(HVScrollWindow, wxHVScrolledWindow)
EVT_IDLE(HVScrollWindow::OnIdle)
EVT_PAINT(HVScrollWindow::OnPaint)
EVT_SCROLLWIN(HVScrollWindow::OnScroll)
END_EVENT_TABLE()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// constants // constants
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -318,10 +179,7 @@ enum
// it is important for the id corresponding to the "About" command to have // it is important for the id corresponding to the "About" command to have
// this standard value as otherwise it won't be handled properly under Mac // this standard value as otherwise it won't be handled properly under Mac
// (where it is special and put into the "Apple" menu) // (where it is special and put into the "Apple" menu)
VScroll_About = wxID_ABOUT, VScroll_About = wxID_ABOUT
VScroll_VScrollMode = wxID_HIGHEST + 1,
VScroll_HVScrollMode
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -331,20 +189,18 @@ enum
// the event tables connect the wxWidgets events with the functions (event // the event tables connect the wxWidgets events with the functions (event
// handlers) which process them. It can be also done at run-time, but for the // handlers) which process them. It can be also done at run-time, but for the
// simple menu events like this the static method is much simpler. // simple menu events like this the static method is much simpler.
BEGIN_EVENT_TABLE(VarScrollFrame, wxFrame) BEGIN_EVENT_TABLE(VScrollFrame, wxFrame)
EVT_MENU(VScroll_Quit, VarScrollFrame::OnQuit) EVT_MENU(VScroll_Quit, VScrollFrame::OnQuit)
EVT_MENU(VScroll_VScrollMode, VarScrollFrame::OnModeVScroll) EVT_MENU(VScroll_About, VScrollFrame::OnAbout)
EVT_MENU(VScroll_HVScrollMode, VarScrollFrame::OnModeHVScroll) EVT_SIZE(VScrollFrame::OnSize)
EVT_MENU(VScroll_About, VarScrollFrame::OnAbout)
EVT_SIZE(VarScrollFrame::OnSize)
END_EVENT_TABLE() END_EVENT_TABLE()
// Create a new application object: this macro will allow wxWidgets to create // Create a new application object: this macro will allow wxWidgets to create
// the application object during program execution (it's better than using a // the application object during program execution (it's better than using a
// static object for many reasons) and also declares the accessor function // static object for many reasons) and also declares the accessor function
// wxGetApp() which will return the reference of the right type (i.e. VarScrollApp and // wxGetApp() which will return the reference of the right type (i.e. VScrollApp and
// not wxApp) // not wxApp)
IMPLEMENT_APP(VarScrollApp) IMPLEMENT_APP(VScrollApp)
// ============================================================================ // ============================================================================
// implementation // implementation
@@ -355,10 +211,10 @@ IMPLEMENT_APP(VarScrollApp)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// 'Main program' equivalent: the program execution "starts" here // 'Main program' equivalent: the program execution "starts" here
bool VarScrollApp::OnInit() bool VScrollApp::OnInit()
{ {
// create the main application window // create the main application window
VarScrollFrame *frame = new VarScrollFrame; VScrollFrame *frame = new VScrollFrame;
// and show it (the frames, unlike simple controls, are not shown when // and show it (the frames, unlike simple controls, are not shown when
// created initially) // created initially)
@@ -373,13 +229,12 @@ bool VarScrollApp::OnInit()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// frame constructor // frame constructor
VarScrollFrame::VarScrollFrame() VScrollFrame::VScrollFrame()
: wxFrame(NULL, : wxFrame(NULL,
wxID_ANY, wxID_ANY,
_T("VScroll wxWidgets Sample"), _T("VScroll wxWidgets Sample"),
wxDefaultPosition, wxDefaultPosition,
wxSize(400, 350)), wxSize(400, 350))
m_scrollWindow(NULL)
{ {
// set the frame icon // set the frame icon
SetIcon(wxICON(sample)); SetIcon(wxICON(sample));
@@ -388,32 +243,15 @@ VarScrollFrame::VarScrollFrame()
// create a menu bar // create a menu bar
wxMenu *menuFile = new wxMenu; wxMenu *menuFile = new wxMenu;
wxMenu *menuMode = new wxMenu;
// the "About" item should be in the help menu // the "About" item should be in the help menu
wxMenu *menuHelp = new wxMenu; wxMenu *menuHelp = new wxMenu;
menuHelp->Append(VScroll_About, _T("&About...\tF1"), _T("Show about dialog")); menuHelp->Append(VScroll_About, _T("&About...\tF1"), _T("Show about dialog"));
#ifdef wxHAS_RADIO_MENU_ITEMS
menuMode->AppendRadioItem(VScroll_VScrollMode, _T("&Vertical\tAlt-V"),
_T("Vertical scrolling only"));
menuMode->AppendRadioItem(VScroll_HVScrollMode,
_T("&Horizontal/Vertical\tAlt-H"),
_T("Horizontal and vertical scrolling"));
menuMode->Check(VScroll_VScrollMode, true);
#else
menuMode->Append(VScroll_VScrollMode, _T("&Vertical\tAlt-V"),
_T("Vertical scrolling only"));
menuMode->Append(VScroll_HVScrollMode, _T("&Horizontal/Vertical\tAlt-H"),
_T("Horizontal and vertical scrolling"));
#endif
menuFile->Append(VScroll_Quit, _T("E&xit\tAlt-X"), _T("Quit this program")); menuFile->Append(VScroll_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
// now append the freshly created menu to the menu bar... // now append the freshly created menu to the menu bar...
wxMenuBar *menuBar = new wxMenuBar; wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append(menuFile, _T("&File")); menuBar->Append(menuFile, _T("&File"));
menuBar->Append(menuMode, _T("&Mode"));
menuBar->Append(menuHelp, _T("&Help")); menuBar->Append(menuHelp, _T("&Help"));
// ... and attach this menu bar to the frame // ... and attach this menu bar to the frame
@@ -424,51 +262,26 @@ VarScrollFrame::VarScrollFrame()
// create a status bar just for fun (by default with 1 pane only) // create a status bar just for fun (by default with 1 pane only)
CreateStatusBar(2); CreateStatusBar(2);
SetStatusText(_T("Welcome to wxWidgets!")); SetStatusText(_T("Welcome to wxWidgets!"));
int widths[2];
widths[0] = -1;
widths[1] = 100;
SetStatusWidths(2, widths);
#endif // wxUSE_STATUSBAR #endif // wxUSE_STATUSBAR
// create our one and only child -- it will take our entire client area // create our one and only child -- it will take our entire client area
if ( menuMode->IsChecked(VScroll_VScrollMode) ) new VScrollWindow(this);
m_scrollWindow = new VScrollWindow(this);
else if ( menuMode->IsChecked(VScroll_VScrollMode) )
m_scrollWindow = new HVScrollWindow(this);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// event handlers // event handlers
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void VarScrollFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) void VScrollFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{ {
// true is to force the frame to close // true is to force the frame to close
Close(true); Close(true);
} }
void VarScrollFrame::OnModeVScroll(wxCommandEvent& WXUNUSED(event)) void VScrollFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
if ( m_scrollWindow )
m_scrollWindow->Destroy();
m_scrollWindow = new VScrollWindow(this);
SendSizeEvent();
}
void VarScrollFrame::OnModeHVScroll(wxCommandEvent& WXUNUSED(event))
{
if ( m_scrollWindow )
m_scrollWindow->Destroy();
m_scrollWindow = new HVScrollWindow(this);
SendSizeEvent();
}
void VarScrollFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{ {
wxMessageBox(_T("VScroll shows how to implement scrolling with\n") wxMessageBox(_T("VScroll shows how to implement scrolling with\n")
_T("variable line widths and heights.\n") _T("variable line heights.\n")
_T("(c) 2003 Vadim Zeitlin"), _T("(c) 2003 Vadim Zeitlin"),
_T("About VScroll"), _T("About VScroll"),
wxOK | wxICON_INFORMATION, wxOK | wxICON_INFORMATION,