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"
26 using namespace lyx::support;
29 // some stuff for inset locking
31 UpdatableInset::UpdatableInset()
36 UpdatableInset::UpdatableInset(UpdatableInset const & in)
41 void UpdatableInset::insetUnlock(BufferView *)
43 lyxerr[Debug::INFO] << "Inset Unlock" << std::endl;
47 // An updatable inset is highly editable by definition
48 InsetOld::EDITABLE UpdatableInset::editable() const
50 return HIGHLY_EDITABLE;
54 void UpdatableInset::fitInsetCursor(BufferView *) const
58 void UpdatableInset::draw(PainterInfo &, int, int) const
60 // ATTENTION: don't do the following here!!!
66 void UpdatableInset::scroll(BufferView * bv, float s) const
75 int const workW = bv->workWidth();
76 int const tmp_top_x = top_x - scx;
78 if (tmp_top_x > 0 && tmp_top_x + width() < workW)
80 if (s > 0 && top_x > 0)
83 scx = int(s * workW / 2);
88 if (tmp_top_x + scx + width() < workW / 2) {
89 scx += workW / 2 - (tmp_top_x + scx + width());
93 void UpdatableInset::scroll(BufferView * bv, int offset) const
96 if (!scx && top_x >= 20)
98 if ((top_x + offset) > 20)
100 // scx += offset - (top_x - scx + offset - 20);
105 if (!scx && top_x + width() < bv->workWidth() - 20)
107 if (top_x - scx + offset + width() < bv->workWidth() - 20) {
108 scx += bv->workWidth() - width() - top_x - 20;
116 /// An updatable inset could handle lyx editing commands
117 InsetOld::RESULT UpdatableInset::localDispatch(FuncRequest const & ev)
119 if (ev.action == LFUN_MOUSE_RELEASE)
120 return (editable() == IS_EDITABLE) ? DISPATCHED : UNDISPATCHED;
122 if (!ev.argument.empty() && ev.action == LFUN_SCROLL_INSET) {
123 if (ev.argument.find('.') != ev.argument.npos) {
124 float const xx = static_cast<float>(strToDbl(ev.argument));
125 scroll(ev.view(), xx);
127 int const xx = strToInt(ev.argument);
128 scroll(ev.view(), xx);
130 ev.view()->updateInset(this);
138 LyXCursor const & InsetOld::cursor(BufferView * bv) const
141 return owner()->getLyXText(bv, false)->cursor;
142 return bv->text->cursor;
147 UpdatableInset::selectNextWordToSpellcheck(BufferView *bv, float & value) const
149 // we have to unlock ourself in this function by default!
150 bv->unlockInset(const_cast<UpdatableInset *>(this));
152 return WordLangTuple();
156 bool UpdatableInset::nextChange(BufferView * bv, lyx::pos_type &)
158 // we have to unlock ourself in this function by default!
159 bv->unlockInset(const_cast<UpdatableInset *>(this));
164 bool UpdatableInset::searchForward(BufferView * bv, string const &,
167 // we have to unlock ourself in this function by default!
168 bv->unlockInset(const_cast<UpdatableInset *>(this));
173 bool UpdatableInset::searchBackward(BufferView * bv, string const &,
176 // we have to unlock ourself in this function by default!
177 bv->unlockInset(const_cast<UpdatableInset *>(this));