]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
mathed31.diff
[lyx.git] / src / text.C
index d915aac7280447325cb8f12ab8e540039e70dcc8..2964b22df4da5a8e38e7376e1fe31af268c7598e 100644 (file)
@@ -54,6 +54,15 @@ int LyXText::workWidth(BufferView * bview) const
 }
 
 
+int LyXText::GetRealCursorX(BufferView * bview) const
+{
+       int x = cursor.x();
+       if (the_locking_inset && (the_locking_inset->getLyXText(bview)!=this))
+               x = the_locking_inset->getLyXText(bview)->GetRealCursorX(bview);
+       return x;
+}
+
+
 unsigned char LyXText::TransformChar(unsigned char c, LyXParagraph * par,
                        LyXParagraph::size_type pos) const
 {
@@ -348,7 +357,8 @@ bool LyXText::IsBoundary(Buffer const * buf, LyXParagraph * par,
                return false;
 
        if (!bidi_InRange(pos - 1)) {
-               lyxerr << "LyXText::IsBoundary This shouldn't happen." << endl;
+               /// This can happen if pos is the first char of a row.
+               /// Returning false in this case is incorrect!
                return false;
        }
 
@@ -504,10 +514,12 @@ void LyXText::draw(BufferView * bview, Row const * row,
 //                     tmpinset->update(bview, font, false);
                        tmpinset->draw(bview, font, offset+row->baseline(), x,
                                       cleared);
+#ifdef SEEMS_TO_BE_NOT_NEEDED
                        if (status == CHANGED_IN_DRAW) {
                                UpdateInset(bview, tmpinset);
                                status = CHANGED_IN_DRAW;
                        }
+#endif
                }
                ++vpos;
 
@@ -1746,11 +1758,14 @@ void LyXText::BreakParagraph(BufferView * bview, char keep_layout)
 #endif
           ); 
 
-   // please break always behind a space
+   // Always break behind a space
+   //
+   // It is better to erase the space (Dekel)
    if (cursor.pos() < cursor.par()->Last()
        && cursor.par()->IsLineSeparator(cursor.pos()))
-     cursor.pos(cursor.pos() + 1);
-   
+          cursor.par()->Erase(cursor.pos());
+           // cursor.pos(cursor.pos() + 1);
+
    // break the paragraph
    if (keep_layout)
      keep_layout = 2;
@@ -1909,9 +1924,13 @@ void LyXText::InsertChar(BufferView * bview, char c)
 
 
        if (lyxrc.auto_number) {
+               static string const number_operators = "+-/*";
+               static string const number_unary_operators = "+-";
+               static string const number_seperators = ".,:";
+
                if (current_font.number() == LyXFont::ON) {
-                       if (!isdigit(c) && !strchr("+-/*", c) &&
-                           !(strchr(".,",c) &&
+                       if (!isdigit(c) && !contains(number_operators, c) &&
+                           !(contains(number_seperators, c) &&
                              cursor.pos() >= 1 &&
                              cursor.pos() < cursor.par()->size() &&
                              GetFont(bview->buffer(),
@@ -1928,7 +1947,7 @@ void LyXText::InsertChar(BufferView * bview, char c)
 
                        if (cursor.pos() > 0) {
                                char const c = cursor.par()->GetChar(cursor.pos() - 1);
-                               if (strchr("+-",c) &&
+                               if (contains(number_unary_operators, c) &&
                                    (cursor.pos() == 1 ||
                                     cursor.par()->IsSeparator(cursor.pos() - 2) ||
                                     cursor.par()->IsNewline(cursor.pos() - 2) )
@@ -1937,7 +1956,7 @@ void LyXText::InsertChar(BufferView * bview, char c)
                                                    cursor.par(),
                                                    cursor.pos() - 1,
                                                    current_font);
-                               } else if (strchr(".,", c) &&
+                               } else if (contains(number_seperators, c) &&
                                           cursor.pos() >= 2 &&
                                           GetFont(bview->buffer(),
                                                   cursor.par(),
@@ -2186,21 +2205,18 @@ void LyXText::PrepareToPrint(BufferView * bview,
 
         bool const is_rtl =
                row->par()->isRightToLeftPar(bview->buffer()->params);
-#ifndef NEW_INSETS
-
        if (is_rtl) {
-               x = RightMargin(bview->buffer(), row);
+               x = (workWidth(bview) > 0)
+                       ? RightMargin(bview->buffer(), row) : 0;
+#ifndef NEW_INSETS
                if (row->par()->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
                        LyXFont font(LyXFont::ALL_SANE);
                        font.setSize(LyXFont::SIZE_SMALL);
                        x += lyxfont::width("Mwide-figM", font);
                }
-       } else
 #endif
-               if (workWidth(bview) > 0)
-               x = LeftMargin(bview, row);
-       else
-               x = 0;
+       } else
+               x = (workWidth(bview) > 0) ? LeftMargin(bview, row) : 0;
        
        // is there a manual margin with a manual label
        if (textclasslist.Style(bview->buffer()->params.textclass,
@@ -2405,7 +2421,7 @@ void LyXText::SelectWord(BufferView * bview)
        SetCursor(bview, cursor.par(), cursor.pos() );
        
        // finally set the selection
-       SetSelection();
+       SetSelection(bview);
 }
 
 
@@ -2516,7 +2532,7 @@ void LyXText::SelectSelectedWord(BufferView * bview)
        SetCursor(bview, cursor.par(), cursor.pos());
        
        // finally set the selection
-       SetSelection();
+       SetSelection(bview);
 }
 
 
@@ -2533,7 +2549,7 @@ void LyXText::DeleteWordForward(BufferView * bview)
                SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
                sel_cursor = cursor;
                cursor = tmpcursor;
-               SetSelection(); 
+               SetSelection(bview); 
                
                /* -----> Great, CutSelection() gets rid of multiple spaces. */
                CutSelection(bview);
@@ -2554,7 +2570,7 @@ void LyXText::DeleteWordBackward(BufferView * bview)
               SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
               sel_cursor = cursor;
               cursor = tmpcursor;
-              SetSelection();
+              SetSelection(bview);
               CutSelection(bview);
        }
 }
@@ -2576,7 +2592,7 @@ void LyXText::DeleteLineForward(BufferView * bview)
                SetCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
                sel_cursor = cursor;
                cursor = tmpcursor;
-               SetSelection();
+               SetSelection(bview);
                // What is this test for ??? (JMarc)
                if (!selection) {
                        DeleteWordForward(bview);
@@ -2876,6 +2892,8 @@ void LyXText::Backspace(BufferView * bview)
                        
                        if (cursor.pos() < cursor.par()->Last() && !cursor.par()->IsSeparator(cursor.pos())) {
                                cursor.par()->InsertChar(cursor.pos(), ' ');
+                               SetCharFont(bview->buffer(), cursor.par(), 
+                                           cursor.pos(), current_font);
                                // refresh the positions
                                tmprow = row;
                                while (tmprow->next() && tmprow->next()->par() == row->par()) {
@@ -3077,10 +3095,15 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
        } else if (clear_area) {
 #ifdef WITH_WARNINGS
 #warning Should be fixed with a lyxinset::clear_width(bv, font) function! (Jug)
+#warning Should we not fix this in the Painter, please have a look Lars! (Jug)
 #endif
-               int const w = (inset_owner ?
-                              inset_owner->width(bview, font)-2 : ww);
-               pain.fillRectangle(x_offset, y_offset, w, row_ptr->height());
+               int const y = y_offset < 0 ? 0 : y_offset;
+               int const h = y_offset < 0 ?
+                       row_ptr->height() + y_offset : row_ptr->height();
+               int const w = inset_owner ?
+                       inset_owner->width(bview, font) - 2 : ww;
+               int const x = x_offset;
+               pain.fillRectangle(x, y, w, h);
        } else if (inset != 0) {
                int h = row_ptr->baseline() - inset->ascent(bview, font);
                if (h > 0) {
@@ -3200,7 +3223,9 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
                                      sel_start_cursor.pos() <= pos) &&
                                     (sel_end_cursor.row() != row_ptr ||
                                      pos < sel_end_cursor.pos()) )
-                                       pain.fillRectangle(x_offset + int(old_tmpx),
+                                       /// Here we do not use x_offset as x_offset was
+                                       // added to x.
+                                       pain.fillRectangle(int(old_tmpx),
                                                           y_offset,
                                                           int(tmpx - old_tmpx + 1),
                                                           row_ptr->height(),
@@ -3391,7 +3416,7 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
 
                for (int i = 1; i <= depth; ++i) {
                        int const line_x = (LYX_PAPER_MARGIN / 5) *
-                               (i + minipage) + box_x;
+                               (i + minipage) + box_x + x_offset;
                        pain.line(line_x, y_offset, line_x,
                                  y_offset + row_ptr->height() - 1 - (i - next_depth - 1) * 3,
                                  LColor::depthbar);