1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
14 #pragma implementation "lyxinset.h"
19 #include "BufferView.h"
20 #include "support/lstrings.h"
22 #include "commandtags.h"
23 #include "support/lstrings.h"
28 // Insets default methods
30 bool Inset::Deletable() const
36 bool Inset::DirectWrite() const
42 Inset::EDITABLE Inset::Editable() const
48 void Inset::Validate(LaTeXFeatures &) const
52 bool Inset::AutoDelete() const
58 void Inset::Edit(BufferView *, int, int, unsigned int)
62 LyXFont const Inset::ConvertFont(LyXFont const & font) const
68 string const Inset::EditMessage() const
70 return _("Opened inset");
74 LyXText * Inset::getLyXText(BufferView const * bv, bool const) const
77 return owner()->getLyXText(bv, false);
83 // some stuff for inset locking
85 void UpdatableInset::InsetButtonPress(BufferView *, int x, int y, int button)
87 lyxerr.debug() << "Inset Button Press x=" << x
88 << ", y=" << y << ", button=" << button << endl;
92 void UpdatableInset::InsetButtonRelease(BufferView *, int x, int y, int button)
94 lyxerr.debug() << "Inset Button Release x=" << x
95 << ", y=" << y << ", button=" << button << endl;
99 void UpdatableInset::InsetKeyPress(XKeyEvent *)
101 lyxerr.debug() << "Inset Keypress" << endl;
105 void UpdatableInset::InsetMotionNotify(BufferView *, int x, int y, int state)
107 lyxerr.debug() << "Inset Motion Notify x=" << x
108 << ", y=" << y << ", state=" << state << endl;
112 void UpdatableInset::InsetUnlock(BufferView *)
114 lyxerr.debug() << "Inset Unlock" << endl;
118 // An updatable inset is highly editable by definition
119 Inset::EDITABLE UpdatableInset::Editable() const
121 return HIGHLY_EDITABLE;
125 void UpdatableInset::ToggleInsetCursor(BufferView *)
129 void UpdatableInset::ShowInsetCursor(BufferView *, bool)
133 void UpdatableInset::HideInsetCursor(BufferView *)
137 void UpdatableInset::Edit(BufferView *, int, int, unsigned int)
141 void UpdatableInset::draw(BufferView *, LyXFont const &,
142 int /* baseline */, float & x,
143 bool/*cleared*/) const
146 // ATTENTION: don't do the following here!!!
148 // top_baseline = baseline;
152 void UpdatableInset::SetFont(BufferView *, LyXFont const &, bool, bool )
156 void UpdatableInset::scroll(BufferView * bv, float s) const
165 int const workW = bv->workWidth();
166 int const tmp_top_x = top_x - scx;
169 (tmp_top_x + width(bv, font)) < workW)
171 if (s > 0 && top_x > 0)
174 // int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
175 //int const save_scx = scx;
177 scx = int(s * workW / 2);
181 if ((tmp_top_x + scx + width(bv, font)) < (workW / 2)) {
182 scx += (workW / 2) - (tmp_top_x + scx + width(bv, font));
185 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
188 void UpdatableInset::scroll(BufferView * bv, int offset) const
191 if (!scx && top_x >= 20)
193 if ((top_x + offset) > 20)
195 // scx += offset - (top_x - scx + offset - 20);
200 if (!scx && (top_x + width(bv, font)) < (bv->workWidth() - 20))
202 if ((top_x - scx + offset + width(bv, font)) < (bv->workWidth() - 20)) {
203 scx = bv->workWidth() - width(bv, font) - top_x + scx - 20;
208 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
212 /// An updatable inset could handle lyx editing commands
213 UpdatableInset::RESULT
214 UpdatableInset::LocalDispatch(BufferView * bv,
215 kb_action action, string const & arg)
217 if (!arg.empty() && (action==LFUN_SCROLL_INSET)) {
218 if (arg.find('.') != arg.npos) {
219 float const xx = static_cast<float>(strToDbl(arg));
222 int const xx = strToInt(arg);
225 bv->updateInset(this, false);
233 int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
236 return static_cast<UpdatableInset*>
237 (owner())->getMaxWidth(bv, this);
238 return bv->workWidth();