GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Files
Gtk Utilities

Files

file  gnc-gtk-utils.h
 gtk helper routines.
 

gtk Miscellaneous Functions

void gnc_cbwe_set_by_string (GtkComboBox *cbwe, const gchar *text)
 
void gnc_cbwe_add_completion (GtkComboBox *cbwe)
 
void gnc_cbwe_require_list_item (GtkComboBox *cbwe)
 

Detailed Description

The API in this file is designed to provide support functions that wrap the base gtk functions and make them easier to use.

Function Documentation

void gnc_cbwe_set_by_string ( GtkComboBox *  cbwe,
const gchar *  text 
)

Find an entry in the GtkComboBox by its text value, and set the widget to that value. This function also records the index of that text value for use when the user leaves the widget.

Parameters
cbweA pointer to a GtkComboBox with entry widget.
textThe entry text to find in the model of the combo box entry.

Definition at line 41 of file gnc-gtk-utils.c.

43 {
44  GtkTreeModel *model;
45  GtkTreeIter iter;
46  gchar *tree_string;
47  gint column, index, id;
48  gboolean match;
49 
50  model = gtk_combo_box_get_model(GTK_COMBO_BOX(cbwe));
51  if (!gtk_tree_model_get_iter_first(model, &iter))
52  {
53  /* empty tree */
54  gtk_combo_box_set_active(GTK_COMBO_BOX(cbwe), -1);
55  return;
56  }
57 
58  column = gtk_combo_box_get_entry_text_column(cbwe);
59  do
60  {
61  gtk_tree_model_get(model, &iter, column, &tree_string, -1);
62  match = g_utf8_collate(text, tree_string) == 0;
63  g_free(tree_string);
64  if (!match)
65  continue;
66 
67  /* Found a matching string */
68  id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(cbwe), CHANGED_ID));
69  g_signal_handler_block(cbwe, id);
70  gtk_combo_box_set_active_iter(GTK_COMBO_BOX(cbwe), &iter);
71  g_signal_handler_unblock(cbwe, id);
72 
73  index = gtk_combo_box_get_active(GTK_COMBO_BOX(cbwe));
74  g_object_set_data(G_OBJECT(cbwe), LAST_INDEX, GINT_TO_POINTER(index));
75  return;
76  }
77  while (gtk_tree_model_iter_next(model, &iter));
78 }