]> git.lyx.org Git - features.git/commitdiff
First step towards model/view separation of Paragraph class.
authorAbdelrazak Younes <younes@lyx.org>
Tue, 19 Dec 2006 14:27:38 +0000 (14:27 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Tue, 19 Dec 2006 14:27:38 +0000 (14:27 +0000)
- ParagraphMetrics: new class gathering everything related to metrics.
- Paragraph: now derives from ParagraphMetrics.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16335 a592a061-630c-0410-9148-cb99ea01b6c8

src/paragraph.C
src/paragraph.h

index 9aab8c122d92c5f2f11723d9fefc472d7592815d..ee256c90af60e01abd461754079e027dbada8f81 100644 (file)
@@ -69,6 +69,88 @@ using std::ostream;
 using std::ostringstream;
 
 
+ParagraphMetrics::ParagraphMetrics()
+{
+}
+
+
+ParagraphMetrics::ParagraphMetrics(ParagraphMetrics const & pm)
+       : dim_(pm.dim_), rows_(pm.rows_), rowSignature_(pm.rowSignature_)
+{
+}
+
+
+ParagraphMetrics & ParagraphMetrics::operator=(ParagraphMetrics const & pm)
+{
+       rows_ = pm.rows_;
+       dim_ = pm.dim_;
+       rowSignature_ = pm.rowSignature_;
+       return *this;
+}
+
+
+Row & ParagraphMetrics::getRow(pos_type pos, bool boundary)
+{
+       BOOST_ASSERT(!rows().empty());
+
+       // If boundary is set we should return the row on which
+       // the character before is inside.
+       if (pos > 0 && boundary)
+               --pos;
+
+       RowList::iterator rit = rows_.end();
+       RowList::iterator const begin = rows_.begin();
+
+       for (--rit; rit != begin && rit->pos() > pos; --rit)
+               ;
+
+       return *rit;
+}
+
+
+Row const & ParagraphMetrics::getRow(pos_type pos, bool boundary) const
+{
+       BOOST_ASSERT(!rows().empty());
+
+       // If boundary is set we should return the row on which
+       // the character before is inside.
+       if (pos > 0 && boundary)
+               --pos;
+
+       RowList::const_iterator rit = rows_.end();
+       RowList::const_iterator const begin = rows_.begin();
+
+       for (--rit; rit != begin && rit->pos() > pos; --rit)
+               ;
+
+       return *rit;
+}
+
+
+size_t ParagraphMetrics::pos2row(pos_type pos) const
+{
+       BOOST_ASSERT(!rows().empty());
+
+       RowList::const_iterator rit = rows_.end();
+       RowList::const_iterator const begin = rows_.begin();
+
+       for (--rit; rit != begin && rit->pos() > pos; --rit)
+               ;
+
+       return rit - begin;
+}
+
+
+void ParagraphMetrics::dump() const
+{
+       lyxerr << "Paragraph::dump: rows.size(): " << rows_.size() << endl;
+       for (size_t i = 0; i != rows_.size(); ++i) {
+               lyxerr << "  row " << i << ":   ";
+               rows_[i].dump();
+       }
+}
+
+
 Paragraph::Paragraph()
        : begin_of_body_(0), pimpl_(new Paragraph::Pimpl(this))
 {
@@ -78,12 +160,11 @@ Paragraph::Paragraph()
 
 
 Paragraph::Paragraph(Paragraph const & par)
-       :       itemdepth(par.itemdepth), insetlist(par.insetlist),
-               dim_(par.dim_),
-               rows_(par.rows_), rowSignature_(par.rowSignature_),
-               layout_(par.layout_),
-               text_(par.text_), begin_of_body_(par.begin_of_body_),
-         pimpl_(new Paragraph::Pimpl(*par.pimpl_, this))
+       : ParagraphMetrics(par),
+       itemdepth(par.itemdepth), insetlist(par.insetlist),
+       layout_(par.layout_),
+       text_(par.text_), begin_of_body_(par.begin_of_body_),
+       pimpl_(new Paragraph::Pimpl(*par.pimpl_, this))
 {
        //lyxerr << "Paragraph::Paragraph(Paragraph const&)" << endl;
        InsetList::iterator it = insetlist.begin();
@@ -105,15 +186,14 @@ Paragraph & Paragraph::operator=(Paragraph const & par)
                for (; it != end; ++it)
                        it->inset = it->inset->clone().release();
 
-               rows_ = par.rows_;
-               dim_ = par.dim_;
-               rowSignature_ = par.rowSignature_;
                layout_ = par.layout();
                text_ = par.text_;
                begin_of_body_ = par.begin_of_body_;
 
                delete pimpl_;
                pimpl_ = new Pimpl(*par.pimpl_, this);
+
+               ParagraphMetrics::operator=(par);
        }
        return *this;
 }
@@ -1538,58 +1618,6 @@ bool Paragraph::allowEmpty() const
 }
 
 
-Row & Paragraph::getRow(pos_type pos, bool boundary)
-{
-       BOOST_ASSERT(!rows().empty());
-
-       // If boundary is set we should return the row on which
-       // the character before is inside.
-       if (pos > 0 && boundary)
-               --pos;
-
-       RowList::iterator rit = rows_.end();
-       RowList::iterator const begin = rows_.begin();
-
-       for (--rit; rit != begin && rit->pos() > pos; --rit)
-               ;
-
-       return *rit;
-}
-
-
-Row const & Paragraph::getRow(pos_type pos, bool boundary) const
-{
-       BOOST_ASSERT(!rows().empty());
-
-       // If boundary is set we should return the row on which
-       // the character before is inside.
-       if (pos > 0 && boundary)
-               --pos;
-
-       RowList::const_iterator rit = rows_.end();
-       RowList::const_iterator const begin = rows_.begin();
-
-       for (--rit; rit != begin && rit->pos() > pos; --rit)
-               ;
-
-       return *rit;
-}
-
-
-size_t Paragraph::pos2row(pos_type pos) const
-{
-       BOOST_ASSERT(!rows().empty());
-
-       RowList::const_iterator rit = rows_.end();
-       RowList::const_iterator const begin = rows_.begin();
-
-       for (--rit; rit != begin && rit->pos() > pos; --rit)
-               ;
-
-       return rit - begin;
-}
-
-
 char_type Paragraph::transformChar(char_type c, pos_type pos) const
 {
        if (!Encodings::is_arabic(c))
@@ -1626,16 +1654,6 @@ char_type Paragraph::transformChar(char_type c, pos_type pos) const
 }
 
 
-void Paragraph::dump() const
-{
-       lyxerr << "Paragraph::dump: rows.size(): " << rows_.size() << endl;
-       for (size_t i = 0; i != rows_.size(); ++i) {
-               lyxerr << "  row " << i << ":   ";
-               rows_[i].dump();
-       }
-}
-
-
 bool Paragraph::hfillExpansion(Row const & row, pos_type pos) const
 {
        if (!isHfill(pos))
index 951a9d537d47befa48aade5eeda55ddc1c0b8eca..5f302f4d869e8c8b0a78575468cca3298da3e87c 100644 (file)
@@ -58,9 +58,56 @@ public:
        pos_type first, last;
 };
 
+/// Helper class for Paragraph Metrics.
+/// \todo FIXME: this class deserves its own .[Ch] files.
+/// Then, the storage of such object should be done in \c BufferView 
+/// (most probably in the \c CoordCache class along \c Point objects).
+class ParagraphMetrics  {
+public:
+       ParagraphMetrics();
+       ParagraphMetrics(ParagraphMetrics const & pm);
+       ParagraphMetrics & operator=(ParagraphMetrics const & pm);
+       ///
+       Row & getRow(pos_type pos, bool boundary);
+       ///
+       Row const & getRow(pos_type pos, bool boundary) const;
+       ///
+       size_t pos2row(pos_type pos) const;
+
+       /// LyXText::redoParagraph updates this
+       Dimension & dim() { return dim_; }
+       /// total height of paragraph
+       unsigned int height() const { return dim_.height(); }
+       /// total width of paragraph, may differ from workwidth
+       unsigned int width() const { return dim_.width(); }
+       /// ascend of paragraph above baseline
+       unsigned int ascent() const { return dim_.ascent(); }
+       /// descend of paragraph below baseline
+       unsigned int descent() const { return dim_.descent(); }
+       /// LyXText updates the rows using this access point
+       RowList & rows() { return rows_; }
+       /// The painter and others use this
+       RowList const & rows() const { return rows_; }
+       ///
+       RowSignature & rowSignature() const { return rowSignature_; }
+
+       /// dump some information to lyxerr
+       void dump() const;
+
+private:
+       ///
+       mutable RowList rows_;
+       ///
+       mutable RowSignature rowSignature_;
+       /// cached dimensions of paragraph
+       Dimension dim_;
+};
+
 
 /// A Paragraph holds all text, attributes and insets in a text paragraph
-class Paragraph  {
+/// \todo FIXME: any reference to ParagraphMetrics (including inheritance)
+/// should go in order to complete the Model/View separation of this class.
+class Paragraph: public ParagraphMetrics  {
 public:
        ///
        enum {
@@ -359,49 +406,14 @@ public:
        ParagraphParameters & params();
        ///
        ParagraphParameters const & params() const;
-
-       ///
-       Row & getRow(pos_type pos, bool boundary);
-       ///
-       Row const & getRow(pos_type pos, bool boundary) const;
-       ///
-       size_t pos2row(pos_type pos) const;
-
-       /// total height of paragraph
-       unsigned int height() const { return dim_.height(); }
-       /// total width of paragraph, may differ from workwidth
-       unsigned int width() const { return dim_.width(); }
-       /// ascend of paragraph above baseline
-       unsigned int ascent() const { return dim_.ascent(); }
-       /// descend of paragraph below baseline
-       unsigned int descent() const { return dim_.descent(); }
-       /// LyXText updates the rows using this access point
-       RowList & rows() { return rows_; }
-       /// The painter and others use this
-       RowList const & rows() const { return rows_; }
-       ///
-       RowSignature & rowSignature() const { return rowSignature_; }
        ///
        bool hfillExpansion(Row const & row, pos_type pos) const;
 
-       /// LyXText::redoParagraph updates this
-       Dimension & dim() { return dim_; }
-
-       /// dump some information to lyxerr
-       void dump() const;
-
 public:
        ///
        InsetList insetlist;
 
 private:
-       /// cached dimensions of paragraph
-       Dimension dim_;
-
-       ///
-       mutable RowList rows_;
-       ///
-       mutable RowSignature rowSignature_;
 
        ///
        LyXLayout_ptr layout_;
@@ -421,7 +433,6 @@ private:
        Pimpl * pimpl_;
 };
 
-
 } // namespace lyx
 
 #endif // PARAGRAPH_H