]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_macro.h
fix typo that put too many include paths for most people
[lyx.git] / src / mathed / math_macro.h
index f58d78041ffa8597da24d8e50b842eae044415dc..ee8059c03dc7d6409ec93883d656b4de651e309c 100644 (file)
 // -*- C++ -*-
 /*
  *  File:        math_macro.h
- *  Purpose:     Declaration of macro class for mathed 
- *  Author:      Alejandro Aguilar Sierra <asierra@servidor.unam.mx> 
+ *  Purpose:     Declaration of macro class for mathed
+ *  Author:      Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
  *  Created:     November 1996
  *  Description: WYSIWYG math macros
  *
- *  Dependencies: Mathed
+ *  Dependencies: Math
  *
  *  Copyright: 1996, 1997 Alejandro Aguilar Sierra
  *
- *   Version: 0.2, Mathed & Lyx project.
+ *   Version: 0.2, Math & Lyx project.
  *
  *   This code is under the GNU General Public Licence version 2 or later.
  */
-#ifndef MATH_MACRO
-#define MATH_MACRO
+#ifndef MATH_MACRO_H
+#define MATH_MACRO_H
 
 #ifdef __GNUG__
 #pragma interface
 #endif
 
-#include "math_defs.h"
-#include "debug.h"
+#include <vector>
+#include <iosfwd>
 
-///
-typedef MathParInset * MathParInsetP;
-///
-typedef LyxArrayBase * LyxArrayBaseP;
+#include "math_nestinset.h"
+#include "math_macroarg.h"
+#include "LString.h"
 
 class MathMacroTemplate;
 
 
-/// This class contains the data for a macro
-class MathMacro : public MathParInset
-{
+/** This class contains the data for a macro
+    \author Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
+    \version November 1996
+ */
+class MathMacro : public MathNestInset {
 public:
-    /// A macro can only be builded from an existing template
-    MathMacro(MathMacroTemplate *);
-    /// or from another macro.
-    MathMacro(MathMacro *);
-       ///
-    ~MathMacro();
-    ///
-    void draw(Painter &, int, int);
-    ///
-    void Metrics();
-       ///
-    MathedInset * Clone();
-       ///
-    void Write(std::ostream &);
-       ///
-    bool setArgumentIdx(int);
-       ///
-    int  getArgumentIdx();
-       ///
-    int  getMaxArgumentIdx();
-       ///
-    int GetColumns();
-       ///
-    void GetXY(int &, int &) const;
-       ///
-    void SetFocus(int, int);
-       ///
-    LyxArrayBase * GetData();
+       /// A macro can be built from an existing template
+       explicit MathMacro(string const &);
        ///
-    MathedRowSt * getRowSt() const { return args[idx].row; }
+       MathMacro(MathMacro const &);
        ///
-    void SetData(LyxArrayBase *);
+       void draw(Painter &, int x, int y) const;
        ///
-    MathedTextCodes getTCode() { return tcode; }
+       void metrics(MathMetricsInfo const & st) const;
        ///
-    bool Permit(short);
-    
-private:
-       ///
-       MathMacroTemplate * tmplate;
-       ///
-       struct MacroArgumentBase {
-               /// Position of the macro
-               int x, y;
-               ///
-               MathedRowSt * row;
-               ///
-               LyxArrayBase * array;
-               ///
-               MacroArgumentBase() { x = y = 0;  array = 0; row = 0; }
-       };
-       MacroArgumentBase * args;
+       MathInset * clone() const;
        ///
-       int idx;
+       void dump() const;
+
        ///
-       int nargs;
+       bool idxUpDown(idx_type &, bool up) const;
        ///
-       MathedTextCodes tcode;
+       bool idxLeft(idx_type &, pos_type &) const;
        ///
-       friend class MathMacroTemplate;
-};
-
+       bool idxRight(idx_type &, pos_type &) const;
 
-/// An argument
-class MathMacroArgument: public MathParInset {
-public:
-    ///
-    MathMacroArgument() { expnd_mode = false; number = 1;  SetType(LM_OT_MACRO_ARG); }
-    ///
-    MathMacroArgument(int);
-    ///
-       ~MathMacroArgument() { lyxerr << "help, destroyme!" << std::endl; }
-    ///
-    MathedInset * Clone() { return this; }
-       ///
-    void Metrics();
        ///
-    void draw(Painter &, int x, int baseline);
+       void validate(LaTeXFeatures &) const;
        ///
-    void Write(std::ostream &);
-    ///
-    void setNumber(int n) { number = n; }
-    /// Is expanded or not
-    void setExpand(bool e) { expnd_mode = e; }
-    /// Is expanded or not
-    bool getExpand() { return expnd_mode; }
-private:
+       bool isMacro() const { return true; }
        ///
-    bool expnd_mode;
-       ///
-    int number;
-};
+       bool match(MathInset *) const { return false; }
 
-
-/// This class contains the macro definition
-class MathMacroTemplate: public MathParInset {
-public:
-    /// A template constructor needs all the data
-    MathMacroTemplate(char const *, int na = 0, int f = 0);
        ///
-    ~MathMacroTemplate();
+       void normalize(NormalStream &) const;
        ///
-    void draw(Painter &, int, int);
+       void maplize(MapleStream &) const;
        ///
-    void Metrics();
+       void mathmlize(MathMLStream &) const;
        ///
-    void WriteDef(std::ostream &);
-    /// useful for special insets
-    void  setTCode(MathedTextCodes t) { tcode = t; }
-    ///
-    MathedTextCodes getTCode() { return tcode; }
-    /// 
-    void setArgument(LyxArrayBase *, int i= 0);
-    /// Number of arguments
-    int getNoArgs() { return nargs; }
-    ///
-    void GetMacroXY(int, int &, int &) const;
-    ///
-    MathParInset * getMacroPar(int) const;
-    ///
-    void SetMacroFocus(int &, int, int);
+       void octavize(OctaveStream &) const;
        ///
-    void setEditMode(bool);
+       void write(WriteStream & os) const;
 
-    /// Replace the appropriate arguments with a specific macro's data
-    void update(MathMacro * m = 0);
-      
 private:
-    ///
-    short flags;
-    ///
-    MathedTextCodes tcode;
-    ///
-    MathMacroArgument * args;
-    ///
-    int nargs;
-    ///
-    friend class MathMacro;
-};
-     
-
-///
-typedef MathMacro * MathMacroP;
-///
-typedef MathMacroTemplate * MathMacroTemplateP;
-
-///
-class MathMacroTable {
-public:
        ///
-    MathMacroTable(int);
+       void operator=(MathMacro const &);
        ///
-    ~MathMacroTable();
+       char const * name() const;
        ///
-    void addTemplate(MathMacroTemplate *);
+       bool defining() const;
        ///
-    MathMacro * getMacro(char const *) const;
+       void updateExpansion() const;
        ///
-    MathMacroTemplate * getTemplate(char const *) const;
-       ///
-    void builtinMacros();
+       void expand() const;
+
        ///
-    static MathMacroTable mathMTable;
+       MathAtom & tmplate_;
        ///
-    static bool built;
-    
-private:
+       mutable MathXArray expanded_;
        ///
-    const int max_macros;
+       mutable MathMetricsInfo mi_;
        ///
-    int num_macros;
-       ///
-    MathMacroTemplateP * macro_table;
+       mutable LyXFont font_;
 };
 
 
-
-/*-----------------------  inlines  -------------------------*/
-
-inline
-bool MathMacro::setArgumentIdx(int i)
-{
-    if (i >= 0 && i < nargs) {
-       idx = i;
-       return true;
-    } else
-      return false;
-}
-
-inline
-int  MathMacro::getArgumentIdx() 
-{ 
-    return idx; 
-}
-
-inline
-int  MathMacro::getMaxArgumentIdx() 
-{ 
-    return nargs - 1; 
-} 
-
-
-inline
-LyxArrayBase * MathMacro::GetData() 
-{ 
-    return args[idx].array; 
-} 
-
-
-inline
-void MathMacro::SetData(LyxArrayBase * a)
-{
-   args[idx].array = a;
-}
-
-
-inline 
-MathMacro * MathMacroTable::getMacro(char const * name) const
-{
-       MathMacroTemplate * mt = getTemplate(name);
-       return (mt) ? new MathMacro(mt): 0;
-}
-
-
 #endif