diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-02-11 16:37:00 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-02-11 18:50:08 +0100 |
commit | b11db88d0174fbad25f7ee04726ae27ceb1488c3 (patch) | |
tree | 42166c5bfa038246b796d478c21f83eea4e4cb4f /sw/qa | |
parent | 8180bdc75c2bf3c1f813469eabd38db0612f1c91 (diff) |
sw tooltip on bibliography fields: add the actual tooltip functionality
- Similar to e.g. SwMacroField::GetMacro(), add a new
SwAuthorityField::GetAuthority() that returns a string which is similar
to the one-liner text node in the bibliography table for a given
bibliography reference.
- Base this on the recently added
SwAuthorityFieldType::CreateTOXInternational() and
SwTOXAuthority::GetText() to share code with
sw::ToxTextGenerator::GenerateText() and SwTOXBaseSection::Update().
- Finally extend SwEditWin::RequestHelp() to actually provide the
tooltip on mouse hover.
Change-Id: I33a58076c6d141566298259e7e4681541fac1055
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110765
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/qa')
-rw-r--r-- | sw/qa/core/fields/fields.cxx | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/sw/qa/core/fields/fields.cxx b/sw/qa/core/fields/fields.cxx new file mode 100644 index 000000000000..8d82344a24af --- /dev/null +++ b/sw/qa/core/fields/fields.cxx @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 <swmodeltestbase.hxx> + +#include <com/sun/star/style/PageStyleLayout.hpp> + +#include <comphelper/propertyvalue.hxx> +#include <svx/svdpage.hxx> +#include <vcl/gdimtf.hxx> + +#include <IDocumentDrawModelAccess.hxx> +#include <IDocumentLayoutAccess.hxx> +#include <IDocumentState.hxx> +#include <authfld.hxx> +#include <docsh.hxx> +#include <drawdoc.hxx> +#include <rootfrm.hxx> +#include <unotxdoc.hxx> +#include <wrtsh.hxx> +#include <ndtxt.hxx> + +namespace +{ +/// Covers sw/source/core/fields/ fixes. +class Test : public SwModelTestBase +{ +}; + +CPPUNIT_TEST_FIXTURE(Test, testAuthorityTooltip) +{ + // Create a document with a bibliography reference in it. + SwDoc* pDoc = createSwDoc(); + uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xField( + xFactory->createInstance("com.sun.star.text.TextField.Bibliography"), uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aFields = { + comphelper::makePropertyValue("Identifier", OUString("ARJ00")), + comphelper::makePropertyValue("Author", OUString("Ar, J")), + comphelper::makePropertyValue("Title", OUString("mytitle")), + comphelper::makePropertyValue("Year", OUString("2020")), + }; + xField->setPropertyValue("Fields", uno::makeAny(aFields)); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + uno::Reference<text::XTextContent> xContent(xField, uno::UNO_QUERY); + xText->insertTextContent(xCursor, xContent, /*bAbsorb=*/false); + + // Get the tooltip of the field. + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false); + SwPaM* pCursor = pWrtShell->GetCursor(); + auto pField = dynamic_cast<SwAuthorityField*>( + SwCursorShell::GetFieldAtCursor(pCursor, /*bIncludeInputFieldAtStart=*/true)); + CPPUNIT_ASSERT(pField); + SwTextNode* pTextNode = pCursor->GetNode().GetTextNode(); + const SwTextAttr* pTextAttr = pTextNode->GetSwpHints().Get(0); + const SwRootFrame* pLayout = pWrtShell->GetLayout(); + OUString aTooltip = pField->GetAuthority(pTextAttr, pLayout); + + // Without the accompanying fix in place, generating this tooltip text was not possible without + // first inserting an empty bibliography table into the document. + CPPUNIT_ASSERT_EQUAL(OUString("ARJ00: Ar, J, mytitle, 2020"), aTooltip); +} +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |