1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
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 UNICODE
|
---|
41 | #define UNICODE
|
---|
42 | #endif
|
---|
43 |
|
---|
44 | #include "qaxobject.h"
|
---|
45 |
|
---|
46 | #ifndef QT_NO_WIN_ACTIVEQT
|
---|
47 |
|
---|
48 | #include <quuid.h>
|
---|
49 | #include <qmetaobject.h>
|
---|
50 | #include <qstringlist.h>
|
---|
51 |
|
---|
52 | #include <windows.h>
|
---|
53 |
|
---|
54 | QT_BEGIN_NAMESPACE
|
---|
55 |
|
---|
56 | /*!
|
---|
57 | \class QAxObject
|
---|
58 | \brief The QAxObject class provides a QObject that wraps a COM object.
|
---|
59 |
|
---|
60 | \inmodule QAxContainer
|
---|
61 |
|
---|
62 | A QAxObject can be instantiated as an empty object, with the name
|
---|
63 | of the COM object it should wrap, or with a pointer to the
|
---|
64 | IUnknown that represents an existing COM object. If the COM object
|
---|
65 | implements the \c IDispatch interface, the properties, methods and
|
---|
66 | events of that object become available as Qt properties, slots and
|
---|
67 | signals. The base class, QAxBase, provides an API to access the
|
---|
68 | COM object directly through the IUnknown pointer.
|
---|
69 |
|
---|
70 | QAxObject is a QObject and can be used as such, e.g. it can be
|
---|
71 | organized in an object hierarchy, receive events and connect to
|
---|
72 | signals and slots.
|
---|
73 |
|
---|
74 | QAxObject also inherits most of its ActiveX-related functionality
|
---|
75 | from QAxBase, notably dynamicCall() and querySubObject().
|
---|
76 |
|
---|
77 | \warning
|
---|
78 | You can subclass QAxObject, but you cannot use the Q_OBJECT macro
|
---|
79 | in the subclass (the generated moc-file will not compile), so you
|
---|
80 | cannot add further signals, slots or properties. This limitation is
|
---|
81 | due to the metaobject information generated in runtime.
|
---|
82 | To work around this problem, aggregate the QAxObject as a member of
|
---|
83 | the QObject subclass.
|
---|
84 |
|
---|
85 | \sa QAxBase, QAxWidget, QAxScript, {ActiveQt Framework}
|
---|
86 | */
|
---|
87 |
|
---|
88 | /*!
|
---|
89 | Creates an empty COM object and propagates \a parent to the
|
---|
90 | QObject constructor. To initialize the object, call \link
|
---|
91 | QAxBase::setControl() setControl \endlink.
|
---|
92 | */
|
---|
93 | QAxObject::QAxObject(QObject *parent)
|
---|
94 | : QObject(parent)
|
---|
95 | {
|
---|
96 | }
|
---|
97 |
|
---|
98 | /*!
|
---|
99 | Creates a QAxObject that wraps the COM object \a c. \a parent is
|
---|
100 | propagated to the QObject constructor.
|
---|
101 |
|
---|
102 | \sa setControl()
|
---|
103 | */
|
---|
104 | QAxObject::QAxObject(const QString &c, QObject *parent)
|
---|
105 | : QObject(parent)
|
---|
106 | {
|
---|
107 | setControl(c);
|
---|
108 | }
|
---|
109 |
|
---|
110 | /*!
|
---|
111 | Creates a QAxObject that wraps the COM object referenced by \a
|
---|
112 | iface. \a parent is propagated to the QObject constructor.
|
---|
113 | */
|
---|
114 | QAxObject::QAxObject(IUnknown *iface, QObject *parent)
|
---|
115 | : QObject(parent), QAxBase(iface)
|
---|
116 | {
|
---|
117 | }
|
---|
118 |
|
---|
119 | /*!
|
---|
120 | Releases the COM object and destroys the QAxObject,
|
---|
121 | cleaning up all allocated resources.
|
---|
122 | */
|
---|
123 | QAxObject::~QAxObject()
|
---|
124 | {
|
---|
125 | clear();
|
---|
126 | }
|
---|
127 |
|
---|
128 | /*!
|
---|
129 | \reimp
|
---|
130 | */
|
---|
131 | const QMetaObject *QAxObject::metaObject() const
|
---|
132 | {
|
---|
133 | return QAxBase::metaObject();
|
---|
134 | }
|
---|
135 |
|
---|
136 | /*!
|
---|
137 | \reimp
|
---|
138 | */
|
---|
139 | const QMetaObject *QAxObject::parentMetaObject() const
|
---|
140 | {
|
---|
141 | return &QObject::staticMetaObject;
|
---|
142 | }
|
---|
143 |
|
---|
144 | /*!
|
---|
145 | \internal
|
---|
146 | */
|
---|
147 | void *QAxObject::qt_metacast(const char *cname)
|
---|
148 | {
|
---|
149 | if (!qstrcmp(cname, "QAxObject")) return (void*)this;
|
---|
150 | if (!qstrcmp(cname, "QAxBase")) return (QAxBase*)this;
|
---|
151 | return QObject::qt_metacast(cname);
|
---|
152 | }
|
---|
153 |
|
---|
154 | /*!
|
---|
155 | \reimp
|
---|
156 | */
|
---|
157 | const char *QAxObject::className() const
|
---|
158 | {
|
---|
159 | return "QAxObject";
|
---|
160 | }
|
---|
161 |
|
---|
162 | /*!
|
---|
163 | \reimp
|
---|
164 | */
|
---|
165 | int QAxObject::qt_metacall(QMetaObject::Call call, int id, void **v)
|
---|
166 | {
|
---|
167 | id = QObject::qt_metacall(call, id, v);
|
---|
168 | if (id < 0)
|
---|
169 | return id;
|
---|
170 | return QAxBase::qt_metacall(call, id, v);
|
---|
171 | }
|
---|
172 |
|
---|
173 | /*!
|
---|
174 | \fn QObject *QAxObject::qObject() const
|
---|
175 | \internal
|
---|
176 | */
|
---|
177 |
|
---|
178 | /*!
|
---|
179 | \reimp
|
---|
180 | */
|
---|
181 | void QAxObject::connectNotify(const char *)
|
---|
182 | {
|
---|
183 | QAxBase::connectNotify();
|
---|
184 | }
|
---|
185 |
|
---|
186 | /*!
|
---|
187 | \since 4.1
|
---|
188 |
|
---|
189 | Requests the COM object to perform the action \a verb. The
|
---|
190 | possible verbs are returned by verbs().
|
---|
191 |
|
---|
192 | The function returns true if the object could perform the action, otherwise returns false.
|
---|
193 | */
|
---|
194 | bool QAxObject::doVerb(const QString &verb)
|
---|
195 | {
|
---|
196 | if (!verbs().contains(verb))
|
---|
197 | return false;
|
---|
198 | IOleObject *ole = 0;
|
---|
199 | queryInterface(IID_IOleObject, (void**)&ole);
|
---|
200 | if (!ole)
|
---|
201 | return false;
|
---|
202 |
|
---|
203 | LONG index = indexOfVerb(verb);
|
---|
204 |
|
---|
205 | HRESULT hres = ole->DoVerb(index, 0, 0, 0, 0, 0);
|
---|
206 |
|
---|
207 | ole->Release();
|
---|
208 |
|
---|
209 | return hres == S_OK;
|
---|
210 | }
|
---|
211 |
|
---|
212 | QT_END_NAMESPACE
|
---|
213 | #endif // QT_NO_WIN_ACTIVEQT
|
---|