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"
17 #include "BufferView.h"
18 #include "funcrequest.h"
21 #include "WordLangTuple.h"
23 #include "support/lstrings.h"
25 using namespace lyx::support;
27 // some stuff for inset locking
29 UpdatableInset::UpdatableInset()
34 UpdatableInset::UpdatableInset(UpdatableInset const & in)
39 void UpdatableInset::insetUnlock(BufferView *)
41 lyxerr[Debug::INFO] << "Inset Unlock" << std::endl;
45 // An updatable inset is highly editable by definition
46 InsetOld::EDITABLE UpdatableInset::editable() const
48 return HIGHLY_EDITABLE;
52 void UpdatableInset::fitInsetCursor(BufferView *) const
56 void UpdatableInset::draw(PainterInfo &, int, int) const
58 // ATTENTION: don't do the following here!!!
64 void UpdatableInset::scroll(BufferView * bv, float s) const
73 int const workW = bv->workWidth();
74 int const tmp_top_x = top_x - scx;
76 if (tmp_top_x > 0 && tmp_top_x + width() < workW)
78 if (s > 0 && top_x > 0)
81 scx = int(s * workW / 2);
86 if (tmp_top_x + scx + width() < workW / 2) {
87 scx += workW / 2 - (tmp_top_x + scx + width());
91 void UpdatableInset::scroll(BufferView * bv, int offset) const
94 if (!scx && top_x >= 20)
96 if ((top_x + offset) > 20)
98 // scx += offset - (top_x - scx + offset - 20);
103 if (!scx && top_x + width() < bv->workWidth() - 20)
105 if (top_x - scx + offset + width() < bv->workWidth() - 20) {
106 scx += bv->workWidth() - width() - top_x - 20;
114 /// An updatable inset could handle lyx editing commands
115 InsetOld::RESULT UpdatableInset::localDispatch(FuncRequest const & ev)
117 if (ev.action == LFUN_MOUSE_RELEASE)
118 return (editable() == IS_EDITABLE) ? DISPATCHED : UNDISPATCHED;
120 if (!ev.argument.empty() && ev.action == LFUN_SCROLL_INSET) {
121 if (ev.argument.find('.') != ev.argument.npos) {
122 float const xx = static_cast<float>(strToDbl(ev.argument));
123 scroll(ev.view(), xx);
125 int const xx = strToInt(ev.argument);
126 scroll(ev.view(), xx);
128 ev.view()->updateInset(this);
136 LyXCursor const & InsetOld::cursor(BufferView * bv) const
139 return owner()->getLyXText(bv, false)->cursor;
140 return bv->text->cursor;
145 UpdatableInset::selectNextWordToSpellcheck(BufferView *bv, float & value) const
147 // we have to unlock ourself in this function by default!
148 bv->unlockInset(const_cast<UpdatableInset *>(this));
150 return WordLangTuple();
154 bool UpdatableInset::nextChange(BufferView * bv, lyx::pos_type &)
156 // we have to unlock ourself in this function by default!
157 bv->unlockInset(const_cast<UpdatableInset *>(this));
162 bool UpdatableInset::searchForward(BufferView * bv, string const &,
165 // we have to unlock ourself in this function by default!
166 bv->unlockInset(const_cast<UpdatableInset *>(this));
171 bool UpdatableInset::searchBackward(BufferView * bv, string const &,
174 // we have to unlock ourself in this function by default!
175 bv->unlockInset(const_cast<UpdatableInset *>(this));