Connecting to insert-text and delete-text is the right idea, but you want to connect using g_signal_connect . If you use g_signal_connect_after , then the wrong text was already displayed before correcting it, which may cause the display to flicker. You also need to block the signal handlers when calling gtk_entry_set_text , as this emits delete-text , followed by insert-text . If you do not block signals, you will recursively call your signal handlers. Remember that GObject signals are just function calls. Emitting a signal is the same as calling handlers directly from your code.
I would suggest having a handler for insert-text that looks to see if it needs to change new input. If so, create a new line and do it according to the GtkEditable documentation
g_signal_handlers_block_by_func (editable, insert_text_handler, data); gtk_editable_insert_text (editable, new-text, g_strlen(new_text) , position); g_signal_handlers_unblock_by_func (editable, insert_text_handler, data); g_signal_stop_emission_by_name (editable, "insert_text");
If you do not need to change the input, just come back.
For the delete-text handler, I'll see if you need to change the text (remember that nothing has been deleted yet), and if so, update the entire line with
g_signal_handlers_block_by_func (editable, insert_text_handler, data); g_signal_handlers_block_by_func (editable, delete_text_handler, data); gtk_entry_set_text (GKT_ENTRY (editable), new-text); g_signal_handlers_unblock_by_func (editable, delete_text_handler, data); g_signal_handlers_unblock_by_func (editable, insert_text_handler, data); g_signal_stop_emission_by_name (editable, "delete_text");
return again if you do not need to change the text.