2008-03-03 Sven Herzberg <sven@imendio.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: Michael Dominic Kostrzewa <michael.kostrzewa@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 #include "hildon-bread-crumb.h"
27
28 static void hildon_bread_crumb_base_init (gpointer g_class);
29
30 GType
31 hildon_bread_crumb_get_type (void)
32 {
33   static GType bread_crumb_type = 0;
34
35   if (G_UNLIKELY (bread_crumb_type == 0))
36     {
37       const GTypeInfo bread_crumb_info =
38         {
39           sizeof (HildonBreadCrumbIface), /* class_size */
40           hildon_bread_crumb_base_init, /* base_init */
41           NULL, /* base_finalize */
42           NULL,
43           NULL, /* class_finalize */
44           NULL, /* class_data */
45           0,
46           0,
47           NULL
48         };
49       
50       bread_crumb_type =
51         g_type_register_static (G_TYPE_INTERFACE, "HildonBreadCrumb",
52                                 &bread_crumb_info, 0);
53
54       g_type_interface_add_prerequisite (bread_crumb_type, GTK_TYPE_WIDGET);
55     }
56
57   return bread_crumb_type;
58 }
59
60 static void
61 hildon_bread_crumb_base_init (gpointer g_class)
62 {
63   static gboolean initialized = FALSE;
64
65   if (initialized == FALSE)
66     {
67       g_signal_new ("crumb-activated",
68                     HILDON_TYPE_BREAD_CRUMB,
69                     G_SIGNAL_RUN_LAST,
70                     G_STRUCT_OFFSET (HildonBreadCrumbIface, crumb_activated),
71                     NULL, NULL,
72                     g_cclosure_marshal_VOID__VOID,
73                     G_TYPE_NONE, 0);
74
75       initialized = TRUE;
76     }
77 }
78
79 /**
80  * hildon_bread_crumb_get_natural_size:
81  * @bread_crumb: A #HildonBreadCrumb
82  * @width: location to store the natural width request of the @bread_crumb
83  * @height: location to store the natural height request of the @bread_crumb
84  *
85  * Function to ask the @bread_crumb its preferred width and height requisition.
86  * Natural size is different to size_request in that it's not the minimum space
87  * the widget needs, but the ideal space it'd like to be allocated. For example,
88  * in the case of a label the natural size would be the width and height needed
89  * to show the full label without line breaks.
90  *
91  **/
92
93 void
94 hildon_bread_crumb_get_natural_size (HildonBreadCrumb *bread_crumb,
95                                      gint *width,
96                                      gint *height)
97 {
98   g_return_if_fail (HILDON_IS_BREAD_CRUMB (bread_crumb));
99
100   (* HILDON_BREAD_CRUMB_GET_IFACE (bread_crumb)->get_natural_size) (bread_crumb, width, height);
101 }
102
103 /**
104  * hildon_bread_crumb_activated:
105  * @bread_crumb: a #HildonBreadCrumb
106  *
107  * Emits the "crumb-activated" signal. The signal is meant to indicate that
108  * the user has interacted with the bread crumb.
109  **/
110
111 void
112 hildon_bread_crumb_activated (HildonBreadCrumb *bread_crumb)
113 {
114   g_return_if_fail (HILDON_IS_BREAD_CRUMB (bread_crumb));
115
116   g_signal_emit_by_name (bread_crumb, "crumb-activated");
117 }
118
119