Reputation: 782
GTK+ v2 in C using Code::Blocks on Win7.
I am using the "insert_text" signal for a callback to an entry widget.
Inside the callback function, how do I change the entry field background color?
I think this is not the same as changing the widget color.
My code:
The Callback...
static void VerifyDOW (GtkEntry *entry,
const gchar *text,
gint length,
gint *position,
gpointer data)
{
GtkEditable *editable = GTK_EDITABLE(entry);
const gchar *result = gtk_editable_get_chars (editable, 0, -1); // = g_new (gchar, length);
int i, count = strlen(result);
for (i=0; i < count; i++) {
if ((! isdigit(result[i])) & (result[i] != ',')) {
i = count;
g_signal_handlers_block_by_func (G_OBJECT (editable), G_CALLBACK (VerifyDOW), data);
/* CHANGE FIELD, NOT WIDGET, COLOR HERE */
g_signal_handlers_unblock_by_func (G_OBJECT (editable), G_CALLBACK (VerifyDOW), data);
}
}
g_signal_stop_emission_by_name (G_OBJECT (editable), "insert_text");
g_free (result);
}
Now in Main()...
entry = gtk_entry_new();
gtk_widget_set_tooltip_text (entry, "Valid input, 1..7 and ,");
gtk_entry_set_text(GTK_ENTRY(entry), "1,3,5");
g_signal_connect(G_OBJECT(entry), "insert_text", g_CALLBACK(VerifyDOW), NULL);
gtk_table_attach(GTK_TABLE(table), entry...
Thanks, Mark.
Upvotes: 0
Views: 561
Reputation: 36
Try gtk_widget_modify_base:
GdkColor color = {0, 255<<8, 220<<8, 220<<8};
gtk_widget_modify_base(GTK_WIDGET(entry), GTK_STATE_NORMAL, &color);
Upvotes: 2