2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
|
* \file InsetMathDecoration.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 Alejandro Aguilar Sierra
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
2001-12-05 08:04:20 +00:00
|
|
|
|
|
2003-08-19 13:00:56 +00:00
|
|
|
|
#include <config.h>
|
2001-02-26 12:53:35 +00:00
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathDecoration.h"
|
2007-04-25 16:11:45 +00:00
|
|
|
|
#include "MathArray.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "MathParser.h"
|
2006-12-17 15:05:18 +00:00
|
|
|
|
#include "MathSupport.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "MathStream.h"
|
2004-04-08 15:20:05 +00:00
|
|
|
|
|
2005-01-08 20:28:29 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2004-08-14 14:03:42 +00:00
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
2003-09-05 17:23:11 +00:00
|
|
|
|
#include "support/std_ostream.h"
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathDecoration::InsetMathDecoration(latexkeys const * key)
|
|
|
|
|
: InsetMathNest(1), key_(key)
|
2004-08-14 14:03:42 +00:00
|
|
|
|
{
|
2004-08-14 19:55:00 +00:00
|
|
|
|
// lyxerr << " creating deco " << key->name << std::endl;
|
2004-08-14 14:03:42 +00:00
|
|
|
|
}
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
std::auto_ptr<InsetBase> InsetMathDecoration::doClone() const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return std::auto_ptr<InsetBase>(new InsetMathDecoration(*this));
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathDecoration::upper() const
|
2001-08-15 06:53:25 +00:00
|
|
|
|
{
|
2002-07-17 10:25:33 +00:00
|
|
|
|
return key_->name.substr(0, 5) != "under";
|
2001-08-15 06:53:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathDecoration::isScriptable() const
|
2001-09-11 10:58:17 +00:00
|
|
|
|
{
|
2001-09-12 13:23:39 +00:00
|
|
|
|
return
|
2002-07-17 10:25:33 +00:00
|
|
|
|
key_->name == "overbrace" ||
|
|
|
|
|
key_->name == "underbrace" ||
|
|
|
|
|
key_->name == "overleftarrow" ||
|
|
|
|
|
key_->name == "overrightarrow" ||
|
|
|
|
|
key_->name == "overleftrightarrow" ||
|
|
|
|
|
key_->name == "underleftarrow" ||
|
|
|
|
|
key_->name == "underrightarrow" ||
|
|
|
|
|
key_->name == "underleftrightarrow";
|
2001-09-11 10:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathDecoration::protect() const
|
2001-08-15 06:53:25 +00:00
|
|
|
|
{
|
|
|
|
|
return
|
2002-07-17 10:25:33 +00:00
|
|
|
|
key_->name == "overbrace" ||
|
|
|
|
|
key_->name == "underbrace" ||
|
|
|
|
|
key_->name == "overleftarrow" ||
|
|
|
|
|
key_->name == "overrightarrow" ||
|
|
|
|
|
key_->name == "overleftrightarrow" ||
|
|
|
|
|
key_->name == "underleftarrow" ||
|
|
|
|
|
key_->name == "underrightarrow" ||
|
|
|
|
|
key_->name == "underleftrightarrow";
|
2001-08-15 06:53:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathDecoration::wide() const
|
2001-09-12 15:56:09 +00:00
|
|
|
|
{
|
|
|
|
|
return
|
2002-07-17 10:25:33 +00:00
|
|
|
|
key_->name == "overline" ||
|
|
|
|
|
key_->name == "underline" ||
|
|
|
|
|
key_->name == "overbrace" ||
|
|
|
|
|
key_->name == "underbrace" ||
|
|
|
|
|
key_->name == "overleftarrow" ||
|
|
|
|
|
key_->name == "overrightarrow" ||
|
|
|
|
|
key_->name == "overleftrightarrow" ||
|
|
|
|
|
key_->name == "widehat" ||
|
|
|
|
|
key_->name == "widetilde" ||
|
|
|
|
|
key_->name == "underleftarrow" ||
|
|
|
|
|
key_->name == "underrightarrow" ||
|
|
|
|
|
key_->name == "underleftrightarrow";
|
2001-09-12 15:56:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathDecoration::ams() const
|
2005-01-05 17:34:12 +00:00
|
|
|
|
{
|
2005-01-08 20:28:29 +00:00
|
|
|
|
return
|
2005-01-05 17:34:12 +00:00
|
|
|
|
key_->name == "overleftrightarrow" ||
|
|
|
|
|
key_->name == "underleftarrow" ||
|
|
|
|
|
key_->name == "underrightarrow" ||
|
|
|
|
|
key_->name == "underleftrightarrow";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-28 15:15:49 +00:00
|
|
|
|
bool InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
|
2001-02-13 13:28:32 +00:00
|
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
|
cell(0).metrics(mi, dim);
|
2003-05-28 13:22:36 +00:00
|
|
|
|
|
2002-07-11 11:27:24 +00:00
|
|
|
|
dh_ = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
|
|
|
|
|
dw_ = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2001-08-15 06:53:25 +00:00
|
|
|
|
if (upper()) {
|
2004-01-30 11:41:12 +00:00
|
|
|
|
dy_ = -dim.asc - dh_;
|
|
|
|
|
dim.asc += dh_ + 1;
|
2001-02-13 13:28:32 +00:00
|
|
|
|
} else {
|
2004-01-30 11:41:12 +00:00
|
|
|
|
dy_ = dim.des + 1;
|
|
|
|
|
dim.des += dh_ + 2;
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
2002-06-24 15:37:14 +00:00
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
metricsMarkers(dim);
|
2006-11-28 15:15:49 +00:00
|
|
|
|
if (dim_ == dim)
|
|
|
|
|
return false;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
dim_ = dim;
|
2006-11-28 15:15:49 +00:00
|
|
|
|
return true;
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-09-03 15:22:55 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathDecoration::draw(PainterInfo & pi, int x, int y) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
|
cell(0).draw(pi, x + 1, y);
|
2002-03-21 17:42:56 +00:00
|
|
|
|
if (wide())
|
2003-06-17 06:34:49 +00:00
|
|
|
|
mathed_draw_deco(pi, x + 1, y + dy_, cell(0).width(), dh_, key_->name);
|
2002-03-19 16:55:58 +00:00
|
|
|
|
else
|
2004-04-08 15:20:05 +00:00
|
|
|
|
mathed_draw_deco(pi, x + 1 + (cell(0).width() - dw_) / 2,
|
2003-05-28 13:22:36 +00:00
|
|
|
|
y + dy_, dw_, dh_, key_->name);
|
2002-06-24 15:37:14 +00:00
|
|
|
|
drawMarkers(pi, x, y);
|
2005-04-04 22:11:53 +00:00
|
|
|
|
setPosCache(pi, x, y);
|
2001-07-05 14:48:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathDecoration::write(WriteStream & os) const
|
2001-02-13 13:28:32 +00:00
|
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
|
if (os.fragile() && protect())
|
2001-02-13 13:28:32 +00:00
|
|
|
|
os << "\\protect";
|
2002-07-17 10:25:33 +00:00
|
|
|
|
os << '\\' << key_->name << '{' << cell(0) << '}';
|
2001-07-13 07:55:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-15 06:53:25 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathDecoration::normalize(NormalStream & os) const
|
2001-07-13 07:55:55 +00:00
|
|
|
|
{
|
2002-07-17 10:25:33 +00:00
|
|
|
|
os << "[deco " << key_->name << ' ' << cell(0) << ']';
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
2002-06-24 15:37:14 +00:00
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void InsetMathDecoration::infoize(odocstream & os) const
|
2002-06-24 15:37:14 +00:00
|
|
|
|
{
|
2002-07-17 10:25:33 +00:00
|
|
|
|
os << "Deco: " << key_->name;
|
2002-06-24 15:37:14 +00:00
|
|
|
|
}
|
2005-01-08 20:28:29 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathDecoration::validate(LaTeXFeatures & features) const
|
2005-01-08 20:28:29 +00:00
|
|
|
|
{
|
|
|
|
|
if (ams())
|
|
|
|
|
features.require("amsmath");
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathNest::validate(features);
|
2005-01-08 20:28:29 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|