]> git.lyx.org Git - features.git/blob - src/insets/insetert.C
better ert handling
[features.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::size_type siz = inset.paragraph()->size();
121         for (Paragraph::size_type i = 0; i != siz; ++i) {
122                 char c = inset.paragraph()->getChar(i);
123                 switch (c) {
124                 case Paragraph::META_NEWLINE:
125                         os << '\n';
126                         break;
127                 default:
128                         os << c;
129                         break;
130                 }
131         }
132         return 1;
133 }
134
135
136 int InsetERT::ascii(Buffer const *,
137                     std::ostream &, int /*linelen*/) const 
138 {
139         return 0;
140 }
141
142
143 int InsetERT::linuxdoc(Buffer const *, std::ostream &) const
144 {
145         return 0;
146 }
147
148
149 int InsetERT::docBook(Buffer const *, std::ostream &) const
150 {
151         return 0;
152 }