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);
93 void Inset::setBackgroundColor(LColor::color color)
95 background_color_ = color;
99 LColor::color Inset::backgroundColor() const
101 if (background_color_ == LColor::inherit) {
103 return owner()->backgroundColor();
105 return LColor::background;
107 return background_color_;
111 int Inset::id() const
116 void Inset::id(int id_arg)
121 // some stuff for inset locking
123 void UpdatableInset::insetButtonPress(BufferView *, int x, int y, int button)
125 lyxerr[Debug::INFO] << "Inset Button Press x=" << x
126 << ", y=" << y << ", button=" << button << endl;
130 void UpdatableInset::insetButtonRelease(BufferView *, int x, int y, int button)
132 lyxerr[Debug::INFO] << "Inset Button Release x=" << x
133 << ", y=" << y << ", button=" << button << endl;
137 void UpdatableInset::insetKeyPress(XKeyEvent *)
139 lyxerr[Debug::INFO] << "Inset Keypress" << endl;
143 void UpdatableInset::insetMotionNotify(BufferView *, int x, int y, int state)
145 lyxerr[Debug::INFO] << "Inset Motion Notify x=" << x
146 << ", y=" << y << ", state=" << state << endl;
150 void UpdatableInset::insetUnlock(BufferView *)
152 lyxerr[Debug::INFO] << "Inset Unlock" << endl;
156 // An updatable inset is highly editable by definition
157 Inset::EDITABLE UpdatableInset::editable() const
159 return HIGHLY_EDITABLE;
163 void UpdatableInset::toggleInsetCursor(BufferView *)
167 void UpdatableInset::showInsetCursor(BufferView *, bool)
171 void UpdatableInset::hideInsetCursor(BufferView *)
175 void UpdatableInset::fitInsetCursor(BufferView *) const
179 void UpdatableInset::edit(BufferView *, int, int, unsigned int)
183 void UpdatableInset::edit(BufferView *, bool)
187 void UpdatableInset::draw(BufferView *, LyXFont const &,
188 int /* baseline */, float & x,
189 bool/*cleared*/) const
192 // ATTENTION: don't do the following here!!!
194 // top_baseline = baseline;
198 void UpdatableInset::setFont(BufferView *, LyXFont const &, bool, bool )
202 void UpdatableInset::scroll(BufferView * bv, float s) const
211 int const workW = bv->workWidth();
212 int const tmp_top_x = top_x - scx;
215 (tmp_top_x + width(bv, font)) < workW)
217 if (s > 0 && top_x > 0)
220 // int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
221 //int const save_scx = scx;
223 scx = int(s * workW / 2);
227 if ((tmp_top_x + scx + width(bv, font)) < (workW / 2)) {
228 scx += (workW / 2) - (tmp_top_x + scx + width(bv, font));
231 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
234 void UpdatableInset::scroll(BufferView * bv, int offset) const
237 if (!scx && top_x >= 20)
239 if ((top_x + offset) > 20)
241 // scx += offset - (top_x - scx + offset - 20);
246 if (!scx && (top_x + width(bv, font)) < (bv->workWidth() - 20))
248 if ((top_x - scx + offset + width(bv, font)) < (bv->workWidth() - 20)) {
249 scx = bv->workWidth() - width(bv, font) - top_x + scx - 20;
254 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
258 /// An updatable inset could handle lyx editing commands
259 UpdatableInset::RESULT
260 UpdatableInset::localDispatch(BufferView * bv,
261 kb_action action, string const & arg)
263 if (!arg.empty() && (action==LFUN_SCROLL_INSET)) {
264 if (arg.find('.') != arg.npos) {
265 float const xx = static_cast<float>(strToDbl(arg));
268 int const xx = strToInt(arg);
271 bv->updateInset(this, false);
279 int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
282 return static_cast<UpdatableInset*>
283 (owner())->getMaxWidth(bv, this);
284 return bv->workWidth();
287 LyXCursor const & Inset::cursor(BufferView * bv) const
289 return bv->text->cursor;
292 string UpdatableInset::selectNextWord(BufferView *bv, float & value) const
294 // we have to unlock ourself in this function by default!
295 bv->unlockInset(const_cast<UpdatableInset *>(this));
300 bool UpdatableInset::searchForward(BufferView * bv, string const &,
301 bool const &, bool const &)
303 // we have to unlock ourself in this function by default!
304 bv->unlockInset(const_cast<UpdatableInset *>(this));
308 bool UpdatableInset::searchBackward(BufferView * bv, string const &,
309 bool const &, bool const &)
311 // we have to unlock ourself in this function by default!
312 bv->unlockInset(const_cast<UpdatableInset *>(this));