]> git.lyx.org Git - lyx.git/blob - src/mathed/math_mboxinset.C
the Paragraph::inInset() changes
[lyx.git] / src / mathed / math_mboxinset.C
1 /**
2  * \file math_mboxinset.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 "math_mboxinset.h"
14 #include "math_data.h"
15 #include "math_mathmlstream.h"
16
17 #include "BufferView.h"
18 #include "buffer.h"
19 #include "bufferparams.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 using std::auto_ptr;
28 using std::endl;
29
30
31 MathMBoxInset::MathMBoxInset(BufferView & bv)
32         : text_(&bv), bv_(&bv)
33 {
34         text_.paragraphs().clear();
35         text_.paragraphs().push_back(Paragraph());
36         text_.paragraphs().back().
37                 layout(bv.buffer()->params().getLyXTextClass().defaultLayout());
38         text_.redoParagraph(0);
39 }
40
41
42 auto_ptr<InsetBase> MathMBoxInset::clone() const
43 {
44         return auto_ptr<InsetBase>(new MathMBoxInset(*this));
45 }
46
47
48 void MathMBoxInset::metrics(MetricsInfo & mi, Dimension & dim) const
49 {
50         text_.metrics(mi, dim);
51         metricsMarkers2(dim);
52         dim_ = dim;
53 }
54
55
56 void MathMBoxInset::draw(PainterInfo & pi, int x, int y) const
57 {
58         text_.draw(pi, x + 1, y - text_.ascent());
59         drawMarkers(pi, x, y);
60 }
61
62
63 void MathMBoxInset::write(WriteStream & ws) const
64 {
65         if (ws.latex()) {
66                 ws << "\\mbox{\n";
67                 TexRow texrow;
68                 OutputParams runparams;
69                 latexParagraphs(*bv_->buffer(), text_.paragraphs(),
70                         ws.os(), texrow, runparams);
71                 ws.addlines(texrow.rows());
72                 ws << "}";
73         } else {
74                 ws << "\\mbox{\n";
75                 text_.write(*bv_->buffer(), ws.os());
76                 ws << "}";
77         }
78 }
79
80
81 int MathMBoxInset::latex(Buffer const & buf, std::ostream & os,
82                         OutputParams const & runparams) const
83 {
84         os << "\\mbox{\n";
85         TexRow texrow;
86         latexParagraphs(buf, text_.paragraphs(), os, texrow, runparams);
87         os << "}";
88         return texrow.rows();
89 }
90
91
92 void MathMBoxInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
93 {
94         text_.dispatch(cur, cmd);
95 }
96
97
98 LyXText * MathMBoxInset::getText(int) const
99 {
100         return &text_;
101 }
102
103
104 void MathMBoxInset::getCursorPos(CursorSlice const & cur, int & x, int & y) const
105 {
106         x = text_.cursorX(cur);
107         y = text_.cursorY(cur);
108 }