OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [native/] [jni/] [qt-peer/] [slotcallbacks.cpp] - Blame information for rev 774

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
/* slotcallbacks.cpp --
2
   Copyright (C)  2005  Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
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)
9
any later version.
10
 
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.
15
 
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
19
02110-1301 USA.
20
 
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
24
combination.
25
 
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. */
37
 
38
#include <QObject>
39
#include <QAbstractButton>
40
#include <QAbstractSlider>
41
#include <QAction>
42
#include <QComboBox>
43
#include <QListWidget>
44
#include <QLineEdit>
45
#include <QPushButton>
46
#include <QTextEdit>
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"
53
 
54
// AdjustmentEvent constants
55
#define UNIT_INCREMENT   1
56
#define UNIT_DECREMENT   2
57
#define BLOCK_DECREMENT  3
58
#define BLOCK_INCREMENT  4
59
#define TRACK  5
60
 
61
 
62
class SlotCallback : public QObject {
63
  Q_OBJECT;
64
 
65
private:
66
  JavaVM* vm;
67
  jobject target;
68
  jclass componentCls;
69
  jmethodID fireEventID;
70
 
71
public:
72
  QScrollBar *sb; // used only by the scrollbar method.
73
  QListWidget *lw; // used only by the listitemclicked method
74
 
75
  SlotCallback(JNIEnv *env, jobject t)
76
  {
77
    env->GetJavaVM(&vm);
78
    target = t;
79
    target = env->NewGlobalRef(t);
80
  }
81
 
82
  ~SlotCallback()
83
  {
84
    JNIEnv *env;
85
    vm->GetEnv((void **)&env, JNI_VERSION_1_1);
86
    env->DeleteGlobalRef(target);
87
  }
88
 
89
  public slots:
90
 
91
  void buttonClicked()
92
  {
93
    JNIEnv *env;
94
    vm->GetEnv((void **)&env, JNI_VERSION_1_1);
95
    componentCls = env->GetObjectClass( target );
96
    fireEventID = env->GetMethodID( componentCls,
97
                                    "fireClick",
98
                                    "(I)V" );
99
    int modifiers = getAEKeyModifiers( QApplication::keyboardModifiers() );
100
    env->CallVoidMethod( target, fireEventID, modifiers );
101
    env->DeleteLocalRef( componentCls );
102
  }
103
 
104
  void buttonToggled(bool checked)
105
  {
106
    JNIEnv *env;
107
    vm->GetEnv((void **)&env, JNI_VERSION_1_1);
108
    componentCls = env->GetObjectClass( target );
109
    fireEventID = env->GetMethodID( componentCls,
110
                                    "fireToggle",
111
                                    "(Z)V" );
112
    if(checked)
113
      env->CallVoidMethod( target, fireEventID, JNI_TRUE );
114
    else
115
      env->CallVoidMethod( target, fireEventID, JNI_FALSE );
116
    env->DeleteLocalRef( componentCls );
117
  }
118
 
119
  // Used for List and Choice
120
  void choiceActivated( int index )
121
  {
122
    JNIEnv *env;
123
    vm->GetEnv((void **)&env, JNI_VERSION_1_1);
124
    componentCls = env->GetObjectClass( target );
125
    fireEventID = env->GetMethodID( componentCls,
126
                                    "fireChoice",
127
                                    "(I)V" );
128
    env->CallVoidMethod( target, fireEventID, (jint)index );
129
    env->DeleteLocalRef( componentCls );
130
  }
131
 
132
  void textChanged()
133
  {
134
    JNIEnv *env;
135
    vm->GetEnv((void **)&env, JNI_VERSION_1_1);
136
    componentCls = env->GetObjectClass( target );
137
    fireEventID = env->GetMethodID( componentCls,
138
                                    "textChanged",
139
                                    "()V" );
140
    env->CallVoidMethod( target, fireEventID );
141
    env->DeleteLocalRef( componentCls );
142
  }
143
 
144
  void scrollBarAction( int action )
145
  {
146
    JNIEnv *env;
147
    int type;
148
    int index;
149
    switch(action)
150
      {
151
      case QAbstractSlider::SliderNoAction:
152
        return;
153
      case QAbstractSlider::SliderSingleStepAdd:
154
        type = UNIT_INCREMENT;
155
        break;
156
      case QAbstractSlider::SliderSingleStepSub:
157
        type = UNIT_DECREMENT;
158
        break;
159
      case QAbstractSlider::SliderPageStepAdd:
160
        type = BLOCK_INCREMENT;
161
        break;
162
      case QAbstractSlider::SliderPageStepSub:
163
        type = BLOCK_DECREMENT;
164
        break;
165
      case QAbstractSlider::SliderToMinimum:
166
        type = TRACK;
167
        break;
168
      case QAbstractSlider::SliderToMaximum:
169
        type = TRACK;
170
        break;
171
      case QAbstractSlider::SliderMove:
172
        type = TRACK;
173
        break;
174
      }
175
    index = sb->value();
176
    vm->GetEnv((void **)&env, JNI_VERSION_1_1);
177
    componentCls = env->GetObjectClass( target );
178
    fireEventID = env->GetMethodID( componentCls,
179
                                    "fireMoved",
180
                                    "(II)V" );
181
    env->CallVoidMethod( target, fireEventID, (jint)type, (jint)index );
182
    env->DeleteLocalRef( componentCls );
183
  }
184
 
185
  void listItemClicked( QListWidgetItem * item )
186
  {
187
    int index = lw->row( item );
188
    JNIEnv *env;
189
    vm->GetEnv((void **)&env, JNI_VERSION_1_1);
190
    componentCls = env->GetObjectClass( target );
191
    fireEventID = env->GetMethodID( componentCls,
192
                                    "itemDoubleClicked",
193
                                    "(II)V" );
194
    int modifiers = getAEKeyModifiers( QApplication::keyboardModifiers() );
195
    env->CallVoidMethod( target, fireEventID, index, modifiers );
196
    env->DeleteLocalRef( componentCls );
197
  }
198
};
199
 
200
#include "slotcallbacks.moc.h"
201
 
202
void connectButton(QPushButton *button, JNIEnv *env, jobject buttonobj)
203
{
204
  SlotCallback *scb = new SlotCallback(env, buttonobj);
205
  QObject::connect( button, SIGNAL( clicked() ), scb, SLOT( buttonClicked() ) );
206
}
207
 
208
void connectChoice(QComboBox *choice, JNIEnv *env, jobject choiceobj)
209
{
210
  SlotCallback *scb = new SlotCallback(env, choiceobj);
211
  QObject::connect( choice, SIGNAL( activated(int) ), scb, SLOT( choiceActivated(int) ) );
212
}
213
 
214
void connectList(QListWidget *list, JNIEnv *env, jobject listobj)
215
{
216
  SlotCallback *scb = new SlotCallback(env, listobj);
217
  scb->lw = list;
218
  QObject::connect( list, SIGNAL( currentRowChanged(int) ),
219
                    scb, SLOT( choiceActivated(int) ) );
220
  QObject::connect( list, SIGNAL( itemDoubleClicked( QListWidgetItem * )),
221
                    scb, SLOT( listItemClicked( QListWidgetItem * )));
222
}
223
 
224
void connectAction(QAction *action, JNIEnv *env, jobject obj)
225
{
226
  SlotCallback *scb = new SlotCallback(env, obj);
227
  QObject::connect( action, SIGNAL( triggered() ), scb, SLOT( buttonClicked() ) );
228
}
229
 
230
void connectToggle(QAbstractButton *action, JNIEnv *env, jobject obj)
231
{
232
  SlotCallback *scb = new SlotCallback(env, obj);
233
  QObject::connect( action, SIGNAL( toggled(bool) ), scb, SLOT( buttonToggled(bool) ) );
234
}
235
 
236
void connectScrollBar(QScrollBar *scroll, JNIEnv *env, jobject obj)
237
{
238
  SlotCallback *scb = new SlotCallback(env, obj);
239
  scb->sb = scroll;
240
  QObject::connect( scroll, SIGNAL( actionTriggered(int) ), scb, SLOT( scrollBarAction(int) ) );
241
}
242
 
243
void connectTextEdit(QTextEdit *edit, JNIEnv *env, jobject obj)
244
{
245
  SlotCallback *scb = new SlotCallback(env, obj);
246
  QObject::connect( edit, SIGNAL( textChanged() ),
247
                    scb, SLOT( textChanged() ) );
248
}
249
 
250
void connectLineEdit(QLineEdit *edit, JNIEnv *env, jobject obj)
251
{
252
  SlotCallback *scb = new SlotCallback(env, obj);
253
  QObject::connect( edit, SIGNAL(textChanged( QString ) ),
254
                    scb, SLOT( textChanged() ) );
255
}
256
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.