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 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 ScrollbarParameters const & BufferView::scrollbarParameters() const
152 return pimpl_->scrollbarParameters();
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_->width();
208 void BufferView::center()
214 FuncStatus BufferView::getStatus(FuncRequest const & cmd)
216 return pimpl_->getStatus(cmd);
220 bool BufferView::dispatch(FuncRequest const & ev)
222 return pimpl_->dispatch(ev);
226 void BufferView::selectionRequested()
228 pimpl_->selectionRequested();
232 void BufferView::selectionLost()
234 pimpl_->selectionLost();
238 void BufferView::workAreaResize(int width, int height)
240 pimpl_->workAreaResize(width, height);
244 void BufferView::workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state)
246 pimpl_->workAreaKeyPress(key, state);
250 bool BufferView::workAreaDispatch(FuncRequest const & ev)
252 return pimpl_->workAreaDispatch(ev);
256 void BufferView::scroll(int lines)
258 pimpl_->scroll(lines);
262 void BufferView::showErrorList(string const & action) const
264 if (getErrorList().size()) {
265 string const title = bformat(_("%1$s Errors (%2$s)"),
266 action, buffer()->fileName());
267 owner()->getDialogs().show("errorlist", title);
268 pimpl_->errorlist_.clear();
273 ErrorList const & BufferView::getErrorList() const
275 return pimpl_->errorlist_;
279 void BufferView::setCursorFromRow(int row)
284 buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
287 text()->setCursor(cursor(), 0, 0);
289 text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), tmppos);
293 void BufferView::gotoLabel(string const & label)
295 for (InsetIterator it = inset_iterator_begin(buffer()->inset()); it; ++it) {
296 vector<string> labels;
297 it->getLabelList(*buffer(), labels);
298 if (find(labels.begin(),labels.end(),label) != labels.end()) {
307 void BufferView::hideCursor()
309 pimpl_->gui().guiCursor().hide();
312 LyXText * BufferView::getLyXText()
314 LyXText * text = cursor().innerText();
320 LyXText const * BufferView::getLyXText() const
322 LyXText const * text = cursor().innerText();
328 int BufferView::workHeight() const
330 return pimpl_->height();
334 LyXText * BufferView::text() const
336 return buffer() ? &buffer()->text() : 0;
340 void BufferView::setCursor(DocIterator const & dit)
342 size_t const n = dit.depth();
343 for (size_t i = 0; i < n; ++i)
344 dit[i].inset().edit(cursor(), true);
346 cursor().setCursor(dit);
347 cursor().selection() = false;
351 void BufferView::mouseSetCursor(LCursor & cur)
353 BOOST_ASSERT(&cur.bv() == this);
355 // Has the cursor just left the inset?
356 if (&cursor().inset() != &cur.inset())
357 cursor().inset().notifyCursorLeaves(cursor());
359 // do the dEPM magic if needed
360 if (cursor().inTexted())
361 cursor().text()->deleteEmptyParagraphMechanism(cur, cursor());
364 cursor().clearSelection();
365 cursor().setTargetX();
371 void BufferView::putSelectionAt(DocIterator const & cur,
372 int length, bool backwards)
374 cursor().clearSelection();
380 cursor().pos() += length;
381 cursor().setSelection(cursor(), -length);
383 cursor().setSelection(cursor(), length);
388 LCursor & BufferView::cursor()
390 return pimpl_->cursor_;
394 LCursor const & BufferView::cursor() const
396 return pimpl_->cursor_;
400 lyx::pit_type BufferView::anchor_ref() const
402 return pimpl_->anchor_ref_;
406 int BufferView::offset_ref() const
408 return pimpl_->offset_ref_;