split SwScrollbar up for reuse of adaptor

Change-Id: Idf46b209c573316e810371597acb1567536d9529
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137806
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
This commit is contained in:
Caolán McNamara 2022-08-04 15:33:51 +01:00
parent 20a5e0feaf
commit 4bc62c4e9b
12 changed files with 221 additions and 174 deletions

View file

@ -0,0 +1,69 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#pragma once
#include <svtools/svtdllapi.h>
#include <vcl/InterimItemWindow.hxx>
#include <vcl/scrollable.hxx>
class SVT_DLLPUBLIC ScrollAdaptor : public InterimItemWindow, public Scrollable
{
protected:
std::unique_ptr<weld::Scrollbar> m_xScrollBar;
Link<weld::Scrollbar&, void> m_aLink;
bool m_bHori;
public:
virtual void SetRange(const Range& rRange) override;
virtual Range GetRange() const override;
virtual void SetRangeMin(tools::Long nNewRange) override;
virtual tools::Long GetRangeMin() const override;
virtual void SetRangeMax(tools::Long nNewRange) override;
virtual tools::Long GetRangeMax() const override;
virtual void SetLineSize(tools::Long nNewSize) override;
virtual tools::Long GetLineSize() const override;
virtual void SetPageSize(tools::Long nNewSize) override;
virtual tools::Long GetPageSize() const override;
virtual void SetVisibleSize(tools::Long nNewSize) override;
virtual tools::Long GetVisibleSize() const override;
virtual void SetThumbPos(tools::Long nThumbPos) override;
virtual tools::Long GetThumbPos() const override;
void SetScrollHdl(const Link<weld::Scrollbar&, void>& rLink);
// what is it
bool IsHoriScroll() const { return m_bHori; }
virtual tools::Long DoScroll(tools::Long nNewPos) override;
virtual bool Inactive() const override { return !m_xScrollBar->get_sensitive(); }
ScrollAdaptor(vcl::Window* pParent, bool bHori);
virtual void dispose() override;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -99,6 +99,7 @@ $(eval $(call gb_Library_add_exception_objects,svt,\
svtools/source/control/inettbc \
svtools/source/control/ruler \
svtools/source/control/scriptedtext \
svtools/source/control/scrolladaptor \
svtools/source/control/tabbar \
svtools/source/control/toolbarmenu \
svtools/source/control/valueacc \

View file

@ -31,6 +31,7 @@ $(eval $(call gb_UIConfig_add_uifiles,svt,\
svtools/uiconfig/ui/printersetupdialog \
svtools/uiconfig/ui/querydeletedialog \
svtools/uiconfig/ui/restartdialog \
svtools/uiconfig/ui/scrollbars \
svtools/uiconfig/ui/spinfieldcontrol \
svtools/uiconfig/ui/subtoolbar \
svtools/uiconfig/ui/tabbuttons \

View file

@ -0,0 +1,112 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <svtools/scrolladaptor.hxx>
ScrollAdaptor::ScrollAdaptor(vcl::Window* pWin, bool bHoriz)
: InterimItemWindow(pWin, "svt/ui/scrollbars.ui", "ScrollBars")
, m_xScrollBar(m_xBuilder->weld_scrollbar(bHoriz ? "horizontal" : "vertical"))
, m_bHori(bHoriz)
{
m_xScrollBar->show();
}
void ScrollAdaptor::dispose()
{
m_xScrollBar.reset();
InterimItemWindow::dispose();
}
void ScrollAdaptor::SetRange(const Range& rRange)
{
m_xScrollBar->adjustment_set_lower(rRange.Min());
m_xScrollBar->adjustment_set_upper(rRange.Max());
}
Range ScrollAdaptor::GetRange() const
{
return Range(m_xScrollBar->adjustment_get_lower(), m_xScrollBar->adjustment_get_upper());
}
void ScrollAdaptor::SetRangeMin(tools::Long nNewRange)
{
m_xScrollBar->adjustment_set_lower(nNewRange);
}
tools::Long ScrollAdaptor::GetRangeMin() const { return m_xScrollBar->adjustment_get_lower(); }
void ScrollAdaptor::SetRangeMax(tools::Long nNewRange)
{
m_xScrollBar->adjustment_set_upper(nNewRange);
}
tools::Long ScrollAdaptor::GetRangeMax() const { return m_xScrollBar->adjustment_get_upper(); }
void ScrollAdaptor::SetLineSize(tools::Long nNewSize)
{
m_xScrollBar->adjustment_set_step_increment(nNewSize);
}
tools::Long ScrollAdaptor::GetLineSize() const
{
return m_xScrollBar->adjustment_get_step_increment();
}
void ScrollAdaptor::SetPageSize(tools::Long nNewSize)
{
m_xScrollBar->adjustment_set_page_increment(nNewSize);
}
tools::Long ScrollAdaptor::GetPageSize() const
{
return m_xScrollBar->adjustment_get_page_increment();
}
void ScrollAdaptor::SetVisibleSize(tools::Long nNewSize)
{
m_xScrollBar->adjustment_set_page_size(nNewSize);
}
tools::Long ScrollAdaptor::GetVisibleSize() const
{
return m_xScrollBar->adjustment_get_page_size();
}
void ScrollAdaptor::SetThumbPos(tools::Long nThumbPos)
{
m_xScrollBar->adjustment_set_value(nThumbPos);
}
tools::Long ScrollAdaptor::GetThumbPos() const { return m_xScrollBar->adjustment_get_value(); }
void ScrollAdaptor::SetScrollHdl(const Link<weld::Scrollbar&, void>& rLink)
{
m_aLink = rLink;
m_xScrollBar->connect_adjustment_changed(rLink);
}
tools::Long ScrollAdaptor::DoScroll(tools::Long nNewPos)
{
const auto nOrig = m_xScrollBar->adjustment_get_value();
m_xScrollBar->adjustment_set_value(nNewPos);
m_aLink.Call(*m_xScrollBar);
return m_xScrollBar->adjustment_get_value() - nOrig;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface domain="sw">
<interface domain="svt">
<requires lib="gtk+" version="3.20"/>
<object class="GtkAdjustment" id="adjustment1">
<property name="upper">100</property>

View file

@ -282,7 +282,6 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/swriter,\
sw/uiconfig/swriter/ui/pageheaderpanel \
sw/uiconfig/swriter/ui/pagefooterpanel \
sw/uiconfig/swriter/ui/poseditbox \
sw/uiconfig/swriter/ui/scrollbars \
sw/uiconfig/swriter/ui/sidebarwrap \
sw/uiconfig/swriter/ui/sidebarstylepresets \
sw/uiconfig/swriter/ui/sidebartableedit \

View file

@ -18,72 +18,31 @@
*/
#pragma once
#include <vcl/InterimItemWindow.hxx>
#include <vcl/scrollable.hxx>
#include <svtools/scrolladaptor.hxx>
class SwScrollbar final : public InterimItemWindow
, public Scrollable
class SwScrollbar final : public ScrollAdaptor
{
Size m_aDocSz;
bool m_bHori :1; // horizontal = true, otherwise vertical
bool m_bAuto :1; // for scrolling mode
bool m_bVisible :1; // show/hide should only set this flag
bool m_bSizeSet :1; // was the size already set?
std::unique_ptr<weld::Scrollbar> m_xScrollBar;
Link<weld::Scrollbar&, void> m_aLink;
void AutoShow();
using Window::Hide;
using Window::IsVisible;
public:
void ExtendedShow( bool bVisible = true );
void SetPosSizePixel( const Point& rNewPos, const Size& rNewSize ) override;
bool IsVisible(bool bReal) const { return bReal ? InterimItemWindow::IsVisible() : m_bVisible; }
bool IsScrollbarVisible(bool bReal) const { return bReal ? ScrollAdaptor::IsVisible() : m_bVisible; }
// changing of document size
void DocSzChgd(const Size &rNewSize);
// changing of visible region
void ViewPortChgd(const tools::Rectangle &rRectangle);
// what is it??
bool IsHoriScroll() const { return m_bHori; }
void SetAuto(bool bSet);
bool IsAuto() const { return m_bAuto;}
virtual void SetRange(const Range& rRange) override;
virtual Range GetRange() const override;
virtual void SetRangeMin(tools::Long nNewRange) override;
virtual tools::Long GetRangeMin() const override;
virtual void SetRangeMax(tools::Long nNewRange) override;
virtual tools::Long GetRangeMax() const override;
virtual void SetLineSize(tools::Long nNewSize) override;
virtual tools::Long GetLineSize() const override;
virtual void SetPageSize(tools::Long nNewSize) override;
virtual tools::Long GetPageSize() const override;
virtual void SetVisibleSize(tools::Long nNewSize) override;
virtual tools::Long GetVisibleSize() const override;
virtual void SetThumbPos(tools::Long nThumbPos) override;
virtual tools::Long GetThumbPos() const override;
void SetScrollHdl(const Link<weld::Scrollbar&, void>& rLink);
virtual tools::Long DoScroll(tools::Long nNewPos) override;
virtual bool Inactive() const override
{
return !m_xScrollBar->get_sensitive();
}
SwScrollbar(vcl::Window *pParent, bool bHori );
virtual void dispose() override;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -1293,9 +1293,9 @@ void SwPagePreview::CalcAndSetBorderPixel( SvBorder &rToFill )
{
const StyleSettings &rSet = m_pViewWin->GetSettings().GetStyleSettings();
const tools::Long nTmp = rSet.GetScrollBarSize();
if ( m_pVScrollbar->IsVisible( true ) )
if (m_pVScrollbar->IsScrollbarVisible(true))
rToFill.Right() = nTmp;
if ( m_pHScrollbar->IsVisible( true ) )
if (m_pHScrollbar->IsScrollbarVisible(true))
rToFill.Bottom() = nTmp;
SetBorderPixel( rToFill );
}

View file

@ -22,12 +22,10 @@
#define SCROLL_LINE_SIZE 250
SwScrollbar::SwScrollbar(vcl::Window *pWin, bool bHoriz)
: InterimItemWindow(pWin, "modules/swriter/ui/scrollbars.ui", "ScrollBars")
, m_bHori(bHoriz)
: ScrollAdaptor(pWin, bHoriz)
, m_bAuto(false)
, m_bVisible(false)
, m_bSizeSet(false)
, m_xScrollBar(m_xBuilder->weld_scrollbar(bHoriz ? "horizontal" : "vertical"))
{
m_xScrollBar->show();
@ -36,12 +34,6 @@ SwScrollbar::SwScrollbar(vcl::Window *pWin, bool bHoriz)
m_xScrollBar->set_direction(false);
}
void SwScrollbar::dispose()
{
m_xScrollBar.reset();
InterimItemWindow::dispose();
}
// Will be called after a change of the document size
// to refresh the range of the scrollbars.
void SwScrollbar::DocSzChgd( const Size &rSize )
@ -80,13 +72,13 @@ void SwScrollbar::ExtendedShow( bool bSet )
m_bVisible = bSet;
if( (!bSet || !m_bAuto) && IsUpdateMode() && m_bSizeSet)
{
InterimItemWindow::Show(bSet);
ScrollAdaptor::Show(bSet);
}
}
void SwScrollbar::SetPosSizePixel( const Point& rNewPos, const Size& rNewSize )
{
InterimItemWindow::SetPosSizePixel(rNewPos, rNewSize);
ScrollAdaptor::SetPosSizePixel(rNewPos, rNewSize);
m_bSizeSet = true;
if(m_bVisible)
ExtendedShow();
@ -99,7 +91,7 @@ void SwScrollbar::SetAuto(bool bSet)
m_bAuto = bSet;
// hide automatically - then show
if(!m_bAuto && m_bVisible && !InterimItemWindow::IsVisible())
if(!m_bAuto && m_bVisible && !ScrollAdaptor::IsVisible())
ExtendedShow();
else if(m_bAuto)
AutoShow(); // or hide automatically
@ -110,101 +102,15 @@ void SwScrollbar::AutoShow()
{
tools::Long nVis = GetVisibleSize();
tools::Long nLen = GetRange().Len();
if( nVis >= nLen - 1)
if (nVis >= nLen - 1)
{
if(InterimItemWindow::IsVisible())
InterimItemWindow::Show(false);
if (ScrollAdaptor::IsVisible())
ScrollAdaptor::Show(false);
}
else if ( !InterimItemWindow::IsVisible() )
else if (!ScrollAdaptor::IsVisible())
{
InterimItemWindow::Show();
ScrollAdaptor::Show();
}
}
void SwScrollbar::SetRange(const Range& rRange)
{
m_xScrollBar->adjustment_set_lower(rRange.Min());
m_xScrollBar->adjustment_set_upper(rRange.Max());
}
Range SwScrollbar::GetRange() const
{
return Range(m_xScrollBar->adjustment_get_lower(),
m_xScrollBar->adjustment_get_upper());
}
void SwScrollbar::SetRangeMin(tools::Long nNewRange)
{
m_xScrollBar->adjustment_set_lower(nNewRange);
}
tools::Long SwScrollbar::GetRangeMin() const
{
return m_xScrollBar->adjustment_get_lower();
}
void SwScrollbar::SetRangeMax(tools::Long nNewRange)
{
m_xScrollBar->adjustment_set_upper(nNewRange);
}
tools::Long SwScrollbar::GetRangeMax() const
{
return m_xScrollBar->adjustment_get_upper();
}
void SwScrollbar::SetLineSize(tools::Long nNewSize)
{
m_xScrollBar->adjustment_set_step_increment(nNewSize);
}
tools::Long SwScrollbar::GetLineSize() const
{
return m_xScrollBar->adjustment_get_step_increment();
}
void SwScrollbar::SetPageSize(tools::Long nNewSize)
{
m_xScrollBar->adjustment_set_page_increment(nNewSize);
}
tools::Long SwScrollbar::GetPageSize() const
{
return m_xScrollBar->adjustment_get_page_increment();
}
void SwScrollbar::SetVisibleSize(tools::Long nNewSize)
{
m_xScrollBar->adjustment_set_page_size(nNewSize);
}
tools::Long SwScrollbar::GetVisibleSize() const
{
return m_xScrollBar->adjustment_get_page_size();
}
void SwScrollbar::SetThumbPos(tools::Long nThumbPos)
{
m_xScrollBar->adjustment_set_value(nThumbPos);
}
tools::Long SwScrollbar::GetThumbPos() const
{
return m_xScrollBar->adjustment_get_value();
}
void SwScrollbar::SetScrollHdl(const Link<weld::Scrollbar&, void>& rLink)
{
m_aLink = rLink;
m_xScrollBar->connect_adjustment_changed(rLink);
}
tools::Long SwScrollbar::DoScroll(tools::Long nNewPos)
{
const auto nOrig = m_xScrollBar->adjustment_get_value();
m_xScrollBar->adjustment_set_value(nNewPos);
m_aLink.Call(*m_xScrollBar);
return m_xScrollBar->adjustment_get_value() - nOrig;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -1049,9 +1049,9 @@ SwView::SwView( SfxViewFrame *_pFrame, SfxViewShell* pOldSh )
rDocSh.EnableSetModified();
InvalidateBorder();
if( !m_pHScrollbar->IsVisible( true ) )
if( !m_pHScrollbar->IsScrollbarVisible(true) )
ShowHScrollbar( false );
if( !m_pVScrollbar->IsVisible( true ) )
if( !m_pVScrollbar->IsScrollbarVisible(true) )
ShowVScrollbar( false );
if (m_pWrtShell && m_pWrtShell->GetViewOptions()->IsShowOutlineContentVisibilityButton())

View file

@ -728,7 +728,7 @@ void SwView::ShowHScrollbar(bool bShow)
bool SwView::IsHScrollbarVisible()const
{
assert(m_pHScrollbar && "Scrollbar invalid");
return m_pHScrollbar->IsVisible( false ) || m_pHScrollbar->IsAuto();
return m_pHScrollbar->IsScrollbarVisible(false) || m_pHScrollbar->IsAuto();
}
void SwView::ShowVScrollbar(bool bShow)
@ -740,7 +740,7 @@ void SwView::ShowVScrollbar(bool bShow)
bool SwView::IsVScrollbarVisible()const
{
assert(m_pVScrollbar && "Scrollbar invalid");
return m_pVScrollbar->IsVisible( false );
return m_pVScrollbar->IsScrollbarVisible(false);
}
void SwView::EnableHScrollbar(bool bEnable)

View file

@ -834,14 +834,14 @@ void SwView::CalcAndSetBorderPixel( SvBorder &rToFill )
const StyleSettings &rSet = GetEditWin().GetSettings().GetStyleSettings();
const tools::Long nTmp = rSet.GetScrollBarSize();
if( m_pVScrollbar->IsVisible(true) )
if( m_pVScrollbar->IsScrollbarVisible(true) )
{
if(bRightVRuler)
rToFill.Left() = nTmp;
else
rToFill.Right() = nTmp;
}
if ( m_pHScrollbar->IsVisible(true) )
if ( m_pHScrollbar->IsScrollbarVisible(true) )
rToFill.Bottom() = nTmp;
SetBorderPixel( rToFill );
@ -868,8 +868,8 @@ void ViewResizePixel( const vcl::RenderContext &rRef,
pVRuler->GetSizePixel().Width() : 0;
const tools::Long nScrollBarSize = rRef.GetSettings().GetStyleSettings().GetScrollBarSize();
const tools::Long nHBSzHeight = rHScrollbar.IsVisible(true) ? nScrollBarSize : 0;
const tools::Long nVBSzWidth = rVScrollbar.IsVisible(true) ? nScrollBarSize : 0;
const tools::Long nHBSzHeight = rHScrollbar.IsScrollbarVisible(true) ? nScrollBarSize : 0;
const tools::Long nVBSzWidth = rVScrollbar.IsScrollbarVisible(true) ? nScrollBarSize : 0;
if(pVRuler)
{
@ -967,8 +967,8 @@ void SwView::InnerResizePixel( const Point &rOfst, const Size &rSize, bool )
}
m_bInInnerResizePixel = true;
const bool bHScrollVisible = m_pHScrollbar->IsVisible(true);
const bool bVScrollVisible = m_pVScrollbar->IsVisible(true);
const bool bHScrollVisible = m_pHScrollbar->IsScrollbarVisible(true);
const bool bVScrollVisible = m_pVScrollbar->IsScrollbarVisible(true);
bool bRepeat = false;
do
{
@ -1023,8 +1023,8 @@ void SwView::InnerResizePixel( const Point &rOfst, const Size &rSize, bool )
// require to repeat the ViewResizePixel() call - but only once!
if(bRepeat)
bRepeat = false;
else if(bHScrollVisible != m_pHScrollbar->IsVisible(true) ||
bVScrollVisible != m_pVScrollbar->IsVisible(true))
else if(bHScrollVisible != m_pHScrollbar->IsScrollbarVisible(true) ||
bVScrollVisible != m_pVScrollbar->IsScrollbarVisible(true))
bRepeat = true;
}while( bRepeat );
bProtectDocShellVisArea = false;
@ -1066,10 +1066,10 @@ void SwView::OuterResizePixel( const Point &rOfst, const Size &rSize )
{
bShowH = bShowV = bHAuto = bAuto = false;
}
if(m_pHScrollbar->IsVisible(false) != bShowH && !bHAuto)
if(m_pHScrollbar->IsScrollbarVisible(false) != bShowH && !bHAuto)
ShowHScrollbar(bShowH);
m_pHScrollbar->SetAuto( bHAuto );
if(m_pVScrollbar->IsVisible(false) != bShowV && !bAuto)
if(m_pVScrollbar->IsScrollbarVisible(false) != bShowV && !bAuto)
ShowVScrollbar(bShowV);
m_pVScrollbar->SetAuto(bAuto);
@ -1083,8 +1083,8 @@ void SwView::OuterResizePixel( const Point &rOfst, const Size &rSize )
do {
++nCnt;
const bool bScroll1 = m_pVScrollbar->IsVisible(true);
const bool bScroll2 = m_pHScrollbar->IsVisible(true);
const bool bScroll1 = m_pVScrollbar->IsScrollbarVisible(true);
const bool bScroll2 = m_pHScrollbar->IsScrollbarVisible(true);
SvBorder aBorder;
CalcAndSetBorderPixel( aBorder );
const Size aEditSz( GetEditWin().GetOutputSizePixel() );
@ -1122,9 +1122,9 @@ void SwView::OuterResizePixel( const Point &rOfst, const Size &rSize )
SetZoom_( aEditSz, m_pWrtShell->GetViewOptions()->GetZoomType(), 100, true );
m_pWrtShell->EndAction();
bRepeat = bScroll1 != m_pVScrollbar->IsVisible(true);
bRepeat = bScroll1 != m_pVScrollbar->IsScrollbarVisible(true);
if ( !bRepeat )
bRepeat = bScroll2 != m_pHScrollbar->IsVisible(true);
bRepeat = bScroll2 != m_pHScrollbar->IsScrollbarVisible(true);
// Do no infinite loops.
// If possible stop when the (auto-) scroll bars are visible.
@ -1179,19 +1179,19 @@ bool SwView::UpdateScrollbars()
aTmpSz.AdjustWidth(lOfst ); aTmpSz.AdjustHeight(lOfst );
{
const bool bVScrollVisible = m_pVScrollbar->IsVisible(true);
const bool bVScrollVisible = m_pVScrollbar->IsScrollbarVisible(true);
m_pVScrollbar->DocSzChgd( aTmpSz );
m_pVScrollbar->ViewPortChgd( aTmpRect );
if ( bVScrollVisible != m_pVScrollbar->IsVisible(true) )
if ( bVScrollVisible != m_pVScrollbar->IsScrollbarVisible(true) )
bRet = true;
}
{
const bool bHScrollVisible = m_pHScrollbar->IsVisible(true);
const bool bHScrollVisible = m_pHScrollbar->IsScrollbarVisible(true);
m_pHScrollbar->DocSzChgd( aTmpSz );
m_pHScrollbar->ViewPortChgd( aTmpRect );
if ( bHScrollVisible != m_pHScrollbar->IsVisible(true) )
if ( bHScrollVisible != m_pHScrollbar->IsScrollbarVisible(true) )
bRet = true;
m_pScrollFill->Show(m_pHScrollbar->IsVisible(true) && m_pVScrollbar->IsVisible(true) );
m_pScrollFill->Show(m_pHScrollbar->IsScrollbarVisible(true) && m_pVScrollbar->IsScrollbarVisible(true) );
}
}
return bRet;