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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
/* qttextareapeer.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 <time.h>
40
#include <QTextEdit>
41
#include <QTextCursor>
42
#include <gnu_java_awt_peer_qt_QtTextAreaPeer.h>
43
#include "mainthreadinterface.h"
44
#include "componentevent.h"
45
#include "slotcallbacks.h"
46
#include "qtcomponent.h"
47
#include "qtstrings.h"
48
 
49
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
70
 */
71
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_init
72
(JNIEnv *env, jobject obj)
73
{
74
  QWidget *parentWidget = (QWidget *)getParentWidget( env, obj );
75
  assert( parentWidget );
76
  QTextEdit *editor = new QTextEdit( parentWidget );
77
  editor->setGeometry( 0, 0, 400, 400 );
78
  assert( editor );
79
 
80
  //  setLineWrapColumnOrWidth ( int w );
81
  setNativeObject( env, obj, editor );
82
 
83
  // Connect TextChanged events.
84
  connectTextEdit(editor, env, obj);
85
}
86
 
87
/*
88
 * Returns the cursor position.
89
 */
90
JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_getCaretPosition
91
(JNIEnv *env, jobject obj)
92
{
93
  int index;
94
 
95
  QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
96
  assert( editor );
97
 
98
  index = editor->textCursor().position();;
99
 
100
  return (jint)index;
101
}
102
 
103
/*
104
 * Returns the char index at a given screen point
105
 */
106
JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_getIndexAtPoint
107
(JNIEnv *env, jobject obj, jint x, jint y)
108
{
109
  QPoint *p = new QPoint(x,y);
110
 
111
  QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
112
  assert( editor );
113
  QTextCursor curs = editor->cursorForPosition( *p );
114
  delete p;
115
 
116
  return curs.position();
117
}
118
 
119
/*
120
 * Returns the start (start = true) or end (start = false) of the selection.
121
 */
122
JNIEXPORT jint JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_getSelection
123
(JNIEnv *env, jobject obj, jboolean isStart)
124
{
125
  int start, end;
126
 
127
  QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
128
  assert( editor );
129
  start = editor->textCursor().selectionStart();
130
  end =  editor->textCursor().selectionEnd();
131
 
132
  return ((isStart == JNI_TRUE) ? start : end);
133
}
134
 
135
/*
136
 * Returns the text.
137
 */
138
JNIEXPORT jstring JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_getText
139
(JNIEnv *env, jobject obj)
140
{
141
  QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
142
  assert( editor );
143
  QString text = editor->toPlainText();
144
 
145
  return getJavaString(env, &text);
146
}
147
 
148
/*
149
 * Sets the editor text.
150
 */
151
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_setText
152
(JNIEnv *env, jobject obj, jstring str)
153
{
154
  QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
155
  assert( editor );
156
 
157
  QString *qStr = getQString(env, str);
158
  mainThread->postEventToMain( new TASetText( editor, qStr ) );
159
}
160
 
161
/*
162
 * Sets the selection.
163
 */
164
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_select
165
(JNIEnv *env, jobject obj, jint startpos, jint endpos)
166
{
167
  QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
168
  assert( editor );
169
 
170
  QTextCursor curs(editor->document());
171
  curs.setPosition(startpos);
172
  curs.setPosition(endpos, QTextCursor::KeepAnchor);
173
  editor->setTextCursor( curs );
174
}
175
 
176
/*
177
 * Allow or disallow editing.
178
 */
179
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_setEditable
180
(JNIEnv *env, jobject obj, jboolean editable)
181
{
182
  QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
183
  assert( editor );
184
  editor->setReadOnly( (editable != JNI_TRUE) );
185
}
186
 
187
/*
188
 * Sets the cursor position
189
 */
190
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_qt_QtTextAreaPeer_setCaretPosition
191
(JNIEnv *env, jobject obj, jint index)
192
{
193
  QTextEdit *editor = (QTextEdit *) getNativeObject( env, obj );
194
  assert( editor );
195
 
196
  editor->textCursor().setPosition( index );
197
}

powered by: WebSVN 2.1.0

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