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"
24 #include "lyx_gui_misc.h" // CancelCloseBoxCB
26 #include "support/lstrings.h"
29 /* Info, used for the Info boxes */
31 extern BufferView * current_view;
34 InsetInfo::InsetInfo()
40 InsetInfo::InsetInfo(string const & string)
47 InsetInfo::~InsetInfo()
58 int InsetInfo::ascent(Painter &, LyXFont const & font) const
60 return font.maxAscent() + 1;
63 int InsetInfo::Ascent(LyXFont const & font) const
65 return font.maxAscent() + 1;
71 int InsetInfo::descent(Painter &, LyXFont const & font) const
73 return font.maxDescent() + 1;
76 int InsetInfo::Descent(LyXFont const & font) const
78 return font.maxDescent() + 1;
84 int InsetInfo::width(Painter &, LyXFont const & font) const
86 return 6 + font.textWidth(_("Note"), strlen(_("Note")));
89 int InsetInfo::Width(LyXFont const & font) const
91 return 6 + font.textWidth(_("Note"), strlen(_("Note")));
97 void InsetInfo::draw(Painter & pain, LyXFont const & f,
98 int baseline, float & x) const
102 /* Info-insets are never LaTeX, so just correct the font */
103 font.setLatex(LyXFont::OFF);
105 // Draw as "Note" in a yellow box
107 pain.fillRectangle(int(x), baseline - ascent(pain, font) + 1,
108 width(pain, font) - 2,
109 ascent(pain, font) + descent(pain, font) - 2);
110 pain.rectangle(int(x), baseline - ascent(pain, font) + 1,
111 width(pain, font) - 2,
112 ascent(pain, font) + descent(pain, font) - 2);
114 pain.text(int(x + 2), baseline, _("Note"), font);
115 x += width(pain, font) - 1;
118 void InsetInfo::Draw(LyXFont font, LyXScreen & scr,
119 int baseline, float & x)
121 /* Info-insets are never LaTeX, so just correct the font */
122 font.setLatex(LyXFont::OFF);
124 // Draw as "Note" in a yellow box
126 scr.fillRectangle(gc_note,
127 int(x), baseline - Ascent(font)+1,
128 Width(font)-2, Ascent(font)+Descent(font)-2);
129 scr.drawRectangle(gc_note_frame,
130 int(x), baseline- Ascent(font)+1,
131 Width(font)-2, Ascent(font)+Descent(font)-2);
133 scr.drawString(font, _("Note"), baseline, int(x+2));
134 x += Width(font) - 1;
139 void InsetInfo::Write(ostream & os)
141 os << "Info " << contents;
145 void InsetInfo::Read(LyXLex & lex)
147 string tmp = lex.GetString(); // should be "Info"
149 lyxerr << "ERROR (InsetInfo::Read): "
150 "consistency check 1 failed." << endl;
154 // blank line in the file being read
155 // should we skip blank lines?
158 string const token = strip(lex.GetString());
159 lyxerr[Debug::PARSER] << "Note: " << token << endl;
161 if (token != "\\end_inset") {
162 contents += token + '\n';
164 else // token == "\\end_inset"
167 // now remove the last '\n's
168 contents = strip(contents, '\n');
172 int InsetInfo::Latex(ostream &, signed char /*fragile*/)
178 int InsetInfo::Latex(string &, signed char /*fragile*/)
184 int InsetInfo::Linuxdoc(string &)
190 int InsetInfo::DocBook(string &)
196 unsigned char InsetInfo::Editable() const
202 void InsetInfo::CloseInfoCB(FL_OBJECT * ob, long)
204 InsetInfo * inset = static_cast<InsetInfo*>(ob->u_vdata);
205 string tmp = fl_get_input(inset->strobj);
206 Buffer * buffer = current_view->buffer();
207 if(tmp != inset->contents && !(buffer->isReadonly()) ) {
209 inset->contents = tmp;
212 fl_hide_form(inset->form);
213 fl_free_form(inset->form);
219 // This is just a wrapper.
220 extern "C" void C_InsetInfo_CloseInfoCB(FL_OBJECT * ob, long data)
222 InsetInfo::CloseInfoCB(ob, data);
226 void InsetInfo::Edit(int, int)
228 static int ow = -1, oh;
230 if(current_view->buffer()->isReadonly())
231 WarnReadonly(current_view->buffer()->fileName());
235 form = fl_bgn_form(FL_UP_BOX, 400, 180);
236 strobj = obj = fl_add_input(FL_MULTILINE_INPUT, 10, 10, 380, 120, "");
237 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
238 fl_set_object_resize(obj, FL_RESIZE_ALL);
239 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
240 obj = fl_add_button(FL_NORMAL_BUTTON, 130, 140, 120, 30, idex(_("Close|#C^[")));
241 fl_set_object_resize(obj, FL_RESIZE_NONE);
242 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
243 fl_set_object_callback(obj, C_InsetInfo_CloseInfoCB, 0);
245 fl_set_object_shortcut(obj, scex(_("Close|#C^[")), 1);
247 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
249 fl_set_input(strobj, contents.c_str());
253 fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
259 fl_set_form_minsize(form, ow, oh);
264 Inset * InsetInfo::Clone() const
266 return new InsetInfo(contents);
270 Inset::Code InsetInfo::LyxCode() const
272 return Inset::IGNORE_CODE;