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, bool same_id)
34 : Inset(in, same_id), 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(BufferView *, LyXFont const &,
56 int /* baseline */, float & x) const
59 // ATTENTION: don't do the following here!!!
61 // top_baseline = baseline;
65 void UpdatableInset::scroll(BufferView * bv, float s) const
74 int const workW = bv->workWidth();
75 int const tmp_top_x = top_x - scx;
78 (tmp_top_x + width(bv, font)) < workW)
80 if (s > 0 && top_x > 0)
83 // int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
84 //int const save_scx = scx;
86 scx = int(s * workW / 2);
90 if ((tmp_top_x + scx + width(bv, font)) < (workW / 2)) {
91 scx += (workW / 2) - (tmp_top_x + scx + width(bv, font));
95 void UpdatableInset::scroll(BufferView * bv, int offset) const
98 if (!scx && top_x >= 20)
100 if ((top_x + offset) > 20)
102 // scx += offset - (top_x - scx + offset - 20);
107 if (!scx && (top_x + width(bv, font)) < (bv->workWidth() - 20))
109 if ((top_x - scx + offset + width(bv, font)) < (bv->workWidth() - 20)) {
110 scx = bv->workWidth() - width(bv, font) - top_x + scx - 20;
118 /// An updatable inset could handle lyx editing commands
119 Inset::RESULT UpdatableInset::localDispatch(FuncRequest const & ev)
121 if (ev.action == LFUN_MOUSE_RELEASE)
122 return (editable() == IS_EDITABLE) ? DISPATCHED : UNDISPATCHED;
124 if (!ev.argument.empty() && ev.action == LFUN_SCROLL_INSET) {
125 if (ev.argument.find('.') != ev.argument.npos) {
126 float const xx = static_cast<float>(strToDbl(ev.argument));
127 scroll(ev.view(), xx);
129 int const xx = strToInt(ev.argument);
130 scroll(ev.view(), xx);
132 ev.view()->updateInset(this);
140 int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
145 w = static_cast<UpdatableInset *>(owner())->getMaxWidth(bv, this);
147 w = bv->text->workWidth(this);
152 // check for margins left/right and extra right margin "const 5"
153 if ((w - (2 * TEXT_TO_INSET_OFFSET + 5)) >= 0)
154 w -= 2 * TEXT_TO_INSET_OFFSET + 5;
156 // Deep magic. I don't understand this either.
157 if (owner() && owner()->owner()) {
158 // add the right paper margin
170 LyXCursor const & Inset::cursor(BufferView * bv) const
173 return owner()->getLyXText(bv, false)->cursor;
174 return bv->text->cursor;
179 UpdatableInset::selectNextWordToSpellcheck(BufferView *bv, float & value) const
181 // we have to unlock ourself in this function by default!
182 bv->unlockInset(const_cast<UpdatableInset *>(this));
184 return WordLangTuple();
188 bool UpdatableInset::nextChange(BufferView * bv, lyx::pos_type &)
190 // we have to unlock ourself in this function by default!
191 bv->unlockInset(const_cast<UpdatableInset *>(this));
196 bool UpdatableInset::searchForward(BufferView * bv, string const &,
199 // we have to unlock ourself in this function by default!
200 bv->unlockInset(const_cast<UpdatableInset *>(this));
205 bool UpdatableInset::searchBackward(BufferView * bv, string const &,
208 // we have to unlock ourself in this function by default!
209 bv->unlockInset(const_cast<UpdatableInset *>(this));