15#include <android/log.h>
17#include <osl/detail/android-bootstrap.h>
19#include <LibreOfficeKit/LibreOfficeKit.h>
26jfieldID getHandleField(JNIEnv* pEnv, jobject aObject)
28 jclass clazz = pEnv->GetObjectClass(aObject);
29 return pEnv->GetFieldID(clazz,
"handle",
"Ljava/nio/ByteBuffer;");
33T* getHandle(JNIEnv* pEnv, jobject aObject)
35 jobject aHandle = pEnv->GetObjectField(aObject, getHandleField(pEnv, aObject));
36 return reinterpret_cast<T*
>(pEnv->GetDirectBufferAddress(aHandle));
39const char* copyJavaString(JNIEnv* pEnv, jstring aJavaString)
41 const char* pTemp = pEnv->GetStringUTFChars(aJavaString, NULL);
42 const char* pClone = strdup(pTemp);
43 pEnv->ReleaseStringUTFChars(aJavaString, pTemp);
51 (JNIEnv* pEnv, jobject aObject)
53 LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject);
54 char* pError = pLibreOfficeKit->pClass->getError(pLibreOfficeKit);
55 return pEnv->NewStringUTF(pError);
59 (JNIEnv* pEnv, jobject aObject)
61 LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject);
62 pLibreOfficeKit->pClass->destroy(pLibreOfficeKit);
67 LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject);
68 pLibreOfficeKit->pClass->destroy(pLibreOfficeKit);
79 jmethodID aJavaCallbackMethod;
84static CallbackData gCallbackData;
85static CallbackData gCallbackDataLOKit;
90void messageCallback(
int nType,
const char* pPayload,
void* pData)
92 CallbackData* pCallbackData = (CallbackData*) pData;
94 JavaVM* pJavaVM = lo_get_javavm();
96 bool bIsAttached =
false;
98 int status = pJavaVM->GetEnv((
void **) &pEnv, JNI_VERSION_1_6);
102 status = pJavaVM->AttachCurrentThread(&pEnv, NULL);
110 jstring sPayload = pEnv->NewStringUTF(pPayload);
112 jvalue aParameter[2];
113 aParameter[0].i =
nType;
114 aParameter[1].l = sPayload;
116 pEnv->CallVoidMethodA(pCallbackData->aObject, pCallbackData->aJavaCallbackMethod, aParameter);
118 pEnv->DeleteLocalRef(sPayload);
122 pJavaVM->DetachCurrentThread();
129 (JNIEnv* pEnv, jobject aObject, jstring documentPath)
131 const char* aCloneDocumentPath = copyJavaString(pEnv, documentPath);
132 LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject);
134 LibreOfficeKitDocument* pDocument = pLibreOfficeKit->pClass->documentLoad(pLibreOfficeKit, aCloneDocumentPath);
136 if (pDocument ==
NULL)
139 jobject aHandle = pEnv->NewDirectByteBuffer((
void*) pDocument,
sizeof(LibreOfficeKitDocument));
145 (JNIEnv* pEnv, jobject aObject, jstring sUrl, jstring sPassword)
147 LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject);
149 char const* pUrl = copyJavaString(pEnv, sUrl);
150 if (sPassword ==
NULL) {
151 pLibreOfficeKit->pClass->setDocumentPassword(pLibreOfficeKit, pUrl,
nullptr);
153 char const* pPassword = copyJavaString(pEnv, sPassword);
154 pLibreOfficeKit->pClass->setDocumentPassword(pLibreOfficeKit, pUrl, pPassword);
159 (JNIEnv* pEnv, jobject aObject, jlong options)
161 LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject);
163 unsigned long long pOptions = (
unsigned long long)options;
165 pLibreOfficeKit->pClass->setOptionalFeatures(pLibreOfficeKit, pOptions);
170 (JNIEnv* pEnv, jobject aObject)
172 LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject);
174 gCallbackDataLOKit.aObject = (jobject) pEnv->NewGlobalRef(aObject);
175 jclass aClass = pEnv->GetObjectClass(aObject);
176 gCallbackDataLOKit.aClass = (jclass) pEnv->NewGlobalRef(aClass);
178 gCallbackDataLOKit.aJavaCallbackMethod = pEnv->GetMethodID(aClass,
"messageRetrievedLOKit",
"(ILjava/lang/String;)V");
180 pLibreOfficeKit->pClass->registerCallback(pLibreOfficeKit, messageCallback, (
void*) &gCallbackDataLOKit);
187 (JNIEnv* pEnv, jobject aObject)
189 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
191 gCallbackData.aObject = (jobject) pEnv->NewGlobalRef(aObject);
192 jclass aClass = pEnv->GetObjectClass(aObject);
193 gCallbackData.aClass = (jclass) pEnv->NewGlobalRef(aClass);
195 gCallbackData.aJavaCallbackMethod = pEnv->GetMethodID(aClass,
"messageRetrieved",
"(ILjava/lang/String;)V");
197 pDocument->pClass->registerCallback(pDocument, messageCallback, (
void*) &gCallbackData);
201 (JNIEnv* pEnv, jobject aObject)
203 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
204 pDocument->pClass->destroy(pDocument);
208 (JNIEnv* pEnv, jobject aObject, jint aPart)
210 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
211 pDocument->pClass->setPart(pDocument, aPart);
215 (JNIEnv* pEnv, jobject aObject)
217 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
218 return (jint) pDocument->pClass->getPart(pDocument);
222 (JNIEnv* pEnv, jobject aObject)
224 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
225 char* pRectangles = pDocument->pClass->getPartPageRectangles(pDocument);
226 return pEnv->NewStringUTF(pRectangles);
230 (JNIEnv* pEnv, jobject aObject)
232 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
233 return (jint) pDocument->pClass->getParts(pDocument);
237 (JNIEnv* pEnv, jobject aObject, jint nPartIndex)
239 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
240 char* pPartName = pDocument->pClass->getPartName(pDocument, nPartIndex);
241 return pEnv->NewStringUTF(pPartName);
245 (JNIEnv* pEnv, jobject aObject, jint nPartMode)
247 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
249 pDocument->pClass->setPartMode(pDocument, nPartMode);
253 (JNIEnv* pEnv, jobject aObject)
255 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
256 return (jint) pDocument->pClass->getDocumentType(pDocument);
260 (JNIEnv* pEnv, jobject aObject, jobject aByteBuffer,
261 jint nCanvasWidth, jint nCanvasHeight, jint nTilePosX, jint nTilePosY,
262 jint nTileWidth, jint nTileHeight)
264 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
266 unsigned char* buffer = (
unsigned char*) pEnv->GetDirectBufferAddress(aByteBuffer);
267 pDocument->pClass->paintTile(pDocument, buffer, nCanvasWidth, nCanvasHeight, nTilePosX, nTilePosY, nTileWidth, nTileHeight);
271 (JNIEnv* pEnv, jobject aObject)
273 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
276 pDocument->pClass->getDocumentSize(pDocument, &nWidth, &nHeight);
281 (JNIEnv* pEnv, jobject aObject)
283 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
286 pDocument->pClass->getDocumentSize(pDocument, &nWidth, &nHeight);
291 (JNIEnv* pEnv, jobject aObject)
293 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
294 pDocument->pClass->initializeForRendering(pDocument,
NULL);
298 (JNIEnv* pEnv, jobject aObject, jstring sUrl, jstring sFormat, jstring sOptions)
300 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
302 const char* pUrl = pEnv->GetStringUTFChars(sUrl,
NULL);
303 const char* pFormat = pEnv->GetStringUTFChars(sFormat,
NULL);
304 const char* pOptions = pEnv->GetStringUTFChars(sOptions,
NULL);
306 int result = pDocument->pClass->saveAs(pDocument, pUrl, pFormat, pOptions);
308 pEnv->ReleaseStringUTFChars(sUrl, pUrl);
309 pEnv->ReleaseStringUTFChars(sFormat, pFormat);
310 pEnv->ReleaseStringUTFChars(sOptions, pOptions);
316 (JNIEnv* pEnv, jobject aObject, jint nType, jint nCharCode, jint nKeyCode)
318 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
319 pDocument->pClass->postKeyEvent(pDocument,
nType, nCharCode, nKeyCode);
323 (JNIEnv* pEnv, jobject aObject, jint type, jint x, jint y, jint count, jint button, jint modifier)
325 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
326 pDocument->pClass->postMouseEvent(pDocument,
type,
x,
y,
count, button, modifier);
330 (JNIEnv* pEnv, jobject aObject, jstring command, jstring arguments, jboolean bNotifyWhenFinished)
332 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
334 const char* pCommand = pEnv->GetStringUTFChars(command,
NULL);
335 const char* pArguments =
nullptr;
336 if (arguments !=
NULL)
337 pArguments = pEnv->GetStringUTFChars(arguments,
NULL);
339 pDocument->pClass->postUnoCommand(pDocument, pCommand, pArguments, bNotifyWhenFinished);
341 pEnv->ReleaseStringUTFChars(command, pCommand);
342 if (arguments !=
NULL)
343 pEnv->ReleaseStringUTFChars(arguments, pArguments);
347 (JNIEnv* pEnv, jobject aObject, jint type, jint x, jint y)
349 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
350 pDocument->pClass->setTextSelection(pDocument,
type,
x,
y);
354 (JNIEnv* pEnv, jobject aObject, jstring mimeType)
356 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
358 const char* pMimeType = pEnv->GetStringUTFChars(mimeType,
NULL);
360 char* pUsedMimeType = 0;
361 LibreOfficeKitDocumentClass* pcls = pDocument->pClass;
362 char* pSelection = pcls->getTextSelection(pDocument, pMimeType, &pUsedMimeType);
365 pEnv->ReleaseStringUTFChars(mimeType, pMimeType);
367 return pEnv->NewStringUTF(pSelection);
371 (JNIEnv* pEnv, jobject aObject, jstring mimeType, jstring data)
373 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
375 const char* pMimeType = pEnv->GetStringUTFChars(mimeType,
NULL);
376 const char*
pData = pEnv->GetStringUTFChars(data,
NULL);
377 const size_t nSize = pEnv->GetStringLength(data);
379 LibreOfficeKitDocumentClass* pcls = pDocument->pClass;
380 bool result = pcls->paste(pDocument, pMimeType,
pData, nSize);
381 pEnv->ReleaseStringUTFChars(mimeType, pMimeType);
382 pEnv->ReleaseStringUTFChars(data,
pData);
388 (JNIEnv* pEnv, jobject aObject, jint type, jint x, jint y)
390 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
391 pDocument->pClass->setGraphicSelection(pDocument,
type,
x,
y);
395 (JNIEnv* pEnv, jobject aObject)
397 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
398 pDocument->pClass->resetSelection(pDocument);
402 (JNIEnv* pEnv, jobject aObject, jstring command)
404 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
406 const char* pCommand = pEnv->GetStringUTFChars(command,
NULL);
408 char* pValue = pDocument->pClass->getCommandValues(pDocument, pCommand);
410 pEnv->ReleaseStringUTFChars(command, pCommand);
412 return pEnv->NewStringUTF(pValue);
416 (JNIEnv* pEnv, jobject aObject, jint nTilePixelWidth, jint nTilePixelHeight, jint nTileTwipWidth, jint nTileTwipHeight)
418 LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
419 pDocument->pClass->setClientZoom(pDocument, nTilePixelWidth, nTilePixelHeight, nTileTwipWidth, nTileTwipHeight);
SAL_JNI_EXPORT jstring JNICALL Java_org_libreoffice_kit_Document_getTextSelection(JNIEnv *pEnv, jobject aObject, jstring mimeType)
SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_destroyAndExit(JNIEnv *pEnv, jobject aObject)
SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_bindMessageCallback(JNIEnv *pEnv, jobject aObject)
Implementation of org.libreoffice.kit.Document.bindMessageCallback method.
SAL_JNI_EXPORT jint JNICALL Java_org_libreoffice_kit_Document_getParts(JNIEnv *pEnv, jobject aObject)
SAL_JNI_EXPORT jobject JNICALL Java_org_libreoffice_kit_Office_documentLoadNative(JNIEnv *pEnv, jobject aObject, jstring documentPath)
SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_setOptionalFeatures(JNIEnv *pEnv, jobject aObject, jlong options)
SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_destroy(JNIEnv *pEnv, jobject aObject)
SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_postUnoCommand(JNIEnv *pEnv, jobject aObject, jstring command, jstring arguments, jboolean bNotifyWhenFinished)
SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_setClientZoom(JNIEnv *pEnv, jobject aObject, jint nTilePixelWidth, jint nTilePixelHeight, jint nTileTwipWidth, jint nTileTwipHeight)
SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_postMouseEvent(JNIEnv *pEnv, jobject aObject, jint type, jint x, jint y, jint count, jint button, jint modifier)
SAL_JNI_EXPORT jint JNICALL Java_org_libreoffice_kit_Document_getDocumentTypeNative(JNIEnv *pEnv, jobject aObject)
SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_destroy(JNIEnv *pEnv, jobject aObject)
SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_resetSelection(JNIEnv *pEnv, jobject aObject)
SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_initializeForRendering(JNIEnv *pEnv, jobject aObject)
SAL_JNI_EXPORT jlong JNICALL Java_org_libreoffice_kit_Document_getDocumentWidth(JNIEnv *pEnv, jobject aObject)
SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_setGraphicSelection(JNIEnv *pEnv, jobject aObject, jint type, jint x, jint y)
SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_paintTileNative(JNIEnv *pEnv, jobject aObject, jobject aByteBuffer, jint nCanvasWidth, jint nCanvasHeight, jint nTilePosX, jint nTilePosY, jint nTileWidth, jint nTileHeight)
SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_setDocumentPassword(JNIEnv *pEnv, jobject aObject, jstring sUrl, jstring sPassword)
SAL_JNI_EXPORT jlong JNICALL Java_org_libreoffice_kit_Document_getDocumentHeight(JNIEnv *pEnv, jobject aObject)
SAL_JNI_EXPORT jint JNICALL Java_org_libreoffice_kit_Document_getPart(JNIEnv *pEnv, jobject aObject)
SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_postKeyEvent(JNIEnv *pEnv, jobject aObject, jint nType, jint nCharCode, jint nKeyCode)
SAL_JNI_EXPORT jstring JNICALL Java_org_libreoffice_kit_Office_getError(JNIEnv *pEnv, jobject aObject)
SAL_JNI_EXPORT jint JNICALL Java_org_libreoffice_kit_Document_saveAs(JNIEnv *pEnv, jobject aObject, jstring sUrl, jstring sFormat, jstring sOptions)
SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_bindMessageCallback(JNIEnv *pEnv, jobject aObject)
Implementation of org.libreoffice.kit.Office.bindMessageCallback method.
SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_setTextSelection(JNIEnv *pEnv, jobject aObject, jint type, jint x, jint y)
SAL_JNI_EXPORT jboolean JNICALL Java_org_libreoffice_kit_Document_paste(JNIEnv *pEnv, jobject aObject, jstring mimeType, jstring data)
SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_setPart(JNIEnv *pEnv, jobject aObject, jint aPart)
SAL_JNI_EXPORT jstring JNICALL Java_org_libreoffice_kit_Document_getPartName(JNIEnv *pEnv, jobject aObject, jint nPartIndex)
SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_setPartMode(JNIEnv *pEnv, jobject aObject, jint nPartMode)
SAL_JNI_EXPORT jstring JNICALL Java_org_libreoffice_kit_Document_getCommandValues(JNIEnv *pEnv, jobject aObject, jstring command)
SAL_JNI_EXPORT jstring JNICALL Java_org_libreoffice_kit_Document_getPartPageRectangles(JNIEnv *pEnv, jobject aObject)
std::unique_ptr< sal_Int32[]> pData