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/updatableinset.h"
49 #include "insets/insettext.h"
51 using lyx::support::bformat;
53 using lyx::cap::setSelectionRange;
62 extern BufferList bufferlist;
65 BufferView::BufferView(LyXView * owner, int width, int height)
66 : pimpl_(new Pimpl(*this, owner, width, height))
70 BufferView::~BufferView()
76 void BufferView::unsetXSel()
78 pimpl_->xsel_cache_.set = false;
82 Buffer * BufferView::buffer() const
84 return pimpl_->buffer_;
88 LyXScreen & BufferView::screen() const
90 return pimpl_->screen();
94 LyXView * BufferView::owner() const
96 return pimpl_->owner_;
100 Painter & BufferView::painter() const
102 return pimpl_->painter();
106 void BufferView::setBuffer(Buffer * b)
108 pimpl_->setBuffer(b);
112 void BufferView::newFile(string const & fn, string const & tn, bool named)
114 pimpl_->newFile(fn, tn, named);
118 bool BufferView::loadLyXFile(string const & fn, bool tl)
120 return pimpl_->loadLyXFile(fn, tl);
124 void BufferView::reload()
126 string const fn = buffer()->fileName();
127 if (bufferlist.close(buffer(), false))
132 void BufferView::resize()
135 pimpl_->resizeCurrentBuffer();
139 bool BufferView::fitCursor()
141 return pimpl_->fitCursor();
145 void BufferView::update(Update::flags flags)
147 pimpl_->update(flags);
151 void BufferView::updateScrollbar()
153 pimpl_->updateScrollbar();
157 void BufferView::scrollDocView(int value)
159 pimpl_->scrollDocView(value);
163 bool BufferView::available() const
165 return pimpl_->available();
169 Change const BufferView::getCurrentChange()
171 return pimpl_->getCurrentChange();
175 void BufferView::savePosition(unsigned int i)
177 pimpl_->savePosition(i);
181 void BufferView::restorePosition(unsigned int i)
183 pimpl_->restorePosition(i);
187 bool BufferView::isSavedPosition(unsigned int i)
189 return pimpl_->isSavedPosition(i);
193 void BufferView::switchKeyMap()
195 pimpl_->switchKeyMap();
199 int BufferView::workWidth() const
201 return pimpl_->workarea().workWidth();
205 void BufferView::center()
211 string const BufferView::getClipboard() const
213 return pimpl_->workarea().getClipboard();
217 void BufferView::stuffClipboard(string const & stuff) const
219 pimpl_->stuffClipboard(stuff);
223 FuncStatus BufferView::getStatus(FuncRequest const & cmd)
225 return pimpl_->getStatus(cmd);
229 bool BufferView::dispatch(FuncRequest const & ev)
231 return pimpl_->dispatch(ev);
235 void BufferView::scroll(int lines)
237 pimpl_->scroll(lines);
241 void BufferView::showErrorList(string const & action) const
243 if (getErrorList().size()) {
244 string const title = bformat(_("%1$s Errors (%2$s)"),
245 action, buffer()->fileName());
246 owner()->getDialogs().show("errorlist", title);
247 pimpl_->errorlist_.clear();
252 ErrorList const & BufferView::getErrorList() const
254 return pimpl_->errorlist_;
258 void BufferView::setCursorFromRow(int row)
263 buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
266 text()->setCursor(cursor(), 0, 0);
268 text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), tmppos);
272 void BufferView::gotoLabel(string const & label)
274 for (InsetIterator it = inset_iterator_begin(buffer()->inset()); it; ++it) {
275 vector<string> labels;
276 it->getLabelList(*buffer(), labels);
277 if (find(labels.begin(),labels.end(),label) != labels.end()) {
286 void BufferView::hideCursor()
288 screen().hideCursor();
291 LyXText * BufferView::getLyXText()
293 LyXText * text = cursor().innerText();
299 LyXText const * BufferView::getLyXText() const
301 LyXText const * text = cursor().innerText();
307 void BufferView::haveSelection(bool sel)
309 pimpl_->workarea().haveSelection(sel);
313 int BufferView::workHeight() const
315 return pimpl_->workarea().workHeight();
319 LyXText * BufferView::text() const
321 return buffer() ? &buffer()->text() : 0;
325 void BufferView::setCursor(DocIterator const & dit)
327 size_t const n = dit.depth();
328 for (size_t i = 0; i < n; ++i)
329 dit[i].inset().edit(cursor(), true);
331 cursor().setCursor(dit);
332 cursor().selection() = false;
336 void BufferView::putSelectionAt(DocIterator const & cur,
337 int length, bool backwards)
339 cursor().clearSelection();
345 cursor().pos() += length;
346 cursor().setSelection(cursor(), -length);
348 cursor().setSelection(cursor(), length);
353 LCursor & BufferView::cursor()
355 return pimpl_->cursor_;
359 LCursor const & BufferView::cursor() const
361 return pimpl_->cursor_;
365 lyx::pit_type BufferView::anchor_ref() const
367 return pimpl_->anchor_ref_;
371 int BufferView::offset_ref() const
373 return pimpl_->offset_ref_;