diff options
Diffstat (limited to 'native/jni/qt-peer')
26 files changed, 603 insertions, 96 deletions
diff --git a/native/jni/qt-peer/eventmethods.h b/native/jni/qt-peer/eventmethods.h new file mode 100644 index 000000000..deb578480 --- /dev/null +++ b/native/jni/qt-peer/eventmethods.h @@ -0,0 +1,240 @@ +/* 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; + clickCount = 0; + modifiers = getMouseModifiers(e); + x = e->x(); + y = e->y(); + callMouseMethod("mouseReleaseEvent", modifiers, x, y, clickCount); + } + + void moveEvent( QMoveEvent *e ) + { + PARENT::moveEvent(e); + callVoidMethod("moveEvent"); + } + + void resizeEvent( QResizeEvent *e ) + { + PARENT::resizeEvent(e); + callMouseMethod("resizeEvent", + e->oldSize().width(), e->oldSize().height(), + e->size().width(), e->size().height()); + } + + void hideEvent( QHideEvent *e ) + { + PARENT::hideEvent(e); + callVoidMethod("hideEvent"); + } + + void showEvent( QShowEvent *e ) + { + PARENT::showEvent(e); + callVoidMethod("showEvent"); + } + + void paintEvent ( QPaintEvent * e ) + { + PARENT::paintEvent( e ); + if ( draw ) + { + // Create a QPainter + GraphicsPainter painter( this ); + + // Get the environment. + JNIEnv *env; + vm->GetEnv((void **)&env, JNI_VERSION_1_1); + + // create a QtGraphics wrapper for the QPainter + jclass cls = env->FindClass( "gnu/java/awt/peer/qt/QtComponentGraphics" ); + jmethodID mid = env->GetMethodID(cls, "<init>", "(JLgnu/java/awt/peer/qt/QtComponentPeer;)V"); + jobject graphics = env->NewObject(cls, mid, (jlong)&painter, target); + + // call QtComponentPeer.paintEvent() + jmethodID paintEventID = env->GetMethodID( componentCls, + "paint", + "(Ljava/awt/Graphics;)V" ); + env->CallVoidMethod( target, paintEventID, graphics ); + env->DeleteLocalRef( cls ); + env->DeleteLocalRef( graphics ); + painter.end(); + } + } + +#endif diff --git a/native/jni/qt-peer/keybindings.cpp b/native/jni/qt-peer/keybindings.cpp index ff2a8a461..ec2d3f3f0 100644 --- a/native/jni/qt-peer/keybindings.cpp +++ b/native/jni/qt-peer/keybindings.cpp @@ -501,6 +501,9 @@ int getUnicode(QKeyEvent *key) return (int)c.unicode(); } +/** + * Returns the key modifiers in KeyEvent format + */ int getKeyModifiers(Qt::KeyboardModifiers state) { int modifier = 0; @@ -516,10 +519,31 @@ int getKeyModifiers(Qt::KeyboardModifiers state) 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 buttons = e->button(); int state = e->modifiers(); if( buttons & Qt::LeftButton ) diff --git a/native/jni/qt-peer/keybindings.h b/native/jni/qt-peer/keybindings.h index 02ff894bd..f509c8c62 100644 --- a/native/jni/qt-peer/keybindings.h +++ b/native/jni/qt-peer/keybindings.h @@ -13,6 +13,7 @@ int mapKeyCode(QKeyEvent *key); int getUnicode(QKeyEvent *key); int getKeyModifiers(Qt::KeyboardModifiers state); +int getAEKeyModifiers(Qt::KeyboardModifiers state); int getMouseModifiers(QMouseEvent *event); #endif diff --git a/native/jni/qt-peer/qtbuttonpeer.cpp b/native/jni/qt-peer/qtbuttonpeer.cpp index 6ec90e2c4..b807ed466 100644 --- a/native/jni/qt-peer/qtbuttonpeer.cpp +++ b/native/jni/qt-peer/qtbuttonpeer.cpp @@ -61,7 +61,7 @@ public: } #define I_KNOW_WHAT_IM_DOING #define PARENT QPushButton -#include "eventmethods.cpp" +#include "eventmethods.h" }; /** diff --git a/native/jni/qt-peer/qtcanvaspeer.cpp b/native/jni/qt-peer/qtcanvaspeer.cpp index 1d3fcb338..9cdbaef8a 100644 --- a/native/jni/qt-peer/qtcanvaspeer.cpp +++ b/native/jni/qt-peer/qtcanvaspeer.cpp @@ -57,7 +57,7 @@ public: #define I_KNOW_WHAT_IM_DOING #define PARENT QWidget -#include "eventmethods.cpp" +#include "eventmethods.h" }; /* diff --git a/native/jni/qt-peer/qtcheckboxpeer.cpp b/native/jni/qt-peer/qtcheckboxpeer.cpp index 46329cb43..c7bbe5511 100644 --- a/native/jni/qt-peer/qtcheckboxpeer.cpp +++ b/native/jni/qt-peer/qtcheckboxpeer.cpp @@ -81,7 +81,7 @@ public: #define I_KNOW_WHAT_IM_DOING #define PARENT QCheckBox -#include "eventmethods.cpp" +#include "eventmethods.h" }; /** diff --git a/native/jni/qt-peer/qtchoicepeer.cpp b/native/jni/qt-peer/qtchoicepeer.cpp index 2a194cdf5..f77d3a0cf 100644 --- a/native/jni/qt-peer/qtchoicepeer.cpp +++ b/native/jni/qt-peer/qtchoicepeer.cpp @@ -89,7 +89,6 @@ class RemoveSelectEvent : public AWTEvent { } }; - /* * Constructs tha QComboBox object */ diff --git a/native/jni/qt-peer/qtcomponent.cpp b/native/jni/qt-peer/qtcomponent.cpp index d9ddd7e20..fc7480091 100644 --- a/native/jni/qt-peer/qtcomponent.cpp +++ b/native/jni/qt-peer/qtcomponent.cpp @@ -49,10 +49,10 @@ exception statement from your version. */ */ void *getParentWidget( JNIEnv *env, jobject qtcomponentpeer ) { - jclass componentCls = env->FindClass( COMPONENT_CLASS ); + 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; diff --git a/native/jni/qt-peer/qtcomponentpeer.cpp b/native/jni/qt-peer/qtcomponentpeer.cpp index 931423644..c940574fa 100644 --- a/native/jni/qt-peer/qtcomponentpeer.cpp +++ b/native/jni/qt-peer/qtcomponentpeer.cpp @@ -82,7 +82,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtComponentPeer_callInit env->MonitorEnter( obj ); p = getNativeObject(env, obj); env->MonitorExit( obj ); - } while( p == NULL); + } while( p == NULL ); } /* diff --git a/native/jni/qt-peer/qtdialogpeer.cpp b/native/jni/qt-peer/qtdialogpeer.cpp index e3ec88111..0eb709443 100644 --- a/native/jni/qt-peer/qtdialogpeer.cpp +++ b/native/jni/qt-peer/qtdialogpeer.cpp @@ -59,7 +59,7 @@ public: #define I_KNOW_WHAT_IM_DOING #define PARENT QDialog -#include "eventmethods.cpp" +#include "eventmethods.h" }; class DialogSettingsEvent : public AWTEvent { diff --git a/native/jni/qt-peer/qtembeddedwindowpeer.cpp b/native/jni/qt-peer/qtembeddedwindowpeer.cpp new file mode 100644 index 000000000..dbbf87ea4 --- /dev/null +++ b/native/jni/qt-peer/qtembeddedwindowpeer.cpp @@ -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 ) ); +} + diff --git a/native/jni/qt-peer/qtframepeer.cpp b/native/jni/qt-peer/qtframepeer.cpp index 9005311b0..e4060c684 100644 --- a/native/jni/qt-peer/qtframepeer.cpp +++ b/native/jni/qt-peer/qtframepeer.cpp @@ -68,7 +68,7 @@ public: #define I_KNOW_WHAT_IM_DOING #define PARENT QMainWindow -#include "eventmethods.cpp" +#include "eventmethods.h" }; /** @@ -104,10 +104,10 @@ class FrameGetMenuHeightEvent : public AWTEvent { private: QMainWindow *frame; - int *value; + int **value; public: - FrameGetMenuHeightEvent(QMainWindow *w, int *v) : AWTEvent() + FrameGetMenuHeightEvent(QMainWindow *w, int **v) : AWTEvent() { frame = w; value = v; @@ -117,13 +117,8 @@ public: { QMenuBar *mb = frame->menuBar(); assert( mb ); - int v; - if( mb->isVisible() ) - v = mb->size().height(); - - if(v <= 0 || v >= 0xFFFFF ) // Work around for strange values. - v = MenuSizeDefault; - + int *v = (int *)malloc( sizeof( int ) ); + *v = mb->sizeHint().height(); *value = v; } }; @@ -139,11 +134,14 @@ QWidget *frameChildWidget( JNIEnv *env, jobject component ) "getPeer", "()Ljava/awt/peer/ComponentPeer;" ); assert(getPeerMID); - jobject framepeerobj = env->CallObjectMethod( component, getPeerMID, 0); - QMainWindow *window = (QMainWindow *)getNativeObject(env, framepeerobj); + jobject framepeerobj = env->CallObjectMethod( component, getPeerMID, 0); + if( framepeerobj == NULL ) + return (QWidget *)NULL; - return window->centralWidget(); + MyWindow *window = (MyWindow *)getNativeObject(env, framepeerobj); + assert( window ); + return window; } /* @@ -158,7 +156,6 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtFramePeer_init QWidget *central = new QWidget( frame ); assert( central ); - frame->setCentralWidget( central ); setNativeObject( env, obj, frame ); } @@ -171,13 +168,13 @@ JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtFramePeer_menuBarHeight QMainWindow *frame = (QMainWindow *) getNativeObject( env, obj ); assert( frame ); - int value = 0; + int *value = NULL; mainThread->postEventToMain( new FrameGetMenuHeightEvent( frame, &value ) ); - while(value == 0); // (Busy) wait for the value to + while(value == NULL); // (Busy) wait for the value to // get set by the main thread. - return (jint)value; + return (jint)(*value); } /* diff --git a/native/jni/qt-peer/qtgraphics.cpp b/native/jni/qt-peer/qtgraphics.cpp index 1abcc9f08..502cbedf8 100644 --- a/native/jni/qt-peer/qtgraphics.cpp +++ b/native/jni/qt-peer/qtgraphics.cpp @@ -119,6 +119,9 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_initImage painter->setRenderHint(QPainter::TextAntialiasing); } +/** + * Deletes the QPainter + */ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_delete (JNIEnv *env, jobject obj) { @@ -132,19 +135,6 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_delete } } -JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_dispose -(JNIEnv *env, jobject obj) -{ -// GraphicsPainter *painter = (GraphicsPainter *)getPainter( env, obj ); -// setNativePtr( env, obj, NULL ); -// if( painter ) -// { -// if( painter->isActive() ) -// painter->end(); -// delete painter; -// } -} - /////////////////////////////////////////////////////////// /* * Sets the clip to a path. @@ -412,11 +402,6 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_setNativeComposite painter->setCompositionMode( mode ); } -JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtGraphics_getFontMetrics -(JNIEnv *env, jobject obj, jobject font) -{ -} - /** * Sets the current brush to a linear gradient. */ diff --git a/native/jni/qt-peer/qtimage.cpp b/native/jni/qt-peer/qtimage.cpp index 778ab5af8..4d2b5b90a 100644 --- a/native/jni/qt-peer/qtimage.cpp +++ b/native/jni/qt-peer/qtimage.cpp @@ -292,10 +292,9 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtImage_drawPixels 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 ) ); + QColor(bg_red, bg_green, bg_blue ) ); painter->drawImage ( QPoint(x, y), *image ); } @@ -371,8 +370,13 @@ Java_gnu_java_awt_peer_qt_QtImage_drawPixelsScaledFlipped QRectF *dstRect = new QRectF((qreal)dstx, (qreal)dsty, (qreal)dstwidth, (qreal)dstheight); - QImage image = originalImage->mirrored ( (flipx == JNI_TRUE), - (flipy == JNI_TRUE) ); + 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 ) ); diff --git a/native/jni/qt-peer/qtlabelpeer.cpp b/native/jni/qt-peer/qtlabelpeer.cpp index 895994e80..196f0cdd5 100644 --- a/native/jni/qt-peer/qtlabelpeer.cpp +++ b/native/jni/qt-peer/qtlabelpeer.cpp @@ -64,7 +64,7 @@ public: #define I_KNOW_WHAT_IM_DOING #define PARENT QLabel -#include "eventmethods.cpp" +#include "eventmethods.h" }; class LabelTitle : public AWTEvent { @@ -103,7 +103,6 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtLabelPeer_init (JNIEnv *env, jobject obj) { QWidget *parentWidget = (QWidget *) getParentWidget( env, obj ); - // QLabel *label = new QLabel( parentWidget ); QLabel *label = new MyLabel( env, obj, parentWidget ); assert( label ); setNativeObject( env, obj, label ); diff --git a/native/jni/qt-peer/qtlistpeer.cpp b/native/jni/qt-peer/qtlistpeer.cpp index b702d7bca..027d47880 100644 --- a/native/jni/qt-peer/qtlistpeer.cpp +++ b/native/jni/qt-peer/qtlistpeer.cpp @@ -42,6 +42,7 @@ exception statement from your version. */ #include "qtcomponent.h" #include "qtstrings.h" #include "mainthreadinterface.h" +#include "slotcallbacks.h" class ListInsert : public AWTEvent { @@ -119,6 +120,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_init assert( list ); setNativeObject( env, obj, list ); + connectList(list, env, obj); } /* diff --git a/native/jni/qt-peer/qtmenupeer.cpp b/native/jni/qt-peer/qtmenupeer.cpp index 568074b17..fc8b0a5d6 100644 --- a/native/jni/qt-peer/qtmenupeer.cpp +++ b/native/jni/qt-peer/qtmenupeer.cpp @@ -104,7 +104,7 @@ public: *newAction = menu->addAction(action->text()); (*newAction)->setSeparator(action->isSeparator()); (*newAction)->setCheckable(action->isCheckable()); - delete action; + // delete action; break; case ADDSEPA: *newAction = menu->addSeparator(); diff --git a/native/jni/qt-peer/qtpanelpeer.cpp b/native/jni/qt-peer/qtpanelpeer.cpp index 41ee1a28c..68aef4864 100644 --- a/native/jni/qt-peer/qtpanelpeer.cpp +++ b/native/jni/qt-peer/qtpanelpeer.cpp @@ -56,11 +56,14 @@ public: #define I_KNOW_WHAT_IM_DOING #define PARENT QWidget -#include "eventmethods.cpp" +#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) { diff --git a/native/jni/qt-peer/qtscrollbarpeer.cpp b/native/jni/qt-peer/qtscrollbarpeer.cpp index 1af3db7fc..0649ebd17 100644 --- a/native/jni/qt-peer/qtscrollbarpeer.cpp +++ b/native/jni/qt-peer/qtscrollbarpeer.cpp @@ -61,7 +61,7 @@ public: #define I_KNOW_WHAT_IM_DOING #define PARENT QScrollBar -#include "eventmethods.cpp" +#include "eventmethods.h" }; /* diff --git a/native/jni/qt-peer/qtscrollpanepeer.cpp b/native/jni/qt-peer/qtscrollpanepeer.cpp index 417c182a3..246155cdf 100644 --- a/native/jni/qt-peer/qtscrollpanepeer.cpp +++ b/native/jni/qt-peer/qtscrollpanepeer.cpp @@ -66,7 +66,7 @@ public: #define I_KNOW_WHAT_IM_DOING #define PARENT QScrollArea -#include "eventmethods.cpp" +#include "eventmethods.h" }; @@ -128,9 +128,12 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtScrollPanePeer_childResized { QScrollArea *view = (QScrollArea *) getNativeObject( env, obj ); assert( view ); + printf("XXX: child size: %i %i\n", w, h); QWidget *child = view->viewport(); assert( child ); + // child->setGeometry( 0, 0, w, h ); +// child->update(); mainThread->postEventToMain( new AWTResizeEvent(child, 0, 0, w, h) ); } diff --git a/native/jni/qt-peer/qttextareapeer.cpp b/native/jni/qt-peer/qttextareapeer.cpp index ceb3847da..50f85b861 100644 --- a/native/jni/qt-peer/qttextareapeer.cpp +++ b/native/jni/qt-peer/qttextareapeer.cpp @@ -40,10 +40,30 @@ exception statement from your version. */ #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" -// FIXME: This stuff ain't thread safe. +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 @@ -58,8 +78,10 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_init assert( editor ); // setLineWrapColumnOrWidth ( int w ); - setNativeObject( env, obj, editor ); + + // Connect TextChanged events. + connectTextEdit(editor, env, obj); } /* @@ -124,24 +146,6 @@ JNIEXPORT jstring JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_getText } /* - * Inserts text. - */ -JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_insert -(JNIEnv *env, jobject obj, jstring str, jint index) -{ - QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj ); - assert( editor ); - - QTextCursor curs = editor->textCursor(); - int oldPos = curs.position(); - curs.setPosition( index ); - QString *qStr = getQString(env, str); - curs.insertText( *qStr ); - delete qStr; - curs.setPosition( oldPos ); -} - -/* * Sets the editor text. */ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_setText @@ -151,8 +155,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_setText assert( editor ); QString *qStr = getQString(env, str); - editor->setPlainText( *qStr ); - delete qStr; + mainThread->postEventToMain( new TASetText( editor, qStr ) ); } /* @@ -163,9 +166,11 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_select { QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj ); assert( editor ); - // FIXME -// QTextCursor curs = editor->textCursor(); -// editor->setSelection ( 0, startpos, 0, endpos ); + + QTextCursor curs(editor->document()); + curs.setPosition(startpos); + curs.setPosition(endpos, QTextCursor::KeepAnchor); + editor->setTextCursor( curs ); } /* diff --git a/native/jni/qt-peer/qttextfieldpeer.cpp b/native/jni/qt-peer/qttextfieldpeer.cpp index da128fb41..5c7113379 100644 --- a/native/jni/qt-peer/qttextfieldpeer.cpp +++ b/native/jni/qt-peer/qttextfieldpeer.cpp @@ -41,6 +41,7 @@ exception statement from your version. */ #include <gnu_java_awt_peer_qt_QtTextFieldPeer.h> #include "qtcomponent.h" #include "qtstrings.h" +#include "slotcallbacks.h" #include "mainthreadinterface.h" class TFEchoChar : public AWTEvent { @@ -147,6 +148,7 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_init assert( line ); setNativeObject( env, obj, line ); + connectLineEdit(line, env, obj); } diff --git a/native/jni/qt-peer/qtwindowpeer.cpp b/native/jni/qt-peer/qtwindowpeer.cpp index 8257051e0..4808ac3be 100644 --- a/native/jni/qt-peer/qtwindowpeer.cpp +++ b/native/jni/qt-peer/qtwindowpeer.cpp @@ -99,19 +99,6 @@ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtWindowPeer_init } /* - * Destructor - */ -JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtWindowPeer_destroy -(JNIEnv *env, jobject obj) -{ - QWidget *window = (QWidget *) getNativeObject( env, obj ); - assert( window ); - - setNativeObject(env, obj, NULL); - delete window; -} - -/* * Lower the window. */ JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtWindowPeer_toBack diff --git a/native/jni/qt-peer/slotcallbacks.cpp b/native/jni/qt-peer/slotcallbacks.cpp index 38a22b16a..3e0820477 100644 --- a/native/jni/qt-peer/slotcallbacks.cpp +++ b/native/jni/qt-peer/slotcallbacks.cpp @@ -40,7 +40,10 @@ exception statement from your version. */ #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" @@ -67,6 +70,7 @@ private: public: QScrollBar *sb; // used only by the scrollbar method. + QListWidget *lw; // used only by the listitemclicked method SlotCallback(JNIEnv *env, jobject t) { @@ -82,7 +86,8 @@ public: env->DeleteGlobalRef(target); } -public slots: + public slots: + void buttonClicked() { JNIEnv *env; @@ -91,7 +96,7 @@ public slots: fireEventID = env->GetMethodID( componentCls, "fireClick", "(I)V" ); - int modifiers = getKeyModifiers( QApplication::keyboardModifiers() ); + int modifiers = getAEKeyModifiers( QApplication::keyboardModifiers() ); env->CallVoidMethod( target, fireEventID, modifiers ); env->DeleteLocalRef( componentCls ); } @@ -110,7 +115,8 @@ public slots: env->CallVoidMethod( target, fireEventID, JNI_FALSE ); env->DeleteLocalRef( componentCls ); } - + + // Used for List and Choice void choiceActivated( int index ) { JNIEnv *env; @@ -123,6 +129,18 @@ public slots: 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; @@ -163,9 +181,23 @@ public slots: 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" +#include "slotcallbacks.moc.h" void connectButton(QPushButton *button, JNIEnv *env, jobject buttonobj) { @@ -179,6 +211,16 @@ void connectChoice(QComboBox *choice, JNIEnv *env, jobject 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); @@ -197,3 +239,18 @@ void connectScrollBar(QScrollBar *scroll, JNIEnv *env, jobject 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() ) ); +} + diff --git a/native/jni/qt-peer/slotcallbacks.h b/native/jni/qt-peer/slotcallbacks.h index 3929bde7a..88c292ce7 100644 --- a/native/jni/qt-peer/slotcallbacks.h +++ b/native/jni/qt-peer/slotcallbacks.h @@ -5,8 +5,11 @@ #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); @@ -14,5 +17,8 @@ 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 diff --git a/native/jni/qt-peer/slotcallbacks.moc.h b/native/jni/qt-peer/slotcallbacks.moc.h new file mode 100644 index 000000000..dd69e1f6c --- /dev/null +++ b/native/jni/qt-peer/slotcallbacks.moc.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** Meta object code from reading C++ file 'slotcallbacks.cpp' +** +** Created: Tue Aug 16 00:30:30 2005 +** by: The Qt Meta Object Compiler version 58 (Qt 4.0.0) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#if !defined(Q_MOC_OUTPUT_REVISION) +#error "The header file 'slotcallbacks.cpp' doesn't include <QObject>." +#elif Q_MOC_OUTPUT_REVISION != 58 +#error "This file was generated using the moc from 4.0.0. It" +#error "cannot be used with the include files from this version of Qt." +#error "(The moc has changed too much.)" +#endif + +static const uint qt_meta_data_SlotCallback[] = { + + // content: + 1, // revision + 0, // classname + 0, 0, // classinfo + 6, 10, // methods + 0, 0, // properties + 0, 0, // enums/sets + + // slots: signature, parameters, type, tag, flags + 14, 13, 13, 13, 0x0a, + 38, 30, 13, 13, 0x0a, + 64, 58, 13, 13, 0x0a, + 85, 13, 13, 13, 0x0a, + 106, 99, 13, 13, 0x0a, + 132, 127, 13, 13, 0x0a, + + 0 // eod +}; + +static const char qt_meta_stringdata_SlotCallback[] = { + "SlotCallback\0\0buttonClicked()\0checked\0buttonToggled(bool)\0index\0" + "choiceActivated(int)\0textChanged()\0action\0scrollBarAction(int)\0item\0" + "listItemClicked(QListWidgetItem*)\0" +}; + +const QMetaObject SlotCallback::staticMetaObject = { + { &QObject::staticMetaObject, qt_meta_stringdata_SlotCallback, + qt_meta_data_SlotCallback, 0 } +}; + +const QMetaObject *SlotCallback::metaObject() const +{ + return &staticMetaObject; +} + +void *SlotCallback::qt_metacast(const char *_clname) +{ + if (!_clname) return 0; + if (!strcmp(_clname, qt_meta_stringdata_SlotCallback)) + return static_cast<void*>(const_cast<SlotCallback*>(this)); + return QObject::qt_metacast(_clname); +} + +int SlotCallback::qt_metacall(QMetaObject::Call _c, int _id, void **_a) +{ + _id = QObject::qt_metacall(_c, _id, _a); + if (_id < 0) + return _id; + if (_c == QMetaObject::InvokeMetaMethod) { + switch (_id) { + case 0: buttonClicked(); break; + case 1: buttonToggled(*(bool*)_a[1]); break; + case 2: choiceActivated(*(int*)_a[1]); break; + case 3: textChanged(); break; + case 4: scrollBarAction(*(int*)_a[1]); break; + case 5: listItemClicked(*(QListWidgetItem**)_a[1]); break; + } + _id -= 6; + } + return _id; +} |