From efc0325e141213439f9937bf6bf31798072860af Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Wed, 21 Aug 2019 22:05:15 -0700 Subject: [PATCH] Handle wx scrollbar thumbs in system-independent way The thumb size changes between system versions and (on GTK) render managers, so hard-coded wasn't working. This gets the actual value from the system and uses to adjust the range. Changes in the range can also trigger the refresh. Fixes: lp:1822617 * https://bugs.launchpad.net/kicad/+bug/1822617 Fixes: lp:1816749 * https://bugs.launchpad.net/kicad/+bug/1816749 (cherry picked from commit 85df994eda4caae28049e92d9d48e7d45d160605) --- common/draw_panel_gal.cpp | 4 ++-- common/view/wx_view_controls.cpp | 29 ++++++++++++----------------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index 8ed3e9795a..93fa843ad3 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -148,8 +148,6 @@ void EDA_DRAW_PANEL_GAL::SetFocus() void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) ) { - m_viewControls->UpdateScrollbars(); - // Update current zoom settings if the canvas is managed by a EDA frame // (i.e. not by a preview panel in a dialog) if( GetParentEDAFrame() && GetParentEDAFrame()->GetScreen() ) @@ -160,6 +158,8 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) ) GetParentEDAFrame()->SetScrollCenterPosition( wxPoint( center.x, center.y ) ); } + m_viewControls->UpdateScrollbars(); + if( !m_gal->IsVisible() ) return; diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 5cbd7ecd70..e4d053e830 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -660,30 +660,25 @@ void WX_VIEW_CONTROLS::UpdateScrollbars() VECTOR2I newScroll( ( viewport.Centre().x - boundary.GetLeft() ) * m_scrollScale.x, ( viewport.Centre().y - boundary.GetTop() ) * m_scrollScale.y ); + // We add the width of the scroll bar thumb to the range because the scroll range is given by + // the full bar while the position is given by the left/top position of the thumb + VECTOR2I newRange( m_scrollScale.x * boundary.GetWidth() + m_parentPanel->GetScrollThumb( wxSB_HORIZONTAL ), + m_scrollScale.y * boundary.GetHeight() + m_parentPanel->GetScrollThumb( wxSB_VERTICAL ) ); + // Flip scroll direction in flipped view if( m_view->IsMirroredX() ) newScroll.x = ( boundary.GetRight() - viewport.Centre().x ) * m_scrollScale.x; - // Adjust scrollbars only if it is needed. Otherwise there are cases when canvas is continuosly + // Adjust scrollbars only if it is needed. Otherwise there are cases when canvas is continuously // refreshed (Windows) - if( m_scrollPos != newScroll ) + if( m_scrollPos != newScroll || newRange.x != m_parentPanel->GetScrollRange( wxSB_HORIZONTAL ) + || newRange.y != m_parentPanel->GetScrollRange( wxSB_VERTICAL ) ) { - // Another example of wxWidgets being broken by design: scroll position is determined by the - // left (or top, if vertical) edge of the slider. Fortunately, slider size seems to be constant - // (at least for wxGTK and wxMSW), so we have to add its size to allow user to scroll the workspace - // till the end. - - m_parentPanel->SetScrollbars( 1, 1, -#if defined(__LINUX__) - m_scrollScale.x * boundary.GetWidth() + 1623, m_scrollScale.y * boundary.GetHeight() + 1623, -#elif defined(__WIN32__) || defined(__WIN64__) - m_scrollScale.x * boundary.GetWidth() + 1377, m_scrollScale.y * boundary.GetHeight() + 741, -#else - m_scrollScale.x * boundary.GetWidth(), m_scrollScale.y * boundary.GetHeight(), -#endif - newScroll.x, newScroll.y, false ); - + m_parentPanel->SetScrollbars( 1, 1, newRange.x, newRange.y, newScroll.x, newScroll.y, true ); m_scrollPos = newScroll; + + // Trigger a mouse refresh to get the canvas update in GTK (re-draws the scrollbars) + refreshMouse(); } }