[Libreoffice-commits] core.git: include/vcl svx/source vcl/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Thu Oct 24 11:06:00 UTC 2019


 include/vcl/status.hxx          |    3 ++-
 svx/source/stbctrls/pszctrl.cxx |    6 +++++-
 vcl/source/window/status.cxx    |   25 ++++++++++++++++++-------
 3 files changed, 25 insertions(+), 9 deletions(-)

New commits:
commit faa4ebb2cdc99505e9be7e1cbed83b19acfd3c4a
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Oct 8 12:33:41 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Oct 24 13:04:21 2019 +0200

    tdf#127411 improve sizing of status items in the status bar
    
    Change-Id: I6ea3fbb893d0141010ee1abd1720d6cdad97b528
    Reviewed-on: https://gerrit.libreoffice.org/80440
    Tested-by: Xisco FaulĂ­ <xiscofauli at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/vcl/status.hxx b/include/vcl/status.hxx
index fe6ec34e41a4..79497a448014 100644
--- a/include/vcl/status.hxx
+++ b/include/vcl/status.hxx
@@ -149,7 +149,8 @@ public:
 
     long                GetItemOffset( sal_uInt16 nItemId ) const;
 
-    void                SetItemText( sal_uInt16 nItemId, const OUString& rText );
+    /// @param nCharsWidth, if not -1, overrides the normal width calculation
+    void                SetItemText( sal_uInt16 nItemId, const OUString& rText, int nCharsWidth = -1 );
     const OUString&     GetItemText( sal_uInt16 nItemId ) const;
 
     void                SetItemData( sal_uInt16 nItemId, void* pNewData );
diff --git a/svx/source/stbctrls/pszctrl.cxx b/svx/source/stbctrls/pszctrl.cxx
index ddb66bd5253a..084d251c91dd 100644
--- a/svx/source/stbctrls/pszctrl.cxx
+++ b/svx/source/stbctrls/pszctrl.cxx
@@ -462,22 +462,26 @@ void SvxPosSizeStatusBarControl::ImplUpdateItemText()
     //  set only strings as text at the statusBar, so that the Help-Tips
     //  can work with the text, when it is too long for the statusBar
     OUString aText;
+    int nCharsWidth = -1;
     if ( pImpl->bPos || pImpl->bSize )
     {
         aText = GetMetricStr_Impl( pImpl->aPos.X());
         aText += " / ";
         aText += GetMetricStr_Impl( pImpl->aPos.Y());
+        // widest X/Y string looks like "-999,99"
+        nCharsWidth = 1 + 6 + 3 + 6; // icon + x + slash + y
         if ( pImpl->bSize )
         {
             aText += " ";
             aText += GetMetricStr_Impl( pImpl->aSize.Width() );
             aText += " x ";
             aText += GetMetricStr_Impl( pImpl->aSize.Height() );
+            nCharsWidth += 1 + 1 + 4 + 3 + 4; // icon + space + w + x + h
         }
     }
     else if ( pImpl->bTable )
        aText = pImpl->aStr;
 
-    GetStatusBar().SetItemText( GetId(), aText );
+    GetStatusBar().SetItemText( GetId(), aText, nCharsWidth );
 }
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/window/status.cxx b/vcl/source/window/status.cxx
index 03b9b41e62a2..92fb94d66587 100644
--- a/vcl/source/window/status.cxx
+++ b/vcl/source/window/status.cxx
@@ -19,6 +19,7 @@
 
 
 #include <sal/log.hxx>
+#include <comphelper/string.hxx>
 #include <vcl/event.hxx>
 #include <vcl/decoview.hxx>
 #include <vcl/svapp.hxx>
@@ -1126,7 +1127,7 @@ long StatusBar::GetItemOffset( sal_uInt16 nItemId ) const
     return 0;
 }
 
-void StatusBar::SetItemText( sal_uInt16 nItemId, const OUString& rText )
+void StatusBar::SetItemText( sal_uInt16 nItemId, const OUString& rText, int nCharsWidth )
 {
     sal_uInt16 nPos = GetItemPos( nItemId );
 
@@ -1141,12 +1142,22 @@ void StatusBar::SetItemText( sal_uInt16 nItemId, const OUString& rText )
             // adjust item width - see also DataChanged()
             long nFudge = GetTextHeight()/4;
 
-            std::unique_ptr<SalLayout> pSalLayout = ImplLayout(pItem->maText,0,-1);
-            const SalLayoutGlyphs* pGlyphs = pSalLayout ? pSalLayout->GetGlyphs() : nullptr;
-            long nWidth = GetTextWidth( pItem->maText,0,-1,nullptr,pGlyphs ) + nFudge;
-
-            // Store the calculated layout.
-            pItem->mxLayoutCache = std::move(pSalLayout);
+            long nWidth;
+            if (nCharsWidth != -1)
+            {
+                std::unique_ptr<SalLayout> pSalLayout = ImplLayout("0",0,-1);
+                const SalLayoutGlyphs* pGlyphs = pSalLayout ? pSalLayout->GetGlyphs() : nullptr;
+                nWidth = GetTextWidth("0",0,-1,nullptr,pGlyphs );
+                nWidth = nWidth * nCharsWidth + nFudge;
+            }
+            else
+            {
+                std::unique_ptr<SalLayout> pSalLayout = ImplLayout(pItem->maText,0,-1);
+                const SalLayoutGlyphs* pGlyphs = pSalLayout ? pSalLayout->GetGlyphs() : nullptr;
+                nWidth = GetTextWidth( pItem->maText,0,-1,nullptr,pGlyphs ) + nFudge;
+                // Store the calculated layout.
+                pItem->mxLayoutCache = std::move(pSalLayout);
+            }
 
             if( (nWidth > pItem->mnWidth + STATUSBAR_OFFSET) ||
                 ((nWidth < pItem->mnWidth) && (mnDX - STATUSBAR_OFFSET) < mnItemsWidth  ))


More information about the Libreoffice-commits mailing list