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"
47 #include "insets/insetcommand.h" // ChangeRefs
48 #include "insets/insettext.h"
51 using lyx::support::bformat;
53 using lyx::cap::setSelectionRange;
61 extern BufferList bufferlist;
64 BufferView::BufferView(LyXView * owner)
65 : pimpl_(new Pimpl(*this, owner))
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 void BufferView::setBuffer(Buffer * b)
99 void BufferView::newFile(string const & fn, string const & tn, bool named)
101 pimpl_->newFile(fn, tn, named);
105 bool BufferView::loadLyXFile(string const & fn, bool tl)
107 return pimpl_->loadLyXFile(fn, tl);
111 void BufferView::reload()
113 string const fn = buffer()->fileName();
114 if (bufferlist.close(buffer(), false))
119 void BufferView::resize()
122 pimpl_->resizeCurrentBuffer();
126 bool BufferView::fitCursor()
128 return pimpl_->fitCursor();
132 void BufferView::update(Update::flags flags)
134 pimpl_->update(flags);
138 void BufferView::updateScrollbar()
140 pimpl_->updateScrollbar();
144 ScrollbarParameters const & BufferView::scrollbarParameters() const
146 return pimpl_->scrollbarParameters();
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_->width();
202 void BufferView::center()
208 FuncStatus BufferView::getStatus(FuncRequest const & cmd)
210 return pimpl_->getStatus(cmd);
214 bool BufferView::dispatch(FuncRequest const & ev)
216 return pimpl_->dispatch(ev);
220 void BufferView::selectionRequested()
222 pimpl_->selectionRequested();
226 void BufferView::selectionLost()
228 pimpl_->selectionLost();
232 void BufferView::workAreaResize(int width, int height)
234 pimpl_->workAreaResize(width, height);
238 void BufferView::workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state)
240 pimpl_->workAreaKeyPress(key, state);
244 bool BufferView::workAreaDispatch(FuncRequest const & ev)
246 return pimpl_->workAreaDispatch(ev);
250 void BufferView::scroll(int lines)
252 pimpl_->scroll(lines);
256 void BufferView::showErrorList(string const & action) const
258 if (getErrorList().size()) {
259 string const title = bformat(_("%1$s Errors (%2$s)"),
260 action, buffer()->fileName());
261 owner()->getDialogs().show("errorlist", title);
262 pimpl_->errorlist_.clear();
267 ErrorList const & BufferView::getErrorList() const
269 return pimpl_->errorlist_;
273 void BufferView::setCursorFromRow(int row)
278 buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
281 text()->setCursor(cursor(), 0, 0);
283 text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), tmppos);
287 void BufferView::gotoLabel(string const & label)
289 for (InsetIterator it = inset_iterator_begin(buffer()->inset()); it; ++it) {
290 vector<string> labels;
291 it->getLabelList(*buffer(), labels);
292 if (find(labels.begin(),labels.end(),label) != labels.end()) {
301 void BufferView::hideCursor()
303 pimpl_->gui().guiCursor().hide();
306 LyXText * BufferView::getLyXText()
308 LyXText * text = cursor().innerText();
314 LyXText const * BufferView::getLyXText() const
316 LyXText const * text = cursor().innerText();
322 int BufferView::workHeight() const
324 return pimpl_->height();
328 LyXText * BufferView::text() const
330 return buffer() ? &buffer()->text() : 0;
334 void BufferView::setCursor(DocIterator const & dit)
336 size_t const n = dit.depth();
337 for (size_t i = 0; i < n; ++i)
338 dit[i].inset().edit(cursor(), true);
340 cursor().setCursor(dit);
341 cursor().selection() = false;
345 void BufferView::mouseSetCursor(LCursor & cur)
347 BOOST_ASSERT(&cur.bv() == this);
349 // Has the cursor just left the inset?
350 if (&cursor().inset() != &cur.inset())
351 cursor().inset().notifyCursorLeaves(cursor());
353 // do the dEPM magic if needed
354 if (cursor().inTexted())
355 cursor().text()->deleteEmptyParagraphMechanism(cur, cursor());
358 cursor().clearSelection();
359 cursor().setTargetX();
365 void BufferView::putSelectionAt(DocIterator const & cur,
366 int length, bool backwards)
368 cursor().clearSelection();
374 cursor().pos() += length;
375 cursor().setSelection(cursor(), -length);
377 cursor().setSelection(cursor(), length);
382 LCursor & BufferView::cursor()
384 return pimpl_->cursor_;
388 LCursor const & BufferView::cursor() const
390 return pimpl_->cursor_;
394 lyx::pit_type BufferView::anchor_ref() const
396 return pimpl_->anchor_ref_;
400 int BufferView::offset_ref() const
402 return pimpl_->offset_ref_;