3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alfredo Braunstein
7 * \author Lars Gullik Bjønnes
10 * \author Jürgen Vigna
12 * Full author contact details are available in file CREDITS.
17 #include "BufferView.h"
20 #include "bufferlist.h"
21 #include "bufferparams.h"
22 #include "BufferView_pimpl.h"
23 #include "CutAndPaste.h"
25 #include "funcrequest.h"
26 #include "FuncStatus.h"
28 #include "insetiterator.h"
30 #include "lyxlayout.h"
32 #include "lyxtextclass.h"
33 #include "paragraph.h"
34 #include "paragraph_funcs.h"
35 #include "pariterator.h"
38 #include "WordLangTuple.h"
40 #include "frontends/Alert.h"
41 #include "frontends/Dialogs.h"
42 #include "frontends/LyXView.h"
43 #include "frontends/screen.h"
44 #include "frontends/WorkArea.h"
46 #include "insets/insetcommand.h" // ChangeRefs
47 #include "insets/updatableinset.h"
48 #include "insets/insettext.h"
50 using lyx::support::bformat;
52 using lyx::cap::setSelectionRange;
61 extern BufferList bufferlist;
64 BufferView::BufferView(LyXView * owner, int width, int height)
65 : pimpl_(new Pimpl(*this, owner, width, height))
69 BufferView::~BufferView()
75 void BufferView::unsetXSel()
77 pimpl_->xsel_cache_.set = false;
81 Buffer * BufferView::buffer() const
83 return pimpl_->buffer_;
87 LyXScreen & BufferView::screen() const
89 return pimpl_->screen();
93 LyXView * BufferView::owner() const
95 return pimpl_->owner_;
99 Painter & BufferView::painter() const
101 return pimpl_->painter();
105 void BufferView::setBuffer(Buffer * b)
107 pimpl_->setBuffer(b);
111 void BufferView::newFile(string const & fn, string const & tn, bool named)
113 pimpl_->newFile(fn, tn, named);
117 bool BufferView::loadLyXFile(string const & fn, bool tl)
119 return pimpl_->loadLyXFile(fn, tl);
123 void BufferView::reload()
125 string const fn = buffer()->fileName();
126 if (bufferlist.close(buffer(), false))
131 void BufferView::resize()
134 pimpl_->resizeCurrentBuffer();
138 bool BufferView::fitCursor()
140 return pimpl_->fitCursor();
144 void BufferView::update()
150 void BufferView::updateScrollbar()
152 pimpl_->updateScrollbar();
156 void BufferView::scrollDocView(int value)
158 pimpl_->scrollDocView(value);
162 void BufferView::redoCurrentBuffer()
164 pimpl_->redoCurrentBuffer();
168 bool BufferView::available() const
170 return pimpl_->available();
174 Change const BufferView::getCurrentChange()
176 return pimpl_->getCurrentChange();
180 void BufferView::savePosition(unsigned int i)
182 pimpl_->savePosition(i);
186 void BufferView::restorePosition(unsigned int i)
188 pimpl_->restorePosition(i);
192 bool BufferView::isSavedPosition(unsigned int i)
194 return pimpl_->isSavedPosition(i);
198 void BufferView::switchKeyMap()
200 pimpl_->switchKeyMap();
204 int BufferView::workWidth() const
206 return pimpl_->workarea().workWidth();
210 void BufferView::center()
216 int BufferView::top_y() const
218 return pimpl_->top_y();
222 void BufferView::top_y(int y)
228 string const BufferView::getClipboard() const
230 return pimpl_->workarea().getClipboard();
234 void BufferView::stuffClipboard(string const & stuff) const
236 pimpl_->stuffClipboard(stuff);
240 FuncStatus BufferView::getStatus(FuncRequest const & cmd)
242 return pimpl_->getStatus(cmd);
246 bool BufferView::dispatch(FuncRequest const & ev)
248 return pimpl_->dispatch(ev);
252 void BufferView::scroll(int lines)
254 pimpl_->scroll(lines);
258 void BufferView::showErrorList(string const & action) const
260 if (getErrorList().size()) {
261 string const title = bformat(_("LyX: %1$s errors (%2$s)"),
262 action, buffer()->fileName());
263 owner()->getDialogs().show("errorlist", title);
264 pimpl_->errorlist_.clear();
269 ErrorList const & BufferView::getErrorList() const
271 return pimpl_->errorlist_;
275 void BufferView::setCursorFromRow(int row)
280 buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
283 text()->setCursor(cursor(), 0, 0);
285 text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), tmppos);
289 void BufferView::gotoLabel(string const & label)
291 for (InsetIterator it = inset_iterator_begin(buffer()->inset()); it; ++it) {
292 vector<string> labels;
293 it->getLabelList(*buffer(), labels);
294 if (find(labels.begin(),labels.end(),label) != labels.end()) {
295 cursor().clearSelection();
296 text()->setCursor(cursor(), it.par(), it.pos());
297 cursor().resetAnchor();
305 void BufferView::hideCursor()
307 screen().hideCursor();
311 LyXText * BufferView::getLyXText() const
313 LyXText * text = cursor().innerText();
319 void BufferView::haveSelection(bool sel)
321 pimpl_->workarea().haveSelection(sel);
325 int BufferView::workHeight() const
327 return pimpl_->workarea().workHeight();
331 LyXText * BufferView::text() const
333 return buffer() ? &buffer()->text() : 0;
337 void BufferView::setCursor(ParIterator const & par, lyx::pos_type pos)
339 int const last = par.size();
340 for (int i = 0; i < last; ++i)
341 par[i].inset().edit(cursor(), true);
343 cursor().setCursor(makeDocIterator(par, pos));
344 cursor().selection() = false;
345 par.bottom().text()->redoParagraph(par.bottom().par());
349 void BufferView::putSelectionAt(DocIterator const & cur,
350 int length, bool backwards)
352 ParIterator par(cur);
354 cursor().clearSelection();
356 setCursor(par, cur.pos());
360 cursor().pos() += length;
361 cursor().setSelection(cursor(), -length);
363 cursor().setSelection(cursor(), length);
368 LCursor & BufferView::cursor()
370 return pimpl_->cursor_;
374 LCursor const & BufferView::cursor() const
376 return pimpl_->cursor_;