]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathMBox.cpp
4fc4ffd95e3406661b26aac9d8b8ca5ff6db54e4
[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 "support/debug.h"
22 #include "MetricsInfo.h"
23 #include "output_latex.h"
24 #include "OutputParams.h"
25 #include "Paragraph.h"
26 #include "TexRow.h"
27 #include "TextMetrics.h"
28
29 using namespace std;
30
31 namespace lyx {
32
33
34 InsetMathMBox::InsetMathMBox()
35 {
36         text_.paragraphs().clear();
37         text_.paragraphs().push_back(Paragraph());
38 }
39
40
41 InsetMathMBox::InsetMathMBox(LayoutPtr const & layout)
42 {
43         text_.paragraphs().clear();
44         text_.paragraphs().push_back(Paragraph());
45         text_.paragraphs().back().layout(layout);
46 }
47
48
49 Inset * InsetMathMBox::clone() const
50 {
51         return new InsetMathMBox(*this);
52 }
53
54
55 void InsetMathMBox::metrics(MetricsInfo & mi, Dimension & dim) const
56 {
57         TextMetrics & tm = mi.base.bv->textMetrics(&text_);
58         tm.metrics(mi, dim);
59         metricsMarkers2(dim);
60 }
61
62
63 void InsetMathMBox::draw(PainterInfo & pi, int x, int y) const
64 {
65         pi.base.bv->textMetrics(&text_).draw(pi, x + 1, y);
66         drawMarkers(pi, x, y);
67 }
68
69
70 void InsetMathMBox::write(Buffer const & buf, WriteStream & ws) const
71 {
72         if (ws.latex()) {
73                 ws << "\\mbox{\n";
74                 TexRow texrow;
75                 OutputParams runparams(&buf.params().encoding());
76                 latexParagraphs(buf, text_.paragraphs(), ws.os(), texrow, runparams);
77                 ws.addlines(texrow.rows());
78                 ws << "}";
79         } else {
80                 ws << "\\mbox{\n";
81                 std::ostringstream os;
82                 text_.write(buf, os);
83                 ws.os() << from_utf8(os.str());
84                 ws << "}";
85         }
86 }
87
88
89 int InsetMathMBox::latex(Buffer const & buf, odocstream & os,
90                         OutputParams const & runparams) const
91 {
92         os << "\\mbox{\n";
93         TexRow texrow;
94         latexParagraphs(buf, text_.paragraphs(), os, texrow, runparams);
95         os << "}";
96         return texrow.rows();
97 }
98
99
100 void InsetMathMBox::doDispatch(Cursor & cur, FuncRequest & cmd)
101 {
102         text_.dispatch(cur, cmd);
103 }
104
105
106 Text * InsetMathMBox::getText(int) const
107 {
108         return &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_).cursorX(sl, boundary);
116         y = bv.textMetrics(&text_).cursorY(sl, boundary);
117 }
118
119
120 } // namespace lyx