1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
1999-10-02 16:21:10 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
2000-03-16 04:29:22 +00:00
|
|
|
* Copyright 1995-2000 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
1999-11-15 10:58:38 +00:00
|
|
|
* ====================================================== */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
#include <cctype>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "insetinfo.h"
|
|
|
|
#include "lyxparagraph.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "gettext.h"
|
|
|
|
#include "lyx_gui_misc.h" // CancelCloseBoxCB
|
|
|
|
#include "buffer.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/lstrings.h"
|
2000-02-10 17:53:36 +00:00
|
|
|
#include "Painter.h"
|
2000-04-04 00:19:15 +00:00
|
|
|
#include "font.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::ostream;
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/* Info, used for the Info boxes */
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
extern BufferView * current_view;
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
InsetInfo::InsetInfo()
|
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
form = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
InsetInfo::InsetInfo(string const & string)
|
1999-09-27 18:44:28 +00:00
|
|
|
: contents(string)
|
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
form = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetInfo::~InsetInfo()
|
|
|
|
{
|
|
|
|
if (form){
|
|
|
|
fl_hide_form(form);
|
|
|
|
fl_free_form(form);
|
1999-10-02 16:21:10 +00:00
|
|
|
form = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
int InsetInfo::ascent(Painter &, LyXFont const & font) const
|
|
|
|
{
|
2000-04-04 00:19:15 +00:00
|
|
|
return lyxfont::maxAscent(font) + 1;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
int InsetInfo::descent(Painter &, LyXFont const & font) const
|
|
|
|
{
|
2000-04-04 00:19:15 +00:00
|
|
|
return lyxfont::maxDescent(font) + 1;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
int InsetInfo::width(Painter &, LyXFont const & font) const
|
|
|
|
{
|
2000-04-04 00:19:15 +00:00
|
|
|
return 6 + lyxfont::width(_("Note"), font);
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-06-21 15:07:57 +00:00
|
|
|
void InsetInfo::draw(BufferView * bv, LyXFont const & f,
|
2000-06-23 15:02:46 +00:00
|
|
|
int baseline, float & x, bool) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2000-06-21 15:07:57 +00:00
|
|
|
Painter & pain = bv->painter();
|
2000-02-10 17:53:36 +00:00
|
|
|
LyXFont font(f);
|
|
|
|
|
|
|
|
/* Info-insets are never LaTeX, so just correct the font */
|
2000-04-09 22:48:51 +00:00
|
|
|
font.setLatex(LyXFont::OFF).setColor(LColor::note);
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
// Draw as "Note" in a yellow box
|
|
|
|
x += 1;
|
|
|
|
pain.fillRectangle(int(x), baseline - ascent(pain, font) + 1,
|
|
|
|
width(pain, font) - 2,
|
2000-04-09 22:48:51 +00:00
|
|
|
ascent(pain, font) + descent(pain, font) - 2,
|
|
|
|
LColor::notebg);
|
2000-02-10 17:53:36 +00:00
|
|
|
pain.rectangle(int(x), baseline - ascent(pain, font) + 1,
|
|
|
|
width(pain, font) - 2,
|
2000-04-09 22:48:51 +00:00
|
|
|
ascent(pain, font) + descent(pain, font) - 2,
|
|
|
|
LColor::noteframe);
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
|
|
pain.text(int(x + 2), baseline, _("Note"), font);
|
|
|
|
x += width(pain, font) - 1;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
void InsetInfo::Write(Buffer const *, ostream & os) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
os << "Info " << contents;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
void InsetInfo::Read(Buffer const *, LyXLex & lex)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string tmp = lex.GetString(); // should be "Info"
|
1999-09-27 18:44:28 +00:00
|
|
|
if (tmp != "Info")
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "ERROR (InsetInfo::Read): "
|
|
|
|
"consistency check 1 failed." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
while (lex.IsOK()) {
|
|
|
|
if (!lex.EatLine())
|
|
|
|
// blank line in the file being read
|
|
|
|
// should we skip blank lines?
|
|
|
|
continue;
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string const token = strip(lex.GetString());
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::PARSER] << "Note: " << token << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (token != "\\end_inset") {
|
|
|
|
contents += token + '\n';
|
|
|
|
}
|
|
|
|
else // token == "\\end_inset"
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// now remove the last '\n's
|
1999-10-02 16:21:10 +00:00
|
|
|
contents = strip(contents, '\n');
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetInfo::Latex(Buffer const *, ostream &,
|
2000-04-19 01:42:55 +00:00
|
|
|
bool /*fragile*/, bool /*free_spc*/) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetInfo::Ascii(Buffer const *, ostream &) const
|
2000-04-24 20:58:23 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetInfo::Linuxdoc(Buffer const *, ostream &) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetInfo::DocBook(Buffer const *, ostream &) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-03-08 13:52:57 +00:00
|
|
|
Inset::EDITABLE InsetInfo::Editable() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-03-08 13:52:57 +00:00
|
|
|
return IS_EDITABLE;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
void InsetInfo::CloseInfoCB(FL_OBJECT * ob, long)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
InsetInfo * inset = static_cast<InsetInfo*>(ob->u_vdata);
|
1999-10-02 16:21:10 +00:00
|
|
|
string tmp = fl_get_input(inset->strobj);
|
1999-11-09 22:53:41 +00:00
|
|
|
Buffer * buffer = current_view->buffer();
|
1999-09-27 18:44:28 +00:00
|
|
|
if(tmp != inset->contents && !(buffer->isReadonly()) ) {
|
|
|
|
buffer->markDirty();
|
|
|
|
inset->contents = tmp;
|
|
|
|
}
|
|
|
|
if (inset->form) {
|
|
|
|
fl_hide_form(inset->form);
|
|
|
|
fl_free_form(inset->form);
|
1999-10-02 16:21:10 +00:00
|
|
|
inset->form = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
1999-10-19 15:06:30 +00:00
|
|
|
// This is just a wrapper.
|
1999-11-04 01:40:20 +00:00
|
|
|
extern "C" void C_InsetInfo_CloseInfoCB(FL_OBJECT * ob, long data)
|
1999-10-19 15:06:30 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
InsetInfo::CloseInfoCB(ob, data);
|
1999-10-19 15:06:30 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
char const * InsetInfo::EditMessage() const
|
|
|
|
{
|
|
|
|
return _("Opened note");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
void InsetInfo::Edit(BufferView *bv, int, int, unsigned int)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-25 14:50:26 +00:00
|
|
|
static int ow = -1, oh;
|
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
if(bv->buffer()->isReadonly())
|
|
|
|
WarnReadonly(bv->buffer()->fileName());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (!form) {
|
|
|
|
FL_OBJECT *obj;
|
1999-11-15 10:58:38 +00:00
|
|
|
form = fl_bgn_form(FL_UP_BOX, 400, 180);
|
|
|
|
strobj = obj = fl_add_input(FL_MULTILINE_INPUT, 10, 10, 380, 120, "");
|
|
|
|
fl_set_object_color(obj, FL_MCOL, FL_MCOL);
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_object_resize(obj, FL_RESIZE_ALL);
|
|
|
|
fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
|
1999-11-15 10:58:38 +00:00
|
|
|
obj = fl_add_button(FL_NORMAL_BUTTON, 130, 140, 120, 30, idex(_("Close|#C^[")));
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_object_resize(obj, FL_RESIZE_NONE);
|
1999-10-25 14:50:26 +00:00
|
|
|
fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
|
1999-11-04 01:40:20 +00:00
|
|
|
fl_set_object_callback(obj, C_InsetInfo_CloseInfoCB, 0);
|
|
|
|
obj->u_vdata = this;
|
|
|
|
fl_set_object_shortcut(obj, scex(_("Close|#C^[")), 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_end_form();
|
1999-10-02 16:21:10 +00:00
|
|
|
fl_set_form_atclose(form, CancelCloseBoxCB, 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
fl_set_input(strobj, contents.c_str());
|
|
|
|
if (form->visible) {
|
|
|
|
fl_raise_form(form);
|
|
|
|
} else {
|
1999-11-15 10:58:38 +00:00
|
|
|
fl_show_form(form, FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
|
1999-09-27 18:44:28 +00:00
|
|
|
_("Note"));
|
1999-10-25 14:50:26 +00:00
|
|
|
if (ow < 0) {
|
|
|
|
ow = form->w;
|
|
|
|
oh = form->h;
|
|
|
|
}
|
|
|
|
fl_set_form_minsize(form, ow, oh);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
Inset * InsetInfo::Clone() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-22 16:19:48 +00:00
|
|
|
return new InsetInfo(contents);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Inset::Code InsetInfo::LyxCode() const
|
|
|
|
{
|
|
|
|
return Inset::IGNORE_CODE;
|
|
|
|
}
|