Commit 9612c648 authored by Tristan Van Berkom's avatar Tristan Van Berkom Committed by Matthias Clasen

Deprecate GtkComboBoxEntry in favor of added properties to GtkComboBox

GtkComboBox now sports a construct-only "has-entry" property which
decides if it uses a GtkEntry to allow additional user input. Also
it has a new "entry-text-column" to fetch strings for the entry
from the model.

This patch deprecates the GtkComboBoxEntry and updates the rest of GTK+
to use the new semantics on GtkComboBox instead.

GtkComboBoxEntry will be removed altogether before GTK+ 3, in a
later commit.
parent 7c8ee80c
......@@ -428,7 +428,14 @@ do_combobox (GtkWidget *do_widget)
gtk_container_set_border_width (GTK_CONTAINER (box), 5);
gtk_container_add (GTK_CONTAINER (frame), box);
combo = gtk_combo_box_entry_new_text ();
model = (GtkTreeModel *)gtk_list_store_new (1, G_TYPE_STRING);
combo = g_object_new (GTK_TYPE_COMBO_BOX,
"has-entry", TRUE,
"model", model,
"entry-text-column", 0,
NULL);
g_object_unref (model);
fill_combo_entry (combo);
gtk_container_add (GTK_CONTAINER (box), combo);
......
......@@ -767,6 +767,7 @@ gtk_color_selection_dialog_get_type
<TITLE>GtkComboBox</TITLE>
GtkComboBox
gtk_combo_box_new
gtk_combo_box_new_with_entry
gtk_combo_box_new_with_model
gtk_combo_box_get_wrap_width
gtk_combo_box_set_wrap_width
......@@ -800,6 +801,9 @@ 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_combo_box_get_has_entry
gtk_combo_box_set_entry_text_column
gtk_combo_box_get_entry_text_column
<SUBSECTION Standard>
GTK_TYPE_COMBO_BOX
GTK_COMBO_BOX
......
......@@ -282,12 +282,21 @@ create_combo_box_entry (void)
GtkWidget *widget;
GtkWidget *align;
GtkWidget *child;
GtkTreeModel *model;
gtk_rc_parse_string ("style \"combo-box-entry-style\" {\n"
" GtkComboBox::appears-as-list = 1\n"
"}\n"
"widget_class \"GtkComboBoxEntry\" style \"combo-box-entry-style\"\n" );
widget = gtk_combo_box_entry_new_text ();
model = (GtkTreeModel *)gtk_list_store_new (1, G_TYPE_STRING);
widget = g_object_new (GTK_TYPE_COMBO_BOX,
"has-entry", TRUE,
"model", model,
"entry-text-column", 0,
NULL);
g_object_unref (model);
child = gtk_bin_get_child (GTK_BIN (widget));
gtk_entry_set_text (GTK_ENTRY (child), "Combo Box Entry");
align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
......
......@@ -804,7 +804,9 @@ gtk_combo_box_get_active_iter
gtk_combo_box_get_active_text
gtk_combo_box_get_add_tearoffs
gtk_combo_box_get_column_span_column
gtk_combo_box_get_entry_text_column
gtk_combo_box_get_focus_on_click
gtk_combo_box_get_has_entry
gtk_combo_box_get_model
gtk_combo_box_get_popup_accessible
gtk_combo_box_get_row_separator_func
......@@ -816,6 +818,7 @@ gtk_combo_box_get_wrap_width
gtk_combo_box_insert_text
gtk_combo_box_new
gtk_combo_box_new_text
gtk_combo_box_new_with_entry
gtk_combo_box_new_with_model
gtk_combo_box_popdown
gtk_combo_box_popup
......@@ -826,6 +829,7 @@ gtk_combo_box_set_active
gtk_combo_box_set_active_iter
gtk_combo_box_set_add_tearoffs
gtk_combo_box_set_column_span_column
gtk_combo_box_set_entry_text_column
gtk_combo_box_set_focus_on_click
gtk_combo_box_set_model
gtk_combo_box_set_row_separator_func
......@@ -838,6 +842,7 @@ gtk_combo_box_set_wrap_width
#if IN_HEADER(__GTK_COMBO_BOX_ENTRY_H__)
#if IN_FILE(__GTK_COMBO_BOX_ENTRY_C__)
#ifndef GTK_DISABLE_DEPRECATED
gtk_combo_box_entry_get_text_column
gtk_combo_box_entry_get_type G_GNUC_CONST
gtk_combo_box_entry_new
......@@ -846,6 +851,7 @@ gtk_combo_box_entry_new_with_model
gtk_combo_box_entry_set_text_column
#endif
#endif
#endif
#if IN_HEADER(__GTK_CONTAINER_H__)
#if IN_FILE(__GTK_CONTAINER_C__)
......
......@@ -27,7 +27,6 @@
#include "gtkcellrenderercombo.h"
#include "gtkcellrenderertext.h"
#include "gtkcombobox.h"
#include "gtkcomboboxentry.h"
#include "gtkmarshalers.h"
#include "gtkprivate.h"
......@@ -351,7 +350,7 @@ gtk_cell_renderer_combo_editing_done (GtkCellEditable *combo,
return;
}
if (GTK_IS_COMBO_BOX_ENTRY (combo))
if (gtk_combo_box_get_has_entry (GTK_COMBO_BOX (combo)))
{
entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (combo)));
new_text = g_strdup (gtk_entry_get_text (entry));
......@@ -449,11 +448,11 @@ gtk_cell_renderer_combo_start_editing (GtkCellRenderer *cell,
if (priv->has_entry)
{
combo = gtk_combo_box_entry_new ();
combo = g_object_new (GTK_TYPE_COMBO_BOX, "has-entry", TRUE, NULL);
if (priv->model)
gtk_combo_box_set_model (GTK_COMBO_BOX (combo), priv->model);
gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (combo),
gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (combo),
priv->text_column);
g_object_get (cell_text, "text", &text, NULL);
......
This diff is collapsed.
......@@ -69,6 +69,7 @@ struct _GtkComboBoxClass
/* construction */
GType gtk_combo_box_get_type (void) G_GNUC_CONST;
GtkWidget *gtk_combo_box_new (void);
GtkWidget *gtk_combo_box_new_with_entry (void);
GtkWidget *gtk_combo_box_new_with_model (GtkTreeModel *model);
/* grids */
......@@ -118,6 +119,11 @@ void gtk_combo_box_set_button_sensitivity (GtkComboBox *com
GtkSensitivityType sensitivity);
GtkSensitivityType gtk_combo_box_get_button_sensitivity (GtkComboBox *combo_box);
gboolean gtk_combo_box_get_has_entry (GtkComboBox *combo_box);
void gtk_combo_box_set_entry_text_column (GtkComboBox *combo_box,
gint text_column);
gint gtk_combo_box_get_entry_text_column (GtkComboBox *combo_box);
/* convenience -- text */
GtkWidget *gtk_combo_box_new_text (void);
void gtk_combo_box_append_text (GtkComboBox *combo_box,
......
......@@ -19,6 +19,9 @@
#include "config.h"
#include <string.h>
#undef GTK_DISABLE_DEPRECATED
#include "gtkcomboboxentry.h"
#include "gtkcelllayout.h"
......@@ -363,6 +366,8 @@ gtk_combo_box_entry_contents_changed (GtkEntry *entry,
* Return value: A new #GtkComboBoxEntry.
*
* Since: 2.4
*
* Deprecated: 2.24: Use gtk_combo_box_new_with_entry() instead
*/
GtkWidget *
gtk_combo_box_entry_new (void)
......@@ -384,6 +389,8 @@ gtk_combo_box_entry_new (void)
* Return value: A new #GtkComboBoxEntry.
*
* Since: 2.4
*
* Deprecated: 2.24: Use gtk_combo_box_new_with_entry() instead
*/
GtkWidget *
gtk_combo_box_entry_new_with_model (GtkTreeModel *model,
......@@ -412,6 +419,8 @@ gtk_combo_box_entry_new_with_model (GtkTreeModel *model,
* to be @text_column.
*
* Since: 2.4
*
* Deprecated: 2.24: Use gtk_combo_box_set_entry_text_column() instead
*/
void
gtk_combo_box_entry_set_text_column (GtkComboBoxEntry *entry_box,
......@@ -439,6 +448,8 @@ gtk_combo_box_entry_set_text_column (GtkComboBoxEntry *entry_box,
* Return value: A column in the data source model of @entry_box.
*
* Since: 2.4
*
* Deprecated: 2.24: Use gtk_combo_box_get_entry_text_column() instead
*/
gint
gtk_combo_box_entry_get_text_column (GtkComboBoxEntry *entry_box)
......
......@@ -29,6 +29,8 @@
G_BEGIN_DECLS
#ifndef GTK_DISABLE_DEPRECATED
#define GTK_TYPE_COMBO_BOX_ENTRY (gtk_combo_box_entry_get_type ())
#define GTK_COMBO_BOX_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COMBO_BOX_ENTRY, GtkComboBoxEntry))
#define GTK_COMBO_BOX_ENTRY_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), GTK_TYPE_COMBO_BOX_ENTRY, GtkComboBoxEntryClass))
......@@ -72,6 +74,7 @@ gint gtk_combo_box_entry_get_text_column (GtkComboBoxEntry *entry_box);
/* convenience -- text */
GtkWidget *gtk_combo_box_entry_new_text (void);
#endif
G_END_DECLS
......
......@@ -29,7 +29,6 @@
#include "gtkcelllayout.h"
#include "gtkcellrenderertext.h"
#include "gtkcombobox.h"
#include "gtkcomboboxentry.h"
#include "gtkfilechooserbutton.h"
#include "gtkimage.h"
#include "gtklabel.h"
......@@ -287,11 +286,11 @@ static GtkWidget *
combo_box_entry_new (void)
{
GtkWidget *combo_box;
combo_box = gtk_combo_box_entry_new ();
combo_box = g_object_new (GTK_TYPE_COMBO_BOX, "has-entry", TRUE, NULL);
combo_box_set_model (combo_box);
gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (combo_box), NAME_COLUMN);
gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (combo_box), NAME_COLUMN);
return combo_box;
}
......@@ -373,7 +372,7 @@ combo_box_get (GtkWidget *combo)
gchar *value;
GtkTreeIter iter;
if (GTK_IS_COMBO_BOX_ENTRY (combo))
if (gtk_combo_box_get_has_entry (GTK_COMBO_BOX (combo)))
{
value = gtk_combo_box_get_active_text(GTK_COMBO_BOX (combo));
}
......
......@@ -1336,8 +1336,9 @@ test_combo_box_entry (void)
" </object>"
" <object class=\"GtkWindow\" id=\"window1\">"
" <child>"
" <object class=\"GtkComboBoxEntry\" id=\"comboboxentry1\">"
" <object class=\"GtkComboBox\" id=\"comboboxentry1\">"
" <property name=\"model\">liststore1</property>"
" <property name=\"has-entry\">True</property>"
" <property name=\"visible\">True</property>"
" <child>"
" <object class=\"GtkCellRendererText\" id=\"renderer1\"/>"
......
......@@ -72,7 +72,6 @@ list_ignore_properties (gboolean buglist)
{ "GtkColorSelection", "current-color", (void*) NULL, }, /* not a valid boxed color */
{ "GtkComboBox", "row-span-column", (void*) MATCH_ANY_VALUE }, /* GtkComboBoxEntry needs a tree model for this */
{ "GtkComboBox", "column-span-column", (void*) MATCH_ANY_VALUE }, /* GtkComboBoxEntry needs a tree model for this */
{ "GtkComboBoxEntry", "text-column", (void*) MATCH_ANY_VALUE }, /* GtkComboBoxEntry needs a tree model for this */
{ "GtkFileChooserButton", "select-multiple", (void*) MATCH_ANY_VALUE }, /* property disabled */
{ "GtkFileChooserButton", "action", (void*) GTK_FILE_CHOOSER_ACTION_SAVE },
{ "GtkFileChooserButton", "action", (void*) GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER },
......@@ -279,14 +278,7 @@ static void
widget_fixups (GtkWidget *widget)
{
/* post-constructor for widgets that need additional settings to work correctly */
if (GTK_IS_COMBO_BOX_ENTRY (widget))
{
GtkListStore *store = gtk_list_store_new (1, G_TYPE_STRING);
g_object_set (widget, "model", store, "text-column", 0, NULL);
g_object_unref (store);
gtk_combo_box_append_text (GTK_COMBO_BOX (widget), "test text");
}
else if (GTK_IS_COMBO_BOX (widget))
if (GTK_IS_COMBO_BOX (widget))
{
GtkListStore *store = gtk_list_store_new (1, G_TYPE_STRING);
g_object_set (widget, "model", store, NULL);
......
......@@ -1021,7 +1021,8 @@ main (int argc, char **argv)
GtkTreePath *path;
GtkTreeIter iter;
GdkColor color;
GtkListStore *store;
gtk_init (&argc, &argv);
if (g_getenv ("RTL"))
......@@ -1265,14 +1266,21 @@ main (int argc, char **argv)
/* GtkComboBoxEntry */
tmp = gtk_frame_new ("GtkComboBoxEntry");
tmp = gtk_frame_new ("GtkComboBox with entry");
gtk_box_pack_start (GTK_BOX (mainbox), tmp, FALSE, FALSE, 0);
boom = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (boom), 5);
gtk_container_add (GTK_CONTAINER (tmp), boom);
comboboxtext = gtk_combo_box_entry_new_text ();
store = gtk_list_store_new (1, G_TYPE_STRING);
comboboxtext = g_object_new (GTK_TYPE_COMBO_BOX,
"has-entry", TRUE,
"model", store,
"entry-text-column", 0,
NULL);
g_object_unref (store);
setup_combo_entry (comboboxtext);
gtk_container_add (GTK_CONTAINER (boom), comboboxtext);
......
......@@ -3955,6 +3955,7 @@ create_entry (GtkWidget *widget)
GtkWidget *cb_entry;
GtkWidget *button;
GtkWidget *separator;
GtkListStore *store;
if (!window)
{
......@@ -3992,7 +3993,14 @@ create_entry (GtkWidget *widget)
G_CALLBACK (props_clicked),
entry);
cb = GTK_COMBO_BOX (gtk_combo_box_entry_new_text ());
store = gtk_list_store_new (1, G_TYPE_STRING);
cb = g_object_new (GTK_TYPE_COMBO_BOX,
"has-entry", TRUE,
"model", store,
"entry-text-column", 0,
NULL);
g_object_unref (store);
gtk_combo_box_append_text (cb, "item0");
gtk_combo_box_append_text (cb, "item0");
gtk_combo_box_append_text (cb, "item1 item1");
......
......@@ -134,8 +134,16 @@ create_combo (void)
{
GtkComboBox *combo;
GtkWidget *entry;
GtkListStore *store;
store = gtk_list_store_new (1, G_TYPE_STRING);
combo = g_object_new (GTK_TYPE_COMBO_BOX,
"has-entry", TRUE,
"model", store,
"entry-text-column", 0,
NULL);
g_object_unref (store);
combo = GTK_COMBO_BOX (gtk_combo_box_entry_new_text ());
gtk_combo_box_append_text (combo, "item0");
gtk_combo_box_append_text (combo, "item1 item1");
gtk_combo_box_append_text (combo, "item2 item2 item2");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment