2001-07-13 11:50:39 +00:00
|
|
|
/**
|
|
|
|
* \file FormSpellchecker.C
|
|
|
|
* Copyright 2001 The LyX Team.
|
|
|
|
* See the file COPYING.
|
|
|
|
*
|
2002-03-11 17:00:41 +00:00
|
|
|
* \author Edwin Leuven, leuven@fee.uva.nl
|
2001-07-13 11:50:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "xformsBC.h"
|
2001-07-17 09:00:17 +00:00
|
|
|
#include "xforms_helpers.h"
|
2001-07-13 11:50:39 +00:00
|
|
|
#include "ControlSpellchecker.h"
|
|
|
|
#include "FormSpellchecker.h"
|
|
|
|
#include "form_spellchecker.h"
|
|
|
|
|
|
|
|
typedef FormCB<ControlSpellchecker, FormDB<FD_form_spellchecker> > base_class;
|
|
|
|
|
|
|
|
FormSpellchecker::FormSpellchecker(ControlSpellchecker & c)
|
2002-01-15 15:31:19 +00:00
|
|
|
: base_class(c, _("LyX: Spellchecker"), false)
|
2001-07-13 11:50:39 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void FormSpellchecker::build()
|
|
|
|
{
|
|
|
|
dialog_.reset(build_spellchecker());
|
|
|
|
|
2001-09-18 12:22:08 +00:00
|
|
|
fl_set_slider_bounds(dialog_->slider, 0.0, 100.0);
|
|
|
|
fl_set_slider_step(dialog_->slider, 1.0);
|
|
|
|
|
2002-01-15 15:31:19 +00:00
|
|
|
fl_set_browser_dblclick_callback(dialog_->browser,
|
|
|
|
C_FormBaseInputCB, 2);
|
|
|
|
|
2002-03-11 18:24:31 +00:00
|
|
|
fl_set_input_return(dialog_->input, FL_RETURN_CHANGED);
|
|
|
|
setPrehandler(dialog_->input);
|
|
|
|
|
2001-07-13 11:50:39 +00:00
|
|
|
// Manage the buttons
|
2002-03-12 14:11:15 +00:00
|
|
|
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);
|
2001-07-17 09:00:17 +00:00
|
|
|
bc().addReadOnly(dialog_->browser);
|
2001-07-13 11:50:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FormSpellchecker::update()
|
|
|
|
{
|
2002-01-15 15:31:19 +00:00
|
|
|
string const w;
|
2001-07-13 11:50:39 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2002-01-15 15:31:19 +00:00
|
|
|
ButtonPolicy::SMInput FormSpellchecker::input(FL_OBJECT * obj, long val)
|
2001-07-13 11:50:39 +00:00
|
|
|
{
|
2002-03-12 14:11:15 +00:00
|
|
|
if (obj == dialog_->button_replace) {
|
2002-01-15 15:31:19 +00:00
|
|
|
string const tmp = getStringFromInput(dialog_->input);
|
2001-07-13 11:50:39 +00:00
|
|
|
controller().replace(tmp);
|
2002-01-15 15:31:19 +00:00
|
|
|
|
2002-03-12 14:11:15 +00:00
|
|
|
} else if (obj == dialog_->button_start) {
|
2001-07-13 11:50:39 +00:00
|
|
|
controller().check();
|
2001-07-17 09:00:17 +00:00
|
|
|
stop(false);
|
2002-01-15 15:31:19 +00:00
|
|
|
|
2002-03-12 14:11:15 +00:00
|
|
|
} else if (obj == dialog_->button_stop) {
|
2001-07-17 09:00:17 +00:00
|
|
|
controller().stop();
|
|
|
|
stop(true);
|
2002-01-15 15:31:19 +00:00
|
|
|
|
2002-03-12 14:11:15 +00:00
|
|
|
} else if (obj == dialog_->button_ignore) {
|
2001-07-13 11:50:39 +00:00
|
|
|
controller().check();
|
2002-01-15 15:31:19 +00:00
|
|
|
|
2002-03-12 14:11:15 +00:00
|
|
|
} else if (obj == dialog_->button_accept) {
|
2001-07-13 11:50:39 +00:00
|
|
|
controller().ignoreAll();
|
2002-01-15 15:31:19 +00:00
|
|
|
|
2002-03-12 14:11:15 +00:00
|
|
|
} else if (obj == dialog_->button_insert) {
|
2001-07-13 11:50:39 +00:00
|
|
|
controller().insert();
|
2002-01-15 15:31:19 +00:00
|
|
|
|
2002-03-12 14:11:15 +00:00
|
|
|
} else if (obj == dialog_->button_options) {
|
2001-07-13 11:50:39 +00:00
|
|
|
controller().options();
|
2002-01-15 15:31:19 +00:00
|
|
|
|
2001-07-13 11:50:39 +00:00
|
|
|
} else if (obj == dialog_->browser) {
|
2002-01-15 15:31:19 +00:00
|
|
|
int const line = fl_get_browser(dialog_->browser);
|
|
|
|
string const tmp =
|
|
|
|
getStringFromBrowser(dialog_->browser, line);
|
|
|
|
if (tmp.empty())
|
2002-01-08 10:05:53 +00:00
|
|
|
return ButtonPolicy::SMI_NOOP;
|
|
|
|
|
2002-01-15 15:31:19 +00:00
|
|
|
if (val != 2) {
|
|
|
|
// single-click
|
|
|
|
// place the chosen string in the input as feedback
|
|
|
|
fl_set_input(dialog_->input, tmp.c_str());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// double-click
|
2001-07-13 11:50:39 +00:00
|
|
|
controller().replace(tmp);
|
2002-01-15 15:31:19 +00:00
|
|
|
// reset the browser so that the following
|
|
|
|
// single-click callback doesn't do anything
|
|
|
|
fl_deselect_browser_line(dialog_->browser, line);
|
2001-07-13 11:50:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ButtonPolicy::SMI_VALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormSpellchecker::partialUpdate(int id)
|
|
|
|
{
|
2001-07-17 09:00:17 +00:00
|
|
|
switch (id) {
|
|
|
|
case 0:
|
|
|
|
// set progress bar
|
2001-07-13 11:50:39 +00:00
|
|
|
fl_set_slider_value(dialog_->slider,
|
|
|
|
controller().getProgress());
|
2001-07-17 09:00:17 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
// set suggestions
|
2001-07-13 11:50:39 +00:00
|
|
|
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);
|
2002-02-16 15:59:55 +00:00
|
|
|
while (!(w = controller().getSuggestion()).empty()) {
|
2001-07-13 11:50:39 +00:00
|
|
|
fl_add_browser_line(dialog_->browser, w.c_str());
|
|
|
|
}
|
2001-07-17 09:00:17 +00:00
|
|
|
}
|
2002-03-21 16:59:12 +00:00
|
|
|
break;
|
2001-07-17 09:00:17 +00:00
|
|
|
case 2:
|
|
|
|
// show exit message
|
2001-07-13 11:50:39 +00:00
|
|
|
fl_show_messages(controller().getMessage().c_str());
|
2001-07-17 09:00:17 +00:00
|
|
|
hide();
|
2001-07-13 11:50:39 +00:00
|
|
|
}
|
2001-07-17 09:00:17 +00:00
|
|
|
|
2001-07-13 11:50:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FormSpellchecker::showMessage(const char * msg)
|
|
|
|
{
|
|
|
|
fl_show_message(msg, "", "");
|
|
|
|
}
|
|
|
|
|
2001-07-17 09:00:17 +00:00
|
|
|
void FormSpellchecker::stop(bool stop)
|
|
|
|
{
|
2002-03-12 14:11:15 +00:00
|
|
|
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);
|
2001-07-17 09:00:17 +00:00
|
|
|
setEnabled(dialog_->browser, !stop);
|
|
|
|
setEnabled(dialog_->input, !stop);
|
|
|
|
}
|