Gtk2-Ex-WidgetCursor

 view release on metacpan or  search on metacpan

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

                   'Whether to apply the cursor to child widgets too.',
                   0, # default no
                   Glib::G_PARAM_READWRITE),

                ];

# @wobjs is all the WidgetCursor objects which currently exist, sorted from
# highest to lowest priority, and from newest to oldest among those of equal
# priority
#
# Elements are weakened so they don't keep the objects alive.  The DESTROY
# method strips elements and undefs from here, but not sure if undef could
# still be seen in here by certain funcs at certain times.
#
my @wobjs = ();

sub INIT_INSTANCE {
  my ($self) = @_;
  ### WidgetCursor INIT_INSTANCE: "$self"

  $self->{'installed_widgets'} = [];

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


=over 4

=item C<widget> (C<Gtk2::Widget>, default C<undef>)

=item C<widgets> (scalar arrayref of C<Gtk2::Widget>, default C<undef>)

The widget or widgets to act on.

A WidgetCursor object only keeps weak references to its widget(s), so the
mere fact there's a desired cursor won't keep a widget alive forever.
Garbage collected widgets drop out of the widgets list.  In particular this
means it's safe to hold a WidgetCursor within a widget's own hash without
creating a circular reference.  Eg.

    my $widget = Gtk2::DrawingArea->new;
    $widget->{'base_cursor'} = Gtk2::Ex::WidgetCursor->new
                                 (widget => $widget,
                                  cursor => 'hand1',
                                  active => 1,
                                  priority => -10);

t/WidgetCursor.t  view on Meta::CPAN

  my $d1 = $default_display;
  my $d2 = Gtk2::Gdk::Display->open ($display_name);
  if ($d1 == $d2) {
    skip 'due to only one GdkDisplay available', 1;
  }
  my $c1 = Gtk2::Ex::WidgetCursor->invisible_cursor ($d1);
  my $c2 = Gtk2::Ex::WidgetCursor->invisible_cursor ($d2);
  isnt ($c1, $c2, 'invisible_cursor() different on different displays');
}

# an invisible cursor hung on a display doesn't keep that object alive
# forever
#
# Crib note: must destroy the cursor object before destroying the display
# object (either closed or still open), since in Gtk 2.22 the cursor object
# doesn't seem to hold a ref to the display object and bad things happen on
# using the cursor after the display is gone.
#
# For the code here the cursor obj is weak here and hard in $d->{'_invis'}.
# The destroy of those $d fields seems to happen soon enough during the
# destroy of $d to work -- as long as you don't hold a hard ref to $c

t/WidgetCursor.t  view on Meta::CPAN


# WidgetCursor on a realized widget should be garbage collected
{
  my $widget = Gtk2::Window->new ('toplevel');
  $widget->show;
  my $wobj = Gtk2::Ex::WidgetCursor->new (widget => $widget);
  Scalar::Util::weaken ($wobj);
  is ($wobj, undef);
}

# WidgetCursor doesn't keep widget alive forever
{
  my $widget = Gtk2::Label->new ('hi');
  my $wobj = Gtk2::Ex::WidgetCursor->new (widget => $widget);
  Scalar::Util::weaken ($widget);
  is ($widget, undef);
  if ($widget) {
    MyTestHelpers::findrefs($widget);
  }
}

# WidgetCursor doesn't keep widgets array alive forever
{
  my $widget1 = Gtk2::Label->new ('hi');
  my $widget2 = Gtk2::Label->new ('bye');
  my $aref = [$widget1, $widget2];
  my $wobj = Gtk2::Ex::WidgetCursor->new (widgets => $aref);

  Scalar::Util::weaken ($aref);
  is ($aref, undef);

  Scalar::Util::weaken ($widget1);
  is ($widget1, undef);

  Scalar::Util::weaken ($widget2);
  is ($widget2, undef);
}

# WidgetCursor add_widgets doesn't keep widget alive forever
{
  my $widget = Gtk2::Label->new ('hi');
  my $wobj = Gtk2::Ex::WidgetCursor->new;
  $wobj->add_widgets ($widget);
  Scalar::Util::weaken ($widget);
  is ($widget, undef);
}

# add_widgets with weakened undefs in wobj
{



( run in 0.360 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )