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
|
|
|
|
* Copyright 1995-1999 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
1999-10-02 16:21:10 +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 "lyxdraw.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "lyx_gui_misc.h" // CancelCloseBoxCB
|
|
|
|
#include "buffer.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/lstrings.h"
|
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-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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
int InsetInfo::Ascent(LyXFont const & font) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
return font.maxAscent() + 1;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
int InsetInfo::Descent(LyXFont const & font) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
return font.maxDescent() + 1;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
int InsetInfo::Width(LyXFont const & font) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return 6 + font.textWidth(_("Note"), strlen(_("Note")));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
void InsetInfo::Draw(LyXFont font, LyXScreen & scr,
|
|
|
|
int baseline, float & x)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
/* Info-insets are never LaTeX, so just correct the font */
|
|
|
|
font.setLatex(LyXFont::OFF);
|
|
|
|
|
|
|
|
// Draw as "Note" in a yellow box
|
|
|
|
x += 1;
|
|
|
|
scr.fillRectangle(gc_note,
|
|
|
|
int(x), baseline - Ascent(font)+1,
|
|
|
|
Width(font)-2, Ascent(font)+Descent(font)-2);
|
|
|
|
scr.drawRectangle(gc_note_frame,
|
|
|
|
int(x), baseline- Ascent(font)+1,
|
|
|
|
Width(font)-2, Ascent(font)+Descent(font)-2);
|
|
|
|
|
|
|
|
scr.drawString(font, _("Note"), baseline, int(x+2));
|
|
|
|
x += Width(font) - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
void InsetInfo::Write(FILE * file)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
fprintf(file, "Info %s", contents.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
void InsetInfo::Read(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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetInfo::Latex(FILE *, signed char /*fragile*/)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
int InsetInfo::Latex(string &, signed char /*fragile*/)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
int InsetInfo::Linuxdoc(string &)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
int InsetInfo::DocBook(string &)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned char InsetInfo::Editable() const
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-04 01:40:20 +00:00
|
|
|
Buffer * buffer = current_view->currentBuffer();
|
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
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void InsetInfo::Edit(int, int)
|
|
|
|
{
|
1999-10-25 14:50:26 +00:00
|
|
|
static int ow = -1, oh;
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
if(current_view->currentBuffer()->isReadonly())
|
|
|
|
WarnReadonly();
|
|
|
|
|
|
|
|
if (!form) {
|
|
|
|
FL_OBJECT *obj;
|
|
|
|
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);
|
|
|
|
fl_set_object_resize(obj, FL_RESIZE_ALL);
|
|
|
|
fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity);
|
|
|
|
obj = fl_add_button(FL_NORMAL_BUTTON,130,140,120,30,idex(_("Close|#C^[")));
|
|
|
|
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-10-25 14:50:26 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Inset* InsetInfo::Clone()
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
InsetInfo * result = new InsetInfo(contents);
|
1999-09-27 18:44:28 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Inset::Code InsetInfo::LyxCode() const
|
|
|
|
{
|
|
|
|
return Inset::IGNORE_CODE;
|
|
|
|
}
|