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"
46 #include "frontends/Gui.h"
48 #include "insets/insetcommand.h" // ChangeRefs
49 #include "insets/insettext.h"
52 using lyx::support::bformat;
54 using lyx::cap::setSelectionRange;
62 extern BufferList bufferlist;
65 BufferView::BufferView(LyXView * owner)
66 : pimpl_(new Pimpl(*this, owner))
70 BufferView::~BufferView()
76 void BufferView::unsetXSel()
78 pimpl_->xsel_cache_.set = false;
82 Buffer * BufferView::buffer() const
84 return pimpl_->buffer_;
88 LyXView * BufferView::owner() const
90 return pimpl_->owner_;
94 void BufferView::setBuffer(Buffer * b)
100 void BufferView::newFile(string const & fn, string const & tn, bool named)
102 pimpl_->newFile(fn, tn, named);
106 bool BufferView::loadLyXFile(string const & fn, bool tl)
108 return pimpl_->loadLyXFile(fn, tl);
112 void BufferView::reload()
114 string const fn = buffer()->fileName();
115 if (bufferlist.close(buffer(), false))
120 void BufferView::resize()
123 pimpl_->resizeCurrentBuffer();
127 bool BufferView::fitCursor()
129 return pimpl_->fitCursor();
133 void BufferView::update(Update::flags flags)
135 pimpl_->update(flags);
139 void BufferView::updateScrollbar()
141 pimpl_->updateScrollbar();
145 ScrollbarParameters const & BufferView::scrollbarParameters() const
147 return pimpl_->scrollbarParameters();
151 void BufferView::scrollDocView(int value)
153 pimpl_->scrollDocView(value);
157 bool BufferView::available() const
159 return pimpl_->available();
163 Change const BufferView::getCurrentChange()
165 return pimpl_->getCurrentChange();
169 void BufferView::savePosition(unsigned int i)
171 pimpl_->savePosition(i);
175 void BufferView::restorePosition(unsigned int i)
177 pimpl_->restorePosition(i);
181 bool BufferView::isSavedPosition(unsigned int i)
183 return pimpl_->isSavedPosition(i);
186 void BufferView::saveSavedPositions()
188 return pimpl_->saveSavedPositions();
191 void BufferView::switchKeyMap()
193 pimpl_->switchKeyMap();
197 int BufferView::workWidth() const
199 return pimpl_->width();
203 void BufferView::center()
209 FuncStatus BufferView::getStatus(FuncRequest const & cmd)
211 return pimpl_->getStatus(cmd);
215 bool BufferView::dispatch(FuncRequest const & ev)
217 return pimpl_->dispatch(ev);
221 void BufferView::selectionRequested()
223 pimpl_->selectionRequested();
227 void BufferView::selectionLost()
229 pimpl_->selectionLost();
233 void BufferView::workAreaResize(int width, int height)
235 pimpl_->workAreaResize(width, height);
239 void BufferView::workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state)
241 pimpl_->workAreaKeyPress(key, state);
245 bool BufferView::workAreaDispatch(FuncRequest const & ev)
247 return pimpl_->workAreaDispatch(ev);
251 void BufferView::scroll(int lines)
253 pimpl_->scroll(lines);
257 void BufferView::showErrorList(string const & action) const
259 if (getErrorList().size()) {
260 string const title = bformat(_("%1$s Errors (%2$s)"),
261 action, buffer()->fileName());
262 owner()->getDialogs().show("errorlist", title);
263 pimpl_->errorlist_.clear();
268 ErrorList const & BufferView::getErrorList() const
270 return pimpl_->errorlist_;
274 void BufferView::setCursorFromRow(int row)
279 buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
282 text()->setCursor(cursor(), 0, 0);
284 text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), tmppos);
288 void BufferView::gotoLabel(string const & label)
290 for (InsetIterator it = inset_iterator_begin(buffer()->inset()); it; ++it) {
291 vector<string> labels;
292 it->getLabelList(*buffer(), labels);
293 if (find(labels.begin(),labels.end(),label) != labels.end()) {
302 void BufferView::hideCursor()
304 pimpl_->gui().guiCursor().hide();
307 LyXText * BufferView::getLyXText()
309 LyXText * text = cursor().innerText();
315 LyXText const * BufferView::getLyXText() const
317 LyXText const * text = cursor().innerText();
323 int BufferView::workHeight() const
325 return pimpl_->height();
329 LyXText * BufferView::text() const
331 return buffer() ? &buffer()->text() : 0;
335 void BufferView::setCursor(DocIterator const & dit)
337 size_t const n = dit.depth();
338 for (size_t i = 0; i < n; ++i)
339 dit[i].inset().edit(cursor(), true);
341 cursor().setCursor(dit);
342 cursor().selection() = false;
346 void BufferView::mouseSetCursor(LCursor & cur)
348 BOOST_ASSERT(&cur.bv() == this);
350 // Has the cursor just left the inset?
351 if (&cursor().inset() != &cur.inset())
352 cursor().inset().notifyCursorLeaves(cursor());
354 // do the dEPM magic if needed
355 if (cursor().inTexted())
356 cursor().text()->deleteEmptyParagraphMechanism(cur, cursor());
359 cursor().clearSelection();
360 cursor().setTargetX();
366 void BufferView::putSelectionAt(DocIterator const & cur,
367 int length, bool backwards)
369 cursor().clearSelection();
375 cursor().pos() += length;
376 cursor().setSelection(cursor(), -length);
378 cursor().setSelection(cursor(), length);
383 LCursor & BufferView::cursor()
385 return pimpl_->cursor_;
389 LCursor const & BufferView::cursor() const
391 return pimpl_->cursor_;
395 lyx::pit_type BufferView::anchor_ref() const
397 return pimpl_->anchor_ref_;
401 int BufferView::offset_ref() const
403 return pimpl_->offset_ref_;
407 ViewMetricsInfo const & BufferView::viewMetricsInfo()
409 return pimpl_->viewMetricsInfo();