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"
|
2004-01-30 11:41:12 +00:00
|
|
|
|
#include "debug.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
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2007-02-22 21:17:34 +00:00
|
|
|
|
//using support::odocstream;
|
2006-10-19 19:16:33 +00:00
|
|
|
|
|
2004-01-30 11:41:12 +00:00
|
|
|
|
using std::auto_ptr;
|
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
|
|
|
2007-02-23 08:27:03 +00:00
|
|
|
|
InsetMathMBox::InsetMathMBox()
|
|
|
|
|
{
|
|
|
|
|
text_.paragraphs().clear();
|
|
|
|
|
text_.paragraphs().push_back(Paragraph());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 18:58:28 +00:00
|
|
|
|
InsetMathMBox::InsetMathMBox(Layout_ptr 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());
|
2007-02-23 08:10:13 +00:00
|
|
|
|
text_.paragraphs().back().layout(layout);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
|
auto_ptr<Inset> InsetMathMBox::doClone() const
|
2004-01-30 11:41:12 +00:00
|
|
|
|
{
|
2007-04-29 13:39:47 +00:00
|
|
|
|
return auto_ptr<Inset>(new InsetMathMBox(*this));
|
2004-01-30 11:41:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-28 15:15:49 +00:00
|
|
|
|
bool 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-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;
|
2004-01-30 11:41:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2004-11-30 01:59:49 +00:00
|
|
|
|
text_.draw(pi, x + 1, y);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
drawMarkers(pi, x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-02-23 08:10:13 +00:00
|
|
|
|
void InsetMathMBox::write(Buffer const & buf, 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;
|
2007-03-19 15:58:20 +00:00
|
|
|
|
OutputParams runparams(&buf.params().encoding());
|
2007-02-23 08:10:13 +00:00
|
|
|
|
latexParagraphs(buf, text_.paragraphs(), ws.os(), texrow, runparams);
|
2004-04-08 15:03:33 +00:00
|
|
|
|
ws.addlines(texrow.rows());
|
|
|
|
|
ws << "}";
|
|
|
|
|
} else {
|
|
|
|
|
ws << "\\mbox{\n";
|
2006-10-19 19:16:33 +00:00
|
|
|
|
std::ostringstream os;
|
2007-02-23 08:10:13 +00:00
|
|
|
|
text_.write(buf, 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetMathMBox::latex(Buffer const & buf, odocstream & os,
|
2004-04-07 18:15:29 +00:00
|
|
|
|
OutputParams const & runparams) const
|
|
|
|
|
{
|
|
|
|
|
os << "\\mbox{\n";
|
|
|
|
|
TexRow texrow;
|
|
|
|
|
latexParagraphs(buf, text_.paragraphs(), os, texrow, runparams);
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
LyXText * 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-02-22 21:17:34 +00:00
|
|
|
|
x = text_.cursorX(bv, sl, boundary);
|
|
|
|
|
y = text_.cursorY(bv, sl, boundary);
|
2004-01-30 11:41:12 +00:00
|
|
|
|
}
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathMBox::drawSelection(PainterInfo & pi, int x, int y) const
|
2004-11-30 01:59:49 +00:00
|
|
|
|
{
|
|
|
|
|
text_.drawSelection(pi, x, y);
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|