]> git.lyx.org Git - features.git/commitdiff
the 'lots of small stuff' patch
authorAndré Pönitz <poenitz@gmx.net>
Tue, 25 Nov 2003 11:17:27 +0000 (11:17 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Tue, 25 Nov 2003 11:17:27 +0000 (11:17 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8135 a592a061-630c-0410-9148-cb99ea01b6c8

14 files changed:
src/ChangeLog
src/InsetList.C
src/InsetList.h
src/insets/insetcollapsable.C
src/insets/insettext.C
src/insets/insettext.h
src/lyxtext.h
src/main.C
src/paragraph.C
src/paragraph_pimpl.C
src/rowpainter.C
src/text.C
src/text2.C
src/text3.C

index 739733ea8b99786f98c73290af8fbe6eb5a5b796..8e9465f0b427d3c118667dd97176a6c9acb8a53e 100644 (file)
@@ -1,3 +1,15 @@
+
+2003-11-25  André Pönitz  <poenitz@gmx.net>
+
+       * InsetList.[Ch] (begein, end): inline as suggested by profiler
+
+       * lyxtext.h (leftMargin/rightMargin): simplify interface
+
+       * rowpainter.C:
+       * text.C:
+       * text2.C:
+       * text3.C: adjust
+
 2003-11-24  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
 
        * lyxfunc.C (dispatch): propogate the bibtex databases from the
index 1921cc108a8f402ad577a79a1554ac870df70b01..43027b3b9189d8fee4e3fdc14e004478cd106aa2 100644 (file)
@@ -53,30 +53,6 @@ InsetList::~InsetList()
 }
 
 
-InsetList::iterator InsetList::begin()
-{
-       return list.begin();
-}
-
-
-InsetList::iterator InsetList::end()
-{
-       return list.end();
-}
-
-
-InsetList::const_iterator InsetList::begin() const
-{
-       return list.begin();
-}
-
-
-InsetList::const_iterator InsetList::end() const
-{
-       return list.end();
-}
-
-
 InsetList::iterator InsetList::insetIterator(pos_type pos)
 {
        InsetTable search_elem(pos, 0);
index 1141a8a84a13418aed63f7cbd27ddb8f0bd61ee9..fc40e450889a960aaad1adaad98e13850aff4c66 100644 (file)
@@ -42,13 +42,15 @@ public:
        ///
        ~InsetList();
        ///
-       iterator begin();
+       iterator begin() { return list.begin(); }
        ///
-       iterator end();
+       iterator end() { return list.end(); }
        ///
-       const_iterator begin() const;
+       const_iterator begin() const { return list.begin(); }
        ///
-       const_iterator end() const;
+       const_iterator end() const { return list.end(); }
+       ///
+       bool empty() const { return list.empty(); }
        ///
        iterator insetIterator(lyx::pos_type pos); 
        ///
index 3e2ab79535dd1db4a24339fcf9da2455c78781f1..4fa6d85db83823ba523abc0ef35ae6ad0051a970 100644 (file)
@@ -356,7 +356,7 @@ int InsetCollapsable::scroll(bool recursive) const
        int sx = UpdatableInset::scroll(false);
 
        if (recursive)
-               sx += inset.scroll(recursive);
+               sx += inset.scroll(false);
 
        return sx;
 }
index 082dbc46605609611b06be81e3440dd7ed0a1e9c..61e4699de3771f6695efb261144561db8e16e408 100644 (file)
@@ -218,38 +218,30 @@ void InsetText::read(Buffer const & buf, LyXLex & lex)
 void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        //lyxerr << "InsetText::metrics: width: " << mi.base.textwidth << endl;
-       textwidth_ = max(40, mi.base.textwidth - 30);
-       BufferView * bv = mi.base.bv;
-       setViewCache(bv);
+       textwidth_ = mi.base.textwidth;
+       mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
+       setViewCache(mi.base.bv);
        text_.metrics(mi, dim);
        dim.asc += TEXT_TO_INSET_OFFSET;
        dim.des += TEXT_TO_INSET_OFFSET;
        dim.wid += 2 * TEXT_TO_INSET_OFFSET;
+       mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
        dim_ = dim;
 }
 
 
-int InsetText::textWidth() const
-{
-       return textwidth_;
-}
-
-
 void InsetText::draw(PainterInfo & pi, int x, int y) const
 {
-       // update our idea of where we are. Clearly, we should
-       // not have to know this information.
+       // update our idea of where we are
        xo_ = x;
        yo_ = y;
 
-       int const start_x = x;
-
        BufferView * bv = pi.base.bv;
        Painter & pain = pi.pain;
 
        // repaint the background if needed
        if (backgroundColor() != LColor::background)
-               clearInset(bv, start_x + TEXT_TO_INSET_OFFSET, y);
+               clearInset(bv, xo_ + TEXT_TO_INSET_OFFSET, y);
 
        bv->hideCursor();
 
@@ -264,7 +256,7 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const
        paintTextInset(*bv, text_, x, y);
 
        if (drawFrame_ == ALWAYS || drawFrame_ == LOCKED)
-               drawFrame(pain, start_x);
+               drawFrame(pain, xo_);
 }
 
 
@@ -627,12 +619,12 @@ void InsetText::clearSelection(BufferView *)
 }
 
 
-void InsetText::clearInset(BufferView * bv, int start_x, int baseline) const
+void InsetText::clearInset(BufferView * bv, int x, int y) const
 {
        Painter & pain = bv->painter();
        int w = dim_.wid;
        int h = dim_.asc + dim_.des;
-       int ty = baseline - dim_.asc;
+       int ty = y - dim_.asc;
 
        if (ty < 0) {
                h += ty;
@@ -642,7 +634,7 @@ void InsetText::clearInset(BufferView * bv, int start_x, int baseline) const
                h = pain.paperHeight();
        if (xo_ + w > pain.paperWidth())
                w = pain.paperWidth();
-       pain.fillRectangle(start_x + 1, ty + 1, w - 3, h - 1, backgroundColor());
+       pain.fillRectangle(x + 1, ty + 1, w - 3, h - 1, backgroundColor());
 }
 
 
index a8b51994066427aa628a69df5d5dfd5550f87e3e..1f257fa378147cd2958a1d020d97774bc3c1daf5 100644 (file)
@@ -65,8 +65,6 @@ public:
        ///
        void metrics(MetricsInfo &, Dimension &) const;
        ///
-       int textWidth() const;
-       ///
        void draw(PainterInfo & pi, int x, int y) const;
        ///
        std::string const editMessage() const;
index 7dc67850fe728cbb076951d536b70b2b352375ac..8af10531b39349b7e1f1b68a1c9a0469ccc21d3d 100644 (file)
@@ -53,15 +53,12 @@ class LyXText : public TextCursor {
 public:
        /// Constructor
        LyXText(BufferView *, InsetText *, bool ininset, ParagraphList & plist);
-
-       // Copy assignment
-       LyXText & operator=(LyXText const &);
-
+       ///
        void init(BufferView *);
 
 
-       /// update all cached row positions
-       void updateRowPositions();
+       /// update y coordinate cache of all paragraphs
+       void updateParPositions();
        ///
        LyXFont getFont(ParagraphList::iterator pit, lyx::pos_type pos) const;
        ///
@@ -152,9 +149,9 @@ public:
        ///
        RowList::iterator cursorRow() 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
+       /** returns an iterator pointing to the row near the specified
+         * y-coordinate (relative to the whole text). y is set to the
+         * real beginning of this row
          */
        RowList::iterator getRowNearY(int y,
                ParagraphList::iterator & pit) const;
@@ -302,15 +299,12 @@ public:
        ///
        void gotoInset(InsetOld::Code code, bool same_content);
 
-       ///
-       int workWidth() const;
+       /// current max text width
+       int textWidth() const;
 
-       /** Updates all counters starting BEHIND the row. Changed paragraphs
-        * with a dynamic left margin will be rebroken. */
+       /// updates all counters
        void updateCounters();
-       /**
-        * Returns an inset if inset was hit, or 0 if not.
-        */
+       /// Returns an inset if inset was hit, or 0 if not.
        InsetOld * checkInsetHit(int x, int y);
 
        ///
@@ -328,9 +322,10 @@ public:
         * in LaTeX the beginning of the text fits in some cases
         * (for example sections) exactly the label-width.
         */
-       int leftMargin(ParagraphList::iterator pit, Row const & row) const;
+       int leftMargin(ParagraphList::iterator pit, lyx::pos_type pos) const;
+       int leftMargin(ParagraphList::iterator pit) const;
        ///
-       int rightMargin(Paragraph const & par, Buffer const &) const;
+       int rightMargin(Paragraph const & par) const;
 
        /** this calculates the specified parameters. needed when setting
         * the cursor and when creating a visible row */
@@ -396,12 +391,13 @@ public:
        bool checkAndActivateInset(bool front);
 
 
-       // Public Variables
 public:
        ///
        int height;
        ///
        unsigned int width;
+       ///
+       int textwidth_;
        /// the current font settings
        LyXFont current_font;
        /// the current font
@@ -426,7 +422,6 @@ public:
        int yo_;
 
 
-       // Private Functions
 private:
        /// rebreaks the given par
        void redoParagraphInternal(ParagraphList::iterator pit);
@@ -470,7 +465,7 @@ private:
        int labelFill(ParagraphList::iterator pit, Row const & row) const;
 
        /// FIXME
-       int labelEnd(ParagraphList::iterator pit, Row const & row) const;
+       int labelEnd(ParagraphList::iterator pit) const;
 
        ///
        void charInserted();
@@ -478,16 +473,6 @@ private:
        void number();
        /// is the cursor paragraph right-to-left?
        bool rtl() const;
-
-       // Private Variables
-private:
-
-       /// prohibit this as long as there are back pointers...
-       LyXText(LyXText const &);
-
-       // cache for cursorPar()
-       mutable ParagraphList::iterator cache_par_;
-       mutable int cache_pos_;
 };
 
 /// return the default height of a row in pixels, considering font zoom
index f0de20d48a027fd0e49e0e0177fc7e52a4e9ea02..ba4637edfed9601bf781367b083d6b762d08d2c0 100644 (file)
@@ -23,7 +23,6 @@
 
 namespace os = lyx::support::os;
 
-
 int main(int argc, char * argv[])
 {
 #ifdef HAVE_IOS
index 4176e2f9309ee997bca432e568430309c6960c57..35101a0327db470d3a223816a7db97c67653d8cd 100644 (file)
@@ -706,9 +706,11 @@ int Paragraph::getPositionOfInset(InsetOld const * inset) const
 
 InsetBibitem * Paragraph::bibitem() const
 {
-       InsetList::const_iterator it = insetlist.begin();
-       if (it != insetlist.end() && it->inset->lyxCode() == InsetOld::BIBTEX_CODE)
-               return static_cast<InsetBibitem *>(it->inset);
+       if (!insetlist.empty()) {
+               InsetOld * inset = insetlist.begin()->inset;
+               if (inset->lyxCode() == InsetOld::BIBTEX_CODE)
+                       return static_cast<InsetBibitem *>(inset);
+       }
        return 0;
 }
 
index 9b71f30898a0dee69162e622a0405fb84208ce7a..91d67776610bbff0ca207c5353890633543ae561 100644 (file)
@@ -362,8 +362,7 @@ bool Paragraph::Pimpl::erase(pos_type pos)
                // only allow the actual removal if it was /new/ text
                if (changetype != Change::INSERTED) {
                        if (owner_->text_[pos] == Paragraph::META_INSET) {
-                               InsetOld * i(owner_->getInset(pos));
-                               i->markErased();
+                               owner_->getInset(pos)->markErased();
                        }
                        return false;
                }
@@ -377,12 +376,9 @@ bool Paragraph::Pimpl::erase(pos_type pos)
 int Paragraph::Pimpl::erase(pos_type start, pos_type end)
 {
        pos_type i = start;
-       pos_type count = end - start;
-       while (count) {
-               if (!erase(i)) {
+       for (pos_type count = end - start; count; --count) {
+               if (!erase(i))
                        ++i;
-               }
-               --count;
        }
        return end - i;
 }
index efdc60a6eecf0b77478fc5e191a036a3ba9e777c..4b25b1a0be1d961b31efd4ff715d9c9f25469977 100644 (file)
@@ -44,9 +44,8 @@ using std::endl;
 using std::max;
 using std::string;
 
-extern int PAPER_MARGIN;
+extern int NEST_MARGIN;
 extern int CHANGEBAR_MARGIN;
-extern int LEFT_MARGIN;
 
 namespace {
 
@@ -122,7 +121,7 @@ RowPainter::RowPainter(BufferView const & bv, LyXText const & text,
      int xo, int yo)
        : bv_(bv), pain_(bv_.painter()), text_(text), rit_(rit), row_(*rit),
          pit_(pit), xo_(xo), yo_(yo), x_(row_.x()),
-               width_(text_.workWidth()),
+               width_(text_.textWidth()),
                separator_(row_.fill_separator()),
                hfill_(row_.fill_hfill()),
                label_hfill_(row_.fill_label_hfill())
@@ -185,7 +184,7 @@ LyXFont const RowPainter::getLabelFont() const
 
 int RowPainter::leftMargin() const
 {
-       return text_.leftMargin(pit_, row_);
+       return text_.leftMargin(pit_, row_.pos());
 }
 
 
@@ -482,7 +481,7 @@ void RowPainter::paintSelection()
        if ((startpit != pit_ && startrow != rit_ && is_rtl) ||
            (endpit != pit_ && endrow != rit_ && !is_rtl)) {
                pain_.fillRectangle(int(xo_ + tmpx),
-                       yo_, int(bv_.workWidth() - tmpx), h, LColor::selection);
+                       yo_, int(width_ - tmpx), h, LColor::selection);
        }
 }
 
@@ -509,7 +508,7 @@ void RowPainter::paintAppendix()
                return;
 
        // FIXME: can be just width_ ?
-       int const ww = bv_.workWidth();
+       int const ww = width_;
 
        int y = yo_;
 
@@ -545,7 +544,7 @@ void RowPainter::paintDepthBar()
        }
 
        for (Paragraph::depth_type i = 1; i <= depth; ++i) {
-               int const w = PAPER_MARGIN / 5;
+               int const w = NEST_MARGIN / 5;
                int x = int(w * i + xo_);
                // only consider the changebar space if we're drawing outer left
                if (xo_ == 0)
@@ -663,10 +662,6 @@ void RowPainter::paintFirst()
        if (parparams.startOfAppendix())
                y_top += paintAppendixStart(yo_ + y_top + 2 * defaultRowHeight());
 
-       // the top margin
-       if (text_.isFirstRow(pit_, row_) && !text_.isInInset())
-               y_top += PAPER_MARGIN;
-
        // draw the additional space if needed:
        y_top += paintLengthMarker(_("Space above"), parparams.spaceTop(),
                        yo_ + y_top);
@@ -771,7 +766,7 @@ void RowPainter::paintFirst()
                        double x = x_;
                        if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
                                x = ((is_rtl ? leftMargin() : x_)
-                                        + ww - text_.rightMargin(*pit_, *bv_.buffer())) / 2;
+                                        + ww - text_.rightMargin(*pit_)) / 2;
                                x -= font_metrics::width(str, font) / 2;
                        } else if (is_rtl) {
                                x = ww - leftMargin() -
@@ -789,11 +784,6 @@ void RowPainter::paintLast()
 {
        ParagraphParameters const & parparams = pit_->params();
        int y_bottom = row_.height() - 1;
-
-       // the bottom margin
-       if (text_.isLastRow(pit_, row_) && !text_.isInInset())
-               y_bottom -= PAPER_MARGIN;
-
        int const ww = bv_.workWidth();
 
        // draw the additional space if needed:
@@ -811,7 +801,7 @@ void RowPainter::paintLast()
                LyXFont const font = getLabelFont();
                int const size = int(0.75 * font_metrics::maxAscent(font));
                int const y = yo_ + row_.baseline() - size;
-               int x = is_rtl ? LEFT_MARGIN : ww - PAPER_MARGIN - size;
+               int x = is_rtl ? NEST_MARGIN + CHANGEBAR_MARGIN: ww - size;
 
                if (row_.fill() <= size)
                        x += (size - row_.fill() + 1) * (is_rtl ? -1 : 1);
@@ -828,7 +818,7 @@ void RowPainter::paintLast()
                string const & str = pit_->layout()->endlabelstring();
                double const x = is_rtl ?
                        x_ - font_metrics::width(str, font)
-                       : ww - text_.rightMargin(*pit_, *bv_.buffer()) - row_.fill();
+                       : ww - text_.rightMargin(*pit_) - row_.fill();
                pain_.text(int(x), yo_ + row_.baseline(), str, font);
                break;
        }
index 74a0cc099bddd5bc7991e5abba5fc894227ef591..d5e550d4921b52613e5b6dea6d7c937794cfceac 100644 (file)
@@ -61,16 +61,10 @@ using std::endl;
 using std::string;
 
 
-/// top, right, bottom pixel margin
-extern int const PAPER_MARGIN = 20;
+/// some space for drawing the 'nested' markers (in pixel)
+extern int const NEST_MARGIN = 20;
 /// margin for changebar
 extern int const CHANGEBAR_MARGIN = 10;
-/// left margin
-extern int const LEFT_MARGIN = PAPER_MARGIN + CHANGEBAR_MARGIN;
-
-
-
-int bibitemMaxWidth(BufferView *, LyXFont const &);
 
 
 namespace {
@@ -110,7 +104,7 @@ BufferView * LyXText::bv() const
 }
 
 
-void LyXText::updateRowPositions()
+void LyXText::updateParPositions()
 {
        ParagraphList::iterator pit = ownerParagraphs().begin();
        ParagraphList::iterator end = ownerParagraphs().end();
@@ -121,9 +115,9 @@ void LyXText::updateRowPositions()
 }
 
 
-int LyXText::workWidth() const
+int LyXText::textWidth() const
 {
-       return inset_owner ? inset_owner->textWidth() : bv()->workWidth();
+       return textwidth_;
 }
 
 
@@ -133,8 +127,7 @@ int LyXText::singleWidth(ParagraphList::iterator pit, pos_type pos) const
                return 0;
 
        char const c = pit->getChar(pos);
-       LyXFont const & font = getFont(pit, pos);
-       return singleWidth(pit, pos, c, font);
+       return singleWidth(pit, pos, c, getFont(pit, pos));
 }
 
 
@@ -173,7 +166,13 @@ int LyXText::singleWidth(ParagraphList::iterator pit,
 }
 
 
-int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const
+int LyXText::leftMargin(ParagraphList::iterator pit) const
+{
+       return leftMargin(pit, pit->size());
+}
+
+
+int LyXText::leftMargin(ParagraphList::iterator pit, pos_type pos) const
 {
        LyXTextClass const & tclass =
                bv()->buffer()->params().getLyXTextClass();
@@ -181,11 +180,11 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const
 
        string parindent = layout->parindent;
 
-       int x = LEFT_MARGIN;
+       int x = NEST_MARGIN + CHANGEBAR_MARGIN;
 
        x += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont());
 
-       // this is the way, LyX handles the LaTeX-Environments.
+       // This is the way LyX handles LaTeX-Environments.
        // I have had this idea very late, so it seems to be a
        // later added hack and this is true
        if (pit->getDepth() == 0) {
@@ -203,11 +202,11 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const
                ParagraphList::iterator newpar =
                        outerHook(pit, ownerParagraphs());
 
-               // make a corresponding row. Needed to call leftMargin()
-               // check wether it is a sufficent paragraph
+               // Make a corresponding row. Need to call leftMargin()
+               // to check whether it is a sufficent paragraph.
                if (newpar != ownerParagraphs().end()
                    && newpar->layout()->isEnvironment()) {
-                       x = leftMargin(newpar, Row(newpar->size()));
+                       x = leftMargin(newpar);
                }
 
                if (newpar != ownerParagraphs().end()
@@ -237,7 +236,7 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const
        case MARGIN_MANUAL:
                x += font_metrics::signedWidth(layout->labelindent, labelfont);
                // The width of an empty par, even with manual label, should be 0
-               if (!pit->empty() && row.pos() >= pit->beginOfBody()) {
+               if (!pit->empty() && pos >= pit->beginOfBody()) {
                        if (!pit->getLabelWidthString().empty()) {
                                x += font_metrics::width(pit->getLabelWidthString(),
                                               labelfont);
@@ -253,14 +252,14 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const
 
        case MARGIN_FIRST_DYNAMIC:
                if (layout->labeltype == LABEL_MANUAL) {
-                       if (row.pos() >= pit->beginOfBody()) {
+                       if (pos >= pit->beginOfBody()) {
                                x += font_metrics::signedWidth(layout->leftmargin,
                                                          labelfont);
                        } else {
                                x += font_metrics::signedWidth(layout->labelindent,
                                                          labelfont);
                        }
-               } else if (row.pos()
+               } else if (pos != 0
                           // Special case to fix problems with
                           // theorems (JMarc)
                           || (layout->labeltype == LABEL_STATIC
@@ -286,22 +285,21 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const
                RowList::iterator rit = pit->rows.begin();
                RowList::iterator end = pit->rows.end();
 #warning This is wrong.
-               int minfill = workWidth() / 2;
+               int minfill = textwidth_;
                for ( ; rit != end; ++rit)
                        if (rit->fill() < minfill)
                                minfill = rit->fill();
                x += font_metrics::signedWidth(layout->leftmargin,
                        tclass.defaultfont());
                x += minfill;
+               break;
        }
-       break;
        }
 
-       if (workWidth() > 0 && !pit->params().leftIndent().zero()) {
-               LyXLength const len = pit->params().leftIndent();
+       if (!pit->params().leftIndent().zero()) {
                int const tw = inset_owner ?
-                       inset_owner->latexTextWidth(bv()) : workWidth();
-               x += len.inPixels(tw);
+                       inset_owner->latexTextWidth(bv()) : textWidth();
+               x += pit->params().leftIndent().inPixels(tw);
        }
 
        LyXAlignment align;
@@ -312,7 +310,7 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const
                align = pit->params().align();
 
        // set the correct parindent
-       if (row.pos() == 0) {
+       if (pos == 0) {
                if ((layout->labeltype == LABEL_NO_LABEL
                     || layout->labeltype == LABEL_TOP_ENVIRONMENT
                     || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
@@ -330,9 +328,6 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const
                        BufferParams::PARSEP_INDENT)) {
                        x += font_metrics::signedWidth(parindent,
                                                  tclass.defaultfont());
-               } else if (layout->labeltype == LABEL_BIBLIO) {
-                       // ale970405 Right width for bibitems
-                       x += bibitemMaxWidth(bv(), tclass.defaultfont());
                }
        }
 
@@ -340,30 +335,26 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const
 }
 
 
-int LyXText::rightMargin(Paragraph const & par, Buffer const & buf) const
+int LyXText::rightMargin(Paragraph const & par) const
 {
-       LyXTextClass const & tclass = buf.params().getLyXTextClass();
-       LyXLayout_ptr const & layout = par.layout();
+       LyXTextClass const & tclass = bv()->buffer()->params().getLyXTextClass();
 
-       return PAPER_MARGIN
+       return 
                + font_metrics::signedWidth(tclass.rightmargin(),
                                       tclass.defaultfont())
-               + font_metrics::signedWidth(layout->rightmargin,
+               + font_metrics::signedWidth(par.layout()->rightmargin,
                                       tclass.defaultfont())
                * 4 / (par.getDepth() + 4);
 }
 
 
-int LyXText::labelEnd(ParagraphList::iterator pit, Row const & row) const
+int LyXText::labelEnd(ParagraphList::iterator pit) const
 {
        // labelEnd is only needed if the layout fills a flushleft label.
        if (pit->layout()->margintype != MARGIN_MANUAL)
                return 0;
-
-       Row tmprow = row;
-       tmprow.pos(pit->size());
        // return the beginning of the body
-       return leftMargin(pit, tmprow);
+       return leftMargin(pit);
 }
 
 
@@ -393,12 +384,8 @@ void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
                return;
        }
 
-       // maximum pixel width of a row.
-       int width = workWidth() - rightMargin(*pit, *bv()->buffer());
-//             - leftMargin(pit, row);
-
-       // inset->textWidth() returns -1 via workWidth(),
-       // but why ?
+       // maximum pixel width of a row
+       int width = textWidth() - rightMargin(*pit); // - leftMargin(pit, row);
        if (width < 0) {
                row.endpos(end);
                return;
@@ -418,7 +405,7 @@ void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
        // or the end of the par, then choose the possible break
        // nearest that.
 
-       int const left = leftMargin(pit, row);
+       int const left = leftMargin(pit, pos);
        int x = left;
 
        // pixel width since last breakpoint
@@ -438,14 +425,12 @@ void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
                }
                // Break before...
                if (i + 1 < end) {
-                       InsetOld * in = pit->getInset(i + 1);
-                       if (in && in->display()) {
+                       if (pit->isInset(i + 1) && pit->getInset(i + 1)->display()) {
                                point = i + 1;
                                break;
                        }
                        // ...and after.
-                       in = pit->getInset(i);
-                       if (in && in->display()) {
+                       if (pit->isInset(i) && pit->getInset(i)->display()) {
                                point = i + 1;
                                break;
                        }
@@ -467,7 +452,7 @@ void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
                                if (pit->isLineSeparator(i - 1))
                                        add -= singleWidth(pit, i - 1);
 
-                               add = std::max(add, labelEnd(pit, row) - x);
+                               add = std::max(add, labelEnd(pit) - x);
                                thiswidth += add;
                        }
 
@@ -477,7 +462,6 @@ void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
                        chunkwidth += thiswidth;
                }
 
-
                // break before a character that will fall off
                // the right of the row
                if (x >= width) {
@@ -489,15 +473,10 @@ void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
                                }
                        }
                        // exit on last registered breakpoint:
-#if 0
-                       // hack removed:
-                       if (i + 1 < end)
-#endif
                        break;
                }
 
-               InsetOld * in = pit->getInset(i);
-               if (!in || in->isChar()) {
+               if (!pit->isInset(i) || pit->getInset(i)->isChar()) {
                        // some insets are line separators too
                        if (pit->isLineSeparator(i)) {
                                // register breakpoint:
@@ -507,13 +486,6 @@ void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
                }
        }
 
-#if 0
-       // hack removed (connected with the #if 0 above):
-       if (point == end && i != end && x >= width) {
-               // didn't find one, break at the point we reached the edge
-               point = i + 1;
-       } else
-#endif
        if (i == end && x < width) {
                // maybe found one, but the par is short enough.
                point = end;
@@ -535,8 +507,8 @@ void LyXText::fill(ParagraphList::iterator pit, Row & row, int workwidth) const
        // get the pure distance
        pos_type const end = row.endpos();
 
-       LyXLayout_ptr const & layout = pit->layout();
-       int w = leftMargin(pit, row);
+       string labelsep = pit->layout()->labelsep;
+       int w = leftMargin(pit, row.pos());
 
        pos_type const body_pos = pit->beginOfBody();
        pos_type i = row.pos();
@@ -547,10 +519,10 @@ void LyXText::fill(ParagraphList::iterator pit, Row & row, int workwidth) const
                lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
                for ( ; i < end; ++i) {
                        if (body_pos > 0 && i == body_pos) {
-                               w += font_metrics::width(layout->labelsep, getLabelFont(pit));
+                               w += font_metrics::width(labelsep, getLabelFont(pit));
                                if (pit->isLineSeparator(i - 1))
                                        w -= singleWidth(pit, i - 1);
-                               w = max(w, labelEnd(pit, row));
+                               w = max(w, labelEnd(pit));
                        }
                        char const c = pit->getChar(i);
                        if (IsPrintable(c) && i > endPosOfFontSpan) {
@@ -563,13 +535,13 @@ void LyXText::fill(ParagraphList::iterator pit, Row & row, int workwidth) const
        }
 
        if (body_pos > 0 && body_pos >= end) {
-               w += font_metrics::width(layout->labelsep, getLabelFont(pit));
+               w += font_metrics::width(labelsep, getLabelFont(pit));
                if (end > 0 && pit->isLineSeparator(end - 1))
                        w -= singleWidth(pit, end - 1);
-               w = max(w, labelEnd(pit, row));
+               w = max(w, labelEnd(pit));
        }
 
-       int const fill = workwidth - w - rightMargin(*pit, *bv()->buffer());
+       int const fill = workwidth - w - rightMargin(*pit);
        row.fill(fill);
        row.width(workwidth - fill);
 }
@@ -682,10 +654,6 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, Row & row)
                                maxasc += bufparams.getDefSkip().inPixels(*bv());
                }
 
-               // the top margin
-               if (pit == ownerParagraphs().begin() && !isInInset())
-                       maxasc += PAPER_MARGIN;
-
                // add user added vertical space
                maxasc += getLengthMarkerHeight(*bv(), pit->params().spaceTop());
 
@@ -744,17 +712,13 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, Row & row)
 
        // is it a bottom line?
        if (row.endpos() >= pit->size()) {
-               // the bottom margin
-               ParagraphList::iterator nextpit = boost::next(pit);
-               if (nextpit == ownerParagraphs().end() && !isInInset())
-                       maxdesc += PAPER_MARGIN;
-
                // add the vertical spaces, that the user added
                maxdesc += getLengthMarkerHeight(*bv(), pit->params().spaceBottom());
 
                // and now the layout spaces, for example before and after
                // a section, or between the items of a itemize or enumerate
                // environment
+               ParagraphList::iterator nextpit = boost::next(pit);
                if (nextpit != ownerParagraphs().end()) {
                        ParagraphList::iterator cpit = pit;
                        double usual = 0;
@@ -1010,9 +974,9 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const
        bool const is_rtl =
                pit->isRightToLeftPar(bv()->buffer()->params());
        if (is_rtl)
-               x = workWidth() > 0 ? rightMargin(*pit, *bv()->buffer()) : 0;
+               x = rightMargin(*pit);
        else
-               x = workWidth() > 0 ? leftMargin(pit, row) : 0;
+               x = leftMargin(pit, row.pos());
 
        // is there a manual margin with a manual label
        LyXLayout_ptr const & layout = pit->layout();
@@ -1043,7 +1007,7 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const
        // we don't have to look at the alignment if it is ALIGN_LEFT and
        // if the row is already larger then the permitted width as then
        // we force the LEFT_ALIGN'edness!
-       } else if (int(row.width()) < workWidth()) {
+       } else if (int(row.width()) < textWidth()) {
                // is it block, flushleft or flushright?
                // set x how you need it
                int align;
@@ -1430,14 +1394,6 @@ void LyXText::backspace()
 ParagraphList::iterator LyXText::cursorPar() const
 {
        return getPar(cursor.par());
-#warning have a look at this again later.
-       // We need some method to mark the cache as invalidated when
-       // the paragraph it points get removed, for this to work.
-       if (cursor.par() != cache_pos_) {
-               cache_pos_ = cursor.par();
-               cache_par_ = getPar(cache_pos_);
-       }
-       return cache_par_;
 }
 
 
@@ -1615,19 +1571,19 @@ void LyXText::redoParagraphInternal(ParagraphList::iterator pit)
        InsetList::iterator iend = pit->insetlist.end();
        for (; ii != iend; ++ii) {
                Dimension dim;
-               MetricsInfo mi(bv(), getFont(pit, ii->pos), workWidth());
+               int const w = textWidth() - leftMargin(pit) - rightMargin(*pit);
+               MetricsInfo mi(bv(), getFont(pit, ii->pos), w);
                ii->inset->metrics(mi, dim);
        }
 
        // rebreak the paragraph
        pit->setBeginOfBody();
-       int const ww = workWidth();
        pos_type z = 0;
        do {
                Row row(z);
                rowBreakPoint(pit, row);
                z = row.endpos();
-               fill(pit, row, ww);
+               fill(pit, row, textwidth_);
                prepareToPrint(pit, row);
                setHeightOfRow(pit, row);
                row.y_offset(pit->height);
@@ -1646,14 +1602,14 @@ void LyXText::redoParagraphs(ParagraphList::iterator pit,
 {
        for ( ; pit != end; ++pit)
                redoParagraphInternal(pit);
-       updateRowPositions();
+       updateParPositions();
 }
 
 
 void LyXText::redoParagraph(ParagraphList::iterator pit)
 {
        redoParagraphInternal(pit);
-       updateRowPositions();
+       updateParPositions();
 }
 
 
@@ -1667,11 +1623,13 @@ void LyXText::fullRebreak()
 
 void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
 {
-       //lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
-       //      << " workWidth: " << workWidth() << "\nfont: " << mi.base.font << endl;
        //BOOST_ASSERT(mi.base.textwidth);
+       if (mi.base.textwidth)
+               textwidth_ = mi.base.textwidth;
+       //lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
+       //      << " textWidth: " << textWidth() << "\nfont: " << mi.base.font << endl;
 
-       // rebuild row cache. This recomputes height as well.
+       // Rebuild row cache. This recomputes height as well.
        redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
 
        width = maxParagraphWidth(ownerParagraphs());
index 63bfd4f2bf98ade8b1fe5636b03c8153e9165d90..4414a28977dd2388c48cb4a362bf6799b1a5d957 100644 (file)
@@ -70,40 +70,14 @@ using std::ostringstream;
 using std::string;
 
 
-LyXText::LyXText(BufferView * bv, InsetText * inset, bool ininset,
+LyXText::LyXText(BufferView * bv, InsetText * inset, bool in_inset,
          ParagraphList & paragraphs)
-       : height(0), width(0), inset_owner(inset), bv_owner(bv),
-         in_inset_(ininset), paragraphs_(&paragraphs), xo_(0), yo_(0),
-         cache_pos_(-1)
+       : height(0), width(0), textwidth_(bv ? bv->workWidth() : 100),
+         inset_owner(inset), bv_owner(bv),
+         in_inset_(in_inset), paragraphs_(&paragraphs), xo_(0), yo_(0)
 {}
 
 
-LyXText & LyXText::operator=(LyXText const & lt)
-{
-       // Copy all public variables
-       height = lt.height;
-       width = lt.width;
-       current_font = lt.current_font;
-       real_current_font = lt.real_current_font;
-       defaultfont_ = lt.defaultfont_;
-       inset_owner = lt.inset_owner;
-       bv_owner = lt.bv_owner;
-       bidi = lt.bidi;
-       in_inset_ = lt.in_inset_;
-       paragraphs_ = lt.paragraphs_;
-       xo_ = lt.xo_;
-       yo_ = lt.yo_;
-
-       // Copy all the private variables
-
-       // we cannot initailize a iterator with a singular iterator.
-       //cache_par_ = lt.cache_par_;
-       cache_pos_ = lt.cache_pos_;
-
-       return *this;
-}
-
-
 void LyXText::init(BufferView * bview)
 {
        bv_owner = bview;
@@ -115,7 +89,6 @@ void LyXText::init(BufferView * bview)
 
        width = 0;
        height = 0;
-       cache_pos_ = -1;
 
        current_font = getFont(beg, 0);
 
@@ -432,8 +405,6 @@ bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
                start = pit;
        }
 
-       ParagraphList::iterator pastend = boost::next(end);
-
        if (!test_only)
                recUndo(parOffset(start), parOffset(end));
 
@@ -473,7 +444,7 @@ bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
        if (test_only)
                return changed;
 
-       redoParagraphs(start, pastend);
+       redoParagraphs(start, boost::next(end));
 
        // We need to actually move the text->cursor. I don't
        // understand why ...
@@ -619,7 +590,8 @@ void LyXText::toggleFree(LyXFont const & font, bool toggleall)
        // If the mask is completely neutral, tell user
        if (font == LyXFont(LyXFont::ALL_IGNORE)) {
                // Could only happen with user style
-               bv()->owner()->message(_("No font change defined. Use Character under the Layout menu to define font change."));
+               bv()->owner()->message(_("No font change defined. "
+                       "Use Character under the Layout menu to define font change."));
                return;
        }
 
@@ -781,8 +753,7 @@ void incrementItemDepth(ParagraphList::iterator pit,
 {
        int const cur_labeltype = pit->layout()->labeltype;
 
-       if (cur_labeltype != LABEL_ENUMERATE &&
-           cur_labeltype != LABEL_ITEMIZE)
+       if (cur_labeltype != LABEL_ENUMERATE && cur_labeltype != LABEL_ITEMIZE)
                return;
 
        int const cur_depth = pit->getDepth();
@@ -1045,7 +1016,7 @@ void LyXText::insertInset(InsetOld * inset)
        // The character will not be inserted a second time
        insertChar(Paragraph::META_INSET);
        // If we enter a highly editable inset the cursor should be before
-       // the inset. After an Undo LyX tries to call inset->edit(...)
+       // the inset. After an undo LyX tries to call inset->edit(...)
        // and fails if the cursor is behind the inset and getInset
        // does not return the inset!
        if (isHighlyEditableInset(inset))
@@ -1582,7 +1553,7 @@ void LyXText::setCursorFromCoordinates(int x, int y)
        deleteEmptyParagraphMechanism(old_cursor);
 }
 
-//x,y are coordinates relative to this LyXText
+// x,y are coordinates relative to this LyXText
 void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
 {
        // Get the row first.
@@ -1601,7 +1572,6 @@ void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
 }
 
 
-
 bool LyXText::checkAndActivateInset(bool front)
 {
        if (cursor.pos() == cursorPar()->size())
index f83af3e7ed532bb69c84a87018cc6e2f0846becc..43e3eba453f626f8b5fcaa3c7a19e055d061cab4 100644 (file)
@@ -67,7 +67,6 @@ using std::vector;
 
 
 extern string current_layout;
-extern int bibitemMaxWidth(BufferView *, LyXFont const &);
 
 // the selection possible is needed, that only motion events are
 // used, where the bottom press event was on the drawing area too
@@ -458,7 +457,6 @@ bool LyXText::rtl() const
 DispatchResult LyXText::dispatch(FuncRequest const & cmd)
 {
        //lyxerr[Debug::ACTION] << "LyXText::dispatch: cmd: " << cmd << endl;
-       lyxerr << "LyXText::dispatch: cmd: " << cmd << endl;
 
        BufferView * bv = cmd.view();