+ EVT_MOUSE_EVENTS(VScrollWindow::OnMouse)
+END_EVENT_TABLE()
+
+class HScrollWindow : public wxHScrolledWindow
+{
+public:
+ HScrollWindow(wxFrame *frame) : wxHScrolledWindow(frame, wxID_ANY)
+ {
+ m_frame = frame;
+
+ SetColumnCount(MAX_LINES);
+
+ int i;
+ for ( i = 0; i < MAX_LINES; ++i )
+ m_heights[i] = rand()%25+16; // low: 15; high: 40
+
+ m_changed = true;
+ }
+
+ void OnIdle(wxIdleEvent&)
+ {
+#if wxUSE_STATUSBAR
+ m_frame->SetStatusText(wxString::Format
+ (
+ _T("Page size = %d, pos = %d, max = %d"),
+ GetScrollThumb(wxVERTICAL),
+ GetScrollPos(wxVERTICAL),
+ GetScrollRange(wxVERTICAL)
+ ));
+#endif // wxUSE_STATUSBAR
+ m_changed = false;
+ }
+
+ void OnPaint(wxPaintEvent&)
+ {
+ wxPaintDC dc(this);
+
+ dc.SetPen(*wxBLACK_PEN);
+
+ const size_t lineFirst = GetVisibleBegin(),
+ lineLast = GetVisibleEnd();
+
+ const wxCoord hText = dc.GetCharHeight();
+
+ wxSize clientSize = GetClientSize();
+
+ wxCoord x = 0;
+ for ( size_t line = lineFirst; line < lineLast; line++ )
+ {
+ dc.DrawLine(x, 0, x, clientSize.GetHeight());
+
+ wxCoord wLine = OnGetColumnWidth(line);
+ dc.DrawRotatedText(wxString::Format(_T("Line %lu"), (unsigned long)line),
+ x + (wLine - hText) / 2, clientSize.GetHeight() - 5, 90);
+
+ x += wLine;
+ dc.DrawLine(x, 0, x, 1000);
+ }
+ }
+
+ void OnScroll(wxScrollWinEvent& event)
+ {
+ m_changed = true;
+
+ event.Skip();
+ }
+
+ void OnMouse(wxMouseEvent& event)
+ {
+ if(event.LeftDown())
+ CaptureMouse();
+ else if(event.LeftUp())
+ ReleaseMouse();
+ event.Skip();
+ }
+
+ virtual wxCoord OnGetColumnWidth(size_t n) const
+ {
+ wxASSERT( n < GetColumnCount() );
+
+ return m_heights[n];
+ }
+
+private:
+ wxFrame *m_frame;
+
+ int m_heights[MAX_LINES];
+
+ bool m_changed;
+
+ DECLARE_EVENT_TABLE()
+};
+
+BEGIN_EVENT_TABLE(HScrollWindow, wxHScrolledWindow)
+ EVT_IDLE(HScrollWindow::OnIdle)
+ EVT_PAINT(HScrollWindow::OnPaint)
+ EVT_SCROLLWIN(HScrollWindow::OnScroll)
+ EVT_MOUSE_EVENTS(HScrollWindow::OnMouse)
+END_EVENT_TABLE()
+
+class HVScrollWindow : public wxHVScrolledWindow
+{
+public:
+ HVScrollWindow(wxFrame *frame) : wxHVScrolledWindow(frame, wxID_ANY)
+ {
+ m_frame = frame;
+
+ SetRowColumnCount(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();
+ }
+
+ void OnMouse(wxMouseEvent& event)
+ {
+ if(event.LeftDown())
+ CaptureMouse();
+ else if(event.LeftUp())
+ ReleaseMouse();
+ 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)
+ EVT_MOUSE_EVENTS(HVScrollWindow::OnMouse)