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;
60 extern BufferList bufferlist;
63 BufferView::BufferView(LyXView * owner, int width, int height)
64 : pimpl_(new Pimpl(*this, owner, width, height))
68 BufferView::~BufferView()
74 void BufferView::unsetXSel()
76 pimpl_->xsel_cache_.set = false;
80 Buffer * BufferView::buffer() const
82 return pimpl_->buffer_;
86 LyXScreen & BufferView::screen() const
88 return pimpl_->screen();
92 LyXView * BufferView::owner() const
94 return pimpl_->owner_;
98 Painter & BufferView::painter() const
100 return pimpl_->painter();
104 void BufferView::setBuffer(Buffer * b)
106 pimpl_->setBuffer(b);
110 void BufferView::newFile(string const & fn, string const & tn, bool named)
112 pimpl_->newFile(fn, tn, named);
116 bool BufferView::loadLyXFile(string const & fn, bool tl)
118 return pimpl_->loadLyXFile(fn, tl);
122 void BufferView::reload()
124 string const fn = buffer()->fileName();
125 if (bufferlist.close(buffer(), false))
130 void BufferView::resize()
133 pimpl_->resizeCurrentBuffer();
137 bool BufferView::fitCursor()
139 return pimpl_->fitCursor();
143 void BufferView::update(Update::flags flags)
145 pimpl_->update(flags);
149 void BufferView::updateScrollbar()
151 pimpl_->updateScrollbar();
155 void BufferView::scrollDocView(int value)
157 pimpl_->scrollDocView(value);
161 bool BufferView::available() const
163 return pimpl_->available();
167 Change const BufferView::getCurrentChange()
169 return pimpl_->getCurrentChange();
173 void BufferView::savePosition(unsigned int i)
175 pimpl_->savePosition(i);
179 void BufferView::restorePosition(unsigned int i)
181 pimpl_->restorePosition(i);
185 bool BufferView::isSavedPosition(unsigned int i)
187 return pimpl_->isSavedPosition(i);
190 void BufferView::saveSavedPositions()
192 return pimpl_->saveSavedPositions();
195 void BufferView::switchKeyMap()
197 pimpl_->switchKeyMap();
201 int BufferView::workWidth() const
203 return pimpl_->workarea().workWidth();
207 void BufferView::center()
213 string const BufferView::getClipboard() const
215 return pimpl_->workarea().getClipboard();
219 void BufferView::stuffClipboard(string const & stuff) const
221 pimpl_->stuffClipboard(stuff);
225 FuncStatus BufferView::getStatus(FuncRequest const & cmd)
227 return pimpl_->getStatus(cmd);
231 bool BufferView::dispatch(FuncRequest const & ev)
233 return pimpl_->dispatch(ev);
237 void BufferView::selectionRequested()
239 pimpl_->selectionRequested();
243 void BufferView::selectionLost()
245 pimpl_->selectionLost();
249 void BufferView::workAreaResize()
251 pimpl_->workAreaResize();
255 void BufferView::workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state)
257 pimpl_->workAreaKeyPress(key, state);
261 bool BufferView::workAreaDispatch(FuncRequest const & ev)
263 return pimpl_->workAreaDispatch(ev);
267 void BufferView::scroll(int lines)
269 pimpl_->scroll(lines);
273 void BufferView::showErrorList(string const & action) const
275 if (getErrorList().size()) {
276 string const title = bformat(_("%1$s Errors (%2$s)"),
277 action, buffer()->fileName());
278 owner()->getDialogs().show("errorlist", title);
279 pimpl_->errorlist_.clear();
284 ErrorList const & BufferView::getErrorList() const
286 return pimpl_->errorlist_;
290 void BufferView::setCursorFromRow(int row)
295 buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
298 text()->setCursor(cursor(), 0, 0);
300 text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), tmppos);
304 void BufferView::gotoLabel(string const & label)
306 for (InsetIterator it = inset_iterator_begin(buffer()->inset()); it; ++it) {
307 vector<string> labels;
308 it->getLabelList(*buffer(), labels);
309 if (find(labels.begin(),labels.end(),label) != labels.end()) {
318 void BufferView::hideCursor()
320 screen().hideCursor();
323 LyXText * BufferView::getLyXText()
325 LyXText * text = cursor().innerText();
331 LyXText const * BufferView::getLyXText() const
333 LyXText const * text = cursor().innerText();
339 void BufferView::haveSelection(bool sel)
341 pimpl_->workarea().haveSelection(sel);
345 int BufferView::workHeight() const
347 return pimpl_->workarea().workHeight();
351 LyXText * BufferView::text() const
353 return buffer() ? &buffer()->text() : 0;
357 void BufferView::setCursor(DocIterator const & dit)
359 size_t const n = dit.depth();
360 for (size_t i = 0; i < n; ++i)
361 dit[i].inset().edit(cursor(), true);
363 cursor().setCursor(dit);
364 cursor().selection() = false;
368 void BufferView::mouseSetCursor(LCursor & cur)
370 BOOST_ASSERT(&cur.bv() == this);
372 // Has the cursor just left the inset?
373 if (&cursor().inset() != &cur.inset())
374 cursor().inset().notifyCursorLeaves(cursor());
376 // do the dEPM magic if needed
377 if (cursor().inTexted())
378 cursor().text()->deleteEmptyParagraphMechanism(cur, cursor());
381 cursor().clearSelection();
382 cursor().setTargetX();
388 void BufferView::putSelectionAt(DocIterator const & cur,
389 int length, bool backwards)
391 cursor().clearSelection();
397 cursor().pos() += length;
398 cursor().setSelection(cursor(), -length);
400 cursor().setSelection(cursor(), length);
405 bool const BufferView::repaintAll() const
407 return pimpl_->repaintAll();
411 void const BufferView::repaintAll(bool r) const
413 pimpl_->repaintAll(r);
417 LCursor & BufferView::cursor()
419 return pimpl_->cursor_;
423 LCursor const & BufferView::cursor() const
425 return pimpl_->cursor_;
429 lyx::pit_type BufferView::anchor_ref() const
431 return pimpl_->anchor_ref_;
435 int BufferView::offset_ref() const
437 return pimpl_->offset_ref_;