Commit 279700e4 authored by Vincent Geddes's avatar Vincent Geddes

Renamed all icons.

        * plugins/gtk+/icons/*, plugins/gnome/icons/*: Renamed all icons.

        * gladeui/glade-project-view.c, gladeui/glade-widget-adaptor.[ch],
          gladeui/glade-palette-item.c, gladeui/glade-clipboard-view.c:
          Use GtkIconTheme for loading and managing widget icons.
          New "icon-name" property on GladeWidgetAdaptor.

        * gladeui/glade-catalog: Added catalog property "icon-prefix". The
          default value of this property is set to the catalog name.

        * gladeui/glade-app.c: Add GtkIconTheme search path for widget icons.

        * plugins/gtk+/icons/16x16/Makefile.am,
          plugins/gtk+/icons/22x22/Makefile.am,
          plugins/gnome/icons/16x16/Makefile.am,
          plugins/gnome/icons/22x22/Makefile.am: Renamed icon files.

        * gladeui/glade-widget-adaptor.c: Use g_type_class_add_private().

        * doc/widgetclasses.sgml, doc/catalogintro.sgml: Update documentation.

svn path=/trunk/; revision=1237
parent 2ebf2703
2007-04-01 Vincent Geddes <vincent.geddes@gmail.com>
* plugins/gtk+/icons/*, plugins/gnome/icons/*: Renamed all icons.
* gladeui/glade-project-view.c, gladeui/glade-widget-adaptor.[ch],
gladeui/glade-palette-item.c, gladeui/glade-clipboard-view.c:
Use GtkIconTheme for loading and managing widget icons.
New "icon-name" property on GladeWidgetAdaptor.
* gladeui/glade-catalog: Added catalog property "icon-prefix". The
default value of this property is set to the catalog name.
* gladeui/glade-app.c: Add GtkIconTheme search path for widget icons.
* plugins/gtk+/icons/16x16/Makefile.am,
plugins/gtk+/icons/22x22/Makefile.am,
plugins/gnome/icons/16x16/Makefile.am,
plugins/gnome/icons/22x22/Makefile.am: Renamed icon files.
* gladeui/glade-widget-adaptor.c: Use g_type_class_add_private().
* doc/widgetclasses.sgml, doc/catalogintro.sgml: Update documentation.
2007-03-30 Vincent Geddes <vincent.geddes@gmail.com>
* src/main.c: Fix warnings when building on win32.
......
......@@ -63,12 +63,12 @@ library to use:
</para>
</refsect1>
<refsect2>
<refsect1>
<title>Toplevel catalog properties and tags</title>
<para>
When defining the catalog, the 'name' and 'library'
are both manditory properties of the 'glade-catalog' tag; optionally
you can also use 'depends' and 'domain'.
are both manditory attributes of the 'glade-catalog' tag; optionally
you can also use 'icon-prefix', 'depends' and 'domain'.
</para>
<variablelist>
......@@ -82,6 +82,16 @@ require it and to manage inter catalog dependencies.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>icon-prefix</term>
<listitem>
<para>
The 'icon-prefix' attribute is used to form icon names for widgets. This property defaults
to the value of the 'name' attribute.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>library</term>
......@@ -150,8 +160,8 @@ Your catalog's init-function will be called before any widget classes are instan
</listitem>
</varlistentry>
</variablelist>
</refsect2>
<refsect3>
</refsect1>
<refsect1>
<title>Validating and installing</title>
<para>
The DTD that is shipped with Glade can be used to validate your catalog
......@@ -171,5 +181,5 @@ The icons for palette etc go into the pixmap directory:
The plugin library should be installed into the modules directory:
<programlisting>pkg-config --variable=moduledir gladeui-1.0</programlisting>
</para>
</refsect3>
</refsect1>
</refentry>
......@@ -6,7 +6,7 @@
<refnamediv>
<refname>Widget Classes</refname>
<refpurpose>
How to augment or define a #GladeWidgetClass
Adding support for custom widgets
</refpurpose>
</refnamediv>
......@@ -50,7 +50,8 @@ To delve further into details; the complex layout looks like this:
</para>
</refsect1>
<refsect2>
<refsect1>
<title>Widget Class Parameters</title>
<variablelist>
<varlistentry>
......@@ -81,9 +82,20 @@ a process that could lead to unexpected results.
<term>generic-name</term>
<listitem>
<para>
The 'generic-name' property is used to get the icon name for the widget palette
and is a regular icon theme icon. The generic name is also used to generate
a default name for instances of the widget in the UI editor.
The 'generic-name' is used to generate a default name for instances of the
widget in the UI editor. It is also used in conjunction with the 'icon-prefix'
to form an icon name for the widget.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>icon-name</term>
<listitem>
<para>
The 'icon-name' property is used to explicitly set an icon name for this widget.
These icon names are looked up in the current icon theme to retrieve an icon for
the widget.
</para>
</listitem>
</varlistentry>
......@@ -143,8 +155,31 @@ your application via libglade.
</varlistentry>
</variablelist>
</refsect2>
<refsect3>
</refsect1>
<refsect1>
<title>Icons</title>
<para>The Glade palette and other components use icons to represent the various widget classes.
It is a good idea to provide icons for your widget classes, as this
enhances the user interface.</para>
<para>Glade uses the GTK+ GtkIconTheme facility to provide icons for widget classes. Any icon
available in the current icon theme can be used as an icon for a widget class.</para>
<para>By default, an icon name of the format "widget-CATALOG_NAME-GENERIC_NAME"
is assigned to every widget class. CATALOG_NAME is the value of catalog name attribute, and GENERIC_NAME is
the value of an widget class's generic name attribute.</para>
<para>To explicity set an icon name for a widget class, the "icon-name" attribute of the "glade-widget-class"
element can be specified. This will override the default icon name assigned to the widget class.</para>
<para>Icon files can be installed under any system icon theme folder, but we recommend
that you install them in glade's private icon theme folder:</para>
<programlisting>pkg-config --variable=pixmapdir gladeui-1.0</programlisting>
</refsect1>
<refsect1>
<title>Grouping widget classes in the catalog</title>
<para>
The widgets are groups in different groups in the Glade UI. Those groups
......@@ -160,5 +195,5 @@ are defined in the catalog file as follows:
</glade-widget-group>]]></programlisting>
The file should contain one or more widget groups.
</para>
</refsect3>
</refsect1>
</refentry>
......@@ -420,6 +420,9 @@ glade_app_init (GladeApp *app)
if (!initialized)
{
gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
GLADE_DATADIR G_DIR_SEPARATOR_S "pixmaps");
glade_cursor_init ();
glade_binding_load_all ();
......
......@@ -58,6 +58,8 @@ struct _GladeCatalog
gchar *book; /* Devhelp search domain
*/
gchar *icon_prefix; /* the prefix for icons */
GList *widget_groups; /* List of widget groups (palette) */
GList *adaptors; /* List of widget class adaptors (all) */
......@@ -174,9 +176,16 @@ catalog_open (const gchar *filename)
glade_xml_get_property_string (root, GLADE_TAG_DOMAIN);
catalog->book =
glade_xml_get_property_string (root, GLADE_TAG_BOOK);
catalog->icon_prefix =
glade_xml_get_property_string (root, GLADE_TAG_ICON_PREFIX);
catalog->init_function_name =
glade_xml_get_value_string (root, GLADE_TAG_INIT_FUNCTION);
/* catalog->icon_prefix defaults to catalog->name */
if (!catalog->icon_prefix)
catalog->icon_prefix = g_strdup (catalog->name);
if (catalog->init_function_name && catalog->language == NULL)
catalog_get_function (catalog, catalog->init_function_name,
(gpointer) &catalog->init_function);
......@@ -315,17 +324,21 @@ catalog_load_classes (GladeCatalog *catalog, GladeXmlNode *widgets_node)
node = glade_xml_node_get_children (widgets_node);
for (; node; node = glade_xml_node_next (node))
{
const gchar *node_name;
const gchar *node_name, *domain;
GladeWidgetAdaptor *adaptor;
node_name = glade_xml_node_get_name (node);
if (strcmp (node_name, GLADE_TAG_GLADE_WIDGET_CLASS) != 0)
continue;
adaptor = glade_widget_adaptor_from_catalog
(node, catalog->name, module,
catalog->domain ? catalog->domain : catalog->library,
catalog->book);
domain = catalog->domain ? catalog->domain : catalog->library;
adaptor = glade_widget_adaptor_from_catalog (node,
catalog->name,
catalog->icon_prefix,
module,
domain,
catalog->book);
catalog->adaptors = g_list_prepend (catalog->adaptors, adaptor);
}
......@@ -527,6 +540,9 @@ glade_catalog_free (GladeCatalog *catalog)
g_free (catalog->name);
if (catalog->book)
g_free (catalog->book);
if (catalog->icon_prefix)
g_free (catalog->icon_prefix);
for (list = catalog->adaptors; list; list = list->next)
g_object_unref (list->data);
......
......@@ -132,26 +132,22 @@ glade_clipboard_view_cell_function (GtkTreeViewColumn *tree_column,
{
gboolean is_icon = GPOINTER_TO_INT (data);
GladeWidget *widget;
GdkPixbuf *pixbuf = NULL;
gtk_tree_model_get (tree_model, iter, 0, &widget, -1);
g_return_if_fail (GLADE_IS_WIDGET (widget));
g_return_if_fail (widget->name != NULL);
g_object_get (widget->adaptor, "small-icon", &pixbuf, NULL);
g_return_if_fail (pixbuf != NULL);
if (is_icon)
g_object_set (G_OBJECT (cell),
"pixbuf", pixbuf,
"icon-name", widget->adaptor->icon_name,
"stock-size", GTK_ICON_SIZE_MENU,
NULL);
else
g_object_set (G_OBJECT (cell),
"text", widget->name,
NULL);
g_object_unref (pixbuf);
}
static gint
......
......@@ -2,10 +2,9 @@
/*
* glade-palette-item.c
*
* Copyright (C) 2006 The GNOME Foundation.
* Copyright (C) 2007 Vincent Geddes
*
* Authors:
* Vincent Geddes <vgeddes@metroweb.co.za>
* Authors: Vincent Geddes <vgeddes@metroweb.co.za>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -64,9 +63,6 @@ enum
};
static GtkToggleButton *parent_class = NULL;
G_DEFINE_TYPE(GladePaletteItem, glade_palette_item, GTK_TYPE_TOGGLE_BUTTON)
static void
......@@ -139,28 +135,37 @@ void
glade_palette_item_set_use_small_icon (GladePaletteItem *item, gboolean use_small_icon)
{
GladePaletteItemPrivate *priv;
GdkPixbuf *pixbuf = NULL;
g_return_if_fail (GLADE_IS_PALETTE_ITEM (item));
priv = GLADE_PALETTE_ITEM_GET_PRIVATE (item);
if (priv->use_small_icon != use_small_icon)
{
priv->use_small_icon = use_small_icon;
if (use_small_icon != FALSE)
g_object_get (priv->adaptor, "small-icon", &pixbuf, NULL);
gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon), priv->adaptor->icon_name, GTK_ICON_SIZE_MENU);
else
g_object_get (priv->adaptor, "large-icon", &pixbuf, NULL);
gtk_image_set_from_pixbuf (GTK_IMAGE (priv->icon), pixbuf);
g_object_unref (G_OBJECT (pixbuf));
gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon), priv->adaptor->icon_name, GTK_ICON_SIZE_BUTTON);
g_object_notify (G_OBJECT (item), "use-small-icon");
}
}
static void
glade_palette_set_adaptor (GladePaletteItem *item, GladeWidgetAdaptor *adaptor)
{
GladePaletteItemPrivate *priv;
priv = GLADE_PALETTE_ITEM_GET_PRIVATE (item);
priv->adaptor = adaptor;
gtk_label_set_text (GTK_LABEL (priv->label), adaptor->title);
gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon), adaptor->icon_name, GTK_ICON_SIZE_BUTTON);
}
static void
glade_palette_item_set_property (GObject *object,
guint prop_id,
......@@ -179,7 +184,7 @@ glade_palette_item_set_property (GObject *object,
switch (prop_id)
{
case PROP_ADAPTOR:
priv->adaptor = g_value_get_object (value);
glade_palette_set_adaptor (item, g_value_get_object (value));
break;
case PROP_APPEARANCE:
glade_palette_item_set_appearance (item, g_value_get_enum (value));
......@@ -242,12 +247,10 @@ glade_palette_item_class_init (GladePaletteItemClass *klass)
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->get_property = glade_palette_item_get_property;
object_class->set_property = glade_palette_item_set_property;
object_class->dispose = glade_palette_item_dispose;
object_class->dispose = glade_palette_item_dispose;
g_object_class_install_property (object_class,
PROP_ADAPTOR,
......@@ -274,7 +277,7 @@ glade_palette_item_class_init (GladePaletteItemClass *klass)
FALSE,
G_PARAM_READWRITE));
g_type_class_add_private (object_class, sizeof (GladePaletteItemPrivate));
g_type_class_add_private (klass, sizeof (GladePaletteItemPrivate));
}
......@@ -328,8 +331,6 @@ GtkWidget*
glade_palette_item_new (GladeWidgetAdaptor *adaptor)
{
GladePaletteItem *item;
GladePaletteItemPrivate *priv;
GdkPixbuf *pixbuf = NULL;
g_return_val_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor), NULL);
......@@ -338,20 +339,6 @@ glade_palette_item_new (GladeWidgetAdaptor *adaptor)
"appearance", GLADE_ITEM_ICON_ONLY,
NULL);
g_return_val_if_fail (item != NULL, NULL);
priv = GLADE_PALETTE_ITEM_GET_PRIVATE (item);
gtk_label_set_text (GTK_LABEL (priv->label), adaptor->title);
g_object_get (G_OBJECT (adaptor), "large-icon", &pixbuf, NULL);
if (pixbuf)
{
gtk_image_set_from_pixbuf (GTK_IMAGE (priv->icon), pixbuf);
g_object_unref (G_OBJECT (pixbuf));
} else
g_warning ("couldnt get an icon from adaptor %s\n", adaptor->name);
return GTK_WIDGET (item);
}
......
......@@ -616,7 +616,6 @@ glade_project_view_cell_function (GtkTreeViewColumn *tree_column,
gpointer data)
{
GPVCellType type = GPOINTER_TO_INT (data);
GdkPixbuf *small_icon = NULL;
GladeWidget *widget;
gchar *text = NULL, *child_type;
......@@ -629,13 +628,11 @@ glade_project_view_cell_function (GtkTreeViewColumn *tree_column,
g_return_if_fail (widget->adaptor != NULL);
g_return_if_fail (widget->adaptor->name != NULL);
g_object_get (widget->adaptor, "small-icon", &small_icon, NULL);
g_return_if_fail (small_icon != NULL);
switch (type)
{
case CELL_ICON:
g_object_set (G_OBJECT (cell), "pixbuf", small_icon, NULL);
g_object_set (G_OBJECT (cell), "icon-name", widget->adaptor->icon_name, NULL);
g_object_set (G_OBJECT (cell), "stock-size", GTK_ICON_SIZE_MENU, NULL);
break;
case CELL_NAME:
g_object_set (G_OBJECT (cell), "text", widget->name, NULL);
......@@ -655,8 +652,6 @@ glade_project_view_cell_function (GtkTreeViewColumn *tree_column,
default:
break;
}
g_object_unref (small_icon);
}
static void
......
......@@ -40,12 +40,12 @@
#include <gmodule.h>
#include <ctype.h>
#define LARGE_ICON_SUBDIR "22x22"
#define LARGE_ICON_SIZE 22
#define SMALL_ICON_SUBDIR "16x16"
#define SMALL_ICON_SIZE 16
#define DEFAULT_ICON_NAME "widget-gtk-frame"
struct _GladeWidgetAdaptorPriv {
#define GLADE_WIDGET_ADAPTOR_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), GLADE_TYPE_WIDGET_ADAPTOR, GladeWidgetAdaptorPrivate))
struct _GladeWidgetAdaptorPrivate {
gchar *catalog; /* The name of the widget catalog this class
* was declared by.
......@@ -54,9 +54,6 @@ struct _GladeWidgetAdaptorPriv {
gchar *book; /* DevHelp search namespace for this widget class
*/
GdkPixbuf *large_icon; /* The 22x22 icon for the widget */
GdkPixbuf *small_icon; /* The 16x16 icon for the widget */
GdkCursor *cursor; /* a cursor for inserting widgets */
gchar *special_child_type; /* Special case code for children that
......@@ -76,11 +73,10 @@ enum {
PROP_TYPE,
PROP_TITLE,
PROP_GENERIC_NAME,
PROP_ICON_NAME,
PROP_CATALOG,
PROP_BOOK,
PROP_SPECIAL_TYPE,
PROP_SMALL_ICON,
PROP_LARGE_ICON,
PROP_CURSOR
};
......@@ -154,106 +150,13 @@ gwa_properties_set_weight (GList **properties, GType parent)
}
}
static void
gwa_load_icons (GladeWidgetAdaptor *adaptor)
{
GError *error = NULL;
gchar *icon_path;
/* only certain widget classes need to have icons */
if (G_TYPE_IS_INSTANTIATABLE (adaptor->type) == FALSE ||
G_TYPE_IS_ABSTRACT (adaptor->type) != FALSE ||
adaptor->generic_name == NULL)
return;
/* load large 22x22 icon */
icon_path = g_strdup_printf ("%s" G_DIR_SEPARATOR_S
LARGE_ICON_SUBDIR
G_DIR_SEPARATOR_S "%s.png",
glade_app_get_pixmaps_dir (),
adaptor->generic_name);
adaptor->priv->large_icon =
gdk_pixbuf_new_from_file_at_size (icon_path,
LARGE_ICON_SIZE,
LARGE_ICON_SIZE,
&error);
if (adaptor->priv->large_icon == NULL)
{
g_warning (_("Unable to load icon for %s (%s)"),
adaptor->name, error->message);
g_error_free (error);
error = NULL;
/* use stock missing icon */
adaptor->priv->large_icon =
gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
GTK_STOCK_MISSING_IMAGE,
LARGE_ICON_SIZE,
GTK_ICON_LOOKUP_USE_BUILTIN,
&error);
if (adaptor->priv->large_icon == NULL)
{
g_critical (_("Unable to load stock icon (%s)"),
error->message);
g_error_free (error);
error = NULL;
}
}
g_free (icon_path);
/* load small 16x16 icon */
icon_path = g_strdup_printf ("%s" G_DIR_SEPARATOR_S
SMALL_ICON_SUBDIR
G_DIR_SEPARATOR_S "%s.png",
glade_app_get_pixmaps_dir (),
adaptor->generic_name);
adaptor->priv->small_icon =
gdk_pixbuf_new_from_file_at_size (icon_path,
SMALL_ICON_SIZE,
SMALL_ICON_SIZE,
&error);
if (adaptor->priv->small_icon == NULL)
{
g_warning (_("Unable to load icon for %s (%s)"),
adaptor->name, error->message);
g_error_free (error);
error = NULL;
/* use stock missing icon */
adaptor->priv->small_icon =
gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
GTK_STOCK_MISSING_IMAGE,
SMALL_ICON_SIZE,
GTK_ICON_LOOKUP_USE_BUILTIN,
&error);
if (adaptor->priv->small_icon == NULL)
{
g_critical (_("Unable to load stock icon (%s)"),
error->message);
g_error_free (error);
error = NULL;
}
}
g_free (icon_path);
}
static void
gwa_create_cursor (GladeWidgetAdaptor *adaptor)
{
GdkPixbuf *tmp_pixbuf;
GdkPixbuf *tmp_pixbuf, *widget_pixbuf;
const GdkPixbuf *add_pixbuf;
GdkDisplay *display;
GError *error = NULL;
/* only certain widget classes need to have cursors */
if (G_TYPE_IS_INSTANTIATABLE (adaptor->type) == FALSE ||
......@@ -271,9 +174,28 @@ gwa_create_cursor (GladeWidgetAdaptor *adaptor)
tmp_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 32, 32);
gdk_pixbuf_fill (tmp_pixbuf, 0x00000000);
if (gtk_icon_theme_has_icon (gtk_icon_theme_get_default (), adaptor->icon_name))
{
widget_pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
adaptor->icon_name,
22,
0,
&error);
if (error) {
g_warning ("Could not load image data for named icon '%s': %s",
adaptor->icon_name,
error->message);
g_error_free (error);
return;
}
} else {
return;
}
/* composite pixbufs */
gdk_pixbuf_composite (adaptor->priv->large_icon, tmp_pixbuf,
gdk_pixbuf_composite (widget_pixbuf, tmp_pixbuf,
8, 8, 22, 22,
8, 8, 1, 1,
GDK_INTERP_NEAREST, 255);
......@@ -286,7 +208,8 @@ gwa_create_cursor (GladeWidgetAdaptor *adaptor)
adaptor->priv->cursor = gdk_cursor_new_from_pixbuf (display, tmp_pixbuf, 6, 6);
g_object_unref(tmp_pixbuf);
g_object_unref (tmp_pixbuf);
g_object_unref (widget_pixbuf);
}
......@@ -615,7 +538,9 @@ glade_widget_adaptor_constructor (GType type,
g_warning ("Adaptor created without a name");
/* Build decorations */
gwa_load_icons (adaptor);
if (!adaptor->icon_name) {
adaptor->icon_name = g_strdup ("gtk-missing-image");
}
gwa_create_cursor (adaptor);
/* Let it leek */
......@@ -710,15 +635,10 @@ glade_widget_adaptor_finalize (GObject *object)
if (adaptor->priv->cursor != NULL)
gdk_cursor_unref (adaptor->priv->cursor);
if (adaptor->priv->large_icon != NULL)
g_object_unref (G_OBJECT (adaptor->priv->large_icon));
if (adaptor->priv->small_icon != NULL)
g_object_unref (G_OBJECT (adaptor->priv->small_icon));
if (adaptor->name) g_free (adaptor->name);
if (adaptor->generic_name) g_free (adaptor->generic_name);
if (adaptor->title) g_free (adaptor->title);
if (adaptor->icon_name) g_free (adaptor->icon_name);
if (adaptor->actions) gwa_actions_free (adaptor->actions);
......@@ -743,6 +663,10 @@ glade_widget_adaptor_real_set_property (GObject *object,