1 /* slotcallbacks.cpp --
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 #include <QAbstractButton>
40 #include <QAbstractSlider>
43 #include <QListWidget>
45 #include <QPushButton>
47 #include <gnu_java_awt_peer_qt_QtButtonPeer.h>
48 #include "qtcomponent.h"
49 #include "qtstrings.h"
50 #include "keybindings.h"
51 #include "buttonevent.h"
52 #include "slotcallbacks.h"
54 // AdjustmentEvent constants
55 #define UNIT_INCREMENT 1
56 #define UNIT_DECREMENT 2
57 #define BLOCK_DECREMENT 3
58 #define BLOCK_INCREMENT 4
62 class SlotCallback
: public QObject
{
69 jmethodID fireEventID
;
72 QScrollBar
*sb
; // used only by the scrollbar method.
73 QListWidget
*lw
; // used only by the listitemclicked method
75 SlotCallback(JNIEnv
*env
, jobject t
)
79 target
= env
->NewGlobalRef(t
);
85 vm
->GetEnv((void **)&env
, JNI_VERSION_1_1
);
86 env
->DeleteGlobalRef(target
);
94 vm
->GetEnv((void **)&env
, JNI_VERSION_1_1
);
95 componentCls
= env
->GetObjectClass( target
);
96 fireEventID
= env
->GetMethodID( componentCls
,
99 int modifiers
= getAEKeyModifiers( QApplication::keyboardModifiers() );
100 env
->CallVoidMethod( target
, fireEventID
, modifiers
);
101 env
->DeleteLocalRef( componentCls
);
104 void buttonToggled(bool checked
)
107 vm
->GetEnv((void **)&env
, JNI_VERSION_1_1
);
108 componentCls
= env
->GetObjectClass( target
);
109 fireEventID
= env
->GetMethodID( componentCls
,
113 env
->CallVoidMethod( target
, fireEventID
, JNI_TRUE
);
115 env
->CallVoidMethod( target
, fireEventID
, JNI_FALSE
);
116 env
->DeleteLocalRef( componentCls
);
119 // Used for List and Choice
120 void choiceActivated( int index
)
123 vm
->GetEnv((void **)&env
, JNI_VERSION_1_1
);
124 componentCls
= env
->GetObjectClass( target
);
125 fireEventID
= env
->GetMethodID( componentCls
,
128 env
->CallVoidMethod( target
, fireEventID
, (jint
)index
);
129 env
->DeleteLocalRef( componentCls
);
135 vm
->GetEnv((void **)&env
, JNI_VERSION_1_1
);
136 componentCls
= env
->GetObjectClass( target
);
137 fireEventID
= env
->GetMethodID( componentCls
,
140 env
->CallVoidMethod( target
, fireEventID
);
141 env
->DeleteLocalRef( componentCls
);
144 void scrollBarAction( int action
)
151 case QAbstractSlider::SliderNoAction
:
153 case QAbstractSlider::SliderSingleStepAdd
:
154 type
= UNIT_INCREMENT
;
156 case QAbstractSlider::SliderSingleStepSub
:
157 type
= UNIT_DECREMENT
;
159 case QAbstractSlider::SliderPageStepAdd
:
160 type
= BLOCK_INCREMENT
;
162 case QAbstractSlider::SliderPageStepSub
:
163 type
= BLOCK_DECREMENT
;
165 case QAbstractSlider::SliderToMinimum
:
168 case QAbstractSlider::SliderToMaximum
:
171 case QAbstractSlider::SliderMove
:
176 vm
->GetEnv((void **)&env
, JNI_VERSION_1_1
);
177 componentCls
= env
->GetObjectClass( target
);
178 fireEventID
= env
->GetMethodID( componentCls
,
181 env
->CallVoidMethod( target
, fireEventID
, (jint
)type
, (jint
)index
);
182 env
->DeleteLocalRef( componentCls
);
185 void listItemClicked( QListWidgetItem
* item
)
187 int index
= lw
->row( item
);
189 vm
->GetEnv((void **)&env
, JNI_VERSION_1_1
);
190 componentCls
= env
->GetObjectClass( target
);
191 fireEventID
= env
->GetMethodID( componentCls
,
194 int modifiers
= getAEKeyModifiers( QApplication::keyboardModifiers() );
195 env
->CallVoidMethod( target
, fireEventID
, index
, modifiers
);
196 env
->DeleteLocalRef( componentCls
);
200 #include "slotcallbacks.moc.h"
202 void connectButton(QPushButton
*button
, JNIEnv
*env
, jobject buttonobj
)
204 SlotCallback
*scb
= new SlotCallback(env
, buttonobj
);
205 QObject::connect( button
, SIGNAL( clicked() ), scb
, SLOT( buttonClicked() ) );
208 void connectChoice(QComboBox
*choice
, JNIEnv
*env
, jobject choiceobj
)
210 SlotCallback
*scb
= new SlotCallback(env
, choiceobj
);
211 QObject::connect( choice
, SIGNAL( activated(int) ), scb
, SLOT( choiceActivated(int) ) );
214 void connectList(QListWidget
*list
, JNIEnv
*env
, jobject listobj
)
216 SlotCallback
*scb
= new SlotCallback(env
, listobj
);
218 QObject::connect( list
, SIGNAL( currentRowChanged(int) ),
219 scb
, SLOT( choiceActivated(int) ) );
220 QObject::connect( list
, SIGNAL( itemDoubleClicked( QListWidgetItem
* )),
221 scb
, SLOT( listItemClicked( QListWidgetItem
* )));
224 void connectAction(QAction
*action
, JNIEnv
*env
, jobject obj
)
226 SlotCallback
*scb
= new SlotCallback(env
, obj
);
227 QObject::connect( action
, SIGNAL( triggered() ), scb
, SLOT( buttonClicked() ) );
230 void connectToggle(QAbstractButton
*action
, JNIEnv
*env
, jobject obj
)
232 SlotCallback
*scb
= new SlotCallback(env
, obj
);
233 QObject::connect( action
, SIGNAL( toggled(bool) ), scb
, SLOT( buttonToggled(bool) ) );
236 void connectScrollBar(QScrollBar
*scroll
, JNIEnv
*env
, jobject obj
)
238 SlotCallback
*scb
= new SlotCallback(env
, obj
);
240 QObject::connect( scroll
, SIGNAL( actionTriggered(int) ), scb
, SLOT( scrollBarAction(int) ) );
243 void connectTextEdit(QTextEdit
*edit
, JNIEnv
*env
, jobject obj
)
245 SlotCallback
*scb
= new SlotCallback(env
, obj
);
246 QObject::connect( edit
, SIGNAL( textChanged() ),
247 scb
, SLOT( textChanged() ) );
250 void connectLineEdit(QLineEdit
*edit
, JNIEnv
*env
, jobject obj
)
252 SlotCallback
*scb
= new SlotCallback(env
, obj
);
253 QObject::connect( edit
, SIGNAL(textChanged( QString
) ),
254 scb
, SLOT( textChanged() ) );