]> git.lyx.org Git - lyx.git/commitdiff
add missing writeNormal() methods to some insets
authorAndré Pönitz <poenitz@gmx.net>
Wed, 24 Oct 2001 16:10:38 +0000 (16:10 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Wed, 24 Oct 2001 16:10:38 +0000 (16:10 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2935 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/array.C
src/mathed/formula.C
src/mathed/math_charinset.C
src/mathed/math_cursor.C
src/mathed/math_deliminset.C
src/mathed/math_deliminset.h
src/mathed/math_rootinset.C
src/mathed/math_scriptinset.C
src/mathed/math_scriptinset.h
src/mathed/math_sqrtinset.C

index 11042bf333273890a22494ded4292a732c7740dc..3c029857907d2b32f8f9f65063dd9835c9845763 100644 (file)
@@ -201,10 +201,17 @@ void MathArray::write(MathWriteInfo & wi) const
 
 void MathArray::writeNormal(ostream & os) const
 {
-       os << "[par ";
-       for (const_iterator it = begin(); it != end(); ++it)
-               (*it)->writeNormal(os);
-       os << "]";
+       for (const_iterator it = begin(); it != end(); ++it) {  
+               MathInset * p = it->nucleus();
+               if (!p)
+                       continue;
+               if (MathScriptInset const * q = asScript(it)) {
+                       q->writeNormal(p, os);
+                       ++it;
+               } else {
+                       p->writeNormal(os);
+               }
+       }
 }
 
 
index ce31858fa874e23716acd48b965d846712ab15f9..02ab30e6f678c4ce7555129b2a492cfc9596602b 100644 (file)
@@ -18,7 +18,6 @@
 #endif
 
 #include <config.h>
-#include <fstream>
 
 #include "formula.h"
 #include "commandtags.h"
@@ -35,6 +34,7 @@
 #include "support/lyxlib.h"
 #include "support/syscall.h"
 #include "support/lstrings.h"
+#include "support/filetools.h" // LibFileSearch
 #include "LyXView.h"
 #include "Painter.h"
 #include "lyxrc.h"
@@ -63,6 +63,40 @@ namespace {
                ar.erase(pos, ar.size());
        }
 
+
+       MathArray pipeThroughExtern(string const & arg, MathArray const & ar)
+       {
+               string lang;
+               string extra;
+               istringstream iss(arg.c_str());
+               iss >> lang >> extra;
+               if (extra.empty())
+                       extra = "noextra";      
+
+               // create normalized expression
+               string outfile = lyx::tempName(string(), "mathextern");
+               ostringstream os;
+               os << "[" << extra << ' ';
+               ar.writeNormal(os); 
+               os << "]";
+               string code = os.str().c_str();
+
+               // run external sript
+               string file = LibFileSearch(string(), "lyx2" + lang);
+               if (file.empty()) {
+                       lyxerr << "converter to '" << lang << "' not found\n";
+                       return MathArray();
+               }
+               string script = file + " '" + code + "' " + outfile;
+               lyxerr << "calling: " << script << endl;
+               Systemcalls cmd(Systemcalls::System, script, 0);
+
+               // append result
+               MathArray res;
+               mathed_parse_cell(res, GetFileContents(outfile));
+               return res;
+       }
+
 }
 
 
@@ -317,49 +351,6 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action,
        return result;
 }
 
-#if 0
-void InsetFormula::handleExtern(const string & arg)
-{
-       // where are we?
-       if (!mathcursor)
-               return; 
-
-       MathArray & ar = mathcursor->cursor().cell();
-
-       // parse args
-       string lang;
-       string extra;
-       istringstream iss(arg.c_str());
-       iss >> lang >> extra;
-       if (extra.empty())
-               extra = "noextra";      
-
-       // strip last '=' and everything behind
-       stripFromLastEqualSign(ar);
-
-       // create normalized expression
-       //string outfile = lyx::tempName("maple.out");
-       string outfile = "/tmp/lyx2" + lang + ".out";
-       ostringstream os;
-       os << "[" << extra << ' ';
-       ar.writeNormal(os); 
-       os << "]";
-       string code = os.str().c_str();
-
-       // run external sript
-       string script = "lyx2" + arg + " '" + code + "' " + outfile;
-       lyxerr << "calling: " << script << endl;
-       Systemcalls cmd(Systemcalls::System, script, 0);
-
-       // append a '='
-       ar.push_back(MathAtom(new MathCharInset('=')));
-       
-       // append result
-       ifstream is(outfile.c_str());
-       mathed_parse_cell(ar, is);
-       mathcursor->end();
-}
-#endif
 
 void InsetFormula::handleExtern(const string & arg)
 {
@@ -374,45 +365,17 @@ void InsetFormula::handleExtern(const string & arg)
                mathcursor->selGet(ar);
                lyxerr << "use selection: " << ar << "\n";
        } else {
+               mathcursor->end();
                ar = mathcursor->cursor().cell();
+               stripFromLastEqualSign(ar);
+               mathcursor->insert(MathAtom(new MathCharInset('=', LM_TC_VAR)));
                lyxerr << "use whole cell: " << ar << "\n";
        }
 
-
-       // parse args
-       string lang;
-       string extra;
-       istringstream iss(arg.c_str());
-       iss >> lang >> extra;
-       if (extra.empty())
-               extra = "noextra";      
-
-       // strip last '=' and everything behind
-       stripFromLastEqualSign(ar);
-
-       // create normalized expression
-       //string outfile = lyx::tempName("maple.out");
-       string outfile = "/tmp/lyx2" + lang + ".out";
-       ostringstream os;
-       os << "[" << extra << ' ';
-       ar.writeNormal(os); 
-       os << "]";
-       string code = os.str().c_str();
-
-       // run external sript
-       string script = "lyx2" + lang + " '" + code + "' " + outfile;
-       lyxerr << "calling: " << script << endl;
-       Systemcalls cmd(Systemcalls::System, script, 0);
-
-       // append result
-       MathArray br;
-       if (selected)
-               br.push_back(MathAtom(new MathCharInset('=', LM_TC_VAR)));
-       ifstream is(outfile.c_str());
-       mathed_parse_cell(br, is);
-       mathcursor->insert(br);
+       mathcursor->insert(pipeThroughExtern(arg, ar));
 }
 
+
 bool InsetFormula::display() const
 {
        return mat()->getType() != LM_OT_SIMPLE;
index 8b0a570184bf7e84c262cf26176c2c20fd7a3973..ff1852c162f67211bb9b97b3c57f004209ed875c 100644 (file)
@@ -119,7 +119,7 @@ void MathCharInset::write(MathWriteInfo & os) const
 
 void MathCharInset::writeNormal(std::ostream & os) const
 {
-       os << char_;
+       os << "[char " << char_ << " " << "mathalpha" << "]";
 }
 
 
index 2bcfb6bb59411c9ddb0261421c9d6fdab119d22a..6535c43bd34167970dc3c2af533744fca6075715 100644 (file)
@@ -702,7 +702,8 @@ void MathCursor::selDel()
        seldump("selDel");
        if (selection_) {
                theSelection.erase(*this);
-               pos() = 0;
+               if (pos() > size())
+                       pos() = size();
                selClear();
        }
 }
index ed1b0ea57398f0d18047bfaab393951a19d73de9..d9755b7cb0463aec46f00381e04b4a111d40aca9 100644 (file)
@@ -49,6 +49,12 @@ void MathDelimInset::write(MathWriteInfo & os) const
 }
 
 
+void MathDelimInset::writeNormal(std::ostream & os) const
+{
+       os << "[delim " << latexName(left_) << " " << latexName(right_) << "]";
+}
+
+
 int MathDelimInset::dw() const
 {
        int w = height() / 5;
index 89240db8cbfa722315481f3596ef54049152d104..f1fb2bf60595d12a95be8a9f8c9e36a51430988c 100644 (file)
@@ -23,6 +23,8 @@ public:
        void draw(Painter &, int x, int y) const;
        ///
        void write(MathWriteInfo & os) const;
+       /// write normalized content
+       void writeNormal(std::ostream &) const;
        ///
        void metrics(MathMetricsInfo const & st) const;
 private:
index d84ec004ace0b2c6febd3b3f25dd9f0222ba6bb7..d7dbad49431ce5a1034326669a5eb5e081d4d362 100644 (file)
@@ -70,7 +70,7 @@ void MathRootInset::writeNormal(std::ostream & os) const
        cell(1).writeNormal(os);  
        os << " ";
        cell(0).writeNormal(os);
-       os << "] ";
+       os << "]";
 }
 
 
index 39de7947d868d1ef89bb2c3b0f2c7803cc11a3ce..3b190369e66d2556b471f3e5346746b74e65b7c2 100644 (file)
@@ -1,4 +1,7 @@
+
 #include <config.h>
+#include <sstream>
+
 #include "debug.h"
 #include "support.h"
 #include "support/LOstream.h"
@@ -10,6 +13,8 @@
 
 #include "math_scriptinset.h"
 
+using std::ostringstream;
+
 
 MathScriptInset::MathScriptInset()
        : MathNestInset(2), limits_(0)
@@ -27,7 +32,6 @@ MathScriptInset::MathScriptInset(bool up)
 }
 
 
-
 MathInset * MathScriptInset::clone() const
 {
        return new MathScriptInset(*this);
@@ -251,6 +255,43 @@ void MathScriptInset::write(MathInset const * nuc, MathWriteInfo & os) const
 }
 
 
+void MathScriptInset::writeNormal(ostream & os) const
+{  
+       //lyxerr << "unexpected call to MathScriptInset::writeNormal()\n";
+       writeNormal(0, os);
+}
+
+
+void MathScriptInset::writeNormal(MathInset const * nuc, ostream & os) const
+{
+       bool d = hasDown() && down().data_.size();
+       bool u = hasUp() && up().data_.size();
+
+       ostringstream osb;
+       if (nuc)
+               nuc->writeNormal(osb);
+       else
+               osb << "[par]";
+       string base = osb.str();
+
+       if (u && d) {
+               os << "[sup [sub " << osb.str() << " ";
+               down().data_.writeNormal(os);
+               os << "]";
+               up().data_.writeNormal(os);
+               os << ']';
+       } else if (u) {
+               os << "[sup " << osb.str() << " ";
+               up().data_.writeNormal(os);
+               os << ']';
+       } else if (d) {
+               os << "[sub " << osb.str() << " ";
+               down().data_.writeNormal(os);
+               os << ']';
+       }
+}
+
+
 bool MathScriptInset::hasLimits(MathInset const * nuc) const
 {
        return limits_ == 1 || (limits_ == 0 && nuc && nuc->isScriptable());
index f7af1546ccfe5ac7482ea4ac0128c30f8ee04f71..0bcb5287e48d58da7c0eed4c535acb57d2302118 100644 (file)
@@ -23,6 +23,8 @@ public:
        ///
        void write(MathWriteInfo & os) const;
        ///
+       void writeNormal(ostream & os) const;
+       ///
        void metrics(MathMetricsInfo const & st) const;
        ///
        void draw(Painter &, int x, int y) const;
@@ -30,6 +32,8 @@ public:
        ///
        void write(MathInset const *, MathWriteInfo & os) const;
        ///
+       void writeNormal(MathInset const *, ostream & os) const;
+       ///
        void metrics(MathInset const * nucleus, MathMetricsInfo const & st) const;
        ///
        void draw(MathInset const * nucleus, Painter &, int x, int y) const;
index acd1440cf9c73288982babdef6859d98f956f4bd..9c6b4b3ed34455f55dc94a54c2883d6ffcca26bf 100644 (file)
@@ -53,5 +53,5 @@ void MathSqrtInset::writeNormal(std::ostream & os) const
 {
        os << "[sqrt ";
        cell(0).writeNormal(os); 
-       os << "] ";
+       os << "]";
 }