X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=hildon%2Fhildon-picker-dialog.c;h=094787704d455cfa3fa9a7ba82c88129458fdeb6;hb=e7ebb4366bbce4a0a9b7b4a04a7e7f0464a0159c;hp=5539c99d6f03cc96e7087c68929bc8dad9ca175a;hpb=69a11338fe0cc36a868e5812b590f5437622988a;p=hildon diff --git a/hildon/hildon-picker-dialog.c b/hildon/hildon-picker-dialog.c index 5539c99..0947877 100644 --- a/hildon/hildon-picker-dialog.c +++ b/hildon/hildon-picker-dialog.c @@ -1,7 +1,7 @@ /* * 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 @@ -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)); } @@ -211,6 +239,8 @@ hildon_picker_dialog_init (HildonPickerDialog * dialog) 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; @@ -296,6 +326,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 +372,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) @@ -321,9 +416,15 @@ selection_completed (HildonPickerDialog *dialog) 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); @@ -449,7 +550,7 @@ _save_current_selection (HildonPickerDialog *dialog) } 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))); } } @@ -495,7 +596,7 @@ _restore_current_selection (HildonPickerDialog *dialog) } 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); @@ -512,10 +613,8 @@ static void 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); } } @@ -586,10 +685,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);