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/Clipboard.h"
43 #include "frontends/Dialogs.h"
44 #include "frontends/LyXView.h"
45 #include "frontends/Gui.h"
46 #include "frontends/WorkArea.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, lyx::frontend::WorkArea * workArea)
66 : pimpl_(new Pimpl(*this, owner, workArea))
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 lyx::frontend::Painter & BufferView::painter() const
96 return pimpl_->painter();
100 void BufferView::setBuffer(Buffer * b)
102 pimpl_->setBuffer(b);
106 void BufferView::newFile(string const & fn, string const & tn, bool named)
108 pimpl_->newFile(fn, tn, named);
112 bool BufferView::loadLyXFile(string const & fn, bool tl)
114 return pimpl_->loadLyXFile(fn, tl);
118 void BufferView::reload()
120 string const fn = buffer()->fileName();
121 if (bufferlist.close(buffer(), false))
126 void BufferView::resize()
129 pimpl_->resizeCurrentBuffer();
133 bool BufferView::fitCursor()
135 return pimpl_->fitCursor();
139 void BufferView::update(Update::flags flags)
141 pimpl_->update(flags);
145 void BufferView::updateScrollbar()
147 pimpl_->updateScrollbar();
151 ScrollbarParameters const & BufferView::scrollbarParameters() const
153 return pimpl_->scrollbarParameters();
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);
192 void BufferView::saveSavedPositions()
194 return pimpl_->saveSavedPositions();
197 void BufferView::switchKeyMap()
199 pimpl_->switchKeyMap();
203 int BufferView::workWidth() const
205 return pimpl_->width();
209 void BufferView::center()
215 FuncStatus BufferView::getStatus(FuncRequest const & cmd)
217 return pimpl_->getStatus(cmd);
221 bool BufferView::dispatch(FuncRequest const & ev)
223 return pimpl_->dispatch(ev);
227 void BufferView::selectionRequested()
229 pimpl_->selectionRequested();
233 void BufferView::selectionLost()
235 pimpl_->selectionLost();
239 void BufferView::workAreaResize(int width, int height)
241 pimpl_->workAreaResize(width, height);
245 void BufferView::workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state)
247 pimpl_->workAreaKeyPress(key, state);
251 bool BufferView::workAreaDispatch(FuncRequest const & ev)
253 return pimpl_->workAreaDispatch(ev);
257 void BufferView::scroll(int lines)
259 pimpl_->scroll(lines);
263 void BufferView::showErrorList(string const & action) const
265 if (getErrorList().size()) {
266 string const title = bformat(_("%1$s Errors (%2$s)"),
267 action, buffer()->fileName());
268 owner()->getDialogs().show("errorlist", title);
269 pimpl_->errorlist_.clear();
274 ErrorList const & BufferView::getErrorList() const
276 return pimpl_->errorlist_;
280 void BufferView::setCursorFromRow(int row)
285 buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
288 text()->setCursor(cursor(), 0, 0);
290 text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), tmppos);
294 void BufferView::gotoLabel(string const & label)
296 for (InsetIterator it = inset_iterator_begin(buffer()->inset()); it; ++it) {
297 vector<string> labels;
298 it->getLabelList(*buffer(), labels);
299 if (find(labels.begin(),labels.end(),label) != labels.end()) {
308 void BufferView::hideCursor()
310 pimpl_->gui().guiCursor().hide();
313 LyXText * BufferView::getLyXText()
315 LyXText * text = cursor().innerText();
321 LyXText const * BufferView::getLyXText() const
323 LyXText const * text = cursor().innerText();
329 int BufferView::workHeight() const
331 return pimpl_->height();
335 LyXText * BufferView::text() const
337 return buffer() ? &buffer()->text() : 0;
341 void BufferView::setCursor(DocIterator const & dit)
343 size_t const n = dit.depth();
344 for (size_t i = 0; i < n; ++i)
345 dit[i].inset().edit(cursor(), true);
347 cursor().setCursor(dit);
348 cursor().selection() = false;
352 void BufferView::mouseSetCursor(LCursor & cur)
354 BOOST_ASSERT(&cur.bv() == this);
356 // Has the cursor just left the inset?
357 if (&cursor().inset() != &cur.inset())
358 cursor().inset().notifyCursorLeaves(cursor());
360 // do the dEPM magic if needed
361 if (cursor().inTexted())
362 cursor().text()->deleteEmptyParagraphMechanism(cur, cursor());
365 cursor().clearSelection();
366 cursor().setTargetX();
372 void BufferView::putSelectionAt(DocIterator const & cur,
373 int length, bool backwards)
375 cursor().clearSelection();
381 cursor().pos() += length;
382 cursor().setSelection(cursor(), -length);
384 cursor().setSelection(cursor(), length);
389 bool const BufferView::repaintAll() const
391 return pimpl_->repaintAll();
395 void const BufferView::repaintAll(bool r) const
397 pimpl_->repaintAll(r);
401 LCursor & BufferView::cursor()
403 return pimpl_->cursor_;
407 LCursor const & BufferView::cursor() const
409 return pimpl_->cursor_;
413 lyx::pit_type BufferView::anchor_ref() const
415 return pimpl_->anchor_ref_;
419 int BufferView::offset_ref() const
421 return pimpl_->offset_ref_;