#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"
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;
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();
}
}
BufferView::BufferView(Buffer & buf)
- : width_(0), height_(0), buffer_(buf), d(new Private(*this))
+ : width_(0), height_(0), full_screen_(false), buffer_(buf), d(new Private(*this))
{
d->xsel_cache_.set = false;
d->intl_.initKeyMapper(lyxrc.use_kbmap);
delete d;
}
+// Put this user variable in lyxrc or pass it through setFullScreen()
+static int const max_row_width = 700;
+
+int BufferView::rightMargin() const
+{
+ if (!full_screen_ || width_ < max_row_width + 20)
+ return 10;
+
+ return (width_ - max_row_width) / 2;
+}
+
+
+int BufferView::leftMargin() const
+{
+ return rightMargin();
+}
+
Intl & BufferView::getIntl()
{
<< " curr par: " << d->cursor_.bottom().pit()
<< " default height " << defaultRowHeight());
- int const parsize = int(t.paragraphs().size());
+ size_t const parsize = t.paragraphs().size();
if (d->par_height_.size() != parsize) {
d->par_height_.clear();
// FIXME: We assume a default paragraph height of 2 rows. This
int top_pos = first.second->position() - first.second->ascent();
int bottom_pos = last.second->position() + last.second->descent();
bool first_visible = first.first == 0 && top_pos >= 0;
- bool last_visible = last.first == parsize - 1 && bottom_pos <= height_;
+ bool last_visible = last.first + 1 == int(parsize) && bottom_pos <= height_;
if (first_visible && last_visible) {
d->scrollbarParameters_.min = 0;
d->scrollbarParameters_.max = 0;
}
d->scrollbarParameters_.min = top_pos;
- for (size_t i = 0; i != first.first; ++i)
+ for (size_t i = 0; i != size_t(first.first); ++i)
d->scrollbarParameters_.min -= d->par_height_[i];
d->scrollbarParameters_.max = bottom_pos;
for (size_t i = last.first + 1; i != parsize; ++i)
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());
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();
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 != int(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);
}
int top_id, pos_type top_pos)
{
bool success = false;
- DocIterator doc_it;
+ DocIterator dit;
d->cursor_.clearSelection();
// This is the case for a 'live' bookmark when unique paragraph ID
// is used to track bookmarks.
if (top_id > 0) {
- ParIterator par = buffer_.getParFromID(top_id);
- if (par != buffer_.par_iterator_end()) {
- doc_it = makeDocIterator(par, min(par->size(), top_pos));
+ dit = buffer_.getParFromID(top_id);
+ if (!dit.atEnd()) {
+ dit.pos() = min(dit.paragraph().size(), top_pos);
// Some slices of the iterator may not be
// reachable (e.g. closed collapsable inset)
// so the dociterator may need to be
// shortened. Otherwise, setCursor may crash
// lyx when the cursor can not be set to these
// insets.
- size_t const n = doc_it.depth();
+ size_t const n = dit.depth();
for (size_t i = 0; i < n; ++i)
- if (doc_it[i].inset().editable() != Inset::HIGHLY_EDITABLE) {
- doc_it.resize(i);
+ if (dit[i].inset().editable() != Inset::HIGHLY_EDITABLE) {
+ dit.resize(i);
break;
}
success = true;
// restoration is inaccurate. If a bookmark was within an inset,
// it will be restored to the left of the outmost inset that contains
// the bookmark.
- if (static_cast<size_t>(bottom_pit) < buffer_.paragraphs().size()) {
- doc_it = doc_iterator_begin(buffer_.inset());
- doc_it.pit() = bottom_pit;
- doc_it.pos() = min(bottom_pos, doc_it.paragraph().size());
+ if (bottom_pit < int(buffer_.paragraphs().size())) {
+ dit = doc_iterator_begin(buffer_.inset());
+
+ dit.pit() = bottom_pit;
+ dit.pos() = min(bottom_pos, dit.paragraph().size());
success = true;
}
if (success) {
// Note: only bottom (document) level pit is set.
- setCursor(doc_it);
+ setCursor(dit);
// set the current font.
d->cursor_.setCurrentFont();
// To center the screen on this new position we need the
for (Buffer * b = &buffer_; i == 0 || b != &buffer_;
b = theBufferList().next(b)) {
- ParIterator par = b->getParFromID(id);
- if (par == b->par_iterator_end()) {
+ DocIterator dit = b->getParFromID(id);
+ if (dit.atEnd()) {
LYXERR(Debug::INFO, "No matching paragraph found! [" << id << "].");
+ ++i;
+ continue;
+ }
+ LYXERR(Debug::INFO, "Paragraph " << dit.paragraph().id()
+ << " found in buffer `"
+ << b->absFileName() << "'.");
+
+ if (b == &buffer_) {
+ // Set the cursor
+ setCursor(dit);
+ processUpdateFlags(Update::Force | Update::FitCursor);
} else {
- LYXERR(Debug::INFO, "Paragraph " << par->id()
- << " found in buffer `"
- << b->absFileName() << "'.");
-
- if (b == &buffer_) {
- // Set the cursor
- setCursor(makeDocIterator(par, 0));
- showCursor();
- } else {
- // Switch to other buffer view and resend cmd
- theLyXFunc().dispatch(FuncRequest(
- LFUN_BUFFER_SWITCH, b->absFileName()));
- theLyXFunc().dispatch(cmd);
- }
- break;
+ // Switch to other buffer view and resend cmd
+ theLyXFunc().dispatch(FuncRequest(
+ LFUN_BUFFER_SWITCH, b->absFileName()));
+ theLyXFunc().dispatch(cmd);
}
- ++i;
+ break;
}
break;
}
break;
case LFUN_WORD_FIND:
- find(this, cmd);
+ if (find(this, cmd))
+ showCursor();
+ else
+ message(_("String not found!"));
break;
case LFUN_WORD_REPLACE: {
void BufferView::resize(int width, int height)
{
+ bool initialResize = (height_ == 0);
+
// Update from work area
width_ = width;
height_ = height;
d->par_height_.clear();
updateMetrics();
+
+ // view got his initial size, make sure that
+ // the cursor has a proper position
+ if (initialResize) {
+ updateScrollbar();
+ showCursor();
+ }
}
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;
// For an example, see bug 2933:
// http://bugzilla.lyx.org/show_bug.cgi?id=2933
// The code below could maybe be moved to a DocIterator method.
- //lyxerr << "cur before " << cur <<endl;
- DocIterator dit(cur.inset());
- dit.push_back(cur.bottom());
+ //lyxerr << "cur before " << cur << endl;
+ DocIterator dit = doc_iterator_begin(cur.inset());
+ dit.bottom() = cur.bottom();
size_t i = 1;
while (i < cur.depth() && dit.nextInset() == &cur[i].inset()) {
dit.push_back(cur[i]);
} else
d->cursor_.setSelection(d->cursor_, length);
}
+ // Ensure a redraw happens in any case because the new selection could
+ // possibly be on the same screen as the previous selection.
+ processUpdateFlags(Update::Force | Update::FitCursor);
}
// 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: "