]> git.lyx.org Git - lyx.git/blobdiff - src/TextMetrics.cpp
make index label translatable
[lyx.git] / src / TextMetrics.cpp
index 9ea86744566b2873085e9836ffe7618b9d4cc61e..0ccfa67026707d92bbfdcba47fcd13cb6ef7c336 100644 (file)
@@ -49,6 +49,7 @@ using std::make_pair;
 using std::max;
 using std::min;
 using std::endl;
+using std::pair;
 
 namespace lyx {
 
@@ -138,6 +139,21 @@ ParagraphMetrics const & TextMetrics::parMetrics(pit_type pit) const
 }
 
 
+
+pair<pit_type, ParagraphMetrics> const & TextMetrics::first() const
+{
+       pair<pit_type, ParagraphMetrics> const & pm = *par_metrics_.begin();
+       return pm;
+}
+
+
+pair<pit_type, ParagraphMetrics> const & TextMetrics::last() const
+{
+       pair<pit_type, ParagraphMetrics> const & pm = *par_metrics_.rbegin();
+       return pm;
+}
+
+
 ParagraphMetrics & TextMetrics::parMetrics(pit_type pit,
                bool redo)
 {
@@ -153,6 +169,19 @@ ParagraphMetrics & TextMetrics::parMetrics(pit_type pit,
 }
 
 
+int TextMetrics::parPosition(pit_type pit) const
+{
+       pair<pit_type, ParagraphMetrics> first = *par_metrics_.begin();
+       pair<pit_type, ParagraphMetrics> last = *par_metrics_.rbegin();
+       if (pit < first.first)
+                       return -1000000;
+       else if (pit > last.first)
+               return +1000000;
+
+       return par_metrics_[pit].position();
+}
+
+
 bool TextMetrics::metrics(MetricsInfo & mi, Dimension & dim)
 {
        BOOST_ASSERT(mi.base.textwidth);
@@ -1139,6 +1168,33 @@ pos_type TextMetrics::x2pos(pit_type pit, int row, int x) const
 }
 
 
+void TextMetrics::newParMetricsDown()
+{
+       pair<pit_type, ParagraphMetrics> const & last = *par_metrics_.rbegin();
+       pit_type const pit = last.first + 1;
+       if (pit == text_->paragraphs().size())
+               return;
+
+       // do it and update its position.
+       redoParagraph(pit);
+       par_metrics_[pit].setPosition(last.second.position()
+               + last.second.descent());
+}
+
+
+void TextMetrics::newParMetricsUp()
+{
+       pair<pit_type, ParagraphMetrics> const & first = *par_metrics_.begin();
+       if (first.first == 0)
+               return;
+
+       pit_type const pit = first.first - 1;
+       // do it and update its position.
+       redoParagraph(pit);
+       par_metrics_[pit].setPosition(first.second.position()
+               - first.second.ascent());
+}
+
 // y is screen coordinate
 pit_type TextMetrics::getPitNearY(int y)
 {