From 47d95f1166a2d2855e9a1fe3c9810bed6c2f0831 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 1 Jul 2016 10:55:27 +0200 Subject: sc lok: add LOK_CALLBACK_CELL_VIEW_CURSOR So a view can be aware where the cell cursors of other views are. Change-Id: Ifcf06c0019c6af8b859e2e92222e4f3fd18da74f Reviewed-on: https://gerrit.libreoffice.org/26844 Reviewed-by: Miklos Vajna Tested-by: Jenkins (cherry picked from commit 68c5c0bb7eed007bbfbb2e51107fc0196825e85a) --- desktop/source/lib/init.cxx | 2 ++ include/LibreOfficeKit/LibreOfficeKitEnums.h | 17 ++++++++++- libreofficekit/source/gtk/lokdocview.cxx | 43 ++++++++++++++++++++++++++++ sc/source/ui/view/gridwin.cxx | 3 ++ 4 files changed, 64 insertions(+), 1 deletion(-) diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 1d14d75b04cf..e8df4df0bb36 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -478,6 +478,7 @@ CallbackFlushHandler::CallbackFlushHandler(LibreOfficeKitDocument* pDocument, Li m_states.emplace(LOK_CALLBACK_STATE_CHANGED, "NIL"); m_states.emplace(LOK_CALLBACK_MOUSE_POINTER, "NIL"); m_states.emplace(LOK_CALLBACK_CELL_CURSOR, "NIL"); + m_states.emplace(LOK_CALLBACK_CELL_VIEW_CURSOR, "NIL"); m_states.emplace(LOK_CALLBACK_CELL_FORMULA, "NIL"); m_states.emplace(LOK_CALLBACK_CURSOR_VISIBLE, "NIL"); m_states.emplace(LOK_CALLBACK_SET_PART, "NIL"); @@ -580,6 +581,7 @@ void CallbackFlushHandler::queue(const int type, const char* data) case LOK_CALLBACK_GRAPHIC_SELECTION: case LOK_CALLBACK_MOUSE_POINTER: case LOK_CALLBACK_CELL_CURSOR: + case LOK_CALLBACK_CELL_VIEW_CURSOR: case LOK_CALLBACK_CELL_FORMULA: case LOK_CALLBACK_CURSOR_VISIBLE: case LOK_CALLBACK_SET_PART: diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h index 4dfb8be670a1..c687879793ca 100644 --- a/include/LibreOfficeKit/LibreOfficeKitEnums.h +++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h @@ -329,7 +329,7 @@ typedef enum LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, /** - * The the text selection in one of the other views has changed. + * The text selection in one of the other views has changed. * * The payload format: * @@ -343,6 +343,21 @@ typedef enum */ LOK_CALLBACK_TEXT_VIEW_SELECTION, + /** + * The cell cursor in one of the other views has changed. + * + * The payload format: + * + * { + * "viewId": "..." + * "rectangle": "..." + * } + * + * - viewId is a value returned earlier by lok::Document::createView() + * - rectangle uses the format of LOK_CALLBACK_CELL_CURSOR. + */ + LOK_CALLBACK_CELL_VIEW_CURSOR, + } LibreOfficeKitCallbackType; diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index e36a1c37d807..c79e0980a4c8 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -102,6 +102,9 @@ struct LOKDocViewPrivateImpl GdkRectangle m_aTextSelectionEnd; GdkRectangle m_aGraphicSelection; GdkRectangle m_aCellCursor; + /// Position and size of the cell view cursors. The current view can only + //see / them, can't modify them. Key is the view id. + std::map m_aCellViewCursors; gboolean m_bInDragGraphicSelection; /// @name Start/middle/end handle. @@ -355,7 +358,12 @@ callbackTypeToString (int nType) return "LOK_CALLBACK_INVALIDATE_VIEW_CURSOR"; case LOK_CALLBACK_TEXT_VIEW_SELECTION: return "LOK_CALLBACK_TEXT_VIEW_SELECTION"; + case LOK_CALLBACK_CELL_VIEW_CURSOR: + return "LOK_CALLBACK_CELL_VIEW_CURSOR"; + case LOK_CALLBACK_CELL_FORMULA: + return "LOK_CALLBACK_CELL_FORMULA"; } + g_assert(false); return nullptr; } @@ -1187,6 +1195,24 @@ callback (gpointer pData) gtk_widget_queue_draw(GTK_WIDGET(pDocView)); break; } + case LOK_CALLBACK_CELL_VIEW_CURSOR: + { + std::stringstream aStream(pCallback->m_aPayload); + boost::property_tree::ptree aTree; + boost::property_tree::read_json(aStream, aTree); + int nViewId = aTree.get("viewId"); + const std::string& rRectangle = aTree.get("rectangle"); + if (rRectangle != "EMPTY") + priv->m_aCellViewCursors[nViewId] = payloadToRectangle(pDocView, rRectangle.c_str()); + else + { + auto it = priv->m_aCellViewCursors.find(nViewId); + if (it != priv->m_aCellViewCursors.end()) + priv->m_aCellViewCursors.erase(it); + } + gtk_widget_queue_draw(GTK_WIDGET(pDocView)); + break; + } default: g_assert(false); break; @@ -1574,6 +1600,7 @@ renderOverlay(LOKDocView* pDocView, cairo_t* pCairo) g_free (handleGraphicPath); } + // Draw the cell cursor. if (!isEmptyRectangle(priv->m_aCellCursor)) { cairo_set_source_rgb(pCairo, 0, 0, 0); @@ -1590,6 +1617,22 @@ renderOverlay(LOKDocView* pDocView, cairo_t* pCairo) cairo_stroke(pCairo); } + // Cell view cursors: they are colored. + for (auto& rPair : priv->m_aCellViewCursors) + { + GdkRectangle& rCursor = rPair.second; + + const GdkRGBA& rDark = getDarkColor(rPair.first); + cairo_set_source_rgb(pCairo, rDark.red, rDark.green, rDark.blue); + cairo_rectangle(pCairo, + twipToPixel(rCursor.x, priv->m_fZoom), + twipToPixel(rCursor.y, priv->m_fZoom), + twipToPixel(rCursor.width, priv->m_fZoom), + twipToPixel(rCursor.height, priv->m_fZoom)); + cairo_set_line_width(pCairo, 2.0); + cairo_stroke(pCairo); + } + return FALSE; } diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index e279da2dd3a2..4e6d9c638a4a 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -136,6 +136,7 @@ #include #include #include +#include #include #include @@ -5853,6 +5854,7 @@ void ScGridWindow::updateLibreOfficeKitCellCursor() OString aCursor = getCellCursor(pViewData->GetZoomX(), pViewData->GetZoomY()); ScTabViewShell* pViewShell = pViewData->GetViewShell(); pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CELL_CURSOR, aCursor.getStr()); + SfxLokHelper::notifyOtherViews(pViewShell, LOK_CALLBACK_CELL_VIEW_CURSOR, "rectangle", aCursor); } void ScGridWindow::CursorChanged() @@ -5897,6 +5899,7 @@ void ScGridWindow::DeleteCursorOverlay() { ScTabViewShell* pViewShell = pViewData->GetViewShell(); pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CELL_CURSOR, "EMPTY"); + SfxLokHelper::notifyOtherViews(pViewShell, LOK_CALLBACK_CELL_VIEW_CURSOR, "rectangle", "EMPTY"); mpOOCursors.reset(); } -- cgit v1.2.3