]> git.lyx.org Git - lyx.git/blob - src/mathed/math_parinset.h
first go at mathed file cleanup
[lyx.git] / src / mathed / math_parinset.h
1 // -*- C++ -*-
2 #ifndef MATH_PARINSET_H
3 #define MATH_PARINSET_H
4
5 #include "math_inset.h"
6
7 struct MathedRowSt;
8
9
10 /** The math paragraph base class, base to all editable math objects */
11 class MathParInset: public MathedInset  {
12  public: 
13     ///
14     MathParInset(short st = LM_ST_TEXT, string const & nm = string(),
15                  short ot = LM_OT_MIN);
16     ///
17     explicit
18     MathParInset(MathParInset *);
19     ///
20     virtual ~MathParInset();
21     ///
22     virtual MathedInset * Clone();
23     /// Draw the object on a drawable
24     virtual void draw(Painter &, int x, int baseline);
25     /// Write LaTeX code
26     virtual void Write(std::ostream &, bool fragile);
27     ///
28     virtual void Metrics();
29     ///
30     virtual void UserSetSize(short);
31     /// Data is stored in a LyXArray
32     virtual void SetData(MathedArray *);
33     ///
34     virtual MathedArray * GetData() { return array; }
35     /// Paragraph position
36     virtual void GetXY(int &, int &) const;
37     ///
38     virtual void setXY(int x, int y) { xo = x;  yo = y; }
39     ///
40     virtual void SetFocus(int, int) {}
41     ///
42     virtual bool Inside(int, int);   
43     // Tab stuff used by Matrix.
44     ///
45     virtual void SetAlign(char, string const &) {}
46     ///
47     virtual int GetColumns() const { return 1; }
48     ///
49     virtual int GetRows() const { return 1; }
50     ///
51     virtual bool isMatrix() const { return false; }
52     // Vertical switching
53     ///
54     virtual bool setArgumentIdx(int i) { return (i == 0); }
55     ///
56     virtual bool setNextArgIdx() { return false; }
57     ///
58     virtual int getArgumentIdx() const { return 0; }
59     ///
60     virtual int getMaxArgumentIdx() const { return 0; }
61     ///
62     virtual void SetStyle(short);
63     ///
64     virtual MathedRowSt * getRowSt() const;
65     ///
66     virtual void setRowSt(MathedRowSt *) {}
67     ///
68     virtual bool Permit(short f) const { return bool(f & flag); }
69  protected:
70     /// Paragraph data is stored here
71     MathedArray * array;
72     /// Cursor start position
73     int xo;
74     ///
75     int yo;
76     /// 
77     short flag;
78  private:
79     ///
80     virtual void setFlag(MathedParFlag f) { flag |= f; }
81     ///
82     friend class InsetFormula;
83     ///
84     friend class MathedXIter;
85     ///
86     friend class MathedCursor;
87     ///
88     friend MathedArray * mathed_parse(unsigned flags = 0,
89                                        MathedArray * a = 0,
90                                        MathParInset ** p = 0);
91 };
92
93
94 inline
95 bool MathParInset::Inside(int x, int y) 
96 {
97   return (x >= xo && x <= xo + width && y <= yo + descent && y >= yo - ascent);
98 }
99
100
101 inline
102 void MathParInset::GetXY(int & x, int & y) const
103 {
104    x = xo; y = yo;
105 }
106
107
108 inline
109 void MathParInset::UserSetSize(short sz)
110 {
111    if (sz >= 0) {
112        size = sz;      
113        flag = flag & ~LMPF_FIXED_SIZE;
114    }
115 }
116
117
118 inline
119 void MathParInset::SetStyle(short sz) 
120 {
121     if (Permit(LMPF_FIXED_SIZE)) {
122         if (Permit(LMPF_SCRIPT)) 
123           sz = (sz < LM_ST_SCRIPT) ? LM_ST_SCRIPT: LM_ST_SCRIPTSCRIPT;
124         if (Permit(LMPF_SMALLER) && sz < LM_ST_SCRIPTSCRIPT) {
125             ++sz;
126         } 
127         MathedInset::SetStyle(sz);
128     }
129 }
130 #endif