2013-03-05 16:19:58 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
2015-02-02 11:03:13 +01:00
|
|
|
#ifndef INCLUDED_LIBREOFFICEKIT_LIBREOFFICEKIT_HXX
|
|
|
|
#define INCLUDED_LIBREOFFICEKIT_LIBREOFFICEKIT_HXX
|
2013-03-05 16:19:58 +00:00
|
|
|
|
2014-06-09 11:33:25 +01:00
|
|
|
#include "LibreOfficeKit.h"
|
2013-11-15 12:09:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The reasons this C++ code is not as pretty as it could be are:
|
|
|
|
* a) provide a pure C API - that's useful for some people
|
|
|
|
* b) allow ABI stability - C++ vtables are not good for that.
|
|
|
|
* c) avoid C++ types as part of the API.
|
|
|
|
*/
|
2014-06-10 11:42:13 +01:00
|
|
|
namespace lok
|
|
|
|
{
|
2013-11-15 12:09:10 +00:00
|
|
|
|
2015-03-30 12:08:25 +02:00
|
|
|
/// The lok::Document class represents one loaded document instance.
|
2014-06-10 11:42:13 +01:00
|
|
|
class Document
|
2013-07-26 18:21:45 +01:00
|
|
|
{
|
2014-04-06 12:05:13 +02:00
|
|
|
private:
|
2014-06-10 11:31:51 +01:00
|
|
|
LibreOfficeKitDocument* mpDoc;
|
2014-04-06 12:05:13 +02:00
|
|
|
|
2013-07-26 18:21:45 +01:00
|
|
|
public:
|
2015-03-30 12:08:25 +02:00
|
|
|
/// A lok::Document is typically created by the lok::Office::documentLoad() method.
|
2014-06-10 11:42:13 +01:00
|
|
|
inline Document(LibreOfficeKitDocument* pDoc) :
|
2014-04-06 12:05:13 +02:00
|
|
|
mpDoc(pDoc)
|
|
|
|
{}
|
|
|
|
|
2014-06-10 11:42:13 +01:00
|
|
|
inline ~Document()
|
2014-04-06 12:05:13 +02:00
|
|
|
{
|
2014-06-17 15:13:33 +01:00
|
|
|
mpDoc->pClass->destroy(mpDoc);
|
2014-04-06 12:05:13 +02:00
|
|
|
}
|
2013-07-26 18:21:45 +01:00
|
|
|
|
2015-03-30 12:08:25 +02:00
|
|
|
/**
|
|
|
|
* Stores the document's persistent data to a URL and
|
|
|
|
* continues to be a representation of the old URL.
|
|
|
|
*
|
|
|
|
* @param pUrl the location where to store the document
|
|
|
|
* @param pFormat the format to use while exporting, when omitted, then deducted from pURL's extension
|
|
|
|
* @param pFilterOptions options for the export filter, e.g. SkipImages.
|
|
|
|
*/
|
2014-06-17 19:33:34 +01:00
|
|
|
inline bool saveAs(const char* pUrl, const char* pFormat = NULL, const char* pFilterOptions = NULL)
|
2013-11-15 12:09:10 +00:00
|
|
|
{
|
2014-11-14 10:56:40 +01:00
|
|
|
return mpDoc->pClass->saveAs(mpDoc, pUrl, pFormat, pFilterOptions) != 0;
|
2013-11-15 12:09:10 +00:00
|
|
|
}
|
2014-05-09 14:37:27 +01:00
|
|
|
|
2015-03-30 12:08:25 +02:00
|
|
|
/// Gives access to the underlying C pointer.
|
2014-06-12 13:28:26 +01:00
|
|
|
inline LibreOfficeKitDocument *get() { return mpDoc; }
|
2014-05-09 14:37:27 +01:00
|
|
|
|
|
|
|
#ifdef LOK_USE_UNSTABLE_API
|
2015-03-30 12:08:25 +02:00
|
|
|
/**
|
|
|
|
* Get document type.
|
|
|
|
*
|
|
|
|
* @return an element of the LibreOfficeKitDocumentType enum.
|
|
|
|
*/
|
2015-02-20 16:21:06 +01:00
|
|
|
inline int getDocumentType()
|
2014-05-09 14:37:27 +01:00
|
|
|
{
|
|
|
|
return mpDoc->pClass->getDocumentType(mpDoc);
|
|
|
|
}
|
|
|
|
|
2015-03-30 12:08:25 +02:00
|
|
|
/**
|
|
|
|
* Get number of part that the document contains.
|
|
|
|
*
|
|
|
|
* Part refers to either indivual sheets in a Calc, or slides in Impress,
|
|
|
|
* and has no relevance for Writer.
|
|
|
|
*/
|
2014-07-08 15:23:06 +02:00
|
|
|
inline int getParts()
|
2014-05-09 14:37:27 +01:00
|
|
|
{
|
2014-07-08 15:23:06 +02:00
|
|
|
return mpDoc->pClass->getParts(mpDoc);
|
|
|
|
}
|
|
|
|
|
2015-03-30 12:08:25 +02:00
|
|
|
/// Get the current part of the document.
|
2014-07-08 15:23:06 +02:00
|
|
|
inline int getPart()
|
|
|
|
{
|
|
|
|
return mpDoc->pClass->getPart(mpDoc);
|
2014-05-09 14:37:27 +01:00
|
|
|
}
|
|
|
|
|
2015-03-30 12:08:25 +02:00
|
|
|
/// Set the current part of the document.
|
2014-05-09 14:37:27 +01:00
|
|
|
inline void setPart(int nPart)
|
|
|
|
{
|
|
|
|
mpDoc->pClass->setPart(mpDoc, nPart);
|
|
|
|
}
|
|
|
|
|
2015-03-30 12:08:25 +02:00
|
|
|
/// Get the current part's name.
|
2014-07-29 08:50:34 +02:00
|
|
|
inline char* getPartName(int nPart)
|
|
|
|
{
|
|
|
|
return mpDoc->pClass->getPartName(mpDoc, nPart);
|
|
|
|
}
|
|
|
|
|
2015-03-30 12:08:25 +02:00
|
|
|
/**
|
|
|
|
* Renders a subset of the document to a pre-allocated buffer.
|
|
|
|
*
|
|
|
|
* Note that the buffer size and the tile size implicitly supports
|
|
|
|
* rendering at different zoom levels, as the number of rendered pixels and
|
|
|
|
* the rendered rectangle of the document are independent.
|
|
|
|
*
|
|
|
|
* @param pBuffer pointer to the buffer, its size is determined by nCanvasWidth and nCanvasHeight.
|
|
|
|
* @param nCanvasWidth number of pixels in a row of pBuffer.
|
|
|
|
* @param nCanvasHeight number of pixels in a column of pBuffer.
|
|
|
|
* @param nTilePosX logical X position of the top left corner of the rendered rectangle, in TWIPs.
|
|
|
|
* @param nTilePosY logical Y position of the top left corner of the rendered rectangle, in TWIPs.
|
|
|
|
* @param nTileWidth logical width of the rendered rectangle, in TWIPs.
|
|
|
|
* @param nTileHeight logical height of the rendered rectangle, in TWIPs.
|
|
|
|
*/
|
2014-06-11 16:24:33 +01:00
|
|
|
inline void paintTile(
|
|
|
|
unsigned char* pBuffer,
|
|
|
|
const int nCanvasWidth,
|
2014-05-09 14:37:27 +01:00
|
|
|
const int nCanvasHeight,
|
|
|
|
const int nTilePosX,
|
|
|
|
const int nTilePosY,
|
|
|
|
const int nTileWidth,
|
|
|
|
const int nTileHeight)
|
|
|
|
{
|
2015-03-20 13:12:08 +02:00
|
|
|
return mpDoc->pClass->paintTile(mpDoc, pBuffer, nCanvasWidth, nCanvasHeight,
|
2014-05-16 09:07:52 +01:00
|
|
|
nTilePosX, nTilePosY, nTileWidth, nTileHeight);
|
2014-05-09 14:37:27 +01:00
|
|
|
}
|
2014-05-18 08:36:16 +01:00
|
|
|
|
2015-03-30 12:08:25 +02:00
|
|
|
/// Get the document sizes in TWIPs.
|
2014-05-18 08:36:16 +01:00
|
|
|
inline void getDocumentSize(long* pWidth, long* pHeight)
|
|
|
|
{
|
2014-07-08 15:23:06 +02:00
|
|
|
mpDoc->pClass->getDocumentSize(mpDoc, pWidth, pHeight);
|
2014-05-18 08:36:16 +01:00
|
|
|
}
|
2014-12-29 16:10:48 +09:00
|
|
|
|
2015-03-30 12:08:25 +02:00
|
|
|
/**
|
|
|
|
* Initialize document for rendering.
|
|
|
|
*
|
|
|
|
* Sets the rendering and document parameters to default values that are
|
|
|
|
* needed to render the document correctly using tiled rendering. This
|
|
|
|
* method has to be called right after documentLoad() in case any of the
|
|
|
|
* tiled rendering methods are to be used later.
|
|
|
|
*/
|
2014-12-29 16:10:48 +09:00
|
|
|
inline void initializeForRendering()
|
|
|
|
{
|
|
|
|
mpDoc->pClass->initializeForRendering(mpDoc);
|
|
|
|
}
|
|
|
|
|
2015-01-06 15:49:12 +01:00
|
|
|
/**
|
|
|
|
* Registers a callback. LOK will invoke this function when it wants to
|
|
|
|
* inform the client about events.
|
|
|
|
*
|
|
|
|
* @param pCallback the callback to invoke
|
|
|
|
* @param pData the user data, will be passed to the callback on invocation
|
|
|
|
*/
|
|
|
|
inline void registerCallback(LibreOfficeKitCallback pCallback, void* pData)
|
|
|
|
{
|
|
|
|
mpDoc->pClass->registerCallback(mpDoc, pCallback, pData);
|
|
|
|
}
|
2015-01-21 12:42:08 +01:00
|
|
|
|
2015-02-27 15:38:30 +01:00
|
|
|
/**
|
|
|
|
* Posts a keyboard event to the focused frame.
|
|
|
|
*
|
|
|
|
* @param nType Event type, like press or release.
|
|
|
|
* @param nCharCode contains the Unicode character generated by this event or 0
|
|
|
|
* @param nKeyCode contains the integer code representing the key of the event (non-zero for control keys)
|
|
|
|
*/
|
|
|
|
inline void postKeyEvent(int nType, int nCharCode, int nKeyCode)
|
|
|
|
{
|
|
|
|
mpDoc->pClass->postKeyEvent(mpDoc, nType, nCharCode, nKeyCode);
|
|
|
|
}
|
|
|
|
|
2015-01-21 12:42:08 +01:00
|
|
|
/**
|
|
|
|
* Posts a mouse event to the document.
|
|
|
|
*
|
|
|
|
* @param nType Event type, like down, move or up.
|
|
|
|
* @param nX horizontal position in document coordinates
|
|
|
|
* @param nY vertical position in document coordinates
|
2015-02-05 14:19:35 +01:00
|
|
|
* @param nCount number of clicks: 1 for single click, 2 for double click
|
2015-01-21 12:42:08 +01:00
|
|
|
*/
|
2015-02-05 14:19:35 +01:00
|
|
|
inline void postMouseEvent(int nType, int nX, int nY, int nCount)
|
2015-01-21 12:42:08 +01:00
|
|
|
{
|
2015-02-05 14:19:35 +01:00
|
|
|
mpDoc->pClass->postMouseEvent(mpDoc, nType, nX, nY, nCount);
|
2015-01-21 12:42:08 +01:00
|
|
|
}
|
2015-02-10 17:43:18 +01:00
|
|
|
|
2015-03-12 14:59:59 +01:00
|
|
|
/**
|
|
|
|
* Posts an UNO command to the document.
|
|
|
|
*
|
2015-04-22 14:28:36 +02:00
|
|
|
* Example argument string:
|
|
|
|
*
|
|
|
|
* {
|
|
|
|
* "SearchItem.SearchString":
|
|
|
|
* {
|
|
|
|
* "type": "string",
|
|
|
|
* "value": "foobar"
|
|
|
|
* },
|
|
|
|
* "SearchItem.Backward":
|
|
|
|
* {
|
|
|
|
* "type": "boolean",
|
|
|
|
* "value": "false"
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
2015-03-12 14:59:59 +01:00
|
|
|
* @param pCommand uno command to be posted to the document, like ".uno:Bold"
|
2015-04-22 14:28:36 +02:00
|
|
|
* @param pArguments arguments of the uno command.
|
2015-03-12 14:59:59 +01:00
|
|
|
*/
|
2015-04-22 14:28:36 +02:00
|
|
|
inline void postUnoCommand(const char* pCommand, const char* pArguments = 0)
|
2015-03-12 14:59:59 +01:00
|
|
|
{
|
2015-04-22 14:28:36 +02:00
|
|
|
mpDoc->pClass->postUnoCommand(mpDoc, pCommand, pArguments);
|
2015-03-12 14:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-02-10 17:43:18 +01:00
|
|
|
/**
|
|
|
|
* Sets the start or end of a text selection.
|
|
|
|
*
|
|
|
|
* @param nType @see LibreOfficeKitSetTextSelectionType
|
|
|
|
* @param nX horizontal position in document coordinates
|
|
|
|
* @param nY vertical position in document coordinates
|
|
|
|
*/
|
|
|
|
inline void setTextSelection(int nType, int nX, int nY)
|
|
|
|
{
|
|
|
|
mpDoc->pClass->setTextSelection(mpDoc, nType, nX, nY);
|
|
|
|
}
|
2015-03-10 09:40:38 +01:00
|
|
|
|
2015-06-17 18:00:01 +02:00
|
|
|
/**
|
|
|
|
* Gets the currently selected text.
|
|
|
|
*
|
2015-06-19 18:13:27 +02:00
|
|
|
* @param pMimeType suggests the return format, for example text/plain;charset=utf-8.
|
|
|
|
* @param pUsedMimeType output parameter to inform about the determined format (suggested one or plain text).
|
2015-06-17 18:00:01 +02:00
|
|
|
*/
|
2015-06-19 18:13:27 +02:00
|
|
|
inline char* getTextSelection(const char* pMimeType, char** pUsedMimeType = 0)
|
2015-06-17 18:00:01 +02:00
|
|
|
{
|
2015-06-19 18:13:27 +02:00
|
|
|
return mpDoc->pClass->getTextSelection(mpDoc, pMimeType, pUsedMimeType);
|
2015-06-17 18:00:01 +02:00
|
|
|
}
|
|
|
|
|
2015-03-10 09:40:38 +01:00
|
|
|
/**
|
|
|
|
* Adjusts the graphic selection.
|
|
|
|
*
|
|
|
|
* @param nType @see LibreOfficeKitSetGraphicSelectionType
|
|
|
|
* @param nX horizontal position in document coordinates
|
|
|
|
* @param nY vertical position in document coordinates
|
|
|
|
*/
|
|
|
|
inline void setGraphicSelection(int nType, int nX, int nY)
|
|
|
|
{
|
|
|
|
mpDoc->pClass->setGraphicSelection(mpDoc, nType, nX, nY);
|
|
|
|
}
|
2015-03-10 16:13:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets rid of any text or graphic selection.
|
|
|
|
*/
|
|
|
|
inline void resetSelection()
|
|
|
|
{
|
|
|
|
mpDoc->pClass->resetSelection(mpDoc);
|
|
|
|
}
|
2014-05-09 14:37:27 +01:00
|
|
|
#endif // LOK_USE_UNSTABLE_API
|
2013-07-26 18:21:45 +01:00
|
|
|
};
|
2013-03-05 16:19:58 +00:00
|
|
|
|
2015-03-30 12:08:25 +02:00
|
|
|
/// The lok::Office class represents one started LibreOfficeKit instance.
|
2014-06-10 11:42:13 +01:00
|
|
|
class Office
|
2013-03-05 16:19:58 +00:00
|
|
|
{
|
2014-04-06 12:05:13 +02:00
|
|
|
private:
|
2014-06-10 11:31:51 +01:00
|
|
|
LibreOfficeKit* mpThis;
|
2014-04-06 12:05:13 +02:00
|
|
|
|
2013-03-05 16:19:58 +00:00
|
|
|
public:
|
2015-03-30 12:08:25 +02:00
|
|
|
/// A lok::Office is typically created by the lok_cpp_init() function.
|
2014-06-10 11:42:13 +01:00
|
|
|
inline Office(LibreOfficeKit* pThis) :
|
2014-04-06 12:05:13 +02:00
|
|
|
mpThis(pThis)
|
|
|
|
{}
|
2013-07-26 18:21:45 +01:00
|
|
|
|
2014-06-10 11:42:13 +01:00
|
|
|
inline ~Office()
|
2013-11-15 12:09:10 +00:00
|
|
|
{
|
2014-06-17 15:13:33 +01:00
|
|
|
mpThis->pClass->destroy(mpThis);
|
2013-11-15 12:09:10 +00:00
|
|
|
}
|
2013-03-05 16:19:58 +00:00
|
|
|
|
2015-03-30 12:08:25 +02:00
|
|
|
/**
|
|
|
|
* Loads a document from an URL.
|
|
|
|
*
|
|
|
|
* @param pUrl the URL of the document to load
|
|
|
|
* @param pFilterOptions options for the import filter, e.g. SkipImages.
|
|
|
|
*/
|
2015-02-17 17:12:45 +01:00
|
|
|
inline Document* documentLoad(const char* pUrl, const char* pFilterOptions = NULL)
|
2014-04-06 12:05:13 +02:00
|
|
|
{
|
2015-02-17 17:12:45 +01:00
|
|
|
LibreOfficeKitDocument* pDoc = NULL;
|
|
|
|
|
|
|
|
if (LIBREOFFICEKIT_HAS(mpThis, documentLoadWithOptions))
|
|
|
|
pDoc = mpThis->pClass->documentLoadWithOptions(mpThis, pUrl, pFilterOptions);
|
|
|
|
else
|
|
|
|
pDoc = mpThis->pClass->documentLoad(mpThis, pUrl);
|
|
|
|
|
2014-04-06 12:05:13 +02:00
|
|
|
if (pDoc == NULL)
|
2013-11-15 12:09:10 +00:00
|
|
|
return NULL;
|
2015-02-17 17:12:45 +01:00
|
|
|
|
2014-06-10 11:42:13 +01:00
|
|
|
return new Document(pDoc);
|
2013-11-15 12:09:10 +00:00
|
|
|
}
|
2013-03-05 16:19:58 +00:00
|
|
|
|
2015-03-30 12:08:25 +02:00
|
|
|
/// Returns the last error as a string, the returned pointer has to be freed by the caller.
|
2014-04-06 12:05:13 +02:00
|
|
|
inline char* getError()
|
|
|
|
{
|
2014-06-17 15:13:33 +01:00
|
|
|
return mpThis->pClass->getError(mpThis);
|
2014-04-06 12:05:13 +02:00
|
|
|
}
|
2013-03-05 16:19:58 +00:00
|
|
|
};
|
|
|
|
|
2015-03-30 12:08:25 +02:00
|
|
|
/// Factory method to create a lok::Office instance.
|
2015-05-06 21:17:51 +03:00
|
|
|
inline Office* lok_cpp_init(const char* pInstallPath, const char* pUserProfilePath = NULL)
|
2013-11-15 12:09:10 +00:00
|
|
|
{
|
2015-05-06 21:17:51 +03:00
|
|
|
LibreOfficeKit* pThis = lok_init_2(pInstallPath, pUserProfilePath);
|
2014-06-17 15:13:33 +01:00
|
|
|
if (pThis == NULL || pThis->pClass->nSize == 0)
|
2013-11-15 12:09:10 +00:00
|
|
|
return NULL;
|
2014-06-10 11:42:13 +01:00
|
|
|
return new ::lok::Office(pThis);
|
2013-11-15 12:09:10 +00:00
|
|
|
}
|
2013-03-05 16:19:58 +00:00
|
|
|
|
2014-06-11 15:37:17 +01:00
|
|
|
}
|
2015-02-02 11:03:13 +01:00
|
|
|
|
|
|
|
#endif // INCLUDED_LIBREOFFICEKIT_LIBREOFFICEKIT_HXX
|
|
|
|
|
2013-03-05 16:19:58 +00:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|