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)
44 .setLatex(LyXFont::OFF)
50 InsetInfo::InsetInfo(string const & str)
51 : contents(str), form(0), labelfont(LyXFont::ALL_SANE)
53 labelfont.decSize().decSize()
54 .setColor(LColor::note)
56 .setLatex(LyXFont::OFF)
62 InsetInfo::~InsetInfo()
72 int InsetInfo::ascent(BufferView *, LyXFont const &) const
74 return lyxfont::maxAscent(labelfont) + 1;
78 int InsetInfo::descent(BufferView *, LyXFont const &) const
80 return lyxfont::maxDescent(labelfont) + 1;
84 int InsetInfo::width(BufferView *, LyXFont const &) const
86 return 6 + lyxfont::width(_("Note"), labelfont);
90 void InsetInfo::draw(BufferView * bv, LyXFont const &,
91 int baseline, float & x, bool) const
93 Painter & pain = bv->painter();
95 // Draw as "Note" in a yellow box
97 pain.fillRectangle(int(x), baseline - ascent(bv, labelfont),
98 width(bv, labelfont) - 2,
99 ascent(bv, labelfont) + descent(bv, labelfont) - 2,
101 pain.rectangle(int(x), baseline - ascent(bv, labelfont),
102 width(bv, labelfont) - 2,
103 ascent(bv, labelfont) + descent(bv, labelfont) - 2,
106 pain.text(int(x + 2), baseline, _("Note"), labelfont);
107 x += width(bv, labelfont) - 1;
111 void InsetInfo::write(Buffer const *, ostream & os) const
113 os << "Info\n" << contents;
117 void InsetInfo::read(Buffer const *, LyXLex & lex)
119 string tmp = lex.GetString(); // should be "Info"
121 lyxerr << "ERROR (InsetInfo::Read): "
122 "consistency check 1 failed." << endl;
126 // blank line in the file being read
127 // should we skip blank lines?
130 string const token = strip(lex.GetString());
131 lyxerr[Debug::PARSER] << "Note: " << token << endl;
133 if (token != "\\end_inset") {
134 contents += token + '\n';
136 else // token == "\\end_inset"
139 // now remove the last '\n's
140 contents = strip(contents, '\n');
144 int InsetInfo::latex(Buffer const *, ostream &,
145 bool /*fragile*/, bool /*free_spc*/) const
151 int InsetInfo::ascii(Buffer const *, ostream &, int) const
157 int InsetInfo::linuxdoc(Buffer const *, ostream &) const
163 int InsetInfo::docBook(Buffer const *, ostream &) const
169 Inset::EDITABLE InsetInfo::editable() const
175 void InsetInfo::closeInfoCB(FL_OBJECT * ob, long)
177 InsetInfo * inset = static_cast<InsetInfo*>(ob->u_vdata);
178 string tmp = fl_get_input(inset->strobj);
179 Buffer * buffer = current_view->buffer();
180 if (tmp != inset->contents && !(buffer->isReadonly())) {
182 inset->contents = tmp;
185 fl_hide_form(inset->form);
186 fl_free_form(inset->form);
192 // This is just a wrapper.
194 void C_InsetInfo_CloseInfoCB(FL_OBJECT * ob, long data)
196 InsetInfo::closeInfoCB(ob, data);
200 string const InsetInfo::editMessage() const
202 return _("Opened note");
206 void InsetInfo::edit(BufferView *bv, int, int, unsigned int)
211 if (bv->buffer()->isReadonly())
212 WarnReadonly(bv->buffer()->fileName());
216 form = fl_bgn_form(FL_UP_BOX, 400, 180);
217 strobj = obj = fl_add_input(FL_MULTILINE_INPUT, 10, 10, 380, 120, "");
218 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
219 fl_set_object_resize(obj, FL_RESIZE_ALL);
220 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
221 obj = fl_add_button(FL_NORMAL_BUTTON, 130, 140, 120, 30, idex(_("Close|#C^[")));
222 fl_set_object_resize(obj, FL_RESIZE_NONE);
223 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
224 fl_set_object_callback(obj, C_InsetInfo_CloseInfoCB, 0);
226 fl_set_object_shortcut(obj, scex(_("Close|#C^[")), 1);
228 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
230 fl_set_input(strobj, contents.c_str());
235 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
241 fl_set_form_minsize(form, ow, oh);
246 void InsetInfo::edit(BufferView * bv, bool)
252 Inset * InsetInfo::clone(Buffer const &, bool) const
254 return new InsetInfo(contents);
258 Inset::Code InsetInfo::lyxCode() const
260 return Inset::IGNORE_CODE;