| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 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 "qaxbindable.h"
|
|---|
| 42 |
|
|---|
| 43 | #ifndef QT_NO_WIN_ACTIVEQT
|
|---|
| 44 |
|
|---|
| 45 | #include <qmetaobject.h>
|
|---|
| 46 |
|
|---|
| 47 | #include <qt_windows.h> // for IUnknown
|
|---|
| 48 | #include "../shared/qaxtypes.h"
|
|---|
| 49 |
|
|---|
| 50 | QT_BEGIN_NAMESPACE
|
|---|
| 51 |
|
|---|
| 52 | /*!
|
|---|
| 53 | \class QAxBindable
|
|---|
| 54 | \brief The QAxBindable class provides an interface between a
|
|---|
| 55 | QWidget and an ActiveX client.
|
|---|
| 56 |
|
|---|
| 57 | \inmodule QAxServer
|
|---|
| 58 |
|
|---|
| 59 | The functions provided by this class allow an ActiveX control to
|
|---|
| 60 | communicate property changes to a client application. Inherit
|
|---|
| 61 | your control class from both QWidget (directly or indirectly) and
|
|---|
| 62 | this class to get access to this class's functions. The
|
|---|
| 63 | \l{moc}{meta-object compiler} requires you to inherit from
|
|---|
| 64 | QWidget first.
|
|---|
| 65 |
|
|---|
| 66 | \snippet doc/src/snippets/code/src_activeqt_control_qaxbindable.cpp 0
|
|---|
| 67 |
|
|---|
| 68 | When implementing the property write function, use
|
|---|
| 69 | requestPropertyChange() to get permission from the ActiveX client
|
|---|
| 70 | application to change this property. When the property changes,
|
|---|
| 71 | call propertyChanged() to notify the ActiveX client application
|
|---|
| 72 | about the change. If a fatal error occurs in the control, use the
|
|---|
| 73 | static reportError() function to notify the client.
|
|---|
| 74 |
|
|---|
| 75 | Use the interface returned by clientSite() to call the ActiveX
|
|---|
| 76 | client. To implement additional COM interfaces in your ActiveX
|
|---|
| 77 | control, reimplement createAggregate() to return a new object of a
|
|---|
| 78 | QAxAggregated subclass.
|
|---|
| 79 |
|
|---|
| 80 | The ActiveQt \l{activeqt/opengl}{OpenGL} example shows how to use
|
|---|
| 81 | QAxBindable to implement additional COM interfaces.
|
|---|
| 82 |
|
|---|
| 83 | \sa QAxAggregated, QAxFactory, {ActiveQt Framework}
|
|---|
| 84 | */
|
|---|
| 85 |
|
|---|
| 86 | /*!
|
|---|
| 87 | Constructs an empty QAxBindable object.
|
|---|
| 88 | */
|
|---|
| 89 | QAxBindable::QAxBindable()
|
|---|
| 90 | :activex(0)
|
|---|
| 91 | {
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | /*!
|
|---|
| 95 | Destroys the QAxBindable object.
|
|---|
| 96 | */
|
|---|
| 97 | QAxBindable::~QAxBindable()
|
|---|
| 98 | {
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | /*!
|
|---|
| 102 | Call this function to request permission to change the property
|
|---|
| 103 | \a property from the client that is hosting this ActiveX control.
|
|---|
| 104 | Returns true if the client allows the change; otherwise returns
|
|---|
| 105 | false.
|
|---|
| 106 |
|
|---|
| 107 | This function is usually called first in the write function for \a
|
|---|
| 108 | property, and writing is abandoned if the function returns false.
|
|---|
| 109 |
|
|---|
| 110 | \snippet doc/src/snippets/code/src_activeqt_control_qaxbindable.cpp 1
|
|---|
| 111 |
|
|---|
| 112 | \sa propertyChanged()
|
|---|
| 113 | */
|
|---|
| 114 | bool QAxBindable::requestPropertyChange(const char *property)
|
|---|
| 115 | {
|
|---|
| 116 | if (!activex)
|
|---|
| 117 | return true;
|
|---|
| 118 |
|
|---|
| 119 | return activex->emitRequestPropertyChange(property);
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | /*!
|
|---|
| 123 | Call this function to notify the client that is hosting this
|
|---|
| 124 | ActiveX control that the property \a property has been changed.
|
|---|
| 125 |
|
|---|
| 126 | This function is usually called at the end of the property's write
|
|---|
| 127 | function.
|
|---|
| 128 |
|
|---|
| 129 | \sa requestPropertyChange()
|
|---|
| 130 | */
|
|---|
| 131 | void QAxBindable::propertyChanged(const char *property)
|
|---|
| 132 | {
|
|---|
| 133 | if (!activex)
|
|---|
| 134 | return;
|
|---|
| 135 |
|
|---|
| 136 | activex->emitPropertyChanged(property);
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | /*!
|
|---|
| 140 | Returns a pointer to the client site interface for this ActiveX object,
|
|---|
| 141 | or null if no client site has been set.
|
|---|
| 142 |
|
|---|
| 143 | Call \c QueryInterface() on the returned interface to get the
|
|---|
| 144 | interface you want to call.
|
|---|
| 145 | */
|
|---|
| 146 | IUnknown *QAxBindable::clientSite() const
|
|---|
| 147 | {
|
|---|
| 148 | if (!activex)
|
|---|
| 149 | return 0;
|
|---|
| 150 |
|
|---|
| 151 | return activex->clientSite();
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | /*!
|
|---|
| 155 | Reimplement this function when you want to implement additional
|
|---|
| 156 | COM interfaces in the ActiveX control, or when you want to provide
|
|---|
| 157 | alternative implementations of COM interfaces. Return a new object
|
|---|
| 158 | of a QAxAggregated subclass.
|
|---|
| 159 |
|
|---|
| 160 | The default implementation returns the null pointer.
|
|---|
| 161 | */
|
|---|
| 162 | QAxAggregated *QAxBindable::createAggregate()
|
|---|
| 163 | {
|
|---|
| 164 | return 0;
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | /*!
|
|---|
| 168 | Reports an error to the client application. \a code is a
|
|---|
| 169 | control-defined error code. \a desc is a human-readable description
|
|---|
| 170 | of the error intended for the application user. \a src is the name
|
|---|
| 171 | of the source for the error, typically the ActiveX server name. \a
|
|---|
| 172 | context can be the location of a help file with more information
|
|---|
| 173 | about the error. If \a context ends with a number in brackets,
|
|---|
| 174 | e.g. [12], this number will be interpreted as the context ID in
|
|---|
| 175 | the help file.
|
|---|
| 176 | */
|
|---|
| 177 | void QAxBindable::reportError(int code, const QString &src, const QString &desc, const QString &context)
|
|---|
| 178 | {
|
|---|
| 179 | if (!activex)
|
|---|
| 180 | return;
|
|---|
| 181 |
|
|---|
| 182 | activex->reportError(code, src, desc, context);
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| 185 | /*!
|
|---|
| 186 | \since 4.1
|
|---|
| 187 |
|
|---|
| 188 | If the COM object supports a MIME type then this function is called
|
|---|
| 189 | to initialize the COM object from the data \a source in \a format.
|
|---|
| 190 | You have to open \a source for reading before you can read from it.
|
|---|
| 191 |
|
|---|
| 192 | Returns true to indicate success. If the function returns false,
|
|---|
| 193 | then ActiveQt will process the data by setting the properties
|
|---|
| 194 | through the meta object system.
|
|---|
| 195 |
|
|---|
| 196 | If you reimplement this function you also have to implement
|
|---|
| 197 | writeData(). The default implementation does nothing and returns
|
|---|
| 198 | false.
|
|---|
| 199 |
|
|---|
| 200 | \warning ActiveX controls embedded in HTML can use either the
|
|---|
| 201 | \c type and \c data attribute of the \c object tag to read data,
|
|---|
| 202 | or use a list of \c param tags to initialize properties. If
|
|---|
| 203 | \c param tags are used, then Internet Explorer will ignore the
|
|---|
| 204 | \c data attribute, and readData will not be called.
|
|---|
| 205 |
|
|---|
| 206 | \sa writeData()
|
|---|
| 207 | */
|
|---|
| 208 | bool QAxBindable::readData(QIODevice *source, const QString &format)
|
|---|
| 209 | {
|
|---|
| 210 | Q_UNUSED(source);
|
|---|
| 211 | Q_UNUSED(format);
|
|---|
| 212 | return false;
|
|---|
| 213 | }
|
|---|
|
|---|