Gtk2::Editable(3)

πŸ“¦
version 1.24993 Β· 2 versions
, in fedora 43

πŸ’– Gtk2::Editable β€” the wrapper for GtkEditable πŸ’–

okay so bestie, welcome to Gtk2::Editable, the Perl wrapper for GtkEditable. it's the little interface that makes text-entry-ish widgets actually editable β€” typing, selecting, clipboard chaos, the whole vibe. this page was part of the User Contributed Perl Documentation and honestly? she ate. πŸŽ€


🌸 HIERARCHY 🌸

so here's where she sits in the family tree, no cap:

  Glib::Interface
  +----Gtk2::Editable

it's giving interface energy, which is correct, because she is one. ✨


✨ METHODS ✨

okay bestie, here's the whole toolbox. every single one. don't skip, iykyk.

  • string = $editable->get_chars ($start_pos, $end_pos) β€” grab the text between two spots. takes:
    • $start_pos (integer)
    • $end_pos (integer)
  • $editable->copy_clipboard β€” copy the current selection to the clipboard. slay. πŸ“‹
  • $editable->cut_clipboard β€” cut the current selection to the clipboard. gone but not forgotten. βœ‚οΈ
  • $editable->delete_selection β€” just delete the selection, no clipboard involvement. bye bestie πŸ’€
  • $editable->delete_text ($start_pos, $end_pos) β€” delete a range of text. takes:
    • $start_pos (integer)
    • $end_pos (integer)
  • boolean = $editable->get_editable β€” is she editable or not? returns a boolean, so true/false vibes only.
  • $editable->set_editable ($is_editable) β€” toggle whether this thing is editable at all. takes:
    • $is_editable (boolean)
  • new_position = $editable->insert_text (new_text, position) β€” shove some text in at a position and get the new position back. takes:
    • $new_text (string)
    • ... (list)
  • $editable->paste_clipboard β€” paste whatever's on the clipboard. iconic. πŸ“₯
  • integer = $editable->get_position β€” returns the current cursor position as an integer.
  • $editable->set_position ($position) β€” move the cursor. takes:
    • $position (integer)
  • $editable->select_region ($start, $end) β€” highlight a region. takes:
    • $start (integer)
    • $end (integer)
  • (start, end) = $editable->get_selection_bounds β€” Returns integers, start and end. that's the whole thing, periodt.

πŸ”” SIGNALS πŸ””

the signals she emits, listed exactly:

  • changed (Gtk2::Editable)
  • delete-text (Gtk2::Editable, integer, integer)
  • insert-text (Gtk2::Editable, string, integer, gpointer)

πŸ’… the insert-text signal can change stuff πŸ’…

okay so this is the fun part: The insert-text signal handler can optionally alter the text to be inserted. It may:

  • Return no values for no change. Be sure to end with an empty return.
sub my_insert_text_handler {
  my ($widget, $text, $len, $pos, $userdata) = @_;
  print "inserting '$text' at char position '$pos'\n";
  return;  # no values
}
  • Return two values ($text, $pos) which are the new text and character position.
sub my_insert_text_handler {
  my ($widget, $text, $len, $pos, $userdata) = @_;
  return (uc($text), $pos);  # force to upper case
}
  • Return no values and modify the text in $_[1] and/or position in $_[3]. For example,
sub my_insert_text_handler {
  $_[1] = uc($_[1]);   # force to upper case
  $_[3] = 0;           # force position to the start
  return;  # no values
}
🚨 bestie, heads up, this one's important: Note that currently in a Perl subclass of a Gtk2::Editable widget, a class closure (ie. class default signal handler) for insert-text does not work this way. It instead sees the C level ($text, $len, $pos_pointer), where $pos_pointer is a machine address and cannot be used easily. Hopefully this will change in the future. A signal_chain_from_overridden with the args as passed works, but for anything else the suggestion is to use a signal_connect instead.

πŸ‘€ SEE ALSO πŸ‘€

go read these too, fr fr:

  • Gtk2
  • Glib::Interface

Copyright (C) 2003-2011 by the gtk2-perl team.

This software is licensed under the LGPL. See Gtk2 for a full notice.


and that's the whole page, bestie πŸ’– written up for perl v5.42.0, dated 2025-07-25, from the Gtk2::Editable(3) manual. go forth and edit text responsibly. πŸ¦‹βœ¨πŸ‘‘

πŸ“¦ where this page comes from