Ok, I decided to try and insert the ColorButton widget in the TreeView. I
declared in my CellRendererColorButton class the thow functions that are
needed for the rendering.
void get_size_vfunc ( Gtk::Widget& widget,
const Gdk::Rectangle* cell_area,
int * x_offset,
int * y_offset,
int * width,
int * height
)
{
Glib::RefPtr<Pango::Layout> ptrLayout =
widget.create_pango_layout( "Hello" );
Pango::Rectangle rect = ptrLayout->get_pixel_logical_extents();
const int calc_width = 2 * 4 + rect.get_width();
const int calc_height = 2 * 4 + rect.get_height();
std::cout << "Done" << std::endl;
*width = calc_width;
*height = calc_height;
if( cell_area )
{
if( x_offset )
{
*x_offset = int( property_xalign() *
( cell_area->get_width() -
this->button->get_width() ) );
*x_offset = std::max( 0, *x_offset );
}
if( y_offset )
{
*y_offset = int( property_yalign() *
( cell_area->get_height() -
this->button->get_height() ) );
*y_offset = std::max( 0, *y_offset );
}
}
and
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
)
{
int x_offset = 0, y_offset = 0, width = 0, height = 0;
get_size( widget, cell_area, x_offset, y_offset, width, height
);
Gtk::StateType state;
if( ( flags & Gtk::CELL_RENDERER_SELECTED ) != 0 )
{
state = Gtk::STATE_SELECTED;
}
else
{
state = Gtk::STATE_NORMAL;
}
Gdk::Color bgColor;
bgColor.set_rgb_p( 1, 0.5, 0.5 );
// Glib::RefPtr< Gdk::GC > gc =
Gdk::GC::create( window );
// gc->set_rgb_bg_color( bgColor
);
//
// window->draw_rectangle( gc,
// true,
//
background_area.get_x(),
//
background_area.get_y(),
//
background_area.get_width(),
//
background_area.get_height() );
Glib::RefPtr<Gdk::Window> win =
Glib::RefPtr<Gdk::Window>::cast_dynamic( window );
Glib::RefPtr< Pango::Layout > ptrLayout =
widget.create_pango_layout( "" );
widget.get_style()->paint_layout
( win,
state,
true,
cell_area,
widget,
"cellrenderertext",
cell_area.get_x() + x_offset,
cell_area.get_y() + y_offset,
ptrLayout );
Glib::RefPtr< Gdk::GC > gc = Gdk::GC::create( window );
gc->set_rgb_fg_color( bgColor );
window->draw_rectangle( gc,
true,
background_area.get_x(),
background_area.get_y() + 1,
background_area.get_width(),
3 );
window->draw_rectangle( gc,
true,
background_area.get_x(),
background_area.get_y() + background_area.get_height() -
4,
background_area.get_width(),
3 );
std::cout << "By here" << std::endl;
}
But the cell appears empty. Here are is the model I defined:
class ZoneModel : public Gtk::TreeModel::ColumnRecord
{
public:
ZoneModel()
{
add(columnStart);
add(columnEnd);
add(columnColor);
}
Gtk::TreeModelColumn< int > columnStart;
Gtk::TreeModelColumn< int > columnEnd;
Gtk::TreeModelColumn< Gdk::Color > columnColor;
};
ZoneModel zoneModel;
Glib::RefPtr<Gtk::ListStore> referenceZones;
CellRendererColorButton* zoneColorRenderer;
When I try assign the color value to the model I get this warning from gtk:
unable to set property `text' of type `gchararray' from value of type
`GdkColor'
Can anyone help me??
Thanks
On Fri, Mar 14, 2008 at 11:10 AM, Andrew E. Makeev <[EMAIL PROTECTED]> wrote:
> В Птн, 14/03/2008 в 10:43 -0400, Roberto Alejandro Espí Muñoz пишет:
> > Ok I saw it .. What I don't understand is why do you have to paint the
> > widget from scratch?? and check if it is active, or toggled to paint
> > that particular behaviour?? isn't there a simpler way to just add it
> > to the cell and call the widget's own paint function?? The widget I
> > want is a little more complex it has an inner rectangle showing the
> > current color.
>
> Because it is not QT :).
>
> TreeView was designed to hold and show lot of data from TreeModel. If
> each cell was represented as widget it could increase CPU usage
> dramatically and slow down the View.
>
> So, you must to draw the widget "from scratch" using cell area. There is
> no other way.
>
> The states and flags I am checking is used to draw my cell properly -
> selected, checked/toggled, etc.
>
> See GTK sources.
>
> -andrew
>
>
>
--
teratux
------------
http://teratux.blogspot.com
_______________________________________________
gtkmm-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtkmm-list