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"
32 labelfont = LyXFont(LyXFont::ALL_SANE);
35 labelfont.setColor(LColor::latex);
40 InsetERT::InsetERT() : InsetCollapsable()
46 InsetERT::InsetERT(string const & contents, bool collapsed)
47 : InsetCollapsable(collapsed)
49 LyXFont font(LyXFont::ALL_INHERIT);
50 font.setFamily(LyXFont::TYPEWRITER_FAMILY);
51 font.setColor(LColor::latex);
52 string::const_iterator cit = contents.begin();
53 string::const_iterator end = contents.end();
54 Paragraph::size_type pos = 0;
55 for (; cit != end; ++cit) {
56 inset.paragraph()->insertChar(pos++, *cit, font);
58 // the init has to be after the initialization of the paragraph
59 // because of the label settings (draw_label for ert insets).
64 void InsetERT::read(Buffer const * buf, LyXLex & lex)
66 InsetCollapsable::read(buf, lex);
72 void InsetERT::write(Buffer const * buf, ostream & os) const
74 os << getInsetName() << "\n";
75 InsetCollapsable::write(buf, os);
79 string const InsetERT::editMessage() const
81 return _("Opened ERT Inset");
85 bool InsetERT::insertInset(BufferView *, Inset *)
91 void InsetERT::setFont(BufferView *, LyXFont const &, bool, bool selectall)
93 // if selectall is activated then the fontchange was an outside general
94 // fontchange and this messages is not needed
96 WriteAlert(_("Impossible Operation!"),
97 _("Not permitted to change font-types inside ERT-insets!"),
102 void InsetERT::edit(BufferView * bv, int x, int y, unsigned int button)
104 InsetCollapsable::edit(bv, x, y, button);
106 LyXFont font(LyXFont::ALL_INHERIT);
107 font.setFamily(LyXFont::TYPEWRITER_FAMILY);
108 font.setColor(LColor::latex);
110 inset.setFont(bv, font);
114 void InsetERT::edit(BufferView * bv, bool)
120 void InsetERT::insetButtonRelease(BufferView * bv,
121 int x, int y, int button)
123 if ((x >= 0) && (x < button_length) &&
124 (y >= button_top_y) && (y <= button_bottom_y)) {
128 setLabel(get_new_label());
131 InsetCollapsable::insetButtonRelease(bv, x, y, button);
135 int InsetERT::latex(Buffer const *, std::ostream & os, bool /*fragile*/,
136 bool /*free_spc*/) const
138 Paragraph * par = inset.paragraph();
140 Paragraph::size_type siz = inset.paragraph()->size();
141 for (Paragraph::size_type i = 0; i != siz; ++i) {
142 char c = inset.paragraph()->getChar(i);
144 case Paragraph::META_NEWLINE:
159 int InsetERT::ascii(Buffer const *,
160 std::ostream &, int /*linelen*/) const
166 int InsetERT::linuxdoc(Buffer const *, std::ostream &) const
172 int InsetERT::docBook(Buffer const *, std::ostream &) const
178 UpdatableInset::RESULT
179 InsetERT::localDispatch(BufferView * bv, kb_action action, string const & arg)
181 UpdatableInset::RESULT result = DISPATCHED_NOUPDATE;
185 bv->owner()->setLayout(inset.paragraph()->getLayout());
188 result = InsetCollapsable::localDispatch(bv, action, arg);
191 case LFUN_BREAKPARAGRAPH:
192 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
194 LyXFont font(LyXFont::ALL_INHERIT);
195 font.setFamily(LyXFont::TYPEWRITER_FAMILY);
196 font.setColor(LColor::latex);
197 inset.setFont(bv, font);
208 string const InsetERT::get_new_label() const
211 Paragraph::size_type const max_length = 15;
213 int const p_siz = inset.paragraph()->size();
214 int const n = std::min(max_length, p_siz);
217 for(; i < n && j < p_siz; ++j) {
218 if (inset.paragraph()->isInset(j))
220 la += inset.paragraph()->getChar(j);
223 if (i > 0 && j < p_siz) {
233 void InsetERT::setButtonLabel()
236 setLabel(get_new_label());