- Fix drawing of widget background. Now I'll move the code to

an abstract base class, and I'll start working out the 
adjustement / resizing problems (they're not easy to work out 
correctly).


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@822 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-08-04 19:12:17 +00:00
parent 974702af3e
commit 2174c25f74
3 changed files with 315 additions and 529 deletions

View file

@ -53,6 +53,8 @@ SchedulablesWidget::~SchedulablesWidget()
void
SchedulablesWidget::update(const History& history)
{
// get_window() returns a null pointer
// if the widget has not been realized
if(!is_realized())
return; // Nowhere to draw to.
@ -60,10 +62,17 @@ SchedulablesWidget::update(const History& history)
unsigned int w = get_allocation().get_width();
_h = calc_height(history);
// get_window() returns a null pointer
// if the widget has not been realized
_buf = Gdk::Pixmap::create(get_window(), w, _h);
// Draw the widget background as the first thing.
// I've seen this is how it's done in the very Gtk+ toolkit
// for the GtkProgressBar widget.
GtkStyle* gStyle = get_style()->gobj();
gtk_paint_box(gStyle, _buf->gobj(),
GTK_STATE_NORMAL, GTK_SHADOW_ETCHED_IN,
NULL, this->gobj(), "through",
0, 0, w, _h);
cairo_t* ctx = gdk_cairo_create(_buf->gobj());
// do the drawing...
@ -118,18 +127,23 @@ SchedulablesWidget::on_realize()
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.event_mask = get_events() | GDK_EXPOSURE_MASK;
attributes.window_type = GDK_WINDOW_CHILD;
attributes.visual = get_visual()->gobj();
attributes.colormap = get_colormap()->gobj();
static const gint attributes_mask = Gdk::WA_X | Gdk::WA_Y | Gdk::WA_WMCLASS
| Gdk::WA_VISUAL | Gdk::WA_COLORMAP;
Glib::RefPtr<Gdk::Window> window = Gdk::Window::create(get_parent_window(),
&attributes,
Gdk::WA_X | Gdk::WA_Y |
Gdk::WA_WMCLASS);
unset_flags(Gtk::NO_WINDOW);
attributes_mask);
unset_flags(Gtk::NO_WINDOW);
set_window(window);
window->set_user_data(gobj());
// Not sure if the following line is needed:
gtk_style_attach(get_style()->gobj(), window->gobj());
get_style()->set_background(window, Gtk::STATE_ACTIVE);
_refGC = Gdk::GC::create(window);
}
void
@ -156,26 +170,22 @@ SchedulablesWidget::on_size_allocate(const Gtk::Allocation& allocation)
bool
SchedulablesWidget::on_expose_event(GdkEventExpose* event)
{
if(event == NULL || event->count > 0)
return false;
// calculated dinamically:
int w = get_allocation().get_width();
set_size_request(w, _h);
// Clip to redraw only the smallest possible area
std::auto_ptr<Gdk::Rectangle> clip_area;
if(event)
clip_area = std::auto_ptr<Gdk::Rectangle>(new Gdk::Rectangle(event->area.x, event->area.y,
event->area.width, event->area.height));
else
clip_area = std::auto_ptr<Gdk::Rectangle>(new Gdk::Rectangle(0, 0, w, _h));
// Use double buffering or we're CPU-dead
// Copy from the buffer to the screen
if(_buf)
get_window()->draw_drawable(_refGC, _buf,
clip_area->get_x(), clip_area->get_y(),
clip_area->get_x(), clip_area->get_y(),
clip_area->get_width(), clip_area->get_height());
get_window()->draw_drawable(get_style()->get_black_gc(), _buf,
event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width, event->area.height);
return true;
}

View file

@ -59,7 +59,6 @@ namespace sgpem
typedef std::vector<area_callback_t> areas_vect_t;
Glib::RefPtr<Gdk::Pixmap> _buf;
Glib::RefPtr<Gdk::GC> _refGC;
};
} //~ namespace sgpem