Commit 29c8c60b authored by Juan Pablo Ugarte's avatar Juan Pablo Ugarte
Browse files

Added glade_displayable_value_is_disabled/set_disabled() functions to disable...

Added glade_displayable_value_is_disabled/set_disabled() functions to disable GdkModifierType reserved values
parent baadf434
......@@ -37,46 +37,47 @@ typedef struct
{
gchar *value;
gchar *string;
gboolean disabled:1;
} ValueTab;
static GHashTable *values_hash = NULL;
static gint
find_by_value (ValueTab * a, const gchar * b)
find_by_value (ValueTab *a, const gchar *b)
{
return strcmp (a->value, b);
}
static gint
find_by_displayable (ValueTab * a, const gchar * b)
find_by_displayable (ValueTab *a, const gchar *b)
{
return strcmp (a->string, b);
}
void
glade_register_displayable_value (GType type,
const gchar * value,
const gchar * domain, const gchar * string)
const gchar *value,
const gchar *domain,
const gchar *string)
{
g_return_if_fail (value && value[0]);
g_return_if_fail (domain && domain[0]);
g_return_if_fail (string && string[0]);
glade_register_translated_value (type, value, dgettext (domain, string));
}
void
glade_register_translated_value (GType type,
const gchar * value, const gchar * string)
const gchar *value,
const gchar *string)
{
ValueTab *tab;
gpointer klass;
GList *values;
g_return_if_fail (value && value[0]);
g_return_if_fail (string && string[0]);
klass = g_type_class_ref (type);
g_return_if_fail (klass != NULL);
......@@ -86,6 +87,7 @@ glade_register_translated_value (GType type,
tab = g_new0 (ValueTab, 1);
tab->value = g_strdup (value);
tab->string = g_strdup (string);
tab->disabled = FALSE;
if ((values = g_hash_table_lookup (values_hash, klass)) != NULL)
{
......@@ -109,6 +111,28 @@ glade_register_translated_value (GType type,
g_type_class_unref (klass);
}
static ValueTab *
get_value_tab (GType type, const gchar *value, GCompareFunc cmpfunc)
{
GList *values, *tab_iter;
gpointer klass;
ValueTab *tab;
if (!values_hash) return NULL;
klass = g_type_class_ref (type);
if ((values = g_hash_table_lookup (values_hash, klass)) != NULL &&
(tab_iter = g_list_find_custom (values, value, cmpfunc)) != NULL)
tab = tab_iter->data;
else
tab = NULL;
g_type_class_unref (klass);
return tab;
}
gboolean
glade_type_has_displayable_values (GType type)
{
......@@ -123,62 +147,54 @@ glade_type_has_displayable_values (GType type)
}
G_CONST_RETURN gchar *
glade_get_displayable_value (GType type, const gchar * value)
glade_get_displayable_value (GType type, const gchar *value)
{
ValueTab *tab;
gpointer klass;
GList *values, *tab_iter;
gchar *displayable = NULL;
g_return_val_if_fail (value && value[0], NULL);
if (!values_hash)
return NULL;
klass = g_type_class_ref (type);
g_return_val_if_fail (klass != NULL, NULL);
if ((tab = get_value_tab (type, value, (GCompareFunc) find_by_value)))
return tab->string;
if ((values = g_hash_table_lookup (values_hash, klass)) != NULL &&
(tab_iter =
g_list_find_custom (values, value,
(GCompareFunc) find_by_value)) != NULL)
{
tab = tab_iter->data;
displayable = tab->string;
}
g_type_class_unref (klass);
return displayable;
return NULL;
}
G_CONST_RETURN gchar *
glade_get_value_from_displayable (GType type, const gchar * displayable)
glade_get_value_from_displayable (GType type, const gchar *displayable)
{
ValueTab *tab;
gpointer klass;
GList *values, *tab_iter;
gchar *value = NULL;
g_return_val_if_fail (displayable && displayable[0], NULL);
if (!values_hash)
return NULL;
if ((tab = get_value_tab (type, displayable, (GCompareFunc) find_by_displayable)))
return tab->value;
klass = g_type_class_ref (type);
return NULL;
}
g_return_val_if_fail (klass != NULL, NULL);
gboolean
glade_displayable_value_is_disabled (GType type, const gchar *value)
{
ValueTab *tab;
if ((values = g_hash_table_lookup (values_hash, klass)) != NULL &&
(tab_iter =
g_list_find_custom (values, displayable,
(GCompareFunc) find_by_displayable)) != NULL)
{
tab = tab_iter->data;
value = tab->value;
}
g_type_class_unref (klass);
g_return_val_if_fail (value && value[0], FALSE);
if ((tab = get_value_tab (type, value, (GCompareFunc) find_by_value)))
return tab->disabled;
return FALSE;
}
void
glade_displayable_value_set_disabled (GType type,
const gchar *value,
gboolean disabled)
{
ValueTab *tab;
g_return_if_fail (value && value[0]);
return value;
if ((tab = get_value_tab (type, value, (GCompareFunc) find_by_value)))
tab->disabled = disabled;
}
......@@ -21,6 +21,13 @@ G_CONST_RETURN
gchar *glade_get_displayable_value (GType type,
const gchar *value);
gboolean glade_displayable_value_is_disabled (GType type,
const gchar *value);
void glade_displayable_value_set_disabled (GType type,
const gchar *value,
gboolean disabled);
G_CONST_RETURN
gchar *glade_get_value_from_displayable (GType type,
const gchar *displayabe);
......
......@@ -72,6 +72,7 @@ static guint glade_eprop_signals[LAST_SIGNAL] = { 0, };
#define GLADE_PROPERTY_TABLE_ROW_SPACING 2
#define FLAGS_COLUMN_SETTING 0
#define FLAGS_COLUMN_SYMBOL 1
#define FLAGS_COLUMN_VALUE 2
struct _GladeEditorPropertyPrivate
{
......@@ -864,9 +865,14 @@ glade_eprop_enum_create_input (GladeEditorProperty *eprop)
for (i = 0; i < eclass->n_values; i++)
{
const gchar *value_name =
glade_get_displayable_value (pspec->value_type,
eclass->values[i].value_nick);
const gchar *value_name;
if (glade_displayable_value_is_disabled (pspec->value_type,
eclass->values[i].value_nick))
continue;
value_name = glade_get_displayable_value (pspec->value_type,
eclass->values[i].value_nick);
if (value_name == NULL)
value_name = eclass->values[i].value_nick;
......@@ -950,6 +956,10 @@ glade_eprop_flags_load (GladeEditorProperty *eprop, GladeProperty *property)
gboolean setting;
const gchar *value_name;
if (glade_displayable_value_is_disabled (pspec->value_type,
klass->values[flag_num].value_nick))
continue;
mask = klass->values[flag_num].value;
setting = ((value & mask) == mask) ? TRUE : FALSE;
......@@ -970,8 +980,9 @@ glade_eprop_flags_load (GladeEditorProperty *eprop, GladeProperty *property)
/* Add a row to represent the flag. */
gtk_list_store_append (GTK_LIST_STORE (eprop_flags->model), &iter);
gtk_list_store_set (GTK_LIST_STORE (eprop_flags->model), &iter,
FLAGS_COLUMN_SETTING,
setting, FLAGS_COLUMN_SYMBOL, value_name, -1);
FLAGS_COLUMN_SETTING, setting,
FLAGS_COLUMN_SYMBOL, value_name,
FLAGS_COLUMN_VALUE, mask, -1);
}
g_type_class_unref (klass);
......@@ -991,10 +1002,8 @@ flag_toggled_direct (GtkCellRendererToggle *cell,
GtkTreeIter iter;
guint new_value = 0;
gboolean selected;
guint value = 0;
gint flag_num = 0;
GFlagsClass *klass;
GValue *gvalue;
gboolean valid;
GladeEPropFlags *eprop_flags = GLADE_EPROP_FLAGS (eprop);
......@@ -1003,9 +1012,6 @@ flag_toggled_direct (GtkCellRendererToggle *cell,
gvalue = glade_property_inline_value (eprop->priv->property);
klass = g_type_class_ref (G_VALUE_TYPE (gvalue));
value = g_value_get_flags (gvalue);
gtk_tree_model_get_iter_from_string (eprop_flags->model, &iter, path_string);
gtk_tree_model_get (eprop_flags->model, &iter,
......@@ -1016,28 +1022,28 @@ flag_toggled_direct (GtkCellRendererToggle *cell,
gtk_list_store_set (GTK_LIST_STORE (eprop_flags->model), &iter,
FLAGS_COLUMN_SETTING, selected, -1);
gtk_tree_model_get_iter_first (GTK_TREE_MODEL (eprop_flags->model), &iter);
valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (eprop_flags->model), &iter);
/* Step through each of the flags in the class, checking if
the corresponding toggle in the dialog is selected, If it
is, OR the flags' mask with the new value. */
for (flag_num = 0; flag_num < klass->n_values; flag_num++)
while (valid)
{
gboolean setting;
guint value;
gtk_tree_model_get (GTK_TREE_MODEL (eprop_flags->model), &iter,
FLAGS_COLUMN_SETTING, &setting, -1);
FLAGS_COLUMN_SETTING, &setting,
FLAGS_COLUMN_VALUE, &value, -1);
if (setting)
new_value |= klass->values[flag_num].value;
if (setting) new_value |= value;
gtk_tree_model_iter_next (GTK_TREE_MODEL (eprop_flags->model), &iter);
valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (eprop_flags->model), &iter);
}
/* If the new_value is different from the old value, we need
to update the property. */
if (new_value != value)
if (new_value != g_value_get_flags (gvalue))
{
GValue val = { 0, };
......@@ -1047,9 +1053,6 @@ flag_toggled_direct (GtkCellRendererToggle *cell,
glade_editor_property_commit_no_callback (eprop, &val);
g_value_unset (&val);
}
}
static GtkWidget *
......@@ -1061,8 +1064,9 @@ glade_eprop_flags_create_treeview (GladeEditorProperty *eprop)
GtkCellRenderer *renderer;
GladeEPropFlags *eprop_flags = GLADE_EPROP_FLAGS (eprop);
if (!eprop_flags->model)
eprop_flags->model = GTK_TREE_MODEL (gtk_list_store_new (2, G_TYPE_BOOLEAN,
G_TYPE_STRING));
eprop_flags->model = GTK_TREE_MODEL (gtk_list_store_new (3, G_TYPE_BOOLEAN,
G_TYPE_STRING,
G_TYPE_UINT));
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
......
......@@ -1530,20 +1530,26 @@ gpc_read_displayable_values_from_node (GladeXmlNode * node,
if ((child = glade_xml_search_child (node, GLADE_TAG_VALUE)) == NULL)
return;
child = glade_xml_node_get_children (node);
while (child != NULL)
for (child = glade_xml_node_get_children (node); child; child = glade_xml_node_next (child))
{
gint i;
gchar *id, *name;
GEnumValue *enum_val;
GFlagsValue *flags_val;
gboolean disabled;
id = glade_xml_get_property_string_required (child, GLADE_TAG_ID, NULL);
if (!id) continue;
disabled = glade_xml_get_property_boolean (child, GLADE_TAG_DISABLED, FALSE);
id = glade_xml_get_property_string_required (child, GLADE_TAG_ID, NULL);
name = glade_xml_get_property_string_required (child, GLADE_TAG_NAME, NULL);
if (!id || !name)
continue;
if (!disabled)
{
name = glade_xml_get_property_string_required (child, GLADE_TAG_NAME, NULL);
if (!name) continue;
}
else
name = NULL;
for (i = 0; i < n_values; i++)
{
......@@ -1563,6 +1569,10 @@ gpc_read_displayable_values_from_node (GladeXmlNode * node,
glade_register_displayable_value (klass->pspec->value_type,
enum_val->value_nick,
domain, name);
if (disabled)
glade_displayable_value_set_disabled (klass->pspec->value_type,
enum_val->value_nick,
TRUE);
}
else
{
......@@ -1570,7 +1580,10 @@ gpc_read_displayable_values_from_node (GladeXmlNode * node,
glade_register_displayable_value (klass->pspec->value_type,
flags_val->value_nick,
domain, name);
if (disabled)
glade_displayable_value_set_disabled (klass->pspec->value_type,
flags_val->value_nick,
TRUE);
}
break;
}
......@@ -1578,8 +1591,6 @@ gpc_read_displayable_values_from_node (GladeXmlNode * node,
g_free (id);
g_free (name);
child = glade_xml_node_next (child);
}
if (n_values != registered_values)
......
......@@ -109,6 +109,8 @@
<value id="GDK_PROXIMITY_OUT_MASK" _name="Proximity Out"/>
<value id="GDK_SUBSTRUCTURE_MASK" _name="Substructure"/>
<value id="GDK_SCROLL_MASK" _name="Scroll"/>
<value id="GDK_TOUCH_MASK" _name="Touch"/>
<value id="GDK_SMOOTH_SCROLL_MASK" _name="Smooth scroll"/>
<value id="GDK_ALL_EVENTS_MASK" _name="All Events"/>
</displayable-values>
</property>
......@@ -2247,8 +2249,18 @@ embedded in another object</_tooltip>
toplevel="True"/>
<glade-widget-class name="GtkTreeModelSort" generic-name="treemodelsort" _title="Tree Model Sort"
toplevel="True"/>
<glade-widget-class name="GtkTreeSelection" generic-name="treeselection" _title="Tree Selection"/>
<glade-widget-class name="GtkTreeSelection" generic-name="treeselection" _title="Tree Selection">
<properties>
<property id="mode">
<displayable-values>
<value id="GTK_SELECTION_NONE" _name="None"/>
<value id="GTK_SELECTION_SINGLE" _name="Single"/>
<value id="GTK_SELECTION_BROWSE" _name="Browse"/>
<value id="GTK_SELECTION_MULTIPLE" _name="Multiple"/>
</displayable-values>
</property>
</properties>
</glade-widget-class>
<glade-widget-class name="GtkTreeView" generic-name="treeview" _title="Tree View">
<post-create-function>empty</post-create-function>
......@@ -2360,14 +2372,7 @@ embedded in another object</_tooltip>
<property id="pixbuf-column" disabled="True"/>
<property id="reorderable" ignore="True"/>
<property id="model" create-type="GtkListStore" query="True" />
<property id="selection-mode" since="2.6">
<displayable-values>
<value id="GTK_SELECTION_NONE" _name="None"/>
<value id="GTK_SELECTION_SINGLE" _name="Single"/>
<value id="GTK_SELECTION_BROWSE" _name="Browse"/>
<value id="GTK_SELECTION_MULTIPLE" _name="Multiple"/>
</displayable-values>
</property>
<property id="selection-mode" since="2.6"/>
</properties>
<packing-properties>
......@@ -3113,6 +3118,20 @@ embedded in another object</_tooltip>
<value id="GDK_META_MASK" _name="Meta Modifier"/>
<value id="GDK_RELEASE_MASK" _name="Release Modifier"/>
<value id="GDK_MODIFIER_MASK" _name="All Modifiers"/>
<value id="GDK_MODIFIER_RESERVED_13_MASK" disabled="True"/>
<value id="GDK_MODIFIER_RESERVED_14_MASK" disabled="True"/>
<value id="GDK_MODIFIER_RESERVED_15_MASK" disabled="True"/>
<value id="GDK_MODIFIER_RESERVED_16_MASK" disabled="True"/>
<value id="GDK_MODIFIER_RESERVED_17_MASK" disabled="True"/>
<value id="GDK_MODIFIER_RESERVED_18_MASK" disabled="True"/>
<value id="GDK_MODIFIER_RESERVED_19_MASK" disabled="True"/>
<value id="GDK_MODIFIER_RESERVED_20_MASK" disabled="True"/>
<value id="GDK_MODIFIER_RESERVED_21_MASK" disabled="True"/>
<value id="GDK_MODIFIER_RESERVED_22_MASK" disabled="True"/>
<value id="GDK_MODIFIER_RESERVED_23_MASK" disabled="True"/>
<value id="GDK_MODIFIER_RESERVED_24_MASK" disabled="True"/>
<value id="GDK_MODIFIER_RESERVED_25_MASK" disabled="True"/>
<value id="GDK_MODIFIER_RESERVED_29_MASK" disabled="True"/>
</displayable-values>
</property>
<property id="attr-accel-mods" _name="Accelerator Modifiers column" save="False" default="-1" custom-layout="True">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment