]> git.lyx.org Git - lyx.git/blob - src/insets/insetert.C
Added copy constructor to inset.h and used it in most insets which permit
[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 #include "BufferView.h"
24 #include "LyXView.h"
25
26 using std::ostream;
27
28 void InsetERT::init()
29 {
30         setLabel(_("666"), true);
31         labelfont = LyXFont(LyXFont::ALL_SANE);
32         labelfont.decSize();
33         labelfont.decSize();
34 #ifndef NO_LATEX
35         labelfont.setLatex(LyXFont::ON);
36 #else
37         labelfont.setColor(LColor::latex);
38 #endif
39         setInsetName("ERT");
40 }
41
42
43 InsetERT::InsetERT() : InsetCollapsable()
44 {
45         init();
46 }
47
48
49 #if 0
50 InsetERT::InsetERT(InsetERT const & in, bool same_id)
51         : InsetCollapsable(in, same_id)
52 {
53 }
54 #endif
55
56
57 InsetERT::InsetERT(string const & contents, bool collapsed)
58         : InsetCollapsable(collapsed)
59 {
60         LyXFont font(LyXFont::ALL_INHERIT);
61         font.setFamily(LyXFont::TYPEWRITER_FAMILY);
62         font.setColor(LColor::latex);
63         string::const_iterator cit = contents.begin();
64         string::const_iterator end = contents.end();
65         Paragraph::size_type pos = 0;
66         for (; cit != end; ++cit) {
67                 inset.paragraph()->insertChar(pos++, *cit, font);
68         }
69         // the init has to be after the initialization of the paragraph
70         // because of the label settings (draw_label for ert insets).
71         init();
72 }
73
74
75 void InsetERT::write(Buffer const * buf, ostream & os) const 
76 {
77         os << getInsetName() << "\n";
78         InsetCollapsable::write(buf, os);
79 }
80
81
82 string const InsetERT::editMessage() const 
83 {
84         return _("Opened ERT Inset");
85 }
86
87
88 bool InsetERT::insertInset(BufferView *, Inset *)
89 {
90         return false;
91 }
92
93
94 void InsetERT::setFont(BufferView *, LyXFont const &, bool, bool selectall)
95 {
96         // if selectall is activated then the fontchange was an outside general
97         // fontchange and this messages is not needed
98         if (!selectall)
99                 WriteAlert(_("Impossible Operation!"),
100                            _("Not permitted to change font-types inside ERT-insets!"),
101                            _("Sorry."));
102 }
103
104
105 void InsetERT::edit(BufferView * bv, int x, int y, unsigned int button)
106 {
107         InsetCollapsable::edit(bv, x, y, button);
108 #ifndef NO_LATEX
109         LyXFont font(LyXFont::ALL_SANE);
110         font.setLatex (LyXFont::ON);
111 #else
112         LyXFont font(LyXFont::ALL_INHERIT);
113         font.setFamily(LyXFont::TYPEWRITER_FAMILY);
114         font.setColor(LColor::latex);
115 #endif
116         inset.setFont(bv, font);
117 }
118
119
120 void InsetERT::edit(BufferView * bv, bool)
121 {
122         edit(bv, 0, 0, 0);
123 }
124
125
126 int InsetERT::latex(Buffer const *, std::ostream & os, bool /*fragile*/,
127                     bool /*free_spc*/) const
128 {
129         Paragraph * par = inset.paragraph();
130         while (par) {
131                 Paragraph::size_type siz = inset.paragraph()->size();
132                 for (Paragraph::size_type i = 0; i != siz; ++i) {
133                         char c = inset.paragraph()->getChar(i);
134                         switch (c) {
135                         case Paragraph::META_NEWLINE:
136                                 os << '\n';
137                                 break;
138                         default:
139                                 os << c;
140                                 break;
141                         }
142                 }
143                 par = par->next();
144         }
145         
146         return 1;
147 }
148
149
150 int InsetERT::ascii(Buffer const *,
151                     std::ostream &, int /*linelen*/) const 
152 {
153         return 0;
154 }
155
156
157 int InsetERT::linuxdoc(Buffer const *, std::ostream &) const
158 {
159         return 0;
160 }
161
162
163 int InsetERT::docBook(Buffer const *, std::ostream &) const
164 {
165         return 0;
166 }
167
168
169 UpdatableInset::RESULT
170 InsetERT::localDispatch(BufferView * bv, kb_action action, string const & arg)
171 {
172         UpdatableInset::RESULT result = DISPATCHED_NOUPDATE;
173         
174         switch(action) {
175         case LFUN_LAYOUT:
176                 bv->owner()->setLayout(inset.paragraph()->getLayout());
177                 break;
178         default:
179                 result = InsetCollapsable::localDispatch(bv, action, arg);
180         }
181         switch(action) {
182         case LFUN_BREAKPARAGRAPH:
183         case LFUN_BREAKPARAGRAPHKEEPLAYOUT: {
184 #ifndef NO_LATEX
185                 LyXFont font(LyXFont::ALL_SANE);
186                 font.setLatex (LyXFont::ON);
187 #else
188                 LyXFont font(LyXFont::ALL_INHERIT);
189                 font.setFamily(LyXFont::TYPEWRITER_FAMILY);
190                 font.setColor(LColor::latex);
191 #endif
192                 inset.setFont(bv, font);
193         }
194                 break;
195         default:
196                 break;
197         }
198         return result;
199 }