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), topx_set(false), top_baseline(0), scx(0),
38 id_(inset_id++), owner_(0), background_color_(LColor::inherit)
42 Inset::Inset(Inset const & in, bool same_id)
43 : top_x(0), topx_set(false), top_baseline(0), scx(0), owner_(0),
44 name_(in.name_), 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)
90 LyXFont const Inset::convertFont(LyXFont const & font) const
101 string const Inset::editMessage() const
103 return _("Opened inset");
107 LyXText * Inset::getLyXText(BufferView const * bv, bool const) const
110 return owner()->getLyXText(bv, false);
116 void Inset::setBackgroundColor(LColor::color color)
118 background_color_ = color;
122 LColor::color Inset::backgroundColor() const
124 if (background_color_ == LColor::inherit) {
126 return owner()->backgroundColor();
128 return LColor::background;
130 return background_color_;
134 int Inset::id() const
139 void Inset::id(int id_arg)
144 void Inset::setFont(BufferView *, LyXFont const &, bool, bool )
147 // some stuff for inset locking
149 UpdatableInset::UpdatableInset()
150 : Inset(), cursor_visible_(false), block_drawing_(false)
154 UpdatableInset::UpdatableInset(UpdatableInset const & in, bool same_id)
155 : Inset(in, same_id), cursor_visible_(false), block_drawing_(false)
159 void UpdatableInset::insetButtonPress(BufferView *, int x, int y, int button)
161 lyxerr[Debug::INFO] << "Inset Button Press x=" << x
162 << ", y=" << y << ", button=" << button << endl;
166 void UpdatableInset::insetButtonRelease(BufferView *, int x, int y, int button)
168 lyxerr[Debug::INFO] << "Inset Button Release x=" << x
169 << ", y=" << y << ", button=" << button << endl;
173 void UpdatableInset::insetKeyPress(XKeyEvent *)
175 lyxerr[Debug::INFO] << "Inset Keypress" << endl;
179 void UpdatableInset::insetMotionNotify(BufferView *, int x, int y, int state)
181 lyxerr[Debug::INFO] << "Inset Motion Notify x=" << x
182 << ", y=" << y << ", state=" << state << endl;
186 void UpdatableInset::insetUnlock(BufferView *)
188 lyxerr[Debug::INFO] << "Inset Unlock" << endl;
192 // An updatable inset is highly editable by definition
193 Inset::EDITABLE UpdatableInset::editable() const
195 return HIGHLY_EDITABLE;
199 void UpdatableInset::toggleInsetCursor(BufferView *)
203 void UpdatableInset::showInsetCursor(BufferView *, bool)
207 void UpdatableInset::hideInsetCursor(BufferView *)
211 void UpdatableInset::fitInsetCursor(BufferView *) const
215 void UpdatableInset::edit(BufferView *, int, int, unsigned int)
219 void UpdatableInset::edit(BufferView *, bool)
223 void UpdatableInset::draw(BufferView *, LyXFont const &,
224 int /* baseline */, float & x,
225 bool/*cleared*/) const
228 // ATTENTION: don't do the following here!!!
230 // top_baseline = baseline;
234 void UpdatableInset::scroll(BufferView * bv, float s) const
243 int const workW = bv->workWidth();
244 int const tmp_top_x = top_x - scx;
247 (tmp_top_x + width(bv, font)) < workW)
249 if (s > 0 && top_x > 0)
252 // int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
253 //int const save_scx = scx;
255 scx = int(s * workW / 2);
259 if ((tmp_top_x + scx + width(bv, font)) < (workW / 2)) {
260 scx += (workW / 2) - (tmp_top_x + scx + width(bv, font));
263 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
266 void UpdatableInset::scroll(BufferView * bv, int offset) const
269 if (!scx && top_x >= 20)
271 if ((top_x + offset) > 20)
273 // scx += offset - (top_x - scx + offset - 20);
278 if (!scx && (top_x + width(bv, font)) < (bv->workWidth() - 20))
280 if ((top_x - scx + offset + width(bv, font)) < (bv->workWidth() - 20)) {
281 scx = bv->workWidth() - width(bv, font) - top_x + scx - 20;
286 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
290 /// An updatable inset could handle lyx editing commands
291 UpdatableInset::RESULT
292 UpdatableInset::localDispatch(BufferView * bv,
293 kb_action action, string const & arg)
295 if (!arg.empty() && (action==LFUN_SCROLL_INSET)) {
296 if (arg.find('.') != arg.npos) {
297 float const xx = static_cast<float>(strToDbl(arg));
300 int const xx = strToInt(arg);
303 bv->updateInset(this, false);
311 int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
315 w = static_cast<UpdatableInset*>
316 (owner())->getMaxWidth(bv, this);
318 w = bv->text->workWidth(bv, const_cast<UpdatableInset *>(this));
323 // check for margins left/right and extra right margin "const 5"
324 if ((w - ((2 * TEXT_TO_INSET_OFFSET) + 5)) >= 0)
325 w -= (2 * TEXT_TO_INSET_OFFSET) + 5;
326 if (topx_set && owner()) {
330 #if 0 // already handled above now!!!
332 // give some left margin this should be made better!
333 // Idea: LyXText::giveLeftMargin(Inset * inset) will search the
334 // inset in the text and return the LeftMargin of that row!
335 lyxerr << "w -= 20\n";
346 LyXCursor const & Inset::cursor(BufferView * bv) const
348 return bv->text->cursor;
352 string const UpdatableInset::selectNextWordToSpellcheck(BufferView *bv,
355 // we have to unlock ourself in this function by default!
356 bv->unlockInset(const_cast<UpdatableInset *>(this));
362 bool UpdatableInset::searchForward(BufferView * bv, string const &,
363 bool const &, bool const &)
365 // we have to unlock ourself in this function by default!
366 bv->unlockInset(const_cast<UpdatableInset *>(this));
371 bool UpdatableInset::searchBackward(BufferView * bv, string const &,
372 bool const &, bool const &)
374 // we have to unlock ourself in this function by default!
375 bv->unlockInset(const_cast<UpdatableInset *>(this));