123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- #include <assert.h>
- #include <time.h>
- #include <QTextEdit>
- #include <QTextCursor>
- #include <gnu_java_awt_peer_qt_QtTextAreaPeer.h>
- #include "mainthreadinterface.h"
- #include "componentevent.h"
- #include "slotcallbacks.h"
- #include "qtcomponent.h"
- #include "qtstrings.h"
- class TASetText : public AWTEvent {
- private:
- QTextEdit *area;
- QString *text;
- public:
- TASetText(QTextEdit *w, QString *t) : AWTEvent()
- {
- area = w;
- text = t;
- }
- void runEvent()
- {
- area->setPlainText( *text );
- delete text;
- }
- };
- JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_init
- (JNIEnv *env, jobject obj)
- {
- QWidget *parentWidget = (QWidget *)getParentWidget( env, obj );
- assert( parentWidget );
- QTextEdit *editor = new QTextEdit( parentWidget );
- editor->setGeometry( 0, 0, 400, 400 );
- assert( editor );
-
- setNativeObject( env, obj, editor );
-
- connectTextEdit(editor, env, obj);
- }
- JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_getCaretPosition
- (JNIEnv *env, jobject obj)
- {
- int index;
-
- QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
- assert( editor );
- index = editor->textCursor().position();;
- return (jint)index;
- }
- JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_getIndexAtPoint
- (JNIEnv *env, jobject obj, jint x, jint y)
- {
- QPoint *p = new QPoint(x,y);
-
- QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
- assert( editor );
- QTextCursor curs = editor->cursorForPosition( *p );
- delete p;
- return curs.position();
- }
- JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_getSelection
- (JNIEnv *env, jobject obj, jboolean isStart)
- {
- int start, end;
-
- QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
- assert( editor );
- start = editor->textCursor().selectionStart();
- end = editor->textCursor().selectionEnd();
- return ((isStart == JNI_TRUE) ? start : end);
- }
- JNIEXPORT jstring JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_getText
- (JNIEnv *env, jobject obj)
- {
- QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
- assert( editor );
- QString text = editor->toPlainText();
- return getJavaString(env, &text);
- }
- JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_setText
- (JNIEnv *env, jobject obj, jstring str)
- {
- QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
- assert( editor );
- QString *qStr = getQString(env, str);
- mainThread->postEventToMain( new TASetText( editor, qStr ) );
- }
- JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_select
- (JNIEnv *env, jobject obj, jint startpos, jint endpos)
- {
- QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
- assert( editor );
- QTextCursor curs(editor->document());
- curs.setPosition(startpos);
- curs.setPosition(endpos, QTextCursor::KeepAnchor);
- editor->setTextCursor( curs );
- }
- JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_setEditable
- (JNIEnv *env, jobject obj, jboolean editable)
- {
- QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
- assert( editor );
- editor->setReadOnly( (editable != JNI_TRUE) );
- }
- JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_setCaretPosition
- (JNIEnv *env, jobject obj, jint index)
- {
- QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
- assert( editor );
- editor->textCursor().setPosition( index );
- }
|