]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathMBox.C
Avoid processing empty lines when reading the symbols 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
16 #include "BufferView.h"
17 #include "buffer.h"
18 #include "bufferparams.h"
19 #include "cursor.h"
20 #include "debug.h"
21 #include "metricsinfo.h"
22 #include "output_latex.h"
23 #include "outputparams.h"
24 #include "paragraph.h"
25 #include "texrow.h"
26
27
28 namespace lyx {
29
30 using odocstream;
31
32 using std::auto_ptr;
33 using std::endl;
34
35
36 InsetMathMBox::InsetMathMBox(BufferView & bv)
37         : text_(&bv), bv_(&bv)
38 {
39         text_.paragraphs().clear();
40         text_.paragraphs().push_back(Paragraph());
41         text_.paragraphs().back().
42                 layout(bv.buffer()->params().getLyXTextClass().defaultLayout());
43         text_.redoParagraph(0);
44 }
45
46
47 auto_ptr<InsetBase> InsetMathMBox::doClone() const
48 {
49         return auto_ptr<InsetBase>(new InsetMathMBox(*this));
50 }
51
52
53 void InsetMathMBox::metrics(MetricsInfo & mi, Dimension & dim) const
54 {
55         text_.metrics(mi, dim);
56         metricsMarkers2(dim);
57         dim_ = dim;
58 }
59
60
61 void InsetMathMBox::draw(PainterInfo & pi, int x, int y) const
62 {
63         text_.draw(pi, x + 1, y);
64         drawMarkers(pi, x, y);
65 }
66
67
68 void InsetMathMBox::write(WriteStream & ws) const
69 {
70         if (ws.latex()) {
71                 ws << "\\mbox{\n";
72                 TexRow texrow;
73                 OutputParams runparams;
74                 latexParagraphs(*bv_->buffer(), text_.paragraphs(),
75                         ws.os(), texrow, runparams);
76                 ws.addlines(texrow.rows());
77                 ws << "}";
78         } else {
79                 ws << "\\mbox{\n";
80                 std::ostringstream os;
81                 text_.write(*bv_->buffer(), os);
82                 ws.os() << from_utf8(os.str());
83                 ws << "}";
84         }
85 }
86
87
88 int InsetMathMBox::latex(Buffer const & buf, odocstream & os,
89                         OutputParams const & runparams) const
90 {
91         os << "\\mbox{\n";
92         TexRow texrow;
93         latexParagraphs(buf, text_.paragraphs(), os, texrow, runparams);
94         os << "}";
95         return texrow.rows();
96 }
97
98
99 void InsetMathMBox::doDispatch(LCursor & cur, FuncRequest & cmd)
100 {
101         text_.dispatch(cur, cmd);
102 }
103
104
105 LyXText * InsetMathMBox::getText(int) const
106 {
107         return &text_;
108 }
109
110
111 void InsetMathMBox::cursorPos(BufferView const & bv,
112                 CursorSlice const & sl, bool boundary, int & x, int & y) const
113 {
114         x = text_.cursorX(sl, boundary);
115         y = text_.cursorY(sl, boundary);
116 }
117
118
119 void InsetMathMBox::drawSelection(PainterInfo & pi, int x, int y) const
120 {
121         text_.drawSelection(pi, x, y);
122 }
123
124
125 } // namespace lyx