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 | #include "qaxfactory.h"
|
---|
41 |
|
---|
42 | #ifndef QT_NO_WIN_ACTIVEQT
|
---|
43 |
|
---|
44 | #include <qfile.h>
|
---|
45 | #include <qfileinfo.h>
|
---|
46 | #include <qmetaobject.h>
|
---|
47 | #include <qsettings.h>
|
---|
48 | #include <qwidget.h>
|
---|
49 | #include <qt_windows.h>
|
---|
50 |
|
---|
51 | QT_BEGIN_NAMESPACE
|
---|
52 |
|
---|
53 | extern char qAxModuleFilename[MAX_PATH];
|
---|
54 |
|
---|
55 | /*!
|
---|
56 | \class QAxFactory
|
---|
57 | \brief The QAxFactory class defines a factory for the creation of COM components.
|
---|
58 |
|
---|
59 | \inmodule QAxServer
|
---|
60 |
|
---|
61 | Implement this factory once in your COM server to provide information
|
---|
62 | about the components the server can create. Subclass QAxFactory and implement
|
---|
63 | the pure virtual functions in any implementation file (e.g. main.cpp), and export
|
---|
64 | the factory using the \c QAXFACTORY_EXPORT() macro.
|
---|
65 |
|
---|
66 | \snippet doc/src/snippets/code/src_activeqt_control_qaxfactory.cpp 0
|
---|
67 |
|
---|
68 | If you use the \c Q_CLASSINFO() macro to provide the unique
|
---|
69 | identifiers or other attributes for your class you can use the \c
|
---|
70 | QAXFACTORY_BEGIN(), \c QAXCLASS() and \c QAXFACTORY_END() macros to
|
---|
71 | expose one or more classes as COM objects.
|
---|
72 |
|
---|
73 | \snippet doc/src/snippets/code/src_activeqt_control_qaxfactory.cpp 1
|
---|
74 |
|
---|
75 |
|
---|
76 | If your server supports just a single COM object, you can use
|
---|
77 | a default factory implementation through the \c QAXFACTORY_DEFAULT() macro.
|
---|
78 |
|
---|
79 | \snippet doc/src/snippets/code/src_activeqt_control_qaxfactory.cpp 2
|
---|
80 |
|
---|
81 | Only one QAxFactory implementation may be instantiated and
|
---|
82 | exported by an ActiveX server application. This instance is accessible
|
---|
83 | through the global qAxFactory() function.
|
---|
84 |
|
---|
85 | A factory can also reimplement the registerClass() and
|
---|
86 | unregisterClass() functions to set additional flags for an ActiveX
|
---|
87 | control in the registry. To limit the number of methods or
|
---|
88 | properties a widget class exposes from its parent classes
|
---|
89 | reimplement exposeToSuperClass().
|
---|
90 |
|
---|
91 | \sa QAxAggregated, QAxBindable, {ActiveQt Framework}
|
---|
92 | */
|
---|
93 |
|
---|
94 | /*!
|
---|
95 | Constructs a QAxFactory object that returns \a libid and \a appid
|
---|
96 | in the implementation of the respective interface functions.
|
---|
97 | */
|
---|
98 |
|
---|
99 | QAxFactory::QAxFactory(const QUuid &libid, const QUuid &appid)
|
---|
100 | : typelib(libid), app(appid)
|
---|
101 | {
|
---|
102 | }
|
---|
103 |
|
---|
104 | /*!
|
---|
105 | Destroys the QAxFactory object.
|
---|
106 | */
|
---|
107 | QAxFactory::~QAxFactory()
|
---|
108 | {
|
---|
109 | }
|
---|
110 |
|
---|
111 | /*!
|
---|
112 | \fn QUuid QAxFactory::typeLibID() const
|
---|
113 |
|
---|
114 | Reimplement this function to return the ActiveX server's type
|
---|
115 | library identifier.
|
---|
116 | */
|
---|
117 | QUuid QAxFactory::typeLibID() const
|
---|
118 | {
|
---|
119 | return typelib;
|
---|
120 | }
|
---|
121 |
|
---|
122 | /*!
|
---|
123 | \fn QUuid QAxFactory::appID() const
|
---|
124 |
|
---|
125 | Reimplement this function to return the ActiveX server's
|
---|
126 | application identifier.
|
---|
127 | */
|
---|
128 | QUuid QAxFactory::appID() const
|
---|
129 | {
|
---|
130 | return app;
|
---|
131 | }
|
---|
132 |
|
---|
133 | /*!
|
---|
134 | \fn QStringList QAxFactory::featureList() const
|
---|
135 |
|
---|
136 | Reimplement this function to return a list of the widgets (class
|
---|
137 | names) supported by this factory.
|
---|
138 | */
|
---|
139 |
|
---|
140 | /*!
|
---|
141 | \fn QObject *QAxFactory::createObject(const QString &key)
|
---|
142 |
|
---|
143 | Reimplement this function to return a new object for \a key, or 0 if
|
---|
144 | this factory doesn't support the value of \a key.
|
---|
145 |
|
---|
146 | If the object returned is a QWidget it will be exposed as an ActiveX
|
---|
147 | control, otherwise the returned object will be exposed as a simple COM
|
---|
148 | object.
|
---|
149 | */
|
---|
150 |
|
---|
151 | /*!
|
---|
152 | \fn const QMetaObject *QAxFactory::metaObject(const QString &key) const
|
---|
153 |
|
---|
154 | Reimplement this function to return the QMetaObject corresponding to
|
---|
155 | \a key, or 0 if this factory doesn't support the value of \a key.
|
---|
156 | */
|
---|
157 |
|
---|
158 | /*!
|
---|
159 | \fn bool QAxFactory::createObjectWrapper(QObject *object, IDispatch **wrapper)
|
---|
160 |
|
---|
161 | Reimplement this function to provide the COM object for \a object
|
---|
162 | in \a wrapper. Return true if the function was successful; otherwise
|
---|
163 | return false.
|
---|
164 |
|
---|
165 | The default implementation creates a generic automation wrapper based
|
---|
166 | on the meta object information of \a object.
|
---|
167 | */
|
---|
168 | // implementation in qaxserverbase.cpp
|
---|
169 |
|
---|
170 | /*!
|
---|
171 | Reimplement this function to return the class identifier for each
|
---|
172 | \a key returned by the featureList() implementation, or an empty
|
---|
173 | QUuid if this factory doesn't support the value of \a key.
|
---|
174 |
|
---|
175 | The default implementation interprets \a key as the class name,
|
---|
176 | and returns the value of the Q_CLASSINFO() entry "ClassID".
|
---|
177 | */
|
---|
178 | QUuid QAxFactory::classID(const QString &key) const
|
---|
179 | {
|
---|
180 | const QMetaObject *mo = metaObject(key);
|
---|
181 | if (!mo)
|
---|
182 | return QUuid();
|
---|
183 | QString id = QString::fromLatin1(mo->classInfo(mo->indexOfClassInfo("ClassID")).value());
|
---|
184 |
|
---|
185 | return QUuid(id);
|
---|
186 | }
|
---|
187 |
|
---|
188 | /*!
|
---|
189 | Reimplement this function to return the interface identifier for
|
---|
190 | each \a key returned by the featureList() implementation, or an
|
---|
191 | empty QUuid if this factory doesn't support the value of \a key.
|
---|
192 |
|
---|
193 | The default implementation interprets \a key as the class name,
|
---|
194 | and returns the value of the Q_CLASSINFO() entry "InterfaceID".
|
---|
195 | */
|
---|
196 | QUuid QAxFactory::interfaceID(const QString &key) const
|
---|
197 | {
|
---|
198 | const QMetaObject *mo = metaObject(key);
|
---|
199 | if (!mo)
|
---|
200 | return QUuid();
|
---|
201 | QString id = QString::fromLatin1(mo->classInfo(mo->indexOfClassInfo("InterfaceID")).value());
|
---|
202 |
|
---|
203 | return QUuid(id);
|
---|
|
---|