Jeff Hallock wrote:
--
| PROJECT TITLE | \/ |
--
--
| PROJECT TITLE|
| Brief Description |
||
| PROJECT TITLE|
| Brief Description |
--
I was going to answer: use a custom cell renderer that behaves differently
depending on whether $combo_box-get('popup-shown') is true or not. As in the
attached example.
Unfortunately, popup-shown is still false when the relevant GET_SIZE() calls are
made on the renderer, so this approach doesn't work. So, I see no way to
achieve what you want.
-Torsten
package CustomRenderer;
use Glib qw(TRUE FALSE);
use Gtk2;
use Glib::Object::Subclass
Gtk2::CellRendererText::,
properties = [
Glib::ParamSpec-object ('combo-box', 'Combo Box',
'The combo box for which we are rendering',
Gtk2::ComboBox::, ['readable', 'writable']),
Glib::ParamSpec-string ('extra-text', 'Extra Text',
'The extra text to display in the popup',
undef, ['readable', 'writable']),
],
;
use constant xpad = 3;
use constant ypad = 2;
sub calc_size {
my ($cell, $layout) = @_;
my ($w, $h) = $layout-get_pixel_size;
return (0, 0, $w + xpad * 2, $h + ypad * 2);
}
sub get_text {
my ($cell) = @_;
if ($cell-get ('combo-box')-get ('popup-shown')) {
return $cell-get ('text') . \n . $cell-get ('extra-text');
} else {
return $cell-get ('text');
}
}
sub get_layout {
my ($cell, $widget) = @_;
return $cell-{layout} if defined $cell-{layout};
return $cell-{layout} = $widget-create_pango_layout ();
}
sub GET_SIZE {
my ($cell, $widget, $area) = @_;
warn GET_SIZE: , $cell-get ('combo-box')-get ('popup-shown'), \n;
my $layout = $cell-get_layout ($widget);
$layout-set_text ($cell-get_text ());
return $cell-calc_size ($layout);
}
sub RENDER {
my ($cell, $drawable, $widget, $background_area, $cell_area, $expose_area, $flags) = @_;
warn RENDER: , $cell-get ('combo-box')-get ('popup-shown'), \n;
my $state = 'normal';
if ($flags 'selected') {
$state = $widget-has_focus
? 'selected'
: 'active';
} else {
$state = $widget-state eq 'insensitive'
? 'insensitive'
: 'normal';
}
my $layout = $cell-get_layout ($widget);
$layout-set_text ($cell-get_text ());
my ($xoff, $yoff, $width, $height) = $cell-calc_size ($layout);
$widget-get_style-paint_layout ($drawable,
$state,
1, $cell_area,
$widget, cellrenderertext,
$cell_area-x + $xoff + xpad,
$cell_area-y + $yoff + ypad,
$layout);
}
package main;
use Gtk2 -init;
my $model = Gtk2::ListStore-new (qw/Glib::String Glib::String/);
foreach (grep /gtk-go/, Gtk2::Stock-list_ids) {
$model-set ($model-append, 0 = $_, 1 = uc $_);
}
my $combo = Gtk2::ComboBox-new ($model);
my $renderer = CustomRenderer-new ('combo-box' = $combo);
$combo-pack_start ($renderer, FALSE);
$combo-set_attributes ($renderer, text = 0, extra_text = 1);
my $window = Gtk2::Window-new;
$window-add ($combo);
$window-show_all;
Gtk2-main;
___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list