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"
28 /* Info, used for the Info boxes */
30 extern BufferView * current_view;
32 InsetInfo::InsetInfo()
38 InsetInfo::InsetInfo(string const & string)
45 InsetInfo::~InsetInfo()
55 int InsetInfo::Ascent(LyXFont const & font) const
57 return font.maxAscent() + 1;
61 int InsetInfo::Descent(LyXFont const & font) const
63 return font.maxDescent() + 1;
67 int InsetInfo::Width(LyXFont const & font) const
69 return 6 + font.textWidth(_("Note"), strlen(_("Note")));
73 void InsetInfo::Draw(LyXFont font, LyXScreen & scr,
74 int baseline, float & x)
76 /* Info-insets are never LaTeX, so just correct the font */
77 font.setLatex(LyXFont::OFF);
79 // Draw as "Note" in a yellow box
81 scr.fillRectangle(gc_note,
82 int(x), baseline - Ascent(font)+1,
83 Width(font)-2, Ascent(font)+Descent(font)-2);
84 scr.drawRectangle(gc_note_frame,
85 int(x), baseline- Ascent(font)+1,
86 Width(font)-2, Ascent(font)+Descent(font)-2);
88 scr.drawString(font, _("Note"), baseline, int(x+2));
93 void InsetInfo::Write(FILE * file)
95 fprintf(file, "Info %s", contents.c_str());
99 void InsetInfo::Read(LyXLex & lex)
101 string tmp = lex.GetString(); // should be "Info"
103 lyxerr << "ERROR (InsetInfo::Read): "
104 "consistency check 1 failed." << endl;
108 // blank line in the file being read
109 // should we skip blank lines?
112 string const token = strip(lex.GetString());
113 lyxerr[Debug::PARSER] << "Note: " << token << endl;
115 if (token != "\\end_inset") {
116 contents += token + '\n';
118 else // token == "\\end_inset"
121 // now remove the last '\n's
122 contents = strip(contents, '\n');
126 int InsetInfo::Latex(FILE *, signed char /*fragile*/)
132 int InsetInfo::Latex(string &, signed char /*fragile*/)
138 int InsetInfo::Linuxdoc(string &)
144 int InsetInfo::DocBook(string &)
150 unsigned char InsetInfo::Editable() const
156 void InsetInfo::CloseInfoCB(FL_OBJECT * ob, long)
158 InsetInfo * inset = static_cast<InsetInfo*>(ob->u_vdata);
159 string tmp = fl_get_input(inset->strobj);
160 Buffer * buffer = current_view->buffer();
161 if(tmp != inset->contents && !(buffer->isReadonly()) ) {
163 inset->contents = tmp;
166 fl_hide_form(inset->form);
167 fl_free_form(inset->form);
173 // This is just a wrapper.
174 extern "C" void C_InsetInfo_CloseInfoCB(FL_OBJECT * ob, long data)
176 InsetInfo::CloseInfoCB(ob, data);
180 void InsetInfo::Edit(int, int)
182 static int ow = -1, oh;
184 if(current_view->buffer()->isReadonly())
189 form = fl_bgn_form(FL_UP_BOX, 400, 180);
190 strobj = obj = fl_add_input(FL_MULTILINE_INPUT, 10, 10, 380, 120, "");
191 fl_set_object_color(obj, FL_MCOL, FL_MCOL);
192 fl_set_object_resize(obj, FL_RESIZE_ALL);
193 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
194 obj = fl_add_button(FL_NORMAL_BUTTON, 130, 140, 120, 30, idex(_("Close|#C^[")));
195 fl_set_object_resize(obj, FL_RESIZE_NONE);
196 fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
197 fl_set_object_callback(obj, C_InsetInfo_CloseInfoCB, 0);
199 fl_set_object_shortcut(obj, scex(_("Close|#C^[")), 1);
201 fl_set_form_atclose(form, CancelCloseBoxCB, 0);
203 fl_set_input(strobj, contents.c_str());
207 fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
213 fl_set_form_minsize(form, ow, oh);
218 Inset * InsetInfo::Clone() const
220 return new InsetInfo(contents);
224 Inset::Code InsetInfo::LyxCode() const
226 return Inset::IGNORE_CODE;