2001-07-13 11:50:39 +00:00
|
|
|
/**
|
|
|
|
* \file FormSpellchecker.C
|
|
|
|
* Copyright 2001 The LyX Team.
|
|
|
|
* See the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Edwin Leuven
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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)
|
|
|
|
: base_class(c, _("LyX: Spellchecker")), clickline_(-1)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void FormSpellchecker::build()
|
|
|
|
{
|
|
|
|
dialog_.reset(build_spellchecker());
|
|
|
|
|
|
|
|
// Manage the buttons
|
|
|
|
bc().setCancel(dialog_->done);
|
|
|
|
bc().addReadOnly(dialog_->replace);
|
|
|
|
bc().addReadOnly(dialog_->accept);
|
|
|
|
bc().addReadOnly(dialog_->insert);
|
|
|
|
bc().addReadOnly(dialog_->ignore);
|
|
|
|
bc().addReadOnly(dialog_->start);
|
|
|
|
bc().addReadOnly(dialog_->stop);
|
2001-07-17 09:00:17 +00:00
|
|
|
bc().addReadOnly(dialog_->browser);
|
2001-07-13 11:50:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FormSpellchecker::update()
|
|
|
|
{
|
|
|
|
string 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);
|
|
|
|
}
|
|
|
|
|
2001-07-17 09:00:17 +00:00
|
|
|
void FormSpellchecker::hide()
|
|
|
|
{
|
|
|
|
clickline_ = -1;
|
|
|
|
|
|
|
|
if (form() && form()->visible)
|
|
|
|
fl_hide_form(form());
|
|
|
|
}
|
2001-07-13 11:50:39 +00:00
|
|
|
|
|
|
|
ButtonPolicy::SMInput FormSpellchecker::input(FL_OBJECT * obj, long)
|
|
|
|
{
|
|
|
|
if (obj == dialog_->replace) {
|
|
|
|
string tmp = fl_get_input(dialog_->input);
|
|
|
|
controller().replace(tmp);
|
|
|
|
} else if (obj == dialog_->start) {
|
|
|
|
controller().check();
|
2001-07-17 09:00:17 +00:00
|
|
|
stop(false);
|
|
|
|
} else if (obj == dialog_->stop) {
|
|
|
|
controller().stop();
|
|
|
|
stop(true);
|
2001-07-13 11:50:39 +00:00
|
|
|
} else if (obj == dialog_->ignore) {
|
|
|
|
controller().check();
|
|
|
|
} else if (obj == dialog_->accept) {
|
|
|
|
controller().ignoreAll();
|
|
|
|
} else if (obj == dialog_->insert) {
|
|
|
|
controller().insert();
|
|
|
|
} else if (obj == dialog_->options) {
|
|
|
|
controller().options();
|
|
|
|
} else if (obj == dialog_->browser) {
|
|
|
|
int sel = fl_get_browser(dialog_->browser);
|
|
|
|
if (clickline_==sel) {
|
|
|
|
string tmp = fl_get_input(dialog_->input);
|
|
|
|
controller().replace(tmp);
|
|
|
|
}
|
|
|
|
clickline_ = sel;
|
|
|
|
string tmp = fl_get_browser_line(dialog_->browser, clickline_);
|
|
|
|
fl_set_input(dialog_->input, tmp.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2001-07-17 09:00:17 +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
|
|
|
}
|
|
|
|
break;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
setEnabled(dialog_->start, stop);
|
|
|
|
setEnabled(dialog_->replace, !stop);
|
|
|
|
setEnabled(dialog_->ignore, !stop);
|
|
|
|
setEnabled(dialog_->accept, !stop);
|
|
|
|
setEnabled(dialog_->insert, !stop);
|
|
|
|
setEnabled(dialog_->stop, !stop);
|
|
|
|
setEnabled(dialog_->browser, !stop);
|
|
|
|
setEnabled(dialog_->input, !stop);
|
|
|
|
}
|