]> git.lyx.org Git - features.git/blob - src/mathed/command_inset.C
Replace LString.h with support/std_string.h,
[features.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_mathmlstream.h"
15 #include "funcrequest.h"
16 #include "support/std_sstream.h"
17
18 using std::auto_ptr;
19
20
21 CommandInset::CommandInset(string const & name)
22         : MathNestInset(2),
23           name_(name),
24           set_label_(false)
25 {
26         lock_ = true;
27 }
28
29
30 auto_ptr<InsetBase> CommandInset::clone() const
31 {
32         return auto_ptr<InsetBase>(new CommandInset(*this));
33 }
34
35
36 void CommandInset::metrics(MetricsInfo & mi, Dimension & dim) const
37 {
38         if (!set_label_) {
39                 set_label_ = true;
40                 button_.update(screenLabel(), true);
41         }
42         button_.metrics(mi, dim);
43 }
44
45
46 void CommandInset::draw(PainterInfo & pi, int x, int y) const
47 {
48         button_.draw(pi, x, y);
49 }
50
51 dispatch_result
52 CommandInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos)
53 {
54         switch (cmd.action) {
55                 default:
56                         return MathNestInset::dispatch(cmd, idx, pos);
57         }
58         return UNDISPATCHED;
59 }
60
61
62 void CommandInset::write(WriteStream & os) const
63 {
64         os << '\\' << name_.c_str();
65         if (cell(1).size())
66                 os << '[' << cell(1) << ']';
67         os << '{' << cell(0) << '}';
68 }
69
70
71 string const CommandInset::screenLabel() const
72 {
73        return name_;
74 }
75
76
77 string const CommandInset::createDialogStr(string const & name) const
78 {
79         ostringstream data;
80         data << name << " LatexCommand ";
81         WriteStream wsdata(data);
82         write(wsdata);
83         wsdata << "\n\\end_inset\n\n";
84         return STRCONV(data.str());
85 }