]> git.lyx.org Git - features.git/blob - src/mathed/InsetMathMBox.C
* mathed/CMakeLists.txt: do not exclude InsetMathMBox.C
[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(BufferView & bv)
38         : text_(), 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 }
45
46
47 auto_ptr<InsetBase> InsetMathMBox::doClone() const
48 {
49         return auto_ptr<InsetBase>(new InsetMathMBox(*this));
50 }
51
52
53 bool InsetMathMBox::metrics(MetricsInfo & mi, Dimension & dim) const
54 {
55         TextMetrics & tm = mi.base.bv->textMetrics(&text_);
56         tm.metrics(mi, dim);
57         metricsMarkers2(dim);
58         if (dim_ == dim)
59                 return false;
60         dim_ = dim;
61         return true;
62 }
63
64
65 void InsetMathMBox::draw(PainterInfo & pi, int x, int y) const
66 {
67         text_.draw(pi, x + 1, y);
68         drawMarkers(pi, x, y);
69 }
70
71
72 void InsetMathMBox::write(WriteStream & ws) const
73 {
74         if (ws.latex()) {
75                 ws << "\\mbox{\n";
76                 TexRow texrow;
77                 OutputParams runparams;
78                 latexParagraphs(*bv_->buffer(), text_.paragraphs(),
79                         ws.os(), texrow, runparams);
80                 ws.addlines(texrow.rows());
81                 ws << "}";
82         } else {
83                 ws << "\\mbox{\n";
84                 std::ostringstream os;
85                 text_.write(*bv_->buffer(), os);
86                 ws.os() << from_utf8(os.str());
87                 ws << "}";
88         }
89 }
90
91
92 int InsetMathMBox::latex(Buffer const & buf, odocstream & os,
93                         OutputParams const & runparams) const
94 {
95         os << "\\mbox{\n";
96         TexRow texrow;
97         latexParagraphs(buf, text_.paragraphs(), os, texrow, runparams);
98         os << "}";
99         return texrow.rows();
100 }
101
102
103 void InsetMathMBox::doDispatch(LCursor & cur, FuncRequest & cmd)
104 {
105         text_.dispatch(cur, cmd);
106 }
107
108
109 LyXText * InsetMathMBox::getText(int) const
110 {
111         return &text_;
112 }
113
114
115 void InsetMathMBox::cursorPos(BufferView const & bv,
116                 CursorSlice const & sl, bool boundary, int & x, int & y) const
117 {
118         x = text_.cursorX(bv, sl, boundary);
119         y = text_.cursorY(bv, sl, boundary);
120 }
121
122
123 void InsetMathMBox::drawSelection(PainterInfo & pi, int x, int y) const
124 {
125         text_.drawSelection(pi, x, y);
126 }
127
128
129 } // namespace lyx