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"
24 #include "coordcache.h"
26 #include "funcrequest.h"
27 #include "FuncStatus.h"
29 #include "insetiterator.h"
31 #include "lyxlayout.h"
33 #include "lyxtextclass.h"
34 #include "paragraph.h"
35 #include "paragraph_funcs.h"
36 #include "pariterator.h"
39 #include "WordLangTuple.h"
41 #include "frontends/Alert.h"
42 #include "frontends/Dialogs.h"
43 #include "frontends/LyXView.h"
44 #include "frontends/screen.h"
45 #include "frontends/WorkArea.h"
47 #include "insets/insetcommand.h" // ChangeRefs
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(Update::flags flags)
146 pimpl_->update(flags);
150 void BufferView::updateScrollbar()
152 pimpl_->updateScrollbar();
156 void BufferView::scrollDocView(int value)
158 pimpl_->scrollDocView(value);
162 bool BufferView::available() const
164 return pimpl_->available();
168 Change const BufferView::getCurrentChange()
170 return pimpl_->getCurrentChange();
174 void BufferView::savePosition(unsigned int i)
176 pimpl_->savePosition(i);
180 void BufferView::restorePosition(unsigned int i)
182 pimpl_->restorePosition(i);
186 bool BufferView::isSavedPosition(unsigned int i)
188 return pimpl_->isSavedPosition(i);
192 void BufferView::switchKeyMap()
194 pimpl_->switchKeyMap();
198 int BufferView::workWidth() const
200 return pimpl_->workarea().workWidth();
204 void BufferView::center()
210 string const BufferView::getClipboard() const
212 return pimpl_->workarea().getClipboard();
216 void BufferView::stuffClipboard(string const & stuff) const
218 pimpl_->stuffClipboard(stuff);
222 FuncStatus BufferView::getStatus(FuncRequest const & cmd)
224 return pimpl_->getStatus(cmd);
228 bool BufferView::dispatch(FuncRequest const & ev)
230 return pimpl_->dispatch(ev);
234 void BufferView::scroll(int lines)
236 pimpl_->scroll(lines);
240 void BufferView::showErrorList(string const & action) const
242 if (getErrorList().size()) {
243 string const title = bformat(_("%1$s Errors (%2$s)"),
244 action, buffer()->fileName());
245 owner()->getDialogs().show("errorlist", title);
246 pimpl_->errorlist_.clear();
251 ErrorList const & BufferView::getErrorList() const
253 return pimpl_->errorlist_;
257 void BufferView::setCursorFromRow(int row)
262 buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
265 text()->setCursor(cursor(), 0, 0);
267 text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), tmppos);
271 void BufferView::gotoLabel(string const & label)
273 for (InsetIterator it = inset_iterator_begin(buffer()->inset()); it; ++it) {
274 vector<string> labels;
275 it->getLabelList(*buffer(), labels);
276 if (find(labels.begin(),labels.end(),label) != labels.end()) {
285 void BufferView::hideCursor()
287 screen().hideCursor();
290 LyXText * BufferView::getLyXText()
292 LyXText * text = cursor().innerText();
298 LyXText const * BufferView::getLyXText() const
300 LyXText const * text = cursor().innerText();
306 void BufferView::haveSelection(bool sel)
308 pimpl_->workarea().haveSelection(sel);
312 int BufferView::workHeight() const
314 return pimpl_->workarea().workHeight();
318 LyXText * BufferView::text() const
320 return buffer() ? &buffer()->text() : 0;
324 void BufferView::setCursor(DocIterator const & dit)
326 size_t const n = dit.depth();
327 for (size_t i = 0; i < n; ++i)
328 dit[i].inset().edit(cursor(), true);
330 cursor().setCursor(dit);
331 cursor().selection() = false;
335 void BufferView::putSelectionAt(DocIterator const & cur,
336 int length, bool backwards)
338 cursor().clearSelection();
344 cursor().pos() += length;
345 cursor().setSelection(cursor(), -length);
347 cursor().setSelection(cursor(), length);
352 LCursor & BufferView::cursor()
354 return pimpl_->cursor_;
358 LCursor const & BufferView::cursor() const
360 return pimpl_->cursor_;
364 lyx::pit_type BufferView::anchor_ref() const
366 return pimpl_->anchor_ref_;
370 int BufferView::offset_ref() const
372 return pimpl_->offset_ref_;