javauis/eswt_qt/org.eclipse.swt/Eclipse_SWT_PI/qt/library/os.cpp
changeset 35 85266cc22c7f
parent 26 dc7c549001d5
child 47 f40128debb5d
child 49 35baca0e7a2e
equal deleted inserted replaced
26:dc7c549001d5 35:85266cc22c7f
    76 #include <QFontDialog>
    76 #include <QFontDialog>
    77 #include <QLocale>
    77 #include <QLocale>
    78 #include <QInputContextFactory>
    78 #include <QInputContextFactory>
    79 #include <QChar>
    79 #include <QChar>
    80 
    80 
    81 #ifndef QT_NO_WEBKIT
       
    82 #include <QWebView>
       
    83 #include <QWebFrame>
       
    84 #include <QWebHistory>
       
    85 #endif
       
    86 
       
    87 #ifdef __SYMBIAN32__
    81 #ifdef __SYMBIAN32__
    88 #include <xqservicerequest.h>
    82 #include <xqservicerequest.h>
    89 #include <xqcallinfo.h>
    83 #include <xqcallinfo.h>
    90 #include <cntservicescontact.h>
    84 #include <cntservicescontact.h>
    91 #include <qnetworkconfigmanager.h>
    85 #include <qnetworkconfigmanager.h>
    97 #include "slotcallback.h"
    91 #include "slotcallback.h"
    98 #include "swtlog.h"
    92 #include "swtlog.h"
    99 #include "jniutils.h"
    93 #include "jniutils.h"
   100 #include "swtfontcache.h"
    94 #include "swtfontcache.h"
   101 #include "swt.h"
    95 #include "swt.h"
       
    96 #include "swterror.h"
   102 #include "listdatamodel.h"
    97 #include "listdatamodel.h"
   103 #include "qcaptionedwidget.h"
    98 #include "qcaptionedwidget.h"
   104 #include "qswttimeedit.h"
    99 #include "qswttimeedit.h"
   105 #include "qtasktipbar.h"
   100 #include "qtasktipbar.h"
   106 #include "swtapplication.h"
   101 #include "swtapplication.h"
   113 #endif
   108 #endif
   114 
   109 
   115 using namespace Java::eSWT;
   110 using namespace Java::eSWT;
   116 
   111 
   117 #define OS_NATIVE(func) Java_org_eclipse_swt_internal_qt_OS_##func
   112 #define OS_NATIVE(func) Java_org_eclipse_swt_internal_qt_OS_##func
   118 
       
   119 #define POINTER_TO_HANDLE(pointer) reinterpret_cast<jint>(static_cast<QObject*>(pointer))
       
   120 #define HANDLE_TO_POINTER(type, variable, handle) type variable = qobject_cast<type>(static_cast<type>(reinterpret_cast<QObject*>( handle )))
       
   121 
       
   122 #define QCOLOR_TO_HANDLE(pointer) reinterpret_cast<jint>(static_cast<QColor*>(pointer))
       
   123 #define HANDLE_TO_QCOLOR(variable, handle) QColor* variable = static_cast<QColor*>(reinterpret_cast<QColor*>( handle ))
       
   124 
       
   125 #define QTABLEWIDGETITEM_TO_HANDLE(pointer) reinterpret_cast<jint>(static_cast<QTableWidgetItem*>(pointer))
       
   126 #define HANDLE_TO_QTABLEWIDGETITEM(variable, handle) QTableWidgetItem* variable = static_cast<QTableWidgetItem*>(reinterpret_cast<QTableWidgetItem*>( handle ))
       
   127 #define QTREEWIDGETITEM_TO_HANDLE(pointer) reinterpret_cast<jint>(static_cast<QTreeWidgetItem*>(pointer))
       
   128 #define HANDLE_TO_QTREEWIDGETITEM(variable, handle) QTreeWidgetItem* variable = static_cast<QTreeWidgetItem*>(reinterpret_cast<QTreeWidgetItem*>( handle ))
       
   129 
       
   130 #define SWT_TRY try
       
   131 #define SWT_CATCH \
       
   132 catch(std::bad_alloc const&)\
       
   133     {\
       
   134     swtApp->jniUtils().Throw( aJniEnv, ESwtErrorNoHandles );\
       
   135     }\
       
   136 catch(std::exception const&)\
       
   137     {\
       
   138     swtApp->jniUtils().Throw( aJniEnv, ESwtErrorUnspecified );\
       
   139     }
       
   140 #define SWT_CATCH_1(err) \
       
   141 catch(std::exception const&)\
       
   142     {\
       
   143     swtApp->jniUtils().Throw( aJniEnv, err );\
       
   144     }
       
   145 
   113 
   146 #ifdef Q_WS_X11
   114 #ifdef Q_WS_X11
   147 void extern qt_x11_wait_for_window_manager(QWidget* widget);
   115 void extern qt_x11_wait_for_window_manager(QWidget* widget);
   148 #endif
   116 #endif
   149 
   117 
 10191     }
 10159     }
 10192     SWT_CATCH
 10160     SWT_CATCH
 10193 #endif
 10161 #endif
 10194     return ( result ? JNI_TRUE : JNI_FALSE );
 10162     return ( result ? JNI_TRUE : JNI_FALSE );
 10195 }
 10163 }
 10196 
       
 10197 
       
 10198 //
       
 10199 // QWebView
       
 10200 //
       
 10201 JNIEXPORT jint JNICALL OS_NATIVE( QWebView_1new )
       
 10202     ( JNIEnv* aJniEnv , jclass )
       
 10203     {
       
 10204 #ifndef QT_NO_WEBKIT
       
 10205     QWebView* browser = NULL;
       
 10206     SWT_TRY
       
 10207         {
       
 10208         SWT_LOG_JNI_CALL();
       
 10209         browser = new QWebView();
       
 10210         }
       
 10211     SWT_CATCH
       
 10212     return POINTER_TO_HANDLE( browser );
       
 10213 #endif
       
 10214 #ifdef QT_NO_WEBKIT
       
 10215     swtApp->jniUtils().Throw( aJniEnv, ESwtErrorNotImplemented );
       
 10216     return 0;
       
 10217 #endif
       
 10218     }
       
 10219 
       
 10220 JNIEXPORT void JNICALL OS_NATIVE( QWebView_1back )
       
 10221     ( JNIEnv* aJniEnv , jclass, jint
       
 10222 #ifndef QT_NO_WEBKIT
       
 10223 aHandle
       
 10224 #endif
       
 10225 )
       
 10226     {
       
 10227     SWT_TRY
       
 10228         {
       
 10229         SWT_LOG_JNI_CALL();
       
 10230 #ifndef QT_NO_WEBKIT
       
 10231         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
 10232         browser->back();
       
 10233 #endif
       
 10234         }
       
 10235     SWT_CATCH
       
 10236     }
       
 10237 
       
 10238 JNIEXPORT void JNICALL OS_NATIVE( QWebView_1forward )
       
 10239     ( JNIEnv* aJniEnv , jclass, jint
       
 10240 #ifndef QT_NO_WEBKIT
       
 10241 aHandle
       
 10242 #endif
       
 10243 )
       
 10244     {
       
 10245     SWT_TRY
       
 10246         {
       
 10247         SWT_LOG_JNI_CALL();
       
 10248 #ifndef QT_NO_WEBKIT
       
 10249         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
 10250         browser->forward();
       
 10251 #endif
       
 10252         }
       
 10253     SWT_CATCH
       
 10254     }
       
 10255 
       
 10256 JNIEXPORT void JNICALL OS_NATIVE( QWebView_1reload )
       
 10257     ( JNIEnv* aJniEnv , jclass, jint
       
 10258 #ifndef QT_NO_WEBKIT
       
 10259 aHandle
       
 10260 #endif
       
 10261 )
       
 10262     {
       
 10263     SWT_TRY
       
 10264         {
       
 10265         SWT_LOG_JNI_CALL();
       
 10266 #ifndef QT_NO_WEBKIT
       
 10267         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
 10268         browser->reload();
       
 10269 #endif
       
 10270         }
       
 10271     SWT_CATCH
       
 10272     }
       
 10273 
       
 10274 JNIEXPORT void JNICALL OS_NATIVE( QWebView_1setHtml )
       
 10275     ( JNIEnv* aJniEnv , jclass, jint
       
 10276 #ifndef QT_NO_WEBKIT
       
 10277 aHandle
       
 10278 #endif
       
 10279 , jstring
       
 10280 #ifndef QT_NO_WEBKIT
       
 10281 aText
       
 10282 #endif
       
 10283 )
       
 10284     {
       
 10285     SWT_TRY
       
 10286         {
       
 10287         SWT_LOG_JNI_CALL();
       
 10288 #ifndef QT_NO_WEBKIT
       
 10289         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
 10290         browser->setHtml( swtApp->jniUtils().JavaStringToQString( aJniEnv, aText ) );
       
 10291 #endif
       
 10292         }
       
 10293     SWT_CATCH
       
 10294     }
       
 10295 
       
 10296 JNIEXPORT void JNICALL OS_NATIVE( QWebView_1setUrl )
       
 10297     ( JNIEnv* aJniEnv , jclass, jint
       
 10298 #ifndef QT_NO_WEBKIT
       
 10299 aHandle
       
 10300 #endif
       
 10301 , jstring
       
 10302 #ifndef QT_NO_WEBKIT
       
 10303 aText
       
 10304 #endif
       
 10305 )
       
 10306     {
       
 10307     SWT_TRY
       
 10308         {
       
 10309         SWT_LOG_JNI_CALL();
       
 10310 #ifndef QT_NO_WEBKIT
       
 10311         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
 10312         browser->setUrl( QUrl( swtApp->jniUtils().JavaStringToQString( aJniEnv, aText ) ) );
       
 10313 #endif
       
 10314         }
       
 10315     SWT_CATCH
       
 10316     }
       
 10317 
       
 10318 JNIEXPORT void JNICALL OS_NATIVE( QWebView_1stop )
       
 10319     ( JNIEnv* aJniEnv , jclass, jint
       
 10320 #ifndef QT_NO_WEBKIT
       
 10321 aHandle
       
 10322 #endif
       
 10323 )
       
 10324     {
       
 10325     SWT_TRY
       
 10326         {
       
 10327         SWT_LOG_JNI_CALL();
       
 10328 #ifndef QT_NO_WEBKIT
       
 10329         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
 10330         browser->stop();
       
 10331 #endif
       
 10332         }
       
 10333     SWT_CATCH
       
 10334     }
       
 10335 
       
 10336 JNIEXPORT jstring JNICALL OS_NATIVE( QWebView_1swt_1backUrl )
       
 10337     ( JNIEnv* aJniEnv , jclass, jint
       
 10338 #ifndef QT_NO_WEBKIT
       
 10339 aHandle
       
 10340 #endif
       
 10341 )
       
 10342     {
       
 10343     jstring res = NULL;
       
 10344     SWT_TRY
       
 10345         {
       
 10346         SWT_LOG_JNI_CALL();
       
 10347 #ifndef QT_NO_WEBKIT
       
 10348         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
 10349         QWebHistory* history = browser->history();
       
 10350         if ( history && history->canGoBack() )
       
 10351             {
       
 10352             res = swtApp->jniUtils().QStringToJavaString( aJniEnv, history->backItem().url().toString() );
       
 10353             }
       
 10354 #endif
       
 10355         }
       
 10356     SWT_CATCH
       
 10357     return res;
       
 10358     }
       
 10359 
       
 10360 JNIEXPORT jboolean JNICALL OS_NATIVE( QWebView_1swt_1canGoBack )
       
 10361     ( JNIEnv* aJniEnv , jclass, jint
       
 10362 #ifndef QT_NO_WEBKIT
       
 10363 aHandle
       
 10364 #endif
       
 10365 )
       
 10366     {
       
 10367     jboolean res = false;
       
 10368     SWT_TRY
       
 10369         {
       
 10370         SWT_LOG_JNI_CALL();
       
 10371 #ifndef QT_NO_WEBKIT
       
 10372         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
 10373         QWebHistory* history = browser->history();
       
 10374         if ( history )
       
 10375             {
       
 10376             res = history->canGoBack();
       
 10377             }
       
 10378 #endif
       
 10379         }
       
 10380     SWT_CATCH
       
 10381     return res;
       
 10382     }
       
 10383 
       
 10384 JNIEXPORT jboolean JNICALL OS_NATIVE( QWebView_1swt_1canGoForward )
       
 10385     ( JNIEnv* aJniEnv , jclass, jint
       
 10386 #ifndef QT_NO_WEBKIT
       
 10387 aHandle
       
 10388 #endif
       
 10389 )
       
 10390     {
       
 10391     jboolean res = false;
       
 10392     SWT_TRY
       
 10393         {
       
 10394         SWT_LOG_JNI_CALL();
       
 10395 #ifndef QT_NO_WEBKIT
       
 10396         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
 10397         QWebHistory* history = browser->history();
       
 10398         if ( history )
       
 10399             {
       
 10400             res = history->canGoForward();
       
 10401             }
       
 10402 #endif
       
 10403         }
       
 10404     SWT_CATCH
       
 10405     return res;
       
 10406     }
       
 10407 
       
 10408 JNIEXPORT jboolean JNICALL OS_NATIVE( QWebView_1swt_1evaluateJavaScript )
       
 10409     ( JNIEnv* aJniEnv , jclass, jint
       
 10410 #ifndef QT_NO_WEBKIT
       
 10411 aHandle
       
 10412 #endif
       
 10413 , jstring
       
 10414 #ifndef QT_NO_WEBKIT
       
 10415 aText
       
 10416 #endif
       
 10417 )
       
 10418     {
       
 10419     jboolean res = false;
       
 10420     SWT_TRY
       
 10421         {
       
 10422         SWT_LOG_JNI_CALL();
       
 10423 #ifndef QT_NO_WEBKIT
       
 10424         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
 10425         QWebPage* page = browser->page();
       
 10426         if ( page )
       
 10427             {
       
 10428             QWebFrame* frame = page->currentFrame();
       
 10429             if ( !frame )
       
 10430                 {
       
 10431                 frame = page->mainFrame();
       
 10432                 }
       
 10433             if ( frame )
       
 10434                 {
       
 10435                 res = ( frame->evaluateJavaScript( swtApp->jniUtils().JavaStringToQString( aJniEnv, aText ) ) ).toBool();
       
 10436                 }
       
 10437             }
       
 10438 #endif
       
 10439         }
       
 10440     SWT_CATCH
       
 10441     return res;
       
 10442     }
       
 10443 
       
 10444 JNIEXPORT jstring JNICALL OS_NATIVE( QWebView_1swt_1forwardUrl )
       
 10445     ( JNIEnv* aJniEnv , jclass, jint
       
 10446 #ifndef QT_NO_WEBKIT
       
 10447 aHandle
       
 10448 #endif
       
 10449 )
       
 10450     {
       
 10451     jstring res = NULL;
       
 10452     SWT_TRY
       
 10453         {
       
 10454         SWT_LOG_JNI_CALL();
       
 10455 #ifndef QT_NO_WEBKIT
       
 10456         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
 10457         QWebHistory* history = browser->history();
       
 10458         if ( history && history->canGoForward() )
       
 10459             {
       
 10460             res = swtApp->jniUtils().QStringToJavaString( aJniEnv, history->forwardItem().url().toString() );
       
 10461             }
       
 10462 #endif
       
 10463         }
       
 10464     SWT_CATCH
       
 10465     return res;
       
 10466     }
       
 10467 
       
 10468 JNIEXPORT jstring JNICALL OS_NATIVE( QWebView_1url )
       
 10469     ( JNIEnv* aJniEnv , jclass, jint
       
 10470 #ifndef QT_NO_WEBKIT
       
 10471 aHandle
       
 10472 #endif
       
 10473 )
       
 10474     {
       
 10475     jstring res = NULL;
       
 10476     SWT_TRY
       
 10477         {
       
 10478         SWT_LOG_JNI_CALL();
       
 10479 #ifndef QT_NO_WEBKIT
       
 10480         HANDLE_TO_POINTER( QWebView*, browser, aHandle );
       
 10481         res = swtApp->jniUtils().QStringToJavaString( aJniEnv, browser->url().toString() );
       
 10482 #endif
       
 10483         }
       
 10484     SWT_CATCH
       
 10485     return res;
       
 10486     }
       
 10487 
 10164 
 10488 //
 10165 //
 10489 // Special purpose global functions exported by Qt
 10166 // Special purpose global functions exported by Qt
 10490 //
 10167 //
 10491 
 10168 
 11728 (JNIEnv* aJniEnv, jclass, jint)
 11405 (JNIEnv* aJniEnv, jclass, jint)
 11729 #endif
 11406 #endif
 11730     {
 11407     {
 11731 #ifdef __SYMBIAN32__    
 11408 #ifdef __SYMBIAN32__    
 11732     bool result = false;
 11409     bool result = false;
 11733     XQServiceRequest* client = NULL;
       
 11734     SWT_TRY
 11410     SWT_TRY
 11735         {
 11411         {
 11736         SWT_LOG_JNI_CALL();
 11412         SWT_LOG_JNI_CALL();
 11737         SWT_LOG_DATA_1( "handle=%x", aHandle );
 11413         SWT_LOG_DATA_1( "handle=%x", aHandle );
 11738         XQServiceRequest* client = reinterpret_cast<XQServiceRequest*>(aHandle);
 11414         XQServiceRequest* client = reinterpret_cast<XQServiceRequest*>(aHandle);
 12108         }
 11784         }
 12109     SWT_CATCH
 11785     SWT_CATCH
 12110     }
 11786     }
 12111 
 11787 
 12112 JNIEXPORT jint JNICALL OS_NATIVE(SignalHandler_1new)
 11788 JNIEXPORT jint JNICALL OS_NATIVE(SignalHandler_1new)
       
 11789   (JNIEnv* aJniEnv, jclass, jint aWidget, jint aSignalId )
       
 11790     {
       
 11791     SlotCallback* cb = NULL;
       
 11792     SWT_TRY
       
 11793         {
       
 11794         SWT_LOG_JNI_CALL();
       
 11795         SWT_LOG_DATA_1("peer=%x", aPeer);
       
 11796 
       
 11797         HANDLE_TO_POINTER( QObject*, widget, aWidget );
       
 11798 
       
 11799         // Widget takes ownership of the signal handler instance
       
 11800         cb = new SlotCallback( aJniEnv, NULL, widget, aSignalId );
       
 11801         }
       
 11802     SWT_CATCH
       
 11803     return POINTER_TO_HANDLE( cb );
       
 11804     }
       
 11805 
       
 11806 JNIEXPORT jint JNICALL OS_NATIVE(SignalForwarder_1new)
 12113   (JNIEnv* aJniEnv, jclass, jint aWidget, jobject aPeer, jint aSignalId )
 11807   (JNIEnv* aJniEnv, jclass, jint aWidget, jobject aPeer, jint aSignalId )
 12114     {
 11808     {
 12115     SlotCallback* cb = NULL;
 11809     SlotCallback* cb = NULL;
 12116     SWT_TRY
 11810     SWT_TRY
 12117         {
 11811         {
 12126     SWT_CATCH
 11820     SWT_CATCH
 12127     return POINTER_TO_HANDLE( cb );
 11821     return POINTER_TO_HANDLE( cb );
 12128     }
 11822     }
 12129 
 11823 
 12130 JNIEXPORT jint JNICALL OS_NATIVE( JniUtils_1new )
 11824 JNIEXPORT jint JNICALL OS_NATIVE( JniUtils_1new )
 12131   (JNIEnv* aJniEnv, jclass, jobject aDisplay)
 11825   (JNIEnv* aJniEnv, jclass)
 12132     {
 11826     {
 12133     // Note that JNI callbacks are not possible before first successfully creating jniUtils
 11827     // Note that JNI callbacks are not possible before first successfully creating jniUtils
 12134     JniUtils* jniUtils = NULL;
 11828     JniUtils* jniUtils = NULL;
 12135     try {
 11829     try {
 12136         jniUtils = new JniUtils(aJniEnv, aDisplay);
 11830         jniUtils = new JniUtils(aJniEnv);
 12137         }
 11831         }
 12138     catch(...)
 11832     catch(...)
 12139         {
 11833         {
 12140         // Can't throw an exception because there's no jniUtils
 11834         // Can't throw an exception because there's no jniUtils
 12141         }
 11835         }
 12218   (JNIEnv* aJniEnv, jclass, jobject aRunner, jint aUid)
 11912   (JNIEnv* aJniEnv, jclass, jobject aRunner, jint aUid)
 12219 #else
 11913 #else
 12220 (JNIEnv*, jclass, jobject, jint)
 11914 (JNIEnv*, jclass, jobject, jint)
 12221 #endif
 11915 #endif
 12222     {
 11916     {
 12223     jint retVal = 0;
 11917     jint retVal = -1;
 12224 #ifdef __SYMBIAN32__
 11918 #ifdef __SYMBIAN32__
 12225     retVal = static_cast<jint>(SymbianUtils::startUI( aJniEnv, aRunner,  aUid));
 11919     retVal = static_cast<jint>(SymbianUtils::startUI( aJniEnv, aRunner,  aUid));
 12226 #endif
 11920 #endif
 12227     return retVal;
 11921     return retVal;
 12228     }
 11922     }