2 * This file is a part of hildon
4 * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
6 * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; version 2.1 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 * SECTION:hildon-caption
27 * @short_description: A single-child container widget that precedes the
28 * contained widget with a field label and an optional icon.
30 * #HildonCaption is a single-child container widget that precedes the
31 * contained widget with a field label and an optional icon. It allows
32 * grouping of several controls together. When a captioned widget has focus,
33 * both widget and caption label are displayed with active focus.
40 #include "hildon-caption.h"
41 #include <gtk/gtkhbox.h>
42 #include <gtk/gtklabel.h>
43 #include <gtk/gtkimage.h>
44 #include <gtk/gtkentry.h>
45 #include <gtk/gtkcombo.h>
46 #include <gtk/gtkcombobox.h>
47 #include <gtk/gtkcomboboxentry.h>
48 #include <gtk/gtkoptionmenu.h>
49 #include <gtk/gtkmarshal.h>
50 #include <gtk/gtkalignment.h>
51 #include <gtk/gtkcheckbutton.h>
54 #include "hildon-defines.h"
56 #include "hildon-caption-private.h"
59 dgettext("hildon-libs", String)
61 #define HILDON_CAPTION_SPACING 6
63 static GtkEventBox* parent_class = NULL;
66 hildon_caption_class_init (HildonCaptionClass *caption_class);
69 hildon_caption_init (HildonCaption *caption);
72 hildon_caption_size_request (GtkWidget *widget,
73 GtkRequisition *requisition);
76 hildon_caption_size_allocate (GtkWidget *widget,
77 GtkAllocation *allocation);
80 hildon_caption_forall (GtkContainer *container,
81 gboolean include_internals,
86 hildon_caption_hierarchy_changed (GtkWidget *widget,
87 GtkWidget *previous_toplevel);
90 hildon_caption_set_focus (GtkWindow *window,
95 hildon_caption_grab_focus (GtkWidget *widget);
98 hildon_caption_activate (GtkWidget *widget);
101 hildon_caption_set_property (GObject *object,
107 hildon_caption_get_property (GObject *object,
113 hildon_caption_expose (GtkWidget *widget,
114 GdkEventExpose *event);
117 hildon_caption_destroy (GtkObject *self);
120 hildon_caption_button_press (GtkWidget *widget,
121 GdkEventButton *event);
124 hildon_caption_set_label_text (HildonCaptionPrivate *priv,
128 hildon_caption_set_child_property (GtkContainer *container,
135 hildon_caption_get_child_property (GtkContainer *container,
160 * hildon_caption_get_type:
162 * Initializes and returns the type of a hildon caption.
164 * @Returns: GType of #HildonCaption
167 hildon_caption_get_type (void)
169 static GType caption_type = 0;
173 static const GTypeInfo caption_info = {
174 sizeof (HildonCaptionClass),
175 NULL, /* base_init */
176 NULL, /* base_finalize */
177 (GClassInitFunc) hildon_caption_class_init,
178 NULL, /* class_finalize */
179 NULL, /* class_data */
180 sizeof (HildonCaption),
182 (GInstanceInitFunc) hildon_caption_init,
184 caption_type = g_type_register_static (GTK_TYPE_EVENT_BOX,
185 "HildonCaption", &caption_info, 0 );
191 * Initialises the caption class.
194 hildon_caption_class_init (HildonCaptionClass *caption_class)
196 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (caption_class);
197 GObjectClass *gobject_class = G_OBJECT_CLASS (caption_class);
198 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (caption_class);
200 parent_class = g_type_class_peek_parent (caption_class);
202 g_type_class_add_private (caption_class, sizeof (HildonCaptionPrivate));
204 /* Override virtual functions */
205 gobject_class->get_property = hildon_caption_get_property;
206 gobject_class->set_property = hildon_caption_set_property;
207 caption_class->activate = (gpointer) hildon_caption_activate;
208 GTK_OBJECT_CLASS(caption_class)->destroy = hildon_caption_destroy;
210 container_class->forall = hildon_caption_forall;
211 container_class->set_child_property = hildon_caption_set_child_property;
212 container_class->get_child_property = hildon_caption_get_child_property;
214 widget_class->expose_event = hildon_caption_expose;
215 widget_class->hierarchy_changed = hildon_caption_hierarchy_changed;
216 widget_class->size_request = hildon_caption_size_request;
217 widget_class->size_allocate = hildon_caption_size_allocate;
218 widget_class->button_press_event = hildon_caption_button_press;
219 widget_class->grab_focus = hildon_caption_grab_focus;
221 /* Create new signals and properties */
222 widget_class->activate_signal = g_signal_new ("activate",
223 G_OBJECT_CLASS_TYPE (
227 G_STRUCT_OFFSET (HildonCaptionClass,
228 activate), NULL, NULL,
229 gtk_marshal_VOID__VOID,
233 * HildonCaption:label:
237 g_object_class_install_property (gobject_class, PROP_LABEL,
238 g_param_spec_string ("label",
239 "Current label", "Caption label",
240 NULL, G_PARAM_READABLE | G_PARAM_WRITABLE) );
243 * HildonCaption:markup:
245 * Caption markup. Mutually exclusive with label.
247 g_object_class_install_property (gobject_class, PROP_MARKUP,
248 g_param_spec_string ("markup",
249 "Current markup", "Caption markup",
250 NULL, G_PARAM_WRITABLE) );
253 * HildonCaption:icon:
255 * The icon shown on the caption area.
257 g_object_class_install_property (gobject_class, PROP_ICON,
258 g_param_spec_object ("icon",
260 "The icon shown on the caption area",
261 GTK_TYPE_WIDGET, G_PARAM_READABLE |
264 * HildonCaption:status:
266 * Mandatory or optional status.
268 g_object_class_install_property (gobject_class, PROP_STATUS,
269 g_param_spec_enum ("status",
271 "Mandatory or optional status",
272 HILDON_TYPE_CAPTION_STATUS,
273 HILDON_CAPTION_OPTIONAL,
274 G_PARAM_READABLE | G_PARAM_WRITABLE) );
276 * HildonCaption:icon-position:
278 * If the icon is positioned on the left or right side.
280 g_object_class_install_property (gobject_class, PROP_ICON_POSITION,
281 g_param_spec_enum ("icon-position",
283 "If the icon is on the left or right side",
284 HILDON_TYPE_CAPTION_ICON_POSITION,
285 HILDON_CAPTION_POSITION_RIGHT,
286 G_PARAM_READABLE | G_PARAM_WRITABLE) );
289 * HildonCaption:size_group:
291 * Current size group the caption is in.
293 g_object_class_install_property (gobject_class, PROP_SIZE_GROUP,
294 g_param_spec_object ("size_group",
295 "Current size group",
296 "Current size group the caption is in",
297 GTK_TYPE_SIZE_GROUP, G_PARAM_READABLE |
301 * HildonCaption:separator:
303 * The current separator.
305 g_object_class_install_property (gobject_class, PROP_SEPARATOR,
306 g_param_spec_string ("separator",
307 "Current separator", "Current separator",
308 _("ecdg_ti_caption_separator"),
309 G_PARAM_READABLE | G_PARAM_WRITABLE) );
311 /* Create child properties. These are related to
312 child <-> parent relationship, not to either of objects itself */
313 gtk_container_class_install_child_property (container_class,
315 g_param_spec_boolean ("expand",
316 "Same as GtkBox expand.",
317 "Same as GtkBox expand. Wheter the child should be expanded or not.",
322 /* Destroy can be called multiple times, remember to set pointers to NULL */
324 hildon_caption_destroy (GtkObject *self)
326 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (self);
328 /* Free our internal child */
329 if (priv && priv->caption_area)
331 gtk_widget_unparent (priv->caption_area);
332 priv->caption_area = NULL;
335 /* Free user provided strings */
336 if (priv && priv->text)
342 if (priv && priv->separator)
344 g_free (priv->separator);
345 priv->separator = NULL;
348 /* Parent classes destroy takes care of user packed contents */
349 if (GTK_OBJECT_CLASS (parent_class)->destroy)
350 GTK_OBJECT_CLASS (parent_class)->destroy (self);
353 /* Parent, eventbox will run allocate also for the child which may be
354 * owning a window too. This window is then moved and resized
355 * and we do not want to do that (it causes flickering).
358 hildon_caption_expose (GtkWidget *widget,
359 GdkEventExpose *event)
361 HildonCaptionPrivate *priv = NULL;
366 g_assert (HILDON_IS_CAPTION (widget));
367 priv = HILDON_CAPTION_GET_PRIVATE (widget);
370 if (! GTK_WIDGET_DRAWABLE (widget))
373 GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
375 /* If our child control is focused, we draw nice looking focus
376 graphics for the caption */
377 if (priv->is_focused && priv->text)
379 /* Determine focus box dimensions */
380 gtk_widget_get_child_requisition (priv->caption_area, &req);
381 align = hildon_caption_get_label_alignment (HILDON_CAPTION(widget));
383 alloc.width = priv->caption_area->allocation.width + HILDON_CAPTION_SPACING;
384 alloc.height = MIN (req.height + (2 * widget->style->ythickness), priv->caption_area->allocation.height);
386 alloc.x = priv->caption_area->allocation.x - HILDON_CAPTION_SPACING; /* - left margin */
387 alloc.y = priv->caption_area->allocation.y +
388 MAX (((priv->caption_area->allocation.height - alloc.height) * align), 0);
390 /* Paint the focus box */
391 gtk_paint_box (widget->style, widget->window, GTK_STATE_ACTIVE,
392 GTK_SHADOW_OUT, NULL, widget, "selection",
393 alloc.x, alloc.y, alloc.width, alloc.height);
395 /* Paint caption contents on top of the focus box */
396 GTK_WIDGET_GET_CLASS (priv->caption_area)->expose_event (priv->caption_area, event);
403 hildon_caption_set_property (GObject *object,
408 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (object);
413 case PROP_ICON_POSITION:
414 hildon_caption_set_icon_position (HILDON_CAPTION (object), g_value_get_enum (value));
418 /* Free old label string */
426 priv->text = g_value_dup_string (value);
427 hildon_caption_set_label_text (priv, FALSE);
431 /* Free old label string */
439 priv->text = g_value_dup_string (value);
440 hildon_caption_set_label_text (priv, TRUE);
444 /* Remove old icon */
446 gtk_container_remove (GTK_CONTAINER (priv->icon_align), priv->icon);
448 /* Pack and display new icon */
449 priv->icon = g_value_get_object (value);
452 gtk_container_add (GTK_CONTAINER (priv->icon_align), priv->icon);
453 gtk_widget_show_all (priv->caption_area);
458 priv->status = g_value_get_enum (value);
461 case PROP_SIZE_GROUP:
462 /* Detach from previous size group */
464 gtk_size_group_remove_widget (priv->group, priv->caption_area);
466 priv->group = g_value_get_object (value);
468 /* Attach to new size group */
470 gtk_size_group_add_widget (priv->group, priv->caption_area);
472 gtk_widget_queue_draw (GTK_WIDGET(object));
477 /* Free old separator */
480 g_free (priv->separator);
481 priv->separator = NULL;
484 priv->separator = g_value_dup_string (value);
485 hildon_caption_set_label_text (priv, FALSE);
489 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
495 hildon_caption_get_property (GObject *object,
500 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (object);
505 g_value_set_string (value, priv->text);
509 g_value_set_object (value, priv->icon);
513 g_value_set_enum (value, priv->status);
516 case PROP_ICON_POSITION:
517 g_value_set_enum (value, priv->icon_position);
520 case PROP_SIZE_GROUP:
521 g_value_set_object (value, priv->group);
525 g_value_set_string (value, priv->separator);
529 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
535 hildon_caption_set_child_property (GtkContainer *container,
543 case CHILD_PROP_EXPAND:
544 hildon_caption_set_child_expand (HILDON_CAPTION (container),
545 g_value_get_boolean (value));
549 G_OBJECT_WARN_INVALID_PROPERTY_ID (container, property_id, pspec);
555 hildon_caption_get_child_property (GtkContainer *container,
563 case CHILD_PROP_EXPAND:
564 g_value_set_boolean (value, hildon_caption_get_child_expand(
565 HILDON_CAPTION (container)));
569 G_OBJECT_WARN_INVALID_PROPERTY_ID(container, property_id, pspec);
574 /* We want to activate out child control on button press */
576 hildon_caption_button_press (GtkWidget *widget,
577 GdkEventButton *event)
579 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (widget);
582 priv->is_focused = TRUE;
583 gtk_widget_grab_focus (GTK_BIN (widget)->child);
589 hildon_caption_init (HildonCaption *caption)
591 HildonCaptionPrivate *priv = NULL;
593 /* Initialize startup state */
594 priv = HILDON_CAPTION_GET_PRIVATE (caption);
597 priv->status = HILDON_CAPTION_OPTIONAL;
600 priv->is_focused = FALSE;
603 priv->separator = g_strdup(_("ecdg_ti_caption_separator"));
605 gtk_widget_push_composite_child();
607 /* Create caption text */
608 priv->caption_area = gtk_hbox_new (FALSE, HILDON_CAPTION_SPACING);
609 priv->label = gtk_label_new (NULL);
610 priv->icon_align = gtk_alignment_new (0.5f, 0.5f, 0.0f, 0.0f);
611 priv->icon_position = HILDON_CAPTION_POSITION_RIGHT;
613 /* We want to receive button presses for child widget activation */
614 gtk_event_box_set_above_child (GTK_EVENT_BOX (caption), FALSE);
615 gtk_widget_add_events (GTK_WIDGET (caption), GDK_BUTTON_PRESS_MASK);
617 /* Pack text label caption layout */
618 gtk_box_pack_end (GTK_BOX (priv->caption_area), priv->icon_align, FALSE, FALSE, 0);
619 gtk_box_pack_end (GTK_BOX (priv->caption_area), priv->label, FALSE, FALSE, 0);
620 gtk_widget_set_parent (priv->caption_area, GTK_WIDGET (caption));
622 gtk_widget_pop_composite_child ();
624 hildon_caption_set_child_expand (caption, TRUE);
626 gtk_widget_show_all (priv->caption_area);
630 hildon_caption_set_focus (GtkWindow *window,
634 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (caption);
637 /* check if ancestor gone */
643 /* Try to find caption among the ancestors of widget */
644 if (gtk_widget_is_ancestor (widget, caption))
646 priv->is_focused = TRUE;
647 gtk_widget_queue_draw (caption);
651 if (priv->is_focused == TRUE)
653 /* Caption wasn't found, so cannot focus */
654 priv->is_focused = FALSE;
655 gtk_widget_queue_draw (caption);
659 /* We need to connect/disconnect signal handlers to toplevel window
660 in which we reside. Ww want to update connected signals if our
663 hildon_caption_hierarchy_changed (GtkWidget *widget,
664 GtkWidget *previous_toplevel)
666 GtkWidget *current_ancestor;
667 HildonCaptionPrivate *priv;
669 priv = HILDON_CAPTION_GET_PRIVATE (widget);
672 if (GTK_WIDGET_CLASS (parent_class)->hierarchy_changed)
673 GTK_WIDGET_CLASS (parent_class)->hierarchy_changed (widget, previous_toplevel);
675 /* If we already were inside a window, remove old handler */
676 if (previous_toplevel) {
677 /* This is a compilation workaround for gcc > 3.3 since glib is buggy */
678 /* see http://bugzilla.gnome.org/show_bug.cgi?id=310175 */
682 g_signal_handlers_disconnect_by_func
683 (previous_toplevel, (gpointer) hildon_caption_set_focus, widget);
686 current_ancestor = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
688 /* Install new handler for focus movement */
689 if (current_ancestor)
690 g_signal_connect( current_ancestor, "set-focus",
691 G_CALLBACK (hildon_caption_set_focus), widget );
695 hildon_caption_size_request (GtkWidget *widget,
696 GtkRequisition *requisition)
699 HildonCaptionPrivate *priv = NULL;
700 g_return_if_fail (HILDON_IS_CAPTION(widget));
702 priv = HILDON_CAPTION_GET_PRIVATE (widget);
705 /* Use the same size requisition for the main box of the caption */
706 gtk_widget_size_request (priv->caption_area, &req);
708 if (GTK_WIDGET_CLASS (parent_class)->size_request)
709 GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition);
711 requisition->width += req.width + HILDON_CAPTION_SPACING * 3;
713 if ((req.height + (2 * widget->style->ythickness)) > requisition->height)
714 requisition->height = req.height + (2 * widget->style->ythickness);
717 /* We use HILDON_CAPTION_SPACING to make it look a bit nicer */
719 hildon_caption_size_allocate (GtkWidget *widget,
720 GtkAllocation *allocation)
722 GtkAllocation child_alloc;
723 GtkAllocation caption_alloc;
725 GtkWidget *child = NULL;
726 HildonCaptionPrivate *priv = NULL;
728 g_assert (HILDON_IS_CAPTION (widget));
729 priv = HILDON_CAPTION_GET_PRIVATE (widget);
732 /* Position the caption to its allocated location */
733 if (GTK_WIDGET_REALIZED (widget))
734 gdk_window_move_resize (widget->window,
735 allocation->x + GTK_CONTAINER (widget)->border_width,
736 allocation->y + GTK_CONTAINER (widget)->border_width,
737 MAX (allocation->width - GTK_CONTAINER (widget)->border_width * 2, 0),
738 MAX (allocation->height - GTK_CONTAINER (widget)->border_width * 2, 0));
740 child = GTK_BIN (widget)->child;
742 widget->allocation = *allocation;
743 gtk_widget_get_child_requisition (priv->caption_area, &req);
745 child_alloc.height = caption_alloc.height = allocation->height;
746 child_alloc.width = caption_alloc.width = allocation->width;
747 child_alloc.x = caption_alloc.x = caption_alloc.y = child_alloc.y = 0;
749 /* Center the captioned widget */
750 if (child_alloc.width > req.width + HILDON_CAPTION_SPACING)
752 child_alloc.x += req.width + HILDON_CAPTION_SPACING * 2;
753 caption_alloc.width = req.width;
756 /* Leave at least the space of the HILDON_CAPTION_SPACING in the left */
757 caption_alloc.x = HILDON_CAPTION_SPACING;
759 /* Leave room for the other drawable parts of the caption control */
760 child_alloc.width -= req.width + HILDON_CAPTION_SPACING * 2;
762 /* Give the child at least its minimum requisition, unless it is expandable */
763 if (! priv->expand && child && GTK_WIDGET_VISIBLE(child))
765 GtkRequisition child_req;
766 gtk_widget_get_child_requisition (child, &child_req);
767 child_alloc.width = MIN (child_alloc.width, child_req.width);
768 child_alloc.height = MIN (child_alloc.height, child_req.height);
769 /* Center the child */
770 child_alloc.y = (allocation->height - child_alloc.height -
771 2 * GTK_CONTAINER (widget)->border_width)/2;
774 /* Ensure there are no negative dimensions */
775 if (child_alloc.width < 0)
777 caption_alloc.width = req.width + child_alloc.width;
778 child_alloc.width = 0;
779 caption_alloc.width = MAX (caption_alloc.width, 0);
782 child_alloc.height = MAX (child_alloc.height, 0);
783 caption_alloc.height = MAX (caption_alloc.height, 0);
785 if (child && GTK_WIDGET_VISIBLE(child) )
786 gtk_widget_size_allocate (child, &child_alloc );
788 gtk_widget_size_allocate (priv->caption_area, &caption_alloc);
792 hildon_caption_forall (GtkContainer *container,
793 gboolean include_internals,
794 GtkCallback callback,
797 HildonCaptionPrivate *priv = NULL;
799 g_assert (HILDON_IS_CAPTION (container));
800 g_assert (callback != NULL);
802 priv = HILDON_CAPTION_GET_PRIVATE (container);
805 /* Execute callback for the child widgets */
806 if (GTK_CONTAINER_CLASS (parent_class)->forall)
807 GTK_CONTAINER_CLASS (parent_class)->forall (container, include_internals, callback, data);
809 if (include_internals)
810 /* Execute callback for the parent box as well */
811 (*callback) (priv->caption_area, data);
815 * hildon_caption_set_size_group:
816 * @caption : a #HildonCaption
817 * @new_group : a #GtkSizeGroup
819 * Sets a #GtkSizeGroup of a given captioned control.
823 hildon_caption_set_size_group (const HildonCaption *self,
826 g_object_set (G_OBJECT(self), "size_group", group, NULL);
830 * hildon_caption_get_size_group:
831 * @caption : a #HildonCaption
833 * Query given captioned control for the #GtkSizeGroup assigned to it.
835 * @Returns : a #GtkSizeGroup
839 hildon_caption_get_size_group (const HildonCaption *self)
841 HildonCaptionPrivate *priv;
842 g_return_val_if_fail (HILDON_IS_CAPTION (self), NULL);
844 priv = HILDON_CAPTION_GET_PRIVATE(self);
851 * hildon_caption_new:
852 * @group : a #GtkSizeGroup for controlling the size of related captions,
854 * @value : the caption text to accompany the text entry. The widget makes
855 * a copy of this text.
856 * @control : the control that is to be captioned
857 * @icon : an icon to accompany the label - can be NULL in which case no
859 * @flag : indicates whether this captioned control is mandatory or
862 * Creates a new instance of hildon_caption widget, with a specific
864 * Note: Clicking on a focused caption will trigger the activate signal.
865 * The default behaviour for the caption's activate signal is to call
866 * gtk_widget_activate on it's control.
868 * @Returns : a #GtkWidget pointer of Caption
871 hildon_caption_new (GtkSizeGroup *group,
875 HildonCaptionStatus flag)
878 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
880 widget = g_object_new (HILDON_TYPE_CAPTION,
888 /* Do not expand GtkCheckButton by default, we want to reduce its activation area */
889 if (GTK_IS_CHECK_BUTTON (child))
890 hildon_caption_set_child_expand (HILDON_CAPTION (widget), FALSE);
896 * hildon_caption_is_mandatory:
897 * @caption : a #HildonCaption
899 * Query #HildonCaption whether this captioned control is a mandatory one.
901 * @Returns : is this captioned control a mandatory one?
904 hildon_caption_is_mandatory (const HildonCaption *caption)
906 HildonCaptionPrivate *priv;
908 g_return_val_if_fail (HILDON_IS_CAPTION (caption), FALSE);
910 priv = HILDON_CAPTION_GET_PRIVATE (caption);
913 return (priv->status == HILDON_CAPTION_MANDATORY);
917 * hildon_caption_set_icon_position:
918 * @caption : a #HildonCaption
919 * @pos : one of the values from #HildonCaptionIconPosition
921 * Sets #HildonCaption icon position.
925 hildon_caption_set_icon_position (HildonCaption *caption,
926 HildonCaptionIconPosition pos)
928 g_return_if_fail (HILDON_IS_CAPTION (caption));
929 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (caption);
932 g_return_if_fail (priv->caption_area != NULL);
934 int order = (pos == HILDON_CAPTION_POSITION_LEFT) ? -1 : 0;
935 gtk_box_reorder_child (GTK_BOX (priv->caption_area), priv->icon_align, order);
937 priv->icon_position = pos;
941 * hildon_caption_get_icon_position:
942 * @caption : a #HildonCaption
944 * Gets #HildonCaption icon position.
946 * @Returns : one of the values from #HildonCaptionIconPosition.
950 HildonCaptionIconPosition
951 hildon_caption_get_icon_position (const HildonCaption *caption)
953 g_return_val_if_fail (HILDON_IS_CAPTION (caption), 0);
955 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (caption);
958 return priv->icon_position;
962 * hildon_caption_set_status:
963 * @caption : a #HildonCaption
964 * @flag : one of the values from #HildonCaptionStatus
966 * Sets #HildonCaption status.
969 hildon_caption_set_status (HildonCaption *caption,
970 HildonCaptionStatus flag)
972 g_return_if_fail (HILDON_IS_CAPTION(caption));
974 g_object_set (G_OBJECT(caption), "status", flag, NULL);
978 * hildon_caption_get_status:
979 * @caption : a #HildonCaption
981 * Gets #HildonCaption status.
983 * @Returns : one of the values from #HildonCaptionStatus
986 hildon_caption_get_status (const HildonCaption *caption)
988 HildonCaptionPrivate *priv;
989 g_return_val_if_fail (HILDON_IS_CAPTION (caption), HILDON_CAPTION_OPTIONAL);
991 priv = HILDON_CAPTION_GET_PRIVATE(caption);
998 * hildon_caption_set_icon_image:
999 * @caption : a #HildonCaption
1000 * @icon : the #GtkImage to use as the icon.
1001 * calls gtk_widget_show on the icon if !GTK_WIDGET_VISIBLE(icon)
1003 * Sets the icon image widget to be used by this hildon_caption widget.
1006 hildon_caption_set_icon_image (HildonCaption *caption,
1009 g_return_if_fail (HILDON_IS_CAPTION(caption));
1011 g_object_set (G_OBJECT(caption), "icon", icon, NULL);
1015 * hildon_caption_get_icon_image:
1016 * @caption : a #HildonCaption
1018 * Gets icon of #HildonCaption
1020 * @Returns : the #GtkImage widget that is being used as the icon by the
1021 * hildon_caption, or NULL if no icon image is in use.
1024 hildon_caption_get_icon_image (const HildonCaption *caption)
1026 HildonCaptionPrivate *priv;
1028 g_return_val_if_fail (HILDON_IS_CAPTION (caption), NULL);
1030 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1037 * hildon_caption_set_label:
1038 * @caption : a #HildonCaption
1039 * @label : the text to use
1041 * Sets the label text that appears before the control.
1042 * Separator character is added to the end of the label string. By default
1043 * the separator is ":".
1046 hildon_caption_set_label (HildonCaption *caption,
1049 g_return_if_fail (HILDON_IS_CAPTION (caption));
1051 g_object_set (G_OBJECT(caption), "label", label, NULL);
1055 * hildon_caption_set_label_markup:
1056 * @caption : a #HildonCaption
1057 * @markup : the markup text to use
1059 * Sets the label markup text that appears before the control. It acts like
1060 * #hildon_caption_set_label but is using the markup text that allows to specify
1061 * text properties such as bold or italic.
1064 hildon_caption_set_label_markup (HildonCaption *caption,
1065 const gchar *markup)
1067 g_return_if_fail (HILDON_IS_CAPTION (caption));
1069 g_object_set (G_OBJECT(caption), "markup", markup, NULL);
1073 * hildon_caption_get_label:
1074 * @caption : a #HildonCaption
1076 * Gets label of #HildonCaption
1078 * @Returns : the text currently being used as the label of the caption
1079 * control. The string is owned by the label and the caller should never
1080 * free or modify this value.
1083 hildon_caption_get_label (const HildonCaption *caption)
1085 HildonCaptionPrivate *priv;
1086 g_return_val_if_fail (HILDON_IS_CAPTION (caption), "");
1087 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1090 return (gchar*) gtk_label_get_text (GTK_LABEL (priv->label));
1094 * hildon_caption_set_separator:
1095 * @caption : a #HildonCaption
1096 * @separator : the separator to use
1098 * Sets the separator character that appears after the label.
1099 * The default seaparator character is ":"
1103 hildon_caption_set_separator (HildonCaption *caption,
1104 const gchar *separator)
1106 g_return_if_fail (HILDON_IS_CAPTION (caption));
1108 g_object_set (G_OBJECT (caption), "separator", separator, NULL);
1112 * hildon_caption_get_separator:
1113 * @caption : a #HildonCaption
1115 * Gets separator string of #HildonCaption
1117 * @Returns : the text currently being used as the separator of the caption
1118 * control. The string is owned by the caption control and the caller should
1119 * never free or modify this value.
1122 hildon_caption_get_separator (const HildonCaption *caption)
1124 HildonCaptionPrivate *priv;
1125 g_return_val_if_fail (HILDON_IS_CAPTION (caption), "");
1127 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1130 return priv->separator;
1133 /* Activates the child control
1134 * We have this signal so that if needed an application can
1135 * know when we've been activated (useful for captions with
1137 * FIXME: There never are multiple children. Possibly activate
1138 * signal could be removed entirely? (does anyone use it?)
1141 hildon_caption_activate (GtkWidget *widget)
1143 GtkWidget *child = GTK_BIN (widget)->child;
1144 gtk_widget_grab_focus (child);
1148 hildon_caption_grab_focus (GtkWidget *widget)
1150 gtk_widget_grab_focus (GTK_BIN (widget)->child);
1154 * hildon_caption_set_child_expand:
1155 * @caption : a #HildonCaption
1156 * @expand : gboolean to determine if the child is expandable
1158 * Sets child expandability.
1161 hildon_caption_set_child_expand (HildonCaption *caption,
1164 HildonCaptionPrivate *priv = NULL;
1165 GtkWidget *child = NULL;
1166 g_return_if_fail (HILDON_IS_CAPTION (caption));
1168 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1171 /* Did the setting really change? */
1172 if (priv->expand == expand)
1175 priv->expand = expand;
1176 child = GTK_BIN (caption)->child;
1178 /* We do not have a child, nothing to do */
1179 if (! GTK_IS_WIDGET (child))
1182 if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (caption))
1183 gtk_widget_queue_resize (child);
1185 gtk_widget_child_notify (child, "expand");
1189 * hildon_caption_get_child_expand:
1190 * @caption : a #HildonCaption
1192 * Gets childs expandability.
1194 * @Returns : wheter the child is expandable or not.
1197 hildon_caption_get_child_expand (const HildonCaption *caption)
1199 HildonCaptionPrivate *priv = NULL;
1200 g_return_val_if_fail (HILDON_IS_CAPTION (caption), FALSE);
1202 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1205 return priv->expand;
1209 hildon_caption_set_label_text (HildonCaptionPrivate *priv,
1213 g_assert (priv != NULL);
1217 if (priv->separator)
1219 /* Don't duplicate the separator, if the string already contains one */
1220 if (g_str_has_suffix (priv->text, priv->separator))
1223 gtk_label_set_markup (GTK_LABEL (priv->label), priv->text);
1225 gtk_label_set_text (GTK_LABEL (priv->label), priv->text);
1229 /* Append separator and set text */
1230 tmp = g_strconcat( priv->text, priv->separator, NULL );
1233 gtk_label_set_markup (GTK_LABEL (priv->label), tmp);
1235 gtk_label_set_text (GTK_LABEL (priv->label), tmp);
1243 gtk_label_set_markup (GTK_LABEL (priv->label), priv->text);
1245 gtk_label_set_text (GTK_LABEL (priv->label), priv->text);
1250 /* Clear the label */
1252 gtk_label_set_markup (GTK_LABEL (priv->label), "");
1254 gtk_label_set_text (GTK_LABEL (priv->label), "" );
1259 * hildon_caption_set_label_alignment:
1260 * @caption: a #HildonCaption widget
1261 * @alignment: new vertical alignment
1263 * Sets the vertical alignment to be used for the
1264 * text part of the caption. Applications need to
1265 * align the child control themselves.
1269 hildon_caption_set_label_alignment (HildonCaption *caption,
1272 HildonCaptionPrivate *priv;
1274 g_return_if_fail (HILDON_IS_CAPTION (caption));
1276 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1279 g_object_set (priv->label, "yalign", alignment, NULL);
1280 g_object_set (priv->icon_align, "yalign", alignment, NULL);
1285 * hildon_caption_get_label_alignment:
1286 * @caption: a #HildonCaption widget
1288 * Gets current vertical alignment for the text part.
1290 * Returns: vertical alignment
1294 hildon_caption_get_label_alignment (HildonCaption *caption)
1296 HildonCaptionPrivate *priv;
1299 g_return_val_if_fail (HILDON_IS_CAPTION (caption), 0);
1300 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1303 g_object_get (priv->label, "yalign", &result, NULL);