135360
From 8289d40ed650611d5c5dbfe84810ac48af3665dc Mon Sep 17 00:00:00 2001
135360
From: Andrzej Hunt <andrzej@ahunt.org>
135360
Date: Mon, 2 Nov 2015 11:43:05 +0100
135360
Subject: [PATCH 276/398] sc lok: Cell Cursor callback
135360
135360
This only works correctly for the default zoom level - since
135360
the updateLibreOfficeKitCellCursor call happens during the
135360
internal / hidden rendering, it uses the internal zoom values,
135360
which can differ from the tiled-rendering zoom values.
135360
135360
Conflicts:
135360
	include/LibreOfficeKit/LibreOfficeKitEnums.h
135360
135360
(cherry picked from commit 799406068d34bb69a077fcc0548bfed002f05641)
135360
135360
Change-Id: Ie4f344fe771078fca10ad9d6f7a93e88fb93880a
135360
---
135360
 include/LibreOfficeKit/LibreOfficeKitEnums.h |  9 +++++++-
135360
 libreofficekit/source/gtk/lokdocview.cxx     | 30 ++++++++++++++++++++++++++
135360
 sc/source/ui/view/gridwin.cxx                | 32 ++++++++++++++++++++++++----
135360
 3 files changed, 66 insertions(+), 5 deletions(-)
135360
135360
diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
135360
index 86d9e6bfd873..bf6267585a0a 100644
135360
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
135360
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
135360
@@ -195,7 +195,14 @@ typedef enum
135360
      *     // TODO "result": "..."  // UNO Any converted to JSON (not implemented yet)
135360
      * }
135360
      */
135360
-    LOK_CALLBACK_UNO_COMMAND_RESULT
135360
+    LOK_CALLBACK_UNO_COMMAND_RESULT,
135360
+
135360
+    /**
135360
+     * The size and/or the position of the cell cursor changed.
135360
+     *
135360
+     * Rectangle format is the same as LOK_CALLBACK_INVALIDATE_TILES.
135360
+     */
135360
+    LOK_CALLBACK_CELL_CURSOR
135360
 }
135360
 LibreOfficeKitCallbackType;
135360
 
135360
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
135360
index 575116f4d028..73b01797dbf9 100644
135360
--- a/libreofficekit/source/gtk/lokdocview.cxx
135360
+++ b/libreofficekit/source/gtk/lokdocview.cxx
135360
@@ -79,6 +79,7 @@ struct LOKDocViewPrivateImpl
135360
     /// Position and size of the selection end.
135360
     GdkRectangle m_aTextSelectionEnd;
135360
     GdkRectangle m_aGraphicSelection;
135360
+    GdkRectangle m_aCellCursor;
135360
     gboolean m_bInDragGraphicSelection;
135360
 
135360
     /// @name Start/middle/end handle.
135360
@@ -140,6 +141,7 @@ struct LOKDocViewPrivateImpl
135360
         m_aTextSelectionStart({0, 0, 0, 0}),
135360
         m_aTextSelectionEnd({0, 0, 0, 0}),
135360
         m_aGraphicSelection({0, 0, 0, 0}),
135360
+        m_aCellCursor({0, 0, 0, 0}),
135360
         m_bInDragGraphicSelection(false),
135360
         m_pHandleStart(0),
135360
         m_aHandleStartRect({0, 0, 0, 0}),
135360
@@ -275,6 +277,8 @@ callbackTypeToString (int nType)
135360
         return "LOK_CALLBACK_CURSOR_VISIBLE";
135360
     case LOK_CALLBACK_GRAPHIC_SELECTION:
135360
         return "LOK_CALLBACK_GRAPHIC_SELECTION";
135360
+    case LOK_CALLBACK_CELL_CURSOR:
135360
+        return "LOK_CALLBACK_CELL_CURSOR";
135360
     case LOK_CALLBACK_HYPERLINK_CLICKED:
135360
         return "LOK_CALLBACK_HYPERLINK_CLICKED";
135360
     case LOK_CALLBACK_STATE_CHANGED:
135360
@@ -719,6 +723,15 @@ callback (gpointer pData)
135360
         gtk_widget_queue_draw(GTK_WIDGET(pDocView));
135360
     }
135360
     break;
135360
+    case LOK_CALLBACK_CELL_CURSOR:
135360
+    {
135360
+        if (pCallback->m_aPayload != "EMPTY")
135360
+            priv->m_aCellCursor = payloadToRectangle(pDocView, pCallback->m_aPayload.c_str());
135360
+        else
135360
+            memset(&priv->m_aCellCursor, 0, sizeof(priv->m_aCellCursor));
135360
+        gtk_widget_queue_draw(GTK_WIDGET(pDocView));
135360
+    }
135360
+    break;
135360
     case LOK_CALLBACK_HYPERLINK_CLICKED:
135360
     {
135360
         hyperlinkClicked(pDocView, pCallback->m_aPayload);
135360
@@ -1074,6 +1087,22 @@ renderOverlay(LOKDocView* pDocView, cairo_t* pCairo)
135360
         g_free (handleGraphicPath);
135360
     }
135360
 
135360
+    if (!isEmptyRectangle(priv->m_aCellCursor))
135360
+    {
135360
+        cairo_set_source_rgb(pCairo, 0, 0, 0);
135360
+        cairo_rectangle(pCairo,
135360
+                        twipToPixel(priv->m_aCellCursor.x, priv->m_fZoom),
135360
+                        twipToPixel(priv->m_aCellCursor.y, priv->m_fZoom),
135360
+                        twipToPixel(priv->m_aCellCursor.width, priv->m_fZoom),
135360
+                        twipToPixel(priv->m_aCellCursor.height, priv->m_fZoom));
135360
+                        // priv->m_aCellCursor.x - 1,
135360
+                        // priv->m_aCellCursor.y - 1,
135360
+                        // priv->m_aCellCursor.width + 2,
135360
+                        // priv->m_aCellCursor.height + 2);
135360
+        cairo_set_line_width(pCairo, 2.0);
135360
+        cairo_stroke(pCairo);
135360
+    }
135360
+
135360
     return FALSE;
135360
 }
135360
 
135360
@@ -2331,6 +2360,7 @@ lok_doc_view_reset_view(LOKDocView* pDocView)
135360
     memset(&priv->m_aTextSelectionEnd, 0, sizeof(priv->m_aTextSelectionEnd));
135360
     memset(&priv->m_aGraphicSelection, 0, sizeof(priv->m_aGraphicSelection));
135360
     priv->m_bInDragGraphicSelection = false;
135360
+    memset(&priv->m_aCellCursor, 0, sizeof(priv->m_aCellCursor));
135360
 
135360
     cairo_surface_destroy(priv->m_pHandleStart);
135360
     priv->m_pHandleStart = 0;
135360
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
135360
index f24b42f3b27e..7ab88c6c0eb1 100644
135360
--- a/sc/source/ui/view/gridwin.cxx
135360
+++ b/sc/source/ui/view/gridwin.cxx
135360
@@ -5782,13 +5782,38 @@ bool ScGridWindow::InsideVisibleRange( SCCOL nPosX, SCROW nPosY )
135360
     return maVisibleRange.isInside(nPosX, nPosY);
135360
 }
135360
 
135360
-// #114409#
135360
+static void updateLibreOfficeKitCellCursor(ScViewData* pViewData, ScSplitPos eWhich) {
135360
+    ScDocument* pDoc = pViewData->GetDocument();
135360
+    ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
135360
+
135360
+    if (!pDrawLayer->isTiledRendering())
135360
+        return;
135360
+
135360
+    SCCOL nX = pViewData->GetCurX();
135360
+    SCROW nY = pViewData->GetCurY();
135360
+    Point aScrPos = pViewData->GetScrPos( nX, nY, eWhich, true );
135360
+
135360
+    long nSizeXPix;
135360
+    long nSizeYPix;
135360
+    pViewData->GetMergeSizePixel( nX, nY, nSizeXPix, nSizeYPix );
135360
+
135360
+    double fPPTX = pViewData->GetPPTX();
135360
+    double fPPTY = pViewData->GetPPTY();
135360
+    Rectangle aRect(Point(aScrPos.getX() / fPPTX, aScrPos.getY() / fPPTY),
135360
+                    Size(nSizeXPix / fPPTX, nSizeYPix / fPPTY));
135360
+
135360
+    pDrawLayer->libreOfficeKitCallback(LOK_CALLBACK_CELL_CURSOR, aRect.toString().getStr());
135360
+
135360
+}
135360
+
135360
 void ScGridWindow::CursorChanged()
135360
 {
135360
     // here the created OverlayObjects may be transformed in later versions. For
135360
     // now, just re-create them
135360
 
135360
     UpdateCursorOverlay();
135360
+
135360
+    updateLibreOfficeKitCellCursor(pViewData, eWhich);
135360
 }
135360
 
135360
 // #114409#
135360
@@ -5942,9 +5967,8 @@ void ScGridWindow::UpdateCursorOverlay()
135360
 {
135360
     ScDocument* pDoc = pViewData->GetDocument();
135360
 
135360
-    // never show the cell cursor when the tiled rendering is going on; either
135360
-    // we want to show the editeng selection, or the cell selection, but not
135360
-    // the cell cursor by itself
135360
+    // The cursor is rendered client-side in tiled rendering -
135360
+    // see updateLibreOfficeKitCellCursor.
135360
     if (pDoc->GetDrawLayer()->isTiledRendering())
135360
         return;
135360
 
135360
-- 
135360
2.12.0
135360