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
52 bool Inset::AutoDelete() const
58 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() << "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() << "Inset Button Release x=" << x
96 << ", y=" << y << ", button=" << button << endl;
100 void UpdatableInset::InsetKeyPress(XKeyEvent *)
102 lyxerr.debug() << "Inset Keypress" << endl;
106 void UpdatableInset::InsetMotionNotify(BufferView *, int x, int y, int state)
108 lyxerr.debug() << "Inset Motion Notify x=" << x
109 << ", y=" << y << ", state=" << state << endl;
113 void UpdatableInset::InsetUnlock(BufferView *)
115 lyxerr.debug() << "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 *)
131 void UpdatableInset::ShowInsetCursor(BufferView *, bool)
136 void UpdatableInset::HideInsetCursor(BufferView *)
141 void UpdatableInset::Edit(BufferView *, int, int, unsigned int)
146 void UpdatableInset::draw(BufferView *, LyXFont const &,
147 int /* baseline */, float & x, bool/*cleared*/) const
150 // ATTENTION: don't do the following here!!!
152 // top_baseline = baseline;
156 void UpdatableInset::SetFont(BufferView *, LyXFont const &, bool )
161 void UpdatableInset::scroll(BufferView * bv, float s) const
169 if (((top_x - scx) > 0) &&
170 (top_x - scx + width(bv, font)) < bv->workWidth())
172 if ((s > 0) && (top_x > 0))
175 // int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
178 scx = int(s*bv->workWidth()/2);
182 if ((top_x - save_scx + scx + width(bv, font)) < (bv->workWidth()/2)) {
183 scx += (bv->workWidth()/2) - (top_x - save_scx + 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);
211 /// An updatable inset could handle lyx editing commands
212 UpdatableInset::RESULT
213 UpdatableInset::LocalDispatch(BufferView * bv,
214 int action, string const & arg)
216 if (!arg.empty() && (action==LFUN_SCROLL_INSET)) {
217 if (arg.find('.') != arg.npos) {
218 float xx = static_cast<float>(strToDbl(arg));
221 int xx = strToInt(arg);
224 bv->updateInset(this, false);
232 int UpdatableInset::getMaxWidth(Painter & pain, UpdatableInset const *) const
235 return static_cast<UpdatableInset*>(owner())->getMaxWidth(pain, this);
236 return pain.paperWidth();