예제 #1
0
static void
glade_gtk_tool_button_parse_finished (GladeProject * project,
                                      GladeWidget * widget)
{
  gchar *stock_str = NULL, *icon_name = NULL;
  gint stock_id = 0;
  GtkWidget *label_widget = NULL, *image_widget = NULL;

  glade_widget_property_get (widget, "stock-id", &stock_str);
  glade_widget_property_get (widget, "icon-name", &icon_name);
  glade_widget_property_get (widget, "icon-widget", &image_widget);
  glade_widget_property_get (widget, "label-widget", &label_widget);

  if (label_widget)
    glade_widget_property_set (widget, "custom-label", TRUE);
  else
    glade_widget_property_set (widget, "custom-label", FALSE);

  if (image_widget)
    glade_widget_property_set (widget, "image-mode", GLADE_TB_MODE_CUSTOM);
  else if (icon_name)
    glade_widget_property_set (widget, "image-mode", GLADE_TB_MODE_ICON);
  else if (stock_str)
    {
      /* Update the stock property */
      stock_id =
          glade_utils_enum_value_from_string (GLADE_TYPE_STOCK_IMAGE,
                                              stock_str);
      if (stock_id < 0)
        stock_id = 0;
      glade_widget_property_set (widget, "glade-stock", stock_id);

      glade_widget_property_set (widget, "image-mode", GLADE_TB_MODE_STOCK);
    }
  else
    glade_widget_property_set (widget, "image-mode", GLADE_TB_MODE_STOCK);
}
예제 #2
0
static void
glade_gtk_icon_factory_read_sources (GladeWidget *widget, GladeXmlNode *node)
{
  GladeIconSources *sources;
  GtkIconSource *source;
  GladeXmlNode *sources_node, *source_node;
  GValue *value;
  GList *list;
  gchar *current_icon_name = NULL;
  GdkPixbuf *pixbuf;

  if ((sources_node = glade_xml_search_child (node, GLADE_TAG_SOURCES)) == NULL)
    return;

  sources = glade_icon_sources_new ();

  /* Here we expect all icon sets to remain together in the list. */
  for (source_node = glade_xml_node_get_children (sources_node); source_node;
       source_node = glade_xml_node_next (source_node))
    {
      gchar *icon_name;
      gchar *str;

      if (!glade_xml_node_verify (source_node, GLADE_TAG_SOURCE))
        continue;

      if (!(icon_name =
            glade_xml_get_property_string_required (source_node,
                                                    GLADE_TAG_STOCK_ID, NULL)))
        continue;

      if (!
          (str =
           glade_xml_get_property_string_required (source_node,
                                                   GLADE_TAG_FILENAME, NULL)))
        {
          g_free (icon_name);
          continue;
        }

      if (!current_icon_name || strcmp (current_icon_name, icon_name) != 0)
        current_icon_name = (g_free (current_icon_name), g_strdup (icon_name));

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      source = gtk_icon_source_new ();
G_GNUC_END_IGNORE_DEPRECATIONS

      /* Deal with the filename... */
      value = glade_utils_value_from_string (GDK_TYPE_PIXBUF, str, glade_widget_get_project (widget));
      pixbuf = g_value_dup_object (value);
      g_value_unset (value);
      g_free (value);

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
      gtk_icon_source_set_pixbuf (source, pixbuf);
G_GNUC_END_IGNORE_DEPRECATIONS
      g_object_unref (G_OBJECT (pixbuf));
      g_free (str);

      /* Now the attributes... */
      if ((str =
           glade_xml_get_property_string (source_node,
                                          GLADE_TAG_DIRECTION)) != NULL)
        {
          GtkTextDirection direction =
              glade_utils_enum_value_from_string (GTK_TYPE_TEXT_DIRECTION, str);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
          gtk_icon_source_set_direction_wildcarded (source, FALSE);
          gtk_icon_source_set_direction (source, direction);
G_GNUC_END_IGNORE_DEPRECATIONS
          g_free (str);
        }

      if ((str =
           glade_xml_get_property_string (source_node, GLADE_TAG_SIZE)) != NULL)
        {
          GtkIconSize size =
              glade_utils_enum_value_from_string (GTK_TYPE_ICON_SIZE, str);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
          gtk_icon_source_set_size_wildcarded (source, FALSE);
          gtk_icon_source_set_size (source, size);
G_GNUC_END_IGNORE_DEPRECATIONS
          g_free (str);
        }

      if ((str =
           glade_xml_get_property_string (source_node,
                                          GLADE_TAG_STATE)) != NULL)
        {
          GtkStateType state =
              glade_utils_enum_value_from_string (GTK_TYPE_STATE_TYPE, str);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
          gtk_icon_source_set_state_wildcarded (source, FALSE);
          gtk_icon_source_set_state (source, state);
G_GNUC_END_IGNORE_DEPRECATIONS
          g_free (str);
        }

      if ((list =
           g_hash_table_lookup (sources->sources,
                                g_strdup (current_icon_name))) != NULL)
        {
          GList *new_list = g_list_append (list, source);

          /* Warning: if we use g_list_prepend() the returned pointer will be different
           * so we would have to replace the list pointer in the hash table.
           * But before doing that we have to steal the old list pointer otherwise
           * we would have to make a copy then add the new icon to finally replace the hash table
           * value.
           * Anyways if we choose to prepend we would have to reverse the list outside this loop
           * so its better to append.
           */
          if (new_list != list)
            {
              /* current g_list_append() returns the same pointer so this is not needed */
              g_hash_table_steal (sources->sources, current_icon_name);
              g_hash_table_insert (sources->sources,
                                   g_strdup (current_icon_name), new_list);
            }
        }
      else
        {
          list = g_list_append (NULL, source);
          g_hash_table_insert (sources->sources, g_strdup (current_icon_name),
                               list);
        }
    }

  if (g_hash_table_size (sources->sources) > 0)
    glade_widget_property_set (widget, "sources", sources);

  glade_icon_sources_free (sources);
}
예제 #3
0
GladeAttribute *
glade_gtk_attribute_from_string (PangoAttrType type, const gchar *strval)
{
  GladeAttribute *gattr;
  GdkColor color;

  gattr = g_new0 (GladeAttribute, 1);
  gattr->type = type;
  gattr->start = 0;
  gattr->end = G_MAXUINT;

  switch (type)
    {
      case PANGO_ATTR_LANGUAGE:
      case PANGO_ATTR_FAMILY:
      case PANGO_ATTR_FONT_DESC:
        g_value_init (&(gattr->value), G_TYPE_STRING);
        g_value_set_string (&(gattr->value), strval);
        break;

      case PANGO_ATTR_STYLE:
      case PANGO_ATTR_WEIGHT:
      case PANGO_ATTR_VARIANT:
      case PANGO_ATTR_STRETCH:
      case PANGO_ATTR_GRAVITY:
      case PANGO_ATTR_GRAVITY_HINT:

        /* Enums ... */
        g_value_init (&(gattr->value), type_from_attr_type (type));
        g_value_set_enum (&(gattr->value),
                          glade_utils_enum_value_from_string (type_from_attr_type (type), strval));
        break;

      case PANGO_ATTR_UNDERLINE:
      case PANGO_ATTR_STRIKETHROUGH:
        /* Booleans */
        g_value_init (&(gattr->value), G_TYPE_BOOLEAN);
        g_value_set_boolean (&(gattr->value), TRUE);
        break;

        /* PangoAttrSize */
      case PANGO_ATTR_SIZE:
      case PANGO_ATTR_ABSOLUTE_SIZE:
        /* ints */
        g_value_init (&(gattr->value), G_TYPE_INT);
        g_value_set_int (&(gattr->value), strtol (strval, NULL, 10));
        break;

        /* PangoAttrFloat */
      case PANGO_ATTR_SCALE:
        /* doubles */
        g_value_init (&(gattr->value), G_TYPE_DOUBLE);
        g_value_set_double (&(gattr->value), g_ascii_strtod (strval, NULL));
        break;

        /* PangoAttrColor */
      case PANGO_ATTR_FOREGROUND:
      case PANGO_ATTR_BACKGROUND:
      case PANGO_ATTR_UNDERLINE_COLOR:
      case PANGO_ATTR_STRIKETHROUGH_COLOR:
        /* boxed colours */
        if (gdk_color_parse (strval, &color))
          {
            g_value_init (&(gattr->value), GDK_TYPE_COLOR);
            g_value_set_boxed (&(gattr->value), &color);
          }
        else
          g_critical ("Unable to parse color attribute '%s'", strval);

        break;

        /* PangoAttrShape */
      case PANGO_ATTR_SHAPE:
        /* Unsupported for now */
        break;

      case PANGO_ATTR_INVALID:
      case PANGO_ATTR_LETTER_SPACING:
      case PANGO_ATTR_RISE:
      case PANGO_ATTR_FALLBACK:
      default:
        break;
    }

  return gattr;
}
예제 #4
0
static void
value_attribute_edited (GtkCellRendererText * cell,
                        const gchar * path,
                        const gchar * new_text, GladeEditorProperty * eprop)
{
  GladeEPropIconSources *eprop_sources = GLADE_EPROP_ICON_SOURCES (eprop);
  GladeProperty *property = glade_editor_property_get_property (eprop);
  GtkTreeIter iter;
  GladeIconSources *icon_sources = NULL;
  GtkIconSource *source;
  gchar *icon_name;
  gint index, edit_column;

  if (!new_text || !new_text[0])
    return;

  if (!gtk_tree_model_get_iter_from_string
      (GTK_TREE_MODEL (eprop_sources->store), &iter, path))
    return;

  edit_column =
      GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "attribute-column"));
  gtk_tree_model_get (GTK_TREE_MODEL (eprop_sources->store), &iter,
                      COLUMN_ICON_NAME, &icon_name, COLUMN_LIST_INDEX, &index,
                      -1);

  glade_property_get (property, &icon_sources);

  if (icon_sources)
    icon_sources = glade_icon_sources_copy (icon_sources);

  if (icon_sources &&
      (source = get_icon_source (icon_sources, icon_name, index)) != NULL)
    {
      GtkTextDirection direction;
      GtkIconSize size;
      GtkStateType state;

      switch (edit_column)
        {
          case COLUMN_DIRECTION:
            direction =
                glade_utils_enum_value_from_string (GTK_TYPE_TEXT_DIRECTION,
                                                    new_text);
            gtk_icon_source_set_direction (source, direction);
            break;
          case COLUMN_SIZE:
            size =
                glade_utils_enum_value_from_string (GTK_TYPE_ICON_SIZE,
                                                    new_text);
            gtk_icon_source_set_size (source, size);
            break;
          case COLUMN_STATE:
            state =
                glade_utils_enum_value_from_string (GTK_TYPE_STATE_TYPE,
                                                    new_text);
            gtk_icon_source_set_state (source, state);
            break;
          default:
            break;
        }

      update_icon_sources (eprop, icon_sources);
      g_free (icon_name);
      return;
    }

  if (icon_sources)
    glade_icon_sources_free (icon_sources);
  g_free (icon_name);
  return;
}