]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathMBox.cpp
0d05d10c36ea3c5fba01c66dc810e3397feb5c3b
[lyx.git] / src / mathed / InsetMathMBox.cpp
1 /**
2  * \file InsetMathMBox.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathMBox.h"
14 #include "MathData.h"
15 #include "MathStream.h"
16
17 #include "BufferView.h"
18 #include "Buffer.h"
19 #include "BufferParams.h"
20 #include "Cursor.h"
21 #include "MetricsInfo.h"
22 #include "output_latex.h"
23 #include "OutputParams.h"
24 #include "Paragraph.h"
25 #include "TexRow.h"
26 #include "TextMetrics.h"
27
28 #include "support/debug.h"
29
30 using namespace std;
31
32 namespace lyx {
33
34
35 InsetMathMBox::InsetMathMBox()
36 {
37         text_.paragraphs().clear();
38         text_.paragraphs().push_back(Paragraph());
39 }
40
41
42 InsetMathMBox::InsetMathMBox(LayoutPtr const & layout)
43 {
44         text_.paragraphs().clear();
45         text_.paragraphs().push_back(Paragraph());
46         text_.paragraphs().back().layout(layout);
47 }
48
49
50 Inset * InsetMathMBox::clone() const
51 {
52         return new InsetMathMBox(*this);
53 }
54
55
56 void InsetMathMBox::metrics(MetricsInfo & mi, Dimension & dim) const
57 {
58         TextMetrics & tm = mi.base.bv->textMetrics(&text_);
59         tm.metrics(mi, dim);
60         metricsMarkers2(dim);
61 }
62
63
64 void InsetMathMBox::draw(PainterInfo & pi, int x, int y) const
65 {
66         pi.base.bv->textMetrics(&text_).draw(pi, x + 1, y);
67         drawMarkers(pi, x, y);
68 }
69
70
71 void InsetMathMBox::write(Buffer const & buf, WriteStream & ws) const
72 {
73         if (ws.latex()) {
74                 ws << "\\mbox{\n";
75                 TexRow texrow;
76                 OutputParams runparams(&buf.params().encoding());
77                 latexParagraphs(buf, text_, ws.os(), texrow, runparams);
78                 ws.addlines(texrow.rows());
79                 ws << "}";
80         } else {
81                 ws << "\\mbox{\n";
82                 ostringstream os;
83                 text_.write(buf, os);
84                 ws.os() << from_utf8(os.str());
85                 ws << "}";
86         }
87 }
88
89
90 int InsetMathMBox::latex(Buffer const & buf, odocstream & os,
91                         OutputParams const & runparams) const
92 {
93         os << "\\mbox{\n";
94         TexRow texrow;
95         latexParagraphs(buf, text_, os, texrow, runparams);
96         os << "}";
97         return texrow.rows();
98 }
99
100
101 void InsetMathMBox::doDispatch(Cursor & cur, FuncRequest & cmd)
102 {
103         text_.dispatch(cur, cmd);
104 }
105
106
107 Text * InsetMathMBox::getText(int) const
108 {
109         return &text_;
110 }
111
112
113 void InsetMathMBox::cursorPos(BufferView const & bv,
114                 CursorSlice const & sl, bool boundary, int & x, int & y) const
115 {
116         x = bv.textMetrics(&text_).cursorX(sl, boundary);
117         y = bv.textMetrics(&text_).cursorY(sl, boundary);
118 }
119
120
121 } // namespace lyx