]> git.lyx.org Git - lyx.git/blob - src/insets/insetcommand.C
29f0f15fbb7d62778f6281b53584145df3d81b89
[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
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         switch (cmd.action) {
69         case LFUN_CITATION_APPLY:
70         case LFUN_INDEX_APPLY:
71         case LFUN_REF_APPLY:
72         case LFUN_TOC_APPLY:
73         case LFUN_URL_APPLY:
74                 break;
75         default:
76                 return UNDISPATCHED;
77         }
78
79         InsetCommandParams p;
80         InsetCommandMailer::string2params(cmd.argument, p);
81         if (p.getCmdName().empty())
82                 return UNDISPATCHED;
83
84         setParams(p);
85         if (view())
86                 view()->updateInset(this, true);
87
88         return DISPATCHED;
89 }
90
91 InsetCommandMailer::InsetCommandMailer(string const & name,
92                                        InsetCommand & inset)
93         : name_(name), inset_(inset)
94 {}
95
96
97 string const InsetCommandMailer::inset2string() const
98 {
99         return params2string(inset_.params());
100 }
101
102
103 void InsetCommandMailer::string2params(string const & in,
104                                        InsetCommandParams & params)
105 {
106         params.setCmdName(string());
107         params.setContents(string());
108         params.setOptions(string());
109
110         if (in.empty())
111                 return;
112
113         istringstream data(in);
114         LyXLex lex(0,0);
115         lex.setStream(data);
116
117         params.read(lex);
118 }
119
120
121 string const
122 InsetCommandMailer::params2string(InsetCommandParams const & params)
123 {
124         ostringstream data;
125         params.write(data);
126         data << "\\end_inset\n";
127
128         return data.str();
129 }