From adcf33fa4d223cb0be763144eb67155257d76109 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 21 Nov 2005 16:01:56 +0000 Subject: [PATCH] Add a tearoff-title property, with getter and setter. (#316482, Olexiy 2005-11-21 Matthias Clasen * gtk/gtk.symbols: * gtk/gtkcombobox.[hc]: Add a tearoff-title property, with getter and setter. (#316482, Olexiy Avramchenko) * tests/testcombo.c (main): Test gtk_combo_box_set_title --- ChangeLog | 6 ++ ChangeLog.pre-2-10 | 6 ++ docs/reference/ChangeLog | 2 + docs/reference/gtk/gtk-sections.txt | 2 + gtk/gtk.symbols | 2 + gtk/gtkcombobox.c | 93 ++++++++++++++++++++++++++++- gtk/gtkcombobox.h | 5 ++ tests/testcombo.c | 1 + 8 files changed, 115 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 43cedd5547..0111721558 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2005-11-21 Matthias Clasen + * gtk/gtk.symbols: + * gtk/gtkcombobox.[hc]: Add a tearoff-title property, + with getter and setter. (#316482, Olexiy Avramchenko) + + * tests/testcombo.c (main): Test gtk_combo_box_set_title + * gtk/gtkpathbar.c: Merge remaining fixes from the 2.8 branch, pointed out by Michael Natterer. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 43cedd5547..0111721558 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,11 @@ 2005-11-21 Matthias Clasen + * gtk/gtk.symbols: + * gtk/gtkcombobox.[hc]: Add a tearoff-title property, + with getter and setter. (#316482, Olexiy Avramchenko) + + * tests/testcombo.c (main): Test gtk_combo_box_set_title + * gtk/gtkpathbar.c: Merge remaining fixes from the 2.8 branch, pointed out by Michael Natterer. diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 6293720e2f..40e230e28c 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,5 +1,7 @@ 2005-11-21 Matthias Clasen + * gtk/gtk-sections.txt: Add gtk_combo_box_[sg]et_title + * gtk/Makefile.am (HTML_IMAGES): Fix some _ vs - confusion. 2005-11-14 Matthias Clasen diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt index 4d71c325c3..75a1ad3287 100644 --- a/docs/reference/gtk/gtk-sections.txt +++ b/docs/reference/gtk/gtk-sections.txt @@ -753,6 +753,8 @@ gtk_combo_box_get_row_separator_func gtk_combo_box_set_row_separator_func gtk_combo_box_set_add_tearoffs gtk_combo_box_get_add_tearoffs +gtk_combo_box_set_title +gtk_combo_box_get_title gtk_combo_box_set_focus_on_click gtk_combo_box_get_focus_on_click diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index 4a42eb045d..da23d29892 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -731,6 +731,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_title gtk_combo_box_get_type G_GNUC_CONST gtk_combo_box_get_wrap_width gtk_combo_box_insert_text @@ -749,6 +750,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_title gtk_combo_box_set_wrap_width #endif #endif diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c index 1a2aa834fb..526b16c751 100644 --- a/gtk/gtkcombobox.c +++ b/gtk/gtkcombobox.c @@ -121,6 +121,8 @@ struct _GtkComboBoxPrivate GtkTreeViewRowSeparatorFunc row_separator_func; gpointer row_separator_data; GtkDestroyNotify row_separator_destroy; + + gchar *tearoff_title; }; /* While debugging this evil code, I have learned that @@ -196,6 +198,7 @@ enum { PROP_COLUMN_SPAN_COLUMN, PROP_ACTIVE, PROP_ADD_TEAROFFS, + PROP_TEAROFF_TITLE, PROP_HAS_FRAME, PROP_FOCUS_ON_CLICK }; @@ -353,6 +356,7 @@ static void gtk_combo_box_menu_fill (GtkComboBox *combo_box) static void gtk_combo_box_menu_fill_level (GtkComboBox *combo_box, GtkWidget *menu, GtkTreeIter *iter); +static void gtk_combo_box_update_title (GtkComboBox *combo_box); static void gtk_combo_box_menu_destroy (GtkComboBox *combo_box); static void gtk_combo_box_relayout_item (GtkComboBox *combo_box, @@ -550,7 +554,7 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass) g_signal_new ("popup-show", G_OBJECT_CLASS_TYPE (klass), G_SIGNAL_RUN_LAST, - NULL, + 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -559,7 +563,7 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass) g_signal_new ("popup-hide", G_OBJECT_CLASS_TYPE (klass), G_SIGNAL_RUN_LAST, - NULL, + 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); @@ -709,6 +713,23 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass) TRUE, GTK_PARAM_READWRITE)); + /** + * GtkComboBox:tearoff-title: + * + * A title that may be displayed by the window manager + * when the popup is torn-off. + * + * Since: 2.10 + */ + g_object_class_install_property (object_class, + PROP_TEAROFF_TITLE, + g_param_spec_string ("tearoff-title", + P_("Tearoff Title"), + P_("A title that may be displayed by the window manager when the popup is torn-off"), + "", + GTK_PARAM_READWRITE)); + + gtk_widget_class_install_style_property (widget_class, g_param_spec_boolean ("appears-as-list", P_("Appears as list"), @@ -805,6 +826,10 @@ gtk_combo_box_set_property (GObject *object, g_value_get_boolean (value)); break; + case PROP_TEAROFF_TITLE: + gtk_combo_box_set_title (combo_box, g_value_get_string (value)); + break; + default: break; } @@ -852,6 +877,10 @@ gtk_combo_box_get_property (GObject *object, g_value_set_boolean (value, combo_box->priv->focus_on_click); break; + case PROP_TEAROFF_TITLE: + g_value_set_string (value, gtk_combo_box_get_title (combo_box)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -2510,6 +2539,8 @@ gtk_combo_box_menu_setup (GtkComboBox *combo_box, gtk_object_sink (GTK_OBJECT (combo_box->priv->column)); gtk_combo_box_sync_cells (combo_box, GTK_CELL_LAYOUT (combo_box->priv->column)); + + gtk_combo_box_update_title (combo_box); } static void @@ -5117,6 +5148,64 @@ gtk_combo_box_set_add_tearoffs (GtkComboBox *combo_box, } } +/** + * gtk_combo_box_get_title: + * @combo_box: a #GtkComboBox + * + * Gets the current title of the menu in tearoff mode. See + * gtk_combo_box_set_add_tearoffs(). + * + * Returns: the menu's title in tearoff mode. This is an internal copy of the + * string which must not be freed. + * + * Since: 2.10 + */ +G_CONST_RETURN gchar* +gtk_combo_box_get_title (GtkComboBox *combo_box) +{ + g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), NULL); + + return combo_box->priv->tearoff_title; +} + +static void +gtk_combo_box_update_title (GtkComboBox *combo_box) +{ + gtk_combo_box_check_appearance (combo_box); + + if (combo_box->priv->popup_widget && + GTK_IS_MENU (combo_box->priv->popup_widget)) + gtk_menu_set_title (GTK_MENU (combo_box->priv->popup_widget), + combo_box->priv->tearoff_title); +} + +/** + * gtk_combo_box_set_title: + * @combo_box: a #GtkComboBox + * @title: a title for the menu in tearoff mode. + * + * Sets the menu's title in tearoff mode. + * + * Since: 2.10 + */ +void +gtk_combo_box_set_title (GtkComboBox *combo_box, + const gchar *title) +{ + g_return_if_fail (GTK_IS_COMBO_BOX (combo_box)); + + if (strcmp (title ? title : "", + combo_box->priv->tearoff_title ? combo_box->priv->tearoff_title : "") != 0) + { + g_free (combo_box->priv->tearoff_title); + combo_box->priv->tearoff_title = g_strdup (title); + + gtk_combo_box_update_title (combo_box); + + g_object_notify (G_OBJECT (combo_box), "tearoff-title"); + } +} + gboolean _gtk_combo_box_editing_canceled (GtkComboBox *combo_box) { diff --git a/gtk/gtkcombobox.h b/gtk/gtkcombobox.h index e8b2a46cc4..6ab2d95454 100644 --- a/gtk/gtkcombobox.h +++ b/gtk/gtkcombobox.h @@ -81,6 +81,11 @@ void gtk_combo_box_set_column_span_column (GtkComboBox *combo_box, gboolean gtk_combo_box_get_add_tearoffs (GtkComboBox *combo_box); void gtk_combo_box_set_add_tearoffs (GtkComboBox *combo_box, gboolean add_tearoffs); + +G_CONST_RETURN gchar *gtk_combo_box_get_title (GtkComboBox *combo_box); +void gtk_combo_box_set_title (GtkComboBox *combo_box, + const gchar *title); + gboolean gtk_combo_box_get_focus_on_click (GtkComboBox *combo); void gtk_combo_box_set_focus_on_click (GtkComboBox *combo, gboolean focus_on_click); diff --git a/tests/testcombo.c b/tests/testcombo.c index ba75342072..32ee4d1cad 100644 --- a/tests/testcombo.c +++ b/tests/testcombo.c @@ -1126,6 +1126,7 @@ main (int argc, char **argv) is_separator, NULL, NULL); gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), 0); + gtk_combo_box_set_title (GTK_COMBO_BOX (combobox), "Dynamic list"); /* GtkComboBox custom entry */ tmp = gtk_frame_new ("GtkComboBox (custom)");