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);
191 void BufferView::saveSavedPositions()
193 return pimpl_->saveSavedPositions();
196 void BufferView::switchKeyMap()
198 pimpl_->switchKeyMap();
202 int BufferView::workWidth() const
204 return pimpl_->workarea().workWidth();
208 void BufferView::center()
214 string const BufferView::getClipboard() const
216 return pimpl_->workarea().getClipboard();
220 void BufferView::stuffClipboard(string const & stuff) const
222 pimpl_->stuffClipboard(stuff);
226 FuncStatus BufferView::getStatus(FuncRequest const & cmd)
228 return pimpl_->getStatus(cmd);
232 bool BufferView::dispatch(FuncRequest const & ev)
234 return pimpl_->dispatch(ev);
238 void BufferView::scroll(int lines)
240 pimpl_->scroll(lines);
244 void BufferView::showErrorList(string const & action) const
246 if (getErrorList().size()) {
247 string const title = bformat(_("%1$s Errors (%2$s)"),
248 action, buffer()->fileName());
249 owner()->getDialogs().show("errorlist", title);
250 pimpl_->errorlist_.clear();
255 ErrorList const & BufferView::getErrorList() const
257 return pimpl_->errorlist_;
261 void BufferView::setCursorFromRow(int row)
266 buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
269 text()->setCursor(cursor(), 0, 0);
271 text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), tmppos);
275 void BufferView::gotoLabel(string const & label)
277 for (InsetIterator it = inset_iterator_begin(buffer()->inset()); it; ++it) {
278 vector<string> labels;
279 it->getLabelList(*buffer(), labels);
280 if (find(labels.begin(),labels.end(),label) != labels.end()) {
289 void BufferView::hideCursor()
291 screen().hideCursor();
294 LyXText * BufferView::getLyXText()
296 LyXText * text = cursor().innerText();
302 LyXText const * BufferView::getLyXText() const
304 LyXText const * text = cursor().innerText();
310 void BufferView::haveSelection(bool sel)
312 pimpl_->workarea().haveSelection(sel);
316 int BufferView::workHeight() const
318 return pimpl_->workarea().workHeight();
322 LyXText * BufferView::text() const
324 return buffer() ? &buffer()->text() : 0;
328 void BufferView::setCursor(DocIterator const & dit)
330 size_t const n = dit.depth();
331 for (size_t i = 0; i < n; ++i)
332 dit[i].inset().edit(cursor(), true);
334 cursor().setCursor(dit);
335 cursor().selection() = false;
339 void BufferView::mouseSetCursor(LCursor & cur)
341 BOOST_ASSERT(&cur.bv() == this);
343 // Has the cursor just left the inset?
344 if (&cursor().inset() != &cur.inset())
345 cursor().inset().notifyCursorLeaves(cursor());
347 // do the dEPM magic if needed
348 if (cursor().inTexted())
349 cursor().text()->deleteEmptyParagraphMechanism(cur, cursor());
352 cursor().clearSelection();
353 cursor().setTargetX();
359 void BufferView::putSelectionAt(DocIterator const & cur,
360 int length, bool backwards)
362 cursor().clearSelection();
368 cursor().pos() += length;
369 cursor().setSelection(cursor(), -length);
371 cursor().setSelection(cursor(), length);
376 bool const BufferView::repaintAll() const
378 return pimpl_->repaintAll();
382 void const BufferView::repaintAll(bool r) const
384 pimpl_->repaintAll(r);
388 LCursor & BufferView::cursor()
390 return pimpl_->cursor_;
394 LCursor const & BufferView::cursor() const
396 return pimpl_->cursor_;
400 lyx::pit_type BufferView::anchor_ref() const
402 return pimpl_->anchor_ref_;
406 int BufferView::offset_ref() const
408 return pimpl_->offset_ref_;