Blame SOURCES/0317-LOK-calc-formula-callback-formula-bar-implementation.patch

135360
From d57909684dd464e1e7b8616ac1cbd43a8f5817c2 Mon Sep 17 00:00:00 2001
135360
From: Mihai Varga <mihai.varga@collabora.com>
135360
Date: Fri, 13 Nov 2015 09:48:14 +0200
135360
Subject: [PATCH 317/398] LOK: calc formula callback + formula bar
135360
 implementation in gtk
135360
135360
We need the callback to be able implement the formula bar
135360
135360
Change-Id: I1c78ab0b9ed9304c0465a9993a7101f8efb91052
135360
135360
Conflicts:
135360
	include/LibreOfficeKit/LibreOfficeKitEnums.h
135360
	libreofficekit/source/gtk/lokdocview.cxx
135360
(cherry picked from commit 5b1e22e9ba941305a7f138adcef75a464161a145)
135360
---
135360
 include/LibreOfficeKit/LibreOfficeKitEnums.h       |  7 +++++-
135360
 .../qa/gtktiledviewer/gtktiledviewer.cxx           | 24 +++++++++++++++++++++
135360
 libreofficekit/source/gtk/lokdocview.cxx           | 25 ++++++++++++++++++++++
135360
 sc/source/ui/app/inputhdl.cxx                      |  8 +++++++
135360
 4 files changed, 63 insertions(+), 1 deletion(-)
135360
135360
diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
135360
index 37837ea49b86..7b23fcbab1c3 100644
135360
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
135360
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
135360
@@ -209,7 +209,12 @@ typedef enum
135360
      *
135360
      * Payload is a css mouse pointer style.
135360
      */
135360
-    LOK_CALLBACK_MOUSE_POINTER
135360
+    LOK_CALLBACK_MOUSE_POINTER,
135360
+
135360
+    /**
135360
+     * The text content of the formula bar in Calc.
135360
+     */
135360
+    LOK_CALLBACK_CELL_FORMULA
135360
 }
135360
 LibreOfficeKitCallbackType;
135360
 
135360
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
index c96ba95e7d99..cd5b23c12bc4 100644
135360
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
@@ -101,6 +101,7 @@ public:
135360
     GtkToolItem* m_pCenterpara;
135360
     GtkToolItem* m_pRightpara;
135360
     GtkToolItem* m_pJustifypara;
135360
+    GtkWidget* m_pFormulabarEntry;
135360
     GtkWidget* m_pScrolledWindow;
135360
     std::map<GtkToolItem*, std::string> m_aToolItemCommandNames;
135360
     std::map<std::string, GtkToolItem*> m_aCommandNameToolItems;
135360
@@ -135,6 +136,7 @@ public:
135360
         m_pCenterpara(nullptr),
135360
         m_pRightpara(nullptr),
135360
         m_pJustifypara(nullptr),
135360
+        m_pFormulabarEntry(nullptr),
135360
         m_pScrolledWindow(nullptr),
135360
         m_bToolItemBroadcast(true),
135360
         m_pVBox(nullptr),
135360
@@ -631,6 +633,14 @@ static gboolean signalFindbar(GtkWidget* pWidget, GdkEventKey* pEvent, gpointer
135360
     return FALSE;
135360
 }
135360
 
135360
+/// Handles the key-press-event of the formula entry widget.
135360
+static gboolean signalFormulabar(GtkWidget* /*pWidget*/, GdkEventKey* /*pEvent*/, gpointer /*pData*/)
135360
+{
135360
+    // for now it just displays the callback
135360
+    // TODO - submit the edited formula
135360
+    return TRUE;
135360
+}
135360
+
135360
 /// LOKDocView changed edit state -> inform the tool button.
135360
 static void signalEdit(LOKDocView* pLOKDocView, gboolean bWasEdit, gpointer /*pData*/)
135360
 {
135360
@@ -767,6 +777,13 @@ static void cursorChanged(LOKDocView* pDocView, gint nX, gint nY,
135360
         gtk_adjustment_set_value(hadj, lok_doc_view_twip_to_pixel(LOK_DOC_VIEW(pDocView), x));
135360
 }
135360
 
135360
+/// LOKDocView the formula has changed
135360
+static void formulaChanged(LOKDocView* pLOKDocView, char* pPayload, gpointer /*pData*/)
135360
+{
135360
+    TiledWindow& rWindow = lcl_getTiledWindow(GTK_WIDGET(pLOKDocView));
135360
+    gtk_entry_set_text((GtkEntry*)rWindow.m_pFormulabarEntry, pPayload);
135360
+}
135360
+
135360
 static void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/)
135360
 {
135360
     TiledWindow& rWindow = lcl_getTiledWindow(pWidget);
135360
@@ -1075,6 +1092,12 @@ static GtkWidget* createWindow(TiledWindow& rWindow)
135360
     gtk_toolbar_insert(GTK_TOOLBAR(pLowerToolbar), rWindow.m_pJustifypara, -1);
135360
     g_signal_connect(G_OBJECT(rWindow.m_pJustifypara), "toggled", G_CALLBACK(toggleToolItem), NULL);
135360
     lcl_registerToolItem(rWindow, rWindow.m_pJustifypara, ".uno:JustifyPara");
135360
+    // Formula bar
135360
+    GtkToolItem* pFormulaEntryContainer = gtk_tool_item_new();
135360
+    rWindow.m_pFormulabarEntry = gtk_entry_new();
135360
+    gtk_container_add(GTK_CONTAINER(pFormulaEntryContainer), rWindow.m_pFormulabarEntry);
135360
+    g_signal_connect(rWindow.m_pFormulabarEntry, "key-press-event", G_CALLBACK(signalFormulabar), 0);
135360
+    gtk_toolbar_insert(GTK_TOOLBAR(pLowerToolbar), pFormulaEntryContainer, -1);
135360
     gtk_box_pack_start(GTK_BOX(rWindow.m_pVBox), pLowerToolbar, FALSE, FALSE, 0 ); // Adds to top.
135360
 
135360
     // Findbar
135360
@@ -1188,6 +1211,7 @@ static void setupDocView(GtkWidget* pDocView)
135360
     g_signal_connect(pDocView, "size-changed", G_CALLBACK(signalSize), NULL);
135360
     g_signal_connect(pDocView, "hyperlink-clicked", G_CALLBACK(signalHyperlink), NULL);
135360
     g_signal_connect(pDocView, "cursor-changed", G_CALLBACK(cursorChanged), NULL);
135360
+    g_signal_connect(pDocView, "formula-changed", G_CALLBACK(formulaChanged), NULL);
135360
 }
135360
 
135360
 int main( int argc, char* argv[] )
135360
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
135360
index db71f80e39c8..9d852351262e 100644
135360
--- a/libreofficekit/source/gtk/lokdocview.cxx
135360
+++ b/libreofficekit/source/gtk/lokdocview.cxx
135360
@@ -184,6 +184,7 @@ enum
135360
     CURSOR_CHANGED,
135360
     SEARCH_RESULT_COUNT,
135360
     COMMAND_RESULT,
135360
+    FORMULA_CHANGED,
135360
 
135360
     LAST_SIGNAL
135360
 };
135360
@@ -495,6 +496,11 @@ static void commandResult(LOKDocView* pDocView, const std::string& rString)
135360
     g_signal_emit(pDocView, doc_view_signals[COMMAND_RESULT], 0, rString.c_str());
135360
 }
135360
 
135360
+static void formulaChanged(LOKDocView* pDocView, const std::string& rString)
135360
+{
135360
+    g_signal_emit(pDocView, doc_view_signals[FORMULA_CHANGED], 0, rString.c_str());
135360
+}
135360
+
135360
 static void
135360
 setPart(LOKDocView* pDocView, const std::string& rString)
135360
 {
135360
@@ -809,6 +815,11 @@ callback (gpointer pData)
135360
         commandResult(pDocView, pCallback->m_aPayload);
135360
     }
135360
     break;
135360
+    case LOK_CALLBACK_CELL_FORMULA:
135360
+    {
135360
+        formulaChanged(pDocView, pCallback->m_aPayload);
135360
+    }
135360
+    break;
135360
     default:
135360
         g_assert(false);
135360
         break;
135360
@@ -2248,6 +2259,20 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
135360
                      G_TYPE_NONE, 1,
135360
                      G_TYPE_STRING);
135360
 
135360
+    /**
135360
+     * LOKDocView::formula-changed:
135360
+     * @pDocView: the #LOKDocView on which the signal is emitted
135360
+     * @aCommand: formula text content
135360
+     */
135360
+    doc_view_signals[FORMULA_CHANGED] =
135360
+        g_signal_new("formula-changed",
135360
+                     G_TYPE_FROM_CLASS(pGObjectClass),
135360
+                     G_SIGNAL_RUN_FIRST,
135360
+                     0,
135360
+                     NULL, NULL,
135360
+                     g_cclosure_marshal_VOID__STRING,
135360
+                     G_TYPE_NONE, 1,
135360
+                     G_TYPE_STRING);
135360
 }
135360
 
135360
 SAL_DLLPUBLIC_EXPORT GtkWidget*
135360
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
135360
index 09bc73d336cd..c656ca75b9b7 100644
135360
--- a/sc/source/ui/app/inputhdl.cxx
135360
+++ b/sc/source/ui/app/inputhdl.cxx
135360
@@ -52,6 +52,7 @@
135360
 #include <tools/urlobj.hxx>
135360
 #include <comphelper/string.hxx>
135360
 #include <formula/formulahelper.hxx>
135360
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
135360
 
135360
 #include "inputwin.hxx"
135360
 #include "tabvwsh.hxx"
135360
@@ -2139,6 +2140,11 @@ void ScInputHandler::DataChanged( bool bFromTopNotify, bool bSetModified )
135360
 
135360
         if ( pInputWin )
135360
             pInputWin->SetTextString( aText );
135360
+
135360
+        ScDocShell* pDocSh = pActiveViewSh->GetViewData().GetDocShell();
135360
+        ScDocument& rDoc = pDocSh->GetDocument();
135360
+        if ( rDoc.GetDrawLayer()->isTiledRendering() )
135360
+            rDoc.GetDrawLayer()->libreOfficeKitCallback(LOK_CALLBACK_CELL_FORMULA, aText.toUtf8().getStr());
135360
     }
135360
 
135360
     // If the cursor is before the end of a paragraph, parts are being pushed to
135360
@@ -3475,6 +3481,8 @@ void ScInputHandler::NotifyChange( const ScInputHdlState* pState,
135360
 
135360
                         if ( pInputWin )
135360
                             pInputWin->SetTextString(aString);
135360
+                        else if ( rDoc.GetDrawLayer()->isTiledRendering() )
135360
+                            rDoc.GetDrawLayer()->libreOfficeKitCallback(LOK_CALLBACK_CELL_FORMULA, aString.toUtf8().getStr());
135360
                     }
135360
 
135360
                     if ( pInputWin )                        // Named range input
135360
-- 
135360
2.12.0
135360