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.gtk; 30 public import gtkc.gtktypes; 31 public import std.algorithm; 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 * Copies the contents of the currently selected content in the editable and 82 * puts it on the clipboard. 83 */ 84 public void copyClipboard() 85 { 86 gtk_editable_copy_clipboard(getEditableStruct()); 87 } 88 89 /** 90 * Removes the contents of the currently selected content in the editable and 91 * puts it on the clipboard. 92 */ 93 public void cutClipboard() 94 { 95 gtk_editable_cut_clipboard(getEditableStruct()); 96 } 97 98 /** 99 * Deletes the currently selected text of the editable. 100 * This call doesn’t do anything if there is no selected text. 101 */ 102 public void deleteSelection() 103 { 104 gtk_editable_delete_selection(getEditableStruct()); 105 } 106 107 /** 108 * Deletes a sequence of characters. The characters that are deleted are 109 * those characters at positions from @start_pos up to, but not including 110 * @end_pos. If @end_pos is negative, then the characters deleted 111 * are those from @start_pos to the end of the text. 112 * 113 * Note that the positions are specified in characters, not bytes. 114 * 115 * Params: 116 * startPos = start position 117 * endPos = end position 118 */ 119 public void deleteText(int startPos, int endPos) 120 { 121 gtk_editable_delete_text(getEditableStruct(), startPos, endPos); 122 } 123 124 /** 125 * Retrieves a sequence of characters. The characters that are retrieved 126 * are those characters at positions from @start_pos up to, but not 127 * including @end_pos. If @end_pos is negative, then the characters 128 * retrieved are those characters from @start_pos to the end of the text. 129 * 130 * Note that positions are specified in characters, not bytes. 131 * 132 * Params: 133 * startPos = start of text 134 * endPos = end of text 135 * 136 * Returns: a pointer to the contents of the widget as a 137 * string. This string is allocated by the #GtkEditable 138 * implementation and should be freed by the caller. 139 */ 140 public string getChars(int startPos, int endPos) 141 { 142 auto retStr = gtk_editable_get_chars(getEditableStruct(), startPos, endPos); 143 144 scope(exit) Str.freeString(retStr); 145 return Str.toString(retStr); 146 } 147 148 /** 149 * Retrieves whether @editable is editable. See 150 * gtk_editable_set_editable(). 151 * 152 * Returns: %TRUE if @editable is editable. 153 */ 154 public bool getEditable() 155 { 156 return gtk_editable_get_editable(getEditableStruct()) != 0; 157 } 158 159 /** 160 * Retrieves the current position of the cursor relative to the start 161 * of the content of the editable. 162 * 163 * Note that this position is in characters, not in bytes. 164 * 165 * Returns: the cursor position 166 */ 167 public int getPosition() 168 { 169 return gtk_editable_get_position(getEditableStruct()); 170 } 171 172 /** 173 * Retrieves the selection bound of the editable. start_pos will be filled 174 * with the start of the selection and @end_pos with end. If no text was 175 * selected both will be identical and %FALSE will be returned. 176 * 177 * Note that positions are specified in characters, not bytes. 178 * 179 * Params: 180 * startPos = location to store the starting position, or %NULL 181 * endPos = location to store the end position, or %NULL 182 * 183 * Returns: %TRUE if an area is selected, %FALSE otherwise 184 */ 185 public bool getSelectionBounds(out int startPos, out int endPos) 186 { 187 return gtk_editable_get_selection_bounds(getEditableStruct(), &startPos, &endPos) != 0; 188 } 189 190 /** 191 * Inserts @new_text_length bytes of @new_text into the contents of the 192 * widget, at position @position. 193 * 194 * Note that the position is in characters, not in bytes. 195 * The function updates @position to point after the newly inserted text. 196 * 197 * Params: 198 * newText = the text to append 199 * newTextLength = the length of the text in bytes, or -1 200 * position = location of the position text will be inserted at 201 */ 202 public void insertText(string newText, int newTextLength, ref int position) 203 { 204 gtk_editable_insert_text(getEditableStruct(), Str.toStringz(newText), newTextLength, &position); 205 } 206 207 /** 208 * Pastes the content of the clipboard to the current position of the 209 * cursor in the editable. 210 */ 211 public void pasteClipboard() 212 { 213 gtk_editable_paste_clipboard(getEditableStruct()); 214 } 215 216 /** 217 * Selects a region of text. The characters that are selected are 218 * those characters at positions from @start_pos up to, but not 219 * including @end_pos. If @end_pos is negative, then the 220 * characters selected are those characters from @start_pos to 221 * the end of the text. 222 * 223 * Note that positions are specified in characters, not bytes. 224 * 225 * Params: 226 * startPos = start of region 227 * endPos = end of region 228 */ 229 public void selectRegion(int startPos, int endPos) 230 { 231 gtk_editable_select_region(getEditableStruct(), startPos, endPos); 232 } 233 234 /** 235 * Determines if the user can edit the text in the editable 236 * widget or not. 237 * 238 * Params: 239 * isEditable = %TRUE if the user is allowed to edit the text 240 * in the widget 241 */ 242 public void setEditable(bool isEditable) 243 { 244 gtk_editable_set_editable(getEditableStruct(), isEditable); 245 } 246 247 /** 248 * Sets the cursor position in the editable to the given value. 249 * 250 * The cursor is displayed before the character with the given (base 0) 251 * index in the contents of the editable. The value must be less than or 252 * equal to the number of characters in the editable. A value of -1 253 * indicates that the position should be set after the last character 254 * of the editable. Note that @position is in characters, not in bytes. 255 * 256 * Params: 257 * position = the position of the cursor 258 */ 259 public void setPosition(int position) 260 { 261 gtk_editable_set_position(getEditableStruct(), position); 262 } 263 264 protected class OnChangedDelegateWrapper 265 { 266 static OnChangedDelegateWrapper[] listeners; 267 void delegate(EditableIF) dlg; 268 gulong handlerId; 269 270 this(void delegate(EditableIF) dlg) 271 { 272 this.dlg = dlg; 273 this.listeners ~= this; 274 } 275 276 void remove(OnChangedDelegateWrapper source) 277 { 278 foreach(index, wrapper; listeners) 279 { 280 if (wrapper.handlerId == source.handlerId) 281 { 282 listeners[index] = null; 283 listeners = std.algorithm.remove(listeners, index); 284 break; 285 } 286 } 287 } 288 } 289 290 /** 291 * The ::changed signal is emitted at the end of a single 292 * user-visible operation on the contents of the #GtkEditable. 293 * 294 * E.g., a paste operation that replaces the contents of the 295 * selection will cause only one signal emission (even though it 296 * is implemented by first deleting the selection, then inserting 297 * the new content, and may cause multiple ::notify::text signals 298 * to be emitted). 299 */ 300 gulong addOnChanged(void delegate(EditableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 301 { 302 auto wrapper = new OnChangedDelegateWrapper(dlg); 303 wrapper.handlerId = Signals.connectData( 304 this, 305 "changed", 306 cast(GCallback)&callBackChanged, 307 cast(void*)wrapper, 308 cast(GClosureNotify)&callBackChangedDestroy, 309 connectFlags); 310 return wrapper.handlerId; 311 } 312 313 extern(C) static void callBackChanged(GtkEditable* editableStruct, OnChangedDelegateWrapper wrapper) 314 { 315 wrapper.dlg(wrapper.outer); 316 } 317 318 extern(C) static void callBackChangedDestroy(OnChangedDelegateWrapper wrapper, GClosure* closure) 319 { 320 wrapper.remove(wrapper); 321 } 322 323 protected class OnDeleteTextDelegateWrapper 324 { 325 static OnDeleteTextDelegateWrapper[] listeners; 326 void delegate(int, int, EditableIF) dlg; 327 gulong handlerId; 328 329 this(void delegate(int, int, EditableIF) dlg) 330 { 331 this.dlg = dlg; 332 this.listeners ~= this; 333 } 334 335 void remove(OnDeleteTextDelegateWrapper source) 336 { 337 foreach(index, wrapper; listeners) 338 { 339 if (wrapper.handlerId == source.handlerId) 340 { 341 listeners[index] = null; 342 listeners = std.algorithm.remove(listeners, index); 343 break; 344 } 345 } 346 } 347 } 348 349 /** 350 * This signal is emitted when text is deleted from 351 * the widget by the user. The default handler for 352 * this signal will normally be responsible for deleting 353 * the text, so by connecting to this signal and then 354 * stopping the signal with g_signal_stop_emission(), it 355 * is possible to modify the range of deleted text, or 356 * prevent it from being deleted entirely. The @start_pos 357 * and @end_pos parameters are interpreted as for 358 * gtk_editable_delete_text(). 359 * 360 * Params: 361 * startPos = the starting position 362 * endPos = the end position 363 */ 364 gulong addOnDeleteText(void delegate(int, int, EditableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 365 { 366 auto wrapper = new OnDeleteTextDelegateWrapper(dlg); 367 wrapper.handlerId = Signals.connectData( 368 this, 369 "delete-text", 370 cast(GCallback)&callBackDeleteText, 371 cast(void*)wrapper, 372 cast(GClosureNotify)&callBackDeleteTextDestroy, 373 connectFlags); 374 return wrapper.handlerId; 375 } 376 377 extern(C) static void callBackDeleteText(GtkEditable* editableStruct, int startPos, int endPos, OnDeleteTextDelegateWrapper wrapper) 378 { 379 wrapper.dlg(startPos, endPos, wrapper.outer); 380 } 381 382 extern(C) static void callBackDeleteTextDestroy(OnDeleteTextDelegateWrapper wrapper, GClosure* closure) 383 { 384 wrapper.remove(wrapper); 385 } 386 387 protected class OnInsertTextDelegateWrapper 388 { 389 static OnInsertTextDelegateWrapper[] listeners; 390 void delegate(string, int, void*, EditableIF) dlg; 391 gulong handlerId; 392 393 this(void delegate(string, int, void*, EditableIF) dlg) 394 { 395 this.dlg = dlg; 396 this.listeners ~= this; 397 } 398 399 void remove(OnInsertTextDelegateWrapper source) 400 { 401 foreach(index, wrapper; listeners) 402 { 403 if (wrapper.handlerId == source.handlerId) 404 { 405 listeners[index] = null; 406 listeners = std.algorithm.remove(listeners, index); 407 break; 408 } 409 } 410 } 411 } 412 413 /** 414 * This signal is emitted when text is inserted into 415 * the widget by the user. The default handler for 416 * this signal will normally be responsible for inserting 417 * the text, so by connecting to this signal and then 418 * stopping the signal with g_signal_stop_emission(), it 419 * is possible to modify the inserted text, or prevent 420 * it from being inserted entirely. 421 * 422 * Params: 423 * newText = the new text to insert 424 * newTextLength = the length of the new text, in bytes, 425 * or -1 if new_text is nul-terminated 426 * position = the position, in characters, 427 * at which to insert the new text. this is an in-out 428 * parameter. After the signal emission is finished, it 429 * should point after the newly inserted text. 430 */ 431 gulong addOnInsertText(void delegate(string, int, void*, EditableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 432 { 433 auto wrapper = new OnInsertTextDelegateWrapper(dlg); 434 wrapper.handlerId = Signals.connectData( 435 this, 436 "insert-text", 437 cast(GCallback)&callBackInsertText, 438 cast(void*)wrapper, 439 cast(GClosureNotify)&callBackInsertTextDestroy, 440 connectFlags); 441 return wrapper.handlerId; 442 } 443 444 extern(C) static void callBackInsertText(GtkEditable* editableStruct, char* newText, int newTextLength, void* position, OnInsertTextDelegateWrapper wrapper) 445 { 446 wrapper.dlg(Str.toString(newText), newTextLength, position, wrapper.outer); 447 } 448 449 extern(C) static void callBackInsertTextDestroy(OnInsertTextDelegateWrapper wrapper, GClosure* closure) 450 { 451 wrapper.remove(wrapper); 452 } 453 }