summaryrefslogtreecommitdiffstats
path: root/lib/kformula/kformuladefs.h
blob: 80879f98cc1cc5894ec827a71095288f6fb7b62a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
/* This file is part of the KDE project
   Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
	              Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef FORMULADEFS_H
#define FORMULADEFS_H

#include <memory>

#include <tqpoint.h>
#include <tqrect.h>
#include <tqstring.h>

#include <KoPoint.h>
#include <KoRect.h>


#define KFORMULA_NAMESPACE_BEGIN namespace KFormula {
#define KFORMULA_NAMESPACE_END }

KFORMULA_NAMESPACE_BEGIN

const int DEBUGID = 40000;

// to make kdDebug a litte more interessting...
//#define TERM_RESET ""
//#define TERM_ERROR ""

/**
 * The type to be used for points.
 */
typedef double pt;
typedef KoPoint PtPoint;
typedef KoRect PtRect;
//typedef KoSize PtSize;

/**
 * Pixels. At any zoom level.
 */
typedef int pixel;
typedef TQPoint PixelPoint;
typedef TQRect PixelRect;
//typedef TQSize PixelSize;

/**
 * Layout Unit. That's the values we store to get
 * wysiwyg right.
 */
typedef int luPt;
typedef TQPoint LuPtPoint;
typedef TQRect LuPtRect;
typedef TQSize LuPtSize;

typedef int luPixel;
typedef TQPoint LuPixelPoint;
typedef TQRect LuPixelRect;
typedef TQSize LuPixelSize;


/**
 * The symbols that are supported by our artwork.
 */
enum SymbolType {
    LeftSquareBracket = '[',
    RightSquareBracket = ']',
    LeftCurlyBracket = '{',
    RightCurlyBracket = '}',
    LeftCornerBracket = '<',
    RightCornerBracket = '>',
    LeftRoundBracket = '(',
    RightRoundBracket = ')',
    SlashBracket = '/',
    BackSlashBracket = '\\',
    LeftLineBracket = 256,
    RightLineBracket,
    EmptyBracket = 1000,
    Integral,
    Sum,
    Product
};


/**
 * Flag for cursor movement functions.
 * Select means move selecting the text (usually Shift key)
 * Word means move by whole words  (usually Control key)
 */
enum MoveFlag { NormalMovement = 0, SelectMovement = 1, WordMovement = 2 };

inline MoveFlag movementFlag( int state )
{
    int flag = NormalMovement;
    if ( state & TQt::ControlButton )
        flag |= WordMovement;
    if ( state & TQt::ShiftButton )
        flag |= SelectMovement;
    return static_cast<MoveFlag>( flag );
}



/**
 * TeX like char classes
 */
enum CharClass {
    ORDINARY = 0,
    BINOP = 1,
    RELATION = 2,
    PUNCTUATION = 3,

    NUMBER, NAME, ELEMENT, INNER, BRACKET, SEQUENCE, SEPARATOR, END
};

typedef CharClass TokenType;


// there are four bits needed to store this
enum CharStyle {
    normalChar,
    boldChar,
    italicChar,
    boldItalicChar, // is required to be (boldChar | italicChar)!
    //slantChar,
    anyChar
};


enum CharFamily {
    normalFamily,
    scriptFamily,
    frakturFamily,
    doubleStruckFamily,
	sansSerifFamily, // TODO: Currently unsupported
	monospaceFamily,       // TODO: Currently unsupported
    anyFamily
};

enum TokenElementType {
    identifierElement,
    operatorElement,
    numberElement,
    textElement,
    anyElement
};

/**
 * The struct used to store static font data.
 */
struct InternFontTable {
    short tqunicode;
    TQChar pos;
    CharClass cl;
    CharStyle style;
};


/**
 * Wether we want to insert to the left of the cursor
 * or right of it.
 * The same for deletion.
 */
enum Direction { beforeCursor, afterCursor };

/**
 * The types of space we know.
 */
enum SpaceWidth { THIN, MEDIUM, THICK, TQUAD, NEGTHIN };

/**
 * The types of MathML horizontal or vertical sizes we know
 */
enum SizeType { 
    NoSize, 
    AutoSize, 
    FitSize,
    InfinitySize,
    RelativeSize, 
    AbsoluteSize, 
    PixelSize,
    NegativeVeryVeryThinMathSpace,
    NegativeVeryThinMathSpace,
    NegativeThinMathSpace,
    NegativeMediumMathSpace,
    NegativeThickMathSpace,
    NegativeVeryThickMathSpace,
    NegativeVeryVeryThickMathSpace,
    VeryVeryThinMathSpace,
    VeryThinMathSpace,
    ThinMathSpace,
    MediumMathSpace,
    ThickMathSpace,
    VeryThickMathSpace,
    VeryVeryThickMathSpace
};

/**
 * The types of horizontal align
 */
enum HorizontalAlign { 
    NoHorizontalAlign, 
    LeftHorizontalAlign, 
    CenterHorizontalAlign, 
    RightHorizontalAlign 
};

/**
 * Type of forms in operators
 */
enum FormType { NoForm, PrefixForm, InfixForm, PostfixForm };

/**
 * each index has its own number.
 */
enum IndexPosition {
    upperLeftPos,
    lowerLeftPos,
    upperMiddlePos,
    contentPos,
    lowerMiddlePos,
    upperRightPos,
    lowerRightPos,
    parentPos
};


class BasicElement;
class FormulaCursor;

/**
 * A type that describes an index. You can get one of those
 * for each index from an element that owns indexes.
 *
 * This type is used to work on indexes in a generic way.
 */
class ElementIndex {
public:

    virtual ~ElementIndex() { /*cerr << "ElementIndex destroyed.\n";*/ }

    /**
     * Moves the cursor inside the index. The index has to exist.
     */
    virtual void moveToIndex(FormulaCursor*, Direction) = 0;

    /**
     * Sets the cursor to point to the place where the index normaly
     * is. These functions are only used if there is no such index and
     * we want to insert them.
     */
    virtual void setToIndex(FormulaCursor*) = 0;

    /**
     * Tells whether we own those indexes.
     */
    virtual bool hasIndex() const = 0;

    /**
     * Tells to which element the index belongs.
     */
    virtual BasicElement* getElement() = 0;
};

typedef std::auto_ptr<ElementIndex> ElementIndexPtr;

enum RequestID {
    req_addBracket,
    req_addOverline,
    req_addUnderline,
    req_addFraction,
    req_addIndex,
    req_addMatrix,
    req_addMultiline,
    req_addNameSequence,
    req_addNewline,
    req_addOneByTwoMatrix,
    req_addRoot,
    req_addSpace,
    req_addSymbol,
    req_addTabMark,
    req_addText,
    req_addTextChar,
    req_addOperator,
    req_addNumber,
    req_addEmptyBox,
    req_appendColumn,
    req_appendRow,
    req_compactExpression,
    req_copy,
    req_cut,
    req_insertColumn,
    req_insertRow,
    req_makeGreek,
    req_paste,
    req_remove,
    req_removeEnclosing,
    req_removeColumn,
    req_removeRow,
    req_formatBold,
    req_formatItalic,
    req_formatFamily,
    req_formatTokenElement
};


class Request {
    RequestID id;
public:
    Request( RequestID _id ) : id( _id ) {}
    virtual ~Request() {}
    operator RequestID() const { return id;}
};


class BracketRequest : public Request {
    SymbolType m_left, m_right;
public:
    BracketRequest( SymbolType l, SymbolType r ) : Request( req_addBracket ), m_left( l ), m_right( r ) {}
    SymbolType left() const { return m_left; }
    SymbolType right() const { return m_right; }
};

class SymbolRequest : public Request {
    SymbolType m_type;
public:
    SymbolRequest( SymbolType t ) : Request( req_addSymbol ), m_type( t ) {}
    SymbolType type() const { return m_type; }
};

class IndexRequest : public Request {
    IndexPosition m_index;
public:
    IndexRequest( IndexPosition i ) : Request( req_addIndex ), m_index( i ) {}
    IndexPosition index() const { return m_index; }
};

class SpaceRequest : public Request {
    SpaceWidth m_space;
public:
    SpaceRequest( SpaceWidth s ) : Request( req_addSpace ), m_space( s ) {}
    SpaceWidth space() const { return m_space; }
};

class DirectedRemove : public Request {
    Direction m_direction;
public:
    DirectedRemove( RequestID id, Direction d ) : Request( id ), m_direction( d ) {}
    Direction direction() const { return m_direction; }
};

class TextCharRequest : public Request {
    TQChar m_ch;
    bool m_isSymbol;
public:
    TextCharRequest( TQChar ch, bool isSymbol=false ) : Request( req_addTextChar ), m_ch( ch ), m_isSymbol( isSymbol ) {}
    TQChar ch() const { return m_ch; }
    bool isSymbol() const { return m_isSymbol; }
};

class OperatorRequest: public Request {
    TQChar m_ch;
public:
    OperatorRequest( TQChar ch ) : Request( req_addOperator ), m_ch( ch ) {}
    TQChar ch() const { return m_ch; }
};

class NumberRequest: public Request {
    TQChar m_ch;
public:
    NumberRequest( TQChar ch ) : Request( req_addNumber ), m_ch( ch ) {}
    TQChar ch() const { return m_ch; }
};

class TextRequest : public Request {
    TQString m_text;
public:
    TextRequest( TQString text ) : Request( req_addText ), m_text( text ) {}
    TQString text() const { return m_text; }
};

class MatrixRequest : public Request {
    uint m_rows, m_columns;
public:
    MatrixRequest( uint rows, uint columns ) : Request( req_addMatrix ), m_rows( rows ), m_columns( columns ) {}
    uint rows() const { return m_rows; }
    uint columns() const { return m_columns; }
};

class CharStyleRequest : public Request {
    bool m_bold;
    bool m_italic;
public:
    CharStyleRequest( RequestID id, bool bold, bool italic ) : Request( id ), m_bold( bold ), m_italic( italic ) {}
    bool bold() const { return m_bold; }
    bool italic() const { return m_italic; }
};

class CharFamilyRequest : public Request {
    CharFamily m_charFamily;
public:
    CharFamilyRequest( CharFamily cf ) : Request( req_formatFamily ), m_charFamily( cf ) {}
    CharFamily charFamily() const { return m_charFamily; }
};

class TokenElementRequest : public Request {
    TokenElementType m_tokenElement;
public:
    TokenElementRequest( TokenElementType te ) : Request( req_formatTokenElement ), m_tokenElement( te ) {}
    TokenElementType tokenElement() const { return m_tokenElement; }
};


KFORMULA_NAMESPACE_END

#endif // FORMULADEFS_H