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