Gtk2-Ex-WidgetBits

 view release on metacpan or  search on metacpan

lib/Gtk2/Ex/EntryBits.pm  view on Meta::CPAN


 use Gtk2::Ex::EntryBits;

=head1 FUNCTIONS

=over 4

=item C<< Gtk2::Ex::EntryBits::select_region_noclip ($entry, $start, $end) >>

Select text from C<$start> to C<$end> like C<< $entry->select_region >>, but
don't put it on the clipboard.  This is a good way to let the user type over
previous text, without upsetting any cut and paste in progress.

This is implemented with a nasty hack temporarily pretending C<$entry> is
unrealized.

=item C<< $pos = Gtk2::Ex::EntryBits::x_to_text_index ($entry, $x) >>

Convert from C<$x> pixel in C<$entry> widget coordinates to a character
index into the text string in the entry.

t/EntryBits.t  view on Meta::CPAN


#-----------------------------------------------------------------------------

{
  my $toplevel = Gtk2::Window->new;
  my $entry = Gtk2::Entry->new;
  $toplevel->add ($entry);
  my $atom = Gtk2::Gdk::Atom->new ('PRIMARY');
  # $entry is on default display, so Gtk2::Clipboard->get() is enough, and
  # doesn't depend on Gtk2::Gdk::Display which is new in Gtk 2.2
  my $clipboard = Gtk2::Clipboard->get ($atom);
  diag $entry->flags;

  Gtk2::Ex::EntryBits::select_region_noclip ($entry, 0, 1);
  ok (! $entry->realized, 'realized - still unrealized');
  isnt ($clipboard->get_owner, $entry, 'unrealized - clipboard owner');

  $entry->realize;
  ok ($entry->realized, 'realized - now realized');
  Gtk2::Ex::EntryBits::select_region_noclip ($entry, 1, 2);
  ok ($entry->realized, 'realized - still realized');
  isnt ($clipboard->get_owner, $entry, 'realized - clipboard owner');
}


#-----------------------------------------------------------------------------
# on a DrawingArea

{
  my $toplevel = Gtk2::Window->new;
  my $drawingarea = Gtk2::DrawingArea->new;
  $toplevel->add ($drawingarea);



( run in 0.446 second using v1.01-cache-2.11-cpan-2398b32b56e )