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 // some stuff for inset locking
140 UpdatableInset::UpdatableInset()
141 : Inset(), cursor_visible_(false), block_drawing_(false)
145 UpdatableInset::UpdatableInset(UpdatableInset const & in, bool same_id)
146 : Inset(in, same_id), cursor_visible_(false), block_drawing_(false)
150 void UpdatableInset::insetButtonPress(BufferView *, int x, int y, int button)
152 lyxerr[Debug::INFO] << "Inset Button Press x=" << x
153 << ", y=" << y << ", button=" << button << endl;
157 void UpdatableInset::insetButtonRelease(BufferView *, int x, int y, int button)
159 lyxerr[Debug::INFO] << "Inset Button Release x=" << x
160 << ", y=" << y << ", button=" << button << endl;
164 void UpdatableInset::insetKeyPress(XKeyEvent *)
166 lyxerr[Debug::INFO] << "Inset Keypress" << endl;
170 void UpdatableInset::insetMotionNotify(BufferView *, int x, int y, int state)
172 lyxerr[Debug::INFO] << "Inset Motion Notify x=" << x
173 << ", y=" << y << ", state=" << state << endl;
177 void UpdatableInset::insetUnlock(BufferView *)
179 lyxerr[Debug::INFO] << "Inset Unlock" << endl;
183 // An updatable inset is highly editable by definition
184 Inset::EDITABLE UpdatableInset::editable() const
186 return HIGHLY_EDITABLE;
190 void UpdatableInset::toggleInsetCursor(BufferView *)
194 void UpdatableInset::showInsetCursor(BufferView *, bool)
198 void UpdatableInset::hideInsetCursor(BufferView *)
202 void UpdatableInset::fitInsetCursor(BufferView *) const
206 void UpdatableInset::edit(BufferView *, int, int, unsigned int)
210 void UpdatableInset::edit(BufferView *, bool)
214 void UpdatableInset::draw(BufferView *, LyXFont const &,
215 int /* baseline */, float & x,
216 bool/*cleared*/) const
219 // ATTENTION: don't do the following here!!!
221 // top_baseline = baseline;
225 void UpdatableInset::setFont(BufferView *, LyXFont const &, bool, bool )
229 void UpdatableInset::scroll(BufferView * bv, float s) const
238 int const workW = bv->workWidth();
239 int const tmp_top_x = top_x - scx;
242 (tmp_top_x + width(bv, font)) < workW)
244 if (s > 0 && top_x > 0)
247 // int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
248 //int const save_scx = scx;
250 scx = int(s * workW / 2);
254 if ((tmp_top_x + scx + width(bv, font)) < (workW / 2)) {
255 scx += (workW / 2) - (tmp_top_x + scx + width(bv, font));
258 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
261 void UpdatableInset::scroll(BufferView * bv, int offset) const
264 if (!scx && top_x >= 20)
266 if ((top_x + offset) > 20)
268 // scx += offset - (top_x - scx + offset - 20);
273 if (!scx && (top_x + width(bv, font)) < (bv->workWidth() - 20))
275 if ((top_x - scx + offset + width(bv, font)) < (bv->workWidth() - 20)) {
276 scx = bv->workWidth() - width(bv, font) - top_x + scx - 20;
281 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
285 /// An updatable inset could handle lyx editing commands
286 UpdatableInset::RESULT
287 UpdatableInset::localDispatch(BufferView * bv,
288 kb_action action, string const & arg)
290 if (!arg.empty() && (action==LFUN_SCROLL_INSET)) {
291 if (arg.find('.') != arg.npos) {
292 float const xx = static_cast<float>(strToDbl(arg));
295 int const xx = strToInt(arg);
298 bv->updateInset(this, false);
306 int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
309 return static_cast<UpdatableInset*>
310 (owner())->getMaxWidth(bv, this);
311 return bv->workWidth();
315 LyXCursor const & Inset::cursor(BufferView * bv) const
317 return bv->text->cursor;
321 string const UpdatableInset::selectNextWord(BufferView *bv,
324 // we have to unlock ourself in this function by default!
325 bv->unlockInset(const_cast<UpdatableInset *>(this));
331 bool UpdatableInset::searchForward(BufferView * bv, string const &,
332 bool const &, bool const &)
334 // we have to unlock ourself in this function by default!
335 bv->unlockInset(const_cast<UpdatableInset *>(this));
340 bool UpdatableInset::searchBackward(BufferView * bv, string const &,
341 bool const &, bool const &)
343 // we have to unlock ourself in this function by default!
344 bv->unlockInset(const_cast<UpdatableInset *>(this));