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.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
2007-02-23 08:27:03 +00:00
|
|
|
|
InsetMathMBox::InsetMathMBox()
|
|
|
|
|
{
|
|
|
|
|
text_.paragraphs().clear();
|
|
|
|
|
text_.paragraphs().push_back(Paragraph());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-23 19:59:07 +00:00
|
|
|
|
InsetMathMBox::InsetMathMBox(LayoutPtr const & layout)
|
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
|
|
|
|
{
|
2007-02-22 21:17:34 +00:00
|
|
|
|
TextMetrics & tm = mi.base.bv->textMetrics(&text_);
|
|
|
|
|
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
|
|
|
|
{
|
2007-08-31 14:26:43 +00:00
|
|
|
|
pi.base.bv->textMetrics(&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());
|
|
|
|
|
latexParagraphs(buffer(), text_, ws.os(), texrow, 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;
|
2008-02-27 20:43:16 +00:00
|
|
|
|
text_.write(buffer(), 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
int InsetMathMBox::latex(odocstream & os, OutputParams const & runparams) const
|
2004-04-07 18:15:29 +00:00
|
|
|
|
{
|
|
|
|
|
os << "\\mbox{\n";
|
|
|
|
|
TexRow texrow;
|
2008-02-27 20:43:16 +00:00
|
|
|
|
latexParagraphs(buffer(), text_, os, texrow, runparams);
|
2004-04-07 18:15:29 +00:00
|
|
|
|
os << "}";
|
|
|
|
|
return texrow.rows();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void InsetMathMBox::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2004-01-30 11:41:12 +00:00
|
|
|
|
{
|
2004-02-16 11:58:51 +00:00
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
return &text_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2007-09-02 09:44:08 +00:00
|
|
|
|
x = bv.textMetrics(&text_).cursorX(sl, boundary);
|
|
|
|
|
y = bv.textMetrics(&text_).cursorY(sl, boundary);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
}
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
} // namespace lyx
|