1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright (C) 1995 Matthias Ettrich
7 * Copyright (C) 1995-1998 The LyX Team.
9 *======================================================*/
15 #pragma implementation
18 #include "insetinfo.h"
19 #include "lyxparagraph.h"
23 #include "lyx_gui_misc.h" // CancelCloseBoxCB
26 // $Id: insetinfo.C,v 1.1 1999/09/27 18:44:39 larsbj Exp $
28 #if !defined(lint) && !defined(WITH_WARNINGS)
29 static char vcid[] = "$Id: insetinfo.C,v 1.1 1999/09/27 18:44:39 larsbj Exp $";
32 extern BufferView *current_view;
34 /* Info, used for the Info boxes */
36 InsetInfo::InsetInfo()
42 InsetInfo::InsetInfo(LString const & string)
49 InsetInfo::~InsetInfo()
59 int InsetInfo::Ascent(LyXFont const &font) const
61 return font.maxAscent()+1;
65 int InsetInfo::Descent(LyXFont const &font) const
67 return font.maxDescent()+1;
71 int InsetInfo::Width(LyXFont const &font) const
73 return 6 + font.textWidth(_("Note"), strlen(_("Note")));
77 void InsetInfo::Draw(LyXFont font, LyXScreen &scr,
78 int baseline, float &x)
80 /* Info-insets are never LaTeX, so just correct the font */
81 font.setLatex(LyXFont::OFF);
83 // Draw as "Note" in a yellow box
85 scr.fillRectangle(gc_note,
86 int(x), baseline - Ascent(font)+1,
87 Width(font)-2, Ascent(font)+Descent(font)-2);
88 scr.drawRectangle(gc_note_frame,
89 int(x), baseline- Ascent(font)+1,
90 Width(font)-2, Ascent(font)+Descent(font)-2);
92 scr.drawString(font, _("Note"), baseline, int(x+2));
97 void InsetInfo::Write(FILE *file)
99 fprintf(file, "Info %s", contents.c_str());
103 void InsetInfo::Read(LyXLex &lex)
105 LString tmp = lex.GetString(); // should be "Info"
107 lyxerr.print("ERROR (InsetInfo::Read): "
108 "consistency check 1 failed.");
112 // blank line in the file being read
113 // should we skip blank lines?
116 LString const token = lex.GetString().strip();
117 lyxerr.debug("Note: " + token, Error::LEX_PARSER);
119 if (token != "\\end_inset") {
120 contents += token + '\n';
122 else // token == "\\end_inset"
125 // now remove the last '\n's
126 contents.strip('\n');
130 int InsetInfo::Latex(FILE *, signed char /*fragile*/)
136 int InsetInfo::Latex(LString &, signed char /*fragile*/)
142 int InsetInfo::Linuxdoc(LString &)
148 int InsetInfo::DocBook(LString &)
154 unsigned char InsetInfo::Editable() const
160 void InsetInfo::CloseInfoCB(FL_OBJECT *, long data)
162 InsetInfo *inset = (InsetInfo*) data;
163 // inset->contents = fl_get_input(inset->strobj);
164 LString tmp = fl_get_input(inset->strobj);
165 Buffer *buffer = current_view->currentBuffer();
166 if(tmp != inset->contents && !(buffer->isReadonly()) ) {
168 inset->contents = tmp;
171 fl_hide_form(inset->form);
172 fl_free_form(inset->form);
178 void InsetInfo::Edit(int, int)
180 if(current_view->currentBuffer()->isReadonly())
185 form = fl_bgn_form(FL_UP_BOX,400,180);
186 strobj = obj = fl_add_input(FL_MULTILINE_INPUT,10,10,380,120,"");
187 fl_set_object_color(obj,FL_MCOL,FL_MCOL);
188 fl_set_object_resize(obj, FL_RESIZE_ALL);
189 fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
190 obj = fl_add_button(FL_NORMAL_BUTTON,130,140,120,30,idex(_("Close|#C^[")));
191 fl_set_object_resize(obj, FL_RESIZE_NONE);
192 fl_set_object_gravity(obj, SouthWestGravity, SouthEastGravity);
193 fl_set_object_callback(obj, CloseInfoCB, (long)this);
194 fl_set_object_shortcut(obj, scex(_("Close|#C^[")), (long)this);
196 fl_set_form_atclose(form, CancelCloseBoxCB, NULL);
198 fl_set_input(strobj, contents.c_str());
202 fl_show_form(form,FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
208 Inset* InsetInfo::Clone()
210 InsetInfo *result = new InsetInfo(contents);
215 Inset::Code InsetInfo::LyxCode() const
217 return Inset::IGNORE_CODE;