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