From 4d59d00ad4bad81050cd2f50e71ad7056765033e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Mon, 24 Jun 2002 15:51:35 +0000 Subject: [PATCH] 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 --- src/mathed/Makefile.am | 8 +- src/mathed/button_inset.C | 41 ++++++++ src/mathed/button_inset.h | 22 +++++ src/mathed/command_inset.C | 41 ++++++++ src/mathed/command_inset.h | 25 +++++ src/mathed/formulabase.C | 3 +- src/mathed/math_boxinset.C | 197 ------------------------------------- src/mathed/math_boxinset.h | 82 --------------- src/mathed/math_factory.C | 2 + src/mathed/math_parser.C | 2 + src/mathed/ref_inset.C | 118 ++++++++++++++++++++++ src/mathed/ref_inset.h | 49 +++++++++ 12 files changed, 309 insertions(+), 281 deletions(-) create mode 100644 src/mathed/button_inset.C create mode 100644 src/mathed/button_inset.h create mode 100644 src/mathed/command_inset.C create mode 100644 src/mathed/command_inset.h create mode 100644 src/mathed/ref_inset.C create mode 100644 src/mathed/ref_inset.h diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index cec9303eb3..fc8b159985 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -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 diff --git a/src/mathed/button_inset.C b/src/mathed/button_inset.C new file mode 100644 index 0000000000..4a5644cb92 --- /dev/null +++ b/src/mathed/button_inset.C @@ -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); + } +} + diff --git a/src/mathed/button_inset.h b/src/mathed/button_inset.h new file mode 100644 index 0000000000..2e26af9396 --- /dev/null +++ b/src/mathed/button_inset.h @@ -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 diff --git a/src/mathed/command_inset.C b/src/mathed/command_inset.C new file mode 100644 index 0000000000..7af795e341 --- /dev/null +++ b/src/mathed/command_inset.C @@ -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_; +} diff --git a/src/mathed/command_inset.h b/src/mathed/command_inset.h new file mode 100644 index 0000000000..772f88054b --- /dev/null +++ b/src/mathed/command_inset.h @@ -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 diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 008a131bd4..aec69509a2 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -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; diff --git a/src/mathed/math_boxinset.C b/src/mathed/math_boxinset.C index f9d527c161..3d5f14b6ad 100644 --- a/src/mathed/math_boxinset.C +++ b/src/mathed/math_boxinset.C @@ -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 << ""; - return 0; -} - - -int RefInset::docbook(std::ostream & os, bool) const -{ - if (cell(1).empty()) { - os << ""; - } else { - os << "" << asString(cell(1)) << ""; - } - - 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) diff --git a/src/mathed/math_boxinset.h b/src/mathed/math_boxinset.h index 52054662a6..59fd02d1ac 100644 --- a/src/mathed/math_boxinset.h +++ b/src/mathed/math_boxinset.h @@ -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 { diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index dc32859eb6..bf37981bf7 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -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" diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index bdb32719e2..484bc2b1d0 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -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" diff --git a/src/mathed/ref_inset.C b/src/mathed/ref_inset.C new file mode 100644 index 0000000000..c607d19812 --- /dev/null +++ b/src/mathed/ref_inset.C @@ -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 << ""; + return 0; +} + + +int RefInset::docbook(std::ostream & os, bool) const +{ + if (cell(1).empty()) { + os << ""; + } else { + os << "" << asString(cell(1)) << ""; + } + + 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: ")}, + { "", "", "" } +}; diff --git a/src/mathed/ref_inset.h b/src/mathed/ref_inset.h new file mode 100644 index 0000000000..852fc320d1 --- /dev/null +++ b/src/mathed/ref_inset.h @@ -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 -- 2.39.2