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"
51 using lyx::support::bformat;
53 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 LyXView * BufferView::owner() const
89 return pimpl_->owner_;
93 lyx::frontend::Painter & BufferView::painter() const
95 return pimpl_->painter();
99 void BufferView::setBuffer(Buffer * b)
101 pimpl_->setBuffer(b);
105 void BufferView::newFile(string const & fn, string const & tn, bool named)
107 pimpl_->newFile(fn, tn, named);
111 bool BufferView::loadLyXFile(string const & fn, bool tl)
113 return pimpl_->loadLyXFile(fn, tl);
117 void BufferView::reload()
119 string const fn = buffer()->fileName();
120 if (bufferlist.close(buffer(), false))
125 void BufferView::resize()
128 pimpl_->resizeCurrentBuffer();
132 bool BufferView::fitCursor()
134 return pimpl_->fitCursor();
138 void BufferView::update(Update::flags flags)
140 pimpl_->update(flags);
144 void BufferView::updateScrollbar()
146 pimpl_->updateScrollbar();
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_->workarea().width();
202 void BufferView::center()
208 string const BufferView::getClipboard() const
210 return pimpl_->clipboard().get();
214 void BufferView::stuffClipboard(string const & stuff) const
216 pimpl_->stuffClipboard(stuff);
220 FuncStatus BufferView::getStatus(FuncRequest const & cmd)
222 return pimpl_->getStatus(cmd);
226 bool BufferView::dispatch(FuncRequest const & ev)
228 return pimpl_->dispatch(ev);
232 void BufferView::selectionRequested()
234 pimpl_->selectionRequested();
238 void BufferView::selectionLost()
240 pimpl_->selectionLost();
244 void BufferView::workAreaResize()
246 pimpl_->workAreaResize();
250 void BufferView::workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state)
252 pimpl_->workAreaKeyPress(key, state);
256 bool BufferView::workAreaDispatch(FuncRequest const & ev)
258 return pimpl_->workAreaDispatch(ev);
262 void BufferView::scroll(int lines)
264 pimpl_->scroll(lines);
268 void BufferView::showErrorList(string const & action) const
270 if (getErrorList().size()) {
271 string const title = bformat(_("%1$s Errors (%2$s)"),
272 action, buffer()->fileName());
273 owner()->getDialogs().show("errorlist", title);
274 pimpl_->errorlist_.clear();
279 ErrorList const & BufferView::getErrorList() const
281 return pimpl_->errorlist_;
285 void BufferView::setCursorFromRow(int row)
290 buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
293 text()->setCursor(cursor(), 0, 0);
295 text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), tmppos);
299 void BufferView::gotoLabel(string const & label)
301 for (InsetIterator it = inset_iterator_begin(buffer()->inset()); it; ++it) {
302 vector<string> labels;
303 it->getLabelList(*buffer(), labels);
304 if (find(labels.begin(),labels.end(),label) != labels.end()) {
313 void BufferView::hideCursor()
315 pimpl_->gui().guiCursor().hide();
318 LyXText * BufferView::getLyXText()
320 LyXText * text = cursor().innerText();
326 LyXText const * BufferView::getLyXText() const
328 LyXText const * text = cursor().innerText();
334 void BufferView::haveSelection(bool sel)
336 pimpl_->clipboard().haveSelection(sel);
340 int BufferView::workHeight() const
342 return pimpl_->workarea().height();
346 LyXText * BufferView::text() const
348 return buffer() ? &buffer()->text() : 0;
352 void BufferView::setCursor(DocIterator const & dit)
354 size_t const n = dit.depth();
355 for (size_t i = 0; i < n; ++i)
356 dit[i].inset().edit(cursor(), true);
358 cursor().setCursor(dit);
359 cursor().selection() = false;
363 void BufferView::mouseSetCursor(LCursor & cur)
365 BOOST_ASSERT(&cur.bv() == this);
367 // Has the cursor just left the inset?
368 if (&cursor().inset() != &cur.inset())
369 cursor().inset().notifyCursorLeaves(cursor());
371 // do the dEPM magic if needed
372 if (cursor().inTexted())
373 cursor().text()->deleteEmptyParagraphMechanism(cur, cursor());
376 cursor().clearSelection();
377 cursor().setTargetX();
383 void BufferView::putSelectionAt(DocIterator const & cur,
384 int length, bool backwards)
386 cursor().clearSelection();
392 cursor().pos() += length;
393 cursor().setSelection(cursor(), -length);
395 cursor().setSelection(cursor(), length);
400 bool const BufferView::repaintAll() const
402 return pimpl_->repaintAll();
406 void const BufferView::repaintAll(bool r) const
408 pimpl_->repaintAll(r);
412 LCursor & BufferView::cursor()
414 return pimpl_->cursor_;
418 LCursor const & BufferView::cursor() const
420 return pimpl_->cursor_;
424 lyx::pit_type BufferView::anchor_ref() const
426 return pimpl_->anchor_ref_;
430 int BufferView::offset_ref() const
432 return pimpl_->offset_ref_;