LOK: Split into instance and class.

Change-Id: I2b6f33eaf12343c7da1328a932eb703bb4e4ef6f
This commit is contained in:
Andrzej Hunt
2014-06-17 15:13:33 +01:00
committed by Michael Meeks
parent 5df0bfdddb
commit 8ba3116a8f
5 changed files with 61 additions and 28 deletions

View File

@@ -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;

View File

@@ -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);
}