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