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