*
* Dependencies: Xlib, XForms
*
- * Copyright: (c) 1996, 1997 Alejandro Aguilar Sierra
+ * Copyright: 1996, 1997 Alejandro Aguilar Sierra
*
* Version: 0.8beta, Mathed & Lyx project.
*
// Note: These math insets are internal to Mathed and are not derived
// from lyx inset.
-#ifndef __MATH_INSET__
-#define __MATH_INSET__
+#ifndef MATH_INSET
+#define MATH_INSET
#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:
///
- MathFuncInset(char const *nm, short ot=LM_OT_FUNC, short st=LM_ST_TEXT);
- ///
- ~MathFuncInset();
+ explicit
+ MathFuncInset(string const & nm,
+ short ot = LM_OT_FUNC, short st = LM_ST_TEXT);
///
- MathedInset *Clone();
+ ~MathFuncInset();
///
- void Draw(int, int);
+ MathedInset * Clone();
///
- void Write(FILE *file);
+ void draw(Painter &, int, int);
///
- void Write(LString &file);
+ void Write(std::ostream &, bool fragile);
///
- void Metrics();
+ void Metrics();
///
- inline bool GetLimits() const;
+ inline bool GetLimits() const;
protected:
///
- int ln;
+ int ln;
///
- bool lims;
+ bool lims;
///
- char *fname;
+ string fname;
};
/// Accents
class MathAccentInset: public MathedInset {
- public:
- ///
- MathAccentInset(byte, MathedTextCodes, int, short st=LM_ST_TEXT);
+public:
///
- MathAccentInset(MathedInset *, int, short st=LM_ST_TEXT);
+ MathAccentInset(byte, MathedTextCodes, int, short st = LM_ST_TEXT);
///
- ~MathAccentInset();
+ MathAccentInset(MathedInset *, int, short st = LM_ST_TEXT);
///
- MathedInset *Clone();
+ ~MathAccentInset();
///
- void Draw(int, int);
+ MathedInset * Clone();
///
- void Write(FILE *file);
+ void draw(Painter &, int, int);
///
- void Write(LString &file);
+ void Write(std::ostream &, bool fragile);
///
- void Metrics();
+ void Metrics();
///
- int getAccentCode() const { return code; }
-
- protected:
+ int getAccentCode() const { return code; }
+
+protected:
///
- byte c;
+ byte c;
///
- MathedTextCodes fn;
+ MathedTextCodes fn;
///
- int code;
+ int code;
///
- MathedInset *inset;
+ MathedInset * inset;
///
- int dh, dy;
+ int dh, dy;
};
///
class MathDotsInset: public MathedInset {
- public:
- ///
- MathDotsInset(char const*,int,short st=LM_ST_TEXT);
- ///
- ~MathDotsInset() { };
+public:
///
- MathedInset *Clone();
+ MathDotsInset(string const &, int, short st = LM_ST_TEXT);
///
- void Draw(int, int);
+ MathedInset * Clone();
///
- void Write(FILE *file);
+ void draw(Painter &, int, int);
///
- void Write(LString &file);
+ void Write(std::ostream &, bool fragile);
///
- void Metrics();
- protected:
+ void Metrics();
+protected:
///
- int dh, code;
+ int dh, code;
};
/// Smart spaces
class MathSpaceInset: public MathedInset {
- public:
- ///
- MathSpaceInset(int sp, short ot=LM_OT_SPACE, short st=LM_ST_TEXT);
- ///
- ~MathSpaceInset() { };
+public:
///
- MathedInset *Clone();
+ MathSpaceInset(int sp, short ot = LM_OT_SPACE, short st = LM_ST_TEXT);
///
- void Draw(int, int);
+ MathedInset * Clone();
///
- void Write(FILE *file);
+ void draw(Painter &, int, int);
///
- void Write(LString &file);
+ void Write(std::ostream &, bool fragile);
///
- inline void Metrics();
+ inline void Metrics();
///
- inline void SetSpace(int sp);
+ inline void SetSpace(int sp);
///
- int GetSpace() { return space; }
- protected:
+ int GetSpace() { return space; }
+protected:
///
- int space;
+ int space;
};
/// big operators
class MathBigopInset: public MathedInset {
- public:
- ///
- MathBigopInset(char const*, int, short st=LM_ST_TEXT);
- ///
- ~MathBigopInset() { };
+public:
///
- MathedInset *Clone();
+ MathBigopInset(string const &, int, short st = LM_ST_TEXT);
///
- void Draw(int, int);
+ MathedInset * Clone();
///
- void Write(FILE *file);
+ void draw(Painter &, int, int);
///
- void Write(LString &file);
+ void Write(std::ostream &, bool fragile);
///
- void Metrics();
+ void Metrics();
///
- inline bool GetLimits() const;
+ inline bool GetLimits() const;
///
- inline void SetLimits(bool);
- protected:
+ inline void SetLimits(bool);
+protected:
///
- int lims;
+ int lims;
///
- int sym;
+ int sym;
};
///
class MathSqrtInset: public MathParInset {
- public:
- ///
- MathSqrtInset(short st=LM_ST_TEXT);
- ///
- ~MathSqrtInset() { };
- ///
- MathedInset *Clone();
- ///
- void Draw(int x, int baseline);
- ///
- void Write(FILE *file);
- ///
- void Write(LString &file);
- ///
- void Metrics();
- ///
- bool Inside(int, int);
-
- private:
- ///
- int hmax, wbody;
+public:
+ ///
+ MathSqrtInset(short st = LM_ST_TEXT);
+ ///
+ MathedInset * Clone();
+ ///
+ void draw(Painter &, int x, int baseline);
+ ///
+ void Write(std::ostream &, bool fragile);
+ ///
+ void Metrics();
+ ///
+ bool Inside(int, int);
+private:
+ ///
+ int hmax, wbody;
};
/// Fraction like objects (frac, stackrel, binom)
class MathFracInset: public MathParInset {
- public:
+public:
///
- MathFracInset(short ot=LM_OT_FRAC);
+ MathFracInset(short ot = LM_OT_FRAC);
///
- ~MathFracInset();
+ ~MathFracInset();
///
- MathedInset *Clone();
+ MathedInset * Clone();
///
- void Draw(int x, int baseline);
+ void draw(Painter &, int x, int baseline);
///
- void Write(FILE *file);
+ void Write(std::ostream &, bool fragile);
///
- void Write(LString &file);
+ void Metrics();
+
+ /** This does the same that SetData(LyxArrayBase*) but for both
+ numerator and denominator at once.
+ */
+ void SetData(LyxArrayBase *, LyxArrayBase *);
///
- void Metrics();
-
- /** This does the same that SetData(LyxArrayBase*) but for both
- numerator and denominator at once.
- */
- void SetData(LyxArrayBase*, LyxArrayBase*);
+ void SetData(LyxArrayBase *);
+ ///
+ void GetXY(int & x, int & y) const;
///
- void SetData(LyxArrayBase*);
+ void SetFocus(int, int);
///
- void GetXY(int& x, int& y) const;
+ bool Inside(int, int);
///
- void SetFocus(int,int);
- ///
- bool Inside(int, int);
- ///
- LyxArrayBase * GetData();
- ///
- bool setArgumentIdx(int i); // was bool Up/down(void);
- ///
- int getArgumentIdx() { return (int)idx; }
- ///
- int getMaxArgumentIdx() { return 1; }
+ LyxArrayBase * GetData();
///
- void SetStyle(short);
- protected:
+ bool setArgumentIdx(int i); // was bool Up/down(void);
///
- short idx;
+ int getArgumentIdx() { return int(idx); }
///
- MathParInset *den;
+ int getMaxArgumentIdx() { return 1; }
+ ///
+ void SetStyle(short);
+protected:
///
- int w0, w1, des0, dh;
+ short idx;
+ ///
+ MathParInset * den;
+ ///
+ int w0, w1, des0, dh;
};
/// A delimiter
class MathDelimInset: public MathParInset {
- public:
- ///
- MathDelimInset(int, int, short st=LM_ST_TEXT);
- ///
- ~MathDelimInset() { };
+public:
///
- MathedInset *Clone();
+ MathDelimInset(int, int, short st = LM_ST_TEXT);
///
- void Draw(int, int);
+ MathedInset * Clone();
///
- void Write(FILE *file);
+ void draw(Painter &, int, int);
///
- void Write(LString &file);
+ void Write(std::ostream &, bool fragile);
///
- void Metrics();
- protected:
+ void Metrics();
+protected:
///
- int left, right;
+ int left, right;
///
- int dw, dh;
+ int dw, dh;
};
/// Decorations over (below) a math object
class MathDecorationInset: public MathParInset {
- public:
- ///
- MathDecorationInset(int, short st=LM_ST_TEXT);
- ///
- ~MathDecorationInset() { };
+public:
///
- MathedInset *Clone();
+ MathDecorationInset(int, short st = LM_ST_TEXT);
///
- void Draw(int, int);
+ MathedInset * Clone();
///
- void Write(FILE *file);
+ void draw(Painter &, int, int);
///
- void Write(LString &file);
+ void Write(std::ostream &, bool fragile);
///
- void Metrics();
+ void Metrics();
///
- inline bool GetLimits() const;
- protected:
+ inline bool GetLimits() const;
+protected:
///
- int deco;
+ int deco;
///
- bool upper;
+ bool upper;
///
- int dw, dh, dy;
+ int dw, dh, dy;
};
inline
MathFuncInset::~MathFuncInset()
-{
- if (fname && GetType()==LM_OT_UNDEF) delete[] fname;
-}
+{}
+
inline
bool MathFuncInset::GetLimits() const
{
- return (bool)(lims && (GetStyle()==LM_ST_DISPLAY));
+ return bool(lims && (GetStyle() == LM_ST_DISPLAY));
}
-inline
-void MathFuncInset::Write(FILE *file)
-{
- fprintf(file, "\\%s ", name);
-}
inline
-void MathFuncInset::Write(LString &file)
+void MathFuncInset::Write(std::ostream & os, bool /* fragile */)
{
- file += '\\';
- file += name;
- file += ' ';
+ os << "\\" << name << ' ';
}
+
inline
void MathSpaceInset::Metrics()
{
- width = (space) ? space*2: 2;
- if (space>3) width *= 2;
- if (space==5) width *= 2;
+ width = space ? space * 2 : 2;
+ if (space > 3) width *= 2;
+ if (space == 5) width *= 2;
width += 4;
ascent = 4; descent = 0;
}
+
inline
void MathSpaceInset::SetSpace(int sp)
{
Metrics();
}
+
inline
bool MathBigopInset::GetLimits() const
{
// Default case
- if (lims<0) {
- return (bool)(sym!=LM_int && sym!=LM_oint && (GetStyle()==LM_ST_DISPLAY));
+ if (lims < 0) {
+ return sym != LM_int && sym != LM_oint && GetStyle() == LM_ST_DISPLAY;
}
// Custom
- return (bool)(lims>0);
+ return lims > 0;
}
+
inline
void MathBigopInset::SetLimits(bool ls)
{
- lims = (ls) ? 1: 0;
+ lims = ls ? 1 : 0;
}
+
inline
bool MathDecorationInset::GetLimits() const
{
- return (bool)(deco==LM_underbrace||deco==LM_overbrace);
+ return deco == LM_underbrace || deco == LM_overbrace;
}
-
#endif
-