]> git.lyx.org Git - lyx.git/blob - src/insets/insetert.C
d81701590edd5b630c1cfead3e04dd75ee45d99e
[lyx.git] / src / insets / insetert.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1998 The LyX Team.
7  *
8  *======================================================*/
9
10 #include <config.h>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include "insetert.h"
17 #include "gettext.h"
18 #include "lyxfont.h"
19 #include "buffer.h"
20 #include "insets/insettext.h"
21 #include "support/LOstream.h"
22 #include "lyx_gui_misc.h"
23
24 using std::ostream;
25
26 InsetERT::InsetERT() : InsetCollapsable()
27 {
28         setLabel(_("666"));
29         //LyXFont font(LyXFont::ALL_SANE);
30         //font.setLatex (LyXFont::ON);
31         labelfont = LyXFont(LyXFont::ALL_SANE);
32         labelfont.decSize();
33         labelfont.decSize();
34         labelfont.setColor(LColor::latex);
35         setAutoCollapse(false);
36         setInsetName("ERT");
37 }
38
39
40 InsetERT::InsetERT(string const & contents)
41 {
42         setLabel(_("666"));
43         LyXFont font(LyXFont::ALL_SANE);
44 #ifndef NO_LATEX
45         font.setLatex(LyXFont::ON);
46 #else
47         font.setColor(LColor::latex);
48 #endif
49         labelfont = LyXFont(LyXFont::ALL_SANE);
50         labelfont.decSize();
51         labelfont.decSize();
52         labelfont.setColor(LColor::latex);
53         setAutoCollapse(false);
54         setInsetName("ERT");
55
56         string::const_iterator cit = contents.begin();
57         string::const_iterator end = contents.end();
58         Paragraph::size_type pos = 0;
59         for (; cit != end; ++cit) {
60                 inset.paragraph()->insertChar(pos++, *cit, font);
61         }
62 }
63
64
65 void InsetERT::write(Buffer const * buf, ostream & os) const 
66 {
67         os << getInsetName() << "\n";
68         InsetCollapsable::write(buf, os);
69 }
70
71
72 Inset * InsetERT::clone(Buffer const &, bool same_id) const
73 {
74         InsetERT * result = new InsetERT;
75         result->inset.init(&inset, same_id);
76         
77         result->collapsed_ = collapsed_;
78         if (same_id)
79                 result->id_ = id_;
80         return result;
81 }
82
83
84 string const InsetERT::editMessage() const 
85 {
86         return _("Opened ERT Inset");
87 }
88
89
90 bool InsetERT::insertInset(BufferView *, Inset *)
91 {
92         return false;
93 }
94
95
96 void InsetERT::setFont(BufferView *, LyXFont const &, bool, bool selectall)
97 {
98         // if selectall is activated then the fontchange was an outside general
99         // fontchange and this messages is not needed
100         if (!selectall)
101                 WriteAlert(_("Impossible Operation!"),
102                            _("Not permitted to change font-types inside ERT-insets!"),
103                            _("Sorry."));
104 }
105
106
107 void InsetERT::edit(BufferView * bv, int x, int y, unsigned int button)
108 {
109         InsetCollapsable::edit(bv, x, y, button);
110 #ifndef NO_LATEX
111         LyXFont font(LyXFont::ALL_SANE);
112         font.setLatex (LyXFont::ON);
113 #endif
114 }
115
116
117 int InsetERT::latex(Buffer const *, std::ostream & os, bool /*fragile*/,
118                     bool /*free_spc*/) const
119 {
120         Paragraph * par = inset.paragraph();
121         while (par) {
122                 Paragraph::size_type siz = inset.paragraph()->size();
123                 for (Paragraph::size_type i = 0; i != siz; ++i) {
124                         char c = inset.paragraph()->getChar(i);
125                         switch (c) {
126                         case Paragraph::META_NEWLINE:
127                                 os << '\n';
128                                 break;
129                         default:
130                                 os << c;
131                                 break;
132                         }
133                 }
134                 par = par->next();
135         }
136         
137         return 1;
138 }
139
140
141 int InsetERT::ascii(Buffer const *,
142                     std::ostream &, int /*linelen*/) const 
143 {
144         return 0;
145 }
146
147
148 int InsetERT::linuxdoc(Buffer const *, std::ostream &) const
149 {
150         return 0;
151 }
152
153
154 int InsetERT::docBook(Buffer const *, std::ostream &) const
155 {
156         return 0;
157 }