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