1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 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*/) const
135 int InsetInfo::Latex(string &, signed char /*fragile*/) const
141 int InsetInfo::Linuxdoc(string &) const
147 int InsetInfo::DocBook(string &) const
153 unsigned char InsetInfo::Editable() const
159 void InsetInfo::CloseInfoCB(FL_OBJECT * ob, long)
161 InsetInfo * inset = static_cast<InsetInfo*>(ob->u_vdata);
162 string tmp = fl_get_input(inset->strobj);
163 Buffer * buffer = current_view->buffer();
164 if(tmp != inset->contents && !(buffer->isReadonly()) ) {
166 inset->contents = tmp;
169 fl_hide_form(inset->form);
170 fl_free_form(inset->form);
176 // This is just a wrapper.
177 extern "C" void C_InsetInfo_CloseInfoCB(FL_OBJECT * ob, long data)
179 InsetInfo::CloseInfoCB(ob, data);
183 void InsetInfo::Edit(BufferView *bv, int, int, unsigned int)
185 static int ow = -1, oh;
187 if(bv->buffer()->isReadonly())
188 WarnReadonly(bv->buffer()->fileName());
192 form = fl_bgn_form(FL_UP_BOX, 400, 180);
193 strobj = obj = fl_add_input(FL_MULTILINE_INPUT, 10, 10, 380, 120, "");
194 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
195 fl_set_object_resize(obj, FL_RESIZE_ALL);
196 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
197 obj = fl_add_button(FL_NORMAL_BUTTON, 130, 140, 120, 30, idex(_("Close|#C^[")));
198 fl_set_object_resize(obj, FL_RESIZE_NONE);
199 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
200 fl_set_object_callback(obj, C_InsetInfo_CloseInfoCB, 0);
202 fl_set_object_shortcut(obj, scex(_("Close|#C^[")), 1);
204 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
206 fl_set_input(strobj, contents.c_str());
210 fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
216 fl_set_form_minsize(form, ow, oh);
221 Inset * InsetInfo::Clone() const
223 return new InsetInfo(contents);
227 Inset::Code InsetInfo::LyxCode() const
229 return Inset::IGNORE_CODE;