From ade49eb1b9f99595f4c8864e7c13acebf9fac030 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Wed, 14 Dec 2022 16:25:25 +0000 Subject: Resolves: tdf#92051 add tooltips to section/table statusbar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I649eabbe266085fdbc0ca9c4a5506c0c2a270721 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144199 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- svx/Library_svx.mk | 1 + svx/sdi/svx.sdi | 2 +- svx/source/items/statusitem.cxx | 134 ++++++++++++++++++++++++++++++++++++++++ svx/source/stbctrls/pszctrl.cxx | 43 +++++++++++++ 4 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 svx/source/items/statusitem.cxx (limited to 'svx') diff --git a/svx/Library_svx.mk b/svx/Library_svx.mk index 092a4613f374..29f8d16454c7 100644 --- a/svx/Library_svx.mk +++ b/svx/Library_svx.mk @@ -200,6 +200,7 @@ $(eval $(call gb_Library_add_exception_objects,svx,\ svx/source/items/postattr \ svx/source/items/rotmodit \ svx/source/items/SmartTagItem \ + svx/source/items/statusitem \ svx/source/items/svxerr \ svx/source/items/viewlayoutitem \ svx/source/items/zoomslideritem \ diff --git a/svx/sdi/svx.sdi b/svx/sdi/svx.sdi index bc1d9e5c429f..d1f02f5b1d3b 100644 --- a/svx/sdi/svx.sdi +++ b/svx/sdi/svx.sdi @@ -10378,7 +10378,7 @@ SfxVoidItem DecrementIndent SID_DEC_INDENT ] -SfxStringItem StateTableCell SID_TABLE_CELL +SvxStatusItem StateTableCell SID_TABLE_CELL [ AutoUpdate = FALSE, diff --git a/svx/source/items/statusitem.cxx b/svx/source/items/statusitem.cxx new file mode 100644 index 000000000000..3b326f39ebe0 --- /dev/null +++ b/svx/source/items/statusitem.cxx @@ -0,0 +1,134 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#include +#include +#include +#include +#include + +constexpr OUStringLiteral STATUS_PARAM_VALUE = u"Value"; +constexpr OUStringLiteral STATUS_PARAM_TYPE = u"Type"; +constexpr int STATUS_PARAMS = 2; + +SvxStatusItem::SvxStatusItem(TypedWhichId nWhich, const OUString& rString, + StatusCategory eCategory) + : SfxStringItem(nWhich, rString) + , m_eCategory(eCategory) +{ +} + +bool SvxStatusItem::operator==(const SfxPoolItem& rItem) const +{ + return SfxStringItem::operator==(rItem) + && static_cast(rItem).m_eCategory == m_eCategory; +} + +bool SvxStatusItem::QueryValue(css::uno::Any& rVal, sal_uInt8 nMemberId) const +{ + nMemberId &= ~CONVERT_TWIPS; + + switch (nMemberId) + { + case 0: + { + css::uno::Sequence aSeq{ + comphelper::makePropertyValue(STATUS_PARAM_VALUE, GetValue()), + comphelper::makePropertyValue(STATUS_PARAM_TYPE, + static_cast(m_eCategory)) + }; + assert(aSeq.getLength() == STATUS_PARAMS); + rVal <<= aSeq; + break; + } + case MID_VALUE: + rVal <<= GetValue(); + break; + case MID_TYPE: + rVal <<= static_cast(m_eCategory); + break; + default: + return false; + } + + return true; +} + +bool SvxStatusItem::PutValue(const css::uno::Any& rVal, sal_uInt8 nMemberId) +{ + nMemberId &= ~CONVERT_TWIPS; + bool bRet; + switch (nMemberId) + { + case 0: + { + css::uno::Sequence aSeq; + if ((rVal >>= aSeq) && (aSeq.getLength() == STATUS_PARAMS)) + { + OUString sValueTmp; + sal_Int16 nTypeTmp(0); + bool bAllConverted(true); + sal_Int16 nConvertedCount(0); + for (const auto& rProp : std::as_const(aSeq)) + { + if (rProp.Name == STATUS_PARAM_VALUE) + { + bAllConverted &= (rProp.Value >>= sValueTmp); + ++nConvertedCount; + } + else if (rProp.Name == STATUS_PARAM_TYPE) + { + bAllConverted &= (rProp.Value >>= nTypeTmp); + ++nConvertedCount; + } + } + + if (bAllConverted && nConvertedCount == STATUS_PARAMS) + { + SetValue(sValueTmp); + m_eCategory = static_cast(nTypeTmp); + return true; + } + } + return false; + } + case MID_TYPE: + { + sal_Int16 nCategory; + bRet = (rVal >>= nCategory); + if (bRet) + m_eCategory = static_cast(nCategory); + break; + } + case MID_VALUE: + { + OUString aStr; + bRet = (rVal >>= aStr); + if (bRet) + SetValue(aStr); + break; + } + default: + return false; + } + + return bRet; +} + +SvxStatusItem* SvxStatusItem::Clone(SfxItemPool* /*pPool*/) const +{ + return new SvxStatusItem(*this); +} + +SfxPoolItem* SvxStatusItem::CreateDefault() +{ + return new SvxStatusItem(TypedWhichId(0), OUString(), StatusCategory::NONE); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/svx/source/stbctrls/pszctrl.cxx b/svx/source/stbctrls/pszctrl.cxx index 5eddc1981727..cd103e258600 100644 --- a/svx/source/stbctrls/pszctrl.cxx +++ b/svx/source/stbctrls/pszctrl.cxx @@ -32,6 +32,9 @@ #include #include #include +#include +#include +#include #include #include @@ -321,8 +324,48 @@ void SvxPosSizeStatusBarControl::StateChangedAtStatusBarControl( sal_uInt16 nSID pImpl->bSize = true; pImpl->bTable = false; } + else if ( auto pStatusItem = dynamic_cast( pState) ) + { + // show string (table cell or different) + pImpl->aStr = pStatusItem->GetValue(); + pImpl->bTable = true; + pImpl->bPos = false; + pImpl->bSize = false; + if (!pImpl->aStr.isEmpty()) + { + OUString sTip; + switch (pStatusItem->GetCategory()) + { + case StatusCategory::TableCell: + sTip = SvxResId(RID_SVXSTR_TABLECELL_HINT); + break; + case StatusCategory::Section: + sTip = SvxResId(RID_SVXSTR_SECTION_HINT); + break; + case StatusCategory::TableOfContents: + sTip = SvxResId(RID_SVXSTR_TOC_HINT); + break; + case StatusCategory::Numbering: + sTip = SvxResId(RID_SVXSTR_NUMBERING_HINT); + break; + case StatusCategory::ListStyle: + sTip = SvxResId(RID_SVXSTR_LIST_STYLE_HINT); + break; + case StatusCategory::Formula: + sTip = SvxResId(RID_SVXSTR_FORMULA_HINT); + break; + case StatusCategory::RowColumn: + sTip = SvxResId(RID_SVXSTR_ROW_COLUMN_HINT); + break; + case StatusCategory::NONE: + break; + } + GetStatusBar().SetQuickHelpText(GetId(), sTip); + } + } else if ( auto pStringItem = dynamic_cast( pState) ) { + SAL_WARN( "svx.stbcrtls", "this should be a SvxStatusItem not a SfxStringItem" ); // show string (table cell or different) pImpl->aStr = pStringItem->GetValue(); pImpl->bTable = true; -- cgit