]> git.lyx.org Git - lyx.git/blob - src/insets/insetert.C
4c76ca4c5f61ebb9ee0e81ab4b012dc7948ec299
[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"), true);
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, bool collapsed)
41         : InsetCollapsable(collapsed)
42 {
43         setLabel(_("666"));
44         LyXFont font(LyXFont::ALL_SANE);
45 #ifndef NO_LATEX
46         font.setLatex(LyXFont::ON);
47 #else
48         font.setColor(LColor::latex);
49 #endif
50         labelfont = LyXFont(LyXFont::ALL_SANE);
51         labelfont.decSize();
52         labelfont.decSize();
53         labelfont.setColor(LColor::latex);
54         setAutoCollapse(false);
55         setInsetName("ERT");
56
57         string::const_iterator cit = contents.begin();
58         string::const_iterator end = contents.end();
59         Paragraph::size_type pos = 0;
60         for (; cit != end; ++cit) {
61                 inset.paragraph()->insertChar(pos++, *cit, font);
62         }
63 }
64
65
66 void InsetERT::write(Buffer const * buf, ostream & os) const 
67 {
68         os << getInsetName() << "\n";
69         InsetCollapsable::write(buf, os);
70 }
71
72
73 Inset * InsetERT::clone(Buffer const &, bool same_id) const
74 {
75         InsetERT * result = new InsetERT;
76         result->inset.init(&inset, same_id);
77         
78         result->collapsed_ = collapsed_;
79         if (same_id)
80                 result->id_ = id_;
81         return result;
82 }
83
84
85 string const InsetERT::editMessage() const 
86 {
87         return _("Opened ERT Inset");
88 }
89
90
91 bool InsetERT::insertInset(BufferView *, Inset *)
92 {
93         return false;
94 }
95
96
97 void InsetERT::setFont(BufferView *, LyXFont const &, bool, bool selectall)
98 {
99         // if selectall is activated then the fontchange was an outside general
100         // fontchange and this messages is not needed
101         if (!selectall)
102                 WriteAlert(_("Impossible Operation!"),
103                            _("Not permitted to change font-types inside ERT-insets!"),
104                            _("Sorry."));
105 }
106
107
108 void InsetERT::edit(BufferView * bv, int x, int y, unsigned int button)
109 {
110         InsetCollapsable::edit(bv, x, y, button);
111 #ifndef NO_LATEX
112         LyXFont font(LyXFont::ALL_SANE);
113         font.setLatex (LyXFont::ON);
114 #endif
115 }
116
117
118 void InsetERT::edit(BufferView * bv, bool)
119 {
120         edit(bv, 0, 0, 0);
121 }
122
123
124 int InsetERT::latex(Buffer const *, std::ostream & os, bool /*fragile*/,
125                     bool /*free_spc*/) const
126 {
127         Paragraph * par = inset.paragraph();
128         while (par) {
129                 Paragraph::size_type siz = inset.paragraph()->size();
130                 for (Paragraph::size_type i = 0; i != siz; ++i) {
131                         char c = inset.paragraph()->getChar(i);
132                         switch (c) {
133                         case Paragraph::META_NEWLINE:
134                                 os << '\n';
135                                 break;
136                         default:
137                                 os << c;
138                                 break;
139                         }
140                 }
141                 par = par->next();
142         }
143         
144         return 1;
145 }
146
147
148 int InsetERT::ascii(Buffer const *,
149                     std::ostream &, int /*linelen*/) const 
150 {
151         return 0;
152 }
153
154
155 int InsetERT::linuxdoc(Buffer const *, std::ostream &) const
156 {
157         return 0;
158 }
159
160
161 int InsetERT::docBook(Buffer const *, std::ostream &) const
162 {
163         return 0;
164 }