1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/*
|
|
|
|
* File: math_inset.h
|
|
|
|
* Purpose: Declaration of insets for mathed
|
|
|
|
* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
|
|
|
|
* Created: January 1996
|
|
|
|
* Description: Math paragraph and objects for a WYSIWYG math editor.
|
|
|
|
*
|
|
|
|
* Dependencies: Xlib, XForms
|
|
|
|
*
|
|
|
|
* Copyright: (c) 1996, 1997 Alejandro Aguilar Sierra
|
|
|
|
*
|
|
|
|
* Version: 0.8beta, Mathed & Lyx project.
|
|
|
|
*
|
|
|
|
* You are free to use and modify this code under the terms of
|
|
|
|
* the GNU General Public Licence version 2 or later.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Note: These math insets are internal to Mathed and are not derived
|
|
|
|
// from lyx inset.
|
|
|
|
|
1999-11-15 11:06:41 +00:00
|
|
|
#ifndef MATH_INSET
|
|
|
|
#define MATH_INSET
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "math_defs.h"
|
|
|
|
#include "symbol_def.h"
|
|
|
|
#include "LString.h"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Functions or LaTeX names for objects that I don't know how to draw.
|
|
|
|
*/
|
|
|
|
class MathFuncInset: public MathedInset {
|
|
|
|
public:
|
|
|
|
///
|
1999-11-24 22:14:46 +00:00
|
|
|
MathFuncInset(char const * nm,
|
|
|
|
short ot = LM_OT_FUNC, short st = LM_ST_TEXT);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
~MathFuncInset();
|
|
|
|
///
|
1999-11-24 22:14:46 +00:00
|
|
|
MathedInset * Clone();
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void Draw(int, int);
|
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
void Write(FILE * file);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
void Write(string & file);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void Metrics();
|
|
|
|
///
|
|
|
|
inline bool GetLimits() const;
|
|
|
|
protected:
|
|
|
|
///
|
|
|
|
int ln;
|
|
|
|
///
|
|
|
|
bool lims;
|
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
char * fname;
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Accents
|
|
|
|
class MathAccentInset: public MathedInset {
|
|
|
|
public:
|
|
|
|
///
|
1999-11-24 22:14:46 +00:00
|
|
|
MathAccentInset(byte, MathedTextCodes, int, short st = LM_ST_TEXT);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-24 22:14:46 +00:00
|
|
|
MathAccentInset(MathedInset *, int, short st = LM_ST_TEXT);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
~MathAccentInset();
|
|
|
|
///
|
1999-11-24 22:14:46 +00:00
|
|
|
MathedInset * Clone();
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void Draw(int, int);
|
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
void Write(FILE * file);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
void Write(string & file);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void Metrics();
|
|
|
|
///
|
|
|
|
int getAccentCode() const { return code; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
///
|
|
|
|
byte c;
|
|
|
|
///
|
|
|
|
MathedTextCodes fn;
|
|
|
|
///
|
|
|
|
int code;
|
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
MathedInset * inset;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
int dh, dy;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
class MathDotsInset: public MathedInset {
|
|
|
|
public:
|
|
|
|
///
|
1999-11-24 22:14:46 +00:00
|
|
|
MathDotsInset(char const *, int, short st = LM_ST_TEXT);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
~MathDotsInset() {}
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-24 22:14:46 +00:00
|
|
|
MathedInset * Clone();
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void Draw(int, int);
|
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
void Write(FILE * file);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-24 22:14:46 +00:00
|
|
|
void Write(string & file);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void Metrics();
|
|
|
|
protected:
|
|
|
|
///
|
|
|
|
int dh, code;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Smart spaces
|
|
|
|
class MathSpaceInset: public MathedInset {
|
|
|
|
public:
|
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
MathSpaceInset(int sp, short ot = LM_OT_SPACE, short st = LM_ST_TEXT);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
~MathSpaceInset() {}
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-24 22:14:46 +00:00
|
|
|
MathedInset * Clone();
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void Draw(int, int);
|
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
void Write(FILE * file);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
void Write(string & file);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
inline void Metrics();
|
|
|
|
///
|
|
|
|
inline void SetSpace(int sp);
|
|
|
|
///
|
|
|
|
int GetSpace() { return space; }
|
|
|
|
protected:
|
|
|
|
///
|
|
|
|
int space;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// big operators
|
|
|
|
class MathBigopInset: public MathedInset {
|
|
|
|
public:
|
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
MathBigopInset(char const *, int, short st = LM_ST_TEXT);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
~MathBigopInset() {}
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-24 22:14:46 +00:00
|
|
|
MathedInset * Clone();
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void Draw(int, int);
|
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
void Write(FILE * file);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
void Write(string & file);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void Metrics();
|
|
|
|
///
|
|
|
|
inline bool GetLimits() const;
|
|
|
|
///
|
|
|
|
inline void SetLimits(bool);
|
|
|
|
protected:
|
|
|
|
///
|
|
|
|
int lims;
|
|
|
|
///
|
|
|
|
int sym;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//------- All editable insets must be derived from MathParInset.
|
|
|
|
|
|
|
|
///
|
|
|
|
class MathSqrtInset: public MathParInset {
|
|
|
|
public:
|
|
|
|
///
|
1999-11-24 22:14:46 +00:00
|
|
|
MathSqrtInset(short st = LM_ST_TEXT);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
~MathSqrtInset() {}
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-24 22:14:46 +00:00
|
|
|
MathedInset * Clone();
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void Draw(int x, int baseline);
|
|
|
|
///
|
1999-11-24 22:14:46 +00:00
|
|
|
void Write(FILE * file);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-24 22:14:46 +00:00
|
|
|
void Write(string & file);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void Metrics();
|
|
|
|
///
|
|
|
|
bool Inside(int, int);
|
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
int hmax, wbody;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Fraction like objects (frac, stackrel, binom)
|
|
|
|
class MathFracInset: public MathParInset {
|
|
|
|
public:
|
|
|
|
///
|
1999-11-24 22:14:46 +00:00
|
|
|
MathFracInset(short ot = LM_OT_FRAC);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
~MathFracInset();
|
|
|
|
///
|
1999-11-24 22:14:46 +00:00
|
|
|
MathedInset * Clone();
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void Draw(int x, int baseline);
|
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
void Write(FILE * file);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
void Write(string & file);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void Metrics();
|
|
|
|
|
|
|
|
/** This does the same that SetData(LyxArrayBase*) but for both
|
|
|
|
numerator and denominator at once.
|
|
|
|
*/
|
1999-11-23 14:39:02 +00:00
|
|
|
void SetData(LyxArrayBase *, LyxArrayBase *);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
void SetData(LyxArrayBase *);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
void GetXY(int & x, int & y) const;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-15 11:06:41 +00:00
|
|
|
void SetFocus(int, int);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
bool Inside(int, int);
|
|
|
|
///
|
|
|
|
LyxArrayBase * GetData();
|
|
|
|
///
|
|
|
|
bool setArgumentIdx(int i); // was bool Up/down(void);
|
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
int getArgumentIdx() { return int(idx); }
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
int getMaxArgumentIdx() { return 1; }
|
|
|
|
///
|
|
|
|
void SetStyle(short);
|
|
|
|
protected:
|
|
|
|
///
|
|
|
|
short idx;
|
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
MathParInset * den;
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
int w0, w1, des0, dh;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// A delimiter
|
|
|
|
class MathDelimInset: public MathParInset {
|
|
|
|
public:
|
|
|
|
///
|
1999-11-24 22:14:46 +00:00
|
|
|
MathDelimInset(int, int, short st = LM_ST_TEXT);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
~MathDelimInset() {}
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-24 22:14:46 +00:00
|
|
|
MathedInset * Clone();
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void Draw(int, int);
|
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
void Write(FILE * file);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
void Write(string & file);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void Metrics();
|
|
|
|
protected:
|
|
|
|
///
|
|
|
|
int left, right;
|
|
|
|
///
|
|
|
|
int dw, dh;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// Decorations over (below) a math object
|
|
|
|
class MathDecorationInset: public MathParInset {
|
|
|
|
public:
|
|
|
|
///
|
1999-11-24 22:14:46 +00:00
|
|
|
MathDecorationInset(int, short st = LM_ST_TEXT);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
~MathDecorationInset() {}
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-24 22:14:46 +00:00
|
|
|
MathedInset * Clone();
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void Draw(int, int);
|
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
void Write(FILE * file);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
1999-11-23 14:39:02 +00:00
|
|
|
void Write(string & file);
|
1999-09-27 18:44:28 +00:00
|
|
|
///
|
|
|
|
void Metrics();
|
|
|
|
///
|
|
|
|
inline bool GetLimits() const;
|
|
|
|
protected:
|
|
|
|
///
|
|
|
|
int deco;
|
|
|
|
///
|
|
|
|
bool upper;
|
|
|
|
///
|
|
|
|
int dw, dh, dy;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------- Inline functions ---------------------
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
MathFuncInset::~MathFuncInset()
|
|
|
|
{
|
1999-11-15 11:06:41 +00:00
|
|
|
if (fname && GetType() == LM_OT_UNDEF) delete[] fname;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
inline
|
|
|
|
bool MathFuncInset::GetLimits() const
|
|
|
|
{
|
1999-11-23 14:39:02 +00:00
|
|
|
return bool(lims && (GetStyle() == LM_ST_DISPLAY));
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
inline
|
1999-11-23 14:39:02 +00:00
|
|
|
void MathFuncInset::Write(FILE * file)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
fprintf(file, "\\%s ", name);
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
inline
|
1999-11-23 14:39:02 +00:00
|
|
|
void MathFuncInset::Write(string & file)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
file += '\\';
|
|
|
|
file += name;
|
|
|
|
file += ' ';
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
inline
|
|
|
|
void MathSpaceInset::Metrics()
|
|
|
|
{
|
1999-11-23 14:39:02 +00:00
|
|
|
width = (space) ? space * 2 : 2;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (space>3) width *= 2;
|
1999-11-15 11:06:41 +00:00
|
|
|
if (space == 5) width *= 2;
|
1999-09-27 18:44:28 +00:00
|
|
|
width += 4;
|
|
|
|
ascent = 4; descent = 0;
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
inline
|
|
|
|
void MathSpaceInset::SetSpace(int sp)
|
|
|
|
{
|
|
|
|
space = sp;
|
|
|
|
Metrics();
|
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
inline
|
|
|
|
bool MathBigopInset::GetLimits() const
|
|
|
|
{
|
|
|
|
// Default case
|
1999-11-23 14:39:02 +00:00
|
|
|
if (lims < 0) {
|
|
|
|
return sym != LM_int && sym != LM_oint && GetStyle() == LM_ST_DISPLAY;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Custom
|
1999-11-23 14:39:02 +00:00
|
|
|
return lims > 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
inline
|
|
|
|
void MathBigopInset::SetLimits(bool ls)
|
|
|
|
{
|
1999-11-23 14:39:02 +00:00
|
|
|
lims = ls ? 1 : 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
inline
|
|
|
|
bool MathDecorationInset::GetLimits() const
|
|
|
|
{
|
1999-11-23 14:39:02 +00:00
|
|
|
return deco == LM_underbrace || deco == LM_overbrace;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|