1 /* qtcomponentpeer.cpp --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 #include <QApplication>
40 #include <QDesktopWidget>
46 #include <gnu_java_awt_peer_qt_QtComponentPeer.h>
47 #include "qtcomponent.h"
48 #include "componentevent.h"
51 extern QApplication
*qApplication
;
54 #define DEFAULT_CURSOR 0
55 #define CROSSHAIR_CURSOR 1
58 #define SW_RESIZE_CURSOR 4
59 #define SE_RESIZE_CURSOR 5
60 #define NW_RESIZE_CURSOR 6
61 #define NE_RESIZE_CURSOR 7
62 #define N_RESIZE_CURSOR 8
63 #define S_RESIZE_CURSOR 9
64 #define W_RESIZE_CURSOR 10
65 #define E_RESIZE_CURSOR 11
66 #define HAND_CURSOR 12
67 #define MOVE_CURSOR 13
70 * Call back the init() method from the main thread.
72 JNIEXPORT
void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_callInit
73 (JNIEnv
*env
, jobject obj
)
75 mainThread
->postEventToMain( new AWTInitEvent( env
, obj
) );
81 JNIEXPORT
void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_disposeNative
82 (JNIEnv
*env
, jobject obj
)
84 QWidget
*widget
= (QWidget
*) getNativeObject( env
, obj
);
85 setNativeObject(env
, obj
, NULL
);
86 mainThread
->postEventToMain( new AWTDestroyEvent( widget
) );
90 * Returns the on-screen location of the component.
92 JNIEXPORT
void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_getLocationOnScreenNative
93 (JNIEnv
*env
, jobject obj
, jobject point
)
95 QWidget
*widget
= (QWidget
*) getNativeObject( env
, obj
);
97 mainThread
->postEventToMain( new AWTGetOriginEvent( widget
, env
, point
) );
101 * Get the preferred/minimum size of the widget
103 JNIEXPORT
void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_getSizeNative
104 (JNIEnv
*env
, jobject obj
, jobject size
, jboolean preferred
)
106 QWidget
*widget
= (QWidget
*) getNativeObject( env
, obj
);
109 mainThread
->postEventToMain
110 (new GetSizeEvent( widget
, env
, size
, (preferred
== JNI_TRUE
)));
115 JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_isObscured
116 (JNIEnv
*env
, jobject obj
)
120 QWidget
*widget
= (QWidget
*) getNativeObject( env
, obj
);
123 retVal
= (widget
->isVisible() == TRUE
) ? JNI_TRUE
: JNI_FALSE
;
129 * Returns whether the widget is focusable or not.
131 JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_isFocusable
132 (JNIEnv
*env
, jobject obj
)
136 QWidget
*widget
= (QWidget
*) getNativeObject( env
, obj
);
139 retVal
= (widget
->focusPolicy() != Qt::NoFocus
) ? JNI_TRUE
: JNI_FALSE
;
147 JNIEXPORT
void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_requestFocus
148 (JNIEnv
*env
, jobject obj
)
150 QWidget
*widget
= (QWidget
*) getNativeObject( env
, obj
);
152 mainThread
->postEventToMain( new AWTReqFocusEvent( widget
) );
156 * Sets the size and position. Important.
158 JNIEXPORT
void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setBoundsNative
159 (JNIEnv
*env
, jobject obj
, jint x
, jint y
, jint width
, jint height
)
161 QWidget
*widget
= (QWidget
*) getNativeObject( env
, obj
);
163 mainThread
->postEventToMain
164 (new AWTResizeEvent( widget
, x
, y
, width
, height
) );
168 * Sets the mouse cursor
170 JNIEXPORT
void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setCursor
171 (JNIEnv
*env
, jobject obj
, jint cursortype
)
173 QWidget
*widget
= (QWidget
*) getNativeObject( env
, obj
);
176 Qt::CursorShape shape
;
179 case CROSSHAIR_CURSOR
:
180 shape
= Qt::CrossCursor
;
183 case W_RESIZE_CURSOR
:
184 case E_RESIZE_CURSOR
:
185 shape
= Qt::SizeHorCursor
;
187 case N_RESIZE_CURSOR
:
188 case S_RESIZE_CURSOR
:
189 shape
= Qt::SizeVerCursor
;
192 shape
= Qt::PointingHandCursor
;
195 shape
= Qt::SizeAllCursor
;
198 case NE_RESIZE_CURSOR
:
199 case SW_RESIZE_CURSOR
:
200 shape
= Qt::SizeBDiagCursor
;
202 case NW_RESIZE_CURSOR
:
203 case SE_RESIZE_CURSOR
:
204 shape
= Qt::SizeFDiagCursor
;
207 shape
= Qt::IBeamCursor
;
210 shape
= Qt::WaitCursor
;
215 shape
= Qt::ArrowCursor
;
219 mainThread
->postEventToMain( new AWTCursorEvent( widget
, shape
) );
225 JNIEXPORT
void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setEnabled
226 (JNIEnv
*env
, jobject obj
, jboolean state
)
228 QWidget
*widget
= (QWidget
*) getNativeObject( env
, obj
);
229 assert(widget
!= NULL
);
231 mainThread
->postEventToMain( new AWTEnableEvent( widget
, (state
== JNI_TRUE
) ) );
237 JNIEXPORT
void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setFontNative
238 (JNIEnv
*env
, jobject obj
, jobject fontpeer
)
240 QWidget
*widget
= (QWidget
*) getNativeObject( env
, obj
);
242 QFont
*font
= (QFont
*) getFont( env
, fontpeer
);
245 mainThread
->postEventToMain( new AWTFontEvent(widget
, font
) );
249 * Sets the back- or foreground color.
251 JNIEXPORT
void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setGround
252 (JNIEnv
*env
, jobject obj
, jint r
, jint g
, jint b
, jboolean isForeground
)
254 QColor
*color
= new QColor(r
, g
, b
);
256 QWidget
*widget
= (QWidget
*) getNativeObject( env
, obj
);
258 mainThread
->postEventToMain( new AWTBackgroundEvent(widget
,
259 (isForeground
== JNI_TRUE
),
264 * Sets the visibility.
266 JNIEXPORT
void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setVisible
267 (JNIEnv
*env
, jobject obj
, jboolean state
)
269 QWidget
*widget
= (QWidget
*) getNativeObject( env
, obj
);
270 assert(widget
!= NULL
);
271 mainThread
->postEventToMain( new AWTShowEvent( widget
, (state
== JNI_TRUE
) ) );
275 * Returns whether the widget handles wheel scrolling.
277 JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_handlesWheelScrolling
278 (JNIEnv
*env
, jobject obj
)
280 jboolean handles
= JNI_FALSE
;
282 QWidget
*cb
= (QWidget
*) getNativeObject( env
, obj
);
284 if( cb
->focusPolicy() & Qt::WheelFocus
)
291 * calls qwidget::update on the compnent.
293 JNIEXPORT
void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_QtUpdateArea
294 (JNIEnv
*env
, jobject obj
, jint x
, jint y
, jint w
, jint h
)
296 QWidget
*cb
= (QWidget
*) getNativeObject( env
, obj
);
298 mainThread
->postEventToMain( new AWTUpdateEvent
299 (cb
, false, x
, y
, w
, h
) );
303 * calls qwidget::update on the compnent.
305 JNIEXPORT
void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_QtUpdate
306 (JNIEnv
*env
, jobject obj
)
308 QWidget
*cb
= (QWidget
*) getNativeObject( env
, obj
);
310 mainThread
->postEventToMain( new AWTUpdateEvent
311 ( cb
, true, 0, 0, 0, 0 ) );
315 * Returns the native background color.
317 JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_getNativeBackground
318 (JNIEnv
*env
, jobject obj
)
320 QWidget
*cb
= (QWidget
*) getNativeObject( env
, obj
);
322 QColor c
= cb
->palette().background().color().toRgb();
324 jclass cls
= env
->FindClass("java/awt/Color");
325 jmethodID mid
= env
->GetMethodID(cls
, "<init>", "(III)V");
328 values
[0].i
= (jint
) c
.red();
329 values
[1].i
= (jint
) c
.green();
330 values
[2].i
= (jint
) c
.blue();
332 return env
->NewObjectA(cls
, mid
, values
);
336 * Returns which screen the component is on.
338 JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_whichScreen
339 (JNIEnv
*env
, jobject obj
)
341 QWidget
*widget
= (QWidget
*) getNativeObject( env
, obj
);
343 return (jint
) qApplication
->desktop()->screenNumber( widget
);
347 * Reparents the widget.
349 JNIEXPORT
void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_reparentNative
350 (JNIEnv
*env
, jobject obj
, jobject newparent
)
352 QWidget
*widget
= (QWidget
*) getNativeObject( env
, obj
);
354 QWidget
*parentWidget
= (QWidget
*) getNativeObject( env
, newparent
);
355 assert( parentWidget
);
356 mainThread
->postEventToMain( new AWTReparent(widget
, parentWidget
) );
360 * Get the preferred size of the widget
362 JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_getBounds
364 (JNIEnv
*env
, jobject obj
)
366 QWidget
*widget
= (QWidget
*) getNativeObject( env
, obj
);
370 widget
->geometry().getRect(&x
, &y
, &w
, &h
);
372 jclass cls
= env
->FindClass("java/awt/Rectangle");
373 assert( cls
!= NULL
);
374 jmethodID mid
= env
->GetMethodID(cls
, "<init>", "(IIII)V");
375 assert( mid
!= NULL
);
378 values
[0].i
= (jint
) x
;
379 values
[1].i
= (jint
) y
;
380 values
[2].i
= (jint
) w
;
381 values
[3].i
= (jint
) h
;
383 return env
->NewObjectA(cls
, mid
, values
);