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
|
|
|
|
*
|
2000-03-09 03:36:48 +00:00
|
|
|
* Copyright: 1996, 1997 Alejandro Aguilar Sierra
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
///
|
2001-02-12 08:55:14 +00:00
|
|
|
typedef MathedArray * MathedArrayP;
|
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
|
|
|
{
|
2000-03-07 01:14:37 +00:00
|
|
|
public:
|
1999-09-27 18:44:28 +00:00
|
|
|
/// A macro can only be builded from an existing template
|
2000-07-04 19:16:35 +00:00
|
|
|
explicit
|
1999-09-27 18:44:28 +00:00
|
|
|
MathMacro(MathMacroTemplate *);
|
|
|
|
/// or from another macro.
|
2000-07-04 19:16:35 +00:00
|
|
|
explicit
|
1999-12-07 00:44:53 +00:00
|
|
|
MathMacro(MathMacro *);
|
2000-07-04 19:16:35 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
~MathMacro();
|
2000-02-17 19:59:08 +00:00
|
|
|
///
|
|
|
|
void draw(Painter &, int, int);
|
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
void Metrics();
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
1999-11-25 13:15:52 +00:00
|
|
|
MathedInset * Clone();
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-04-19 01:42:55 +00:00
|
|
|
void Write(std::ostream &, bool fragile);
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
bool setArgumentIdx(int);
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-09-29 18:44:07 +00:00
|
|
|
int getArgumentIdx() const;
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-09-29 18:44:07 +00:00
|
|
|
int getMaxArgumentIdx() const;
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-09-29 18:44:07 +00:00
|
|
|
int GetColumns() const;
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
1999-12-07 00:44:53 +00:00
|
|
|
void GetXY(int &, int &) const;
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
void SetFocus(int, int);
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2001-02-12 08:55:14 +00:00
|
|
|
MathedArray * GetData();
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2001-02-12 15:55:40 +00:00
|
|
|
MathedRowSt * getRowSt() const { return args_[idx].row; }
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2001-02-12 08:55:14 +00:00
|
|
|
void SetData(MathedArray *);
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-09-29 18:44:07 +00:00
|
|
|
MathedTextCodes getTCode() const { return tcode; }
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2001-02-12 15:55:40 +00:00
|
|
|
bool Permit(short) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-03-07 01:14:37 +00:00
|
|
|
private:
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
|
|
|
MathMacroTemplate * tmplate;
|
|
|
|
///
|
|
|
|
struct MacroArgumentBase {
|
|
|
|
/// Position of the macro
|
|
|
|
int x, y;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-08-07 20:58:24 +00:00
|
|
|
MathedRowSt * row;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2001-02-12 08:55:14 +00:00
|
|
|
MathedArray * array;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-08-07 20:58:24 +00:00
|
|
|
MacroArgumentBase() { x = y = 0; array = 0; row = 0; }
|
|
|
|
};
|
2001-02-12 15:55:40 +00:00
|
|
|
std::vector<MacroArgumentBase> args_;
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
|
|
|
int idx;
|
|
|
|
///
|
|
|
|
int nargs;
|
|
|
|
///
|
|
|
|
MathedTextCodes tcode;
|
|
|
|
///
|
|
|
|
friend class MathMacroTemplate;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// An argument
|
2000-03-07 01:14:37 +00:00
|
|
|
class MathMacroArgument: public MathParInset {
|
|
|
|
public:
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-07-04 19:16:35 +00:00
|
|
|
MathMacroArgument() {
|
|
|
|
expnd_mode = false;
|
|
|
|
number = 1;
|
|
|
|
SetType(LM_OT_MACRO_ARG);
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2000-07-04 19:16:35 +00:00
|
|
|
explicit
|
1999-09-27 18:44:28 +00:00
|
|
|
MathMacroArgument(int);
|
|
|
|
///
|
2000-07-04 19:16:35 +00:00
|
|
|
~MathMacroArgument() { lyxerr << "help, destroyme!" << std::endl; }
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-25 13:15:52 +00:00
|
|
|
MathedInset * Clone() { return this; }
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
void Metrics();
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-02-17 19:59:08 +00:00
|
|
|
void draw(Painter &, int x, int baseline);
|
2000-08-07 20:58:24 +00:00
|
|
|
///
|
2000-04-19 01:42:55 +00:00
|
|
|
void Write(std::ostream &, bool fragile);
|
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
|
2000-09-29 18:44:07 +00:00
|
|
|
bool getExpand() const { return expnd_mode; }
|
2000-03-07 01:14:37 +00:00
|
|
|
private:
|
2000-07-04 19:16:35 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
bool expnd_mode;
|
2000-07-04 19:16:35 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
int number;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// This class contains the macro definition
|
2000-03-07 01:14:37 +00:00
|
|
|
class MathMacroTemplate: public MathParInset {
|
|
|
|
public:
|
1999-09-27 18:44:28 +00:00
|
|
|
/// A template constructor needs all the data
|
2000-07-04 19:16:35 +00:00
|
|
|
explicit
|
2000-09-26 13:54:57 +00:00
|
|
|
MathMacroTemplate(string const &, int na = 0, int f = 0);
|
2000-07-04 19:16:35 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
~MathMacroTemplate();
|
2000-07-04 19:16:35 +00:00
|
|
|
///
|
2000-02-17 19:59:08 +00:00
|
|
|
void draw(Painter &, int, int);
|
2000-07-04 19:16:35 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
void Metrics();
|
2000-07-04 19:16:35 +00:00
|
|
|
///
|
2000-04-19 01:42:55 +00:00
|
|
|
void WriteDef(std::ostream &, bool fragile);
|
1999-09-27 18:44:28 +00:00
|
|
|
/// useful for special insets
|
|
|
|
void setTCode(MathedTextCodes t) { tcode = t; }
|
|
|
|
///
|
2000-09-29 18:44:07 +00:00
|
|
|
MathedTextCodes getTCode() const { return tcode; }
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
2001-02-12 08:55:14 +00:00
|
|
|
void setArgument(MathedArray *, int i= 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
/// Number of arguments
|
2000-09-29 18:44:07 +00:00
|
|
|
int getNoArgs() const { return nargs; }
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
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);
|
2000-07-04 19:16:35 +00:00
|
|
|
///
|
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
|
|
|
|
2000-03-07 01:14:37 +00:00
|
|
|
private:
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
short flags;
|
|
|
|
///
|
|
|
|
MathedTextCodes tcode;
|
|
|
|
///
|
2001-02-12 15:55:40 +00:00
|
|
|
std::vector<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
|
|
|
|
|
|
|
///
|
2000-03-07 01:14:37 +00:00
|
|
|
class MathMacroTable {
|
|
|
|
public:
|
2000-07-04 19:16:35 +00:00
|
|
|
///
|
|
|
|
explicit
|
1999-09-27 18:44:28 +00:00
|
|
|
MathMacroTable(int);
|
2000-07-04 19:16:35 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
~MathMacroTable();
|
2000-07-04 19:16:35 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
void addTemplate(MathMacroTemplate *);
|
2000-07-04 19:16:35 +00:00
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
MathMacro * getMacro(string const &) const;
|
2000-07-04 19:16:35 +00:00
|
|
|
///
|
2000-09-14 17:53:12 +00:00
|
|
|
MathMacroTemplate * getTemplate(string const &) const;
|
2000-07-04 19:16:35 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
void builtinMacros();
|
2000-07-04 19:16:35 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
static MathMacroTable mathMTable;
|
2000-07-04 19:16:35 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
static bool built;
|
|
|
|
|
2000-03-07 01:14:37 +00:00
|
|
|
private:
|
2000-07-04 19:16:35 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
const int max_macros;
|
2000-07-04 19:16:35 +00:00
|
|
|
///
|
1999-09-27 18:44:28 +00:00
|
|
|
int num_macros;
|
2000-07-04 19:16:35 +00:00
|
|
|
///
|
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
|
2000-09-29 18:44:07 +00:00
|
|
|
int MathMacro::getArgumentIdx() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2000-09-29 18:44:07 +00:00
|
|
|
int MathMacro::getMaxArgumentIdx() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
return nargs - 1;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
2001-02-12 08:55:14 +00:00
|
|
|
MathedArray * MathMacro::GetData()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-12 15:55:40 +00:00
|
|
|
return args_[idx].array;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
2001-02-12 08:55:14 +00:00
|
|
|
void MathMacro::SetData(MathedArray * a)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-12 15:55:40 +00:00
|
|
|
args_[idx].array = a;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
2000-09-14 17:53:12 +00:00
|
|
|
MathMacro * MathMacroTable::getMacro(string const & name) const
|
2000-03-07 01:14:37 +00:00
|
|
|
{
|
|
|
|
MathMacroTemplate * mt = getTemplate(name);
|
|
|
|
return (mt) ? new MathMacro(mt): 0;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
#endif
|