1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.EditableT; 26 27 public import glib.Str; 28 public import gobject.Signals; 29 public import gtkc.gdktypes; 30 public import gtkc.gtk; 31 public import gtkc.gtktypes; 32 33 34 /** 35 * The #GtkEditable interface is an interface which should be implemented by 36 * text editing widgets, such as #GtkEntry and #GtkSpinButton. It contains functions 37 * for generically manipulating an editable widget, a large number of action 38 * signals used for key bindings, and several signals that an application can 39 * connect to to modify the behavior of a widget. 40 * 41 * As an example of the latter usage, by connecting 42 * the following handler to #GtkEditable::insert-text, an application 43 * can convert all entry into a widget into uppercase. 44 * 45 * ## Forcing entry to uppercase. 46 * 47 * |[<!-- language="C" --> 48 * #include <ctype.h>; 49 * 50 * void 51 * insert_text_handler (GtkEditable *editable, 52 * const gchar *text, 53 * gint length, 54 * gint *position, 55 * gpointer data) 56 * { 57 * gchar *result = g_utf8_strup (text, length); 58 * 59 * g_signal_handlers_block_by_func (editable, 60 * (gpointer) insert_text_handler, data); 61 * gtk_editable_insert_text (editable, result, length, position); 62 * g_signal_handlers_unblock_by_func (editable, 63 * (gpointer) insert_text_handler, data); 64 * 65 * g_signal_stop_emission_by_name (editable, "insert_text"); 66 * 67 * g_free (result); 68 * } 69 * ]| 70 */ 71 public template EditableT(TStruct) 72 { 73 /** Get the main Gtk struct */ 74 public GtkEditable* getEditableStruct() 75 { 76 return cast(GtkEditable*)getStruct(); 77 } 78 79 /** 80 */ 81 82 /** 83 * Copies the contents of the currently selected content in the editable and 84 * puts it on the clipboard. 85 */ 86 public void copyClipboard() 87 { 88 gtk_editable_copy_clipboard(getEditableStruct()); 89 } 90 91 /** 92 * Removes the contents of the currently selected content in the editable and 93 * puts it on the clipboard. 94 */ 95 public void cutClipboard() 96 { 97 gtk_editable_cut_clipboard(getEditableStruct()); 98 } 99 100 /** 101 * Deletes the currently selected text of the editable. 102 * This call doesn’t do anything if there is no selected text. 103 */ 104 public void deleteSelection() 105 { 106 gtk_editable_delete_selection(getEditableStruct()); 107 } 108 109 /** 110 * Deletes a sequence of characters. The characters that are deleted are 111 * those characters at positions from @start_pos up to, but not including 112 * @end_pos. If @end_pos is negative, then the characters deleted 113 * are those from @start_pos to the end of the text. 114 * 115 * Note that the positions are specified in characters, not bytes. 116 * 117 * Params: 118 * startPos = start position 119 * endPos = end position 120 */ 121 public void deleteText(int startPos, int endPos) 122 { 123 gtk_editable_delete_text(getEditableStruct(), startPos, endPos); 124 } 125 126 /** 127 * Retrieves a sequence of characters. The characters that are retrieved 128 * are those characters at positions from @start_pos up to, but not 129 * including @end_pos. If @end_pos is negative, then the characters 130 * retrieved are those characters from @start_pos to the end of the text. 131 * 132 * Note that positions are specified in characters, not bytes. 133 * 134 * Params: 135 * startPos = start of text 136 * endPos = end of text 137 * 138 * Return: a pointer to the contents of the widget as a 139 * string. This string is allocated by the #GtkEditable 140 * implementation and should be freed by the caller. 141 */ 142 public string getChars(int startPos, int endPos) 143 { 144 return Str.toString(gtk_editable_get_chars(getEditableStruct(), startPos, endPos)); 145 } 146 147 /** 148 * Retrieves whether @editable is editable. See 149 * gtk_editable_set_editable(). 150 * 151 * Return: %TRUE if @editable is editable. 152 */ 153 public bool getEditable() 154 { 155 return gtk_editable_get_editable(getEditableStruct()) != 0; 156 } 157 158 /** 159 * Retrieves the current position of the cursor relative to the start 160 * of the content of the editable. 161 * 162 * Note that this position is in characters, not in bytes. 163 * 164 * Return: the cursor position 165 */ 166 public int getPosition() 167 { 168 return gtk_editable_get_position(getEditableStruct()); 169 } 170 171 /** 172 * Retrieves the selection bound of the editable. start_pos will be filled 173 * with the start of the selection and @end_pos with end. If no text was 174 * selected both will be identical and %FALSE will be returned. 175 * 176 * Note that positions are specified in characters, not bytes. 177 * 178 * Params: 179 * startPos = location to store the starting position, or %NULL 180 * endPos = location to store the end position, or %NULL 181 * 182 * Return: %TRUE if an area is selected, %FALSE otherwise 183 */ 184 public bool getSelectionBounds(out int startPos, out int endPos) 185 { 186 return gtk_editable_get_selection_bounds(getEditableStruct(), &startPos, &endPos) != 0; 187 } 188 189 /** 190 * Inserts @new_text_length bytes of @new_text into the contents of the 191 * widget, at position @position. 192 * 193 * Note that the position is in characters, not in bytes. 194 * The function updates @position to point after the newly inserted text. 195 * 196 * Params: 197 * newText = the text to append 198 * newTextLength = the length of the text in bytes, or -1 199 * position = location of the position text will be inserted at 200 */ 201 public void insertText(string newText, int newTextLength, ref int position) 202 { 203 gtk_editable_insert_text(getEditableStruct(), Str.toStringz(newText), newTextLength, &position); 204 } 205 206 /** 207 * Pastes the content of the clipboard to the current position of the 208 * cursor in the editable. 209 */ 210 public void pasteClipboard() 211 { 212 gtk_editable_paste_clipboard(getEditableStruct()); 213 } 214 215 /** 216 * Selects a region of text. The characters that are selected are 217 * those characters at positions from @start_pos up to, but not 218 * including @end_pos. If @end_pos is negative, then the 219 * characters selected are those characters from @start_pos to 220 * the end of the text. 221 * 222 * Note that positions are specified in characters, not bytes. 223 * 224 * Params: 225 * startPos = start of region 226 * endPos = end of region 227 */ 228 public void selectRegion(int startPos, int endPos) 229 { 230 gtk_editable_select_region(getEditableStruct(), startPos, endPos); 231 } 232 233 /** 234 * Determines if the user can edit the text in the editable 235 * widget or not. 236 * 237 * Params: 238 * isEditable = %TRUE if the user is allowed to edit the text 239 * in the widget 240 */ 241 public void setEditable(bool isEditable) 242 { 243 gtk_editable_set_editable(getEditableStruct(), isEditable); 244 } 245 246 /** 247 * Sets the cursor position in the editable to the given value. 248 * 249 * The cursor is displayed before the character with the given (base 0) 250 * index in the contents of the editable. The value must be less than or 251 * equal to the number of characters in the editable. A value of -1 252 * indicates that the position should be set after the last character 253 * of the editable. Note that @position is in characters, not in bytes. 254 * 255 * Params: 256 * position = the position of the cursor 257 */ 258 public void setPosition(int position) 259 { 260 gtk_editable_set_position(getEditableStruct(), position); 261 } 262 263 int[string] connectedSignals; 264 265 void delegate(EditableIF)[] _onChangedListeners; 266 @property void delegate(EditableIF)[] onChangedListeners() 267 { 268 return _onChangedListeners; 269 } 270 /** 271 * The ::changed signal is emitted at the end of a single 272 * user-visible operation on the contents of the #GtkEditable. 273 * 274 * E.g., a paste operation that replaces the contents of the 275 * selection will cause only one signal emission (even though it 276 * is implemented by first deleting the selection, then inserting 277 * the new content, and may cause multiple ::notify::text signals 278 * to be emitted). 279 */ 280 void addOnChanged(void delegate(EditableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 281 { 282 if ( "changed" !in connectedSignals ) 283 { 284 Signals.connectData( 285 this, 286 "changed", 287 cast(GCallback)&callBackChanged, 288 cast(void*)cast(EditableIF)this, 289 null, 290 connectFlags); 291 connectedSignals["changed"] = 1; 292 } 293 _onChangedListeners ~= dlg; 294 } 295 extern(C) static void callBackChanged(GtkEditable* editableStruct, EditableIF _editable) 296 { 297 foreach ( void delegate(EditableIF) dlg; _editable.onChangedListeners ) 298 { 299 dlg(_editable); 300 } 301 } 302 303 void delegate(int, int, EditableIF)[] _onDeleteTextListeners; 304 @property void delegate(int, int, EditableIF)[] onDeleteTextListeners() 305 { 306 return _onDeleteTextListeners; 307 } 308 /** 309 * This signal is emitted when text is deleted from 310 * the widget by the user. The default handler for 311 * this signal will normally be responsible for deleting 312 * the text, so by connecting to this signal and then 313 * stopping the signal with g_signal_stop_emission(), it 314 * is possible to modify the range of deleted text, or 315 * prevent it from being deleted entirely. The @start_pos 316 * and @end_pos parameters are interpreted as for 317 * gtk_editable_delete_text(). 318 * 319 * Params: 320 * startPos = the starting position 321 * endPos = the end position 322 */ 323 void addOnDeleteText(void delegate(int, int, EditableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 324 { 325 if ( "delete-text" !in connectedSignals ) 326 { 327 Signals.connectData( 328 this, 329 "delete-text", 330 cast(GCallback)&callBackDeleteText, 331 cast(void*)cast(EditableIF)this, 332 null, 333 connectFlags); 334 connectedSignals["delete-text"] = 1; 335 } 336 _onDeleteTextListeners ~= dlg; 337 } 338 extern(C) static void callBackDeleteText(GtkEditable* editableStruct, int startPos, int endPos, EditableIF _editable) 339 { 340 foreach ( void delegate(int, int, EditableIF) dlg; _editable.onDeleteTextListeners ) 341 { 342 dlg(startPos, endPos, _editable); 343 } 344 } 345 346 void delegate(string, int, void*, EditableIF)[] _onInsertTextListeners; 347 @property void delegate(string, int, void*, EditableIF)[] onInsertTextListeners() 348 { 349 return _onInsertTextListeners; 350 } 351 /** 352 * This signal is emitted when text is inserted into 353 * the widget by the user. The default handler for 354 * this signal will normally be responsible for inserting 355 * the text, so by connecting to this signal and then 356 * stopping the signal with g_signal_stop_emission(), it 357 * is possible to modify the inserted text, or prevent 358 * it from being inserted entirely. 359 * 360 * Params: 361 * newText = the new text to insert 362 * newTextLength = the length of the new text, in bytes, 363 * or -1 if new_text is nul-terminated 364 * position = the position, in characters, 365 * at which to insert the new text. this is an in-out 366 * parameter. After the signal emission is finished, it 367 * should point after the newly inserted text. 368 */ 369 void addOnInsertText(void delegate(string, int, void*, EditableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 370 { 371 if ( "insert-text" !in connectedSignals ) 372 { 373 Signals.connectData( 374 this, 375 "insert-text", 376 cast(GCallback)&callBackInsertText, 377 cast(void*)cast(EditableIF)this, 378 null, 379 connectFlags); 380 connectedSignals["insert-text"] = 1; 381 } 382 _onInsertTextListeners ~= dlg; 383 } 384 extern(C) static void callBackInsertText(GtkEditable* editableStruct, char* newText, int newTextLength, void* position, EditableIF _editable) 385 { 386 foreach ( void delegate(string, int, void*, EditableIF) dlg; _editable.onInsertTextListeners ) 387 { 388 dlg(Str.toString(newText), newTextLength, position, _editable); 389 } 390 } 391 }