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

jsfactory.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 KJSEMBEDFACTORY_H
00023 #define KJSEMBEDFACTORY_H
00024 
00025 #include <qmap.h>
00026 #include <qdict.h>
00027 #include <qstringlist.h>
00028 
00029 #include <kparts/part.h>
00030 
00031 #include <kjs/interpreter.h>
00032 #include <kjs/object.h>
00033 
00034 #include <kjsembed/jsbinding.h>
00035 #include <kjsembed/xmlactionclient.h>
00036 
00037 class QWidget;
00038 class QTextStream;
00039 
00040 namespace KParts { class ReadOnlyPart; }
00041 
00045 namespace KJSEmbed {
00046 
00047 namespace Bindings { class JSFactoryImp; }
00048 
00049 class KJSEmbedPart;
00050 class JSEventMapper;
00051 class JSOpaqueProxy;
00052 
00058 class JSFactory
00059 {
00060 public:
00065     enum ProxyTypes {
00066         TypeInvalid,
00067         TypeQObject,
00068         TypeValue,
00069         TypeOpaque,
00070         TypePlugin
00071     };
00072 
00074     JSFactory( KJSEmbedPart *part );
00075 
00077     virtual ~JSFactory();
00078 
00083     JSEventMapper *eventMapper() const { return evmapper; }
00084 
00086     KJSEmbedPart *part() const { return jspart; }
00087 
00088     //
00089     // Methods for creating objects and wrappers.
00090     //
00091 
00093     KJS::Object create( KJS::ExecState *exec, const QString &classname, const KJS::List &args );
00094 
00096     KJS::Object createProxy( KJS::ExecState *exec, QObject *target,
00097                              const JSObjectProxy *context=0 ) const;
00098 
00100     KJS::Object createProxy( KJS::ExecState *exec, QTextStream *target,
00101                              const JSObjectProxy *context=0 ) const;
00102 
00104     KJS::Object createProxy( KJS::ExecState *exec, QEvent *target,
00105                              const JSObjectProxy *context ) const;
00106 
00107     //
00108     // Methods for creating custom objects.
00109     //
00110 
00117     KParts::ReadOnlyPart *createROPart( const QString &svc, QObject *parent=0, const char *name=0 );
00118 
00123     KParts::ReadOnlyPart *createROPart( const QString &svc, const QString &constraint,
00124                                         QObject *parent=0, const char *name=0 );
00125     
00130     QWidget *loadUI( const QString &uiFile, QObject *connector=0, QWidget *parent=0, const char *name=0 );
00131 
00136     QStringList listBindingPlugins( KJS::ExecState *exec, KJS::Object &self);
00137     //
00138     // Methods that tell the factory how to handle different classes.
00139     //
00143     void addBindingPluginTypes(KJS::ExecState *exec, KJS::Object &parent);
00144     bool isBindingPlugin(const QString &classname);
00148     KJS::Object createBindingPlugin(KJS::ExecState *exec, const QString &classname, const KJS::List &args );
00153     bool isSupported( const QString &clazz ) const;
00154 
00159     bool isQObject( const QString &clazz ) const;
00160 
00165     bool isValue( const QString &clazz ) const;
00166 
00171     bool isOpaque( const QString &clazz ) const;
00172 
00178     uint proxyType( const QString &clazz ) const;
00179 
00185     void addType( const QString &clazz, uint proxytype=JSFactory::TypeQObject );
00186 
00188     void addTypes( KJS::ExecState *exec, KJS::Object &parent );
00189 
00190     QStringList types() const;
00191     
00192 protected:
00194     KJS::Object extendProxy( KJS::ExecState *exec, KJS::Object &target ) const;
00195     
00197     KJS::Object createValue( KJS::ExecState *exec, const QString &cname, const KJS::List &args );
00198 
00203     QObject *create( const QString &classname, QObject *parent=0, const char *name=0  );
00204 
00206     KJS::Object createOpaque( KJS::ExecState *exec, const QString &cname, const KJS::List &args );
00207 
00208 
00210     QObject *createBinding( const QString &cname, QObject *parent, const char *name );
00211 
00216     QObject *createObject( const QString &cname, QObject *parent, const char *name );
00217 
00222     QWidget *createWidget( const QString &cname, QWidget *parent, const char *name );
00223 
00224 private:
00226     void addWidgetFactoryTypes( KJS::ExecState *exec, KJS::Object &parent );
00227 
00229     void addCustomTypes( KJS::ExecState *exec, KJS::Object &parent );
00230 
00232     void addBindingTypes( KJS::ExecState *exec, KJS::Object &parent );
00233 
00238     void addObjectTypes( KJS::ExecState *exec, KJS::Object &parent );
00239 
00240     void addOpaqueTypes( KJS::ExecState *exec, KJS::Object &parent );
00241 
00242     void addValueTypes( KJS::ExecState *exec, KJS::Object &parent );
00243     
00244 private:
00245     KJSEmbedPart *jspart;
00246     JSEventMapper *evmapper;
00247     QMap<QString,uint> objtypes;
00248     class JSFactoryPrivate *d;
00249 };
00250 
00251 } // namespace KJSEmbed
00252 
00253 #endif // KJSEMBEDFACTORY_H
00254 
00255 // Local Variables:
00256 // c-basic-offset: 4
00257 // End:

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