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 setLabel(_("666"), true);
35 labelfont = LyXFont(LyXFont::ALL_SANE);
39 labelfont.setLatex(LyXFont::ON);
41 labelfont.setColor(LColor::latex);
47 InsetERT::InsetERT() : InsetCollapsable()
54 InsetERT::InsetERT(InsetERT const & in, bool same_id)
55 : InsetCollapsable(in, same_id)
61 InsetERT::InsetERT(string const & contents, bool collapsed)
62 : InsetCollapsable(collapsed)
64 LyXFont font(LyXFont::ALL_INHERIT);
65 font.setFamily(LyXFont::TYPEWRITER_FAMILY);
66 font.setColor(LColor::latex);
67 string::const_iterator cit = contents.begin();
68 string::const_iterator end = contents.end();
69 Paragraph::size_type pos = 0;
70 for (; cit != end; ++cit) {
71 inset.paragraph()->insertChar(pos++, *cit, font);
73 // the init has to be after the initialization of the paragraph
74 // because of the label settings (draw_label for ert insets).
79 void InsetERT::read(Buffer const * buf, LyXLex & lex)
81 InsetCollapsable::read(buf, lex);
83 setLabel(get_new_label());
90 void InsetERT::write(Buffer const * buf, ostream & os) const
92 os << getInsetName() << "\n";
93 InsetCollapsable::write(buf, os);
97 string const InsetERT::editMessage() const
99 return _("Opened ERT Inset");
103 bool InsetERT::insertInset(BufferView *, Inset *)
109 void InsetERT::setFont(BufferView *, LyXFont const &, bool, bool selectall)
111 // if selectall is activated then the fontchange was an outside general
112 // fontchange and this messages is not needed
114 WriteAlert(_("Impossible Operation!"),
115 _("Not permitted to change font-types inside ERT-insets!"),
120 void InsetERT::edit(BufferView * bv, int x, int y, unsigned int button)
122 InsetCollapsable::edit(bv, x, y, button);
124 LyXFont font(LyXFont::ALL_SANE);
125 font.setLatex (LyXFont::ON);
127 LyXFont font(LyXFont::ALL_INHERIT);
128 font.setFamily(LyXFont::TYPEWRITER_FAMILY);
129 font.setColor(LColor::latex);
131 inset.setFont(bv, font);
135 void InsetERT::edit(BufferView * bv, bool)
141 void InsetERT::insetButtonRelease(BufferView * bv,
142 int x, int y, int button)
144 if ((x >= 0) && (x < button_length) &&
145 (y >= button_top_y) && (y <= button_bottom_y)) {
149 setLabel(get_new_label());
152 InsetCollapsable::insetButtonRelease(bv, x, y, button);
156 int InsetERT::latex(Buffer const *, std::ostream & os, bool /*fragile*/,
157 bool /*free_spc*/) const
159 Paragraph * par = inset.paragraph();
161 Paragraph::size_type siz = inset.paragraph()->size();
162 for (Paragraph::size_type i = 0; i != siz; ++i) {
163 char c = inset.paragraph()->getChar(i);
165 case Paragraph::META_NEWLINE:
180 int InsetERT::ascii(Buffer const *,
181 std::ostream &, int /*linelen*/) const
187 int InsetERT::linuxdoc(Buffer const *, std::ostream &) const
193 int InsetERT::docBook(Buffer const *, std::ostream &) const
199 UpdatableInset::RESULT
200 InsetERT::localDispatch(BufferView * bv, kb_action action, string const & arg)
202 UpdatableInset::RESULT result = DISPATCHED_NOUPDATE;
206 bv->owner()->setLayout(inset.paragraph()->getLayout());
209 result = InsetCollapsable::localDispatch(bv, action, arg);
212 case LFUN_BREAKPARAGRAPH:
213 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
216 LyXFont font(LyXFont::ALL_SANE);
217 font.setLatex (LyXFont::ON);
219 LyXFont font(LyXFont::ALL_INHERIT);
220 font.setFamily(LyXFont::TYPEWRITER_FAMILY);
221 font.setColor(LColor::latex);
223 inset.setFont(bv, font);
234 string const InsetERT::get_new_label() const
237 Paragraph::size_type const max_length = 15;
239 int const n = std::min(max_length, inset.paragraph()->size());
242 for(; i < n && j < inset.paragraph()->size(); ++j) {
243 if (inset.paragraph()->isInset(j))
245 la += inset.paragraph()->getChar(j);
248 if ((i > 0) && (j < inset.paragraph()->size()))