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 e63d60c90d465ea6d9177bb82c25a35185a05a6e Author: Noel Grandin <[email protected]> AuthorDate: Tue Oct 8 12:33:41 2019 +0200 Commit: Xisco FaulĂ <[email protected]> CommitDate: Thu Oct 24 16:43:35 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Ă <[email protected]> Reviewed-by: Noel Grandin <[email protected]> (cherry picked from commit faa4ebb2cdc99505e9be7e1cbed83b19acfd3c4a) Reviewed-on: https://gerrit.libreoffice.org/81449 Reviewed-by: Adolfo Jayme Barrientos <[email protected]> Tested-by: Noel Grandin <[email protected]> Tested-by: Jenkins diff --git a/include/vcl/status.hxx b/include/vcl/status.hxx index c89b5064ff81..7e35033a4e5e 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 06877c8f06e4..54639a890433 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 f966bc7f71a3..4e6c15c8b8b0 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> @@ -1127,7 +1128,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 ); @@ -1142,12 +1143,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 )) _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
