summaryrefslogtreecommitdiff
path: root/libreofficekit
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2022-04-22 12:25:31 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-04-22 13:20:09 +0200
commite4d1731ba3e8bac2801d1b76cfb66bf7f9795468 (patch)
tree089fb4cc7b6f3eabbf33d6f656dff799b3fe61b0 /libreofficekit
parent50774644bbede54784bf710e8f4c527110513361 (diff)
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 <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'libreofficekit')
-rw-r--r--libreofficekit/source/gtk/lokdocview.cxx55
1 files changed, 55 insertions, 0 deletions
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<GdkRectangle> m_aTextSelectionRectangles;
+ /// Rectangles of the current content control.
+ std::vector<GdkRectangle> m_aContentControlRectangles;
/// 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;
@@ -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<std::string>("action");
+ if (aAction == "show")
+ {
+ auto aRectangles = aTree.get<std::string>("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)
{
@@ -3284,6 +3323,21 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
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
* @pUrl: URL of the document for which password is required
@@ -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));