]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathMBox.C
fix reading UTF8 encoded symbol file
[lyx.git] / src / mathed / InsetMathMBox.C
1 /**
2  * \file InsetMathMBox.C
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 "MathMLStream.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
28
29 namespace lyx {
30
31 using odocstream;
32
33 using std::auto_ptr;
34 using std::endl;
35
36
37 InsetMathMBox::InsetMathMBox(BufferView & bv)
38         : text_(&bv), bv_(&bv)
39 {
40         text_.paragraphs().clear();
41         text_.paragraphs().push_back(Paragraph());
42         text_.paragraphs().back().
43                 layout(bv.buffer()->params().getLyXTextClass().defaultLayout());
44         text_.redoParagraph(0);
45 }
46
47
48 auto_ptr<InsetBase> InsetMathMBox::doClone() const
49 {
50         return auto_ptr<InsetBase>(new InsetMathMBox(*this));
51 }
52
53
54 void InsetMathMBox::metrics(MetricsInfo & mi, Dimension & dim) const
55 {
56         text_.metrics(mi, dim);
57         metricsMarkers2(dim);
58         dim_ = dim;
59 }
60
61
62 void InsetMathMBox::draw(PainterInfo & pi, int x, int y) const
63 {
64         text_.draw(pi, x + 1, y);
65         drawMarkers(pi, x, y);
66 }
67
68
69 void InsetMathMBox::write(WriteStream & ws) const
70 {
71         if (ws.latex()) {
72                 ws << "\\mbox{\n";
73                 TexRow texrow;
74                 OutputParams runparams;
75                 latexParagraphs(*bv_->buffer(), text_.paragraphs(),
76                         ws.os(), texrow, runparams);
77                 ws.addlines(texrow.rows());
78                 ws << "}";
79         } else {
80                 ws << "\\mbox{\n";
81                 std::ostringstream os;
82                 text_.write(*bv_->buffer(), 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(LCursor & cur, FuncRequest & cmd)
101 {
102         text_.dispatch(cur, cmd);
103 }
104
105
106 LyXText * 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 = text_.cursorX(sl, boundary);
116         y = text_.cursorY(sl, boundary);
117 }
118
119
120 void InsetMathMBox::drawSelection(PainterInfo & pi, int x, int y) const
121 {
122         text_.drawSelection(pi, x, y);
123 }
124
125
126 } // namespace lyx