Implemented spellchecking inside insets. Small fixes. Baruchs fix.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2265 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Vigna 2001-07-17 15:39:12 +00:00
parent 30f11bef59
commit 2c5ab94d01
18 changed files with 277 additions and 24 deletions

View File

@ -384,24 +384,25 @@ void BufferView::replaceWord(string const & replacestring)
{ {
if (!available()) return; if (!available()) return;
LyXText * tt = getLyXText();
hideCursor(); hideCursor();
update(text, BufferView::SELECT|BufferView::FITCUR); update(tt, BufferView::SELECT|BufferView::FITCUR);
/* clear the selection (if there is any) */ /* clear the selection (if there is any) */
toggleSelection(false); toggleSelection(false);
update(text, BufferView::SELECT|BufferView::FITCUR); update(tt, BufferView::SELECT|BufferView::FITCUR);
/* clear the selection (if there is any) */ /* clear the selection (if there is any) */
toggleSelection(false); toggleSelection(false);
text->replaceSelectionWithString(this, replacestring); tt->replaceSelectionWithString(this, replacestring);
text->setSelectionOverString(this, replacestring); tt->setSelectionOverString(this, replacestring);
// Go back so that replacement string is also spellchecked // Go back so that replacement string is also spellchecked
for (string::size_type i = 0; i < replacestring.length() + 1; ++i) { for (string::size_type i = 0; i < replacestring.length() + 1; ++i) {
text->cursorLeft(this); tt->cursorLeft(this);
} }
update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); update(tt, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
} }
// End of spellchecker stuff // End of spellchecker stuff

View File

@ -1266,8 +1266,11 @@ void BufferView::Pimpl::hideCursor()
void BufferView::Pimpl::toggleSelection(bool b) void BufferView::Pimpl::toggleSelection(bool b)
{ {
if (screen_.get()) if (screen_.get()) {
if (bv_->theLockingInset())
bv_->theLockingInset()->toggleSelection(bv_, b);
screen_->toggleSelection(bv_->text, bv_, b); screen_->toggleSelection(bv_->text, bv_, b);
}
} }

View File

@ -1,3 +1,14 @@
2001-07-17 Juergen Vigna <jug@sad.it>
* BufferView_pimpl.C (toggleSelection): adapted too.
* text.C (selectNextWord): adapted for use with insets.
(selectSelectedWord): ditto
2001-07-17 Juergen Vigna <jug@sad.it>
* sp_spell.C (PSpell): fix initialitation order.
2001-07-17 Lars Gullik Bjønnes <larsbj@birdstep.com> 2001-07-17 Lars Gullik Bjønnes <larsbj@birdstep.com>
* paragraph.C: spacing * paragraph.C: spacing

View File

@ -1,3 +1,7 @@
2001-07-16 Baruch Even <baruch@lyx.org>
* ControlVCLog.h: Added Lsstream.h to includes.
2001-07-17 Angus Leeming <a.leeming@ic.ac.uk> 2001-07-17 Angus Leeming <a.leeming@ic.ac.uk>
* ControlSpellchecker.[Ch]: remove d-tor. * ControlSpellchecker.[Ch]: remove d-tor.

View File

@ -21,6 +21,7 @@
#endif #endif
#include "ControlDialogs.h" #include "ControlDialogs.h"
#include "Lsstream.h"
/** /**
* A controller for the Version Control log viewer. * A controller for the Version Control log viewer.

View File

@ -1,3 +1,13 @@
2001-07-17 Juergen Vigna <jug@sad.it>
* various files: implemented the below functions.
* inset.h: added functions
- virtual string selectNextWord(BufferView *, float & value) const;
- virtual void selectSelectedWord(BufferView *) { return; }
- virtual void toggleSelection(BufferView *, bool /*kill_selection*/)
needed for spellchecking correctly!
2001-07-16 Lars Gullik Bjønnes <larsbj@birdstep.com> 2001-07-16 Lars Gullik Bjønnes <larsbj@birdstep.com>
* insetert.C (latex): write out all paragraphs. * insetert.C (latex): write out all paragraphs.

View File

@ -258,3 +258,11 @@ LyXCursor const & Inset::cursor(BufferView * bv) const
{ {
return bv->text->cursor; return bv->text->cursor;
} }
string UpdatableInset::selectNextWord(BufferView *bv, float & value) const
{
// we have to unlock ourself in this function by default!
bv->unlockInset(const_cast<UpdatableInset *>(this));
value = 0;
return string();
}

View File

@ -414,6 +414,14 @@ public:
/// ///
virtual bool collapsed() const { return false; } virtual bool collapsed() const { return false; }
virtual void collapsed(BufferView *, bool) {} virtual void collapsed(BufferView *, bool) {}
///
// needed for spellchecking text
///
virtual string selectNextWord(BufferView *, float & value) const;
virtual void selectSelectedWord(BufferView *) { return; }
virtual void toggleSelection(BufferView *, bool /*kill_selection*/) {
return;
}
protected: protected:
/// ///

View File

@ -160,6 +160,16 @@ public:
bool isCollapsable() const { return true; } bool isCollapsable() const { return true; }
bool collapsed() const { return collapsed_; } bool collapsed() const { return collapsed_; }
void collapsed(BufferView *, bool); void collapsed(BufferView *, bool);
///
string selectNextWord(BufferView * bv, float & value) const {
return inset.selectNextWord(bv, value);
}
void selectSelectedWord(BufferView * bv) {
return inset.selectSelectedWord(bv);
}
void toggleSelection(BufferView * bv, bool kill_selection) {
return inset.toggleSelection(bv, kill_selection);
}
protected: protected:
/// ///

View File

@ -1173,9 +1173,12 @@ bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv,
} }
void InsetTabular::getCursorPos(BufferView *, void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
int & x, int & y) const
{ {
if (the_locking_inset) {
the_locking_inset->getCursorPos(bv, x, y);
return;
}
x = cursor_.x() - top_x; x = cursor_.x() - top_x;
y = cursor_.y(); y = cursor_.y();
} }
@ -2431,3 +2434,64 @@ Inset * InsetTabular::getInsetFromID(int id_arg) const
} }
return 0; return 0;
} }
string InsetTabular::selectNextWord(BufferView * bv, float & value) const
{
if (the_locking_inset) {
string str;
str = the_locking_inset->selectNextWord(bv, value);
if (!str.empty())
return str;
}
if (tabular->IsLastCell(actcell)) {
bv->unlockInset(const_cast<InsetTabular *>(this));
return string();
}
// otherwise we have to lock the next inset and ask for it's selecttion
UpdatableInset * inset =
static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
inset->edit(bv, 0, 0, 0);
string str = selectNextWordInt(bv, value);
if (!str.empty())
resetPos(bv);
return str;
}
string InsetTabular::selectNextWordInt(BufferView * bv, float & value) const
{
if (the_locking_inset) {
string str;
str = the_locking_inset->selectNextWord(bv, value);
if (!str.empty())
return str;
}
if (tabular->IsLastCell(actcell)) {
bv->unlockInset(const_cast<InsetTabular *>(this));
return string();
}
// otherwise we have to lock the next inset and ask for it's selecttion
UpdatableInset * inset =
static_cast<UpdatableInset*>(tabular->GetCellInset(++actcell));
inset->edit(bv, 0, 0, 0);
return selectNextWordInt(bv, value);
}
void InsetTabular::selectSelectedWord(BufferView * bv)
{
if (the_locking_inset) {
the_locking_inset->selectSelectedWord(bv);
return;
}
return;
}
void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection)
{
if (the_locking_inset) {
the_locking_inset->toggleSelection(bv, kill_selection);
}
}

View File

@ -209,6 +209,10 @@ public:
Paragraph * firstParagraph() const; Paragraph * firstParagraph() const;
/// ///
LyXCursor const & cursor(BufferView *) const; LyXCursor const & cursor(BufferView *) const;
///
string selectNextWord(BufferView *, float & value) const;
void selectSelectedWord(BufferView *);
void toggleSelection(BufferView *, bool kill_selection);
// //
// Public structures and variables // Public structures and variables
@ -284,6 +288,8 @@ private:
bool isRightToLeft(BufferView *); bool isRightToLeft(BufferView *);
/// ///
void getSelection(int & scol, int & ecol, int & srow, int & erow) const; void getSelection(int & scol, int & ecol, int & srow, int & erow) const;
///
string selectNextWordInt(BufferView *, float & value) const;
// //
// Private structures and variables // Private structures and variables

View File

@ -1267,6 +1267,10 @@ int InsetText::beginningOfMainBody(Buffer const * buf, Paragraph * p) const
void InsetText::getCursorPos(BufferView * bv, void InsetText::getCursorPos(BufferView * bv,
int & x, int & y) const int & x, int & y) const
{ {
if (the_locking_inset) {
the_locking_inset->getCursorPos(bv, x, y);
return;
}
x = cx(bv); x = cx(bv);
y = cy(bv); y = cy(bv);
} }
@ -1960,3 +1964,76 @@ Inset * InsetText::getInsetFromID(int id_arg) const
} }
return 0; return 0;
} }
string InsetText::selectNextWord(BufferView * bv, float & value) const
{
bool clear = false;
string str;
if (!lt) {
lt = getLyXText(bv);
clear = true;
}
if (the_locking_inset) {
str = the_locking_inset->selectNextWord(bv, value);
if (!str.empty()) {
value += cy(bv);
if (clear)
lt = 0;
return str;
}
#warning Dekel please have a look on this one RTL? (Jug)
// we have to go on checking so move cusor to the right
lt->cursor.pos(lt->cursor.pos() + 1);
}
str = lt->selectNextWord(bv, value);
if (str.empty())
bv->unlockInset(const_cast<InsetText *>(this));
else
value = cy(bv);
if (clear)
lt = 0;
return str;
}
void InsetText::selectSelectedWord(BufferView * bv)
{
if (the_locking_inset) {
the_locking_inset->selectSelectedWord(bv);
return;
}
getLyXText(bv)->selectSelectedWord(bv);
updateLocal(bv, SELECTION, false);
}
void InsetText::toggleSelection(BufferView * bv, bool kill_selection)
{
if (the_locking_inset) {
the_locking_inset->toggleSelection(bv, kill_selection);
}
bool clear = false;
if (!lt) {
lt = getLyXText(bv);
clear = true;
}
int x = top_x + TEXT_TO_INSET_OFFSET;
int y = 0;
Row * row = lt->getRowNearY(y);
int y_offset = top_baseline - row->ascent_of_text();
y = y_offset;
while ((row != 0) && ((y+row->height()) <= 0)) {
y += row->height();
row = row->next();
}
if (y_offset < 0)
y_offset = y;
bv->screen()->toggleSelection(lt, bv, kill_selection, y_offset, x);
if (clear)
lt = 0;
}

View File

@ -218,6 +218,10 @@ public:
/// ///
void paragraph(Paragraph *); void paragraph(Paragraph *);
/// ///
string selectNextWord(BufferView *, float & value) const;
void selectSelectedWord(BufferView *);
void toggleSelection(BufferView *, bool kill_selection);
///
mutable int need_update; mutable int need_update;
protected: protected:

View File

@ -11,8 +11,8 @@ class ISpell : public SpellBase
public: public:
enum ActualSpellChecker { enum ActualSpellChecker {
ASC_ISPELL, ASC_ISPELL,
ASC_ASPELL ASC_ASPELL
}; };
ISpell(); ISpell();

View File

@ -74,12 +74,12 @@ extern void sigchldchecker(pid_t pid, int * status);
PSpell::PSpell() PSpell::PSpell()
: els(0), sc(0), spell_error_object(0), flag(ISP_UNKNOWN) : sc(0), els(0), spell_error_object(0), flag(ISP_UNKNOWN)
{ {
} }
PSpell::PSpell(BufferParams const & params, string const & lang) PSpell::PSpell(BufferParams const & params, string const & lang)
: els(0), sc(0), spell_error_object(0), flag(ISP_UNKNOWN) : sc(0), els(0), spell_error_object(0), flag(ISP_UNKNOWN)
{ {
initialize(params, lang); initialize(params, lang);
} }

View File

@ -1730,6 +1730,7 @@ int LyXTabular::GetLastCellBelow(int cell) const
int LyXTabular::GetCellNumber(int row, int column) const int LyXTabular::GetCellNumber(int row, int column) const
{ {
#if 1
if (column >= columns_) if (column >= columns_)
column = columns_ - 1; column = columns_ - 1;
else if (column < 0) else if (column < 0)
@ -1738,7 +1739,9 @@ int LyXTabular::GetCellNumber(int row, int column) const
row = rows_ - 1; row = rows_ - 1;
else if (row < 0) else if (row < 0)
row = 0; row = 0;
#else
lyx::Assert(column < 0 || column >= columns_ || row < 0 || row >= rows_);
#endif
return cell_info[row][column].cellno; return cell_info[row][column].cellno;
} }
@ -2534,11 +2537,6 @@ InsetText * LyXTabular::GetCellInset(int cell) const
InsetText * LyXTabular::GetCellInset(int row, int column) const InsetText * LyXTabular::GetCellInset(int row, int column) const
{ {
#ifdef WITH_WARNINGS
#warning Juergen, should we check whether the row/column values are correct?
// If we do not need to do that, the tests in GetCellNumber should be
// changed to asserts.
#endif
cur_cell = GetCellNumber(row, column); cur_cell = GetCellNumber(row, column);
return & cell_info[row][column].inset; return & cell_info[row][column].inset;
} }

View File

@ -2224,6 +2224,22 @@ bool LyXText::selectWordWhenUnderCursor(BufferView * bview)
string const LyXText::selectNextWord(BufferView * bview, string const LyXText::selectNextWord(BufferView * bview,
float & value) const float & value) const
{ {
if (the_locking_inset) {
string str = the_locking_inset->selectNextWord(bview, value);
if (!str.empty()) {
value += float(cursor.y())/float(height);
return str;
}
#warning Dekel please have a look on this one RTL? (Jug)
// we have to go on checking so move cusor to the right
if (cursor.pos() == cursor.par()->size()) {
if (!cursor.par()->next())
return str;
cursor.par(cursor.par()->next());
cursor.pos(0);
} else
cursor.pos(cursor.pos() + 1);
}
Paragraph * tmppar = cursor.par(); Paragraph * tmppar = cursor.par();
// If this is not the very first word, skip rest of // If this is not the very first word, skip rest of
@ -2237,20 +2253,33 @@ string const LyXText::selectNextWord(BufferView * bview,
// Now, skip until we have real text (will jump paragraphs) // Now, skip until we have real text (will jump paragraphs)
while ((cursor.par()->size() > cursor.pos() while ((cursor.par()->size() > cursor.pos()
&& (!cursor.par()->isLetter(cursor.pos()) && (!cursor.par()->isLetter(cursor.pos())
#ifndef NO_LATEX #ifndef NO_LATEX
|| cursor.par()->getFont(bview->buffer()->params, cursor.pos()) || cursor.par()->getFont(bview->buffer()->params, cursor.pos())
.latex() == LyXFont::ON .latex() == LyXFont::ON
#endif #endif
)) )
&& (!cursor.par()->isInset(cursor.pos()) ||
!cursor.par()->getInset(cursor.pos())->isTextInset()))
|| (cursor.par()->size() == cursor.pos() || (cursor.par()->size() == cursor.pos()
&& cursor.par()->next())){ && cursor.par()->next()))
{
if (cursor.pos() == cursor.par()->size()) { if (cursor.pos() == cursor.par()->size()) {
cursor.par(cursor.par()->next()); cursor.par(cursor.par()->next());
cursor.pos(0); cursor.pos(0);
} else } else
cursor.pos(cursor.pos() + 1); cursor.pos(cursor.pos() + 1);
} }
// now check if we hit an inset so it has to be a inset containing text!
if (cursor.pos() < cursor.par()->size() &&
cursor.par()->isInset(cursor.pos()))
{
// lock the inset!
cursor.par()->getInset(cursor.pos())->edit(bview, 0, 0, 0);
// now call us again to do the above trick
return selectNextWord(bview, value);
}
// Update the value if we changed paragraphs // Update the value if we changed paragraphs
if (cursor.par() != tmppar){ if (cursor.par() != tmppar){
@ -2290,6 +2319,10 @@ string const LyXText::selectNextWord(BufferView * bview,
// This one is also only for the spellchecker // This one is also only for the spellchecker
void LyXText::selectSelectedWord(BufferView * bview) void LyXText::selectSelectedWord(BufferView * bview)
{ {
if (the_locking_inset) {
the_locking_inset->selectSelectedWord(bview);
return;
}
// move cursor to the beginning // move cursor to the beginning
setCursor(bview, selection.cursor.par(), selection.cursor.pos()); setCursor(bview, selection.cursor.par(), selection.cursor.pos());

View File

@ -2493,12 +2493,27 @@ void LyXText::status(BufferView * bview, LyXText::text_status st) const
} }
} }
#else #else
#warning Please tell what the intention is here. #warning Please tell what the intention is here. (Lgb)
// The above does not make any sense, I changed it to what is here, // The above does not make any sense, I changed it to what is here,
// but it still does not make much sense. (Lgb) // but it still does not make much sense. (Lgb)
#warning Sure have a look now! (Jug)
// well as much as I know && binds more then || so the above and the
// below are identical (this for your known use of parentesis!)
// Now some explanation:
// We should only go up with refreshing code so this means that if
// we have a MORE refresh we should never set it to LITTLE if we still
// didn't handle it (and then it will be UNCHANGED. Now as long as
// we stay inside one LyXText this may work but we need to tell the
// outermost LyXText that it should REALLY draw us if there is some
// change in a Inset::LyXText. So you see that when we are inside a
// inset's LyXText we give the LITTLE to the outermost LyXText to
// tell'em that it should redraw the actual row (where the inset
// resides! Capito?!
if ((status_ != NEED_MORE_REFRESH) if ((status_ != NEED_MORE_REFRESH)
|| (status_ == NEED_MORE_REFRESH || (status_ == NEED_MORE_REFRESH
&& st != NEED_VERY_LITTLE_REFRESH)) { && st != NEED_VERY_LITTLE_REFRESH))
{
status_ = st; status_ = st;
if (inset_owner && st != UNCHANGED) { if (inset_owner && st != UNCHANGED) {
bview->text->status(bview, NEED_VERY_LITTLE_REFRESH); bview->text->status(bview, NEED_VERY_LITTLE_REFRESH);