]> git.lyx.org Git - lyx.git/blob - src/mathed/command_inset.C
IU of clone() and getLabelList()
[lyx.git] / src / mathed / command_inset.C
1
2 #include "command_inset.h"
3 #include "math_mathmlstream.h"
4 #include "funcrequest.h"
5 #include "Lsstream.h"
6
7
8 CommandInset::CommandInset(string const & name)
9         : MathNestInset(2),
10           name_(name),
11           set_label_(false)
12 {
13         lock_ = true;
14 }
15
16
17 InsetBase * CommandInset::clone() const
18 {
19         return new CommandInset(*this);
20 }
21
22
23 void CommandInset::metrics(MetricsInfo & mi, Dimension & dim) const
24 {
25         if (!set_label_) {
26                 set_label_ = true;
27                 button_.update(screenLabel(), true);
28         }
29         button_.metrics(mi, dim);
30 }
31
32
33 void CommandInset::draw(PainterInfo & pi, int x, int y) const
34 {
35         button_.draw(pi, x, y);
36 }
37
38 dispatch_result
39 CommandInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
40 {
41         switch (cmd.action) {
42                 default:
43                         return MathNestInset::dispatch(cmd, idx, pos);
44         }
45         return UNDISPATCHED;
46 }
47
48
49 void CommandInset::write(WriteStream & os) const
50 {
51         os << '\\' << name_.c_str();
52         if (cell(1).size())
53                 os << '[' << cell(1) << ']';
54         os << '{' << cell(0) << '}';
55 }
56
57
58 string const CommandInset::screenLabel() const
59 {
60        return name_;
61 }
62
63
64 string const CommandInset::createDialogStr(string const & name) const
65 {
66         ostringstream data;
67         data << name << " LatexCommand ";
68         WriteStream wsdata(data);
69         write(wsdata);
70         wsdata << "\n\\end_inset\n\n";
71         return STRCONV(data.str());
72 }