50
|
1 |
#include "swt.h"
|
|
2 |
#include "os.h"
|
|
3 |
#include <QAbstractAnimation>
|
|
4 |
#include <QPropertyAnimation>
|
|
5 |
#include <QVariant>
|
|
6 |
#include <QPoint>
|
|
7 |
#include <QAnimationGroup>
|
|
8 |
#include <QParallelAnimationGroup>
|
|
9 |
#include <QSequentialAnimationGroup>
|
|
10 |
|
|
11 |
using namespace Java::eSWT;
|
|
12 |
|
|
13 |
#define OS_NATIVE(func) Java_org_eclipse_swt_animation_internal_qt_OS_##func
|
|
14 |
|
|
15 |
#define POINTER_TO_HANDLE(pointer) reinterpret_cast<jint>(static_cast<QObject*>(pointer))
|
|
16 |
#define HANDLE_TO_POINTER(type, variable, handle) type variable = qobject_cast<type>(static_cast<type>(reinterpret_cast<QObject*>( handle )))
|
|
17 |
|
|
18 |
#define SWT_TRY try
|
|
19 |
#define SWT_CATCH \
|
|
20 |
catch(std::bad_alloc const&)\
|
|
21 |
{\
|
|
22 |
Throw( aJniEnv, ESwtErrorNoHandles );\
|
|
23 |
}\
|
|
24 |
catch(std::exception const&)\
|
|
25 |
{\
|
|
26 |
Throw( aJniEnv, ESwtErrorUnspecified );\
|
|
27 |
}
|
|
28 |
#define SWT_CATCH_1(err) \
|
|
29 |
catch(std::exception const&)\
|
|
30 |
{\
|
|
31 |
Throw( aJniEnv, err );\
|
|
32 |
}
|
|
33 |
|
|
34 |
#ifdef __cplusplus
|
|
35 |
extern "C" {
|
|
36 |
#endif
|
|
37 |
|
|
38 |
//TODO: use from jniutils
|
|
39 |
void Throw( JNIEnv* aJniEnv, const int& aError )
|
|
40 |
{
|
|
41 |
jclass clazz = aJniEnv->FindClass("org/eclipse/swt/SWT");
|
|
42 |
if (clazz != NULL)
|
|
43 |
{
|
|
44 |
jmethodID id = aJniEnv->GetStaticMethodID(clazz, "error", "(I)V");
|
|
45 |
if (id != NULL)
|
|
46 |
aJniEnv->CallStaticVoidMethod(clazz, id, aError);
|
|
47 |
aJniEnv->DeleteLocalRef(clazz);
|
|
48 |
}
|
|
49 |
}
|
|
50 |
|
|
51 |
JNIEXPORT jint JNICALL OS_NATIVE(QPropertyAnimation_1new)
|
|
52 |
(JNIEnv *aJniEnv, jclass, jint aHandle)
|
|
53 |
{
|
|
54 |
QPropertyAnimation* animation = NULL;
|
|
55 |
SWT_TRY
|
|
56 |
{
|
|
57 |
HANDLE_TO_POINTER( QObject*, parent, aHandle );
|
|
58 |
animation = new QPropertyAnimation( parent );
|
|
59 |
}
|
|
60 |
SWT_CATCH
|
|
61 |
return POINTER_TO_HANDLE( animation );
|
|
62 |
|
|
63 |
}
|
|
64 |
|
|
65 |
JNIEXPORT void JNICALL OS_NATIVE( QAbstractAnimation_1start )
|
|
66 |
(JNIEnv *aJniEnv, jclass, jint aHandle)
|
|
67 |
{
|
|
68 |
SWT_TRY
|
|
69 |
{
|
|
70 |
HANDLE_TO_POINTER( QAbstractAnimation*, animation, aHandle );
|
|
71 |
animation->start();
|
|
72 |
}
|
|
73 |
SWT_CATCH
|
|
74 |
}
|
|
75 |
|
|
76 |
JNIEXPORT void JNICALL OS_NATIVE( QAbstractAnimation_1stop )
|
|
77 |
(JNIEnv *aJniEnv, jclass, jint aHandle)
|
|
78 |
{
|
|
79 |
SWT_TRY
|
|
80 |
{
|
|
81 |
HANDLE_TO_POINTER( QAbstractAnimation*, animation, aHandle );
|
|
82 |
animation->stop();
|
|
83 |
}
|
|
84 |
SWT_CATCH
|
|
85 |
}
|
|
86 |
|
|
87 |
JNIEXPORT void JNICALL OS_NATIVE (QAbstractAnimation_1setLoopCount)
|
|
88 |
(JNIEnv *aJniEnv, jclass, jint aHandle, jint aLoopCount)
|
|
89 |
{
|
|
90 |
SWT_TRY
|
|
91 |
{
|
|
92 |
HANDLE_TO_POINTER( QAbstractAnimation*, animation, aHandle );
|
|
93 |
animation->setLoopCount( aLoopCount );
|
|
94 |
}
|
|
95 |
SWT_CATCH
|
|
96 |
}
|
|
97 |
|
|
98 |
JNIEXPORT jint JNICALL OS_NATIVE( QAbstractAnimation_1duration)
|
|
99 |
(JNIEnv *aJniEnv, jclass, jint aHandle )
|
|
100 |
{
|
|
101 |
int duration = 0;
|
|
102 |
SWT_TRY
|
|
103 |
{
|
|
104 |
HANDLE_TO_POINTER( QAbstractAnimation*, animation, aHandle );
|
|
105 |
duration= animation->duration();
|
|
106 |
}
|
|
107 |
SWT_CATCH
|
|
108 |
return duration;
|
|
109 |
}
|
|
110 |
|
|
111 |
JNIEXPORT void JNICALL OS_NATIVE( QPropertyAnimation_1setPropertyName)
|
|
112 |
(JNIEnv *aJniEnv, jclass, jint aHandle, jstring string)
|
|
113 |
{
|
|
114 |
SWT_TRY
|
|
115 |
{
|
|
116 |
jboolean isCopy;
|
|
117 |
const jchar* javaChars = aJniEnv->GetStringChars( string, &isCopy );
|
|
118 |
|
|
119 |
jsize length = aJniEnv->GetStringLength( string );
|
|
120 |
QString s = QString::fromUtf16( javaChars, length );
|
|
121 |
QByteArray a =s.toAscii();
|
|
122 |
|
|
123 |
HANDLE_TO_POINTER( QPropertyAnimation*, animation, aHandle );
|
|
124 |
|
|
125 |
animation->setPropertyName( a );
|
|
126 |
aJniEnv->ReleaseStringChars( string, javaChars );
|
|
127 |
}
|
|
128 |
SWT_CATCH
|
|
129 |
}
|
|
130 |
|
|
131 |
JNIEXPORT void JNICALL OS_NATIVE(QPropertyAnimation_1setTargetObject)
|
|
132 |
(JNIEnv *aJniEnv, jclass, jint aHandle, jint aWidgetHandle)
|
|
133 |
{
|
|
134 |
SWT_TRY
|
|
135 |
{
|
|
136 |
HANDLE_TO_POINTER( QPropertyAnimation*, animation, aHandle );
|
|
137 |
HANDLE_TO_POINTER( QObject*, object, aWidgetHandle );
|
|
138 |
animation->setTargetObject( object );
|
|
139 |
}
|
|
140 |
SWT_CATCH
|
|
141 |
}
|
|
142 |
|
|
143 |
JNIEXPORT void JNICALL OS_NATIVE( QVariantAnimation_1setDuration )
|
|
144 |
(JNIEnv *aJniEnv, jclass, jint aHandle, jint aDuration)
|
|
145 |
{
|
|
146 |
SWT_TRY
|
|
147 |
{
|
|
148 |
HANDLE_TO_POINTER( QVariantAnimation*, animation, aHandle );
|
|
149 |
animation->setDuration( aDuration );
|
|
150 |
}
|
|
151 |
SWT_CATCH
|
|
152 |
}
|
|
153 |
|
|
154 |
|
|
155 |
JNIEXPORT void JNICALL OS_NATIVE( QVariantAnimation_1setEasingCurve)
|
|
156 |
(JNIEnv *aJniEnv, jclass, jint aHandle, jint aEasing )
|
|
157 |
{
|
|
158 |
SWT_TRY
|
|
159 |
{
|
|
160 |
HANDLE_TO_POINTER( QVariantAnimation*, animation, aHandle );
|
|
161 |
QEasingCurve* easing = static_cast<QEasingCurve*>(reinterpret_cast<QEasingCurve*>( aEasing ));
|
|
162 |
animation->setEasingCurve( *easing );
|
|
163 |
}
|
|
164 |
SWT_CATCH
|
|
165 |
}
|
|
166 |
|
|
167 |
JNIEXPORT void JNICALL OS_NATIVE(QVariantAnimation_1swt_1setEndValuePoint)
|
|
168 |
(JNIEnv *aJniEnv, jclass, jint aHandle, jint aX, jint aY)
|
|
169 |
{
|
|
170 |
SWT_TRY
|
|
171 |
{
|
|
172 |
HANDLE_TO_POINTER( QVariantAnimation*, animation, aHandle );
|
|
173 |
QPoint point(static_cast<int>(aX), static_cast<int>(aY));
|
|
174 |
animation->setEndValue(QVariant(point));
|
|
175 |
}
|
|
176 |
SWT_CATCH
|
|
177 |
}
|
|
178 |
|
|
179 |
JNIEXPORT void JNICALL OS_NATIVE(QVariantAnimation_1swt_1setStartValuePoint)
|
|
180 |
(JNIEnv *aJniEnv, jclass, jint aHandle, jint aX, jint aY)
|
|
181 |
{
|
|
182 |
SWT_TRY
|
|
183 |
{
|
|
184 |
HANDLE_TO_POINTER( QVariantAnimation*, animation, aHandle );
|
|
185 |
QPoint point(static_cast<int>(aX), static_cast<int>(aY));
|
|
186 |
animation->setStartValue(QVariant(point));
|
|
187 |
}
|
|
188 |
SWT_CATCH
|
|
189 |
}
|
|
190 |
|
|
191 |
JNIEXPORT void JNICALL OS_NATIVE (QVariantAnimation_1swt_1setEndValueDouble)
|
|
192 |
(JNIEnv *aJniEnv, jclass, jint aHandle, jdouble aDouble)
|
|
193 |
{
|
|
194 |
SWT_TRY
|
|
195 |
{
|
|
196 |
HANDLE_TO_POINTER( QVariantAnimation*, animation, aHandle );
|
|
197 |
animation->setEndValue(QVariant(static_cast<double>(aDouble)));
|
|
198 |
}
|
|
199 |
SWT_CATCH
|
|
200 |
}
|
|
201 |
|
|
202 |
|
|
203 |
JNIEXPORT void JNICALL OS_NATIVE (QVariantAnimation_1swt_1setStartValueDouble )
|
|
204 |
(JNIEnv *aJniEnv, jclass, jint aHandle, jdouble aDouble)
|
|
205 |
{
|
|
206 |
SWT_TRY
|
|
207 |
{
|
|
208 |
HANDLE_TO_POINTER( QVariantAnimation*, animation, aHandle );
|
|
209 |
animation->setStartValue(QVariant(static_cast<double>(aDouble)));
|
|
210 |
}
|
|
211 |
SWT_CATCH
|
|
212 |
}
|
|
213 |
|
|
214 |
JNIEXPORT void JNICALL OS_NATIVE(QAnimationGroup_1addAnimation)
|
|
215 |
(JNIEnv *aJniEnv, jclass, jint aHandle, jint aAnimation)
|
|
216 |
{
|
|
217 |
SWT_TRY
|
|
218 |
{
|
|
219 |
HANDLE_TO_POINTER( QAnimationGroup*, group, aHandle );
|
|
220 |
HANDLE_TO_POINTER( QAbstractAnimation*, animation, aAnimation );
|
|
221 |
group->addAnimation(animation);
|
|
222 |
}
|
|
223 |
SWT_CATCH
|
|
224 |
}
|
|
225 |
|
|
226 |
JNIEXPORT jint JNICALL OS_NATIVE( QSequentialAnimationGroup_1new)
|
|
227 |
(JNIEnv *aJniEnv, jclass, jint aHandle)
|
|
228 |
{
|
|
229 |
QSequentialAnimationGroup* animation = NULL;
|
|
230 |
SWT_TRY
|
|
231 |
{
|
|
232 |
HANDLE_TO_POINTER( QObject*, parent, aHandle );
|
|
233 |
animation = new QSequentialAnimationGroup ( parent );
|
|
234 |
}
|
|
235 |
SWT_CATCH
|
|
236 |
return POINTER_TO_HANDLE( animation );
|
|
237 |
}
|
|
238 |
|
|
239 |
|
|
240 |
JNIEXPORT void OS_NATIVE( QSequentialAnimationGroup_1addPause)
|
|
241 |
(JNIEnv *aJniEnv, jclass, jint aHandle, jint aMsec)
|
|
242 |
{
|
|
243 |
SWT_TRY
|
|
244 |
{
|
|
245 |
HANDLE_TO_POINTER( QSequentialAnimationGroup*, animation, aHandle );
|
|
246 |
animation->addPause(aMsec);
|
|
247 |
}
|
|
248 |
SWT_CATCH
|
|
249 |
}
|
|
250 |
|
|
251 |
JNIEXPORT jint OS_NATIVE( QParallelAnimationGroup_1new)
|
|
252 |
(JNIEnv *aJniEnv, jclass, jint aHandle)
|
|
253 |
{
|
|
254 |
QParallelAnimationGroup* animation = NULL;
|
|
255 |
SWT_TRY
|
|
256 |
{
|
|
257 |
HANDLE_TO_POINTER( QObject*, parent, aHandle );
|
|
258 |
animation = new QParallelAnimationGroup( parent );
|
|
259 |
}
|
|
260 |
SWT_CATCH
|
|
261 |
return POINTER_TO_HANDLE( animation );
|
|
262 |
}
|
|
263 |
|
|
264 |
JNIEXPORT jint OS_NATIVE( QEasingCurve_1new)
|
|
265 |
(JNIEnv *aJniEnv, jclass, jint aType)
|
|
266 |
{
|
|
267 |
QEasingCurve* easing = NULL;
|
|
268 |
SWT_TRY
|
|
269 |
{
|
|
270 |
easing = new QEasingCurve( static_cast<QEasingCurve::Type>(aType) );
|
|
271 |
}
|
|
272 |
SWT_CATCH
|
|
273 |
return reinterpret_cast<jint>(easing);
|
|
274 |
|
|
275 |
}
|
|
276 |
|
|
277 |
#ifdef __cplusplus
|
|
278 |
}
|
|
279 |
#endif
|
|
280 |
|