/**
* \file BufferView_pimpl.C
- * Copyright 2002 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
+ * \author Asger Alstrup
+ * \author Alfredo Braustein
* \author Lars Gullik Bjønnes
- * \author various
+ * \author Jean-Marc Lasgouttes
+ * \author Angus Leeming
+ * \author John Levon
+ * \author André Pönitz
+ * \author Dekel Tsur
+ * \author Jürgen Vigna
+ *
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "lyxrc.h"
#include "lastfiles.h"
#include "paragraph.h"
+#include "paragraph_funcs.h"
#include "ParagraphParameters.h"
#include "TextCache.h"
#include "undo_funcs.h"
}
+void BufferView::Pimpl::top_y(int y)
+{
+ top_y_ = y;
+}
+
+
+int BufferView::Pimpl::top_y() const
+{
+ return top_y_;
+}
+
+
void BufferView::Pimpl::buffer(Buffer * b)
{
lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
// set current buffer
buffer_ = b;
+ top_y_ = 0;
+
// if we're quitting lyx, don't bother updating stuff
if (quitting)
return;
resizeCurrentBuffer();
// FIXME: needed when ?
- bv_->text->top_y(screen().topCursorVisible(bv_->text));
+ top_y(screen().topCursorVisible(bv_->text));
// Buffer-dependent dialogs should be updated or
// hidden. This should go here because some dialogs (eg ToC)
textcache.show(lyxerr, "resizeCurrentBuffer");
} else {
lyxerr << "no text in cache!" << endl;
- bv_->text = new LyXText(bv_);
+ bv_->text = new LyXText(bv_, 0, false, bv_->buffer()->paragraphs);
bv_->text->init(bv_);
}
selendpar = bv_->text->ownerParagraphs().end();
}
+#warning does not help much
+ bv_->text->redoParagraphs(bv_->text->ownerParagraphs().begin(),
+ bv_->text->ownerParagraphs().end());
+
if (par != bv_->text->ownerParagraphs().end()) {
bv_->text->selection.set(true);
// At this point just to avoid the Delete-Empty-Paragraph-
bv_->theLockingInset(the_locking_inset);
}
- bv_->text->top_y(screen().topCursorVisible(bv_->text));
+ top_y(screen().topCursorVisible(bv_->text));
switchKeyMap();
owner_->busy(false);
LyXText const & t = *bv_->text;
lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", top_y() "
- << t.top_y() << ", default height " << defaultRowHeight() << endl;
+ << top_y() << ", default height " << defaultRowHeight() << endl;
- workarea().setScrollbarParams(t.height, t.top_y(), defaultRowHeight());
+ workarea().setScrollbarParams(t.height, top_y(), defaultRowHeight());
}
screen().hideCursor();
- screen().draw(bv_->text, bv_, value);
+ top_y(value);
+ screen().redraw(*bv_);
if (!lyxrc.cursor_follows_scrollbar)
return;
- LyXText * vbt = bv_->text;
-
int const height = defaultRowHeight();
- int const first = static_cast<int>((bv_->text->top_y() + height));
- int const last = static_cast<int>((bv_->text->top_y() + workarea().workHeight() - height));
+ int const first = top_y() + height;
+ int const last = top_y() + workarea().workHeight() - height;
- if (vbt->cursor.y() < first)
- vbt->setCursorFromCoordinates(0, first);
- else if (vbt->cursor.y() > last)
- vbt->setCursorFromCoordinates(0, last);
+ LyXText * text = bv_->text;
+ if (text->cursor.y() < first)
+ text->setCursorFromCoordinates(0, first);
+ else if (text->cursor.y() > last)
+ text->setCursorFromCoordinates(0, last);
owner_->updateLayoutChoice();
}
int const line_height = defaultRowHeight();
// The new absolute coordinate
- int new_top_y = t->top_y() + lines * line_height;
+ int new_top_y = top_y() + lines * line_height;
// Restrict to a valid value
new_top_y = std::min(t->height - 4 * line_height, new_top_y);
scrollDocView(new_top_y);
// Update the scrollbar.
- workarea().setScrollbarParams(t->height, t->top_y(), defaultRowHeight());
+ workarea().setScrollbarParams(t->height, top_y(), defaultRowHeight());
}
text->selection.end != bv_->text->xsel_cache.end))
{
bv_->text->xsel_cache = text->selection;
- sel = text->selectionAsString(bv_->buffer(), false);
+ sel = text->selectionAsString(*bv_->buffer(), false);
} else if (!text->selection.set()) {
sel = string();
bv_->text->xsel_cache.set(false);
{
if (available()) {
screen().hideCursor();
- toggleSelection();
bv_->getLyXText()->clearSelection();
bv_->text->xsel_cache.set(false);
}
if (bv_->getLyXText()) {
// check needed to survive LyX startup
bv_->getLyXText()->redoCursor();
- fitCursor();
}
screen().redraw(*bv_);
}
if (!bv_->buffer()->params.tracking_changes)
return Change(Change::UNCHANGED);
- LyXText * t(bv_->getLyXText());
+ LyXText * text = bv_->getLyXText();
- if (!t->selection.set())
+ if (!text->selection.set())
return Change(Change::UNCHANGED);
- LyXCursor const & cur(t->selection.start);
+ LyXCursor const & cur = text->selection.start;
return cur.par()->lookupChangeFull(cur.pos());
}
void BufferView::Pimpl::beforeChange(LyXText * text)
{
- toggleSelection();
text->clearSelection();
}
}
-void BufferView::Pimpl::toggleSelection(bool b)
-{
- screen().toggleSelection(bv_->text, bv_, b);
-}
-
-
void BufferView::Pimpl::center()
{
- LyXText * t = bv_->text;
+ LyXText * text = bv_->text;
- beforeChange(t);
+ beforeChange(text);
int const half_height = workarea().workHeight() / 2;
- int new_y = 0;
-
- if (t->cursor.y() > half_height)
- new_y = t->cursor.y() - half_height;
+ int new_y = std::max(0, text->cursor.y() - half_height);
// FIXME: look at this comment again ...
// and also might have moved top_y() must make sure to call
// updateScrollbar() currently. Never mind that this is a
// pretty obfuscated way of updating t->top_y()
- screen().draw(t, bv_, new_y);
-
+ top_y(new_y);
+ //screen().draw();
update();
}
return it != buffer_->inset_iterator_end() ? (*it) : 0;
#else
// Ok, this is a little bit too brute force but it
- // should work for now. Better infrastructure is comming. (Lgb)
+ // should work for now. Better infrastructure is coming. (Lgb)
Buffer * b = bv_->buffer();
LyXCursor cursor = bv_->getLyXText()->cursor;
screen().hideCursor();
bool const res = dispatch(ev);
-
+
// see workAreaKeyPress
cursor_timeout.restart();
screen().showCursor(*bv_);
case LFUN_INSET_INSERT: {
InsetOld * inset = createInset(ev);
if (inset && insertInset(inset)) {
- updateInset();
+ updateInset(inset);
string const name = ev.getArg(0);
if (name == "bibitem") {
// We need to do a redraw because the maximum
// InsetBibitem width could have changed
- bv_->fitCursor();
#warning check whether the update() is needed at all
bv_->update();
}
break;
case LFUN_LAYOUT_PARAGRAPH: {
- Paragraph const * par = &*bv_->getLyXText()->cursor.par();
- if (!par)
- break;
-
string data;
- params2string(*par, data);
+ params2string(*bv_->getLyXText()->cursor.par(), data);
data = "show\n" + data;
bv_->owner()->getDialogs().show("paragraph", data);
string arg = ev.argument;
if (arg.empty()) {
- arg = bv_->getLyXText()->selectionAsString(buffer_,
+ arg = bv_->getLyXText()->selectionAsString(*buffer_,
false);
// FIXME
if (arg.size() > 100 || arg.empty()) {
// Get word or selection
bv_->getLyXText()->selectWordWhenUnderCursor(lyx::WHOLE_WORD);
- arg = bv_->getLyXText()->selectionAsString(buffer_, false);
+ arg = bv_->getLyXText()->selectionAsString(*buffer_, false);
// FIXME: where is getLyXText()->unselect(bv_) ?
}
}
}
-void BufferView::Pimpl::updateInset()
+void BufferView::Pimpl::updateInset(InsetOld const * inset)
{
if (!available())
return;
+ bv_->text->redoParagraph(outerPar(*bv_->buffer(), inset));
+
// this should not be needed, but it is...
- bv_->text->redoParagraph(bv_->text->cursor.par());
+ // bv_->text->redoParagraph(bv_->text->cursor.par());
+ // bv_->text->fullRebreak();
update();
updateScrollbar();