Re: inserting ColorButton in CellRenderer ....
- From: "Roberto Alejandro Espí Muñoz" <teratux gmail com>
- To: andrew solvo ru
- Cc: gtkmm-list <gtkmm-list gnome org>
- Subject: Re: inserting ColorButton in CellRenderer ....
- Date: Wed, 26 Mar 2008 10:15:27 -0400
I tried the solution you provided, but didn't work. The cell still renders a black box ( from the default color in ColorButton ). Here's the implementation from what you told me:
Gtk::TreeViewColumn* new123 = new Gtk::TreeViewColumn( "Color" );
new123->pack_start( *zoneColorRenderer, true );
new123->add_attribute(zoneColorRenderer->property_color(), zoneModel.columnColor);
view->append_column( *new123 );
Gtk::TreeModel::Row row = *( referenceZones->append() );
row[zoneModel.columnStart] = 123;
row[zoneModel.columnEnd] = 456;
Gdk::Color color;
double red = 1;
double green = 0;
double blue = 0;
color.set_rgb_p( red, green, blue );
row[zoneModel.columnColor] = color;I created a custom TreeViewColumn and packed in it my CellRenderer. I related the thow attributes from the CellRenderer and the TreeModelColumn, and later initialized a row with the color yellow on that column.
Thanks ...
On Wed, Mar 26, 2008 at 5:53 AM, Andrew E. Makeev <
andrew solvo ru> wrote:
В Срд, 19/03/2008 в 10:58 -0400, Roberto Alejandro Espí Muñoz пишет:
> 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:
Of course it's empty.
You should draw button (rectangle), color rectangle, and only then text
layout inside.
But wait, you set layout as empty... If you don't need text, then you
shouldn't draw text layout at all.
>
> 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'
>
You should create your cell renderer and add new column "manually" to
TreeView.
Then add attribute:
TreeViewColumn* col = new TreeViewColumn( caption );
YourCellRenderer* cr = new YourCellRenderer();
column->pack_start( *cr, true );
column->add_attribute( cr->property_color(), yourColumnModel.columnColor );
-andrew
--
teratux
------------
http://teratux.blogspot.com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]