include/LibreOfficeKit/LibreOfficeKitEnums.h | 12 ++++++++++ include/sfx2/lokhelper.hxx | 3 ++ include/vcl/ITiledRenderable.hxx | 6 +++++ libreofficekit/source/gtk/lokdocview.cxx | 1 sfx2/source/view/lokhelper.cxx | 5 ++++ sw/inc/unotxdoc.hxx | 3 ++ sw/qa/extras/tiledrendering/tiledrendering.cxx | 30 +++++++++++++++++++++++++ sw/source/core/view/viewsh.cxx | 3 ++ sw/source/uibase/uno/unotxdoc.cxx | 18 +++++++++++++++ 9 files changed, 81 insertions(+)
New commits: commit c1d6af3e9a8937cef192e2764ad4afb572743d86 Author: Paris Oplopoios <paris.oplopo...@collabora.com> AuthorDate: Thu Mar 2 02:24:59 2023 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Mar 10 08:48:23 2023 +0000 sw lok: notify clients about view option changes Send a string of the view options to the kit when the view changes Change-Id: I89f65ff1d22a83a54dde35e39eb487edda0b58e1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148078 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h index 38b3e5e62a40..6e02c92596f1 100644 --- a/include/LibreOfficeKit/LibreOfficeKitEnums.h +++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h @@ -907,6 +907,16 @@ typedef enum * "file:///tmp/hello-world.pdf" */ LOK_CALLBACK_EXPORT_FILE = 59, + + /** + * Some attribute of this view has changed, that will cause it + * to completely re-render, eg. non-printing characters or + * or dark mode was toggled, and then distinct from other views. + * + * Payload is an opaque string that matches this set of states. + * this will be emitted after creating a new view. + */ + LOK_CALLBACK_VIEW_RENDER_STATE = 60 } LibreOfficeKitCallbackType; @@ -1055,6 +1065,8 @@ static inline const char* lokCallbackTypeToString(int nType) return "LOK_CALLBACK_MEDIA_SHAPE"; case LOK_CALLBACK_EXPORT_FILE: return "LOK_CALLBACK_EXPORT_FILE"; + case LOK_CALLBACK_VIEW_RENDER_STATE: + return "LOK_CALLBACK_VIEW_RENDER_STATE"; } assert(!"Unknown LibreOfficeKitCallbackType type."); diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index f7de18112c04..b572ddf076b5 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -140,6 +140,9 @@ public: /// Notify about the editing context change. static void notifyContextChange(const css::ui::ContextChangeEventObject& rEvent); + /// Emits an LOK_CALLBACK_VIEW_RENDER_STATE + static void notifyViewRenderState(SfxViewShell const* pViewShell, vcl::ITiledRenderable* pDoc); + // Notify about the given type needing an update. static void notifyUpdate(SfxViewShell const* pViewShell, int nType); // Notify about the given type needing a per-viewid update. diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx index d110e33f7e19..9fa61258fc7a 100644 --- a/include/vcl/ITiledRenderable.hxx +++ b/include/vcl/ITiledRenderable.hxx @@ -376,6 +376,12 @@ public: virtual void getCommandValues(tools::JsonWriter& /*rJsonWriter*/, std::string_view /*rCommand*/) { } + + /** + * Returns an opaque string reflecting the render state of a component + * eg. 'PD' - P for non-printing-characters, D for dark-mode. + */ + virtual OString getViewRenderState() { return rtl::OString(); } }; } // namespace vcl diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index ff40e4929781..8fcbe9a404fc 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -1486,6 +1486,7 @@ callback (gpointer pData) case LOK_CALLBACK_FONTS_MISSING: case LOK_CALLBACK_MEDIA_SHAPE: case LOK_CALLBACK_EXPORT_FILE: + case LOK_CALLBACK_VIEW_RENDER_STATE: { // TODO: Implement me break; diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index ddcad7bab42d..70d18b54edae 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -557,6 +557,11 @@ void SfxLokHelper::sendUnoStatus(const SfxViewShell* pShell, const SfxPoolItem* } } +void SfxLokHelper::notifyViewRenderState(const SfxViewShell* pShell, vcl::ITiledRenderable* pDoc) +{ + pShell->libreOfficeKitViewCallback(LOK_CALLBACK_VIEW_RENDER_STATE, pDoc->getViewRenderState().getStr()); +} + void SfxLokHelper::notifyWindow(const SfxViewShell* pThisView, vcl::LOKWindowId nLOKWindowId, std::u16string_view rAction, diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx index 57cb3ccca589..056013d75056 100644 --- a/sw/inc/unotxdoc.hxx +++ b/sw/inc/unotxdoc.hxx @@ -462,6 +462,9 @@ public: /// @see vcl::ITiledRenderable::getCommandValues(). void getCommandValues(tools::JsonWriter& rJsonWriter, std::string_view rCommand) override; + /// @see vcl::ITiledRenderable::getViewRenderState(). + OString getViewRenderState() override; + /// @see vcl::ITiledRenderable::supportsCommand(). bool supportsCommand(std::u16string_view rCommand) override; diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index d302e6413ea7..31eb9b267fba 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -1669,6 +1669,36 @@ CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testRedlineUpdateCallback) CPPUNIT_ASSERT_EQUAL(3, m_nRedlineTableEntryModified); } +CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testGetViewRenderState) +{ + SwXTextDocument* pXTextDocument = createDoc(); + int nFirstViewId = SfxLokHelper::getView(); + ViewCallback aView1; + { + SwViewOption aViewOptions; + aViewOptions.SetViewMetaChars(true); + aViewOptions.SetOnlineSpell(true); + pXTextDocument->GetDocShell()->GetWrtShell()->ApplyViewOptions(aViewOptions); + } + CPPUNIT_ASSERT_EQUAL(OString("PS"), pXTextDocument->getViewRenderState()); + + // Create a second view + SfxLokHelper::createView(); + ViewCallback aView2; + { + // Give the second view different options + SwViewOption aViewOptions; + aViewOptions.SetViewMetaChars(false); + aViewOptions.SetOnlineSpell(true); + pXTextDocument->GetDocShell()->GetWrtShell()->ApplyViewOptions(aViewOptions); + } + CPPUNIT_ASSERT_EQUAL(OString("S"), pXTextDocument->getViewRenderState()); + + // Switch back to the first view, and check that the options string is the same + SfxLokHelper::setView(nFirstViewId); + CPPUNIT_ASSERT_EQUAL(OString("PS"), pXTextDocument->getViewRenderState()); +} + CPPUNIT_TEST_FIXTURE(SwTiledRenderingTest, testSetViewGraphicSelection) { // Load a document. diff --git a/sw/source/core/view/viewsh.cxx b/sw/source/core/view/viewsh.cxx index 51559c606146..d7b548d9b944 100644 --- a/sw/source/core/view/viewsh.cxx +++ b/sw/source/core/view/viewsh.cxx @@ -2409,6 +2409,9 @@ void SwViewShell::ImplApplyViewOptions( const SwViewOption &rOpt ) InvalidateLayout( true ); } + SwXTextDocument* pModel = comphelper::getFromUnoTunnel<SwXTextDocument>(GetSfxViewShell()->GetCurrentDocument()); + SfxLokHelper::notifyViewRenderState(GetSfxViewShell(), pModel); + pMyWin->Invalidate(); if ( bReformat ) { diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index b2eec7838274..ece205867661 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -3402,6 +3402,24 @@ SwXTextDocument::getSearchResultRectangles(const char* pPayload) return std::vector<basegfx::B2DRange>(); } +OString SwXTextDocument::getViewRenderState() +{ + OStringBuffer aState; + SwView* pView = m_pDocShell->GetView(); + if (pView && pView->GetWrtShellPtr()) + { + const SwViewOption* pVOpt = pView->GetWrtShell().GetViewOptions(); + if (pVOpt) + { + if (pVOpt->IsViewMetaChars()) + aState.append('P'); + if (pVOpt->IsOnlineSpell()) + aState.append('S'); + } + } + return aState.makeStringAndClear(); +} + namespace { inline constexpr OUStringLiteral SELECTED_DATE_FORMAT = u"YYYY-MM-DD";