]> git.lyx.org Git - features.git/blob - src/mathed/math_inset.h
more mathed cleanup
[features.git] / src / mathed / math_inset.h
1 // -*- C++ -*-
2 /*
3  *  File:        math_inset.h
4  *  Purpose:     Declaration of insets for mathed 
5  *  Author:      Alejandro Aguilar Sierra <asierra@servidor.unam.mx> 
6  *  Created:     January 1996
7  *  Description: Math paragraph and objects for a WYSIWYG math editor.
8  *
9  *  Dependencies: Xlib, XForms
10  *
11  *  Copyright: 1996, 1997 Alejandro Aguilar Sierra
12  *
13  *   Version: 0.8beta, Mathed & Lyx project.
14  *
15  *   You are free to use and modify this code under the terms of
16  *   the GNU General Public Licence version 2 or later.
17  */
18
19 //  Note: These math insets are internal to Mathed and are not derived
20 //        from lyx inset.
21
22 #ifndef MATH_INSET
23 #define MATH_INSET
24
25 #ifdef __GNUG__
26 #pragma interface
27 #endif
28
29 #include "LString.h"
30 #include "symbol_def.h"
31
32 class Painter;
33
34 /** Abstract base class for all math objects.
35     A math insets is for use of the math editor only, it isn't a
36     general LyX inset. It's used to represent all the math objects.
37     The formulaInset (a LyX inset) encapsulates a math inset.
38  */
39 class MathedInset  {
40  public: 
41     /// A math inset has a name (usually its LaTeX name), type and font-size
42     MathedInset(string const & nm, short ot, short st);
43     ///
44     explicit
45     MathedInset(MathedInset *);
46     ///
47     virtual ~MathedInset() {}
48     /// Draw the object
49     virtual void draw(Painter &, int x, int baseline) = 0;      
50     /// Write LaTeX and Lyx code
51     virtual void Write(std::ostream &, bool fragile) = 0;
52     /// Reproduces itself
53     virtual MathedInset * Clone() = 0;
54     /// Compute the size of the object
55     virtual void Metrics() = 0; 
56     /// 
57     virtual int Ascent() const { return ascent; }
58     ///
59     virtual int Descent() const { return descent; }
60     ///
61     virtual int Width() const { return width; }
62     ///
63     virtual int Height() const { return ascent + descent; }
64     ///
65     virtual bool GetLimits() const { return false; }
66     ///
67     virtual void SetLimits(bool) {}   
68     ///
69     string const & GetName() const { return name; }
70     ///
71     short GetType() const { return objtype; }
72     ///
73     short GetStyle() const { return size; }
74     //Man:  Avoid to use these functions if it's not strictly necessary 
75     ///
76     virtual void  SetType(short t) { objtype = t; }
77     ///
78     virtual void  SetStyle(short st) { size = st; } // Metrics();
79     ///
80     virtual void  SetName(string const & n) { name = n; }
81     ///
82     static int workWidth;
83          protected:
84     ///
85     string name;
86     ///
87     short objtype;
88     ///
89     int width;
90     ///
91     int ascent;
92     ///
93     int descent;
94     ///
95     short size;
96     /// Default metrics
97     static int df_asc;
98     ///
99     static int df_des;
100     ///
101     static int df_width;
102     /// In a near future maybe we use a better fonts renderer than X
103     void drawStr(Painter &, short, int, int, int, string const &);
104     ///
105     friend class MathedCursor;
106     ///
107     friend void mathed_init_fonts();
108 };
109 #endif