Finally get round to replacing InsetInfo with the new collabsable InsetNote.

Functionality should be identical.

Yes, I know that it'd be nice to have a yellow button with black text, like
a PostIt note. Ma�ana!


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2290 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2001-07-20 09:57:23 +00:00
parent 76a135cf07
commit b60c06df7e
12 changed files with 140 additions and 352 deletions

View File

@ -13,6 +13,7 @@ src/ext_l10n.h
src/figureForm.C
src/figure_form.C
src/FontLoader.C
src/frontends/controllers/biblio.C
src/frontends/controllers/ButtonController.h
src/frontends/controllers/character.C
src/frontends/controllers/ControlAboutlyx.C
@ -170,11 +171,11 @@ src/insets/insetfoot.C
src/insets/insetgraphics.C
src/insets/insetinclude.C
src/insets/insetindex.C
src/insets/insetinfo.C
src/insets/insetlabel.C
src/insets/insetlist.C
src/insets/insetmarginal.C
src/insets/insetminipage.C
src/insets/insetnote.C
src/insets/insetparent.C
src/insets/insetref.C
src/insets/insettabular.C

View File

@ -41,7 +41,7 @@
#include "insets/insetref.h"
#include "insets/insetparent.h"
#include "insets/insetindex.h"
#include "insets/insetinfo.h"
#include "insets/insetnote.h"
#include "insets/insetinclude.h"
#include "insets/insetcite.h"
#include "insets/insetert.h"
@ -3279,9 +3279,9 @@ void BufferView::Pimpl::specialChar(InsetSpecialChar::Kind kind)
void BufferView::Pimpl::insertNote()
{
InsetInfo * new_inset = new InsetInfo();
insertInset(new_inset);
new_inset->edit(bv_, 0, 0, 0);
Inset * inset = new InsetNote;
insertInset(inset);
inset->edit(bv_, 0, 0, 0);
}

View File

@ -1,3 +1,12 @@
2001-07-20 Angus Leeming <a.leeming@ic.ac.uk>
* src/LColor.[Ch]: remove noteframe. Change note to "yellow".
* src/BufferView_pimpl.C (insertNote): use InsetNote in place of
InsetInfo.
* src/buffer.C (readInset): ditto.
2001-07-19 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* BufferView_pimpl.C (specialChar): new method. Obsoletes

View File

@ -62,9 +62,8 @@ LColor::LColor()
{ foreground, N_("text"), "foreground", "black", "foreground" },
{ selection, N_("selection"), "selection", "LightBlue", "selection" },
{ latex, N_("latex text"), "latex", "DarkRed", "latex" },
{ note, N_("note"), "note", "black", "note" },
{ note, N_("note"), "note", "yellow", "note" },
{ notebg, N_("note background"), "notebg", "yellow", "notebg" },
{ noteframe, N_("note frame"), "noteframe", "black", "noteframe" },
{ depthbar, N_("depth bar"), "depthbar", "IndianRed", "depthbar" },
{ language, N_("language"), "language", "Blue", "language" },
{ command, N_("command inset"), "command", "black", "command" },

View File

@ -83,8 +83,6 @@ public:
note,
/// Background color of notes
notebg,
/// Frame color for notes
noteframe,
/// Color for the depth bars in the margin

View File

@ -55,7 +55,7 @@
#include "insets/insetlabel.h"
#include "insets/insetref.h"
#include "insets/inseturl.h"
#include "insets/insetinfo.h"
#include "insets/insetnote.h"
#include "insets/insetquotes.h"
#include "insets/insetlatexaccent.h"
#include "insets/insetbib.h"
@ -1389,7 +1389,7 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& par,
} else if (tmptok == "Figure") {
inset = new InsetFig(100, 100, *this);
} else if (tmptok == "Info") {
inset = new InsetInfo;
inset = new InsetNote;
} else if (tmptok == "Include") {
InsetCommandParams p( "Include" );
inset = new InsetInclude(p, *this);

View File

@ -1,3 +1,11 @@
2001-07-20 Angus Leeming <a.leeming@ic.ac.uk>
* insetinfo.[Ch]: removed.
* insetnote.[Ch]: new files. InsetNote replaces InsetInfo. The inset is
now collapsable, but functionality is otherwise identical to InsetInfo.
* Makefile.am: removed insetinfo.[Ch]. Added insetnote.[Ch].
2001-07-19 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* insetspecialchar.[Ch]: add support for HYPHENATION_BREAK. some

View File

@ -48,8 +48,6 @@ libinsets_la_SOURCES = \
insetinclude.h \
insetindex.C \
insetindex.h \
insetinfo.C \
insetinfo.h \
insetlabel.C \
insetlabel.h \
insetlatexaccent.C \
@ -60,6 +58,8 @@ libinsets_la_SOURCES = \
insetmarginal.C \
insetminipage.C \
insetminipage.h \
insetnote.C \
insetnote.h \
insetparent.C \
insetparent.h \
insetquotes.C \

View File

@ -1,255 +0,0 @@
/* This file is part of
* ======================================================
*
* LyX, The Document Processor
*
* Copyright 1995 Matthias Ettrich
* Copyright 1995-2001 The LyX Team.
*
* ====================================================== */
#include <config.h>
#include <cctype>
#ifdef __GNUG__
#pragma implementation
#endif
#include "insetinfo.h"
#include "paragraph.h"
#include "debug.h"
#include "gettext.h"
#include "lyx_gui_misc.h" // CancelCloseBoxCB
#include "buffer.h"
#include "support/lstrings.h"
#include "Painter.h"
#include "font.h"
#include "BufferView.h"
using std::ostream;
using std::endl;
/* Info, used for the Info boxes */
extern BufferView * current_view;
InsetInfo::InsetInfo()
: form(0), labelfont(LyXFont::ALL_SANE)
{
labelfont.decSize().decSize()
.setColor(LColor::note)
#ifndef NO_LATEX
.setLatex(LyXFont::OFF)
#endif
;
}
InsetInfo::InsetInfo(string const & str)
: contents(str), form(0), labelfont(LyXFont::ALL_SANE)
{
labelfont.decSize().decSize()
.setColor(LColor::note)
#ifndef NO_LATEX
.setLatex(LyXFont::OFF)
#endif
;
}
InsetInfo::~InsetInfo()
{
if (form) {
fl_hide_form(form);
fl_free_form(form);
form = 0;
}
}
int InsetInfo::ascent(BufferView *, LyXFont const &) const
{
return lyxfont::maxAscent(labelfont) + 1;
}
int InsetInfo::descent(BufferView *, LyXFont const &) const
{
return lyxfont::maxDescent(labelfont) + 1;
}
int InsetInfo::width(BufferView *, LyXFont const &) const
{
return 6 + lyxfont::width(_("Note"), labelfont);
}
void InsetInfo::draw(BufferView * bv, LyXFont const &,
int baseline, float & x, bool) const
{
Painter & pain = bv->painter();
// Draw as "Note" in a yellow box
x += 1;
pain.fillRectangle(int(x), baseline - ascent(bv, labelfont),
width(bv, labelfont) - 2,
ascent(bv, labelfont) + descent(bv, labelfont) - 2,
LColor::notebg);
pain.rectangle(int(x), baseline - ascent(bv, labelfont),
width(bv, labelfont) - 2,
ascent(bv, labelfont) + descent(bv, labelfont) - 2,
LColor::noteframe);
pain.text(int(x + 2), baseline, _("Note"), labelfont);
x += width(bv, labelfont) - 1;
}
void InsetInfo::write(Buffer const *, ostream & os) const
{
os << "Info\n" << contents;
}
void InsetInfo::read(Buffer const *, LyXLex & lex)
{
string tmp = lex.GetString(); // should be "Info"
if (tmp != "Info")
lyxerr << "ERROR (InsetInfo::Read): "
"consistency check 1 failed." << endl;
while (lex.IsOK()) {
if (!lex.EatLine())
// blank line in the file being read
// should we skip blank lines?
continue;
string const token = strip(lex.GetString());
lyxerr[Debug::PARSER] << "Note: " << token << endl;
if (token != "\\end_inset") {
contents += token + '\n';
}
else // token == "\\end_inset"
break;
}
// now remove the last '\n's
contents = strip(contents, '\n');
}
int InsetInfo::latex(Buffer const *, ostream &,
bool /*fragile*/, bool /*free_spc*/) const
{
return 0;
}
int InsetInfo::ascii(Buffer const *, ostream &, int) const
{
return 0;
}
int InsetInfo::linuxdoc(Buffer const *, ostream &) const
{
return 0;
}
int InsetInfo::docBook(Buffer const *, ostream &) const
{
return 0;
}
Inset::EDITABLE InsetInfo::editable() const
{
return IS_EDITABLE;
}
void InsetInfo::closeInfoCB(FL_OBJECT * ob, long)
{
InsetInfo * inset = static_cast<InsetInfo*>(ob->u_vdata);
string tmp = fl_get_input(inset->strobj);
Buffer * buffer = current_view->buffer();
if (tmp != inset->contents && !(buffer->isReadonly())) {
buffer->markDirty();
inset->contents = tmp;
}
if (inset->form) {
fl_hide_form(inset->form);
fl_free_form(inset->form);
inset->form = 0;
}
}
// This is just a wrapper.
extern "C"
void C_InsetInfo_CloseInfoCB(FL_OBJECT * ob, long data)
{
InsetInfo::closeInfoCB(ob, data);
}
string const InsetInfo::editMessage() const
{
return _("Opened note");
}
void InsetInfo::edit(BufferView *bv, int, int, unsigned int)
{
static int ow = -1;
static int oh;
if (bv->buffer()->isReadonly())
WarnReadonly(bv->buffer()->fileName());
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);
fl_set_object_gravity(obj, SouthEastGravity, SouthEastGravity);
fl_set_object_callback(obj, C_InsetInfo_CloseInfoCB, 0);
obj->u_vdata = this;
fl_set_object_shortcut(obj, scex(_("Close|#C^[")), 1);
fl_end_form();
fl_set_form_atclose(form, CancelCloseBoxCB, 0);
}
fl_set_input(strobj, contents.c_str());
if (form->visible) {
fl_raise_form(form);
} else {
fl_show_form(form,
FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
_("Note"));
if (ow < 0) {
ow = form->w;
oh = form->h;
}
fl_set_form_minsize(form, ow, oh);
}
}
Inset * InsetInfo::clone(Buffer const &, bool) const
{
return new InsetInfo(contents);
}
Inset::Code InsetInfo::lyxCode() const
{
return Inset::IGNORE_CODE;
}

View File

@ -1,84 +0,0 @@
// -*- C++ -*-
/* This file is part of*
* ======================================================
*
* LyX, The Document Processor
*
* Copyright 1995 Matthias Ettrich
* Copyright 1995-2001 the LyX Team.
*
* ====================================================== */
#ifndef INSET_INFO_H
#define INSET_INFO_H
#ifdef __GNUG__
#pragma interface
#endif
#include "inset.h"
#include FORMS_H_LOCATION
#include "LString.h"
#include "lyxfont.h"
/** Info. Handles the note insets.
This class handles the note insets. The edit operation bringes up
a dialog, where the user can type a note about life or something
else of interest. When collapsed, the inset is displayed as "Note"
in a yellow box. Currently, the Read-function is a terrible hack.
Some day in the distant future, this will hopefully be obsoleted by
a true comment-environment. */
class InsetInfo : public Inset {
public:
///
InsetInfo();
///
explicit
InsetInfo(string const & string);
///
~InsetInfo();
///
int ascent(BufferView *, LyXFont const &) const;
///
int descent(BufferView *, LyXFont const &) const;
///
int width(BufferView *, LyXFont const &) const;
///
void draw(BufferView *, LyXFont const &, int, float &, bool) const;
///
void write(Buffer const *, std::ostream &) const;
///
void read(Buffer const *, LyXLex & lex);
///
int latex(Buffer const *, std::ostream &,
bool fragile, bool free_spc) const;
///
int ascii(Buffer const *, std::ostream &, int linelen) const;
///
int linuxdoc(Buffer const *, std::ostream &) const;
///
int docBook(Buffer const *, std::ostream &) const;
/// what appears in the minibuffer when opening
string const editMessage() const;
///
void edit(BufferView *, int, int, unsigned int);
///
EDITABLE editable() const;
///
Inset::Code lyxCode() const;
///
virtual Inset * clone(Buffer const &, bool same_id = false) const;
///
static void closeInfoCB(FL_OBJECT *, long data);
private:
///
string contents;
///
FL_FORM * form;
///
FL_OBJECT * strobj;
///
LyXFont labelfont;
};
#endif

67
src/insets/insetnote.C Normal file
View File

@ -0,0 +1,67 @@
/* This file is part of
* ======================================================
*
* LyX, The Document Processor
*
* Copyright 1998 The LyX Team.
*
* ======================================================
*/
#include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "insetnote.h"
#include "gettext.h"
#include "lyxfont.h"
#include "BufferView.h"
#include "lyxtext.h"
#include "insets/insettext.h"
#include "support/LOstream.h"
#include "debug.h"
using std::ostream;
InsetNote::InsetNote()
: InsetCollapsable()
{
LyXFont font(LyXFont::ALL_SANE);
font.decSize();
font.decSize();
font.setColor(LColor::note);
setLabelFont(font);
setAutoCollapse(true);
setLabel(_("note"));
setInsetName("Note");
}
Inset * InsetNote::clone(Buffer const &, bool same_id) const
{
InsetNote * result = new InsetNote;
result->inset.init(&inset, same_id);
result->collapsed_ = collapsed_;
if (same_id)
result->id_ = id_;
return result;
}
string const InsetNote::editMessage() const
{
return _("Opened Note Inset");
}
void InsetNote::write(Buffer const *buf, ostream & os) const
{
//os << getInsetName() << "\n";
os << "Info\n";
InsetCollapsable::write(buf, os);
}

45
src/insets/insetnote.h Normal file
View File

@ -0,0 +1,45 @@
// -*- C++ -*-
/* This file is part of
* ======================================================
*
* LyX, The Document Processor
*
* Copyright 2001 The LyX Team.
*
*======================================================
*/
#ifndef INSETNOTE_H
#define INSETNOTE_H
#ifdef __GNUG__
#pragma interface
#endif
#include "insetcollapsable.h"
/** The PostIt note inset
*/
class InsetNote : public InsetCollapsable {
public:
///
InsetNote();
///
virtual Inset * clone(Buffer const &, bool) const;
///
virtual string const editMessage() const;
///
virtual Inset::Code lyxCode() const { return Inset::IGNORE_CODE; }
///
virtual bool insertInset(BufferView *, Inset *) { return false; }
///
virtual bool insetAllowed(Inset::Code) const { return false; }
///
virtual void write(Buffer const *, std::ostream &) const;
///
virtual int latex(Buffer const *, std::ostream &, bool, bool) const
{ return 0; }
};
#endif