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"
40 #include "metricsinfo.h"
42 #include "frontends/Alert.h"
43 #include "frontends/Clipboard.h"
44 #include "frontends/Dialogs.h"
45 #include "frontends/LyXView.h"
47 #include "insets/insetcommand.h" // ChangeRefs
48 #include "insets/insettext.h"
51 using lyx::support::bformat;
53 using lyx::cap::setSelectionRange;
61 extern BufferList bufferlist;
64 BufferView::BufferView(LyXView * owner)
65 : pimpl_(new Pimpl(*this, owner))
69 BufferView::~BufferView()
75 void BufferView::unsetXSel()
77 pimpl_->xsel_cache_.set = false;
81 Buffer * BufferView::buffer() const
83 return pimpl_->buffer_;
87 LyXView * BufferView::owner() const
89 return pimpl_->owner_;
93 void BufferView::setBuffer(Buffer * b)
99 string BufferView::firstLayout()
101 return pimpl_->firstLayout();
105 bool BufferView::loadLyXFile(string const & fn, bool tl)
107 return pimpl_->loadLyXFile(fn, tl);
111 void BufferView::reload()
113 string const fn = buffer()->fileName();
114 if (bufferlist.close(buffer(), false))
119 void BufferView::resize()
122 pimpl_->resizeCurrentBuffer();
126 bool BufferView::fitCursor()
128 return pimpl_->fitCursor();
132 bool BufferView::update(Update::flags flags)
134 return pimpl_->update(flags);
138 void BufferView::updateScrollbar()
140 pimpl_->updateScrollbar();
144 ScrollbarParameters const & BufferView::scrollbarParameters() const
146 return pimpl_->scrollbarParameters();
150 void BufferView::scrollDocView(int value)
152 pimpl_->scrollDocView(value);
156 bool BufferView::available() const
158 return pimpl_->available();
162 Change const BufferView::getCurrentChange()
164 return pimpl_->getCurrentChange();
168 void BufferView::savePosition(unsigned int i)
170 pimpl_->savePosition(i);
174 void BufferView::restorePosition(unsigned int i)
176 pimpl_->restorePosition(i);
180 bool BufferView::isSavedPosition(unsigned int i)
182 return pimpl_->isSavedPosition(i);
185 void BufferView::saveSavedPositions()
187 return pimpl_->saveSavedPositions();
190 void BufferView::switchKeyMap()
192 pimpl_->switchKeyMap();
196 int BufferView::workWidth() const
198 return pimpl_->width();
202 void BufferView::center()
208 FuncStatus BufferView::getStatus(FuncRequest const & cmd)
210 return pimpl_->getStatus(cmd);
214 bool BufferView::dispatch(FuncRequest const & ev)
216 return pimpl_->dispatch(ev);
220 void BufferView::selectionRequested()
222 pimpl_->selectionRequested();
226 void BufferView::selectionLost()
228 pimpl_->selectionLost();
232 void BufferView::workAreaResize(int width, int height)
234 pimpl_->workAreaResize(width, height);
238 void BufferView::workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state)
240 pimpl_->workAreaKeyPress(key, state);
244 bool BufferView::workAreaDispatch(FuncRequest const & ev)
246 return pimpl_->workAreaDispatch(ev);
250 void BufferView::scroll(int lines)
252 pimpl_->scroll(lines);
256 void BufferView::showErrorList(string const & action) const
258 if (getErrorList().size()) {
259 string const title = bformat(_("%1$s Errors (%2$s)"),
260 action, buffer()->fileName());
261 owner()->getDialogs().show("errorlist", title);
262 pimpl_->errorlist_.clear();
267 ErrorList const & BufferView::getErrorList() const
269 return pimpl_->errorlist_;
273 void BufferView::setCursorFromRow(int row)
278 buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
281 text()->setCursor(cursor(), 0, 0);
283 text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), tmppos);
287 void BufferView::gotoLabel(string const & label)
289 for (InsetIterator it = inset_iterator_begin(buffer()->inset()); it; ++it) {
290 vector<string> labels;
291 it->getLabelList(*buffer(), labels);
292 if (find(labels.begin(),labels.end(),label) != labels.end()) {
301 LyXText * BufferView::getLyXText()
303 LyXText * text = cursor().innerText();
309 LyXText const * BufferView::getLyXText() const
311 LyXText const * text = cursor().innerText();
317 int BufferView::workHeight() const
319 return pimpl_->height();
323 LyXText * BufferView::text() const
325 return buffer() ? &buffer()->text() : 0;
329 void BufferView::setCursor(DocIterator const & dit)
331 size_t const n = dit.depth();
332 for (size_t i = 0; i < n; ++i)
333 dit[i].inset().edit(cursor(), true);
335 cursor().setCursor(dit);
336 cursor().selection() = false;
340 void BufferView::mouseSetCursor(LCursor & cur)
342 BOOST_ASSERT(&cur.bv() == this);
344 // Has the cursor just left the inset?
345 if (&cursor().inset() != &cur.inset())
346 cursor().inset().notifyCursorLeaves(cursor());
348 // do the dEPM magic if needed
349 if (cursor().inTexted())
350 cursor().text()->deleteEmptyParagraphMechanism(cur, cursor());
353 cursor().clearSelection();
354 cursor().setTargetX();
360 void BufferView::putSelectionAt(DocIterator const & cur,
361 int length, bool backwards)
363 cursor().clearSelection();
369 cursor().pos() += length;
370 cursor().setSelection(cursor(), -length);
372 cursor().setSelection(cursor(), length);
377 LCursor & BufferView::cursor()
379 return pimpl_->cursor_;
383 LCursor const & BufferView::cursor() const
385 return pimpl_->cursor_;
389 lyx::pit_type BufferView::anchor_ref() const
391 return pimpl_->anchor_ref_;
395 int BufferView::offset_ref() const
397 return pimpl_->offset_ref_;
401 ViewMetricsInfo const & BufferView::viewMetricsInfo()
403 return pimpl_->viewMetricsInfo();
407 void BufferView::updateMetrics(bool singlepar)
409 pimpl_->updateMetrics(singlepar);