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

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