]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathMBox.cpp
Substack support for XHTML.
[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(Buffer * buffer) : InsetMath(buffer), text_(buffer)
36 {
37         text_.paragraphs().clear();
38         text_.paragraphs().push_back(Paragraph());
39 }
40
41
42 InsetMathMBox::InsetMathMBox(Buffer * buffer, Layout const & layout)
43         : InsetMath(buffer), text_(buffer)
44 {
45         text_.paragraphs().clear();
46         text_.paragraphs().push_back(Paragraph());
47         text_.paragraphs().back().setLayout(layout);
48 }
49
50
51 Inset * InsetMathMBox::clone() const
52 {
53         return new InsetMathMBox(*this);
54 }
55
56
57 void InsetMathMBox::metrics(MetricsInfo & mi, Dimension & dim) const
58 {
59         TextMetrics & tm = mi.base.bv->textMetrics(&text_.text());
60         tm.metrics(mi, dim);
61         metricsMarkers2(dim);
62 }
63
64
65 void InsetMathMBox::draw(PainterInfo & pi, int x, int y) const
66 {
67         pi.base.bv->textMetrics(&text_.text()).draw(pi, x + 1, y);
68         drawMarkers(pi, x, y);
69 }
70
71
72 void InsetMathMBox::write(WriteStream & ws) const
73 {
74         if (ws.latex()) {
75                 ws << "\\mbox{\n";
76                 TexRow texrow;
77                 OutputParams runparams(&buffer().params().encoding());
78                 otexstream os(ws.os(), texrow);
79                 latexParagraphs(buffer(), text_.text(), os, runparams);
80                 ws.addlines(texrow.rows());
81                 ws << "}";
82         } else {
83                 ws << "\\mbox{\n";
84                 ostringstream os;
85                 text_.text().write(os);
86                 ws.os() << from_utf8(os.str());
87                 ws << "}";
88         }
89 }
90
91
92 void InsetMathMBox::latex(otexstream & os, OutputParams const & runparams) const
93 {
94         os << "\\mbox{\n";
95         latexParagraphs(buffer(), text_.text(), os, runparams);
96         os << "}";
97 }
98
99
100 void InsetMathMBox::doDispatch(Cursor & cur, FuncRequest & cmd)
101 {
102         text_.text().dispatch(cur, cmd);
103 }
104
105
106 Text * InsetMathMBox::getText(int) const
107 {
108         return &text_.text();
109 }
110
111
112 void InsetMathMBox::cursorPos(BufferView const & bv,
113                 CursorSlice const & sl, bool boundary, int & x, int & y) const
114 {
115         x = bv.textMetrics(&text_.text()).cursorX(sl, boundary);
116         y = bv.textMetrics(&text_.text()).cursorY(sl, boundary);
117 }
118
119
120 void InsetMathMBox::mathmlize(MathStream & ms) const
121 {       
122         SetMode textmode(ms, true);
123         ms << cell(0);
124 }
125
126 void InsetMathMBox::htmlize(HtmlStream & ms) const
127 {       
128         SetHTMLMode textmode(ms, true);
129         ms << cell(0);
130 }
131
132 } // namespace lyx