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>
53 #include "hildon-defines.h"
55 #include "hildon-caption-private.h"
58 dgettext("hildon-libs", String)
60 #define HILDON_CAPTION_SPACING 6
62 static GtkEventBox* parent_class = NULL;
65 hildon_caption_class_init (HildonCaptionClass *caption_class);
68 hildon_caption_init (HildonCaption *caption);
71 hildon_caption_size_request (GtkWidget *widget,
72 GtkRequisition *requisition);
75 hildon_caption_size_allocate (GtkWidget *widget,
76 GtkAllocation *allocation);
79 hildon_caption_forall (GtkContainer *container,
80 gboolean include_internals,
85 hildon_caption_hierarchy_changed (GtkWidget *widget,
86 GtkWidget *previous_toplevel);
89 hildon_caption_set_focus (GtkWindow *window,
94 hildon_caption_activate (GtkWidget *widget);
97 hildon_caption_set_property (GObject *object,
103 hildon_caption_get_property (GObject *object,
109 hildon_caption_expose (GtkWidget *widget,
110 GdkEventExpose *event);
113 hildon_caption_destroy (GtkObject *self);
116 hildon_caption_button_press (GtkWidget *widget,
117 GdkEventButton *event);
120 hildon_caption_set_label_text (HildonCaptionPrivate *priv);
123 hildon_caption_set_child_property (GtkContainer *container,
130 hildon_caption_get_child_property (GtkContainer *container,
154 * hildon_caption_get_type:
156 * Initializes and returns the type of a hildon caption.
158 * @Returns: GType of #HildonCaption
161 hildon_caption_get_type (void)
163 static GType caption_type = 0;
167 static const GTypeInfo caption_info = {
168 sizeof (HildonCaptionClass),
169 NULL, /* base_init */
170 NULL, /* base_finalize */
171 (GClassInitFunc) hildon_caption_class_init,
172 NULL, /* class_finalize */
173 NULL, /* class_data */
174 sizeof (HildonCaption),
176 (GInstanceInitFunc) hildon_caption_init,
178 caption_type = g_type_register_static (GTK_TYPE_EVENT_BOX,
179 "HildonCaption", &caption_info, 0 );
185 * Initialises the caption class.
188 hildon_caption_class_init (HildonCaptionClass *caption_class)
190 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (caption_class);
191 GObjectClass *gobject_class = G_OBJECT_CLASS (caption_class);
192 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (caption_class);
194 parent_class = g_type_class_peek_parent (caption_class);
196 g_type_class_add_private (caption_class, sizeof (HildonCaptionPrivate));
198 /* Override virtual functions */
199 gobject_class->get_property = hildon_caption_get_property;
200 gobject_class->set_property = hildon_caption_set_property;
201 caption_class->activate = (gpointer) hildon_caption_activate;
202 GTK_OBJECT_CLASS(caption_class)->destroy = hildon_caption_destroy;
204 container_class->forall = hildon_caption_forall;
205 container_class->set_child_property = hildon_caption_set_child_property;
206 container_class->get_child_property = hildon_caption_get_child_property;
208 widget_class->expose_event = hildon_caption_expose;
209 widget_class->hierarchy_changed = hildon_caption_hierarchy_changed;
210 widget_class->size_request = hildon_caption_size_request;
211 widget_class->size_allocate = hildon_caption_size_allocate;
212 widget_class->button_press_event = hildon_caption_button_press;
214 /* Create new signals and properties */
215 widget_class->activate_signal = g_signal_new ("activate",
216 G_OBJECT_CLASS_TYPE (
220 G_STRUCT_OFFSET (HildonCaptionClass,
221 activate), NULL, NULL,
222 gtk_marshal_VOID__VOID,
226 * HildonCaption:label:
230 g_object_class_install_property (gobject_class, PROP_LABEL,
231 g_param_spec_string ("label",
232 "Current label", "Caption label",
233 NULL, G_PARAM_READABLE | G_PARAM_WRITABLE) );
236 * HildonCaption:icon:
238 * The icon shown on the caption area.
240 g_object_class_install_property (gobject_class, PROP_ICON,
241 g_param_spec_object ("icon",
243 "The icon shown on the caption area",
244 GTK_TYPE_WIDGET, G_PARAM_READABLE |
247 * HildonCaption:status:
249 * Mandatory or optional status.
251 g_object_class_install_property (gobject_class, PROP_STATUS,
252 g_param_spec_enum ("status",
254 "Mandatory or optional status",
255 HILDON_TYPE_CAPTION_STATUS,
256 HILDON_CAPTION_OPTIONAL,
257 G_PARAM_READABLE | G_PARAM_WRITABLE) );
259 * HildonCaption:icon-position:
261 * If the icon is positioned on the left or right side.
263 g_object_class_install_property (gobject_class, PROP_ICON_POSITION,
264 g_param_spec_enum ("icon-position",
266 "If the icon is on the left or right side",
267 HILDON_TYPE_CAPTION_ICON_POSITION,
268 HILDON_CAPTION_POSITION_RIGHT,
269 G_PARAM_READABLE | G_PARAM_WRITABLE) );
272 * HildonCaption:size_group:
274 * Current size group the caption is in.
276 g_object_class_install_property (gobject_class, PROP_SIZE_GROUP,
277 g_param_spec_object ("size_group",
278 "Current size group",
279 "Current size group the caption is in",
280 GTK_TYPE_SIZE_GROUP, G_PARAM_READABLE |
284 * HildonCaption:separator:
286 * The current separator.
288 g_object_class_install_property (gobject_class, PROP_SEPARATOR,
289 g_param_spec_string ("separator",
290 "Current separator", "Current separator",
291 _("ecdg_ti_caption_separator"),
292 G_PARAM_READABLE | G_PARAM_WRITABLE) );
294 /* Create child properties. These are related to
295 child <-> parent relationship, not to either of objects itself */
296 gtk_container_class_install_child_property (container_class,
298 g_param_spec_boolean ("expand",
299 "Same as GtkBox expand.",
300 "Same as GtkBox expand. Wheter the child should be expanded or not.",
305 /* Destroy can be called multiple times, remember to set pointers to NULL */
307 hildon_caption_destroy (GtkObject *self)
309 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (self);
311 /* Free our internal child */
312 if (priv && priv->caption_area)
314 gtk_widget_unparent (priv->caption_area);
315 priv->caption_area = NULL;
318 /* Free user provided strings */
319 if (priv && priv->text)
325 if (priv && priv->separator)
327 g_free (priv->separator);
328 priv->separator = NULL;
331 /* Parent classes destroy takes care of user packed contents */
332 if (GTK_OBJECT_CLASS (parent_class)->destroy)
333 GTK_OBJECT_CLASS (parent_class)->destroy (self);
336 /* Parent, eventbox will run allocate also for the child which may be
337 * owning a window too. This window is then moved and resized
338 * and we do not want to do that (it causes flickering).
341 hildon_caption_expose (GtkWidget *widget,
342 GdkEventExpose *event)
344 HildonCaptionPrivate *priv = NULL;
349 g_assert (HILDON_IS_CAPTION (widget));
350 priv = HILDON_CAPTION_GET_PRIVATE (widget);
353 if (! GTK_WIDGET_DRAWABLE (widget))
356 GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
358 /* If our child control is focused, we draw nice looking focus
359 graphics for the caption */
360 if (priv->is_focused && priv->text)
362 /* Determine focus box dimensions */
363 gtk_widget_get_child_requisition (priv->caption_area, &req);
364 align = hildon_caption_get_label_alignment (HILDON_CAPTION(widget));
366 alloc.width = priv->caption_area->allocation.width + HILDON_CAPTION_SPACING;
367 alloc.height = MIN (req.height + (2 * widget->style->ythickness), priv->caption_area->allocation.height);
369 alloc.x = priv->caption_area->allocation.x - HILDON_CAPTION_SPACING; /* - left margin */
370 alloc.y = priv->caption_area->allocation.y +
371 MAX (((priv->caption_area->allocation.height - alloc.height) * align), 0);
373 /* Paint the focus box */
374 gtk_paint_box (widget->style, widget->window, GTK_STATE_ACTIVE,
375 GTK_SHADOW_OUT, NULL, widget, "selection",
376 alloc.x, alloc.y, alloc.width, alloc.height);
378 /* Paint caption contents on top of the focus box */
379 GTK_WIDGET_GET_CLASS (priv->caption_area)->expose_event (priv->caption_area, event);
386 hildon_caption_set_property (GObject *object,
391 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (object);
396 case PROP_ICON_POSITION:
397 hildon_caption_set_icon_position (HILDON_CAPTION (object), g_value_get_enum (value));
401 /* Free old label string */
409 priv->text = g_value_dup_string (value);
410 hildon_caption_set_label_text (priv);
414 /* Remove old icon */
416 gtk_container_remove (GTK_CONTAINER (priv->icon_align), priv->icon);
418 /* Pack and display new icon */
419 priv->icon = g_value_get_object (value);
422 gtk_container_add (GTK_CONTAINER (priv->icon_align), priv->icon);
423 gtk_widget_show_all (priv->caption_area);
428 priv->status = g_value_get_enum (value);
431 case PROP_SIZE_GROUP:
432 /* Detach from previous size group */
434 gtk_size_group_remove_widget (priv->group, priv->caption_area);
436 priv->group = g_value_get_object (value);
438 /* Attach to new size group */
440 gtk_size_group_add_widget (priv->group, priv->caption_area);
442 gtk_widget_queue_draw (GTK_WIDGET(object));
447 /* Free old separator */
450 g_free (priv->separator);
451 priv->separator = NULL;
454 priv->separator = g_value_dup_string (value);
455 hildon_caption_set_label_text (priv);
459 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
465 hildon_caption_get_property (GObject *object,
470 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (object);
475 g_value_set_string (value, priv->text);
479 g_value_set_object (value, priv->icon);
483 g_value_set_enum (value, priv->status);
486 case PROP_ICON_POSITION:
487 g_value_set_enum (value, priv->icon_position);
490 case PROP_SIZE_GROUP:
491 g_value_set_object (value, priv->group);
495 g_value_set_string (value, priv->separator);
499 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
505 hildon_caption_set_child_property (GtkContainer *container,
513 case CHILD_PROP_EXPAND:
514 hildon_caption_set_child_expand (HILDON_CAPTION (container),
515 g_value_get_boolean (value));
519 G_OBJECT_WARN_INVALID_PROPERTY_ID (container, property_id, pspec);
525 hildon_caption_get_child_property (GtkContainer *container,
533 case CHILD_PROP_EXPAND:
534 g_value_set_boolean (value, hildon_caption_get_child_expand(
535 HILDON_CAPTION (container)));
539 G_OBJECT_WARN_INVALID_PROPERTY_ID(container, property_id, pspec);
544 /* We want to activate out child control on button press */
546 hildon_caption_button_press (GtkWidget *widget,
547 GdkEventButton *event)
549 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (widget);
551 GtkWidget *child = GTK_BIN (widget)->child;
554 if (priv->is_focused == TRUE)
557 /* If child can take focus, we simply grab focus to it */
558 if ((GTK_WIDGET_CAN_FOCUS (child) || GTK_IS_CONTAINER (child)) &&
559 GTK_WIDGET_IS_SENSITIVE (child))
561 /* Only if container can be focusable we must set is_focused to TRUE */
562 if (GTK_IS_CONTAINER (child))
564 if (gtk_widget_child_focus (child, GTK_DIR_TAB_FORWARD))
565 priv->is_focused = TRUE;
569 priv->is_focused = TRUE;
570 gtk_widget_grab_focus (GTK_BIN (widget)->child);
578 hildon_caption_init (HildonCaption *caption)
580 HildonCaptionPrivate *priv = NULL;
582 /* Initialize startup state */
583 priv = HILDON_CAPTION_GET_PRIVATE (caption);
586 priv->status = HILDON_CAPTION_OPTIONAL;
589 priv->is_focused = FALSE;
592 priv->separator = g_strdup(_("ecdg_ti_caption_separator"));
594 gtk_widget_push_composite_child();
596 /* Create caption text */
597 priv->caption_area = gtk_hbox_new (FALSE, HILDON_CAPTION_SPACING);
598 priv->label = gtk_label_new (NULL);
599 priv->icon_align = gtk_alignment_new (0.5f, 0.5f, 0.0f, 0.0f);
600 priv->icon_position = HILDON_CAPTION_POSITION_RIGHT;
602 /* We want to receive button presses for child widget activation */
603 gtk_event_box_set_above_child (GTK_EVENT_BOX (caption), FALSE);
604 gtk_widget_add_events (GTK_WIDGET (caption), GDK_BUTTON_PRESS_MASK);
606 /* Pack text label caption layout */
607 gtk_box_pack_end (GTK_BOX (priv->caption_area), priv->icon_align, FALSE, FALSE, 0);
608 gtk_box_pack_end (GTK_BOX (priv->caption_area), priv->label, FALSE, FALSE, 0);
609 gtk_widget_set_parent (priv->caption_area, GTK_WIDGET (caption));
611 gtk_widget_pop_composite_child ();
613 hildon_caption_set_child_expand (caption, TRUE);
615 gtk_widget_show_all (priv->caption_area);
619 hildon_caption_set_focus (GtkWindow *window,
623 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (caption);
626 /* check if ancestor gone */
632 /* Try to find caption among the ancestors of widget */
633 if (gtk_widget_is_ancestor (widget, caption))
635 priv->is_focused = TRUE;
636 gtk_widget_queue_draw (caption);
640 if (priv->is_focused == TRUE)
642 /* Caption wasn't found, so cannot focus */
643 priv->is_focused = FALSE;
644 gtk_widget_queue_draw (caption);
648 /* We need to connect/disconnect signal handlers to toplevel window
649 in which we reside. Ww want to update connected signals if our
652 hildon_caption_hierarchy_changed (GtkWidget *widget,
653 GtkWidget *previous_toplevel)
655 GtkWidget *current_ancestor;
656 HildonCaptionPrivate *priv;
658 priv = HILDON_CAPTION_GET_PRIVATE (widget);
661 if (GTK_WIDGET_CLASS (parent_class)->hierarchy_changed)
662 GTK_WIDGET_CLASS (parent_class)->hierarchy_changed (widget, previous_toplevel);
664 /* If we already were inside a window, remove old handler */
665 if (previous_toplevel) {
666 /* This is a compilation workaround for gcc > 3.3 since glib is buggy */
667 /* see http://bugzilla.gnome.org/show_bug.cgi?id=310175 */
671 g_signal_handlers_disconnect_by_func
672 (previous_toplevel, (gpointer) hildon_caption_set_focus, widget);
675 current_ancestor = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
677 /* Install new handler for focus movement */
678 if (current_ancestor)
679 g_signal_connect( current_ancestor, "set-focus",
680 G_CALLBACK (hildon_caption_set_focus), widget );
684 hildon_caption_size_request (GtkWidget *widget,
685 GtkRequisition *requisition)
688 HildonCaptionPrivate *priv = NULL;
689 g_return_if_fail (HILDON_IS_CAPTION(widget));
691 priv = HILDON_CAPTION_GET_PRIVATE (widget);
694 /* Use the same size requisition for the main box of the caption */
695 gtk_widget_size_request (priv->caption_area, &req);
697 if (GTK_WIDGET_CLASS (parent_class)->size_request)
698 GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition);
700 requisition->width += req.width + HILDON_CAPTION_SPACING * 3;
702 if ((req.height + (2 * widget->style->ythickness)) > requisition->height)
703 requisition->height = req.height + (2 * widget->style->ythickness);
706 /* We use HILDON_CAPTION_SPACING to make it look a bit nicer */
708 hildon_caption_size_allocate (GtkWidget *widget,
709 GtkAllocation *allocation)
711 GtkAllocation allocA;
712 GtkAllocation allocB;
714 GtkWidget *child = NULL;
715 HildonCaptionPrivate *priv = NULL;
717 g_assert (HILDON_IS_CAPTION (widget));
718 priv = HILDON_CAPTION_GET_PRIVATE (widget);
721 /* Position the caption to its allocated location */
722 if (GTK_WIDGET_REALIZED (widget))
723 gdk_window_move_resize (widget->window,
724 allocation->x + GTK_CONTAINER (widget)->border_width,
725 allocation->y + GTK_CONTAINER (widget)->border_width,
726 MAX (allocation->width - GTK_CONTAINER (widget)->border_width * 2, 0),
727 MAX (allocation->height - GTK_CONTAINER (widget)->border_width * 2, 0));
729 child = GTK_BIN (widget)->child;
731 widget->allocation = *allocation;
732 gtk_widget_get_child_requisition (priv->caption_area, &req);
734 allocA.height = allocB.height = allocation->height;
735 allocA.width = allocB.width = allocation->width;
736 allocA.x = allocB.x = allocB.y = allocA.y = 0;
738 /* Center the captioned widget */
739 if (allocA.width > req.width + HILDON_CAPTION_SPACING)
741 allocA.x += req.width + HILDON_CAPTION_SPACING * 2;
742 allocB.width = req.width;
745 /* Leave at least the space of the HILDON_CAPTION_SPACING in the left */
746 allocB.x = HILDON_CAPTION_SPACING;
748 /* Leave room for the other drawable parts of the caption control */
749 allocA.width -= req.width + HILDON_CAPTION_SPACING * 2;
751 /* Give the child at least its minimum requisition, unless it is expandable */
752 if (! priv->expand && child && GTK_WIDGET_VISIBLE(child))
754 GtkRequisition child_req;
755 gtk_widget_get_child_requisition (child, &child_req);
756 allocA.width = MIN (allocA.width, child_req.width);
757 allocA.height = MIN (allocA.height, child_req.height);
760 /* Ensure there are no negative dimensions */
761 if (allocA.width < 0)
763 allocB.width = req.width + allocA.width;
765 allocB.width = MAX (allocB.width, 0);
768 allocA.height = MAX (allocA.height, 0);
769 allocB.height = MAX (allocB.height, 0);
771 if (child && GTK_WIDGET_VISIBLE(child) )
772 gtk_widget_size_allocate( child, &allocA );
774 gtk_widget_size_allocate (priv->caption_area, &allocB);
778 hildon_caption_forall (GtkContainer *container,
779 gboolean include_internals,
780 GtkCallback callback,
783 HildonCaptionPrivate *priv = NULL;
785 g_assert (HILDON_IS_CAPTION (container));
786 g_assert (callback != NULL);
788 priv = HILDON_CAPTION_GET_PRIVATE (container);
791 /* Execute callback for the child widgets */
792 if (GTK_CONTAINER_CLASS (parent_class)->forall)
793 GTK_CONTAINER_CLASS (parent_class)->forall (container, include_internals, callback, data);
795 if (include_internals)
796 /* Execute callback for the parent box as well */
797 (*callback) (priv->caption_area, data);
801 * hildon_caption_set_sizegroup:
802 * @caption : a #HildonCaption
803 * @new_group : a #GtkSizeGroup
805 * Sets a #GtkSizeGroup of a given captioned control.
809 hildon_caption_set_size_group (const HildonCaption *self,
812 g_object_set (G_OBJECT(self), "size_group", group, NULL);
816 * hildon_caption_get_sizegroup:
817 * @caption : a #HildonCaption
819 * Query given captioned control for the #GtkSizeGroup assigned to it.
821 * @Returns : a #GtkSizeGroup
825 hildon_caption_get_size_group (const HildonCaption *self)
827 HildonCaptionPrivate *priv;
828 g_return_val_if_fail (HILDON_IS_CAPTION (self), NULL);
830 priv = HILDON_CAPTION_GET_PRIVATE(self);
837 * hildon_caption_new:
838 * @group : a #GtkSizeGroup for controlling the size of related captions,
840 * @value : the caption text to accompany the text entry. The widget makes
841 * a copy of this text.
842 * @control : the control that is to be captioned
843 * @icon : an icon to accompany the label - can be NULL in which case no
845 * @flag : indicates whether this captioned control is mandatory or
848 * Creates a new instance of hildon_caption widget, with a specific
850 * Note: Clicking on a focused caption will trigger the activate signal.
851 * The default behaviour for the caption's activate signal is to call
852 * gtk_widget_activate on it's control.
854 * @Returns : a #GtkWidget pointer of Caption
857 hildon_caption_new (GtkSizeGroup *group,
861 HildonCaptionStatus flag)
864 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
866 widget = g_object_new (HILDON_TYPE_CAPTION,
878 * hildon_caption_is_mandatory:
879 * @caption : a #HildonCaption
881 * Query #HildonCaption whether this captioned control is a mandatory one.
883 * @Returns : is this captioned control a mandatory one?
886 hildon_caption_is_mandatory (const HildonCaption *caption)
888 HildonCaptionPrivate *priv;
890 g_return_val_if_fail (HILDON_IS_CAPTION (caption), FALSE);
892 priv = HILDON_CAPTION_GET_PRIVATE (caption);
895 return (priv->status == HILDON_CAPTION_MANDATORY);
899 * hildon_caption_set_icon_position:
900 * @caption : a #HildonCaption
901 * @pos : one of the values from #HildonCaptionIconPosition
903 * Sets #HildonCaption icon position.
907 hildon_caption_set_icon_position (HildonCaption *caption,
908 HildonCaptionIconPosition pos)
910 g_return_if_fail (HILDON_IS_CAPTION (caption));
911 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (caption);
914 g_return_if_fail (priv->caption_area != NULL);
916 int order = (pos == HILDON_CAPTION_POSITION_LEFT) ? -1 : 0;
917 gtk_box_reorder_child (GTK_BOX (priv->caption_area), priv->icon_align, order);
919 priv->icon_position = pos;
923 * hildon_caption_get_icon_position:
924 * @caption : a #HildonCaption
926 * Gets #HildonCaption icon position.
928 * @Returns : one of the values from #HildonCaptionIconPosition.
932 HildonCaptionIconPosition
933 hildon_caption_get_icon_position (const HildonCaption *caption)
935 g_return_val_if_fail (HILDON_IS_CAPTION (caption), 0);
937 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (caption);
940 return priv->icon_position;
944 * hildon_caption_set_status:
945 * @caption : a #HildonCaption
946 * @flag : one of the values from #HildonCaptionStatus
948 * Sets #HildonCaption status.
951 hildon_caption_set_status (HildonCaption *caption,
952 HildonCaptionStatus flag)
954 g_return_if_fail (HILDON_IS_CAPTION(caption));
956 g_object_set (G_OBJECT(caption), "status", flag, NULL);
960 * hildon_caption_get_status:
961 * @caption : a #HildonCaption
963 * Gets #HildonCaption status.
965 * @Returns : one of the values from #HildonCaptionStatus
968 hildon_caption_get_status (const HildonCaption *caption)
970 HildonCaptionPrivate *priv;
971 g_return_val_if_fail (HILDON_IS_CAPTION (caption), HILDON_CAPTION_OPTIONAL);
973 priv = HILDON_CAPTION_GET_PRIVATE(caption);
980 * hildon_caption_set_icon_image:
981 * @caption : a #HildonCaption
982 * @icon : the #GtkImage to use as the icon.
983 * calls gtk_widget_show on the icon if !GTK_WIDGET_VISIBLE(icon)
985 * Sets the icon image widget to be used by this hildon_caption widget.
988 hildon_caption_set_icon_image (HildonCaption *caption,
991 g_return_if_fail (HILDON_IS_CAPTION(caption));
993 g_object_set (G_OBJECT(caption), "icon", icon, NULL);
997 * hildon_caption_get_icon_image:
998 * @caption : a #HildonCaption
1000 * Gets icon of #HildonCaption
1002 * @Returns : the #GtkImage widget that is being used as the icon by the
1003 * hildon_caption, or NULL if no icon image is in use.
1006 hildon_caption_get_icon_image (const HildonCaption *caption)
1008 HildonCaptionPrivate *priv;
1010 g_return_val_if_fail (HILDON_IS_CAPTION (caption), NULL);
1012 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1019 * hildon_caption_set_label:
1020 * @caption : a #HildonCaption
1021 * @label : the text to use
1023 * Sets the label text that appears before the control.
1024 * Separator character is added to the end of the label string. By default
1025 * the separator is ":".
1028 hildon_caption_set_label (HildonCaption *caption,
1031 g_return_if_fail (HILDON_IS_CAPTION(caption));
1033 g_object_set (G_OBJECT(caption), "label", label, NULL);
1037 * hildon_caption_get_label:
1038 * @caption : a #HildonCaption
1040 * Gets label of #HildonCaption
1042 * @Returns : the text currently being used as the label of the caption
1043 * control. The string is owned by the label and the caller should never
1044 * free or modify this value.
1047 hildon_caption_get_label (const HildonCaption *caption)
1049 HildonCaptionPrivate *priv;
1050 g_return_val_if_fail (HILDON_IS_CAPTION (caption), "");
1051 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1054 return (gchar*) gtk_label_get_text (GTK_LABEL (GTK_LABEL (priv->label)));
1058 * hildon_caption_set_separator:
1059 * @caption : a #HildonCaption
1060 * @separator : the separator to use
1062 * Sets the separator character that appears after the label.
1063 * The default seaparator character is ":"
1067 hildon_caption_set_separator (HildonCaption *caption,
1068 const gchar *separator)
1070 g_return_if_fail (HILDON_IS_CAPTION (caption));
1072 g_object_set (G_OBJECT (caption), "separator", separator, NULL);
1076 * hildon_caption_get_separator:
1077 * @caption : a #HildonCaption
1079 * Gets separator string of #HildonCaption
1081 * @Returns : the text currently being used as the separator of the caption
1082 * control. The string is owned by the caption control and the caller should
1083 * never free or modify this value.
1086 hildon_caption_get_separator (const HildonCaption *caption)
1088 HildonCaptionPrivate *priv;
1089 g_return_val_if_fail (HILDON_IS_CAPTION (caption), "");
1091 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1094 return priv->separator;
1097 /* Activates the child control
1098 * We have this signal so that if needed an application can
1099 * know when we've been activated (useful for captions with
1101 * FIXME: There never are multiple children. Possibly activate
1102 * signal could be removed entirely? (does anyone use it?)
1105 hildon_caption_activate (GtkWidget *widget)
1107 GtkWidget *child = GTK_BIN (widget)->child;
1108 gtk_widget_grab_focus (child);
1112 * hildon_caption_set_child_expand:
1113 * @caption : a #HildonCaption
1114 * @expand : gboolean to determine if the child is expandable
1116 * Sets child expandability.
1119 hildon_caption_set_child_expand (HildonCaption *caption,
1122 HildonCaptionPrivate *priv = NULL;
1123 GtkWidget *child = NULL;
1124 g_return_if_fail (HILDON_IS_CAPTION (caption));
1126 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1129 /* Did the setting really change? */
1130 if (priv->expand == expand)
1133 priv->expand = expand;
1134 child = GTK_BIN (caption)->child;
1136 /* We do not have a child, nothing to do */
1137 if (! GTK_IS_WIDGET (child))
1140 if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (caption))
1141 gtk_widget_queue_resize (child);
1143 gtk_widget_child_notify (child, "expand");
1147 * hildon_caption_get_child_expand:
1148 * @caption : a #HildonCaption
1150 * Gets childs expandability.
1152 * @Returns : wheter the child is expandable or not.
1155 hildon_caption_get_child_expand (const HildonCaption *caption)
1157 HildonCaptionPrivate *priv = NULL;
1158 g_return_val_if_fail (HILDON_IS_CAPTION (caption), FALSE);
1160 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1163 return priv->expand;
1167 hildon_caption_set_label_text (HildonCaptionPrivate *priv)
1170 g_assert (priv != NULL);
1174 if (priv->separator)
1176 /* Don't duplicate the separator, if the string already contains one */
1177 if (g_str_has_suffix (priv->text, priv->separator))
1179 gtk_label_set_text (GTK_LABEL (priv->label), priv->text);
1183 /* Append separator and set text */
1184 tmp = g_strconcat( priv->text, priv->separator, NULL );
1185 gtk_label_set_text (GTK_LABEL( priv->label), tmp);
1191 gtk_label_set_text (GTK_LABEL (priv->label), priv->text);
1196 /* Clear the label */
1197 gtk_label_set_text (GTK_LABEL (priv->label), "" );
1203 * hildon_caption_set_label_alignment:
1204 * @caption: a #HildonCaption widget
1205 * @alignment: new vertical alignment
1207 * Sets the vertical alignment to be used for the
1208 * text part of the caption. Applications need to
1209 * align the child control themselves.
1213 hildon_caption_set_label_alignment (HildonCaption *caption,
1216 HildonCaptionPrivate *priv;
1218 g_return_if_fail (HILDON_IS_CAPTION (caption));
1220 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1223 g_object_set (priv->label, "yalign", alignment, NULL);
1224 g_object_set (priv->icon_align, "yalign", alignment, NULL);
1229 * hildon_caption_get_label_alignment:
1230 * @caption: a #HildonCaption widget
1232 * Gets current vertical alignment for the text part.
1234 * Returns: vertical alignment
1238 hildon_caption_get_label_alignment (HildonCaption *caption)
1240 HildonCaptionPrivate *priv;
1243 g_return_val_if_fail (HILDON_IS_CAPTION (caption), 0);
1244 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1247 g_object_get (priv->label, "yalign", &result, NULL);