|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Public class defining the interface for MIDP Text Editor |
|
15 * |
|
16 */ |
|
17 |
|
18 // PACKAGE |
|
19 package com.nokia.mid.ui; |
|
20 |
|
21 // INTERNAL IMPORTS |
|
22 import com.nokia.mid.ui.impl.LCDUIPackageInvoker; |
|
23 import com.nokia.mid.ui.impl.TextEditorListenerImpl; |
|
24 import com.nokia.mid.ui.impl.TextEditorContainer; |
|
25 |
|
26 // EXTERNAL IMPORTS |
|
27 import com.nokia.mj.impl.rt.legacy.NativeError; |
|
28 import com.nokia.mj.impl.rt.legacy.ToolkitInvoker; |
|
29 import com.nokia.mid.ui.CanvasItem; |
|
30 import javax.microedition.lcdui.Font; |
|
31 import javax.microedition.lcdui.Canvas; |
|
32 import javax.microedition.lcdui.CustomItem; |
|
33 import javax.microedition.lcdui.TextField; |
|
34 import java.util.Enumeration; |
|
35 import com.nokia.mj.impl.rt.support.Finalizer; |
|
36 |
|
37 /** |
|
38 * <P> |
|
39 * A <code>TextEditor</code> is an editable text component that is used with a |
|
40 * parent object; with <code>Canvas</code> or <code>CustomItem</code>. The |
|
41 * <code>TextEditor</code> maybe set to and removed from <code>Canvas</code> |
|
42 * through <code>setParent()</code> method. |
|
43 * </P> |
|
44 * |
|
45 * <P> |
|
46 * The implementation presents the <code>TextEditor</code> with minimal |
|
47 * decoration; only the caret is shown at the requested text insertion position. |
|
48 * It is the responsibility of the application to draw any additional decoration |
|
49 * like focus highlight, border or scroll bar. The animation of the caret, e.g. |
|
50 * blinking, is handled by the TextEditor implementation. |
|
51 * </P> |
|
52 * |
|
53 * <P> |
|
54 * <code>TextEditor</code> supports <em>input constraints</em> identically to |
|
55 * <code>TextField</code>. See <a href="TextField.html#constraints">input |
|
56 * constraints</a> section in the <code>TextField</code> for the definition of |
|
57 * these constants. In addition <code>TextEditor</code> has the same concept of |
|
58 * <em>actual contents</em> and <em>displayed contents</em> as |
|
59 * <code>TextField</code>; these are described in the same <a |
|
60 * href="TextField.html#constraints">input constraints</a> section. |
|
61 * </P> |
|
62 * |
|
63 * <P> |
|
64 * <code>TextEditor</code> supports <em>input modes</em> identically to |
|
65 * <code>TextField</code>. See <a href="TextField.html#modes">input modes</a> |
|
66 * section in the <code>TextField</code> for the definition of these constants. |
|
67 * </P> |
|
68 * |
|
69 * <P> |
|
70 * The text may contain <A HREF="Form.html#linebreak">line breaks</A>. The |
|
71 * display of the text must break accordingly and the user must be able to enter |
|
72 * line break characters. |
|
73 * </P> |
|
74 * |
|
75 * <P> |
|
76 * The TextEditor provides necessary interaction for example for touch input |
|
77 * (handwriting recognition) on touch screen devices and selection of additional |
|
78 * characters. The input on touch devices requires additional windows of top of |
|
79 * the editor window which depending on the implementation may obscure the |
|
80 * parent completely. |
|
81 * </P> |
|
82 * |
|
83 * <P> |
|
84 * Application can add a TextEditorListener to the <code>TextEditor</code> for |
|
85 * example for keeping track of user navigation (caret movement) and other |
|
86 * content changes such as text selection. The events are sent on all occasions |
|
87 * that cause the the caret position to change (including but not limited to |
|
88 * text typing by user, programmatic text insertion, navigation within the |
|
89 * <code>TextEditor</code> content, and text deletion). The events must be sent |
|
90 * to the application prior to they have effect on the editor - for example an |
|
91 * event indicating caret movement must be available for the application before |
|
92 * the implementation actually moves the caret in the editor. |
|
93 * </P> |
|
94 * |
|
95 * <P> |
|
96 * When the <code>TextEditor</code> has focus all the key events that are not |
|
97 * consumed by <code>TextEditor</code> with the current constraints or mapped to |
|
98 * Commands by the implementation are sent to <code>Canvas</code>. |
|
99 * </P> |
|
100 * |
|
101 * <P> |
|
102 * Touch pointer events are not delivered to parent object from the area of the |
|
103 * visible TextEditor. |
|
104 * </P> |
|
105 * |
|
106 * <P> |
|
107 * The implementation will scroll the <code>TextEditor</code> content |
|
108 * automatically on user interaction and when the application calls setCaret or |
|
109 * setSelection methods. For example if a user clicks down on the last visible |
|
110 * row the <code>TextEditor</code> content is scrolled accordingly by one row. |
|
111 * However the Java platform implementation does not draw any scroll bars, this |
|
112 * is left to the application. |
|
113 * </P> |
|
114 * |
|
115 * @since 1.4 |
|
116 */ |
|
117 |
|
118 public class TextEditor |
|
119 extends CanvasItem |
|
120 { |
|
121 |
|
122 // Protected data for extending classes. |
|
123 |
|
124 // LCDUI Toolkit object. |
|
125 Object iToolkit; |
|
126 |
|
127 // Native handle |
|
128 int iHandle; |
|
129 |
|
130 // LCDUI package invoker. |
|
131 LCDUIPackageInvoker iLCDUIPackageInvoker; |
|
132 |
|
133 // Change listener. May be NULL. |
|
134 TextEditorListenerImpl iListener; |
|
135 |
|
136 // Private data |
|
137 |
|
138 // LCDUI Toolkit invoker object. |
|
139 private ToolkitInvoker iToolkitInvoker; |
|
140 // The current set of constraints of this text editor component. |
|
141 private int iConstraints; |
|
142 |
|
143 // Initial input mode |
|
144 private java.lang.String iCharacterSubset; |
|
145 |
|
146 // The current maximum size of this text editor component. |
|
147 private int iMaxSize; |
|
148 |
|
149 // The current font of this text editor component |
|
150 private Font iFont; |
|
151 |
|
152 // Indicates receiving of pointer events by the editor |
|
153 private boolean iTouchEnabled; |
|
154 |
|
155 // Text editor container for handling editor focusing. |
|
156 private static TextEditorContainer iEditorContainer; |
|
157 |
|
158 // Color indicators. Must be in sync with MMIDTextEditor::TColorType |
|
159 private static final int COLOR_BACKGROUND = 0; |
|
160 private static final int COLOR_FOREGROUND = 1; |
|
161 private static final int COLOR_HIGHLIGHT_BACKGROUND = 2; |
|
162 private static final int COLOR_HIGHLIGHT_FOREGROUND = 3; |
|
163 |
|
164 // The maximum value for all colors. |
|
165 private static final int COLOR_MAX_VALUE = 255; |
|
166 |
|
167 // Static block for creating editor container. |
|
168 static |
|
169 { |
|
170 iEditorContainer = new TextEditorContainer(); |
|
171 } |
|
172 |
|
173 private Finalizer mFinalizer; |
|
174 |
|
175 /** |
|
176 * <P> |
|
177 * Creates a new <code>TextEditor</code> object with the given initial |
|
178 * contents, maximum size in characters, constraints and editor size in |
|
179 * pixels. |
|
180 * </P> |
|
181 * |
|
182 * <P> |
|
183 * If the text parameter is <code>null</code>, the <code>TextEditor</code> |
|
184 * is created empty. |
|
185 * </P> |
|
186 * |
|
187 * <P> |
|
188 * The <code>maxSize</code> parameter must be greater than zero. An |
|
189 * <code>IllegalArgumentException</code> is thrown if the length of the |
|
190 * initial contents string exceeds <code>maxSize</code>. However, the |
|
191 * implementation may assign a maximum size smaller than the application had |
|
192 * requested. If this occurs, and if the length of the contents exceeds the |
|
193 * newly assigned maximum size, the contents are truncated from the end in |
|
194 * order to fit, and no exception is thrown. |
|
195 * </P> |
|
196 * |
|
197 * <P> |
|
198 * On Series60-devices, if the MIDlet is manufacturer or operator-signed, |
|
199 * the object returned by this method will also implement the |
|
200 * com.nokia.mid.ui.s60.TextEditor |
|
201 * </P> |
|
202 * |
|
203 * @param text |
|
204 * the initial contents, or <code>null</code> if the |
|
205 * <code>TextEditor</code> is to be created empty |
|
206 * @param maxSize |
|
207 * the maximum capacity in characters |
|
208 * @param constraints |
|
209 * see the input constraints in <code>TextField</code></a> |
|
210 * @param width |
|
211 * the width of the bounding box, in pixels |
|
212 * @param height |
|
213 * the height of the bounding box, in pixels |
|
214 * @return Instance of TextEditor |
|
215 * |
|
216 * @throws IllegalArgumentException |
|
217 * if <code>aMaxSize</code> is zero or less |
|
218 * @throws IllegalArgumentException |
|
219 * if the value of the constraints parameter is invalid |
|
220 * @throws IllegalArgumentException |
|
221 * if <code>aText</code> is illegal for the specified |
|
222 * constraints |
|
223 * @throws IllegalArgumentException |
|
224 * if the length of the string exceeds the requested maximum |
|
225 * capacity |
|
226 * @throws IllegalArgumentException |
|
227 * if the width or height is less than one pixel |
|
228 */ |
|
229 public static TextEditor createTextEditor( |
|
230 String text, |
|
231 int maxSize, |
|
232 int constraints, |
|
233 int width, |
|
234 int height) |
|
235 { |
|
236 return new TextEditorImpl(text, maxSize, constraints, width, height); |
|
237 } |
|
238 |
|
239 /** |
|
240 * <P> |
|
241 * Creates a new empty <code>TextEditor</code> with the given maximum size |
|
242 * in characters, constraints and editor size as number of visible rows. |
|
243 * </P> |
|
244 * |
|
245 * <P> |
|
246 * The <code>rows</code> parameter indicates the requested number of visible |
|
247 * rows in the editor. TextEditor then assigns the initial height for the |
|
248 * editor based on the requested number of rows and width of the editor. |
|
249 * </P> |
|
250 * |
|
251 * <P> |
|
252 * The <code>maxSize</code> parameter must be greater than zero. An |
|
253 * <code>IllegalArgumentException</code> is thrown if the length of the |
|
254 * initial contents string exceeds <code>maxSize</code>. However, the |
|
255 * implementation may assign a maximum size smaller than the application had |
|
256 * requested. If this occurs, and if the length of the contents exceeds the |
|
257 * newly assigned maximum size, the contents are truncated from the end in |
|
258 * order to fit, and no exception is thrown. |
|
259 * </P> |
|
260 * |
|
261 * <P> |
|
262 * On Series60-devices, if the MIDlet is manufacturer or operator-signed, |
|
263 * the object returned by this method will also implement the |
|
264 * com.nokia.mid.ui.s60.TextEditor |
|
265 * </P> |
|
266 * |
|
267 * @param maxSize |
|
268 * the maximum capacity in characters |
|
269 * @param constraints |
|
270 * see the input constraints in <code>TextField</code></a> |
|
271 * @param width |
|
272 * the width of the bounding box, in pixels |
|
273 * @param rows |
|
274 * the requested number of visible rows in the editor |
|
275 * @return Instance of TextEditor |
|
276 * |
|
277 * @throws IllegalArgumentException |
|
278 * if <code>aMaxSize</code> or <code>aRows</code> is zero or |
|
279 * less |
|
280 * @throws IllegalArgumentException |
|
281 * if the value of the constraints parameter is invalid |
|
282 * @throws IllegalArgumentException |
|
283 * if the length of the string exceeds the requested maximum |
|
284 * capacity |
|
285 * @throws IllegalArgumentException |
|
286 * if the width is less than one pixel |
|
287 */ |
|
288 public static TextEditor createTextEditor( |
|
289 int maxSize, |
|
290 int constraints, |
|
291 int width, |
|
292 int rows) |
|
293 { |
|
294 return new TextEditorImpl(maxSize, constraints, width, rows); |
|
295 } |
|
296 |
|
297 /** |
|
298 * Sets this TextEditor focused or removes keyboard focus. |
|
299 * Calling setFocus(true) enables text editing from keys as the delivery |
|
300 * of needed key events will be targeted to the TextEditor instead of |
|
301 * the parent object (e.g. Canvas). Focus needs to be explicitly set to |
|
302 * the TextEditor by application. When Canvas or CustomItem does not have |
|
303 * any focused TextEditor all key and pointer events are delivered to |
|
304 * normal key delivery methods of parent. Necessary key events are |
|
305 * captured by TextEditor only when it has focus. |
|
306 * <P> |
|
307 * The setFocus affects to the parent key event delivery in following |
|
308 * way: If all TextEditors are unfocused the key event delivery of parent |
|
309 * works as if there are not any TextEditors in it, only when a focus is |
|
310 * set via this method to a TextEditor the key event delivery is modified. |
|
311 * The focused editor starts to capture the necessary key events and these |
|
312 * key events are not delivered to parent. The set of key events captured |
|
313 * depends on TextEditor implementation and device HW but in most |
|
314 * implementations nearly all device keys are captured by the editor for |
|
315 * text insertion, input mode changes and caret move functionalities. |
|
316 * Especially applications should not assume to get key events from keys |
|
317 * mapped to game actions as most probably the same keys are used to |
|
318 * navigate the text caret within the editor. The keys that are used for |
|
319 * Command launching in Canvas are available for applications on focused |
|
320 * TextEditor and these keys either launch commands or send low-level |
|
321 * key events as normally. |
|
322 * <P> |
|
323 * Setting focus does not cause any visual focus indication by the |
|
324 * implementation other than showing the caret. Any other change in the |
|
325 * visual appearance of the editor in focused state is the responsibility |
|
326 * of the application; this can be done for example by drawing a focus |
|
327 * border around the TextEditor or by changing the background color or |
|
328 * transparency of the editor. |
|
329 * <P> |
|
330 * If this TextEditor has already been focused earlier and the editor |
|
331 * contents has not changed after previous unfocusing, then after calling |
|
332 * setFocus again the caret position should be retained. |
|
333 * <P> |
|
334 * If there already is another focused TextEditor on the Canvas, the |
|
335 * focus is first removed from that TextEditor before setting this |
|
336 * TextEditor focused. |
|
337 * <P> |
|
338 * Calling setFocus(false) disables key based text editing and returns |
|
339 * the delivery of key events and pointer events to the underlying Canvas. |
|
340 * |
|
341 * @param focused |
|
342 * keyboard focus of the TextEditor |
|
343 * |
|
344 * @throws java.lang.IllegalStateException |
|
345 * If the TextEditor is not added to Canvas |
|
346 * |
|
347 * @see #hasFocus() |
|
348 */ |
|
349 |
|
350 public void setFocus(boolean focused) |
|
351 { |
|
352 synchronized (iToolkit) |
|
353 { |
|
354 checkParent(); |
|
355 |
|
356 // If focus is set, adjust the focus of other known editors. |
|
357 if (focused) |
|
358 { |
|
359 // Remove focus from other editors in this parent |
|
360 Enumeration editors = iEditorContainer.getEditors(iParent); |
|
361 |
|
362 while (editors.hasMoreElements()) |
|
363 { |
|
364 TextEditor editor = (TextEditor) editors.nextElement(); |
|
365 |
|
366 // Do not remove focus from this editor if it is on. |
|
367 if (editor != this) |
|
368 { |
|
369 editor.setFocus(false); |
|
370 } |
|
371 } |
|
372 } |
|
373 |
|
374 NativeError.check(_setFocusState(getToolkitHandle(), iHandle, |
|
375 focused)); |
|
376 } |
|
377 } |
|
378 |
|
379 /** |
|
380 * Returns the focus state of TextEditor. |
|
381 * |
|
382 * @return the focus state of the editor |
|
383 * @see #setFocus(boolean focused) |
|
384 */ |
|
385 public boolean hasFocus() |
|
386 { |
|
387 boolean focusState; |
|
388 |
|
389 synchronized (iToolkit) |
|
390 { |
|
391 checkParent(); |
|
392 focusState = _getFocusState(getToolkitHandle(), iHandle); |
|
393 } |
|
394 |
|
395 return focusState; |
|
396 } |
|
397 |
|
398 /** |
|
399 * Set the parent object of this <code>TextEditor</code>. |
|
400 * <P> |
|
401 * Typically the parent object would be Canvas. Setting the parameter to |
|
402 * null removes the association to the parent. If |
|
403 * <code>setParent(null)</code> is called for a <code>TextEditor</code> yet |
|
404 * not having any parent or <code>setParent(parent)</code> is called with |
|
405 * the same parent, the call is silently ignored. |
|
406 * <P> |
|
407 * |
|
408 * @param parent |
|
409 * the parent object |
|
410 * |
|
411 * @throws IllegalArgumentException |
|
412 * if parent is not a valid object with which a |
|
413 * <code>TextEditor</code> can be associated, or if CanvasItem |
|
414 * is already set to another another parent |
|
415 */ |
|
416 public void setParent(java.lang.Object parent) |
|
417 { |
|
418 // Ignore argument check if parent is set to null. |
|
419 // Custom item support will be added in future, currently it's |
|
420 // unsupported. |
|
421 if (((parent != null) && !(parent instanceof Canvas)) || |
|
422 ((parent != null) && (iParent != null) && (iParent != parent))) |
|
423 { |
|
424 throw new IllegalArgumentException(ERROR_NOT_A_VALID_PARENT_OBJECT); |
|
425 } |
|
426 |
|
427 int parentHandle = 0; |
|
428 |
|
429 if (parent != iParent) |
|
430 { |
|
431 // Lock this object so that parent cannot be adjusted from |
|
432 // other threads. |
|
433 synchronized (iToolkit) |
|
434 { |
|
435 // Toolkit invoker can be used to get proper handles. |
|
436 if (parent instanceof Canvas) |
|
437 { |
|
438 // Note that canvas is shown inside a displayable so in |
|
439 // this case we use the handle to the displayble object. |
|
440 parentHandle = iToolkitInvoker.getDisplayableHandle(parent); |
|
441 } |
|
442 else if (parent instanceof CustomItem) |
|
443 { |
|
444 parentHandle = iToolkitInvoker.itemGetHandle(parent); |
|
445 } |
|
446 |
|
447 // parentHandle = 0 indicates removal of the parent. |
|
448 int error = |
|
449 _setParent(getToolkitHandle(), iHandle, parentHandle); |
|
450 |
|
451 // Check if an error occured when setting the parent object. |
|
452 NativeError.check(error); |
|
453 |
|
454 // Operation was successful. Store parent and register |
|
455 // to container. Remove from container and previous parent. |
|
456 if (iParent != null) |
|
457 { |
|
458 iEditorContainer.removeEditor(this, iParent); |
|
459 } |
|
460 // Store the editor with new parent if not null. |
|
461 if (parent != null) |
|
462 { |
|
463 iEditorContainer.addEditor(this, parent); |
|
464 } |
|
465 |
|
466 iParent = parent; |
|
467 } |
|
468 } |
|
469 } |
|
470 |
|
471 /** |
|
472 * Sets the size of this <code>TextEditor</code> in pixels. |
|
473 * |
|
474 * @param width |
|
475 * width in pixels |
|
476 * @param height |
|
477 * height in pixels |
|
478 * |
|
479 * @throws IllegalArgumentException |
|
480 * if the width or height is less than one pixel |
|
481 */ |
|
482 public void setSize(int width, int height) |
|
483 { |
|
484 // Validate width and row count |
|
485 if (width < 1 || height < 1) |
|
486 { |
|
487 throw new IllegalArgumentException(ERROR_GIVEN_ARGUMENTS_NOT_VALID); |
|
488 } |
|
489 |
|
490 synchronized (iToolkit) |
|
491 { |
|
492 NativeError.check(_setSize(getToolkitHandle(), iHandle, width, |
|
493 height)); |
|
494 |
|
495 // Operation was a success, store size. |
|
496 iWidth = width; |
|
497 iHeight = height; |
|
498 } |
|
499 } |
|
500 |
|
501 /** |
|
502 * <P> |
|
503 * Sets the rendering position of this <code>TextEditor</code>. The anchor |
|
504 * point given is relative to the upper left corner of the parent, |
|
505 * <code>Canvas</code>. |
|
506 * </P> |
|
507 * |
|
508 * <P> |
|
509 * The <code>TextEditor</code> may be placed fully off or partially of the |
|
510 * visible area of the parent, <code>Canvas</code>, by the |
|
511 * <code>setPosition</code> method; in this case the <code>TextEditor</code> |
|
512 * is just partly visible. |
|
513 * </P> |
|
514 * |
|
515 * @param x |
|
516 * the x coordinate of the anchor point, in pixels. |
|
517 * @param y |
|
518 * the y coordinate of the anchor point, in pixels. |
|
519 * @throws IllegalStateException |
|
520 * if a valid parent object has not been set. |
|
521 * @see #setParent(java.lang.Object parent) |
|
522 */ |
|
523 public void setPosition(int x, int y) |
|
524 { |
|
525 synchronized (iToolkit) |
|
526 { |
|
527 checkParent(); |
|
528 |
|
529 NativeError.check(_setPosition(getToolkitHandle(), iHandle, x, y)); |
|
530 |
|
531 // Store current position. |
|
532 iPositionX = x; |
|
533 iPositionY = y; |
|
534 } |
|
535 } |
|
536 |
|
537 /** |
|
538 * <P> |
|
539 * Sets the visibility value of <code>TextEditor</code>. Initially |
|
540 * <code>TextEditor</code> is not visible so it must be explicitly set to |
|
541 * visible in order it to appear on UI. |
|
542 * </P> |
|
543 * |
|
544 * <P> |
|
545 * Setting visibility to true shows the editor with its content, but without |
|
546 * the caret. If the editor does not have any visible content and does not |
|
547 * have any background color set then this method effectively does not cause |
|
548 * any visual change in the display. If the editor is already visible |
|
549 * calling <code>setVisible(true)</code> does nothing. |
|
550 * </P> |
|
551 * |
|
552 * <P> |
|
553 * Setting the visibility to false hides the editor and its content. If the |
|
554 * <code>TextEditor</code> has focus then the focus is removed. If the |
|
555 * editor is already hidden calling <code>setVisible(false)</code> does |
|
556 * nothing. |
|
557 * </P> |
|
558 * |
|
559 * @param visible |
|
560 * visibility of the <code>TextEditor</code> |
|
561 * @throws IllegalStateException |
|
562 * if a valid parent object has not been set. |
|
563 * @see #setParent(java.lang.Object parent) |
|
564 */ |
|
565 public void setVisible(boolean visible) |
|
566 { |
|
567 synchronized (iToolkit) |
|
568 { |
|
569 checkParent(); |
|
570 |
|
571 NativeError |
|
572 .check(_setVisible(getToolkitHandle(), iHandle, visible)); |
|
573 |
|
574 iVisible = visible; |
|
575 } |
|
576 } |
|
577 |
|
578 /** |
|
579 * <P> |
|
580 * Sets the Z-position, or the elevation, of the item. |
|
581 * <p> |
|
582 * The elevation decides the stacking order of neighboring items. An item of |
|
583 * high Z-position will be drawn on top of an item with a lower Z-position |
|
584 * if they share the same parent item. |
|
585 * <p> |
|
586 * The z-position is unique for each item meaning that changing a Z-position |
|
587 * of an item may change the Z-position of the items that share the same |
|
588 * parent item. The Z-position does not affect the item's size in any way. |
|
589 * <p> |
|
590 * When items are added with {@link CanvasItem#setParent} they will get a |
|
591 * Z-position that is increased by 1 from the item that is the top most item |
|
592 * at that time. |
|
593 * </P> |
|
594 * |
|
595 * @param z |
|
596 * the Z-position of the item. |
|
597 * |
|
598 * @throws IllegalArgumentException |
|
599 * If <code>z</code> < 0 |
|
600 * @throws IllegalStateException |
|
601 * if a valid parent object has not been set. |
|
602 * |
|
603 * @see #getZPosition() |
|
604 * @see #setParent(java.lang.Object parent) |
|
605 */ |
|
606 public void setZPosition(int z) |
|
607 { |
|
608 if (z < 0) |
|
609 { |
|
610 throw new IllegalArgumentException(); |
|
611 } |
|
612 |
|
613 synchronized (iToolkit) |
|
614 { |
|
615 checkParent(); |
|
616 |
|
617 NativeError.check(_setZPosition(getToolkitHandle(), iHandle, z)); |
|
618 } |
|
619 } |
|
620 |
|
621 /** |
|
622 * Specifies whether or not the editor will receive touch-events. |
|
623 * <p> |
|
624 * This is enabled by default. |
|
625 * An editor with touch-event disabled won't be able to perform any |
|
626 * touch-related functionality such as scrolling or positioning the |
|
627 * cursor. It may however still be controlled via the |
|
628 * virtual keypad/control-panel if that is enabled, or receive other + |
|
629 * input e.g. via physical keys |
|
630 * <p> |
|
631 * @param enabled |
|
632 * true to enabled touch-event, false to disable |
|
633 */ |
|
634 public void setTouchEnabled(boolean enabled) |
|
635 { |
|
636 if (iTouchEnabled != enabled) |
|
637 { |
|
638 synchronized (iToolkit) |
|
639 { |
|
640 _setTouchEnabled(getToolkitHandle(), iHandle, enabled); |
|
641 iTouchEnabled = enabled; |
|
642 } |
|
643 } |
|
644 } |
|
645 |
|
646 /** |
|
647 * Gets the current touch-enabled state |
|
648 * <p> |
|
649 * @return true if the editor is touch-enabled, false otherwise |
|
650 */ |
|
651 public boolean isTouchEnabled() |
|
652 { |
|
653 return iTouchEnabled; |
|
654 } |
|
655 |
|
656 /** |
|
657 * <P> |
|
658 * Returns the Z-position, or the elevation, of the item. The Z-position |
|
659 * decides the stacking order of neighboring items. |
|
660 * </P> |
|
661 * |
|
662 * @return the Z-position of the item. |
|
663 * |
|
664 * @throws IllegalStateException |
|
665 * if a valid parent object has not been set. |
|
666 * |
|
667 * @see #setZPosition(int) |
|
668 * @see #setParent(java.lang.Object parent) |
|
669 */ |
|
670 public int getZPosition() |
|
671 { |
|
672 int positionZ = -1; |
|
673 |
|
674 synchronized (iToolkit) |
|
675 { |
|
676 checkParent(); |
|
677 |
|
678 positionZ = _getZPosition(getToolkitHandle(), iHandle); |
|
679 } |
|
680 |
|
681 NativeError.check(positionZ); |
|
682 return positionZ; |
|
683 } |
|
684 |
|
685 /** |
|
686 * Gets the line margin height in this <code>TextEditor</code> in pixels. |
|
687 * <p> |
|
688 * Gets the possible line margin height that editor has in addition to the |
|
689 * normal font height (<code>Font getHeight()</code>). The returned value is |
|
690 * 0 if the editor does not have any additional line margins to the text |
|
691 * height returned from <code>getHeight()</code> of Font set to the editor. |
|
692 * <p> |
|
693 * |
|
694 * @return the line margin height in pixels |
|
695 * |
|
696 * @see #setParent(java.lang.Object parent) |
|
697 */ |
|
698 public int getLineMarginHeight() |
|
699 { |
|
700 int lineMarginHeight = 0; |
|
701 |
|
702 if (iParent != null) |
|
703 { |
|
704 synchronized (iToolkit) |
|
705 { |
|
706 // Get the line margin height from the native side. |
|
707 lineMarginHeight = |
|
708 _getLineMarginHeight(getToolkitHandle(), iHandle); |
|
709 } |
|
710 |
|
711 // Check if the line margin height was not returned correctly. |
|
712 NativeError.check(lineMarginHeight); |
|
713 } |
|
714 return lineMarginHeight; |
|
715 } |
|
716 |
|
717 /** |
|
718 * Gets the whole content height in this <code>TextEditor</code> in pixels. |
|
719 * <p> |
|
720 * |
|
721 * The returned value must include the height of the whole content in the |
|
722 * editor, not just the height of the visible content. |
|
723 * <p> |
|
724 * |
|
725 * Note that the method returns 0, if the editor has no parent. |
|
726 * <p> |
|
727 * |
|
728 * @return the height of the whole content in the editor in pixels |
|
729 * |
|
730 * @see #setParent(java.lang.Object parent) |
|
731 */ |
|
732 public int getContentHeight() |
|
733 { |
|
734 int contentHeight = 0; |
|
735 if (iParent != null) |
|
736 { |
|
737 synchronized (iToolkit) |
|
738 { |
|
739 // Get the content height from the native side. |
|
740 contentHeight = _getContentHeight(getToolkitHandle(), iHandle); |
|
741 } |
|
742 |
|
743 // Check if the size was not returned correctly. |
|
744 NativeError.check(contentHeight); |
|
745 } |
|
746 return contentHeight; |
|
747 } |
|
748 |
|
749 /** |
|
750 * <P> |
|
751 * Sets the index of the caret. The caret can be used to indicate a position |
|
752 * in the text. |
|
753 * </P> |
|
754 * |
|
755 * <P> |
|
756 * The Java platform implementation must scroll the content of the |
|
757 * <code>TextEditor</code> automatically so that the caret is within the |
|
758 * visible area. If the caret is set above the current position the content |
|
759 * should be scrolled so that the caret is on the top most visible row. If |
|
760 * the caret is set below the current position the content should be |
|
761 * scrolled so that the caret is on the lowest visible row. |
|
762 * </P> |
|
763 * |
|
764 * @param index |
|
765 * the character index before which to place the caret |
|
766 * |
|
767 * @throws StringIndexOutOfBoundsException |
|
768 * if <code>index</code> does not specify a valid range within |
|
769 * the content of the <code>TextEditor</code> |
|
770 */ |
|
771 public void setCaret(int index) |
|
772 { |
|
773 // New position must be in range of the current content. |
|
774 if (index < 0 || index > size()) |
|
775 { |
|
776 throw new StringIndexOutOfBoundsException( |
|
777 ERROR_GIVEN_ARGUMENTS_NOT_VALID); |
|
778 } |
|
779 |
|
780 synchronized (iToolkit) |
|
781 { |
|
782 NativeError.check(_setCaret(getToolkitHandle(), iHandle, index)); |
|
783 } |
|
784 } |
|
785 |
|
786 /** |
|
787 * Gets the current position of the caret in the editor. |
|
788 * |
|
789 * @return the current caret position, <code>0</code> if at the beginning |
|
790 */ |
|
791 public int getCaretPosition() |
|
792 { |
|
793 int caretPosition = 0; |
|
794 |
|
795 synchronized (iToolkit) |
|
796 { |
|
797 caretPosition = _getCaretPosition(getToolkitHandle(), iHandle); |
|
798 } |
|
799 |
|
800 // Verify that the operation was a success. |
|
801 NativeError.check(caretPosition); |
|
802 return caretPosition; |
|
803 } |
|
804 |
|
805 /** |
|
806 * <P> |
|
807 * Gets the topmost pixel position of the topmost visible line in the |
|
808 * editor. |
|
809 * </P> |
|
810 * |
|
811 * <P> |
|
812 * The returned y coordinate value is relative to the whole content height, |
|
813 * not just the visible part. |
|
814 * </P> |
|
815 * |
|
816 * <P> |
|
817 * This method can be used by the application together with the |
|
818 * <code>getContentHeight</code>, height of the font, |
|
819 * <code>getLineMarginHeight</code>, and <code>getCaretPosition</code> |
|
820 * methods in drawing custom visual cues like a scroll bar or other content |
|
821 * sensitive pop-ups. |
|
822 * </P> |
|
823 * |
|
824 * <P> |
|
825 * Note that the method returns 0, if the editor has no parent. |
|
826 * </P> |
|
827 * |
|
828 * @return the topmost pixel position of the visible content. |
|
829 */ |
|
830 public int getVisibleContentPosition() |
|
831 { |
|
832 int ypos = 0; |
|
833 |
|
834 if (iParent != null) |
|
835 { |
|
836 synchronized (iToolkit) |
|
837 { |
|
838 ypos = _getVisibleContentPosition(getToolkitHandle(), iHandle); |
|
839 } |
|
840 |
|
841 // Verify that the operation was a success. |
|
842 NativeError.check(ypos); |
|
843 } |
|
844 return ypos; |
|
845 } |
|
846 |
|
847 /** |
|
848 * <P> |
|
849 * Gets the font being used in rendering the text content in this |
|
850 * <code>TextEditor</code>. |
|
851 * </P> |
|
852 * |
|
853 * @return the font being used in this <code>TextEditor</code> |
|
854 */ |
|
855 public Font getFont() |
|
856 { |
|
857 synchronized (iToolkit) |
|
858 { |
|
859 return iFont == null ? Font.getDefaultFont() : iFont; |
|
860 } |
|
861 } |
|
862 |
|
863 /** |
|
864 * <P> |
|
865 * Sets the application preferred font for rendering the text content in |
|
866 * this <code>TextEditor</code>. Setting the font is a hint to the |
|
867 * implementation, and the implementation may disregard the requested font. |
|
868 * </P> |
|
869 * |
|
870 * <P> |
|
871 * The <code>font</code> parameter must be a valid <code>Font</code> object |
|
872 * or <code>null</code>. If the <code>font</code> parameter is |
|
873 * <code>null</code>, the implementation must use its default font to render |
|
874 * the text content. |
|
875 * </P> |
|
876 * |
|
877 * @param font |
|
878 * the application preferred font to be used in this |
|
879 * <code>TextEditor</code> |
|
880 */ |
|
881 public void setFont(Font font) |
|
882 { |
|
883 if (font == null) |
|
884 { |
|
885 font = Font.getDefaultFont(); |
|
886 } |
|
887 |
|
888 int[] newSize = new int[2]; |
|
889 |
|
890 synchronized (iToolkit) |
|
891 { |
|
892 NativeError.check(_setFont(getToolkitHandle(), iHandle, |
|
893 iLCDUIPackageInvoker.getFontHandle(font), newSize)); |
|
894 |
|
895 iFont = font; |
|
896 |
|
897 iWidth = newSize[0]; |
|
898 iHeight = newSize[1]; |
|
899 } |
|
900 } |
|
901 |
|
902 /** |
|
903 * Gets the background color and alpha of this <code>TextEditor</code>. |
|
904 * |
|
905 * @return the background color |
|
906 */ |
|
907 public int getBackgroundColor() |
|
908 { |
|
909 int color = 0; |
|
910 |
|
911 synchronized (iToolkit) |
|
912 { |
|
913 color = _getColor(getToolkitHandle(), iHandle, |
|
914 COLOR_BACKGROUND); |
|
915 } |
|
916 return color; |
|
917 } |
|
918 |
|
919 /** |
|
920 * Gets the foreground color and alpha of this <code>TextEditor</code> |
|
921 * |
|
922 * @return the foreground color |
|
923 */ |
|
924 public int getForegroundColor() |
|
925 { |
|
926 int color = 0; |
|
927 |
|
928 synchronized (iToolkit) |
|
929 { |
|
930 color = _getColor(getToolkitHandle(), iHandle, |
|
931 COLOR_FOREGROUND); |
|
932 } |
|
933 return color; |
|
934 } |
|
935 |
|
936 /** |
|
937 * Sets the background color and alpha of this <code>TextEditor</code> to |
|
938 * the specified values. The default background color for editor is fully |
|
939 * transparent white. |
|
940 * |
|
941 * @param color |
|
942 * the color |
|
943 */ |
|
944 public void setBackgroundColor(int color) |
|
945 { |
|
946 int alpha = (color >> 24) & 0xff; |
|
947 int red = (color >> 16) & 0xff; |
|
948 int green = (color >> 8) & 0xff; |
|
949 int blue = (color) & 0xff; |
|
950 |
|
951 doSetColor(alpha, red, green, blue, COLOR_BACKGROUND); |
|
952 } |
|
953 |
|
954 /** |
|
955 * Sets the foreground color and alpha of this <code>TextEditor</code> to |
|
956 * the specified values. The content, e.g. text, in the editor must be drawn |
|
957 * with this color. The default foreground color is fully opaque black. |
|
958 * |
|
959 * @param color |
|
960 * the color |
|
961 */ |
|
962 public void setForegroundColor(int color) |
|
963 { |
|
964 int alpha = (color >> 24) & 0xff; |
|
965 int red = (color >> 16) & 0xff; |
|
966 int green = (color >> 8) & 0xff; |
|
967 int blue = (color) & 0xff; |
|
968 |
|
969 doSetColor(alpha, red, green, blue, COLOR_FOREGROUND); |
|
970 } |
|
971 |
|
972 /** |
|
973 * Sets the highlight background color. This impacts text background color |
|
974 * for the selected text. |
|
975 * The text in a current selection range will be |
|
976 * rendered using given color value. The default highlight background |
|
977 * color is fully opaque black. |
|
978 * |
|
979 * This method is not supported on S40 platform. |
|
980 * |
|
981 * @param color |
|
982 * the color |
|
983 */ |
|
984 public void setHighlightBackgroundColor(int color) |
|
985 { |
|
986 int alpha = (color >> 24) & 0xff; |
|
987 int red = (color >> 16) & 0xff; |
|
988 int green = (color >> 8) & 0xff; |
|
989 int blue = (color) & 0xff; |
|
990 |
|
991 doSetColor(alpha, red, green, blue, COLOR_HIGHLIGHT_BACKGROUND); |
|
992 } |
|
993 |
|
994 /** |
|
995 * Sets the highlight foreground color. This impacts text color for the |
|
996 * selected text. |
|
997 * The text in a current selection range will be rendered |
|
998 * using given color value. The default highlight foreground color is fully |
|
999 * opaque white. |
|
1000 * |
|
1001 * This method is not supported on S40 platform. |
|
1002 * |
|
1003 * @param color |
|
1004 * the color |
|
1005 */ |
|
1006 public void setHighlightForegroundColor(int color) |
|
1007 { |
|
1008 int alpha = (color >> 24) & 0xff; |
|
1009 int red = (color >> 16) & 0xff; |
|
1010 int green = (color >> 8) & 0xff; |
|
1011 int blue = (color) & 0xff; |
|
1012 |
|
1013 doSetColor(alpha, red, green, blue, COLOR_HIGHLIGHT_FOREGROUND); |
|
1014 } |
|
1015 |
|
1016 /** |
|
1017 * Sets the content of the <code>TextEditor</code> as a string. The set |
|
1018 * string replaces any previous content in the editor. |
|
1019 * |
|
1020 * @param content |
|
1021 * the new content of the <code>TextEditor</code> as string, |
|
1022 * <code>null</code> empties the <code>TextEditor</code> |
|
1023 * |
|
1024 * @throws IllegalArgumentException |
|
1025 * if <code>aContent</code> is illegal for the current input |
|
1026 * constraints |
|
1027 * @throws IllegalArgumentException |
|
1028 * if the given text would exceed the current maximum capacity |
|
1029 * of the editor |
|
1030 */ |
|
1031 public void setContent(String content) |
|
1032 { |
|
1033 // Verify that text is not invalid. |
|
1034 iLCDUIPackageInvoker.checkText(content, iMaxSize); |
|
1035 |
|
1036 synchronized (iToolkit) |
|
1037 { |
|
1038 NativeError |
|
1039 .check(_setContent(getToolkitHandle(), iHandle, content)); |
|
1040 } |
|
1041 } |
|
1042 |
|
1043 /** |
|
1044 * Gets the string content in the <code>TextEditor</code>. |
|
1045 * |
|
1046 * @return The editor current content |
|
1047 */ |
|
1048 public String getContent() |
|
1049 { |
|
1050 String content = null; |
|
1051 int[] error = new int[1]; |
|
1052 |
|
1053 synchronized (iToolkit) |
|
1054 { |
|
1055 content = _getContent(getToolkitHandle(), iHandle, error); |
|
1056 } |
|
1057 |
|
1058 NativeError.check(error[0]); |
|
1059 return content; |
|
1060 } |
|
1061 |
|
1062 /** |
|
1063 * <P> |
|
1064 * Inserts a string into the content of the <code>TextEditor</code>. |
|
1065 * </P> |
|
1066 * |
|
1067 * <P> |
|
1068 * The string is inserted just prior to the character indicated by the |
|
1069 * <code>position</code> parameter, where zero specifies the first character |
|
1070 * of the content in the <code>TextEditor</code>. If <code>position</code> |
|
1071 * is less than or equal to zero, the insertion occurs at the beginning of |
|
1072 * the content. If <code>position</code> is greater than or equal to the |
|
1073 * current size of the content, the insertion occurs immediately after the |
|
1074 * end of the content. |
|
1075 * </P> |
|
1076 * |
|
1077 * <P> |
|
1078 * The current size of the contents is increased by the number of inserted |
|
1079 * characters. The resulting string must fit within the current maximum |
|
1080 * capacity. |
|
1081 * </P> |
|
1082 * |
|
1083 * @param text |
|
1084 * the <code>String</code> to be inserted |
|
1085 * @param position |
|
1086 * the position at which insertion is to occur |
|
1087 * |
|
1088 * @throws IllegalArgumentException |
|
1089 * if the resulting content would be illegal for the current |
|
1090 * input constraints |
|
1091 * @throws IllegalArgumentException |
|
1092 * if the insertion would exceed the current maximum capacity |
|
1093 * @throws NullPointerException |
|
1094 * if <code>text</code> is <code>null</code> |
|
1095 */ |
|
1096 public void insert(String text, int position) |
|
1097 { |
|
1098 // Check illegal arguments. Note that NullPointerException is thrown |
|
1099 // correctly if text is null when text.length() is called. |
|
1100 if (text.length() + size() > iMaxSize) |
|
1101 { |
|
1102 throw new IllegalArgumentException(ERROR_GIVEN_ARGUMENTS_NOT_VALID); |
|
1103 } |
|
1104 |
|
1105 synchronized (iToolkit) |
|
1106 { |
|
1107 NativeError.check(_insert(getToolkitHandle(), iHandle, text, |
|
1108 position)); |
|
1109 } |
|
1110 } |
|
1111 |
|
1112 /** |
|
1113 * <P> |
|
1114 * Deletes characters from the <code>TextEditor</code>. |
|
1115 * </P> |
|
1116 * |
|
1117 * <P> |
|
1118 * The <code>offset</code> and <code>length</code> parameters must specify a |
|
1119 * valid range of characters within the contents of the |
|
1120 * <code>TextEditor</code>. The <code>offset</code> parameter must be within |
|
1121 * the range <code>[0..(size())]</code>, inclusive. The <code>length</code> |
|
1122 * parameter must be a non-negative integer such that |
|
1123 * <code>(offset + length) <= size()</code>. |
|
1124 * </P> |
|
1125 * |
|
1126 * @param offset |
|
1127 * the beginning of the region to be deleted |
|
1128 * @param length |
|
1129 * the number of characters to be deleted |
|
1130 * |
|
1131 * @throws IllegalArgumentException |
|
1132 * if the resulting contents would be illegal for the current |
|
1133 * input constraints |
|
1134 * @throws StringIndexOutOfBoundsException |
|
1135 * if <code>offset</code> and <code>length</code> do not specify |
|
1136 * a valid range within the content of the |
|
1137 * <code>TextEditor</code> |
|
1138 */ |
|
1139 public void delete(int offset, int length) |
|
1140 { |
|
1141 iLCDUIPackageInvoker.checkOffset(offset, length, size()); |
|
1142 |
|
1143 synchronized (iToolkit) |
|
1144 { |
|
1145 NativeError.check(_delete(getToolkitHandle(), iHandle, offset, |
|
1146 length)); |
|
1147 } |
|
1148 } |
|
1149 |
|
1150 /** |
|
1151 * Returns the maximum size (number of characters) that can be stored in |
|
1152 * this <code>TextEditor</code>. |
|
1153 * |
|
1154 * @return the maximum size in characters |
|
1155 */ |
|
1156 public int getMaxSize() |
|
1157 { |
|
1158 return iMaxSize; |
|
1159 } |
|
1160 |
|
1161 /** |
|
1162 * Sets the maximum size (number of characters) that can be contained in |
|
1163 * this <code>TextEditor</code>. If the current content of the |
|
1164 * <code>TextEditor</code> is larger than the new <code>maxSize</code>, the |
|
1165 * content is truncated to fit. |
|
1166 * |
|
1167 * @param maxSize |
|
1168 * the new maximum size |
|
1169 * |
|
1170 * @return assigned maximum capacity - may be smaller than requested. |
|
1171 * |
|
1172 * @throws IllegalArgumentException |
|
1173 * if <code>maxSize</code> is zero or less. |
|
1174 * @throws IllegalArgumentException |
|
1175 * if the contents after truncation would be illegal for the |
|
1176 * current input constraints |
|
1177 */ |
|
1178 public int setMaxSize(int maxSize) |
|
1179 { |
|
1180 if (maxSize <= 0) |
|
1181 { |
|
1182 throw new IllegalArgumentException(ERROR_GIVEN_ARGUMENTS_NOT_VALID); |
|
1183 } |
|
1184 |
|
1185 int newMaxSize = 0; |
|
1186 |
|
1187 synchronized (iToolkit) |
|
1188 { |
|
1189 newMaxSize = _setMaxSize(getToolkitHandle(), iHandle, maxSize); |
|
1190 NativeError.check(newMaxSize); |
|
1191 |
|
1192 // Operation was successful, store maximum size. |
|
1193 iMaxSize = newMaxSize; |
|
1194 } |
|
1195 return newMaxSize; |
|
1196 } |
|
1197 |
|
1198 /** |
|
1199 * Gets the number of characters that are currently stored in this |
|
1200 * <code>TextEditor</code>. |
|
1201 * |
|
1202 * @return the number of characters |
|
1203 */ |
|
1204 public int size() |
|
1205 { |
|
1206 int size = 0; |
|
1207 |
|
1208 synchronized (iToolkit) |
|
1209 { |
|
1210 // Get the size from the native side. |
|
1211 size = _size(getToolkitHandle(), iHandle); |
|
1212 } |
|
1213 |
|
1214 // Check if the size was not returned correctly. |
|
1215 NativeError.check(size); |
|
1216 return size; |
|
1217 } |
|
1218 |
|
1219 /** |
|
1220 * Sets the input constraints of this <code>TextEditor</code>. If the |
|
1221 * current content of this <code>TextEditor</code> do not match the new |
|
1222 * constraints, the content is set to empty. |
|
1223 * |
|
1224 * @param constraints |
|
1225 * see <a href="TextField.html#constraints">input constraints</a> |
|
1226 * |
|
1227 * @throws IllegalArgumentException |
|
1228 * if the value of the constraints parameter is invalid |
|
1229 */ |
|
1230 public void setConstraints(int constraints) |
|
1231 { |
|
1232 // Validate constraints through TextComponentInvoker. |
|
1233 iLCDUIPackageInvoker.checkConstraints(constraints); |
|
1234 |
|
1235 synchronized (iToolkit) |
|
1236 { |
|
1237 NativeError.check(_setConstraints(getToolkitHandle(), iHandle, |
|
1238 constraints)); |
|
1239 |
|
1240 iConstraints = constraints; |
|
1241 } |
|
1242 } |
|
1243 |
|
1244 /** |
|
1245 * Gets the current input constraints of this <code>TextEditor</code>. |
|
1246 * |
|
1247 * @return the current constraints value (see <a |
|
1248 * href="TextField.html#constraints">input constraints</a>) |
|
1249 */ |
|
1250 public int getConstraints() |
|
1251 { |
|
1252 return iConstraints; |
|
1253 } |
|
1254 |
|
1255 /** |
|
1256 * <P> |
|
1257 * Sets a hint to the implementation as to the input mode that should be |
|
1258 * used when the user initiates editing of this <code>TextEditor</code>. The |
|
1259 * <code>characterSubset</code> parameter names a subset of Unicode |
|
1260 * characters that is used by the implementation to choose an initial input |
|
1261 * mode. If <code>null</code> is passed, the implementation should choose a |
|
1262 * default input mode. |
|
1263 * </P> |
|
1264 * |
|
1265 * <P> |
|
1266 * See <a href="TextField#modes">Input Modes</a> for a full explanation of |
|
1267 * input modes. |
|
1268 * </P> |
|
1269 * |
|
1270 * @param characterSubset |
|
1271 * a string naming a Unicode character subset, or |
|
1272 * <code>null</code> |
|
1273 */ |
|
1274 public void setInitialInputMode(String characterSubset) |
|
1275 { |
|
1276 synchronized (iToolkit) |
|
1277 { |
|
1278 NativeError.check(_setInitialInputMode(getToolkitHandle(), iHandle, |
|
1279 characterSubset)); |
|
1280 |
|
1281 iCharacterSubset = characterSubset; |
|
1282 } |
|
1283 } |
|
1284 |
|
1285 /** |
|
1286 * Returns the initial input mode set to the editor, or null if no initial |
|
1287 * input mode has been set. |
|
1288 * |
|
1289 * @return the initial input mode as a String, or null if no initial input |
|
1290 * mode is set. |
|
1291 * |
|
1292 * @see #setInitialInputMode(String characterSubset ) |
|
1293 */ |
|
1294 public String getInitialInputMode() |
|
1295 { |
|
1296 return iCharacterSubset; |
|
1297 } |
|
1298 |
|
1299 /** |
|
1300 * <P> |
|
1301 * Sets a selection on a range of text in the <code>TextEditor</code> |
|
1302 * content. The implementation should highlight the selection visually. A |
|
1303 * selection may be set with this method or by user interaction. If there |
|
1304 * already is a selection set, it is replaced by this new selection. |
|
1305 * </P> |
|
1306 * |
|
1307 * <P> |
|
1308 * The caret must be automatically set directly after the set selection. The |
|
1309 * Java platform implementation must scroll the content of the |
|
1310 * <code>TextEditor</code> automatically so that the caret is within the |
|
1311 * visible area and as much as possible of the selection is visible in the |
|
1312 * <code>TextEditor</code>. |
|
1313 * </P> |
|
1314 * |
|
1315 * @param index |
|
1316 * the index of the first character to be selected. |
|
1317 * @param length |
|
1318 * the length of the selection in characters, 0 length clears the |
|
1319 * selection. |
|
1320 * |
|
1321 * @throws StringIndexOutOfBoundsException |
|
1322 * if <code>index</code> and <code>length</code> do not specify |
|
1323 * a valid range within the content of the |
|
1324 * <code>TextEditor</code> |
|
1325 */ |
|
1326 public void setSelection(int index, int length) |
|
1327 { |
|
1328 iLCDUIPackageInvoker.checkOffset(index, length, size()); |
|
1329 |
|
1330 synchronized (iToolkit) |
|
1331 { |
|
1332 NativeError.check(_setSelection(getToolkitHandle(), iHandle, index, |
|
1333 length)); |
|
1334 } |
|
1335 } |
|
1336 |
|
1337 /** |
|
1338 * Gets the currently selected content in the <code>TextEditor</code>. A |
|
1339 * selection may be set with setSelection method or by user interaction. If |
|
1340 * selection is not set non-null empty string is returned. |
|
1341 * |
|
1342 * @return the currently selected content |
|
1343 */ |
|
1344 public String getSelection() |
|
1345 { |
|
1346 String selection = null; |
|
1347 int[] error = new int[1]; |
|
1348 |
|
1349 synchronized (iToolkit) |
|
1350 { |
|
1351 selection = _getSelection(getToolkitHandle(), iHandle, error); |
|
1352 } |
|
1353 |
|
1354 NativeError.check(error[0]); |
|
1355 return selection; |
|
1356 } |
|
1357 |
|
1358 /** |
|
1359 * <P> |
|
1360 * Sets a listener for content changes in this <code>TextEditor</code>, |
|
1361 * replacing any previous <code>TextEditorListener</code>. |
|
1362 * </P> |
|
1363 * |
|
1364 * <P> |
|
1365 * A <code>null</code> reference is allowed and has the effect of removing |
|
1366 * any existing <code>TextEditorListener</code> from this |
|
1367 * <code>TextEditor</code>. |
|
1368 * </P> |
|
1369 * |
|
1370 * <P> |
|
1371 * Callbacks to the TextEditorListener may throw exceptions, but they must |
|
1372 * be ignored. |
|
1373 * </P> |
|
1374 * |
|
1375 * @param listener |
|
1376 * the new listener, or <code>null</code> |
|
1377 */ |
|
1378 public void setTextEditorListener(TextEditorListener listener) |
|
1379 { |
|
1380 TextEditorListenerImpl newListener = null; |
|
1381 int listenerHandle = 0; |
|
1382 |
|
1383 // Create new listener implementation if listener has been defined. |
|
1384 if (listener != null) |
|
1385 { |
|
1386 newListener = new TextEditorListenerImpl(this, listener); |
|
1387 listenerHandle = newListener.getHandle(); |
|
1388 } |
|
1389 |
|
1390 synchronized (iToolkit) |
|
1391 { |
|
1392 NativeError.check(_setListener(getToolkitHandle(), iHandle, |
|
1393 listenerHandle)); |
|
1394 } |
|
1395 |
|
1396 iListener = newListener; |
|
1397 } |
|
1398 |
|
1399 /** |
|
1400 * Returns the multiline state of the <code>TextEditor</code>. |
|
1401 * |
|
1402 * @return the multiline state |
|
1403 */ |
|
1404 public boolean isMultiline() |
|
1405 { |
|
1406 boolean multiline = false; |
|
1407 |
|
1408 synchronized (iToolkit) |
|
1409 { |
|
1410 multiline = _isMultiline(getToolkitHandle(), iHandle); |
|
1411 } |
|
1412 |
|
1413 return multiline; |
|
1414 } |
|
1415 |
|
1416 /** |
|
1417 * Sets the editor to be either multi-line (true) or single-line (false). |
|
1418 * TextEditor is by default single-line editor, which meeans that user |
|
1419 * is not possible to insert line breaks to the editor. A possible Enter |
|
1420 * (or similar) key event should be passed in this case to the parent object |
|
1421 * as a normal key event for client to handle it as appropriately. A single-line |
|
1422 * editor will have horizontal scrolling of text if it is possible to enter text |
|
1423 * that does not fit to the editor. This may happen if maximum size is large enough |
|
1424 * for the width of the editor. |
|
1425 * In multi-line editor user is able to insert line breaks but also word |
|
1426 * wrapping is enabled automatically on word boundaries. |
|
1427 * |
|
1428 * @param aMultiline |
|
1429 * true if multi-line editor, false if single-line editor |
|
1430 * |
|
1431 * @throws IllegalStateException if a valid parent object has not been set. |
|
1432 */ |
|
1433 public void setMultiline(boolean aMultiline) |
|
1434 { |
|
1435 synchronized (iToolkit) |
|
1436 { |
|
1437 // Parent must be set |
|
1438 checkParent(); |
|
1439 |
|
1440 NativeError.check(_setMultiline(getToolkitHandle(), iHandle, |
|
1441 aMultiline)); |
|
1442 } |
|
1443 } |
|
1444 |
|
1445 /* |
|
1446 * Disposes the Landmark native peer object, if the handles are valid. |
|
1447 * Invalid (negative) handles indicate that their creation failed in the |
|
1448 * first place. |
|
1449 */ |
|
1450 final void registeredFinalize() |
|
1451 { |
|
1452 synchronized (iToolkit) |
|
1453 { |
|
1454 if (iHandle > 0) |
|
1455 { |
|
1456 _dispose(getToolkitHandle(), iHandle); |
|
1457 iHandle = 0; |
|
1458 |
|
1459 if (iParent != null) |
|
1460 { |
|
1461 // Remove from editor container. |
|
1462 iEditorContainer.removeEditor(this, iParent); |
|
1463 } |
|
1464 } |
|
1465 } |
|
1466 } |
|
1467 |
|
1468 /* |
|
1469 * Returns the native side handle to the LCDUI Toolkit. |
|
1470 * |
|
1471 * @return The native side handle to the LCDUI Toolkit. |
|
1472 */ |
|
1473 synchronized int getToolkitHandle() |
|
1474 { |
|
1475 return iToolkitInvoker.toolkitGetHandle(iToolkit); |
|
1476 } |
|
1477 |
|
1478 /* |
|
1479 * Package private default constructor. |
|
1480 */ |
|
1481 TextEditor() |
|
1482 { |
|
1483 } |
|
1484 |
|
1485 /* |
|
1486 * Package private constructor. |
|
1487 * |
|
1488 * Allocates the needed native side resources. |
|
1489 * |
|
1490 * @param aContent The content of the editor. |
|
1491 * |
|
1492 * @param maxSize The maximum Size of the editor. |
|
1493 * |
|
1494 * @param constraints The constraints of the editor. |
|
1495 * |
|
1496 * @param aWidth The width of the editor in pixels. |
|
1497 * |
|
1498 * @param aHeight The height of the editor in pixels on in rows. |
|
1499 * |
|
1500 * @param aHeighInRows If <code>true</code>, height is measured as row |
|
1501 * count. |
|
1502 * |
|
1503 * @throws IllegalArgumentException if the width or height is less than one |
|
1504 * pixel |
|
1505 */ |
|
1506 TextEditor( |
|
1507 String aContent, |
|
1508 int maxSize, |
|
1509 int constraints, |
|
1510 int aWidth, |
|
1511 int aHeight, |
|
1512 boolean aHeightInRows) |
|
1513 { |
|
1514 // Get text component invoker. |
|
1515 iLCDUIPackageInvoker = LCDUIPackageInvoker.getInvoker(); |
|
1516 // Check that the give the given text is valid. |
|
1517 checkValid(aContent, maxSize, constraints); |
|
1518 |
|
1519 // Validate width and height. |
|
1520 if (aWidth < 1 || aHeight < 1) |
|
1521 { |
|
1522 throw new IllegalArgumentException(ERROR_GIVEN_ARGUMENTS_NOT_VALID); |
|
1523 } |
|
1524 |
|
1525 // Toolkit invoker is needed for accessing javax.microedition.lcdui |
|
1526 // package |
|
1527 iToolkitInvoker = ToolkitInvoker.getToolkitInvoker(); |
|
1528 iToolkit = iToolkitInvoker.getToolkit(); |
|
1529 |
|
1530 int handle = 0; |
|
1531 |
|
1532 // The size of the editor must be known after construction. Use return |
|
1533 // values to store the height and width of the editor after |
|
1534 // construction. |
|
1535 int[] size = new int[2]; |
|
1536 |
|
1537 synchronized (iToolkit) |
|
1538 { |
|
1539 // Create native peer object for this Java object. |
|
1540 handle = |
|
1541 _createNativePeer(getToolkitHandle(), maxSize, aWidth, aHeight, |
|
1542 aHeightInRows, size); |
|
1543 } |
|
1544 |
|
1545 // Check if construction failed and throw out of memory error. |
|
1546 if (handle <= NativeError.KErrNone) |
|
1547 { |
|
1548 throw new OutOfMemoryError(); |
|
1549 } |
|
1550 |
|
1551 // Operation was a success, store size. |
|
1552 iWidth = size[0]; |
|
1553 iHeight = size[1]; |
|
1554 iMaxSize = maxSize; |
|
1555 |
|
1556 // Enabling receiving pointer events |
|
1557 iTouchEnabled = true; |
|
1558 |
|
1559 // Sets parent to null |
|
1560 iParent = null; |
|
1561 |
|
1562 // Construction was successful. Store handle and register for |
|
1563 // finalization. |
|
1564 iHandle = handle; |
|
1565 mFinalizer = new Finalizer() |
|
1566 { |
|
1567 public void finalizeImpl() |
|
1568 { |
|
1569 registeredFinalize(); |
|
1570 } |
|
1571 }; |
|
1572 |
|
1573 // Set the constraints of the editor. The content is now empty. |
|
1574 setConstraints(constraints); |
|
1575 |
|
1576 // Set font to Java default font. |
|
1577 setFont(Font.getDefaultFont()); |
|
1578 |
|
1579 // Set the text. This now throws an exception if the content is not |
|
1580 // valid for the current set of constraints. |
|
1581 setContent(aContent); |
|
1582 } |
|
1583 |
|
1584 // Private methods. |
|
1585 |
|
1586 /* |
|
1587 * Checks that the given arguments are valid. |
|
1588 * |
|
1589 * @param text The text to check. |
|
1590 * |
|
1591 * @param maxSize The maximum size to check. |
|
1592 * |
|
1593 * @param constraints The constraints to check. |
|
1594 * |
|
1595 * @throws java.lang.IllegalArgumentException if the arguments are not |
|
1596 * valid. |
|
1597 */ |
|
1598 private void checkValid(String text, int maxSize, int constraints) |
|
1599 { |
|
1600 try |
|
1601 { |
|
1602 iLCDUIPackageInvoker.checkText(text, maxSize); |
|
1603 iLCDUIPackageInvoker.checkConstraints(constraints); |
|
1604 } |
|
1605 catch (IllegalArgumentException e) |
|
1606 { |
|
1607 throw new IllegalArgumentException(ERROR_GIVEN_ARGUMENTS_NOT_VALID); |
|
1608 } |
|
1609 } |
|
1610 |
|
1611 /* |
|
1612 * Sets the specified color for the specified color type. |
|
1613 * |
|
1614 * @param alpha the alpha component of the color being set within range |
|
1615 * <code>0-255</code> |
|
1616 * |
|
1617 * @param red the red component of the color being set within range |
|
1618 * <code>0-255</code> |
|
1619 * |
|
1620 * @param green the green component of the color being set within range |
|
1621 * <code>0-255</code> |
|
1622 * |
|
1623 * @param blue the blue component of the color being set within range |
|
1624 * <code>0-255</code> |
|
1625 * |
|
1626 * @param aColorType the type of the color to be set. |
|
1627 * |
|
1628 * @throws IllegalArgumentException if any of the parameters is outside the |
|
1629 * range of <code>0-255</code> |
|
1630 */ |
|
1631 private void doSetColor( |
|
1632 int alpha, |
|
1633 int red, |
|
1634 int green, |
|
1635 int blue, |
|
1636 int aColorType) |
|
1637 { |
|
1638 if ((alpha < 0 || alpha > COLOR_MAX_VALUE) |
|
1639 || (red < 0 || red > COLOR_MAX_VALUE) |
|
1640 || (green < 0 || green > COLOR_MAX_VALUE) |
|
1641 || (blue < 0 || blue > COLOR_MAX_VALUE)) |
|
1642 { |
|
1643 throw new IllegalArgumentException(ERROR_GIVEN_ARGUMENTS_NOT_VALID); |
|
1644 } |
|
1645 |
|
1646 int[] color = new int[] { red, green, blue, alpha }; |
|
1647 |
|
1648 synchronized (iToolkit) |
|
1649 { |
|
1650 NativeError.check(_setColor(getToolkitHandle(), iHandle, color, |
|
1651 aColorType)); |
|
1652 } |
|
1653 } |
|
1654 |
|
1655 // Native methods |
|
1656 |
|
1657 /* |
|
1658 * Creates the native side peer object for this TextEditor. |
|
1659 * |
|
1660 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
1661 * |
|
1662 * @param maxSize The maximum size of the content in the text editor. |
|
1663 * |
|
1664 * @param aWidth The new width of this text editor. |
|
1665 * |
|
1666 * @param aHeight The new hight of this text editor. |
|
1667 * |
|
1668 * @param aHeightInRows If <code>true</code> height is measured in rows. |
|
1669 * |
|
1670 * @param aSize On return, contains the size of the editor as width and |
|
1671 * height. |
|
1672 * |
|
1673 * @return A handle to the the native side peer object or a system-wide |
|
1674 * error code. |
|
1675 */ |
|
1676 private native int _createNativePeer( |
|
1677 int aToolkitHandle, |
|
1678 int maxSize, |
|
1679 int aWidth, |
|
1680 int aHeight, |
|
1681 boolean aHeightInRows, |
|
1682 int[] aSize); |
|
1683 |
|
1684 /* |
|
1685 * Disposes the native side peer object. |
|
1686 * |
|
1687 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
1688 * |
|
1689 * @param aNativePeerHandle A handle to the native side peer object. |
|
1690 */ |
|
1691 private native void _dispose(int aToolkitHandle, int aNativePeerHandle); |
|
1692 |
|
1693 /* |
|
1694 * Sets the size of this text editor using the given width and height. |
|
1695 * |
|
1696 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
1697 * |
|
1698 * @param aNativePeerHandle A handle to the native side peer object. |
|
1699 * |
|
1700 * @param aWidth The new width of this text editor. |
|
1701 * |
|
1702 * @param aHeight The new hight of this text editor. |
|
1703 * |
|
1704 * @return NativeError.KErrNone if the operation was successful. Otherwise, |
|
1705 * a system-wide error code is returned. |
|
1706 */ |
|
1707 private native int _setSize( |
|
1708 int aToolkitHandle, |
|
1709 int aNativePeerHandle, |
|
1710 int aWidth, |
|
1711 int aHeight); |
|
1712 |
|
1713 /* |
|
1714 * Disposes the native side peer object. |
|
1715 * |
|
1716 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
1717 * |
|
1718 * @param aNativePeerHandle A handle to the native side peer object. |
|
1719 * |
|
1720 * @param aParentHandle A handle to the parent object. |
|
1721 * |
|
1722 * @return NativeError.KErrNone if the operation was successful. Otherwise, |
|
1723 * a system-wide error code is returned. |
|
1724 */ |
|
1725 private native int _setParent( |
|
1726 int aToolkitHandle, |
|
1727 int aNativePeerHandle, |
|
1728 int aParentHandle); |
|
1729 |
|
1730 /* |
|
1731 * Sets the focus state of text editor. |
|
1732 * |
|
1733 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
1734 * |
|
1735 * @param aNativePeerHandle A handle to the native side peer object. |
|
1736 * |
|
1737 * @param aFocused Indicates whether the text editor should be focused or |
|
1738 * not. |
|
1739 * |
|
1740 * @return NativeError.KErrNone if the operation was successful. Otherwise, |
|
1741 * a system-wide error code is returned. |
|
1742 */ |
|
1743 private native int _setFocusState( |
|
1744 int aToolkitHandle, |
|
1745 int aNativePeerHandle, |
|
1746 boolean aFocusState); |
|
1747 |
|
1748 /* |
|
1749 * Gets focus state of the text editor. |
|
1750 * |
|
1751 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
1752 * |
|
1753 * @param aNativePeerHandle A handle to the native side peer object. |
|
1754 * |
|
1755 * @param aFocused Indicates whether the text editor should be focused or |
|
1756 * not. |
|
1757 * |
|
1758 * @return focus state. |
|
1759 */ |
|
1760 private native boolean _getFocusState(int aToolkitHandle, |
|
1761 int aNativePeerHandle); |
|
1762 |
|
1763 /* |
|
1764 * Gets the multiline setting of TextEditor. |
|
1765 * |
|
1766 * @return the multiline state. |
|
1767 */ |
|
1768 private native boolean _isMultiline(int aToolkitHandle, |
|
1769 int aNativePeerHandle); |
|
1770 |
|
1771 /* |
|
1772 * Sets the text editor visible. |
|
1773 * |
|
1774 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
1775 * |
|
1776 * @param aNativePeerHandle A handle to the native side peer object. |
|
1777 * |
|
1778 * @param aVisible The visibility status of this text editor. |
|
1779 * |
|
1780 * @return NativeError.KErrNone if the operation was successful. Otherwise, |
|
1781 * a system-wide error code is returned. |
|
1782 */ |
|
1783 private native int _setVisible( |
|
1784 int aToolkitHandle, |
|
1785 int aNativePeerHandle, |
|
1786 boolean aVisible); |
|
1787 |
|
1788 /* |
|
1789 * Sets the text editor's position. |
|
1790 * |
|
1791 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
1792 * |
|
1793 * @param aNativePeerHandle A handle to the native side peer object. |
|
1794 * |
|
1795 * @param aX The x coordinate of the anchor point. |
|
1796 * |
|
1797 * @param aY The y coordinate of the anchor point. |
|
1798 * |
|
1799 * @return NativeError.KErrNone if the operation was successful. Otherwise, |
|
1800 * a system-wide error code is returned. |
|
1801 */ |
|
1802 private native int _setPosition( |
|
1803 int aToolkitHandle, |
|
1804 int aNativePeerHandle, |
|
1805 int aX, |
|
1806 int aY); |
|
1807 |
|
1808 /* |
|
1809 * Sets the text input constraints of this text editor. |
|
1810 * |
|
1811 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
1812 * |
|
1813 * @param aNativePeerHandle A handle to the native side peer object. |
|
1814 * |
|
1815 * @param constraints The new constraints for the editor. |
|
1816 * |
|
1817 * @return NativeError.KErrNone if the operation was successful. Otherwise, |
|
1818 * a system-wide error code is returned. |
|
1819 */ |
|
1820 private native int _setConstraints( |
|
1821 int aToolkitHandle, |
|
1822 int aNativePeerHandle, |
|
1823 int constraints); |
|
1824 |
|
1825 /* |
|
1826 * Sets the editor to be either multi-line (true) or single-line (false). |
|
1827 * |
|
1828 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
1829 * |
|
1830 * @param aNativePeerHandle A handle to the native side peer object. |
|
1831 * |
|
1832 * @param aMultiline True if multi-line editor, false if single-line editor. |
|
1833 * |
|
1834 * @return NativeError.KErrNone if the operation was successful. Otherwise, |
|
1835 * a system-wide error code is returned. |
|
1836 */ |
|
1837 private native int _setMultiline( |
|
1838 int aToolkitHandle, |
|
1839 int aNativePeerHandle, |
|
1840 boolean aMultiline); |
|
1841 |
|
1842 /* |
|
1843 * Sets the initial input mode of this text editor. |
|
1844 * |
|
1845 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
1846 * |
|
1847 * @param aNativePeerHandle A handle to the native side peer object. |
|
1848 * |
|
1849 * @param characterSubset The character subset. |
|
1850 * |
|
1851 * @return NativeError.KErrNone if the operation was successful. Otherwise, |
|
1852 * a system-wide error code is returned. |
|
1853 */ |
|
1854 private native int _setInitialInputMode( |
|
1855 int aToolkitHandle, |
|
1856 int aNativePeerHandle, |
|
1857 String characterSubset); |
|
1858 |
|
1859 /* |
|
1860 * Deletes the content in the text editor. |
|
1861 * |
|
1862 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
1863 * |
|
1864 * @param aNativePeerHandle A handle to the native side peer object. |
|
1865 * |
|
1866 * @param offset The beginning of the range to be deleted. |
|
1867 * |
|
1868 * @param length The lenght of the range to be deleted. |
|
1869 * |
|
1870 * @return NativeError.KErrNone if the operation was successful. Otherwise, |
|
1871 * a system-wide error code is returned. |
|
1872 */ |
|
1873 private native int _delete( |
|
1874 int aToolkitHandle, |
|
1875 int aNativePeerHandle, |
|
1876 int offset, |
|
1877 int length); |
|
1878 |
|
1879 /* |
|
1880 * Returns the number of characters in the text editor. |
|
1881 * |
|
1882 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
1883 * |
|
1884 * @param aNativePeerHandle A handle to the native side peer object. |
|
1885 * |
|
1886 * @param The number of characters in the text editor or a system-wide error |
|
1887 * code if the operation failed. |
|
1888 */ |
|
1889 private native int _size(int aToolkitHandle, int aNativePeerHandle); |
|
1890 |
|
1891 /* |
|
1892 * Returns the line margin height in the text editor. |
|
1893 * |
|
1894 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
1895 * |
|
1896 * @param aNativePeerHandle A handle to the native side peer object. |
|
1897 * |
|
1898 * @return The line margin height in the text editor or a system-wide error |
|
1899 * code if the operation failed. |
|
1900 */ |
|
1901 private native int _getLineMarginHeight( |
|
1902 int aToolkitHandle, |
|
1903 int aNativePeerHandle); |
|
1904 |
|
1905 /* |
|
1906 * Returns the number of characters in the text editor. |
|
1907 * |
|
1908 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
1909 * |
|
1910 * @param aNativePeerHandle A handle to the native side peer object. |
|
1911 * |
|
1912 * @return The full content hight in the text editor or a system-wide error |
|
1913 * code if the operation failed. |
|
1914 */ |
|
1915 private native int _getContentHeight( |
|
1916 int aToolkitHandle, |
|
1917 int aNativePeerHandle); |
|
1918 |
|
1919 /* |
|
1920 * Sets the content of this text editor. |
|
1921 * |
|
1922 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
1923 * |
|
1924 * @param aNativePeerHandle A handle to the native side peer object. |
|
1925 * |
|
1926 * @param aContent The new content of this text editor. |
|
1927 * |
|
1928 * @return NativeError.KErrNone if the operation was successful. Otherwise, |
|
1929 * a system-wide error code is returned. |
|
1930 */ |
|
1931 private native int _setContent( |
|
1932 int aToolkitHandle, |
|
1933 int aNativePeerHandle, |
|
1934 String aContent); |
|
1935 |
|
1936 /* |
|
1937 * Inserts content to this text editor. |
|
1938 * |
|
1939 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
1940 * |
|
1941 * @param aNativePeerHandle A handle to the native side peer object. |
|
1942 * |
|
1943 * @param aContent The content to be inserted to this text editor. |
|
1944 * |
|
1945 * @param position The position to which the content should be inserted. |
|
1946 * |
|
1947 * @return NativeError.KErrNone if the operation was successful. Otherwise, |
|
1948 * a system-wide error code is returned. |
|
1949 */ |
|
1950 private native int _insert( |
|
1951 int aToolkitHandle, |
|
1952 int aNativePeerHandle, |
|
1953 String aContent, |
|
1954 int position); |
|
1955 |
|
1956 /* |
|
1957 * Gets the content of this text editor. |
|
1958 * |
|
1959 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
1960 * |
|
1961 * @param aNativePeerHandle A handle to the native side peer object. |
|
1962 * |
|
1963 * @param aError On return contains the error code for the operation. |
|
1964 * |
|
1965 * @return The content of the editor as a string. |
|
1966 */ |
|
1967 private native String _getContent( |
|
1968 int aToolkitHandle, |
|
1969 int aNativePeerHandle, |
|
1970 int[] aError); |
|
1971 |
|
1972 /* |
|
1973 * Sets the maximum size of this text editor. |
|
1974 * |
|
1975 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
1976 * |
|
1977 * @param aNativePeerHandle A handle to the native side peer object. |
|
1978 * |
|
1979 * @param maxSize The new maximum size of this text editor. |
|
1980 * |
|
1981 * @return The maximum size of the editor if the operation was successful. |
|
1982 * Otherwise, a system-wide error code is returned. |
|
1983 */ |
|
1984 private native int _setMaxSize( |
|
1985 int aToolkitHandle, |
|
1986 int aNativePeerHandle, |
|
1987 int maxSize); |
|
1988 |
|
1989 /* |
|
1990 * Returns the current position of the caret in the text editor. |
|
1991 * |
|
1992 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
1993 * |
|
1994 * @param aNativePeerHandle A handle to the native side peer object. |
|
1995 * |
|
1996 * @param The current position of the caret or a system-wide error code if |
|
1997 * the operation failed. |
|
1998 */ |
|
1999 private native int _getCaretPosition( |
|
2000 int aToolkitHandle, |
|
2001 int aNativePeerHandle); |
|
2002 |
|
2003 /* |
|
2004 * Returns the topmost pixel's position of the visible content. |
|
2005 * |
|
2006 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
2007 * |
|
2008 * @param aNativePeerHandle A handle to the native side peer object. |
|
2009 * |
|
2010 * @param The topmost pixel's position of the visible content or a |
|
2011 * system-wide error code if the operation failed. |
|
2012 */ |
|
2013 private native int _getVisibleContentPosition( |
|
2014 int aToolkitHandle, |
|
2015 int aNativePeerHandle); |
|
2016 |
|
2017 /* |
|
2018 * Sets a new position for the caret in the text editor. |
|
2019 * |
|
2020 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
2021 * |
|
2022 * @param aNativePeerHandle A handle to the native side peer object. |
|
2023 * |
|
2024 * @param index The new position of the caret. |
|
2025 * |
|
2026 * @return NativeError.KErrNone if the operation was successful. Otherwise, |
|
2027 * a system-wide error code is returned. |
|
2028 */ |
|
2029 private native int _setCaret( |
|
2030 int aToolkitHandle, |
|
2031 int aNativePeerHandle, |
|
2032 int index); |
|
2033 |
|
2034 /* |
|
2035 * Sets a new color for the specified color type in the text editor. |
|
2036 * |
|
2037 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
2038 * |
|
2039 * @param aNativePeerHandle A handle to the native side peer object. |
|
2040 * |
|
2041 * @param aColor An array containing new color value (r,g,b,a). |
|
2042 * |
|
2043 * @param aColorType Type of color to set. |
|
2044 * |
|
2045 * @return NativeError.KErrNone if the operation was successful. Otherwise, |
|
2046 * a system-wide error code is returned. |
|
2047 */ |
|
2048 private native int _setColor( |
|
2049 int aToolkitHandle, |
|
2050 int aNativePeerHandle, |
|
2051 int[] aColor, |
|
2052 int aColorType); |
|
2053 |
|
2054 /* |
|
2055 * Gets a color of the specified color type from the text editor. |
|
2056 * |
|
2057 * |
|
2058 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
2059 * |
|
2060 * @param aNativePeerHandle A handle to the native side peer object. |
|
2061 * |
|
2062 * @param aColorType Type of color to set. |
|
2063 * |
|
2064 * @return color in RGBA |
|
2065 */ |
|
2066 private native int _getColor( |
|
2067 int aToolkitHandle, |
|
2068 int aNativePeerHandle, |
|
2069 int aColorType); |
|
2070 |
|
2071 /* |
|
2072 * Selects the specified range of text in the text editor. |
|
2073 * |
|
2074 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
2075 * |
|
2076 * @param aNativePeerHandle A handle to the native side peer object. |
|
2077 * |
|
2078 * @param index The beginning of the range to be selected. |
|
2079 * |
|
2080 * @param length The lenght of the range to be selected. |
|
2081 * |
|
2082 * @return NativeError.KErrNone if the operation was successful. Otherwise, |
|
2083 * a system-wide error code is returned. |
|
2084 */ |
|
2085 private native int _setSelection( |
|
2086 int aToolkitHandle, |
|
2087 int aNativePeerHandle, |
|
2088 int index, |
|
2089 int length); |
|
2090 |
|
2091 /* |
|
2092 * Gets the current selection of this text editor. |
|
2093 * |
|
2094 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
2095 * |
|
2096 * @param aNativePeerHandle A handle to the native side peer object. |
|
2097 * |
|
2098 * @param aError On return contains the error code for the operation. |
|
2099 * |
|
2100 * @return The selected content of the editor as a string. |
|
2101 */ |
|
2102 private native String _getSelection( |
|
2103 int aToolkitHandle, |
|
2104 int aNativePeerHandle, |
|
2105 int[] aError); |
|
2106 |
|
2107 /* |
|
2108 * Sets the specified font for the text editor. |
|
2109 * |
|
2110 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
2111 * |
|
2112 * @param aNativePeerHandle A handle to the native side peer object. |
|
2113 * |
|
2114 * @param aFont The application preferred font to be used in this |
|
2115 * TextEditor. |
|
2116 * |
|
2117 * @param aNewSize On return, contains the new size of the editor. |
|
2118 * |
|
2119 * @return NativeError.KErrNone if the operation was successful. Otherwise, |
|
2120 * a system-wide error code is returned. |
|
2121 */ |
|
2122 private native int _setFont( |
|
2123 int aToolkitHandle, |
|
2124 int aNativePeerHandle, |
|
2125 int aFont, |
|
2126 int[] aNewSize); |
|
2127 |
|
2128 /* |
|
2129 * Sets a listener for this text editor. |
|
2130 * |
|
2131 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
2132 * |
|
2133 * @param aNativePeerHandle A handle to the native side peer object. |
|
2134 * |
|
2135 * @param listenerHandle A handle to the listener. |
|
2136 * |
|
2137 * @return NativeError.KErrNone if the operation was successful. Otherwise, |
|
2138 * a system-wide error code is returned. |
|
2139 */ |
|
2140 private native int _setListener( |
|
2141 int aToolkitHandle, |
|
2142 int aNativePeerHandle, |
|
2143 int listenerHandle); |
|
2144 |
|
2145 /* |
|
2146 * Sets the elevation of this text editor. |
|
2147 * |
|
2148 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
2149 * |
|
2150 * @param aNativePeerHandle A handle to the native side peer object. |
|
2151 * |
|
2152 * @param aZ The new z-position. |
|
2153 * |
|
2154 * @return NativeError.KErrNone if the operation was successful. Otherwise, |
|
2155 * a system-wide error code is returned. |
|
2156 */ |
|
2157 private native int _setZPosition( |
|
2158 int aToolkitHandle, |
|
2159 int aNativePeerHandle, |
|
2160 int aZ); |
|
2161 |
|
2162 /* |
|
2163 * Gets the elevation of this text editor. |
|
2164 * |
|
2165 * @param aToolkitHandle A handle to the LCDUI toolkit. |
|
2166 * |
|
2167 * @param aNativePeerHandle A handle to the native side peer object. |
|
2168 * |
|
2169 * @return The elevation if the operation was successful. Otherwise, a |
|
2170 * system-wide error code is returned. |
|
2171 */ |
|
2172 private native int _getZPosition(int aToolkitHandle, int aNativePeerHandle); |
|
2173 |
|
2174 /* |
|
2175 * Specifies whether or not the editor will receive touch-events. |
|
2176 * |
|
2177 * This is enabled by default. |
|
2178 * An editor with touch-event disabled won't be able to perform any |
|
2179 * touch-related functionality such as scrolling or positioning the |
|
2180 * cursor. It may however still be controlled via the |
|
2181 * virtual keypad/control-panel if that is enabled, or receive other + |
|
2182 * input e.g. via physical keys |
|
2183 * |
|
2184 * @param aEnabled |
|
2185 * true to enabled touch-event, false to disable |
|
2186 */ |
|
2187 private native int _setTouchEnabled(int aToolkitHandle, |
|
2188 int aNativePeerHandle, boolean aEnabled); |
|
2189 |
|
2190 } |
|
2191 |
|
2192 // End of file |