#include "insets/insettext.h"
#include "frontends/Alert.h"
-#include "frontends/Clipboard.h"
-#include "frontends/Dialogs.h"
#include "frontends/FileDialog.h"
-#include "frontends/font_metrics.h"
-#include "frontends/Gui.h"
-#include "frontends/LyXView.h"
-#include "frontends/Selection.h"
+#include "frontends/FontMetrics.h"
#include "graphics/Previews.h"
#include <vector>
-using lyx::frontend::Clipboard;
-using lyx::frontend::Gui;
-
+using lyx::CoordCache;
using lyx::docstring;
using lyx::pos_type;
+using lyx::Point;
using lyx::support::addPath;
using lyx::support::bformat;
using std::string;
using std::vector;
-extern BufferList bufferlist;
-
+namespace Alert = lyx::frontend::Alert;
namespace {
} // anon namespace
-BufferView::BufferView(LyXView * owner)
- : owner_(owner), buffer_(0), wh_(0),
+BufferView::BufferView()
+ : buffer_(0), wh_(0),
cursor_(*this),
- multiparsel_cache_(false), anchor_ref_(0), offset_ref_(0)
+ multiparsel_cache_(false), anchor_ref_(0), offset_ref_(0),
+ intl_(new Intl)
{
xsel_cache_.set = false;
saved_positions[bm->get<0>()] = Position( bm->get<1>(), bm->get<2>(), bm->get<3>() );
// and then clear them
bmList.clear();
+
+ intl_->initKeyMapper(lyxrc.use_kbmap);
}
}
-LyXView * BufferView::owner() const
-{
- return owner_;
-}
-
-
void BufferView::setBuffer(Buffer * b)
{
lyxerr[Debug::INFO] << BOOST_CURRENT_FUNCTION
lyxerr[Debug::INFO] << BOOST_CURRENT_FUNCTION
<< " No Buffer!" << endl;
// We are closing the buffer, use the first buffer as current
- buffer_ = bufferlist.first();
+ buffer_ = theBufferList().first();
} else {
// Set current buffer
buffer_ = b;
s = filename;
// File already open?
- if (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(bufferlist.getBuffer(s));
+ setBuffer(theBufferList().getBuffer(s));
return true;
}
// FIXME: should be LFUN_REVERT
- if (!bufferlist.close(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 = bufferlist.newBuffer(s);
+ b = theBufferList().newBuffer(s);
if (!::loadLyXFile(b, s)) {
- bufferlist.release(b);
+ theBufferList().release(b);
return false;
}
} else {
void BufferView::reload()
{
string const fn = buffer_->fileName();
- if (bufferlist.close(buffer_, false))
+ if (theBufferList().close(buffer_, false))
loadLyXFile(fn);
}
bool BufferView::fitCursor()
{
if (bv_funcs::status(this, cursor_) == bv_funcs::CUR_INSIDE) {
- LyXFont const font = cursor_.getFont();
- int const asc = font_metrics::maxAscent(font);
- int const des = font_metrics::maxDescent(font);
- Point const p = bv_funcs::getPos(cursor_, cursor_.boundary());
+ lyx::frontend::FontMetrics const & fm =
+ theFontMetrics(cursor_.getFont());
+ int const asc = fm.maxAscent();
+ int const des = fm.maxDescent();
+ 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 (!buffer_->params().tracking_changes || !cursor_.selection())
+ if (!cursor_.selection())
return Change(Change::UNCHANGED);
DocIterator dit = cursor_.selectionBegin();
if (fname != buffer_->fileName()) {
Buffer * b = 0;
- if (bufferlist.exists(fname))
- b = bufferlist.getBuffer(fname);
+ if (theBufferList().exists(fname))
+ b = theBufferList().getBuffer(fname);
else {
- b = bufferlist.newBuffer(fname);
+ b = theBufferList().newBuffer(fname);
// Don't ask, just load it
::loadLyXFile(b, fname);
}
if (!lyxrc.rtl_support)
return;
- Intl & intl = owner_->getIntl();
if (getLyXText()->real_current_font.isRightToLeft()) {
- if (intl.keymap == Intl::PRIMARY)
- intl.keyMapSec();
+ if (intl_->keymap == Intl::PRIMARY)
+ intl_->keyMapSec();
} else {
- if (intl.keymap == Intl::SECONDARY)
- intl.keyMapPrim();
+ if (intl_->keymap == Intl::SECONDARY)
+ intl_->keyMapPrim();
}
}
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;
}
case LFUN_BOOKMARK_GOTO:
flag.enabled(isSavedPosition(convert<unsigned int>(lyx::to_utf8(cmd.argument()))));
break;
+
case LFUN_CHANGES_TRACK:
flag.enabled(true);
- flag.setOnOff(buffer_->params().tracking_changes);
+ flag.setOnOff(buffer_->params().trackChanges);
break;
case LFUN_CHANGES_OUTPUT: {
OutputParams runparams;
LaTeXFeatures features(*buffer_, buffer_->params(), runparams);
- flag.enabled(buffer_ && buffer_->params().tracking_changes
- && features.isAvailable("dvipost"));
- flag.setOnOff(buffer_->params().output_changes);
+ flag.enabled(buffer_ && features.isAvailable("dvipost"));
+ flag.setOnOff(buffer_->params().outputChanges);
break;
}
case LFUN_CHANGES_MERGE:
- case LFUN_CHANGE_ACCEPT: // what about these two
- case LFUN_CHANGE_REJECT: // what about these two
+ case LFUN_CHANGE_NEXT:
case LFUN_ALL_CHANGES_ACCEPT:
case LFUN_ALL_CHANGES_REJECT:
- flag.enabled(buffer_ && buffer_->params().tracking_changes);
+ flag.enabled(buffer_); // FIXME: Change tracking (MG)
break;
case LFUN_BUFFER_TOGGLE_COMPRESSION: {
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);
}
}
}
case LFUN_CHANGES_TRACK:
- trackChanges();
+ buffer_->params().trackChanges = !buffer_->params().trackChanges;
break;
case LFUN_CHANGES_OUTPUT: {
- bool const state = buffer_->params().output_changes;
- buffer_->params().output_changes = !state;
+ buffer_->params().outputChanges = !buffer_->params().outputChanges;
break;
}
+ case LFUN_CHANGE_NEXT:
+ lyx::find::findNextChange(this);
+ break;
+
case LFUN_CHANGES_MERGE:
if (lyx::find::findNextChange(this))
- owner_->getDialogs().show("changes");
+ showDialog("changes");
break;
case LFUN_ALL_CHANGES_ACCEPT: {
}
-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);
}
-int BufferView::offset_ref() const
-{
- return offset_ref_;
-}
-
-
ViewMetricsInfo const & BufferView::viewMetricsInfo()
{
return metrics_info_;
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();
if (filename.empty()) {
// Launch a file browser
+ // FIXME UNICODE
string initpath = lyxrc.document_path;
if (buffer_) {
initpath = trypath;
}
- FileDialog fileDlg(lyx::to_utf8(_("Select LyX document to insert")),
+ // FIXME UNICODE
+ FileDialog fileDlg(_("Select LyX document to insert"),
LFUN_FILE_INSERT,
- make_pair(string(lyx::to_utf8(_("Documents|#o#O"))),
- string(lyxrc.document_path)),
- make_pair(string(lyx::to_utf8(_("Examples|#E#e"))),
- string(addPath(package().system_support(), "examples"))));
+ make_pair(_("Documents|#o#O"), lyx::from_utf8(lyxrc.document_path)),
+ make_pair(_("Examples|#E#e"), lyx::from_utf8(addPath(package().system_support(), "examples"))));
FileDialog::Result result =
- fileDlg.open(initpath,
- FileFilterList(lyx::to_utf8(_("LyX Documents (*.lyx)"))),
- string());
+ fileDlg.open(lyx::from_utf8(initpath),
+ FileFilterList(_("LyX Documents (*.lyx)")),
+ docstring());
if (result.first == FileDialog::Later)
return;
- filename = result.second;
+ // FIXME UNICODE
+ filename = lyx::to_utf8(result.second);
// check selected filename
if (filename.empty()) {
buffer_->errors("Parse");
resize();
}
-
-
-void BufferView::trackChanges()
-{
- bool const tracking = buffer_->params().tracking_changes;
-
- if (!tracking) {
- for_each(buffer_->par_iterator_begin(),
- buffer_->par_iterator_end(),
- bind(&Paragraph::trackChanges, _1, Change::UNCHANGED));
- buffer_->params().tracking_changes = true;
-
- // We cannot allow undos beyond the freeze point
- buffer_->undostack().clear();
- } else {
- cursor_.setCursor(doc_iterator_begin(buffer_->inset()));
- if (lyx::find::findNextChange(this)) {
- owner_->getDialogs().show("changes");
- return;
- }
-
- for_each(buffer_->par_iterator_begin(),
- buffer_->par_iterator_end(),
- mem_fun_ref(&Paragraph::untrackChanges));
-
- buffer_->params().tracking_changes = false;
- }
-
- buffer_->redostack().clear();
-}