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;
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 LyXScreen & BufferView::screen() const
89 return pimpl_->screen();
93 LyXView * BufferView::owner() const
95 return pimpl_->owner_;
99 Painter & BufferView::painter() const
101 return pimpl_->painter();
105 void BufferView::setBuffer(Buffer * b)
107 pimpl_->setBuffer(b);
111 void BufferView::newFile(string const & fn, string const & tn, bool named)
113 pimpl_->newFile(fn, tn, named);
117 bool BufferView::loadLyXFile(string const & fn, bool tl)
119 return pimpl_->loadLyXFile(fn, tl);
123 void BufferView::reload()
125 string const fn = buffer()->fileName();
126 if (bufferlist.close(buffer(), false))
131 void BufferView::resize()
134 pimpl_->resizeCurrentBuffer();
138 bool BufferView::fitCursor()
140 return pimpl_->fitCursor();
144 void BufferView::update(Update::flags flags)
146 pimpl_->update(flags);
150 void BufferView::updateScrollbar()
152 pimpl_->updateScrollbar();
156 void BufferView::scrollDocView(int value)
158 pimpl_->scrollDocView(value);
162 bool BufferView::available() const
164 return pimpl_->available();
168 Change const BufferView::getCurrentChange()
170 return pimpl_->getCurrentChange();
174 void BufferView::savePosition(unsigned int i)
176 pimpl_->savePosition(i);
180 void BufferView::restorePosition(unsigned int i)
182 pimpl_->restorePosition(i);
186 bool BufferView::isSavedPosition(unsigned int i)
188 return pimpl_->isSavedPosition(i);
191 void BufferView::saveSavedPositions()
193 return pimpl_->saveSavedPositions();
196 void BufferView::switchKeyMap()
198 pimpl_->switchKeyMap();
202 int BufferView::workWidth() const
204 return pimpl_->workarea().workWidth();
208 void BufferView::center()
214 string const BufferView::getClipboard() const
216 return pimpl_->workarea().getClipboard();
220 void BufferView::stuffClipboard(string const & stuff) const
222 pimpl_->stuffClipboard(stuff);
226 FuncStatus BufferView::getStatus(FuncRequest const & cmd)
228 return pimpl_->getStatus(cmd);
232 bool BufferView::dispatch(FuncRequest const & ev)
234 return pimpl_->dispatch(ev);
238 void BufferView::selectionRequested()
240 pimpl_->selectionRequested();
244 void BufferView::selectionLost()
246 pimpl_->selectionLost();
250 void BufferView::workAreaResize()
252 pimpl_->workAreaResize();
256 void BufferView::workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state)
258 pimpl_->workAreaKeyPress(key, state);
262 bool BufferView::workAreaDispatch(FuncRequest const & ev)
264 return pimpl_->workAreaDispatch(ev);
268 void BufferView::scroll(int lines)
270 pimpl_->scroll(lines);
274 void BufferView::showErrorList(string const & action) const
276 if (getErrorList().size()) {
277 string const title = bformat(_("%1$s Errors (%2$s)"),
278 action, buffer()->fileName());
279 owner()->getDialogs().show("errorlist", title);
280 pimpl_->errorlist_.clear();
285 ErrorList const & BufferView::getErrorList() const
287 return pimpl_->errorlist_;
291 void BufferView::setCursorFromRow(int row)
296 buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
299 text()->setCursor(cursor(), 0, 0);
301 text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), tmppos);
305 void BufferView::gotoLabel(string const & label)
307 for (InsetIterator it = inset_iterator_begin(buffer()->inset()); it; ++it) {
308 vector<string> labels;
309 it->getLabelList(*buffer(), labels);
310 if (find(labels.begin(),labels.end(),label) != labels.end()) {
319 void BufferView::hideCursor()
321 screen().hideCursor();
324 LyXText * BufferView::getLyXText()
326 LyXText * text = cursor().innerText();
332 LyXText const * BufferView::getLyXText() const
334 LyXText const * text = cursor().innerText();
340 void BufferView::haveSelection(bool sel)
342 pimpl_->workarea().haveSelection(sel);
346 int BufferView::workHeight() const
348 return pimpl_->workarea().workHeight();
352 LyXText * BufferView::text() const
354 return buffer() ? &buffer()->text() : 0;
358 void BufferView::setCursor(DocIterator const & dit)
360 size_t const n = dit.depth();
361 for (size_t i = 0; i < n; ++i)
362 dit[i].inset().edit(cursor(), true);
364 cursor().setCursor(dit);
365 cursor().selection() = false;
369 void BufferView::mouseSetCursor(LCursor & cur)
371 BOOST_ASSERT(&cur.bv() == this);
373 // Has the cursor just left the inset?
374 if (&cursor().inset() != &cur.inset())
375 cursor().inset().notifyCursorLeaves(cursor());
377 // do the dEPM magic if needed
378 if (cursor().inTexted())
379 cursor().text()->deleteEmptyParagraphMechanism(cur, cursor());
382 cursor().clearSelection();
383 cursor().setTargetX();
389 void BufferView::putSelectionAt(DocIterator const & cur,
390 int length, bool backwards)
392 cursor().clearSelection();
398 cursor().pos() += length;
399 cursor().setSelection(cursor(), -length);
401 cursor().setSelection(cursor(), length);
406 bool const BufferView::repaintAll() const
408 return pimpl_->repaintAll();
412 void const BufferView::repaintAll(bool r) const
414 pimpl_->repaintAll(r);
418 LCursor & BufferView::cursor()
420 return pimpl_->cursor_;
424 LCursor const & BufferView::cursor() const
426 return pimpl_->cursor_;
430 lyx::pit_type BufferView::anchor_ref() const
432 return pimpl_->anchor_ref_;
436 int BufferView::offset_ref() const
438 return pimpl_->offset_ref_;