First shot at inset-unification mathed & rest of the world

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4467 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-06-24 15:51:35 +00:00
parent 3786644124
commit 4d59d00ad4
12 changed files with 309 additions and 281 deletions

View File

@ -140,4 +140,10 @@ libmathed_la_SOURCES = \
math_xyarrowinset.C \
math_xyarrowinset.h \
math_xymatrixinset.C \
math_xymatrixinset.h
math_xymatrixinset.h \
button_inset.C \
button_inset.h \
command_inset.h \
command_inset.C \
ref_inset.h \
ref_inset.C

41
src/mathed/button_inset.C Normal file
View File

@ -0,0 +1,41 @@
#include "button_inset.h"
#include "math_support.h"
#include "frontends/Painter.h"
ButtonInset::ButtonInset()
: MathNestInset(2)
{}
void ButtonInset::metrics(MathMetricsInfo & mi) const
{
MathFontSetChanger dummy(mi.base, "textnormal");
if (editing()) {
MathNestInset::metrics(mi);
width_ = xcell(0).width() + xcell(1).width() + 4;
ascent_ = max(xcell(0).ascent(), xcell(1).ascent());
descent_ = max(xcell(0).descent(), xcell(1).descent());
} else {
string s = screenLabel();
mathed_string_dim(mi.base.font,
s, ascent_, descent_, width_);
width_ += 10;
}
}
void ButtonInset::draw(MathPainterInfo & pi, int x, int y) const
{
MathFontSetChanger dummy(pi.base, "textnormal");
if (editing()) {
xcell(0).draw(pi, x, y);
xcell(1).draw(pi, x + xcell(0).width() + 2, y);
mathed_draw_framebox(pi, x, y, this);
} else {
pi.pain.buttonText(x + 2, y, screenLabel(),
pi.base.font);
}
}

22
src/mathed/button_inset.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef BUTTON_INSET_H
#define BUTTON_INSET_H
#include "math_nestinset.h"
// Try to implement the reference inset "natively" for mathed.
class ButtonInset: public MathNestInset {
public:
///
ButtonInset();
///
void metrics(MathMetricsInfo & mi) const;
///
void draw(MathPainterInfo & pi, int x, int y) const;
protected:
/// This should provide the text for the button
virtual string screenLabel() const = 0;
};
#endif

View File

@ -0,0 +1,41 @@
#include "command_inset.h"
#include "math_mathmlstream.h"
CommandInset::CommandInset(string const & data)
{
lock_ = true;
string::size_type idx0 = data.find("|++|");
name_ = data.substr(0, idx0);
if (idx0 == string::npos)
return;
idx0 += 4;
string::size_type idx1 = data.find("|++|", idx0);
cell(0) = asArray(data.substr(idx0, idx1 - idx0));
if (idx1 == string::npos)
return;
cell(1) = asArray(data.substr(idx1 + 4));
}
MathInset * CommandInset::clone() const
{
return new CommandInset(*this);
}
void CommandInset::write(WriteStream & os) const
{
os << "\\" << name_.c_str();
if (cell(1).size())
os << "[" << cell(1) << "]";
os << "{" << cell(0) << "}";
}
string CommandInset::screenLabel() const
{
return name_;
}

View File

@ -0,0 +1,25 @@
#ifndef COMMAND_INSET_H
#define COMMAND_INSET_H
#include "button_inset.h"
// for things like \name[options]{contents}
class CommandInset : public ButtonInset {
public:
/// name, contents, options deliminited by '|++|'
explicit CommandInset(string const & data);
///
MathInset * clone() const;
///
void write(WriteStream & os) const;
///
//void infoize(std::ostream & os) const;
///
//int dispatch(string const & cmd, idx_type idx, pos_type pos);
///
string screenLabel() const;
public:
string name_;
};
#endif

View File

@ -38,7 +38,6 @@
#include "frontends/mouse_state.h"
#include "Lsstream.h"
#include "math_arrayinset.h"
#include "math_boxinset.h"
#include "math_charinset.h"
#include "math_cursor.h"
#include "math_factory.h"
@ -55,6 +54,8 @@
#include "intl.h"
#include "../insets/insetcommand.h"
#include "ref_inset.h"
using std::endl;
using std::ostream;
using std::vector;

View File

@ -9,203 +9,6 @@
#include "math_mathmlstream.h"
#include "math_streamstr.h"
#include "math_cursor.h"
#include "commandtags.h"
#include "formulabase.h"
#include "BufferView.h"
#include "frontends/LyXView.h"
#include "frontends/Painter.h"
#include "frontends/Dialogs.h"
#include "lyxfunc.h"
#include "gettext.h"
#include "LaTeXFeatures.h"
ButtonInset::ButtonInset()
: MathNestInset(2)
{}
void ButtonInset::metrics(MathMetricsInfo & mi) const
{
MathFontSetChanger dummy(mi.base, "textnormal");
if (editing()) {
MathNestInset::metrics(mi);
width_ = xcell(0).width() + xcell(1).width() + 4;
ascent_ = max(xcell(0).ascent(), xcell(1).ascent());
descent_ = max(xcell(0).descent(), xcell(1).descent());
} else {
string s = screenLabel();
mathed_string_dim(mi.base.font,
s, ascent_, descent_, width_);
width_ += 10;
}
}
void ButtonInset::draw(MathPainterInfo & pi, int x, int y) const
{
MathFontSetChanger dummy(pi.base, "textnormal");
if (editing()) {
xcell(0).draw(pi, x, y);
xcell(1).draw(pi, x + xcell(0).width() + 2, y);
mathed_draw_framebox(pi, x, y, this);
} else {
pi.pain.buttonText(x + 2, y, screenLabel(),
pi.base.font);
}
}
////////////////////////////////
CommandInset::CommandInset(string const & data)
{
lock_ = true;
string::size_type idx0 = data.find("|++|");
name_ = data.substr(0, idx0);
if (idx0 == string::npos)
return;
idx0 += 4;
string::size_type idx1 = data.find("|++|", idx0);
cell(0) = asArray(data.substr(idx0, idx1 - idx0));
if (idx1 == string::npos)
return;
cell(1) = asArray(data.substr(idx1 + 4));
}
MathInset * CommandInset::clone() const
{
return new CommandInset(*this);
}
void CommandInset::write(WriteStream & os) const
{
os << "\\" << name_;
if (cell(1).size())
os << "[" << cell(1) << "]";
os << "{" << cell(0) << "}";
}
string CommandInset::screenLabel() const
{
return name_;
}
////////////////////////////////
RefInset::RefInset()
: CommandInset("ref")
{}
RefInset::RefInset(string const & data)
: CommandInset(data)
{}
MathInset * RefInset::clone() const
{
return new RefInset(*this);
}
void RefInset::infoize(std::ostream & os) const
{
os << "Ref: " << cell(0);
}
int RefInset::dispatch(string const & cmd, idx_type, pos_type)
{
if (cmd == "mouse 3") {
cerr << "trying to goto ref" << cell(0) << "\n";
mathcursor->formula()->view()->owner()->getLyXFunc()->
dispatch(LFUN_REF_GOTO, asString(cell(0)));
return 1; // dispatched
}
if (cmd == "mouse 1") {
cerr << "trying to open ref" << cell(0) << "\n";
// Eventually trigger dialog with button 3 not 1
// mathcursor->formula()->view()->owner()->getDialogs()
// ->showRef(this);
return 1; // dispatched
}
return 0; // undispatched
}
string RefInset::screenLabel() const
{
string str;
for (int i = 0; !types[i].latex_name.empty(); ++i)
if (name_ == types[i].latex_name) {
str = _(types[i].short_gui_name);
break;
}
str += asString(cell(0));
//if (/* !isLatex && */ !cell(0).empty()) {
// str += "||";
// str += asString(cell(1));
//}
return str;
}
void RefInset::validate(LaTeXFeatures & features) const
{
if (name_ == "vref" || name_ == "vpageref")
features.require("varioref");
else if (name_ == "prettyref")
features.require("prettyref");
}
int RefInset::ascii(std::ostream & os, int) const
{
os << "[" << asString(cell(0)) << "]";
return 0;
}
int RefInset::linuxdoc(std::ostream & os) const
{
os << "<ref id=\"" << asString(cell(0))
<< "\" name=\"" << asString(cell(1)) << "\" >";
return 0;
}
int RefInset::docbook(std::ostream & os, bool) const
{
if (cell(1).empty()) {
os << "<xref linkend=\"" << asString(cell(0)) << "\">";
} else {
os << "<link linkend=\"" << asString(cell(0))
<< "\">" << asString(cell(1)) << "</link>";
}
return 0;
}
RefInset::type_info RefInset::types[] = {
{ "ref", N_("Standard"), N_("Ref: ")},
{ "pageref", N_("Page Number"), N_("Page: ")},
{ "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
{ "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
{ "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
{ "", "", "" }
};
///////////////////////////////////
MathBoxInset::MathBoxInset(string const & name)
: MathGridInset(1, 1), name_(name)

View File

@ -11,88 +11,6 @@
class LyXFont;
// Try to implement the reference inset "natively" for mathed.
// This is here temporarily until I can do cvs add again.
class ButtonInset: public MathNestInset {
public:
///
ButtonInset();
///
void metrics(MathMetricsInfo & mi) const;
///
void draw(MathPainterInfo & pi, int x, int y) const;
protected:
/// This should provide the text for the button
virtual string screenLabel() const = 0;
};
// for things like \name[options]{contents}
class CommandInset : public ButtonInset {
public:
/// name, contents, options deliminited by '|++|'
explicit CommandInset(string const & data);
///
MathInset * clone() const;
///
void write(WriteStream & os) const;
///
//void infoize(std::ostream & os) const;
///
//int dispatch(string const & cmd, idx_type idx, pos_type pos);
///
string screenLabel() const;
public:
string name_;
};
// for \ref
class RefInset : public CommandInset {
public:
///
RefInset();
///
explicit RefInset(string const & data);
///
MathInset * clone() const;
///
//void write(WriteStream & os) const;
///
void infoize(std::ostream & os) const;
///
int dispatch(string const & cmd, idx_type idx, pos_type pos);
///
string screenLabel() const;
///
void validate(LaTeXFeatures & features) const;
/// plain ascii output
int ascii(std::ostream & os, int) const;
/// linuxdoc output
int linuxdoc(std::ostream & os) const;
/// docbook output
int docbook(std::ostream & os, bool) const;
struct type_info {
///
string latex_name;
///
string gui_name;
///
string short_gui_name;
};
static type_info types[];
///
static int getType(string const & name);
///
static string const & getName(int type);
};
/// Support for \\mbox
class MathBoxInset : public MathGridInset {

View File

@ -31,6 +31,8 @@
#include "math_xymatrixinset.h"
#include "math_xyarrowinset.h"
#include "ref_inset.h"
#include "math_metricsinfo.h"
#include "debug.h"
#include "math_support.h"

View File

@ -58,6 +58,8 @@ following hack as starting point to write some macros:
#include "math_support.h"
#include "math_xyarrowinset.h"
#include "ref_inset.h"
#include "lyxlex.h"
#include "debug.h"
#include "support/LAssert.h"

118
src/mathed/ref_inset.C Normal file
View File

@ -0,0 +1,118 @@
#include "ref_inset.h"
#include "math_cursor.h"
#include "commandtags.h"
#include "formulabase.h"
#include "BufferView.h"
#include "frontends/LyXView.h"
#include "frontends/Painter.h"
#include "frontends/Dialogs.h"
#include "lyxfunc.h"
#include "gettext.h"
#include "LaTeXFeatures.h"
RefInset::RefInset()
: CommandInset("ref")
{}
RefInset::RefInset(string const & data)
: CommandInset(data)
{}
MathInset * RefInset::clone() const
{
return new RefInset(*this);
}
void RefInset::infoize(std::ostream & os) const
{
os << "Ref: " << cell(0);
}
int RefInset::dispatch(string const & cmd, idx_type, pos_type)
{
if (cmd == "mouse 3") {
cerr << "trying to goto ref" << cell(0) << "\n";
mathcursor->formula()->view()->owner()->getLyXFunc()->
dispatch(LFUN_REF_GOTO, asString(cell(0)));
return 1; // dispatched
}
if (cmd == "mouse 1") {
cerr << "trying to open ref" << cell(0) << "\n";
// Eventually trigger dialog with button 3 not 1
// mathcursor->formula()->view()->owner()->getDialogs()
// ->showRef(this);
return 1; // dispatched
}
return 0; // undispatched
}
string RefInset::screenLabel() const
{
string str;
for (int i = 0; !types[i].latex_name.empty(); ++i)
if (name_ == types[i].latex_name) {
str = _(types[i].short_gui_name);
break;
}
str += asString(cell(0));
//if (/* !isLatex && */ !cell(0).empty()) {
// str += "||";
// str += asString(cell(1));
//}
return str;
}
void RefInset::validate(LaTeXFeatures & features) const
{
if (name_ == "vref" || name_ == "vpageref")
features.require("varioref");
else if (name_ == "prettyref")
features.require("prettyref");
}
int RefInset::ascii(std::ostream & os, int) const
{
os << "[" << asString(cell(0)) << "]";
return 0;
}
int RefInset::linuxdoc(std::ostream & os) const
{
os << "<ref id=\"" << asString(cell(0))
<< "\" name=\"" << asString(cell(1)) << "\" >";
return 0;
}
int RefInset::docbook(std::ostream & os, bool) const
{
if (cell(1).empty()) {
os << "<xref linkend=\"" << asString(cell(0)) << "\">";
} else {
os << "<link linkend=\"" << asString(cell(0))
<< "\">" << asString(cell(1)) << "</link>";
}
return 0;
}
RefInset::type_info RefInset::types[] = {
{ "ref", N_("Standard"), N_("Ref: ")},
{ "pageref", N_("Page Number"), N_("Page: ")},
{ "vpageref", N_("Textual Page Number"), N_("TextPage: ")},
{ "vref", N_("Standard+Textual Page"), N_("Ref+Text: ")},
{ "prettyref", N_("PrettyRef"), N_("PrettyRef: ")},
{ "", "", "" }
};

49
src/mathed/ref_inset.h Normal file
View File

@ -0,0 +1,49 @@
#ifndef REF_INSET_H
#define REF_INSET_H
#include "command_inset.h"
// for \ref
class RefInset : public CommandInset {
public:
///
RefInset();
///
explicit RefInset(string const & data);
///
MathInset * clone() const;
///
//void write(WriteStream & os) const;
///
void infoize(std::ostream & os) const;
///
int dispatch(string const & cmd, idx_type idx, pos_type pos);
///
string screenLabel() const;
///
void validate(LaTeXFeatures & features) const;
/// plain ascii output
int ascii(std::ostream & os, int) const;
/// linuxdoc output
int linuxdoc(std::ostream & os) const;
/// docbook output
int docbook(std::ostream & os, bool) const;
struct type_info {
///
string latex_name;
///
string gui_name;
///
string short_gui_name;
};
static type_info types[];
///
static int getType(string const & name);
///
static string const & getName(int type);
};
#endif