]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph.h
Scons: handle the case when qt4 is in system directories
[lyx.git] / src / paragraph.h
index 14974f56954b1a9a1379d80cb91d7fc2ea6fe45e..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 {
@@ -178,8 +225,6 @@ public:
        ///
        bool empty() const { return text_.empty(); }
        ///
-       void setContentsFromPar(Paragraph const & par);
-       ///
        void clearContents();
 
        ///
@@ -198,22 +243,34 @@ public:
 
        /// is there a change within the given range ?
        bool isChanged(pos_type start, pos_type end) const;
+       /// is there an unchanged char at the given pos ?
+       bool isUnchanged(pos_type pos) const {
+               return lookupChange(pos).type == Change::UNCHANGED;
+       }
+       /// is there an insertion at the given pos ?
+       bool isInserted(pos_type pos) const {
+               return lookupChange(pos).type == Change::INSERTED;
+       }
        /// is there a deletion at the given pos ?
        bool isDeleted(pos_type pos) const {
                return lookupChange(pos).type == Change::DELETED;
        }
 
+       /// will the paragraph be physically merged with the next
+       /// one if the imaginary end-of-par character is logically deleted?
+       bool isMergedOnEndOfParDeletion(bool trackChanges) const;
+
        /// set change for the entire par
        void setChange(Change const & change);
 
        /// set change at given pos
        void setChange(pos_type pos, Change const & change);
 
-       /// accept change
-       void acceptChange(pos_type start, pos_type end);
+       /// accept changes within the given range
+       void acceptChanges(pos_type start, pos_type end);
 
-       /// reject change
-       void rejectChange(pos_type start, pos_type end);
+       /// reject changes within the given range
+       void rejectChanges(pos_type start, pos_type end);
 
        /// Paragraphs can contain "manual labels", for example, Description
        /// environment. The text for this user-editable label is stored in
@@ -231,7 +288,7 @@ public:
        docstring const getLabelWidthString() const;
        ///
        void setLabelWidthString(docstring const & s);
-       ///
+       /// Actual paragraph alignment used
        char getAlign() const;
        /// The nesting depth of a paragraph
        depth_type getDepth() const;
@@ -240,10 +297,10 @@ public:
        ///
        void applyLayout(LyXLayout_ptr const & new_layout);
 
-       /// erase the char at the given position
-       bool erase(pos_type pos, bool trackChanges);
-       /// erase the given range. Returns the number of chars actually erased
-       int erase(pos_type start, pos_type end, bool trackChanges);
+       /// (logically) erase the char at pos; return true if it was actually erased
+       bool eraseChar(pos_type pos, bool trackChanges);
+       /// (logically) erase the given range; return the number of chars actually erased
+       int eraseChars(pos_type start, pos_type end, bool trackChanges);
 
        /** Get uninstantiated font setting. Returns the difference
            between the characters font and the layoutfont.
@@ -280,15 +337,13 @@ public:
        value_type getChar(pos_type pos) const { return text_[pos]; }
        /// Get the char, but mirror all bracket characters if it is right-to-left
        value_type getUChar(BufferParams const &, pos_type pos) const;
-       /// The position must already exist.
-       void setChar(pos_type pos, value_type c);
        /// pos <= size() (there is a dummy font change at the end of each par)
        void setFont(pos_type pos, LyXFont const & font);
        /// Returns the height of the highest font in range
        LyXFont_size highestFontInRange(pos_type startpos,
                                        pos_type endpos, LyXFont_size def_size) const;
        ///
-       void insert(pos_type pos, std::string const & str,
+       void insert(pos_type pos, docstring const & str,
                    LyXFont const & font, Change const & change);
        ///
        void insertChar(pos_type pos, value_type c, bool trackChanges);
@@ -351,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_;
@@ -413,7 +433,6 @@ private:
        Pimpl * pimpl_;
 };
 
-
 } // namespace lyx
 
 #endif // PARAGRAPH_H