summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParis Oplopoios <paris.oplopoios@collabora.com>2023-03-02 02:24:59 +0200
committerMiklos Vajna <vmiklos@collabora.com>2023-03-10 08:48:23 +0000
commitc1d6af3e9a8937cef192e2764ad4afb572743d86 (patch)
tree8ced8b9004a737254c178d243822bc8bfd309b16
parentf5b7967b01e68a16ff2f9bc94afec7d405d03dbd (diff)
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 <vmiklos@collabora.com>
-rw-r--r--include/LibreOfficeKit/LibreOfficeKitEnums.h12
-rw-r--r--include/sfx2/lokhelper.hxx3
-rw-r--r--include/vcl/ITiledRenderable.hxx6
-rw-r--r--libreofficekit/source/gtk/lokdocview.cxx1
-rw-r--r--sfx2/source/view/lokhelper.cxx5
-rw-r--r--sw/inc/unotxdoc.hxx3
-rw-r--r--sw/qa/extras/tiledrendering/tiledrendering.cxx30
-rw-r--r--sw/source/core/view/viewsh.cxx3
-rw-r--r--sw/source/uibase/uno/unotxdoc.cxx18
9 files changed, 81 insertions, 0 deletions
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";