update emoji autocorrect entries from po-files
[LibreOffice.git] / include / LibreOfficeKit / LibreOfficeKit.hxx
blob816ade5649b2039229bc71f09e5382aa1d92bc39
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef INCLUDED_LIBREOFFICEKIT_LIBREOFFICEKIT_HXX
11 #define INCLUDED_LIBREOFFICEKIT_LIBREOFFICEKIT_HXX
13 #include "LibreOfficeKit.h"
16 * The reasons this C++ code is not as pretty as it could be are:
17 * a) provide a pure C API - that's useful for some people
18 * b) allow ABI stability - C++ vtables are not good for that.
19 * c) avoid C++ types as part of the API.
21 namespace lok
24 /// The lok::Document class represents one loaded document instance.
25 class Document
27 private:
28 LibreOfficeKitDocument* mpDoc;
30 public:
31 /// A lok::Document is typically created by the lok::Office::documentLoad() method.
32 inline Document(LibreOfficeKitDocument* pDoc) :
33 mpDoc(pDoc)
36 inline ~Document()
38 mpDoc->pClass->destroy(mpDoc);
41 /**
42 * Stores the document's persistent data to a URL and
43 * continues to be a representation of the old URL.
45 * @param pUrl the location where to store the document
46 * @param pFormat the format to use while exporting, when omitted, then deducted from pURL's extension
47 * @param pFilterOptions options for the export filter, e.g. SkipImages.
49 inline bool saveAs(const char* pUrl, const char* pFormat = NULL, const char* pFilterOptions = NULL)
51 return mpDoc->pClass->saveAs(mpDoc, pUrl, pFormat, pFilterOptions) != 0;
54 /// Gives access to the underlying C pointer.
55 inline LibreOfficeKitDocument *get() { return mpDoc; }
57 #ifdef LOK_USE_UNSTABLE_API
58 /**
59 * Get document type.
61 * @return an element of the LibreOfficeKitDocumentType enum.
63 inline int getDocumentType()
65 return mpDoc->pClass->getDocumentType(mpDoc);
68 /**
69 * Get number of part that the document contains.
71 * Part refers to either indivual sheets in a Calc, or slides in Impress,
72 * and has no relevance for Writer.
74 inline int getParts()
76 return mpDoc->pClass->getParts(mpDoc);
79 /// Get the current part of the document.
80 inline int getPart()
82 return mpDoc->pClass->getPart(mpDoc);
85 /// Set the current part of the document.
86 inline void setPart(int nPart)
88 mpDoc->pClass->setPart(mpDoc, nPart);
91 /// Get the current part's name.
92 inline char* getPartName(int nPart)
94 return mpDoc->pClass->getPartName(mpDoc, nPart);
97 /**
98 * Renders a subset of the document to a pre-allocated buffer.
100 * Note that the buffer size and the tile size implicitly supports
101 * rendering at different zoom levels, as the number of rendered pixels and
102 * the rendered rectangle of the document are independent.
104 * @param pBuffer pointer to the buffer, its size is determined by nCanvasWidth and nCanvasHeight.
105 * @param nCanvasWidth number of pixels in a row of pBuffer.
106 * @param nCanvasHeight number of pixels in a column of pBuffer.
107 * @param nTilePosX logical X position of the top left corner of the rendered rectangle, in TWIPs.
108 * @param nTilePosY logical Y position of the top left corner of the rendered rectangle, in TWIPs.
109 * @param nTileWidth logical width of the rendered rectangle, in TWIPs.
110 * @param nTileHeight logical height of the rendered rectangle, in TWIPs.
112 inline void paintTile(
113 unsigned char* pBuffer,
114 const int nCanvasWidth,
115 const int nCanvasHeight,
116 const int nTilePosX,
117 const int nTilePosY,
118 const int nTileWidth,
119 const int nTileHeight)
121 return mpDoc->pClass->paintTile(mpDoc, pBuffer, nCanvasWidth, nCanvasHeight,
122 nTilePosX, nTilePosY, nTileWidth, nTileHeight);
125 /// Get the document sizes in TWIPs.
126 inline void getDocumentSize(long* pWidth, long* pHeight)
128 mpDoc->pClass->getDocumentSize(mpDoc, pWidth, pHeight);
132 * Initialize document for rendering.
134 * Sets the rendering and document parameters to default values that are
135 * needed to render the document correctly using tiled rendering. This
136 * method has to be called right after documentLoad() in case any of the
137 * tiled rendering methods are to be used later.
139 inline void initializeForRendering()
141 mpDoc->pClass->initializeForRendering(mpDoc);
145 * Registers a callback. LOK will invoke this function when it wants to
146 * inform the client about events.
148 * @param pCallback the callback to invoke
149 * @param pData the user data, will be passed to the callback on invocation
151 inline void registerCallback(LibreOfficeKitCallback pCallback, void* pData)
153 mpDoc->pClass->registerCallback(mpDoc, pCallback, pData);
157 * Posts a keyboard event to the focused frame.
159 * @param nType Event type, like press or release.
160 * @param nCharCode contains the Unicode character generated by this event or 0
161 * @param nKeyCode contains the integer code representing the key of the event (non-zero for control keys)
163 inline void postKeyEvent(int nType, int nCharCode, int nKeyCode)
165 mpDoc->pClass->postKeyEvent(mpDoc, nType, nCharCode, nKeyCode);
169 * Posts a mouse event to the document.
171 * @param nType Event type, like down, move or up.
172 * @param nX horizontal position in document coordinates
173 * @param nY vertical position in document coordinates
174 * @param nCount number of clicks: 1 for single click, 2 for double click
176 inline void postMouseEvent(int nType, int nX, int nY, int nCount)
178 mpDoc->pClass->postMouseEvent(mpDoc, nType, nX, nY, nCount);
182 * Posts an UNO command to the document.
184 * Example argument string:
187 * "SearchItem.SearchString":
189 * "type": "string",
190 * "value": "foobar"
191 * },
192 * "SearchItem.Backward":
194 * "type": "boolean",
195 * "value": "false"
199 * @param pCommand uno command to be posted to the document, like ".uno:Bold"
200 * @param pArguments arguments of the uno command.
202 inline void postUnoCommand(const char* pCommand, const char* pArguments = 0)
204 mpDoc->pClass->postUnoCommand(mpDoc, pCommand, pArguments);
208 * Sets the start or end of a text selection.
210 * @param nType @see LibreOfficeKitSetTextSelectionType
211 * @param nX horizontal position in document coordinates
212 * @param nY vertical position in document coordinates
214 inline void setTextSelection(int nType, int nX, int nY)
216 mpDoc->pClass->setTextSelection(mpDoc, nType, nX, nY);
220 * Gets the currently selected text.
222 * @param pMimeType suggests the return format, for example text/plain;charset=utf-8.
223 * @param pUsedMimeType output parameter to inform about the determined format (suggested one or plain text).
225 inline char* getTextSelection(const char* pMimeType, char** pUsedMimeType = 0)
227 return mpDoc->pClass->getTextSelection(mpDoc, pMimeType, pUsedMimeType);
231 * Adjusts the graphic selection.
233 * @param nType @see LibreOfficeKitSetGraphicSelectionType
234 * @param nX horizontal position in document coordinates
235 * @param nY vertical position in document coordinates
237 inline void setGraphicSelection(int nType, int nX, int nY)
239 mpDoc->pClass->setGraphicSelection(mpDoc, nType, nX, nY);
243 * Gets rid of any text or graphic selection.
245 inline void resetSelection()
247 mpDoc->pClass->resetSelection(mpDoc);
249 #endif // LOK_USE_UNSTABLE_API
252 /// The lok::Office class represents one started LibreOfficeKit instance.
253 class Office
255 private:
256 LibreOfficeKit* mpThis;
258 public:
259 /// A lok::Office is typically created by the lok_cpp_init() function.
260 inline Office(LibreOfficeKit* pThis) :
261 mpThis(pThis)
264 inline ~Office()
266 mpThis->pClass->destroy(mpThis);
270 * Loads a document from an URL.
272 * @param pUrl the URL of the document to load
273 * @param pFilterOptions options for the import filter, e.g. SkipImages.
275 inline Document* documentLoad(const char* pUrl, const char* pFilterOptions = NULL)
277 LibreOfficeKitDocument* pDoc = NULL;
279 if (LIBREOFFICEKIT_HAS(mpThis, documentLoadWithOptions))
280 pDoc = mpThis->pClass->documentLoadWithOptions(mpThis, pUrl, pFilterOptions);
281 else
282 pDoc = mpThis->pClass->documentLoad(mpThis, pUrl);
284 if (pDoc == NULL)
285 return NULL;
287 return new Document(pDoc);
290 /// Returns the last error as a string, the returned pointer has to be freed by the caller.
291 inline char* getError()
293 return mpThis->pClass->getError(mpThis);
297 /// Factory method to create a lok::Office instance.
298 inline Office* lok_cpp_init(const char* pInstallPath, const char* pUserProfilePath = NULL)
300 LibreOfficeKit* pThis = lok_init_2(pInstallPath, pUserProfilePath);
301 if (pThis == NULL || pThis->pClass->nSize == 0)
302 return NULL;
303 return new ::lok::Office(pThis);
308 #endif // INCLUDED_LIBREOFFICEKIT_LIBREOFFICEKIT_HXX
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */