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;
76 if (tmp_top_x > 0 && tmp_top_x + width() < workW)
78 if (s > 0 && top_x > 0)
81 scx = int(s * workW / 2);
86 if (tmp_top_x + scx + width() < workW / 2) {
87 scx += workW / 2 - (tmp_top_x + scx + width());
91 void UpdatableInset::scroll(BufferView * bv, int offset) const
94 if (!scx && top_x >= 20)
96 if ((top_x + offset) > 20)
98 // scx += offset - (top_x - scx + offset - 20);
103 if (!scx && top_x + width() < bv->workWidth() - 20)
105 if (top_x - scx + offset + width() < bv->workWidth() - 20) {
106 scx += bv->workWidth() - width() - top_x - 20;
114 /// An updatable inset could handle lyx editing commands
115 Inset::RESULT UpdatableInset::localDispatch(FuncRequest const & ev)
117 if (ev.action == LFUN_MOUSE_RELEASE)
118 return (editable() == IS_EDITABLE) ? DISPATCHED : UNDISPATCHED;
120 if (!ev.argument.empty() && ev.action == LFUN_SCROLL_INSET) {
121 if (ev.argument.find('.') != ev.argument.npos) {
122 float const xx = static_cast<float>(strToDbl(ev.argument));
123 scroll(ev.view(), xx);
125 int const xx = strToInt(ev.argument);
126 scroll(ev.view(), xx);
128 ev.view()->updateInset(this);
136 int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
141 w = owner()->getMaxWidth(bv, this);
143 w = bv->text->workWidth(this);
148 // check for margins left/right and extra right margin "const 5"
149 if ((w - (2 * TEXT_TO_INSET_OFFSET + 5)) >= 0)
150 w -= 2 * TEXT_TO_INSET_OFFSET + 5;
152 // Deep magic. I don't understand this either.
153 if (owner() && owner()->owner()) {
154 // add the right paper margin
166 LyXCursor const & Inset::cursor(BufferView * bv) const
169 return owner()->getLyXText(bv, false)->cursor;
170 return bv->text->cursor;
175 UpdatableInset::selectNextWordToSpellcheck(BufferView *bv, float & value) const
177 // we have to unlock ourself in this function by default!
178 bv->unlockInset(const_cast<UpdatableInset *>(this));
180 return WordLangTuple();
184 bool UpdatableInset::nextChange(BufferView * bv, lyx::pos_type &)
186 // we have to unlock ourself in this function by default!
187 bv->unlockInset(const_cast<UpdatableInset *>(this));
192 bool UpdatableInset::searchForward(BufferView * bv, string const &,
195 // we have to unlock ourself in this function by default!
196 bv->unlockInset(const_cast<UpdatableInset *>(this));
201 bool UpdatableInset::searchBackward(BufferView * bv, string const &,
204 // we have to unlock ourself in this function by default!
205 bv->unlockInset(const_cast<UpdatableInset *>(this));