]> git.lyx.org Git - lyx.git/blob - src/mathed/CommandInset.cpp
Make Buffer argument mandatory in most of the InsetMath based class... boring work...
[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 using namespace std;
22
23 namespace lyx {
24
25
26 CommandInset::CommandInset(Buffer * buf, docstring const & name, bool needs_math_mode)
27         : InsetMathNest(buf, 2), name_(name), needs_math_mode_(needs_math_mode),
28           set_label_(false)
29 {
30         lock_ = true;
31 }
32
33
34 Inset * CommandInset::clone() const
35 {
36         return new CommandInset(*this);
37 }
38
39
40 void 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         // Cache the inset dimension. 
48         setDimCache(mi, dim);
49 }
50
51
52 Inset * CommandInset::editXY(Cursor & cur, int /*x*/, int /*y*/)
53 {
54         edit(cur, true);
55         return this;
56 }
57
58
59 void CommandInset::draw(PainterInfo & pi, int x, int y) const
60 {
61         button_.draw(pi, x, y);
62         setPosCache(pi, x, y);
63 }
64
65
66 void CommandInset::write(WriteStream & os) const
67 {
68         MathEnsurer ensurer(os, needs_math_mode_);
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