Blob Blame History Raw
From 8289d40ed650611d5c5dbfe84810ac48af3665dc Mon Sep 17 00:00:00 2001
From: Andrzej Hunt <andrzej@ahunt.org>
Date: Mon, 2 Nov 2015 11:43:05 +0100
Subject: [PATCH 276/398] sc lok: Cell Cursor callback

This only works correctly for the default zoom level - since
the updateLibreOfficeKitCellCursor call happens during the
internal / hidden rendering, it uses the internal zoom values,
which can differ from the tiled-rendering zoom values.

Conflicts:
	include/LibreOfficeKit/LibreOfficeKitEnums.h

(cherry picked from commit 799406068d34bb69a077fcc0548bfed002f05641)

Change-Id: Ie4f344fe771078fca10ad9d6f7a93e88fb93880a
---
 include/LibreOfficeKit/LibreOfficeKitEnums.h |  9 +++++++-
 libreofficekit/source/gtk/lokdocview.cxx     | 30 ++++++++++++++++++++++++++
 sc/source/ui/view/gridwin.cxx                | 32 ++++++++++++++++++++++++----
 3 files changed, 66 insertions(+), 5 deletions(-)

diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
index 86d9e6bfd873..bf6267585a0a 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -195,7 +195,14 @@ typedef enum
      *     // TODO "result": "..."  // UNO Any converted to JSON (not implemented yet)
      * }
      */
-    LOK_CALLBACK_UNO_COMMAND_RESULT
+    LOK_CALLBACK_UNO_COMMAND_RESULT,
+
+    /**
+     * The size and/or the position of the cell cursor changed.
+     *
+     * Rectangle format is the same as LOK_CALLBACK_INVALIDATE_TILES.
+     */
+    LOK_CALLBACK_CELL_CURSOR
 }
 LibreOfficeKitCallbackType;
 
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 575116f4d028..73b01797dbf9 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -79,6 +79,7 @@ struct LOKDocViewPrivateImpl
     /// Position and size of the selection end.
     GdkRectangle m_aTextSelectionEnd;
     GdkRectangle m_aGraphicSelection;
+    GdkRectangle m_aCellCursor;
     gboolean m_bInDragGraphicSelection;
 
     /// @name Start/middle/end handle.
@@ -140,6 +141,7 @@ struct LOKDocViewPrivateImpl
         m_aTextSelectionStart({0, 0, 0, 0}),
         m_aTextSelectionEnd({0, 0, 0, 0}),
         m_aGraphicSelection({0, 0, 0, 0}),
+        m_aCellCursor({0, 0, 0, 0}),
         m_bInDragGraphicSelection(false),
         m_pHandleStart(0),
         m_aHandleStartRect({0, 0, 0, 0}),
@@ -275,6 +277,8 @@ callbackTypeToString (int nType)
         return "LOK_CALLBACK_CURSOR_VISIBLE";
     case LOK_CALLBACK_GRAPHIC_SELECTION:
         return "LOK_CALLBACK_GRAPHIC_SELECTION";
+    case LOK_CALLBACK_CELL_CURSOR:
+        return "LOK_CALLBACK_CELL_CURSOR";
     case LOK_CALLBACK_HYPERLINK_CLICKED:
         return "LOK_CALLBACK_HYPERLINK_CLICKED";
     case LOK_CALLBACK_STATE_CHANGED:
@@ -719,6 +723,15 @@ callback (gpointer pData)
         gtk_widget_queue_draw(GTK_WIDGET(pDocView));
     }
     break;
+    case LOK_CALLBACK_CELL_CURSOR:
+    {
+        if (pCallback->m_aPayload != "EMPTY")
+            priv->m_aCellCursor = payloadToRectangle(pDocView, pCallback->m_aPayload.c_str());
+        else
+            memset(&priv->m_aCellCursor, 0, sizeof(priv->m_aCellCursor));
+        gtk_widget_queue_draw(GTK_WIDGET(pDocView));
+    }
+    break;
     case LOK_CALLBACK_HYPERLINK_CLICKED:
     {
         hyperlinkClicked(pDocView, pCallback->m_aPayload);
@@ -1074,6 +1087,22 @@ renderOverlay(LOKDocView* pDocView, cairo_t* pCairo)
         g_free (handleGraphicPath);
     }
 
+    if (!isEmptyRectangle(priv->m_aCellCursor))
+    {
+        cairo_set_source_rgb(pCairo, 0, 0, 0);
+        cairo_rectangle(pCairo,
+                        twipToPixel(priv->m_aCellCursor.x, priv->m_fZoom),
+                        twipToPixel(priv->m_aCellCursor.y, priv->m_fZoom),
+                        twipToPixel(priv->m_aCellCursor.width, priv->m_fZoom),
+                        twipToPixel(priv->m_aCellCursor.height, priv->m_fZoom));
+                        // priv->m_aCellCursor.x - 1,
+                        // priv->m_aCellCursor.y - 1,
+                        // priv->m_aCellCursor.width + 2,
+                        // priv->m_aCellCursor.height + 2);
+        cairo_set_line_width(pCairo, 2.0);
+        cairo_stroke(pCairo);
+    }
+
     return FALSE;
 }
 
@@ -2331,6 +2360,7 @@ lok_doc_view_reset_view(LOKDocView* pDocView)
     memset(&priv->m_aTextSelectionEnd, 0, sizeof(priv->m_aTextSelectionEnd));
     memset(&priv->m_aGraphicSelection, 0, sizeof(priv->m_aGraphicSelection));
     priv->m_bInDragGraphicSelection = false;
+    memset(&priv->m_aCellCursor, 0, sizeof(priv->m_aCellCursor));
 
     cairo_surface_destroy(priv->m_pHandleStart);
     priv->m_pHandleStart = 0;
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index f24b42f3b27e..7ab88c6c0eb1 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -5782,13 +5782,38 @@ bool ScGridWindow::InsideVisibleRange( SCCOL nPosX, SCROW nPosY )
     return maVisibleRange.isInside(nPosX, nPosY);
 }
 
-// #114409#
+static void updateLibreOfficeKitCellCursor(ScViewData* pViewData, ScSplitPos eWhich) {
+    ScDocument* pDoc = pViewData->GetDocument();
+    ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
+
+    if (!pDrawLayer->isTiledRendering())
+        return;
+
+    SCCOL nX = pViewData->GetCurX();
+    SCROW nY = pViewData->GetCurY();
+    Point aScrPos = pViewData->GetScrPos( nX, nY, eWhich, true );
+
+    long nSizeXPix;
+    long nSizeYPix;
+    pViewData->GetMergeSizePixel( nX, nY, nSizeXPix, nSizeYPix );
+
+    double fPPTX = pViewData->GetPPTX();
+    double fPPTY = pViewData->GetPPTY();
+    Rectangle aRect(Point(aScrPos.getX() / fPPTX, aScrPos.getY() / fPPTY),
+                    Size(nSizeXPix / fPPTX, nSizeYPix / fPPTY));
+
+    pDrawLayer->libreOfficeKitCallback(LOK_CALLBACK_CELL_CURSOR, aRect.toString().getStr());
+
+}
+
 void ScGridWindow::CursorChanged()
 {
     // here the created OverlayObjects may be transformed in later versions. For
     // now, just re-create them
 
     UpdateCursorOverlay();
+
+    updateLibreOfficeKitCellCursor(pViewData, eWhich);
 }
 
 // #114409#
@@ -5942,9 +5967,8 @@ void ScGridWindow::UpdateCursorOverlay()
 {
     ScDocument* pDoc = pViewData->GetDocument();
 
-    // never show the cell cursor when the tiled rendering is going on; either
-    // we want to show the editeng selection, or the cell selection, but not
-    // the cell cursor by itself
+    // The cursor is rendered client-side in tiled rendering -
+    // see updateLibreOfficeKitCellCursor.
     if (pDoc->GetDrawLayer()->isTiledRendering())
         return;
 
-- 
2.12.0