21#include "KoTextObject.h"
22#include "KoTextParag.h"
23#include "KoParagCounter.h"
24#include "KoTextZoomHandler.h"
25#include "KoTextCommand.h"
26#include "KoStyleCollection.h"
28#include "KoOasisContext.h"
29#include "KoVariable.h"
30#include "KoAutoFormat.h"
36#include <tdeapplication.h>
40#include <tqprogressdialog.h>
47const char KoTextObject::s_customItemChar =
'#';
49struct KoTextObject::KoTextObjectPrivate
52 KoTextObjectPrivate() {
53 afterFormattingEmitted =
false;
54 abortFormatting =
false;
56 bool afterFormattingEmitted;
61 const TQString &defaultLanguage,
bool hyphenation,
63 TQObject* parent,
const char *name )
64 : TQObject( parent, name ), m_defaultStyle( defaultStyle ), undoRedoInfo( this )
66 textdoc =
new KoTextDocument( zh,
new KoTextFormatCollection( defaultFont, TQColor(),defaultLanguage, hyphenation ) );
67 if ( tabStopWidth != -1 )
68 textdoc->setTabStops( tabStopWidth );
73 TQObject* parent,
const char *name )
74 : TQObject( parent, name ), m_defaultStyle( defaultStyle ), undoRedoInfo( this )
80void KoTextObject::init()
82 d =
new KoTextObjectPrivate;
83 m_needsSpellCheck =
true;
84 m_protectContent =
false;
86 m_availableHeight = -1;
87 m_lastFormatted = textdoc->firstParag();
88 m_highlightSelectionAdded =
false;
90 changeIntervalTimer =
new TQTimer(
this );
91 connect( changeIntervalTimer, TQ_SIGNAL( timeout() ),
92 this, TQ_SLOT( doChangeInterval() ) );
94 formatTimer =
new TQTimer(
this );
95 connect( formatTimer, TQ_SIGNAL( timeout() ),
96 this, TQ_SLOT( formatMore() ) );
99 if ( m_lastFormatted && m_defaultStyle )
100 m_lastFormatted->applyStyle( m_defaultStyle );
102 connect( textdoc, TQ_SIGNAL( paragraphDeleted( KoTextParag* ) ),
103 this, TQ_SIGNAL( paragraphDeleted( KoTextParag* ) ) );
104 connect( textdoc, TQ_SIGNAL( paragraphDeleted( KoTextParag* ) ),
105 this, TQ_SLOT( slotParagraphDeleted( KoTextParag* ) ) );
109 this, TQ_SLOT( emitRepaintChanged() ) );
111 connect(
this, TQ_SIGNAL(paragraphModified( KoTextParag*,
int,
int ,
int ) ),
112 this, TQ_SLOT(slotParagraphModified(KoTextParag *,
int,
int ,
int)));
113 connect(
this, TQ_SIGNAL(paragraphCreated( KoTextParag* )),
114 this, TQ_SLOT(slotParagraphCreated(KoTextParag *)));
117KoTextObject::~KoTextObject()
121 undoRedoInfo.clear();
122 delete textdoc; textdoc = 0;
126int KoTextObject::availableHeight()
const
128 if ( m_availableHeight == -1 )
130 Q_ASSERT( m_availableHeight != -1 );
131 return m_availableHeight;
134void KoTextObject::slotParagraphModified(KoTextParag * ,
int _type,
int ,
int)
136 if ( _type == ChangeFormat)
138 m_needsSpellCheck =
true;
141void KoTextObject::slotParagraphCreated(KoTextParag * )
143 m_needsSpellCheck =
true;
146void KoTextObject::slotParagraphDeleted(KoTextParag * parag)
148 if ( m_lastFormatted == parag )
149 m_lastFormatted = parag->next();
158 return format->pointSize();
163 kdDebug(32500) <<
"KoTextObject::zoomedFontSize: docFontSize=" <<
docFontSize
174 virtual bool visit( KoTextParag *parag,
int start,
int end )
176 for (
int i = start ; i < end ; ++i )
178 KoTextStringChar * ch = parag->at( i );
179 if ( ch->isCustom() )
188 KoHasCustomItemVisitor visitor;
189 bool noneFound = textdoc->visitSelection( selectionId, &visitor );
193void KoTextObject::slotAfterUndoRedo()
204 undoRedoInfo.clear();
208void KoTextObject::checkUndoRedoInfo( KoTextCursor * cursor, UndoRedoInfo::Type t )
210 if ( undoRedoInfo.valid() && ( t != undoRedoInfo.type || cursor != undoRedoInfo.cursor ) ) {
211 undoRedoInfo.clear();
213 undoRedoInfo.type = t;
214 undoRedoInfo.cursor = cursor;
217void KoTextObject::undo()
219 undoRedoInfo.clear();
221 KoTextCursor *cursor =
new KoTextCursor( textdoc );
222 KoTextCursor *c = textdoc->undo( cursor );
232 setLastFormattedParag( textdoc->firstParag() );
234 TQTimer::singleShot( 0,
this, TQ_SLOT( slotAfterUndoRedo() ) );
237void KoTextObject::redo()
239 undoRedoInfo.clear();
241 KoTextCursor *cursor =
new KoTextCursor( textdoc );
242 KoTextCursor *c = textdoc->redo( cursor );
249 setLastFormattedParag( textdoc->firstParag() );
251 TQTimer::singleShot( 0,
this, TQ_SLOT( slotAfterUndoRedo() ) );
254KoTextObject::UndoRedoInfo::UndoRedoInfo(
KoTextObject *to )
255 : type(
Invalid ), textobj(to), cursor( 0 )
263bool KoTextObject::UndoRedoInfo::valid()
const
265 return text.length() > 0 &&
id >= 0 && index >= 0 && type != Invalid;
268void KoTextObject::UndoRedoInfo::clear()
271 KoTextDocument* textdoc = textobj->textDocument();
276 KoTextDocCommand * cmd =
new KoTextInsertCommand( textdoc,
id, index, text.rawData(), customItemsMap, oldParagLayouts );
277 textdoc->addCommand( cmd );
278 Q_ASSERT( placeHolderCmd );
279 if ( placeHolderCmd )
282 if ( !customItemsMap.isEmpty() )
284 CustomItemsMap::Iterator it = customItemsMap.begin();
285 for ( ; it != customItemsMap.end(); ++it )
287 KoTextCustomItem * item = it.data();
290 placeHolderCmd->addCommand( itemCmd );
292 placeHolderCmd->addCommand(
new KoTextCommand( textobj, TQString() ) );
296 placeHolderCmd->addCommand(
new KoTextCommand( textobj, TQString() ) );
303 KoTextDocCommand * cmd = textobj->deleteTextCommand( textdoc,
id, index, text.rawData(), customItemsMap, oldParagLayouts );
304 textdoc->addCommand( cmd );
305 Q_ASSERT( placeHolderCmd );
306 placeHolderCmd->addCommand(
new KoTextCommand( textobj, TQString() ) );
308 if ( !customItemsMap.isEmpty() )
310 customItemsMap.deleteAll( placeHolderCmd );
324 oldParagLayouts.clear();
325 customItemsMap.clear();
331 KoTextStringChar * ch = parag->at( position );
332 if ( ch->format() ) {
333 ch->format()->addRef();
334 undoRedoInfo.text.at( index ).setFormat( ch->format() );
336 if ( ch->isCustom() )
338 kdDebug(32500) <<
"KoTextObject::copyCharFormatting moving custom item " << ch->customItem() <<
" to text's " << index <<
" char" << endl;
339 undoRedoInfo.customItemsMap.insert( index, ch->customItem() );
342 if ( moveCustomItems )
343 parag->removeCustomItem(position);
349void KoTextObject::readFormats( KoTextCursor &c1, KoTextCursor &c2,
bool copyParagLayouts,
bool moveCustomItems )
352 int oldLen = undoRedoInfo.text.length();
353 if ( c1.parag() == c2.parag() ) {
354 undoRedoInfo.text += c1.parag()->string()->toString().mid( c1.index(), c2.index() - c1.index() );
355 for (
int i = c1.index(); i < c2.index(); ++i )
358 int lastIndex = oldLen;
362 undoRedoInfo.text += c1.parag()->string()->toString().mid( c1.index(), c1.parag()->length() - 1 - c1.index() ) +
'\n';
363 for ( i = c1.index(); i < c1.parag()->length(); ++i, ++lastIndex )
366 KoTextParag *p = c1.parag()->next();
367 while ( p && p != c2.parag() ) {
368 undoRedoInfo.text += p->string()->toString().left( p->length() - 1 ) +
'\n';
370 for ( i = 0; i < p->length(); ++i )
372 lastIndex += p->length();
377 undoRedoInfo.text += c2.parag()->string()->toString().left( c2.index() );
378 for ( i = 0; i < c2.index(); ++i )
382 if ( copyParagLayouts ) {
383 KoTextParag *p = c1.parag();
385 undoRedoInfo.oldParagLayouts << p->paragLayout();
386 if ( p == c2.parag() )
395 Q_ASSERT( !undoRedoInfo.placeHolderCmd );
396 if ( undoRedoInfo.placeHolderCmd ) kdDebug(32500) << kdBacktrace();
398 emit
newCommand( undoRedoInfo.placeHolderCmd );
403 undoRedoInfo.clear();
404 undoRedoInfo.oldParagLayouts.clear();
405 undoRedoInfo.text =
" ";
406 undoRedoInfo.index = 1;
407 if ( cursor && !textdoc->hasSelection( selectionId,
true ) ) {
408 KoTextParag * p = cursor->parag();
409 undoRedoInfo.id = p->paragId();
410 undoRedoInfo.eid = p->paragId();
411 undoRedoInfo.oldParagLayouts << p->paragLayout();
414 Q_ASSERT( textdoc->hasSelection( selectionId,
true ) );
415 KoTextParag *start = textdoc->selectionStart( selectionId );
416 KoTextParag *end = textdoc->selectionEnd( selectionId );
417 undoRedoInfo.id = start->paragId();
418 undoRedoInfo.eid = end->paragId();
419 for ( ; start && start != end->next() ; start = start->next() )
421 undoRedoInfo.oldParagLayouts << start->paragLayout();
429 KoTextParag * parag = cursor->parag();
430 setLastFormattedParag( parag );
432 bool doUpdateCurrentFormat =
true;
435 checkUndoRedoInfo( cursor, UndoRedoInfo::Delete );
436 if ( !undoRedoInfo.valid() ) {
438 undoRedoInfo.id = parag->paragId();
439 undoRedoInfo.index = cursor->index();
440 undoRedoInfo.text = TQString();
441 undoRedoInfo.oldParagLayouts << parag->paragLayout();
443 if ( !cursor->atParagEnd() )
445 KoTextStringChar * ch = parag->at( cursor->index() );
446 undoRedoInfo.text += ch->c;
451 paragLayout = parag->next()->paragLayout();
453 KoTextParag *old = cursor->parag();
454 if ( cursor->remove() ) {
455 if ( old != cursor->parag() && m_lastFormatted == old )
456 m_lastFormatted = cursor->parag() ? cursor->parag()->prev() : 0;
457 undoRedoInfo.text +=
"\n";
458 undoRedoInfo.oldParagLayouts << paragLayout;
460 emit paragraphModified( old, RemoveChar, cursor->index(), 1 );
462 case ActionBackspace: {
464 if ( parag->counter() && parag->counter()->style() != KoParagCounter::STYLE_NONE && cursor->index() == 0 ) {
468 c.setDepth( parag->counter()->
depth() );
469 KCommand *cmd=setCounterCommand( cursor, c );
473 else if ( !cursor->atParagStart() )
475 checkUndoRedoInfo( cursor, UndoRedoInfo::Delete );
476 if ( !undoRedoInfo.valid() ) {
478 undoRedoInfo.id = parag->paragId();
479 undoRedoInfo.index = cursor->index();
480 undoRedoInfo.text = TQString();
481 undoRedoInfo.oldParagLayouts << parag->paragLayout();
483 undoRedoInfo.text.insert( 0, cursor->parag()->at( cursor->index()-1 ) );
485 undoRedoInfo.index = cursor->index()-1;
487 cursor->removePreviousChar();
488 emit paragraphModified( cursor->parag(), RemoveChar, cursor->index(),1 );
489 m_lastFormatted = cursor->parag();
490 }
else if ( parag->prev() ) {
491 emit paragraphDeleted( cursor->parag() );
493 textdoc->setSelectionStart( KoTextDocument::Temp, cursor );
494 cursor->gotoPreviousLetter();
495 textdoc->setSelectionEnd( KoTextDocument::Temp, cursor );
497 emit paragraphModified( cursor->parag(), AddChar, cursor->index(), cursor->parag()->length() - cursor->index() );
501 checkUndoRedoInfo( cursor, UndoRedoInfo::Return );
502 if ( !undoRedoInfo.valid() ) {
504 undoRedoInfo.id = cursor->parag()->paragId();
505 undoRedoInfo.index = cursor->index();
506 undoRedoInfo.text = TQString();
508 undoRedoInfo.text +=
"\n";
509 if ( cursor->parag() )
511 TQString last_line = cursor->parag()->toString();
512 last_line.remove(0,last_line.find(
' ')+1);
514 if( last_line.isEmpty() && cursor->parag()->counter() && cursor->parag()->counter()->
numbering() == KoParagCounter::NUM_LIST )
517 KCommand *cmd=setCounterCommand( cursor, c );
520 setLastFormattedParag( cursor->parag() );
521 cursor->parag()->setNoCounter();
527 emit
updateUI( doUpdateCurrentFormat );
531 cursor->splitAndInsertEmptyParag();
534 Q_ASSERT( cursor->parag()->prev() );
535 setLastFormattedParag( cursor->parag() );
537 doUpdateCurrentFormat =
false;
538 KoParagStyle * style = cursor->parag()->prev()->style();
542 if ( newStyle && style != newStyle )
544 doUpdateCurrentFormat =
true;
549 if ( cursor->parag()->joinBorder() && cursor->parag()->bottomBorder().width() > 0 )
550 cursor->parag()->prev()->setChanged(
true );
551 if ( cursor->parag()->joinBorder() && cursor->parag()->next() && cursor->parag()->next()->joinBorder() && cursor->parag()->bottomBorder() == cursor->parag()->next()->bottomBorder())
552 cursor->parag()->next()->setChanged(
true );
553 emit paragraphCreated( cursor->parag() );
558 if ( !cursor->atParagEnd() || cursor->parag()->next() ) {
559 checkUndoRedoInfo( cursor, UndoRedoInfo::Delete );
560 if ( !undoRedoInfo.valid() ) {
562 undoRedoInfo.id = cursor->parag()->paragId();
563 undoRedoInfo.index = cursor->index();
564 undoRedoInfo.text = TQString();
565 undoRedoInfo.oldParagLayouts << parag->paragLayout();
567 if ( cursor->atParagEnd() ) {
570 if ( cursor->remove() )
572 m_lastFormatted = cursor->parag();
573 undoRedoInfo.text +=
"\n";
574 undoRedoInfo.oldParagLayouts << paragLayout;
577 int oldLen = undoRedoInfo.text.length();
578 undoRedoInfo.text += cursor->parag()->string()->toString().mid( cursor->index() );
579 for (
int i = cursor->index(); i < cursor->parag()->length(); ++i )
582 emit paragraphModified( cursor->parag(), RemoveChar, cursor->index(), cursor->parag()->length()-cursor->index() );
588 if ( !undoRedoInfo.customItemsMap.isEmpty() )
595 emit
updateUI( doUpdateCurrentFormat );
599 const TQString &txt,
const TQString & commandName, KoTextDocument::SelectionId selectionId,
602 if ( protectContent() )
604 const bool checkNewLine = insertFlags & CheckNewLine;
606 const bool repaint = ( insertFlags &
DoNotRepaint ) == 0;
608 bool tinyRepaint = !checkNewLine;
611 if ( textdoc->hasSelection( selectionId,
true ) && removeSelected ) {
612 kdDebug() << k_funcinfo <<
"removing selection " << selectionId << endl;
614 emitNewCommand(replaceSelectionCommand( cursor, txt, commandName, selectionId, insertFlags, customItemsMap ));
619 textdoc->setSelectionStart( KoTextDocument::Temp, cursor );
620 KoTextCursor oc = *cursor;
621 kdDebug(32500) <<
"overwrite: going to insert " << txt.length() <<
" chars; idx=" << oc.index() << endl;
622 oc.setIndex( TQMIN( oc.index() + (
int)txt.length(), oc.parag()->lastCharPos() + 1 ) );
623 kdDebug(32500) <<
"overwrite: removing from " << cursor->index() <<
" to " << oc.index() << endl;
624 if ( oc.index() > cursor->index() )
626 textdoc->setSelectionEnd( KoTextDocument::Temp, &oc );
629 emitNewCommand(replaceSelectionCommand( cursor, txt, commandName, KoTextDocument::Temp, newInsertFlags, customItemsMap ));
633 KoTextCursor c2 = *cursor;
635 if ( !customItemsMap.isEmpty() )
637 checkUndoRedoInfo( cursor, UndoRedoInfo::Insert );
638 if ( !undoRedoInfo.valid() ) {
639 if ( !commandName.isNull() )
641 undoRedoInfo.id = cursor->parag()->paragId();
642 undoRedoInfo.index = cursor->index();
643 undoRedoInfo.text = TQString();
645 int oldLen = undoRedoInfo.text.length();
646 KoTextCursor oldCursor = *cursor;
647 bool wasChanged = cursor->parag()->hasChanged();
649 oldCursor.parag()->lineStartOfChar( oldCursor.index(), 0, &origLine );
652 cursor->insert( txt, checkNewLine );
654 setLastFormattedParag( checkNewLine ? oldCursor.parag() : cursor->parag() );
656 if ( !customItemsMap.isEmpty() ) {
657 customItemsMap.
insertItems( oldCursor, txt.length() );
658 undoRedoInfo.customItemsMap = customItemsMap;
662 textdoc->setSelectionStart( KoTextDocument::Temp, &oldCursor );
663 textdoc->setSelectionEnd( KoTextDocument::Temp, cursor );
665 textdoc->setFormat( KoTextDocument::Temp,
currentFormat, KoTextFormat::Format );
666 textdoc->setFormat( KoTextDocument::InputMethodPreedit,
currentFormat, KoTextFormat::Format );
667 textdoc->removeSelection( KoTextDocument::Temp );
669 if ( !customItemsMap.isEmpty() ) {
671 CustomItemsMap::Iterator it = customItemsMap.begin();
672 for ( ; it != customItemsMap.end(); ++it )
680 KoTextParag *parag = cursor->parag();
681 if ( !checkNewLine && m_lastFormatted == parag && ( !parag->next() || parag->next()->isValid() ) )
684 m_lastFormatted = m_lastFormatted->next();
694 if ( !checkNewLine && tinyRepaint && !wasChanged )
698 Q_ASSERT( cursor->parag() == oldCursor.parag() );
699 KoTextParag* parag = cursor->parag();
703 parag->setChanged(
false );
704 parag->setLineChanged( origLine - 1 );
712 if ( oldCursor.index() == 0 && oldCursor.parag()->alignment() == TQt::AlignAuto )
716 undoRedoInfo.text += txt;
717 for (
int i = 0; i < (int)txt.length(); ++i ) {
718 if ( txt[ oldLen + i ] !=
'\n' )
723 if ( !removeSelected ) {
726 if ( textdoc->removeSelection( selectionId ) && repaint )
727 selectionChangedNotify();
729 if ( !customItemsMap.isEmpty()
730 && !commandName.isNull() ) {
735 emit paragraphModified( oldCursor.parag(), AddChar, cursor->index(), txt.length() );
737 KoTextParag* p = oldCursor.parag()->next();
738 while ( p && p != cursor->parag() ) {
739 emit paragraphCreated( p );
747 if ( protectContent() )
749 kdDebug(32500) <<
"KoTextObject::pasteText cursor parag=" << cursor->parag()->paragId() << endl;
752 TQRegExp crlf( TQString::fromLatin1(
"\r\n") );
753 t.replace( crlf, TQChar(
'\n') );
755 for (
int i=0; (uint) i<t.length(); i++ ) {
756 if ( t[ i ] <
' ' && t[ i ] !=
'\n' && t[ i ] !=
'\t' )
761 int insertFlags = CheckNewLine;
762 if ( !removeSelected )
765 KoTextDocument::Standard, insertFlags );
771KCommand* KoTextObject::setParagLayoutCommand( KoTextCursor * cursor,
const KoParagLayout& paragLayout,
772 KoTextDocument::SelectionId selectionId,
int paragLayoutFlags,
773 int marginIndex,
bool createUndoRedo )
775 if ( protectContent() )
778 undoRedoInfo.type = UndoRedoInfo::Invalid;
779 if ( paragLayoutFlags != 0 )
782 if ( !textdoc->hasSelection( selectionId,
true ) ) {
783 cursor->parag()->setParagLayout( paragLayout, paragLayoutFlags, marginIndex );
784 setLastFormattedParag( cursor->parag() );
786 KoTextParag *start = textdoc->selectionStart( selectionId );
787 KoTextParag *end = textdoc->selectionEnd( selectionId );
788 for ( ; start && start != end->next() ; start = start->next() ) {
789 if ( paragLayoutFlags == KoParagLayout::BulletNumber && start->length() <= 1 )
791 start->setParagLayout( paragLayout, paragLayoutFlags, marginIndex );
793 setLastFormattedParag( start );
801 if ( createUndoRedo )
804 KoTextDocCommand * cmd =
new KoTextParagCommand( textdoc, undoRedoInfo.id, undoRedoInfo.eid,
805 undoRedoInfo.oldParagLayouts,
806 paragLayout, paragLayoutFlags,
807 (TQStyleSheetItem::Margin)marginIndex );
808 textdoc->addCommand( cmd );
809 return new KoTextCommand(
this,
"related to KoTextParagCommand" );
817 KoTextDocument::SelectionId selectionId,
818 int paragLayoutFlags,
int formatFlags,
819 bool createUndoRedo,
bool interactive )
822 paragLayoutFlags, formatFlags,
823 createUndoRedo, interactive );
824 if ( createUndoRedo && cmd )
831 KoTextDocument::SelectionId selectionId,
832 int paragLayoutFlags,
int formatFlags,
833 bool createUndoRedo,
bool interactive )
835 if ( protectContent())
839 if ( !textdoc->hasSelection( selectionId,
true ) && !cursor)
851 KCommand* cmd = setParagLayoutCommand( cursor, newStyle->paragLayout(), selectionId, paragLayoutFlags, -1, createUndoRedo );
857 KoTextParag * firstParag;
858 KoTextParag * lastParag;
859 if ( !textdoc->hasSelection( selectionId,
true ) ) {
861 firstParag = cursor->parag();
862 lastParag = cursor->parag();
866 firstParag = textdoc->selectionStart( selectionId );
867 lastParag = textdoc->selectionEnd( selectionId );
870 if ( formatFlags != 0 )
872 KoTextFormat * newFormat = textdoc->formatCollection()->format( &newStyle->
format() );
874 if ( createUndoRedo )
876 TQValueList<KoTextFormat *> lstFormats;
878 for ( KoTextParag * parag = firstParag ; parag && parag != lastParag->next() ; parag = parag->next() )
881 lstFormats.append( parag->paragFormat() );
883 KoTextCursor c1( textdoc );
884 c1.setParag( firstParag );
886 KoTextCursor c2( textdoc );
887 c2.setParag( lastParag );
888 c2.setIndex( lastParag->string()->length() );
889 undoRedoInfo.clear();
890 undoRedoInfo.type = UndoRedoInfo::Invalid;
891 readFormats( c1, c2 );
894 lastParag->paragId(), c2.index(),
895 undoRedoInfo.text.rawData(), newFormat,
897 textdoc->addCommand( cmd );
902 lstFormats, newFormat );
903 textdoc->addCommand( cmd );
908 for ( KoTextParag * parag = firstParag ; parag && parag != lastParag->next() ; parag = parag->next() )
912 parag->setFormat( 0, parag->string()->length(), newFormat,
true, formatFlags );
913 parag->setFormat( newFormat );
920 TQPtrListIterator<KoTextCustomItem> cit( textdoc->allCustomItems() );
921 for ( ; cit.current() ; ++cit )
922 cit.current()->resize();
927 setLastFormattedParag( firstParag );
934 undoRedoInfo.clear();
942 kdDebug(32500) <<
"KoTextObject::applyStyleChange " << changed.count() <<
" styles." << endl;
943 for( KoStyleChangeDefMap::const_iterator it = changed.begin(); it != changed.end(); ++it ) {
944 kdDebug(32500) <<
" " << it.key()->name()
945 <<
" paragLayoutChanged=" << (*it).paragLayoutChanged
946 <<
" formatChanged=" << (*it).formatChanged
951 KoTextParag *p = textdoc->firstParag();
953 KoStyleChangeDefMap::Iterator it = changed.find( p->style() );
954 if ( it != changed.end() )
956 if ( (*it).paragLayoutChanged == -1 || (*it).formatChanged == -1 )
958 p->setStyle( m_defaultStyle );
964 KoTextCursor cursor( textdoc );
965 cursor.setParag( p );
966 cursor.setIndex( 0 );
969 KoTextDocument::Temp,
970 (*it).paragLayoutChanged, (*it).formatChanged,
979 setLastFormattedParag( textdoc->firstParag() );
988 textdoc->selectAll( KoTextDocument::Temp );
990 textdoc->removeSelection( KoTextDocument::Temp );
997 if ( protectContent() )
1004 bool isNewFormat = ( pCurrentFormat && *pCurrentFormat && (*pCurrentFormat)->key() != format->key() );
1005 if ( isNewFormat || !pCurrentFormat )
1008 int origFontSize = 0;
1011 origFontSize = format->pointSize();
1017 if ( pCurrentFormat )
1018 (*pCurrentFormat)->removeRef();
1020 newFormat = textdoc->formatCollection()->format( format );
1021 if ( newFormat->isMisspelled() ) {
1023 newFormat->removeRef();
1024 fNoMisspelled.setMisspelled(
false );
1025 newFormat = textdoc->formatCollection()->format( &fNoMisspelled );
1027 if ( pCurrentFormat )
1028 (*pCurrentFormat) = newFormat;
1031 if ( textdoc->hasSelection( selectionId,
true ) ) {
1033 KoTextCursor c1 = textdoc->selectionStartCursor( selectionId );
1034 KoTextCursor c2 = textdoc->selectionEndCursor( selectionId );
1035 undoRedoInfo.clear();
1036 int id = c1.parag()->paragId();
1037 int index = c1.index();
1038 int eid = c2.parag()->paragId();
1039 int eindex = c2.index();
1040 readFormats( c1, c2 );
1042 textdoc->setFormat( selectionId, format, flags );
1043 if ( !undoRedoInfo.customItemsMap.isEmpty() )
1046 CustomItemsMap::Iterator it = undoRedoInfo.customItemsMap.begin();
1047 for ( ; it != undoRedoInfo.customItemsMap.end(); ++it )
1048 it.data()->resize();
1051 textdoc,
id, index, eid, eindex, undoRedoInfo.text.rawData(),
1053 textdoc->addCommand( cmd );
1055 undoRedoInfo.clear();
1056 setLastFormattedParag( c1.parag() );
1061 if ( isNewFormat ) {
1064 if ( cursor && cursor->index() == cursor->parag()->length() - 1 ) {
1065 newFormat->addRef();
1066 cursor->parag()->string()->setFormat( cursor->index(), newFormat,
true );
1067 if ( cursor->parag()->length() == 1 ) {
1068 newFormat->addRef();
1069 cursor->parag()->setFormat( newFormat );
1070 cursor->parag()->invalidate(0);
1071 cursor->parag()->format();
1081 if ( protectContent() )
1088void KoTextObject::emitNewCommand(
KCommand *cmd)
1094KCommand *KoTextObject::setCounterCommand( KoTextCursor * cursor,
const KoParagCounter & counter, KoTextDocument::SelectionId selectionId )
1096 if ( protectContent() )
1098 const KoParagCounter * curCounter = 0L;
1100 curCounter=cursor->parag()->counter();
1101 if ( !textdoc->hasSelection( selectionId,
true ) &&
1102 curCounter && counter == *curCounter ) {
1107 if ( !textdoc->hasSelection( selectionId,
true ) && cursor) {
1108 cursor->parag()->setCounter( counter );
1109 setLastFormattedParag( cursor->parag() );
1111 KoTextParag *start = textdoc->selectionStart( selectionId );
1112 KoTextParag *end = textdoc->selectionEnd( selectionId );
1115 if ( start != end && end->length() <= 1 )
1118 undoRedoInfo.eid = end->paragId();
1121 setLastFormattedParag( start );
1122 for ( ; start && start != end->next() ; start = start->next() )
1124 if ( start->length() > 1 )
1125 start->setCounter( counter );
1130 if ( !undoRedoInfo.newParagLayout.counter )
1131 undoRedoInfo.newParagLayout.counter =
new KoParagCounter;
1132 *undoRedoInfo.newParagLayout.counter = counter;
1133 KoTextParagCommand *cmd =
new KoTextParagCommand(
1134 textdoc, undoRedoInfo.id, undoRedoInfo.eid,
1135 undoRedoInfo.oldParagLayouts, undoRedoInfo.newParagLayout,
1136 KoParagLayout::BulletNumber );
1137 textdoc->addCommand( cmd );
1139 undoRedoInfo.clear();
1142 return new KoTextCommand(
this, i18n(
"Change List Type") );
1145KCommand * KoTextObject::setAlignCommand( KoTextCursor * cursor,
int align, KoTextDocument::SelectionId selectionId )
1147 if ( protectContent() )
1149 if ( !textdoc->hasSelection( selectionId,
true ) && cursor &&
1150 (
int)cursor->parag()->alignment() == align )
1155 if ( !textdoc->hasSelection( selectionId,
true ) &&cursor ) {
1156 cursor->parag()->setAlign(align);
1157 setLastFormattedParag( cursor->parag() );
1161 KoTextParag *start = textdoc->selectionStart( selectionId );
1162 KoTextParag *end = textdoc->selectionEnd( selectionId );
1163 setLastFormattedParag( start );
1164 for ( ; start && start != end->next() ; start = start->next() )
1165 start->setAlign(align);
1169 undoRedoInfo.newParagLayout.alignment = align;
1170 KoTextParagCommand *cmd =
new KoTextParagCommand(
1171 textdoc, undoRedoInfo.id, undoRedoInfo.eid,
1172 undoRedoInfo.oldParagLayouts, undoRedoInfo.newParagLayout,
1173 KoParagLayout::Alignment );
1174 textdoc->addCommand( cmd );
1175 undoRedoInfo.clear();
1178 return new KoTextCommand(
this, i18n(
"Change Alignment") );
1181KCommand * KoTextObject::setMarginCommand( KoTextCursor * cursor, TQStyleSheetItem::Margin m,
double margin , KoTextDocument::SelectionId selectionId ) {
1182 if ( protectContent() )
1187 if ( !textdoc->hasSelection( selectionId,
true ) && cursor &&
1188 cursor->parag()->margin(m) == margin )
1193 if ( !textdoc->hasSelection( selectionId,
true )&&cursor ) {
1194 cursor->parag()->setMargin(m, margin);
1195 setLastFormattedParag( cursor->parag() );
1199 KoTextParag *start = textdoc->selectionStart( selectionId );
1200 KoTextParag *end = textdoc->selectionEnd( selectionId );
1201 setLastFormattedParag( start );
1202 for ( ; start && start != end->next() ; start = start->next() )
1203 start->setMargin(m, margin);
1207 undoRedoInfo.newParagLayout.margins[m] = margin;
1208 KoTextParagCommand *cmd =
new KoTextParagCommand(
1209 textdoc, undoRedoInfo.id, undoRedoInfo.eid,
1210 undoRedoInfo.oldParagLayouts, undoRedoInfo.newParagLayout,
1211 KoParagLayout::Margins, m );
1212 textdoc->addCommand( cmd );
1214 if ( m == TQStyleSheetItem::MarginFirstLine )
1215 name = i18n(
"Change First Line Indent");
1216 else if ( m == TQStyleSheetItem::MarginLeft || m == TQStyleSheetItem::MarginRight )
1217 name = i18n(
"Change Indent");
1219 name = i18n(
"Change Paragraph Spacing");
1220 undoRedoInfo.clear();
1223 return new KoTextCommand(
this, name );
1226KCommand * KoTextObject::setBackgroundColorCommand( KoTextCursor * cursor,
1227 const TQColor & color,
1228 KoTextDocument::SelectionId selectionId ) {
1229 if ( protectContent() )
1232 if ( !textdoc->hasSelection( selectionId,
true ) && cursor &&
1233 cursor->parag()->backgroundColor() == color )
1238 if ( !textdoc->hasSelection( selectionId,
true )&&cursor )
1241 cursor->parag()->setBackgroundColor(color);
1242 setLastFormattedParag( cursor->parag() );
1247 KoTextParag *start = textdoc->selectionStart( selectionId );
1248 KoTextParag *end = textdoc->selectionEnd( selectionId );
1249 setLastFormattedParag( start );
1250 for ( ; start && start != end->next() ; start = start->next() )
1251 start->setBackgroundColor(color);
1257 undoRedoInfo.newParagLayout.backgroundColor = color;
1258 KoTextParagCommand *cmd =
new KoTextParagCommand(
1259 textdoc, undoRedoInfo.id, undoRedoInfo.eid,
1260 undoRedoInfo.oldParagLayouts, undoRedoInfo.newParagLayout,
1261 KoParagLayout::BackgroundColor );
1262 textdoc->addCommand( cmd );
1263 undoRedoInfo.clear();
1267 return new KoTextCommand(
this, i18n(
"Change Paragraph Background Color" ) );
1270KCommand * KoTextObject::setLineSpacingCommand( KoTextCursor * cursor,
double spacing,
KoParagLayout::SpacingType _type, KoTextDocument::SelectionId selectionId )
1272 if ( protectContent() )
1278 if ( !textdoc->hasSelection( selectionId,
true ) && cursor &&
1279 cursor->parag()->kwLineSpacing() == spacing
1280 && cursor->parag()->kwLineSpacingType() == _type)
1285 if ( !textdoc->hasSelection( selectionId,
true ) && cursor ) {
1286 cursor->parag()->setLineSpacing(spacing);
1287 cursor->parag()->setLineSpacingType( _type);
1288 setLastFormattedParag( cursor->parag() );
1292 KoTextParag *start = textdoc->selectionStart( selectionId );
1293 KoTextParag *end = textdoc->selectionEnd( selectionId );
1294 setLastFormattedParag( start );
1295 for ( ; start && start != end->next() ; start = start->next() )
1297 start->setLineSpacing(spacing);
1298 start->setLineSpacingType( _type);
1303 undoRedoInfo.newParagLayout.setLineSpacingValue( spacing );
1304 undoRedoInfo.newParagLayout.lineSpacingType = _type;
1305 KoTextParagCommand *cmd =
new KoTextParagCommand(
1306 textdoc, undoRedoInfo.id, undoRedoInfo.eid,
1307 undoRedoInfo.oldParagLayouts, undoRedoInfo.newParagLayout,
1308 KoParagLayout::LineSpacing );
1309 textdoc->addCommand( cmd );
1311 undoRedoInfo.clear();
1313 return new KoTextCommand(
this, i18n(
"Change Line Spacing") );
1317KCommand * KoTextObject::setBordersCommand( KoTextCursor * cursor,
const KoBorder& leftBorder,
const KoBorder& rightBorder,
const KoBorder& topBorder,
const KoBorder& bottomBorder , KoTextDocument::SelectionId selectionId )
1319 if ( protectContent() )
1321 if ( !textdoc->hasSelection( selectionId,
true ) && cursor &&
1322 cursor->parag()->leftBorder() ==leftBorder &&
1323 cursor->parag()->rightBorder() ==rightBorder &&
1324 cursor->parag()->topBorder() ==topBorder &&
1325 cursor->parag()->bottomBorder() ==bottomBorder )
1330 if ( !textdoc->hasSelection( selectionId,
true ) ) {
1331 cursor->parag()->setLeftBorder(leftBorder);
1332 cursor->parag()->setRightBorder(rightBorder);
1333 cursor->parag()->setBottomBorder(bottomBorder);
1334 cursor->parag()->setTopBorder(topBorder);
1335 setLastFormattedParag( cursor->parag() );
1337 if ( cursor->parag()->next() )
1338 cursor->parag()->next()->setChanged(
true );
1339 if ( cursor->parag()->prev() )
1340 cursor->parag()->prev()->setChanged(
true );
1344 KoTextParag *start = textdoc->selectionStart( selectionId );
1345 KoTextParag *end = textdoc->selectionEnd( selectionId );
1346 setLastFormattedParag( start );
1347 for ( ; start && start != end->next() ; start = start->next() )
1349 start->setLeftBorder(leftBorder);
1350 start->setRightBorder(rightBorder);
1351 start->setTopBorder(topBorder);
1352 start->setBottomBorder(bottomBorder);
1354 textdoc->selectionStart( selectionId )->setTopBorder(topBorder);
1356 if ( start && start->prev() )
1357 start->prev()->setChanged(
true );
1358 if ( end && end->next() )
1359 end->next()->setChanged(
true );
1363 undoRedoInfo.newParagLayout.leftBorder=leftBorder;
1364 undoRedoInfo.newParagLayout.rightBorder=rightBorder;
1365 undoRedoInfo.newParagLayout.topBorder=topBorder;
1366 undoRedoInfo.newParagLayout.bottomBorder=bottomBorder;
1368 KoTextParagCommand *cmd =
new KoTextParagCommand(
1369 textdoc, undoRedoInfo.id, undoRedoInfo.eid,
1370 undoRedoInfo.oldParagLayouts, undoRedoInfo.newParagLayout,
1371 KoParagLayout::Borders, (TQStyleSheetItem::Margin)-1 );
1372 textdoc->addCommand( cmd );
1374 undoRedoInfo.clear();
1377 return new KoTextCommand(
this, i18n(
"Change Borders") );
1380KCommand * KoTextObject::setJoinBordersCommand( KoTextCursor * cursor,
bool join, KoTextDocument::SelectionId selectionId )
1382 if ( protectContent() )
1384 if ( !textdoc->hasSelection( selectionId,
true ) &&
1385 cursor && cursor->parag()->joinBorder() == join )
1390 if ( !textdoc->hasSelection( selectionId,
true ) )
1392 cursor->parag()->setJoinBorder( join );
1393 setLastFormattedParag( cursor->parag() );
1395 if ( cursor->parag()->next() )
1396 cursor->parag()->next()->setChanged(
true );
1397 if ( cursor->parag()->prev() )
1398 cursor->parag()->prev()->setChanged(
true );
1402 KoTextParag *start = textdoc->selectionStart( selectionId );
1403 KoTextParag *end = textdoc->selectionEnd( selectionId );
1404 setLastFormattedParag( start );
1405 for ( ; start && start != end->next() ; start = start->next() )
1407 start->setJoinBorder(
true );
1409 end->setJoinBorder (
true );
1411 if ( start && start->prev() )
1412 start->prev()->setChanged(
true );
1413 if ( end && end->next() )
1414 end->next()->setChanged(
true );
1419 undoRedoInfo.newParagLayout.joinBorder=join;
1421 KoTextParagCommand *cmd =
new KoTextParagCommand(
1422 textdoc, undoRedoInfo.id, undoRedoInfo.eid,
1423 undoRedoInfo.oldParagLayouts, undoRedoInfo.newParagLayout,
1424 KoParagLayout::Borders, (TQStyleSheetItem::Margin)-1 );
1425 textdoc->addCommand( cmd );
1427 undoRedoInfo.clear();
1431 return new KoTextCommand(
this, i18n(
"Change Join Borders") );
1435KCommand * KoTextObject::setTabListCommand( KoTextCursor * cursor,
const KoTabulatorList &tabList, KoTextDocument::SelectionId selectionId )
1437 if ( protectContent() )
1439 if ( !textdoc->hasSelection( selectionId,
true ) && cursor &&
1440 cursor->parag()->tabList() == tabList )
1446 if ( !textdoc->hasSelection( selectionId,
true ) && cursor ) {
1447 cursor->parag()->setTabList( tabList );
1448 setLastFormattedParag( cursor->parag() );
1452 KoTextParag *start = textdoc->selectionStart( selectionId );
1453 KoTextParag *end = textdoc->selectionEnd( selectionId );
1454 setLastFormattedParag( start );
1455 for ( ; start && start != end->next() ; start = start->next() )
1456 start->setTabList( tabList );
1461 undoRedoInfo.newParagLayout.setTabList( tabList );
1462 KoTextParagCommand *cmd =
new KoTextParagCommand(
1463 textdoc, undoRedoInfo.id, undoRedoInfo.eid,
1464 undoRedoInfo.oldParagLayouts, undoRedoInfo.newParagLayout,
1465 KoParagLayout::Tabulator);
1466 textdoc->addCommand( cmd );
1467 undoRedoInfo.clear();
1470 return new KoTextCommand(
this, i18n(
"Change Tabulator") );
1473KCommand * KoTextObject::setParagDirectionCommand( KoTextCursor * cursor, TQChar::Direction d, KoTextDocument::SelectionId selectionId )
1475 if ( protectContent() )
1477 if ( !textdoc->hasSelection( selectionId,
true ) && cursor &&
1478 cursor->parag()->direction() == d )
1484 if ( !textdoc->hasSelection( selectionId,
true ) && cursor ) {
1485 cursor->parag()->setDirection( d );
1486 setLastFormattedParag( cursor->parag() );
1490 KoTextParag *start = textdoc->selectionStart( selectionId );
1491 KoTextParag *end = textdoc->selectionEnd( selectionId );
1492 setLastFormattedParag( start );
1493 for ( ; start && start != end->next() ; start = start->next() )
1494 start->setDirection( d );
1501 undoRedoInfo.newParagLayout.direction = d;
1502 KoTextParagCommand *cmd =
new KoTextParagCommand(
1503 textdoc, undoRedoInfo.id, undoRedoInfo.eid,
1504 undoRedoInfo.oldParagLayouts, undoRedoInfo.newParagLayout,
1505 KoParagLayout::Shadow);
1506 textdoc->addCommand( cmd );
1508 undoRedoInfo.clear();
1512 return new KoTextCommand(
this, i18n(
"Change Shadow") );
1520 if ( protectContent() )
1525 checkUndoRedoInfo( cursor, UndoRedoInfo::RemoveSelected );
1526 if ( !undoRedoInfo.valid() ) {
1527 textdoc->selectionStart( selectionId, undoRedoInfo.id, undoRedoInfo.index );
1528 undoRedoInfo.text = TQString();
1532 KoTextCursor c1 = textdoc->selectionStartCursor( selectionId );
1533 KoTextCursor c2 = textdoc->selectionEndCursor( selectionId );
1534 readFormats( c1, c2,
true,
true );
1537 textdoc->removeSelectedText( selectionId, cursor );
1539 setLastFormattedParag( cursor->parag() );
1545 if(selectionId==KoTextDocument::Standard || selectionId==KoTextDocument::InputMethodPreedit)
1546 selectionChangedNotify();
1547 if ( createUndoRedo)
1548 undoRedoInfo.clear();
1551KCommand * KoTextObject::removeSelectedTextCommand( KoTextCursor * cursor, KoTextDocument::SelectionId selectionId,
bool repaint )
1553 if ( protectContent() )
1555 if ( !textdoc->hasSelection( selectionId,
true ) )
1558 undoRedoInfo.clear();
1559 textdoc->selectionStart( selectionId, undoRedoInfo.id, undoRedoInfo.index );
1560 Q_ASSERT( undoRedoInfo.id >= 0 );
1562 KoTextCursor c1 = textdoc->selectionStartCursor( selectionId );
1563 KoTextCursor c2 = textdoc->selectionEndCursor( selectionId );
1564 readFormats( c1, c2,
true,
true );
1566 textdoc->removeSelectedText( selectionId, cursor );
1570 KoTextDocCommand *cmd = deleteTextCommand( textdoc, undoRedoInfo.id, undoRedoInfo.index,
1571 undoRedoInfo.text.rawData(),
1572 undoRedoInfo.customItemsMap,
1573 undoRedoInfo.oldParagLayouts );
1574 textdoc->addCommand(cmd);
1577 if(!undoRedoInfo.customItemsMap.isEmpty())
1578 undoRedoInfo.customItemsMap.
deleteAll( macroCmd );
1580 undoRedoInfo.type = UndoRedoInfo::Invalid;
1581 undoRedoInfo.clear();
1583 selectionChangedNotify();
1587KCommand* KoTextObject::replaceSelectionCommand( KoTextCursor * cursor,
const TQString & replacement,
1588 const TQString & cmdName,
1589 KoTextDocument::SelectionId selectionId,
1591 CustomItemsMap customItemsMap )
1593 if ( protectContent() )
1596 const bool repaint = ( insertFlags &
DoNotRepaint ) == 0;
1600 KMacroCommand * macroCmd =
new KMacroCommand( cmdName );
1603 KoTextCursor c1 = textdoc->selectionStartCursor( selectionId );
1604 KoTextFormat * format = c1.parag()->at( c1.index() )->format();
1608 KCommand* removeSelCmd = removeSelectedTextCommand( cursor, selectionId, repaint );
1614 replacement, TQString() ,
1617 KoTextDocCommand * cmd =
new KoTextInsertCommand( textdoc, undoRedoInfo.id, undoRedoInfo.index,
1618 undoRedoInfo.text.rawData(),
1619 CustomItemsMap(), undoRedoInfo.oldParagLayouts );
1620 textdoc->addCommand( cmd );
1621 macroCmd->
addCommand(
new KoTextCommand(
this, TQString() ) );
1623 undoRedoInfo.type = UndoRedoInfo::Invalid;
1624 undoRedoInfo.clear();
1626 format->removeRef();
1628 setLastFormattedParag( c1.parag() );
1636 if(selectionId==KoTextDocument::Standard)
1637 selectionChangedNotify();
1642KCommand * KoTextObject::insertParagraphCommand( KoTextCursor *cursor )
1644 if ( protectContent() )
1646 return replaceSelectionCommand( cursor,
"\n", TQString(), KoTextDocument::Standard, CheckNewLine );
1651 if ( !m_highlightSelectionAdded )
1653 textdoc->addSelection( KoTextDocument::HighlightSelection );
1654 textdoc->setSelectionColor( KoTextDocument::HighlightSelection,
1655 TQApplication::palette().color( TQPalette::Active, TQColorGroup::Dark ) );
1656 textdoc->setInvertSelectionText( KoTextDocument::HighlightSelection,
true );
1657 m_highlightSelectionAdded =
true;
1660 removeHighlight(repaint);
1661 KoTextCursor cursor( textdoc );
1662 cursor.setParag( parag );
1663 cursor.setIndex( index );
1664 textdoc->setSelectionStart( KoTextDocument::HighlightSelection, &cursor );
1665 cursor.setIndex( index + length );
1666 textdoc->setSelectionEnd( KoTextDocument::HighlightSelection, &cursor );
1668 parag->setChanged(
true );
1673void KoTextObject::removeHighlight(
bool repaint)
1675 if ( textdoc->hasSelection( KoTextDocument::HighlightSelection,
true ) )
1677 KoTextParag * oldParag = textdoc->selectionStart( KoTextDocument::HighlightSelection );
1678 oldParag->setChanged(
true );
1679 textdoc->removeSelection( KoTextDocument::HighlightSelection );
1685void KoTextObject::selectAll(
bool select )
1688 textdoc->removeSelection( KoTextDocument::Standard );
1690 textdoc->selectAll( KoTextDocument::Standard );
1691 selectionChangedNotify();
1694void KoTextObject::selectionChangedNotify(
bool enableActions )
1697 if ( enableActions )
1703 m_mapViewAreas.replace( w, maxY );
1706void KoTextObject::setLastFormattedParag( KoTextParag *parag )
1709 if ( !m_lastFormatted || !parag || m_lastFormatted->paragId() >= parag->paragId() ) {
1710 m_lastFormatted = parag;
1716 if ( !textdoc->lastParag() )
1719 if ( !parag->isValid() && m_lastFormatted == 0 )
1720 m_lastFormatted = parag;
1722 while ( !parag->isValid() )
1724 if ( !m_lastFormatted ) {
1725 kdWarning() <<
"ensureFormatted for parag " << parag <<
" " << parag->paragId() <<
" still not formatted, but m_lastFormatted==0" << endl;
1729 bool ret = formatMore( TQMAX( 1, parag->paragId() - m_lastFormatted->paragId() ), emitAfterFormatting );
1738bool KoTextObject::formatMore(
int count ,
bool emitAfterFormatting )
1740 if ( ( !m_lastFormatted && d->afterFormattingEmitted )
1741 || !m_visible || m_availableHeight == -1 )
1744 if ( !textdoc->lastParag() )
1747 if ( d->abortFormatting ) {
1748 d->abortFormatting =
false;
1754 formatTimer->start( interval,
true );
1759 if ( m_lastFormatted )
1761 d->afterFormattingEmitted =
false;
1763 int viewsBottom = 0;
1764 TQMapIterator<TQWidget *, int> mapIt = m_mapViewAreas.begin();
1765 for ( ; mapIt != m_mapViewAreas.end() ; ++mapIt )
1766 viewsBottom = TQMAX( viewsBottom, mapIt.data() );
1768#ifdef DEBUG_FORMAT_MORE
1769 kdDebug(32500) <<
"formatMore " <<
name()
1770 <<
" lastFormatted id=" << m_lastFormatted->paragId()
1771 <<
" lastFormatted's top=" << m_lastFormatted->rect().top()
1772 <<
" lastFormatted's height=" << m_lastFormatted->rect().height()
1773 <<
" count=" << count <<
" viewsBottom=" << viewsBottom
1774 <<
" availableHeight=" << m_availableHeight << endl;
1776 if ( m_lastFormatted->prev() == 0 )
1780 kdDebug(32500) <<
"formatMore " <<
name() <<
". First parag -> starting timer" << endl;
1790 m_lastFormatted && bottom + m_lastFormatted->rect().height() <= m_availableHeight &&
1791 ( i < count || bottom <= viewsBottom ) ; ++i )
1793 KoTextParag* parag = m_lastFormatted;
1794#ifdef DEBUG_FORMAT_MORE
1795 kdDebug(32500) <<
"formatMore formatting " << parag <<
" id=" << parag->paragId() << endl;
1797 assert( parag->string() );
1799 bottom = parag->rect().top() + parag->rect().height();
1801 kdDebug(32500) <<
"formatMore(inside) top=" << parag->rect().top()
1802 <<
" height=" << parag->rect().height()
1803 <<
" bottom=" << bottom <<
" m_lastFormatted(next parag) = " << m_lastFormatted->next() << endl;
1807 if ( parag->counter() && parag->counter()->
numbering() == KoParagCounter::NUM_CHAPTER
1808 && parag->counter()->
depth() == 0 )
1811 if ( d->abortFormatting ) {
1812#ifdef DEBUG_FORMAT_MORE
1813 kdDebug(32500) <<
"formatMore formatting aborted. " << endl;
1815 d->abortFormatting =
false;
1819 if ( parag != m_lastFormatted )
1820 kdWarning() <<
"Some code changed m_lastFormatted during formatting! Was " << parag->paragId() <<
", is now " << m_lastFormatted->paragId() << endl;
1822 else if (!parag->isValid())
1823 kdWarning() <<
"PARAGRAPH " << parag->paragId() <<
" STILL INVALID AFTER FORMATTING" << endl;
1825 m_lastFormatted = parag->next();
1830 TQRect rect = textdoc->lastParag()->rect();
1831 bottom = rect.top() + rect.height();
1833#ifdef DEBUG_FORMAT_MORE
1835 if ( m_lastFormatted )
id = TQString(
" (%1)").arg(m_lastFormatted->paragId());
1836 kdDebug(32500) <<
"formatMore finished formatting. "
1837 <<
" bottom=" << bottom
1838 <<
" m_lastFormatted=" << m_lastFormatted <<
id
1842 if ( emitAfterFormatting )
1844 d->afterFormattingEmitted =
true;
1845 bool needMoreSpace =
false;
1847 if ( ( bottom > m_availableHeight ) ||
1848 ( m_lastFormatted && bottom + m_lastFormatted->rect().height() > m_availableHeight ) )
1849 needMoreSpace =
true;
1851 bool abort = needMoreSpace;
1855 else if ( needMoreSpace && m_lastFormatted )
1856 return formatMore( 2 );
1860 if ( m_lastFormatted )
1862 formatTimer->start( interval,
true );
1863#ifdef DEBUG_FORMAT_MORE
1864 kdDebug(32500) <<
name() <<
" formatMore: will have to format more. formatTimer->start with interval=" << interval << endl;
1869 interval = TQMAX( 0, interval );
1870#ifdef DEBUG_FORMAT_MORE
1871 kdDebug(32500) <<
name() <<
" formatMore: all formatted interval=" << interval << endl;
1875 kdDebug(32500) <<
"formatMore: " <<
name() <<
" all formatted. Took "
1876 << (double)(m_time.elapsed()) / 1000 <<
" seconds." << endl;
1884 d->abortFormatting =
true;
1887void KoTextObject::doChangeInterval()
1893void KoTextObject::typingStarted()
1896 changeIntervalTimer->stop();
1900void KoTextObject::typingDone()
1902 changeIntervalTimer->start( 100,
true );
1907KCommand *KoTextObject::changeCaseOfTextParag(
int cursorPosStart,
int cursorPosEnd,
1908 KoChangeCaseDia::TypeOfCase _type,
1909 KoTextCursor *cursor, KoTextParag *parag )
1911 if ( protectContent() )
1914 KMacroCommand * macroCmd =
new KMacroCommand( i18n(
"Change Case") );
1915 KoTextFormat *curFormat = parag->paragraphFormat();
1916 const TQString text = parag->string()->toString().mid( cursorPosStart, cursorPosEnd - cursorPosStart );
1917 int posStart = cursorPosStart;
1918 int posEnd = cursorPosStart;
1919 KoTextCursor c1( textdoc );
1920 KoTextCursor c2( textdoc );
1922 for (
int i = cursorPosStart; i < cursorPosEnd; ++i )
1924 KoTextStringChar & ch = *(parag->at(i));
1925 KoTextFormat * newFormat = ch.format();
1929 c1.setParag( parag );
1930 c1.setIndex( posStart );
1931 c2.setParag( parag );
1932 c2.setIndex( posEnd );
1935 const TQString repl = text.mid( posStart, posEnd - posStart );
1936 textdoc->setSelectionStart( KoTextDocument::Temp, &c1 );
1937 textdoc->setSelectionEnd( KoTextDocument::Temp, &c2 );
1938 macroCmd->
addCommand(replaceSelectionCommand(
1939 cursor, textChangedCase(repl,_type),
1940 TQString(), KoTextDocument::Temp));
1945 while( parag->at(i)->isCustom() && i != cursorPosEnd);
1951 if ( newFormat != curFormat )
1954 c1.setParag( parag );
1955 c1.setIndex( posStart );
1956 c2.setParag( parag );
1957 c2.setIndex( posEnd );
1960 const TQString repl = text.mid( posStart, posEnd - posStart );
1961 textdoc->setSelectionStart( KoTextDocument::Temp, &c1 );
1962 textdoc->setSelectionEnd( KoTextDocument::Temp, &c2 );
1963 macroCmd->
addCommand(replaceSelectionCommand(
1964 cursor, textChangedCase(repl,_type),
1965 TQString(), KoTextDocument::Temp));
1968 curFormat = newFormat;
1972 if ( posStart != cursorPosEnd )
1975 c1.setParag( parag );
1976 c1.setIndex( posStart );
1977 c2.setParag( parag );
1978 c2.setIndex( cursorPosEnd );
1980 textdoc->setSelectionStart( KoTextDocument::Temp, &c1 );
1981 textdoc->setSelectionEnd( KoTextDocument::Temp, &c2 );
1982 const TQString repl = text.mid( posStart, cursorPosEnd - posStart );
1983 macroCmd->
addCommand(replaceSelectionCommand(
1984 cursor, textChangedCase(repl,_type),
1985 TQString(), KoTextDocument::Temp));
1991KCommand *KoTextObject::changeCaseOfText(KoTextCursor *cursor,KoChangeCaseDia::TypeOfCase _type)
1993 if ( protectContent() )
1995 KMacroCommand * macroCmd =
new KMacroCommand( i18n(
"Change Case") );
1997 KoTextCursor start = textdoc->selectionStartCursor( KoTextDocument::Standard );
1998 KoTextCursor end = textdoc->selectionEndCursor( KoTextDocument::Standard );
2001 if ( start.parag() == end.parag() )
2003 int endIndex = TQMIN( start.parag()->length() - 1, end.index() );
2004 macroCmd->
addCommand( changeCaseOfTextParag( start.index(), endIndex, _type,
2005 cursor, start.parag() ) );
2009 macroCmd->
addCommand( changeCaseOfTextParag( start.index(), start.parag()->length() - 1, _type,
2010 cursor, start.parag() ) );
2011 KoTextParag *p = start.parag()->next();
2012 while ( p && p != end.parag() )
2014 macroCmd->
addCommand( changeCaseOfTextParag(0, p->length() - 1, _type, cursor, p ) );
2019 int endIndex = TQMIN( p->length() - 1, end.index() );
2020 macroCmd->
addCommand( changeCaseOfTextParag(0, endIndex, _type, cursor, end.parag() ));
2031TQString KoTextObject::textChangedCase(
const TQString& _text,KoChangeCaseDia::TypeOfCase _type)
2033 TQString text(_text);
2036 case KoChangeCaseDia::UpperCase:
2039 case KoChangeCaseDia::LowerCase:
2042 case KoChangeCaseDia::TitleCase:
2043 for(uint i=0;i<text.length();i++)
2047 TQChar prev = text.at(TQMAX(i-1,0));
2048 if(i==0 || prev ==
' ' || prev ==
'\n' || prev ==
'\t')
2049 text=text.replace(i, 1, text.at(i).upper() );
2051 text=text.replace(i, 1, text.at(i).lower() );
2055 case KoChangeCaseDia::ToggleCase:
2056 for(uint i=0;i<text.length();i++)
2058 TQString repl=TQString(text.at(i));
2059 if(text.at(i)!=text.at(i).upper())
2061 else if(text.at(i).lower()!=text.at(i))
2063 text=text.replace(i, 1, repl );
2066 case KoChangeCaseDia::SentenceCase:
2067 for(uint i=0;i<text.length();i++)
2071 TQChar prev = text.at(TQMAX(i-1,0));
2072 if(i==0 || prev ==
'\n' ||prev.isPunct())
2073 text=text.replace(i, 1, text.at(i).upper() );
2078 kdDebug(32500)<<
"Error in changeCaseOfText !\n";
2090 KoTextStringChar *ch = textdoc->firstParag()->at( 0 );
2091 return ch->format();
2096 KoTextParag * parag = textdoc->firstParag();
2097 return &(parag->paragLayout());
2100bool KoTextObject::rtl()
const
2102 return textdoc->firstParag()->string()->isRightToLeft();
2105void KoTextObject::loadOasisContent(
const TQDomElement &bodyElem, KoOasisContext& context, KoStyleCollection * styleColl )
2108 setLastFormattedParag( 0L );
2110 KoTextParag *lastParagraph =
textDocument()->loadOasisText( bodyElem, context, 0, styleColl, 0 );
2112 if ( !lastParagraph )
2124KoTextCursor KoTextObject::pasteOasisText(
const TQDomElement &bodyElem, KoOasisContext& context,
2125 KoTextCursor& cursor, KoStyleCollection * styleColl )
2127 KoTextCursor resultCursor( cursor );
2128 KoTextParag* lastParagraph = cursor.parag();
2129 bool removeNewline =
false;
2130 uint pos = cursor.index();
2131 if ( pos == 0 && lastParagraph->length() <= 1 ) {
2133 lastParagraph = lastParagraph->prev();
2134 lastParagraph =
textDocument()->loadOasisText( bodyElem, context, lastParagraph, styleColl, cursor.parag() );
2135 if ( lastParagraph ) {
2136 resultCursor.setParag( lastParagraph );
2137 resultCursor.setIndex( lastParagraph->length() - 1 );
2139 removeNewline =
true;
2143 for ( TQDomNode text (bodyElem.firstChild()); !text.isNull(); text = text.nextSibling() )
2145 TQDomElement tag = text.toElement();
2146 if ( tag.isNull() )
continue;
2150 TQDomElement tagToLoad = tag;
2151 if ( tag.localName() ==
"numbered-paragraph" ) {
2152 TQDomElement npchild;
2153 forEachElement( npchild, tag )
2155 if ( npchild.localName() ==
"p" || npchild.localName() ==
"h" ) {
2156 tagToLoad = npchild;
2162 if ( tagToLoad.localName() ==
"p" || tagToLoad.localName() ==
"h" ) {
2163 context.styleStack().save();
2164 context.fillStyleStack( tagToLoad, KoXmlNS::text,
"style-name",
"paragraph" );
2167 lastParagraph->loadOasisSpan( tagToLoad, context, pos,
true );
2168 context.styleStack().restore();
2170 lastParagraph->setChanged(
true );
2171 lastParagraph->invalidate( 0 );
2174 resultCursor.setParag( lastParagraph );
2175 resultCursor.setIndex( pos );
2176 resultCursor.splitAndInsertEmptyParag(
false,
true );
2177 removeNewline =
true;
2180 const_cast<TQDomElement &
>( bodyElem ).removeChild( tag );
2184 resultCursor.setParag( lastParagraph );
2185 resultCursor.setIndex( pos );
2187 lastParagraph =
textDocument()->loadOasisText( bodyElem, context, lastParagraph, styleColl, lastParagraph->next() );
2188 if ( lastParagraph != resultCursor.parag() )
2190 removeNewline =
true;
2191 resultCursor.setParag( lastParagraph );
2192 resultCursor.setIndex( lastParagraph->length() - 1 );
2195 KoTextParag* p = resultCursor.parag();
2196 if ( p ) p = p->next();
2198 if ( removeNewline && resultCursor.remove() ) {
2199 if ( m_lastFormatted == p ) {
2200 m_lastFormatted = resultCursor.parag();
2203 return resultCursor;
2206void KoTextObject::saveOasisContent( KoXmlWriter& writer, KoSavingContext& context )
const
2213 if ( protectContent() )
2215 textdoc->selectAll( KoTextDocument::Temp );
2216 KoTextCursor *cursor =
new KoTextCursor( textdoc );
2217 KCommand* cmd = setParagLayoutCommand( cursor, *newLayout, KoTextDocument::Temp,
2218 flags, marginIndex,
true );
2219 textdoc->removeSelection( KoTextDocument::Temp );
2226 if ( protectContent() )
2229 textdoc->selectAll( KoTextDocument::Temp );
2231 flags, zoomFont, KoTextDocument::Temp );
2232 textdoc->removeSelection( KoTextDocument::Temp );
2238 emit showFormatObject(format);
2241KCommand *KoTextObject::setChangeCaseOfTextCommand(KoChangeCaseDia::TypeOfCase _type)
2243 if ( protectContent() )
2245 textdoc->selectAll( KoTextDocument::Standard );
2246 KoTextCursor *cursor =
new KoTextCursor( textdoc );
2247 KCommand* cmd = changeCaseOfText(cursor, _type);
2248 textdoc->removeSelection( KoTextDocument::Standard );
2253void KoTextObject::setNeedSpellCheck(
bool b)
2255 m_needsSpellCheck = b;
2256 for (KoTextParag * parag = textdoc->firstParag(); parag ; parag = parag->next())
2257 parag->string()->setNeedsSpellCheck( b );
2260bool KoTextObject::statistics( TQProgressDialog *progress, ulong & charsWithSpace, ulong & charsWithoutSpace, ulong & words, ulong & sentences, ulong & syllables, ulong & lines,
bool selected )
2265 TQStringList subs_syl;
2266 subs_syl <<
"cial" <<
"tia" <<
"cius" <<
"cious" <<
"giu" <<
"ion" <<
"iou";
2267 TQStringList subs_syl_regexp;
2268 subs_syl_regexp <<
"sia$" <<
"ely$";
2270 TQStringList add_syl;
2271 add_syl <<
"ia" <<
"riet" <<
"dien" <<
"iu" <<
"io" <<
"ii";
2272 TQStringList add_syl_regexp;
2273 add_syl_regexp <<
"[aeiouym]bl$" <<
"[aeiou]{3}" <<
"^mc" <<
"ism$"
2274 <<
"[^l]lien" <<
"^coa[dglx]." <<
"[^gq]ua[^auieo]" <<
"dnt$";
2277 KoTextParag * parag = textdoc->firstParag();
2278 for ( ; parag ; parag = parag->next() )
2282 progress->setProgress(progress->progress()+1);
2284 kapp->processEvents();
2285 if ( progress->wasCancelled() )
2295 bool hasTrailingSpace =
true;
2297 s = parag->string()->toString();
2298 lines += parag->lines();
2300 if ( parag->hasSelection( KoTextDocument::Standard ) ) {
2301 hasTrailingSpace =
false;
2302 s = parag->string()->toString();
2303 if ( !( parag->fullSelected( KoTextDocument::Standard ) ) ) {
2304 s = s.mid( parag->selectionStart( KoTextDocument::Standard ), parag->selectionEnd( KoTextDocument::Standard ) - parag->selectionStart( KoTextDocument::Standard ) );
2305 lines+=numberOfparagraphLineSelected(parag);
2308 lines += parag->lines();
2315 for ( uint i = 0 ; i < s.length() - ( hasTrailingSpace ? 1 : 0 ) ; ++i )
2319 if ( !ch.isSpace() )
2320 ++charsWithoutSpace;
2329 TQRegExp re(
"\\s+");
2330 TQStringList wordlist = TQStringList::split(re, s);
2331 words += wordlist.count();
2332 re.setCaseSensitive(
false);
2333 for ( TQStringList::Iterator it = wordlist.begin(); it != wordlist.end(); ++it ) {
2334 TQString word = *it;
2335 re.setPattern(
"[!?.,:_\"-]");
2337 if ( word.length() <= 3 ) {
2341 re.setPattern(
"e$");
2343 re.setPattern(
"[^aeiouy]+");
2344 TQStringList syls = TQStringList::split(re, word);
2345 int word_syllables = 0;
2346 for ( TQStringList::Iterator it = subs_syl.begin(); it != subs_syl.end(); ++it ) {
2347 if( word.find(*it, 0,
false) != -1 )
2350 for ( TQStringList::Iterator it = subs_syl_regexp.begin(); it != subs_syl_regexp.end(); ++it ) {
2352 if( word.find(re) != -1 )
2355 for ( TQStringList::Iterator it = add_syl.begin(); it != add_syl.end(); ++it ) {
2356 if( word.find(*it, 0,
false) != -1 )
2359 for ( TQStringList::Iterator it = add_syl_regexp.begin(); it != add_syl_regexp.end(); ++it ) {
2361 if( word.find(re) != -1 )
2364 word_syllables += syls.count();
2365 if ( word_syllables == 0 )
2367 syllables += word_syllables;
2369 re.setCaseSensitive(
true);
2373 s = s.stripWhiteSpace();
2374 TQChar lastchar = s.at(s.length());
2375 if( ! s.isEmpty() && ! KoAutoFormat::isMark( lastchar ) ) {
2378 re.setPattern(
"[.?!]+");
2380 re.setPattern(
"\\d\\.\\d");
2381 s.replace(re,
"0,0");
2382 re.setPattern(
"[A-Z]\\.+");
2384 for ( uint i = 0 ; i < s.length() ; ++i )
2387 if ( KoAutoFormat::isMark( ch ) )
2394int KoTextObject::numberOfparagraphLineSelected( KoTextParag *parag)
2396 int indexOfLineStart;
2399 KoTextCursor c1 = textdoc->selectionStartCursor( KoTextDocument::Standard );
2400 KoTextCursor c2 = textdoc->selectionEndCursor( KoTextDocument::Standard );
2401 parag->lineStartOfChar( c1.index(), &indexOfLineStart, &lineStart );
2403 parag->lineStartOfChar( c2.index(), &indexOfLineStart, &lineEnd );
2404 return (lineEnd - lineStart+1);
2410 int variablePosition = -1;
2411 cursor.place( iPoint,
textDocument()->firstParag(),
false, &variablePosition );
2412 if ( variablePosition == -1 )
2419 KoTextStringChar * ch = parag->at( index );
2420 if ( ch->isCustom() )
2421 return dynamic_cast<KoVariable *
>( ch->customItem() );
2425const char * KoTextObject::acceptSelectionMimeType()
2427 return "application/vnd.oasis.opendocument.";
2433 const char* acceptMimeType = acceptSelectionMimeType();
2434 for (
int i = 0; (fmt = mime->format(i)); ++i )
2436 if ( TQString( fmt ).startsWith( acceptMimeType ) )
2445void KoTextObject::printRTDebug(
int info)
2447 KoTextParag* lastParag = 0;
2448 for (KoTextParag * parag = textdoc->firstParag(); parag ; parag = parag->next())
2450 assert( parag->prev() == lastParag );
2451 parag->printRTDebug( info );
2455 textdoc->formatCollection()->debug();
2461KCommand *KoTextFormatInterface::setBoldCommand(
bool on)
2464 format.setBold( on );
2468KCommand *KoTextFormatInterface::setItalicCommand(
bool on)
2471 format.setItalic( on );
2475KCommand *KoTextFormatInterface::setUnderlineCommand(
bool on )
2478 format.setUnderlineType( on ? KoTextFormat::U_SIMPLE : KoTextFormat::U_NONE);
2482KCommand *KoTextFormatInterface::setUnderlineColorCommand(
const TQColor &color )
2485 format.setTextUnderlineColor( color);
2489KCommand *KoTextFormatInterface::setDoubleUnderlineCommand(
bool on )
2492 format.setUnderlineType( on ? KoTextFormat::U_DOUBLE : KoTextFormat::U_NONE);
2496KCommand *KoTextFormatInterface::setStrikeOutCommand(
bool on )
2499 format.setStrikeOutType( on ? KoTextFormat::S_SIMPLE : KoTextFormat::S_NONE);
2503KCommand *KoTextFormatInterface::setTextBackgroundColorCommand(
const TQColor & col)
2506 format.setTextBackgroundColor( col );
2510KCommand *KoTextFormatInterface::setPointSizeCommand(
int s )
2513 format.setPointSize( s );
2517KCommand *KoTextFormatInterface::setFamilyCommand(
const TQString &font)
2520 format.setFamily( font );
2524TQColor KoTextFormatInterface::textBackgroundColor()
const
2529TQColor KoTextFormatInterface::textUnderlineColor()
const
2534TQColor KoTextFormatInterface::textColor()
const
2539bool KoTextFormatInterface::textUnderline()
const
2544bool KoTextFormatInterface::textDoubleUnderline()
const
2549bool KoTextFormatInterface::textBold()
const
2554bool KoTextFormatInterface::textStrikeOut()
const
2559bool KoTextFormatInterface::textItalic()
const
2564bool KoTextFormatInterface::textSubScript()
const
2566 return (
currentFormat()->vAlign()==KoTextFormat::AlignSubScript);
2569bool KoTextFormatInterface::textSuperScript()
const
2571 return (
currentFormat()->vAlign()==KoTextFormat::AlignSuperScript);
2574double KoTextFormatInterface::shadowDistanceX()
const
2579double KoTextFormatInterface::shadowDistanceY()
const
2584TQColor KoTextFormatInterface::shadowColor()
const
2589KoTextFormat::AttributeStyle KoTextFormatInterface::fontAttribute()
const
2594double KoTextFormatInterface::relativeTextSize()
const
2599int KoTextFormatInterface::offsetFromBaseLine()
const
2604bool KoTextFormatInterface::wordByWord()
const
2609bool KoTextFormatInterface::hyphenation()
const
2614KoTextFormat::UnderlineType KoTextFormatInterface::underlineType()
const
2619KoTextFormat::StrikeOutType KoTextFormatInterface::strikeOutType()
const
2624KoTextFormat::UnderlineStyle KoTextFormatInterface::underlineStyle()
const
2629KoTextFormat::StrikeOutStyle KoTextFormatInterface::strikeOutStyle()
const
2634TQFont KoTextFormatInterface::textFont()
const
2642TQString KoTextFormatInterface::textFontFamily()
const
2647TQString KoTextFormatInterface::language()
const
2652KCommand *KoTextFormatInterface::setTextColorCommand(
const TQColor &color)
2655 format.setColor( color );
2659KCommand *KoTextFormatInterface::setTextSubScriptCommand(
bool on)
2663 format.setVAlign(KoTextFormat::AlignNormal);
2665 format.setVAlign(KoTextFormat::AlignSubScript);
2669KCommand *KoTextFormatInterface::setTextSuperScriptCommand(
bool on)
2673 format.setVAlign(KoTextFormat::AlignNormal);
2675 format.setVAlign(KoTextFormat::AlignSuperScript);
2679KCommand *KoTextFormatInterface::setDefaultFormatCommand()
2685 KoTextFormat * format = coll->defaultFormat();
2688 kdDebug() <<
"useless call to setDefaultFormatCommand at: " << kdBacktrace() << endl;
2693KCommand *KoTextFormatInterface::setAlignCommand(
int align)
2696 format.alignment=align;
2700KCommand *KoTextFormatInterface::setHyphenationCommand(
bool _b )
2703 format.setHyphenation( _b );
2708KCommand *KoTextFormatInterface::setShadowTextCommand(
double shadowDistanceX,
double shadowDistanceY,
const TQColor& shadowColor )
2711 format.setShadow( shadowDistanceX, shadowDistanceY, shadowColor );
2715KCommand *KoTextFormatInterface::setFontAttributeCommand( KoTextFormat::AttributeStyle _att)
2718 format.setAttributeFont( _att );
2722KCommand *KoTextFormatInterface::setRelativeTextSizeCommand(
double _size )
2725 format.setRelativeTextSize( _size );
2729KCommand *KoTextFormatInterface::setOffsetFromBaseLineCommand(
int _offset )
2732 format.setOffsetFromBaseLine( _offset );
2736KCommand *KoTextFormatInterface::setWordByWordCommand(
bool _b )
2739 format.setWordByWord( _b );
2744void KoTextFormatInterface::setAlign(
int align)
2746 KCommand *cmd = setAlignCommand( align );
2747 emitNewCommand( cmd );
2750void KoTextFormatInterface::setMargin(TQStyleSheetItem::Margin m,
double margin)
2752 KCommand *cmd = setMarginCommand( m, margin );
2753 emitNewCommand( cmd );
2756void KoTextFormatInterface::setTabList(
const KoTabulatorList & tabList )
2758 KCommand *cmd = setTabListCommand( tabList );
2759 emitNewCommand( cmd );
2762void KoTextFormatInterface::setCounter(
const KoParagCounter & counter )
2764 KCommand *cmd = setCounterCommand( counter );
2765 emitNewCommand( cmd );
2768void KoTextFormatInterface::setParagLayoutFormat( KoParagLayout *newLayout,
int flags,
int marginIndex)
2771 emitNewCommand( cmd );
2775KCommand *KoTextFormatInterface::setMarginCommand(TQStyleSheetItem::Margin m,
double margin)
2778 format.margins[m]=margin;
2782KCommand *KoTextFormatInterface::setTabListCommand(
const KoTabulatorList & tabList )
2785 format.setTabList(tabList);
2789KCommand *KoTextFormatInterface::setCounterCommand(
const KoParagCounter & counter )
2793 format.counter =
new KoParagCounter;
2794 *format.counter = counter;
2798KCommand *KoTextFormatInterface::setLanguageCommand(
const TQString &_lang)
2801 format.setLanguage(_lang);
2805KoTextDocCommand *KoTextFormatInterface::deleteTextCommand( KoTextDocument *textdoc,
int id,
int index,
const TQMemArray<KoTextStringChar> & str,
const CustomItemsMap & customItemsMap,
const TQValueList<KoParagLayout> & oldParagLayouts )
2807 return textdoc->deleteTextCommand( textdoc,
id, index, str, customItemsMap, oldParagLayouts );
2810#include "KoTextObject.moc"
A CustomItemsMap associates a custom item to an index Used in the undo/redo info for insert/delete te...
void deleteAll(KMacroCommand *macroCmd)
Delete all the items from the map, adding their commands into macroCmd.
void insertItems(const KoTextCursor &startCursor, int size)
Insert all the items from the map, into the existing text.
void addCommand(KCommand *command)
const KoTextFormat & format() const
Return a format.
This is the structure associated with a paragraph (KoTextParag), to define the bullet or numbering of...
unsigned int depth() const
The level of the numbering.
Numbering numbering() const
Numbering type and style.
This class holds the paragraph-specific formatting information It's separated from KoTextParag so tha...
SpacingType
Line spacing values Assuming h is the height of the biggest char in the line, and v is the linespacin...
A paragraph style is a combination of a character style and paragraph-layout attributes,...
Base class for "visitors".
KoParagStyle * findStyle(const TQString &name) const
Find style based on the internal name name.
Wraps a KoTextDocCommand into a KCommand, for the UI In fact the KoTextDocCommand isn't even known fr...
virtual KCommand * createCommand()
Called when the item is created or 'deleted' by the user Most custom items don't need to reimplement ...
Command created when changing formatted text.
Each character (KoTextStringChar) points to a KoTextFormat that defines the formatting of that charac...
The KoTextObject is the high-level object that contains a KoTextDocument (the list of paragraphs),...
void storeParagUndoRedoInfo(KoTextCursor *cursor, KoTextDocument::SelectionId selectionId=KoTextDocument::Standard)
This prepares undoRedoInfo for a paragraph formatting change If this does too much,...
void applyStyle(KoTextCursor *cursor, const KoParagStyle *style, KoTextDocument::SelectionId selectionId=KoTextDocument::Standard, int paragLayoutFlags=KoParagLayout::All, int formatFlags=KoTextFormat::Format, bool createUndoRedo=true, bool interactive=true)
Apply a KoParagStyle to a selection.
void newPlaceHolderCommand(const TQString &name)
Creates a place holder for a command that will be completed later on.
bool hasSelection() const
return true if some text is selected
virtual const KoParagLayout * currentParagLayoutFormat() const
Use this format for displaying the properties (Align/counter/...) of the object.
void clearUndoRedoInfo()
Terminate our current undo/redo info, to start with a new one.
void repaintChanged(KoTextObject *)
Tell the world that we'd like some repainting to happen.
virtual KoTextFormat * currentFormat() const
Support for treating the whole textobject as a single object Use this format for displaying the prope...
void selectionChanged(bool hasSelection)
Tell the views that the selection changed (for cut/copy...).
void showCurrentFormat()
Same thing, when the current format (of the edit object) was changed.
void applyStyleChange(KoStyleChangeDefMap changed)
Update the paragraph that use the given style, after this style was changed.
void availableHeightNeeded()
Emitted by availableHeight() when the available height hasn't been calculated yet or is invalid.
void formattingFirstParag()
Emitted by formatMore() when formatting the first paragraph.
bool selectionHasCustomItems(KoTextDocument::SelectionId selectionId=KoTextDocument::Standard) const
returns true if the given selection has any custom item in it
int zoomedFontSize(int docFontSize) const
Return the font size in LU, for this user-visible font size in pt.
void insert(KoTextCursor *cursor, KoTextFormat *currentFormat, const TQString &text, const TQString &commandName, KoTextDocument::SelectionId selectionId=KoTextDocument::Standard, int insertFlags=DefaultInsertFlags, CustomItemsMap customItemsMap=CustomItemsMap())
The main "insert" method, including undo/redo creation/update.
void setCursor(KoTextCursor *cursor)
Special hack for undo/redo - used by KoTextView.
void doKeyboardAction(KoTextCursor *cursor, KoTextFormat *¤tFormat, KeyboardAction action)
Executes keyboard action action.
@ OverwriteMode
< if true, the text to be inserted is checked for '\n' (as a paragraph delimiter)
@ DoNotRemoveSelected
whether to remove selected text before
@ DoNotRepaint
usually we repaint in insert(), this allows to turn it off
void afterFormatting(int bottom, KoTextParag *m_lastFormatted, bool *abort)
Emitted by formatMore() after formatting a bunch of paragraphs.
void abortFormatting()
Abort the current formatMore() loop, or prevent the next one from starting.
KoVariable * variableAtPoint(const TQPoint &iPoint) const
Return the variable at the given point (in document coordinates), if any.
void removeSelectedText(KoTextCursor *cursor, KoTextDocument::SelectionId selectionId=KoTextDocument::Standard, const TQString &cmdName=TQString(), bool createUndoRedo=true)
Remove the text currently selected, including undo/redo creation/update.
void copyCharFormatting(KoTextParag *parag, int position, int index, bool moveCustomItems)
Copies a formatted char, <parag, position>, into undoRedoInfo.text, at position index.
void chapterParagraphFormatted(KoTextParag *parag)
Emitted by formatMore() when formatting a "Head 1" paragraph.
KoVariable * variableAtPosition(KoTextParag *parag, int index) const
Return the variable at the given position, if any.
KCommand * applyStyleCommand(KoTextCursor *cursor, const KoParagStyle *style, KoTextDocument::SelectionId selectionId=KoTextDocument::Standard, int paragLayoutFlags=KoParagLayout::All, int formatFlags=KoTextFormat::Format, bool createUndoRedo=true, bool interactive=true)
Helper for applyStyle.
void setViewArea(TQWidget *w, int maxY)
Set the bottom of the view - in LU.
KoTextObject(KoTextZoomHandler *zh, const TQFont &defaultFont, const TQString &defaultLanguage, bool defaultHyphenation, KoParagStyle *defaultStyle, int tabStopWidth=-1, TQObject *parent=0, const char *name=0)
Constructor.
KoTextDocument * textDocument() const
Return the text document contained in this KoTextObject.
void ensureCursorVisible()
The views should make sure the cursor is visible.
void updateUI(bool updateFormat, bool force=false)
Emitted when the formatting under the cursor may have changed.
void setFormat(KoTextCursor *cursor, KoTextFormat **currentFormat, KoTextFormat *format, int flags, bool zoomFont=false)
Set format changes on selection or current cursor.
void highlightPortion(KoTextParag *parag, int index, int length, bool repaint)
Highlighting support (for search/replace, spellchecking etc.).
static TQCString providesOasis(TQMimeSource *mime)
Check if the mimesource mime provides one of the OASIS mimetypes, and if so, return it.
virtual KCommand * setParagLayoutFormatCommand(KoParagLayout *newLayout, int flags, int marginIndex=-1)
Support for changing the format in the whole textobject.
void ensureFormatted(KoTextParag *parag, bool emitAfterFormatting=true)
Make sure that parag is formatted.
int docFontSize(KoTextFormat *format) const
Return the user-visible font size for this format (i.e.
KCommand * setFormatCommand(const KoTextFormat *format, int flags, bool zoomFont=false)
Implementation of setFormatCommand from KoTextFormatInterface - apply change to the whole document.
void pasteText(KoTextCursor *cursor, const TQString &text, KoTextFormat *currentFormat, bool removeSelected)
Paste plain text at the given cursor.
void newCommand(KCommand *cmd)
Emitted when a new command has been created and should be added to the main list of commands (usually...
This class extends KoZoomHandler to add support for WYSIWYG text layouting.
static double ptToLayoutUnitPt(double pt)
Not zoom dependent.
TQString displayName() const
The user-visible name (e.g. translated, or set by the user).
A KoVariable is a custom item, i.e.
const char * name(StdAction id)
@ Invalid
invalid property type