Re: Trying hard with a custom cellrenderer.
- From: "Andrew E. Makeev" <andrew solvo ru>
- To: Germán Diago <germandiago gmail com>
- Cc: gtkmm-list gnome org
- Subject: Re: Trying hard with a custom cellrenderer.
- Date: Thu, 01 Jul 2010 17:10:30 +0400
There is only template specialization for "standart" types of
TreeModelColumn, such as <int>, <ustring>, <void*>, etc.
To use <URL*> template you must specialize it yourself using Gtk
namespace. And implement all functions to get/set value from/into cell,
I guess.
I suggest, you to use <void*> template and override
render/get_size-_vfunc() where get value from property with:
void* ptr = property_url();
URL* url = reimplement_cast< URL* >( ptr );
Either use TreeViewColumn::set_cell_data_func().
Regards,
В Чтв, 01/07/2010 в 13:34 +0200, Germán Diago пишет:
> Partially solved:
>
> #include <gtkmm.h>
> #include <string>
> #include <iostream>
>
>
> using namespace Gtk;
>
>
> class URL {
> std::string url_;
> public:
> explicit URL(const std::string & url) : url_(url) {}
> const std::string & getAsString() const { return url_; }
> };
>
>
> class URLCellRenderer : public Gtk::CellRendererPixbuf {
> private:
> // the property whose value will be set by Gtk before a cell is rendered
> Glib::Property<Glib::ustring> property_url_;
> OffscreenWindow osw_;
> Gtk::Button button_;
> Gtk::Image img_;
>
> public:
> URLCellRenderer() : Glib::ObjectBase(typeid(URLCellRenderer)),
> Gtk::CellRendererPixbuf(), property_url_ (*this, "url"),
> img_(Gtk::Stock::MEDIA_PLAY, Gtk::ICON_SIZE_BUTTON)
> {
> button_.set_image(img_);
>
> osw_.add(button_);
> osw_.show_all();
> property_pixbuf() = osw_.get_pixbuf();
> }
>
> void get_size_vfunc (Widget& widget,
> const Gdk::Rectangle* cell_area,
> int * x_offset,
> int * y_offset,
> int * width,
> int * height
> ) const
> {
> *width = property_pixbuf().get_value()->get_width();
> *height = property_pixbuf().get_value()->get_height();
> }
>
>
> void render_vfunc(Glib::RefPtr<Gdk::Drawable> const & window,
> Gtk::Widget& widget,
> Gdk::Rectangle const & background_area,
> Gdk::Rectangle const & cell_area,
> Gdk::Rectangle const & expose_area,
> Gtk::CellRendererState flags) {
> property_pixbuf() = osw_.get_pixbuf();
> CellRendererPixbuf::render_vfunc(window, widget,
> background_area, cell_area, expose_area, flags);
> }
> };
>
>
> class Cols : public Gtk::TreeModelColumnRecord {
> public:
> Cols() { add(name); add(url); }
>
> TreeModelColumn<Glib::ustring> name;
> TreeModelColumn<Glib::ustring> url;
> };
>
>
> int main (int argc, char* argv[])
> {
> Gtk::Main m(&argc, &argv);
> Cols c;
> URL location("http://www.uji.es");
>
> auto store = ListStore::create(c);
> TreeView view(store);
> CellRendererText cellr;
> URLCellRenderer cellr2;
>
> TreeViewColumn tvcol("Name");
> TreeViewColumn tvcol2("Location");
>
> view.append_column(tvcol);
> view.append_column(tvcol2);
>
> tvcol.pack_start(cellr);
> tvcol.add_attribute(cellr, "text", c.name);
>
> tvcol2.pack_start(cellr2, false);
> //tvcol2.add_attribute(cellr2, "url", c.url);
>
> view.set_headers_visible(true);
> Gtk::Window window;
> window.add(view);
>
>
> auto iter = store->append();
> iter->set_value(c.name, Glib::ustring("Germán"));
> iter->set_value(c.url, Glib::ustring(location.getAsString()));
>
> window.show_all();
> Main::run(window);
> return 0;
> }
>
>
> If someone could tell me how to use a Gtk::TreeModelColumn<URL *>
> instead of Glib::ustring I would be happy. This works, but
> it's not exactly what I had in my head. Thanks.
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
--
Andrew E. Makeev <andrew solvo ru>
Solvo Logistic
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]