]> git.lyx.org Git - lyx.git/blob - src/insets/insetcommand.C
7c291d23afba654edf978df9b79e0dd660ef1369
[lyx.git] / src / insets / insetcommand.C
1 /**
2  * \file insetcommand.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  * \author Lars Gullik Bjønnes
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #include <config.h>
13
14 #include "insetcommand.h"
15 #include "BufferView.h"
16 #include "debug.h"
17 #include "funcrequest.h"
18 #include "lyxlex.h"
19
20 #include "frontends/Painter.h"
21
22 #include "Lsstream.h"
23
24 using std::ostream;
25 using std::endl;
26
27
28 InsetCommand::InsetCommand(InsetCommandParams const & p, bool)
29         : p_(p.getCmdName(), p.getContents(), p.getOptions())
30 {}
31
32
33 void InsetCommand::setParams(InsetCommandParams const & p)
34 {
35         p_.setCmdName(p.getCmdName());
36         p_.setContents(p.getContents());
37         p_.setOptions(p.getOptions());
38 }
39
40
41 int InsetCommand::latex(Buffer const *, ostream & os,
42                         bool /*fragile*/, bool/*fs*/) const
43 {
44         os << getCommand();
45         return 0;
46 }
47
48
49 int InsetCommand::ascii(Buffer const *, ostream &, int) const
50 {
51         return 0;
52 }
53
54
55 int InsetCommand::linuxdoc(Buffer const *, ostream &) const
56 {
57         return 0;
58 }
59
60
61 int InsetCommand::docbook(Buffer const *, ostream &, bool) const
62 {
63         return 0;
64 }
65
66
67 dispatch_result InsetCommand::localDispatch(FuncRequest const & cmd)
68 {
69         InsetCommandParams p;
70         InsetCommandMailer::string2params(cmd.argument, p);
71         if (p.getCmdName().empty())
72                 return UNDISPATCHED;
73
74         setParams(p);
75         if (view())
76                 view()->updateInset(this, true);
77
78         return DISPATCHED;
79 }
80
81 InsetCommandMailer::InsetCommandMailer(string const & name,
82                                        InsetCommand & inset)
83         : name_(name), inset_(inset)
84 {}
85
86
87 string const InsetCommandMailer::inset2string() const
88 {
89         return params2string(inset_.params());
90 }
91
92
93 void InsetCommandMailer::string2params(string const & in,
94                                        InsetCommandParams & params)
95 {
96         params.setCmdName(string());
97         params.setContents(string());
98         params.setOptions(string());
99
100         if (in.empty())
101                 return;
102
103         istringstream data(in);
104         LyXLex lex(0,0);
105         lex.setStream(data);
106
107         params.read(lex);
108 }
109
110
111 string const
112 InsetCommandMailer::params2string(InsetCommandParams const & params)
113 {
114         ostringstream data;
115         params.write(data);
116         data << "\\end_inset\n";
117
118         return data.str();
119 }