diff options
author | U-Vladimir\Vadim <k.kergakov@gmail.com> | 2018-08-06 00:11:55 +0300 |
---|---|---|
committer | Tamás Zolnai <tamas.zolnai@collabora.com> | 2018-08-10 11:51:40 +0200 |
commit | 8055f402dbe6783884a51c8a78f4abcf7adda6c4 (patch) | |
tree | 0a33990f3b978e844818410d79fc019eab2d311c /cui | |
parent | e07fe2495b89c645a006de2966126d252aca9a0f (diff) |
tdf#113853 fix keeping visible selected items jumping by tab
Calc range of window, check if item is inside that range, calc scroll offset
Change-Id: I5ce7c95b167fe18e20f81bb4656093c15309d1c7
Reviewed-on: https://gerrit.libreoffice.org/58633
Tested-by: Jenkins
Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com>
Diffstat (limited to 'cui')
-rw-r--r-- | cui/source/options/optcolor.cxx | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/cui/source/options/optcolor.cxx b/cui/source/options/optcolor.cxx index 2e73996d46ef..91b9d75a2269 100644 --- a/cui/source/options/optcolor.cxx +++ b/cui/source/options/optcolor.cxx @@ -181,6 +181,7 @@ public: public: void SetLinks (Link<Button*,void> const&, Link<SvxColorListBox&,void> const&, Link<Control&,void> const&); unsigned GetEntryHeight () const { return vEntries[0]->GetHeight(); } + long GetScrollOffset() const { return vEntries[1]->GetTop() - vEntries[0]->GetTop(); } void Update (EditableColorConfig const*, EditableExtendedColorConfig const*); void ScrollHdl(const ScrollBar&); void ClickHdl (EditableColorConfig*, CheckBox const *); @@ -599,9 +600,7 @@ void ColorConfigWindow_Impl::AdjustHeaderBar() void ColorConfigWindow_Impl::AdjustScrollBar() { - unsigned const nScrollOffset = - vEntries[1]->GetTop() - vEntries[0]->GetTop(); - unsigned const nVisibleEntries = GetSizePixel().Height() / nScrollOffset; + unsigned const nVisibleEntries = GetSizePixel().Height() / GetScrollOffset(); m_pVScroll->SetPageSize(nVisibleEntries - 1); m_pVScroll->SetVisibleSize(nVisibleEntries); } @@ -655,8 +654,7 @@ void ColorConfigWindow_Impl::Update ( void ColorConfigWindow_Impl::ScrollHdl(const ScrollBar& rVScroll) { SetUpdateMode(true); - const long nRowHeight = (vEntries[1]->GetTop() - vEntries[0]->GetTop()); - Point aPos(0, 0 - rVScroll.GetThumbPos() * nRowHeight); + Point aPos(0, 0 - rVScroll.GetThumbPos() * GetScrollOffset()); m_pGrid->SetPosPixel(aPos); SetUpdateMode(true); } @@ -942,22 +940,32 @@ IMPL_LINK(ColorConfigCtrl_Impl, ControlFocusHdl, Control&, rCtrl, void) { // determine whether a control is completely visible // and make it visible - long aCtrlPosY = rCtrl.GetPosPixel().Y(); unsigned const nWinHeight = m_pScrollWindow->GetSizePixel().Height(); unsigned const nEntryHeight = m_pScrollWindow->GetEntryHeight(); - if ((GetFocusFlags::Tab & rCtrl.GetGetFocusFlags()) && - (aCtrlPosY < 0 || nWinHeight < aCtrlPosY + nEntryHeight) - ) { - long nThumbPos = m_pVScroll->GetThumbPos(); - if (nWinHeight < aCtrlPosY + nEntryHeight) + + // calc visible area + long const nScrollOffset = m_pScrollWindow->GetScrollOffset(); + long nThumbPos = m_pVScroll->GetThumbPos(); + long const nWinTop = (nThumbPos * nScrollOffset); + long const nWinBottom = nWinTop + nWinHeight; + + long const nCtrlPosY = rCtrl.GetPosPixel().Y(); + long const nSelectedItemPos = nCtrlPosY + nEntryHeight; + bool const shouldScrollDown = nSelectedItemPos >= nWinBottom; + bool const shouldScrollUp = nSelectedItemPos <= nWinTop; + bool const isNeedToScroll = shouldScrollDown || shouldScrollUp || nCtrlPosY < 0; + + if ((GetFocusFlags::Tab & rCtrl.GetGetFocusFlags()) && isNeedToScroll) + { + if (shouldScrollDown) { - //scroll down - nThumbPos += 2; + long nOffset = (nSelectedItemPos - nWinBottom) / nScrollOffset; + nThumbPos += nOffset + 2; } else { - //scroll up - nThumbPos -= 2; + long nOffset = (nWinTop - nSelectedItemPos) / nScrollOffset; + nThumbPos -= nOffset + 2; if(nThumbPos < 0) nThumbPos = 0; } |