]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
more guii moving around.
[lyx.git] / src / text.C
index 7bbca3dfeec05b024f4961df1bb939389768b95f..e376fff0af1d3c56ddc16df1c3f1a8bc17e1b8cc 100644 (file)
 #include "buffer.h"
 #include "debug.h"
 #include "lyxrc.h"
-#include "LyXView.h"
-#include "Painter.h"
+#include "frontends/LyXView.h"
+#include "frontends/Painter.h"
+#include "frontends/screen.h"
 #include "tracer.h"
 #include "font.h"
 #include "encoding.h"
-#include "lyxscreen.h"
 #include "bufferview_funcs.h"
 #include "BufferView.h"
 #include "language.h"
@@ -283,6 +283,13 @@ void LyXText::computeBidiTables(Buffer const * buf, Row * row) const
                return;
        }
 
+       Inset * inset = row->par()->inInset();
+       if (inset && inset->owner() &&
+           inset->owner()->lyxCode() == Inset::ERT_CODE) {
+               bidi_start = -1;
+               return;
+       }
+
        bidi_start = row->pos();
        bidi_end = rowLastPrintable(row);
 
@@ -306,7 +313,7 @@ void LyXText::computeBidiTables(Buffer const * buf, Row * row) const
 
        pos_type stack[2];
        bool const rtl_par =
-               row->par()->getParLanguage(buf->params)->RightToLeft();
+               row->par()->isRightToLeftPar(buf->params);
        int level = 0;
        bool rtl = false;
        bool rtl0 = false;
@@ -475,23 +482,25 @@ void LyXText::drawNewline(DrawRowParams & p, pos_type const pos)
 }
 
 
-void LyXText::drawInset(DrawRowParams & p, pos_type const pos)
+bool LyXText::drawInset(DrawRowParams & p, pos_type const pos)
 {
        Inset * inset = p.row->par()->getInset(pos);
 
        // FIXME: shouldn't happen
        if (!inset) {
-               return;
+               return true;
        }
 
        LyXFont const & font = getFont(p.bv->buffer(), p.row->par(), pos);
+       // we need this here as the row pointer may be illegal
+       // at a later time (Jug20020502)
+       Row * prev = p.row->previous();
 
        inset->update(p.bv, font, false);
        inset->draw(p.bv, font, p.yo + p.row->baseline(), p.x, p.cleared);
 
        if (!need_break_row && !inset_owner
            && p.bv->text->status() == CHANGED_IN_DRAW) {
-               Row * prev = p.row->previous();
                if (prev && prev->par() == p.row->par()) {
                        breakAgainOneRow(p.bv, prev);
                        if (prev->next() != p.row) {
@@ -501,11 +510,15 @@ void LyXText::drawInset(DrawRowParams & p, pos_type const pos)
                        } else {
                                need_break_row = p.row;
                        }
+               } else if (!prev) {
+                       need_break_row = firstrow;
                } else {
-                       need_break_row = p.row;
+                       need_break_row = prev->next();
                }
                setCursor(p.bv, cursor.par(), cursor.pos());
+               return false;
        }
+       return true;
 }
 
 
@@ -630,7 +643,7 @@ void LyXText::drawChars(DrawRowParams & p, pos_type & vpos,
 }
 
 
-void LyXText::draw(DrawRowParams & p, pos_type & vpos)
+bool LyXText::draw(DrawRowParams & p, pos_type & vpos)
 {
        pos_type const pos = vis2log(vpos);
        Paragraph * par = p.row->par();
@@ -644,12 +657,13 @@ void LyXText::draw(DrawRowParams & p, pos_type & vpos)
        if (IsNewlineChar(c)) {
                ++vpos;
                drawNewline(p, pos);
-               return;
+               return true;
        } else if (IsInsetChar(c)) {
-               drawInset(p, pos);
+               if (!drawInset(p, pos))
+                       return false;
                ++vpos;
                drawForeignMark(p, orig_x, orig_font);
-               return;
+               return true;
        }
 
        // usual characters, no insets
@@ -681,6 +695,7 @@ void LyXText::draw(DrawRowParams & p, pos_type & vpos)
                lyxerr << "No this shouldn't happen!\n";
 #endif
 #endif
+       return true;
 }
 
 
@@ -690,6 +705,12 @@ void LyXText::draw(DrawRowParams & p, pos_type & vpos)
 // exactly the label-width.
 int LyXText::leftMargin(BufferView * bview, Row const * row) const
 {
+       Inset * ins;
+       if ((row->par()->getChar(row->pos()) == Paragraph::META_INSET) &&
+               (ins=row->par()->getInset(row->pos())) &&
+               (ins->needFullRow() || ins->display()))
+               return LYX_PAPER_MARGIN;
+
        LyXTextClass const & tclass =
                textclasslist[bview->buffer()->params.textclass];
        LyXLayout const & layout = tclass[row->par()->layout()];
@@ -828,6 +849,15 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
        break;
        }
 
+       if ((workWidth(bview) > 0) &&
+               !row->par()->params().leftIndent().zero())
+       {
+               LyXLength const len = row->par()->params().leftIndent();
+               int const tw = inset_owner ?
+                       inset_owner->latexTextWidth(bview) : workWidth(bview);
+               x += len.inPixels(tw, bview->text->defaultHeight());
+       }
+
        LyXAlignment align; // wrong type
 
        if (row->par()->params().align() == LYX_ALIGN_LAYOUT)
@@ -866,6 +896,12 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
 
 int LyXText::rightMargin(Buffer const * buf, Row const * row) const
 {
+       Inset * ins;
+       if ((row->par()->getChar(row->pos()) == Paragraph::META_INSET) &&
+               (ins=row->par()->getInset(row->pos())) &&
+               (ins->needFullRow() || ins->display()))
+               return LYX_PAPER_MARGIN;
+
        LyXTextClass const & tclass = textclasslist[buf->params.textclass];
        LyXLayout const & layout = tclass[row->par()->layout()];
 
@@ -1147,7 +1183,7 @@ int LyXText::numberOfSeparators(Buffer const * buf, Row const * row) const
 {
        pos_type last = rowLastPrintable(row);
        pos_type p = max(row->pos(), beginningOfMainBody(buf, row->par()));
-               
+
        int n = 0;
        for (; p <= last; ++p) {
                if (row->par()->isSeparator(p)) {
@@ -1698,8 +1734,10 @@ void LyXText::breakParagraph(BufferView * bview, char keep_layout)
    LyXLayout const & layout = tclass[cursor.par()->layout()];
 
    // this is only allowed, if the current paragraph is not empty or caption
+   // and if it has not the keepempty flag aktive
    if ((cursor.par()->size() <= 0)
-       && layout.labeltype!= LABEL_SENSITIVE)
+       && layout.labeltype != LABEL_SENSITIVE
+          && !layout.keepempty)
           return;
 
    setUndo(bview, Undo::FINISH, cursor.par(), cursor.par()->next());
@@ -1717,6 +1755,12 @@ void LyXText::breakParagraph(BufferView * bview, char keep_layout)
      keep_layout = 2;
    else
      keep_layout = layout.isEnvironment();
+
+   // we need to set this before we insert the paragraph. IMO the
+   // breakParagraph call should return a bool if it inserts the
+   // paragraph before or behind and we should react on that one
+   // but we can fix this in 1.3.0 (Jug 20020509)
+   bool const isempty = (layout.keepempty && !cursor.par()->size());
    cursor.par()->breakParagraph(bview->buffer()->params, cursor.pos(),
                                keep_layout);
 
@@ -1735,7 +1779,8 @@ void LyXText::breakParagraph(BufferView * bview, char keep_layout)
     * This touches only the screen-update. Otherwise we would may have
     * an empty row on the screen */
    if (cursor.pos() && !cursor.row()->par()->isNewline(cursor.row()->pos() - 1)
-       && cursor.row()->pos() == cursor.pos()) {
+       && cursor.row()->pos() == cursor.pos())
+   {
           cursorLeft(bview);
    }
 
@@ -1768,7 +1813,7 @@ void LyXText::breakParagraph(BufferView * bview, char keep_layout)
 
    /* This check is necessary. Otherwise the new empty paragraph will
     * be deleted automatically. And it is more friendly for the user! */
-   if (cursor.pos())
+   if (cursor.pos() || isempty)
           setCursor(bview, cursor.par()->next(), 0);
    else
           setCursor(bview, cursor.par(), 0);
@@ -1895,13 +1940,14 @@ void LyXText::insertChar(BufferView * bview, char c)
                }
        } else if (IsNewlineChar(c)) {
                if (cursor.pos() <= beginningOfMainBody(bview->buffer(),
-                                                       cursor.par())) {
+                                                       cursor.par()))
+               {
                        charInserted();
                        return;
                }
                /* No newline at first position
                 * of a paragraph or behind labels.
-                * TeX does not allow that. */
+                * TeX does not allow that */
 
                if (cursor.pos() < cursor.par()->size() &&
                    cursor.par()->isLineSeparator(cursor.pos()))
@@ -1937,12 +1983,12 @@ void LyXText::insertChar(BufferView * bview, char c)
        }
 
        // Is there a break one row above
-       if ((cursor.par()->isLineSeparator(cursor.pos())
-            || cursor.par()->isNewline(cursor.pos())
-                || ((cursor.pos() < cursor.par()->size()) &&
-                        cursor.par()->isInset(cursor.pos()+1))
-            || cursor.row()->fill() == -1)
-           && row->previous() && row->previous()->par() == row->par())
+       if (row->previous() && row->previous()->par() == row->par()
+           && (cursor.par()->isLineSeparator(cursor.pos())
+               || cursor.par()->isNewline(cursor.pos())
+               || ((cursor.pos() < cursor.par()->size()) &&
+                   cursor.par()->isInset(cursor.pos()+1))
+               || cursor.row()->fill() == -1))
        {
                pos_type z = nextBreakPoint(bview,
                                                           row->previous(),
@@ -1990,7 +2036,7 @@ void LyXText::insertChar(BufferView * bview, char c)
                                * will set fill to -1. Otherwise
                                * we would not get a rebreak! */
                row->fill(fill(bview, row, workWidth(bview)));
-       if (row->fill() < 0) {
+       if (c == Paragraph::META_INSET || row->fill() < 0) {
                refresh_y = y;
                refresh_row = row;
                refresh_x = cursor.x();
@@ -2088,7 +2134,8 @@ void LyXText::prepareToPrint(BufferView * bview,
                x = (workWidth(bview) > 0)
                        ? rightMargin(bview->buffer(), row) : 0;
        } else
-               x = (workWidth(bview) > 0) ? leftMargin(bview, row) : 0;
+               x = (workWidth(bview) > 0)
+                       ? leftMargin(bview, row) : 0;
 
        // is there a manual margin with a manual label
        LyXTextClass const & tclass = textclasslist[bview->buffer()->params.textclass];
@@ -3592,7 +3639,14 @@ void LyXText::paintRowText(DrawRowParams & p)
 
        pos_type vpos = p.row->pos();
        while (vpos <= last) {
+               if (p.x > p.bv->workWidth())
+                       break;
                pos_type pos = vis2log(vpos);
+               if (p.x + singleWidth(p.bv, par, pos) < 0) {
+                       p.x += singleWidth(p.bv, par, pos);
+                       ++vpos;
+                       continue;
+               }
                if (main_body > 0 && pos == main_body - 1) {
                        int const lwidth = lyxfont::width(layout.labelsep,
                                getLabelFont(buffer, par));
@@ -3638,7 +3692,8 @@ void LyXText::paintRowText(DrawRowParams & p)
                                p.x += p.separator;
                        ++vpos;
                } else {
-                       draw(p, vpos);
+                       if (!draw(p, vpos))
+                               break;
                }
        }
 }