Bump version to 6.4-15
[LibreOffice.git] / include / LibreOfficeKit / LibreOfficeKit.hxx
blob2192d9870d01e9aaa672cc089556109b71633a98
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 <cstddef>
15 #include <LibreOfficeKit/LibreOfficeKit.h>
16 #include <LibreOfficeKit/LibreOfficeKitInit.h>
19 * The reasons this C++ code is not as pretty as it could be are:
20 * a) provide a pure C API - that's useful for some people
21 * b) allow ABI stability - C++ vtables are not good for that.
22 * c) avoid C++ types as part of the API.
24 namespace lok
27 /// The lok::Document class represents one loaded document instance.
28 class Document
30 private:
31 LibreOfficeKitDocument* mpDoc;
33 public:
34 /// A lok::Document is typically created by the lok::Office::documentLoad() method.
35 Document(LibreOfficeKitDocument* pDoc) :
36 mpDoc(pDoc)
39 ~Document()
41 mpDoc->pClass->destroy(mpDoc);
44 /**
45 * Stores the document's persistent data to a URL and
46 * continues to be a representation of the old URL.
48 * @param pUrl the location where to store the document
49 * @param pFormat the format to use while exporting, when omitted, then deducted from pURL's extension
50 * @param pFilterOptions options for the export filter, e.g. SkipImages.
51 * Another useful FilterOption is "TakeOwnership". It is consumed
52 * by the saveAs() itself, and when provided, the document identity
53 * changes to the provided pUrl - meaning that '.uno:ModifiedStatus'
54 * is triggered as with the "Save As..." in the UI.
55 * "TakeOwnership" mode must not be used when saving to PNG or PDF.
57 bool saveAs(const char* pUrl, const char* pFormat = NULL, const char* pFilterOptions = NULL)
59 return mpDoc->pClass->saveAs(mpDoc, pUrl, pFormat, pFilterOptions) != 0;
62 /// Gives access to the underlying C pointer.
63 LibreOfficeKitDocument *get() { return mpDoc; }
65 /**
66 * Get document type.
68 * @since LibreOffice 6.0
69 * @return an element of the LibreOfficeKitDocumentType enum.
71 int getDocumentType()
73 return mpDoc->pClass->getDocumentType(mpDoc);
76 #if defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
77 /**
78 * Get number of part that the document contains.
80 * Part refers to either individual sheets in a Calc, or slides in Impress,
81 * and has no relevance for Writer.
83 int getParts()
85 return mpDoc->pClass->getParts(mpDoc);
88 /**
89 * Get the logical rectangle of each part in the document.
91 * A part refers to an individual page in Writer and has no relevant for
92 * Calc or Impress.
94 * @return a rectangle list, using the same format as
95 * LOK_CALLBACK_TEXT_SELECTION.
97 char* getPartPageRectangles()
99 return mpDoc->pClass->getPartPageRectangles(mpDoc);
102 /// Get the current part of the document.
103 int getPart()
105 return mpDoc->pClass->getPart(mpDoc);
108 /// Set the current part of the document.
109 void setPart(int nPart)
111 mpDoc->pClass->setPart(mpDoc, nPart);
114 /// Get the current part's name.
115 char* getPartName(int nPart)
117 return mpDoc->pClass->getPartName(mpDoc, nPart);
120 /// Get the current part's hash.
121 char* getPartHash(int nPart)
123 return mpDoc->pClass->getPartHash(mpDoc, nPart);
126 void setPartMode(int nMode)
128 mpDoc->pClass->setPartMode(mpDoc, nMode);
132 * Renders a subset of the document to a pre-allocated buffer.
134 * Note that the buffer size and the tile size implicitly supports
135 * rendering at different zoom levels, as the number of rendered pixels and
136 * the rendered rectangle of the document are independent.
138 * @param pBuffer pointer to the buffer, its size is determined by nCanvasWidth and nCanvasHeight.
139 * @param nCanvasWidth number of pixels in a row of pBuffer.
140 * @param nCanvasHeight number of pixels in a column of pBuffer.
141 * @param nTilePosX logical X position of the top left corner of the rendered rectangle, in TWIPs.
142 * @param nTilePosY logical Y position of the top left corner of the rendered rectangle, in TWIPs.
143 * @param nTileWidth logical width of the rendered rectangle, in TWIPs.
144 * @param nTileHeight logical height of the rendered rectangle, in TWIPs.
146 void paintTile(unsigned char* pBuffer,
147 const int nCanvasWidth,
148 const int nCanvasHeight,
149 const int nTilePosX,
150 const int nTilePosY,
151 const int nTileWidth,
152 const int nTileHeight)
154 return mpDoc->pClass->paintTile(mpDoc, pBuffer, nCanvasWidth, nCanvasHeight,
155 nTilePosX, nTilePosY, nTileWidth, nTileHeight);
159 * Renders a window (dialog, popup, etc.) with give id
161 * @param nWindowId
162 * @param pBuffer Buffer with enough memory allocated to render any dialog
163 * @param x x-coordinate from where the dialog should start painting
164 * @param y y-coordinate from where the dialog should start painting
165 * @param width The width of the dialog image to be painted
166 * @param height The height of the dialog image to be painted
167 * @param dpiscale The dpi scale value used by the client. Please note
168 * that the x, y, width, height are supposed to be the
169 * values with dpiscale applied (ie. dialog covering
170 * 100x100 "normal" pixels with dpiscale '2' will have
171 * 200x200 width x height), so that it is easy to compute
172 * the buffer sizes etc.
174 void paintWindow(unsigned nWindowId,
175 unsigned char* pBuffer,
176 const int x,
177 const int y,
178 const int width,
179 const int height,
180 const double dpiscale = 1.0,
181 const int viewId = -1)
183 return mpDoc->pClass->paintWindowForView(mpDoc, nWindowId, pBuffer, x, y,
184 width, height, dpiscale, viewId);
188 * Posts a command to the window (dialog, popup, etc.) with given id
190 * @param nWindowid
192 void postWindow(unsigned nWindowId, int nAction, const char* pData = nullptr)
194 return mpDoc->pClass->postWindow(mpDoc, nWindowId, nAction, pData);
198 * Gets the tile mode: the pixel format used for the pBuffer of paintTile().
200 * @return an element of the LibreOfficeKitTileMode enum.
202 int getTileMode()
204 return mpDoc->pClass->getTileMode(mpDoc);
207 /// Get the document sizes in TWIPs.
208 void getDocumentSize(long* pWidth, long* pHeight)
210 mpDoc->pClass->getDocumentSize(mpDoc, pWidth, pHeight);
214 * Initialize document for rendering.
216 * Sets the rendering and document parameters to default values that are
217 * needed to render the document correctly using tiled rendering. This
218 * method has to be called right after documentLoad() in case any of the
219 * tiled rendering methods are to be used later.
221 * Example argument string for text documents:
224 * ".uno:HideWhitespace":
226 * "type": "boolean",
227 * "value": "true"
231 * @param pArguments arguments of the rendering
233 void initializeForRendering(const char* pArguments = NULL)
235 mpDoc->pClass->initializeForRendering(mpDoc, pArguments);
239 * Registers a callback. LOK will invoke this function when it wants to
240 * inform the client about events.
242 * @param pCallback the callback to invoke
243 * @param pData the user data, will be passed to the callback on invocation
245 void registerCallback(LibreOfficeKitCallback pCallback, void* pData)
247 mpDoc->pClass->registerCallback(mpDoc, pCallback, pData);
251 * Posts a keyboard event to the focused frame.
253 * @param nType Event type, like press or release.
254 * @param nCharCode contains the Unicode character generated by this event or 0
255 * @param nKeyCode contains the integer code representing the key of the event (non-zero for control keys)
257 void postKeyEvent(int nType, int nCharCode, int nKeyCode)
259 mpDoc->pClass->postKeyEvent(mpDoc, nType, nCharCode, nKeyCode);
263 * Posts a keyboard event to the dialog
265 * @param nWindowId
266 * @param nType Event type, like press or release.
267 * @param nCharCode contains the Unicode character generated by this event or 0
268 * @param nKeyCode contains the integer code representing the key of the event (non-zero for control keys)
270 void postWindowKeyEvent(unsigned nWindowId, int nType, int nCharCode, int nKeyCode)
272 mpDoc->pClass->postWindowKeyEvent(mpDoc, nWindowId, nType, nCharCode, nKeyCode);
276 * Posts a mouse event to the document.
278 * @param nType Event type, like down, move or up.
279 * @param nX horizontal position in document coordinates
280 * @param nY vertical position in document coordinates
281 * @param nCount number of clicks: 1 for single click, 2 for double click
282 * @param nButtons: which mouse buttons: 1 for left, 2 for middle, 4 right
283 * @param nModifier: which keyboard modifier: (see include/vcl/vclenum.hxx for possible values)
285 void postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier)
287 mpDoc->pClass->postMouseEvent(mpDoc, nType, nX, nY, nCount, nButtons, nModifier);
291 * Posts a mouse event to the window with given id.
293 * @param nWindowId
294 * @param nType Event type, like down, move or up.
295 * @param nX horizontal position in document coordinates
296 * @param nY vertical position in document coordinates
297 * @param nCount number of clicks: 1 for single click, 2 for double click
298 * @param nButtons: which mouse buttons: 1 for left, 2 for middle, 4 right
299 * @param nModifier: which keyboard modifier: (see include/vcl/vclenum.hxx for possible values)
301 void postWindowMouseEvent(unsigned nWindowId, int nType, int nX, int nY, int nCount, int nButtons, int nModifier)
303 mpDoc->pClass->postWindowMouseEvent(mpDoc, nWindowId, nType, nX, nY, nCount, nButtons, nModifier);
307 * Posts a dialog event for the window with given id
309 * @param nWindowId id of the window to notify
310 * @param pArguments arguments of the event.
312 void sendDialogEvent(unsigned long long int nWindowId, const char* pArguments = NULL)
314 mpDoc->pClass->sendDialogEvent(mpDoc, nWindowId, pArguments);
318 * Posts a UNO command to the document.
320 * Example argument string:
323 * "SearchItem.SearchString":
325 * "type": "string",
326 * "value": "foobar"
327 * },
328 * "SearchItem.Backward":
330 * "type": "boolean",
331 * "value": "false"
335 * @param pCommand uno command to be posted to the document, like ".uno:Bold"
336 * @param pArguments arguments of the uno command.
338 void postUnoCommand(const char* pCommand, const char* pArguments = NULL, bool bNotifyWhenFinished = false)
340 mpDoc->pClass->postUnoCommand(mpDoc, pCommand, pArguments, bNotifyWhenFinished);
344 * Sets the start or end of a text selection.
346 * @param nType @see LibreOfficeKitSetTextSelectionType
347 * @param nX horizontal position in document coordinates
348 * @param nY vertical position in document coordinates
350 void setTextSelection(int nType, int nX, int nY)
352 mpDoc->pClass->setTextSelection(mpDoc, nType, nX, nY);
356 * Gets the currently selected text.
358 * @param pMimeType suggests the return format, for example text/plain;charset=utf-8.
359 * @param pUsedMimeType output parameter to inform about the determined format (suggested one or plain text).
361 char* getTextSelection(const char* pMimeType, char** pUsedMimeType = NULL)
363 return mpDoc->pClass->getTextSelection(mpDoc, pMimeType, pUsedMimeType);
367 * Gets the type of the selected content.
369 * @return an element of the LibreOfficeKitSelectionType enum.
371 int getSelectionType()
373 return mpDoc->pClass->getSelectionType(mpDoc);
377 * Gets the content on the clipboard for the current view as a series of binary streams.
379 * NB. returns a complete set of possible selection types if nullptr is passed for pMimeTypes.
381 * @param pMimeTypes passes in a nullptr terminated list of mime types to fetch
382 * @param pOutCount returns the size of the other @pOut arrays
383 * @param pOutMimeTypes returns an array of mime types
384 * @param pOutSizes returns the size of each pOutStream
385 * @param pOutStreams the content of each mime-type, of length in @pOutSizes
387 * @returns: true on success, false on error.
389 bool getClipboard(const char **pMimeTypes,
390 size_t *pOutCount,
391 char ***pOutMimeTypes,
392 size_t **pOutSizes,
393 char ***pOutStreams)
395 return mpDoc->pClass->getClipboard(mpDoc, pMimeTypes, pOutCount, pOutMimeTypes, pOutSizes, pOutStreams);
399 * Populates the clipboard for this view with multiple types of content.
401 * @param nInCount the number of types to paste
402 * @param pInMimeTypes array of mime type strings
403 * @param pInSizes array of sizes of the data to paste
404 * @param pInStreams array containing the data of the various types
406 * @return if the supplied data was populated successfully.
408 bool setClipboard(const size_t nInCount,
409 const char **pInMimeTypes,
410 const size_t *pInSizes,
411 const char **pInStreams)
413 return mpDoc->pClass->setClipboard(mpDoc, nInCount, pInMimeTypes, pInSizes, pInStreams);
417 * Pastes content at the current cursor position.
419 * @param pMimeType format of pData, for example text/plain;charset=utf-8.
420 * @param pData the actual data to be pasted.
421 * @return if the supplied data was pasted successfully.
423 bool paste(const char* pMimeType, const char* pData, size_t nSize)
425 return mpDoc->pClass->paste(mpDoc, pMimeType, pData, nSize);
429 * Adjusts the graphic selection.
431 * @param nType @see LibreOfficeKitSetGraphicSelectionType
432 * @param nX horizontal position in document coordinates
433 * @param nY vertical position in document coordinates
435 void setGraphicSelection(int nType, int nX, int nY)
437 mpDoc->pClass->setGraphicSelection(mpDoc, nType, nX, nY);
441 * Gets rid of any text or graphic selection.
443 void resetSelection()
445 mpDoc->pClass->resetSelection(mpDoc);
449 * Returns a json mapping of the possible values for the given command
450 * e.g. {commandName: ".uno:StyleApply", commandValues: {"familyName1" : ["list of style names in the family1"], etc.}}
451 * @param pCommand a UNO command for which the possible values are requested
452 * @return {commandName: unoCmd, commandValues: {possible_values}}
454 char* getCommandValues(const char* pCommand)
456 return mpDoc->pClass->getCommandValues(mpDoc, pCommand);
460 * Save the client's view so that we can compute the right zoom level
461 * for the mouse events. This only affects CALC.
462 * @param nTilePixelWidth - tile width in pixels
463 * @param nTilePixelHeight - tile height in pixels
464 * @param nTileTwipWidth - tile width in twips
465 * @param nTileTwipHeight - tile height in twips
467 void setClientZoom(
468 int nTilePixelWidth,
469 int nTilePixelHeight,
470 int nTileTwipWidth,
471 int nTileTwipHeight)
473 mpDoc->pClass->setClientZoom(mpDoc, nTilePixelWidth, nTilePixelHeight, nTileTwipWidth, nTileTwipHeight);
477 * Inform core about the currently visible area of the document on the
478 * client, so that it can perform e.g. page down (which depends on the
479 * visible height) in a sane way.
481 * @param nX - top left corner horizontal position
482 * @param nY - top left corner vertical position
483 * @param nWidth - area width
484 * @param nHeight - area height
486 void setClientVisibleArea(int nX, int nY, int nWidth, int nHeight)
488 mpDoc->pClass->setClientVisibleArea(mpDoc, nX, nY, nWidth, nHeight);
492 * Show/Hide a single row/column header outline for Calc documents.
494 * @param bColumn - if we are dealing with a column or row group
495 * @param nLevel - the level to which the group belongs
496 * @param nIndex - the group entry index
497 * @param bHidden - the new group state (collapsed/expanded)
499 void setOutlineState(bool bColumn, int nLevel, int nIndex, bool bHidden)
501 mpDoc->pClass->setOutlineState(mpDoc, bColumn, nLevel, nIndex, bHidden);
505 * Create a new view for an existing document with
506 * options similar to documentLoadWithOptions.
507 * By default a loaded document has 1 view.
508 * @return the ID of the new view.
510 int createView(const char* pOptions = nullptr)
512 if (LIBREOFFICEKIT_DOCUMENT_HAS(mpDoc, createViewWithOptions))
513 return mpDoc->pClass->createViewWithOptions(mpDoc, pOptions);
514 else
515 return mpDoc->pClass->createView(mpDoc);
519 * Destroy a view of an existing document.
520 * @param nId a view ID, returned by createView().
522 void destroyView(int nId)
524 mpDoc->pClass->destroyView(mpDoc, nId);
528 * Set an existing view of an existing document as current.
529 * @param nId a view ID, returned by createView().
531 void setView(int nId)
533 mpDoc->pClass->setView(mpDoc, nId);
537 * Get the current view.
538 * @return a view ID, previously returned by createView().
540 int getView()
542 return mpDoc->pClass->getView(mpDoc);
546 * Get number of views of this document.
548 int getViewsCount()
550 return mpDoc->pClass->getViewsCount(mpDoc);
554 * Paints a font name or character if provided to be displayed in the font list
555 * @param pFontName the font to be painted
557 unsigned char* renderFont(const char *pFontName,
558 const char *pChar,
559 int *pFontWidth,
560 int *pFontHeight,
561 int pOrientation=0)
563 if (LIBREOFFICEKIT_DOCUMENT_HAS(mpDoc, renderFontOrientation))
564 return mpDoc->pClass->renderFontOrientation(mpDoc, pFontName, pChar, pFontWidth, pFontHeight, pOrientation);
565 else
566 return mpDoc->pClass->renderFont(mpDoc, pFontName, pChar, pFontWidth, pFontHeight);
570 * Renders a subset of the document's part to a pre-allocated buffer.
572 * @param nPart the part number of the document of which the tile is painted.
573 * @see paintTile.
575 void paintPartTile(unsigned char* pBuffer,
576 const int nPart,
577 const int nCanvasWidth,
578 const int nCanvasHeight,
579 const int nTilePosX,
580 const int nTilePosY,
581 const int nTileWidth,
582 const int nTileHeight)
584 return mpDoc->pClass->paintPartTile(mpDoc, pBuffer, nPart,
585 nCanvasWidth, nCanvasHeight,
586 nTilePosX, nTilePosY,
587 nTileWidth, nTileHeight);
591 * Returns the viewID for each existing view. Since viewIDs are not reused,
592 * viewIDs are not the same as the index of the view in the view array over
593 * time. Use getViewsCount() to know the minimal nSize that's large enough.
595 * @param pArray the array to write the viewIDs into
596 * @param nSize the size of pArray
597 * @returns true if pArray was large enough and result is written, false
598 * otherwise.
600 bool getViewIds(int* pArray,
601 size_t nSize)
603 return mpDoc->pClass->getViewIds(mpDoc, pArray, nSize);
607 * Set the language tag of the window with the specified nId.
609 * @param nId a view ID, returned by createView().
610 * @param language Bcp47 languageTag, like en-US or so.
612 void setViewLanguage(int nId, const char* language)
614 mpDoc->pClass->setViewLanguage(mpDoc, nId, language);
618 * Post the text input from external input window, like IME, to given windowId
620 * @param nWindowId Specify the window id to post the input event to. If
621 * nWindow is 0, the event is posted into the document
622 * @param nType see LibreOfficeKitExtTextInputType
623 * @param pText Text for LOK_EXT_TEXTINPUT
625 void postWindowExtTextInputEvent(unsigned nWindowId, int nType, const char* pText)
627 mpDoc->pClass->postWindowExtTextInputEvent(mpDoc, nWindowId, nType, pText);
630 #ifdef IOS
632 * Renders a subset of the document to a Core Graphics context.
634 * Note that the buffer size and the tile size implicitly supports
635 * rendering at different zoom levels, as the number of rendered pixels and
636 * the rendered rectangle of the document are independent.
638 * @param rCGContext the CGContextRef, cast to a void*.
639 * @param nCanvasHeight number of pixels in a column of pBuffer.
640 * @param nTilePosX logical X position of the top left corner of the rendered rectangle, in TWIPs.
641 * @param nTilePosY logical Y position of the top left corner of the rendered rectangle, in TWIPs.
642 * @param nTileWidth logical width of the rendered rectangle, in TWIPs.
643 * @param nTileHeight logical height of the rendered rectangle, in TWIPs.
645 void paintTileToCGContext(void* rCGContext,
646 const int nCanvasWidth,
647 const int nCanvasHeight,
648 const int nTilePosX,
649 const int nTilePosY,
650 const int nTileWidth,
651 const int nTileHeight)
653 return mpDoc->pClass->paintTileToCGContext(mpDoc, rCGContext, nCanvasWidth, nCanvasHeight,
654 nTilePosX, nTilePosY, nTileWidth, nTileHeight);
656 #endif // IOS
659 * Insert certificate (in binary form) to the certificate store.
661 bool insertCertificate(const unsigned char* pCertificateBinary,
662 const int pCertificateBinarySize,
663 const unsigned char* pPrivateKeyBinary,
664 const int nPrivateKeyBinarySize)
666 return mpDoc->pClass->insertCertificate(mpDoc,
667 pCertificateBinary, pCertificateBinarySize,
668 pPrivateKeyBinary, nPrivateKeyBinarySize);
672 * Add the certificate (in binary form) to the certificate store.
675 bool addCertificate(const unsigned char* pCertificateBinary,
676 const int pCertificateBinarySize)
678 return mpDoc->pClass->addCertificate(mpDoc,
679 pCertificateBinary, pCertificateBinarySize);
683 * Verify signature of the document.
685 * Check possible values in include/sfx2/signaturestate.hxx
687 int getSignatureState()
689 return mpDoc->pClass->getSignatureState(mpDoc);
693 * Gets an image of the selected shapes.
694 * @param pOutput contains the result; use free to deallocate.
695 * @return the size of *pOutput in bytes.
697 size_t renderShapeSelection(char** pOutput)
699 return mpDoc->pClass->renderShapeSelection(mpDoc, pOutput);
703 * Posts a gesture event to the window with given id.
705 * @param nWindowId
706 * @param pType Event type, like panStart, panEnd, panUpdate.
707 * @param nX horizontal position in document coordinates
708 * @param nY vertical position in document coordinates
709 * @param nOffset difference value from when the gesture started to current value
711 void postWindowGestureEvent(unsigned nWindowId,
712 const char* pType,
713 int nX, int nY, int nOffset)
715 return mpDoc->pClass->postWindowGestureEvent(mpDoc, nWindowId, pType, nX, nY, nOffset);
718 /// Set a part's selection mode.
719 /// nSelect is 0 to deselect, 1 to select, and 2 to toggle.
720 void selectPart(int nPart, int nSelect)
722 mpDoc->pClass->selectPart(mpDoc, nPart, nSelect);
725 /// Moves the selected pages/slides to a new position.
726 /// nPosition is the new position where the selection
727 /// should go. bDuplicate when true will copy instead of move.
728 void moveSelectedParts(int nPosition, bool bDuplicate)
730 mpDoc->pClass->moveSelectedParts(mpDoc, nPosition, bDuplicate);
734 * Resize a window (dialog, popup, etc.) with give id.
736 * @param nWindowId
737 * @param width The width of the window.
738 * @param height The height of the window.
740 void resizeWindow(unsigned nWindowId,
741 const int width,
742 const int height)
744 return mpDoc->pClass->resizeWindow(mpDoc, nWindowId, width, height);
748 * For deleting many characters all at once
750 * @param nWindowId Specify the window id to post the input event to. If
751 * nWindow is 0, the event is posted into the document
752 * @param nBefore The characters to be deleted before the cursor position
753 * @param nAfter The characters to be deleted after the cursor position
755 void removeTextContext(unsigned nWindowId, int nBefore, int nAfter)
757 mpDoc->pClass->removeTextContext(mpDoc, nWindowId, nBefore, nAfter);
761 * Select the Calc function to be pasted into the formula input box
763 * @param nIndex is the index of the selected function
765 void completeFunction(const char* pFunctionName)
767 mpDoc->pClass->completeFunction(mpDoc, pFunctionName);
771 * Sets the start or end of a text selection for a dialog.
773 * @param nWindowId
774 * @param bSwap swap anchor and cursor position of current selection
775 * @param nX horizontal position in document coordinates
776 * @param nY vertical position in document coordinates
778 void setWindowTextSelection(unsigned nWindowId, bool bSwap, int nX, int nY)
780 mpDoc->pClass->setWindowTextSelection(mpDoc, nWindowId, bSwap, nX, nY);
784 * Posts an event for the form field at the cursor position.
786 * @param pArguments arguments of the event.
788 void sendFormFieldEvent(const char* pArguments)
790 mpDoc->pClass->sendFormFieldEvent(mpDoc, pArguments);
793 #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
796 /// The lok::Office class represents one started LibreOfficeKit instance.
797 class Office
799 private:
800 LibreOfficeKit* mpThis;
802 public:
803 /// A lok::Office is typically created by the lok_cpp_init() function.
804 Office(LibreOfficeKit* pThis) :
805 mpThis(pThis)
808 ~Office()
810 mpThis->pClass->destroy(mpThis);
814 * Loads a document from a URL.
816 * @param pUrl the URL of the document to load
817 * @param pFilterOptions options for the import filter, e.g. SkipImages.
818 * Another useful FilterOption is "Language=...". It is consumed
819 * by the documentLoad() itself, and when provided, LibreOfficeKit
820 * switches the language accordingly first.
821 * @since pFilterOptions argument added in LibreOffice 5.0
823 Document* documentLoad(const char* pUrl, const char* pFilterOptions = NULL)
825 LibreOfficeKitDocument* pDoc = NULL;
827 if (LIBREOFFICEKIT_HAS(mpThis, documentLoadWithOptions))
828 pDoc = mpThis->pClass->documentLoadWithOptions(mpThis, pUrl, pFilterOptions);
829 else
830 pDoc = mpThis->pClass->documentLoad(mpThis, pUrl);
832 if (pDoc == NULL)
833 return NULL;
835 return new Document(pDoc);
838 /// Returns the last error as a string, the returned pointer has to be freed by the caller.
839 char* getError()
841 return mpThis->pClass->getError(mpThis);
845 * Frees the memory pointed to by pFree.
847 * @since LibreOffice 5.2
849 void freeError(char* pFree)
851 mpThis->pClass->freeError(pFree);
855 * Registers a callback. LOK will invoke this function when it wants to
856 * inform the client about events.
858 * @since LibreOffice 6.0
859 * @param pCallback the callback to invoke
860 * @param pData the user data, will be passed to the callback on invocation
862 void registerCallback(LibreOfficeKitCallback pCallback, void* pData)
864 mpThis->pClass->registerCallback(mpThis, pCallback, pData);
868 * Returns details of filter types.
870 * Example returned string:
873 * "writer8": {
874 * "MediaType": "application/vnd.oasis.opendocument.text"
875 * },
876 * "calc8": {
877 * "MediaType": "application/vnd.oasis.opendocument.spreadsheet"
881 * @since LibreOffice 6.0
883 char* getFilterTypes()
885 return mpThis->pClass->getFilterTypes(mpThis);
889 * Set bitmask of optional features supported by the client.
891 * @since LibreOffice 6.0
892 * @see LibreOfficeKitOptionalFeatures
894 void setOptionalFeatures(unsigned long long features)
896 return mpThis->pClass->setOptionalFeatures(mpThis, features);
900 * Set password required for loading or editing a document.
902 * Loading the document is blocked until the password is provided.
904 * @param pURL the URL of the document, as sent to the callback
905 * @param pPassword the password, nullptr indicates no password
907 * In response to LOK_CALLBACK_DOCUMENT_PASSWORD, a valid password
908 * will continue loading the document, an invalid password will
909 * result in another LOK_CALLBACK_DOCUMENT_PASSWORD request,
910 * and a NULL password will abort loading the document.
912 * In response to LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY, a valid
913 * password will continue loading the document, an invalid password will
914 * result in another LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY request,
915 * and a NULL password will continue loading the document in read-only
916 * mode.
918 * @since LibreOffice 6.0
920 void setDocumentPassword(char const* pURL, char const* pPassword)
922 mpThis->pClass->setDocumentPassword(mpThis, pURL, pPassword);
926 * Get version information of the LOKit process
928 * @since LibreOffice 6.0
929 * @returns JSON string containing version information in format:
930 * {ProductName: <>, ProductVersion: <>, ProductExtension: <>, BuildId: <>}
932 * Eg: {"ProductName": "LibreOffice",
933 * "ProductVersion": "5.3",
934 * "ProductExtension": ".0.0.alpha0",
935 * "BuildId": "<full 40 char git hash>"}
937 char* getVersionInfo()
939 return mpThis->pClass->getVersionInfo(mpThis);
943 * Run a macro.
945 * Same syntax as on command line is permissible (ie. the macro:// URI forms)
947 * @since LibreOffice 6.0
948 * @param pURL macro url to run
951 bool runMacro( const char* pURL)
953 return mpThis->pClass->runMacro( mpThis, pURL );
957 * Exports the document and signes its content.
959 bool signDocument(const char* pURL,
960 const unsigned char* pCertificateBinary, const int nCertificateBinarySize,
961 const unsigned char* pPrivateKeyBinary, const int nPrivateKeyBinarySize)
963 return mpThis->pClass->signDocument(mpThis, pURL,
964 pCertificateBinary, nCertificateBinarySize,
965 pPrivateKeyBinary, nPrivateKeyBinarySize);
969 * Runs the main-loop in the current thread. To trigger this
970 * mode you need to putenv a SAL_LOK_OPTIONS containing 'unipoll'.
971 * The @pPollCallback is called to poll for events from the Kit client
972 * and the @pWakeCallback can be called by internal LibreOfficeKit threads
973 * to wake the caller of 'runLoop' ie. the main thread.
975 * it is expected that runLoop does not return until Kit exit.
977 * @pData is a context/closure passed to both methods.
979 void runLoop(LibreOfficeKitPollCallback pPollCallback,
980 LibreOfficeKitWakeCallback pWakeCallback,
981 void* pData)
983 mpThis->pClass->runLoop(mpThis, pPollCallback, pWakeCallback, pData);
987 /// Factory method to create a lok::Office instance.
988 inline Office* lok_cpp_init(const char* pInstallPath, const char* pUserProfileUrl = NULL)
990 LibreOfficeKit* pThis = lok_init_2(pInstallPath, pUserProfileUrl);
991 if (pThis == NULL || pThis->pClass->nSize == 0)
992 return NULL;
993 return new ::lok::Office(pThis);
998 #endif // INCLUDED_LIBREOFFICEKIT_LIBREOFFICEKIT_HXX
1000 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */