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"
40 #include "metricsinfo.h"
42 #include "frontends/Alert.h"
43 #include "frontends/Clipboard.h"
44 #include "frontends/Dialogs.h"
45 #include "frontends/LyXView.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 string BufferView::firstLayout()
101 return pimpl_->firstLayout();
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 bool BufferView::update(Update::flags flags)
134 return 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::setCursorFromRow(int row)
261 buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
264 text()->setCursor(cursor(), 0, 0);
266 text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), tmppos);
270 void BufferView::gotoLabel(string const & label)
272 for (InsetIterator it = inset_iterator_begin(buffer()->inset()); it; ++it) {
273 vector<string> labels;
274 it->getLabelList(*buffer(), labels);
275 if (find(labels.begin(),labels.end(),label) != labels.end()) {
284 LyXText * BufferView::getLyXText()
286 LyXText * text = cursor().innerText();
292 LyXText const * BufferView::getLyXText() const
294 LyXText const * text = cursor().innerText();
300 int BufferView::workHeight() const
302 return pimpl_->height();
306 LyXText * BufferView::text() const
308 return buffer() ? &buffer()->text() : 0;
312 void BufferView::setCursor(DocIterator const & dit)
314 size_t const n = dit.depth();
315 for (size_t i = 0; i < n; ++i)
316 dit[i].inset().edit(cursor(), true);
318 cursor().setCursor(dit);
319 cursor().selection() = false;
323 void BufferView::mouseSetCursor(LCursor & cur)
325 BOOST_ASSERT(&cur.bv() == this);
327 // Has the cursor just left the inset?
328 if (&cursor().inset() != &cur.inset())
329 cursor().inset().notifyCursorLeaves(cursor());
331 // do the dEPM magic if needed
332 if (cursor().inTexted())
333 cursor().text()->deleteEmptyParagraphMechanism(cur, cursor());
336 cursor().clearSelection();
337 cursor().setTargetX();
343 void BufferView::putSelectionAt(DocIterator const & cur,
344 int length, bool backwards)
346 cursor().clearSelection();
352 cursor().pos() += length;
353 cursor().setSelection(cursor(), -length);
355 cursor().setSelection(cursor(), length);
360 LCursor & BufferView::cursor()
362 return pimpl_->cursor_;
366 LCursor const & BufferView::cursor() const
368 return pimpl_->cursor_;
372 lyx::pit_type BufferView::anchor_ref() const
374 return pimpl_->anchor_ref_;
378 int BufferView::offset_ref() const
380 return pimpl_->offset_ref_;
384 ViewMetricsInfo const & BufferView::viewMetricsInfo()
386 return pimpl_->viewMetricsInfo();
390 void BufferView::updateMetrics(bool singlepar)
392 pimpl_->updateMetrics(singlepar);