/**
* \file FormSpellchecker.C
- * See the file COPYING.
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
* \author Edwin Leuven
*
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
-#include "xformsBC.h"
-#include "xforms_helpers.h"
-#include "ControlSpellchecker.h"
#include "FormSpellchecker.h"
+#include "ControlSpellchecker.h"
#include "forms/form_spellchecker.h"
-#include FORMS_H_LOCATION
+
+#include "Tooltips.h"
+#include "xforms_helpers.h"
+#include "xformsBC.h"
+
+#include "support/tostr.h"
+
+#include "lyx_forms.h"
+
+
+using std::string;
+
typedef FormCB<ControlSpellchecker, FormDB<FD_spellchecker> > base_class;
FormSpellchecker::FormSpellchecker()
- : base_class(_("LyX: Spellchecker"), false)
+ : base_class(_("Spell-check Document"))
{}
{
dialog_.reset(build_spellchecker(this));
- fl_set_slider_bounds(dialog_->slider, 0.0, 100.0);
- fl_set_slider_step(dialog_->slider, 1.0);
+ // Manage the buttons
+ bcview().setCancel(dialog_->button_close);
- fl_set_browser_dblclick_callback(dialog_->browser,
- C_FormBaseInputCB, 2);
+ // disable for read-only documents
+ bcview().addReadOnly(dialog_->button_replace);
- fl_set_input_return(dialog_->input, FL_RETURN_CHANGED);
- setPrehandler(dialog_->input);
+ // trigger an input event for cut&paste with middle mouse button.
+ setPrehandler(dialog_->input_replacement);
- // Manage the buttons
- bc().setCancel(dialog_->button_close);
- bc().addReadOnly(dialog_->button_replace);
- bc().addReadOnly(dialog_->button_accept);
- bc().addReadOnly(dialog_->button_insert);
- bc().addReadOnly(dialog_->button_ignore);
- bc().addReadOnly(dialog_->button_start);
- bc().addReadOnly(dialog_->button_stop);
- bc().addReadOnly(dialog_->browser);
+ fl_set_input_return(dialog_->input_replacement, FL_RETURN_CHANGED);
+
+ // callback for double click in browser
+ fl_set_browser_dblclick_callback(dialog_->browser_suggestions,
+ C_FormBaseInputCB, 2);
+
+ // do not allow setting of slider by the mouse
+ fl_deactivate_object(dialog_->slider_progress);
+
+ // set up the tooltips
+ string str = _("Type replacement for unknown word "
+ "or select from suggestions.");
+ tooltips().init(dialog_->input_replacement, str);
+ str = _("List of replacement suggestions from dictionary.");
+ tooltips().init(dialog_->browser_suggestions, str);
+ // Work-around xforms' bug; enable tooltips for browser widgets.
+ setPrehandler(dialog_->browser_suggestions);
+ str = _("Replace unknown word.");
+ tooltips().init(dialog_->button_replace, str);
+ str = _("Ignore unknown word.");
+ tooltips().init(dialog_->button_ignore, str);
+ str = _("Accept unknown word as known in this session.");
+ tooltips().init(dialog_->button_accept, str);
+ str = _("Add unknown word to personal dictionary.");
+ tooltips().init(dialog_->button_add, str);
+ str = _("Shows word count and progress on spell check.");
+ tooltips().init(dialog_->slider_progress, str);
}
-void FormSpellchecker::update()
+
+void FormSpellchecker::partialUpdate(int s)
{
- string const w;
- fl_set_input(dialog_->input, w.c_str());
- fl_set_object_label(dialog_->text, w.c_str());
- fl_clear_browser(dialog_->browser);
- fl_set_slider_value(dialog_->slider, 0);
+ ControlSpellchecker::State const state =
+ static_cast<ControlSpellchecker::State>(s);
+
+ switch (state) {
+
+ case ControlSpellchecker::SPELL_FOUND_WORD: {
+ // Set suggestions.
+ string w = controller().getWord();
+ fl_set_input(dialog_->input_replacement, w.c_str());
+ fl_set_object_label(dialog_->text_unknown, w.c_str());
+ fl_clear_browser(dialog_->browser_suggestions);
+ while (!(w = controller().getSuggestion()).empty()) {
+ fl_add_browser_line(dialog_->browser_suggestions,
+ w.c_str());
+ }
+ // Fall through...
+ }
+
+ case ControlSpellchecker::SPELL_PROGRESSED: {
+ int const progress = controller().getProgress();
+ if (progress == 0)
+ break;
+
+ double const wordcount = controller().getCount();
+ double const total = 100.0 * wordcount / progress;
+ string const label = tostr(progress) + " %";
+
+ fl_set_slider_bounds(dialog_->slider_progress, 0.0, total);
+ fl_set_slider_value(dialog_->slider_progress, wordcount);
+ fl_set_object_label(dialog_->slider_progress, label.c_str());
+ fl_redraw_object(dialog_->slider_progress);
+ break;
+ }
+
+ }
}
-ButtonPolicy::SMInput FormSpellchecker::input(FL_OBJECT * obj, long val)
+
+ButtonPolicy::SMInput FormSpellchecker::input(FL_OBJECT * ob, long ob_value)
{
- if (obj == dialog_->button_replace) {
- string const tmp = getString(dialog_->input);
+ if (ob == dialog_->button_replace) {
+ string const tmp = getString(dialog_->input_replacement);
controller().replace(tmp);
- } else if (obj == dialog_->button_start) {
+ } else if (ob == dialog_->button_ignore) {
controller().check();
- stop(false);
- } else if (obj == dialog_->button_stop) {
- controller().stop();
- stop(true);
-
- } else if (obj == dialog_->button_ignore) {
- controller().check();
-
- } else if (obj == dialog_->button_accept) {
+ } else if (ob == dialog_->button_accept) {
controller().ignoreAll();
- } else if (obj == dialog_->button_insert) {
+ } else if (ob == dialog_->button_add) {
controller().insert();
- } else if (obj == dialog_->browser) {
- int const line = fl_get_browser(dialog_->browser);
- string const tmp =
- getString(dialog_->browser, line);
+ } else if (ob == dialog_->browser_suggestions) {
+ string const tmp = getString(dialog_->browser_suggestions);
if (tmp.empty())
return ButtonPolicy::SMI_NOOP;
- if (val != 2) {
+ if (ob_value != 2) {
// single-click
// place the chosen string in the input as feedback
- fl_set_input(dialog_->input, tmp.c_str());
+ fl_set_input(dialog_->input_replacement, tmp.c_str());
} else {
// double-click
controller().replace(tmp);
// reset the browser so that the following
// single-click callback doesn't do anything
- fl_deselect_browser_line(dialog_->browser, line);
+ fl_deselect_browser(dialog_->browser_suggestions);
}
}
return ButtonPolicy::SMI_VALID;
}
-
-void FormSpellchecker::partialUpdate(int id)
-{
- switch (id) {
- case 0:
- // set progress bar
- fl_set_slider_value(dialog_->slider,
- controller().getProgress());
- break;
- case 1:
- {
- // set suggestions
- string w = controller().getWord();
- fl_set_input(dialog_->input, w.c_str());
- fl_set_object_label(dialog_->text, w.c_str());
- fl_clear_browser(dialog_->browser);
- while (!(w = controller().getSuggestion()).empty()) {
- fl_add_browser_line(dialog_->browser, w.c_str());
- }
- }
- break;
- case 2:
- // show exit message
- fl_show_messages(controller().getMessage().c_str());
- hide();
- }
-}
-
-
-void FormSpellchecker::showMessage(const char * msg)
-{
- fl_show_message(msg, "", "");
-}
-
-void FormSpellchecker::stop(bool stop)
-{
- setEnabled(dialog_->button_start, stop);
- setEnabled(dialog_->button_replace, !stop);
- setEnabled(dialog_->button_ignore, !stop);
- setEnabled(dialog_->button_accept, !stop);
- setEnabled(dialog_->button_insert, !stop);
- setEnabled(dialog_->button_stop, !stop);
- setEnabled(dialog_->browser, !stop);
- setEnabled(dialog_->input, !stop);
-}