]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
compil fix for Qt-4.2
[lyx.git] / src / BufferView.cpp
index d7e7e1655e929deb8a5642f295cebfec57c7f543..5870b0476c2bb9df485724da0c3f14815f952484 100644 (file)
@@ -69,7 +69,6 @@
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/ExceptionMessage.h"
-#include "support/FileFilterList.h"
 #include "support/filetools.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
@@ -114,7 +113,7 @@ bool findNextInset(DocIterator & dit, vector<InsetCode> const & codes,
        while (tmpdit) {
                Inset const * inset = tmpdit.nextInset();
                if (inset
-                   && find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()
+                   && std::find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()
                    && (contents.empty() ||
                    static_cast<InsetCommand const *>(inset)->getFirstNonOptParam() == contents)) {
                        dit = tmpdit;
@@ -140,7 +139,7 @@ bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
        if (same_content) {
                Inset const * inset = tmpdit.nextInset();
                if (inset
-                   && find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()) {
+                   && std::find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()) {
                        contents = static_cast<InsetCommand const *>(inset)->getFirstNonOptParam();
                }
        }
@@ -501,6 +500,13 @@ docstring BufferView::contextMenu(int x, int y) const
 
 void BufferView::scrollDocView(int value)
 {
+       int const offset = value - d->scrollbarParameters_.position;
+       // If the offset is less than 2 screen height, prefer to scroll instead.
+       if (abs(offset) <= 2 * height_) {
+               scroll(offset);
+               return;
+       }
+
        // cut off at the top
        if (value <= d->scrollbarParameters_.min) {
                DocIterator dit = doc_iterator_begin(buffer_.inset());
@@ -509,7 +515,7 @@ void BufferView::scrollDocView(int value)
                return;
        }
 
-       // cut off at the top
+       // cut off at the bottom
        if (value >= d->scrollbarParameters_.max) {
                DocIterator dit = doc_iterator_end(buffer_.inset());
                dit.backwardPos();
@@ -518,39 +524,27 @@ void BufferView::scrollDocView(int value)
                return;
        }
 
-
-       int const offset = value - d->scrollbarParameters_.position;
-       // If the offset is less than 2 screen height, prefer to scroll instead.
-       if (abs(offset) <= 2 * height_) {
-               scroll(offset);
-               return;
-       }
-
-       // find paragraph at target positin
+       // find paragraph at target position
        int par_pos = d->scrollbarParameters_.min;
-       for (size_t i = 0; i != d->par_height_.size(); ++i) {
+       pit_type i = 0;
+       for (; i != d->par_height_.size(); ++i) {
                par_pos += d->par_height_[i];
-               if (par_pos >= value) {
-                       d->anchor_pit_ = pit_type(i);
+               if (par_pos >= value)
                        break;
-               }
        }
 
-       LYXERR(Debug::SCROLLING, "value = " << value
-               << "\tanchor_ref_ = " << d->anchor_pit_
-               << "\tpar_pos = " << par_pos);
-
-       // cut off at the end of the buffer
-       if (value > par_pos) {
-               value = d->scrollbarParameters_.max;
-               d->anchor_pit_ = d->par_height_.size() - 1;
+       if (par_pos < value) {
+               // It seems we didn't find the correct pit so stay on the safe side and
+               // scroll to bottom.
+               LYXERR0("scrolling position not found!");
+               scrollDocView(d->scrollbarParameters_.max);
+               return;
        }
 
-       // set pixel offset of screen to anchor pit
-       d->anchor_ypos_ = par_pos - value;
-
-       updateMetrics();
-       buffer_.changed();
+       DocIterator dit = doc_iterator_begin(buffer_.inset());
+       dit.pit() = i;
+       LYXERR(Debug::SCROLLING, "value = " << value << " -> scroll to pit " << i);
+       showCursor(dit);
 }
 
 
@@ -1341,6 +1335,8 @@ void BufferView::clearSelection()
 
 void BufferView::resize(int width, int height)
 {
+       bool initialResize = (height_ == 0);
+       
        // Update from work area
        width_ = width;
        height_ = height;
@@ -1349,6 +1345,13 @@ void BufferView::resize(int width, int height)
        d->par_height_.clear();
 
        updateMetrics();
+
+       // view got his initial size, make sure that
+       // the cursor has a proper position
+       if (initialResize) {
+               updateScrollbar();
+               showCursor();
+       }
 }
 
 
@@ -1560,7 +1563,7 @@ void BufferView::gotoLabel(docstring const & label)
        for (InsetIterator it = inset_iterator_begin(buffer_.inset()); it; ++it) {
                vector<docstring> labels;
                it->getLabelList(buffer_, labels);
-               if (find(labels.begin(), labels.end(), label) != labels.end()) {
+               if (std::find(labels.begin(), labels.end(), label) != labels.end()) {
                        setCursor(it);
                        showCursor();
                        return;
@@ -1773,6 +1776,19 @@ void BufferView::updateMetrics()
        // Rebreak anchor paragraph.
        tm.redoParagraph(d->anchor_pit_);
        ParagraphMetrics & anchor_pm = tm.par_metrics_[d->anchor_pit_];
+       
+       // position anchor
+       if (d->anchor_pit_ == 0) {
+               int scrollRange = d->scrollbarParameters_.max - d->scrollbarParameters_.min;
+               
+               // Complete buffer visible? Then it's easy.
+               if (scrollRange == 0)
+                       d->anchor_ypos_ = anchor_pm.ascent();
+       
+               // FIXME: Some clever handling needed to show
+               // the _first_ paragraph up to the top if the cursor is
+               // in the first line.
+       }               
        anchor_pm.setPosition(d->anchor_ypos_);
 
        LYXERR(Debug::PAINTING, "metrics: "