Initial revision
From-SVN: r104578
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
*.o
|
||||
*.a
|
||||
*.lo
|
||||
*.la
|
||||
.libs
|
||||
.deps
|
||||
Makefile
|
||||
Makefile.in
|
||||
@@ -0,0 +1,16 @@
|
||||
pkglib_LTLIBRARIES = libjawtgnu.la
|
||||
|
||||
libjawtgnu_la_SOURCES = jawt.c
|
||||
libjawtgnu_la_LIBADD = $(top_builddir)/native/jni/gtk-peer/libgtkpeer.la
|
||||
# FIXME: libtool doesn't allow overriding SONAME, but we need to set
|
||||
# it to libjawt.so for binary compatibility.
|
||||
#
|
||||
# libjawtgnu_la_LDFLAGS = -Wl,-soname -Wl,libjawt.so
|
||||
|
||||
AM_LDFLAGS = @CLASSPATH_MODULE@ @GTK_LIBS@ @CAIRO_LIBS@ @PANGOFT2_LIBS@ @X_LIBS@ -lXtst
|
||||
AM_CPPFLAGS = @CLASSPATH_INCLUDES@
|
||||
|
||||
# Just the WARNING_CFLAGS. We cannot use the strict flags since the gtk
|
||||
# headers contain broken prototypes (by design, see gtkitemfactory.h).
|
||||
AM_CFLAGS = @WARNING_CFLAGS@ @ERROR_CFLAGS@ \
|
||||
@GTK_CFLAGS@ @CAIRO_CFLAGS@ @PANGOFT2_CFLAGS@
|
||||
@@ -0,0 +1,186 @@
|
||||
/* jawt.c -- X11 implementation of the AWT Native Interface
|
||||
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 <stdlib.h>
|
||||
#include <jni.h>
|
||||
#include <jawt.h>
|
||||
#include <jawt_md.h>
|
||||
#include "classpath_jawt.h"
|
||||
|
||||
#ifndef __GNUC__
|
||||
#define __attribute__(x) /* nothing */
|
||||
#endif
|
||||
|
||||
static jint (JNICALL _Jv_Lock) (JAWT_DrawingSurface* surface);
|
||||
static void (JNICALL _Jv_Unlock) (JAWT_DrawingSurface* surface);
|
||||
static JAWT_DrawingSurfaceInfo* (JNICALL _Jv_GetDrawingSurfaceInfo)
|
||||
(JAWT_DrawingSurface* surface);
|
||||
static void (JNICALL _Jv_FreeDrawingSurfaceInfo)
|
||||
(JAWT_DrawingSurfaceInfo* surface_info);
|
||||
static JAWT_DrawingSurface* (JNICALL _Jv_GetDrawingSurface) (JNIEnv* env,
|
||||
jobject canvas);
|
||||
static void (JNICALL _Jv_FreeDrawingSurface) (JAWT_DrawingSurface* surface);
|
||||
static void (JNICALL _Jv_AWTLock) (JNIEnv*);
|
||||
static void (JNICALL _Jv_AWTUnlock) (JNIEnv*);
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
JAWT_GetAWT (JNIEnv* env __attribute__((unused)), JAWT* awt)
|
||||
{
|
||||
jint retrieved_version;
|
||||
|
||||
retrieved_version = classpath_jawt_get_awt_version ();
|
||||
|
||||
if (awt->version > retrieved_version)
|
||||
return JNI_FALSE;
|
||||
|
||||
awt->GetDrawingSurface = _Jv_GetDrawingSurface;
|
||||
awt->FreeDrawingSurface = _Jv_FreeDrawingSurface;
|
||||
awt->Lock = _Jv_AWTLock;
|
||||
awt->Unlock = _Jv_AWTUnlock;
|
||||
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
/* JAWT_DrawingSurface functions */
|
||||
|
||||
static jint
|
||||
(JNICALL _Jv_Lock) (JAWT_DrawingSurface* surface __attribute__((unused)))
|
||||
{
|
||||
return classpath_jawt_lock ();
|
||||
}
|
||||
|
||||
static void
|
||||
(JNICALL _Jv_Unlock) (JAWT_DrawingSurface* surface __attribute__((unused)))
|
||||
{
|
||||
classpath_jawt_unlock ();
|
||||
}
|
||||
|
||||
static JAWT_DrawingSurfaceInfo*
|
||||
(JNICALL _Jv_GetDrawingSurfaceInfo) (JAWT_DrawingSurface* surface)
|
||||
{
|
||||
JAWT_DrawingSurfaceInfo* surface_info;
|
||||
JAWT_X11DrawingSurfaceInfo* surface_info_x11;
|
||||
|
||||
if (surface == NULL || surface->target == NULL)
|
||||
return NULL;
|
||||
|
||||
surface_info = (JAWT_DrawingSurfaceInfo*) malloc (sizeof (JAWT_DrawingSurfaceInfo));
|
||||
|
||||
if (surface_info == NULL)
|
||||
return NULL;
|
||||
|
||||
surface_info->platformInfo = malloc (sizeof (JAWT_X11DrawingSurfaceInfo));
|
||||
|
||||
if (surface_info->platformInfo == NULL)
|
||||
return NULL;
|
||||
|
||||
surface_info_x11 = (JAWT_X11DrawingSurfaceInfo*) surface_info->platformInfo;
|
||||
|
||||
surface_info_x11->display = classpath_jawt_get_default_display (surface->env,
|
||||
surface->target);
|
||||
surface_info_x11->drawable = classpath_jawt_get_drawable (surface->env,
|
||||
surface->target);
|
||||
surface_info_x11->visualID = classpath_jawt_get_visualID (surface->env,
|
||||
surface->target);
|
||||
|
||||
/* FIXME: also include bounding rectangle of drawing surface */
|
||||
/* FIXME: also include current clipping region */
|
||||
|
||||
return surface_info;
|
||||
}
|
||||
|
||||
static void
|
||||
(JNICALL _Jv_FreeDrawingSurfaceInfo) (JAWT_DrawingSurfaceInfo* surface_info)
|
||||
{
|
||||
JAWT_X11DrawingSurfaceInfo* surface_info_x11;
|
||||
|
||||
if (surface_info == NULL)
|
||||
return;
|
||||
|
||||
surface_info_x11 = (JAWT_X11DrawingSurfaceInfo*) surface_info->platformInfo;
|
||||
|
||||
surface_info_x11->display = NULL;
|
||||
surface_info_x11->drawable = 0;
|
||||
surface_info_x11->visualID = 0;
|
||||
|
||||
free (surface_info->platformInfo);
|
||||
free (surface_info);
|
||||
surface_info = NULL;
|
||||
}
|
||||
|
||||
/* JAWT functions */
|
||||
|
||||
static JAWT_DrawingSurface*
|
||||
(JNICALL _Jv_GetDrawingSurface) (JNIEnv* env, jobject canvas)
|
||||
{
|
||||
JAWT_DrawingSurface* surface;
|
||||
|
||||
surface = (JAWT_DrawingSurface*) malloc (sizeof (JAWT_DrawingSurface));
|
||||
|
||||
if (surface == NULL)
|
||||
return NULL;
|
||||
|
||||
surface->env = env;
|
||||
surface->target = canvas;
|
||||
|
||||
/* initialize function pointers */
|
||||
surface->GetDrawingSurfaceInfo = _Jv_GetDrawingSurfaceInfo;
|
||||
surface->FreeDrawingSurfaceInfo = _Jv_FreeDrawingSurfaceInfo;
|
||||
|
||||
surface->Lock = _Jv_Lock;
|
||||
surface->Unlock = _Jv_Unlock;
|
||||
|
||||
return surface;
|
||||
}
|
||||
|
||||
static void
|
||||
(JNICALL _Jv_FreeDrawingSurface) (JAWT_DrawingSurface* surface)
|
||||
{
|
||||
free (surface);
|
||||
}
|
||||
|
||||
static void
|
||||
(JNICALL _Jv_AWTLock) (JNIEnv* env __attribute__((unused)))
|
||||
{
|
||||
classpath_jawt_lock ();
|
||||
}
|
||||
|
||||
static void
|
||||
(JNICALL _Jv_AWTUnlock) (JNIEnv* env __attribute__((unused)))
|
||||
{
|
||||
classpath_jawt_unlock ();
|
||||
}
|
||||
@@ -0,0 +1,440 @@
|
||||
/* gtkselection.c -- Native C functions for GtkSelection class using gtk+.
|
||||
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 "jcl.h"
|
||||
#include "gtkpeer.h"
|
||||
#include "gnu_java_awt_peer_gtk_GtkSelection.h"
|
||||
|
||||
static jmethodID mimeTypesAvailableID;
|
||||
|
||||
/* Note this is actually just a GtkClipboardReceivedFunc, not a real
|
||||
GtkClipboardTargetsReceivedFunc, see requestMimeTypes. */
|
||||
static void
|
||||
clipboard_targets_received (GtkClipboard *clipboard
|
||||
__attribute__((unused)),
|
||||
GtkSelectionData *target_data,
|
||||
gpointer selection)
|
||||
{
|
||||
GdkAtom *targets = NULL;
|
||||
gint targets_len = 0;
|
||||
gchar **target_strings = NULL;
|
||||
jobjectArray strings = NULL;
|
||||
int strings_len = 0;
|
||||
gboolean include_text = FALSE;
|
||||
gboolean include_image = FALSE;
|
||||
gboolean include_uris = FALSE;
|
||||
jobject selection_obj = (jobject) selection;
|
||||
JNIEnv *env = cp_gtk_gdk_env ();
|
||||
|
||||
if (target_data != NULL && target_data->length > 0)
|
||||
{
|
||||
include_text = gtk_selection_data_targets_include_text (target_data);
|
||||
|
||||
#if GTK_MINOR_VERSION > 4
|
||||
include_image = gtk_selection_data_targets_include_image (target_data,
|
||||
TRUE);
|
||||
#endif
|
||||
if (gtk_selection_data_get_targets (target_data, &targets, &targets_len))
|
||||
{
|
||||
int i;
|
||||
GdkAtom uri_list_atom = gdk_atom_intern ("text/uri-list", FALSE);
|
||||
target_strings = g_new (gchar*, targets_len);
|
||||
if (target_strings != NULL)
|
||||
for (i = 0; i < targets_len; i++)
|
||||
{
|
||||
gchar *name = gdk_atom_name (targets[i]);
|
||||
if (strchr (name, '/') != NULL)
|
||||
{
|
||||
target_strings[i] = name;
|
||||
strings_len++;
|
||||
if (! include_uris && targets[i] == uri_list_atom)
|
||||
include_uris = TRUE;
|
||||
}
|
||||
else
|
||||
target_strings[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (target_strings != NULL)
|
||||
{
|
||||
int i = 0, j = 0;
|
||||
jclass stringClass;
|
||||
|
||||
if (include_text)
|
||||
strings_len++;
|
||||
if (include_image)
|
||||
strings_len++;
|
||||
if (include_uris)
|
||||
strings_len++;
|
||||
|
||||
stringClass = (*env)->FindClass (env, "java/lang/String");
|
||||
strings = (*env)->NewObjectArray (env, strings_len, stringClass,
|
||||
NULL);
|
||||
if (strings != NULL)
|
||||
{
|
||||
if (include_text)
|
||||
(*env)->SetObjectArrayElement (env, strings, i++,
|
||||
cp_gtk_stringTarget);
|
||||
if (include_image)
|
||||
(*env)->SetObjectArrayElement (env, strings, i++,
|
||||
cp_gtk_imageTarget);
|
||||
if (include_uris)
|
||||
(*env)->SetObjectArrayElement (env, strings, i++,
|
||||
cp_gtk_filesTarget);
|
||||
|
||||
while(i < strings_len)
|
||||
{
|
||||
if (target_strings[j] == NULL)
|
||||
j++;
|
||||
else
|
||||
{
|
||||
jstring string;
|
||||
string = (*env)->NewStringUTF (env,
|
||||
target_strings[j++]);
|
||||
if (string == NULL)
|
||||
break;
|
||||
(*env)->SetObjectArrayElement (env, strings, i++,
|
||||
string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < targets_len; i++)
|
||||
g_free (target_strings[i]);
|
||||
g_free (target_strings);
|
||||
}
|
||||
}
|
||||
|
||||
(*env)->CallVoidMethod (env, selection_obj,
|
||||
mimeTypesAvailableID,
|
||||
strings);
|
||||
(*env)->DeleteGlobalRef (env, selection_obj);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_gnu_java_awt_peer_gtk_GtkSelection_requestMimeTypes
|
||||
(JNIEnv *env, jobject selection)
|
||||
{
|
||||
jobject selection_obj;
|
||||
selection_obj = (*env)->NewGlobalRef(env, selection);
|
||||
if (selection_obj == NULL)
|
||||
return;
|
||||
|
||||
if (mimeTypesAvailableID == NULL)
|
||||
{
|
||||
jclass gtk_selection_class;
|
||||
gtk_selection_class = (*env)->GetObjectClass (env, selection_obj);
|
||||
mimeTypesAvailableID = (*env)->GetMethodID (env, gtk_selection_class,
|
||||
"mimeTypesAvailable",
|
||||
"([Ljava/lang/String;)V");
|
||||
if (mimeTypesAvailableID == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
/* We would have liked to call gtk_clipboard_request_targets ()
|
||||
since that is more general. But the result of that, an array of
|
||||
GdkAtoms, cannot be used with the
|
||||
gtk_selection_data_targets_include_<x> functions (despite what
|
||||
the name suggests). */
|
||||
gdk_threads_enter ();
|
||||
gtk_clipboard_request_contents (cp_gtk_clipboard,
|
||||
gdk_atom_intern ("TARGETS", FALSE),
|
||||
clipboard_targets_received,
|
||||
(gpointer) selection_obj);
|
||||
gdk_threads_leave ();
|
||||
}
|
||||
|
||||
|
||||
static jmethodID textAvailableID;
|
||||
|
||||
static void
|
||||
clipboard_text_received (GtkClipboard *clipboard
|
||||
__attribute__((unused)),
|
||||
const gchar *text,
|
||||
gpointer selection)
|
||||
{
|
||||
jstring string;
|
||||
jobject selection_obj = (jobject) selection;
|
||||
|
||||
JNIEnv *env = cp_gtk_gdk_env ();
|
||||
if (text != NULL)
|
||||
string = (*env)->NewStringUTF (env, text);
|
||||
else
|
||||
string = NULL;
|
||||
|
||||
(*env)->CallVoidMethod (env, selection_obj,
|
||||
textAvailableID,
|
||||
string);
|
||||
(*env)->DeleteGlobalRef (env, selection_obj);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_gnu_java_awt_peer_gtk_GtkSelection_requestText
|
||||
(JNIEnv *env, jobject selection)
|
||||
{
|
||||
jobject selection_obj;
|
||||
selection_obj = (*env)->NewGlobalRef(env, selection);
|
||||
if (selection_obj == NULL)
|
||||
return;
|
||||
|
||||
if (textAvailableID == NULL)
|
||||
{
|
||||
jclass gtk_selection_class;
|
||||
gtk_selection_class = (*env)->GetObjectClass (env, selection_obj);
|
||||
textAvailableID = (*env)->GetMethodID (env, gtk_selection_class,
|
||||
"textAvailable",
|
||||
"(Ljava/lang/String;)V");
|
||||
if (textAvailableID == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
gdk_threads_enter ();
|
||||
gtk_clipboard_request_text (cp_gtk_clipboard,
|
||||
clipboard_text_received,
|
||||
(gpointer) selection_obj);
|
||||
gdk_threads_leave ();
|
||||
}
|
||||
|
||||
static jmethodID imageAvailableID;
|
||||
|
||||
static void
|
||||
clipboard_image_received (GtkClipboard *clipboard
|
||||
__attribute__((unused)),
|
||||
GdkPixbuf *pixbuf,
|
||||
gpointer selection)
|
||||
{
|
||||
jobject pointer = NULL;
|
||||
jobject selection_obj = (jobject) selection;
|
||||
JNIEnv *env = cp_gtk_gdk_env ();
|
||||
|
||||
if (pixbuf != NULL)
|
||||
{
|
||||
g_object_ref (pixbuf);
|
||||
pointer = JCL_NewRawDataObject (env, (void *) pixbuf);
|
||||
}
|
||||
|
||||
(*env)->CallVoidMethod (env, selection_obj,
|
||||
imageAvailableID,
|
||||
pointer);
|
||||
(*env)->DeleteGlobalRef (env, selection_obj);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_gnu_java_awt_peer_gtk_GtkSelection_requestImage (JNIEnv *env, jobject obj)
|
||||
{
|
||||
jobject selection_obj;
|
||||
selection_obj = (*env)->NewGlobalRef(env, obj);
|
||||
if (selection_obj == NULL)
|
||||
return;
|
||||
|
||||
if (imageAvailableID == NULL)
|
||||
{
|
||||
jclass gtk_selection_class;
|
||||
gtk_selection_class = (*env)->GetObjectClass (env, selection_obj);
|
||||
imageAvailableID = (*env)->GetMethodID (env, gtk_selection_class,
|
||||
"imageAvailable",
|
||||
"(Lgnu/classpath/Pointer;)V");
|
||||
if (imageAvailableID == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
#if GTK_MINOR_VERSION > 4
|
||||
gdk_threads_enter ();
|
||||
gtk_clipboard_request_image (cp_gtk_clipboard,
|
||||
clipboard_image_received,
|
||||
(gpointer) selection_obj);
|
||||
gdk_threads_leave ();
|
||||
#else
|
||||
clipboard_image_received (cp_gtk_clipboard, NULL, (gpointer) selection_obj);
|
||||
#endif
|
||||
}
|
||||
|
||||
static jmethodID urisAvailableID;
|
||||
|
||||
static void
|
||||
clipboard_uris_received (GtkClipboard *clipboard
|
||||
__attribute__((unused)),
|
||||
GtkSelectionData *uri_data,
|
||||
gpointer selection)
|
||||
{
|
||||
gchar **uris = NULL;
|
||||
jobjectArray strings = NULL;
|
||||
jobject selection_obj = (jobject) selection;
|
||||
JNIEnv *env = cp_gtk_gdk_env ();
|
||||
|
||||
#if GTK_MINOR_VERSION > 4
|
||||
if (uri_data != NULL)
|
||||
uris = gtk_selection_data_get_uris (uri_data);
|
||||
#else
|
||||
if (uri_data != NULL)
|
||||
uris = NULL;
|
||||
#endif
|
||||
|
||||
if (uris != NULL)
|
||||
{
|
||||
int len, i;
|
||||
gchar **count = uris;
|
||||
jclass stringClass = (*env)->FindClass (env, "java/lang/String");
|
||||
|
||||
len = 0;
|
||||
while (count[len])
|
||||
len++;
|
||||
|
||||
strings = (*env)->NewObjectArray (env, len, stringClass, NULL);
|
||||
if (strings != NULL)
|
||||
{
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
jstring string = (*env)->NewStringUTF (env, uris[i]);
|
||||
if (string == NULL)
|
||||
break;
|
||||
(*env)->SetObjectArrayElement (env, strings, i, string);
|
||||
}
|
||||
}
|
||||
g_strfreev (uris);
|
||||
}
|
||||
|
||||
(*env)->CallVoidMethod (env, selection_obj,
|
||||
urisAvailableID,
|
||||
strings);
|
||||
(*env)->DeleteGlobalRef (env, selection_obj);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_gnu_java_awt_peer_gtk_GtkSelection_requestURIs (JNIEnv *env, jobject obj)
|
||||
{
|
||||
#if GTK_MINOR_VERSION > 4
|
||||
GdkAtom uri_atom;
|
||||
#endif
|
||||
jobject selection_obj;
|
||||
selection_obj = (*env)->NewGlobalRef(env, obj);
|
||||
if (selection_obj == NULL)
|
||||
return;
|
||||
|
||||
if (urisAvailableID == NULL)
|
||||
{
|
||||
jclass gtk_selection_class;
|
||||
gtk_selection_class = (*env)->GetObjectClass (env, selection_obj);
|
||||
urisAvailableID = (*env)->GetMethodID (env, gtk_selection_class,
|
||||
"urisAvailable",
|
||||
"([Ljava/lang/String;)V");
|
||||
if (urisAvailableID == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
#if GTK_MINOR_VERSION > 4
|
||||
/* There is no real request_uris so we have to make one ourselves. */
|
||||
gdk_threads_enter ();
|
||||
uri_atom = gdk_atom_intern ("text/uri-list", FALSE);
|
||||
gtk_clipboard_request_contents (cp_gtk_clipboard,
|
||||
uri_atom,
|
||||
clipboard_uris_received,
|
||||
(gpointer) selection_obj);
|
||||
gdk_threads_leave ();
|
||||
#else
|
||||
clipboard_uris_received (cp_gtk_clipboard, NULL, (gpointer) selection_obj);
|
||||
#endif
|
||||
}
|
||||
|
||||
static jmethodID bytesAvailableID;
|
||||
|
||||
static void
|
||||
clipboard_bytes_received (GtkClipboard *clipboard
|
||||
__attribute__((unused)),
|
||||
GtkSelectionData *selection_data,
|
||||
gpointer selection)
|
||||
{
|
||||
jbyteArray bytes = NULL;
|
||||
jobject selection_obj = (jobject) selection;
|
||||
JNIEnv *env = cp_gtk_gdk_env ();
|
||||
|
||||
if (selection_data != NULL && selection_data->length > 0)
|
||||
{
|
||||
bytes = (*env)->NewByteArray (env, selection_data->length);
|
||||
if (bytes != NULL)
|
||||
(*env)->SetByteArrayRegion(env, bytes, 0, selection_data->length,
|
||||
(jbyte *) selection_data->data);
|
||||
}
|
||||
|
||||
(*env)->CallVoidMethod (env, selection_obj,
|
||||
bytesAvailableID,
|
||||
bytes);
|
||||
(*env)->DeleteGlobalRef (env, selection_obj);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_gnu_java_awt_peer_gtk_GtkSelection_requestBytes (JNIEnv *env,
|
||||
jobject obj,
|
||||
jstring target_string)
|
||||
{
|
||||
int len;
|
||||
const gchar *target_text;
|
||||
GdkAtom target_atom;
|
||||
jobject selection_obj;
|
||||
selection_obj = (*env)->NewGlobalRef(env, obj);
|
||||
if (selection_obj == NULL)
|
||||
return;
|
||||
|
||||
if (bytesAvailableID == NULL)
|
||||
{
|
||||
jclass gtk_selection_class;
|
||||
gtk_selection_class = (*env)->GetObjectClass (env, selection_obj);
|
||||
bytesAvailableID = (*env)->GetMethodID (env, gtk_selection_class,
|
||||
"bytesAvailable",
|
||||
"([B)V");
|
||||
if (bytesAvailableID == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
len = (*env)->GetStringUTFLength (env, target_string);
|
||||
if (len == -1)
|
||||
return;
|
||||
target_text = (*env)->GetStringUTFChars (env, target_string, NULL);
|
||||
if (target_text == NULL)
|
||||
return;
|
||||
|
||||
gdk_threads_enter ();
|
||||
target_atom = gdk_atom_intern (target_text, FALSE);
|
||||
gtk_clipboard_request_contents (cp_gtk_clipboard,
|
||||
target_atom,
|
||||
clipboard_bytes_received,
|
||||
(gpointer) selection_obj);
|
||||
gdk_threads_leave ();
|
||||
|
||||
(*env)->ReleaseStringUTFChars (env, target_string, target_text);
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* Does not require locking: meant to be called after the drawing
|
||||
surface is locked. */
|
||||
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);
|
||||
|
||||
widget = GTK_WIDGET (ptr);
|
||||
|
||||
if (GTK_WIDGET_REALIZED (widget))
|
||||
{
|
||||
display = gtk_widget_get_display (widget);
|
||||
|
||||
xdisplay = GDK_DISPLAY_XDISPLAY (display);
|
||||
|
||||
return xdisplay;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Does not require locking: meant to be called after the drawing
|
||||
surface is locked. */
|
||||
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);
|
||||
|
||||
widget = GTK_WIDGET (ptr);
|
||||
|
||||
if (GTK_WIDGET_REALIZED (widget))
|
||||
{
|
||||
visual = gdk_x11_visual_get_xvisual (gtk_widget_get_visual (widget));
|
||||
g_assert (visual != NULL);
|
||||
|
||||
return visual->visualid;
|
||||
}
|
||||
else
|
||||
return (VisualID) NULL;
|
||||
}
|
||||
|
||||
/* Does not require locking: meant to be called after the drawing
|
||||
surface is locked. */
|
||||
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);
|
||||
|
||||
widget = GTK_WIDGET (ptr);
|
||||
|
||||
if (GTK_WIDGET_REALIZED (widget))
|
||||
{
|
||||
drawable = GDK_DRAWABLE_XID (widget->window);
|
||||
|
||||
return drawable;
|
||||
}
|
||||
else
|
||||
return (Drawable) NULL;
|
||||
}
|
||||
|
||||
jint
|
||||
classpath_jawt_lock ()
|
||||
{
|
||||
gdk_threads_enter ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
classpath_jawt_unlock ()
|
||||
{
|
||||
gdk_threads_leave ();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
*.o
|
||||
*.a
|
||||
*.lo
|
||||
*.la
|
||||
.libs
|
||||
.deps
|
||||
Makefile
|
||||
Makefile.in
|
||||
slotcallbacks.moc.h
|
||||
@@ -0,0 +1,78 @@
|
||||
# Qt AWT backend for Classpath
|
||||
#
|
||||
|
||||
pkglib_LTLIBRARIES = libqtpeer.la
|
||||
|
||||
AM_LDFLAGS = @CLASSPATH_MODULE@ @QT_LIBS@
|
||||
AM_CPPFLAGS = @CLASSPATH_INCLUDES@
|
||||
|
||||
AM_CXXFLAGS = @QT_CFLAGS@
|
||||
|
||||
libqtpeer_la_MOC = \
|
||||
slotcallbacks.moc.h
|
||||
|
||||
slotcallbacks.moc.h: slotcallbacks.cpp
|
||||
$(MOC) -o slotcallbacks.moc.h $(srcdir)/slotcallbacks.cpp
|
||||
|
||||
nodist_libqtpeer_la_SOURCES = \
|
||||
$(libqtpeer_la_MOC)
|
||||
|
||||
libqtpeer_la_SOURCES = \
|
||||
buttonevent.h \
|
||||
componentevent.cpp \
|
||||
componentevent.h \
|
||||
containers.h \
|
||||
eventmethods.h \
|
||||
keybindings.cpp \
|
||||
keybindings.h \
|
||||
mainqtthread.cpp \
|
||||
mainthreadinterface.cpp \
|
||||
mainthreadinterface.h \
|
||||
nativewrapper.cpp \
|
||||
nativewrapper.h \
|
||||
qmatrix.cpp \
|
||||
qpainterpath.cpp \
|
||||
qpen.cpp \
|
||||
qtaudioclip.cpp \
|
||||
qtbuttonpeer.cpp \
|
||||
qtcanvaspeer.cpp \
|
||||
qtcheckboxpeer.cpp \
|
||||
qtchoicepeer.cpp \
|
||||
qtcomponent.cpp \
|
||||
qtcomponent.h \
|
||||
qtcomponentpeer.cpp \
|
||||
qtdialogpeer.cpp \
|
||||
qtembeddedwindowpeer.cpp \
|
||||
qtfiledialogpeer.cpp \
|
||||
qtfont.h \
|
||||
qtfontmetrics.cpp \
|
||||
qtfontpeer.cpp \
|
||||
qtframepeer.cpp \
|
||||
qtgraphics.cpp \
|
||||
qtgraphics.h \
|
||||
qtimage.cpp \
|
||||
qtimage.h \
|
||||
qtlabelpeer.cpp \
|
||||
qtlistpeer.cpp \
|
||||
qtmenubarpeer.cpp \
|
||||
qtmenucomponentpeer.cpp \
|
||||
qtmenuitempeer.cpp \
|
||||
qtmenupeer.cpp \
|
||||
qtpanelpeer.cpp \
|
||||
qtpopupmenupeer.cpp \
|
||||
qtscreendevice.cpp \
|
||||
qtscrollbarpeer.cpp \
|
||||
qtscrollpanepeer.cpp \
|
||||
qtstrings.cpp \
|
||||
qtstrings.h \
|
||||
qttextareapeer.cpp \
|
||||
qttextfieldpeer.cpp \
|
||||
qttoolkit.cpp \
|
||||
qtvolatileimage.cpp \
|
||||
qtwindowpeer.cpp \
|
||||
slotcallbacks.cpp \
|
||||
slotcallbacks.h
|
||||
|
||||
BUILT_SOURCES = $(libqtpeer_la_MOC)
|
||||
|
||||
CLEANFILES = so_locations $(BUILT_SOURCES)
|
||||
@@ -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
|
||||
@@ -0,0 +1,222 @@
|
||||
/* 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 <QWidget>
|
||||
#include <QPoint>
|
||||
|
||||
#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 );
|
||||
// call init()
|
||||
jmethodID mID = env->GetMethodID( targetCls,
|
||||
"init",
|
||||
"()V" );
|
||||
env->CallVoidMethod( target, mID );
|
||||
|
||||
// call notify()
|
||||
mID = env->GetMethodID( targetCls,
|
||||
"notify",
|
||||
"()V" );
|
||||
assert(mID != NULL);
|
||||
env->MonitorEnter( target );
|
||||
env->CallVoidMethod( target, mID );
|
||||
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()
|
||||
{
|
||||
QRect g = widget->geometry();
|
||||
if(g.x() != x || g.y() != y || g.width() != w || g.height() != h)
|
||||
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;
|
||||
}
|
||||
|
||||
AWTGetOriginEvent::AWTGetOriginEvent(QWidget *w, JNIEnv *env, jobject obj) : AWTEvent()
|
||||
{
|
||||
widget = w;
|
||||
env->GetJavaVM( &vm );
|
||||
target = env->NewGlobalRef( obj );
|
||||
}
|
||||
|
||||
void AWTGetOriginEvent::runEvent()
|
||||
{
|
||||
JNIEnv *env;
|
||||
vm->GetEnv((void **)&env, JNI_VERSION_1_1);
|
||||
jclass targetCls = env->GetObjectClass( target );
|
||||
|
||||
QPoint *p = new QPoint( widget->mapToGlobal( QPoint(0, 0) ) );
|
||||
// call init()
|
||||
jmethodID mID = env->GetMethodID( targetCls,
|
||||
"setLocation",
|
||||
"(II)V" );
|
||||
env->CallVoidMethod( target, mID, p->x(), p->y() );
|
||||
delete p;
|
||||
|
||||
// call notify()
|
||||
mID = env->GetMethodID( targetCls,
|
||||
"notify",
|
||||
"()V" );
|
||||
assert(mID != NULL);
|
||||
env->MonitorEnter( target );
|
||||
env->CallVoidMethod( target, mID );
|
||||
env->MonitorExit( target );
|
||||
|
||||
env->DeleteGlobalRef( target );
|
||||
}
|
||||
|
||||
GetSizeEvent::GetSizeEvent(QWidget *w, JNIEnv *env, jobject obj, bool p) : AWTEvent()
|
||||
{
|
||||
widget = w;
|
||||
env->GetJavaVM( &vm );
|
||||
target = env->NewGlobalRef( obj );
|
||||
pref = p;
|
||||
}
|
||||
|
||||
void GetSizeEvent::runEvent()
|
||||
{
|
||||
JNIEnv *env;
|
||||
vm->GetEnv((void **)&env, JNI_VERSION_1_1);
|
||||
jclass targetCls = env->GetObjectClass( target );
|
||||
|
||||
QPoint *p = new QPoint( widget->mapToGlobal( QPoint(0, 0) ) );
|
||||
QSize s;
|
||||
if( pref )
|
||||
s = widget->sizeHint();
|
||||
else
|
||||
s = widget->minimumSizeHint();
|
||||
|
||||
// call init()
|
||||
jmethodID mID = env->GetMethodID( targetCls,
|
||||
"setSize",
|
||||
"(II)V" );
|
||||
env->CallVoidMethod( target, mID, s.width(), s.height() );
|
||||
|
||||
// call notify()
|
||||
mID = env->GetMethodID( targetCls,
|
||||
"notify",
|
||||
"()V" );
|
||||
assert(mID != NULL);
|
||||
env->MonitorEnter( target );
|
||||
env->CallVoidMethod( target, mID );
|
||||
env->MonitorExit( target );
|
||||
|
||||
env->DeleteGlobalRef( target );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
#ifndef CALLBACKEVENT_H
|
||||
#define CALLBACKEVENT_H
|
||||
|
||||
#include <jni.h>
|
||||
#include <QWidget>
|
||||
#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()
|
||||
{
|
||||
if( widget != NULL )
|
||||
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:
|
||||
JavaVM* vm;
|
||||
jobject target;
|
||||
QWidget *widget;
|
||||
|
||||
public:
|
||||
AWTGetOriginEvent(QWidget *w, JNIEnv *env, jobject obj);
|
||||
void runEvent();
|
||||
};
|
||||
|
||||
class GetSizeEvent : public AWTEvent {
|
||||
|
||||
private:
|
||||
JavaVM* vm;
|
||||
jobject target;
|
||||
QWidget *widget;
|
||||
bool pref;
|
||||
|
||||
public:
|
||||
GetSizeEvent(QWidget *w, JNIEnv *env, jobject obj, bool p);
|
||||
void runEvent();
|
||||
};
|
||||
|
||||
class AWTReparent : public AWTEvent {
|
||||
|
||||
private:
|
||||
QWidget *widget;
|
||||
QWidget *parent;
|
||||
|
||||
public:
|
||||
AWTReparent(QWidget *w, QWidget *p) : AWTEvent()
|
||||
{
|
||||
widget = w;
|
||||
parent = p;
|
||||
}
|
||||
void runEvent()
|
||||
{
|
||||
widget->setParent( parent );
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -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
|
||||
@@ -0,0 +1,245 @@
|
||||
/* 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
|
||||
|
||||
bool draw;
|
||||
|
||||
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 );
|
||||
draw = 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;
|
||||
modifiers = 0;
|
||||
|
||||
modifiers |= getReleaseModifiers( e );
|
||||
x = e->x();
|
||||
y = e->y();
|
||||
callMouseMethod("mouseReleaseEvent", modifiers, x, y, 0);
|
||||
}
|
||||
|
||||
void moveEvent( QMoveEvent *e )
|
||||
{
|
||||
PARENT::moveEvent(e);
|
||||
callMouseMethod("moveEvent", e->pos().x(), e->pos().y(),
|
||||
e->oldPos().x(), e->oldPos().y());
|
||||
}
|
||||
|
||||
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 );
|
||||
if ( draw )
|
||||
{
|
||||
// Create a QPainter
|
||||
GraphicsPainter painter( this );
|
||||
int x, y, w, h;
|
||||
e->rect().getRect ( &x, &y, &w, &h );
|
||||
|
||||
// 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;IIII)V");
|
||||
jobject graphics = env->NewObject(cls, mid, (jlong)&painter, target,
|
||||
(jint)x, (jint)y, (jint)w, (jint)h);
|
||||
|
||||
// call QtComponentPeer.paintEvent()
|
||||
jmethodID paintEventID = env->GetMethodID( componentCls,
|
||||
"paint",
|
||||
"(Ljava/awt/Graphics;)V" );
|
||||
env->CallVoidMethod( target, paintEventID, graphics );
|
||||
env->DeleteLocalRef( cls );
|
||||
env->DeleteLocalRef( graphics );
|
||||
painter.end();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,600 @@
|
||||
/* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key modifiers in KeyEvent format
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key modifiers in ActionEvent format
|
||||
*/
|
||||
int getAEKeyModifiers(Qt::KeyboardModifiers state)
|
||||
{
|
||||
int modifier = 0;
|
||||
if( state & Qt::ShiftModifier )
|
||||
modifier |= SHIFT_MASK;
|
||||
if( state & Qt::ControlModifier )
|
||||
modifier |= CTRL_MASK;
|
||||
if( state & Qt::AltModifier )
|
||||
modifier |= ALT_MASK;
|
||||
if( state & Qt::MetaModifier )
|
||||
modifier |= META_MASK;
|
||||
|
||||
return modifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mouse modifiers in InputEvent format
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mouse modifiers in InputEvent format
|
||||
* We need a different method here because e->buttons() doesn't work for,
|
||||
* mouseReleased events. (But strangely enough it does for pressed ones)
|
||||
*/
|
||||
int getReleaseModifiers(QMouseEvent *e)
|
||||
{
|
||||
int modifier = 0;
|
||||
int button = e->button();
|
||||
int state = e->modifiers();
|
||||
|
||||
if( button & Qt::LeftButton )
|
||||
modifier |= BUTTON1_DOWN_MASK;
|
||||
if( button & Qt::MidButton )
|
||||
modifier |= BUTTON2_DOWN_MASK;
|
||||
if( button & 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#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 getAEKeyModifiers(Qt::KeyboardModifiers state);
|
||||
int getMouseModifiers(QMouseEvent *event);
|
||||
int getReleaseModifiers(QMouseEvent *e);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,112 @@
|
||||
/* 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 <assert.h>
|
||||
#include <jni.h>
|
||||
#include <QApplication>
|
||||
#include <QThread>
|
||||
#include <gnu_java_awt_peer_qt_MainQtThread.h>
|
||||
#include "mainthreadinterface.h"
|
||||
|
||||
MainThreadInterface *mainThread;
|
||||
QApplication *qApplication;
|
||||
|
||||
#if defined(Q_WS_X11)
|
||||
extern void qt_x11_set_global_double_buffer( bool );
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Starts up a QApplication
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_gnu_java_awt_peer_qt_MainQtThread_init
|
||||
(JNIEnv *env, jobject obj, jstring theme, jboolean doublebuffer)
|
||||
{
|
||||
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 );
|
||||
|
||||
#if defined(Q_WS_X11)
|
||||
// turn off double-buffering.
|
||||
qt_x11_set_global_double_buffer( (doublebuffer == JNI_TRUE) );
|
||||
#endif
|
||||
|
||||
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();
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/* 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 )
|
||||
{
|
||||
QObject::event( 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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#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()
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class MainThreadInterface : public QObject {
|
||||
|
||||
private:
|
||||
QApplication *mainApp;
|
||||
|
||||
public:
|
||||
MainThreadInterface(QApplication *parent);
|
||||
bool event ( QEvent * e );
|
||||
void postEventToMain(AWTEvent *event);
|
||||
};
|
||||
|
||||
extern MainThreadInterface *mainThread;
|
||||
|
||||
#endif
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,96 @@
|
||||
/* 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 <assert.h>
|
||||
#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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,239 @@
|
||||
/* 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 <assert.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/* 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 <assert.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/* 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 <assert.h>
|
||||
#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.h"
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/* 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 <assert.h>
|
||||
#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.h"
|
||||
};
|
||||
|
||||
/*
|
||||
* 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 );
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
/* 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 <assert.h>
|
||||
#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.h"
|
||||
};
|
||||
|
||||
/**
|
||||
* 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) ) );
|
||||
}
|
||||
|
||||
@@ -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 <assert.h>
|
||||
#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 ) );
|
||||
}
|
||||
|
||||
@@ -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->GetObjectClass( qtcomponentpeer );
|
||||
jfieldID ownerField = env->GetFieldID( componentCls,
|
||||
"owner", "Ljava/awt/Component;" );
|
||||
assert( ownerField );
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,384 @@
|
||||
/* 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 <assert.h>
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QShowEvent>
|
||||
#include <QHideEvent>
|
||||
#include <QColor>
|
||||
#include <QCursor>
|
||||
#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 ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* Generic disposal.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_disposeNative
|
||||
(JNIEnv *env, jobject obj)
|
||||
{
|
||||
QWidget *widget = (QWidget *) getNativeObject( env, obj );
|
||||
setNativeObject(env, obj, NULL);
|
||||
mainThread->postEventToMain( new AWTDestroyEvent( widget ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the on-screen location of the component.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_getLocationOnScreenNative
|
||||
(JNIEnv *env, jobject obj, jobject point)
|
||||
{
|
||||
QWidget *widget = (QWidget *) getNativeObject( env, obj );
|
||||
assert( widget );
|
||||
mainThread->postEventToMain( new AWTGetOriginEvent( widget, env, point) );
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the preferred/minimum size of the widget
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_getSizeNative
|
||||
(JNIEnv *env, jobject obj, jobject size, jboolean preferred)
|
||||
{
|
||||
QWidget *widget = (QWidget *) getNativeObject( env, obj );
|
||||
assert( widget );
|
||||
|
||||
mainThread->postEventToMain
|
||||
(new GetSizeEvent( widget, env, size, (preferred == JNI_TRUE)));
|
||||
}
|
||||
|
||||
/*
|
||||
*/
|
||||
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 );
|
||||
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 );
|
||||
}
|
||||
|
||||
/*
|
||||
* Reparents the widget.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_reparentNative
|
||||
(JNIEnv *env, jobject obj, jobject newparent)
|
||||
{
|
||||
QWidget *widget = (QWidget *) getNativeObject( env, obj );
|
||||
assert( widget );
|
||||
QWidget *parentWidget = (QWidget *) getNativeObject( env, newparent );
|
||||
assert( parentWidget );
|
||||
mainThread->postEventToMain( new AWTReparent(widget, parentWidget ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the preferred size of the widget
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_getBounds
|
||||
|
||||
(JNIEnv *env, jobject obj)
|
||||
{
|
||||
QWidget *widget = (QWidget *) getNativeObject( env, obj );
|
||||
assert( widget );
|
||||
|
||||
int x, y, w, h;
|
||||
widget->geometry().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);
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
/* 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 <assert.h>
|
||||
#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.h"
|
||||
};
|
||||
|
||||
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) ) );
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/* qtembeddedwindowpeer.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 <assert.h>
|
||||
#include <QWidget>
|
||||
#include <QX11EmbedWidget>
|
||||
#include <gnu_java_awt_peer_qt_QtEmbeddedWindowPeer.h>
|
||||
#include "qtcomponent.h"
|
||||
#include "keybindings.h"
|
||||
#include "mainthreadinterface.h"
|
||||
|
||||
/**
|
||||
* Event wrapper for embedding.
|
||||
*/
|
||||
class EmbedEvent : public AWTEvent {
|
||||
|
||||
private:
|
||||
QX11EmbedWidget *widget;
|
||||
WId id;
|
||||
|
||||
public:
|
||||
EmbedEvent(QX11EmbedWidget *w, WId i) : AWTEvent()
|
||||
{
|
||||
widget = w;
|
||||
id = i;
|
||||
}
|
||||
|
||||
void runEvent()
|
||||
{
|
||||
widget->embedInto( id );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class MyEmbeddedPanel : public QX11EmbedWidget
|
||||
{
|
||||
public:
|
||||
MyEmbeddedPanel(JNIEnv *env, jobject obj, QWidget *parent) : QX11EmbedWidget( parent )
|
||||
{
|
||||
setup(env, obj);
|
||||
}
|
||||
|
||||
~MyEmbeddedPanel()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
#define I_KNOW_WHAT_IM_DOING
|
||||
#define PARENT QX11EmbedWidget
|
||||
#include "eventmethods.h"
|
||||
#undef I_KNOW_WHAT_IM_DOING
|
||||
#undef PARENT
|
||||
};
|
||||
|
||||
/**
|
||||
* Init
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtEmbeddedWindowPeer_init
|
||||
(JNIEnv *env, jobject obj)
|
||||
{
|
||||
QWidget *parentWidget = (QWidget *) getParentWidget( env, obj );
|
||||
QWidget *panel = new MyEmbeddedPanel( env, obj, parentWidget );
|
||||
assert( panel );
|
||||
|
||||
setNativeObject( env, obj, panel );
|
||||
}
|
||||
|
||||
/**
|
||||
* Embed the thing.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtEmbeddedWindowPeer_embed
|
||||
(JNIEnv *env, jobject obj, jlong wid)
|
||||
{
|
||||
MyEmbeddedPanel *panel = (MyEmbeddedPanel *)getNativeObject( env, obj );
|
||||
assert( panel );
|
||||
|
||||
mainThread->postEventToMain( new EmbedEvent( panel, (WId)wid ) );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/* 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 <assert.h>
|
||||
#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) ) );
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef QTFONT_H
|
||||
#define QTFONT_H
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
QFont *getFont( JNIEnv *env, jobject obj );
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,233 @@
|
||||
/* 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 <assert.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/* 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 <assert.h>
|
||||
#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 );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
/* 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 <assert.h>
|
||||
#include <QApplication>
|
||||
#include <QIcon>
|
||||
#include <QMainWindow>
|
||||
#include <QMenuBar>
|
||||
#include <QPixmap>
|
||||
#include <QToolBar>
|
||||
#include <QThread>
|
||||
#include <gnu_java_awt_peer_qt_QtFramePeer.h>
|
||||
#include "qtcomponent.h"
|
||||
#include "qtstrings.h"
|
||||
#include "qtimage.h"
|
||||
#include "containers.h"
|
||||
#include "keybindings.h"
|
||||
#include "mainthreadinterface.h"
|
||||
|
||||
#define MenuSizeDefault 5
|
||||
|
||||
/*
|
||||
* Our QMainWindow subclass
|
||||
*/
|
||||
class MyFrame : public QMainWindow
|
||||
{
|
||||
public:
|
||||
MyFrame(JNIEnv *env, jobject obj) : QMainWindow(0, Qt::Window )
|
||||
{
|
||||
setup(env, obj);
|
||||
}
|
||||
|
||||
~MyFrame()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
#define I_KNOW_WHAT_IM_DOING
|
||||
#define PARENT QMainWindow
|
||||
#include "eventmethods.h"
|
||||
};
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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);
|
||||
if( framepeerobj == NULL )
|
||||
return (QWidget *)NULL;
|
||||
|
||||
MyFrame *window = (MyFrame *)getNativeObject(env, framepeerobj);
|
||||
assert( window );
|
||||
return window;
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructs a QMainWindow native object.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFramePeer_init
|
||||
(JNIEnv *env, jobject obj)
|
||||
{
|
||||
MyFrame *frame = new MyFrame(env, obj);
|
||||
assert( frame );
|
||||
frame->addToolBarBreak ( Qt::BottomToolBarArea );
|
||||
setNativeObject( env, obj, frame );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the icon image.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFramePeer_setIcon
|
||||
(JNIEnv *env, jobject obj, jobject image)
|
||||
{
|
||||
QMainWindow *frame = (QMainWindow *) getNativeObject( env, obj );
|
||||
assert( frame );
|
||||
|
||||
QIcon *i;
|
||||
if( image == NULL )
|
||||
{
|
||||
// remove icon
|
||||
i = new QIcon();
|
||||
}
|
||||
else
|
||||
{
|
||||
// set icon
|
||||
QImage *img = getQtImage( env, image );
|
||||
assert( img );
|
||||
i = new QIcon( QPixmap::fromImage( *img ) );
|
||||
}
|
||||
frame->setWindowIcon( *i );
|
||||
delete i;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 );
|
||||
|
||||
QMenuBar *mb = frame->menuBar();
|
||||
|
||||
return ( mb != NULL ) ? mb->sizeHint().height() : 0 ;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bounds of the maximized frame
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFramePeer_setMaximizedBounds (JNIEnv *env, jobject obj, jint w, jint h)
|
||||
{
|
||||
QMainWindow *frame = (QMainWindow *) getNativeObject( env, obj );
|
||||
assert( frame );
|
||||
// FIXME
|
||||
}
|
||||
|
||||
@@ -0,0 +1,475 @@
|
||||
/* 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 <assert.h>
|
||||
#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 );
|
||||
assert( im );
|
||||
QPainter *painter = new GraphicsPainter( im );
|
||||
assert( painter );
|
||||
setNativePtr(env, obj, painter);
|
||||
painter->setRenderHint(QPainter::TextAntialiasing);
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
painter->setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
}
|
||||
|
||||
/*
|
||||
* Start of JNI methods
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_initVolatileImage
|
||||
(JNIEnv *env, jobject obj, jobject image)
|
||||
{
|
||||
QPixmap *im = getQtVolatileImage( env, image );
|
||||
assert( im );
|
||||
QPainter *painter = new GraphicsPainter( im );
|
||||
assert( painter );
|
||||
setNativePtr(env, obj, painter);
|
||||
painter->setRenderHint(QPainter::TextAntialiasing);
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
painter->setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the QPainter
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
/*
|
||||
* 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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,401 @@
|
||||
/* 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 <assert.h>
|
||||
#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;
|
||||
if( flipx == JNI_TRUE || flipy == JNI_TRUE)
|
||||
image = originalImage->mirrored ( (flipx == JNI_TRUE),
|
||||
(flipy == JNI_TRUE) );
|
||||
else
|
||||
image = *originalImage;
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef QTIMAGE_H
|
||||
#define QTIMAGE_H
|
||||
|
||||
#include <QImage>
|
||||
#include <QPixmap>
|
||||
|
||||
QImage *getQtImage( JNIEnv *env, jobject obj );
|
||||
QPixmap *getQtVolatileImage( JNIEnv *env, jobject obj );
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,151 @@
|
||||
/* 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 <assert.h>
|
||||
#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.h"
|
||||
};
|
||||
|
||||
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 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 ) );
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
/* 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 <assert.h>
|
||||
#include <QWidget>
|
||||
#include <QListWidget>
|
||||
#include <gnu_java_awt_peer_qt_QtListPeer.h>
|
||||
#include "qtcomponent.h"
|
||||
#include "qtstrings.h"
|
||||
#include "mainthreadinterface.h"
|
||||
#include "slotcallbacks.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 );
|
||||
connectList(list, env, obj);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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) );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
/* 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 <assert.h>
|
||||
#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
|
||||
|
||||
}
|
||||
|
||||
@@ -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 <assert.h>
|
||||
#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.
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 ) );
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
/* 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 <assert.h>
|
||||
#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)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,264 @@
|
||||
/* 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 <assert.h>
|
||||
#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
|
||||
JavaVM *vm;
|
||||
jobject menuPeer;
|
||||
jobject itemPeer;
|
||||
|
||||
public:
|
||||
MenuAction(JNIEnv *env, jobject mp, jobject ip, QMenu *m, QAction *a,
|
||||
bool ismenu) : AWTEvent()
|
||||
{
|
||||
menu = m;
|
||||
action = a;
|
||||
isMenu = ismenu;
|
||||
env->GetJavaVM( &vm );
|
||||
menuPeer = env->NewGlobalRef( mp );
|
||||
if( ip != NULL )
|
||||
itemPeer = env->NewGlobalRef( ip );
|
||||
else
|
||||
itemPeer = NULL;
|
||||
}
|
||||
|
||||
void runEvent()
|
||||
{
|
||||
JNIEnv *env;
|
||||
QAction *newAction; // adding an action creates a new duplicate.
|
||||
vm->GetEnv((void **)&env, JNI_VERSION_1_1);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
jclass menuCls = env->GetObjectClass( menuPeer );
|
||||
jmethodID mid = env->GetMethodID(menuCls, "add", "(J)V");
|
||||
env->CallVoidMethod( menuPeer, mid, (jlong)newAction );
|
||||
|
||||
env->DeleteGlobalRef( menuPeer );
|
||||
if( itemPeer != NULL )
|
||||
{
|
||||
setNativeObject( env, itemPeer, newAction );
|
||||
connectAction(newAction, env, itemPeer);
|
||||
env->DeleteGlobalRef( itemPeer );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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 void JNICALL Java_gnu_java_awt_peer_qt_QtMenuPeer_insertSeperator
|
||||
(JNIEnv *env, jobject obj)
|
||||
{
|
||||
QMenu *menu = (QMenu *)getNativeObject( env, obj );
|
||||
assert( menu );
|
||||
mainThread->postEventToMain( new MenuAction( env, obj, NULL,
|
||||
menu, NULL, ADDSEPA ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* Inserts an item.
|
||||
*/
|
||||
JNIEXPORT void 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 );
|
||||
|
||||
mainThread->postEventToMain( new MenuAction( env, obj, item, menu, action, ADDITEM ));
|
||||
}
|
||||
|
||||
/*
|
||||
* Inserts a sub-menu
|
||||
*/
|
||||
JNIEXPORT void 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 );
|
||||
|
||||
mainThread->postEventToMain( new MenuAction( env, obj, menu, thisMenu, (QAction *)insMenu, ADDMENU ) );
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 ) );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/* 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 <assert.h>
|
||||
#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.h"
|
||||
#undef I_KNOW_WHAT_IM_DOING
|
||||
#undef PARENT
|
||||
};
|
||||
|
||||
/**
|
||||
* Init
|
||||
*/
|
||||
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 );
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/* 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 <assert.h>
|
||||
#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 ) );
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
/* 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 <assert.h>
|
||||
#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();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
/* 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 <assert.h>
|
||||
#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.h"
|
||||
};
|
||||
|
||||
/*
|
||||
* 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 );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
/* 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 <assert.h>
|
||||
#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.h"
|
||||
};
|
||||
|
||||
|
||||
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 );
|
||||
// child->setGeometry( 0, 0, w, h );
|
||||
// child->update();
|
||||
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 ) );
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,197 @@
|
||||
/* 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 <assert.h>
|
||||
#include <time.h>
|
||||
#include <QTextEdit>
|
||||
#include <QTextCursor>
|
||||
#include <gnu_java_awt_peer_qt_QtTextAreaPeer.h>
|
||||
#include "mainthreadinterface.h"
|
||||
#include "componentevent.h"
|
||||
#include "slotcallbacks.h"
|
||||
#include "qtcomponent.h"
|
||||
#include "qtstrings.h"
|
||||
|
||||
class TASetText : public AWTEvent {
|
||||
private:
|
||||
QTextEdit *area;
|
||||
QString *text;
|
||||
|
||||
public:
|
||||
TASetText(QTextEdit *w, QString *t) : AWTEvent()
|
||||
{
|
||||
area = w;
|
||||
text = t;
|
||||
}
|
||||
|
||||
void runEvent()
|
||||
{
|
||||
area->setPlainText( *text );
|
||||
delete text;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* 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 );
|
||||
|
||||
// Connect TextChanged events.
|
||||
connectTextEdit(editor, env, obj);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
mainThread->postEventToMain( new TASetText( editor, 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 );
|
||||
|
||||
QTextCursor curs(editor->document());
|
||||
curs.setPosition(startpos);
|
||||
curs.setPosition(endpos, QTextCursor::KeepAnchor);
|
||||
editor->setTextCursor( curs );
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 );
|
||||
}
|
||||
@@ -0,0 +1,290 @@
|
||||
/* 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 <assert.h>
|
||||
#include <QLineEdit>
|
||||
#include <QWidget>
|
||||
#include <gnu_java_awt_peer_qt_QtTextFieldPeer.h>
|
||||
#include "qtcomponent.h"
|
||||
#include "qtstrings.h"
|
||||
#include "slotcallbacks.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 );
|
||||
connectLineEdit(line, env, obj);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
|
||||
@@ -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 ) );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,347 @@
|
||||
/* 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 <assert.h>
|
||||
#include <QPixmap>
|
||||
#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
|
||||
|
||||
QPixmap *getQtVolatileImage( JNIEnv *env, jobject obj )
|
||||
{
|
||||
jclass cls = env->GetObjectClass( obj );
|
||||
jfieldID field = env->GetFieldID( cls, "nativeObject", "J" );
|
||||
return (QPixmap *)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 );
|
||||
}
|
||||
|
||||
/*
|
||||
* Clears the image to zero.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_clear
|
||||
(JNIEnv *env, jobject obj)
|
||||
{
|
||||
QPixmap *image = getQtVolatileImage(env, obj);
|
||||
assert( image );
|
||||
image->fill();
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the pixel data in an int array.
|
||||
*/
|
||||
JNIEXPORT jintArray JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_getPixels
|
||||
(JNIEnv *env, jobject obj)
|
||||
{
|
||||
QPixmap *image = getQtVolatileImage(env, obj);
|
||||
jintArray result_array;
|
||||
jint *result_array_ptr, *dst;
|
||||
int x, y;
|
||||
jint pixel;
|
||||
QRgb current;
|
||||
|
||||
assert( image );
|
||||
QImage im = image->toImage();
|
||||
|
||||
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 = im.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);
|
||||
|
||||
QPixmap *image = new QPixmap ( width, height );
|
||||
setNativePtr(env, obj, image);
|
||||
}
|
||||
|
||||
/*
|
||||
* Frees the image data.
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_freeImage
|
||||
(JNIEnv *env, jobject obj)
|
||||
{
|
||||
QPixmap *image = getQtVolatileImage(env, obj);
|
||||
if ( image )
|
||||
delete image;
|
||||
setNativePtr(env, obj, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Blits a QImage
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_blit__Lgnu_java_awt_peer_qt_QtImage_2
|
||||
(JNIEnv *env, jobject obj, jobject i2)
|
||||
{
|
||||
QPixmap *image = getQtVolatileImage(env, obj);
|
||||
assert( image );
|
||||
|
||||
QImage *blit = getQtImage(env, i2);
|
||||
assert( blit );
|
||||
|
||||
QPainter *p = new QPainter( image );
|
||||
assert( p );
|
||||
p->drawImage( 0, 0, *blit );
|
||||
|
||||
delete p;
|
||||
}
|
||||
|
||||
/*
|
||||
* Blits a QImage
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtVolatileImage_blit__Lgnu_java_awt_peer_qt_QtImage_2IIII
|
||||
(JNIEnv *env, jobject obj, jobject i2, jint x, jint y, jint w, jint h)
|
||||
{
|
||||
QPixmap *image = getQtVolatileImage(env, obj);
|
||||
assert( image );
|
||||
|
||||
QImage *blit = getQtImage(env, i2);
|
||||
assert( blit );
|
||||
|
||||
QPainter *p = new QPainter( image );
|
||||
assert( p );
|
||||
p->drawImage( x, y, *blit, x, y, w, h);
|
||||
|
||||
delete p;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
QPixmap *ip = getQtVolatileImage(env, src);
|
||||
assert( ip );
|
||||
QImage image = ip->toImage();
|
||||
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)
|
||||
{
|
||||
QPixmap *image = getQtVolatileImage(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->drawPixmap ( 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)
|
||||
{
|
||||
QPixmap *image = getQtVolatileImage(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->drawPixmap( *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)
|
||||
{
|
||||
QPixmap *originalImage = getQtVolatileImage(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->toImage().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)
|
||||
{
|
||||
QPixmap *originalImage = getQtVolatileImage(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);
|
||||
|
||||
if(composite == JNI_TRUE)
|
||||
painter->fillRect( *dstRect, QColor(bg_red, bg_green, bg_blue ) );
|
||||
|
||||
if( flipx == JNI_TRUE || flipy == JNI_TRUE )
|
||||
{
|
||||
QImage im = originalImage->toImage().mirrored ( (flipx == JNI_TRUE),
|
||||
(flipy == JNI_TRUE) );
|
||||
painter->drawImage ( *dstRect, im, *srcRect);
|
||||
}
|
||||
else
|
||||
painter->drawPixmap ( *dstRect, *originalImage, *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)
|
||||
{
|
||||
QPixmap *image = getQtVolatileImage(env, obj);
|
||||
assert( image );
|
||||
|
||||
// FIXME
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
/* 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 <assert.h>
|
||||
#include <QWidget>
|
||||
#include <qstyle.h>
|
||||
#include <gnu_java_awt_peer_qt_QtWindowPeer.h>
|
||||
#include "qtcomponent.h"
|
||||
#include "keybindings.h"
|
||||
#include "qtstrings.h"
|
||||
#include "containers.h"
|
||||
#include "mainthreadinterface.h"
|
||||
|
||||
/*
|
||||
* Our QMainWindow subclass
|
||||
*/
|
||||
class MyWindow : public QWidget
|
||||
{
|
||||
public:
|
||||
MyWindow(JNIEnv *env, jobject obj) : QWidget(0, (Qt::Window | Qt::FramelessWindowHint))
|
||||
{
|
||||
setup(env, obj);
|
||||
}
|
||||
|
||||
~MyWindow()
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
#define I_KNOW_WHAT_IM_DOING
|
||||
#define PARENT QWidget
|
||||
#include "eventmethods.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 MyWindow(env, obj);
|
||||
assert( window );
|
||||
// Qt::WStyle_StaysOnTop
|
||||
setNativeObject( env, obj, 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 ) );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,256 @@
|
||||
/* 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 <QListWidget>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QTextEdit>
|
||||
#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.
|
||||
QListWidget *lw; // used only by the listitemclicked 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 = getAEKeyModifiers( 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 );
|
||||
}
|
||||
|
||||
// Used for List and Choice
|
||||
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 textChanged()
|
||||
{
|
||||
JNIEnv *env;
|
||||
vm->GetEnv((void **)&env, JNI_VERSION_1_1);
|
||||
componentCls = env->GetObjectClass( target );
|
||||
fireEventID = env->GetMethodID( componentCls,
|
||||
"textChanged",
|
||||
"()V" );
|
||||
env->CallVoidMethod( target, fireEventID );
|
||||
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 );
|
||||
}
|
||||
|
||||
void listItemClicked( QListWidgetItem * item )
|
||||
{
|
||||
int index = lw->row( item );
|
||||
JNIEnv *env;
|
||||
vm->GetEnv((void **)&env, JNI_VERSION_1_1);
|
||||
componentCls = env->GetObjectClass( target );
|
||||
fireEventID = env->GetMethodID( componentCls,
|
||||
"itemDoubleClicked",
|
||||
"(II)V" );
|
||||
int modifiers = getAEKeyModifiers( QApplication::keyboardModifiers() );
|
||||
env->CallVoidMethod( target, fireEventID, index, modifiers );
|
||||
env->DeleteLocalRef( componentCls );
|
||||
}
|
||||
};
|
||||
|
||||
#include "slotcallbacks.moc.h"
|
||||
|
||||
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 connectList(QListWidget *list, JNIEnv *env, jobject listobj)
|
||||
{
|
||||
SlotCallback *scb = new SlotCallback(env, listobj);
|
||||
scb->lw = list;
|
||||
QObject::connect( list, SIGNAL( currentRowChanged(int) ),
|
||||
scb, SLOT( choiceActivated(int) ) );
|
||||
QObject::connect( list, SIGNAL( itemDoubleClicked( QListWidgetItem * )),
|
||||
scb, SLOT( listItemClicked( QListWidgetItem * )));
|
||||
}
|
||||
|
||||
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) ) );
|
||||
}
|
||||
|
||||
void connectTextEdit(QTextEdit *edit, JNIEnv *env, jobject obj)
|
||||
{
|
||||
SlotCallback *scb = new SlotCallback(env, obj);
|
||||
QObject::connect( edit, SIGNAL( textChanged() ),
|
||||
scb, SLOT( textChanged() ) );
|
||||
}
|
||||
|
||||
void connectLineEdit(QLineEdit *edit, JNIEnv *env, jobject obj)
|
||||
{
|
||||
SlotCallback *scb = new SlotCallback(env, obj);
|
||||
QObject::connect( edit, SIGNAL(textChanged( QString ) ),
|
||||
scb, SLOT( textChanged() ) );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef SLOTCALLBACKS_H
|
||||
#define SLOTCALLBACKS_H
|
||||
|
||||
#include <QAbstractButton>
|
||||
#include <QAbstractSlider>
|
||||
#include <QAction>
|
||||
#include <QComboBox>
|
||||
#include <QListWidget>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QScrollBar>
|
||||
#include <QTextEdit>
|
||||
#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);
|
||||
void connectList(QListWidget *list, JNIEnv *env, jobject choiceobj);
|
||||
void connectTextEdit(QTextEdit *edit, JNIEnv *env, jobject obj);
|
||||
void connectLineEdit(QLineEdit *edit, JNIEnv *env, jobject obj);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user