1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
16 #pragma implementation
19 #include "insetinfo.h"
20 #include "lyxparagraph.h"
23 #include "lyx_gui_misc.h" // CancelCloseBoxCB
25 #include "support/lstrings.h"
32 /* Info, used for the Info boxes */
34 extern BufferView * current_view;
37 InsetInfo::InsetInfo()
38 : form(0), labelfont(LyXFont::ALL_SANE)
40 labelfont.decSize().decSize()
41 .setColor(LColor::note).setLatex(LyXFont::OFF);
45 InsetInfo::InsetInfo(string const & str)
46 : contents(str), form(0), labelfont(LyXFont::ALL_SANE)
48 labelfont.decSize().decSize()
49 .setColor(LColor::note).setLatex(LyXFont::OFF);
53 InsetInfo::~InsetInfo()
63 int InsetInfo::ascent(BufferView *, LyXFont const &) const
65 return lyxfont::maxAscent(labelfont) + 1;
69 int InsetInfo::descent(BufferView *, LyXFont const &) const
71 return lyxfont::maxDescent(labelfont) + 1;
75 int InsetInfo::width(BufferView *, LyXFont const &) const
77 return 6 + lyxfont::width(_("Note"), labelfont);
81 void InsetInfo::draw(BufferView * bv, LyXFont const &,
82 int baseline, float & x, bool) const
84 Painter & pain = bv->painter();
88 // Info-insets are never LaTeX, so just correct the font
89 font.setLatex(LyXFont::OFF).setColor(LColor::note);
91 // Draw as "Note" in a yellow box
93 pain.fillRectangle(int(x), baseline - ascent(bv, labelfont),
94 width(bv, labelfont) - 2,
95 ascent(bv, labelfont) + descent(bv, labelfont) - 2,
97 pain.rectangle(int(x), baseline - ascent(bv, labelfont),
98 width(bv, labelfont) - 2,
99 ascent(bv, labelfont) + descent(bv, labelfont) - 2,
102 pain.text(int(x + 2), baseline, _("Note"), labelfont);
103 x += width(bv, labelfont) - 1;
107 void InsetInfo::Write(Buffer const *, ostream & os) const
109 os << "Info\n" << contents;
113 void InsetInfo::Read(Buffer const *, LyXLex & lex)
115 string tmp = lex.GetString(); // should be "Info"
117 lyxerr << "ERROR (InsetInfo::Read): "
118 "consistency check 1 failed." << endl;
122 // blank line in the file being read
123 // should we skip blank lines?
126 string const token = strip(lex.GetString());
127 lyxerr[Debug::PARSER] << "Note: " << token << endl;
129 if (token != "\\end_inset") {
130 contents += token + '\n';
132 else // token == "\\end_inset"
135 // now remove the last '\n's
136 contents = strip(contents, '\n');
140 int InsetInfo::Latex(Buffer const *, ostream &,
141 bool /*fragile*/, bool /*free_spc*/) const
147 int InsetInfo::Ascii(Buffer const *, ostream &) const
153 int InsetInfo::Linuxdoc(Buffer const *, ostream &) const
159 int InsetInfo::DocBook(Buffer const *, ostream &) const
165 Inset::EDITABLE InsetInfo::Editable() const
171 void InsetInfo::CloseInfoCB(FL_OBJECT * ob, long)
173 InsetInfo * inset = static_cast<InsetInfo*>(ob->u_vdata);
174 string tmp = fl_get_input(inset->strobj);
175 Buffer * buffer = current_view->buffer();
176 if(tmp != inset->contents && !(buffer->isReadonly()) ) {
178 inset->contents = tmp;
181 fl_hide_form(inset->form);
182 fl_free_form(inset->form);
188 // This is just a wrapper.
190 void C_InsetInfo_CloseInfoCB(FL_OBJECT * ob, long data)
192 InsetInfo::CloseInfoCB(ob, data);
196 char const * InsetInfo::EditMessage() const
198 return _("Opened note");
202 void InsetInfo::Edit(BufferView *bv, int, int, unsigned int)
204 static int ow = -1, oh;
206 if(bv->buffer()->isReadonly())
207 WarnReadonly(bv->buffer()->fileName());
211 form = fl_bgn_form(FL_UP_BOX, 400, 180);
212 strobj = obj = fl_add_input(FL_MULTILINE_INPUT, 10, 10, 380, 120, "");
213 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
214 fl_set_object_resize(obj, FL_RESIZE_ALL);
215 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
216 obj = fl_add_button(FL_NORMAL_BUTTON, 130, 140, 120, 30, idex(_("Close|#C^[")));
217 fl_set_object_resize(obj, FL_RESIZE_NONE);
218 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
219 fl_set_object_callback(obj, C_InsetInfo_CloseInfoCB, 0);
221 fl_set_object_shortcut(obj, scex(_("Close|#C^[")), 1);
223 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
225 fl_set_input(strobj, contents.c_str());
229 fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
235 fl_set_form_minsize(form, ow, oh);
240 Inset * InsetInfo::Clone() const
242 return new InsetInfo(contents);
246 Inset::Code InsetInfo::LyxCode() const
248 return Inset::IGNORE_CODE;