Qt 4.8
qaxbase.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia Plc and its Subsidiary(-ies) nor the names
21 ** of its contributors may be used to endorse or promote products derived
22 ** from this software without specific prior written permission.
23 **
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 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40 
41 #ifndef QAXBASE_H
42 #define QAXBASE_H
43 
44 #include <QtCore/qdatastream.h>
45 #include <QtCore/qmap.h>
46 #include <QtCore/qobject.h>
47 #include <QtCore/qvariant.h>
48 
49 struct IUnknown;
50 struct IDispatch;
51 
53 
55 
56 QT_MODULE(ActiveQt)
57 
58 #ifndef QT_NO_WIN_ACTIVEQT
59 
60 struct QUuid;
61 class QAxEventSink;
62 class QAxObject;
63 class QAxBasePrivate;
64 struct QAxMetaObject;
65 
66 class QAxBase
67 {
69 
70 public:
72 
73  QAxBase(IUnknown *iface = 0);
74  virtual ~QAxBase();
75 
76  QString control() const;
77 
78  long queryInterface(const QUuid &, void**) const;
79 
80  QVariant dynamicCall(const char *name, const QVariant &v1 = QVariant(),
81  const QVariant &v2 = QVariant(),
82  const QVariant &v3 = QVariant(),
83  const QVariant &v4 = QVariant(),
84  const QVariant &v5 = QVariant(),
85  const QVariant &v6 = QVariant(),
86  const QVariant &v7 = QVariant(),
87  const QVariant &v8 = QVariant());
88  QVariant dynamicCall(const char *name, QList<QVariant> &vars);
89  QAxObject *querySubObject(const char *name, const QVariant &v1 = QVariant(),
90  const QVariant &v2 = QVariant(),
91  const QVariant &v3 = QVariant(),
92  const QVariant &v4 = QVariant(),
93  const QVariant &v5 = QVariant(),
94  const QVariant &v6 = QVariant(),
95  const QVariant &v7 = QVariant(),
96  const QVariant &v8 = QVariant());
97  QAxObject* querySubObject(const char *name, QList<QVariant> &vars);
98 
99  virtual const QMetaObject *metaObject() const;
100  virtual int qt_metacall(QMetaObject::Call, int, void **);
101 
102  virtual QObject *qObject() const = 0;
103  virtual const char *className() const = 0;
104 
105  PropertyBag propertyBag() const;
106  void setPropertyBag(const PropertyBag&);
107 
109 
110  virtual bool propertyWritable(const char*) const;
111  virtual void setPropertyWritable(const char*, bool);
112 
113  bool isNull() const;
114 
115  QStringList verbs() const;
116 
117  QVariant asVariant() const;
118 
119 #ifdef qdoc
120 Q_SIGNALS:
121  void signal(const QString&,int,void*);
122  void propertyChanged(const QString&);
123  void exception(int,const QString&,const QString&,const QString&);
124 #endif
125 
126 public:
127  virtual void clear();
128  bool setControl(const QString&);
129 
130  void disableMetaObject();
131  void disableClassInfo();
132  void disableEventSink();
133 
134 protected:
135  virtual bool initialize(IUnknown** ptr);
136  bool initializeRemote(IUnknown** ptr);
137  bool initializeLicensed(IUnknown** ptr);
138  bool initializeActive(IUnknown** ptr);
139  bool initializeFromFile(IUnknown** ptr);
140 
141  void internalRelease();
142  void initializeFrom(QAxBase *that);
143  void connectNotify();
144  long indexOfVerb(const QString &verb) const;
145 
146 private:
147  friend class QAxEventSink;
148  friend void *qax_createObjectWrapper(int, IUnknown*);
149  bool initializeLicensedHelper(void *factory, const QString &key, IUnknown **ptr);
152 
153  virtual const QMetaObject *parentMetaObject() const = 0;
154  int internalProperty(QMetaObject::Call, int index, void **v);
155  int internalInvoke(QMetaObject::Call, int index, void **v);
156  bool dynamicCallHelper(const char *name, void *out, QList<QVariant> &var, QByteArray &type);
157 
159 };
160 
161 #if defined Q_CC_MSVC && _MSC_VER < 1300
162 template <> inline QAxBase *qobject_cast_helper<QAxBase*>(const QObject *o, QAxBase *)
163 #else
164 template <> inline QAxBase *qobject_cast<QAxBase*>(const QObject *o)
165 #endif
166 {
167  void *result = o ? const_cast<QObject *>(o)->qt_metacast("QAxBase") : 0;
168  return (QAxBase*)(result);
169 }
170 
171 #if defined Q_CC_MSVC && _MSC_VER < 1300
172 template <> inline QAxBase *qobject_cast_helper<QAxBase*>(QObject *o, QAxBase *)
173 #else
174 template <> inline QAxBase *qobject_cast<QAxBase*>(QObject *o)
175 #endif
176 {
177  void *result = o ? o->qt_metacast("QAxBase") : 0;
178  return (QAxBase*)(result);
179 }
180 
182 
184 {
185  return qax_generateDocumentation(this);
186 }
187 
188 #ifndef QT_NO_DATASTREAM
190 {
192  c.qObject()->blockSignals(true);
194  s >> control;
195  c.setControl(control);
196  s >> bag;
197  c.setPropertyBag(bag);
198  c.qObject()->blockSignals(false);
199 
200  return s;
201 }
202 
204 {
206  s << c.control();
207  s << bag;
208 
209  return s;
210 }
211 #endif // QT_NO_DATASTREAM
212 
214 
215 #ifndef Q_COM_METATYPE_DECLARED
216 #define Q_COM_METATYPE_DECLARED
217 
218 Q_DECLARE_METATYPE(IUnknown*)
219 Q_DECLARE_METATYPE(IDispatch*)
220 
221 #endif
222 
223 #endif // QT_NO_WIN_ACTIVEQT
224 
226 
227 #endif // QAXBASE_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QStringList verbs() const
Returns the list of verbs that the COM object can execute.
Definition: qaxbase.cpp:1137
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QString qax_generateDocumentation(QAxBase *)
Definition: qaxdump.cpp:130
bool blockSignals(bool b)
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke...
Definition: qobject.cpp:1406
bool isNull() const
Returns true if there is no COM object loaded by this wrapper; otherwise return false.
Definition: qaxbase.cpp:4412
int type
Definition: qmetatype.cpp:239
unsigned char c[8]
Definition: qnumeric_p.h:62
virtual ~QAxBase()
Shuts down the COM object and destroys the QAxBase object.
Definition: qaxbase.cpp:868
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual const QMetaObject * metaObject() const
The metaobject is generated on the fly from the information provided by the IDispatch and ITypeInfo i...
Definition: qaxbase.cpp:3245
#define QDOC_PROPERTY(text)
Definition: qglobal.h:2503
#define QT_MODULE(x)
Definition: qglobal.h:2783
QVariant dynamicCall(const char *name, const QVariant &v1=QVariant(), const QVariant &v2=QVariant(), const QVariant &v3=QVariant(), const QVariant &v4=QVariant(), const QVariant &v5=QVariant(), const QVariant &v6=QVariant(), const QVariant &v7=QVariant(), const QVariant &v8=QVariant())
Calls the COM object&#39;s method function, passing the parameters var1, var1, var2, var3, var4, var5, var6, var7 and var8, and returns the value returned by the method, or an invalid QVariant if the method does not return a value or when the function call failed.
Definition: qaxbase.cpp:4046
QVariant asVariant() const
Returns a QVariant that wraps the COM object.
Definition: qaxbase.cpp:4421
void signal(const QString &, int, void *)
This generic signal gets emitted when the COM object issues the event name.
bool initializeActive(IUnknown **ptr)
Connects to an active instance running on the current machine, and returns the IUnknown interface to ...
Definition: qaxbase.cpp:1321
bool dynamicCallHelper(const char *name, void *out, QList< QVariant > &var, QByteArray &type)
Definition: qaxbase.cpp:3784
void initializeFrom(QAxBase *that)
Used by subclasses generated with dumpcpp to implement cast-operators.
Definition: qaxbase.cpp:902
QString control() const
the name of the COM object wrapped by this QAxBase object.
Definition: qaxbase.cpp:1029
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
bool initializeRemote(IUnknown **ptr)
Creates the instance on a remote server, and returns the IUnknown interface to the object in ptr...
Definition: qaxbase.cpp:1390
virtual QObject * qObject() const =0
void internalRelease()
Used by subclasses generated with dumpcpp to balance reference count.
Definition: qaxbase.cpp:888
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void disableClassInfo()
Disables the class info generation for this ActiveX container.
Definition: qaxbase.cpp:1083
void setPropertyBag(const PropertyBag &)
Sets the properties of the COM object to the corresponding values in bag.
Definition: qaxbase.cpp:4347
virtual void setPropertyWritable(const char *, bool)
Sets the property prop to writable if ok is true, otherwise sets prop to be read-only.
Definition: qaxbase.cpp:4401
QString generateDocumentation()
Returns a rich text string with documentation for the wrapped COM object.
Definition: qaxbase.h:183
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QAxObject class provides a QObject that wraps a COM object.
Definition: qaxobject.h:54
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
QMap< QString, QVariant > PropertyBag
A QMap<QString,QVariant> that can store properties as name:value pairs.
Definition: qaxbase.h:71
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QAxObject * querySubObject(const char *name, const QVariant &v1=QVariant(), const QVariant &v2=QVariant(), const QVariant &v3=QVariant(), const QVariant &v4=QVariant(), const QVariant &v5=QVariant(), const QVariant &v6=QVariant(), const QVariant &v7=QVariant(), const QVariant &v8=QVariant())
Returns a pointer to a QAxObject wrapping the COM object provided by the method or property name...
Definition: qaxbase.cpp:4130
virtual const char * className() const =0
virtual const QMetaObject * parentMetaObject() const =0
int internalProperty(QMetaObject::Call, int index, void **v)
Definition: qaxbase.cpp:3476
int internalInvoke(QMetaObject::Call, int index, void **v)
Definition: qaxbase.cpp:3593
const char * name
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QAxBasePrivate * d
Definition: qaxbase.h:150
virtual int qt_metacall(QMetaObject::Call, int, void **)
Definition: qaxbase.cpp:3705
void connectNotify()
Connects to all event interfaces of the object.
Definition: qaxbase.cpp:3282
bool setControl(const QString &)
Definition: qaxbase.cpp:975
void propertyChanged(const QString &)
If the COM object supports property notification, this signal gets emitted when the property called n...
const T * ptr(const T &t)
virtual bool propertyWritable(const char *) const
Returns true if the property prop is writable; otherwise returns false.
Definition: qaxbase.cpp:4385
bool initializeLicensedHelper(void *factory, const QString &key, IUnknown **ptr)
Definition: qaxbase.cpp:1261
friend void * qax_createObjectWrapper(int, IUnknown *)
Definition: qaxbase.cpp:4448
#define Q_DECLARE_METATYPE(TYPE)
This macro makes the type Type known to QMetaType as long as it provides a public default constructor...
Definition: qmetatype.h:265
bool initializeFromFile(IUnknown **ptr)
Creates the COM object handling the filename in the control property, and returns the IUnknown interf...
Definition: qaxbase.cpp:1352
void disableMetaObject()
Disables the meta object generation for this ActiveX container.
Definition: qaxbase.cpp:1068
void exception(int, const QString &, const QString &, const QString &)
This signal is emitted when the COM object throws an exception while called using the OLE automation ...
long indexOfVerb(const QString &verb) const
Definition: qaxbase.cpp:1172
QDataStream & operator>>(QDataStream &s, QAxBase &c)
Definition: qaxbase.h:189
QAxMetaObject * internalMetaObject() const
Definition: qaxbase.cpp:915
PropertyBag propertyBag() const
Returns a name:value map of all the properties exposed by the COM object.
Definition: qaxbase.cpp:4303
int key
bool initializeLicensed(IUnknown **ptr)
Creates an instance of a licensed control, and returns the IUnknown interface to the object in ptr...
Definition: qaxbase.cpp:1240
quint16 index
void disableEventSink()
Disables the event sink implementation for this ActiveX container.
Definition: qaxbase.cpp:1047
QDataStream & operator<<(QDataStream &s, const QAxBase &c)
Definition: qaxbase.h:203
static QMetaObject staticMetaObject
Definition: qaxbase.h:158
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:71
long queryInterface(const QUuid &, void **) const
Requests the interface uuid from the COM object and sets the value of iface to the provided interface...
Definition: qaxbase.cpp:1479
virtual void clear()
Disconnects and destroys the COM object.
Definition: qaxbase.cpp:1095
QAxBase(IUnknown *iface=0)
Creates a QAxBase object that wraps the COM object iface.
Definition: qaxbase.cpp:850
virtual bool initialize(IUnknown **ptr)
This virtual function is called by setControl() and creates the requested COM object.
Definition: qaxbase.cpp:1199
#define QT_END_HEADER
Definition: qglobal.h:137
The QAxBase class is an abstract class that provides an API to initialize and access a COM object...
Definition: qaxbase.h:66
The QUuid class stores a Universally Unique Identifier (UUID).
Definition: quuid.h:67