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