javauis/lcdui_akn/javalcdui/src.nokialcdui/TextEditor.cpp
branchRCL_3
changeset 23 e5618cc85d74
parent 14 04becd199f91
equal deleted inserted replaced
21:4376525cdefb 23:e5618cc85d74
    90     jobject aPeer,
    90     jobject aPeer,
    91     TInt* aNativePeerHandle,
    91     TInt* aNativePeerHandle,
    92     TInt aMaxSize,
    92     TInt aMaxSize,
    93     TInt aWidth,
    93     TInt aWidth,
    94     TInt aHeight,
    94     TInt aHeight,
    95     TBool aHeightInRows,
    95     TBool aHeightInRows)
    96     TSize* aSize)
       
    97 {
    96 {
    98     // Get LCDUI component factory.
    97     // Get LCDUI component factory.
    99     MMIDComponentFactory* factory = aToolkit->ComponentFactory();
    98     MMIDComponentFactory* factory = aToolkit->ComponentFactory();
   100 
    99 
   101     // Create new text editor component.
   100     // Create new text editor component.
   108     // Register component to the LCDUI.
   107     // Register component to the LCDUI.
   109     *aNativePeerHandle = aToolkit->RegisterComponentL(textEditor, aPeer);
   108     *aNativePeerHandle = aToolkit->RegisterComponentL(textEditor, aPeer);
   110 
   109 
   111     // Component can be popped from the cleanup stack.
   110     // Component can be popped from the cleanup stack.
   112     CleanupPopComponent(textEditor);
   111     CleanupPopComponent(textEditor);
   113 
       
   114     // Store the size of the text editor.
       
   115     *aSize = textEditor->EditorSize();
       
   116 }
   112 }
   117 
   113 
   118 /*
   114 /*
   119  * Class:     com_nokia_mid_ui_TextEditor
   115  * Class:     com_nokia_mid_ui_TextEditor
   120  * Method:    _createNativePeer
   116  * Method:    _createNativePeer
   125     jobject aPeer,
   121     jobject aPeer,
   126     jint aToolkitHandle,
   122     jint aToolkitHandle,
   127     jint aMaxSize,
   123     jint aMaxSize,
   128     jint aWidth,
   124     jint aWidth,
   129     jint aHeight,
   125     jint aHeight,
   130     jboolean aHeightInRows,
   126     jboolean aHeightInRows)
   131     jintArray aSize)
       
   132 {
   127 {
   133     DEBUG("TextEditor.cpp - createNativePeer +");
   128     DEBUG("TextEditor.cpp - createNativePeer +");
   134 
   129 
   135     CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
   130     CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
   136 
   131 
   137     jobject peer = aJniEnv->NewWeakGlobalRef(aPeer);
   132     jobject peer = aJniEnv->NewWeakGlobalRef(aPeer);
   138     TInt handle = -1;
   133     TInt handle = -1;
   139     TSize size;
       
   140 
   134 
   141     TInt error = toolkit->ExecuteTrap(
   135     TInt error = toolkit->ExecuteTrap(
   142                      &CreateNativePeerL,
   136                      &CreateNativePeerL,
   143                      toolkit,
   137                      toolkit,
   144                      peer,
   138                      peer,
   145                      &handle,
   139                      &handle,
   146                      aMaxSize,
   140                      aMaxSize,
   147                      aWidth,
   141                      aWidth,
   148                      aHeight,
   142                      aHeight,
   149                      (TBool)aHeightInRows,
   143                      (TBool)aHeightInRows);
   150                      &size);
   144 
   151 
   145     if (error != KErrNone)
   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     {
   146     {
   163         // Global reference must be removed at this point if construction
   147         // Global reference must be removed at this point if construction
   164         // failed for some reason.
   148         // failed for some reason.
   165         aJniEnv->DeleteWeakGlobalRef(static_cast< jweak >(peer));
   149         aJniEnv->DeleteWeakGlobalRef(static_cast< jweak >(peer));
   166     }
   150     }
   434 
   418 
   435     return KErrNone;
   419     return KErrNone;
   436 }
   420 }
   437 
   421 
   438 /**
   422 /**
   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
   423  * Local helper function for setting the focus state of a text editor
   479  *
   424  *
   480  * @param aTextEditor The text editor object to be modified.
   425  * @param aTextEditor The text editor object to be modified.
   481  * @param aFocused The focus status of the text editor to be set.
   426  * @param aFocused The focus status of the text editor to be set.
   482  */
   427  */
  1308 /**
  1253 /**
  1309  * Local helper function for setting the font to text editor.
  1254  * Local helper function for setting the font to text editor.
  1310  *
  1255  *
  1311  * @param aEditor The editor.
  1256  * @param aEditor The editor.
  1312  * @param aFont The font to be set.
  1257  * @param aFont The font to be set.
  1313  * @param aSize On return, contains the new size of the editor.
       
  1314  */
  1258  */
  1315 LOCAL_C void SetFontL(
  1259 LOCAL_C void SetFontL(
  1316     MMIDTextEditor* aEditor,
  1260     MMIDTextEditor* aEditor,
  1317     MMIDFont* aFont,
  1261     MMIDFont* aFont)
  1318     TSize* aSize)
       
  1319 {
  1262 {
  1320     aEditor->SetFontL(aFont);
  1263     aEditor->SetFontL(aFont);
  1321 
       
  1322     // Store the size of the text editor.
       
  1323     *aSize = aEditor->EditorSize();
       
  1324 }
  1264 }
  1325 
  1265 
  1326 /*
  1266 /*
  1327  * Class:     com_nokia_mid_ui_TextEditor
  1267  * Class:     com_nokia_mid_ui_TextEditor
  1328  * Method:    _setFont
  1268  * Method:    _setFont
  1329  * Signature: (III)I
  1269  * Signature: (III)I
  1330  */
  1270  */
  1331 JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1setFont(
  1271 JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_TextEditor__1setFont(
  1332     JNIEnv* aJniEnv,
  1272     JNIEnv* /* aJniEnv */,
  1333     jobject /* aPeer */,
  1273     jobject /* aPeer */,
  1334     jint aToolkitHandle,
  1274     jint aToolkitHandle,
  1335     jint aNativePeerHandle,
  1275     jint aNativePeerHandle,
  1336     jint aFontHandle,
  1276     jint aFontHandle)
  1337     jintArray aNewSize)
       
  1338 {
  1277 {
  1339     DEBUG("TextEditor.cpp - setFont +");
  1278     DEBUG("TextEditor.cpp - setFont +");
  1340 
  1279 
  1341     CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
  1280     CMIDToolkit* toolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
  1342 
  1281 
  1343     MMIDTextEditor* editor =
  1282     MMIDTextEditor* editor =
  1344         MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
  1283         MIDUnhandObject< MMIDTextEditor >(aNativePeerHandle);
  1345 
  1284 
  1346     MMIDFont* font = MIDUnhandObject< MMIDFont >(aFontHandle);
  1285     MMIDFont* font = MIDUnhandObject< MMIDFont >(aFontHandle);
  1347     TSize size;
       
  1348 
  1286 
  1349     TInt error = toolkit->ExecuteTrap(
  1287     TInt error = toolkit->ExecuteTrap(
  1350                      &SetFontL,
  1288                      &SetFontL,
  1351                      editor,
  1289                      editor,
  1352                      font,
  1290                      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 
  1291 
  1364     DEBUG_INT("TextEditor.cpp - setFont -, error=%d", error);
  1292     DEBUG_INT("TextEditor.cpp - setFont -, error=%d", error);
  1365 
  1293 
  1366     return error;
  1294     return error;
  1367 }
  1295 }
  1523     toolkit->ExecuteV(&Dispose, toolkit, editor);
  1451     toolkit->ExecuteV(&Dispose, toolkit, editor);
  1524 
  1452 
  1525     DEBUG("TextEditor.cpp - dispose -");
  1453     DEBUG("TextEditor.cpp - dispose -");
  1526 }
  1454 }
  1527 
  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 }
  1528 // End of file
  1499 // End of file