lib

kformulacommand.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 KFORMULACOMMAND_H
00022 #define KFORMULACOMMAND_H
00023 
00024 #include <qmap.h>
00025 #include <qptrlist.h>
00026 #include <qptrdict.h>
00027 #include <qvaluevector.h>
00028 
00029 #include <kcommand.h>
00030 
00031 #include "fontstyle.h"
00032 #include "kformulacontainer.h"
00033 #include "formulacursor.h"
00034 
00035 KFORMULA_NAMESPACE_BEGIN
00036 
00037 
00052 class PlainCommand : public KNamedCommand
00053 {
00054 public:
00055 
00064     PlainCommand(const QString& name);
00065     virtual ~PlainCommand();
00066 
00070     static int getEvilDestructionCount() { return evilDestructionCount; }
00071 
00072 private:
00073 
00074     // debug
00075     static int evilDestructionCount;
00076 };
00077 
00078 
00079 class Command : public PlainCommand
00080 {
00081 public:
00082 
00092     Command(const QString& name, Container* document);
00093     virtual ~Command();
00094 
00095 protected:
00096 
00101     FormulaCursor* getExecuteCursor();
00102 
00107     FormulaCursor* getUnexecuteCursor();
00108 
00112     void setExecuteCursor(FormulaCursor* cursor);
00113 
00120     void setUnexecuteCursor(FormulaCursor* cursor);
00121 
00126     FormulaCursor* getActiveCursor() { return doc->activeCursor(); }
00127 
00132     void testDirty() { doc->testDirty(); }
00133 
00137     Container* getDocument() const { return doc; }
00138 
00139 private:
00140 
00141     void destroyUndoCursor() { delete undocursor; undocursor = 0; }
00142 
00146     FormulaCursor::CursorData* cursordata;
00147 
00151     FormulaCursor::CursorData* undocursor;
00152 
00156     Container* doc;
00157 };
00158 
00159 
00163 class KFCAdd : public Command
00164 {
00165 public:
00166 
00167     KFCAdd(const QString &name, Container* document);
00168 
00169     virtual void execute();
00170     virtual void unexecute();
00171 
00175     void addElement(BasicElement* element) { addList.append(element); }
00176 
00177 private:
00178 
00183     QPtrList<BasicElement> addList;
00184 };
00185 
00186 
00191 class KFCRemoveSelection : public Command
00192 {
00193 public:
00194 
00198     KFCRemoveSelection(Container* document,
00199                        Direction dir = beforeCursor);
00200 
00201     virtual void execute();
00202     virtual void unexecute();
00203 
00204 private:
00205 
00210     QPtrList<BasicElement> removedList;
00211 
00212     Direction dir;
00213 };
00214 
00215 
00220 class KFCReplace : public KFCAdd
00221 {
00222 public:
00223 
00224     KFCReplace(const QString &name, Container* document);
00225     ~KFCReplace();
00226 
00227     virtual void execute();
00228     virtual void unexecute();
00229 
00230 private:
00231 
00235     KFCRemoveSelection* removeSelection;
00236 };
00237 
00241 class KFCAddToken : public Command
00242 {
00243 public:
00244     KFCAddToken( const QString &name, Container *document);
00245     ~KFCAddToken();
00246 
00247     virtual void execute();
00248     virtual void unexecute();
00249 
00253     void addToken( BasicElement* element );
00254 
00258     void addContent( BasicElement* element, BasicElement* content ) { 
00259         contentList.find( element )->append( content ); 
00260     }
00261 
00262 
00263 private:
00264 
00268     QPtrList< BasicElement > tokenList;
00269 
00273     QPtrDict< QPtrList< BasicElement > > contentList;
00274 };
00275 
00280 class KFCReplaceToken : public KFCAddToken
00281 {
00282 public:
00283 
00284     KFCReplaceToken(const QString &name, Container* document);
00285     ~KFCReplaceToken();
00286 
00287     virtual void execute();
00288     virtual void unexecute();
00289 
00290 private:
00291 
00295     KFCRemoveSelection* removeSelection;
00296 
00297 };
00298 
00299 
00305 class KFCSplitToken : public KFCAddToken
00306 {
00307 public:
00308 
00309     KFCSplitToken(const QString &name, Container* document);
00310     ~KFCSplitToken();
00311 
00312     virtual void execute();
00313     virtual void unexecute();
00314 
00318     void addCursor( FormulaCursor* cursor ) { setExecuteCursor( cursor ); }
00319 
00320 private:
00321 
00325     KFCRemoveSelection* removeSelection;
00326 
00330     QPtrList< BasicElement > splitList;
00331 
00336     FormulaCursor::CursorData* splitCursor;
00337 };
00338 
00339 
00344 class KFCRemove : public Command
00345 {
00346 public:
00347 
00351     KFCRemove(Container* document, Direction dir);
00352     ~KFCRemove();
00353 
00354     virtual void execute();
00355     virtual void unexecute();
00356 
00361     //virtual bool isSenseless() { return removedList.isEmpty(); }
00362 
00363 private:
00364 
00369     QPtrList<BasicElement> removedList;
00370 
00374     BasicElement* element;
00375 
00381     FormulaCursor::CursorData* simpleRemoveCursor;
00382 
00383     Direction dir;
00384 };
00385 
00386 
00390 class KFCRemoveEnclosing : public Command
00391 {
00392 public:
00393     KFCRemoveEnclosing(Container* document, Direction dir);
00394     ~KFCRemoveEnclosing();
00395 
00396     virtual void execute();
00397     virtual void unexecute();
00398 
00399 private:
00400     BasicElement* element;
00401 
00402     Direction direction;
00403 };
00404 
00405 
00410 class KFCAddReplacing : public Command
00411 {
00412 public:
00413     KFCAddReplacing(const QString &name, Container* document);
00414     ~KFCAddReplacing();
00415 
00416     virtual void execute();
00417     virtual void unexecute();
00418 
00419     void setElement(BasicElement* e) { element = e; }
00420 
00421 private:
00422 
00426     BasicElement* element;
00427 };
00428 
00429 
00434 class KFCAddGenericIndex : public KFCAdd
00435 {
00436 public:
00437 
00438     KFCAddGenericIndex(Container* document, ElementIndexPtr index);
00439 
00440     virtual void execute();
00441 
00442 private:
00443     ElementIndexPtr index;
00444 };
00445 
00446 
00447 class IndexElement;
00448 
00452 class KFCAddIndex : public KFCAddReplacing
00453 {
00454 public:
00455 
00456     KFCAddIndex(Container* document, IndexElement* element, ElementIndexPtr index);
00457     ~KFCAddIndex();
00458 
00459     virtual void execute();
00460     virtual void unexecute();
00461 
00462 private:
00463     KFCAddGenericIndex addIndex;
00464 };
00465 
00466 
00467 class FormulaElement;
00468 
00469 class KFCChangeBaseSize : public PlainCommand {
00470 public:
00471     KFCChangeBaseSize( const QString& name, Container* document, FormulaElement* formula, int size );
00472 
00473     void execute();
00474     void unexecute();
00475 
00476 private:
00477     Container* m_document;
00478     FormulaElement* m_formula;
00479     int m_size;
00480     int m_oldSize;
00481 };
00482 
00483 
00488 class FontCommand : public Command {
00489 public:
00490     FontCommand( const QString& name, Container* document );
00491 
00495     void addTextElement( TextElement* element ) { list.append(element); }
00496 
00500     void addElement( BasicElement* element ) { elementList.append( element ); }
00501 
00502 protected:
00503 
00504     QPtrList<TextElement>& childrenList() { return list; }
00505 
00506     void collectChildren();
00507 
00508     void parseSequences( const QMap<SequenceElement*, int>& parents );
00509 
00510 private:
00511 
00516     QPtrList<TextElement> list;
00517 
00518     QPtrList<BasicElement> elementList;
00519 };
00520 
00521 
00525 class CharStyleCommand : public FontCommand {
00526 public:
00527     CharStyleCommand( CharStyle cs, const QString& name, Container* document );
00528 
00529     virtual void execute();
00530     virtual void unexecute();
00531 
00532 private:
00533 
00534     typedef QValueVector<CharStyle> StyleList;
00535 
00536     StyleList styleList;
00537     CharStyle charStyle;
00538 };
00539 
00540 
00544 class CharFamilyCommand : public FontCommand {
00545 public:
00546     CharFamilyCommand( CharFamily cf, const QString& name, Container* document );
00547 
00548     virtual void execute();
00549     virtual void unexecute();
00550 
00551 private:
00552 
00553     typedef QValueVector<CharFamily> FamilyList;
00554 
00555     FamilyList familyList;
00556     CharFamily charFamily;
00557 };
00558 
00559 
00560 KFORMULA_NAMESPACE_END
00561 
00562 #endif // KFORMULACOMMAND_H
KDE Home | KDE Accessibility Home | Description of Access Keys