From b8bbe9a3ca4758102ce6aa5d1e0fbb077eedbe64 Mon Sep 17 00:00:00 2001 From: Jim Raykowski Date: Mon, 18 Nov 2019 19:43:29 -0900 Subject: tdf#128557 Add tooltips to styles lists Change-Id: Ia8f00cd882c1c8c239b95de8e917ff317a6485e8 Reviewed-on: https://gerrit.libreoffice.org/83152 Tested-by: Jenkins Reviewed-by: Jim Raykowski --- include/sfx2/strings.hrc | 2 ++ include/svl/style.hxx | 2 ++ sfx2/source/dialog/templdlg.cxx | 47 +++++++++++++++++++++++++++++++++++++++ sfx2/source/inc/templdgi.hxx | 1 + sw/inc/docstyle.hxx | 2 ++ sw/inc/numrule.hxx | 1 + sw/source/core/doc/number.cxx | 12 ++++++++++ sw/source/uibase/app/docstyle.cxx | 5 +++++ 8 files changed, 72 insertions(+) diff --git a/include/sfx2/strings.hrc b/include/sfx2/strings.hrc index d1196842d36c..52d24f048671 100644 --- a/include/sfx2/strings.hrc +++ b/include/sfx2/strings.hrc @@ -350,6 +350,8 @@ #define STR_CTRLCLICKHYPERLINK NC_("STR_CTRLCLICKHYPERLINK", "%{key}-click to open hyperlink: %{link}") #define STR_CLICKHYPERLINK NC_("STR_CLICKHYPERLINK", "Click to open hyperlink: %{link}") + +#define STR_STYLEUSEDBY NC_("STR_STYLEUSEDBY", "(used by: %STYLELIST)") #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/svl/style.hxx b/include/svl/style.hxx index 9ac7151f48d8..24656eb2318a 100644 --- a/include/svl/style.hxx +++ b/include/svl/style.hxx @@ -157,6 +157,8 @@ public: virtual bool IsUsed() const; // Default true virtual OUString GetDescription( MapUnit eMetric ); + virtual OUString GetUsedBy() { return OUString(); } + SfxStyleSheetBasePool* GetPool() { return m_pPool; } SfxStyleFamily GetFamily() const { return nFamily; } SfxStyleSearchBits GetMask() const { return nMask; } diff --git a/sfx2/source/dialog/templdlg.cxx b/sfx2/source/dialog/templdlg.cxx index 937c241008d9..8ebb054a2a8d 100644 --- a/sfx2/source/dialog/templdlg.cxx +++ b/sfx2/source/dialog/templdlg.cxx @@ -314,6 +314,53 @@ bool DropListBox_Impl::EventNotify( NotifyEvent& rNEvt ) return bRet; } +void DropListBox_Impl::RequestHelp(const HelpEvent& rHEvt) +{ + if (rHEvt.GetMode() & HelpEventMode::QUICK) + { + Point aPos(ScreenToOutputPixel(rHEvt.GetMousePosPixel())); + SvTreeListEntry* pEntry = GetEntry(aPos); + if (pEntry) + { + const OUString aTemplName(GetEntryText(pEntry)); + OUString sQuickHelpText(aTemplName); + + const SfxStyleFamilyItem* pItem = pDialog->GetFamilyItem_Impl(); + SfxStyleSheetBase* pStyle = pDialog->pStyleSheetPool->Find(aTemplName, pItem->GetFamily()); + + if (pStyle && pStyle->IsUsed()) // pStyle is in use in the document? + { + OUString sUsedBy; + if (pStyle->GetFamily() == SfxStyleFamily::Pseudo) + { + sUsedBy = pStyle->GetUsedBy(); + } + + if (!sUsedBy.isEmpty()) + { + const sal_Int32 nMaxLen = 80; + if (sUsedBy.getLength() > nMaxLen) + { + sUsedBy = sUsedBy.copy(0, nMaxLen) + "..."; + } + + OUString aMessage = SfxResId(STR_STYLEUSEDBY); + aMessage = aMessage.replaceFirst("%STYLELIST", sUsedBy); + sQuickHelpText = aTemplName + " " + aMessage; + } + } + + Size aSize(GetOutputSizePixel().Width(), GetEntryHeight()); + tools::Rectangle aScreenRect(OutputToScreenPixel(GetEntryPosition(pEntry)), aSize); + + Help::ShowQuickHelp(this, aScreenRect, + sQuickHelpText, QuickHelpFlags::Left | QuickHelpFlags::VCenter); + return; + } + } + SvTreeListBox::RequestHelp(rHEvt); +} + /** ListBox class that starts a PopupMenu (designer specific) in the command handler. */ diff --git a/sfx2/source/inc/templdgi.hxx b/sfx2/source/inc/templdgi.hxx index 9ab64b0262a7..1981bb25101b 100644 --- a/sfx2/source/inc/templdgi.hxx +++ b/sfx2/source/inc/templdgi.hxx @@ -83,6 +83,7 @@ public: } virtual bool EventNotify( NotifyEvent& rNEvt ) override; + virtual void RequestHelp(const HelpEvent& rHEvt) override; }; diff --git a/sw/inc/docstyle.hxx b/sw/inc/docstyle.hxx index 609cee5c9426..d3160b6e54a7 100644 --- a/sw/inc/docstyle.hxx +++ b/sw/inc/docstyle.hxx @@ -127,6 +127,8 @@ public: virtual bool HasClearParentSupport() const override; virtual OUString GetDescription(MapUnit eUnit) override; + virtual OUString GetUsedBy() override; + SwCharFormat* GetCharFormat(); SwTextFormatColl* GetCollection(); SwFrameFormat* GetFrameFormat(); diff --git a/sw/inc/numrule.hxx b/sw/inc/numrule.hxx index 3702ce2b71bd..6152e6bee99f 100644 --- a/sw/inc/numrule.hxx +++ b/sw/inc/numrule.hxx @@ -172,6 +172,7 @@ public: OUString MakeRefNumString( const SwNodeNum& rNodeNum, const bool bInclSuperiorNumLabels, const int nRestrictInclToThisLevel ) const; + OUString MakeParagraphStyleListString() const; /** @return list of associated text nodes */ void GetTextNodeList( SwNumRule::tTextNodeList& rTextNodeList ) const; diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx index e1a5af928d68..f57933440278 100644 --- a/sw/source/core/doc/number.cxx +++ b/sw/source/core/doc/number.cxx @@ -795,6 +795,18 @@ OUString SwNumRule::MakeRefNumString( const SwNodeNum& rNodeNum, return aRefNumStr; } +OUString SwNumRule::MakeParagraphStyleListString() const +{ + OUString aParagraphStyleListString; + for (const auto& rParagraphStyle : maParagraphStyleList) + { + if (!aParagraphStyleListString.isEmpty()) + aParagraphStyleListString += ", "; + aParagraphStyleListString += rParagraphStyle->GetName(); + } + return aParagraphStyleListString; +} + /** Copy method of SwNumRule A kind of copy constructor, so that the num formats are attached to the diff --git a/sw/source/uibase/app/docstyle.cxx b/sw/source/uibase/app/docstyle.cxx index fae87682edf0..4326445cd8ec 100644 --- a/sw/source/uibase/app/docstyle.cxx +++ b/sw/source/uibase/app/docstyle.cxx @@ -2259,6 +2259,11 @@ bool SwDocStyleSheet::IsUsed() const return rDoc.IsUsed( *pMod ); } +OUString SwDocStyleSheet::GetUsedBy() +{ + return pNumRule ? pNumRule->MakeParagraphStyleListString() : OUString(); +} + sal_uLong SwDocStyleSheet::GetHelpId( OUString& rFile ) { sal_uInt16 nId = 0; -- cgit v1.2.3