diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-10-08 12:33:41 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-10-24 13:04:21 +0200 |
commit | faa4ebb2cdc99505e9be7e1cbed83b19acfd3c4a (patch) | |
tree | 0d6ee926ac5cc5b12262ecc9f47e2e40cc5d3e8d | |
parent | 808da2c918e662c19618c9f4035e8c9a802bb887 (diff) |
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@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | include/vcl/status.hxx | 3 | ||||
-rw-r--r-- | svx/source/stbctrls/pszctrl.cxx | 6 | ||||
-rw-r--r-- | vcl/source/window/status.cxx | 25 |
3 files changed, 25 insertions, 9 deletions
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 )) |