fix cairo widget background
This commit is contained in:
parent
926d4eb36e
commit
585fa45b62
|
@ -41,12 +41,14 @@ CairoWidget::CairoWidget ()
|
|||
, _need_bg (true)
|
||||
, _grabbed (false)
|
||||
, _name_proxy (this, X_("name"))
|
||||
, _current_parent (0)
|
||||
{
|
||||
_name_proxy.connect (sigc::mem_fun (*this, &CairoWidget::on_name_changed));
|
||||
}
|
||||
|
||||
CairoWidget::~CairoWidget ()
|
||||
{
|
||||
if (_parent_style_change) _parent_style_change.disconnect();
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -54,14 +56,13 @@ CairoWidget::on_expose_event (GdkEventExpose *ev)
|
|||
{
|
||||
cairo_t* cr = gdk_cairo_create (get_window ()->gobj());
|
||||
cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
|
||||
cairo_clip (cr);
|
||||
cairo_clip_preserve (cr);
|
||||
|
||||
/* paint expose area the color of the parent window bg
|
||||
*/
|
||||
|
||||
Gdk::Color bg (get_parent_bg());
|
||||
|
||||
cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
|
||||
cairo_set_source_rgb (cr, bg.get_red_p(), bg.get_green_p(), bg.get_blue_p());
|
||||
cairo_fill (cr);
|
||||
|
||||
|
@ -112,6 +113,11 @@ CairoWidget::get_parent_bg ()
|
|||
|
||||
if (p) {
|
||||
Glib::RefPtr<Gtk::Style> style = parent->get_style();
|
||||
if (_current_parent != parent) {
|
||||
if (_parent_style_change) _parent_style_change.disconnect();
|
||||
_current_parent = parent;
|
||||
_parent_style_change = parent->signal_style_changed().connect (mem_fun (*this, &CairoWidget::on_style_changed));
|
||||
}
|
||||
return style->get_bg (get_state());
|
||||
}
|
||||
|
||||
|
@ -123,6 +129,11 @@ CairoWidget::get_parent_bg ()
|
|||
}
|
||||
|
||||
if (parent && parent->get_has_window()) {
|
||||
if (_current_parent != parent) {
|
||||
if (_parent_style_change) _parent_style_change.disconnect();
|
||||
_current_parent = parent;
|
||||
_parent_style_change = parent->signal_style_changed().connect (mem_fun (*this, &CairoWidget::on_style_changed));
|
||||
}
|
||||
return parent->get_style ()->get_bg (parent->get_state());
|
||||
}
|
||||
|
||||
|
@ -161,6 +172,12 @@ CairoWidget::set_active (bool yn)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
CairoWidget::on_style_changed (const Glib::RefPtr<Gtk::Style>&)
|
||||
{
|
||||
queue_draw();
|
||||
}
|
||||
|
||||
void
|
||||
CairoWidget::on_state_changed (Gtk::StateType)
|
||||
{
|
||||
|
|
|
@ -79,6 +79,7 @@ protected:
|
|||
virtual bool on_expose_event (GdkEventExpose *);
|
||||
void on_size_allocate (Gtk::Allocation &);
|
||||
void on_state_changed (Gtk::StateType);
|
||||
void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
|
||||
Gdk::Color get_parent_bg ();
|
||||
|
||||
/* this is an additional virtual "on_..." method. Glibmm does not
|
||||
|
@ -96,6 +97,8 @@ protected:
|
|||
|
||||
private:
|
||||
Glib::SignalProxyProperty _name_proxy;
|
||||
sigc::connection _parent_style_change;
|
||||
Widget * _current_parent;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user