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