~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to kword/kwcommand.cc

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
*/
19
19
 
20
20
#include "kwdoc.h"
21
 
#include "kwview.h"
 
21
#include "kwtextframeset.h"
22
22
#include "kwcommand.h"
23
 
#include "kwtextframeset.h"
 
23
#include "kwtablestyle.h"
 
24
#include "kwtabletemplate.h"
24
25
#include "kwtableframeset.h"
 
26
#include "kwpartframeset.h"
 
27
#include "kwtextparag.h"
25
28
#include "kwanchor.h"
26
 
 
27
 
#include <qrichtext_p.h>
 
29
#include "kwvariable.h"
 
30
#include "kovariable.h"
 
31
#include <kotextobject.h>
 
32
#include <klocale.h>
28
33
#include <kdebug.h>
29
34
 
30
 
// This is automatically called by KCommandHistory's redo action when redo is activated
31
 
void KWTextCommand::execute()
32
 
{
33
 
    m_textfs->redo();
34
 
}
35
 
 
36
 
// This is automatically called by KCommandHistory's undo action when undo is activated
37
 
void KWTextCommand::unexecute()
38
 
{
39
 
    m_textfs->undo();
40
 
}
41
 
 
42
 
KWTextDeleteCommand::KWTextDeleteCommand(
43
 
    QTextDocument *d, int i, int idx, const QArray<QTextStringChar> &str,
44
 
    const CustomItemsMap & customItemsMap,
45
 
    const QValueList<KWParagLayout> &oldParagLayouts )
46
 
    : QTextDeleteCommand( d, i, idx, str,
47
 
                          QValueList< QVector<QStyleSheetItem> >(),
48
 
                          QValueList<QStyleSheetItem::ListStyle>(),
49
 
                          QArray<int>() ),
50
 
      m_oldParagLayouts( oldParagLayouts ),
51
 
      m_customItemsMap( customItemsMap )
52
 
{
53
 
    // Note that we don't pass aligns and liststyles to QTextDeleteCommand.
54
 
    // We'll handle them here, as part of the rest, since they are in the paraglayouts
55
 
}
56
 
 
57
 
QTextCursor * KWTextDeleteCommand::execute( QTextCursor *c )
58
 
{
59
 
    QTextParag *s = doc ? doc->paragAt( id ) : parag;
60
 
    if ( !s ) {
61
 
        qWarning( "can't locate parag at %d, last parag: %d", id, doc->lastParag()->paragId() );
62
 
        return 0;
63
 
    }
64
 
    cursor.setParag( s );
65
 
    cursor.setIndex( index );
66
 
    int len = text.size();
67
 
    // Detach from custom items. They are already in the map, and we don't
68
 
    // want them to be deleted
69
 
    for ( int i = 0; i < len; ++i )
70
 
    {
71
 
        QTextStringChar * ch = cursor.parag()->at( cursor.index() );
72
 
        if ( ch->isCustom() )
73
 
        {
74
 
            static_cast<KWTextCustomItem *>( ch->customItem() )->setDeleted( true );
75
 
            static_cast<KWTextParag*>(cursor.parag())->removeCustomItem(cursor.index());
76
 
        }
77
 
        cursor.gotoRight();
78
 
    }
79
 
 
80
 
    return QTextDeleteCommand::execute(c);
81
 
}
82
 
 
83
 
QTextCursor * KWTextDeleteCommand::unexecute( QTextCursor *c )
84
 
{
85
 
    // Let QRichText re-create the text and formatting
86
 
    QTextCursor * cr = QTextDeleteCommand::unexecute(c);
87
 
 
88
 
    QTextParag *s = doc ? doc->paragAt( id ) : parag;
89
 
    if ( !s ) {
90
 
        qWarning( "can't locate parag at %d, last parag: %d", id, doc->lastParag()->paragId() );
91
 
        return 0;
92
 
    }
93
 
    cursor.setParag( s );
94
 
    cursor.setIndex( index );
95
 
    // Set any custom item that we had
96
 
    m_customItemsMap.insertItems( cursor, text.size() );
97
 
 
98
 
    // Now restore the parag layouts (i.e. KWord specific stuff)
99
 
    QValueList<KWParagLayout>::Iterator lit = m_oldParagLayouts.begin();
100
 
    kdDebug() << "KWTextDeleteCommand::unexecute " << m_oldParagLayouts.count() << " parag layouts. First parag=" << s->paragId() << endl;
101
 
    ASSERT( id == s->paragId() );
102
 
    QTextParag *p = s;
103
 
    while ( p ) {
104
 
        if ( lit != m_oldParagLayouts.end() )
105
 
        {
106
 
            kdDebug() << "KWTextDeleteCommand::unexecute applying paraglayout to parag " << p->paragId() << endl;
107
 
            static_cast<KWTextParag*>(p)->setParagLayout( *lit );
108
 
        }
109
 
        else
110
 
            break;
111
 
        //if ( s == cr->parag() )
112
 
        //    break;
113
 
        p = p->next();
114
 
        ++lit;
115
 
    }
116
 
    return cr;
117
 
}
118
 
 
119
 
KWTextParagCommand::KWTextParagCommand( QTextDocument *d, int fParag, int lParag,
120
 
                                        const QValueList<KWParagLayout> &oldParagLayouts,
121
 
                                        KWParagLayout newParagLayout,
122
 
                                        int flags,
123
 
                                        QStyleSheetItem::Margin margin )
124
 
    : QTextCommand( d ), firstParag( fParag ), lastParag( lParag ), m_oldParagLayouts( oldParagLayouts ),
125
 
      m_newParagLayout( newParagLayout ), m_flags( flags ), m_margin( margin )
126
 
{
127
 
}
128
 
 
129
 
QTextCursor * KWTextParagCommand::execute( QTextCursor *c )
130
 
{
131
 
    //kdDebug() << "KWTextParagCommand::execute" << endl;
132
 
    KWTextParag *p = static_cast<KWTextParag *>(doc->paragAt( firstParag ));
133
 
    if ( !p )
134
 
    {
135
 
        kdWarning() << "KWTextParagCommand::execute paragraph " << firstParag << "not found" << endl;
136
 
        return c;
137
 
    }
138
 
    while ( p ) {
139
 
        if ( ( m_flags & KWParagLayout::Margins ) && m_margin != (QStyleSheetItem::Margin)-1 ) // all
140
 
            p->setMargin( static_cast<QStyleSheetItem::Margin>(m_margin), m_newParagLayout.margins[m_margin] );
141
 
        else
142
 
        {
143
 
            p->setParagLayout( m_newParagLayout, m_flags );
144
 
        }
145
 
        if ( p->paragId() == lastParag )
146
 
            break;
147
 
        p = static_cast<KWTextParag *>(p->next());
148
 
    }
149
 
    //kdDebug() << "KWTextParagCommand::execute done" << endl;
150
 
    // Set cursor to end of selection. Like in QTextFormatCommand::[un]execute...
151
 
    c->setParag( p );
152
 
    c->setIndex( p->length()-1 );
153
 
    return c;
154
 
}
155
 
 
156
 
QTextCursor * KWTextParagCommand::unexecute( QTextCursor *c )
157
 
{
158
 
    KWTextParag *p = static_cast<KWTextParag *>(doc->paragAt( firstParag ));
159
 
    if ( !p )
160
 
    {
161
 
        kdDebug() << "KWTextParagCommand::unexecute paragraph " << firstParag << "not found" << endl;
162
 
        return c;
163
 
    }
164
 
    QValueList<KWParagLayout>::Iterator lit = m_oldParagLayouts.begin();
165
 
    while ( p ) {
166
 
        if ( lit == m_oldParagLayouts.end() )
167
 
        {
168
 
            kdDebug() << "KWTextParagCommand::unexecute m_oldParagLayouts not big enough!" << endl;
169
 
            break;
170
 
        }
171
 
        if ( m_flags & KWParagLayout::Margins && m_margin != (QStyleSheetItem::Margin)-1 ) // just one
172
 
            p->setMargin( static_cast<QStyleSheetItem::Margin>(m_margin), (*lit).margins[m_margin] );
173
 
        else
174
 
        {
175
 
            p->setParagLayout( *lit, m_flags );
176
 
        }
177
 
        if ( p->paragId() == lastParag )
178
 
            break;
179
 
        p = static_cast<KWTextParag *>(p->next());
180
 
        ++lit;
181
 
    }
182
 
    // Set cursor to end of selection. Like in QTextFormatCommand::[un]execute...
183
 
    c->setParag( p );
184
 
    c->setIndex( p->length()-1 );
185
 
    return c;
186
 
}
187
 
 
188
 
//////////
189
 
 
190
 
KWParagFormatCommand::KWParagFormatCommand( QTextDocument *d, int fParag, int lParag,
191
 
                                                          const QValueList<QTextFormat *> &oldFormats,
192
 
                                                          QTextFormat * newFormat )
193
 
    : QTextCommand( d ), firstParag( fParag ), lastParag( lParag ), m_oldFormats( oldFormats ),
194
 
      m_newFormat( newFormat )
195
 
{
196
 
    QValueList<QTextFormat *>::Iterator lit = m_oldFormats.begin();
197
 
    for ( ; lit != m_oldFormats.end() ; ++lit )
198
 
        (*lit)->addRef();
199
 
}
200
 
 
201
 
KWParagFormatCommand::~KWParagFormatCommand()
202
 
{
203
 
    QValueList<QTextFormat *>::Iterator lit = m_oldFormats.begin();
204
 
    for ( ; lit != m_oldFormats.end() ; ++lit )
205
 
        (*lit)->removeRef();
206
 
}
207
 
 
208
 
QTextCursor * KWParagFormatCommand::execute( QTextCursor *c )
209
 
{
210
 
    KWTextParag *p = static_cast<KWTextParag *>(doc->paragAt( firstParag ));
211
 
    if ( !p )
212
 
    {
213
 
        kdDebug() << "KWTextParagCommand::execute paragraph " << firstParag << "not found" << endl;
214
 
        return c;
215
 
    }
216
 
    while ( p ) {
217
 
        p->setFormat( m_newFormat );
218
 
        p->invalidate(0);
219
 
        if ( p->paragId() == lastParag )
220
 
            break;
221
 
        p = static_cast<KWTextParag *>(p->next());
222
 
    }
223
 
    return c;
224
 
}
225
 
 
226
 
QTextCursor * KWParagFormatCommand::unexecute( QTextCursor *c )
227
 
{
228
 
    QTextParag *p = doc->paragAt( firstParag );
229
 
    if ( !p )
230
 
    {
231
 
        kdDebug() << "KWParagFormatCommand::unexecute paragraph " << firstParag << "not found" << endl;
232
 
        return c;
233
 
    }
234
 
    QValueList<QTextFormat *>::Iterator lit = m_oldFormats.begin();
235
 
    while ( p ) {
236
 
        if ( lit == m_oldFormats.end() )
237
 
        {
238
 
            kdDebug() << "KWParagFormatCommand::unexecute m_oldFormats not big enough!" << endl;
239
 
            break;
240
 
        }
241
 
        p->setFormat( (*lit) );
242
 
        if ( p->paragId() == lastParag )
243
 
            break;
244
 
        p = p->next();
245
 
        ++lit;
246
 
    }
247
 
    return c;
248
 
}
249
 
 
250
 
KWPasteTextCommand::KWPasteTextCommand( QTextDocument *d, int parag, int idx,
 
35
 
 
36
KWPasteTextCommand::KWPasteTextCommand( KoTextDocument *d, int parag, int idx,
251
37
                                const QCString & data )
252
 
    : QTextCommand( d ), m_parag( parag ), m_idx( idx ), m_data( data )
 
38
    : KoTextDocCommand( d ), m_parag( parag ), m_idx( idx ), m_data( data ), m_oldParagLayout( 0 )
253
39
{
254
40
}
255
41
 
256
 
QTextCursor * KWPasteTextCommand::execute( QTextCursor *c )
 
42
KoTextCursor * KWPasteTextCommand::execute( KoTextCursor *c )
257
43
{
258
 
    QTextParag *firstParag = doc->paragAt( m_parag );
 
44
    KoTextParag *firstParag = doc->paragAt( m_parag );
259
45
    if ( !firstParag ) {
260
46
        qWarning( "can't locate parag at %d, last parag: %d", m_parag, doc->lastParag()->paragId() );
261
47
        return 0;
264
50
    //          << " firstParag=" << firstParag << " " << firstParag->paragId() << endl;
265
51
    cursor.setParag( firstParag );
266
52
    cursor.setIndex( m_idx );
 
53
    c->setParag( firstParag );
 
54
    c->setIndex( m_idx );
267
55
    QDomDocument domDoc;
268
56
    domDoc.setContent( m_data );
269
57
    QDomElement elem = domDoc.documentElement();
 
58
    KWTextDocument * textdoc = static_cast<KWTextDocument *>(c->parag()->document());
 
59
    KWTextFrameSet * textFs = textdoc->textFrameSet();
270
60
    // We iterate twice over the list of paragraphs.
271
61
    // First time to gather the text,
272
62
    // second time to apply the character & paragraph formatting
274
64
 
275
65
    QValueList<QDomElement> listParagraphs;
276
66
    QDomElement paragraph = elem.firstChild().toElement();
277
 
    bool first = true;
278
67
    for ( ; !paragraph.isNull() ; paragraph = paragraph.nextSibling().toElement() )
279
68
    {
280
69
        if ( paragraph.tagName() == "PARAGRAPH" )
281
70
        {
282
71
            QString s = paragraph.namedItem( "TEXT" ).toElement().text();
283
 
            if ( !first )
284
 
                text += '\n';
285
 
            else
286
 
                first = false;
287
 
            text += s;
 
72
            //kdDebug() << "KWPasteTextCommand::execute Inserting text: '" << s << "'" << endl;
 
73
            c->insert( s, false /*newline=linebreak, not new parag*/ );
 
74
 
 
75
            if ( !paragraph.nextSibling().isNull() ) // Not for last parag
 
76
            {
 
77
                // Create new parag
 
78
                // Lowlevel method:
 
79
                c->splitAndInsertEmptyParag( FALSE, TRUE );
 
80
                // Highlevel method:
 
81
                //c->insert( "\n", true );
 
82
            }
288
83
            listParagraphs.append( paragraph );
289
84
        }
290
85
    }
291
 
    //kdDebug() << "KWPasteTextCommand::execute Inserting text: '" << text << "'" << endl;
292
 
    KWTextDocument * textdoc = static_cast<KWTextDocument *>(c->parag()->document());
293
 
    KWTextFrameSet * textFs = textdoc->textFrameSet();
294
 
    textFs->unzoom();
295
 
 
296
 
    cursor.insert( text, true );
297
 
 
298
 
    // Move cursor to the end
299
 
    c->setParag( firstParag );
300
 
    c->setIndex( m_idx );
301
 
    for ( int i = 0; i < (int)text.length(); ++i )
302
 
        c->gotoRight();
303
86
 
304
87
    // Redo the parag lookup because if firstParag was empty, insert() has
305
88
    // shifted it down (side effect of splitAndInsertEmptyParag)
327
110
                QDomElement formatElem = layout.namedItem( "FORMAT" ).toElement();
328
111
                if ( !formatElem.isNull() )
329
112
                {
330
 
                    QTextFormat f = parag->loadFormat( formatElem, 0L, QFont() );
331
 
                    QTextFormat * defaultFormat = doc->formatCollection()->format( &f );
 
113
                    KoTextFormat f = parag->loadFormat( formatElem, 0L, QFont(), KGlobal::locale()->language(),false );
 
114
                    KoTextFormat * defaultFormat = doc->formatCollection()->format( &f );
332
115
                    // Last paragraph (i.e. only one in all) : some of the text might be from before the paste
333
116
                    int endIndex = (item == count-1) ? c->index() : parag->string()->length() - 1;
334
117
                    parag->setFormat( m_idx, endIndex - m_idx, defaultFormat, TRUE );
335
118
                }
336
119
            }
337
120
 
338
 
            parag->loadFormatting( paragElem, m_idx );
 
121
            parag->loadFormatting( paragElem, m_idx, (textFs->isMainFrameset()));
339
122
        }
340
123
        else
341
124
        {
342
125
            if ( item == 0 ) // This paragraph existed, store its parag layout
343
 
                m_oldParagLayout = parag->paragLayout();
 
126
            {
 
127
                delete m_oldParagLayout;
 
128
                m_oldParagLayout = new KoParagLayout( parag->paragLayout() );
 
129
            }
344
130
            parag->loadLayout( paragElem );
345
131
            // Last paragraph: some of the text might be from before the paste
346
132
            int len = (item == count-1) ? c->index() : parag->string()->length();
347
133
            // Apply default format
348
134
            parag->setFormat( 0, len, parag->paragFormat(), TRUE );
349
 
            parag->loadFormatting( paragElem );
 
135
            parag->loadFormatting( paragElem, 0, (textFs->isMainFrameset()) );
350
136
        }
351
 
        parag->format();
 
137
        parag->invalidate(0); // the formatting will be done by caller (either KWTextFrameSet::pasteKWord or KoTextObject::undo/redo)
352
138
        parag->setChanged( TRUE );
353
139
        parag = static_cast<KWTextParag *>(parag->next());
354
140
        //kdDebug() << "KWPasteTextCommand::execute going to next parag: " << parag << endl;
355
141
    }
 
142
    textFs->textObject()->setNeedSpellCheck( true );
356
143
    textFs->zoom( false );
357
 
 
358
144
    // In case loadFormatting queued any image request
359
145
    KWDocument * doc = textFs->kWordDocument();
360
 
    doc->processImageRequests();
 
146
    doc->processPictureRequests();
361
147
 
 
148
    //kdDebug() << "KWPasteTextCommand::execute calling doc->pasteFrames" << endl;
362
149
    // In case of any inline frameset
363
 
    doc->pasteFrames( elem, 0 );
 
150
    doc->pasteFrames( elem, 0,
 
151
                      true /*don't change footnote attribute*/ ,
 
152
                      (textFs->isMainFrameset()) /*load footnotes if mainframeset*/,
 
153
                      false /*don't select frames*/ );
 
154
    doc->completePasting();
364
155
 
365
156
    m_lastParag = c->parag()->paragId();
366
157
    m_lastIndex = c->index();
370
161
// Helper class for deleting all custom items
371
162
// (KWTextFrameset::removeSelectedText and readFormats do that already,
372
163
//  but with undo/redo, and copying all formatting etc.)
373
 
class KWDeleteCustomItemVisitor : public KWParagVisitor // see kwtextdocument.h
 
164
class KWDeleteCustomItemVisitor : public KoParagVisitor // see kotextdocument.h
374
165
{
375
166
public:
376
 
    KWDeleteCustomItemVisitor() : KWParagVisitor() { }
377
 
    virtual bool visit( QTextParag *parag, int start, int end )
 
167
    KWDeleteCustomItemVisitor() : KoParagVisitor() { }
 
168
    virtual bool visit( KoTextParag *parag, int start, int end )
378
169
    {
379
170
        kdDebug() << "KWPasteTextCommand::execute " << parag->paragId() << " " << start << " " << end << endl;
380
171
        for ( int i = start ; i < end ; ++i )
381
172
        {
382
 
            QTextStringChar * ch = parag->at( i );
 
173
            KoTextStringChar * ch = parag->at( i );
383
174
            if ( ch->isCustom() )
384
175
            {
385
 
               KWTextCustomItem* item = static_cast<KWTextCustomItem *>( ch->customItem() );
386
 
               item->setDeleted( true );
 
176
               KoTextCustomItem* item = ch->customItem();
 
177
       item->setDeleted( true );
 
178
            parag->removeCustomItem(i);
387
179
               KCommand* itemCmd = item->deleteCommand();
388
180
               if ( itemCmd ) itemCmd->execute();
389
181
            }
392
184
    }
393
185
};
394
186
 
395
 
QTextCursor * KWPasteTextCommand::unexecute( QTextCursor *c )
 
187
KoTextCursor * KWPasteTextCommand::unexecute( KoTextCursor *c )
396
188
{
397
 
    QTextParag *firstParag = doc->paragAt( m_parag );
 
189
    KoTextParag *firstParag = doc->paragAt( m_parag );
398
190
    if ( !firstParag ) {
399
191
        qWarning( "can't locate parag at %d, last parag: %d", m_parag, doc->lastParag()->paragId() );
400
192
        return 0;
401
193
    }
402
194
    cursor.setParag( firstParag );
403
195
    cursor.setIndex( m_idx );
404
 
    doc->setSelectionStart( QTextDocument::Temp, &cursor );
 
196
    doc->setSelectionStart( KoTextDocument::Temp, &cursor );
405
197
 
406
 
    QTextParag *lastParag = doc->paragAt( m_lastParag );
 
198
    KoTextParag *lastParag = doc->paragAt( m_lastParag );
407
199
    if ( !lastParag ) {
408
200
        qWarning( "can't locate parag at %d, last parag: %d", m_lastParag, doc->lastParag()->paragId() );
409
201
        return 0;
410
202
    }
 
203
    Q_ASSERT( lastParag->document() );
 
204
    // Get hold of the document before deleting the parag
 
205
    KoTextDocument* textdoc = lastParag->document();
 
206
 
 
207
    //kdDebug() << "Undoing paste: deleting from (" << firstParag->paragId() << "," << m_idx << ")"
 
208
    //          << " to (" << lastParag->paragId() << "," << m_lastIndex << ")" << endl;
 
209
 
411
210
    cursor.setParag( lastParag );
412
211
    cursor.setIndex( m_lastIndex );
413
 
    doc->setSelectionEnd( QTextDocument::Temp, &cursor );
 
212
    doc->setSelectionEnd( KoTextDocument::Temp, &cursor );
414
213
    // Delete all custom items
415
214
    KWDeleteCustomItemVisitor visitor;
416
 
    static_cast<KoTextDocument *>(doc)->visitSelection( QTextDocument::Temp, &visitor );
417
 
 
418
 
    doc->removeSelectedText( QTextDocument::Temp, c /* sets c to the correct position */ );
419
 
 
420
 
    if ( m_idx == 0 )
421
 
        static_cast<KWTextParag *>( firstParag )->setParagLayout( m_oldParagLayout );
 
215
    doc->visitSelection( KoTextDocument::Temp, &visitor );
 
216
 
 
217
    doc->removeSelectedText( KoTextDocument::Temp, c /* sets c to the correct position */ );
 
218
 
 
219
    KWTextFrameSet * textFs = static_cast<KWTextDocument *>(textdoc)->textFrameSet();
 
220
 
 
221
    textFs->renumberFootNotes();
 
222
    if ( m_idx == 0 ) {
 
223
        Q_ASSERT( m_oldParagLayout );
 
224
        if ( m_oldParagLayout )
 
225
            firstParag->setParagLayout( *m_oldParagLayout );
 
226
    }
422
227
    return c;
423
228
}
424
229
 
425
 
KWTextFormatCommand::KWTextFormatCommand(QTextDocument *d, int sid, int sidx, int eid, int eidx, const QMemArray<QTextStringChar> &old, QTextFormat *f, int fl )
426
 
    : QTextFormatCommand(d, sid, sidx, eid, eidx, old, f, fl)
427
 
{
428
 
}
429
 
 
430
 
 
431
 
KWTextFormatCommand::~KWTextFormatCommand()
432
 
{
433
 
}
434
 
 
435
 
void KWTextFormatCommand::resizeCustomItem()
436
 
{
437
 
    QTextParag *sp = doc->paragAt( startId );
438
 
    QTextParag *ep = doc->paragAt( endId );
439
 
    if ( !sp || !ep )
 
230
 
 
231
KWTextDeleteCommand::KWTextDeleteCommand( KoTextDocument *d, int i, int idx, const QMemArray<KoTextStringChar> &str,
 
232
                         const CustomItemsMap & customItemsMap,
 
233
                         const QValueList<KoParagLayout> & oldParagLayouts )
 
234
    :KoTextDeleteCommand(d, i, idx, str, customItemsMap, oldParagLayouts)
 
235
{
 
236
    //createBookmarkList();
 
237
}
 
238
 
 
239
void KWTextDeleteCommand::createBookmarkList()
 
240
{
 
241
#if 0
 
242
    KoTextParag *s = doc ? doc->paragAt( id ) : parag;
 
243
    if ( !s ) {
 
244
        qWarning( "can't locate parag at %d, last parag: %d", id, doc->lastParag()->paragId() );
440
245
        return;
441
 
 
442
 
    QTextCursor start( doc );
443
 
    start.setParag( sp );
444
 
    start.setIndex( startIndex );
445
 
    QTextCursor end( doc );
446
 
    end.setParag( ep );
447
 
    end.setIndex( endIndex );
448
 
 
449
 
    doc->setSelectionStart( QTextDocument::Temp, &start );
450
 
    doc->setSelectionEnd( QTextDocument::Temp, &end );
451
 
 
452
 
 
453
 
    if ( start.parag() == end.parag() )
454
 
    {
455
 
        QString text = start.parag()->string()->toString().mid( start.index(), end.index() - start.index() );
456
 
        for ( int i = start.index(); i < end.index(); ++i )
457
 
        {
458
 
            if( start.parag()->at(i)->isCustom())
459
 
            {
460
 
                static_cast<KWTextCustomItem *>( start.parag()->at(i)->customItem() )->resize();
461
 
            }
462
 
        }
463
 
    }
464
 
    else
465
 
    {
466
 
        int i;
467
 
        QString text = start.parag()->string()->toString().mid( start.index(), start.parag()->length() - 1 - start.index() );
468
 
        for ( i = start.index(); i < start.parag()->length(); ++i )
469
 
            if( start.parag()->at(i)->isCustom())
470
 
            {
471
 
                static_cast<KWTextCustomItem *>( start.parag()->at(i)->customItem() )->resize();
472
 
            }
473
 
 
474
 
        QTextParag *p = start.parag()->next();
475
 
        while ( p && p != end.parag() )
476
 
        {
477
 
            text = p->string()->toString().left( p->length() - 1 );
478
 
            for ( i = 0; i < p->length(); ++i )
479
 
            {
480
 
               if( p->at(i)->isCustom())
481
 
               {
482
 
                   static_cast<KWTextCustomItem *>(p->at(i)->customItem() )->resize();
483
 
               }
484
 
            }
485
 
            p = p->next();
486
 
        }
487
 
        text = end.parag()->string()->toString().left( end.index() );
488
 
        for ( i = 0; i < end.index(); ++i )
489
 
        {
490
 
            if( end.parag()->at(i)->isCustom())
491
 
            {
492
 
                static_cast<KWTextCustomItem *>( end.parag()->at(i)->customItem() )->resize();
493
 
            }
494
 
        }
495
 
    }
496
 
}
497
 
 
498
 
QTextCursor *KWTextFormatCommand::execute( QTextCursor *c )
499
 
{
500
 
    QTextCursor *tmp=QTextFormatCommand::execute( c );
501
 
    QTextParag *sp = doc->paragAt( startId );
502
 
    QTextParag *ep = doc->paragAt( endId );
503
 
    if ( !sp || !ep )
504
 
        return c;
505
 
 
506
 
    resizeCustomItem();
507
 
 
508
 
    return tmp;
509
 
}
510
 
 
511
 
QTextCursor *KWTextFormatCommand::unexecute( QTextCursor *c )
512
 
{
513
 
    QTextCursor*tmp= QTextFormatCommand::unexecute( c );
514
 
 
515
 
    QTextParag *sp = doc->paragAt( startId );
516
 
    QTextParag *ep = doc->paragAt( endId );
517
 
    if ( !sp || !ep )
518
 
        return c;
519
 
 
520
 
    resizeCustomItem();
521
 
 
522
 
    return tmp;
523
 
}
524
 
 
 
246
    }
 
247
 
 
248
    // Now restore the parag layouts (i.e. libkotext specific stuff)
 
249
    QValueList<KoParagLayout>::Iterator lit = m_oldParagLayouts.begin();
 
250
    kdDebug(32500) << "KWTextDeleteCommand::createBookmarkList " << m_oldParagLayouts.count() << " parag layouts. First parag=" << s->paragId() << endl;
 
251
    Q_ASSERT( id == s->paragId() );
 
252
    KoTextParag *p = s;
 
253
    while ( p ) {
 
254
        if ( lit != m_oldParagLayouts.end() )
 
255
        {
 
256
            kdDebug(32500) << "KWTextDeleteCommand::unexecute find bookmark in parag " << p->paragId() << endl;
 
257
            //p->setParagLayout( *lit );
 
258
        }
 
259
        else
 
260
            break;
 
261
        p = p->next();
 
262
        ++lit;
 
263
    }
 
264
#endif
 
265
}
 
266
 
 
267
KoTextCursor *KWTextDeleteCommand::execute( KoTextCursor *c )
 
268
{
 
269
    return KoTextDeleteCommand::execute( c );
 
270
}
 
271
 
 
272
KoTextCursor *KWTextDeleteCommand::unexecute( KoTextCursor *c )
 
273
{
 
274
    return KoTextDeleteCommand::unexecute( c );
 
275
}
525
276
 
526
277
////////////////////////// Frame commands ////////////////////////////////
527
278
 
528
279
FrameIndex::FrameIndex( KWFrame *frame )
529
280
{
530
 
    m_pFrameSet=frame->getFrameSet();
531
 
    m_iFrameIndex=m_pFrameSet->getFrameFromPtr(frame);
 
281
    m_pFrameSet=frame->frameSet();
 
282
    m_iFrameIndex=m_pFrameSet->frameFromPtr(frame);
532
283
}
533
284
 
534
 
KWFrameBorderCommand::KWFrameBorderCommand( const QString &name, QList<FrameIndex> &_listFrameIndex, QList<FrameBorderTypeStruct> &_frameTypeBorder,const Border & _newBorder):
535
 
    KCommand(name),
 
285
KWFrameBorderCommand::KWFrameBorderCommand( const QString &name, QPtrList<FrameIndex> &_listFrameIndex, QPtrList<FrameBorderTypeStruct> &_frameTypeBorder,const KoBorder & _newBorder):
 
286
    KNamedCommand(name),
536
287
    m_indexFrame(_listFrameIndex),
537
288
    m_oldBorderFrameType(_frameTypeBorder),
538
289
    m_newBorder( _newBorder)
539
290
{
540
291
}
541
292
 
 
293
KWFrameBorderCommand::~KWFrameBorderCommand()
 
294
{
 
295
    m_indexFrame.setAutoDelete( true);
 
296
    m_oldBorderFrameType.setAutoDelete( true);
 
297
}
 
298
 
542
299
void KWFrameBorderCommand::execute()
543
300
{
544
301
    FrameIndex *tmp;
547
304
    {
548
305
        KWFrameSet *frameSet =tmp->m_pFrameSet;
549
306
        doc = frameSet->kWordDocument();
550
 
        KWFrame *frame=frameSet->getFrame(tmp->m_iFrameIndex);
 
307
        KWFrame *frame=frameSet->frame(tmp->m_iFrameIndex);
 
308
        KWTableFrameSet::Cell *cell = dynamic_cast<KWTableFrameSet::Cell *>(frame->frameSet());
551
309
        FrameBorderTypeStruct *tmpFrameStruct=m_oldBorderFrameType.at(m_indexFrame.find(tmp));
 
310
 
552
311
        switch( tmpFrameStruct->m_EFrameType)
553
312
        {
554
313
            case  FBLeft:
555
 
                frame->setLeftBorder(m_newBorder);
 
314
                if(cell) // is a table cell
 
315
                    cell->setLeftBorder(m_newBorder);
 
316
                else
 
317
                    frame->setLeftBorder(m_newBorder);
556
318
                break;
557
319
            case FBRight:
558
 
                frame->setRightBorder(m_newBorder);
 
320
                if(cell) // is a table cell
 
321
                    cell->setRightBorder(m_newBorder);
 
322
                else
 
323
                     frame->setRightBorder(m_newBorder);
559
324
                break;
560
325
            case FBTop:
561
 
                frame->setTopBorder(m_newBorder);
 
326
                if(cell) // is a table cell
 
327
                    cell->setTopBorder(m_newBorder);
 
328
                else
 
329
                      frame->setTopBorder(m_newBorder);
562
330
                break;
563
331
            case FBBottom:
564
 
                frame->setBottomBorder(m_newBorder);
 
332
                if(cell) // is a table cell
 
333
                    cell->setBottomBorder(m_newBorder);
 
334
                else
 
335
                    frame->setBottomBorder(m_newBorder);
565
336
                break;
566
337
            default:
567
338
                break;
568
339
        }
 
340
 
 
341
        if (!cell) {
 
342
            frame->frameBordersChanged();
 
343
            if (frame->isSelected())
 
344
                frame->updateResizeHandles();
 
345
            //fixme frameBorderChanged for table cells here too ?
 
346
        }
 
347
        else
 
348
            cell->table()->refreshSelectedCell();
569
349
    }
 
350
 
 
351
 
570
352
    if ( doc )
571
353
    {
572
354
        doc->refreshFrameBorderButton();
582
364
    {
583
365
        KWFrameSet *frameSet =tmp->m_pFrameSet;
584
366
        doc = frameSet->kWordDocument();
585
 
        KWFrame *frame=frameSet->getFrame(tmp->m_iFrameIndex);
 
367
        KWFrame *frame=frameSet->frame(tmp->m_iFrameIndex);
 
368
        KWTableFrameSet::Cell *cell = dynamic_cast<KWTableFrameSet::Cell *>(frame->frameSet());
586
369
        FrameBorderTypeStruct *tmpFrameStruct=m_oldBorderFrameType.at(m_indexFrame.find(tmp));
587
370
        switch(tmpFrameStruct->m_EFrameType)
588
371
        {
589
372
            case  FBLeft:
590
 
                frame->setLeftBorder(tmpFrameStruct->m_OldBorder);
 
373
                if(cell) // is a table cell
 
374
                    cell->setLeftBorder(tmpFrameStruct->m_OldBorder);
 
375
                else
 
376
                    frame->setLeftBorder(tmpFrameStruct->m_OldBorder);
591
377
                break;
592
378
            case FBRight:
593
 
                frame->setRightBorder(tmpFrameStruct->m_OldBorder);
 
379
                if(cell) // is a table cell
 
380
                    cell->setRightBorder(tmpFrameStruct->m_OldBorder);
 
381
                else
 
382
                    frame->setRightBorder(tmpFrameStruct->m_OldBorder);
594
383
                break;
595
384
            case FBTop:
596
 
                frame->setTopBorder(tmpFrameStruct->m_OldBorder);
 
385
                if(cell) // is a table cell
 
386
                    cell->setTopBorder(tmpFrameStruct->m_OldBorder);
 
387
                else
 
388
                    frame->setTopBorder(tmpFrameStruct->m_OldBorder);
597
389
                break;
598
390
            case FBBottom:
599
 
                frame->setBottomBorder(tmpFrameStruct->m_OldBorder);
 
391
                if(cell) // is a table cell
 
392
                    cell->setBottomBorder(tmpFrameStruct->m_OldBorder);
 
393
                else
 
394
                    frame->setBottomBorder(tmpFrameStruct->m_OldBorder);
600
395
                break;
601
396
            default:
602
397
                break;
603
398
        }
 
399
        if (!cell) {
 
400
                frame->frameBordersChanged();
 
401
                if (frame->isSelected())
 
402
                        frame->updateResizeHandles();
 
403
                    //fixme frameBorderChanged for table cells here too ?
 
404
        }
 
405
        else
 
406
            cell->table()->refreshSelectedCell();
 
407
 
604
408
    }
 
409
 
 
410
 
 
411
 
605
412
    if ( doc )
606
413
    {
607
414
        doc->refreshFrameBorderButton();
610
417
    }
611
418
}
612
419
 
613
 
KWFrameBackGroundColorCommand::KWFrameBackGroundColorCommand( const QString &name, QList<FrameIndex> &_listFrameIndex, QList<QBrush> &_oldBrush,const QBrush & _newColor ):
614
 
    KCommand(name),
 
420
KWFrameBackGroundColorCommand::KWFrameBackGroundColorCommand( const QString &name, QPtrList<FrameIndex> &_listFrameIndex, QPtrList<QBrush> &_oldBrush,const QBrush & _newColor ):
 
421
    KNamedCommand(name),
615
422
    m_indexFrame(_listFrameIndex),
616
423
    m_oldBackGroundColor(_oldBrush),
617
424
    m_newColor( _newColor)
618
425
{
619
426
}
620
427
 
 
428
KWFrameBackGroundColorCommand::~KWFrameBackGroundColorCommand()
 
429
{
 
430
    m_indexFrame.setAutoDelete(true);
 
431
    m_oldBackGroundColor.setAutoDelete(true);
 
432
}
 
433
 
 
434
 
621
435
void KWFrameBackGroundColorCommand::execute()
622
436
{
623
437
    FrameIndex *tmp;
625
439
    for ( tmp=m_indexFrame.first(); tmp != 0; tmp=m_indexFrame.next() )
626
440
    {
627
441
        KWFrameSet *frameSet =tmp->m_pFrameSet;
628
 
        doc = frameSet->kWordDocument();
629
 
        KWFrame *frame=frameSet->getFrame(tmp->m_iFrameIndex);
630
 
        frame->setBackgroundColor(m_newColor);
 
442
        if ( frameSet && (frameSet->type() != FT_PICTURE) && (frameSet->type() != FT_PART))
 
443
        {
 
444
            doc = frameSet->kWordDocument();
 
445
            KWFrame *frame=frameSet->frame(tmp->m_iFrameIndex);
 
446
            frame->setBackgroundColor(m_newColor);
 
447
        }
631
448
    }
632
449
    //update frame
633
450
    if ( doc )
641
458
    for ( tmp=m_indexFrame.first(); tmp != 0; tmp=m_indexFrame.next() )
642
459
    {
643
460
        KWFrameSet *frameSet =tmp->m_pFrameSet;
644
 
        doc = frameSet->kWordDocument();
645
 
        KWFrame *frame=frameSet->getFrame(tmp->m_iFrameIndex);
646
 
        QBrush *tmpFrameStruct=m_oldBackGroundColor.at(m_indexFrame.find(tmp));
647
 
        frame->setBackgroundColor(*tmpFrameStruct);
 
461
        if ( frameSet && (frameSet->type() != FT_PICTURE) && (frameSet->type() != FT_PART) )
 
462
        {
 
463
            doc = frameSet->kWordDocument();
 
464
            KWFrame *frame=frameSet->frame(tmp->m_iFrameIndex);
 
465
            QBrush *tmpFrameStruct=m_oldBackGroundColor.at(m_indexFrame.find(tmp));
 
466
            frame->setBackgroundColor(*tmpFrameStruct);
 
467
        }
648
468
    }
649
469
 
650
470
    //update frames
652
472
        doc->repaintAllViews();
653
473
}
654
474
 
655
 
 
656
 
KWFrameResizeCommand::KWFrameResizeCommand( const QString &name, FrameIndex _frameIndex, FrameResizeStruct _frameResize ) :
657
 
    KCommand(name),
 
475
KWFrameStyleCommand::KWFrameStyleCommand( const QString &name, KWFrame *_frame, KWFrameStyle *_fs, bool _repaintViews ) :
 
476
    KNamedCommand( name )
 
477
{
 
478
    m_frame = _frame;
 
479
    m_fs = _fs;
 
480
    repaintViews = _repaintViews;
 
481
 
 
482
    m_oldValues = new KWFrameStyle( "Old", m_frame );
 
483
}
 
484
 
 
485
void KWFrameStyleCommand::execute()
 
486
{
 
487
    applyFrameStyle( m_fs);
 
488
}
 
489
 
 
490
void KWFrameStyleCommand::unexecute()
 
491
{
 
492
    applyFrameStyle( m_oldValues);
 
493
}
 
494
 
 
495
void KWFrameStyleCommand::applyFrameStyle( KWFrameStyle * _sty )
 
496
{
 
497
    if ( m_frame->frameSet() && (m_frame->frameSet()->type() != FT_PICTURE)&& (m_frame->frameSet()->type() != FT_PART))
 
498
        m_frame->setBackgroundColor( _sty->backgroundColor() );
 
499
    m_frame->setLeftBorder( _sty->leftBorder() );
 
500
    m_frame->setRightBorder( _sty->rightBorder() );
 
501
    m_frame->setTopBorder( _sty->topBorder() );
 
502
    m_frame->setBottomBorder( _sty->bottomBorder() );
 
503
 
 
504
    m_frame->frameBordersChanged();
 
505
    if (m_frame->isSelected())
 
506
        m_frame->updateResizeHandles();
 
507
 
 
508
    if ( repaintViews )
 
509
        m_frame->frameSet()->kWordDocument()->repaintAllViews();
 
510
    m_frame->frameSet()->kWordDocument()->refreshFrameBorderButton();
 
511
}
 
512
 
 
513
 
 
514
KWTableStyleCommand::KWTableStyleCommand( const QString &name, KWFrame *_frame, KWTableStyle *_ts, bool _repaintViews ) :
 
515
    KNamedCommand( name )
 
516
{
 
517
    m_frame = _frame;
 
518
    m_ts = _ts;
 
519
    repaintViews = _repaintViews;
 
520
 
 
521
    // No need for i18n because it will never be displayed.
 
522
    m_fsc = new KWFrameStyleCommand( "Apply Framestyle to Frame", m_frame, m_ts->pFrameStyle(), repaintViews );
 
523
    m_sc = 0L;
 
524
}
 
525
 
 
526
KWTableStyleCommand::~KWTableStyleCommand()
 
527
{
 
528
    delete m_fsc;
 
529
    delete m_sc;
 
530
}
 
531
 
 
532
void KWTableStyleCommand::execute()
 
533
{
 
534
    if (m_fsc)
 
535
        m_fsc->execute();
 
536
 
 
537
    if ( (m_ts) && ( m_frame->frameSet()->type() == FT_TEXT ) && ( m_ts->pStyle() ) )
 
538
    {
 
539
        KoTextObject *textObject = ((KWTextFrameSet*)m_frame->frameSet())->textObject();
 
540
        textObject->textDocument()->selectAll( KoTextDocument::Temp );
 
541
        m_sc = textObject->applyStyleCommand( 0L, m_ts->pStyle(), KoTextDocument::Temp, KoParagLayout::All, KoTextFormat::Format, true, false );
 
542
        textObject->textDocument()->removeSelection( KoTextDocument::Temp );
 
543
    }
 
544
 
 
545
    m_frame->frameBordersChanged();
 
546
    if (m_frame->isSelected())
 
547
        m_frame->updateResizeHandles();
 
548
 
 
549
    if ( repaintViews )
 
550
        m_frame->frameSet()->kWordDocument()->repaintAllViews();
 
551
    m_frame->frameSet()->kWordDocument()->refreshFrameBorderButton();
 
552
 
 
553
}
 
554
 
 
555
void KWTableStyleCommand::unexecute()
 
556
{
 
557
    if (m_fsc)
 
558
        m_fsc->unexecute();
 
559
    if (m_sc)
 
560
        m_sc->unexecute();
 
561
 
 
562
    m_frame->frameBordersChanged();
 
563
    if (m_frame->isSelected())
 
564
        m_frame->updateResizeHandles();
 
565
 
 
566
    if ( repaintViews )
 
567
        m_frame->frameSet()->kWordDocument()->repaintAllViews();
 
568
    m_frame->frameSet()->kWordDocument()->refreshFrameBorderButton();
 
569
}
 
570
 
 
571
KWTableTemplateCommand::KWTableTemplateCommand( const QString &name, KWTableFrameSet *_table, KWTableTemplate *_tt ) :
 
572
    KNamedCommand( name )
 
573
{
 
574
    m_table = _table;
 
575
    m_tt = _tt;
 
576
 
 
577
    // No need for i18n because it will never be displayed.
 
578
    m_tableCommands = new KMacroCommand( "Apply Tablestyles to Table" );
 
579
 
 
580
 
 
581
    KWTableStyle *cell = 0L;
 
582
    unsigned int rows = m_table->getRows();
 
583
    unsigned int cols = m_table->getCols();
 
584
 
 
585
    for ( unsigned int i = 0; i < rows; i++ )
 
586
    {
 
587
        for ( unsigned int j = 0; j < cols; j++ )
 
588
        {
 
589
            if ( (i==0) && (j==0) ) // TOP LEFT CORNER
 
590
                cell = m_tt->pTopLeftCorner();
 
591
            else
 
592
            if ( (i==0) && ( j==(cols-1) ) ) // TOP RIGHT CORNER
 
593
                cell = m_tt->pTopRightCorner();
 
594
            else
 
595
            if ( ( i==(rows-1) ) && (j==0) ) // BOTTOM LEFT CORNER
 
596
                cell = m_tt->pBottomLeftCorner();
 
597
            else
 
598
            if ( ( i==(rows-1) ) && ( j==(cols-1) ) ) // BOTTOM RIGHT CORNER
 
599
                cell = m_tt->pBottomRightCorner();
 
600
            else
 
601
            if ( ( i==0 ) && ( j>0 ) && ( j<(cols-1) ) ) // FIRST ROW
 
602
                cell = m_tt->pFirstRow();
 
603
            else
 
604
            if ( ( j==0 ) && ( i>0 ) && ( i<(rows-1) ) ) // FIRST COL
 
605
                cell = m_tt->pFirstCol();
 
606
            else
 
607
            if ( ( i==(rows-1) ) && ( j>0 ) && ( j<(cols-1) ) )  // LAST ROW
 
608
                cell = m_tt->pLastRow();
 
609
            else
 
610
            if ( ( j==(cols-1) ) && ( i>0 ) && ( i<(rows-1) ) ) // LAST COL
 
611
                cell = m_tt->pLastCol();
 
612
            else
 
613
            if ( (i>0) && (j>0) && (i<(rows-1)) && (j<(cols-1)) ) // BODY
 
614
                cell = m_tt->pBodyCell();
 
615
 
 
616
            m_tableCommands->addCommand( new KWTableStyleCommand( "Apply tablestyle to cell", m_table->getCell(i,j)->frame(0),cell, false ) );
 
617
        }
 
618
    }
 
619
}
 
620
 
 
621
KWTableTemplateCommand::~KWTableTemplateCommand()
 
622
{
 
623
    delete m_tableCommands;
 
624
}
 
625
 
 
626
void KWTableTemplateCommand::execute()
 
627
{
 
628
    m_tableCommands->execute();
 
629
    m_table->kWordDocument()->repaintAllViews();
 
630
}
 
631
 
 
632
void KWTableTemplateCommand::unexecute()
 
633
{
 
634
    m_tableCommands->unexecute();
 
635
    m_table->kWordDocument()->repaintAllViews();
 
636
}
 
637
 
 
638
 
 
639
KWFrameResizeCommand::KWFrameResizeCommand( const QString &name, FrameIndex _frameIndex, const FrameResizeStruct& _frameResize ) :
 
640
    KNamedCommand(name),
658
641
    m_indexFrame(_frameIndex),
659
642
    m_FrameResize(_frameResize)
660
643
{
 
644
    //kdDebug() << "Resize command: oldRect=" << m_FrameResize.oldRect
 
645
    //          << " oldMinHeight=" << m_FrameResize.oldMinHeight
 
646
    //          << " newRect=" << m_FrameResize.newRect
 
647
    //          << " newMinHeight=" << m_FrameResize.newMinHeight << endl;
661
648
}
662
649
 
663
650
void KWFrameResizeCommand::execute()
664
651
{
665
652
    KWFrameSet *frameSet = m_indexFrame.m_pFrameSet;
666
 
    ASSERT( frameSet );
667
 
    KWFrame *frame = frameSet->getFrame(m_indexFrame.m_iFrameIndex);
668
 
    ASSERT( frame );
669
 
    frame->setCoords(m_FrameResize.sizeOfEnd.left(),m_FrameResize.sizeOfEnd.top(),m_FrameResize.sizeOfEnd.right(),m_FrameResize.sizeOfEnd.bottom());
 
653
    Q_ASSERT( frameSet );
 
654
    KWFrame *frame = frameSet->frame(m_indexFrame.m_iFrameIndex);
 
655
    Q_ASSERT( frame );
 
656
    frame->setCoords(m_FrameResize.newRect.left(),m_FrameResize.newRect.top(),m_FrameResize.newRect.right(),m_FrameResize.newRect.bottom());
 
657
    frame->setMinFrameHeight(m_FrameResize.newMinHeight);
670
658
 
671
 
    KWTableFrameSet *table = frame->getFrameSet()->getGroupManager();
 
659
    KWTableFrameSet *table = frame->frameSet()->getGroupManager();
672
660
    if (table) {
673
 
        KWTableFrameSet::Cell *cell=dynamic_cast<KWTableFrameSet::Cell *>(frame->getFrameSet());
 
661
        KWTableFrameSet::Cell *cell=dynamic_cast<KWTableFrameSet::Cell *>(frame->frameSet());
674
662
        if(cell)
675
663
        {
676
 
            table->recalcCols(cell->m_col,cell->m_row);
677
 
            table->recalcRows(cell->m_col,cell->m_row);
 
664
            table->recalcCols(cell->firstCol(), cell->firstRow());
 
665
            table->recalcRows(cell->firstCol(), cell->firstRow());
678
666
        }
679
667
        else
680
668
        {
681
669
           table->recalcCols();
682
670
           table->recalcRows();
683
671
        }
684
 
        table->updateTempHeaders();
685
672
        table->refreshSelectedCell();
686
673
        //repaintTableHeaders( table );
687
674
    }
688
675
    KWDocument * doc = frameSet->kWordDocument();
689
 
 
690
 
    if(frameSet->isAHeader() || frameSet->isAFooter())
 
676
    if ( frameSet->frameSetInfo() != KWFrameSet::FI_BODY ) // header/footer/footnote
691
677
        doc->recalcFrames();
 
678
 
692
679
    frame->updateRulerHandles();
693
680
 
 
681
    //update frames
694
682
    doc->frameChanged( frame );
695
683
}
696
684
 
697
685
void KWFrameResizeCommand::unexecute()
698
686
{
699
687
    KWFrameSet *frameSet =m_indexFrame.m_pFrameSet;
700
 
    KWFrame *frame=frameSet->getFrame(m_indexFrame.m_iFrameIndex);
701
 
    frame->setCoords(m_FrameResize.sizeOfBegin.left(),m_FrameResize.sizeOfBegin.top(),m_FrameResize.sizeOfBegin.right(),m_FrameResize.sizeOfBegin.bottom());
702
 
    KWTableFrameSet *table = frame->getFrameSet()->getGroupManager();
 
688
    KWFrame *frame=frameSet->frame(m_indexFrame.m_iFrameIndex);
 
689
    frame->setCoords(m_FrameResize.oldRect.left(),m_FrameResize.oldRect.top(),m_FrameResize.oldRect.right(),m_FrameResize.oldRect.bottom());
 
690
    frame->setMinFrameHeight(m_FrameResize.oldMinHeight);
 
691
    KWTableFrameSet *table = frame->frameSet()->getGroupManager();
703
692
    if (table) {
704
 
        KWTableFrameSet::Cell *cell=dynamic_cast<KWTableFrameSet::Cell *>(frame->getFrameSet());
 
693
        KWTableFrameSet::Cell *cell=dynamic_cast<KWTableFrameSet::Cell *>(frame->frameSet());
705
694
        if(cell)
706
695
        {
707
 
            table->recalcCols(cell->m_col,cell->m_row);
708
 
            table->recalcRows(cell->m_col,cell->m_row);
 
696
            table->recalcCols(cell->firstCol(), cell->firstRow());
 
697
            table->recalcRows(cell->firstCol(), cell->firstRow());
709
698
        }
710
699
        else
711
700
        {
712
701
           table->recalcCols();
713
702
           table->recalcRows();
714
703
        }
715
 
        table->updateTempHeaders();
716
704
        table->refreshSelectedCell();
717
705
        //repaintTableHeaders( table );
718
706
    }
719
707
    KWDocument * doc = frameSet->kWordDocument();
720
 
    if(frameSet->isAHeader() || frameSet->isAFooter())
 
708
    if ( frameSet->frameSetInfo() != KWFrameSet::FI_BODY ) // header/footer/footnote
721
709
        doc->recalcFrames();
722
710
 
723
711
    frame->updateRulerHandles();
726
714
    doc->frameChanged( frame );
727
715
}
728
716
 
729
 
 
730
 
KWFramePartMoveCommand::KWFramePartMoveCommand( const QString &name, FrameIndex _frameIndex, FrameResizeStruct _frameMove ) :
731
 
    KCommand(name),
 
717
KWFrameChangePictureCommand::KWFrameChangePictureCommand( const QString &name, FrameIndex _frameIndex, const KoPictureKey & _oldKey, const KoPictureKey & _newKey ) :
 
718
    KNamedCommand(name),
 
719
    m_indexFrame(_frameIndex),
 
720
    m_oldKey(_oldKey),
 
721
    m_newKey(_newKey)
 
722
{
 
723
}
 
724
 
 
725
void KWFrameChangePictureCommand::execute()
 
726
{
 
727
    KWFrameSet *frameSet = m_indexFrame.m_pFrameSet;
 
728
    Q_ASSERT( frameSet );
 
729
    KWFrame *frame = frameSet->frame(m_indexFrame.m_iFrameIndex);
 
730
    Q_ASSERT( frame );
 
731
    KWDocument * doc = frameSet->kWordDocument();
 
732
    KWPictureFrameSet *frameset = static_cast<KWPictureFrameSet *>(frame->frameSet());
 
733
    frameset->reloadPicture( m_newKey );
 
734
    frameSet->kWordDocument()->refreshDocStructure( frameSet->type() );
 
735
    doc->frameChanged( frame );
 
736
}
 
737
 
 
738
void KWFrameChangePictureCommand::unexecute()
 
739
{
 
740
    KWFrameSet *frameSet =m_indexFrame.m_pFrameSet;
 
741
    KWFrame *frame=frameSet->frame(m_indexFrame.m_iFrameIndex);
 
742
    KWDocument * doc = frameSet->kWordDocument();
 
743
    KWPictureFrameSet *frameset = static_cast<KWPictureFrameSet *>(frame->frameSet());
 
744
    frameset->reloadPicture( m_oldKey );
 
745
    frameSet->kWordDocument()->refreshDocStructure( frameSet->type() );
 
746
    doc->frameChanged( frame );
 
747
}
 
748
 
 
749
 
 
750
KWFramePartMoveCommand::KWFramePartMoveCommand( const QString &name, FrameIndex _frameIndex,  FrameResizeStruct _frameMove ) :
 
751
    KNamedCommand(name),
732
752
    m_indexFrame(_frameIndex),
733
753
    m_frameMove(_frameMove)
734
754
{
737
757
void KWFramePartMoveCommand::execute()
738
758
{
739
759
    KWFrameSet *frameSet = m_indexFrame.m_pFrameSet;
740
 
    ASSERT( frameSet );
741
 
    KWFrame *frame = frameSet->getFrame(m_indexFrame.m_iFrameIndex);
742
 
    ASSERT( frame );
743
 
    frame->setCoords(m_frameMove.sizeOfEnd.left(),m_frameMove.sizeOfEnd.top(),m_frameMove.sizeOfEnd.right(),m_frameMove.sizeOfEnd.bottom());
 
760
    Q_ASSERT( frameSet );
 
761
    KWFrame *frame = frameSet->frame(m_indexFrame.m_iFrameIndex);
 
762
    Q_ASSERT( frame );
 
763
    frame->setCoords(m_frameMove.newRect.left(),m_frameMove.newRect.top(),m_frameMove.newRect.right(),m_frameMove.newRect.bottom());
744
764
 
745
765
    KWDocument * doc = frameSet->kWordDocument();
746
766
 
751
771
void KWFramePartMoveCommand::unexecute()
752
772
{
753
773
    KWFrameSet *frameSet =m_indexFrame.m_pFrameSet;
754
 
    ASSERT( frameSet );
755
 
    KWFrame *frame=frameSet->getFrame(m_indexFrame.m_iFrameIndex);
756
 
    ASSERT( frame );
757
 
    frame->setCoords(m_frameMove.sizeOfBegin.left(),m_frameMove.sizeOfBegin.top(),m_frameMove.sizeOfBegin.right(),m_frameMove.sizeOfBegin.bottom());
 
774
    KWFrame *frame=frameSet->frame(m_indexFrame.m_iFrameIndex);
 
775
    frame->setCoords(m_frameMove.oldRect.left(),m_frameMove.oldRect.top(),m_frameMove.oldRect.right(),m_frameMove.oldRect.bottom());
758
776
 
759
777
    KWDocument * doc = frameSet->kWordDocument();
760
778
    frame->updateRulerHandles();
765
783
 
766
784
bool KWFramePartMoveCommand::frameMoved()
767
785
{
768
 
    return  (m_frameMove.sizeOfBegin!=m_frameMove.sizeOfEnd);
769
 
}
770
 
 
771
 
KWFrameMoveCommand::KWFrameMoveCommand( const QString &name, QList<FrameIndex> &_frameIndex, QList<FrameResizeStruct>&_frameMove  ) :
772
 
    KCommand(name),
 
786
    return  (m_frameMove.oldRect!=m_frameMove.newRect);
 
787
}
 
788
 
 
789
KWFramePartInternalCommand::KWFramePartInternalCommand( const QString &name, KWPartFrameSet *part ) :
 
790
    KNamedCommand(name),
 
791
    m_part(part)
 
792
{
 
793
    m_url = m_part->getChild()->document()->url();
 
794
}
 
795
 
 
796
void KWFramePartInternalCommand::execute()
 
797
{
 
798
    m_part->getChild()->document()->setStoreInternal(true);
 
799
}
 
800
 
 
801
void KWFramePartInternalCommand::unexecute()
 
802
{
 
803
    m_part->getChild()->document()->setStoreInternal(false);
 
804
    m_part->getChild()->document()->setURL( m_url );
 
805
}
 
806
 
 
807
 
 
808
KWFramePartExternalCommand::KWFramePartExternalCommand( const QString &name, KWPartFrameSet *part ) :
 
809
    KNamedCommand(name),
 
810
    m_part(part)
 
811
{
 
812
}
 
813
 
 
814
void KWFramePartExternalCommand::execute()
 
815
{
 
816
    m_part->getChild()->document()->setStoreInternal(false);
 
817
}
 
818
 
 
819
void KWFramePartExternalCommand::unexecute()
 
820
{
 
821
    m_part->getChild()->document()->setStoreInternal(true);
 
822
}
 
823
 
 
824
 
 
825
KWFrameMoveCommand::KWFrameMoveCommand( const QString &name,
 
826
                                        const QValueList<FrameIndex> & _frameIndex,
 
827
                                        const QValueList<FrameMoveStruct> & _frameMove  ) :
 
828
    KNamedCommand(name),
773
829
    m_indexFrame(_frameIndex),
774
830
    m_frameMove(_frameMove)
775
831
{
778
834
void KWFrameMoveCommand::execute()
779
835
{
780
836
    bool needRelayout = false;
781
 
    FrameIndex *tmp;
782
837
    KWDocument * doc = 0L;
783
 
    for ( tmp=m_indexFrame.first(); tmp != 0; tmp=m_indexFrame.next() )
 
838
    QValueList<FrameMoveStruct>::Iterator moveIt = m_frameMove.begin();
 
839
    QValueList<FrameIndex>::Iterator tmp = m_indexFrame.begin();
 
840
    for( ; tmp != m_indexFrame.end() && moveIt != m_frameMove.end(); ++tmp, ++moveIt )
784
841
    {
785
 
        KWFrameSet *frameSet = tmp->m_pFrameSet;
 
842
        KWFrameSet *frameSet = (*tmp).m_pFrameSet;
786
843
        doc = frameSet->kWordDocument();
787
 
        KWFrame *frame=frameSet->getFrame(tmp->m_iFrameIndex);
788
 
        FrameResizeStruct *tmpFrameMove=m_frameMove.at(m_indexFrame.find(tmp));
789
 
        KWTableFrameSet *table=frameSet->getGroupManager();
 
844
        KWFrame *frame = frameSet->frame((*tmp).m_iFrameIndex);
 
845
        KWTableFrameSet *table = frameSet->getGroupManager();
790
846
        if(table)
791
847
        {
792
 
            table->moveBy(tmpFrameMove->sizeOfEnd.left()-tmpFrameMove->sizeOfBegin.left(),tmpFrameMove->sizeOfEnd.top()-tmpFrameMove->sizeOfBegin.top());
 
848
            KoPoint diff = (*moveIt).newPos - (*moveIt).oldPos;
 
849
            table->moveBy( diff.x(), diff.y() );
793
850
        }
794
851
        else
795
 
            frame->setCoords(tmpFrameMove->sizeOfEnd.left(),tmpFrameMove->sizeOfEnd.top(),tmpFrameMove->sizeOfEnd.right(),tmpFrameMove->sizeOfEnd.bottom());
 
852
            frame->moveTopLeft( (*moveIt).newPos );
796
853
 
797
854
        frame->updateRulerHandles();
798
855
        needRelayout = needRelayout || ( frame->runAround() != KWFrame::RA_NO );
811
868
void KWFrameMoveCommand::unexecute()
812
869
{
813
870
    bool needRelayout = false;
814
 
    FrameIndex *tmp;
815
871
    KWDocument * doc = 0L;
816
 
    for ( tmp=m_indexFrame.first(); tmp != 0; tmp=m_indexFrame.next() )
 
872
    QValueList<FrameMoveStruct>::Iterator moveIt = m_frameMove.begin();
 
873
    QValueList<FrameIndex>::Iterator tmp = m_indexFrame.begin();
 
874
    for( ; tmp != m_indexFrame.end() && moveIt != m_frameMove.end(); ++tmp, ++moveIt )
817
875
    {
818
 
        KWFrameSet *frameSet =tmp->m_pFrameSet;
 
876
        KWFrameSet *frameSet = (*tmp).m_pFrameSet;
819
877
        doc = frameSet->kWordDocument();
820
 
        KWFrame *frame=frameSet->getFrame(tmp->m_iFrameIndex);
821
 
        FrameResizeStruct *tmpFrameMove=m_frameMove.at(m_indexFrame.find(tmp));
822
 
        KWTableFrameSet *table=frameSet->getGroupManager();
 
878
        KWFrame *frame = frameSet->frame((*tmp).m_iFrameIndex);
 
879
        KWTableFrameSet *table = frameSet->getGroupManager();
823
880
        if(table)
824
881
        {
825
 
            table->moveBy(tmpFrameMove->sizeOfBegin.left()-tmpFrameMove->sizeOfEnd.left(),tmpFrameMove->sizeOfBegin.top()-tmpFrameMove->sizeOfEnd.top());
 
882
            KoPoint diff = (*moveIt).oldPos - (*moveIt).newPos;
 
883
            table->moveBy( diff.x(), diff.y() );
826
884
        }
827
885
        else
828
 
            frame->setCoords(tmpFrameMove->sizeOfBegin.left(),tmpFrameMove->sizeOfBegin.top(),tmpFrameMove->sizeOfBegin.right(),tmpFrameMove->sizeOfBegin.bottom());
 
886
            frame->moveTopLeft( (*moveIt).oldPos );
829
887
 
830
888
        frame->updateRulerHandles();
831
889
        needRelayout = needRelayout || ( frame->runAround() != KWFrame::RA_NO );
842
900
}
843
901
 
844
902
KWFramePropertiesCommand::KWFramePropertiesCommand( const QString &name, KWFrame *_frameBefore,  KWFrame *_frameAfter ) :
845
 
    KCommand(name),
 
903
    KNamedCommand(name),
846
904
    m_frameIndex( _frameAfter ),
847
905
    m_frameBefore(_frameBefore),
848
906
    m_frameAfter(_frameAfter->getCopy())
859
917
{
860
918
    kdDebug() << "KWFrameChangeParamCommand::execute" << endl;
861
919
    KWFrameSet *frameSet = m_frameIndex.m_pFrameSet;
862
 
    ASSERT( frameSet );
 
920
    Q_ASSERT( frameSet );
863
921
 
864
 
    KWFrame *frame = frameSet->getFrame( m_frameIndex.m_iFrameIndex );
865
 
    ASSERT( frame );
 
922
    KWFrame *frame = frameSet->frame( m_frameIndex.m_iFrameIndex );
 
923
    Q_ASSERT( frame );
866
924
    frame->copySettings(m_frameAfter);
867
925
 
868
926
    KWDocument * doc = frameSet->kWordDocument();
881
939
{
882
940
    kdDebug() << "KWFrameChangeParamCommand::unexecute" << endl;
883
941
    KWFrameSet *frameSet = m_frameIndex.m_pFrameSet;
884
 
    ASSERT( frameSet );
 
942
    Q_ASSERT( frameSet );
885
943
 
886
 
    KWFrame *frame = frameSet->getFrame( m_frameIndex.m_iFrameIndex );
887
 
    ASSERT( frame );
 
944
    KWFrame *frame = frameSet->frame( m_frameIndex.m_iFrameIndex );
 
945
    Q_ASSERT( frame );
888
946
    frame->copySettings(m_frameBefore);
889
 
 
890
947
    KWDocument * doc = frameSet->kWordDocument();
891
948
    if(doc)
892
949
    {
900
957
}
901
958
 
902
959
 
903
 
KWFrameSetFloatingCommand::KWFrameSetFloatingCommand( const QString &name, KWFrameSet *frameset, bool floating ) :
904
 
    KCommand(name),
 
960
KWFrameSetPropertyCommand::KWFrameSetPropertyCommand( const QString &name, KWFrameSet *frameset, Property prop, const QString& value ) :
 
961
    KNamedCommand(name),
905
962
    m_pFrameSet( frameset ),
906
 
    m_bFloating( floating )
907
 
{
908
 
}
909
 
 
910
 
void KWFrameSetFloatingCommand::execute()
911
 
{
912
 
    kdDebug() << "KWFrameSetFloatingCommand::execute" << endl;
913
 
    if ( m_bFloating )
914
 
    {
915
 
        // Make frame(set) floating
916
 
        m_pFrameSet->setFloating();
917
 
        // ## We might want to store a list of anchors in the command, and reuse them
918
 
        // in execute/unexecute. Currently setFixed forgets the anchors and setFloating recreates new ones...
919
 
    }
920
 
    else
921
 
    {
922
 
        // Make frame(set) non-floating
923
 
        m_pFrameSet->setFixed();
924
 
    }
925
 
    m_pFrameSet->kWordDocument()->updateAllFrames();
926
 
    m_pFrameSet->kWordDocument()->repaintAllViews();
927
 
    m_pFrameSet->kWordDocument()->updateRulerFrameStartEnd();
928
 
    m_pFrameSet->kWordDocument()->updateResizeHandles();
929
 
}
930
 
 
931
 
void KWFrameSetFloatingCommand::unexecute()
932
 
{
933
 
    kdDebug() << "KWFrameSetFloatingCommand::unexecute" << endl;
934
 
    if ( !m_bFloating )
935
 
    {
936
 
        // Make frame(set) floating again
937
 
        m_pFrameSet->setFloating();
938
 
    }
939
 
    else
940
 
    {
941
 
        // Make frame(set) non-floating again
942
 
        m_pFrameSet->setFixed();
943
 
    }
944
 
    m_pFrameSet->kWordDocument()->updateAllFrames();
945
 
    m_pFrameSet->kWordDocument()->repaintAllViews();
946
 
    m_pFrameSet->kWordDocument()->updateRulerFrameStartEnd();
947
 
    m_pFrameSet->kWordDocument()->updateResizeHandles();
948
 
}
949
 
 
950
 
KWPageLayoutCommand::KWPageLayoutCommand( const QString &name,KWDocument *_doc,pageLayout &_oldLayout, pageLayout &_newLayout  ) :
951
 
    KCommand(name),
 
963
    m_property( prop ),
 
964
    m_value( value )
 
965
{
 
966
    switch ( m_property ) {
 
967
    case FSP_NAME:
 
968
        m_oldValue = m_pFrameSet->getName();
 
969
        break;
 
970
    case FSP_FLOATING:
 
971
        m_oldValue = m_pFrameSet->isFloating() ? "true" : "false";
 
972
        break;
 
973
    case FSP_KEEPASPECTRATION:
 
974
        m_oldValue = static_cast<KWPictureFrameSet*>(m_pFrameSet)->keepAspectRatio() ? "keepRatio" : "dontKeepRatio";
 
975
        break;
 
976
    case FSP_PROTECTSIZE:
 
977
        m_oldValue = m_pFrameSet->isProtectSize() ? "true" : "false";
 
978
        break;
 
979
    }
 
980
}
 
981
 
 
982
void KWFrameSetPropertyCommand::setValue( const QString &value )
 
983
{
 
984
    kdDebug() << "KWFrameSetPropertyCommand::execute" << endl;
 
985
    switch ( m_property ) {
 
986
    case FSP_NAME:
 
987
        m_pFrameSet->setName( value );
 
988
        break;
 
989
    case FSP_FLOATING:
 
990
        if ( value == "true" )
 
991
        {
 
992
            // Make frame(set) floating
 
993
            m_pFrameSet->setFloating();
 
994
            // ## We might want to store a list of anchors in the command, and reuse them
 
995
            // in execute/unexecute. Currently setFixed forgets the anchors and setFloating recreates new ones...
 
996
        }
 
997
        else if(value == "false")
 
998
        {
 
999
            // Make frame(set) non-floating
 
1000
            m_pFrameSet->setFixed();
 
1001
        }
 
1002
    case FSP_KEEPASPECTRATION:
 
1003
        if( value == "keepRatio")
 
1004
        {
 
1005
            KWPictureFrameSet * frameSet=dynamic_cast<KWPictureFrameSet*>(m_pFrameSet);
 
1006
            if(frameSet)
 
1007
                frameSet->setKeepAspectRatio( true );
 
1008
        }
 
1009
        else if( value=="dontKeepRatio")
 
1010
        {
 
1011
            KWPictureFrameSet * frameSet=dynamic_cast<KWPictureFrameSet*>(m_pFrameSet);
 
1012
            if(frameSet)
 
1013
                frameSet->setKeepAspectRatio( false );
 
1014
        }
 
1015
        break;
 
1016
    case FSP_PROTECTSIZE:
 
1017
        if( value == "true")
 
1018
            m_pFrameSet->setProtectSize( true );
 
1019
        else
 
1020
            m_pFrameSet->setProtectSize( false );
 
1021
        m_pFrameSet->kWordDocument()->repaintResizeHandles();
 
1022
        m_pFrameSet->kWordDocument()->updateCursorType();
 
1023
        break;
 
1024
    }
 
1025
 
 
1026
    m_pFrameSet->kWordDocument()->updateResizeHandles();
 
1027
 
 
1028
    m_pFrameSet->kWordDocument()->updateAllFrames();
 
1029
    m_pFrameSet->kWordDocument()->repaintAllViews();
 
1030
    m_pFrameSet->kWordDocument()->updateRulerFrameStartEnd();
 
1031
}
 
1032
 
 
1033
void KWFrameSetPropertyCommand::execute()
 
1034
{
 
1035
    setValue( m_value );
 
1036
}
 
1037
 
 
1038
void KWFrameSetPropertyCommand::unexecute()
 
1039
{
 
1040
    setValue( m_oldValue );
 
1041
}
 
1042
 
 
1043
KWPageLayoutCommand::KWPageLayoutCommand( const QString &name,KWDocument *_doc,KWPageLayoutStruct &_oldLayout, KWPageLayoutStruct &_newLayout  ) :
 
1044
    KNamedCommand(name),
952
1045
    m_pDoc(_doc),
953
 
    m_OldLayout(_oldLayout),
954
 
    m_NewLayout(_newLayout)
 
1046
    m_oldLayout(_oldLayout),
 
1047
    m_newLayout(_newLayout)
955
1048
{
956
1049
}
957
1050
 
958
1051
void KWPageLayoutCommand::execute()
959
1052
{
960
 
    m_pDoc->setPageLayout( m_NewLayout._pgLayout,m_NewLayout._cl, m_NewLayout._hf );
961
 
    m_pDoc->updateRuler();
962
 
    m_pDoc->updateResizeHandles();
963
 
    m_pDoc->updateContentsSize();
964
 
    m_pDoc->repaintAllViews();
 
1053
    m_pDoc->setPageLayout( m_newLayout._pgLayout, m_newLayout._cl, m_newLayout._hf );
965
1054
}
966
1055
 
967
1056
void KWPageLayoutCommand::unexecute()
968
1057
{
969
 
    m_pDoc->setPageLayout( m_OldLayout._pgLayout,m_OldLayout._cl, m_OldLayout._hf);
970
 
    m_pDoc->updateRuler();
971
 
    m_pDoc->updateResizeHandles();
972
 
    m_pDoc->updateContentsSize();
973
 
    m_pDoc->repaintAllViews();
 
1058
    m_pDoc->setPageLayout( m_oldLayout._pgLayout, m_oldLayout._cl, m_oldLayout._hf);
974
1059
}
975
1060
 
976
1061
 
977
1062
KWDeleteFrameCommand::KWDeleteFrameCommand( const QString &name, KWFrame * frame ):
978
 
    KCommand(name),
 
1063
    KNamedCommand(name),
979
1064
    m_frameIndex( frame ),
980
1065
    m_copyFrame( frame->getCopy() )
981
1066
{
986
1071
    delete m_copyFrame;
987
1072
}
988
1073
 
 
1074
 
989
1075
void KWDeleteFrameCommand::execute()
990
1076
{
991
1077
    KWFrameSet *frameSet = m_frameIndex.m_pFrameSet;
992
 
    ASSERT( frameSet );
993
 
 
994
 
    KWFrame *frame = frameSet->getFrame( m_frameIndex.m_iFrameIndex );
995
 
    ASSERT( frame );
996
 
 
 
1078
    Q_ASSERT( frameSet );
 
1079
 
 
1080
    KWFrame *frame = frameSet->frame( m_frameIndex.m_iFrameIndex );
 
1081
    Q_ASSERT( frame );
 
1082
    KWDocument* doc = frameSet->kWordDocument();
 
1083
    doc->terminateEditing( frameSet );
997
1084
    frameSet->delFrame( m_frameIndex.m_iFrameIndex );
998
 
    frameSet->kWordDocument()->terminateEditing(frameSet);
999
1085
    //when you delete a frame frame pointer is deleted
1000
1086
    //so used frameChanged with a null pointer.
1001
 
    frameSet->kWordDocument()->frameChanged( 0L );
1002
 
    frameSet->kWordDocument()->refreshDocStructure( frameSet->type() );
 
1087
    doc->frameChanged( 0L );
 
1088
    doc->refreshDocStructure( frameSet->type() );
 
1089
    doc->updateRulerFrameStartEnd();
 
1090
    doc->updateTextFrameSetEdit();
1003
1091
}
1004
1092
 
1005
1093
void KWDeleteFrameCommand::unexecute()
1009
1097
    frame->setFrameSet( frameSet );
1010
1098
    frameSet->addFrame( frame );
1011
1099
 
 
1100
    KWPartFrameSet * partfs = dynamic_cast<KWPartFrameSet *>( frameSet );
 
1101
    if ( partfs )
 
1102
        partfs->setDeleted( false );
 
1103
 
1012
1104
    KWTextFrameSet * textfs = dynamic_cast<KWTextFrameSet *>( frameSet );
1013
1105
    if ( textfs )
1014
 
        textfs->formatMore();
1015
 
 
1016
 
    frameSet->kWordDocument()->frameChanged( frame );
1017
 
    frameSet->kWordDocument()->refreshDocStructure(frameSet->type());
 
1106
        textfs->textObject()->formatMore( 2 );
 
1107
    KWDocument* doc = frameSet->kWordDocument();
 
1108
    doc->frameChanged( frame );
 
1109
    // could have been the last frame on a page, so undeleting it needs to recreate the page
 
1110
    doc->recalcFrames( frame->pageNum() );
 
1111
    doc->refreshDocStructure(frameSet->type());
 
1112
    doc->updateRulerFrameStartEnd();
 
1113
    doc->updateTextFrameSetEdit();
1018
1114
}
1019
1115
 
1020
1116
KWCreateFrameCommand::KWCreateFrameCommand( const QString &name, KWFrame * frame ) :
1023
1119
 
1024
1120
 
1025
1121
KWUngroupTableCommand::KWUngroupTableCommand( const QString &name, KWTableFrameSet * _table ):
1026
 
    KCommand(name),
 
1122
    KNamedCommand(name),
1027
1123
    m_pTable(_table)
1028
1124
{
1029
1125
    m_ListFrame.clear();
1030
 
    for ( unsigned int i = 0; i < m_pTable->getNumCells(); i++ ) {
1031
 
        m_ListFrame.append(m_pTable->getCell( i ));
 
1126
    for ( KWTableFrameSet::TableIter i(m_pTable); i ; ++i ) {
 
1127
        m_ListFrame.append( i.current() );
1032
1128
    }
1033
1129
}
1034
1130
 
1035
1131
void KWUngroupTableCommand::execute()
1036
1132
{
1037
1133
    KWDocument * doc = m_pTable->kWordDocument();
1038
 
    for ( unsigned int i = 0; i < m_pTable->getNumCells(); i++ ) {
1039
 
        m_pTable->getCell( i )->setGroupManager( 0L );
1040
 
        doc->addFrameSet(m_pTable->getCell( i ));
 
1134
    for ( KWTableFrameSet::TableIter i(m_pTable) ; i ; ++i ) {
 
1135
        i->setGroupManager( 0L );
 
1136
        doc->addFrameSet( i.current() );
1041
1137
    }
1042
1138
    m_pTable->ungroup();
1043
1139
    doc->removeFrameSet(m_pTable);
1057
1153
 
1058
1154
void KWUngroupTableCommand::unexecute()
1059
1155
{
1060
 
    ASSERT(m_pTable);
 
1156
    Q_ASSERT(m_pTable);
1061
1157
    m_pTable->group();
1062
1158
    KWDocument * doc = m_pTable->kWordDocument();
1063
1159
    KWFrameSet *tmp;
1066
1162
        tmp->setGroupManager(m_pTable);
1067
1163
        doc->removeFrameSet(tmp);
1068
1164
        KWTableFrameSet::Cell *cell=static_cast<KWTableFrameSet::Cell *>(tmp);
1069
 
        ASSERT(cell);
 
1165
        Q_ASSERT(cell);
1070
1166
        m_pTable->addCell( cell );
1071
1167
    }
1072
1168
    doc->addFrameSet(m_pTable);
1083
1179
 
1084
1180
 
1085
1181
KWDeleteTableCommand::KWDeleteTableCommand( const QString &name, KWTableFrameSet * _table ):
1086
 
    KCommand(name),
 
1182
    KNamedCommand(name),
1087
1183
    m_pTable(_table)
1088
1184
{
1089
 
    ASSERT(m_pTable);
 
1185
    Q_ASSERT(m_pTable);
1090
1186
}
1091
1187
 
1092
1188
void KWDeleteTableCommand::execute()
1094
1190
    kdDebug() << "KWDeleteTableCommand::execute" << endl;
1095
1191
    KWDocument * doc = m_pTable->kWordDocument();
1096
1192
    doc->removeFrameSet(m_pTable);
 
1193
    m_pTable->setVisible( false );
1097
1194
    doc->refreshDocStructure((int)Tables);
1098
1195
    doc->updateAllFrames();
 
1196
    m_pTable->updateFrames(); // not in the doc list anymore, so the above call didn't do it!
1099
1197
    doc->layout();
1100
1198
    doc->repaintAllViews();
 
1199
    doc->updateRulerFrameStartEnd();
 
1200
 
1101
1201
}
1102
1202
 
1103
1203
void KWDeleteTableCommand::unexecute()
1104
1204
{
1105
1205
    kdDebug() << "KWDeleteTableCommand::unexecute" << endl;
1106
1206
    KWDocument * doc = m_pTable->kWordDocument();
 
1207
    m_pTable->setVisible( true );
1107
1208
    doc->addFrameSet(m_pTable);
1108
1209
    doc->refreshDocStructure((int)Tables);
1109
1210
    doc->updateAllFrames();
1110
1211
    doc->layout();
1111
1212
    doc->repaintAllViews();
 
1213
    doc->updateRulerFrameStartEnd();
1112
1214
}
1113
1215
 
1114
1216
 
1115
 
KWInsertColumnCommand::KWInsertColumnCommand( const QString &name, KWTableFrameSet * _table, int _col ):
1116
 
    KCommand(name),
 
1217
KWInsertColumnCommand::KWInsertColumnCommand( const QString &name, KWTableFrameSet * _table, int _col, double _maxRight ):
 
1218
    KNamedCommand(name),
1117
1219
    m_pTable(_table),
1118
 
    m_colPos(_col)
1119
 
{
1120
 
    ASSERT(m_pTable);
1121
 
    m_ListFrameSet.clear();
 
1220
    m_rc(new RemovedColumn()),
 
1221
    m_colPos(_col),
 
1222
    m_maxRight(_maxRight),
 
1223
    m_oldWidth(0)
 
1224
{
 
1225
    Q_ASSERT(m_pTable);
 
1226
}
 
1227
 
 
1228
KWInsertColumnCommand::~KWInsertColumnCommand()
 
1229
{
 
1230
    delete m_rc;
1122
1231
}
1123
1232
 
1124
1233
void KWInsertColumnCommand::execute()
1125
1234
{
1126
1235
    kdDebug() << "KWInsertColumnCommand::execute" << endl;
1127
1236
    KWDocument * doc = m_pTable->kWordDocument();
1128
 
    m_pTable->insertCol( m_colPos,m_ListFrameSet);
 
1237
    // a insert column = KWTableFrameSet::m_sDefaultColWidth, see kwtableframeset.cc
 
1238
    if (m_pTable->boundingRect().right() + KWTableFrameSet::m_sDefaultColWidth >= static_cast<int>(m_maxRight))
 
1239
    {   // must create space (resize the table)
 
1240
        m_oldWidth = m_pTable->boundingRect().width();
 
1241
        // here we calculate the new table size for a table that would take the
 
1242
        // entire width of the page, which what the user wants 99% of the time.
 
1243
        double newTableWidth =m_maxRight - m_pTable->boundingRect().left();
 
1244
        double newColSize = newTableWidth / (m_pTable->getCols()+1);
 
1245
        double resizeTableWidth = m_maxRight - m_pTable->boundingRect().left();
 
1246
        m_pTable->resizeWidth(resizeTableWidth - newColSize);
 
1247
        m_pTable->insertNewCol(m_colPos, newColSize);
 
1248
    }
 
1249
    else
 
1250
    {   // simply insert the column without asking for a specific size :
 
1251
        m_pTable->insertNewCol(m_colPos);
 
1252
    }
 
1253
    Q_ASSERT(m_pTable->boundingRect().right() <= m_maxRight);
1129
1254
    doc->updateAllFrames();
1130
1255
    doc->layout();
1131
1256
    doc->updateResizeHandles( );
1136
1261
{
1137
1262
    kdDebug() << "KWInsertColumnCommand::unexecute" << endl;
1138
1263
    KWDocument * doc = m_pTable->kWordDocument();
1139
 
    if(m_ListFrameSet.isEmpty())
1140
 
    {
1141
 
        for ( unsigned int i = 0; i < m_pTable->getNumCells(); i++ ) {
1142
 
            KWTableFrameSet::Cell *cell=static_cast<KWTableFrameSet::Cell *>(m_pTable->getCell( i ));
1143
 
            if(cell->m_col==m_colPos)
1144
 
                m_ListFrameSet.append(cell);
1145
 
        }
1146
 
    }
1147
1264
    doc->terminateEditing(m_pTable);
1148
1265
    doc->frameSelectedChanged();
1149
 
    m_pTable->deleteCol( m_colPos);
 
1266
    m_pTable->deleteCol(m_colPos, *m_rc);
 
1267
    // now undo the resize of the table if necessary:
 
1268
    if (m_oldWidth) {
 
1269
        // yes, the table was resized, let's undo that :
 
1270
        m_pTable->resizeWidth(m_oldWidth);
 
1271
    }
1150
1272
    doc->updateAllFrames();
1151
1273
    doc->layout();
1152
1274
    doc->updateResizeHandles( );
1156
1278
 
1157
1279
 
1158
1280
KWInsertRowCommand::KWInsertRowCommand( const QString &name, KWTableFrameSet * _table, int _row ):
1159
 
    KCommand(name),
 
1281
    KNamedCommand(name),
1160
1282
    m_pTable(_table),
1161
 
    m_rowPos(_row)
1162
 
{
1163
 
    ASSERT(m_pTable);
1164
 
    m_ListFrameSet.clear();
 
1283
    m_rr(new RemovedRow()),
 
1284
    m_rowPos(_row),
 
1285
    m_inserted(false)
 
1286
{
 
1287
    Q_ASSERT(m_pTable);
 
1288
}
 
1289
 
 
1290
KWInsertRowCommand::~KWInsertRowCommand()
 
1291
{
 
1292
    delete m_rr;
1165
1293
}
1166
1294
 
1167
1295
void KWInsertRowCommand::execute()
1168
1296
{
1169
1297
    kdDebug() << "KWInsertRowCommand::execute" << endl;
1170
1298
    KWDocument * doc = m_pTable->kWordDocument();
1171
 
    m_pTable->insertRow( m_rowPos,m_ListFrameSet);
 
1299
    if(m_inserted)
 
1300
        m_pTable->reInsertRow(*m_rr);
 
1301
    else {
 
1302
        m_inserted = true;
 
1303
        m_pTable->insertNewRow(m_rowPos);  //only happens the first time
 
1304
    }
1172
1305
    doc->updateAllFrames();
1173
1306
    doc->layout();
1174
1307
    doc->updateResizeHandles( );
1179
1312
{
1180
1313
    kdDebug() << "KWInsertRowCommand::unexecute" << endl;
1181
1314
    KWDocument * doc = m_pTable->kWordDocument();
1182
 
    if(m_ListFrameSet.isEmpty())
1183
 
    {
1184
 
        for ( unsigned int i = 0; i < m_pTable->getNumCells(); i++ ) {
1185
 
            KWTableFrameSet::Cell *cell=static_cast<KWTableFrameSet::Cell *>(m_pTable->getCell( i ));
1186
 
            if(cell->m_row==m_rowPos)
1187
 
                m_ListFrameSet.append(cell);
1188
 
        }
1189
 
    }
 
1315
 
1190
1316
    doc->terminateEditing(m_pTable);
1191
 
    m_pTable->deleteRow( m_rowPos);
 
1317
    m_pTable->deleteRow( m_rowPos, *m_rr);
 
1318
 
1192
1319
    doc->frameSelectedChanged();
1193
1320
    doc->updateAllFrames();
1194
1321
    doc->layout();
1197
1324
}
1198
1325
 
1199
1326
 
1200
 
 
1201
 
 
1202
1327
KWRemoveRowCommand::KWRemoveRowCommand( const QString &name, KWTableFrameSet * _table, int _row ):
1203
 
    KCommand(name),
 
1328
    KNamedCommand(name),
1204
1329
    m_pTable(_table),
 
1330
    m_rr(new RemovedRow()),
1205
1331
    m_rowPos(_row)
1206
1332
{
1207
 
    ASSERT(m_pTable);
 
1333
    Q_ASSERT(m_pTable);
 
1334
}
 
1335
 
 
1336
KWRemoveRowCommand::~KWRemoveRowCommand()
 
1337
{
 
1338
    delete m_rr;
1208
1339
}
1209
1340
 
1210
1341
void KWRemoveRowCommand::execute()
1213
1344
    KWDocument * doc = m_pTable->kWordDocument();
1214
1345
    doc->terminateEditing(m_pTable);
1215
1346
 
1216
 
    m_ListFrameSet.clear();
1217
 
    m_copyFrame.clear();
1218
 
    for ( unsigned int i = 0; i < m_pTable->getNumCells(); i++ )
1219
 
    {
1220
 
        KWTableFrameSet::Cell *cell=static_cast<KWTableFrameSet::Cell *>(m_pTable->getCell( i ));
1221
 
        if(cell->m_row==m_rowPos)
1222
 
        {
1223
 
            m_ListFrameSet.append(cell);
1224
 
            m_copyFrame.append(cell->getFrame(0)->getCopy());
1225
 
        }
1226
 
    }
 
1347
    m_pTable->deleteRow( m_rowPos, *m_rr);
1227
1348
 
1228
 
    m_pTable->deleteRow( m_rowPos);
1229
1349
    doc->frameSelectedChanged();
1230
1350
    doc->updateAllFrames();
1231
1351
    doc->layout();
1237
1357
{
1238
1358
    kdDebug() << "KWRemoveRowCommand::unexecute" << endl;
1239
1359
    KWDocument * doc = m_pTable->kWordDocument();
1240
 
    m_pTable->insertRow( m_rowPos,m_ListFrameSet,m_copyFrame);
 
1360
    m_pTable->reInsertRow(*m_rr);
1241
1361
    doc->updateAllFrames();
1242
1362
    doc->layout();
1243
1363
    doc->updateResizeHandles( );
1244
1364
    doc->repaintAllViews();
1245
1365
}
1246
1366
 
1247
 
 
1248
1367
KWRemoveColumnCommand::KWRemoveColumnCommand( const QString &name, KWTableFrameSet * _table, int _col ):
1249
 
    KCommand(name),
 
1368
    KNamedCommand(name),
1250
1369
    m_pTable(_table),
 
1370
    m_rc(new RemovedColumn()),
1251
1371
    m_colPos(_col)
1252
1372
{
1253
 
    ASSERT(m_pTable);
 
1373
    Q_ASSERT(m_pTable);
 
1374
}
 
1375
 
 
1376
KWRemoveColumnCommand::~KWRemoveColumnCommand()
 
1377
{
 
1378
    delete m_rc;
1254
1379
}
1255
1380
 
1256
1381
void KWRemoveColumnCommand::execute()
1259
1384
    KWDocument * doc = m_pTable->kWordDocument();
1260
1385
    doc->terminateEditing(m_pTable);
1261
1386
 
1262
 
    m_ListFrameSet.clear();
1263
 
    m_copyFrame.clear();
1264
 
    for ( unsigned int i = 0; i < m_pTable->getNumCells(); i++ )
1265
 
    {
1266
 
        KWTableFrameSet::Cell *cell=static_cast<KWTableFrameSet::Cell *>(m_pTable->getCell( i ));
1267
 
        if(cell->m_col==m_colPos)
1268
 
        {
1269
 
            m_ListFrameSet.append(cell);
1270
 
            m_copyFrame.append(cell->getFrame(0)->getCopy());
1271
 
        }
1272
 
    }
1273
 
 
1274
 
    m_pTable->deleteCol( m_colPos);
 
1387
    m_pTable->deleteCol( m_colPos, *m_rc);
1275
1388
    doc->frameSelectedChanged();
1276
1389
    doc->updateAllFrames();
1277
1390
    doc->layout();
1283
1396
{
1284
1397
    kdDebug() << "KWRemoveColumnCommand::unexecute" << endl;
1285
1398
    KWDocument * doc = m_pTable->kWordDocument();
1286
 
    m_pTable->insertCol( m_colPos,m_ListFrameSet,m_copyFrame);
 
1399
    m_pTable->reInsertCol(*m_rc);
1287
1400
    doc->updateAllFrames();
1288
1401
    doc->layout();
1289
1402
    doc->updateResizeHandles( );
1293
1406
 
1294
1407
 
1295
1408
KWSplitCellCommand::KWSplitCellCommand( const QString &name, KWTableFrameSet * _table,unsigned int colBegin,unsigned int rowBegin, unsigned int colEnd,unsigned int rowEnd ):
1296
 
    KCommand(name),
 
1409
    KNamedCommand(name),
1297
1410
    m_pTable(_table),
1298
1411
    m_colBegin(colBegin),
1299
1412
    m_rowBegin(rowBegin),
1300
1413
    m_colEnd(colEnd),
1301
1414
    m_rowEnd(rowEnd)
1302
1415
{
1303
 
    ASSERT(m_pTable);
 
1416
    Q_ASSERT(m_pTable);
1304
1417
}
1305
1418
 
1306
1419
void KWSplitCellCommand::execute()
1346
1459
        }
1347
1460
    }
1348
1461
    KWTableFrameSet::Cell *cell=static_cast<KWTableFrameSet::Cell *>(m_pTable->getCell( m_rowBegin,m_colBegin ));
1349
 
    m_pTable->joinCells(m_colBegin,m_rowBegin,m_colEnd+m_colBegin-1+cell->m_cols-1,m_rowBegin+m_rowEnd-1+cell->m_rows-1);
 
1462
    m_pTable->joinCells(m_colBegin, m_rowBegin, m_colEnd+m_colBegin-1+cell->colSpan()-1,
 
1463
        m_rowBegin+m_rowEnd-1+cell->rowSpan()-1);
1350
1464
 
1351
1465
    doc->frameSelectedChanged();
1352
1466
    doc->updateAllFrames();
1356
1470
 
1357
1471
 
1358
1472
 
1359
 
KWJoinCellCommand::KWJoinCellCommand( const QString &name, KWTableFrameSet * _table,unsigned int colBegin,unsigned int rowBegin, unsigned int colEnd,unsigned int rowEnd, QList<KWFrameSet> listFrameSet,QList<KWFrame> listCopyFrame):
1360
 
    KCommand(name),
 
1473
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):
 
1474
    KNamedCommand(name),
1361
1475
    m_pTable(_table),
1362
1476
    m_colBegin(colBegin),
1363
1477
    m_rowBegin(rowBegin),
1366
1480
    m_ListFrameSet(listFrameSet),
1367
1481
    m_copyFrame(listCopyFrame)
1368
1482
{
1369
 
    ASSERT(m_pTable);
 
1483
    Q_ASSERT(m_pTable);
 
1484
}
 
1485
KWJoinCellCommand::~KWJoinCellCommand()
 
1486
{
 
1487
    m_copyFrame.setAutoDelete( true );
1370
1488
}
1371
1489
 
1372
1490
void KWJoinCellCommand::execute()
1392
1510
    doc->layout();
1393
1511
    doc->repaintAllViews();
1394
1512
}
 
1513
 
 
1514
 
 
1515
KWChangeStartingPageCommand::KWChangeStartingPageCommand( const QString &name, KWDocument *_doc, int _oldStartingPage, int _newStartingPage):
 
1516
    KNamedCommand(name),
 
1517
    m_doc(_doc),
 
1518
    oldStartingPage(_oldStartingPage),
 
1519
    newStartingPage(_newStartingPage)
 
1520
{
 
1521
}
 
1522
 
 
1523
void KWChangeStartingPageCommand::execute()
 
1524
{
 
1525
    m_doc->getVariableCollection()->variableSetting()->setStartingPage(newStartingPage);
 
1526
    m_doc->recalcVariables( VT_PGNUM );
 
1527
}
 
1528
 
 
1529
void KWChangeStartingPageCommand::unexecute()
 
1530
{
 
1531
    m_doc->getVariableCollection()->variableSetting()->setStartingPage(oldStartingPage);
 
1532
    m_doc->recalcVariables( VT_PGNUM );
 
1533
}
 
1534
 
 
1535
KWChangeVariableSettingsCommand::KWChangeVariableSettingsCommand( const QString &name, KWDocument *_doc, bool _oldValue, bool _newValue, VariableProperties _type):
 
1536
    KNamedCommand(name),
 
1537
    m_doc(_doc),
 
1538
    type(_type),
 
1539
    m_bOldValue(_oldValue),
 
1540
    m_bNewValue(_newValue)
 
1541
{
 
1542
}
 
1543
 
 
1544
void KWChangeVariableSettingsCommand::changeValue( bool b )
 
1545
{
 
1546
    switch(type)
 
1547
    {
 
1548
    case VS_DISPLAYLINK:
 
1549
        m_doc->getVariableCollection()->variableSetting()->setDisplayLink(b);
 
1550
        m_doc->recalcVariables( VT_LINK );
 
1551
        break;
 
1552
    case  VS_UNDERLINELINK:
 
1553
        m_doc->getVariableCollection()->variableSetting()->setUnderlineLink(b);
 
1554
        m_doc->recalcVariables( VT_LINK );
 
1555
        break;
 
1556
    case VS_DISPLAYCOMMENT:
 
1557
        m_doc->getVariableCollection()->variableSetting()->setDisplayComment(b);
 
1558
        m_doc->recalcVariables( VT_NOTE );
 
1559
        break;
 
1560
    case VS_DISPLAYFIELDCODE:
 
1561
        m_doc->getVariableCollection()->variableSetting()->setDisplayFieldCode(b);
 
1562
        //hack necessary otherwise footnote frameset is not refreshing
 
1563
        //and footnote is not resize.
 
1564
        m_doc->displayFootNoteFieldCode();
 
1565
        m_doc->recalcVariables( VT_ALL );
 
1566
        break;
 
1567
    }
 
1568
}
 
1569
 
 
1570
void KWChangeVariableSettingsCommand::execute()
 
1571
{
 
1572
    changeValue(m_bNewValue);
 
1573
}
 
1574
 
 
1575
void KWChangeVariableSettingsCommand::unexecute()
 
1576
{
 
1577
    changeValue(m_bOldValue);
 
1578
}
 
1579
 
 
1580
KWChangeCustomVariableValue::KWChangeCustomVariableValue( const QString &name, KWDocument *_doc,const QString & _oldValue, const QString & _newValue,KoCustomVariable *var):
 
1581
    KNamedCommand(name),
 
1582
    m_doc(_doc),
 
1583
    newValue(_newValue),
 
1584
    oldValue(_oldValue),
 
1585
    m_var(var)
 
1586
{
 
1587
}
 
1588
 
 
1589
KWChangeCustomVariableValue::~KWChangeCustomVariableValue()
 
1590
{
 
1591
}
 
1592
 
 
1593
void KWChangeCustomVariableValue::execute()
 
1594
{
 
1595
    Q_ASSERT(m_var);
 
1596
    m_var->setValue(newValue);
 
1597
    m_doc->recalcVariables( VT_CUSTOM );
 
1598
}
 
1599
 
 
1600
void KWChangeCustomVariableValue::unexecute()
 
1601
{
 
1602
    Q_ASSERT(m_var);
 
1603
    m_var->setValue(oldValue);
 
1604
    m_doc->recalcVariables( VT_CUSTOM );
 
1605
}
 
1606
 
 
1607
KWChangeVariableNoteText::KWChangeVariableNoteText( const QString &name, KWDocument *_doc,
 
1608
                        const QString &_oldValue,const QString &_newValue,
 
1609
                        KoNoteVariable *var):
 
1610
    KNamedCommand(name),
 
1611
    m_doc(_doc),
 
1612
    newValue(_newValue),
 
1613
    oldValue(_oldValue),
 
1614
    m_var(var)
 
1615
{
 
1616
}
 
1617
 
 
1618
KWChangeVariableNoteText::~KWChangeVariableNoteText()
 
1619
{
 
1620
}
 
1621
 
 
1622
void KWChangeVariableNoteText::execute()
 
1623
{
 
1624
    Q_ASSERT(m_var);
 
1625
    m_var->setNote(newValue);
 
1626
}
 
1627
 
 
1628
void KWChangeVariableNoteText::unexecute()
 
1629
{
 
1630
    Q_ASSERT(m_var);
 
1631
    m_var->setNote(oldValue);
 
1632
}
 
1633
 
 
1634
// TODO: move to libkotext to remove code duplication with kpresenter
 
1635
KWChangeLinkVariable::KWChangeLinkVariable( const QString &name, KWDocument *_doc,const QString & _oldHref, const QString & _newHref, const QString & _oldLink,const QString &_newLink, KoLinkVariable *var):
 
1636
    KNamedCommand(name),
 
1637
    m_doc(_doc),
 
1638
    oldHref(_oldHref),
 
1639
    newHref(_newHref),
 
1640
    oldLink(_oldLink),
 
1641
    newLink(_newLink),
 
1642
    m_var(var)
 
1643
{
 
1644
}
 
1645
 
 
1646
 
 
1647
void KWChangeLinkVariable::execute()
 
1648
{
 
1649
    m_var->setLink(newLink,newHref);
 
1650
    m_doc->recalcVariables(VT_LINK);
 
1651
}
 
1652
 
 
1653
void KWChangeLinkVariable::unexecute()
 
1654
{
 
1655
    m_var->setLink(oldLink,oldHref);
 
1656
    m_doc->recalcVariables(VT_LINK);
 
1657
}
 
1658
 
 
1659
KWHideShowHeader::KWHideShowHeader( const QString &name, KWDocument *_doc, bool _newValue):
 
1660
    KNamedCommand(name),
 
1661
    m_doc(_doc),
 
1662
    newValue(_newValue)
 
1663
{
 
1664
}
 
1665
 
 
1666
 
 
1667
void KWHideShowHeader::execute()
 
1668
{
 
1669
    m_doc->setHeaderVisible(newValue );
 
1670
    m_doc->updateHeaderButton();
 
1671
 
 
1672
}
 
1673
 
 
1674
void KWHideShowHeader::unexecute()
 
1675
{
 
1676
    m_doc->setHeaderVisible(!newValue );
 
1677
    m_doc->updateHeaderButton();
 
1678
}
 
1679
 
 
1680
KWHideShowFooter::KWHideShowFooter( const QString &name, KWDocument *_doc, bool _newValue):
 
1681
    KNamedCommand(name),
 
1682
    m_doc(_doc),
 
1683
    newValue(_newValue)
 
1684
{
 
1685
}
 
1686
 
 
1687
 
 
1688
void KWHideShowFooter::execute()
 
1689
{
 
1690
    m_doc->setFooterVisible( newValue );
 
1691
    m_doc->updateFooterButton();
 
1692
}
 
1693
 
 
1694
void KWHideShowFooter::unexecute()
 
1695
{
 
1696
    m_doc->setFooterVisible( !newValue );
 
1697
    m_doc->updateFooterButton();
 
1698
}
 
1699
 
 
1700
 
 
1701
KWProtectContentCommand::KWProtectContentCommand( const QString &name, KWTextFrameSet*frameset, bool _protect):
 
1702
    KNamedCommand(name),
 
1703
    m_pFrameSet(frameset),
 
1704
    m_bProtect(_protect)
 
1705
{
 
1706
}
 
1707
 
 
1708
 
 
1709
void KWProtectContentCommand::execute()
 
1710
{
 
1711
    m_pFrameSet->textObject()->setProtectContent(m_bProtect);
 
1712
    m_pFrameSet->kWordDocument()->updateTextFrameSetEdit();
 
1713
    m_pFrameSet->kWordDocument()->testAndCloseAllFrameSetProtectedContent();
 
1714
    m_pFrameSet->kWordDocument()->updateRulerInProtectContentMode();
 
1715
 
 
1716
}
 
1717
 
 
1718
void KWProtectContentCommand::unexecute()
 
1719
{
 
1720
    m_pFrameSet->textObject()->setProtectContent(!m_bProtect);
 
1721
    m_pFrameSet->kWordDocument()->updateTextFrameSetEdit();
 
1722
    m_pFrameSet->kWordDocument()->testAndCloseAllFrameSetProtectedContent();
 
1723
    m_pFrameSet->kWordDocument()->updateRulerInProtectContentMode();
 
1724
 
 
1725
}
 
1726
 
 
1727
KWInsertRemovePageCommand::KWInsertRemovePageCommand( KWDocument *_doc, Command cmd, int pgNum)
 
1728
    : KCommand(), m_doc(_doc), m_cmd(cmd), m_pgNum(pgNum)
 
1729
{}
 
1730
 
 
1731
QString KWInsertRemovePageCommand::name() const
 
1732
{
 
1733
    return m_cmd == Insert ? i18n("Insert Page") // problem with after/before page
 
1734
                  : i18n("Delete Page %1").arg(m_pgNum);
 
1735
}
 
1736
 
 
1737
void KWInsertRemovePageCommand::execute()
 
1738
{
 
1739
    if ( m_cmd == Insert ) {
 
1740
        m_doc->insertPage( m_pgNum );
 
1741
        m_doc->afterAppendPage( m_pgNum ); // TODO rename to afterInsertPage
 
1742
    } else { // Remove
 
1743
        m_doc->removePage( m_pgNum );
 
1744
        m_doc->afterRemovePages();
 
1745
    }
 
1746
}
 
1747
 
 
1748
void KWInsertRemovePageCommand::unexecute()
 
1749
{
 
1750
    if ( m_cmd == Insert ) { // remove the page that was inserted
 
1751
        m_doc->removePage( m_pgNum+1 );
 
1752
        m_doc->afterRemovePages();
 
1753
    } else { // Re-insert the page that was deleted
 
1754
        m_doc->insertPage( m_pgNum-1 );
 
1755
        m_doc->afterAppendPage( m_pgNum-1 ); // TODO rename to afterInsertPage
 
1756
    }
 
1757
}
 
1758
 
 
1759
FrameMarginsStruct::FrameMarginsStruct( KWFrame *frame )
 
1760
{
 
1761
    topMargin = frame->bTop();
 
1762
    bottomMargin= frame->bBottom();
 
1763
    leftMargin = frame->bLeft();
 
1764
    rightMargin= frame->bRight();
 
1765
}
 
1766
 
 
1767
FrameMarginsStruct::FrameMarginsStruct( double _left, double _top, double _right, double _bottom ):
 
1768
    topMargin(_top),
 
1769
    bottomMargin(_bottom),
 
1770
    leftMargin(_left),
 
1771
    rightMargin(_right)
 
1772
{
 
1773
}
 
1774
 
 
1775
 
 
1776
KWFrameChangeFrameMarginCommand::KWFrameChangeFrameMarginCommand( const QString &name, FrameIndex _frameIndex, FrameMarginsStruct _frameMarginsBegin, FrameMarginsStruct _frameMarginsEnd ) :
 
1777
    KNamedCommand(name),
 
1778
    m_indexFrame(_frameIndex),
 
1779
    m_frameMarginsBegin(_frameMarginsBegin),
 
1780
    m_frameMarginsEnd(_frameMarginsEnd)
 
1781
{
 
1782
}
 
1783
 
 
1784
void KWFrameChangeFrameMarginCommand::execute()
 
1785
{
 
1786
    KWFrameSet *frameSet = m_indexFrame.m_pFrameSet;
 
1787
    Q_ASSERT( frameSet );
 
1788
    KWFrame *frame = frameSet->frame(m_indexFrame.m_iFrameIndex);
 
1789
    Q_ASSERT( frame );
 
1790
    frame->setFrameMargins( m_frameMarginsEnd.leftMargin,m_frameMarginsEnd.topMargin , m_frameMarginsEnd.rightMargin, m_frameMarginsEnd.bottomMargin);
 
1791
    frameSet->kWordDocument()->frameChanged( frame );
 
1792
}
 
1793
 
 
1794
void KWFrameChangeFrameMarginCommand::unexecute()
 
1795
{
 
1796
    KWFrameSet *frameSet = m_indexFrame.m_pFrameSet;
 
1797
    Q_ASSERT( frameSet );
 
1798
    KWFrame *frame = frameSet->frame(m_indexFrame.m_iFrameIndex);
 
1799
    Q_ASSERT( frame );
 
1800
    frame->setFrameMargins( m_frameMarginsBegin.leftMargin,m_frameMarginsBegin.topMargin , m_frameMarginsBegin.rightMargin, m_frameMarginsBegin.bottomMargin);
 
1801
    frameSet->kWordDocument()->frameChanged( frame );
 
1802
}
 
1803
 
 
1804
KWChangeFootEndNoteSettingsCommand::KWChangeFootEndNoteSettingsCommand( const QString &name, KoParagCounter _oldCounter, KoParagCounter _newCounter ,bool _footNote ,KWDocument *_doc):
 
1805
    KNamedCommand(name),
 
1806
    m_oldCounter(_oldCounter),
 
1807
    m_newCounter(_newCounter),
 
1808
    m_footNote( _footNote ),
 
1809
    m_doc(_doc)
 
1810
{
 
1811
}
 
1812
 
 
1813
void KWChangeFootEndNoteSettingsCommand::execute()
 
1814
{
 
1815
    changeCounter( m_newCounter);
 
1816
}
 
1817
 
 
1818
void KWChangeFootEndNoteSettingsCommand::unexecute()
 
1819
{
 
1820
    changeCounter( m_oldCounter);
 
1821
}
 
1822
 
 
1823
void KWChangeFootEndNoteSettingsCommand::changeCounter( KoParagCounter counter)
 
1824
{
 
1825
    if (m_footNote )
 
1826
    {
 
1827
        static_cast<KWVariableSettings*>(m_doc->getVariableCollection()->variableSetting())->changeFootNoteCounter(counter );
 
1828
    }
 
1829
    else
 
1830
    {
 
1831
        static_cast<KWVariableSettings*>(m_doc->getVariableCollection()->variableSetting())->changeEndNoteCounter(counter );
 
1832
    }
 
1833
    m_doc->changeFootNoteConfig();
 
1834
}
 
1835
 
 
1836
 
 
1837
KWChangeTabStopValueCommand::KWChangeTabStopValueCommand( const QString &name, double _oldValue, double _newValue, KWDocument *_doc):
 
1838
    KNamedCommand(name),
 
1839
    m_doc( _doc ),
 
1840
    m_oldValue(_oldValue),
 
1841
    m_newValue(_newValue)
 
1842
{
 
1843
}
 
1844
 
 
1845
void KWChangeTabStopValueCommand::execute()
 
1846
{
 
1847
    m_doc->setTabStopValue ( m_newValue );
 
1848
}
 
1849
 
 
1850
void KWChangeTabStopValueCommand::unexecute()
 
1851
{
 
1852
    m_doc->setTabStopValue ( m_oldValue );
 
1853
}
 
1854
 
 
1855
 
 
1856
 
 
1857
FootNoteParameter::FootNoteParameter( KWFootNoteVariable *_var )
 
1858
{
 
1859
    noteType = _var->noteType();
 
1860
    numberingType = _var->numberingType();
 
1861
    manualString = _var->manualString();
 
1862
}
 
1863
 
 
1864
FootNoteParameter::FootNoteParameter( NoteType _noteType, KWFootNoteVariable::Numbering _numberingType, const QString &_manualString)
 
1865
{
 
1866
    noteType= _noteType;
 
1867
    numberingType = _numberingType;
 
1868
    manualString = _manualString;
 
1869
}
 
1870
 
 
1871
KWChangeFootNoteParametersCommand::KWChangeFootNoteParametersCommand( const QString &name, KWFootNoteVariable * _var, FootNoteParameter _oldParameter, FootNoteParameter _newParameter, KWDocument *_doc):
 
1872
    KNamedCommand(name),
 
1873
    m_doc( _doc ),
 
1874
    m_var( _var ),
 
1875
    m_oldParameter( _oldParameter ),
 
1876
    m_newParameter( _newParameter)
 
1877
{
 
1878
}
 
1879
 
 
1880
void KWChangeFootNoteParametersCommand::execute()
 
1881
{
 
1882
    changeVariableParameter( m_newParameter );
 
1883
}
 
1884
 
 
1885
void KWChangeFootNoteParametersCommand::unexecute()
 
1886
{
 
1887
    changeVariableParameter( m_oldParameter );
 
1888
}
 
1889
 
 
1890
void KWChangeFootNoteParametersCommand::changeVariableParameter( FootNoteParameter _param )
 
1891
{
 
1892
    m_var->setNoteType( _param.noteType );
 
1893
    m_var->setNumberingType( _param.numberingType );
 
1894
    m_var->setManualString( _param.manualString );
 
1895
    m_var->setNumDisplay( -1 ); // force renumberFootNotes to recalc
 
1896
    if (  m_var->numberingType()== KWFootNoteVariable::Manual)
 
1897
    {
 
1898
        m_var->resize();
 
1899
        m_var->paragraph()->invalidate(0);
 
1900
        m_var->paragraph()->setChanged( true );
 
1901
    }
 
1902
 
 
1903
    KWTextFrameSet * frameset = dynamic_cast<KWTextFrameSet *>( m_doc->frameSet( 0 ));
 
1904
    Q_ASSERT( frameset );
 
1905
    if ( frameset)
 
1906
        frameset->renumberFootNotes();
 
1907
 
 
1908
    // Re-layout the footnote/endnote frame
 
1909
    KWFrame* footNoteFrame = m_var->frameSet()->frame( 0 );
 
1910
    int framePage = footNoteFrame->pageNum();
 
1911
    m_doc->recalcFrames( framePage, -1 );
 
1912
 
 
1913
    // Repaint
 
1914
    m_doc->delayedRepaintAllViews();
 
1915
}
 
1916
 
 
1917
 
 
1918
KWChangeFootNoteLineSeparatorParametersCommand::KWChangeFootNoteLineSeparatorParametersCommand( const QString &name, SeparatorLinePos _oldValuePos, SeparatorLinePos _newValuePos, int _oldLength, int _newLength, double _oldWidth, double _newWidth, SeparatorLineLineType _oldLineType, SeparatorLineLineType _newLineType, KWDocument *_doc):
 
1919
    KNamedCommand(name),
 
1920
    m_doc( _doc ),
 
1921
    m_oldValuePos(_oldValuePos),
 
1922
    m_newValuePos(_newValuePos),
 
1923
    m_oldLength(_oldLength),
 
1924
    m_newLength(_newLength),
 
1925
    m_oldWidth(_oldWidth),
 
1926
    m_newWidth(_newWidth),
 
1927
    m_oldLineType(_oldLineType),
 
1928
    m_newLineType(_newLineType)
 
1929
 
 
1930
{
 
1931
}
 
1932
 
 
1933
void KWChangeFootNoteLineSeparatorParametersCommand::execute()
 
1934
{
 
1935
    changeLineSeparatorParameter( m_newValuePos, m_newLength, m_newWidth,m_newLineType );
 
1936
}
 
1937
 
 
1938
void KWChangeFootNoteLineSeparatorParametersCommand::unexecute()
 
1939
{
 
1940
    changeLineSeparatorParameter( m_oldValuePos, m_oldLength, m_oldWidth, m_oldLineType);
 
1941
}
 
1942
 
 
1943
void KWChangeFootNoteLineSeparatorParametersCommand::changeLineSeparatorParameter( SeparatorLinePos _pos, int _length, double _width, SeparatorLineLineType _type)
 
1944
{
 
1945
    m_doc->setFootNoteSeparatorLinePosition( _pos );
 
1946
    m_doc->setFootNoteSeparatorLineLength( _length);
 
1947
    m_doc->setFootNoteSeparatorLineWidth(_width );
 
1948
    m_doc->setFootNoteSeparatorLineType( _type );
 
1949
    m_doc->repaintAllViews();
 
1950
}
 
1951
 
 
1952
 
 
1953
KWRenameBookmarkCommand::KWRenameBookmarkCommand( const QString &name, const QString & _oldname, const QString & _newName, KWDocument *_doc):
 
1954
    KNamedCommand(name),
 
1955
    m_doc( _doc ),
 
1956
    m_oldName( _oldname),
 
1957
    m_newName( _newName)
 
1958
{
 
1959
}
 
1960
 
 
1961
void KWRenameBookmarkCommand::execute()
 
1962
{
 
1963
    m_doc->renameBookMark( m_oldName, m_newName);
 
1964
}
 
1965
 
 
1966
void KWRenameBookmarkCommand::unexecute()
 
1967
{
 
1968
    m_doc->renameBookMark( m_newName, m_oldName);
 
1969
}