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