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"
31 /* Info, used for the Info boxes */
33 extern BufferView * current_view;
36 InsetInfo::InsetInfo()
42 InsetInfo::InsetInfo(string const & string)
49 InsetInfo::~InsetInfo()
60 int InsetInfo::ascent(Painter &, LyXFont const & font) const
62 return font.maxAscent() + 1;
65 int InsetInfo::Ascent(LyXFont const & font) const
67 return font.maxAscent() + 1;
73 int InsetInfo::descent(Painter &, LyXFont const & font) const
75 return font.maxDescent() + 1;
78 int InsetInfo::Descent(LyXFont const & font) const
80 return font.maxDescent() + 1;
86 int InsetInfo::width(Painter &, LyXFont const & font) const
88 return 6 + font.textWidth(_("Note"), strlen(_("Note")));
91 int InsetInfo::Width(LyXFont const & font) const
93 return 6 + font.textWidth(_("Note"), strlen(_("Note")));
99 void InsetInfo::draw(Painter & pain, LyXFont const & f,
100 int baseline, float & x) const
104 /* Info-insets are never LaTeX, so just correct the font */
105 font.setLatex(LyXFont::OFF);
107 // Draw as "Note" in a yellow box
109 pain.fillRectangle(int(x), baseline - ascent(pain, font) + 1,
110 width(pain, font) - 2,
111 ascent(pain, font) + descent(pain, font) - 2);
112 pain.rectangle(int(x), baseline - ascent(pain, font) + 1,
113 width(pain, font) - 2,
114 ascent(pain, font) + descent(pain, font) - 2);
116 pain.text(int(x + 2), baseline, _("Note"), font);
117 x += width(pain, font) - 1;
120 void InsetInfo::Draw(LyXFont font, LyXScreen & scr,
121 int baseline, float & x)
123 /* Info-insets are never LaTeX, so just correct the font */
124 font.setLatex(LyXFont::OFF);
126 // Draw as "Note" in a yellow box
128 scr.fillRectangle(gc_note,
129 int(x), baseline - Ascent(font)+1,
130 Width(font)-2, Ascent(font)+Descent(font)-2);
131 scr.drawRectangle(gc_note_frame,
132 int(x), baseline- Ascent(font)+1,
133 Width(font)-2, Ascent(font)+Descent(font)-2);
135 scr.drawString(font, _("Note"), baseline, int(x+2));
136 x += Width(font) - 1;
141 void InsetInfo::Write(ostream & os)
143 os << "Info " << contents;
147 void InsetInfo::Read(LyXLex & lex)
149 string tmp = lex.GetString(); // should be "Info"
151 lyxerr << "ERROR (InsetInfo::Read): "
152 "consistency check 1 failed." << endl;
156 // blank line in the file being read
157 // should we skip blank lines?
160 string const token = strip(lex.GetString());
161 lyxerr[Debug::PARSER] << "Note: " << token << endl;
163 if (token != "\\end_inset") {
164 contents += token + '\n';
166 else // token == "\\end_inset"
169 // now remove the last '\n's
170 contents = strip(contents, '\n');
174 int InsetInfo::Latex(ostream &, signed char /*fragile*/)
180 int InsetInfo::Latex(string &, signed char /*fragile*/)
186 int InsetInfo::Linuxdoc(string &)
192 int InsetInfo::DocBook(string &)
198 unsigned char InsetInfo::Editable() const
204 void InsetInfo::CloseInfoCB(FL_OBJECT * ob, long)
206 InsetInfo * inset = static_cast<InsetInfo*>(ob->u_vdata);
207 string tmp = fl_get_input(inset->strobj);
208 Buffer * buffer = current_view->buffer();
209 if(tmp != inset->contents && !(buffer->isReadonly()) ) {
211 inset->contents = tmp;
214 fl_hide_form(inset->form);
215 fl_free_form(inset->form);
221 // This is just a wrapper.
222 extern "C" void C_InsetInfo_CloseInfoCB(FL_OBJECT * ob, long data)
224 InsetInfo::CloseInfoCB(ob, data);
228 void InsetInfo::Edit(int, int)
230 static int ow = -1, oh;
232 if(current_view->buffer()->isReadonly())
233 WarnReadonly(current_view->buffer()->fileName());
237 form = fl_bgn_form(FL_UP_BOX, 400, 180);
238 strobj = obj = fl_add_input(FL_MULTILINE_INPUT, 10, 10, 380, 120, "");
239 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
240 fl_set_object_resize(obj, FL_RESIZE_ALL);
241 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
242 obj = fl_add_button(FL_NORMAL_BUTTON, 130, 140, 120, 30, idex(_("Close|#C^[")));
243 fl_set_object_resize(obj, FL_RESIZE_NONE);
244 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
245 fl_set_object_callback(obj, C_InsetInfo_CloseInfoCB, 0);
247 fl_set_object_shortcut(obj, scex(_("Close|#C^[")), 1);
249 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
251 fl_set_input(strobj, contents.c_str());
255 fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
261 fl_set_form_minsize(form, ow, oh);
266 Inset * InsetInfo::Clone() const
268 return new InsetInfo(contents);
272 Inset::Code InsetInfo::LyxCode() const
274 return Inset::IGNORE_CODE;