LOK: Split into instance and class.
Change-Id: I2b6f33eaf12343c7da1328a932eb703bb4e4ef6f
This commit is contained in:
committed by
Michael Meeks
parent
5df0bfdddb
commit
8ba3116a8f
@@ -13,6 +13,9 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
|
||||
#include <LibreOfficeKit/LibreOfficeKit.h>
|
||||
|
||||
#include <tools/errinf.hxx>
|
||||
@@ -42,10 +45,14 @@
|
||||
using namespace css;
|
||||
using namespace utl;
|
||||
|
||||
using namespace boost;
|
||||
|
||||
struct LibLODocument_Impl;
|
||||
struct LibLibreOffice_Impl;
|
||||
|
||||
static LibLibreOffice_Impl *gImpl = NULL;
|
||||
static weak_ptr< LibreOfficeKitClass > gOfficeClass;
|
||||
static weak_ptr< LibreOfficeKitDocumentClass > gDocumentClass;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -151,15 +158,24 @@ static int doc_saveAsWithOptions(LibreOfficeKitDocument* pThis, const char* pUr
|
||||
struct LibLODocument_Impl : public _LibreOfficeKitDocument
|
||||
{
|
||||
uno::Reference<css::lang::XComponent> mxComponent;
|
||||
shared_ptr< LibreOfficeKitDocumentClass > m_pDocumentClass;
|
||||
|
||||
LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent) :
|
||||
mxComponent( xComponent )
|
||||
{
|
||||
nSize = sizeof(LibreOfficeKitDocument);
|
||||
if (!(m_pDocumentClass = gDocumentClass.lock()))
|
||||
{
|
||||
m_pDocumentClass.reset(new LibreOfficeKitDocumentClass);
|
||||
|
||||
destroy = doc_destroy;
|
||||
saveAs = doc_saveAs;
|
||||
saveAsWithOptions = doc_saveAsWithOptions;
|
||||
m_pDocumentClass->nSize = sizeof(LibreOfficeKitDocument);
|
||||
|
||||
m_pDocumentClass->destroy = doc_destroy;
|
||||
m_pDocumentClass->saveAs = doc_saveAs;
|
||||
m_pDocumentClass->saveAsWithOptions = doc_saveAsWithOptions;
|
||||
|
||||
gDocumentClass = m_pDocumentClass;
|
||||
}
|
||||
pClass = m_pDocumentClass.get();
|
||||
}
|
||||
|
||||
~LibLODocument_Impl()
|
||||
@@ -182,15 +198,23 @@ static char * lo_getError (LibreOfficeKit* pThis);
|
||||
struct LibLibreOffice_Impl : public _LibreOfficeKit
|
||||
{
|
||||
OUString maLastExceptionMsg;
|
||||
shared_ptr< LibreOfficeKitClass > m_pOfficeClass;
|
||||
|
||||
LibLibreOffice_Impl()
|
||||
{
|
||||
nSize = sizeof(LibreOfficeKit);
|
||||
if(!(m_pOfficeClass = gOfficeClass.lock())) {
|
||||
m_pOfficeClass.reset(new LibreOfficeKitClass);
|
||||
m_pOfficeClass->nSize = sizeof(LibreOfficeKitClass);
|
||||
|
||||
destroy = lo_destroy;
|
||||
initialize = lo_initialize;
|
||||
documentLoad = lo_documentLoad;
|
||||
getError = lo_getError;
|
||||
m_pOfficeClass->destroy = lo_destroy;
|
||||
m_pOfficeClass->initialize = lo_initialize;
|
||||
m_pOfficeClass->documentLoad = lo_documentLoad;
|
||||
m_pOfficeClass->getError = lo_getError;
|
||||
|
||||
gOfficeClass = m_pOfficeClass;
|
||||
}
|
||||
|
||||
pClass = m_pOfficeClass.get();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -416,7 +440,7 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath)
|
||||
return bInitialized;
|
||||
}
|
||||
|
||||
SAL_DLLPUBLIC_EXPORT LibreOfficeKit *liblibreoffice_hook(void)
|
||||
SAL_DLLPUBLIC_EXPORT LibreOfficeKit *libreofficekit_hook(void)
|
||||
{
|
||||
if (!gImpl)
|
||||
{
|
||||
|
@@ -18,16 +18,24 @@ extern "C"
|
||||
#endif
|
||||
|
||||
typedef struct _LibreOfficeKit LibreOfficeKit;
|
||||
typedef struct _LibreOfficeKitClass LibreOfficeKitClass;
|
||||
|
||||
typedef struct _LibreOfficeKitDocument LibreOfficeKitDocument;
|
||||
typedef struct _LibreOfficeKitDocumentClass LibreOfficeKitDocumentClass;
|
||||
|
||||
// Do we have an extended member in this struct ?
|
||||
#define LIBREOFFICEKIT_HAS_MEMBER(strct,member,nSize) \
|
||||
((((size_t)((unsigned char *)&((strct *) 0)->member) + \
|
||||
sizeof ((strct *) 0)->member)) <= (nSize))
|
||||
|
||||
#define LIBREOFFICEKIT_HAS(pKit,member) LIBREOFFICEKIT_HAS_MEMBER(LibreOfficeKit,member,(pKit)->nSize)
|
||||
#define LIBREOFFICEKIT_HAS(pKit,member) LIBREOFFICEKIT_HAS_MEMBER(LibreOfficeKitClass,member,(pKit)->pClass->nSize)
|
||||
|
||||
struct _LibreOfficeKit
|
||||
{
|
||||
LibreOfficeKitClass* pClass;
|
||||
};
|
||||
|
||||
struct _LibreOfficeKitClass
|
||||
{
|
||||
size_t nSize;
|
||||
|
||||
@@ -37,9 +45,14 @@ struct _LibreOfficeKit
|
||||
char* (*getError) (LibreOfficeKit *pThis);
|
||||
};
|
||||
|
||||
#define LIBREOFFICEKIT_DOCUMENT_HAS(pDoc,member) LIBREOFFICEKIT_HAS_MEMBER(LibreOfficeKitDocument,member,(pDoc)->nSize)
|
||||
#define LIBREOFFICEKIT_DOCUMENT_HAS(pDoc,member) LIBREOFFICEKIT_HAS_MEMBER(LibreOfficeKitDocumentClass,member,(pDoc)->pClass->nSize)
|
||||
|
||||
struct _LibreOfficeKitDocument
|
||||
{
|
||||
LibreOfficeKitDocumentClass* pClass;
|
||||
};
|
||||
|
||||
struct _LibreOfficeKitDocumentClass
|
||||
{
|
||||
size_t nSize;
|
||||
|
||||
|
@@ -33,22 +33,18 @@ public:
|
||||
|
||||
inline ~Document()
|
||||
{
|
||||
mpDoc->destroy(mpDoc);
|
||||
mpDoc->pClass->destroy(mpDoc);
|
||||
}
|
||||
|
||||
// Save as the given format, if format is NULL sniff from ext'n
|
||||
inline bool saveAs(const char* pUrl, const char* pFormat = NULL)
|
||||
{
|
||||
return mpDoc->saveAs(mpDoc, pUrl, pFormat);
|
||||
return mpDoc->pClass->saveAs(mpDoc, pUrl, pFormat);
|
||||
}
|
||||
|
||||
inline bool saveAsWithOptions(const char* pUrl, const char* pFormat = NULL, const char* pFilterOptions = NULL)
|
||||
{
|
||||
// available since LibreOffice 4.3
|
||||
if (!LIBREOFFICEKIT_DOCUMENT_HAS(mpDoc, saveAsWithOptions))
|
||||
return false;
|
||||
|
||||
return mpDoc->saveAsWithOptions(mpDoc, pUrl, pFormat, pFilterOptions);
|
||||
return mpDoc->pClass->saveAsWithOptions(mpDoc, pUrl, pFormat, pFilterOptions);
|
||||
}
|
||||
inline LibreOfficeKitDocument *get() { return mpDoc; }
|
||||
};
|
||||
@@ -65,17 +61,17 @@ public:
|
||||
|
||||
inline ~Office()
|
||||
{
|
||||
mpThis->destroy(mpThis);
|
||||
mpThis->pClass->destroy(mpThis);
|
||||
}
|
||||
|
||||
inline bool initialize(const char* pInstallPath)
|
||||
{
|
||||
return mpThis->initialize(mpThis, pInstallPath);
|
||||
return mpThis->pClass->initialize(mpThis, pInstallPath);
|
||||
}
|
||||
|
||||
inline Document* documentLoad(const char* pUrl)
|
||||
{
|
||||
LibreOfficeKitDocument* pDoc = mpThis->documentLoad(mpThis, pUrl);
|
||||
LibreOfficeKitDocument* pDoc = mpThis->pClass->documentLoad(mpThis, pUrl);
|
||||
if (pDoc == NULL)
|
||||
return NULL;
|
||||
return new Document(pDoc);
|
||||
@@ -84,14 +80,14 @@ public:
|
||||
// return the last error as a string, free me.
|
||||
inline char* getError()
|
||||
{
|
||||
return mpThis->getError(mpThis);
|
||||
return mpThis->pClass->getError(mpThis);
|
||||
}
|
||||
};
|
||||
|
||||
inline Office* lok_cpp_init(const char* pInstallPath)
|
||||
{
|
||||
LibreOfficeKit* pThis = lok_init(pInstallPath);
|
||||
if (pThis == NULL || pThis->nSize == 0)
|
||||
if (pThis == NULL || pThis->pClass->nSize == 0)
|
||||
return NULL;
|
||||
return new ::lok::Office(pThis);
|
||||
}
|
||||
|
@@ -50,7 +50,7 @@ SAL_DLLPUBLIC_EXPORT LibreOfficeKit *lok_init( const char *install_path )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pSym = (HookFunction *) dlsym( dlhandle, "liblibreoffice_hook" );
|
||||
pSym = (HookFunction *) dlsym( dlhandle, "libreofficekit_hook" );
|
||||
if( !pSym ) {
|
||||
fprintf( stderr, "failed to find hook in library '%s'\n", imp_lib );
|
||||
dlclose( dlhandle );
|
||||
|
@@ -79,9 +79,9 @@ int main (int argc, char **argv)
|
||||
if (!LIBREOFFICEKIT_DOCUMENT_HAS(pDocument->get(), saveAsWithOptions))
|
||||
{
|
||||
fprintf( stderr, "using obsolete LibreOffice %" SAL_PRI_SIZET "d + %" SAL_PRI_SIZET "d vs. %" SAL_PRI_SIZET "d\n",
|
||||
(size_t)((unsigned char *)&((LibreOfficeKitDocument *) 0)->saveAsWithOptions),
|
||||
sizeof ((LibreOfficeKitDocument *) 0)->saveAsWithOptions,
|
||||
pDocument->get()->nSize );
|
||||
(size_t)((unsigned char *)&((LibreOfficeKitDocumentClass *) 0)->saveAsWithOptions),
|
||||
sizeof ((LibreOfficeKitDocumentClass *) 0)->saveAsWithOptions,
|
||||
pDocument->get()->pClass->nSize );
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user