, _widget (w)
{
Event.connect (sigc::mem_fun (*this, &Widget::event_proxy));
+ w.set_canvas_widget ();
+ w.QueueDraw.connect (sigc::mem_fun(*this, &Widget::queue_draw));
+ w.QueueResize.connect (sigc::mem_fun(*this, &Widget::queue_resize));
}
Widget::Widget (Item* parent, CairoWidget& w)
, _widget (w)
{
Event.connect (sigc::mem_fun (*this, &Widget::event_proxy));
+ w.set_canvas_widget ();
+ w.QueueDraw.connect (sigc::mem_fun(*this, &Widget::queue_draw));
+ w.QueueResize.connect (sigc::mem_fun(*this, &Widget::queue_resize));
}
bool
return _widget.event (ev);
}
+bool
+Widget::queue_draw ()
+{
+ begin_visual_change ();
+ end_visual_change ();
+ return true;
+}
+
+bool
+Widget::queue_resize ()
+{
+ begin_change ();
+ end_change ();
+ return true;
+}
+
void
Widget::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
{
, _grabbed (false)
, _name_proxy (this, X_("name"))
, _current_parent (0)
+ , _canvas_widget (false)
{
_name_proxy.connect (sigc::mem_fun (*this, &CairoWidget::on_name_changed));
}
CairoWidget::~CairoWidget ()
{
+ if (_canvas_widget) {
+ gtk_widget_set_realized (GTK_WIDGET(gobj()), false);
+ }
if (_parent_style_change) _parent_style_change.disconnect();
}
+void
+CairoWidget::set_canvas_widget ()
+{
+ assert (!_canvas_widget);
+ ensure_style ();
+ gtk_widget_set_realized (GTK_WIDGET(gobj()), true);
+ _canvas_widget = true;
+}
+
+int
+CairoWidget::get_width () const
+{
+ if (_canvas_widget) {
+ return _allocation.get_width ();
+ }
+ return Gtk::EventBox::get_width ();
+}
+
+int
+CairoWidget::get_height () const
+{
+ if (_canvas_widget) {
+ return _allocation.get_height ();
+ }
+ return Gtk::EventBox::get_height ();
+}
+
+void
+CairoWidget::size_allocate (Gtk::Allocation& alloc)
+{
+ if (_canvas_widget) {
+ memcpy (&_allocation, &alloc, sizeof(Gtk::Allocation));
+ return;
+ }
+ Gtk::EventBox::size_allocate (alloc);
+}
+
+
bool
CairoWidget::on_button_press_event (GdkEventButton*)
{
if (!area) {
queue_draw ();
} else {
+ // TODO emit QueueDrawArea -> ArdourCanvas::Widget
+ if (QueueDraw ()) {
+ return;
+ }
queue_draw_area (area->x, area->y, area->width, area->height);
}
}
+void
+CairoWidget::queue_draw ()
+{
+ if (QueueDraw ()) {
+ return;
+ }
+ Gtk::EventBox::queue_draw ();
+}
+
+void
+CairoWidget::queue_resize ()
+{
+ if (QueueResize ()) {
+ return;
+ }
+ Gtk::EventBox::queue_resize ();
+}
+
/** Handle a size allocation.
* @param alloc GTK allocation.
*/
void
CairoWidget::on_size_allocate (Gtk::Allocation& alloc)
{
- Gtk::EventBox::on_size_allocate (alloc);
+ if (!_canvas_widget) {
+ Gtk::EventBox::on_size_allocate (alloc);
+ } else {
+ memcpy (&_allocation, &alloc, sizeof(Gtk::Allocation));
+ }
#ifdef OPTIONAL_CAIRO_IMAGE_SURFACE
if (getenv("ARDOUR_IMAGE_SURFACE")) {
}
#endif
+ if (_canvas_widget) {
+ return;
+ }
set_dirty ();
}
void
CairoWidget::on_style_changed (const Glib::RefPtr<Gtk::Style>&)
{
- queue_draw();
+ set_dirty ();
}
void
set_visual_state (Gtkmm2ext::VisualState (visual_state() & ~Gtkmm2ext::Insensitive));
}
- queue_draw ();
+ set_dirty ();
}
void
CairoWidget ();
virtual ~CairoWidget ();
+ void set_canvas_widget ();
+
+ /* swizzle Gtk::Widget methods for Canvas::Widget */
+ void queue_draw ();
+ void queue_resize ();
+ int get_width () const;
+ int get_height () const;
+ void size_allocate (Gtk::Allocation&);
+
void set_dirty (cairo_rectangle_t *area = 0);
Gtkmm2ext::ActiveState active_state() const { return _active_state; }
void set_draw_background (bool yn);
sigc::signal<void> StateChanged;
+ sigc::signal<bool> QueueDraw;
+ sigc::signal<bool> QueueResize;
static void provide_background_for_cairo_widget (Gtk::Widget& w, const Gdk::Color& bg);
Glib::SignalProxyProperty _name_proxy;
sigc::connection _parent_style_change;
Widget * _current_parent;
+ bool _canvas_widget;
+ Gdk::Rectangle _allocation;
};