Kaydet (Commit) 18c052d6 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

LOKit: add "destroy" and "saveAs" to android JNI

Change-Id: I08542b736e49cb9262323e9fe6188b1976d47935
üst 67ad72f5
...@@ -24,6 +24,8 @@ public class Document { ...@@ -24,6 +24,8 @@ public class Document {
this.handle = handle; this.handle = handle;
} }
public native void destroy();
public native int getPart(); public native int getPart();
public native void setPart(int partIndex); public native void setPart(int partIndex);
...@@ -40,6 +42,8 @@ public class Document { ...@@ -40,6 +42,8 @@ public class Document {
private native int getDocumentTypeNative(); private native int getDocumentTypeNative();
private native void saveAs(String url, String format, String options);
private native void paintTileNative(ByteBuffer buffer, int canvasWidth, int canvasHeight, int tilePositionX, int tilePositionY, int tileWidth, int tileHeight); private native void paintTileNative(ByteBuffer buffer, int canvasWidth, int canvasHeight, int tilePositionX, int tilePositionY, int tileWidth, int tileHeight);
public int getDocumentType() { public int getDocumentType() {
......
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
package org.libreoffice.kit; package org.libreoffice.kit;
import android.util.Log;
public class Office { public class Office {
private long handle; private long handle;
...@@ -31,4 +29,6 @@ public class Office { ...@@ -31,4 +29,6 @@ public class Office {
} }
return document; return document;
} }
public native void destroy();
} }
...@@ -41,6 +41,17 @@ void setHandle(JNIEnv* pEnv, jobject aObject, T* aType) ...@@ -41,6 +41,17 @@ void setHandle(JNIEnv* pEnv, jobject aObject, T* aType)
pEnv->SetLongField(aObject, getHandleField(pEnv, aObject), aHandle); pEnv->SetLongField(aObject, getHandleField(pEnv, aObject), aHandle);
} }
const char* copyJavaString(JNIEnv* pEnv, jstring aJavaString)
{
const char* pClone = NULL;
const char* pTemp = pEnv->GetStringUTFChars(aJavaString, NULL);
pClone = strdup(pTemp);
pEnv->ReleaseStringUTFChars(aJavaString, pTemp);
return pClone;
}
extern "C" SAL_JNI_EXPORT jstring JNICALL Java_org_libreoffice_kit_Office_getError(JNIEnv* pEnv, jobject aObject) extern "C" SAL_JNI_EXPORT jstring JNICALL Java_org_libreoffice_kit_Office_getError(JNIEnv* pEnv, jobject aObject)
{ {
LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject); LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject);
...@@ -53,21 +64,29 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_initializ ...@@ -53,21 +64,29 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_initializ
pEnv->SetLongField(aObject, getHandleField(pEnv, aObject), aLokHandle); pEnv->SetLongField(aObject, getHandleField(pEnv, aObject), aLokHandle);
} }
extern "C" SAL_JNI_EXPORT jlong JNICALL Java_org_libreoffice_kit_Office_documentLoadNative(JNIEnv* pEnv, jobject aObject, jstring documentPath) extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_destroy(JNIEnv* pEnv, jobject aObject)
{ {
const char* aCloneDocumentPath; LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject);
pLibreOfficeKit->pClass->destroy(pLibreOfficeKit);
const char* aCharDocumentPath = pEnv->GetStringUTFChars(documentPath, NULL); }
aCloneDocumentPath = strdup(aCharDocumentPath);
pEnv->ReleaseStringUTFChars(documentPath, aCharDocumentPath);
extern "C" SAL_JNI_EXPORT jlong JNICALL Java_org_libreoffice_kit_Office_documentLoadNative(JNIEnv* pEnv, jobject aObject, jstring documentPath)
{
const char* aCloneDocumentPath = copyJavaString(pEnv, documentPath);
LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject); LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject);
LibreOfficeKitDocument* pDocument = pLibreOfficeKit->pClass->documentLoad(pLibreOfficeKit, aCloneDocumentPath); LibreOfficeKitDocument* pDocument = pLibreOfficeKit->pClass->documentLoad(pLibreOfficeKit, aCloneDocumentPath);
return (jlong) (intptr_t) pDocument; return (jlong) pDocument;
} }
/* Document */ /* Document */
extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_destroy
(JNIEnv* pEnv, jobject aObject)
{
LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
pDocument->pClass->destroy(pDocument);
}
extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_setPart extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_setPart
(JNIEnv* pEnv, jobject aObject, jint aPart) (JNIEnv* pEnv, jobject aObject, jint aPart)
{ {
...@@ -145,4 +164,21 @@ extern "C" SAL_JNI_EXPORT jlong JNICALL Java_org_libreoffice_kit_Document_getDoc ...@@ -145,4 +164,21 @@ extern "C" SAL_JNI_EXPORT jlong JNICALL Java_org_libreoffice_kit_Document_getDoc
return nWidth; return nWidth;
} }
extern "C" SAL_JNI_EXPORT jint JNICALL Java_org_libreoffice_kit_Office_saveAs(JNIEnv* pEnv, jobject aObject, jstring sUrl, jstring sFormat, jstring sOptions)
{
LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
const char* pUrl = pEnv->GetStringUTFChars(sUrl, NULL);
const char* pFormat = pEnv->GetStringUTFChars(sFormat, NULL);
const char* pOptions = pEnv->GetStringUTFChars(sOptions, NULL);
int result = pDocument->pClass->saveAs(pDocument, pUrl, pFormat, pOptions);
pEnv->ReleaseStringUTFChars(sUrl, pUrl);
pEnv->ReleaseStringUTFChars(sFormat, pFormat);
pEnv->ReleaseStringUTFChars(sOptions, pOptions);
return result;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment