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"
26 #include "lyxcursor.h"
31 // Insets default methods
33 // Initialization of the counter for the inset id's,
34 unsigned int Inset::inset_id = 0;
36 bool Inset::deletable() const
42 bool Inset::directWrite() const
48 Inset::EDITABLE Inset::editable() const
54 void Inset::validate(LaTeXFeatures &) const
58 bool Inset::autoDelete() const
64 void Inset::edit(BufferView *, int, int, unsigned int)
68 LyXFont const Inset::convertFont(LyXFont const & font) const
74 string const Inset::editMessage() const
76 return _("Opened inset");
80 LyXText * Inset::getLyXText(BufferView const * bv, bool const) const
83 return owner()->getLyXText(bv, false);
94 void Inset::id(int id_arg)
99 // some stuff for inset locking
101 void UpdatableInset::insetButtonPress(BufferView *, int x, int y, int button)
103 lyxerr[Debug::INFO] << "Inset Button Press x=" << x
104 << ", y=" << y << ", button=" << button << endl;
108 void UpdatableInset::insetButtonRelease(BufferView *, int x, int y, int button)
110 lyxerr[Debug::INFO] << "Inset Button Release x=" << x
111 << ", y=" << y << ", button=" << button << endl;
115 void UpdatableInset::insetKeyPress(XKeyEvent *)
117 lyxerr[Debug::INFO] << "Inset Keypress" << endl;
121 void UpdatableInset::insetMotionNotify(BufferView *, int x, int y, int state)
123 lyxerr[Debug::INFO] << "Inset Motion Notify x=" << x
124 << ", y=" << y << ", state=" << state << endl;
128 void UpdatableInset::insetUnlock(BufferView *)
130 lyxerr[Debug::INFO] << "Inset Unlock" << endl;
134 // An updatable inset is highly editable by definition
135 Inset::EDITABLE UpdatableInset::editable() const
137 return HIGHLY_EDITABLE;
141 void UpdatableInset::toggleInsetCursor(BufferView *)
145 void UpdatableInset::showInsetCursor(BufferView *, bool)
149 void UpdatableInset::hideInsetCursor(BufferView *)
153 void UpdatableInset::edit(BufferView *, int, int, unsigned int)
157 void UpdatableInset::draw(BufferView *, LyXFont const &,
158 int /* baseline */, float & x,
159 bool/*cleared*/) const
162 // ATTENTION: don't do the following here!!!
164 // top_baseline = baseline;
168 void UpdatableInset::setFont(BufferView *, LyXFont const &, bool, bool )
172 void UpdatableInset::scroll(BufferView * bv, float s) const
181 int const workW = bv->workWidth();
182 int const tmp_top_x = top_x - scx;
185 (tmp_top_x + width(bv, font)) < workW)
187 if (s > 0 && top_x > 0)
190 // int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
191 //int const save_scx = scx;
193 scx = int(s * workW / 2);
197 if ((tmp_top_x + scx + width(bv, font)) < (workW / 2)) {
198 scx += (workW / 2) - (tmp_top_x + scx + width(bv, font));
201 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
204 void UpdatableInset::scroll(BufferView * bv, int offset) const
207 if (!scx && top_x >= 20)
209 if ((top_x + offset) > 20)
211 // scx += offset - (top_x - scx + offset - 20);
216 if (!scx && (top_x + width(bv, font)) < (bv->workWidth() - 20))
218 if ((top_x - scx + offset + width(bv, font)) < (bv->workWidth() - 20)) {
219 scx = bv->workWidth() - width(bv, font) - top_x + scx - 20;
224 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
228 /// An updatable inset could handle lyx editing commands
229 UpdatableInset::RESULT
230 UpdatableInset::localDispatch(BufferView * bv,
231 kb_action action, string const & arg)
233 if (!arg.empty() && (action==LFUN_SCROLL_INSET)) {
234 if (arg.find('.') != arg.npos) {
235 float const xx = static_cast<float>(strToDbl(arg));
238 int const xx = strToInt(arg);
241 bv->updateInset(this, false);
249 int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
252 return static_cast<UpdatableInset*>
253 (owner())->getMaxWidth(bv, this);
254 return bv->workWidth();
257 LyXCursor const & Inset::cursor(BufferView * bv) const
259 return bv->text->cursor;
262 string UpdatableInset::selectNextWord(BufferView *bv, float & value) const
264 // we have to unlock ourself in this function by default!
265 bv->unlockInset(const_cast<UpdatableInset *>(this));