]> git.lyx.org Git - lyx.git/blob - src/mathed/math_defs.h
first go at mathed file cleanup
[lyx.git] / src / mathed / math_defs.h
1 // -*- C++ -*-
2 /*
3  *  File:        math_defs.h
4  *  Purpose:     Math editor definitions 
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
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
20 #ifndef MATH_DEFS
21 #define MATH_DEFS
22
23 #ifdef __GNUG__
24 #pragma interface
25 #endif
26
27 #include <iosfwd>
28
29 #include "LString.h"
30 #include "debug.h"
31
32 //#include "array.h"
33
34 class MathedArray;
35 class Painter;
36
37 #ifndef byte
38 #define byte unsigned char
39 #endif
40
41 ///
42 enum math_align {
43         ///
44         MATH_ALIGN_LEFT = 1,
45         ///
46         MATH_ALIGN_RIGHT = 2,
47         ///
48         MATH_ALIGN_BOTTOM = 4,
49         ///
50         MATH_ALIGN_TOP = 8
51 };
52 ///
53 static int const MATH_COLSEP = 8;
54 ///
55 static int const MATH_ROWSEP = 8;
56
57
58 /// Standard Math Sizes (Math mode styles)
59 enum MathedStyles {
60         ///
61         LM_ST_DISPLAY = 0,
62         ///
63         LM_ST_TEXT,
64         ///
65         LM_ST_SCRIPT,
66         ///
67         LM_ST_SCRIPTSCRIPT
68 };
69
70
71 /** The restrictions of a standard LaTeX math paragraph
72   allows to get a small number of text codes (<30) */
73 enum MathedTextCodes  {
74         /// This must be >= 0
75         LM_TC_MIN = 0,
76         /// Open and Close group
77         LM_TC_OPEN,
78         ///
79         LM_TC_CLOSE,
80         /// Tabulator
81         LM_TC_TAB,
82         /// New line
83         LM_TC_CR,
84         /// Math Inset
85         LM_TC_INSET,
86         /// Super and sub scripts
87         LM_TC_UP,
88         ///
89         LM_TC_DOWN,
90         /// Editable Math Inset
91         LM_TC_ACTIVE_INSET,
92         /// Editable Text Inset
93         LM_TC_TEXT_INSET,
94         ///
95         LM_FONT_BEGIN,
96         /// Internal code for constants
97         LM_TC_CONST,
98         /// Internal code for variables
99         LM_TC_VAR,
100         ///
101         LM_TC_RM,
102         ///
103         LM_TC_CAL,
104         ///
105         LM_TC_BF,
106         ///
107         LM_TC_SF,
108         ///
109         LM_TC_TT,
110         ///
111         LM_TC_IT,
112         ///
113         LM_TC_TEXTRM,
114         /// Math mode TeX characters ",;:{}"
115         LM_TC_TEX,
116         /// Special characters "{}&#_%"
117         LM_TC_SPECIAL,
118         /// Internal code for operators
119         LM_TC_BOP,
120         /// Internal code for symbols
121         LM_TC_SYMB,
122         ///
123         LM_TC_BOPS,
124         ///
125         LM_TC_BSYM,
126         ///
127         LM_FONT_END,
128         
129         /// This must be < 32 
130         LM_TC_MAX
131 };
132
133 ///
134 std::ostream & operator<<(std::ostream &, MathedTextCodes mtc);
135
136 ///
137 #define LM_TC_NORMAL LM_TC_VAR
138  
139        
140 /// Types of lyx-math insets 
141 enum MathedInsetTypes  {
142         ///
143         LM_OT_MIN = 0,
144         /// A simple paragraph
145         LM_OT_PAR,
146         /// A simple numbered paragraph
147         LM_OT_PARN,
148         /// A multiline paragraph
149         LM_OT_MPAR,
150         /// A multiline numbered paragraph
151         LM_OT_MPARN,
152         ///
153         LM_OT_ALIGN,
154         ///
155         LM_OT_ALIGNN,
156         ///
157         LM_OT_ALIGNAT,
158         ///
159         LM_OT_ALIGNATN,
160         ///
161         LM_OT_MULTLINE,
162         ///
163         LM_OT_MULTLINEN,
164         /// An array
165         LM_OT_MATRIX,
166
167         /// A big operator
168         LM_OT_BIGOP,
169         /// A LaTeX macro
170         LM_OT_UNDEF,
171         ///
172         LM_OT_FUNC,
173         ///
174         LM_OT_FUNCLIM,
175         ///
176         LM_OT_SCRIPT,
177         ///
178         LM_OT_SPACE,
179         ///
180         LM_OT_DOTS,
181         /// A fraction
182         LM_OT_FRAC,
183         ///
184         LM_OT_ATOP,
185         ///
186         LM_OT_STACKREL,
187         /// A radical
188         LM_OT_SQRT,
189         /// A delimiter
190         LM_OT_DELIM,
191         /// A decoration
192         LM_OT_DECO,
193         /// An accent
194         LM_OT_ACCENT,
195         ///
196         LM_OT_MACRO,
197         ///
198         LM_OT_MACRO_ARG,
199         ///
200         LM_OT_MAX
201 };
202
203 ///
204 enum MathedBinaryTypes {
205         ///
206         LMB_NONE = 0,
207         ///
208         LMB_RELATION,
209         ///
210         LMB_OPERATOR,
211         ///
212         LMB_BOP = (LMB_RELATION | LMB_OPERATOR)
213 };
214
215 class MathParInset;
216
217
218 /// Paragraph permissions
219 enum MathedParFlag {
220         LMPF_BASIC = 0,
221         /// If false can use a non-standard size
222         LMPF_FIXED_SIZE = 1,
223         /// If true can insert newlines 
224         LMPF_ALLOW_CR  = 2,
225         /// If true can use tabs
226         LMPF_ALLOW_TAB = 4,
227         /// If true can insert new columns
228         LMPF_ALLOW_NEW_COL = 8,
229         /// Smaller than current size (frac)
230         LMPF_SMALLER = 16,
231         /// Script size (subscript, stackrel)
232         LMPF_SCRIPT = 32
233 };
234
235
236
237
238
239 /*************************  Prototypes  **********************************/
240 /// 
241 MathedArray * mathed_parse(unsigned flags, MathedArray * data,
242                             MathParInset ** mt);
243 ///
244 void mathed_write(MathParInset *, std::ostream &, int *, bool fragile,
245                   string const & label = string());
246
247 ///
248 void mathed_parser_file(std::istream &, int);
249 ///
250 int mathed_parser_lineno();
251 ///
252 int MathedLookupBOP(short);
253
254 /************************ Inline functions ********************************/
255
256 ///
257 inline
258 bool MathIsInset(short x)
259 {
260         return LM_TC_INSET <= x && x <= LM_TC_ACTIVE_INSET;
261 }
262
263 ///
264 inline
265 bool MathIsFont(short x)
266 {
267         return LM_TC_CONST <= x && x <= LM_TC_BSYM;
268 }
269
270 ///
271 inline
272 bool MathIsAlphaFont(short x)
273 {
274         return LM_TC_VAR <= x && x <= LM_TC_TEXTRM;
275 }
276
277 ///
278 inline
279 bool MathIsActive(short x)
280 {
281         return LM_TC_INSET < x && x <= LM_TC_ACTIVE_INSET;
282 }
283
284 ///
285 inline
286 bool MathIsUp(short x)
287 {
288         return x == LM_TC_UP;
289 }
290
291 ///
292 inline
293 bool MathIsDown(short x)
294 {
295         return x == LM_TC_DOWN;
296 }
297
298 ///
299 inline
300 bool MathIsScript(short x)
301 {
302         return x == LM_TC_DOWN || x == LM_TC_UP;
303 }
304
305 ///
306 inline
307 bool MathIsBOPS(short x)
308 {
309         return MathedLookupBOP(x) > LMB_NONE;
310 }
311
312 ///
313 inline
314 bool MathIsBinary(short x)
315 {
316     return x == LM_TC_BOP || x == LM_TC_BOPS;
317 }
318
319 ///
320 inline
321 bool MathIsSymbol(short x) {
322     return LM_TC_SYMB <= x && x <= LM_TC_BSYM;
323 }
324      
325
326 inline
327 bool is_eqn_type(short int type)
328 {
329         return type >= LM_OT_MIN && type < LM_OT_MATRIX;
330 }
331
332
333 inline
334 bool is_matrix_type(short int type)
335 {
336         return type == LM_OT_MATRIX;
337 }
338
339 inline
340 bool is_multiline(short int type)
341 {
342         return type >= LM_OT_MPAR && type < LM_OT_MATRIX;
343 }
344
345
346 inline bool is_ams(short int type)
347 {
348         return type > LM_OT_MPARN && type < LM_OT_MATRIX;
349 }
350
351 inline
352 bool is_singlely_numbered(short int type)
353 {
354         return type == LM_OT_PARN || type == LM_OT_MULTLINEN;
355 }
356
357 inline
358 bool is_multi_numbered(short int type)
359 {
360         return type == LM_OT_MPARN || type == LM_OT_ALIGNN
361                 || type == LM_OT_ALIGNATN;
362 }
363
364 inline
365 bool is_numbered(short int type)
366 {
367         return is_singlely_numbered(type) || is_multi_numbered(type);
368 }
369
370 inline
371 bool is_multicolumn(short int type)
372 {
373         return type == LM_OT_ALIGN || type == LM_OT_ALIGNN
374                 || type == LM_OT_ALIGNAT || type == LM_OT_ALIGNATN;
375 }
376
377 #endif