[Libreoffice-commits] core.git: Branch 'feature/tiled-editing' - 2 commits - desktop/source include/LibreOfficeKit libreofficekit/qa libreofficekit/source

Miklos Vajna vmiklos at collabora.co.uk
Tue Jan 20 01:22:47 PST 2015


 desktop/source/lib/init.cxx                         |   24 ++++++++++++++++++++
 include/LibreOfficeKit/LibreOfficeKit.h             |   12 ++++++++++
 include/LibreOfficeKit/LibreOfficeKit.hxx           |   12 ++++++++++
 libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx |    9 -------
 libreofficekit/source/gtk/lokdocview.c              |   24 ++++++++++++++++++--
 5 files changed, 70 insertions(+), 11 deletions(-)

New commits:
commit a28584efe460813f43d552498825622b6907f976
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Jan 20 10:20:24 2015 +0100

    gtktiledviewer: call postMouseEvent()
    
    Again, no unit conversion yet.
    
    Change-Id: I261febd875bac5a729f449e42558b5af9d7a359b

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 085e3e3..ea5a273 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -160,14 +160,6 @@ static void signalKey(GtkWidget* /*pWidget*/, GdkEventKey* pEvent, gpointer /*pD
         pLOKDocView->pOffice->pClass->postKeyEvent(pLOKDocView->pOffice, LOK_KEYEVENT_KEYINPUT, nCode);
 }
 
-/// Receives a button press event.
-static void signalButton(GtkWidget* /*pWidget*/, GdkEvent* /*pEvent*/, gpointer /*pData*/)
-{
-    LOKDocView* pLOKDocView = LOK_DOCVIEW(pDocView);
-
-    lok_docview_set_edit(pLOKDocView, TRUE);
-}
-
 // GtkComboBox requires gtk 2.24 or later
 #if ( GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 24 ) || GTK_MAJOR_VERSION > 2
 void populatePartSelector()
@@ -325,7 +317,6 @@ int main( int argc, char* argv[] )
     // Input handling.
     g_signal_connect(pWindow, "key-press-event", G_CALLBACK(signalKey), NULL);
     g_signal_connect(pWindow, "key-release-event", G_CALLBACK(signalKey), NULL);
-    g_signal_connect(pDocView, "button-press-event", G_CALLBACK(signalButton), NULL);
 
     gtk_container_add( GTK_CONTAINER(pVBox), pDocView );
 
diff --git a/libreofficekit/source/gtk/lokdocview.c b/libreofficekit/source/gtk/lokdocview.c
index b335d8b..bf8dd71 100644
--- a/libreofficekit/source/gtk/lokdocview.c
+++ b/libreofficekit/source/gtk/lokdocview.c
@@ -33,6 +33,26 @@ void lcl_onDestroy( LOKDocView* pDocView, gpointer pData )
     pDocView->pDocument = NULL;
 }
 
+/// Receives a button press event.
+void lcl_signalButton(GtkWidget* pEventBox, GdkEventButton* pEvent, LOKDocView* pDocView)
+{
+    (void) pEventBox;
+
+    lok_docview_set_edit(pDocView, TRUE);
+
+    switch (pEvent->type)
+    {
+    case GDK_BUTTON_PRESS:
+        pDocView->pOffice->pClass->postMouseEvent(pDocView->pOffice, LOK_MOUSEEVENT_MOUSEBUTTONDOWN, pEvent->x, pEvent->y);
+        break;
+    case GDK_BUTTON_RELEASE:
+        pDocView->pOffice->pClass->postMouseEvent(pDocView->pOffice, LOK_MOUSEEVENT_MOUSEBUTTONUP, pEvent->x, pEvent->y);
+        break;
+    default:
+        break;
+    }
+}
+
 SAL_DLLPUBLIC_EXPORT guint lok_docview_get_type()
 {
     static guint lok_docview_type = 0;
@@ -73,8 +93,8 @@ static void lok_docview_init( LOKDocView* pDocView )
     gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(pDocView),
                                            pDocView->pEventBox );
 
-    // Allow reacting to button press events.
-    gtk_widget_set_events(pDocView->pEventBox, GDK_BUTTON_PRESS_MASK);
+    gtk_signal_connect(GTK_OBJECT(pDocView->pEventBox), "button-press-event", GTK_SIGNAL_FUNC(lcl_signalButton), pDocView);
+    gtk_signal_connect(GTK_OBJECT(pDocView->pEventBox), "button-release-event", GTK_SIGNAL_FUNC(lcl_signalButton), pDocView);
 
     gtk_widget_show( pDocView->pEventBox );
 
commit cdabb94b3e4de2978a999ffda1e7cb0aa62454da
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Jan 20 10:17:03 2015 +0100

    Add initial lok::Office::postMouseEvent()
    
    There is no unit conversion yet, most probably we want to work with doc
    model coordinates at an API level, while VCL works with pixel
    coordinates.
    
    Change-Id: I98848851fbec5253e76c997844f6339402dfac46

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 14c1860..e8f98aa 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -253,6 +253,7 @@ static int                     lo_initialize    (LibreOfficeKit* pThis, const ch
 static LibreOfficeKitDocument* lo_documentLoad  (LibreOfficeKit* pThis, const char* pURL);
 static char *                  lo_getError      (LibreOfficeKit* pThis);
 static void                    lo_postKeyEvent  (LibreOfficeKit* pThis, int nType, int nCode);
+static void                    lo_postMouseEvent (LibreOfficeKit* pThis, int nType, int nX, int nY);
 
 
 struct LibLibreOffice_Impl : public _LibreOfficeKit
@@ -272,6 +273,7 @@ struct LibLibreOffice_Impl : public _LibreOfficeKit
             m_pOfficeClass->documentLoad = lo_documentLoad;
             m_pOfficeClass->getError = lo_getError;
             m_pOfficeClass->postKeyEvent = lo_postKeyEvent;
+            m_pOfficeClass->postMouseEvent = lo_postMouseEvent;
 
             gOfficeClass = m_pOfficeClass;
         }
@@ -670,6 +672,28 @@ static void lo_postKeyEvent(LibreOfficeKit* /*pThis*/, int nType, int nCode)
 #endif
 }
 
+static void lo_postMouseEvent(LibreOfficeKit* /*pThis*/, int nType, int nX, int nY)
+{
+#if defined(UNX) && !defined(MACOSX) && !defined(ENABLE_HEADLESS)
+    if (SalFrame *pFocus = SvpSalFrame::GetFocusFrame())
+    {
+        MouseEvent aEvent = MouseEvent(Point(nX, nY), 1, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT);
+        switch (nType)
+        {
+        case LOK_MOUSEEVENT_MOUSEBUTTONDOWN:
+            Application::PostMouseEvent(VCLEVENT_WINDOW_MOUSEBUTTONDOWN, pFocus->GetWindow(), &aEvent);
+            break;
+        case LOK_MOUSEEVENT_MOUSEBUTTONUP:
+            Application::PostMouseEvent(VCLEVENT_WINDOW_MOUSEBUTTONUP, pFocus->GetWindow(), &aEvent);
+            break;
+        default:
+            assert(false);
+            break;
+        }
+    }
+#endif
+}
+
 static void force_c_locale(void)
 {
     // force locale (and resource files loaded) to en-US
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index c5909ef..397d435 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -73,6 +73,17 @@ typedef enum
 }
 LibreOfficeKitKeyEventType;
 
+typedef enum
+{
+    /// A pressed gesture has started.
+    LOK_MOUSEEVENT_MOUSEBUTTONDOWN,
+    /// A pressed gesture has finished.
+    LOK_MOUSEEVENT_MOUSEBUTTONUP,
+    /// A change has happened during a press gesture.
+    LOK_MOUSEEVENT_MOUSEMOVE
+}
+LibreOfficeKitMouseEventType;
+
 typedef void (*LibreOfficeKitCallback)(int nType, const char* pPayload, void* pData);
 #endif // LOK_USE_UNSTABLE_API
 
@@ -89,6 +100,7 @@ struct _LibreOfficeKitClass
   LibreOfficeKitDocument* (*documentLoad)  (LibreOfficeKit* pThis, const char* pURL);
   char*                   (*getError)      (LibreOfficeKit* pThis);
   void                    (*postKeyEvent)  (LibreOfficeKit* pThis, int nType, int nCode);
+  void                    (*postMouseEvent)(LibreOfficeKit* pThis, int nType, int nX, int nY);
 };
 
 #define LIBREOFFICEKIT_DOCUMENT_HAS(pDoc,member) LIBREOFFICEKIT_HAS_MEMBER(LibreOfficeKitDocumentClass,member,(pDoc)->pClass->nSize)
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index fdc025b..bd3ce55 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -146,6 +146,18 @@ public:
     {
         mpThis->pClass->postKeyEvent(mpThis, nType, nCode);
     }
+
+    /**
+     * Posts a mouse event to the focused frame.
+     *
+     * @param nType Event type, like down, move or up.
+     * @param nX horizontal position
+     * @param nY vertical position
+     */
+    inline void postMouseEvent(int nType, int nX, int nY)
+    {
+        mpThis->pClass->postMouseEvent(mpThis, nType, nX, nY);
+    }
 };
 
 inline Office* lok_cpp_init(const char* pInstallPath)


More information about the Libreoffice-commits mailing list