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
14 #pragma implementation
19 #include "xforms_helpers.h"
20 #include "ControlSpellchecker.h"
21 #include "FormSpellchecker.h"
22 #include "forms/form_spellchecker.h"
23 #include FORMS_H_LOCATION
25 typedef FormCB<ControlSpellchecker, FormDB<FD_spellchecker> > base_class;
27 FormSpellchecker::FormSpellchecker()
28 : base_class(_("Spellchecker"))
32 void FormSpellchecker::build()
34 dialog_.reset(build_spellchecker(this));
36 fl_set_browser_dblclick_callback(dialog_->browser,
37 C_FormBaseInputCB, 2);
39 fl_set_input_return(dialog_->input, FL_RETURN_CHANGED);
40 setPrehandler(dialog_->input);
43 bc().setCancel(dialog_->button_close);
44 bc().addReadOnly(dialog_->button_replace);
45 bc().addReadOnly(dialog_->button_accept);
46 bc().addReadOnly(dialog_->button_add);
47 bc().addReadOnly(dialog_->button_ignore);
48 bc().addReadOnly(dialog_->button_start);
49 bc().addReadOnly(dialog_->browser);
51 // set up the tooltips
52 string str = _("Type replacement for unknown word "
53 " or select from suggestions.");
54 tooltips().init(dialog_->input, str);
55 str = _("List of replacement suggestions from dictionary.");
56 tooltips().init(dialog_->browser, str);
57 str = _("Start the spellingchecker.");
58 tooltips().init(dialog_->button_start, str);
59 str = _("Replace unknown word.");
60 tooltips().init(dialog_->button_replace, str);
61 str = _("Ignore unknown word.");
62 tooltips().init(dialog_->button_ignore, str);
63 str = _("Accept unknown word as known in this session.");
64 tooltips().init(dialog_->button_accept, str);
65 str = _("Add unknown word to personal dictionary.");
66 tooltips().init(dialog_->button_add, str);
69 void FormSpellchecker::update()
71 fl_set_input(dialog_->input, "");
72 fl_set_object_label(dialog_->text, "");
73 fl_clear_browser(dialog_->browser);
74 fl_set_slider_value(dialog_->slider, 0);
78 ButtonPolicy::SMInput FormSpellchecker::input(FL_OBJECT * obj, long val)
80 if (obj == dialog_->button_replace) {
81 string const tmp = getString(dialog_->input);
82 controller().replace(tmp);
84 } else if (obj == dialog_->button_start) {
90 } else if (obj == dialog_->button_ignore) {
93 } else if (obj == dialog_->button_accept) {
94 controller().ignoreAll();
96 } else if (obj == dialog_->button_add) {
97 controller().insert();
99 } else if (obj == dialog_->browser) {
100 int const line = fl_get_browser(dialog_->browser);
102 getString(dialog_->browser, line);
104 return ButtonPolicy::SMI_NOOP;
108 // place the chosen string in the input as feedback
109 fl_set_input(dialog_->input, tmp.c_str());
113 controller().replace(tmp);
114 // reset the browser so that the following
115 // single-click callback doesn't do anything
116 fl_deselect_browser_line(dialog_->browser, line);
120 return ButtonPolicy::SMI_VALID;
123 void FormSpellchecker::partialUpdate(int id)
128 fl_set_slider_value(dialog_->slider,
129 controller().getProgress());
134 string w = controller().getWord();
135 fl_set_input(dialog_->input, w.c_str());
136 fl_set_object_label(dialog_->text, w.c_str());
137 fl_clear_browser(dialog_->browser);
138 while (!(w = controller().getSuggestion()).empty()) {
139 fl_add_browser_line(dialog_->browser, w.c_str());
145 fl_show_messages(controller().getMessage().c_str());
151 void FormSpellchecker::showMessage(const char * msg)
153 fl_show_message(msg, "", "");
156 bool FormSpellchecker::start(bool init)
158 static bool running = false;
166 fl_set_object_label(dialog_->button_start,
167 (running ? _("Stop") : _("Start")));
168 fl_set_button_shortcut(dialog_->button_start, "#S", 1);
169 fl_show_object(dialog_->button_start);
171 string const str = (running ? _("Stop the spellingchecker.") :
172 _("Start the spellingchecker."));
173 tooltips().init(dialog_->button_start, str);
175 setEnabled(dialog_->button_replace, running);
176 setEnabled(dialog_->button_ignore, running);
177 setEnabled(dialog_->button_accept, running);
178 setEnabled(dialog_->button_add, running);
179 setEnabled(dialog_->browser, running);
180 setEnabled(dialog_->input, running);