+// ----------------------------------------------------------------------------
+// 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;
+ }
+}