dev/null |binary include/LibreOfficeKit/LibreOfficeKitEnums.h | 1 libreofficekit/source/gtk/lokdocview.cxx | 34 +++++++++++++++++++++++++ sw/qa/extras/tiledrendering/tiledrendering.cxx | 17 +++++++++++- sw/source/core/crsr/viscrs.cxx | 5 +++ 5 files changed, 56 insertions(+), 1 deletion(-)
New commits: commit e368d26a7f24dc25f3d855511baabc128bc151e6 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Thu Oct 20 08:52:02 2022 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Oct 20 11:39:04 2022 +0200 sw content controls, alias: add LOK API And implement sample handling of it in lokdocview. Change-Id: Ia1975e4daef6260e2030e5d0dba8fb4293a9484f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141541 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h index 825d9791b806..3bc0ad940b18 100644 --- a/include/LibreOfficeKit/LibreOfficeKitEnums.h +++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h @@ -803,6 +803,7 @@ typedef enum * Entered a rich text content control: * { * "action": "show", + * "alias": "my alias", // omitted if empty * "rectangles": "1418, 1694, 720, 551; 10291, 1418, 1099, 275" * } * diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index 4c5dbdd9f595..eb06f2608520 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -127,6 +127,8 @@ struct LOKDocViewPrivateImpl std::vector<GdkRectangle> m_aTextSelectionRectangles; /// Rectangles of the current content control. std::vector<GdkRectangle> m_aContentControlRectangles; + /// Alias/title of the current content control. + std::string m_aContentControlAlias; /// Rectangles of view selections. The current view can only see /// them, can't modify them. Key is the view id. std::map<int, ViewRectangles> m_aTextViewSelectionRectangles; @@ -1406,10 +1408,21 @@ callback (gpointer pData) { auto aRectangles = aTree.get<std::string>("rectangles"); priv->m_aContentControlRectangles = payloadToRectangles(pDocView, aRectangles.c_str()); + + auto it = aTree.find("alias"); + if (it == aTree.not_found()) + { + priv->m_aContentControlAlias.clear(); + } + else + { + priv->m_aContentControlAlias = it->second.get_value<std::string>(); + } } else if (aAction == "hide") { priv->m_aContentControlRectangles.clear(); + priv->m_aContentControlAlias.clear(); } else if (aAction == "change-picture") { @@ -1872,6 +1885,27 @@ renderOverlay(LOKDocView* pDocView, cairo_t* pCairo) twipToPixel(rRectangle.height, priv->m_fZoom)); cairo_fill(pCairo); } + + if (!priv->m_aContentControlAlias.empty()) + { + cairo_text_extents_t aExtents; + cairo_text_extents(pCairo, priv->m_aContentControlAlias.c_str(), &aExtents); + // Blue with 75% transparency. + cairo_set_source_rgba(pCairo, 0, 0, 1, 0.25); + cairo_rectangle(pCairo, + twipToPixel(priv->m_aContentControlRectangles[0].x, priv->m_fZoom) + aExtents.x_bearing, + twipToPixel(priv->m_aContentControlRectangles[0].y, priv->m_fZoom) + aExtents.y_bearing, + aExtents.width, + aExtents.height); + cairo_fill(pCairo); + + cairo_move_to(pCairo, + twipToPixel(priv->m_aContentControlRectangles[0].x, priv->m_fZoom), + twipToPixel(priv->m_aContentControlRectangles[0].y, priv->m_fZoom)); + cairo_set_source_rgb(pCairo, 0, 0, 0); + cairo_show_text(pCairo, priv->m_aContentControlAlias.c_str()); + cairo_fill(pCairo); + } } // Selections of other views. diff --git a/sw/qa/extras/tiledrendering/data/content-control.odt b/sw/qa/extras/tiledrendering/data/content-control.odt deleted file mode 100644 index 624063fbd606..000000000000 Binary files a/sw/qa/extras/tiledrendering/data/content-control.odt and /dev/null differ diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 9aa5fc7e2fb3..5cb98bc928c7 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -3505,7 +3505,17 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testRedlinePortions) CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testContentControl) { // Given a document with a content control: - SwXTextDocument* pXTextDocument = createDoc("content-control.odt"); + SwXTextDocument* pXTextDocument = createDoc(); + uno::Reference<text::XText> xText = pXTextDocument->getText(); + uno::Reference<text::XTextCursor> xCursor = xText->createTextCursor(); + xText->insertString(xCursor, "test", /*bAbsorb=*/false); + xCursor->gotoStart(/*bExpand=*/false); + xCursor->gotoEnd(/*bExpand=*/true); + uno::Reference<text::XTextContent> xContentControl( + pXTextDocument->createInstance("com.sun.star.text.ContentControl"), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY); + xContentControlProps->setPropertyValue("Alias", uno::Any(OUString("my alias"))); + xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true); SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell(); setupLibreOfficeKitViewCallback(pWrtShell->GetSfxViewShell()); pWrtShell->SttEndDoc(/*bStt=*/true); @@ -3525,6 +3535,11 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testContentControl) CPPUNIT_ASSERT_EQUAL(OString("show"), sAction); OString sRectangles = aTree.get_child("rectangles").get_value<std::string>().c_str(); CPPUNIT_ASSERT(!sRectangles.isEmpty()); + // Without the accompanying fix in place, this test would have failed width: + // uncaught exception of type std::exception (or derived). + // - No such node (alias) + OString sAlias = aTree.get_child("alias").get_value<std::string>().c_str(); + CPPUNIT_ASSERT_EQUAL(OString("my alias"), sAlias); } // And when leaving that content control: diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx index 35ff9c7ae2e1..5bcc251e22c7 100644 --- a/sw/source/core/crsr/viscrs.cxx +++ b/sw/source/core/crsr/viscrs.cxx @@ -710,6 +710,11 @@ void SwSelPaintRects::HighlightContentControl() aJson.put("date", "true"); } + if (pContentControl && !pContentControl->GetAlias().isEmpty()) + { + aJson.put("alias", pContentControl->GetAlias()); + } + std::unique_ptr<char, o3tl::free_delete> pJson(aJson.extractData()); GetShell()->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_CONTENT_CONTROL, pJson.get()); }