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,
125 hildon_caption_set_child_property (GtkContainer *container,
132 hildon_caption_get_child_property (GtkContainer *container,
157 * hildon_caption_get_type:
159 * Initializes and returns the type of a hildon caption.
161 * @Returns: GType of #HildonCaption
164 hildon_caption_get_type (void)
166 static GType caption_type = 0;
170 static const GTypeInfo caption_info = {
171 sizeof (HildonCaptionClass),
172 NULL, /* base_init */
173 NULL, /* base_finalize */
174 (GClassInitFunc) hildon_caption_class_init,
175 NULL, /* class_finalize */
176 NULL, /* class_data */
177 sizeof (HildonCaption),
179 (GInstanceInitFunc) hildon_caption_init,
181 caption_type = g_type_register_static (GTK_TYPE_EVENT_BOX,
182 "HildonCaption", &caption_info, 0 );
188 * Initialises the caption class.
191 hildon_caption_class_init (HildonCaptionClass *caption_class)
193 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (caption_class);
194 GObjectClass *gobject_class = G_OBJECT_CLASS (caption_class);
195 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (caption_class);
197 parent_class = g_type_class_peek_parent (caption_class);
199 g_type_class_add_private (caption_class, sizeof (HildonCaptionPrivate));
201 /* Override virtual functions */
202 gobject_class->get_property = hildon_caption_get_property;
203 gobject_class->set_property = hildon_caption_set_property;
204 caption_class->activate = (gpointer) hildon_caption_activate;
205 GTK_OBJECT_CLASS(caption_class)->destroy = hildon_caption_destroy;
207 container_class->forall = hildon_caption_forall;
208 container_class->set_child_property = hildon_caption_set_child_property;
209 container_class->get_child_property = hildon_caption_get_child_property;
211 widget_class->expose_event = hildon_caption_expose;
212 widget_class->hierarchy_changed = hildon_caption_hierarchy_changed;
213 widget_class->size_request = hildon_caption_size_request;
214 widget_class->size_allocate = hildon_caption_size_allocate;
215 widget_class->button_press_event = hildon_caption_button_press;
217 /* Create new signals and properties */
218 widget_class->activate_signal = g_signal_new ("activate",
219 G_OBJECT_CLASS_TYPE (
223 G_STRUCT_OFFSET (HildonCaptionClass,
224 activate), NULL, NULL,
225 gtk_marshal_VOID__VOID,
229 * HildonCaption:label:
233 g_object_class_install_property (gobject_class, PROP_LABEL,
234 g_param_spec_string ("label",
235 "Current label", "Caption label",
236 NULL, G_PARAM_READABLE | G_PARAM_WRITABLE) );
239 * HildonCaption:markup:
241 * Caption markup. Mutually exclusive with label.
243 g_object_class_install_property (gobject_class, PROP_MARKUP,
244 g_param_spec_string ("markup",
245 "Current markup", "Caption markup",
246 NULL, G_PARAM_WRITABLE) );
249 * HildonCaption:icon:
251 * The icon shown on the caption area.
253 g_object_class_install_property (gobject_class, PROP_ICON,
254 g_param_spec_object ("icon",
256 "The icon shown on the caption area",
257 GTK_TYPE_WIDGET, G_PARAM_READABLE |
260 * HildonCaption:status:
262 * Mandatory or optional status.
264 g_object_class_install_property (gobject_class, PROP_STATUS,
265 g_param_spec_enum ("status",
267 "Mandatory or optional status",
268 HILDON_TYPE_CAPTION_STATUS,
269 HILDON_CAPTION_OPTIONAL,
270 G_PARAM_READABLE | G_PARAM_WRITABLE) );
272 * HildonCaption:icon-position:
274 * If the icon is positioned on the left or right side.
276 g_object_class_install_property (gobject_class, PROP_ICON_POSITION,
277 g_param_spec_enum ("icon-position",
279 "If the icon is on the left or right side",
280 HILDON_TYPE_CAPTION_ICON_POSITION,
281 HILDON_CAPTION_POSITION_RIGHT,
282 G_PARAM_READABLE | G_PARAM_WRITABLE) );
285 * HildonCaption:size_group:
287 * Current size group the caption is in.
289 g_object_class_install_property (gobject_class, PROP_SIZE_GROUP,
290 g_param_spec_object ("size_group",
291 "Current size group",
292 "Current size group the caption is in",
293 GTK_TYPE_SIZE_GROUP, G_PARAM_READABLE |
297 * HildonCaption:separator:
299 * The current separator.
301 g_object_class_install_property (gobject_class, PROP_SEPARATOR,
302 g_param_spec_string ("separator",
303 "Current separator", "Current separator",
304 _("ecdg_ti_caption_separator"),
305 G_PARAM_READABLE | G_PARAM_WRITABLE) );
307 /* Create child properties. These are related to
308 child <-> parent relationship, not to either of objects itself */
309 gtk_container_class_install_child_property (container_class,
311 g_param_spec_boolean ("expand",
312 "Same as GtkBox expand.",
313 "Same as GtkBox expand. Wheter the child should be expanded or not.",
318 /* Destroy can be called multiple times, remember to set pointers to NULL */
320 hildon_caption_destroy (GtkObject *self)
322 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (self);
324 /* Free our internal child */
325 if (priv && priv->caption_area)
327 gtk_widget_unparent (priv->caption_area);
328 priv->caption_area = NULL;
331 /* Free user provided strings */
332 if (priv && priv->text)
338 if (priv && priv->separator)
340 g_free (priv->separator);
341 priv->separator = NULL;
344 /* Parent classes destroy takes care of user packed contents */
345 if (GTK_OBJECT_CLASS (parent_class)->destroy)
346 GTK_OBJECT_CLASS (parent_class)->destroy (self);
349 /* Parent, eventbox will run allocate also for the child which may be
350 * owning a window too. This window is then moved and resized
351 * and we do not want to do that (it causes flickering).
354 hildon_caption_expose (GtkWidget *widget,
355 GdkEventExpose *event)
357 HildonCaptionPrivate *priv = NULL;
362 g_assert (HILDON_IS_CAPTION (widget));
363 priv = HILDON_CAPTION_GET_PRIVATE (widget);
366 if (! GTK_WIDGET_DRAWABLE (widget))
369 GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
371 /* If our child control is focused, we draw nice looking focus
372 graphics for the caption */
373 if (priv->is_focused && priv->text)
375 /* Determine focus box dimensions */
376 gtk_widget_get_child_requisition (priv->caption_area, &req);
377 align = hildon_caption_get_label_alignment (HILDON_CAPTION(widget));
379 alloc.width = priv->caption_area->allocation.width + HILDON_CAPTION_SPACING;
380 alloc.height = MIN (req.height + (2 * widget->style->ythickness), priv->caption_area->allocation.height);
382 alloc.x = priv->caption_area->allocation.x - HILDON_CAPTION_SPACING; /* - left margin */
383 alloc.y = priv->caption_area->allocation.y +
384 MAX (((priv->caption_area->allocation.height - alloc.height) * align), 0);
386 /* Paint the focus box */
387 gtk_paint_box (widget->style, widget->window, GTK_STATE_ACTIVE,
388 GTK_SHADOW_OUT, NULL, widget, "selection",
389 alloc.x, alloc.y, alloc.width, alloc.height);
391 /* Paint caption contents on top of the focus box */
392 GTK_WIDGET_GET_CLASS (priv->caption_area)->expose_event (priv->caption_area, event);
399 hildon_caption_set_property (GObject *object,
404 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (object);
409 case PROP_ICON_POSITION:
410 hildon_caption_set_icon_position (HILDON_CAPTION (object), g_value_get_enum (value));
414 /* Free old label string */
422 priv->text = g_value_dup_string (value);
423 hildon_caption_set_label_text (priv, FALSE);
427 /* Free old label string */
435 priv->text = g_value_dup_string (value);
436 hildon_caption_set_label_text (priv, TRUE);
440 /* Remove old icon */
442 gtk_container_remove (GTK_CONTAINER (priv->icon_align), priv->icon);
444 /* Pack and display new icon */
445 priv->icon = g_value_get_object (value);
448 gtk_container_add (GTK_CONTAINER (priv->icon_align), priv->icon);
449 gtk_widget_show_all (priv->caption_area);
454 priv->status = g_value_get_enum (value);
457 case PROP_SIZE_GROUP:
458 /* Detach from previous size group */
460 gtk_size_group_remove_widget (priv->group, priv->caption_area);
462 priv->group = g_value_get_object (value);
464 /* Attach to new size group */
466 gtk_size_group_add_widget (priv->group, priv->caption_area);
468 gtk_widget_queue_draw (GTK_WIDGET(object));
473 /* Free old separator */
476 g_free (priv->separator);
477 priv->separator = NULL;
480 priv->separator = g_value_dup_string (value);
481 hildon_caption_set_label_text (priv, FALSE);
485 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
491 hildon_caption_get_property (GObject *object,
496 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (object);
501 g_value_set_string (value, priv->text);
505 g_value_set_object (value, priv->icon);
509 g_value_set_enum (value, priv->status);
512 case PROP_ICON_POSITION:
513 g_value_set_enum (value, priv->icon_position);
516 case PROP_SIZE_GROUP:
517 g_value_set_object (value, priv->group);
521 g_value_set_string (value, priv->separator);
525 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
531 hildon_caption_set_child_property (GtkContainer *container,
539 case CHILD_PROP_EXPAND:
540 hildon_caption_set_child_expand (HILDON_CAPTION (container),
541 g_value_get_boolean (value));
545 G_OBJECT_WARN_INVALID_PROPERTY_ID (container, property_id, pspec);
551 hildon_caption_get_child_property (GtkContainer *container,
559 case CHILD_PROP_EXPAND:
560 g_value_set_boolean (value, hildon_caption_get_child_expand(
561 HILDON_CAPTION (container)));
565 G_OBJECT_WARN_INVALID_PROPERTY_ID(container, property_id, pspec);
570 /* We want to activate out child control on button press */
572 hildon_caption_button_press (GtkWidget *widget,
573 GdkEventButton *event)
575 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (widget);
577 GtkWidget *child = GTK_BIN (widget)->child;
580 if (priv->is_focused == TRUE)
583 /* If child can take focus, we simply grab focus to it */
584 if ((GTK_WIDGET_CAN_FOCUS (child) || GTK_IS_CONTAINER (child)) &&
585 GTK_WIDGET_IS_SENSITIVE (child))
587 /* Only if container can be focusable we must set is_focused to TRUE */
588 if (GTK_IS_CONTAINER (child))
590 if (gtk_widget_child_focus (child, GTK_DIR_TAB_FORWARD))
591 priv->is_focused = TRUE;
595 priv->is_focused = TRUE;
596 gtk_widget_grab_focus (GTK_BIN (widget)->child);
604 hildon_caption_init (HildonCaption *caption)
606 HildonCaptionPrivate *priv = NULL;
608 /* Initialize startup state */
609 priv = HILDON_CAPTION_GET_PRIVATE (caption);
612 priv->status = HILDON_CAPTION_OPTIONAL;
615 priv->is_focused = FALSE;
618 priv->separator = g_strdup(_("ecdg_ti_caption_separator"));
620 gtk_widget_push_composite_child();
622 /* Create caption text */
623 priv->caption_area = gtk_hbox_new (FALSE, HILDON_CAPTION_SPACING);
624 priv->label = gtk_label_new (NULL);
625 priv->icon_align = gtk_alignment_new (0.5f, 0.5f, 0.0f, 0.0f);
626 priv->icon_position = HILDON_CAPTION_POSITION_RIGHT;
628 /* We want to receive button presses for child widget activation */
629 gtk_event_box_set_above_child (GTK_EVENT_BOX (caption), FALSE);
630 gtk_widget_add_events (GTK_WIDGET (caption), GDK_BUTTON_PRESS_MASK);
632 /* Pack text label caption layout */
633 gtk_box_pack_end (GTK_BOX (priv->caption_area), priv->icon_align, FALSE, FALSE, 0);
634 gtk_box_pack_end (GTK_BOX (priv->caption_area), priv->label, FALSE, FALSE, 0);
635 gtk_widget_set_parent (priv->caption_area, GTK_WIDGET (caption));
637 gtk_widget_pop_composite_child ();
639 hildon_caption_set_child_expand (caption, TRUE);
641 gtk_widget_show_all (priv->caption_area);
645 hildon_caption_set_focus (GtkWindow *window,
649 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (caption);
652 /* check if ancestor gone */
658 /* Try to find caption among the ancestors of widget */
659 if (gtk_widget_is_ancestor (widget, caption))
661 priv->is_focused = TRUE;
662 gtk_widget_queue_draw (caption);
666 if (priv->is_focused == TRUE)
668 /* Caption wasn't found, so cannot focus */
669 priv->is_focused = FALSE;
670 gtk_widget_queue_draw (caption);
674 /* We need to connect/disconnect signal handlers to toplevel window
675 in which we reside. Ww want to update connected signals if our
678 hildon_caption_hierarchy_changed (GtkWidget *widget,
679 GtkWidget *previous_toplevel)
681 GtkWidget *current_ancestor;
682 HildonCaptionPrivate *priv;
684 priv = HILDON_CAPTION_GET_PRIVATE (widget);
687 if (GTK_WIDGET_CLASS (parent_class)->hierarchy_changed)
688 GTK_WIDGET_CLASS (parent_class)->hierarchy_changed (widget, previous_toplevel);
690 /* If we already were inside a window, remove old handler */
691 if (previous_toplevel) {
692 /* This is a compilation workaround for gcc > 3.3 since glib is buggy */
693 /* see http://bugzilla.gnome.org/show_bug.cgi?id=310175 */
697 g_signal_handlers_disconnect_by_func
698 (previous_toplevel, (gpointer) hildon_caption_set_focus, widget);
701 current_ancestor = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
703 /* Install new handler for focus movement */
704 if (current_ancestor)
705 g_signal_connect( current_ancestor, "set-focus",
706 G_CALLBACK (hildon_caption_set_focus), widget );
710 hildon_caption_size_request (GtkWidget *widget,
711 GtkRequisition *requisition)
714 HildonCaptionPrivate *priv = NULL;
715 g_return_if_fail (HILDON_IS_CAPTION(widget));
717 priv = HILDON_CAPTION_GET_PRIVATE (widget);
720 /* Use the same size requisition for the main box of the caption */
721 gtk_widget_size_request (priv->caption_area, &req);
723 if (GTK_WIDGET_CLASS (parent_class)->size_request)
724 GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition);
726 requisition->width += req.width + HILDON_CAPTION_SPACING * 3;
728 if ((req.height + (2 * widget->style->ythickness)) > requisition->height)
729 requisition->height = req.height + (2 * widget->style->ythickness);
732 /* We use HILDON_CAPTION_SPACING to make it look a bit nicer */
734 hildon_caption_size_allocate (GtkWidget *widget,
735 GtkAllocation *allocation)
737 GtkAllocation child_alloc;
738 GtkAllocation caption_alloc;
740 GtkWidget *child = NULL;
741 HildonCaptionPrivate *priv = NULL;
743 g_assert (HILDON_IS_CAPTION (widget));
744 priv = HILDON_CAPTION_GET_PRIVATE (widget);
747 /* Position the caption to its allocated location */
748 if (GTK_WIDGET_REALIZED (widget))
749 gdk_window_move_resize (widget->window,
750 allocation->x + GTK_CONTAINER (widget)->border_width,
751 allocation->y + GTK_CONTAINER (widget)->border_width,
752 MAX (allocation->width - GTK_CONTAINER (widget)->border_width * 2, 0),
753 MAX (allocation->height - GTK_CONTAINER (widget)->border_width * 2, 0));
755 child = GTK_BIN (widget)->child;
757 widget->allocation = *allocation;
758 gtk_widget_get_child_requisition (priv->caption_area, &req);
760 child_alloc.height = caption_alloc.height = allocation->height;
761 child_alloc.width = caption_alloc.width = allocation->width;
762 child_alloc.x = caption_alloc.x = caption_alloc.y = child_alloc.y = 0;
764 /* Center the captioned widget */
765 if (child_alloc.width > req.width + HILDON_CAPTION_SPACING)
767 child_alloc.x += req.width + HILDON_CAPTION_SPACING * 2;
768 caption_alloc.width = req.width;
771 /* Leave at least the space of the HILDON_CAPTION_SPACING in the left */
772 caption_alloc.x = HILDON_CAPTION_SPACING;
774 /* Leave room for the other drawable parts of the caption control */
775 child_alloc.width -= req.width + HILDON_CAPTION_SPACING * 2;
777 /* Give the child at least its minimum requisition, unless it is expandable */
778 if (! priv->expand && child && GTK_WIDGET_VISIBLE(child))
780 GtkRequisition child_req;
781 gtk_widget_get_child_requisition (child, &child_req);
782 child_alloc.width = MIN (child_alloc.width, child_req.width);
783 child_alloc.height = MIN (child_alloc.height, child_req.height);
784 /* Center the child */
785 child_alloc.y = (allocation->height - child_alloc.height -
786 2 * GTK_CONTAINER (widget)->border_width)/2;
789 /* Ensure there are no negative dimensions */
790 if (child_alloc.width < 0)
792 caption_alloc.width = req.width + child_alloc.width;
793 child_alloc.width = 0;
794 caption_alloc.width = MAX (caption_alloc.width, 0);
797 child_alloc.height = MAX (child_alloc.height, 0);
798 caption_alloc.height = MAX (caption_alloc.height, 0);
800 if (child && GTK_WIDGET_VISIBLE(child) )
801 gtk_widget_size_allocate (child, &child_alloc );
803 gtk_widget_size_allocate (priv->caption_area, &caption_alloc);
807 hildon_caption_forall (GtkContainer *container,
808 gboolean include_internals,
809 GtkCallback callback,
812 HildonCaptionPrivate *priv = NULL;
814 g_assert (HILDON_IS_CAPTION (container));
815 g_assert (callback != NULL);
817 priv = HILDON_CAPTION_GET_PRIVATE (container);
820 /* Execute callback for the child widgets */
821 if (GTK_CONTAINER_CLASS (parent_class)->forall)
822 GTK_CONTAINER_CLASS (parent_class)->forall (container, include_internals, callback, data);
824 if (include_internals)
825 /* Execute callback for the parent box as well */
826 (*callback) (priv->caption_area, data);
830 * hildon_caption_set_size_group:
831 * @caption : a #HildonCaption
832 * @new_group : a #GtkSizeGroup
834 * Sets a #GtkSizeGroup of a given captioned control.
838 hildon_caption_set_size_group (const HildonCaption *self,
841 g_object_set (G_OBJECT(self), "size_group", group, NULL);
845 * hildon_caption_get_size_group:
846 * @caption : a #HildonCaption
848 * Query given captioned control for the #GtkSizeGroup assigned to it.
850 * @Returns : a #GtkSizeGroup
854 hildon_caption_get_size_group (const HildonCaption *self)
856 HildonCaptionPrivate *priv;
857 g_return_val_if_fail (HILDON_IS_CAPTION (self), NULL);
859 priv = HILDON_CAPTION_GET_PRIVATE(self);
866 * hildon_caption_new:
867 * @group : a #GtkSizeGroup for controlling the size of related captions,
869 * @value : the caption text to accompany the text entry. The widget makes
870 * a copy of this text.
871 * @control : the control that is to be captioned
872 * @icon : an icon to accompany the label - can be NULL in which case no
874 * @flag : indicates whether this captioned control is mandatory or
877 * Creates a new instance of hildon_caption widget, with a specific
879 * Note: Clicking on a focused caption will trigger the activate signal.
880 * The default behaviour for the caption's activate signal is to call
881 * gtk_widget_activate on it's control.
883 * @Returns : a #GtkWidget pointer of Caption
886 hildon_caption_new (GtkSizeGroup *group,
890 HildonCaptionStatus flag)
893 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
895 widget = g_object_new (HILDON_TYPE_CAPTION,
903 /* Do not expand GtkCheckButton by default, we want to reduce its activation area */
904 if (GTK_IS_CHECK_BUTTON (child))
905 hildon_caption_set_child_expand (HILDON_CAPTION (widget), FALSE);
911 * hildon_caption_is_mandatory:
912 * @caption : a #HildonCaption
914 * Query #HildonCaption whether this captioned control is a mandatory one.
916 * @Returns : is this captioned control a mandatory one?
919 hildon_caption_is_mandatory (const HildonCaption *caption)
921 HildonCaptionPrivate *priv;
923 g_return_val_if_fail (HILDON_IS_CAPTION (caption), FALSE);
925 priv = HILDON_CAPTION_GET_PRIVATE (caption);
928 return (priv->status == HILDON_CAPTION_MANDATORY);
932 * hildon_caption_set_icon_position:
933 * @caption : a #HildonCaption
934 * @pos : one of the values from #HildonCaptionIconPosition
936 * Sets #HildonCaption icon position.
940 hildon_caption_set_icon_position (HildonCaption *caption,
941 HildonCaptionIconPosition pos)
943 g_return_if_fail (HILDON_IS_CAPTION (caption));
944 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (caption);
947 g_return_if_fail (priv->caption_area != NULL);
949 int order = (pos == HILDON_CAPTION_POSITION_LEFT) ? -1 : 0;
950 gtk_box_reorder_child (GTK_BOX (priv->caption_area), priv->icon_align, order);
952 priv->icon_position = pos;
956 * hildon_caption_get_icon_position:
957 * @caption : a #HildonCaption
959 * Gets #HildonCaption icon position.
961 * @Returns : one of the values from #HildonCaptionIconPosition.
965 HildonCaptionIconPosition
966 hildon_caption_get_icon_position (const HildonCaption *caption)
968 g_return_val_if_fail (HILDON_IS_CAPTION (caption), 0);
970 HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (caption);
973 return priv->icon_position;
977 * hildon_caption_set_status:
978 * @caption : a #HildonCaption
979 * @flag : one of the values from #HildonCaptionStatus
981 * Sets #HildonCaption status.
984 hildon_caption_set_status (HildonCaption *caption,
985 HildonCaptionStatus flag)
987 g_return_if_fail (HILDON_IS_CAPTION(caption));
989 g_object_set (G_OBJECT(caption), "status", flag, NULL);
993 * hildon_caption_get_status:
994 * @caption : a #HildonCaption
996 * Gets #HildonCaption status.
998 * @Returns : one of the values from #HildonCaptionStatus
1001 hildon_caption_get_status (const HildonCaption *caption)
1003 HildonCaptionPrivate *priv;
1004 g_return_val_if_fail (HILDON_IS_CAPTION (caption), HILDON_CAPTION_OPTIONAL);
1006 priv = HILDON_CAPTION_GET_PRIVATE(caption);
1009 return priv->status;
1013 * hildon_caption_set_icon_image:
1014 * @caption : a #HildonCaption
1015 * @icon : the #GtkImage to use as the icon.
1016 * calls gtk_widget_show on the icon if !GTK_WIDGET_VISIBLE(icon)
1018 * Sets the icon image widget to be used by this hildon_caption widget.
1021 hildon_caption_set_icon_image (HildonCaption *caption,
1024 g_return_if_fail (HILDON_IS_CAPTION(caption));
1026 g_object_set (G_OBJECT(caption), "icon", icon, NULL);
1030 * hildon_caption_get_icon_image:
1031 * @caption : a #HildonCaption
1033 * Gets icon of #HildonCaption
1035 * @Returns : the #GtkImage widget that is being used as the icon by the
1036 * hildon_caption, or NULL if no icon image is in use.
1039 hildon_caption_get_icon_image (const HildonCaption *caption)
1041 HildonCaptionPrivate *priv;
1043 g_return_val_if_fail (HILDON_IS_CAPTION (caption), NULL);
1045 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1052 * hildon_caption_set_label:
1053 * @caption : a #HildonCaption
1054 * @label : the text to use
1056 * Sets the label text that appears before the control.
1057 * Separator character is added to the end of the label string. By default
1058 * the separator is ":".
1061 hildon_caption_set_label (HildonCaption *caption,
1064 g_return_if_fail (HILDON_IS_CAPTION (caption));
1066 g_object_set (G_OBJECT(caption), "label", label, NULL);
1070 * hildon_caption_set_label_markup:
1071 * @caption : a #HildonCaption
1072 * @markup : the markup text to use
1074 * Sets the label markup text that appears before the control. It acts like
1075 * #hildon_caption_set_label but is using the markup text that allows to specify
1076 * text properties such as bold or italic.
1079 hildon_caption_set_label_markup (HildonCaption *caption,
1080 const gchar *markup)
1082 g_return_if_fail (HILDON_IS_CAPTION (caption));
1084 g_object_set (G_OBJECT(caption), "markup", markup, NULL);
1088 * hildon_caption_get_label:
1089 * @caption : a #HildonCaption
1091 * Gets label of #HildonCaption
1093 * @Returns : the text currently being used as the label of the caption
1094 * control. The string is owned by the label and the caller should never
1095 * free or modify this value.
1098 hildon_caption_get_label (const HildonCaption *caption)
1100 HildonCaptionPrivate *priv;
1101 g_return_val_if_fail (HILDON_IS_CAPTION (caption), "");
1102 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1105 return (gchar*) gtk_label_get_text (GTK_LABEL (priv->label));
1109 * hildon_caption_set_separator:
1110 * @caption : a #HildonCaption
1111 * @separator : the separator to use
1113 * Sets the separator character that appears after the label.
1114 * The default seaparator character is ":"
1118 hildon_caption_set_separator (HildonCaption *caption,
1119 const gchar *separator)
1121 g_return_if_fail (HILDON_IS_CAPTION (caption));
1123 g_object_set (G_OBJECT (caption), "separator", separator, NULL);
1127 * hildon_caption_get_separator:
1128 * @caption : a #HildonCaption
1130 * Gets separator string of #HildonCaption
1132 * @Returns : the text currently being used as the separator of the caption
1133 * control. The string is owned by the caption control and the caller should
1134 * never free or modify this value.
1137 hildon_caption_get_separator (const HildonCaption *caption)
1139 HildonCaptionPrivate *priv;
1140 g_return_val_if_fail (HILDON_IS_CAPTION (caption), "");
1142 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1145 return priv->separator;
1148 /* Activates the child control
1149 * We have this signal so that if needed an application can
1150 * know when we've been activated (useful for captions with
1152 * FIXME: There never are multiple children. Possibly activate
1153 * signal could be removed entirely? (does anyone use it?)
1156 hildon_caption_activate (GtkWidget *widget)
1158 GtkWidget *child = GTK_BIN (widget)->child;
1159 gtk_widget_grab_focus (child);
1163 * hildon_caption_set_child_expand:
1164 * @caption : a #HildonCaption
1165 * @expand : gboolean to determine if the child is expandable
1167 * Sets child expandability.
1170 hildon_caption_set_child_expand (HildonCaption *caption,
1173 HildonCaptionPrivate *priv = NULL;
1174 GtkWidget *child = NULL;
1175 g_return_if_fail (HILDON_IS_CAPTION (caption));
1177 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1180 /* Did the setting really change? */
1181 if (priv->expand == expand)
1184 priv->expand = expand;
1185 child = GTK_BIN (caption)->child;
1187 /* We do not have a child, nothing to do */
1188 if (! GTK_IS_WIDGET (child))
1191 if (GTK_WIDGET_VISIBLE (child) && GTK_WIDGET_VISIBLE (caption))
1192 gtk_widget_queue_resize (child);
1194 gtk_widget_child_notify (child, "expand");
1198 * hildon_caption_get_child_expand:
1199 * @caption : a #HildonCaption
1201 * Gets childs expandability.
1203 * @Returns : wheter the child is expandable or not.
1206 hildon_caption_get_child_expand (const HildonCaption *caption)
1208 HildonCaptionPrivate *priv = NULL;
1209 g_return_val_if_fail (HILDON_IS_CAPTION (caption), FALSE);
1211 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1214 return priv->expand;
1218 hildon_caption_set_label_text (HildonCaptionPrivate *priv,
1222 g_assert (priv != NULL);
1226 if (priv->separator)
1228 /* Don't duplicate the separator, if the string already contains one */
1229 if (g_str_has_suffix (priv->text, priv->separator))
1232 gtk_label_set_markup (GTK_LABEL (priv->label), priv->text);
1234 gtk_label_set_text (GTK_LABEL (priv->label), priv->text);
1238 /* Append separator and set text */
1239 tmp = g_strconcat( priv->text, priv->separator, NULL );
1242 gtk_label_set_markup (GTK_LABEL (priv->label), tmp);
1244 gtk_label_set_text (GTK_LABEL (priv->label), tmp);
1252 gtk_label_set_markup (GTK_LABEL (priv->label), priv->text);
1254 gtk_label_set_text (GTK_LABEL (priv->label), priv->text);
1259 /* Clear the label */
1261 gtk_label_set_markup (GTK_LABEL (priv->label), "");
1263 gtk_label_set_text (GTK_LABEL (priv->label), "" );
1268 * hildon_caption_set_label_alignment:
1269 * @caption: a #HildonCaption widget
1270 * @alignment: new vertical alignment
1272 * Sets the vertical alignment to be used for the
1273 * text part of the caption. Applications need to
1274 * align the child control themselves.
1278 hildon_caption_set_label_alignment (HildonCaption *caption,
1281 HildonCaptionPrivate *priv;
1283 g_return_if_fail (HILDON_IS_CAPTION (caption));
1285 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1288 g_object_set (priv->label, "yalign", alignment, NULL);
1289 g_object_set (priv->icon_align, "yalign", alignment, NULL);
1294 * hildon_caption_get_label_alignment:
1295 * @caption: a #HildonCaption widget
1297 * Gets current vertical alignment for the text part.
1299 * Returns: vertical alignment
1303 hildon_caption_get_label_alignment (HildonCaption *caption)
1305 HildonCaptionPrivate *priv;
1308 g_return_val_if_fail (HILDON_IS_CAPTION (caption), 0);
1309 priv = HILDON_CAPTION_GET_PRIVATE (caption);
1312 g_object_get (priv->label, "yalign", &result, NULL);