Re: How to install a new "property"?



> > class MyClass : public Glib::Object
> > {
> > ...
> > public:
> >     Glib::PropertyProxy<void *> property_data()
> {return
> > property_data_.get_proxy(); }
> > private:
> >     Glib::Property<void *> property_data_;
> > ...
> > };
Thanks. That is what I am looking for. It is actually
shown in the source codes of customcellrender in the
example. I should have read that. 

I finished the "captioned image" cellrender, as shown
in Anjuta's preferences window. Actually, a big part
of codes are translated from the C codes in anjuta
project.
The codes are listed below, and wish it could be
useful by any chance.



/****Howto use it*****/
class ModelColumns :
publicGtk::TreeModel::ColumnRecord
{
public:
ModelColumns()
{ add(m_icon); add(m_caption); add(m_data); }
		Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf> >  
m_icon;
			Gtk::TreeModelColumn<std::string>   m_caption;
Gtk::TreeModelColumn<void*>   m_data;
};
ModelColumns m_Columns;

/* ...... add the column ....*/
CellRenderer_CaptionedImage* render = Gtk::manage( new
CellRenderer_CaptionedImage());
int cols_count=m_table_view.append_column("Whatever",
*render);
Gtk::TreeViewColumn* pColumn =
m_table_view.get_column(cols_count-1);
if(pColumn) 
{
pColumn->add_attribute(render->property_pixbuf(),m_Columns.m_icon);
pColumn->add_attribute(render->property_text(),m_Columns.m_caption);
}
/* ...... add a row ....*/
Gtk::TreeRow row = *m_list_store->append ();
//an image (pixbuf), say, return of render_icon(...)
row[m_Columns.m_icon]=pixbuf;
row[m_Columns.m_caption]="caption";
//some private data, say, a page widget of a notebook
row[m_Columns.m_data]=data; 
##################################################################

#define PAD 3
#define SPACE 5
class CellRenderer_CaptionedImage: public
Gtk::CellRenderer
{
public:
  CellRenderer_CaptionedImage();
  Glib::PropertyProxy<Glib::ustring> property_text()
  {return property_text_.get_proxy();}
  Glib::PropertyProxy< Glib::RefPtr<Gdk::Pixbuf> >  
property_pixbuf()
  {return property_pixbuf_.get_proxy();}
protected:
   virtual void get_size_vfunc(Gtk::Widget& widget,
const Gdk::Rectangle* cell_area, int* x_offset, int*
y_offset, int* width, int* height) const;
   virtual void render_vfunc(const
Glib::RefPtr<Gdk::Drawable>& window, Gtk::Widget&
widget, const Gdk::Rectangle& background_area, const
Gdk::Rectangle& cell_area, const Gdk::Rectangle&
expose_area, Gtk::CellRendererState flags);

private:
  Glib::Property<Glib::ustring> property_text_;
  Glib::Property<Glib::RefPtr<Gdk::Pixbuf> >
property_pixbuf_;
  mutable Gtk::CellRendererText* m_caption;
  mutable Gtk::CellRendererPixbuf* m_pixbuf;
};
	

CellRenderer_CaptionedImage::CellRenderer_CaptionedImage():

Glib::ObjectBase(typeid(CellRenderer_CaptionedImage)),
Gtk::CellRenderer(),
property_text_ (*this, "text"),
property_pixbuf_(*this,"pixbuf"),
m_caption(Gtk::manage(new Gtk::CellRendererText())),
m_pixbuf(Gtk::manage(new Gtk::CellRendererPixbuf()))
{
}
	
void
CellRenderer_CaptionedImage::get_size_vfunc(Gtk::Widget&
widget, const Gdk::Rectangle* cell_area, int*
x_offset, int* y_offset, int* width, int* height)
const
{
int
text_x_offset,text_y_offset,text_width,text_height;
int pixbuf_x_offset, pixbuf_y_offset, 
pixbuf_width,pixbuf_height;

Gdk::Rectangle temp_cell_area;
	
m_pixbuf->property_pixbuf()=property_pixbuf_.get_value();
	
m_caption->property_text()=property_text_.get_value();
	
m_pixbuf->get_size(widget,temp_cell_area,pixbuf_x_offset,pixbuf_y_offset,pixbuf_width,pixbuf_height);
	   
m_caption->get_size(widget,temp_cell_area,text_x_offset,text_y_offset,text_width,text_height);
if (height) {
*height = pixbuf_height + text_height + PAD;
}
if (width) {
*width = MAX (pixbuf_width, text_width);
*width += SPACE * 2;
}
}

void CellRenderer_CaptionedImage::render_vfunc(const
Glib::RefPtr<Gdk::Drawable>& window, Gtk::Widget&
widget, const Gdk::Rectangle& background_area, const
Gdk::Rectangle& cell_area, const Gdk::Rectangle&
expose_area, Gtk::CellRendererState flags)
{
Gdk::Rectangle text_area, pixbuf_area;
int width, height,x_offset,y_offset;	
m_pixbuf->property_pixbuf()=property_pixbuf_.get_value();
m_caption->property_text()=property_text_.get_value();
m_pixbuf->get_size(widget,cell_area,x_offset,y_offset,width,height);
		pixbuf_area.set_y( cell_area.get_y());
		pixbuf_area.set_x( cell_area.get_x());
		pixbuf_area.set_height(height);
		pixbuf_area.set_width       
(cell_area.get_width());
		m_caption->get_size(widget,
cell_area,x_offset,y_offset,width,height);
		text_area.set_x(cell_area.get_x() +
(cell_area.get_width() - width) / 2);
		text_area.set_y(cell_area.get_y() +
(pixbuf_area.get_height() + PAD));
		text_area.set_height(height);
		text_area.set_width(width);
/*
m_pixbuf->render(window,widget,background_area,
pixbuf_area, expose_area, flags);
m_caption->render(window, widget,background_area,
text_area, expose_area, flags);
*/		  
	
gtk_cell_renderer_render((GtkCellRenderer*)m_pixbuf->gobj(),
Glib::unwrap(window), (widget).gobj(),
const_cast<GdkRectangle*>(background_area.gobj()),
const_cast<GdkRectangle*>(pixbuf_area.gobj()),
const_cast<GdkRectangle*>(expose_area.gobj()),
((GtkCellRendererState)(flags)));
	
gtk_cell_renderer_render((GtkCellRenderer*)m_caption->gobj(),
Glib::unwrap(window), (widget).gobj(),
const_cast<GdkRectangle*>(background_area.gobj()),
const_cast<GdkRectangle*>(text_area.gobj()),
const_cast<GdkRectangle*>(expose_area.gobj()),
((GtkCellRendererState)(flags)));
}





----------------------------------------------------------
Have fun!
__________________________________________________________


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/ 



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