1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 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"
28 /* Info, used for the Info boxes */
30 extern BufferView * current_view;
33 InsetInfo::InsetInfo()
39 InsetInfo::InsetInfo(string const & string)
46 InsetInfo::~InsetInfo()
56 int InsetInfo::ascent(Painter &, LyXFont const & font) const
58 return font.maxAscent() + 1;
62 int InsetInfo::descent(Painter &, LyXFont const & font) const
64 return font.maxDescent() + 1;
68 int InsetInfo::width(Painter &, LyXFont const & font) const
70 return 6 + font.textWidth(_("Note"), strlen(_("Note")));
74 void InsetInfo::draw(Painter & pain, LyXFont const & f,
75 int baseline, float & x) const
79 /* Info-insets are never LaTeX, so just correct the font */
80 font.setLatex(LyXFont::OFF);
82 // Draw as "Note" in a yellow box
84 pain.fillRectangle(int(x), baseline - ascent(pain, font) + 1,
85 width(pain, font) - 2,
86 ascent(pain, font) + descent(pain, font) - 2);
87 pain.rectangle(int(x), baseline - ascent(pain, font) + 1,
88 width(pain, font) - 2,
89 ascent(pain, font) + descent(pain, font) - 2);
91 pain.text(int(x + 2), baseline, _("Note"), font);
92 x += width(pain, font) - 1;
96 void InsetInfo::Write(ostream & os) const
98 os << "Info " << contents;
102 void InsetInfo::Read(LyXLex & lex)
104 string tmp = lex.GetString(); // should be "Info"
106 lyxerr << "ERROR (InsetInfo::Read): "
107 "consistency check 1 failed." << endl;
111 // blank line in the file being read
112 // should we skip blank lines?
115 string const token = strip(lex.GetString());
116 lyxerr[Debug::PARSER] << "Note: " << token << endl;
118 if (token != "\\end_inset") {
119 contents += token + '\n';
121 else // token == "\\end_inset"
124 // now remove the last '\n's
125 contents = strip(contents, '\n');
129 int InsetInfo::Latex(ostream &, signed char /*fragile*/) const
135 #ifndef USE_OSTREAM_ONLY
136 int InsetInfo::Latex(string &, signed char /*fragile*/) const
142 int InsetInfo::Linuxdoc(string &) const
148 int InsetInfo::DocBook(string &) const
155 int InsetInfo::Linuxdoc(ostream &) const
161 int InsetInfo::DocBook(ostream &) const
168 unsigned char InsetInfo::Editable() const
174 void InsetInfo::CloseInfoCB(FL_OBJECT * ob, long)
176 InsetInfo * inset = static_cast<InsetInfo*>(ob->u_vdata);
177 string tmp = fl_get_input(inset->strobj);
178 Buffer * buffer = current_view->buffer();
179 if(tmp != inset->contents && !(buffer->isReadonly()) ) {
181 inset->contents = tmp;
184 fl_hide_form(inset->form);
185 fl_free_form(inset->form);
191 // This is just a wrapper.
192 extern "C" void C_InsetInfo_CloseInfoCB(FL_OBJECT * ob, long data)
194 InsetInfo::CloseInfoCB(ob, data);
198 void InsetInfo::Edit(BufferView *bv, int, int, unsigned int)
200 static int ow = -1, oh;
202 if(bv->buffer()->isReadonly())
203 WarnReadonly(bv->buffer()->fileName());
207 form = fl_bgn_form(FL_UP_BOX, 400, 180);
208 strobj = obj = fl_add_input(FL_MULTILINE_INPUT, 10, 10, 380, 120, "");
209 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
210 fl_set_object_resize(obj, FL_RESIZE_ALL);
211 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
212 obj = fl_add_button(FL_NORMAL_BUTTON, 130, 140, 120, 30, idex(_("Close|#C^[")));
213 fl_set_object_resize(obj, FL_RESIZE_NONE);
214 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
215 fl_set_object_callback(obj, C_InsetInfo_CloseInfoCB, 0);
217 fl_set_object_shortcut(obj, scex(_("Close|#C^[")), 1);
219 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
221 fl_set_input(strobj, contents.c_str());
225 fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
231 fl_set_form_minsize(form, ow, oh);
236 Inset * InsetInfo::Clone() const
238 return new InsetInfo(contents);
242 Inset::Code InsetInfo::LyxCode() const
244 return Inset::IGNORE_CODE;