2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2006-09-17 09:14:18 +00:00
|
|
|
|
* \file InsetMathCases.C
|
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"
|
|
|
|
|
#include "MathData.h"
|
2006-10-22 10:15:23 +00:00
|
|
|
|
#include "MathStream.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "MathSupport.h"
|
2005-03-24 16:26:15 +00:00
|
|
|
|
#include "FuncStatus.h"
|
2003-03-06 08:10:50 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2003-09-05 17:23:11 +00:00
|
|
|
|
#include "support/std_ostream.h"
|
2005-03-24 16:26:15 +00:00
|
|
|
|
#include "cursor.h"
|
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "gettext.h"
|
|
|
|
|
#include "undo.h"
|
|
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using support::bformat;
|
2005-03-24 16:26:15 +00:00
|
|
|
|
|
|
|
|
|
using std::endl;
|
|
|
|
|
using std::max;
|
|
|
|
|
using std::min;
|
|
|
|
|
using std::swap;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using std::auto_ptr;
|
|
|
|
|
|
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
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
auto_ptr<InsetBase> InsetMathCases::doClone() const
|
2001-11-12 16:45:09 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new InsetMathCases(*this));
|
2001-11-12 16:45:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-28 15:15:49 +00:00
|
|
|
|
bool InsetMathCases::metrics(MetricsInfo & mi, Dimension & dim) const
|
2001-11-12 16:45:09 +00:00
|
|
|
|
{
|
2006-11-28 15:15:49 +00:00
|
|
|
|
dim = dim_;
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathGrid::metrics(mi);
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim_.wid += 8;
|
2006-11-28 15:15:49 +00:00
|
|
|
|
|
|
|
|
|
if (dim_ == dim)
|
|
|
|
|
return false;
|
2003-06-02 10:03:27 +00:00
|
|
|
|
dim = dim_;
|
2006-11-28 15:15:49 +00:00
|
|
|
|
return true;
|
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
|
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathCases::doDispatch(LCursor & 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: {
|
|
|
|
|
recordUndo(cur);
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathCases::getStatus(LCursor & 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") {
|
|
|
|
|
flag.enabled(false);
|
|
|
|
|
flag.message(bformat(
|
2006-10-21 00:16:43 +00:00
|
|
|
|
from_utf8(N_("No vertical grid lines in '%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
|
|
|
|
{
|
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
|