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).setColor(LColor::note);
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,
92 pain.rectangle(int(x), baseline - ascent(pain, font) + 1,
93 width(pain, font) - 2,
94 ascent(pain, font) + descent(pain, font) - 2,
97 pain.text(int(x + 2), baseline, _("Note"), font);
98 x += width(pain, font) - 1;
102 void InsetInfo::Write(ostream & os) const
104 os << "Info " << contents;
108 void InsetInfo::Read(LyXLex & lex)
110 string tmp = lex.GetString(); // should be "Info"
112 lyxerr << "ERROR (InsetInfo::Read): "
113 "consistency check 1 failed." << endl;
117 // blank line in the file being read
118 // should we skip blank lines?
121 string const token = strip(lex.GetString());
122 lyxerr[Debug::PARSER] << "Note: " << token << endl;
124 if (token != "\\end_inset") {
125 contents += token + '\n';
127 else // token == "\\end_inset"
130 // now remove the last '\n's
131 contents = strip(contents, '\n');
135 int InsetInfo::Latex(ostream &,
136 bool /*fragile*/, bool /*free_spc*/) const
142 int InsetInfo::Ascii(ostream &) const
148 int InsetInfo::Linuxdoc(ostream &) const
154 int InsetInfo::DocBook(ostream &) const
160 Inset::EDITABLE InsetInfo::Editable() const
166 void InsetInfo::CloseInfoCB(FL_OBJECT * ob, long)
168 InsetInfo * inset = static_cast<InsetInfo*>(ob->u_vdata);
169 string tmp = fl_get_input(inset->strobj);
170 Buffer * buffer = current_view->buffer();
171 if(tmp != inset->contents && !(buffer->isReadonly()) ) {
173 inset->contents = tmp;
176 fl_hide_form(inset->form);
177 fl_free_form(inset->form);
183 // This is just a wrapper.
184 extern "C" void C_InsetInfo_CloseInfoCB(FL_OBJECT * ob, long data)
186 InsetInfo::CloseInfoCB(ob, data);
190 char const * InsetInfo::EditMessage() const
192 return _("Opened note");
196 void InsetInfo::Edit(BufferView *bv, int, int, unsigned int)
198 static int ow = -1, oh;
200 if(bv->buffer()->isReadonly())
201 WarnReadonly(bv->buffer()->fileName());
205 form = fl_bgn_form(FL_UP_BOX, 400, 180);
206 strobj = obj = fl_add_input(FL_MULTILINE_INPUT, 10, 10, 380, 120, "");
207 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
208 fl_set_object_resize(obj, FL_RESIZE_ALL);
209 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
210 obj = fl_add_button(FL_NORMAL_BUTTON, 130, 140, 120, 30, idex(_("Close|#C^[")));
211 fl_set_object_resize(obj, FL_RESIZE_NONE);
212 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
213 fl_set_object_callback(obj, C_InsetInfo_CloseInfoCB, 0);
215 fl_set_object_shortcut(obj, scex(_("Close|#C^[")), 1);
217 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
219 fl_set_input(strobj, contents.c_str());
223 fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
229 fl_set_form_minsize(form, ow, oh);
234 Inset * InsetInfo::Clone() const
236 return new InsetInfo(contents);
240 Inset::Code InsetInfo::LyxCode() const
242 return Inset::IGNORE_CODE;