2 #include "updatableinset.h"
3 #include "BufferView.h"
4 #include "funcrequest.h"
7 #include "WordLangTuple.h"
9 #include "support/lstrings.h"
12 // some stuff for inset locking
14 UpdatableInset::UpdatableInset()
15 : Inset(), cursor_visible_(false), block_drawing_(false)
19 UpdatableInset::UpdatableInset(UpdatableInset const & in, bool same_id)
20 : Inset(in, same_id), cursor_visible_(false), block_drawing_(false)
24 void UpdatableInset::insetUnlock(BufferView *)
26 lyxerr[Debug::INFO] << "Inset Unlock" << endl;
30 // An updatable inset is highly editable by definition
31 Inset::EDITABLE UpdatableInset::editable() const
33 return HIGHLY_EDITABLE;
37 void UpdatableInset::toggleInsetCursor(BufferView *)
41 void UpdatableInset::showInsetCursor(BufferView *, bool)
45 void UpdatableInset::hideInsetCursor(BufferView *)
49 void UpdatableInset::fitInsetCursor(BufferView *) const
53 void UpdatableInset::edit(BufferView *, int, int, mouse_button::state)
57 void UpdatableInset::edit(BufferView *, bool)
61 void UpdatableInset::draw(BufferView *, LyXFont const &,
62 int /* baseline */, float & x,
63 bool/*cleared*/) const
66 // ATTENTION: don't do the following here!!!
68 // top_baseline = baseline;
72 void UpdatableInset::scroll(BufferView * bv, float s) const
81 int const workW = bv->workWidth();
82 int const tmp_top_x = top_x - scx;
85 (tmp_top_x + width(bv, font)) < workW)
87 if (s > 0 && top_x > 0)
90 // int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
91 //int const save_scx = scx;
93 scx = int(s * workW / 2);
97 if ((tmp_top_x + scx + width(bv, font)) < (workW / 2)) {
98 scx += (workW / 2) - (tmp_top_x + scx + width(bv, font));
101 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
104 void UpdatableInset::scroll(BufferView * bv, int offset) const
107 if (!scx && top_x >= 20)
109 if ((top_x + offset) > 20)
111 // scx += offset - (top_x - scx + offset - 20);
116 if (!scx && (top_x + width(bv, font)) < (bv->workWidth() - 20))
118 if ((top_x - scx + offset + width(bv, font)) < (bv->workWidth() - 20)) {
119 scx = bv->workWidth() - width(bv, font) - top_x + scx - 20;
124 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
128 /// An updatable inset could handle lyx editing commands
129 Inset::RESULT UpdatableInset::localDispatch(FuncRequest const & ev)
131 if (ev.action == LFUN_MOUSE_RELEASE)
132 return (editable() == IS_EDITABLE) ? DISPATCHED : UNDISPATCHED;
134 if (!ev.argument.empty() && ev.action == LFUN_SCROLL_INSET) {
135 if (ev.argument.find('.') != ev.argument.npos) {
136 float const xx = static_cast<float>(strToDbl(ev.argument));
137 scroll(ev.view(), xx);
139 int const xx = strToInt(ev.argument);
140 scroll(ev.view(), xx);
142 ev.view()->updateInset(this, false);
150 int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
154 w = static_cast<UpdatableInset*>
155 (owner())->getMaxWidth(bv, this);
157 w = bv->text->workWidth(bv, const_cast<UpdatableInset *>(this));
162 // check for margins left/right and extra right margin "const 5"
163 if ((w - ((2 * TEXT_TO_INSET_OFFSET) + 5)) >= 0)
164 w -= (2 * TEXT_TO_INSET_OFFSET) + 5;
165 if (topx_set && owner()) {
168 } else if (owner()) {
169 // this is needed as otherwise we might have a too large inset if
170 // its top_x afterwards changes to LeftMargin so we try to put at
171 // least the default margin as top_x
181 LyXCursor const & Inset::cursor(BufferView * bv) const
184 return owner()->getLyXText(bv, false)->cursor;
185 return bv->text->cursor;
190 UpdatableInset::selectNextWordToSpellcheck(BufferView *bv, float & value) const
192 // we have to unlock ourself in this function by default!
193 bv->unlockInset(const_cast<UpdatableInset *>(this));
195 return WordLangTuple();
199 bool UpdatableInset::nextChange(BufferView * bv, lyx::pos_type &)
201 // we have to unlock ourself in this function by default!
202 bv->unlockInset(const_cast<UpdatableInset *>(this));
207 bool UpdatableInset::searchForward(BufferView * bv, string const &,
210 // we have to unlock ourself in this function by default!
211 bv->unlockInset(const_cast<UpdatableInset *>(this));
216 bool UpdatableInset::searchBackward(BufferView * bv, string const &,
219 // we have to unlock ourself in this function by default!
220 bv->unlockInset(const_cast<UpdatableInset *>(this));