2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file math_binominset.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
2001-12-18 03:16:46 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2001-08-13 15:26:41 +00:00
|
|
|
|
#include "math_binominset.h"
|
2003-09-07 21:25:37 +00:00
|
|
|
|
#include "math_data.h"
|
2001-11-08 12:15:12 +00:00
|
|
|
|
#include "math_support.h"
|
2001-11-08 12:06:56 +00:00
|
|
|
|
#include "math_mathmlstream.h"
|
2001-08-13 15:26:41 +00:00
|
|
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
using std::max;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using std::auto_ptr;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
|
|
|
|
|
2002-07-04 11:00:51 +00:00
|
|
|
|
MathBinomInset::MathBinomInset(bool choose)
|
|
|
|
|
: choose_(choose)
|
2001-08-13 15:26:41 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2004-11-23 23:04:52 +00:00
|
|
|
|
auto_ptr<InsetBase> MathBinomInset::doClone() const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new MathBinomInset(*this));
|
2001-08-13 15:26:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int MathBinomInset::dw() const
|
|
|
|
|
{
|
2003-05-28 13:22:36 +00:00
|
|
|
|
int w = dim_.height() / 5;
|
2001-08-13 15:26:41 +00:00
|
|
|
|
if (w > 15)
|
|
|
|
|
w = 15;
|
|
|
|
|
if (w < 6)
|
|
|
|
|
w = 6;
|
|
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
void MathBinomInset::metrics(MetricsInfo & mi, Dimension & dim) const
|
2001-08-13 15:26:41 +00:00
|
|
|
|
{
|
2003-03-21 14:20:48 +00:00
|
|
|
|
ScriptChanger dummy(mi.base);
|
2002-08-02 14:29:42 +00:00
|
|
|
|
cell(0).metrics(mi);
|
|
|
|
|
cell(1).metrics(mi);
|
2004-04-07 16:54:15 +00:00
|
|
|
|
dim.asc = cell(0).height() + 4 + 5;
|
|
|
|
|
dim.des = cell(1).height() + 4 - 5;
|
|
|
|
|
dim.wid = max(cell(0).width(), cell(1).width()) + 2 * dw() + 4;
|
|
|
|
|
metricsMarkers2(dim);
|
|
|
|
|
dim_ = dim;
|
2001-08-13 15:26:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
void MathBinomInset::draw(PainterInfo & pi, int x, int y) const
|
2001-08-13 15:26:41 +00:00
|
|
|
|
{
|
2003-05-28 13:22:36 +00:00
|
|
|
|
int m = x + dim_.width() / 2;
|
2003-03-21 14:20:48 +00:00
|
|
|
|
ScriptChanger dummy(pi.base);
|
2002-08-02 14:29:42 +00:00
|
|
|
|
cell(0).draw(pi, m - cell(0).width() / 2, y - cell(0).descent() - 3 - 5);
|
|
|
|
|
cell(1).draw(pi, m - cell(1).width() / 2, y + cell(1).ascent() + 3 - 5);
|
2003-05-28 13:22:36 +00:00
|
|
|
|
mathed_draw_deco(pi, x, y - dim_.ascent(), dw(), dim_.height(), "(");
|
|
|
|
|
mathed_draw_deco(pi, x + dim_.width() - dw(), y - dim_.ascent(),
|
|
|
|
|
dw(), dim_.height(), ")");
|
2004-04-07 16:54:15 +00:00
|
|
|
|
drawMarkers2(pi, x, y);
|
2001-08-13 15:26:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-07-16 17:19:05 +00:00
|
|
|
|
bool MathBinomInset::extraBraces() const
|
|
|
|
|
{
|
|
|
|
|
return choose_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
|
void MathBinomInset::write(WriteStream & os) const
|
2001-08-13 15:26:41 +00:00
|
|
|
|
{
|
2002-07-04 11:00:51 +00:00
|
|
|
|
if (choose_)
|
|
|
|
|
os << '{' << cell(0) << " \\choose " << cell(1) << '}';
|
|
|
|
|
else
|
|
|
|
|
os << "\\binom{" << cell(0) << "}{" << cell(1) << '}';
|
2001-08-13 15:26:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
|
void MathBinomInset::normalize(NormalStream & os) const
|
2001-08-13 15:26:41 +00:00
|
|
|
|
{
|
2001-11-09 08:35:57 +00:00
|
|
|
|
os << "[binom " << cell(0) << ' ' << cell(1) << ']';
|
2001-08-13 15:26:41 +00:00
|
|
|
|
}
|