*
* \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 "ControlSpellchecker.h"
#include "FormSpellchecker.h"
+#include "ControlSpellchecker.h"
#include "forms/form_spellchecker.h"
-#include "forms_gettext.h"
#include "Tooltips.h"
#include "xforms_helpers.h"
-#include "support/lstrings.h"
+#include "xformsBC.h"
-#include FORMS_H_LOCATION
+#include "support/tostr.h"
-typedef FormCB<ControlSpellchecker, FormDB<FD_spellchecker> > base_class;
+#include "lyx_forms.h"
+
+
+using std::string;
+typedef FormCB<ControlSpellchecker, FormDB<FD_spellchecker> > base_class;
+
FormSpellchecker::FormSpellchecker()
- : base_class(_("Spellchecker")), state_(STOPPED)
+ : 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);
tooltips().init(dialog_->browser_suggestions, str);
// Work-around xforms' bug; enable tooltips for browser widgets.
setPrehandler(dialog_->browser_suggestions);
- str = _("Start the spellingchecker.");
- tooltips().init(dialog_->button_start, str);
str = _("Replace unknown word.");
tooltips().init(dialog_->button_replace, str);
str = _("Ignore unknown word.");
}
-void FormSpellchecker::updateState(State state)
+void FormSpellchecker::partialUpdate(int s)
{
+ ControlSpellchecker::State const state =
+ static_cast<ControlSpellchecker::State>(s);
+
switch (state) {
- case READY_TO_START:
- fl_set_slider_value(dialog_->slider_progress, 0.0);
- fl_set_object_label(dialog_->slider_progress, "0 %");
- break;
- case CHECKING:
- {
+ case ControlSpellchecker::SPELL_FOUND_WORD: {
// Set suggestions.
string w = controller().getWord();
fl_set_input(dialog_->input_replacement, w.c_str());
// Fall through...
}
- case STARTED:
- {
+ case ControlSpellchecker::SPELL_PROGRESSED: {
int const progress = controller().getProgress();
if (progress == 0)
break;
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;
}
- case STOPPED:
- {
- controller().stop();
-
- double const wordcount = controller().getCount();
-
- fl_set_slider_bounds(dialog_->slider_progress, 0.0, wordcount);
- fl_set_slider_value(dialog_->slider_progress, wordcount);
- fl_set_object_label(dialog_->slider_progress, "100 %");
- break;
- }
}
-
- bool const state_change = state_ != state;
- state_ = state;
-
- if (!state_change)
- return;
-
- bool const running = (state == STARTED || state == CHECKING);
- string const label = running ? _("Stop|#S") : _("Start|#S");
-
- fl_set_object_label(dialog_->button_start, idex(label).c_str());
- fl_set_button_shortcut(dialog_->button_start, scex(label).c_str(), 1);
- fl_redraw_object(dialog_->button_start);
-
- string const tip = running ?
- _("Stop the spellingchecker.") :
- _("Start the spellingchecker.");
- tooltips().init(dialog_->button_start, tip);
-
- 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);
-}
-
-
-void FormSpellchecker::update()
-{
- // clear input fields
- fl_set_input(dialog_->input_replacement, "");
- fl_set_object_label(dialog_->text_unknown, "");
- fl_clear_browser(dialog_->browser_suggestions);
-
- // reset dialog and buttons into start condition
- updateState(READY_TO_START);
}
ButtonPolicy::SMInput FormSpellchecker::input(FL_OBJECT * ob, long ob_value)
{
- if (ob == dialog_->button_start) {
- updateState(STARTED);
- controller().check();
-
- } else if (ob == dialog_->button_replace) {
+ if (ob == dialog_->button_replace) {
string const tmp = getString(dialog_->input_replacement);
controller().replace(tmp);
return ButtonPolicy::SMI_VALID;
}
-
-
-void FormSpellchecker::partialUpdate(int id)
-{
- switch (id) {
- case 1:
- // Set suggestions.
- updateState(CHECKING);
- break;
- case 2:
- // End of spell checking.
- updateState(STOPPED);
- break;
- }
-}