1999-09-27 18:44:28 +00:00
|
|
|
// -*- 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
|
|
|
|
*
|
|
|
|
* Dependencies: Mathed
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
1999-10-07 18:44:17 +00:00
|
|
|
#ifndef MATH_MACRO
|
|
|
|
#define MATH_MACRO
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "math_defs.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
typedef MathParInset * MathParInsetP;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
typedef LyxArrayBase * LyxArrayBaseP;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
class MathMacroTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
/// This class contains the data for a macro
|
1999-12-07 00:44:53 +00:00
|
|
|
class MathMacro : public MathParInset
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// A macro can only be builded from an existing template
|
|
|
|
MathMacro(MathMacroTemplate *);
|
|
|
|
/// or from another macro.
|
1999-12-07 00:44:53 +00:00
|
|
|
MathMacro(MathMacro *);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
~MathMacro();
|
|
|
|
///
|
|
|
|
void Draw(int, int);
|
|
|
|
///
|
|
|
|
void Metrics();
|
|
|
|
///
|
1999-11-25 13:15:52 +00:00
|
|
|
MathedInset * Clone();
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
void Write(ostream &);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-10-02 16:21:10 +00:00
|
|
|
void Write(string &);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
bool setArgumentIdx(int);
|
|
|
|
///
|
|
|
|
int getArgumentIdx();
|
|
|
|
///
|
|
|
|
int getMaxArgumentIdx();
|
|
|
|
///
|
|
|
|
int GetColumns();
|
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
void GetXY(int &, int &) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void SetFocus(int, int);
|
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
LyxArrayBase * GetData();
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
MathedRowSt * getRowSt() const { return args[idx].row; }
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void SetData(LyxArrayBase *);
|
|
|
|
///
|
|
|
|
MathedTextCodes getTCode() { return tcode; }
|
|
|
|
///
|
|
|
|
bool Permit(short);
|
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
MathMacroTemplate * tmplate;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
struct MacroArgumentBase {
|
|
|
|
/// Position of the macro
|
|
|
|
int x, y;
|
|
|
|
///
|
|
|
|
MathedRowSt * row;
|
|
|
|
///
|
|
|
|
LyxArrayBase * array;
|
|
|
|
///
|
|
|
|
MacroArgumentBase() { x = y = 0; array = 0; row = 0; }
|
|
|
|
};
|
|
|
|
MacroArgumentBase * args;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
int idx;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
int nargs;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
MathedTextCodes tcode;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
friend class MathMacroTemplate;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// An argument
|
|
|
|
class MathMacroArgument: public MathParInset
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
MathMacroArgument() { expnd_mode = false; number = 1; SetType(LM_OT_MACRO_ARG); }
|
|
|
|
///
|
|
|
|
MathMacroArgument(int);
|
|
|
|
///
|
1999-10-07 18:44:17 +00:00
|
|
|
~MathMacroArgument() { lyxerr << "help, destroyme!" << endl; }
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-25 13:15:52 +00:00
|
|
|
MathedInset * Clone() { return this; }
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void Metrics();
|
|
|
|
///
|
|
|
|
void Draw(int x, int baseline);
|
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
void Write(ostream &);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-10-02 16:21:10 +00:00
|
|
|
void Write(string &);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
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 expnd_mode;
|
|
|
|
///
|
|
|
|
int number;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// This class contains the macro definition
|
|
|
|
class MathMacroTemplate: public MathParInset
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// A template constructor needs all the data
|
1999-12-07 00:44:53 +00:00
|
|
|
MathMacroTemplate(char const *, int na = 0, int f = 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
~MathMacroTemplate();
|
|
|
|
///
|
|
|
|
void Draw(int, int);
|
|
|
|
///
|
|
|
|
void Metrics();
|
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
void WriteDef(ostream &);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-10-02 16:21:10 +00:00
|
|
|
void WriteDef(string &);
|
1999-09-27 18:44:28 +00:00
|
|
|
/// useful for special insets
|
|
|
|
void setTCode(MathedTextCodes t) { tcode = t; }
|
|
|
|
///
|
|
|
|
MathedTextCodes getTCode() { return tcode; }
|
|
|
|
///
|
1999-11-15 11:06:41 +00:00
|
|
|
void setArgument(LyxArrayBase *, int i= 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
/// Number of arguments
|
|
|
|
int getNoArgs() { return nargs; }
|
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
void GetMacroXY(int, int &, int &) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
MathParInset * getMacroPar(int) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
void SetMacroFocus(int &, int, int);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void setEditMode(bool);
|
|
|
|
|
|
|
|
/// Replace the appropriate arguments with a specific macro's data
|
1999-12-07 00:44:53 +00:00
|
|
|
void update(MathMacro * m = 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
short flags;
|
|
|
|
///
|
|
|
|
MathedTextCodes tcode;
|
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
MathMacroArgument * args;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
int nargs;
|
|
|
|
///
|
|
|
|
friend class MathMacro;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
typedef MathMacro * MathMacroP;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
typedef MathMacroTemplate * MathMacroTemplateP;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
class MathMacroTable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
MathMacroTable(int);
|
|
|
|
///
|
|
|
|
~MathMacroTable();
|
|
|
|
///
|
|
|
|
void addTemplate(MathMacroTemplate *);
|
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
MathMacro * getMacro(char const *) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
MathMacroTemplate * getTemplate(char const *) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void builtinMacros();
|
|
|
|
///
|
|
|
|
static MathMacroTable mathMTable;
|
|
|
|
///
|
|
|
|
static bool built;
|
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
const int max_macros;
|
|
|
|
///
|
|
|
|
int num_macros;
|
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
MathMacroTemplateP * macro_table;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*----------------------- inlines -------------------------*/
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool MathMacro::setArgumentIdx(int i)
|
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
if (i >= 0 && i < nargs) {
|
1999-09-27 18:44:28 +00:00
|
|
|
idx = i;
|
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int MathMacro::getArgumentIdx()
|
|
|
|
{
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int MathMacro::getMaxArgumentIdx()
|
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
return nargs - 1;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
1999-12-07 00:44:53 +00:00
|
|
|
LyxArrayBase * MathMacro::GetData()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return args[idx].array;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
1999-12-07 00:44:53 +00:00
|
|
|
void MathMacro::SetData(LyxArrayBase * a)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
args[idx].array = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
1999-12-07 00:44:53 +00:00
|
|
|
MathMacro * MathMacroTable::getMacro(char const * name) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
MathMacroTemplate * mt = getTemplate(name);
|
1999-09-27 18:44:28 +00:00
|
|
|
return (mt) ? new MathMacro(mt): 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|