1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 #include "gtkeditable.h"
31 #include "gtkmarshalers.h"
36 static void gtk_editable_base_init (gpointer g_class);
40 gtk_editable_get_type (void)
42 static GType editable_type = 0;
46 const GTypeInfo editable_info =
48 sizeof (GtkEditableClass), /* class_size */
49 gtk_editable_base_init, /* base_init */
50 NULL, /* base_finalize */
53 editable_type = g_type_register_static (G_TYPE_INTERFACE, I_("GtkEditable"),
61 gtk_editable_base_init (gpointer g_class)
63 static gboolean initialized = FALSE;
67 g_signal_new (I_("insert-text"),
70 G_STRUCT_OFFSET (GtkEditableClass, insert_text),
72 _gtk_marshal_VOID__STRING_INT_POINTER,
77 g_signal_new (I_("delete-text"),
80 G_STRUCT_OFFSET (GtkEditableClass, delete_text),
82 _gtk_marshal_VOID__INT_INT,
86 g_signal_new (I_("changed"),
89 G_STRUCT_OFFSET (GtkEditableClass, changed),
91 _gtk_marshal_VOID__VOID,
99 * gtk_editable_insert_text:
100 * @editable: a #GtkEditable
101 * @new_text: the text to append
102 * @new_text_length: the length of the text in bytes, or -1
103 * @position: position text will be inserted at
105 * Appends @new_text_length bytes of @new_text to the contents of the widget,
106 * at position @position. Note that this position is in characters, not in bytes.
109 gtk_editable_insert_text (GtkEditable *editable,
110 const gchar *new_text,
111 gint new_text_length,
114 g_return_if_fail (GTK_IS_EDITABLE (editable));
115 g_return_if_fail (position != NULL);
117 if (new_text_length < 0)
118 new_text_length = strlen (new_text);
120 GTK_EDITABLE_GET_CLASS (editable)->do_insert_text (editable, new_text, new_text_length, position);
124 * gtk_editable_delete_text:
125 * @editable: a #GtkEditable
126 * @start_pos: start position
127 * @end_pos: end position
129 * Deletes the content of the editable between @start_pos and @end_pos.
130 * Note that positions are specified in characters, not bytes.
133 gtk_editable_delete_text (GtkEditable *editable,
137 g_return_if_fail (GTK_IS_EDITABLE (editable));
139 GTK_EDITABLE_GET_CLASS (editable)->do_delete_text (editable, start_pos, end_pos);
143 * gtk_editable_get_chars:
144 * @editable: a #GtkEditable
145 * @start: start of text
148 * Retreives the content of the editable between @start and @end.
149 * Note that positions are specified in characters, not bytes.
151 * Return value: a pointer to the contents of the widget as a
152 * string. This string is allocated by the #GtkEditable
153 * implementation and should be freed by the caller.
156 gtk_editable_get_chars (GtkEditable *editable,
160 g_return_val_if_fail (GTK_IS_EDITABLE (editable), NULL);
162 return GTK_EDITABLE_GET_CLASS (editable)->get_chars (editable, start, end);
166 * gtk_editable_set_position:
167 * @editable: a #GtkEditable
168 * @position: the position of the cursor. The cursor is displayed
169 * before the character with the given (base 0) index in the editable.
170 * The value must be less than or equal to the number of characters
171 * in the editable. A value of -1 indicates that the position should
172 * be set after the last character of the editable. Note that this
173 * position is in characters, not in bytes.
175 * Sets the cursor position in the editable to the given value.
178 gtk_editable_set_position (GtkEditable *editable,
181 g_return_if_fail (GTK_IS_EDITABLE (editable));
183 GTK_EDITABLE_GET_CLASS (editable)->set_position (editable, position);
187 * gtk_editable_get_position:
188 * @editable: a #GtkEditable
190 * Retrieves the current position of the cursor relative to the start
191 * of the content of the editable. Note that this position is in characters,
194 * Return value: the cursor position
197 gtk_editable_get_position (GtkEditable *editable)
199 g_return_val_if_fail (GTK_IS_EDITABLE (editable), 0);
201 return GTK_EDITABLE_GET_CLASS (editable)->get_position (editable);
205 * gtk_editable_get_selection_bounds:
206 * @editable: a #GtkEditable
207 * @start_pos: beginning of selection
208 * @end_pos: end of selection
210 * Retrieves the selection bound of the editable. @start_pos will be filled
211 * with the start of the selection and @end_pos with end. If no text was selected
212 * both will be identical and %FALSE will be returned. Note that positions are
213 * specified in characters, not bytes.
215 * Return value: %TRUE if an area is selected, %FALSE otherwise
219 gtk_editable_get_selection_bounds (GtkEditable *editable,
223 gint tmp_start, tmp_end;
226 g_return_val_if_fail (GTK_IS_EDITABLE (editable), FALSE);
228 result = GTK_EDITABLE_GET_CLASS (editable)->get_selection_bounds (editable, &tmp_start, &tmp_end);
231 *start_pos = MIN (tmp_start, tmp_end);
233 *end_pos = MAX (tmp_start, tmp_end);
239 * gtk_editable_delete_selection:
240 * @editable: a #GtkEditable
242 * Deletes the currently selected text of the editable.
243 * This call will not do anything if there is no selected text.
246 gtk_editable_delete_selection (GtkEditable *editable)
250 g_return_if_fail (GTK_IS_EDITABLE (editable));
252 if (gtk_editable_get_selection_bounds (editable, &start, &end))
253 gtk_editable_delete_text (editable, start, end);
257 * gtk_editable_select_region:
258 * @editable: a #GtkEditable
259 * @start: start of region
260 * @end: end of region
262 * Selects the text between @start and @end. Both @start and @end are
263 * relative to the start of the content. Note that positions are specified
264 * in characters, not bytes.
267 gtk_editable_select_region (GtkEditable *editable,
271 g_return_if_fail (GTK_IS_EDITABLE (editable));
273 GTK_EDITABLE_GET_CLASS (editable)->set_selection_bounds (editable, start, end);
277 * gtk_editable_cut_clipboard:
278 * @editable: a #GtkEditable
280 * Removes the contents of the currently selected content in the editable and
281 * puts it on the clipboard.
284 gtk_editable_cut_clipboard (GtkEditable *editable)
286 g_return_if_fail (GTK_IS_EDITABLE (editable));
288 g_signal_emit_by_name (editable, "cut-clipboard");
292 * gtk_editable_copy_clipboard:
293 * @editable: a #GtkEditable
295 * Copies the contents of the currently selected content in the editable and
296 * puts it on the clipboard.
299 gtk_editable_copy_clipboard (GtkEditable *editable)
301 g_return_if_fail (GTK_IS_EDITABLE (editable));
303 g_signal_emit_by_name (editable, "copy-clipboard");
307 * gtk_editable_paste_clipboard:
308 * @editable: a #GtkEditable
310 * Pastes the content of the clipboard to the current position of the
311 * cursor in the editable.
314 gtk_editable_paste_clipboard (GtkEditable *editable)
316 g_return_if_fail (GTK_IS_EDITABLE (editable));
318 g_signal_emit_by_name (editable, "paste-clipboard");
322 * gtk_editable_set_editable:
323 * @editable: a #GtkEditable
324 * @is_editable: %TRUE if the user is allowed to edit the text
327 * Determines if the user can edit the text in the editable
332 gtk_editable_set_editable (GtkEditable *editable,
333 gboolean is_editable)
335 g_return_if_fail (GTK_IS_EDITABLE (editable));
337 g_object_set (editable,
338 "editable", is_editable != FALSE,
343 * gtk_editable_get_editable:
344 * @editable: a #GtkEditable
346 * Retrieves whether @editable is editable. See
347 * gtk_editable_set_editable().
349 * Return value: %TRUE if @editable is editable.
352 gtk_editable_get_editable (GtkEditable *editable)
356 g_return_val_if_fail (GTK_IS_EDITABLE (editable), FALSE);
358 g_object_get (editable, "editable", &value, NULL);
363 #define __GTK_EDITABLE_C__
364 #include "gtkaliasdef.c"