2 * \file FormSpellchecker.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "FormSpellchecker.h"
14 #include "ControlSpellchecker.h"
15 #include "forms/form_spellchecker.h"
18 #include "xforms_helpers.h"
21 #include "support/tostr.h"
23 #include "lyx_forms.h"
29 typedef FormCB<ControlSpellchecker, FormDB<FD_spellchecker> > base_class;
31 FormSpellchecker::FormSpellchecker()
32 : base_class(_("Spell-check Document"))
36 void FormSpellchecker::build()
38 dialog_.reset(build_spellchecker(this));
41 bcview().setCancel(dialog_->button_close);
43 // disable for read-only documents
44 bcview().addReadOnly(dialog_->button_replace);
46 // trigger an input event for cut&paste with middle mouse button.
47 setPrehandler(dialog_->input_replacement);
49 fl_set_input_return(dialog_->input_replacement, FL_RETURN_CHANGED);
51 // callback for double click in browser
52 fl_set_browser_dblclick_callback(dialog_->browser_suggestions,
53 C_FormBaseInputCB, 2);
55 // do not allow setting of slider by the mouse
56 fl_deactivate_object(dialog_->slider_progress);
58 // set up the tooltips
59 string str = _("Type replacement for unknown word "
60 "or select from suggestions.");
61 tooltips().init(dialog_->input_replacement, str);
62 str = _("List of replacement suggestions from dictionary.");
63 tooltips().init(dialog_->browser_suggestions, str);
64 // Work-around xforms' bug; enable tooltips for browser widgets.
65 setPrehandler(dialog_->browser_suggestions);
66 str = _("Replace unknown word.");
67 tooltips().init(dialog_->button_replace, str);
68 str = _("Ignore unknown word.");
69 tooltips().init(dialog_->button_ignore, str);
70 str = _("Accept unknown word as known in this session.");
71 tooltips().init(dialog_->button_accept, str);
72 str = _("Add unknown word to personal dictionary.");
73 tooltips().init(dialog_->button_add, str);
74 str = _("Shows word count and progress on spell check.");
75 tooltips().init(dialog_->slider_progress, str);
79 void FormSpellchecker::partialUpdate(int s)
81 ControlSpellchecker::State const state =
82 static_cast<ControlSpellchecker::State>(s);
86 case ControlSpellchecker::SPELL_FOUND_WORD: {
88 string w = controller().getWord();
89 fl_set_input(dialog_->input_replacement, w.c_str());
90 fl_set_object_label(dialog_->text_unknown, w.c_str());
91 fl_clear_browser(dialog_->browser_suggestions);
92 while (!(w = controller().getSuggestion()).empty()) {
93 fl_add_browser_line(dialog_->browser_suggestions,
99 case ControlSpellchecker::SPELL_PROGRESSED: {
100 int const progress = controller().getProgress();
104 double const wordcount = controller().getCount();
105 double const total = 100.0 * wordcount / progress;
106 string const label = tostr(progress) + " %";
108 fl_set_slider_bounds(dialog_->slider_progress, 0.0, total);
109 fl_set_slider_value(dialog_->slider_progress, wordcount);
110 fl_set_object_label(dialog_->slider_progress, label.c_str());
111 fl_redraw_object(dialog_->slider_progress);
119 ButtonPolicy::SMInput FormSpellchecker::input(FL_OBJECT * ob, long ob_value)
121 if (ob == dialog_->button_replace) {
122 string const tmp = getString(dialog_->input_replacement);
123 controller().replace(tmp);
125 } else if (ob == dialog_->button_ignore) {
126 controller().check();
128 } else if (ob == dialog_->button_accept) {
129 controller().ignoreAll();
131 } else if (ob == dialog_->button_add) {
132 controller().insert();
134 } else if (ob == dialog_->browser_suggestions) {
135 string const tmp = getString(dialog_->browser_suggestions);
137 return ButtonPolicy::SMI_NOOP;
141 // place the chosen string in the input as feedback
142 fl_set_input(dialog_->input_replacement, tmp.c_str());
146 controller().replace(tmp);
147 // reset the browser so that the following
148 // single-click callback doesn't do anything
149 fl_deselect_browser(dialog_->browser_suggestions);
153 return ButtonPolicy::SMI_VALID;