summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Smith <john.smith7545@yahoo.com>2012-09-19 00:49:35 +0000
committerJohn Smith <john.smith7545@yahoo.com>2012-09-19 00:49:35 +0000
commit891ab5f239c03c2f3867d9445f070bc53f9d70b6 (patch)
treea83b5e7007670a914e1979bf9c81a5c93e829e87 /src
parentFix for 168164 : Fix precision of font size (diff)
downloadinkscape-891ab5f239c03c2f3867d9445f070bc53f9d70b6.tar.gz
inkscape-891ab5f239c03c2f3867d9445f070bc53f9d70b6.zip
Fix for 900602 : Enter key returns focus to canvas for Font family selector
(bzr r11676)
Diffstat (limited to 'src')
-rw-r--r--src/ink-comboboxentry-action.cpp69
-rw-r--r--src/ink-comboboxentry-action.h4
-rw-r--r--src/widgets/text-toolbar.cpp15
3 files changed, 82 insertions, 6 deletions
diff --git a/src/ink-comboboxentry-action.cpp b/src/ink-comboboxentry-action.cpp
index 869296f87..6e6071654 100644
--- a/src/ink-comboboxentry-action.cpp
+++ b/src/ink-comboboxentry-action.cpp
@@ -27,6 +27,7 @@
#include <string.h>
#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
#include "ink-comboboxentry-action.h"
@@ -42,6 +43,7 @@ static gint check_comma_separated_text( Ink_ComboBoxEntry_Action* action );
static void combo_box_changed_cb( GtkComboBox* widget, gpointer data );
static void entry_activate_cb( GtkEntry* widget, gpointer data );
static gboolean match_selected_cb( GtkEntryCompletion* widget, GtkTreeModel* model, GtkTreeIter* iter, gpointer data );
+static gboolean keypress_cb( GtkWidget *widget, GdkEventKey *event, gpointer data );
enum {
PROP_MODEL = 1,
@@ -50,7 +52,8 @@ enum {
PROP_ENTRY_WIDTH,
PROP_EXTRA_WIDTH,
PROP_CELL_DATA_FUNC,
- PROP_POPUP
+ PROP_POPUP,
+ PROP_FOCUS_WIDGET
};
enum {
@@ -105,6 +108,11 @@ static void ink_comboboxentry_action_set_property (GObject *object, guint proper
action->popup = g_value_get_boolean( value );
break;
+ case PROP_FOCUS_WIDGET:
+ action->focusWidget = (GtkWidget*)g_value_get_pointer( value );
+ break;
+
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -145,6 +153,11 @@ static void ink_comboboxentry_action_get_property (GObject *object, guint proper
g_value_set_boolean (value, action->popup);
break;
+ case PROP_FOCUS_WIDGET:
+ g_value_set_pointer (value, action->focusWidget);
+ break;
+
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -240,6 +253,13 @@ static void ink_comboboxentry_action_class_init (Ink_ComboBoxEntry_ActionClass *
false,
(GParamFlags)G_PARAM_READWRITE));
+ g_object_class_install_property( gobject_class,
+ PROP_FOCUS_WIDGET,
+ g_param_spec_pointer( "focus-widget",
+ "Focus Widget",
+ "The widget to return focus to",
+ (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) );
+
// We need to know when GtkComboBoxEvent or Menu ready for reading
signals[CHANGED] = g_signal_new( "changed",
G_TYPE_FROM_CLASS(klass),
@@ -269,6 +289,7 @@ static void ink_comboboxentry_action_init (Ink_ComboBoxEntry_Action *action)
action->popup = false;
action->warning = NULL;
action->altx_name = NULL;
+ action->focusWidget = NULL;
}
GType ink_comboboxentry_action_get_type ()
@@ -306,7 +327,8 @@ Ink_ComboBoxEntry_Action *ink_comboboxentry_action_new (const gchar *name,
GtkTreeModel *model,
gint entry_width,
gint extra_width,
- void *cell_data_func )
+ void *cell_data_func,
+ GtkWidget *focusWidget)
{
g_return_val_if_fail (name != NULL, NULL);
@@ -319,6 +341,7 @@ Ink_ComboBoxEntry_Action *ink_comboboxentry_action_new (const gchar *name,
"entry_width", entry_width,
"extra_width", extra_width,
"cell_data_func", cell_data_func,
+ "focus-widget", focusWidget,
NULL);
}
@@ -415,6 +438,7 @@ GtkWidget* create_tool_item( GtkAction* action )
// Add signal for GtkEntry to check if finished typing.
g_signal_connect( G_OBJECT(child), "activate", G_CALLBACK(entry_activate_cb), action );
+ g_signal_connect( G_OBJECT(child), "key-press-event", G_CALLBACK(keypress_cb), action );
}
@@ -561,6 +585,7 @@ void ink_comboboxentry_action_popup_enable( Ink_ComboBoxEntry_Action* action ) {
g_signal_connect (G_OBJECT (action->entry_completion), "match-selected", G_CALLBACK (match_selected_cb), action );
+
}
}
@@ -764,3 +789,43 @@ static gboolean match_selected_cb( GtkEntryCompletion* /*widget*/, GtkTreeModel*
return false;
}
+void ink_comboboxentry_action_defocus( Ink_ComboBoxEntry_Action* action )
+{
+ if ( action->focusWidget ) {
+ gtk_widget_grab_focus( action->focusWidget );
+ }
+}
+
+gboolean keypress_cb( GtkWidget *widget, GdkEventKey *event, gpointer data )
+{
+ gboolean wasConsumed = FALSE; /* default to report event not consumed */
+ guint key = 0;
+ Ink_ComboBoxEntry_Action* action = INK_COMBOBOXENTRY_ACTION( data );
+ gdk_keymap_translate_keyboard_state( gdk_keymap_get_for_display( gdk_display_get_default() ),
+ event->hardware_keycode, (GdkModifierType)event->state,
+ 0, &key, 0, 0, 0 );
+
+ switch ( key ) {
+
+ // TODO Add bindings for Esc/Tab/LeftTab
+ case GDK_KEY_Escape:
+ {
+ //gtk_spin_button_set_value( GTK_SPIN_BUTTON(widget), action->private_data->lastVal );
+ ink_comboboxentry_action_defocus( action );
+ wasConsumed = TRUE;
+ }
+ break;
+
+ case GDK_KEY_Return:
+ case GDK_KEY_KP_Enter:
+ {
+ ink_comboboxentry_action_defocus( action );
+ //wasConsumed = TRUE;
+ }
+ break;
+
+
+ }
+
+ return wasConsumed;
+}
diff --git a/src/ink-comboboxentry-action.h b/src/ink-comboboxentry-action.h
index 95306bcaa..7d4093f4e 100644
--- a/src/ink-comboboxentry-action.h
+++ b/src/ink-comboboxentry-action.h
@@ -59,6 +59,7 @@ struct _Ink_ComboBoxEntry_Action {
gboolean popup; // Do we pop-up an entry-completion dialog?
gchar *warning; // Text for warning that entry isn't in list.
gchar *altx_name; // Target for Alt-X keyboard shortcut.
+ GtkWidget *focusWidget;
};
@@ -74,7 +75,8 @@ Ink_ComboBoxEntry_Action *ink_comboboxentry_action_new ( const gchar *name,
GtkTreeModel *model,
gint entry_width = -1,
gint extra_width = -1,
- gpointer cell_data_func = NULL );
+ gpointer cell_data_func = NULL,
+ GtkWidget* focusWidget = NULL);
GtkTreeModel *ink_comboboxentry_action_get_model( Ink_ComboBoxEntry_Action* action );
GtkComboBox *ink_comboboxentry_action_get_comboboxentry( Ink_ComboBoxEntry_Action* action );
diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp
index db9abc4c8..60ede002f 100644
--- a/src/widgets/text-toolbar.cpp
+++ b/src/widgets/text-toolbar.cpp
@@ -1464,7 +1464,8 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
GTK_TREE_MODEL(model),
-1, // Entry width
50, // Extra list width
- (gpointer)cell_data_func ); // Cell layout
+ (gpointer)cell_data_func,// Cell layout
+ GTK_WIDGET(desktop->canvas)); // Focus widget
ink_comboboxentry_action_popup_enable( act ); // Enable entry completion
gchar *const warning = _("Font not found on system");
ink_comboboxentry_action_set_warning( act, warning ); // Show icon with tooltip if missing font
@@ -1498,7 +1499,11 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
_(tooltip.c_str()),
NULL,
GTK_TREE_MODEL(model_size),
- 4 ); // Width in characters
+ 4, // Width in characters
+ 0, // Extra list width
+ NULL, // Cell layout
+ GTK_WIDGET(desktop->canvas)); // Focus widget
+
g_signal_connect( G_OBJECT(act), "changed", G_CALLBACK(sp_text_fontsize_value_changed), holder );
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
g_object_set_data( holder, "TextFontSizeAction", act );
@@ -1513,7 +1518,11 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje
_("Font style"),
NULL,
GTK_TREE_MODEL(model_style),
- 12 ); // Width in characters
+ 12, // Width in characters
+ 0, // Extra list width
+ NULL, // Cell layout
+ GTK_WIDGET(desktop->canvas)); // Focus widget
+
g_signal_connect( G_OBJECT(act), "changed", G_CALLBACK(sp_text_fontstyle_value_changed), holder );
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
g_object_set_data( holder, "TextFontStyleAction", act );