*
* \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 "FormSpellchecker.h"
+#include "ControlSpellchecker.h"
+#include "forms/form_spellchecker.h"
#include "Tooltips.h"
-#include "xformsBC.h"
#include "xforms_helpers.h"
-#include "ControlSpellchecker.h"
-#include "FormSpellchecker.h"
-#include "forms/form_spellchecker.h"
-#include "support/lstrings.h"
+#include "xformsBC.h"
-#include FORMS_H_LOCATION
+#include "support/tostr.h"
+
+#include "lyx_forms.h"
-typedef FormCB<ControlSpellchecker, FormDB<FD_spellchecker> > base_class;
+using std::string;
+
+
+typedef FormCB<ControlSpellchecker, FormDB<FD_spellchecker> > base_class;
FormSpellchecker::FormSpellchecker()
- : base_class(_("Spellchecker"))
+ : base_class(_("Spell-check Document"))
{}
dialog_.reset(build_spellchecker(this));
// Manage the buttons
- bc().setCancel(dialog_->button_close);
+ bcview().setCancel(dialog_->button_close);
// disable for read-only documents
- bc().addReadOnly(dialog_->button_replace);
+ bcview().addReadOnly(dialog_->button_replace);
// trigger an input event for cut&paste with middle mouse button.
setPrehandler(dialog_->input_replacement);
// set up the tooltips
string str = _("Type replacement for unknown word "
- " or select from suggestions.");
+ "or select from suggestions.");
tooltips().init(dialog_->input_replacement, str);
str = _("List of replacement suggestions from dictionary.");
tooltips().init(dialog_->browser_suggestions, str);
- str = _("Start the spellingchecker.");
- tooltips().init(dialog_->button_start, 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.");
}
-void FormSpellchecker::update()
+void FormSpellchecker::partialUpdate(int s)
{
- // clear input fields
- fl_set_input(dialog_->input_replacement, "");
- fl_set_object_label(dialog_->text_unknown, "");
- fl_clear_browser(dialog_->browser_suggestions);
+ ControlSpellchecker::State const state =
+ static_cast<ControlSpellchecker::State>(s);
- // reset dialog and buttons into start condition
- input(0, 0);
+ switch (state) {
- // reset slider to zero count
- fl_set_slider_value(dialog_->slider_progress, 0.0);
- fl_set_object_label(dialog_->slider_progress, "0 %");
+ 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 * ob, long ob_value)
{
- if (!ob || ob == dialog_->button_start) {
- static bool running = false;
-
- // update running status of spellingchecker
- running = !running && ob == dialog_->button_start;
-
- // modify text of Start/Stop button according to running status
- string const labeltext = running ? _("Stop") : _("Start");
- fl_set_object_label(dialog_->button_start, labeltext.c_str());
- fl_set_button_shortcut(dialog_->button_start, "#S", 1);
- fl_show_object(dialog_->button_start);
-
- // adjust tooltips to modified Start/Stop button
- string const str = (running ? _("Stop the spellingchecker.") :
- _("Start the spellingchecker."));
- tooltips().init(dialog_->button_start, str);
-
- // enable buttons according to running status
- setEnabled(dialog_->button_replace, running);
- setEnabled(dialog_->button_ignore, running);
- setEnabled(dialog_->button_accept, running);
- setEnabled(dialog_->button_add, running);
- setEnabled(dialog_->browser_suggestions, running);
- setEnabled(dialog_->input_replacement, running);
-
- // call controller if Start/Stop button is pressed
- if (ob) {
- if (running)
- controller().check();
- else
- controller().stop();
- }
-
- } else if (ob == dialog_->button_replace) {
+ if (ob == dialog_->button_replace) {
string const tmp = getString(dialog_->input_replacement);
controller().replace(tmp);
}
}
- // update slider with word count and progress
- double const wordcount = controller().getCount();
- if (wordcount > 0.0) {
- int const progress = controller().getProgress();
- double const total = 100.0 * wordcount / 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,
- (tostr(progress) + " %").c_str());
- }
-
return ButtonPolicy::SMI_VALID;
}
-
-
-void FormSpellchecker::partialUpdate(int id)
-{
- switch (id) {
- case 1: // 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());
- }
- }
- break;
- case 2: // end of spell checking
-
- // reset dialog and buttons into start condition
- input(0, 0);
-
- // set slider 'finished' status
- fl_set_slider_bounds(dialog_->slider_progress, 0.0, controller().getCount());
- fl_set_slider_value(dialog_->slider_progress, controller().getCount());
- fl_set_object_label(dialog_->slider_progress, "100 %");
-
- break;
- }
-}