#include "insets/insettext.h"
#include "frontends/Alert.h"
-#include "frontends/Application.h"
#include "frontends/FileDialog.h"
-#include "frontends/FontLoader.h"
#include "frontends/FontMetrics.h"
#include "graphics/Previews.h"
#include <vector>
+using lyx::CoordCache;
using lyx::docstring;
using lyx::pos_type;
+using lyx::Point;
using lyx::support::addPath;
using lyx::support::bformat;
namespace Alert = lyx::frontend::Alert;
-
namespace {
unsigned int const saved_positions_num = 20;
lyxerr[Debug::INFO] << BOOST_CURRENT_FUNCTION
<< " No Buffer!" << endl;
// We are closing the buffer, use the first buffer as current
- buffer_ = theApp->bufferList().first();
+ buffer_ = theBufferList().first();
} else {
// Set current buffer
buffer_ = b;
s = filename;
// File already open?
- if (theApp->bufferList().exists(s)) {
+ if (theBufferList().exists(s)) {
docstring const file = makeDisplayPath(s, 20);
docstring text = bformat(_("The document %1$s is already "
"loaded.\n\nDo you want to revert "
text, 0, 1, _("&Revert"), _("&Switch to document"));
if (ret != 0) {
- setBuffer(theApp->bufferList().getBuffer(s));
+ setBuffer(theBufferList().getBuffer(s));
return true;
}
// FIXME: should be LFUN_REVERT
- if (!theApp->bufferList().close(theApp->bufferList().getBuffer(s), false))
+ if (!theBufferList().close(theBufferList().getBuffer(s), false))
return false;
// Fall through to new load. (Asger)
}
Buffer * b = 0;
if (found) {
- b = theApp->bufferList().newBuffer(s);
+ b = theBufferList().newBuffer(s);
if (!::loadLyXFile(b, s)) {
- theApp->bufferList().release(b);
+ theBufferList().release(b);
return false;
}
} else {
void BufferView::reload()
{
string const fn = buffer_->fileName();
- if (theApp->bufferList().close(buffer_, false))
+ if (theBufferList().close(buffer_, false))
loadLyXFile(fn);
}
bool BufferView::fitCursor()
{
if (bv_funcs::status(this, cursor_) == bv_funcs::CUR_INSIDE) {
- lyx::frontend::FontMetrics const & fm
- = theApp->fontLoader().metrics(cursor_.getFont());
+ lyx::frontend::FontMetrics const & fm =
+ theFontMetrics(cursor_.getFont());
int const asc = fm.maxAscent();
int const des = fm.maxDescent();
- Point const p = bv_funcs::getPos(cursor_, cursor_.boundary());
+ Point const p = bv_funcs::getPos(*this, cursor_, cursor_.boundary());
if (p.y_ - asc >= 0 && p.y_ + des < height_)
return false;
}
cur.clearSelection();
break;
case bv_funcs::CUR_INSIDE:
- int const y = bv_funcs::getPos(cur, cur.boundary()).y_;
+ int const y = bv_funcs::getPos(*this, cur, cur.boundary()).y_;
int const newy = min(last, max(y, first));
if (y != newy) {
cur.reset(buffer_->inset());
}
-Change const BufferView::getCurrentChange()
+Change const BufferView::getCurrentChange() const
{
if (!cursor_.selection())
return Change(Change::UNCHANGED);
if (fname != buffer_->fileName()) {
Buffer * b = 0;
- if (theApp->bufferList().exists(fname))
- b = theApp->bufferList().getBuffer(fname);
+ if (theBufferList().exists(fname))
+ b = theBufferList().getBuffer(fname);
else {
- b = theApp->bufferList().newBuffer(fname);
+ b = theBufferList().newBuffer(fname);
// Don't ask, just load it
::loadLyXFile(b, fname);
}
bot.text()->redoParagraph(pit);
Paragraph const & par = bot.text()->paragraphs()[pit];
anchor_ref_ = pit;
- offset_ref_ = bv_funcs::coordOffset(cursor_, cursor_.boundary()).y_
+ offset_ref_ = bv_funcs::coordOffset(*this, cursor_, cursor_.boundary()).y_
+ par.ascent() - height_ / 2;
}
break;
case LFUN_LABEL_GOTO: {
- string label = lyx::to_utf8(cmd.argument());
+ docstring label = cmd.argument();
if (label.empty()) {
InsetRef * inset =
getInsetByCode<InsetRef>(cursor_,
InsetBase::REF_CODE);
if (inset) {
- label = inset->getContents();
+ label = lyx::from_utf8(inset->getContents());
savePosition(0);
}
}
}
-void BufferView::gotoLabel(string const & label)
+void BufferView::gotoLabel(docstring const & label)
{
for (InsetIterator it = inset_iterator_begin(buffer_->inset()); it; ++it) {
- vector<string> labels;
+ vector<docstring> labels;
it->getLabelList(*buffer_, labels);
if (find(labels.begin(),labels.end(),label) != labels.end()) {
setCursor(it);
void BufferView::updateMetrics(bool singlepar)
{
+ // FIXME (Abdel 19/10/2006):
+ // There's something fishy in tabular. The coord_cache_ is not
+ // correctly reconstructed when a character is trying to be inserted.
+ // Not clearing out the coord_cache_ fixes the crash but I don't know
+ // what side effect this could have on other insets.
+ //
// Remove old position cache
- theCoords.clear();
+ // coord_cache_.clear();
+
LyXText & buftext = buffer_->text();
lyx::pit_type size = int(buftext.paragraphs().size());
// The coordinates of all these paragraphs are correct, cache them
int y = y1;
- CoordCache::InnerParPosCache & parPos = theCoords.parPos()[&buftext];
+ CoordCache::InnerParPosCache & parPos = coord_cache_.parPos()[&buftext];
for (lyx::pit_type pit = pit1; pit <= pit2; ++pit) {
Paragraph const & par = buftext.getPar(pit);
y += par.ascent();