]> git.lyx.org Git - lyx.git/blob - src/mathed/command_inset.C
Andreas' patch to prevent crash on click on previewd inset
[lyx.git] / src / mathed / command_inset.C
1 /**
2  * \file command_inset.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 "command_inset.h"
14 #include "math_data.h"
15 #include "math_mathmlstream.h"
16 #include "dispatchresult.h"
17 #include "funcrequest.h"
18
19 #include <sstream>
20
21 using std::string;
22 using std::auto_ptr;
23 using std::ostringstream;
24
25
26 CommandInset::CommandInset(string const & name)
27         : MathNestInset(2), name_(name), set_label_(false)
28 {
29         lock_ = true;
30 }
31
32
33 auto_ptr<InsetBase> CommandInset::doClone() const
34 {
35         return auto_ptr<InsetBase>(new CommandInset(*this));
36 }
37
38
39 void 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         dim_ = dim;
47 }
48
49
50 void CommandInset::draw(PainterInfo & pi, int x, int y) const
51 {
52         button_.draw(pi, x, y);
53         setPosCache(pi, x, y);
54 }
55
56
57 void CommandInset::write(WriteStream & os) const
58 {
59         os << '\\' << name_.c_str();
60         if (cell(1).size())
61                 os << '[' << cell(1) << ']';
62         os << '{' << cell(0) << '}';
63 }
64
65
66 string const CommandInset::screenLabel() const
67 {
68         return name_;
69 }
70
71
72 string const CommandInset::createDialogStr(string const & name) const
73 {
74         ostringstream os;
75         os << name << " LatexCommand ";
76         WriteStream ws(os);
77         write(ws);
78         ws << "\n\\end_inset\n\n";
79         return os.str();
80 }