/**
* \file BufferView.C
- * Copyright 1995-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 Alfredo Braustein
* \author Lars Gullik Bjønnes
- * \author John Levon <moz@compsoc.man.ac.uk>
+ * \author John Levon
+ * \author André Pönitz
+ * \author Jürgen Vigna
+ *
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "debug.h"
#include "gettext.h"
#include "errorlist.h"
+#include "funcrequest.h"
#include "iterators.h"
#include "language.h"
#include "lyxcursor.h"
#include "support/FileInfo.h"
#include "support/filetools.h"
-#include "support/lyxfunctional.h" // equal_1st_in_pair
#include "support/types.h"
#include "support/lyxalgo.h" // lyx_count
+#include "support/LAssert.h"
#include <fstream>
}
-void BufferView::repaint()
-{
- pimpl_->repaint();
-}
-
-
bool BufferView::fitCursor()
{
return pimpl_->fitCursor();
}
-void BufferView::update(LyXText * text, UpdateCodes f)
-{
- pimpl_->update(text, f);
-}
-
-
-void BufferView::update(UpdateCodes f)
-{
- pimpl_->update(f);
-}
-
-
void BufferView::switchKeyMap()
{
pimpl_->switchKeyMap();
}
-void BufferView::toggleSelection(bool b)
+void BufferView::center()
{
- pimpl_->toggleSelection(b);
+ pimpl_->center();
}
-void BufferView::center()
+int BufferView::top_y() const
{
- pimpl_->center();
+ return pimpl_->top_y();
}
-string const BufferView::getClipboard() const
+void BufferView::top_y(int y)
{
- return pimpl_->workarea().getClipboard();
+ pimpl_->top_y(y);
}
-void BufferView::stuffClipboard(string const & stuff) const
+string const BufferView::getClipboard() const
{
- pimpl_->stuffClipboard(stuff);
+ return pimpl_->workarea().getClipboard();
}
-BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
- BufferView::UpdateCodes uc2)
+void BufferView::stuffClipboard(string const & stuff) const
{
- return static_cast<BufferView::UpdateCodes>
- (static_cast<int>(uc1) | static_cast<int>(uc2));
+ pimpl_->stuffClipboard(stuff);
}
//
// Moved from lyx_cb.C (Lgb)
{
- if (filen.empty())
- return false;
+ Assert(!filen.empty());
string const fname = MakeAbsPath(filen);
- // check if file exist
- FileInfo const fi(fname);
-
- if (!fi.readable()) {
- string const file = MakeDisplayPath(fname, 50);
- string const text =
- bformat(_("The specified document\n%1$s\ncould not be read."), file);
- Alert::error(_("Could not read document"), text);
- return false;
- }
-
beforeChange(text);
- ifstream ifs(fname.c_str());
- if (!ifs) {
- string const file = MakeDisplayPath(fname, 50);
- string const text =
- bformat(_("Could not open the specified document %1$s\n"), file);
- Alert::error(_("Could not open file"), text);
- return false;
- }
-
- int const c = ifs.peek();
-
- LyXLex lex(0, 0);
- lex.setStream(ifs);
-
- bool res = true;
-
text->breakParagraph(buffer()->paragraphs);
- if (c == '#') {
- // FIXME: huh ? No we won't !
- lyxerr[Debug::INFO] << "Will insert file with header" << endl;
- res = buffer()->readFile(lex, fname, ParagraphList::iterator(text->cursor.par()));
- } else {
- lyxerr[Debug::INFO] << "Will insert file without header"
- << endl;
- res = buffer()->readBody(lex, ParagraphList::iterator(text->cursor.par()));
- }
+ bool res = buffer()->readFile(fname, text->cursor.par());
resize();
return res;
it != buffer()->inset_iterator_end(); ++it) {
vector<string> labels;
it->getLabelList(labels);
- if (find(labels.begin(),labels.end(),label)
- != labels.end()) {
+ if (find(labels.begin(),labels.end(),label) != labels.end()) {
beforeChange(text);
text->setCursor(it.getPar(), it.getPos());
text->selection.cursor = text->cursor;
- update(text, BufferView::SELECT);
+ update();
return;
}
}
owner()->message(_("Undo"));
beforeChange(text);
- update(text, BufferView::SELECT);
if (!textUndo(this))
owner()->message(_("No further undo information"));
- else
- update(text, BufferView::SELECT);
+ update();
switchKeyMap();
}
owner()->message(_("Redo"));
beforeChange(text);
- update(text, BufferView::SELECT);
if (!textRedo(this))
owner()->message(_("No further redo information"));
- else
- update(text, BufferView::SELECT);
+ update();
switchKeyMap();
}
beforeChange(text);
text->selection.cursor = cur;
text->selectSelectedWord();
- toggleSelection(false);
- update(text, BufferView::SELECT);
+ update();
}
beforeChange(text);
text->selectSelectedWord();
text->clearSelection();
- update(text, BufferView::SELECT);
+ update();
}
return;
LyXText * tt = getLyXText();
- update(tt, BufferView::SELECT);
- // clear the selection (if there is any)
- toggleSelection(false);
- update(tt, BufferView::SELECT);
-
- // clear the selection (if there is any)
- toggleSelection(false);
tt->replaceSelectionWithString(replacestring);
-
tt->setSelectionRange(replacestring.length());
// Go back so that replacement string is also spellchecked
- for (string::size_type i = 0; i < replacestring.length() + 1; ++i) {
+ for (string::size_type i = 0; i < replacestring.length() + 1; ++i)
tt->cursorLeft(this);
- }
- update(tt, BufferView::SELECT);
// FIXME: should be done through LFUN
buffer()->markDirty();
- fitCursor();
+ update();
}
-// End of spellchecker stuff
bool BufferView::lockInset(UpdatableInset * inset)
bool BufferView::fitLockedInsetCursor(int x, int y, int asc, int desc)
{
if (theLockingInset() && available()) {
- y += text->cursor.iy() + theLockingInset()->insetInInsetY();
+ y += text->cursor.y() + theLockingInset()->insetInInsetY();
if (screen().fitManualCursor(this, text, x, y, asc, desc)) {
updateScrollbar();
return true;
}
-void BufferView::updateInset(InsetOld * inset)
+void BufferView::updateInset(InsetOld const * inset)
{
pimpl_->updateInset(inset);
}
// How to set the cursor corretly when it.size()>1 ??
if (it.size() == 1) {
text->setCursorIntern(it.pit(), 0);
- text->redoParagraphs(text->cursor,
- boost::next(text->cursor.par()));
- text->partialRebreak();
+ text->redoParagraph(text->cursor.par());
}
}
}
}
-bool BufferView::ChangeCitationsIfUnique(string const & from, string const & to)
-{
- typedef pair<string, string> StringPair;
-
- vector<StringPair> keys;
- buffer()->fillWithBibKeys(keys);
- if (count_if(keys.begin(), keys.end(),
- lyx::equal_1st_in_pair<StringPair>(from))
- > 1)
- return false;
-
- return ChangeInsets(InsetOld::CITE_CODE, from, to);
-}
-
-
UpdatableInset * BufferView::theLockingInset() const
{
// If NULL is not allowed we should put an Assert here. (Lgb)
}
-LyXText * BufferView::getParentText(InsetOld * inset) const
-{
- if (inset->owner()) {
- LyXText * txt = inset->getLyXText(this);
- inset = inset->owner();
- while (inset && inset->getLyXText(this) == txt)
- inset = inset->owner();
- if (inset)
- return inset->getLyXText(this);
- }
- return text;
-}
-
-
Language const * BufferView::getParentLanguage(InsetOld * inset) const
{
- LyXText * text = getParentText(inset);
- return text->cursor.par()->getFontSettings(buffer()->params,
- text->cursor.pos()).language();
+ Paragraph const & par = ownerPar(*buffer(), inset);
+ return par.getFontSettings(buffer()->params,
+ par.getPositionOfInset(inset)).language();
}