Re: [gtkmm] Any easy way to write a cell renderer with a combo box it it.

Thanks for the hint. 

Finally I worked out my combo cell renderer after
studying the example codes. 
Since I wrap a combo directly and thus I do not have
to handle the popup issues, the codes are much simpler
than in the gtkmm example. 
But there is still one thing I do not understand. 
What is the "Glib::ObjectBase (typeid
(CMy_Combo_Editable))" for(marked in the soruces
below)? If I remove that it, I got an error that says:

(test: 4937): Gtk - CRITICAL **: file
gtktreeviewcolumn.c: line 2500
GTK_IS_CELL_EDITABLE (*editable_widget)' failed

It looks to me the line registers the class to
somewhere. Is that right? I found a lot of mystery
stuffs(to me) like this in the gtkmm source codes, and
it was really hard to figure out a big image. Is there
any document around about these "gtkmm internals" ?

The source of my combo renderer is following. The
"spinbox" cell renderer can also be 
implemented in this way, and is actually easier(Do not
need an extra editable widget). 

class CMy_Combo_Editable:
public Gtk::EventBox,public Gtk::CellEditable
            Gtk::Combo combo_;
            CMy_Combo_Editable (std::list <
std::string > &items):
            Glib::ObjectBase (typeid
                Gtk::EventBox (),
                Gtk::CellEditable ()
                get_entry ()->set_has_frame (false);
                combo_.set_popdown_strings (items);
                add (combo_);
            Gtk::Entry * get_entry ()
                return combo_.get_entry ();
            void set_editable (bool editable)
                get_entry ()->set_editable (editable);
            virtual void start_editing_vfunc (GdkEvent
* event)
                get_entry ()->start_editing (event);
            virtual void on_editing_done ()
                get_entry ()->editing_done ();

class CMy_Combo_CellRenderer:public 
        void add_item (std::string str)
            items.push_back (item);
        void clear ()
            items.clear ();
        std::list < std::string > items;
        virtual Gtk::CellEditable *
start_editing_vfunc (GdkEvent * event,
            Gtk::Widget & widget, const Glib::ustring
& path,
            const Gdk::Rectangle & background_area,
            const Gdk::Rectangle & cell_area,
            if (!property_editable ())
                return NULL;
            CMy_Combo_Editable * combo =
                Gtk::manage (new CMy_Combo_Editable
            Glib::ustring text = property_text ();
            Gtk::Entry * entry = combo->get_entry ();
            entry->property_editable () = true;
            entry->set_text (text);
            entry->select_region (0, -1);
(bind(SigC::slot (*this, &CMy_Combo_CellRenderer::
on_edited), entry, path));
            combo->show ();
            return combo;
        virtual void on_edited (Gtk::Entry * entry,
Glib::ustring path)
            Glib::ustring old_text = property_text ();
            Glib::ustring new_text = entry->get_text
            if ( (old_text) != 0)
                edited (path, new_text);

void treeView_add_column(Gtk::TreeView& treeview,
const Glib::ustring& title, Gtk::CellRendererText*
render, Gtk::TreeModelColumn<ColumnType>&
	int cols_count=treeview.append_column(title,
	Gtk::TreeViewColumn* pColumn =

CMy_Combo_CellRenderer* render0=Gtk::manage(new
treeView_add_column(m_list_table, "Students", render0,

--- Daniel Elstner <daniel elstner gmx net> wrote:
> On Fre, 2003-01-10 at 02:05, ZHOU DX wrote:
> > Hi everyone, 
> > 
> > Since Gtk::combo is neither a Gtk::CellEditable or
> > Gtk::Editable, it is not straightforward to fit it
> > into the Treeview interface as a cell renderer. I
> > tried to write a new "editable" widget that wraps
> a
> > combo, but it looks like I have to write a
> > correponding widget_Class to declare the widget as
> > editable which is really a pain.  
> > Anyone knows a easy way to do that?
> You have to implement your own cell renderer. 
> Luckily, it has already
> been done: have a look at
> examples/cellrenderercustom/
> --Daniel

Have fun!

Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.

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