]>
Commit | Line | Data |
---|---|---|
5aac1dac | 1 | /* gtktextareapeer.c -- Native implementation of GtkTextAreaPeer |
85fa3bde | 2 | Copyright (C) 1998, 1999, 2003 Free Software Foundation, Inc. |
5aac1dac TT |
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., 59 Temple Place, Suite 330, Boston, MA | |
19 | 02111-1307 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 | ||
39 | #include "gtkpeer.h" | |
40 | #include "gnu_java_awt_peer_gtk_GtkTextAreaPeer.h" | |
41 | ||
29e531ff | 42 | #define TEXT_FROM_SW(obj) (GTK_TEXT_VIEW(GTK_SCROLLED_WINDOW (obj)->container.child)) |
5aac1dac TT |
43 | JNIEXPORT void JNICALL |
44 | Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_create | |
9e2c04c5 TF |
45 | (JNIEnv *env, jobject obj, |
46 | jint textview_width, jint textview_height, jint scroll) | |
5aac1dac TT |
47 | { |
48 | GtkWidget *text, *sw; | |
49 | ||
7ecd4576 FN |
50 | /* Create global reference and save it for future use */ |
51 | NSA_SET_GLOBAL_REF (env, obj); | |
d0b8b6fb | 52 | |
7ecd4576 | 53 | gdk_threads_enter (); |
9e2c04c5 | 54 | |
29e531ff | 55 | text = gtk_text_view_new (); |
9e2c04c5 | 56 | gtk_widget_set_size_request (text, textview_width, textview_height); |
5aac1dac TT |
57 | gtk_widget_show (text); |
58 | ||
59 | sw = gtk_scrolled_window_new (NULL, NULL); | |
60 | gtk_container_add (GTK_CONTAINER (sw), text); | |
61 | ||
ff4cc28b | 62 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), |
5aac1dac TT |
63 | /* horizontal scrollbar */ |
64 | (scroll == AWT_TEXTAREA_SCROLLBARS_BOTH | |
65 | || scroll == AWT_TEXTAREA_SCROLLBARS_HORIZONTAL_ONLY) ? | |
66 | GTK_POLICY_ALWAYS : GTK_POLICY_NEVER, | |
5aac1dac TT |
67 | /* vertical scrollbar */ |
68 | (scroll == AWT_TEXTAREA_SCROLLBARS_BOTH | |
69 | || scroll == AWT_TEXTAREA_SCROLLBARS_VERTICAL_ONLY) ? | |
70 | GTK_POLICY_ALWAYS : GTK_POLICY_NEVER); | |
5aac1dac | 71 | |
85fa3bde KH |
72 | gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text), |
73 | (scroll == AWT_TEXTAREA_SCROLLBARS_BOTH | |
74 | || scroll == AWT_TEXTAREA_SCROLLBARS_HORIZONTAL_ONLY) | |
75 | ? GTK_WRAP_NONE : GTK_WRAP_WORD); | |
54ab3303 | 76 | |
5aac1dac TT |
77 | gdk_threads_leave (); |
78 | ||
5aac1dac TT |
79 | NSA_SET_PTR (env, obj, sw); |
80 | } | |
81 | ||
5aac1dac TT |
82 | JNIEXPORT void JNICALL |
83 | Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_insert | |
84 | (JNIEnv *env, jobject obj, jstring contents, jint position) | |
85 | { | |
29e531ff TF |
86 | GtkTextBuffer *buf; |
87 | GtkTextIter iter; | |
88 | GtkWidget *text; | |
5aac1dac TT |
89 | void *ptr; |
90 | const char *str; | |
91 | int pos=position; | |
92 | ||
93 | ptr = NSA_GET_PTR (env, obj); | |
94 | str = (*env)->GetStringUTFChars (env, contents, NULL); | |
95 | ||
96 | gdk_threads_enter (); | |
29e531ff TF |
97 | |
98 | text = GTK_WIDGET (TEXT_FROM_SW (ptr)); | |
99 | ||
100 | buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); | |
101 | gtk_text_buffer_get_iter_at_offset (buf, &iter, pos); | |
102 | gtk_text_buffer_insert (buf, &iter, str, strlen (str)); | |
103 | ||
5aac1dac TT |
104 | gdk_threads_leave (); |
105 | ||
106 | (*env)->ReleaseStringUTFChars (env, contents, str); | |
107 | } | |
108 | ||
109 | JNIEXPORT void JNICALL | |
110 | Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_replaceRange | |
111 | (JNIEnv *env, jobject obj, jstring contents, jint start, jint end) | |
112 | { | |
29e531ff TF |
113 | GtkWidget *text; |
114 | GtkTextBuffer *buf; | |
115 | GtkTextIter iter, startIter, endIter; | |
5aac1dac | 116 | void *ptr; |
5aac1dac | 117 | const char *str; |
29e531ff TF |
118 | int mystart = start; |
119 | int myend = end; | |
5aac1dac TT |
120 | |
121 | ptr = NSA_GET_PTR (env, obj); | |
122 | str = (*env)->GetStringUTFChars (env, contents, NULL); | |
123 | ||
124 | gdk_threads_enter (); | |
125 | ||
29e531ff TF |
126 | text = GTK_WIDGET (TEXT_FROM_SW (ptr)); |
127 | ||
128 | buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text)); | |
129 | ||
130 | gtk_text_buffer_get_iter_at_offset (buf, &startIter, mystart); | |
131 | gtk_text_buffer_get_iter_at_offset (buf, &endIter, myend); | |
132 | gtk_text_buffer_delete (buf, &startIter, &endIter); | |
133 | ||
134 | gtk_text_buffer_get_iter_at_offset (buf, &iter, mystart); | |
135 | gtk_text_buffer_insert(buf, &iter, str, strlen (str)); | |
5aac1dac TT |
136 | |
137 | gdk_threads_leave (); | |
138 | (*env)->ReleaseStringUTFChars (env, contents, str); | |
139 | } | |
140 | ||
d0b8b6fb | 141 | JNIEXPORT void JNICALL |
56bba8cf | 142 | Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_gtkSetFont |
a5586c38 | 143 | (JNIEnv *env, jobject obj, jstring name, jint style, jint size) |
56bba8cf | 144 | { |
29e531ff | 145 | const char *font_name; |
56bba8cf | 146 | void *ptr; |
29e531ff TF |
147 | GtkWidget *text; |
148 | PangoFontDescription *font_desc; | |
56bba8cf HB |
149 | |
150 | ptr = NSA_GET_PTR (env, obj); | |
d0b8b6fb | 151 | |
56bba8cf | 152 | text = GTK_WIDGET (TEXT_FROM_SW (ptr)); |
5596e92f | 153 | |
a5586c38 | 154 | font_name = (*env)->GetStringUTFChars (env, name, NULL); |
29e531ff | 155 | |
56bba8cf | 156 | gdk_threads_enter(); |
29e531ff TF |
157 | |
158 | font_desc = pango_font_description_from_string (font_name); | |
5596e92f TF |
159 | pango_font_description_set_size (font_desc, size * PANGO_SCALE); |
160 | ||
a5586c38 TF |
161 | if (style & AWT_STYLE_BOLD) |
162 | pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); | |
163 | ||
164 | if (style & AWT_STYLE_ITALIC) | |
165 | pango_font_description_set_style (font_desc, PANGO_STYLE_OBLIQUE); | |
166 | ||
c5d2de6b | 167 | gtk_widget_modify_font (GTK_WIDGET (text), font_desc); |
5596e92f | 168 | |
29e531ff | 169 | pango_font_description_free (font_desc); |
5596e92f | 170 | |
56bba8cf | 171 | gdk_threads_leave(); |
29e531ff | 172 | |
a5586c38 | 173 | (*env)->ReleaseStringUTFChars (env, name, font_name); |
56bba8cf | 174 | } |
9e2c04c5 | 175 | |
c5d2de6b GH |
176 | JNIEXPORT void JNICALL |
177 | Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_gtkWidgetRequestFocus | |
178 | (JNIEnv *env, jobject obj) | |
179 | { | |
180 | void *ptr; | |
181 | GtkWidget *text; | |
182 | ||
183 | ptr = NSA_GET_PTR (env, obj); | |
184 | ||
185 | gdk_threads_enter (); | |
186 | ||
187 | text = GTK_WIDGET (TEXT_FROM_SW (ptr)); | |
188 | ||
189 | gtk_widget_grab_focus (text); | |
190 | ||
191 | gdk_threads_leave (); | |
192 | } | |
193 | ||
9e2c04c5 TF |
194 | JNIEXPORT jint JNICALL |
195 | Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_getHScrollbarHeight | |
196 | (JNIEnv *env, jobject obj) | |
197 | { | |
198 | void *ptr; | |
199 | GtkScrolledWindow *sw; | |
200 | GtkRequisition requisition; | |
201 | jint height = 0; | |
202 | jint spacing = 0; | |
203 | ||
204 | ptr = NSA_GET_PTR (env, obj); | |
205 | ||
206 | gdk_threads_enter (); | |
207 | sw = GTK_SCROLLED_WINDOW (ptr); | |
208 | ||
edb3d426 MW |
209 | if (sw) |
210 | { | |
211 | gtk_widget_size_request (sw->hscrollbar, &requisition); | |
212 | gtk_widget_style_get (GTK_WIDGET (sw), "scrollbar_spacing", &spacing, NULL); | |
213 | height = requisition.height + spacing; | |
214 | } | |
9e2c04c5 TF |
215 | |
216 | gdk_threads_leave (); | |
217 | ||
218 | return height; | |
219 | } | |
220 | ||
221 | JNIEXPORT jint JNICALL | |
222 | Java_gnu_java_awt_peer_gtk_GtkTextAreaPeer_getVScrollbarWidth | |
223 | (JNIEnv *env, jobject obj) | |
224 | { | |
225 | void *ptr; | |
226 | GtkScrolledWindow *sw; | |
227 | GtkRequisition requisition; | |
228 | jint width = 0; | |
229 | jint spacing = 0; | |
230 | ||
231 | ptr = NSA_GET_PTR (env, obj); | |
232 | ||
233 | gdk_threads_enter (); | |
234 | sw = GTK_SCROLLED_WINDOW (ptr); | |
235 | ||
edb3d426 MW |
236 | if (sw) |
237 | { | |
238 | gtk_widget_size_request (sw->vscrollbar, &requisition); | |
239 | gtk_widget_style_get (GTK_WIDGET (sw), "scrollbar_spacing", &spacing, NULL); | |
240 | width = requisition.width + spacing; | |
241 | } | |
9e2c04c5 TF |
242 | |
243 | gdk_threads_leave (); | |
244 | ||
245 | return width; | |
246 | } |