2010-05-19 15:27:47 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Christian Dywan
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkcomboboxtext.h"
|
|
|
|
#include "gtkcombobox.h"
|
|
|
|
#include "gtkcellrenderertext.h"
|
|
|
|
#include "gtkcelllayout.h"
|
2011-01-09 06:25:53 +00:00
|
|
|
#include "gtkbuildable.h"
|
|
|
|
#include "gtkbuilderprivate.h"
|
2020-06-21 22:03:39 +00:00
|
|
|
#include "gtkliststore.h"
|
2011-01-09 06:25:53 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
2010-05-19 15:27:47 +00:00
|
|
|
|
2010-10-15 20:52:25 +00:00
|
|
|
/**
|
2021-02-21 22:21:00 +00:00
|
|
|
* GtkComboBoxText:
|
2010-10-15 20:52:25 +00:00
|
|
|
*
|
2021-02-21 22:21:00 +00:00
|
|
|
* A `GtkComboBoxText` is a simple variant of `GtkComboBox` for text-only
|
|
|
|
* use cases.
|
2010-10-15 20:52:25 +00:00
|
|
|
*
|
2021-02-21 22:21:00 +00:00
|
|
|
* ![An example GtkComboBoxText](combo-box-text.png)
|
2010-10-15 20:52:25 +00:00
|
|
|
*
|
2021-02-21 22:21:00 +00:00
|
|
|
* `GtkComboBoxText` hides the model-view complexity of `GtkComboBox`.
|
2010-12-13 20:45:07 +00:00
|
|
|
*
|
2021-02-21 22:21:00 +00:00
|
|
|
* To create a `GtkComboBoxText`, use [ctor@Gtk.ComboBoxText.new] or
|
|
|
|
* [ctor@Gtk.ComboBoxText.new_with_entry].
|
2011-01-09 06:25:53 +00:00
|
|
|
*
|
2021-02-21 22:21:00 +00:00
|
|
|
* You can add items to a `GtkComboBoxText` with
|
|
|
|
* [method@Gtk.ComboBoxText.append_text],
|
|
|
|
* [method@Gtk.ComboBoxText.insert_text] or
|
|
|
|
* [method@Gtk.ComboBoxText.prepend_text] and remove options with
|
|
|
|
* [method@Gtk.ComboBoxText.remove].
|
|
|
|
*
|
|
|
|
* If the `GtkComboBoxText` contains an entry (via the
|
|
|
|
* [property@Gtk.ComboBox:has-entry] property), its contents can be retrieved
|
2021-04-02 23:44:30 +00:00
|
|
|
* using [method@Gtk.ComboBoxText.get_active_text].
|
2021-02-21 22:21:00 +00:00
|
|
|
*
|
|
|
|
* You should not call [method@Gtk.ComboBox.set_model] or attempt to pack more
|
2021-05-23 01:21:10 +00:00
|
|
|
* cells into this combo box via its [iface@Gtk.CellLayout] interface.
|
2011-12-28 15:32:32 +00:00
|
|
|
*
|
2014-02-05 02:00:58 +00:00
|
|
|
* # GtkComboBoxText as GtkBuildable
|
2014-02-02 05:29:00 +00:00
|
|
|
*
|
2021-02-21 22:21:00 +00:00
|
|
|
* The `GtkComboBoxText` implementation of the `GtkBuildable` interface supports
|
2014-02-09 22:24:06 +00:00
|
|
|
* adding items directly using the <items> element and specifying <item>
|
|
|
|
* elements for each item. Each <item> element can specify the “id”
|
|
|
|
* corresponding to the appended text and also supports the regular
|
|
|
|
* translation attributes “translatable”, “context” and “comments”.
|
2011-01-09 06:25:53 +00:00
|
|
|
*
|
2021-02-21 22:21:00 +00:00
|
|
|
* Here is a UI definition fragment specifying `GtkComboBoxText` items:
|
2021-02-28 00:45:37 +00:00
|
|
|
* ```xml
|
2011-01-09 06:25:53 +00:00
|
|
|
* <object class="GtkComboBoxText">
|
|
|
|
* <items>
|
2013-05-12 12:56:40 +00:00
|
|
|
* <item translatable="yes" id="factory">Factory</item>
|
|
|
|
* <item translatable="yes" id="home">Home</item>
|
|
|
|
* <item translatable="yes" id="subway">Subway</item>
|
2011-01-09 06:25:53 +00:00
|
|
|
* </items>
|
|
|
|
* </object>
|
2021-02-28 00:45:37 +00:00
|
|
|
* ```
|
2015-11-03 19:19:08 +00:00
|
|
|
*
|
|
|
|
* # CSS nodes
|
|
|
|
*
|
2021-02-28 00:45:37 +00:00
|
|
|
* ```
|
2016-03-02 20:20:47 +00:00
|
|
|
* combobox
|
|
|
|
* ╰── box.linked
|
|
|
|
* ├── entry.combo
|
|
|
|
* ├── button.combo
|
|
|
|
* ╰── window.popup
|
2021-02-28 00:45:37 +00:00
|
|
|
* ```
|
2015-11-03 19:19:08 +00:00
|
|
|
*
|
2021-02-21 22:21:00 +00:00
|
|
|
* `GtkComboBoxText` has a single CSS node with name combobox. It adds
|
2015-11-03 19:19:08 +00:00
|
|
|
* the style class .combo to the main CSS nodes of its entry and button
|
2016-03-02 20:20:47 +00:00
|
|
|
* children, and the .linked class to the node of its internal box.
|
2010-10-15 20:52:25 +00:00
|
|
|
*/
|
|
|
|
|
2019-05-27 02:16:58 +00:00
|
|
|
typedef struct _GtkComboBoxTextClass GtkComboBoxTextClass;
|
|
|
|
|
|
|
|
struct _GtkComboBoxText
|
|
|
|
{
|
|
|
|
GtkComboBox parent_instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkComboBoxTextClass
|
|
|
|
{
|
|
|
|
GtkComboBoxClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-08-29 13:21:20 +00:00
|
|
|
static void gtk_combo_box_text_buildable_interface_init (GtkBuildableIface *iface);
|
|
|
|
static gboolean gtk_combo_box_text_buildable_custom_tag_start (GtkBuildable *buildable,
|
|
|
|
GtkBuilder *builder,
|
|
|
|
GObject *child,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *tagname,
|
2019-08-29 13:21:20 +00:00
|
|
|
GtkBuildableParser *parser,
|
|
|
|
gpointer *data);
|
|
|
|
|
|
|
|
static void gtk_combo_box_text_buildable_custom_finished (GtkBuildable *buildable,
|
|
|
|
GtkBuilder *builder,
|
|
|
|
GObject *child,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *tagname,
|
2019-08-29 13:21:20 +00:00
|
|
|
gpointer user_data);
|
|
|
|
|
2011-01-09 06:25:53 +00:00
|
|
|
|
|
|
|
static GtkBuildableIface *buildable_parent_iface = NULL;
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkComboBoxText, gtk_combo_box_text, GTK_TYPE_COMBO_BOX,
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
|
|
|
|
gtk_combo_box_text_buildable_interface_init));
|
2010-05-19 15:27:47 +00:00
|
|
|
|
2014-06-26 22:22:42 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_text_constructed (GObject *object)
|
2010-05-19 15:27:47 +00:00
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
const int text_column = 0;
|
2010-10-18 12:13:41 +00:00
|
|
|
|
2014-06-26 22:22:42 +00:00
|
|
|
G_OBJECT_CLASS (gtk_combo_box_text_parent_class)->constructed (object);
|
2010-10-18 12:13:41 +00:00
|
|
|
|
2011-12-28 15:32:32 +00:00
|
|
|
gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (object), text_column);
|
|
|
|
gtk_combo_box_set_id_column (GTK_COMBO_BOX (object), 1);
|
|
|
|
|
2010-10-18 12:13:41 +00:00
|
|
|
if (!gtk_combo_box_get_has_entry (GTK_COMBO_BOX (object)))
|
|
|
|
{
|
|
|
|
GtkCellRenderer *cell;
|
|
|
|
|
|
|
|
cell = gtk_cell_renderer_text_new ();
|
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (object), cell, TRUE);
|
|
|
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (object), cell,
|
2011-12-28 15:32:32 +00:00
|
|
|
"text", text_column,
|
2010-10-18 12:13:41 +00:00
|
|
|
NULL);
|
|
|
|
}
|
2010-05-19 15:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_text_init (GtkComboBoxText *combo_box)
|
|
|
|
{
|
|
|
|
GtkListStore *store;
|
|
|
|
|
2010-11-30 05:07:08 +00:00
|
|
|
store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
|
2010-05-19 15:27:47 +00:00
|
|
|
gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), GTK_TREE_MODEL (store));
|
|
|
|
g_object_unref (store);
|
2010-10-18 12:13:41 +00:00
|
|
|
}
|
2010-05-19 15:27:47 +00:00
|
|
|
|
2010-10-18 12:13:41 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_text_class_init (GtkComboBoxTextClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class;
|
|
|
|
|
|
|
|
object_class = (GObjectClass *)klass;
|
2014-06-26 22:22:42 +00:00
|
|
|
object_class->constructed = gtk_combo_box_text_constructed;
|
2010-05-19 15:27:47 +00:00
|
|
|
}
|
|
|
|
|
2011-01-09 06:25:53 +00:00
|
|
|
static void
|
|
|
|
gtk_combo_box_text_buildable_interface_init (GtkBuildableIface *iface)
|
|
|
|
{
|
|
|
|
buildable_parent_iface = g_type_interface_peek_parent (iface);
|
|
|
|
|
|
|
|
iface->custom_tag_start = gtk_combo_box_text_buildable_custom_tag_start;
|
|
|
|
iface->custom_finished = gtk_combo_box_text_buildable_custom_finished;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GtkBuilder *builder;
|
|
|
|
GObject *object;
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *domain;
|
|
|
|
char *id;
|
2011-01-09 06:25:53 +00:00
|
|
|
|
2011-01-26 12:44:18 +00:00
|
|
|
GString *string;
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
char *context;
|
2011-01-09 06:25:53 +00:00
|
|
|
guint translatable : 1;
|
|
|
|
|
|
|
|
guint is_text : 1;
|
|
|
|
} ItemParserData;
|
|
|
|
|
|
|
|
static void
|
2019-08-29 13:21:20 +00:00
|
|
|
item_start_element (GtkBuildableParseContext *context,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *element_name,
|
|
|
|
const char **names,
|
|
|
|
const char **values,
|
2019-08-29 13:21:20 +00:00
|
|
|
gpointer user_data,
|
|
|
|
GError **error)
|
2011-01-09 06:25:53 +00:00
|
|
|
{
|
|
|
|
ItemParserData *data = (ItemParserData*)user_data;
|
|
|
|
|
2015-04-26 14:26:07 +00:00
|
|
|
if (strcmp (element_name, "items") == 0)
|
2011-01-09 06:25:53 +00:00
|
|
|
{
|
2015-04-26 14:26:07 +00:00
|
|
|
if (!_gtk_builder_check_parent (data->builder, context, "object", error))
|
|
|
|
return;
|
2011-01-09 06:25:53 +00:00
|
|
|
|
2015-04-26 14:26:07 +00:00
|
|
|
if (!g_markup_collect_attributes (element_name, names, values, error,
|
|
|
|
G_MARKUP_COLLECT_INVALID, NULL, NULL,
|
|
|
|
G_MARKUP_COLLECT_INVALID))
|
|
|
|
_gtk_builder_prefix_error (data->builder, context, error);
|
|
|
|
}
|
|
|
|
else if (strcmp (element_name, "item") == 0)
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *id = NULL;
|
2015-04-26 14:26:07 +00:00
|
|
|
gboolean translatable = FALSE;
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *msg_context = NULL;
|
2015-04-26 14:26:07 +00:00
|
|
|
|
|
|
|
if (!_gtk_builder_check_parent (data->builder, context, "items", error))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_markup_collect_attributes (element_name, names, values, error,
|
|
|
|
G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "id", &id,
|
|
|
|
G_MARKUP_COLLECT_BOOLEAN|G_MARKUP_COLLECT_OPTIONAL, "translatable", &translatable,
|
|
|
|
G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "comments", NULL,
|
|
|
|
G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "context", &msg_context,
|
|
|
|
G_MARKUP_COLLECT_INVALID))
|
|
|
|
{
|
|
|
|
_gtk_builder_prefix_error (data->builder, context, error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->is_text = TRUE;
|
|
|
|
data->translatable = translatable;
|
|
|
|
data->context = g_strdup (msg_context);
|
|
|
|
data->id = g_strdup (id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_gtk_builder_error_unhandled_tag (data->builder, context,
|
|
|
|
"GtkComboBoxText", element_name,
|
|
|
|
error);
|
2011-01-09 06:25:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-29 13:21:20 +00:00
|
|
|
item_text (GtkBuildableParseContext *context,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *text,
|
2019-08-29 13:21:20 +00:00
|
|
|
gsize text_len,
|
|
|
|
gpointer user_data,
|
|
|
|
GError **error)
|
2011-01-09 06:25:53 +00:00
|
|
|
{
|
|
|
|
ItemParserData *data = (ItemParserData*)user_data;
|
|
|
|
|
2011-01-26 12:56:43 +00:00
|
|
|
if (data->is_text)
|
|
|
|
g_string_append_len (data->string, text, text_len);
|
2011-01-09 06:25:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-29 13:21:20 +00:00
|
|
|
item_end_element (GtkBuildableParseContext *context,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *element_name,
|
2019-08-29 13:21:20 +00:00
|
|
|
gpointer user_data,
|
|
|
|
GError **error)
|
2011-01-09 06:25:53 +00:00
|
|
|
{
|
|
|
|
ItemParserData *data = (ItemParserData*)user_data;
|
|
|
|
|
|
|
|
/* Append the translated strings */
|
2011-01-26 12:44:18 +00:00
|
|
|
if (data->string->len)
|
|
|
|
{
|
|
|
|
if (data->translatable)
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *translated;
|
2011-01-26 12:44:18 +00:00
|
|
|
|
|
|
|
translated = _gtk_builder_parser_translate (data->domain,
|
|
|
|
data->context,
|
|
|
|
data->string->str);
|
2013-06-07 12:12:14 +00:00
|
|
|
g_string_assign (data->string, translated);
|
2011-01-26 12:44:18 +00:00
|
|
|
}
|
|
|
|
|
2012-01-04 21:32:39 +00:00
|
|
|
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (data->object), data->id, data->string->str);
|
2011-01-26 12:44:18 +00:00
|
|
|
}
|
2011-01-09 06:25:53 +00:00
|
|
|
|
|
|
|
data->translatable = FALSE;
|
2011-01-26 12:44:18 +00:00
|
|
|
g_string_set_size (data->string, 0);
|
2015-04-26 14:26:07 +00:00
|
|
|
g_clear_pointer (&data->context, g_free);
|
|
|
|
g_clear_pointer (&data->id, g_free);
|
2011-01-09 06:25:53 +00:00
|
|
|
data->is_text = FALSE;
|
|
|
|
}
|
|
|
|
|
2019-08-29 13:21:20 +00:00
|
|
|
static const GtkBuildableParser item_parser =
|
2011-01-09 06:25:53 +00:00
|
|
|
{
|
|
|
|
item_start_element,
|
|
|
|
item_end_element,
|
|
|
|
item_text
|
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
2019-08-29 13:21:20 +00:00
|
|
|
gtk_combo_box_text_buildable_custom_tag_start (GtkBuildable *buildable,
|
|
|
|
GtkBuilder *builder,
|
|
|
|
GObject *child,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *tagname,
|
2019-08-29 13:21:20 +00:00
|
|
|
GtkBuildableParser *parser,
|
|
|
|
gpointer *parser_data)
|
2011-01-09 06:25:53 +00:00
|
|
|
{
|
2015-04-26 14:26:07 +00:00
|
|
|
if (buildable_parent_iface->custom_tag_start (buildable, builder, child,
|
|
|
|
tagname, parser, parser_data))
|
2011-01-09 06:25:53 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (strcmp (tagname, "items") == 0)
|
|
|
|
{
|
2015-04-26 14:26:07 +00:00
|
|
|
ItemParserData *data;
|
|
|
|
|
|
|
|
data = g_slice_new0 (ItemParserData);
|
|
|
|
data->builder = g_object_ref (builder);
|
2017-12-08 22:48:47 +00:00
|
|
|
data->object = (GObject *) g_object_ref (buildable);
|
2015-04-26 14:26:07 +00:00
|
|
|
data->domain = gtk_builder_get_translation_domain (builder);
|
|
|
|
data->string = g_string_new ("");
|
2011-01-09 06:25:53 +00:00
|
|
|
|
|
|
|
*parser = item_parser;
|
2015-04-26 14:26:07 +00:00
|
|
|
*parser_data = data;
|
|
|
|
|
2011-01-09 06:25:53 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2015-04-26 14:26:07 +00:00
|
|
|
|
2011-01-09 06:25:53 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_combo_box_text_buildable_custom_finished (GtkBuildable *buildable,
|
2015-04-26 14:26:07 +00:00
|
|
|
GtkBuilder *builder,
|
|
|
|
GObject *child,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *tagname,
|
2015-04-26 14:26:07 +00:00
|
|
|
gpointer user_data)
|
2011-01-09 06:25:53 +00:00
|
|
|
{
|
|
|
|
ItemParserData *data;
|
|
|
|
|
2015-04-26 14:26:07 +00:00
|
|
|
buildable_parent_iface->custom_finished (buildable, builder, child,
|
2011-01-09 06:25:53 +00:00
|
|
|
tagname, user_data);
|
|
|
|
|
|
|
|
if (strcmp (tagname, "items") == 0)
|
|
|
|
{
|
|
|
|
data = (ItemParserData*)user_data;
|
|
|
|
|
|
|
|
g_object_unref (data->object);
|
|
|
|
g_object_unref (data->builder);
|
2011-01-26 12:44:18 +00:00
|
|
|
g_string_free (data->string, TRUE);
|
2011-01-09 06:25:53 +00:00
|
|
|
g_slice_free (ItemParserData, data);
|
|
|
|
}
|
|
|
|
}
|
2010-10-18 12:13:41 +00:00
|
|
|
|
2010-05-19 15:27:47 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_text_new:
|
|
|
|
*
|
2021-02-21 22:21:00 +00:00
|
|
|
* Creates a new `GtkComboBoxText`.
|
2010-05-19 15:27:47 +00:00
|
|
|
*
|
2021-02-21 22:21:00 +00:00
|
|
|
* Returns: A new `GtkComboBoxText`
|
2010-05-19 15:27:47 +00:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_combo_box_text_new (void)
|
|
|
|
{
|
2010-10-16 12:17:34 +00:00
|
|
|
return g_object_new (GTK_TYPE_COMBO_BOX_TEXT,
|
|
|
|
NULL);
|
2010-05-19 15:27:47 +00:00
|
|
|
}
|
|
|
|
|
2010-10-15 20:16:45 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_text_new_with_entry:
|
|
|
|
*
|
2021-02-21 22:21:00 +00:00
|
|
|
* Creates a new `GtkComboBoxText` with an entry.
|
2010-10-15 20:16:45 +00:00
|
|
|
*
|
2021-02-21 22:21:00 +00:00
|
|
|
* Returns: a new `GtkComboBoxText`
|
2010-10-15 20:16:45 +00:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_combo_box_text_new_with_entry (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_COMBO_BOX_TEXT,
|
|
|
|
"has-entry", TRUE,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2010-05-19 15:27:47 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_text_append_text:
|
2021-02-21 22:21:00 +00:00
|
|
|
* @combo_box: A `GtkComboBoxText`
|
2010-05-19 15:27:47 +00:00
|
|
|
* @text: A string
|
|
|
|
*
|
2010-10-23 01:03:50 +00:00
|
|
|
* Appends @text to the list of strings stored in @combo_box.
|
2010-05-19 15:27:47 +00:00
|
|
|
*
|
2021-02-21 22:21:00 +00:00
|
|
|
* This is the same as calling [method@Gtk.ComboBoxText.insert_text]
|
|
|
|
* with a position of -1.
|
2010-05-19 15:27:47 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_combo_box_text_append_text (GtkComboBoxText *combo_box,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *text)
|
2010-05-19 15:27:47 +00:00
|
|
|
{
|
2010-11-30 05:07:08 +00:00
|
|
|
gtk_combo_box_text_insert (combo_box, -1, NULL, text);
|
2010-10-22 21:33:30 +00:00
|
|
|
}
|
2010-05-19 15:27:47 +00:00
|
|
|
|
2010-10-22 21:33:30 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_text_prepend_text:
|
2021-02-21 22:21:00 +00:00
|
|
|
* @combo_box: A `GtkComboBox`
|
2010-10-22 21:33:30 +00:00
|
|
|
* @text: A string
|
|
|
|
*
|
2010-10-23 00:52:24 +00:00
|
|
|
* Prepends @text to the list of strings stored in @combo_box.
|
2010-10-22 21:33:30 +00:00
|
|
|
*
|
2021-02-21 22:21:00 +00:00
|
|
|
* This is the same as calling [method@Gtk.ComboBoxText.insert_text]
|
|
|
|
* with a position of 0.
|
2010-10-22 21:33:30 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_combo_box_text_prepend_text (GtkComboBoxText *combo_box,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *text)
|
2010-10-22 21:33:30 +00:00
|
|
|
{
|
2010-11-30 05:07:08 +00:00
|
|
|
gtk_combo_box_text_insert (combo_box, 0, NULL, text);
|
2010-05-19 15:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_combo_box_text_insert_text:
|
2021-02-21 22:21:00 +00:00
|
|
|
* @combo_box: A `GtkComboBoxText`
|
2010-05-19 15:27:47 +00:00
|
|
|
* @position: An index to insert @text
|
|
|
|
* @text: A string
|
|
|
|
*
|
2010-10-23 00:52:24 +00:00
|
|
|
* Inserts @text at @position in the list of strings stored in @combo_box.
|
2010-05-19 15:27:47 +00:00
|
|
|
*
|
2010-11-30 05:07:08 +00:00
|
|
|
* If @position is negative then @text is appended.
|
|
|
|
*
|
2021-02-21 22:21:00 +00:00
|
|
|
* This is the same as calling [method@Gtk.ComboBoxText.insert]
|
|
|
|
* with a %NULL ID string.
|
2010-05-19 15:27:47 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_combo_box_text_insert_text (GtkComboBoxText *combo_box,
|
2020-07-24 13:54:49 +00:00
|
|
|
int position,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *text)
|
2010-11-30 05:07:08 +00:00
|
|
|
{
|
|
|
|
gtk_combo_box_text_insert (combo_box, position, NULL, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_combo_box_text_append:
|
2021-02-21 22:21:00 +00:00
|
|
|
* @combo_box: A `GtkComboBoxText`
|
2021-05-21 00:45:06 +00:00
|
|
|
* @id: (nullable): a string ID for this value
|
2010-11-30 05:07:08 +00:00
|
|
|
* @text: A string
|
|
|
|
*
|
2011-02-09 04:14:46 +00:00
|
|
|
* Appends @text to the list of strings stored in @combo_box.
|
2021-02-21 22:21:00 +00:00
|
|
|
*
|
2011-02-09 04:14:46 +00:00
|
|
|
* If @id is non-%NULL then it is used as the ID of the row.
|
2010-11-30 05:07:08 +00:00
|
|
|
*
|
2021-02-21 22:21:00 +00:00
|
|
|
* This is the same as calling [method@Gtk.ComboBoxText.insert]
|
|
|
|
* with a position of -1.
|
2010-11-30 05:07:08 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_combo_box_text_append (GtkComboBoxText *combo_box,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *id,
|
|
|
|
const char *text)
|
2010-11-30 05:07:08 +00:00
|
|
|
{
|
|
|
|
gtk_combo_box_text_insert (combo_box, -1, id, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_combo_box_text_prepend:
|
2021-02-21 22:21:00 +00:00
|
|
|
* @combo_box: A `GtkComboBox`
|
2021-05-21 00:45:06 +00:00
|
|
|
* @id: (nullable): a string ID for this value
|
2011-01-06 13:12:01 +00:00
|
|
|
* @text: a string
|
2010-11-30 05:07:08 +00:00
|
|
|
*
|
2011-02-09 04:14:46 +00:00
|
|
|
* Prepends @text to the list of strings stored in @combo_box.
|
2021-02-21 22:21:00 +00:00
|
|
|
*
|
2011-02-09 04:14:46 +00:00
|
|
|
* If @id is non-%NULL then it is used as the ID of the row.
|
2010-11-30 05:07:08 +00:00
|
|
|
*
|
2021-02-21 22:21:00 +00:00
|
|
|
* This is the same as calling [method@Gtk.ComboBoxText.insert]
|
|
|
|
* with a position of 0.
|
2010-11-30 05:07:08 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_combo_box_text_prepend (GtkComboBoxText *combo_box,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *id,
|
|
|
|
const char *text)
|
2010-11-30 05:07:08 +00:00
|
|
|
{
|
|
|
|
gtk_combo_box_text_insert (combo_box, 0, id, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_combo_box_text_insert:
|
2021-02-21 22:21:00 +00:00
|
|
|
* @combo_box: A `GtkComboBoxText`
|
2010-11-30 05:07:08 +00:00
|
|
|
* @position: An index to insert @text
|
2021-05-21 00:45:06 +00:00
|
|
|
* @id: (nullable): a string ID for this value
|
2010-11-30 05:07:08 +00:00
|
|
|
* @text: A string to display
|
|
|
|
*
|
|
|
|
* Inserts @text at @position in the list of strings stored in @combo_box.
|
2021-02-21 22:21:00 +00:00
|
|
|
*
|
|
|
|
* If @id is non-%NULL then it is used as the ID of the row.
|
|
|
|
* See [property@Gtk.ComboBox:id-column].
|
2010-11-30 05:07:08 +00:00
|
|
|
*
|
|
|
|
* If @position is negative then @text is appended.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_combo_box_text_insert (GtkComboBoxText *combo_box,
|
2020-07-24 13:54:49 +00:00
|
|
|
int position,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *id,
|
|
|
|
const char *text)
|
2010-05-19 15:27:47 +00:00
|
|
|
{
|
|
|
|
GtkListStore *store;
|
|
|
|
GtkTreeIter iter;
|
2020-07-24 13:54:49 +00:00
|
|
|
int text_column;
|
2010-05-19 15:27:47 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX_TEXT (combo_box));
|
|
|
|
g_return_if_fail (text != NULL);
|
|
|
|
|
|
|
|
store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)));
|
|
|
|
g_return_if_fail (GTK_IS_LIST_STORE (store));
|
2011-01-09 06:25:53 +00:00
|
|
|
|
2010-10-15 20:16:45 +00:00
|
|
|
text_column = gtk_combo_box_get_entry_text_column (GTK_COMBO_BOX (combo_box));
|
2011-01-09 06:25:53 +00:00
|
|
|
|
|
|
|
if (gtk_combo_box_get_has_entry (GTK_COMBO_BOX (combo_box)))
|
|
|
|
g_return_if_fail (text_column >= 0);
|
|
|
|
else if (text_column < 0)
|
|
|
|
text_column = 0;
|
|
|
|
|
2020-02-22 05:55:08 +00:00
|
|
|
g_return_if_fail (gtk_tree_model_get_column_type (GTK_TREE_MODEL (store), text_column) == G_TYPE_STRING);
|
2010-05-19 15:27:47 +00:00
|
|
|
|
2011-01-09 06:25:53 +00:00
|
|
|
if (position < 0)
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
else
|
|
|
|
gtk_list_store_insert (store, &iter, position);
|
|
|
|
|
2010-10-23 17:28:05 +00:00
|
|
|
gtk_list_store_set (store, &iter, text_column, text, -1);
|
2010-11-30 05:07:08 +00:00
|
|
|
|
|
|
|
if (id != NULL)
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int id_column;
|
2010-11-30 05:07:08 +00:00
|
|
|
|
|
|
|
id_column = gtk_combo_box_get_id_column (GTK_COMBO_BOX (combo_box));
|
2010-12-11 14:12:47 +00:00
|
|
|
g_return_if_fail (id_column >= 0);
|
2020-02-22 05:55:08 +00:00
|
|
|
g_return_if_fail (gtk_tree_model_get_column_type (GTK_TREE_MODEL (store), id_column) == G_TYPE_STRING);
|
2010-11-30 05:07:08 +00:00
|
|
|
|
|
|
|
gtk_list_store_set (store, &iter, id_column, id, -1);
|
|
|
|
}
|
2010-05-19 15:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_combo_box_text_remove:
|
2021-02-21 22:21:00 +00:00
|
|
|
* @combo_box: A `GtkComboBox`
|
2010-05-19 15:27:47 +00:00
|
|
|
* @position: Index of the item to remove
|
|
|
|
*
|
|
|
|
* Removes the string at @position from @combo_box.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_combo_box_text_remove (GtkComboBoxText *combo_box,
|
2020-07-24 13:54:49 +00:00
|
|
|
int position)
|
2010-05-19 15:27:47 +00:00
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkListStore *store;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX_TEXT (combo_box));
|
|
|
|
g_return_if_fail (position >= 0);
|
|
|
|
|
|
|
|
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
|
|
|
|
store = GTK_LIST_STORE (model);
|
|
|
|
g_return_if_fail (GTK_IS_LIST_STORE (store));
|
|
|
|
|
|
|
|
if (gtk_tree_model_iter_nth_child (model, &iter, NULL, position))
|
|
|
|
gtk_list_store_remove (store, &iter);
|
|
|
|
}
|
|
|
|
|
2010-10-21 12:25:08 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_text_remove_all:
|
2021-02-21 22:21:00 +00:00
|
|
|
* @combo_box: A `GtkComboBoxText`
|
2010-10-21 12:25:08 +00:00
|
|
|
*
|
|
|
|
* Removes all the text entries from the combo box.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_combo_box_text_remove_all (GtkComboBoxText *combo_box)
|
|
|
|
{
|
|
|
|
GtkListStore *store;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_COMBO_BOX_TEXT (combo_box));
|
|
|
|
|
|
|
|
store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)));
|
|
|
|
gtk_list_store_clear (store);
|
|
|
|
}
|
|
|
|
|
2010-05-19 15:27:47 +00:00
|
|
|
/**
|
|
|
|
* gtk_combo_box_text_get_active_text:
|
2021-02-21 22:21:00 +00:00
|
|
|
* @combo_box: A `GtkComboBoxText`
|
|
|
|
*
|
|
|
|
* Returns the currently active string in @combo_box.
|
2010-05-19 15:27:47 +00:00
|
|
|
*
|
2021-02-21 22:21:00 +00:00
|
|
|
* If no row is currently selected, %NULL is returned.
|
|
|
|
* If @combo_box contains an entry, this function will
|
|
|
|
* return its contents (which will not necessarily
|
2011-02-19 18:27:51 +00:00
|
|
|
* be an item from the list).
|
2010-05-19 15:27:47 +00:00
|
|
|
*
|
2021-02-21 22:21:00 +00:00
|
|
|
* Returns: (nullable) (transfer full): a newly allocated
|
|
|
|
* string containing the currently active text.
|
|
|
|
* Must be freed with g_free().
|
2010-05-19 15:27:47 +00:00
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
char *
|
2010-05-19 15:27:47 +00:00
|
|
|
gtk_combo_box_text_get_active_text (GtkComboBoxText *combo_box)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *text = NULL;
|
2010-05-19 15:27:47 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_COMBO_BOX_TEXT (combo_box), NULL);
|
|
|
|
|
2011-02-19 18:27:51 +00:00
|
|
|
if (gtk_combo_box_get_has_entry (GTK_COMBO_BOX (combo_box)))
|
|
|
|
{
|
|
|
|
GtkWidget *entry;
|
|
|
|
|
2020-05-03 16:19:17 +00:00
|
|
|
entry = gtk_combo_box_get_child (GTK_COMBO_BOX (combo_box));
|
2019-02-28 19:31:36 +00:00
|
|
|
text = g_strdup (gtk_editable_get_text (GTK_EDITABLE (entry)));
|
2011-02-19 18:27:51 +00:00
|
|
|
}
|
|
|
|
else if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo_box), &iter))
|
2010-05-19 15:27:47 +00:00
|
|
|
{
|
|
|
|
GtkTreeModel *model;
|
2020-07-24 13:54:49 +00:00
|
|
|
int text_column;
|
2010-05-19 15:27:47 +00:00
|
|
|
|
|
|
|
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
|
|
|
|
g_return_val_if_fail (GTK_IS_LIST_STORE (model), NULL);
|
2010-10-15 13:26:00 +00:00
|
|
|
text_column = gtk_combo_box_get_entry_text_column (GTK_COMBO_BOX (combo_box));
|
2010-12-11 14:12:47 +00:00
|
|
|
g_return_val_if_fail (text_column >= 0, NULL);
|
2020-02-22 05:55:08 +00:00
|
|
|
g_return_val_if_fail (gtk_tree_model_get_column_type (model, text_column) == G_TYPE_STRING, NULL);
|
2010-10-15 13:26:00 +00:00
|
|
|
gtk_tree_model_get (model, &iter, text_column, &text, -1);
|
2010-05-19 15:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|