23#include <tqvaluelist.h>
25#include "formulacursor.h"
26#include "formulaelement.h"
27#include "indexelement.h"
28#include "kformulacommand.h"
29#include "matrixelement.h"
30#include "sequenceelement.h"
31#include "textelement.h"
32#include "tokenelement.h"
35KFORMULA_NAMESPACE_BEGIN
37int PlainCommand::evilDestructionCount = 0;
42 evilDestructionCount++;
45PlainCommand::~PlainCommand()
47 evilDestructionCount--;
50Command::Command(
const TQString &name,
Container* document)
64 if (cursordata == 0) {
65 setExecuteCursor(getActiveCursor());
96KFCAdd::KFCAdd(
const TQString &name,
Container *document)
97 : Command(
name, document)
99 addList.setAutoDelete(
true );
103void KFCAdd::execute()
106 cursor->
insert(addList, beforeCursor);
107 setUnexecuteCursor(cursor);
113void KFCAdd::unexecute()
116 cursor->
remove(addList, beforeCursor);
127 : Command(i18n(
"Remove Selected Text"), document),
130 removedList.setAutoDelete(
true );
133void KFCRemoveSelection::execute()
136 cursor->
remove(removedList, dir);
137 setUnexecuteCursor(cursor);
141void KFCRemoveSelection::unexecute()
144 cursor->
insert(removedList);
151KFCReplace::KFCReplace(
const TQString &name,
Container* document)
156KFCReplace::~KFCReplace()
158 delete removeSelection;
161void KFCReplace::execute()
163 if (getActiveCursor()->isSelection() && (removeSelection == 0)) {
166 if (removeSelection != 0) {
167 removeSelection->execute();
172void KFCReplace::unexecute()
175 if (removeSelection != 0) {
176 removeSelection->unexecute();
183KFCAddToken::KFCAddToken(
const TQString &name,
Container *document)
184 : Command(
name, document)
188KFCAddToken::~KFCAddToken()
190 TQPtrDictIterator< TQPtrList< BasicElement > > it( contentList );
191 TQPtrList< BasicElement >* list;
192 while ( ( list = it.current() ) != 0 ) {
198void KFCAddToken::execute()
200 kdDebug( DEBUGID ) << k_funcinfo << endl;
202 TQPtrList<BasicElement> tokenListTmp = tokenList;
203 cursor->
insert( tokenList, beforeCursor );
204 tokenList = tokenListTmp;
205 TQPtrListIterator< BasicElement > it( tokenList );
208 while ( (element = it.current()) != 0 ) {
210 cursor->
insert( *contentList.find( element ), beforeCursor );
213 setUnexecuteCursor( cursor );
219void KFCAddToken::unexecute()
221 kdDebug( DEBUGID ) << k_funcinfo << endl;
225 for (
int i = 0; i < tokenList.count(); i++ ) {
227 TQPtrList< BasicElement > list;
229 cursor->
remove( list, beforeCursor );
232 int pos = parent->childPos( current );
233 cursor->
setTo( parent, pos + 1);
234 cursor->
remove( list, beforeCursor );
250 tokenList.append( element );
251 contentList.insert( element,
new TQPtrList< BasicElement > );
252 contentList.find( element )->setAutoDelete(
true );
255KFCReplaceToken::KFCReplaceToken(
const TQString &name,
Container* document)
260KFCReplaceToken::~KFCReplaceToken()
262 delete removeSelection;
265void KFCReplaceToken::execute()
267 kdDebug( DEBUGID ) << k_funcinfo << endl;
268 if (getActiveCursor()->isSelection() && (removeSelection == 0)) {
271 if (removeSelection != 0) {
272 removeSelection->execute();
274 KFCAddToken::execute();
277void KFCReplaceToken::unexecute()
279 kdDebug( DEBUGID ) << k_funcinfo << endl;
280 KFCAddToken::unexecute();
281 if (removeSelection != 0) {
282 removeSelection->unexecute();
287KFCSplitToken::KFCSplitToken(
const TQString &name,
Container* document)
290 splitList.setAutoDelete(
true );
293KFCSplitToken::~KFCSplitToken()
296 delete removeSelection;
299void KFCSplitToken::execute()
302 if (getActiveCursor()->isSelection() && (removeSelection == 0)) {
305 if (removeSelection != 0) {
306 removeSelection->execute();
314 cursor->
remove( splitList, afterCursor );
315 TokenElement *token =
new TokenElement();
317 TQPtrListIterator< BasicElement > it ( splitList );
319 while ( ( element = it.current() ) != 0 ) {
323 KFCAddToken::execute();
324 cursor = getExecuteCursor();
333void KFCSplitToken::unexecute()
335 kdDebug( DEBUGID ) << k_funcinfo << endl;
336 KFCAddToken::unexecute();
339 cursor->
insert( splitList, afterCursor );
340 if (removeSelection != 0) {
341 removeSelection->unexecute();
349 : Command(i18n(
"Remove Selected Text"), document),
350 element(0), simpleRemoveCursor(0), dir(direction)
352 removedList.setAutoDelete(
true );
355KFCRemove::~KFCRemove()
357 delete simpleRemoveCursor;
361void KFCRemove::execute()
364 cursor->
remove(removedList, dir);
369 setUnexecuteCursor(cursor);
374void KFCRemove::unexecute()
382 delete simpleRemoveCursor;
383 simpleRemoveCursor = 0;
385 cursor->
insert(removedList, dir);
391KFCRemoveEnclosing::KFCRemoveEnclosing(
Container* document,
393 : Command(i18n(
"Remove Enclosing Element"), document),
394 element(0), direction(dir)
398KFCRemoveEnclosing::~KFCRemoveEnclosing()
403void KFCRemoveEnclosing::execute()
407 setUnexecuteCursor(cursor);
413void KFCRemoveEnclosing::unexecute()
428KFCAddReplacing::KFCAddReplacing(
const TQString &name,
Container* document)
429 : Command(
name, document), element(0)
433KFCAddReplacing::~KFCAddReplacing()
439void KFCAddReplacing::execute()
443 setUnexecuteCursor(cursor);
450void KFCAddReplacing::unexecute()
461KFCAddGenericIndex::KFCAddGenericIndex(
Container* document, ElementIndexPtr &_index)
462 :
KFCAdd(i18n(
"Add Index"), document), index(std::move(_index))
467void KFCAddGenericIndex::execute()
469 index->setToIndex(getActiveCursor());
474KFCAddIndex::KFCAddIndex(
Container* document,
477 addIndex(document, index)
482KFCAddIndex::~KFCAddIndex()
486void KFCAddIndex::execute()
488 KFCAddReplacing::execute();
492void KFCAddIndex::unexecute()
494 addIndex.unexecute();
495 KFCAddReplacing::unexecute();
499KFCChangeBaseSize::KFCChangeBaseSize(
const TQString& name,
Container* document,
501 :
PlainCommand(
name ), m_document( document ), m_formula( formula ), m_size( size )
503 m_oldSize = formula->getBaseSize();
506void KFCChangeBaseSize::execute()
508 m_formula->setBaseSize( m_size );
509 m_document->recalc();
512void KFCChangeBaseSize::unexecute()
514 m_formula->setBaseSize( m_oldSize );
515 m_document->recalc();
519FontCommand::FontCommand(
const TQString& name,
Container* document )
520 : Command(
name, document )
522 list.setAutoDelete(
false );
523 elementList.setAutoDelete(
false );
527void FontCommand::collectChildren()
530 uint count = elementList.count();
531 for ( uint i=0; i<count; ++i ) {
532 elementList.at( i )->dispatchFontCommand(
this );
537void FontCommand::parseSequences(
const TQMap<SequenceElement*, int>& parents )
539 TQValueList<SequenceElement*> sequences = parents.keys();
540 for ( TQValueList<SequenceElement*>::iterator i = sequences.begin();
541 i != sequences.end();
548CharStyleCommand::CharStyleCommand( CharStyle cs,
const TQString& name,
Container* document )
553void CharStyleCommand::execute()
556 TQMap<SequenceElement*, int> parentCollector;
559 uint count = childrenList().count();
560 styleList.reserve( count );
561 for ( uint i=0; i<count; ++i ) {
563 styleList[i] = child->getCharStyle();
564 child->setCharStyle( charStyle );
565 parentCollector[
static_cast<SequenceElement*
>( child->getParent() )] = 1;
567 parseSequences( parentCollector );
571void CharStyleCommand::unexecute()
573 TQMap<SequenceElement*, int> parentCollector;
574 uint count = childrenList().count();
576 for ( uint i=0; i<count; ++i ) {
578 child->setCharStyle( styleList[i] );
579 parentCollector[
static_cast<SequenceElement*
>( child->getParent() )] = 1;
581 parseSequences( parentCollector );
586CharFamilyCommand::CharFamilyCommand( CharFamily cf,
const TQString& name,
Container* document )
591void CharFamilyCommand::execute()
595 TQMap<SequenceElement*, int> parentCollector;
598 uint count = childrenList().count();
599 familyList.reserve( count );
600 for ( uint i=0; i<count; ++i ) {
602 familyList[i] = child->getCharFamily();
603 child->setCharFamily( charFamily );
604 parentCollector[
static_cast<SequenceElement*
>( child->getParent() )] = 1;
606 parseSequences( parentCollector );
610void CharFamilyCommand::unexecute()
612 TQMap<SequenceElement*, int> parentCollector;
613 uint count = childrenList().count();
615 for ( uint i=0; i<count; ++i ) {
617 child->setCharFamily( familyList[i] );
618 parentCollector[
static_cast<SequenceElement*
>( child->getParent() )] = 1;
620 parseSequences( parentCollector );
625KFORMULA_NAMESPACE_END
Basis of every formula element.
virtual void goInside(FormulaCursor *cursor)
Sets the cursor inside this element to its start position.
virtual void moveEnd(FormulaCursor *)
Moves the cursor to the last position in this sequence.
Base for all font commands that act on the current selection.
The element with up to four indexes in the four corners.
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.
Command that is used to remove the current selection if we want to replace it with another element.
KFCRemoveSelection(Container *document, Direction dir=beforeCursor)
generic add command, default implementation do nothing
KFCRemove(Container *document, Direction dir)
generic add command, default implementation do nothing
Base for all kformula commands.
PlainCommand(const TQString &name)
Sets up the command.
The element that contains a number of children.
uint countChildren() const
virtual BasicElement * getChild(FormulaCursor *, Direction=beforeCursor)
Returns the child at the cursor.
An element that represents one char.
const char * name(StdAction id)