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), par_owner_(0),
39 background_color_(LColor::inherit)
43 Inset::Inset(Inset const & in, bool same_id)
44 : top_x(0), topx_set(false), top_baseline(0), scx(0), owner_(0),
45 name_(in.name_), background_color_(in.background_color_)
54 bool Inset::deletable() const
60 bool Inset::directWrite() const
66 Inset::EDITABLE Inset::editable() const
72 void Inset::validate(LaTeXFeatures &) const
76 bool Inset::autoDelete() const
82 void Inset::edit(BufferView *, int, int, unsigned int)
86 void Inset::edit(BufferView *, bool)
91 LyXFont const Inset::convertFont(LyXFont const & font) const
102 string const Inset::editMessage() const
104 return _("Opened inset");
108 LyXText * Inset::getLyXText(BufferView const * bv, bool const) const
111 return owner()->getLyXText(bv, false);
117 void Inset::setBackgroundColor(LColor::color color)
119 background_color_ = color;
123 LColor::color Inset::backgroundColor() const
125 if (background_color_ == LColor::inherit) {
127 return owner()->backgroundColor();
129 return LColor::background;
131 return background_color_;
135 int Inset::id() const
140 void Inset::id(int id_arg)
145 void Inset::setFont(BufferView *, LyXFont const &, bool, bool )
148 // some stuff for inset locking
150 UpdatableInset::UpdatableInset()
151 : Inset(), cursor_visible_(false), block_drawing_(false)
155 UpdatableInset::UpdatableInset(UpdatableInset const & in, bool same_id)
156 : Inset(in, same_id), cursor_visible_(false), block_drawing_(false)
160 void UpdatableInset::insetButtonPress(BufferView *, int x, int y, int button)
162 lyxerr[Debug::INFO] << "Inset Button Press x=" << x
163 << ", y=" << y << ", button=" << button << endl;
167 bool UpdatableInset::insetButtonRelease(BufferView *, int x, int y, int button)
169 lyxerr[Debug::INFO] << "Inset Button Release x=" << x
170 << ", y=" << y << ", button=" << button << endl;
175 void UpdatableInset::insetKeyPress(XKeyEvent *)
177 lyxerr[Debug::INFO] << "Inset Keypress" << endl;
181 void UpdatableInset::insetMotionNotify(BufferView *, int x, int y, int state)
183 lyxerr[Debug::INFO] << "Inset Motion Notify x=" << x
184 << ", y=" << y << ", state=" << state << endl;
188 void UpdatableInset::insetUnlock(BufferView *)
190 lyxerr[Debug::INFO] << "Inset Unlock" << endl;
194 // An updatable inset is highly editable by definition
195 Inset::EDITABLE UpdatableInset::editable() const
197 return HIGHLY_EDITABLE;
201 void UpdatableInset::toggleInsetCursor(BufferView *)
205 void UpdatableInset::showInsetCursor(BufferView *, bool)
209 void UpdatableInset::hideInsetCursor(BufferView *)
213 void UpdatableInset::fitInsetCursor(BufferView *) const
217 void UpdatableInset::edit(BufferView *, int, int, unsigned int)
221 void UpdatableInset::edit(BufferView *, bool)
225 void UpdatableInset::draw(BufferView *, LyXFont const &,
226 int /* baseline */, float & x,
227 bool/*cleared*/) const
230 // ATTENTION: don't do the following here!!!
232 // top_baseline = baseline;
236 void UpdatableInset::scroll(BufferView * bv, float s) const
245 int const workW = bv->workWidth();
246 int const tmp_top_x = top_x - scx;
249 (tmp_top_x + width(bv, font)) < workW)
251 if (s > 0 && top_x > 0)
254 // int mx_scx=abs((width(bv,font) - bv->workWidth())/2);
255 //int const save_scx = scx;
257 scx = int(s * workW / 2);
261 if ((tmp_top_x + scx + width(bv, font)) < (workW / 2)) {
262 scx += (workW / 2) - (tmp_top_x + scx + width(bv, font));
265 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
268 void UpdatableInset::scroll(BufferView * bv, int offset) const
271 if (!scx && top_x >= 20)
273 if ((top_x + offset) > 20)
275 // scx += offset - (top_x - scx + offset - 20);
280 if (!scx && (top_x + width(bv, font)) < (bv->workWidth() - 20))
282 if ((top_x - scx + offset + width(bv, font)) < (bv->workWidth() - 20)) {
283 scx = bv->workWidth() - width(bv, font) - top_x + scx - 20;
288 // bv->updateInset(const_cast<UpdatableInset *>(this), false);
292 /// An updatable inset could handle lyx editing commands
293 UpdatableInset::RESULT
294 UpdatableInset::localDispatch(BufferView * bv,
295 kb_action action, string const & arg)
297 if (!arg.empty() && (action==LFUN_SCROLL_INSET)) {
298 if (arg.find('.') != arg.npos) {
299 float const xx = static_cast<float>(strToDbl(arg));
302 int const xx = strToInt(arg);
305 bv->updateInset(this, false);
313 int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const
317 w = static_cast<UpdatableInset*>
318 (owner())->getMaxWidth(bv, this);
320 w = bv->text->workWidth(bv, const_cast<UpdatableInset *>(this));
325 // check for margins left/right and extra right margin "const 5"
326 if ((w - ((2 * TEXT_TO_INSET_OFFSET) + 5)) >= 0)
327 w -= (2 * TEXT_TO_INSET_OFFSET) + 5;
328 if (topx_set && owner()) {
332 #if 0 // already handled above now!!!
334 // give some left margin this should be made better!
335 // Idea: LyXText::giveLeftMargin(Inset * inset) will search the
336 // inset in the text and return the LeftMargin of that row!
337 lyxerr << "w -= 20\n";
348 LyXCursor const & Inset::cursor(BufferView * bv) const
351 return owner()->getLyXText(bv, false)->cursor;
352 return bv->text->cursor;
356 string const UpdatableInset::selectNextWordToSpellcheck(BufferView *bv,
359 // we have to unlock ourself in this function by default!
360 bv->unlockInset(const_cast<UpdatableInset *>(this));
366 bool UpdatableInset::searchForward(BufferView * bv, string const &,
367 bool const &, bool const &)
369 // we have to unlock ourself in this function by default!
370 bv->unlockInset(const_cast<UpdatableInset *>(this));
375 bool UpdatableInset::searchBackward(BufferView * bv, string const &,
376 bool const &, bool const &)
378 // we have to unlock ourself in this function by default!
379 bv->unlockInset(const_cast<UpdatableInset *>(this));