/*
* This file is part of hildon-libs
*
- * Copyright (C) 2005 Nokia Corporation.
+ * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
*
- * Contact: Luc Pionchon <luc.pionchon@nokia.com>
+ * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
+ * as published by the Free Software Foundation; version 2.1 of
+ * the License or any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
*
*/
-/*
- * @file hildon-grid-item.c
- *
- * This file contains the implementation of HildonGridItem.
- * HildonGridItem is an item mainly used in HildonGrid. It has an icon,
- * emblem and a label.
+/**
+ * SECTION:hildon-grid-item
+ * @short_description: Creating grid items used by #HildonGrid
+ * @see_also: #HildonGrid
*
+ * HildonGridItem is used to create grid items used by #HildonGrid. The
+ * grid item consists of an icon and a label. Based on the displaying
+ * mode employed by #HildonGrid, the label is justified to the right or
+ * the bottom.
*/
/*
enum{
PROP_NONE = 0,
- PROP_EMBLEM_TYPE
+ PROP_EMBLEM_TYPE,
+ PROP_ICON_BASENAME
};
/* Prototypes. */
case PROP_EMBLEM_TYPE:
hildon_grid_item_set_emblem_type(item, g_value_get_string(value));
break;
+ case PROP_ICON_BASENAME:
+ if(priv->icon_basename)
+ g_free(priv->icon_basename);
+
+ priv->icon_basename = g_strdup(g_value_get_string(value));
+ update_icon(item);
+
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
string = hildon_grid_item_get_emblem_type(item);
g_value_set_string(value, string);
break;
+ case PROP_ICON_BASENAME:
+ g_value_set_string(value, priv->icon_basename);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
"The emblem's basename",
NULL,
G_PARAM_WRITABLE));
+
+ g_object_class_install_property
+ (gobject_class,
+ PROP_ICON_BASENAME,
+ g_param_spec_string ("icon-basename",
+ "Icon Basename",
+ "The icon's basename",
+ NULL,
+ G_PARAM_WRITABLE));
}
priv->pending_icon_width = priv->icon_width = 64;
priv->pending_icon_height = priv->icon_height = 54;
priv->pending_label_height = priv->label_height = 30;
+
+
+ GTK_WIDGET_SET_FLAGS(GTK_WIDGET(item), GTK_CAN_FOCUS);
+
+ priv->label = gtk_label_new(NULL);
+ gtk_widget_set_name(priv->label, "hildon-grid-item-label");
+ gtk_widget_set_parent(priv->label, GTK_WIDGET(item));
+
+ update_icon(item);
+ set_label_justify(item);
+
+ gtk_widget_show(priv->label);
}
/**
* hildon_grid_item_new:
- * @icon_basename: Icon base name
+ * @icon_basename: icon base name
*
* Creates a new #HildonGridItem.
*
- * Return value: A new #HildonGridItem
+ * Returns: a new #HildonGridItem
*/
GtkWidget *
hildon_grid_item_new(const gchar *icon_basename)
{
HildonGridItem *item;
- HildonGridItemPrivate *priv;
-
- item = g_object_new(HILDON_TYPE_GRID_ITEM, NULL);
- GTK_WIDGET_SET_FLAGS(GTK_WIDGET(item), GTK_CAN_FOCUS);
- priv = HILDON_GRID_ITEM_GET_PRIVATE(item);
- priv->icon_basename = g_strdup(icon_basename);
-
- priv->label = gtk_label_new("");
- gtk_widget_set_parent(priv->label, GTK_WIDGET(item));
- gtk_widget_set_name(priv->label, "hildon-grid-item-label");
-
- update_icon(item);
- set_label_justify(item);
-
- gtk_widget_show(priv->label);
+ item = g_object_new(HILDON_TYPE_GRID_ITEM, "icon-basename", icon_basename, NULL);
return GTK_WIDGET(item);
}
/**
* hildon_grid_item_new_with_label:
- * @icon_basename: Icon base name
- * @label: Text label for icon
+ * @icon_basename: icon base name
+ * @label: text label for icon
*
- * Creates a new #HildonGridItem.
+ * Creates a new #HildonGridItem with a specified label for the icon.
*
- * Return value: A new #HildonGridItem
+ * Returns: a new #HildonGridItem
*/
GtkWidget *
hildon_grid_item_new_with_label(const gchar *icon_basename,
const gchar *label)
{
HildonGridItem *item;
- HildonGridItemPrivate *priv;
-
-
- item = g_object_new(HILDON_TYPE_GRID_ITEM, NULL);
- GTK_WIDGET_SET_FLAGS(GTK_WIDGET(item), GTK_CAN_FOCUS);
-
- priv = HILDON_GRID_ITEM_GET_PRIVATE(item);
- priv->icon_basename = g_strdup(icon_basename);
- priv->label = gtk_label_new(label != NULL ? label : "");
- gtk_widget_set_name(priv->label, "hildon-grid-item-label");
- gtk_widget_set_parent(priv->label, GTK_WIDGET(item));
+ item = g_object_new(HILDON_TYPE_GRID_ITEM, "icon-basename", icon_basename, NULL);
- update_icon(item);
- set_label_justify(item);
-
- gtk_widget_show(priv->label);
+ hildon_grid_item_set_label(item, label);
return GTK_WIDGET(item);
}
icon_theme = gtk_icon_theme_get_default();
- /* Load icon. Fall to default it loading fails. */
- error = NULL;
- icon = gtk_icon_theme_load_icon(icon_theme,
- priv->icon_basename,
- priv->icon_size, 0, &error);
- if (icon == NULL) {
- g_warning("Couldn't load icon \"%s\": %s", priv->icon_basename,
- error->message);
- g_error_free(error);
+ /* Load icon. Fall to default if loading fails. */
+ icon = NULL;
+ if (priv->icon_basename)
+ {
+ error = NULL;
+ icon = gtk_icon_theme_load_icon(icon_theme,
+ priv->icon_basename,
+ priv->icon_size, 0, &error);
+ if (icon == NULL) {
+ g_warning("Couldn't load icon \"%s\": %s", priv->icon_basename,
+ error->message);
+ g_error_free(error);
+ }
+ }
+ if (icon == NULL) {
error = NULL;
icon = gtk_icon_theme_load_icon(icon_theme,
DEFAULT_ICON_BASENAME,
}
void
-_hildon_grid_item_set_label(HildonGridItem *item, const gchar *label)
+hildon_grid_item_set_label(HildonGridItem *item, const gchar *label)
{
HildonGridItemPrivate *priv;
g_return_if_fail(HILDON_IS_GRID_ITEM(item));
+ if (label == NULL)
+ label = "";
+
priv = HILDON_GRID_ITEM_GET_PRIVATE(item);
- if ((priv->label == NULL && label == NULL) ||
- (priv->label != NULL && label != NULL &&
- strcmp((char *) priv->label, (char *) label) == 0)) {
- return;
- }
+ if (strcmp (gtk_label_get_label (GTK_LABEL (priv->label)), label) == 0)
+ return;
gtk_label_set_label(GTK_LABEL(priv->label), label);
}
focused = priv->icon;
}
+ /* Determine the coordinates and size of clip */
switch (priv->label_pos) {
case HILDON_GRID_ITEM_LABEL_POS_BOTTOM:
clip.x = focused->allocation.x - priv->focus_margin;
break;
}
+ /* Build painting box for the exposure event */
gtk_paint_box(focused->style,
gtk_widget_get_toplevel(focused)->window,
GTK_STATE_SELECTED,
l_req.width = l_req.height = 0;
}
+ /* Determine icon and label allocation based on label position */
switch (priv->label_pos) {
case HILDON_GRID_ITEM_LABEL_POS_BOTTOM:
i_alloc.x = (allocation->width - priv->icon_width) / 2 +
item = HILDON_GRID_ITEM(container);
priv = HILDON_GRID_ITEM_GET_PRIVATE(item);
+ /* Connect callback functions to the item */
if (priv->icon != NULL) {
(*callback) (priv->icon, callback_data);
}
/**
* hildon_grid_item_set_emblem_type:
* @item: #HildonGridItem
- * @emblem_basename: Emblem's basename
+ * @emblem_basename: emblem's basename
*
* Sets item emblem type.
*/
* hildon_grid_item_get_emblem_type:
* @item: #HildonGridItem
*
- * Returns emblem's basename. Must not be changed or freed.
- *
- * Return value: Emblem's basename
+ * Returns: emblem's basename. Must not be changed or freed.
*/
const gchar *
hildon_grid_item_get_emblem_type(HildonGridItem *item)