2013-12-12 21:21:59 +00:00
|
|
|
/* Combo Boxes
|
2005-05-25 06:15:19 +00:00
|
|
|
*
|
2013-12-12 21:21:59 +00:00
|
|
|
* The GtkComboBox widget allows to select one option out of a list.
|
|
|
|
* The GtkComboBoxEntry additionally allows the user to enter a value
|
2011-09-02 03:55:47 +00:00
|
|
|
* that is not in the list of options.
|
2005-05-25 06:15:19 +00:00
|
|
|
*
|
|
|
|
* How the options are displayed is controlled by cell renderers.
|
|
|
|
*/
|
|
|
|
|
2013-06-21 17:46:54 +00:00
|
|
|
#include <glib/gi18n.h>
|
2005-05-25 06:15:19 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2011-09-02 03:55:47 +00:00
|
|
|
enum
|
2005-05-25 06:15:19 +00:00
|
|
|
{
|
2013-06-21 17:46:54 +00:00
|
|
|
ICON_NAME_COL,
|
2005-05-25 06:15:19 +00:00
|
|
|
TEXT_COL
|
|
|
|
};
|
|
|
|
|
|
|
|
static GtkTreeModel *
|
2013-06-21 17:46:54 +00:00
|
|
|
create_icon_store (void)
|
2005-05-25 06:15:19 +00:00
|
|
|
{
|
2020-03-07 14:01:21 +00:00
|
|
|
const char *icon_names[6] = {
|
2013-06-21 17:46:54 +00:00
|
|
|
"dialog-warning",
|
|
|
|
"process-stop",
|
|
|
|
"document-new",
|
|
|
|
"edit-clear",
|
|
|
|
NULL,
|
|
|
|
"document-open"
|
|
|
|
};
|
2020-03-07 14:01:21 +00:00
|
|
|
const char *labels[6] = {
|
2013-06-21 17:46:54 +00:00
|
|
|
N_("Warning"),
|
|
|
|
N_("Stop"),
|
|
|
|
N_("New"),
|
|
|
|
N_("Clear"),
|
2005-05-25 06:15:19 +00:00
|
|
|
NULL,
|
2013-06-21 17:46:54 +00:00
|
|
|
N_("Open")
|
2005-05-25 06:15:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkListStore *store;
|
|
|
|
gint i;
|
|
|
|
|
2013-06-21 17:46:54 +00:00
|
|
|
store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
|
2005-05-25 06:15:19 +00:00
|
|
|
|
2013-06-21 17:46:54 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (icon_names); i++)
|
2005-05-25 06:15:19 +00:00
|
|
|
{
|
2013-06-21 17:46:54 +00:00
|
|
|
if (icon_names[i])
|
2011-09-02 03:55:47 +00:00
|
|
|
{
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter,
|
2013-06-21 17:46:54 +00:00
|
|
|
ICON_NAME_COL, icon_names[i],
|
|
|
|
TEXT_COL, _(labels[i]),
|
2011-09-02 03:55:47 +00:00
|
|
|
-1);
|
|
|
|
}
|
2005-05-25 06:15:19 +00:00
|
|
|
else
|
2011-09-02 03:55:47 +00:00
|
|
|
{
|
|
|
|
gtk_list_store_append (store, &iter);
|
|
|
|
gtk_list_store_set (store, &iter,
|
2013-06-21 17:46:54 +00:00
|
|
|
ICON_NAME_COL, NULL,
|
2011-09-02 03:55:47 +00:00
|
|
|
TEXT_COL, "separator",
|
|
|
|
-1);
|
|
|
|
}
|
2005-05-25 06:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return GTK_TREE_MODEL (store);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A GtkCellLayoutDataFunc that demonstrates how one can control
|
2011-09-02 03:55:47 +00:00
|
|
|
* sensitivity of rows. This particular function does nothing
|
2005-05-25 06:15:19 +00:00
|
|
|
* useful and just makes the second row insensitive.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
set_sensitive (GtkCellLayout *cell_layout,
|
2011-09-02 03:55:47 +00:00
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
2005-05-25 06:15:19 +00:00
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
gint *indices;
|
|
|
|
gboolean sensitive;
|
|
|
|
|
|
|
|
path = gtk_tree_model_get_path (tree_model, iter);
|
|
|
|
indices = gtk_tree_path_get_indices (path);
|
|
|
|
sensitive = indices[0] != 1;
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
g_object_set (cell, "sensitive", sensitive, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A GtkTreeViewRowSeparatorFunc that demonstrates how rows can be
|
2011-09-02 03:55:47 +00:00
|
|
|
* rendered as separators. This particular function does nothing
|
2005-05-25 06:15:19 +00:00
|
|
|
* useful and just turns the fourth row into a separator.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
is_separator (GtkTreeModel *model,
|
2011-09-02 03:55:47 +00:00
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
2005-05-25 06:15:19 +00:00
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
path = gtk_tree_model_get_path (model, iter);
|
|
|
|
result = gtk_tree_path_get_indices (path)[0] == 4;
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkTreeModel *
|
|
|
|
create_capital_store (void)
|
|
|
|
{
|
|
|
|
struct {
|
2020-03-07 14:01:21 +00:00
|
|
|
const char *group;
|
|
|
|
const char *capital;
|
2005-05-25 06:15:19 +00:00
|
|
|
} capitals[] = {
|
2011-09-02 03:55:47 +00:00
|
|
|
{ "A - B", NULL },
|
2005-05-25 06:15:19 +00:00
|
|
|
{ NULL, "Albany" },
|
|
|
|
{ NULL, "Annapolis" },
|
|
|
|
{ NULL, "Atlanta" },
|
2011-09-02 03:55:47 +00:00
|
|
|
{ NULL, "Augusta" },
|
2005-05-25 06:15:19 +00:00
|
|
|
{ NULL, "Austin" },
|
|
|
|
{ NULL, "Baton Rouge" },
|
|
|
|
{ NULL, "Bismarck" },
|
|
|
|
{ NULL, "Boise" },
|
|
|
|
{ NULL, "Boston" },
|
|
|
|
{ "C - D", NULL },
|
|
|
|
{ NULL, "Carson City" },
|
|
|
|
{ NULL, "Charleston" },
|
|
|
|
{ NULL, "Cheyenne" },
|
|
|
|
{ NULL, "Columbia" },
|
|
|
|
{ NULL, "Columbus" },
|
|
|
|
{ NULL, "Concord" },
|
|
|
|
{ NULL, "Denver" },
|
|
|
|
{ NULL, "Des Moines" },
|
|
|
|
{ NULL, "Dover" },
|
|
|
|
{ "E - J", NULL },
|
|
|
|
{ NULL, "Frankfort" },
|
|
|
|
{ NULL, "Harrisburg" },
|
|
|
|
{ NULL, "Hartford" },
|
|
|
|
{ NULL, "Helena" },
|
|
|
|
{ NULL, "Honolulu" },
|
|
|
|
{ NULL, "Indianapolis" },
|
|
|
|
{ NULL, "Jackson" },
|
|
|
|
{ NULL, "Jefferson City" },
|
|
|
|
{ NULL, "Juneau" },
|
2018-12-10 04:25:02 +00:00
|
|
|
{ "K - O", NULL },
|
2005-05-25 06:15:19 +00:00
|
|
|
{ NULL, "Lansing" },
|
|
|
|
{ NULL, "Lincoln" },
|
|
|
|
{ NULL, "Little Rock" },
|
|
|
|
{ NULL, "Madison" },
|
|
|
|
{ NULL, "Montgomery" },
|
|
|
|
{ NULL, "Montpelier" },
|
|
|
|
{ NULL, "Nashville" },
|
|
|
|
{ NULL, "Oklahoma City" },
|
|
|
|
{ NULL, "Olympia" },
|
2018-12-10 04:25:02 +00:00
|
|
|
{ "P - S", NULL },
|
2005-05-25 06:15:19 +00:00
|
|
|
{ NULL, "Phoenix" },
|
|
|
|
{ NULL, "Pierre" },
|
|
|
|
{ NULL, "Providence" },
|
|
|
|
{ NULL, "Raleigh" },
|
|
|
|
{ NULL, "Richmond" },
|
|
|
|
{ NULL, "Sacramento" },
|
|
|
|
{ NULL, "Salem" },
|
|
|
|
{ NULL, "Salt Lake City" },
|
|
|
|
{ NULL, "Santa Fe" },
|
|
|
|
{ NULL, "Springfield" },
|
|
|
|
{ NULL, "St. Paul" },
|
|
|
|
{ "T - Z", NULL },
|
|
|
|
{ NULL, "Tallahassee" },
|
|
|
|
{ NULL, "Topeka" },
|
|
|
|
{ NULL, "Trenton" },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2005-05-25 06:15:19 +00:00
|
|
|
GtkTreeIter iter, iter2;
|
|
|
|
GtkTreeStore *store;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
store = gtk_tree_store_new (1, G_TYPE_STRING);
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2005-05-25 06:15:19 +00:00
|
|
|
for (i = 0; capitals[i].group || capitals[i].capital; i++)
|
|
|
|
{
|
|
|
|
if (capitals[i].group)
|
2011-09-02 03:55:47 +00:00
|
|
|
{
|
|
|
|
gtk_tree_store_append (store, &iter, NULL);
|
|
|
|
gtk_tree_store_set (store, &iter, 0, capitals[i].group, -1);
|
|
|
|
}
|
2005-05-25 06:15:19 +00:00
|
|
|
else if (capitals[i].capital)
|
2011-09-02 03:55:47 +00:00
|
|
|
{
|
|
|
|
gtk_tree_store_append (store, &iter2, &iter);
|
|
|
|
gtk_tree_store_set (store, &iter2, 0, capitals[i].capital, -1);
|
|
|
|
}
|
2005-05-25 06:15:19 +00:00
|
|
|
}
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2005-05-25 06:15:19 +00:00
|
|
|
return GTK_TREE_MODEL (store);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
is_capital_sensitive (GtkCellLayout *cell_layout,
|
2011-09-02 03:55:47 +00:00
|
|
|
GtkCellRenderer *cell,
|
|
|
|
GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
2005-05-25 06:15:19 +00:00
|
|
|
{
|
|
|
|
gboolean sensitive;
|
|
|
|
|
|
|
|
sensitive = !gtk_tree_model_iter_has_child (tree_model, iter);
|
|
|
|
|
|
|
|
g_object_set (cell, "sensitive", sensitive, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-10-18 07:10:27 +00:00
|
|
|
fill_combo_entry (GtkWidget *combo)
|
2005-05-25 06:15:19 +00:00
|
|
|
{
|
2010-10-18 07:10:27 +00:00
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "One");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Two");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "2\302\275");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Three");
|
2005-05-25 06:15:19 +00:00
|
|
|
}
|
|
|
|
|
2007-04-26 15:55:48 +00:00
|
|
|
|
|
|
|
/* A simple validating entry */
|
|
|
|
|
|
|
|
#define TYPE_MASK_ENTRY (mask_entry_get_type ())
|
|
|
|
#define MASK_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MASK_ENTRY, MaskEntry))
|
|
|
|
#define MASK_ENTRY_CLASS(vtable) (G_TYPE_CHECK_CLASS_CAST ((vtable), TYPE_MASK_ENTRY, MaskEntryClass))
|
|
|
|
#define IS_MASK_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MASK_ENTRY))
|
|
|
|
#define IS_MASK_ENTRY_CLASS(vtable) (G_TYPE_CHECK_CLASS_TYPE ((vtable), TYPE_MASK_ENTRY))
|
|
|
|
#define MASK_ENTRY_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), TYPE_MASK_ENTRY, MaskEntryClass))
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _MaskEntry MaskEntry;
|
|
|
|
struct _MaskEntry
|
|
|
|
{
|
|
|
|
GtkEntry entry;
|
2020-03-07 14:01:21 +00:00
|
|
|
const char *mask;
|
2007-04-26 15:55:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _MaskEntryClass MaskEntryClass;
|
|
|
|
struct _MaskEntryClass
|
|
|
|
{
|
|
|
|
GtkEntryClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-09-11 02:12:42 +00:00
|
|
|
static void mask_entry_editable_init (GtkEditableInterface *iface);
|
2007-04-26 15:55:48 +00:00
|
|
|
|
2020-03-07 14:01:21 +00:00
|
|
|
static GType mask_entry_get_type (void);
|
2007-04-26 15:55:48 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (MaskEntry, mask_entry, GTK_TYPE_ENTRY,
|
2011-09-02 03:55:47 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
|
|
|
|
mask_entry_editable_init));
|
2007-04-26 15:55:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
mask_entry_set_background (MaskEntry *entry)
|
|
|
|
{
|
|
|
|
if (entry->mask)
|
|
|
|
{
|
2019-02-28 19:31:36 +00:00
|
|
|
if (!g_regex_match_simple (entry->mask, gtk_editable_get_text (GTK_EDITABLE (entry)), 0, 0))
|
2011-09-02 03:55:47 +00:00
|
|
|
{
|
2014-10-03 04:38:21 +00:00
|
|
|
PangoAttrList *attrs;
|
|
|
|
|
|
|
|
attrs = pango_attr_list_new ();
|
|
|
|
pango_attr_list_insert (attrs, pango_attr_foreground_new (65535, 32767, 32767));
|
|
|
|
gtk_entry_set_attributes (GTK_ENTRY (entry), attrs);
|
|
|
|
pango_attr_list_unref (attrs);
|
2011-09-02 03:55:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-04-26 15:55:48 +00:00
|
|
|
}
|
|
|
|
|
2014-10-03 04:38:21 +00:00
|
|
|
gtk_entry_set_attributes (GTK_ENTRY (entry), NULL);
|
2007-04-26 15:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
mask_entry_changed (GtkEditable *editable)
|
|
|
|
{
|
|
|
|
mask_entry_set_background (MASK_ENTRY (editable));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
mask_entry_init (MaskEntry *entry)
|
|
|
|
{
|
|
|
|
entry->mask = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
mask_entry_class_init (MaskEntryClass *klass)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2010-09-11 02:12:42 +00:00
|
|
|
mask_entry_editable_init (GtkEditableInterface *iface)
|
2007-04-26 15:55:48 +00:00
|
|
|
{
|
|
|
|
iface->changed = mask_entry_changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-25 06:15:19 +00:00
|
|
|
GtkWidget *
|
|
|
|
do_combobox (GtkWidget *do_widget)
|
|
|
|
{
|
|
|
|
static GtkWidget *window = NULL;
|
2007-04-26 15:55:48 +00:00
|
|
|
GtkWidget *vbox, *frame, *box, *combo, *entry;
|
2005-05-25 06:15:19 +00:00
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
if (!window)
|
|
|
|
{
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2017-10-31 06:41:15 +00:00
|
|
|
gtk_window_set_display (GTK_WINDOW (window),
|
|
|
|
gtk_widget_get_display (do_widget));
|
2015-06-20 01:59:15 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Combo Boxes");
|
2020-05-09 16:03:11 +00:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (vbox, 10);
|
|
|
|
gtk_widget_set_margin_end (vbox, 10);
|
|
|
|
gtk_widget_set_margin_top (vbox, 10);
|
|
|
|
gtk_widget_set_margin_bottom (vbox, 10);
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), vbox);
|
2005-05-25 06:15:19 +00:00
|
|
|
|
|
|
|
/* A combobox demonstrating cell renderers, separators and
|
2011-09-02 03:55:47 +00:00
|
|
|
* insensitive rows
|
2005-05-25 06:15:19 +00:00
|
|
|
*/
|
2013-06-21 17:46:54 +00:00
|
|
|
frame = gtk_frame_new ("Items with icons");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), frame);
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (box, 5);
|
|
|
|
gtk_widget_set_margin_end (box, 5);
|
|
|
|
gtk_widget_set_margin_top (box, 5);
|
|
|
|
gtk_widget_set_margin_bottom (box, 5);
|
2020-05-01 17:41:22 +00:00
|
|
|
gtk_frame_set_child (GTK_FRAME (frame), box);
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2013-06-21 17:46:54 +00:00
|
|
|
model = create_icon_store ();
|
2005-05-25 06:15:19 +00:00
|
|
|
combo = gtk_combo_box_new_with_model (model);
|
|
|
|
g_object_unref (model);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), combo);
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2005-05-25 06:15:19 +00:00
|
|
|
renderer = gtk_cell_renderer_pixbuf_new ();
|
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, FALSE);
|
|
|
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer,
|
2013-06-21 17:46:54 +00:00
|
|
|
"icon-name", ICON_NAME_COL,
|
2011-09-02 03:55:47 +00:00
|
|
|
NULL);
|
2005-05-25 06:15:19 +00:00
|
|
|
|
|
|
|
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo),
|
2011-09-02 03:55:47 +00:00
|
|
|
renderer,
|
|
|
|
set_sensitive,
|
|
|
|
NULL, NULL);
|
|
|
|
|
2005-05-25 06:15:19 +00:00
|
|
|
renderer = gtk_cell_renderer_text_new ();
|
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
|
|
|
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer,
|
2011-09-02 03:55:47 +00:00
|
|
|
"text", TEXT_COL,
|
|
|
|
NULL);
|
2005-05-25 06:15:19 +00:00
|
|
|
|
|
|
|
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo),
|
2011-09-02 03:55:47 +00:00
|
|
|
renderer,
|
|
|
|
set_sensitive,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo),
|
|
|
|
is_separator, NULL, NULL);
|
2005-05-25 06:15:19 +00:00
|
|
|
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2005-05-25 06:15:19 +00:00
|
|
|
/* A combobox demonstrating trees.
|
|
|
|
*/
|
|
|
|
frame = gtk_frame_new ("Where are we ?");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), frame);
|
2005-05-25 06:15:19 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (box, 5);
|
|
|
|
gtk_widget_set_margin_end (box, 5);
|
|
|
|
gtk_widget_set_margin_top (box, 5);
|
|
|
|
gtk_widget_set_margin_bottom (box, 5);
|
2020-05-01 17:41:22 +00:00
|
|
|
gtk_frame_set_child (GTK_FRAME (frame), box);
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2005-05-25 06:15:19 +00:00
|
|
|
model = create_capital_store ();
|
|
|
|
combo = gtk_combo_box_new_with_model (model);
|
|
|
|
g_object_unref (model);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), combo);
|
2005-05-25 06:15:19 +00:00
|
|
|
|
|
|
|
renderer = gtk_cell_renderer_text_new ();
|
|
|
|
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
|
|
|
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer,
|
2011-09-02 03:55:47 +00:00
|
|
|
"text", 0,
|
|
|
|
NULL);
|
2005-05-25 06:15:19 +00:00
|
|
|
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (combo),
|
2011-09-02 03:55:47 +00:00
|
|
|
renderer,
|
|
|
|
is_capital_sensitive,
|
|
|
|
NULL, NULL);
|
2005-05-25 06:15:19 +00:00
|
|
|
|
|
|
|
path = gtk_tree_path_new_from_indices (0, 8, -1);
|
|
|
|
gtk_tree_model_get_iter (model, &iter, path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);
|
|
|
|
|
2015-06-28 13:23:28 +00:00
|
|
|
/* A GtkComboBoxEntry with validation */
|
2005-05-25 06:15:19 +00:00
|
|
|
frame = gtk_frame_new ("Editable");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), frame);
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (box, 5);
|
|
|
|
gtk_widget_set_margin_end (box, 5);
|
|
|
|
gtk_widget_set_margin_top (box, 5);
|
|
|
|
gtk_widget_set_margin_bottom (box, 5);
|
2020-05-01 17:41:22 +00:00
|
|
|
gtk_frame_set_child (GTK_FRAME (frame), box);
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2010-10-18 07:10:27 +00:00
|
|
|
combo = gtk_combo_box_text_new_with_entry ();
|
2005-05-25 06:15:19 +00:00
|
|
|
fill_combo_entry (combo);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), combo);
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2007-04-26 15:55:48 +00:00
|
|
|
entry = g_object_new (TYPE_MASK_ENTRY, NULL);
|
|
|
|
MASK_ENTRY (entry)->mask = "^([0-9]*|One|Two|2\302\275|Three)$";
|
2011-09-02 03:55:47 +00:00
|
|
|
|
2020-05-03 16:19:17 +00:00
|
|
|
gtk_combo_box_set_child (GTK_COMBO_BOX (combo), entry);
|
2010-11-30 05:07:08 +00:00
|
|
|
|
|
|
|
/* A combobox with string IDs */
|
|
|
|
frame = gtk_frame_new ("String IDs");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), frame);
|
2010-11-30 05:07:08 +00:00
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (box, 5);
|
|
|
|
gtk_widget_set_margin_end (box, 5);
|
|
|
|
gtk_widget_set_margin_top (box, 5);
|
|
|
|
gtk_widget_set_margin_bottom (box, 5);
|
2020-05-01 17:41:22 +00:00
|
|
|
gtk_frame_set_child (GTK_FRAME (frame), box);
|
2010-11-30 05:07:08 +00:00
|
|
|
|
|
|
|
combo = gtk_combo_box_text_new ();
|
|
|
|
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "never", "Not visible");
|
|
|
|
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "when-active", "Visible when active");
|
|
|
|
gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "always", "Always visible");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), combo);
|
2010-11-30 05:07:08 +00:00
|
|
|
|
|
|
|
entry = gtk_entry_new ();
|
|
|
|
g_object_bind_property (combo, "active-id",
|
|
|
|
entry, "text",
|
|
|
|
G_BINDING_BIDIRECTIONAL);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), entry);
|
2005-05-25 06:15:19 +00:00
|
|
|
}
|
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
if (!gtk_widget_get_visible (window))
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2005-05-25 06:15:19 +00:00
|
|
|
else
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2005-05-25 06:15:19 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|