GtkSpell Tutorial

Basic GtkSpell
Building using GtkSpell
Simple Programs
Building Using Autoconf

GtkSpell is pretty simple; including it in your program can be as simple as calling gtkspell_new_attach to attach GtkSpell to a GtkTextView. GtkSpell then watches modifications to the GtkTextView and tries to highlight the misspellings.

Basic GtkSpell

Ignoring error-checking, a basic GtkSpell-using program will call gtkspell_new_attach like this:

view = gtk_text_view_new();
gtkspell_new_attach(GTK_TEXT_VIEW(view), NULL, NULL);

Note

I leave the details of setting up the GtkTextView (setting the word wrap mode, packing it into a GtkScrolledWindow) for the GTK documentation to describe.

gtkspell_new_attach returns FALSE if there was an error (currently, the only error is one from the spell-checking backend). If a GError ** was provided as the last argument, the error message can be displayed to the user:

GError *err = NULL; /* this initialization is important. */

/* ... */

if (!gtkspell_new_attach(GTK_TEXT_VIEW(view), NULL, &err)) {
	GtkWidget *errdlg;
	errdlg = gtk_message_dialog_new(main_application_window,
			GTK_DIALOG_DESTROY_WITH_PARENT,
			GTK_MESSAGE_ERROR,
			GTK_BUTTONS_CLOSE,
			"Error initializing spell checking: %s",
			err->message);
	gtk_dialog_run(GTK_DIALOG(errdlg));
	gtk_widget_destroy(errdlg);
	g_error_free(err); /* don't forget to free GErrors when you're done! */
}