diff options
Diffstat (limited to 'libreofficekit')
-rw-r--r-- | libreofficekit/source/gtk/lokdocview.cxx | 59 |
1 files changed, 59 insertions, 0 deletions
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<int, ViewRectangle> 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<int>("viewId"); + int nPart = aTree.get<int>("part"); + const std::string& rRectangle = aTree.get<std::string>("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; } |