| 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 | #include "qaxbindable.h"
|
|---|
| 41 |
|
|---|
| 42 | #ifndef QT_NO_WIN_ACTIVEQT
|
|---|
| 43 |
|
|---|
| 44 | #include <qmetaobject.h>
|
|---|
| 45 |
|
|---|
| 46 | #include <qt_windows.h> // for IUnknown
|
|---|
| 47 | #include "../shared/qaxtypes.h"
|
|---|
| 48 |
|
|---|
| 49 | QT_BEGIN_NAMESPACE
|
|---|
| 50 |
|
|---|
| 51 | /*!
|
|---|
| 52 | \class QAxBindable
|
|---|
| 53 | \brief The QAxBindable class provides an interface between a
|
|---|
| 54 | QWidget and an ActiveX client.
|
|---|
| 55 |
|
|---|
| 56 | \inmodule QAxServer
|
|---|
| 57 |
|
|---|
| 58 | The functions provided by this class allow an ActiveX control to
|
|---|
| 59 | communicate property changes to a client application. Inherit
|
|---|
| 60 | your control class from both QWidget (directly or indirectly) and
|
|---|
| 61 | this class to get access to this class's functions. The
|
|---|
| 62 | \l{moc}{meta-object compiler} requires you to inherit from
|
|---|
| 63 | QWidget first.
|
|---|
| 64 |
|
|---|
| 65 | \snippet doc/src/snippets/code/src_activeqt_control_qaxbindable.cpp 0
|
|---|
| 66 |
|
|---|
| 67 | When implementing the property write function, use
|
|---|
| 68 | requestPropertyChange() to get permission from the ActiveX client
|
|---|
| 69 | application to change this property. When the property changes,
|
|---|
| 70 | call propertyChanged() to notify the ActiveX client application
|
|---|
| 71 | about the change. If a fatal error occurs in the control, use the
|
|---|
| 72 | static reportError() function to notify the client.
|
|---|
| 73 |
|
|---|
| 74 | Use the interface returned by clientSite() to call the ActiveX
|
|---|
| 75 | client. To implement additional COM interfaces in your ActiveX
|
|---|
| 76 | control, reimplement createAggregate() to return a new object of a
|
|---|
| 77 | QAxAggregated subclass.
|
|---|
| 78 |
|
|---|
| 79 | The ActiveQt \l{activeqt/opengl}{OpenGL} example shows how to use
|
|---|
| 80 | QAxBindable to implement additional COM interfaces.
|
|---|
| 81 |
|
|---|
| 82 | \sa QAxAggregated, QAxFactory, {ActiveQt Framework}
|
|---|
| 83 | */
|
|---|
| 84 |
|
|---|
| 85 | /*!
|
|---|
| 86 | Constructs an empty QAxBindable object.
|
|---|
| 87 | */
|
|---|
| 88 | QAxBindable::QAxBindable()
|
|---|
| 89 | :activex(0)
|
|---|
| 90 | {
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | /*!
|
|---|
| 94 | Destroys the QAxBindable object.
|
|---|
| 95 | */
|
|---|
| 96 | QAxBindable::~QAxBindable()
|
|---|
| 97 | {
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | /*!
|
|---|
| 101 | Call this function to request permission to change the property
|
|---|
| 102 | \a property from the client that is hosting this ActiveX control.
|
|---|
| 103 | Returns true if the client allows the change; otherwise returns
|
|---|
| 104 | false.
|
|---|
| 105 |
|
|---|
| 106 | This function is usually called first in the write function for \a
|
|---|
| 107 | property, and writing is abandoned if the function returns false.
|
|---|
| 108 |
|
|---|
| 109 | \snippet doc/src/snippets/code/src_activeqt_control_qaxbindable.cpp 1
|
|---|
| 110 |
|
|---|
| 111 | \sa propertyChanged()
|
|---|
| 112 | */
|
|---|
| 113 | bool QAxBindable::requestPropertyChange(const char *property)
|
|---|
| 114 | {
|
|---|
| 115 | if (!activex)
|
|---|
| 116 | return true;
|
|---|
| 117 |
|
|---|
| 118 | return activex->emitRequestPropertyChange(property);
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | /*!
|
|---|
| 122 | Call this function to notify the client that is hosting this
|
|---|
| 123 | ActiveX control that the property \a property has been changed.
|
|---|
| 124 |
|
|---|
| 125 | This function is usually called at the end of the property's write
|
|---|
| 126 | function.
|
|---|
| 127 |
|
|---|
| 128 | \sa requestPropertyChange()
|
|---|
| 129 | */
|
|---|
| 130 | void QAxBindable::propertyChanged(const char *property)
|
|---|
| 131 | {
|
|---|
| 132 | if (!activex)
|
|---|
| 133 | return;
|
|---|
| 134 |
|
|---|
| 135 | activex->emitPropertyChanged(property);
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | /*!
|
|---|
| 139 | Returns a pointer to the client site interface for this ActiveX object,
|
|---|
| 140 | or null if no client site has been set.
|
|---|
| 141 |
|
|---|
| 142 | Call \c QueryInterface() on the returned interface to get the
|
|---|
| 143 | interface you want to call.
|
|---|
| 144 | */
|
|---|
| 145 | IUnknown *QAxBindable::clientSite() const
|
|---|
| 146 | {
|
|---|
| 147 | if (!activex)
|
|---|
| 148 | return 0;
|
|---|
| 149 |
|
|---|
| 150 | return activex->clientSite();
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | /*!
|
|---|
| 154 | Reimplement this function when you want to implement additional
|
|---|
| 155 | COM interfaces in the ActiveX control, or when you want to provide
|
|---|
| 156 | alternative implementations of COM interfaces. Return a new object
|
|---|
| 157 | of a QAxAggregated subclass.
|
|---|
| 158 |
|
|---|
| 159 | The default implementation returns the null pointer.
|
|---|
| 160 | */
|
|---|
| 161 | QAxAggregated *QAxBindable::createAggregate()
|
|---|
| 162 | {
|
|---|
| 163 | return 0;
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | /*!
|
|---|
| 167 | Reports an error to the client application. \a code is a
|
|---|
| 168 | control-defined error code. \a desc is a human-readable description
|
|---|
| 169 | of the error intended for the application user. \a src is the name
|
|---|
| 170 | of the source for the error, typically the ActiveX server name. \a
|
|---|
| 171 | context can be the location of a help file with more information
|
|---|
| 172 | about the error. If \a context ends with a number in brackets,
|
|---|
| 173 | e.g. [12], this number will be interpreted as the context ID in
|
|---|
| 174 | the help file.
|
|---|
| 175 | */
|
|---|
| 176 | void QAxBindable::reportError(int code, const QString &src, const QString &desc, const QString &context)
|
|---|
| 177 | {
|
|---|
| 178 | if (!activex)
|
|---|
| 179 | return;
|
|---|
| 180 |
|
|---|
| 181 | activex->reportError(code, src, desc, context);
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | /*!
|
|---|
| 185 | \since 4.1
|
|---|
| 186 |
|
|---|
| 187 | If the COM object supports a MIME type then this function is called
|
|---|
| 188 | to initialize the COM object from the data \a source in \a format.
|
|---|
| 189 | You have to open \a source for reading before you can read from it.
|
|---|
| 190 |
|
|---|
| 191 | Returns true to indicate success. If the function returns false,
|
|---|
| 192 | then ActiveQt will process the data by setting the properties
|
|---|
| 193 | through the meta object system.
|
|---|
| 194 |
|
|---|
| 195 | If you reimplement this function you also have to implement
|
|---|
| 196 | writeData(). The default implementation does nothing and returns
|
|---|
| 197 | false.
|
|---|
| 198 |
|
|---|
| 199 | \warning ActiveX controls embedded in HTML can use either the
|
|---|
| 200 | \c type and \c data attribute of the \c object tag to read data,
|
|---|
| 201 | or use a list of \c param tags to initialize properties. If
|
|---|
| 202 | \c param tags are used, then Internet Explorer will ignore the
|
|---|
| 203 | \c data attribute, and readData will not be called.
|
|---|
| 204 |
|
|---|
| 205 | \sa writeData()
|
|---|
| 206 | */
|
|---|
| 207 | bool QAxBindable::readData(QIODevice *source, const QString &format)
|
|---|
| 208 | {
|
|---|
| 209 | Q_UNUSED(source);
|
|---|
| 210 | Q_UNUSED(format);
|
|---|
| 211 | return false;
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | /*!
|
|---|
| 215 | \since 4.1
|
|---|
| 216 |
|
|---|
| 217 | If the COM object supports a MIME type then this function is called
|
|---|
| 218 | to store the COM object into \a sink.
|
|---|
| 219 | You have to open \a sink for writing before you can write to it.
|
|---|
| 220 |
|
|---|
| 221 | Returns true to indicate success. If the function returns false,
|
|---|
| 222 | then ActiveQt will serialize the object by storing the property
|
|---|
| 223 | values.
|
|---|
| 224 |
|
|---|
| 225 | If you reimplement this function you also have to implement
|
|---|
| 226 | readData(). The default implementation does nothing and returns
|
|---|
| 227 | false.
|
|---|
| 228 |
|
|---|
| 229 | \sa readData()
|
|---|
| 230 | */
|
|---|
| 231 | bool QAxBindable::writeData(QIODevice *sink)
|
|---|
| 232 | {
|
|---|
| 233 | Q_UNUSED(sink);
|
|---|
| 234 | return false;
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | /*!
|
|---|
| 238 | \class QAxAggregated
|
|---|
| 239 | \brief The QAxAggregated class is an abstract base class for implementations of
|
|---|
| 240 | additional COM interfaces.
|
|---|
| 241 |
|
|---|
| 242 | \inmodule QAxServer
|
|---|
| 243 |
|
|---|
| 244 | Create a subclass of QAxAggregated and reimplement
|
|---|
| 245 | queryInterface() to support additional COM interfaces. Use
|
|---|
| 246 | multiple inheritance from those COM interfaces. Implement the
|
|---|
| 247 | IUnknown interface of those COM interfaces by delegating the
|
|---|
| 248 | calls to \c QueryInterface(), \c AddRef() and \c Release() to the
|
|---|
| 249 | interface provided by controllingUnknown().
|
|---|
| 250 |
|
|---|
| 251 | Use the widget() method if you need to make calls to the QWidget
|
|---|
| 252 | implementing the ActiveX control. You must not store that pointer
|
|---|
| 253 | in your subclass (unless you use QPointer), as the QWidget can
|
|---|
| 254 | be destroyed by the ActiveQt framework at any time.
|
|---|
| 255 |
|
|---|
| 256 | \sa QAxBindable, QAxFactory, {ActiveQt Framework}
|
|---|
| 257 | */
|
|---|
| 258 |
|
|---|
| 259 | /*!
|
|---|
| 260 | \fn QAxAggregated::~QAxAggregated()
|
|---|
| 261 |
|
|---|
| 262 | The destructor is called internally by Qt.
|
|---|
| 263 | */
|
|---|
| 264 |
|
|---|
| 265 | /*!
|
|---|
| 266 | \fn long QAxAggregated::queryInterface(const QUuid &iid, void **iface)
|
|---|
| 267 |
|
|---|
| 268 | Reimplement this pure virtual function to support additional COM
|
|---|
| 269 | interfaces. Set the value of \a iface to point to this object to
|
|---|
| 270 | support the interface \a iid. Note that you must cast the \c
|
|---|
| 271 | this pointer to the appropriate superclass.
|
|---|
| 272 |
|
|---|
| 273 | \snippet doc/src/snippets/code/src_activeqt_control_qaxbindable.cpp 2
|
|---|
| 274 |
|
|---|
| 275 | Return the standard COM results \c S_OK (interface is supported)
|
|---|
| 276 | or \c E_NOINTERFACE (requested interface is not supported).
|
|---|
| 277 |
|
|---|
| 278 | \warning
|
|---|
| 279 | Even though you must implement the \c IUnknown interface if you
|
|---|
| 280 | implement any COM interface you must not support the \c IUnknown
|
|---|
| 281 | interface in your queryInterface() implementation.
|
|---|
| 282 | */
|
|---|
| 283 |
|
|---|
| 284 | /*!
|
|---|
| 285 | \fn IUnknown *QAxAggregated::controllingUnknown() const
|
|---|
| 286 |
|
|---|
| 287 | Returns the \c IUnknown interface of the ActiveX control. Implement
|
|---|
| 288 | the \c IUnknown interface in your QAxAggregated subclass to
|
|---|
| 289 | delegate calls to \c QueryInterface(), \c AddRef(), and \c
|
|---|
| 290 | Release() to the interface provided by this function.
|
|---|
| 291 |
|
|---|
| 292 | \snippet doc/src/snippets/code/src_activeqt_control_qaxbindable.cpp 3
|
|---|
| 293 |
|
|---|
| 294 | Instead of declaring and implementing these three functions
|
|---|
| 295 | manually, you can use the \c QAXAGG_IUNKNOWN macro in the class
|
|---|
| 296 | declaration of your subclass.
|
|---|
| 297 | */
|
|---|
| 298 |
|
|---|
| 299 | /*!
|
|---|
| 300 | \fn QObject *QAxAggregated::object() const
|
|---|
| 301 |
|
|---|
| 302 | Returns a pointer to the QObject subclass implementing the COM object.
|
|---|
| 303 | This function might return 0.
|
|---|
| 304 |
|
|---|
| 305 | \warning
|
|---|
| 306 | You must not store the returned pointer, unless you use a
|
|---|
| 307 | QPointer, since the QObject can be destroyed by ActiveQt at any
|
|---|
| 308 | time.
|
|---|
| 309 | */
|
|---|
| 310 |
|
|---|
| 311 | /*!
|
|---|
| 312 | \fn QWidget *QAxAggregated::widget() const
|
|---|
| 313 |
|
|---|
| 314 | Returns a pointer to the QWidget subclass implementing the ActiveX control.
|
|---|
| 315 | This function might return 0.
|
|---|
| 316 |
|
|---|
| 317 | \warning
|
|---|
| 318 | You must not store the returned pointer, unless you use a
|
|---|
| 319 | QPointer, since the QWidget can be destroyed by ActiveQt at any
|
|---|
| 320 | time.
|
|---|
| 321 | */
|
|---|
| 322 |
|
|---|
| 323 | QT_END_NAMESPACE
|
|---|
| 324 | #endif // QT_NO_WIN_ACTIVEQT
|
|---|