# jsfactory.h

Go to the documentation of this file.

    00001 // -*- c++ -*-
    00002
    00003 /*
    00004  *  Copyright (C) 2001-2004, 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 KJSEMBEDFACTORY_H
    00023 #define KJSEMBEDFACTORY_H
    00024
    00025 #include <qmap.h>
    00026 #include <qdict.h>
    00027 #include <qstringlist.h>
    00028
    00029 #include <kjs/interpreter.h>
    00030 #include <kjs/object.h>
    00031
    00032 class QEvent;
    00033 class QObject;
    00034 class QWidget;
    00035 class QTextStream;
    00036
    00037 namespace KParts {
    00038     class ReadOnlyPart;
    00039     class ReadWritePart;
    00040 }
    00041
    00045 namespace KJSEmbed {
    00046
    00047 namespace Bindings { class JSFactoryImp;
    00048     class JSBindingPlugin; }
    00049
    00050 class KJSEmbedPart;
    00051 class JSEventMapper;
    00052 class JSOpaqueProxy;
    00053 class JSObjectProxy;
    00054
    00060 class JSFactory
    00061 {
    00062 public:
    00067     enum ProxyTypes {
    00068         TypeInvalid=0,
    00069         TypeQObject=1,
    00070         TypeValue=2,
    00071         TypeOpaque=4,
    00072         TypePlugin=8,
    00073         TypeQObjectPlugin=9 /*TypeObject|TypePlugin*/
    00074     };
    00075
    00077     JSFactory( KJSEmbedPart *part );
    00078
    00080     virtual ~JSFactory();
    00081
    00086     JSEventMapper *eventMapper() const { return evmapper; }
    00087
    00089     KJSEmbedPart *part() const { return jspart; }
    00090
    00091     //
    00092     // Methods for creating objects and wrappers.
    00093     //
    00094
    00096     KJS::Object create( KJS::ExecState *exec, const QString &classname, const KJS::List &args );
    00097
    00099     KJS::Object createProxy( KJS::ExecState *exec, QObject *target,
    00100                              const JSObjectProxy *context=0 ) const;
    00101
    00103     KJS::Object createProxy( KJS::ExecState *exec, QTextStream *target,
    00104                              const JSObjectProxy *context=0 ) const;
    00105
    00107     KJS::Object createProxy( KJS::ExecState *exec, QEvent *target,
    00108                              const JSObjectProxy *context ) const;
    00109
    00110     //
    00111     // Methods for creating custom objects.
    00112     //
    00113
    00120     KParts::ReadOnlyPart *createROPart( const QString &svc, QObject *parent=0, const char *name=0 );
    00121
    00126     KParts::ReadOnlyPart *createROPart( const QString &svc, const QString &constraint,
    00127                                         QObject *parent=0, const char *name=0 );
    00128
    00133     KParts::ReadOnlyPart *createROPart( const QString &svc, const QString &constraint,
    00134                                         QObject *parent, const char *name,
    00135                                         const QStringList &args );
    00136
    00143     KParts::ReadWritePart *createRWPart( const QString &svc, QObject *parent=0, const char *name=0 );
    00144
    00149     KParts::ReadWritePart *createRWPart( const QString &svc, const QString &constraint,
    00150                                          QObject *parent=0, const char *name=0 );
    00151
    00156     KParts::ReadWritePart *createRWPart( const QString &svc, const QString &constraint,
    00157                                          QObject *parent, const char *name,
    00158                                          const QStringList &args );
    00159
    00164     QWidget *loadUI( const QString &uiFile, QObject *connector=0, QWidget *parent=0, const char *name=0 );
    00165
    00170     QStringList listBindingPlugins( KJS::ExecState *exec, KJS::Object &self);
    00171     //
    00172     // Methods that tell the factory how to handle different classes.
    00173     //
    00177     void addBindingPluginTypes(KJS::ExecState *exec, KJS::Object &parent);
    00178     bool isBindingPlugin(const QString &classname) const;
    00182     KJS::Object createBindingPlugin(KJS::ExecState *exec, const QString &classname, const KJS::List &args );
    00187     bool isSupported( const QString &clazz ) const;
    00188
    00193     bool isQObject( const QString &clazz ) const;
    00194
    00199     bool isValue( const QString &clazz ) const;
    00200
    00205     bool isOpaque( const QString &clazz ) const;
    00206
    00212     uint proxyType( const QString &clazz ) const;
    00213
    00214
    00219     void addQObjectPlugin(const QString &classname, KJSEmbed::Bindings::JSBindingPlugin* plugin);
    00220
    00221     void addBindingsPlugin(KJS::ExecState *exec, KJS::Object &target) const;
    00222
    00228     void addType( const QString &clazz, uint proxytype=JSFactory::TypeQObject );
    00229
    00231     void addTypes( KJS::ExecState *exec, KJS::Object &parent );
    00232
    00233     QStringList types() const;
    00234
    00235 protected:
    00237     KJS::Object extendProxy( KJS::ExecState *exec, KJS::Object &target ) const;
    00238
    00240     KJS::Object createValue( KJS::ExecState *exec, const QString &cname, const KJS::List &args );
    00241
    00246     QObject *create( const QString &classname, QObject *parent=0, const char *name=0  );
    00247
    00249     KJS::Object createOpaque( KJS::ExecState *exec, const QString &cname, const KJS::List &args );
    00250
    00251
    00253     QObject *createBinding( const QString &cname, QObject *parent, const char *name );
    00254
    00259     QObject *createObject( const QString &cname, QObject *parent, const char *name );
    00260
    00265     QWidget *createWidget( const QString &cname, QWidget *parent, const char *name );
    00266
    00267 private:
    00269     void addWidgetFactoryTypes( KJS::ExecState *exec, KJS::Object &parent );
    00270
    00272     void addCustomTypes( KJS::ExecState *exec, KJS::Object &parent );
    00273
    00275     void addBindingTypes( KJS::ExecState *exec, KJS::Object &parent );
    00276
    00281     void addObjectTypes( KJS::ExecState *exec, KJS::Object &parent );
    00282
    00283     void addOpaqueTypes( KJS::ExecState *exec, KJS::Object &parent );
    00284
    00285     void addValueTypes( KJS::ExecState *exec, KJS::Object &parent );
    00286
    00287 private:
    00288     KJSEmbedPart *jspart;
    00289     JSEventMapper *evmapper;
    00290     QMap<QString,uint> objtypes;
    00291     class JSFactoryPrivate *d;
    00292 };
    00293
    00294 } // namespace KJSEmbed
    00295
    00296 #endif // KJSEMBEDFACTORY_H
    00297
    00298 // Local Variables:
    00299 // c-basic-offset: 4
    00300 // End: