]> git.lyx.org Git - features.git/blob - src/mathed/InsetMathMBox.C
57bcef336968043383b6571a7b21539fb73aa330
[features.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 "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 namespace lyx {
30
31 //using support::odocstream;
32
33 using std::auto_ptr;
34 using std::endl;
35
36
37 InsetMathMBox::InsetMathMBox(LyXLayout_ptr const & layout)
38 {
39         text_.paragraphs().clear();
40         text_.paragraphs().push_back(Paragraph());
41         text_.paragraphs().back().layout(layout);
42 }
43
44
45 auto_ptr<InsetBase> InsetMathMBox::doClone() const
46 {
47         return auto_ptr<InsetBase>(new InsetMathMBox(*this));
48 }
49
50
51 bool InsetMathMBox::metrics(MetricsInfo & mi, Dimension & dim) const
52 {
53         TextMetrics & tm = mi.base.bv->textMetrics(&text_);
54         tm.metrics(mi, dim);
55         metricsMarkers2(dim);
56         if (dim_ == dim)
57                 return false;
58         dim_ = dim;
59         return true;
60 }
61
62
63 void InsetMathMBox::draw(PainterInfo & pi, int x, int y) const
64 {
65         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;
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(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(bv, sl, boundary);
116         y = text_.cursorY(bv, 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