summaryrefslogtreecommitdiff
path: root/native
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2005-08-16 16:22:34 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2005-08-16 16:22:34 +0000
commit988ea14cc6a504c6d5c7b9bfcbc01ca2b0a4e432 (patch)
tree0ee0ebd2e7d7a1b0b00edf51b48286965b1b4fca /native
parente439fd75db6107e87660301775017154f05e1c06 (diff)
downloadclasspath-988ea14cc6a504c6d5c7b9bfcbc01ca2b0a4e432.tar.gz
2005-08-16 Andrew John Hughes <gnu_andrew@member.fsf.org>
* Merge of HEAD-->generics-branch for 2005/08/07-2005/08/14.
Diffstat (limited to 'native')
-rw-r--r--native/jni/classpath/Makefile.am3
-rw-r--r--native/jni/classpath/classpath_jawt.h8
-rw-r--r--native/jni/gtk-peer/Makefile.am1
-rw-r--r--native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c50
-rw-r--r--native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c38
-rw-r--r--native/jni/gtk-peer/gtk_jawt.c197
-rw-r--r--native/jni/java-net/gnu_java_net_PlainSocketImpl.c1
-rw-r--r--native/jni/qt-peer/buttonevent.h27
-rw-r--r--native/jni/qt-peer/componentevent.cpp133
-rw-r--r--native/jni/qt-peer/componentevent.h203
-rw-r--r--native/jni/qt-peer/containers.h10
-rw-r--r--native/jni/qt-peer/eventmethods.cpp233
-rw-r--r--native/jni/qt-peer/keybindings.cpp545
-rw-r--r--native/jni/qt-peer/keybindings.h18
-rw-r--r--native/jni/qt-peer/mainqtthread.cpp102
-rw-r--r--native/jni/qt-peer/mainthreadinterface.cpp68
-rw-r--r--native/jni/qt-peer/mainthreadinterface.h39
-rw-r--r--native/jni/qt-peer/nativewrapper.cpp64
-rw-r--r--native/jni/qt-peer/nativewrapper.h10
-rw-r--r--native/jni/qt-peer/qmatrix.cpp95
-rw-r--r--native/jni/qt-peer/qpainterpath.cpp238
-rw-r--r--native/jni/qt-peer/qpen.cpp107
-rw-r--r--native/jni/qt-peer/qtaudioclip.cpp114
-rw-r--r--native/jni/qt-peer/qtbuttonpeer.cpp93
-rw-r--r--native/jni/qt-peer/qtcanvaspeer.cpp74
-rw-r--r--native/jni/qt-peer/qtcheckboxpeer.cpp163
-rw-r--r--native/jni/qt-peer/qtchoicepeer.cpp142
-rw-r--r--native/jni/qt-peer/qtcomponent.cpp122
-rw-r--r--native/jni/qt-peer/qtcomponent.h16
-rw-r--r--native/jni/qt-peer/qtcomponentpeer.cpp391
-rw-r--r--native/jni/qt-peer/qtdialogpeer.cpp163
-rw-r--r--native/jni/qt-peer/qtfiledialogpeer.cpp100
-rw-r--r--native/jni/qt-peer/qtfont.h8
-rw-r--r--native/jni/qt-peer/qtfontmetrics.cpp232
-rw-r--r--native/jni/qt-peer/qtfontpeer.cpp91
-rw-r--r--native/jni/qt-peer/qtframepeer.cpp202
-rw-r--r--native/jni/qt-peer/qtgraphics.cpp471
-rw-r--r--native/jni/qt-peer/qtgraphics.h26
-rw-r--r--native/jni/qt-peer/qtimage.cpp396
-rw-r--r--native/jni/qt-peer/qtimage.h8
-rw-r--r--native/jni/qt-peer/qtlabelpeer.cpp152
-rw-r--r--native/jni/qt-peer/qtlistpeer.cpp207
-rw-r--r--native/jni/qt-peer/qtmenubarpeer.cpp149
-rw-r--r--native/jni/qt-peer/qtmenucomponentpeer.cpp66
-rw-r--r--native/jni/qt-peer/qtmenuitempeer.cpp181
-rw-r--r--native/jni/qt-peer/qtmenupeer.cpp259
-rw-r--r--native/jni/qt-peer/qtpanelpeer.cpp73
-rw-r--r--native/jni/qt-peer/qtpopupmenupeer.cpp75
-rw-r--r--native/jni/qt-peer/qtscreendevice.cpp122
-rw-r--r--native/jni/qt-peer/qtscrollbarpeer.cpp141
-rw-r--r--native/jni/qt-peer/qtscrollpanepeer.cpp211
-rw-r--r--native/jni/qt-peer/qtstrings.cpp54
-rw-r--r--native/jni/qt-peer/qtstrings.h10
-rw-r--r--native/jni/qt-peer/qttextareapeer.cpp191
-rw-r--r--native/jni/qt-peer/qttextfieldpeer.cpp287
-rw-r--r--native/jni/qt-peer/qttoolkit.cpp156
-rw-r--r--native/jni/qt-peer/qtvolatileimage.cpp296
-rw-r--r--native/jni/qt-peer/qtwindowpeer.cpp146
-rw-r--r--native/jni/qt-peer/slotcallbacks.cpp199
-rw-r--r--native/jni/qt-peer/slotcallbacks.h18
-rw-r--r--native/jni/qt-peer/slotcallbacks.moc75
61 files changed, 8066 insertions, 4 deletions
diff --git a/native/jni/classpath/Makefile.am b/native/jni/classpath/Makefile.am
index 0171d3728..2baa60abc 100644
--- a/native/jni/classpath/Makefile.am
+++ b/native/jni/classpath/Makefile.am
@@ -1,3 +1,6 @@
+# Header needed for jawt implementations such as the one found in ../gtk-peer.
+EXTRA_DIST = classpath_jawt.h
+
noinst_LTLIBRARIES = libclasspath.la
libclasspath_la_SOURCES = jcl.c jcl.h \
diff --git a/native/jni/classpath/classpath_jawt.h b/native/jni/classpath/classpath_jawt.h
index 66ba9c70a..967f66fed 100644
--- a/native/jni/classpath/classpath_jawt.h
+++ b/native/jni/classpath/classpath_jawt.h
@@ -50,15 +50,15 @@ exception statement from your version. */
#define CLASSPATH_JAWT_VERSION 0x10004
-jint classpath_jawt_get_awt_version ();
+jint classpath_jawt_get_awt_version (void);
Display* classpath_jawt_get_default_display (JNIEnv* env, jobject canvas);
Drawable classpath_jawt_get_drawable (JNIEnv* env, jobject canvas);
VisualID classpath_jawt_get_visualID (JNIEnv* env, jobject canvas);
jint classpath_jawt_object_lock (jobject lock);
void classpath_jawt_object_unlock (jobject lock);
-jint classpath_jawt_lock ();
-void classpath_jawt_unlock ();
-jobject classpath_jawt_create_lock ();
+jint classpath_jawt_lock (void);
+void classpath_jawt_unlock (void);
+jobject classpath_jawt_create_lock (void);
void classpath_jawt_destroy_lock (jobject lock);
#endif /* __classpath_jawt_h__ */
diff --git a/native/jni/gtk-peer/Makefile.am b/native/jni/gtk-peer/Makefile.am
index f4e7bdfcc..0fe6d8311 100644
--- a/native/jni/gtk-peer/Makefile.am
+++ b/native/jni/gtk-peer/Makefile.am
@@ -47,6 +47,7 @@ libgtkpeer_la_SOURCES = $(gtk_cairo_c_source_files) \
gdkfont.h \
gthread-jni.h \
gtkcairopeer.h \
+ gtk_jawt.c \
gtkpeer.h
libgtkpeer_la_LIBADD = $(top_builddir)/native/jni/classpath/native_state.lo \
diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c
index 5e8ab26c3..140fbb54b 100644
--- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c
+++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkButtonPeer.c
@@ -86,6 +86,56 @@ Java_gnu_java_awt_peer_gtk_GtkButtonPeer_create
gdk_threads_leave ();
}
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_gtk_GtkButtonPeer_gtkWidgetGetPreferredDimensions
+ (JNIEnv *env, jobject obj, jintArray jdims)
+{
+ void *ptr;
+ jint *dims;
+ GtkWidget *button;
+ GtkWidget *label;
+ GtkRequisition current_req;
+ GtkRequisition current_label_req;
+ GtkRequisition natural_req;
+
+ gdk_threads_enter ();
+
+ ptr = NSA_GET_PTR (env, obj);
+
+ button = gtk_bin_get_child (GTK_BIN (ptr));
+ label = gtk_bin_get_child (GTK_BIN (button));
+
+ dims = (*env)->GetIntArrayElements (env, jdims, 0);
+ dims[0] = dims[1] = 0;
+
+ /* Save the button's current size request. */
+ gtk_widget_size_request (GTK_WIDGET (button), &current_req);
+
+ /* Save the label's current size request. */
+ gtk_widget_size_request (GTK_WIDGET (label), &current_label_req);
+
+ /* Get the widget's "natural" size request. */
+ gtk_widget_set_size_request (GTK_WIDGET (button), -1, -1);
+ gtk_widget_set_size_request (GTK_WIDGET (label), -1, -1);
+
+ gtk_widget_size_request (GTK_WIDGET (button), &natural_req);
+
+ /* Reset the button's size request. */
+ gtk_widget_set_size_request (GTK_WIDGET (button),
+ current_req.width, current_req.height);
+
+ /* Reset the label's size request. */
+ gtk_widget_set_size_request (GTK_WIDGET (label),
+ current_label_req.width, current_label_req.height);
+
+ dims[0] = natural_req.width;
+ dims[1] = natural_req.height;
+
+ (*env)->ReleaseIntArrayElements (env, jdims, dims, 0);
+
+ gdk_threads_leave ();
+}
+
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkButtonPeer_connectSignals
(JNIEnv *env, jobject obj)
diff --git a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c
index 7968ca773..74180a784 100644
--- a/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c
+++ b/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkLabelPeer.c
@@ -66,6 +66,44 @@ Java_gnu_java_awt_peer_gtk_GtkLabelPeer_create
gdk_threads_leave ();
}
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_gtk_GtkLabelPeer_gtkWidgetGetPreferredDimensions
+ (JNIEnv *env, jobject obj, jintArray jdims)
+{
+ void *ptr;
+ jint *dims;
+ GtkWidget *label;
+ GtkRequisition current_req;
+ GtkRequisition natural_req;
+
+ gdk_threads_enter ();
+
+ ptr = NSA_GET_PTR (env, obj);
+
+ label = gtk_bin_get_child (GTK_BIN (ptr));
+
+ dims = (*env)->GetIntArrayElements (env, jdims, 0);
+ dims[0] = dims[1] = 0;
+
+ /* Save the widget's current size request. */
+ gtk_widget_size_request (GTK_WIDGET (label), &current_req);
+
+ /* Get the widget's "natural" size request. */
+ gtk_widget_set_size_request (GTK_WIDGET (label), -1, -1);
+ gtk_widget_size_request (GTK_WIDGET (label), &natural_req);
+
+ /* Reset the widget's size request. */
+ gtk_widget_set_size_request (GTK_WIDGET (label),
+ current_req.width, current_req.height);
+
+ dims[0] = natural_req.width;
+ dims[1] = natural_req.height;
+
+ (*env)->ReleaseIntArrayElements (env, jdims, dims, 0);
+
+ gdk_threads_leave ();
+}
+
JNIEXPORT void JNICALL
Java_gnu_java_awt_peer_gtk_GtkLabelPeer_gtkWidgetModifyFont
(JNIEnv *env, jobject obj, jstring name, jint style, jint size)
diff --git a/native/jni/gtk-peer/gtk_jawt.c b/native/jni/gtk-peer/gtk_jawt.c
new file mode 100644
index 000000000..d540c1e56
--- /dev/null
+++ b/native/jni/gtk-peer/gtk_jawt.c
@@ -0,0 +1,197 @@
+/* gtk_jawt.c -- GTK implementation of classpath_jawt.h
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+ This file is part of GNU Classpath.
+
+ GNU Classpath is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ GNU Classpath is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU Classpath; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+
+ Linking this library statically or dynamically with other modules is
+ making a combined work based on this library. Thus, the terms and
+ conditions of the GNU General Public License cover the whole
+ combination.
+
+ As a special exception, the copyright holders of this library give you
+ permission to link this library with independent modules to produce an
+ executable, regardless of the license terms of these independent
+ modules, and to copy and distribute the resulting executable under
+ terms of your choice, provided that you also meet, for each linked
+ independent module, the terms and conditions of the license of that
+ module. An independent module is a module which is not derived from
+ or based on this library. If you modify this library, you may extend
+ this exception to your version of the library, but you are not
+ obligated to do so. If you do not wish to do so, delete this
+ exception statement from your version. */
+
+
+#include "gtkpeer.h"
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+#include "classpath_jawt.h"
+
+jint
+classpath_jawt_get_awt_version ()
+{
+ return CLASSPATH_JAWT_VERSION;
+}
+
+Display*
+classpath_jawt_get_default_display (JNIEnv* env, jobject canvas)
+{
+ GdkDisplay *display;
+ Display *xdisplay;
+ GtkWidget *widget;
+ void *ptr;
+ jobject peer;
+ jclass class_id;
+ jmethodID method_id;
+
+ /* retrieve peer object */
+ class_id = (*env)->GetObjectClass (env, canvas);
+
+ method_id = (*env)->GetMethodID (env, class_id,
+ "getPeer",
+ "()Ljava/awt/peer/ComponentPeer;");
+
+ peer = (*env)->CallObjectMethod (env, canvas, method_id);
+
+ ptr = NSA_GET_PTR (env, peer);
+
+ gdk_threads_enter ();
+
+ widget = GTK_WIDGET (ptr);
+
+ /* widget should be realized before Canvas.paint is called. */
+ g_assert (GTK_WIDGET_REALIZED (widget));
+
+ display = gtk_widget_get_display (widget);
+
+ xdisplay = GDK_DISPLAY_XDISPLAY (display);
+
+ gdk_threads_leave ();
+
+ return xdisplay;
+}
+
+VisualID
+classpath_jawt_get_visualID (JNIEnv* env, jobject canvas)
+{
+ GtkWidget *widget;
+ Visual *visual;
+ void *ptr;
+ jobject peer;
+ jclass class_id;
+ jmethodID method_id;
+
+ class_id = (*env)->GetObjectClass (env, canvas);
+
+ method_id = (*env)->GetMethodID (env, class_id,
+ "getPeer",
+ "()Ljava/awt/peer/ComponentPeer;");
+
+ peer = (*env)->CallObjectMethod (env, canvas, method_id);
+
+ ptr = NSA_GET_PTR (env, peer);
+
+ gdk_threads_enter ();
+
+ widget = GTK_WIDGET (ptr);
+
+ g_assert (GTK_WIDGET_REALIZED (widget));
+
+ visual = gdk_x11_visual_get_xvisual (gtk_widget_get_visual (widget));
+ g_assert (visual != NULL);
+
+ gdk_threads_leave ();
+
+ return visual->visualid;
+}
+
+Drawable
+classpath_jawt_get_drawable (JNIEnv* env, jobject canvas)
+{
+ GtkWidget *widget;
+ int drawable;
+ void *ptr;
+ jobject peer;
+ jclass class_id;
+ jmethodID method_id;
+
+ class_id = (*env)->GetObjectClass (env, canvas);
+
+ method_id = (*env)->GetMethodID (env, class_id,
+ "getPeer",
+ "()Ljava/awt/peer/ComponentPeer;");
+
+ peer = (*env)->CallObjectMethod (env, canvas, method_id);
+
+ ptr = NSA_GET_PTR (env, peer);
+
+ gdk_threads_enter ();
+
+ widget = GTK_WIDGET (ptr);
+
+ g_assert (GTK_WIDGET_REALIZED (widget));
+
+ drawable = GDK_DRAWABLE_XID (widget->window);
+
+ gdk_threads_leave ();
+
+ return drawable;
+}
+
+jint
+classpath_jawt_object_lock (jobject lock)
+{
+ JNIEnv *env = cp_gtk_gdk_env();
+ (*env)->MonitorEnter (env, lock);
+ return 0;
+}
+
+void
+classpath_jawt_object_unlock (jobject lock)
+{
+ JNIEnv *env = cp_gtk_gdk_env();
+ (*env)->MonitorExit (env, lock);
+}
+
+jint
+classpath_jawt_lock ()
+{
+ gdk_threads_enter ();
+ return 0;
+}
+
+void
+classpath_jawt_unlock ()
+{
+ gdk_threads_leave ();
+}
+
+jobject
+classpath_jawt_create_lock ()
+{
+ JNIEnv *env = cp_gtk_gdk_env ();
+ jobject lock = (*env)->NewStringUTF (env, "jawt-lock");
+ NSA_SET_GLOBAL_REF (env, lock);
+ return lock;
+}
+
+void
+classpath_jawt_destroy_lock (jobject lock)
+{
+ JNIEnv *env = cp_gtk_gdk_env ();
+ NSA_DEL_GLOBAL_REF (env, lock);
+}
diff --git a/native/jni/java-net/gnu_java_net_PlainSocketImpl.c b/native/jni/java-net/gnu_java_net_PlainSocketImpl.c
index a5261514d..f5f22ab77 100644
--- a/native/jni/java-net/gnu_java_net_PlainSocketImpl.c
+++ b/native/jni/java-net/gnu_java_net_PlainSocketImpl.c
@@ -50,6 +50,7 @@ exception statement from your version. */
#include "target_native.h"
#ifndef WITHOUT_NETWORK
+#include "target_native_file.h" /* Get FIONREAD on Solaris. */
#include "target_native_network.h"
#endif /* WITHOUT_NETWORK */
diff --git a/native/jni/qt-peer/buttonevent.h b/native/jni/qt-peer/buttonevent.h
new file mode 100644
index 000000000..aab11dd03
--- /dev/null
+++ b/native/jni/qt-peer/buttonevent.h
@@ -0,0 +1,27 @@
+#ifndef BUTTONEVENT_H
+#define BUTTONEVENT_H
+
+#include <QAbstractButton>
+#include "mainthreadinterface.h"
+
+class AWTLabelEvent : public AWTEvent {
+
+ private:
+ QAbstractButton *widget;
+ QString *string;
+
+ public:
+ AWTLabelEvent(QAbstractButton *w, QString *s) : AWTEvent()
+ {
+ widget = w;
+ string = s;
+ }
+
+ void runEvent()
+ {
+ widget->setText( *string );
+ delete string;
+ }
+};
+
+#endif
diff --git a/native/jni/qt-peer/componentevent.cpp b/native/jni/qt-peer/componentevent.cpp
new file mode 100644
index 000000000..4a46a5a52
--- /dev/null
+++ b/native/jni/qt-peer/componentevent.cpp
@@ -0,0 +1,133 @@
+/* componentevent.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include "componentevent.h"
+
+AWTInitEvent::AWTInitEvent(JNIEnv *env, jobject obj) : AWTEvent()
+{
+ env->GetJavaVM( &vm );
+ target = env->NewGlobalRef( obj );
+}
+
+void AWTInitEvent::runEvent()
+{
+ JNIEnv *env;
+ vm->GetEnv((void **)&env, JNI_VERSION_1_1);
+ jclass targetCls = env->GetObjectClass( target );
+ jmethodID initID = env->GetMethodID( targetCls,
+ "init",
+ "()V" );
+ env->MonitorEnter( target );
+ env->CallVoidMethod( target, initID );
+ env->MonitorExit( target );
+ env->DeleteGlobalRef( target );
+}
+
+AWTShowEvent::AWTShowEvent(QWidget *w, bool v) : AWTEvent()
+{
+ widget = w;
+ visible = v;
+}
+
+void AWTShowEvent::runEvent()
+{
+ widget->setVisible( visible );
+}
+
+AWTEnableEvent::AWTEnableEvent(QWidget *w, bool v) : AWTEvent()
+{
+ widget = w;
+ enabled = v;
+}
+
+void AWTEnableEvent::runEvent()
+{
+ widget->setEnabled( enabled );
+}
+
+AWTCursorEvent::AWTCursorEvent(QWidget *w, Qt::CursorShape s) : AWTEvent()
+{
+ widget = w;
+ shape = s;
+}
+
+void AWTCursorEvent::runEvent()
+{
+ QCursor *s = new QCursor(shape);
+ widget->setCursor( *s );
+}
+
+AWTResizeEvent::AWTResizeEvent(QWidget *wid, int x0, int y0, int w0, int h0)
+{
+ widget = wid;
+ x = x0; y = y0;
+ w = w0; h = h0;
+ if(w == 0 && h == 0) w = h = 10;
+}
+
+void AWTResizeEvent::runEvent()
+{
+ widget->setGeometry( x, y, w, h );
+}
+
+AWTBackgroundEvent::AWTBackgroundEvent(QWidget *wid, bool fg, QColor *clr)
+{
+ widget = wid;
+ foreground = fg;
+ color = clr;
+}
+
+void AWTBackgroundEvent::runEvent()
+{
+ QPalette p = widget->palette();
+ if (foreground)
+ {
+ p.setColor(QPalette::Active, QPalette::Foreground, *color);
+ p.setColor(QPalette::Active, QPalette::Text, *color);
+ }
+ else
+ {
+ p.setColor(QPalette::Active, QPalette::Background, *color);
+ p.setColor(QPalette::Active, QPalette::Button, *color);
+ p.setColor(QPalette::Active, QPalette::Base, *color);
+ p.setColor(QPalette::Active, QPalette::AlternateBase, *color);
+ }
+ widget->setPalette(p);
+ widget->repaint();
+ delete color;
+}
+
diff --git a/native/jni/qt-peer/componentevent.h b/native/jni/qt-peer/componentevent.h
new file mode 100644
index 000000000..cfcbef860
--- /dev/null
+++ b/native/jni/qt-peer/componentevent.h
@@ -0,0 +1,203 @@
+#ifndef CALLBACKEVENT_H
+#define CALLBACKEVENT_H
+
+#include <jni.h>
+#include <QEvent>
+#include <QColor>
+#include <QCursor>
+#include <QFont>
+#include <QPoint>
+#include <QWidget>
+#include <QSize>
+
+#include "mainthreadinterface.h"
+
+class AWTInitEvent : public AWTEvent {
+
+ private:
+ JavaVM* vm;
+ jobject target;
+
+ public:
+ AWTInitEvent(JNIEnv *env, jobject obj);
+ void runEvent();
+};
+
+class AWTDestroyEvent : public AWTEvent {
+
+ private:
+ QWidget *widget;
+
+ public:
+ AWTDestroyEvent(QWidget *w)
+ {
+ widget = w;
+ }
+
+ void runEvent()
+ {
+ delete widget;
+ }
+};
+
+class AWTFontEvent : public AWTEvent {
+
+ private:
+ QWidget *widget;
+ QFont *font;
+
+ public:
+ AWTFontEvent(QWidget *w, QFont *f)
+ {
+ widget = w;
+ font = f;
+ }
+
+ void runEvent()
+ {
+ widget->setFont( *font );
+ }
+};
+
+class AWTUpdateEvent : public AWTEvent {
+
+ private:
+ QWidget *widget;
+ int x,y,w,h;
+ bool updateAll;
+
+ public:
+ AWTUpdateEvent(QWidget *src, bool all, int x0, int y0, int w0, int h0)
+ {
+ widget = src;
+ updateAll = all;
+ x = x0; y = y0; w = w0; h = h0;
+ }
+
+ void runEvent()
+ {
+ if(updateAll)
+ widget->update();
+ else
+ widget->update(x,y,w,h);
+ }
+};
+
+class AWTShowEvent : public AWTEvent {
+
+ private:
+ QWidget *widget;
+ bool visible;
+
+ public:
+ AWTShowEvent(QWidget *w, bool v);
+ void runEvent();
+};
+
+class AWTEnableEvent : public AWTEvent {
+
+ private:
+ QWidget *widget;
+ bool enabled;
+
+ public:
+ AWTEnableEvent(QWidget *w, bool v);
+ void runEvent();
+};
+
+class AWTCursorEvent : public AWTEvent {
+
+ private:
+ QWidget *widget;
+ Qt::CursorShape shape;
+
+ public:
+ AWTCursorEvent(QWidget *w, Qt::CursorShape s);
+ void runEvent();
+};
+
+class AWTResizeEvent : public AWTEvent {
+
+ private:
+ QWidget *widget;
+ int x, y, w, h;
+
+ public:
+ AWTResizeEvent(QWidget *wid, int x0, int y0, int w0, int h0);
+ void runEvent();
+};
+
+class AWTBackgroundEvent : public AWTEvent {
+
+ private:
+ QWidget *widget;
+ bool foreground;
+ QColor *color;
+
+ public:
+ AWTBackgroundEvent(QWidget *wid, bool fg, QColor *clr);
+ void runEvent();
+};
+
+class AWTReqFocusEvent : public AWTEvent {
+
+ private:
+ QWidget *widget;
+
+ public:
+ AWTReqFocusEvent(QWidget *w) : AWTEvent()
+ {
+ widget = w;
+ }
+ void runEvent()
+ {
+ widget->setFocus();
+ }
+};
+
+class AWTGetOriginEvent : public AWTEvent {
+
+ private:
+ QWidget *widget;
+ QPoint **origin;
+
+ public:
+ AWTGetOriginEvent(QWidget *w, QPoint **o) : AWTEvent()
+ {
+ widget = w;
+ origin = o;
+ }
+ void runEvent()
+ {
+ *origin = new QPoint( widget->mapToGlobal( QPoint(0, 0) ) );
+ }
+};
+
+class AWTGetSizeEvent : public AWTEvent {
+
+ private:
+ QWidget *widget;
+ bool preferred;
+
+ public:
+
+ QSize **size;
+
+ AWTGetSizeEvent(QWidget *w, QSize **s, bool pref) : AWTEvent()
+ {
+ widget = w;
+ preferred = pref;
+ size = s;
+ }
+ void runEvent()
+ {
+ QSize s;
+ if( preferred )
+ s = widget->sizeHint();
+ else
+ s = widget->minimumSizeHint();
+ *size = new QSize( s.width(), s.height() );
+ }
+};
+
+#endif
diff --git a/native/jni/qt-peer/containers.h b/native/jni/qt-peer/containers.h
new file mode 100644
index 000000000..a2ae76af0
--- /dev/null
+++ b/native/jni/qt-peer/containers.h
@@ -0,0 +1,10 @@
+#ifndef QTFRAME_H
+#define QTFRAME_H
+
+#include <jni.h>
+#include <QWidget>
+
+QWidget *frameChildWidget( JNIEnv *env, jobject component );
+QWidget *scrollPaneChildWidget( JNIEnv *env, jobject component);
+
+#endif
diff --git a/native/jni/qt-peer/eventmethods.cpp b/native/jni/qt-peer/eventmethods.cpp
new file mode 100644
index 000000000..3e5482622
--- /dev/null
+++ b/native/jni/qt-peer/eventmethods.cpp
@@ -0,0 +1,233 @@
+/* eventmethods.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#ifdef I_KNOW_WHAT_IM_DOING
+
+private:
+ JavaVM* vm;
+ jobject target;
+ jclass componentCls;
+
+ void setup(JNIEnv *env, jobject obj)
+ {
+ env->GetJavaVM(&vm);
+ componentCls = NULL;
+ target = env->NewGlobalRef(obj);
+ componentCls = (jclass)env->NewGlobalRef(env->GetObjectClass( target ));
+ setMouseTracking( true );
+ }
+
+ void destroy()
+ {
+ JNIEnv *env;
+ vm->GetEnv((void **)&env, JNI_VERSION_1_1);
+ env->DeleteGlobalRef(target);
+ env->DeleteGlobalRef(componentCls);
+ }
+
+ void callVoidMethod(char *methodName)
+ {
+ JNIEnv *env;
+ vm->GetEnv((void **)&env, JNI_VERSION_1_1);
+ jmethodID fireEventID = env->GetMethodID( componentCls,
+ methodName,
+ "()V" );
+ env->CallVoidMethod( target, fireEventID );
+ }
+
+ void callMouseMethod(char *methodName,
+ int modifiers, int x, int y, int clickCount)
+ {
+ JNIEnv *env;
+ vm->GetEnv((void **)&env, JNI_VERSION_1_1);
+ jmethodID fireEventID = env->GetMethodID( componentCls,
+ methodName,
+ "(IIII)V" );
+ env->CallVoidMethod( target, fireEventID, modifiers, x, y, clickCount );
+ }
+
+protected:
+
+ void closeEvent( QCloseEvent *e )
+ {
+ PARENT::closeEvent(e);
+ callVoidMethod("closeEvent");
+ }
+
+ void focusInEvent( QFocusEvent *e )
+ {
+ PARENT::focusInEvent(e);
+ callVoidMethod("focusInEvent");
+ }
+
+ void focusOutEvent( QFocusEvent *e )
+ {
+ PARENT::focusOutEvent(e);
+ callVoidMethod("focusOutEvent");
+ }
+
+ void enterEvent( QEvent *e )
+ {
+ PARENT::enterEvent(e);
+ QPoint p = mapFromGlobal( QCursor::pos() );
+ int modifiers = getKeyModifiers( QApplication::keyboardModifiers() );
+ callMouseMethod("enterEvent", modifiers, p.x(), p.y(), 0);
+ }
+
+ void keyPressEvent( QKeyEvent *e )
+ {
+ PARENT::keyPressEvent(e);
+ int modifiers, x, y;
+ modifiers = getKeyModifiers(e->modifiers());
+ x = mapKeyCode(e);
+ y = getUnicode(e);
+ callMouseMethod("keyPressEvent", modifiers, x, y, 0);
+ }
+
+ void keyReleaseEvent( QKeyEvent *e )
+ {
+ PARENT::keyReleaseEvent(e);
+ int modifiers, x, y;
+ modifiers = getKeyModifiers(e->modifiers());
+ x = mapKeyCode(e);
+ y = getUnicode(e);
+ callMouseMethod("keyReleaseEvent", modifiers, x, y, 0);
+ }
+
+ void leaveEvent( QEvent *e )
+ {
+ PARENT::leaveEvent(e);
+ QPoint p = mapFromGlobal( QCursor::pos() );
+ int modifiers = getKeyModifiers( QApplication::keyboardModifiers() );
+ callMouseMethod("leaveEvent", modifiers, p.x(), p.y(), 0);
+ }
+
+ void mouseDoubleClickEvent( QMouseEvent *e )
+ {
+ PARENT::mouseDoubleClickEvent(e);
+ int modifiers, x, y, clickCount;
+ clickCount = 2;
+ modifiers = getMouseModifiers(e);
+ x = e->x();
+ y = e->y();
+ callMouseMethod("mouseDoubleClickEvent", modifiers, x, y, clickCount);
+ }
+
+ void mouseMoveEvent( QMouseEvent *e )
+ {
+ PARENT::mouseMoveEvent(e);
+ int modifiers, x, y, clickCount;
+ clickCount = 0;
+ modifiers = getMouseModifiers(e);
+ x = e->x();
+ y = e->y();
+ callMouseMethod("mouseMoveEvent", modifiers, x, y, clickCount);
+ }
+
+ void mousePressEvent( QMouseEvent *e )
+ {
+ PARENT::mousePressEvent(e);
+ int modifiers, x, y, clickCount;
+ clickCount = 0;
+ modifiers = getMouseModifiers(e);
+ x = e->x();
+ y = e->y();
+ callMouseMethod("mousePressEvent", modifiers, x, y, clickCount);
+ }
+
+ void mouseReleaseEvent( QMouseEvent *e )
+ {
+ PARENT::mouseReleaseEvent(e);
+ int modifiers, x, y, clickCount;
+ clickCount = 0;
+ modifiers = getMouseModifiers(e);
+ x = e->x();
+ y = e->y();
+ callMouseMethod("mouseReleaseEvent", modifiers, x, y, clickCount);
+ }
+
+ void moveEvent( QMoveEvent *e )
+ {
+ PARENT::moveEvent(e);
+ callVoidMethod("moveEvent");
+ }
+
+ void resizeEvent( QResizeEvent *e )
+ {
+ PARENT::resizeEvent(e);
+ callMouseMethod("resizeEvent",
+ e->oldSize().width(), e->oldSize().height(),
+ e->size().width(), e->size().height());
+ }
+
+ void hideEvent( QHideEvent *e )
+ {
+ PARENT::hideEvent(e);
+ callVoidMethod("hideEvent");
+ }
+
+ void showEvent( QShowEvent *e )
+ {
+ PARENT::showEvent(e);
+ callVoidMethod("showEvent");
+ }
+
+ void paintEvent ( QPaintEvent * e )
+ {
+ PARENT::paintEvent(e);
+ // Create a QPainter
+ GraphicsPainter painter( this );
+
+ // Get the environment.
+ JNIEnv *env;
+ vm->GetEnv((void **)&env, JNI_VERSION_1_1);
+
+ // create a QtGraphics wrapper for the QPainter
+ jclass cls = env->FindClass( "gnu/java/awt/peer/qt/QtComponentGraphics" );
+ jmethodID mid = env->GetMethodID(cls, "<init>", "(JLgnu/java/awt/peer/qt/QtComponentPeer;)V");
+ jobject graphics = env->NewObject(cls, mid, (jlong)&painter, target);
+
+ // call QtComponentPeer.paintEvent()
+ jmethodID paintEventID = env->GetMethodID( componentCls,
+ "paintEvent",
+ "(Lgnu/java/awt/peer/qt/QtGraphics;)V" );
+ env->CallVoidMethod( target, paintEventID, graphics );
+ env->DeleteLocalRef( cls );
+ env->DeleteLocalRef( graphics );
+ }
+
+#endif
diff --git a/native/jni/qt-peer/keybindings.cpp b/native/jni/qt-peer/keybindings.cpp
new file mode 100644
index 000000000..ff2a8a461
--- /dev/null
+++ b/native/jni/qt-peer/keybindings.cpp
@@ -0,0 +1,545 @@
+/* keybindings.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include "keybindings.h"
+
+/* InputEvent key modifiers */
+#define SHIFT_MASK 1
+#define CTRL_MASK 2
+#define META_MASK 4
+#define ALT_MASK 8
+#define ALT_GRAPH_MASK 0x20
+#define BUTTON1_MASK 0x10
+#define BUTTON2_MASK 8
+#define BUTTON3_MASK 4
+
+#define SHIFT_DOWN_MASK 0x0040
+#define CTRL_DOWN_MASK 0x0080
+#define META_DOWN_MASK 0x0100
+#define ALT_DOWN_MASK 0x0200
+#define BUTTON1_DOWN_MASK 0x0400
+#define BUTTON2_DOWN_MASK 0x0800
+#define BUTTON3_DOWN_MASK 0x1000
+#define ALT_GRAPH_DOWN_MASK 0x2000
+
+/* Virtual Keys */
+/* This list should be kept in the same order as the VK_ field
+ declarations in KeyEvent.java. */
+#define VK_ENTER '\n'
+#define VK_BACK_SPACE '\b'
+#define VK_TAB '\t'
+#define VK_CANCEL 3
+#define VK_CLEAR 12
+#define VK_SHIFT 16
+#define VK_CONTROL 17
+#define VK_ALT 18
+#define VK_PAUSE 19
+#define VK_CAPS_LOCK 20
+#define VK_ESCAPE 27
+#define VK_SPACE ' '
+#define VK_PAGE_UP 33
+#define VK_PAGE_DOWN 34
+#define VK_END 35
+#define VK_HOME 36
+#define VK_LEFT 37
+#define VK_UP 38
+#define VK_RIGHT 39
+#define VK_DOWN 40
+#define VK_COMMA ','
+#define VK_MINUS '-'
+#define VK_PERIOD '.'
+#define VK_SLASH '/'
+#define VK_0 '0'
+#define VK_1 '1'
+#define VK_2 '2'
+#define VK_3 '3'
+#define VK_4 '4'
+#define VK_5 '5'
+#define VK_6 '6'
+#define VK_7 '7'
+#define VK_8 '8'
+#define VK_9 '9'
+#define VK_SEMICOLON ';'
+#define VK_EQUALS '='
+#define VK_A 'A'
+#define VK_B 'B'
+#define VK_C 'C'
+#define VK_D 'D'
+#define VK_E 'E'
+#define VK_F 'F'
+#define VK_G 'G'
+#define VK_H 'H'
+#define VK_I 'I'
+#define VK_J 'J'
+#define VK_K 'K'
+#define VK_L 'L'
+#define VK_M 'M'
+#define VK_N 'N'
+#define VK_O 'O'
+#define VK_P 'P'
+#define VK_Q 'Q'
+#define VK_R 'R'
+#define VK_S 'S'
+#define VK_T 'T'
+#define VK_U 'U'
+#define VK_V 'V'
+#define VK_W 'W'
+#define VK_X 'X'
+#define VK_Y 'Y'
+#define VK_Z 'Z'
+#define VK_OPEN_BRACKET '['
+#define VK_BACK_SLASH '\\'
+#define VK_CLOSE_BRACKET ']'
+#define VK_NUMPAD0 96
+#define VK_NUMPAD1 97
+#define VK_NUMPAD2 98
+#define VK_NUMPAD3 99
+#define VK_NUMPAD4 100
+#define VK_NUMPAD5 101
+#define VK_NUMPAD6 102
+#define VK_NUMPAD7 103
+#define VK_NUMPAD8 104
+#define VK_NUMPAD9 105
+#define VK_MULTIPLY 106
+#define VK_ADD 107
+#define VK_SEPARATER 108
+#define VK_SEPARATOR 108
+#define VK_SUBTRACT 109
+#define VK_DECIMAL 110
+#define VK_DIVIDE 111
+#define VK_DELETE 127
+#define VK_NUM_LOCK 144
+#define VK_SCROLL_LOCK 145
+#define VK_F1 112
+#define VK_F2 113
+#define VK_F3 114
+#define VK_F4 115
+#define VK_F5 116
+#define VK_F6 117
+#define VK_F7 118
+#define VK_F8 119
+#define VK_F9 120
+#define VK_F10 121
+#define VK_F11 122
+#define VK_F12 123
+#define VK_F13 61440
+#define VK_F14 61441
+#define VK_F15 61442
+#define VK_F16 61443
+#define VK_F17 61444
+#define VK_F18 61445
+#define VK_F19 61446
+#define VK_F20 61447
+#define VK_F21 61448
+#define VK_F22 61449
+#define VK_F23 61450
+#define VK_F24 61451
+#define VK_PRINTSCREEN 154
+#define VK_INSERT 155
+#define VK_HELP 156
+#define VK_META 157
+#define VK_BACK_QUOTE 192
+#define VK_QUOTE 222
+#define VK_KP_UP 224
+#define VK_KP_DOWN 225
+#define VK_KP_LEFT 226
+#define VK_KP_RIGHT 227
+#define VK_DEAD_GRAVE 128
+#define VK_DEAD_ACUTE 129
+#define VK_DEAD_CIRCUMFLEX 130
+#define VK_DEAD_TILDE 131
+#define VK_DEAD_MACRON 132
+#define VK_DEAD_BREVE 133
+#define VK_DEAD_ABOVEDOT 134
+#define VK_DEAD_DIAERESIS 135
+#define VK_DEAD_ABOVERING 136
+#define VK_DEAD_DOUBLEACUTE 137
+#define VK_DEAD_CARON 138
+#define VK_DEAD_CEDILLA 139
+#define VK_DEAD_OGONEK 140
+#define VK_DEAD_IOTA 141
+#define VK_DEAD_VOICED_SOUND 142
+#define VK_DEAD_SEMIVOICED_SOUND 143
+#define VK_AMPERSAND 150
+#define VK_ASTERISK 151
+#define VK_QUOTEDBL 152
+#define VK_LESS 153
+#define VK_GREATER 160
+#define VK_BRACELEFT 161
+#define VK_BRACERIGHT 162
+#define VK_AT 512
+#define VK_COLON 513
+#define VK_CIRCUMFLEX 514
+#define VK_DOLLAR 515
+#define VK_EURO_SIGN 516
+#define VK_EXCLAMATION_MARK 517
+#define VK_INVERTED_EXCLAMATION_MARK 518
+#define VK_LEFT_PARENTHESIS 519
+#define VK_NUMBER_SIGN 520
+#define VK_PLUS 521
+#define VK_RIGHT_PARENTHESIS 522
+#define VK_UNDERSCORE 523
+#define VK_FINAL 24
+#define VK_CONVERT 28
+#define VK_NONCONVERT 29
+#define VK_ACCEPT 30
+#define VK_MODECHANGE 31
+#define VK_KANA 21
+#define VK_KANJI 25
+#define VK_ALPHANUMERIC 240
+#define VK_KATAKANA 241
+#define VK_HIRAGANA 242
+#define VK_FULL_WIDTH 243
+#define VK_HALF_WIDTH 244
+#define VK_ROMAN_CHARACTERS 245
+#define VK_ALL_CANDIDATES 256
+#define VK_PREVIOUS_CANDIDATE 257
+#define VK_CODE_INPUT 258
+#define VK_JAPANESE_KATAKANA 259
+#define VK_JAPANESE_HIRAGANA 260
+#define VK_JAPANESE_ROMAN 261
+#define VK_KANA_LOCK 262
+#define VK_INPUT_METHOD_ON_OFF 263
+#define VK_CUT 65489
+#define VK_COPY 65485
+#define VK_PASTE 65487
+#define VK_UNDO 65483
+#define VK_AGAIN 65481
+#define VK_FIND 65488
+#define VK_PROPS 65482
+#define VK_STOP 65480
+#define VK_COMPOSE 65312
+#define VK_ALT_GRAPH 65406
+#define VK_UNDEFINED 0
+
+
+int mapKeyCode(QKeyEvent *key)
+{
+ switch(key->key())
+ {
+ case Qt::Key_Escape:
+ return VK_ESCAPE;
+ case Qt::Key_Tab:
+ return VK_TAB;
+ case Qt::Key_Backspace:
+ return VK_BACK_SPACE;
+ case Qt::Key_Return:
+ case Qt::Key_Enter:
+ return VK_ENTER;
+ case Qt::Key_Insert:
+ return VK_INSERT;
+ case Qt::Key_Delete:
+ return VK_DELETE;
+ case Qt::Key_Pause:
+ return VK_PAUSE;
+ case Qt::Key_Print:
+ case Qt::Key_SysReq:
+ return VK_PRINTSCREEN;
+ case Qt::Key_Home:
+ return VK_HOME;
+ case Qt::Key_End:
+ return VK_END;
+ case Qt::Key_Left:
+ return VK_LEFT;
+ case Qt::Key_Up:
+ return VK_UP;
+ case Qt::Key_Right:
+ return VK_RIGHT;
+ case Qt::Key_Down:
+ return VK_DOWN;
+ case Qt::Key_PageUp:
+ return VK_PAGE_UP;
+ case Qt::Key_PageDown:
+ return VK_PAGE_DOWN;
+ case Qt::Key_Shift:
+ return VK_SHIFT;
+ case Qt::Key_Control:
+ return VK_CONTROL;
+ case Qt::Key_Meta:
+ return VK_META;
+ case Qt::Key_Alt:
+ return VK_ALT;
+ case Qt::Key_CapsLock:
+ return VK_CAPS_LOCK;
+ case Qt::Key_NumLock:
+ return VK_NUM_LOCK;
+ case Qt::Key_ScrollLock:
+ return VK_SCROLL_LOCK;
+ case Qt::Key_Clear:
+ return VK_CLEAR;
+ case Qt::Key_F1:
+ return VK_F1;
+ case Qt::Key_F2:
+ return VK_F2;
+ case Qt::Key_F3:
+ return VK_F3;
+ case Qt::Key_F4:
+ return VK_F4;
+ case Qt::Key_F5:
+ return VK_F5;
+ case Qt::Key_F6:
+ return VK_F6;
+ case Qt::Key_F7:
+ return VK_F7;
+ case Qt::Key_F8:
+ return VK_F8;
+ case Qt::Key_F9:
+ return VK_F9;
+ case Qt::Key_F10:
+ return VK_F10;
+ case Qt::Key_F11:
+ return VK_F11;
+ case Qt::Key_F12:
+ return VK_F12;
+ case Qt::Key_F13:
+ return VK_F13;
+ case Qt::Key_F14:
+ return VK_F14;
+ case Qt::Key_F15:
+ return VK_F15;
+ case Qt::Key_F16:
+ return VK_F16;
+ case Qt::Key_F17:
+ return VK_F17;
+ case Qt::Key_F18:
+ return VK_F18;
+ case Qt::Key_F19:
+ return VK_F19;
+ case Qt::Key_F20:
+ return VK_F20;
+ case Qt::Key_F21:
+ return VK_F21;
+ case Qt::Key_F22:
+ return VK_F22;
+ case Qt::Key_F23:
+ return VK_F23;
+ case Qt::Key_F24:
+ return VK_F24;
+ case Qt::Key_Help:
+ return VK_HELP;
+
+ case Qt::Key_Space:
+ return VK_SPACE;
+
+ case Qt::Key_Exclam:
+ return VK_EXCLAMATION_MARK;
+ case Qt::Key_QuoteDbl:
+ return VK_QUOTEDBL;
+ case Qt::Key_NumberSign:
+ return VK_NUMBER_SIGN;
+
+ case Qt::Key_Dollar:
+ return VK_DOLLAR;
+
+
+ case Qt::Key_Ampersand:
+ return VK_AMPERSAND;
+
+ case Qt::Key_ParenLeft:
+ return VK_LEFT_PARENTHESIS;
+ case Qt::Key_ParenRight:
+ return VK_RIGHT_PARENTHESIS;
+ case Qt::Key_Asterisk:
+ return VK_ASTERISK;
+ case Qt::Key_Plus:
+ return VK_PLUS;
+ case Qt::Key_Comma:
+ return VK_COMMA;
+ case Qt::Key_Minus:
+ return VK_MINUS;
+ case Qt::Key_Period:
+ return VK_PERIOD;
+ case Qt::Key_Slash:
+ return VK_SLASH;
+
+ case Qt::Key_0:
+ return VK_0;
+ case Qt::Key_1:
+ return VK_1;
+ case Qt::Key_2:
+ return VK_2;
+ case Qt::Key_3:
+ return VK_3;
+ case Qt::Key_4:
+ return VK_4;
+ case Qt::Key_5:
+ return VK_5 ;
+ case Qt::Key_6:
+ return VK_6;
+ case Qt::Key_7:
+ return VK_7;
+ case Qt::Key_8:
+ return VK_8;
+ case Qt::Key_9:
+ return VK_9;
+
+ case Qt::Key_Colon:
+ return VK_COLON;
+ case Qt::Key_Semicolon:
+ return VK_SEMICOLON;
+ case Qt::Key_Less:
+ return VK_LESS;
+ case Qt::Key_Equal:
+ return VK_EQUALS;
+ case Qt::Key_Greater:
+ return VK_GREATER;
+ case Qt::Key_Question:
+ case Qt::Key_At:
+
+ case Qt::Key_A:
+ return VK_A;
+ case Qt::Key_B:
+ return VK_B;
+ case Qt::Key_C:
+ return VK_C;
+ case Qt::Key_D:
+ return VK_D;
+ case Qt::Key_E:
+ return VK_E;
+ case Qt::Key_F:
+ return VK_F;
+ case Qt::Key_G:
+ return VK_G;
+ case Qt::Key_H:
+ return VK_H;
+ case Qt::Key_I:
+ return VK_I;
+ case Qt::Key_J:
+ return VK_J;
+ case Qt::Key_K:
+ return VK_K;
+ case Qt::Key_L:
+ return VK_L;
+ case Qt::Key_M:
+ return VK_M;
+ case Qt::Key_N:
+ return VK_N;
+ case Qt::Key_O:
+ return VK_O;
+ case Qt::Key_P:
+ return VK_P;
+ case Qt::Key_Q:
+ return VK_Q;
+ case Qt::Key_R:
+ return VK_R;
+ case Qt::Key_S:
+ return VK_S;
+ case Qt::Key_T:
+ return VK_T;
+ case Qt::Key_U:
+ return VK_U;
+ case Qt::Key_V:
+ return VK_V;
+ case Qt::Key_W:
+ return VK_W;
+ case Qt::Key_X:
+ return VK_X;
+ case Qt::Key_Y:
+ return VK_Y;
+ case Qt::Key_Z:
+ return VK_Z;
+ case Qt::Key_division:
+ return VK_DIVIDE;
+ case Qt::Key_BracketLeft:
+ return VK_OPEN_BRACKET;
+ case Qt::Key_Backslash:
+ return VK_BACK_SLASH;
+ case Qt::Key_BracketRight:
+ return VK_CLOSE_BRACKET;
+ case Qt::Key_BraceLeft:
+ return VK_BRACELEFT;
+ case Qt::Key_BraceRight:
+ return VK_BRACERIGHT;
+ case Qt::Key_brokenbar:
+ return VK_SEPARATOR; // correct?
+
+ default:
+ return VK_UNDEFINED;
+ }
+}
+
+int getUnicode(QKeyEvent *key)
+{
+ QString s = key->text();
+ if(s.isEmpty())
+ return 0; // CHAR_UNDEFINED
+ QChar c = s.at(0);
+ return (int)c.unicode();
+}
+
+int getKeyModifiers(Qt::KeyboardModifiers state)
+{
+ int modifier = 0;
+ if( state & Qt::ShiftModifier )
+ modifier |= SHIFT_DOWN_MASK;
+ if( state & Qt::ControlModifier )
+ modifier |= CTRL_DOWN_MASK;
+ if( state & Qt::AltModifier )
+ modifier |= ALT_DOWN_MASK;
+ if( state & Qt::MetaModifier )
+ modifier |= META_DOWN_MASK;
+
+ return modifier;
+}
+
+int getMouseModifiers(QMouseEvent *e)
+{
+ int modifier = 0;
+ int buttons = e->buttons();
+ int state = e->modifiers();
+
+ if( buttons & Qt::LeftButton )
+ modifier |= BUTTON1_DOWN_MASK;
+ if( buttons & Qt::MidButton )
+ modifier |= BUTTON2_DOWN_MASK;
+ if( buttons & Qt::RightButton )
+ modifier |= BUTTON3_DOWN_MASK;
+
+ if( state & Qt::ShiftModifier )
+ modifier |= SHIFT_DOWN_MASK;
+ if( state & Qt::ControlModifier )
+ modifier |= CTRL_DOWN_MASK;
+ if( state & Qt::AltModifier )
+ modifier |= ALT_DOWN_MASK;
+ if( state & Qt::MetaModifier )
+ modifier |= META_DOWN_MASK;
+
+ // FIXME: Alt Gr?
+ return modifier;
+}
+
+
diff --git a/native/jni/qt-peer/keybindings.h b/native/jni/qt-peer/keybindings.h
new file mode 100644
index 000000000..02ff894bd
--- /dev/null
+++ b/native/jni/qt-peer/keybindings.h
@@ -0,0 +1,18 @@
+#ifndef KEYBINDINGS_H
+#define KEYBINDINGS_H
+
+#include <QApplication>
+#include <QKeyEvent>
+#include <QMouseEvent>
+#include <QPainter>
+#include <QPoint>
+#include <qwidget.h>
+#include <qstring.h>
+#include "qtgraphics.h"
+
+int mapKeyCode(QKeyEvent *key);
+int getUnicode(QKeyEvent *key);
+int getKeyModifiers(Qt::KeyboardModifiers state);
+int getMouseModifiers(QMouseEvent *event);
+
+#endif
diff --git a/native/jni/qt-peer/mainqtthread.cpp b/native/jni/qt-peer/mainqtthread.cpp
new file mode 100644
index 000000000..a908370b4
--- /dev/null
+++ b/native/jni/qt-peer/mainqtthread.cpp
@@ -0,0 +1,102 @@
+/* mainqtthread.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <jni.h>
+#include <QApplication>
+#include <QThread>
+#include <gnu_java_awt_peer_qt_MainQtThread.h>
+#include "mainthreadinterface.h"
+
+MainThreadInterface *mainThread;
+QApplication *qApplication;
+
+/**
+ * Starts up a QApplication
+ */
+JNIEXPORT jlong JNICALL Java_gnu_java_awt_peer_qt_MainQtThread_init
+(JNIEnv *env, jobject obj, jstring theme)
+{
+ int *argc;
+ char **argv;
+
+ if(theme != NULL)
+ {
+ argc = (int*)malloc(sizeof(int));
+ *argc = 3;
+ argv = (char **)malloc( 3 * sizeof(char *) );
+ argv[0] = (char *)malloc(10 * sizeof(char));
+ argv[1] = (char *)malloc(10 * sizeof(char));
+ argv[2] = (char *)malloc(100 * sizeof(char));
+ strncpy(argv[0], "\0", 2);
+ strncpy(argv[1], "-style\0", 8);
+ strncpy(argv[2], (char *)env->GetStringUTFChars( theme, NULL ), 100);
+ }
+ else
+ {
+ argc = (int*)malloc(sizeof(int));
+ *argc = 1;
+ argv = (char **)malloc( 3 * sizeof(char *) );
+ argv[0] = (char *)malloc(10 * sizeof(char));
+ strncpy(argv[0], " \0", 3);
+ }
+ QApplication *qtApp = new QApplication( *argc, argv );
+ assert( qtApp );
+
+ qApplication = qtApp;
+
+ if( theme != NULL)
+ env->ReleaseStringUTFChars( theme, argv[1] );
+
+ mainThread = new MainThreadInterface( qtApp );
+
+ jclass cls = env->GetObjectClass(obj);
+ jfieldID nofid = env->GetFieldID( cls, "mainThreadInterface", "J" );
+ env->SetLongField( obj, nofid, (jlong)mainThread );
+
+ return (jlong)qtApp;
+}
+
+/*
+ * Calls QApplication::exec()
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_MainQtThread_exec
+(JNIEnv *env, jobject obj, jlong ptr)
+{
+ QApplication *app = (QApplication *)ptr;
+ if(app)
+ app->exec();
+}
diff --git a/native/jni/qt-peer/mainthreadinterface.cpp b/native/jni/qt-peer/mainthreadinterface.cpp
new file mode 100644
index 000000000..6eb2a0df0
--- /dev/null
+++ b/native/jni/qt-peer/mainthreadinterface.cpp
@@ -0,0 +1,68 @@
+/* mainthreadinterface.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QWidget>
+#include <QThread>
+#include "mainthreadinterface.h"
+
+MainThreadInterface::MainThreadInterface(QApplication *parent) : QObject( parent )
+{
+ mainApp = parent;
+}
+
+/**
+ * This is called from the main Qt event loop, and delegates the work to
+ * the AWTEvent runEvent method.
+ */
+bool MainThreadInterface::event ( QEvent * e )
+{
+ if( e->type() == QEvent::User)
+ {
+ AWTEvent *fe = (AWTEvent *)e;
+ fe->runEvent();
+ }
+ return true;
+}
+
+/**
+ * Posts the event to the main Qt event loop for execution.
+ */
+void MainThreadInterface::postEventToMain(AWTEvent *event)
+{
+ mainApp->postEvent(this, event);
+}
+
diff --git a/native/jni/qt-peer/mainthreadinterface.h b/native/jni/qt-peer/mainthreadinterface.h
new file mode 100644
index 000000000..cabf44775
--- /dev/null
+++ b/native/jni/qt-peer/mainthreadinterface.h
@@ -0,0 +1,39 @@
+#ifndef MAINTHREADINTERFACE_H
+#define MAINTHREADINTERFACE_H
+
+#include <jni.h>
+#include <QApplication>
+#include <QObject>
+#include <QWidget>
+#include <QEvent>
+
+class AWTEvent : public QEvent {
+
+ public:
+ AWTEvent() : QEvent( QEvent::User )
+ {
+ }
+
+ virtual void runEvent()
+ {
+ }
+
+};
+
+#define AWT_INIT 0
+#define AWT_SETVISIBLE 1
+
+class MainThreadInterface : public QObject {
+
+ private:
+ QApplication *mainApp;
+
+ public:
+ MainThreadInterface(QApplication *parent);
+ bool event ( QEvent * e );
+ void postEventToMain(AWTEvent *event);
+};
+
+extern MainThreadInterface *mainThread;
+
+#endif
diff --git a/native/jni/qt-peer/nativewrapper.cpp b/native/jni/qt-peer/nativewrapper.cpp
new file mode 100644
index 000000000..0dec02c96
--- /dev/null
+++ b/native/jni/qt-peer/nativewrapper.cpp
@@ -0,0 +1,64 @@
+/* nativewrapper.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include "nativewrapper.h"
+
+#define WRAPPER_CLASS "gnu/java/awt/peer/qt/NativeWrapper"
+
+/*
+ * Sets the native object field.
+ */
+void setNativeObject( JNIEnv *env, jobject qtcomponent, void *ptr )
+{
+ jclass cls = env->GetObjectClass( qtcomponent );
+ jlong value = (jlong) ptr;
+ jfieldID nofid = env->GetFieldID( cls, "nativeObject", "J" );
+ env->SetLongField( qtcomponent, nofid, value );
+ env->DeleteLocalRef( cls );
+}
+
+/**
+ * Gets the native object field.
+ */
+void *getNativeObject( JNIEnv *env, jobject qtcomponent )
+{
+ jclass cls = env->GetObjectClass( qtcomponent );
+ jfieldID nofid = env->GetFieldID( cls, "nativeObject", "J" );
+ jlong value = env->GetLongField( qtcomponent, nofid );
+ env->DeleteLocalRef( cls );
+ return (void *) value;
+}
diff --git a/native/jni/qt-peer/nativewrapper.h b/native/jni/qt-peer/nativewrapper.h
new file mode 100644
index 000000000..1207aa1d3
--- /dev/null
+++ b/native/jni/qt-peer/nativewrapper.h
@@ -0,0 +1,10 @@
+#ifndef NATIVEWRAPPER_H
+#define NATIVEWRAPPER_H
+
+#include <jni.h>
+
+void *getNativeObject( JNIEnv *env, jobject qtcomponent );
+
+void setNativeObject( JNIEnv *env, jobject qtcomponent, void *ptr );
+
+#endif
diff --git a/native/jni/qt-peer/qmatrix.cpp b/native/jni/qt-peer/qmatrix.cpp
new file mode 100644
index 000000000..96a9407d8
--- /dev/null
+++ b/native/jni/qt-peer/qmatrix.cpp
@@ -0,0 +1,95 @@
+/* qmatrix.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QMatrix>
+#include <gnu_java_awt_peer_qt_QMatrix.h>
+#include "nativewrapper.h"
+
+/*
+ * Creates a QMatrix
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QMatrix_init
+(JNIEnv *env, jobject obj, jdouble m00, jdouble m10, jdouble m01, jdouble m11,
+ jdouble m02, jdouble m12 )
+{
+ QMatrix *matrix = new QMatrix( (qreal) m00, (qreal) m10,
+ (qreal) m01, (qreal) m11,
+ (qreal) m02, (qreal) m12 );
+ assert( matrix );
+ setNativeObject(env, obj, matrix);
+}
+
+/*
+ * Returns the matrix a java array of doubles,
+ * in m00, m10, m01, m11, m02, m12 (java notation) format.
+ * Note that qt has different notations for the array elements.
+ */
+JNIEXPORT jdoubleArray JNICALL Java_gnu_java_awt_peer_qt_QMatrix_getMatrix
+(JNIEnv *env, jobject obj)
+{
+ QMatrix *matrix = (QMatrix *)getNativeObject(env, obj);
+ assert( matrix );
+
+ jdoubleArray result_array;
+ jdouble *dst;
+
+ result_array = env->NewDoubleArray( 6 );
+ dst = env->GetDoubleArrayElements(result_array, NULL);
+
+ dst[0] = (jdouble)matrix->m11(); // qt m11 = java m00
+ dst[1] = (jdouble)matrix->m12(); // qt m12 = java m10
+ dst[2] = (jdouble)matrix->m21(); // qt m21 = java m01
+ dst[3] = (jdouble)matrix->m22(); // qt m22 = java m11
+ dst[4] = (jdouble)matrix->dx(); // qt dx = java m02
+ dst[5] = (jdouble)matrix->dy(); // qt dy = java m12
+
+ env->ReleaseDoubleArrayElements (result_array, dst, 0);
+ return result_array;
+}
+
+/*
+ * Dispose of the thing.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QMatrix_dispose
+(JNIEnv *env, jobject obj)
+{
+ QMatrix *matrix = (QMatrix *)getNativeObject(env, obj);
+ if( matrix )
+ delete matrix;
+ setNativeObject(env, obj, NULL);
+}
+
diff --git a/native/jni/qt-peer/qpainterpath.cpp b/native/jni/qt-peer/qpainterpath.cpp
new file mode 100644
index 000000000..97103d6a5
--- /dev/null
+++ b/native/jni/qt-peer/qpainterpath.cpp
@@ -0,0 +1,238 @@
+/* qpainterpath.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QPainterPath>
+#include <gnu_java_awt_peer_qt_QPainterPath.h>
+#include "nativewrapper.h"
+
+// java.awt.geom.PathIterator constants.
+#define WIND_EVEN_ODD 0
+#define WIND_NON_ZERO 1
+
+
+/*
+ * Creates an empty QPainterPath.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_init
+(JNIEnv *env, jobject obj, jint windingRule)
+{
+ QPainterPath *path = new QPainterPath();
+ assert( path );
+ path->setFillRule( (windingRule == WIND_EVEN_ODD) ?
+ Qt::OddEvenFill : Qt::WindingFill );
+ setNativeObject(env, obj, path);
+}
+
+/*
+ * MoveTo
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_moveTo
+(JNIEnv *env, jobject obj, jdouble x, jdouble y)
+{
+ QPainterPath *path = (QPainterPath *)getNativeObject(env, obj);
+ assert( path );
+ path->moveTo( (qreal)x, (qreal)y );
+}
+
+/*
+ * Closes the subpath.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_close
+(JNIEnv *env, jobject obj)
+{
+ QPainterPath *path = (QPainterPath *)getNativeObject(env, obj);
+ assert( path );
+ path->closeSubpath();
+}
+
+/*
+ * LineTo
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_lineTo
+(JNIEnv *env, jobject obj, jdouble x, jdouble y)
+{
+ QPainterPath *path = (QPainterPath *)getNativeObject(env, obj);
+ assert( path );
+ path->lineTo( (qreal)x, (qreal)y );
+}
+
+/*
+ * QuadraticTo
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_quadTo
+(JNIEnv *env, jobject obj, jdouble x, jdouble y, jdouble x2, jdouble y2)
+{
+ QPainterPath *path = (QPainterPath *)getNativeObject(env, obj);
+ assert( path );
+ path->quadTo( (qreal)x, (qreal)y, (qreal)x2, (qreal)y2 );
+}
+
+/*
+ * CubicTo
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_cubicTo
+(JNIEnv *env, jobject obj, jdouble x, jdouble y, jdouble x2, jdouble y2,
+ jdouble x3, jdouble y3)
+{
+ QPainterPath *path = (QPainterPath *)getNativeObject(env, obj);
+ assert( path );
+ path->cubicTo( (qreal)x, (qreal)y,
+ (qreal)x2, (qreal)y2,
+ (qreal)x3, (qreal)y3 );
+}
+
+/*
+ * Delete the native object
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_dispose
+ (JNIEnv *env, jobject obj)
+{
+ QPainterPath *path = (QPainterPath *)getNativeObject(env, obj);
+ if ( path )
+ delete path;
+}
+
+/********* GeneralPath functions *****************************/
+
+// FIXME : Cache method ids.
+
+static void gp_moveTo( JNIEnv *env,
+ jobject gp,
+ jclass cls,
+ double x1,
+ double y1 )
+{
+ jmethodID method;
+ jvalue values[2];
+
+ values[0].f = (jfloat) x1;
+ values[1].f = (jfloat) y1;
+
+ method = env->GetMethodID(cls, "moveTo", "(FF)V");
+ env->CallVoidMethodA( gp, method, values );
+}
+
+static void gp_lineTo( JNIEnv *env,
+ jobject gp,
+ jclass cls,
+ double x1,
+ double y1 )
+{
+ jmethodID method;
+ jvalue values[2];
+
+ values[0].f = (jfloat) x1;
+ values[1].f = (jfloat) y1;
+
+ method = env->GetMethodID(cls, "lineTo", "(FF)V");
+ env->CallVoidMethodA( gp, method, values );
+}
+
+static void gp_curveTo( JNIEnv *env,
+ jobject gp,
+ jclass cls,
+ double x1,
+ double y1,
+ double x2,
+ double y2,
+ double x3,
+ double y3 )
+{
+ jmethodID method;
+ jvalue values[6];
+
+ values[0].f = (jfloat) x1;
+ values[1].f = (jfloat) y1;
+ values[2].f = (jfloat) x2;
+ values[3].f = (jfloat) y2;
+ values[4].f = (jfloat) x3;
+ values[5].f = (jfloat) y3;
+
+ method = env->GetMethodID(cls, "curveTo", "(FFFFFF)V");
+ env->CallVoidMethodA( gp, method, values );
+}
+
+/**
+ * Returns the QPainterPath obj as a java.awt.geom.GeneralPath.
+ */
+JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QPainterPath_getPath
+(JNIEnv *env, jobject obj)
+{
+ jclass cls;
+ jmethodID method;
+ jobject gp;
+ QPainterPath::Element currElement;
+ int windingRule;
+
+ QPainterPath *path = new QPainterPath();
+ assert( path );
+
+ windingRule = (path->fillRule() == Qt::OddEvenFill) ?
+ WIND_EVEN_ODD : WIND_NON_ZERO;
+
+ cls = env->FindClass("java/awt/geom/GeneralPath");
+ method = env->GetMethodID(cls, "<init>", "(I)V");
+ gp = env->NewObject(cls, method, windingRule);
+
+ for( int i = 0; i < path->elementCount(); i++)
+ {
+ currElement = path->elementAt( i );
+ switch(currElement.type)
+ {
+ case QPainterPath::MoveToElement:
+ gp_moveTo(env, gp, cls, currElement.x, currElement.y);
+ break;
+ case QPainterPath::LineToElement:
+ gp_lineTo(env, gp, cls, currElement.x, currElement.y);
+ break;
+ case QPainterPath::CurveToElement:
+ if( i + 2 >= path->elementCount() )
+ break;
+ if(path->elementAt(i + 1).type != QPainterPath::CurveToDataElement ||
+ path->elementAt(i + 2).type != QPainterPath::CurveToDataElement)
+ break;
+ gp_curveTo(env, gp, cls, currElement.x, currElement.y,
+ path->elementAt(i + 1).x, path->elementAt(i + 1).y,
+ path->elementAt(i + 2).x, path->elementAt(i + 2).y );
+ i += 2;
+ break;
+ }
+ }
+ env->DeleteLocalRef( cls );
+ return gp;
+}
+
diff --git a/native/jni/qt-peer/qpen.cpp b/native/jni/qt-peer/qpen.cpp
new file mode 100644
index 000000000..de3cf4721
--- /dev/null
+++ b/native/jni/qt-peer/qpen.cpp
@@ -0,0 +1,107 @@
+/* qpen.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QColor>
+#include <QPen>
+#include <gnu_java_awt_peer_qt_QPen.h>
+#include "nativewrapper.h"
+
+/*
+ * java.awt.geom.BasicStroke constants.
+ */
+#define JOIN_MITER 0
+#define JOIN_ROUND 1
+#define JOIN_BEVEL 2
+#define CAP_BUTT 0
+#define CAP_ROUND 1
+#define CAP_SQUARE 2
+
+/**
+ * Create a QPen object
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPen_init
+(JNIEnv *env, jobject obj , jdouble width, jint cap, jint join, jdouble miterlimit)
+{
+ Qt::PenCapStyle qtCap;
+ Qt::PenJoinStyle qtJoin;
+
+ switch(cap)
+ {
+ case CAP_BUTT:
+ qtCap = Qt::FlatCap;
+ break;
+ case CAP_ROUND:
+ qtCap = Qt::RoundCap;
+ break;
+ case CAP_SQUARE:
+ qtCap = Qt::SquareCap;
+ break;
+ }
+
+ switch(join)
+ {
+ case JOIN_MITER:
+ qtJoin = Qt::MiterJoin;
+ break;
+ case JOIN_ROUND:
+ qtJoin = Qt::RoundJoin;
+ break;
+ case JOIN_BEVEL:
+ qtJoin = Qt::BevelJoin;
+ break;
+ }
+
+ QPen *pen = new QPen();
+ assert( pen );
+ pen->setWidthF( (qreal)width );
+ pen->setCapStyle( qtCap );
+ pen->setJoinStyle( qtJoin );
+
+ setNativeObject(env, obj, pen);
+}
+
+/**
+ * Dispose of the QPen object
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QPen_dispose
+(JNIEnv *env, jobject obj)
+{
+ QPen *pen = (QPen *)getNativeObject(env, obj);
+ if ( pen )
+ delete pen;
+}
+
diff --git a/native/jni/qt-peer/qtaudioclip.cpp b/native/jni/qt-peer/qtaudioclip.cpp
new file mode 100644
index 000000000..d5689b26d
--- /dev/null
+++ b/native/jni/qt-peer/qtaudioclip.cpp
@@ -0,0 +1,114 @@
+/* qtaudioclip.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <jni.h>
+#include <assert.h>
+#include <QString>
+#include <QSound>
+#include <gnu_java_awt_peer_qt_QtAudioClip.h>
+#include "qtstrings.h"
+#include "nativewrapper.h"
+
+/*
+ * Loads an audio clip. Returns JNI_TRUE if the load succeded,
+ * JNI_FALSE otherwise.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtAudioClip_loadClip
+(JNIEnv *env, jobject obj, jstring filename)
+{
+ QString *qStr = getQString(env, filename);
+
+ QSound *sound = new QSound( *qStr );
+
+ delete qStr;
+
+ setNativeObject( env, obj, sound );
+}
+
+/*
+ * Plays the audio clip, plays looped if loop equals JNI_TRUE.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtAudioClip_play
+(JNIEnv *env, jobject obj, jboolean loop)
+{
+ QSound *sound = (QSound *)getNativeObject(env, obj);
+ if( sound != NULL )
+ {
+ sound->setLoops( (loop == JNI_TRUE) ? -1 : 1 );
+ sound->play();
+ }
+}
+
+/*
+ * Stops the audio playback.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtAudioClip_stop
+(JNIEnv *env, jobject obj)
+{
+ QSound *sound = (QSound *)getNativeObject(env, obj);
+ if( sound != NULL )
+ sound->stop();
+}
+
+/**
+ * Disposes the audio clip
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtAudioClip_dispose
+(JNIEnv *env, jobject obj)
+{
+ QSound *sound = (QSound *)getNativeObject(env, obj);
+ if( sound != NULL )
+ {
+ setNativeObject( env, obj, NULL );
+ if( !sound->isFinished() )
+ sound->stop();
+ delete sound;
+ }
+}
+
+/**
+ * Returns whether sound is available.
+ */
+JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtAudioClip_isAvailable
+(JNIEnv *env, jobject obj)
+{
+ if( QSound::isAvailable() )
+ return JNI_TRUE;
+ else
+ return JNI_FALSE;
+}
+
diff --git a/native/jni/qt-peer/qtbuttonpeer.cpp b/native/jni/qt-peer/qtbuttonpeer.cpp
new file mode 100644
index 000000000..cf0ec21d7
--- /dev/null
+++ b/native/jni/qt-peer/qtbuttonpeer.cpp
@@ -0,0 +1,93 @@
+/* qtbuttonpeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QMainWindow>
+#include <QPushButton>
+#include <QFont>
+#include <gnu_java_awt_peer_qt_QtButtonPeer.h>
+#include "qtcomponent.h"
+#include "qtstrings.h"
+#include "keybindings.h"
+#include "buttonevent.h"
+#include "slotcallbacks.h"
+
+
+class MyButton : public QPushButton
+{
+public:
+ MyButton(JNIEnv *env, jobject obj, QWidget *parent) : QPushButton(parent)
+ {
+ setup(env, obj);
+ }
+
+ ~MyButton()
+ {
+ destroy();
+ }
+#define I_KNOW_WHAT_IM_DOING
+#define PARENT QPushButton
+#include "eventmethods.cpp"
+};
+
+/**
+ * Init method
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtButtonPeer_init
+(JNIEnv *env, jobject obj)
+{
+
+ QWidget *parentWidget = (QWidget *) getParentWidget( env, obj );
+ MyButton *button = new MyButton( env, obj, parentWidget );
+ assert( button );
+ setNativeObject( env, obj, button );
+ connectButton(button, env, obj); // connect the fireClick method.
+}
+
+/**
+ * Sets the button label.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtButtonPeer_setLabel
+(JNIEnv *env, jobject obj, jstring str)
+{
+ QPushButton *button = (QPushButton *) getNativeObject( env, obj );
+ assert( button );
+
+ QString *qStr = getQString(env, str); // AWTLabelEvent takes care of disposal.
+ mainThread->postEventToMain( new AWTLabelEvent( button, qStr ) );
+}
+
+
diff --git a/native/jni/qt-peer/qtcanvaspeer.cpp b/native/jni/qt-peer/qtcanvaspeer.cpp
new file mode 100644
index 000000000..f6f6926bf
--- /dev/null
+++ b/native/jni/qt-peer/qtcanvaspeer.cpp
@@ -0,0 +1,74 @@
+/* qtcanvaspeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QMainWindow>
+#include <QWidget>
+#include <gnu_java_awt_peer_qt_QtCanvasPeer.h>
+#include "qtcomponent.h"
+#include "keybindings.h"
+
+class MyCanvas : public QWidget
+{
+public:
+ MyCanvas(JNIEnv *env, jobject obj, QWidget *parent) : QWidget( parent )
+ {
+ setup(env, obj);
+ }
+
+ ~MyCanvas()
+ {
+ destroy();
+ }
+
+#define I_KNOW_WHAT_IM_DOING
+#define PARENT QWidget
+#include "eventmethods.cpp"
+};
+
+/*
+ * Construct a QWidget object
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtCanvasPeer_init
+(JNIEnv *env, jobject obj)
+{
+ QWidget *parentWidget = (QWidget *)getParentWidget(env, obj);
+ // QWidget *canvas = new QWidget( parentWidget );
+ QWidget *canvas = new MyCanvas( env, obj, parentWidget );
+ assert( canvas );
+
+ setNativeObject( env, obj, canvas );
+}
diff --git a/native/jni/qt-peer/qtcheckboxpeer.cpp b/native/jni/qt-peer/qtcheckboxpeer.cpp
new file mode 100644
index 000000000..018d2e06c
--- /dev/null
+++ b/native/jni/qt-peer/qtcheckboxpeer.cpp
@@ -0,0 +1,163 @@
+/* qtcheckboxpeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QAbstractButton>
+#include <QCheckBox>
+#include <QRadioButton>
+#include <gnu_java_awt_peer_qt_QtCheckboxPeer.h>
+#include "qtstrings.h"
+#include "qtcomponent.h"
+#include "keybindings.h"
+#include "buttonevent.h"
+#include "slotcallbacks.h"
+
+class CheckboxCheckEvent : public AWTEvent {
+
+ private:
+ QAbstractButton *widget;
+ bool checked;
+
+ public:
+ CheckboxCheckEvent(QAbstractButton *w, bool c)
+ {
+ widget = w;
+ checked = c;
+ }
+
+ void runEvent()
+ {
+ if (checked != widget->isChecked())
+ widget->setChecked( checked );
+ }
+};
+
+class MyCheckBox : public QCheckBox
+{
+public:
+ MyCheckBox(JNIEnv *env, jobject obj, QWidget *parent) : QCheckBox( parent )
+ {
+ setup(env, obj);
+ }
+
+ ~MyCheckBox()
+ {
+ destroy();
+ }
+
+#define I_KNOW_WHAT_IM_DOING
+#define PARENT QCheckBox
+#include "eventmethods.cpp"
+};
+
+/**
+ * Determines whether the darn native object should be a radio button or not
+ */
+static bool isRadioButton( JNIEnv *env, jobject obj )
+{
+ jclass cls = env->FindClass( "gnu/java/awt/peer/qt/QtCheckboxPeer" );
+ jfieldID field = env->GetFieldID( cls, "group", "Ljava/awt/CheckboxGroup;" );
+ if (env->GetObjectField( obj, field ) != NULL)
+ return true;
+ return false;
+}
+
+/**
+ * Construct the native object.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtCheckboxPeer_init
+(JNIEnv *env, jobject obj)
+{
+ QWidget *parentWidget = (QWidget *)getParentWidget(env, obj);
+
+ QAbstractButton *cb = (QAbstractButton *) getNativeObject( env, obj );
+ if (cb)
+ delete cb;
+
+ bool radioButton;
+ {
+ jclass cls = env->GetObjectClass( obj );
+ jfieldID field = env->GetFieldID( cls, "owner", "Ljava/awt/Component;" );
+ assert(field != NULL);
+ jobject owner = env->GetObjectField( obj, field );
+ assert(owner != NULL);
+ cls = env->GetObjectClass( owner );
+ jmethodID method = env->GetMethodID( cls,
+ "getCheckboxGroup",
+ "()Ljava/awt/CheckboxGroup;" );
+ assert(method != NULL);
+ jobject group = env->CallObjectMethod( owner, method, 0);
+ radioButton = (group != NULL);
+ }
+
+ if(radioButton)
+ cb = new QRadioButton( parentWidget );
+ else
+ cb = new QCheckBox( parentWidget );
+ // cb = new MyCheckBox( env, obj, parentWidget );
+ assert( cb );
+
+ connectToggle(cb, env, obj); // connect the native event.
+
+ setNativeObject( env, obj, cb );
+}
+
+/*
+ * Sets the checkbox label.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtCheckboxPeer_setLabel
+(JNIEnv *env, jobject obj, jstring label)
+{
+ /* Both QCheckbox and QRadioButton inherit QAbstractButton */
+ QAbstractButton *cb = (QAbstractButton *) getNativeObject( env, obj );
+ assert( cb );
+
+ QString *qStr = getQString(env, label);
+ mainThread->postEventToMain( new AWTLabelEvent( cb, qStr ) );
+ // AWTLabelEvent takes care of disposal of qStr
+}
+
+/*
+ * Sets the checkbox state.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtCheckboxPeer_setState
+(JNIEnv *env, jobject obj, jboolean state)
+{
+ QAbstractButton *cb = (QAbstractButton *) getNativeObject( env, obj );
+ assert( cb );
+ mainThread->postEventToMain( new CheckboxCheckEvent( cb, (state == JNI_TRUE) ) );
+}
+
diff --git a/native/jni/qt-peer/qtchoicepeer.cpp b/native/jni/qt-peer/qtchoicepeer.cpp
new file mode 100644
index 000000000..b1675bebe
--- /dev/null
+++ b/native/jni/qt-peer/qtchoicepeer.cpp
@@ -0,0 +1,142 @@
+/* qtchoicepeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QComboBox>
+#include <gnu_java_awt_peer_qt_QtChoicePeer.h>
+#include "qtcomponent.h"
+#include "qtstrings.h"
+#include "mainthreadinterface.h"
+#include "slotcallbacks.h"
+
+class InsertEvent : public AWTEvent {
+
+ private:
+ QComboBox *widget;
+ QString *string;
+ int index;
+
+ public:
+ InsertEvent(QComboBox *w, QString *s, int i) : AWTEvent()
+ {
+ widget = w;
+ string = s;
+ index = i;
+ }
+
+ void runEvent()
+ {
+ widget->insertItem( index, *string );
+ delete string;
+ }
+};
+
+class RemoveSelectEvent : public AWTEvent {
+
+ private:
+ QComboBox *widget;
+ int index;
+ bool remove;
+
+ public:
+ RemoveSelectEvent(QComboBox *w, int i, bool r) : AWTEvent()
+ {
+ widget = w;
+ index = i;
+ remove = r;
+ }
+
+ void runEvent()
+ {
+ if (remove)
+ widget->removeItem( index );
+ else
+ widget->setCurrentIndex( index );
+ }
+};
+
+
+/*
+ * Constructs tha QComboBox object
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtChoicePeer_init
+(JNIEnv *env, jobject obj)
+{
+ QWidget *parentWidget = (QWidget *)getParentWidget(env, obj);
+
+ QComboBox *box = new QComboBox( parentWidget );
+ assert( box );
+
+ setNativeObject( env, obj, box );
+
+ connectChoice(box, env, obj); // connect the fireChoice method.
+}
+
+/*
+ * Inserts a choice box item at index.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtChoicePeer_add
+(JNIEnv *env, jobject obj, jstring itemLabel, jint index)
+{
+ QComboBox *box = (QComboBox *) getNativeObject( env, obj );
+ assert( box );
+
+ QString *qStr = getQString( env, itemLabel );
+ mainThread->postEventToMain( new InsertEvent( box, qStr, index ) );
+}
+
+/*
+ * Removes a choice box item at index.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtChoicePeer_remove
+(JNIEnv *env, jobject obj, jint index)
+{
+ QComboBox *box = (QComboBox *) getNativeObject( env, obj );
+ assert( box );
+ mainThread->postEventToMain( new RemoveSelectEvent( box, index, true ) );
+}
+
+/**
+ * Selects a choice box item.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtChoicePeer_select
+(JNIEnv *env, jobject obj, jint index)
+{
+ QComboBox *box = (QComboBox *) getNativeObject( env, obj );
+ assert( box );
+ mainThread->postEventToMain( new RemoveSelectEvent( box, index, false ) );
+}
+
diff --git a/native/jni/qt-peer/qtcomponent.cpp b/native/jni/qt-peer/qtcomponent.cpp
new file mode 100644
index 000000000..d9ddd7e20
--- /dev/null
+++ b/native/jni/qt-peer/qtcomponent.cpp
@@ -0,0 +1,122 @@
+/* qtcomponent.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <jni.h>
+#include <assert.h>
+#include <qmainwindow.h>
+#include <qwidget.h>
+#include "qtcomponent.h"
+#include "containers.h"
+
+#define COMPONENT_CLASS "gnu/java/awt/peer/qt/QtComponentPeer"
+
+/*
+ * Returns the parent widget for a QtComponentPeer
+ */
+void *getParentWidget( JNIEnv *env, jobject qtcomponentpeer )
+{
+ jclass componentCls = env->FindClass( COMPONENT_CLASS );
+ jfieldID ownerField = env->GetFieldID( componentCls,
+ "owner", "Ljava/awt/Component;" );
+
+ jobject owner = env->GetObjectField( qtcomponentpeer, ownerField );
+ if (owner == NULL)
+ return NULL;
+
+ jclass ownerCls = env->GetObjectClass( owner );
+ jmethodID getParentMID = env->GetMethodID( ownerCls,
+ "getParent",
+ "()Ljava/awt/Container;" );
+ assert(getParentMID);
+
+ jobject parent = env->CallObjectMethod( owner, getParentMID, 0);
+ assert(parent);
+
+ // Get the parents peer
+ jclass parentCls = env->GetObjectClass( parent );
+ {
+ jclass frameCls = env->FindClass( "java/awt/Frame" );
+ if(env->IsInstanceOf( parent, frameCls ) == JNI_TRUE)
+ return frameChildWidget( env, parent );
+ }
+ {
+ jclass scrollpaneCls = env->FindClass( "java/awt/ScrollPane" );
+ if(env->IsInstanceOf( parent, scrollpaneCls ) == JNI_TRUE)
+ return scrollPaneChildWidget( env, parent );
+ }
+
+ jmethodID getPeerMID = env->GetMethodID( parentCls,
+ "getPeer",
+ "()Ljava/awt/peer/ComponentPeer;" );
+ assert(getPeerMID);
+ return getNativeObject(env, env->CallObjectMethod( parent, getPeerMID, 0));
+}
+
+/*
+ * Creates a java.awt.Dimension object from a QSize.
+ */
+jobject makeDimension(JNIEnv *env, QSize *size)
+{
+ if( size == NULL )
+ return NULL;
+ if( size->isNull() || !size->isValid() )
+ return NULL;
+ jclass cls = env->FindClass("java/awt/Dimension");
+ jmethodID mid = env->GetMethodID(cls, "<init>", "(II)V");
+ jvalue values[2];
+
+ values[0].i = (jint) size->width();
+ values[1].i = (jint) size->height();
+
+ return env->NewObjectA(cls, mid, values);
+}
+
+/*
+ * Creates a java.awt.Point object from a QPoint.
+ */
+jobject makePoint(JNIEnv *env, QPoint &p)
+{
+ jclass cls = env->FindClass("java/awt/Point");
+ jmethodID mid = env->GetMethodID(cls, "<init>", "(II)V");
+ jvalue values[2];
+
+ values[0].i = (jint) p.x();
+ values[1].i = (jint) p.y();
+
+ return env->NewObjectA(cls, mid, values);
+}
+
diff --git a/native/jni/qt-peer/qtcomponent.h b/native/jni/qt-peer/qtcomponent.h
new file mode 100644
index 000000000..3188f03f5
--- /dev/null
+++ b/native/jni/qt-peer/qtcomponent.h
@@ -0,0 +1,16 @@
+#ifndef QTCOMPONENT_H
+#define QTCOMPONENT_H
+
+#include <QSize>
+#include <QPoint>
+//#include <cassert.h>
+#include <jni.h>
+#include "nativewrapper.h"
+
+void *getParentWidget( JNIEnv *env, jobject qtcomponentpeer );
+
+jobject makeDimension(JNIEnv *env, QSize *size);
+
+jobject makePoint(JNIEnv *env, QPoint &p);
+
+#endif
diff --git a/native/jni/qt-peer/qtcomponentpeer.cpp b/native/jni/qt-peer/qtcomponentpeer.cpp
new file mode 100644
index 000000000..0996b6973
--- /dev/null
+++ b/native/jni/qt-peer/qtcomponentpeer.cpp
@@ -0,0 +1,391 @@
+/* qtcomponentpeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QShowEvent>
+#include <QHideEvent>
+#include <QColor>
+#include <QCursor>
+#include <QPoint>
+#include <QWidget>
+#include <gnu_java_awt_peer_qt_QtComponentPeer.h>
+#include "qtcomponent.h"
+#include "componentevent.h"
+#include "qtfont.h"
+
+extern QApplication *qApplication;
+
+// Java Cursor types.
+#define DEFAULT_CURSOR 0
+#define CROSSHAIR_CURSOR 1
+#define TEXT_CURSOR 2
+#define WAIT_CURSOR 3
+#define SW_RESIZE_CURSOR 4
+#define SE_RESIZE_CURSOR 5
+#define NW_RESIZE_CURSOR 6
+#define NE_RESIZE_CURSOR 7
+#define N_RESIZE_CURSOR 8
+#define S_RESIZE_CURSOR 9
+#define W_RESIZE_CURSOR 10
+#define E_RESIZE_CURSOR 11
+#define HAND_CURSOR 12
+#define MOVE_CURSOR 13
+
+/**
+ * Call back the init() method from the main thread.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_callInit
+(JNIEnv *env, jobject obj)
+{
+ mainThread->postEventToMain( new AWTInitEvent( env, obj ) );
+
+ // wait for the thing to be created.
+ void *p = NULL;
+ do
+ {
+ env->MonitorEnter( obj );
+ p = getNativeObject(env, obj);
+ env->MonitorExit( obj );
+ } while( p == NULL);
+}
+
+/*
+ * Generic disposal.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_disposeNative
+(JNIEnv *env, jobject obj)
+{
+ QWidget *widget = (QWidget *) getNativeObject( env, obj );
+ if( widget )
+ {
+ setNativeObject(env, obj, NULL);
+ mainThread->postEventToMain( new AWTDestroyEvent( widget ) );
+ }
+}
+
+/**
+ * Returns the on-screen location of the component.
+ */
+JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_getLocationOnScreen
+(JNIEnv *env, jobject obj)
+{
+ QWidget *widget = (QWidget *) getNativeObject( env, obj );
+ assert( widget );
+ QPoint *p = NULL;
+ mainThread->postEventToMain( new AWTGetOriginEvent( widget, &p) );
+ while (p == NULL); // wait for the thing to be retrived.
+
+ return makePoint(env, *p);
+}
+
+/*
+ * Get the minimum size
+ */
+JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_getMinimumSizeNative
+(JNIEnv *env, jobject obj)
+{
+ QWidget *widget = (QWidget *) getNativeObject( env, obj );
+ assert( widget );
+ QSize *size = NULL;
+
+ AWTGetSizeEvent *e = new AWTGetSizeEvent( widget, &size, false );
+ mainThread->postEventToMain( e );
+ while(size == NULL);
+ return makeDimension(env, size);
+
+ delete size;
+}
+
+/*
+ * Get the preferred size of the widget
+ */
+JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_getPreferredSizeNative
+
+(JNIEnv *env, jobject obj)
+{
+ QWidget *widget = (QWidget *) getNativeObject( env, obj );
+ assert( widget );
+ QSize *size = NULL;
+
+ AWTGetSizeEvent *e = new AWTGetSizeEvent( widget, &size, true );
+ mainThread->postEventToMain( e );
+ while(size == NULL);
+
+ return makeDimension(env, size);
+
+ delete size;
+}
+
+/*
+ */
+JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_isObscured
+(JNIEnv *env, jobject obj)
+{
+ jboolean retVal;
+
+ QWidget *widget = (QWidget *) getNativeObject( env, obj );
+ assert( widget );
+
+ retVal = (widget->isVisible() == TRUE) ? JNI_TRUE : JNI_FALSE;
+
+ return retVal;
+}
+
+/*
+ * Returns whether the widget is focusable or not.
+ */
+JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_isFocusable
+(JNIEnv *env, jobject obj)
+{
+ jboolean retVal;
+
+ QWidget *widget = (QWidget *) getNativeObject( env, obj );
+ assert( widget );
+
+ retVal = (widget->focusPolicy() != Qt::NoFocus) ? JNI_TRUE : JNI_FALSE;
+
+ return retVal;
+}
+
+/**
+ * Requests the focus
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_requestFocus
+ (JNIEnv *env, jobject obj)
+{
+ QWidget *widget = (QWidget *) getNativeObject( env, obj );
+ assert( widget );
+ mainThread->postEventToMain( new AWTReqFocusEvent( widget ) );
+}
+
+/*
+ * Sets the size and position. Important.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setBoundsNative
+(JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height)
+{
+ QWidget *widget = (QWidget *) getNativeObject( env, obj );
+ assert( widget );
+
+ QRect g = widget->geometry();
+ if(g.x() != x || g.y() != y ||
+ g.width() != width || g.height() != height)
+ {
+ mainThread->postEventToMain
+ (new AWTResizeEvent( widget, x, y, width, height ) );
+ }
+}
+
+/*
+ * Sets the mouse cursor
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setCursor
+ (JNIEnv *env, jobject obj, jint cursortype)
+{
+ QWidget *widget = (QWidget *) getNativeObject( env, obj );
+ assert( widget );
+
+ Qt::CursorShape shape;
+ switch(cursortype)
+ {
+ case CROSSHAIR_CURSOR:
+ shape = Qt::CrossCursor;
+ break;
+
+ case W_RESIZE_CURSOR:
+ case E_RESIZE_CURSOR:
+ shape = Qt::SizeHorCursor;
+ break;
+ case N_RESIZE_CURSOR:
+ case S_RESIZE_CURSOR:
+ shape = Qt::SizeVerCursor;
+ break;
+ case HAND_CURSOR:
+ shape = Qt::PointingHandCursor;
+ break;
+ case MOVE_CURSOR:
+ shape = Qt::SizeAllCursor;
+ break;
+
+ case NE_RESIZE_CURSOR:
+ case SW_RESIZE_CURSOR:
+ shape = Qt::SizeBDiagCursor;
+ break;
+ case NW_RESIZE_CURSOR:
+ case SE_RESIZE_CURSOR:
+ shape = Qt::SizeFDiagCursor;
+ break;
+ case TEXT_CURSOR:
+ shape = Qt::IBeamCursor;
+ break;
+ case WAIT_CURSOR:
+ shape = Qt::WaitCursor;
+ break;
+
+ case DEFAULT_CURSOR:
+ default:
+ shape = Qt::ArrowCursor;
+ break;
+ }
+
+ mainThread->postEventToMain( new AWTCursorEvent( widget, shape ) );
+}
+
+/*
+ * Enable, disable.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setEnabled
+(JNIEnv *env, jobject obj, jboolean state)
+{
+ QWidget *widget = (QWidget *) getNativeObject( env, obj );
+ assert(widget != NULL);
+
+ mainThread->postEventToMain( new AWTEnableEvent( widget, (state == JNI_TRUE) ) );
+}
+
+/**
+ * Set the font
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setFontNative
+(JNIEnv *env, jobject obj, jobject fontpeer)
+{
+ QWidget *widget = (QWidget *) getNativeObject( env, obj );
+ assert( widget );
+ QFont *font = (QFont *) getFont( env, fontpeer );
+ assert( font );
+
+ mainThread->postEventToMain( new AWTFontEvent(widget, font) );
+}
+
+/*
+ * Sets the back- or foreground color.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setGround
+(JNIEnv *env, jobject obj, jint r, jint g, jint b, jboolean isForeground)
+{
+ QColor *color = new QColor(r, g, b);
+
+ QWidget *widget = (QWidget *) getNativeObject( env, obj );
+ assert(widget);
+ mainThread->postEventToMain( new AWTBackgroundEvent(widget,
+ (isForeground == JNI_TRUE),
+ color) );
+}
+
+/*
+ * Sets the visibility.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_setVisible
+(JNIEnv *env, jobject obj, jboolean state)
+{
+ QWidget *widget = (QWidget *) getNativeObject( env, obj );
+ assert(widget != NULL);
+ mainThread->postEventToMain( new AWTShowEvent( widget, (state == JNI_TRUE) ) );
+}
+
+/*
+ * Returns whether the widget handles wheel scrolling.
+ */
+JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_handlesWheelScrolling
+(JNIEnv *env, jobject obj)
+{
+ jboolean handles = JNI_FALSE;
+
+ QWidget *cb = (QWidget *) getNativeObject( env, obj );
+ if( cb )
+ if( cb->focusPolicy() & Qt::WheelFocus )
+ handles = JNI_TRUE;
+
+ return handles;
+}
+
+/**
+ * calls qwidget::update on the compnent.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_QtUpdateArea
+(JNIEnv *env, jobject obj, jint x, jint y, jint w, jint h)
+{
+ QWidget *cb = (QWidget *) getNativeObject( env, obj );
+ if( cb )
+ mainThread->postEventToMain( new AWTUpdateEvent
+ (cb, false, x, y, w, h ) );
+}
+
+/*
+ * calls qwidget::update on the compnent.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_QtUpdate
+(JNIEnv *env, jobject obj)
+{
+ QWidget *cb = (QWidget *) getNativeObject( env, obj );
+ if( cb )
+ mainThread->postEventToMain( new AWTUpdateEvent
+ ( cb, true, 0, 0, 0, 0 ) );
+}
+
+/*
+ * Returns the native background color.
+ */
+JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_getNativeBackground
+(JNIEnv *env, jobject obj)
+{
+ QWidget *cb = (QWidget *) getNativeObject( env, obj );
+ assert(cb);
+ QColor c = cb->palette().background().color().toRgb();
+
+ jclass cls = env->FindClass("java/awt/Color");
+ jmethodID mid = env->GetMethodID(cls, "<init>", "(III)V");
+ jvalue values[3];
+
+ values[0].i = (jint) c.red();
+ values[1].i = (jint) c.green();
+ values[2].i = (jint) c.blue();
+
+ return env->NewObjectA(cls, mid, values);
+}
+
+/*
+ * Returns which screen the component is on.
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_whichScreen
+(JNIEnv *env, jobject obj)
+{
+ QWidget *widget = (QWidget *) getNativeObject( env, obj );
+ assert( widget );
+ return (jint) qApplication->desktop()->screenNumber( widget );
+}
diff --git a/native/jni/qt-peer/qtdialogpeer.cpp b/native/jni/qt-peer/qtdialogpeer.cpp
new file mode 100644
index 000000000..bc7157b15
--- /dev/null
+++ b/native/jni/qt-peer/qtdialogpeer.cpp
@@ -0,0 +1,163 @@
+/* qtdialogpeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <qdialog.h>
+#include <gnu_java_awt_peer_qt_QtDialogPeer.h>
+#include "qtcomponent.h"
+#include "containers.h"
+#include "qtstrings.h"
+#include "keybindings.h"
+#include "mainthreadinterface.h"
+
+class MyDialog : public QDialog
+{
+public:
+ MyDialog(JNIEnv *env, jobject obj, QWidget *parent) : QDialog(parent)
+ {
+ setup(env, obj);
+ }
+
+ ~MyDialog()
+ {
+ destroy();
+ }
+
+#define I_KNOW_WHAT_IM_DOING
+#define PARENT QDialog
+#include "eventmethods.cpp"
+};
+
+class DialogSettingsEvent : public AWTEvent {
+
+ private:
+ QDialog *widget;
+ bool modal;
+ bool value;
+
+ public:
+ DialogSettingsEvent(QDialog *w, bool m, bool v) : AWTEvent()
+ {
+ widget = w;
+ modal = m;
+ value = v;
+ }
+
+ void runEvent()
+ {
+ if( modal )
+ widget->setModal( value );
+ else
+ widget->setSizeGripEnabled( value );
+ }
+};
+
+class DialogResizeEvent : public AWTEvent {
+
+ private:
+ QWidget *widget;
+ bool fixed;
+ int x, y, w, h;
+
+ public:
+ DialogResizeEvent(QWidget *wid, int x0, int y0, int w0, int h0, bool f)
+ {
+ widget = wid;
+ fixed = f;
+ x = x0; y = y0;
+ w = w0; h = h0;
+ if(w == 0 && h == 0) w = h = 10;
+ }
+
+ void runEvent()
+ {
+ if( fixed )
+ widget->setFixedSize( w, h );
+ widget->setGeometry( x, y, w, h );
+ }
+};
+
+/*
+ * Constructs a QDialog native object.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtDialogPeer_init
+(JNIEnv *env, jobject obj)
+{
+ QWidget *parentWidget = (QWidget *) getParentWidget( env, obj );
+ // QDialog *dialog = new QDialog(parentWidget);
+ MyDialog *dialog = new MyDialog(env, obj, parentWidget);
+ assert( dialog );
+ setNativeObject( env, obj, dialog );
+}
+
+
+/*
+ * Sets the modality of the dialog.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtDialogPeer_setModal
+(JNIEnv *env, jobject obj, jboolean flag)
+{
+ QDialog *dialog = (QDialog *) getNativeObject( env, obj );
+ assert( dialog );
+ mainThread->postEventToMain( new DialogSettingsEvent(dialog, true, (flag == JNI_TRUE)));
+}
+
+
+/*
+ * Set resizeable.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtDialogPeer_setResizable
+(JNIEnv *env, jobject obj, jboolean flag)
+{
+ QDialog *dialog = (QDialog *) getNativeObject( env, obj );
+ assert( dialog );
+ mainThread->postEventToMain( new DialogSettingsEvent(dialog, false, (flag == JNI_TRUE)));
+}
+
+/*
+ * Overloaded to allow for size locking.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtDialogPeer_setBoundsNative
+(JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height, jboolean fixed)
+{
+ QWidget *widget = (QWidget *) getNativeObject( env, obj );
+ assert( widget );
+
+ QRect g = widget->geometry();
+ if(g.x() != x || g.y() != y ||
+ g.width() != width || g.height() != height)
+ mainThread->postEventToMain( new DialogResizeEvent( widget, x, y, width, height, (fixed == JNI_TRUE) ) );
+}
diff --git a/native/jni/qt-peer/qtfiledialogpeer.cpp b/native/jni/qt-peer/qtfiledialogpeer.cpp
new file mode 100644
index 000000000..dbcf6cfdf
--- /dev/null
+++ b/native/jni/qt-peer/qtfiledialogpeer.cpp
@@ -0,0 +1,100 @@
+/* qtfiledialogpeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QFileDialog>
+#include <QDialog>
+#include <gnu_java_awt_peer_qt_QtFileDialogPeer.h>
+#include "qtcomponent.h"
+#include "qtstrings.h"
+#include "mainthreadinterface.h"
+
+// Constants from FileDialog
+#define LOAD 0
+#define SAVE 1
+
+class FileDialogMode : public AWTEvent {
+
+ private:
+ QFileDialog *widget;
+ bool open;
+
+ public:
+ FileDialogMode(QFileDialog *w, bool o) : AWTEvent()
+ {
+ widget = w;
+ open = o;
+ }
+
+ void runEvent()
+ {
+ if( open )
+ {
+ widget->setAcceptMode( QFileDialog::AcceptOpen );
+ widget->setFileMode( QFileDialog::ExistingFile );
+ }
+ else
+ {
+ widget->setAcceptMode( QFileDialog::AcceptSave );
+ widget->setFileMode( QFileDialog::AnyFile );
+ }
+ }
+};
+
+
+/*
+ * Constructs a QDialog native object.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFileDialogPeer_init
+(JNIEnv *env, jobject obj)
+{
+ QWidget *parentWidget = (QWidget *) getParentWidget( env, obj );
+ QFileDialog *dialog = new QFileDialog(parentWidget);
+ assert( dialog );
+ setNativeObject( env, obj, dialog );
+}
+
+/**
+ * Sets the mode (LOAD or SAVE)
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFileDialogPeer_setMode
+(JNIEnv *env, jobject obj, jint mode)
+{
+ QFileDialog *filedialog = (QFileDialog *) getNativeObject( env, obj );
+ assert( filedialog );
+
+ mainThread->postEventToMain( new FileDialogMode( filedialog, (mode != SAVE) ) );
+}
diff --git a/native/jni/qt-peer/qtfont.h b/native/jni/qt-peer/qtfont.h
new file mode 100644
index 000000000..d13b8e098
--- /dev/null
+++ b/native/jni/qt-peer/qtfont.h
@@ -0,0 +1,8 @@
+#ifndef QTFONT_H
+#define QTFONT_H
+
+#include <jni.h>
+
+QFont *getFont( JNIEnv *env, jobject obj );
+
+#endif
diff --git a/native/jni/qt-peer/qtfontmetrics.cpp b/native/jni/qt-peer/qtfontmetrics.cpp
new file mode 100644
index 000000000..b95c0e111
--- /dev/null
+++ b/native/jni/qt-peer/qtfontmetrics.cpp
@@ -0,0 +1,232 @@
+/* qtfontmetrics.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QChar>
+#include <QFont>
+#include <QFontMetrics>
+#include <QString>
+#include <QPainter>
+#include <QStringList>
+#include <QFontDatabase>
+#include <gnu_java_awt_peer_qt_QtFontMetrics.h>
+#include "qtfont.h"
+#include "qtstrings.h"
+#include "qtgraphics.h"
+
+QFontMetrics *getFontMetrics( JNIEnv *env, jobject obj )
+{
+ jclass cls = env->GetObjectClass( obj );
+ jfieldID field = env->GetFieldID( cls, "nativeObject", "J" );
+ return (QFontMetrics *)env->GetLongField( obj, field );
+}
+
+static void setNativePtr( JNIEnv *env, jobject obj, void *value )
+{
+ jlong longValue = (jlong) value;
+ jclass cls = env->GetObjectClass( obj );
+ jfieldID field = env->GetFieldID( cls, "nativeObject", "J" );
+ env->SetLongField( obj, field, longValue );
+}
+
+static jobject makeRectangle(JNIEnv *env, QRect *rect)
+{
+ if( rect == NULL )
+ return NULL;
+ if( rect->isNull() || !rect->isValid() )
+ return NULL;
+ jclass cls = env->FindClass("java/awt/Rectangle");
+ jmethodID mid = env->GetMethodID(cls, "<init>", "(IIII)V");
+ jvalue values[4];
+
+ int x,y,w,h;
+ rect->getRect(&x, &y, &w, &h);
+ values[0].i = (jint) x;
+ values[1].i = (jint) y;
+ values[2].i = (jint) w;
+ values[3].i = (jint) h;
+
+ return env->NewObjectA(cls, mid, values);
+}
+
+/*
+ * Create font metrics from a font.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_init
+(JNIEnv *env, jobject obj, jobject fontPeer)
+{
+ QFont *f = getFont(env, fontPeer);
+ assert( f );
+ QFontMetrics *fm = new QFontMetrics( *f );
+ assert( fm );
+ setNativePtr( env, obj, fm );
+}
+
+/*
+ * Create font metrics from a font.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_initGraphics
+(JNIEnv *env, jobject obj, jobject fontPeer, jobject graphics)
+{
+ QFont *f = getFont(env, fontPeer);
+ assert( f );
+ QPainter *painter = getPainter( env, graphics );
+ assert( painter );
+ QFontMetrics *fm = new QFontMetrics( *f , painter->device());
+ assert( fm );
+ setNativePtr( env, obj, fm );
+}
+
+/*
+ * Dispose
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_dispose
+(JNIEnv *env, jobject obj)
+{
+ QFontMetrics *fm = getFontMetrics( env, obj );
+ if ( fm )
+ delete fm;
+ setNativePtr( env, obj, NULL );
+}
+
+/*
+ * Returns JNI_TRUE if a character is displayable.
+ */
+JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_canDisplay
+(JNIEnv *env, jobject obj, jchar c)
+{
+ QFontMetrics *fm = getFontMetrics( env, obj );
+ assert( fm );
+ bool result = fm->inFont( QChar( (unsigned short)c ) );
+ return (result ? JNI_TRUE : JNI_FALSE);
+}
+
+/*
+ * Returns the ascent.
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_getAscent
+(JNIEnv *env, jobject obj)
+{
+ QFontMetrics *fm = getFontMetrics( env, obj );
+ assert( fm );
+ return fm->ascent();
+}
+
+/*
+ * Returns the descent
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_getDescent
+(JNIEnv *env, jobject obj)
+{
+ QFontMetrics *fm = getFontMetrics( env, obj );
+ assert( fm );
+ return fm->descent();
+}
+
+/*
+ * Returns the height.
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_getHeight
+(JNIEnv *env, jobject obj)
+{
+ QFontMetrics *fm = getFontMetrics( env, obj );
+ assert( fm );
+ return fm->height();
+}
+
+/*
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_getLeading
+(JNIEnv *env, jobject obj)
+{
+ QFontMetrics *fm = getFontMetrics( env, obj );
+ assert( fm );
+ return fm->leading();
+}
+
+/*
+ * getStringBounds
+ */
+JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_getStringBounds
+(JNIEnv *env, jobject obj, jstring str)
+{
+ QFontMetrics *fm = getFontMetrics( env, obj );
+ assert( fm );
+ QString *qStr = getQString(env, str);
+ QRect r = fm->boundingRect( *qStr );
+ delete qStr;
+
+ return makeRectangle( env, &r );
+}
+
+/*
+ * Returns the width of the widest character.
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_getMaxAdvance
+(JNIEnv *env, jobject obj)
+{
+ QFontMetrics *fm = getFontMetrics( env, obj );
+ assert( fm );
+ return fm->maxWidth();
+}
+
+/*
+ * Returns the width of a given character.
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_charWidth
+(JNIEnv *env, jobject obj, jchar c)
+{
+ QFontMetrics *fm = getFontMetrics( env, obj );
+ assert( fm );
+ return fm->width( QChar( (unsigned short)c ) );
+}
+
+/*
+ * Returns the width of a string.
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtFontMetrics_stringWidth
+(JNIEnv *env, jobject obj, jstring str)
+{
+ QFontMetrics *fm = getFontMetrics( env, obj );
+ assert( fm );
+ QString *qStr = getQString(env, str);
+ int width = fm->width( *qStr );
+ delete qStr;
+ return width;
+}
+
+
+
diff --git a/native/jni/qt-peer/qtfontpeer.cpp b/native/jni/qt-peer/qtfontpeer.cpp
new file mode 100644
index 000000000..dbf27d0fc
--- /dev/null
+++ b/native/jni/qt-peer/qtfontpeer.cpp
@@ -0,0 +1,91 @@
+/* qtfontpeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QFont>
+#include <QString>
+#include <gnu_java_awt_peer_qt_QtFontPeer.h>
+#include "qtfont.h"
+#include "qtstrings.h"
+
+// java.awt.Font constants
+#define PLAIN 0
+#define BOLD 1
+#define ITALIC 2
+
+QFont *getFont( JNIEnv *env, jobject obj )
+{
+ jclass cls = env->GetObjectClass( obj );
+ jfieldID field = env->GetFieldID( cls, "nativeObject", "J" );
+ return (QFont *)env->GetLongField( obj, field );
+}
+
+static void setNativePtr( JNIEnv *env, jobject obj, void *value )
+{
+ jlong longValue = (jlong) value;
+ jclass cls = env->GetObjectClass( obj );
+ jfieldID field = env->GetFieldID( cls, "nativeObject", "J" );
+ env->SetLongField( obj, field, longValue );
+}
+
+/*
+ * Creates a font.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFontPeer_create
+(JNIEnv *env, jobject obj, jstring name, jint style, jint size)
+{
+ QString *str = getQString(env, name);
+ QFont *font = NULL;
+ font = new QFont( *str, size,
+ ((style & BOLD) != 0) ? QFont::Bold : QFont::Normal,
+ ((style & ITALIC) != 0) );
+ assert( font );
+ delete str;
+ setNativePtr( env, obj, font );
+}
+
+/*
+ * Destroys a font.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFontPeer_dispose
+(JNIEnv *env, jobject obj)
+{
+ QFont *font = getFont( env, obj );
+ if( font )
+ delete font;
+ setNativePtr( env, obj, NULL );
+}
+
diff --git a/native/jni/qt-peer/qtframepeer.cpp b/native/jni/qt-peer/qtframepeer.cpp
new file mode 100644
index 000000000..b2c763943
--- /dev/null
+++ b/native/jni/qt-peer/qtframepeer.cpp
@@ -0,0 +1,202 @@
+/* qtframepeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QApplication>
+#include <QMainWindow>
+#include <QMenuBar>
+#include <QToolBar>
+#include <QThread>
+#include <gnu_java_awt_peer_qt_QtFramePeer.h>
+#include "qtcomponent.h"
+#include "qtstrings.h"
+#include "containers.h"
+#include "keybindings.h"
+#include "mainthreadinterface.h"
+
+#define MenuSizeDefault 5
+
+/*
+ * Our QMainWindow subclass
+ */
+class MyWindow : public QMainWindow
+{
+public:
+ MyWindow(JNIEnv *env, jobject obj) : QMainWindow(0, Qt::Window )
+ {
+ setup(env, obj);
+ }
+
+ ~MyWindow()
+ {
+ destroy();
+ }
+
+#define I_KNOW_WHAT_IM_DOING
+#define PARENT QMainWindow
+#include "eventmethods.cpp"
+};
+
+/**
+ * Event wrapper for adding a menu bar to the frame
+ * if the QMenuBar pointer is NULL, the current menu bar is removed.
+ */
+class FrameMenuEvent : public AWTEvent {
+
+ private:
+ QMainWindow *widget;
+ QMenuBar *menu;
+
+ public:
+ FrameMenuEvent(QMainWindow *w, QMenuBar *mb) : AWTEvent()
+ {
+ widget = w;
+ menu = mb;
+ }
+
+ void runEvent()
+ {
+ if( menu != NULL)
+ widget->setMenuBar( menu );
+ else
+ delete widget->menuBar();
+ }
+};
+
+/**
+ * Event wrapper for getting the menu bar height
+ */
+class FrameGetMenuHeightEvent : public AWTEvent {
+
+private:
+ QMainWindow *frame;
+ int *value;
+
+public:
+ FrameGetMenuHeightEvent(QMainWindow *w, int *v) : AWTEvent()
+ {
+ frame = w;
+ value = v;
+ }
+
+ void runEvent()
+ {
+ QMenuBar *mb = frame->menuBar();
+ assert( mb );
+ int v;
+ if( mb->isVisible() )
+ v = mb->size().height();
+
+ if(v <= 0 || v >= 0xFFFFF ) // Work around for strange values.
+ v = MenuSizeDefault;
+
+ *value = v;
+ }
+};
+
+/**
+ * Returns the child widget for the frame (the centralWidget in qt terms)
+ */
+QWidget *frameChildWidget( JNIEnv *env, jobject component )
+{
+ jclass frameCls = env->FindClass( "java/awt/Frame" );
+ assert( frameCls );
+ jmethodID getPeerMID = env->GetMethodID( frameCls,
+ "getPeer",
+ "()Ljava/awt/peer/ComponentPeer;" );
+ assert(getPeerMID);
+ jobject framepeerobj = env->CallObjectMethod( component, getPeerMID, 0);
+
+ QMainWindow *window = (QMainWindow *)getNativeObject(env, framepeerobj);
+
+ return window->centralWidget();
+}
+
+/*
+ * Constructs a QMainWindow native object.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFramePeer_init
+(JNIEnv *env, jobject obj)
+{
+ MyWindow *frame = new MyWindow(env, obj);
+ assert( frame );
+
+ QWidget *central = new QWidget( frame );
+ assert( central );
+
+ frame->setCentralWidget( central );
+ setNativeObject( env, obj, frame );
+}
+
+/**
+ * Returns the menu bar height for insets.
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtFramePeer_menuBarHeight
+(JNIEnv *env, jobject obj)
+{
+ QMainWindow *frame = (QMainWindow *) getNativeObject( env, obj );
+ assert( frame );
+
+ int value = 0;
+ mainThread->postEventToMain( new FrameGetMenuHeightEvent( frame, &value ) );
+
+ while(value == 0); // (Busy) wait for the value to
+ // get set by the main thread.
+
+ return (jint)value;
+}
+
+/*
+ * set Menu bar.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFramePeer_setMenu
+(JNIEnv *env, jobject obj, jobject mbPeer)
+{
+ QMainWindow *frame = (QMainWindow *) getNativeObject( env, obj );
+ assert( frame );
+
+ QMenuBar *menubar = NULL;
+
+ if( mbPeer != NULL )
+ {
+ menubar = (QMenuBar *) getNativeObject( env, mbPeer );
+ assert( menubar );
+ }
+
+ mainThread->postEventToMain( new FrameMenuEvent( frame, menubar ) );
+}
+
+
diff --git a/native/jni/qt-peer/qtgraphics.cpp b/native/jni/qt-peer/qtgraphics.cpp
new file mode 100644
index 000000000..f149c32ec
--- /dev/null
+++ b/native/jni/qt-peer/qtgraphics.cpp
@@ -0,0 +1,471 @@
+/* qtgraphics.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <jni.h>
+#include <QPainter>
+#include <QBrush>
+#include <QLinearGradient>
+#include <QPen>
+#include <QPaintDevice>
+#include <QPainterPath>
+#include <QImage>
+#include <QColor>
+#include <gnu_java_awt_peer_qt_QtGraphics.h>
+#include "nativewrapper.h"
+#include "qtimage.h"
+#include "qtstrings.h"
+#include "qtcomponent.h"
+#include "qtgraphics.h"
+#include "qtfont.h"
+
+// Constants from java.awt.AlphaComposite
+#define CLEAR 1
+#define SRC 2
+#define DST 9
+#define SRC_OVER 3
+#define DST_OVER 4
+#define SRC_IN 5
+#define DST_IN 6
+#define SRC_OUT 7
+#define DST_OUT 8
+#define SRC_ATOP 10
+#define DST_ATOP 11
+#define XOR 12
+
+GraphicsPainter *getPainter( JNIEnv *env, jobject obj )
+{
+ jclass cls = env->GetObjectClass( obj );
+ jfieldID field = env->GetFieldID( cls, "nativeObject", "J" );
+ return (GraphicsPainter *)env->GetLongField( obj, field );
+}
+
+static void setNativePtr( JNIEnv *env, jobject obj, void *value )
+{
+ jlong longValue = (jlong) value;
+ jclass cls = env->GetObjectClass( obj );
+ jfieldID field = env->GetFieldID( cls, "nativeObject", "J" );
+ env->SetLongField( obj, field, longValue );
+}
+
+static jobject getToolkit( JNIEnv *env, jobject obj )
+{
+ jclass cls = env->FindClass( "gnu/java/awt/peer/qt/QtGraphics" );
+
+ jfieldID field = env->GetFieldID( cls, "toolkit",
+ "Lgnu/java/awt/peer/qt/QtToolkit;" );
+ return env->GetObjectField( obj, field );
+}
+
+///////////////////////// JNI methods ////////////////////////////////
+
+/**
+ * Clones the parent QPainter object.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_cloneNativeContext
+(JNIEnv *env, jobject obj, jobject parent)
+{
+ GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, parent );
+ assert( painter );
+ QPainter *newPainter = new GraphicsPainter( painter->device() );
+ assert( newPainter );
+ setNativePtr(env, obj, newPainter);
+}
+
+/*
+ * Start of JNI methods
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_initImage
+(JNIEnv *env, jobject obj, jobject image)
+{
+ QImage *im = getQtImage( env, image );
+ QPainter *painter = new GraphicsPainter( im );
+ assert( painter );
+ setNativePtr(env, obj, painter);
+ painter->setRenderHint(QPainter::TextAntialiasing);
+}
+
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_delete
+(JNIEnv *env, jobject obj)
+{
+ GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, obj );
+ setNativePtr( env, obj, NULL );
+ if( painter )
+ {
+ if( painter->isActive() )
+ painter->end();
+ delete painter;
+ }
+}
+
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_dispose
+(JNIEnv *env, jobject obj)
+{
+// GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, obj );
+// setNativePtr( env, obj, NULL );
+// if( painter )
+// {
+// if( painter->isActive() )
+// painter->end();
+// delete painter;
+// }
+}
+
+///////////////////////////////////////////////////////////
+/*
+ * Sets the clip to a path.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setClipNative
+(JNIEnv *env, jobject obj, jobject path)
+{
+ QPainter *painter = getPainter( env, obj );
+ assert( painter );
+ QPainterPath *pp = (QPainterPath *)getNativeObject( env, path );
+ assert( pp );
+ painter->setClipPath( *pp );
+}
+
+/*
+ * Sets the clip to a rectangle.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setClipRectNative
+(JNIEnv *env, jobject obj, jint x, jint y, jint w, jint h)
+{
+ QPainter *painter = getPainter( env, obj );
+ assert( painter );
+ painter->setClipRect( x, y, w, h );
+}
+
+/*
+ * Intersects a shape with the current clip.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_intersectClipNative
+(JNIEnv *env, jobject obj, jobject path)
+{
+ QPainter *painter = getPainter( env, obj );
+ assert( painter );
+ QPainterPath *pp = (QPainterPath *)getNativeObject( env, path );
+ assert( pp );
+ painter->setClipPath( *pp, Qt::IntersectClip );
+}
+
+/*
+ * Intersect a rectangle with the current clip.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_intersectClipRectNative
+(JNIEnv *env, jobject obj, jint x, jint y, jint w, jint h)
+{
+ QPainter *painter = getPainter( env, obj );
+ assert( painter );
+ painter->setClipRect( x, y, w, h, Qt::IntersectClip );
+}
+
+/*
+ * Returns a QPainterPath object with the clip path of this painter.
+ */
+JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_getClipNative
+(JNIEnv *env, jobject obj)
+{
+ QPainter *painter = getPainter( env, obj );
+ assert( painter );
+ jclass cls = env->FindClass("gnu/java/awt/peer/qt/QPainterPath");
+ jmethodID method = env->GetMethodID(cls, "<init>", "()V");
+
+ jobject ppo = env->NewObject(cls, method);
+ QPainterPath qpp = painter->clipPath();
+ setNativeObject(env, ppo, &qpp);
+
+ env->DeleteLocalRef( cls );
+ return ppo;
+}
+
+/*
+ * Returns a Rectangle with the bounds of this painters clip path.
+ */
+JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_getClipBounds
+(JNIEnv *env, jobject obj)
+{
+ QPainter *painter = getPainter( env, obj );
+ assert( painter );
+
+ qreal x, y, w, h;
+ painter->clipPath().boundingRect().getRect(&x, &y, &w, &h);
+
+ jclass cls = env->FindClass("java/awt/Rectangle");
+ assert( cls != NULL);
+ jmethodID mid = env->GetMethodID(cls, "<init>", "(IIII)V");
+ assert( mid != NULL);
+ jvalue values[4];
+
+ values[0].i = (jint) x;
+ values[1].i = (jint) y;
+ values[2].i = (jint) w;
+ values[3].i = (jint) h;
+
+ return env->NewObjectA(cls, mid, values);
+}
+
+///////////////////////// Color stuff ////////////////////////
+/**
+ *
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setColor
+(JNIEnv *env, jobject obj, jint r, jint g, jint b, jint alpha)
+{
+ GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, obj );
+ assert( painter );
+ painter->currentPen->setColor( QColor(r, g, b, alpha) );
+ painter->setPen( *painter->currentPen );
+ painter->currentBrush = new QBrush( QColor(r, g, b, alpha) );
+ painter->setBrush( *painter->currentBrush );
+ painter->currentColor = new QColor(r, g, b, alpha);
+}
+
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setAlphaNative
+ (JNIEnv *env, jobject obj, jdouble alpha)
+{
+ GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, obj );
+ assert( painter );
+
+ QColor c = painter->currentPen->color();
+ c.setAlphaF( (qreal)alpha );
+ painter->currentPen->setColor(c);
+
+ c = painter->currentBrush->color();
+ c.setAlphaF( (qreal)alpha );
+ painter->currentBrush->setColor( c );
+}
+
+/*
+ * Class: gnu_java_awt_peer_qt_QtGraphics
+ * Method: drawNative
+ * Signature: (Lgnu/java/awt/peer/qt/QPainterPath;)V
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_drawNative
+(JNIEnv *env, jobject obj, jobject path)
+{
+ GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, obj );
+ assert( painter );
+ QPainterPath *pp = (QPainterPath *)getNativeObject( env, path );
+ assert( pp );
+ painter->setPen( *painter->currentPen );
+ painter->setBrush( Qt::NoBrush );
+ painter->drawPath( *pp );
+}
+
+/*
+ * Class: gnu_java_awt_peer_qt_QtGraphics
+ * Method: fillNative
+ * Signature: (Lgnu/java/awt/peer/qt/QPainterPath;)V
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_fillNative
+(JNIEnv *env, jobject obj, jobject path)
+{
+ GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, obj );
+ assert( painter );
+ QPainterPath *pp = (QPainterPath *)getNativeObject( env, path );
+ assert( pp );
+
+ painter->setPen(Qt::NoPen);
+ painter->setBrush( *painter->currentBrush );
+ painter->drawPath( *pp );
+}
+
+/**
+ * Draws a string.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_drawStringNative
+(JNIEnv *env, jobject obj, jstring str, jdouble x, jdouble y)
+{
+ GraphicsPainter *painter = getPainter( env, obj );
+ assert( painter );
+ QString *qStr = getQString(env, str);
+ painter->setBrush( Qt::NoBrush );
+ painter->setPen( *painter->currentPen );
+ painter->drawText(QPointF( (qreal)x, (qreal)y ), *qStr);
+ delete qStr;
+}
+
+/*
+ * Sets the native stroke
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setNativeStroke
+(JNIEnv *env, jobject obj, jobject stroke)
+{
+ GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, obj );
+ assert( painter );
+ QPen *pen = (QPen *)getNativeObject(env, stroke);
+ assert( pen );
+ painter->currentPen = new QPen( *pen );
+ painter->setPen( *painter->currentPen );
+}
+
+/*
+ * Sets the transform
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setQtTransform
+(JNIEnv *env, jobject obj, jobject matrix)
+{
+ QPainter *painter = getPainter( env, obj );
+ assert( painter );
+ QMatrix *m = (QMatrix *)getNativeObject( env, matrix );
+ assert( m );
+ painter->setMatrix( *m );
+}
+
+/**
+ * Set the font
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setFontNative
+(JNIEnv *env, jobject obj, jobject fontpeer)
+{
+ QPainter *painter = getPainter( env, obj );
+ assert( painter );
+ QFont *font = (QFont *) getFont( env, fontpeer );
+ assert( font );
+ painter->setFont( *font );
+}
+
+/*
+ * Sets Porter-Duff compositing.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setNativeComposite
+(JNIEnv *env, jobject obj, jint compositeMode)
+{
+ QPainter *painter = getPainter( env, obj );
+ assert( painter );
+ QPainter::CompositionMode mode;
+
+ switch( compositeMode )
+ {
+ case CLEAR:
+ mode = QPainter::CompositionMode_Clear;
+ break;
+ case SRC:
+ mode = QPainter::CompositionMode_Source;
+ break;
+ case DST:
+ mode = QPainter::CompositionMode_Destination;
+ break;
+ case SRC_OVER:
+ mode = QPainter::CompositionMode_SourceOver;
+ break;
+ case DST_OVER:
+ mode = QPainter::CompositionMode_DestinationOver;
+ break;
+ case SRC_IN:
+ mode = QPainter::CompositionMode_SourceIn;
+ break;
+ case DST_IN:
+ mode = QPainter::CompositionMode_DestinationIn;
+ break;
+ case SRC_OUT:
+ mode = QPainter::CompositionMode_SourceOut;
+ break;
+ case DST_OUT:
+ mode = QPainter::CompositionMode_DestinationOut;
+ break;
+ case SRC_ATOP:
+ mode = QPainter::CompositionMode_SourceAtop;
+ break;
+ case DST_ATOP:
+ mode = QPainter::CompositionMode_DestinationAtop;
+ break;
+ case XOR:
+ mode = QPainter::CompositionMode_Xor;
+ break;
+ }
+ painter->setCompositionMode( mode );
+}
+
+JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_getFontMetrics
+(JNIEnv *env, jobject obj, jobject font)
+{
+}
+
+/**
+ * Sets the current brush to a linear gradient.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setLinearGradient
+(JNIEnv *env, jobject obj, jint r1, jint g1, jint b1, jint r2, jint g2,
+jint b2, jdouble x1, jdouble y1, jdouble x2, jdouble y2, jboolean cyclic)
+{
+ GraphicsPainter *painter = getPainter( env, obj );
+ assert( painter );
+ QLinearGradient *lg = new QLinearGradient(QPointF( (qreal)x1, (qreal)y1 ),
+ QPointF( (qreal)x2, (qreal)y2 ) );
+ lg->setColorAt( (qreal)0.0, QColor(r1, g1, b1) );
+ lg->setColorAt( (qreal)1.0, QColor(r2, g2, b2) );
+ if( cyclic == JNI_TRUE )
+ lg->setSpread( QGradient::ReflectSpread );
+ else
+ lg->setSpread( QGradient::PadSpread );
+ painter->currentBrush = new QBrush( *lg );
+ delete lg;
+}
+
+/*
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_fill3DRect
+(JNIEnv *env, jobject obj, jint x, jint y, jint w, jint h, jboolean raised)
+{
+ GraphicsPainter *painter = getPainter( env, obj );
+ assert( painter );
+ // FIXME: Adjust colors
+ painter->fillRect ( x, y, w, h, QBrush( *painter->currentColor) );
+ QPen *p = new QPen( *painter->currentColor );
+ p->setWidth( 1 );
+ painter->setPen( *p );
+ painter->drawLine( x + w, y, x + w, y + h);
+ painter->drawLine( x, y + h, x + w, y + h);
+}
+
+/*
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_draw3DRect
+(JNIEnv *env, jobject obj, jint x, jint y, jint w, jint h, jboolean raised)
+{
+ GraphicsPainter *painter = getPainter( env, obj );
+ assert( painter );
+ // FIXME: Adjust colors
+ QPen *p = new QPen( *painter->currentColor );
+ p->setWidth( 1 );
+ painter->setPen( *p );
+ painter->drawLine( x, y, x + w, y );
+ painter->drawLine( x, y, x, y + h);
+ painter->drawLine( x + w, y, x + w, y + h);
+ painter->drawLine( x, y + h, x + w, y + h);
+}
diff --git a/native/jni/qt-peer/qtgraphics.h b/native/jni/qt-peer/qtgraphics.h
new file mode 100644
index 000000000..5252897db
--- /dev/null
+++ b/native/jni/qt-peer/qtgraphics.h
@@ -0,0 +1,26 @@
+#ifndef QTGRAPHICS_H
+#define QTGRAPHICS_H
+
+#include <jni.h>
+#include <QPainter>
+#include <QPaintDevice>
+#include <QPen>
+#include <QBrush>
+
+class GraphicsPainter : public QPainter
+{
+public:
+ QPen *currentPen;
+ QBrush *currentBrush;
+ QColor *currentColor;
+ GraphicsPainter(QPaintDevice *dev) : QPainter( dev )
+ {
+ currentPen = new QPen();
+ currentBrush = new QBrush();
+ currentColor = new QColor();
+ }
+};
+
+GraphicsPainter *getPainter( JNIEnv *env, jobject obj );
+
+#endif
diff --git a/native/jni/qt-peer/qtimage.cpp b/native/jni/qt-peer/qtimage.cpp
new file mode 100644
index 000000000..2a86feac9
--- /dev/null
+++ b/native/jni/qt-peer/qtimage.cpp
@@ -0,0 +1,396 @@
+/* qtimage.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QImage>
+#include <QColor>
+#include <QMatrix>
+#include <QPainter>
+#include <gnu_java_awt_peer_qt_QtImage.h>
+#include "qtimage.h"
+#include "qtstrings.h"
+#include "qtgraphics.h"
+#include "nativewrapper.h"
+
+/* The constant fields in java.awt.Image */
+#define SCALE_DEFAULT 1
+#define SCALE_FAST 2
+#define SCALE_SMOOTH 4
+#define SCALE_REPLICATE 8
+#define SCALE_AREA_AVERAGING 16
+
+QImage *getQtImage( JNIEnv *env, jobject obj )
+{
+ jclass cls = env->GetObjectClass( obj );
+ jfieldID field = env->GetFieldID( cls, "nativeObject", "J" );
+ return (QImage *)env->GetLongField( obj, field );
+}
+
+static void setNativePtr( JNIEnv *env, jobject obj, void *value )
+{
+ jlong longValue = (jlong) value;
+ jclass cls = env->GetObjectClass( obj );
+ jfieldID field = env->GetFieldID( cls, "nativeObject", "J" );
+ env->SetLongField( obj, field, longValue );
+}
+
+/*
+ * Creates a QImage.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtImage_createImage
+(JNIEnv *env, jobject obj)
+{
+ int width, height;
+ jclass cls;
+ jfieldID field;
+
+ cls = env->GetObjectClass( obj );
+ field = env->GetFieldID (cls, "width", "I");
+ assert (field != 0);
+ width = env->GetIntField(obj, field);
+
+ field = env->GetFieldID(cls, "height", "I");
+ assert (field != 0);
+ height = env->GetIntField(obj, field);
+
+ QImage *image = new QImage ( width, height,
+ QImage::Format_ARGB32_Premultiplied );
+ setNativePtr(env, obj, image);
+}
+
+/*
+ * Frees the image data.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtImage_freeImage
+(JNIEnv *env, jobject obj)
+{
+ QImage *image = getQtImage(env, obj);
+ setNativePtr(env, obj, NULL);
+ if ( image )
+ delete image;
+}
+
+/*
+ * Clears the image to zero.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtImage_clear
+(JNIEnv *env, jobject obj)
+{
+ QImage *image = getQtImage(env, obj);
+ assert( image );
+ image->fill(0);
+}
+
+/*
+ * Returns the pixel data in an int array.
+ */
+JNIEXPORT jintArray JNICALL Java_gnu_java_awt_peer_qt_QtImage_getPixels
+(JNIEnv *env, jobject obj)
+{
+ QImage *image = getQtImage(env, obj);
+ jintArray result_array;
+ jint *result_array_ptr, *dst;
+ int x, y;
+ jint pixel;
+ QRgb current;
+
+ assert( image );
+
+ result_array = env->NewIntArray (image->width() * image->height());
+ dst = result_array_ptr =
+ env->GetIntArrayElements(result_array, NULL);
+
+ // A bit inefficient.
+ for ( y = 0; y < image->height(); y++)
+ for ( x = 0; x < image->width(); x++)
+ {
+ current = image->pixel(x, y);
+ pixel = 0;
+ pixel = (qAlpha(current) & 0xFF) << 24 |
+ (qRed(current) & 0xFF) << 16 |
+ (qGreen(current) & 0xFF) << 8 |
+ (qBlue(current) & 0xFF);
+ *dst = pixel;
+ dst++;
+ }
+
+ env->ReleaseIntArrayElements (result_array, result_array_ptr, 0);
+ return result_array;
+}
+
+/*
+ * Sets the pixel data.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtImage_setPixels
+(JNIEnv *env, jobject obj, jintArray pixels)
+{
+ QImage *image = getQtImage(env, obj);
+ assert( image );
+
+ int width, height;
+ jint *src_array, *src;
+
+ width = image->width();
+ height = image->height();
+
+ src = src_array =
+ env->GetIntArrayElements(pixels, NULL);
+
+ for(int i = 0 ; i < height; i++)
+ {
+ uchar *scanline = image->scanLine( i );
+ memcpy((void *)scanline, (void *)src, width * 4);
+ src += width;
+ }
+
+ env->ReleaseIntArrayElements(pixels, src_array, 0);
+}
+
+
+/*
+ * Loads an image from a file,
+ * returns true on success, false on failure.
+ */
+JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtImage_loadImage
+(JNIEnv *env, jobject obj, jstring fn)
+{
+ QString *filename = getQString(env, fn);
+
+ QImage *image = new QImage();
+ bool retVal = image->load( *filename );
+ delete filename;
+
+ if(image->isNull() && !retVal)
+ {
+ setNativePtr(env, obj, NULL);
+ return JNI_FALSE;
+ }
+
+ setNativePtr(env, obj, image);
+
+ jclass cls = env->GetObjectClass( obj );
+ jfieldID field = env->GetFieldID( cls, "width", "I" );
+ env->SetIntField( obj, field, image->width() );
+ field = env->GetFieldID( cls, "height", "I" );
+ env->SetIntField( obj, field, image->height() );
+
+ return JNI_TRUE;
+}
+
+/*
+ * Creates the image from an array of java bytes.
+ */
+JNIEXPORT jboolean JNICALL Java_gnu_java_awt_peer_qt_QtImage_loadImageFromData
+(JNIEnv *env, jobject obj, jbyteArray data)
+{
+ jbyte *src_array, *src;
+ bool retVal;
+
+ src = env->GetByteArrayElements(data, NULL);
+ int len = env->GetArrayLength( data );
+
+ QImage *image = new QImage();
+ retVal = image->loadFromData( (uchar *) src, len);
+ env->ReleaseByteArrayElements(data, src, 0);
+
+ if(image->isNull() || retVal == false)
+ {
+ setNativePtr(env, obj, NULL);
+ return JNI_FALSE;
+ }
+
+ setNativePtr(env, obj, image);
+
+ jclass cls = env->GetObjectClass( obj );
+ jfieldID field = env->GetFieldID( cls, "width", "I" );
+ env->SetIntField( obj, field, image->width() );
+ field = env->GetFieldID( cls, "height", "I" );
+ env->SetIntField( obj, field, image->height() );
+
+ return JNI_TRUE;
+}
+
+
+/*
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtImage_createScaledImage
+(JNIEnv *env, jobject obj, jobject src, jint hints)
+{
+ int w,h;
+ jclass cls;
+ jfieldID field;
+
+ cls = env->GetObjectClass( obj );
+ field = env->GetFieldID(cls, "width", "I");
+ assert (field != 0);
+ w = env->GetIntField(obj, field);
+
+ field = env->GetFieldID(cls, "height", "I");
+ assert (field != 0);
+ h = env->GetIntField(obj, field);
+
+ QImage *image = getQtImage(env, src);
+ assert( image );
+ QImage imageScaled;
+
+ if (hints == SCALE_SMOOTH || hints == SCALE_AREA_AVERAGING)
+ imageScaled = image->scaled(w, h,
+ Qt::IgnoreAspectRatio,
+ Qt::SmoothTransformation);
+ else
+ imageScaled = image->scaled(w, h,
+ Qt::IgnoreAspectRatio,
+ Qt::FastTransformation);
+ QImage *scaledPtr = new QImage( imageScaled );
+
+ // create new QtImage object
+ setNativePtr( env, obj, scaledPtr );
+}
+
+/*
+ * Simple draw without scaling.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtImage_drawPixels
+(JNIEnv *env, jobject obj, jobject graphics, jint bg_red, jint bg_green,
+ jint bg_blue, jint x, jint y, jboolean composite)
+{
+ QImage *image = getQtImage(env, obj);
+ assert( image );
+ QPainter *painter = getPainter( env, graphics );
+ assert( painter );
+
+ if(composite == JNI_TRUE)
+ painter->fillRect ( x, y, image->width(), image->height(),
+ QColor(bg_red, bg_green, bg_blue ) );
+ painter->drawImage ( QPoint(x, y), *image );
+}
+
+/*
+ * Draw the image with scaling.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtImage_drawPixelsScaled
+(JNIEnv *env, jobject obj, jobject graphics,
+ jint bg_red, jint bg_green, jint bg_blue,
+ jint x, jint y, jint w, jint h, jboolean composite)
+{
+ QImage *image = getQtImage(env, obj);
+ assert( image );
+ QPainter *painter = getPainter( env, graphics );
+ assert( painter );
+
+ if(composite == JNI_TRUE)
+ painter->fillRect ( x, y, w, h, QColor(bg_red, bg_green, bg_blue ) );
+
+ QRectF *srcRect = new QRectF((qreal)0, (qreal)0,
+ (qreal)image->width(), (qreal)image->height());
+ QRectF *dstRect = new QRectF((qreal)x, (qreal)y,
+ (qreal)w, (qreal)h);
+
+ if(composite == JNI_TRUE)
+ painter->fillRect( *dstRect, QColor(bg_red, bg_green, bg_blue ) );
+
+ painter->drawImage( *dstRect, *image, *srcRect);
+
+ delete srcRect;
+ delete dstRect;
+}
+
+/*
+ * Draws a transformed image.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtImage_drawPixelsTransformed
+(JNIEnv *env, jobject obj, jobject graphics, jobject transform)
+{
+ QImage *originalImage = getQtImage(env, obj);
+ assert( originalImage );
+ QPainter *painter = getPainter( env, graphics );
+ assert( painter );
+ QMatrix *matrix = (QMatrix *)getNativeObject(env, transform);
+ assert( matrix );
+
+ // FIXME : Add rendering hint support here.
+ QPoint p = matrix->map( QPoint(0,0) );
+ QImage image = originalImage->transformed ( *matrix, Qt::FastTransformation );
+ painter->drawImage(p, image);
+}
+
+/**
+ * Draws the pixbuf at x, y, scaled to width and height and
+ * optionally composited and/or flipped with a given background color.
+ */
+JNIEXPORT void JNICALL
+Java_gnu_java_awt_peer_qt_QtImage_drawPixelsScaledFlipped
+(JNIEnv *env, jobject obj, jobject graphics,
+ jint bg_red, jint bg_green, jint bg_blue,
+ jboolean flipx, jboolean flipy,
+ jint srcx, jint srcy, jint srcwidth, jint srcheight,
+ jint dstx, jint dsty, jint dstwidth, jint dstheight,
+ jboolean composite)
+{
+ QImage *originalImage = getQtImage(env, obj);
+ assert( originalImage );
+ QPainter *painter = getPainter( env, graphics );
+ assert( painter );
+
+ QRectF *srcRect = new QRectF((qreal)srcx, (qreal)srcy,
+ (qreal)srcwidth, (qreal)srcheight);
+ QRectF *dstRect = new QRectF((qreal)dstx, (qreal)dsty,
+ (qreal)dstwidth, (qreal)dstheight);
+
+ QImage image = originalImage->mirrored ( (flipx == JNI_TRUE),
+ (flipy == JNI_TRUE) );
+ if(composite == JNI_TRUE)
+ painter->fillRect( *dstRect, QColor(bg_red, bg_green, bg_blue ) );
+
+ painter->drawImage( *dstRect, image, *srcRect);
+
+ delete srcRect;
+ delete dstRect;
+}
+
+/**
+ * Copies an area of the image (used by Graphics)
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtImage_copyArea
+(JNIEnv *env, jobject obj , jint x, jint y, jint w, jint h, jint dx, jint dy)
+{
+ QImage *image = getQtImage(env, obj);
+ assert( image );
+ QImage area = image->copy(x, y, w, h);
+ QPainter *p = new QPainter( image );
+ p->drawImage( x + dx, y + dy, area );
+ delete p;
+}
diff --git a/native/jni/qt-peer/qtimage.h b/native/jni/qt-peer/qtimage.h
new file mode 100644
index 000000000..2aeb34207
--- /dev/null
+++ b/native/jni/qt-peer/qtimage.h
@@ -0,0 +1,8 @@
+#ifndef QTIMAGE_H
+#define QTIMAGE_H
+
+#include <QImage>
+
+QImage *getQtImage( JNIEnv *env, jobject obj );
+
+#endif
diff --git a/native/jni/qt-peer/qtlabelpeer.cpp b/native/jni/qt-peer/qtlabelpeer.cpp
new file mode 100644
index 000000000..1ff376a04
--- /dev/null
+++ b/native/jni/qt-peer/qtlabelpeer.cpp
@@ -0,0 +1,152 @@
+/* qtlabelpeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QLabel>
+#include <QString>
+#include <gnu_java_awt_peer_qt_QtLabelPeer.h>
+#include "qtcomponent.h"
+#include "qtstrings.h"
+#include "mainthreadinterface.h"
+#include "keybindings.h"
+
+// java.awt.Label justification fields
+#define LEFT 0
+#define CENTER 1
+#define RIGHT 2
+
+class MyLabel : public QLabel
+{
+public:
+ MyLabel(JNIEnv *env, jobject obj, QWidget *parent) : QLabel( parent )
+ {
+ setup(env, obj);
+ }
+
+ ~MyLabel()
+ {
+ destroy();
+ }
+
+#define I_KNOW_WHAT_IM_DOING
+#define PARENT QLabel
+#include "eventmethods.cpp"
+};
+
+class LabelTitle : public AWTEvent {
+
+ private:
+ QLabel *widget;
+ QString *string;
+ Qt::Alignment alignment;
+
+ public:
+ LabelTitle(QLabel *w, QString *s, Qt::Alignment a) : AWTEvent()
+ {
+ widget = w;
+ string = s;
+ alignment = a;
+ }
+
+ void runEvent()
+ {
+ if( string != NULL)
+ {
+ widget->setText( *string );
+ delete string;
+ }
+ else
+ {
+ widget->setAlignment( alignment );
+ }
+ }
+};
+
+/*
+ * Init a QLabel
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtLabelPeer_init
+(JNIEnv *env, jobject obj)
+{
+ QWidget *parentWidget = (QWidget *) getParentWidget( env, obj );
+ // QLabel *label = new QLabel( parentWidget );
+ QLabel *label = new MyLabel( env, obj, parentWidget );
+ assert( label );
+ setNativeObject( env, obj, label );
+}
+
+/*
+ * Sets the text
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtLabelPeer_setText
+(JNIEnv *env, jobject obj, jstring str)
+{
+ QLabel *label = (QLabel *) getNativeObject( env, obj );
+ assert( label );
+
+ QString *qStr = getQString(env, str);
+ mainThread->postEventToMain( new LabelTitle( label, qStr, 0 ) );
+}
+
+/*
+ * Sets the alignment
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtLabelPeer_setAlignment
+(JNIEnv *env, jobject obj, jint align)
+{
+ Qt::Alignment alignment = Qt::AlignVCenter;
+
+ QLabel *label = (QLabel *) getNativeObject( env, obj );
+ assert( label );
+
+ switch(align)
+ {
+ case LEFT:
+ alignment |= Qt::AlignLeft;
+ break;
+
+ case RIGHT:
+ alignment |= Qt::AlignRight;
+ break;
+
+ default:
+ case CENTER:
+ alignment |= Qt::AlignHCenter;
+ break;
+ }
+
+ mainThread->postEventToMain( new LabelTitle( label, NULL, alignment ) );
+}
diff --git a/native/jni/qt-peer/qtlistpeer.cpp b/native/jni/qt-peer/qtlistpeer.cpp
new file mode 100644
index 000000000..a5d8bff4e
--- /dev/null
+++ b/native/jni/qt-peer/qtlistpeer.cpp
@@ -0,0 +1,207 @@
+/* qtlistpeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QWidget>
+#include <QListWidget>
+#include <gnu_java_awt_peer_qt_QtListPeer.h>
+#include "qtcomponent.h"
+#include "qtstrings.h"
+#include "mainthreadinterface.h"
+
+class ListInsert : public AWTEvent {
+
+ private:
+ QListWidget *widget;
+ QString *string;
+ int index;
+
+ public:
+ ListInsert(QListWidget *w, QString *s, int i) : AWTEvent()
+ {
+ widget = w;
+ string = s;
+ index = i;
+ }
+
+ void runEvent()
+ {
+ widget->insertItem( index, *string );
+ delete string;
+ }
+};
+
+class SelectEvent : public AWTEvent {
+
+ private:
+ QListWidget *widget;
+ int index;
+ bool selected;
+
+ public:
+ SelectEvent(QListWidget *w, int i, bool s) : AWTEvent()
+ {
+ widget = w;
+ index = i;
+ selected = s;
+ }
+
+ void runEvent()
+ {
+ widget->setItemSelected ( widget->item(index), selected );
+ }
+};
+
+class ListDelete : public AWTEvent {
+
+ private:
+ QListWidget *widget;
+ int startIndex, endIndex;
+
+ public:
+ ListDelete(QListWidget *w, int starti, int endi) : AWTEvent()
+ {
+ widget = w;
+ startIndex = starti;
+ endIndex = endi;
+ }
+
+ void runEvent()
+ {
+ for (int i = endIndex; i >= startIndex; i--)
+ delete widget->takeItem(i);
+ }
+};
+
+/*
+ * Construct a QListWidget object
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_init
+(JNIEnv *env, jobject obj)
+{
+ QWidget *parentWidget = (QWidget *)getParentWidget(env, obj);
+ assert( parentWidget );
+ QListWidget *list = new QListWidget( parentWidget );
+ assert( list );
+
+ setNativeObject( env, obj, list );
+}
+
+/*
+ * Adds an element.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_add
+(JNIEnv *env, jobject obj, jstring str, jint index)
+{
+ QListWidget *list = (QListWidget *) getNativeObject( env, obj );
+ assert( list );
+ QString *qStr = getQString(env, str);
+ mainThread->postEventToMain( new ListInsert(list, qStr, index) );
+}
+
+/*
+ * Delete items
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_delItems
+(JNIEnv *env, jobject obj, jint startindex, jint endindex)
+{
+ QListWidget *list = (QListWidget *) getNativeObject( env, obj );
+ assert( list );
+ mainThread->postEventToMain( new ListDelete(list, startindex, endindex) );
+}
+
+/*
+ * (De)select an element.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_select
+(JNIEnv *env, jobject obj, jint index, jboolean sel)
+{
+ QListWidget *list = (QListWidget *) getNativeObject( env, obj );
+ assert( list );
+
+ mainThread->postEventToMain( new SelectEvent(list, index,
+ (sel == JNI_TRUE)) );
+}
+
+/**
+ * Returns the indices of the selected items.
+ */
+JNIEXPORT jintArray JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_getSelectedIndexes
+ (JNIEnv *env, jobject obj)
+{
+ jintArray retArray;
+ jint *arr;
+
+ QListWidget *list = (QListWidget *) getNativeObject( env, obj );
+ assert( list );
+
+ QList<QListWidgetItem *> items = list->selectedItems();
+ retArray = env->NewIntArray( items.count() );
+ arr = env->GetIntArrayElements( retArray, NULL );
+
+ for(int i = 0; i < items.count(); i++)
+ arr[i] = list->row(items.at(i));
+
+ env->ReleaseIntArrayElements( retArray, arr, 0 );
+ return retArray;
+}
+
+/*
+ * Sets the current item and makes it visible.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_makeVisible
+ (JNIEnv *env, jobject obj, jint index)
+{
+
+ QListWidget *list = (QListWidget *) getNativeObject( env, obj );
+ assert( list );
+
+ list->scrollToItem( list->item(index) );
+}
+
+/*
+ * Set multiple selection mode.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_setMultipleMode
+(JNIEnv *env, jobject obj, jboolean allow)
+{
+ QListWidget *list = (QListWidget *) getNativeObject( env, obj );
+ assert( list );
+
+ // FIXME: Multiple selection is buggy in Qt4. Workaround needed.
+ list->setSelectionMode( ((allow == JNI_TRUE) ? QAbstractItemView::MultiSelection : QAbstractItemView::SingleSelection) );
+}
+
diff --git a/native/jni/qt-peer/qtmenubarpeer.cpp b/native/jni/qt-peer/qtmenubarpeer.cpp
new file mode 100644
index 000000000..ae62c8dd0
--- /dev/null
+++ b/native/jni/qt-peer/qtmenubarpeer.cpp
@@ -0,0 +1,149 @@
+/* qtmenubarpeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QMenuBar>
+#include <QToolBar>
+#include <QMenu>
+#include <QList>
+#include <QThread>
+#include <gnu_java_awt_peer_qt_QtMenuBarPeer.h>
+#include "nativewrapper.h"
+#include "qtstrings.h"
+#include "mainthreadinterface.h"
+
+/*
+ * Event wrapper to add a menu to a menu bar
+ */
+class MenuBarAdd : public AWTEvent {
+
+ private:
+ QMenuBar *widget;
+ QMenu *menu;
+ bool isHelp;
+
+ public:
+ MenuBarAdd(QMenuBar *w, QMenu *m, bool help) : AWTEvent()
+ {
+ widget = w;
+ menu = m;
+ isHelp = help;
+ }
+
+ void runEvent()
+ {
+ if ( isHelp )
+ widget->addSeparator();
+ QAction *ptr = widget->addMenu( menu );
+ }
+};
+
+/**
+ * Event wrapper to remove a menu from a menu bar.
+ */
+class MenuBarRemove : public AWTEvent {
+
+ private:
+ QMenuBar *widget;
+ QMenu *menu;
+
+ public:
+ MenuBarRemove(QMenuBar *w, QMenu *m) : AWTEvent()
+ {
+ widget = w;
+ menu = m;
+ }
+
+ void runEvent()
+ {
+ // FIXME
+ }
+};
+
+
+/*
+ * Constructs a QMenuBar object.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuBarPeer_init
+ (JNIEnv *env, jobject obj)
+{
+ QMenuBar *menubar = new QMenuBar();
+ assert( menubar );
+ setNativeObject( env, obj, menubar );
+}
+
+/*
+ * Adds a menu item.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuBarPeer_addMenu
+(JNIEnv *env, jobject obj, jobject menuPeer)
+{
+ QMenuBar *menubar = (QMenuBar *)getNativeObject(env, obj);
+ assert( menubar );
+ QMenu *menu = (QMenu *)getNativeObject(env, menuPeer);
+ assert( menu );
+ mainThread->postEventToMain( new MenuBarAdd( menubar, menu, false ) );
+}
+
+/*
+ * Add a help menu.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuBarPeer_addHelpMenu
+(JNIEnv *env, jobject obj, jobject menuPeer)
+{
+ QMenuBar *menubar = (QMenuBar *)getNativeObject(env, obj);
+ assert( menubar );
+ QMenu *menu = (QMenu *)getNativeObject(env, menuPeer);
+ assert( menu );
+
+ mainThread->postEventToMain( new MenuBarAdd( menubar, menu, true ) );
+}
+
+/*
+ * Delete a menu.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuBarPeer_delMenu
+(JNIEnv *env, jobject obj, jobject menuPeer)
+{
+ QMenuBar *menubar = (QMenuBar *)getNativeObject(env, obj);
+ assert( menubar );
+ QMenu *menu = (QMenu *)getNativeObject(env, menuPeer);
+ assert( menu );
+
+ // FIXME
+
+}
+
diff --git a/native/jni/qt-peer/qtmenucomponentpeer.cpp b/native/jni/qt-peer/qtmenucomponentpeer.cpp
new file mode 100644
index 000000000..68388fc82
--- /dev/null
+++ b/native/jni/qt-peer/qtmenucomponentpeer.cpp
@@ -0,0 +1,66 @@
+/* qtmenucomponentpeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QWidget>
+#include <gnu_java_awt_peer_qt_QtMenuComponentPeer.h>
+#include "nativewrapper.h"
+#include "componentevent.h"
+
+
+/**
+ * Calls back init() from the main thread.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuComponentPeer_callInit
+(JNIEnv *env, jobject obj)
+{
+ mainThread->postEventToMain( new AWTInitEvent( env, obj ) );
+ // wait for the thing to be created.
+ while(getNativeObject(env, obj) == 0);
+}
+
+/*
+ * Generic disposal.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuComponentPeer_dispose
+(JNIEnv *env, jobject obj)
+{
+ QWidget *widget = (QWidget *) getNativeObject( env, obj );
+ assert( widget );
+
+ setNativeObject(env, obj, NULL);
+ mainThread->postEventToMain( new AWTDestroyEvent( widget ) );
+}
diff --git a/native/jni/qt-peer/qtmenuitempeer.cpp b/native/jni/qt-peer/qtmenuitempeer.cpp
new file mode 100644
index 000000000..b5dba0393
--- /dev/null
+++ b/native/jni/qt-peer/qtmenuitempeer.cpp
@@ -0,0 +1,181 @@
+/* qtmenuitempeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QMenu>
+#include <QAction>
+#include <QThread>
+#include <gnu_java_awt_peer_qt_QtMenuItemPeer.h>
+#include "nativewrapper.h"
+#include "qtstrings.h"
+#include "mainthreadinterface.h"
+
+class MenuItemDestroyEvent : public AWTEvent {
+
+ private:
+ QAction *widget;
+
+ public:
+ MenuItemDestroyEvent(QAction *w)
+ {
+ widget = w;
+ }
+
+ void runEvent()
+ {
+ delete widget;
+ }
+};
+
+class MenuItemLabelEvent : public AWTEvent {
+
+ private:
+ QAction *widget;
+ QString *string;
+
+ public:
+ MenuItemLabelEvent(QAction *w, QString *s) : AWTEvent()
+ {
+ widget = w;
+ string = s;
+ }
+
+ void runEvent()
+ {
+ widget->setText( *string );
+ delete string;
+ }
+};
+
+class MenuItemStatusEvent : public AWTEvent {
+
+ private:
+ QAction *widget;
+ bool enabled;
+ bool value;
+
+ public:
+ MenuItemStatusEvent(QAction *w, bool e, bool v) : AWTEvent()
+ {
+ widget = w;
+ enabled = e;
+ value = v;
+ }
+
+ void runEvent()
+ {
+ if( enabled )
+ widget->setEnabled( value );
+ else
+ widget->setChecked( value );
+ }
+};
+
+/*
+ * Creates a QAction object
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuItemPeer_create
+(JNIEnv *env, jobject obj, jstring label, jboolean isSeperator, jboolean isCheckable)
+{
+ QAction *action;
+ if(label == NULL || isSeperator == JNI_TRUE)
+ {
+ action = new QAction(NULL);
+ action->setSeparator(true);
+ assert( action );
+ }
+ else
+ {
+ QString *qStr = getQString(env, label);
+ action = new QAction(*qStr, NULL);
+ delete qStr;
+ assert( action );
+ action->setCheckable( (isCheckable == JNI_TRUE) );
+ }
+
+ setNativeObject( env, obj, action );
+}
+
+/**
+ * Disposal.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuItemPeer_dispose
+(JNIEnv *env, jobject obj)
+{
+ QAction *action = (QAction *)getNativeObject( env, obj );
+ assert( action );
+ mainThread->postEventToMain( new MenuItemDestroyEvent( action ) );
+}
+
+/*
+ * Enables/disables the item
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuItemPeer_setEnabled
+(JNIEnv *env, jobject obj, jboolean enabled)
+{
+ QAction *action = (QAction *)getNativeObject( env, obj );
+ assert( action );
+ mainThread->postEventToMain(new MenuItemStatusEvent(action, true,
+ (enabled == JNI_TRUE)));
+}
+
+/*
+ * Sets the item label.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuItemPeer_setLabel
+(JNIEnv *env, jobject obj, jstring label)
+{
+ QAction *action = (QAction *)getNativeObject( env, obj );
+ assert( action );
+
+ QString *qStr = getQString(env, label);
+ mainThread->postEventToMain( new MenuItemLabelEvent( action, qStr ) );
+}
+
+/*
+ * Sets the checkbox state.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuItemPeer_setState
+(JNIEnv *env, jobject obj, jboolean state)
+{
+ QAction *action = (QAction *)getNativeObject( env, obj );
+ assert( action );
+ mainThread->postEventToMain(new MenuItemStatusEvent(action, false,
+ (state == JNI_TRUE)));
+}
+
+
+
diff --git a/native/jni/qt-peer/qtmenupeer.cpp b/native/jni/qt-peer/qtmenupeer.cpp
new file mode 100644
index 000000000..e498bbe21
--- /dev/null
+++ b/native/jni/qt-peer/qtmenupeer.cpp
@@ -0,0 +1,259 @@
+/* qtmenupeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QMenu>
+#include <gnu_java_awt_peer_qt_QtMenuPeer.h>
+#include "nativewrapper.h"
+#include "qtstrings.h"
+#include "mainthreadinterface.h"
+#include "slotcallbacks.h"
+#include "componentevent.h"
+
+#define ADDMENU 0
+#define ADDITEM 1
+#define ADDSEPA 2
+
+// Sets the title, but also tear-off.
+class MenuTitleEvent : public AWTEvent {
+
+ private:
+ QMenu *widget;
+ QString *string;
+ bool tearOff;
+
+ public:
+ MenuTitleEvent(QMenu *w, QString *s, bool tear) : AWTEvent()
+ {
+ widget = w;
+ string = s;
+ tearOff = tear;
+ }
+
+ void runEvent()
+ {
+ if (tearOff)
+ widget->setTearOffEnabled( true );
+ else
+ {
+ widget->setTitle( *string );
+ delete string;
+ }
+ }
+};
+
+class MenuAction : public AWTEvent {
+
+ private:
+ QMenu *menu;
+ QAction *action;
+ int isMenu; // 0 to add a menu, 1 to add an item, 2 to add a seperator
+ QAction **newAction; // adding an action creates a new duplicate.
+
+public:
+ MenuAction(QMenu *m, QAction *a, QAction **na, bool ismenu) : AWTEvent()
+ {
+ menu = m;
+ action = a;
+ isMenu = ismenu;
+ newAction = na;
+ }
+
+ void runEvent()
+ {
+ switch(isMenu)
+ {
+ case ADDMENU:
+ *newAction = menu->addMenu( (QMenu *)action );
+ break;
+ case ADDITEM:
+ *newAction = menu->addAction(action->text());
+ (*newAction)->setSeparator(action->isSeparator());
+ (*newAction)->setCheckable(action->isCheckable());
+ delete action;
+ break;
+ case ADDSEPA:
+ *newAction = menu->addSeparator();
+ break;
+ }
+ }
+};
+
+class MenuRemoveAction : public AWTEvent {
+
+ private:
+ QMenu *menu;
+ QAction *action;
+
+public:
+ MenuRemoveAction(QMenu *m, QAction *a) : AWTEvent()
+ {
+ menu = m;
+ action = a;
+ }
+
+ void runEvent()
+ {
+ if (action)
+ menu->removeAction(action);
+ }
+};
+
+/*
+ * Constructs a QMenu item
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuPeer_init
+(JNIEnv *env, jobject obj)
+{
+ QMenu *menu = new QMenu();
+ assert( menu );
+
+ setNativeObject( env, obj, menu );
+}
+
+/**
+ * Allows tear-off: Only called once, if ever.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuPeer_allowTearOff
+(JNIEnv *env, jobject obj)
+{
+ QMenu *menu = (QMenu *)getNativeObject( env, obj );
+ assert( menu );
+ mainThread->postEventToMain( new MenuTitleEvent( menu, NULL, true ) );
+}
+
+/*
+ * Inserts a seperator.
+ */
+JNIEXPORT jlong JNICALL Java_gnu_java_awt_peer_qt_QtMenuPeer_insertSeperator
+(JNIEnv *env, jobject obj)
+{
+ QMenu *menu = (QMenu *)getNativeObject( env, obj );
+ assert( menu );
+ QAction *newAction = NULL;
+ MenuAction *ma = new MenuAction( menu, NULL, &newAction, ADDSEPA );
+
+ while (newAction == NULL); // Wait for new action.
+
+ return (jlong)newAction;
+}
+
+/*
+ * Inserts an item.
+ */
+JNIEXPORT jlong JNICALL Java_gnu_java_awt_peer_qt_QtMenuPeer_insertItem
+(JNIEnv *env, jobject obj, jobject item)
+{
+ QMenu *menu = (QMenu *)getNativeObject( env, obj );
+ assert( menu );
+ QAction *action = (QAction *)getNativeObject( env, item );
+ assert( action );
+
+ QAction *newAction = NULL;
+ MenuAction *ma = new MenuAction( menu, action, &newAction, ADDITEM );
+ mainThread->postEventToMain( ma );
+
+ while (newAction == NULL); // Wait for new action.
+
+ connectAction(newAction, env, item);
+ setNativeObject(env, item, newAction); // update the MenuItemPeer action.
+
+ return (jlong)newAction;
+}
+
+/*
+ * Inserts a sub-menu
+ */
+JNIEXPORT jlong JNICALL Java_gnu_java_awt_peer_qt_QtMenuPeer_insertMenu
+(JNIEnv *env, jobject obj, jobject menu)
+{
+ assert( menu );
+ QMenu *thisMenu = (QMenu *)getNativeObject( env, obj );
+ assert( thisMenu );
+ QMenu *insMenu = (QMenu *)getNativeObject(env, menu);
+ assert( insMenu );
+
+ QAction *newAction = NULL;
+ MenuAction *ma = new MenuAction( thisMenu, (QAction *)insMenu,
+ &newAction, ADDMENU );
+ mainThread->postEventToMain( ma );
+
+ while (newAction == NULL); // Wait for new action.
+
+ connectAction(newAction, env, menu);
+ return (jlong) newAction;
+}
+
+/*
+ * Removes an item at index.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuPeer_delItem
+(JNIEnv *env, jobject obj, jlong ptr)
+{
+ QMenu *menu = (QMenu *)getNativeObject( env, obj );
+ assert( menu );
+ QAction *action = (QAction *)ptr;
+
+ mainThread->postEventToMain( new MenuRemoveAction( menu, action ) );
+}
+
+/*
+ * Enables/Disables the menu.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuPeer_setEnabled
+(JNIEnv *env, jobject obj, jboolean enabled)
+{
+ QMenu *menu = (QMenu *)getNativeObject( env, obj );
+ assert( menu );
+
+ mainThread->postEventToMain(new AWTEnableEvent(menu, (enabled == JNI_TRUE)));
+}
+
+/*
+ * Sets the menu title.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtMenuPeer_setLabel
+(JNIEnv *env, jobject obj, jstring label)
+{
+ if(label == NULL)
+ return;
+
+ QMenu *menu = (QMenu *)getNativeObject( env, obj );
+ assert( menu );
+ QString *qStr = getQString(env, label);
+ mainThread->postEventToMain( new MenuTitleEvent( menu, qStr, false ) );
+}
+
diff --git a/native/jni/qt-peer/qtpanelpeer.cpp b/native/jni/qt-peer/qtpanelpeer.cpp
new file mode 100644
index 000000000..d9c1ed573
--- /dev/null
+++ b/native/jni/qt-peer/qtpanelpeer.cpp
@@ -0,0 +1,73 @@
+/* qtpanelpeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <qwidget.h>
+#include <gnu_java_awt_peer_qt_QtPanelPeer.h>
+#include "qtcomponent.h"
+#include "keybindings.h"
+
+class MyPanel : public QWidget
+{
+public:
+ MyPanel(JNIEnv *env, jobject obj, QWidget *parent) : QWidget( parent )
+ {
+ setup(env, obj);
+ }
+
+ ~MyPanel()
+ {
+ destroy();
+ }
+
+#define I_KNOW_WHAT_IM_DOING
+#define PARENT QWidget
+#include "eventmethods.cpp"
+#undef I_KNOW_WHAT_IM_DOING
+#undef PARENT
+};
+
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtPanelPeer_init
+(JNIEnv *env, jobject obj)
+{
+ QWidget *parentWidget = (QWidget *) getParentWidget( env, obj );
+ QWidget *canvas = new MyPanel( env, obj, parentWidget );
+ assert( canvas );
+
+ setNativeObject( env, obj, canvas );
+}
+
+
diff --git a/native/jni/qt-peer/qtpopupmenupeer.cpp b/native/jni/qt-peer/qtpopupmenupeer.cpp
new file mode 100644
index 000000000..a25492e18
--- /dev/null
+++ b/native/jni/qt-peer/qtpopupmenupeer.cpp
@@ -0,0 +1,75 @@
+/* qtpopupmenupeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QMenu>
+#include <QPoint>
+#include <QWidget>
+#include <gnu_java_awt_peer_qt_QtPopupMenuPeer.h>
+#include "nativewrapper.h"
+#include "qtstrings.h"
+#include "mainthreadinterface.h"
+
+class PopupMenuShowEvent : public AWTEvent {
+
+ private:
+ QMenu *menu;
+ int x, y;
+
+ public:
+ PopupMenuShowEvent(QMenu *m, int x0, int y0) : AWTEvent()
+ {
+ menu = m;
+ x = x0;
+ y = y0;
+ }
+
+ void runEvent()
+ {
+ menu->exec( QPoint( x, y ) );
+ }
+};
+
+/*
+ * Shows the menu.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtPopupMenuPeer_showNative
+(JNIEnv *env, jobject obj, jint x, jint y)
+{
+ QMenu *menu = (QMenu *)getNativeObject( env, obj );
+ assert( menu );
+ mainThread->postEventToMain( new PopupMenuShowEvent(menu, x, y ) );
+}
diff --git a/native/jni/qt-peer/qtscreendevice.cpp b/native/jni/qt-peer/qtscreendevice.cpp
new file mode 100644
index 000000000..91217cbba
--- /dev/null
+++ b/native/jni/qt-peer/qtscreendevice.cpp
@@ -0,0 +1,122 @@
+/* qtscreendevice.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QApplication>
+#include <QDesktopWidget>
+#include <gnu_java_awt_peer_qt_QtScreenDevice.h>
+#include "nativewrapper.h"
+
+extern QApplication *qApplication;
+
+/*
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScreenDevice_init
+(JNIEnv *env, jobject obj, jint id)
+{
+ QWidget *widget = qApplication->desktop()->screen( id );
+ assert( widget );
+ setNativeObject(env, obj, widget);
+}
+
+/*
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScreenDevice_dispose
+(JNIEnv *env, jobject obj)
+{
+ QWidget *widget = (QWidget *)getNativeObject(env, obj);
+ setNativeObject(env, obj, NULL);
+ if( widget )
+ delete widget;
+}
+
+/*
+ * Returns the bounds
+ */
+JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtScreenDevice_getBounds
+(JNIEnv *env, jobject obj)
+{
+ QWidget *widget = (QWidget *)getNativeObject(env, obj);
+ assert( widget );
+
+ jclass cls = env->FindClass("java/awt/Rectangle");
+ jmethodID mid = env->GetMethodID(cls, "<init>", "(IIII)V");
+ jvalue values[4];
+
+ int x,y,w,h;
+ widget->geometry().getRect( &x, &y, &w, &h );
+
+ values[0].i = (jint) x;
+ values[1].i = (jint) y;
+ values[2].i = (jint) w;
+ values[3].i = (jint) h;
+
+ return env->NewObjectA(cls, mid, values);
+}
+
+/*
+ * Returns the X DPI
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtScreenDevice_getDpiX
+(JNIEnv *env, jobject obj)
+{
+ QWidget *widget = (QWidget *)getNativeObject(env, obj);
+ assert( widget );
+ return widget->logicalDpiX();
+}
+
+/*
+ * Returns the Y DPI
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtScreenDevice_getDpiY
+(JNIEnv *env, jobject obj)
+{
+ QWidget *widget = (QWidget *)getNativeObject(env, obj);
+ assert( widget );
+ return widget->logicalDpiY();
+}
+
+/*
+ * Returns the bitplane depth
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtScreenDevice_depth
+(JNIEnv *env, jobject obj)
+{
+ QWidget *widget = (QWidget *)getNativeObject(env, obj);
+ assert( widget );
+ return widget->depth();
+}
+
diff --git a/native/jni/qt-peer/qtscrollbarpeer.cpp b/native/jni/qt-peer/qtscrollbarpeer.cpp
new file mode 100644
index 000000000..af87b4968
--- /dev/null
+++ b/native/jni/qt-peer/qtscrollbarpeer.cpp
@@ -0,0 +1,141 @@
+/* qtscrollbarpeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QScrollBar>
+#include <gnu_java_awt_peer_qt_QtScrollbarPeer.h>
+#include "keybindings.h"
+#include "slotcallbacks.h"
+#include "qtcomponent.h"
+
+// Constant fields from java.awt.Scrollbar
+#define HORIZONTAL 0
+#define VERTICAL 1
+
+class MyScrollBar : public QScrollBar
+{
+public:
+ MyScrollBar(JNIEnv *env, jobject obj, QWidget *parent) : QScrollBar( parent )
+ {
+ setup(env, obj);
+ }
+
+ ~MyScrollBar()
+ {
+ destroy();
+ }
+
+#define I_KNOW_WHAT_IM_DOING
+#define PARENT QScrollBar
+#include "eventmethods.cpp"
+};
+
+/*
+ * Construct a QScrollbar object
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScrollbarPeer_init
+(JNIEnv *env, jobject obj)
+{
+ QWidget *parentWidget = (QWidget *)getParentWidget( env, obj );
+ assert( parentWidget );
+ // QScrollBar *scrollbar = new QScrollBar( parentWidget );
+ MyScrollBar *scrollbar = new MyScrollBar( env, obj, parentWidget );
+ assert( scrollbar );
+
+ setNativeObject( env, obj, scrollbar );
+ connectScrollBar(scrollbar, env, obj);
+}
+
+/*
+ * Set the line increment.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScrollbarPeer_setLineIncrement
+(JNIEnv *env, jobject obj, jint inc)
+{
+ QScrollBar *bar = (QScrollBar *) getNativeObject( env, obj );
+ assert( bar );
+
+ bar->setSingleStep(inc);
+}
+
+/**
+ * Sets the orientation of the scrollbar
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScrollbarPeer_setOrientation
+(JNIEnv *env, jobject obj, jint orientation)
+{
+ QScrollBar *bar = (QScrollBar *) getNativeObject( env, obj );
+ assert( bar );
+
+ switch(orientation)
+ {
+ case HORIZONTAL:
+ bar->setOrientation ( Qt::Horizontal );
+ break;
+
+ default:
+ case VERTICAL:
+ bar->setOrientation ( Qt::Vertical );
+ break;
+ }
+}
+
+/**
+ * Sets the page increment (equivalent to slider size)
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScrollbarPeer_setPageIncrement
+(JNIEnv *env, jobject obj, jint inc)
+{
+ QScrollBar *bar = (QScrollBar *) getNativeObject( env, obj );
+ assert( bar );
+
+ bar->setPageStep( inc );
+}
+
+/*
+ * Setvalues.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScrollbarPeer_setValues
+(JNIEnv *env, jobject obj, jint value, jint visible, jint min, jint max)
+{
+ QScrollBar *bar = (QScrollBar *) getNativeObject( env, obj );
+ assert( bar );
+
+ bar->setValue(value);
+ bar->setPageStep( visible ); // page step and slider size are the same in Qt
+ bar->setRange( min , max );
+}
+
diff --git a/native/jni/qt-peer/qtscrollpanepeer.cpp b/native/jni/qt-peer/qtscrollpanepeer.cpp
new file mode 100644
index 000000000..b10c44b06
--- /dev/null
+++ b/native/jni/qt-peer/qtscrollpanepeer.cpp
@@ -0,0 +1,211 @@
+/* qtscrollpanepeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QScrollArea>
+#include <QScrollBar>
+#include <gnu_java_awt_peer_qt_QtScrollPanePeer.h>
+#include "qtcomponent.h"
+#include "containers.h"
+#include "mainthreadinterface.h"
+#include "componentevent.h"
+#include "keybindings.h"
+
+// Constants in java.awt.ScrollPane
+#define SCROLLBARS_AS_NEEDED 0
+#define SCROLLBARS_ALWAYS 1
+#define SCROLLBARS_NEVER 2
+
+
+class MyScrollArea : public QScrollArea
+{
+public:
+ MyScrollArea(JNIEnv *env, jobject obj, QWidget *parent) : QScrollArea( parent )
+ {
+ setup(env, obj);
+ }
+
+ ~MyScrollArea()
+ {
+ destroy();
+ }
+
+#define I_KNOW_WHAT_IM_DOING
+#define PARENT QScrollArea
+#include "eventmethods.cpp"
+};
+
+
+class ScrollPanePolicy : public AWTEvent {
+
+ private:
+ QScrollArea *widget;
+ Qt::ScrollBarPolicy policy;
+
+ public:
+ ScrollPanePolicy(QScrollArea *w, Qt::ScrollBarPolicy p) : AWTEvent()
+ {
+ widget = w;
+ policy = p;
+ }
+
+ void runEvent()
+ {
+ widget->setHorizontalScrollBarPolicy(policy);
+ widget->setVerticalScrollBarPolicy(policy);
+ }
+};
+
+/**
+ * Returns the child widget, given the owner Component.
+ */
+QWidget *scrollPaneChildWidget( JNIEnv *env, jobject component )
+{
+ jclass scrollpaneCls = env->FindClass( "java/awt/ScrollPane" );
+ jmethodID getPeerMID = env->GetMethodID( scrollpaneCls,
+ "getPeer",
+ "()Ljava/awt/peer/ComponentPeer;");
+ assert(getPeerMID != 0);
+ jobject scrollpanepeerobj = env->CallObjectMethod( component, getPeerMID, NULL );
+ QScrollArea *view = (QScrollArea *) getNativeObject( env, scrollpanepeerobj );
+ assert(view != 0);
+ return view->viewport();
+}
+
+/*
+ * Creates a QScrollArea object.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScrollPanePeer_init
+(JNIEnv *env, jobject obj)
+{
+ QWidget *parentWidget = (QWidget *) getParentWidget( env, obj );
+ assert( parentWidget );
+ // QScrollArea *pane = new MyScrollArea( env, obj, parentWidget );
+ QScrollArea *pane = new QScrollArea( parentWidget );
+ assert( pane );
+ setNativeObject( env, obj, pane );
+}
+
+/*
+ * Resize the child.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScrollPanePeer_childResized
+(JNIEnv *env, jobject obj, jint w, jint h)
+{
+ QScrollArea *view = (QScrollArea *) getNativeObject( env, obj );
+ assert( view );
+
+ QWidget *child = view->viewport();
+ assert( child );
+ mainThread->postEventToMain( new AWTResizeEvent(child, 0, 0, w, h) );
+}
+
+/*
+ * Returns the horizontal scrollbar height.
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtScrollPanePeer_getHScrollbarHeight
+(JNIEnv *env, jobject obj)
+{
+ QScrollArea *pane = (QScrollArea *) getNativeObject( env, obj );
+ assert( pane );
+ QScrollBar *hbar = pane->horizontalScrollBar();
+ if(hbar == NULL)
+ return 0;
+ if(!hbar->isVisible())
+ return 0;
+ int height = hbar->height();
+
+ return height;
+}
+
+/*
+ * Returns the vertical scrollbar width.
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtScrollPanePeer_getVScrollbarWidth
+(JNIEnv *env, jobject obj)
+{
+ QScrollArea *pane = (QScrollArea *) getNativeObject( env, obj );
+ assert( pane );
+ QScrollBar *vbar = pane->verticalScrollBar();
+ if(vbar == NULL)
+ return 0;
+ if(!vbar->isVisible())
+ return 0;
+ int width = vbar->width();
+
+ return width;
+}
+
+/*
+ * Sets the current upper-left corner to x, y.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScrollPanePeer_setScrollPosition
+(JNIEnv *env, jobject obj, jint x, jint y)
+{
+ QScrollArea *pane = (QScrollArea *) getNativeObject( env, obj );
+ assert( pane );
+ // pane->scrollContentsBy( x, y );
+}
+
+/*
+ * Sets the scrollbar policy
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScrollPanePeer_setPolicy
+(JNIEnv *env, jobject obj, jint policy)
+{
+ QScrollArea *pane = (QScrollArea *) getNativeObject( env, obj );
+ assert( pane );
+
+ Qt::ScrollBarPolicy qtpolicy;
+ switch( policy )
+ {
+ case SCROLLBARS_ALWAYS:
+ qtpolicy = Qt::ScrollBarAlwaysOn;
+ break;
+
+ case SCROLLBARS_NEVER:
+ qtpolicy = Qt::ScrollBarAlwaysOff;
+ break;
+
+ default:
+ case SCROLLBARS_AS_NEEDED:
+ qtpolicy = Qt::ScrollBarAsNeeded;
+ break;
+ }
+
+ mainThread->postEventToMain( new ScrollPanePolicy( pane, qtpolicy ) );
+}
+
diff --git a/native/jni/qt-peer/qtstrings.cpp b/native/jni/qt-peer/qtstrings.cpp
new file mode 100644
index 000000000..c343c6331
--- /dev/null
+++ b/native/jni/qt-peer/qtstrings.cpp
@@ -0,0 +1,54 @@
+/* qtstrings.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include "qtstrings.h"
+
+QString *getQString(JNIEnv *env, jstring str)
+{
+ QString qStr;
+ {
+ const char *chars = env->GetStringUTFChars( str, NULL );
+ qStr = QString::fromUtf8( chars, env->GetStringLength( str ) );
+ env->ReleaseStringUTFChars( str, chars );
+ }
+ return new QString(qStr);
+}
+
+jstring getJavaString(JNIEnv *env, QString *qstring)
+{
+ return env->NewStringUTF(qstring->toUtf8());
+}
diff --git a/native/jni/qt-peer/qtstrings.h b/native/jni/qt-peer/qtstrings.h
new file mode 100644
index 000000000..ba5ab8c99
--- /dev/null
+++ b/native/jni/qt-peer/qtstrings.h
@@ -0,0 +1,10 @@
+#ifndef QTSTRINGS_H
+#define QTSTRINGS_H
+
+#include <jni.h>
+#include <QString>
+
+QString *getQString(JNIEnv *env, jstring str);
+jstring getJavaString(JNIEnv *env, QString *qstring);
+
+#endif
diff --git a/native/jni/qt-peer/qttextareapeer.cpp b/native/jni/qt-peer/qttextareapeer.cpp
new file mode 100644
index 000000000..087640a94
--- /dev/null
+++ b/native/jni/qt-peer/qttextareapeer.cpp
@@ -0,0 +1,191 @@
+/* qttextareapeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <time.h>
+#include <QTextEdit>
+#include <QTextCursor>
+#include <gnu_java_awt_peer_qt_QtTextAreaPeer.h>
+#include "qtcomponent.h"
+#include "qtstrings.h"
+
+// FIXME: This stuff ain't thread safe.
+
+/*
+ * Construct a QTextEdit object
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_init
+(JNIEnv *env, jobject obj)
+{
+ QWidget *parentWidget = (QWidget *)getParentWidget( env, obj );
+ assert( parentWidget );
+ QTextEdit *editor = new QTextEdit( parentWidget );
+ editor->setGeometry( 0, 0, 400, 400 );
+ assert( editor );
+
+ // setLineWrapColumnOrWidth ( int w );
+
+ setNativeObject( env, obj, editor );
+}
+
+/*
+ * Returns the cursor position.
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_getCaretPosition
+(JNIEnv *env, jobject obj)
+{
+ int index;
+
+ QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
+ assert( editor );
+
+ index = editor->textCursor().position();;
+
+ return (jint)index;
+}
+
+/*
+ * Returns the char index at a given screen point
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_getIndexAtPoint
+(JNIEnv *env, jobject obj, jint x, jint y)
+{
+ QPoint *p = new QPoint(x,y);
+
+ QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
+ assert( editor );
+ QTextCursor curs = editor->cursorForPosition( *p );
+ delete p;
+
+ return curs.position();
+}
+
+/*
+ * Returns the start (start = true) or end (start = false) of the selection.
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_getSelection
+(JNIEnv *env, jobject obj, jboolean isStart)
+{
+ int start, end;
+
+ QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
+ assert( editor );
+ start = editor->textCursor().selectionStart();
+ end = editor->textCursor().selectionEnd();
+
+ return ((isStart == JNI_TRUE) ? start : end);
+}
+
+/*
+ * Returns the text.
+ */
+JNIEXPORT jstring JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_getText
+(JNIEnv *env, jobject obj)
+{
+ QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
+ assert( editor );
+ QString text = editor->toPlainText();
+
+ return getJavaString(env, &text);
+}
+
+/*
+ * Inserts text.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_insert
+(JNIEnv *env, jobject obj, jstring str, jint index)
+{
+ QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
+ assert( editor );
+
+ QTextCursor curs = editor->textCursor();
+ int oldPos = curs.position();
+ curs.setPosition( index );
+ QString *qStr = getQString(env, str);
+ curs.insertText( *qStr );
+ delete qStr;
+ curs.setPosition( oldPos );
+}
+
+/*
+ * Sets the editor text.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_setText
+(JNIEnv *env, jobject obj, jstring str)
+{
+ QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
+ assert( editor );
+
+ QString *qStr = getQString(env, str);
+ editor->setPlainText( *qStr );
+ delete qStr;
+}
+
+/*
+ * Sets the selection.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_select
+(JNIEnv *env, jobject obj, jint startpos, jint endpos)
+{
+ QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
+ assert( editor );
+ // FIXME
+// QTextCursor curs = editor->textCursor();
+// editor->setSelection ( 0, startpos, 0, endpos );
+}
+
+/*
+ * Allow or disallow editing.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_setEditable
+(JNIEnv *env, jobject obj, jboolean editable)
+{
+ QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
+ assert( editor );
+ editor->setReadOnly( (editable != JNI_TRUE) );
+}
+
+/*
+ * Sets the cursor position
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_setCaretPosition
+(JNIEnv *env, jobject obj, jint index)
+{
+ QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
+ assert( editor );
+
+ editor->textCursor().setPosition( index );
+}
diff --git a/native/jni/qt-peer/qttextfieldpeer.cpp b/native/jni/qt-peer/qttextfieldpeer.cpp
new file mode 100644
index 000000000..8ff944cec
--- /dev/null
+++ b/native/jni/qt-peer/qttextfieldpeer.cpp
@@ -0,0 +1,287 @@
+/* qttextfieldpeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QLineEdit>
+#include <QWidget>
+#include <gnu_java_awt_peer_qt_QtTextFieldPeer.h>
+#include "qtcomponent.h"
+#include "qtstrings.h"
+#include "mainthreadinterface.h"
+
+class TFEchoChar : public AWTEvent {
+ private:
+ QLineEdit *line;
+ jchar c;
+
+ public:
+ TFEchoChar(QLineEdit *w, jchar ch) : AWTEvent()
+ {
+ line = w;
+ c = ch;
+ }
+
+ void runEvent()
+ {
+ line->setEchoMode( (c) ? QLineEdit::Password : QLineEdit::Normal );
+ }
+};
+
+class TFEditable : public AWTEvent {
+ private:
+ QLineEdit *line;
+ bool editable;
+
+ public:
+ TFEditable(QLineEdit *w, bool e) : AWTEvent()
+ {
+ line = w;
+ editable = e;
+ }
+
+ void runEvent()
+ {
+ line->setReadOnly( editable );
+ }
+};
+
+class TFSetText : public AWTEvent {
+ private:
+ QLineEdit *line;
+ QString *text;
+
+ public:
+ TFSetText(QLineEdit *w, QString *t) : AWTEvent()
+ {
+ line = w;
+ text = t;
+ }
+
+ void runEvent()
+ {
+ line->setText( *text );
+ delete text;
+ }
+};
+
+class TFSetCursorPos : public AWTEvent {
+ private:
+ QLineEdit *line;
+ int pos;
+
+ public:
+ TFSetCursorPos(QLineEdit *w, int p) : AWTEvent()
+ {
+ line = w;
+ pos = p;
+ }
+
+ void runEvent()
+ {
+ line->setCursorPosition(pos);
+ }
+};
+
+class TFSelect : public AWTEvent {
+ private:
+ QLineEdit *line;
+ int start,end;
+
+ public:
+ TFSelect(QLineEdit *w, int s, int e) : AWTEvent()
+ {
+ line = w;
+ start = s;
+ end = e;
+ }
+
+ void runEvent()
+ {
+ line->setSelection(start, end - start);
+ }
+};
+
+
+/*
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_init
+(JNIEnv *env, jobject obj)
+{
+ QWidget *parentWidget = (QWidget *)getParentWidget(env, obj);
+ assert( parentWidget );
+ QLineEdit *line = new QLineEdit( parentWidget );
+ assert( line );
+
+ setNativeObject( env, obj, line );
+}
+
+
+/*
+ * Sets the echo char.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_setEchoChar
+(JNIEnv *env, jobject obj, jchar echo)
+{
+ QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
+ assert( line );
+ mainThread->postEventToMain( new TFEchoChar( line, echo ) );
+}
+
+/*
+ */
+JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getMinimumSizeNative
+(JNIEnv *env, jobject obj, jint columns)
+{
+ QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
+ assert( line );
+
+ // FIXME does this work?
+ int old = line->maxLength();
+ line->setMaxLength(columns);
+ QSize size = line->minimumSizeHint();
+ line->setMaxLength(old);
+
+ return makeDimension(env, &size);
+}
+
+/*
+ */
+JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getPreferredSizeNative
+(JNIEnv *env, jobject obj, jint columns)
+{
+ QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
+ assert( line );
+
+ int old = line->maxLength();
+ line->setMaxLength(columns);
+ QSize size = line->sizeHint();
+ line->setMaxLength(old);
+
+ return makeDimension(env, &size);
+}
+
+/*
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_setEditable
+(JNIEnv *env, jobject obj, jboolean edit)
+{
+ QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
+ assert( line );
+
+ mainThread->postEventToMain( new TFEditable( line, (edit != JNI_TRUE) ) );
+}
+
+/*
+ * Gets the text.
+ */
+JNIEXPORT jstring JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getText
+(JNIEnv *env, jobject obj)
+{
+ QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
+ assert( line );
+ QString text = line->text();
+
+ return getJavaString(env, &text);
+}
+
+/*
+ * Sets the text
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_setText
+(JNIEnv *env, jobject obj, jstring text)
+{
+ QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
+ assert( line );
+
+ QString *qStr = getQString(env, text);
+ mainThread->postEventToMain( new TFSetText( line, qStr ) );
+}
+
+/*
+ * Returns the start (start = true) or end (start = false) of the selection.
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getSelection
+(JNIEnv *env, jobject obj, jboolean start)
+{
+ int index, length;
+
+ QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
+ assert( line );
+ index = line->selectionStart();
+
+ if(start == JNI_TRUE)
+ return index;
+
+ length = (line->selectedText()).length();
+
+ return index + length;
+}
+
+/*
+ * Sets the selection.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_select
+(JNIEnv *env, jobject obj, jint start, jint end)
+{
+ QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
+ assert( line );
+
+ mainThread->postEventToMain( new TFSelect( line, start, end ) );
+}
+
+/*
+ * Sets the cursor position.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_setCaretPosition
+(JNIEnv *env, jobject obj, jint pos)
+{
+ QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
+ assert( line );
+ mainThread->postEventToMain( new TFSetCursorPos( line, (int)pos ) );
+}
+
+/*
+ * Returns the caret position.
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getCaretPosition
+(JNIEnv *env, jobject obj)
+{
+ QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
+ assert( line );
+
+ return line->cursorPosition();
+}
+
diff --git a/native/jni/qt-peer/qttoolkit.cpp b/native/jni/qt-peer/qttoolkit.cpp
new file mode 100644
index 000000000..222b32344
--- /dev/null
+++ b/native/jni/qt-peer/qttoolkit.cpp
@@ -0,0 +1,156 @@
+/* qttoolkit.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QApplication>
+#include <QDesktopWidget>
+#include <QString>
+#include <QStringList>
+#include <QFontDatabase>
+#include <gnu_java_awt_peer_qt_QtToolkit.h>
+#include "qtcomponent.h"
+#include "mainthreadinterface.h"
+#include "qtstrings.h"
+
+extern QApplication *qApplication;
+
+/**
+ * Calls syncX();
+ */
+class AWTSyncEvent : public AWTEvent {
+
+ private:
+ QApplication *application;
+
+ public:
+ AWTSyncEvent(QApplication *app) : AWTEvent()
+ {
+ application = app;
+ }
+
+ void runEvent()
+ {
+ application->syncX();
+ }
+};
+
+/*
+ * Causes your machine to beep. Wow.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtToolkit_beep
+(JNIEnv *env, jobject obj)
+{
+ qApplication->beep();
+}
+
+/**
+ * Returns the # of the default screen.
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtToolkit_defaultScreen
+(JNIEnv *env, jobject obj)
+{
+ return (jint) qApplication->desktop()->primaryScreen();
+}
+
+/**
+ * Returns the # of screens.
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtToolkit_numScreens
+(JNIEnv *env, jobject obj)
+{
+ return (jint) qApplication->desktop()->numScreens();
+}
+
+/*
+ * Returns the screen size.
+ */
+JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtToolkit_getScreenSize
+(JNIEnv *env, jobject obj)
+{
+ QDesktopWidget *d = QApplication::desktop();
+ QSize s = d->size();
+ return makeDimension( env, &s );
+}
+
+/*
+ * Returns the available fonts
+ */
+JNIEXPORT jobjectArray JNICALL Java_gnu_java_awt_peer_qt_QtToolkit_nativeFontFamilies
+(JNIEnv *env, jobject obj)
+{
+ jobjectArray result_array;
+ jobject *result_array_ptr;
+ QFontDatabase db;
+ QStringList fonts = db.families();
+
+ result_array = env->NewObjectArray(fonts.size(),
+ env->FindClass("java/lang/String"),
+ env->NewStringUTF(""));
+ for (int i = 0; i < fonts.size(); i++)
+ {
+ QString qstr = fonts.at(i);
+ jstring jstr = getJavaString(env, &qstr);
+ env->SetObjectArrayElement( result_array, i, jstr );
+ }
+ return result_array;
+}
+
+
+/*
+ * Returns the screen resolution
+ */
+JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtToolkit_getScreenResolution
+(JNIEnv *env, jobject obj)
+{
+ QDesktopWidget *d = qApplication->desktop();
+
+ // Java assumes square pixels. Qt, more intelligently, does not.
+ // What to do? Well.. Average them?
+ // FIXME: Weird values?
+ int dpi = (d->logicalDpiX() + d->logicalDpiY()) >> 1;
+
+ return (jint)dpi;
+}
+
+/*
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtToolkit_sync
+(JNIEnv *env, jobject obj)
+{
+ // SyncX needs to be called from the main thread.
+ mainThread->postEventToMain( new AWTSyncEvent( qApplication ) );
+}
+
diff --git a/native/jni/qt-peer/qtvolatileimage.cpp b/native/jni/qt-peer/qtvolatileimage.cpp
new file mode 100644
index 000000000..1b618c4eb
--- /dev/null
+++ b/native/jni/qt-peer/qtvolatileimage.cpp
@@ -0,0 +1,296 @@
+/* qtvolatileimage.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QImage>
+#include <QColor>
+#include <QMatrix>
+#include <QPainter>
+#include <gnu_java_awt_peer_qt_QtVolatileImage.h>
+#include "qtimage.h"
+#include "qtstrings.h"
+#include "qtgraphics.h"
+#include "nativewrapper.h"
+
+/* The constant fields in java.awt.Image */
+#define SCALE_DEFAULT 1
+#define SCALE_FAST 2
+#define SCALE_SMOOTH 4
+#define SCALE_REPLICATE 8
+#define SCALE_AREA_AVERAGING 16
+
+static void setNativePtr( JNIEnv *env, jobject obj, void *value )
+{
+ jlong longValue = (jlong) value;
+ jclass cls = env->GetObjectClass( obj );
+ jfieldID field = env->GetFieldID( cls, "nativeObject", "J" );
+ env->SetLongField( obj, field, longValue );
+}
+
+/*
+ * Clears the image to zero.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_clear
+(JNIEnv *env, jobject obj)
+{
+ QImage *image = getQtImage(env, obj);
+ assert( image );
+ image->fill(0);
+}
+
+/*
+ * Returns the pixel data in an int array.
+ */
+JNIEXPORT jintArray JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_getPixels
+(JNIEnv *env, jobject obj)
+{
+ QImage *image = getQtImage(env, obj);
+ jintArray result_array;
+ jint *result_array_ptr, *dst;
+ int x, y;
+ jint pixel;
+ QRgb current;
+
+ assert( image );
+
+ result_array = env->NewIntArray (image->width() * image->height());
+ dst = result_array_ptr =
+ env->GetIntArrayElements(result_array, NULL);
+
+ // A bit inefficient.
+ for ( y = 0; y < image->height(); y++)
+ for ( x = 0; x < image->width(); x++)
+ {
+ current = image->pixel(x, y);
+ pixel = 0;
+ pixel = (qAlpha(current) & 0xFF) << 24 |
+ (qRed(current) & 0xFF) << 16 |
+ (qGreen(current) & 0xFF) << 8 |
+ (qBlue(current) & 0xFF);
+ *dst = pixel;
+ dst++;
+ }
+
+ env->ReleaseIntArrayElements (result_array, result_array_ptr, 0);
+ return result_array;
+}
+
+/*
+ * Creates a QImage.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_createImage
+(JNIEnv *env, jobject obj)
+{
+ int width, height;
+ jclass cls;
+ jfieldID field;
+
+ cls = env->GetObjectClass( obj );
+ field = env->GetFieldID (cls, "width", "I");
+ assert (field != 0);
+ width = env->GetIntField(obj, field);
+
+ field = env->GetFieldID(cls, "height", "I");
+ assert (field != 0);
+ height = env->GetIntField(obj, field);
+
+ QImage *image = new QImage ( width, height,
+ QImage::Format_ARGB32_Premultiplied );
+ setNativePtr(env, obj, image);
+}
+
+/*
+ * Frees the image data.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_freeImage
+(JNIEnv *env, jobject obj)
+{
+ QImage *image = getQtImage(env, obj);
+ if ( image )
+ delete image;
+ setNativePtr(env, obj, NULL);
+}
+
+/*
+ * Creates a scaled version.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_createScaledImage
+(JNIEnv *env, jobject obj, jobject src, jint hints)
+{
+ int w,h;
+ jclass cls;
+ jfieldID field;
+
+ cls = env->GetObjectClass( obj );
+ field = env->GetFieldID(cls, "width", "I");
+ assert (field != 0);
+ w = env->GetIntField(obj, field);
+
+ field = env->GetFieldID(cls, "height", "I");
+ assert (field != 0);
+ h = env->GetIntField(obj, field);
+
+ QImage *image = getQtImage(env, src);
+ assert( image );
+ QImage imageScaled;
+
+ if (hints == SCALE_SMOOTH || hints == SCALE_AREA_AVERAGING)
+ imageScaled = image->scaled(w, h,
+ Qt::IgnoreAspectRatio,
+ Qt::SmoothTransformation);
+ else
+ imageScaled = image->scaled(w, h,
+ Qt::IgnoreAspectRatio,
+ Qt::FastTransformation);
+ QImage *scaledPtr = new QImage( imageScaled );
+
+ // create new QtImage object
+ setNativePtr( env, obj, scaledPtr );
+}
+
+/*
+ * DrawPixels.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_drawPixels
+(JNIEnv *env, jobject obj, jobject graphics, jint bg_red, jint bg_green,
+ jint bg_blue, jint x, jint y, jboolean composite)
+{
+ QImage *image = getQtImage(env, obj);
+ assert( image );
+ QPainter *painter = getPainter( env, graphics );
+ assert( painter );
+
+ if(composite == JNI_TRUE)
+ painter->fillRect ( x, y, image->width(), image->height(),
+ QColor(bg_red, bg_green, bg_blue ) );
+ painter->drawImage ( QPoint(x, y), *image );
+}
+
+/*
+ * DrawPixels scaled.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_drawPixelsScaled
+(JNIEnv *env, jobject obj, jobject graphics,
+ jint bg_red, jint bg_green, jint bg_blue,
+ jint x, jint y, jint w, jint h, jboolean composite)
+{
+ QImage *image = getQtImage(env, obj);
+ assert( image );
+ QPainter *painter = getPainter( env, graphics );
+ assert( painter );
+
+ if(composite == JNI_TRUE)
+ painter->fillRect ( x, y, w, h, QColor(bg_red, bg_green, bg_blue ) );
+
+ QRectF *srcRect = new QRectF((qreal)0, (qreal)0,
+ (qreal)image->width(), (qreal)image->height());
+ QRectF *dstRect = new QRectF((qreal)x, (qreal)y,
+ (qreal)w, (qreal)h);
+
+ if(composite == JNI_TRUE)
+ painter->fillRect( *dstRect, QColor(bg_red, bg_green, bg_blue ) );
+
+ painter->drawImage( *dstRect, *image, *srcRect);
+
+ delete srcRect;
+ delete dstRect;
+}
+
+/*
+ * Draw pixels transformed.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_drawPixelsTransformed
+(JNIEnv *env, jobject obj, jobject graphics, jobject transform)
+{
+ QImage *originalImage = getQtImage(env, obj);
+ assert( originalImage );
+ QPainter *painter = getPainter( env, graphics );
+ assert( painter );
+ QMatrix *matrix = (QMatrix *)getNativeObject(env, transform);
+ assert( matrix );
+
+ // FIXME : Add rendering hint support here.
+ QPoint p = matrix->map( QPoint(0,0) );
+ QImage image = originalImage->transformed ( *matrix, Qt::FastTransformation );
+ painter->drawImage(p, image);
+}
+
+
+/**
+ * Draw pixels scaled and flipped
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_drawPixelsScaledFlipped
+(JNIEnv *env, jobject obj, jobject graphics,
+ jint bg_red, jint bg_green, jint bg_blue,
+ jboolean flipx, jboolean flipy,
+ jint srcx, jint srcy, jint srcwidth, jint srcheight,
+ jint dstx, jint dsty, jint dstwidth, jint dstheight,
+ jboolean composite)
+{
+ QImage *originalImage = getQtImage(env, obj);
+ assert( originalImage );
+ QPainter *painter = getPainter( env, graphics );
+ assert( painter );
+
+ QRectF *srcRect = new QRectF((qreal)srcx, (qreal)srcy,
+ (qreal)srcwidth, (qreal)srcheight);
+ QRectF *dstRect = new QRectF((qreal)dstx, (qreal)dsty,
+ (qreal)dstwidth, (qreal)dstheight);
+
+ QImage image = originalImage->mirrored ( (flipx == JNI_TRUE),
+ (flipy == JNI_TRUE) );
+ if(composite == JNI_TRUE)
+ painter->fillRect( *dstRect, QColor(bg_red, bg_green, bg_blue ) );
+
+ painter->drawImage( *dstRect, image, *srcRect);
+
+ delete srcRect;
+ delete dstRect;
+}
+
+/**
+ * Copies an area of the image (used by Graphics)
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_copyArea
+(JNIEnv *env, jobject obj , jint x, jint y, jint w, jint h, jint dx, jint dy)
+{
+ QImage *image = getQtImage(env, obj);
+ assert( image );
+ QImage area = image->copy(x, y, w, h);
+ QPainter *p = new QPainter( image );
+ p->drawImage( x + dx, y + dy, area );
+ delete p;
+}
diff --git a/native/jni/qt-peer/qtwindowpeer.cpp b/native/jni/qt-peer/qtwindowpeer.cpp
new file mode 100644
index 000000000..915c7ce94
--- /dev/null
+++ b/native/jni/qt-peer/qtwindowpeer.cpp
@@ -0,0 +1,146 @@
+/* qtwindowpeer.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QWidget>
+#include <qstyle.h>
+#include <gnu_java_awt_peer_qt_QtWindowPeer.h>
+#include "qtcomponent.h"
+#include "qtstrings.h"
+#include "containers.h"
+#include "mainthreadinterface.h"
+
+class RaiseLower : public AWTEvent {
+
+ private:
+ QWidget *widget;
+ bool raise;
+
+ public:
+ RaiseLower(QWidget *w, bool r) : AWTEvent()
+ {
+ widget = w;
+ raise = r;
+ }
+
+ void runEvent()
+ {
+ if (raise)
+ widget->raise();
+ else
+ widget->lower();
+ }
+};
+
+class FrameTitleEvent : public AWTEvent {
+
+ private:
+ QWidget *widget;
+ QString *string;
+
+ public:
+ FrameTitleEvent(QWidget *w, QString *s) : AWTEvent()
+ {
+ widget = w;
+ string = s;
+ }
+
+ void runEvent()
+ {
+ widget->setWindowTitle( *string );
+ delete string;
+ }
+};
+
+/*
+ * Constructs a top-level QWidget native object.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtWindowPeer_init
+(JNIEnv *env, jobject obj)
+{
+ QWidget *window = new QWidget(0, (Qt::Window | Qt::FramelessWindowHint) );
+ assert( window );
+ // Qt::WStyle_StaysOnTop
+ setNativeObject( env, obj, window );
+}
+
+/*
+ * Destructor
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtWindowPeer_destroy
+(JNIEnv *env, jobject obj)
+{
+ QWidget *window = (QWidget *) getNativeObject( env, obj );
+ assert( window );
+
+ setNativeObject(env, obj, NULL);
+ delete window;
+}
+
+/*
+ * Lower the window.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtWindowPeer_toBack
+(JNIEnv *env, jobject obj)
+{
+ QWidget *window = (QWidget *) getNativeObject( env, obj );
+ assert( window );
+ mainThread->postEventToMain( new RaiseLower( window, false ) );
+}
+
+/*
+ * Raise the window.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtWindowPeer_toFront
+(JNIEnv *env, jobject obj)
+{
+ QWidget *window = (QWidget *) getNativeObject( env, obj );
+ assert( window );
+ mainThread->postEventToMain( new RaiseLower( window, true ) );
+}
+
+/*
+ * Title.
+ */
+JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtWindowPeer_setTitle
+(JNIEnv *env, jobject obj, jstring string)
+{
+ QWidget *frame = (QWidget *) getNativeObject( env, obj );
+ assert( frame );
+ QString *qStr = getQString(env, string);
+ mainThread->postEventToMain( new FrameTitleEvent( frame, qStr ) );
+}
+
diff --git a/native/jni/qt-peer/slotcallbacks.cpp b/native/jni/qt-peer/slotcallbacks.cpp
new file mode 100644
index 000000000..38a22b16a
--- /dev/null
+++ b/native/jni/qt-peer/slotcallbacks.cpp
@@ -0,0 +1,199 @@
+/* slotcallbacks.cpp --
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+#include <QObject>
+#include <QAbstractButton>
+#include <QAbstractSlider>
+#include <QAction>
+#include <QComboBox>
+#include <QPushButton>
+#include <gnu_java_awt_peer_qt_QtButtonPeer.h>
+#include "qtcomponent.h"
+#include "qtstrings.h"
+#include "keybindings.h"
+#include "buttonevent.h"
+#include "slotcallbacks.h"
+
+// AdjustmentEvent constants
+#define UNIT_INCREMENT 1
+#define UNIT_DECREMENT 2
+#define BLOCK_DECREMENT 3
+#define BLOCK_INCREMENT 4
+#define TRACK 5
+
+
+class SlotCallback : public QObject {
+ Q_OBJECT;
+
+private:
+ JavaVM* vm;
+ jobject target;
+ jclass componentCls;
+ jmethodID fireEventID;
+
+public:
+ QScrollBar *sb; // used only by the scrollbar method.
+
+ SlotCallback(JNIEnv *env, jobject t)
+ {
+ env->GetJavaVM(&vm);
+ target = t;
+ target = env->NewGlobalRef(t);
+ }
+
+ ~SlotCallback()
+ {
+ JNIEnv *env;
+ vm->GetEnv((void **)&env, JNI_VERSION_1_1);
+ env->DeleteGlobalRef(target);
+ }
+
+public slots:
+ void buttonClicked()
+ {
+ JNIEnv *env;
+ vm->GetEnv((void **)&env, JNI_VERSION_1_1);
+ componentCls = env->GetObjectClass( target );
+ fireEventID = env->GetMethodID( componentCls,
+ "fireClick",
+ "(I)V" );
+ int modifiers = getKeyModifiers( QApplication::keyboardModifiers() );
+ env->CallVoidMethod( target, fireEventID, modifiers );
+ env->DeleteLocalRef( componentCls );
+ }
+
+ void buttonToggled(bool checked)
+ {
+ JNIEnv *env;
+ vm->GetEnv((void **)&env, JNI_VERSION_1_1);
+ componentCls = env->GetObjectClass( target );
+ fireEventID = env->GetMethodID( componentCls,
+ "fireToggle",
+ "(Z)V" );
+ if(checked)
+ env->CallVoidMethod( target, fireEventID, JNI_TRUE );
+ else
+ env->CallVoidMethod( target, fireEventID, JNI_FALSE );
+ env->DeleteLocalRef( componentCls );
+ }
+
+ void choiceActivated( int index )
+ {
+ JNIEnv *env;
+ vm->GetEnv((void **)&env, JNI_VERSION_1_1);
+ componentCls = env->GetObjectClass( target );
+ fireEventID = env->GetMethodID( componentCls,
+ "fireChoice",
+ "(I)V" );
+ env->CallVoidMethod( target, fireEventID, (jint)index );
+ env->DeleteLocalRef( componentCls );
+ }
+
+ void scrollBarAction( int action )
+ {
+ JNIEnv *env;
+ int type;
+ int index;
+ switch(action)
+ {
+ case QAbstractSlider::SliderNoAction:
+ return;
+ case QAbstractSlider::SliderSingleStepAdd:
+ type = UNIT_INCREMENT;
+ break;
+ case QAbstractSlider::SliderSingleStepSub:
+ type = UNIT_DECREMENT;
+ break;
+ case QAbstractSlider::SliderPageStepAdd:
+ type = BLOCK_INCREMENT;
+ break;
+ case QAbstractSlider::SliderPageStepSub:
+ type = BLOCK_DECREMENT;
+ break;
+ case QAbstractSlider::SliderToMinimum:
+ type = TRACK;
+ break;
+ case QAbstractSlider::SliderToMaximum:
+ type = TRACK;
+ break;
+ case QAbstractSlider::SliderMove:
+ type = TRACK;
+ break;
+ }
+ index = sb->value();
+ vm->GetEnv((void **)&env, JNI_VERSION_1_1);
+ componentCls = env->GetObjectClass( target );
+ fireEventID = env->GetMethodID( componentCls,
+ "fireMoved",
+ "(II)V" );
+ env->CallVoidMethod( target, fireEventID, (jint)type, (jint)index );
+ env->DeleteLocalRef( componentCls );
+ }
+};
+
+#include "slotcallbacks.moc"
+
+void connectButton(QPushButton *button, JNIEnv *env, jobject buttonobj)
+{
+ SlotCallback *scb = new SlotCallback(env, buttonobj);
+ QObject::connect( button, SIGNAL( clicked() ), scb, SLOT( buttonClicked() ) );
+}
+
+void connectChoice(QComboBox *choice, JNIEnv *env, jobject choiceobj)
+{
+ SlotCallback *scb = new SlotCallback(env, choiceobj);
+ QObject::connect( choice, SIGNAL( activated(int) ), scb, SLOT( choiceActivated(int) ) );
+}
+
+void connectAction(QAction *action, JNIEnv *env, jobject obj)
+{
+ SlotCallback *scb = new SlotCallback(env, obj);
+ QObject::connect( action, SIGNAL( triggered() ), scb, SLOT( buttonClicked() ) );
+}
+
+void connectToggle(QAbstractButton *action, JNIEnv *env, jobject obj)
+{
+ SlotCallback *scb = new SlotCallback(env, obj);
+ QObject::connect( action, SIGNAL( toggled(bool) ), scb, SLOT( buttonToggled(bool) ) );
+}
+
+void connectScrollBar(QScrollBar *scroll, JNIEnv *env, jobject obj)
+{
+ SlotCallback *scb = new SlotCallback(env, obj);
+ scb->sb = scroll;
+ QObject::connect( scroll, SIGNAL( actionTriggered(int) ), scb, SLOT( scrollBarAction(int) ) );
+}
diff --git a/native/jni/qt-peer/slotcallbacks.h b/native/jni/qt-peer/slotcallbacks.h
new file mode 100644
index 000000000..3929bde7a
--- /dev/null
+++ b/native/jni/qt-peer/slotcallbacks.h
@@ -0,0 +1,18 @@
+#ifndef SLOTCALLBACKS_H
+#define SLOTCALLBACKS_H
+
+#include <QAbstractButton>
+#include <QAbstractSlider>
+#include <QAction>
+#include <QComboBox>
+#include <QPushButton>
+#include <QScrollBar>
+#include <jni.h>
+
+void connectButton(QPushButton *button, JNIEnv *env, jobject buttonobj);
+void connectChoice(QComboBox *choice, JNIEnv *env, jobject choiceobj);
+void connectAction(QAction *action, JNIEnv *env, jobject obj);
+void connectToggle(QAbstractButton *action, JNIEnv *env, jobject obj);
+void connectScrollBar(QScrollBar *scroll, JNIEnv *env, jobject obj);
+
+#endif
diff --git a/native/jni/qt-peer/slotcallbacks.moc b/native/jni/qt-peer/slotcallbacks.moc
new file mode 100644
index 000000000..b36b88b3e
--- /dev/null
+++ b/native/jni/qt-peer/slotcallbacks.moc
@@ -0,0 +1,75 @@
+/****************************************************************************
+** Meta object code from reading C++ file 'slotcallbacks.cpp'
+**
+** Created: Sun Jul 24 22:00:17 2005
+** by: The Qt Meta Object Compiler version 58 (Qt 4.0.0)
+**
+** WARNING! All changes made in this file will be lost!
+*****************************************************************************/
+
+#if !defined(Q_MOC_OUTPUT_REVISION)
+#error "The header file 'slotcallbacks.cpp' doesn't include <QObject>."
+#elif Q_MOC_OUTPUT_REVISION != 58
+#error "This file was generated using the moc from 4.0.0. It"
+#error "cannot be used with the include files from this version of Qt."
+#error "(The moc has changed too much.)"
+#endif
+
+static const uint qt_meta_data_SlotCallback[] = {
+
+ // content:
+ 1, // revision
+ 0, // classname
+ 0, 0, // classinfo
+ 4, 10, // methods
+ 0, 0, // properties
+ 0, 0, // enums/sets
+
+ // slots: signature, parameters, type, tag, flags
+ 14, 13, 13, 13, 0x0a,
+ 38, 30, 13, 13, 0x0a,
+ 64, 58, 13, 13, 0x0a,
+ 92, 85, 13, 13, 0x0a,
+
+ 0 // eod
+};
+
+static const char qt_meta_stringdata_SlotCallback[] = {
+ "SlotCallback\0\0buttonClicked()\0checked\0buttonToggled(bool)\0index\0"
+ "choiceActivated(int)\0action\0scrollBarAction(int)\0"
+};
+
+const QMetaObject SlotCallback::staticMetaObject = {
+ { &QObject::staticMetaObject, qt_meta_stringdata_SlotCallback,
+ qt_meta_data_SlotCallback, 0 }
+};
+
+const QMetaObject *SlotCallback::metaObject() const
+{
+ return &staticMetaObject;
+}
+
+void *SlotCallback::qt_metacast(const char *_clname)
+{
+ if (!_clname) return 0;
+ if (!strcmp(_clname, qt_meta_stringdata_SlotCallback))
+ return static_cast<void*>(const_cast<SlotCallback*>(this));
+ return QObject::qt_metacast(_clname);
+}
+
+int SlotCallback::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
+{
+ _id = QObject::qt_metacall(_c, _id, _a);
+ if (_id < 0)
+ return _id;
+ if (_c == QMetaObject::InvokeMetaMethod) {
+ switch (_id) {
+ case 0: buttonClicked(); break;
+ case 1: buttonToggled(*(bool*)_a[1]); break;
+ case 2: choiceActivated(*(int*)_a[1]); break;
+ case 3: scrollBarAction(*(int*)_a[1]); break;
+ }
+ _id -= 4;
+ }
+ return _id;
+}