]> git.lyx.org Git - lyx.git/blob - src/insets/InsetERT.cpp
Restore XHTML output for InsetListings.
[lyx.git] / src / insets / InsetERT.cpp
1 /**
2  * \file InsetERT.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jürgen Vigna
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 "InsetERT.h"
15
16 #include "Buffer.h"
17 #include "BufferParams.h"
18 #include "BufferView.h"
19 #include "Cursor.h"
20 #include "DispatchResult.h"
21 #include "FuncRequest.h"
22 #include "FuncStatus.h"
23 #include "Language.h"
24 #include "Layout.h"
25 #include "Lexer.h"
26 #include "LyXAction.h"
27 #include "MetricsInfo.h"
28 #include "OutputParams.h"
29 #include "ParagraphParameters.h"
30 #include "Paragraph.h"
31 #include "TextClass.h"
32
33 #include "frontends/alert.h"
34 #include "frontends/Application.h"
35
36 #include "support/debug.h"
37 #include "support/gettext.h"
38 #include "support/lstrings.h"
39
40 #include <sstream>
41
42 using namespace std;
43 using namespace lyx::support;
44
45 namespace lyx {
46
47 InsetERT::InsetERT(Buffer * buf, CollapseStatus status)
48         : InsetCollapsable(buf)
49 {
50         status_ = status;
51 }
52
53
54 InsetERT::~InsetERT()
55 {
56         hideDialogs("ert", this);
57 }
58
59
60 void InsetERT::write(ostream & os) const
61 {
62         os << "ERT" << "\n";
63         InsetCollapsable::write(os);
64 }
65
66
67 int InsetERT::plaintext(odocstream & os, OutputParams const & rp) const
68 {
69         if (!rp.inIndexEntry)
70                 // do not output TeX code
71                 return 0;
72
73         ParagraphList::const_iterator par = paragraphs().begin();
74         ParagraphList::const_iterator end = paragraphs().end();
75
76         while (par != end) {
77                 pos_type siz = par->size();
78                 for (pos_type i = 0; i < siz; ++i) {
79                         char_type const c = par->getChar(i);
80                         // output the active characters
81                         switch (c) {
82                         case '|':
83                         case '!':
84                         case '@':
85                                 os.put(c);
86                                 break;
87                         default:
88                                 break;
89                         }
90                 }
91                 ++par;
92         }
93         return 0;
94 }
95
96
97 int InsetERT::docbook(odocstream & os, OutputParams const &) const
98 {
99         // FIXME can we do the same thing here as for LaTeX?
100         ParagraphList::const_iterator par = paragraphs().begin();
101         ParagraphList::const_iterator end = paragraphs().end();
102
103         int lines = 0;
104         while (par != end) {
105                 pos_type siz = par->size();
106                 for (pos_type i = 0; i < siz; ++i)
107                         os.put(par->getChar(i));
108                 ++par;
109                 if (par != end) {
110                         os << "\n";
111                         ++lines;
112                 }
113         }
114
115         return lines;
116 }
117
118
119 void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
120 {
121         switch (cmd.action) {
122         case LFUN_INSET_MODIFY: {
123                 setStatus(cur, string2params(to_utf8(cmd.argument())));
124                 break;
125         }
126         default:
127                 InsetCollapsable::doDispatch(cur, cmd);
128                 break;
129         }
130 }
131
132
133 bool InsetERT::getStatus(Cursor & cur, FuncRequest const & cmd,
134         FuncStatus & status) const
135 {
136         switch (cmd.action) {
137         case LFUN_INSET_MODIFY:
138                 status.setEnabled(true);
139                 return true;
140                 
141         default:
142                 return InsetCollapsable::getStatus(cur, cmd, status);
143         }
144 }
145
146
147 docstring const InsetERT::buttonLabel(BufferView const & bv) const
148 {
149         if (decoration() == InsetLayout::CLASSIC)
150                 return isOpen(bv) ? _("ERT") : getNewLabel(_("ERT"));
151         else
152                 return getNewLabel(_("ERT"));
153 }
154
155
156 bool InsetERT::showInsetDialog(BufferView * bv) const
157 {
158         bv->showDialog("ert", params2string(status(*bv)), 
159                 const_cast<InsetERT *>(this));
160         return true;
161 }
162
163
164 InsetCollapsable::CollapseStatus InsetERT::string2params(string const & in)
165 {
166         if (in.empty())
167                 return Collapsed;
168         istringstream data(in);
169         Lexer lex;
170         lex.setStream(data);
171         lex.setContext("InsetERT::string2params");
172         lex >> "ert";
173         int s;
174         lex >> s;
175         return static_cast<CollapseStatus>(s);
176 }
177
178
179 string InsetERT::params2string(CollapseStatus status)
180 {
181         ostringstream data;
182         data << "ert" << ' ' << status;
183         return data.str();
184 }
185
186
187 docstring InsetERT::xhtml(XHTMLStream &, OutputParams const &) const
188 {
189         return docstring();
190 }
191
192 } // namespace lyx