Re: Combo Box Setup

2008-10-26 Thread Torsten Schoenfeld

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


Combo Box Setup

2008-10-21 Thread Jeff Hallock
I'm hoping that this is possible with the ComboBox widget. What I want is to 
display different text in the drop-down than what is displayed when an entry is 
selected.

Example:

--
|   PROJECT TITLE   | \/ |
--
--
|   PROJECT TITLE|
| Brief Description  |
||
|   PROJECT TITLE|
| Brief Description  |
--

Also, can anyone clue me in on the functionality of the row_span_column and 
columns_span_column - no behavior change was apparent to me.
Jeffrey Hallock
Data Processing Programmer
WBA Market Research
2191 Defense Highway, Suite 401
Crofton, MD  21114
Phone:  (607) 330-5300 x318
Fax:  (607) 273-0295
[cid:image001.jpg@01C9339A.E8511D60]
This email may contain information that is confidential or privileged.  If you 
are not the intended recipient, any use, disclosure, copying or distribution of 
this message or any attachments is strictly prohibited.  If you have received 
this message in error, please notify the sender and destroy any and all copies. 
 Thank you.

inline: image001.jpg___
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list