kword

KWCommand.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 David Faure <faure@kde.org>
00003    Copyright (C) 2005 Thomas Zander <zander@kde.org>
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 #include "KWCommand.h"
00022 #include "KWDocument.h"
00023 #include "KWTextFrameSet.h"
00024 #include "KWTableStyle.h"
00025 #include "KWTableTemplate.h"
00026 #include "KWTableFrameSet.h"
00027 #include "KWPartFrameSet.h"
00028 #include "KWTextDocument.h"
00029 #include "KWTextParag.h"
00030 #include "KWAnchor.h"
00031 #include "KWVariable.h"
00032 #include "KWOasisLoader.h"
00033 #include "KWFrameList.h"
00034 #include "KWFrameSet.h"
00035 #include "KWPictureFrameSet.h"
00036 #include "KWPageManager.h"
00037 #include "KWPage.h"
00038 
00039 #include <KoTextObject.h>
00040 #include <KoOasisStyles.h>
00041 #include <KoOasisContext.h>
00042 #include <KoXmlNS.h>
00043 #include <KoDom.h>
00044 #include <KoStore.h>
00045 #include <KoOasisStore.h>
00046 
00047 #include <klocale.h>
00048 #include <kdebug.h>
00049 
00050 #include <qxml.h>
00051 #include <qbuffer.h>
00052 #include <algorithm>
00053 
00054 // Helper class for deleting all custom items
00055 // (KWTextFrameset::removeSelectedText and readFormats do that already,
00056 //  but with undo/redo, and copying all formatting etc.)
00057 class KWDeleteCustomItemVisitor : public KoParagVisitor // see kotextdocument.h
00058 {
00059 public:
00060     KWDeleteCustomItemVisitor() : KoParagVisitor() { }
00061     virtual bool visit( KoTextParag *parag, int start, int end )
00062     {
00063         kdDebug(32001) << "KWPasteTextCommand::execute " << parag->paragId() << " " << start << " " << end << endl;
00064         for ( int i = start ; i < end ; ++i )
00065         {
00066             KoTextStringChar * ch = parag->at( i );
00067             if ( ch->isCustom() ) {
00068                 KoTextCustomItem* item = ch->customItem();
00069                 item->setDeleted( true );
00070                 parag->removeCustomItem(i);
00071                 KCommand* itemCmd = item->deleteCommand();
00072                 if ( itemCmd )
00073                     itemCmd->execute();
00074             }
00075         }
00076         return true;
00077     }
00078 };
00079 
00080 #if 0 // kept for comparison with KWOasisPasteCommand
00081 KWPasteTextCommand::KWPasteTextCommand( KoTextDocument *d, int parag, int idx,
00082                                 const QCString & data )
00083     : KoTextDocCommand( d ), m_parag( parag ), m_idx( idx ), m_data( data ), m_oldParagLayout( 0 )
00084 {
00085 }
00086 
00087 KoTextCursor * KWPasteTextCommand::execute( KoTextCursor *c )
00088 {
00089     KoTextParag *firstParag = doc->paragAt( m_parag );
00090     if ( !firstParag ) {
00091         qWarning( "can't locate parag at %d, last parag: %d", m_parag, doc->lastParag()->paragId() );
00092         return 0;
00093     }
00094     //kdDebug() << "KWPasteTextCommand::execute m_parag=" << m_parag << " m_idx=" << m_idx
00095     //          << " firstParag=" << firstParag << " " << firstParag->paragId() << endl;
00096     cursor.setParag( firstParag );
00097     cursor.setIndex( m_idx );
00098     c->setParag( firstParag );
00099     c->setIndex( m_idx );
00100     QDomDocument domDoc;
00101     domDoc.setContent( m_data );
00102     QDomElement elem = domDoc.documentElement();
00103     KWTextDocument * textdoc = static_cast<KWTextDocument *>(doc);
00104     KWTextFrameSet * textFs = textdoc->textFrameSet();
00105     // We iterate twice over the list of paragraphs.
00106     // First time to gather the text,
00107     // second time to apply the character & paragraph formatting
00108     QString text;
00109 
00110     QValueList<QDomElement> listParagraphs;
00111     QDomElement paragraph = elem.firstChild().toElement();
00112     for ( ; !paragraph.isNull() ; paragraph = paragraph.nextSibling().toElement() )
00113     {
00114         if ( paragraph.tagName() == "PARAGRAPH" )
00115         {
00116             QString s = paragraph.namedItem( "TEXT" ).toElement().text();
00117             //kdDebug() << "KWPasteTextCommand::execute Inserting text: '" << s << "'" << endl;
00118             c->insert( s, false /*newline=linebreak, not new parag*/ );
00119 
00120             if ( !paragraph.nextSibling().isNull() ) // Not for last parag
00121             {
00122                 // Create new parag
00123                 // Lowlevel method:
00124                 c->splitAndInsertEmptyParag( FALSE, TRUE );
00125                 // Highlevel method:
00126                 //c->insert( "\n", true );
00127             }
00128             listParagraphs.append( paragraph );
00129         }
00130     }
00131 
00132     // Redo the parag lookup because if firstParag was empty, insert() has
00133     // shifted it down (side effect of splitAndInsertEmptyParag)
00134     firstParag = doc->paragAt( m_parag );
00135     KWTextParag * parag = static_cast<KWTextParag *>(firstParag);
00136     //kdDebug() << "KWPasteTextCommand::execute starting at parag " << parag << " " << parag->paragId() << endl;
00137     uint count = listParagraphs.count();
00138     QValueList<QDomElement>::Iterator it = listParagraphs.begin();
00139     QValueList<QDomElement>::Iterator end = listParagraphs.end();
00140     for ( uint item = 0 ; it != end ; ++it, ++item )
00141     {
00142         if (!parag)
00143         {
00144             kdWarning() << "KWPasteTextCommand: parag==0L ! KWord bug, please report." << endl;
00145             break;
00146         }
00147         QDomElement paragElem = *it;
00148         // First line (if appending to non-empty line) : apply offset to formatting, don't apply parag layout
00149         if ( item == 0 && m_idx > 0 )
00150         {
00151             // First load the default format, but only apply it to our new chars
00152             QDomElement layout = paragElem.namedItem( "LAYOUT" ).toElement();
00153             if ( !layout.isNull() )
00154             {
00155                 QDomElement formatElem = layout.namedItem( "FORMAT" ).toElement();
00156                 if ( !formatElem.isNull() )
00157                 {
00158                     KoTextFormat f = parag->loadFormat( formatElem, 0L, QFont(), KGlobal::locale()->language(),false );
00159                     KoTextFormat * defaultFormat = doc->formatCollection()->format( &f );
00160                     // Last paragraph (i.e. only one in all) : some of the text might be from before the paste
00161                     int endIndex = (item == count-1) ? c->index() : parag->string()->length() - 1;
00162                     parag->setFormat( m_idx, endIndex - m_idx, defaultFormat, TRUE );
00163                 }
00164             }
00165 
00166             parag->loadFormatting( paragElem, m_idx, (textFs->isMainFrameset()));
00167         }
00168         else
00169         {
00170             if ( item == 0 ) // This paragraph existed, store its parag layout
00171             {
00172                 delete m_oldParagLayout;
00173                 m_oldParagLayout = new KoParagLayout( parag->paragLayout() );
00174             }
00175             parag->loadLayout( paragElem );
00176             // Last paragraph: some of the text might be from before the paste
00177             int len = (item == count-1) ? c->index() : parag->string()->length();
00178             // Apply default format
00179             parag->setFormat( 0, len, parag->paragFormat(), TRUE );
00180             parag->loadFormatting( paragElem, 0, (textFs->isMainFrameset()) );
00181         }
00182         parag->invalidate(0); // the formatting will be done by caller (either KWTextFrameSet::pasteOasis or KoTextObject::undo/redo)
00183         parag->setChanged( TRUE );
00184         parag = static_cast<KWTextParag *>(parag->next());
00185         //kdDebug() << "KWPasteTextCommand::execute going to next parag: " << parag << endl;
00186     }
00187     textFs->textObject()->setNeedSpellCheck( true );
00188     // In case loadFormatting queued any image request
00189     KWDocument * doc = textFs->kWordDocument();
00190     doc->processPictureRequests();
00191 
00192     //kdDebug() << "KWPasteTextCommand::execute calling doc->pasteFrames" << endl;
00193     // In case of any inline frameset
00194     doc->pasteFrames( elem, 0,
00195                       true /*don't change footnote attribute*/ ,
00196                       (textFs->isMainFrameset()) /*load footnotes if mainframeset*/,
00197                       false /*don't select frames*/ );
00198     doc->completePasting();
00199 
00200     m_lastParag = c->parag()->paragId();
00201     m_lastIndex = c->index();
00202     return c;
00203 }
00204 
00205 KoTextCursor * KWPasteTextCommand::unexecute( KoTextCursor *c )
00206 {
00207     KoTextParag *firstParag = doc->paragAt( m_parag );
00208     if ( !firstParag ) {
00209         qWarning( "can't locate parag at %d, last parag: %d", m_parag, doc->lastParag()->paragId() );
00210         return 0;
00211     }
00212     cursor.setParag( firstParag );
00213     cursor.setIndex( m_idx );
00214     doc->setSelectionStart( KoTextDocument::Temp, &cursor );
00215 
00216     KoTextParag *lastParag = doc->paragAt( m_lastParag );
00217     if ( !lastParag ) {
00218         qWarning( "can't locate parag at %d, last parag: %d", m_lastParag, doc->lastParag()->paragId() );
00219         return 0;
00220     }
00221     Q_ASSERT( lastParag->document() );
00222     KWTextDocument * textdoc = static_cast<KWTextDocument *>(doc);
00223 
00224     //kdDebug() << "Undoing paste: deleting from (" << firstParag->paragId() << "," << m_idx << ")"
00225     //          << " to (" << lastParag->paragId() << "," << m_lastIndex << ")" << endl;
00226 
00227     cursor.setParag( lastParag );
00228     cursor.setIndex( m_lastIndex );
00229     doc->setSelectionEnd( KoTextDocument::Temp, &cursor );
00230     // Delete all custom items
00231     KWDeleteCustomItemVisitor visitor;
00232     doc->visitSelection( KoTextDocument::Temp, &visitor );
00233 
00234     doc->removeSelectedText( KoTextDocument::Temp, c /* sets c to the correct position */ );
00235 
00236     KWTextFrameSet * textFs = textdoc->textFrameSet();
00237 
00238     textFs->renumberFootNotes();
00239     if ( m_idx == 0 ) {
00240         Q_ASSERT( m_oldParagLayout );
00241         if ( m_oldParagLayout )
00242             firstParag->setParagLayout( *m_oldParagLayout );
00243     }
00244     return c;
00245 }
00246 #endif
00247 
00248 KWOasisPasteCommand::KWOasisPasteCommand( KoTextDocument *d, int parag, int idx,
00249                                 const QByteArray& data )
00250     : KoTextDocCommand( d ), m_parag( parag ), m_idx( idx ), m_data( data ), m_oldParagLayout( 0 )
00251 {
00252 }
00253 
00254 KoTextCursor * KWOasisPasteCommand::execute( KoTextCursor *c )
00255 {
00256     KoTextParag *firstParag = doc->paragAt( m_parag );
00257     if ( !firstParag ) {
00258         qWarning( "can't locate parag at %d, last parag: %d", m_parag, doc->lastParag()->paragId() );
00259         return c;
00260     }
00261     //kdDebug() << "KWOasisPasteCommand::execute m_parag=" << m_parag << " m_idx=" << m_idx
00262     //          << " firstParag=" << firstParag << " " << firstParag->paragId() << endl;
00263     cursor.setParag( firstParag );
00264     cursor.setIndex( m_idx );
00265     c->setParag( firstParag );
00266     c->setIndex( m_idx );
00267 
00268     KWTextDocument * textdoc = static_cast<KWTextDocument *>(doc);
00269 
00270     QBuffer buffer( m_data );
00271 
00272     KoStore * store = KoStore::createStore( &buffer, KoStore::Read );
00273     KWDocument* kwdoc = textdoc->textFrameSet()->kWordDocument();
00274     KWOasisLoader loader( kwdoc );
00275     loader.insertOasisData( store, c );
00276 
00277     delete store;
00278 
00279     m_lastParag = c->parag()->paragId();
00280     m_lastIndex = c->index();
00281     return c;
00282 }
00283 
00284 KoTextCursor * KWOasisPasteCommand::unexecute( KoTextCursor *c )
00285 {
00286     KoTextParag *firstParag = doc->paragAt( m_parag );
00287     if ( !firstParag ) {
00288         qWarning( "can't locate parag at %d, last parag: %d", m_parag, doc->lastParag()->paragId() );
00289         return 0;
00290     }
00291     cursor.setParag( firstParag );
00292     cursor.setIndex( m_idx );
00293     doc->setSelectionStart( KoTextDocument::Temp, &cursor );
00294 
00295     KoTextParag *lastParag = doc->paragAt( m_lastParag );
00296     if ( !lastParag ) {
00297         qWarning( "can't locate parag at %d, last parag: %d", m_lastParag, doc->lastParag()->paragId() );
00298         return 0;
00299     }
00300     Q_ASSERT( lastParag->document() );
00301     // Get hold of the document before deleting the parag
00302     KWTextDocument * textdoc = static_cast<KWTextDocument *>(doc);
00303 
00304     //kdDebug() << "Undoing paste: deleting from (" << firstParag->paragId() << "," << m_idx << ")"
00305     //          << " to (" << lastParag->paragId() << "," << m_lastIndex << ")" << endl;
00306 
00307     cursor.setParag( lastParag );
00308     cursor.setIndex( m_lastIndex );
00309     doc->setSelectionEnd( KoTextDocument::Temp, &cursor );
00310     // Delete all custom items
00311     KWDeleteCustomItemVisitor visitor;
00312     doc->visitSelection( KoTextDocument::Temp, &visitor );
00313 
00314     doc->removeSelectedText( KoTextDocument::Temp, c /* sets c to the correct position */ );
00315 
00316     KWTextFrameSet * textFs = textdoc->textFrameSet();
00317 
00318     textFs->renumberFootNotes();
00319 #if 0
00320     if ( m_idx == 0 ) {
00321         Q_ASSERT( m_oldParagLayout );
00322         if ( m_oldParagLayout )
00323             firstParag->setParagLayout( *m_oldParagLayout );
00324     }
00325 #endif
00326     return c;
00327 }
00328 
00329 
00330 KWTextDeleteCommand::KWTextDeleteCommand( KoTextDocument *d, int i, int idx, const QMemArray<KoTextStringChar> &str,
00331                          const CustomItemsMap & customItemsMap,
00332                          const QValueList<KoParagLayout> & oldParagLayouts )
00333     :KoTextDeleteCommand(d, i, idx, str, customItemsMap, oldParagLayouts)
00334 {
00335     //createBookmarkList();
00336 }
00337 
00338 void KWTextDeleteCommand::createBookmarkList()
00339 {
00340 #if 0
00341     KoTextParag *s = doc ? doc->paragAt( id ) : parag;
00342     if ( !s ) {
00343         qWarning( "can't locate parag at %d, last parag: %d", id, doc->lastParag()->paragId() );
00344         return;
00345     }
00346 
00347     // Now restore the parag layouts (i.e. libkotext specific stuff)
00348     QValueList<KoParagLayout>::Iterator lit = m_oldParagLayouts.begin();
00349     kdDebug(32500) << "KWTextDeleteCommand::createBookmarkList " << m_oldParagLayouts.count() << " parag layouts. First parag=" << s->paragId() << endl;
00350     Q_ASSERT( id == s->paragId() );
00351     KoTextParag *p = s;
00352     while ( p ) {
00353         if ( lit != m_oldParagLayouts.end() )
00354         {
00355             kdDebug(32500) << "KWTextDeleteCommand::unexecute find bookmark in parag " << p->paragId() << endl;
00356             //p->setParagLayout( *lit );
00357         }
00358         else
00359             break;
00360         p = p->next();
00361         ++lit;
00362     }
00363 #endif
00364 }
00365 
00366 KoTextCursor *KWTextDeleteCommand::execute( KoTextCursor *c )
00367 {
00368     return KoTextDeleteCommand::execute( c );
00369 }
00370 
00371 KoTextCursor *KWTextDeleteCommand::unexecute( KoTextCursor *c )
00372 {
00373     return KoTextDeleteCommand::unexecute( c );
00374 }
00375 
00377 
00378 FrameIndex::FrameIndex( KWFrame *frame )
00379 {
00380     m_pFrameSet=frame->frameSet();
00381     m_iFrameIndex=m_pFrameSet->frameFromPtr(frame);
00382 }
00383 
00384 KWFrameBorderCommand::KWFrameBorderCommand( const QString &name, QPtrList<FrameIndex> &_listFrameIndex, QPtrList<FrameBorderTypeStruct> &_frameTypeBorder,const KoBorder & _newBorder):
00385     KNamedCommand(name),
00386     m_indexFrame(_listFrameIndex),
00387     m_oldBorderFrameType(_frameTypeBorder),
00388     m_newBorder( _newBorder)
00389 {
00390 }
00391 
00392 KWFrameBorderCommand::~KWFrameBorderCommand()
00393 {
00394     m_indexFrame.setAutoDelete( true);
00395     m_oldBorderFrameType.setAutoDelete( true);
00396 }
00397 
00398 void KWFrameBorderCommand::execute()
00399 {
00400     FrameIndex *tmp;
00401     KWDocument *doc = 0L;
00402     for ( tmp=m_indexFrame.first(); tmp != 0; tmp=m_indexFrame.next() )
00403     {
00404         KWFrameSet *frameSet =tmp->m_pFrameSet;
00405         doc = frameSet->kWordDocument();
00406         KWFrame *frame=frameSet->frame(tmp->m_iFrameIndex);
00407         KWTableFrameSet::Cell *cell = dynamic_cast<KWTableFrameSet::Cell *>(frame->frameSet());
00408         FrameBorderTypeStruct *tmpFrameStruct=m_oldBorderFrameType.at(m_indexFrame.find(tmp));
00409 
00410         switch( tmpFrameStruct->m_EFrameType)
00411         {
00412             case KoBorder::LeftBorder:
00413                 if(cell) // is a table cell
00414                     cell->setLeftBorder(m_newBorder);
00415                 else
00416                     frame->setLeftBorder(m_newBorder);
00417                 break;
00418             case KoBorder::RightBorder:
00419                 if(cell) // is a table cell
00420                     cell->setRightBorder(m_newBorder);
00421                 else
00422                      frame->setRightBorder(m_newBorder);
00423                 break;
00424             case KoBorder::TopBorder:
00425                 if(cell) // is a table cell
00426                     cell->setTopBorder(m_newBorder);
00427                 else
00428                       frame->setTopBorder(m_newBorder);
00429                 break;
00430             case KoBorder::BottomBorder:
00431                 if(cell) // is a table cell
00432                     cell->setBottomBorder(m_newBorder);
00433                 else
00434                     frame->setBottomBorder(m_newBorder);
00435                 break;
00436             default:
00437                 break;
00438         }
00439 
00440         if (!cell) {
00441             frame->frameBordersChanged();
00442             //fixme frameBorderChanged for table cells here too ?
00443         }
00444     }
00445 
00446 
00447     if ( doc )
00448     {
00449         doc->repaintAllViews();
00450     }
00451 }
00452 
00453 void KWFrameBorderCommand::unexecute()
00454 {
00455     FrameIndex *tmp;
00456     KWDocument *doc = 0L;
00457     for ( tmp=m_indexFrame.first(); tmp != 0; tmp=m_indexFrame.next() )
00458     {
00459         KWFrameSet *frameSet =tmp->m_pFrameSet;
00460         doc = frameSet->kWordDocument();
00461         KWFrame *frame=frameSet->frame(tmp->m_iFrameIndex);
00462         KWTableFrameSet::Cell *cell = dynamic_cast<KWTableFrameSet::Cell *>(frame->frameSet());
00463         FrameBorderTypeStruct *tmpFrameStruct=m_oldBorderFrameType.at(m_indexFrame.find(tmp));
00464         switch(tmpFrameStruct->m_EFrameType)
00465         {
00466             case KoBorder::LeftBorder:
00467                 if(cell) // is a table cell
00468                     cell->setLeftBorder(tmpFrameStruct->m_OldBorder);
00469                 else
00470                     frame->setLeftBorder(tmpFrameStruct->m_OldBorder);
00471                 break;
00472             case KoBorder::RightBorder:
00473                 if(cell) // is a table cell
00474                     cell->setRightBorder(tmpFrameStruct->m_OldBorder);
00475                 else
00476                     frame->setRightBorder(tmpFrameStruct->m_OldBorder);
00477                 break;
00478             case KoBorder::TopBorder:
00479                 if(cell) // is a table cell
00480                     cell->setTopBorder(tmpFrameStruct->m_OldBorder);
00481                 else
00482                     frame->setTopBorder(tmpFrameStruct->m_OldBorder);
00483                 break;
00484             case KoBorder::BottomBorder:
00485                 if(cell) // is a table cell
00486                     cell->setBottomBorder(tmpFrameStruct->m_OldBorder);
00487                 else
00488                     frame->setBottomBorder(tmpFrameStruct->m_OldBorder);
00489                 break;
00490             default:
00491                 break;
00492         }
00493         if (!cell) {
00494             frame->frameBordersChanged();
00495             //fixme frameBorderChanged for table cells here too ?
00496         }
00497     }
00498 
00499 
00500 
00501     if ( doc )
00502     {
00503         //update frames
00504         doc->repaintAllViews();
00505     }
00506 }
00507 
00508 KWFrameBackGroundColorCommand::KWFrameBackGroundColorCommand( const QString &name, QPtrList<FrameIndex> &_listFrameIndex, QPtrList<QBrush> &_oldBrush,const QBrush & _newColor ):
00509     KNamedCommand(name),
00510     m_indexFrame(_listFrameIndex),
00511     m_oldBackGroundColor(_oldBrush),
00512     m_newColor( _newColor)
00513 {
00514 }
00515 
00516 KWFrameBackGroundColorCommand::~KWFrameBackGroundColorCommand()
00517 {
00518     m_indexFrame.setAutoDelete(true);
00519     m_oldBackGroundColor.setAutoDelete(true);
00520 }
00521 
00522 
00523 void KWFrameBackGroundColorCommand::execute()
00524 {
00525     FrameIndex *tmp;
00526     KWDocument * doc = 0L;
00527     for ( tmp=m_indexFrame.first(); tmp != 0; tmp=m_indexFrame.next() )
00528     {
00529         KWFrameSet *frameSet =tmp->m_pFrameSet;
00530         if ( frameSet && (frameSet->type() != FT_PICTURE) && (frameSet->type() != FT_PART))
00531         {
00532             doc = frameSet->kWordDocument();
00533             KWFrame *frame=frameSet->frame(tmp->m_iFrameIndex);
00534             frame->setBackgroundColor(m_newColor);
00535         }
00536     }
00537     //update frame
00538     if ( doc )
00539         doc->repaintAllViews();
00540 }
00541 
00542 void KWFrameBackGroundColorCommand::unexecute()
00543 {
00544     FrameIndex *tmp;
00545     KWDocument * doc = 0L;
00546     for ( tmp=m_indexFrame.first(); tmp != 0; tmp=m_indexFrame.next() )
00547     {
00548         KWFrameSet *frameSet =tmp->m_pFrameSet;
00549         if ( frameSet && (frameSet->type() != FT_PICTURE) && (frameSet->type() != FT_PART) )
00550         {
00551             doc = frameSet->kWordDocument();
00552             KWFrame *frame=frameSet->frame(tmp->m_iFrameIndex);
00553             QBrush *tmpFrameStruct=m_oldBackGroundColor.at(m_indexFrame.find(tmp));
00554             frame->setBackgroundColor(*tmpFrameStruct);
00555         }
00556     }
00557 
00558     //update frames
00559     if ( doc )
00560         doc->repaintAllViews();
00561 }
00562 
00563 KWFrameStyleCommand::KWFrameStyleCommand( const QString &name, KWFrame *_frame, KWFrameStyle *_fs, bool _repaintViews ) :
00564     KNamedCommand( name )
00565 {
00566     m_frame = _frame;
00567     m_fs = _fs;
00568     repaintViews = _repaintViews;
00569 
00570     m_oldValues = new KWFrameStyle( "Old", m_frame );
00571 }
00572 
00573 void KWFrameStyleCommand::execute()
00574 {
00575     applyFrameStyle( m_fs);
00576 }
00577 
00578 void KWFrameStyleCommand::unexecute()
00579 {
00580     applyFrameStyle( m_oldValues);
00581 }
00582 
00583 void KWFrameStyleCommand::applyFrameStyle( KWFrameStyle * _sty )
00584 {
00585     if ( m_frame->frameSet() && (m_frame->frameSet()->type() != FT_PICTURE)&& (m_frame->frameSet()->type() != FT_PART))
00586         m_frame->setBackgroundColor( _sty->backgroundColor() );
00587     m_frame->setLeftBorder( _sty->leftBorder() );
00588     m_frame->setRightBorder( _sty->rightBorder() );
00589     m_frame->setTopBorder( _sty->topBorder() );
00590     m_frame->setBottomBorder( _sty->bottomBorder() );
00591 
00592     m_frame->frameBordersChanged();
00593     if ( repaintViews )
00594         m_frame->frameSet()->kWordDocument()->repaintAllViews();
00595 }
00596 
00597 
00598 KWTableStyleCommand::KWTableStyleCommand( const QString &name, KWFrame *_frame, KWTableStyle *_ts, bool _repaintViews ) :
00599     KNamedCommand( name )
00600 {
00601     m_frame = _frame;
00602     m_ts = _ts;
00603     repaintViews = _repaintViews;
00604 
00605     // No need for i18n because it will never be displayed.
00606     m_fsc = new KWFrameStyleCommand( "Apply Framestyle to Frame", m_frame, m_ts->frameStyle(), repaintViews );
00607     m_sc = 0L;
00608 }
00609 
00610 KWTableStyleCommand::~KWTableStyleCommand()
00611 {
00612     delete m_fsc;
00613     delete m_sc;
00614 }
00615 
00616 void KWTableStyleCommand::execute()
00617 {
00618     if (m_fsc)
00619         m_fsc->execute();
00620 
00621     if ( (m_ts) && ( m_frame->frameSet()->type() == FT_TEXT ) && ( m_ts->paragraphStyle() ) )
00622     {
00623         KoTextObject *textObject = ((KWTextFrameSet*)m_frame->frameSet())->textObject();
00624         textObject->textDocument()->selectAll( KoTextDocument::Temp );
00625         m_sc = textObject->applyStyleCommand( 0L, m_ts->paragraphStyle(), KoTextDocument::Temp, KoParagLayout::All, KoTextFormat::Format, true, false );
00626         textObject->textDocument()->removeSelection( KoTextDocument::Temp );
00627     }
00628 
00629     m_frame->frameBordersChanged();
00630     if ( repaintViews )
00631         m_frame->frameSet()->kWordDocument()->repaintAllViews();
00632 
00633 }
00634 
00635 void KWTableStyleCommand::unexecute()
00636 {
00637     if (m_fsc)
00638         m_fsc->unexecute();
00639     if (m_sc)
00640         m_sc->unexecute();
00641 
00642     m_frame->frameBordersChanged();
00643     if ( repaintViews )
00644         m_frame->frameSet()->kWordDocument()->repaintAllViews();
00645 }
00646 
00647 KWTableTemplateCommand::KWTableTemplateCommand( const QString &name, KWTableFrameSet *_table, KWTableTemplate *_tt ) :
00648     KNamedCommand( name )
00649 {
00650     m_table = _table;
00651     m_tt = _tt;
00652 
00653     // No need for i18n because it will never be displayed.
00654     m_tableCommands = new KMacroCommand( "Apply Tablestyles to Table" );
00655 
00656 
00657     KWTableStyle *cell = 0L;
00658     unsigned int rows = m_table->getRows();
00659     unsigned int cols = m_table->getColumns();
00660 
00661     for ( unsigned int i = 0; i < rows; i++ )
00662     {
00663         for ( unsigned int j = 0; j < cols; j++ )
00664         {
00665             if ( (i==0) && (j==0) ) // TOP LEFT CORNER
00666                 cell = m_tt->pTopLeftCorner();
00667             else
00668             if ( (i==0) && ( j==(cols-1) ) ) // TOP RIGHT CORNER
00669                 cell = m_tt->pTopRightCorner();
00670             else
00671             if ( ( i==(rows-1) ) && (j==0) ) // BOTTOM LEFT CORNER
00672                 cell = m_tt->pBottomLeftCorner();
00673             else
00674             if ( ( i==(rows-1) ) && ( j==(cols-1) ) ) // BOTTOM RIGHT CORNER
00675                 cell = m_tt->pBottomRightCorner();
00676             else
00677             if ( ( i==0 ) && ( j>0 ) && ( j<(cols-1) ) ) // FIRST ROW
00678                 cell = m_tt->pFirstRow();
00679             else
00680             if ( ( j==0 ) && ( i>0 ) && ( i<(rows-1) ) ) // FIRST COL
00681                 cell = m_tt->pFirstCol();
00682             else
00683             if ( ( i==(rows-1) ) && ( j>0 ) && ( j<(cols-1) ) )  // LAST ROW
00684                 cell = m_tt->pLastRow();
00685             else
00686             if ( ( j==(cols-1) ) && ( i>0 ) && ( i<(rows-1) ) ) // LAST COL
00687                 cell = m_tt->pLastCol();
00688             else
00689             if ( (i>0) && (j>0) && (i<(rows-1)) && (j<(cols-1)) ) // BODY
00690                 cell = m_tt->pBodyCell();
00691 
00692             m_tableCommands->addCommand( new KWTableStyleCommand( "Apply tablestyle to cell", m_table->cell(i,j)->frame(0),cell, false ) );
00693         }
00694     }
00695 }
00696 
00697 KWTableTemplateCommand::~KWTableTemplateCommand()
00698 {
00699     delete m_tableCommands;
00700 }
00701 
00702 void KWTableTemplateCommand::execute()
00703 {
00704     m_tableCommands->execute();
00705     m_table->kWordDocument()->repaintAllViews();
00706 }
00707 
00708 void KWTableTemplateCommand::unexecute()
00709 {
00710     m_tableCommands->unexecute();
00711     m_table->kWordDocument()->repaintAllViews();
00712 }
00713 
00714 
00715 KWFrameResizeCommand::KWFrameResizeCommand(const QString &name, const QValueList<FrameIndex> &frameIndex, const QValueList<FrameResizeStruct> &frameResize )
00716     : KNamedCommand(name), m_indexFrame(frameIndex), m_frameResize(frameResize) {
00717     Q_ASSERT(m_indexFrame.count() == m_frameResize.count());
00718 }
00719 KWFrameResizeCommand::KWFrameResizeCommand(const QString &name, FrameIndex frameIndex, const FrameResizeStruct &frameResize )
00720     : KNamedCommand(name) {
00721     m_indexFrame.append(frameIndex);
00722     m_frameResize.append(frameResize);
00723 }
00724 
00725 void KWFrameResizeCommand::execute()
00726 {
00727     QValueList<FrameResizeStruct>::Iterator resizeIter = m_frameResize.begin();
00728     QValueList<FrameIndex>::Iterator iter = m_indexFrame.begin();
00729     for(; iter != m_indexFrame.end() && resizeIter != m_frameResize.end(); ++resizeIter, ++iter ) {
00730         FrameIndex index = *iter;
00731         FrameResizeStruct frs = *resizeIter;
00732 
00733         KWFrameSet *frameSet = index.m_pFrameSet;
00734         Q_ASSERT( frameSet );
00735         KWFrame *frame = frameSet->frame(index.m_iFrameIndex);
00736         Q_ASSERT( frame );
00737         frame->setCoords(frs.newRect.left(),frs.newRect.top(),frs.newRect.right(),frs.newRect.bottom());
00738         frame->setMinimumFrameHeight(frs.newMinHeight);
00739         KWTableFrameSet *table = frameSet->groupmanager();
00740         if (table) {
00741             KWTableFrameSet::Cell *cell=dynamic_cast<KWTableFrameSet::Cell *>(frameSet);
00742             if(cell) {
00743                 table->recalcCols(cell->firstColumn(), cell->firstRow());
00744                 table->recalcRows(cell->firstColumn(), cell->firstRow());
00745             }
00746             else {
00747                 table->recalcCols(0, 0);
00748                 table->recalcRows(0, 0);
00749             }
00750         }
00751 
00752         KWDocument * doc = frameSet->kWordDocument();
00753         if ( frameSet->frameSetInfo() != KWFrameSet::FI_BODY ) // header/footer/footnote
00754             doc->recalcFrames();
00755 
00756         //update frames
00757         doc->frameChanged( frame );
00758     }
00759 }
00760 
00761 void KWFrameResizeCommand::unexecute()
00762 {
00763     QValueList<FrameResizeStruct>::Iterator resizeIter = m_frameResize.begin();
00764     QValueList<FrameIndex>::Iterator iter = m_indexFrame.begin();
00765     for(; iter != m_indexFrame.end() && resizeIter != m_frameResize.end(); ++resizeIter, ++iter ) {
00766         FrameIndex index = *iter;
00767         FrameResizeStruct frs = *resizeIter;
00768         KWFrameSet *frameSet =index.m_pFrameSet;
00769         Q_ASSERT( frameSet );
00770         KWFrame *frame=frameSet->frame(index.m_iFrameIndex);
00771         Q_ASSERT( frame );
00772         frame->setCoords(frs.oldRect.left(),frs.oldRect.top(),frs.oldRect.right(),frs.oldRect.bottom());
00773         frame->setMinimumFrameHeight(frs.oldMinHeight);
00774         KWTableFrameSet *table = frameSet->groupmanager();
00775         if (table) {
00776             KWTableFrameSet::Cell *cell=dynamic_cast<KWTableFrameSet::Cell *>(frameSet);
00777             if(cell) {
00778                 table->recalcCols(cell->firstColumn(), cell->firstRow());
00779                 table->recalcRows(cell->firstColumn(), cell->firstRow());
00780             }
00781             else {
00782                 table->recalcCols(0, 0);
00783                 table->recalcRows(0, 0);
00784             }
00785         }
00786         KWDocument * doc = frameSet->kWordDocument();
00787         if ( frameSet->frameSetInfo() != KWFrameSet::FI_BODY ) // header/footer/footnote
00788             doc->recalcFrames();
00789 
00790         frame->updateRulerHandles();
00791 
00792         //update frames
00793         doc->frameChanged( frame );
00794     }
00795 }
00796 
00797 KWFrameChangePictureCommand::KWFrameChangePictureCommand( const QString &name, FrameIndex _frameIndex, const KoPictureKey & _oldKey, const KoPictureKey & _newKey ) :
00798     KNamedCommand(name),
00799     m_indexFrame(_frameIndex),
00800     m_oldKey(_oldKey),
00801     m_newKey(_newKey)
00802 {
00803 }
00804 
00805 void KWFrameChangePictureCommand::execute()
00806 {
00807     KWFrameSet *frameSet = m_indexFrame.m_pFrameSet;
00808     Q_ASSERT( frameSet );
00809     KWFrame *frame = frameSet->frame(m_indexFrame.m_iFrameIndex);
00810     Q_ASSERT( frame );
00811     KWDocument * doc = frameSet->kWordDocument();
00812     KWPictureFrameSet *frameset = static_cast<KWPictureFrameSet *>(frame->frameSet());
00813     frameset->reloadPicture( m_newKey );
00814     frameSet->kWordDocument()->refreshDocStructure( frameSet->type() );
00815     doc->frameChanged( frame );
00816 }
00817 
00818 void KWFrameChangePictureCommand::unexecute()
00819 {
00820     KWFrameSet *frameSet =m_indexFrame.m_pFrameSet;
00821     KWFrame *frame=frameSet->frame(m_indexFrame.m_iFrameIndex);
00822     KWDocument * doc = frameSet->kWordDocument();
00823     KWPictureFrameSet *frameset = static_cast<KWPictureFrameSet *>(frame->frameSet());
00824     frameset->reloadPicture( m_oldKey );
00825     frameSet->kWordDocument()->refreshDocStructure( frameSet->type() );
00826     doc->frameChanged( frame );
00827 }
00828 
00829 
00830 KWFramePartMoveCommand::KWFramePartMoveCommand( const QString &name, FrameIndex _frameIndex,  FrameResizeStruct _frameMove ) :
00831     KNamedCommand(name),
00832     m_indexFrame(_frameIndex),
00833     m_frameMove(_frameMove)
00834 {
00835 }
00836 
00837 void KWFramePartMoveCommand::execute()
00838 {
00839     KWFrameSet *frameSet = m_indexFrame.m_pFrameSet;
00840     Q_ASSERT( frameSet );
00841     KWFrame *frame = frameSet->frame(m_indexFrame.m_iFrameIndex);
00842     Q_ASSERT( frame );
00843     frame->setCoords(m_frameMove.newRect.left(),m_frameMove.newRect.top(),m_frameMove.newRect.right(),m_frameMove.newRect.bottom());
00844 
00845     KWDocument * doc = frameSet->kWordDocument();
00846 
00847     frame->updateRulerHandles();
00848     doc->frameChanged( frame );
00849 }
00850 
00851 void KWFramePartMoveCommand::unexecute()
00852 {
00853     KWFrameSet *frameSet =m_indexFrame.m_pFrameSet;
00854     KWFrame *frame=frameSet->frame(m_indexFrame.m_iFrameIndex);
00855     frame->setCoords(m_frameMove.oldRect.left(),m_frameMove.oldRect.top(),m_frameMove.oldRect.right(),m_frameMove.oldRect.bottom());
00856 
00857     KWDocument * doc = frameSet->kWordDocument();
00858     frame->updateRulerHandles();
00859 
00860     //update frames
00861     doc->frameChanged( frame );
00862 }
00863 
00864 bool KWFramePartMoveCommand::frameMoved()
00865 {
00866     return  (m_frameMove.oldRect!=m_frameMove.newRect);
00867 }
00868 
00869 KWFramePartInternalCommand::KWFramePartInternalCommand( const QString &name, KWPartFrameSet *part ) :
00870     KNamedCommand(name),
00871     m_part(part)
00872 {
00873     m_url = m_part->getChild()->document()->url();
00874 }
00875 
00876 void KWFramePartInternalCommand::execute()
00877 {
00878     m_part->getChild()->document()->setStoreInternal(true);
00879 }
00880 
00881 void KWFramePartInternalCommand::unexecute()
00882 {
00883     m_part->getChild()->document()->setStoreInternal(false);
00884     m_part->getChild()->document()->setURL( m_url );
00885 }
00886 
00887 
00888 KWFramePartExternalCommand::KWFramePartExternalCommand( const QString &name, KWPartFrameSet *part ) :
00889     KNamedCommand(name),
00890     m_part(part)
00891 {
00892 }
00893 
00894 void KWFramePartExternalCommand::execute()
00895 {
00896     m_part->getChild()->document()->setStoreInternal(false);
00897 }
00898 
00899 void KWFramePartExternalCommand::unexecute()
00900 {
00901     m_part->getChild()->document()->setStoreInternal(true);
00902 }
00903 
00904 
00905 KWFrameMoveCommand::KWFrameMoveCommand( const QString &name,
00906                                         const QValueList<FrameIndex> & _frameIndex,
00907                                         const QValueList<FrameMoveStruct> & _frameMove  ) :
00908     KNamedCommand(name),
00909     m_indexFrame(_frameIndex),
00910     m_frameMove(_frameMove)
00911 {
00912 }
00913 
00914 void KWFrameMoveCommand::execute()
00915 {
00916     bool needRelayout = false;
00917     KWDocument * doc = 0L;
00918     QValueList<FrameMoveStruct>::Iterator moveIt = m_frameMove.begin();
00919     QValueList<FrameIndex>::Iterator tmp = m_indexFrame.begin();
00920     for( ; tmp != m_indexFrame.end() && moveIt != m_frameMove.end(); ++tmp, ++moveIt )
00921     {
00922         KWFrameSet *frameSet = (*tmp).m_pFrameSet;
00923         doc = frameSet->kWordDocument();
00924         KWFrame *frame = frameSet->frame((*tmp).m_iFrameIndex);
00925         frame->moveTopLeft( (*moveIt).newPos );
00926 
00927         frame->updateRulerHandles();
00928         needRelayout = needRelayout || ( frame->runAround() != KWFrame::RA_NO );
00929     }
00930     if ( doc )
00931     {
00932         doc->updateAllFrames();
00933         if ( needRelayout )
00934             doc->layout();
00935 
00936         doc->updateRulerFrameStartEnd();
00937         doc->repaintAllViews();
00938     }
00939 }
00940 
00941 void KWFrameMoveCommand::unexecute()
00942 {
00943     bool needRelayout = false;
00944     KWDocument * doc = 0L;
00945     QValueList<FrameMoveStruct>::Iterator moveIt = m_frameMove.begin();
00946     QValueList<FrameIndex>::Iterator tmp = m_indexFrame.begin();
00947     for( ; tmp != m_indexFrame.end() && moveIt != m_frameMove.end(); ++tmp, ++moveIt )
00948     {
00949         KWFrameSet *frameSet = (*tmp).m_pFrameSet;
00950         doc = frameSet->kWordDocument();
00951         KWFrame *frame = frameSet->frame((*tmp).m_iFrameIndex);
00952         frame->moveTopLeft( (*moveIt).oldPos );
00953 
00954         frame->updateRulerHandles();
00955         needRelayout = needRelayout || ( frame->runAround() != KWFrame::RA_NO );
00956     }
00957 
00958     if ( doc )
00959     {
00960         doc->updateAllFrames();
00961         if ( needRelayout )
00962             doc->layout();
00963         doc->updateRulerFrameStartEnd();
00964         doc->repaintAllViews();
00965     }
00966 }
00967 
00968 KWFramePropertiesCommand::KWFramePropertiesCommand( const QString &name, KWFrame *_frameBefore,  KWFrame *_frameAfter ) :
00969     KNamedCommand(name),
00970     m_frameIndex( _frameAfter ),
00971     m_frameBefore(_frameBefore),
00972     m_frameAfter(_frameAfter->getCopy())
00973 {
00974 }
00975 
00976 KWFramePropertiesCommand::~KWFramePropertiesCommand()
00977 {
00978     delete m_frameBefore;
00979     delete m_frameAfter;
00980 }
00981 
00982 void KWFramePropertiesCommand::execute()
00983 {
00984     kdDebug(32001) << "KWFrameChangeParamCommand::execute" << endl;
00985     KWFrameSet *frameSet = m_frameIndex.m_pFrameSet;
00986     Q_ASSERT( frameSet );
00987 
00988     KWFrame *frame = frameSet->frame( m_frameIndex.m_iFrameIndex );
00989     Q_ASSERT( frame );
00990     frame->copySettings(m_frameAfter);
00991     frame->frameStack()->update();
00992 
00993     KWDocument * doc = frameSet->kWordDocument();
00994     if(doc)
00995     {
00996         doc->frameChanged( frame );
00997         doc->updateAllFrames();
00998         doc->layout();
00999         doc->repaintAllViews();
01000         doc->updateRulerFrameStartEnd();
01001     }
01002 }
01003 
01004 void KWFramePropertiesCommand::unexecute()
01005 {
01006     kdDebug(32001) << "KWFrameChangeParamCommand::unexecute" << endl;
01007     KWFrameSet *frameSet = m_frameIndex.m_pFrameSet;
01008     Q_ASSERT( frameSet );
01009 
01010     KWFrame *frame = frameSet->frame( m_frameIndex.m_iFrameIndex );
01011     Q_ASSERT( frame );
01012     frame->copySettings(m_frameBefore);
01013     frame->frameStack()->update();
01014     KWDocument * doc = frameSet->kWordDocument();
01015     if(doc)
01016     {
01017         doc->frameChanged( frame );
01018         doc->updateAllFrames();
01019         doc->layout();
01020         doc->repaintAllViews();
01021         doc->updateRulerFrameStartEnd();
01022     }
01023 }
01024 
01025 
01026 KWFrameSetInlineCommand::KWFrameSetInlineCommand( const QString &name, KWFrameSet *frameset, bool value ) :
01027     KNamedCommand(name),
01028     m_pFrameSet( frameset ),
01029     m_value( value )
01030 {
01031     m_oldValue = m_pFrameSet->isFloating();
01032 }
01033 
01034 void KWFrameSetInlineCommand::setValue( bool value )
01035 {
01036     kdDebug(32001) << "KWFrameSetInlineCommand::execute" << endl;
01037     if ( value )
01038     {
01039         // Make frame(set) floating
01040         m_pFrameSet->setFloating();
01041         // ## We might want to store a list of anchors in the command, and reuse them
01042         // in execute/unexecute. Currently setFixed forgets the anchors and setFloating recreates new ones...
01043     }
01044     else
01045     {
01046         // Make frame(set) non-floating
01047         m_pFrameSet->setFixed();
01048     }
01049 
01050     m_pFrameSet->kWordDocument()->updateAllFrames();
01051 }
01052 
01053 void KWFrameSetInlineCommand::execute()
01054 {
01055     setValue( m_value );
01056 }
01057 
01058 void KWFrameSetInlineCommand::unexecute()
01059 {
01060     setValue( m_oldValue );
01061 }
01062 
01063 KWPageLayoutCommand::KWPageLayoutCommand( const QString &name,KWDocument *_doc,KWPageLayoutStruct &_oldLayout, KWPageLayoutStruct &_newLayout  ) :
01064     KNamedCommand(name),
01065     m_pDoc(_doc),
01066     m_oldLayout(_oldLayout),
01067     m_newLayout(_newLayout)
01068 {
01069 }
01070 
01071 void KWPageLayoutCommand::execute()
01072 {
01073     m_pDoc->setPageLayout( m_newLayout._pgLayout, m_newLayout._cl, m_newLayout._hf );
01074 }
01075 
01076 void KWPageLayoutCommand::unexecute()
01077 {
01078     m_pDoc->setPageLayout( m_oldLayout._pgLayout, m_oldLayout._cl, m_oldLayout._hf);
01079 }
01080 
01081 
01082 KWDeleteFrameCommand::KWDeleteFrameCommand( const QString &name, KWFrame * frame ):
01083     KNamedCommand(name),
01084     m_frameIndex( frame ),
01085     m_copyFrame( frame->getCopy() )
01086 {
01087 }
01088 
01089 KWDeleteFrameCommand::KWDeleteFrameCommand( const FrameIndex &frameIndex) :
01090     KNamedCommand("")
01091 {
01092     m_frameIndex = frameIndex;
01093     m_copyFrame = m_frameIndex.m_pFrameSet->frame(m_frameIndex.m_iFrameIndex)->getCopy();
01094 }
01095 
01096 KWDeleteFrameCommand::~KWDeleteFrameCommand()
01097 {
01098     delete m_copyFrame;
01099 }
01100 
01101 
01102 void KWDeleteFrameCommand::execute()
01103 {
01104     KWFrameSet *frameSet = m_frameIndex.m_pFrameSet;
01105     Q_ASSERT( frameSet );
01106 
01107     KWFrame *frame = frameSet->frame( m_frameIndex.m_iFrameIndex );
01108     Q_ASSERT( frame );
01109 
01110 kdDebug() << "delete frame " << m_frameIndex.m_iFrameIndex << " of " << frameSet->name() << endl;
01111     KWDocument* doc = frameSet->kWordDocument();
01112     doc->terminateEditing( frameSet );
01113     doc->frameChanged( frame );
01114     frameSet->deleteFrame( m_frameIndex.m_iFrameIndex );
01115 
01116 /*   KWTextFrameSet * textfs = dynamic_cast<KWTextFrameSet *>(fs);
01117      if(textfs) { TODO
01118         // if content does not fit; change properties of previous frame to be 'do not show'
01119      }
01120 */
01121 
01122     doc->refreshDocStructure( frameSet->type() );
01123     doc->updateTextFrameSetEdit();
01124 }
01125 
01126 void KWDeleteFrameCommand::unexecute()
01127 {
01128     KWFrameSet *frameSet = m_frameIndex.m_pFrameSet;
01129     KWFrame * frame = m_copyFrame->getCopy();
01130     frame->setFrameSet( frameSet );
01131     frameSet->addFrame( frame );
01132 
01133     KWPartFrameSet * partfs = dynamic_cast<KWPartFrameSet *>( frameSet );
01134     if ( partfs )
01135         partfs->setDeleted( false );
01136 
01137     KWTextFrameSet * textfs = dynamic_cast<KWTextFrameSet *>( frameSet );
01138     if ( textfs )
01139         textfs->textObject()->formatMore( 2 );
01140     KWDocument* doc = frameSet->kWordDocument();
01141     doc->frameChanged( frame );
01142     // could have been the last frame on a page, so undeleting it needs to recreate the page
01143     doc->recalcFrames( frame->pageNumber() );
01144     doc->refreshDocStructure(frameSet->type());
01145     doc->updateRulerFrameStartEnd();
01146 }
01147 
01148 KWCreateFrameCommand::KWCreateFrameCommand( const QString &name, KWFrame * frame ) :
01149     KWDeleteFrameCommand( name, frame )
01150 {}
01151 
01152 
01153 KWUngroupTableCommand::KWUngroupTableCommand( const QString &name, KWTableFrameSet * _table ):
01154     KNamedCommand(name),
01155     m_pTable(_table)
01156 {
01157     m_ListFrame.clear();
01158     for ( KWTableFrameSet::TableIter i(m_pTable); i ; ++i ) {
01159         m_ListFrame.append( i.current() );
01160     }
01161 }
01162 
01163 void KWUngroupTableCommand::execute()
01164 {
01165     KWDocument * doc = m_pTable->kWordDocument();
01166     for ( KWTableFrameSet::TableIter i(m_pTable) ; i ; ++i ) {
01167         i->setGroupManager( 0L );
01168         doc->addFrameSet( i.current() );
01169     }
01170     m_pTable->ungroup();
01171     doc->removeFrameSet(m_pTable);
01172 
01173     //when you ungroup a table
01174     // you must remove table item in docstruct
01175     // create items in text item in docstruct
01176 
01177     int refresh=0;
01178     refresh |=Tables;
01179     refresh |=TextFrames;
01180     doc->refreshDocStructure(refresh);
01181 
01182     doc->updateAllFrames();
01183     doc->repaintAllViews();
01184 }
01185 
01186 void KWUngroupTableCommand::unexecute()
01187 {
01188     Q_ASSERT(m_pTable);
01189     m_pTable->group();
01190     KWDocument * doc = m_pTable->kWordDocument();
01191     KWFrameSet *tmp;
01192     for ( tmp=m_ListFrame.first(); tmp != 0; tmp=m_ListFrame.next() )
01193     {
01194         tmp->setGroupManager(m_pTable);
01195         doc->removeFrameSet(tmp);
01196         KWTableFrameSet::Cell *cell=static_cast<KWTableFrameSet::Cell *>(tmp);
01197         Q_ASSERT(cell);
01198         m_pTable->addCell( cell );
01199     }
01200     doc->addFrameSet(m_pTable);
01201 
01202     int refresh=0;
01203     refresh |=Tables;
01204     refresh |=TextFrames;
01205     doc->refreshDocStructure(refresh);
01206 
01207 
01208     doc->updateAllFrames();
01209     doc->repaintAllViews();
01210 }
01211 
01212 
01213 KWDeleteTableCommand::KWDeleteTableCommand( const QString &name, KWTableFrameSet * _table ):
01214     KNamedCommand(name),
01215     m_pTable(_table)
01216 {
01217     Q_ASSERT(m_pTable);
01218 }
01219 
01220 void KWDeleteTableCommand::execute()
01221 {
01222     kdDebug(32001) << "KWDeleteTableCommand::execute" << endl;
01223     KWDocument * doc = m_pTable->kWordDocument();
01224     doc->removeFrameSet(m_pTable);
01225     m_pTable->setVisible( false );
01226     doc->refreshDocStructure((int)Tables);
01227     doc->updateAllFrames();
01228     m_pTable->updateFrames(); // not in the doc list anymore, so the above call didn't do it!
01229     doc->layout();
01230     doc->repaintAllViews();
01231     doc->updateRulerFrameStartEnd();
01232 
01233 }
01234 
01235 void KWDeleteTableCommand::unexecute()
01236 {
01237     kdDebug(32001) << "KWDeleteTableCommand::unexecute" << endl;
01238     KWDocument * doc = m_pTable->kWordDocument();
01239     m_pTable->setVisible( true );
01240     doc->addFrameSet(m_pTable);
01241     doc->refreshDocStructure((int)Tables);
01242     doc->updateAllFrames();
01243     doc->layout();
01244     doc->repaintAllViews();
01245     doc->updateRulerFrameStartEnd();
01246 }
01247 
01248 
01249 KWInsertColumnCommand::KWInsertColumnCommand( const QString &name, KWTableFrameSet * _table, int _col, double _maxRight ):
01250     KNamedCommand(name),
01251     m_pTable(_table),
01252     m_rc(new RemovedColumn()),
01253     m_colPos(_col),
01254     m_maxRight(_maxRight),
01255     m_oldWidth(0)
01256 {
01257     Q_ASSERT(m_pTable);
01258 }
01259 
01260 KWInsertColumnCommand::~KWInsertColumnCommand()
01261 {
01262     delete m_rc;
01263 }
01264 
01265 void KWInsertColumnCommand::execute()
01266 {
01267     kdDebug(32001) << "KWInsertColumnCommand::execute" << endl;
01268     KWDocument * doc = m_pTable->kWordDocument();
01269     // a insert column = KWTableFrameSet::m_sDefaultColWidth, see kwtableframeset.cc
01270     if (m_pTable->boundingRect().right() + KWTableFrameSet::m_sDefaultColWidth >= static_cast<int>(m_maxRight))
01271     {   // must create space (resize the table)
01272         m_oldWidth = m_pTable->boundingRect().width();
01273         // here we calculate the new table size for a table that would take the
01274         // entire width of the page, which what the user wants 99% of the time.
01275         double newTableWidth =m_maxRight - m_pTable->boundingRect().left();
01276         double newColSize = newTableWidth / (m_pTable->getColumns()+1);
01277         double resizeTableWidth = m_maxRight - m_pTable->boundingRect().left();
01278         m_pTable->resizeWidth(resizeTableWidth - newColSize);
01279         m_pTable->insertNewColumn(m_colPos, newColSize);
01280     }
01281     else
01282     {   // simply insert the column without asking for a specific size :
01283         m_pTable->insertNewColumn(m_colPos);
01284     }
01285     Q_ASSERT(m_pTable->boundingRect().right() <= m_maxRight);
01286     doc->updateAllFrames();
01287     doc->layout();
01288     doc->repaintAllViews();
01289 }
01290 
01291 void KWInsertColumnCommand::unexecute()
01292 {
01293     kdDebug(32001) << "KWInsertColumnCommand::unexecute" << endl;
01294     KWDocument * doc = m_pTable->kWordDocument();
01295     doc->terminateEditing(m_pTable);
01296     m_pTable->deleteColumn(m_colPos, *m_rc);
01297     // now undo the resize of the table if necessary:
01298     if (m_oldWidth) {
01299         // yes, the table was resized, let's undo that :
01300         m_pTable->resizeWidth(m_oldWidth);
01301     }
01302     doc->updateAllFrames();
01303     doc->layout();
01304     doc->repaintAllViews();
01305 }
01306 
01307 
01308 
01309 KWInsertRowCommand::KWInsertRowCommand( const QString &name, KWTableFrameSet * _table, int _row ):
01310     KNamedCommand(name),
01311     m_pTable(_table),
01312     m_rr(new RemovedRow()),
01313     m_rowPos(_row),
01314     m_inserted(false)
01315 {
01316     Q_ASSERT(m_pTable);
01317 }
01318 
01319 KWInsertRowCommand::~KWInsertRowCommand()
01320 {
01321     delete m_rr;
01322 }
01323 
01324 void KWInsertRowCommand::execute()
01325 {
01326     kdDebug(32001) << "KWInsertRowCommand::execute" << endl;
01327     KWDocument * doc = m_pTable->kWordDocument();
01328     if(m_inserted)
01329         m_pTable->reInsertRow(*m_rr);
01330     else {
01331         m_inserted = true;
01332         m_pTable->insertNewRow(m_rowPos);  //only happens the first time
01333     }
01334     doc->updateAllFrames();
01335     doc->layout();
01336     doc->repaintAllViews();
01337 }
01338 
01339 void KWInsertRowCommand::unexecute()
01340 {
01341     kdDebug(32001) << "KWInsertRowCommand::unexecute" << endl;
01342     KWDocument * doc = m_pTable->kWordDocument();
01343 
01344     doc->terminateEditing(m_pTable);
01345     m_pTable->deleteRow( m_rowPos, *m_rr);
01346 
01347     doc->updateAllFrames();
01348     doc->layout();
01349 }
01350 
01351 
01352 KWRemoveRowCommand::KWRemoveRowCommand( const QString &name, KWTableFrameSet * _table, int _row ):
01353     KNamedCommand(name),
01354     m_pTable(_table),
01355     m_rr(new RemovedRow()),
01356     m_rowPos(_row)
01357 {
01358     Q_ASSERT(m_pTable);
01359 }
01360 
01361 KWRemoveRowCommand::~KWRemoveRowCommand()
01362 {
01363     delete m_rr;
01364 }
01365 
01366 void KWRemoveRowCommand::execute()
01367 {
01368     kdDebug(32001) << "KWRemoveRowCommand::execute" << endl;
01369     KWDocument * doc = m_pTable->kWordDocument();
01370     doc->terminateEditing(m_pTable);
01371 
01372     m_pTable->deleteRow( m_rowPos, *m_rr);
01373 
01374     doc->updateAllFrames();
01375     doc->layout();
01376 }
01377 
01378 void KWRemoveRowCommand::unexecute()
01379 {
01380     kdDebug(32001) << "KWRemoveRowCommand::unexecute" << endl;
01381     KWDocument * doc = m_pTable->kWordDocument();
01382     m_pTable->reInsertRow(*m_rr);
01383     doc->updateAllFrames();
01384     doc->layout();
01385     doc->repaintAllViews();
01386 }
01387 
01388 KWRemoveColumnCommand::KWRemoveColumnCommand( const QString &name, KWTableFrameSet * _table, int _col ):
01389     KNamedCommand(name),
01390     m_pTable(_table),
01391     m_rc(new RemovedColumn()),
01392     m_colPos(_col)
01393 {
01394     Q_ASSERT(m_pTable);
01395 }
01396 
01397 KWRemoveColumnCommand::~KWRemoveColumnCommand()
01398 {
01399     delete m_rc;
01400 }
01401 
01402 void KWRemoveColumnCommand::execute()
01403 {
01404     kdDebug(32001) << "KWRemoveColumnCommand::execute" << endl;
01405     KWDocument * doc = m_pTable->kWordDocument();
01406     doc->terminateEditing(m_pTable);
01407 
01408     m_pTable->deleteColumn( m_colPos, *m_rc);
01409     doc->updateAllFrames();
01410     doc->layout();
01411 }
01412 
01413 void KWRemoveColumnCommand::unexecute()
01414 {
01415     kdDebug(32001) << "KWRemoveColumnCommand::unexecute" << endl;
01416     KWDocument * doc = m_pTable->kWordDocument();
01417     m_pTable->reInsertColumn(*m_rc);
01418     doc->updateAllFrames();
01419     doc->layout();
01420     doc->repaintAllViews();
01421 }
01422 
01423 
01424 
01425 KWSplitCellCommand::KWSplitCellCommand( const QString &name, KWTableFrameSet * _table,unsigned int colBegin,unsigned int rowBegin, unsigned int colEnd,unsigned int rowEnd ):
01426     KNamedCommand(name),
01427     m_pTable(_table),
01428     m_colBegin(colBegin),
01429     m_rowBegin(rowBegin),
01430     m_colEnd(colEnd),
01431     m_rowEnd(rowEnd)
01432 {
01433     Q_ASSERT(m_pTable);
01434 }
01435 
01436 void KWSplitCellCommand::execute()
01437 {
01438     kdDebug(32001) << "KWSplitCellCommand::execute" << endl;
01439     KWDocument * doc = m_pTable->kWordDocument();
01440     doc->terminateEditing(m_pTable);
01441     //kdDebug()<<"split Cell m_colBegin :"<<m_colBegin<<" m_colEnd :"<<m_colEnd<<" m_rowBegin :"<<m_rowBegin<<" m_colEnd :"<<m_colEnd<<endl;
01442     m_pTable->splitCell(m_rowEnd, m_colEnd,m_colBegin,m_rowBegin,m_ListFrameSet);
01443     doc->updateAllFrames();
01444     doc->layout();
01445 }
01446 
01447 void KWSplitCellCommand::unexecute()
01448 {
01449     kdDebug(32001) << "KWSplitCellCommand::unexecute" << endl;
01450     KWDocument * doc = m_pTable->kWordDocument();
01451     doc->terminateEditing(m_pTable);
01452 
01453     //kdDebug()<<"Join Cell m_colBegin :"<<m_colBegin<<" m_colEnd :"<<m_colBegin+m_colEnd-1<<" m_rowBegin :"<<m_rowBegin<<" m_rowEnd :"<<m_rowBegin+m_rowEnd-1<<endl;
01454 
01455     if(m_ListFrameSet.isEmpty())
01456     {
01457         for ( unsigned int i = 0; i < m_pTable->getColumns(); i++ )
01458         {
01459             for ( unsigned int j = 0; j < m_pTable->getRows(); j++ )
01460             {
01461                 if(j>=m_rowBegin && j<=(m_rowBegin+m_rowEnd-1)
01462                    && i>=m_colBegin && i<=(m_colEnd+m_colBegin-1))
01463                 {
01464                     //don't store first cell
01465                     if( !(j==m_rowBegin && i==m_colBegin))
01466                     {
01467                         kdDebug(32001)<<"store cell row :"<<j<<" col :"<<i<<endl;
01468                         KWTableFrameSet::Cell *cell=static_cast<KWTableFrameSet::Cell *>(m_pTable->cell( j,i ));
01469                         m_ListFrameSet.append(cell);
01470                     }
01471                 }
01472 
01473             }
01474         }
01475     }
01476     KWTableFrameSet::Cell *cell=static_cast<KWTableFrameSet::Cell *>(m_pTable->cell( m_rowBegin,m_colBegin ));
01477     m_pTable->joinCells(m_colBegin, m_rowBegin, m_colEnd+m_colBegin-1+cell->columnSpan()-1,
01478         m_rowBegin+m_rowEnd-1+cell->rowSpan()-1);
01479 
01480     doc->updateAllFrames();
01481     doc->layout();
01482 }
01483 
01484 
01485 
01486 KWJoinCellCommand::KWJoinCellCommand( const QString &name, KWTableFrameSet * _table,unsigned int colBegin,unsigned int rowBegin, unsigned int colEnd,unsigned int rowEnd, QPtrList<KWFrameSet> listFrameSet,QPtrList<KWFrame> listCopyFrame):
01487     KNamedCommand(name),
01488     m_pTable(_table),
01489     m_colBegin(colBegin),
01490     m_rowBegin(rowBegin),
01491     m_colEnd(colEnd),
01492     m_rowEnd(rowEnd),
01493     m_ListFrameSet(listFrameSet),
01494     m_copyFrame(listCopyFrame)
01495 {
01496     Q_ASSERT(m_pTable);
01497 }
01498 KWJoinCellCommand::~KWJoinCellCommand()
01499 {
01500     m_copyFrame.setAutoDelete( true );
01501 }
01502 
01503 void KWJoinCellCommand::execute()
01504 {
01505     kdDebug(32001) << "KWJoinCellCommand::execute" << endl;
01506     KWDocument * doc = m_pTable->kWordDocument();
01507     doc->terminateEditing(m_pTable);
01508     m_pTable->joinCells(m_colBegin,m_rowBegin,m_colEnd,m_rowEnd);
01509     doc->updateAllFrames();
01510     doc->layout();
01511 }
01512 
01513 void KWJoinCellCommand::unexecute()
01514 {
01515     kdDebug(32001) << "KWJoinCellCommand::unexecute" << endl;
01516     KWDocument * doc = m_pTable->kWordDocument();
01517     doc->terminateEditing(m_pTable);
01518     m_pTable->splitCell(m_rowEnd-m_rowBegin+1, m_colEnd-m_colBegin+1,m_colBegin,m_rowBegin,m_ListFrameSet,m_copyFrame);
01519     doc->updateAllFrames();
01520     doc->layout();
01521 }
01522 
01523 
01524 KWChangeStartingPageCommand::KWChangeStartingPageCommand( const QString &name, KWDocument *_doc, int _oldStartingPage, int _newStartingPage):
01525     KNamedCommand(name),
01526     m_doc(_doc),
01527     oldStartingPage(_oldStartingPage),
01528     newStartingPage(_newStartingPage)
01529 {
01530 }
01531 
01532 void KWChangeStartingPageCommand::execute()
01533 {
01534     m_doc->variableCollection()->variableSetting()->setStartingPageNumber(newStartingPage);
01535     m_doc->recalcVariables( VT_PGNUM );
01536 }
01537 
01538 void KWChangeStartingPageCommand::unexecute()
01539 {
01540     m_doc->variableCollection()->variableSetting()->setStartingPageNumber(oldStartingPage);
01541     m_doc->recalcVariables( VT_PGNUM );
01542 }
01543 
01544 KWChangeVariableSettingsCommand::KWChangeVariableSettingsCommand( const QString &name, KWDocument *_doc, bool _oldValue, bool _newValue, VariableProperties _type):
01545     KNamedCommand(name),
01546     m_doc(_doc),
01547     type(_type),
01548     m_bOldValue(_oldValue),
01549     m_bNewValue(_newValue)
01550 {
01551 }
01552 
01553 void KWChangeVariableSettingsCommand::changeValue( bool b )
01554 {
01555     switch(type)
01556     {
01557     case VS_DISPLAYLINK:
01558         m_doc->variableCollection()->variableSetting()->setDisplayLink(b);
01559         m_doc->recalcVariables( VT_LINK );
01560         break;
01561     case  VS_UNDERLINELINK:
01562         m_doc->variableCollection()->variableSetting()->setUnderlineLink(b);
01563         m_doc->recalcVariables( VT_LINK );
01564         break;
01565     case VS_DISPLAYCOMMENT:
01566         m_doc->variableCollection()->variableSetting()->setDisplayComment(b);
01567         m_doc->recalcVariables( VT_NOTE );
01568         break;
01569     case VS_DISPLAYFIELDCODE:
01570         m_doc->variableCollection()->variableSetting()->setDisplayFieldCode(b);
01571         //hack necessary otherwise footnote frameset is not refreshing
01572         //and footnote is not resize.
01573         m_doc->displayFootNoteFieldCode();
01574         m_doc->recalcVariables( VT_ALL );
01575         break;
01576     }
01577 }
01578 
01579 void KWChangeVariableSettingsCommand::execute()
01580 {
01581     changeValue(m_bNewValue);
01582 }
01583 
01584 void KWChangeVariableSettingsCommand::unexecute()
01585 {
01586     changeValue(m_bOldValue);
01587 }
01588 
01589 KWChangeCustomVariableValue::KWChangeCustomVariableValue( const QString &name, KWDocument *_doc,const QString & _oldValue, const QString & _newValue,KoCustomVariable *var):
01590     KNamedCommand(name),
01591     m_doc(_doc),
01592     newValue(_newValue),
01593     oldValue(_oldValue),
01594     m_var(var)
01595 {
01596 }
01597 
01598 KWChangeCustomVariableValue::~KWChangeCustomVariableValue()
01599 {
01600 }
01601 
01602 void KWChangeCustomVariableValue::execute()
01603 {
01604     Q_ASSERT(m_var);
01605     m_var->setValue(newValue);
01606     m_doc->recalcVariables( VT_CUSTOM );
01607 }
01608 
01609 void KWChangeCustomVariableValue::unexecute()
01610 {
01611     Q_ASSERT(m_var);
01612     m_var->setValue(oldValue);
01613     m_doc->recalcVariables( VT_CUSTOM );
01614 }
01615 
01616 KWChangeVariableNoteText::KWChangeVariableNoteText( const QString &name, KWDocument *_doc,
01617                         const QString &_oldValue,const QString &_newValue,
01618                         KoNoteVariable *var):
01619     KNamedCommand(name),
01620     m_doc(_doc),
01621     newValue(_newValue),
01622     oldValue(_oldValue),
01623     m_var(var)
01624 {
01625 }
01626 
01627 KWChangeVariableNoteText::~KWChangeVariableNoteText()
01628 {
01629 }
01630 
01631 void KWChangeVariableNoteText::execute()
01632 {
01633     Q_ASSERT(m_var);
01634     m_var->setNote(newValue);
01635 }
01636 
01637 void KWChangeVariableNoteText::unexecute()
01638 {
01639     Q_ASSERT(m_var);
01640     m_var->setNote(oldValue);
01641 }
01642 
01643 // TODO: move to libkotext to remove code duplication with kpresenter
01644 KWChangeLinkVariable::KWChangeLinkVariable( const QString &name, KWDocument *_doc,const QString & _oldHref, const QString & _newHref, const QString & _oldLink,const QString &_newLink, KoLinkVariable *var):
01645     KNamedCommand(name),
01646     m_doc(_doc),
01647     oldHref(_oldHref),
01648     newHref(_newHref),
01649     oldLink(_oldLink),
01650     newLink(_newLink),
01651     m_var(var)
01652 {
01653 }
01654 
01655 
01656 void KWChangeLinkVariable::execute()
01657 {
01658     m_var->setLink(newLink,newHref);
01659     m_doc->recalcVariables(VT_LINK);
01660 }
01661 
01662 void KWChangeLinkVariable::unexecute()
01663 {
01664     m_var->setLink(oldLink,oldHref);
01665     m_doc->recalcVariables(VT_LINK);
01666 }
01667 
01668 KWHideShowHeader::KWHideShowHeader( const QString &name, KWDocument *_doc, bool _newValue):
01669     KNamedCommand(name),
01670     m_doc(_doc),
01671     newValue(_newValue)
01672 {
01673 }
01674 
01675 
01676 void KWHideShowHeader::execute()
01677 {
01678     m_doc->setHeaderVisible(newValue );
01679     m_doc->updateHeaderButton();
01680 
01681 }
01682 
01683 void KWHideShowHeader::unexecute()
01684 {
01685     m_doc->setHeaderVisible(!newValue );
01686     m_doc->updateHeaderButton();
01687 }
01688 
01689 KWHideShowFooter::KWHideShowFooter( const QString &name, KWDocument *_doc, bool _newValue):
01690     KNamedCommand(name),
01691     m_doc(_doc),
01692     newValue(_newValue)
01693 {
01694 }
01695 
01696 
01697 void KWHideShowFooter::execute()
01698 {
01699     m_doc->setFooterVisible( newValue );
01700     m_doc->updateFooterButton();
01701 }
01702 
01703 void KWHideShowFooter::unexecute()
01704 {
01705     m_doc->setFooterVisible( !newValue );
01706     m_doc->updateFooterButton();
01707 }
01708 
01709 
01710 KWProtectContentCommand::KWProtectContentCommand( const QString &name, KWTextFrameSet*frameset, bool _protect):
01711     KNamedCommand(name),
01712     m_pFrameSet(frameset),
01713     m_bProtect(_protect)
01714 {
01715 }
01716 
01717 
01718 void KWProtectContentCommand::execute()
01719 {
01720     m_pFrameSet->setProtectContent(m_bProtect);
01721     m_pFrameSet->kWordDocument()->updateTextFrameSetEdit();
01722     m_pFrameSet->kWordDocument()->testAndCloseAllFrameSetProtectedContent();
01723     m_pFrameSet->kWordDocument()->updateRulerInProtectContentMode();
01724 
01725 }
01726 
01727 void KWProtectContentCommand::unexecute()
01728 {
01729     m_pFrameSet->setProtectContent(!m_bProtect);
01730     m_pFrameSet->kWordDocument()->updateTextFrameSetEdit();
01731     m_pFrameSet->kWordDocument()->testAndCloseAllFrameSetProtectedContent();
01732     m_pFrameSet->kWordDocument()->updateRulerInProtectContentMode();
01733 
01734 }
01735 
01736 KWInsertRemovePageCommand::KWInsertRemovePageCommand( KWDocument *_doc, Command cmd, int pgNum)
01737     : KCommand(), m_doc(_doc), m_cmd(cmd), m_pgNum(pgNum)
01738 {}
01739 
01740 KWInsertRemovePageCommand::~KWInsertRemovePageCommand() {
01741     QValueListIterator<KCommand*> cmdIter = childCommands.begin();
01742     for(;cmdIter != childCommands.end(); ++ cmdIter)
01743          delete (*cmdIter);
01744 }
01745 
01746 QString KWInsertRemovePageCommand::name() const
01747 {
01748     return m_cmd == Insert ? i18n("Insert Page") // problem with after/before page
01749                   : i18n("Delete Page %1").arg(m_pgNum);
01750 }
01751 
01752 void KWInsertRemovePageCommand::execute() {
01753     if ( m_cmd == Insert )
01754         doInsert(m_pgNum);
01755     else
01756         doRemove(m_pgNum);
01757 }
01758 
01759 void KWInsertRemovePageCommand::unexecute() {
01760     if ( m_cmd == Insert )
01761         // remove the page that was inserted
01762         doRemove(m_pgNum+1);
01763     else
01764         // Re-insert the page that was deleted
01765         doInsert(m_pgNum-1);
01766 }
01767 
01768 void KWInsertRemovePageCommand::doRemove(int pageNumber) {
01769     bool firstRun = childCommands.count() == 0;
01770     if(firstRun) {
01771         QValueVector<FrameIndex> indexes;
01772         QPtrList<KWFrame> frames = m_doc->framesInPage(pageNumber, false);
01773         QPtrListIterator<KWFrame> framesIter(frames);
01774         for(; framesIter.current(); ++framesIter)
01775             indexes.append(FrameIndex(*framesIter));
01776 
01777         // we sort them to make sure frames are deleted in order and indexes are not going
01778         // to get mixed up when there is more then one frame of a frameset on the page
01779         std::sort(indexes.begin(), indexes.end(), compareIndex);
01780 
01781         QValueVector<FrameIndex>::iterator iter = indexes.begin();
01782         for(; iter != indexes.end(); ++iter)
01783             childCommands.append(new KWDeleteFrameCommand(*iter));
01784     }
01785     QValueListIterator<KCommand*> cmdIter = childCommands.begin();
01786     for(;cmdIter != childCommands.end(); ++ cmdIter)
01787          (*cmdIter)->execute();
01788 
01789     // next move all frames up that are on higher pagenumbers
01790     const double pageHeight = m_doc->pageManager()->page(pageNumber)->height();
01791     const double topOfPage = m_doc->pageManager()->topOfPage(pageNumber);
01792     m_doc->pageManager()->removePage( pageNumber );
01793 
01794     if(firstRun && m_doc->lastPage() >= pageNumber) { // only walk frames when there was a page
01795                                                       // after the deleted one
01796         QValueList<FrameIndex> indexes;
01797         QValueList<FrameMoveStruct> moveStructs;
01798         QPtrListIterator<KWFrameSet> fss = m_doc->framesetsIterator();
01799         for(;fss.current(); ++fss) {
01800             KWFrameSet *fs = *fss;
01801             if(fs->isMainFrameset()) continue;
01802             if(fs->isHeaderOrFooter()) continue;
01803             if(fs->isFootEndNote()) continue;
01804             if(! fs->isVisible()) continue;
01805             QPtrList<KWFrame> frames = fs->frameIterator();
01806             QPtrListIterator<KWFrame> framesIter(frames);
01807             for(; framesIter.current(); ++framesIter) {
01808                 KWFrame *frame = *framesIter;
01809                 if(frame->top() > topOfPage) {
01810                     indexes.append(FrameIndex(frame));
01811                     KoPoint before = frame->topLeft();
01812                     frame->moveBy(0, -pageHeight);
01813                     moveStructs.append(FrameMoveStruct(before, frame->topLeft()));
01814                 }
01815             }
01816         }
01817         KCommand *cmd = new KWFrameMoveCommand("", indexes, moveStructs);
01818         childCommands.append(cmd);
01819     }
01820     m_doc->afterRemovePages();
01821 }
01822 
01823 bool KWInsertRemovePageCommand::compareIndex(const FrameIndex &index1, const FrameIndex &index2) {
01824     if(index1.m_pFrameSet == index2.m_pFrameSet)
01825         return index1.m_iFrameIndex >= index2.m_iFrameIndex;
01826     return index1.m_pFrameSet >= index2.m_pFrameSet; // I don't care about frameset order,
01827                                                      // so just sort on pointers..
01828 }
01829 
01830 void KWInsertRemovePageCommand::doInsert(int pageNumber) {
01831     m_doc->pageManager()->insertPage( pageNumber );
01832     for(int i=childCommands.count()-1; i > 0; i--) // reverse order
01833         childCommands[i]->unexecute();
01834     m_doc->afterInsertPage( pageNumber );
01835 }
01836 
01837 FramePaddingStruct::FramePaddingStruct( KWFrame *frame )
01838 {
01839     topPadding = frame->paddingTop();
01840     bottomPadding= frame->paddingBottom();
01841     leftPadding = frame->paddingLeft();
01842     rightPadding= frame->paddingRight();
01843 }
01844 
01845 FramePaddingStruct::FramePaddingStruct( double _left, double _top, double _right, double _bottom ):
01846     topPadding(_top),
01847     bottomPadding(_bottom),
01848     leftPadding(_left),
01849     rightPadding(_right)
01850 {
01851 }
01852 
01853 
01854 KWFrameChangeFramePaddingCommand::KWFrameChangeFramePaddingCommand( const QString &name, FrameIndex _frameIndex, FramePaddingStruct _framePaddingBegin, FramePaddingStruct _framePaddingEnd ) :
01855     KNamedCommand(name),
01856     m_indexFrame(_frameIndex),
01857     m_framePaddingBegin(_framePaddingBegin),
01858     m_framePaddingEnd(_framePaddingEnd)
01859 {
01860 }
01861 
01862 void KWFrameChangeFramePaddingCommand::execute()
01863 {
01864     KWFrameSet *frameSet = m_indexFrame.m_pFrameSet;
01865     Q_ASSERT( frameSet );
01866     KWFrame *frame = frameSet->frame(m_indexFrame.m_iFrameIndex);
01867     Q_ASSERT( frame );
01868     frame->setFramePadding( m_framePaddingEnd.leftPadding,m_framePaddingEnd.topPadding , m_framePaddingEnd.rightPadding, m_framePaddingEnd.bottomPadding);
01869     frameSet->kWordDocument()->frameChanged( frame );
01870 }
01871 
01872 void KWFrameChangeFramePaddingCommand::unexecute()
01873 {
01874     KWFrameSet *frameSet = m_indexFrame.m_pFrameSet;
01875     Q_ASSERT( frameSet );
01876     KWFrame *frame = frameSet->frame(m_indexFrame.m_iFrameIndex);
01877     Q_ASSERT( frame );
01878     frame->setFramePadding( m_framePaddingBegin.leftPadding,m_framePaddingBegin.topPadding , m_framePaddingBegin.rightPadding, m_framePaddingBegin.bottomPadding);
01879     frameSet->kWordDocument()->frameChanged( frame );
01880 }
01881 
01882 KWChangeFootEndNoteSettingsCommand::KWChangeFootEndNoteSettingsCommand( const QString &name, KoParagCounter _oldCounter, KoParagCounter _newCounter ,bool _footNote ,KWDocument *_doc):
01883     KNamedCommand(name),
01884     m_oldCounter(_oldCounter),
01885     m_newCounter(_newCounter),
01886     m_footNote( _footNote ),
01887     m_doc(_doc)
01888 {
01889 }
01890 
01891 void KWChangeFootEndNoteSettingsCommand::execute()
01892 {
01893     changeCounter( m_newCounter);
01894 }
01895 
01896 void KWChangeFootEndNoteSettingsCommand::unexecute()
01897 {
01898     changeCounter( m_oldCounter);
01899 }
01900 
01901 void KWChangeFootEndNoteSettingsCommand::changeCounter( KoParagCounter counter)
01902 {
01903     if (m_footNote )
01904     {
01905         static_cast<KWVariableSettings*>(m_doc->variableCollection()->variableSetting())->changeFootNoteCounter(counter );
01906     }
01907     else
01908     {
01909         static_cast<KWVariableSettings*>(m_doc->variableCollection()->variableSetting())->changeEndNoteCounter(counter );
01910     }
01911     m_doc->changeFootNoteConfig();
01912 }
01913 
01914 
01915 KWChangeTabStopValueCommand::KWChangeTabStopValueCommand( const QString &name, double _oldValue, double _newValue, KWDocument *_doc):
01916     KNamedCommand(name),
01917     m_doc( _doc ),
01918     m_oldValue(_oldValue),
01919     m_newValue(_newValue)
01920 {
01921 }
01922 
01923 void KWChangeTabStopValueCommand::execute()
01924 {
01925     m_doc->setTabStopValue ( m_newValue );
01926 }
01927 
01928 void KWChangeTabStopValueCommand::unexecute()
01929 {
01930     m_doc->setTabStopValue ( m_oldValue );
01931 }
01932 
01933 
01934 
01935 FootNoteParameter::FootNoteParameter( KWFootNoteVariable *_var )
01936 {
01937     noteType = _var->noteType();
01938     numberingType = _var->numberingType();
01939     manualString = _var->manualString();
01940 }
01941 
01942 FootNoteParameter::FootNoteParameter( NoteType _noteType, KWFootNoteVariable::Numbering _numberingType, const QString &_manualString)
01943 {
01944     noteType= _noteType;
01945     numberingType = _numberingType;
01946     manualString = _manualString;
01947 }
01948 
01949 KWChangeFootNoteParametersCommand::KWChangeFootNoteParametersCommand( const QString &name, KWFootNoteVariable * _var, FootNoteParameter _oldParameter, FootNoteParameter _newParameter, KWDocument *_doc):
01950     KNamedCommand(name),
01951     m_doc( _doc ),
01952     m_var( _var ),
01953     m_oldParameter( _oldParameter ),
01954     m_newParameter( _newParameter)
01955 {
01956 }
01957 
01958 void KWChangeFootNoteParametersCommand::execute()
01959 {
01960     changeVariableParameter( m_newParameter );
01961 }
01962 
01963 void KWChangeFootNoteParametersCommand::unexecute()
01964 {
01965     changeVariableParameter( m_oldParameter );
01966 }
01967 
01968 void KWChangeFootNoteParametersCommand::changeVariableParameter( FootNoteParameter _param )
01969 {
01970     m_var->setNoteType( _param.noteType );
01971     m_var->setNumberingType( _param.numberingType );
01972     m_var->setManualString( _param.manualString );
01973     m_var->setNumDisplay( -1 ); // force renumberFootNotes to recalc
01974     if (  m_var->numberingType()== KWFootNoteVariable::Manual)
01975     {
01976         m_var->resize();
01977         m_var->paragraph()->invalidate(0);
01978         m_var->paragraph()->setChanged( true );
01979     }
01980 
01981     KWTextFrameSet * frameset = dynamic_cast<KWTextFrameSet *>( m_doc->frameSet( 0 ));
01982     Q_ASSERT( frameset );
01983     if ( frameset)
01984         frameset->renumberFootNotes();
01985 
01986     // Re-layout the footnote/endnote frame
01987     KWFrame* footNoteFrame = m_var->frameSet()->frame( 0 );
01988     int framePage = footNoteFrame->pageNumber();
01989     m_doc->recalcFrames( framePage, -1 );
01990 
01991     // Repaint
01992     m_doc->delayedRepaintAllViews();
01993 }
01994 
01995 
01996 KWChangeFootNoteLineSeparatorParametersCommand::KWChangeFootNoteLineSeparatorParametersCommand( const QString &name, SeparatorLinePos _oldValuePos, SeparatorLinePos _newValuePos, int _oldLength, int _newLength, double _oldWidth, double _newWidth, SeparatorLineLineType _oldLineType, SeparatorLineLineType _newLineType, KWDocument *_doc):
01997     KNamedCommand(name),
01998     m_doc( _doc ),
01999     m_oldValuePos(_oldValuePos),
02000     m_newValuePos(_newValuePos),
02001     m_oldLength(_oldLength),
02002     m_newLength(_newLength),
02003     m_oldWidth(_oldWidth),
02004     m_newWidth(_newWidth),
02005     m_oldLineType(_oldLineType),
02006     m_newLineType(_newLineType)
02007 
02008 {
02009 }
02010 
02011 void KWChangeFootNoteLineSeparatorParametersCommand::execute()
02012 {
02013     changeLineSeparatorParameter( m_newValuePos, m_newLength, m_newWidth,m_newLineType );
02014 }
02015 
02016 void KWChangeFootNoteLineSeparatorParametersCommand::unexecute()
02017 {
02018     changeLineSeparatorParameter( m_oldValuePos, m_oldLength, m_oldWidth, m_oldLineType);
02019 }
02020 
02021 void KWChangeFootNoteLineSeparatorParametersCommand::changeLineSeparatorParameter( SeparatorLinePos _pos, int _length, double _width, SeparatorLineLineType _type)
02022 {
02023     m_doc->setFootNoteSeparatorLinePosition( _pos );
02024     m_doc->setFootNoteSeparatorLineLength( _length);
02025     m_doc->setFootNoteSeparatorLineWidth(_width );
02026     m_doc->setFootNoteSeparatorLineType( _type );
02027     m_doc->repaintAllViews();
02028 }
02029 
02030 
02031 KWRenameBookmarkCommand::KWRenameBookmarkCommand( const QString &name, const QString & _oldname, const QString & _newName, KWDocument *_doc):
02032     KNamedCommand(name),
02033     m_doc( _doc ),
02034     m_oldName( _oldname),
02035     m_newName( _newName)
02036 {
02037 }
02038 
02039 void KWRenameBookmarkCommand::execute()
02040 {
02041     m_doc->renameBookmark( m_oldName, m_newName);
02042 }
02043 
02044 void KWRenameBookmarkCommand::unexecute()
02045 {
02046     m_doc->renameBookmark( m_newName, m_oldName);
02047 }
02048 
02049 KWResizeColumnCommand::KWResizeColumnCommand( KWTableFrameSet *table, int col, double oldSize, double newSize ):
02050     KNamedCommand( i18n("Resize Column") ),
02051     m_table( table ),
02052     m_oldSize( oldSize ),
02053     m_newSize( newSize ),
02054     m_col( col )
02055 {
02056 }
02057 
02058 void KWResizeColumnCommand::execute()
02059 {
02060   m_table->resizeColumn(m_col, m_newSize);
02061   m_table->kWordDocument()->layout();
02062   m_table->kWordDocument()->repaintAllViews();
02063 }
02064 
02065 void KWResizeColumnCommand::unexecute()
02066 {
02067   m_table->resizeColumn(m_col, m_oldSize);
02068   m_table->kWordDocument()->layout();
02069   m_table->kWordDocument()->repaintAllViews();
02070 }
02071 
02072 KWResizeRowCommand::KWResizeRowCommand( KWTableFrameSet *table, int row, double oldSize, double newSize ):
02073     KNamedCommand( i18n("Resize Row") ),
02074     m_table( table ),
02075     m_oldSize( oldSize ),
02076     m_newSize( newSize ),
02077     m_row( row )
02078 {
02079 }
02080 
02081 void KWResizeRowCommand::execute()
02082 {
02083   m_table->resizeRow( m_row, m_newSize );
02084   m_table->kWordDocument()->repaintAllViews();
02085 }
02086 
02087 void KWResizeRowCommand::unexecute()
02088 {
02089   m_table->resizeRow( m_row, m_oldSize );
02090   m_table->kWordDocument()->repaintAllViews();
02091 }
KDE Home | KDE Accessibility Home | Description of Access Keys