javauis/m2g_qt/src/jni/M2GDocument.cpp
changeset 87 1627c337e51e
parent 80 d6dafc5d983f
equal deleted inserted replaced
80:d6dafc5d983f 87:1627c337e51e
     1 /*
     1 /*
     2 * Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    59     jclass,
    59     jclass,
    60     jint aSvgProxyHandle,
    60     jint aSvgProxyHandle,
    61     jstring aData)
    61     jstring aData)
    62 {
    62 {
    63     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _createDocument - begin");
    63     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _createDocument - begin");
    64     
    64 
    65     TInt handle = M2G_INVALID_HANDLE;
    65     TInt handle = M2G_INVALID_HANDLE;
    66     TInt err    = KM2GNotOk;
    66     TInt err    = KM2GNotOk;
    67     JStringUtils data(*aJni, aData);
    67     JStringUtils data(*aJni, aData);
    68     //RJString data(*aJni, aData);
    68 
    69     TPtrC16* bData = STATIC_CAST(TPtrC16*, &data);
    69     TPtrC16* bData = STATIC_CAST(TPtrC16*, &data);
    70 
    70 
    71     M2G_DO_LOCK
    71     M2G_DO_LOCK
    72     if (aSvgProxyHandle)
    72     if (aSvgProxyHandle)
    73         {
    73     {
    74         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
    74         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
    75         TRAP(err,aProxy->CreateDocumentL(*bData, handle););
    75         TRAP(err,aProxy->CreateDocumentL(*bData, handle););
    76         }
    76     }
    77     M2G_DO_UNLOCK(aJni)
    77     M2G_DO_UNLOCK(aJni)
    78 
    78 
    79     handle = M2GGeneral::CheckErrorCodeAndHandle(aJni, err, handle, M2G_INVALID_HANDLE); 
    79     handle = M2GGeneral::CheckErrorCodeAndHandle(aJni, err, handle, M2G_INVALID_HANDLE);
    80     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GDocument ) _createDocument: %d - end", handle);
    80     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GDocument ) _createDocument: %d - end", handle);
    81     return handle;
    81     return handle;
    82 }
    82 }
    83 
    83 
    84 // -----------------------------------------------------------------------------
    84 // -----------------------------------------------------------------------------
   104     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _createElementNS - begin");
   104     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _createElementNS - begin");
   105 
   105 
   106     // Execute native engine method
   106     // Execute native engine method
   107     TInt handle = M2G_INVALID_HANDLE;
   107     TInt handle = M2G_INVALID_HANDLE;
   108     TInt err = KM2GNotOk;
   108     TInt err = KM2GNotOk;
   109     
   109 
   110     M2G_DO_LOCK
   110     M2G_DO_LOCK
   111     if (aSvgProxyHandle)
   111     if (aSvgProxyHandle)
   112         {
   112     {
   113         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
   113         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
   114         TRAP(err,aProxy->CreateElementNsL(
   114         TRAP(err,aProxy->CreateElementNsL(
   115                 aType,
   115                  aType,
   116                 aDocumentHandle,
   116                  aDocumentHandle,
   117                 handle);    );
   117                  handle););
   118         
   118 
   119         }
   119     }
   120     M2G_DO_UNLOCK(aJni) 
   120     M2G_DO_UNLOCK(aJni)
   121     
   121 
   122     M2GGeneral::CheckErrorCode(aJni, err);
   122     M2GGeneral::CheckErrorCode(aJni, err);
   123     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GDocument ) _createElementNS: %d - end", handle);
   123     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GDocument ) _createElementNS: %d - end", handle);
   124     return handle;
   124     return handle;
   125 }
   125 }
   126 
   126 
   137 JNIEXPORT void JNICALL
   137 JNIEXPORT void JNICALL
   138 Java_com_nokia_microedition_m2g_M2GDocument__1deleteDocument(
   138 Java_com_nokia_microedition_m2g_M2GDocument__1deleteDocument(
   139     JNIEnv* aJni,
   139     JNIEnv* aJni,
   140     jclass,
   140     jclass,
   141     jint aSvgProxyHandle,
   141     jint aSvgProxyHandle,
   142     jint aDocumentHandle )
   142     jint aDocumentHandle)
   143 {
   143 {
   144     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _deleteDocument - begin");
   144     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _deleteDocument - begin");
   145     TInt err = KM2GNotOk;
   145     TInt err = KM2GNotOk;
   146     
   146 
   147     M2G_DO_LOCK
   147     M2G_DO_LOCK
   148     // Extract the SVGProxy handle
   148     // Extract the SVGProxy handle
   149     if (aSvgProxyHandle)
   149     if (aSvgProxyHandle)
   150         {
   150     {
   151         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
   151         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
   152         TRAP(err,aProxy->DeleteDocumentL(aDocumentHandle););
   152         TRAP(err,aProxy->DeleteDocumentL(aDocumentHandle););
   153         }
   153     }
   154     M2G_DO_UNLOCK(aJni)
   154     M2G_DO_UNLOCK(aJni)
   155 
   155 
   156     M2GGeneral::CheckErrorCode(aJni, err);
   156     M2GGeneral::CheckErrorCode(aJni, err);
   157     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _deleteDocument - end");
   157     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _deleteDocument - end");
   158 }
   158 }
   178     jstring aId)
   178     jstring aId)
   179 {
   179 {
   180     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _getElementById - begin");
   180     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _getElementById - begin");
   181     TInt handle = M2G_INVALID_HANDLE;
   181     TInt handle = M2G_INVALID_HANDLE;
   182     TInt err    = KM2GNotOk;
   182     TInt err    = KM2GNotOk;
   183     //RJString id(*aJni, aId);
   183 
   184     JStringUtils id(*aJni, aId);
   184     JStringUtils id(*aJni, aId);
   185     TPtrC16* lId = STATIC_CAST(TPtrC16*, &id);
   185     TPtrC16* lId = STATIC_CAST(TPtrC16*, &id);
   186 
   186 
   187     M2G_DO_LOCK
   187     M2G_DO_LOCK
   188     if (aSvgProxyHandle)
   188     if (aSvgProxyHandle)
   189         {
   189     {
   190         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
   190         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
   191         TRAP(err,aProxy->GetElementByIdL(aDocumentHandle, *lId, handle););
   191         TRAP(err,aProxy->GetElementByIdL(aDocumentHandle, *lId, handle););
   192         }
   192     }
   193     M2G_DO_UNLOCK(aJni)
   193     M2G_DO_UNLOCK(aJni)
   194 
   194 
   195     M2GGeneral::CheckErrorCode(aJni, err);
   195     M2GGeneral::CheckErrorCode(aJni, err);
   196 
   196 
   197     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GDocument ) _getElementById: %d - end", handle);
   197     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GDocument ) _getElementById: %d - end", handle);
   216     jint aDocumentHandle)
   216     jint aDocumentHandle)
   217 {
   217 {
   218     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _getViewportHeight - begin");
   218     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _getViewportHeight - begin");
   219     TInt err    = KM2GNotOk;
   219     TInt err    = KM2GNotOk;
   220     TInt height = 0;
   220     TInt height = 0;
   221     
   221 
   222     M2G_DO_LOCK
   222     M2G_DO_LOCK
   223     if (aSvgProxyHandle)
   223     if (aSvgProxyHandle)
   224         {
   224     {
   225         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
   225         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
   226         TRAP(err,aProxy->GetViewportHeightL(aDocumentHandle, height););
   226         TRAP(err,aProxy->GetViewportHeightL(aDocumentHandle, height););
   227         }
   227     }
   228     M2G_DO_UNLOCK(aJni)
   228     M2G_DO_UNLOCK(aJni)
   229 
   229 
   230     M2GGeneral::CheckErrorCode(aJni, err);
   230     M2GGeneral::CheckErrorCode(aJni, err);
   231 
   231 
   232     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GDocument ) _getViewportHeight: %d - end", height);
   232     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GDocument ) _getViewportHeight: %d - end", height);
   253     jint aDocumentHandle)
   253     jint aDocumentHandle)
   254 {
   254 {
   255     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _getViewportWidth - begin");
   255     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _getViewportWidth - begin");
   256     TInt   err = KM2GNotOk;
   256     TInt   err = KM2GNotOk;
   257     TInt width = 0;
   257     TInt width = 0;
   258     
   258 
   259     M2G_DO_LOCK
   259     M2G_DO_LOCK
   260     if (aSvgProxyHandle)
   260     if (aSvgProxyHandle)
   261         {
   261     {
   262         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
   262         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
   263         TRAP(err,aProxy->GetViewportWidthL(aDocumentHandle, width););
   263         TRAP(err,aProxy->GetViewportWidthL(aDocumentHandle, width););
   264         }
   264     }
   265     M2G_DO_UNLOCK(aJni)
   265     M2G_DO_UNLOCK(aJni)
   266 
   266 
   267     M2GGeneral::CheckErrorCode(aJni, err);
   267     M2GGeneral::CheckErrorCode(aJni, err);
   268 
   268 
   269     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GDocument ) _getViewportWidth: %d - end", width);
   269     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GDocument ) _getViewportWidth: %d - end", width);
   293     TInt isElementInDom = -1;
   293     TInt isElementInDom = -1;
   294     TInt            err = KM2GNotOk;
   294     TInt            err = KM2GNotOk;
   295 
   295 
   296     M2G_DO_LOCK
   296     M2G_DO_LOCK
   297     if (aSvgProxyHandle)
   297     if (aSvgProxyHandle)
   298         {
   298     {
   299             MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
   299         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
   300             TRAP(err,aProxy->IsElementInDomL(
   300         TRAP(err,aProxy->IsElementInDomL(
   301                 aDocumentHandle, aElementHandle, isElementInDom););
   301                  aDocumentHandle, aElementHandle, isElementInDom););
   302         }
   302     }
   303     M2G_DO_UNLOCK(aJni)
   303     M2G_DO_UNLOCK(aJni)
   304 
   304 
   305     M2GGeneral::CheckErrorCode(aJni, err);
   305     M2GGeneral::CheckErrorCode(aJni, err);
   306 
   306 
   307     M2G_DEBUG_1("M2G_DEBUG: JNI _isElementInDOM: %d - end", isElementInDom);
   307     M2G_DEBUG_1("M2G_DEBUG: JNI _isElementInDOM: %d - end", isElementInDom);
   336     TInt err = KM2GNotOk;
   336     TInt err = KM2GNotOk;
   337     TPtrC8 lResData8;
   337     TPtrC8 lResData8;
   338     jbyte* resBytes = NULL;
   338     jbyte* resBytes = NULL;
   339 
   339 
   340     if (aResourceData)
   340     if (aResourceData)
   341         {
   341     {
   342         resBytes  = aJni->GetByteArrayElements(aResourceData, NULL);
   342         resBytes  = aJni->GetByteArrayElements(aResourceData, NULL);
   343         lResData8.Set(REINTERPRET_CAST(TUint8*, resBytes), aJni->GetArrayLength(aResourceData));
   343         lResData8.Set(REINTERPRET_CAST(TUint8*, resBytes), aJni->GetArrayLength(aResourceData));
   344         }
   344     }
   345 
   345 
   346     TInt completed = -1;
   346     TInt completed = -1;
   347     TPtrC16* pUri = STATIC_CAST(TPtrC16*, &uri);
   347     TPtrC16* pUri = STATIC_CAST(TPtrC16*, &uri);
   348     
   348 
   349     M2G_DO_LOCK
   349     M2G_DO_LOCK
   350     
   350 
   351     if (aSvgProxyHandle)
   351     if (aSvgProxyHandle)
   352         {
   352     {
   353         
   353 
   354         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
   354         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
   355         
   355 
   356         TRAP(err,    aProxy->RequestCompletedL(
   356         TRAP(err,    aProxy->RequestCompletedL(
   357                 aDocumentHandle,
   357                  aDocumentHandle,
   358                 *pUri,
   358                  *pUri,
   359                 lResData8,
   359                  lResData8,
   360                 completed););
   360                  completed););
   361         }
   361     }
   362     M2G_DO_UNLOCK(aJni)
   362     M2G_DO_UNLOCK(aJni)
   363 
   363 
   364     M2GGeneral::CheckErrorCode(aJni, err);
   364     M2GGeneral::CheckErrorCode(aJni, err);
   365     if (aResourceData)
   365     if (aResourceData)
   366         {
   366     {
   367         aJni->ReleaseByteArrayElements(aResourceData, resBytes, JNI_ABORT);   // don't copy back
   367         aJni->ReleaseByteArrayElements(aResourceData, resBytes, JNI_ABORT);   // don't copy back
   368         }
   368     }
   369 
   369 
   370     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GDocument ) _requestCompleted: %d - end", completed);
   370     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GDocument ) _requestCompleted: %d - end", completed);
   371 
   371 
   372     return completed;
   372     return completed;
   373 }
   373 }
   391     jint aDocumentHandle,
   391     jint aDocumentHandle,
   392     jint aHeight)
   392     jint aHeight)
   393 {
   393 {
   394     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _setViewportHeight - begin");
   394     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _setViewportHeight - begin");
   395     TInt err = KM2GNotOk;
   395     TInt err = KM2GNotOk;
   396     
   396 
   397     M2G_DO_LOCK
   397     M2G_DO_LOCK
   398     if (aSvgProxyHandle)
   398     if (aSvgProxyHandle)
   399         {
   399     {
   400         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
   400         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
   401         TRAP(err,aProxy->SetViewportHeightL(
   401         TRAP(err,aProxy->SetViewportHeightL(
   402                 (TM2GSvgDocumentHandle)aDocumentHandle, aHeight););
   402                  (TM2GSvgDocumentHandle)aDocumentHandle, aHeight););
   403         }
   403     }
   404     M2G_DO_UNLOCK(aJni)
   404     M2G_DO_UNLOCK(aJni)
   405     
   405 
   406     M2GGeneral::CheckErrorCode(aJni, err);
   406     M2GGeneral::CheckErrorCode(aJni, err);
   407 
   407 
   408     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _setViewportHeight - end");
   408     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _setViewportHeight - end");
   409 }
   409 }
   410 // -----------------------------------------------------------------------------
   410 // -----------------------------------------------------------------------------
   426     jint aDocumentHandle,
   426     jint aDocumentHandle,
   427     jint aWidth)
   427     jint aWidth)
   428 {
   428 {
   429     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _setViewportWidth - begin");
   429     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _setViewportWidth - begin");
   430     TInt err = KM2GNotOk;
   430     TInt err = KM2GNotOk;
   431  
   431 
   432     M2G_DO_LOCK
   432     M2G_DO_LOCK
   433     if (aSvgProxyHandle)
   433     if (aSvgProxyHandle)
   434         {
   434     {
   435             MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
   435         MM2GSVGProxy* aProxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
   436             TRAP(err,    aProxy->SetViewportWidthL(
   436         TRAP(err,    aProxy->SetViewportWidthL(
   437                     (TM2GSvgDocumentHandle)aDocumentHandle, aWidth););
   437                  (TM2GSvgDocumentHandle)aDocumentHandle, aWidth););
   438         }
   438     }
   439     M2G_DO_UNLOCK(aJni)
   439     M2G_DO_UNLOCK(aJni)
   440     
   440 
   441     M2GGeneral::CheckErrorCode(aJni, err);
   441     M2GGeneral::CheckErrorCode(aJni, err);
   442     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _setViewportWidth - end");
   442     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GDocument ) _setViewportWidth - end");
   443 }
   443 }
   444 
   444 
   445 M2G_NS_END
   445 M2G_NS_END