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"
26 // some stuff for inset locking
28 UpdatableInset::UpdatableInset()
29 : Inset(), block_drawing_(false)
33 UpdatableInset::UpdatableInset(UpdatableInset const & in)
34 : Inset(in), block_drawing_(false)
38 void UpdatableInset::insetUnlock(BufferView *)
40 lyxerr[Debug::INFO] << "Inset Unlock" << std::endl;
44 // An updatable inset is highly editable by definition
45 Inset::EDITABLE UpdatableInset::editable() const
47 return HIGHLY_EDITABLE;
51 void UpdatableInset::fitInsetCursor(BufferView *) const
55 void UpdatableInset::draw(PainterInfo &, int, int) const
57 // ATTENTION: don't do the following here!!!
63 void UpdatableInset::scroll(BufferView * bv, float s) const
72 int const workW = bv->workWidth();
73 int const tmp_top_x = top_x - scx;
76 (tmp_top_x + width(bv, font)) < workW)
78 if (s > 0 && top_x > 0)
81 // int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
82 //int const save_scx = scx;
84 scx = int(s * workW / 2);
88 if ((tmp_top_x + scx + width(bv, font)) < (workW / 2)) {
89 scx += (workW / 2) - (tmp_top_x + scx + width(bv, font));
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, font)) < (bv->workWidth() - 20))
107 if ((top_x - scx + offset + width(bv, font)) < (bv->workWidth() - 20)) {
108 scx = bv->workWidth() - width(bv, font) - top_x + scx - 20;
116 /// An updatable inset could handle lyx editing commands
117 Inset::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 int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
143 w = static_cast<UpdatableInset *>(owner())->getMaxWidth(bv, this);
145 w = bv->text->workWidth(this);
150 // check for margins left/right and extra right margin "const 5"
151 if ((w - (2 * TEXT_TO_INSET_OFFSET + 5)) >= 0)
152 w -= 2 * TEXT_TO_INSET_OFFSET + 5;
154 // Deep magic. I don't understand this either.
155 if (owner() && owner()->owner()) {
156 // add the right paper margin
168 LyXCursor const & Inset::cursor(BufferView * bv) const
171 return owner()->getLyXText(bv, false)->cursor;
172 return bv->text->cursor;
177 UpdatableInset::selectNextWordToSpellcheck(BufferView *bv, float & value) const
179 // we have to unlock ourself in this function by default!
180 bv->unlockInset(const_cast<UpdatableInset *>(this));
182 return WordLangTuple();
186 bool UpdatableInset::nextChange(BufferView * bv, lyx::pos_type &)
188 // we have to unlock ourself in this function by default!
189 bv->unlockInset(const_cast<UpdatableInset *>(this));
194 bool UpdatableInset::searchForward(BufferView * bv, string const &,
197 // we have to unlock ourself in this function by default!
198 bv->unlockInset(const_cast<UpdatableInset *>(this));
203 bool UpdatableInset::searchBackward(BufferView * bv, string const &,
206 // we have to unlock ourself in this function by default!
207 bv->unlockInset(const_cast<UpdatableInset *>(this));