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"
30 /* Info, used for the Info boxes */
32 extern BufferView * current_view;
35 InsetInfo::InsetInfo()
41 InsetInfo::InsetInfo(string const & string)
48 InsetInfo::~InsetInfo()
58 int InsetInfo::ascent(Painter &, LyXFont const & font) const
60 return font.maxAscent() + 1;
64 int InsetInfo::descent(Painter &, LyXFont const & font) const
66 return font.maxDescent() + 1;
70 int InsetInfo::width(Painter &, LyXFont const & font) const
72 return 6 + font.textWidth(_("Note"), strlen(_("Note")));
76 void InsetInfo::draw(Painter & pain, LyXFont const & f,
77 int baseline, float & x) const
81 /* Info-insets are never LaTeX, so just correct the font */
82 font.setLatex(LyXFont::OFF);
84 // Draw as "Note" in a yellow box
86 pain.fillRectangle(int(x), baseline - ascent(pain, font) + 1,
87 width(pain, font) - 2,
88 ascent(pain, font) + descent(pain, font) - 2);
89 pain.rectangle(int(x), baseline - ascent(pain, font) + 1,
90 width(pain, font) - 2,
91 ascent(pain, font) + descent(pain, font) - 2);
93 pain.text(int(x + 2), baseline, _("Note"), font);
94 x += width(pain, font) - 1;
98 void InsetInfo::Write(ostream & os) const
100 os << "Info " << contents;
104 void InsetInfo::Read(LyXLex & lex)
106 string tmp = lex.GetString(); // should be "Info"
108 lyxerr << "ERROR (InsetInfo::Read): "
109 "consistency check 1 failed." << endl;
113 // blank line in the file being read
114 // should we skip blank lines?
117 string const token = strip(lex.GetString());
118 lyxerr[Debug::PARSER] << "Note: " << token << endl;
120 if (token != "\\end_inset") {
121 contents += token + '\n';
123 else // token == "\\end_inset"
126 // now remove the last '\n's
127 contents = strip(contents, '\n');
131 int InsetInfo::Latex(ostream &,
132 signed char /*fragile*/, bool /*free_spc*/) const
138 int InsetInfo::Linuxdoc(ostream &) const
144 int InsetInfo::DocBook(ostream &) const
150 Inset::EDITABLE InsetInfo::Editable() const
156 void InsetInfo::CloseInfoCB(FL_OBJECT * ob, long)
158 InsetInfo * inset = static_cast<InsetInfo*>(ob->u_vdata);
159 string tmp = fl_get_input(inset->strobj);
160 Buffer * buffer = current_view->buffer();
161 if(tmp != inset->contents && !(buffer->isReadonly()) ) {
163 inset->contents = tmp;
166 fl_hide_form(inset->form);
167 fl_free_form(inset->form);
173 // This is just a wrapper.
174 extern "C" void C_InsetInfo_CloseInfoCB(FL_OBJECT * ob, long data)
176 InsetInfo::CloseInfoCB(ob, data);
180 void InsetInfo::Edit(BufferView *bv, int, int, unsigned int)
182 static int ow = -1, oh;
184 if(bv->buffer()->isReadonly())
185 WarnReadonly(bv->buffer()->fileName());
189 form = fl_bgn_form(FL_UP_BOX, 400, 180);
190 strobj = obj = fl_add_input(FL_MULTILINE_INPUT, 10, 10, 380, 120, "");
191 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
192 fl_set_object_resize(obj, FL_RESIZE_ALL);
193 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
194 obj = fl_add_button(FL_NORMAL_BUTTON, 130, 140, 120, 30, idex(_("Close|#C^[")));
195 fl_set_object_resize(obj, FL_RESIZE_NONE);
196 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
197 fl_set_object_callback(obj, C_InsetInfo_CloseInfoCB, 0);
199 fl_set_object_shortcut(obj, scex(_("Close|#C^[")), 1);
201 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
203 fl_set_input(strobj, contents.c_str());
207 fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
213 fl_set_form_minsize(form, ow, oh);
218 Inset * InsetInfo::Clone() const
220 return new InsetInfo(contents);
224 Inset::Code InsetInfo::LyxCode() const
226 return Inset::IGNORE_CODE;