From 7e73723961129cf0356d877d7dce5c7f265c9800 Mon Sep 17 00:00:00 2001 From: Thomas Jaeger Date: Tue, 19 Feb 2013 00:50:22 -0500 Subject: [PATCH] Port CellRendererTextish to Vala We need an actual GObject, otherwise things blow up in our face. Unfortunately, you can't create custom GObjects with gtkmm, so we have to look elsewhere. As of now, this requires slight modifications of the gtk+-3.0.vapi file. --- Makefile | 6 +- actions.cc | 187 +++----- actions.h | 12 +- cellrenderertextish.c | 979 +++++++++++++++++++++++++++++++++++++++ cellrenderertextish.h | 58 +++ cellrenderertextish.vala | 127 +++++ prefs.cc | 20 +- prefs.h | 4 +- win.h | 19 - 9 files changed, 1248 insertions(+), 164 deletions(-) create mode 100644 cellrenderertextish.c create mode 100644 cellrenderertextish.h create mode 100644 cellrenderertextish.vala diff --git a/Makefile b/Makefile index c7b2af26..33b02adf 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,7 @@ OFLAGS = -O2 AOFLAGS = -O3 STROKEFLAGS = -Wall -std=c99 $(DFLAGS) CXXFLAGS = -Wall $(DFLAGS) -DLOCALEDIR=\"$(LOCALEDIR)\" `pkg-config gtkmm-3.0 dbus-glib-1 --cflags` +CFLAGS = -Wall $(DFLAGS) -DLOCALEDIR=\"$(LOCALEDIR)\" `pkg-config gtk+-3.0 --cflags` -DGETTEXT_PACKAGE='"easystroke"' LDFLAGS = $(DFLAGS) LIBS = $(DFLAGS) -lboost_serialization -lX11 -lXext -lXi -lXfixes -lXtst `pkg-config gtkmm-3.0 dbus-glib-1 --libs` @@ -34,7 +35,7 @@ MANPAGE = easystroke.1 CCFILES = $(wildcard *.cc) HFILES = $(wildcard *.h) -OFILES = $(patsubst %.cc,%.o,$(CCFILES)) stroke.o gui.o desktop.o version.o +OFILES = $(patsubst %.cc,%.o,$(CCFILES)) stroke.o cellrenderertextish.o gui.o desktop.o version.o POFILES = $(wildcard po/*.po) MOFILES = $(patsubst po/%.po,po/%/LC_MESSAGES/easystroke.mo,$(POFILES)) MODIRS = $(patsubst po/%.po,po/%,$(POFILES)) @@ -64,6 +65,9 @@ $(BINARY): $(OFILES) stroke.o: stroke.c $(CC) $(STROKEFLAGS) $(AOFLAGS) -MT $@ -MMD -MP -MF $*.Po -o $@ -c $< +%.o: %.c + $(CC) $(CFLAGS) $(OFLAGS) -MT $@ -MMD -MP -MF $*.Po -o $@ -c $< + %.o: %.cc $(CXX) $(CXXFLAGS) $(OFLAGS) -MT $@ -MMD -MP -MF $*.Po -o $@ -c $< diff --git a/actions.cc b/actions.cc index 222f5b85..e9544f06 100644 --- a/actions.cc +++ b/actions.cc @@ -21,6 +21,7 @@ #include #include #include "grabber.h" +#include "cellrenderertextish.h" #include @@ -56,124 +57,24 @@ TreeViewMulti::TreeViewMulti() : Gtk::TreeView(), pending(false) { get_selection()->set_select_function(sigc::group(&negate, sigc::ref(pending))); } -class CellEditableAccel : public Gtk::EventBox, public Gtk::CellEditable { - CellRendererTextish *parent; - Glib::ustring path; -public: - CellEditableAccel(CellRendererTextish *parent_, const Glib::ustring &path_, Gtk::Widget &widget) : - Glib::ObjectBase(typeid(CellEditableAccel)), - parent(parent_), path(path_) - { - WIDGET(Gtk::Label, label, _("Key combination...")); - label.set_alignment(0.0, 0.5); - add(label); - override_background_color(widget.get_style_context()->get_background_color(Gtk::STATE_FLAG_SELECTED), Gtk::STATE_FLAG_NORMAL); - label.override_color(widget.get_style_context()->get_color(Gtk::STATE_FLAG_SELECTED), Gtk::STATE_FLAG_NORMAL); - show_all(); - } -protected: - - virtual void start_editing_vfunc(GdkEvent *event) { - add_modal_grab(); -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - gdk_keyboard_grab(get_window()->gobj(), false, gdk_event_get_time(event)); -#pragma GCC diagnostic pop - signal_key_press_event().connect(sigc::mem_fun(*this, &CellEditableAccel::on_key)); - } - - bool on_key(GdkEventKey* event) { - if (event->is_modifier) - return true; - switch (event->keyval) { - case GDK_KEY_Super_L: - case GDK_KEY_Super_R: - case GDK_KEY_Hyper_L: - case GDK_KEY_Hyper_R: - return true; - } - guint mods = event->state & gtk_accelerator_get_default_mod_mask(); - guint key = XkbKeycodeToKeysym(dpy, event->hardware_keycode, 0, 0); - - editing_done(); - remove_widget(); - - parent->signal_key_edited().emit(path, key, (Gdk::ModifierType)mods, event->hardware_keycode); - return true; - } - - virtual void on_editing_done() { - remove_modal_grab(); -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - gdk_keyboard_ungrab(CurrentTime); -#pragma GCC diagnostic pop - Gtk::CellEditable::on_editing_done(); - } -}; - -class CellEditableCombo : public Gtk::ComboBoxText { - CellRendererTextish *parent; - Glib::ustring path; -public: - CellEditableCombo(CellRendererTextish *parent_, const Glib::ustring &path_, Gtk::Widget &widget, const char **items) : - Glib::ObjectBase(typeid(CellEditableCombo)), - parent(parent_), path(path_) - { - while (*items) - append(_(*(items++))); - } -protected: - virtual void on_changed() { - parent->signal_combo_edited().emit(path, get_active_row_number()); - } -}; - -class CellEditableDummy : public Gtk::EventBox, public Gtk::CellEditable { -public: - CellEditableDummy() : Glib::ObjectBase(typeid(CellEditableDummy)) {} -protected: - virtual void start_editing_vfunc(GdkEvent *event) { - editing_done(); - remove_widget(); - } -}; - -Gtk::CellEditable* CellRendererTextish::start_editing_vfunc(GdkEvent *event, Gtk::Widget &widget, const Glib::ustring &path, - const Gdk::Rectangle &background_area, const Gdk::Rectangle &cell_area, Gtk::CellRendererState flags) { - if (!property_editable()) - return 0; - switch (mode) { - case TEXT: - return Gtk::CellRendererText::start_editing_vfunc(event, widget, path, background_area, cell_area, flags); - case KEY: - return Gtk::manage(new CellEditableAccel(this, path, widget)); - case COMBO: - return Gtk::manage(new CellEditableCombo(this, path, widget, items)); - case POPUP: - return Gtk::manage(new CellEditableDummy); - } - return NULL; -} - enum Type { COMMAND, KEY, TEXT, SCROLL, IGNORE, BUTTON, MISC }; struct TypeInfo { Type type; const char *name; const std::type_info *type_info; - const CellRendererTextish::Mode mode; + const CellRendererTextishMode mode; }; TypeInfo all_types[8] = { - { COMMAND, N_("Command"), &typeid(Command), CellRendererTextish::TEXT }, - { KEY, N_("Key"), &typeid(SendKey), CellRendererTextish::KEY }, - { TEXT, N_("Text"), &typeid(SendText), CellRendererTextish::TEXT }, - { SCROLL, N_("Scroll"), &typeid(Scroll), CellRendererTextish::KEY }, - { IGNORE, N_("Ignore"), &typeid(Ignore), CellRendererTextish::KEY }, - { BUTTON, N_("Button"), &typeid(Button), CellRendererTextish::POPUP }, - { MISC, N_("Misc"), &typeid(Misc), CellRendererTextish::COMBO }, - { COMMAND, 0, 0, CellRendererTextish::TEXT } + { COMMAND, N_("Command"), &typeid(Command), CELL_RENDERER_TEXTISH_MODE_Text }, + { KEY, N_("Key"), &typeid(SendKey), CELL_RENDERER_TEXTISH_MODE_Key }, + { TEXT, N_("Text"), &typeid(SendText), CELL_RENDERER_TEXTISH_MODE_Text }, + { SCROLL, N_("Scroll"), &typeid(Scroll), CELL_RENDERER_TEXTISH_MODE_Key }, + { IGNORE, N_("Ignore"), &typeid(Ignore), CELL_RENDERER_TEXTISH_MODE_Key }, + { BUTTON, N_("Button"), &typeid(Button), CELL_RENDERER_TEXTISH_MODE_Popup }, + { MISC, N_("Misc"), &typeid(Misc), CELL_RENDERER_TEXTISH_MODE_Combo }, + { COMMAND, 0, 0, CELL_RENDERER_TEXTISH_MODE_Text } }; const Type from_name(Glib::ustring name) { @@ -189,6 +90,31 @@ const char *type_info_to_name(const std::type_info *info) { return ""; } +static void on_actions_cell_data_arg(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) { + GtkTreePath *path = gtk_tree_model_get_path(tree_model, iter); + gchar *path_string = gtk_tree_path_to_string(path); + ((Actions *)data)->on_cell_data_arg(cell, path_string); + g_free(path_string); + gtk_tree_path_free(path); +} + +static void on_actions_accel_edited(CellRendererTextish *, gchar *path, GdkModifierType mods, guint code, gpointer data) { + guint key = XkbKeycodeToKeysym(dpy, code, 0, 0); + ((Actions *)data)->on_accel_edited(path, key, mods, code); +} + +static void on_actions_combo_edited(CellRendererTextish *, gchar *path, guint row, gpointer data) { + ((Actions *)data)->on_combo_edited(path, row); +} + +static void on_actions_text_edited(GtkCellRendererText *, gchar *path, gchar *new_text, gpointer data) { + ((Actions *)data)->on_text_edited(path, new_text); +} + +static void on_actions_editing_started(GtkCellRenderer *, GtkCellEditable *editable, const gchar *path, gpointer data) { + ((Actions *)data)->on_arg_editing_started(editable, path); +} + Actions::Actions() : apps_view(0), vpaned_position(-1), @@ -264,18 +190,19 @@ Actions::Actions() : col_type->add_attribute(type_renderer->property_text(), cols.type); col_type->set_cell_data_func(*type_renderer, sigc::mem_fun(*this, &Actions::on_cell_data_type)); - CellRendererTextish *arg_renderer = Gtk::manage(new CellRendererTextish); - n = tv.append_column(_("Details"), *arg_renderer); - Gtk::TreeView::Column *col_arg = tv.get_column(n-1); - col_arg->add_attribute(arg_renderer->property_text(), cols.arg); - col_arg->set_cell_data_func(*arg_renderer, sigc::mem_fun(*this, &Actions::on_cell_data_arg)); - col_arg->set_resizable(); - arg_renderer->property_editable() = true; - arg_renderer->signal_key_edited().connect(sigc::mem_fun(*this, &Actions::on_accel_edited)); - arg_renderer->signal_combo_edited().connect(sigc::mem_fun(*this, &Actions::on_combo_edited)); - arg_renderer->signal_edited().connect(sigc::mem_fun(*this, &Actions::on_text_edited)); - arg_renderer->signal_editing_started().connect(sigc::mem_fun(*this, &Actions::on_arg_editing_started)); - arg_renderer->items = Misc::types; + int i = 0; + while (Misc::types[i]) i++; + CellRendererTextish *arg_renderer = cell_renderer_textish_new_with_items ((gchar**)Misc::types, i); + GtkTreeViewColumn *col_arg = gtk_tree_view_column_new_with_attributes(_("Details"), GTK_CELL_RENDERER (arg_renderer), "text", cols.arg.index(), NULL); + gtk_tree_view_append_column(tv.gobj(), col_arg); + + gtk_tree_view_column_set_cell_data_func (col_arg, GTK_CELL_RENDERER (arg_renderer), on_actions_cell_data_arg, this, NULL); + gtk_tree_view_column_set_resizable(col_arg, true); + g_object_set(arg_renderer, "editable", true, NULL); + g_signal_connect(arg_renderer, "key-edited", G_CALLBACK(on_actions_accel_edited), this); + g_signal_connect(arg_renderer, "combo-edited", G_CALLBACK(on_actions_combo_edited), this); + g_signal_connect(arg_renderer, "edited", G_CALLBACK(on_actions_text_edited), this); + g_signal_connect(arg_renderer, "editing-started", G_CALLBACK(on_actions_editing_started), this); update_action_list(); tv.set_model(tm); @@ -331,15 +258,14 @@ void Actions::on_cell_data_type(Gtk::CellRenderer* cell, const Gtk::TreeModel::i cell->property_sensitive().set_value(!deactivated); } -void Actions::on_cell_data_arg(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter) { +void Actions::on_cell_data_arg(GtkCellRenderer *cell, gchar *path) { + Gtk::TreeModel::iterator iter = tm->get_iter(path); bool bold = (*iter)[cols.action_bold]; bool deactivated = (*iter)[cols.deactivated]; - cell->property_sensitive().set_value(!deactivated); - CellRendererTextish *renderer = dynamic_cast(cell); + g_object_set(cell, "sensitive", !deactivated, "weight", bold ? 700 : 400, NULL); + CellRendererTextish *renderer = CELL_RENDERER_TEXTISH (cell); if (!renderer) return; - renderer->property_weight().set_value(bold ? 700 : 400); - Glib::ustring str = (*iter)[cols.type]; renderer->mode = all_types[from_name(str)].mode; } @@ -929,7 +855,7 @@ void Actions::on_name_edited(const Glib::ustring& path, const Glib::ustring& new focus(row[cols.id], 2, editing_new); } -void Actions::on_text_edited(const Glib::ustring& path, const Glib::ustring& new_text) { +void Actions::on_text_edited(const gchar *path, const gchar *new_text) { Gtk::TreeRow row(*tm->get_iter(path)); Type type = from_name(row[cols.type]); if (type == COMMAND) { @@ -941,7 +867,8 @@ void Actions::on_text_edited(const Glib::ustring& path, const Glib::ustring& new update_actions(); } -void Actions::on_accel_edited(const Glib::ustring& path_string, guint accel_key, Gdk::ModifierType accel_mods, guint hardware_keycode) { +void Actions::on_accel_edited(const gchar *path_string, guint accel_key, GdkModifierType mods, guint hardware_keycode) { + Gdk::ModifierType accel_mods = (Gdk::ModifierType)mods; Gtk::TreeRow row(*tm->get_iter(path_string)); Type type = from_name(row[cols.type]); if (type == KEY) { @@ -967,7 +894,7 @@ void Actions::on_accel_edited(const Glib::ustring& path_string, guint accel_key, update_actions(); } -void Actions::on_combo_edited(const Glib::ustring& path_string, guint item) { +void Actions::on_combo_edited(const gchar *path_string, guint item) { RMisc misc = Misc::create((Misc::Type)item); Glib::ustring str = misc->get_label(); Gtk::TreeRow row(*tm->get_iter(path_string)); @@ -986,7 +913,7 @@ void Actions::on_something_editing_started(Gtk::CellEditable* editable, const Gl editing = true; } -void Actions::on_arg_editing_started(Gtk::CellEditable* editable, const Glib::ustring& path) { +void Actions::on_arg_editing_started(GtkCellEditable *editable, const gchar *path) { tv.grab_focus(); Gtk::TreeRow row(*tm->get_iter(path)); if (from_name(row[cols.type]) != BUTTON) diff --git a/actions.h b/actions.h index 0d15c351..49b9db61 100644 --- a/actions.h +++ b/actions.h @@ -42,17 +42,19 @@ class Actions { void on_button_record(); void on_selection_changed(); void on_name_edited(const Glib::ustring& path, const Glib::ustring& new_text); - void on_text_edited(const Glib::ustring& path, const Glib::ustring& new_text); void on_type_edited(const Glib::ustring& path, const Glib::ustring& new_text); - void on_accel_edited(const Glib::ustring& path_string, guint accel_key, Gdk::ModifierType accel_mods, guint hardware_keycode); - void on_combo_edited(const Glib::ustring& path_string, guint item); - void on_arg_editing_started(Gtk::CellEditable* editable, const Glib::ustring& path); void on_something_editing_started(Gtk::CellEditable* editable, const Glib::ustring& path); void on_something_editing_canceled(); void on_row_activated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column); void on_cell_data_name(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter); void on_cell_data_type(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter); - void on_cell_data_arg(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter); +public: + void on_accel_edited(const gchar *path_string, guint accel_key, GdkModifierType accel_mods, guint hardware_keycode); + void on_combo_edited(const gchar *path_string, guint item); + void on_arg_editing_started(GtkCellEditable *editable, const gchar *path); + void on_text_edited(const gchar *path, const gchar *new_text); + void on_cell_data_arg(GtkCellRenderer *cell, gchar *path); +private: int compare_ids(const Gtk::TreeModel::iterator &a, const Gtk::TreeModel::iterator &b); class OnStroke; Gtk::TreeRow get_selected_row(); diff --git a/cellrenderertextish.c b/cellrenderertextish.c new file mode 100644 index 00000000..e9f4f59e --- /dev/null +++ b/cellrenderertextish.c @@ -0,0 +1,979 @@ +/* cellrenderertextish.c generated by valac 0.18.1, the Vala compiler + * generated from cellrenderertextish.vala, do not modify */ + +/* compile with valac -c cellrenderertextish.vala --pkg gtk+-3.0 -C -H cellrenderertextish.h */ + +#include +#include +#include +#include +#include +#include +#include + + +#define TYPE_CELL_RENDERER_TEXTISH (cell_renderer_textish_get_type ()) +#define CELL_RENDERER_TEXTISH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CELL_RENDERER_TEXTISH, CellRendererTextish)) +#define CELL_RENDERER_TEXTISH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CELL_RENDERER_TEXTISH, CellRendererTextishClass)) +#define IS_CELL_RENDERER_TEXTISH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CELL_RENDERER_TEXTISH)) +#define IS_CELL_RENDERER_TEXTISH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CELL_RENDERER_TEXTISH)) +#define CELL_RENDERER_TEXTISH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CELL_RENDERER_TEXTISH, CellRendererTextishClass)) + +typedef struct _CellRendererTextish CellRendererTextish; +typedef struct _CellRendererTextishClass CellRendererTextishClass; +typedef struct _CellRendererTextishPrivate CellRendererTextishPrivate; + +#define CELL_RENDERER_TEXTISH_TYPE_MODE (cell_renderer_textish_mode_get_type ()) +#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) + +#define TYPE_CELL_EDITABLE_ACCEL (cell_editable_accel_get_type ()) +#define CELL_EDITABLE_ACCEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CELL_EDITABLE_ACCEL, CellEditableAccel)) +#define CELL_EDITABLE_ACCEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CELL_EDITABLE_ACCEL, CellEditableAccelClass)) +#define IS_CELL_EDITABLE_ACCEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CELL_EDITABLE_ACCEL)) +#define IS_CELL_EDITABLE_ACCEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CELL_EDITABLE_ACCEL)) +#define CELL_EDITABLE_ACCEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CELL_EDITABLE_ACCEL, CellEditableAccelClass)) + +typedef struct _CellEditableAccel CellEditableAccel; +typedef struct _CellEditableAccelClass CellEditableAccelClass; + +#define TYPE_CELL_EDITABLE_COMBO (cell_editable_combo_get_type ()) +#define CELL_EDITABLE_COMBO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CELL_EDITABLE_COMBO, CellEditableCombo)) +#define CELL_EDITABLE_COMBO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CELL_EDITABLE_COMBO, CellEditableComboClass)) +#define IS_CELL_EDITABLE_COMBO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CELL_EDITABLE_COMBO)) +#define IS_CELL_EDITABLE_COMBO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CELL_EDITABLE_COMBO)) +#define CELL_EDITABLE_COMBO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CELL_EDITABLE_COMBO, CellEditableComboClass)) + +typedef struct _CellEditableCombo CellEditableCombo; +typedef struct _CellEditableComboClass CellEditableComboClass; + +#define TYPE_CELL_EDITABLE_DUMMY (cell_editable_dummy_get_type ()) +#define CELL_EDITABLE_DUMMY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CELL_EDITABLE_DUMMY, CellEditableDummy)) +#define CELL_EDITABLE_DUMMY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CELL_EDITABLE_DUMMY, CellEditableDummyClass)) +#define IS_CELL_EDITABLE_DUMMY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CELL_EDITABLE_DUMMY)) +#define IS_CELL_EDITABLE_DUMMY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CELL_EDITABLE_DUMMY)) +#define CELL_EDITABLE_DUMMY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CELL_EDITABLE_DUMMY, CellEditableDummyClass)) + +typedef struct _CellEditableDummy CellEditableDummy; +typedef struct _CellEditableDummyClass CellEditableDummyClass; +typedef struct _CellEditableDummyPrivate CellEditableDummyPrivate; +typedef struct _CellEditableAccelPrivate CellEditableAccelPrivate; +#define _g_free0(var) (var = (g_free (var), NULL)) +typedef struct _CellEditableComboPrivate CellEditableComboPrivate; +typedef struct _Block1Data Block1Data; + +typedef enum { + CELL_RENDERER_TEXTISH_MODE_Text, + CELL_RENDERER_TEXTISH_MODE_Key, + CELL_RENDERER_TEXTISH_MODE_Popup, + CELL_RENDERER_TEXTISH_MODE_Combo +} CellRendererTextishMode; + +struct _CellRendererTextish { + GtkCellRendererText parent_instance; + CellRendererTextishPrivate * priv; + CellRendererTextishMode mode; + gchar** items; + gint items_length1; +}; + +struct _CellRendererTextishClass { + GtkCellRendererTextClass parent_class; +}; + +struct _CellRendererTextishPrivate { + GtkCellEditable* cell; +}; + +struct _CellEditableDummy { + GtkEventBox parent_instance; + CellEditableDummyPrivate * priv; +}; + +struct _CellEditableDummyClass { + GtkEventBoxClass parent_class; + void (*start_editing) (CellEditableDummy* self, GdkEvent* event); +}; + +struct _CellEditableDummyPrivate { + gboolean _editing_canceled; +}; + +struct _CellEditableAccel { + GtkEventBox parent_instance; + CellEditableAccelPrivate * priv; +}; + +struct _CellEditableAccelClass { + GtkEventBoxClass parent_class; + void (*start_editing) (CellEditableAccel* self, GdkEvent* event); +}; + +struct _CellEditableAccelPrivate { + gboolean _editing_canceled; + CellRendererTextish* parent; + gchar* path; +}; + +struct _CellEditableCombo { + GtkComboBoxText parent_instance; + CellEditableComboPrivate * priv; +}; + +struct _CellEditableComboClass { + GtkComboBoxTextClass parent_class; +}; + +struct _CellEditableComboPrivate { + CellRendererTextish* parent; + gchar* path; +}; + +struct _Block1Data { + int _ref_count_; + CellEditableCombo * self; + CellRendererTextish* parent; + gchar* path; +}; + + +static gpointer cell_renderer_textish_parent_class = NULL; +static gpointer cell_editable_dummy_parent_class = NULL; +static GtkCellEditableIface* cell_editable_dummy_gtk_cell_editable_parent_iface = NULL; +static gpointer cell_editable_accel_parent_class = NULL; +static GtkCellEditableIface* cell_editable_accel_gtk_cell_editable_parent_iface = NULL; +static gpointer cell_editable_combo_parent_class = NULL; + +GType cell_renderer_textish_get_type (void) G_GNUC_CONST; +GType cell_renderer_textish_mode_get_type (void) G_GNUC_CONST; +#define CELL_RENDERER_TEXTISH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_CELL_RENDERER_TEXTISH, CellRendererTextishPrivate)) +enum { + CELL_RENDERER_TEXTISH_DUMMY_PROPERTY +}; +CellRendererTextish* cell_renderer_textish_new (void); +CellRendererTextish* cell_renderer_textish_construct (GType object_type); +CellRendererTextish* cell_renderer_textish_new_with_items (gchar** items, int items_length1); +CellRendererTextish* cell_renderer_textish_construct_with_items (GType object_type, gchar** items, int items_length1); +static gchar** _vala_array_dup1 (gchar** self, int length); +static GtkCellEditable* cell_renderer_textish_real_start_editing (GtkCellRenderer* base, GdkEvent* event, GtkWidget* widget, const gchar* path, GdkRectangle* background_area, GdkRectangle* cell_area, GtkCellRendererState flags); +CellEditableAccel* cell_editable_accel_new (CellRendererTextish* parent, const gchar* path, GtkWidget* widget); +CellEditableAccel* cell_editable_accel_construct (GType object_type, CellRendererTextish* parent, const gchar* path, GtkWidget* widget); +GType cell_editable_accel_get_type (void) G_GNUC_CONST; +CellEditableCombo* cell_editable_combo_new (CellRendererTextish* parent, const gchar* path, GtkWidget* widget, gchar** items, int items_length1); +CellEditableCombo* cell_editable_combo_construct (GType object_type, CellRendererTextish* parent, const gchar* path, GtkWidget* widget, gchar** items, int items_length1); +GType cell_editable_combo_get_type (void) G_GNUC_CONST; +CellEditableDummy* cell_editable_dummy_new (void); +CellEditableDummy* cell_editable_dummy_construct (GType object_type); +GType cell_editable_dummy_get_type (void) G_GNUC_CONST; +static void g_cclosure_user_marshal_VOID__STRING_FLAGS_UINT (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data); +static void g_cclosure_user_marshal_VOID__STRING_UINT (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data); +static void cell_renderer_textish_finalize (GObject* obj); +#define CELL_EDITABLE_DUMMY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_CELL_EDITABLE_DUMMY, CellEditableDummyPrivate)) +enum { + CELL_EDITABLE_DUMMY_DUMMY_PROPERTY, + CELL_EDITABLE_DUMMY_EDITING_CANCELED +}; +void cell_editable_dummy_start_editing (CellEditableDummy* self, GdkEvent* event); +static void cell_editable_dummy_real_start_editing (CellEditableDummy* self, GdkEvent* event); +gboolean cell_editable_dummy_get_editing_canceled (CellEditableDummy* self); +void cell_editable_dummy_set_editing_canceled (CellEditableDummy* self, gboolean value); +static void cell_editable_dummy_finalize (GObject* obj); +static void _vala_cell_editable_dummy_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec); +static void _vala_cell_editable_dummy_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec); +#define CELL_EDITABLE_ACCEL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_CELL_EDITABLE_ACCEL, CellEditableAccelPrivate)) +enum { + CELL_EDITABLE_ACCEL_DUMMY_PROPERTY, + CELL_EDITABLE_ACCEL_EDITING_CANCELED +}; +static void cell_editable_accel_on_editing_done (CellEditableAccel* self); +static void _cell_editable_accel_on_editing_done_gtk_cell_editable_editing_done (GtkCellEditable* _sender, gpointer self); +void cell_editable_accel_start_editing (CellEditableAccel* self, GdkEvent* event); +static void cell_editable_accel_real_start_editing (CellEditableAccel* self, GdkEvent* event); +static gboolean cell_editable_accel_on_key (CellEditableAccel* self, GdkEventKey* event); +static gboolean _cell_editable_accel_on_key_gtk_widget_key_press_event (GtkWidget* _sender, GdkEventKey* event, gpointer self); +gboolean cell_editable_accel_get_editing_canceled (CellEditableAccel* self); +void cell_editable_accel_set_editing_canceled (CellEditableAccel* self, gboolean value); +static void cell_editable_accel_finalize (GObject* obj); +static void _vala_cell_editable_accel_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec); +static void _vala_cell_editable_accel_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec); +#define CELL_EDITABLE_COMBO_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_CELL_EDITABLE_COMBO, CellEditableComboPrivate)) +enum { + CELL_EDITABLE_COMBO_DUMMY_PROPERTY +}; +static Block1Data* block1_data_ref (Block1Data* _data1_); +static void block1_data_unref (void * _userdata_); +static void __lambda2_ (Block1Data* _data1_); +static void ___lambda2__gtk_combo_box_changed (GtkComboBox* _sender, gpointer self); +static void cell_editable_combo_finalize (GObject* obj); +static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func); + + +GType cell_renderer_textish_mode_get_type (void) { + static volatile gsize cell_renderer_textish_mode_type_id__volatile = 0; + if (g_once_init_enter (&cell_renderer_textish_mode_type_id__volatile)) { + static const GEnumValue values[] = {{CELL_RENDERER_TEXTISH_MODE_Text, "CELL_RENDERER_TEXTISH_MODE_Text", "text"}, {CELL_RENDERER_TEXTISH_MODE_Key, "CELL_RENDERER_TEXTISH_MODE_Key", "key"}, {CELL_RENDERER_TEXTISH_MODE_Popup, "CELL_RENDERER_TEXTISH_MODE_Popup", "popup"}, {CELL_RENDERER_TEXTISH_MODE_Combo, "CELL_RENDERER_TEXTISH_MODE_Combo", "combo"}, {0, NULL, NULL}}; + GType cell_renderer_textish_mode_type_id; + cell_renderer_textish_mode_type_id = g_enum_register_static ("CellRendererTextishMode", values); + g_once_init_leave (&cell_renderer_textish_mode_type_id__volatile, cell_renderer_textish_mode_type_id); + } + return cell_renderer_textish_mode_type_id__volatile; +} + + +CellRendererTextish* cell_renderer_textish_construct (GType object_type) { + CellRendererTextish * self = NULL; + self = (CellRendererTextish*) g_object_new (object_type, NULL); + self->mode = CELL_RENDERER_TEXTISH_MODE_Text; + _g_object_unref0 (self->priv->cell); + self->priv->cell = NULL; + self->items = (_vala_array_free (self->items, self->items_length1, (GDestroyNotify) g_free), NULL); + self->items = NULL; + self->items_length1 = 0; + return self; +} + + +CellRendererTextish* cell_renderer_textish_new (void) { + return cell_renderer_textish_construct (TYPE_CELL_RENDERER_TEXTISH); +} + + +static gchar** _vala_array_dup1 (gchar** self, int length) { + gchar** result; + int i; + result = g_new0 (gchar*, length + 1); + for (i = 0; i < length; i++) { + gchar* _tmp0_; + _tmp0_ = g_strdup (self[i]); + result[i] = _tmp0_; + } + return result; +} + + +CellRendererTextish* cell_renderer_textish_construct_with_items (GType object_type, gchar** items, int items_length1) { + CellRendererTextish * self = NULL; + gchar** _tmp0_; + gint _tmp0__length1; + gchar** _tmp1_; + gint _tmp1__length1; + self = (CellRendererTextish*) g_object_new (object_type, NULL); + self->mode = CELL_RENDERER_TEXTISH_MODE_Text; + _g_object_unref0 (self->priv->cell); + self->priv->cell = NULL; + _tmp0_ = items; + _tmp0__length1 = items_length1; + _tmp1_ = (_tmp0_ != NULL) ? _vala_array_dup1 (_tmp0_, _tmp0__length1) : ((gpointer) _tmp0_); + _tmp1__length1 = _tmp0__length1; + self->items = (_vala_array_free (self->items, self->items_length1, (GDestroyNotify) g_free), NULL); + self->items = _tmp1_; + self->items_length1 = _tmp1__length1; + return self; +} + + +CellRendererTextish* cell_renderer_textish_new_with_items (gchar** items, int items_length1) { + return cell_renderer_textish_construct_with_items (TYPE_CELL_RENDERER_TEXTISH, items, items_length1); +} + + +static gpointer _g_object_ref0 (gpointer self) { + return self ? g_object_ref (self) : NULL; +} + + +static GtkCellEditable* cell_renderer_textish_real_start_editing (GtkCellRenderer* base, GdkEvent* event, GtkWidget* widget, const gchar* path, GdkRectangle* background_area, GdkRectangle* cell_area, GtkCellRendererState flags) { + CellRendererTextish * self; + GtkCellEditable* result = NULL; + gboolean _tmp0_ = FALSE; + gboolean _tmp1_; + CellRendererTextishMode _tmp3_; + GtkCellEditable* _tmp20_; + self = (CellRendererTextish*) base; + g_return_val_if_fail (widget != NULL, NULL); + g_return_val_if_fail (path != NULL, NULL); + g_return_val_if_fail (background_area != NULL, NULL); + g_return_val_if_fail (cell_area != NULL, NULL); + _g_object_unref0 (self->priv->cell); + self->priv->cell = NULL; + g_object_get ((GtkCellRendererText*) self, "editable", &_tmp0_, NULL); + _tmp1_ = _tmp0_; + if (!_tmp1_) { + GtkCellEditable* _tmp2_; + _tmp2_ = self->priv->cell; + result = _tmp2_; + return result; + } + _tmp3_ = self->mode; + switch (_tmp3_) { + case CELL_RENDERER_TEXTISH_MODE_Text: + { + GdkEvent* _tmp4_; + GtkWidget* _tmp5_; + const gchar* _tmp6_; + GdkRectangle _tmp7_; + GdkRectangle _tmp8_; + GtkCellRendererState _tmp9_; + GtkCellEditable* _tmp10_ = NULL; + GtkCellEditable* _tmp11_; + _tmp4_ = event; + _tmp5_ = widget; + _tmp6_ = path; + _tmp7_ = *background_area; + _tmp8_ = *cell_area; + _tmp9_ = flags; + _tmp10_ = GTK_CELL_RENDERER_CLASS (cell_renderer_textish_parent_class)->start_editing ((GtkCellRenderer*) G_TYPE_CHECK_INSTANCE_CAST (self, GTK_TYPE_CELL_RENDERER_TEXT, GtkCellRendererText), _tmp4_, _tmp5_, _tmp6_, &_tmp7_, &_tmp8_, _tmp9_); + _tmp11_ = _g_object_ref0 (_tmp10_); + _g_object_unref0 (self->priv->cell); + self->priv->cell = _tmp11_; + break; + } + case CELL_RENDERER_TEXTISH_MODE_Key: + { + const gchar* _tmp12_; + GtkWidget* _tmp13_; + CellEditableAccel* _tmp14_; + _tmp12_ = path; + _tmp13_ = widget; + _tmp14_ = cell_editable_accel_new (self, _tmp12_, _tmp13_); + g_object_ref_sink (_tmp14_); + _g_object_unref0 (self->priv->cell); + self->priv->cell = (GtkCellEditable*) _tmp14_; + break; + } + case CELL_RENDERER_TEXTISH_MODE_Combo: + { + const gchar* _tmp15_; + GtkWidget* _tmp16_; + gchar** _tmp17_; + gint _tmp17__length1; + CellEditableCombo* _tmp18_; + _tmp15_ = path; + _tmp16_ = widget; + _tmp17_ = self->items; + _tmp17__length1 = self->items_length1; + _tmp18_ = cell_editable_combo_new (self, _tmp15_, _tmp16_, _tmp17_, _tmp17__length1); + g_object_ref_sink (_tmp18_); + _g_object_unref0 (self->priv->cell); + self->priv->cell = (GtkCellEditable*) _tmp18_; + break; + } + case CELL_RENDERER_TEXTISH_MODE_Popup: + { + CellEditableDummy* _tmp19_; + _tmp19_ = cell_editable_dummy_new (); + g_object_ref_sink (_tmp19_); + _g_object_unref0 (self->priv->cell); + self->priv->cell = (GtkCellEditable*) _tmp19_; + break; + } + default: + break; + } + _tmp20_ = self->priv->cell; + result = _tmp20_; + return result; +} + + +static void g_cclosure_user_marshal_VOID__STRING_FLAGS_UINT (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data) { + typedef void (*GMarshalFunc_VOID__STRING_FLAGS_UINT) (gpointer data1, const char* arg_1, gint arg_2, guint arg_3, gpointer data2); + register GMarshalFunc_VOID__STRING_FLAGS_UINT callback; + register GCClosure * cc; + register gpointer data1; + register gpointer data2; + cc = (GCClosure *) closure; + g_return_if_fail (n_param_values == 4); + if (G_CCLOSURE_SWAP_DATA (closure)) { + data1 = closure->data; + data2 = param_values->data[0].v_pointer; + } else { + data1 = param_values->data[0].v_pointer; + data2 = closure->data; + } + callback = (GMarshalFunc_VOID__STRING_FLAGS_UINT) (marshal_data ? marshal_data : cc->callback); + callback (data1, g_value_get_string (param_values + 1), g_value_get_flags (param_values + 2), g_value_get_uint (param_values + 3), data2); +} + + +static void g_cclosure_user_marshal_VOID__STRING_UINT (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data) { + typedef void (*GMarshalFunc_VOID__STRING_UINT) (gpointer data1, const char* arg_1, guint arg_2, gpointer data2); + register GMarshalFunc_VOID__STRING_UINT callback; + register GCClosure * cc; + register gpointer data1; + register gpointer data2; + cc = (GCClosure *) closure; + g_return_if_fail (n_param_values == 3); + if (G_CCLOSURE_SWAP_DATA (closure)) { + data1 = closure->data; + data2 = param_values->data[0].v_pointer; + } else { + data1 = param_values->data[0].v_pointer; + data2 = closure->data; + } + callback = (GMarshalFunc_VOID__STRING_UINT) (marshal_data ? marshal_data : cc->callback); + callback (data1, g_value_get_string (param_values + 1), g_value_get_uint (param_values + 2), data2); +} + + +static void cell_renderer_textish_class_init (CellRendererTextishClass * klass) { + cell_renderer_textish_parent_class = g_type_class_peek_parent (klass); + g_type_class_add_private (klass, sizeof (CellRendererTextishPrivate)); + GTK_CELL_RENDERER_CLASS (klass)->start_editing = cell_renderer_textish_real_start_editing; + G_OBJECT_CLASS (klass)->finalize = cell_renderer_textish_finalize; + g_signal_new ("key_edited", TYPE_CELL_RENDERER_TEXTISH, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__STRING_FLAGS_UINT, G_TYPE_NONE, 3, G_TYPE_STRING, gdk_modifier_type_get_type (), G_TYPE_UINT); + g_signal_new ("combo_edited", TYPE_CELL_RENDERER_TEXTISH, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__STRING_UINT, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_UINT); +} + + +static void cell_renderer_textish_instance_init (CellRendererTextish * self) { + self->priv = CELL_RENDERER_TEXTISH_GET_PRIVATE (self); +} + + +static void cell_renderer_textish_finalize (GObject* obj) { + CellRendererTextish * self; + self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_CELL_RENDERER_TEXTISH, CellRendererTextish); + self->items = (_vala_array_free (self->items, self->items_length1, (GDestroyNotify) g_free), NULL); + _g_object_unref0 (self->priv->cell); + G_OBJECT_CLASS (cell_renderer_textish_parent_class)->finalize (obj); +} + + +GType cell_renderer_textish_get_type (void) { + static volatile gsize cell_renderer_textish_type_id__volatile = 0; + if (g_once_init_enter (&cell_renderer_textish_type_id__volatile)) { + static const GTypeInfo g_define_type_info = { sizeof (CellRendererTextishClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) cell_renderer_textish_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (CellRendererTextish), 0, (GInstanceInitFunc) cell_renderer_textish_instance_init, NULL }; + GType cell_renderer_textish_type_id; + cell_renderer_textish_type_id = g_type_register_static (GTK_TYPE_CELL_RENDERER_TEXT, "CellRendererTextish", &g_define_type_info, 0); + g_once_init_leave (&cell_renderer_textish_type_id__volatile, cell_renderer_textish_type_id); + } + return cell_renderer_textish_type_id__volatile; +} + + +static void cell_editable_dummy_real_start_editing (CellEditableDummy* self, GdkEvent* event) { + gtk_cell_editable_editing_done ((GtkCellEditable*) self); + gtk_cell_editable_remove_widget ((GtkCellEditable*) self); +} + + +void cell_editable_dummy_start_editing (CellEditableDummy* self, GdkEvent* event) { + g_return_if_fail (self != NULL); + CELL_EDITABLE_DUMMY_GET_CLASS (self)->start_editing (self, event); +} + + +CellEditableDummy* cell_editable_dummy_construct (GType object_type) { + CellEditableDummy * self = NULL; + self = (CellEditableDummy*) g_object_new (object_type, NULL); + return self; +} + + +CellEditableDummy* cell_editable_dummy_new (void) { + return cell_editable_dummy_construct (TYPE_CELL_EDITABLE_DUMMY); +} + + +gboolean cell_editable_dummy_get_editing_canceled (CellEditableDummy* self) { + gboolean result; + gboolean _tmp0_; + g_return_val_if_fail (self != NULL, FALSE); + _tmp0_ = self->priv->_editing_canceled; + result = _tmp0_; + return result; +} + + +void cell_editable_dummy_set_editing_canceled (CellEditableDummy* self, gboolean value) { + gboolean _tmp0_; + g_return_if_fail (self != NULL); + _tmp0_ = value; + self->priv->_editing_canceled = _tmp0_; + g_object_notify ((GObject *) self, "editing-canceled"); +} + + +static void cell_editable_dummy_class_init (CellEditableDummyClass * klass) { + cell_editable_dummy_parent_class = g_type_class_peek_parent (klass); + g_type_class_add_private (klass, sizeof (CellEditableDummyPrivate)); + CELL_EDITABLE_DUMMY_CLASS (klass)->start_editing = cell_editable_dummy_real_start_editing; + G_OBJECT_CLASS (klass)->get_property = _vala_cell_editable_dummy_get_property; + G_OBJECT_CLASS (klass)->set_property = _vala_cell_editable_dummy_set_property; + G_OBJECT_CLASS (klass)->finalize = cell_editable_dummy_finalize; + g_object_class_install_property (G_OBJECT_CLASS (klass), CELL_EDITABLE_DUMMY_EDITING_CANCELED, g_param_spec_boolean ("editing-canceled", "editing-canceled", "editing-canceled", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE)); +} + + +static void cell_editable_dummy_gtk_cell_editable_interface_init (GtkCellEditableIface * iface) { + cell_editable_dummy_gtk_cell_editable_parent_iface = g_type_interface_peek_parent (iface); + iface->start_editing = (void (*)(GtkCellEditable*, GdkEvent*)) cell_editable_dummy_start_editing; +} + + +static void cell_editable_dummy_instance_init (CellEditableDummy * self) { + self->priv = CELL_EDITABLE_DUMMY_GET_PRIVATE (self); +} + + +static void cell_editable_dummy_finalize (GObject* obj) { + CellEditableDummy * self; + self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_CELL_EDITABLE_DUMMY, CellEditableDummy); + G_OBJECT_CLASS (cell_editable_dummy_parent_class)->finalize (obj); +} + + +GType cell_editable_dummy_get_type (void) { + static volatile gsize cell_editable_dummy_type_id__volatile = 0; + if (g_once_init_enter (&cell_editable_dummy_type_id__volatile)) { + static const GTypeInfo g_define_type_info = { sizeof (CellEditableDummyClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) cell_editable_dummy_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (CellEditableDummy), 0, (GInstanceInitFunc) cell_editable_dummy_instance_init, NULL }; + static const GInterfaceInfo gtk_cell_editable_info = { (GInterfaceInitFunc) cell_editable_dummy_gtk_cell_editable_interface_init, (GInterfaceFinalizeFunc) NULL, NULL}; + GType cell_editable_dummy_type_id; + cell_editable_dummy_type_id = g_type_register_static (GTK_TYPE_EVENT_BOX, "CellEditableDummy", &g_define_type_info, 0); + g_type_add_interface_static (cell_editable_dummy_type_id, GTK_TYPE_CELL_EDITABLE, >k_cell_editable_info); + g_once_init_leave (&cell_editable_dummy_type_id__volatile, cell_editable_dummy_type_id); + } + return cell_editable_dummy_type_id__volatile; +} + + +static void _vala_cell_editable_dummy_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) { + CellEditableDummy * self; + self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_CELL_EDITABLE_DUMMY, CellEditableDummy); + switch (property_id) { + case CELL_EDITABLE_DUMMY_EDITING_CANCELED: + g_value_set_boolean (value, cell_editable_dummy_get_editing_canceled (self)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +static void _vala_cell_editable_dummy_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) { + CellEditableDummy * self; + self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_CELL_EDITABLE_DUMMY, CellEditableDummy); + switch (property_id) { + case CELL_EDITABLE_DUMMY_EDITING_CANCELED: + cell_editable_dummy_set_editing_canceled (self, g_value_get_boolean (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +static void _cell_editable_accel_on_editing_done_gtk_cell_editable_editing_done (GtkCellEditable* _sender, gpointer self) { + cell_editable_accel_on_editing_done (self); +} + + +CellEditableAccel* cell_editable_accel_construct (GType object_type, CellRendererTextish* parent, const gchar* path, GtkWidget* widget) { + CellEditableAccel * self = NULL; + CellRendererTextish* _tmp0_; + CellRendererTextish* _tmp1_; + const gchar* _tmp2_; + gchar* _tmp3_; + const gchar* _tmp4_ = NULL; + GtkLabel* _tmp5_; + GtkLabel* label; + GtkWidget* _tmp6_; + GtkStyleContext* _tmp7_ = NULL; + GdkRGBA _tmp8_ = {0}; + GtkWidget* _tmp9_; + GtkStyleContext* _tmp10_ = NULL; + GdkRGBA _tmp11_ = {0}; + g_return_val_if_fail (parent != NULL, NULL); + g_return_val_if_fail (path != NULL, NULL); + g_return_val_if_fail (widget != NULL, NULL); + self = (CellEditableAccel*) g_object_new (object_type, NULL); + _tmp0_ = parent; + _tmp1_ = _g_object_ref0 (_tmp0_); + _g_object_unref0 (self->priv->parent); + self->priv->parent = _tmp1_; + _tmp2_ = path; + _tmp3_ = g_strdup (_tmp2_); + _g_free0 (self->priv->path); + self->priv->path = _tmp3_; + g_signal_connect_object ((GtkCellEditable*) self, "editing-done", (GCallback) _cell_editable_accel_on_editing_done_gtk_cell_editable_editing_done, self, 0); + _tmp4_ = _ ("Key combination..."); + _tmp5_ = (GtkLabel*) gtk_label_new (_tmp4_); + g_object_ref_sink (_tmp5_); + label = _tmp5_; + gtk_misc_set_alignment ((GtkMisc*) label, 0.0f, 0.5f); + gtk_container_add ((GtkContainer*) self, (GtkWidget*) label); + _tmp6_ = widget; + _tmp7_ = gtk_widget_get_style_context (_tmp6_); + gtk_style_context_get_background_color (_tmp7_, GTK_STATE_FLAG_SELECTED, &_tmp8_); + gtk_widget_override_background_color ((GtkWidget*) self, GTK_STATE_FLAG_NORMAL, &_tmp8_); + _tmp9_ = widget; + _tmp10_ = gtk_widget_get_style_context (_tmp9_); + gtk_style_context_get_color (_tmp10_, GTK_STATE_FLAG_SELECTED, &_tmp11_); + gtk_widget_override_color ((GtkWidget*) label, GTK_STATE_FLAG_NORMAL, &_tmp11_); + gtk_widget_show_all ((GtkWidget*) self); + _g_object_unref0 (label); + return self; +} + + +CellEditableAccel* cell_editable_accel_new (CellRendererTextish* parent, const gchar* path, GtkWidget* widget) { + return cell_editable_accel_construct (TYPE_CELL_EDITABLE_ACCEL, parent, path, widget); +} + + +static gboolean _cell_editable_accel_on_key_gtk_widget_key_press_event (GtkWidget* _sender, GdkEventKey* event, gpointer self) { + gboolean result; + result = cell_editable_accel_on_key (self, event); + return result; +} + + +static void cell_editable_accel_real_start_editing (CellEditableAccel* self, GdkEvent* event) { + guint32 _tmp0_ = 0U; + GdkEvent* _tmp1_; + GdkWindow* _tmp4_ = NULL; + guint32 _tmp5_; + gtk_grab_add ((GtkWidget*) self); + _tmp1_ = event; + if (_tmp1_ != NULL) { + GdkEvent* _tmp2_; + guint32 _tmp3_ = 0U; + _tmp2_ = event; + _tmp3_ = gdk_event_get_time (_tmp2_); + _tmp0_ = _tmp3_; + } else { + _tmp0_ = (guint32) GDK_CURRENT_TIME; + } + _tmp4_ = gtk_widget_get_window ((GtkWidget*) self); + _tmp5_ = _tmp0_; + gdk_keyboard_grab (_tmp4_, FALSE, _tmp5_); + g_signal_connect_object ((GtkWidget*) self, "key-press-event", (GCallback) _cell_editable_accel_on_key_gtk_widget_key_press_event, self, 0); +} + + +void cell_editable_accel_start_editing (CellEditableAccel* self, GdkEvent* event) { + g_return_if_fail (self != NULL); + CELL_EDITABLE_ACCEL_GET_CLASS (self)->start_editing (self, event); +} + + +static gboolean cell_editable_accel_on_key (CellEditableAccel* self, GdkEventKey* event) { + gboolean result = FALSE; + GdkEventKey _tmp0_; + guint _tmp1_; + GdkEventKey _tmp2_; + guint _tmp3_; + GdkEventKey _tmp4_; + GdkModifierType _tmp5_; + GdkModifierType _tmp6_ = 0; + GdkModifierType mods; + CellRendererTextish* _tmp7_; + const gchar* _tmp8_; + GdkModifierType _tmp9_; + GdkEventKey _tmp10_; + guint16 _tmp11_; + g_return_val_if_fail (self != NULL, FALSE); + g_return_val_if_fail (event != NULL, FALSE); + _tmp0_ = *event; + _tmp1_ = _tmp0_.is_modifier; + if (_tmp1_ != ((guint) 0)) { + result = TRUE; + return result; + } + _tmp2_ = *event; + _tmp3_ = _tmp2_.keyval; + switch (_tmp3_) { + case GDK_KEY_Super_L: + case GDK_KEY_Super_R: + case GDK_KEY_Hyper_L: + case GDK_KEY_Hyper_R: + { + result = TRUE; + return result; + } + default: + break; + } + _tmp4_ = *event; + _tmp5_ = _tmp4_.state; + _tmp6_ = gtk_accelerator_get_default_mod_mask (); + mods = _tmp5_ & _tmp6_; + gtk_cell_editable_editing_done ((GtkCellEditable*) self); + gtk_cell_editable_remove_widget ((GtkCellEditable*) self); + _tmp7_ = self->priv->parent; + _tmp8_ = self->priv->path; + _tmp9_ = mods; + _tmp10_ = *event; + _tmp11_ = _tmp10_.hardware_keycode; + g_signal_emit_by_name (_tmp7_, "key-edited", _tmp8_, _tmp9_, (guint) _tmp11_); + result = TRUE; + return result; +} + + +static void cell_editable_accel_on_editing_done (CellEditableAccel* self) { + g_return_if_fail (self != NULL); + gtk_grab_remove ((GtkWidget*) self); + gdk_keyboard_ungrab ((guint32) GDK_CURRENT_TIME); +} + + +gboolean cell_editable_accel_get_editing_canceled (CellEditableAccel* self) { + gboolean result; + gboolean _tmp0_; + g_return_val_if_fail (self != NULL, FALSE); + _tmp0_ = self->priv->_editing_canceled; + result = _tmp0_; + return result; +} + + +void cell_editable_accel_set_editing_canceled (CellEditableAccel* self, gboolean value) { + gboolean _tmp0_; + g_return_if_fail (self != NULL); + _tmp0_ = value; + self->priv->_editing_canceled = _tmp0_; + g_object_notify ((GObject *) self, "editing-canceled"); +} + + +static void cell_editable_accel_class_init (CellEditableAccelClass * klass) { + cell_editable_accel_parent_class = g_type_class_peek_parent (klass); + g_type_class_add_private (klass, sizeof (CellEditableAccelPrivate)); + CELL_EDITABLE_ACCEL_CLASS (klass)->start_editing = cell_editable_accel_real_start_editing; + G_OBJECT_CLASS (klass)->get_property = _vala_cell_editable_accel_get_property; + G_OBJECT_CLASS (klass)->set_property = _vala_cell_editable_accel_set_property; + G_OBJECT_CLASS (klass)->finalize = cell_editable_accel_finalize; + g_object_class_install_property (G_OBJECT_CLASS (klass), CELL_EDITABLE_ACCEL_EDITING_CANCELED, g_param_spec_boolean ("editing-canceled", "editing-canceled", "editing-canceled", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE)); +} + + +static void cell_editable_accel_gtk_cell_editable_interface_init (GtkCellEditableIface * iface) { + cell_editable_accel_gtk_cell_editable_parent_iface = g_type_interface_peek_parent (iface); + iface->start_editing = (void (*)(GtkCellEditable*, GdkEvent*)) cell_editable_accel_start_editing; +} + + +static void cell_editable_accel_instance_init (CellEditableAccel * self) { + self->priv = CELL_EDITABLE_ACCEL_GET_PRIVATE (self); +} + + +static void cell_editable_accel_finalize (GObject* obj) { + CellEditableAccel * self; + self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_CELL_EDITABLE_ACCEL, CellEditableAccel); + _g_object_unref0 (self->priv->parent); + _g_free0 (self->priv->path); + G_OBJECT_CLASS (cell_editable_accel_parent_class)->finalize (obj); +} + + +GType cell_editable_accel_get_type (void) { + static volatile gsize cell_editable_accel_type_id__volatile = 0; + if (g_once_init_enter (&cell_editable_accel_type_id__volatile)) { + static const GTypeInfo g_define_type_info = { sizeof (CellEditableAccelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) cell_editable_accel_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (CellEditableAccel), 0, (GInstanceInitFunc) cell_editable_accel_instance_init, NULL }; + static const GInterfaceInfo gtk_cell_editable_info = { (GInterfaceInitFunc) cell_editable_accel_gtk_cell_editable_interface_init, (GInterfaceFinalizeFunc) NULL, NULL}; + GType cell_editable_accel_type_id; + cell_editable_accel_type_id = g_type_register_static (GTK_TYPE_EVENT_BOX, "CellEditableAccel", &g_define_type_info, 0); + g_type_add_interface_static (cell_editable_accel_type_id, GTK_TYPE_CELL_EDITABLE, >k_cell_editable_info); + g_once_init_leave (&cell_editable_accel_type_id__volatile, cell_editable_accel_type_id); + } + return cell_editable_accel_type_id__volatile; +} + + +static void _vala_cell_editable_accel_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) { + CellEditableAccel * self; + self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_CELL_EDITABLE_ACCEL, CellEditableAccel); + switch (property_id) { + case CELL_EDITABLE_ACCEL_EDITING_CANCELED: + g_value_set_boolean (value, cell_editable_accel_get_editing_canceled (self)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +static void _vala_cell_editable_accel_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) { + CellEditableAccel * self; + self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_CELL_EDITABLE_ACCEL, CellEditableAccel); + switch (property_id) { + case CELL_EDITABLE_ACCEL_EDITING_CANCELED: + cell_editable_accel_set_editing_canceled (self, g_value_get_boolean (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +static Block1Data* block1_data_ref (Block1Data* _data1_) { + g_atomic_int_inc (&_data1_->_ref_count_); + return _data1_; +} + + +static void block1_data_unref (void * _userdata_) { + Block1Data* _data1_; + _data1_ = (Block1Data*) _userdata_; + if (g_atomic_int_dec_and_test (&_data1_->_ref_count_)) { + CellEditableCombo * self; + self = _data1_->self; + _g_object_unref0 (_data1_->parent); + _g_free0 (_data1_->path); + _g_object_unref0 (self); + g_slice_free (Block1Data, _data1_); + } +} + + +static void __lambda2_ (Block1Data* _data1_) { + CellEditableCombo * self; + CellRendererTextish* _tmp0_; + const gchar* _tmp1_; + gint _tmp2_; + gint _tmp3_; + self = _data1_->self; + _tmp0_ = _data1_->parent; + _tmp1_ = _data1_->path; + _tmp2_ = gtk_combo_box_get_active ((GtkComboBox*) self); + _tmp3_ = _tmp2_; + g_signal_emit_by_name (_tmp0_, "combo-edited", _tmp1_, (guint) _tmp3_); +} + + +static void ___lambda2__gtk_combo_box_changed (GtkComboBox* _sender, gpointer self) { + __lambda2_ (self); +} + + +CellEditableCombo* cell_editable_combo_construct (GType object_type, CellRendererTextish* parent, const gchar* path, GtkWidget* widget, gchar** items, int items_length1) { + CellEditableCombo * self = NULL; + Block1Data* _data1_; + CellRendererTextish* _tmp0_; + CellRendererTextish* _tmp1_; + const gchar* _tmp2_; + gchar* _tmp3_; + CellRendererTextish* _tmp4_; + CellRendererTextish* _tmp5_; + const gchar* _tmp6_; + gchar* _tmp7_; + gchar** _tmp8_; + gint _tmp8__length1; + g_return_val_if_fail (parent != NULL, NULL); + g_return_val_if_fail (path != NULL, NULL); + g_return_val_if_fail (widget != NULL, NULL); + _data1_ = g_slice_new0 (Block1Data); + _data1_->_ref_count_ = 1; + _tmp0_ = parent; + _tmp1_ = _g_object_ref0 (_tmp0_); + _g_object_unref0 (_data1_->parent); + _data1_->parent = _tmp1_; + _tmp2_ = path; + _tmp3_ = g_strdup (_tmp2_); + _g_free0 (_data1_->path); + _data1_->path = _tmp3_; + self = (CellEditableCombo*) g_object_new (object_type, NULL); + _data1_->self = g_object_ref (self); + _tmp4_ = _data1_->parent; + _tmp5_ = _g_object_ref0 (_tmp4_); + _g_object_unref0 (self->priv->parent); + self->priv->parent = _tmp5_; + _tmp6_ = _data1_->path; + _tmp7_ = g_strdup (_tmp6_); + _g_free0 (self->priv->path); + self->priv->path = _tmp7_; + _tmp8_ = items; + _tmp8__length1 = items_length1; + { + gchar** item_collection = NULL; + gint item_collection_length1 = 0; + gint _item_collection_size_ = 0; + gint item_it = 0; + item_collection = _tmp8_; + item_collection_length1 = _tmp8__length1; + for (item_it = 0; item_it < _tmp8__length1; item_it = item_it + 1) { + gchar* _tmp9_; + gchar* item = NULL; + _tmp9_ = g_strdup (item_collection[item_it]); + item = _tmp9_; + { + const gchar* _tmp10_; + const gchar* _tmp11_ = NULL; + _tmp10_ = item; + _tmp11_ = _ (_tmp10_); + gtk_combo_box_text_append_text ((GtkComboBoxText*) self, _tmp11_); + _g_free0 (item); + } + } + } + g_signal_connect_data ((GtkComboBox*) self, "changed", (GCallback) ___lambda2__gtk_combo_box_changed, block1_data_ref (_data1_), (GClosureNotify) block1_data_unref, 0); + block1_data_unref (_data1_); + _data1_ = NULL; + return self; +} + + +CellEditableCombo* cell_editable_combo_new (CellRendererTextish* parent, const gchar* path, GtkWidget* widget, gchar** items, int items_length1) { + return cell_editable_combo_construct (TYPE_CELL_EDITABLE_COMBO, parent, path, widget, items, items_length1); +} + + +static void cell_editable_combo_class_init (CellEditableComboClass * klass) { + cell_editable_combo_parent_class = g_type_class_peek_parent (klass); + g_type_class_add_private (klass, sizeof (CellEditableComboPrivate)); + G_OBJECT_CLASS (klass)->finalize = cell_editable_combo_finalize; +} + + +static void cell_editable_combo_instance_init (CellEditableCombo * self) { + self->priv = CELL_EDITABLE_COMBO_GET_PRIVATE (self); +} + + +static void cell_editable_combo_finalize (GObject* obj) { + CellEditableCombo * self; + self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_CELL_EDITABLE_COMBO, CellEditableCombo); + _g_object_unref0 (self->priv->parent); + _g_free0 (self->priv->path); + G_OBJECT_CLASS (cell_editable_combo_parent_class)->finalize (obj); +} + + +GType cell_editable_combo_get_type (void) { + static volatile gsize cell_editable_combo_type_id__volatile = 0; + if (g_once_init_enter (&cell_editable_combo_type_id__volatile)) { + static const GTypeInfo g_define_type_info = { sizeof (CellEditableComboClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) cell_editable_combo_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (CellEditableCombo), 0, (GInstanceInitFunc) cell_editable_combo_instance_init, NULL }; + GType cell_editable_combo_type_id; + cell_editable_combo_type_id = g_type_register_static (GTK_TYPE_COMBO_BOX_TEXT, "CellEditableCombo", &g_define_type_info, 0); + g_once_init_leave (&cell_editable_combo_type_id__volatile, cell_editable_combo_type_id); + } + return cell_editable_combo_type_id__volatile; +} + + +static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) { + if ((array != NULL) && (destroy_func != NULL)) { + int i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + + +static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) { + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + + + diff --git a/cellrenderertextish.h b/cellrenderertextish.h new file mode 100644 index 00000000..a9d217d0 --- /dev/null +++ b/cellrenderertextish.h @@ -0,0 +1,58 @@ +/* cellrenderertextish.h generated by valac 0.18.1, the Vala compiler, do not modify */ + + +#ifndef __CELLRENDERERTEXTISH_H__ +#define __CELLRENDERERTEXTISH_H__ + +#include +#include +#include +#include + +G_BEGIN_DECLS + + +#define TYPE_CELL_RENDERER_TEXTISH (cell_renderer_textish_get_type ()) +#define CELL_RENDERER_TEXTISH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CELL_RENDERER_TEXTISH, CellRendererTextish)) +#define CELL_RENDERER_TEXTISH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CELL_RENDERER_TEXTISH, CellRendererTextishClass)) +#define IS_CELL_RENDERER_TEXTISH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CELL_RENDERER_TEXTISH)) +#define IS_CELL_RENDERER_TEXTISH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CELL_RENDERER_TEXTISH)) +#define CELL_RENDERER_TEXTISH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CELL_RENDERER_TEXTISH, CellRendererTextishClass)) + +typedef struct _CellRendererTextish CellRendererTextish; +typedef struct _CellRendererTextishClass CellRendererTextishClass; +typedef struct _CellRendererTextishPrivate CellRendererTextishPrivate; + +#define CELL_RENDERER_TEXTISH_TYPE_MODE (cell_renderer_textish_mode_get_type ()) + +typedef enum { + CELL_RENDERER_TEXTISH_MODE_Text, + CELL_RENDERER_TEXTISH_MODE_Key, + CELL_RENDERER_TEXTISH_MODE_Popup, + CELL_RENDERER_TEXTISH_MODE_Combo +} CellRendererTextishMode; + +struct _CellRendererTextish { + GtkCellRendererText parent_instance; + CellRendererTextishPrivate * priv; + CellRendererTextishMode mode; + gchar** items; + gint items_length1; +}; + +struct _CellRendererTextishClass { + GtkCellRendererTextClass parent_class; +}; + + +GType cell_renderer_textish_get_type (void) G_GNUC_CONST; +GType cell_renderer_textish_mode_get_type (void) G_GNUC_CONST; +CellRendererTextish* cell_renderer_textish_new (void); +CellRendererTextish* cell_renderer_textish_construct (GType object_type); +CellRendererTextish* cell_renderer_textish_new_with_items (gchar** items, int items_length1); +CellRendererTextish* cell_renderer_textish_construct_with_items (GType object_type, gchar** items, int items_length1); + + +G_END_DECLS + +#endif diff --git a/cellrenderertextish.vala b/cellrenderertextish.vala new file mode 100644 index 00000000..b6aade9a --- /dev/null +++ b/cellrenderertextish.vala @@ -0,0 +1,127 @@ +/* compile with valac -c cellrenderertextish.vala --pkg gtk+-3.0 -C -H cellrenderertextish.h */ + +public class CellRendererTextish : Gtk.CellRendererText { + public enum Mode { Text, Key, Popup, Combo } + public new Mode mode; + public string[] items; + + public signal void key_edited(string path, Gdk.ModifierType mods, uint code); + public signal void combo_edited(string path, uint row); + + private Gtk.CellEditable? cell; + + public CellRendererTextish() { + mode = Mode.Text; + cell = null; + items = null; + } + + public CellRendererTextish.with_items(string[] items) { + mode = Mode.Text; + cell = null; + this.items = items; + } + + public override unowned Gtk.CellEditable start_editing (Gdk.Event? event, Gtk.Widget widget, string path, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, Gtk.CellRendererState flags) { + cell = null; + if (!editable) + return cell; + switch (mode) { + case Mode.Text: + cell = base.start_editing(event, widget, path, background_area, cell_area, flags); + break; + case Mode.Key: + cell = new CellEditableAccel(this, path, widget); + break; + case Mode.Combo: + cell = new CellEditableCombo(this, path, widget, items); + break; + case Mode.Popup: + cell = new CellEditableDummy(); + break; + } + return cell; + } +} + +class CellEditableDummy : Gtk.EventBox, Gtk.CellEditable { + public bool editing_canceled { get; set; } + protected virtual void start_editing(Gdk.Event? event) { + editing_done(); + remove_widget(); + } +} + +class CellEditableAccel : Gtk.EventBox, Gtk.CellEditable { + public bool editing_canceled { get; set; } + new CellRendererTextish parent; + new string path; + + public CellEditableAccel(CellRendererTextish parent, string path, Gtk.Widget widget) { + this.parent = parent; + this.path = path; + editing_done.connect(on_editing_done); + Gtk.Label label = new Gtk.Label(_("Key combination...")); + label.set_alignment(0.0f, 0.5f); + add(label); + override_background_color(Gtk.StateFlags.NORMAL, widget.get_style_context().get_background_color(Gtk.StateFlags.SELECTED)); + label.override_color(Gtk.StateFlags.NORMAL, widget.get_style_context().get_color(Gtk.StateFlags.SELECTED)); + show_all(); + } + + protected virtual void start_editing(Gdk.Event? event) { + Gtk.grab_add(this); + Gdk.keyboard_grab(get_window(), false, event != null ? event.get_time() : Gdk.CURRENT_TIME); + +/* + Gdk.DeviceManager dm = get_window().get_display().get_device_manager(); + foreach (Gdk.Device dev in dm.list_devices(Gdk.DeviceType.SLAVE)) + Gtk.device_grab_add(this, dev, true); +*/ + key_press_event.connect(on_key); + } + + bool on_key(Gdk.EventKey event) { + if (event.is_modifier != 0) + return true; + switch (event.keyval) { + case Gdk.Key.Super_L: + case Gdk.Key.Super_R: + case Gdk.Key.Hyper_L: + case Gdk.Key.Hyper_R: + return true; + } + Gdk.ModifierType mods = event.state & Gtk.accelerator_get_default_mod_mask(); + + editing_done(); + remove_widget(); + + parent.key_edited(path, mods, event.hardware_keycode); + return true; + } + void on_editing_done() { + Gtk.grab_remove(this); + Gdk.keyboard_ungrab(Gdk.CURRENT_TIME); + +/* + Gdk.DeviceManager dm = get_window().get_display().get_device_manager(); + foreach (Gdk.Device dev in dm.list_devices(Gdk.DeviceType.SLAVE)) + Gtk.device_grab_remove(this, dev); +*/ + } +} + + +class CellEditableCombo : Gtk.ComboBoxText { + new CellRendererTextish parent; + new string path; + + public CellEditableCombo(CellRendererTextish parent, string path, Gtk.Widget widget, string[] items) { + this.parent = parent; + this.path = path; + foreach (string item in items) { + append_text(_(item)); + } + changed.connect(() => parent.combo_edited(path, active)); + } +} diff --git a/prefs.cc b/prefs.cc index 9061870d..ec592998 100644 --- a/prefs.cc +++ b/prefs.cc @@ -19,6 +19,7 @@ #include "grabber.h" #include #include +#include "cellrenderertextish.h" #include #include @@ -234,6 +235,10 @@ void remove_last_entry(const Glib::ustring & name) { combo_model->erase(--i); } +static void on_prefs_editing_started(GtkCellRenderer *, GtkCellEditable *editable, const gchar *path, gpointer data) { + ((Prefs *)data)->on_button_editing_started(editable, path); +} + Prefs::Prefs() { new Check(prefs.advanced_ignore, "check_advanced_ignore"); @@ -292,13 +297,12 @@ Prefs::Prefs() { tv->append_column(_("Application (WM__CLASS)"), cols.user_app); tm->set_sort_column(cols.user_app, Gtk::SORT_ASCENDING); - CellRendererTextish *button_renderer = Gtk::manage(new CellRendererTextish); - button_renderer->mode = CellRendererTextish::POPUP; - tv->append_column(_("Button"), *button_renderer); - Gtk::TreeView::Column *col_button = tv->get_column(1); - col_button->add_attribute(button_renderer->property_text(), cols.button); - button_renderer->property_editable() = true; - button_renderer->signal_editing_started().connect(sigc::mem_fun(*this, &Prefs::on_button_editing_started)); + CellRendererTextish *button_renderer = cell_renderer_textish_new (); + button_renderer->mode = CELL_RENDERER_TEXTISH_MODE_Popup; + GtkTreeViewColumn *col_button = gtk_tree_view_column_new_with_attributes(_("Button"), GTK_CELL_RENDERER (button_renderer), "text", cols.button.index(), NULL); + gtk_tree_view_append_column(tv->gobj(), col_button); + g_object_set(button_renderer, "editable", true, NULL); + g_signal_connect(button_renderer, "editing-started", G_CALLBACK(on_prefs_editing_started), this); bbutton->signal_clicked().connect(sigc::mem_fun(*this, &Prefs::on_select_button)); @@ -630,7 +634,7 @@ void Prefs::on_add() { } } -void Prefs::on_button_editing_started(Gtk::CellEditable* editable, const Glib::ustring& path) { +void Prefs::on_button_editing_started(GtkCellEditable* editable, const gchar *path) { Gtk::TreeRow row(*tm->get_iter(path)); std::string app = row[cols.app]; ButtonInfo bi; diff --git a/prefs.h b/prefs.h index 40b5905b..91f09d01 100644 --- a/prefs.h +++ b/prefs.h @@ -34,7 +34,9 @@ class Prefs { void on_edit_extra(); void on_remove_extra(); void on_select_button(); - void on_button_editing_started(Gtk::CellEditable* editable, const Glib::ustring& path); +public: + void on_button_editing_started(GtkCellEditable *editable, const gchar *path); +private: void on_device_toggled(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter); void on_device_timeout_changed(const Glib::ustring& path, const Glib::ustring& new_text); bool select_row(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter, std::string name); diff --git a/win.h b/win.h index ada98d02..fcaa7d46 100644 --- a/win.h +++ b/win.h @@ -30,25 +30,6 @@ class Ranking; extern Glib::RefPtr widgets; -class CellRendererTextish : public Gtk::CellRendererText { -public: - enum Mode { TEXT, KEY, POPUP, COMBO }; - Mode mode; - const char **items; - CellRendererTextish() : mode(TEXT) {} - typedef sigc::signal key_edited; - typedef sigc::signal combo_edited; - key_edited &signal_key_edited() { return signal_key_edited_; } - combo_edited &signal_combo_edited() { return signal_combo_edited_; } -protected: - virtual Gtk::CellEditable* start_editing_vfunc(GdkEvent *event, Gtk::Widget &widget, const Glib::ustring &path, - const Gdk::Rectangle &background_area, const Gdk::Rectangle &cell_area, - Gtk::CellRendererState flags); -private: - key_edited signal_key_edited_; - combo_edited signal_combo_edited_; -}; - class Win : Timeout { public: Win();