tdf#97569 docxexport: export russianUpper/russianLower numbering
[LibreOffice.git] / include / LibreOfficeKit / LibreOfficeKit.hxx
blob962270452e20e01931cd59b318b8b67cc9477c41
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 #pragma once
12 #include <LibreOfficeKit/LibreOfficeKit.h>
13 #include <LibreOfficeKit/LibreOfficeKitInit.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 Document(LibreOfficeKitDocument* pDoc) :
33 mpDoc(pDoc)
36 ~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.
48 * Another useful FilterOption is "TakeOwnership". It is consumed
49 * by the saveAs() itself, and when provided, the document identity
50 * changes to the provided pUrl - meaning that '.uno:ModifiedStatus'
51 * is triggered as with the "Save As..." in the UI.
52 * "TakeOwnership" mode must not be used when saving to PNG or PDF.
54 bool saveAs(const char* pUrl, const char* pFormat = NULL, const char* pFilterOptions = NULL)
56 return mpDoc->pClass->saveAs(mpDoc, pUrl, pFormat, pFilterOptions) != 0;
59 /// Gives access to the underlying C pointer.
60 LibreOfficeKitDocument *get() { return mpDoc; }
62 /**
63 * Get document type.
65 * @since LibreOffice 6.0
66 * @return an element of the LibreOfficeKitDocumentType enum.
68 int getDocumentType()
70 return mpDoc->pClass->getDocumentType(mpDoc);
73 #if defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
74 /**
75 * Get number of part that the document contains.
77 * Part refers to either individual sheets in a Calc, or slides in Impress,
78 * and has no relevance for Writer.
80 int getParts()
82 return mpDoc->pClass->getParts(mpDoc);
85 /**
86 * Get the logical rectangle of each part in the document.
88 * A part refers to an individual page in Writer and has no relevant for
89 * Calc or Impress.
91 * @return a rectangle list, using the same format as
92 * LOK_CALLBACK_TEXT_SELECTION.
94 char* getPartPageRectangles()
96 return mpDoc->pClass->getPartPageRectangles(mpDoc);
99 /// Get the current part of the document.
100 int getPart()
102 return mpDoc->pClass->getPart(mpDoc);
105 /// Set the current part of the document.
106 void setPart(int nPart)
108 mpDoc->pClass->setPart(mpDoc, nPart);
111 /// Get the current part's name.
112 char* getPartName(int nPart)
114 return mpDoc->pClass->getPartName(mpDoc, nPart);
117 /// Get the current part's hash.
118 char* getPartHash(int nPart)
120 return mpDoc->pClass->getPartHash(mpDoc, nPart);
123 void setPartMode(int nMode)
125 mpDoc->pClass->setPartMode(mpDoc, nMode);
129 * Renders a subset of the document to a pre-allocated buffer.
131 * Note that the buffer size and the tile size implicitly supports
132 * rendering at different zoom levels, as the number of rendered pixels and
133 * the rendered rectangle of the document are independent.
135 * @param pBuffer pointer to the buffer, its size is determined by nCanvasWidth and nCanvasHeight.
136 * @param nCanvasWidth number of pixels in a row of pBuffer.
137 * @param nCanvasHeight number of pixels in a column of pBuffer.
138 * @param nTilePosX logical X position of the top left corner of the rendered rectangle, in TWIPs.
139 * @param nTilePosY logical Y position of the top left corner of the rendered rectangle, in TWIPs.
140 * @param nTileWidth logical width of the rendered rectangle, in TWIPs.
141 * @param nTileHeight logical height of the rendered rectangle, in TWIPs.
143 void paintTile(unsigned char* pBuffer,
144 const int nCanvasWidth,
145 const int nCanvasHeight,
146 const int nTilePosX,
147 const int nTilePosY,
148 const int nTileWidth,
149 const int nTileHeight)
151 return mpDoc->pClass->paintTile(mpDoc, pBuffer, nCanvasWidth, nCanvasHeight,
152 nTilePosX, nTilePosY, nTileWidth, nTileHeight);
156 * Renders a window (dialog, popup, etc.) with give id
158 * @param nWindowId
159 * @param pBuffer Buffer with enough memory allocated to render any dialog
160 * @param x x-coordinate from where the dialog should start painting
161 * @param y y-coordinate from where the dialog should start painting
162 * @param width The width of the dialog image to be painted
163 * @param height The height of the dialog image to be painted
164 * @param dpiscale The dpi scale value used by the client. Please note
165 * that the x, y, width, height are supposed to be the
166 * values with dpiscale applied (ie. dialog covering
167 * 100x100 "normal" pixels with dpiscale '2' will have
168 * 200x200 width x height), so that it is easy to compute
169 * the buffer sizes etc.
171 void paintWindow(unsigned nWindowId,
172 unsigned char* pBuffer,
173 const int x,
174 const int y,
175 const int width,
176 const int height,
177 const double dpiscale = 1.0,
178 const int viewId = -1)
180 return mpDoc->pClass->paintWindowForView(mpDoc, nWindowId, pBuffer, x, y,
181 width, height, dpiscale, viewId);
185 * Posts a command to the window (dialog, popup, etc.) with given id
187 * @param nWindowid
189 void postWindow(unsigned nWindowId, int nAction, const char* pData = nullptr)
191 return mpDoc->pClass->postWindow(mpDoc, nWindowId, nAction, pData);
195 * Gets the tile mode: the pixel format used for the pBuffer of paintTile().
197 * @return an element of the LibreOfficeKitTileMode enum.
199 int getTileMode()
201 return mpDoc->pClass->getTileMode(mpDoc);
204 /// Get the document sizes in TWIPs.
205 void getDocumentSize(long* pWidth, long* pHeight)
207 mpDoc->pClass->getDocumentSize(mpDoc, pWidth, pHeight);
211 * Initialize document for rendering.
213 * Sets the rendering and document parameters to default values that are
214 * needed to render the document correctly using tiled rendering. This
215 * method has to be called right after documentLoad() in case any of the
216 * tiled rendering methods are to be used later.
218 * Example argument string for text documents:
221 * ".uno:HideWhitespace":
223 * "type": "boolean",
224 * "value": "true"
228 * @param pArguments arguments of the rendering
230 void initializeForRendering(const char* pArguments = NULL)
232 mpDoc->pClass->initializeForRendering(mpDoc, pArguments);
236 * Registers a callback. LOK will invoke this function when it wants to
237 * inform the client about events.
239 * @param pCallback the callback to invoke
240 * @param pData the user data, will be passed to the callback on invocation
242 void registerCallback(LibreOfficeKitCallback pCallback, void* pData)
244 mpDoc->pClass->registerCallback(mpDoc, pCallback, pData);
248 * Posts a keyboard event to the focused frame.
250 * @param nType Event type, like press or release.
251 * @param nCharCode contains the Unicode character generated by this event or 0
252 * @param nKeyCode contains the integer code representing the key of the event (non-zero for control keys)
254 void postKeyEvent(int nType, int nCharCode, int nKeyCode)
256 mpDoc->pClass->postKeyEvent(mpDoc, nType, nCharCode, nKeyCode);
260 * Posts a keyboard event to the dialog
262 * @param nWindowId
263 * @param nType Event type, like press or release.
264 * @param nCharCode contains the Unicode character generated by this event or 0
265 * @param nKeyCode contains the integer code representing the key of the event (non-zero for control keys)
267 void postWindowKeyEvent(unsigned nWindowId, int nType, int nCharCode, int nKeyCode)
269 mpDoc->pClass->postWindowKeyEvent(mpDoc, nWindowId, nType, nCharCode, nKeyCode);
273 * Posts a mouse event to the document.
275 * @param nType Event type, like down, move or up.
276 * @param nX horizontal position in document coordinates
277 * @param nY vertical position in document coordinates
278 * @param nCount number of clicks: 1 for single click, 2 for double click
279 * @param nButtons: which mouse buttons: 1 for left, 2 for middle, 4 right
280 * @param nModifier: which keyboard modifier: (see include/vcl/vclenum.hxx for possible values)
282 void postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier)
284 mpDoc->pClass->postMouseEvent(mpDoc, nType, nX, nY, nCount, nButtons, nModifier);
288 * Posts a mouse event to the window with given id.
290 * @param nWindowId
291 * @param nType Event type, like down, move or up.
292 * @param nX horizontal position in document coordinates
293 * @param nY vertical position in document coordinates
294 * @param nCount number of clicks: 1 for single click, 2 for double click
295 * @param nButtons: which mouse buttons: 1 for left, 2 for middle, 4 right
296 * @param nModifier: which keyboard modifier: (see include/vcl/vclenum.hxx for possible values)
298 void postWindowMouseEvent(unsigned nWindowId, int nType, int nX, int nY, int nCount, int nButtons, int nModifier)
300 mpDoc->pClass->postWindowMouseEvent(mpDoc, nWindowId, nType, nX, nY, nCount, nButtons, nModifier);
304 * Posts a dialog event for the window with given id
306 * @param nWindowId id of the window to notify
307 * @param pArguments arguments of the event.
309 void sendDialogEvent(unsigned long long int nWindowId, const char* pArguments = NULL)
311 mpDoc->pClass->sendDialogEvent(mpDoc, nWindowId, pArguments);
315 * Posts a UNO command to the document.
317 * Example argument string:
320 * "SearchItem.SearchString":
322 * "type": "string",
323 * "value": "foobar"
324 * },
325 * "SearchItem.Backward":
327 * "type": "boolean",
328 * "value": "false"
332 * @param pCommand uno command to be posted to the document, like ".uno:Bold"
333 * @param pArguments arguments of the uno command.
335 void postUnoCommand(const char* pCommand, const char* pArguments = NULL, bool bNotifyWhenFinished = false)
337 mpDoc->pClass->postUnoCommand(mpDoc, pCommand, pArguments, bNotifyWhenFinished);
341 * Sets the start or end of a text selection.
343 * @param nType @see LibreOfficeKitSetTextSelectionType
344 * @param nX horizontal position in document coordinates
345 * @param nY vertical position in document coordinates
347 void setTextSelection(int nType, int nX, int nY)
349 mpDoc->pClass->setTextSelection(mpDoc, nType, nX, nY);
353 * Gets the currently selected text.
355 * @param pMimeType suggests the return format, for example text/plain;charset=utf-8.
356 * @param pUsedMimeType output parameter to inform about the determined format (suggested one or plain text).
358 char* getTextSelection(const char* pMimeType, char** pUsedMimeType = NULL)
360 return mpDoc->pClass->getTextSelection(mpDoc, pMimeType, pUsedMimeType);
364 * Gets the type of the selected content.
366 * @return an element of the LibreOfficeKitSelectionType enum.
368 int getSelectionType()
370 return mpDoc->pClass->getSelectionType(mpDoc);
374 * Gets the content on the clipboard for the current view as a series of binary streams.
376 * NB. returns a complete set of possible selection types if nullptr is passed for pMimeTypes.
378 * @param pMimeTypes passes in a nullptr terminated list of mime types to fetch
379 * @param pOutCount returns the size of the other @pOut arrays
380 * @param pOutMimeTypes returns an array of mime types
381 * @param pOutSizes returns the size of each pOutStream
382 * @param pOutStreams the content of each mime-type, of length in @pOutSizes
384 * @returns: true on success, false on error.
386 bool getClipboard(const char **pMimeTypes,
387 size_t *pOutCount,
388 char ***pOutMimeTypes,
389 size_t **pOutSizes,
390 char ***pOutStreams)
392 return mpDoc->pClass->getClipboard(mpDoc, pMimeTypes, pOutCount, pOutMimeTypes, pOutSizes, pOutStreams);
396 * Populates the clipboard for this view with multiple types of content.
398 * @param nInCount the number of types to paste
399 * @param pInMimeTypes array of mime type strings
400 * @param pInSizes array of sizes of the data to paste
401 * @param pInStreams array containing the data of the various types
403 * @return if the supplied data was populated successfully.
405 bool setClipboard(const size_t nInCount,
406 const char **pInMimeTypes,
407 const size_t *pInSizes,
408 const char **pInStreams)
410 return mpDoc->pClass->setClipboard(mpDoc, nInCount, pInMimeTypes, pInSizes, pInStreams);
414 * Pastes content at the current cursor position.
416 * @param pMimeType format of pData, for example text/plain;charset=utf-8.
417 * @param pData the actual data to be pasted.
418 * @return if the supplied data was pasted successfully.
420 bool paste(const char* pMimeType, const char* pData, size_t nSize)
422 return mpDoc->pClass->paste(mpDoc, pMimeType, pData, nSize);
426 * Adjusts the graphic selection.
428 * @param nType @see LibreOfficeKitSetGraphicSelectionType
429 * @param nX horizontal position in document coordinates
430 * @param nY vertical position in document coordinates
432 void setGraphicSelection(int nType, int nX, int nY)
434 mpDoc->pClass->setGraphicSelection(mpDoc, nType, nX, nY);
438 * Gets rid of any text or graphic selection.
440 void resetSelection()
442 mpDoc->pClass->resetSelection(mpDoc);
446 * Returns a json mapping of the possible values for the given command
447 * e.g. {commandName: ".uno:StyleApply", commandValues: {"familyName1" : ["list of style names in the family1"], etc.}}
448 * @param pCommand a UNO command for which the possible values are requested
449 * @return {commandName: unoCmd, commandValues: {possible_values}}
451 char* getCommandValues(const char* pCommand)
453 return mpDoc->pClass->getCommandValues(mpDoc, pCommand);
457 * Save the client's view so that we can compute the right zoom level
458 * for the mouse events. This only affects CALC.
459 * @param nTilePixelWidth - tile width in pixels
460 * @param nTilePixelHeight - tile height in pixels
461 * @param nTileTwipWidth - tile width in twips
462 * @param nTileTwipHeight - tile height in twips
464 void setClientZoom(
465 int nTilePixelWidth,
466 int nTilePixelHeight,
467 int nTileTwipWidth,
468 int nTileTwipHeight)
470 mpDoc->pClass->setClientZoom(mpDoc, nTilePixelWidth, nTilePixelHeight, nTileTwipWidth, nTileTwipHeight);
474 * Inform core about the currently visible area of the document on the
475 * client, so that it can perform e.g. page down (which depends on the
476 * visible height) in a sane way.
478 * @param nX - top left corner horizontal position
479 * @param nY - top left corner vertical position
480 * @param nWidth - area width
481 * @param nHeight - area height
483 void setClientVisibleArea(int nX, int nY, int nWidth, int nHeight)
485 mpDoc->pClass->setClientVisibleArea(mpDoc, nX, nY, nWidth, nHeight);
489 * Show/Hide a single row/column header outline for Calc documents.
491 * @param bColumn - if we are dealing with a column or row group
492 * @param nLevel - the level to which the group belongs
493 * @param nIndex - the group entry index
494 * @param bHidden - the new group state (collapsed/expanded)
496 void setOutlineState(bool bColumn, int nLevel, int nIndex, bool bHidden)
498 mpDoc->pClass->setOutlineState(mpDoc, bColumn, nLevel, nIndex, bHidden);
502 * Create a new view for an existing document with
503 * options similar to documentLoadWithOptions.
504 * By default a loaded document has 1 view.
505 * @return the ID of the new view.
507 int createView(const char* pOptions = nullptr)
509 if (LIBREOFFICEKIT_DOCUMENT_HAS(mpDoc, createViewWithOptions))
510 return mpDoc->pClass->createViewWithOptions(mpDoc, pOptions);
511 else
512 return mpDoc->pClass->createView(mpDoc);
516 * Destroy a view of an existing document.
517 * @param nId a view ID, returned by createView().
519 void destroyView(int nId)
521 mpDoc->pClass->destroyView(mpDoc, nId);
525 * Set an existing view of an existing document as current.
526 * @param nId a view ID, returned by createView().
528 void setView(int nId)
530 mpDoc->pClass->setView(mpDoc, nId);
534 * Get the current view.
535 * @return a view ID, previously returned by createView().
537 int getView()
539 return mpDoc->pClass->getView(mpDoc);
543 * Get number of views of this document.
545 int getViewsCount()
547 return mpDoc->pClass->getViewsCount(mpDoc);
551 * Paints a font name or character if provided to be displayed in the font list
552 * @param pFontName the font to be painted
554 unsigned char* renderFont(const char *pFontName,
555 const char *pChar,
556 int *pFontWidth,
557 int *pFontHeight,
558 int pOrientation=0)
560 if (LIBREOFFICEKIT_DOCUMENT_HAS(mpDoc, renderFontOrientation))
561 return mpDoc->pClass->renderFontOrientation(mpDoc, pFontName, pChar, pFontWidth, pFontHeight, pOrientation);
562 else
563 return mpDoc->pClass->renderFont(mpDoc, pFontName, pChar, pFontWidth, pFontHeight);
567 * Renders a subset of the document's part to a pre-allocated buffer.
569 * @param nPart the part number of the document of which the tile is painted.
570 * @see paintTile.
572 void paintPartTile(unsigned char* pBuffer,
573 const int nPart,
574 const int nCanvasWidth,
575 const int nCanvasHeight,
576 const int nTilePosX,
577 const int nTilePosY,
578 const int nTileWidth,
579 const int nTileHeight)
581 return mpDoc->pClass->paintPartTile(mpDoc, pBuffer, nPart,
582 nCanvasWidth, nCanvasHeight,
583 nTilePosX, nTilePosY,
584 nTileWidth, nTileHeight);
588 * Returns the viewID for each existing view. Since viewIDs are not reused,
589 * viewIDs are not the same as the index of the view in the view array over
590 * time. Use getViewsCount() to know the minimal nSize that's large enough.
592 * @param pArray the array to write the viewIDs into
593 * @param nSize the size of pArray
594 * @returns true if pArray was large enough and result is written, false
595 * otherwise.
597 bool getViewIds(int* pArray,
598 size_t nSize)
600 return mpDoc->pClass->getViewIds(mpDoc, pArray, nSize);
604 * Set the language tag of the window with the specified nId.
606 * @param nId a view ID, returned by createView().
607 * @param language Bcp47 languageTag, like en-US or so.
609 void setViewLanguage(int nId, const char* language)
611 mpDoc->pClass->setViewLanguage(mpDoc, nId, language);
615 * Post the text input from external input window, like IME, to given windowId
617 * @param nWindowId Specify the window id to post the input event to. If
618 * nWindow is 0, the event is posted into the document
619 * @param nType see LibreOfficeKitExtTextInputType
620 * @param pText Text for LOK_EXT_TEXTINPUT
622 void postWindowExtTextInputEvent(unsigned nWindowId, int nType, const char* pText)
624 mpDoc->pClass->postWindowExtTextInputEvent(mpDoc, nWindowId, nType, pText);
627 #ifdef IOS
629 * Renders a subset of the document to a Core Graphics context.
631 * Note that the buffer size and the tile size implicitly supports
632 * rendering at different zoom levels, as the number of rendered pixels and
633 * the rendered rectangle of the document are independent.
635 * @param rCGContext the CGContextRef, cast to a void*.
636 * @param nCanvasHeight number of pixels in a column of pBuffer.
637 * @param nTilePosX logical X position of the top left corner of the rendered rectangle, in TWIPs.
638 * @param nTilePosY logical Y position of the top left corner of the rendered rectangle, in TWIPs.
639 * @param nTileWidth logical width of the rendered rectangle, in TWIPs.
640 * @param nTileHeight logical height of the rendered rectangle, in TWIPs.
642 void paintTileToCGContext(void* rCGContext,
643 const int nCanvasWidth,
644 const int nCanvasHeight,
645 const int nTilePosX,
646 const int nTilePosY,
647 const int nTileWidth,
648 const int nTileHeight)
650 return mpDoc->pClass->paintTileToCGContext(mpDoc, rCGContext, nCanvasWidth, nCanvasHeight,
651 nTilePosX, nTilePosY, nTileWidth, nTileHeight);
653 #endif // IOS
656 * Insert certificate (in binary form) to the certificate store.
658 bool insertCertificate(const unsigned char* pCertificateBinary,
659 const int pCertificateBinarySize,
660 const unsigned char* pPrivateKeyBinary,
661 const int nPrivateKeyBinarySize)
663 return mpDoc->pClass->insertCertificate(mpDoc,
664 pCertificateBinary, pCertificateBinarySize,
665 pPrivateKeyBinary, nPrivateKeyBinarySize);
669 * Add the certificate (in binary form) to the certificate store.
672 bool addCertificate(const unsigned char* pCertificateBinary,
673 const int pCertificateBinarySize)
675 return mpDoc->pClass->addCertificate(mpDoc,
676 pCertificateBinary, pCertificateBinarySize);
680 * Verify signature of the document.
682 * Check possible values in include/sfx2/signaturestate.hxx
684 int getSignatureState()
686 return mpDoc->pClass->getSignatureState(mpDoc);
690 * Gets an image of the selected shapes.
691 * @param pOutput contains the result; use free to deallocate.
692 * @return the size of *pOutput in bytes.
694 size_t renderShapeSelection(char** pOutput)
696 return mpDoc->pClass->renderShapeSelection(mpDoc, pOutput);
700 * Posts a gesture event to the window with given id.
702 * @param nWindowId
703 * @param pType Event type, like panStart, panEnd, panUpdate.
704 * @param nX horizontal position in document coordinates
705 * @param nY vertical position in document coordinates
706 * @param nOffset difference value from when the gesture started to current value
708 void postWindowGestureEvent(unsigned nWindowId,
709 const char* pType,
710 int nX, int nY, int nOffset)
712 return mpDoc->pClass->postWindowGestureEvent(mpDoc, nWindowId, pType, nX, nY, nOffset);
715 /// Set a part's selection mode.
716 /// nSelect is 0 to deselect, 1 to select, and 2 to toggle.
717 void selectPart(int nPart, int nSelect)
719 mpDoc->pClass->selectPart(mpDoc, nPart, nSelect);
722 /// Moves the selected pages/slides to a new position.
723 /// nPosition is the new position where the selection
724 /// should go. bDuplicate when true will copy instead of move.
725 void moveSelectedParts(int nPosition, bool bDuplicate)
727 mpDoc->pClass->moveSelectedParts(mpDoc, nPosition, bDuplicate);
731 * Resize a window (dialog, popup, etc.) with give id.
733 * @param nWindowId
734 * @param width The width of the window.
735 * @param height The height of the window.
737 void resizeWindow(unsigned nWindowId,
738 const int width,
739 const int height)
741 return mpDoc->pClass->resizeWindow(mpDoc, nWindowId, width, height);
745 * For deleting many characters all at once
747 * @param nWindowId Specify the window id to post the input event to. If
748 * nWindow is 0, the event is posted into the document
749 * @param nBefore The characters to be deleted before the cursor position
750 * @param nAfter The characters to be deleted after the cursor position
752 void removeTextContext(unsigned nWindowId, int nBefore, int nAfter)
754 mpDoc->pClass->removeTextContext(mpDoc, nWindowId, nBefore, nAfter);
758 * Select the Calc function to be pasted into the formula input box
760 * @param nIndex is the index of the selected function
762 void completeFunction(const char* pFunctionName)
764 mpDoc->pClass->completeFunction(mpDoc, pFunctionName);
768 * Sets the start or end of a text selection for a dialog.
770 * @param nWindowId
771 * @param bSwap swap anchor and cursor position of current selection
772 * @param nX horizontal position in document coordinates
773 * @param nY vertical position in document coordinates
775 void setWindowTextSelection(unsigned nWindowId, bool bSwap, int nX, int nY)
777 mpDoc->pClass->setWindowTextSelection(mpDoc, nWindowId, bSwap, nX, nY);
781 * Posts an event for the form field at the cursor position.
783 * @param pArguments arguments of the event.
785 void sendFormFieldEvent(const char* pArguments)
787 mpDoc->pClass->sendFormFieldEvent(mpDoc, pArguments);
790 #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
793 /// The lok::Office class represents one started LibreOfficeKit instance.
794 class Office
796 private:
797 LibreOfficeKit* mpThis;
799 public:
800 /// A lok::Office is typically created by the lok_cpp_init() function.
801 Office(LibreOfficeKit* pThis) :
802 mpThis(pThis)
805 ~Office()
807 mpThis->pClass->destroy(mpThis);
811 * Loads a document from a URL.
813 * @param pUrl the URL of the document to load
814 * @param pFilterOptions options for the import filter, e.g. SkipImages.
815 * Another useful FilterOption is "Language=...". It is consumed
816 * by the documentLoad() itself, and when provided, LibreOfficeKit
817 * switches the language accordingly first.
818 * @since pFilterOptions argument added in LibreOffice 5.0
820 Document* documentLoad(const char* pUrl, const char* pFilterOptions = NULL)
822 LibreOfficeKitDocument* pDoc = NULL;
824 if (LIBREOFFICEKIT_HAS(mpThis, documentLoadWithOptions))
825 pDoc = mpThis->pClass->documentLoadWithOptions(mpThis, pUrl, pFilterOptions);
826 else
827 pDoc = mpThis->pClass->documentLoad(mpThis, pUrl);
829 if (pDoc == NULL)
830 return NULL;
832 return new Document(pDoc);
835 /// Returns the last error as a string, the returned pointer has to be freed by the caller.
836 char* getError()
838 return mpThis->pClass->getError(mpThis);
842 * Frees the memory pointed to by pFree.
844 * @since LibreOffice 5.2
846 void freeError(char* pFree)
848 mpThis->pClass->freeError(pFree);
852 * Registers a callback. LOK will invoke this function when it wants to
853 * inform the client about events.
855 * @since LibreOffice 6.0
856 * @param pCallback the callback to invoke
857 * @param pData the user data, will be passed to the callback on invocation
859 void registerCallback(LibreOfficeKitCallback pCallback, void* pData)
861 mpThis->pClass->registerCallback(mpThis, pCallback, pData);
865 * Returns details of filter types.
867 * Example returned string:
870 * "writer8": {
871 * "MediaType": "application/vnd.oasis.opendocument.text"
872 * },
873 * "calc8": {
874 * "MediaType": "application/vnd.oasis.opendocument.spreadsheet"
878 * @since LibreOffice 6.0
880 char* getFilterTypes()
882 return mpThis->pClass->getFilterTypes(mpThis);
886 * Set bitmask of optional features supported by the client.
888 * @since LibreOffice 6.0
889 * @see LibreOfficeKitOptionalFeatures
891 void setOptionalFeatures(unsigned long long features)
893 return mpThis->pClass->setOptionalFeatures(mpThis, features);
897 * Set password required for loading or editing a document.
899 * Loading the document is blocked until the password is provided.
901 * @param pURL the URL of the document, as sent to the callback
902 * @param pPassword the password, nullptr indicates no password
904 * In response to LOK_CALLBACK_DOCUMENT_PASSWORD, a valid password
905 * will continue loading the document, an invalid password will
906 * result in another LOK_CALLBACK_DOCUMENT_PASSWORD request,
907 * and a NULL password will abort loading the document.
909 * In response to LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY, a valid
910 * password will continue loading the document, an invalid password will
911 * result in another LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY request,
912 * and a NULL password will continue loading the document in read-only
913 * mode.
915 * @since LibreOffice 6.0
917 void setDocumentPassword(char const* pURL, char const* pPassword)
919 mpThis->pClass->setDocumentPassword(mpThis, pURL, pPassword);
923 * Get version information of the LOKit process
925 * @since LibreOffice 6.0
926 * @returns JSON string containing version information in format:
927 * {ProductName: <>, ProductVersion: <>, ProductExtension: <>, BuildId: <>}
929 * Eg: {"ProductName": "LibreOffice",
930 * "ProductVersion": "5.3",
931 * "ProductExtension": ".0.0.alpha0",
932 * "BuildId": "<full 40 char git hash>"}
934 char* getVersionInfo()
936 return mpThis->pClass->getVersionInfo(mpThis);
940 * Run a macro.
942 * Same syntax as on command line is permissible (ie. the macro:// URI forms)
944 * @since LibreOffice 6.0
945 * @param pURL macro url to run
948 bool runMacro( const char* pURL)
950 return mpThis->pClass->runMacro( mpThis, pURL );
954 * Exports the document and signes its content.
956 bool signDocument(const char* pURL,
957 const unsigned char* pCertificateBinary, const int nCertificateBinarySize,
958 const unsigned char* pPrivateKeyBinary, const int nPrivateKeyBinarySize)
960 return mpThis->pClass->signDocument(mpThis, pURL,
961 pCertificateBinary, nCertificateBinarySize,
962 pPrivateKeyBinary, nPrivateKeyBinarySize);
966 * Runs the main-loop in the current thread. To trigger this
967 * mode you need to putenv a SAL_LOK_OPTIONS containing 'unipoll'.
968 * The @pPollCallback is called to poll for events from the Kit client
969 * and the @pWakeCallback can be called by internal LibreOfficeKit threads
970 * to wake the caller of 'runLoop' ie. the main thread.
972 * it is expected that runLoop does not return until Kit exit.
974 * @pData is a context/closure passed to both methods.
976 void runLoop(LibreOfficeKitPollCallback pPollCallback,
977 LibreOfficeKitWakeCallback pWakeCallback,
978 void* pData)
980 mpThis->pClass->runLoop(mpThis, pPollCallback, pWakeCallback, pData);
984 * Posts a dialog event for the window with given id
986 * @param nWindowId id of the window to notify
987 * @param pArguments arguments of the event.
989 void sendDialogEvent(unsigned long long int nWindowId, const char* pArguments = NULL)
991 mpThis->pClass->sendDialogEvent(mpThis, nWindowId, pArguments);
995 /// Factory method to create a lok::Office instance.
996 inline Office* lok_cpp_init(const char* pInstallPath, const char* pUserProfileUrl = NULL)
998 LibreOfficeKit* pThis = lok_init_2(pInstallPath, pUserProfileUrl);
999 if (pThis == NULL || pThis->pClass->nSize == 0)
1000 return NULL;
1001 return new ::lok::Office(pThis);
1006 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */