static void glade_gtk_parse_atk_relation (GladeProperty * property, GladeXmlNode * node) { GladeXmlNode *prop; GladePropertyClass *pclass; gchar *type, *target, *id, *tmp; gchar *string = NULL; for (prop = glade_xml_node_get_children (node); prop; prop = glade_xml_node_next (prop)) { if (!glade_xml_node_verify_silent (prop, GLADE_TAG_A11Y_RELATION)) continue; if (!(type = glade_xml_get_property_string_required (prop, GLADE_TAG_A11Y_TYPE, NULL))) continue; if (!(target = glade_xml_get_property_string_required (prop, GLADE_TAG_A11Y_TARGET, NULL))) { g_free (type); continue; } id = glade_util_read_prop_name (type); pclass = glade_property_get_class (property); if (!strcmp (id, glade_property_class_id (pclass))) { if (string == NULL) string = g_strdup (target); else { tmp = g_strdup_printf ("%s%s%s", string, GPC_OBJECT_DELIMITER, target); string = (g_free (string), tmp); } } g_free (id); g_free (type); g_free (target); } /* we must synchronize this directly after loading this project * (i.e. lookup the actual objects after they've been parsed and * are present). this is a feature of object and object list properties * that needs a better api. */ if (string) { g_object_set_data_full (G_OBJECT (property), "glade-loaded-object", /* 'string' here is already allocated on the heap */ string, g_free); } }
static GladeEditorProperty * append_item (GladeEditorTable *table, GladePropertyClass *klass, gboolean from_query_dialog) { GladeEditorProperty *property; GtkWidget *label; if (!(property = glade_widget_adaptor_create_eprop (glade_property_class_get_adaptor (klass), klass, from_query_dialog == FALSE))) { g_critical ("Unable to create editor for property '%s' of class '%s'", glade_property_class_id (klass), glade_widget_adaptor_get_name (glade_property_class_get_adaptor (klass))); return NULL; } gtk_widget_show (GTK_WIDGET (property)); gtk_widget_show_all (glade_editor_property_get_item_label (property)); label = glade_editor_property_get_item_label (property); gtk_widget_set_hexpand (label, FALSE); glade_editor_table_attach (table, label, 0, table->priv->rows); glade_editor_table_attach (table, GTK_WIDGET (property), 1, table->priv->rows); table->priv->rows++; return property; }
static void glade_gtk_widget_write_atk_relation (GladeProperty * property, GladeXmlContext * context, GladeXmlNode * node) { GladeXmlNode *prop_node; GladePropertyClass *pclass; gchar *value, **split; gint i; if ((value = glade_widget_adaptor_string_from_value (glade_property_class_get_adaptor (glade_property_get_class (property)), glade_property_get_class (property), glade_property_inline_value (property))) != NULL) { if ((split = g_strsplit (value, GPC_OBJECT_DELIMITER, 0)) != NULL) { for (i = 0; split[i] != NULL; i++) { pclass = glade_property_get_class (property); prop_node = glade_xml_node_new (context, GLADE_TAG_A11Y_RELATION); glade_xml_node_append_child (node, prop_node); glade_xml_node_set_property_string (prop_node, GLADE_TAG_A11Y_TYPE, glade_property_class_id (pclass)); glade_xml_node_set_property_string (prop_node, GLADE_TAG_A11Y_TARGET, split[i]); } g_strfreev (split); } } }
static gint property_class_comp (gconstpointer a, gconstpointer b) { GladePropertyClass *ca = (GladePropertyClass *)a, *cb = (GladePropertyClass *)b; GParamSpec *pa, *pb; const gchar *name_a, *name_b; pa = glade_property_class_get_pspec (ca); pb = glade_property_class_get_pspec (cb); name_a = glade_property_class_id (ca); name_b = glade_property_class_id (cb); /* Special case for the 'name' property, it *always* comes first. */ if (strcmp (name_a, "name") == 0) return -1; else if (strcmp (name_b, "name") == 0) return 1; /* Properties of the same class are sorted in the same level */ else if (pa->owner_type == pb->owner_type) { gdouble result = glade_property_class_weight (ca) - glade_property_class_weight (cb); /* Avoid cast to int */ if (result < 0.0) return -1; else if (result > 0.0) return 1; else return 0; } /* Group properties by thier class hierarchy */ else { if (g_type_is_a (pa->owner_type, pb->owner_type)) return (glade_property_class_common (ca) || glade_property_class_get_is_packing (ca)) ? 1 : -1; else return (glade_property_class_common (ca) || glade_property_class_get_is_packing (ca)) ? -1 : 1; } }
static gboolean glade_property_verify (GladeProperty * property, const GValue * value) { gboolean ret = FALSE; GladeWidget *parent; parent = glade_widget_get_parent (property->priv->widget); if (glade_property_class_get_is_packing (property->priv->klass) && parent) ret = glade_widget_adaptor_child_verify_property (glade_widget_get_adaptor (parent), glade_widget_get_object (parent), glade_widget_get_object (property->priv->widget), glade_property_class_id (property->priv->klass), value); else if (!glade_property_class_get_is_packing (property->priv->klass)) ret = glade_widget_adaptor_verify_property (glade_widget_get_adaptor (property->priv->widget), glade_widget_get_object (property->priv->widget), glade_property_class_id (property->priv->klass), value); return ret; }
static void glade_property_load_impl (GladeProperty * property) { GObject *object; GObjectClass *oclass; GParamSpec *pspec; pspec = glade_property_class_get_pspec (property->priv->klass); if (property->priv->widget == NULL || glade_property_class_get_virtual (property->priv->klass) || glade_property_class_get_is_packing (property->priv->klass) || glade_property_class_get_ignore (property->priv->klass) || !(pspec->flags & G_PARAM_READABLE) || G_IS_PARAM_SPEC_OBJECT (pspec)) return; object = glade_widget_get_object (property->priv->widget); oclass = G_OBJECT_GET_CLASS (object); if (g_object_class_find_property (oclass, glade_property_class_id (property->priv->klass))) glade_widget_object_get_property (property->priv->widget, glade_property_class_id (property->priv->klass), property->priv->value); }
static void glade_popup_property_docs_cb (GtkMenuItem *item, GladeProperty *property) { GladeWidgetAdaptor *adaptor, *prop_adaptor; GladePropertyClass *pclass; GParamSpec *pspec; gchar *search; pclass = glade_property_get_class (property); pspec = glade_property_class_get_pspec (pclass); prop_adaptor = glade_property_class_get_adaptor (pclass); adaptor = glade_widget_adaptor_from_pspec (prop_adaptor, pspec); search = g_strdup_printf ("The \"%s\" property", glade_property_class_id (pclass)); glade_app_search_docs (glade_widget_adaptor_get_book (adaptor), g_type_name (pspec->owner_type), search); g_free (search); }
static void glade_gtk_widget_write_atk_property (GladeProperty * property, GladeXmlContext * context, GladeXmlNode * node) { GladeXmlNode *prop_node; GladePropertyClass *pclass; gchar *value; glade_property_get (property, &value); if (value && value[0]) { pclass = glade_property_get_class (property); prop_node = glade_xml_node_new (context, GLADE_TAG_A11Y_PROPERTY); glade_xml_node_append_child (node, prop_node); glade_xml_node_set_property_string (prop_node, GLADE_TAG_NAME, glade_property_class_id (pclass)); glade_xml_set_content (prop_node, value); if (glade_property_i18n_get_translatable (property)) glade_xml_node_set_property_string (prop_node, GLADE_TAG_TRANSLATABLE, GLADE_XML_TAG_I18N_TRUE); if (glade_property_i18n_get_comment (property)) glade_xml_node_set_property_string (prop_node, GLADE_TAG_COMMENT, glade_property_i18n_get_comment (property)); if (glade_property_i18n_get_context (property)) glade_xml_node_set_property_string (prop_node, GLADE_TAG_CONTEXT, glade_property_i18n_get_context (property)); } }
static GList * create_command_property_list (GladeWidget * gnew, GList * saved_props) { GList *l, *command_properties = NULL; for (l = saved_props; l; l = l->next) { GladeProperty *property = l->data; GladePropertyClass *pclass = glade_property_get_class (property); GladeProperty *orig_prop = glade_widget_get_pack_property (gnew, glade_property_class_id (pclass)); GCSetPropData *pdata = g_new0 (GCSetPropData, 1); pdata->property = orig_prop; pdata->old_value = g_new0 (GValue, 1); pdata->new_value = g_new0 (GValue, 1); glade_property_get_value (orig_prop, pdata->old_value); glade_property_get_value (property, pdata->new_value); command_properties = g_list_prepend (command_properties, pdata); } return g_list_reverse (command_properties); }
static void glade_gtk_widget_write_atk_action (GladeProperty * property, GladeXmlContext * context, GladeXmlNode * node) { GladeXmlNode *prop_node; GladePropertyClass *pclass; gchar *value = NULL; glade_property_get (property, &value); if (value && value[0]) { pclass = glade_property_get_class (property); prop_node = glade_xml_node_new (context, GLADE_TAG_A11Y_ACTION); glade_xml_node_append_child (node, prop_node); glade_xml_node_set_property_string (prop_node, GLADE_TAG_A11Y_ACTION_NAME, &glade_property_class_id (pclass)[4]); glade_xml_node_set_property_string (prop_node, GLADE_TAG_A11Y_DESC, value); } }
static void glade_property_sync_impl (GladeProperty * property) { /* Heh, here are the many reasons not to * sync a property ;-) */ if (/* the class can be NULL during object, * construction this is just a temporary state */ property->priv->klass == NULL || /* optional properties that are disabled */ property->priv->enabled == FALSE || /* explicit "never sync" flag */ glade_property_class_get_ignore (property->priv->klass) || /* recursion guards */ property->priv->syncing >= property->priv->sync_tolerance || /* No widget owns this property yet */ property->priv->widget == NULL) return; /* Only the properties from widget->properties should affect the runtime widget. * (other properties may be used for convenience in the plugin). */ if ((glade_property_class_get_is_packing (property->priv->klass) && !glade_widget_get_pack_property (property->priv->widget, glade_property_class_id (property->priv->klass))) || !glade_widget_get_property (property->priv->widget, glade_property_class_id (property->priv->klass))) return; property->priv->syncing++; /* In the case of construct_only, the widget instance must be rebuilt * to apply the property */ if (glade_property_class_get_construct_only (property->priv->klass) && property->priv->syncing == 1) { /* Virtual properties can be construct only, in which * case they are allowed to trigger a rebuild, and in * the process are allowed to get "synced" after the * instance is rebuilt. */ if (glade_property_class_get_virtual (property->priv->klass)) property->priv->sync_tolerance++; glade_widget_rebuild (property->priv->widget); if (glade_property_class_get_virtual (property->priv->klass)) property->priv->sync_tolerance--; } else if (glade_property_class_get_is_packing (property->priv->klass)) glade_widget_child_set_property (glade_widget_get_parent (property->priv->widget), property->priv->widget, glade_property_class_id (property->priv->klass), property->priv->value); else glade_widget_object_set_property (property->priv->widget, glade_property_class_id (property->priv->klass), property->priv->value); property->priv->syncing--; }
static gboolean glade_property_set_value_impl (GladeProperty * property, const GValue * value) { GladeProject *project = property->priv->widget ? glade_widget_get_project (property->priv->widget) : NULL; gboolean changed = FALSE; GValue old_value = { 0, }; gboolean warn_before, warn_after; #ifdef GLADE_ENABLE_DEBUG if (glade_get_debug_flags () & GLADE_DEBUG_PROPERTIES) { g_print ("PROPERTY: Setting %s property %s on %s ", glade_property_class_get_is_packing (property->priv->klass) ? "packing" : "normal", glade_property_class_id (property->priv->klass), property->priv->widget ? glade_widget_get_name (property->priv->widget) : "unknown"); gchar *str1 = glade_widget_adaptor_string_from_value (glade_property_class_get_adaptor (property->priv->klass), property->priv->klass, property->priv->value); gchar *str2 = glade_widget_adaptor_string_from_value (glade_property_class_get_adaptor (property->priv->klass), property->priv->klass, value); g_print ("from %s to %s\n", str1, str2); g_free (str1); g_free (str2); } #endif /* GLADE_ENABLE_DEBUG */ if (!g_value_type_compatible (G_VALUE_TYPE (property->priv->value), G_VALUE_TYPE (value))) { g_warning ("Trying to assign an incompatible value to property %s\n", glade_property_class_id (property->priv->klass)); return FALSE; } /* Check if the backend doesnt give us permission to * set this value. */ if (glade_property_superuser () == FALSE && property->priv->widget && project && glade_project_is_loading (project) == FALSE && glade_property_verify (property, value) == FALSE) { return FALSE; } /* save "changed" state. */ changed = !glade_property_equals_value (property, value); /* Add/Remove references from widget ref stacks here * (before assigning the value) */ if (property->priv->widget && changed && glade_property_class_is_object (property->priv->klass)) glade_property_update_prop_refs (property, property->priv->value, value); /* Check pre-changed warning state */ warn_before = glade_property_warn_usage (property); /* Make a copy of the old value */ g_value_init (&old_value, G_VALUE_TYPE (property->priv->value)); g_value_copy (property->priv->value, &old_value); /* Assign property first so that; if the object need be * rebuilt, it will reflect the new value */ g_value_reset (property->priv->value); g_value_copy (value, property->priv->value); GLADE_PROPERTY_GET_KLASS (property)->sync (property); glade_property_fix_state (property); if (changed && property->priv->widget) { g_signal_emit (G_OBJECT (property), glade_property_signals[VALUE_CHANGED], 0, &old_value, property->priv->value); glade_project_verify_property (property); /* Check post change warning state */ warn_after = glade_property_warn_usage (property); /* Update owning widget's warning state if need be */ if (property->priv->widget != NULL && warn_before != warn_after) glade_widget_verify (property->priv->widget); } /* Special case parentless widget properties */ if (glade_property_class_parentless_widget (property->priv->klass)) { GladeWidget *gobj; GObject *obj; if ((obj = g_value_get_object (&old_value)) && (gobj = glade_widget_get_from_gobject (obj))) glade_widget_show (gobj); if ((obj = g_value_get_object (value)) && (gobj = glade_widget_get_from_gobject (obj))) glade_widget_hide (gobj); } g_value_unset (&old_value); return TRUE; }
/** * glade_property_write: * @property: a #GladeProperty * @context: A #GladeXmlContext * @node: A #GladeXmlNode * * Write @property to @node */ void glade_property_write (GladeProperty * property, GladeXmlContext * context, GladeXmlNode * node) { GladeXmlNode *prop_node; gchar *name, *value; gboolean save_always; g_return_if_fail (GLADE_IS_PROPERTY (property)); g_return_if_fail (node != NULL); /* This code should work the same for <packing>, <widget> and <template> */ if (!(glade_xml_node_verify_silent (node, GLADE_XML_TAG_PACKING) || glade_xml_node_verify_silent (node, GLADE_XML_TAG_WIDGET) || glade_xml_node_verify_silent (node, GLADE_XML_TAG_TEMPLATE))) return; /* There can be a couple of reasons to forcefully save a property */ save_always = (glade_property_class_save_always (property->priv->klass) || property->priv->save_always); save_always = save_always || (glade_property_class_optional (property->priv->klass) && property->priv->enabled); /* Skip properties that are default by original pspec default * (excepting those that specified otherwise). */ if (!save_always && glade_property_original_default (property)) return; /* Escape our string and save with underscores */ name = g_strdup (glade_property_class_id (property->priv->klass)); glade_util_replace (name, '-', '_'); /* convert the value of this property to a string */ if (!(value = glade_widget_adaptor_string_from_value (glade_property_class_get_adaptor (property->priv->klass), property->priv->klass, property->priv->value))) /* make sure we keep the empty string, also... upcomming * funcs that may not like NULL. */ value = g_strdup (""); /* Now dump the node values... */ prop_node = glade_xml_node_new (context, GLADE_XML_TAG_PROPERTY); glade_xml_node_append_child (node, prop_node); /* Name and value */ glade_xml_node_set_property_string (prop_node, GLADE_XML_TAG_NAME, name); glade_xml_set_content (prop_node, value); /* i18n stuff */ if (glade_property_class_translatable (property->priv->klass)) { if (property->priv->i18n_translatable) glade_xml_node_set_property_string (prop_node, GLADE_TAG_TRANSLATABLE, GLADE_XML_TAG_I18N_TRUE); if (property->priv->i18n_context) glade_xml_node_set_property_string (prop_node, GLADE_TAG_CONTEXT, property->priv->i18n_context); if (property->priv->i18n_comment) glade_xml_node_set_property_string (prop_node, GLADE_TAG_COMMENT, property->priv->i18n_comment); } g_free (name); g_free (value); }