📄 spelling-callbacks.c
字号:
/* TradeClient <http://tradeclient.sourceforge.net> * $Id: spelling-callbacks.c,v 1.3 2001/03/20 22:19:33 ttabner Exp $ * * Copyright (C) 1999-2000 Bynari Inc. * Copyright (C) 2001 Project TradeClient * * LGPL * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Library General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library * General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include "puma.h"int row_selected=-1;void spelling_done (GtkWidget *widget) { GtkWidget *gtext=lw (widget, "spell_text"); gtk_widget_set_sensitive (lw (widget, "skip_button"), FALSE); gtk_widget_set_sensitive (lw (widget, "replace_button"), FALSE); gtk_widget_set_sensitive (lw (widget, "insert_button"), FALSE); gtk_widget_set_sensitive (lw (widget, "stop_button"), FALSE); gtk_text_insert (GTK_TEXT (gtext), NULL, NULL, NULL, "Finished.", -1);}void spelling_clear_window (GtkWidget *widget) { GtkCList *gclist=GTK_CLIST (lw (widget, "spell_correct_clist")); GtkWidget *gtext=lw (widget, "spell_text"); GtkWidget *gentry=lw (widget, "spell_word"); gtk_text_set_point (GTK_TEXT (gtext), 0); gtk_text_forward_delete (GTK_TEXT (gtext), gtk_text_get_length (GTK_TEXT (gtext))); gtk_entry_set_text (GTK_ENTRY (gentry), ""); gtk_clist_freeze (gclist); gtk_clist_clear (gclist); gtk_clist_thaw (gclist);}int spelling_populate_window (GtkWidget *widget, CheckSpelling *cs) { GtkWidget *gtext=lw (widget, "spell_text"); GdkFont *gfnt=gdk_font_load ("-*-helvetica-bold-r-*--*-*-*-*-*-*-*-1"); GtkCList *gclist=GTK_CLIST (lw (widget, "spell_correct_clist")); GtkWidget *gentry=lw (widget, "spell_word"); Misspelled *msw; char *text; char *ctext[1]; int i; msw=cs->msws[cs->curimsw-1];// spell_print_cs (cs);// spell_print_msw (msw); if (msw) { gtk_entry_set_text (GTK_ENTRY (gentry), msw->origword); for (i=0; i<msw->numofsugg; i++) { ctext[0]=strdup (msw->sugg[i]); gtk_clist_append (gclist, ctext); free (ctext[0]); } text=(char *)calloc (42, sizeof(char)); if (cs->ph1-40>0) memmove (text, cs->text+(cs->ph1-40), 40); else memmove (text, cs->text, cs->ph1); gtk_text_insert (GTK_TEXT (gtext), NULL, NULL, NULL, text, -1); free (text); text=(char *)calloc (cs->ph2-cs->ph1+2, sizeof(char)); memmove (text, cs->text+cs->ph1, cs->ph2-cs->ph1); gtk_text_insert (GTK_TEXT (gtext), gfnt, NULL, NULL, text, -1); free (text); text=(char *)calloc (42, sizeof(char)); if (cs->ph2+40 > strlen (cs->text)) memmove (text, cs->text+cs->ph2, strlen (cs->text+cs->ph2)); else memmove (text, cs->text+cs->ph2, 40); gtk_text_insert (GTK_TEXT (gtext), NULL, NULL, NULL, text, -1); free (text); return TRUE; } return FALSE;}void spelling_widget_destroy (GtkWidget *widget, GdkEvent *event, CheckSpelling *cs) { GtkWidget *wid; GtkWidget *textb; if (cs) { wid=(GtkWidget *)cs->extra; textb=lw (wid, "body_textbox"); gtk_text_set_point (GTK_TEXT (textb), 0); gtk_text_forward_delete (GTK_TEXT (textb), gtk_text_get_length (GTK_TEXT (textb))); gtk_text_insert (GTK_TEXT (textb), NULL, NULL, NULL, cs->text, -1); spell_destroy_cs (cs); } gtk_widget_destroy (lw (widget, "spelling_window"));}void spelling_widget_skip (GtkWidget *widget, CheckSpelling *cs) { Misspelled *msw; msw=spell_getnext_misspelled (cs); spelling_clear_window (widget); if (!msw || !spelling_populate_window (widget, cs)) { spelling_done (widget); }}void spelling_widget_replace (GtkWidget *widget, CheckSpelling *cs) { GtkWidget *gentry=lw (widget, "spell_word"); Misspelled *msw; char *word; word=gtk_entry_get_text (GTK_ENTRY(gentry)); spell_insert_correction (cs, word); msw=spell_getnext_misspelled (cs); spelling_clear_window (widget); if (!msw || !spelling_populate_window (widget, cs)) { spelling_done (widget); }}void spelling_widget_insert (GtkWidget *widget, CheckSpelling *cs) { GtkWidget *gentry=lw (widget, "spell_word"); Misspelled *msw; char *word; word=gtk_entry_get_text (GTK_ENTRY(gentry)); spell_insert_todict_word (word); msw=spell_getnext_misspelled (cs); spelling_clear_window (widget); if (!msw || !spelling_populate_window (widget, cs)) { spelling_done (widget); }}void spelling_widget_stop (GtkWidget *widget, CheckSpelling *cs) { spelling_widget_destroy (widget, NULL, cs);}void spelling_widget_suggestion_selected (GtkWidget *widget, gint row, gint column, GdkEventButton *event, gpointer data) { char *text; gtk_clist_get_text (GTK_CLIST (widget), row, 0, &text); gtk_entry_set_text (GTK_ENTRY (lw (widget, "spell_word")), text); row_selected=row;}void spelling_widget_suggestion_unselected (GtkWidget *widget, gint row, gint column, GdkEventButton *event, gpointer data) { row_selected=-1;}void spelling_entry_changed (GtkWidget *widget, CheckSpelling *cs) { GtkWidget *gentry=lw (widget, "spell_word"); GtkCList *gclist=GTK_CLIST (lw (widget, "spell_correct_clist")); Misspelled *msw=cs->msws[cs->curimsw-1]; char *word, *ctext[1]; int i, issugg=FALSE; word=gtk_entry_get_text (GTK_ENTRY(gentry)); if (strncmp (msw->origword, word, strlen (word))==0) { issugg=TRUE; } else { for (i=0; i<msw->numofsugg; i++) { if (strncmp (msw->sugg[i], word, strlen (word))==0) { issugg=TRUE; break; } } } if (issugg==FALSE) { msw=spell_check_word (word); if (msw) { gtk_clist_freeze (gclist); gtk_clist_clear (gclist); gtk_clist_thaw (gclist); if (!msw->correct) { for (i=0; i<msw->numofsugg; i++) { ctext[0]=strdup (msw->sugg[i]); gtk_clist_append (gclist, ctext); free (ctext[0]); } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -