From 7d85757776f42ce6214b617d4cc42eb9fcbd3e4a Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 4 Aug 2008 23:40:36 +0000 Subject: [PATCH] =?UTF-8?q?Bug=20382291=20=E2=80=93=20Automatically=20dim?= =?UTF-8?q?=20the=20combobox=20when=20the=20model=20is=20empty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2008-08-04 Matthias Clasen Bug 382291 – Automatically dim the combobox when the model is empty * gtk/gtk.symbols: * gtkcombobox.[hc]: Add a GtkComboBox::button-sensitivity property with getter and setter to control the sensitity of empty combo boxes. Patch by Carlos Garnacho, Sven Herzberg, Christian Dywan and others. * README.in: Add a note about automatic combobox sensitivity. svn path=/trunk/; revision=20997 --- ChangeLog | 10 +-- README.in | 6 ++ docs/reference/ChangeLog | 4 + docs/reference/gtk/gtk-sections.txt | 2 + gtk/gtk.symbols | 2 + gtk/gtkcombobox.c | 113 +++++++++++++++++++++++++++- gtk/gtkcombobox.h | 4 + 7 files changed, 135 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0ec0758c23..6f5f0e60ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,13 +1,13 @@ -2008-08-05 Tor Lillqvist - - * gtk/updateiconcache.c (write_bucket): Enclose ?: expression - with parens so cast covers all of it. - 2008-08-04 Matthias Clasen * gtk/gtksettings.c: Improve a setting nick: 'aureal' is not really a word, use 'audible' instead. +2008-08-05 Tor Lillqvist + + * gtk/updateiconcache.c (write_bucket): Enclose ?: expression + with parens so cast covers all of it. + 2008-08-04 Matthias Clasen Bug 382291 – Automatically dim the combobox when the model is empty diff --git a/README.in b/README.in index 908358f215..71b6538206 100644 --- a/README.in +++ b/README.in @@ -42,6 +42,12 @@ Release notes for 2.14 the GtkFileSystem interface is no longer available, nor the filechooser will load any GtkFileSystem implementation. +* GtkComboBox now renders the popdown button insensitive when + the model is empty. Applications which want to populate the list + only before displaying it can set gtk_combo_box_set_button_sensitivity + to GTK_SENSITIVITY_ON, so that the button is always sensitive or + GTK_SENSITIVITY_OFF to make it insensitive respectively. + Release notes for 2.12 ====================== diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 2cb03367d4..8838760872 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,7 @@ +2008-08-04 Matthias Clasen + + * gtk/gtk-sections.txt: Add new functions + 2008-08-02 Matthias Clasen * gtk/gtk-sections.txt: Add new functions diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt index 83ea0dd21d..21571a7519 100644 --- a/docs/reference/gtk/gtk-sections.txt +++ b/docs/reference/gtk/gtk-sections.txt @@ -895,6 +895,8 @@ gtk_combo_box_set_title gtk_combo_box_get_title gtk_combo_box_set_focus_on_click gtk_combo_box_get_focus_on_click +gtk_combo_box_set_button_sensitivity +gtk_combo_box_get_button_sensitivity GTK_TYPE_COMBO_BOX GTK_COMBO_BOX diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index 0c4a436b8d..acb5286c27 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -853,6 +853,7 @@ gtk_combo_box_get_model gtk_combo_box_get_popup_accessible gtk_combo_box_get_row_separator_func gtk_combo_box_get_row_span_column +gtk_combo_box_get_button_sensitivity gtk_combo_box_get_title gtk_combo_box_get_type G_GNUC_CONST gtk_combo_box_get_wrap_width @@ -872,6 +873,7 @@ gtk_combo_box_set_focus_on_click gtk_combo_box_set_model gtk_combo_box_set_row_separator_func gtk_combo_box_set_row_span_column +gtk_combo_box_set_button_sensitivity gtk_combo_box_set_title gtk_combo_box_set_wrap_width #endif diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c index 14a6bec9df..0a081d11a5 100644 --- a/gtk/gtkcombobox.c +++ b/gtk/gtkcombobox.c @@ -120,6 +120,7 @@ struct _GtkComboBoxPrivate guint editing_canceled : 1; guint auto_scroll : 1; guint focus_on_click : 1; + guint button_sensitivity : 2; GtkTreeViewRowSeparatorFunc row_separator_func; gpointer row_separator_data; @@ -201,7 +202,8 @@ enum { PROP_TEAROFF_TITLE, PROP_HAS_FRAME, PROP_FOCUS_ON_CLICK, - PROP_POPUP_SHOWN + PROP_POPUP_SHOWN, + PROP_BUTTON_SENSITIVITY }; static guint combo_box_signals[LAST_SIGNAL] = {0,}; @@ -822,6 +824,24 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass) FALSE, GTK_PARAM_READABLE)); + + /** + * GtkComboBox:button-sensitivity: + * + * Whether the dropdown button is sensitive when + * the model is empty. + * + * Since: 2.14 + */ + g_object_class_install_property (object_class, + PROP_BUTTON_SENSITIVITY, + g_param_spec_enum ("button-sensitivity", + P_("Button Sensitivity"), + P_("Whether the dropdown button is sensitive when the model is empty"), + GTK_TYPE_SENSITIVITY_TYPE, + GTK_SENSITIVITY_AUTO, + GTK_PARAM_READWRITE)); + gtk_widget_class_install_style_property (widget_class, g_param_spec_boolean ("appears-as-list", P_("Appears as list"), @@ -919,6 +939,7 @@ gtk_combo_box_init (GtkComboBox *combo_box) priv->editing_canceled = FALSE; priv->auto_scroll = FALSE; priv->focus_on_click = TRUE; + priv->button_sensitivity = GTK_SENSITIVITY_AUTO; combo_box->priv = priv; @@ -979,6 +1000,11 @@ gtk_combo_box_set_property (GObject *object, gtk_combo_box_popdown (combo_box); break; + case PROP_BUTTON_SENSITIVITY: + gtk_combo_box_set_button_sensitivity (combo_box, + g_value_get_enum (value)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -1035,6 +1061,10 @@ gtk_combo_box_get_property (GObject *object, g_value_set_boolean (value, combo_box->priv->popup_shown); break; + case PROP_BUTTON_SENSITIVITY: + g_value_set_enum (value, combo_box->priv->button_sensitivity); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -3121,6 +3151,32 @@ gtk_combo_box_menu_item_activate (GtkWidget *item, combo_box->priv->editing_canceled = FALSE; } +static void +gtk_combo_box_update_sensitivity (GtkComboBox *combo_box) +{ + GtkTreeIter iter; + gboolean sensitive = TRUE; /* fool code checkers */ + + switch (combo_box->priv->button_sensitivity) + { + case GTK_SENSITIVITY_ON: + sensitive = TRUE; + break; + case GTK_SENSITIVITY_OFF: + sensitive = FALSE; + break; + case GTK_SENSITIVITY_AUTO: + sensitive = combo_box->priv->model && + gtk_tree_model_get_iter_first (combo_box->priv->model, &iter); + break; + default: + g_assert_not_reached (); + break; + } + + gtk_widget_set_sensitive (combo_box->priv->button, sensitive); +} + static void gtk_combo_box_model_row_inserted (GtkTreeModel *model, GtkTreePath *path, @@ -3133,6 +3189,8 @@ gtk_combo_box_model_row_inserted (GtkTreeModel *model, gtk_combo_box_list_popup_resize (combo_box); else gtk_combo_box_menu_row_inserted (model, path, iter, user_data); + + gtk_combo_box_update_sensitivity (combo_box); } static void @@ -3154,6 +3212,8 @@ gtk_combo_box_model_row_deleted (GtkTreeModel *model, gtk_combo_box_list_popup_resize (combo_box); else gtk_combo_box_menu_row_deleted (model, path, user_data); + + gtk_combo_box_update_sensitivity (combo_box); } static void @@ -4945,6 +5005,8 @@ gtk_combo_box_set_model (GtkComboBox *combo_box, combo_box->priv->model); out: + gtk_combo_box_update_sensitivity (combo_box); + g_object_notify (G_OBJECT (combo_box), "model"); } @@ -5670,6 +5732,55 @@ gtk_combo_box_set_row_separator_func (GtkComboBox *combo_box, gtk_widget_queue_draw (GTK_WIDGET (combo_box)); } +/** + * gtk_combo_box_set_button_sensitivity: + * @combo_box: a #GtkComboBox + * @sensitivity: specify the sensitivity of the dropdown button + * + * Sets whether the dropdown button of the combo box should be + * always sensitive (%GTK_SENSITIVITY_ON), never sensitive (%GTK_SENSITIVITY_OFF) + * or only if there is at least one item to display (%GTK_SENSITIVITY_AUTO). + * + * Since: 2.14 + **/ +void +gtk_combo_box_set_button_sensitivity (GtkComboBox *combo_box, + GtkSensitivityType sensitivity) +{ + g_return_if_fail (GTK_IS_COMBO_BOX (combo_box)); + + if (combo_box->priv->button_sensitivity != sensitivity) + { + combo_box->priv->button_sensitivity = sensitivity; + gtk_combo_box_update_sensitivity (combo_box); + + g_object_notify (G_OBJECT (combo_box), "button-sensitivity"); + } +} + +/** + * gtk_combo_box_get_button_sensitivity: + * @combo_box: a #GtkComboBox + * + * Returns whether the combo box sets the dropdown button + * sensitive or not when there are no items in the model. + * + * Return Value: %GTK_SENSITIVITY_ON if the dropdown button + * is sensitive when the model is empty, %GTK_SENSITIVITY_OFF + * if the button is always insensitive or + * %GTK_SENSITIVITY_AUTO if it is only sensitive as long as + * the model has one item to be selected. + * + * Since: 2.14 + **/ +GtkSensitivityType +gtk_combo_box_get_button_sensitivity (GtkComboBox *combo_box) +{ + g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE); + + return combo_box->priv->button_sensitivity; +} + /** * gtk_combo_box_set_focus_on_click: diff --git a/gtk/gtkcombobox.h b/gtk/gtkcombobox.h index cc93415a0c..1da1562b19 100644 --- a/gtk/gtkcombobox.h +++ b/gtk/gtkcombobox.h @@ -114,6 +114,10 @@ void gtk_combo_box_set_row_separator_func (GtkComboBox gpointer data, GDestroyNotify destroy); +void gtk_combo_box_set_button_sensitivity (GtkComboBox *combo_box, + GtkSensitivityType sensitivity); +GtkSensitivityType gtk_combo_box_get_button_sensitivity (GtkComboBox *combo_box); + /* convenience -- text */ GtkWidget *gtk_combo_box_new_text (void); void gtk_combo_box_append_text (GtkComboBox *combo_box,