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

Last change on this file since 122 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

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