1 /* vim: set ts=4 sw=4 wm=5 : */
2 
3 #include <gtk/gtk.h>
4 #include <gtkspell/gtkspell.h>
5 
6 int
main(int argc,char * argv[])7 main(int argc, char* argv[]) {
8 	GtkWidget *win, *box, *scroll, *view;
9 	GError *error = NULL;
10 	char *errortext = NULL;
11 
12 	gtk_init(&argc, &argv);
13 
14 	view = gtk_text_view_new();
15 	gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD);
16 
17 	if (gtkspell_new_attach(GTK_TEXT_VIEW(view), NULL, &error) == NULL) {
18 		g_print("gtkspell error: %s\n", error->message);
19 		errortext = g_strdup_printf("GtkSpell was unable to initialize.\n"
20 				"%s", error->message);
21 		g_error_free(error);
22 	}
23 
24 	scroll = gtk_scrolled_window_new(NULL, NULL);
25 	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
26 			GTK_POLICY_AUTOMATIC,
27 			GTK_POLICY_AUTOMATIC);
28 	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll),
29 			GTK_SHADOW_IN);
30 	gtk_container_add(GTK_CONTAINER(scroll), view);
31 
32 	box = gtk_vbox_new(FALSE, 5);
33 	if (errortext) {
34 		gtk_box_pack_start(GTK_BOX(box), gtk_label_new(errortext),
35 				FALSE, FALSE, 0);
36 		g_free(errortext);
37 	} else {
38 		gtk_box_pack_start(GTK_BOX(box),
39 				gtk_label_new("Type some text into the text box.\n"
40 					"Try misspelling some words.  Then right-click on them."),
41 				FALSE, FALSE, 0);
42 	}
43 	gtk_box_pack_start(GTK_BOX(box), scroll, TRUE, TRUE, 0);
44 	gtk_widget_show_all(box);
45 
46 	win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
47 	gtk_window_set_default_size(GTK_WINDOW(win), 400, 300);
48 	gtk_window_set_title(GTK_WINDOW(win), "Simple GtkSpell Demonstration");
49 	gtk_container_set_border_width(GTK_CONTAINER(win), 10);
50 	g_signal_connect(G_OBJECT(win), "delete-event",
51 			G_CALLBACK(gtk_main_quit), NULL);
52 	gtk_container_add(GTK_CONTAINER(win), box);
53 
54 	gtk_widget_show(win);
55 	gtk_main();
56 
57 	return 0;
58 }
59