simplelist and custom cell renderers


I'm building an application which displays a list, using SimpleList, of
modules, each row has the module name and a checkbox which tells whether
to use the module on that row. The catch is that I must use checkboxes
with the 'inconsistent' property to indicate modules that must be forced
due to dependencies.

So at first I created a new column type to display the checkbox with the
inconsistent state base on the data placed on the simplelist:

         type     => 'Glib::Scalar',
         renderer => 'MyCheckboxCellRenderer',
         attr     => sub {
              my ($treecol, $cell, $model, $iter, $col_num) = @_;

          my $val = $model->get ($iter, $col_num);
          $cell->set (inconsistent => ($val < 0), active => $val > 0);

Trouble is, now I couldn't toggle the checkboxes. So I headed off to
create a new cell renderer. I managed to make them togglable, but now I
can't figure out how to change the data back in the list. Actually, I
can't really toggle them properly since I'm using the hack of calling
$simplelist->get_selected_indices to find which row is selected, so I
can toggle only the row that I clicked previously.

There has to be a simpler way, but I can't figure out which of the rows
is being clicked on. How do I find that out?

Here's my code for the cell renderer:

package MyCheckboxCellRenderer;

use strict;

use Gtk2;

use Glib::Object::Subclass
   signals => { },
   properties => [ ];

   my $self = shift;
   my ($cell, $event, $widget, $path, $background_area, $cell_area,
$flags) = @_;

   my $idx = ($event->get_selected_indices) [0];
   if ($event->{data}->[$idx]->[0] >= 0) { # toggle?
       $event->{data}->[$idx]->[0] = ($event->{data}->[$idx]->[0] + 1) % 2;

   return 1;

Thanks in advance!

Cristóvão Dalla Costa
cbraga freedows com

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