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)
// find paragraph at target position
int par_pos = d->scrollbarParameters_.min;
pit_type i = 0;
- for (; i != d->par_height_.size(); ++i) {
+ for (; i != int(d->par_height_.size()); ++i) {
par_pos += d->par_height_[i];
if (par_pos >= value)
break;
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: {
// 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);
}