// -*- C++ -*-
-/*
- * File: math_macro.h
- * Purpose: Declaration of macro class for mathed
- * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
- * Created: November 1996
- * Description: WYSIWYG math macros
+/**
+ * \file math_macro.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * Dependencies: Mathed
+ * \author Alejandro Aguilar Sierra
+ * \author André Pönitz
*
- * Copyright: (c) 1996, 1997 Alejandro Aguilar Sierra
- *
- * Version: 0.2, Mathed & Lyx project.
- *
- * This code is under the GNU General Public Licence version 2 or later.
+ * Full author contact details are available in file CREDITS.
*/
-#ifndef MATH_MACRO
-#define MATH_MACRO
-#ifdef __GNUG__
-#pragma interface
-#endif
+#ifndef MATH_MACRO_H
+#define MATH_MACRO_H
-#include "math_defs.h"
-#include "debug.h"
+#include "math_data.h"
+#include "math_nestinset.h"
+#include "metricsinfo.h"
-///
-typedef MathParInset* MathParInsetP;
-///
-typedef LyxArrayBase *LyxArrayBaseP;
class MathMacroTemplate;
-/// This class contains the data for a macro
-class MathMacro: public MathParInset
-{
- public:
- /// A macro can only be builded from an existing template
- MathMacro(MathMacroTemplate *);
- /// or from another macro.
- MathMacro(MathMacro*);
- ///
- ~MathMacro();
- ///
- void Draw(int, int);
- ///
- void Metrics();
- ///
- MathedInset *Clone();
- ///
- void Write(FILE *);
- ///
- void Write(string &);
- ///
- bool setArgumentIdx(int);
- ///
- int getArgumentIdx();
- ///
- int getMaxArgumentIdx();
+/// This class contains the data for a macro.
+class MathMacro : public MathNestInset {
+public:
+ /// A macro can be built from an existing template
+ explicit MathMacro(std::string const &);
///
- int GetColumns();
+ MathMacro(MathMacro const &);
///
- void GetXY(int&, int&) const;
+ void draw(PainterInfo & pi, int x, int y) const;
///
- void SetFocus(int, int);
+ void metrics(MetricsInfo & mi, Dimension & dim) const;
///
- LyxArrayBase *GetData();
+ virtual std::auto_ptr<InsetBase> clone() const;
///
- MathedRowSt *getRowSt() const { return args[idx].row; }
- ///
- void SetData(LyxArrayBase *);
- ///
- MathedTextCodes getTCode() { return tcode; }
- ///
- 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; }
- } *args;
- ///
- int idx;
- ///
- int nargs;
- ///
- MathedTextCodes tcode;
- ///
- friend class MathMacroTemplate;
-};
-
+ void dump() 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!" << endl; }
- ///
- MathedInset *Clone() { return this; }
///
- void Metrics();
+ bool idxUpDown(LCursor & cur, bool up) const;
///
- void Draw(int x, int baseline);
+ bool idxLeft(LCursor & cur) const;
///
- void Write(FILE*);
- ///
- void Write(string &);
- ///
- 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 idxRight(LCursor & cur) const;
+
///
- bool expnd_mode;
+ void validate(LaTeXFeatures &) const;
///
- int number;
-};
+ bool isMacro() const { return true; }
-
-/// 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 Draw(int, int);
+ void maple(MapleStream &) const;
///
- void Metrics();
+ void mathmlize(MathMLStream &) const;
///
- void WriteDef(FILE *);
+ void octave(OctaveStream &) const;
///
- void WriteDef(string &);
- /// 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 infoize(std::ostream &) const;
///
- void setEditMode(bool);
-
- /// 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;
+ void infoize2(std::ostream &) const;
-///
-class MathMacroTable
-{
- public:
- ///
- MathMacroTable(int);
+private:
///
- ~MathMacroTable();
+ void operator=(MathMacro const &);
///
- void addTemplate(MathMacroTemplate *);
+ std::string name() const;
///
- MathMacro *getMacro(char const*) const;
+ bool defining() const;
///
- MathMacroTemplate *getTemplate(char const*) const;
+ void updateExpansion() const;
///
- void builtinMacros();
- ///
- static MathMacroTable mathMTable;
+ void expand() const;
+
///
- static bool built;
-
- private:
+ MathAtom & tmplate_;
///
- const int max_macros;
+ mutable MathArray expanded_;
///
- int num_macros;
+ mutable MetricsInfo mi_;
///
- 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