Commit 0ab57356 authored by Torsten Schönfeld's avatar Torsten Schönfeld

Add overrides for Gtk3::Widget::add_events, set_events, get_events

parent 321ae8b3
......@@ -1892,6 +1892,45 @@ sub Gtk3::VBox::new {
$_GTK_BASENAME, 'VBox', 'new', $class, $homogeneous, $spacing);
}
=item * C<Gtk3::Widget::add_events> and C<Gtk3::Widget::set_events> also accept
strings, array references and C<Gtk3::Gdk::EventMask> objects for the C<events>
parameter.
=cut
sub Gtk3::Widget::add_events {
my ($widget, $events) = @_;
eval {
$events = Glib::Object::Introspection->convert_sv_to_flags (
'Gtk3::Gdk::EventMask', $events);
};
return Glib::Object::Introspection->invoke (
$_GTK_BASENAME, 'Widget', 'add_events', $widget, $events);
}
sub Gtk3::Widget::set_events {
my ($widget, $events) = @_;
eval {
$events = Glib::Object::Introspection->convert_sv_to_flags (
'Gtk3::Gdk::EventMask', $events);
};
return Glib::Object::Introspection->invoke (
$_GTK_BASENAME, 'Widget', 'set_events', $widget, $events);
}
=item * C<Gtk3::Widget::get_events> returns a C<Gtk3::Gdk::EventMask> object
that can also be compared to numeric values with C<< == >> and C<< >= >>.
=cut
sub Gtk3::Widget::get_events {
my ($widget) = @_;
my $events = Glib::Object::Introspection->invoke (
$_GTK_BASENAME, 'Widget', 'get_events', $widget);
return Glib::Object::Introspection->convert_flags_to_sv (
'Gtk3::Gdk::EventMask', $events);
}
sub Gtk3::Widget::render_icon {
my ($widget, $stock_id, $size, $detail) = @_;
Glib::Object::Introspection->invoke (
......@@ -2305,6 +2344,43 @@ sub _rest_to_ref {
}
}
package Gtk3::Gdk::EventMask;
use overload
'==' => \&eq,
'>=' => \&ge;
use Scalar::Util qw/looks_like_number/;
my $_convert_one = sub {
return Glib::Object::Introspection->convert_flags_to_sv (
'Gtk3::Gdk::EventMask', $_[0]);
};
my $_convert_two = sub {
my ($a, $b) = @_;
if (looks_like_number ($a)) {
$a = $_convert_one->($a);
}
if (looks_like_number ($b)) {
$b = $_convert_one->($b);
}
return ($a, $b);
};
sub eq {
my ($a, $b, $swap) = @_;
($a, $b) = $_convert_two->($a, $b);
return Glib::Flags::eq ($a, $b, $swap);
}
sub ge {
my ($a, $b, $swap) = @_;
($a, $b) = $_convert_two->($a, $b);
return Glib::Flags::ge ($a, $b, $swap);
}
package Gtk3;
1;
__END__
......
......@@ -7,7 +7,7 @@ use warnings;
use utf8;
use Encode;
plan tests => 224;
plan tests => 230;
note('Gtk3::CHECK_VERSION and check_version');
{
......@@ -600,6 +600,27 @@ SKIP: {
isa_ok (Gtk3::Label->find_style_property('interior-focus'), 'Glib::ParamSpec');
}
{
my $widget = Gtk3::Label->new ("Test");
$widget->set_events ([qw/enter-notify-mask leave-notify-mask/]);
ok ($widget->get_events >= [qw/enter-notify-mask leave-notify-mask/],
'$widget->set_events|get_events');
$widget->add_events ([qw/button-press-mask/]);
ok ($widget->get_events >= [qw/button-press-mask enter-notify-mask leave-notify-mask/],
'$widget->add_events|get_events');
$widget->set_events (0);
ok ($widget->get_events == 0, '$widget->set_events|get_events with numeric 0');
ok ($widget->get_events == [], '$widget->set_events|get_events with numeric 0');
$widget->add_events (24);
ok ($widget->get_events == 24, '$widget->add_events|get_events with numeric 24');
ok ($widget->get_events == [qw/pointer-motion-hint-mask button-motion-mask/],
'$widget->add_events|get_events with numeric 24');
}
SKIP: {
skip 'atom stuff; missing annotations', 2
unless Gtk3::CHECK_VERSION(3, 2, 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment