]> git.lyx.org Git - lyx.git/blob - src/mathed/command_inset.C
8ddd8fbe9aff80b96dc6d302888d40f4f986e5a7
[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 #include "support/std_sstream.h"
19
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),
28           name_(name),
29           set_label_(false)
30 {
31         lock_ = true;
32 }
33
34
35 auto_ptr<InsetBase> CommandInset::clone() 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 }
49
50
51 void CommandInset::draw(PainterInfo & pi, int x, int y) const
52 {
53         button_.draw(pi, x, y);
54 }
55
56
57 DispatchResult
58 CommandInset::priv_dispatch(LCursor & bv, FuncRequest const & cmd)
59 {
60         switch (cmd.action) {
61                 default:
62                         return MathNestInset::priv_dispatch(bv, cmd);
63         }
64         return DispatchResult(false);
65 }
66
67
68 void CommandInset::write(WriteStream & os) const
69 {
70         os << '\\' << name_.c_str();
71         if (cell(1).size())
72                 os << '[' << cell(1) << ']';
73         os << '{' << cell(0) << '}';
74 }
75
76
77 string const CommandInset::screenLabel() const
78 {
79        return name_;
80 }
81
82
83 string const CommandInset::createDialogStr(string const & name) const
84 {
85         ostringstream data;
86         data << name << " LatexCommand ";
87         WriteStream wsdata(data);
88         write(wsdata);
89         wsdata << "\n\\end_inset\n\n";
90         return data.str();
91 }