• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

kjsembed

qobject_binding.h

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002     Copyright (C) 2005, 2006 Ian Reinhart Geiser <geiseri@kde.org>
00003     Copyright (C) 2005, 2006 Matt Broadstone <mbroadst@gmail.com>
00004     Copyright (C) 2005, 2006 Richard J. Moore <rich@kde.org>
00005     Copyright (C) 2005, 2006 Erik L. Bunce <kde@bunce.us>
00006     Copyright (C) 2007, 2008 Sebastian Sauer <mail@dipe.org>
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Library General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Library General Public License for more details.
00017 
00018     You should have received a copy of the GNU Library General Public License
00019     along with this library; see the file COPYING.LIB.  If not, write to
00020     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021     Boston, MA 02110-1301, USA.
00022 */
00023 
00024 
00025 #ifndef QOBJECT_BINDING_H
00026 #define QOBJECT_BINDING_H
00027 
00028 #include <QtCore/QObjectCleanupHandler>
00029 #include <QtCore/QDebug>
00030 #include <QtCore/QBool>
00031 
00032 #include <kjs/function.h>
00033 #include <kdemacros.h>
00034 
00035 #include "binding_support.h"
00036 #include "object_binding.h"
00037 
00038 
00045 #define START_QOBJECT_METHOD( METHODNAME, TYPE) \
00046 KJS::JSValue *METHODNAME( KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args ) \
00047 { \
00048         Q_UNUSED( args ); \
00049         KJS::JSValue *result = KJS::jsNull(); \
00050         KJSEmbed::QObjectBinding *imp = KJSEmbed::extractBindingImp<KJSEmbed::QObjectBinding>(exec, self ); \
00051         if( imp ) \
00052         { \
00053             TYPE *object = imp->qobject<TYPE>(); \
00054             if( object ) \
00055             {
00056 
00060 #define END_QOBJECT_METHOD \
00061             } \
00062             else \
00063                 KJS::throwError(exec, KJS::ReferenceError, QString("QO: The internal object died %1:%2.").arg(__FILE__).arg(__LINE__));\
00064         } \
00065         else \
00066            KJS::throwError(exec, KJS::ReferenceError, QString("QObject died."));\
00067         return result; \
00068 }
00069 
00070 class QObject;
00071 class QMetaMethod;
00072 
00073 namespace KJSEmbed {
00074 
00075 KJS_BINDING( QObjectFactory )
00076 
00077 class EventProxy;
00078 
00079 class KJSEMBED_EXPORT QObjectBinding : public ObjectBinding
00080 {
00081     public:
00082 
00083         QObjectBinding( KJS::ExecState *exec, QObject *object );
00084         virtual ~QObjectBinding();
00085 
00086         static void publishQObject( KJS::ExecState *exec, KJS::JSObject *target, QObject *object);
00087 
00094         enum Access {
00095             None = 0x00, 
00096 
00097             ScriptableSlots = 0x01, 
00098             NonScriptableSlots = 0x02, 
00099             PrivateSlots = 0x04, 
00100             ProtectedSlots = 0x08, 
00101             PublicSlots = 0x10, 
00102             AllSlots = ScriptableSlots|NonScriptableSlots|PrivateSlots|ProtectedSlots|PublicSlots,
00103 
00104             ScriptableSignals = 0x100, 
00105             NonScriptableSignals = 0x200, 
00106             PrivateSignals = 0x400, 
00107             ProtectedSignals = 0x800, 
00108             PublicSignals = 0x1000, 
00109             AllSignals = ScriptableSignals|NonScriptableSignals|PrivateSignals|ProtectedSignals|PublicSignals,
00110 
00111             ScriptableProperties = 0x10000, 
00112             NonScriptableProperties = 0x20000, 
00113             AllProperties = ScriptableProperties|NonScriptableProperties,
00114 
00115             GetParentObject = 0x100000, 
00116             SetParentObject = 0x200000, 
00117             ChildObjects = 0x400000, 
00118             AllObjects = GetParentObject|SetParentObject|ChildObjects
00119         };
00120 
00121         Q_DECLARE_FLAGS(AccessFlags, Access)
00122 
00123         
00126         AccessFlags access() const;
00127 
00131         void setAccess(AccessFlags access);
00132 
00136         void put(KJS::ExecState *exec, const KJS::Identifier &propertyName, KJS::JSValue *value, int attr=KJS::None);
00137 
00141         bool canPut(KJS::ExecState *exec, const KJS::Identifier &propertyName) const;
00142 
00147         bool getOwnPropertySlot( KJS::ExecState *exec, const KJS::Identifier &propertyName, KJS::PropertySlot &slot );
00148 
00152         static KJS::JSValue *propertyGetter( KJS::ExecState *exec, KJS::JSObject*, const KJS::Identifier& name, const KJS::PropertySlot& );
00153 
00158         KJS::UString toString(KJS::ExecState *exec) const;
00159 
00164         KJS::UString className() const;
00165 
00170         void watchObject( QObject *object );
00171 
00176         template <typename T>
00177         T *qobject() const
00178         {
00179           QObject* object = QObjectBinding::object<QObject>();
00180           if (object)
00181             return qobject_cast<T*>(object);
00182           else
00183             return 0;
00184         }
00185 
00186     private:
00187         EventProxy *m_evproxy;
00188         QObjectCleanupHandler *m_cleanupHandler;
00189         AccessFlags m_access;
00190 };
00191 
00192 Q_DECLARE_OPERATORS_FOR_FLAGS(QObjectBinding::AccessFlags)
00193 
00194 class KJSEMBED_EXPORT SlotBinding : public KJS::InternalFunctionImp
00195 {
00196     public:
00197         SlotBinding(KJS::ExecState *exec, const QMetaMethod &memberName);
00198         KJS::JSValue *callAsFunction( KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args );
00199         bool implementsCall() const { return true; }
00200         bool implementsConstruct() const { return false; }
00201 
00202     protected:
00203         QByteArray m_memberName;
00204 };
00205 
00230 KJSEMBED_EXPORT KJS::JSObject *createQObject(KJS::ExecState *exec, QObject *value, KJSEmbed::ObjectBinding::Ownership owner = KJSEmbed::ObjectBinding::JSOwned);
00231 
00232 
00233 }
00234 #endif
00235 
00236 //kate: indent-spaces on; indent-width 4; replace-tabs on; indent-mode cstyle;

kjsembed

Skip menu "kjsembed"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal