]> git.lyx.org Git - lyx.git/blob - src/mathed/command_inset.C
Finish the task of removing all cruft from the header files.
[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 "funcrequest.h"
17 #include "support/std_sstream.h"
18
19 using std::auto_ptr;
20 using std::ostringstream;
21
22
23 CommandInset::CommandInset(string const & name)
24         : MathNestInset(2),
25           name_(name),
26           set_label_(false)
27 {
28         lock_ = true;
29 }
30
31
32 auto_ptr<InsetBase> CommandInset::clone() const
33 {
34         return auto_ptr<InsetBase>(new CommandInset(*this));
35 }
36
37
38 void CommandInset::metrics(MetricsInfo & mi, Dimension & dim) const
39 {
40         if (!set_label_) {
41                 set_label_ = true;
42                 button_.update(screenLabel(), true);
43         }
44         button_.metrics(mi, dim);
45 }
46
47
48 void CommandInset::draw(PainterInfo & pi, int x, int y) const
49 {
50         button_.draw(pi, x, y);
51 }
52
53 dispatch_result
54 CommandInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
55 {
56         switch (cmd.action) {
57                 default:
58                         return MathNestInset::dispatch(cmd, idx, pos);
59         }
60         return UNDISPATCHED;
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 data;
82         data << name << " LatexCommand ";
83         WriteStream wsdata(data);
84         write(wsdata);
85         wsdata << "\n\\end_inset\n\n";
86         return STRCONV(data.str());
87 }