Hi, all

When i extends Gtk::CellRenderer from the gems of
http://rubygems.org/gems/gtk2 ¡ÊMS Windows), i got some error messages as
followed:
Gtk-CRITICAL **:gtk_cell_renderer_get_size: assertion
`GTK_CELL_RENDERER_GET_CLASS (cell)->get_size != NULL' failed
Gtk-CRITICAL **:gtk_cell_renderer_render: assertion
`GTK_CELL_RENDERER_GET_CLASS (cell)->render != NULL' failed

I think they must caused by the methods such as
gtk_cell_renderer_get_size of GTK+:
g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->get_size != NULL);

Maybe that means my custom cell renderer(Here as CellRendererRow, for
different cell renderer per row in the same column)'s get_size cann't be
recognized by GTK+.

I know i have use the 'type_register ' to register the CellRendererRow
to GTK+, but has there some way to register the methods such as
get_size, or we only need to name the method as do_get_size like
Python/GTK, but how to name the method in Ruby?

The followed is my source code(CellRendererRow.rb):


begin
  require 'rubygems'
rescue LoadError
end

require 'gtk2'
require 'glib2'

class CellRendererRow < Gtk::CellRenderer
  type_register

  install_property(GLib::Param::String.new(
                           "cell_type",
                           "cell_type",
                           "The type of the cell renderer",
                           "",
                           GLib::Param::READABLE|GLib::Param::WRITABLE))

  install_property(GLib::Param::String.new(
                       "cell_value",
                       "cell_value",
                       "The value of the cell renderer",
                       "",
                       GLib::Param::READABLE|GLib::Param::WRITABLE))

  PIXBUF   = "1"
  PROGRESS = "2"
  SPIN     = "3"
  TEXT     = "4"
  TOGGLE   = "5"

  attr_reader :cell_type, :cell_value

  def initialize(treeview)
    super()
    @treeview = treeview
    @comb_renderers = Hash.new
    @pixbuf = Gtk::CellRendererPixbuf.new
    @spin = Gtk::CellRendererSpin.new
    @text = Gtk::CellRendererText.new
    @toggle = Gtk::CellRendererToggle.new
  end

  def cell_type= (s)
    puts "cell type is: " + s
    @cell_type = s
  end

  def cell_value= (s)
    puts "cell value is: " + s

    @s = s
    case cell_type
      when  PIXBUF
        @pixbuf.pixbuf = s
      when  SPIN
        @spin.adjustment = s
      when  TEXT
        @text.text = s
      when  TOGGLE
        @toggle.active = s
      else
        cellrenderer = @comb_renderers.fetch(cell_type, @text)
        cellrenderer.text = s
    end
  end

  def renderer
    cellrenderer = case cell_type
                     when  PIXBUF
                       @pixbuf
                     when  SPIN
                       @spin
                     when  TEXT
                       @text
                     when  TOGGLE
                       @toggle
                     else  @comb_renderers.fetch(cell_type, @text)
                   end
  end

  def get_size(widget, cell_area)
    cellrenderer = renderer
    puts cellrenderer.class
    cellrenderer.get_size(widget, cell_area)
  end

  def render(window, widget, background_area, cell_area, expose_area,
flags)
    cellrenderer = renderer
    puts cellrenderer.class
    cellrenderer.render(window, widget, background_area, cell_area,
expose_area, flags)
 end

end

Attachments:
http://www.ruby-forum.com/attachment/8599/CellRendererRow.rb