2008-12-05 Claudio Saavedra <csaavedra@igalia.com>
[hildon] / src / hildon-caption.c
index a28171c..4632ee7 100644 (file)
 #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)\
@@ -226,7 +215,7 @@ hildon_caption_class_init                       (HildonCaptionClass *caption_cla
             G_SIGNAL_ACTION,
             G_STRUCT_OFFSET (HildonCaptionClass,
                 activate), NULL, NULL,
-            gtk_marshal_VOID__VOID,
+            g_cclosure_marshal_VOID__VOID,
             G_TYPE_NONE, 0);
 
     /**
@@ -576,12 +565,10 @@ static gboolean
 hildon_caption_button_press                     (GtkWidget *widget, 
                                                  GdkEventButton *event)
 {
-    HildonCaptionPrivate *priv = HILDON_CAPTION_GET_PRIVATE (widget);
-    g_assert (priv);
-    GtkWidget *child = GTK_BIN (widget)->child;
-
-    priv->is_focused = TRUE;
     gtk_widget_grab_focus (GTK_BIN (widget)->child);
+    
+    /* we'll update our focused state in set-focus when/if the child receives
+     * focus */
 
     return FALSE;
 }
@@ -722,14 +709,18 @@ hildon_caption_size_allocate                    (GtkWidget *widget,
 {
     GtkAllocation child_alloc;
     GtkAllocation caption_alloc;
-    GtkRequisition req;
+    GtkRequisition req, child_req;
     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))
         gdk_window_move_resize (widget->window,
@@ -739,6 +730,8 @@ hildon_caption_size_allocate                    (GtkWidget *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);
@@ -748,23 +741,32 @@ hildon_caption_size_allocate                    (GtkWidget *widget,
     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 */
@@ -780,6 +782,9 @@ hildon_caption_size_allocate                    (GtkWidget *widget,
         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);