From 897189cfc6b3f6f3a9a0148b060ea25e5f8d9eaa Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 22 Jul 2016 16:39:47 +0200 Subject: sw: add new LOK_CALLBACK_VIEW_LOCK callback When we're after SdrBeginTextEdit(), but before SdrEndTextEdit(), and have multiple views, then only the active view paints the edited text, the other views look like the shape has no text at all. Add a new callback that exposes the position and size of the rectangle where the shape text will be painted after text edit ended, so clients can draw some kind of locking indicator there. This way the rendered result can differ in the "shape has no text" and the "shape text is edited in an other view" cases. Change-Id: I6096479a8a05c2547d15222e6d997b848af02945 Reviewed-on: https://gerrit.libreoffice.org/27441 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- libreofficekit/source/gtk/lokdocview.cxx | 59 ++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'libreofficekit') diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index d5a1dd34be93..f604b583e985 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -190,6 +190,10 @@ struct LOKDocViewPrivateImpl /// Event source ID for handleTimeout() of this widget. guint m_nTimeoutId; + /// Rectangles of view locks. The current view can only see + /// them, can't modify them. Key is the view id. + std::map m_aViewLockRectangles; + LOKDocViewPrivateImpl() : m_aLOPath(nullptr), m_pUserProfileURL(nullptr), @@ -415,6 +419,8 @@ callbackTypeToString (int nType) return "LOK_CALLBACK_UNO_COMMAND_RESULT"; case LOK_CALLBACK_ERROR: return "LOK_CALLBACK_ERROR"; + case LOK_CALLBACK_VIEW_LOCK: + return "LOK_CALLBACK_VIEW_LOCK"; } g_assert(false); return nullptr; @@ -1314,6 +1320,25 @@ callback (gpointer pData) gtk_widget_queue_draw(GTK_WIDGET(pDocView)); break; } + case LOK_CALLBACK_VIEW_LOCK: + { + std::stringstream aStream(pCallback->m_aPayload); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + int nViewId = aTree.get("viewId"); + int nPart = aTree.get("part"); + const std::string& rRectangle = aTree.get("rectangle"); + if (rRectangle != "EMPTY") + priv->m_aViewLockRectangles[nViewId] = ViewRectangle(nPart, payloadToRectangle(pDocView, rRectangle.c_str())); + else + { + auto it = priv->m_aViewLockRectangles.find(nViewId); + if (it != priv->m_aViewLockRectangles.end()) + priv->m_aViewLockRectangles.erase(it); + } + gtk_widget_queue_draw(GTK_WIDGET(pDocView)); + break; + } default: g_assert(false); break; @@ -1746,6 +1771,40 @@ renderOverlay(LOKDocView* pDocView, cairo_t* pCairo) cairo_stroke(pCairo); } + // View locks: they are colored. + for (auto& rPair : priv->m_aViewLockRectangles) + { + const ViewRectangle& rRectangle = rPair.second; + if (rRectangle.m_nPart != priv->m_nPartId) + continue; + + // Draw a rectangle. + const GdkRGBA& rDark = getDarkColor(rPair.first); + cairo_set_source_rgb(pCairo, rDark.red, rDark.green, rDark.blue); + cairo_rectangle(pCairo, + twipToPixel(rRectangle.m_aRectangle.x, priv->m_fZoom), + twipToPixel(rRectangle.m_aRectangle.y, priv->m_fZoom), + twipToPixel(rRectangle.m_aRectangle.width, priv->m_fZoom), + twipToPixel(rRectangle.m_aRectangle.height, priv->m_fZoom)); + cairo_set_line_width(pCairo, 2.0); + cairo_stroke(pCairo); + + // Cross it. + cairo_move_to(pCairo, + twipToPixel(rRectangle.m_aRectangle.x, priv->m_fZoom), + twipToPixel(rRectangle.m_aRectangle.y, priv->m_fZoom)); + cairo_line_to(pCairo, + twipToPixel(rRectangle.m_aRectangle.x + rRectangle.m_aRectangle.width, priv->m_fZoom), + twipToPixel(rRectangle.m_aRectangle.y + rRectangle.m_aRectangle.height, priv->m_fZoom)); + cairo_move_to(pCairo, + twipToPixel(rRectangle.m_aRectangle.x, priv->m_fZoom), + twipToPixel(rRectangle.m_aRectangle.y + rRectangle.m_aRectangle.height, priv->m_fZoom)); + cairo_line_to(pCairo, + twipToPixel(rRectangle.m_aRectangle.x + rRectangle.m_aRectangle.width, priv->m_fZoom), + twipToPixel(rRectangle.m_aRectangle.y, priv->m_fZoom)); + cairo_stroke(pCairo); + } + return FALSE; } -- cgit