]> git.lyx.org Git - features.git/commitdiff
First shot at inset-unification mathed & rest of the world
authorAndré Pönitz <poenitz@gmx.net>
Mon, 24 Jun 2002 15:51:35 +0000 (15:51 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 24 Jun 2002 15:51:35 +0000 (15:51 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4467 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
src/mathed/Makefile.am
src/mathed/button_inset.C [new file with mode: 0644]
src/mathed/button_inset.h [new file with mode: 0644]
src/mathed/command_inset.C [new file with mode: 0644]
src/mathed/command_inset.h [new file with mode: 0644]
src/mathed/formulabase.C
src/mathed/math_boxinset.C
src/mathed/math_boxinset.h
src/mathed/math_factory.C
src/mathed/math_parser.C
src/mathed/ref_inset.C [new file with mode: 0644]
src/mathed/ref_inset.h [new file with mode: 0644]

index cec9303eb347c65f3ad9bbd0045deb13cc1fd59d..fc8b15998579bf74072f74308f057baaca1ec9d1 100644 (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
diff --git a/src/mathed/button_inset.C b/src/mathed/button_inset.C
new file mode 100644 (file)
index 0000000..4a5644c
--- /dev/null
@@ -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 (file)
index 0000000..2e26af9
--- /dev/null
@@ -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 (file)
index 0000000..7af795e
--- /dev/null
@@ -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 (file)
index 0000000..772f880
--- /dev/null
@@ -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
index 008a131bd4c196bc14aa77c79128568ad011106b..aec69509a231f78be40d27697f370ae7cf207009 100644 (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;
index f9d527c16121f2a23bb11eedae58cb1afd15f0a7..3d5f14b6adc567282a8dd5dc285795b90172d518 100644 (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)
index 52054662a6c9794c1f0e63d3d10551845dfffde3..59fd02d1ac3c212638df7f0570ffd254e5109bfb 100644 (file)
 
 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 {
index dc32859eb66a36d697a90880bfa51276ae817309..bf37981bf7f6f9a5dd9a5116da954758c98569e1 100644 (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"
index bdb32719e22f743bf3c40669c4a13f7eb5970e6e..484bc2b1d02bb939337285356d85e918e02152a2 100644 (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"
diff --git a/src/mathed/ref_inset.C b/src/mathed/ref_inset.C
new file mode 100644 (file)
index 0000000..c607d19
--- /dev/null
@@ -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: ")},
+       { "", "", "" }
+};
diff --git a/src/mathed/ref_inset.h b/src/mathed/ref_inset.h
new file mode 100644 (file)
index 0000000..852fc32
--- /dev/null
@@ -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