]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathMBox.cpp
882c93b6189fc4e66576a2d05c9b87c6dec249e3
[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 "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
30 namespace lyx {
31
32 using std::endl;
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 bool 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         if (dim_ == dim)
62                 return false;
63         dim_ = dim;
64         return true;
65 }
66
67
68 void InsetMathMBox::draw(PainterInfo & pi, int x, int y) const
69 {
70         text_.draw(pi, x + 1, y);
71         drawMarkers(pi, x, y);
72 }
73
74
75 void InsetMathMBox::write(Buffer const & buf, WriteStream & ws) const
76 {
77         if (ws.latex()) {
78                 ws << "\\mbox{\n";
79                 TexRow texrow;
80                 OutputParams runparams(&buf.params().encoding());
81                 latexParagraphs(buf, text_.paragraphs(), ws.os(), texrow, runparams);
82                 ws.addlines(texrow.rows());
83                 ws << "}";
84         } else {
85                 ws << "\\mbox{\n";
86                 std::ostringstream os;
87                 text_.write(buf, os);
88                 ws.os() << from_utf8(os.str());
89                 ws << "}";
90         }
91 }
92
93
94 int InsetMathMBox::latex(Buffer const & buf, odocstream & os,
95                         OutputParams const & runparams) const
96 {
97         os << "\\mbox{\n";
98         TexRow texrow;
99         latexParagraphs(buf, text_.paragraphs(), os, texrow, runparams);
100         os << "}";
101         return texrow.rows();
102 }
103
104
105 void InsetMathMBox::doDispatch(Cursor & cur, FuncRequest & cmd)
106 {
107         text_.dispatch(cur, cmd);
108 }
109
110
111 Text * InsetMathMBox::getText(int) const
112 {
113         return &text_;
114 }
115
116
117 void InsetMathMBox::cursorPos(BufferView const & bv,
118                 CursorSlice const & sl, bool boundary, int & x, int & y) const
119 {
120         x = text_.cursorX(bv, sl, boundary);
121         y = text_.cursorY(bv, sl, boundary);
122 }
123
124
125 void InsetMathMBox::drawSelection(PainterInfo & pi, int x, int y) const
126 {
127         pi.base.bv->textMetrics(&text_).drawSelection(pi, x, y);
128 }
129
130
131 } // namespace lyx