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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
/* qtlistpeer.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 <assert.h>
39
#include <QWidget>
40
#include <QListWidget>
41
#include <gnu_java_awt_peer_qt_QtListPeer.h>
42
#include "qtcomponent.h"
43
#include "qtstrings.h"
44
#include "mainthreadinterface.h"
45
#include "slotcallbacks.h"
46
 
47
class ListInsert : public AWTEvent {
48
 
49
 private:
50
  QListWidget *widget;
51
  QString *string;
52
  int index;
53
 
54
 public:
55
  ListInsert(QListWidget *w, QString *s, int i) : AWTEvent()
56
  {
57
    widget = w;
58
    string = s;
59
    index = i;
60
  }
61
 
62
  void runEvent()
63
  {
64
    widget->insertItem( index, *string );
65
    delete string;
66
  }
67
};
68
 
69
class SelectEvent : public AWTEvent {
70
 
71
 private:
72
  QListWidget *widget;
73
  int index;
74
  bool selected;
75
 
76
 public:
77
  SelectEvent(QListWidget *w, int i, bool s) : AWTEvent()
78
  {
79
    widget = w;
80
    index = i;
81
    selected = s;
82
  }
83
 
84
  void runEvent()
85
  {
86
    widget->setItemSelected ( widget->item(index), selected );
87
  }
88
};
89
 
90
class ListDelete : public AWTEvent {
91
 
92
 private:
93
  QListWidget *widget;
94
  int startIndex, endIndex;
95
 
96
 public:
97
  ListDelete(QListWidget *w, int starti, int endi) : AWTEvent()
98
  {
99
    widget = w;
100
    startIndex = starti;
101
    endIndex = endi;
102
  }
103
 
104
  void runEvent()
105
  {
106
    for (int i = endIndex; i >= startIndex; i--)
107
      delete widget->takeItem(i);
108
  }
109
};
110
 
111
/*
112
 * Construct a QListWidget object
113
 */
114
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_init
115
(JNIEnv *env, jobject obj)
116
{
117
  QWidget *parentWidget = (QWidget *)getParentWidget(env, obj);
118
  assert( parentWidget );
119
  QListWidget *list = new QListWidget( parentWidget );
120
  assert( list );
121
 
122
  setNativeObject( env, obj, list );
123
  connectList(list, env, obj);
124
}
125
 
126
/*
127
 * Adds an element.
128
 */
129
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_add
130
(JNIEnv *env, jobject obj, jstring str, jint index)
131
{
132
  QListWidget *list = (QListWidget *) getNativeObject( env, obj );
133
  assert( list );
134
  QString *qStr = getQString(env, str);
135
  mainThread->postEventToMain( new ListInsert(list, qStr, index) );
136
}
137
 
138
/*
139
 * Delete items
140
 */
141
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_delItems
142
(JNIEnv *env, jobject obj, jint startindex, jint endindex)
143
{
144
  QListWidget *list = (QListWidget *) getNativeObject( env, obj );
145
  assert( list );
146
  mainThread->postEventToMain( new ListDelete(list, startindex, endindex) );
147
}
148
 
149
/*
150
 * (De)select an element.
151
 */
152
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_select
153
(JNIEnv *env, jobject obj, jint index, jboolean sel)
154
{
155
  QListWidget *list = (QListWidget *) getNativeObject( env, obj );
156
  assert( list );
157
 
158
  mainThread->postEventToMain( new SelectEvent(list, index,
159
                                               (sel == JNI_TRUE)) );
160
}
161
 
162
/**
163
 * Returns the indices of the selected items.
164
 */
165
JNIEXPORT jintArray JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_getSelectedIndexes
166
  (JNIEnv *env, jobject obj)
167
{
168
  jintArray retArray;
169
  jint *arr;
170
 
171
  QListWidget *list = (QListWidget *) getNativeObject( env, obj );
172
  assert( list );
173
 
174
  QList<QListWidgetItem *> items = list->selectedItems();
175
  retArray = env->NewIntArray( items.count() );
176
  arr = env->GetIntArrayElements( retArray, NULL );
177
 
178
  for(int i = 0; i < items.count(); i++)
179
    arr[i] = list->row(items.at(i));
180
 
181
  env->ReleaseIntArrayElements( retArray, arr, 0 );
182
  return retArray;
183
}
184
 
185
/*
186
 * Sets the current item and makes it visible.
187
 */
188
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_makeVisible
189
  (JNIEnv *env, jobject obj, jint index)
190
{
191
 
192
  QListWidget *list = (QListWidget *) getNativeObject( env, obj );
193
  assert( list );
194
 
195
  list->scrollToItem( list->item(index) );
196
}
197
 
198
/*
199
 * Set multiple selection mode.
200
 */
201
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtListPeer_setMultipleMode
202
(JNIEnv *env, jobject obj, jboolean allow)
203
{
204
  QListWidget *list = (QListWidget *) getNativeObject( env, obj );
205
  assert( list );
206
 
207
  // FIXME: Multiple selection is buggy in Qt4. Workaround needed.
208
  list->setSelectionMode( ((allow == JNI_TRUE) ? QAbstractItemView::MultiSelection : QAbstractItemView::SingleSelection) );
209
}
210
 

powered by: WebSVN 2.1.0

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