lyx_mirror/src/mathed/InsetMathTabular.cpp
Guillaume Munch e2bc7ffae3 RefChanger
RefChanger temporarily assigns a value to a non-const reference of any
kind. RefChanger provides a flexible and uniform generalisation of the various
scope guards previously derived from the old Changer class in MetricsInfo.h.

As before, a temporary assignment lasts as long as the Changer object lives. But
the new Changer is movable. In particular, contorsions are no longer needed to
change a private field. Special code can be moved into the appropriate classes,
and it is no longer necessary to create a new class for each specific use.

Syntax change:

   FontSetChanger dummy(mi.base, value);
-> Changer dummy = mi.base.changeFontSet(value);

New function for generating arbitrary Changers:

  Changer dummy = make_change(ref, val, condition);

Bugfix:

* Fix the display of \displaystyle{\substack{\frac{xyz}{}}} (missing style
  change).
2016-06-13 08:46:15 +01:00

118 lines
2.3 KiB
C++

/**
* \file InsetMathTabular.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author André Pönitz
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "InsetMathTabular.h"
#include "MathData.h"
#include "MathStream.h"
#include "MathStream.h"
#include "support/lstrings.h"
#include <ostream>
namespace lyx {
InsetMathTabular::InsetMathTabular(Buffer * buf, docstring const & name, int m,
int n)
: InsetMathGrid(buf, m, n), name_(name)
{}
InsetMathTabular::InsetMathTabular(Buffer * buf, docstring const & name, int m,
int n, char valign, docstring const & halign)
: InsetMathGrid(buf, m, n, valign, halign), name_(name)
{}
Inset * InsetMathTabular::clone() const
{
return new InsetMathTabular(*this);
}
void InsetMathTabular::metrics(MetricsInfo & mi, Dimension & dim) const
{
Changer dummy = mi.base.changeFontSet("textnormal");
InsetMathGrid::metrics(mi, dim);
dim.wid += 6;
}
Dimension const InsetMathTabular::dimension(BufferView const & bv) const
{
Dimension dim = InsetMathGrid::dimension(bv);
dim.wid += 6;
return dim;
}
void InsetMathTabular::draw(PainterInfo & pi, int x, int y) const
{
Changer dummy = pi.base.changeFontSet("textnormal");
InsetMathGrid::drawWithMargin(pi, x, y, 4, 2);
}
void InsetMathTabular::write(WriteStream & os) const
{
ModeSpecifier specifier(os, TEXT_MODE);
if (os.fragile())
os << "\\protect";
os << "\\begin{" << name_ << '}';
bool open = os.startOuterRow();
char const v = verticalAlignment();
if (v == 't' || v == 'b')
os << '[' << v << ']';
os << '{' << horizontalAlignments() << "}\n";
InsetMathGrid::write(os);
if (os.fragile())
os << "\\protect";
os << "\\end{" << name_ << '}';
if (open)
os.startOuterRow();
// adding a \n here is bad if the tabular is the last item
// in an \eqnarray...
}
void InsetMathTabular::infoize(odocstream & os) const
{
docstring name = name_;
name[0] = support::uppercase(name[0]);
os << name << ' ';
}
void InsetMathTabular::normalize(NormalStream & os) const
{
os << '[' << name_ << ' ';
InsetMathGrid::normalize(os);
os << ']';
}
void InsetMathTabular::maple(MapleStream & os) const
{
os << "array(";
InsetMathGrid::maple(os);
os << ')';
}
} // namespace lyx