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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
/* qttextfieldpeer.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 <QLineEdit>
40
#include <QWidget>
41
#include <gnu_java_awt_peer_qt_QtTextFieldPeer.h>
42
#include "qtcomponent.h"
43
#include "qtstrings.h"
44
#include "slotcallbacks.h"
45
#include "mainthreadinterface.h"
46
 
47
class TFEchoChar : public AWTEvent {
48
 private:
49
  QLineEdit *line;
50
  jchar c;
51
 
52
 public:
53
  TFEchoChar(QLineEdit *w, jchar ch) : AWTEvent()
54
  {
55
    line = w;
56
    c = ch;
57
  }
58
 
59
  void runEvent()
60
  {
61
    line->setEchoMode( (c) ? QLineEdit::Password : QLineEdit::Normal );
62
  }
63
};
64
 
65
class TFEditable : public AWTEvent {
66
 private:
67
  QLineEdit *line;
68
  bool editable;
69
 
70
 public:
71
  TFEditable(QLineEdit *w, bool e) : AWTEvent()
72
  {
73
    line = w;
74
    editable = e;
75
  }
76
 
77
  void runEvent()
78
  {
79
    line->setReadOnly( editable );
80
  }
81
};
82
 
83
class TFSetText : public AWTEvent {
84
 private:
85
  QLineEdit *line;
86
  QString *text;
87
 
88
 public:
89
  TFSetText(QLineEdit *w, QString *t) : AWTEvent()
90
  {
91
    line = w;
92
    text = t;
93
  }
94
 
95
  void runEvent()
96
  {
97
    line->setText( *text );
98
    delete text;
99
  }
100
};
101
 
102
class TFSetCursorPos : public AWTEvent {
103
 private:
104
  QLineEdit *line;
105
  int pos;
106
 
107
 public:
108
  TFSetCursorPos(QLineEdit *w, int p) : AWTEvent()
109
  {
110
    line = w;
111
    pos = p;
112
  }
113
 
114
  void runEvent()
115
  {
116
    line->setCursorPosition(pos);
117
  }
118
};
119
 
120
class TFSelect : public AWTEvent {
121
 private:
122
  QLineEdit *line;
123
  int start,end;
124
 
125
 public:
126
  TFSelect(QLineEdit *w, int s, int e) : AWTEvent()
127
  {
128
    line = w;
129
    start = s;
130
    end = e;
131
  }
132
 
133
  void runEvent()
134
  {
135
    line->setSelection(start, end - start);
136
  }
137
};
138
 
139
 
140
/*
141
 */
142
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_init
143
(JNIEnv *env, jobject obj)
144
{
145
  QWidget *parentWidget = (QWidget *)getParentWidget(env, obj);
146
  assert( parentWidget );
147
  QLineEdit *line = new QLineEdit( parentWidget );
148
  assert( line );
149
 
150
  setNativeObject( env, obj, line );
151
  connectLineEdit(line, env, obj);
152
}
153
 
154
 
155
/*
156
 * Sets the echo char.
157
 */
158
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_setEchoChar
159
(JNIEnv *env, jobject obj, jchar echo)
160
{
161
  QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
162
  assert( line );
163
  mainThread->postEventToMain( new TFEchoChar( line, echo ) );
164
}
165
 
166
/*
167
 */
168
JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getMinimumSizeNative
169
(JNIEnv *env, jobject obj, jint columns)
170
{
171
  QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
172
  assert( line );
173
 
174
  // FIXME does this work?
175
  int old = line->maxLength();
176
  line->setMaxLength(columns);
177
  QSize size = line->minimumSizeHint();
178
  line->setMaxLength(old);
179
 
180
  return makeDimension(env, &size);
181
}
182
 
183
/*
184
 */
185
JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getPreferredSizeNative
186
(JNIEnv *env, jobject obj, jint columns)
187
{
188
  QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
189
  assert( line );
190
 
191
  int old = line->maxLength();
192
  line->setMaxLength(columns);
193
  QSize size = line->sizeHint();
194
  line->setMaxLength(old);
195
 
196
  return makeDimension(env, &size);
197
}
198
 
199
/*
200
 */
201
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_setEditable
202
(JNIEnv *env, jobject obj, jboolean edit)
203
{
204
  QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
205
  assert( line );
206
 
207
  mainThread->postEventToMain( new TFEditable( line, (edit != JNI_TRUE) ) );
208
}
209
 
210
/*
211
 * Gets the text.
212
 */
213
JNIEXPORT jstring JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getText
214
(JNIEnv *env, jobject obj)
215
{
216
  QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
217
  assert( line );
218
  QString text = line->text();
219
 
220
  return getJavaString(env, &text);
221
}
222
 
223
/*
224
 * Sets the text
225
 */
226
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_setText
227
(JNIEnv *env, jobject obj, jstring text)
228
{
229
  QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
230
  assert( line );
231
 
232
  QString *qStr = getQString(env, text);
233
  mainThread->postEventToMain( new TFSetText( line, qStr ) );
234
}
235
 
236
/*
237
 * Returns the start (start = true) or end (start = false) of the selection.
238
 */
239
JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getSelection
240
(JNIEnv *env, jobject obj, jboolean start)
241
{
242
  int index, length;
243
 
244
  QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
245
  assert( line );
246
  index = line->selectionStart();
247
 
248
  if(start == JNI_TRUE)
249
    return index;
250
 
251
  length = (line->selectedText()).length();
252
 
253
  return index + length;
254
}
255
 
256
/*
257
 * Sets the selection.
258
 */
259
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_select
260
(JNIEnv *env, jobject obj, jint start, jint end)
261
{
262
  QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
263
  assert( line );
264
 
265
  mainThread->postEventToMain( new TFSelect( line, start, end ) );
266
}
267
 
268
/*
269
 * Sets the cursor position.
270
 */
271
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_setCaretPosition
272
(JNIEnv *env, jobject obj, jint pos)
273
{
274
  QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
275
  assert( line );
276
  mainThread->postEventToMain( new TFSetCursorPos( line, (int)pos ) );
277
}
278
 
279
/*
280
 * Returns the caret position.
281
 */
282
JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getCaretPosition
283
(JNIEnv *env, jobject obj)
284
{
285
  QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
286
  assert( line );
287
 
288
  return line->cursorPosition();
289
}
290
 

powered by: WebSVN 2.1.0

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