-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommonqt.cpp
350 lines (292 loc) · 7.56 KB
/
commonqt.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
// -*- c-basic-offset: 8; indent-tabs: nil -*-
//
// See LICENSE for details.
//
#include <smoke.h>
#include <smoke/qtcore_smoke.h>
#include <QtCore>
#include <QtGui>
#include "commonqt.h"
// #define DEBUG 1
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
typedef void (*t_deletion_callback)(void*, void*);
typedef bool (*t_callmethod_callback)(void*, short, void*, void*, bool);
typedef void (*t_child_callback)(void*, bool, void*);
class Binding : public SmokeBinding
{
public:
Binding(Smoke* s) : SmokeBinding(s) {}
t_deletion_callback deletion_callback;
t_callmethod_callback callmethod_callback;
t_child_callback child_callback;
void deleted(Smoke::Index, void* obj) {
deletion_callback(smoke, obj);
}
bool callMethod(Smoke::Index method, void* obj,
Smoke::Stack args, bool isAbstract)
{
Smoke::Method* m = &smoke->methods[method];
const char* name = smoke->methodNames[m->name];
Smoke::Class* c = &smoke->classes[m->classId];
if (*name == '~')
callmethod_callback(smoke, method, obj, args, isAbstract);
else if (!strcmp(name, "notify")
&& (!strcmp(c->className, "QApplication")
|| !strcmp(c->className, "QCoreApplication")))
{
QEvent* e = (QEvent*) args[2].s_voidp;
if (e->type() == QEvent::ChildAdded
|| e->type() == QEvent::ChildRemoved)
{
QChildEvent* f = (QChildEvent*) e;
child_callback(smoke, f->added(), f->child());
}
}
return false;
}
char* className(Smoke::Index classId) {
return (char*) smoke->classes[classId].className;
}
};
class DynamicBinding : public Binding
{
public:
DynamicBinding(Smoke* s) : Binding(s) {}
bool callMethod(Smoke::Index method, void* obj,
Smoke::Stack args, bool isAbstract)
{
return callmethod_callback(smoke, method, obj, args, isAbstract);
}
};
void
sw_smoke(Smoke* smoke,
SmokeData* data,
void* deletion_callback,
void* method_callback,
void* child_callback)
{
Binding* binding = new Binding(smoke);
DynamicBinding* dynamicBinding = new DynamicBinding(smoke);
data->name = smoke->moduleName();
data->classes = smoke->classes;
data->numClasses = smoke->numClasses;
data->methods = smoke->methods;
data->numMethods = smoke->numMethods;
data->methodMaps = smoke->methodMaps;
data->numMethodMaps = smoke->numMethodMaps;
data->methodNames = smoke->methodNames;
data->numMethodNames = smoke->numMethodNames;
data->types = smoke->types;
data->numTypes = smoke->numTypes;
data->inheritanceList = smoke->inheritanceList;
data->argumentList = smoke->argumentList;
data->ambiguousMethodList = smoke->ambiguousMethodList;
data->castFn = (void *) smoke->castFn;
dynamicBinding->deletion_callback
= (t_deletion_callback) deletion_callback;
dynamicBinding->callmethod_callback
= (t_callmethod_callback) method_callback;
dynamicBinding->child_callback
= (t_child_callback) child_callback;
binding->deletion_callback = dynamicBinding->deletion_callback;
binding->callmethod_callback = dynamicBinding->callmethod_callback;
binding->child_callback = dynamicBinding->child_callback;
data->thin = binding;
data->fat = dynamicBinding;
}
int
sw_windows_version()
{
#ifdef WINDOWS
return QSysInfo::windowsVersion();
#else
return -1;
#endif
}
// void*
// sw_make_qstring(char *str)
// {
// QString* qstr = new QString();
// *qstr = QString::fromUtf8(str);
// return qstr;
// }
void*
sw_make_qbytearray(char* str)
{
return new QByteArray(str);
}
void
sw_delete_qbytearray(void *q)
{
delete (QByteArray*) q;
}
void*
sw_make_qstring(char *str)
{
return new QString(QString::fromUtf8(str));
}
void*
sw_qstring_to_utf8(void* s)
{
QString* str = (QString*) s;
return new QByteArray(str->toUtf8());
}
const void*
sw_qstring_to_utf16(void* s)
{
QString* str = static_cast<QString*>(s);
return str->utf16();
}
void
sw_delete_qstring(void *q)
{
delete (QString*) q;
}
void*
sw_make_metaobject(void *p, char *strings, int *d)
{
QMetaObject* parent = (QMetaObject*) p;
const uint* data = (const uint*) d;
QMetaObject tmp = { { parent, strings, data, 0 } };
QMetaObject* ptr = new QMetaObject;
*ptr = tmp;
return ptr;
}
void
sw_delete(void *p)
{
QObject* q = (QObject*) p;
delete q;
}
typedef void (*t_ptr_callback)(void *);
void
sw_find_class(char *name, Smoke **smoke, short *index)
{
Smoke::ModuleIndex mi = qtcore_Smoke->findClass(name);
*smoke = mi.smoke;
*index = mi.index;
}
void
sw_id_instance_class(void *ptr, Smoke **smoke, short *index)
{
Smoke::ModuleIndex mi = qtcore_Smoke->findClass(((QObject*)ptr)->metaObject()->className());
*smoke = mi.smoke;
*index = mi.index;
}
short
sw_find_name(Smoke *smoke, char *name)
{
Smoke::ModuleIndex mi = smoke->idMethodName(name);
return mi.index;
}
short
sw_id_method(Smoke *smoke, short classIndex, short name)
{
Smoke::ModuleIndex mi = smoke->idMethod(classIndex, name);
return mi.index;
}
short
sw_id_type(Smoke *smoke, char *name)
{
return smoke->idType(name);
}
short
sw_id_class(Smoke *smoke, char *name, bool external)
{
return smoke->idClass(name, external).index;
}
// QStringList marshalling
void*
sw_qstringlist_new()
{
return new QStringList();
}
int
sw_qstringlist_size(void* q)
{
return static_cast<QStringList*>(q)->size();
}
void
sw_qstringlist_delete(void *q)
{
delete static_cast<QStringList*>(q);
}
const void*
sw_qstringlist_at(void* q, int index)
{
return static_cast<QStringList*>(q)->at(index).utf16();
}
void
sw_qstringlist_append(void *q, char *x)
{
static_cast<QStringList*>(q)->append(QString(QString::fromUtf8(x)));
}
// QList<Something*> marshalling
void*
sw_qlist_void_new()
{
return new QList<void*>;
}
int
sw_qlist_void_size(void *ptr)
{
QList<void*>* qlist = static_cast<QList<void*>*>(ptr);
return qlist->size();
}
void
sw_qlist_void_delete(void *ptr)
{
QList<void*>* qlist = static_cast<QList<void*>*>(ptr);
delete qlist;
}
const void*
sw_qlist_void_at(void *ptr, int index)
{
QList<void*>* qlist = static_cast<QList<void*>*>(ptr);
return qlist->at(index);
}
void
sw_qlist_void_append(void *ptr, void *whatptr)
{
QList<void*>* qlist = static_cast<QList<void*>*>(ptr);
qlist->append(whatptr);
}
// QList<scalar> marshalling
#define DEFINE_QLIST_SCALAR_MARSHALLER(ELEMENT_TYPE, NAME) \
void* \
sw_qlist_##NAME##_new() \
{ \
return new QList<ELEMENT_TYPE>; \
} \
int \
sw_qlist_##NAME##_size(void *ptr) \
{ \
QList<ELEMENT_TYPE>* qlist = static_cast<QList<ELEMENT_TYPE>*>(ptr); \
return qlist->size(); \
} \
void \
sw_qlist_##NAME##_delete(void *ptr) \
{ \
QList<ELEMENT_TYPE>* qlist = static_cast<QList<ELEMENT_TYPE>*>(ptr); \
delete qlist; \
} \
const void* \
sw_qlist_##NAME##_at(void *ptr, int index) \
{ \
QList<ELEMENT_TYPE>* qlist = static_cast<QList<ELEMENT_TYPE>*>(ptr); \
return &qlist->at(index); \
} \
void \
sw_qlist_##NAME##_append(void *ptr, void *whatptr) \
{ \
QList<ELEMENT_TYPE>* qlist = static_cast<QList<ELEMENT_TYPE>*>(ptr); \
qlist->append(*static_cast<ELEMENT_TYPE*>(whatptr)); \
}
DEFINE_QLIST_SCALAR_MARSHALLER(int, int)
DEFINE_QLIST_SCALAR_MARSHALLER(QVariant, qvariant)
DEFINE_QLIST_SCALAR_MARSHALLER(QByteArray, qbytearray)
DEFINE_QLIST_SCALAR_MARSHALLER(QModelIndex, qmodelindex)
DEFINE_QLIST_SCALAR_MARSHALLER(QKeySequence, qkeysequence)