1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team.
9 * ====================================================== */
16 #pragma implementation
19 #include "insetinfo.h"
20 #include "paragraph.h"
23 #include "lyx_gui_misc.h" // CancelCloseBoxCB
25 #include "support/lstrings.h"
28 #include "BufferView.h"
33 /* Info, used for the Info boxes */
35 extern BufferView * current_view;
38 InsetInfo::InsetInfo()
39 : form(0), labelfont(LyXFont::ALL_SANE)
41 labelfont.decSize().decSize()
42 .setColor(LColor::note).setLatex(LyXFont::OFF);
46 InsetInfo::InsetInfo(string const & str)
47 : contents(str), form(0), labelfont(LyXFont::ALL_SANE)
49 labelfont.decSize().decSize()
50 .setColor(LColor::note).setLatex(LyXFont::OFF);
54 InsetInfo::~InsetInfo()
64 int InsetInfo::ascent(BufferView *, LyXFont const &) const
66 return lyxfont::maxAscent(labelfont) + 1;
70 int InsetInfo::descent(BufferView *, LyXFont const &) const
72 return lyxfont::maxDescent(labelfont) + 1;
76 int InsetInfo::width(BufferView *, LyXFont const &) const
78 return 6 + lyxfont::width(_("Note"), labelfont);
82 void InsetInfo::draw(BufferView * bv, LyXFont const &,
83 int baseline, float & x, bool) const
85 Painter & pain = bv->painter();
87 // Draw as "Note" in a yellow box
89 pain.fillRectangle(int(x), baseline - ascent(bv, labelfont),
90 width(bv, labelfont) - 2,
91 ascent(bv, labelfont) + descent(bv, labelfont) - 2,
93 pain.rectangle(int(x), baseline - ascent(bv, labelfont),
94 width(bv, labelfont) - 2,
95 ascent(bv, labelfont) + descent(bv, labelfont) - 2,
98 pain.text(int(x + 2), baseline, _("Note"), labelfont);
99 x += width(bv, labelfont) - 1;
103 void InsetInfo::Write(Buffer const *, ostream & os) const
105 os << "Info\n" << contents;
109 void InsetInfo::Read(Buffer const *, LyXLex & lex)
111 string tmp = lex.GetString(); // should be "Info"
113 lyxerr << "ERROR (InsetInfo::Read): "
114 "consistency check 1 failed." << endl;
118 // blank line in the file being read
119 // should we skip blank lines?
122 string const token = strip(lex.GetString());
123 lyxerr[Debug::PARSER] << "Note: " << token << endl;
125 if (token != "\\end_inset") {
126 contents += token + '\n';
128 else // token == "\\end_inset"
131 // now remove the last '\n's
132 contents = strip(contents, '\n');
136 int InsetInfo::Latex(Buffer const *, ostream &,
137 bool /*fragile*/, bool /*free_spc*/) const
143 int InsetInfo::Ascii(Buffer const *, ostream &, int) const
149 int InsetInfo::Linuxdoc(Buffer const *, ostream &) const
155 int InsetInfo::DocBook(Buffer const *, ostream &) const
161 Inset::EDITABLE InsetInfo::Editable() const
167 void InsetInfo::CloseInfoCB(FL_OBJECT * ob, long)
169 InsetInfo * inset = static_cast<InsetInfo*>(ob->u_vdata);
170 string tmp = fl_get_input(inset->strobj);
171 Buffer * buffer = current_view->buffer();
172 if (tmp != inset->contents && !(buffer->isReadonly())) {
174 inset->contents = tmp;
177 fl_hide_form(inset->form);
178 fl_free_form(inset->form);
184 // This is just a wrapper.
186 void C_InsetInfo_CloseInfoCB(FL_OBJECT * ob, long data)
188 InsetInfo::CloseInfoCB(ob, data);
192 string const InsetInfo::EditMessage() const
194 return _("Opened note");
198 void InsetInfo::Edit(BufferView *bv, int, int, unsigned int)
203 if (bv->buffer()->isReadonly())
204 WarnReadonly(bv->buffer()->fileName());
208 form = fl_bgn_form(FL_UP_BOX, 400, 180);
209 strobj = obj = fl_add_input(FL_MULTILINE_INPUT, 10, 10, 380, 120, "");
210 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
211 fl_set_object_resize(obj, FL_RESIZE_ALL);
212 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
213 obj = fl_add_button(FL_NORMAL_BUTTON, 130, 140, 120, 30, idex(_("Close|#C^[")));
214 fl_set_object_resize(obj, FL_RESIZE_NONE);
215 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
216 fl_set_object_callback(obj, C_InsetInfo_CloseInfoCB, 0);
218 fl_set_object_shortcut(obj, scex(_("Close|#C^[")), 1);
220 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
222 fl_set_input(strobj, contents.c_str());
227 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
233 fl_set_form_minsize(form, ow, oh);
238 Inset * InsetInfo::Clone(Buffer const &) const
240 return new InsetInfo(contents);
244 Inset::Code InsetInfo::LyxCode() const
246 return Inset::IGNORE_CODE;