#include <aspell.h>
-#include "gtk/gtktext.h"
#include "utils.h"
#include "codeconv.h"
#include "alertpanel.h"
#include "gtkaspell.h"
+#include "gtk/gtkutils.h"
+
#define ASPELL_FASTMODE 1
#define ASPELL_NORMALMODE 2
#define ASPELL_BADSPELLERMODE 3
/******************************************************************************/
static gint get_textview_buffer_charcount(GtkTextView *view);
-static gint get_textview_buffer_position(GtkTextView *view);
static gint get_textview_buffer_charcount(GtkTextView *view)
{
g_slist_foreach(checkers, free_checkers, NULL);
g_slist_free(checkers);
+ gtkaspellcheckers->checkers = NULL;
}
if ((dict_list = gtkaspellcheckers->dictionary_list)) {
}
g_free(gtkaspellcheckers->error_message);
-
+ gtkaspellcheckers->error_message = NULL;
return;
}
return gtkaspell;
}
-void gtkaspell_delete(GtkAspell * gtkaspell)
+void gtkaspell_delete(GtkAspell *gtkaspell)
{
GtkTextView *gtktext = gtkaspell->gtktext;
g_signal_handlers_disconnect_by_func(G_OBJECT(gtktext),
G_CALLBACK(entry_insert_cb),
- gtkaspell);
+ gtkaspell);
g_signal_handlers_disconnect_by_func(G_OBJECT(gtktext),
G_CALLBACK(entry_delete_cb),
- gtkaspell);
+ gtkaspell);
g_signal_handlers_disconnect_by_func(G_OBJECT(gtktext),
- G_CALLBACK(button_press_intercept_cb),
- gtkaspell);
+ G_CALLBACK(button_press_intercept_cb),
+ gtkaspell);
gtkaspell_uncheck_all(gtkaspell);
free_suggestions_list(gtkaspell);
g_free((gchar *)gtkaspell->dictionary_path);
+ gtkaspell->dictionary_path = NULL;
debug_print("Aspell: deleting gtkaspell %0x\n", (guint) gtkaspell);
gint len,
GtkAspell *gtkaspell)
{
- size_t wlen;
guint pos;
g_return_if_fail(gtkaspell->gtkaspeller->checker);
{
char *themode;
- gtk_label_get(GTK_LABEL(GTK_BIN(w)->child), (gchar **) &themode);
+ themode = (char *) gtk_label_get_text(GTK_LABEL(GTK_BIN(w)->child));
+ themode = g_strdup(themode);
set_real_sug_mode(gtkaspell, themode);
+ g_free(themode);
if (gtkaspell->config_menu)
populate_submenu(gtkaspell, gtkaspell->config_menu);
elements = aspell_word_list_elements(suggestions);
list = g_list_append(list, g_strdup(word));
- while (newword = aspell_string_enumeration_next(elements))
+ while ((newword = aspell_string_enumeration_next(elements)) != NULL)
list = g_list_append(list, g_strdup(newword));
gtkaspell->max_sug = g_list_length(list) - 1;
static gboolean iswordsep(unsigned char c)
{
- return !isalpha(c) && c != '\'';
+ return (isspace(c) || ispunct(c)) && c != '\'';
}
static guchar get_text_index_whar(GtkAspell *gtkaspell, int pos)
c = get_text_index_whar(gtkaspell, start);
if (c == '\'') {
if (start > 0) {
- if (!isalpha(get_text_index_whar(gtkaspell,
+ if (isspace(get_text_index_whar(gtkaspell,
+ start - 1))
+ || ispunct(get_text_index_whar(gtkaspell,
+ start - 1))
+ || isdigit(get_text_index_whar(gtkaspell,
start - 1))) {
/* start_quote = TRUE; */
break;
break;
}
}
- else if (!isalpha(c))
+ else if (isspace(c) || ispunct(c) || isdigit(c))
break;
}
c = get_text_index_whar(gtkaspell, end);
if (c == '\'') {
if (end < get_textview_buffer_charcount(gtktext)) {
- if (!isalpha(get_text_index_whar(gtkaspell,
+ if (isspace(get_text_index_whar(gtkaspell,
+ end + 1))
+ || ispunct(get_text_index_whar(gtkaspell,
+ end + 1))
+ || isdigit(get_text_index_whar(gtkaspell,
end + 1))) {
/* end_quote = TRUE; */
break;
break;
}
}
- else if(!isalpha(c))
+ else if (isspace(c) || ispunct(c) || isdigit(c))
break;
}
if (buf) {
if (end - start < buflen) {
- for (pos = start; pos < end; pos++) {
- buf[pos - start] =
- get_text_index_whar(gtkaspell, pos);
- }
- buf[pos - start] = 0;
+ GtkTextIter iterstart, iterend;
+ gchar *tmp, *conv;
+ GtkTextBuffer *buffer = gtk_text_view_get_buffer(gtktext);
+ gtk_text_buffer_get_iter_at_offset(buffer, &iterstart, start);
+ gtk_text_buffer_get_iter_at_offset(buffer, &iterend, end);
+ tmp = gtk_text_buffer_get_text(buffer, &iterstart, &iterend, FALSE);
+ conv = conv_iconv_strdup(tmp, CS_UTF_8,
+ gtkaspell->gtkaspeller->dictionary->encoding);
+ g_free(tmp);
+ strncpy(buf, conv, buflen-1);
+ buf[buflen]='\0';
+ g_free(conv);
} else
return FALSE;
}
if (!get_word_from_pos(gtkaspell, from_pos, buf, sizeof(buf),
&start, &end))
return FALSE;
-
if (misspelled_test(gtkaspell, buf)) {
strncpy(gtkaspell->theword, buf, GTKASPELLWORDSIZE - 1);
gtkaspell->theword[GTKASPELLWORDSIZE - 1] = 0;
{
unsigned char *newword;
GdkEvent *e= (GdkEvent *) gtk_get_current_event();
-
+
newword = gtk_editable_get_chars(GTK_EDITABLE(gtkaspell->replace_entry),
0, -1);
g_free(newword);
+ if (w && GTK_IS_DIALOG(w)) {
+ gtk_widget_destroy(w);
+ }
+
set_point_continue(gtkaspell);
}
GtkAspell *gtkaspell = (GtkAspell *) data;
GdkEvent *e= (GdkEvent *) gtk_get_current_event();
- gtk_label_get(GTK_LABEL(GTK_BIN(w)->child), (gchar**) &newword);
+ newword = (unsigned char *) gtk_label_get_text(GTK_LABEL(GTK_BIN(w)->child));
+ newword = g_strdup(newword);
replace_real_word(gtkaspell, newword);
gtk_menu_shell_deactivate(GTK_MENU_SHELL(w->parent));
set_point_continue(gtkaspell);
+ g_free(newword);
}
static void replace_real_word(GtkAspell *gtkaspell, gchar *newword)
int oldlen, newlen, wordlen;
gint origpos;
gint pos;
- gint start = gtkaspell->start_pos;
GtkTextView *gtktext;
GtkTextBuffer *textbuf;
GtkTextIter startiter, enditer;
static void add_word_to_personal_cb(GtkWidget *w, gpointer data)
{
GtkAspell *gtkaspell = (GtkAspell *) data;
- GtkTextView *gtktext = gtkaspell->gtktext;
aspell_speller_add_to_personal(gtkaspell->gtkaspeller->checker,
gtkaspell->theword,
gtk_widget_destroy(widget);
return TRUE;
} else if (event && event->keyval == GDK_Return) {
- replace_with_supplied_word_cb(NULL, gtkaspell);
- gtk_widget_destroy(widget);
+ replace_with_supplied_word_cb(widget, gtkaspell);
return TRUE;
}
return FALSE;
static void replace_with_create_dialog_cb(GtkWidget *w, gpointer data)
{
+ static PangoFontDescription *font_desc;
GtkWidget *dialog;
GtkWidget *label;
+ GtkWidget *w_hbox;
GtkWidget *hbox;
+ GtkWidget *vbox;
GtkWidget *entry;
GtkWidget *ok_button;
GtkWidget *cancel_button;
+ GtkWidget *confirm_area;
+ GtkWidget *icon;
gchar *thelabel;
gint xx, yy;
GtkAspell *gtkaspell = (GtkAspell *) data;
gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
gtk_window_set_title(GTK_WINDOW(dialog),_("Replace unknown word"));
+ gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
gtk_widget_set_uposition(dialog, xx, yy);
g_signal_connect_swapped(G_OBJECT(dialog), "destroy",
G_CALLBACK(gtk_widget_destroy),
G_OBJECT(dialog));
- hbox = gtk_hbox_new(FALSE, 0);
- gtk_container_set_border_width(GTK_CONTAINER(hbox), 8);
+ gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 14);
+ hbox = gtk_hbox_new (FALSE, 12);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
+ gtk_widget_show (hbox);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox,
+ FALSE, FALSE, 0);
- thelabel = g_strdup_printf(_("Replace \"%s\" with: "),
+ thelabel = g_strdup_printf(_("<span weight=\"bold\" "
+ "size=\"larger\">Replace \"%s\" with: </span>"),
gtkaspell->theword);
+ /* for title label */
+ w_hbox = gtk_hbox_new(FALSE, 0);
+
+ icon = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION,
+ GTK_ICON_SIZE_DIALOG);
+ gtk_misc_set_alignment (GTK_MISC (icon), 0.5, 0.0);
+ gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
+
+ vbox = gtk_vbox_new (FALSE, 12);
+ gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
+ gtk_widget_show (vbox);
+
label = gtk_label_new(thelabel);
+ gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+ gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
+ gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+ gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+ gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
+ if (!font_desc) {
+ gint size;
+
+ size = pango_font_description_get_size
+ (label->style->font_desc);
+ font_desc = pango_font_description_new();
+ pango_font_description_set_weight
+ (font_desc, PANGO_WEIGHT_BOLD);
+ pango_font_description_set_size
+ (font_desc, size * PANGO_SCALE_LARGE);
+ }
+ if (font_desc)
+ gtk_widget_modify_font(label, font_desc);
g_free(thelabel);
- gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
-
+
entry = gtk_entry_new();
gtkaspell->replace_entry = entry;
gtk_entry_set_text(GTK_ENTRY(entry), gtkaspell->theword);
g_signal_connect(G_OBJECT(dialog),
"key_press_event",
G_CALLBACK(replace_key_pressed), gtkaspell);
- gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, TRUE,
- TRUE, 0);
label = gtk_label_new(_("Holding down Control key while pressing "
"Enter\nwill learn from mistake.\n"));
+ gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
- gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
- gtk_misc_set_padding(GTK_MISC(label), 8, 0);
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), label,
- TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+ gtk_widget_show(label);
hbox = gtk_hbox_new(TRUE, 0);
- ok_button = gtk_button_new_with_label(_("OK"));
- gtk_box_pack_start(GTK_BOX(hbox), ok_button, TRUE, TRUE, 8);
+ gtkut_stock_button_set_create(&confirm_area,
+ &ok_button, GTK_STOCK_OK,
+ &cancel_button, GTK_STOCK_CANCEL,
+ NULL, NULL);
+
+ gtk_box_pack_end(GTK_BOX(GTK_DIALOG(dialog)->action_area),
+ confirm_area, FALSE, FALSE, 0);
+ gtk_container_set_border_width(GTK_CONTAINER(confirm_area), 5);
+
g_signal_connect(G_OBJECT(ok_button), "clicked",
G_CALLBACK(replace_with_supplied_word_cb),
gtkaspell);
G_CALLBACK(gtk_widget_destroy),
G_OBJECT(dialog));
- cancel_button = gtk_button_new_with_label(_("Cancel"));
- gtk_box_pack_start(GTK_BOX(hbox), cancel_button, TRUE, TRUE, 8);
g_signal_connect_swapped(G_OBJECT(cancel_button), "clicked",
G_CALLBACK(gtk_widget_destroy),
G_OBJECT(dialog));
- gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), hbox);
-
gtk_widget_grab_focus(entry);
gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
void gtkaspell_uncheck_all(GtkAspell * gtkaspell)
{
- gint origpos;
- gchar *text;
- gfloat adj_value;
GtkTextView *gtktext;
GtkTextBuffer *buffer;
GtkTextIter startiter, enditer;
list = NULL;
config = new_aspell_config();
-#if 0
- aspell_config_replace(config, "rem-all-word-list-path", "");
- if (aspell_config_error_number(config) != 0) {
- gtkaspellcheckers->error_message = g_strdup(
- aspell_config_error_message(config));
- gtkaspellcheckers->dictionary_list =
- create_empty_dictionary_list();
- return gtkaspellcheckers->dictionary_list;
- }
-#endif
aspell_config_replace(config, "dict-dir", aspell_path);
if (aspell_config_error_number(config) != 0) {
gtkaspellcheckers->error_message = g_strdup(
entry->name);
dict->dictname = dict->fullname + strlen(aspell_path);
dict->encoding = g_strdup(entry->code);
- debug_print("Aspell: found dictionary %s %s\n", dict->fullname,
- dict->dictname);
+
+ if (g_slist_find_custom(list, dict,
+ (GCompareFunc) compare_dict) != NULL) {
+ dictionary_delete(dict);
+ continue;
+ }
+
+ debug_print("Aspell: found dictionary %s %s %s\n", dict->fullname,
+ dict->dictname, dict->encoding);
list = g_slist_insert_sorted(list, dict,
(GCompareFunc) compare_dict);
}
g_signal_connect(G_OBJECT(menu), "cancel",
G_CALLBACK(cancel_menu_cb), gtkaspell);
+ utf8buf = conv_codeset_strdup((unsigned char*)l->data,
+ conv_get_locale_charset_str(),
+ CS_UTF_8);
caption = g_strdup_printf(_("\"%s\" unknown in %s"),
- (unsigned char*) l->data,
+ utf8buf,
gtkaspell->gtkaspeller->dictionary->dictname);
item = gtk_menu_item_new_with_label(caption);
+ g_free(utf8buf);
gtk_widget_show(item);
gtk_menu_append(GTK_MENU(menu), item);
gtk_misc_set_alignment(GTK_MISC(GTK_BIN(item)->child), 0.5, 0.5);
conv_get_locale_charset_str(),
CS_UTF_8);
item = gtk_menu_item_new_with_label(utf8buf);
+ g_free(utf8buf);
gtk_widget_show(item);
gtk_menu_append(GTK_MENU(curmenu), item);
g_signal_connect(G_OBJECT(item), "activate",
dict == gtkaspell->alternate_speller->dictionary) {
use_alternate_dict(gtkaspell);
dictionary_delete(dict);
+ gtkaspell->alternate_speller->dictionary = NULL;
return TRUE;
}
color->blue = (int) (((gdouble) (rgbvalue & 0x0000ff) / 255.0)
* 65535.0);
- gtk_text_buffer_create_tag(buffer, "misspelled",
+ if (rgbvalue != 0)
+ gtk_text_buffer_create_tag(buffer, "misspelled",
"foreground-gdk", color, NULL);
+ else
+ gtk_text_buffer_create_tag(buffer, "misspelled",
+ "underline", PANGO_UNDERLINE_ERROR, NULL);
+
}
static void change_color(GtkAspell * gtkaspell,
GtkTextBuffer *buffer;
GtkTextIter startiter, enditer;
- g_return_if_fail(start < end);
+ if (start > end)
+ return;
gtktext = gtkaspell->gtktext;
if (color)
gtk_text_buffer_apply_tag_by_name(buffer, "misspelled",
&startiter, &enditer);
- else
+ else {
+ gtk_text_iter_forward_char(&enditer);
gtk_text_buffer_remove_tag_by_name(buffer, "misspelled",
&startiter, &enditer);
+ }
}
/* convert_to_aspell_encoding () - converts ISO-8859-* strings to iso8859-*
list = list->next)
g_free(list->data);
- g_list_free(list);
+ g_list_free(gtkaspell->suggestions_list);
gtkaspell->max_sug = -1;
gtkaspell->suggestions_list = NULL;