]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_macro.C
Hopefully fix the problem with stateText() in lyxfont.C
[lyx.git] / src / mathed / math_macro.C
index 6fcd845ad7d0a920b1c9351de97335c5624ed309..a68705933dd2997f19462f4a2e88fa6a6fa4e0f7 100644 (file)
@@ -8,7 +8,7 @@
  *
  *  Dependencies: Mathed
  *
- *  Copyright: (c) 1996, 1997 Alejandro Aguilar Sierra
+ *  Copyright: 1996, 1997 Alejandro Aguilar Sierra
  *
  *  Version: 0.2, Mathed & Lyx project.
  *
@@ -30,6 +30,8 @@
 #include "support/lstrings.h"
 #include "debug.h"
 
+using std::ostream;
+using std::endl;
 
 ostream & operator<<(ostream & o, MathedTextCodes mtc)
 {
@@ -156,14 +158,13 @@ void MathMacro::SetFocus(int x, int y)
 }
 
 
-void MathMacro::Write(ostream & os)
+void MathMacro::Write(ostream & os, bool fragile)
 {
-#ifdef USE_OSTREAM_ONLY
     if (tmplate->flags & MMF_Exp) {
            lyxerr[Debug::MATHED] << "Expand " << tmplate->flags
                                  << ' ' << MMF_Exp << endl; 
        tmplate->update(this);
-       tmplate->Write(os);
+       tmplate->Write(os, fragile);
     } else {
        if (tmplate->flags & MMF_Env) {
                os << "\\begin{"
@@ -183,7 +184,7 @@ void MathMacro::Write(ostream & os)
        
        for (int i = 0; i < nargs; ++i) {
            array = args[i].array;
-           MathParInset::Write(os);
+           MathParInset::Write(os, fragile);
            if (i < nargs - 1)  
                    os << "}{";
        }   
@@ -198,61 +199,9 @@ void MathMacro::Write(ostream & os)
                    os << ' ';
        }
     }
-#else
-   string output;
-   MathMacro::Write(output);
-   os << output;
-#endif
 }
 
 
-#ifndef USE_OSTREAM_ONLY
-void MathMacro::Write(string &file)
-{
-    if (tmplate->flags & MMF_Exp) {
-           lyxerr[Debug::MATHED] << "Expand " << tmplate->flags
-                                 << ' ' << MMF_Exp << endl; 
-       tmplate->update(this);
-       tmplate->Write(file);
-    } else {
-       if (tmplate->flags & MMF_Env) {
-         file += "\\begin{";
-         file += name;
-         file += "} ";
-       } else {
-         file += '\\';
-         file += name;
-       }
-//     if (options) { 
-//       file += '[';
-//       file += options;
-//       file += ']';
-//      }
-       
-       if (!(tmplate->flags & MMF_Env) && nargs > 0) 
-         file += '{';
-       
-       for (int i = 0; i < nargs; ++i) {
-           array = args[i].array;
-           MathParInset::Write(file);
-           if (i < nargs - 1)  
-             file += "}{";
-       }   
-       if (tmplate->flags & MMF_Env) {
-           file += "\\end{";
-           file += name;
-           file += '}';
-       } else {
-           if (nargs > 0) 
-               file += '}';
-           else
-               file += ' ';
-       }
-    }
-}
-#endif
-
-
 /*---------------  Macro argument -----------------------------------*/
 
 MathMacroArgument::MathMacroArgument(int n)
@@ -269,15 +218,16 @@ void MathMacroArgument::draw(Painter & pain, int x, int baseline)
        MathParInset::draw(pain, x, baseline);
     } else {
 #ifdef HAVE_SSTREAM
-           ostringstream ost;
+           std::ostringstream ost;
            ost << '#' << number;
-           drawStr(pain, LM_TC_TEX, size, x, baseline, ost.str().c_str(), 2);
+           drawStr(pain, LM_TC_TEX, size, x, baseline, 
+                   reinterpret_cast<byte const *>(ost.str().c_str()), 2);
 #else
            char s[3];
            ostrstream ost(s, 3);
            ost << '#' << number << '\0';
            drawStr(pain, LM_TC_TEX, size, x, baseline,
-                   reinterpret_cast<unsigned char*>(ost.str()), 2);
+                   reinterpret_cast<byte *>(ost.str()), 2);
 #endif
     }
 }
@@ -289,56 +239,38 @@ void MathMacroArgument::Metrics()
        MathParInset::Metrics();
     } else {
 #ifdef HAVE_SSTREAM
-           ostringstream ost;
+           std::ostringstream ost;
            ost << '#' << number;
-           width = mathed_string_width(LM_TC_TEX, size, ost.str().c_str(), 2);
+           width = mathed_string_width(LM_TC_TEX, size, 
+                                       reinterpret_cast<byte const *>(ost.str().c_str()), 2);
            mathed_string_height(LM_TC_TEX, size,
-                                ost.str().c_str(), 2, ascent, descent);
+                                reinterpret_cast<byte const *>(ost.str().c_str()), 
+                                2, ascent, descent);
 #else
        char s[3];
        ostrstream ost(s, 3);
        ost << '#' << number << '\0';
        width = mathed_string_width(LM_TC_TEX, size,
-                                   reinterpret_cast<unsigned char*>
+                                   reinterpret_cast<byte *>
                                    (ost.str()), 2);
        mathed_string_height(LM_TC_TEX, size,
-                            reinterpret_cast<unsigned char*>(ost.str()),
+                            reinterpret_cast<byte *>(ost.str()),
                             2, ascent, descent);
 #endif
     }
 }
 
 
-void MathMacroArgument::Write(ostream & os)
+void MathMacroArgument::Write(ostream & os, bool fragile)
 {
-#ifdef USE_OSTREAM_ONLY
     if (expnd_mode) {
-       MathParInset::Write(os);
+       MathParInset::Write(os, fragile);
     } else {
            os << '#' << number << ' ';
     }
-#else
-   string output;
-   MathMacroArgument::Write(output);
-   os << output;
-#endif
 }
 
 
-#ifndef USE_OSTREAM_ONLY
-void MathMacroArgument::Write(string & file)
-{
-    if (expnd_mode) {
-       MathParInset::Write(file);
-    } else {
-       file += '#';
-       file += tostr(number);
-       file += ' ';
-    }
-}
-#endif
-
-
 /* --------------------- MathMacroTemplate ---------------------------*/
 
 MathMacroTemplate::MathMacroTemplate(char const * nm, int na, int flg):
@@ -443,7 +375,7 @@ void MathMacroTemplate::update(MathMacro * macro)
 }
     
 
-void MathMacroTemplate::WriteDef(ostream & os)
+void MathMacroTemplate::WriteDef(ostream & os, bool fragile)
 {
        os << "\n\\newcommand{\\" << name << "}";
       
@@ -455,35 +387,11 @@ void MathMacroTemplate::WriteDef(ostream & os)
     for (int i = 0; i < nargs; ++i) {
        args[i].setExpand(false);
     }   
-    Write(os); 
+    Write(os, fragile); 
     os << "}\n";
 }
 
 
-#ifndef USE_OSTREAM_ONLY
-void MathMacroTemplate::WriteDef(string & file)
-{
-    file += "\n\\newcommand{\\";
-    file += name;
-    file += '}';
-      
-    if (nargs > 0 ) {
-      file += '[';
-      file += tostr(nargs);
-      file += ']';
-    }
-    
-    file += '{';
-    
-    for (int i = 0; i < nargs; ++i) {
-       args[i].setExpand(false);
-    }   
-    Write(file); 
-    file += "}\n";
-}
-#endif
-
-
 void MathMacroTemplate::setArgument(LyxArrayBase * a, int i)
 {
     args[i].SetData(a);