[Libreoffice-commits] core.git: Branch 'distro/lhm/libreoffice-6-1+backports' - include/vcl toolkit/source vcl/source

Thorsten Behrens (via logerrit) logerrit at kemper.freedesktop.org
Mon Dec 7 12:34:10 UTC 2020


 include/vcl/tabpage.hxx                  |   25 +++++
 toolkit/source/awt/vclxcontainer.cxx     |   16 ++-
 toolkit/source/awt/vclxtoolkit.cxx       |    3 
 toolkit/source/controls/tabpagemodel.cxx |    6 +
 vcl/source/window/tabpage.cxx            |  130 +++++++++++++++++++++++++++++++
 5 files changed, 174 insertions(+), 6 deletions(-)

New commits:
commit 9baad0c1620e924a6dd34d2de8e35ae2cb94f787
Author:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
AuthorDate: Fri Oct 2 23:38:46 2020 +0200
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Mon Dec 7 13:33:34 2020 +0100

    Permit scrollable AWT tab pages a la scrolled Dialog
    
    UNO dialogs since LibreOffice 4.0 permitted setting HScroll /
    VScroll properties to enable scrolling for too large a content.
    Conceptually clone this code over to TabPage as well, and register
    necessary UNO properties in the toolkit UNO wrappers.
    
    Add missing API documentation also to UnoControlDialogModel,
    plus the new properties to the UnoControlTabPageModel.
    
    Change-Id: Iff90f60d0152ca21e4fe61c31315b9e1feab0dea
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103999
    Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104714

diff --git a/include/vcl/tabpage.hxx b/include/vcl/tabpage.hxx
index 3845da4fffed..9e93de8f37a1 100644
--- a/include/vcl/tabpage.hxx
+++ b/include/vcl/tabpage.hxx
@@ -26,6 +26,8 @@
 #include <vcl/window.hxx>
 #include <vcl/IContext.hxx>
 
+class ScrollBar;
+class ScrollBarBox;
 
 class VCL_DLLPUBLIC TabPage
     : public vcl::Window
@@ -36,6 +38,19 @@ private:
     using Window::ImplInit;
     SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
     SAL_DLLPRIVATE void ImplInitSettings();
+    void    lcl_Scroll( long nX, long nY );
+    DECL_LINK( ScrollBarHdl, ScrollBar*, void );
+
+    VclPtr<ScrollBar>    m_pVScroll;
+    VclPtr<ScrollBar>    m_pHScroll;
+    VclPtr<ScrollBarBox> m_aScrollBarBox;
+    Size                 maScrollArea;
+    bool                 mbHasHoriBar;
+    bool                 mbHasVertBar;
+    Point                mnScrollPos;
+    long                 mnScrWidth;
+    enum ScrollBarVisibility { None, Vert, Hori, Both };
+    ScrollBarVisibility  maScrollVis;
 
 public:
     explicit        TabPage( vcl::Window* pParent, WinBits nStyle = 0 );
@@ -57,6 +72,16 @@ public:
     virtual void    SetPosPixel(const Point& rNewPos) override;
     virtual void    SetSizePixel(const Size& rNewSize) override;
     virtual Size    GetOptimalSize() const override;
+
+    // for scrollable tabpage
+    virtual void Resize() override;
+
+    void    SetScrollWidth( long nWidth );
+    void    SetScrollHeight( long nHeight );
+    void    SetScrollLeft( long nLeft );
+    void    SetScrollTop( long Top );
+    void    setScrollVisibility( ScrollBarVisibility rState );
+    void    ResetScrollBars();
 };
 
 #endif // INCLUDED_VCL_TABPAGE_HXX
diff --git a/toolkit/source/awt/vclxcontainer.cxx b/toolkit/source/awt/vclxcontainer.cxx
index 27be3f5e6c98..727c8d6bfa15 100644
--- a/toolkit/source/awt/vclxcontainer.cxx
+++ b/toolkit/source/awt/vclxcontainer.cxx
@@ -26,6 +26,7 @@
 
 #include <vcl/svapp.hxx>
 #include <vcl/window.hxx>
+#include <vcl/tabpage.hxx>
 #include <tools/debug.hxx>
 #include <toolkit/awt/scrollabledialog.hxx>
 #include <toolkit/helper/property.hxx>
@@ -245,7 +246,8 @@ void SAL_CALL VCLXContainer::setProperty(
             VclPtr<vcl::Window> pWindow = GetWindow();
             MapMode aMode( MapUnit::MapAppFont );
             toolkit::ScrollableDialog* pScrollable = dynamic_cast< toolkit::ScrollableDialog* >( pWindow.get() );
-            if ( pWindow && pScrollable )
+            TabPage* pScrollTabPage = dynamic_cast< TabPage* >( pWindow.get() );
+            if ( pWindow && (pScrollable || pScrollTabPage) )
             {
                 OutputDevice* pDev = VCLUnoHelper::GetOutputDevice( getGraphics() );
                 if ( !pDev )
@@ -259,16 +261,20 @@ void SAL_CALL VCLXContainer::setProperty(
                 switch ( nPropType )
                 {
                     case BASEPROPERTY_SCROLLHEIGHT:
-                        pScrollable->SetScrollHeight( aSize.Height() );
+                        pScrollable ? pScrollable->SetScrollHeight( aSize.Height() ) : (void)0;
+                        pScrollTabPage ? pScrollTabPage->SetScrollHeight( aSize.Height() ) : (void)0;
                         break;
                     case BASEPROPERTY_SCROLLWIDTH:
-                        pScrollable->SetScrollWidth( aSize.Width() );
+                        pScrollable ? pScrollable->SetScrollWidth( aSize.Width() ) : (void)0;
+                        pScrollTabPage ? pScrollTabPage->SetScrollWidth( aSize.Width() ) : (void)0;
                         break;
                     case BASEPROPERTY_SCROLLTOP:
-                        pScrollable->SetScrollTop( aSize.Height() );
+                        pScrollable ? pScrollable->SetScrollTop( aSize.Height() ) : (void)0;
+                        pScrollTabPage ? pScrollTabPage->SetScrollTop( aSize.Height() ) : (void)0;
                         break;
                     case BASEPROPERTY_SCROLLLEFT:
-                        pScrollable->SetScrollLeft( aSize.Width() );
+                        pScrollable ? pScrollable->SetScrollLeft( aSize.Width() ) : (void)0;
+                        pScrollTabPage ? pScrollTabPage->SetScrollLeft( aSize.Width() ) : (void)0;
                         break;
                     default:
                         break;
diff --git a/toolkit/source/awt/vclxtoolkit.cxx b/toolkit/source/awt/vclxtoolkit.cxx
index 2eb26ff41a94..479b7500d5c0 100644
--- a/toolkit/source/awt/vclxtoolkit.cxx
+++ b/toolkit/source/awt/vclxtoolkit.cxx
@@ -658,7 +658,8 @@ std::pair<WinBits,MessBoxStyle> ImplGetWinBits( sal_uInt32 nComponentAttribs, Wi
         if( nComponentAttribs & css::awt::VclWindowPeerAttribute::DEF_NO )
             nStyle |= MessBoxStyle::DefaultNo;
     }
-    if ( nCompType == WindowType::MULTILINEEDIT || nCompType == WindowType::DIALOG || nCompType == WindowType::GROUPBOX )
+    if ( nCompType == WindowType::MULTILINEEDIT || nCompType == WindowType::DIALOG
+         || nCompType == WindowType::GROUPBOX || nCompType == WindowType::TABPAGE )
     {
         if( nComponentAttribs & css::awt::VclWindowPeerAttribute::AUTOHSCROLL )
             nWinBits |= WB_AUTOHSCROLL;
diff --git a/toolkit/source/controls/tabpagemodel.cxx b/toolkit/source/controls/tabpagemodel.cxx
index 5ddbe3d0f8ef..c40b61ccb129 100644
--- a/toolkit/source/controls/tabpagemodel.cxx
+++ b/toolkit/source/controls/tabpagemodel.cxx
@@ -56,6 +56,12 @@ UnoControlTabPageModel::UnoControlTabPageModel( Reference< XComponentContext > c
     ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
     ImplRegisterProperty( BASEPROPERTY_HELPURL );
     ImplRegisterProperty( BASEPROPERTY_USERFORMCONTAINEES );
+    ImplRegisterProperty( BASEPROPERTY_HSCROLL );
+    ImplRegisterProperty( BASEPROPERTY_VSCROLL );
+    ImplRegisterProperty( BASEPROPERTY_SCROLLWIDTH );
+    ImplRegisterProperty( BASEPROPERTY_SCROLLHEIGHT );
+    ImplRegisterProperty( BASEPROPERTY_SCROLLTOP );
+    ImplRegisterProperty( BASEPROPERTY_SCROLLLEFT );
 }
 
 OUString SAL_CALL UnoControlTabPageModel::getImplementationName()
diff --git a/vcl/source/window/tabpage.cxx b/vcl/source/window/tabpage.cxx
index a9d44ffa20e1..dc714847bdbd 100644
--- a/vcl/source/window/tabpage.cxx
+++ b/vcl/source/window/tabpage.cxx
@@ -24,6 +24,7 @@
 #include <vcl/tabctrl.hxx>
 #include <vcl/bitmapex.hxx>
 #include <vcl/settings.hxx>
+#include <vcl/scrbar.hxx>
 
 #include <svdata.hxx>
 
@@ -38,6 +39,34 @@ void TabPage::ImplInit( vcl::Window* pParent, WinBits nStyle )
 
     ImplInitSettings();
 
+    m_pVScroll.set(VclPtr<ScrollBar>::Create(this, ((nStyle & WB_VSCROLL) ? WB_HIDE : 0) | WB_VSCROLL | WB_DRAG));
+    m_pHScroll.set(VclPtr<ScrollBar>::Create(this, ((nStyle & WB_HSCROLL) ? WB_HIDE : 0) | WB_HSCROLL | WB_DRAG));
+    m_aScrollBarBox.set(
+        VclPtr<ScrollBarBox>::Create(this,
+                                     ((nStyle & (WB_VSCROLL|WB_HSCROLL)) ? WB_HIDE : 0)));
+    mbHasHoriBar = false;
+    mbHasVertBar = false;
+    ScrollBarVisibility aVis = None;
+
+    if ( nStyle & ( WB_AUTOHSCROLL | WB_AUTOVSCROLL ) )
+    {
+        if ( nStyle & WB_AUTOHSCROLL )
+            aVis = Hori;
+        if ( nStyle &  WB_AUTOVSCROLL )
+        {
+            if ( aVis == Hori )
+                aVis = Both;
+            else
+                aVis = Vert;
+        }
+    }
+    setScrollVisibility( aVis );
+    mnScrWidth = Application::GetSettings().GetStyleSettings().GetScrollBarSize();
+
+    Link<ScrollBar*,void> aLink( LINK( this, TabPage, ScrollBarHdl ) );
+    m_pVScroll->SetScrollHdl(aLink);
+    m_pHScroll->SetScrollHdl(aLink);
+
     // if the tabpage is drawn (ie filled) by a native widget, make sure all controls will have transparent background
     // otherwise they will paint with a wrong background
     if( IsNativeControlSupported(ControlType::TabBody, ControlPart::Entire) && GetParent() && (GetParent()->GetType() == WindowType::TABCONTROL) )
@@ -93,6 +122,9 @@ TabPage::~TabPage()
 void TabPage::dispose()
 {
     disposeBuilder();
+    m_pVScroll.disposeAndClear();
+    m_pHScroll.disposeAndClear();
+    m_aScrollBarBox.disposeAndClear();
     vcl::Window::dispose();
 }
 
@@ -212,4 +244,102 @@ void TabPage::SetPosPixel(const Point& rAllocPos)
     }
 }
 
+void TabPage::setScrollVisibility( ScrollBarVisibility rVisState )
+{
+    maScrollVis = rVisState;
+    if (  maScrollVis == Hori || maScrollVis == Both )
+    {
+        mbHasHoriBar = true;
+        m_pHScroll->Show();
+    }
+    if ( maScrollVis == Vert || maScrollVis == Both )
+    {
+        mbHasVertBar = true;
+        m_pVScroll->Show();
+    }
+    if ( mbHasHoriBar || mbHasVertBar )
+        SetStyle( GetStyle() | WB_CLIPCHILDREN );
+}
+
+void TabPage::lcl_Scroll( long nX, long nY )
+{
+    long nXScroll = mnScrollPos.X() - nX;
+    long nYScroll = mnScrollPos.Y() - nY;
+    mnScrollPos = Point( nX, nY );
+
+    tools::Rectangle aScrollableArea( 0, 0, maScrollArea.Width(), maScrollArea.Height() );
+    Scroll(nXScroll, nYScroll, aScrollableArea );
+    // Manually scroll all children ( except the scrollbars )
+    for ( int index = 0; index < GetChildCount(); ++index )
+    {
+        vcl::Window* pChild = GetChild( index );
+        if ( pChild && pChild != m_pVScroll.get() && pChild != m_pHScroll.get() )
+        {
+            Point aPos = pChild->GetPosPixel();
+            aPos += Point( nXScroll, nYScroll );
+            pChild->SetPosPixel( aPos );
+        }
+    }
+}
+
+IMPL_LINK( TabPage, ScrollBarHdl, ScrollBar*, pSB, void )
+{
+    sal_uInt16 nPos = static_cast<sal_uInt16>(pSB->GetThumbPos());
+    if( pSB == m_pVScroll.get() )
+        lcl_Scroll(mnScrollPos.X(), nPos );
+    else if( pSB == m_pHScroll.get() )
+        lcl_Scroll(nPos, mnScrollPos.Y() );
+}
+
+void TabPage::SetScrollTop( long nTop )
+{
+    Point aOld = mnScrollPos;
+    lcl_Scroll( mnScrollPos.X() , mnScrollPos.Y() - nTop );
+    m_pHScroll->SetThumbPos( 0 );
+    // new pos is 0,0
+    mnScrollPos = aOld;
+}
+void TabPage::SetScrollLeft( long nLeft )
+{
+    Point aOld = mnScrollPos;
+    lcl_Scroll( mnScrollPos.X() - nLeft , mnScrollPos.Y() );
+    m_pVScroll->SetThumbPos( 0 );
+    // new pos is 0,0
+    mnScrollPos = aOld;
+}
+
+void TabPage::SetScrollWidth( long nWidth )
+{
+    maScrollArea.setWidth( nWidth );
+    ResetScrollBars();
+}
+
+void TabPage::SetScrollHeight( long nHeight )
+{
+    maScrollArea.setHeight( nHeight );
+    ResetScrollBars();
+}
+
+void TabPage::Resize()
+{
+    ResetScrollBars();
+}
+
+void TabPage::ResetScrollBars()
+{
+    Size aOutSz = GetOutputSizePixel();
+
+    Point aVPos( aOutSz.Width() - mnScrWidth, 0 );
+    Point aHPos( 0, aOutSz.Height() - mnScrWidth );
+
+    m_pVScroll->SetPosSizePixel( aVPos, Size( mnScrWidth,  GetSizePixel().Height() - mnScrWidth ) );
+    m_pHScroll->SetPosSizePixel( aHPos, Size(  GetSizePixel().Width() - mnScrWidth, mnScrWidth ) );
+
+    m_pHScroll->SetRangeMax( maScrollArea.Width() + mnScrWidth  );
+    m_pHScroll->SetVisibleSize( GetSizePixel().Width() );
+
+    m_pVScroll->SetRangeMax( maScrollArea.Height() + mnScrWidth );
+    m_pVScroll->SetVisibleSize( GetSizePixel().Height() );
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list