2004-01-30 11:41:12 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file InsetMathMBox.cpp
|
2004-01-30 11:41:12 +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
|
2004-01-30 11:41:12 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathMBox.h"
|
2007-04-26 16:05:57 +00:00
|
|
|
#include "MathData.h"
|
2007-02-22 21:17:34 +00:00
|
|
|
#include "MathStream.h"
|
2004-01-30 11:41:12 +00:00
|
|
|
|
|
|
|
#include "BufferView.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
#include "Cursor.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "MetricsInfo.h"
|
2004-04-07 18:15:29 +00:00
|
|
|
#include "output_latex.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "OutputParams.h"
|
|
|
|
#include "Paragraph.h"
|
|
|
|
#include "TexRow.h"
|
2007-02-22 21:17:34 +00:00
|
|
|
#include "TextMetrics.h"
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
namespace lyx {
|
2006-10-19 19:16:33 +00:00
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
InsetMathMBox::InsetMathMBox(Buffer * buffer) : InsetMath(buffer), text_(buffer)
|
2007-02-23 08:27:03 +00:00
|
|
|
{
|
|
|
|
text_.paragraphs().clear();
|
|
|
|
text_.paragraphs().push_back(Paragraph());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
InsetMathMBox::InsetMathMBox(Buffer * buffer, Layout const & layout)
|
|
|
|
: InsetMath(buffer), text_(buffer)
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
text_.paragraphs().clear();
|
2004-01-30 11:41:12 +00:00
|
|
|
text_.paragraphs().push_back(Paragraph());
|
2008-02-23 21:59:38 +00:00
|
|
|
text_.paragraphs().back().setLayout(layout);
|
2004-01-30 11:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
Inset * InsetMathMBox::clone() const
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
return new InsetMathMBox(*this);
|
2004-01-30 11:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetMathMBox::metrics(MetricsInfo & mi, Dimension & dim) const
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
2009-08-09 15:05:36 +00:00
|
|
|
TextMetrics & tm = mi.base.bv->textMetrics(&text_.text());
|
2007-02-22 21:17:34 +00:00
|
|
|
tm.metrics(mi, dim);
|
2004-01-30 11:41:12 +00:00
|
|
|
metricsMarkers2(dim);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMathMBox::draw(PainterInfo & pi, int x, int y) const
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
2009-08-09 15:05:36 +00:00
|
|
|
pi.base.bv->textMetrics(&text_.text()).draw(pi, x + 1, y);
|
2004-01-30 11:41:12 +00:00
|
|
|
drawMarkers(pi, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetMathMBox::write(WriteStream & ws) const
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
2004-04-08 15:03:33 +00:00
|
|
|
if (ws.latex()) {
|
|
|
|
ws << "\\mbox{\n";
|
|
|
|
TexRow texrow;
|
2008-02-27 20:43:16 +00:00
|
|
|
OutputParams runparams(&buffer().params().encoding());
|
2011-02-10 20:02:48 +00:00
|
|
|
otexstream os(ws.os(), texrow);
|
|
|
|
latexParagraphs(buffer(), text_.text(), os, runparams);
|
2004-04-08 15:03:33 +00:00
|
|
|
ws.addlines(texrow.rows());
|
|
|
|
ws << "}";
|
|
|
|
} else {
|
|
|
|
ws << "\\mbox{\n";
|
2007-12-12 19:28:07 +00:00
|
|
|
ostringstream os;
|
2009-08-09 15:29:34 +00:00
|
|
|
text_.text().write(os);
|
2006-10-21 00:16:43 +00:00
|
|
|
ws.os() << from_utf8(os.str());
|
2004-04-08 15:03:33 +00:00
|
|
|
ws << "}";
|
|
|
|
}
|
2004-01-30 11:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-10 20:02:48 +00:00
|
|
|
void InsetMathMBox::latex(otexstream & os, OutputParams const & runparams) const
|
2004-04-07 18:15:29 +00:00
|
|
|
{
|
|
|
|
os << "\\mbox{\n";
|
2011-02-10 20:02:48 +00:00
|
|
|
latexParagraphs(buffer(), text_.text(), os, runparams);
|
2004-04-07 18:15:29 +00:00
|
|
|
os << "}";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetMathMBox::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
2009-08-09 15:05:36 +00:00
|
|
|
text_.text().dispatch(cur, cmd);
|
2004-01-30 11:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 23:33:02 +00:00
|
|
|
Text * InsetMathMBox::getText(int) const
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
2009-08-09 15:05:36 +00:00
|
|
|
return &text_.text();
|
2004-01-30 11:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-17 16:23:27 +00:00
|
|
|
void InsetMathMBox::cursorPos(BufferView const & bv,
|
|
|
|
CursorSlice const & sl, bool boundary, int & x, int & y) const
|
2004-01-30 11:41:12 +00:00
|
|
|
{
|
2009-08-09 15:05:36 +00:00
|
|
|
x = bv.textMetrics(&text_.text()).cursorX(sl, boundary);
|
|
|
|
y = bv.textMetrics(&text_.text()).cursorY(sl, boundary);
|
2004-01-30 11:41:12 +00:00
|
|
|
}
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
|
|
|
2009-12-31 20:44:09 +00:00
|
|
|
void InsetMathMBox::mathmlize(MathStream & ms) const
|
|
|
|
{
|
2011-04-01 22:34:40 +00:00
|
|
|
SetMode textmode(ms, true);
|
2010-03-31 19:01:15 +00:00
|
|
|
ms << cell(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InsetMathMBox::htmlize(HtmlStream & ms) const
|
|
|
|
{
|
2011-04-01 22:34:40 +00:00
|
|
|
SetHTMLMode textmode(ms, true);
|
2009-12-31 20:44:09 +00:00
|
|
|
ms << cell(0);
|
|
|
|
}
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|