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 "coordcache.h"
25 #include "funcrequest.h"
26 #include "FuncStatus.h"
28 #include "insetiterator.h"
30 #include "lyxlayout.h"
32 #include "lyxtextclass.h"
33 #include "paragraph.h"
34 #include "paragraph_funcs.h"
35 #include "pariterator.h"
38 #include "WordLangTuple.h"
39 #include "metricsinfo.h"
41 #include "frontends/Alert.h"
42 #include "frontends/Clipboard.h"
43 #include "frontends/Dialogs.h"
44 #include "frontends/LyXView.h"
46 #include "insets/insetcommand.h" // ChangeRefs
47 #include "insets/insettext.h"
50 using lyx::support::bformat;
58 extern BufferList bufferlist;
61 BufferView::BufferView(LyXView * owner)
62 : pimpl_(new Pimpl(*this, owner))
66 BufferView::~BufferView()
72 void BufferView::unsetXSel()
74 pimpl_->xsel_cache_.set = false;
78 Buffer * BufferView::buffer() const
80 return pimpl_->buffer_;
84 LyXView * BufferView::owner() const
86 return pimpl_->owner_;
90 void BufferView::setBuffer(Buffer * b)
96 string BufferView::firstLayout()
98 return pimpl_->firstLayout();
102 bool BufferView::loadLyXFile(string const & fn, bool tl)
104 return pimpl_->loadLyXFile(fn, tl);
108 void BufferView::reload()
110 string const fn = buffer()->fileName();
111 if (bufferlist.close(buffer(), false))
116 void BufferView::resize()
119 pimpl_->resizeCurrentBuffer();
123 bool BufferView::fitCursor()
125 return pimpl_->fitCursor();
129 bool BufferView::update(Update::flags flags)
131 return pimpl_->update(flags);
135 void BufferView::updateScrollbar()
137 pimpl_->updateScrollbar();
141 ScrollbarParameters const & BufferView::scrollbarParameters() const
143 return pimpl_->scrollbarParameters();
147 void BufferView::scrollDocView(int value)
149 pimpl_->scrollDocView(value);
153 void BufferView::setCursorFromScrollbar()
155 pimpl_->setCursorFromScrollbar();
159 bool BufferView::available() const
161 return pimpl_->available();
165 Change const BufferView::getCurrentChange()
167 return pimpl_->getCurrentChange();
171 void BufferView::savePosition(unsigned int i)
173 pimpl_->savePosition(i);
177 void BufferView::restorePosition(unsigned int i)
179 pimpl_->restorePosition(i);
183 bool BufferView::isSavedPosition(unsigned int i)
185 return pimpl_->isSavedPosition(i);
188 void BufferView::saveSavedPositions()
190 return pimpl_->saveSavedPositions();
193 void BufferView::switchKeyMap()
195 pimpl_->switchKeyMap();
199 int BufferView::workWidth() const
201 return pimpl_->width();
205 void BufferView::center()
211 FuncStatus BufferView::getStatus(FuncRequest const & cmd)
213 return pimpl_->getStatus(cmd);
217 bool BufferView::dispatch(FuncRequest const & ev)
219 return pimpl_->dispatch(ev);
223 void BufferView::selectionRequested()
225 pimpl_->selectionRequested();
229 void BufferView::selectionLost()
231 pimpl_->selectionLost();
235 void BufferView::workAreaResize(int width, int height)
237 pimpl_->workAreaResize(width, height);
241 bool BufferView::workAreaDispatch(FuncRequest const & ev)
243 return pimpl_->workAreaDispatch(ev);
247 void BufferView::scroll(int lines)
249 pimpl_->scroll(lines);
253 void BufferView::setCursorFromRow(int row)
258 buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
261 text()->setCursor(cursor(), 0, 0);
263 text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), tmppos);
267 void BufferView::gotoLabel(string const & label)
269 for (InsetIterator it = inset_iterator_begin(buffer()->inset()); it; ++it) {
270 vector<string> labels;
271 it->getLabelList(*buffer(), labels);
272 if (find(labels.begin(),labels.end(),label) != labels.end()) {
281 LyXText * BufferView::getLyXText()
283 LyXText * text = cursor().innerText();
289 LyXText const * BufferView::getLyXText() const
291 LyXText const * text = cursor().innerText();
297 int BufferView::workHeight() const
299 return pimpl_->height();
303 LyXText * BufferView::text() const
305 return buffer() ? &buffer()->text() : 0;
309 void BufferView::setCursor(DocIterator const & dit)
311 size_t const n = dit.depth();
312 for (size_t i = 0; i < n; ++i)
313 dit[i].inset().edit(cursor(), true);
315 cursor().setCursor(dit);
316 cursor().selection() = false;
320 void BufferView::mouseSetCursor(LCursor & cur)
322 BOOST_ASSERT(&cur.bv() == this);
324 // Has the cursor just left the inset?
325 if (&cursor().inset() != &cur.inset())
326 cursor().inset().notifyCursorLeaves(cursor());
328 // do the dEPM magic if needed
329 if (cursor().inTexted())
330 cursor().text()->deleteEmptyParagraphMechanism(cur, cursor());
333 cursor().clearSelection();
334 cursor().setTargetX();
340 void BufferView::putSelectionAt(DocIterator const & cur,
341 int length, bool backwards)
343 cursor().clearSelection();
349 cursor().pos() += length;
350 cursor().setSelection(cursor(), -length);
352 cursor().setSelection(cursor(), length);
357 LCursor & BufferView::cursor()
359 return pimpl_->cursor_;
363 LCursor const & BufferView::cursor() const
365 return pimpl_->cursor_;
369 lyx::pit_type BufferView::anchor_ref() const
371 return pimpl_->anchor_ref_;
375 int BufferView::offset_ref() const
377 return pimpl_->offset_ref_;
381 ViewMetricsInfo const & BufferView::viewMetricsInfo()
383 return pimpl_->viewMetricsInfo();
387 void BufferView::updateMetrics(bool singlepar)
389 pimpl_->updateMetrics(singlepar);