kformulacommand.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 KFORMULACOMMAND_H
22#define KFORMULACOMMAND_H
23
24#include <tqmap.h>
25#include <tqptrlist.h>
26#include <tqptrdict.h>
27#include <tqvaluevector.h>
28
29#include <kcommand.h>
30
31#include "fontstyle.h"
32#include "kformulacontainer.h"
33#include "formulacursor.h"
34
35KFORMULA_NAMESPACE_BEGIN
36
37
53{
54public:
55
64 PlainCommand(const TQString& name);
65 virtual ~PlainCommand();
66
70 static int getEvilDestructionCount() { return evilDestructionCount; }
71
72private:
73
74 // debug
75 static int evilDestructionCount;
76};
77
78
79class Command : public PlainCommand
80{
81public:
82
92 Command(const TQString& name, Container* document);
93 virtual ~Command();
94
95protected:
96
101 FormulaCursor* getExecuteCursor();
102
107 FormulaCursor* getUnexecuteCursor();
108
112 void setExecuteCursor(FormulaCursor* cursor);
113
120 void setUnexecuteCursor(FormulaCursor* cursor);
121
126 FormulaCursor* getActiveCursor() { return doc->activeCursor(); }
127
132 void testDirty() { doc->testDirty(); }
133
137 Container* getDocument() const { return doc; }
138
139private:
140
141 void destroyUndoCursor() { delete undocursor; undocursor = 0; }
142
146 FormulaCursor::CursorData* cursordata;
147
151 FormulaCursor::CursorData* undocursor;
152
156 Container* doc;
157};
158
159
163class KFCAdd : public Command
164{
165public:
166
167 KFCAdd(const TQString &name, Container* document);
168
169 virtual void execute();
170 virtual void unexecute();
171
175 void addElement(BasicElement* element) { addList.append(element); }
176
177private:
178
183 TQPtrList<BasicElement> addList;
184};
185
186
191class KFCRemoveSelection : public Command
192{
193public:
194
199 Direction dir = beforeCursor);
200
201 virtual void execute();
202 virtual void unexecute();
203
204private:
205
210 TQPtrList<BasicElement> removedList;
211
212 Direction dir;
213};
214
215
220class KFCReplace : public KFCAdd
221{
222public:
223
224 KFCReplace(const TQString &name, Container* document);
225 ~KFCReplace();
226
227 virtual void execute();
228 virtual void unexecute();
229
230private:
231
235 KFCRemoveSelection* removeSelection;
236};
237
241class KFCAddToken : public Command
242{
243public:
244 KFCAddToken( const TQString &name, Container *document);
245 ~KFCAddToken();
246
247 virtual void execute();
248 virtual void unexecute();
249
253 void addToken( BasicElement* element );
254
258 void addContent( BasicElement* element, BasicElement* content ) {
259 contentList.find( element )->append( content );
260 }
261
262
263private:
264
268 TQPtrList< BasicElement > tokenList;
269
273 TQPtrDict< TQPtrList< BasicElement > > contentList;
274};
275
281{
282public:
283
284 KFCReplaceToken(const TQString &name, Container* document);
286
287 virtual void execute();
288 virtual void unexecute();
289
290private:
291
295 KFCRemoveSelection* removeSelection;
296
297};
298
299
306{
307public:
308
309 KFCSplitToken(const TQString &name, Container* document);
311
312 virtual void execute();
313 virtual void unexecute();
314
318 void addCursor( FormulaCursor* cursor ) { setExecuteCursor( cursor ); }
319
320private:
321
325 KFCRemoveSelection* removeSelection;
326
330 TQPtrList< BasicElement > splitList;
331
336 FormulaCursor::CursorData* splitCursor;
337};
338
339
344class KFCRemove : public Command
345{
346public:
347
351 KFCRemove(Container* document, Direction dir);
352 ~KFCRemove();
353
354 virtual void execute();
355 virtual void unexecute();
356
361 //virtual bool isSenseless() { return removedList.isEmpty(); }
362
363private:
364
369 TQPtrList<BasicElement> removedList;
370
374 BasicElement* element;
375
381 FormulaCursor::CursorData* simpleRemoveCursor;
382
383 Direction dir;
384};
385
386
390class KFCRemoveEnclosing : public Command
391{
392public:
393 KFCRemoveEnclosing(Container* document, Direction dir);
395
396 virtual void execute();
397 virtual void unexecute();
398
399private:
400 BasicElement* element;
401
402 Direction direction;
403};
404
405
410class KFCAddReplacing : public Command
411{
412public:
413 KFCAddReplacing(const TQString &name, Container* document);
415
416 virtual void execute();
417 virtual void unexecute();
418
419 void setElement(BasicElement* e) { element = e; }
420
421private:
422
426 BasicElement* element;
427};
428
429
435{
436public:
437
438 KFCAddGenericIndex(Container* document, ElementIndexPtr &index);
439 KFCAddGenericIndex(KFCAddGenericIndex const &) = delete;
440 KFCAddGenericIndex& operator=(KFCAddGenericIndex const &) = delete;
441
442 virtual void execute();
443
444private:
445 ElementIndexPtr index;
446};
447
448
449class IndexElement;
450
455{
456public:
457
458 KFCAddIndex(Container* document, IndexElement* element, ElementIndexPtr index);
459 ~KFCAddIndex();
460
461 virtual void execute();
462 virtual void unexecute();
463
464private:
465 KFCAddGenericIndex addIndex;
466};
467
468
469class FormulaElement;
470
471class KFCChangeBaseSize : public PlainCommand {
472public:
473 KFCChangeBaseSize( const TQString& name, Container* document, FormulaElement* formula, int size );
474
475 void execute();
476 void unexecute();
477
478private:
479 Container* m_document;
480 FormulaElement* m_formula;
481 int m_size;
482 int m_oldSize;
483};
484
485
490class FontCommand : public Command {
491public:
492 FontCommand( const TQString& name, Container* document );
493
497 void addTextElement( TextElement* element ) { list.append(element); }
498
502 void addElement( BasicElement* element ) { elementList.append( element ); }
503
504protected:
505
506 TQPtrList<TextElement>& childrenList() { return list; }
507
508 void collectChildren();
509
510 void parseSequences( const TQMap<SequenceElement*, int>& parents );
511
512private:
513
518 TQPtrList<TextElement> list;
519
520 TQPtrList<BasicElement> elementList;
521};
522
523
528public:
529 CharStyleCommand( CharStyle cs, const TQString& name, Container* document );
530
531 virtual void execute();
532 virtual void unexecute();
533
534private:
535
536 typedef TQValueVector<CharStyle> StyleList;
537
538 StyleList styleList;
539 CharStyle charStyle;
540};
541
542
547public:
548 CharFamilyCommand( CharFamily cf, const TQString& name, Container* document );
549
550 virtual void execute();
551 virtual void unexecute();
552
553private:
554
555 typedef TQValueVector<CharFamily> FamilyList;
556
557 FamilyList familyList;
558 CharFamily charFamily;
559};
560
561
562KFORMULA_NAMESPACE_END
563
564#endif // KFORMULACOMMAND_H
Basis of every formula element.
Changes the char family of a number of elements an their children.
Changes the char style of a number of elements an their children.
The document.
Base for all font commands that act on the current selection.
void addTextElement(TextElement *element)
Collects all elements that are to be modified.
void addElement(BasicElement *element)
Collects all parent elements those children are to be changend.
A black box that is supposed to contain everything which is needed to describe a cursor.
The selection.
The main element.
The element with up to four indexes in the four corners.
virtual void unexecute()=0
virtual void execute()=0
Add an IndexElement.
The command that takes the main child out of the selected element and replaces the element with it.
Command to add a token element, with content.
void addContent(BasicElement *element, BasicElement *content)
Collect content for each token.
void addToken(BasicElement *element)
Collect all tokens that are to be added.
Base for all commands that want to add a simple element.
void addElement(BasicElement *element)
Collects all elements that are to be added.
Command to remove the parent element.
Command that is used to remove the current selection if we want to replace it with another element.
Command that is used to remove the currently selected element.
Removes the current selection and adds any new tokens afterwards.
Removes the current selection and adds any new elements afterwards.
Add and remove arbitrary token elements and their contents.
void addCursor(FormulaCursor *cursor)
Collect cursor data that will be needed to do the stuff properly.
virtual TQString name() const
Base for all kformula commands.
static int getEvilDestructionCount()
debug only.
An element that represents one char.
Definition textelement.h:37