1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
14 #pragma implementation
19 #include "BufferView.h"
20 #include "support/lstrings.h"
22 #include "commandtags.h"
23 #include "support/lstrings.h"
29 // Insets default methods
31 bool Inset::deletable() const
37 bool Inset::directWrite() const
43 Inset::EDITABLE Inset::editable() const
49 void Inset::validate(LaTeXFeatures &) const
53 bool Inset::autoDelete() const
59 void Inset::edit(BufferView *, int, int, unsigned int)
63 LyXFont const Inset::convertFont(LyXFont const & font) const
69 string const Inset::editMessage() const
71 return _("Opened inset");
75 LyXText * Inset::getLyXText(BufferView const * bv, bool const) const
78 return owner()->getLyXText(bv, false);
84 // some stuff for inset locking
86 void UpdatableInset::insetButtonPress(BufferView *, int x, int y, int button)
88 lyxerr[Debug::INFO] << "Inset Button Press x=" << x
89 << ", y=" << y << ", button=" << button << endl;
93 void UpdatableInset::insetButtonRelease(BufferView *, int x, int y, int button)
95 lyxerr[Debug::INFO] << "Inset Button Release x=" << x
96 << ", y=" << y << ", button=" << button << endl;
100 void UpdatableInset::insetKeyPress(XKeyEvent *)
102 lyxerr[Debug::INFO] << "Inset Keypress" << endl;
106 void UpdatableInset::insetMotionNotify(BufferView *, int x, int y, int state)
108 lyxerr[Debug::INFO] << "Inset Motion Notify x=" << x
109 << ", y=" << y << ", state=" << state << endl;
113 void UpdatableInset::insetUnlock(BufferView *)
115 lyxerr[Debug::INFO] << "Inset Unlock" << endl;
119 // An updatable inset is highly editable by definition
120 Inset::EDITABLE UpdatableInset::editable() const
122 return HIGHLY_EDITABLE;
126 void UpdatableInset::toggleInsetCursor(BufferView *)
130 void UpdatableInset::showInsetCursor(BufferView *, bool)
134 void UpdatableInset::hideInsetCursor(BufferView *)
138 void UpdatableInset::edit(BufferView *, int, int, unsigned int)
142 void UpdatableInset::draw(BufferView *, LyXFont const &,
143 int /* baseline */, float & x,
144 bool/*cleared*/) const
147 // ATTENTION: don't do the following here!!!
149 // top_baseline = baseline;
153 void UpdatableInset::setFont(BufferView *, LyXFont const &, bool, bool )
157 void UpdatableInset::scroll(BufferView * bv, float s) const
166 int const workW = bv->workWidth();
167 int const tmp_top_x = top_x - scx;
170 (tmp_top_x + width(bv, font)) < workW)
172 if (s > 0 && top_x > 0)
175 // int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
176 //int const save_scx = scx;
178 scx = int(s * workW / 2);
182 if ((tmp_top_x + scx + width(bv, font)) < (workW / 2)) {
183 scx += (workW / 2) - (tmp_top_x + scx + width(bv, font));
186 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
189 void UpdatableInset::scroll(BufferView * bv, int offset) const
192 if (!scx && top_x >= 20)
194 if ((top_x + offset) > 20)
196 // scx += offset - (top_x - scx + offset - 20);
201 if (!scx && (top_x + width(bv, font)) < (bv->workWidth() - 20))
203 if ((top_x - scx + offset + width(bv, font)) < (bv->workWidth() - 20)) {
204 scx = bv->workWidth() - width(bv, font) - top_x + scx - 20;
209 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
213 /// An updatable inset could handle lyx editing commands
214 UpdatableInset::RESULT
215 UpdatableInset::localDispatch(BufferView * bv,
216 kb_action action, string const & arg)
218 if (!arg.empty() && (action==LFUN_SCROLL_INSET)) {
219 if (arg.find('.') != arg.npos) {
220 float const xx = static_cast<float>(strToDbl(arg));
223 int const xx = strToInt(arg);
226 bv->updateInset(this, false);
234 int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
237 return static_cast<UpdatableInset*>
238 (owner())->getMaxWidth(bv, this);
239 return bv->workWidth();