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.EditableIF; 26 27 private import glib.Str; 28 private import glib.c.functions; 29 private import gobject.ObjectClass; 30 private import gobject.ObjectG; 31 private import gobject.ParamSpec; 32 private import gobject.Signals; 33 private import gobject.Value; 34 private import gtk.EditableIF; 35 private import gtk.c.functions; 36 public import gtk.c.types; 37 private import std.algorithm; 38 39 40 /** 41 * `GtkEditable` is an interface for text editing widgets. 42 * 43 * Typical examples of editable widgets are [class@Gtk.Entry] and 44 * [class@Gtk.SpinButton]. It contains functions for generically manipulating 45 * an editable widget, a large number of action signals used for key bindings, 46 * and several signals that an application can connect to modify the behavior 47 * of a widget. 48 * 49 * As an example of the latter usage, by connecting the following handler to 50 * [signal@Gtk.Editable::insert-text], an application can convert all entry 51 * into a widget into uppercase. 52 * 53 * ## Forcing entry to uppercase. 54 * 55 * ```c 56 * #include <ctype.h> 57 * 58 * void 59 * insert_text_handler (GtkEditable *editable, 60 * const char *text, 61 * int length, 62 * int *position, 63 * gpointer data) 64 * { 65 * char *result = g_utf8_strup (text, length); 66 * 67 * g_signal_handlers_block_by_func (editable, 68 * (gpointer) insert_text_handler, data); 69 * gtk_editable_insert_text (editable, result, length, position); 70 * g_signal_handlers_unblock_by_func (editable, 71 * (gpointer) insert_text_handler, data); 72 * 73 * g_signal_stop_emission_by_name (editable, "insert_text"); 74 * 75 * g_free (result); 76 * } 77 * ``` 78 * 79 * ## Implementing GtkEditable 80 * 81 * The most likely scenario for implementing `GtkEditable` on your own widget 82 * is that you will embed a #GtkText inside a complex widget, and want to 83 * delegate the editable functionality to that text widget. `GtkEditable` 84 * provides some utility functions to make this easy. 85 * 86 * In your class_init function, call [func@Gtk.Editable.install_properties], 87 * passing the first available property ID: 88 * 89 * ```c 90 * static void 91 * my_class_init (MyClass *class) 92 * { 93 * ... 94 * g_object_class_install_properties (object_class, NUM_PROPERTIES, props); 95 * gtk_editable_install_properties (object_clas, NUM_PROPERTIES); 96 * ... 97 * } 98 * ``` 99 * 100 * In your interface_init function for the `GtkEditable` interface, provide 101 * an implementation for the get_delegate vfunc that returns your text widget: 102 * 103 * ```c 104 * GtkEditable * 105 * get_editable_delegate (GtkEditable *editable) 106 * { 107 * return GTK_EDITABLE (MY_WIDGET (editable)->text_widget); 108 * } 109 * 110 * static void 111 * my_editable_init (GtkEditableInterface *iface) 112 * { 113 * iface->get_delegate = get_editable_delegate; 114 * } 115 * ``` 116 * 117 * You don't need to provide any other vfuncs. The default implementations 118 * work by forwarding to the delegate that the GtkEditableInterface.get_delegate() 119 * vfunc returns. 120 * 121 * In your instance_init function, create your text widget, and then call 122 * [method@Gtk.Editable.init_delegate]: 123 * 124 * ```c 125 * static void 126 * my_widget_init (MyWidget *self) 127 * { 128 * ... 129 * self->text_widget = gtk_text_new (); 130 * gtk_editable_init_delegate (GTK_EDITABLE (self)); 131 * ... 132 * } 133 * ``` 134 * 135 * In your dispose function, call [method@Gtk.Editable.finish_delegate] before 136 * destroying your text widget: 137 * 138 * ```c 139 * static void 140 * my_widget_dispose (GObject *object) 141 * { 142 * ... 143 * gtk_editable_finish_delegate (GTK_EDITABLE (self)); 144 * g_clear_pointer (&self->text_widget, gtk_widget_unparent); 145 * ... 146 * } 147 * ``` 148 * 149 * Finally, use [func@Gtk.Editable.delegate_set_property] in your `set_property` 150 * function (and similar for `get_property`), to set the editable properties: 151 * 152 * ```c 153 * ... 154 * if (gtk_editable_delegate_set_property (object, prop_id, value, pspec)) 155 * return; 156 * 157 * switch (prop_id) 158 * ... 159 * ``` 160 * 161 * It is important to note that if you create a `GtkEditable` that uses 162 * a delegate, the low level [signal@Gtk.Editable::insert-text] and 163 * [signal@Gtk.Editable::delete-text] signals will be propagated from the 164 * "wrapper" editable to the delegate, but they will not be propagated from 165 * the delegate to the "wrapper" editable, as they would cause an infinite 166 * recursion. If you wish to connect to the [signal@Gtk.Editable::insert-text] 167 * and [signal@Gtk.Editable::delete-text] signals, you will need to connect 168 * to them on the delegate obtained via [method@Gtk.Editable.get_delegate]. 169 */ 170 public interface EditableIF{ 171 /** Get the main Gtk struct */ 172 public GtkEditable* getEditableStruct(bool transferOwnership = false); 173 174 /** the main Gtk struct as a void* */ 175 protected void* getStruct(); 176 177 178 /** */ 179 public static GType getType() 180 { 181 return gtk_editable_get_type(); 182 } 183 184 /** 185 * Gets a property of the `GtkEditable` delegate for @object. 186 * 187 * This is helper function that should be called in the `get_property` 188 * function of your `GtkEditable` implementation, before handling your 189 * own properties. 190 * 191 * Params: 192 * object = a `GObject` 193 * propId = a property ID 194 * value = value to set 195 * pspec = the `GParamSpec` for the property 196 * 197 * Returns: %TRUE if the property was found 198 */ 199 public static bool delegateGetProperty(ObjectG object, uint propId, Value value, ParamSpec pspec) 200 { 201 return gtk_editable_delegate_get_property((object is null) ? null : object.getObjectGStruct(), propId, (value is null) ? null : value.getValueStruct(), (pspec is null) ? null : pspec.getParamSpecStruct()) != 0; 202 } 203 204 /** 205 * Sets a property on the `GtkEditable` delegate for @object. 206 * 207 * This is a helper function that should be called in the `set_property` 208 * function of your `GtkEditable` implementation, before handling your 209 * own properties. 210 * 211 * Params: 212 * object = a `GObject` 213 * propId = a property ID 214 * value = value to set 215 * pspec = the `GParamSpec` for the property 216 * 217 * Returns: %TRUE if the property was found 218 */ 219 public static bool delegateSetProperty(ObjectG object, uint propId, Value value, ParamSpec pspec) 220 { 221 return gtk_editable_delegate_set_property((object is null) ? null : object.getObjectGStruct(), propId, (value is null) ? null : value.getValueStruct(), (pspec is null) ? null : pspec.getParamSpecStruct()) != 0; 222 } 223 224 /** 225 * Installs the `GtkEditable` properties for @class. 226 * 227 * This is a helper function that should be called in class_init, 228 * after installing your own properties. 229 * 230 * To handle the properties in your set_property and get_property 231 * functions, you can either use [func@Gtk.Editable.delegate_set_property] 232 * and [func@Gtk.Editable.delegate_get_property] (if you are using 233 * a delegate), or remember the @first_prop offset and add it to the 234 * values in the [enum@Gtk.EditableProperties] enumeration to get the 235 * property IDs for these properties. 236 * 237 * Params: 238 * objectClass = a `GObjectClass` 239 * firstProp = property ID to use for the first property 240 * 241 * Returns: the number of properties that were installed 242 */ 243 public static uint installProperties(ObjectClass objectClass, uint firstProp) 244 { 245 return gtk_editable_install_properties((objectClass is null) ? null : objectClass.getObjectClassStruct(), firstProp); 246 } 247 248 /** 249 * Deletes the currently selected text of the editable. 250 * 251 * This call doesn’t do anything if there is no selected text. 252 */ 253 public void deleteSelection(); 254 255 /** 256 * Deletes a sequence of characters. 257 * 258 * The characters that are deleted are those characters at positions 259 * from @start_pos up to, but not including @end_pos. If @end_pos is 260 * negative, then the characters deleted are those from @start_pos to 261 * the end of the text. 262 * 263 * Note that the positions are specified in characters, not bytes. 264 * 265 * Params: 266 * startPos = start position 267 * endPos = end position 268 */ 269 public void deleteText(int startPos, int endPos); 270 271 /** 272 * Undoes the setup done by [method@Gtk.Editable.init_delegate]. 273 * 274 * This is a helper function that should be called from dispose, 275 * before removing the delegate object. 276 */ 277 public void finishDelegate(); 278 279 /** 280 * Gets the alignment of the editable. 281 * 282 * Returns: the alignment 283 */ 284 public float getAlignment(); 285 286 /** 287 * Retrieves a sequence of characters. 288 * 289 * The characters that are retrieved are those characters at positions 290 * from @start_pos up to, but not including @end_pos. If @end_pos is negative, 291 * then the characters retrieved are those characters from @start_pos to 292 * the end of the text. 293 * 294 * Note that positions are specified in characters, not bytes. 295 * 296 * Params: 297 * startPos = start of text 298 * endPos = end of text 299 * 300 * Returns: a pointer to the contents of the widget as a 301 * string. This string is allocated by the `GtkEditable` implementation 302 * and should be freed by the caller. 303 */ 304 public string getChars(int startPos, int endPos); 305 306 /** 307 * Gets the `GtkEditable` that @editable is delegating its 308 * implementation to. 309 * 310 * Typically, the delegate is a [class@Gtk.Text] widget. 311 * 312 * Returns: the delegate `GtkEditable` 313 */ 314 public EditableIF getDelegate(); 315 316 /** 317 * Retrieves whether @editable is editable. 318 * 319 * Returns: %TRUE if @editable is editable. 320 */ 321 public bool getEditable(); 322 323 /** 324 * Gets if undo/redo actions are enabled for @editable 325 * 326 * Returns: %TRUE if undo is enabled 327 */ 328 public bool getEnableUndo(); 329 330 /** 331 * Retrieves the desired maximum width of @editable, in characters. 332 * 333 * Returns: the maximum width of the entry, in characters 334 */ 335 public int getMaxWidthChars(); 336 337 /** 338 * Retrieves the current position of the cursor relative 339 * to the start of the content of the editable. 340 * 341 * Note that this position is in characters, not in bytes. 342 * 343 * Returns: the cursor position 344 */ 345 public int getPosition(); 346 347 /** 348 * Retrieves the selection bound of the editable. 349 * 350 * @start_pos will be filled with the start of the selection and 351 * @end_pos with end. If no text was selected both will be identical 352 * and %FALSE will be returned. 353 * 354 * Note that positions are specified in characters, not bytes. 355 * 356 * Params: 357 * startPos = location to store the starting position, or %NULL 358 * endPos = location to store the end position, or %NULL 359 * 360 * Returns: %TRUE if there is a non-empty selection, %FALSE otherwise 361 */ 362 public bool getSelectionBounds(out int startPos, out int endPos); 363 364 /** 365 * Retrieves the contents of @editable. 366 * 367 * The returned string is owned by GTK and must not be modified or freed. 368 * 369 * Returns: a pointer to the contents of the editable 370 */ 371 public string getText(); 372 373 /** 374 * Gets the number of characters of space reserved 375 * for the contents of the editable. 376 * 377 * Returns: number of chars to request space for, or negative if unset 378 */ 379 public int getWidthChars(); 380 381 /** 382 * Sets up a delegate for `GtkEditable`. 383 * 384 * This is assuming that the get_delegate vfunc in the `GtkEditable` 385 * interface has been set up for the @editable's type. 386 * 387 * This is a helper function that should be called in instance init, 388 * after creating the delegate object. 389 */ 390 public void initDelegate(); 391 392 /** 393 * Inserts @length bytes of @text into the contents of the 394 * widget, at position @position. 395 * 396 * Note that the position is in characters, not in bytes. 397 * The function updates @position to point after the newly 398 * inserted text. 399 * 400 * Params: 401 * text = the text to append 402 * length = the length of the text in bytes, or -1 403 * position = location of the position text will be inserted at 404 */ 405 public void insertText(string text, int length, ref int position); 406 407 /** 408 * Selects a region of text. 409 * 410 * The characters that are selected are those characters at positions 411 * from @start_pos up to, but not including @end_pos. If @end_pos is 412 * negative, then the characters selected are those characters from 413 * @start_pos to the end of the text. 414 * 415 * Note that positions are specified in characters, not bytes. 416 * 417 * Params: 418 * startPos = start of region 419 * endPos = end of region 420 */ 421 public void selectRegion(int startPos, int endPos); 422 423 /** 424 * Sets the alignment for the contents of the editable. 425 * 426 * This controls the horizontal positioning of the contents when 427 * the displayed text is shorter than the width of the editable. 428 * 429 * Params: 430 * xalign = The horizontal alignment, from 0 (left) to 1 (right). 431 * Reversed for RTL layouts 432 */ 433 public void setAlignment(float xalign); 434 435 /** 436 * Determines if the user can edit the text in the editable widget. 437 * 438 * Params: 439 * isEditable = %TRUE if the user is allowed to edit the text 440 * in the widget 441 */ 442 public void setEditable(bool isEditable); 443 444 /** 445 * If enabled, changes to @editable will be saved for undo/redo 446 * actions. 447 * 448 * This results in an additional copy of text changes and are not 449 * stored in secure memory. As such, undo is forcefully disabled 450 * when [property@Gtk.Text:visibility] is set to %FALSE. 451 * 452 * Params: 453 * enableUndo = if undo/redo should be enabled 454 */ 455 public void setEnableUndo(bool enableUndo); 456 457 /** 458 * Sets the desired maximum width in characters of @editable. 459 * 460 * Params: 461 * nChars = the new desired maximum width, in characters 462 */ 463 public void setMaxWidthChars(int nChars); 464 465 /** 466 * Sets the cursor position in the editable to the given value. 467 * 468 * The cursor is displayed before the character with the given (base 0) 469 * index in the contents of the editable. The value must be less than 470 * or equal to the number of characters in the editable. A value of -1 471 * indicates that the position should be set after the last character 472 * of the editable. Note that @position is in characters, not in bytes. 473 * 474 * Params: 475 * position = the position of the cursor 476 */ 477 public void setPosition(int position); 478 479 /** 480 * Sets the text in the editable to the given value. 481 * 482 * This is replacing the current contents. 483 * 484 * Params: 485 * text = the text to set 486 */ 487 public void setText(string text); 488 489 /** 490 * Changes the size request of the editable to be about the 491 * right size for @n_chars characters. 492 * 493 * Note that it changes the size request, the size can still 494 * be affected by how you pack the widget into containers. 495 * If @n_chars is -1, the size reverts to the default size. 496 * 497 * Params: 498 * nChars = width in chars 499 */ 500 public void setWidthChars(int nChars); 501 502 /** 503 * Emitted at the end of a single user-visible operation on the 504 * contents. 505 * 506 * E.g., a paste operation that replaces the contents of the 507 * selection will cause only one signal emission (even though it 508 * is implemented by first deleting the selection, then inserting 509 * the new content, and may cause multiple ::notify::text signals 510 * to be emitted). 511 */ 512 gulong addOnChanged(void delegate(EditableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0); 513 514 /** 515 * Emitted when text is deleted from the widget by the user. 516 * 517 * The default handler for this signal will normally be responsible for 518 * deleting the text, so by connecting to this signal and then stopping 519 * the signal with g_signal_stop_emission(), it is possible to modify the 520 * range of deleted text, or prevent it from being deleted entirely. 521 * 522 * The @start_pos and @end_pos parameters are interpreted as for 523 * [method@Gtk.Editable.delete_text]. 524 * 525 * Params: 526 * startPos = the starting position 527 * endPos = the end position 528 */ 529 gulong addOnDeleteText(void delegate(int, int, EditableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0); 530 531 /** 532 * Emitted when text is inserted into the widget by the user. 533 * 534 * The default handler for this signal will normally be responsible 535 * for inserting the text, so by connecting to this signal and then 536 * stopping the signal with g_signal_stop_emission(), it is possible 537 * to modify the inserted text, or prevent it from being inserted entirely. 538 * 539 * Params: 540 * text = the new text to insert 541 * length = the length of the new text, in bytes, 542 * or -1 if new_text is nul-terminated 543 * position = the position, in characters, 544 * at which to insert the new text. this is an in-out 545 * parameter. After the signal emission is finished, it 546 * should point after the newly inserted text. 547 */ 548 gulong addOnInsertText(void delegate(string, int, void*, EditableIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0); 549 }