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(BufferView *, LyXFont const & font) const
62 return lyxfont::maxAscent(font) + 1;
66 int InsetInfo::descent(BufferView *, LyXFont const & font) const
68 return lyxfont::maxDescent(font) + 1;
72 int InsetInfo::width(BufferView *, LyXFont const & font) const
74 return 6 + lyxfont::width(_("Note"), font);
78 void InsetInfo::draw(BufferView * bv, LyXFont const & f,
79 int baseline, float & x, bool) const
81 Painter & pain = bv->painter();
84 /* Info-insets are never LaTeX, so just correct the font */
85 font.setLatex(LyXFont::OFF).setColor(LColor::note);
87 // Draw as "Note" in a yellow box
89 pain.fillRectangle(int(x), baseline - ascent(bv, font) + 1,
91 ascent(bv, font) + descent(bv, font) - 2,
93 pain.rectangle(int(x), baseline - ascent(bv, font) + 1,
95 ascent(bv, font) + descent(bv, font) - 2,
98 pain.text(int(x + 2), baseline, _("Note"), font);
99 x += width(bv, font) - 1;
103 void InsetInfo::Write(Buffer const *, ostream & os) const
105 os << "Info " << contents;
109 void InsetInfo::Read(Buffer const *, LyXLex & lex)
111 string tmp = lex.GetString(); // should be "Info"
113 lyxerr << "ERROR (InsetInfo::Read): "
114 "consistency check 1 failed." << endl;
118 // blank line in the file being read
119 // should we skip blank lines?
122 string const token = strip(lex.GetString());
123 lyxerr[Debug::PARSER] << "Note: " << token << endl;
125 if (token != "\\end_inset") {
126 contents += token + '\n';
128 else // token == "\\end_inset"
131 // now remove the last '\n's
132 contents = strip(contents, '\n');
136 int InsetInfo::Latex(Buffer const *, ostream &,
137 bool /*fragile*/, bool /*free_spc*/) const
143 int InsetInfo::Ascii(Buffer const *, ostream &) const
149 int InsetInfo::Linuxdoc(Buffer const *, ostream &) const
155 int InsetInfo::DocBook(Buffer const *, ostream &) const
161 Inset::EDITABLE InsetInfo::Editable() const
167 void InsetInfo::CloseInfoCB(FL_OBJECT * ob, long)
169 InsetInfo * inset = static_cast<InsetInfo*>(ob->u_vdata);
170 string tmp = fl_get_input(inset->strobj);
171 Buffer * buffer = current_view->buffer();
172 if(tmp != inset->contents && !(buffer->isReadonly()) ) {
174 inset->contents = tmp;
177 fl_hide_form(inset->form);
178 fl_free_form(inset->form);
184 // This is just a wrapper.
185 extern "C" void C_InsetInfo_CloseInfoCB(FL_OBJECT * ob, long data)
187 InsetInfo::CloseInfoCB(ob, data);
191 char const * InsetInfo::EditMessage() const
193 return _("Opened note");
197 void InsetInfo::Edit(BufferView *bv, int, int, unsigned int)
199 static int ow = -1, oh;
201 if(bv->buffer()->isReadonly())
202 WarnReadonly(bv->buffer()->fileName());
206 form = fl_bgn_form(FL_UP_BOX, 400, 180);
207 strobj = obj = fl_add_input(FL_MULTILINE_INPUT, 10, 10, 380, 120, "");
208 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
209 fl_set_object_resize(obj, FL_RESIZE_ALL);
210 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
211 obj = fl_add_button(FL_NORMAL_BUTTON, 130, 140, 120, 30, idex(_("Close|#C^[")));
212 fl_set_object_resize(obj, FL_RESIZE_NONE);
213 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
214 fl_set_object_callback(obj, C_InsetInfo_CloseInfoCB, 0);
216 fl_set_object_shortcut(obj, scex(_("Close|#C^[")), 1);
218 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
220 fl_set_input(strobj, contents.c_str());
224 fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
230 fl_set_form_minsize(form, ow, oh);
235 Inset * InsetInfo::Clone() const
237 return new InsetInfo(contents);
241 Inset::Code InsetInfo::LyxCode() const
243 return Inset::IGNORE_CODE;