Fixed the hard-coded height in HildonPickerDialog
authorAlejandro Piñeiro <apinheiro@igalia.com>
Wed, 6 May 2009 16:20:11 +0000 (18:20 +0200)
committerAlejandro Piñeiro <apinheiro@igalia.com>
Wed, 6 May 2009 16:34:29 +0000 (18:34 +0200)
* hildon/hildon-touch-selector.[ch]
(hildon_touch_selector_optimal_size_request): function added to get a
optimal size request from the touch selector, when you want a dialog to
show as much of the selector
* hildon/hildon-picker-dialog.c:
Removed HILDON_TOUCH_SELECTOR_HEIGHT macro
(hildon_app_menu_class_init):
New "max-height-landscape" and "max-height-portrait" style properties
(hildon_picker_dialog_size_request): redefined GtkWidget::size_request
(hildon_picker_dialog_get_max_height): returns the maximum height using
the style properties defined and checking the current portrait/landscape
status
(_hildon_picker_dialog_set_selector): removed the set_size_request

Fixes: NB#109369 (Hard-coded height in HildonPickerDialog)

ChangeLog
hildon/hildon-picker-dialog.c
hildon/hildon-touch-selector.c
hildon/hildon-touch-selector.h

index d5b89c3..26e8e2d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2009-05-06 Alejandro Pinheiro <apinheiro@igalia.com>
+
+       * hildon/hildon-touch-selector.[ch]
+       (hildon_touch_selector_optimal_size_request): function added to get a
+       optimal size request from the touch selector, when you want a dialog to
+       show as much of the selector
+       * hildon/hildon-picker-dialog.c:
+       Removed HILDON_TOUCH_SELECTOR_HEIGHT macro
+       (hildon_app_menu_class_init):
+       New "max-height-landscape" and "max-height-portrait" style properties
+       (hildon_picker_dialog_size_request): redefined GtkWidget::size_request
+       (hildon_picker_dialog_get_max_height): returns the maximum height using
+       the style properties defined and checking the current portrait/landscape
+       status
+       (_hildon_picker_dialog_set_selector): removed the set_size_request
+
+       Fixes: NB#109369 (Hard-coded height in HildonPickerDialog)
+
 2009-05-06  Claudio Saavedra  <csaavedra@igalia.com>
 
        * hildon/hildon-bread-crumb-trail.c:
index 5539c99..87afb52 100644 (file)
@@ -54,8 +54,6 @@
 
 G_DEFINE_TYPE (HildonPickerDialog, hildon_picker_dialog, HILDON_TYPE_DIALOG)
 
-#define HILDON_TOUCH_SELECTOR_HEIGHT            320
-
 struct _HildonPickerDialogPrivate
 {
   GtkWidget *selector;
@@ -107,6 +105,10 @@ hildon_picker_dialog_show                       (GtkWidget *widget);
 static void
 hildon_picker_dialog_realize                    (GtkWidget *widget);
 
+static void
+hildon_picker_dialog_size_request               (GtkWidget *widget,
+                                                 GtkRequisition *requisition);
+
 /* private functions */
 static gboolean
 requires_done_button                            (HildonPickerDialog * dialog);
@@ -140,6 +142,9 @@ _restore_current_selection                      (HildonPickerDialog *dialog);
 static void
 _clean_current_selection                        (HildonPickerDialog *dialog);
 
+static guint
+hildon_picker_dialog_get_max_height             (HildonPickerDialog *dialog);
+
 /**********************************************************************************/
 
 static void
@@ -163,6 +168,7 @@ hildon_picker_dialog_class_init (HildonPickerDialogClass * class)
   /* GtkWidget */
   widget_class->show = hildon_picker_dialog_show;
   widget_class->realize = hildon_picker_dialog_realize;
+  widget_class->size_request = hildon_picker_dialog_size_request,
 
   /* HildonPickerDialog */
   class->set_selector = _hildon_picker_dialog_set_selector;
@@ -198,6 +204,28 @@ hildon_picker_dialog_class_init (HildonPickerDialogClass * class)
                                                          G_PARAM_READWRITE |
                                                          G_PARAM_CONSTRUCT));
 
+  /* Using the default height, we get 5 full rows. With the header it sums 404 pixels */
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_uint
+                                           ("max-height-landscape",
+                                            "Max dialog height on landscape mode",
+                                            "Maximum dialog height on landscape mode",
+                                            0,
+                                            G_MAXUINT,
+                                            358,
+                                            G_PARAM_READWRITE));
+
+  /* Using the default height, we get 9 full rows. With the header it sums 684 pixels */
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_uint
+                                           ("max-height-portrait",
+                                            "Max dialog height on portrait mode",
+                                            "Maximum dialog height on portrait mode",
+                                            0,
+                                            G_MAXUINT,
+                                            638,
+                                            G_PARAM_READWRITE));
+
   g_type_class_add_private (object_class, sizeof (HildonPickerDialogPrivate));
 }
 
@@ -296,6 +324,43 @@ hildon_picker_dialog_show                       (GtkWidget *widget)
 }
 
 static void
+hildon_picker_dialog_size_request               (GtkWidget *widget,
+                                                 GtkRequisition *requisition)
+{
+  HildonTouchSelector *selector;
+
+  selector = hildon_picker_dialog_get_selector (HILDON_PICKER_DIALOG (widget));
+
+  if (selector) {
+    GtkRequisition child_requisition;
+    GtkRequisition optimal_requisition;
+    GtkBin *bin;
+    guint max_height;
+
+    bin = GTK_BIN (widget);
+
+    requisition->width = GTK_CONTAINER (widget)->border_width * 2;
+    /* Adding pannable container border using 4 instead of 2 */
+    requisition->height = GTK_CONTAINER (widget)->border_width * 4;
+
+    /* assure the requisition is done */
+    gtk_widget_size_request (bin->child, &child_requisition);
+
+    hildon_touch_selector_optimal_size_request (selector,
+                                                &optimal_requisition);
+
+    requisition->width += child_requisition.width;
+
+    max_height = hildon_picker_dialog_get_max_height (HILDON_PICKER_DIALOG (widget));
+
+    requisition->height = MIN (max_height,
+                               requisition->height + optimal_requisition.height);
+  } else
+    GTK_WIDGET_CLASS (hildon_picker_dialog_parent_class)->size_request
+      (widget, requisition);
+}
+
+static void
 hildon_picker_dialog_realize (GtkWidget *widget)
 {
   setup_interaction_mode (HILDON_PICKER_DIALOG (widget));
@@ -305,6 +370,34 @@ hildon_picker_dialog_realize (GtkWidget *widget)
 
 /* ------------------------------ PRIVATE METHODS ---------------------------- */
 
+static guint
+hildon_picker_dialog_get_max_height             (HildonPickerDialog *dialog)
+{
+  gboolean landscape = TRUE;
+  guint max_value = 0;
+  GdkScreen *screen = NULL;
+
+  screen = gtk_widget_get_screen (GTK_WIDGET (dialog));
+  if (screen != NULL) {
+    if (gdk_screen_get_width (screen) > gdk_screen_get_height (screen)) {
+      landscape = TRUE;
+    } else {
+      landscape = FALSE;
+    }
+  }
+
+  if (landscape) {
+    gtk_widget_style_get (GTK_WIDGET (dialog), "max-height-landscape",
+                          &max_value, NULL);
+  } else {
+    gtk_widget_style_get (GTK_WIDGET (dialog), "max-height-portrait",
+                          &max_value, NULL);
+  }
+
+  return max_value;
+}
+
+
 static void
 _select_on_selector_changed_cb (HildonTouchSelector * selector,
                                 gint column, gpointer data)
@@ -586,10 +679,6 @@ _hildon_picker_dialog_set_selector (HildonPickerDialog * dialog,
 
   g_object_unref (selector);
 
-  /* Ensure that the dialog's height is correct */
-  gtk_widget_set_size_request (GTK_WIDGET (dialog->priv->selector), -1,
-                               HILDON_TOUCH_SELECTOR_HEIGHT);
-
   gtk_widget_show (dialog->priv->selector);
 
   prepare_action_area (dialog);
index 6a4d323..7d4c859 100644 (file)
@@ -2157,3 +2157,65 @@ hildon_touch_selector_center_on_selected         (HildonTouchSelector *selector)
                                                     HILDON_TOUCH_SELECTOR_COLUMN (iter->data));
   }
 }
+
+/**
+ * hildon_touch_selector_optimal_size_request
+ * @selector: a #HildonTouchSelector
+ * @requisition: a #GtkRequisition
+ *
+ * Gets the optimal size request of the touch selector. This function is mostly
+ * intended for dialog implementations that include a #HildonTouchSelector and
+ * want to optimize the screen real state, for example, when you want a dialog
+ * to show as much of the selector, avoiding any extra empty space below the
+ * selector.
+ *
+ * See #HildonPickerDialog implementation for an example.
+ *
+ * This function is oriented to be used in the size_request of a dialog or window,
+ * if you are not sure do not use it.
+ *
+ * There is a precondition to this function: Since this function does not
+ * call the "size_request" method, it can only be used when you know that
+ * gtk_widget_size_request() has been called since the last time a resize was
+ * queued.
+ *
+ * Since: 2.2
+ **/
+void
+hildon_touch_selector_optimal_size_request      (HildonTouchSelector *selector,
+                                                 GtkRequisition *requisition)
+{
+  GSList *iter = NULL;
+  gint height = 0;
+
+  g_return_if_fail (HILDON_IS_TOUCH_SELECTOR (selector));
+
+  iter = selector->priv->columns;
+
+  /* Default optimal values are the current ones */
+  gtk_widget_get_child_requisition (GTK_WIDGET (selector),
+                                    requisition);
+
+  if (iter == NULL) {
+    height = requisition->height;
+  }
+
+  /* Compute optimal height */
+  while (iter) {
+    HildonTouchSelectorColumn *column;
+    GtkWidget *child;
+    GtkRequisition child_requisition = {0};
+
+    column = HILDON_TOUCH_SELECTOR_COLUMN (iter->data);
+    child = GTK_WIDGET (column->priv->tree_view);
+
+    gtk_widget_get_child_requisition (child, &child_requisition);
+
+    height = MAX (height, child_requisition.height);
+
+    iter = g_slist_next (iter);
+  }
+
+  requisition->height = height;
+}
+
index 14b4d9f..6f3022c 100644 (file)
@@ -215,6 +215,10 @@ hildon_touch_selector_has_multiple_selection    (HildonTouchSelector *selector);
 void
 hildon_touch_selector_center_on_selected        (HildonTouchSelector *selector);
 
+void
+hildon_touch_selector_optimal_size_request      (HildonTouchSelector *selector,
+                                                 GtkRequisition *requisition);
+
 G_END_DECLS
 
 #endif /* __HILDON_TOUCH_SELECTOR_H__ */