]> git.lyx.org Git - lyx.git/blob - src/mathed/command_inset.C
dispatchresult -> DispatchResult
[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(FuncRequest const & cmd,
59                             idx_type & idx, pos_type & pos)
60 {
61         switch (cmd.action) {
62                 default:
63                         return MathNestInset::priv_dispatch(cmd, idx, pos);
64         }
65         return UNDISPATCHED;
66 }
67
68
69 void CommandInset::write(WriteStream & os) const
70 {
71         os << '\\' << name_.c_str();
72         if (cell(1).size())
73                 os << '[' << cell(1) << ']';
74         os << '{' << cell(0) << '}';
75 }
76
77
78 string const CommandInset::screenLabel() const
79 {
80        return name_;
81 }
82
83
84 string const CommandInset::createDialogStr(string const & name) const
85 {
86         ostringstream data;
87         data << name << " LatexCommand ";
88         WriteStream wsdata(data);
89         write(wsdata);
90         wsdata << "\n\\end_inset\n\n";
91         return data.str();
92 }