]> git.lyx.org Git - lyx.git/blob - src/insets/insetert.C
d6c4542ae0452e952dd275672fab216bc850d5be
[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 void InsetERT::edit(BufferView * bv, bool)
118 {
119         edit(bv, 0, 0, 0);
120 }
121
122
123 int InsetERT::latex(Buffer const *, std::ostream & os, bool /*fragile*/,
124                     bool /*free_spc*/) const
125 {
126         Paragraph * par = inset.paragraph();
127         while (par) {
128                 Paragraph::size_type siz = inset.paragraph()->size();
129                 for (Paragraph::size_type i = 0; i != siz; ++i) {
130                         char c = inset.paragraph()->getChar(i);
131                         switch (c) {
132                         case Paragraph::META_NEWLINE:
133                                 os << '\n';
134                                 break;
135                         default:
136                                 os << c;
137                                 break;
138                         }
139                 }
140                 par = par->next();
141         }
142         
143         return 1;
144 }
145
146
147 int InsetERT::ascii(Buffer const *,
148                     std::ostream &, int /*linelen*/) const 
149 {
150         return 0;
151 }
152
153
154 int InsetERT::linuxdoc(Buffer const *, std::ostream &) const
155 {
156         return 0;
157 }
158
159
160 int InsetERT::docBook(Buffer const *, std::ostream &) const
161 {
162         return 0;
163 }