Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / android / Bootstrap / src / org / libreoffice / kit / Document.java
blob69f8f76c3eb429e66a638347c7d49679af10e358
1 /* -*- Mode: Java; 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 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;
18 /**
19 * Document types
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;
27 /**
28 * Mouse event types
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;
34 /**
35 * Key event types
37 public static final int KEY_EVENT_PRESS = 0;
38 public static final int KEY_EVENT_RELEASE = 1;
40 /**
41 * State change types
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;
55 /**
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;
96 /**
97 * Set text selection types
99 public static final int SET_TEXT_SELECTION_START = 0;
100 public static final int SET_TEXT_SELECTION_END = 1;
101 public static final int SET_TEXT_SELECTION_RESET = 2;
104 * Set graphic selection types
106 public static final int SET_GRAPHIC_SELECTION_START = 0;
107 public static final int SET_GRAPHIC_SELECTION_END = 1;
110 * Mouse button type
112 public static final int MOUSE_BUTTON_LEFT = 1;
113 public static final int MOUSE_BUTTON_MIDDLE = 2;
114 public static final int MOUSE_BUTTON_RIGHT = 4;
116 public static final int KEYBOARD_MODIFIER_NONE = 0x0000;
117 public static final int KEYBOARD_MODIFIER_SHIFT = 0x1000;
118 public static final int KEYBOARD_MODIFIER_MOD1 = 0x2000;
119 public static final int KEYBOARD_MODIFIER_MOD2 = 0x4000;
120 public static final int KEYBOARD_MODIFIER_MOD3 = 0x8000;
122 /** Optional features of LibreOfficeKit, in particular callbacks that block
123 * LibreOfficeKit until the corresponding reply is received, which would
124 * deadlock if the client does not support the feature.
126 public static final long LOK_FEATURE_DOCUMENT_PASSWORD = 1;
127 public static final long LOK_FEATURE_DOCUMENT_PASSWORD_TO_MODIFY = (1 << 1);
128 public static final long LOK_FEATURE_PART_IN_INVALIDATION_CALLBACK = (1 << 2);
129 public static final long LOK_FEATURE_NO_TILED_ANNOTATIONS = (1 << 3);
131 private final ByteBuffer handle;
132 private MessageCallback messageCallback = null;
134 public Document(ByteBuffer handle) {
135 this.handle = handle;
136 bindMessageCallback();
139 public void setMessageCallback(MessageCallback messageCallback) {
140 this.messageCallback = messageCallback;
144 * Callback triggered through JNI to indicate that a new signal
145 * from LibreOfficeKit was retrieved.
147 private void messageRetrieved(int signalNumber, String payload) {
148 if (messageCallback != null) {
149 messageCallback.messageRetrieved(signalNumber, payload);
154 * Bind the signal callback in LOK.
156 private native void bindMessageCallback();
158 public native void destroy();
160 public native int getPart();
162 public native void setPart(int partIndex);
164 public native int getParts();
166 public native String getPartName(int partIndex);
168 public native void setPartMode(int partMode);
170 public native String getPartPageRectangles();
172 public native long getDocumentHeight();
174 public native long getDocumentWidth();
176 private native int getDocumentTypeNative();
178 public native void setClientZoom(int nTilePixelWidth, int nTilePixelHeight, int nTileTwipWidth, int nTileTwipHeight);
180 public native void saveAs(String url, String format, String options);
182 private native void paintTileNative(ByteBuffer buffer, int canvasWidth, int canvasHeight, int tilePositionX, int tilePositionY, int tileWidth, int tileHeight);
184 public int getDocumentType() {
185 return getDocumentTypeNative();
188 public void paintTile(ByteBuffer buffer, int canvasWidth, int canvasHeight, int tilePositionX, int tilePositionY, int tileWidth, int tileHeight) {
189 paintTileNative(buffer, canvasWidth, canvasHeight, tilePositionX, tilePositionY, tileWidth, tileHeight);
192 public native void initializeForRendering();
195 * Post a key event to LibreOffice.
196 * @param type - type of key event
197 * @param charCode - the Unicode character generated by this event or 0.
198 * @param keyCode - the integer code representing the key of the event (non-zero for control keys).
200 public native void postKeyEvent(int type, int charCode, int keyCode);
203 * Post a mouse event to LOK
204 * @param type - mouse event type
205 * @param x - x coordinate
206 * @param y - y coordinate
207 * @param count - number of events
209 public native void postMouseEvent(int type, int x, int y, int count, int button, int modifier);
212 * Post a .uno: command to LOK
213 * @param command - the command, like ".uno:Bold"
214 * @param arguments
216 public native void postUnoCommand(String command, String arguments, boolean notifyWhenFinished);
219 * Change text selection.
220 * @param type - text selection type
221 * @param x - x coordinate
222 * @param y - y coordinate
224 public native void setTextSelection(int type, int x, int y);
227 * Change graphic selection.
228 * @param type - graphic selection type
229 * @param x - x coordinate
230 * @param y - y coordinate
232 public native void setGraphicSelection(int type, int x, int y);
235 * Get selected text
236 * @param mimeType
237 * @return
239 public native String getTextSelection(String mimeType);
242 * paste
243 * @param mimeType
244 * @param data
245 * @return
247 public native boolean paste(String mimeType, String data);
250 * Reset current (any kind of) selection.
252 public native void resetSelection();
254 public native String getCommandValues(String command);
257 * Callback to retrieve messages from LOK
259 public interface MessageCallback {
261 * Invoked when a message is retrieved from LOK
262 * @param signalNumber - signal type / number
263 * @param payload - retrieved for the signal
265 void messageRetrieved(int signalNumber, String payload);