Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / native / jni / qt-peer / qttextfieldpeer.cpp
blob5c71133791becbc097184c27ac4c6abdcac51114
1 /* qttextfieldpeer.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)
9 any later version.
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
19 02110-1301 USA.
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.
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. */
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"
47 class TFEchoChar : public AWTEvent {
48 private:
49 QLineEdit *line;
50 jchar c;
52 public:
53 TFEchoChar(QLineEdit *w, jchar ch) : AWTEvent()
55 line = w;
56 c = ch;
59 void runEvent()
61 line->setEchoMode( (c) ? QLineEdit::Password : QLineEdit::Normal );
65 class TFEditable : public AWTEvent {
66 private:
67 QLineEdit *line;
68 bool editable;
70 public:
71 TFEditable(QLineEdit *w, bool e) : AWTEvent()
73 line = w;
74 editable = e;
77 void runEvent()
79 line->setReadOnly( editable );
83 class TFSetText : public AWTEvent {
84 private:
85 QLineEdit *line;
86 QString *text;
88 public:
89 TFSetText(QLineEdit *w, QString *t) : AWTEvent()
91 line = w;
92 text = t;
95 void runEvent()
97 line->setText( *text );
98 delete text;
102 class TFSetCursorPos : public AWTEvent {
103 private:
104 QLineEdit *line;
105 int pos;
107 public:
108 TFSetCursorPos(QLineEdit *w, int p) : AWTEvent()
110 line = w;
111 pos = p;
114 void runEvent()
116 line->setCursorPosition(pos);
120 class TFSelect : public AWTEvent {
121 private:
122 QLineEdit *line;
123 int start,end;
125 public:
126 TFSelect(QLineEdit *w, int s, int e) : AWTEvent()
128 line = w;
129 start = s;
130 end = e;
133 void runEvent()
135 line->setSelection(start, end - start);
142 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_init
143 (JNIEnv *env, jobject obj)
145 QWidget *parentWidget = (QWidget *)getParentWidget(env, obj);
146 assert( parentWidget );
147 QLineEdit *line = new QLineEdit( parentWidget );
148 assert( line );
150 setNativeObject( env, obj, line );
151 connectLineEdit(line, env, obj);
156 * Sets the echo char.
158 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_setEchoChar
159 (JNIEnv *env, jobject obj, jchar echo)
161 QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
162 assert( line );
163 mainThread->postEventToMain( new TFEchoChar( line, echo ) );
168 JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getMinimumSizeNative
169 (JNIEnv *env, jobject obj, jint columns)
171 QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
172 assert( line );
174 // FIXME does this work?
175 int old = line->maxLength();
176 line->setMaxLength(columns);
177 QSize size = line->minimumSizeHint();
178 line->setMaxLength(old);
180 return makeDimension(env, &size);
185 JNIEXPORT jobject JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getPreferredSizeNative
186 (JNIEnv *env, jobject obj, jint columns)
188 QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
189 assert( line );
191 int old = line->maxLength();
192 line->setMaxLength(columns);
193 QSize size = line->sizeHint();
194 line->setMaxLength(old);
196 return makeDimension(env, &size);
201 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_setEditable
202 (JNIEnv *env, jobject obj, jboolean edit)
204 QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
205 assert( line );
207 mainThread->postEventToMain( new TFEditable( line, (edit != JNI_TRUE) ) );
211 * Gets the text.
213 JNIEXPORT jstring JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getText
214 (JNIEnv *env, jobject obj)
216 QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
217 assert( line );
218 QString text = line->text();
220 return getJavaString(env, &text);
224 * Sets the text
226 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_setText
227 (JNIEnv *env, jobject obj, jstring text)
229 QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
230 assert( line );
232 QString *qStr = getQString(env, text);
233 mainThread->postEventToMain( new TFSetText( line, qStr ) );
237 * Returns the start (start = true) or end (start = false) of the selection.
239 JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getSelection
240 (JNIEnv *env, jobject obj, jboolean start)
242 int index, length;
244 QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
245 assert( line );
246 index = line->selectionStart();
248 if(start == JNI_TRUE)
249 return index;
251 length = (line->selectedText()).length();
253 return index + length;
257 * Sets the selection.
259 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_select
260 (JNIEnv *env, jobject obj, jint start, jint end)
262 QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
263 assert( line );
265 mainThread->postEventToMain( new TFSelect( line, start, end ) );
269 * Sets the cursor position.
271 JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_setCaretPosition
272 (JNIEnv *env, jobject obj, jint pos)
274 QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
275 assert( line );
276 mainThread->postEventToMain( new TFSetCursorPos( line, (int)pos ) );
280 * Returns the caret position.
282 JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getCaretPosition
283 (JNIEnv *env, jobject obj)
285 QLineEdit *line = (QLineEdit *) getNativeObject( env, obj );
286 assert( line );
288 return line->cursorPosition();