2 * \file updatableinset.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
8 * \author Lars Gullik Bjønnes
9 * \author Matthias Ettrich
11 * Full author contact details are available in file CREDITS.
16 #include "updatableinset.h"
18 #include "BufferView.h"
20 #include "funcrequest.h"
22 #include "WordLangTuple.h"
24 #include "support/lstrings.h"
27 using lyx::support::strToDbl;
28 using lyx::support::strToInt;
33 // some stuff for inset locking
35 void UpdatableInset::insetUnlock(BufferView *)
37 lyxerr[Debug::INFO] << "Inset Unlock" << std::endl;
41 // An updatable inset is highly editable by definition
42 InsetOld::EDITABLE UpdatableInset::editable() const
44 return HIGHLY_EDITABLE;
48 void UpdatableInset::fitInsetCursor(BufferView *) const
52 void UpdatableInset::draw(PainterInfo &, int, int) const
54 // ATTENTION: don't do the following here!!!
60 void UpdatableInset::scroll(BufferView * bv, float s) const
69 int const workW = bv->workWidth();
70 int const tmp_top_x = top_x - scx;
72 if (tmp_top_x > 0 && tmp_top_x + width() < workW)
74 if (s > 0 && top_x > 0)
77 scx = int(s * workW / 2);
82 if (tmp_top_x + scx + width() < workW / 2) {
83 scx += workW / 2 - (tmp_top_x + scx + width());
87 void UpdatableInset::scroll(BufferView * bv, int offset) const
90 if (!scx && top_x >= 20)
92 if ((top_x + offset) > 20)
94 // scx += offset - (top_x - scx + offset - 20);
99 if (!scx && top_x + width() < bv->workWidth() - 20)
101 if (top_x - scx + offset + width() < bv->workWidth() - 20) {
102 scx += bv->workWidth() - width() - top_x - 20;
110 /// An updatable inset could handle lyx editing commands
112 UpdatableInset::priv_dispatch(FuncRequest const & ev, idx_type &, pos_type &)
114 if (ev.action == LFUN_MOUSE_RELEASE)
115 return (editable() == IS_EDITABLE) ? DISPATCHED : UNDISPATCHED;
117 if (!ev.argument.empty() && ev.action == LFUN_SCROLL_INSET) {
118 if (ev.argument.find('.') != ev.argument.npos) {
119 float const xx = static_cast<float>(strToDbl(ev.argument));
120 scroll(ev.view(), xx);
122 int const xx = strToInt(ev.argument);
123 scroll(ev.view(), xx);
125 ev.view()->updateInset(this);
133 LyXCursor const & InsetOld::cursor(BufferView * bv) const
136 return owner()->getLyXText(bv, false)->cursor;
137 return bv->text->cursor;
142 UpdatableInset::selectNextWordToSpellcheck(BufferView *bv, float & value) const
144 // we have to unlock ourself in this function by default!
145 bv->unlockInset(const_cast<UpdatableInset *>(this));
147 return WordLangTuple();
151 bool UpdatableInset::nextChange(BufferView * bv, lyx::pos_type &)
153 // we have to unlock ourself in this function by default!
154 bv->unlockInset(const_cast<UpdatableInset *>(this));
159 bool UpdatableInset::searchForward(BufferView * bv, string const &,
162 // we have to unlock ourself in this function by default!
163 bv->unlockInset(const_cast<UpdatableInset *>(this));
168 bool UpdatableInset::searchBackward(BufferView * bv, string const &,
171 // we have to unlock ourself in this function by default!
172 bv->unlockInset(const_cast<UpdatableInset *>(this));