]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
Trivial fixes to some warnings thrown up by MSVS.Net 2003.
[lyx.git] / src / text.C
index 95e8dccc9d5b4de611058517c535b78790cc6b5d..264a732a3c8f08352e554fd1136600028d8a9070 100644 (file)
@@ -70,6 +70,8 @@
 #include "support/textutils.h"
 #include "support/convert.h"
 
+#include <boost/current_function.hpp>
+
 #include <sstream>
 
 using lyx::pit_type;
@@ -152,10 +154,8 @@ int numberOfHfills(Paragraph const & par, Row const & row)
 
 
 void readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex,
-       string const & token, LyXFont & font)
+       string const & token, LyXFont & font, Change & change)
 {
-       static Change change;
-
        BufferParams const & bp = buf.params();
 
        if (token[0] != '\\') {
@@ -346,10 +346,11 @@ void readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex)
        lex.nextToken();
        string token = lex.getString();
        LyXFont font;
+       Change change;
 
        while (lex.isOK()) {
 
-               readParToken(buf, par, lex, token, font);
+               readParToken(buf, par, lex, token, font, change);
 
                lex.nextToken();
                token = lex.getString();
@@ -592,14 +593,12 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
                   && !isFirstInSequence(pit, pars_)))
            && align == LYX_ALIGN_BLOCK
            && !par.params().noindent()
+           // in some insets, paragraphs are never indented
+           && !(par.inInset() && par.inInset()->neverIndent())
            // display style insets are always centered, omit indentation
            && !(!par.empty()
                    && par.isInset(pos)
                    && par.getInset(pos)->display())
-           // in charstyles, tabulars and ert paragraphs are never indented!
-           && ((par.ownerCode() != InsetBase::TEXT_CODE || isMainText())
-                   && par.ownerCode() != InsetBase::ERT_CODE
-                   && par.ownerCode() != InsetBase::CHARSTYLE_CODE)
            && (par.layout() != tclass.defaultLayout()
                || bv()->buffer()->params().paragraph_separation ==
                   BufferParams::PARSEP_INDENT))
@@ -1003,7 +1002,8 @@ void LyXText::setHeightOfRow(pit_type const pit, Row & row)
        if (bv_owner->text() == this) {
                if (pit == 0 && row.pos() == 0)
                        maxasc += 20;
-               if (pit + 1 == pars_.size() && row.endpos() == par.size())
+               if (pit + 1 == pit_type(pars_.size()) &&
+                   row.endpos() == par.size())
                        maxdesc += 20;
        }
 
@@ -1187,8 +1187,7 @@ void LyXText::insertChar(LCursor & cur, char c)
 
        current_font = rawtmpfont;
        real_current_font = realtmpfont;
-       //setCursor(cur, cur.pit(), cur.pos() + 1, false, cur.boundary());
-       setCursor(cur, cur.pit(), cur.pos() + 1, false, true);
+       setCursor(cur, cur.pit(), cur.pos() + 1, false, cur.boundary());
        charInserted();
 }
 
@@ -1695,7 +1694,7 @@ bool LyXText::redoParagraph(pit_type const pit)
        InsetList::iterator iend = par.insetlist.end();
        for (; ii != iend; ++ii) {
                Dimension dim;
-               int const w = maxwidth_ - leftMargin(pit) - rightMargin(par);
+               int const w = maxwidth_ - leftMargin(pit, ii->pos) - rightMargin(par);
                MetricsInfo mi(bv(), getFont(par, ii->pos), w);
                ii->inset->metrics(mi, dim);
        }
@@ -1898,12 +1897,13 @@ void LyXText::drawSelection(PainterInfo & pi, int x, int) const
                X2 = !isRTL(par2) ? endx : 0 + dim_.wid;
        }
 
-       if (!above && !below && &par1.getRow(beg.pos(), end.boundary())
+       if (!above && !below && &par1.getRow(beg.pos(), beg.boundary())
            == &par2.getRow(end.pos(), end.boundary()))
        {
                // paint only one rectangle
-               pi.pain.fillRectangle(x + x1, y1, X2 - x1, y2 - y1,
-                                     LColor::selection);
+               int const b( !isRTL(par1) ? x + x1 : x + X1 );
+               int const w( !isRTL(par1) ? X2 - x1 : x2 - X1 );
+               pi.pain.fillRectangle(b, y1, w, y2 - y1, LColor::selection);
                return;
        }
 
@@ -1988,8 +1988,6 @@ void LyXText::write(Buffer const & buf, std::ostream & os) const
 
 bool LyXText::read(Buffer const & buf, LyXLex & lex)
 {
-       static Change current_change;
-
        Paragraph::depth_type depth = 0;
 
        while (lex.isOK()) {
@@ -2129,8 +2127,19 @@ int LyXText::cursorX(CursorSlice const & sl, bool boundary) const
        
        // see correction above
        if (boundary_correction)
-               x += singleWidth(par, ppos);
-
+               if (getFont(par, ppos).isVisibleRightToLeft())
+                       x -= singleWidth(par, ppos);
+               else
+                       x += singleWidth(par, ppos);
+
+       // Make sure inside an inset we always count from the left
+       // edge (bidi!) -- MV
+       if (sl.pos() < par.size()) {
+               font = getFont(par, sl.pos());
+               if (!boundary && font.isVisibleRightToLeft()
+                 && par.isInset(sl.pos()))
+                       x -= par.getInset(sl.pos())->width();
+       }       
        return int(x);
 }
 
@@ -2305,7 +2314,7 @@ pos_type LyXText::x2pos(pit_type pit, int row, int x) const
 
 // x,y are screen coordinates
 // sets cursor only within this LyXText
-void LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
+bool LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
 {
        pit_type pit = getPitNearY(y);
        int yy = theCoords.get(this, pit).y_ - pars_[pit].ascent();
@@ -2344,5 +2353,5 @@ void LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
                 << " pos: " << pos
                 << endl;
         
-       setCursor(cur, pit, pos, true, bound);
+       return setCursor(cur, pit, pos, true, bound);
 }