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"
21 #include "BufferView.h"
22 #include "support/lstrings.h"
25 #include "commandtags.h"
26 #include "support/lstrings.h"
31 /* Insets default methods */
33 bool Inset::Deletable() const
39 bool Inset::DirectWrite() const
45 Inset::EDITABLE Inset::Editable() const
51 void Inset::Validate(LaTeXFeatures &) const
56 bool Inset::AutoDelete() const
62 void Inset::Edit(BufferView *, int, int, unsigned int)
67 LyXFont const Inset::ConvertFont(LyXFont const & font) const
73 string const Inset::EditMessage() const
75 return _("Opened inset");
79 LyXText * Inset::getLyXText(BufferView const * bv) const
82 return owner()->getLyXText(bv);
88 /* some stuff for inset locking */
90 void UpdatableInset::InsetButtonPress(BufferView *, int x, int y, int button)
92 lyxerr.debug() << "Inset Button Press x=" << x
93 << ", y=" << y << ", button=" << button << endl;
97 void UpdatableInset::InsetButtonRelease(BufferView *, int x, int y, int button)
99 lyxerr.debug() << "Inset Button Release x=" << x
100 << ", y=" << y << ", button=" << button << endl;
104 void UpdatableInset::InsetKeyPress(XKeyEvent *)
106 lyxerr.debug() << "Inset Keypress" << endl;
110 void UpdatableInset::InsetMotionNotify(BufferView *, int x, int y, int state)
112 lyxerr.debug() << "Inset Motion Notify x=" << x
113 << ", y=" << y << ", state=" << state << endl;
117 void UpdatableInset::InsetUnlock(BufferView *)
119 lyxerr.debug() << "Inset Unlock" << endl;
123 // An updatable inset is highly editable by definition
124 Inset::EDITABLE UpdatableInset::Editable() const
126 return HIGHLY_EDITABLE;
130 void UpdatableInset::ToggleInsetCursor(BufferView *)
135 void UpdatableInset::ShowInsetCursor(BufferView *, bool)
140 void UpdatableInset::HideInsetCursor(BufferView *)
145 void UpdatableInset::Edit(BufferView *, int, int, unsigned int)
150 void UpdatableInset::draw(BufferView *, LyXFont const &,
151 int /* baseline */, float & x, bool/*cleared*/) const
154 // ATTENTION: don't do the following here!!!
156 // top_baseline = baseline;
160 void UpdatableInset::SetFont(BufferView *, LyXFont const &, bool )
166 void UpdatableInset::scroll(BufferView * bv, float s) const
174 if (((top_x - scx) > 0) &&
175 (top_x - scx + width(bv, font)) < bv->workWidth())
177 if ((s > 0) && (top_x > 0))
180 // int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
183 scx = int(s*bv->workWidth()/2);
187 if ((top_x - save_scx + scx + width(bv, font)) < (bv->workWidth()/2)) {
188 scx += (bv->workWidth()/2) - (top_x - save_scx + scx + width(bv,font));
190 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
193 void UpdatableInset::scroll(BufferView * bv, int offset) const
196 if (!scx && top_x >= 20)
198 if ((top_x + offset) > 20)
199 scx += offset - (top_x - scx + offset - 20);
204 if (!scx && (top_x+width(bv, font)) < (bv->workWidth()-20))
206 if ((top_x - scx + offset + width(bv,font)) < (bv->workWidth()-20)) {
207 scx = bv->workWidth() - width(bv,font) - top_x + scx - 20;
212 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
218 /// An updatable inset could handle lyx editing commands
220 UpdatableInset::RESULT
221 UpdatableInset::LocalDispatch(BufferView * bv,
222 int action, string const & arg)
224 UpdatableInset::RESULT
225 UpdatableInset::LocalDispatch(BufferView *, int, string const &)
230 if (!arg.empty() && (action==LFUN_SCROLL_INSET)) {
231 if (arg.find('.') != arg.npos) {
232 float xx = static_cast<float>(strToDbl(arg));
235 int xx = strToInt(arg);
238 bv->updateInset(this, false);
247 int UpdatableInset::getMaxWidth(Painter & pain, UpdatableInset const *) const
250 return static_cast<UpdatableInset*>(owner())->getMaxWidth(pain, this);
251 return pain.paperWidth();