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()
30 : Inset(), block_drawing_(false)
34 UpdatableInset::UpdatableInset(UpdatableInset const & in)
35 : Inset(in), block_drawing_(false)
39 void UpdatableInset::insetUnlock(BufferView *)
41 lyxerr[Debug::INFO] << "Inset Unlock" << std::endl;
45 // An updatable inset is highly editable by definition
46 Inset::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;
77 (tmp_top_x + width(bv, font)) < workW)
79 if (s > 0 && top_x > 0)
82 // int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
83 //int const save_scx = scx;
85 scx = int(s * workW / 2);
89 if ((tmp_top_x + scx + width(bv, font)) < (workW / 2)) {
90 scx += (workW / 2) - (tmp_top_x + scx + width(bv, font));
94 void UpdatableInset::scroll(BufferView * bv, int offset) const
97 if (!scx && top_x >= 20)
99 if ((top_x + offset) > 20)
101 // scx += offset - (top_x - scx + offset - 20);
106 if (!scx && (top_x + width(bv, font)) < (bv->workWidth() - 20))
108 if ((top_x - scx + offset + width(bv, font)) < (bv->workWidth() - 20)) {
109 scx = bv->workWidth() - width(bv, font) - top_x + scx - 20;
117 /// An updatable inset could handle lyx editing commands
118 Inset::RESULT UpdatableInset::localDispatch(FuncRequest const & ev)
120 if (ev.action == LFUN_MOUSE_RELEASE)
121 return (editable() == IS_EDITABLE) ? DISPATCHED : UNDISPATCHED;
123 if (!ev.argument.empty() && ev.action == LFUN_SCROLL_INSET) {
124 if (ev.argument.find('.') != ev.argument.npos) {
125 float const xx = static_cast<float>(strToDbl(ev.argument));
126 scroll(ev.view(), xx);
128 int const xx = strToInt(ev.argument);
129 scroll(ev.view(), xx);
131 ev.view()->updateInset(this);
139 int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
144 w = static_cast<UpdatableInset *>(owner())->getMaxWidth(bv, this);
146 w = bv->text->workWidth(this);
151 // check for margins left/right and extra right margin "const 5"
152 if ((w - (2 * TEXT_TO_INSET_OFFSET + 5)) >= 0)
153 w -= 2 * TEXT_TO_INSET_OFFSET + 5;
155 // Deep magic. I don't understand this either.
156 if (owner() && owner()->owner()) {
157 // add the right paper margin
169 LyXCursor const & Inset::cursor(BufferView * bv) const
172 return owner()->getLyXText(bv, false)->cursor;
173 return bv->text->cursor;
178 UpdatableInset::selectNextWordToSpellcheck(BufferView *bv, float & value) const
180 // we have to unlock ourself in this function by default!
181 bv->unlockInset(const_cast<UpdatableInset *>(this));
183 return WordLangTuple();
187 bool UpdatableInset::nextChange(BufferView * bv, lyx::pos_type &)
189 // we have to unlock ourself in this function by default!
190 bv->unlockInset(const_cast<UpdatableInset *>(this));
195 bool UpdatableInset::searchForward(BufferView * bv, string const &,
198 // we have to unlock ourself in this function by default!
199 bv->unlockInset(const_cast<UpdatableInset *>(this));
204 bool UpdatableInset::searchBackward(BufferView * bv, string const &,
207 // we have to unlock ourself in this function by default!
208 bv->unlockInset(const_cast<UpdatableInset *>(this));