66
|
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: JNI implementation of TextEditor class
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INTERNAL INCLUDES
|
|
20 |
#include "com_nokia_mid_ui_TextEditor.h"
|
|
21 |
#include "CMIDCanvas.h" // userinclude in nokialcdui.component
|
|
22 |
|
|
23 |
// EXTERNAL INCLUDES
|
|
24 |
#include <MMIDTextEditor.h>
|
|
25 |
#include <CMIDToolkit.h>
|
|
26 |
#include <jutils.h>
|
|
27 |
#include <jdebug.h>
|
|
28 |
|
|
29 |
// UNNAMED LOCAL NAMESPACE
|
|
30 |
namespace
|
|
31 |
{
|
|
32 |
// The number of colors (r,g,b,a)
|
|
33 |
const TInt KNumColors = 4;
|
|
34 |
const TInt KColorIndexRed = 0;
|
|
35 |
const TInt KColorIndexGreen = 1;
|
|
36 |
const TInt KColorIndexBlue = 2;
|
|
37 |
const TInt KColorIndexAlpha = 3;
|
|
38 |
}
|
|
39 |
|
|
40 |
/**
|
|
41 |
* Local helper method for handling native strings and converting them to
|
|
42 |
* Java strings.
|
|
43 |
*
|
|
44 |
* Error is set also in this method.
|
|
45 |
*
|
|
46 |
* @param aJniEnv A valid reference JNI environment.
|
|
47 |
* @param aText The native descriptor to be converted.
|
|
48 |
* @param aError The return value from ExecuteTrap.
|
|
49 |
* @param aReturnError On return, contains an error code.
|
|
50 |
* @return The converted Java string of NULL if the conversion failed.
|
|
51 |
*/
|
|
52 |
LOCAL_C jstring HandleString(
|
|
53 |
JNIEnv& aJniEnv,
|
|
54 |
const TDesC& aText,
|
|
55 |
TInt aError,
|
|
56 |
jintArray aReturnError)
|
|
57 |
{
|
|
58 |
DEBUG("TextEditor.cpp - HandleString +");
|
|
59 |
|
|
60 |
jstring javaText = NULL;
|
|
61 |
|
|
62 |
// Create Java string if the operation was successful.
|
|
63 |
if (aError == KErrNone)
|
|
64 |
{
|
|
65 |
javaText = CreateJavaString(aJniEnv, aText);
|
|
66 |
|
|
67 |
// If NULL is returned, it indicates that the creation failed.
|
|
68 |
if (!javaText)
|
|
69 |
{
|
|
70 |
aError = KErrNoMemory;
|
|
71 |
}
|
|
72 |
}
|
|
73 |
|
|
74 |
jint errorArray[ 1 ] = { aError };
|
|
75 |
aJniEnv.SetIntArrayRegion(aReturnError, 0, 1, errorArray);
|
|
76 |
|
|
77 |
DEBUG_INT("TextEditor.cpp - HandleString -, aError=%d", aError);
|
|
78 |
|
|
79 |
return javaText;
|
|
80 |
}
|
|
81 |
|
|
82 |
/**
|
|
83 |
* Local helper function for creating the native side peer object for
|
|
84 |
* TextEditor.
|
|
85 |
*
|
|
86 |
* @param aNativePeerHandle On return, contains the native peer's handle
|
|
87 |
*/
|
|
88 |
LOCAL_C void CreateNativePeerL(
|
|
89 |
CMIDToolkit* aToolkit,
|
|
90 |
jobject aPeer,
|
|
91 |
TInt* aNativePeerHandle,
|
|
92 |
TInt aMaxSize,
|
|
93 |
TInt aWidth,
|
|
94 |
TInt aHeight,
|
|
95 |
TBool aHeightInRows)
|
|
96 |
{
|
|
97 |
// Get LCDUI component factory.
|
|
98 |
MMIDComponentFactory* factory = aToolkit->ComponentFactory();
|
|
99 |
|
|
100 |
// Create new text editor component.
|
|
101 |
MMIDTextEditor* textEditor = factory->CreateTextEditorL(
|
|
102 |
aMaxSize, aWidth, aHeight, aHeightInRows);
|
|
103 |
|
|
104 |
// Put the component to cleanup stack during the register operation.
|
|
105 |
CleanupDisposePushL(textEditor);
|
|
106 |
|
|
107 |
// Register component to the LCDUI.
|
|
108 |
*aNativePeerHandle = aToolkit->RegisterComponentL(textEditor, aPeer);
|
|
109 |
|
|
110 |
// Component can be popped from the cleanup stack.
|
|
111 |
CleanupPopComponent(textEditor);
|
|
112 |
}
|
|
113 |
|
|
114 |
/*
|
|
115 |
* Class: com_nokia_mid_ui_TextEditor
|
|
116 |
* Method: _createNativePeer
|
|
117 |
* Signature: (I)I
|
|
118 |
*/
|
|
119 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1createNativePeer(
|
|
120 |
JNIEnv* aJniEnv,
|
|
121 |
jobject aPeer,
|
|
122 |
jint aToolkitHandle,
|
|
123 |
jint aMaxSize,
|
|
124 |
jint aWidth,
|
|
125 |
jint aHeight,
|
|
126 |
jboolean aHeightInRows)
|
|
127 |
{
|
|
128 |
DEBUG("TextEditor.cpp - createNativePeer +");
|
|
129 |
|
|
130 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
131 |
|
|
132 |
jobject peer = aJniEnv->NewWeakGlobalRef(aPeer);
|
|
133 |
TInt handle = -1;
|
|
134 |
|
|
135 |
TInt error = toolkit->ExecuteTrap(
|
|
136 |
&CreateNativePeerL,
|
|
137 |
toolkit,
|
|
138 |
peer,
|
|
139 |
&handle,
|
|
140 |
aMaxSize,
|
|
141 |
aWidth,
|
|
142 |
aHeight,
|
|
143 |
(TBool)aHeightInRows);
|
|
144 |
|
|
145 |
if (error != KErrNone)
|
|
146 |
{
|
|
147 |
// Global reference must be removed at this point if construction
|
|
148 |
// failed for some reason.
|
|
149 |
aJniEnv->DeleteWeakGlobalRef(static_cast< jweak >(peer));
|
|
150 |
}
|
|
151 |
|
|
152 |
DEBUG_INT("TextEditor.cpp - createNativePeer, error = %d", error);
|
|
153 |
|
|
154 |
return (error != KErrNone ? error : handle);
|
|
155 |
}
|
|
156 |
|
|
157 |
/**
|
|
158 |
* Local helper function for setting the multiline status of text editor
|
|
159 |
*
|
|
160 |
* @param aTextEditor The text editor object to be modified.
|
|
161 |
* @param aMultiline The multiline status of the text editor to be set.
|
|
162 |
*/
|
|
163 |
LOCAL_C void SetMultilineL(
|
|
164 |
MMIDTextEditor* aTextEditor,
|
|
165 |
TBool aMultiline)
|
|
166 |
{
|
|
167 |
aTextEditor->SetMultilineL(aMultiline);
|
|
168 |
}
|
|
169 |
|
|
170 |
/*
|
|
171 |
* Class: com_nokia_mid_ui_TextEditor
|
|
172 |
* Method: _setMultiline
|
|
173 |
* Signature: (IIZ)I
|
|
174 |
*/
|
|
175 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1setMultiline(
|
|
176 |
JNIEnv* /*aJniEnv*/,
|
|
177 |
jobject /*aPeer*/,
|
|
178 |
jint aToolkitHandle,
|
|
179 |
jint aNativePeerHandle,
|
|
180 |
jboolean aMultiline)
|
|
181 |
{
|
|
182 |
DEBUG("TextEditor.cpp - setMultiline +");
|
|
183 |
|
|
184 |
CMIDToolkit* toolkit =
|
|
185 |
JavaUnhand<CMIDToolkit>(aToolkitHandle);
|
|
186 |
MMIDTextEditor* editor =
|
|
187 |
MIDUnhandObject<MMIDTextEditor>(aNativePeerHandle);
|
|
188 |
|
|
189 |
TInt error = toolkit->ExecuteTrap(&SetMultilineL, editor,
|
|
190 |
(TBool)aMultiline);
|
|
191 |
|
|
192 |
DEBUG_INT("TextEditor.cpp - setMultiline -, error=%d", error);
|
|
193 |
|
|
194 |
return error;
|
|
195 |
}
|
|
196 |
|
|
197 |
/**
|
|
198 |
* Local helper function for getting of multiline state of a text editor
|
|
199 |
*
|
|
200 |
* @param aTextEditor The text editor object to be modified.
|
|
201 |
* @return The multiline state of the text editor.
|
|
202 |
*/
|
|
203 |
LOCAL_C TBool IsMultiline(MMIDTextEditor* aTextEditor)
|
|
204 |
{
|
|
205 |
return aTextEditor->IsMultiline();
|
|
206 |
}
|
|
207 |
|
|
208 |
/*
|
|
209 |
* Class: com_nokia_mid_ui_TextEditor
|
|
210 |
* Method: _isMultiline
|
|
211 |
* Signature: (IIZ)I
|
|
212 |
*/
|
|
213 |
JNIEXPORT jboolean JNICALL Java_com_nokia_mid_ui_TextEditor__1isMultiline(
|
|
214 |
JNIEnv* /* aJniEnv */,
|
|
215 |
jobject /* aPeer */,
|
|
216 |
jint aToolkitHandle,
|
|
217 |
jint aNativePeerHandle)
|
|
218 |
{
|
|
219 |
DEBUG("TextEditor.cpp - isMultiline +");
|
|
220 |
|
|
221 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
222 |
|
|
223 |
MMIDTextEditor* editor =
|
|
224 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
225 |
|
|
226 |
TBool multiline = toolkit->Execute(&IsMultiline, editor);
|
|
227 |
|
|
228 |
DEBUG_INT("TextEditor.cpp - isMultiline -, multiline=%d", multiline);
|
|
229 |
|
|
230 |
return multiline;
|
|
231 |
}
|
|
232 |
|
|
233 |
/**
|
|
234 |
* Local helper function for setting the size of a text editor
|
|
235 |
*
|
|
236 |
* @param aTextEditor The text editor object to be modified.
|
|
237 |
* @param aWidth The width of the editor.
|
|
238 |
* @param aHeight The height of the editor.
|
|
239 |
* @param aHeightInRows Indicates if the height is presented in rows.
|
|
240 |
*/
|
|
241 |
LOCAL_C void SetSize(
|
|
242 |
MMIDTextEditor* aTextEditor,
|
|
243 |
TInt aWidth,
|
|
244 |
TInt aHeight)
|
|
245 |
{
|
|
246 |
aTextEditor->SetEditorSize(aWidth, aHeight);
|
|
247 |
}
|
|
248 |
|
|
249 |
/*
|
|
250 |
* Class: com_nokia_mid_ui_TextEditor
|
|
251 |
* Method: _setSize
|
|
252 |
* Signature: (IIII)I
|
|
253 |
*/
|
|
254 |
JNIEXPORT int JNICALL Java_com_nokia_mid_ui_TextEditor__1setSize(
|
|
255 |
JNIEnv* /*aJniEnv*/,
|
|
256 |
jobject /* aPeer */,
|
|
257 |
jint aToolkitHandle,
|
|
258 |
jint aNativePeerHandle,
|
|
259 |
jint aWidth,
|
|
260 |
jint aHeight)
|
|
261 |
{
|
|
262 |
DEBUG("TextEditor.cpp - setSize +");
|
|
263 |
|
|
264 |
CMIDToolkit* toolkit =
|
|
265 |
JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
266 |
MMIDTextEditor* editor =
|
|
267 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
268 |
|
|
269 |
toolkit->ExecuteV(
|
|
270 |
&SetSize,
|
|
271 |
editor,
|
|
272 |
aWidth,
|
|
273 |
aHeight);
|
|
274 |
|
|
275 |
DEBUG("TextEditor.cpp - setSize -");
|
|
276 |
|
|
277 |
return KErrNone;
|
|
278 |
}
|
|
279 |
|
|
280 |
/**
|
|
281 |
* Local helper function for setting the parent of a text editor
|
|
282 |
*
|
|
283 |
* @param aTextEditor The text editor object to be modified.
|
|
284 |
* @param aParent The parent to be set.
|
|
285 |
*/
|
|
286 |
LOCAL_C void SetParentL(MMIDTextEditor* aTextEditor, MMIDComponent* aParent)
|
|
287 |
{
|
|
288 |
MMIDCustomComponentContainer* container = NULL;
|
|
289 |
MDirectContainer* directContainer = NULL;
|
|
290 |
|
|
291 |
if (aParent)
|
|
292 |
{
|
|
293 |
MMIDComponent::TType type(aParent->Type());
|
|
294 |
|
|
295 |
__ASSERT_DEBUG(type == MMIDComponent::ECanvas ||
|
|
296 |
type == MMIDComponent::ECustomItem,
|
|
297 |
User::Invariant());
|
|
298 |
|
|
299 |
// Use static cast instead of reinterpret_cast because
|
|
300 |
// reinterpret_cast does not preform the conversion correctly.
|
|
301 |
// static_cast is OK eventhough CMIDCanvas is non-sharable class.
|
|
302 |
// We don't use its methods.
|
|
303 |
container = static_cast< CMIDCanvas* >(aParent);
|
|
304 |
directContainer = static_cast< CMIDCanvas* >(aParent);
|
|
305 |
}
|
|
306 |
|
|
307 |
aTextEditor->SetParentL(container);
|
|
308 |
aTextEditor->SetDirectContainerL(directContainer);
|
|
309 |
}
|
|
310 |
|
|
311 |
/*
|
|
312 |
* Class: com_nokia_mid_ui_TextEditor
|
|
313 |
* Method: _setParent
|
|
314 |
* Signature: (III)I
|
|
315 |
*/
|
|
316 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1setParent(
|
|
317 |
JNIEnv* /* aJniEnv */,
|
|
318 |
jobject /* aPeer */,
|
|
319 |
jint aToolkitHandle,
|
|
320 |
jint aNativePeerHandle,
|
|
321 |
jint aParentHandle)
|
|
322 |
{
|
|
323 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
324 |
MMIDComponent* parent = NULL;
|
|
325 |
|
|
326 |
MMIDTextEditor* editor =
|
|
327 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
328 |
|
|
329 |
if (aParentHandle)
|
|
330 |
{
|
|
331 |
parent = MIDUnhandObject< MMIDComponent >(aParentHandle);
|
|
332 |
}
|
|
333 |
|
|
334 |
TInt error = toolkit->ExecuteTrap(
|
|
335 |
&SetParentL,
|
|
336 |
editor,
|
|
337 |
parent);
|
|
338 |
|
|
339 |
DEBUG_INT("TextEditor.cpp - setParent, error = %d", error);
|
|
340 |
|
|
341 |
return error;
|
|
342 |
}
|
|
343 |
|
|
344 |
/**
|
|
345 |
* Local helper function for setting a text editor visible.
|
|
346 |
*
|
|
347 |
* @param aEditor The editor to set visible.
|
|
348 |
*/
|
|
349 |
LOCAL_C void SetVisibleL(MMIDTextEditor* aEditor, TBool aVisible)
|
|
350 |
{
|
|
351 |
aEditor->SetVisibleL(aVisible);
|
|
352 |
}
|
|
353 |
|
|
354 |
/*
|
|
355 |
* Class: com_nokia_mid_ui_TextEditor
|
|
356 |
* Method: _show
|
|
357 |
* Signature: (II)I
|
|
358 |
*/
|
|
359 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1setVisible(
|
|
360 |
JNIEnv* /* aJniEnv */,
|
|
361 |
jobject /* aPeer */,
|
|
362 |
jint aToolkitHandle,
|
|
363 |
jint aNativePeerHandle,
|
|
364 |
jboolean aVisible)
|
|
365 |
{
|
|
366 |
DEBUG_INT("TextEditor.cpp - setVisible +, aVisible=%d", aVisible);
|
|
367 |
|
|
368 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
369 |
|
|
370 |
MMIDTextEditor* editor =
|
|
371 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
372 |
|
|
373 |
TInt error = toolkit->ExecuteTrap(
|
|
374 |
&SetVisibleL,
|
|
375 |
editor,
|
|
376 |
(TBool)aVisible);
|
|
377 |
|
|
378 |
DEBUG_INT("TextEditor.cpp - setVisible -, error=%d", error);
|
|
379 |
|
|
380 |
return error;
|
|
381 |
}
|
|
382 |
|
|
383 |
/**
|
|
384 |
* Local helper function for setting a text editor's position.
|
|
385 |
*
|
|
386 |
* @param aEditor The editor.
|
|
387 |
* @param aX The x coordinate of the anchor point.
|
|
388 |
* @param aY The y coordinate of the anchor point.
|
|
389 |
*/
|
|
390 |
LOCAL_C void SetPosition(MMIDTextEditor* aEditor, TInt aX, TInt aY)
|
|
391 |
{
|
|
392 |
aEditor->SetPosition(aX, aY);
|
|
393 |
}
|
|
394 |
|
|
395 |
/*
|
|
396 |
* Class: com_nokia_mid_ui_TextEditor
|
|
397 |
* Method: _setPosition
|
|
398 |
* Signature: (IIII)I
|
|
399 |
*/
|
|
400 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1setPosition(
|
|
401 |
JNIEnv* /* aJniEnv */,
|
|
402 |
jobject /* aPeer */,
|
|
403 |
jint aToolkitHandle,
|
|
404 |
jint aNativePeerHandle,
|
|
405 |
jint aX,
|
|
406 |
jint aY)
|
|
407 |
{
|
|
408 |
DEBUG("TextEditor.cpp - setPosition +");
|
|
409 |
|
|
410 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
411 |
|
|
412 |
MMIDTextEditor* editor =
|
|
413 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
414 |
|
|
415 |
toolkit->ExecuteV(&SetPosition, editor, aX, aY);
|
|
416 |
|
|
417 |
DEBUG("TextEditor.cpp - setPosition -");
|
|
418 |
|
|
419 |
return KErrNone;
|
|
420 |
}
|
|
421 |
|
|
422 |
/**
|
|
423 |
* Local helper function for setting the focus state of a text editor
|
|
424 |
*
|
|
425 |
* @param aTextEditor The text editor object to be modified.
|
|
426 |
* @param aFocused The focus status of the text editor to be set.
|
|
427 |
*/
|
|
428 |
LOCAL_C void SetFocusStateL(
|
|
429 |
MMIDTextEditor* aTextEditor,
|
|
430 |
TBool aFocusState)
|
|
431 |
{
|
|
432 |
aTextEditor->SetFocusStateL(aFocusState);
|
|
433 |
}
|
|
434 |
|
|
435 |
/*
|
|
436 |
* Class: com_nokia_mid_ui_TextEditor
|
|
437 |
* Method: _setFocusState
|
|
438 |
* Signature: (IIZ)I
|
|
439 |
*/
|
|
440 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1setFocusState(
|
|
441 |
JNIEnv* /* aJniEnv */,
|
|
442 |
jobject /* aPeer */,
|
|
443 |
jint aToolkitHandle,
|
|
444 |
jint aNativePeerHandle,
|
|
445 |
jboolean aFocusState)
|
|
446 |
{
|
|
447 |
DEBUG("TextEditor.cpp - setFocusState +");
|
|
448 |
|
|
449 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
450 |
|
|
451 |
MMIDTextEditor* editor =
|
|
452 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
453 |
|
|
454 |
TInt error = toolkit->ExecuteTrap(
|
|
455 |
&SetFocusStateL,
|
|
456 |
editor,
|
|
457 |
(TBool)aFocusState);
|
|
458 |
|
|
459 |
DEBUG_INT("TextEditor.cpp - setFocusState -, error=%d", error);
|
|
460 |
|
|
461 |
return error;
|
|
462 |
}
|
|
463 |
|
|
464 |
/**
|
|
465 |
* Local helper function for getting of focus state of a text editor
|
|
466 |
*
|
|
467 |
* @param aTextEditor The text editor object to be modified.
|
|
468 |
* @return The focus state of the text editor.
|
|
469 |
*/
|
|
470 |
LOCAL_C TBool GetFocusState(MMIDTextEditor* aTextEditor)
|
|
471 |
{
|
|
472 |
return aTextEditor->GetFocusState();
|
|
473 |
}
|
|
474 |
|
|
475 |
/*
|
|
476 |
* Class: com_nokia_mid_ui_TextEditor
|
|
477 |
* Method: _setFocusState
|
|
478 |
* Signature: (IIZ)I
|
|
479 |
*/
|
|
480 |
JNIEXPORT jboolean JNICALL Java_com_nokia_mid_ui_TextEditor__1getFocusState(
|
|
481 |
JNIEnv* /* aJniEnv */,
|
|
482 |
jobject /* aPeer */,
|
|
483 |
jint aToolkitHandle,
|
|
484 |
jint aNativePeerHandle)
|
|
485 |
{
|
|
486 |
DEBUG("TextEditor.cpp - getFocusState +");
|
|
487 |
|
|
488 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
489 |
|
|
490 |
MMIDTextEditor* editor =
|
|
491 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
492 |
|
|
493 |
TBool focusState = toolkit->Execute(&GetFocusState, editor);
|
|
494 |
|
|
495 |
DEBUG_INT("TextEditor.cpp - getFocusState -, focusState=%d", focusState);
|
|
496 |
|
|
497 |
return focusState;
|
|
498 |
}
|
|
499 |
|
|
500 |
/**
|
|
501 |
* Local helper function for setting the constraints of a text editor
|
|
502 |
*
|
|
503 |
* @param aTextEditor The text editor object to be modified.
|
|
504 |
* @param aConstraints The new constraints for the editor.
|
|
505 |
*/
|
|
506 |
LOCAL_C void SetConstraintsL(MMIDTextEditor* aTextEditor, TInt aConstraints)
|
|
507 |
{
|
|
508 |
aTextEditor->SetConstraintsL(aConstraints);
|
|
509 |
}
|
|
510 |
|
|
511 |
/*
|
|
512 |
* Class: com_nokia_mid_ui_TextEditor
|
|
513 |
* Method: _setConstraints
|
|
514 |
* Signature: (III)I
|
|
515 |
*/
|
|
516 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1setConstraints(
|
|
517 |
JNIEnv* /* aJniEnv */,
|
|
518 |
jobject /* aPeer */,
|
|
519 |
jint aToolkitHandle,
|
|
520 |
jint aNativePeerHandle,
|
|
521 |
jint aConstraints)
|
|
522 |
{
|
|
523 |
DEBUG("TextEditor.cpp - setConstraints +");
|
|
524 |
|
|
525 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
526 |
|
|
527 |
MMIDTextEditor* editor =
|
|
528 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
529 |
|
|
530 |
TInt error = toolkit->ExecuteTrap(
|
|
531 |
&SetConstraintsL,
|
|
532 |
editor,
|
|
533 |
aConstraints);
|
|
534 |
|
|
535 |
DEBUG_INT("TextEditor.cpp - setConstraints -, error=%d", error);
|
|
536 |
|
|
537 |
return error;
|
|
538 |
}
|
|
539 |
|
|
540 |
/**
|
|
541 |
* Local helper function for setting the initial input mode of a text editor
|
|
542 |
*
|
|
543 |
* @param aTextEditor The text editor object to be modified.
|
|
544 |
* @param aCharacterSubset The character subset for the input mode
|
|
545 |
*/
|
|
546 |
LOCAL_C void SetInitialInputModeL(
|
|
547 |
MMIDTextEditor* aTextEditor,
|
|
548 |
const TDesC* aCharacterSubset)
|
|
549 |
{
|
|
550 |
// Subset must be at least an empty string.
|
|
551 |
__ASSERT_DEBUG(aCharacterSubset, User::Invariant());
|
|
552 |
|
|
553 |
aTextEditor->SetInitialInputModeL(*aCharacterSubset);
|
|
554 |
}
|
|
555 |
|
|
556 |
/*
|
|
557 |
* Class: com_nokia_mid_ui_TextEditor
|
|
558 |
* Method: _setInitialInputMode
|
|
559 |
* Signature: (IILjava/lang/String;)I
|
|
560 |
*/
|
|
561 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1setInitialInputMode(
|
|
562 |
JNIEnv* aJniEnv,
|
|
563 |
jobject /* aPeer */,
|
|
564 |
jint aToolkitHandle,
|
|
565 |
jint aNativePeerHandle,
|
|
566 |
jstring aCharacterSubset)
|
|
567 |
{
|
|
568 |
DEBUG("TextEditor.cpp - setInitialInputMode +");
|
|
569 |
|
|
570 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
571 |
|
|
572 |
MMIDTextEditor* editor =
|
|
573 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
574 |
|
|
575 |
// Convert the subset to a native descriptor. NULL indicates
|
|
576 |
// that an empty string is set as initial input mode.
|
|
577 |
const RJString subset(*aJniEnv, aCharacterSubset);
|
|
578 |
const TDesC* nativeSubset = (aCharacterSubset ? &subset : &KNullDesC);
|
|
579 |
|
|
580 |
TInt error = toolkit->ExecuteTrap(
|
|
581 |
&SetInitialInputModeL,
|
|
582 |
editor,
|
|
583 |
nativeSubset);
|
|
584 |
|
|
585 |
DEBUG_INT("TextEditor.cpp - setInitialInputMode -, error=%d", error);
|
|
586 |
|
|
587 |
return error;
|
|
588 |
}
|
|
589 |
|
|
590 |
/**
|
|
591 |
* Local helper function for setting the content of a text editor
|
|
592 |
*
|
|
593 |
* @param aTextEditor The text editor object to be modified.
|
|
594 |
* @param aConstraints The new content for the editor.
|
|
595 |
*/
|
|
596 |
LOCAL_C void SetContentL(MMIDTextEditor* aTextEditor, const TDesC* aContent)
|
|
597 |
{
|
|
598 |
// Content must be at least an empty string.
|
|
599 |
__ASSERT_DEBUG(aContent, User::Invariant());
|
|
600 |
|
|
601 |
aTextEditor->SetContentL(*aContent);
|
|
602 |
}
|
|
603 |
|
|
604 |
/*
|
|
605 |
* Class: com_nokia_mid_ui_TextEditor
|
|
606 |
* Method: _setContent
|
|
607 |
* Signature: (IILjava/lang/String;)I
|
|
608 |
*/
|
|
609 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1setContent(
|
|
610 |
JNIEnv* aJniEnv,
|
|
611 |
jobject /* aPeer */,
|
|
612 |
jint aToolkitHandle,
|
|
613 |
jint aNativePeerHandle,
|
|
614 |
jstring aContent)
|
|
615 |
{
|
|
616 |
DEBUG("TextEditor.cpp - setContent +");
|
|
617 |
|
|
618 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
619 |
|
|
620 |
MMIDTextEditor* editor =
|
|
621 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
622 |
|
|
623 |
// Convert the content to a native descriptor. NULL indicates
|
|
624 |
// that an empty string is set as content.
|
|
625 |
const RJString content(*aJniEnv, aContent);
|
|
626 |
const TDesC* nativeContent = (aContent ? &content : &KNullDesC);
|
|
627 |
|
|
628 |
TInt error = toolkit->ExecuteTrap(
|
|
629 |
&SetContentL,
|
|
630 |
editor,
|
|
631 |
nativeContent);
|
|
632 |
|
|
633 |
DEBUG_INT("TextEditor.cpp - setContent -, error=%d", error);
|
|
634 |
|
|
635 |
return error;
|
|
636 |
}
|
|
637 |
|
|
638 |
/**
|
|
639 |
* Local helper function for getting the content of a text editor
|
|
640 |
*
|
|
641 |
* @param aTextEditor The text editor object to be modified.
|
|
642 |
* @param aContent On return, contains the content of the editor.
|
|
643 |
* The ownership is transferred to the caller.
|
|
644 |
*/
|
|
645 |
LOCAL_C void GetContentL(MMIDTextEditor* aTextEditor, HBufC** aContent)
|
|
646 |
{
|
|
647 |
*aContent = aTextEditor->ContentL();
|
|
648 |
}
|
|
649 |
|
|
650 |
/*
|
|
651 |
* Class: com_nokia_mid_ui_TextEditor
|
|
652 |
* Method: _getContent
|
|
653 |
* Signature: (II[I)Ljava/lang/String;
|
|
654 |
*/
|
|
655 |
JNIEXPORT jstring JNICALL Java_com_nokia_mid_ui_TextEditor__1getContent(
|
|
656 |
JNIEnv* aJniEnv,
|
|
657 |
jobject /* aPeer */,
|
|
658 |
jint aToolkitHandle,
|
|
659 |
jint aNativePeerHandle,
|
|
660 |
jintArray aError)
|
|
661 |
{
|
|
662 |
DEBUG("TextEditor.cpp - getContent +");
|
|
663 |
|
|
664 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
665 |
|
|
666 |
MMIDTextEditor* editor =
|
|
667 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
668 |
|
|
669 |
HBufC* text = NULL;
|
|
670 |
|
|
671 |
TInt error = toolkit->ExecuteTrap(
|
|
672 |
&GetContentL,
|
|
673 |
editor,
|
|
674 |
&text);
|
|
675 |
|
|
676 |
// Handle text conversion an errors.
|
|
677 |
jstring content = HandleString(*aJniEnv, *text, error, aError);
|
|
678 |
|
|
679 |
// Text is not needed anymore.
|
|
680 |
delete text;
|
|
681 |
|
|
682 |
DEBUG("TextEditor.cpp - getContent -");
|
|
683 |
|
|
684 |
return content;
|
|
685 |
}
|
|
686 |
|
|
687 |
/**
|
|
688 |
* Local helper function for deleting a content from a text editor.
|
|
689 |
*
|
|
690 |
* @param aEditor The editor.
|
|
691 |
* @param aOffset The beginning of the range to be deleted.
|
|
692 |
* @param aLength The length of the range to be deleted.
|
|
693 |
*/
|
|
694 |
LOCAL_C void DeleteContentL(
|
|
695 |
MMIDTextEditor* aEditor,
|
|
696 |
TInt aOffset,
|
|
697 |
TInt aLength)
|
|
698 |
{
|
|
699 |
return aEditor->DeleteContentL(aOffset, aLength);
|
|
700 |
}
|
|
701 |
|
|
702 |
|
|
703 |
/*
|
|
704 |
* Class: com_nokia_mid_ui_TextEditor
|
|
705 |
* Method: _delete
|
|
706 |
* Signature: (IIII)I
|
|
707 |
*/
|
|
708 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1delete(
|
|
709 |
JNIEnv* /* aJniEnv */,
|
|
710 |
jobject /* aPeer */,
|
|
711 |
jint aToolkitHandle,
|
|
712 |
jint aNativePeerHandle,
|
|
713 |
jint aOffset,
|
|
714 |
jint aLength)
|
|
715 |
{
|
|
716 |
DEBUG("TextEditor.cpp - delete +");
|
|
717 |
|
|
718 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
719 |
|
|
720 |
MMIDTextEditor* editor =
|
|
721 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
722 |
|
|
723 |
TInt error = toolkit->ExecuteTrap(
|
|
724 |
&DeleteContentL,
|
|
725 |
editor,
|
|
726 |
aOffset,
|
|
727 |
aLength);
|
|
728 |
|
|
729 |
DEBUG_INT("TextEditor.cpp - delete -, error=%d", error);
|
|
730 |
|
|
731 |
return error;
|
|
732 |
}
|
|
733 |
|
|
734 |
/**
|
|
735 |
* Local helper function for getting the number of characters in a text
|
|
736 |
* editor.
|
|
737 |
*
|
|
738 |
* @param aEditor The editor.
|
|
739 |
* @return The size of the editor's content.
|
|
740 |
*/
|
|
741 |
LOCAL_C TInt Size(MMIDTextEditor* aEditor)
|
|
742 |
{
|
|
743 |
return aEditor->ContentLength();
|
|
744 |
}
|
|
745 |
|
|
746 |
/*
|
|
747 |
* Class: com_nokia_mid_ui_TextEditor
|
|
748 |
* Method: _size
|
|
749 |
* Signature: (II)I
|
|
750 |
*/
|
|
751 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1size(
|
|
752 |
JNIEnv* /* aJniEnv */,
|
|
753 |
jobject /* aPeer */,
|
|
754 |
jint aToolkitHandle,
|
|
755 |
jint aNativePeerHandle)
|
|
756 |
{
|
|
757 |
DEBUG("TextEditor.cpp - size +");
|
|
758 |
|
|
759 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
760 |
|
|
761 |
MMIDTextEditor* editor =
|
|
762 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
763 |
|
|
764 |
TInt size = toolkit->Execute(&Size, editor);
|
|
765 |
|
|
766 |
DEBUG_INT("TextEditor.cpp - size -, size=%d", size);
|
|
767 |
|
|
768 |
return size;
|
|
769 |
}
|
|
770 |
|
|
771 |
/**
|
|
772 |
* Local helper function for getting the line margin height in a text editor.
|
|
773 |
*
|
|
774 |
* @param aEditor The editor.
|
|
775 |
* @return The line margin height of the editor.
|
|
776 |
*/
|
|
777 |
LOCAL_C TInt LineMarginHeight(MMIDTextEditor* aEditor)
|
|
778 |
{
|
|
779 |
return aEditor->LineMarginHeight();
|
|
780 |
}
|
|
781 |
|
|
782 |
/*
|
|
783 |
* Class: com_nokia_mid_ui_TextEditor
|
|
784 |
* Method: _getLineMarginHeight
|
|
785 |
* Signature: (II)I
|
|
786 |
*/
|
|
787 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1getLineMarginHeight(
|
|
788 |
JNIEnv* /* aJniEnv */,
|
|
789 |
jobject /* aPeer */,
|
|
790 |
jint aToolkitHandle,
|
|
791 |
jint aNativePeerHandle)
|
|
792 |
{
|
|
793 |
DEBUG("TextEditor.cpp - getLineMarginHeight +");
|
|
794 |
|
|
795 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
796 |
|
|
797 |
MMIDTextEditor* editor =
|
|
798 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
799 |
|
|
800 |
TInt lineMarginHeight = toolkit->Execute(&LineMarginHeight, editor);
|
|
801 |
|
|
802 |
DEBUG_INT("TextEditor.cpp - getLineMarginHeight -, lineMarginHeight=%d",
|
|
803 |
lineMarginHeight);
|
|
804 |
|
|
805 |
return lineMarginHeight;
|
|
806 |
}
|
|
807 |
|
|
808 |
/**
|
|
809 |
* Local helper function for getting the content height in a text editor.
|
|
810 |
*
|
|
811 |
* @param aEditor The editor.
|
|
812 |
* @return The content height of the editor.
|
|
813 |
*/
|
|
814 |
LOCAL_C TInt ContentHeight(MMIDTextEditor* aEditor)
|
|
815 |
{
|
|
816 |
return aEditor->ContentHeight();
|
|
817 |
}
|
|
818 |
|
|
819 |
/*
|
|
820 |
* Class: com_nokia_mid_ui_TextEditor
|
|
821 |
* Method: _getContentHeight
|
|
822 |
* Signature: (II)I
|
|
823 |
*/
|
|
824 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1getContentHeight(
|
|
825 |
JNIEnv* /* aJniEnv */,
|
|
826 |
jobject /* aPeer */,
|
|
827 |
jint aToolkitHandle,
|
|
828 |
jint aNativePeerHandle)
|
|
829 |
{
|
|
830 |
DEBUG("TextEditor.cpp - getContentHeight +");
|
|
831 |
|
|
832 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
833 |
|
|
834 |
MMIDTextEditor* editor =
|
|
835 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
836 |
|
|
837 |
TInt contentHeight = toolkit->Execute(&ContentHeight, editor);
|
|
838 |
|
|
839 |
DEBUG_INT("TextEditor.cpp - getContentHeight -, contentHeight=%d",
|
|
840 |
contentHeight);
|
|
841 |
|
|
842 |
return contentHeight;
|
|
843 |
}
|
|
844 |
|
|
845 |
/**
|
|
846 |
* Local helper function for inserting content to a text editor.
|
|
847 |
*
|
|
848 |
* @param aEditor The editor.
|
|
849 |
* @param aContent The content to be inserted.
|
|
850 |
* @param aPosition The position of the inserted text.
|
|
851 |
*/
|
|
852 |
LOCAL_C void InsertContentL(
|
|
853 |
MMIDTextEditor* aEditor,
|
|
854 |
const TDesC* aContent,
|
|
855 |
TInt aPosition)
|
|
856 |
{
|
|
857 |
// Content must not be NULL.
|
|
858 |
__ASSERT_DEBUG(aContent, User::Invariant());
|
|
859 |
aEditor->InsertContentL(*aContent, aPosition);
|
|
860 |
}
|
|
861 |
|
|
862 |
/*
|
|
863 |
* Class: com_nokia_mid_ui_TextEditor
|
|
864 |
* Method: _insert
|
|
865 |
* Signature: (IILjava/lang/String;I)I
|
|
866 |
*/
|
|
867 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1insert(
|
|
868 |
JNIEnv* aJniEnv,
|
|
869 |
jobject /* aPeer */,
|
|
870 |
jint aToolkitHandle,
|
|
871 |
jint aNativePeerHandle,
|
|
872 |
jstring aContent,
|
|
873 |
jint aPosition)
|
|
874 |
{
|
|
875 |
DEBUG("TextEditor.cpp - insert +");
|
|
876 |
|
|
877 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
878 |
|
|
879 |
MMIDTextEditor* editor =
|
|
880 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
881 |
|
|
882 |
// Convert the content to a native descriptor.
|
|
883 |
const RJString content(*aJniEnv, aContent);
|
|
884 |
const TDesC* nativeContent = (aContent ? &content : NULL);
|
|
885 |
|
|
886 |
TInt error = toolkit->ExecuteTrap(
|
|
887 |
&InsertContentL,
|
|
888 |
editor,
|
|
889 |
nativeContent,
|
|
890 |
aPosition);
|
|
891 |
|
|
892 |
DEBUG_INT("TextEditor.cpp - insert -, error=%d", error);
|
|
893 |
|
|
894 |
return error;
|
|
895 |
}
|
|
896 |
|
|
897 |
/**
|
|
898 |
* Local helper function for setting the maximum size of a text editor.
|
|
899 |
*
|
|
900 |
* @param aEditor The editor.
|
|
901 |
* @param aMaxSize The new maximum size for the editor.
|
|
902 |
* @param aChangedMaxSize The actual size which the editor has accepted.
|
|
903 |
*/
|
|
904 |
LOCAL_C void SetMaxSizeL(
|
|
905 |
MMIDTextEditor* aEditor,
|
|
906 |
TInt aMaxSize,
|
|
907 |
TInt* aChangedMaxSize)
|
|
908 |
{
|
|
909 |
*aChangedMaxSize = aEditor->SetMaxSizeL(aMaxSize);
|
|
910 |
}
|
|
911 |
|
|
912 |
/*
|
|
913 |
* Class: com_nokia_mid_ui_TextEditor
|
|
914 |
* Method: _setMaxSize
|
|
915 |
* Signature: (III)I
|
|
916 |
*/
|
|
917 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1setMaxSize(
|
|
918 |
JNIEnv* /* aJniEnv */,
|
|
919 |
jobject /* aPeer */,
|
|
920 |
jint aToolkitHandle,
|
|
921 |
jint aNativePeerHandle,
|
|
922 |
jint aMaxSize)
|
|
923 |
{
|
|
924 |
DEBUG("TextEditor.cpp - setMaxSize +");
|
|
925 |
|
|
926 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
927 |
|
|
928 |
MMIDTextEditor* editor =
|
|
929 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
930 |
|
|
931 |
TInt changedMaxSize = 0;
|
|
932 |
|
|
933 |
TInt error = toolkit->ExecuteTrap(
|
|
934 |
&SetMaxSizeL,
|
|
935 |
editor,
|
|
936 |
aMaxSize,
|
|
937 |
&changedMaxSize);
|
|
938 |
|
|
939 |
DEBUG_INT("TextEditor.cpp - setMaxSize -, error=%d", error);
|
|
940 |
|
|
941 |
return (error == KErrNone ? changedMaxSize : error);
|
|
942 |
}
|
|
943 |
|
|
944 |
/**
|
|
945 |
* Local helper function for getting the cursor position in a text editor.
|
|
946 |
*
|
|
947 |
* @param aEditor The editor.
|
|
948 |
* @return The current position of the cursor in the text editor.
|
|
949 |
*/
|
|
950 |
LOCAL_C TInt CursorPosition(MMIDTextEditor* aEditor)
|
|
951 |
{
|
|
952 |
return aEditor->CursorPosition();
|
|
953 |
}
|
|
954 |
|
|
955 |
/*
|
|
956 |
* Class: com_nokia_mid_ui_TextEditor
|
|
957 |
* Method: _getCaretPosition
|
|
958 |
* Signature: (II)I
|
|
959 |
*/
|
|
960 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1getCaretPosition(
|
|
961 |
JNIEnv* /* aJniEnv */,
|
|
962 |
jobject /* aPeer */,
|
|
963 |
jint aToolkitHandle,
|
|
964 |
jint aNativePeerHandle)
|
|
965 |
{
|
|
966 |
DEBUG("TextEditor.cpp - getCaretPosition +");
|
|
967 |
|
|
968 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
969 |
|
|
970 |
MMIDTextEditor* editor =
|
|
971 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
972 |
|
|
973 |
TInt position = toolkit->Execute(&CursorPosition, editor);
|
|
974 |
|
|
975 |
DEBUG_INT("TextEditor.cpp - getCaretPosition -, position=%d", position);
|
|
976 |
|
|
977 |
return position;
|
|
978 |
}
|
|
979 |
|
|
980 |
/**
|
|
981 |
* Local helper function for getting the topmost pixel's position
|
|
982 |
* in a text editor.
|
|
983 |
*
|
|
984 |
* @param aEditor The editor.
|
|
985 |
* @return The topmost pixel's position of the visible content.
|
|
986 |
*/
|
|
987 |
LOCAL_C TInt VisibleContentPosition(MMIDTextEditor* aEditor)
|
|
988 |
{
|
|
989 |
return aEditor->VisibleContentPosition();
|
|
990 |
}
|
|
991 |
|
|
992 |
/*
|
|
993 |
* Class: com_nokia_mid_ui_TextEditor
|
|
994 |
* Method: _getVisibleContentPosition
|
|
995 |
* Signature: (II)I
|
|
996 |
*/
|
|
997 |
JNIEXPORT jint JNICALL
|
|
998 |
Java_com_nokia_mid_ui_TextEditor__1getVisibleContentPosition(
|
|
999 |
JNIEnv* /* aJniEnv */,
|
|
1000 |
jobject /* aPeer */,
|
|
1001 |
jint aToolkitHandle,
|
|
1002 |
jint aNativePeerHandle)
|
|
1003 |
{
|
|
1004 |
DEBUG("TextEditor.cpp - getVisibleContentPosition +");
|
|
1005 |
|
|
1006 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
1007 |
|
|
1008 |
MMIDTextEditor* editor =
|
|
1009 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
1010 |
|
|
1011 |
TInt position = toolkit->Execute(&VisibleContentPosition, editor);
|
|
1012 |
|
|
1013 |
DEBUG_INT("TextEditor.cpp - getVisibleContentPosition -, position=%d",
|
|
1014 |
position);
|
|
1015 |
|
|
1016 |
return position;
|
|
1017 |
}
|
|
1018 |
|
|
1019 |
/**
|
|
1020 |
* Local helper function for setting the cursor's position in a text editor.
|
|
1021 |
*
|
|
1022 |
* @param aEditor The editor.
|
|
1023 |
* @param aIndex The new position of the cursor.
|
|
1024 |
*/
|
|
1025 |
LOCAL_C void SetCursorPositionL(
|
|
1026 |
MMIDTextEditor* aEditor,
|
|
1027 |
TInt aIndex)
|
|
1028 |
{
|
|
1029 |
aEditor->SetCursorPositionL(aIndex);
|
|
1030 |
}
|
|
1031 |
|
|
1032 |
/*
|
|
1033 |
* Class: com_nokia_mid_ui_TextEditor
|
|
1034 |
* Method: _setCaret
|
|
1035 |
* Signature: (III)I
|
|
1036 |
*/
|
|
1037 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1setCaret(
|
|
1038 |
JNIEnv* /* aJniEnv */,
|
|
1039 |
jobject /* aPeer */,
|
|
1040 |
jint aToolkitHandle,
|
|
1041 |
jint aNativePeerHandle,
|
|
1042 |
jint aIndex)
|
|
1043 |
{
|
|
1044 |
DEBUG("TextEditor.cpp - setCaret +");
|
|
1045 |
|
|
1046 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
1047 |
|
|
1048 |
MMIDTextEditor* editor =
|
|
1049 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
1050 |
|
|
1051 |
TInt error = toolkit->ExecuteTrap(
|
|
1052 |
&SetCursorPositionL,
|
|
1053 |
editor,
|
|
1054 |
aIndex);
|
|
1055 |
|
|
1056 |
DEBUG_INT("TextEditor.cpp - setCaret -, error=%d", error);
|
|
1057 |
|
|
1058 |
return error;
|
|
1059 |
}
|
|
1060 |
|
|
1061 |
/**
|
|
1062 |
* Local helper function for setting the color in a text editor.
|
|
1063 |
*
|
|
1064 |
* @param aEditor The editor.
|
|
1065 |
* @param aColor The new color for the specified color type.
|
|
1066 |
* @param aColorType The color type to be modified.
|
|
1067 |
*/
|
|
1068 |
LOCAL_C void SetColorL(
|
|
1069 |
MMIDTextEditor* aEditor,
|
|
1070 |
const TRgb* aColor,
|
|
1071 |
TInt aColorType)
|
|
1072 |
{
|
|
1073 |
aEditor->SetColorL(
|
|
1074 |
*aColor,
|
|
1075 |
static_cast< MMIDTextEditor::TColorType >(aColorType));
|
|
1076 |
}
|
|
1077 |
|
|
1078 |
/*
|
|
1079 |
* Class: com_nokia_mid_ui_TextEditor
|
|
1080 |
* Method: _setColor
|
|
1081 |
* Signature: (II[II)I
|
|
1082 |
*/
|
|
1083 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1setColor(
|
|
1084 |
JNIEnv* aJniEnv,
|
|
1085 |
jobject /* aPeer */,
|
|
1086 |
jint aToolkitHandle,
|
|
1087 |
jint aNativePeerHandle,
|
|
1088 |
jintArray aColor,
|
|
1089 |
jint aColorType)
|
|
1090 |
{
|
|
1091 |
DEBUG("TextEditor.cpp - setColor +");
|
|
1092 |
|
|
1093 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
1094 |
|
|
1095 |
MMIDTextEditor* editor =
|
|
1096 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
1097 |
|
|
1098 |
jint colorArray[ KNumColors ];
|
|
1099 |
aJniEnv->GetIntArrayRegion(aColor, 0, KNumColors, colorArray);
|
|
1100 |
|
|
1101 |
const TRgb color(
|
|
1102 |
colorArray[ KColorIndexRed ],
|
|
1103 |
colorArray[ KColorIndexGreen ],
|
|
1104 |
colorArray[ KColorIndexBlue ],
|
|
1105 |
colorArray[ KColorIndexAlpha ]);
|
|
1106 |
|
|
1107 |
TInt error = toolkit->ExecuteTrap(
|
|
1108 |
&SetColorL,
|
|
1109 |
editor,
|
|
1110 |
&color,
|
|
1111 |
aColorType);
|
|
1112 |
|
|
1113 |
DEBUG_INT("TextEditor.cpp - setColor -, error=%d", error);
|
|
1114 |
|
|
1115 |
return error;
|
|
1116 |
}
|
|
1117 |
|
|
1118 |
/**
|
|
1119 |
* Local helper function for getting the color from a text editor.
|
|
1120 |
*
|
|
1121 |
* @param aEditor The editor.
|
|
1122 |
* @param aColor The new color for the specified color type.
|
|
1123 |
* @param aColorType The color type to be modified.
|
|
1124 |
*/
|
|
1125 |
LOCAL_C TInt GetColor(MMIDTextEditor* aEditor, TInt aColorType)
|
|
1126 |
{
|
|
1127 |
return aEditor->GetColor(
|
|
1128 |
static_cast< MMIDTextEditor::TColorType >(aColorType));
|
|
1129 |
}
|
|
1130 |
|
|
1131 |
/*
|
|
1132 |
* Class: com_nokia_mid_ui_TextEditor
|
|
1133 |
* Method: _setColor
|
|
1134 |
* Signature: (II[II)I
|
|
1135 |
*/
|
|
1136 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1getColor(
|
|
1137 |
JNIEnv* /* aJniEnv */,
|
|
1138 |
jobject /* aPeer */,
|
|
1139 |
jint aToolkitHandle,
|
|
1140 |
jint aNativePeerHandle,
|
|
1141 |
jint aColorType)
|
|
1142 |
{
|
|
1143 |
DEBUG("TextEditor.cpp - getColor +");
|
|
1144 |
|
|
1145 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
1146 |
|
|
1147 |
MMIDTextEditor* editor =
|
|
1148 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
1149 |
|
|
1150 |
jint color = toolkit->Execute(&GetColor, editor, (TInt)aColorType);
|
|
1151 |
|
|
1152 |
//DEBUG_INT("TextEditor.cpp - getColor -, error=%d", error);
|
|
1153 |
|
|
1154 |
return color;
|
|
1155 |
}
|
|
1156 |
|
|
1157 |
|
|
1158 |
/**
|
|
1159 |
* Local helper function for selecting a content from a text editor.
|
|
1160 |
*
|
|
1161 |
* @param aEditor The editor.
|
|
1162 |
* @param aIndex The beginning of the range to be selected.
|
|
1163 |
* @param aLength The length of the range to be selected.
|
|
1164 |
*/
|
|
1165 |
LOCAL_C void SetSelectionL(
|
|
1166 |
MMIDTextEditor* aEditor,
|
|
1167 |
TInt aIndex,
|
|
1168 |
TInt aLength)
|
|
1169 |
{
|
|
1170 |
return aEditor->SetSelectionL(aIndex, aLength);
|
|
1171 |
}
|
|
1172 |
|
|
1173 |
/*
|
|
1174 |
* Class: com_nokia_mid_ui_TextEditor
|
|
1175 |
* Method: _setSelection
|
|
1176 |
* Signature: (IIII)I
|
|
1177 |
*/
|
|
1178 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1setSelection(
|
|
1179 |
JNIEnv* /* aJniEnv */,
|
|
1180 |
jobject /* aPeer */,
|
|
1181 |
jint aToolkitHandle,
|
|
1182 |
jint aNativePeerHandle,
|
|
1183 |
jint aIndex,
|
|
1184 |
jint aLength)
|
|
1185 |
{
|
|
1186 |
DEBUG("TextEditor.cpp - setSelection +");
|
|
1187 |
|
|
1188 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
1189 |
|
|
1190 |
MMIDTextEditor* editor =
|
|
1191 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
1192 |
|
|
1193 |
TInt error = toolkit->ExecuteTrap(
|
|
1194 |
&SetSelectionL,
|
|
1195 |
editor,
|
|
1196 |
aIndex,
|
|
1197 |
aLength);
|
|
1198 |
|
|
1199 |
DEBUG_INT("TextEditor.cpp - setSelection -, error=%d", error);
|
|
1200 |
|
|
1201 |
return error;
|
|
1202 |
}
|
|
1203 |
|
|
1204 |
/**
|
|
1205 |
* Local helper function for getting the current selection of a text editor
|
|
1206 |
*
|
|
1207 |
* @param aTextEditor The text editor object to be modified.
|
|
1208 |
* @param aContent On return, contains the current selection of the editor.
|
|
1209 |
* The ownership is transferred to the caller.
|
|
1210 |
*/
|
|
1211 |
LOCAL_C void GetSelectionL(MMIDTextEditor* aTextEditor, HBufC** aContent)
|
|
1212 |
{
|
|
1213 |
*aContent = aTextEditor->SelectionL();
|
|
1214 |
}
|
|
1215 |
|
|
1216 |
/*
|
|
1217 |
* Class: com_nokia_mid_ui_TextEditor
|
|
1218 |
* Method: _getSelection
|
|
1219 |
* Signature: (II[I)Ljava/lang/String;
|
|
1220 |
*/
|
|
1221 |
JNIEXPORT jstring JNICALL Java_com_nokia_mid_ui_TextEditor__1getSelection(
|
|
1222 |
JNIEnv* aJniEnv,
|
|
1223 |
jobject /* aPeer */,
|
|
1224 |
jint aToolkitHandle,
|
|
1225 |
jint aNativePeerHandle,
|
|
1226 |
jintArray aError)
|
|
1227 |
{
|
|
1228 |
DEBUG("TextEditor.cpp - getSelection +");
|
|
1229 |
|
|
1230 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
1231 |
|
|
1232 |
MMIDTextEditor* editor =
|
|
1233 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
1234 |
|
|
1235 |
HBufC* text = NULL;
|
|
1236 |
|
|
1237 |
TInt error = toolkit->ExecuteTrap(
|
|
1238 |
&GetSelectionL,
|
|
1239 |
editor,
|
|
1240 |
&text);
|
|
1241 |
|
|
1242 |
// Handle text conversion an errors.
|
|
1243 |
jstring selection = HandleString(*aJniEnv, *text, error, aError);
|
|
1244 |
|
|
1245 |
// Text is not needed anymore.
|
|
1246 |
delete text;
|
|
1247 |
|
|
1248 |
DEBUG("TextEditor.cpp - getSelection -");
|
|
1249 |
|
|
1250 |
return selection;
|
|
1251 |
}
|
|
1252 |
|
|
1253 |
/**
|
|
1254 |
* Local helper function for setting the font to text editor.
|
|
1255 |
*
|
|
1256 |
* @param aEditor The editor.
|
|
1257 |
* @param aFont The font to be set.
|
|
1258 |
*/
|
|
1259 |
LOCAL_C void SetFontL(
|
|
1260 |
MMIDTextEditor* aEditor,
|
|
1261 |
MMIDFont* aFont)
|
|
1262 |
{
|
|
1263 |
aEditor->SetFontL(aFont);
|
|
1264 |
}
|
|
1265 |
|
|
1266 |
/*
|
|
1267 |
* Class: com_nokia_mid_ui_TextEditor
|
|
1268 |
* Method: _setFont
|
|
1269 |
* Signature: (III)I
|
|
1270 |
*/
|
|
1271 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1setFont(
|
|
1272 |
JNIEnv* /* aJniEnv */,
|
|
1273 |
jobject /* aPeer */,
|
|
1274 |
jint aToolkitHandle,
|
|
1275 |
jint aNativePeerHandle,
|
|
1276 |
jint aFontHandle)
|
|
1277 |
{
|
|
1278 |
DEBUG("TextEditor.cpp - setFont +");
|
|
1279 |
|
|
1280 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
1281 |
|
|
1282 |
MMIDTextEditor* editor =
|
|
1283 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
1284 |
|
|
1285 |
MMIDFont* font = MIDUnhandObject< MMIDFont >(aFontHandle);
|
|
1286 |
|
|
1287 |
TInt error = toolkit->ExecuteTrap(
|
|
1288 |
&SetFontL,
|
|
1289 |
editor,
|
|
1290 |
font);
|
|
1291 |
|
|
1292 |
DEBUG_INT("TextEditor.cpp - setFont -, error=%d", error);
|
|
1293 |
|
|
1294 |
return error;
|
|
1295 |
}
|
|
1296 |
|
|
1297 |
/**
|
|
1298 |
* Local helper function for setting an observer for a text editor.
|
|
1299 |
*
|
|
1300 |
* @param aTextEditor The text editor object to be modified.
|
|
1301 |
* @param aObserver The text editor observer or NULL.
|
|
1302 |
*/
|
|
1303 |
LOCAL_C void SetObserver(
|
|
1304 |
MMIDTextEditor* aTextEditor,
|
|
1305 |
MMIDTextEditorObserver* aObserver)
|
|
1306 |
{
|
|
1307 |
aTextEditor->SetObserver(aObserver);
|
|
1308 |
}
|
|
1309 |
|
|
1310 |
/*
|
|
1311 |
* Class: com_nokia_mid_ui_TextEditor
|
|
1312 |
* Method: _setListener
|
|
1313 |
* Signature: (III)I
|
|
1314 |
*/
|
|
1315 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1setListener(
|
|
1316 |
JNIEnv* /* aJniEnv */,
|
|
1317 |
jobject /* aPeer */,
|
|
1318 |
jint aToolkitHandle,
|
|
1319 |
jint aNativePeerHandle,
|
|
1320 |
jint aListenerHandle)
|
|
1321 |
{
|
|
1322 |
DEBUG("TextEditor.cpp - setListener +");
|
|
1323 |
|
|
1324 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
1325 |
|
|
1326 |
MMIDTextEditor* editor =
|
|
1327 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
1328 |
|
|
1329 |
MMIDTextEditorObserver* observer = NULL;
|
|
1330 |
|
|
1331 |
if (aListenerHandle > 0)
|
|
1332 |
{
|
|
1333 |
observer =
|
|
1334 |
MIDUnhandObject< MMIDTextEditorObserver >(aListenerHandle);
|
|
1335 |
}
|
|
1336 |
|
|
1337 |
toolkit->ExecuteV(
|
|
1338 |
&SetObserver,
|
|
1339 |
editor,
|
|
1340 |
observer);
|
|
1341 |
|
|
1342 |
DEBUG("TextEditor.cpp - setListener -");
|
|
1343 |
|
|
1344 |
return KErrNone;
|
|
1345 |
}
|
|
1346 |
|
|
1347 |
/**
|
|
1348 |
* Local helper function for setting the elevation of a text editor.
|
|
1349 |
*
|
|
1350 |
* @param aTextEditor The text editor object to be modified.
|
|
1351 |
* @param aZ The z-position defining the elevation.
|
|
1352 |
*/
|
|
1353 |
LOCAL_C void SetElevationL(MMIDTextEditor* aTextEditor, TInt aZ)
|
|
1354 |
{
|
|
1355 |
aTextEditor->SetElevationL(aZ);
|
|
1356 |
}
|
|
1357 |
|
|
1358 |
/*
|
|
1359 |
* Class: com_nokia_mid_ui_TextEditor
|
|
1360 |
* Method: _setZPosition
|
|
1361 |
* Signature: (III)I
|
|
1362 |
*/
|
|
1363 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1setZPosition(
|
|
1364 |
JNIEnv* /* aJniEnv */,
|
|
1365 |
jobject /* aPeer */,
|
|
1366 |
jint aToolkitHandle,
|
|
1367 |
jint aNativePeerHandle,
|
|
1368 |
jint aZ)
|
|
1369 |
{
|
|
1370 |
DEBUG("TextEditor.cpp - setZPosition +");
|
|
1371 |
|
|
1372 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
1373 |
MMIDTextEditor* editor =
|
|
1374 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
1375 |
|
|
1376 |
TInt error = toolkit->ExecuteTrap(
|
|
1377 |
&SetElevationL,
|
|
1378 |
editor,
|
|
1379 |
aZ);
|
|
1380 |
|
|
1381 |
DEBUG_INT("TextEditor.cpp - setZPosition -, error=%d", error);
|
|
1382 |
|
|
1383 |
return error;
|
|
1384 |
}
|
|
1385 |
|
|
1386 |
/**
|
|
1387 |
* Local helper function for getting the elevation of a text editor.
|
|
1388 |
*
|
|
1389 |
* @param aEditor The editor.
|
|
1390 |
* @return The size of the editor's content.
|
|
1391 |
*/
|
|
1392 |
LOCAL_C TInt Elevation(MMIDTextEditor* aEditor)
|
|
1393 |
{
|
|
1394 |
return aEditor->Elevation();
|
|
1395 |
}
|
|
1396 |
|
|
1397 |
/*
|
|
1398 |
* Class: com_nokia_mid_ui_TextEditor
|
|
1399 |
* Method: _getZPosition
|
|
1400 |
* Signature: (II)I
|
|
1401 |
*/
|
|
1402 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1getZPosition(
|
|
1403 |
JNIEnv* /* aJniEnv */,
|
|
1404 |
jobject /*aPeer*/,
|
|
1405 |
jint aToolkitHandle,
|
|
1406 |
jint aNativePeerHandle)
|
|
1407 |
{
|
|
1408 |
DEBUG("TextEditor.cpp - getZPosition +");
|
|
1409 |
|
|
1410 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
1411 |
|
|
1412 |
MMIDTextEditor* editor =
|
|
1413 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
1414 |
|
|
1415 |
TInt position = toolkit->Execute(&Elevation, editor);
|
|
1416 |
|
|
1417 |
DEBUG_INT("TextEditor.cpp - getZPosition -, position=%d", position);
|
|
1418 |
|
|
1419 |
return position;
|
|
1420 |
}
|
|
1421 |
|
|
1422 |
|
|
1423 |
/**
|
|
1424 |
* Local helper function for dispoisng text editor native side component.
|
|
1425 |
*
|
|
1426 |
* @param aEditor The editor to be destroyed.
|
|
1427 |
*/
|
|
1428 |
LOCAL_C void Dispose(CMIDToolkit* aToolkit, MMIDTextEditor* aEditor)
|
|
1429 |
{
|
|
1430 |
aToolkit->DisposeObject(aEditor);
|
|
1431 |
}
|
|
1432 |
|
|
1433 |
/*
|
|
1434 |
* Class: com_nokia_mid_ui_TextEditor
|
|
1435 |
* Method: _dispose
|
|
1436 |
* Signature: (II)V
|
|
1437 |
*/
|
|
1438 |
JNIEXPORT void JNICALL Java_com_nokia_mid_ui_TextEditor__1dispose(
|
|
1439 |
JNIEnv* /* aJniEnv */,
|
|
1440 |
jobject /* aPeer */,
|
|
1441 |
jint aToolkitHandle,
|
|
1442 |
jint aNativePeerHandle)
|
|
1443 |
{
|
|
1444 |
DEBUG("TextEditor.cpp - dispose +");
|
|
1445 |
|
|
1446 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
1447 |
|
|
1448 |
MMIDTextEditor* editor =
|
|
1449 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
1450 |
|
|
1451 |
toolkit->ExecuteV(&Dispose, toolkit, editor);
|
|
1452 |
|
|
1453 |
DEBUG("TextEditor.cpp - dispose -");
|
|
1454 |
}
|
|
1455 |
|
|
1456 |
/**
|
|
1457 |
* Local helper function for getting the size of the text editor.
|
|
1458 |
*
|
|
1459 |
* @param aEditor The editor.
|
|
1460 |
* @param aSize On return, contains the new size of the editor.
|
|
1461 |
*/
|
|
1462 |
LOCAL_C void EditorSize(
|
|
1463 |
MMIDTextEditor* aEditor,
|
|
1464 |
TSize* aSize)
|
|
1465 |
{
|
|
1466 |
// Store the size of the text editor.
|
|
1467 |
*aSize = aEditor->EditorSize();
|
|
1468 |
}
|
|
1469 |
|
|
1470 |
/*
|
|
1471 |
* Class: com_nokia_mid_ui_TextEditor
|
|
1472 |
* Method: _getSize
|
|
1473 |
* Signature: (III)V
|
|
1474 |
*/
|
|
1475 |
JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1getSize(
|
|
1476 |
JNIEnv* aJniEnv,
|
|
1477 |
jobject /* aPeer */,
|
|
1478 |
jint aToolkitHandle,
|
|
1479 |
jint aNativePeerHandle,
|
|
1480 |
jintArray aNewSize)
|
|
1481 |
{
|
|
1482 |
DEBUG("TextEditor.cpp - getSize +");
|
|
1483 |
|
|
1484 |
CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
|
|
1485 |
|
|
1486 |
MMIDTextEditor* editor =
|
|
1487 |
MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
|
|
1488 |
|
|
1489 |
TSize size;
|
|
1490 |
|
|
1491 |
toolkit->ExecuteV(&EditorSize, editor, &size);
|
|
1492 |
|
|
1493 |
jint sizeArray[2] = {size.iWidth, size.iHeight};
|
|
1494 |
aJniEnv->SetIntArrayRegion(aNewSize, 0, 2, sizeArray);
|
|
1495 |
|
|
1496 |
DEBUG("TextEditor.cpp - getSize");
|
|
1497 |
return KErrNone;
|
|
1498 |
}
|
|
1499 |
// End of file
|