]> git.lyx.org Git - features.git/blob - src/insets/insetcommand.C
ws + small stuff
[features.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
26
27 InsetCommand::InsetCommand(InsetCommandParams const & p, bool)
28         : p_(p.getCmdName(), p.getContents(), p.getOptions())
29 {}
30
31
32 void InsetCommand::setParams(InsetCommandParams const & p)
33 {
34         p_.setCmdName(p.getCmdName());
35         p_.setContents(p.getContents());
36         p_.setOptions(p.getOptions());
37 }
38
39
40 int InsetCommand::latex(Buffer const *, ostream & os,
41                         bool /*fragile*/, bool/*fs*/) const
42 {
43         os << getCommand();
44         return 0;
45 }
46
47
48 int InsetCommand::ascii(Buffer const *, ostream &, int) const
49 {
50         return 0;
51 }
52
53
54 int InsetCommand::linuxdoc(Buffer const *, ostream &) const
55 {
56         return 0;
57 }
58
59
60 int InsetCommand::docbook(Buffer const *, ostream &, bool) const
61 {
62         return 0;
63 }
64
65
66 dispatch_result InsetCommand::localDispatch(FuncRequest const & cmd)
67 {
68         InsetCommandParams p;
69         InsetCommandMailer::string2params(cmd.argument, p);
70         if (p.getCmdName().empty())
71                 return UNDISPATCHED;
72
73         setParams(p);
74         if (view())
75                 view()->updateInset(this, true);
76
77         return DISPATCHED;
78 }
79
80 InsetCommandMailer::InsetCommandMailer(string const & name,
81                                        InsetCommand & inset)
82         : name_(name), inset_(inset)
83 {}
84
85
86 string const InsetCommandMailer::inset2string() const
87 {
88         return params2string(inset_.params());
89 }
90
91
92 void InsetCommandMailer::string2params(string const & in,
93                                        InsetCommandParams & params)
94 {
95         params.setCmdName(string());
96         params.setContents(string());
97         params.setOptions(string());
98
99         if (in.empty())
100                 return;
101
102         istringstream data(in);
103         LyXLex lex(0,0);
104         lex.setStream(data);
105
106         params.read(lex);
107 }
108
109
110 string const
111 InsetCommandMailer::params2string(InsetCommandParams const & params)
112 {
113         ostringstream data;
114         params.write(data);
115         data << "\\end_inset\n";
116
117         return data.str();
118 }