1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 package org
.libreoffice
.kit
;
12 import java
.nio
.ByteBuffer
;
14 public class Document
{
15 public static final int PART_MODE_SLIDE
= 0;
16 public static final int PART_MODE_NOTES
= 1;
21 public static final int DOCTYPE_TEXT
= 0;
22 public static final int DOCTYPE_SPREADSHEET
= 1;
23 public static final int DOCTYPE_PRESENTATION
= 2;
24 public static final int DOCTYPE_DRAWING
= 3;
25 public static final int DOCTYPE_OTHER
= 4;
30 public static final int MOUSE_EVENT_BUTTON_DOWN
= 0;
31 public static final int MOUSE_EVENT_BUTTON_UP
= 1;
32 public static final int MOUSE_EVENT_MOVE
= 2;
37 public static final int KEY_EVENT_PRESS
= 0;
38 public static final int KEY_EVENT_RELEASE
= 1;
43 public static final int BOLD
= 0;
44 public static final int ITALIC
= 1;
45 public static final int UNDERLINE
= 2;
46 public static final int STRIKEOUT
= 3;
48 public static final int ALIGN_LEFT
= 4;
49 public static final int ALIGN_CENTER
= 5;
50 public static final int ALIGN_RIGHT
= 6;
51 public static final int ALIGN_JUSTIFY
= 7;
52 public static final int NUMBERED_LIST
= 8;
53 public static final int BULLET_LIST
= 9;
56 * Callback message types
57 * Refer to https://opengrok.libreoffice.org/xref/core/include/LibreOfficeKit/LibreOfficeKitEnums.h
58 * for more details about each callback.
60 public static final int CALLBACK_INVALIDATE_TILES
= 0;
61 public static final int CALLBACK_INVALIDATE_VISIBLE_CURSOR
= 1;
62 public static final int CALLBACK_TEXT_SELECTION
= 2;
63 public static final int CALLBACK_TEXT_SELECTION_START
= 3;
64 public static final int CALLBACK_TEXT_SELECTION_END
= 4;
65 public static final int CALLBACK_CURSOR_VISIBLE
= 5;
66 public static final int CALLBACK_GRAPHIC_SELECTION
= 6;
67 public static final int CALLBACK_HYPERLINK_CLICKED
= 7;
68 public static final int CALLBACK_STATE_CHANGED
= 8;
69 public static final int CALLBACK_STATUS_INDICATOR_START
= 9;
70 public static final int CALLBACK_STATUS_INDICATOR_SET_VALUE
= 10;
71 public static final int CALLBACK_STATUS_INDICATOR_FINISH
= 11;
72 public static final int CALLBACK_SEARCH_NOT_FOUND
= 12;
73 public static final int CALLBACK_DOCUMENT_SIZE_CHANGED
= 13;
74 public static final int CALLBACK_SET_PART
= 14;
75 public static final int CALLBACK_SEARCH_RESULT_SELECTION
= 15;
76 public static final int CALLBACK_UNO_COMMAND_RESULT
= 16;
77 public static final int CALLBACK_CELL_CURSOR
= 17;
78 public static final int CALLBACK_MOUSE_POINTER
= 18;
79 public static final int CALLBACK_CELL_FORMULA
= 19;
80 public static final int CALLBACK_DOCUMENT_PASSWORD
= 20;
81 public static final int CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY
= 21;
82 public static final int CALLBACK_ERROR
= 22;
83 public static final int CALLBACK_CONTEXT_MENU
= 23;
84 public static final int CALLBACK_INVALIDATE_VIEW_CURSOR
= 24;
85 public static final int CALLBACK_TEXT_VIEW_SELECTION
= 25;
86 public static final int CALLBACK_CELL_VIEW_CURSOR
= 26;
87 public static final int CALLBACK_GRAPHIC_VIEW_SELECTION
= 27;
88 public static final int CALLBACK_VIEW_CURSOR_VISIBLE
= 28;
89 public static final int CALLBACK_VIEW_LOCK
= 29;
90 public static final int CALLBACK_REDLINE_TABLE_SIZE_CHANGED
= 30;
91 public static final int CALLBACK_REDLINE_TABLE_ENTRY_MODIFIED
= 31;
92 public static final int CALLBACK_COMMENT
= 32;
93 public static final int CALLBACK_INVALIDATE_HEADER
= 33;
94 public static final int CALLBACK_CELL_ADDRESS
= 34;
95 public static final int CALLBACK_SC_FOLLOW_JUMP
= 54;
98 * Set text selection types
100 public static final int SET_TEXT_SELECTION_START
= 0;
101 public static final int SET_TEXT_SELECTION_END
= 1;
102 public static final int SET_TEXT_SELECTION_RESET
= 2;
105 * Set graphic selection types
107 public static final int SET_GRAPHIC_SELECTION_START
= 0;
108 public static final int SET_GRAPHIC_SELECTION_END
= 1;
113 public static final int MOUSE_BUTTON_LEFT
= 1;
114 public static final int MOUSE_BUTTON_MIDDLE
= 2;
115 public static final int MOUSE_BUTTON_RIGHT
= 4;
117 public static final int KEYBOARD_MODIFIER_NONE
= 0x0000;
118 public static final int KEYBOARD_MODIFIER_SHIFT
= 0x1000;
119 public static final int KEYBOARD_MODIFIER_MOD1
= 0x2000;
120 public static final int KEYBOARD_MODIFIER_MOD2
= 0x4000;
121 public static final int KEYBOARD_MODIFIER_MOD3
= 0x8000;
123 /** Optional features of LibreOfficeKit, in particular callbacks that block
124 * LibreOfficeKit until the corresponding reply is received, which would
125 * deadlock if the client does not support the feature.
127 public static final long LOK_FEATURE_DOCUMENT_PASSWORD
= 1;
128 public static final long LOK_FEATURE_DOCUMENT_PASSWORD_TO_MODIFY
= (1 << 1);
129 public static final long LOK_FEATURE_PART_IN_INVALIDATION_CALLBACK
= (1 << 2);
130 public static final long LOK_FEATURE_NO_TILED_ANNOTATIONS
= (1 << 3);
132 private final ByteBuffer handle
;
133 private MessageCallback messageCallback
= null;
135 public Document(ByteBuffer handle
) {
136 this.handle
= handle
;
137 bindMessageCallback();
140 public void setMessageCallback(MessageCallback messageCallback
) {
141 this.messageCallback
= messageCallback
;
145 * Callback triggered through JNI to indicate that a new signal
146 * from LibreOfficeKit was retrieved.
148 private void messageRetrieved(int signalNumber
, String payload
) {
149 if (messageCallback
!= null) {
150 messageCallback
.messageRetrieved(signalNumber
, payload
);
155 * Bind the signal callback in LOK.
157 private native void bindMessageCallback();
159 public native void destroy();
161 public native int getPart();
163 public native void setPart(int partIndex
);
165 public native int getParts();
167 public native String
getPartName(int partIndex
);
169 public native void setPartMode(int partMode
);
171 public native String
getPartPageRectangles();
173 public native long getDocumentHeight();
175 public native long getDocumentWidth();
177 private native int getDocumentTypeNative();
179 public native void setClientZoom(int nTilePixelWidth
, int nTilePixelHeight
, int nTileTwipWidth
, int nTileTwipHeight
);
181 public native void saveAs(String url
, String format
, String options
);
183 private native void paintTileNative(ByteBuffer buffer
, int canvasWidth
, int canvasHeight
, int tilePositionX
, int tilePositionY
, int tileWidth
, int tileHeight
);
185 public int getDocumentType() {
186 return getDocumentTypeNative();
189 public void paintTile(ByteBuffer buffer
, int canvasWidth
, int canvasHeight
, int tilePositionX
, int tilePositionY
, int tileWidth
, int tileHeight
) {
190 paintTileNative(buffer
, canvasWidth
, canvasHeight
, tilePositionX
, tilePositionY
, tileWidth
, tileHeight
);
193 public native void initializeForRendering();
196 * Post a key event to LibreOffice.
197 * @param type - type of key event
198 * @param charCode - the Unicode character generated by this event or 0.
199 * @param keyCode - the integer code representing the key of the event (non-zero for control keys).
201 public native void postKeyEvent(int type
, int charCode
, int keyCode
);
204 * Post a mouse event to LOK
205 * @param type - mouse event type
206 * @param x - x coordinate
207 * @param y - y coordinate
208 * @param count - number of events
210 public native void postMouseEvent(int type
, int x
, int y
, int count
, int button
, int modifier
);
213 * Post a .uno: command to LOK
214 * @param command - the command, like ".uno:Bold"
217 public native void postUnoCommand(String command
, String arguments
, boolean notifyWhenFinished
);
220 * Change text selection.
221 * @param type - text selection type
222 * @param x - x coordinate
223 * @param y - y coordinate
225 public native void setTextSelection(int type
, int x
, int y
);
228 * Change graphic selection.
229 * @param type - graphic selection type
230 * @param x - x coordinate
231 * @param y - y coordinate
233 public native void setGraphicSelection(int type
, int x
, int y
);
240 public native String
getTextSelection(String mimeType
);
248 public native boolean paste(String mimeType
, String data
);
251 * Reset current (any kind of) selection.
253 public native void resetSelection();
255 public native String
getCommandValues(String command
);
258 * Callback to retrieve messages from LOK
260 public interface MessageCallback
{
262 * Invoked when a message is retrieved from LOK
263 * @param signalNumber - signal type / number
264 * @param payload - retrieved for the signal
266 void messageRetrieved(int signalNumber
, String payload
);