]> git.lyx.org Git - features.git/commitdiff
Implemented spellchecking inside insets. Small fixes. Baruchs fix.
authorJürgen Vigna <jug@sad.it>
Tue, 17 Jul 2001 15:39:12 +0000 (15:39 +0000)
committerJürgen Vigna <jug@sad.it>
Tue, 17 Jul 2001 15:39:12 +0000 (15:39 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2265 a592a061-630c-0410-9148-cb99ea01b6c8

18 files changed:
src/BufferView2.C
src/BufferView_pimpl.C
src/ChangeLog
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlVCLog.h
src/insets/ChangeLog
src/insets/inset.C
src/insets/inset.h
src/insets/insetcollapsable.h
src/insets/insettabular.C
src/insets/insettabular.h
src/insets/insettext.C
src/insets/insettext.h
src/sp_ispell.h
src/sp_spell.C
src/tabular.C
src/text.C
src/text2.C

index c1ccb9009925591ea8d26ef9395a5d69c2a45378..2da94d1b357068697583874a94bd02cf73de28ef 100644 (file)
@@ -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
 
index 45ec862af5433f26073b680f2fd869630097f006..e56cc687f07e66cf50a32d672f425a130ef9aa12 100644 (file)
@@ -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);
+       }
 }
 
 
index af5cef522d646dcfc28ac3b9763ea83e1e616c39..f88ed698918d3e056a688121ead43c96f9becc4c 100644 (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>
 
        * paragraph.C: spacing
index 6e4301c02d951559c6524b58bafc877abc2a27fe..fdc7be4d3c25a1e8ceece594f28e65ff67bc3693 100644 (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>
 
        * ControlSpellchecker.[Ch]: remove d-tor.
index 1b6eeed7a80904473450756894137a3748ff20e0..b54bdadd01f2ef6821c1b8ae5d1d1083caa90ff5 100644 (file)
@@ -21,6 +21,7 @@
 #endif
 
 #include "ControlDialogs.h"
+#include "Lsstream.h"
 
 /**
  * A controller for the Version Control log viewer.
index cb8dbae101017888c10db45a0a54f8e34b5e302e..de2e6acc3d46c3bbc1cbd6cad20d77e394b638ff 100644 (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>
 
        * insetert.C (latex): write out all paragraphs.
index dc8163dd031d2b83a511f29b2007db5ac84d3657..28458d27160c72f48b9ded761e8d12c63c720b4c 100644 (file)
@@ -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<UpdatableInset *>(this));
+       value = 0;
+       return string();
+}
index 54ffa4720fa1551575db536bd01d65a6bb16ee65..33b8f7ad7f52b745b3c882f4d80ca07b49b06fe2 100644 (file)
@@ -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:
        ///
index 2bcc18955c0049fbd1e6bc0f4262b2fa853b4ea0..c93790867f5f413f1145c8881757aacde235e3bb 100644 (file)
@@ -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:
        ///
index 64bdd4d84d76f7cb82929847cab68dc71118be90..f02b5e0556afc5862889b1cfc80b0c2596e33909 100644 (file)
@@ -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<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);
+       }
+}
index 5d5af999f4c06ee5d951720f69d2069eb67a10c3..10ec2bf72a9fa8e00775e58f5fbc1b543889a121 100644 (file)
@@ -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
index bbb7aa4cf0528a314000a3e6381ea2cc9e448f38..a17efbd2aea1d2275169292c75f2f8e0a7f107f6 100644 (file)
@@ -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<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;
+}
index 682ff48d1e720d3279c36c00328fbc36756ab756..1c6a448b6e046bf5b16c914286308508593e658c 100644 (file)
@@ -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:
index aad831cb0f7c5fcc9a7bbdb509b6c29e60a7c557..43436a0b7fe57edaf8d7e15dfc96f0ff4e9ddbf8 100644 (file)
@@ -11,8 +11,8 @@ class ISpell : public SpellBase
   public:
 
     enum ActualSpellChecker {
-       ASC_ISPELL,
-       ASC_ASPELL
+               ASC_ISPELL,
+               ASC_ASPELL
     };
     
     ISpell();
index 33db1f4cfa1a848713618916fafb7752946bc23e..40d54da87370c73fdec641a50ee12572900ec24c 100644 (file)
@@ -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);
 }
index 183b2f2e68fd5d40a80e37b63db5784ec82c34ae..ce9179602ba15ce461bf614574eaa43b0d279418 100644 (file)
@@ -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;
 }
index 3b21f04f20fc104d03be607814ae2e5129b80ea5..a49c9c155a90b5a21bc207b03e9da0e521ba4eaa 100644 (file)
@@ -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());
        
index c4f7064999d60d46b66be39e36f646f2d36d2608..3c64a7ab7558c064036bf2edf922c44f112695a1 100644 (file)
@@ -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);