Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / declarative / qml / qdeclarativeprivate.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QDECLARATIVEPRIVATE_H
43 #define QDECLARATIVEPRIVATE_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists purely as an
50 // implementation detail.  This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55
56 #include <QtCore/qglobal.h>
57 #include <QtCore/qvariant.h>
58
59 QT_BEGIN_HEADER
60
61 QT_BEGIN_NAMESPACE
62
63
64 typedef QObject *(*QDeclarativeAttachedPropertiesFunc)(QObject *);
65
66 template <typename TYPE>
67 class QDeclarativeTypeInfo
68 {
69 public:
70     enum {
71         hasAttachedProperties = 0
72     };
73 };
74
75
76 class QJSValue;
77 class QJSEngine;
78 class QDeclarativeEngine;
79 class QDeclarativeCustomParser;
80 namespace QDeclarativePrivate
81 {
82     void Q_DECLARATIVE_EXPORT qdeclarativeelement_destructor(QObject *);
83     template<typename T>
84     class QDeclarativeElement : public T
85     {
86     public:
87         virtual ~QDeclarativeElement() { 
88             QDeclarativePrivate::qdeclarativeelement_destructor(this); 
89         }
90     };
91
92     template<typename T>
93     void createInto(void *memory) { new (memory) QDeclarativeElement<T>; }
94
95     template<typename T>
96     QObject *createParent(QObject *p) { return new T(p); }
97
98     template<class From, class To, int N>
99     struct StaticCastSelectorClass
100     {
101         static inline int cast() { return -1; }
102     };
103
104     template<class From, class To>
105     struct StaticCastSelectorClass<From, To, sizeof(int)>
106     {
107         static inline int cast() { return int(reinterpret_cast<quintptr>(static_cast<To *>(reinterpret_cast<From *>(0x10000000)))) - 0x10000000; }
108     };
109
110     template<class From, class To>
111     struct StaticCastSelector
112     {
113         typedef int yes_type;
114         typedef char no_type;
115
116         static yes_type check(To *);
117         static no_type check(...);
118
119         static inline int cast()
120         {
121             return StaticCastSelectorClass<From, To, sizeof(check(reinterpret_cast<From *>(0)))>::cast();
122         }
123     };
124
125     template <typename T>
126     struct has_attachedPropertiesMember
127     {
128         static bool const value = QDeclarativeTypeInfo<T>::hasAttachedProperties;
129     };
130
131     template <typename T, bool hasMember>
132     class has_attachedPropertiesMethod 
133     {
134     public:
135         typedef int yes_type;
136         typedef char no_type;
137
138         template<typename ReturnType>
139         static yes_type check(ReturnType *(*)(QObject *));
140         static no_type check(...);
141
142         static bool const value = sizeof(check(&T::qmlAttachedProperties)) == sizeof(yes_type);
143     }; 
144
145     template <typename T>
146     class has_attachedPropertiesMethod<T, false>
147     {
148     public:
149         static bool const value = false;
150     };
151
152     template<typename T, int N>
153     class AttachedPropertySelector
154     {
155     public:
156         static inline QDeclarativeAttachedPropertiesFunc func() { return 0; }
157         static inline const QMetaObject *metaObject() { return 0; }
158     };
159     template<typename T>
160     class AttachedPropertySelector<T, 1>
161     {
162         static inline QObject *attachedProperties(QObject *obj) {
163             return T::qmlAttachedProperties(obj);
164         }
165         template<typename ReturnType>
166         static inline const QMetaObject *attachedPropertiesMetaObject(ReturnType *(*)(QObject *)) {
167             return &ReturnType::staticMetaObject;
168         }
169     public:
170         static inline QDeclarativeAttachedPropertiesFunc func() {
171             return &attachedProperties;
172         }
173         static inline const QMetaObject *metaObject() {
174             return attachedPropertiesMetaObject(&T::qmlAttachedProperties);
175         }
176     };
177
178     template<typename T>
179     inline QDeclarativeAttachedPropertiesFunc attachedPropertiesFunc()
180     {
181         return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::func();
182     }
183
184     template<typename T>
185     inline const QMetaObject *attachedPropertiesMetaObject()
186     {
187         return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::metaObject();
188     }
189
190     enum AutoParentResult { Parented, IncompatibleObject, IncompatibleParent };
191     typedef AutoParentResult (*AutoParentFunction)(QObject *object, QObject *parent);
192
193     struct RegisterType {
194         int version;
195
196         int typeId;
197         int listId;
198         int objectSize;
199         void (*create)(void *);
200         QString noCreationReason;
201
202         const char *uri;
203         int versionMajor;
204         int versionMinor;
205         const char *elementName;
206         const QMetaObject *metaObject;
207
208         QDeclarativeAttachedPropertiesFunc attachedPropertiesFunction;
209         const QMetaObject *attachedPropertiesMetaObject;
210
211         int parserStatusCast;
212         int valueSourceCast;
213         int valueInterceptorCast;
214
215         QObject *(*extensionObjectCreate)(QObject *);
216         const QMetaObject *extensionMetaObject;
217
218         QDeclarativeCustomParser *customParser;
219         int revision;
220         // If this is extended ensure "version" is bumped!!!
221     };
222
223     struct RegisterInterface {
224         int version;
225
226         int typeId;
227         int listId;
228
229         const char *iid;
230     };
231
232     struct RegisterAutoParent {
233         int version;
234
235         AutoParentFunction function;
236     };
237
238     struct RegisterModuleApi {
239         int version;
240
241         const char *uri;
242         int versionMajor;
243         int versionMinor;
244
245         QJSValue (*scriptApi)(QDeclarativeEngine *, QJSEngine *);
246         QObject *(*qobjectApi)(QDeclarativeEngine *, QJSEngine *);
247     };
248
249     enum RegistrationType {
250         TypeRegistration       = 0, 
251         InterfaceRegistration  = 1,
252         AutoParentRegistration = 2,
253         ModuleApiRegistration  = 3
254     };
255
256     int Q_DECLARATIVE_EXPORT qmlregister(RegistrationType, void *);
257 }
258
259 QT_END_NAMESPACE
260
261 QT_END_HEADER
262
263 #endif // QDECLARATIVEPRIVATE_H