Re: [gtkmm] TreeView and callbacks



Hello, A little background:
When clicking on the text widget the signal handler is not called, also
when pressing the space bar when the text widget is highlighted will not
call the activated handler.

Things seem to work fine when clicking on the pixbuf, also the button
release event is called when expected all the time.

Attached is a simple example I wrote to show what is happening. It seems
the text widget is swallowing the events or something.

Steve
On Fri, 2002-08-02 at 14:42, Murray Cumming wrote:
> On Fri, 2002-08-02 at 18:53, Stephen M. Przepiora wrote:
> > If I try to hook up to signal_row_activated the call back will only be
> > called IF you double click on the cell with the Pixbuff renderer, and
> > will not do anything when double clicking on the text renderer cell.
> 
> If nobody offers a solution, then if you create a simple, compileable
> example, then I'll investigate that. But it needs to be
> simple-as-possible.
> 
> -- 
> Murray Cumming
> murrayc usa net
> www.murrayc.com
> 

#include <gtkmm.h>
//g++ -o treetest treetest.cc `pkg-config --cflags --libs gtkmm-2.0`

/*
	When clicking on the text widget the signal handler is not called, also
	when pressing the space bar when the text widget is highlited will not call the activated handler.
	Things seem to work fine when clicking on the pixbuf, also the button release event is called when expected.
*/
class ModelColumns:public
  Gtk::TreeModelColumnRecord
{
public:
  Gtk::TreeModelColumn <Glib::RefPtr <Gdk::Pixbuf> >icon;
  Gtk::TreeModelColumn <Glib::ustring> name;
  Gtk::TreeModelColumn <bool> editable;
  ModelColumns ()
  {
    add (icon);
    add (name);
    add (editable);
  }
};

class App:public Gtk::Window
{
public:
	Gtk::TreeView tree;
	ModelColumns m_columns;
	Glib::RefPtr <Gtk::TreeStore >  model;

	App();

	bool on_cell_button_press_event(GdkEventButton * event)
	{
		cout << "on_cell_button_press_event called" << endl;
	};
	bool on_cell_button_release_event(GdkEventButton * event)
	{
		cout << "on_cell_button_release_event called" << endl;
	};
	void on_row_activated(const Gtk::TreePath& path, Gtk::TreeViewColumn* column)
	{
		cout << "on_row_activated called" << endl;
	};
};

App::App()
{
		//setup signal handlers
		tree.set_events(tree.get_events() | Gdk::BUTTON_PRESS_MASK);
		tree.signal_button_press_event().connect(SigC::slot(*this,&App::on_cell_button_press_event));
		tree.signal_button_release_event().connect(SigC::slot(*this,&App::on_cell_button_release_event));
		tree.signal_row_activated().connect(SigC::slot(*this,&App::on_row_activated));

		//set up the columns in the view
		Gtk::CellRendererPixbuf* iconrenderer = Gtk::manage(new Gtk::CellRendererPixbuf());
		Gtk::TreeViewColumn* iconcolumn = Gtk::manage(new Gtk::TreeViewColumn("Icon", *iconrenderer));
		iconcolumn->pack_start(m_columns.icon, false);
		tree.append_column(*iconcolumn);
	
		Gtk::CellRendererText* namerenderer = Gtk::manage(new Gtk::CellRendererText());
		Gtk::TreeViewColumn* namecolumn = Gtk::manage(new Gtk::TreeViewColumn("Name", *namerenderer));
		namecolumn->add_attribute(namerenderer->property_text(),  m_columns.name);
		namecolumn->add_attribute(namerenderer->property_editable(), m_columns.editable);
		tree.append_column(*namecolumn);
		
		//setup the model
		model = Gtk::TreeStore::create (m_columns);
		tree.set_model(model);
		Gtk::TreeRow row = *(model->append());
		Glib::RefPtr < Gdk::Pixbuf > icon;
		//root item
		row[m_columns.icon] = icon;
		row[m_columns.name] = "root";
		row[m_columns.editable] = true;
		//root items children
		Gtk::TreeRow child_row = *(model->append(row.children()));
		child_row[m_columns.icon] = icon;
		child_row[m_columns.name] = "child1";
		child_row[m_columns.editable] = true;
		
		child_row = *(model->append(row.children()));
		child_row[m_columns.icon] = icon;
		child_row[m_columns.name] = "child2";
		child_row[m_columns.editable] = true;
		
		child_row = *(model->append(row.children()));
		child_row[m_columns.icon] = icon;
		child_row[m_columns.name] = "child3";
		child_row[m_columns.editable] = true;
		
		tree.show();
		add(tree);
}

int main(int argc, char* argv[])
{
	Gtk::Main kit(argc, argv);
	App app;
	kit.run(app);
	return 0;
}



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