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.
(cherry picked from commit 9612c64817)
This commit is contained in:
Matthias Clasen 2010-10-13 22:43:40 -04:00
parent 9f08f69f4b
commit 880c9d82ec
15 changed files with 484 additions and 57 deletions

View File

@ -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);

View File

@ -932,6 +932,7 @@ gtk_combo_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
@ -964,6 +965,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

View File

@ -279,13 +279,24 @@ 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 ();
gtk_entry_set_text (GTK_ENTRY (GTK_BIN (widget)->child), "Combo Box Entry");
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);
gtk_container_add (GTK_CONTAINER (align), widget);

View File

@ -943,7 +943,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
@ -955,6 +957,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
@ -964,6 +967,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
@ -976,6 +980,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
@ -984,6 +989,7 @@ gtk_combo_box_entry_new_with_model
gtk_combo_box_entry_set_text_column
#endif
#endif
#endif
#if IN_HEADER(__GTK_SMART_COMBO_H__)
#if IN_FILE(__GTK_SMART_COMBO_C__)

View File

@ -27,7 +27,6 @@
#include "gtkcellrenderercombo.h"
#include "gtkcellrenderertext.h"
#include "gtkcombobox.h"
#include "gtkcomboboxentry.h"
#include "gtkmarshalers.h"
#include "gtkprivate.h"
#include "gtkalias.h"
@ -342,7 +341,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));
@ -431,11 +430,11 @@ gtk_cell_renderer_combo_start_editing (GtkCellRenderer *cell,
if (cell_combo->has_entry)
{
combo = gtk_combo_box_entry_new ();
combo = g_object_new (GTK_TYPE_COMBO_BOX, "has-entry", TRUE, NULL);
if (cell_combo->model)
gtk_combo_box_set_model (GTK_COMBO_BOX (combo), cell_combo->model);
gtk_combo_box_entry_set_text_column (GTK_COMBO_BOX_ENTRY (combo),
gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (combo),
cell_combo->text_column);
if (cell_text->text)

View File

@ -111,6 +111,12 @@ struct _GtkComboBoxPrivate
gint width;
gint height;
/* For "has-entry" specific behavior we track
* an automated cell renderer and text column */
gint text_column;
GtkCellRenderer *text_renderer;
GSList *cells;
guint popup_in_progress : 1;
@ -122,6 +128,7 @@ struct _GtkComboBoxPrivate
guint auto_scroll : 1;
guint focus_on_click : 1;
guint button_sensitivity : 2;
guint has_entry : 1;
GtkTreeViewRowSeparatorFunc row_separator_func;
gpointer row_separator_data;
@ -205,7 +212,9 @@ enum {
PROP_FOCUS_ON_CLICK,
PROP_POPUP_SHOWN,
PROP_BUTTON_SENSITIVITY,
PROP_EDITING_CANCELED
PROP_EDITING_CANCELED,
PROP_HAS_ENTRY,
PROP_ENTRY_TEXT_COLUMN
};
static guint combo_box_signals[LAST_SIGNAL] = {0,};
@ -217,6 +226,9 @@ static guint combo_box_signals[LAST_SIGNAL] = {0,};
static void gtk_combo_box_cell_layout_init (GtkCellLayoutIface *iface);
static void gtk_combo_box_cell_editable_init (GtkCellEditableIface *iface);
static GObject *gtk_combo_box_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_properties);
static void gtk_combo_box_dispose (GObject *object);
static void gtk_combo_box_finalize (GObject *object);
static void gtk_combo_box_destroy (GtkObject *object);
@ -446,6 +458,13 @@ static void gtk_combo_box_child_show (GtkWidget *w
static void gtk_combo_box_child_hide (GtkWidget *widget,
GtkComboBox *combo_box);
/* GtkComboBox:has-entry callbacks */
static void gtk_combo_box_entry_contents_changed (GtkEntry *entry,
gpointer user_data);
static void gtk_combo_box_entry_active_changed (GtkComboBox *combo_box,
gpointer user_data);
/* GtkBuildable method implementation */
static GtkBuildableIface *parent_buildable_iface;
@ -461,6 +480,10 @@ static void gtk_combo_box_buildable_custom_tag_end (GtkBuildable *bui
GObject *child,
const gchar *tagname,
gpointer *data);
static GObject *gtk_combo_box_buildable_get_internal_child (GtkBuildable *buildable,
GtkBuilder *builder,
const gchar *childname);
/* GtkCellEditable method implementations */
static void gtk_combo_box_start_editing (GtkCellEditable *cell_editable,
@ -507,6 +530,7 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
gtk_object_class->destroy = gtk_combo_box_destroy;
object_class = (GObjectClass *)klass;
object_class->constructor = gtk_combo_box_constructor;
object_class->dispose = gtk_combo_box_dispose;
object_class->finalize = gtk_combo_box_finalize;
object_class->set_property = gtk_combo_box_set_property;
@ -850,6 +874,39 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
GTK_SENSITIVITY_AUTO,
GTK_PARAM_READWRITE));
/**
* GtkComboBox:has-entry:
*
* Whether the combo box has an entry.
*
* Since: 3.0
*/
g_object_class_install_property (object_class,
PROP_HAS_ENTRY,
g_param_spec_boolean ("has-entry",
P_("Has Entry"),
P_("Whether combo box has an entry"),
FALSE,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
/**
* GtkComboBox:entry-text-column:
*
* The column in the combo box's model to associate with strings from the entry
* if the combo was created with #GtkComboBox:has-entry = %TRUE.
*
* Since: 3.0
*/
g_object_class_install_property (object_class,
PROP_ENTRY_TEXT_COLUMN,
g_param_spec_int ("entry-text-column",
P_("Entry Text Column"),
P_("The column in the combo box's model to associate "
"with strings from the entry if the combo was "
"created with #GtkComboBox:has-entry = %TRUE"),
-1, G_MAXINT, -1,
GTK_PARAM_READWRITE));
gtk_widget_class_install_style_property (widget_class,
g_param_spec_boolean ("appears-as-list",
P_("Appears as list"),
@ -901,6 +958,7 @@ gtk_combo_box_buildable_init (GtkBuildableIface *iface)
iface->add_child = _gtk_cell_layout_buildable_add_child;
iface->custom_tag_start = gtk_combo_box_buildable_custom_tag_start;
iface->custom_tag_end = gtk_combo_box_buildable_custom_tag_end;
iface->get_internal_child = gtk_combo_box_buildable_get_internal_child;
}
static void
@ -949,6 +1007,10 @@ gtk_combo_box_init (GtkComboBox *combo_box)
priv->auto_scroll = FALSE;
priv->focus_on_click = TRUE;
priv->button_sensitivity = GTK_SENSITIVITY_AUTO;
priv->has_entry = FALSE;
priv->text_column = -1;
priv->text_renderer = NULL;
combo_box->priv = priv;
@ -991,6 +1053,17 @@ gtk_combo_box_set_property (GObject *object,
case PROP_HAS_FRAME:
combo_box->priv->has_frame = g_value_get_boolean (value);
if (combo_box->priv->has_entry)
{
GtkWidget *child;
child = gtk_bin_get_child (GTK_BIN (combo_box));
gtk_entry_set_has_frame (GTK_ENTRY (child),
combo_box->priv->has_frame);
}
break;
case PROP_FOCUS_ON_CLICK:
@ -1018,6 +1091,14 @@ gtk_combo_box_set_property (GObject *object,
combo_box->priv->editing_canceled = g_value_get_boolean (value);
break;
case PROP_HAS_ENTRY:
combo_box->priv->has_entry = g_value_get_boolean (value);
break;
case PROP_ENTRY_TEXT_COLUMN:
gtk_combo_box_set_entry_text_column (combo_box, g_value_get_int (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -1083,6 +1164,13 @@ gtk_combo_box_get_property (GObject *object,
g_value_set_boolean (value, priv->editing_canceled);
break;
case PROP_HAS_ENTRY:
g_value_set_boolean (value, priv->has_entry);
break;
case PROP_ENTRY_TEXT_COLUMN:
g_value_set_int (value, priv->text_column);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -1213,7 +1301,16 @@ gtk_combo_box_add (GtkContainer *container,
GtkComboBox *combo_box = GTK_COMBO_BOX (container);
GtkComboBoxPrivate *priv = combo_box->priv;
if (priv->cell_view && priv->cell_view->parent)
if (priv->has_entry && !GTK_IS_ENTRY (widget))
{
g_warning ("Attempting to add a widget with type %s to a GtkComboBox that needs an entry "
"(need an instance of GtkEntry or of a subclass)",
G_OBJECT_TYPE_NAME (widget));
return;
}
if (priv->cell_view &&
gtk_widget_get_parent (priv->cell_view))
{
gtk_widget_unparent (priv->cell_view);
GTK_BIN (container)->child = NULL;
@ -1244,6 +1341,19 @@ gtk_combo_box_add (GtkContainer *container,
priv->box = NULL;
}
}
if (priv->has_entry)
{
/* this flag is a hack to tell the entry to fill its allocation.
*/
GTK_ENTRY (widget)->is_cell_renderer = TRUE;
g_signal_connect (widget, "changed",
G_CALLBACK (gtk_combo_box_entry_contents_changed),
combo_box);
gtk_entry_set_has_frame (GTK_ENTRY (widget), priv->has_frame);
}
}
static void
@ -1255,6 +1365,20 @@ gtk_combo_box_remove (GtkContainer *container,
GtkTreePath *path;
gboolean appears_as_list;
if (priv->has_entry)
{
GtkWidget *child_widget;
child_widget = gtk_bin_get_child (GTK_BIN (container));
if (widget && widget == child_widget)
{
g_signal_handlers_disconnect_by_func (widget,
gtk_combo_box_entry_contents_changed,
container);
GTK_ENTRY (widget)->is_cell_renderer = FALSE;
}
}
if (widget == priv->cell_view)
priv->cell_view = NULL;
@ -4641,6 +4765,19 @@ gtk_combo_box_new (void)
return g_object_new (GTK_TYPE_COMBO_BOX, NULL);
}
/**
* gtk_combo_box_new_with_entry:
*
* Creates a new empty #GtkComboBox with an entry.
*
* Return value: A new #GtkComboBox.
*/
GtkWidget *
gtk_combo_box_new_with_entry (void)
{
return g_object_new (GTK_TYPE_COMBO_BOX, "has-entry", TRUE, NULL);
}
/**
* gtk_combo_box_new_with_model:
* @model: A #GtkTreeModel.
@ -5320,15 +5457,29 @@ gtk_combo_box_real_get_active_text (GtkComboBox *combo_box)
GtkTreeIter iter;
gchar *text = NULL;
g_return_val_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model), NULL);
g_return_val_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
== G_TYPE_STRING, NULL);
if (combo_box->priv->has_entry)
{
GtkBin *combo = GTK_BIN (combo_box);
GtkWidget *child;
if (gtk_combo_box_get_active_iter (combo_box, &iter))
gtk_tree_model_get (combo_box->priv->model, &iter,
0, &text, -1);
child = gtk_bin_get_child (combo);
if (child)
return g_strdup (gtk_entry_get_text (GTK_ENTRY (child)));
return text;
return NULL;
}
else
{
g_return_val_if_fail (GTK_IS_LIST_STORE (combo_box->priv->model), NULL);
g_return_val_if_fail (gtk_tree_model_get_column_type (combo_box->priv->model, 0)
== G_TYPE_STRING, NULL);
if (gtk_combo_box_get_active_iter (combo_box, &iter))
gtk_tree_model_get (combo_box->priv->model, &iter,
0, &text, -1);
return text;
}
}
static void
@ -5421,7 +5572,16 @@ gtk_combo_box_mnemonic_activate (GtkWidget *widget,
{
GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
gtk_widget_grab_focus (combo_box->priv->button);
if (combo_box->priv->has_entry)
{
GtkWidget* child;
child = gtk_bin_get_child (GTK_BIN (combo_box));
if (child)
gtk_widget_grab_focus (child);
}
else
gtk_widget_grab_focus (combo_box->priv->button);
return TRUE;
}
@ -5431,7 +5591,16 @@ gtk_combo_box_grab_focus (GtkWidget *widget)
{
GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
gtk_widget_grab_focus (combo_box->priv->button);
if (combo_box->priv->has_entry)
{
GtkWidget *child;
child = gtk_bin_get_child (GTK_BIN (combo_box));
if (child)
gtk_widget_grab_focus (child);
}
else
gtk_widget_grab_focus (combo_box->priv->button);
}
static void
@ -5458,6 +5627,94 @@ gtk_combo_box_destroy (GtkObject *object)
combo_box->priv->cell_view = NULL;
}
static void
gtk_combo_box_entry_contents_changed (GtkEntry *entry,
gpointer user_data)
{
GtkComboBox *combo_box = GTK_COMBO_BOX (user_data);
/*
* Fixes regression reported in bug #574059. The old functionality relied on
* bug #572478. As a bugfix, we now emit the "changed" signal ourselves
* when the selection was already set to -1.
*/
if (gtk_combo_box_get_active(combo_box) == -1)
g_signal_emit_by_name (combo_box, "changed");
else
gtk_combo_box_set_active (combo_box, -1);
}
static void
gtk_combo_box_entry_active_changed (GtkComboBox *combo_box,
gpointer user_data)
{
GtkComboBoxPrivate *priv = combo_box->priv;
GtkTreeModel *model;
GtkTreeIter iter;
gchar *str = NULL;
if (gtk_combo_box_get_active_iter (combo_box, &iter))
{
GtkEntry *entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (combo_box)));
if (entry)
{
g_signal_handlers_block_by_func (entry,
gtk_combo_box_entry_contents_changed,
combo_box);
model = gtk_combo_box_get_model (combo_box);
gtk_tree_model_get (model, &iter,
priv->text_column, &str,
-1);
gtk_entry_set_text (entry, str);
g_free (str);
g_signal_handlers_unblock_by_func (entry,
gtk_combo_box_entry_contents_changed,
combo_box);
}
}
}
static GObject *
gtk_combo_box_constructor (GType type,
guint n_construct_properties,
GObjectConstructParam *construct_properties)
{
GObject *object;
GtkComboBox *combo_box;
GtkComboBoxPrivate *priv;
object = G_OBJECT_CLASS (gtk_combo_box_parent_class)->constructor
(type, n_construct_properties, construct_properties);
combo_box = GTK_COMBO_BOX (object);
priv = combo_box->priv;
if (priv->has_entry)
{
GtkWidget *entry;
entry = gtk_entry_new ();
gtk_widget_show (entry);
gtk_container_add (GTK_CONTAINER (combo_box), entry);
priv->text_renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box),
priv->text_renderer, TRUE);
gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), -1);
g_signal_connect (combo_box, "changed",
G_CALLBACK (gtk_combo_box_entry_active_changed), NULL);
}
return object;
}
static void
gtk_combo_box_dispose(GObject* object)
{
@ -5512,6 +5769,7 @@ gtk_combo_box_finalize (GObject *object)
G_OBJECT_CLASS (gtk_combo_box_parent_class)->finalize (object);
}
static gboolean
gtk_cell_editable_key_press (GtkWidget *widget,
GdkEventKey *event,
@ -5875,6 +6133,77 @@ gtk_combo_box_get_button_sensitivity (GtkComboBox *combo_box)
}
/**
* gtk_combo_box_get_has_entry:
* @combo_box: a #GtkComboBox
*
* Returns whether the combo box has an entry.
*
* Return Value: whether there is an entry in @combo_box.
*
* Since: 3.0
**/
gboolean
gtk_combo_box_get_has_entry (GtkComboBox *combo_box)
{
g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), FALSE);
return combo_box->priv->has_entry;
}
/**
* gtk_combo_box_set_entry_text_column:
* @combo_box: A #GtkComboBox.
* @text_column: A column in @model to get the strings from for the internal entry.
*
* Sets the model column which @combo_box should use to get strings from
* to be @text_column.
*
* @combo_box must be created with GtkComboBox:has-entry as %TRUE.
*
* Since: 3.0
*/
void
gtk_combo_box_set_entry_text_column (GtkComboBox *combo_box,
gint text_column)
{
GtkTreeModel *model;
g_return_if_fail (GTK_IS_COMBO_BOX (combo_box));
g_return_if_fail (combo_box->priv->has_entry != FALSE);
model = gtk_combo_box_get_model (combo_box);
g_return_if_fail (text_column >= 0);
g_return_if_fail (model == NULL || text_column < gtk_tree_model_get_n_columns (model));
combo_box->priv->text_column = text_column;
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box),
combo_box->priv->text_renderer,
"text", text_column,
NULL);
}
/**
* gtk_combo_box_get_entry_text_column:
* @combo_box: A #GtkComboBox.
*
* Returns the column which @combo_box is using to get the strings
* from to display in the internal entry.
*
* Return value: A column in the data source model of @combo_box.
*
* Since: 3.0
*/
gint
gtk_combo_box_get_entry_text_column (GtkComboBox *combo_box)
{
g_return_val_if_fail (GTK_IS_COMBO_BOX (combo_box), 0);
return combo_box->priv->text_column;
}
/**
* gtk_combo_box_set_focus_on_click:
* @combo: a #GtkComboBox
@ -5960,5 +6289,18 @@ gtk_combo_box_buildable_custom_tag_end (GtkBuildable *buildable,
data);
}
static GObject *
gtk_combo_box_buildable_get_internal_child (GtkBuildable *buildable,
GtkBuilder *builder,
const gchar *childname)
{
GtkComboBox *combo_box = GTK_COMBO_BOX (buildable);
if (combo_box->priv->has_entry && strcmp (childname, "entry") == 0)
return G_OBJECT (gtk_bin_get_child (GTK_BIN (buildable)));
return parent_buildable_iface->get_internal_child (buildable, builder, childname);
}
#define __GTK_COMBO_BOX_C__
#include "gtkaliasdef.c"

View File

@ -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,

View File

@ -19,6 +19,9 @@
#include "config.h"
#include <string.h>
#undef GTK_DISABLE_DEPRECATED
#include "gtkcomboboxentry.h"
#include "gtkcelllayout.h"
@ -314,6 +317,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)
@ -335,6 +340,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,
@ -363,6 +370,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,
@ -390,6 +399,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)

View File

@ -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

View File

@ -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"
@ -288,11 +287,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;
}
@ -374,7 +373,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));
}

View File

@ -1333,8 +1333,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\"/>"

View File

@ -73,7 +73,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 },
@ -280,14 +279,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);

View File

@ -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);

View File

@ -6094,6 +6094,18 @@ static void
create_list (GtkWidget *widget)
{
static GtkWidget *window = NULL;
GtkWidget *box1;
GtkWidget *box2;
GtkWidget *hbox;
GtkWidget *has_frame_check;
GtkWidget *sensitive_check;
GtkWidget *progress_check;
GtkWidget *entry;
GtkComboBox *cb;
GtkWidget *cb_entry;
GtkWidget *button;
GtkWidget *separator;
GtkListStore *store;
if (!window)
{
@ -6171,11 +6183,30 @@ create_list (GtkWidget *widget)
G_CALLBACK (list_add),
list);
button = gtk_button_new_with_label ("Clear List");
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (list_clear),
list);
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");
gtk_combo_box_append_text (cb, "item2 item2 item2");
gtk_combo_box_append_text (cb, "item3 item3 item3 item3");
gtk_combo_box_append_text (cb, "item4 item4 item4 item4 item4");
gtk_combo_box_append_text (cb, "item5 item5 item5 item5 item5 item5");
gtk_combo_box_append_text (cb, "item6 item6 item6 item6 item6");
gtk_combo_box_append_text (cb, "item7 item7 item7 item7");
gtk_combo_box_append_text (cb, "item8 item8 item8");
gtk_combo_box_append_text (cb, "item9 item9");
cb_entry = gtk_bin_get_child (GTK_BIN (cb));
gtk_entry_set_text (GTK_ENTRY (cb_entry), "hello world \n\n\n foo");
gtk_editable_select_region (GTK_EDITABLE (cb_entry), 0, -1);
gtk_box_pack_start (GTK_BOX (box2), GTK_WIDGET (cb), TRUE, TRUE, 0);
button = gtk_button_new_with_label ("Remove Selection");
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);

View File

@ -145,25 +145,32 @@ add_buttons (GtkWidget *widget, GtkWidget *box)
static GtkWidget *
create_combo (void)
{
GList *cbitems;
GtkCombo *combo;
GtkComboBox *combo;
GtkWidget *entry;
GtkListStore *store;
cbitems = NULL;
cbitems = g_list_append (cbitems, "item0");
cbitems = g_list_append (cbitems, "item1 item1");
cbitems = g_list_append (cbitems, "item2 item2 item2");
cbitems = g_list_append (cbitems, "item3 item3 item3 item3");
cbitems = g_list_append (cbitems, "item4 item4 item4 item4 item4");
cbitems = g_list_append (cbitems, "item5 item5 item5 item5 item5 item5");
cbitems = g_list_append (cbitems, "item6 item6 item6 item6 item6");
cbitems = g_list_append (cbitems, "item7 item7 item7 item7");
cbitems = g_list_append (cbitems, "item8 item8 item8");
cbitems = g_list_append (cbitems, "item9 item9");
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 (gtk_combo_new ());
gtk_combo_set_popdown_strings (combo, cbitems);
gtk_entry_set_text (GTK_ENTRY (combo->entry), "hello world");
gtk_editable_select_region (GTK_EDITABLE (combo->entry), 0, -1);
gtk_combo_box_append_text (combo, "item0");
gtk_combo_box_append_text (combo, "item1 item1");
gtk_combo_box_append_text (combo, "item2 item2 item2");
gtk_combo_box_append_text (combo, "item3 item3 item3 item3");
gtk_combo_box_append_text (combo, "item4 item4 item4 item4 item4");
gtk_combo_box_append_text (combo, "item5 item5 item5 item5 item5 item5");
gtk_combo_box_append_text (combo, "item6 item6 item6 item6 item6");
gtk_combo_box_append_text (combo, "item7 item7 item7 item7");
gtk_combo_box_append_text (combo, "item8 item8 item8");
gtk_combo_box_append_text (combo, "item9 item9");
entry = gtk_bin_get_child (GTK_BIN (combo));
gtk_entry_set_text (GTK_ENTRY (entry), "hello world");
gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
return GTK_WIDGET (combo);
}