#include <config.h>
+#include "debug.h"
+#include "support/LOstream.h"
#ifdef __GNUG__
#pragma implementation
#endif
-#include <functional>
-
#include "math_scriptinset.h"
-#include "LColor.h"
-#include "Painter.h"
-#include "debug.h"
-#include "mathed/support.h"
-#include "support/LOstream.h"
-
-MathScriptInset::MathScriptInset()
- : MathInset("script", LM_OT_SCRIPT, 2), up_(false), down_(false)
-{}
-MathScriptInset::MathScriptInset(bool up, bool down)
- : MathInset("script", LM_OT_SCRIPT, 2), up_(up), down_(down)
+MathScriptInset::MathScriptInset(bool up)
+ : MathNestInset(1), up_(up)
{}
-MathInset * MathScriptInset::Clone() const
-{
- return new MathScriptInset(*this);
-}
-
-
-void MathScriptInset::Metrics(MathStyles st)
+MathInset * MathScriptInset::clone() const
{
- MathInset::Metrics(st);
- size_ = st;
- width_ = std::max(xcell(0).width(), xcell(1).width()) + 2;
- if (up())
- ascent_ = std::max(ascent_, xcell(0).height() + 9);
- if (down())
- descent_ = std::max(descent_, xcell(1).height());
+ return new MathScriptInset(*this);
}
-bool MathScriptInset::up() const
+MathScriptInset const * MathScriptInset::asScriptInset() const
{
- return up_;
+ return this;
}
-bool MathScriptInset::down() const
+void MathScriptInset::write(std::ostream & os, bool fragile) const
{
- return down_;
+ cell(0).write(os, fragile);
}
-void MathScriptInset::up(bool b)
-{
- up_ = b;
-}
-void MathScriptInset::down(bool b)
+void MathScriptInset::metrics(MathStyles st) const
{
- down_ = b;
+ size_ = st;
+ xcell(0).metrics(st);
+ width_ = xcell(0).width();
+ ascent_ = xcell(0).ascent();
+ descent_ = xcell(0).descent();
+ //lyxerr << "MathScriptInset::metrics: w: " << width_ << " a: " << ascent_
+ // << " d: " << descent_ << "\n";
}
-void MathScriptInset::draw(Painter & pain, int x, int y)
-{
+void MathScriptInset::draw(Painter & pain, int x, int y) const
+{
xo(x);
yo(y);
- if (up())
- xcell(0).draw(pain, x, y - xcell(0).descent() - 9);
- if (down())
- xcell(1).draw(pain, x, y + xcell(1).ascent());
-}
-
-
-void MathScriptInset::Write(std::ostream & os, bool fragile) const
-{
- if (up()) {
- os << "^{";
- cell(0).Write(os, fragile);
- os << "}";
- }
- if (down()) {
- os << "_{";
- cell(1).Write(os, fragile);
- os << "}";
- }
-}
-
-
-void MathScriptInset::WriteNormal(std::ostream & os) const
-{
- if (up()) {
- os << "[superscript ";
- cell(0).WriteNormal(os);
- os << "] ";
- }
- if (down()) {
- os << "[subscript ";
- cell(1).WriteNormal(os);
- os << "] ";
- }
-}
-
-bool MathScriptInset::idxRight(int &, int &) const
-{
- return false;
-}
-
-bool MathScriptInset::idxLeft(int &, int &) const
-{
- return false;
-}
-
-
-bool MathScriptInset::idxUp(int & idx, int & pos) const
-{
- if (idx == 0 || !up())
- return false;
- idx = 0;
- pos = 0;
- return true;
-}
-
-bool MathScriptInset::idxDown(int & idx, int & pos) const
-{
- if (idx == 1 || !down())
- return false;
- idx = 1;
- pos = 0;
- return true;
-}
-
-bool MathScriptInset::idxFirst(int & idx, int & pos) const
-{
- idx = up() ? 0 : 1;
- pos = 0;
- return true;
-}
-
-bool MathScriptInset::idxLast(int & idx, int & pos) const
-{
- idx = down() ? 1 : 0;
- pos = cell(idx).size();
- return true;
-}
-
-
-bool MathScriptInset::idxFirstUp(int & idx, int & pos) const
-{
- if (!up())
- return false;
- idx = 0;
- pos = 0;
- return true;
-}
-
-bool MathScriptInset::idxFirstDown(int & idx, int & pos) const
-{
- if (!down())
- return false;
- idx = 1;
- pos = 0;
- return true;
-}
-
-bool MathScriptInset::idxLastUp(int & idx, int & pos) const
-{
- if (!up())
- return false;
- idx = 0;
- pos = cell(idx).size();
- return true;
-}
-
-bool MathScriptInset::idxLastDown(int & idx, int & pos) const
-{
- if (!down())
- return false;
- idx = 1;
- pos = cell(idx).size();
- return true;
-}
-
-
-bool MathScriptInset::idxDelete(int idx)
-{
- if (idx == 0) {
- up(false);
- return !down();
- } else {
- down(false);
- return !up();
- }
+ xcell(0).draw(pain, x, y);
}