alternative to assert
[gtkD.git] / gtkD / src / gtk / Editable.d
blob606ae2dfdcac567377124b165755abed3c78177d
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD 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
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = GtkEditable.html
26 * outPack = gtk
27 * outFile = Editable
28 * strct = GtkEditable
29 * realStrct=
30 * ctorStrct=
31 * clss = Editable
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - gtk_editable_
40 * - gtk_
41 * omit structs:
42 * omit prefixes:
43 * omit code:
44 * imports:
45 * - glib.Str
46 * structWrap:
47 * module aliases:
48 * local aliases:
51 module gtk.Editable;
53 version(noAssert)
55 version(Tango)
57 import tango.io.Stdout; // use the tango loging?
61 private import gtkc.gtktypes;
63 private import gtkc.gtk;
66 private import glib.Str;
71 /**
72 * Description
73 * The GtkEditable interface is an interface which should be implemented by
74 * text editing widgets, such as GtkEntry and GtkText. It contains functions
75 * for generically manipulating an editable widget, a large number of action
76 * signals used for key bindings, and several signals that an application can
77 * connect to to modify the behavior of a widget.
78 * As an example of the latter usage, by connecting
79 * the following handler to "insert_text", an application
80 * can convert all entry into a widget into uppercase.
81 * Example3.Forcing entry to uppercase.
82 * #include <ctype.h>
83 * void
84 * insert_text_handler (GtkEditable *editable,
85 * const gchar *text,
86 * gint length,
87 * gint *position,
88 * gpointer data)
89 * {
90 * int i;
91 * gchar *result = g_utf8_strup (text, length);
92 * g_signal_handlers_block_by_func (editable,
93 * (gpointer) insert_text_handler, data);
94 * gtk_editable_insert_text (editable, result, length, position);
95 * g_signal_handlers_unblock_by_func (editable,
96 * (gpointer) insert_text_handler, data);
97 * g_signal_stop_emission_by_name (editable, "insert_text");
98 * g_free (result);
99 * }
101 public class Editable
104 /** the main Gtk struct */
105 protected GtkEditable* gtkEditable;
108 public GtkEditable* getEditableStruct()
110 return gtkEditable;
114 /** the main Gtk struct as a void* */
115 protected void* getStruct()
117 return cast(void*)gtkEditable;
121 * Sets our main struct and passes it to the parent class
123 public this (GtkEditable* gtkEditable)
125 version(noAssert)
127 if ( gtkEditable is null )
129 int zero = 0;
130 version(Tango)
132 Stdout("struct gtkEditable is null on constructor").newline;
134 else
136 printf("struct gtkEditable is null on constructor");
138 zero = zero / zero;
141 else
143 assert(gtkEditable !is null, "struct gtkEditable is null on constructor");
145 this.gtkEditable = gtkEditable;
151 // imports for the signal processing
152 private import gobject.Signals;
153 private import gtkc.gdktypes;
154 int[char[]] connectedSignals;
156 void delegate(Editable)[] onChangedListeners;
157 void addOnChanged(void delegate(Editable) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
159 if ( !("changed" in connectedSignals) )
161 Signals.connectData(
162 getStruct(),
163 "changed",
164 cast(GCallback)&callBackChanged,
165 cast(void*)this,
166 null,
167 connectFlags);
168 connectedSignals["changed"] = 1;
170 onChangedListeners ~= dlg;
172 extern(C) static void callBackChanged(GtkEditable* editableStruct, Editable editable)
174 bool consumed = false;
176 foreach ( void delegate(Editable) dlg ; editable.onChangedListeners )
178 dlg(editable);
181 return consumed;
184 void delegate(gint, gint, Editable)[] onDeleteTextListeners;
185 void addOnDeleteText(void delegate(gint, gint, Editable) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
187 if ( !("delete-text" in connectedSignals) )
189 Signals.connectData(
190 getStruct(),
191 "delete-text",
192 cast(GCallback)&callBackDeleteText,
193 cast(void*)this,
194 null,
195 connectFlags);
196 connectedSignals["delete-text"] = 1;
198 onDeleteTextListeners ~= dlg;
200 extern(C) static void callBackDeleteText(GtkEditable* editableStruct, gint startPos, gint endPos, Editable editable)
202 bool consumed = false;
204 foreach ( void delegate(gint, gint, Editable) dlg ; editable.onDeleteTextListeners )
206 dlg(startPos, endPos, editable);
209 return consumed;
212 void delegate(char[], gint, gint*, Editable)[] onInsertTextListeners;
213 void addOnInsertText(void delegate(char[], gint, gint*, Editable) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
215 if ( !("insert-text" in connectedSignals) )
217 Signals.connectData(
218 getStruct(),
219 "insert-text",
220 cast(GCallback)&callBackInsertText,
221 cast(void*)this,
222 null,
223 connectFlags);
224 connectedSignals["insert-text"] = 1;
226 onInsertTextListeners ~= dlg;
228 extern(C) static void callBackInsertText(GtkEditable* editableStruct, gchar* newText, gint newTextLength, gint* position, Editable editable)
230 bool consumed = false;
232 foreach ( void delegate(char[], gint, gint*, Editable) dlg ; editable.onInsertTextListeners )
234 dlg(Str.toString(newText), newTextLength, position, editable);
237 return consumed;
243 * Selects a region of text. The characters that
244 * are selected are those characters at positions from
245 * start_pos up to, but not including end_pos. If
246 * end_pos is negative, then the the characters selected
247 * will be those characters from start_pos to the end
248 * of the text.
249 * editable:
250 * a GtkEditable widget.
251 * start:
252 * the starting position.
253 * end:
254 * the end position.
256 public void selectRegion(int start, int end)
258 // void gtk_editable_select_region (GtkEditable *editable, gint start, gint end);
259 gtk_editable_select_region(gtkEditable, start, end);
263 * Gets the current selection bounds, if there is a selection.
264 * editable:
265 * a GtkEditable widget.
266 * start:
267 * location to store the starting position, or NULL.
268 * end:
269 * location to store the end position, or NULL.
270 * Returns:
271 * TRUE if there is a selection.
273 public int getSelectionBounds(int* start, int* end)
275 // gboolean gtk_editable_get_selection_bounds (GtkEditable *editable, gint *start, gint *end);
276 return gtk_editable_get_selection_bounds(gtkEditable, start, end);
280 * Inserts text at a given position.
281 * editable:
282 * a GtkEditable widget.
283 * new_text:
284 * the text to insert.
285 * new_text_length:
286 * the length of the text to insert, in bytes
287 * position:
288 * an inout parameter. The caller initializes it to
289 * the position at which to insert the text. After the
290 * call it points at the position after the newly
291 * inserted text.
293 public void insertText(char[] newText, int newTextLength, int* position)
295 // void gtk_editable_insert_text (GtkEditable *editable, const gchar *new_text, gint new_text_length, gint *position);
296 gtk_editable_insert_text(gtkEditable, Str.toStringz(newText), newTextLength, position);
300 * Deletes a sequence of characters. The characters that
301 * are deleted are those characters at positions from
302 * start_pos up to, but not including end_pos. If
303 * end_pos is negative, then the the characters deleted
304 * will be those characters from start_pos to the end
305 * of the text.
306 * editable:
307 * a GtkEditable widget.
308 * start_pos:
309 * the starting position.
310 * end_pos:
311 * the end position.
313 public void deleteText(int startPos, int endPos)
315 // void gtk_editable_delete_text (GtkEditable *editable, gint start_pos, gint end_pos);
316 gtk_editable_delete_text(gtkEditable, startPos, endPos);
320 * Retrieves a sequence of characters. The characters that
321 * are retrieved are those characters at positions from
322 * start_pos up to, but not including end_pos. If
323 * end_pos is negative, then the the characters retrieved
324 * will be those characters from start_pos to the end
325 * of the text.
326 * editable:
327 * a GtkEditable widget.
328 * start_pos:
329 * the starting position.
330 * end_pos:
331 * the end position.
332 * Returns:
333 * the characters in the indicated region.
334 * The result must be freed with g_free() when
335 * the application is finished with it.
337 public char[] getChars(int startPos, int endPos)
339 // gchar* gtk_editable_get_chars (GtkEditable *editable, gint start_pos, gint end_pos);
340 return Str.toString(gtk_editable_get_chars(gtkEditable, startPos, endPos) );
344 * Causes the characters in the current selection to
345 * be copied to the clipboard and then deleted from
346 * the widget.
347 * editable:
348 * a GtkEditable widget.
350 public void cutClipboard()
352 // void gtk_editable_cut_clipboard (GtkEditable *editable);
353 gtk_editable_cut_clipboard(gtkEditable);
357 * Causes the characters in the current selection to
358 * be copied to the clipboard.
359 * editable:
360 * a GtkEditable widget.
362 public void copyClipboard()
364 // void gtk_editable_copy_clipboard (GtkEditable *editable);
365 gtk_editable_copy_clipboard(gtkEditable);
369 * Causes the contents of the clipboard to be pasted into
370 * the given widget at the current cursor position.
371 * editable:
372 * a GtkEditable widget.
374 public void pasteClipboard()
376 // void gtk_editable_paste_clipboard (GtkEditable *editable);
377 gtk_editable_paste_clipboard(gtkEditable);
381 * Deletes the current contents of the widgets selection and
382 * disclaims the selection.
383 * editable:
384 * a GtkEditable widget.
386 public void deleteSelection()
388 // void gtk_editable_delete_selection (GtkEditable *editable);
389 gtk_editable_delete_selection(gtkEditable);
393 * Sets the cursor position.
394 * editable:
395 * a GtkEditable widget.
396 * position:
397 * the position of the cursor. The cursor is displayed
398 * before the character with the given (base 0) index
399 * in the widget. The value must be less than or
400 * equal to the number of characters in the widget.
401 * A value of -1 indicates that the position should
402 * be set after the last character in the entry.
403 * Note that this position is in characters, not in
404 * bytes.
406 public void setPosition(int position)
408 // void gtk_editable_set_position (GtkEditable *editable, gint position);
409 gtk_editable_set_position(gtkEditable, position);
413 * Retrieves the current cursor position.
414 * editable:
415 * a GtkEditable widget.
416 * Returns:
417 * the position of the cursor. The cursor is displayed
418 * before the character with the given (base 0) index
419 * in the widget. The value will be less than or
420 * equal to the number of characters in the widget.
421 * Note that this position is in characters, not in
422 * bytes.
424 public int getPosition()
426 // gint gtk_editable_get_position (GtkEditable *editable);
427 return gtk_editable_get_position(gtkEditable);
431 * Determines if the user can edit the text in the editable
432 * widget or not.
433 * editable:
434 * a GtkEditable widget.
435 * is_editable:
436 * TRUE if the user is allowed to edit the text
437 * in the widget.
439 public void setEditable(int isEditable)
441 // void gtk_editable_set_editable (GtkEditable *editable, gboolean is_editable);
442 gtk_editable_set_editable(gtkEditable, isEditable);
446 * Retrieves whether editable is editable. See
447 * gtk_editable_set_editable().
448 * editable:
449 * a GtkEditable
450 * Returns:
451 * TRUE if editable is editable.
452 * Signal Details
453 * The "changed" signal
454 * void user_function (GtkEditable *editable,
455 * gpointer user_data) : Run Last
456 * Indicates that the user has changed the contents
457 * of the widget.
458 * editable:
459 * the object which received the signal.
460 * user_data:
461 * user data set when the signal handler was connected.
463 public int getEditable()
465 // gboolean gtk_editable_get_editable (GtkEditable *editable);
466 return gtk_editable_get_editable(gtkEditable);