/*
* This file is a part of hildon
*
- * Copyright (C) 2005, 2008 Nokia Corporation.
+ * Copyright (C) 2005, 2008, 2009 Nokia Corporation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
G_DEFINE_TYPE (HildonPickerDialog, hildon_picker_dialog, HILDON_TYPE_DIALOG)
-#define HILDON_TOUCH_SELECTOR_HEIGHT 320
-
struct _HildonPickerDialogPrivate
{
GtkWidget *selector;
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);
static void
_clean_current_selection (HildonPickerDialog *dialog);
+static guint
+hildon_picker_dialog_get_max_height (HildonPickerDialog *dialog);
+
/**********************************************************************************/
static void
/* 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;
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));
}
dialog->priv->button =
gtk_dialog_add_button (GTK_DIALOG (dialog), "", GTK_RESPONSE_OK);
gtk_widget_grab_default (dialog->priv->button);
+ gtk_button_set_focus_on_click (GTK_BUTTON (dialog->priv->button), FALSE);
+ gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
dialog->priv->signal_changed_id = 0;
dialog->priv->signal_columns_changed_id = 0;
}
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));
/* ------------------------------ 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)
GList *list;
gint i, n_cols;
gboolean all_selected = TRUE;
+ HildonUIMode mode = HILDON_UI_MODE_NORMAL;
priv = HILDON_PICKER_DIALOG_GET_PRIVATE (dialog);
+ mode = hildon_touch_selector_get_hildon_ui_mode (HILDON_TOUCH_SELECTOR (priv->selector));
+ if (mode == HILDON_UI_MODE_NORMAL) {
+ return TRUE;
+ }
+
n_cols = hildon_touch_selector_get_num_columns (HILDON_TOUCH_SELECTOR (priv->selector));
for (i = 0; i < n_cols; i++) {
list = hildon_touch_selector_get_selected_rows (HILDON_TOUCH_SELECTOR (priv->selector), i);
}
if (HILDON_IS_TOUCH_SELECTOR_ENTRY (selector)) {
HildonEntry *entry = hildon_touch_selector_entry_get_entry (HILDON_TOUCH_SELECTOR_ENTRY (selector));
- dialog->priv->current_text = g_strdup (hildon_entry_get_text (entry));
+ dialog->priv->current_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
}
}
}
if (HILDON_IS_TOUCH_SELECTOR_ENTRY (selector) && dialog->priv->current_text != NULL) {
HildonEntry *entry = hildon_touch_selector_entry_get_entry (HILDON_TOUCH_SELECTOR_ENTRY (selector));
- hildon_entry_set_text (entry, dialog->priv->current_text);
+ gtk_entry_set_text (GTK_ENTRY (entry), dialog->priv->current_text);
}
if (dialog->priv->signal_changed_id)
g_signal_handler_unblock (selector, dialog->priv->signal_changed_id);
prepare_action_area (HildonPickerDialog *dialog)
{
if (requires_done_button (dialog)) {
- gtk_dialog_set_has_separator (GTK_DIALOG (dialog), TRUE);
gtk_widget_show (GTK_DIALOG (dialog)->action_area);
} else {
- gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
gtk_widget_hide (GTK_DIALOG (dialog)->action_area);
}
}
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);