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)
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. */
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
{
53 TFEchoChar(QLineEdit
*w
, jchar ch
) : AWTEvent()
61 line
->setEchoMode( (c
) ? QLineEdit::Password
: QLineEdit::Normal
);
65 class TFEditable
: public AWTEvent
{
71 TFEditable(QLineEdit
*w
, bool e
) : AWTEvent()
79 line
->setReadOnly( editable
);
83 class TFSetText
: public AWTEvent
{
89 TFSetText(QLineEdit
*w
, QString
*t
) : AWTEvent()
97 line
->setText( *text
);
102 class TFSetCursorPos
: public AWTEvent
{
108 TFSetCursorPos(QLineEdit
*w
, int p
) : AWTEvent()
116 line
->setCursorPosition(pos
);
120 class TFSelect
: public AWTEvent
{
126 TFSelect(QLineEdit
*w
, int s
, int e
) : AWTEvent()
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
);
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
);
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
);
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
);
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
);
207 mainThread
->postEventToMain( new TFEditable( line
, (edit
!= JNI_TRUE
) ) );
213 JNIEXPORT jstring JNICALL Java_gnu_java_awt_peer_qt_QtTextFieldPeer_getText
214 (JNIEnv
*env
, jobject obj
)
216 QLineEdit
*line
= (QLineEdit
*) getNativeObject( env
, obj
);
218 QString text
= line
->text();
220 return getJavaString(env
, &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
);
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
)
244 QLineEdit
*line
= (QLineEdit
*) getNativeObject( env
, obj
);
246 index
= line
->selectionStart();
248 if(start
== JNI_TRUE
)
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
);
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
);
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
);
288 return line
->cursorPosition();