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"
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*/, bool /*free_spc*/) const
135 int InsetInfo::Linuxdoc(ostream &) const
141 int InsetInfo::DocBook(ostream &) const
147 Inset::EDITABLE InsetInfo::Editable() const
153 void InsetInfo::CloseInfoCB(FL_OBJECT * ob, long)
155 InsetInfo * inset = static_cast<InsetInfo*>(ob->u_vdata);
156 string tmp = fl_get_input(inset->strobj);
157 Buffer * buffer = current_view->buffer();
158 if(tmp != inset->contents && !(buffer->isReadonly()) ) {
160 inset->contents = tmp;
163 fl_hide_form(inset->form);
164 fl_free_form(inset->form);
170 // This is just a wrapper.
171 extern "C" void C_InsetInfo_CloseInfoCB(FL_OBJECT * ob, long data)
173 InsetInfo::CloseInfoCB(ob, data);
177 void InsetInfo::Edit(BufferView *bv, int, int, unsigned int)
179 static int ow = -1, oh;
181 if(bv->buffer()->isReadonly())
182 WarnReadonly(bv->buffer()->fileName());
186 form = fl_bgn_form(FL_UP_BOX, 400, 180);
187 strobj = obj = fl_add_input(FL_MULTILINE_INPUT, 10, 10, 380, 120, "");
188 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
189 fl_set_object_resize(obj, FL_RESIZE_ALL);
190 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
191 obj = fl_add_button(FL_NORMAL_BUTTON, 130, 140, 120, 30, idex(_("Close|#C^[")));
192 fl_set_object_resize(obj, FL_RESIZE_NONE);
193 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
194 fl_set_object_callback(obj, C_InsetInfo_CloseInfoCB, 0);
196 fl_set_object_shortcut(obj, scex(_("Close|#C^[")), 1);
198 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
200 fl_set_input(strobj, contents.c_str());
204 fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
210 fl_set_form_minsize(form, ow, oh);
215 Inset * InsetInfo::Clone() const
217 return new InsetInfo(contents);
221 Inset::Code InsetInfo::LyxCode() const
223 return Inset::IGNORE_CODE;