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"
32 /* Info, used for the Info boxes */
34 extern BufferView * current_view;
37 InsetInfo::InsetInfo()
43 InsetInfo::InsetInfo(string const & string)
50 InsetInfo::~InsetInfo()
60 int InsetInfo::ascent(Painter &, LyXFont const & font) const
62 return lyxfont::maxAscent(font) + 1;
66 int InsetInfo::descent(Painter &, LyXFont const & font) const
68 return lyxfont::maxDescent(font) + 1;
72 int InsetInfo::width(Painter &, LyXFont const & font) const
74 return 6 + lyxfont::width(_("Note"), font);
78 void InsetInfo::draw(Painter & pain, LyXFont const & f,
79 int baseline, float & x) const
83 /* Info-insets are never LaTeX, so just correct the font */
84 font.setLatex(LyXFont::OFF);
86 // Draw as "Note" in a yellow box
88 pain.fillRectangle(int(x), baseline - ascent(pain, font) + 1,
89 width(pain, font) - 2,
90 ascent(pain, font) + descent(pain, font) - 2);
91 pain.rectangle(int(x), baseline - ascent(pain, font) + 1,
92 width(pain, font) - 2,
93 ascent(pain, font) + descent(pain, font) - 2);
95 pain.text(int(x + 2), baseline, _("Note"), font);
96 x += width(pain, font) - 1;
100 void InsetInfo::Write(ostream & os) const
102 os << "Info " << contents;
106 void InsetInfo::Read(LyXLex & lex)
108 string tmp = lex.GetString(); // should be "Info"
110 lyxerr << "ERROR (InsetInfo::Read): "
111 "consistency check 1 failed." << endl;
115 // blank line in the file being read
116 // should we skip blank lines?
119 string const token = strip(lex.GetString());
120 lyxerr[Debug::PARSER] << "Note: " << token << endl;
122 if (token != "\\end_inset") {
123 contents += token + '\n';
125 else // token == "\\end_inset"
128 // now remove the last '\n's
129 contents = strip(contents, '\n');
133 int InsetInfo::Latex(ostream &,
134 signed char /*fragile*/, bool /*free_spc*/) const
140 int InsetInfo::Linuxdoc(ostream &) const
146 int InsetInfo::DocBook(ostream &) const
152 Inset::EDITABLE InsetInfo::Editable() const
158 void InsetInfo::CloseInfoCB(FL_OBJECT * ob, long)
160 InsetInfo * inset = static_cast<InsetInfo*>(ob->u_vdata);
161 string tmp = fl_get_input(inset->strobj);
162 Buffer * buffer = current_view->buffer();
163 if(tmp != inset->contents && !(buffer->isReadonly()) ) {
165 inset->contents = tmp;
168 fl_hide_form(inset->form);
169 fl_free_form(inset->form);
175 // This is just a wrapper.
176 extern "C" void C_InsetInfo_CloseInfoCB(FL_OBJECT * ob, long data)
178 InsetInfo::CloseInfoCB(ob, data);
182 char const * InsetInfo::EditMessage() const
184 return _("Opened note");
188 void InsetInfo::Edit(BufferView *bv, int, int, unsigned int)
190 static int ow = -1, oh;
192 if(bv->buffer()->isReadonly())
193 WarnReadonly(bv->buffer()->fileName());
197 form = fl_bgn_form(FL_UP_BOX, 400, 180);
198 strobj = obj = fl_add_input(FL_MULTILINE_INPUT, 10, 10, 380, 120, "");
199 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
200 fl_set_object_resize(obj, FL_RESIZE_ALL);
201 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
202 obj = fl_add_button(FL_NORMAL_BUTTON, 130, 140, 120, 30, idex(_("Close|#C^[")));
203 fl_set_object_resize(obj, FL_RESIZE_NONE);
204 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
205 fl_set_object_callback(obj, C_InsetInfo_CloseInfoCB, 0);
207 fl_set_object_shortcut(obj, scex(_("Close|#C^[")), 1);
209 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
211 fl_set_input(strobj, contents.c_str());
215 fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
221 fl_set_form_minsize(form, ow, oh);
226 Inset * InsetInfo::Clone() const
228 return new InsetInfo(contents);
232 Inset::Code InsetInfo::LyxCode() const
234 return Inset::IGNORE_CODE;