Strange bug while subclassing Gtk2::Box



Hi,

For zim I'm working on a Gtk2::Ex::PathBar class to implement a path bar that looks like the one that is found in the gtk filechooser. Now I have a strange bug. My implementation works perfectly fine on my own system which runs archlinux. But I now get bug reports from people with gentoo and slackware systems that my widget doesn't render properly. I tried comparing the versions for both gtk+ and gtk2-perl running on those systems, as well as compile time options but I didn't find anything except for the fact that it works on one distro but not on the other.

The problem is this: my widget is a subclass of Gtk2::Box which implements size_request and size_allocate. Now on some systems it justs works, on other systems it doesn't. When it doesn't the buttons are allocated but they don't show up in the widget. But they are there, they are clickable - they just don't show.

The code below reproduces the problem. If you do see the buttons that means you have one of the systems where it just works, if you see an empty space try clicking it, you should see output from the buttons being clicked in your terminal.

I really hope someone can tell me how to fix this.

-- Jaap <pardus cpan>





#!/usr/bin/perl

package MyBox;

use strict;
use Gtk2;
use Glib::Object::Subclass
        Gtk2::Box::,
        signals => {
                size_request => \&do_size_request,
                size_allocate => \&do_size_allocate,
        };

sub do_size_request {
        # get minimum required size and store it in $requisition
        my ($self, $requisition) = @_;
        my ($height, $width) = (0, 0);
        for ($self->get_children) {
                my $req = $_->size_request;
                my ($w, $h) = ($req->width, $req->height);
                $height = $h if $h > $height;
                $width += $w;
        }
        $requisition->height($height);
        $requisition->width($width);
}

sub do_size_allocate {
        # distribute given space to children
        my ($self, $allocation) = @_;
        my ($x, $y, $w, $h) = ($allocation->values);
        my $all = Gtk2::Gdk::Rectangle->new($x, $y, 0, $h); # x, y, w, h
        for ($self->get_children) {
                my $req = $_->size_request;
                my $req_w = $req->width;
                $all->width($req_w);
                $_->set_child_visible(1);
                $_->size_allocate($all);
                $all->x( $all->x + $req_w );
        }
}

package main;

use strict;
use Gtk2 '-init';

my $window = Gtk2::Window->new('toplevel');
$window->signal_connect(destroy => sub { Gtk2->main_quit });
my $box = MyBox->new;
$window->add($box);

for my $i (1 .. 5) {
        my $button = Gtk2::Button->new("Button $i");
        $button->signal_connect(
                clicked => sub {print "You clicked button $i\n"} );
        $box->add($button);
}

$window->show_all;

Gtk2->main;

exit 0;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]