Remove LocaleGuard from ARDOUR::IO class state methods
[ardour.git] / libs / canvas / canvas.cc
index a72700b94af1707cc87a190bb4f3fa17e7a30e7a..fb06b06b975eb49eca34793a18cfee07c125742f 100644 (file)
 #include "canvas/scroll_group.h"
 #include "canvas/utils.h"
 
+#ifdef __APPLE__
+#include <gdk/gdk.h>
+#include "gtkmm2ext/nsglview.h"
+#endif
+
 using namespace std;
 using namespace ArdourCanvas;
 
@@ -390,6 +395,7 @@ GtkCanvas::GtkCanvas ()
        , current_tooltip_item (0)
        , tooltip_window (0)
        , _in_dtor (false)
+       , _nsglview (0)
 {
        /* these are the events we want to know about */
        add_events (Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::POINTER_MOTION_MASK |
@@ -397,6 +403,16 @@ GtkCanvas::GtkCanvas ()
                    Gdk::KEY_PRESS_MASK | Gdk::KEY_RELEASE_MASK);
 }
 
+void
+GtkCanvas::use_nsglview ()
+{
+       assert (!_nsglview);
+       assert (!is_realized());
+#ifdef ARDOUR_CANVAS_NSVIEW_TAG // patched gdkquartz.h
+       _nsglview = Gtkmm2ext::nsglview_create (this);
+#endif
+}
+
 void
 GtkCanvas::pick_current_item (int state)
 {
@@ -713,6 +729,15 @@ GtkCanvas::deliver_event (GdkEvent* event)
        return false;
 }
 
+void
+GtkCanvas::item_shown_or_hidden (Item* item)
+{
+       if (item == current_tooltip_item) {
+               stop_tooltip_timeout ();
+       }
+       Canvas::item_shown_or_hidden (item);
+}
+
 /** Called when an item is being destroyed.
  *  @param item Item being destroyed.
  *  @param bounding_box Last known bounding box of the item.
@@ -755,6 +780,17 @@ GtkCanvas::item_going_away (Item* item, Rect bounding_box)
 
 }
 
+void
+GtkCanvas::on_realize ()
+{
+       Gtk::EventBox::on_realize();
+#ifdef __APPLE__
+       if (_nsglview) {
+               Gtkmm2ext::nsglview_overlay (_nsglview, get_window()->gobj());
+       }
+#endif
+}
+
 void
 GtkCanvas::on_size_allocate (Gtk::Allocation& a)
 {
@@ -771,6 +807,18 @@ GtkCanvas::on_size_allocate (Gtk::Allocation& a)
 #ifdef OPTIONAL_CAIRO_IMAGE_SURFACE
        }
 #endif
+
+#ifdef __APPLE__
+       if (_nsglview) {
+               gint xx, yy;
+               gtk_widget_translate_coordinates(
+                               GTK_WIDGET(gobj()),
+                               GTK_WIDGET(get_toplevel()->gobj()),
+                               0, 0, &xx, &yy);
+               Gtkmm2ext::nsglview_resize (_nsglview, xx, yy, a.get_width(), a.get_height());
+       }
+#endif
+
 }
 
 /** Handler for GDK expose events.
@@ -783,6 +831,12 @@ GtkCanvas::on_expose_event (GdkEventExpose* ev)
        if (_in_dtor) {
                return true;
        }
+#ifdef __APPLE__
+       if (_nsglview) {
+               Gtkmm2ext::nsglview_queue_draw (_nsglview, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
+               return true;
+       }
+#endif
 
 #ifdef CANVAS_PROFILE
        const int64_t start = g_get_monotonic_time ();
@@ -837,7 +891,7 @@ GtkCanvas::on_expose_event (GdkEventExpose* ev)
        /* render canvas */
        if ( _single_exposure ) {
 
-               render (Rect (ev->area.x, ev->area.y, ev->area.x + ev->area.width, ev->area.y + ev->area.height), draw_context);
+               Canvas::render (Rect (ev->area.x, ev->area.y, ev->area.x + ev->area.width, ev->area.y + ev->area.height), draw_context);
 
        } else {
                GdkRectangle* rects;
@@ -846,7 +900,7 @@ GtkCanvas::on_expose_event (GdkEventExpose* ev)
                gdk_region_get_rectangles (ev->region, &rects, &nrects);
                for (gint n = 0; n < nrects; ++n) {
                        draw_context->set_identity_matrix();  //reset the cairo matrix, just in case someone left it transformed after drawing ( cough )
-                       render (Rect (rects[n].x, rects[n].y, rects[n].x + rects[n].width, rects[n].y + rects[n].height), draw_context);
+                       Canvas::render (Rect (rects[n].x, rects[n].y, rects[n].x + rects[n].width, rects[n].y + rects[n].height), draw_context);
                }
                g_free (rects);
        }
@@ -1070,6 +1124,36 @@ GtkCanvas::on_leave_notify_event (GdkEventCrossing* ev)
        return true;
 }
 
+void
+GtkCanvas::on_map ()
+{
+       Gtk::EventBox::on_map();
+#ifdef __APPLE__
+       if (_nsglview) {
+               Gtkmm2ext::nsglview_set_visible (_nsglview, true);
+               Gtk::Allocation a = get_allocation();
+               gint xx, yy;
+               gtk_widget_translate_coordinates(
+                               GTK_WIDGET(gobj()),
+                               GTK_WIDGET(get_toplevel()->gobj()),
+                               0, 0, &xx, &yy);
+               Gtkmm2ext::nsglview_resize (_nsglview, xx, yy, a.get_width(), a.get_height());
+       }
+#endif
+}
+
+void
+GtkCanvas::on_unmap ()
+{
+       stop_tooltip_timeout ();
+       Gtk::EventBox::on_unmap();
+#ifdef __APPLE__
+       if (_nsglview) {
+               Gtkmm2ext::nsglview_set_visible (_nsglview, false);
+       }
+#endif
+}
+
 /** Called to request a redraw of our canvas.
  *  @param area Area to redraw, in window coordinates.
  */
@@ -1154,7 +1238,7 @@ GtkCanvas::unfocus (Item* item)
 }
 
 /** @return The visible area of the canvas, in window coordinates */
-Rect
+ArdourCanvas::Rect
 GtkCanvas::visible_area () const
 {
        return Rect (0, 0, get_allocation().get_width (), get_allocation().get_height ());