| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the ActiveQt framework of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:BSD$
|
|---|
| 9 | ** You may use this file under the terms of the BSD license as follows:
|
|---|
| 10 | **
|
|---|
| 11 | ** "Redistribution and use in source and binary forms, with or without
|
|---|
| 12 | ** modification, are permitted provided that the following conditions are
|
|---|
| 13 | ** met:
|
|---|
| 14 | ** * Redistributions of source code must retain the above copyright
|
|---|
| 15 | ** notice, this list of conditions and the following disclaimer.
|
|---|
| 16 | ** * Redistributions in binary form must reproduce the above copyright
|
|---|
| 17 | ** notice, this list of conditions and the following disclaimer in
|
|---|
| 18 | ** the documentation and/or other materials provided with the
|
|---|
| 19 | ** distribution.
|
|---|
| 20 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
|---|
| 21 | ** the names of its contributors may be used to endorse or promote
|
|---|
| 22 | ** products derived from this software without specific prior written
|
|---|
| 23 | ** permission.
|
|---|
| 24 | **
|
|---|
| 25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|---|
| 26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|---|
| 27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|---|
| 28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|---|
| 29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|---|
| 30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|---|
| 31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|---|
| 35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
|---|
| 36 | ** $QT_END_LICENSE$
|
|---|
| 37 | **
|
|---|
| 38 | ****************************************************************************/
|
|---|
| 39 |
|
|---|
| 40 | #ifndef QAXBASE_H
|
|---|
| 41 | #define QAXBASE_H
|
|---|
| 42 |
|
|---|
| 43 | #include <QtCore/qdatastream.h>
|
|---|
| 44 | #include <QtCore/qmap.h>
|
|---|
| 45 | #include <QtCore/qobject.h>
|
|---|
| 46 | #include <QtCore/qvariant.h>
|
|---|
| 47 |
|
|---|
| 48 | struct IUnknown;
|
|---|
| 49 | struct IDispatch;
|
|---|
| 50 |
|
|---|
| 51 | QT_BEGIN_HEADER
|
|---|
| 52 |
|
|---|
| 53 | QT_BEGIN_NAMESPACE
|
|---|
| 54 |
|
|---|
| 55 | QT_MODULE(ActiveQt)
|
|---|
| 56 |
|
|---|
| 57 | #ifndef QT_NO_WIN_ACTIVEQT
|
|---|
| 58 |
|
|---|
| 59 | struct QUuid;
|
|---|
| 60 | class QAxEventSink;
|
|---|
| 61 | class QAxObject;
|
|---|
| 62 | class QAxBasePrivate;
|
|---|
| 63 | struct QAxMetaObject;
|
|---|
| 64 |
|
|---|
| 65 | class QAxBase
|
|---|
| 66 | {
|
|---|
| 67 | QDOC_PROPERTY(QString control READ control WRITE setControl)
|
|---|
| 68 |
|
|---|
| 69 | public:
|
|---|
| 70 | typedef QMap<QString, QVariant> PropertyBag;
|
|---|
| 71 |
|
|---|
| 72 | QAxBase(IUnknown *iface = 0);
|
|---|
| 73 | virtual ~QAxBase();
|
|---|
| 74 |
|
|---|
| 75 | QString control() const;
|
|---|
| 76 |
|
|---|
| 77 | long queryInterface(const QUuid &, void**) const;
|
|---|
| 78 |
|
|---|
| 79 | QVariant dynamicCall(const char *name, const QVariant &v1 = QVariant(),
|
|---|
| 80 | const QVariant &v2 = QVariant(),
|
|---|
| 81 | const QVariant &v3 = QVariant(),
|
|---|
| 82 | const QVariant &v4 = QVariant(),
|
|---|
| 83 | const QVariant &v5 = QVariant(),
|
|---|
| 84 | const QVariant &v6 = QVariant(),
|
|---|
| 85 | const QVariant &v7 = QVariant(),
|
|---|
| 86 | const QVariant &v8 = QVariant());
|
|---|
| 87 | QVariant dynamicCall(const char *name, QList<QVariant> &vars);
|
|---|
| 88 | QAxObject *querySubObject(const char *name, const QVariant &v1 = QVariant(),
|
|---|
| 89 | const QVariant &v2 = QVariant(),
|
|---|
| 90 | const QVariant &v3 = QVariant(),
|
|---|
| 91 | const QVariant &v4 = QVariant(),
|
|---|
| 92 | const QVariant &v5 = QVariant(),
|
|---|
| 93 | const QVariant &v6 = QVariant(),
|
|---|
| 94 | const QVariant &v7 = QVariant(),
|
|---|
| 95 | const QVariant &v8 = QVariant());
|
|---|
| 96 | QAxObject* querySubObject(const char *name, QList<QVariant> &vars);
|
|---|
| 97 |
|
|---|
| 98 | virtual const QMetaObject *metaObject() const;
|
|---|
| 99 | virtual int qt_metacall(QMetaObject::Call, int, void **);
|
|---|
| 100 |
|
|---|
| 101 | virtual QObject *qObject() const = 0;
|
|---|
| 102 | virtual const char *className() const = 0;
|
|---|
| 103 |
|
|---|
| 104 | PropertyBag propertyBag() const;
|
|---|
| 105 | void setPropertyBag(const PropertyBag&);
|
|---|
| 106 |
|
|---|
| 107 | QString generateDocumentation();
|
|---|
| 108 |
|
|---|
| 109 | virtual bool propertyWritable(const char*) const;
|
|---|
| 110 | virtual void setPropertyWritable(const char*, bool);
|
|---|
| 111 |
|
|---|
| 112 | bool isNull() const;
|
|---|
| 113 |
|
|---|
| 114 | QStringList verbs() const;
|
|---|
| 115 |
|
|---|
| 116 | QVariant asVariant() const;
|
|---|
| 117 |
|
|---|
| 118 | #ifdef qdoc
|
|---|
| 119 | Q_SIGNALS:
|
|---|
| 120 | void signal(const QString&,int,void*);
|
|---|
| 121 | void propertyChanged(const QString&);
|
|---|
| 122 | void exception(int,const QString&,const QString&,const QString&);
|
|---|
| 123 | #endif
|
|---|
| 124 |
|
|---|
| 125 | public:
|
|---|
| 126 | virtual void clear();
|
|---|
| 127 | bool setControl(const QString&);
|
|---|
| 128 |
|
|---|
| 129 | void disableMetaObject();
|
|---|
| 130 | void disableClassInfo();
|
|---|
| 131 | void disableEventSink();
|
|---|
| 132 |
|
|---|
| 133 | protected:
|
|---|
| 134 | virtual bool initialize(IUnknown** ptr);
|
|---|
| 135 | bool initializeRemote(IUnknown** ptr);
|
|---|
| 136 | bool initializeLicensed(IUnknown** ptr);
|
|---|
| 137 | bool initializeActive(IUnknown** ptr);
|
|---|
| 138 | bool initializeFromFile(IUnknown** ptr);
|
|---|
| 139 |
|
|---|
| 140 | void internalRelease();
|
|---|
| 141 | void initializeFrom(QAxBase *that);
|
|---|
| 142 | void connectNotify();
|
|---|
| 143 | long indexOfVerb(const QString &verb) const;
|
|---|
| 144 |
|
|---|
| 145 | private:
|
|---|
| 146 | friend class QAxEventSink;
|
|---|
| 147 | friend void *qax_createObjectWrapper(int, IUnknown*);
|
|---|
| 148 | bool initializeLicensedHelper(void *factory, const QString &key, IUnknown **ptr);
|
|---|
| 149 | QAxBasePrivate *d;
|
|---|
| 150 | QAxMetaObject *internalMetaObject() const;
|
|---|
| 151 |
|
|---|
| 152 | virtual const QMetaObject *parentMetaObject() const = 0;
|
|---|
| 153 | int internalProperty(QMetaObject::Call, int index, void **v);
|
|---|
| 154 | int internalInvoke(QMetaObject::Call, int index, void **v);
|
|---|
| 155 | bool dynamicCallHelper(const char *name, void *out, QList<QVariant> &var, QByteArray &type);
|
|---|
| 156 |
|
|---|
| 157 | static QMetaObject staticMetaObject;
|
|---|
| 158 | };
|
|---|
| 159 |
|
|---|
| 160 | #if defined Q_CC_MSVC && _MSC_VER < 1300
|
|---|
| 161 | template <> inline QAxBase *qobject_cast_helper<QAxBase*>(const QObject *o, QAxBase *)
|
|---|
| 162 | #else
|
|---|
| 163 | template <> inline QAxBase *qobject_cast<QAxBase*>(const QObject *o)
|
|---|
| 164 | #endif
|
|---|
| 165 | {
|
|---|
| 166 | void *result = o ? const_cast<QObject *>(o)->qt_metacast("QAxBase") : 0;
|
|---|
| 167 | return (QAxBase*)(result);
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | #if defined Q_CC_MSVC && _MSC_VER < 1300
|
|---|
| 171 | template <> inline QAxBase *qobject_cast_helper<QAxBase*>(QObject *o, QAxBase *)
|
|---|
| 172 | #else
|
|---|
| 173 | template <> inline QAxBase *qobject_cast<QAxBase*>(QObject *o)
|
|---|
| 174 | #endif
|
|---|
| 175 | {
|
|---|
| 176 | void *result = o ? o->qt_metacast("QAxBase") : 0;
|
|---|
| 177 | return (QAxBase*)(result);
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | extern QString qax_generateDocumentation(QAxBase *);
|
|---|
| 181 |
|
|---|
| 182 | inline QString QAxBase::generateDocumentation()
|
|---|
| 183 | {
|
|---|
| 184 | return qax_generateDocumentation(this);
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | #ifndef QT_NO_DATASTREAM
|
|---|
| 188 | inline QDataStream &operator >>(QDataStream &s, QAxBase &c)
|
|---|
| 189 | {
|
|---|
| 190 | QAxBase::PropertyBag bag;
|
|---|
| 191 | c.qObject()->blockSignals(true);
|
|---|
| 192 | QString control;
|
|---|
| 193 | s >> control;
|
|---|
| 194 | c.setControl(control);
|
|---|
| 195 | s >> bag;
|
|---|
| 196 | c.setPropertyBag(bag);
|
|---|
| 197 | c.qObject()->blockSignals(false);
|
|---|
| 198 |
|
|---|
| 199 | return s;
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | inline QDataStream &operator <<(QDataStream &s, const QAxBase &c)
|
|---|
| 203 | {
|
|---|
| 204 | QAxBase::PropertyBag bag = c.propertyBag();
|
|---|
| 205 | s << c.control();
|
|---|
| 206 | s << bag;
|
|---|
| 207 |
|
|---|
| 208 | return s;
|
|---|
| 209 | }
|
|---|
| 210 | #endif // QT_NO_DATASTREAM
|
|---|
| 211 |
|
|---|
| 212 | QT_END_NAMESPACE
|
|---|
| 213 |
|
|---|
| 214 | #ifndef Q_COM_METATYPE_DECLARED
|
|---|
| 215 | #define Q_COM_METATYPE_DECLARED
|
|---|
| 216 |
|
|---|
| 217 | Q_DECLARE_METATYPE(IUnknown*)
|
|---|
| 218 | Q_DECLARE_METATYPE(IDispatch*)
|
|---|
| 219 |
|
|---|
| 220 | #endif
|
|---|
| 221 |
|
|---|
| 222 | #endif // QT_NO_WIN_ACTIVEQT
|
|---|
| 223 |
|
|---|
| 224 | QT_END_HEADER
|
|---|
| 225 |
|
|---|
| 226 | #endif // QAXBASE_H
|
|---|