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(), cursor_visible_(false), block_drawing_(false)
33 UpdatableInset::UpdatableInset(UpdatableInset const & in, bool same_id)
34 : Inset(in, same_id), cursor_visible_(false), 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::toggleInsetCursor(BufferView *)
55 void UpdatableInset::showInsetCursor(BufferView *, bool)
59 void UpdatableInset::hideInsetCursor(BufferView *)
63 void UpdatableInset::fitInsetCursor(BufferView *) const
67 void UpdatableInset::edit(BufferView *, int, int, mouse_button::state)
71 void UpdatableInset::edit(BufferView *, bool)
75 void UpdatableInset::draw(BufferView *, LyXFont const &,
76 int /* baseline */, float & x) const
79 // ATTENTION: don't do the following here!!!
81 // top_baseline = baseline;
85 void UpdatableInset::scroll(BufferView * bv, float s) const
94 int const workW = bv->workWidth();
95 int const tmp_top_x = top_x - scx;
98 (tmp_top_x + width(bv, font)) < workW)
100 if (s > 0 && top_x > 0)
103 // int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
104 //int const save_scx = scx;
106 scx = int(s * workW / 2);
110 if ((tmp_top_x + scx + width(bv, font)) < (workW / 2)) {
111 scx += (workW / 2) - (tmp_top_x + scx + width(bv, font));
114 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
117 void UpdatableInset::scroll(BufferView * bv, int offset) const
120 if (!scx && top_x >= 20)
122 if ((top_x + offset) > 20)
124 // scx += offset - (top_x - scx + offset - 20);
129 if (!scx && (top_x + width(bv, font)) < (bv->workWidth() - 20))
131 if ((top_x - scx + offset + width(bv, font)) < (bv->workWidth() - 20)) {
132 scx = bv->workWidth() - width(bv, font) - top_x + scx - 20;
137 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
141 /// An updatable inset could handle lyx editing commands
142 Inset::RESULT UpdatableInset::localDispatch(FuncRequest const & ev)
144 if (ev.action == LFUN_MOUSE_RELEASE)
145 return (editable() == IS_EDITABLE) ? DISPATCHED : UNDISPATCHED;
147 if (!ev.argument.empty() && ev.action == LFUN_SCROLL_INSET) {
148 if (ev.argument.find('.') != ev.argument.npos) {
149 float const xx = static_cast<float>(strToDbl(ev.argument));
150 scroll(ev.view(), xx);
152 int const xx = strToInt(ev.argument);
153 scroll(ev.view(), xx);
155 ev.view()->updateInset(this, false);
163 int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
167 w = static_cast<UpdatableInset*>
168 (owner())->getMaxWidth(bv, this);
170 w = bv->text->workWidth(*bv, const_cast<UpdatableInset *>(this));
175 // check for margins left/right and extra right margin "const 5"
176 if ((w - ((2 * TEXT_TO_INSET_OFFSET) + 5)) >= 0)
177 w -= (2 * TEXT_TO_INSET_OFFSET) + 5;
178 if (topx_set && owner()) {
181 } else if (owner()) {
182 // this is needed as otherwise we might have a too large inset if
183 // its top_x afterwards changes to LeftMargin so we try to put at
184 // least the default margin as top_x
194 LyXCursor const & Inset::cursor(BufferView * bv) const
197 return owner()->getLyXText(bv, false)->cursor;
198 return bv->text->cursor;
203 UpdatableInset::selectNextWordToSpellcheck(BufferView *bv, float & value) const
205 // we have to unlock ourself in this function by default!
206 bv->unlockInset(const_cast<UpdatableInset *>(this));
208 return WordLangTuple();
212 bool UpdatableInset::nextChange(BufferView * bv, lyx::pos_type &)
214 // we have to unlock ourself in this function by default!
215 bv->unlockInset(const_cast<UpdatableInset *>(this));
220 bool UpdatableInset::searchForward(BufferView * bv, string const &,
223 // we have to unlock ourself in this function by default!
224 bv->unlockInset(const_cast<UpdatableInset *>(this));
229 bool UpdatableInset::searchBackward(BufferView * bv, string const &,
232 // we have to unlock ourself in this function by default!
233 bv->unlockInset(const_cast<UpdatableInset *>(this));