-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 1995 Matthias Ettrich
- * Copyright 1995-2000 The LyX Team.
+/**
+ * \file inset.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * ====================================================== */
+ * \author Alejandro Aguilar Sierra
+ * \author Jürgen Vigna
+ * \author Lars Gullik Bjønnes
+ * \author Matthias Ettrich
+ *
+ * Full author contact details are available in file CREDITS
+ */
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation "lyxinset.h"
-#endif
-#include "lyxinset.h"
-#include "debug.h"
+#include "inset.h"
+
#include "BufferView.h"
+#include "funcrequest.h"
+#include "gettext.h"
+#include "lyxfont.h"
+#include "lyxtext.h"
+
+#include "frontends/Painter.h"
+#include "frontends/mouse_state.h"
+
#include "support/lstrings.h"
-#include "Painter.h"
using std::endl;
-/* Insets default methods */
+// Insets default methods
-bool Inset::Deletable() const
-{
- return true;
-}
+// Initialization of the counter for the inset id's,
+unsigned int Inset::inset_id = 0;
-
-bool Inset::DirectWrite() const
-{
- return false;
-}
+Inset::Inset()
+ : InsetBase(),
+ top_x(0), topx_set(false), top_baseline(0), scx(0),
+ id_(inset_id++), owner_(0), par_owner_(0),
+ background_color_(LColor::inherit)
+{}
-Inset::EDITABLE Inset::Editable() const
+Inset::Inset(Inset const & in, bool same_id)
+ : InsetBase(),
+ top_x(0), topx_set(false), top_baseline(0), scx(0), owner_(0),
+ name_(in.name_), background_color_(in.background_color_)
{
- return NOT_EDITABLE;
+ if (same_id)
+ id_ = in.id();
+ else
+ id_ = inset_id++;
}
-void Inset::Validate(LaTeXFeatures &) const
+bool Inset::directWrite() const
{
+ return false;
}
-bool Inset::AutoDelete() const
+Inset::EDITABLE Inset::editable() const
{
- return false;
+ return NOT_EDITABLE;
}
-void Inset::Edit(BufferView *, int, int, unsigned int)
-{
-}
+void Inset::edit(BufferView *, int, int, mouse_button::state)
+{}
-LyXFont Inset::ConvertFont(LyXFont const & font) const
-{
- return LyXFont(font);
-}
-
-
-char const * Inset::EditMessage() const
-{
- return _("Opened inset");
-}
+void Inset::validate(LaTeXFeatures &) const
+{}
-LyXText * Inset::getLyXText(BufferView * bv) const
+bool Inset::autoDelete() const
{
- if (owner())
- return owner()->getLyXText(bv);
- else
- return bv->text;
+ return false;
}
- /* some stuff for inset locking */
-
-void UpdatableInset::InsetButtonPress(BufferView *, int x, int y, int button)
-{
- lyxerr.debug() << "Inset Button Press x=" << x
- << ", y=" << y << ", button=" << button << endl;
-}
+void Inset::edit(BufferView *, bool)
+{}
-void UpdatableInset::InsetButtonRelease(BufferView *, int x, int y, int button)
+#if 0
+LyXFont const Inset::convertFont(LyXFont const & font) const
{
- lyxerr.debug() << "Inset Button Release x=" << x
- << ", y=" << y << ", button=" << button << endl;
-}
-
-
-void UpdatableInset::InsetKeyPress(XKeyEvent *)
-{
- lyxerr.debug() << "Inset Keypress" << endl;
-}
-
-
-void UpdatableInset::InsetMotionNotify(BufferView *, int x, int y, int state)
-{
- lyxerr.debug() << "Inset Motion Notify x=" << x
- << ", y=" << y << ", state=" << state << endl;
+#if 1
+ return font;
+#else
+ return LyXFont(font);
+#endif
}
+#endif
-void UpdatableInset::InsetUnlock(BufferView *)
+string const Inset::editMessage() const
{
- lyxerr.debug() << "Inset Unlock" << endl;
+ return _("Opened inset");
}
-// An updatable inset is highly editable by definition
-Inset::EDITABLE UpdatableInset::Editable() const
+LyXText * Inset::getLyXText(BufferView const * bv, bool const) const
{
- return HIGHLY_EDITABLE;
+ if (owner())
+ return owner()->getLyXText(bv, false);
+ else
+ return bv->text;
}
-void UpdatableInset::ToggleInsetCursor(BufferView *)
+void Inset::setBackgroundColor(LColor::color color)
{
+ background_color_ = color;
}
-void UpdatableInset::ShowInsetCursor(BufferView *)
+LColor::color Inset::backgroundColor() const
{
+ if (background_color_ == LColor::inherit) {
+ if (owner())
+ return owner()->backgroundColor();
+ else
+ return LColor::background;
+ } else
+ return background_color_;
}
-void UpdatableInset::HideInsetCursor(BufferView *)
+int Inset::id() const
{
+ return id_;
}
-
-void UpdatableInset::Edit(BufferView * bv, int, int, unsigned int)
+void Inset::id(int id_arg)
{
- LyXFont font;
-
- scx = 0;
-
- mx_scx = abs((width(bv, font) - bv->workWidth()) / 2);
+ id_ = id_arg;
}
-
-void UpdatableInset::draw(BufferView *, LyXFont const &,
- int /* baseline */, float & x, bool/*cleared*/) const
-{
- if (scx) x += float(scx);
-// ATTENTION: don't do the following here!!!
-// top_x = int(x);
-// top_baseline = baseline;
-}
+void Inset::setFont(BufferView *, LyXFont const &, bool, bool)
+{}
-void UpdatableInset::SetFont(BufferView *, LyXFont const &, bool )
+bool Inset::forceDefaultParagraphs(Inset const * in) const
{
+ if (owner())
+ return owner()->forceDefaultParagraphs(in);
+ return false;
}
-
-/// An updatable inset could handle lyx editing commands
-#ifdef SCROLL_INSET
-UpdatableInset::RESULT
-UpdatableInset::LocalDispatch(BufferView *,
- int action, string const & arg)
-#else
-UpdatableInset::RESULT
-UpdatableInset::LocalDispatch(BufferView *, int, string const &)
-#endif
+int Inset::latexTextWidth(BufferView * bv) const
{
-#ifdef SCROLL_INSET
- if (action==LFUN_SCROLL_INSET)
- {
- float xx;
- sscanf(arg.c_str(), "%f", &xx);
- scroll(xx);
-
- return DISPATCHED;
- }
-#endif
- return UNDISPATCHED;
+ if (owner())
+ return (owner()->latexTextWidth(bv));
+ return bv->workWidth();
}
-
-int UpdatableInset::getMaxWidth(Painter & pain, UpdatableInset const *) const
-{
- if (owner())
- return static_cast<UpdatableInset*>(owner())->getMaxWidth(pain, this);
- return pain.paperWidth();
-}