]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_inset.h
small cleanup, doxygen, formatting changes
[lyx.git] / src / mathed / math_inset.h
index 6497d698edd0bdf9e3feb42d9dd57eddccdc95ad..dd1cb92e0f6e6bdefd4db540365d7188974b7c52 100644 (file)
@@ -8,7 +8,7 @@
  *
  *  Dependencies: Xlib, XForms
  *
- *  Copyright: (c) 1996, 1997 Alejandro Aguilar Sierra
+ *  Copyright: 1996, 1997 Alejandro Aguilar Sierra
  *
  *   Version: 0.8beta, Mathed & Lyx project.
  *
 #pragma interface
 #endif
 
-#include <stdio.h>
-#include "math_defs.h"
-#include "symbol_def.h"
 #include "LString.h"
+#include "symbol_def.h"
 
+class Painter;
 
-/**
- 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();
-       ///
-   MathedInset *Clone();
-       ///
-   void Draw(int, int);
-       ///
-   void Write(FILE *file);
-       ///
-   void Write(string &file);
-       ///
-   void Metrics();
-       ///
-   inline bool GetLimits() const;
-protected:
-       ///
-   int ln;
-       ///
-   bool lims;
-       ///
-   char *fname;
-};
-
-
-/// Accents
-class MathAccentInset: public MathedInset {
- public:
-       ///
-   MathAccentInset(byte, MathedTextCodes, int, short st= LM_ST_TEXT);
-       ///
-   MathAccentInset(MathedInset *, int, short st= LM_ST_TEXT);
-       ///
-   ~MathAccentInset();
-       ///
-   MathedInset *Clone();
-       ///
-   void Draw(int, int);
-       ///
-   void Write(FILE *file);
-       ///
-   void Write(string &file);
-       ///
-   void Metrics();
-       ///
-   int getAccentCode() const { return code; }
-
- protected:
-       ///
-   byte c;
-       ///
-   MathedTextCodes fn;
-       ///
-   int code;
-       ///
-   MathedInset *inset;
-       ///
-   int dh, dy;
-};
-
-
-///
-class MathDotsInset: public MathedInset {
- public:
-       ///
-   MathDotsInset(char const*, int, short st= LM_ST_TEXT);
-       ///
-   ~MathDotsInset() { };
-       ///
-   MathedInset *Clone();
-       ///
-   void Draw(int, int);
-       ///
-   void Write(FILE *file);
-       ///
-   void Write(string &file);
-       ///
-   void Metrics();
- protected:
-       ///
-   int dh, code;
-};   
-
-
-/// Smart spaces
-class MathSpaceInset: public MathedInset  {
- public:
-       ///
-   MathSpaceInset(int sp, short ot= LM_OT_SPACE, short st= LM_ST_TEXT);
-       ///
-   ~MathSpaceInset() { };
-       ///
-   MathedInset *Clone();
-       ///
-  void Draw(int, int);
-       ///
-   void Write(FILE *file);
-       ///
-   void Write(string &file);
-       ///
-   inline void Metrics();
-       ///
-   inline void SetSpace(int sp);
-       ///
-   int GetSpace() { return space; }
- protected:
-       ///
-   int space;
-};
-
-
-/// big operators
-class MathBigopInset: public MathedInset {
- public:
-       ///
-   MathBigopInset(char const*, int, short st= LM_ST_TEXT);
-       ///
-   ~MathBigopInset() { };
-       ///
-   MathedInset *Clone();
-       ///
-   void Draw(int, int);
-       ///
-   void Write(FILE *file);
-       ///
-   void Write(string &file);
-       ///
-   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:
-    ///
-    MathSqrtInset(short st= LM_ST_TEXT);
-    ///
-    ~MathSqrtInset() { };
-    ///
-    MathedInset *Clone();
-    ///
-    void Draw(int x, int baseline);
-    ///
-    void Write(FILE *file);
-    ///
-    void Write(string &file);
-    ///
-    void Metrics();
-    ///
-    bool Inside(int, int);
-    
- private:
-    ///
-   int hmax, wbody;
-};
-
-
-/// Fraction like objects (frac, stackrel, binom) 
-class MathFracInset: public MathParInset {
- public:
-       ///
-    MathFracInset(short ot= LM_OT_FRAC);
-       ///
-    ~MathFracInset();
+/** Abstract base class for all math objects.
+    A math insets is for use of the math editor only, it isn't a
+    general LyX inset. It's used to represent all the math objects.
+    The formulaInset (a LyX inset) encapsulates a math inset.
+*/
+class MathedInset  {
+public: 
+       /** A math inset has a name (usually its LaTeX name),
+           type and font-size
+       */
+       MathedInset(string const & nm, short ot, short st);
        ///
-    MathedInset *Clone();
+       explicit
+       MathedInset(MathedInset *);
        ///
-    void Draw(int x, int baseline);
+       virtual ~MathedInset() {}
+       /// Draw the object
+       virtual void draw(Painter &, int x, int baseline) = 0;  
+       /// Write LaTeX and Lyx code
+       virtual void Write(std::ostream &, bool fragile) = 0;
+       /// Reproduces itself
+       virtual MathedInset * Clone() = 0;
+       /// Compute the size of the object
+       virtual void Metrics() = 0; 
+       /// 
+       virtual int Ascent() const;
        ///
-    void Write(FILE *file);
+       virtual int Descent() const;
        ///
-    void Write(string &file);
+       virtual int Width() const;
        ///
-    void Metrics();
-    /** This does the same that SetData(LyxArrayBase*) but for both
-         numerator and denominator at once.
-     */
-    void SetData(LyxArrayBase*, LyxArrayBase*);
+       virtual int Height() const;
        ///
-    void SetData(LyxArrayBase*);
+       virtual bool GetLimits() const;
        ///
-    void GetXY(int& x, int& y) const;
+       virtual void SetLimits(bool);
        ///
-    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; }
+       string const & GetName() const;
        ///
-    void  SetStyle(short);
- protected:
+       short GetType() const;
        ///
-    short idx;
+       short GetStyle() const;
+       //Man:  Avoid to use these functions if it's not strictly necessary 
        ///
-    MathParInset *den;
+       virtual void  SetType(short t);
        ///
-    int w0, w1, des0, dh;
-};
-
-
-/// A delimiter
-class MathDelimInset: public MathParInset {
- public:
-       ///
-   MathDelimInset(int, int, short st= LM_ST_TEXT);
+       virtual void  SetStyle(short st);
        ///
-   ~MathDelimInset() { };
+       virtual void  SetName(string const & n);
        ///
-   MathedInset *Clone();
+       static int workWidth;
        ///
-   void Draw(int, int);
+       static void defaultAscent(int da);
        ///
-   void Write(FILE *file);
+       static void defaultDescent(int dd);
        ///
-   void Write(string &file);
+       static void defaultWidth(int dw);
        ///
-   void Metrics();
- protected:
-       ///
-   int left, right;
-       ///
-   int dw, dh;
-};
-
-
-/// Decorations over (below) a math object
-class MathDecorationInset: public MathParInset {
- public:
-       ///
-   MathDecorationInset(int, short st= LM_ST_TEXT);
-       ///
-   ~MathDecorationInset() { };
+       short size() const {
+               return size_;
+       }
+protected:
        ///
-   MathedInset *Clone();
+       string name;
        ///
-   void Draw(int, int);
+       short objtype;
        ///
-   void Write(FILE *file);
+       int width;
        ///
-   void Write(string &file);
+       int ascent;
        ///
-   void Metrics();
+       int descent;
+       /// Default metrics
+       static int df_asc;
        ///
-   inline bool GetLimits() const;
- protected:
+       static int df_des;
        ///
-   int deco;
+       static int df_width;
+       /// In a near future maybe we use a better fonts renderer than X
+       void drawStr(Painter &, short, int, int, int, string const &);
        ///
-   bool upper;
+       void size(short s) {
+               size_ = s;
+       }
+       void incSize() {
+               ++size_;
+       }
+private:
        ///
-   int dw, dh, dy;
+       short size_;
 };
-
-
-// --------------------  Inline functions ---------------------
-
-inline
-MathFuncInset::~MathFuncInset()
-{
-    if (fname && GetType() == LM_OT_UNDEF) delete[] fname;
-}
-
-inline
-bool MathFuncInset::GetLimits() const 
-{  
-   return (bool)(lims && (GetStyle() == LM_ST_DISPLAY)); 
-} 
-
-inline
-void MathFuncInset::Write(FILE *file)
-{
-   fprintf(file, "\\%s ", name);
-}
-
-inline
-void MathFuncInset::Write(string &file)
-{
-   file += '\\';
-   file += name;
-   file += ' ';
-}
-
-inline
-void MathSpaceInset::Metrics()
-{
-   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)
-{ 
-   space = sp;
-   Metrics();
-}    
-
-inline
-bool MathBigopInset::GetLimits() const 
-{  
-    // Default case
-    if (lims<0) {
-       return (bool)(sym!= LM_int && sym!= LM_oint && (GetStyle() == LM_ST_DISPLAY));
-    } 
-    
-    // Custom 
-    return (bool)(lims>0);
-} 
-
-inline
-void MathBigopInset::SetLimits(bool ls) 
-{  
-    lims = (ls) ? 1: 0; 
-} 
-
-inline
-bool MathDecorationInset::GetLimits() const
-{ 
-   return (bool)(deco == LM_underbrace||deco == LM_overbrace);
-}    
-
-
 #endif
-