2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file InsetMathCases.cpp
|
2003-08-19 13:00:56 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-08-19 13:00:56 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
2001-12-18 03:16:46 +00:00
|
|
|
|
2003-08-19 13:00:56 +00:00
|
|
|
#include <config.h>
|
2001-11-12 16:45:09 +00:00
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathCases.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
#include "Cursor.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
#include "FuncStatus.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/gettext.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
#include "MathData.h"
|
|
|
|
#include "MathStream.h"
|
|
|
|
#include "MathSupport.h"
|
|
|
|
#include "MetricsInfo.h"
|
2005-03-24 16:26:15 +00:00
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2008-05-06 10:36:32 +00:00
|
|
|
#include <ostream>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2005-03-24 16:26:15 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2001-11-12 16:45:09 +00:00
|
|
|
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathCases::InsetMathCases(Buffer * buf, row_type n)
|
|
|
|
: InsetMathGrid(buf, 2, n, 'c', from_ascii("ll"))
|
2001-11-12 16:45:09 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
Inset * InsetMathCases::clone() const
|
2001-11-12 16:45:09 +00:00
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
return new InsetMathCases(*this);
|
2001-11-12 16:45:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetMathCases::metrics(MetricsInfo & mi, Dimension & dim) const
|
2001-11-12 16:45:09 +00:00
|
|
|
{
|
2007-09-23 22:39:49 +00:00
|
|
|
InsetMathGrid::metrics(mi, dim);
|
|
|
|
dim.wid += 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Dimension const InsetMathCases::dimension(BufferView const & bv) const
|
|
|
|
{
|
|
|
|
Dimension dim = InsetMathGrid::dimension(bv);
|
|
|
|
dim.wid += 8;
|
|
|
|
return dim;
|
2001-11-12 16:45:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathCases::draw(PainterInfo & pi, int x, int y) const
|
2002-03-21 17:42:56 +00:00
|
|
|
{
|
2007-09-23 22:39:49 +00:00
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
|
|
|
mathed_draw_deco(pi, x + 1, y - dim.ascent(), 6, dim.height(), from_ascii("{"));
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::drawWithMargin(pi, x, y, 8, 0);
|
2004-04-07 16:54:15 +00:00
|
|
|
setPosCache(pi, x, y);
|
2001-11-12 16:45:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetMathCases::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2005-03-24 16:26:15 +00:00
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
//lyxerr << "*** InsetMathCases: request: " << cmd << endl;
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2010-02-18 08:28:46 +00:00
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
istringstream is(to_utf8(cmd.argument()));
|
|
|
|
string s;
|
|
|
|
is >> s;
|
|
|
|
if (s != "tabular")
|
|
|
|
break;
|
|
|
|
is >> s;
|
2009-03-04 01:30:08 +00:00
|
|
|
// vertical lines and adding/deleting columns is not allowed for \cases
|
|
|
|
if (s == "append-column" || s == "delete-column"
|
2010-02-18 08:28:46 +00:00
|
|
|
|| s == "add-vline-left" || s == "add-vline-right") {
|
2005-03-24 16:26:15 +00:00
|
|
|
cur.undispatched();
|
|
|
|
break;
|
|
|
|
}
|
2009-03-04 01:30:08 +00:00
|
|
|
cur.recordUndo();
|
2005-03-24 16:26:15 +00:00
|
|
|
}
|
|
|
|
default:
|
2010-02-18 08:28:46 +00:00
|
|
|
break;
|
2005-03-24 16:26:15 +00:00
|
|
|
}
|
2010-02-18 08:28:46 +00:00
|
|
|
InsetMathGrid::doDispatch(cur, cmd);
|
2005-03-24 16:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool InsetMathCases::getStatus(Cursor & cur, FuncRequest const & cmd,
|
2005-03-24 16:26:15 +00:00
|
|
|
FuncStatus & flag) const
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2010-02-18 08:28:46 +00:00
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
istringstream is(to_utf8(cmd.argument()));
|
|
|
|
string s;
|
|
|
|
is >> s;
|
|
|
|
if (s != "tabular")
|
|
|
|
break;
|
|
|
|
is >> s;
|
2005-03-24 16:26:15 +00:00
|
|
|
if (s == "add-vline-left" || s == "add-vline-right") {
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(false);
|
2005-03-24 16:26:15 +00:00
|
|
|
flag.message(bformat(
|
2007-08-30 08:21:28 +00:00
|
|
|
from_utf8(N_("No vertical grid lines in 'cases': feature %1$s")),
|
2010-02-18 08:28:46 +00:00
|
|
|
from_utf8(s)));
|
2005-03-24 16:26:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-03-04 01:30:08 +00:00
|
|
|
if (s == "append-column" || s == "delete-column") {
|
|
|
|
flag.setEnabled(false);
|
|
|
|
flag.message(bformat(
|
2009-03-17 10:47:55 +00:00
|
|
|
from_utf8(N_("Changing number of columns not allowed in "
|
2010-02-18 08:28:46 +00:00
|
|
|
"'cases': feature %1$s")), from_utf8(s)));
|
2009-03-04 01:30:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-02-18 08:28:46 +00:00
|
|
|
break;
|
2005-03-24 16:26:15 +00:00
|
|
|
}
|
|
|
|
default:
|
2010-02-18 08:28:46 +00:00
|
|
|
break;
|
2005-03-24 16:26:15 +00:00
|
|
|
}
|
2010-02-18 08:28:46 +00:00
|
|
|
return InsetMathGrid::getStatus(cur, cmd, flag);
|
2005-03-24 16:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathCases::write(WriteStream & os) const
|
2001-11-12 16:45:09 +00:00
|
|
|
{
|
2008-06-17 11:10:43 +00:00
|
|
|
MathEnsurer ensurer(os);
|
2001-12-03 16:24:50 +00:00
|
|
|
if (os.fragile())
|
2001-11-12 16:45:09 +00:00
|
|
|
os << "\\protect";
|
2002-03-19 16:55:58 +00:00
|
|
|
os << "\\begin{cases}\n";
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::write(os);
|
2001-12-03 16:24:50 +00:00
|
|
|
if (os.fragile())
|
2001-11-12 16:45:09 +00:00
|
|
|
os << "\\protect";
|
2002-03-18 13:05:52 +00:00
|
|
|
os << "\\end{cases}";
|
2001-11-12 16:45:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathCases::normalize(NormalStream & os) const
|
2001-11-12 16:45:09 +00:00
|
|
|
{
|
|
|
|
os << "[cases ";
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::normalize(os);
|
2002-11-27 10:30:28 +00:00
|
|
|
os << ']';
|
2001-11-12 16:45:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathCases::maple(MapleStream & os) const
|
2001-11-12 16:45:09 +00:00
|
|
|
{
|
|
|
|
os << "cases(";
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::maple(os);
|
2002-11-27 10:30:28 +00:00
|
|
|
os << ')';
|
2001-11-12 16:45:09 +00:00
|
|
|
}
|
2002-07-08 16:20:53 +00:00
|
|
|
|
|
|
|
|
2009-12-31 21:01:00 +00:00
|
|
|
void InsetMathCases::mathmlize(MathStream & ms) const
|
|
|
|
{
|
|
|
|
ms << "<mo form='prefix' fence='true' stretchy='true' symmetric='true'>{</mo>";
|
|
|
|
InsetMathGrid::mathmlize(ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-30 02:57:05 +00:00
|
|
|
// FIXME XHTML
|
|
|
|
// We need a brace here, somehow.
|
|
|
|
void InsetMathCases::htmlize(HtmlStream & ms) const
|
|
|
|
{
|
2010-03-31 19:58:49 +00:00
|
|
|
InsetMathGrid::htmlize(ms, "class='cases'");
|
2010-03-30 02:57:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
void InsetMathCases::infoize(odocstream & os) const
|
2002-07-08 16:20:53 +00:00
|
|
|
{
|
|
|
|
os << "Cases ";
|
|
|
|
}
|
2003-03-06 08:10:50 +00:00
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathCases::validate(LaTeXFeatures & features) const
|
2003-03-06 08:10:50 +00:00
|
|
|
{
|
|
|
|
features.require("amsmath");
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathGrid::validate(features);
|
2010-03-31 18:24:52 +00:00
|
|
|
if (features.runparams().math_flavor == OutputParams::MathAsHTML)
|
2010-03-30 02:57:05 +00:00
|
|
|
// CSS based on eLyXer's
|
|
|
|
features.addPreambleSnippet("<style type=\"text/css\">\n"
|
|
|
|
"table.cases{display: inline-block; text-align: center;"
|
|
|
|
"border-left: thin solid black; vertical-align: middle; padding-left: 0.5ex;}\n"
|
|
|
|
"table.cases td {text-align: left;}\n"
|
|
|
|
"</style>");
|
2003-03-06 08:10:50 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|