ardour-button-ize zoom buttons; move MIDI panic button to transport bar
[ardour.git] / gtk2_ardour / cairo_widget.cc
index 573f3e5ba65e7f721dd3900206c147c689586f1b..5f83cb80d5023275942a3311a7e4c2d5d90af101 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2009 Paul Davis 
+    Copyright (C) 2009 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 #include "gui_thread.h"
 
 CairoWidget::CairoWidget ()
-       : _width (1),
-         _height (1),
-         _dirty (true),
-         _pixmap (0)
+       : _width (1)
+       , _height (1)
+       , _active_state (Gtkmm2ext::ActiveState (0))
+       , _visual_state (Gtkmm2ext::VisualState (0))
 {
 
 }
 
 CairoWidget::~CairoWidget ()
 {
-       if (_pixmap) {
-               gdk_pixmap_unref (_pixmap);
-       }
 }
 
 bool
-CairoWidget::on_expose_event (GdkEventExpose *event)
+CairoWidget::on_expose_event (GdkEventExpose *ev)
 {
-       Gdk::Rectangle const exposure (
-               event->area.x, event->area.y, event->area.width, event->area.height
-               );
-
-       Gdk::Rectangle r = exposure;
-       Gdk::Rectangle content (0, 0, _width, _height);
-       bool intersects;
-       r.intersect (content, intersects);
-       
-       if (intersects) {
-
-               GdkDrawable* drawable = get_window()->gobj ();
-
-               if (_dirty) {
-
-                       if (_pixmap) {
-                               gdk_pixmap_unref (_pixmap);
-                       }
-
-                       _pixmap = gdk_pixmap_new (drawable, _width, _height, -1);
-
-                       cairo_t* cr = gdk_cairo_create (_pixmap);
-                       render (cr);
-                       cairo_destroy (cr);
-
-                       _dirty = false;
-               }
-
-               gdk_draw_drawable (
-                       drawable,
-                       get_style()->get_fg_gc (Gtk::STATE_NORMAL)->gobj(),
-                       _pixmap,
-                       r.get_x(),
-                       r.get_y(),
-                       r.get_x(),
-                       r.get_y(),
-                       r.get_width(),
-                       r.get_height()
-                       );
-       }
-       
+       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);
+       render (cr);
+       cairo_destroy (cr);
+
        return true;
 }
 
@@ -90,9 +52,7 @@ CairoWidget::on_expose_event (GdkEventExpose *event)
 void
 CairoWidget::set_dirty ()
 {
-       ENSURE_GUI_THREAD (mem_fun (*this, &CairoWidget::set_dirty));
-
-       _dirty = true;
+       ENSURE_GUI_THREAD (*this, &CairoWidget::set_dirty);
        queue_draw ();
 }
 
@@ -109,3 +69,55 @@ CairoWidget::on_size_allocate (Gtk::Allocation& alloc)
 
        set_dirty ();
 }
+
+Gdk::Color
+CairoWidget::get_parent_bg ()
+{
+        Widget* parent;
+
+       parent = get_parent ();
+
+        while (parent && !parent->get_has_window()) {
+                parent = parent->get_parent();
+        }
+
+        if (parent && parent->get_has_window()) {
+               return parent->get_style ()->get_bg (parent->get_state());
+        } 
+
+       return get_style ()->get_bg (get_state());
+}
+
+void
+CairoWidget::set_active_state (Gtkmm2ext::ActiveState s)
+{
+       if (_active_state != s) {
+               _active_state = s;
+               StateChanged ();
+       }
+}
+
+void
+CairoWidget::set_visual_state (Gtkmm2ext::VisualState s)
+{
+       if (_visual_state != s) {
+               _visual_state = s;
+               StateChanged ();
+       }
+}
+
+void
+CairoWidget::on_state_changed (Gtk::StateType)
+{
+       /* this will catch GTK-level state changes from calls like
+          ::set_sensitive() 
+       */
+
+       if (get_state() == Gtk::STATE_INSENSITIVE) {
+               set_visual_state (Gtkmm2ext::VisualState (visual_state() | Gtkmm2ext::Insensitive));
+       } else {
+               set_visual_state (Gtkmm2ext::VisualState (visual_state() & ~Gtkmm2ext::Insensitive));
+       }
+
+       queue_draw ();
+}