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"
27 // Insets default methods
29 bool Inset::Deletable() const
35 bool Inset::DirectWrite() const
41 Inset::EDITABLE Inset::Editable() const
47 void Inset::Validate(LaTeXFeatures &) const
51 bool Inset::AutoDelete() const
57 void Inset::Edit(BufferView *, int, int, unsigned int)
61 LyXFont const Inset::ConvertFont(LyXFont const & font) const
67 string const Inset::EditMessage() const
69 return _("Opened inset");
73 LyXText * Inset::getLyXText(BufferView const * bv, bool const) const
76 return owner()->getLyXText(bv, false);
82 // some stuff for inset locking
84 void UpdatableInset::InsetButtonPress(BufferView *, int x, int y, int button)
86 lyxerr.debug() << "Inset Button Press x=" << x
87 << ", y=" << y << ", button=" << button << endl;
91 void UpdatableInset::InsetButtonRelease(BufferView *, int x, int y, int button)
93 lyxerr.debug() << "Inset Button Release x=" << x
94 << ", y=" << y << ", button=" << button << endl;
98 void UpdatableInset::InsetKeyPress(XKeyEvent *)
100 lyxerr.debug() << "Inset Keypress" << endl;
104 void UpdatableInset::InsetMotionNotify(BufferView *, int x, int y, int state)
106 lyxerr.debug() << "Inset Motion Notify x=" << x
107 << ", y=" << y << ", state=" << state << endl;
111 void UpdatableInset::InsetUnlock(BufferView *)
113 lyxerr.debug() << "Inset Unlock" << endl;
117 // An updatable inset is highly editable by definition
118 Inset::EDITABLE UpdatableInset::Editable() const
120 return HIGHLY_EDITABLE;
124 void UpdatableInset::ToggleInsetCursor(BufferView *)
128 void UpdatableInset::ShowInsetCursor(BufferView *, bool)
132 void UpdatableInset::HideInsetCursor(BufferView *)
136 void UpdatableInset::Edit(BufferView *, int, int, unsigned int)
140 void UpdatableInset::draw(BufferView *, LyXFont const &,
141 int /* baseline */, float & x,
142 bool/*cleared*/) const
145 // ATTENTION: don't do the following here!!!
147 // top_baseline = baseline;
151 void UpdatableInset::SetFont(BufferView *, LyXFont const &, bool )
155 void UpdatableInset::scroll(BufferView * bv, float s) const
164 int const workW = bv->workWidth();
165 int const tmp_top_x = top_x - scx;
168 (tmp_top_x + width(bv, font)) < workW)
170 if (s > 0 && top_x > 0)
173 // int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
174 //int const save_scx = scx;
176 scx = int(s * workW / 2);
180 if ((tmp_top_x + scx + width(bv, font)) < (workW / 2)) {
181 scx += (workW / 2) - (tmp_top_x + scx + width(bv, font));
183 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
186 void UpdatableInset::scroll(BufferView * bv, int offset) const
189 if (!scx && top_x >= 20)
191 if ((top_x + offset) > 20)
193 // scx += offset - (top_x - scx + offset - 20);
198 if (!scx && (top_x + width(bv, font)) < (bv->workWidth() - 20))
200 if ((top_x - scx + offset + width(bv, font)) < (bv->workWidth() - 20)) {
201 scx = bv->workWidth() - width(bv, font) - top_x + scx - 20;
206 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
210 /// An updatable inset could handle lyx editing commands
211 UpdatableInset::RESULT
212 UpdatableInset::LocalDispatch(BufferView * bv,
213 kb_action action, string const & arg)
215 if (!arg.empty() && (action==LFUN_SCROLL_INSET)) {
216 if (arg.find('.') != arg.npos) {
217 float const xx = static_cast<float>(strToDbl(arg));
220 int const xx = strToInt(arg);
223 bv->updateInset(this, false);
231 int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
234 return static_cast<UpdatableInset*>
235 (owner())->getMaxWidth(bv, this);
236 return bv->workWidth();