kformuladefs.h
1/* This file is part of the KDE project
2 Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
3 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#ifndef FORMULADEFS_H
22#define FORMULADEFS_H
23
24#include <memory>
25
26#include <tqpoint.h>
27#include <tqrect.h>
28#include <tqstring.h>
29
30#include <KoPoint.h>
31#include <KoRect.h>
32
33
34#define KFORMULA_NAMESPACE_BEGIN namespace KFormula {
35#define KFORMULA_NAMESPACE_END }
36
37KFORMULA_NAMESPACE_BEGIN
38
39const int DEBUGID = 40000;
40
41// to make kdDebug a litte more interessting...
42//#define TERM_RESET "␛[0m"
43//#define TERM_ERROR "␛[40;31;m"
44
48typedef double pt;
49typedef KoPoint PtPoint;
50typedef KoRect PtRect;
51//typedef KoSize PtSize;
52
56typedef int pixel;
57typedef TQPoint PixelPoint;
58typedef TQRect PixelRect;
59//typedef TQSize PixelSize;
60
65typedef int luPt;
66typedef TQPoint LuPtPoint;
67typedef TQRect LuPtRect;
68typedef TQSize LuPtSize;
69
70typedef int luPixel;
71typedef TQPoint LuPixelPoint;
72typedef TQRect LuPixelRect;
73typedef TQSize LuPixelSize;
74
75
79enum SymbolType {
80 LeftSquareBracket = '[',
81 RightSquareBracket = ']',
82 LeftCurlyBracket = '{',
83 RightCurlyBracket = '}',
84 LeftCornerBracket = '<',
85 RightCornerBracket = '>',
86 LeftRoundBracket = '(',
87 RightRoundBracket = ')',
88 SlashBracket = '/',
89 BackSlashBracket = '\\',
90 LeftLineBracket = 256,
91 RightLineBracket,
92 EmptyBracket = 1000,
93 Integral,
94 Sum,
95 Product
96};
97
98
104enum MoveFlag { NormalMovement = 0, SelectMovement = 1, WordMovement = 2 };
105
106inline MoveFlag movementFlag( int state )
107{
108 int flag = NormalMovement;
109 if ( state & TQt::ControlButton )
110 flag |= WordMovement;
111 if ( state & TQt::ShiftButton )
112 flag |= SelectMovement;
113 return static_cast<MoveFlag>( flag );
114}
115
116
117
121enum CharClass {
122 ORDINARY = 0,
123 BINOP = 1,
124 RELATION = 2,
125 PUNCTUATION = 3,
126
127 NUMBER, NAME, ELEMENT, INNER, BRACKET, SEQUENCE, SEPARATOR, END
128};
129
130typedef CharClass TokenType;
131
132
133// there are four bits needed to store this
134enum CharStyle {
135 normalChar,
136 boldChar,
137 italicChar,
138 boldItalicChar, // is required to be (boldChar | italicChar)!
139 //slantChar,
140 anyChar
141};
142
143
144enum CharFamily {
145 normalFamily,
146 scriptFamily,
147 frakturFamily,
148 doubleStruckFamily,
149 sansSerifFamily, // TODO: Currently unsupported
150 monospaceFamily, // TODO: Currently unsupported
151 anyFamily
152};
153
154enum TokenElementType {
155 identifierElement,
156 operatorElement,
157 numberElement,
158 textElement,
159 anyElement
160};
161
166 unsigned short unicode;
167 TQChar pos;
168 CharClass cl;
169 CharStyle style;
170};
171
172
178enum Direction { beforeCursor, afterCursor };
179
183enum SpaceWidth { THIN, MEDIUM, THICK, QUAD, NEGTHIN };
184
188enum SizeType {
189 NoSize,
190 AutoSize,
191 FitSize,
192 InfinitySize,
193 RelativeSize,
194 AbsoluteSize,
195 PixelSize,
196 NegativeVeryVeryThinMathSpace,
197 NegativeVeryThinMathSpace,
198 NegativeThinMathSpace,
199 NegativeMediumMathSpace,
200 NegativeThickMathSpace,
201 NegativeVeryThickMathSpace,
202 NegativeVeryVeryThickMathSpace,
203 VeryVeryThinMathSpace,
204 VeryThinMathSpace,
205 ThinMathSpace,
206 MediumMathSpace,
207 ThickMathSpace,
208 VeryThickMathSpace,
209 VeryVeryThickMathSpace
210};
211
215enum HorizontalAlign {
216 NoHorizontalAlign,
217 LeftHorizontalAlign,
218 CenterHorizontalAlign,
219 RightHorizontalAlign
220};
221
225enum FormType { NoForm, PrefixForm, InfixForm, PostfixForm };
226
230enum IndexPosition {
231 upperLeftPos,
232 lowerLeftPos,
233 upperMiddlePos,
234 contentPos,
235 lowerMiddlePos,
236 upperRightPos,
237 lowerRightPos,
238 parentPos
239};
240
241
242class BasicElement;
243class FormulaCursor;
244
252public:
253
254 virtual ~ElementIndex() { /*cerr << "ElementIndex destroyed.\n";*/ }
255
259 virtual void moveToIndex(FormulaCursor*, Direction) = 0;
260
266 virtual void setToIndex(FormulaCursor*) = 0;
267
271 virtual bool hasIndex() const = 0;
272
276 virtual BasicElement* getElement() = 0;
277};
278
279typedef std::unique_ptr<ElementIndex> ElementIndexPtr;
280
281enum RequestID {
282 req_addBracket,
283 req_addOverline,
284 req_addUnderline,
285 req_addFraction,
286 req_addIndex,
287 req_addMatrix,
288 req_addMultiline,
289 req_addNameSequence,
290 req_addNewline,
291 req_addOneByTwoMatrix,
292 req_addRoot,
293 req_addSpace,
294 req_addSymbol,
295 req_addTabMark,
296 req_addText,
297 req_addTextChar,
298 req_addOperator,
299 req_addNumber,
300 req_addEmptyBox,
301 req_appendColumn,
302 req_appendRow,
303 req_compactExpression,
304 req_copy,
305 req_cut,
306 req_insertColumn,
307 req_insertRow,
308 req_makeGreek,
309 req_paste,
310 req_remove,
311 req_removeEnclosing,
312 req_removeColumn,
313 req_removeRow,
314 req_formatBold,
315 req_formatItalic,
316 req_formatFamily,
317 req_formatTokenElement
318};
319
320
321class Request {
322 RequestID id;
323public:
324 Request( RequestID _id ) : id( _id ) {}
325 virtual ~Request() {}
326 operator RequestID() const { return id;}
327};
328
329
330class BracketRequest : public Request {
331 SymbolType m_left, m_right;
332public:
333 BracketRequest( SymbolType l, SymbolType r ) : Request( req_addBracket ), m_left( l ), m_right( r ) {}
334 SymbolType left() const { return m_left; }
335 SymbolType right() const { return m_right; }
336};
337
338class SymbolRequest : public Request {
339 SymbolType m_type;
340public:
341 SymbolRequest( SymbolType t ) : Request( req_addSymbol ), m_type( t ) {}
342 SymbolType type() const { return m_type; }
343};
344
345class IndexRequest : public Request {
346 IndexPosition m_index;
347public:
348 IndexRequest( IndexPosition i ) : Request( req_addIndex ), m_index( i ) {}
349 IndexPosition index() const { return m_index; }
350};
351
352class SpaceRequest : public Request {
353 SpaceWidth m_space;
354public:
355 SpaceRequest( SpaceWidth s ) : Request( req_addSpace ), m_space( s ) {}
356 SpaceWidth space() const { return m_space; }
357};
358
359class DirectedRemove : public Request {
360 Direction m_direction;
361public:
362 DirectedRemove( RequestID id, Direction d ) : Request( id ), m_direction( d ) {}
363 Direction direction() const { return m_direction; }
364};
365
366class TextCharRequest : public Request {
367 TQChar m_ch;
368 bool m_isSymbol;
369public:
370 TextCharRequest( TQChar ch, bool isSymbol=false ) : Request( req_addTextChar ), m_ch( ch ), m_isSymbol( isSymbol ) {}
371 TQChar ch() const { return m_ch; }
372 bool isSymbol() const { return m_isSymbol; }
373};
374
375class OperatorRequest: public Request {
376 TQChar m_ch;
377public:
378 OperatorRequest( TQChar ch ) : Request( req_addOperator ), m_ch( ch ) {}
379 TQChar ch() const { return m_ch; }
380};
381
382class NumberRequest: public Request {
383 TQChar m_ch;
384public:
385 NumberRequest( TQChar ch ) : Request( req_addNumber ), m_ch( ch ) {}
386 TQChar ch() const { return m_ch; }
387};
388
389class TextRequest : public Request {
390 TQString m_text;
391public:
392 TextRequest( TQString text ) : Request( req_addText ), m_text( text ) {}
393 TQString text() const { return m_text; }
394};
395
396class MatrixRequest : public Request {
397 uint m_rows, m_columns;
398public:
399 MatrixRequest( uint rows, uint columns ) : Request( req_addMatrix ), m_rows( rows ), m_columns( columns ) {}
400 uint rows() const { return m_rows; }
401 uint columns() const { return m_columns; }
402};
403
404class CharStyleRequest : public Request {
405 bool m_bold;
406 bool m_italic;
407public:
408 CharStyleRequest( RequestID id, bool bold, bool italic ) : Request( id ), m_bold( bold ), m_italic( italic ) {}
409 bool bold() const { return m_bold; }
410 bool italic() const { return m_italic; }
411};
412
413class CharFamilyRequest : public Request {
414 CharFamily m_charFamily;
415public:
416 CharFamilyRequest( CharFamily cf ) : Request( req_formatFamily ), m_charFamily( cf ) {}
417 CharFamily charFamily() const { return m_charFamily; }
418};
419
420class TokenElementRequest : public Request {
421 TokenElementType m_tokenElement;
422public:
423 TokenElementRequest( TokenElementType te ) : Request( req_formatTokenElement ), m_tokenElement( te ) {}
424 TokenElementType tokenElement() const { return m_tokenElement; }
425};
426
427
428KFORMULA_NAMESPACE_END
429
430#endif // FORMULADEFS_H
Basis of every formula element.
A type that describes an index.
virtual void setToIndex(FormulaCursor *)=0
Sets the cursor to point to the place where the index normaly is.
virtual void moveToIndex(FormulaCursor *, Direction)=0
Moves the cursor inside the index.
virtual BasicElement * getElement()=0
Tells to which element the index belongs.
virtual bool hasIndex() const =0
Tells whether we own those indexes.
The selection.
A point whose coordinates are floating-point values ( "double"s ).
Definition KoPoint.h:30
A rect whose coordinates are floating-point values ( "double"s ).
Definition KoRect.h:31
The struct used to store static font data.