40 |
#include <QTextEdit> |
#include <QTextEdit> |
41 |
#include <QTextCursor> |
#include <QTextCursor> |
42 |
#include <gnu_java_awt_peer_qt_QtTextAreaPeer.h> |
#include <gnu_java_awt_peer_qt_QtTextAreaPeer.h> |
43 |
|
#include "mainthreadinterface.h" |
44 |
|
#include "componentevent.h" |
45 |
|
#include "slotcallbacks.h" |
46 |
#include "qtcomponent.h" |
#include "qtcomponent.h" |
47 |
#include "qtstrings.h" |
#include "qtstrings.h" |
48 |
|
|
49 |
// FIXME: This stuff ain't thread safe. |
class TASetText : public AWTEvent { |
50 |
|
private: |
51 |
|
QTextEdit *area; |
52 |
|
QString *text; |
53 |
|
|
54 |
|
public: |
55 |
|
TASetText(QTextEdit *w, QString *t) : AWTEvent() |
56 |
|
{ |
57 |
|
area = w; |
58 |
|
text = t; |
59 |
|
} |
60 |
|
|
61 |
|
void runEvent() |
62 |
|
{ |
63 |
|
area->setPlainText( *text ); |
64 |
|
delete text; |
65 |
|
} |
66 |
|
}; |
67 |
|
|
68 |
/* |
/* |
69 |
* Construct a QTextEdit object |
* Construct a QTextEdit object |
78 |
assert( editor ); |
assert( editor ); |
79 |
|
|
80 |
// setLineWrapColumnOrWidth ( int w ); |
// setLineWrapColumnOrWidth ( int w ); |
|
|
|
81 |
setNativeObject( env, obj, editor ); |
setNativeObject( env, obj, editor ); |
82 |
|
|
83 |
|
// Connect TextChanged events. |
84 |
|
connectTextEdit(editor, env, obj); |
85 |
} |
} |
86 |
|
|
87 |
/* |
/* |
146 |
} |
} |
147 |
|
|
148 |
/* |
/* |
|
* Inserts text. |
|
|
*/ |
|
|
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_insert |
|
|
(JNIEnv *env, jobject obj, jstring str, jint index) |
|
|
{ |
|
|
QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj ); |
|
|
assert( editor ); |
|
|
|
|
|
QTextCursor curs = editor->textCursor(); |
|
|
int oldPos = curs.position(); |
|
|
curs.setPosition( index ); |
|
|
QString *qStr = getQString(env, str); |
|
|
curs.insertText( *qStr ); |
|
|
delete qStr; |
|
|
curs.setPosition( oldPos ); |
|
|
} |
|
|
|
|
|
/* |
|
149 |
* Sets the editor text. |
* Sets the editor text. |
150 |
*/ |
*/ |
151 |
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_setText |
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_setText |
155 |
assert( editor ); |
assert( editor ); |
156 |
|
|
157 |
QString *qStr = getQString(env, str); |
QString *qStr = getQString(env, str); |
158 |
editor->setPlainText( *qStr ); |
mainThread->postEventToMain( new TASetText( editor, qStr ) ); |
|
delete qStr; |
|
159 |
} |
} |
160 |
|
|
161 |
/* |
/* |
166 |
{ |
{ |
167 |
QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj ); |
QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj ); |
168 |
assert( editor ); |
assert( editor ); |
169 |
// FIXME |
|
170 |
// QTextCursor curs = editor->textCursor(); |
QTextCursor curs(editor->document()); |
171 |
// editor->setSelection ( 0, startpos, 0, endpos ); |
curs.setPosition(startpos); |
172 |
|
curs.setPosition(endpos, QTextCursor::KeepAnchor); |
173 |
|
editor->setTextCursor( curs ); |
174 |
} |
} |
175 |
|
|
176 |
/* |
/* |