int GetScrollPageSize(int orient) const;
void SetScrollPageSize(int orient, int pageSize);
+ // get the number of lines the window can scroll,
+ // returns 0 if no scrollbars are there.
+ int GetScrollLines( int orient ) const;
+
// Set the x, y scrolling increments.
void SetScrollRate( int xstep, int ystep );
*y_unit = m_yScrollPixelsPerLine;
}
+
+int wxScrollHelper::GetScrollLines( int orient ) const
+{
+ if ( orient == wxHORIZONTAL )
+ return m_xScrollLines;
+ else
+ return m_yScrollLines;
+}
+
int wxScrollHelper::GetScrollPageSize(int orient) const
{
if ( orient == wxHORIZONTAL )
// Calculate page size i.e. number of scroll units you get on the
// current client window
- int noPagePositions = (int) ( (w/(double)m_xScrollPixelsPerLine) + 0.5 );
+ int noPagePositions = w/m_xScrollPixelsPerLine;
if (noPagePositions < 1) noPagePositions = 1;
// Correct position if greater than extent of canvas minus
m_xScrollPosition = wxMin( m_xScrollLines-noPagePositions, m_xScrollPosition );
m_xScrollPosition = wxMax( 0, m_xScrollPosition );
- if (old_x != m_xScrollPosition) {
+ if (old_x != m_xScrollPosition)
+ {
m_win->SetScrollPos( wxHORIZONTAL, m_xScrollPosition );
m_targetWindow->ScrollWindow( (old_x-m_xScrollPosition)*m_xScrollPixelsPerLine, 0,
GetScrollRect() );
// Calculate page size i.e. number of scroll units you get on the
// current client window
- int noPagePositions = (int) ( (h/(double)m_yScrollPixelsPerLine) + 0.5 );
+ int noPagePositions = h/m_yScrollPixelsPerLine;
if (noPagePositions < 1) noPagePositions = 1;
// Correct position if greater than extent of canvas minus
m_yScrollPosition = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition );
m_yScrollPosition = wxMax( 0, m_yScrollPosition );
- if (old_y != m_yScrollPosition) {
+ if (old_y != m_yScrollPosition)
+ {
m_win->SetScrollPos( wxVERTICAL, m_yScrollPosition );
m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine,
GetScrollRect() );
#endif
#include "wx/fontutil.h"
+#include "wx/scrolwin.h"
#include "wx/gtk/win_gtk.h"
#include "wx/gtk/private.h"
if (m_owner && m_owner->m_wxwindow && (m_owner->GetLayoutDirection() == wxLayout_RightToLeft))
{
+ // reverse sense
m_signX = -1;
- gint width;
- gdk_window_get_geometry( GTK_PIZZA(m_owner->m_wxwindow)->bin_window,
- NULL, NULL, &width, NULL, NULL );
- m_deviceOriginX = width;;
+
+ // origin in the upper right corner
+ wxScrolledWindow *sw = wxDynamicCast( m_owner, wxScrolledWindow );
+ if (sw)
+ {
+ // We cannot use just the virtual size here, because
+ // the virtual size may be less than the visible area
+ // due to rounding errors of the scroll steps. If the
+ // horizontal scroll step is 10 pixels and the virtual
+ // area is 97 pixels, we should be able to see or scroll
+ // to 100 pixels, so the origin is at -100, not -97.
+ if (sw->GetScrollLines(wxHORIZONTAL) == 0)
+ {
+ int client_width = m_owner->GetClientSize().x;
+ m_deviceOriginX = client_width;
+ }
+ else
+ {
+ int scroll_step = 0;
+ sw->GetScrollPixelsPerUnit( &scroll_step, NULL );
+ int client_width = m_owner->GetClientSize().x;
+ int virtual_size = sw->GetVirtualSize().x;
+ int steps = (virtual_size + scroll_step - 1) / scroll_step;
+ int width = steps * scroll_step + (client_width % scroll_step);
+ m_deviceOriginX = width;
+ }
+ }
+ else
+ {
+ int client_width = m_owner->GetClientSize().x;
+ m_deviceOriginX = client_width;
+ }
}
}
int *lines,
int *linesPerPage)
{
- // GtkRange won't allow upper == lower, so for disabled state use [0,1]
- // with a page size of 1. This will also clamp position to 0.
- int upper = 1;
- int page_size = 1;
if (pixelsPerLine > 0 && winSize > 0 && winSize < virtSize)
{
- upper = (virtSize + pixelsPerLine - 1) / pixelsPerLine;
- page_size = winSize / pixelsPerLine;
+ int upper = (virtSize + pixelsPerLine - 1) / pixelsPerLine;
+ int page_size = winSize / pixelsPerLine;
+
+ *lines = upper;
+ *linesPerPage = page_size;
+
+ GtkAdjustment* adj = range->adjustment;
+ adj->step_increment = 1;
+ adj->page_increment =
+ adj->page_size = page_size;
+ gtk_range_set_range(range, 0, upper);
+ }
+ else
+ {
+ // GtkRange won't allow upper == lower, so for disabled state use [0,1]
+ // with a page size of 1. This will also clamp position to 0.
+ int upper = 1;
+ int page_size = 1;
+
+ *lines = 0;
+ *linesPerPage = 0;
+
+ GtkAdjustment* adj = range->adjustment;
+ adj->step_increment = 1;
+ adj->page_increment =
+ adj->page_size = page_size;
+ gtk_range_set_range(range, 0, upper);
}
-
- *lines = upper;
- *linesPerPage = page_size;
-
- GtkAdjustment* adj = range->adjustment;
- adj->step_increment = 1;
- adj->page_increment =
- adj->page_size = page_size;
- gtk_range_set_range(range, 0, upper);
}
void wxScrollHelperNative::AdjustScrollbars()