]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
mathed31.diff
[lyx.git] / src / text2.C
index 8836bccca5ba1bfe941f8a9cfa2930966de4116c..8517d5a738f8b4837c971fb9122c31088d0b5930 100644 (file)
@@ -45,7 +45,9 @@
 #include "FloatList.h"
 
 using std::copy;
+using std::find;
 using std::endl;
+using std::find;
 using std::pair;
 
 
@@ -67,6 +69,7 @@ LyXText::LyXText(InsetText * inset)
 
 void LyXText::init()
 {
+       the_locking_inset = 0;
        firstrow = 0;
        lastrow = 0;
        number_of_rows = 0;
@@ -655,7 +658,7 @@ void LyXText::SetLayout(BufferView * bview, LyXTextClass::size_type layout)
                  false);
        UpdateCounters(bview, cursor.row());
        ClearSelection();
-       SetSelection();
+       SetSelection(bview);
        SetCursor(bview, tmpcursor.par(), tmpcursor.pos(), true);
 }
 
@@ -773,7 +776,7 @@ void  LyXText::IncDepth(BufferView * bview)
        SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos());
        UpdateCounters(bview, cursor.row());
        ClearSelection();
-       SetSelection();
+       SetSelection(bview);
        SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
 }
 
@@ -850,7 +853,7 @@ void  LyXText::DecDepth(BufferView * bview)
        SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos());
        UpdateCounters(bview, cursor.row());
        ClearSelection();
-       SetSelection();
+       SetSelection(bview);
        SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
 }
 
@@ -869,7 +872,7 @@ void LyXText::SetFont(BufferView * bview, LyXFont const & font, bool toggleall)
                        layoutfont = GetFont(bview->buffer(), cursor.par(),-1);
                // Update current font
                real_current_font.update(font,
-                                        bview->buffer()->params.language_info,
+                                        bview->buffer()->params.language,
                                         toggleall);
 
                // Reduce to implicit settings
@@ -913,7 +916,7 @@ void LyXText::SetFont(BufferView * bview, LyXFont const & font, bool toggleall)
                        LyXFont newfont = GetFont(bview->buffer(), 
                                                  cursor.par(), cursor.pos());
                        newfont.update(font,
-                                      bview->buffer()->params.language_info,
+                                      bview->buffer()->params.language,
                                       toggleall);
                        SetCharFont(bview->buffer(),
                                    cursor.par(), cursor.pos(), newfont);
@@ -932,7 +935,7 @@ void LyXText::SetFont(BufferView * bview, LyXFont const & font, bool toggleall)
        sel_cursor = cursor;
        SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos());
        ClearSelection();
-       SetSelection();
+       SetSelection(bview);
        SetCursor(bview, tmpcursor.par(), tmpcursor.pos(), true,
                  tmpcursor.boundary());
 }
@@ -1114,8 +1117,10 @@ bool LyXText::FullRebreak(BufferView * bview)
  * They also delete the corresponding row */
    
 // need the selection cursor:
-void LyXText::SetSelection()
+void LyXText::SetSelection(BufferView * bview)
 {
+       const bool lsel = selection;
+
        if (!selection) {
                last_sel_cursor = sel_cursor;
                sel_start_cursor = sel_cursor;
@@ -1161,6 +1166,9 @@ void LyXText::SetSelection()
        if (sel_start_cursor.par() == sel_end_cursor.par() && 
            sel_start_cursor.pos() == sel_end_cursor.pos())
                selection = false;
+
+       if (inset_owner && (selection || lsel))
+               inset_owner->SetUpdateStatus(bview, InsetText::SELECTION);
 }
 
 
@@ -1202,6 +1210,8 @@ string const LyXText::selectionAsString(Buffer const * buffer) const
 
 void LyXText::ClearSelection() const
 {
+       if (selection)
+               status = LyXText::NEED_MORE_REFRESH;
        selection = false;
        mark_set = false;
 }
@@ -1278,7 +1288,8 @@ void LyXText::ToggleFree(BufferView * bview,
        // If there is a change in the language the implicit word selection 
        // is disabled.
        LyXCursor resetCursor = cursor;
-       bool implicitSelection = (font.language() == ignore_language)
+       bool implicitSelection = (font.language() == ignore_language
+                                 && font.number() == LyXFont::IGNORE)
                ? SelectWordWhenUnderCursor(bview) : false;
 
        // Set font
@@ -1292,6 +1303,8 @@ void LyXText::ToggleFree(BufferView * bview,
                SetCursor(bview, cursor.par(), cursor.pos());
                sel_cursor = cursor;
        }
+       if (inset_owner)
+               inset_owner->SetUpdateStatus(bview, InsetText::CURSOR_PAR);
 }
 
 
@@ -1511,7 +1524,7 @@ void LyXText::SetParagraph(BufferView * bview,
        SetCursor(bview, sel_start_cursor.par(), sel_start_cursor.pos());
        sel_cursor = cursor;
        SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos());
-       SetSelection();
+       SetSelection(bview);
        SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
        if (inset_owner)
            bview->updateInset(inset_owner, true);
@@ -1601,7 +1614,7 @@ void LyXText::SetParagraphExtraOpt(BufferView * bview, int type,
        SetCursor(bview, sel_start_cursor.par(), sel_start_cursor.pos());
        sel_cursor = cursor;
        SetCursor(bview, sel_end_cursor.par(), sel_end_cursor.pos());
-       SetSelection();
+       SetSelection(bview);
        SetCursor(bview, tmpcursor.par(), tmpcursor.pos());
 }
 
@@ -1717,7 +1730,7 @@ void LyXText::SetCounter(Buffer const * buf, LyXParagraph * par) const
         // entry in the marginnote and the enclosing
         // environment is an enum/item then correct for the
         // LaTeX behaviour (ARRae)
-        if(par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
+        if (par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
           && par->footnotekind == LyXParagraph::MARGIN
            && par->Previous()
            && par->Previous()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE
@@ -2033,7 +2046,7 @@ void LyXText::SetCounter(Buffer const * buf, LyXParagraph * par) const
                                Floating const & fl
                                        = floatList.getType(tmp->type());
                                // We should get the correct number here too.
-                               s = fl.name + " #:";
+                               s = fl.name() + " #:";
                        } else {
                                /* par->SetLayout(0); 
                                   s = layout->labelstring;  */
@@ -2141,16 +2154,13 @@ void LyXText::InsertInset(BufferView * bview, Inset * inset)
                                      * The character will not be inserted a
                                      * second time */
 #if 1
-       // if we enter a text-inset the cursor should be to the left side
-       // of it! This couldn't happen before as Undo was not handled inside
+       // If we enter a highly editable inset the cursor should be to before
+       // the inset. This couldn't happen before as Undo was not handled inside
        // inset now after the Undo LyX tries to call inset->Edit(...) again
        // and cannot do this as the cursor is behind the inset and GetInset
        // does not return the inset!
-       if (inset->IsTextInset()) {
-               if (cursor.par()->isRightToLeftPar(bview->buffer()->params))
-                       CursorRight(bview);
-               else
-                       CursorLeft(bview);
+       if (inset->Editable() == Inset::HIGHLY_EDITABLE) {
+               CursorLeft(bview, true);
        }
 #endif
 }
@@ -2185,7 +2195,7 @@ void LyXText::CutSelection(BufferView * bview, bool doclear)
                return;
    
        // OK, we have a selection. This is always between sel_start_cursor
-       // and sel_end cursor
+       // and sel_end_cursor
 #ifndef NEW_INSETS
        // Check whether there are half footnotes in the selection
        if (sel_start_cursor.par()->footnoteflag != LyXParagraph::NO_FOOTNOTE
@@ -2363,7 +2373,7 @@ void LyXText::PasteSelection(BufferView * bview)
    
        sel_cursor = cursor;
        SetCursor(bview, actpar, pos);
-       SetSelection();
+       SetSelection(bview);
        UpdateCounters(bview, cursor.row());
 }
 
@@ -2380,16 +2390,17 @@ bool LyXText::IsStringInText(LyXParagraph * par,
                             LyXParagraph::size_type pos,
                             string const & str) const
 {
-       if (par) {
-               LyXParagraph::size_type i = 0;
-               while (pos + i < par->Last()
-                      && string::size_type(i) < str.length()
-                      && str[i] == par->GetChar(pos + i)) {
-                       ++i;
-               }
-               if (str.length() == string::size_type(i))
-                       return true;
+       if (!par)
+               return false;
+
+       LyXParagraph::size_type i = 0;
+       while (pos + i < par->Last()
+              && string::size_type(i) < str.length()
+              && str[i] == par->GetChar(pos + i)) {
+               ++i;
        }
+       if (str.length() == string::size_type(i))
+               return true;
        return false;
 }
 
@@ -2400,7 +2411,7 @@ void LyXText::SetSelectionOverString(BufferView * bview, string const & str)
        sel_cursor = cursor;
        for (int i = 0; str[i]; ++i)
                CursorRight(bview);
-       SetSelection();
+       SetSelection(bview);
 }
 
 
@@ -2561,7 +2572,7 @@ void LyXText::InsertStringA(BufferView * bview, string const & str)
        SetCursor(bview, cursor.par(), cursor.pos());
        sel_cursor = cursor;
        SetCursor(bview, par, pos);
-       SetSelection();
+       SetSelection(bview);
 }
 
 
@@ -2600,9 +2611,12 @@ void LyXText::InsertStringB(BufferView * bview, string const & s)
 }
 
 
-bool LyXText::GotoNextError(BufferView * bview) const
+bool LyXText::GotoNextInset(BufferView * bview,
+                           std::vector<Inset::Code> const & codes,
+                           string const & contents) const
 {
        LyXCursor res = cursor;
+       Inset * inset;
        do {
                if (res.pos() < res.par()->Last() - 1) {
                        res.pos(res.pos() + 1);
@@ -2613,31 +2627,13 @@ bool LyXText::GotoNextError(BufferView * bview) const
       
        } while (res.par() && 
                 !(res.par()->GetChar(res.pos()) == LyXParagraph::META_INSET
-                  && res.par()->GetInset(res.pos())->AutoDelete()));
-   
-       if (res.par()) {
-               SetCursor(bview, res.par(), res.pos());
-               return true;
-       }
-       return false;
-}
-
+                  && (inset = res.par()->GetInset(res.pos())) != 0
+                  && find(codes.begin(), codes.end(), inset->LyxCode())
+                     != codes.end()
+                  && (contents.empty() ||
+                      static_cast<InsetCommand *>(res.par()->GetInset(res.pos()))->getContents()
+                      == contents)));
 
-bool LyXText::GotoNextNote(BufferView * bview) const
-{
-       LyXCursor res = cursor;
-       do {
-               if (res.pos() < res.par()->Last() - 1) {
-                       res.pos(res.pos() + 1);
-               } else  {
-                       res.par(res.par()->Next());
-                       res.pos(0);
-               }
-      
-       } while (res.par() && 
-                !(res.par()->GetChar(res.pos()) == LyXParagraph::META_INSET
-                  && res.par()->GetInset(res.pos())->LyxCode() == Inset::IGNORE_CODE));
-   
        if (res.par()) {
                SetCursor(bview, res.par(), res.pos());
                return true;
@@ -2658,7 +2654,7 @@ void LyXText::CheckParagraph(BufferView * bview, LyXParagraph * par,
        // is there a break one row above
        if (row->previous() && row->previous()->par() == row->par()) {
                z = NextBreakPoint(bview, row->previous(), workWidth(bview));
-               if ( z >= row->pos()) {
+               if (z >= row->pos()) {
                        // set the dimensions of the row above
                        y -= row->previous()->height();
                        refresh_y = y;
@@ -2669,7 +2665,8 @@ void LyXText::CheckParagraph(BufferView * bview, LyXParagraph * par,
                        
                        // set the cursor again. Otherwise
                        // dangling pointers are possible
-                       SetCursor(bview, cursor.par(), cursor.pos());
+                       SetCursor(bview, cursor.par(), cursor.pos(),
+                                 false, cursor.boundary());
                        sel_cursor = cursor;
                        return;
                }
@@ -2704,20 +2701,25 @@ void LyXText::CheckParagraph(BufferView * bview, LyXParagraph * par,
    
        if (selection) {
                tmpcursor = cursor;
-               SetCursorIntern(bview, sel_cursor.par(), sel_cursor.pos());
+               SetCursorIntern(bview, sel_cursor.par(), sel_cursor.pos(),
+                               false, sel_cursor.boundary());
                sel_cursor = cursor; 
                SetCursorIntern(bview, sel_start_cursor.par(),
-                               sel_start_cursor.pos());
+                               sel_start_cursor.pos(),
+                               false, sel_start_cursor.boundary());
                sel_start_cursor = cursor; 
                SetCursorIntern(bview, sel_end_cursor.par(),
-                               sel_end_cursor.pos());
+                               sel_end_cursor.pos(),
+                               false, sel_end_cursor.boundary());
                sel_end_cursor = cursor; 
                SetCursorIntern(bview, last_sel_cursor.par(),
-                               last_sel_cursor.pos());
+                               last_sel_cursor.pos(),
+                               false, last_sel_cursor.boundary());
                last_sel_cursor = cursor; 
                cursor = tmpcursor;
        }
-       SetCursorIntern(bview, cursor.par(), cursor.pos());
+       SetCursorIntern(bview, cursor.par(), cursor.pos(),
+                       false, cursor.boundary());
 }
 
 
@@ -3089,7 +3091,7 @@ void LyXText::DeleteEmptyParagraphMechanism(BufferView * bview,
        LyXCursor tmpcursor;
 
        if (old_cursor.par() != cursor.par()) {
-               if ( (old_cursor.par()->Last() == 0
+               if ((old_cursor.par()->Last() == 0
                      || (old_cursor.par()->Last() == 1
                          && old_cursor.par()->IsLineSeparator(0)))
 #ifndef NEW_INSETS
@@ -3496,9 +3498,9 @@ Undo * LyXText::CreateUndo(Buffer * buf, Undo::undo_kind kind,
                        end = end->next;
        }
 
-       if (start && end
-           && start != end->next
-           && (before != behind || (!before && !behind))) {
+       if (start && end && (start != end->next) &&
+           ((before != behind) || (!before && !behind)))
+       {
                tmppar = start;
                tmppar2 = tmppar->Clone();
                tmppar2->id(tmppar->id());