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.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathCases::InsetMathCases(row_type n)
|
2006-10-22 10:15:23 +00:00
|
|
|
|
: InsetMathGrid(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;
|
2005-03-24 16:26:15 +00:00
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
case LFUN_TABULAR_FEATURE: {
|
2007-10-18 11:51:17 +00:00
|
|
|
|
cur.recordUndo();
|
2006-09-01 15:41:38 +00:00
|
|
|
|
docstring const & s = cmd.argument();
|
2005-03-24 16:26:15 +00:00
|
|
|
|
if (s == "add-vline-left" || s == "add-vline-right") {
|
|
|
|
|
cur.undispatched();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
default:
|
2006-09-16 18:11:38 +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
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
case LFUN_TABULAR_FEATURE: {
|
2006-09-01 15:41:38 +00:00
|
|
|
|
docstring const & s = cmd.argument();
|
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")),
|
2006-09-11 08:54:10 +00:00
|
|
|
|
s));
|
2005-03-24 16:26:15 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
default:
|
2006-09-16 18:11:38 +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
|
|
|
|
|
|
|
|
|
|
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);
|
2003-03-06 08:10:50 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|