Blob Blame History Raw
From d57909684dd464e1e7b8616ac1cbd43a8f5817c2 Mon Sep 17 00:00:00 2001
From: Mihai Varga <mihai.varga@collabora.com>
Date: Fri, 13 Nov 2015 09:48:14 +0200
Subject: [PATCH 317/398] LOK: calc formula callback + formula bar
 implementation in gtk

We need the callback to be able implement the formula bar

Change-Id: I1c78ab0b9ed9304c0465a9993a7101f8efb91052

Conflicts:
	include/LibreOfficeKit/LibreOfficeKitEnums.h
	libreofficekit/source/gtk/lokdocview.cxx
(cherry picked from commit 5b1e22e9ba941305a7f138adcef75a464161a145)
---
 include/LibreOfficeKit/LibreOfficeKitEnums.h       |  7 +++++-
 .../qa/gtktiledviewer/gtktiledviewer.cxx           | 24 +++++++++++++++++++++
 libreofficekit/source/gtk/lokdocview.cxx           | 25 ++++++++++++++++++++++
 sc/source/ui/app/inputhdl.cxx                      |  8 +++++++
 4 files changed, 63 insertions(+), 1 deletion(-)

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