*
* Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
*
- * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
+ * Contact: Rodrigo Novo <rodrigo.novo@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
#include <config.h>
#endif
-#include "hildon-caption.h"
-#include <gtk/gtkhbox.h>
-#include <gtk/gtklabel.h>
-#include <gtk/gtkimage.h>
-#include <gtk/gtkentry.h>
-#include <gtk/gtkcombo.h>
-#include <gtk/gtkcombobox.h>
-#include <gtk/gtkcomboboxentry.h>
-#include <gtk/gtkoptionmenu.h>
-#include <gtk/gtkmarshal.h>
-#include <gtk/gtkalignment.h>
-#include <gtk/gtkcheckbutton.h>
-#include <stdio.h>
-#include <string.h>
-#include "hildon-defines.h"
#include <libintl.h>
+#include <gtk/gtk.h>
+
+#include "hildon-defines.h"
+#include "hildon-caption.h"
#include "hildon-caption-private.h"
#define _(String)\
GValue *value,
GParamSpec *pspec);
-static gboolean
-hildon_caption_expose (GtkWidget *widget,
- GdkEventExpose *event);
-
static void
hildon_caption_destroy (GtkObject *self);
*
* Initializes and returns the type of a hildon caption.
*
- * @Returns: GType of #HildonCaption
+ * Returns: GType of #HildonCaption
*/
GType G_GNUC_CONST
hildon_caption_get_type (void)
container_class->set_child_property = hildon_caption_set_child_property;
container_class->get_child_property = hildon_caption_get_child_property;
- widget_class->expose_event = hildon_caption_expose;
widget_class->hierarchy_changed = hildon_caption_hierarchy_changed;
widget_class->size_request = hildon_caption_size_request;
widget_class->size_allocate = hildon_caption_size_allocate;
G_SIGNAL_ACTION,
G_STRUCT_OFFSET (HildonCaptionClass,
activate), NULL, NULL,
- gtk_marshal_VOID__VOID,
+ g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
GTK_OBJECT_CLASS (parent_class)->destroy (self);
}
-/* Parent, eventbox will run allocate also for the child which may be
- * owning a window too. This window is then moved and resized
- * and we do not want to do that (it causes flickering).
- */
-static gboolean
-hildon_caption_expose (GtkWidget *widget,
- GdkEventExpose *event)
-{
- HildonCaptionPrivate *priv = NULL;
- GtkRequisition req;
- GtkAllocation alloc;
- gfloat align;
-
- g_assert (HILDON_IS_CAPTION (widget));
- priv = HILDON_CAPTION_GET_PRIVATE (widget);
- g_assert (priv);
-
- if (! GTK_WIDGET_DRAWABLE (widget))
- return FALSE;
-
- GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
-
- /* If our child control is focused, we draw nice looking focus
- graphics for the caption */
- if (priv->is_focused && priv->text)
- {
- /* Determine focus box dimensions */
- gtk_widget_get_child_requisition (priv->caption_area, &req);
- align = hildon_caption_get_label_alignment (HILDON_CAPTION(widget));
-
- alloc.width = priv->caption_area->allocation.width + HILDON_CAPTION_SPACING;
- alloc.height = MIN (req.height + (2 * widget->style->ythickness), priv->caption_area->allocation.height);
-
- alloc.x = priv->caption_area->allocation.x - HILDON_CAPTION_SPACING; /* - left margin */
- alloc.y = priv->caption_area->allocation.y +
- MAX (((priv->caption_area->allocation.height - alloc.height) * align), 0);
-
- /* Paint the focus box */
- gtk_paint_box (widget->style, widget->window, GTK_STATE_ACTIVE,
- GTK_SHADOW_OUT, NULL, widget, "selection",
- alloc.x, alloc.y, alloc.width, alloc.height);
-
- /* Paint caption contents on top of the focus box */
- GTK_WIDGET_GET_CLASS (priv->caption_area)->expose_event (priv->caption_area, event);
- }
-
- return FALSE;
-}
-
static void
hildon_caption_set_property (GObject *object,
guint param_id,
GParamSpec *pspec)
{
HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (object);
- g_assert (priv);
switch (param_id)
{
/* Initialize startup state */
priv = HILDON_CAPTION_GET_PRIVATE (caption);
- g_assert (priv);
priv->status = HILDON_CAPTION_OPTIONAL;
priv->icon = NULL;
GtkWidget *caption)
{
HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (caption);
- g_assert (priv);
/* check if ancestor gone */
if (! widget)
GtkWidget *previous_toplevel)
{
GtkWidget *current_ancestor;
- HildonCaptionPrivate *priv;
-
- priv = HILDON_CAPTION_GET_PRIVATE (widget);
- g_assert (priv);
if (GTK_WIDGET_CLASS (parent_class)->hierarchy_changed)
GTK_WIDGET_CLASS (parent_class)->hierarchy_changed (widget, previous_toplevel);
g_return_if_fail (HILDON_IS_CAPTION(widget));
priv = HILDON_CAPTION_GET_PRIVATE (widget);
- g_assert (priv);
/* Use the same size requisition for the main box of the caption */
gtk_widget_size_request (priv->caption_area, &req);
{
GtkAllocation child_alloc;
GtkAllocation caption_alloc;
- GtkRequisition req;
+ GtkRequisition req, child_req = {0};
GtkWidget *child = NULL;
HildonCaptionPrivate *priv = NULL;
+ gboolean rtl;
g_assert (HILDON_IS_CAPTION (widget));
priv = HILDON_CAPTION_GET_PRIVATE (widget);
- g_assert (priv);
+
+ /* Get the rtl status */
+ rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
/* Position the caption to its allocated location */
if (GTK_WIDGET_REALIZED (widget))
MAX (allocation->height - GTK_CONTAINER (widget)->border_width * 2, 0));
child = GTK_BIN (widget)->child;
+ if (child)
+ gtk_widget_get_child_requisition (child, &child_req);
widget->allocation = *allocation;
gtk_widget_get_child_requisition (priv->caption_area, &req);
child_alloc.x = caption_alloc.x = caption_alloc.y = child_alloc.y = 0;
/* Center the captioned widget */
- if (child_alloc.width > req.width + HILDON_CAPTION_SPACING)
+ if (rtl)
{
- child_alloc.x += req.width + HILDON_CAPTION_SPACING * 2;
- caption_alloc.width = req.width;
+ if (caption_alloc.width > child_req.width + HILDON_CAPTION_SPACING)
+ {
+ caption_alloc.x = caption_alloc.width - req.width;
+ child_alloc.width = child_req.width;
+ }
+ caption_alloc.width -= child_req.width + HILDON_CAPTION_SPACING * 2;
}
+ else
+ {
+ if (child_alloc.width > req.width + HILDON_CAPTION_SPACING)
+ {
+ child_alloc.x += req.width + HILDON_CAPTION_SPACING * 2;
+ caption_alloc.width = req.width;
+ }
+ /* Leave at least the space of the HILDON_CAPTION_SPACING in the left */
+ caption_alloc.x = HILDON_CAPTION_SPACING;
- /* Leave at least the space of the HILDON_CAPTION_SPACING in the left */
- caption_alloc.x = HILDON_CAPTION_SPACING;
-
- /* Leave room for the other drawable parts of the caption control */
- child_alloc.width -= req.width + HILDON_CAPTION_SPACING * 2;
+ /* Leave room for the other drawable parts of the caption control */
+ child_alloc.width -= req.width + HILDON_CAPTION_SPACING * 2;
+ }
/* Give the child at least its minimum requisition, unless it is expandable */
if (! priv->expand && child && GTK_WIDGET_VISIBLE(child))
{
- GtkRequisition child_req;
- gtk_widget_get_child_requisition (child, &child_req);
child_alloc.width = MIN (child_alloc.width, child_req.width);
child_alloc.height = MIN (child_alloc.height, child_req.height);
/* Center the child */
caption_alloc.width = MAX (caption_alloc.width, 0);
}
+ if (rtl)
+ child_alloc.x = caption_alloc.x - child_req.width - HILDON_CAPTION_SPACING * 2;
+
child_alloc.height = MAX (child_alloc.height, 0);
caption_alloc.height = MAX (caption_alloc.height, 0);
g_assert (callback != NULL);
priv = HILDON_CAPTION_GET_PRIVATE (container);
- g_assert (priv);
/* Execute callback for the child widgets */
if (GTK_CONTAINER_CLASS (parent_class)->forall)
*
* Query given captioned control for the #GtkSizeGroup assigned to it.
*
- * @Returns : a #GtkSizeGroup
+ * Returns: a #GtkSizeGroup
*
*/
GtkSizeGroup*
g_return_val_if_fail (HILDON_IS_CAPTION (self), NULL);
priv = HILDON_CAPTION_GET_PRIVATE(self);
- g_assert (priv);
return priv->group;
}
* The default behaviour for the caption's activate signal is to call
* gtk_widget_activate on it's control.
*
- * @Returns : a #GtkWidget pointer of Caption
+ * Returns: a #GtkWidget pointer of Caption
*/
GtkWidget*
hildon_caption_new (GtkSizeGroup *group,
*
* Query #HildonCaption whether this captioned control is a mandatory one.
*
- * @Returns : is this captioned control a mandatory one?
+ * Returns: is this captioned control a mandatory one?
*/
gboolean
hildon_caption_is_mandatory (const HildonCaption *caption)
g_return_val_if_fail (HILDON_IS_CAPTION (caption), FALSE);
priv = HILDON_CAPTION_GET_PRIVATE (caption);
- g_assert (priv);
return (priv->status == HILDON_CAPTION_MANDATORY);
}
{
g_return_if_fail (HILDON_IS_CAPTION (caption));
HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (caption);
- g_assert (priv);
g_return_if_fail (priv->caption_area != NULL);
*
* Gets #HildonCaption icon position.
*
- * @Returns : one of the values from #HildonCaptionIconPosition.
+ * Returns: one of the values from #HildonCaptionIconPosition.
*
*/
g_return_val_if_fail (HILDON_IS_CAPTION (caption), 0);
HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (caption);
- g_assert (priv);
return priv->icon_position;
}
/**
* hildon_caption_get_status:
- * @caption : a #HildonCaption
+ * @caption: a #HildonCaption
*
* Gets #HildonCaption status.
*
- * @Returns : one of the values from #HildonCaptionStatus
+ * Returns: one of the values from #HildonCaptionStatus
*/
HildonCaptionStatus
hildon_caption_get_status (const HildonCaption *caption)
g_return_val_if_fail (HILDON_IS_CAPTION (caption), HILDON_CAPTION_OPTIONAL);
priv = HILDON_CAPTION_GET_PRIVATE(caption);
- g_assert (priv);
return priv->status;
}
*
* Gets icon of #HildonCaption
*
- * @Returns : the #GtkImage widget that is being used as the icon by the
+ * Returns: the #GtkImage widget that is being used as the icon by the
* hildon_caption, or NULL if no icon image is in use.
*/
GtkWidget*
g_return_val_if_fail (HILDON_IS_CAPTION (caption), NULL);
priv = HILDON_CAPTION_GET_PRIVATE (caption);
- g_assert (priv);
return priv->icon;
}
*
* Gets label of #HildonCaption
*
- * @Returns : the text currently being used as the label of the caption
+ * Returns: the text currently being used as the label of the caption
* control. The string is owned by the label and the caller should never
* free or modify this value.
*/
HildonCaptionPrivate *priv;
g_return_val_if_fail (HILDON_IS_CAPTION (caption), "");
priv = HILDON_CAPTION_GET_PRIVATE (caption);
- g_assert (priv);
return (gchar*) gtk_label_get_text (GTK_LABEL (priv->label));
}
*
* Gets separator string of #HildonCaption
*
- * @Returns : the text currently being used as the separator of the caption
+ * Returns: the text currently being used as the separator of the caption
* control. The string is owned by the caption control and the caller should
* never free or modify this value.
*/
g_return_val_if_fail (HILDON_IS_CAPTION (caption), "");
priv = HILDON_CAPTION_GET_PRIVATE (caption);
- g_assert (priv);
return priv->separator;
}
g_return_if_fail (HILDON_IS_CAPTION (caption));
priv = HILDON_CAPTION_GET_PRIVATE (caption);
- g_assert (priv);
/* Did the setting really change? */
if (priv->expand == expand)
*
* Gets childs expandability.
*
- * @Returns : wheter the child is expandable or not.
+ * Returns: wheter the child is expandable or not.
*/
gboolean
hildon_caption_get_child_expand (const HildonCaption *caption)
g_return_val_if_fail (HILDON_IS_CAPTION (caption), FALSE);
priv = HILDON_CAPTION_GET_PRIVATE (caption);
- g_assert (priv);
return priv->expand;
}
g_return_if_fail (HILDON_IS_CAPTION (caption));
priv = HILDON_CAPTION_GET_PRIVATE (caption);
- g_assert (priv);
g_object_set (priv->label, "yalign", alignment, NULL);
g_object_set (priv->icon_align, "yalign", alignment, NULL);
g_return_val_if_fail (HILDON_IS_CAPTION (caption), 0);
priv = HILDON_CAPTION_GET_PRIVATE (caption);
- g_assert (priv);
g_object_get (priv->label, "yalign", &result, NULL);