lib

formulacursor.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
00003                   Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #ifndef FORMULACURSOR_H
00022 #define FORMULACURSOR_H
00023 
00024 #include <qstring.h>
00025 
00026 #include "basicelement.h"
00027 #include "kformuladefs.h"
00028 
00029 KFORMULA_NAMESPACE_BEGIN
00030 
00031 class FormulaElement;
00032 class IndexElement;
00033 class MatrixElement;
00034 class NameSequence;
00035 class RootElement;
00036 class SymbolElement;
00037 class TextElement;
00038 
00039 
00050 class FormulaCursor {
00051 
00052     // Yes, we do have a friend.
00053     friend class SequenceElement;
00054 
00055 public:
00056 
00063     FormulaCursor(FormulaElement* element);
00064 
00065     FormulaCursor& operator= (const FormulaCursor&);
00066 
00067     // where the cursor and the mark are
00068     uint getPos() const { return cursorPos; }
00069     int getMark() const { return markPos; }
00070 
00074     bool hasChanged() const { return hasChangedFlag; }
00075 
00080     void clearChangedFlag() { hasChangedFlag = false; }
00081 
00085     bool isSelectionMode() const { return selectionFlag; }
00086 
00090     bool isSelection() const { return selectionFlag && (getPos() != getMark()); }
00091 
00095     void setSelection(bool selection) { selectionFlag = selection; hasChangedFlag = true; }
00096 
00101     void calcCursorSize( const ContextStyle& context, bool smallCursor );
00102 
00107     void draw( QPainter&, const ContextStyle& context, StyleAttributes& style,
00108                bool smallCursor, bool activeCursor );
00109 
00110 
00111     // simple cursor movement.
00112 
00113     void moveLeft(int flag = NormalMovement);
00114     void moveRight(int flag = NormalMovement);
00115     void moveUp(int flag = NormalMovement);
00116     void moveDown(int flag = NormalMovement);
00117 
00118     void moveHome(int flag = NormalMovement);
00119     void moveEnd(int flag = NormalMovement);
00120 
00122     bool isHome() const;
00123 
00125     bool isEnd() const;
00126 
00127     // how to travel
00128 
00129     bool getLinearMovement() const { return linearMovement; }
00130 
00135     void setLinearMovement(bool linear) { linearMovement = linear; }
00136 
00140     void goInsideElement(BasicElement* element);
00141 
00142     // mouse selection
00143 
00144     void mousePress( const LuPixelPoint&, int flags );
00145     void mouseMove( const LuPixelPoint&, int flags );
00146     void mouseRelease( const LuPixelPoint&, int flags );
00147 
00152     void insert(BasicElement*, Direction = beforeCursor);
00153 
00159     void insert(QPtrList<BasicElement>&,
00160                 Direction = beforeCursor);
00161 
00167     void remove(QPtrList<BasicElement>&,
00168                 Direction = beforeCursor);
00169 
00170 
00175     void replaceSelectionWith(BasicElement*,
00176                               Direction = beforeCursor);
00177 
00182     BasicElement* replaceByMainChildContent(Direction = beforeCursor);
00183 
00191     BasicElement* removeEnclosingElement(Direction = beforeCursor);
00192 
00197     bool elementIsSenseless();
00198 
00199 
00200     // The range that is selected. Makes no sense if there is
00201     // no selection.
00202 
00203     int getSelectionStart() const { return QMIN(getPos(), getMark()); }
00204     int getSelectionEnd() const { return QMAX(getPos(), getMark()); }
00205 
00206 
00217     void setTo(BasicElement* element, uint cursor, int mark=-1);
00218 
00219     void setPos(uint pos);
00220     void setMark(int mark);
00221 
00222 
00232     BasicElement* getElement() { return current; }
00233     const BasicElement* getElement() const { return current; }
00234 
00235 
00242     void normalize(Direction direction = beforeCursor);
00243 
00244 
00248     SequenceElement* normal();
00249     const SequenceElement* normal() const;
00250 
00255     IndexElement* getActiveIndexElement();
00256 
00261     RootElement* getActiveRootElement();
00262 
00267     SymbolElement* getActiveSymbolElement();
00268 
00273     NameSequence* getActiveNameSequence();
00274 
00278     TextElement* getActiveTextElement();
00279 
00283     MatrixElement* getActiveMatrixElement();
00284 
00289     void selectActiveElement();
00290 
00294     void copy( QDomDocument& doc );
00295 
00300     bool buildElementsFromDom( QDomElement root, QPtrList<BasicElement>& list );
00301 
00306     bool buildElementsFromMathMLDom( QDomElement root, QPtrList<BasicElement>& list );
00307 
00308     // undo/redo support
00309 
00315     class CursorData {
00316         friend class FormulaCursor;
00317         BasicElement* current;
00318         uint cursorPos;
00319         int markPos;
00320         bool selectionFlag;
00321         bool linearMovement;
00322         bool readOnly;
00323 
00324         CursorData(BasicElement* c,
00325                    uint pos, int mark, bool selection, bool linear, bool ro)
00326             : current(c), cursorPos(pos), markPos(mark),
00327               selectionFlag(selection), linearMovement(linear),
00328               readOnly(ro) {}
00329     };
00330 
00335     CursorData* getCursorData();
00336 
00341     void setCursorData(CursorData* data);
00342 
00346     void elementWillVanish(BasicElement* element);
00347 
00351     void formulaLoaded(FormulaElement* rootElement);
00352 
00356     const LuPixelPoint& getCursorPoint() const { return cursorPoint; }
00357 
00361     const LuPixelRect& getCursorSize() const { return cursorSize; }
00362     void addCursorSize( const LuPixelRect& rect ) { cursorSize |= rect; }
00363 
00367     bool isReadOnly() const;
00368 
00372     void setReadOnly(bool ro) { readOnly = ro; }
00373 
00374 private:
00375 
00383     BasicElement* getActiveChild(Direction direction);
00384 
00391     BasicElement* getSelectedChild();
00392 
00397     bool pointsAfterMainChild(BasicElement*);
00398 
00402     void handleSelectState(int flag);
00403 
00404 
00408     BasicElement* current;
00409 
00416     uint cursorPos;
00417 
00424     int markPos;
00425 
00430     bool selectionFlag;
00431 
00436     bool linearMovement;
00437 
00442     LuPixelPoint cursorPoint;
00443 
00448     LuPixelRect cursorSize;
00449 
00455     bool hasChangedFlag;
00456 
00460     bool readOnly;
00461 };
00462 
00463 KFORMULA_NAMESPACE_END
00464 
00465 #endif // FORMULACURSOR_H
KDE Home | KDE Accessibility Home | Description of Access Keys