]> git.lyx.org Git - lyx.git/blob - src/mathed/CommandInset.cpp
rename MathArray into MathData
[lyx.git] / src / mathed / CommandInset.cpp
1 /**
2  * \file CommandInset.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 "CommandInset.h"
14 #include "MathData.h"
15 #include "MathStream.h"
16 #include "DispatchResult.h"
17 #include "FuncRequest.h"
18
19 #include <sstream>
20
21
22 namespace lyx {
23
24 using std::auto_ptr;
25 using std::string;
26
27 CommandInset::CommandInset(docstring const & name)
28         : InsetMathNest(2), name_(name), set_label_(false)
29 {
30         lock_ = true;
31 }
32
33
34 auto_ptr<InsetBase> CommandInset::doClone() const
35 {
36         return auto_ptr<InsetBase>(new CommandInset(*this));
37 }
38
39
40 bool CommandInset::metrics(MetricsInfo & mi, Dimension & dim) const
41 {
42         if (!set_label_) {
43                 set_label_ = true;
44                 button_.update(screenLabel(), true);
45         }
46         button_.metrics(mi, dim);
47         if (dim_ == dim)
48                 return false;
49         dim_ = dim;
50         return true;
51 }
52
53
54 InsetBase * CommandInset::editXY(Cursor & cur, int /*x*/, int /*y*/)
55 {
56         edit(cur, true);
57         return this;
58 }
59
60
61 void CommandInset::draw(PainterInfo & pi, int x, int y) const
62 {
63         button_.draw(pi, x, y);
64         setPosCache(pi, x, y);
65 }
66
67
68 void CommandInset::write(WriteStream & os) const
69 {
70         os << '\\' << name_.c_str();
71         if (cell(1).size())
72                 os << '[' << cell(1) << ']';
73         os << '{' << cell(0) << '}';
74 }
75
76
77 docstring const CommandInset::screenLabel() const
78 {
79         return name_;
80 }
81
82 } // namespace lyx