Re: CellRendererSpinButton




Jens Wilke said:
On Friday 09 July 2004 04:51, muppet wrote:

what are you wanting to do with this size?

look at this, you will immediately realize, what i want:
http://photo.wilke.org/gtk-gallery/img/shot-olist.jpg

oi!  that's funny looking.  ;-)


can you not get it
normally, e.g. $spin_button->allocation?

Is there any docu for allocation?

it's just a Gtk2::Gdk::Rectangle describing the widget's currently allocated
size.  from Gtk2::Widget:

       allocation = $widget->allocation

           Returns $widget?s current allocated size as a read-only rectangle;
           the allocated size is not necessarily the same as the requested
           size.

this implies that the widget must be realized and shown.


I tried the following:
In RENDERER i use $widget -> get_style -> paint_layout
which works fine for the cellrenderer, but can't get it working on the
spinbutton in START_EDITING, because thers's no $window variable set,
which is need by paint_layout...

well, you don't get to draw the editing widget; we return an editable to gtk+,
and it resizes and maps that editable by the cell's area.  so, the trick is to
tell the system that the cell's area is only as tall as the spinbutton:

  $spin_button -> show_all();

  # we don't want the editor widget to be the full height of the cell;
  # if the cell is taller than the spinbutton, the entry will grow, but
  # the spinner buttons won't.  tell the system that the cell is only
  # as tall as the spinbutton wants to be, and it will do the right thing.
  # this means we have to ask the spinbutton how big it wants to be; it
  # hasn't been mapped yet, so we'll have to trigger an actual size_request
  # calculation.
  my $requisition = $spin_button->size_request;
  $cell_area->height ($requisition->height);


in my testcase (adding a 72x72 pixbuf column to cellrenderer_spinbutton.pl)
the cell text is top-aligned, and i don't see a way to change that.  how did
you get the centered stuff?  i imagine that if you need the cell to be
centered, you'll have to add (height-spinbuttonheight)/2 to the y position of
the cell area to get it properly centered.


I changed the event handler from "key_press" to "focus_out" to have
better usability:

how do you mean better usability?

You won't loose the new value, if you leave the cell without pressing
return (When selecting another row with the mouse)

aaaaah...  that's a good thing.  ;-)

in the same way that people who usually drive with the mouse overlook keyboard
navigation, i usually drive with the keyboard and overlook mousey things.


the code you posted makes the up
and down arrows close the editor widget rather than change the value,

ok, i just lost the key bindings, should be included again.

the assertion comes out because the entry (the spinbutton is an entry) really
really wants to have a parent when it's being destroyed, and needs to have its
default focus-out handler called (among other things, it has to uninstall the
timeout that blinks the cursor); by returning true from the handler you were
preventing that from doing proper cleanup somehow.

my first instinct was to try to keep the id for the focus-out handler and
uninstall it when we're finished; a look at the code for GtkCellRendererText
in gtk+ itself shows that this is exactly what they do.  ;-)

first, instead of emitting 'edited' by hand in the key-press handler, use a
helper function:

  sub _editing_done {
    my ($self, $path, $new_value) = @_;
    if ($self->{_focus_out_id}) {
      $self->signal_handler_disconnect ($self->{_focus_out_id});
      delete $self->{_focus_out_id};
    }
    $self->signal_emit('edited', $path, $new_value);
  }

and then add new code to START_EDITING:

    $spin_button->{_focus_out_id} =
      $spin_button -> signal_connect(focus_out_event => sub {
        my (undef, $event) = @_;
        $cell -> _editing_done ($path, $spin_button -> get_value());
        # the spinbutton needs the focus-out event, don't eat it.
        return 0;
      });

that appears to work as expected.


if you like the key handling i posted last night, i'll commit all of this
stuff this evening when i get home.

-- 
muppet <scott at asofyet dot org>



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