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 void Inset::edit(BufferView *, bool)
72 LyXFont const Inset::convertFont(LyXFont const & font) const
78 string const Inset::editMessage() const
80 return _("Opened inset");
84 LyXText * Inset::getLyXText(BufferView const * bv, bool const) const
87 return owner()->getLyXText(bv, false);
98 void Inset::id(int id_arg)
103 // some stuff for inset locking
105 void UpdatableInset::insetButtonPress(BufferView *, int x, int y, int button)
107 lyxerr[Debug::INFO] << "Inset Button Press x=" << x
108 << ", y=" << y << ", button=" << button << endl;
112 void UpdatableInset::insetButtonRelease(BufferView *, int x, int y, int button)
114 lyxerr[Debug::INFO] << "Inset Button Release x=" << x
115 << ", y=" << y << ", button=" << button << endl;
119 void UpdatableInset::insetKeyPress(XKeyEvent *)
121 lyxerr[Debug::INFO] << "Inset Keypress" << endl;
125 void UpdatableInset::insetMotionNotify(BufferView *, int x, int y, int state)
127 lyxerr[Debug::INFO] << "Inset Motion Notify x=" << x
128 << ", y=" << y << ", state=" << state << endl;
132 void UpdatableInset::insetUnlock(BufferView *)
134 lyxerr[Debug::INFO] << "Inset Unlock" << endl;
138 // An updatable inset is highly editable by definition
139 Inset::EDITABLE UpdatableInset::editable() const
141 return HIGHLY_EDITABLE;
145 void UpdatableInset::toggleInsetCursor(BufferView *)
149 void UpdatableInset::showInsetCursor(BufferView *, bool)
153 void UpdatableInset::hideInsetCursor(BufferView *)
157 void UpdatableInset::fitInsetCursor(BufferView *) const
161 void UpdatableInset::edit(BufferView *, int, int, unsigned int)
165 void UpdatableInset::edit(BufferView *, bool)
169 void UpdatableInset::draw(BufferView *, LyXFont const &,
170 int /* baseline */, float & x,
171 bool/*cleared*/) const
174 // ATTENTION: don't do the following here!!!
176 // top_baseline = baseline;
180 void UpdatableInset::setFont(BufferView *, LyXFont const &, bool, bool )
184 void UpdatableInset::scroll(BufferView * bv, float s) const
193 int const workW = bv->workWidth();
194 int const tmp_top_x = top_x - scx;
197 (tmp_top_x + width(bv, font)) < workW)
199 if (s > 0 && top_x > 0)
202 // int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
203 //int const save_scx = scx;
205 scx = int(s * workW / 2);
209 if ((tmp_top_x + scx + width(bv, font)) < (workW / 2)) {
210 scx += (workW / 2) - (tmp_top_x + scx + width(bv, font));
213 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
216 void UpdatableInset::scroll(BufferView * bv, int offset) const
219 if (!scx && top_x >= 20)
221 if ((top_x + offset) > 20)
223 // scx += offset - (top_x - scx + offset - 20);
228 if (!scx && (top_x + width(bv, font)) < (bv->workWidth() - 20))
230 if ((top_x - scx + offset + width(bv, font)) < (bv->workWidth() - 20)) {
231 scx = bv->workWidth() - width(bv, font) - top_x + scx - 20;
236 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
240 /// An updatable inset could handle lyx editing commands
241 UpdatableInset::RESULT
242 UpdatableInset::localDispatch(BufferView * bv,
243 kb_action action, string const & arg)
245 if (!arg.empty() && (action==LFUN_SCROLL_INSET)) {
246 if (arg.find('.') != arg.npos) {
247 float const xx = static_cast<float>(strToDbl(arg));
250 int const xx = strToInt(arg);
253 bv->updateInset(this, false);
261 int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
264 return static_cast<UpdatableInset*>
265 (owner())->getMaxWidth(bv, this);
266 return bv->workWidth();
269 LyXCursor const & Inset::cursor(BufferView * bv) const
271 return bv->text->cursor;
274 string UpdatableInset::selectNextWord(BufferView *bv, float & value) const
276 // we have to unlock ourself in this function by default!
277 bv->unlockInset(const_cast<UpdatableInset *>(this));
282 bool UpdatableInset::searchForward(BufferView * bv, string const &,
283 bool const &, bool const &)
285 // we have to unlock ourself in this function by default!
286 bv->unlockInset(const_cast<UpdatableInset *>(this));
290 bool UpdatableInset::searchBackward(BufferView * bv, string const &,
291 bool const &, bool const &)
293 // we have to unlock ourself in this function by default!
294 bv->unlockInset(const_cast<UpdatableInset *>(this));