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;
37 : top_x(0), top_baseline(0), scx(0), id_(inset_id++), owner_(0),
38 background_color_(LColor::inherit)
42 Inset::Inset(Inset const & in, bool same_id)
43 : top_x(0), top_baseline(0), scx(0), owner_(0), name_(in.name_),
44 background_color_(in.background_color_)
53 bool Inset::deletable() const
59 bool Inset::directWrite() const
65 Inset::EDITABLE Inset::editable() const
71 void Inset::validate(LaTeXFeatures &) const
75 bool Inset::autoDelete() const
81 void Inset::edit(BufferView *, int, int, unsigned int)
85 void Inset::edit(BufferView *, bool)
89 LyXFont const Inset::convertFont(LyXFont const & font) const
95 string const Inset::editMessage() const
97 return _("Opened inset");
101 LyXText * Inset::getLyXText(BufferView const * bv, bool const) const
104 return owner()->getLyXText(bv, false);
110 void Inset::setBackgroundColor(LColor::color color)
112 background_color_ = color;
116 LColor::color Inset::backgroundColor() const
118 if (background_color_ == LColor::inherit) {
120 return owner()->backgroundColor();
122 return LColor::background;
124 return background_color_;
128 int Inset::id() const
133 void Inset::id(int id_arg)
138 void Inset::setFont(BufferView *, LyXFont const &, bool, bool )
141 // some stuff for inset locking
143 UpdatableInset::UpdatableInset()
144 : Inset(), cursor_visible_(false), block_drawing_(false)
148 UpdatableInset::UpdatableInset(UpdatableInset const & in, bool same_id)
149 : Inset(in, same_id), cursor_visible_(false), block_drawing_(false)
153 void UpdatableInset::insetButtonPress(BufferView *, int x, int y, int button)
155 lyxerr[Debug::INFO] << "Inset Button Press x=" << x
156 << ", y=" << y << ", button=" << button << endl;
160 void UpdatableInset::insetButtonRelease(BufferView *, int x, int y, int button)
162 lyxerr[Debug::INFO] << "Inset Button Release x=" << x
163 << ", y=" << y << ", button=" << button << endl;
167 void UpdatableInset::insetKeyPress(XKeyEvent *)
169 lyxerr[Debug::INFO] << "Inset Keypress" << endl;
173 void UpdatableInset::insetMotionNotify(BufferView *, int x, int y, int state)
175 lyxerr[Debug::INFO] << "Inset Motion Notify x=" << x
176 << ", y=" << y << ", state=" << state << endl;
180 void UpdatableInset::insetUnlock(BufferView *)
182 lyxerr[Debug::INFO] << "Inset Unlock" << endl;
186 // An updatable inset is highly editable by definition
187 Inset::EDITABLE UpdatableInset::editable() const
189 return HIGHLY_EDITABLE;
193 void UpdatableInset::toggleInsetCursor(BufferView *)
197 void UpdatableInset::showInsetCursor(BufferView *, bool)
201 void UpdatableInset::hideInsetCursor(BufferView *)
205 void UpdatableInset::fitInsetCursor(BufferView *) const
209 void UpdatableInset::edit(BufferView *, int, int, unsigned int)
213 void UpdatableInset::edit(BufferView *, bool)
217 void UpdatableInset::draw(BufferView *, LyXFont const &,
218 int /* baseline */, float & x,
219 bool/*cleared*/) const
222 // ATTENTION: don't do the following here!!!
224 // top_baseline = baseline;
228 void UpdatableInset::scroll(BufferView * bv, float s) const
237 int const workW = bv->workWidth();
238 int const tmp_top_x = top_x - scx;
241 (tmp_top_x + width(bv, font)) < workW)
243 if (s > 0 && top_x > 0)
246 // int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
247 //int const save_scx = scx;
249 scx = int(s * workW / 2);
253 if ((tmp_top_x + scx + width(bv, font)) < (workW / 2)) {
254 scx += (workW / 2) - (tmp_top_x + scx + width(bv, font));
257 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
260 void UpdatableInset::scroll(BufferView * bv, int offset) const
263 if (!scx && top_x >= 20)
265 if ((top_x + offset) > 20)
267 // scx += offset - (top_x - scx + offset - 20);
272 if (!scx && (top_x + width(bv, font)) < (bv->workWidth() - 20))
274 if ((top_x - scx + offset + width(bv, font)) < (bv->workWidth() - 20)) {
275 scx = bv->workWidth() - width(bv, font) - top_x + scx - 20;
280 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
284 /// An updatable inset could handle lyx editing commands
285 UpdatableInset::RESULT
286 UpdatableInset::localDispatch(BufferView * bv,
287 kb_action action, string const & arg)
289 if (!arg.empty() && (action==LFUN_SCROLL_INSET)) {
290 if (arg.find('.') != arg.npos) {
291 float const xx = static_cast<float>(strToDbl(arg));
294 int const xx = strToInt(arg);
297 bv->updateInset(this, false);
305 int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
308 return static_cast<UpdatableInset*>
309 (owner())->getMaxWidth(bv, this);
310 return bv->workWidth();
314 LyXCursor const & Inset::cursor(BufferView * bv) const
316 return bv->text->cursor;
320 string const UpdatableInset::selectNextWord(BufferView *bv,
323 // we have to unlock ourself in this function by default!
324 bv->unlockInset(const_cast<UpdatableInset *>(this));
330 bool UpdatableInset::searchForward(BufferView * bv, string const &,
331 bool const &, bool const &)
333 // we have to unlock ourself in this function by default!
334 bv->unlockInset(const_cast<UpdatableInset *>(this));
339 bool UpdatableInset::searchBackward(BufferView * bv, string const &,
340 bool const &, bool const &)
342 // we have to unlock ourself in this function by default!
343 bv->unlockInset(const_cast<UpdatableInset *>(this));