From e4d1731ba3e8bac2801d1b76cfb66bf7f9795468 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 22 Apr 2022 12:25:31 +0200 Subject: sw content controls: add LOK API This is somewhat similar to LOK_CALLBACK_FORM_FIELD_BUTTON: if the cursor enters or leaves a content control, then we send this message, so the LOK client can render some kind of shading and/or border around the content control to indicate the boundaries of the object. Similar to selections, this can be multiple rectangles in case the string is long enough that the layout breaks it into multiple lines. Change-Id: I0641a19503b7a1d4cade8fe9b510605cab49f258 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133314 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- libreofficekit/source/gtk/lokdocview.cxx | 55 ++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'libreofficekit') diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index 45c9cacedff6..1bf7e7301d7c 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -124,6 +124,8 @@ struct LOKDocViewPrivateImpl guint32 m_nKeyModifier; /// Rectangles of the current text selection. std::vector m_aTextSelectionRectangles; + /// Rectangles of the current content control. + std::vector m_aContentControlRectangles; /// Rectangles of view selections. The current view can only see /// them, can't modify them. Key is the view id. std::map m_aTextViewSelectionRectangles; @@ -281,6 +283,7 @@ enum ADDRESS_CHANGED, FORMULA_CHANGED, TEXT_SELECTION, + CONTENT_CONTROL, PASSWORD_REQUIRED, COMMENT, RULER, @@ -1392,6 +1395,27 @@ callback (gpointer pData) break; } + case LOK_CALLBACK_CONTENT_CONTROL: + { + std::stringstream aStream(pCallback->m_aPayload); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + auto aAction = aTree.get("action"); + if (aAction == "show") + { + auto aRectangles = aTree.get("rectangles"); + priv->m_aContentControlRectangles = payloadToRectangles(pDocView, aRectangles.c_str()); + } + else if (aAction == "hide") + { + priv->m_aContentControlRectangles.clear(); + } + bool bIsTextSelected = !priv->m_aContentControlRectangles.empty(); + g_signal_emit(pDocView, doc_view_signals[CONTENT_CONTROL], 0, bIsTextSelected); + gtk_widget_queue_draw(GTK_WIDGET(pDocView)); + } + break; + case LOK_CALLBACK_STATUS_INDICATOR_START: case LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE: case LOK_CALLBACK_STATUS_INDICATOR_FINISH: @@ -1809,6 +1833,21 @@ renderOverlay(LOKDocView* pDocView, cairo_t* pCairo) } } + if (!priv->m_aContentControlRectangles.empty()) + { + for (const GdkRectangle& rRectangle : priv->m_aContentControlRectangles) + { + // Black with 75% transparency. + cairo_set_source_rgba(pCairo, (double(0x7f))/255, (double(0x7f))/255, (double(0x7f))/255, 0.25); + cairo_rectangle(pCairo, + twipToPixel(rRectangle.x, priv->m_fZoom), + twipToPixel(rRectangle.y, priv->m_fZoom), + twipToPixel(rRectangle.width, priv->m_fZoom), + twipToPixel(rRectangle.height, priv->m_fZoom)); + cairo_fill(pCairo); + } + } + // Selections of other views. for (const auto& rPair : priv->m_aTextViewSelectionRectangles) { @@ -3283,6 +3322,21 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass) G_TYPE_NONE, 1, G_TYPE_BOOLEAN); + /** + * LOKDocView::content-control: + * @pDocView: the #LOKDocView on which the signal is emitted + * @bIsTextSelected: whether current content control is non-null + */ + doc_view_signals[CONTENT_CONTROL] = + g_signal_new("content-control", + G_TYPE_FROM_CLASS(pGObjectClass), + G_SIGNAL_RUN_FIRST, + 0, + nullptr, nullptr, + g_cclosure_marshal_VOID__BOOLEAN, + G_TYPE_NONE, 1, + G_TYPE_BOOLEAN); + /** * LOKDocView::password-required: * @pDocView: the #LOKDocView on which the signal is emitted @@ -3727,6 +3781,7 @@ lok_doc_view_reset_view(LOKDocView* pDocView) priv->m_nLastButtonPressTime = 0; priv->m_nLastButtonReleaseTime = 0; priv->m_aTextSelectionRectangles.clear(); + priv->m_aContentControlRectangles.clear(); memset(&priv->m_aTextSelectionStart, 0, sizeof(priv->m_aTextSelectionStart)); memset(&priv->m_aTextSelectionEnd, 0, sizeof(priv->m_aTextSelectionEnd)); -- cgit