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 "forms/form_spellchecker.h"
16 #include "controllers/ControlSpellchecker.h"
19 #include "xforms_helpers.h"
22 #include "support/convert.h"
24 #include "lyx_forms.h"
31 typedef FormController<ControlSpellchecker, FormView<FD_spellchecker> > base_class;
33 FormSpellchecker::FormSpellchecker(Dialog & parent)
34 : base_class(parent, _("Spell-check document"))
38 void FormSpellchecker::build()
40 dialog_.reset(build_spellchecker(this));
43 bcview().setCancel(dialog_->button_close);
45 // disable for read-only documents
46 bcview().addReadOnly(dialog_->button_replace);
48 // trigger an input event for cut&paste with middle mouse button.
49 setPrehandler(dialog_->input_replacement);
51 fl_set_input_return(dialog_->input_replacement, FL_RETURN_CHANGED);
53 // callback for double click in browser
54 fl_set_browser_dblclick_callback(dialog_->browser_suggestions,
55 C_FormDialogView_InputCB, 2);
57 // do not allow setting of slider by the mouse
58 fl_deactivate_object(dialog_->slider_progress);
60 // set up the tooltips
61 string str = _("Type replacement for unknown word "
62 "or select from suggestions.");
63 tooltips().init(dialog_->input_replacement, str);
64 str = _("List of replacement suggestions from dictionary.");
65 tooltips().init(dialog_->browser_suggestions, str);
66 // Work-around xforms' bug; enable tooltips for browser widgets.
67 setPrehandler(dialog_->browser_suggestions);
68 str = _("Replace unknown word.");
69 tooltips().init(dialog_->button_replace, str);
70 str = _("Ignore unknown word.");
71 tooltips().init(dialog_->button_ignore, str);
72 str = _("Accept unknown word as known in this session.");
73 tooltips().init(dialog_->button_accept, str);
74 str = _("Add unknown word to personal dictionary.");
75 tooltips().init(dialog_->button_add, str);
76 str = _("Shows word count and progress on spell check.");
77 tooltips().init(dialog_->slider_progress, str);
81 void FormSpellchecker::update()
87 void FormSpellchecker::partialUpdate(int s)
89 ControlSpellchecker::State const state =
90 static_cast<ControlSpellchecker::State>(s);
94 case ControlSpellchecker::SPELL_FOUND_WORD: {
96 string w = controller().getWord();
97 fl_set_input(dialog_->input_replacement, w.c_str());
98 fl_set_object_label(dialog_->text_unknown, w.c_str());
99 fl_clear_browser(dialog_->browser_suggestions);
100 while (!(w = controller().getSuggestion()).empty()) {
101 fl_add_browser_line(dialog_->browser_suggestions,
107 case ControlSpellchecker::SPELL_PROGRESSED: {
108 int const progress = controller().getProgress();
112 double const wordcount = controller().getCount();
113 double const total = 100.0 * wordcount / progress;
114 string const label = convert<string>(progress) + " %";
116 fl_set_slider_bounds(dialog_->slider_progress, 0.0, total);
117 fl_set_slider_value(dialog_->slider_progress, wordcount);
118 fl_set_object_label(dialog_->slider_progress, label.c_str());
119 fl_redraw_object(dialog_->slider_progress);
127 ButtonPolicy::SMInput FormSpellchecker::input(FL_OBJECT * ob, long ob_value)
129 if (ob == dialog_->button_replace) {
130 string const tmp = getString(dialog_->input_replacement);
131 controller().replace(tmp);
133 } else if (ob == dialog_->button_ignore) {
134 controller().check();
136 } else if (ob == dialog_->button_accept) {
137 controller().ignoreAll();
139 } else if (ob == dialog_->button_add) {
140 controller().insert();
142 } else if (ob == dialog_->browser_suggestions) {
143 string const tmp = getString(dialog_->browser_suggestions);
145 return ButtonPolicy::SMI_NOOP;
149 // place the chosen string in the input as feedback
150 fl_set_input(dialog_->input_replacement, tmp.c_str());
154 controller().replace(tmp);
155 // reset the browser so that the following
156 // single-click callback doesn't do anything
157 fl_deselect_browser(dialog_->browser_suggestions);
161 return ButtonPolicy::SMI_VALID;
164 } // namespace frontend