123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- #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 );
- }
- };
- 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 );
- }
- 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 ) );
- }
- 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)));
- }
- 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 ) );
- }
- 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)));
- }
|