From 5713b34914d8216e1af3dce0373d10566a6d7ea3 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Wed, 13 Sep 2006 10:01:21 +0000 Subject: [PATCH] Make wxGTK's wxScrolledWindow set m_x/xScrollLines to 0 if scrollbars disappear (instead of 1) as per wxMSW. Expose m_x/yScrollLines in public getters. Correct window origin for scrolled window in RTL. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41186 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/scrolwin.h | 4 ++++ src/generic/scrlwing.cpp | 19 ++++++++++++++---- src/gtk/dcclient.cpp | 38 ++++++++++++++++++++++++++++++++---- src/gtk/scrolwin.cpp | 42 ++++++++++++++++++++++++++-------------- 4 files changed, 80 insertions(+), 23 deletions(-) diff --git a/include/wx/scrolwin.h b/include/wx/scrolwin.h index 96df44be6f..485195577d 100644 --- a/include/wx/scrolwin.h +++ b/include/wx/scrolwin.h @@ -68,6 +68,10 @@ public: 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 ); diff --git a/src/generic/scrlwing.cpp b/src/generic/scrlwing.cpp index ad1b381399..e05ecbda17 100644 --- a/src/generic/scrlwing.cpp +++ b/src/generic/scrlwing.cpp @@ -844,6 +844,15 @@ void wxScrollHelper::GetScrollPixelsPerUnit (int *x_unit, int *y_unit) const *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 ) @@ -881,7 +890,7 @@ void wxScrollHelper::Scroll( int x_pos, int y_pos ) // 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 @@ -889,7 +898,8 @@ void wxScrollHelper::Scroll( int x_pos, int y_pos ) 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() ); @@ -902,7 +912,7 @@ void wxScrollHelper::Scroll( int x_pos, int y_pos ) // 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 @@ -910,7 +920,8 @@ void wxScrollHelper::Scroll( int x_pos, int y_pos ) 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() ); diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 5d6c7a9c44..d99ad46033 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -26,6 +26,7 @@ #endif #include "wx/fontutil.h" +#include "wx/scrolwin.h" #include "wx/gtk/win_gtk.h" #include "wx/gtk/private.h" @@ -326,11 +327,40 @@ wxWindowDC::wxWindowDC( wxWindow *window ) 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; + } } } diff --git a/src/gtk/scrolwin.cpp b/src/gtk/scrolwin.cpp index cdba2c5e56..20c4d1594d 100644 --- a/src/gtk/scrolwin.cpp +++ b/src/gtk/scrolwin.cpp @@ -88,24 +88,36 @@ void wxScrollHelperNative::DoAdjustScrollbar(GtkRange* range, 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() -- 2.47.2