javauis/m2g_qt/src/jni/M2GDocument.cpp
changeset 80 d6dafc5d983f
child 87 1627c337e51e
equal deleted inserted replaced
78:71ad690e91f5 80:d6dafc5d983f
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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 methods
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "com_nokia_microedition_m2g_M2GDocument.h"
       
    20 #include "MM2GSVGProxy.h"
       
    21 
       
    22 
       
    23 M2G_NS_START
       
    24 
       
    25 // EXTERNAL DATA STRUCTURES
       
    26 
       
    27 // EXTERNAL FUNCTION PROTOTYPES
       
    28 
       
    29 // CONSTANTS
       
    30 
       
    31 // MACROS
       
    32 
       
    33 // LOCAL CONSTANTS AND MACROS
       
    34 
       
    35 // MODULE DATA STRUCTURES
       
    36 
       
    37 // LOCAL FUNCTION PROTOTYPES
       
    38 
       
    39 // FORWARD DECLARATIONS
       
    40 
       
    41 // CLASS DECLARATION
       
    42 
       
    43 // ================================ FUNCTIONS ==================================
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // Java_com_nokia_microedition_m2g_M2GDocument::_createDocument
       
    47 // -----------------------------------------------------------------------------
       
    48 /**
       
    49  * Calls MM2GSVGProxy::CreateDocumentL method.
       
    50  * @since Series S60 3.0
       
    51  * @param aProxy Proxy instance.
       
    52  * @param aData Document data
       
    53  * @param aHandle Document handle to be returned
       
    54  * @throws Exception if not ok
       
    55 */
       
    56 JNIEXPORT jint JNICALL
       
    57 Java_com_nokia_microedition_m2g_M2GDocument__1createDocument(
       
    58     JNIEnv* aJni,
       
    59     jclass,
       
    60     jint aSvgProxyHandle,
       
    61     jstring aData)
       
    62 {
       
    63     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _createDocument - begin");
       
    64     
       
    65     TInt handle = M2G_INVALID_HANDLE;
       
    66     TInt err    = KM2GNotOk;
       
    67     JStringUtils data(*aJni, aData);
       
    68     //RJString data(*aJni, aData);
       
    69     TPtrC16* bData = STATIC_CAST(TPtrC16*, &data);
       
    70 
       
    71     M2G_DO_LOCK
       
    72     if (aSvgProxyHandle)
       
    73         {
       
    74         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
       
    75         TRAP(err,aProxy->CreateDocumentL(*bData, handle););
       
    76         }
       
    77     M2G_DO_UNLOCK(aJni)
       
    78 
       
    79     handle = M2GGeneral::CheckErrorCodeAndHandle(aJni, err, handle, M2G_INVALID_HANDLE); 
       
    80     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GDocument ) _createDocument: %d - end", handle);
       
    81     return handle;
       
    82 }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // Java_com_nokia_microedition_m2g_M2GDocument::_createElementNS
       
    86 // -----------------------------------------------------------------------------
       
    87 /**
       
    88  * Calls MM2GSVGProxy::CreateElementNsL method.
       
    89  * @since Series S60 3.0
       
    90  * @param aProxy Proxy instance.
       
    91  * @param aType Element type id.
       
    92  * @param aDocumentHandle Document handle.
       
    93  * @param aHandle Element handle to be returned
       
    94  * @throws Exception if not ok
       
    95  */
       
    96 JNIEXPORT jint JNICALL
       
    97 Java_com_nokia_microedition_m2g_M2GDocument__1createElementNS(
       
    98     JNIEnv* aJni,
       
    99     jclass,
       
   100     jint aSvgProxyHandle,
       
   101     jshort aType,
       
   102     jint aDocumentHandle)
       
   103 {
       
   104     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _createElementNS - begin");
       
   105 
       
   106     // Execute native engine method
       
   107     TInt handle = M2G_INVALID_HANDLE;
       
   108     TInt err = KM2GNotOk;
       
   109     
       
   110     M2G_DO_LOCK
       
   111     if (aSvgProxyHandle)
       
   112         {
       
   113         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
       
   114         TRAP(err,aProxy->CreateElementNsL(
       
   115                 aType,
       
   116                 aDocumentHandle,
       
   117                 handle);    );
       
   118         
       
   119         }
       
   120     M2G_DO_UNLOCK(aJni) 
       
   121     
       
   122     M2GGeneral::CheckErrorCode(aJni, err);
       
   123     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GDocument ) _createElementNS: %d - end", handle);
       
   124     return handle;
       
   125 }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // Java_com_nokia_microedition_m2g_M2GDocument::_deleteDocument
       
   129 // -----------------------------------------------------------------------------
       
   130 /**
       
   131  * Calls MM2GSVGProxy::DeleteDocumentL method.
       
   132  * @since Series S60 3.0
       
   133  * @param aProxy Proxy instance.
       
   134  * @param aDocumentHandle Document handle
       
   135  * @throws Exception if not ok
       
   136  */
       
   137 JNIEXPORT void JNICALL
       
   138 Java_com_nokia_microedition_m2g_M2GDocument__1deleteDocument(
       
   139     JNIEnv* aJni,
       
   140     jclass,
       
   141     jint aSvgProxyHandle,
       
   142     jint aDocumentHandle )
       
   143 {
       
   144     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _deleteDocument - begin");
       
   145     TInt err = KM2GNotOk;
       
   146     
       
   147     M2G_DO_LOCK
       
   148     // Extract the SVGProxy handle
       
   149     if (aSvgProxyHandle)
       
   150         {
       
   151         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
       
   152         TRAP(err,aProxy->DeleteDocumentL(aDocumentHandle););
       
   153         }
       
   154     M2G_DO_UNLOCK(aJni)
       
   155 
       
   156     M2GGeneral::CheckErrorCode(aJni, err);
       
   157     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _deleteDocument - end");
       
   158 }
       
   159 
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // Java_com_nokia_microedition_m2g_M2GDocument::_getElementById
       
   163 // -----------------------------------------------------------------------------
       
   164 /**
       
   165  * Calls MM2GSVGProxy::GetElementByIdL method.
       
   166  * @since Series S60 3.0
       
   167  * @param aProxy Proxy instance.
       
   168  * @param aDocumentHandle Document pointer.
       
   169  * @param aId Element ID.
       
   170  * @param aHandle Element handle to be returned.
       
   171  */
       
   172 JNIEXPORT jint JNICALL
       
   173 Java_com_nokia_microedition_m2g_M2GDocument__1getElementById(
       
   174     JNIEnv* aJni,
       
   175     jclass,
       
   176     jint aSvgProxyHandle,
       
   177     jint aDocumentHandle,
       
   178     jstring aId)
       
   179 {
       
   180     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _getElementById - begin");
       
   181     TInt handle = M2G_INVALID_HANDLE;
       
   182     TInt err    = KM2GNotOk;
       
   183     //RJString id(*aJni, aId);
       
   184     JStringUtils id(*aJni, aId);
       
   185     TPtrC16* lId = STATIC_CAST(TPtrC16*, &id);
       
   186 
       
   187     M2G_DO_LOCK
       
   188     if (aSvgProxyHandle)
       
   189         {
       
   190         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
       
   191         TRAP(err,aProxy->GetElementByIdL(aDocumentHandle, *lId, handle););
       
   192         }
       
   193     M2G_DO_UNLOCK(aJni)
       
   194 
       
   195     M2GGeneral::CheckErrorCode(aJni, err);
       
   196 
       
   197     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GDocument ) _getElementById: %d - end", handle);
       
   198     return handle;
       
   199 }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // Java_com_nokia_microedition_m2g_M2GDocument::_getViewportHeight
       
   203 // -----------------------------------------------------------------------------
       
   204 /**
       
   205  * Calls MM2GSVGProxy::GetViewportHeightL method.
       
   206  * @since Series S60 3.0
       
   207  * @param aProxy Proxy instance.
       
   208  * @param aDocumentHandle Document pointer.
       
   209  * @param aHeight Height to be returned.
       
   210  */
       
   211 JNIEXPORT jint JNICALL
       
   212 Java_com_nokia_microedition_m2g_M2GDocument__1getViewportHeight(
       
   213     JNIEnv* aJni,
       
   214     jclass,
       
   215     jint aSvgProxyHandle,
       
   216     jint aDocumentHandle)
       
   217 {
       
   218     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _getViewportHeight - begin");
       
   219     TInt err    = KM2GNotOk;
       
   220     TInt height = 0;
       
   221     
       
   222     M2G_DO_LOCK
       
   223     if (aSvgProxyHandle)
       
   224         {
       
   225         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
       
   226         TRAP(err,aProxy->GetViewportHeightL(aDocumentHandle, height););
       
   227         }
       
   228     M2G_DO_UNLOCK(aJni)
       
   229 
       
   230     M2GGeneral::CheckErrorCode(aJni, err);
       
   231 
       
   232     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GDocument ) _getViewportHeight: %d - end", height);
       
   233     return height;
       
   234 }
       
   235 // -----------------------------------------------------------------------------
       
   236 // Java_com_nokia_microedition_m2g_M2GDocument::_getViewportWidth
       
   237 // -----------------------------------------------------------------------------
       
   238 /**
       
   239  * Calls MM2GSVGProxy::GetViewportWidthL method.
       
   240  * @since Series S60 3.0
       
   241  * @param aProxy Proxy instance.
       
   242  * @param aDocumentHandle Document pointer.
       
   243  * @param aWidth Width to be returned.
       
   244  * Class: com_nokia_microedition_m2g_M2GDocument
       
   245  * Method: _getViewportWidth
       
   246  * Signature:
       
   247  */
       
   248 JNIEXPORT jint JNICALL
       
   249 Java_com_nokia_microedition_m2g_M2GDocument__1getViewportWidth(
       
   250     JNIEnv* aJni,
       
   251     jclass,
       
   252     jint aSvgProxyHandle,
       
   253     jint aDocumentHandle)
       
   254 {
       
   255     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _getViewportWidth - begin");
       
   256     TInt   err = KM2GNotOk;
       
   257     TInt width = 0;
       
   258     
       
   259     M2G_DO_LOCK
       
   260     if (aSvgProxyHandle)
       
   261         {
       
   262         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
       
   263         TRAP(err,aProxy->GetViewportWidthL(aDocumentHandle, width););
       
   264         }
       
   265     M2G_DO_UNLOCK(aJni)
       
   266 
       
   267     M2GGeneral::CheckErrorCode(aJni, err);
       
   268 
       
   269     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GDocument ) _getViewportWidth: %d - end", width);
       
   270     return width;
       
   271 }
       
   272 
       
   273 // -----------------------------------------------------------------------------
       
   274 // Java_com_nokia_microedition_m2g_M2GDocument::_isElementInDom
       
   275 // -----------------------------------------------------------------------------
       
   276 /**
       
   277  * Calls MM2GSVGProxy::IsElementInDomL method.
       
   278  * @since Series S60 3.0
       
   279  * @param aProxy Proxy instance.
       
   280  * @param aDocumentHandle Document pointer.
       
   281  * @param aElementHandle Element pointer.
       
   282  * @param aIsElementInDom Result
       
   283  */
       
   284 JNIEXPORT jint JNICALL
       
   285 Java_com_nokia_microedition_m2g_M2GDocument__1isElementInDOM(
       
   286     JNIEnv* aJni,
       
   287     jclass,
       
   288     jint aSvgProxyHandle,
       
   289     jint aDocumentHandle,
       
   290     jint aElementHandle)
       
   291 {
       
   292     M2G_DEBUG_0("M2G_DEBUG: JNI _isElementInDOM - begin");
       
   293     TInt isElementInDom = -1;
       
   294     TInt            err = KM2GNotOk;
       
   295 
       
   296     M2G_DO_LOCK
       
   297     if (aSvgProxyHandle)
       
   298         {
       
   299             MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
       
   300             TRAP(err,aProxy->IsElementInDomL(
       
   301                 aDocumentHandle, aElementHandle, isElementInDom););
       
   302         }
       
   303     M2G_DO_UNLOCK(aJni)
       
   304 
       
   305     M2GGeneral::CheckErrorCode(aJni, err);
       
   306 
       
   307     M2G_DEBUG_1("M2G_DEBUG: JNI _isElementInDOM: %d - end", isElementInDom);
       
   308     return isElementInDom;
       
   309 }
       
   310 
       
   311 // -----------------------------------------------------------------------------
       
   312 // Java_com_nokia_microedition_m2g_M2GDocument::_requestCompleted
       
   313 // -----------------------------------------------------------------------------
       
   314 /**
       
   315  * Calls MM2GSVGProxy::RequestCompletedL method.
       
   316  * @since Series S60 3.0
       
   317  * @param aProxy Proxy instance.
       
   318  * @param aDocumentHandle Document pointer.
       
   319  * @param aURI Resource uri
       
   320  * @param aResourceData Resource data
       
   321  * @param aCompleted Result
       
   322  */
       
   323 JNIEXPORT jint JNICALL
       
   324 Java_com_nokia_microedition_m2g_M2GDocument__1requestCompleted(
       
   325     JNIEnv* aJni,
       
   326     jclass,
       
   327     jint aSvgProxyHandle,
       
   328     jint aDocumentHandle,
       
   329     jstring aURI,
       
   330     jbyteArray aResourceData)
       
   331 {
       
   332     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _requestCompleted - begin");
       
   333 
       
   334     //RJString uri(*aJni, aURI);
       
   335     JStringUtils uri(*aJni, aURI);
       
   336     TInt err = KM2GNotOk;
       
   337     TPtrC8 lResData8;
       
   338     jbyte* resBytes = NULL;
       
   339 
       
   340     if (aResourceData)
       
   341         {
       
   342         resBytes  = aJni->GetByteArrayElements(aResourceData, NULL);
       
   343         lResData8.Set(REINTERPRET_CAST(TUint8*, resBytes), aJni->GetArrayLength(aResourceData));
       
   344         }
       
   345 
       
   346     TInt completed = -1;
       
   347     TPtrC16* pUri = STATIC_CAST(TPtrC16*, &uri);
       
   348     
       
   349     M2G_DO_LOCK
       
   350     
       
   351     if (aSvgProxyHandle)
       
   352         {
       
   353         
       
   354         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
       
   355         
       
   356         TRAP(err,    aProxy->RequestCompletedL(
       
   357                 aDocumentHandle,
       
   358                 *pUri,
       
   359                 lResData8,
       
   360                 completed););
       
   361         }
       
   362     M2G_DO_UNLOCK(aJni)
       
   363 
       
   364     M2GGeneral::CheckErrorCode(aJni, err);
       
   365     if (aResourceData)
       
   366         {
       
   367         aJni->ReleaseByteArrayElements(aResourceData, resBytes, JNI_ABORT);   // don't copy back
       
   368         }
       
   369 
       
   370     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GDocument ) _requestCompleted: %d - end", completed);
       
   371 
       
   372     return completed;
       
   373 }
       
   374 
       
   375 // -----------------------------------------------------------------------------
       
   376 // Java_com_nokia_microedition_m2g_M2GDocument::_setViewportHeight
       
   377 // -----------------------------------------------------------------------------
       
   378 /**
       
   379  * Calls MM2GSVGProxy::SetViewportHeightL method.
       
   380  * @since Series S60 3.0
       
   381  * @param aProxy Proxy instance.
       
   382  * @param aDocumentHandle Document pointer.
       
   383  * @param aHeight Height
       
   384  * JNI method
       
   385  */
       
   386 JNIEXPORT void JNICALL
       
   387 Java_com_nokia_microedition_m2g_M2GDocument__1setViewportHeight(
       
   388     JNIEnv* aJni,
       
   389     jclass,
       
   390     jint aSvgProxyHandle,
       
   391     jint aDocumentHandle,
       
   392     jint aHeight)
       
   393 {
       
   394     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _setViewportHeight - begin");
       
   395     TInt err = KM2GNotOk;
       
   396     
       
   397     M2G_DO_LOCK
       
   398     if (aSvgProxyHandle)
       
   399         {
       
   400         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
       
   401         TRAP(err,aProxy->SetViewportHeightL(
       
   402                 (TM2GSvgDocumentHandle)aDocumentHandle, aHeight););
       
   403         }
       
   404     M2G_DO_UNLOCK(aJni)
       
   405     
       
   406     M2GGeneral::CheckErrorCode(aJni, err);
       
   407 
       
   408     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _setViewportHeight - end");
       
   409 }
       
   410 // -----------------------------------------------------------------------------
       
   411 // Java_com_nokia_microedition_m2g_M2GDocument::_setViewportWidth
       
   412 // -----------------------------------------------------------------------------
       
   413 /**
       
   414  * Calls MM2GSVGProxy::SetViewportWidthL method.
       
   415  * @since Series S60 3.0
       
   416  * @param aProxy Proxy instance.
       
   417  * @param aDocumentHandle Document pointer.
       
   418  * @param aWidth Width
       
   419  * JNI method
       
   420  */
       
   421 JNIEXPORT void JNICALL
       
   422 Java_com_nokia_microedition_m2g_M2GDocument__1setViewportWidth(
       
   423     JNIEnv* aJni,
       
   424     jclass,
       
   425     jint aSvgProxyHandle,
       
   426     jint aDocumentHandle,
       
   427     jint aWidth)
       
   428 {
       
   429     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _setViewportWidth - begin");
       
   430     TInt err = KM2GNotOk;
       
   431  
       
   432     M2G_DO_LOCK
       
   433     if (aSvgProxyHandle)
       
   434         {
       
   435             MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
       
   436             TRAP(err,    aProxy->SetViewportWidthL(
       
   437                     (TM2GSvgDocumentHandle)aDocumentHandle, aWidth););
       
   438         }
       
   439     M2G_DO_UNLOCK(aJni)
       
   440     
       
   441     M2GGeneral::CheckErrorCode(aJni, err);
       
   442     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _setViewportWidth - end");
       
   443 }
       
   444 
       
   445 M2G_NS_END