formulacursor.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 FORMULACURSOR_H
22#define FORMULACURSOR_H
23
24#include <tqstring.h>
25
26#include "basicelement.h"
27#include "kformuladefs.h"
28
29KFORMULA_NAMESPACE_BEGIN
30
31class FormulaElement;
32class IndexElement;
33class MatrixElement;
34class NameSequence;
35class RootElement;
36class SymbolElement;
37class TextElement;
38
39
51
52 // Yes, we do have a friend.
53 friend class SequenceElement;
54
55public:
56
64
65 FormulaCursor& operator= (const FormulaCursor&);
66
67 // where the cursor and the mark are
68 uint getPos() const { return cursorPos; }
69 int getMark() const { return markPos; }
70
74 bool hasChanged() const { return hasChangedFlag; }
75
80 void clearChangedFlag() { hasChangedFlag = false; }
81
85 bool isSelectionMode() const { return selectionFlag; }
86
90 bool isSelection() const { return selectionFlag && (getPos() != getMark()); }
91
95 void setSelection(bool selection) { selectionFlag = selection; hasChangedFlag = true; }
96
101 void calcCursorSize( const ContextStyle& context, bool smallCursor );
102
107 void draw( TQPainter&, const ContextStyle& context, StyleAttributes& style,
108 bool smallCursor, bool activeCursor );
109
110
111 // simple cursor movement.
112
113 void moveLeft(int flag = NormalMovement);
114 void moveRight(int flag = NormalMovement);
115 void moveUp(int flag = NormalMovement);
116 void moveDown(int flag = NormalMovement);
117
118 void moveHome(int flag = NormalMovement);
119 void moveEnd(int flag = NormalMovement);
120
122 bool isHome() const;
123
125 bool isEnd() const;
126
127 // how to travel
128
129 bool getLinearMovement() const { return linearMovement; }
130
135 void setLinearMovement(bool linear) { linearMovement = linear; }
136
140 void goInsideElement(BasicElement* element);
141
142 // mouse selection
143
144 void mousePress( const LuPixelPoint&, int flags );
145 void mouseMove( const LuPixelPoint&, int flags );
146 void mouseRelease( const LuPixelPoint&, int flags );
147
152 void insert(BasicElement*, Direction = beforeCursor);
153
159 void insert(TQPtrList<BasicElement>&,
160 Direction = beforeCursor);
161
167 void remove(TQPtrList<BasicElement>&,
168 Direction = beforeCursor);
169
170
176 Direction = beforeCursor);
177
182 BasicElement* replaceByMainChildContent(Direction = beforeCursor);
183
191 BasicElement* removeEnclosingElement(Direction = beforeCursor);
192
197 bool elementIsSenseless();
198
199
200 // The range that is selected. Makes no sense if there is
201 // no selection.
202
203 int getSelectionStart() const { return TQMIN(getPos(), getMark()); }
204 int getSelectionEnd() const { return TQMAX(getPos(), getMark()); }
205
206
217 void setTo(BasicElement* element, uint cursor, int mark=-1);
218
219 void setPos(uint pos);
220 void setMark(int mark);
221
222
232 BasicElement* getElement() { return current; }
233 const BasicElement* getElement() const { return current; }
234
235
242 void normalize(Direction direction = beforeCursor);
243
244
249 const SequenceElement* normal() const;
250
256
262
268
274
279
284
289 void selectActiveElement();
290
294 void copy( TQDomDocument& doc );
295
300 bool buildElementsFromDom( TQDomElement root, TQPtrList<BasicElement>& list );
301
306 bool buildElementsFromMathMLDom( TQDomElement root, TQPtrList<BasicElement>& list );
307
308 // undo/redo support
309
316 friend class FormulaCursor;
317 BasicElement* current;
318 uint cursorPos;
319 int markPos;
320 bool selectionFlag;
321 bool linearMovement;
322 bool readOnly;
323
325 uint pos, int mark, bool selection, bool linear, bool ro)
326 : current(c), cursorPos(pos), markPos(mark),
327 selectionFlag(selection), linearMovement(linear),
328 readOnly(ro) {}
329 };
330
336
341 void setCursorData(CursorData* data);
342
346 void elementWillVanish(BasicElement* element);
347
351 void formulaLoaded(FormulaElement* rootElement);
352
356 const LuPixelPoint& getCursorPoint() const { return cursorPoint; }
357
361 const LuPixelRect& getCursorSize() const { return cursorSize; }
362 void addCursorSize( const LuPixelRect& rect ) { cursorSize |= rect; }
363
367 bool isReadOnly() const;
368
372 void setReadOnly(bool ro) { readOnly = ro; }
373
374private:
375
383 BasicElement* getActiveChild(Direction direction);
384
391 BasicElement* getSelectedChild();
392
397 bool pointsAfterMainChild(BasicElement*);
398
402 void handleSelectState(int flag);
403
404
408 BasicElement* current;
409
416 uint cursorPos;
417
424 int markPos;
425
430 bool selectionFlag;
431
436 bool linearMovement;
437
442 LuPixelPoint cursorPoint;
443
448 LuPixelRect cursorSize;
449
455 bool hasChangedFlag;
456
460 bool readOnly;
461};
462
463KFORMULA_NAMESPACE_END
464
465#endif // FORMULACURSOR_H
Basis of every formula element.
Contains all the style information for the formela.
A black box that is supposed to contain everything which is needed to describe a cursor.
The selection.
void setReadOnly(bool ro)
Puts the widget in read only mode.
bool isSelection() const
Returns wether there actually is a selection.
bool buildElementsFromMathMLDom(TQDomElement root, TQPtrList< BasicElement > &list)
Inserts the elements that could be read from the MathML dom into the list.
IndexElement * getActiveIndexElement()
Returns the IndexElement the cursor is on or 0 if there is non.
const LuPixelPoint & getCursorPoint() const
NameSequence * getActiveNameSequence()
void setLinearMovement(bool linear)
Sets the cursor in linear mode.
SequenceElement * normal()
Returns the sequence the cursor is in if we are normal.
void normalize(Direction direction=beforeCursor)
Moves the cursor to a normal position.
void insert(BasicElement *, Direction=beforeCursor)
Inserts the child at the current position.
SymbolElement * getActiveSymbolElement()
Returns the SymbolElement the cursor is on or 0 if there is non.
void selectActiveElement()
Selects the element the cursor points to (stands after) if there is such an element and if there is n...
void replaceSelectionWith(BasicElement *, Direction=beforeCursor)
Replaces the current selection with the supplied element.
void setCursorData(CursorData *data)
Sets the cursor to where the CursorData points to.
void clearChangedFlag()
Resets the cursor's change flag.
void setSelection(bool selection)
Sets the selection mode.
CursorData * getCursorData()
Creates a new CursorData object that describes the cursor.
RootElement * getActiveRootElement()
Returns the RootElement the cursor is on or 0 if there is non.
bool isEnd() const
BasicElement * replaceByMainChildContent(Direction=beforeCursor)
Replaces the element the cursor points to with its main child's content.
bool isSelectionMode() const
Returns wether we are in selection mode.
BasicElement * removeEnclosingElement(Direction=beforeCursor)
Trys to find the element we are the main child of and replace it with our content.
void calcCursorSize(const ContextStyle &context, bool smallCursor)
Calculates the size of the cursor.
void goInsideElement(BasicElement *element)
Moves the cursor inside the element.
const LuPixelRect & getCursorSize() const
void elementWillVanish(BasicElement *element)
The element is going to leave the formula with and all its children.
void setTo(BasicElement *element, uint cursor, int mark=-1)
Sets the cursor to a new position.
bool buildElementsFromDom(TQDomElement root, TQPtrList< BasicElement > &list)
Inserts the elements that could be read from the dom into the list.
bool elementIsSenseless()
Returns wether the element the cursor points to should be replaced.
BasicElement * getElement()
The element we are in.
bool hasChanged() const
Tells whether the cursor has changed since last cleaning.
MatrixElement * getActiveMatrixElement()
TextElement * getActiveTextElement()
bool isHome() const
bool isReadOnly() const
void remove(TQPtrList< BasicElement > &, Direction=beforeCursor)
Removes the current selected children and returns them.
void draw(TQPainter &, const ContextStyle &context, StyleAttributes &style, bool smallCursor, bool activeCursor)
Draws the cursor at its current position.
void formulaLoaded(FormulaElement *rootElement)
A new formula has been loaded.
void copy(TQDomDocument &doc)
Stores the currently selected elements inside a dom.
The main element.
The element with up to four indexes in the four corners.
The sequence thats a name.
A nice graphical root.
Definition rootelement.h:35
The element that contains a number of children.
A symbol is simply a piece of art.
An element that represents one char.
Definition textelement.h:37