00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef KJSEMBEDJSCONSOLEPART_H
00023 #define KJSEMBEDJSCONSOLEPART_H
00024
00025 #include <qstringlist.h>
00026
00027 #ifndef QT_ONLY
00028 #include <kparts/part.h>
00029 #endif
00030
00031 #include <kjs/interpreter.h>
00032 #include <kjs/object.h>
00033 #include <kjs/value.h>
00034
00035 #include <kjsembed/jsbinding.h>
00036
00037 #ifndef QT_ONLY
00038 #include <kjsembed/xmlactionclient.h>
00039 #else
00040 #include <kjsembed/qtstubs.h>
00041 #endif
00042
00043 class QWidget;
00044
00045 #define KJSEMBED_VERSION_STRING "0.3"
00046 #define KJSEMBED_VERSION_MAJOR 0
00047 #define KJSEMBED_VERSION_MINOR 3
00048
00052 namespace KJSEmbed {
00053
00054 class JSObjectProxy;
00055 class JSConsoleWidget;
00056 class JSFactory;
00057 class JSBuiltIn;
00058
00065 class KJSEmbedPart : public KParts::ReadOnlyPart
00066 {
00067 Q_OBJECT
00068 Q_PROPERTY( QStringList constructorNames READ constructorNames )
00069 Q_PROPERTY( QCString versionString READ versionString )
00070 Q_PROPERTY( int versionMajor READ versionMajor )
00071 Q_PROPERTY( int versionMinor READ versionMinor )
00072
00073 public:
00075 KJSEmbedPart( QObject *parent=0, const char *name=0 );
00076
00086 KJSEmbedPart( QWidget *wparent, const char *wname=0, QObject *parent=0, const char *name=0 );
00087
00093 KJSEmbedPart( KJS::Interpreter *js, QWidget *wparent, const char *wname=0,
00094 QObject *parent=0, const char *name=0 );
00095
00097 virtual ~KJSEmbedPart();
00098
00099
00100
00101
00102
00104 QCString versionString() const;
00105
00107 int versionMajor() const;
00108
00110 int versionMinor() const;
00111
00112
00113
00114
00115
00123 bool hasMethod( const QString &methodName );
00124
00136 KJS::Value callMethod(const QString &methodName, const KJS::List &args) const;
00143 KJS::Value getValue( const QString &valueName ) const;
00144
00153 void putValue( const QString &valueName, const KJS::Value &value);
00154
00161 void putVariant( const QString &valueName, const QVariant &value);
00162
00169 QVariant getVariant( const QString &valueName ) const;
00170
00172 KJS::Object globalObject() const { return js->globalObject(); }
00173
00175 KJS::Completion completion() const { return res; }
00176
00178 KJS::Object partObject() const { return partobj; }
00179
00184 KJS::Object addObject( QObject *obj, const char *name=0 );
00185
00190 KJS::Object addObject( QObject *obj, KJS::Object &parent, const char *name=0 );
00191
00193 KJS::Object bind( QObject *obj );
00194
00195
00196
00197
00198
00200 QStringList constructorNames() const;
00201
00203 KJS::Value constructors() const;
00204
00206 KJS::List constructorList() const;
00207
00208 public slots:
00209
00210
00211
00212
00214 virtual KJSEmbed::JSConsoleWidget *view();
00215
00217 virtual bool openURL( const KURL &url );
00218
00219
00220
00221
00222
00224 KJSEmbed::XMLActionClient *actionClient() const { return xmlclient; }
00225
00227 bool loadActionSet( const QString &file );
00228
00229
00230
00231
00232
00234 KJS::Interpreter *interpreter() const { return js; }
00235
00237 KJS::ExecState *globalExec() const { return js->globalExec(); }
00238
00240 JSFactory *factory() const { return jsfactory; }
00241
00243 virtual KJS::Value evaluate( const QString &script, const KJS::Value &self=KJS::Null() );
00244
00246 bool execute( const QString &script, const KJS::Value &self=KJS::Null() );
00247
00252 virtual bool execute( KJS::Completion &result, const QString &script, const KJS::Value &self );
00253
00255 virtual bool runFile( const QString &filename, const KJS::Value &self=KJS::Null() );
00256
00262 QString loadFile( const QString &file );
00263
00264 protected:
00266 void createInterpreter();
00267
00275 void createBuiltIn( KJS::ExecState *exec, KJS::Object &parent );
00276
00278 void createActionClient();
00279
00281 virtual bool openFile() { return false; }
00282
00284 virtual void virtual_hook( int id, void *data );
00285
00286 private:
00287 XMLActionClient *xmlclient;
00288 JSConsoleWidget *jsConsole;
00289 JSFactory *jsfactory;
00290 JSBuiltIn *builtins;
00291 QWidget *widgetparent;
00292 QCString widgetname;
00293
00294 KJS::Object partobj;
00295 KJS::Completion res;
00296 KJS::Interpreter *js;
00297 bool deletejs;
00298
00299 class KJSEmbedPartPrivate *d;
00300 };
00301
00302
00303 }
00304
00305 #endif // KJSEMBEDJSCONSOLEPART_H
00306
00307
00308
00309
00310