]> git.lyx.org Git - lyx.git/blob - src/mathed/command_inset.C
Fix event loop to no longer eat CPU
[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 InsetBase * CommandInset::editXY(LCursor & cur, int /*x*/, int /*y*/)
51 {
52         edit(cur, true);
53         return this;
54 }
55
56
57 void CommandInset::draw(PainterInfo & pi, int x, int y) const
58 {
59         button_.draw(pi, x, y);
60         setPosCache(pi, x, y);
61 }
62
63
64 void CommandInset::write(WriteStream & os) const
65 {
66         os << '\\' << name_.c_str();
67         if (cell(1).size())
68                 os << '[' << cell(1) << ']';
69         os << '{' << cell(0) << '}';
70 }
71
72
73 string const CommandInset::screenLabel() const
74 {
75         return name_;
76 }
77
78
79 string const CommandInset::createDialogStr(string const & name) const
80 {
81         ostringstream os;
82         os << name << " LatexCommand ";
83         WriteStream ws(os);
84         write(ws);
85         ws << "\n\\end_inset\n\n";
86         return os.str();
87 }