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