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
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_activate (GtkWidget *widget);
98 hildon_caption_set_property (GObject *object,
104 hildon_caption_get_property (GObject *object,
110 hildon_caption_expose (GtkWidget *widget,
111 GdkEventExpose *event);
114 hildon_caption_destroy (GtkObject *self);
117 hildon_caption_button_press (GtkWidget *widget,
118 GdkEventButton *event);
121 hildon_caption_set_label_text (HildonCaptionPrivate *priv);
124 hildon_caption_set_child_property (GtkContainer *container,
131 hildon_caption_get_child_property (GtkContainer *container,
155 * hildon_caption_get_type:
157 * Initializes and returns the type of a hildon caption.
159 * @Returns: GType of #HildonCaption
162 hildon_caption_get_type (void)
164 static GType caption_type = 0;
168 static const GTypeInfo caption_info = {
169 sizeof (HildonCaptionClass),
170 NULL, /* base_init */
171 NULL, /* base_finalize */
172 (GClassInitFunc) hildon_caption_class_init,
173 NULL, /* class_finalize */
174 NULL, /* class_data */
175 sizeof (HildonCaption),
177 (GInstanceInitFunc) hildon_caption_init,
179 caption_type = g_type_register_static (GTK_TYPE_EVENT_BOX,
180 "HildonCaption", &caption_info, 0 );
186 * Initialises the caption class.
189 hildon_caption_class_init (HildonCaptionClass *caption_class)
191 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (caption_class);
192 GObjectClass *gobject_class = G_OBJECT_CLASS (caption_class);
193 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (caption_class);
195 parent_class = g_type_class_peek_parent (caption_class);
197 g_type_class_add_private (caption_class, sizeof (HildonCaptionPrivate));
199 /* Override virtual functions */
200 gobject_class->get_property = hildon_caption_get_property;
201 gobject_class->set_property = hildon_caption_set_property;
202 caption_class->activate = (gpointer) hildon_caption_activate;
203 GTK_OBJECT_CLASS(caption_class)->destroy = hildon_caption_destroy;
205 container_class->forall = hildon_caption_forall;
206 container_class->set_child_property = hildon_caption_set_child_property;
207 container_class->get_child_property = hildon_caption_get_child_property;
209 widget_class->expose_event = hildon_caption_expose;
210 widget_class->hierarchy_changed = hildon_caption_hierarchy_changed;
211 widget_class->size_request = hildon_caption_size_request;
212 widget_class->size_allocate = hildon_caption_size_allocate;
213 widget_class->button_press_event = hildon_caption_button_press;
215 /* Create new signals and properties */
216 widget_class->activate_signal = g_signal_new ("activate",
217 G_OBJECT_CLASS_TYPE (
221 G_STRUCT_OFFSET (HildonCaptionClass,
222 activate), NULL, NULL,
223 gtk_marshal_VOID__VOID,
227 * HildonCaption:label:
231 g_object_class_install_property (gobject_class, PROP_LABEL,
232 g_param_spec_string ("label",
233 "Current label", "Caption label",
234 NULL, G_PARAM_READABLE | G_PARAM_WRITABLE) );
237 * HildonCaption:icon:
239 * The icon shown on the caption area.
241 g_object_class_install_property (gobject_class, PROP_ICON,
242 g_param_spec_object ("icon",
244 "The icon shown on the caption area",
245 GTK_TYPE_WIDGET, G_PARAM_READABLE |
248 * HildonCaption:status:
250 * Mandatory or optional status.
252 g_object_class_install_property (gobject_class, PROP_STATUS,
253 g_param_spec_enum ("status",
255 "Mandatory or optional status",
256 HILDON_TYPE_CAPTION_STATUS,
257 HILDON_CAPTION_OPTIONAL,
258 G_PARAM_READABLE | G_PARAM_WRITABLE) );
260 * HildonCaption:icon-position:
262 * If the icon is positioned on the left or right side.
264 g_object_class_install_property (gobject_class, PROP_ICON_POSITION,
265 g_param_spec_enum ("icon-position",
267 "If the icon is on the left or right side",
268 HILDON_TYPE_CAPTION_ICON_POSITION,
269 HILDON_CAPTION_POSITION_RIGHT,
270 G_PARAM_READABLE | G_PARAM_WRITABLE) );
273 * HildonCaption:size_group:
275 * Current size group the caption is in.
277 g_object_class_install_property (gobject_class, PROP_SIZE_GROUP,
278 g_param_spec_object ("size_group",
279 "Current size group",
280 "Current size group the caption is in",
281 GTK_TYPE_SIZE_GROUP, G_PARAM_READABLE |
285 * HildonCaption:separator:
287 * The current separator.
289 g_object_class_install_property (gobject_class, PROP_SEPARATOR,
290 g_param_spec_string ("separator",
291 "Current separator", "Current separator",
292 _("ecdg_ti_caption_separator"),
293 G_PARAM_READABLE | G_PARAM_WRITABLE) );
295 /* Create child properties. These are related to
296 child <-> parent relationship, not to either of objects itself */
297 gtk_container_class_install_child_property (container_class,
299 g_param_spec_boolean ("expand",
300 "Same as GtkBox expand.",
301 "Same as GtkBox expand. Wheter the child should be expanded or not.",
306 /* Destroy can be called multiple times, remember to set pointers to NULL */
308 hildon_caption_destroy (GtkObject *self)
310 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (self);
312 /* Free our internal child */
313 if (priv && priv->caption_area)
315 gtk_widget_unparent (priv->caption_area);
316 priv->caption_area = NULL;
319 /* Free user provided strings */
320 if (priv && priv->text)
326 if (priv && priv->separator)
328 g_free (priv->separator);
329 priv->separator = NULL;
332 /* Parent classes destroy takes care of user packed contents */
333 if (GTK_OBJECT_CLASS (parent_class)->destroy)
334 GTK_OBJECT_CLASS (parent_class)->destroy (self);
337 /* Parent, eventbox will run allocate also for the child which may be
338 * owning a window too. This window is then moved and resized
339 * and we do not want to do that (it causes flickering).
342 hildon_caption_expose (GtkWidget *widget,
343 GdkEventExpose *event)
345 HildonCaptionPrivate *priv = NULL;
350 g_assert (HILDON_IS_CAPTION (widget));
351 priv = HILDON_CAPTION_GET_PRIVATE (widget);
354 if (! GTK_WIDGET_DRAWABLE (widget))
357 GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
359 /* If our child control is focused, we draw nice looking focus
360 graphics for the caption */
361 if (priv->is_focused && priv->text)
363 /* Determine focus box dimensions */
364 gtk_widget_get_child_requisition (priv->caption_area, &req);
365 align = hildon_caption_get_label_alignment (HILDON_CAPTION(widget));
367 alloc.width = priv->caption_area->allocation.width + HILDON_CAPTION_SPACING;
368 alloc.height = MIN (req.height + (2 * widget->style->ythickness), priv->caption_area->allocation.height);
370 alloc.x = priv->caption_area->allocation.x - HILDON_CAPTION_SPACING; /* - left margin */
371 alloc.y = priv->caption_area->allocation.y +
372 MAX (((priv->caption_area->allocation.height - alloc.height) * align), 0);
374 /* Paint the focus box */
375 gtk_paint_box (widget->style, widget->window, GTK_STATE_ACTIVE,
376 GTK_SHADOW_OUT, NULL, widget, "selection",
377 alloc.x, alloc.y, alloc.width, alloc.height);
379 /* Paint caption contents on top of the focus box */
380 GTK_WIDGET_GET_CLASS (priv->caption_area)->expose_event (priv->caption_area, event);
387 hildon_caption_set_property (GObject *object,
392 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (object);
397 case PROP_ICON_POSITION:
398 hildon_caption_set_icon_position (HILDON_CAPTION (object), g_value_get_enum (value));
402 /* Free old label string */
410 priv->text = g_value_dup_string (value);
411 hildon_caption_set_label_text (priv);
415 /* Remove old icon */
417 gtk_container_remove (GTK_CONTAINER (priv->icon_align), priv->icon);
419 /* Pack and display new icon */
420 priv->icon = g_value_get_object (value);
423 gtk_container_add (GTK_CONTAINER (priv->icon_align), priv->icon);
424 gtk_widget_show_all (priv->caption_area);
429 priv->status = g_value_get_enum (value);
432 case PROP_SIZE_GROUP:
433 /* Detach from previous size group */
435 gtk_size_group_remove_widget (priv->group, priv->caption_area);
437 priv->group = g_value_get_object (value);
439 /* Attach to new size group */
441 gtk_size_group_add_widget (priv->group, priv->caption_area);
443 gtk_widget_queue_draw (GTK_WIDGET(object));
448 /* Free old separator */
451 g_free (priv->separator);
452 priv->separator = NULL;
455 priv->separator = g_value_dup_string (value);
456 hildon_caption_set_label_text (priv);
460 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
466 hildon_caption_get_property (GObject *object,
471 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (object);
476 g_value_set_string (value, priv->text);
480 g_value_set_object (value, priv->icon);
484 g_value_set_enum (value, priv->status);
487 case PROP_ICON_POSITION:
488 g_value_set_enum (value, priv->icon_position);
491 case PROP_SIZE_GROUP:
492 g_value_set_object (value, priv->group);
496 g_value_set_string (value, priv->separator);
500 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
506 hildon_caption_set_child_property (GtkContainer *container,
514 case CHILD_PROP_EXPAND:
515 hildon_caption_set_child_expand (HILDON_CAPTION (container),
516 g_value_get_boolean (value));
520 G_OBJECT_WARN_INVALID_PROPERTY_ID (container, property_id, pspec);
526 hildon_caption_get_child_property (GtkContainer *container,
534 case CHILD_PROP_EXPAND:
535 g_value_set_boolean (value, hildon_caption_get_child_expand(
536 HILDON_CAPTION (container)));
540 G_OBJECT_WARN_INVALID_PROPERTY_ID(container, property_id, pspec);
545 /* We want to activate out child control on button press */
547 hildon_caption_button_press (GtkWidget *widget,
548 GdkEventButton *event)
550 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (widget);
552 GtkWidget *child = GTK_BIN (widget)->child;
555 if (priv->is_focused == TRUE)
558 /* If child can take focus, we simply grab focus to it */
559 if ((GTK_WIDGET_CAN_FOCUS (child) || GTK_IS_CONTAINER (child)) &&
560 GTK_WIDGET_IS_SENSITIVE (child))
562 /* Only if container can be focusable we must set is_focused to TRUE */
563 if (GTK_IS_CONTAINER (child))
565 if (gtk_widget_child_focus (child, GTK_DIR_TAB_FORWARD))
566 priv->is_focused = TRUE;
570 priv->is_focused = TRUE;
571 gtk_widget_grab_focus (GTK_BIN (widget)->child);
579 hildon_caption_init (HildonCaption *caption)
581 HildonCaptionPrivate *priv = NULL;
583 /* Initialize startup state */
584 priv = HILDON_CAPTION_GET_PRIVATE (caption);
587 priv->status = HILDON_CAPTION_OPTIONAL;
590 priv->is_focused = FALSE;
593 priv->separator = g_strdup(_("ecdg_ti_caption_separator"));
595 gtk_widget_push_composite_child();
597 /* Create caption text */
598 priv->caption_area = gtk_hbox_new (FALSE, HILDON_CAPTION_SPACING);
599 priv->label = gtk_label_new (NULL);
600 priv->icon_align = gtk_alignment_new (0.5f, 0.5f, 0.0f, 0.0f);
601 priv->icon_position = HILDON_CAPTION_POSITION_RIGHT;
603 /* We want to receive button presses for child widget activation */
604 gtk_event_box_set_above_child (GTK_EVENT_BOX (caption), FALSE);
605 gtk_widget_add_events (GTK_WIDGET (caption), GDK_BUTTON_PRESS_MASK);
607 /* Pack text label caption layout */
608 gtk_box_pack_end (GTK_BOX (priv->caption_area), priv->icon_align, FALSE, FALSE, 0);
609 gtk_box_pack_end (GTK_BOX (priv->caption_area), priv->label, FALSE, FALSE, 0);
610 gtk_widget_set_parent (priv->caption_area, GTK_WIDGET (caption));
612 gtk_widget_pop_composite_child ();
614 hildon_caption_set_child_expand (caption, TRUE);
616 gtk_widget_show_all (priv->caption_area);
620 hildon_caption_set_focus (GtkWindow *window,
624 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (caption);
627 /* check if ancestor gone */
633 /* Try to find caption among the ancestors of widget */
634 if (gtk_widget_is_ancestor (widget, caption))
636 priv->is_focused = TRUE;
637 gtk_widget_queue_draw (caption);
641 if (priv->is_focused == TRUE)
643 /* Caption wasn't found, so cannot focus */
644 priv->is_focused = FALSE;
645 gtk_widget_queue_draw (caption);
649 /* We need to connect/disconnect signal handlers to toplevel window
650 in which we reside. Ww want to update connected signals if our
653 hildon_caption_hierarchy_changed (GtkWidget *widget,
654 GtkWidget *previous_toplevel)
656 GtkWidget *current_ancestor;
657 HildonCaptionPrivate *priv;
659 priv = HILDON_CAPTION_GET_PRIVATE (widget);
662 if (GTK_WIDGET_CLASS (parent_class)->hierarchy_changed)
663 GTK_WIDGET_CLASS (parent_class)->hierarchy_changed (widget, previous_toplevel);
665 /* If we already were inside a window, remove old handler */
666 if (previous_toplevel) {
667 /* This is a compilation workaround for gcc > 3.3 since glib is buggy */
668 /* see http://bugzilla.gnome.org/show_bug.cgi?id=310175 */
672 g_signal_handlers_disconnect_by_func
673 (previous_toplevel, (gpointer) hildon_caption_set_focus, widget);
676 current_ancestor = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
678 /* Install new handler for focus movement */
679 if (current_ancestor)
680 g_signal_connect( current_ancestor, "set-focus",
681 G_CALLBACK (hildon_caption_set_focus), widget );
685 hildon_caption_size_request (GtkWidget *widget,
686 GtkRequisition *requisition)
689 HildonCaptionPrivate *priv = NULL;
690 g_return_if_fail (HILDON_IS_CAPTION(widget));
692 priv = HILDON_CAPTION_GET_PRIVATE (widget);
695 /* Use the same size requisition for the main box of the caption */
696 gtk_widget_size_request (priv->caption_area, &req);
698 if (GTK_WIDGET_CLASS (parent_class)->size_request)
699 GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition);
701 requisition->width += req.width + HILDON_CAPTION_SPACING * 3;
703 if ((req.height + (2 * widget->style->ythickness)) > requisition->height)
704 requisition->height = req.height + (2 * widget->style->ythickness);
707 /* We use HILDON_CAPTION_SPACING to make it look a bit nicer */
709 hildon_caption_size_allocate (GtkWidget *widget,
710 GtkAllocation *allocation)
712 GtkAllocation child_alloc;
713 GtkAllocation caption_alloc;
715 GtkWidget *child = NULL;
716 HildonCaptionPrivate *priv = NULL;
718 g_assert (HILDON_IS_CAPTION (widget));
719 priv = HILDON_CAPTION_GET_PRIVATE (widget);
722 /* Position the caption to its allocated location */
723 if (GTK_WIDGET_REALIZED (widget))
724 gdk_window_move_resize (widget->window,
725 allocation->x + GTK_CONTAINER (widget)->border_width,
726 allocation->y + GTK_CONTAINER (widget)->border_width,
727 MAX (allocation->width - GTK_CONTAINER (widget)->border_width * 2, 0),
728 MAX (allocation->height - GTK_CONTAINER (widget)->border_width * 2, 0));
730 child = GTK_BIN (widget)->child;
732 widget->allocation = *allocation;
733 gtk_widget_get_child_requisition (priv->caption_area, &req);
735 child_alloc.height = caption_alloc.height = allocation->height;
736 child_alloc.width = caption_alloc.width = allocation->width;
737 child_alloc.x = caption_alloc.x = caption_alloc.y = child_alloc.y = 0;
739 /* Center the captioned widget */
740 if (child_alloc.width > req.width + HILDON_CAPTION_SPACING)
742 child_alloc.x += req.width + HILDON_CAPTION_SPACING * 2;
743 caption_alloc.width = req.width;
746 /* Leave at least the space of the HILDON_CAPTION_SPACING in the left */
747 caption_alloc.x = HILDON_CAPTION_SPACING;
749 /* Leave room for the other drawable parts of the caption control */
750 child_alloc.width -= req.width + HILDON_CAPTION_SPACING * 2;
752 /* Give the child at least its minimum requisition, unless it is expandable */
753 if (! priv->expand && child && GTK_WIDGET_VISIBLE(child))
755 GtkRequisition child_req;
756 gtk_widget_get_child_requisition (child, &child_req);
757 child_alloc.width = MIN (child_alloc.width, child_req.width);
758 child_alloc.height = MIN (child_alloc.height, child_req.height);
759 /* Center the child */
760 child_alloc.y = (allocation->height - child_alloc.height -
761 2 * GTK_CONTAINER (widget)->border_width)/2;
764 /* Ensure there are no negative dimensions */
765 if (child_alloc.width < 0)
767 caption_alloc.width = req.width + child_alloc.width;
768 child_alloc.width = 0;
769 caption_alloc.width = MAX (caption_alloc.width, 0);
772 child_alloc.height = MAX (child_alloc.height, 0);
773 caption_alloc.height = MAX (caption_alloc.height, 0);
775 if (child && GTK_WIDGET_VISIBLE(child) )
776 gtk_widget_size_allocate (child, &child_alloc );
778 gtk_widget_size_allocate (priv->caption_area, &caption_alloc);
782 hildon_caption_forall (GtkContainer *container,
783 gboolean include_internals,
784 GtkCallback callback,
787 HildonCaptionPrivate *priv = NULL;
789 g_assert (HILDON_IS_CAPTION (container));
790 g_assert (callback != NULL);
792 priv = HILDON_CAPTION_GET_PRIVATE (container);
795 /* Execute callback for the child widgets */
796 if (GTK_CONTAINER_CLASS (parent_class)->forall)
797 GTK_CONTAINER_CLASS (parent_class)->forall (container, include_internals, callback, data);
799 if (include_internals)
800 /* Execute callback for the parent box as well */
801 (*callback) (priv->caption_area, data);
805 * hildon_caption_set_sizegroup:
806 * @caption : a #HildonCaption
807 * @new_group : a #GtkSizeGroup
809 * Sets a #GtkSizeGroup of a given captioned control.
813 hildon_caption_set_size_group (const HildonCaption *self,
816 g_object_set (G_OBJECT(self), "size_group", group, NULL);
820 * hildon_caption_get_sizegroup:
821 * @caption : a #HildonCaption
823 * Query given captioned control for the #GtkSizeGroup assigned to it.
825 * @Returns : a #GtkSizeGroup
829 hildon_caption_get_size_group (const HildonCaption *self)
831 HildonCaptionPrivate *priv;
832 g_return_val_if_fail (HILDON_IS_CAPTION (self), NULL);
834 priv = HILDON_CAPTION_GET_PRIVATE(self);
841 * hildon_caption_new:
842 * @group : a #GtkSizeGroup for controlling the size of related captions,
844 * @value : the caption text to accompany the text entry. The widget makes
845 * a copy of this text.
846 * @control : the control that is to be captioned
847 * @icon : an icon to accompany the label - can be NULL in which case no
849 * @flag : indicates whether this captioned control is mandatory or
852 * Creates a new instance of hildon_caption widget, with a specific
854 * Note: Clicking on a focused caption will trigger the activate signal.
855 * The default behaviour for the caption's activate signal is to call
856 * gtk_widget_activate on it's control.
858 * @Returns : a #GtkWidget pointer of Caption
861 hildon_caption_new (GtkSizeGroup *group,
865 HildonCaptionStatus flag)
868 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
870 widget = g_object_new (HILDON_TYPE_CAPTION,
878 /* Do not expand GtkCheckButton by default, we want to reduce its activation area */
879 if (GTK_IS_CHECK_BUTTON (child))
880 hildon_caption_set_child_expand (HILDON_CAPTION (widget), FALSE);
886 * hildon_caption_is_mandatory:
887 * @caption : a #HildonCaption
889 * Query #HildonCaption whether this captioned control is a mandatory one.
891 * @Returns : is this captioned control a mandatory one?
894 hildon_caption_is_mandatory (const HildonCaption *caption)
896 HildonCaptionPrivate *priv;
898 g_return_val_if_fail (HILDON_IS_CAPTION (caption), FALSE);
900 priv = HILDON_CAPTION_GET_PRIVATE (caption);
903 return (priv->status == HILDON_CAPTION_MANDATORY);
907 * hildon_caption_set_icon_position:
908 * @caption : a #HildonCaption
909 * @pos : one of the values from #HildonCaptionIconPosition
911 * Sets #HildonCaption icon position.
915 hildon_caption_set_icon_position (HildonCaption *caption,
916 HildonCaptionIconPosition pos)
918 g_return_if_fail (HILDON_IS_CAPTION (caption));
919 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (caption);
922 g_return_if_fail (priv->caption_area != NULL);
924 int order = (pos == HILDON_CAPTION_POSITION_LEFT) ? -1 : 0;
925 gtk_box_reorder_child (GTK_BOX (priv->caption_area), priv->icon_align, order);
927 priv->icon_position = pos;
931 * hildon_caption_get_icon_position:
932 * @caption : a #HildonCaption
934 * Gets #HildonCaption icon position.
936 * @Returns : one of the values from #HildonCaptionIconPosition.
940 HildonCaptionIconPosition
941 hildon_caption_get_icon_position (const HildonCaption *caption)
943 g_return_val_if_fail (HILDON_IS_CAPTION (caption), 0);
945 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (caption);
948 return priv->icon_position;
952 * hildon_caption_set_status:
953 * @caption : a #HildonCaption
954 * @flag : one of the values from #HildonCaptionStatus
956 * Sets #HildonCaption status.
959 hildon_caption_set_status (HildonCaption *caption,
960 HildonCaptionStatus flag)
962 g_return_if_fail (HILDON_IS_CAPTION(caption));
964 g_object_set (G_OBJECT(caption), "status", flag, NULL);
968 * hildon_caption_get_status:
969 * @caption : a #HildonCaption
971 * Gets #HildonCaption status.
973 * @Returns : one of the values from #HildonCaptionStatus
976 hildon_caption_get_status (const HildonCaption *caption)
978 HildonCaptionPrivate *priv;
979 g_return_val_if_fail (HILDON_IS_CAPTION (caption), HILDON_CAPTION_OPTIONAL);
981 priv = HILDON_CAPTION_GET_PRIVATE(caption);
988 * hildon_caption_set_icon_image:
989 * @caption : a #HildonCaption
990 * @icon : the #GtkImage to use as the icon.
991 * calls gtk_widget_show on the icon if !GTK_WIDGET_VISIBLE(icon)
993 * Sets the icon image widget to be used by this hildon_caption widget.
996 hildon_caption_set_icon_image (HildonCaption *caption,
999 g_return_if_fail (HILDON_IS_CAPTION(caption));
1001 g_object_set (G_OBJECT(caption), "icon", icon, NULL);
1005 * hildon_caption_get_icon_image:
1006 * @caption : a #HildonCaption
1008 * Gets icon of #HildonCaption
1010 * @Returns : the #GtkImage widget that is being used as the icon by the
1011 * hildon_caption, or NULL if no icon image is in use.
1014 hildon_caption_get_icon_image (const HildonCaption *caption)
1016 HildonCaptionPrivate *priv;
1018 g_return_val_if_fail (HILDON_IS_CAPTION (caption), NULL);
1020 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1027 * hildon_caption_set_label:
1028 * @caption : a #HildonCaption
1029 * @label : the text to use
1031 * Sets the label text that appears before the control.
1032 * Separator character is added to the end of the label string. By default
1033 * the separator is ":".
1036 hildon_caption_set_label (HildonCaption *caption,
1039 g_return_if_fail (HILDON_IS_CAPTION(caption));
1041 g_object_set (G_OBJECT(caption), "label", label, NULL);
1045 * hildon_caption_get_label:
1046 * @caption : a #HildonCaption
1048 * Gets label of #HildonCaption
1050 * @Returns : the text currently being used as the label of the caption
1051 * control. The string is owned by the label and the caller should never
1052 * free or modify this value.
1055 hildon_caption_get_label (const HildonCaption *caption)
1057 HildonCaptionPrivate *priv;
1058 g_return_val_if_fail (HILDON_IS_CAPTION (caption), "");
1059 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1062 return (gchar*) gtk_label_get_text (GTK_LABEL (GTK_LABEL (priv->label)));
1066 * hildon_caption_set_separator:
1067 * @caption : a #HildonCaption
1068 * @separator : the separator to use
1070 * Sets the separator character that appears after the label.
1071 * The default seaparator character is ":"
1075 hildon_caption_set_separator (HildonCaption *caption,
1076 const gchar *separator)
1078 g_return_if_fail (HILDON_IS_CAPTION (caption));
1080 g_object_set (G_OBJECT (caption), "separator", separator, NULL);
1084 * hildon_caption_get_separator:
1085 * @caption : a #HildonCaption
1087 * Gets separator string of #HildonCaption
1089 * @Returns : the text currently being used as the separator of the caption
1090 * control. The string is owned by the caption control and the caller should
1091 * never free or modify this value.
1094 hildon_caption_get_separator (const HildonCaption *caption)
1096 HildonCaptionPrivate *priv;
1097 g_return_val_if_fail (HILDON_IS_CAPTION (caption), "");
1099 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1102 return priv->separator;
1105 /* Activates the child control
1106 * We have this signal so that if needed an application can
1107 * know when we've been activated (useful for captions with
1109 * FIXME: There never are multiple children. Possibly activate
1110 * signal could be removed entirely? (does anyone use it?)
1113 hildon_caption_activate (GtkWidget *widget)
1115 GtkWidget *child = GTK_BIN (widget)->child;
1116 gtk_widget_grab_focus (child);
1120 * hildon_caption_set_child_expand:
1121 * @caption : a #HildonCaption
1122 * @expand : gboolean to determine if the child is expandable
1124 * Sets child expandability.
1127 hildon_caption_set_child_expand (HildonCaption *caption,
1130 HildonCaptionPrivate *priv = NULL;
1131 GtkWidget *child = NULL;
1132 g_return_if_fail (HILDON_IS_CAPTION (caption));
1134 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1137 /* Did the setting really change? */
1138 if (priv->expand == expand)
1141 priv->expand = expand;
1142 child = GTK_BIN (caption)->child;
1144 /* We do not have a child, nothing to do */
1145 if (! GTK_IS_WIDGET (child))
1148 if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (caption))
1149 gtk_widget_queue_resize (child);
1151 gtk_widget_child_notify (child, "expand");
1155 * hildon_caption_get_child_expand:
1156 * @caption : a #HildonCaption
1158 * Gets childs expandability.
1160 * @Returns : wheter the child is expandable or not.
1163 hildon_caption_get_child_expand (const HildonCaption *caption)
1165 HildonCaptionPrivate *priv = NULL;
1166 g_return_val_if_fail (HILDON_IS_CAPTION (caption), FALSE);
1168 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1171 return priv->expand;
1175 hildon_caption_set_label_text (HildonCaptionPrivate *priv)
1178 g_assert (priv != NULL);
1182 if (priv->separator)
1184 /* Don't duplicate the separator, if the string already contains one */
1185 if (g_str_has_suffix (priv->text, priv->separator))
1187 gtk_label_set_text (GTK_LABEL (priv->label), priv->text);
1191 /* Append separator and set text */
1192 tmp = g_strconcat( priv->text, priv->separator, NULL );
1193 gtk_label_set_text (GTK_LABEL( priv->label), tmp);
1199 gtk_label_set_text (GTK_LABEL (priv->label), priv->text);
1204 /* Clear the label */
1205 gtk_label_set_text (GTK_LABEL (priv->label), "" );
1211 * hildon_caption_set_label_alignment:
1212 * @caption: a #HildonCaption widget
1213 * @alignment: new vertical alignment
1215 * Sets the vertical alignment to be used for the
1216 * text part of the caption. Applications need to
1217 * align the child control themselves.
1221 hildon_caption_set_label_alignment (HildonCaption *caption,
1224 HildonCaptionPrivate *priv;
1226 g_return_if_fail (HILDON_IS_CAPTION (caption));
1228 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1231 g_object_set (priv->label, "yalign", alignment, NULL);
1232 g_object_set (priv->icon_align, "yalign", alignment, NULL);
1237 * hildon_caption_get_label_alignment:
1238 * @caption: a #HildonCaption widget
1240 * Gets current vertical alignment for the text part.
1242 * Returns: vertical alignment
1246 hildon_caption_get_label_alignment (HildonCaption *caption)
1248 HildonCaptionPrivate *priv;
1251 g_return_val_if_fail (HILDON_IS_CAPTION (caption), 0);
1252 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1255 g_object_get (priv->label, "yalign", &result, NULL);