Code

Switching to new input dialog. Allows for a better UI and addresses bug #334800 and...
authorJon A. Cruz <jon@joncruz.org>
Sun, 11 Apr 2010 08:51:39 +0000 (01:51 -0700)
committerJon A. Cruz <jon@joncruz.org>
Sun, 11 Apr 2010 08:51:39 +0000 (01:51 -0700)
src/dialogs/CMakeLists.txt
src/dialogs/Makefile_insert
src/dialogs/input.cpp [deleted file]
src/dialogs/input.h [deleted file]
src/inkscape.cpp
src/menus-skeleton.h
src/ui/dialog/input.cpp
src/ui/dialog/input.h
src/verbs.cpp
src/verbs.h

index 4e6b1ee3de715da1c413025e3135bfbb98006ec2..9bcb1cd5a49a6d358a2e07b132600cfff9a94d97 100644 (file)
@@ -8,7 +8,6 @@ find.cpp
 guidelinedialog.cpp
 iconpreview.cpp
 in-dt-coordsys.cpp
-input.cpp
 item-properties.cpp
 layer-properties.cpp
 layers-panel.cpp
index 32a11e83115b8403a88122b9ca2c90451d5c5601..8d7d3f21dee21093d5ab960dceb334ebb88a4759 100644 (file)
@@ -9,8 +9,6 @@ ink_common_sources +=   \
        dialogs/export.h                \
        dialogs/find.cpp                \
        dialogs/find.h                  \
-       dialogs/input.cpp               \
-       dialogs/input.h                 \
        dialogs/item-properties.cpp     \
        dialogs/item-properties.h       \
        dialogs/object-attributes.cpp   \
diff --git a/src/dialogs/input.cpp b/src/dialogs/input.cpp
deleted file mode 100644 (file)
index 55e9704..0000000
+++ /dev/null
@@ -1,607 +0,0 @@
-/** @file
- * @brief Extended input devices dialog
- */
-/* Authors:
- *   Nicklas Lindgren <nili@lysator.liu.se>
- *   Johan Engelen <goejendaagh@zonnet.nl>
- *
- * Copyright (C) 2005-2006 Authors
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#ifdef HAVE_CONFIG_H
-#   include <config.h>
-#endif
-
-#include <gtk/gtksignal.h>
-#include <gtk/gtkinputdialog.h>
-#include <glibmm/ustring.h>
-#include <list>
-#include <set>
-
-#include "macros.h"
-#include "verbs.h"
-#include "inkscape.h"
-#include "interface.h"
-#include "xml/repr.h"
-
-#include "dialogs/dialog-events.h"
-#include "preferences.h"
-
-#define MIN_ONSCREEN_DISTANCE 50
-
-static GtkWidget *dlg = NULL;
-static win_data wd;
-
-// impossible original values to make sure they are read from prefs
-static gint x = -1000, y = -1000, w = 0, h = 0;
-static Glib::ustring const prefs_path = "/dialogs/input/";
-
-#define noTEST_WITH_GOOD_TABLET 1
-#define noTEST_WITH_BAD_TABLET 1
-
-#if defined(TEST_WITH_GOOD_TABLET) || defined(TEST_WITH_BAD_TABLET)
-static int testDeviceCount = 0;
-static GdkDevice* testDevices = 0;
-
-// Defined at the end of the file to keep debugging out of the way.
-static void initTestDevices();
-#endif
-
-static std::list<GdkDevice *> getInputDevices()
-{
-    std::list<GdkDevice*> devices;
-
-#if defined(TEST_WITH_GOOD_TABLET) || defined(TEST_WITH_BAD_TABLET)
-    initTestDevices();
-    for (int i = 0; i < testDeviceCount; i++) {
-        devices.push_back(&testDevices[i]);
-    }
-#else
-    for (GList *ptr = gdk_devices_list(); ptr; ptr = ptr->next) {
-        GdkDevice *device = static_cast<GdkDevice *>(ptr->data);
-        devices.push_back(device);
-    }
-#endif
-
-    return devices;
-}
-
-// wrap these GDK calls to be able to intercept for testing.
-
-static bool setDeviceMode( GdkDevice *device, GdkInputMode mode )
-{
-#if defined(TEST_WITH_GOOD_TABLET) || defined(TEST_WITH_BAD_TABLET)
-    (void)device;
-    (void)mode;
-    bool retVal = true; // Can't let the Gdk call be called with bad data
-#else
-    bool retVal = gdk_device_set_mode(device, mode);
-#endif
-    return retVal;
-}
-
-static void setDeviceAxisUse( GdkDevice *device, guint index, GdkAxisUse use )
-{
-#if defined(TEST_WITH_GOOD_TABLET) && !defined(TEST_WITH_BAD_TABLET)
-    (void)device;
-    (void)index;
-    (void)use;
-#else
-    gdk_device_set_axis_use(device, index, use);
-#endif
-}
-
-static void setDeviceKey( GdkDevice* device, guint index, guint keyval, GdkModifierType modifiers )
-{
-#if defined(TEST_WITH_GOOD_TABLET) && !defined(TEST_WITH_BAD_TABLET)
-    (void)device;
-    (void)index;
-    (void)keyval;
-    (void)modifiers;
-#else
-    gdk_device_set_key(device, index, keyval, modifiers);
-#endif
-}
-
-
-static void
-sp_input_dialog_destroy (GtkObject */*object*/, gpointer /*data*/)
-{
-    sp_signal_disconnect_by_data (INKSCAPE, dlg);
-    wd.win = dlg = NULL;
-    wd.stop = 0;
-}
-
-static gboolean
-sp_input_dialog_delete (GtkObject */*object*/, GdkEvent */*event*/, gpointer /*data*/)
-{
-    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
-    gtk_window_get_position ((GtkWindow *) dlg, &x, &y);
-    gtk_window_get_size ((GtkWindow *) dlg, &w, &h);
-
-    if (x<0) x=0;
-    if (y<0) y=0;
-
-    prefs->setInt(prefs_path + "x", x);
-    prefs->setInt(prefs_path + "y", y);
-    prefs->setInt(prefs_path + "w", w);
-    prefs->setInt(prefs_path + "h", h);
-
-    return FALSE; // which means, go ahead and destroy it
-
-}
-
-static gchar const *axis_use_strings[GDK_AXIS_LAST] = {
-    "ignore", "x", "y", "pressure", "xtilt", "ytilt", "wheel"
-};
-
-static const int RUNAWAY_MAX = 1000;
-
-static Glib::ustring getBaseDeviceName(GdkInputSource source)
-{
-    Glib::ustring name;
-    switch (source) {
-        case GDK_SOURCE_MOUSE:
-            name ="pointer";
-            break;
-        case GDK_SOURCE_PEN:
-            name ="pen";
-            break;
-        case GDK_SOURCE_ERASER:
-            name ="eraser";
-            break;
-        case GDK_SOURCE_CURSOR:
-            name ="cursor";
-            break;
-        default:
-            name = "tablet";
-    }
-    return name;
-}
-
-static Glib::ustring createSanitizedPath(GdkDevice* device, std::set<Glib::ustring> &seenPaths)
-{
-    // LP #334800: tablet device names on Windows sometimes contain funny junk like
-    // \x03, \xf2, etc. Moreover this junk changes between runs.
-    // If the tablet name contains unprintable or non-ASCII characters,
-    // we use some default name.
-    // This might break if someone has two tablets with broken names, but it's
-    // not possible to do anything 100% correct then.
-    bool broken = false;
-
-    if (!device->name || (*(device->name) == 0)) {
-        broken = true;
-    } else {
-        for (gchar const *s = device->name; *s; ++s) {
-            if ((*s < 0x20) || (*s >= 0x7f)) {
-                broken = true;
-                break;
-            }
-        }
-    }
-
-    Glib::ustring device_path;
-    if (broken) {
-        Glib::ustring base = Glib::ustring("/devices/") + getBaseDeviceName(device->source);
-        int num = 1;
-        device_path = base;
-        while ((seenPaths.find(device_path) != seenPaths.end()) && (num < RUNAWAY_MAX)) {
-            device_path = Glib::ustring::compose("%1%2", base, ++num);
-        }
-    } else {
-        device_path += Glib::ustring("/devices/") + device->name;
-    }
-
-    seenPaths.insert(device_path);
-
-    return device_path;
-}
-
-void sp_input_load_from_preferences(void)
-{
-    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
-
-    std::list<GdkDevice *> devices = getInputDevices();
-    std::set<Glib::ustring> seenPaths;
-    for (std::list<GdkDevice *>::iterator it = devices.begin(); it != devices.end(); ++it) {
-        GdkDevice *device = *it;
-
-//         g_message("    s:%d m:%d hc:%d a:%d k:%d [%s]", device->source, device->mode, device->has_cursor, device->num_axes, device->num_keys, device->name);
-//         for (int i = 0; i < device->num_axes; i++) {
-//             GdkDeviceAxis &axis = device->axes[i];
-//             g_message("        axis[%d] u:%d  min:%f max:%f", i, axis.use, axis.min, axis.max);
-//         }
-
-        Glib::ustring device_path = createSanitizedPath(device, seenPaths);
-//         if (device_path != (Glib::ustring("/devices/") + device->name)) {
-//             g_message("        re-name [%s]", device_path.c_str());
-//         }
-
-        Glib::ustring device_mode = prefs->getString(device_path + "/mode");
-
-        GdkInputMode mode = GDK_MODE_DISABLED;
-        if (device_mode == "screen") {
-            mode = GDK_MODE_SCREEN;
-        } else if (device_mode == "window") {
-            mode = GDK_MODE_WINDOW;
-        }
-
-        if (device->mode != mode) {
-            setDeviceMode(device, mode);
-        }
-
-        Glib::ustring::size_type pos0, pos1;
-        GdkAxisUse axis_use;
-
-        //temp_ptr = repr->attribute("axes");
-        Glib::ustring const axes_str = prefs->getString(device_path + "/axes");
-        pos0 = pos1 = 0;
-        for (gint i=0; i < device->num_axes; i++) {
-            pos1 = axes_str.find(';', pos0);
-            if (pos1 == Glib::ustring::npos) {
-                break;  // Too few axis specifications
-            }
-
-            axis_use = GDK_AXIS_IGNORE;
-            for (gint j=0; j < GDK_AXIS_LAST; j++) {
-                if (!strcmp(axes_str.substr(pos0, pos1-pos0).c_str(), axis_use_strings[j])) {
-                    axis_use = static_cast<GdkAxisUse>(j);
-                    break;
-                }
-            }
-            setDeviceAxisUse(device, i, axis_use);
-            pos0 = pos1 + 1;
-        }
-
-        guint keyval;
-        GdkModifierType modifier;
-
-        Glib::ustring const keys_str = prefs->getString(device_path + "/keys");
-        pos0 = pos1 = 0;
-        for (gint i=0; i < device->num_keys; i++) {
-            pos1 = keys_str.find(';', pos0);
-            if (pos1 == Glib::ustring::npos) {
-                break;  // Too few key specifications
-            }
-
-            gtk_accelerator_parse(keys_str.substr(pos0, pos1-pos0).c_str(), &keyval, &modifier);
-            setDeviceKey(device, i, keyval, modifier);
-            pos0 = pos1 + 1;
-        }
-    }
-}
-
-void sp_input_save_to_preferences(void)
-{
-    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
-
-    std::list<GdkDevice *> devices = getInputDevices();
-    std::set<Glib::ustring> seenPaths;
-    for (std::list<GdkDevice *>::iterator it = devices.begin(); it != devices.end(); ++it) {
-        GdkDevice *device = *it;
-
-        Glib::ustring device_path = createSanitizedPath(device, seenPaths);
-
-        switch (device->mode) {
-            default:
-            case GDK_MODE_DISABLED: {
-                prefs->setString(device_path + "/mode", "disabled");
-                break;
-            }
-            case GDK_MODE_SCREEN: {
-                prefs->setString(device_path + "/mode", "screen");
-                break;
-            }
-            case GDK_MODE_WINDOW: {
-                prefs->setString(device_path + "/mode", "window");
-                break;
-            }
-        }
-
-        Glib::ustring temp_attribute = "";
-        for (gint i=0; i < device->num_axes; i++) {
-            temp_attribute += axis_use_strings[device->axes[i].use];
-            temp_attribute += ";";
-        }
-        prefs->setString(device_path + "/axes", temp_attribute);
-
-        temp_attribute = "";
-        for (gint i=0; i < device->num_keys; i++) {
-            temp_attribute += gtk_accelerator_name(device->keys[i].keyval, device->keys[i].modifiers);
-            temp_attribute += ";";
-        }
-        prefs->setString(device_path + "/keys", temp_attribute);
-    }
-}
-
-static void
-sp_input_save_button (GtkObject */*object*/, gpointer /*data*/)
-{
-    sp_input_save_to_preferences();
-}
-
-void
-sp_input_dialog (void)
-{
-    if (dlg == NULL) {
-        Inkscape::Preferences *prefs = Inkscape::Preferences::get();
-
-        gchar title[500];
-        sp_ui_dialog_title_string (Inkscape::Verb::get(SP_VERB_DIALOG_INPUT), title);
-
-        dlg = gtk_input_dialog_new();
-
-        if (x == -1000 || y == -1000) {
-            x = prefs->getInt(prefs_path + "x", -1000);
-            y = prefs->getInt(prefs_path + "y", -1000);
-        }
-
-        if (w ==0 || h == 0) {
-            w = prefs->getInt(prefs_path + "w", 0);
-            h = prefs->getInt(prefs_path + "h", 0);
-        }
-
-//        if (x<0) x=0;
-//        if (y<0) y=0;
-
-        if (w && h) {
-            gtk_window_resize ((GtkWindow *) dlg, w, h);
-        }
-        if (x >= 0 && y >= 0 && (x < (gdk_screen_width()-MIN_ONSCREEN_DISTANCE)) && (y < (gdk_screen_height()-MIN_ONSCREEN_DISTANCE))) {
-            gtk_window_move ((GtkWindow *) dlg, x, y);
-        } else {
-            gtk_window_set_position(GTK_WINDOW(dlg), GTK_WIN_POS_CENTER);
-        }
-
-
-        sp_transientize (dlg);
-        wd.win = dlg;
-        wd.stop = 0;
-
-        g_signal_connect   ( G_OBJECT (INKSCAPE), "activate_desktop", G_CALLBACK (sp_transientize_callback), &wd);
-        gtk_signal_connect ( GTK_OBJECT (dlg), "event", GTK_SIGNAL_FUNC (sp_dialog_event_handler), dlg);
-        gtk_signal_connect ( GTK_OBJECT (dlg), "destroy", G_CALLBACK (sp_input_dialog_destroy), dlg);
-        gtk_signal_connect ( GTK_OBJECT (dlg), "delete_event", G_CALLBACK (sp_input_dialog_delete), dlg);
-        g_signal_connect   ( G_OBJECT (INKSCAPE), "shut_down", G_CALLBACK (sp_input_dialog_delete), dlg);
-        g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_hide", G_CALLBACK (sp_dialog_hide), dlg);
-        g_signal_connect   ( G_OBJECT (INKSCAPE), "dialogs_unhide", G_CALLBACK (sp_dialog_unhide), dlg);
-
-        // Dialog-specific stuff
-        gtk_signal_connect_object (GTK_OBJECT(GTK_INPUT_DIALOG(dlg)->close_button),
-                                   "clicked",
-                                   (GtkSignalFunc)gtk_widget_destroy,
-                                   GTK_OBJECT(dlg));
-        gtk_signal_connect (GTK_OBJECT(GTK_INPUT_DIALOG(dlg)->save_button),
-                            "clicked",
-                            (GtkSignalFunc)sp_input_save_button, NULL);
-    }
-
-    gtk_window_present ((GtkWindow *) dlg);
-}
-
-// /////////////////////////////////
-// For debugging:
-// /////////////////////////////////
-
-
-#if defined(TEST_WITH_GOOD_TABLET)
-static void initTestDevices()
-{
-    static bool init = false;
-    if (!init) {
-        static GdkDevice devs[5] = {};
-        int i = 0; // use variable instead of constant to allow devices to be moved around, commented out, etc.
-
-        {
-            // Laptop trackpad
-            devs[i].name = g_strdup("pointer");
-            devs[i].source = GDK_SOURCE_MOUSE;
-            devs[i].mode = GDK_MODE_DISABLED;
-            devs[i].has_cursor = 0;
-            static GdkDeviceAxis tmp[] = {{GDK_AXIS_X, 0, 0},
-                                          {GDK_AXIS_Y, 0, 0}};
-            devs[i].num_axes = G_N_ELEMENTS(tmp);
-            devs[i].axes = tmp;
-            devs[i].num_keys = 0;
-            devs[i].keys = 0;
-            i++;
-        }
-
-        {
-            // Tablet stylus
-            devs[i].name = g_strdup("pen");
-            devs[i].source = GDK_SOURCE_PEN;
-            devs[i].mode = GDK_MODE_DISABLED;
-            devs[i].has_cursor = 0;
-            static GdkDeviceAxis tmp[] = {{GDK_AXIS_X, 0, 0},
-                                          {GDK_AXIS_Y, 0, 0},
-                                          {GDK_AXIS_PRESSURE, 0, 1},
-                                          {GDK_AXIS_XTILT, -1, 1},
-                                          {GDK_AXIS_YTILT, -1, 1}};
-            devs[i].num_axes = G_N_ELEMENTS(tmp);
-            devs[i].axes = tmp;
-            devs[i].num_keys = 0;
-            devs[i].keys = 0;
-            i++;
-        }
-
-        {
-            // Puck
-            devs[i].name = g_strdup("cursor");
-            devs[i].source = GDK_SOURCE_CURSOR;
-            devs[i].mode = GDK_MODE_DISABLED;
-            devs[i].has_cursor = 0;
-            static GdkDeviceAxis tmp[] = {{GDK_AXIS_X, 0, 0},
-                                          {GDK_AXIS_Y, 0, 0},
-                                          {GDK_AXIS_PRESSURE, 0, 1},
-                                          {GDK_AXIS_XTILT, -1, 1},
-                                          {GDK_AXIS_YTILT, -1, 1}};
-            devs[i].num_axes = G_N_ELEMENTS(tmp);
-            devs[i].axes = tmp;
-            devs[i].num_keys = 0;
-            devs[i].keys = 0;
-            i++;
-        }
-
-        {
-            // Back of tablet stylus
-            devs[i].name = g_strdup("eraser");
-            devs[i].source = GDK_SOURCE_ERASER;
-            devs[i].mode = GDK_MODE_DISABLED;
-            devs[i].has_cursor = 0;
-            static GdkDeviceAxis tmp[] = {{GDK_AXIS_X, 0, 0},
-                                          {GDK_AXIS_Y, 0, 0},
-                                          {GDK_AXIS_PRESSURE, 0, 1},
-                                          {GDK_AXIS_XTILT, -1, 1},
-                                          {GDK_AXIS_YTILT, -1, 1}};
-            devs[i].num_axes = G_N_ELEMENTS(tmp);
-            devs[i].axes = tmp;
-            devs[i].num_keys = 0;
-            devs[i].keys = 0;
-            i++;
-        }
-
-        {
-            // Main (composit) mouse device
-            devs[i].name = g_strdup("Core Pointer");
-            devs[i].source = GDK_SOURCE_MOUSE;
-            devs[i].mode = GDK_MODE_SCREEN;
-            devs[i].has_cursor = 1;
-            static GdkDeviceAxis tmp[] = {{GDK_AXIS_X, 0, 0},
-                                          {GDK_AXIS_Y, 0, 0}};
-            devs[i].num_axes = G_N_ELEMENTS(tmp);
-            devs[i].axes = tmp;
-            devs[i].num_keys = 0;
-            devs[i].keys = 0;
-            i++;
-        }
-
-        testDeviceCount = i;
-        testDevices = devs;
-        init = true;
-    }
-}
-#elif defined(TEST_WITH_BAD_TABLET)
-
-/**
- * Uses the current time in seconds to change a name to be unique from one
- * run of the program to the next.
- */
-void perturbName(gchar *str)
-{
-    if (str) {
-        GTimeVal when = {0,0};
-        g_get_current_time(&when);
-        gchar *tmp = g_strdup_printf("%ld", when.tv_sec);
-
-        size_t partLen = strlen(tmp);
-        size_t len = strlen(str);
-        if (len > (partLen + 4)) {
-            size_t pos = (len - partLen) / 2;
-            for (size_t i = 0; i < partLen; i++) {
-                str[pos + i] = tmp[i];
-            }
-        }
-        g_free(tmp);
-    }
-}
-
-static void initTestDevices()
-{
-    static bool init = false;
-    if (!init) {
-        static GdkDevice devs[5] = {};
-        int i = 0; // use variable instead of constant to allow devices to be moved around, commented out, etc.
-
-        {
-            // Main (composit) mouse device
-            devs[i].name = g_strdup("Core Pointer");
-            devs[i].source = GDK_SOURCE_MOUSE;
-            devs[i].mode = GDK_MODE_SCREEN;
-            devs[i].has_cursor = 1;
-            static GdkDeviceAxis tmp[] = {{GDK_AXIS_X, 0, 0},
-                                          {GDK_AXIS_Y, 0, 0}};
-            devs[i].num_axes = G_N_ELEMENTS(tmp);
-            devs[i].axes = tmp;
-            devs[i].num_keys = 0;
-            devs[i].keys = 0;
-            i++;
-        }
-
-        {
-            // Back of tablet stylus
-            devs[i].name = g_strdup("\346\205\227\347\221\254\347\201\257\345\220\240\346\211\241\346\225\254t\303\265\006 \347\211\220\347\215\245\347\225\263\346\225\262\345\214\240\347\245\264\347\225\254s\357\227\230#\354\234\274C\356\232\210\307\255\350\271\214\310\201\350\222\200\310\201\356\202\250\310\200\350\223\260\310\201\356\202\250\310\200");
-            perturbName(devs[i].name);
-            devs[i].source = GDK_SOURCE_ERASER;
-            devs[i].mode = GDK_MODE_DISABLED;
-            devs[i].has_cursor = 0;
-            static GdkDeviceAxis tmp[] = {{GDK_AXIS_X, 0, 0},
-                                          {GDK_AXIS_Y, 0, 0},
-                                          {GDK_AXIS_PRESSURE, 0, 1},
-                                          {GDK_AXIS_XTILT, -1, 1},
-                                          {GDK_AXIS_YTILT, -1, 1}};
-            devs[i].num_axes = G_N_ELEMENTS(tmp);
-            devs[i].axes = tmp;
-            devs[i].num_keys = 0;
-            devs[i].keys = 0;
-            i++;
-        }
-
-        {
-            // Tablet stylus
-            devs[i].name = g_strdup("\346\205\227\347\221\254\347\201\257\345\220\240\346\211\241\346\225\254t\303\265\006 \347\211\220\347\215\245\347\225\263\346\225\262\345\214\240\347\245\264\347\225\254s\357\227\230#\354\234\274C\341\221\230\307\255\343\277\214\310\202\343\230\200\310\202\331\270\310\202\343\231\260\310\202\331\270\310\202");
-            perturbName(devs[i].name);
-            devs[i].source = GDK_SOURCE_PEN;
-            devs[i].mode = GDK_MODE_DISABLED;
-            devs[i].has_cursor = 0;
-            static GdkDeviceAxis tmp[] = {{GDK_AXIS_X, 0, 0},
-                                          {GDK_AXIS_Y, 0, 0},
-                                          {GDK_AXIS_PRESSURE, 0, 1},
-                                          {GDK_AXIS_XTILT, -1, 1},
-                                          {GDK_AXIS_YTILT, -1, 1}};
-            devs[i].num_axes = G_N_ELEMENTS(tmp);
-            devs[i].axes = tmp;
-            devs[i].num_keys = 0;
-            devs[i].keys = 0;
-            i++;
-        }
-
-        {
-            // Tablet stylus
-            devs[i].name = g_strdup("\346\205\227\347\221\254\347\201\257\345\220\240\346\211\241\346\225\254t\303\265\006 \347\211\220\347\215\245\347\225\263\346\225\262\345\214\240\347\245\264\347\225\254s\357\227\230#\354\234\274C\341\221\230\307\255\343\277\214\310\202\343\230\200\310\202\331\270\310\202\343\231\260\310\202\331\270\310\202");
-            perturbName(devs[i].name);
-            devs[i].source = GDK_SOURCE_PEN;
-            devs[i].mode = GDK_MODE_DISABLED;
-            devs[i].has_cursor = 0;
-            static GdkDeviceAxis tmp[] = {{GDK_AXIS_X, 0, 0},
-                                          {GDK_AXIS_Y, 0, 0},
-                                          {GDK_AXIS_PRESSURE, 0, 1},
-                                          {GDK_AXIS_XTILT, -1, 1},
-                                          {GDK_AXIS_YTILT, -1, 1}};
-            devs[i].num_axes = G_N_ELEMENTS(tmp);
-            devs[i].axes = tmp;
-            devs[i].num_keys = 0;
-            devs[i].keys = 0;
-            i++;
-        }
-
-        testDeviceCount = i;
-        testDevices = devs;
-        init = true;
-    }
-}
-#endif
-
-
-/*
-  Local Variables:
-  mode:c++
-  c-file-style:"stroustrup"
-  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
-  indent-tabs-mode:nil
-  fill-column:99
-  End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/dialogs/input.h b/src/dialogs/input.h
deleted file mode 100644 (file)
index 0996d06..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/** @file
- * @brief  Extended input device dialog
- */
-/* Author:
- *   Nicklas Lindgren <nili@lysator.liu.se>
- *
- * Copyright (C) 2005 Authors
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#ifndef SEEN_DIALOGS_INPUT_H
-#define SEEN_DIALOGS_INPUT_H
-
-void sp_input_load_from_preferences (void);
-void sp_input_save_to_preferences (void);
-void sp_input_dialog (void);
-
-
-#endif
-
-/*
-  Local Variables:
-  mode:c++
-  c-file-style:"stroustrup"
-  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
-  indent-tabs-mode:nil
-  fill-column:99
-  End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
index 8506f05de30e8cc0a96a51f1e9974916f5d5199c..d0f9a11fc4227b82b510fbe62b2dd6a2827ae235 100644 (file)
@@ -49,7 +49,7 @@ using Inkscape::Extension::Internal::PrintWin32;
 #include "application/editor.h"
 #include "desktop.h"
 #include "desktop-handles.h"
-#include "dialogs/input.h"
+#include "device-manager.h"
 #include "document.h"
 #include "event-context.h"
 #include "extension/db.h"
@@ -807,7 +807,7 @@ inkscape_application_init (const gchar *argv0, gboolean use_gui)
 
     if (use_gui) {
         inkscape_load_menus(inkscape);
-        sp_input_load_from_preferences();
+        Inkscape::DeviceManager::getManager().loadConfig();
     }
 
     /* set language for user interface according setting in preferences */
index 978b555b08df6cd310d4933e9974e302e45c5382..0a9aa27510fdfffa1ef5e514c24b7751930337f7 100644 (file)
@@ -40,7 +40,6 @@ static char const menus_skeleton[] =
 "       <verb verb-id=\"DialogMetadata\" />\n"
 "       <verb verb-id=\"DialogPreferences\" />\n"
 "       <verb verb-id=\"DialogInput\" />\n"
-"       <verb verb-id=\"DialogInput2\" />\n"
 "       <separator/>\n"
 "       <verb verb-id=\"FileClose\" />\n"
 "       <verb verb-id=\"FileQuit\" />\n"
index 555b18349a61594953e47093510e5a1cf066f5ab..570f009447d01e8f02e5eb49a581ab086c3f6a61 100644 (file)
 #include <set>
 #include <glib/gprintf.h>
 #include <glibmm/i18n.h>
+#include <gtkmm/alignment.h>
+#include <gtkmm/cellrenderercombo.h>
+#include <gtkmm/checkbutton.h>
 #include <gtkmm/comboboxtext.h>
 #include <gtkmm/enums.h>
 #include <gtkmm/eventbox.h>
 #include <gtkmm/frame.h>
 #include <gtkmm/image.h>
+#include <gtkmm/liststore.h>
 #include <gtkmm/menubar.h>
 #include <gtkmm/notebook.h>
 #include <gtkmm/paned.h>
@@ -28,8 +32,9 @@
 #include <gtkmm/treestore.h>
 #include <gtkmm/treeview.h>
 
-#include "ui/widget/panel.h"
 #include "device-manager.h"
+#include "preferences.h"
+#include "ui/widget/panel.h"
 
 #include "input.h"
 
@@ -323,38 +328,87 @@ namespace Dialog {
 
 
 
-class MyModelColumns : public Gtk::TreeModel::ColumnRecord
+class DeviceModelColumns : public Gtk::TreeModel::ColumnRecord
 {
 public:
-    Gtk::TreeModelColumn<Glib::ustring>                filename;
     Gtk::TreeModelColumn<Glib::ustring>                description;
     Gtk::TreeModelColumn< Glib::RefPtr<Gdk::Pixbuf> >  thumbnail;
     Gtk::TreeModelColumn<Glib::RefPtr<InputDevice const> > device;
+    Gtk::TreeModelColumn<Gdk::InputMode>               mode;
 
-    MyModelColumns() { add(filename); add(description); add(thumbnail); add(device); }
+    DeviceModelColumns() { add(description); add(thumbnail); add(device); add(mode); }
 };
 
+static std::map<Gdk::InputMode, Glib::ustring> &getModeToString()
+{
+    static std::map<Gdk::InputMode, Glib::ustring> mapping;
+    if (mapping.empty()) {
+        mapping[Gdk::MODE_DISABLED] = _("Disabled");
+        mapping[Gdk::MODE_SCREEN]   = _("Screen");
+        mapping[Gdk::MODE_WINDOW]   = _("Window");
+    }
+
+    return mapping;
+}
+
+static std::map<Glib::ustring, Gdk::InputMode> &getStringToMode()
+{
+    static std::map<Glib::ustring, Gdk::InputMode> mapping;
+    if (mapping.empty()) {
+        mapping[_("Disabled")] = Gdk::MODE_DISABLED;
+        mapping[_("Screen")]   = Gdk::MODE_SCREEN;
+        mapping[_("Window")]   = Gdk::MODE_WINDOW;
+    }
+
+    return mapping;
+}
+
+
+
 class InputDialogImpl : public InputDialog {
 public:
     InputDialogImpl();
     virtual ~InputDialogImpl() {}
 
 private:
-    Glib::RefPtr<Gdk::Pixbuf> corePix;
-    Glib::RefPtr<Gdk::Pixbuf> penPix;
-    Glib::RefPtr<Gdk::Pixbuf> mousePix;
-    Glib::RefPtr<Gdk::Pixbuf> tipPix;
-    Glib::RefPtr<Gdk::Pixbuf> tabletPix;
-    Glib::RefPtr<Gdk::Pixbuf> eraserPix;
-    Glib::RefPtr<Gdk::Pixbuf> sidebuttonsPix;
-
-    Glib::RefPtr<Gdk::Pixbuf> buttonsNonePix;
-    Glib::RefPtr<Gdk::Pixbuf> buttonsOnPix;
-    Glib::RefPtr<Gdk::Pixbuf> buttonsOffPix;
-
-    Glib::RefPtr<Gdk::Pixbuf> axisNonePix;
-    Glib::RefPtr<Gdk::Pixbuf> axisOnPix;
-    Glib::RefPtr<Gdk::Pixbuf> axisOffPix;
+    class ConfPanel : public Gtk::VBox
+    {
+    public:
+        ConfPanel();
+        ~ConfPanel();
+
+        class Blink : public Preferences::Observer
+        {
+        public:
+            Blink(ConfPanel &parent);
+            virtual ~Blink();
+            virtual void notify(Preferences::Entry const &new_val);
+
+            ConfPanel &parent;
+        };
+
+        static void commitCellModeChange(Glib::ustring const &path, Glib::ustring const &newText, Glib::RefPtr<Gtk::TreeStore> store);
+        static void setModeCellString(Gtk::CellRenderer *rndr, Gtk::TreeIter const &iter);
+
+        void saveSettings();
+        void useExtToggled();
+
+        Glib::RefPtr<Gtk::TreeStore> store;
+        Gtk::TreeIter tabletIter;
+        Gtk::TreeView tree;
+        Gtk::ScrolledWindow treeScroller;
+        Blink watcher;
+        Gtk::CheckButton useExt;
+        Gtk::Button save;
+    };
+
+    static DeviceModelColumns &getCols();
+
+    enum PixId {PIX_CORE, PIX_PEN, PIX_MOUSE, PIX_TIP, PIX_TABLET, PIX_ERASER, PIX_SIDEBUTTONS,
+                PIX_BUTTONS_NONE, PIX_BUTTONS_ON, PIX_BUTTONS_OFF,
+                PIX_AXIS_NONE, PIX_AXIS_ON, PIX_AXIS_OFF};
+
+    static Glib::RefPtr<Gdk::Pixbuf> getPix(PixId id);
 
     std::map<Glib::ustring, std::set<guint> > buttonMap;
     std::map<Glib::ustring, std::map<guint, std::pair<guint, gdouble> > > axesMap;
@@ -362,7 +416,6 @@ private:
     GdkInputSource lastSourceSeen;
     Glib::ustring lastDevnameSeen;
 
-    MyModelColumns cols;
     Glib::RefPtr<Gtk::TreeStore> store;
     Gtk::TreeIter tabletIter;
     Gtk::TreeView tree;
@@ -383,7 +436,6 @@ private:
     Gtk::Label keyVal;
     Gtk::Entry keyEntry;
     Gtk::Table devDetails;
-    Gtk::HPaned confSplitter;
     Gtk::Notebook topHolder;
     Gtk::Image testThumb;
     Gtk::Image testButtons[24];
@@ -391,6 +443,9 @@ private:
     Gtk::Table imageTable;
     Gtk::EventBox testDetector;
 
+    ConfPanel cfgPanel;
+
+    static void setupTree( Glib::RefPtr<Gtk::TreeStore> store, Gtk::TreeIter &tablet );
     void setupValueAndCombo( gint reported, gint actual, Gtk::Label& label, Gtk::ComboBoxText& combo );
     void updateTestButtons( Glib::ustring const& key, gint hotButton );
     void updateTestAxes( Glib::ustring const& key, GdkDevice* dev );
@@ -402,15 +457,51 @@ private:
     void handleDeviceChange(const Glib::RefPtr<InputDevice>& device);
     void updateDeviceAxes(const Glib::RefPtr<InputDevice>& device);
     void updateDeviceButtons(const Glib::RefPtr<InputDevice>& device);
-    void updateDeviceLinks(const Glib::RefPtr<InputDevice>& device);
-
-    bool findDevice(const Gtk::TreeModel::iterator& iter,
-                    Glib::ustring id,
-                    Gtk::TreeModel::iterator* result);
-    bool findDeviceByLink(const Gtk::TreeModel::iterator& iter,
-                          Glib::ustring link,
-                          Gtk::TreeModel::iterator* result);
-};
+    static void updateDeviceLinks(const Glib::RefPtr<InputDevice>& device, Gtk::TreeIter &tabletIter, Gtk::TreeView &tree);
+
+    static bool findDevice(const Gtk::TreeModel::iterator& iter,
+                           Glib::ustring id,
+                           Gtk::TreeModel::iterator* result);
+    static bool findDeviceByLink(const Gtk::TreeModel::iterator& iter,
+                                 Glib::ustring link,
+                                 Gtk::TreeModel::iterator* result);
+
+}; // class InputDialogImpl
+
+
+DeviceModelColumns &InputDialogImpl::getCols()
+{
+    static DeviceModelColumns cols;
+    return cols;
+}
+
+Glib::RefPtr<Gdk::Pixbuf> InputDialogImpl::getPix(PixId id)
+{
+    static std::map<PixId, Glib::RefPtr<Gdk::Pixbuf> > mappings;
+
+    mappings[PIX_CORE]          = Gdk::Pixbuf::create_from_xpm_data(core_xpm);
+    mappings[PIX_PEN]           = Gdk::Pixbuf::create_from_xpm_data(pen);
+    mappings[PIX_MOUSE]         = Gdk::Pixbuf::create_from_xpm_data(mouse);
+    mappings[PIX_TIP]           = Gdk::Pixbuf::create_from_xpm_data(tip);
+    mappings[PIX_TABLET]        = Gdk::Pixbuf::create_from_xpm_data(tablet);
+    mappings[PIX_ERASER]        = Gdk::Pixbuf::create_from_xpm_data(eraser);
+    mappings[PIX_SIDEBUTTONS]   = Gdk::Pixbuf::create_from_xpm_data(sidebuttons);
+
+    mappings[PIX_BUTTONS_NONE]  = Gdk::Pixbuf::create_from_xpm_data(button_none);
+    mappings[PIX_BUTTONS_ON]    = Gdk::Pixbuf::create_from_xpm_data(button_on);
+    mappings[PIX_BUTTONS_OFF]   = Gdk::Pixbuf::create_from_xpm_data(button_off);
+
+    mappings[PIX_AXIS_NONE]     = Gdk::Pixbuf::create_from_xpm_data(axis_none_xpm);
+    mappings[PIX_AXIS_ON]       = Gdk::Pixbuf::create_from_xpm_data(axis_on_xpm);
+    mappings[PIX_AXIS_OFF]      = Gdk::Pixbuf::create_from_xpm_data(axis_off_xpm);
+
+    Glib::RefPtr<Gdk::Pixbuf> pix;
+    if (mappings.find(id) != mappings.end()) {
+        pix = mappings[id];
+    }
+
+    return pix;
+}
 
 
 // Now that we've defined the *Impl class, we can do the method to aquire one.
@@ -424,38 +515,23 @@ InputDialog &InputDialog::getInstance()
 InputDialogImpl::InputDialogImpl() :
     InputDialog(),
 
-    corePix(Gdk::Pixbuf::create_from_xpm_data(core_xpm)),
-    penPix(Gdk::Pixbuf::create_from_xpm_data(pen)),
-    mousePix(Gdk::Pixbuf::create_from_xpm_data(mouse)),
-    tipPix(Gdk::Pixbuf::create_from_xpm_data(tip)),
-    tabletPix(Gdk::Pixbuf::create_from_xpm_data(tablet)),
-    eraserPix(Gdk::Pixbuf::create_from_xpm_data(eraser)),
-    sidebuttonsPix(Gdk::Pixbuf::create_from_xpm_data(sidebuttons)),
-
-    buttonsNonePix(Gdk::Pixbuf::create_from_xpm_data(button_none)),
-    buttonsOnPix(Gdk::Pixbuf::create_from_xpm_data(button_on)),
-    buttonsOffPix(Gdk::Pixbuf::create_from_xpm_data(button_off)),
-
-    axisNonePix(Gdk::Pixbuf::create_from_xpm_data(axis_none_xpm)),
-    axisOnPix(Gdk::Pixbuf::create_from_xpm_data(axis_on_xpm)),
-    axisOffPix(Gdk::Pixbuf::create_from_xpm_data(axis_off_xpm)),
-
     lastSourceSeen((GdkInputSource)-1),
     lastDevnameSeen(""),
-    cols(),
-    store(Gtk::TreeStore::create(cols)),
+    store(Gtk::TreeStore::create(getCols())),
+    tabletIter(),
     tree(store),
     frame2(),
-    testFrame("Test Area"),
+    testFrame(_("Test Area")),
     treeScroller(),
     detailScroller(),
     splitter(),
     split2(),
     linkCombo(),
     devDetails(12, 2),
-    confSplitter(),
     topHolder(),
-    imageTable(8, 7)
+    imageTable(8, 7),
+    testDetector(),
+    cfgPanel()
 {
     Gtk::Box *contents = _getContents();
 
@@ -469,14 +545,14 @@ InputDialogImpl::InputDialogImpl() :
 
     testDetector.add(imageTable);
     testFrame.add(testDetector);
-    testThumb.set(tabletPix);
+    testThumb.set(getPix(PIX_TABLET));
     testThumb.set_padding(24, 24);
     imageTable.attach(testThumb, 0, 8, 0, 1, ::Gtk::EXPAND, ::Gtk::EXPAND);
     {
         guint col = 0;
         guint row = 1;
         for ( guint num = 0; num < G_N_ELEMENTS(testButtons); num++ ) {
-            testButtons[num].set(buttonsNonePix);
+            testButtons[num].set(getPix(PIX_BUTTONS_NONE));
             imageTable.attach(testButtons[num], col, col + 1, row, row + 1, ::Gtk::FILL, ::Gtk::FILL);
             col++;
             if (col > 7) {
@@ -487,7 +563,7 @@ InputDialogImpl::InputDialogImpl() :
 
         col = 0;
         for ( guint num = 0; num < G_N_ELEMENTS(testAxes); num++ ) {
-            testAxes[num].set(axisNonePix);
+            testAxes[num].set(getPix(PIX_AXIS_NONE));
             imageTable.attach(testAxes[num], col * 2, (col + 1) * 2, row, row + 1, ::Gtk::FILL, ::Gtk::FILL);
             col++;
             if (col > 3) {
@@ -498,18 +574,16 @@ InputDialogImpl::InputDialogImpl() :
     }
 
 
-    topHolder.append_page(confSplitter, "Configuration");
-    topHolder.append_page(splitter, "Hardware");
-//     confSplitter.show_all();
-//     splitter.show_all();
+    topHolder.append_page(cfgPanel, _("Configuration"));
+    topHolder.append_page(splitter, _("Hardware"));
     topHolder.show_all();
-    topHolder.set_current_page(1);
+    topHolder.set_current_page(0);
 
     contents->pack_start(topHolder);
 
     int rowNum = 0;
 
-    Gtk::Label* lbl = Gtk::manage(new Gtk::Label("Name:"));
+    Gtk::Label* lbl = Gtk::manage(new Gtk::Label(_("Name:")));
     devDetails.attach(*lbl, 0, 1, rowNum, rowNum+ 1,
                       ::Gtk::FILL,
                       ::Gtk::SHRINK);
@@ -519,13 +593,13 @@ InputDialogImpl::InputDialogImpl() :
 
     rowNum++;
 
-    lbl = Gtk::manage(new Gtk::Label("Link:"));
+    lbl = Gtk::manage(new Gtk::Label(_("Link:")));
     devDetails.attach(*lbl, 0, 1, rowNum, rowNum+ 1,
                       ::Gtk::FILL,
                       ::Gtk::SHRINK);
 
-    linkCombo.append_text("None");
-    linkCombo.set_active_text("None");
+    linkCombo.append_text(_("None"));
+    linkCombo.set_active_text(_("None"));
     linkCombo.set_sensitive(false);
     linkConnection = linkCombo.signal_changed().connect(sigc::mem_fun(*this, &InputDialogImpl::linkComboChanged));
 
@@ -534,7 +608,7 @@ InputDialogImpl::InputDialogImpl() :
                       ::Gtk::SHRINK);
     rowNum++;
 
-    lbl = Gtk::manage(new Gtk::Label("Axes count:"));
+    lbl = Gtk::manage(new Gtk::Label(_("Axes count:")));
     devDetails.attach(*lbl, 0, 1, rowNum, rowNum+ 1,
                       ::Gtk::FILL,
                       ::Gtk::SHRINK);
@@ -545,7 +619,7 @@ InputDialogImpl::InputDialogImpl() :
     rowNum++;
 
 /*
-    lbl = Gtk::manage(new Gtk::Label("Actual axes count:"));
+    lbl = Gtk::manage(new Gtk::Label(_("Actual axes count:")));
     devDetails.attach(*lbl, 0, 1, rowNum, rowNum+ 1,
                       ::Gtk::FILL,
                       ::Gtk::SHRINK);
@@ -557,7 +631,7 @@ InputDialogImpl::InputDialogImpl() :
 */
 
     for ( guint barNum = 0; barNum < static_cast<guint>(G_N_ELEMENTS(axesValues)); barNum++ ) {
-        lbl = Gtk::manage(new Gtk::Label("axis:"));
+        lbl = Gtk::manage(new Gtk::Label(_("axis:")));
         devDetails.attach(*lbl, 0, 1, rowNum, rowNum+ 1,
                           ::Gtk::FILL,
                           ::Gtk::SHRINK);
@@ -569,7 +643,7 @@ InputDialogImpl::InputDialogImpl() :
         rowNum++;
     }
 
-    lbl = Gtk::manage(new Gtk::Label("Button count:"));
+    lbl = Gtk::manage(new Gtk::Label(_("Button count:")));
     devDetails.attach(*lbl, 0, 1, rowNum, rowNum+ 1,
                       ::Gtk::FILL,
                       ::Gtk::SHRINK);
@@ -580,7 +654,7 @@ InputDialogImpl::InputDialogImpl() :
     rowNum++;
 
 /*
-    lbl = Gtk::manage(new Gtk::Label("Actual button count:"));
+    lbl = Gtk::manage(new Gtk::Label(_("Actual button count:")));
     devDetails.attach(*lbl, 0, 1, rowNum, rowNum+ 1,
                       ::Gtk::FILL,
                       ::Gtk::SHRINK);
@@ -625,30 +699,37 @@ InputDialogImpl::InputDialogImpl() :
 
 
 
-    Gtk::TreeModel::Row row;
-    Gtk::TreeModel::Row childrow;
-    Gtk::TreeModel::Row deviceRow;
-
-
     //Add the TreeView's view columns:
-    tree.append_column("I", cols.thumbnail);
-    tree.append_column("Bar", cols.description);
+    tree.append_column("I", getCols().thumbnail);
+    tree.append_column("Bar", getCols().description);
 
     tree.set_enable_tree_lines();
     tree.set_headers_visible(false);
     tree.get_selection()->signal_changed().connect(sigc::mem_fun(*this, &InputDialogImpl::resyncToSelection));
 
 
+    setupTree( store, tabletIter );
+
+    Inkscape::DeviceManager::getManager().signalDeviceChanged().connect(sigc::mem_fun(*this, &InputDialogImpl::handleDeviceChange));
+    Inkscape::DeviceManager::getManager().signalAxesChanged().connect(sigc::mem_fun(*this, &InputDialogImpl::updateDeviceAxes));
+    Inkscape::DeviceManager::getManager().signalButtonsChanged().connect(sigc::mem_fun(*this, &InputDialogImpl::updateDeviceButtons));
+    Inkscape::DeviceManager::getManager().signalLinkChanged().connect(sigc::bind<Gtk::TreeIter &, Gtk::TreeView &>(sigc::ptr_fun(&InputDialogImpl::updateDeviceLinks), tabletIter, tree));
+
+    tree.expand_all();
+    show_all_children();
+}
 
+void InputDialogImpl::setupTree( Glib::RefPtr<Gtk::TreeStore> store, Gtk::TreeIter &tablet )
+{
     std::list<Glib::RefPtr<InputDevice const> > devList = Inkscape::DeviceManager::getManager().getDevices();
     if ( !devList.empty() ) {
-        row = *(store->append());
-        row[cols.description] = "Hardware";
+        Gtk::TreeModel::Row row = *(store->append());
+        row[getCols().description] = _("Hardware");
 
-        tabletIter = store->append(row.children());
-        childrow = *tabletIter;
-        childrow[cols.description] = "Tablet";
-        childrow[cols.thumbnail] = tabletPix;
+        tablet = store->append(row.children());
+        Gtk::TreeModel::Row childrow = *tablet;
+        childrow[getCols().description] = _("Tablet");
+        childrow[getCols().thumbnail] = getPix(PIX_TABLET);
 
         for ( std::list<Glib::RefPtr<InputDevice const> >::iterator it = devList.begin(); it != devList.end(); ++it ) {
             Glib::RefPtr<InputDevice const> dev = *it;
@@ -658,25 +739,26 @@ InputDialogImpl::InputDialogImpl() :
 
 //                 if ( dev->getSource() != Gdk::SOURCE_MOUSE ) {
                 if ( dev ) {
-                    deviceRow = *(store->append(childrow.children()));
-                    deviceRow[cols.description] = dev->getName();
-                    deviceRow[cols.device] = dev;
+                    Gtk::TreeModel::Row deviceRow = *(store->append(childrow.children()));
+                    deviceRow[getCols().description] = dev->getName();
+                    deviceRow[getCols().device] = dev;
+                    deviceRow[getCols().mode] = dev->getMode();
                     switch ( dev->getSource() ) {
                         case GDK_SOURCE_MOUSE:
-                            deviceRow[cols.thumbnail] = corePix;
+                            deviceRow[getCols().thumbnail] = getPix(PIX_CORE);
                             break;
                         case GDK_SOURCE_PEN:
-                            if (deviceRow[cols.description] == "pad") {
-                                deviceRow[cols.thumbnail] = sidebuttonsPix;
+                            if (deviceRow[getCols().description] == _("pad")) {
+                                deviceRow[getCols().thumbnail] = getPix(PIX_SIDEBUTTONS);
                             } else {
-                                deviceRow[cols.thumbnail] = tipPix;
+                                deviceRow[getCols().thumbnail] = getPix(PIX_TIP);
                             }
                             break;
                         case GDK_SOURCE_CURSOR:
-                            deviceRow[cols.thumbnail] = mousePix;
+                            deviceRow[getCols().thumbnail] = getPix(PIX_MOUSE);
                             break;
                         case GDK_SOURCE_ERASER:
-                            deviceRow[cols.thumbnail] = eraserPix;
+                            deviceRow[getCols().thumbnail] = getPix(PIX_ERASER);
                             break;
                         default:
                             ; // nothing
@@ -689,18 +771,165 @@ InputDialogImpl::InputDialogImpl() :
     } else {
         g_warning("No devices found");
     }
-    Inkscape::DeviceManager::getManager().signalDeviceChanged().connect(sigc::mem_fun(*this, &InputDialogImpl::handleDeviceChange));
-    Inkscape::DeviceManager::getManager().signalAxesChanged().connect(sigc::mem_fun(*this, &InputDialogImpl::updateDeviceAxes));
-    Inkscape::DeviceManager::getManager().signalButtonsChanged().connect(sigc::mem_fun(*this, &InputDialogImpl::updateDeviceButtons));
-    Inkscape::DeviceManager::getManager().signalLinkChanged().connect(sigc::mem_fun(*this, &InputDialogImpl::updateDeviceLinks));
+}
+
+
+InputDialogImpl::ConfPanel::ConfPanel() :
+    Gtk::VBox(),
+    store(Gtk::TreeStore::create(getCols())),
+    tabletIter(),
+    tree(store),
+    treeScroller(),
+    watcher(*this),
+    useExt(_("Use pressure-sensitive tablet (requires restart)")),
+    save(_("Save"))
+{
+    pack_start(treeScroller);
+
+    treeScroller.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+    treeScroller.add(tree);
+
+    class Foo : public Gtk::TreeModel::ColumnRecord {
+    public :
+        Gtk::TreeModelColumn<Glib::ustring> one;
+        Foo() {add(one);}
+    };
+    static Foo foo;
+    Glib::RefPtr<Gtk::ListStore> poppers = Gtk::ListStore::create(foo);
+    poppers->reference();
+
+    Gtk::TreeModel::Row row = *(poppers->append());
+    row[foo.one] = getModeToString()[Gdk::MODE_DISABLED];
+    row = *(poppers->append());
+    row[foo.one] = getModeToString()[Gdk::MODE_SCREEN];
+    row = *(poppers->append());
+    row[foo.one] = getModeToString()[Gdk::MODE_WINDOW];
+
+    Gtk::CellRendererCombo *rendr = new Gtk::CellRendererCombo();
+    rendr->property_model().set_value(poppers);
+    rendr->property_text_column().set_value(0);
+    rendr->property_has_entry() = false;
+
+    //Add the TreeView's view columns:
+    tree.append_column("I", getCols().thumbnail);
+    tree.append_column("Bar", getCols().description);
+    Gtk::TreeViewColumn *col = new Gtk::TreeViewColumn("X", *rendr);
+    if (col) {
+        tree.append_column(*col);
+        col->set_cell_data_func(*rendr, sigc::ptr_fun(setModeCellString));
+        rendr->signal_edited().connect(sigc::bind(sigc::ptr_fun(commitCellModeChange), store));
+        rendr->property_editable() = true;
+    }
+
+    tree.set_enable_tree_lines();
+    tree.set_headers_visible(false);
+
+    setupTree( store, tabletIter );
+
+    Inkscape::DeviceManager::getManager().signalLinkChanged().connect(sigc::bind<Gtk::TreeIter &, Gtk::TreeView &>(sigc::ptr_fun(&InputDialogImpl::updateDeviceLinks), tabletIter, tree));
 
     tree.expand_all();
-    show_all_children();
+
+    useExt.set_active(Preferences::get()->getBool("/options/useextinput/value"));
+    useExt.signal_toggled().connect(sigc::mem_fun(*this, &InputDialogImpl::ConfPanel::useExtToggled));
+    pack_start(useExt, Gtk::PACK_SHRINK);
+
+    save.signal_clicked().connect(sigc::mem_fun(*this, &InputDialogImpl::ConfPanel::saveSettings));
+    Gtk::Alignment *align = new Gtk::Alignment(Gtk::ALIGN_RIGHT, Gtk::ALIGN_TOP, 0, 0);
+    align->add(save);
+    pack_start(*Gtk::manage(align), Gtk::PACK_SHRINK);
+}
+
+InputDialogImpl::ConfPanel::~ConfPanel()
+{
+}
+
+void InputDialogImpl::ConfPanel::setModeCellString(Gtk::CellRenderer *rndr, Gtk::TreeIter const &iter)
+{
+    if (iter) {
+        Gtk::CellRendererCombo *combo = dynamic_cast<Gtk::CellRendererCombo *>(rndr);
+        if (combo) {
+            Glib::RefPtr<InputDevice const> dev = (*iter)[getCols().device];
+            Gdk::InputMode mode = (*iter)[getCols().mode];
+            if (dev && (getModeToString().find(mode) != getModeToString().end())) {
+                combo->property_text() = getModeToString()[mode];
+            } else {
+                combo->property_text() = "";
+            }
+        }
+    }
+}
+
+void InputDialogImpl::ConfPanel::commitCellModeChange(Glib::ustring const &path, Glib::ustring const &newText, Glib::RefPtr<Gtk::TreeStore> store)
+{
+    Gtk::TreeIter iter = store->get_iter(path);
+    if (iter) {
+        Glib::RefPtr<InputDevice const> dev = (*iter)[getCols().device];
+        if (dev && (getStringToMode().find(newText) != getStringToMode().end())) {
+            Gdk::InputMode mode = getStringToMode()[newText];
+            Inkscape::DeviceManager::getManager().setMode( dev->getId(), mode );
+        }
+    }
+}
+
+void InputDialogImpl::ConfPanel::saveSettings()
+{
+    Inkscape::DeviceManager::getManager().saveConfig();
+}
+
+void InputDialogImpl::ConfPanel::useExtToggled()
+{
+    bool active = useExt.get_active();
+    if (active != Preferences::get()->getBool("/options/useextinput/value")) {
+        Preferences::get()->setBool("/options/useextinput/value", active);
+        if (active) {
+            // As a work-around for a common problem, enable tablet toggles on the calligraphic tool.
+            // Covered in Launchpad bug #196195.
+            Preferences::get()->setBool("/tools/tweak/usepressure", true);
+            Preferences::get()->setBool("/tools/calligraphic/usepressure", true);
+            Preferences::get()->setBool("/tools/calligraphic/usetilt", true);
+        }
+    }
+}
+
+InputDialogImpl::ConfPanel::Blink::Blink(ConfPanel &parent) :
+    Preferences::Observer("/options/useextinput/value"),
+    parent(parent)
+{
+    Preferences::get()->addObserver(*this);
+}
+
+InputDialogImpl::ConfPanel::Blink::~Blink()
+{
+    Preferences::get()->removeObserver(*this);
 }
 
-void InputDialogImpl::handleDeviceChange(const Glib::RefPtr<InputDevice>& /*device*/)
+void InputDialogImpl::ConfPanel::Blink::notify(Preferences::Entry const &new_val)
+{
+    parent.useExt.set_active(new_val.getBool());
+}
+
+void InputDialogImpl::handleDeviceChange(const Glib::RefPtr<InputDevice>& device)
 {
 //     g_message("OUCH!!!! for %p  hits %s", &device, device->getId().c_str());
+    std::vector<Glib::RefPtr<Gtk::TreeStore> > stores;
+    stores.push_back(store);
+    stores.push_back(cfgPanel.store);
+
+    for (std::vector<Glib::RefPtr<Gtk::TreeStore> >::iterator it = stores.begin(); it != stores.end(); ++it) {
+        Gtk::TreeModel::iterator deviceIter;
+        (*it)->foreach_iter( sigc::bind<Glib::ustring, Gtk::TreeModel::iterator*>(
+                                 sigc::ptr_fun(&InputDialogImpl::findDevice),
+                                 device->getId(),
+                                 &deviceIter) );
+        if ( deviceIter ) {
+            Gdk::InputMode mode = device->getMode();
+            Gtk::TreeModel::Row row = *deviceIter;
+            if (row[getCols().mode] != mode) {
+                row[getCols().mode] = mode;
+            }
+        }
+    }
 }
 
 void InputDialogImpl::updateDeviceAxes(const Glib::RefPtr<InputDevice>& device)
@@ -741,7 +970,7 @@ bool InputDialogImpl::findDevice(const Gtk::TreeModel::iterator& iter,
                                  Gtk::TreeModel::iterator* result)
 {
     bool stop = false;
-    Glib::RefPtr<InputDevice const> dev = (*iter)[cols.device];
+    Glib::RefPtr<InputDevice const> dev = (*iter)[getCols().device];
     if ( dev && (dev->getId() == id) ) {
         if ( result ) {
             *result = iter;
@@ -756,7 +985,7 @@ bool InputDialogImpl::findDeviceByLink(const Gtk::TreeModel::iterator& iter,
                                        Gtk::TreeModel::iterator* result)
 {
     bool stop = false;
-    Glib::RefPtr<InputDevice const> dev = (*iter)[cols.device];
+    Glib::RefPtr<InputDevice const> dev = (*iter)[getCols().device];
     if ( dev && (dev->getLink() == link) ) {
         if ( result ) {
             *result = iter;
@@ -766,12 +995,14 @@ bool InputDialogImpl::findDeviceByLink(const Gtk::TreeModel::iterator& iter,
     return stop;
 }
 
-void InputDialogImpl::updateDeviceLinks(const Glib::RefPtr<InputDevice>& device)
+void InputDialogImpl::updateDeviceLinks(const Glib::RefPtr<InputDevice>& device, Gtk::TreeIter &tabletIter, Gtk::TreeView &tree)
 {
+    Glib::RefPtr<Gtk::TreeStore> store = Glib::RefPtr<Gtk::TreeStore>::cast_dynamic(tree.get_model());
+
 //     g_message("Links!!!! for %p  hits [%s]  with link of [%s]", &device, device->getId().c_str(), device->getLink().c_str());
     Gtk::TreeModel::iterator deviceIter;
     store->foreach_iter( sigc::bind<Glib::ustring, Gtk::TreeModel::iterator*>(
-                             sigc::mem_fun(*this, &InputDialogImpl::findDevice),
+                             sigc::ptr_fun(&InputDialogImpl::findDevice),
                              device->getId(),
                              &deviceIter) );
 
@@ -784,14 +1015,15 @@ void InputDialogImpl::updateDeviceLinks(const Glib::RefPtr<InputDevice>& device)
             if ( deviceIter->parent() != tabletIter ) {
                 // Not the child of the tablet. move on up
 
-                Glib::RefPtr<InputDevice const> dev = (*deviceIter)[cols.device];
-                Glib::ustring descr = (*deviceIter)[cols.description];
-                Glib::RefPtr<Gdk::Pixbuf> thumb = (*deviceIter)[cols.thumbnail];
+                Glib::RefPtr<InputDevice const> dev = (*deviceIter)[getCols().device];
+                Glib::ustring descr = (*deviceIter)[getCols().description];
+                Glib::RefPtr<Gdk::Pixbuf> thumb = (*deviceIter)[getCols().thumbnail];
 
                 Gtk::TreeModel::Row deviceRow = *store->append(tabletIter->children());
-                deviceRow[cols.description] = descr;
-                deviceRow[cols.thumbnail] = thumb;
-                deviceRow[cols.device] = dev;
+                deviceRow[getCols().description] = descr;
+                deviceRow[getCols().thumbnail] = thumb;
+                deviceRow[getCols().device] = dev;
+                deviceRow[getCols().mode] = dev->getMode();
 
                 Gtk::TreeModel::iterator oldParent = deviceIter->parent();
                 store->erase(deviceIter);
@@ -805,33 +1037,35 @@ void InputDialogImpl::updateDeviceLinks(const Glib::RefPtr<InputDevice>& device)
                 // Simple case. Not already linked
 
                 Gtk::TreeIter newGroup = store->append(tabletIter->children());
-                (*newGroup)[cols.description] = "Pen";
-                (*newGroup)[cols.thumbnail] = penPix;
+                (*newGroup)[getCols().description] = _("Pen");
+                (*newGroup)[getCols().thumbnail] = getPix(PIX_PEN);
 
-                Glib::RefPtr<InputDevice const> dev = (*deviceIter)[cols.device];
-                Glib::ustring descr = (*deviceIter)[cols.description];
-                Glib::RefPtr<Gdk::Pixbuf> thumb = (*deviceIter)[cols.thumbnail];
+                Glib::RefPtr<InputDevice const> dev = (*deviceIter)[getCols().device];
+                Glib::ustring descr = (*deviceIter)[getCols().description];
+                Glib::RefPtr<Gdk::Pixbuf> thumb = (*deviceIter)[getCols().thumbnail];
 
                 Gtk::TreeModel::Row deviceRow = *store->append(newGroup->children());
-                deviceRow[cols.description] = descr;
-                deviceRow[cols.thumbnail] = thumb;
-                deviceRow[cols.device] = dev;
+                deviceRow[getCols().description] = descr;
+                deviceRow[getCols().thumbnail] = thumb;
+                deviceRow[getCols().device] = dev;
+                deviceRow[getCols().mode] = dev->getMode();
 
 
                 Gtk::TreeModel::iterator linkIter;
                 store->foreach_iter( sigc::bind<Glib::ustring, Gtk::TreeModel::iterator*>(
-                                         sigc::mem_fun(*this, &InputDialogImpl::findDeviceByLink),
+                                         sigc::ptr_fun(&InputDialogImpl::findDeviceByLink),
                                          device->getId(),
                                          &linkIter) );
                 if ( linkIter ) {
-                    dev = (*linkIter)[cols.device];
-                    descr = (*linkIter)[cols.description];
-                    thumb = (*linkIter)[cols.thumbnail];
+                    dev = (*linkIter)[getCols().device];
+                    descr = (*linkIter)[getCols().description];
+                    thumb = (*linkIter)[getCols().thumbnail];
 
                     deviceRow = *store->append(newGroup->children());
-                    deviceRow[cols.description] = descr;
-                    deviceRow[cols.thumbnail] = thumb;
-                    deviceRow[cols.device] = dev;
+                    deviceRow[getCols().description] = descr;
+                    deviceRow[getCols().thumbnail] = thumb;
+                    deviceRow[getCols().device] = dev;
+                    deviceRow[getCols().mode] = dev->getMode();
                     Gtk::TreeModel::iterator oldParent = linkIter->parent();
                     store->erase(linkIter);
                     if ( oldParent->children().empty() ) {
@@ -855,8 +1089,8 @@ void InputDialogImpl::linkComboChanged() {
     Gtk::TreeModel::iterator iter = treeSel->get_selected();
     if (iter) {
         Gtk::TreeModel::Row row = *iter;
-        Glib::ustring val = row[cols.description];
-        Glib::RefPtr<InputDevice const> dev = row[cols.device];
+        Glib::ustring val = row[getCols().description];
+        Glib::RefPtr<InputDevice const> dev = row[getCols().device];
         if ( dev ) {
             if ( linkCombo.get_active_row_number() == 0 ) {
                 // It is the "None" entry
@@ -881,14 +1115,14 @@ void InputDialogImpl::resyncToSelection() {
     Gtk::TreeModel::iterator iter = treeSel->get_selected();
     if (iter) {
         Gtk::TreeModel::Row row = *iter;
-        Glib::ustring val = row[cols.description];
-        Glib::RefPtr<InputDevice const> dev = row[cols.device];
+        Glib::ustring val = row[getCols().description];
+        Glib::RefPtr<InputDevice const> dev = row[getCols().device];
         if ( dev ) {
             devDetails.set_sensitive(true);
 
             linkConnection.block();
             linkCombo.clear_items();
-            linkCombo.append_text("None");
+            linkCombo.append_text(_("None"));
             linkCombo.set_active(0);
             if ( dev->getSource() != Gdk::SOURCE_MOUSE ) {
                 Glib::ustring linked = dev->getLink();
@@ -908,7 +1142,7 @@ void InputDialogImpl::resyncToSelection() {
             linkConnection.unblock();
 
             clear = false;
-            devName.set_label(row[cols.description]);
+            devName.set_label(row[getCols().description]);
             setupValueAndCombo( dev->getNumAxes(), dev->getNumAxes(), devAxesCount, axesCombo);
             setupValueAndCombo( dev->getNumKeys(), dev->getNumKeys(), devKeyCount, buttonCombo);
         }
@@ -945,12 +1179,12 @@ void InputDialogImpl::updateTestButtons( Glib::ustring const& key, gint hotButto
     for ( gint i = 0; i < static_cast<gint>(G_N_ELEMENTS(testButtons)); i++ ) {
         if ( buttonMap[key].find(i) != buttonMap[key].end() ) {
             if ( i == hotButton ) {
-                testButtons[i].set(buttonsOnPix);
+                testButtons[i].set(getPix(PIX_BUTTONS_ON));
             } else {
-                testButtons[i].set(buttonsOffPix);
+                testButtons[i].set(getPix(PIX_BUTTONS_OFF));
             }
         } else {
-            testButtons[i].set(buttonsNonePix);
+            testButtons[i].set(getPix(PIX_BUTTONS_NONE));
         }
     }
 }
@@ -963,8 +1197,8 @@ void InputDialogImpl::updateTestAxes( Glib::ustring const& key, GdkDevice* dev )
         Gtk::TreeModel::iterator iter = treeSel->get_selected();
         if (iter) {
             Gtk::TreeModel::Row row = *iter;
-            Glib::ustring val = row[cols.description];
-            Glib::RefPtr<InputDevice const> idev = row[cols.device];
+            Glib::ustring val = row[getCols().description];
+            Glib::RefPtr<InputDevice const> idev = row[getCols().device];
             if ( !idev || (idev->getId() != key) ) {
                 dev = 0;
             }
@@ -977,13 +1211,13 @@ void InputDialogImpl::updateTestAxes( Glib::ustring const& key, GdkDevice* dev )
             switch ( axesMap[key][i].first ) {
                 case 0:
                 case 1:
-                    testAxes[i].set(axisNonePix);
+                    testAxes[i].set(getPix(PIX_AXIS_NONE));
                     if ( dev && (i < static_cast<gint>(G_N_ELEMENTS(axesValues)) ) ) {
                         axesValues[i].set_sensitive(false);
                     }
                     break;
                 case 2:
-                    testAxes[i].set(axisOffPix);
+                    testAxes[i].set(getPix(PIX_AXIS_OFF));
                     axesValues[i].set_sensitive(true);
                     if ( dev && (i < static_cast<gint>(G_N_ELEMENTS(axesValues)) ) ) {
                         if ( (dev->axes[i].max - dev->axes[i].min) > epsilon ) {
@@ -996,7 +1230,7 @@ void InputDialogImpl::updateTestAxes( Glib::ustring const& key, GdkDevice* dev )
                     }
                     break;
                 case 3:
-                    testAxes[i].set(axisOnPix);
+                    testAxes[i].set(getPix(PIX_AXIS_ON));
                     axesValues[i].set_sensitive(true);
                     if ( dev && (i < static_cast<gint>(G_N_ELEMENTS(axesValues)) ) ) {
                         if ( (dev->axes[i].max - dev->axes[i].min) > epsilon ) {
@@ -1010,7 +1244,7 @@ void InputDialogImpl::updateTestAxes( Glib::ustring const& key, GdkDevice* dev )
             }
 
         } else {
-            testAxes[i].set(axisNonePix);
+            testAxes[i].set(getPix(PIX_AXIS_NONE));
         }
     }
     if ( !dev ) {
@@ -1180,30 +1414,30 @@ bool InputDialogImpl::eventSnoop(GdkEvent* event)
         switch (source) {
             case GDK_SOURCE_MOUSE:
             {
-                testThumb.set(corePix);
+                testThumb.set(getPix(PIX_CORE));
             }
             break;
             case GDK_SOURCE_CURSOR:
             {
 //                 g_message("flip to cursor");
-                testThumb.set(mousePix);
+                testThumb.set(getPix(PIX_MOUSE));
             }
             break;
             case GDK_SOURCE_PEN:
             {
-                if (devName == "pad") {
+                if (devName == _("pad")) {
 //                     g_message("flip to pad");
-                    testThumb.set(sidebuttonsPix);
+                    testThumb.set(getPix(PIX_SIDEBUTTONS));
                 } else {
 //                     g_message("flip to pen");
-                    testThumb.set(tipPix);
+                    testThumb.set(getPix(PIX_TIP));
                 }
             }
             break;
             case GDK_SOURCE_ERASER:
             {
 //                 g_message("flip to eraser");
-                testThumb.set(eraserPix);
+                testThumb.set(getPix(PIX_ERASER));
             }
             break;
 //             default:
index 38666f52c41bb8d4571482503c4ce42a57f7bbb6..186612af0d94853e77b8512010d5adb454c86057 100644 (file)
@@ -25,7 +25,7 @@ class InputDialog : public UI::Widget::Panel
 public:
     static InputDialog &getInstance();
 
-    InputDialog() : UI::Widget::Panel("", "/dialogs/inputdevices2", SP_VERB_DIALOG_INPUT2) {}
+    InputDialog() : UI::Widget::Panel("", "/dialogs/inputdevices", SP_VERB_DIALOG_INPUT) {}
     virtual ~InputDialog() {}
 };
 
index 66b6140b446df068ca3a6b268b3a2eb8d2b7ff5f..24c17aad8fd93f4035f486201cd626324c8b396b 100644 (file)
@@ -40,7 +40,6 @@
 #include "desktop-handles.h"
 #include "dialogs/clonetiler.h"
 #include "dialogs/find.h"
-#include "dialogs/input.h"
 #include "dialogs/item-properties.h"
 #include "dialogs/spellcheck.h"
 #include "dialogs/text-edit.h"
@@ -1791,9 +1790,6 @@ DialogVerb::perform(SPAction *action, void *data, void */*pdata*/)
         }
 #endif*/
         case SP_VERB_DIALOG_INPUT:
-            sp_input_dialog();
-            break;
-        case SP_VERB_DIALOG_INPUT2:
             dt->_dlg_mgr->showDialog("InputDevices");
             break;
         case SP_VERB_DIALOG_EXTENSIONEDITOR:
@@ -2640,8 +2636,6 @@ Verb *Verb::_base_verbs[] = {
 #endif*/
     new DialogVerb(SP_VERB_DIALOG_INPUT, "DialogInput", N_("_Input Devices..."),
                    N_("Configure extended input devices, such as a graphics tablet"), INKSCAPE_ICON_DIALOG_INPUT_DEVICES),
-    new DialogVerb(SP_VERB_DIALOG_INPUT2, "DialogInput2", N_("_Input Devices (new)..."),
-                   N_("Configure extended input devices, such as a graphics tablet"), INKSCAPE_ICON_DIALOG_INPUT_DEVICES),
     new DialogVerb(SP_VERB_DIALOG_EXTENSIONEDITOR, "org.inkscape.dialogs.extensioneditor", N_("_Extensions..."),
                    N_("Query information about extensions"), NULL),
     new DialogVerb(SP_VERB_DIALOG_LAYERS, "DialogLayers", N_("Layer_s..."),
index eea6042c0f92720f3f8d648fd9295fa8ea3a9825..36bb9f9d9963624c252a4e86828043f6480da868 100644 (file)
@@ -247,7 +247,6 @@ enum {
     SP_VERB_XMPP_CLIENT,
 #endif*/
     SP_VERB_DIALOG_INPUT,
-    SP_VERB_DIALOG_INPUT2,
     SP_VERB_DIALOG_EXTENSIONEDITOR,
     SP_VERB_DIALOG_LAYERS,
     SP_VERB_DIALOG_LIVE_PATH_EFFECT,