author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Mon, 19 Apr 2010 10:15:19 +0300 | |
branch | RCL_3 |
changeset 9 | b5b118452c7d |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the ActiveQt framework of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:BSD$ |
|
10 |
** You may use this file under the terms of the BSD license as follows: |
|
11 |
** |
|
12 |
** "Redistribution and use in source and binary forms, with or without |
|
13 |
** modification, are permitted provided that the following conditions are |
|
14 |
** met: |
|
15 |
** * Redistributions of source code must retain the above copyright |
|
16 |
** notice, this list of conditions and the following disclaimer. |
|
17 |
** * Redistributions in binary form must reproduce the above copyright |
|
18 |
** notice, this list of conditions and the following disclaimer in |
|
19 |
** the documentation and/or other materials provided with the |
|
20 |
** distribution. |
|
21 |
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor |
|
22 |
** the names of its contributors may be used to endorse or promote |
|
23 |
** products derived from this software without specific prior written |
|
24 |
** permission. |
|
25 |
** |
|
26 |
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
27 |
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
28 |
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
29 |
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
30 |
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
31 |
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
32 |
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
33 |
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
34 |
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
35 |
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
36 |
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
|
37 |
** $QT_END_LICENSE$ |
|
38 |
** |
|
39 |
****************************************************************************/ |
|
40 |
||
41 |
#include "qaxobject.h" |
|
42 |
||
43 |
#ifndef QT_NO_WIN_ACTIVEQT |
|
44 |
||
45 |
#include <quuid.h> |
|
46 |
#include <qmetaobject.h> |
|
47 |
#include <qstringlist.h> |
|
48 |
||
49 |
#include <windows.h> |
|
50 |
||
51 |
QT_BEGIN_NAMESPACE |
|
52 |
||
53 |
/*! |
|
54 |
\class QAxObject |
|
55 |
\brief The QAxObject class provides a QObject that wraps a COM object. |
|
56 |
||
57 |
\inmodule QAxContainer |
|
58 |
||
59 |
A QAxObject can be instantiated as an empty object, with the name |
|
60 |
of the COM object it should wrap, or with a pointer to the |
|
61 |
IUnknown that represents an existing COM object. If the COM object |
|
62 |
implements the \c IDispatch interface, the properties, methods and |
|
63 |
events of that object become available as Qt properties, slots and |
|
64 |
signals. The base class, QAxBase, provides an API to access the |
|
65 |
COM object directly through the IUnknown pointer. |
|
66 |
||
67 |
QAxObject is a QObject and can be used as such, e.g. it can be |
|
68 |
organized in an object hierarchy, receive events and connect to |
|
69 |
signals and slots. |
|
70 |
||
71 |
QAxObject also inherits most of its ActiveX-related functionality |
|
72 |
from QAxBase, notably dynamicCall() and querySubObject(). |
|
73 |
||
74 |
\warning |
|
75 |
You can subclass QAxObject, but you cannot use the Q_OBJECT macro |
|
76 |
in the subclass (the generated moc-file will not compile), so you |
|
77 |
cannot add further signals, slots or properties. This limitation is |
|
78 |
due to the metaobject information generated in runtime. |
|
79 |
To work around this problem, aggregate the QAxObject as a member of |
|
80 |
the QObject subclass. |
|
81 |
||
82 |
\sa QAxBase, QAxWidget, QAxScript, {ActiveQt Framework} |
|
83 |
*/ |
|
84 |
||
85 |
/*! |
|
86 |
Creates an empty COM object and propagates \a parent to the |
|
87 |
QObject constructor. To initialize the object, call \link |
|
88 |
QAxBase::setControl() setControl \endlink. |
|
89 |
*/ |
|
90 |
QAxObject::QAxObject(QObject *parent) |
|
91 |
: QObject(parent) |
|
92 |
{ |
|
93 |
} |
|
94 |
||
95 |
/*! |
|
96 |
Creates a QAxObject that wraps the COM object \a c. \a parent is |
|
97 |
propagated to the QObject constructor. |
|
98 |
||
99 |
\sa setControl() |
|
100 |
*/ |
|
101 |
QAxObject::QAxObject(const QString &c, QObject *parent) |
|
102 |
: QObject(parent) |
|
103 |
{ |
|
104 |
setControl(c); |
|
105 |
} |
|
106 |
||
107 |
/*! |
|
108 |
Creates a QAxObject that wraps the COM object referenced by \a |
|
109 |
iface. \a parent is propagated to the QObject constructor. |
|
110 |
*/ |
|
111 |
QAxObject::QAxObject(IUnknown *iface, QObject *parent) |
|
112 |
: QObject(parent), QAxBase(iface) |
|
113 |
{ |
|
114 |
} |
|
115 |
||
116 |
/*! |
|
117 |
Releases the COM object and destroys the QAxObject, |
|
118 |
cleaning up all allocated resources. |
|
119 |
*/ |
|
120 |
QAxObject::~QAxObject() |
|
121 |
{ |
|
122 |
clear(); |
|
123 |
} |
|
124 |
||
125 |
/*! |
|
126 |
\internal |
|
127 |
*/ |
|
128 |
const QMetaObject *QAxObject::metaObject() const |
|
129 |
{ |
|
130 |
return QAxBase::metaObject(); |
|
131 |
} |
|
132 |
||
133 |
/*! |
|
134 |
\internal |
|
135 |
*/ |
|
136 |
const QMetaObject *QAxObject::parentMetaObject() const |
|
137 |
{ |
|
138 |
return &QObject::staticMetaObject; |
|
139 |
} |
|
140 |
||
141 |
/*! |
|
142 |
\internal |
|
143 |
*/ |
|
144 |
void *QAxObject::qt_metacast(const char *cname) |
|
145 |
{ |
|
146 |
if (!qstrcmp(cname, "QAxObject")) return (void*)this; |
|
147 |
if (!qstrcmp(cname, "QAxBase")) return (QAxBase*)this; |
|
148 |
return QObject::qt_metacast(cname); |
|
149 |
} |
|
150 |
||
151 |
/*! |
|
152 |
\internal |
|
153 |
*/ |
|
154 |
const char *QAxObject::className() const |
|
155 |
{ |
|
156 |
return "QAxObject"; |
|
157 |
} |
|
158 |
||
159 |
/*! |
|
160 |
\internal |
|
161 |
*/ |
|
162 |
int QAxObject::qt_metacall(QMetaObject::Call call, int id, void **v) |
|
163 |
{ |
|
164 |
id = QObject::qt_metacall(call, id, v); |
|
165 |
if (id < 0) |
|
166 |
return id; |
|
167 |
return QAxBase::qt_metacall(call, id, v); |
|
168 |
} |
|
169 |
||
170 |
/*! |
|
171 |
\fn QObject *QAxObject::qObject() const |
|
172 |
\internal |
|
173 |
*/ |
|
174 |
||
175 |
/*! |
|
176 |
\reimp |
|
177 |
*/ |
|
178 |
void QAxObject::connectNotify(const char *) |
|
179 |
{ |
|
180 |
QAxBase::connectNotify(); |
|
181 |
} |
|
182 |
||
183 |
/*! |
|
184 |
\since 4.1 |
|
185 |
||
186 |
Requests the COM object to perform the action \a verb. The |
|
187 |
possible verbs are returned by verbs(). |
|
188 |
||
189 |
The function returns true if the object could perform the action, otherwise returns false. |
|
190 |
*/ |
|
191 |
bool QAxObject::doVerb(const QString &verb) |
|
192 |
{ |
|
193 |
if (!verbs().contains(verb)) |
|
194 |
return false; |
|
195 |
IOleObject *ole = 0; |
|
196 |
queryInterface(IID_IOleObject, (void**)&ole); |
|
197 |
if (!ole) |
|
198 |
return false; |
|
199 |
||
200 |
LONG index = indexOfVerb(verb); |
|
201 |
||
202 |
HRESULT hres = ole->DoVerb(index, 0, 0, 0, 0, 0); |
|
203 |
||
204 |
ole->Release(); |
|
205 |
||
206 |
return hres == S_OK; |
|
207 |
} |
|
208 |
||
209 |
QT_END_NAMESPACE |
|
210 |
#endif // QT_NO_WIN_ACTIVEQT |