2008-12-11 Claudio Saavedra <csaavedra@igalia.com>
[hildon] / src / hildon-bread-crumb.c
1 /*
2  * This file is a part of hildon
3  *
4  * Copyright (C) 2007 Nokia Corporation, all rights reserved.
5  *
6  * Contact: Rodrigo Novo <rodrigo.novo@nokia.com>
7  * Author: Xan Lopez <xan.lopez@nokia.com>
8  *
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.
13  *
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.
18  *
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
22  * 02110-1301 USA
23  *
24  */
25
26 /**
27  * SECTION:hildon-bread-crumb
28  * @short_description: Interface for elements in a #HildonBreadCrumbTrail
29  *
30  * #HildonBreadCrumb is an interface for creating new types of items
31  * for the #HildonBreadCrumbTrail widget.
32  */
33
34 #undef HILDON_DISABLE_DEPRECATED
35
36 #include "hildon-bread-crumb.h"
37
38 static void hildon_bread_crumb_base_init (gpointer g_class);
39
40 GType
41 hildon_bread_crumb_get_type (void)
42 {
43   static GType bread_crumb_type = 0;
44
45   if (G_UNLIKELY (bread_crumb_type == 0))
46     {
47       const GTypeInfo bread_crumb_info =
48         {
49           sizeof (HildonBreadCrumbIface), /* class_size */
50           hildon_bread_crumb_base_init, /* base_init */
51           NULL, /* base_finalize */
52           NULL,
53           NULL, /* class_finalize */
54           NULL, /* class_data */
55           0,
56           0,
57           NULL
58         };
59       
60       bread_crumb_type =
61         g_type_register_static (G_TYPE_INTERFACE, "HildonBreadCrumb",
62                                 &bread_crumb_info, 0);
63
64       g_type_interface_add_prerequisite (bread_crumb_type, GTK_TYPE_WIDGET);
65     }
66
67   return bread_crumb_type;
68 }
69
70 static void
71 hildon_bread_crumb_base_init (gpointer g_class)
72 {
73   static gboolean initialized = FALSE;
74
75   if (initialized == FALSE)
76     {
77       g_signal_new ("crumb-activated",
78                     HILDON_TYPE_BREAD_CRUMB,
79                     G_SIGNAL_RUN_LAST,
80                     G_STRUCT_OFFSET (HildonBreadCrumbIface, crumb_activated),
81                     NULL, NULL,
82                     g_cclosure_marshal_VOID__VOID,
83                     G_TYPE_NONE, 0);
84
85       initialized = TRUE;
86     }
87 }
88
89 /**
90  * hildon_bread_crumb_get_natural_size:
91  * @bread_crumb: A #HildonBreadCrumb
92  * @width: location to store the natural width request of the @bread_crumb
93  * @height: location to store the natural height request of the @bread_crumb
94  *
95  * Function to ask the @bread_crumb its preferred width and height requisition.
96  * Natural size is different to size_request in that it's not the minimum space
97  * the widget needs, but the ideal space it'd like to be allocated. For example,
98  * in the case of a label the natural size would be the width and height needed
99  * to show the full label without line breaks.
100  *
101  **/
102
103 void
104 hildon_bread_crumb_get_natural_size (HildonBreadCrumb *bread_crumb,
105                                      gint *width,
106                                      gint *height)
107 {
108   g_return_if_fail (HILDON_IS_BREAD_CRUMB (bread_crumb));
109
110   (* HILDON_BREAD_CRUMB_GET_IFACE (bread_crumb)->get_natural_size) (bread_crumb, width, height);
111 }
112
113 /**
114  * hildon_bread_crumb_activated:
115  * @bread_crumb: a #HildonBreadCrumb
116  *
117  * Emits the "crumb-activated" signal. The signal is meant to indicate that
118  * the user has interacted with the bread crumb.
119  **/
120
121 void
122 hildon_bread_crumb_activated (HildonBreadCrumb *bread_crumb)
123 {
124   g_return_if_fail (HILDON_IS_BREAD_CRUMB (bread_crumb));
125
126   g_signal_emit_by_name (bread_crumb, "crumb-activated");
127 }
128
129