[Libreoffice-commits] core.git: Branch 'feature/tiled-editing' - 3 commits - android/Bootstrap desktop/source include/LibreOfficeKit sal/android

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Wed Jan 7 03:00:05 PST 2015


 android/Bootstrap/src/org/libreoffice/kit/Document.java |   16 +++
 desktop/source/lib/lokandroid.cxx                       |   69 ++++++++++++++++
 include/LibreOfficeKit/LibreOfficeKit.h                 |   28 ++++--
 sal/android/lo-bootstrap.c                              |    2 
 4 files changed, 104 insertions(+), 11 deletions(-)

New commits:
commit 1c4ba83a395dd105620c104a29cabdcc84675aad
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Wed Jan 7 19:37:53 2015 +0900

    android: Add support for callbacks from LO to JNI and Java LOK
    
    This adds support to retrieve callbacks from LibreOffice (like
    for example that a part of document has been invalidated) to
    LibreOfficeKit JNI and Java wrappers.
    
    Change-Id: Ib70187194d002c72b64d58032aab216adc591565

diff --git a/android/Bootstrap/src/org/libreoffice/kit/Document.java b/android/Bootstrap/src/org/libreoffice/kit/Document.java
index e415d8f..6985a7c 100644
--- a/android/Bootstrap/src/org/libreoffice/kit/Document.java
+++ b/android/Bootstrap/src/org/libreoffice/kit/Document.java
@@ -9,6 +9,8 @@
 
 package org.libreoffice.kit;
 
+import android.util.Log;
+
 import java.nio.ByteBuffer;
 
 public class Document {
@@ -28,8 +30,22 @@ public class Document {
 
     public Document(ByteBuffer handle) {
         this.handle = handle;
+        bindMessageCallback();
+    }
+
+    /**
+     * Callback triggered through JNI to indicate that a new singal
+     * from LibreOfficeKit was retrieved.
+     */
+    private void messageRetrieved(int signalNumber, String payload) {
+        Log.i("Document", "Signal retrieved: " + signalNumber + " " + payload);
     }
 
+    /**
+     * Bind the signal callback in LOK.
+     */
+    private native void bindMessageCallback();
+
     public native void destroy();
 
     public native int getPart();
diff --git a/desktop/source/lib/lokandroid.cxx b/desktop/source/lib/lokandroid.cxx
index 2b18071..06da8a9 100644
--- a/desktop/source/lib/lokandroid.cxx
+++ b/desktop/source/lib/lokandroid.cxx
@@ -22,6 +22,9 @@
 
 /* LibreOfficeKit */
 
+namespace
+{
+
 jfieldID getHandleField(JNIEnv* pEnv, jobject aObject)
 {
     jclass clazz = pEnv->GetObjectClass(aObject);
@@ -46,6 +49,8 @@ const char* copyJavaString(JNIEnv* pEnv, jstring aJavaString)
     return pClone;
 }
 
+} // anonymous namespace
+
 extern "C" SAL_JNI_EXPORT jstring JNICALL Java_org_libreoffice_kit_Office_getError(JNIEnv* pEnv, jobject aObject)
 {
     LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject);
@@ -68,6 +73,55 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_destroyAn
     _exit(0);
 }
 
+namespace
+{
+
+struct CallbackData
+{
+    jmethodID aJavaCallbackMethod;
+    jclass aClass;
+    jobject aObject;
+};
+
+static CallbackData gCallbackData;
+
+/**
+ * Handle retrieved callback
+ */
+void messageCallback(int nType, const char* pPayload, void* pData)
+{
+    CallbackData* pCallbackData = (CallbackData*) pData;
+
+    JavaVM* pJavaVM = lo_get_javavm();
+    JNIEnv* pEnv;
+    bool bIsAttached = false;
+
+    int status = pJavaVM->GetEnv((void **) &pEnv, JNI_VERSION_1_6);
+
+    if(status < 0)
+    {
+        status = pJavaVM->AttachCurrentThread(&pEnv, NULL);
+        if(status < 0)
+        {
+            return;
+        }
+        bIsAttached = true;
+    }
+
+    jvalue aParameter[2];
+    aParameter[0].i = nType;
+    aParameter[1].l = pEnv->NewStringUTF(pPayload);
+
+    pEnv->CallVoidMethodA(pCallbackData->aObject, pCallbackData->aJavaCallbackMethod, aParameter);
+
+    if (bIsAttached)
+    {
+        pJavaVM->DetachCurrentThread();
+    }
+}
+
+} // anonymous namespace
+
 extern "C" SAL_JNI_EXPORT jobject JNICALL Java_org_libreoffice_kit_Office_documentLoadNative(JNIEnv* pEnv, jobject aObject, jstring documentPath)
 {
     const char* aCloneDocumentPath = copyJavaString(pEnv, documentPath);
@@ -81,6 +135,21 @@ extern "C" SAL_JNI_EXPORT jobject JNICALL Java_org_libreoffice_kit_Office_docume
 
 /* Document */
 
+/** Implementation of org.libreoffice.kit.Document.bindMessageCallback method */
+extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_bindMessageCallback
+    (JNIEnv* pEnv, jobject aObject)
+{
+    LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
+
+    gCallbackData.aObject = (jobject) pEnv->NewGlobalRef(aObject);
+    jclass aClass = pEnv->GetObjectClass(aObject);
+    gCallbackData.aClass = (jclass) pEnv->NewGlobalRef(aClass);
+
+    gCallbackData.aJavaCallbackMethod = pEnv->GetMethodID(aClass, "messageRetrieved", "(ILjava/lang/String;)V");
+
+    pDocument->pClass->registerCallback(pDocument, messageCallback, (void*) &gCallbackData);
+}
+
 extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_destroy
     (JNIEnv* pEnv, jobject aObject)
 {
commit 66f0c3a135977e487ab62a1148ab56cdf8c72331
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Wed Jan 7 19:05:05 2015 +0900

    android: No reason to return JNI version less than Java 6
    
    Change-Id: Id9fae6561268bb7e5a465c19bdb80124f94f4939

diff --git a/sal/android/lo-bootstrap.c b/sal/android/lo-bootstrap.c
index 2d2f01a..4d318e8 100644
--- a/sal/android/lo-bootstrap.c
+++ b/sal/android/lo-bootstrap.c
@@ -247,7 +247,7 @@ JNI_OnLoad(JavaVM* vm, void* reserved)
 
     the_java_vm = vm;
 
-    return JNI_VERSION_1_2;
+    return JNI_VERSION_1_6;
 }
 
 // public static native boolean setup(String dataDir,
commit 1e5cdbef8d62c5b15d5bbfb9f019c86668b72143
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Wed Jan 7 19:02:16 2015 +0900

    lok: Add comments to some methods, put the star where it belongs
    
    Change-Id: I751eb175f29489637f465c9d97ebe920372f38bf

diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index a4addb8..573e44d 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -76,9 +76,9 @@ struct _LibreOfficeKitClass
 {
   size_t  nSize;
 
-  void                    (*destroy)       (LibreOfficeKit *pThis);
-  LibreOfficeKitDocument* (*documentLoad)  (LibreOfficeKit *pThis, const char *pURL);
-  char*                   (*getError)      (LibreOfficeKit *pThis);
+  void                    (*destroy)       (LibreOfficeKit* pThis);
+  LibreOfficeKitDocument* (*documentLoad)  (LibreOfficeKit* pThis, const char* pURL);
+  char*                   (*getError)      (LibreOfficeKit* pThis);
 };
 
 #define LIBREOFFICEKIT_DOCUMENT_HAS(pDoc,member) LIBREOFFICEKIT_HAS_MEMBER(LibreOfficeKitDocumentClass,member,(pDoc)->pClass->nSize)
@@ -94,16 +94,20 @@ struct _LibreOfficeKitDocumentClass
 
   void (*destroy)   (LibreOfficeKitDocument* pThis);
   int (*saveAs)     (LibreOfficeKitDocument* pThis,
-                     const char *pUrl,
-                     const char *pFormat,
-                     const char *pFilterOptions);
+                     const char* pUrl,
+                     const char* pFormat,
+                     const char* pFilterOptions);
 #ifdef LOK_USE_UNSTABLE_API
   LibreOfficeKitDocumentType (*getDocumentType) (LibreOfficeKitDocument* pThis);
 
-  // Part refers to either indivual sheets in a Spreadsheet, or slides
-  // in a Slideshow, and has no relevance for writer documents.
+  /** Get number of part that the document contains.
+   * Part refers to either indivual sheets in a Spreadsheet,
+   * or slides in a Slideshow, and has no relevance for
+   * writer documents.
+   */
   int (*getParts) (LibreOfficeKitDocument* pThis);
 
+  /** Get current part of the document */
   int (*getPart)          (LibreOfficeKitDocument* pThis);
   void (*setPart)         (LibreOfficeKitDocument* pThis,
                            int nPart);
@@ -124,12 +128,16 @@ struct _LibreOfficeKitDocumentClass
                            const int nTileWidth,
                            const int nTileHeight);
 
-  // Get the document sizes in twips.
+  /** Get the document sizes in twips. */
   void (*getDocumentSize) (LibreOfficeKitDocument* pThis,
                            long* pWidth,
                            long* pHeight);
 
-  // Initialize document for rendering.
+  /** Initialize document for rendering.
+   * Sets the rendering and document parameters to default values
+   * that are needed to render the document correctly using
+   * tiled rendering.
+   */
   void (*initializeForRendering) (LibreOfficeKitDocument* pThis);
 
   void (*registerCallback)   (LibreOfficeKitDocument* pThis,


More information about the Libreoffice-commits mailing list