Version 24.8.3.2, tag libreoffice-24.8.3.2
[LibreOffice.git] / include / LibreOfficeKit / LibreOfficeKit.hxx
blob2d58fb0ce1e065afc2ffacc67f52d1e9f79c8ca7
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.h"
13 #include "LibreOfficeKitEnums.h"
14 #include "LibreOfficeKitInit.h"
17 * The reasons this C++ code is not as pretty as it could be are:
18 * a) provide a pure C API - that's useful for some people
19 * b) allow ABI stability - C++ vtables are not good for that.
20 * c) avoid C++ types as part of the API.
22 namespace lok
25 /// The lok::Document class represents one loaded document instance.
26 class Document
28 private:
29 LibreOfficeKitDocument* mpDoc;
31 public:
32 /// A lok::Document is typically created by the lok::Office::documentLoad() method.
33 Document(LibreOfficeKitDocument* pDoc) :
34 mpDoc(pDoc)
37 ~Document()
39 mpDoc->pClass->destroy(mpDoc);
42 /**
43 * Stores the document's persistent data to a URL and
44 * continues to be a representation of the old URL.
46 * @param pUrl the location where to store the document
47 * @param pFormat the format to use while exporting, when omitted, then deducted from pURL's extension
48 * @param pFilterOptions options for the export filter, e.g. SkipImages.
49 * Another useful FilterOption is "TakeOwnership". It is consumed
50 * by the saveAs() itself, and when provided, the document identity
51 * changes to the provided pUrl - meaning that '.uno:ModifiedStatus'
52 * is triggered as with the "Save As..." in the UI.
53 * "TakeOwnership" mode must not be used when saving to PNG or PDF.
55 bool saveAs(const char* pUrl, const char* pFormat = NULL, const char* pFilterOptions = NULL)
57 return mpDoc->pClass->saveAs(mpDoc, pUrl, pFormat, pFilterOptions) != 0;
60 /// Gives access to the underlying C pointer.
61 LibreOfficeKitDocument *get() { return mpDoc; }
63 /**
64 * Get document type.
66 * @since LibreOffice 6.0
67 * @return an element of the LibreOfficeKitDocumentType enum.
69 int getDocumentType()
71 return mpDoc->pClass->getDocumentType(mpDoc);
74 #if defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
75 /**
76 * Get number of part that the document contains.
78 * Part refers to either individual sheets in a Calc, or slides in Impress,
79 * and has no relevance for Writer.
81 int getParts()
83 return mpDoc->pClass->getParts(mpDoc);
86 /**
87 * Get the extent of each page in the document.
89 * This function is relevant for Writer documents only. It is a
90 * mistake that the API has "part" in its name as Writer documents
91 * don't have parts.
93 * @return a rectangle list, using the same format as
94 * LOK_CALLBACK_TEXT_SELECTION.
96 char* getPartPageRectangles()
98 return mpDoc->pClass->getPartPageRectangles(mpDoc);
101 /// Get the current part of the document.
102 int getPart()
104 return mpDoc->pClass->getPart(mpDoc);
107 /// Set the current part of the document.
108 void setPart(int nPart)
110 mpDoc->pClass->setPart(mpDoc, nPart);
113 /// Get the current part's name.
114 char* getPartName(int nPart)
116 return mpDoc->pClass->getPartName(mpDoc, nPart);
119 /// Get the current part's hash.
120 char* getPartHash(int nPart)
122 return mpDoc->pClass->getPartHash(mpDoc, nPart);
125 void setPartMode(int nMode)
127 mpDoc->pClass->setPartMode(mpDoc, nMode);
130 int getEditMode()
132 return mpDoc->pClass->getEditMode(mpDoc);
136 * Renders a subset of the document to a pre-allocated buffer.
138 * Note that the buffer size and the tile size implicitly supports
139 * rendering at different zoom levels, as the number of rendered pixels and
140 * the rendered rectangle of the document are independent.
142 * @param pBuffer pointer to the buffer, its size is determined by nCanvasWidth and nCanvasHeight.
143 * @param nCanvasWidth number of pixels in a row of pBuffer.
144 * @param nCanvasHeight number of pixels in a column of pBuffer.
145 * @param nTilePosX logical X position of the top left corner of the rendered rectangle, in TWIPs.
146 * @param nTilePosY logical Y position of the top left corner of the rendered rectangle, in TWIPs.
147 * @param nTileWidth logical width of the rendered rectangle, in TWIPs.
148 * @param nTileHeight logical height of the rendered rectangle, in TWIPs.
150 void paintTile(unsigned char* pBuffer,
151 const int nCanvasWidth,
152 const int nCanvasHeight,
153 const int nTilePosX,
154 const int nTilePosY,
155 const int nTileWidth,
156 const int nTileHeight)
158 return mpDoc->pClass->paintTile(mpDoc, pBuffer, nCanvasWidth, nCanvasHeight,
159 nTilePosX, nTilePosY, nTileWidth, nTileHeight);
163 * Renders a window (dialog, popup, etc.) with give id
165 * @param nWindowId
166 * @param pBuffer Buffer with enough memory allocated to render any dialog
167 * @param x x-coordinate from where the dialog should start painting
168 * @param y y-coordinate from where the dialog should start painting
169 * @param width The width of the dialog image to be painted
170 * @param height The height of the dialog image to be painted
171 * @param dpiscale The dpi scale value used by the client. Please note
172 * that the x, y, width, height are supposed to be the
173 * values with dpiscale applied (ie. dialog covering
174 * 100x100 "normal" pixels with dpiscale '2' will have
175 * 200x200 width x height), so that it is easy to compute
176 * the buffer sizes etc.
178 void paintWindow(unsigned nWindowId,
179 unsigned char* pBuffer,
180 const int x,
181 const int y,
182 const int width,
183 const int height,
184 const double dpiscale = 1.0,
185 const int viewId = -1)
187 return mpDoc->pClass->paintWindowForView(mpDoc, nWindowId, pBuffer, x, y,
188 width, height, dpiscale, viewId);
192 * Posts a command to the window (dialog, popup, etc.) with given id
194 * @param nWindowid
196 void postWindow(unsigned nWindowId, int nAction, const char* pData = nullptr)
198 return mpDoc->pClass->postWindow(mpDoc, nWindowId, nAction, pData);
202 * Gets the tile mode: the pixel format used for the pBuffer of paintTile().
204 * @return an element of the LibreOfficeKitTileMode enum.
206 int getTileMode()
208 return mpDoc->pClass->getTileMode(mpDoc);
211 /// Get the document sizes in TWIPs.
212 void getDocumentSize(long* pWidth, long* pHeight)
214 mpDoc->pClass->getDocumentSize(mpDoc, pWidth, pHeight);
217 /// Get the data area (in Calc last row and column).
218 void getDataArea(long nPart, long* pCol, long* pRow)
220 mpDoc->pClass->getDataArea(mpDoc, nPart, pCol, pRow);
224 * Initialize document for rendering.
226 * Sets the rendering and document parameters to default values that are
227 * needed to render the document correctly using tiled rendering. This
228 * method has to be called right after documentLoad() in case any of the
229 * tiled rendering methods are to be used later.
231 * Example argument string for text documents:
234 * ".uno:HideWhitespace":
236 * "type": "boolean",
237 * "value": "true"
241 * @param pArguments arguments of the rendering
243 void initializeForRendering(const char* pArguments = NULL)
245 mpDoc->pClass->initializeForRendering(mpDoc, pArguments);
249 * Registers a callback. LOK will invoke this function when it wants to
250 * inform the client about events.
252 * @param pCallback the callback to invoke
253 * @param pData the user data, will be passed to the callback on invocation
255 void registerCallback(LibreOfficeKitCallback pCallback, void* pData)
257 mpDoc->pClass->registerCallback(mpDoc, pCallback, pData);
261 * Posts a keyboard event to the focused frame.
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 postKeyEvent(int nType, int nCharCode, int nKeyCode)
269 mpDoc->pClass->postKeyEvent(mpDoc, nType, nCharCode, nKeyCode);
273 * Posts a keyboard event to the dialog
275 * @param nWindowId
276 * @param nType Event type, like press or release.
277 * @param nCharCode contains the Unicode character generated by this event or 0
278 * @param nKeyCode contains the integer code representing the key of the event (non-zero for control keys)
280 void postWindowKeyEvent(unsigned nWindowId, int nType, int nCharCode, int nKeyCode)
282 mpDoc->pClass->postWindowKeyEvent(mpDoc, nWindowId, nType, nCharCode, nKeyCode);
286 * Posts a mouse event to the document.
288 * @param nType Event type, like down, move or up.
289 * @param nX horizontal position in document coordinates
290 * @param nY vertical position in document coordinates
291 * @param nCount number of clicks: 1 for single click, 2 for double click
292 * @param nButtons: which mouse buttons: 1 for left, 2 for middle, 4 right
293 * @param nModifier: which keyboard modifier: (see include/vcl/vclenum.hxx for possible values)
295 void postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier)
297 mpDoc->pClass->postMouseEvent(mpDoc, nType, nX, nY, nCount, nButtons, nModifier);
301 * Posts a mouse event to the window with given id.
303 * @param nWindowId
304 * @param nType Event type, like down, move or up.
305 * @param nX horizontal position in document coordinates
306 * @param nY vertical position in document coordinates
307 * @param nCount number of clicks: 1 for single click, 2 for double click
308 * @param nButtons: which mouse buttons: 1 for left, 2 for middle, 4 right
309 * @param nModifier: which keyboard modifier: (see include/vcl/vclenum.hxx for possible values)
311 void postWindowMouseEvent(unsigned nWindowId, int nType, int nX, int nY, int nCount, int nButtons, int nModifier)
313 mpDoc->pClass->postWindowMouseEvent(mpDoc, nWindowId, nType, nX, nY, nCount, nButtons, nModifier);
317 * Posts a dialog event for the window with given id
319 * @param nWindowId id of the window to notify
320 * @param pArguments arguments of the event.
322 void sendDialogEvent(unsigned long long int nWindowId, const char* pArguments = NULL)
324 mpDoc->pClass->sendDialogEvent(mpDoc, nWindowId, pArguments);
328 * Posts a UNO command to the document.
330 * Example argument string:
333 * "SearchItem.SearchString":
335 * "type": "string",
336 * "value": "foobar"
337 * },
338 * "SearchItem.Backward":
340 * "type": "boolean",
341 * "value": "false"
345 * @param pCommand uno command to be posted to the document, like ".uno:Bold"
346 * @param pArguments arguments of the uno command.
348 void postUnoCommand(const char* pCommand, const char* pArguments = NULL, bool bNotifyWhenFinished = false)
350 mpDoc->pClass->postUnoCommand(mpDoc, pCommand, pArguments, bNotifyWhenFinished);
354 * Sets the start or end of a text selection.
356 * @param nType @see LibreOfficeKitSetTextSelectionType
357 * @param nX horizontal position in document coordinates
358 * @param nY vertical position in document coordinates
360 void setTextSelection(int nType, int nX, int nY)
362 mpDoc->pClass->setTextSelection(mpDoc, nType, nX, nY);
366 * Gets the currently selected text.
368 * @param pMimeType suggests the return format, for example text/plain;charset=utf-8.
369 * @param pUsedMimeType output parameter to inform about the determined format (suggested one or plain text).
371 char* getTextSelection(const char* pMimeType, char** pUsedMimeType = NULL)
373 return mpDoc->pClass->getTextSelection(mpDoc, pMimeType, pUsedMimeType);
377 * Gets the type of the selected content.
379 * In most cases it is more efficient to use getSelectionTypeAndText().
381 * @return an element of the LibreOfficeKitSelectionType enum.
383 int getSelectionType()
385 return mpDoc->pClass->getSelectionType(mpDoc);
389 * Gets the type of the selected content and possibly its text.
391 * This function is a more efficient combination of getSelectionType() and getTextSelection().
392 * It returns the same as getSelectionType(), and additionally if the return value is
393 * LOK_SELTYPE_TEXT then it also returns the same as getTextSelection(), otherwise
394 * pText and pUsedMimeType are unchanged.
396 * @param pMimeType suggests the return format, for example text/plain;charset=utf-8.
397 * @param pText the currently selected text
398 * @param pUsedMimeType output parameter to inform about the determined format (suggested one or plain text).
399 * @return an element of the LibreOfficeKitSelectionType enum.
400 * @since LibreOffice 7.4
402 int getSelectionTypeAndText(const char* pMimeType, char** pText, char** pUsedMimeType = NULL)
404 if (LIBREOFFICEKIT_DOCUMENT_HAS(mpDoc, getSelectionTypeAndText))
405 return mpDoc->pClass->getSelectionTypeAndText(mpDoc, pMimeType, pText, pUsedMimeType);
406 int type = mpDoc->pClass->getSelectionType(mpDoc);
407 if(type == LOK_SELTYPE_TEXT && pText)
408 *pText = mpDoc->pClass->getTextSelection(mpDoc, pMimeType, pUsedMimeType);
409 return type;
413 * Gets the content on the clipboard for the current view as a series of binary streams.
415 * NB. returns a complete set of possible selection types if nullptr is passed for pMimeTypes.
417 * @param pMimeTypes passes in a nullptr terminated list of mime types to fetch
418 * @param pOutCount returns the size of the other @pOut arrays
419 * @param pOutMimeTypes returns an array of mime types
420 * @param pOutSizes returns the size of each pOutStream
421 * @param pOutStreams the content of each mime-type, of length in @pOutSizes
423 * @returns: true on success, false on error.
425 bool getClipboard(const char **pMimeTypes,
426 size_t *pOutCount,
427 char ***pOutMimeTypes,
428 size_t **pOutSizes,
429 char ***pOutStreams)
431 return mpDoc->pClass->getClipboard(mpDoc, pMimeTypes, pOutCount, pOutMimeTypes, pOutSizes, pOutStreams);
435 * Populates the clipboard for this view with multiple types of content.
437 * @param nInCount the number of types to paste
438 * @param pInMimeTypes array of mime type strings
439 * @param pInSizes array of sizes of the data to paste
440 * @param pInStreams array containing the data of the various types
442 * @return if the supplied data was populated successfully.
444 bool setClipboard(const size_t nInCount,
445 const char **pInMimeTypes,
446 const size_t *pInSizes,
447 const char **pInStreams)
449 return mpDoc->pClass->setClipboard(mpDoc, nInCount, pInMimeTypes, pInSizes, pInStreams);
453 * Pastes content at the current cursor position.
455 * @param pMimeType format of pData, for example text/plain;charset=utf-8.
456 * @param pData the actual data to be pasted.
457 * @return if the supplied data was pasted successfully.
459 bool paste(const char* pMimeType, const char* pData, size_t nSize)
461 return mpDoc->pClass->paste(mpDoc, pMimeType, pData, nSize);
465 * Adjusts the graphic selection.
467 * @param nType @see LibreOfficeKitSetGraphicSelectionType
468 * @param nX horizontal position in document coordinates
469 * @param nY vertical position in document coordinates
471 void setGraphicSelection(int nType, int nX, int nY)
473 mpDoc->pClass->setGraphicSelection(mpDoc, nType, nX, nY);
477 * Gets rid of any text or graphic selection.
479 void resetSelection()
481 mpDoc->pClass->resetSelection(mpDoc);
485 * Returns a json mapping of the possible values for the given command
486 * e.g. {commandName: ".uno:StyleApply", commandValues: {"familyName1" : ["list of style names in the family1"], etc.}}
487 * @param pCommand a UNO command for which the possible values are requested
488 * @return {commandName: unoCmd, commandValues: {possible_values}}
490 char* getCommandValues(const char* pCommand)
492 return mpDoc->pClass->getCommandValues(mpDoc, pCommand);
496 * Save the client's view so that we can compute the right zoom level
497 * for the mouse events. This only affects CALC.
498 * @param nTilePixelWidth - tile width in pixels
499 * @param nTilePixelHeight - tile height in pixels
500 * @param nTileTwipWidth - tile width in twips
501 * @param nTileTwipHeight - tile height in twips
503 void setClientZoom(
504 int nTilePixelWidth,
505 int nTilePixelHeight,
506 int nTileTwipWidth,
507 int nTileTwipHeight)
509 mpDoc->pClass->setClientZoom(mpDoc, nTilePixelWidth, nTilePixelHeight, nTileTwipWidth, nTileTwipHeight);
513 * Inform core about the currently visible area of the document on the
514 * client, so that it can perform e.g. page down (which depends on the
515 * visible height) in a sane way.
517 * @param nX - top left corner horizontal position
518 * @param nY - top left corner vertical position
519 * @param nWidth - area width
520 * @param nHeight - area height
522 void setClientVisibleArea(int nX, int nY, int nWidth, int nHeight)
524 mpDoc->pClass->setClientVisibleArea(mpDoc, nX, nY, nWidth, nHeight);
528 * Show/Hide a single row/column header outline for Calc documents.
530 * @param bColumn - if we are dealing with a column or row group
531 * @param nLevel - the level to which the group belongs
532 * @param nIndex - the group entry index
533 * @param bHidden - the new group state (collapsed/expanded)
535 void setOutlineState(bool bColumn, int nLevel, int nIndex, bool bHidden)
537 mpDoc->pClass->setOutlineState(mpDoc, bColumn, nLevel, nIndex, bHidden);
541 * Create a new view for an existing document with
542 * options similar to documentLoadWithOptions.
543 * By default a loaded document has 1 view.
544 * @return the ID of the new view.
546 int createView(const char* pOptions = nullptr)
548 if (LIBREOFFICEKIT_DOCUMENT_HAS(mpDoc, createViewWithOptions))
549 return mpDoc->pClass->createViewWithOptions(mpDoc, pOptions);
550 else
551 return mpDoc->pClass->createView(mpDoc);
555 * Destroy a view of an existing document.
556 * @param nId a view ID, returned by createView().
558 void destroyView(int nId)
560 mpDoc->pClass->destroyView(mpDoc, nId);
564 * Set an existing view of an existing document as current.
565 * @param nId a view ID, returned by createView().
567 void setView(int nId)
569 mpDoc->pClass->setView(mpDoc, nId);
573 * Get the current view.
574 * @return a view ID, previously returned by createView().
576 int getView()
578 return mpDoc->pClass->getView(mpDoc);
582 * Get number of views of this document.
584 int getViewsCount()
586 return mpDoc->pClass->getViewsCount(mpDoc);
590 * Paints a font name or character if provided to be displayed in the font list
591 * @param pFontName the font to be painted
593 unsigned char* renderFont(const char *pFontName,
594 const char *pChar,
595 int *pFontWidth,
596 int *pFontHeight,
597 int pOrientation=0)
599 if (LIBREOFFICEKIT_DOCUMENT_HAS(mpDoc, renderFontOrientation))
600 return mpDoc->pClass->renderFontOrientation(mpDoc, pFontName, pChar, pFontWidth, pFontHeight, pOrientation);
601 else
602 return mpDoc->pClass->renderFont(mpDoc, pFontName, pChar, pFontWidth, pFontHeight);
606 * Renders a subset of the document's part to a pre-allocated buffer.
608 * @param nPart the part number of the document of which the tile is painted.
609 * @see paintTile.
611 void paintPartTile(unsigned char* pBuffer,
612 const int nPart,
613 const int nMode,
614 const int nCanvasWidth,
615 const int nCanvasHeight,
616 const int nTilePosX,
617 const int nTilePosY,
618 const int nTileWidth,
619 const int nTileHeight)
621 return mpDoc->pClass->paintPartTile(mpDoc, pBuffer, nPart, nMode,
622 nCanvasWidth, nCanvasHeight,
623 nTilePosX, nTilePosY,
624 nTileWidth, nTileHeight);
628 * Returns the viewID for each existing view. Since viewIDs are not reused,
629 * viewIDs are not the same as the index of the view in the view array over
630 * time. Use getViewsCount() to know the minimal nSize that's large enough.
632 * @param pArray the array to write the viewIDs into
633 * @param nSize the size of pArray
634 * @returns true if pArray was large enough and result is written, false
635 * otherwise.
637 bool getViewIds(int* pArray,
638 size_t nSize)
640 return mpDoc->pClass->getViewIds(mpDoc, pArray, nSize);
644 * Set the language tag of the window with the specified nId.
646 * @param nId a view ID, returned by createView().
647 * @param language Bcp47 languageTag, like en-US or so.
649 void setViewLanguage(int nId, const char* language)
651 mpDoc->pClass->setViewLanguage(mpDoc, nId, language);
655 * Post the text input from external input window, like IME, to given windowId
657 * @param nWindowId Specify the window id to post the input event to. If
658 * nWindow is 0, the event is posted into the document
659 * @param nType see LibreOfficeKitExtTextInputType
660 * @param pText Text for LOK_EXT_TEXTINPUT
662 void postWindowExtTextInputEvent(unsigned nWindowId, int nType, const char* pText)
664 mpDoc->pClass->postWindowExtTextInputEvent(mpDoc, nWindowId, nType, pText);
668 * Insert certificate (in binary form) to the certificate store.
670 bool insertCertificate(const unsigned char* pCertificateBinary,
671 const int pCertificateBinarySize,
672 const unsigned char* pPrivateKeyBinary,
673 const int nPrivateKeyBinarySize)
675 return mpDoc->pClass->insertCertificate(mpDoc,
676 pCertificateBinary, pCertificateBinarySize,
677 pPrivateKeyBinary, nPrivateKeyBinarySize);
681 * Add the certificate (in binary form) to the certificate store.
684 bool addCertificate(const unsigned char* pCertificateBinary,
685 const int pCertificateBinarySize)
687 return mpDoc->pClass->addCertificate(mpDoc,
688 pCertificateBinary, pCertificateBinarySize);
692 * Verify signature of the document.
694 * Check possible values in include/sfx2/signaturestate.hxx
696 int getSignatureState()
698 return mpDoc->pClass->getSignatureState(mpDoc);
702 * Gets an image of the selected shapes.
703 * @param pOutput contains the result; use free to deallocate.
704 * @return the size of *pOutput in bytes.
706 size_t renderShapeSelection(char** pOutput)
708 return mpDoc->pClass->renderShapeSelection(mpDoc, pOutput);
712 * Posts a gesture event to the window with given id.
714 * @param nWindowId
715 * @param pType Event type, like panStart, panEnd, panUpdate.
716 * @param nX horizontal position in document coordinates
717 * @param nY vertical position in document coordinates
718 * @param nOffset difference value from when the gesture started to current value
720 void postWindowGestureEvent(unsigned nWindowId,
721 const char* pType,
722 int nX, int nY, int nOffset)
724 return mpDoc->pClass->postWindowGestureEvent(mpDoc, nWindowId, pType, nX, nY, nOffset);
727 /// Set a part's selection mode.
728 /// nSelect is 0 to deselect, 1 to select, and 2 to toggle.
729 void selectPart(int nPart, int nSelect)
731 mpDoc->pClass->selectPart(mpDoc, nPart, nSelect);
734 /// Moves the selected pages/slides to a new position.
735 /// nPosition is the new position where the selection
736 /// should go. bDuplicate when true will copy instead of move.
737 void moveSelectedParts(int nPosition, bool bDuplicate)
739 mpDoc->pClass->moveSelectedParts(mpDoc, nPosition, bDuplicate);
743 * Resize a window (dialog, popup, etc.) with give id.
745 * @param nWindowId
746 * @param width The width of the window.
747 * @param height The height of the window.
749 void resizeWindow(unsigned nWindowId,
750 const int width,
751 const int height)
753 return mpDoc->pClass->resizeWindow(mpDoc, nWindowId, width, height);
757 * For deleting many characters all at once
759 * @param nWindowId Specify the window id to post the input event to. If
760 * nWindow is 0, the event is posted into the document
761 * @param nBefore The characters to be deleted before the cursor position
762 * @param nAfter The characters to be deleted after the cursor position
764 void removeTextContext(unsigned nWindowId, int nBefore, int nAfter)
766 mpDoc->pClass->removeTextContext(mpDoc, nWindowId, nBefore, nAfter);
770 * Select the Calc function to be pasted into the formula input box
772 * @param nIndex is the index of the selected function
774 void completeFunction(const char* pFunctionName)
776 mpDoc->pClass->completeFunction(mpDoc, pFunctionName);
780 * Sets the start or end of a text selection for a dialog.
782 * @param nWindowId
783 * @param bSwap swap anchor and cursor position of current selection
784 * @param nX horizontal position in document coordinates
785 * @param nY vertical position in document coordinates
787 void setWindowTextSelection(unsigned nWindowId, bool bSwap, int nX, int nY)
789 mpDoc->pClass->setWindowTextSelection(mpDoc, nWindowId, bSwap, nX, nY);
793 * Posts an event for the form field at the cursor position.
795 * @param pArguments arguments of the event.
797 void sendFormFieldEvent(const char* pArguments)
799 mpDoc->pClass->sendFormFieldEvent(mpDoc, pArguments);
802 void setBlockedCommandList(int nViewId, const char* blockedCommandList)
804 mpDoc->pClass->setBlockedCommandList(mpDoc, nViewId, blockedCommandList);
807 * Render input search result to a bitmap buffer.
809 * @param pSearchResult payload containing the search result data
810 * @param pBitmapBuffer contains the bitmap; use free to deallocate.
811 * @param nWidth output bitmap width
812 * @param nHeight output bitmap height
813 * @param nByteSize output bitmap byte size
814 * @return true if successful
816 bool renderSearchResult(const char* pSearchResult, unsigned char** pBitmapBuffer,
817 int* pWidth, int* pHeight, size_t* pByteSize)
819 return mpDoc->pClass->renderSearchResult(mpDoc, pSearchResult, pBitmapBuffer, pWidth, pHeight, pByteSize);
823 * Posts an event for the content control at the cursor position.
825 * @param pArguments arguments of the event.
827 * Examples:
828 * To select the 3rd list item of the drop-down:
830 * "type": "drop-down",
831 * "selected": "2"
834 * To change a picture place-holder:
836 * "type": "picture",
837 * "changed": "file:///path/to/test.png"
840 * To select a date of the current date content control:
842 * "type": "date",
843 * "selected": "2022-05-29T00:00:00Z"
846 void sendContentControlEvent(const char* pArguments)
848 mpDoc->pClass->sendContentControlEvent(mpDoc, pArguments);
852 * Set the timezone of the window with the specified nId.
854 * @param nId a view ID, returned by createView().
855 * @param timezone a timezone in the tzfile(5) format (e.g. Pacific/Auckland).
857 void setViewTimezone(int nId, const char* timezone)
859 mpDoc->pClass->setViewTimezone(mpDoc, nId, timezone);
862 /** Set if the view should be treated as readonly or not.
864 * @param nId view ID
865 * @param readOnly
867 void setViewReadOnly(int nId, const bool readOnly)
869 mpDoc->pClass->setViewReadOnly(mpDoc, nId, readOnly);
872 /** Set if the view can edit comments on readonly mode or not.
874 * @param nId view ID
875 * @param allow
877 void setAllowChangeComments(int nId, const bool allow)
879 mpDoc->pClass->setAllowChangeComments(mpDoc, nId, allow);
883 * Enable/Disable accessibility support for the window with the specified nId.
885 * @param nId a view ID, returned by createView().
886 * @param nEnabled true/false
888 void setAccessibilityState(int nId, bool nEnabled)
890 mpDoc->pClass->setAccessibilityState(mpDoc, nId, nEnabled);
894 * Get the current focused paragraph info:
896 * "content": paragraph content
897 * "start": selection start
898 * "end": selection end
901 char* getA11yFocusedParagraph()
903 return mpDoc->pClass->getA11yFocusedParagraph(mpDoc);
906 /// Get the current text cursor position.
907 int getA11yCaretPosition()
909 return mpDoc->pClass->getA11yCaretPosition(mpDoc);
912 #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
915 /// The lok::Office class represents one started LibreOfficeKit instance.
916 class Office
918 private:
919 LibreOfficeKit* mpThis;
921 public:
922 /// A lok::Office is typically created by the lok_cpp_init() function.
923 Office(LibreOfficeKit* pThis) :
924 mpThis(pThis)
927 ~Office()
929 mpThis->pClass->destroy(mpThis);
933 * Loads a document from a URL.
935 * @param pUrl the URL of the document to load
936 * @param pFilterOptions options for the import filter, e.g. SkipImages.
937 * Another useful FilterOption is "Language=...". It is consumed
938 * by the documentLoad() itself, and when provided, LibreOfficeKit
939 * switches the language accordingly first.
940 * @since pFilterOptions argument added in LibreOffice 5.0
942 Document* documentLoad(const char* pUrl, const char* pFilterOptions = NULL)
944 LibreOfficeKitDocument* pDoc = NULL;
946 if (LIBREOFFICEKIT_HAS(mpThis, documentLoadWithOptions))
947 pDoc = mpThis->pClass->documentLoadWithOptions(mpThis, pUrl, pFilterOptions);
948 else
949 pDoc = mpThis->pClass->documentLoad(mpThis, pUrl);
951 if (pDoc == NULL)
952 return NULL;
954 return new Document(pDoc);
957 /// Returns the last error as a string, the returned pointer has to be freed by the caller.
958 char* getError()
960 return mpThis->pClass->getError(mpThis);
964 * Frees the memory pointed to by pFree.
966 * @since LibreOffice 5.2
968 void freeError(char* pFree)
970 mpThis->pClass->freeError(pFree);
974 * Registers a callback. LOK will invoke this function when it wants to
975 * inform the client about events.
977 * @since LibreOffice 6.0
978 * @param pCallback the callback to invoke
979 * @param pData the user data, will be passed to the callback on invocation
981 void registerCallback(LibreOfficeKitCallback pCallback, void* pData)
983 mpThis->pClass->registerCallback(mpThis, pCallback, pData);
987 * Returns details of filter types.
989 * Example returned string:
992 * "writer8": {
993 * "MediaType": "application/vnd.oasis.opendocument.text"
994 * },
995 * "calc8": {
996 * "MediaType": "application/vnd.oasis.opendocument.spreadsheet"
1000 * @since LibreOffice 6.0
1002 char* getFilterTypes()
1004 return mpThis->pClass->getFilterTypes(mpThis);
1008 * Set bitmask of optional features supported by the client.
1010 * @since LibreOffice 6.0
1011 * @see LibreOfficeKitOptionalFeatures
1013 void setOptionalFeatures(unsigned long long features)
1015 return mpThis->pClass->setOptionalFeatures(mpThis, features);
1019 * Set password required for loading or editing a document.
1021 * Loading the document is blocked until the password is provided.
1023 * @param pURL the URL of the document, as sent to the callback
1024 * @param pPassword the password, nullptr indicates no password
1026 * In response to LOK_CALLBACK_DOCUMENT_PASSWORD, a valid password
1027 * will continue loading the document, an invalid password will
1028 * result in another LOK_CALLBACK_DOCUMENT_PASSWORD request,
1029 * and a NULL password will abort loading the document.
1031 * In response to LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY, a valid
1032 * password will continue loading the document, an invalid password will
1033 * result in another LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY request,
1034 * and a NULL password will continue loading the document in read-only
1035 * mode.
1037 * @since LibreOffice 6.0
1039 void setDocumentPassword(char const* pURL, char const* pPassword)
1041 mpThis->pClass->setDocumentPassword(mpThis, pURL, pPassword);
1045 * Get version information of the LOKit process
1047 * @since LibreOffice 6.0
1048 * @returns JSON string containing version information in format:
1049 * {ProductName: <>, ProductVersion: <>, ProductExtension: <>, BuildId: <>}
1051 * Eg: {"ProductName": "LibreOffice",
1052 * "ProductVersion": "5.3",
1053 * "ProductExtension": ".0.0.alpha0",
1054 * "BuildId": "<full 40 char git hash>"}
1056 char* getVersionInfo()
1058 return mpThis->pClass->getVersionInfo(mpThis);
1062 * Run a macro.
1064 * Same syntax as on command line is permissible (ie. the macro:// URI forms)
1066 * @since LibreOffice 6.0
1067 * @param pURL macro url to run
1069 bool runMacro( const char* pURL)
1071 return mpThis->pClass->runMacro( mpThis, pURL );
1075 * Exports the document and signs its content.
1077 bool signDocument(const char* pURL,
1078 const unsigned char* pCertificateBinary, const int nCertificateBinarySize,
1079 const unsigned char* pPrivateKeyBinary, const int nPrivateKeyBinarySize)
1081 return mpThis->pClass->signDocument(mpThis, pURL,
1082 pCertificateBinary, nCertificateBinarySize,
1083 pPrivateKeyBinary, nPrivateKeyBinarySize);
1087 * Runs the main-loop in the current thread. To trigger this
1088 * mode you need to putenv a SAL_LOK_OPTIONS containing 'unipoll'.
1089 * The @pPollCallback is called to poll for events from the Kit client
1090 * and the @pWakeCallback can be called by internal LibreOfficeKit threads
1091 * to wake the caller of 'runLoop' ie. the main thread.
1093 * it is expected that runLoop does not return until Kit exit.
1095 * @pData is a context/closure passed to both methods.
1097 void runLoop(LibreOfficeKitPollCallback pPollCallback,
1098 LibreOfficeKitWakeCallback pWakeCallback,
1099 void* pData)
1101 mpThis->pClass->runLoop(mpThis, pPollCallback, pWakeCallback, pData);
1105 * Posts a dialog event for the window with given id
1107 * @param nWindowId id of the window to notify
1108 * @param pArguments arguments of the event.
1110 void sendDialogEvent(unsigned long long int nWindowId, const char* pArguments = NULL)
1112 mpThis->pClass->sendDialogEvent(mpThis, nWindowId, pArguments);
1116 * Generic function to toggle and tweak various things in the core LO
1118 * The currently available option names and their allowed values are:
1120 * "profilezonerecording": "start" or "stop"
1121 * Start or stop recording profile zone trace data in the process.
1123 * "sallogoverride": "<string>"
1124 * Override the SAL_LOG environment variable
1126 * For the syntax of the string see the documentation for "Basic
1127 * logging functionality" in LibreOffice internal API
1128 * documentation (include/sal/log.hxx). If the logging selector
1129 * has been set by this function to a non-empty value, that is used
1130 * instead of the environment variable SAL_LOG.
1132 * The parameter is not copied so you should pass a value that
1133 * points to memory that will stay valid until you call setOption
1134 * with this option name the next time.
1136 * If you pass nullptr or an empty string as value, the
1137 * environment variable SAL_LOG is again used as by default. You
1138 * can switch back and forth as you like.
1140 * "addfont": "<string>"
1142 * Adds the font at the URL given.
1144 * @param pOption the option name
1145 * @param pValue its value
1147 void setOption(const char* pOption, const char* pValue)
1149 mpThis->pClass->setOption(mpThis, pOption, pValue);
1153 * Debugging tool for triggering a dump of internal state.
1155 * LibreOfficeKit can get into an unhelpful state at run-time when
1156 * in heavy use. This provides a critical tool for inspecting
1157 * relevant internal state.
1159 * @param pOption future expansion - string options.
1160 * @param pState - heap allocated, C string containing the state dump.
1162 void dumpState(const char* pOption, char** pState)
1164 mpThis->pClass->dumpState(mpThis, pOption, pState);
1167 char* extractRequest(const char* pFilePath)
1169 return mpThis->pClass->extractRequest(mpThis, pFilePath);
1173 * Trim memory usage.
1175 * LibreOfficeKit caches lots of information from large pixmaps
1176 * to view and calculation results. When a view has not been
1177 * used for some time, depending on the load on memory it can
1178 * be useful to free up memory.
1180 * @param nTarget - a negative number means the app is back
1181 * in active use, and to re-fill caches, a large positive
1182 * number (>=1000) encourages immediate maximum memory saving.
1184 void trimMemory (int nTarget)
1186 mpThis->pClass->trimMemory(mpThis, nTarget);
1190 * Start a UNO acceptor using the function pointers provides to read and write data to/from the acceptor.
1192 * @param pReceiveURPFromLOContext A pointer that will be passed to your fnRecieveURPFromLO function
1193 * @param pSendURPToLOContext A pointer that will be passed to your fnSendURPToLO function
1194 * @param fnReceiveURPFromLO A function pointer that LO should use to pass URP back to the caller
1195 * @param fnSendURPToLO A function pointer pointer that the caller should use to pass URP to LO
1197 void* startURP(void* pReceiveURPFromLOContext, void* pSendURPToLOContext,
1198 int (*fnReceiveURPFromLO)(void* pContext, const signed char* pBuffer, int nLen),
1199 int (*fnSendURPToLO)(void* pContext, signed char* pBuffer, int nLen))
1201 return mpThis->pClass->startURP(mpThis, pReceiveURPFromLOContext, pSendURPToLOContext,
1202 fnReceiveURPFromLO, fnSendURPToLO);
1206 * Stop a function based URP connection you previously started with startURP
1208 * @param pURPContext the context returned by startURP when starting the connection
1210 void stopURP(void* pURPContext)
1212 mpThis->pClass->stopURP(mpThis, pURPContext);
1216 * Joins all threads if possible to get down to a single process
1217 * which can be forked from safely.
1219 * @returns non-zero for successful join, 0 for failure.
1221 int joinThreads()
1223 return mpThis->pClass->joinThreads(mpThis);
1227 * Informs that this process is either a parent, or a child
1228 * process post-fork, allowing improved resource sharing.
1230 void setForkedChild(bool bIsChild)
1232 return mpThis->pClass->setForkedChild(mpThis, bIsChild);
1236 /// Factory method to create a lok::Office instance.
1237 inline Office* lok_cpp_init(const char* pInstallPath, const char* pUserProfileUrl = NULL)
1239 LibreOfficeKit* pThis = lok_init_2(pInstallPath, pUserProfileUrl);
1240 if (pThis == NULL || pThis->pClass->nSize == 0)
1241 return NULL;
1242 return new ::lok::Office(pThis);
1247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */