summaryrefslogtreecommitdiffstats
path: root/src/ink-comboboxentry-action.cpp
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2013-02-06 08:19:53 +0000
committerJabiertxo Arraiza Cenoz <jtx@jtx.marker.es>2013-02-06 08:19:53 +0000
commit549a79b5367ffd259a23fbd18e93199d1c0149b7 (patch)
tree9c4ce4a0217afa63b59f32d02a60b848f43a9520 /src/ink-comboboxentry-action.cpp
parentMerge from branch (diff)
parentSupress Pango error message. (diff)
downloadinkscape-549a79b5367ffd259a23fbd18e93199d1c0149b7.tar.gz
inkscape-549a79b5367ffd259a23fbd18e93199d1c0149b7.zip
Merge from branch
(bzr r11950.1.19)
Diffstat (limited to 'src/ink-comboboxentry-action.cpp')
-rw-r--r--src/ink-comboboxentry-action.cpp111
1 files changed, 47 insertions, 64 deletions
diff --git a/src/ink-comboboxentry-action.cpp b/src/ink-comboboxentry-action.cpp
index d9b1b0965..a28ec4f53 100644
--- a/src/ink-comboboxentry-action.cpp
+++ b/src/ink-comboboxentry-action.cpp
@@ -25,6 +25,7 @@
#include <iostream>
#include <string.h>
+#include <glibmm/ustring.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
@@ -37,7 +38,7 @@ static GtkWidget* create_menu_item( GtkAction* action );
// Internal
static gint get_active_row_from_text( Ink_ComboBoxEntry_Action* action, const gchar* target_text );
-static gint check_comma_separated_text( Ink_ComboBoxEntry_Action* action );
+static Glib::ustring check_comma_separated_text( Ink_ComboBoxEntry_Action* action );
// Callbacks
static void combo_box_changed_cb( GtkComboBox* widget, gpointer data );
@@ -63,9 +64,13 @@ enum {
};
static guint signals[N_SIGNALS] = {0};
-static GtkActionClass *ink_comboboxentry_action_parent_class = NULL;
static GQuark gDataName = 0;
+static void ink_comboboxentry_action_init (Ink_ComboBoxEntry_Action *action);
+static void ink_comboboxentry_action_class_init (Ink_ComboBoxEntry_ActionClass *klass);
+
+G_DEFINE_TYPE(Ink_ComboBoxEntry_Action, ink_comboboxentry_action, GTK_TYPE_ACTION);
+
static void ink_comboboxentry_action_finalize (GObject *object)
{
// Free any allocated resources.
@@ -174,8 +179,8 @@ ink_comboboxentry_action_connect_proxy (GtkAction *action,
GTK_ACTION_CLASS (ink_comboboxentry_action_parent_class)->connect_proxy (action, proxy);
}
-
-static void ink_comboboxentry_action_class_init (Ink_ComboBoxEntry_ActionClass *klass)
+static void
+ink_comboboxentry_action_class_init (Ink_ComboBoxEntry_ActionClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
@@ -192,8 +197,6 @@ static void ink_comboboxentry_action_class_init (Ink_ComboBoxEntry_ActionClass *
klass->parent_class.create_tool_item = create_tool_item;
klass->parent_class.create_menu_item = create_menu_item;
- ink_comboboxentry_action_parent_class = GTK_ACTION_CLASS(g_type_class_peek_parent (klass) );
-
g_object_class_install_property (
gobject_class,
PROP_MODEL,
@@ -292,34 +295,6 @@ static void ink_comboboxentry_action_init (Ink_ComboBoxEntry_Action *action)
action->focusWidget = NULL;
}
-GType ink_comboboxentry_action_get_type ()
-{
- static GType ink_comboboxentry_action_type = 0;
-
- if (!ink_comboboxentry_action_type) {
- static const GTypeInfo ink_comboboxentry_action_info = {
- sizeof(Ink_ComboBoxEntry_ActionClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) ink_comboboxentry_action_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof(Ink_ComboBoxEntry_Action),
- 0, /* n_preallocs */
- (GInstanceInitFunc)ink_comboboxentry_action_init, /* instance_init */
- NULL /* value_table */
- };
-
- ink_comboboxentry_action_type = g_type_register_static (GTK_TYPE_ACTION,
- "Ink_ComboBoxEntry_Action",
- &ink_comboboxentry_action_info,
- (GTypeFlags)0 );
- }
-
- return ink_comboboxentry_action_type;
-}
-
-
Ink_ComboBoxEntry_Action *ink_comboboxentry_action_new (const gchar *name,
const gchar *label,
const gchar *tooltip,
@@ -439,7 +414,7 @@ GtkWidget* create_tool_item( GtkAction* action )
} else {
- item = ink_comboboxentry_action_parent_class->create_tool_item( action );
+ item = GTK_ACTION_CLASS(ink_comboboxentry_action_parent_class)->create_tool_item( action );
}
@@ -451,7 +426,7 @@ GtkWidget* create_menu_item( GtkAction* action )
{
GtkWidget* item = 0;
- item = ink_comboboxentry_action_parent_class->create_menu_item( action );
+ item = GTK_ACTION_CLASS(ink_comboboxentry_action_parent_class)->create_menu_item( action );
g_warning( "ink_comboboxentry_action: create_menu_item not implemented" );
// One can easily modify ege-select-one-action routine to implement this.
return item;
@@ -495,10 +470,12 @@ gboolean ink_comboboxentry_action_set_active_text( Ink_ComboBoxEntry_Action* ink
gtk_entry_set_text( ink_comboboxentry_action->entry, text );
// Show or hide warning
+ bool clear = true;
if( ink_comboboxentry_action->active == -1 &&
- ink_comboboxentry_action->warning != NULL &&
- check_comma_separated_text( ink_comboboxentry_action ) ) {
- {
+ ink_comboboxentry_action->warning != NULL ) {
+ Glib::ustring missing = check_comma_separated_text( ink_comboboxentry_action );
+ if( !missing.empty() ) {
+
GtkStockItem item;
gboolean isStock = gtk_stock_lookup( GTK_STOCK_DIALOG_WARNING, &item );
if (isStock) {
@@ -510,15 +487,21 @@ gboolean ink_comboboxentry_action_set_active_text( Ink_ComboBoxEntry_Action* ink
GTK_ENTRY_ICON_SECONDARY,
GTK_STOCK_DIALOG_WARNING );
}
+ // Can't add tooltip until icon set
+ Glib::ustring warning = ink_comboboxentry_action->warning;
+ warning += ": ";
+ warning += missing;
+ gtk_entry_set_icon_tooltip_text( ink_comboboxentry_action->entry,
+ GTK_ENTRY_ICON_SECONDARY,
+ warning.c_str() );
+ clear = false;
}
- // Can't add tooltip until icon set
- gtk_entry_set_icon_tooltip_text( ink_comboboxentry_action->entry,
- GTK_ENTRY_ICON_SECONDARY,
- ink_comboboxentry_action->warning );
- } else {
+ }
+
+ if( clear ) {
gtk_entry_set_icon_from_icon_name( GTK_ENTRY(ink_comboboxentry_action->entry),
- GTK_ENTRY_ICON_SECONDARY,
- NULL );
+ GTK_ENTRY_ICON_SECONDARY,
+ NULL );
gtk_entry_set_icon_from_stock( GTK_ENTRY(ink_comboboxentry_action->entry),
GTK_ENTRY_ICON_SECONDARY,
NULL );
@@ -657,18 +640,21 @@ gint get_active_row_from_text( Ink_ComboBoxEntry_Action* action, const gchar* ta
}
-// Checks if all comma separated text fragments are in the list.
+// Checks if all comma separated text fragments are in the list and
+// returns a ustring with a list of missing fragments.
// This is useful for checking if all fonts in a font-family fallback
// list are available on the system.
-// The return value is set to the number of missing text fragments.
+//
// This routine could also create a Pango Markup string to show which
-// fragments are invalid.
-// It is envisioned that one can construct a Pango Markup String here
-// so that individual text fragments can be flagged as not being in the
-// list.
-static gint check_comma_separated_text( Ink_ComboBoxEntry_Action* action ) {
+// fragments are invalid in the entry box itself. See:
+// http://developer.gnome.org/pango/stable/PangoMarkupFormat.html
+// However... it appears that while one can retrieve the PangoLayout
+// for a GtkEntry box, it is only a copy and changing it has no effect.
+// PangoLayout * pl = gtk_entry_get_layout( entry );
+// pango_layout_set_markup( pl, "NEW STRING", -1 ); // DOESN'T WORK
+static Glib::ustring check_comma_separated_text( Ink_ComboBoxEntry_Action* action ) {
- gint ret_val = 0;
+ Glib::ustring missing;
// Parse fallback_list using a comma as deliminator
gchar** tokens = g_strsplit( action->text, ",", 0 );
@@ -680,21 +666,18 @@ static gint check_comma_separated_text( Ink_ComboBoxEntry_Action* action ) {
g_strstrip( tokens[i] );
if( get_active_row_from_text( action, tokens[i] ) == -1 ) {
- ret_val += 1;
+ missing += tokens[i];
+ missing += ", ";
}
++i;
}
g_strfreev( tokens );
- // Pango Markup notes:
- // GString* Pango_Markup = g_string_new("");
- // if not present:
- // g_string_sprintfa( Pango_Markup, "<span strikethrough=\"true\" strikethrough_color=\"#880000\">%s</span>", tokens[i] );
- // PangoLayout * pl = gtk_entry_get_layout( entry );
- // pango_layout_set_markup( pl, Pango_Markup->str, -1 );
- // g_string_free( Pango_Markup, TRUE );
-
- return ret_val;
+ // Remove extra comma and space from end.
+ if( missing.size() >= 2 ) {
+ missing.resize( missing.size()-2 );
+ }
+ return missing;
}
// Callbacks ---------------------------------------------------