Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

kjsembedpart.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 
00003 /*
00004  *  Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org>
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Library General Public
00008  *  License as published by the Free Software Foundation; either
00009  *  version 2 of the License, or (at your option) any later version.
00010  *
00011  *  This library is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  Library General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU Library General Public License
00017  *  along with this library; see the file COPYING.LIB.  If not, write to
00018  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  *  Boston, MA 02111-1307, USA.
00020  */
00021 
00022 #ifndef KJSEMBEDJSCONSOLEPART_H
00023 #define KJSEMBEDJSCONSOLEPART_H
00024 
00025 #include <qstringlist.h>
00026 
00027 #include <kparts/part.h>
00028 #include <kjs/interpreter.h>
00029 #include <kjs/object.h>
00030 #include <kjs/value.h>
00031 
00032 #include <kjsembed/jsbinding.h>
00033 #include <kjsembed/xmlactionclient.h>
00034 
00035 class QWidget;
00036 
00037 #define KJSEMBED_VERSION_STRING "0.3"
00038 #define KJSEMBED_VERSION_MAJOR 0
00039 #define KJSEMBED_VERSION_MINOR 3
00040 
00044 namespace KJSEmbed {
00045 
00046 class JSObjectProxy;
00047 class JSConsoleWidget;
00048 class JSFactory;
00049 class JSBuiltIn;
00050 
00057 class KJSEmbedPart : public KParts::ReadOnlyPart
00058 {
00059     Q_OBJECT
00060     Q_PROPERTY( QStringList constructorNames READ constructorNames )
00061     Q_PROPERTY( QCString versionString READ versionString )
00062     Q_PROPERTY( int versionMajor READ versionMajor )
00063     Q_PROPERTY( int versionMinor READ versionMinor )
00064 
00065 public:
00067     KJSEmbedPart( QObject *parent=0, const char *name=0 );
00068 
00078     KJSEmbedPart( QWidget *wparent, const char *wname=0, QObject *parent=0, const char *name=0 );
00079 
00085     KJSEmbedPart( KJS::Interpreter *js, QWidget *wparent, const char *wname=0,
00086                   QObject *parent=0, const char *name=0 );
00087 
00089     virtual ~KJSEmbedPart();
00090 
00091     //
00092     // Version information
00093     //
00094 
00096     QCString versionString() const;
00097 
00099     int versionMajor() const;
00100 
00102     int versionMinor() const;
00103 
00104     //
00105     // Script environment.
00106     //
00107 
00109     KJS::Object globalObject() const { return js->globalObject(); }
00110 
00112     KJS::Completion completion() const { return res; }
00113 
00115     KJS::Object partObject() const { return partobj; }
00116 
00121     KJS::Object addObject( QObject *obj, const char *name=0 );
00122 
00127     KJS::Object addObject( QObject *obj, KJS::Object &parent, const char *name=0 );
00128 
00130     KJS::Object bind( QObject *obj );
00131 
00132     //
00133     // Query the supported types
00134     //
00135 
00137     QStringList constructorNames() const;
00138 
00140     KJS::Value constructors() const;
00141 
00143     KJS::List constructorList() const;
00144 
00145 public slots:
00146     //
00147     // Reimplement the KPart API.
00148     //
00149 
00151     virtual KJSEmbed::JSConsoleWidget *view();
00152 
00154     virtual bool openURL( const KURL &url );
00155 
00156     //
00157     // XML Action Handling
00158     //
00159 
00161     KJSEmbed::XMLActionClient *actionClient() const { return xmlclient; }
00162 
00164     bool loadActionSet( const QString &file );
00165 
00166     //
00167     // Script environemnt
00168     //
00169 
00171     KJS::Interpreter *interpreter() const { return js; }
00172 
00174     KJS::ExecState *globalExec() const { return js->globalExec(); }
00175 
00177     JSFactory *factory() const { return jsfactory; }
00178 
00180     virtual KJS::Value evaluate( const QString &script, const KJS::Value &self=KJS::Null() );
00181 
00183     bool execute( const QString &script, const KJS::Value &self=KJS::Null() );
00184 
00189     virtual bool execute( KJS::Completion &result, const QString &script, const KJS::Value &self );
00190 
00192     virtual bool runFile( const QString &filename, const KJS::Value &self=KJS::Null() );
00193 
00199     QString loadFile( const QString &file );
00200 
00201 protected:
00203     void createInterpreter();
00204 
00212     void createBuiltIn( KJS::ExecState *exec, KJS::Object &parent );
00213 
00215     void createActionClient();
00216 
00218     virtual bool openFile() { return false; }
00219 
00221     virtual void virtual_hook( int id, void *data );
00222 
00223 private:
00224     XMLActionClient *xmlclient;
00225     JSConsoleWidget *jsConsole;
00226     JSFactory *jsfactory;
00227     JSBuiltIn *builtins;
00228     QWidget *widgetparent;
00229     QCString widgetname;
00230 
00231     KJS::Object partobj;
00232     KJS::Completion res;
00233     KJS::Interpreter *js;
00234     bool deletejs;
00235 
00236     class KJSEmbedPartPrivate *d;
00237 };
00238 
00239 
00240 } // namespace KJSEmbed
00241 
00242 #endif // KJSEMBEDJSCONSOLEPART_H
00243 
00244 // Local Variables:
00245 // c-basic-offset: 4
00246 // End:
00247 

Generated on Sun Jan 11 02:29:53 2004 for KJSEmbed by doxygen1.2.18