]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
More fixes to insettabular/text (and some missing features added).
[lyx.git] / src / text2.C
index d20c3ecc1ce6809326c2f1ce005f1d738784c8a4..16fe687dc3057cc29c3c0af02da180ff8c9a6ce2 100644 (file)
@@ -67,6 +67,7 @@ LyXText::LyXText(InsetText * inset)
 
 void LyXText::init()
 {
+       the_locking_inset = 0;
        firstrow = 0;
        lastrow = 0;
        number_of_rows = 0;
@@ -345,7 +346,7 @@ void LyXText::RemoveRow(Row * row) const
        /* this must not happen before the currentrow for clear reasons.
           so the trick is just to set the current row onto the previous
           row of this row */
-       long unused_y;
+       int unused_y;
        GetRow(row->par(), row->pos(), unused_y);
    
        if (row->next())
@@ -869,7 +870,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 +914,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);
@@ -941,7 +942,7 @@ void LyXText::SetFont(BufferView * bview, LyXFont const & font, bool toggleall)
 void LyXText::RedoHeightOfParagraph(BufferView * bview, LyXCursor const & cur)
 {
        Row * tmprow = cur.row();
-       long y = cur.y() - tmprow->baseline();
+       int y = cur.y() - tmprow->baseline();
 
        SetHeightOfRow(bview, tmprow);
 #ifndef NEW_INSETS
@@ -975,7 +976,7 @@ void LyXText::RedoDrawingOfParagraph(BufferView * bview, LyXCursor const & cur)
 {
        Row * tmprow = cur.row();
    
-       long y = cur.y() - tmprow->baseline();
+       int y = cur.y() - tmprow->baseline();
        SetHeightOfRow(bview, tmprow);
 #ifndef NEW_INSETS
        LyXParagraph * first_phys_par = tmprow->par()->FirstPhysicalPar();
@@ -1014,7 +1015,7 @@ void LyXText::RedoParagraphs(BufferView * bview, LyXCursor const & cur,
    
        Row * tmprow = cur.row();
    
-       long y = cur.y() - tmprow->baseline();
+       int y = cur.y() - tmprow->baseline();
    
        if (!tmprow->previous()){
                first_phys_par = FirstParagraph();   // a trick/hack for UNDO
@@ -1202,6 +1203,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;
 }
@@ -1247,10 +1250,10 @@ void  LyXText::CursorBottom(BufferView * bview) const
 /* returns a pointer to the row near the specified y-coordinate
 * (relative to the whole text). y is set to the real beginning
 * of this row */
-Row * LyXText::GetRowNearY(long & y) const
+Row * LyXText::GetRowNearY(int & y) const
 {
        Row * tmprow = firstrow;
-       long tmpy = 0;
+       int tmpy = 0;
 
        while (tmprow->next() && tmpy + tmprow->height() <= y) {
                tmpy += tmprow->height();
@@ -1278,7 +1281,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
@@ -1615,6 +1619,7 @@ char loweralphaCounter(int n)
 }
 
 
+static inline
 char alphaCounter(int n)
 {
        if (n < 1 || n > 26)
@@ -1624,6 +1629,7 @@ char alphaCounter(int n)
 }
 
 
+static inline
 char hebrewCounter(int n)
 {
        static const char hebrew[22] = {
@@ -1715,7 +1721,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
@@ -2031,7 +2037,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;  */
@@ -2138,6 +2144,19 @@ void LyXText::InsertInset(BufferView * bview, Inset * inset)
        InsertChar(bview, LyXParagraph::META_INSET);  /* just to rebreak and refresh correctly.
                                      * 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
+       // 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);
+       }
+#endif
 }
 
 
@@ -2170,7 +2189,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
@@ -2365,15 +2384,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() && i < str.length()&& 
-                      str[i] == par->GetChar(pos + i)) {
-                       ++i;
-               }
-               if (str.length() == 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;
 }
 
@@ -2635,14 +2656,14 @@ void LyXText::CheckParagraph(BufferView * bview, LyXParagraph * par,
 {
        LyXCursor tmpcursor;                    
 
-       long y = 0;
+       int y = 0;
        LyXParagraph::size_type z;
        Row * row = GetRow(par, pos, y);
        
        // 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;
@@ -2653,7 +2674,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;
                }
@@ -2688,20 +2710,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());
 }
 
 
@@ -2783,7 +2810,7 @@ void LyXText::SetCursor(BufferView *bview, LyXCursor & cur, LyXParagraph * par,
        cur.boundary(boundary);
 
        /* get the cursor y position in text  */
-       long y = 0;
+       int y = 0;
        Row * row = GetRow(par, pos, y);
        /* y is now the beginning of the cursor row */ 
        y += row->baseline();
@@ -2902,7 +2929,7 @@ void LyXText::SetCurrentFont(BufferView * bview) const
 }
 
 
-void LyXText::SetCursorFromCoordinates(BufferView * bview, int x, long y) const
+void LyXText::SetCursorFromCoordinates(BufferView * bview, int x, int y) const
 {
        LyXCursor old_cursor = cursor;
    
@@ -2924,7 +2951,7 @@ void LyXText::SetCursorFromCoordinates(BufferView * bview, int x, long y) const
 
 
 void LyXText::SetCursorFromCoordinates(BufferView * bview, LyXCursor & cur,
-                                      int x, long y) const
+                                      int x, int y) const
 {
        /* get the row first */ 
    
@@ -2942,12 +2969,6 @@ void LyXText::SetCursorFromCoordinates(BufferView * bview, LyXCursor & cur,
 
 
 void LyXText::CursorLeft(BufferView * bview, bool internal) const
-{
-       CursorLeftIntern(bview, internal);
-}
-
-
-void LyXText::CursorLeftIntern(BufferView * bview, bool internal) const
 {
        if (cursor.pos() > 0) {
                bool boundary = cursor.boundary();
@@ -2963,12 +2984,6 @@ void LyXText::CursorLeftIntern(BufferView * bview, bool internal) const
 
 
 void LyXText::CursorRight(BufferView * bview, bool internal) const
-{
-       CursorRightIntern(bview, internal);
-}
-
-
-void LyXText::CursorRightIntern(BufferView * bview, bool internal) const
 {
        if (!internal && cursor.boundary() &&
            !cursor.par()->IsNewline(cursor.pos()))
@@ -3085,7 +3100,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
@@ -3492,9 +3507,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());