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
This commit is contained in:
Seth Hillbrand 2019-08-21 22:05:15 -07:00
parent 03d5bf0df5
commit 85df994eda
2 changed files with 14 additions and 19 deletions

View File

@ -142,8 +142,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() )
@ -152,6 +150,8 @@ void EDA_DRAW_PANEL_GAL::onPaint( wxPaintEvent& WXUNUSED( aEvent ) )
GetParentEDAFrame()->GetScreen()->m_ScrollCenter = GetView()->GetCenter();
}
m_viewControls->UpdateScrollbars();
if( !m_gal->IsVisible() )
return;

View File

@ -687,30 +687,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();
}
}