From 2c5ab94d010ed837a10eadade1a1bd6299a3d5d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Vigna?= Date: Tue, 17 Jul 2001 15:39:12 +0000 Subject: [PATCH] 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 --- src/BufferView2.C | 13 ++-- src/BufferView_pimpl.C | 5 +- src/ChangeLog | 11 ++++ src/frontends/controllers/ChangeLog | 4 ++ src/frontends/controllers/ControlVCLog.h | 1 + src/insets/ChangeLog | 10 +++ src/insets/inset.C | 8 +++ src/insets/inset.h | 8 +++ src/insets/insetcollapsable.h | 10 +++ src/insets/insettabular.C | 68 ++++++++++++++++++++- src/insets/insettabular.h | 6 ++ src/insets/insettext.C | 77 ++++++++++++++++++++++++ src/insets/insettext.h | 4 ++ src/sp_ispell.h | 4 +- src/sp_spell.C | 4 +- src/tabular.C | 10 ++- src/text.C | 39 +++++++++++- src/text2.C | 19 +++++- 18 files changed, 277 insertions(+), 24 deletions(-) diff --git a/src/BufferView2.C b/src/BufferView2.C index c1ccb90099..2da94d1b35 100644 --- a/src/BufferView2.C +++ b/src/BufferView2.C @@ -384,24 +384,25 @@ void BufferView::replaceWord(string const & replacestring) { if (!available()) return; + LyXText * tt = getLyXText(); hideCursor(); - update(text, BufferView::SELECT|BufferView::FITCUR); + update(tt, BufferView::SELECT|BufferView::FITCUR); /* clear the selection (if there is any) */ toggleSelection(false); - update(text, BufferView::SELECT|BufferView::FITCUR); + update(tt, BufferView::SELECT|BufferView::FITCUR); /* clear the selection (if there is any) */ 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 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 diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 45ec862af5..e56cc687f0 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -1266,8 +1266,11 @@ void BufferView::Pimpl::hideCursor() 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); + } } diff --git a/src/ChangeLog b/src/ChangeLog index af5cef522d..f88ed69891 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,14 @@ +2001-07-17 Juergen Vigna + + * BufferView_pimpl.C (toggleSelection): adapted too. + + * text.C (selectNextWord): adapted for use with insets. + (selectSelectedWord): ditto + +2001-07-17 Juergen Vigna + + * sp_spell.C (PSpell): fix initialitation order. + 2001-07-17 Lars Gullik Bjønnes * paragraph.C: spacing diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 6e4301c02d..fdc7be4d3c 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,7 @@ +2001-07-16 Baruch Even + + * ControlVCLog.h: Added Lsstream.h to includes. + 2001-07-17 Angus Leeming * ControlSpellchecker.[Ch]: remove d-tor. diff --git a/src/frontends/controllers/ControlVCLog.h b/src/frontends/controllers/ControlVCLog.h index 1b6eeed7a8..b54bdadd01 100644 --- a/src/frontends/controllers/ControlVCLog.h +++ b/src/frontends/controllers/ControlVCLog.h @@ -21,6 +21,7 @@ #endif #include "ControlDialogs.h" +#include "Lsstream.h" /** * A controller for the Version Control log viewer. diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index cb8dbae101..de2e6acc3d 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,13 @@ +2001-07-17 Juergen Vigna + + * 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 * insetert.C (latex): write out all paragraphs. diff --git a/src/insets/inset.C b/src/insets/inset.C index dc8163dd03..28458d2716 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -258,3 +258,11 @@ LyXCursor const & Inset::cursor(BufferView * bv) const { 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(this)); + value = 0; + return string(); +} diff --git a/src/insets/inset.h b/src/insets/inset.h index 54ffa4720f..33b8f7ad7f 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -414,6 +414,14 @@ public: /// virtual bool collapsed() const { return false; } 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: /// diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 2bcc18955c..c93790867f 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -160,6 +160,16 @@ public: bool isCollapsable() const { return true; } bool collapsed() const { return collapsed_; } 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: /// diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 64bdd4d84d..f02b5e0556 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -1173,9 +1173,12 @@ bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, } -void InsetTabular::getCursorPos(BufferView *, - int & x, int & y) const +void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const { + if (the_locking_inset) { + the_locking_inset->getCursorPos(bv, x, y); + return; + } x = cursor_.x() - top_x; y = cursor_.y(); } @@ -2431,3 +2434,64 @@ Inset * InsetTabular::getInsetFromID(int id_arg) const } 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(this)); + return string(); + } + + // otherwise we have to lock the next inset and ask for it's selecttion + UpdatableInset * inset = + static_cast(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(this)); + return string(); + } + + // otherwise we have to lock the next inset and ask for it's selecttion + UpdatableInset * inset = + static_cast(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); + } +} diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 5d5af999f4..10ec2bf72a 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -209,6 +209,10 @@ public: Paragraph * firstParagraph() 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 @@ -284,6 +288,8 @@ private: bool isRightToLeft(BufferView *); /// void getSelection(int & scol, int & ecol, int & srow, int & erow) const; + /// + string selectNextWordInt(BufferView *, float & value) const; // // Private structures and variables diff --git a/src/insets/insettext.C b/src/insets/insettext.C index bbb7aa4cf0..a17efbd2ae 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -1267,6 +1267,10 @@ int InsetText::beginningOfMainBody(Buffer const * buf, Paragraph * p) const void InsetText::getCursorPos(BufferView * bv, int & x, int & y) const { + if (the_locking_inset) { + the_locking_inset->getCursorPos(bv, x, y); + return; + } x = cx(bv); y = cy(bv); } @@ -1960,3 +1964,76 @@ Inset * InsetText::getInsetFromID(int id_arg) const } 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(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; +} diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 682ff48d1e..1c6a448b6e 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -218,6 +218,10 @@ public: /// void paragraph(Paragraph *); /// + string selectNextWord(BufferView *, float & value) const; + void selectSelectedWord(BufferView *); + void toggleSelection(BufferView *, bool kill_selection); + /// mutable int need_update; protected: diff --git a/src/sp_ispell.h b/src/sp_ispell.h index aad831cb0f..43436a0b7f 100644 --- a/src/sp_ispell.h +++ b/src/sp_ispell.h @@ -11,8 +11,8 @@ class ISpell : public SpellBase public: enum ActualSpellChecker { - ASC_ISPELL, - ASC_ASPELL + ASC_ISPELL, + ASC_ASPELL }; ISpell(); diff --git a/src/sp_spell.C b/src/sp_spell.C index 33db1f4cfa..40d54da873 100644 --- a/src/sp_spell.C +++ b/src/sp_spell.C @@ -74,12 +74,12 @@ extern void sigchldchecker(pid_t pid, int * status); 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) - : 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); } diff --git a/src/tabular.C b/src/tabular.C index 183b2f2e68..ce9179602b 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -1730,6 +1730,7 @@ int LyXTabular::GetLastCellBelow(int cell) const int LyXTabular::GetCellNumber(int row, int column) const { +#if 1 if (column >= columns_) column = columns_ - 1; else if (column < 0) @@ -1738,7 +1739,9 @@ int LyXTabular::GetCellNumber(int row, int column) const row = rows_ - 1; else if (row < 0) row = 0; - +#else + lyx::Assert(column < 0 || column >= columns_ || row < 0 || row >= rows_); +#endif return cell_info[row][column].cellno; } @@ -2534,11 +2537,6 @@ InsetText * LyXTabular::GetCellInset(int cell) 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); return & cell_info[row][column].inset; } diff --git a/src/text.C b/src/text.C index 3b21f04f20..a49c9c155a 100644 --- a/src/text.C +++ b/src/text.C @@ -2224,6 +2224,22 @@ bool LyXText::selectWordWhenUnderCursor(BufferView * bview) string const LyXText::selectNextWord(BufferView * bview, 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(); // 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) while ((cursor.par()->size() > cursor.pos() - && (!cursor.par()->isLetter(cursor.pos()) + && (!cursor.par()->isLetter(cursor.pos()) #ifndef NO_LATEX || cursor.par()->getFont(bview->buffer()->params, cursor.pos()) .latex() == LyXFont::ON #endif - )) + ) + && (!cursor.par()->isInset(cursor.pos()) || + !cursor.par()->getInset(cursor.pos())->isTextInset())) || (cursor.par()->size() == cursor.pos() - && cursor.par()->next())){ + && cursor.par()->next())) + { if (cursor.pos() == cursor.par()->size()) { cursor.par(cursor.par()->next()); cursor.pos(0); } else 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 if (cursor.par() != tmppar){ @@ -2290,6 +2319,10 @@ string const LyXText::selectNextWord(BufferView * bview, // This one is also only for the spellchecker void LyXText::selectSelectedWord(BufferView * bview) { + if (the_locking_inset) { + the_locking_inset->selectSelectedWord(bview); + return; + } // move cursor to the beginning setCursor(bview, selection.cursor.par(), selection.cursor.pos()); diff --git a/src/text2.C b/src/text2.C index c4f7064999..3c64a7ab75 100644 --- a/src/text2.C +++ b/src/text2.C @@ -2493,12 +2493,27 @@ void LyXText::status(BufferView * bview, LyXText::text_status st) const } } #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, // 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) || (status_ == NEED_MORE_REFRESH - && st != NEED_VERY_LITTLE_REFRESH)) { + && st != NEED_VERY_LITTLE_REFRESH)) + { status_ = st; if (inset_owner && st != UNCHANGED) { bview->text->status(bview, NEED_VERY_LITTLE_REFRESH);