first compilable version of tabbable design.
[ardour.git] / gtk2_ardour / utils.cc
index ee7ad737e0ee5c10f1fb9afd94030f5d35402efc..3c7945993a9765c72372dedefaf90c67ea6a83e3 100644 (file)
@@ -26,7 +26,6 @@
 #include <cstring>
 #include <cctype>
 #include <cmath>
-#include <fstream>
 #include <list>
 #include <sys/stat.h>
 #include <gtkmm/rc.h>
 #include "pbd/file_utils.h"
 
 #include <gtkmm2ext/utils.h>
-#include "ardour/rc_configuration.h"
+
 #include "ardour/filesystem_paths.h"
 
 #include "canvas/item.h"
 #include "canvas/utils.h"
 
-#include "ardour_ui.h"
 #include "debug.h"
 #include "public_editor.h"
 #include "keyboard.h"
@@ -54,6 +52,8 @@
 #include "i18n.h"
 #include "rgb_macros.h"
 #include "gui_thread.h"
+#include "ui_config.h"
+#include "ardour_dialog.h"
 
 using namespace std;
 using namespace Gtk;
@@ -205,15 +205,15 @@ ARDOUR_UI_UTILS::xpm2rgba (const char** xpm, uint32_t& w, uint32_t& h)
        return (savergb);
 }
 
-/** Returns a Pango::FontDescription given a string describing the font. 
+/** Returns a Pango::FontDescription given a string describing the font.
  *
  * If the returned FontDescription does not specify a family, then
  * the family is set to "Sans". This mirrors GTK's behaviour in
- * gtkstyle.c. 
+ * gtkstyle.c.
  *
  * Some environments will force Pango to specify the family
  * even if it was not specified in the string describing the font.
- * Such environments should be left unaffected by this function, 
+ * Such environments should be left unaffected by this function,
  * since the font family will be left alone.
  *
  * There may be other similar font specification enforcement
@@ -297,39 +297,28 @@ ARDOUR_UI_UTILS::gdk_color_to_rgba (Gdk::Color const& c)
 bool
 ARDOUR_UI_UTILS::relay_key_press (GdkEventKey* ev, Gtk::Window* win)
 {
-       PublicEditor& ed (PublicEditor::instance());
-
-       if (!key_press_focus_accelerator_handler (*win, ev)) {
-               if (&ed == 0) {
-                       /* early key press in pre-main-window-dialogs, no editor yet */
-                       return false;
-               }
-               return ed.on_key_press_event(ev);
-       } else {
-               return true;
+       switch (ev->type) {
+       case GDK_KEY_PRESS:
+               return ARDOUR_UI::instance()->key_press_handler (ev, win);
+       default:
+               return ARDOUR_UI::instance()->key_release_handler (ev, win);
        }
 }
 
 bool
-ARDOUR_UI_UTILS::forward_key_press (GdkEventKey* ev)
-{
-       return PublicEditor::instance().on_key_press_event(ev);
-}
-
-bool
-ARDOUR_UI_UTILS::emulate_key_event (Gtk::Widget* w, unsigned int keyval)
+ARDOUR_UI_UTILS::emulate_key_event (unsigned int keyval)
 {
-       GdkDisplay  *display = gtk_widget_get_display (GTK_WIDGET(w->gobj()));
+       GdkDisplay  *display = gtk_widget_get_display (GTK_WIDGET(ARDOUR_UI::instance()->main_window().gobj()));
        GdkKeymap   *keymap  = gdk_keymap_get_for_display (display);
        GdkKeymapKey *keymapkey = NULL;
        gint n_keys;
-
+       
        if (!gdk_keymap_get_entries_for_keyval(keymap, keyval, &keymapkey, &n_keys)) return false;
        if (n_keys !=1) { g_free(keymapkey); return false;}
 
        GdkEventKey ev;
        ev.type = GDK_KEY_PRESS;
-       ev.window = gtk_widget_get_window(GTK_WIDGET(w->gobj()));
+       ev.window = ARDOUR_UI::instance()->main_window().get_window()->gobj();
        ev.send_event = FALSE;
        ev.time = 0;
        ev.state = 0;
@@ -340,9 +329,9 @@ ARDOUR_UI_UTILS::emulate_key_event (Gtk::Widget* w, unsigned int keyval)
        ev.group = keymapkey[0].group;
        g_free(keymapkey);
 
-       forward_key_press(&ev);
+       relay_key_press(&ev);
        ev.type = GDK_KEY_RELEASE;
-       return forward_key_press(&ev);
+       return relay_key_press(&ev);
 }
 
 static string
@@ -427,7 +416,7 @@ ARDOUR_UI_UTILS::key_press_focus_accelerator_handler (Gtk::Window& window, GdkEv
            appear to be. if it ever is necessar, figure out if it should apply
            to all platforms.
         */
-#if 0 
+#if 0
        if (Keyboard::some_magic_widget_has_focus ()) {
                 allow_activating = false;
        }
@@ -487,7 +476,7 @@ ARDOUR_UI_UTILS::key_press_focus_accelerator_handler (Gtk::Window& window, GdkEv
                 * automatically sent through the accel groups activation
                 * pathway, which prevents individual widgets & canvas items
                 * from ever seeing it if is used by a key binding.
-                * 
+                *
                 * specifically, this hid Ctrl-down-arrow from MIDI region
                 * views because it is also bound to an action.
                 *
@@ -507,7 +496,7 @@ ARDOUR_UI_UTILS::key_press_focus_accelerator_handler (Gtk::Window& window, GdkEv
                                                                          ev->keyval, fakekey));
 
                        DEBUG_TRACE (DEBUG::Accelerators, string_compose ("\tmodified modifier was %1\n", show_gdk_event_state (modifier)));
-                       
+
                        if (allow_activating && gtk_accel_groups_activate(G_OBJECT(win), fakekey, modifier)) {
                                DEBUG_TRACE (DEBUG::Accelerators, "\taccel group activated by fakekey\n");
                                return true;
@@ -590,7 +579,7 @@ ARDOUR_UI_UTILS::get_icon_sets ()
        Searchpath spath(ARDOUR::ardour_data_search_path());
        spath.add_subdirectory_to_paths ("icons");
        vector<string> r;
-       
+
        r.push_back (_("default"));
 
        for (vector<string>::iterator s = spath.begin(); s != spath.end(); ++s) {
@@ -626,22 +615,22 @@ ARDOUR_UI_UTILS::get_icon_path (const char* cname, string icon_set, bool is_imag
                /* add "icons/icon_set" but .. not allowed to add both of these at once */
                spath.add_subdirectory_to_paths ("icons");
                spath.add_subdirectory_to_paths (icon_set);
-               
+
                find_file (spath, name, data_file_path);
        } else {
                spath.add_subdirectory_to_paths ("icons");
                find_file (spath, name, data_file_path);
        }
-       
+
        if (is_image && data_file_path.empty()) {
-               
+
                if (!icon_set.empty() && icon_set != _("default")) {
                        warning << string_compose (_("icon \"%1\" not found for icon set \"%2\", fallback to default"), cname, icon_set) << endmsg;
                }
-               
+
                Searchpath def (ARDOUR::ardour_data_search_path());
                def.add_subdirectory_to_paths ("icons");
-       
+
                if (!find_file (def, name, data_file_path)) {
                        fatal << string_compose (_("cannot find icon image for %1 using %2"), name, spath.to_string()) << endmsg;
                        abort(); /*NOTREACHED*/
@@ -714,7 +703,7 @@ ARDOUR_UI_UTILS::longest (vector<string>& strings)
 bool
 ARDOUR_UI_UTILS::key_is_legal_for_numeric_entry (guint keyval)
 {
-       /* we assume that this does not change over the life of the process 
+       /* we assume that this does not change over the life of the process
         */
 
        static int comma_decimal = -1;
@@ -879,7 +868,7 @@ ARDOUR_UI_UTILS::unique_random_color (list<Gdk::Color>& used_colors)
        }
 }
 
-string 
+string
 ARDOUR_UI_UTILS::rate_as_string (float r)
 {
        char buf[32];
@@ -927,3 +916,23 @@ ARDOUR_UI_UTILS::windows_overlap (Gtk::Window *a, Gtk::Window *b)
        }
        return false;
 }
+
+bool
+ARDOUR_UI_UTILS::overwrite_file_dialog (Gtk::Window& parent, string title, string text)
+{
+       ArdourDialog dialog (parent, title, true);
+       Label label (text);
+
+       dialog.get_vbox()->pack_start (label, true, true);
+       dialog.add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+       dialog.add_button (_("Overwrite"), Gtk::RESPONSE_ACCEPT);
+       dialog.show_all ();
+
+       switch (dialog.run()) {
+       case RESPONSE_ACCEPT:
+               return true;
+       case RESPONSE_CANCEL:
+       default:
+               return false;
+       }
+}