2 * This file is a part of hildon
4 * Copyright (C) 2007 Nokia Corporation, all rights reserved.
6 * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
7 * Author: Xan Lopez <xan.lopez@nokia.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; version 2.1 of
12 * the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 #include "hildon-bread-crumb.h"
28 #define HILDON_BREAD_CRUMB_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), HILDON_TYPE_BREAD_CRUMB, HildonBreadCrumbPrivate))
30 struct _HildonBreadCrumbPrivate
37 gboolean show_separator;
55 static guint bread_crumb_item_signals[LAST_SIGNAL] = { 0 };
60 static void hildon_bread_crumb_finalize (GObject *object);
61 static void hildon_bread_crumb_set_property (GObject *object, guint prop_id,
62 const GValue *value, GParamSpec *pspec);
63 static void hildon_bread_crumb_get_property (GObject *object, guint prop_id,
64 GValue *value, GParamSpec *pspec);
66 G_DEFINE_TYPE (HildonBreadCrumb, hildon_bread_crumb, GTK_TYPE_BUTTON)
69 hildon_bread_crumb_class_init (HildonBreadCrumbClass *klass)
71 GObjectClass *gobject_class = (GObjectClass*)klass;
74 gobject_class->finalize = hildon_bread_crumb_finalize;
75 gobject_class->set_property = hildon_bread_crumb_set_property;
76 gobject_class->get_property = hildon_bread_crumb_get_property;
79 g_object_class_install_property (gobject_class,
81 g_param_spec_string ("text",
83 "Text displayed as the name of the item",
85 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
87 g_object_class_install_property (gobject_class,
89 g_param_spec_boolean ("show-separator",
91 "Show the separator attached to the item",
93 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
96 g_type_class_add_private (gobject_class, sizeof (HildonBreadCrumbPrivate));
100 hildon_bread_crumb_init (HildonBreadCrumb *item)
103 HildonBreadCrumbPrivate *priv = HILDON_BREAD_CRUMB_GET_PRIVATE (item);
107 hbox = gtk_hbox_new (FALSE, 6);
108 gtk_container_add (GTK_CONTAINER (item), hbox);
110 priv->arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
111 gtk_widget_set_name (priv->arrow, "hildon-bread-crumb-separator-arrow");
112 gtk_box_pack_start (GTK_BOX (hbox), priv->arrow, FALSE, FALSE, 0);
114 if (priv->show_separator)
115 gtk_widget_show (priv->arrow);
117 priv->label = gtk_label_new ("");
118 gtk_box_pack_start (GTK_BOX (hbox), priv->label, TRUE, TRUE, 0);
119 gtk_widget_show (priv->label);
121 gtk_widget_show (hbox);
125 hildon_bread_crumb_finalize (GObject *object)
127 HildonBreadCrumbPrivate *priv = HILDON_BREAD_CRUMB (object)->priv;
131 G_OBJECT_CLASS (hildon_bread_crumb_parent_class)->finalize (object);
135 hildon_bread_crumb_set_property (GObject *object, guint prop_id,
136 const GValue *value, GParamSpec *pspec)
138 HildonBreadCrumb *item = HILDON_BREAD_CRUMB (object);
143 hildon_bread_crumb_set_text (item, g_value_get_string (value));
145 case PROP_SHOW_SEPARATOR:
146 hildon_bread_crumb_set_show_separator (item, g_value_get_boolean (value));
149 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
155 hildon_bread_crumb_get_property (GObject *object, guint prop_id,
156 GValue *value, GParamSpec *pspec)
158 HildonBreadCrumb *item = HILDON_BREAD_CRUMB (object);
163 g_value_set_string (value, item->priv->text);
165 case PROP_SHOW_SEPARATOR:
166 g_value_set_boolean (value, item->priv->show_separator);
169 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
175 hildon_bread_crumb_set_text (HildonBreadCrumb *item,
178 HildonBreadCrumbPrivate *priv;
180 g_return_if_fail (HILDON_IS_BREAD_CRUMB (item));
187 priv->text = g_strdup (text);
189 gtk_label_set_label (GTK_LABEL (priv->label), text);
190 gtk_label_set_ellipsize (GTK_LABEL (item->priv->label),
191 PANGO_ELLIPSIZE_START);
192 gtk_widget_show (priv->label);
194 g_object_notify (G_OBJECT (item), "text");
198 hildon_bread_crumb_get_text (HildonBreadCrumb *item)
200 HildonBreadCrumbPrivate *priv;
202 g_return_val_if_fail (HILDON_IS_BREAD_CRUMB (item), NULL);
210 hildon_bread_crumb_set_show_separator (HildonBreadCrumb *item,
211 gboolean show_separator)
213 HildonBreadCrumbPrivate *priv;
215 g_return_if_fail (HILDON_IS_BREAD_CRUMB (item));
219 if (priv->show_separator == show_separator)
222 priv->show_separator = show_separator;
225 gtk_widget_show (priv->arrow);
227 gtk_widget_hide (priv->arrow);
229 g_object_notify (G_OBJECT (item), "show-separator");
233 hildon_bread_crumb_get_natural_size (HildonBreadCrumb *item,
235 gint *natural_height)
240 HildonBreadCrumbPrivate *priv;
242 g_return_if_fail (HILDON_IS_BREAD_CRUMB (item));
246 gtk_widget_size_request (GTK_WIDGET (item), &req);
248 *natural_width = req.width;
251 *natural_height = req.height;
252 /* Substract the size request of the label */
253 gtk_widget_size_request (priv->label, &req);
255 *natural_width -= req.width;
256 layout = gtk_widget_create_pango_layout (priv->label, priv->text);
257 pango_layout_get_size (layout, &width, &height);
260 *natural_width += PANGO_PIXELS (width);
263 *natural_width += GTK_CONTAINER (item)->border_width * 2;
266 *natural_height += GTK_CONTAINER (item)->border_width * 2;
270 hildon_bread_crumb_new (const gchar* text)
272 return GTK_WIDGET (g_object_new (HILDON_TYPE_BREAD_CRUMB,