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