source: trunk/src/activeqt/control/qaxfactory.h

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 10.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
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#ifndef QAXFACTORY_H
42#define QAXFACTORY_H
43
44#include <QtCore/qhash.h>
45#include <QtCore/quuid.h>
46#include <QtCore/qfactoryinterface.h>
47#include <QtCore/qmetaobject.h>
48#include <QtCore/qstringlist.h>
49
50struct IUnknown;
51struct IDispatch;
52
53QT_BEGIN_HEADER
54
55QT_BEGIN_NAMESPACE
56
57QT_MODULE(ActiveQt)
58
59#ifndef QT_NO_WIN_ACTIVEQT
60
61class QWidget;
62class QSettings;
63
64class QAxFactory : public QObject
65{
66public:
67 QAxFactory(const QUuid &libId, const QUuid &appId);
68 virtual ~QAxFactory();
69
70 virtual QStringList featureList() const = 0;
71
72 virtual QObject *createObject(const QString &key) = 0;
73 virtual const QMetaObject *metaObject(const QString &key) const = 0;
74 virtual bool createObjectWrapper(QObject *object, IDispatch **wrapper);
75
76 virtual QUuid classID(const QString &key) const;
77 virtual QUuid interfaceID(const QString &key) const;
78 virtual QUuid eventsID(const QString &key) const;
79
80 virtual QUuid typeLibID() const;
81 virtual QUuid appID() const;
82
83 virtual void registerClass(const QString &key, QSettings *) const;
84 virtual void unregisterClass(const QString &key, QSettings *) const;
85
86 virtual bool validateLicenseKey(const QString &key, const QString &licenseKey) const;
87
88 virtual QString exposeToSuperClass(const QString &key) const;
89 virtual bool stayTopLevel(const QString &key) const;
90 virtual bool hasStockEvents(const QString &key) const;
91 virtual bool isService() const;
92
93 enum ServerType {
94 SingleInstance,
95 MultipleInstances
96 };
97
98 static bool isServer();
99 static QString serverDirPath();
100 static QString serverFilePath();
101 static bool startServer(ServerType type = MultipleInstances);
102 static bool stopServer();
103
104 static bool registerActiveObject(QObject *object);
105
106private:
107 QUuid typelib;
108 QUuid app;
109};
110
111extern QAxFactory *qAxFactory();
112
113extern bool qax_startServer(QAxFactory::ServerType);
114
115inline bool QAxFactory::startServer(ServerType type)
116{
117 // implementation in qaxservermain.cpp
118 return qax_startServer(type);
119}
120
121extern bool qax_stopServer();
122
123inline bool QAxFactory::stopServer()
124{
125 // implementation in qaxservermain.cpp
126 return qax_stopServer();
127}
128
129#define QAXFACTORY_EXPORT(IMPL, TYPELIB, APPID) \
130 QT_BEGIN_NAMESPACE \
131 QAxFactory *qax_instantiate() \
132 { \
133 IMPL *impl = new IMPL(QUuid(TYPELIB), QUuid(APPID)); \
134 return impl; \
135 } \
136 QT_END_NAMESPACE
137
138#define QAXFACTORY_DEFAULT(Class, IIDClass, IIDInterface, IIDEvents, IIDTypeLib, IIDApp) \
139 QT_BEGIN_NAMESPACE \
140 class QAxDefaultFactory : public QAxFactory \
141 { \
142 public: \
143 QAxDefaultFactory(const QUuid &app, const QUuid &lib) \
144 : QAxFactory(app, lib), className(QLatin1String(#Class)) {} \
145 QStringList featureList() const \
146 { \
147 QStringList list; \
148 list << className; \
149 return list; \
150 } \
151 const QMetaObject *metaObject(const QString &key) const \
152 { \
153 if (key == className) \
154 return &Class::staticMetaObject; \
155 return 0; \
156 } \
157 QObject *createObject(const QString &key) \
158 { \
159 if (key == className) \
160 return new Class(0); \
161 return 0; \
162 } \
163 QUuid classID(const QString &key) const \
164 { \
165 if (key == className) \
166 return QUuid(IIDClass); \
167 return QUuid(); \
168 } \
169 QUuid interfaceID(const QString &key) const \
170 { \
171 if (key == className) \
172 return QUuid(IIDInterface); \
173 return QUuid(); \
174 } \
175 QUuid eventsID(const QString &key) const \
176 { \
177 if (key == className) \
178 return QUuid(IIDEvents); \
179 return QUuid(); \
180 } \
181 private: \
182 QString className; \
183 }; \
184 QT_END_NAMESPACE \
185 QAXFACTORY_EXPORT(QAxDefaultFactory, IIDTypeLib, IIDApp) \
186
187template<class T>
188class QAxClass : public QAxFactory
189{
190public:
191 QAxClass(const QString &libId, const QString &appId)
192 : QAxFactory(libId, appId)
193 {}
194
195 const QMetaObject *metaObject(const QString &) const { return &T::staticMetaObject; }
196 QStringList featureList() const { return QStringList(QString(T::staticMetaObject.className())); }
197 QObject *createObject(const QString &key)
198 {
199 const QMetaObject &mo = T::staticMetaObject;
200 if (key != QLatin1String(mo.className()))
201 return 0;
202 if (!qstrcmp(mo.classInfo(mo.indexOfClassInfo("Creatable")).value(), "no"))
203 return 0;
204 return new T(0);
205 }
206};
207
208#define QAXFACTORY_BEGIN(IDTypeLib, IDApp) \
209 QT_BEGIN_NAMESPACE \
210 class QAxFactoryList : public QAxFactory \
211 { \
212 QStringList factoryKeys; \
213 QHash<QString, QAxFactory*> factories; \
214 QHash<QString, bool> creatable; \
215 public: \
216 QAxFactoryList() \
217 : QAxFactory(IDTypeLib, IDApp) \
218 { \
219 QAxFactory *factory = 0; \
220 QStringList keys; \
221 QStringList::Iterator it; \
222
223#define QAXCLASS(Class) \
224 factory = new QAxClass<Class>(typeLibID(), appID()); \
225 qRegisterMetaType<Class*>(#Class"*"); \
226 keys = factory->featureList(); \
227 for (it = keys.begin(); it != keys.end(); ++it) { \
228 factoryKeys += *it; \
229 factories.insert(*it, factory); \
230 creatable.insert(*it, true); \
231 }\
232
233#define QAXTYPE(Class) \
234 factory = new QAxClass<Class>(typeLibID(), appID()); \
235 qRegisterMetaType<Class*>(#Class"*"); \
236 keys = factory->featureList(); \
237 for (it = keys.begin(); it != keys.end(); ++it) { \
238 factoryKeys += *it; \
239 factories.insert(*it, factory); \
240 creatable.insert(*it, false); \
241 }\
242
243#define QAXFACTORY_END() \
244 } \
245 ~QAxFactoryList() { qDeleteAll(factories); } \
246 QStringList featureList() const { return factoryKeys; } \
247 const QMetaObject *metaObject(const QString&key) const { \
248 QAxFactory *f = factories[key]; \
249 return f ? f->metaObject(key) : 0; \
250 } \
251 QObject *createObject(const QString &key) { \
252 if (!creatable.value(key)) \
253 return 0; \
254 QAxFactory *f = factories[key]; \
255 return f ? f->createObject(key) : 0; \
256 } \
257 QUuid classID(const QString &key) { \
258 QAxFactory *f = factories.value(key); \
259 return f ? f->classID(key) : QUuid(); \
260 } \
261 QUuid interfaceID(const QString &key) { \
262 QAxFactory *f = factories.value(key); \
263 return f ? f->interfaceID(key) : QUuid(); \
264 } \
265 QUuid eventsID(const QString &key) { \
266 QAxFactory *f = factories.value(key); \
267 return f ? f->eventsID(key) : QUuid(); \
268 } \
269 void registerClass(const QString &key, QSettings *s) const { \
270 QAxFactory *f = factories.value(key); \
271 if (f) f->registerClass(key, s); \
272 } \
273 void unregisterClass(const QString &key, QSettings *s) const { \
274 QAxFactory *f = factories.value(key); \
275 if (f) f->unregisterClass(key, s); \
276 } \
277 QString exposeToSuperClass(const QString &key) const { \
278 QAxFactory *f = factories.value(key); \
279 return f ? f->exposeToSuperClass(key) : QString(); \
280 } \
281 bool stayTopLevel(const QString &key) const { \
282 QAxFactory *f = factories.value(key); \
283 return f ? f->stayTopLevel(key) : false; \
284 } \
285 bool hasStockEvents(const QString &key) const { \
286 QAxFactory *f = factories.value(key); \
287 return f ? f->hasStockEvents(key) : false; \
288 } \
289 }; \
290 QAxFactory *qax_instantiate() \
291 { \
292 QAxFactoryList *impl = new QAxFactoryList(); \
293 return impl; \
294 } \
295 QT_END_NAMESPACE
296
297QT_END_NAMESPACE
298
299#ifndef Q_COM_METATYPE_DECLARED
300#define Q_COM_METATYPE_DECLARED
301
302Q_DECLARE_METATYPE(IUnknown*)
303Q_DECLARE_METATYPE(IDispatch*)
304
305#endif
306
307#endif // QT_NO_WIN_ACTIVEQT
308
309QT_END_HEADER
310
311#endif // QAXFACTORY_H
Note: See TracBrowser for help on using the repository browser.