]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathCommand.C
This commit saves the need to check for lyx::use_gui in a number of places.
[lyx.git] / src / mathed / InsetMathCommand.C
1 /**
2  * \file InsetMathCommand.C
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 "InsetMathCommand.h"
14 #include "MathData.h"
15 #include "MathMLStream.h"
16 #include "dispatchresult.h"
17 #include "funcrequest.h"
18
19 #include <sstream>
20
21 using lyx::docstring;
22
23 using std::string;
24 using std::auto_ptr;
25 using std::ostringstream;
26
27
28 CommandInset::CommandInset(string const & name)
29         : InsetMathNest(2), name_(name), set_label_(false)
30 {
31         lock_ = true;
32 }
33
34
35 auto_ptr<InsetBase> CommandInset::doClone() const
36 {
37         return auto_ptr<InsetBase>(new CommandInset(*this));
38 }
39
40
41 void CommandInset::metrics(MetricsInfo & mi, Dimension & dim) const
42 {
43         if (!set_label_) {
44                 set_label_ = true;
45                 button_.update(screenLabel(), true);
46         }
47         button_.metrics(mi, dim);
48         dim_ = dim;
49 }
50
51
52 InsetBase * CommandInset::editXY(LCursor & 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         os << '\\' << name_.c_str();
69         if (cell(1).size())
70                 os << '[' << cell(1) << ']';
71         os << '{' << cell(0) << '}';
72 }
73
74
75 docstring const CommandInset::screenLabel() const
76 {
77         return lyx::from_ascii(name_);
78 }
79
80
81 string const CommandInset::createDialogStr(string const & name) const
82 {
83         ostringstream os;
84         os << name << " LatexCommand ";
85         WriteStream ws(os);
86         write(ws);
87         ws << "\n\\end_inset\n\n";
88         return os.str();
89 }