2013-03-05 16:40:01 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2013-03-05 13:16:36 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
2013-08-16 11:08:32 +03:00
|
|
|
#include <config_folders.h>
|
|
|
|
|
2013-03-05 13:16:36 +00:00
|
|
|
#include <stdio.h>
|
2013-07-26 18:21:45 +01:00
|
|
|
#include <string.h>
|
2013-07-26 19:15:41 +01:00
|
|
|
#include <stdlib.h>
|
2013-07-26 18:21:45 +01:00
|
|
|
|
2015-09-17 09:21:43 +01:00
|
|
|
#include <memory>
|
2015-04-22 14:28:36 +02:00
|
|
|
#include <boost/property_tree/json_parser.hpp>
|
2014-06-17 15:13:33 +01:00
|
|
|
|
2014-05-09 14:37:27 +01:00
|
|
|
#define LOK_USE_UNSTABLE_API
|
2014-06-09 11:33:25 +01:00
|
|
|
#include <LibreOfficeKit/LibreOfficeKit.h>
|
2015-02-20 16:21:06 +01:00
|
|
|
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
|
2013-03-05 13:16:36 +00:00
|
|
|
|
2015-04-22 09:42:28 +02:00
|
|
|
#include <sal/log.hxx>
|
2013-03-05 13:16:36 +00:00
|
|
|
#include <tools/errinf.hxx>
|
|
|
|
#include <osl/file.hxx>
|
2013-03-05 14:29:26 +00:00
|
|
|
#include <osl/process.h>
|
2015-03-11 10:31:14 +01:00
|
|
|
#include <osl/thread.h>
|
2013-03-05 13:16:36 +00:00
|
|
|
#include <rtl/bootstrap.hxx>
|
2015-07-06 15:16:56 +02:00
|
|
|
#include <rtl/strbuf.hxx>
|
|
|
|
#include <rtl/uri.hxx>
|
2013-03-05 13:16:36 +00:00
|
|
|
#include <cppuhelper/bootstrap.hxx>
|
2015-03-12 14:59:59 +01:00
|
|
|
#include <comphelper/dispatchcommand.hxx>
|
2015-04-02 13:22:04 +03:00
|
|
|
#include <comphelper/lok.hxx>
|
2013-03-05 13:16:36 +00:00
|
|
|
#include <comphelper/processfactory.hxx>
|
|
|
|
|
2013-03-05 14:29:26 +00:00
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
2015-08-17 18:49:40 +03:00
|
|
|
#include <com/sun/star/container/XNameAccess.hpp>
|
2013-03-05 14:29:26 +00:00
|
|
|
#include <com/sun/star/frame/Desktop.hpp>
|
2013-07-26 18:21:45 +01:00
|
|
|
#include <com/sun/star/frame/XStorable.hpp>
|
2013-03-05 13:16:36 +00:00
|
|
|
#include <com/sun/star/lang/Locale.hpp>
|
|
|
|
#include <com/sun/star/lang/XComponent.hpp>
|
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
2015-08-17 18:49:40 +03:00
|
|
|
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
|
2013-03-05 13:16:36 +00:00
|
|
|
#include <com/sun/star/ucb/XContentProvider.hpp>
|
|
|
|
#include <com/sun/star/ucb/XUniversalContentBroker.hpp>
|
2015-09-14 20:14:34 -04:00
|
|
|
#include <com/sun/star/util/URLTransformer.hpp>
|
2013-03-05 13:16:36 +00:00
|
|
|
|
2015-09-10 11:31:48 +03:00
|
|
|
#include <editeng/fontitem.hxx>
|
|
|
|
#include <editeng/flstitem.hxx>
|
|
|
|
#include <sfx2/objsh.hxx>
|
2015-09-14 20:14:34 -04:00
|
|
|
#include <sfx2/viewsh.hxx>
|
|
|
|
#include <sfx2/viewfrm.hxx>
|
|
|
|
#include <sfx2/msgpool.hxx>
|
|
|
|
#include <sfx2/dispatch.hxx>
|
2015-09-14 14:36:56 +02:00
|
|
|
#include <sfx2/lokhelper.hxx>
|
2015-09-17 15:39:19 +02:00
|
|
|
#include <sfx2/viewfrm.hxx>
|
|
|
|
#include <sfx2/viewsh.hxx>
|
2015-09-10 11:31:48 +03:00
|
|
|
#include <svx/svxids.hrc>
|
2013-03-05 13:16:36 +00:00
|
|
|
#include <vcl/svapp.hxx>
|
2015-03-20 12:36:09 +02:00
|
|
|
#include <vcl/svpforlokit.hxx>
|
2013-03-05 13:16:36 +00:00
|
|
|
#include <tools/resmgr.hxx>
|
2014-11-13 21:47:20 +01:00
|
|
|
#include <tools/fract.hxx>
|
2015-09-10 11:31:48 +03:00
|
|
|
#include <svtools/ctrltool.hxx>
|
2013-03-05 13:16:36 +00:00
|
|
|
#include <vcl/graphicfilter.hxx>
|
2014-05-09 14:37:27 +01:00
|
|
|
#include <vcl/sysdata.hxx>
|
|
|
|
#include <vcl/virdev.hxx>
|
2014-06-13 17:32:44 +01:00
|
|
|
#include <vcl/ITiledRenderable.hxx>
|
2013-03-05 13:16:36 +00:00
|
|
|
#include <unotools/syslocaleoptions.hxx>
|
2014-04-05 21:48:47 +02:00
|
|
|
#include <unotools/mediadescriptor.hxx>
|
2014-06-17 19:57:25 +01:00
|
|
|
#include <osl/module.hxx>
|
2015-04-22 14:28:36 +02:00
|
|
|
#include <comphelper/sequence.hxx>
|
2013-03-05 13:16:36 +00:00
|
|
|
|
2014-12-10 12:31:15 +01:00
|
|
|
#include <app.hxx>
|
2014-05-23 20:00:58 +01:00
|
|
|
|
2014-12-10 12:31:15 +01:00
|
|
|
#include "../app/cmdlineargs.hxx"
|
|
|
|
// We also need to hackily be able to start the main libreoffice thread:
|
2014-07-26 16:06:04 +02:00
|
|
|
#include "../app/sofficemain.h"
|
2014-07-18 10:02:48 +02:00
|
|
|
#include "../app/officeipcthread.hxx"
|
2015-09-09 15:08:26 +03:00
|
|
|
#include "../../inc/lib/init.hxx"
|
2014-07-26 16:06:04 +02:00
|
|
|
|
2015-09-11 18:46:53 +02:00
|
|
|
#include "lokinteractionhandler.hxx"
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
using namespace css;
|
2014-08-13 09:10:08 +02:00
|
|
|
using namespace vcl;
|
2014-07-18 10:02:48 +02:00
|
|
|
using namespace desktop;
|
2014-04-05 21:48:47 +02:00
|
|
|
using namespace utl;
|
2013-03-05 13:16:36 +00:00
|
|
|
|
2013-07-26 18:21:45 +01:00
|
|
|
static LibLibreOffice_Impl *gImpl = NULL;
|
2015-09-17 09:21:43 +01:00
|
|
|
static std::weak_ptr< LibreOfficeKitClass > gOfficeClass;
|
|
|
|
static std::weak_ptr< LibreOfficeKitDocumentClass > gDocumentClass;
|
2013-07-26 18:21:45 +01:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2013-07-29 18:09:37 +01:00
|
|
|
const char *extn;
|
|
|
|
const char *filterName;
|
|
|
|
} ExtensionMap;
|
|
|
|
|
2014-06-11 16:24:33 +01:00
|
|
|
// We need a shared_array for passing into the BitmapDevice (via
|
|
|
|
// VirtualDevice.SetOutputSizePixelScaleOffsetAndBuffer which goes via the
|
|
|
|
// SvpVirtualDevice, ending up in the basebmp BitmapDevice. However as we're
|
|
|
|
// given the array externally we can't delete it, and hence need to override
|
|
|
|
// shared_array's default of deleting its pointer.
|
|
|
|
template<typename T>
|
|
|
|
struct NoDelete
|
|
|
|
{
|
|
|
|
void operator()(T* /* p */) {}
|
|
|
|
};
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
static const ExtensionMap aWriterExtensionMap[] =
|
|
|
|
{
|
2013-07-29 18:09:37 +01:00
|
|
|
{ "doc", "MS Word 97" },
|
|
|
|
{ "docx", "MS Word 2007 XML" },
|
|
|
|
{ "fodt", "OpenDocument Text Flat XML" },
|
|
|
|
{ "html", "HTML (StarWriter)" },
|
|
|
|
{ "odt", "writer8" },
|
|
|
|
{ "ott", "writer8_template" },
|
|
|
|
{ "pdf", "writer_pdf_Export" },
|
|
|
|
{ "txt", "Text" },
|
|
|
|
{ "xhtml", "XHTML Writer File" },
|
2015-10-20 17:13:30 +02:00
|
|
|
{ "png", "writer_png_Export" },
|
2013-07-29 18:09:37 +01:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
static const ExtensionMap aCalcExtensionMap[] =
|
|
|
|
{
|
2013-07-29 18:09:37 +01:00
|
|
|
{ "csv", "Text - txt - csv (StarCalc)" },
|
|
|
|
{ "fods", "OpenDocument Spreadsheet Flat XML" },
|
|
|
|
{ "html", "HTML (StarCalc)" },
|
|
|
|
{ "ods", "calc8" },
|
|
|
|
{ "ots", "calc8_template" },
|
|
|
|
{ "pdf", "calc_pdf_Export" },
|
|
|
|
{ "xhtml", "XHTML Calc File" },
|
|
|
|
{ "xls", "MS Excel 97" },
|
|
|
|
{ "xlsx", "Calc MS Excel 2007 XML" },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
static const ExtensionMap aImpressExtensionMap[] =
|
|
|
|
{
|
2013-07-29 18:09:37 +01:00
|
|
|
{ "fodp", "OpenDocument Presentation Flat XML" },
|
|
|
|
{ "html", "impress_html_Export" },
|
|
|
|
{ "odg", "impress8_draw" },
|
|
|
|
{ "odp", "impress8" },
|
|
|
|
{ "otp", "impress8_template" },
|
|
|
|
{ "pdf", "impress_pdf_Export" },
|
|
|
|
{ "potm", "Impress MS PowerPoint 2007 XML Template" },
|
|
|
|
{ "pot", "MS PowerPoint 97 Vorlage" },
|
|
|
|
{ "pptx", "Impress MS PowerPoint 2007 XML" },
|
|
|
|
{ "pps", "MS PowerPoint 97 Autoplay" },
|
|
|
|
{ "ppt", "MS PowerPoint 97" },
|
|
|
|
{ "svg", "impress_svg_Export" },
|
|
|
|
{ "swf", "impress_flash_Export" },
|
|
|
|
{ "xhtml", "XHTML Impress File" },
|
2015-10-20 17:13:30 +02:00
|
|
|
{ "png", "impress_png_Export"},
|
2013-07-29 18:09:37 +01:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2014-04-28 17:36:30 +02:00
|
|
|
static const ExtensionMap aDrawExtensionMap[] =
|
|
|
|
{
|
|
|
|
{ "fodg", "draw_ODG_FlatXML" },
|
|
|
|
{ "html", "draw_html_Export" },
|
2014-11-06 21:00:02 +01:00
|
|
|
{ "odg", "draw8" },
|
|
|
|
{ "pdf", "draw_pdf_Export" },
|
2014-04-28 17:36:30 +02:00
|
|
|
{ "svg", "draw_svg_Export" },
|
|
|
|
{ "swf", "draw_flash_Export" },
|
|
|
|
{ "xhtml", "XHTML Draw File" },
|
2015-10-20 17:13:30 +02:00
|
|
|
{ "png", "draw_png_Export"},
|
2014-04-28 17:36:30 +02:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
static OUString getUString(const char* pString)
|
2013-11-15 18:00:05 +02:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
if (pString == NULL)
|
|
|
|
return OUString();
|
|
|
|
|
2014-11-06 17:24:13 +01:00
|
|
|
OString sString(pString, strlen(pString));
|
|
|
|
return OStringToOUString(sString, RTL_TEXTENCODING_UTF8);
|
2013-11-15 18:00:05 +02:00
|
|
|
}
|
|
|
|
|
2015-07-03 18:14:31 +02:00
|
|
|
/// Try to convert a relative URL to an absolute one, unless it already looks like an URL.
|
2014-04-05 21:48:47 +02:00
|
|
|
static OUString getAbsoluteURL(const char* pURL)
|
2013-11-15 18:00:05 +02:00
|
|
|
{
|
2015-07-03 18:14:31 +02:00
|
|
|
OUString aURL(getUString(pURL));
|
2015-07-06 15:16:56 +02:00
|
|
|
if (aURL.isEmpty())
|
2015-07-03 18:14:31 +02:00
|
|
|
return aURL;
|
|
|
|
|
|
|
|
// convert relative paths to absolute ones
|
2015-07-06 15:16:56 +02:00
|
|
|
OUString aWorkingDir;
|
|
|
|
osl_getProcessWorkingDir(&aWorkingDir.pData);
|
2015-07-07 08:40:28 +02:00
|
|
|
if (!aWorkingDir.endsWith("/"))
|
|
|
|
aWorkingDir += "/";
|
2013-11-15 18:00:05 +02:00
|
|
|
|
2015-07-06 15:16:56 +02:00
|
|
|
try {
|
2015-07-07 08:40:28 +02:00
|
|
|
return rtl::Uri::convertRelToAbs(aWorkingDir, aURL);
|
2015-07-06 15:16:56 +02:00
|
|
|
}
|
|
|
|
catch (const rtl::MalformedUriException &)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
return OUString();
|
2013-11-15 18:00:05 +02:00
|
|
|
}
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
extern "C"
|
|
|
|
{
|
2013-11-15 12:09:10 +00:00
|
|
|
|
2014-06-10 11:31:51 +01:00
|
|
|
static void doc_destroy(LibreOfficeKitDocument* pThis);
|
2014-06-17 19:33:34 +01:00
|
|
|
static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* pUrl, const char* pFormat, const char* pFilterOptions);
|
2015-02-20 16:21:06 +01:00
|
|
|
static int doc_getDocumentType(LibreOfficeKitDocument* pThis);
|
2014-07-08 15:23:06 +02:00
|
|
|
static int doc_getParts(LibreOfficeKitDocument* pThis);
|
2015-09-29 10:47:31 +02:00
|
|
|
static char* doc_getPartPageRectangles(LibreOfficeKitDocument* pThis);
|
2014-07-08 15:23:06 +02:00
|
|
|
static int doc_getPart(LibreOfficeKitDocument* pThis);
|
2014-05-09 14:37:27 +01:00
|
|
|
static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart);
|
2014-07-29 08:50:34 +02:00
|
|
|
static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart);
|
2015-02-20 16:21:06 +01:00
|
|
|
static void doc_setPartMode(LibreOfficeKitDocument* pThis, int nPartMode);
|
2014-06-11 16:24:33 +01:00
|
|
|
void doc_paintTile(LibreOfficeKitDocument* pThis,
|
|
|
|
unsigned char* pBuffer,
|
2014-05-09 14:37:27 +01:00
|
|
|
const int nCanvasWidth, const int nCanvasHeight,
|
|
|
|
const int nTilePosX, const int nTilePosY,
|
|
|
|
const int nTileWidth, const int nTileHeight);
|
2014-06-11 16:24:33 +01:00
|
|
|
static void doc_getDocumentSize(LibreOfficeKitDocument* pThis,
|
2014-05-18 08:36:16 +01:00
|
|
|
long* pWidth,
|
|
|
|
long* pHeight);
|
2014-12-29 16:10:48 +09:00
|
|
|
static void doc_initializeForRendering(LibreOfficeKitDocument* pThis);
|
|
|
|
|
2015-01-06 15:49:12 +01:00
|
|
|
static void doc_registerCallback(LibreOfficeKitDocument* pThis,
|
|
|
|
LibreOfficeKitCallback pCallback,
|
|
|
|
void* pData);
|
2015-02-27 15:38:30 +01:00
|
|
|
static void doc_postKeyEvent(LibreOfficeKitDocument* pThis,
|
|
|
|
int nType,
|
|
|
|
int nCharCode,
|
|
|
|
int nKeyCode);
|
2015-01-21 12:42:08 +01:00
|
|
|
static void doc_postMouseEvent (LibreOfficeKitDocument* pThis,
|
|
|
|
int nType,
|
|
|
|
int nX,
|
2015-02-05 14:19:35 +01:00
|
|
|
int nY,
|
2015-10-04 19:40:13 +03:00
|
|
|
int nCount,
|
|
|
|
int nButtons,
|
|
|
|
int nModifier);
|
2015-03-12 14:59:59 +01:00
|
|
|
static void doc_postUnoCommand(LibreOfficeKitDocument* pThis,
|
2015-04-22 14:28:36 +02:00
|
|
|
const char* pCommand,
|
|
|
|
const char* pArguments);
|
2015-02-10 17:43:18 +01:00
|
|
|
static void doc_setTextSelection (LibreOfficeKitDocument* pThis,
|
|
|
|
int nType,
|
|
|
|
int nX,
|
|
|
|
int nY);
|
2015-06-17 18:00:01 +02:00
|
|
|
static char* doc_getTextSelection(LibreOfficeKitDocument* pThis,
|
2015-06-19 18:13:27 +02:00
|
|
|
const char* pMimeType,
|
|
|
|
char** pUsedMimeType);
|
2015-03-10 09:40:38 +01:00
|
|
|
static void doc_setGraphicSelection (LibreOfficeKitDocument* pThis,
|
|
|
|
int nType,
|
|
|
|
int nX,
|
|
|
|
int nY);
|
2015-03-10 16:13:53 +01:00
|
|
|
static void doc_resetSelection (LibreOfficeKitDocument* pThis);
|
2015-09-10 09:21:45 +03:00
|
|
|
static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand);
|
2013-07-29 18:09:37 +01:00
|
|
|
|
2015-09-14 14:36:56 +02:00
|
|
|
static int doc_createView(LibreOfficeKitDocument* pThis);
|
2015-09-15 09:31:49 +02:00
|
|
|
static void doc_destroyView(LibreOfficeKitDocument* pThis, int nId);
|
2015-09-16 09:30:41 +02:00
|
|
|
static void doc_setView(LibreOfficeKitDocument* pThis, int nId);
|
|
|
|
static int doc_getView(LibreOfficeKitDocument* pThis);
|
2015-09-16 14:14:04 +02:00
|
|
|
static int doc_getViews(LibreOfficeKitDocument* pThis);
|
2013-11-15 12:09:10 +00:00
|
|
|
|
2015-09-09 15:08:26 +03:00
|
|
|
LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent) :
|
|
|
|
mxComponent( xComponent )
|
|
|
|
{
|
|
|
|
if (!(m_pDocumentClass = gDocumentClass.lock()))
|
2013-11-15 12:09:10 +00:00
|
|
|
{
|
2015-09-09 15:08:26 +03:00
|
|
|
m_pDocumentClass.reset(new LibreOfficeKitDocumentClass);
|
|
|
|
|
|
|
|
m_pDocumentClass->nSize = sizeof(LibreOfficeKitDocument);
|
|
|
|
|
|
|
|
m_pDocumentClass->destroy = doc_destroy;
|
|
|
|
m_pDocumentClass->saveAs = doc_saveAs;
|
|
|
|
m_pDocumentClass->getDocumentType = doc_getDocumentType;
|
|
|
|
m_pDocumentClass->getParts = doc_getParts;
|
2015-09-29 10:47:31 +02:00
|
|
|
m_pDocumentClass->getPartPageRectangles = doc_getPartPageRectangles;
|
2015-09-09 15:08:26 +03:00
|
|
|
m_pDocumentClass->getPart = doc_getPart;
|
|
|
|
m_pDocumentClass->setPart = doc_setPart;
|
|
|
|
m_pDocumentClass->getPartName = doc_getPartName;
|
|
|
|
m_pDocumentClass->setPartMode = doc_setPartMode;
|
|
|
|
m_pDocumentClass->paintTile = doc_paintTile;
|
|
|
|
m_pDocumentClass->getDocumentSize = doc_getDocumentSize;
|
|
|
|
m_pDocumentClass->initializeForRendering = doc_initializeForRendering;
|
|
|
|
m_pDocumentClass->registerCallback = doc_registerCallback;
|
|
|
|
m_pDocumentClass->postKeyEvent = doc_postKeyEvent;
|
|
|
|
m_pDocumentClass->postMouseEvent = doc_postMouseEvent;
|
|
|
|
m_pDocumentClass->postUnoCommand = doc_postUnoCommand;
|
|
|
|
m_pDocumentClass->setTextSelection = doc_setTextSelection;
|
|
|
|
m_pDocumentClass->getTextSelection = doc_getTextSelection;
|
|
|
|
m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection;
|
|
|
|
m_pDocumentClass->resetSelection = doc_resetSelection;
|
2015-09-10 09:21:45 +03:00
|
|
|
m_pDocumentClass->getCommandValues = doc_getCommandValues;
|
2015-09-09 15:08:26 +03:00
|
|
|
|
2015-09-14 14:36:56 +02:00
|
|
|
m_pDocumentClass->createView = doc_createView;
|
2015-09-15 09:31:49 +02:00
|
|
|
m_pDocumentClass->destroyView = doc_destroyView;
|
2015-09-16 09:30:41 +02:00
|
|
|
m_pDocumentClass->setView = doc_setView;
|
|
|
|
m_pDocumentClass->getView = doc_getView;
|
2015-09-16 14:14:04 +02:00
|
|
|
m_pDocumentClass->getViews = doc_getViews;
|
2015-09-14 14:36:56 +02:00
|
|
|
|
2015-09-09 15:08:26 +03:00
|
|
|
gDocumentClass = m_pDocumentClass;
|
2013-11-15 12:09:10 +00:00
|
|
|
}
|
2015-09-09 15:08:26 +03:00
|
|
|
pClass = m_pDocumentClass.get();
|
|
|
|
}
|
2014-05-29 20:27:08 -04:00
|
|
|
|
2015-09-09 15:08:26 +03:00
|
|
|
LibLODocument_Impl::~LibLODocument_Impl()
|
|
|
|
{
|
|
|
|
mxComponent->dispose();
|
|
|
|
}
|
2013-07-26 18:21:45 +01:00
|
|
|
|
2014-06-10 11:31:51 +01:00
|
|
|
static void doc_destroy(LibreOfficeKitDocument *pThis)
|
2013-07-26 18:21:45 +01:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
LibLODocument_Impl *pDocument = static_cast<LibLODocument_Impl*>(pThis);
|
2013-11-15 12:09:10 +00:00
|
|
|
delete pDocument;
|
|
|
|
}
|
2013-07-26 18:21:45 +01:00
|
|
|
|
2014-06-10 11:31:51 +01:00
|
|
|
static void lo_destroy (LibreOfficeKit* pThis);
|
2015-04-08 22:44:29 +03:00
|
|
|
static int lo_initialize (LibreOfficeKit* pThis, const char* pInstallPath, const char* pUserProfilePath);
|
2014-06-10 11:31:51 +01:00
|
|
|
static LibreOfficeKitDocument* lo_documentLoad (LibreOfficeKit* pThis, const char* pURL);
|
|
|
|
static char * lo_getError (LibreOfficeKit* pThis);
|
2015-02-13 12:56:11 +02:00
|
|
|
static LibreOfficeKitDocument* lo_documentLoadWithOptions (LibreOfficeKit* pThis,
|
|
|
|
const char* pURL,
|
|
|
|
const char* pOptions);
|
2015-05-06 16:43:33 +03:00
|
|
|
static void lo_registerCallback (LibreOfficeKit* pThis,
|
|
|
|
LibreOfficeKitCallback pCallback,
|
|
|
|
void* pData);
|
2015-09-25 01:02:23 +02:00
|
|
|
static char* lo_getFilterTypes(LibreOfficeKit* pThis);
|
|
|
|
|
2015-09-25 01:06:31 +02:00
|
|
|
LibLibreOffice_Impl::LibLibreOffice_Impl()
|
|
|
|
: maThread(0)
|
|
|
|
, mpCallback(nullptr)
|
|
|
|
, mpCallbackData(nullptr)
|
2013-11-15 12:09:10 +00:00
|
|
|
{
|
2015-09-25 01:06:31 +02:00
|
|
|
if(!(m_pOfficeClass = gOfficeClass.lock())) {
|
|
|
|
m_pOfficeClass.reset(new LibreOfficeKitClass);
|
|
|
|
m_pOfficeClass->nSize = sizeof(LibreOfficeKitClass);
|
|
|
|
|
|
|
|
m_pOfficeClass->destroy = lo_destroy;
|
|
|
|
m_pOfficeClass->documentLoad = lo_documentLoad;
|
|
|
|
m_pOfficeClass->getError = lo_getError;
|
|
|
|
m_pOfficeClass->documentLoadWithOptions = lo_documentLoadWithOptions;
|
|
|
|
m_pOfficeClass->registerCallback = lo_registerCallback;
|
|
|
|
m_pOfficeClass->getFilterTypes = lo_getFilterTypes;
|
|
|
|
|
|
|
|
gOfficeClass = m_pOfficeClass;
|
2013-11-15 12:09:10 +00:00
|
|
|
}
|
2015-09-25 01:06:31 +02:00
|
|
|
|
|
|
|
pClass = m_pOfficeClass.get();
|
|
|
|
}
|
2013-07-26 18:21:45 +01:00
|
|
|
|
2014-08-13 09:10:08 +02:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
ITiledRenderable* getTiledRenderable(LibreOfficeKitDocument* pThis)
|
|
|
|
{
|
|
|
|
LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
|
|
|
|
return dynamic_cast<ITiledRenderable*>(pDocument->mxComponent.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2013-03-05 13:16:36 +00:00
|
|
|
// Wonder global state ...
|
|
|
|
static uno::Reference<css::uno::XComponentContext> xContext;
|
|
|
|
static uno::Reference<css::lang::XMultiServiceFactory> xSFactory;
|
|
|
|
static uno::Reference<css::lang::XMultiComponentFactory> xFactory;
|
|
|
|
|
2014-06-10 11:31:51 +01:00
|
|
|
static LibreOfficeKitDocument* lo_documentLoad(LibreOfficeKit* pThis, const char* pURL)
|
2015-02-13 12:56:11 +02:00
|
|
|
{
|
|
|
|
return lo_documentLoadWithOptions(pThis, pURL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis, const char* pURL, const char* pOptions)
|
2013-03-05 13:16:36 +00:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
|
2013-11-15 12:09:10 +00:00
|
|
|
|
2014-11-17 10:36:53 +01:00
|
|
|
SolarMutexGuard aGuard;
|
|
|
|
|
2015-07-03 18:14:31 +02:00
|
|
|
OUString aURL(getAbsoluteURL(pURL));
|
2015-07-06 15:16:56 +02:00
|
|
|
if (aURL.isEmpty())
|
|
|
|
{
|
|
|
|
pLib->maLastExceptionMsg = "Filename to load was not provided.";
|
|
|
|
SAL_INFO("lok", "URL for load is empty");
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-03-05 14:29:26 +00:00
|
|
|
|
2014-12-19 09:48:07 +01:00
|
|
|
pLib->maLastExceptionMsg.clear();
|
2014-11-17 10:36:53 +01:00
|
|
|
|
|
|
|
if (!xContext.is())
|
|
|
|
{
|
2015-03-28 14:54:54 +02:00
|
|
|
pLib->maLastExceptionMsg = "ComponentContext is not available";
|
|
|
|
SAL_INFO("lok", "ComponentContext is not available");
|
2014-11-17 10:36:53 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2014-07-31 11:20:00 +02:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
uno::Reference<frame::XDesktop2> xComponentLoader = frame::Desktop::create(xContext);
|
2013-03-05 14:29:26 +00:00
|
|
|
|
2014-11-17 10:36:53 +01:00
|
|
|
if (!xComponentLoader.is())
|
|
|
|
{
|
2015-03-28 14:54:54 +02:00
|
|
|
pLib->maLastExceptionMsg = "ComponentLoader is not available";
|
|
|
|
SAL_INFO("lok", "ComponentLoader is not available");
|
2014-11-17 10:36:53 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
try
|
|
|
|
{
|
2015-09-11 18:46:53 +02:00
|
|
|
uno::Sequence<css::beans::PropertyValue> aFilterOptions(2);
|
2015-02-13 12:56:11 +02:00
|
|
|
aFilterOptions[0] = css::beans::PropertyValue( OUString("FilterOptions"),
|
|
|
|
0,
|
|
|
|
uno::makeAny(OUString::createFromAscii(pOptions)),
|
|
|
|
beans::PropertyState_DIRECT_VALUE);
|
2015-09-11 18:46:53 +02:00
|
|
|
|
|
|
|
uno::Reference<task::XInteractionHandler2> xInteraction(new LOKInteractionHandler(::comphelper::getProcessComponentContext()));
|
|
|
|
aFilterOptions[1].Name = "InteractionHandler";
|
|
|
|
aFilterOptions[1].Value <<= xInteraction;
|
|
|
|
|
|
|
|
/* TODO
|
|
|
|
sal_Int16 nMacroExecMode = document::MacroExecMode::USE_CONFIG;
|
|
|
|
aFilterOptions[2].Name = "MacroExecutionMode";
|
|
|
|
aFilterOptions[2].Value <<= nMacroExecMode;
|
|
|
|
|
|
|
|
sal_Int16 nUpdateDoc = document::UpdateDocMode::ACCORDING_TO_CONFIG;
|
|
|
|
aFilterOptions[3].Name = "UpdateDocMode";
|
|
|
|
aFilterOptions[3].Value <<= nUpdateDoc;
|
|
|
|
*/
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
uno::Reference<lang::XComponent> xComponent;
|
|
|
|
xComponent = xComponentLoader->loadComponentFromURL(
|
|
|
|
aURL, OUString("_blank"), 0,
|
2015-02-13 12:56:11 +02:00
|
|
|
aFilterOptions);
|
2014-04-05 21:48:47 +02:00
|
|
|
|
2014-11-17 10:36:53 +01:00
|
|
|
if (!xComponent.is())
|
|
|
|
{
|
2014-12-10 10:36:55 +01:00
|
|
|
pLib->maLastExceptionMsg = "loadComponentFromURL returned an empty reference";
|
|
|
|
SAL_INFO("lok", "Document can't be loaded - " << pLib->maLastExceptionMsg);
|
2015-02-07 19:57:29 +01:00
|
|
|
return NULL;
|
2014-11-17 10:36:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return new LibLODocument_Impl(xComponent);
|
2014-04-05 21:48:47 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
catch (const uno::Exception& exception)
|
|
|
|
{
|
|
|
|
pLib->maLastExceptionMsg = exception.Message;
|
2014-11-17 10:36:53 +01:00
|
|
|
SAL_INFO("lok", "Document can't be loaded - exception: " << exception.Message);
|
2013-07-26 18:21:45 +01:00
|
|
|
}
|
2014-04-05 21:48:47 +02:00
|
|
|
|
2013-03-05 13:16:36 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-05-06 16:43:33 +03:00
|
|
|
|
|
|
|
static void lo_registerCallback (LibreOfficeKit* pThis,
|
|
|
|
LibreOfficeKitCallback pCallback,
|
|
|
|
void* pData)
|
|
|
|
{
|
|
|
|
LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
|
|
|
|
|
|
|
|
pLib->mpCallback = pCallback;
|
|
|
|
pLib->mpCallbackData = pData;
|
|
|
|
}
|
|
|
|
|
2014-06-17 19:33:34 +01:00
|
|
|
static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const char* pFormat, const char* pFilterOptions)
|
2013-03-05 13:16:36 +00:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
|
2013-07-26 18:21:45 +01:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
OUString sFormat = getUString(pFormat);
|
2015-07-03 18:14:31 +02:00
|
|
|
OUString aURL(getAbsoluteURL(sUrl));
|
2015-07-06 15:16:56 +02:00
|
|
|
if (aURL.isEmpty())
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "Filename to save to was not provided.";
|
|
|
|
SAL_INFO("lok", "URL for save is empty");
|
|
|
|
return false;
|
|
|
|
}
|
2013-11-05 23:34:37 +01:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
try
|
|
|
|
{
|
2014-06-13 15:00:42 +01:00
|
|
|
const ExtensionMap* pMap;
|
2013-07-29 18:09:37 +01:00
|
|
|
|
2014-06-13 15:00:42 +01:00
|
|
|
switch (doc_getDocumentType(pThis))
|
2013-07-29 18:09:37 +01:00
|
|
|
{
|
2014-06-13 15:00:42 +01:00
|
|
|
case LOK_DOCTYPE_SPREADSHEET:
|
2015-06-02 11:26:10 +02:00
|
|
|
pMap = aCalcExtensionMap;
|
2014-06-13 15:00:42 +01:00
|
|
|
break;
|
|
|
|
case LOK_DOCTYPE_PRESENTATION:
|
2015-06-02 11:26:10 +02:00
|
|
|
pMap = aImpressExtensionMap;
|
2014-06-13 15:00:42 +01:00
|
|
|
break;
|
|
|
|
case LOK_DOCTYPE_DRAWING:
|
2015-06-02 11:26:10 +02:00
|
|
|
pMap = aDrawExtensionMap;
|
2014-06-13 15:00:42 +01:00
|
|
|
break;
|
|
|
|
case LOK_DOCTYPE_TEXT:
|
2015-06-02 11:26:10 +02:00
|
|
|
pMap = aWriterExtensionMap;
|
2014-06-13 15:00:42 +01:00
|
|
|
break;
|
|
|
|
case LOK_DOCTYPE_OTHER:
|
2014-06-26 09:07:37 +02:00
|
|
|
default:
|
2014-04-28 17:36:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
2013-07-29 18:09:37 +01:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
if (pFormat == NULL)
|
2013-11-05 23:34:37 +01:00
|
|
|
{
|
|
|
|
// sniff from the extension
|
2014-04-05 21:48:47 +02:00
|
|
|
sal_Int32 idx = aURL.lastIndexOf(".");
|
2013-11-05 23:34:37 +01:00
|
|
|
if( idx > 0 )
|
|
|
|
{
|
2013-11-07 11:37:19 +00:00
|
|
|
sFormat = aURL.copy( idx + 1 );
|
2013-11-05 23:34:37 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "input filename without a suffix";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString aFilterName;
|
2014-04-05 21:48:47 +02:00
|
|
|
for (sal_Int32 i = 0; pMap[i].extn; ++i)
|
2013-07-29 18:09:37 +01:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
if (sFormat.equalsIgnoreAsciiCaseAscii(pMap[i].extn))
|
2013-07-29 18:09:37 +01:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
aFilterName = getUString(pMap[i].filterName);
|
2013-11-05 23:34:37 +01:00
|
|
|
break;
|
2013-07-29 18:09:37 +01:00
|
|
|
}
|
|
|
|
}
|
2014-04-05 21:48:47 +02:00
|
|
|
if (aFilterName.isEmpty())
|
2013-11-05 23:34:37 +01:00
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "no output filter found for provided suffix";
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-29 18:09:37 +01:00
|
|
|
|
2014-04-06 12:17:23 +02:00
|
|
|
OUString aFilterOptions = getUString(pFilterOptions);
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
MediaDescriptor aSaveMediaDescriptor;
|
|
|
|
aSaveMediaDescriptor["Overwrite"] <<= sal_True;
|
|
|
|
aSaveMediaDescriptor["FilterName"] <<= aFilterName;
|
2014-04-06 12:17:23 +02:00
|
|
|
aSaveMediaDescriptor[MediaDescriptor::PROP_FILTEROPTIONS()] <<= aFilterOptions;
|
2013-07-26 18:21:45 +01:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
uno::Reference<frame::XStorable> xStorable(pDocument->mxComponent, uno::UNO_QUERY_THROW);
|
|
|
|
xStorable->storeToURL(aURL, aSaveMediaDescriptor.getAsConstPropertyValueList());
|
2013-07-26 18:21:45 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2014-04-05 21:48:47 +02:00
|
|
|
catch (const uno::Exception& exception)
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "exception: " + exception.Message;
|
|
|
|
}
|
|
|
|
return false;
|
2013-07-26 18:21:45 +01:00
|
|
|
}
|
|
|
|
|
2015-09-14 20:14:34 -04:00
|
|
|
static void doc_iniUnoCommands ()
|
|
|
|
{
|
|
|
|
OUString sUnoCommands[] =
|
|
|
|
{
|
|
|
|
OUString(".uno:Bold"),
|
|
|
|
OUString(".uno:Italic"),
|
|
|
|
OUString(".uno:Underline"),
|
|
|
|
OUString(".uno:Strikeout"),
|
2015-09-15 12:00:25 +02:00
|
|
|
OUString(".uno:DefaultBullet"),
|
|
|
|
OUString(".uno:DefaultNumbering"),
|
2015-09-14 20:14:34 -04:00
|
|
|
OUString(".uno:LeftPara"),
|
|
|
|
OUString(".uno:CenterPara"),
|
|
|
|
OUString(".uno:RightPara"),
|
|
|
|
OUString(".uno:JustifyPara"),
|
|
|
|
OUString(".uno:IncrementIndent"),
|
2015-09-15 12:00:25 +02:00
|
|
|
OUString(".uno:DecrementIndent"),
|
|
|
|
OUString(".uno:CharFontName"),
|
|
|
|
OUString(".uno:FontHeight"),
|
|
|
|
OUString(".uno:StyleApply")
|
2015-09-14 20:14:34 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
util::URL aCommandURL;
|
|
|
|
SfxViewShell* pViewShell = SfxViewShell::Current();
|
2015-09-15 17:04:58 +02:00
|
|
|
SfxViewFrame* pViewFrame = pViewShell? pViewShell->GetViewFrame(): NULL;
|
2015-09-14 20:14:34 -04:00
|
|
|
|
|
|
|
// check if Frame-Controller were created.
|
|
|
|
if (!pViewShell && !pViewFrame)
|
|
|
|
{
|
|
|
|
SAL_WARN("lok", "iniUnoCommands: No Frame-Controller created.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-08 10:27:53 +02:00
|
|
|
if (!xContext.is())
|
|
|
|
xContext = comphelper::getProcessComponentContext();
|
|
|
|
if (!xContext.is())
|
|
|
|
{
|
|
|
|
SAL_WARN("lok", "iniUnoCommands: Component context is not available");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-15 17:04:58 +02:00
|
|
|
SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool(pViewFrame);
|
|
|
|
uno::Reference<util::XURLTransformer> xParser(util::URLTransformer::create(xContext));
|
2015-09-14 20:14:34 -04:00
|
|
|
|
2015-09-15 17:04:58 +02:00
|
|
|
for (sal_uInt32 nIterator = 0; nIterator < SAL_N_ELEMENTS(sUnoCommands); nIterator++)
|
2015-09-14 20:14:34 -04:00
|
|
|
{
|
2015-09-21 15:11:57 +02:00
|
|
|
const SfxSlot* pSlot = NULL;
|
|
|
|
|
2015-09-14 20:14:34 -04:00
|
|
|
aCommandURL.Complete = sUnoCommands[nIterator];
|
|
|
|
xParser->parseStrict(aCommandURL);
|
|
|
|
pSlot = rSlotPool.GetUnoSlot(aCommandURL.Path);
|
|
|
|
|
2015-09-15 17:04:58 +02:00
|
|
|
// when null, this command is not supported by the given component
|
|
|
|
// (like eg. Calc does not have ".uno:DefaultBullet" etc.)
|
|
|
|
if (pSlot)
|
2015-09-14 20:14:34 -04:00
|
|
|
{
|
2015-09-15 17:04:58 +02:00
|
|
|
// Initialize slot to dispatch .uno: Command.
|
|
|
|
pViewFrame->GetBindings().GetDispatch(pSlot, aCommandURL, false);
|
2015-09-14 20:14:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-20 16:21:06 +01:00
|
|
|
static int doc_getDocumentType (LibreOfficeKitDocument* pThis)
|
2014-05-09 14:37:27 +01:00
|
|
|
{
|
2014-06-13 15:00:42 +01:00
|
|
|
LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2014-12-16 14:31:16 +01:00
|
|
|
uno::Reference<lang::XServiceInfo> xDocument(pDocument->mxComponent, uno::UNO_QUERY_THROW);
|
2014-06-13 15:00:42 +01:00
|
|
|
|
2014-12-16 14:31:16 +01:00
|
|
|
if (xDocument->supportsService("com.sun.star.sheet.SpreadsheetDocument"))
|
2014-06-13 15:00:42 +01:00
|
|
|
{
|
|
|
|
return LOK_DOCTYPE_SPREADSHEET;
|
|
|
|
}
|
2014-12-16 14:31:16 +01:00
|
|
|
else if (xDocument->supportsService("com.sun.star.presentation.PresentationDocument"))
|
2014-06-13 15:00:42 +01:00
|
|
|
{
|
|
|
|
return LOK_DOCTYPE_PRESENTATION;
|
|
|
|
}
|
2014-12-16 14:31:16 +01:00
|
|
|
else if (xDocument->supportsService("com.sun.star.drawing.DrawingDocument"))
|
2014-06-13 15:00:42 +01:00
|
|
|
{
|
|
|
|
return LOK_DOCTYPE_DRAWING;
|
|
|
|
}
|
2014-12-16 14:31:16 +01:00
|
|
|
else if (xDocument->supportsService("com.sun.star.text.TextDocument"))
|
2014-06-13 15:00:42 +01:00
|
|
|
{
|
|
|
|
return LOK_DOCTYPE_TEXT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-16 14:31:16 +01:00
|
|
|
gImpl->maLastExceptionMsg = "unknown document type";
|
2014-06-13 15:00:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const uno::Exception& exception)
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "exception: " + exception.Message;
|
|
|
|
}
|
|
|
|
return LOK_DOCTYPE_OTHER;
|
2014-05-09 14:37:27 +01:00
|
|
|
}
|
|
|
|
|
2014-07-08 15:23:06 +02:00
|
|
|
static int doc_getParts (LibreOfficeKitDocument* pThis)
|
2014-05-09 14:37:27 +01:00
|
|
|
{
|
2014-08-13 09:10:08 +02:00
|
|
|
ITiledRenderable* pDoc = getTiledRenderable(pThis);
|
2014-07-08 15:23:06 +02:00
|
|
|
if (!pDoc)
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pDoc->getParts();
|
|
|
|
}
|
|
|
|
|
|
|
|
static int doc_getPart (LibreOfficeKitDocument* pThis)
|
|
|
|
{
|
2014-08-13 09:10:08 +02:00
|
|
|
ITiledRenderable* pDoc = getTiledRenderable(pThis);
|
2014-07-08 15:23:06 +02:00
|
|
|
if (!pDoc)
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pDoc->getPart();
|
2014-05-09 14:37:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart)
|
|
|
|
{
|
2014-08-13 09:10:08 +02:00
|
|
|
ITiledRenderable* pDoc = getTiledRenderable(pThis);
|
2014-07-08 15:23:06 +02:00
|
|
|
if (!pDoc)
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-30 15:16:49 +02:00
|
|
|
SolarMutexGuard aGuard;
|
|
|
|
pDoc->setPart( nPart );
|
2014-05-09 14:37:27 +01:00
|
|
|
}
|
|
|
|
|
2015-09-29 10:47:31 +02:00
|
|
|
static char* doc_getPartPageRectangles(LibreOfficeKitDocument* pThis)
|
|
|
|
{
|
|
|
|
ITiledRenderable* pDoc = getTiledRenderable(pThis);
|
|
|
|
if (!pDoc)
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString sRectangles = pDoc->getPartPageRectangles();
|
|
|
|
OString aString = OUStringToOString(sRectangles, RTL_TEXTENCODING_UTF8);
|
|
|
|
char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1));
|
|
|
|
strcpy(pMemory, aString.getStr());
|
|
|
|
return pMemory;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-07-29 08:50:34 +02:00
|
|
|
static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart)
|
|
|
|
{
|
2014-08-13 09:10:08 +02:00
|
|
|
ITiledRenderable* pDoc = getTiledRenderable(pThis);
|
2014-07-29 08:50:34 +02:00
|
|
|
if (!pDoc)
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString sName = pDoc->getPartName( nPart );
|
|
|
|
OString aString = OUStringToOString(sName, RTL_TEXTENCODING_UTF8);
|
2015-03-28 19:00:39 +01:00
|
|
|
char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1));
|
2014-07-29 08:50:34 +02:00
|
|
|
strcpy(pMemory, aString.getStr());
|
|
|
|
return pMemory;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-07-29 08:59:13 +02:00
|
|
|
static void doc_setPartMode(LibreOfficeKitDocument* pThis,
|
2015-02-20 16:21:06 +01:00
|
|
|
int nPartMode)
|
2014-07-29 08:59:13 +02:00
|
|
|
{
|
2014-08-13 09:10:08 +02:00
|
|
|
ITiledRenderable* pDoc = getTiledRenderable(pThis);
|
2014-07-29 08:59:13 +02:00
|
|
|
if (!pDoc)
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-30 15:16:49 +02:00
|
|
|
SolarMutexGuard aGuard;
|
|
|
|
|
|
|
|
int nCurrentPart = pDoc->getPart();
|
|
|
|
|
2015-02-20 16:21:06 +01:00
|
|
|
pDoc->setPartMode(nPartMode);
|
2014-07-30 15:16:49 +02:00
|
|
|
|
|
|
|
// We need to make sure the internal state is updated, just changing the mode
|
|
|
|
// might not update the relevant shells (i.e. impress will keep rendering the
|
|
|
|
// previous mode unless we do this).
|
|
|
|
// TODO: we might want to do this within the relevant components rather than
|
|
|
|
// here, but that's also dependent on how we implement embedded object
|
|
|
|
// rendering I guess?
|
|
|
|
// TODO: we could be clever and e.g. set to 0 when we change to/from
|
|
|
|
// embedded object mode, and not when changing between slide/notes/combined
|
|
|
|
// modes?
|
|
|
|
if ( nCurrentPart < pDoc->getParts() )
|
2014-07-29 17:01:20 +02:00
|
|
|
{
|
2014-07-30 15:16:49 +02:00
|
|
|
pDoc->setPart( nCurrentPart );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pDoc->setPart( 0 );
|
2014-07-29 17:01:20 +02:00
|
|
|
}
|
2014-07-29 08:59:13 +02:00
|
|
|
}
|
|
|
|
|
2014-06-11 16:24:33 +01:00
|
|
|
void doc_paintTile (LibreOfficeKitDocument* pThis,
|
|
|
|
unsigned char* pBuffer,
|
2014-05-25 18:30:00 +01:00
|
|
|
const int nCanvasWidth, const int nCanvasHeight,
|
|
|
|
const int nTilePosX, const int nTilePosY,
|
|
|
|
const int nTileWidth, const int nTileHeight)
|
2014-05-09 14:37:27 +01:00
|
|
|
{
|
2014-07-11 09:13:21 +02:00
|
|
|
SAL_INFO( "lok.tiledrendering", "paintTile: painting [" << nTileWidth << "x" << nTileHeight <<
|
|
|
|
"]@(" << nTilePosX << ", " << nTilePosY << ") to [" <<
|
|
|
|
nCanvasWidth << "x" << nCanvasHeight << "]px" );
|
2014-05-09 14:37:27 +01:00
|
|
|
|
2014-08-13 09:10:08 +02:00
|
|
|
ITiledRenderable* pDoc = getTiledRenderable(pThis);
|
2014-06-13 17:32:44 +01:00
|
|
|
if (!pDoc)
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
|
|
|
|
return;
|
|
|
|
}
|
2014-06-13 15:00:42 +01:00
|
|
|
|
2014-07-30 15:16:49 +02:00
|
|
|
SolarMutexGuard aGuard;
|
|
|
|
|
2014-06-25 14:41:45 +01:00
|
|
|
#if defined(UNX) && !defined(MACOSX) && !defined(ENABLE_HEADLESS)
|
2015-02-05 10:54:56 +02:00
|
|
|
|
|
|
|
#ifndef IOS
|
2015-03-20 12:36:09 +02:00
|
|
|
InitSvpForLibreOfficeKit();
|
2014-05-23 20:00:58 +01:00
|
|
|
|
2015-04-01 09:27:07 +01:00
|
|
|
ScopedVclPtrInstance< VirtualDevice > pDevice(nullptr, Size(1, 1), (sal_uInt16)32) ;
|
2015-10-01 14:17:21 +02:00
|
|
|
|
|
|
|
// Set background to transparent by default.
|
|
|
|
memset(pBuffer, 0, nCanvasWidth * nCanvasHeight * 4);
|
|
|
|
pDevice->SetBackground(Wallpaper(Color(COL_TRANSPARENT)));
|
|
|
|
|
2014-07-30 15:16:49 +02:00
|
|
|
boost::shared_array< sal_uInt8 > aBuffer( pBuffer, NoDelete< sal_uInt8 >() );
|
2015-10-01 14:17:21 +02:00
|
|
|
|
|
|
|
// Allocate a separate buffer for the alpha device.
|
|
|
|
std::vector<sal_uInt8> aAlpha(nCanvasWidth * nCanvasHeight);
|
|
|
|
memset(aAlpha.data(), 0, nCanvasWidth * nCanvasHeight);
|
|
|
|
boost::shared_array<sal_uInt8> aAlphaBuffer(aAlpha.data(), NoDelete<sal_uInt8>());
|
|
|
|
|
2015-03-19 14:58:31 +00:00
|
|
|
pDevice->SetOutputSizePixelScaleOffsetAndBuffer(
|
2014-10-23 17:41:47 +02:00
|
|
|
Size(nCanvasWidth, nCanvasHeight), Fraction(1.0), Point(),
|
2015-10-01 14:17:21 +02:00
|
|
|
aBuffer, aAlphaBuffer, true );
|
2014-05-16 09:07:52 +01:00
|
|
|
|
2015-03-19 14:58:31 +00:00
|
|
|
pDoc->paintTile(*pDevice.get(), nCanvasWidth, nCanvasHeight,
|
2014-07-30 15:16:49 +02:00
|
|
|
nTilePosX, nTilePosY, nTileWidth, nTileHeight);
|
2015-02-04 17:48:41 +01:00
|
|
|
|
2015-10-01 14:17:21 +02:00
|
|
|
// Overwrite pBuffer's alpha channel with the separate alpha buffer.
|
|
|
|
for (int nRow = 0; nRow < nCanvasHeight; ++nRow)
|
|
|
|
{
|
|
|
|
for (int nCol = 0; nCol < nCanvasWidth; ++nCol)
|
|
|
|
{
|
2015-10-15 09:41:52 +02:00
|
|
|
const int nOffset = (nCanvasWidth * nRow) + nCol;
|
2015-10-01 14:17:21 +02:00
|
|
|
// VCL's transparent is 0, RGBA's transparent is 0xff.
|
|
|
|
pBuffer[nOffset * 4 +3] = 0xff - aAlpha[nOffset];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-07 21:25:50 +03:00
|
|
|
#else
|
|
|
|
SystemGraphicsData aData;
|
|
|
|
aData.rCGContext = reinterpret_cast<CGContextRef>(pBuffer);
|
|
|
|
// the Size argument is irrelevant, I hope
|
|
|
|
ScopedVclPtrInstance<VirtualDevice> pDevice(&aData, Size(1, 1), (sal_uInt16)0);
|
|
|
|
|
|
|
|
pDoc->paintTile(*pDevice.get(), nCanvasWidth, nCanvasHeight,
|
|
|
|
nTilePosX, nTilePosY, nTileWidth, nTileHeight);
|
|
|
|
#endif
|
|
|
|
|
2015-02-24 17:04:24 +01:00
|
|
|
static bool bDebug = getenv("LOK_DEBUG") != 0;
|
|
|
|
if (bDebug)
|
|
|
|
{
|
|
|
|
// Draw a small red rectangle in the top left corner so that it's easy to see where a new tile begins.
|
|
|
|
Rectangle aRect(0, 0, 5, 5);
|
2015-04-10 18:36:40 +01:00
|
|
|
aRect = pDevice->PixelToLogic(aRect);
|
|
|
|
pDevice->Push(PushFlags::FILLCOLOR | PushFlags::LINECOLOR);
|
|
|
|
pDevice->SetFillColor(COL_LIGHTRED);
|
|
|
|
pDevice->SetLineColor();
|
|
|
|
pDevice->DrawRect(aRect);
|
|
|
|
pDevice->Pop();
|
2015-02-24 17:04:24 +01:00
|
|
|
}
|
|
|
|
|
2014-06-25 14:30:28 +01:00
|
|
|
#else
|
2014-07-30 15:16:49 +02:00
|
|
|
(void) pBuffer;
|
|
|
|
(void) nCanvasWidth;
|
|
|
|
(void) nCanvasHeight;
|
|
|
|
(void) nTilePosX;
|
|
|
|
(void) nTilePosY;
|
|
|
|
(void) nTileWidth;
|
|
|
|
(void) nTileHeight;
|
2014-06-25 14:30:28 +01:00
|
|
|
#endif
|
2014-05-09 14:37:27 +01:00
|
|
|
}
|
|
|
|
|
2014-06-11 16:24:33 +01:00
|
|
|
static void doc_getDocumentSize(LibreOfficeKitDocument* pThis,
|
2014-05-18 08:36:16 +01:00
|
|
|
long* pWidth,
|
|
|
|
long* pHeight)
|
|
|
|
{
|
2014-08-13 09:10:08 +02:00
|
|
|
ITiledRenderable* pDoc = getTiledRenderable(pThis);
|
2014-06-13 17:32:44 +01:00
|
|
|
if (pDoc)
|
2014-05-18 08:36:16 +01:00
|
|
|
{
|
2014-06-13 17:32:44 +01:00
|
|
|
Size aDocumentSize = pDoc->getDocumentSize();
|
2014-05-18 08:36:16 +01:00
|
|
|
*pWidth = aDocumentSize.Width();
|
|
|
|
*pHeight = aDocumentSize.Height();
|
|
|
|
}
|
2014-06-13 15:00:42 +01:00
|
|
|
else
|
|
|
|
{
|
2014-06-13 17:32:44 +01:00
|
|
|
gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
|
2014-06-13 15:00:42 +01:00
|
|
|
}
|
2014-05-18 08:36:16 +01:00
|
|
|
}
|
|
|
|
|
2014-12-29 16:10:48 +09:00
|
|
|
static void doc_initializeForRendering(LibreOfficeKitDocument* pThis)
|
|
|
|
{
|
|
|
|
ITiledRenderable* pDoc = getTiledRenderable(pThis);
|
|
|
|
if (pDoc)
|
|
|
|
{
|
2015-09-14 20:14:34 -04:00
|
|
|
doc_iniUnoCommands();
|
2014-12-29 16:10:48 +09:00
|
|
|
pDoc->initializeForTiledRendering();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-06 15:49:12 +01:00
|
|
|
static void doc_registerCallback(LibreOfficeKitDocument* pThis,
|
|
|
|
LibreOfficeKitCallback pCallback,
|
|
|
|
void* pData)
|
|
|
|
{
|
2015-09-17 15:39:19 +02:00
|
|
|
if (comphelper::LibreOfficeKit::isViewCallback())
|
2015-01-06 15:49:12 +01:00
|
|
|
{
|
2015-09-17 15:39:19 +02:00
|
|
|
if (SfxViewShell* pViewShell = SfxViewFrame::Current()->GetViewShell())
|
|
|
|
pViewShell->registerLibreOfficeKitViewCallback(pCallback, pData);
|
2015-01-06 15:49:12 +01:00
|
|
|
}
|
2015-09-17 15:39:19 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ITiledRenderable* pDoc = getTiledRenderable(pThis);
|
|
|
|
if (!pDoc)
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
|
|
|
|
return;
|
|
|
|
}
|
2015-01-06 15:49:12 +01:00
|
|
|
|
2015-09-17 15:39:19 +02:00
|
|
|
pDoc->registerCallback(pCallback, pData);
|
|
|
|
}
|
2015-01-06 15:49:12 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 12:29:28 +02:00
|
|
|
static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nType, int nCharCode, int nKeyCode)
|
2015-02-27 15:38:30 +01:00
|
|
|
{
|
2015-04-03 12:29:28 +02:00
|
|
|
ITiledRenderable* pDoc = getTiledRenderable(pThis);
|
|
|
|
if (!pDoc)
|
2015-02-27 15:38:30 +01:00
|
|
|
{
|
2015-04-03 12:29:28 +02:00
|
|
|
gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
|
|
|
|
return;
|
2015-02-27 15:38:30 +01:00
|
|
|
}
|
2015-04-03 12:29:28 +02:00
|
|
|
|
|
|
|
pDoc->postKeyEvent(nType, nCharCode, nKeyCode);
|
2015-02-27 15:38:30 +01:00
|
|
|
}
|
|
|
|
|
2015-04-22 14:28:36 +02:00
|
|
|
static void jsonToPropertyValues(const char* pJSON, uno::Sequence<beans::PropertyValue>& rPropertyValues)
|
|
|
|
{
|
|
|
|
std::vector<beans::PropertyValue> aArguments;
|
2015-04-29 20:25:52 +02:00
|
|
|
if (pJSON)
|
2015-04-22 14:28:36 +02:00
|
|
|
{
|
2015-04-29 20:25:52 +02:00
|
|
|
boost::property_tree::ptree aTree;
|
|
|
|
std::stringstream aStream(pJSON);
|
|
|
|
boost::property_tree::read_json(aStream, aTree);
|
|
|
|
|
|
|
|
for (const std::pair<std::string, boost::property_tree::ptree>& rPair : aTree)
|
|
|
|
{
|
|
|
|
const std::string& rType = rPair.second.get<std::string>("type");
|
|
|
|
const std::string& rValue = rPair.second.get<std::string>("value");
|
|
|
|
|
|
|
|
beans::PropertyValue aValue;
|
|
|
|
aValue.Name = OUString::fromUtf8(rPair.first.c_str());
|
|
|
|
if (rType == "string")
|
|
|
|
aValue.Value <<= OUString::fromUtf8(rValue.c_str());
|
|
|
|
else if (rType == "boolean")
|
|
|
|
aValue.Value <<= OString(rValue.c_str()).toBoolean();
|
2015-09-04 11:55:47 +03:00
|
|
|
else if (rType == "float")
|
|
|
|
aValue.Value <<= OString(rValue.c_str()).toFloat();
|
2015-05-28 17:13:38 +02:00
|
|
|
else if (rType == "long")
|
|
|
|
aValue.Value <<= OString(rValue.c_str()).toInt32();
|
2015-10-05 11:29:02 +02:00
|
|
|
else if (rType == "unsigned short")
|
|
|
|
aValue.Value <<= static_cast<sal_uInt16>(OString(rValue.c_str()).toUInt32());
|
2015-04-29 20:25:52 +02:00
|
|
|
else
|
|
|
|
SAL_WARN("desktop.lib", "jsonToPropertyValues: unhandled type '"<<rType<<"'");
|
|
|
|
aArguments.push_back(aValue);
|
|
|
|
}
|
2015-04-22 14:28:36 +02:00
|
|
|
}
|
|
|
|
rPropertyValues = comphelper::containerToSequence(aArguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void doc_postUnoCommand(LibreOfficeKitDocument* /*pThis*/, const char* pCommand, const char* pArguments)
|
2015-03-12 14:59:59 +01:00
|
|
|
{
|
|
|
|
OUString aCommand(pCommand, strlen(pCommand), RTL_TEXTENCODING_UTF8);
|
|
|
|
|
2015-04-22 14:28:36 +02:00
|
|
|
uno::Sequence<beans::PropertyValue> aPropertyValues;
|
|
|
|
jsonToPropertyValues(pArguments, aPropertyValues);
|
|
|
|
if (!comphelper::dispatchCommand(aCommand, aPropertyValues))
|
2015-03-12 14:59:59 +01:00
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "Failed to dispatch the .uno: command";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-04 19:40:13 +03:00
|
|
|
static void doc_postMouseEvent(LibreOfficeKitDocument* pThis, int nType, int nX, int nY, int nCount, int nButtons, int nModifier)
|
2015-01-21 12:42:08 +01:00
|
|
|
{
|
|
|
|
ITiledRenderable* pDoc = getTiledRenderable(pThis);
|
|
|
|
if (!pDoc)
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-04 19:40:13 +03:00
|
|
|
pDoc->postMouseEvent(nType, nX, nY, nCount, nButtons, nModifier);
|
2015-01-21 12:42:08 +01:00
|
|
|
}
|
|
|
|
|
2015-02-10 17:43:18 +01:00
|
|
|
static void doc_setTextSelection(LibreOfficeKitDocument* pThis, int nType, int nX, int nY)
|
|
|
|
{
|
|
|
|
ITiledRenderable* pDoc = getTiledRenderable(pThis);
|
|
|
|
if (!pDoc)
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pDoc->setTextSelection(nType, nX, nY);
|
|
|
|
}
|
2015-01-21 12:42:08 +01:00
|
|
|
|
2015-06-19 18:13:27 +02:00
|
|
|
static char* doc_getTextSelection(LibreOfficeKitDocument* pThis, const char* pMimeType, char** pUsedMimeType)
|
2015-06-17 18:00:01 +02:00
|
|
|
{
|
|
|
|
ITiledRenderable* pDoc = getTiledRenderable(pThis);
|
|
|
|
if (!pDoc)
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-19 18:13:27 +02:00
|
|
|
OString aUsedMimeType;
|
|
|
|
OString aRet = pDoc->getTextSelection(pMimeType, aUsedMimeType);
|
|
|
|
if (aUsedMimeType.isEmpty())
|
|
|
|
aRet = pDoc->getTextSelection("text/plain;charset=utf-8", aUsedMimeType);
|
2015-06-17 18:00:01 +02:00
|
|
|
|
|
|
|
char* pMemory = static_cast<char*>(malloc(aRet.getLength() + 1));
|
|
|
|
strcpy(pMemory, aRet.getStr());
|
2015-06-19 18:13:27 +02:00
|
|
|
|
|
|
|
if (pUsedMimeType)
|
|
|
|
{
|
|
|
|
*pUsedMimeType = static_cast<char*>(malloc(aUsedMimeType.getLength() + 1));
|
|
|
|
strcpy(*pUsedMimeType, aUsedMimeType.getStr());
|
|
|
|
}
|
|
|
|
|
2015-06-17 18:00:01 +02:00
|
|
|
return pMemory;
|
|
|
|
}
|
|
|
|
|
2015-03-10 09:40:38 +01:00
|
|
|
static void doc_setGraphicSelection(LibreOfficeKitDocument* pThis, int nType, int nX, int nY)
|
|
|
|
{
|
|
|
|
ITiledRenderable* pDoc = getTiledRenderable(pThis);
|
|
|
|
if (!pDoc)
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pDoc->setGraphicSelection(nType, nX, nY);
|
|
|
|
}
|
|
|
|
|
2015-03-10 16:13:53 +01:00
|
|
|
static void doc_resetSelection(LibreOfficeKitDocument* pThis)
|
|
|
|
{
|
|
|
|
ITiledRenderable* pDoc = getTiledRenderable(pThis);
|
|
|
|
if (!pDoc)
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pDoc->resetSelection();
|
|
|
|
}
|
2015-09-10 11:31:48 +03:00
|
|
|
static char* getFonts (const char* pCommand)
|
|
|
|
{
|
|
|
|
SfxObjectShell* pDocSh = SfxObjectShell::Current();
|
|
|
|
const SvxFontListItem* pFonts = static_cast<const SvxFontListItem*>(
|
|
|
|
pDocSh->GetItem(SID_ATTR_CHAR_FONTLIST));
|
|
|
|
const FontList* pList = pFonts ? pFonts->GetFontList() : 0;
|
|
|
|
|
|
|
|
boost::property_tree::ptree aTree;
|
|
|
|
aTree.put("commandName", pCommand);
|
|
|
|
boost::property_tree::ptree aValues;
|
|
|
|
if ( pList )
|
|
|
|
{
|
|
|
|
sal_uInt16 nFontCount = pList->GetFontNameCount();
|
|
|
|
for (sal_uInt16 i = 0; i < nFontCount; ++i)
|
|
|
|
{
|
|
|
|
boost::property_tree::ptree aChildren;
|
|
|
|
const vcl::FontInfo& rInfo = pList->GetFontName(i);
|
|
|
|
const sal_IntPtr* pAry = pList->GetSizeAry(rInfo);
|
|
|
|
sal_uInt16 nSizeCount = 0;
|
|
|
|
while (pAry[nSizeCount])
|
|
|
|
{
|
|
|
|
boost::property_tree::ptree aChild;
|
|
|
|
aChild.put("", (float)pAry[nSizeCount] / 10);
|
|
|
|
aChildren.push_back(std::make_pair("", aChild));
|
|
|
|
nSizeCount++;
|
|
|
|
}
|
|
|
|
aValues.add_child(rInfo.GetName().toUtf8().getStr(), aChildren);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aTree.add_child("commandValues", aValues);
|
|
|
|
std::stringstream aStream;
|
|
|
|
boost::property_tree::write_json(aStream, aTree);
|
|
|
|
char* pJson = static_cast<char*>(malloc(aStream.str().size() + 1));
|
|
|
|
strcpy(pJson, aStream.str().c_str());
|
|
|
|
pJson[aStream.str().size()] = '\0';
|
|
|
|
return pJson;
|
|
|
|
}
|
2015-03-10 16:13:53 +01:00
|
|
|
|
2015-09-10 09:21:45 +03:00
|
|
|
static char* getStyles(LibreOfficeKitDocument* pThis, const char* pCommand)
|
2015-08-17 18:49:40 +03:00
|
|
|
{
|
|
|
|
LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
|
|
|
|
|
|
|
|
boost::property_tree::ptree aTree;
|
2015-09-10 09:21:45 +03:00
|
|
|
aTree.put("commandName", pCommand);
|
2015-08-17 18:49:40 +03:00
|
|
|
uno::Reference<css::style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(pDocument->mxComponent, uno::UNO_QUERY);
|
|
|
|
uno::Reference<container::XNameAccess> xStyleFamilies(xStyleFamiliesSupplier->getStyleFamilies(), uno::UNO_QUERY);
|
|
|
|
uno::Sequence<OUString> aStyleFamilies = xStyleFamilies->getElementNames();
|
|
|
|
|
2015-09-10 09:21:45 +03:00
|
|
|
boost::property_tree::ptree aValues;
|
2015-08-17 18:49:40 +03:00
|
|
|
for (sal_Int32 nStyleFam = 0; nStyleFam < aStyleFamilies.getLength(); ++nStyleFam)
|
|
|
|
{
|
|
|
|
boost::property_tree::ptree aChildren;
|
|
|
|
OUString sStyleFam = aStyleFamilies[nStyleFam];
|
|
|
|
uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName(sStyleFam), uno::UNO_QUERY);
|
|
|
|
uno::Sequence<OUString> aStyles = xStyleFamily->getElementNames();
|
|
|
|
for (sal_Int32 nInd = 0; nInd < aStyles.getLength(); ++nInd)
|
|
|
|
{
|
|
|
|
boost::property_tree::ptree aChild;
|
|
|
|
aChild.put("", aStyles[nInd]);
|
|
|
|
aChildren.push_back(std::make_pair("", aChild));
|
|
|
|
}
|
2015-09-10 09:21:45 +03:00
|
|
|
aValues.add_child(sStyleFam.toUtf8().getStr(), aChildren);
|
2015-08-17 18:49:40 +03:00
|
|
|
}
|
2015-09-10 09:21:45 +03:00
|
|
|
aTree.add_child("commandValues", aValues);
|
2015-08-17 18:49:40 +03:00
|
|
|
std::stringstream aStream;
|
|
|
|
boost::property_tree::write_json(aStream, aTree);
|
|
|
|
char* pJson = static_cast<char*>(malloc(aStream.str().size() + 1));
|
|
|
|
strcpy(pJson, aStream.str().c_str());
|
|
|
|
pJson[aStream.str().size()] = '\0';
|
|
|
|
return pJson;
|
|
|
|
}
|
2015-09-10 09:21:45 +03:00
|
|
|
|
|
|
|
static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCommand)
|
|
|
|
{
|
2015-09-10 11:31:48 +03:00
|
|
|
if (!strcmp(pCommand, ".uno:CharFontName"))
|
|
|
|
{
|
|
|
|
return getFonts(pCommand);
|
|
|
|
}
|
|
|
|
else if (!strcmp(pCommand, ".uno:StyleApply"))
|
2015-09-10 09:21:45 +03:00
|
|
|
{
|
|
|
|
return getStyles(pThis, pCommand);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gImpl->maLastExceptionMsg = "Unknown command, no values returned";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-16 10:32:34 +02:00
|
|
|
static int doc_createView(LibreOfficeKitDocument* /*pThis*/)
|
2015-09-14 14:36:56 +02:00
|
|
|
{
|
|
|
|
SolarMutexGuard aGuard;
|
|
|
|
|
2015-09-16 10:32:34 +02:00
|
|
|
return SfxLokHelper::createView();
|
2015-09-14 14:36:56 +02:00
|
|
|
}
|
|
|
|
|
2015-09-15 09:31:49 +02:00
|
|
|
static void doc_destroyView(LibreOfficeKitDocument* /*pThis*/, int nId)
|
|
|
|
{
|
|
|
|
SolarMutexGuard aGuard;
|
|
|
|
|
|
|
|
SfxLokHelper::destroyView(nId);
|
|
|
|
}
|
|
|
|
|
2015-09-16 09:30:41 +02:00
|
|
|
static void doc_setView(LibreOfficeKitDocument* /*pThis*/, int nId)
|
|
|
|
{
|
|
|
|
SolarMutexGuard aGuard;
|
|
|
|
|
|
|
|
SfxLokHelper::setView(nId);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int doc_getView(LibreOfficeKitDocument* /*pThis*/)
|
|
|
|
{
|
|
|
|
SolarMutexGuard aGuard;
|
|
|
|
|
|
|
|
return SfxLokHelper::getView();
|
|
|
|
}
|
|
|
|
|
2015-09-16 14:14:04 +02:00
|
|
|
static int doc_getViews(LibreOfficeKitDocument* /*pThis*/)
|
|
|
|
{
|
|
|
|
SolarMutexGuard aGuard;
|
|
|
|
|
|
|
|
return SfxLokHelper::getViews();
|
|
|
|
}
|
|
|
|
|
2014-06-10 11:31:51 +01:00
|
|
|
static char* lo_getError (LibreOfficeKit *pThis)
|
2013-07-26 18:21:45 +01:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
|
|
|
|
OString aString = OUStringToOString(pLib->maLastExceptionMsg, RTL_TEXTENCODING_UTF8);
|
2015-03-28 19:00:39 +01:00
|
|
|
char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1));
|
2014-04-05 21:48:47 +02:00
|
|
|
strcpy(pMemory, aString.getStr());
|
|
|
|
return pMemory;
|
2013-03-05 13:16:36 +00:00
|
|
|
}
|
|
|
|
|
2015-09-25 01:02:23 +02:00
|
|
|
static char* lo_getFilterTypes(LibreOfficeKit* pThis)
|
|
|
|
{
|
|
|
|
LibLibreOffice_Impl* pImpl = static_cast<LibLibreOffice_Impl*>(pThis);
|
|
|
|
|
|
|
|
if (!xSFactory.is())
|
|
|
|
xSFactory = comphelper::getProcessServiceFactory();
|
|
|
|
|
|
|
|
if (!xSFactory.is())
|
|
|
|
{
|
|
|
|
pImpl->maLastExceptionMsg = "Service factory is not available";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uno::Reference<container::XNameAccess> xTypeDetection(xSFactory->createInstance("com.sun.star.document.TypeDetection"), uno::UNO_QUERY);
|
|
|
|
uno::Sequence<OUString> aTypes = xTypeDetection->getElementNames();
|
|
|
|
boost::property_tree::ptree aTree;
|
|
|
|
for (const OUString& rType : aTypes)
|
|
|
|
{
|
|
|
|
uno::Sequence<beans::PropertyValue> aValues;
|
|
|
|
if (xTypeDetection->getByName(rType) >>= aValues)
|
|
|
|
{
|
|
|
|
auto it = std::find_if(aValues.begin(), aValues.end(), [](const beans::PropertyValue& rValue) { return rValue.Name == "MediaType"; });
|
|
|
|
OUString aValue;
|
|
|
|
if (it != aValues.end() && (it->Value >>= aValue) && !aValue.isEmpty())
|
|
|
|
{
|
|
|
|
boost::property_tree::ptree aChild;
|
|
|
|
aChild.put("MediaType", aValue.toUtf8());
|
|
|
|
aTree.add_child(rType.toUtf8().getStr(), aChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::stringstream aStream;
|
|
|
|
boost::property_tree::write_json(aStream, aTree);
|
|
|
|
return strdup(aStream.str().c_str());
|
|
|
|
}
|
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
static void force_c_locale()
|
2013-03-05 13:16:36 +00:00
|
|
|
{
|
|
|
|
// force locale (and resource files loaded) to en-US
|
2014-04-05 21:48:47 +02:00
|
|
|
OUString aLangISO("en-US");
|
|
|
|
LanguageTag aLocale(aLangISO);
|
|
|
|
ResMgr::SetDefaultLocale(aLocale);
|
2013-03-05 13:16:36 +00:00
|
|
|
SvtSysLocaleOptions aLocalOptions;
|
2014-04-05 21:48:47 +02:00
|
|
|
aLocalOptions.SetLocaleConfigString(aLangISO);
|
|
|
|
aLocalOptions.SetUILocaleConfigString(aLangISO);
|
2013-03-05 13:16:36 +00:00
|
|
|
}
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
static void aBasicErrorFunc(const OUString& rError, const OUString& rAction)
|
2013-03-05 13:16:36 +00:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
OStringBuffer aBuffer("Unexpected dialog: ");
|
|
|
|
aBuffer.append(OUStringToOString(rAction, RTL_TEXTENCODING_ASCII_US));
|
|
|
|
aBuffer.append(" Error: ");
|
|
|
|
aBuffer.append(OUStringToOString(rError, RTL_TEXTENCODING_ASCII_US));
|
|
|
|
|
|
|
|
fprintf(stderr, "Unexpected basic error dialog '%s'\n", aBuffer.getStr());
|
2013-03-05 13:16:36 +00:00
|
|
|
}
|
|
|
|
|
2014-11-17 10:36:53 +01:00
|
|
|
static bool initialize_uno(const OUString& aAppProgramURL)
|
2013-03-05 13:16:36 +00:00
|
|
|
{
|
2015-02-03 15:47:53 +01:00
|
|
|
#ifdef IOS
|
2015-10-02 09:57:58 +02:00
|
|
|
// For iOS we already hardcode the inifile as "rc" in the .app directory.
|
2015-02-03 15:47:53 +01:00
|
|
|
(void) aAppProgramURL;
|
2015-05-23 10:09:18 +01:00
|
|
|
#elif defined MACOSX
|
|
|
|
rtl::Bootstrap::setIniFilename(aAppProgramURL + "/../Resources/" SAL_CONFIGFILE("soffice"));
|
2015-02-03 15:47:53 +01:00
|
|
|
#else
|
2014-07-01 15:45:52 +02:00
|
|
|
rtl::Bootstrap::setIniFilename(aAppProgramURL + "/" SAL_CONFIGFILE("soffice"));
|
2015-02-03 15:47:53 +01:00
|
|
|
#endif
|
2013-03-05 22:21:57 +00:00
|
|
|
|
2013-03-05 16:40:01 +00:00
|
|
|
xContext = cppu::defaultBootstrap_InitialComponentContext();
|
2014-11-17 10:36:53 +01:00
|
|
|
if (!xContext.is())
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "XComponentContext could not be created";
|
|
|
|
SAL_INFO("lok", "XComponentContext could not be created");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-05 16:40:01 +00:00
|
|
|
xFactory = xContext->getServiceManager();
|
2014-11-17 10:36:53 +01:00
|
|
|
if (!xFactory.is())
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "XMultiComponentFactory could not be created";
|
|
|
|
SAL_INFO("lok", "XMultiComponentFactory could not be created");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-05 16:40:01 +00:00
|
|
|
xSFactory = uno::Reference<lang::XMultiServiceFactory>(xFactory, uno::UNO_QUERY_THROW);
|
2014-11-17 10:36:53 +01:00
|
|
|
if (!xSFactory.is())
|
|
|
|
{
|
|
|
|
gImpl->maLastExceptionMsg = "XMultiServiceFactory could not be created";
|
|
|
|
SAL_INFO("lok", "XMultiServiceFactory could not be created");
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-05 16:40:01 +00:00
|
|
|
comphelper::setProcessServiceFactory(xSFactory);
|
|
|
|
|
2014-11-17 10:36:53 +01:00
|
|
|
SAL_INFO("lok", "Uno initialized - " << xContext.is());
|
|
|
|
|
2013-03-05 13:16:36 +00:00
|
|
|
// set UserInstallation to user profile dir in test/user-template
|
2013-03-05 22:21:57 +00:00
|
|
|
// rtl::Bootstrap aDefaultVars;
|
2014-07-01 12:37:58 +02:00
|
|
|
// aDefaultVars.set(OUString("UserInstallation"), aAppProgramURL + "../registry" );
|
2013-03-05 22:21:57 +00:00
|
|
|
// configmgr setup ?
|
2014-11-17 10:36:53 +01:00
|
|
|
|
|
|
|
return true;
|
2013-03-05 13:16:36 +00:00
|
|
|
}
|
|
|
|
|
2015-03-11 10:31:14 +01:00
|
|
|
static void lo_startmain(void*)
|
2014-07-26 16:06:04 +02:00
|
|
|
{
|
2015-08-06 11:40:28 -04:00
|
|
|
osl_setThreadName("lo_startmain");
|
|
|
|
|
2014-07-26 16:06:04 +02:00
|
|
|
soffice_main();
|
|
|
|
}
|
|
|
|
|
2014-10-15 10:55:42 +03:00
|
|
|
static bool bInitialized = false;
|
|
|
|
|
2015-05-06 16:43:33 +03:00
|
|
|
static void lo_status_indicator_callback(void *data, comphelper::LibreOfficeKit::statusIndicatorCallbackType type, int percent)
|
|
|
|
{
|
|
|
|
LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(data);
|
|
|
|
|
|
|
|
if (!pLib->mpCallback)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case comphelper::LibreOfficeKit::statusIndicatorCallbackType::Start:
|
|
|
|
pLib->mpCallback(LOK_CALLBACK_STATUS_INDICATOR_START, 0, pLib->mpCallbackData);
|
|
|
|
break;
|
|
|
|
case comphelper::LibreOfficeKit::statusIndicatorCallbackType::SetValue:
|
2015-05-06 21:15:59 +03:00
|
|
|
pLib->mpCallback(LOK_CALLBACK_STATUS_INDICATOR_SET_VALUE, OUString::number(percent).toUtf8().getStr(), pLib->mpCallbackData);
|
2015-05-06 16:43:33 +03:00
|
|
|
break;
|
|
|
|
case comphelper::LibreOfficeKit::statusIndicatorCallbackType::Finish:
|
|
|
|
pLib->mpCallback(LOK_CALLBACK_STATUS_INDICATOR_FINISH, 0, pLib->mpCallbackData);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 22:44:29 +03:00
|
|
|
static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char* pUserProfilePath)
|
2013-03-05 13:16:36 +00:00
|
|
|
{
|
2014-07-28 16:18:57 +02:00
|
|
|
LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
|
2013-11-15 12:09:10 +00:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
if (bInitialized)
|
2013-11-15 12:09:10 +00:00
|
|
|
return 1;
|
2013-03-05 13:16:36 +00:00
|
|
|
|
2015-04-02 13:22:04 +03:00
|
|
|
comphelper::LibreOfficeKit::setActive();
|
2015-09-17 10:59:13 +02:00
|
|
|
|
|
|
|
static bool bViewCallback = getenv("LOK_VIEW_CALLBACK");
|
|
|
|
comphelper::LibreOfficeKit::setViewCallback(bViewCallback);
|
|
|
|
|
2015-05-06 16:43:33 +03:00
|
|
|
comphelper::LibreOfficeKit::setStatusIndicatorCallback(lo_status_indicator_callback, pLib);
|
2015-03-29 22:59:22 +03:00
|
|
|
|
2015-04-08 22:44:29 +03:00
|
|
|
if (pUserProfilePath)
|
|
|
|
rtl::Bootstrap::set(OUString("UserInstallation"), OUString(pUserProfilePath, strlen(pUserProfilePath), RTL_TEXTENCODING_UTF8));
|
|
|
|
|
2014-06-17 19:57:25 +01:00
|
|
|
OUString aAppPath;
|
|
|
|
if (pAppPath)
|
|
|
|
{
|
|
|
|
aAppPath = OUString(pAppPath, strlen(pAppPath), RTL_TEXTENCODING_UTF8);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-02 16:02:36 +01:00
|
|
|
// Fun conversion dance back and forth between URLs and system paths...
|
|
|
|
OUString aAppURL;
|
2014-06-17 19:57:25 +01:00
|
|
|
::osl::Module::getUrlFromAddress( reinterpret_cast< oslGenericFunction >(lo_initialize),
|
2015-02-02 16:02:36 +01:00
|
|
|
aAppURL);
|
|
|
|
osl::FileBase::getSystemPathFromFileURL( aAppURL, aAppPath );
|
2014-06-17 19:57:25 +01:00
|
|
|
}
|
|
|
|
|
2013-03-05 13:16:36 +00:00
|
|
|
OUString aAppURL;
|
2014-04-05 21:48:47 +02:00
|
|
|
if (osl::FileBase::getFileURLFromSystemPath(aAppPath, aAppURL) != osl::FileBase::E_None)
|
2013-11-15 12:09:10 +00:00
|
|
|
return 0;
|
2013-03-05 13:16:36 +00:00
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
try
|
|
|
|
{
|
2014-11-17 10:36:53 +01:00
|
|
|
SAL_INFO("lok", "Attempting to initalize UNO");
|
|
|
|
if (!initialize_uno(aAppURL))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-05 13:16:36 +00:00
|
|
|
force_c_locale();
|
2013-03-05 22:21:57 +00:00
|
|
|
|
2014-07-18 10:00:42 +02:00
|
|
|
// Force headless -- this is only for bitmap rendering.
|
2014-04-05 21:48:47 +02:00
|
|
|
rtl::Bootstrap::set("SAL_USE_VCLPLUGIN", "svp");
|
2014-07-26 16:06:04 +02:00
|
|
|
|
2014-12-10 12:31:15 +01:00
|
|
|
// We specifically need to make sure we have the "headless"
|
|
|
|
// command arg set (various code specifically checks via
|
|
|
|
// CommandLineArgs):
|
|
|
|
desktop::Desktop::GetCommandLineArgs().setHeadless();
|
|
|
|
|
2014-12-10 18:28:11 +01:00
|
|
|
Application::EnableHeadlessMode(true);
|
|
|
|
|
2015-03-28 23:37:02 +02:00
|
|
|
// This is horrible crack. I really would want to go back to simply just call
|
|
|
|
// InitVCL() here. The OfficeIPCThread thing is just horrible.
|
|
|
|
|
2014-07-18 10:02:48 +02:00
|
|
|
// We could use InitVCL() here -- and used to before using soffice_main,
|
|
|
|
// however that now deals with the initialisation for us (and it's not
|
|
|
|
// possible to try to set up VCL twice.
|
|
|
|
|
|
|
|
// Instead VCL init is done for us by soffice_main in a separate thread,
|
|
|
|
// however we specifically can't proceed until this setup is complete
|
|
|
|
// (or you get segfaults trying to use VCL and/or deadlocks due to other
|
|
|
|
// setup within soffice_main). Specifically the various Application::
|
|
|
|
// functions depend on VCL being ready -- the deadlocks would happen
|
|
|
|
// if you try to use loadDocument too early.
|
|
|
|
|
|
|
|
// The OfficeIPCThread is specifically set to be read when all the other
|
|
|
|
// init in Desktop::Main (run from soffice_main) is done. We can "enable"
|
|
|
|
// the Thread from wherever (it's done again in Desktop::Main), and can
|
|
|
|
// then use it to wait until we're definitely ready to continue.
|
|
|
|
|
2014-11-17 10:36:53 +01:00
|
|
|
SAL_INFO("lok", "Enabling OfficeIPCThread");
|
2014-07-18 10:02:48 +02:00
|
|
|
OfficeIPCThread::EnableOfficeIPCThread();
|
2014-11-17 10:36:53 +01:00
|
|
|
SAL_INFO("lok", "Starting soffice_main");
|
2015-03-11 10:31:14 +01:00
|
|
|
pLib->maThread = osl_createThread(lo_startmain, NULL);
|
2014-11-17 10:36:53 +01:00
|
|
|
SAL_INFO("lok", "Waiting for OfficeIPCThread");
|
2014-07-18 10:02:48 +02:00
|
|
|
OfficeIPCThread::WaitForReady();
|
2014-09-26 09:12:56 +01:00
|
|
|
SAL_INFO("lok", "OfficeIPCThread ready -- continuing");
|
2014-07-26 16:06:04 +02:00
|
|
|
|
2014-07-18 13:12:25 +02:00
|
|
|
// If the Thread has been disabled again that indicates that a
|
|
|
|
// restart is required (or in any case we don't have a useable
|
|
|
|
// process around).
|
|
|
|
if (!OfficeIPCThread::IsEnabled())
|
|
|
|
{
|
|
|
|
fprintf(stderr, "LOK init failed -- restart required\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-05 21:48:47 +02:00
|
|
|
ErrorHandler::RegisterDisplay(aBasicErrorFunc);
|
2013-03-05 13:16:36 +00:00
|
|
|
|
2014-11-17 10:36:53 +01:00
|
|
|
SAL_INFO("lok", "LOK Initialized");
|
2013-03-05 13:16:36 +00:00
|
|
|
bInitialized = true;
|
2014-04-05 21:48:47 +02:00
|
|
|
}
|
|
|
|
catch (css::uno::Exception& exception)
|
|
|
|
{
|
2014-11-17 10:36:53 +01:00
|
|
|
fprintf(stderr, "Bootstrapping exception '%s'\n",
|
2014-04-05 21:48:47 +02:00
|
|
|
OUStringToOString(exception.Message, RTL_TEXTENCODING_UTF8).getStr());
|
2013-03-05 13:16:36 +00:00
|
|
|
}
|
|
|
|
return bInitialized;
|
|
|
|
}
|
|
|
|
|
2015-02-02 15:22:52 +01:00
|
|
|
// Undo our clever trick of having SAL_DLLPUBLIC_EXPORT actually not
|
|
|
|
// meaning what is says in for the DISABLE_DYNLOADING case. See
|
|
|
|
// <sal/types.h>. Normally, when building just one big dylib (Android)
|
|
|
|
// or executable (iOS), most of our "public" symbols don't need to be
|
|
|
|
// visible outside that resulting dylib/executable. But
|
|
|
|
// libreofficekit_hook must be exported for dlsym() to find it,
|
|
|
|
// though, at least on iOS.
|
|
|
|
|
|
|
|
#if defined(__GNUC__) && defined(HAVE_GCC_VISIBILITY_FEATURE) && defined(DISABLE_DYNLOADING)
|
|
|
|
__attribute__ ((visibility("default")))
|
|
|
|
#else
|
|
|
|
SAL_DLLPUBLIC_EXPORT
|
|
|
|
#endif
|
2015-04-08 22:44:29 +03:00
|
|
|
LibreOfficeKit *libreofficekit_hook_2(const char* install_path, const char* user_profile_path)
|
2013-03-05 13:16:36 +00:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
if (!gImpl)
|
2013-07-26 18:21:45 +01:00
|
|
|
{
|
2014-11-17 10:36:53 +01:00
|
|
|
SAL_INFO("lok", "Create libreoffice object");
|
|
|
|
|
2013-07-26 18:21:45 +01:00
|
|
|
gImpl = new LibLibreOffice_Impl();
|
2015-04-08 22:44:29 +03:00
|
|
|
if (!lo_initialize(gImpl, install_path, user_profile_path))
|
2014-06-17 19:57:25 +01:00
|
|
|
{
|
|
|
|
lo_destroy(gImpl);
|
|
|
|
}
|
2013-07-26 18:21:45 +01:00
|
|
|
}
|
2014-06-10 11:31:51 +01:00
|
|
|
return static_cast<LibreOfficeKit*>(gImpl);
|
2013-03-05 16:19:58 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 22:44:29 +03:00
|
|
|
#if defined(__GNUC__) && defined(HAVE_GCC_VISIBILITY_FEATURE) && defined(DISABLE_DYNLOADING)
|
|
|
|
__attribute__ ((visibility("default")))
|
|
|
|
#else
|
|
|
|
SAL_DLLPUBLIC_EXPORT
|
|
|
|
#endif
|
|
|
|
LibreOfficeKit *libreofficekit_hook(const char* install_path)
|
|
|
|
{
|
|
|
|
return libreofficekit_hook_2(install_path, NULL);
|
|
|
|
}
|
|
|
|
|
2014-11-17 10:36:53 +01:00
|
|
|
static void lo_destroy(LibreOfficeKit* pThis)
|
2013-03-05 16:19:58 +00:00
|
|
|
{
|
2014-04-05 21:48:47 +02:00
|
|
|
LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
|
2013-07-26 18:21:45 +01:00
|
|
|
gImpl = NULL;
|
2014-07-28 16:18:57 +02:00
|
|
|
|
2014-11-17 10:36:53 +01:00
|
|
|
SAL_INFO("lok", "LO Destroy");
|
2014-10-15 10:55:42 +03:00
|
|
|
|
2015-05-06 16:43:33 +03:00
|
|
|
comphelper::LibreOfficeKit::setStatusIndicatorCallback(0, 0);
|
|
|
|
|
2014-07-28 16:18:57 +02:00
|
|
|
Application::Quit();
|
2015-03-11 10:31:14 +01:00
|
|
|
osl_joinWithThread(pLib->maThread);
|
|
|
|
osl_destroyThread(pLib->maThread);
|
2014-07-28 16:18:57 +02:00
|
|
|
|
|
|
|
delete pLib;
|
2014-10-15 10:55:42 +03:00
|
|
|
bInitialized = false;
|
2014-11-17 10:36:53 +01:00
|
|
|
SAL_INFO("lok", "LO Destroy Done");
|
2013-03-05 13:16:36 +00:00
|
|
|
}
|
|
|
|
|
2013-11-15 12:09:10 +00:00
|
|
|
}
|
|
|
|
|
2013-03-05 13:16:36 +00:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|