1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1998 The LyX Team.
8 *======================================================*/
13 #pragma implementation
20 #include "insets/insettext.h"
21 #include "support/LOstream.h"
22 #include "lyx_gui_misc.h"
23 #include "BufferView.h"
31 labelfont = LyXFont(LyXFont::ALL_SANE);
34 labelfont.setColor(LColor::latex);
39 InsetERT::InsetERT() : InsetCollapsable()
45 InsetERT::InsetERT(InsetERT const & in, bool same_id)
46 : InsetCollapsable(in, same_id)
52 Inset * InsetERT::clone(Buffer const &, bool same_id) const
54 return new InsetERT(*const_cast<InsetERT *>(this), same_id);
58 InsetERT::InsetERT(string const & contents, bool collapsed)
59 : InsetCollapsable(collapsed)
61 LyXFont font(LyXFont::ALL_INHERIT);
62 font.setFamily(LyXFont::TYPEWRITER_FAMILY);
63 font.setColor(LColor::latex);
64 string::const_iterator cit = contents.begin();
65 string::const_iterator end = contents.end();
66 Paragraph::size_type pos = 0;
67 for (; cit != end; ++cit) {
68 inset.paragraph()->insertChar(pos++, *cit, font);
70 // the init has to be after the initialization of the paragraph
71 // because of the label settings (draw_label for ert insets).
76 void InsetERT::read(Buffer const * buf, LyXLex & lex)
78 InsetCollapsable::read(buf, lex);
84 void InsetERT::write(Buffer const * buf, ostream & os) const
86 os << getInsetName() << "\n";
87 InsetCollapsable::write(buf, os);
91 string const InsetERT::editMessage() const
93 return _("Opened ERT Inset");
97 bool InsetERT::insertInset(BufferView *, Inset *)
103 void InsetERT::setFont(BufferView *, LyXFont const &, bool, bool selectall)
105 // if selectall is activated then the fontchange was an outside general
106 // fontchange and this messages is not needed
108 WriteAlert(_("Impossible Operation!"),
109 _("Not permitted to change font-types inside ERT-insets!"),
114 void InsetERT::edit(BufferView * bv, int x, int y, unsigned int button)
116 InsetCollapsable::edit(bv, x, y, button);
118 LyXFont font(LyXFont::ALL_INHERIT);
119 font.setFamily(LyXFont::TYPEWRITER_FAMILY);
120 font.setColor(LColor::latex);
122 inset.setFont(bv, font);
126 void InsetERT::edit(BufferView * bv, bool)
132 void InsetERT::insetButtonRelease(BufferView * bv,
133 int x, int y, int button)
135 if ((x >= 0) && (x < button_length) &&
136 (y >= button_top_y) && (y <= button_bottom_y)) {
140 setLabel(get_new_label());
143 InsetCollapsable::insetButtonRelease(bv, x, y, button);
147 int InsetERT::latex(Buffer const *, std::ostream & os, bool /*fragile*/,
148 bool /*free_spc*/) const
150 Paragraph * par = inset.paragraph();
152 Paragraph::size_type siz = inset.paragraph()->size();
153 for (Paragraph::size_type i = 0; i != siz; ++i) {
154 char c = inset.paragraph()->getChar(i);
156 case Paragraph::META_NEWLINE:
171 int InsetERT::ascii(Buffer const *,
172 std::ostream &, int /*linelen*/) const
178 int InsetERT::linuxdoc(Buffer const *, std::ostream &) const
184 int InsetERT::docBook(Buffer const *, std::ostream &) const
190 UpdatableInset::RESULT
191 InsetERT::localDispatch(BufferView * bv, kb_action action, string const & arg)
193 UpdatableInset::RESULT result = DISPATCHED_NOUPDATE;
197 bv->owner()->setLayout(inset.paragraph()->getLayout());
200 result = InsetCollapsable::localDispatch(bv, action, arg);
203 case LFUN_BREAKPARAGRAPH:
204 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
206 LyXFont font(LyXFont::ALL_INHERIT);
207 font.setFamily(LyXFont::TYPEWRITER_FAMILY);
208 font.setColor(LColor::latex);
209 inset.setFont(bv, font);
220 string const InsetERT::get_new_label() const
223 Paragraph::size_type const max_length = 15;
225 Paragraph::size_type const p_siz = inset.paragraph()->size();
226 Paragraph::size_type const n = std::min(max_length, p_siz);
229 for(; i < n && j < p_siz; ++j) {
230 if (inset.paragraph()->isInset(j))
232 la += inset.paragraph()->getChar(j);
235 if (i > 0 && j < p_siz) {
245 void InsetERT::setButtonLabel()
248 setLabel(get_new_label());
255 bool InsetERT::checkInsertChar(LyXFont & font)
257 LyXFont f(LyXFont::ALL_INHERIT);
259 font.setFamily(LyXFont::TYPEWRITER_FAMILY);
260 font.setColor(LColor::latex);