Blame gtk/gtkcomboboxtext.c

Packit Service fb6fa5
/* GTK - The GIMP Toolkit
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Copyright (C) 2010 Christian Dywan
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This library is free software; you can redistribute it and/or
Packit Service fb6fa5
 * modify it under the terms of the GNU Lesser General Public
Packit Service fb6fa5
 * License as published by the Free Software Foundation; either
Packit Service fb6fa5
 * version 2 of the License, or (at your option) any later version.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * This library is distributed in the hope that it will be useful,
Packit Service fb6fa5
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fb6fa5
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service fb6fa5
 * Lesser General Public License for more details.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * You should have received a copy of the GNU Lesser General Public
Packit Service fb6fa5
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
Packit Service fb6fa5
 */
Packit Service fb6fa5
Packit Service fb6fa5
#include <string.h>
Packit Service fb6fa5
Packit Service fb6fa5
#include "config.h"
Packit Service fb6fa5
Packit Service fb6fa5
#include "gtkcomboboxtext.h"
Packit Service fb6fa5
#include "gtkcombobox.h"
Packit Service fb6fa5
#include "gtkcellrenderertext.h"
Packit Service fb6fa5
#include "gtkcelllayout.h"
Packit Service fb6fa5
#include "gtkbuildable.h"
Packit Service fb6fa5
#include "gtkbuilderprivate.h"
Packit Service fb6fa5
#include "gtkalias.h"
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * SECTION:gtkcomboboxtext
Packit Service fb6fa5
 * @Short_description: A simple, text-only combo box
Packit Service fb6fa5
 * @Title: GtkComboBoxText
Packit Service fb6fa5
 * @See_also: @GtkComboBox
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * A GtkComboBoxText is a simple variant of #GtkComboBox that hides
Packit Service fb6fa5
 * the model-view complexity for simple text-only use cases.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * To create a GtkComboBoxText, use gtk_combo_box_text_new() or
Packit Service fb6fa5
 * gtk_combo_box_text_new_with_entry().
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * You can add items to a GtkComboBoxText with
Packit Service fb6fa5
 * gtk_combo_box_text_append_text(), gtk_combo_box_text_insert_text()
Packit Service fb6fa5
 * or gtk_combo_box_text_prepend_text() and remove options with
Packit Service fb6fa5
 * gtk_combo_box_text_remove().
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * If the GtkComboBoxText contains an entry (via the 'has-entry' property),
Packit Service fb6fa5
 * its contents can be retrieved using gtk_combo_box_text_get_active_text().
Packit Service fb6fa5
 * The entry itself can be accessed by calling gtk_bin_get_child() on the
Packit Service fb6fa5
 * combo box.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * <refsect2 id="GtkComboBoxText-BUILDER-UI">
Packit Service fb6fa5
 * <title>GtkComboBoxText as GtkBuildable</title>
Packit Service fb6fa5
 * <para>
Packit Service fb6fa5
 * The GtkComboBoxText implementation of the GtkBuildable interface
Packit Service fb6fa5
 * supports adding items directly using the <items&gt element
Packit Service fb6fa5
 * and specifying <item> elements for each item. Each <item>
Packit Service fb6fa5
 * element supports the regular translation attributes "translatable",
Packit Service fb6fa5
 * "context" and "comments".
Packit Service fb6fa5
 * </para>
Packit Service fb6fa5
 * <example>
Packit Service fb6fa5
 * <title>A UI definition fragment specifying GtkComboBoxText items</title>
Packit Service fb6fa5
 * <programlisting>
Packit Service fb6fa5
 * <object class="GtkComboBoxText">
Packit Service fb6fa5
 *   <items>
Packit Service fb6fa5
 *     <item translatable="yes">Factory</item>
Packit Service fb6fa5
 *     <item translatable="yes">Home</item>
Packit Service fb6fa5
 *     <item translatable="yes">Subway</item>
Packit Service fb6fa5
 *   </items>
Packit Service fb6fa5
 * </object>
Packit Service fb6fa5
 * ]]></programlisting>
Packit Service fb6fa5
 * </example>
Packit Service fb6fa5
 * </refsect2>
Packit Service fb6fa5
 */
Packit Service fb6fa5
Packit Service fb6fa5
static void     gtk_combo_box_text_buildable_interface_init     (GtkBuildableIface *iface);
Packit Service fb6fa5
static gboolean gtk_combo_box_text_buildable_custom_tag_start   (GtkBuildable     *buildable,
Packit Service fb6fa5
								 GtkBuilder       *builder,
Packit Service fb6fa5
								 GObject          *child,
Packit Service fb6fa5
								 const gchar      *tagname,
Packit Service fb6fa5
								 GMarkupParser    *parser,
Packit Service fb6fa5
								 gpointer         *data);
Packit Service fb6fa5
Packit Service fb6fa5
static void     gtk_combo_box_text_buildable_custom_finished    (GtkBuildable     *buildable,
Packit Service fb6fa5
								 GtkBuilder       *builder,
Packit Service fb6fa5
								 GObject          *child,
Packit Service fb6fa5
								 const gchar      *tagname,
Packit Service fb6fa5
								 gpointer          user_data);
Packit Service fb6fa5
Packit Service fb6fa5
static GtkBuildableIface *buildable_parent_iface = NULL;
Packit Service fb6fa5
Packit Service fb6fa5
G_DEFINE_TYPE_WITH_CODE (GtkComboBoxText, gtk_combo_box_text, GTK_TYPE_COMBO_BOX,
Packit Service fb6fa5
			 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
Packit Service fb6fa5
						gtk_combo_box_text_buildable_interface_init));
Packit Service fb6fa5
Packit Service fb6fa5
static GObject *
Packit Service fb6fa5
gtk_combo_box_text_constructor (GType                  type,
Packit Service fb6fa5
                                guint                  n_construct_properties,
Packit Service fb6fa5
                                GObjectConstructParam *construct_properties)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GObject            *object;
Packit Service fb6fa5
Packit Service fb6fa5
  object = G_OBJECT_CLASS (gtk_combo_box_text_parent_class)->constructor
Packit Service fb6fa5
    (type, n_construct_properties, construct_properties);
Packit Service fb6fa5
Packit Service fb6fa5
  if (!gtk_combo_box_get_has_entry (GTK_COMBO_BOX (object)))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      GtkCellRenderer *cell;
Packit Service fb6fa5
Packit Service fb6fa5
      cell = gtk_cell_renderer_text_new ();
Packit Service fb6fa5
      gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (object), cell, TRUE);
Packit Service fb6fa5
      gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (object), cell,
Packit Service fb6fa5
                                      "text", 0,
Packit Service fb6fa5
                                      NULL);
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  return object;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_combo_box_text_init (GtkComboBoxText *combo_box)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkListStore *store;
Packit Service fb6fa5
Packit Service fb6fa5
  store = gtk_list_store_new (1, G_TYPE_STRING);
Packit Service fb6fa5
  gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), GTK_TREE_MODEL (store));
Packit Service fb6fa5
  g_object_unref (store);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_combo_box_text_class_init (GtkComboBoxTextClass *klass)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GObjectClass *object_class;
Packit Service fb6fa5
Packit Service fb6fa5
  object_class = (GObjectClass *)klass;
Packit Service fb6fa5
  object_class->constructor = gtk_combo_box_text_constructor;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_combo_box_text_buildable_interface_init (GtkBuildableIface *iface)
Packit Service fb6fa5
{
Packit Service fb6fa5
  buildable_parent_iface = g_type_interface_peek_parent (iface);
Packit Service fb6fa5
Packit Service fb6fa5
  iface->custom_tag_start = gtk_combo_box_text_buildable_custom_tag_start;
Packit Service fb6fa5
  iface->custom_finished = gtk_combo_box_text_buildable_custom_finished;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
typedef struct {
Packit Service fb6fa5
  GtkBuilder    *builder;
Packit Service fb6fa5
  GObject       *object;
Packit Service fb6fa5
  const gchar   *domain;
Packit Service fb6fa5
Packit Service fb6fa5
  gchar         *context;
Packit Service fb6fa5
  gchar         *string;
Packit Service fb6fa5
  guint          translatable : 1;
Packit Service fb6fa5
Packit Service fb6fa5
  guint          is_text : 1;
Packit Service fb6fa5
} ItemParserData;
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
item_start_element (GMarkupParseContext *context,
Packit Service fb6fa5
		    const gchar         *element_name,
Packit Service fb6fa5
		    const gchar        **names,
Packit Service fb6fa5
		    const gchar        **values,
Packit Service fb6fa5
		    gpointer             user_data,
Packit Service fb6fa5
		    GError             **error)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ItemParserData *data = (ItemParserData*)user_data;
Packit Service fb6fa5
  guint i;
Packit Service fb6fa5
Packit Service fb6fa5
  if (strcmp (element_name, "item") == 0)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      data->is_text = TRUE;
Packit Service fb6fa5
Packit Service fb6fa5
      for (i = 0; names[i]; i++)
Packit Service fb6fa5
	{
Packit Service fb6fa5
	  if (strcmp (names[i], "translatable") == 0)
Packit Service fb6fa5
	    {
Packit Service fb6fa5
	      gboolean bval;
Packit Service fb6fa5
Packit Service fb6fa5
	      if (!_gtk_builder_boolean_from_string (values[i], &bval,
Packit Service fb6fa5
						     error))
Packit Service fb6fa5
		return;
Packit Service fb6fa5
Packit Service fb6fa5
	      data->translatable = bval;
Packit Service fb6fa5
	    }
Packit Service fb6fa5
	  else if (strcmp (names[i], "comments") == 0)
Packit Service fb6fa5
	    {
Packit Service fb6fa5
	      /* do nothing, comments are for translators */
Packit Service fb6fa5
	    }
Packit Service fb6fa5
	  else if (strcmp (names[i], "context") == 0) 
Packit Service fb6fa5
	    data->context = g_strdup (values[i]);
Packit Service fb6fa5
	  else
Packit Service fb6fa5
	    g_warning ("Unknown custom combo box item attribute: %s", names[i]);
Packit Service fb6fa5
	}
Packit Service fb6fa5
    }
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
item_text (GMarkupParseContext *context,
Packit Service fb6fa5
	   const gchar         *text,
Packit Service fb6fa5
	   gsize                text_len,
Packit Service fb6fa5
	   gpointer             user_data,
Packit Service fb6fa5
	   GError             **error)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ItemParserData *data = (ItemParserData*)user_data;
Packit Service fb6fa5
  gchar *string;
Packit Service fb6fa5
Packit Service fb6fa5
  if (!data->is_text)
Packit Service fb6fa5
    return;
Packit Service fb6fa5
Packit Service fb6fa5
  string = g_strndup (text, text_len);
Packit Service fb6fa5
Packit Service fb6fa5
  if (data->translatable && text_len)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      gchar *translated;
Packit Service fb6fa5
Packit Service fb6fa5
      /* FIXME: This will not use the domain set in the .ui file,
Packit Service fb6fa5
       * since the parser is not telling the builder about the domain.
Packit Service fb6fa5
       * However, it will work for gtk_builder_set_translation_domain() calls.
Packit Service fb6fa5
       */
Packit Service fb6fa5
      translated = _gtk_builder_parser_translate (data->domain,
Packit Service fb6fa5
						  data->context,
Packit Service fb6fa5
						  string);
Packit Service fb6fa5
      g_free (string);
Packit Service fb6fa5
      string = translated;
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  data->string = string;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
item_end_element (GMarkupParseContext *context,
Packit Service fb6fa5
		  const gchar         *element_name,
Packit Service fb6fa5
		  gpointer             user_data,
Packit Service fb6fa5
		  GError             **error)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ItemParserData *data = (ItemParserData*)user_data;
Packit Service fb6fa5
Packit Service fb6fa5
  /* Append the translated strings */
Packit Service fb6fa5
  if (data->string)
Packit Service fb6fa5
    gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (data->object), data->string);
Packit Service fb6fa5
Packit Service fb6fa5
  data->translatable = FALSE;
Packit Service fb6fa5
  g_free (data->context);
Packit Service fb6fa5
  g_free (data->string);
Packit Service fb6fa5
  data->context = NULL;
Packit Service fb6fa5
  data->string = NULL;
Packit Service fb6fa5
  data->is_text = FALSE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static const GMarkupParser item_parser =
Packit Service fb6fa5
  {
Packit Service fb6fa5
    item_start_element,
Packit Service fb6fa5
    item_end_element,
Packit Service fb6fa5
    item_text
Packit Service fb6fa5
  };
Packit Service fb6fa5
Packit Service fb6fa5
static gboolean
Packit Service fb6fa5
gtk_combo_box_text_buildable_custom_tag_start (GtkBuildable     *buildable,
Packit Service fb6fa5
					       GtkBuilder       *builder,
Packit Service fb6fa5
					       GObject          *child,
Packit Service fb6fa5
					       const gchar      *tagname,
Packit Service fb6fa5
					       GMarkupParser    *parser,
Packit Service fb6fa5
					       gpointer         *data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  if (buildable_parent_iface->custom_tag_start (buildable, builder, child, 
Packit Service fb6fa5
						tagname, parser, data))
Packit Service fb6fa5
    return TRUE;
Packit Service fb6fa5
Packit Service fb6fa5
  if (strcmp (tagname, "items") == 0)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      ItemParserData *parser_data;
Packit Service fb6fa5
Packit Service fb6fa5
      parser_data = g_slice_new0 (ItemParserData);
Packit Service fb6fa5
      parser_data->builder = g_object_ref (builder);
Packit Service fb6fa5
      parser_data->object = g_object_ref (buildable);
Packit Service fb6fa5
      parser_data->domain = gtk_builder_get_translation_domain (builder);
Packit Service fb6fa5
      *parser = item_parser;
Packit Service fb6fa5
      *data = parser_data;
Packit Service fb6fa5
      return TRUE;
Packit Service fb6fa5
    }
Packit Service fb6fa5
  return FALSE;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
static void
Packit Service fb6fa5
gtk_combo_box_text_buildable_custom_finished (GtkBuildable *buildable,
Packit Service fb6fa5
					      GtkBuilder   *builder,
Packit Service fb6fa5
					      GObject      *child,
Packit Service fb6fa5
					      const gchar  *tagname,
Packit Service fb6fa5
					      gpointer      user_data)
Packit Service fb6fa5
{
Packit Service fb6fa5
  ItemParserData *data;
Packit Service fb6fa5
Packit Service fb6fa5
  buildable_parent_iface->custom_finished (buildable, builder, child, 
Packit Service fb6fa5
					   tagname, user_data);
Packit Service fb6fa5
Packit Service fb6fa5
  if (strcmp (tagname, "items") == 0)
Packit Service fb6fa5
    {
Packit Service fb6fa5
      data = (ItemParserData*)user_data;
Packit Service fb6fa5
Packit Service fb6fa5
      g_object_unref (data->object);
Packit Service fb6fa5
      g_object_unref (data->builder);
Packit Service fb6fa5
      g_slice_free (ItemParserData, data);
Packit Service fb6fa5
    }
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_combo_box_text_new:
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Creates a new #GtkComboBoxText, which is a #GtkComboBox just displaying
Packit Service fb6fa5
 * strings. See gtk_combo_box_entry_new_with_text().
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: A new #GtkComboBoxText
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.24
Packit Service fb6fa5
 */
Packit Service fb6fa5
GtkWidget *
Packit Service fb6fa5
gtk_combo_box_text_new (void)
Packit Service fb6fa5
{
Packit Service fb6fa5
  return g_object_new (GTK_TYPE_COMBO_BOX_TEXT,
Packit Service fb6fa5
                       "entry-text-column", 0,
Packit Service fb6fa5
                       NULL);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_combo_box_text_new_with_entry:
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Creates a new #GtkComboBoxText, which is a #GtkComboBox just displaying
Packit Service fb6fa5
 * strings. The combo box created by this function has an entry.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Return value: a new #GtkComboBoxText
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.24
Packit Service fb6fa5
 */
Packit Service fb6fa5
GtkWidget *
Packit Service fb6fa5
gtk_combo_box_text_new_with_entry (void)
Packit Service fb6fa5
{
Packit Service fb6fa5
  return g_object_new (GTK_TYPE_COMBO_BOX_TEXT,
Packit Service fb6fa5
                       "has-entry", TRUE,
Packit Service fb6fa5
                       "entry-text-column", 0,
Packit Service fb6fa5
                       NULL);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_combo_box_text_append_text:
Packit Service fb6fa5
 * @combo_box: A #GtkComboBoxText
Packit Service fb6fa5
 * @text: A string
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Appends @string to the list of strings stored in @combo_box.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.24
Packit Service fb6fa5
 */
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_combo_box_text_append_text (GtkComboBoxText *combo_box,
Packit Service fb6fa5
                                const gchar     *text)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkListStore *store;
Packit Service fb6fa5
  GtkTreeIter iter;
Packit Service fb6fa5
  gint text_column;
Packit Service fb6fa5
  gint column_type;
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_COMBO_BOX_TEXT (combo_box));
Packit Service fb6fa5
  g_return_if_fail (text != NULL);
Packit Service fb6fa5
Packit Service fb6fa5
  store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)));
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_LIST_STORE (store));
Packit Service fb6fa5
Packit Service fb6fa5
  text_column = gtk_combo_box_get_entry_text_column (GTK_COMBO_BOX (combo_box));
Packit Service fb6fa5
  if (gtk_combo_box_get_has_entry (GTK_COMBO_BOX (combo_box)))
Packit Service fb6fa5
    g_return_if_fail (text_column >= 0);
Packit Service fb6fa5
  else if (text_column < 0)
Packit Service fb6fa5
    text_column = 0;
Packit Service fb6fa5
Packit Service fb6fa5
  column_type = gtk_tree_model_get_column_type (GTK_TREE_MODEL (store), text_column);
Packit Service fb6fa5
  g_return_if_fail (column_type == G_TYPE_STRING);
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_list_store_append (store, &iter);
Packit Service fb6fa5
  gtk_list_store_set (store, &iter, text_column, text, -1);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_combo_box_text_insert_text:
Packit Service fb6fa5
 * @combo_box: A #GtkComboBoxText
Packit Service fb6fa5
 * @position: An index to insert @text
Packit Service fb6fa5
 * @text: A string
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Inserts @string at @position in the list of strings stored in @combo_box.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.24
Packit Service fb6fa5
 */
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_combo_box_text_insert_text (GtkComboBoxText *combo_box,
Packit Service fb6fa5
                                gint             position,
Packit Service fb6fa5
                                const gchar     *text)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkListStore *store;
Packit Service fb6fa5
  GtkTreeIter iter;
Packit Service fb6fa5
  gint text_column;
Packit Service fb6fa5
  gint column_type;
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_COMBO_BOX_TEXT (combo_box));
Packit Service fb6fa5
  g_return_if_fail (position >= 0);
Packit Service fb6fa5
  g_return_if_fail (text != NULL);
Packit Service fb6fa5
Packit Service fb6fa5
  store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)));
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_LIST_STORE (store));
Packit Service fb6fa5
  text_column = gtk_combo_box_get_entry_text_column (GTK_COMBO_BOX (combo_box));
Packit Service fb6fa5
  column_type = gtk_tree_model_get_column_type (GTK_TREE_MODEL (store), text_column);
Packit Service fb6fa5
  g_return_if_fail (column_type == G_TYPE_STRING);
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_list_store_insert (store, &iter, position);
Packit Service fb6fa5
  gtk_list_store_set (store, &iter, text_column, text, -1);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_combo_box_text_prepend_text:
Packit Service fb6fa5
 * @combo_box: A #GtkComboBox
Packit Service fb6fa5
 * @text: A string
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Prepends @string to the list of strings stored in @combo_box.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.24
Packit Service fb6fa5
 */
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_combo_box_text_prepend_text (GtkComboBoxText *combo_box,
Packit Service fb6fa5
                                 const gchar     *text)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkListStore *store;
Packit Service fb6fa5
  GtkTreeIter iter;
Packit Service fb6fa5
  gint text_column;
Packit Service fb6fa5
  gint column_type;
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_COMBO_BOX_TEXT (combo_box));
Packit Service fb6fa5
  g_return_if_fail (text != NULL);
Packit Service fb6fa5
Packit Service fb6fa5
  store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)));
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_LIST_STORE (store));
Packit Service fb6fa5
Packit Service fb6fa5
  text_column = gtk_combo_box_get_entry_text_column (GTK_COMBO_BOX (combo_box));
Packit Service fb6fa5
  column_type = gtk_tree_model_get_column_type (GTK_TREE_MODEL (store), text_column);
Packit Service fb6fa5
  g_return_if_fail (column_type == G_TYPE_STRING);
Packit Service fb6fa5
Packit Service fb6fa5
  gtk_list_store_prepend (store, &iter);
Packit Service fb6fa5
  gtk_list_store_set (store, &iter, text_column, text, -1);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_combo_box_text_remove:
Packit Service fb6fa5
 * @combo_box: A #GtkComboBox
Packit Service fb6fa5
 * @position: Index of the item to remove
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Removes the string at @position from @combo_box.
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.24
Packit Service fb6fa5
 */
Packit Service fb6fa5
void
Packit Service fb6fa5
gtk_combo_box_text_remove (GtkComboBoxText *combo_box,
Packit Service fb6fa5
                           gint             position)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkTreeModel *model;
Packit Service fb6fa5
  GtkListStore *store;
Packit Service fb6fa5
  GtkTreeIter iter;
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_COMBO_BOX_TEXT (combo_box));
Packit Service fb6fa5
  g_return_if_fail (position >= 0);
Packit Service fb6fa5
Packit Service fb6fa5
  model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
Packit Service fb6fa5
  store = GTK_LIST_STORE (model);
Packit Service fb6fa5
  g_return_if_fail (GTK_IS_LIST_STORE (store));
Packit Service fb6fa5
Packit Service fb6fa5
  if (gtk_tree_model_iter_nth_child (model, &iter, NULL, position))
Packit Service fb6fa5
    gtk_list_store_remove (store, &iter);
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
/**
Packit Service fb6fa5
 * gtk_combo_box_text_get_active_text:
Packit Service fb6fa5
 * @combo_box: A #GtkComboBoxText
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Returns the currently active string in @combo_box, or %NULL
Packit Service fb6fa5
 * if none is selected. If @combo_box contains an entry, this
Packit Service fb6fa5
 * function will return its contents (which will not necessarily
Packit Service fb6fa5
 * be an item from the list).
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Returns: a newly allocated string containing the currently
Packit Service fb6fa5
 *     active text. Must be freed with g_free().
Packit Service fb6fa5
 *
Packit Service fb6fa5
 * Since: 2.24
Packit Service fb6fa5
 */
Packit Service fb6fa5
gchar *
Packit Service fb6fa5
gtk_combo_box_text_get_active_text (GtkComboBoxText *combo_box)
Packit Service fb6fa5
{
Packit Service fb6fa5
  GtkTreeIter iter;
Packit Service fb6fa5
  gchar *text = NULL;
Packit Service fb6fa5
Packit Service fb6fa5
  g_return_val_if_fail (GTK_IS_COMBO_BOX_TEXT (combo_box), NULL);
Packit Service fb6fa5
Packit Service fb6fa5
 if (gtk_combo_box_get_has_entry (GTK_COMBO_BOX (combo_box)))
Packit Service fb6fa5
   {
Packit Service fb6fa5
     GtkWidget *entry;
Packit Service fb6fa5
Packit Service fb6fa5
     entry = gtk_bin_get_child (GTK_BIN (combo_box));
Packit Service fb6fa5
     text = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
Packit Service fb6fa5
   }
Packit Service fb6fa5
  else if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo_box), &iter))
Packit Service fb6fa5
    {
Packit Service fb6fa5
      GtkTreeModel *model;
Packit Service fb6fa5
      gint text_column;
Packit Service fb6fa5
      gint column_type;
Packit Service fb6fa5
Packit Service fb6fa5
      model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
Packit Service fb6fa5
      g_return_val_if_fail (GTK_IS_LIST_STORE (model), NULL);
Packit Service fb6fa5
      text_column = gtk_combo_box_get_entry_text_column (GTK_COMBO_BOX (combo_box));
Packit Service fb6fa5
      column_type = gtk_tree_model_get_column_type (model, text_column);
Packit Service fb6fa5
      g_return_val_if_fail (column_type == G_TYPE_STRING, NULL);
Packit Service fb6fa5
      gtk_tree_model_get (model, &iter, text_column, &text, -1);
Packit Service fb6fa5
    }
Packit Service fb6fa5
Packit Service fb6fa5
  return text;
Packit Service fb6fa5
}
Packit Service fb6fa5
Packit Service fb6fa5
#define __GTK_COMBO_BOX_TEXT_C__
Packit Service fb6fa5
#include "gtkaliasdef.c"