kword

KWCommand.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001 David Faure <faure@kde.org>
3 Copyright (C) 2005 Thomas Zander <zander@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "KWCommand.h"
22#include "KWDocument.h"
23#include "KWTextFrameSet.h"
24#include "KWTableStyle.h"
25#include "KWTableTemplate.h"
26#include "KWTableFrameSet.h"
27#include "KWPartFrameSet.h"
28#include "KWTextDocument.h"
29#include "KWTextParag.h"
30#include "KWAnchor.h"
31#include "KWVariable.h"
32#include "KWOasisLoader.h"
33#include "KWFrameList.h"
34#include "KWFrameSet.h"
35#include "KWPictureFrameSet.h"
36#include "KWPageManager.h"
37#include "KWPage.h"
38
39#include <KoTextObject.h>
40#include <KoOasisStyles.h>
41#include <KoOasisContext.h>
42#include <KoXmlNS.h>
43#include <KoDom.h>
44#include <KoStore.h>
45#include <KoOasisStore.h>
46
47#include <tdelocale.h>
48#include <kdebug.h>
49
50#include <tqxml.h>
51#include <tqbuffer.h>
52#include <algorithm>
53
54// Helper class for deleting all custom items
55// (KWTextFrameset::removeSelectedText and readFormats do that already,
56// but with undo/redo, and copying all formatting etc.)
57class KWDeleteCustomItemVisitor : public KoParagVisitor // see kotextdocument.h
58{
59public:
60 KWDeleteCustomItemVisitor() : KoParagVisitor() { }
61 virtual bool visit( KoTextParag *parag, int start, int end )
62 {
63 kdDebug(32001) << "KWPasteTextCommand::execute " << parag->paragId() << " " << start << " " << end << endl;
64 for ( int i = start ; i < end ; ++i )
65 {
66 KoTextStringChar * ch = parag->at( i );
67 if ( ch->isCustom() ) {
68 KoTextCustomItem* item = ch->customItem();
69 item->setDeleted( true );
70 parag->removeCustomItem(i);
71 KCommand* itemCmd = item->deleteCommand();
72 if ( itemCmd )
73 itemCmd->execute();
74 }
75 }
76 return true;
77 }
78};
79
80#if 0 // kept for comparison with KWOasisPasteCommand
81KWPasteTextCommand::KWPasteTextCommand( KoTextDocument *d, int parag, int idx,
82 const TQCString & data )
83 : KoTextDocCommand( d ), m_parag( parag ), m_idx( idx ), m_data( data ), m_oldParagLayout( 0 )
84{
85}
86
87KoTextCursor * KWPasteTextCommand::execute( KoTextCursor *c )
88{
89 KoTextParag *firstParag = doc->paragAt( m_parag );
90 if ( !firstParag ) {
91 tqWarning( "can't locate parag at %d, last parag: %d", m_parag, doc->lastParag()->paragId() );
92 return 0;
93 }
94 //kdDebug() << "KWPasteTextCommand::execute m_parag=" << m_parag << " m_idx=" << m_idx
95 // << " firstParag=" << firstParag << " " << firstParag->paragId() << endl;
96 cursor.setParag( firstParag );
97 cursor.setIndex( m_idx );
98 c->setParag( firstParag );
99 c->setIndex( m_idx );
100 TQDomDocument domDoc;
101 domDoc.setContent( m_data );
102 TQDomElement elem = domDoc.documentElement();
103 KWTextDocument * textdoc = static_cast<KWTextDocument *>(doc);
104 KWTextFrameSet * textFs = textdoc->textFrameSet();
105 // We iterate twice over the list of paragraphs.
106 // First time to gather the text,
107 // second time to apply the character & paragraph formatting
108 TQString text;
109
110 TQValueList<TQDomElement> listParagraphs;
111 TQDomElement paragraph = elem.firstChild().toElement();
112 for ( ; !paragraph.isNull() ; paragraph = paragraph.nextSibling().toElement() )
113 {
114 if ( paragraph.tagName() == "PARAGRAPH" )
115 {
116 TQString s = paragraph.namedItem( "TEXT" ).toElement().text();
117 //kdDebug() << "KWPasteTextCommand::execute Inserting text: '" << s << "'" << endl;
118 c->insert( s, false /*newline=linebreak, not new parag*/ );
119
120 if ( !paragraph.nextSibling().isNull() ) // Not for last parag
121 {
122 // Create new parag
123 // Lowlevel method:
124 c->splitAndInsertEmptyParag( false, true );
125 // Highlevel method:
126 //c->insert( "\n", true );
127 }
128 listParagraphs.append( paragraph );
129 }
130 }
131
132 // Redo the parag lookup because if firstParag was empty, insert() has
133 // shifted it down (side effect of splitAndInsertEmptyParag)
134 firstParag = doc->paragAt( m_parag );
135 KWTextParag * parag = static_cast<KWTextParag *>(firstParag);
136 //kdDebug() << "KWPasteTextCommand::execute starting at parag " << parag << " " << parag->paragId() << endl;
137 uint count = listParagraphs.count();
138 TQValueList<TQDomElement>::Iterator it = listParagraphs.begin();
139 TQValueList<TQDomElement>::Iterator end = listParagraphs.end();
140 for ( uint item = 0 ; it != end ; ++it, ++item )
141 {
142 if (!parag)
143 {
144 kdWarning() << "KWPasteTextCommand: parag==0L ! KWord bug, please report." << endl;
145 break;
146 }
147 TQDomElement paragElem = *it;
148 // First line (if appending to non-empty line) : apply offset to formatting, don't apply parag layout
149 if ( item == 0 && m_idx > 0 )
150 {
151 // First load the default format, but only apply it to our new chars
152 TQDomElement layout = paragElem.namedItem( "LAYOUT" ).toElement();
153 if ( !layout.isNull() )
154 {
155 TQDomElement formatElem = layout.namedItem( "FORMAT" ).toElement();
156 if ( !formatElem.isNull() )
157 {
158 KoTextFormat f = parag->loadFormat( formatElem, 0L, TQFont(), TDEGlobal::locale()->language(),false );
159 KoTextFormat * defaultFormat = doc->formatCollection()->format( &f );
160 // Last paragraph (i.e. only one in all) : some of the text might be from before the paste
161 int endIndex = (item == count-1) ? c->index() : parag->string()->length() - 1;
162 parag->setFormat( m_idx, endIndex - m_idx, defaultFormat, true );
163 }
164 }
165
166 parag->loadFormatting( paragElem, m_idx, (textFs->isMainFrameset()));
167 }
168 else
169 {
170 if ( item == 0 ) // This paragraph existed, store its parag layout
171 {
172 delete m_oldParagLayout;
173 m_oldParagLayout = new KoParagLayout( parag->paragLayout() );
174 }
175 parag->loadLayout( paragElem );
176 // Last paragraph: some of the text might be from before the paste
177 int len = (item == count-1) ? c->index() : parag->string()->length();
178 // Apply default format
179 parag->setFormat( 0, len, parag->paragFormat(), true );
180 parag->loadFormatting( paragElem, 0, (textFs->isMainFrameset()) );
181 }
182 parag->invalidate(0); // the formatting will be done by caller (either KWTextFrameSet::pasteOasis or KoTextObject::undo/redo)
183 parag->setChanged( true );
184 parag = static_cast<KWTextParag *>(parag->next());
185 //kdDebug() << "KWPasteTextCommand::execute going to next parag: " << parag << endl;
186 }
187 textFs->textObject()->setNeedSpellCheck( true );
188 // In case loadFormatting queued any image request
189 KWDocument * doc = textFs->kWordDocument();
190 doc->processPictureRequests();
191
192 //kdDebug() << "KWPasteTextCommand::execute calling doc->pasteFrames" << endl;
193 // In case of any inline frameset
194 doc->pasteFrames( elem, 0,
195 true /*don't change footnote attribute*/ ,
196 (textFs->isMainFrameset()) /*load footnotes if mainframeset*/,
197 false /*don't select frames*/ );
198 doc->completePasting();
199
200 m_lastParag = c->parag()->paragId();
201 m_lastIndex = c->index();
202 return c;
203}
204
205KoTextCursor * KWPasteTextCommand::unexecute( KoTextCursor *c )
206{
207 KoTextParag *firstParag = doc->paragAt( m_parag );
208 if ( !firstParag ) {
209 tqWarning( "can't locate parag at %d, last parag: %d", m_parag, doc->lastParag()->paragId() );
210 return 0;
211 }
212 cursor.setParag( firstParag );
213 cursor.setIndex( m_idx );
214 doc->setSelectionStart( KoTextDocument::Temp, &cursor );
215
216 KoTextParag *lastParag = doc->paragAt( m_lastParag );
217 if ( !lastParag ) {
218 tqWarning( "can't locate parag at %d, last parag: %d", m_lastParag, doc->lastParag()->paragId() );
219 return 0;
220 }
221 Q_ASSERT( lastParag->document() );
222 KWTextDocument * textdoc = static_cast<KWTextDocument *>(doc);
223
224 //kdDebug() << "Undoing paste: deleting from (" << firstParag->paragId() << "," << m_idx << ")"
225 // << " to (" << lastParag->paragId() << "," << m_lastIndex << ")" << endl;
226
227 cursor.setParag( lastParag );
228 cursor.setIndex( m_lastIndex );
229 doc->setSelectionEnd( KoTextDocument::Temp, &cursor );
230 // Delete all custom items
231 KWDeleteCustomItemVisitor visitor;
232 doc->visitSelection( KoTextDocument::Temp, &visitor );
233
234 doc->removeSelectedText( KoTextDocument::Temp, c /* sets c to the correct position */ );
235
236 KWTextFrameSet * textFs = textdoc->textFrameSet();
237
238 textFs->renumberFootNotes();
239 if ( m_idx == 0 ) {
240 Q_ASSERT( m_oldParagLayout );
241 if ( m_oldParagLayout )
242 firstParag->setParagLayout( *m_oldParagLayout );
243 }
244 return c;
245}
246#endif
247
248KWOasisPasteCommand::KWOasisPasteCommand( KoTextDocument *d, int parag, int idx,
249 const TQByteArray& data )
250 : KoTextDocCommand( d ), m_parag( parag ), m_idx( idx ), m_data( data ), m_oldParagLayout( 0 )
251{
252}
253
254KoTextCursor * KWOasisPasteCommand::execute( KoTextCursor *c )
255{
256 KoTextParag *firstParag = doc->paragAt( m_parag );
257 if ( !firstParag ) {
258 tqWarning( "can't locate parag at %d, last parag: %d", m_parag, doc->lastParag()->paragId() );
259 return c;
260 }
261 //kdDebug() << "KWOasisPasteCommand::execute m_parag=" << m_parag << " m_idx=" << m_idx
262 // << " firstParag=" << firstParag << " " << firstParag->paragId() << endl;
263 cursor.setParag( firstParag );
264 cursor.setIndex( m_idx );
265 c->setParag( firstParag );
266 c->setIndex( m_idx );
267
268 KWTextDocument * textdoc = static_cast<KWTextDocument *>(doc);
269
270 TQBuffer buffer( m_data );
271
272 KoStore * store = KoStore::createStore( &buffer, KoStore::Read );
273 KWDocument* kwdoc = textdoc->textFrameSet()->kWordDocument();
274 KWOasisLoader loader( kwdoc );
275 loader.insertOasisData( store, c );
276
277 delete store;
278
279 m_lastParag = c->parag()->paragId();
280 m_lastIndex = c->index();
281 return c;
282}
283
284KoTextCursor * KWOasisPasteCommand::unexecute( KoTextCursor *c )
285{
286 KoTextParag *firstParag = doc->paragAt( m_parag );
287 if ( !firstParag ) {
288 tqWarning( "can't locate parag at %d, last parag: %d", m_parag, doc->lastParag()->paragId() );
289 return 0;
290 }
291 cursor.setParag( firstParag );
292 cursor.setIndex( m_idx );
293 doc->setSelectionStart( KoTextDocument::Temp, &cursor );
294
295 KoTextParag *lastParag = doc->paragAt( m_lastParag );
296 if ( !lastParag ) {
297 tqWarning( "can't locate parag at %d, last parag: %d", m_lastParag, doc->lastParag()->paragId() );
298 return 0;
299 }
300 Q_ASSERT( lastParag->document() );
301 // Get hold of the document before deleting the parag
302 KWTextDocument * textdoc = static_cast<KWTextDocument *>(doc);
303
304 //kdDebug() << "Undoing paste: deleting from (" << firstParag->paragId() << "," << m_idx << ")"
305 // << " to (" << lastParag->paragId() << "," << m_lastIndex << ")" << endl;
306
307 cursor.setParag( lastParag );
308 cursor.setIndex( m_lastIndex );
309 doc->setSelectionEnd( KoTextDocument::Temp, &cursor );
310 // Delete all custom items
311 KWDeleteCustomItemVisitor visitor;
312 doc->visitSelection( KoTextDocument::Temp, &visitor );
313
314 doc->removeSelectedText( KoTextDocument::Temp, c /* sets c to the correct position */ );
315
316 KWTextFrameSet * textFs = textdoc->textFrameSet();
317
318 textFs->renumberFootNotes();
319#if 0
320 if ( m_idx == 0 ) {
321 Q_ASSERT( m_oldParagLayout );
322 if ( m_oldParagLayout )
323 firstParag->setParagLayout( *m_oldParagLayout );
324 }
325#endif
326 return c;
327}
328
329
330KWTextDeleteCommand::KWTextDeleteCommand( KoTextDocument *d, int i, int idx, const TQMemArray<KoTextStringChar> &str,
331 const CustomItemsMap & customItemsMap,
332 const TQValueList<KoParagLayout> & oldParagLayouts )
333 :KoTextDeleteCommand(d, i, idx, str, customItemsMap, oldParagLayouts)
334{
335 //createBookmarkList();
336}
337
338void KWTextDeleteCommand::createBookmarkList()
339{
340#if 0
341 KoTextParag *s = doc ? doc->paragAt( id ) : parag;
342 if ( !s ) {
343 tqWarning( "can't locate parag at %d, last parag: %d", id, doc->lastParag()->paragId() );
344 return;
345 }
346
347 // Now restore the parag layouts (i.e. libkotext specific stuff)
348 TQValueList<KoParagLayout>::Iterator lit = m_oldParagLayouts.begin();
349 kdDebug(32500) << "KWTextDeleteCommand::createBookmarkList " << m_oldParagLayouts.count() << " parag layouts. First parag=" << s->paragId() << endl;
350 Q_ASSERT( id == s->paragId() );
351 KoTextParag *p = s;
352 while ( p ) {
353 if ( lit != m_oldParagLayouts.end() )
354 {
355 kdDebug(32500) << "KWTextDeleteCommand::unexecute find bookmark in parag " << p->paragId() << endl;
356 //p->setParagLayout( *lit );
357 }
358 else
359 break;
360 p = p->next();
361 ++lit;
362 }
363#endif
364}
365
366KoTextCursor *KWTextDeleteCommand::execute( KoTextCursor *c )
367{
368 return KoTextDeleteCommand::execute( c );
369}
370
371KoTextCursor *KWTextDeleteCommand::unexecute( KoTextCursor *c )
372{
373 return KoTextDeleteCommand::unexecute( c );
374}
375
377
378FrameIndex::FrameIndex( KWFrame *frame )
379{
380 m_pFrameSet=frame->frameSet();
381 m_iFrameIndex=m_pFrameSet->frameFromPtr(frame);
382}
383
384KWFrameBorderCommand::KWFrameBorderCommand( const TQString &name, TQPtrList<FrameIndex> &_listFrameIndex, TQPtrList<FrameBorderTypeStruct> &_frameTypeBorder,const KoBorder & _newBorder):
385 KNamedCommand(name),
386 m_indexFrame(_listFrameIndex),
387 m_oldBorderFrameType(_frameTypeBorder),
388 m_newBorder( _newBorder)
389{
390}
391
392KWFrameBorderCommand::~KWFrameBorderCommand()
393{
394 m_indexFrame.setAutoDelete( true);
395 m_oldBorderFrameType.setAutoDelete( true);
396}
397
398void KWFrameBorderCommand::execute()
399{
400 FrameIndex *tmp;
401 KWDocument *doc = 0L;
402 for ( tmp=m_indexFrame.first(); tmp != 0; tmp=m_indexFrame.next() )
403 {
404 KWFrameSet *frameSet =tmp->m_pFrameSet;
405 doc = frameSet->kWordDocument();
406 KWFrame *frame=frameSet->frame(tmp->m_iFrameIndex);
407 KWTableFrameSet::Cell *cell = dynamic_cast<KWTableFrameSet::Cell *>(frame->frameSet());
408 FrameBorderTypeStruct *tmpFrameStruct=m_oldBorderFrameType.at(m_indexFrame.find(tmp));
409
410 switch( tmpFrameStruct->m_EFrameType)
411 {
412 case KoBorder::LeftBorder:
413 if(cell) // is a table cell
414 cell->setLeftBorder(m_newBorder);
415 else
416 frame->setLeftBorder(m_newBorder);
417 break;
418 case KoBorder::RightBorder:
419 if(cell) // is a table cell
420 cell->setRightBorder(m_newBorder);
421 else
422 frame->setRightBorder(m_newBorder);
423 break;
424 case KoBorder::TopBorder:
425 if(cell) // is a table cell
426 cell->setTopBorder(m_newBorder);
427 else
428 frame->setTopBorder(m_newBorder);
429 break;
430 case KoBorder::BottomBorder:
431 if(cell) // is a table cell
432 cell->setBottomBorder(m_newBorder);
433 else
434 frame->setBottomBorder(m_newBorder);
435 break;
436 default:
437 break;
438 }
439
440 if (!cell) {
441 frame->frameBordersChanged();
442 //fixme frameBorderChanged for table cells here too ?
443 }
444 }
445
446
447 if ( doc )
448 {
449 doc->repaintAllViews();
450 }
451}
452
453void KWFrameBorderCommand::unexecute()
454{
455 FrameIndex *tmp;
456 KWDocument *doc = 0L;
457 for ( tmp=m_indexFrame.first(); tmp != 0; tmp=m_indexFrame.next() )
458 {
459 KWFrameSet *frameSet =tmp->m_pFrameSet;
460 doc = frameSet->kWordDocument();
461 KWFrame *frame=frameSet->frame(tmp->m_iFrameIndex);
462 KWTableFrameSet::Cell *cell = dynamic_cast<KWTableFrameSet::Cell *>(frame->frameSet());
463 FrameBorderTypeStruct *tmpFrameStruct=m_oldBorderFrameType.at(m_indexFrame.find(tmp));
464 switch(tmpFrameStruct->m_EFrameType)
465 {
466 case KoBorder::LeftBorder:
467 if(cell) // is a table cell
468 cell->setLeftBorder(tmpFrameStruct->m_OldBorder);
469 else
470 frame->setLeftBorder(tmpFrameStruct->m_OldBorder);
471 break;
472 case KoBorder::RightBorder:
473 if(cell) // is a table cell
474 cell->setRightBorder(tmpFrameStruct->m_OldBorder);
475 else
476 frame->setRightBorder(tmpFrameStruct->m_OldBorder);
477 break;
478 case KoBorder::TopBorder:
479 if(cell) // is a table cell
480 cell->setTopBorder(tmpFrameStruct->m_OldBorder);
481 else
482 frame->setTopBorder(tmpFrameStruct->m_OldBorder);
483 break;
484 case KoBorder::BottomBorder:
485 if(cell) // is a table cell
486 cell->setBottomBorder(tmpFrameStruct->m_OldBorder);
487 else
488 frame->setBottomBorder(tmpFrameStruct->m_OldBorder);
489 break;
490 default:
491 break;
492 }
493 if (!cell) {
494 frame->frameBordersChanged();
495 //fixme frameBorderChanged for table cells here too ?
496 }
497 }
498
499
500
501 if ( doc )
502 {
503 //update frames
504 doc->repaintAllViews();
505 }
506}
507
508KWFrameBackGroundColorCommand::KWFrameBackGroundColorCommand( const TQString &name, TQPtrList<FrameIndex> &_listFrameIndex, TQPtrList<TQBrush> &_oldBrush,const TQBrush & _newColor ):
509 KNamedCommand(name),
510 m_indexFrame(_listFrameIndex),
511 m_oldBackGroundColor(_oldBrush),
512 m_newColor( _newColor)
513{
514}
515
516KWFrameBackGroundColorCommand::~KWFrameBackGroundColorCommand()
517{
518 m_indexFrame.setAutoDelete(true);
519 m_oldBackGroundColor.setAutoDelete(true);
520}
521
522
523void KWFrameBackGroundColorCommand::execute()
524{
525 FrameIndex *tmp;
526 KWDocument * doc = 0L;
527 for ( tmp=m_indexFrame.first(); tmp != 0; tmp=m_indexFrame.next() )
528 {
529 KWFrameSet *frameSet =tmp->m_pFrameSet;
530 if ( frameSet && (frameSet->type() != FT_PICTURE) && (frameSet->type() != FT_PART))
531 {
532 doc = frameSet->kWordDocument();
533 KWFrame *frame=frameSet->frame(tmp->m_iFrameIndex);
534 frame->setBackgroundColor(m_newColor);
535 }
536 }
537 //update frame
538 if ( doc )
539 doc->repaintAllViews();
540}
541
542void KWFrameBackGroundColorCommand::unexecute()
543{
544 FrameIndex *tmp;
545 KWDocument * doc = 0L;
546 for ( tmp=m_indexFrame.first(); tmp != 0; tmp=m_indexFrame.next() )
547 {
548 KWFrameSet *frameSet =tmp->m_pFrameSet;
549 if ( frameSet && (frameSet->type() != FT_PICTURE) && (frameSet->type() != FT_PART) )
550 {
551 doc = frameSet->kWordDocument();
552 KWFrame *frame=frameSet->frame(tmp->m_iFrameIndex);
553 TQBrush *tmpFrameStruct=m_oldBackGroundColor.at(m_indexFrame.find(tmp));
554 frame->setBackgroundColor(*tmpFrameStruct);
555 }
556 }
557
558 //update frames
559 if ( doc )
560 doc->repaintAllViews();
561}
562
563KWFrameStyleCommand::KWFrameStyleCommand( const TQString &name, KWFrame *_frame, KWFrameStyle *_fs, bool _repaintViews ) :
564 KNamedCommand( name )
565{
566 m_frame = _frame;
567 m_fs = _fs;
568 repaintViews = _repaintViews;
569
570 m_oldValues = new KWFrameStyle( "Old", m_frame );
571}
572
573void KWFrameStyleCommand::execute()
574{
575 applyFrameStyle( m_fs);
576}
577
578void KWFrameStyleCommand::unexecute()
579{
580 applyFrameStyle( m_oldValues);
581}
582
583void KWFrameStyleCommand::applyFrameStyle( KWFrameStyle * _sty )
584{
585 if ( m_frame->frameSet() && (m_frame->frameSet()->type() != FT_PICTURE)&& (m_frame->frameSet()->type() != FT_PART))
586 m_frame->setBackgroundColor( _sty->backgroundColor() );
587 m_frame->setLeftBorder( _sty->leftBorder() );
588 m_frame->setRightBorder( _sty->rightBorder() );
589 m_frame->setTopBorder( _sty->topBorder() );
590 m_frame->setBottomBorder( _sty->bottomBorder() );
591
592 m_frame->frameBordersChanged();
593 if ( repaintViews )
594 m_frame->frameSet()->kWordDocument()->repaintAllViews();
595}
596
597
598KWTableStyleCommand::KWTableStyleCommand( const TQString &name, KWFrame *_frame, KWTableStyle *_ts, bool _repaintViews ) :
599 KNamedCommand( name )
600{
601 m_frame = _frame;
602 m_ts = _ts;
603 repaintViews = _repaintViews;
604
605 // No need for i18n because it will never be displayed.
606 m_fsc = new KWFrameStyleCommand( "Apply Framestyle to Frame", m_frame, m_ts->frameStyle(), repaintViews );
607 m_sc = 0L;
608}
609
610KWTableStyleCommand::~KWTableStyleCommand()
611{
612 delete m_fsc;
613 delete m_sc;
614}
615
616void KWTableStyleCommand::execute()
617{
618 if (m_fsc)
619 m_fsc->execute();
620
621 if ( (m_ts) && ( m_frame->frameSet()->type() == FT_TEXT ) && ( m_ts->paragraphStyle() ) )
622 {
623 KoTextObject *textObject = ((KWTextFrameSet*)m_frame->frameSet())->textObject();
624 textObject->textDocument()->selectAll( KoTextDocument::Temp );
625 m_sc = textObject->applyStyleCommand( 0L, m_ts->paragraphStyle(), KoTextDocument::Temp, KoParagLayout::All, KoTextFormat::Format, true, false );
626 textObject->textDocument()->removeSelection( KoTextDocument::Temp );
627 }
628
629 m_frame->frameBordersChanged();
630 if ( repaintViews )
631 m_frame->frameSet()->kWordDocument()->repaintAllViews();
632
633}
634
635void KWTableStyleCommand::unexecute()
636{
637 if (m_fsc)
638 m_fsc->unexecute();
639 if (m_sc)
640 m_sc->unexecute();
641
642 m_frame->frameBordersChanged();
643 if ( repaintViews )
644 m_frame->frameSet()->kWordDocument()->repaintAllViews();
645}
646
647KWTableTemplateCommand::KWTableTemplateCommand( const TQString &name, KWTableFrameSet *_table, KWTableTemplate *_tt ) :
648 KNamedCommand( name )
649{
650 m_table = _table;
651 m_tt = _tt;
652
653 // No need for i18n because it will never be displayed.
654 m_tableCommands = new KMacroCommand( "Apply Tablestyles to Table" );
655
656
657 KWTableStyle *cell = 0L;
658 unsigned int rows = m_table->getRows();
659 unsigned int cols = m_table->getColumns();
660
661 for ( unsigned int i = 0; i < rows; i++ )
662 {
663 for ( unsigned int j = 0; j < cols; j++ )
664 {
665 if ( (i==0) && (j==0) ) // TOP LEFT CORNER
666 cell = m_tt->pTopLeftCorner();
667 else
668 if ( (i==0) && ( j==(cols-1) ) ) // TOP RIGHT CORNER
669 cell = m_tt->pTopRightCorner();
670 else
671 if ( ( i==(rows-1) ) && (j==0) ) // BOTTOM LEFT CORNER
672 cell = m_tt->pBottomLeftCorner();
673 else
674 if ( ( i==(rows-1) ) && ( j==(cols-1) ) ) // BOTTOM RIGHT CORNER
675 cell = m_tt->pBottomRightCorner();
676 else
677 if ( ( i==0 ) && ( j>0 ) && ( j<(cols-1) ) ) // FIRST ROW
678 cell = m_tt->pFirstRow();
679 else
680 if ( ( j==0 ) && ( i>0 ) && ( i<(rows-1) ) ) // FIRST COL
681 cell = m_tt->pFirstCol();
682 else
683 if ( ( i==(rows-1) ) && ( j>0 ) && ( j<(cols-1) ) ) // LAST ROW
684 cell = m_tt->pLastRow();
685 else
686 if ( ( j==(cols-1) ) && ( i>0 ) && ( i<(rows-1) ) ) // LAST COL
687 cell = m_tt->pLastCol();
688 else
689 if ( (i>0) && (j>0) && (i<(rows-1)) && (j<(cols-1)) ) // BODY
690 cell = m_tt->pBodyCell();
691
692 m_tableCommands->addCommand( new KWTableStyleCommand( "Apply tablestyle to cell", m_table->cell(i,j)->frame(0),cell, false ) );
693 }
694 }
695}
696
697KWTableTemplateCommand::~KWTableTemplateCommand()
698{
699 delete m_tableCommands;
700}
701
702void KWTableTemplateCommand::execute()
703{
704 m_tableCommands->execute();
705 m_table->kWordDocument()->repaintAllViews();
706}
707
708void KWTableTemplateCommand::unexecute()
709{
710 m_tableCommands->unexecute();
711 m_table->kWordDocument()->repaintAllViews();
712}
713
714
715KWFrameResizeCommand::KWFrameResizeCommand(const TQString &name, const TQValueList<FrameIndex> &frameIndex, const TQValueList<FrameResizeStruct> &frameResize )
716 : KNamedCommand(name), m_indexFrame(frameIndex), m_frameResize(frameResize) {
717 Q_ASSERT(m_indexFrame.count() == m_frameResize.count());
718}
719KWFrameResizeCommand::KWFrameResizeCommand(const TQString &name, FrameIndex frameIndex, const FrameResizeStruct &frameResize )
720 : KNamedCommand(name) {
721 m_indexFrame.append(frameIndex);
722 m_frameResize.append(frameResize);
723}
724
725void KWFrameResizeCommand::execute()
726{
727 TQValueList<FrameResizeStruct>::Iterator resizeIter = m_frameResize.begin();
728 TQValueList<FrameIndex>::Iterator iter = m_indexFrame.begin();
729 for(; iter != m_indexFrame.end() && resizeIter != m_frameResize.end(); ++resizeIter, ++iter ) {
730 FrameIndex index = *iter;
731 FrameResizeStruct frs = *resizeIter;
732
733 KWFrameSet *frameSet = index.m_pFrameSet;
734 Q_ASSERT( frameSet );
735 KWFrame *frame = frameSet->frame(index.m_iFrameIndex);
736 Q_ASSERT( frame );
737 frame->setCoords(frs.newRect.left(),frs.newRect.top(),frs.newRect.right(),frs.newRect.bottom());
738 frame->setMinimumFrameHeight(frs.newMinHeight);
739 KWTableFrameSet *table = frameSet->groupmanager();
740 if (table) {
741 KWTableFrameSet::Cell *cell=dynamic_cast<KWTableFrameSet::Cell *>(frameSet);
742 if(cell) {
743 table->recalcCols(cell->firstColumn(), cell->firstRow());
744 table->recalcRows(cell->firstColumn(), cell->firstRow());
745 }
746 else {
747 table->recalcCols(0, 0);
748 table->recalcRows(0, 0);
749 }
750 }
751
752 KWDocument * doc = frameSet->kWordDocument();
753 if ( frameSet->frameSetInfo() != KWFrameSet::FI_BODY ) // header/footer/footnote
754 doc->recalcFrames();
755
756 //update frames
757 doc->frameChanged( frame );
758 }
759}
760
761void KWFrameResizeCommand::unexecute()
762{
763 TQValueList<FrameResizeStruct>::Iterator resizeIter = m_frameResize.begin();
764 TQValueList<FrameIndex>::Iterator iter = m_indexFrame.begin();
765 for(; iter != m_indexFrame.end() && resizeIter != m_frameResize.end(); ++resizeIter, ++iter ) {
766 FrameIndex index = *iter;
767 FrameResizeStruct frs = *resizeIter;
768 KWFrameSet *frameSet =index.m_pFrameSet;
769 Q_ASSERT( frameSet );
770 KWFrame *frame=frameSet->frame(index.m_iFrameIndex);
771 Q_ASSERT( frame );
772 frame->setCoords(frs.oldRect.left(),frs.oldRect.top(),frs.oldRect.right(),frs.oldRect.bottom());
773 frame->setMinimumFrameHeight(frs.oldMinHeight);
774 KWTableFrameSet *table = frameSet->groupmanager();
775 if (table) {
776 KWTableFrameSet::Cell *cell=dynamic_cast<KWTableFrameSet::Cell *>(frameSet);
777 if(cell) {
778 table->recalcCols(cell->firstColumn(), cell->firstRow());
779 table->recalcRows(cell->firstColumn(), cell->firstRow());
780 }
781 else {
782 table->recalcCols(0, 0);
783 table->recalcRows(0, 0);
784 }
785 }
786 KWDocument * doc = frameSet->kWordDocument();
787 if ( frameSet->frameSetInfo() != KWFrameSet::FI_BODY ) // header/footer/footnote
788 doc->recalcFrames();
789
790 frame->updateRulerHandles();
791
792 //update frames
793 doc->frameChanged( frame );
794 }
795}
796
797KWFrameChangePictureCommand::KWFrameChangePictureCommand( const TQString &name, FrameIndex _frameIndex, const KoPictureKey & _oldKey, const KoPictureKey & _newKey ) :
798 KNamedCommand(name),
799 m_indexFrame(_frameIndex),
800 m_oldKey(_oldKey),
801 m_newKey(_newKey)
802{
803}
804
805void KWFrameChangePictureCommand::execute()
806{
807 KWFrameSet *frameSet = m_indexFrame.m_pFrameSet;
808 Q_ASSERT( frameSet );
809 KWFrame *frame = frameSet->frame(m_indexFrame.m_iFrameIndex);
810 Q_ASSERT( frame );
811 KWDocument * doc = frameSet->kWordDocument();
812 KWPictureFrameSet *frameset = static_cast<KWPictureFrameSet *>(frame->frameSet());
813 frameset->reloadPicture( m_newKey );
814 frameSet->kWordDocument()->refreshDocStructure( frameSet->type() );
815 doc->frameChanged( frame );
816}
817
818void KWFrameChangePictureCommand::unexecute()
819{
820 KWFrameSet *frameSet =m_indexFrame.m_pFrameSet;
821 KWFrame *frame=frameSet->frame(m_indexFrame.m_iFrameIndex);
822 KWDocument * doc = frameSet->kWordDocument();
823 KWPictureFrameSet *frameset = static_cast<KWPictureFrameSet *>(frame->frameSet());
824 frameset->reloadPicture( m_oldKey );
825 frameSet->kWordDocument()->refreshDocStructure( frameSet->type() );
826 doc->frameChanged( frame );
827}
828
829
830KWFramePartMoveCommand::KWFramePartMoveCommand( const TQString &name, FrameIndex _frameIndex, FrameResizeStruct _frameMove ) :
831 KNamedCommand(name),
832 m_indexFrame(_frameIndex),
833 m_frameMove(_frameMove)
834{
835}
836
837void KWFramePartMoveCommand::execute()
838{
839 KWFrameSet *frameSet = m_indexFrame.m_pFrameSet;
840 Q_ASSERT( frameSet );
841 KWFrame *frame = frameSet->frame(m_indexFrame.m_iFrameIndex);
842 Q_ASSERT( frame );
843 frame->setCoords(m_frameMove.newRect.left(),m_frameMove.newRect.top(),m_frameMove.newRect.right(),m_frameMove.newRect.bottom());
844
845 KWDocument * doc = frameSet->kWordDocument();
846
847 frame->updateRulerHandles();
848 doc->frameChanged( frame );
849}
850
851void KWFramePartMoveCommand::unexecute()
852{
853 KWFrameSet *frameSet =m_indexFrame.m_pFrameSet;
854 KWFrame *frame=frameSet->frame(m_indexFrame.m_iFrameIndex);
855 frame->setCoords(m_frameMove.oldRect.left(),m_frameMove.oldRect.top(),m_frameMove.oldRect.right(),m_frameMove.oldRect.bottom());
856
857 KWDocument * doc = frameSet->kWordDocument();
858 frame->updateRulerHandles();
859
860 //update frames
861 doc->frameChanged( frame );
862}
863
864bool KWFramePartMoveCommand::frameMoved()
865{
866 return (m_frameMove.oldRect!=m_frameMove.newRect);
867}
868
869KWFramePartInternalCommand::KWFramePartInternalCommand( const TQString &name, KWPartFrameSet *part ) :
870 KNamedCommand(name),
871 m_part(part)
872{
873 m_url = m_part->getChild()->document()->url();
874}
875
876void KWFramePartInternalCommand::execute()
877{
878 m_part->getChild()->document()->setStoreInternal(true);
879}
880
881void KWFramePartInternalCommand::unexecute()
882{
883 m_part->getChild()->document()->setStoreInternal(false);
884 m_part->getChild()->document()->setURL( m_url );
885}
886
887
888KWFramePartExternalCommand::KWFramePartExternalCommand( const TQString &name, KWPartFrameSet *part ) :
889 KNamedCommand(name),
890 m_part(part)
891{
892}
893
894void KWFramePartExternalCommand::execute()
895{
896 m_part->getChild()->document()->setStoreInternal(false);
897}
898
899void KWFramePartExternalCommand::unexecute()
900{
901 m_part->getChild()->document()->setStoreInternal(true);
902}
903
904
905KWFrameMoveCommand::KWFrameMoveCommand( const TQString &name,
906 const TQValueList<FrameIndex> & _frameIndex,
907 const TQValueList<FrameMoveStruct> & _frameMove ) :
908 KNamedCommand(name),
909 m_indexFrame(_frameIndex),
910 m_frameMove(_frameMove)
911{
912}
913
914void KWFrameMoveCommand::execute()
915{
916 bool needRelayout = false;
917 KWDocument * doc = 0L;
918 TQValueList<FrameMoveStruct>::Iterator moveIt = m_frameMove.begin();
919 TQValueList<FrameIndex>::Iterator tmp = m_indexFrame.begin();
920 for( ; tmp != m_indexFrame.end() && moveIt != m_frameMove.end(); ++tmp, ++moveIt )
921 {
922 KWFrameSet *frameSet = (*tmp).m_pFrameSet;
923 doc = frameSet->kWordDocument();
924 KWFrame *frame = frameSet->frame((*tmp).m_iFrameIndex);
925 frame->moveTopLeft( (*moveIt).newPos );
926
927 frame->updateRulerHandles();
928 needRelayout = needRelayout || ( frame->runAround() != KWFrame::RA_NO );
929 }
930 if ( doc )
931 {
932 doc->updateAllFrames();
933 if ( needRelayout )
934 doc->layout();
935
936 doc->updateRulerFrameStartEnd();
937 doc->repaintAllViews();
938 }
939}
940
941void KWFrameMoveCommand::unexecute()
942{
943 bool needRelayout = false;
944 KWDocument * doc = 0L;
945 TQValueList<FrameMoveStruct>::Iterator moveIt = m_frameMove.begin();
946 TQValueList<FrameIndex>::Iterator tmp = m_indexFrame.begin();
947 for( ; tmp != m_indexFrame.end() && moveIt != m_frameMove.end(); ++tmp, ++moveIt )
948 {
949 KWFrameSet *frameSet = (*tmp).m_pFrameSet;
950 doc = frameSet->kWordDocument();
951 KWFrame *frame = frameSet->frame((*tmp).m_iFrameIndex);
952 frame->moveTopLeft( (*moveIt).oldPos );
953
954 frame->updateRulerHandles();
955 needRelayout = needRelayout || ( frame->runAround() != KWFrame::RA_NO );
956 }
957
958 if ( doc )
959 {
960 doc->updateAllFrames();
961 if ( needRelayout )
962 doc->layout();
963 doc->updateRulerFrameStartEnd();
964 doc->repaintAllViews();
965 }
966}
967
968KWFramePropertiesCommand::KWFramePropertiesCommand( const TQString &name, KWFrame *_frameBefore, KWFrame *_frameAfter ) :
969 KNamedCommand(name),
970 m_frameIndex( _frameAfter ),
971 m_frameBefore(_frameBefore),
972 m_frameAfter(_frameAfter->getCopy())
973{
974}
975
976KWFramePropertiesCommand::~KWFramePropertiesCommand()
977{
978 delete m_frameBefore;
979 delete m_frameAfter;
980}
981
982void KWFramePropertiesCommand::execute()
983{
984 kdDebug(32001) << "KWFrameChangeParamCommand::execute" << endl;
985 KWFrameSet *frameSet = m_frameIndex.m_pFrameSet;
986 Q_ASSERT( frameSet );
987
988 KWFrame *frame = frameSet->frame( m_frameIndex.m_iFrameIndex );
989 Q_ASSERT( frame );
990 frame->copySettings(m_frameAfter);
991 frame->frameStack()->update();
992
993 KWDocument * doc = frameSet->kWordDocument();
994 if(doc)
995 {
996 doc->frameChanged( frame );
997 doc->updateAllFrames();
998 doc->layout();
999 doc->repaintAllViews();
1000 doc->updateRulerFrameStartEnd();
1001 }
1002}
1003
1004void KWFramePropertiesCommand::unexecute()
1005{
1006 kdDebug(32001) << "KWFrameChangeParamCommand::unexecute" << endl;
1007 KWFrameSet *frameSet = m_frameIndex.m_pFrameSet;
1008 Q_ASSERT( frameSet );
1009
1010 KWFrame *frame = frameSet->frame( m_frameIndex.m_iFrameIndex );
1011 Q_ASSERT( frame );
1012 frame->copySettings(m_frameBefore);
1013 frame->frameStack()->update();
1014 KWDocument * doc = frameSet->kWordDocument();
1015 if(doc)
1016 {
1017 doc->frameChanged( frame );
1018 doc->updateAllFrames();
1019 doc->layout();
1020 doc->repaintAllViews();
1021 doc->updateRulerFrameStartEnd();
1022 }
1023}
1024
1025
1026KWFrameSetInlineCommand::KWFrameSetInlineCommand( const TQString &name, KWFrameSet *frameset, bool value ) :
1027 KNamedCommand(name),
1028 m_pFrameSet( frameset ),
1029 m_value( value )
1030{
1031 m_oldValue = m_pFrameSet->isFloating();
1032}
1033
1034void KWFrameSetInlineCommand::setValue( bool value )
1035{
1036 kdDebug(32001) << "KWFrameSetInlineCommand::execute" << endl;
1037 if ( value )
1038 {
1039 // Make frame(set) floating
1040 m_pFrameSet->setFloating();
1041 // ## We might want to store a list of anchors in the command, and reuse them
1042 // in execute/unexecute. Currently setFixed forgets the anchors and setFloating recreates new ones...
1043 }
1044 else
1045 {
1046 // Make frame(set) non-floating
1047 m_pFrameSet->setFixed();
1048 }
1049
1050 m_pFrameSet->kWordDocument()->updateAllFrames();
1051}
1052
1053void KWFrameSetInlineCommand::execute()
1054{
1055 setValue( m_value );
1056}
1057
1058void KWFrameSetInlineCommand::unexecute()
1059{
1060 setValue( m_oldValue );
1061}
1062
1063KWPageLayoutCommand::KWPageLayoutCommand( const TQString &name,KWDocument *_doc,KWPageLayoutStruct &_oldLayout, KWPageLayoutStruct &_newLayout ) :
1064 KNamedCommand(name),
1065 m_pDoc(_doc),
1066 m_oldLayout(_oldLayout),
1067 m_newLayout(_newLayout)
1068{
1069}
1070
1071void KWPageLayoutCommand::execute()
1072{
1073 m_pDoc->setPageLayout( m_newLayout._pgLayout, m_newLayout._cl, m_newLayout._hf );
1074}
1075
1076void KWPageLayoutCommand::unexecute()
1077{
1078 m_pDoc->setPageLayout( m_oldLayout._pgLayout, m_oldLayout._cl, m_oldLayout._hf);
1079}
1080
1081
1082KWDeleteFrameCommand::KWDeleteFrameCommand( const TQString &name, KWFrame * frame ):
1083 KNamedCommand(name),
1084 m_frameIndex( frame ),
1085 m_copyFrame( frame->getCopy() )
1086{
1087}
1088
1089KWDeleteFrameCommand::KWDeleteFrameCommand( const FrameIndex &frameIndex) :
1090 KNamedCommand("")
1091{
1092 m_frameIndex = frameIndex;
1093 m_copyFrame = m_frameIndex.m_pFrameSet->frame(m_frameIndex.m_iFrameIndex)->getCopy();
1094}
1095
1096KWDeleteFrameCommand::~KWDeleteFrameCommand()
1097{
1098 delete m_copyFrame;
1099}
1100
1101
1102void KWDeleteFrameCommand::execute()
1103{
1104 KWFrameSet *frameSet = m_frameIndex.m_pFrameSet;
1105 Q_ASSERT( frameSet );
1106
1107 KWFrame *frame = frameSet->frame( m_frameIndex.m_iFrameIndex );
1108 Q_ASSERT( frame );
1109
1110kdDebug() << "delete frame " << m_frameIndex.m_iFrameIndex << " of " << frameSet->name() << endl;
1111 KWDocument* doc = frameSet->kWordDocument();
1112 doc->terminateEditing( frameSet );
1113 doc->frameChanged( frame );
1114 frameSet->deleteFrame( m_frameIndex.m_iFrameIndex );
1115
1116/* KWTextFrameSet * textfs = dynamic_cast<KWTextFrameSet *>(fs);
1117 if(textfs) { TODO
1118 // if content does not fit; change properties of previous frame to be 'do not show'
1119 }
1120*/
1121
1122 doc->refreshDocStructure( frameSet->type() );
1123 doc->updateTextFrameSetEdit();
1124}
1125
1126void KWDeleteFrameCommand::unexecute()
1127{
1128 KWFrameSet *frameSet = m_frameIndex.m_pFrameSet;
1129 KWFrame * frame = m_copyFrame->getCopy();
1130 frame->setFrameSet( frameSet );
1131 frameSet->addFrame( frame );
1132
1133 KWPartFrameSet * partfs = dynamic_cast<KWPartFrameSet *>( frameSet );
1134 if ( partfs )
1135 partfs->setDeleted( false );
1136
1137 KWTextFrameSet * textfs = dynamic_cast<KWTextFrameSet *>( frameSet );
1138 if ( textfs )
1139 textfs->textObject()->formatMore( 2 );
1140 KWDocument* doc = frameSet->kWordDocument();
1141 doc->frameChanged( frame );
1142 // could have been the last frame on a page, so undeleting it needs to recreate the page
1143 doc->recalcFrames( frame->pageNumber() );
1144 doc->refreshDocStructure(frameSet->type());
1145 doc->updateRulerFrameStartEnd();
1146}
1147
1148KWCreateFrameCommand::KWCreateFrameCommand( const TQString &name, KWFrame * frame ) :
1149 KWDeleteFrameCommand( name, frame )
1150{}
1151
1152
1153KWUngroupTableCommand::KWUngroupTableCommand( const TQString &name, KWTableFrameSet * _table ):
1154 KNamedCommand(name),
1155 m_pTable(_table)
1156{
1157 m_ListFrame.clear();
1158 for ( KWTableFrameSet::TableIter i(m_pTable); i ; ++i ) {
1159 m_ListFrame.append( i.current() );
1160 }
1161}
1162
1163void KWUngroupTableCommand::execute()
1164{
1165 KWDocument * doc = m_pTable->kWordDocument();
1166 for ( KWTableFrameSet::TableIter i(m_pTable) ; i ; ++i ) {
1167 i->setGroupManager( 0L );
1168 doc->addFrameSet( i.current() );
1169 }
1170 m_pTable->ungroup();
1171 doc->removeFrameSet(m_pTable);
1172
1173 //when you ungroup a table
1174 // you must remove table item in docstruct
1175 // create items in text item in docstruct
1176
1177 int refresh=0;
1178 refresh |=Tables;
1179 refresh |=TextFrames;
1180 doc->refreshDocStructure(refresh);
1181
1182 doc->updateAllFrames();
1183 doc->repaintAllViews();
1184}
1185
1186void KWUngroupTableCommand::unexecute()
1187{
1188 Q_ASSERT(m_pTable);
1189 m_pTable->group();
1190 KWDocument * doc = m_pTable->kWordDocument();
1191 KWFrameSet *tmp;
1192 for ( tmp=m_ListFrame.first(); tmp != 0; tmp=m_ListFrame.next() )
1193 {
1194 tmp->setGroupManager(m_pTable);
1195 doc->removeFrameSet(tmp);
1196 KWTableFrameSet::Cell *cell=static_cast<KWTableFrameSet::Cell *>(tmp);
1197 Q_ASSERT(cell);
1198 m_pTable->addCell( cell );
1199 }
1200 doc->addFrameSet(m_pTable);
1201
1202 int refresh=0;
1203 refresh |=Tables;
1204 refresh |=TextFrames;
1205 doc->refreshDocStructure(refresh);
1206
1207
1208 doc->updateAllFrames();
1209 doc->repaintAllViews();
1210}
1211
1212
1213KWDeleteTableCommand::KWDeleteTableCommand( const TQString &name, KWTableFrameSet * _table ):
1214 KNamedCommand(name),
1215 m_pTable(_table)
1216{
1217 Q_ASSERT(m_pTable);
1218}
1219
1220void KWDeleteTableCommand::execute()
1221{
1222 kdDebug(32001) << "KWDeleteTableCommand::execute" << endl;
1223 KWDocument * doc = m_pTable->kWordDocument();
1224 doc->removeFrameSet(m_pTable);
1225 m_pTable->setVisible( false );
1226 doc->refreshDocStructure((int)Tables);
1227 doc->updateAllFrames();
1228 m_pTable->updateFrames(); // not in the doc list anymore, so the above call didn't do it!
1229 doc->layout();
1230 doc->repaintAllViews();
1231 doc->updateRulerFrameStartEnd();
1232
1233}
1234
1235void KWDeleteTableCommand::unexecute()
1236{
1237 kdDebug(32001) << "KWDeleteTableCommand::unexecute" << endl;
1238 KWDocument * doc = m_pTable->kWordDocument();
1239 m_pTable->setVisible( true );
1240 doc->addFrameSet(m_pTable);
1241 doc->refreshDocStructure((int)Tables);
1242 doc->updateAllFrames();
1243 doc->layout();
1244 doc->repaintAllViews();
1245 doc->updateRulerFrameStartEnd();
1246}
1247
1248
1249KWInsertColumnCommand::KWInsertColumnCommand( const TQString &name, KWTableFrameSet * _table, int _col, double _maxRight ):
1250 KNamedCommand(name),
1251 m_pTable(_table),
1252 m_rc(new RemovedColumn()),
1253 m_colPos(_col),
1254 m_maxRight(_maxRight),
1255 m_oldWidth(0)
1256{
1257 Q_ASSERT(m_pTable);
1258}
1259
1260KWInsertColumnCommand::~KWInsertColumnCommand()
1261{
1262 delete m_rc;
1263}
1264
1265void KWInsertColumnCommand::execute()
1266{
1267 kdDebug(32001) << "KWInsertColumnCommand::execute" << endl;
1268 KWDocument * doc = m_pTable->kWordDocument();
1269 // a insert column = KWTableFrameSet::m_sDefaultColWidth, see kwtableframeset.cpp
1270 if (m_pTable->boundingRect().right() + KWTableFrameSet::m_sDefaultColWidth >= static_cast<int>(m_maxRight))
1271 { // must create space (resize the table)
1272 m_oldWidth = m_pTable->boundingRect().width();
1273 // here we calculate the new table size for a table that would take the
1274 // entire width of the page, which what the user wants 99% of the time.
1275 double newTableWidth =m_maxRight - m_pTable->boundingRect().left();
1276 double newColSize = newTableWidth / (m_pTable->getColumns()+1);
1277 double resizeTableWidth = m_maxRight - m_pTable->boundingRect().left();
1278 m_pTable->resizeWidth(resizeTableWidth - newColSize);
1279 m_pTable->insertNewColumn(m_colPos, newColSize);
1280 }
1281 else
1282 { // simply insert the column without asking for a specific size :
1283 m_pTable->insertNewColumn(m_colPos);
1284 }
1285 Q_ASSERT(m_pTable->boundingRect().right() <= m_maxRight);
1286 doc->updateAllFrames();
1287 doc->layout();
1288 doc->repaintAllViews();
1289}
1290
1291void KWInsertColumnCommand::unexecute()
1292{
1293 kdDebug(32001) << "KWInsertColumnCommand::unexecute" << endl;
1294 KWDocument * doc = m_pTable->kWordDocument();
1295 doc->terminateEditing(m_pTable);
1296 m_pTable->deleteColumn(m_colPos, *m_rc);
1297 // now undo the resize of the table if necessary:
1298 if (m_oldWidth) {
1299 // yes, the table was resized, let's undo that :
1300 m_pTable->resizeWidth(m_oldWidth);
1301 }
1302 doc->updateAllFrames();
1303 doc->layout();
1304 doc->repaintAllViews();
1305}
1306
1307
1308
1309KWInsertRowCommand::KWInsertRowCommand( const TQString &name, KWTableFrameSet * _table, int _row ):
1310 KNamedCommand(name),
1311 m_pTable(_table),
1312 m_rr(new RemovedRow()),
1313 m_rowPos(_row),
1314 m_inserted(false)
1315{
1316 Q_ASSERT(m_pTable);
1317}
1318
1319KWInsertRowCommand::~KWInsertRowCommand()
1320{
1321 delete m_rr;
1322}
1323
1324void KWInsertRowCommand::execute()
1325{
1326 kdDebug(32001) << "KWInsertRowCommand::execute" << endl;
1327 KWDocument * doc = m_pTable->kWordDocument();
1328 if(m_inserted)
1329 m_pTable->reInsertRow(*m_rr);
1330 else {
1331 m_inserted = true;
1332 m_pTable->insertNewRow(m_rowPos); //only happens the first time
1333 }
1334 doc->updateAllFrames();
1335 doc->layout();
1336 doc->repaintAllViews();
1337}
1338
1339void KWInsertRowCommand::unexecute()
1340{
1341 kdDebug(32001) << "KWInsertRowCommand::unexecute" << endl;
1342 KWDocument * doc = m_pTable->kWordDocument();
1343
1344 doc->terminateEditing(m_pTable);
1345 m_pTable->deleteRow( m_rowPos, *m_rr);
1346
1347 doc->updateAllFrames();
1348 doc->layout();
1349}
1350
1351
1352KWRemoveRowCommand::KWRemoveRowCommand( const TQString &name, KWTableFrameSet * _table, int _row ):
1353 KNamedCommand(name),
1354 m_pTable(_table),
1355 m_rr(new RemovedRow()),
1356 m_rowPos(_row)
1357{
1358 Q_ASSERT(m_pTable);
1359}
1360
1361KWRemoveRowCommand::~KWRemoveRowCommand()
1362{
1363 delete m_rr;
1364}
1365
1366void KWRemoveRowCommand::execute()
1367{
1368 kdDebug(32001) << "KWRemoveRowCommand::execute" << endl;
1369 KWDocument * doc = m_pTable->kWordDocument();
1370 doc->terminateEditing(m_pTable);
1371
1372 m_pTable->deleteRow( m_rowPos, *m_rr);
1373
1374 doc->updateAllFrames();
1375 doc->layout();
1376}
1377
1378void KWRemoveRowCommand::unexecute()
1379{
1380 kdDebug(32001) << "KWRemoveRowCommand::unexecute" << endl;
1381 KWDocument * doc = m_pTable->kWordDocument();
1382 m_pTable->reInsertRow(*m_rr);
1383 doc->updateAllFrames();
1384 doc->layout();
1385 doc->repaintAllViews();
1386}
1387
1388KWRemoveColumnCommand::KWRemoveColumnCommand( const TQString &name, KWTableFrameSet * _table, int _col ):
1389 KNamedCommand(name),
1390 m_pTable(_table),
1391 m_rc(new RemovedColumn()),
1392 m_colPos(_col)
1393{
1394 Q_ASSERT(m_pTable);
1395}
1396
1397KWRemoveColumnCommand::~KWRemoveColumnCommand()
1398{
1399 delete m_rc;
1400}
1401
1402void KWRemoveColumnCommand::execute()
1403{
1404 kdDebug(32001) << "KWRemoveColumnCommand::execute" << endl;
1405 KWDocument * doc = m_pTable->kWordDocument();
1406 doc->terminateEditing(m_pTable);
1407
1408 m_pTable->deleteColumn( m_colPos, *m_rc);
1409 doc->updateAllFrames();
1410 doc->layout();
1411}
1412
1413void KWRemoveColumnCommand::unexecute()
1414{
1415 kdDebug(32001) << "KWRemoveColumnCommand::unexecute" << endl;
1416 KWDocument * doc = m_pTable->kWordDocument();
1417 m_pTable->reInsertColumn(*m_rc);
1418 doc->updateAllFrames();
1419 doc->layout();
1420 doc->repaintAllViews();
1421}
1422
1423
1424
1425KWSplitCellCommand::KWSplitCellCommand( const TQString &name, KWTableFrameSet * _table,unsigned int colBegin,unsigned int rowBegin, unsigned int colEnd,unsigned int rowEnd ):
1426 KNamedCommand(name),
1427 m_pTable(_table),
1428 m_colBegin(colBegin),
1429 m_rowBegin(rowBegin),
1430 m_colEnd(colEnd),
1431 m_rowEnd(rowEnd)
1432{
1433 Q_ASSERT(m_pTable);
1434}
1435
1436void KWSplitCellCommand::execute()
1437{
1438 kdDebug(32001) << "KWSplitCellCommand::execute" << endl;
1439 KWDocument * doc = m_pTable->kWordDocument();
1440 doc->terminateEditing(m_pTable);
1441 //kdDebug()<<"split Cell m_colBegin :"<<m_colBegin<<" m_colEnd :"<<m_colEnd<<" m_rowBegin :"<<m_rowBegin<<" m_colEnd :"<<m_colEnd<<endl;
1442 m_pTable->splitCell(m_rowEnd, m_colEnd,m_colBegin,m_rowBegin,m_ListFrameSet);
1443 doc->updateAllFrames();
1444 doc->layout();
1445}
1446
1447void KWSplitCellCommand::unexecute()
1448{
1449 kdDebug(32001) << "KWSplitCellCommand::unexecute" << endl;
1450 KWDocument * doc = m_pTable->kWordDocument();
1451 doc->terminateEditing(m_pTable);
1452
1453 //kdDebug()<<"Join Cell m_colBegin :"<<m_colBegin<<" m_colEnd :"<<m_colBegin+m_colEnd-1<<" m_rowBegin :"<<m_rowBegin<<" m_rowEnd :"<<m_rowBegin+m_rowEnd-1<<endl;
1454
1455 if(m_ListFrameSet.isEmpty())
1456 {
1457 for ( unsigned int i = 0; i < m_pTable->getColumns(); i++ )
1458 {
1459 for ( unsigned int j = 0; j < m_pTable->getRows(); j++ )
1460 {
1461 if(j>=m_rowBegin && j<=(m_rowBegin+m_rowEnd-1)
1462 && i>=m_colBegin && i<=(m_colEnd+m_colBegin-1))
1463 {
1464 //don't store first cell
1465 if( !(j==m_rowBegin && i==m_colBegin))
1466 {
1467 kdDebug(32001)<<"store cell row :"<<j<<" col :"<<i<<endl;
1468 KWTableFrameSet::Cell *cell=static_cast<KWTableFrameSet::Cell *>(m_pTable->cell( j,i ));
1469 m_ListFrameSet.append(cell);
1470 }
1471 }
1472
1473 }
1474 }
1475 }
1476 KWTableFrameSet::Cell *cell=static_cast<KWTableFrameSet::Cell *>(m_pTable->cell( m_rowBegin,m_colBegin ));
1477 m_pTable->joinCells(m_colBegin, m_rowBegin, m_colEnd+m_colBegin-1+cell->columnSpan()-1,
1478 m_rowBegin+m_rowEnd-1+cell->rowSpan()-1);
1479
1480 doc->updateAllFrames();
1481 doc->layout();
1482}
1483
1484
1485
1486KWJoinCellCommand::KWJoinCellCommand( const TQString &name, KWTableFrameSet * _table,unsigned int colBegin,unsigned int rowBegin, unsigned int colEnd,unsigned int rowEnd, TQPtrList<KWFrameSet> listFrameSet,TQPtrList<KWFrame> listCopyFrame):
1487 KNamedCommand(name),
1488 m_pTable(_table),
1489 m_colBegin(colBegin),
1490 m_rowBegin(rowBegin),
1491 m_colEnd(colEnd),
1492 m_rowEnd(rowEnd),
1493 m_ListFrameSet(listFrameSet),
1494 m_copyFrame(listCopyFrame)
1495{
1496 Q_ASSERT(m_pTable);
1497}
1498KWJoinCellCommand::~KWJoinCellCommand()
1499{
1500 m_copyFrame.setAutoDelete( true );
1501}
1502
1503void KWJoinCellCommand::execute()
1504{
1505 kdDebug(32001) << "KWJoinCellCommand::execute" << endl;
1506 KWDocument * doc = m_pTable->kWordDocument();
1507 doc->terminateEditing(m_pTable);
1508 m_pTable->joinCells(m_colBegin,m_rowBegin,m_colEnd,m_rowEnd);
1509 doc->updateAllFrames();
1510 doc->layout();
1511}
1512
1513void KWJoinCellCommand::unexecute()
1514{
1515 kdDebug(32001) << "KWJoinCellCommand::unexecute" << endl;
1516 KWDocument * doc = m_pTable->kWordDocument();
1517 doc->terminateEditing(m_pTable);
1518 m_pTable->splitCell(m_rowEnd-m_rowBegin+1, m_colEnd-m_colBegin+1,m_colBegin,m_rowBegin,m_ListFrameSet,m_copyFrame);
1519 doc->updateAllFrames();
1520 doc->layout();
1521}
1522
1523
1524KWChangeStartingPageCommand::KWChangeStartingPageCommand( const TQString &name, KWDocument *_doc, int _oldStartingPage, int _newStartingPage):
1525 KNamedCommand(name),
1526 m_doc(_doc),
1527 oldStartingPage(_oldStartingPage),
1528 newStartingPage(_newStartingPage)
1529{
1530}
1531
1532void KWChangeStartingPageCommand::execute()
1533{
1534 m_doc->variableCollection()->variableSetting()->setStartingPageNumber(newStartingPage);
1535 m_doc->recalcVariables( VT_PGNUM );
1536}
1537
1538void KWChangeStartingPageCommand::unexecute()
1539{
1540 m_doc->variableCollection()->variableSetting()->setStartingPageNumber(oldStartingPage);
1541 m_doc->recalcVariables( VT_PGNUM );
1542}
1543
1544KWChangeVariableSettingsCommand::KWChangeVariableSettingsCommand( const TQString &name, KWDocument *_doc, bool _oldValue, bool _newValue, VariableProperties _type):
1545 KNamedCommand(name),
1546 m_doc(_doc),
1547 type(_type),
1548 m_bOldValue(_oldValue),
1549 m_bNewValue(_newValue)
1550{
1551}
1552
1553void KWChangeVariableSettingsCommand::changeValue( bool b )
1554{
1555 switch(type)
1556 {
1557 case VS_DISPLAYLINK:
1558 m_doc->variableCollection()->variableSetting()->setDisplayLink(b);
1559 m_doc->recalcVariables( VT_LINK );
1560 break;
1561 case VS_UNDERLINELINK:
1562 m_doc->variableCollection()->variableSetting()->setUnderlineLink(b);
1563 m_doc->recalcVariables( VT_LINK );
1564 break;
1565 case VS_DISPLAYCOMMENT:
1566 m_doc->variableCollection()->variableSetting()->setDisplayComment(b);
1567 m_doc->recalcVariables( VT_NOTE );
1568 break;
1569 case VS_DISPLAYFIELDCODE:
1570 m_doc->variableCollection()->variableSetting()->setDisplayFieldCode(b);
1571 //hack necessary otherwise footnote frameset is not refreshing
1572 //and footnote is not resize.
1573 m_doc->displayFootNoteFieldCode();
1574 m_doc->recalcVariables( VT_ALL );
1575 break;
1576 }
1577}
1578
1579void KWChangeVariableSettingsCommand::execute()
1580{
1581 changeValue(m_bNewValue);
1582}
1583
1584void KWChangeVariableSettingsCommand::unexecute()
1585{
1586 changeValue(m_bOldValue);
1587}
1588
1589KWChangeCustomVariableValue::KWChangeCustomVariableValue( const TQString &name, KWDocument *_doc,const TQString & _oldValue, const TQString & _newValue,KoCustomVariable *var):
1590 KNamedCommand(name),
1591 m_doc(_doc),
1592 newValue(_newValue),
1593 oldValue(_oldValue),
1594 m_var(var)
1595{
1596}
1597
1598KWChangeCustomVariableValue::~KWChangeCustomVariableValue()
1599{
1600}
1601
1602void KWChangeCustomVariableValue::execute()
1603{
1604 Q_ASSERT(m_var);
1605 m_var->setValue(newValue);
1606 m_doc->recalcVariables( VT_CUSTOM );
1607}
1608
1609void KWChangeCustomVariableValue::unexecute()
1610{
1611 Q_ASSERT(m_var);
1612 m_var->setValue(oldValue);
1613 m_doc->recalcVariables( VT_CUSTOM );
1614}
1615
1616KWChangeVariableNoteText::KWChangeVariableNoteText( const TQString &name, KWDocument *_doc,
1617 const TQString &_oldValue,const TQString &_newValue,
1618 KoNoteVariable *var):
1619 KNamedCommand(name),
1620 m_doc(_doc),
1621 newValue(_newValue),
1622 oldValue(_oldValue),
1623 m_var(var)
1624{
1625}
1626
1627KWChangeVariableNoteText::~KWChangeVariableNoteText()
1628{
1629}
1630
1631void KWChangeVariableNoteText::execute()
1632{
1633 Q_ASSERT(m_var);
1634 m_var->setNote(newValue);
1635}
1636
1637void KWChangeVariableNoteText::unexecute()
1638{
1639 Q_ASSERT(m_var);
1640 m_var->setNote(oldValue);
1641}
1642
1643// TODO: move to libkotext to remove code duplication with kpresenter
1644KWChangeLinkVariable::KWChangeLinkVariable( const TQString &name, KWDocument *_doc,const TQString & _oldHref, const TQString & _newHref, const TQString & _oldLink,const TQString &_newLink, KoLinkVariable *var):
1645 KNamedCommand(name),
1646 m_doc(_doc),
1647 oldHref(_oldHref),
1648 newHref(_newHref),
1649 oldLink(_oldLink),
1650 newLink(_newLink),
1651 m_var(var)
1652{
1653}
1654
1655
1656void KWChangeLinkVariable::execute()
1657{
1658 m_var->setLink(newLink,newHref);
1659 m_doc->recalcVariables(VT_LINK);
1660}
1661
1662void KWChangeLinkVariable::unexecute()
1663{
1664 m_var->setLink(oldLink,oldHref);
1665 m_doc->recalcVariables(VT_LINK);
1666}
1667
1668KWHideShowHeader::KWHideShowHeader( const TQString &name, KWDocument *_doc, bool _newValue):
1669 KNamedCommand(name),
1670 m_doc(_doc),
1671 newValue(_newValue)
1672{
1673}
1674
1675
1676void KWHideShowHeader::execute()
1677{
1678 m_doc->setHeaderVisible(newValue );
1679 m_doc->updateHeaderButton();
1680
1681}
1682
1683void KWHideShowHeader::unexecute()
1684{
1685 m_doc->setHeaderVisible(!newValue );
1686 m_doc->updateHeaderButton();
1687}
1688
1689KWHideShowFooter::KWHideShowFooter( const TQString &name, KWDocument *_doc, bool _newValue):
1690 KNamedCommand(name),
1691 m_doc(_doc),
1692 newValue(_newValue)
1693{
1694}
1695
1696
1697void KWHideShowFooter::execute()
1698{
1699 m_doc->setFooterVisible( newValue );
1700 m_doc->updateFooterButton();
1701}
1702
1703void KWHideShowFooter::unexecute()
1704{
1705 m_doc->setFooterVisible( !newValue );
1706 m_doc->updateFooterButton();
1707}
1708
1709
1710KWProtectContentCommand::KWProtectContentCommand( const TQString &name, KWTextFrameSet*frameset, bool _protect):
1711 KNamedCommand(name),
1712 m_pFrameSet(frameset),
1713 m_bProtect(_protect)
1714{
1715}
1716
1717
1718void KWProtectContentCommand::execute()
1719{
1720 m_pFrameSet->setProtectContent(m_bProtect);
1721 m_pFrameSet->kWordDocument()->updateTextFrameSetEdit();
1722 m_pFrameSet->kWordDocument()->testAndCloseAllFrameSetProtectedContent();
1723 m_pFrameSet->kWordDocument()->updateRulerInProtectContentMode();
1724
1725}
1726
1727void KWProtectContentCommand::unexecute()
1728{
1729 m_pFrameSet->setProtectContent(!m_bProtect);
1730 m_pFrameSet->kWordDocument()->updateTextFrameSetEdit();
1731 m_pFrameSet->kWordDocument()->testAndCloseAllFrameSetProtectedContent();
1732 m_pFrameSet->kWordDocument()->updateRulerInProtectContentMode();
1733
1734}
1735
1736KWInsertRemovePageCommand::KWInsertRemovePageCommand( KWDocument *_doc, Command cmd, int pgNum)
1737 : KCommand(), m_doc(_doc), m_cmd(cmd), m_pgNum(pgNum)
1738{}
1739
1740KWInsertRemovePageCommand::~KWInsertRemovePageCommand() {
1741 TQValueListIterator<KCommand*> cmdIter = childCommands.begin();
1742 for(;cmdIter != childCommands.end(); ++ cmdIter)
1743 delete (*cmdIter);
1744}
1745
1746TQString KWInsertRemovePageCommand::name() const
1747{
1748 return m_cmd == Insert ? i18n("Insert Page") // problem with after/before page
1749 : i18n("Delete Page %1").arg(m_pgNum);
1750}
1751
1752void KWInsertRemovePageCommand::execute() {
1753 if ( m_cmd == Insert )
1754 doInsert(m_pgNum);
1755 else
1756 doRemove(m_pgNum);
1757}
1758
1759void KWInsertRemovePageCommand::unexecute() {
1760 if ( m_cmd == Insert )
1761 // remove the page that was inserted
1762 doRemove(m_pgNum+1);
1763 else
1764 // Re-insert the page that was deleted
1765 doInsert(m_pgNum-1);
1766}
1767
1768void KWInsertRemovePageCommand::doRemove(int pageNumber) {
1769 bool firstRun = childCommands.count() == 0;
1770 if(firstRun) {
1771 TQValueVector<FrameIndex> indexes;
1772 TQPtrList<KWFrame> frames = m_doc->framesInPage(pageNumber, false);
1773 TQPtrListIterator<KWFrame> framesIter(frames);
1774 for(; framesIter.current(); ++framesIter)
1775 indexes.append(FrameIndex(*framesIter));
1776
1777 // we sort them to make sure frames are deleted in order and indexes are not going
1778 // to get mixed up when there is more then one frame of a frameset on the page
1779 std::sort(indexes.begin(), indexes.end(), compareIndex);
1780
1781 TQValueVector<FrameIndex>::iterator iter = indexes.begin();
1782 for(; iter != indexes.end(); ++iter)
1783 childCommands.append(new KWDeleteFrameCommand(*iter));
1784 }
1785 TQValueListIterator<KCommand*> cmdIter = childCommands.begin();
1786 for(;cmdIter != childCommands.end(); ++ cmdIter)
1787 (*cmdIter)->execute();
1788
1789 // next move all frames up that are on higher pagenumbers
1790 KWPage* page = m_doc->pageManager()->page(pageNumber);
1791 Q_ASSERT(page);
1792 if(! page) return; // hack to work around bug #125998
1793 const double pageHeight = page->height();
1794 const double topOfPage = m_doc->pageManager()->topOfPage(pageNumber);
1795 m_doc->pageManager()->removePage( pageNumber );
1796
1797 if(firstRun && m_doc->lastPage() >= pageNumber) { // only walk frames when there was a page
1798 // after the deleted one
1799 TQValueList<FrameIndex> indexes;
1800 TQValueList<FrameMoveStruct> moveStructs;
1801 TQPtrListIterator<KWFrameSet> fss = m_doc->framesetsIterator();
1802 for(;fss.current(); ++fss) {
1803 KWFrameSet *fs = *fss;
1804 if(fs->isMainFrameset()) continue;
1805 if(fs->isHeaderOrFooter()) continue;
1806 if(fs->isFootEndNote()) continue;
1807 if(! fs->isVisible()) continue;
1808 TQPtrList<KWFrame> frames = fs->frameIterator();
1809 TQPtrListIterator<KWFrame> framesIter(frames);
1810 for(; framesIter.current(); ++framesIter) {
1811 KWFrame *frame = *framesIter;
1812 if(frame->top() > topOfPage) {
1813 indexes.append(FrameIndex(frame));
1814 KoPoint before = frame->topLeft();
1815 frame->moveBy(0, -pageHeight);
1816 moveStructs.append(FrameMoveStruct(before, frame->topLeft()));
1817 }
1818 }
1819 }
1820 KCommand *cmd = new KWFrameMoveCommand("", indexes, moveStructs);
1821 childCommands.append(cmd);
1822 }
1823 m_doc->afterRemovePages();
1824}
1825
1826bool KWInsertRemovePageCommand::compareIndex(const FrameIndex &index1, const FrameIndex &index2) {
1827 if(index1.m_pFrameSet == index2.m_pFrameSet)
1828 return index1.m_iFrameIndex >= index2.m_iFrameIndex;
1829 return index1.m_pFrameSet >= index2.m_pFrameSet; // I don't care about frameset order,
1830 // so just sort on pointers..
1831}
1832
1833void KWInsertRemovePageCommand::doInsert(int pageNumber) {
1834 m_doc->pageManager()->insertPage( pageNumber );
1835 for(int i=childCommands.count()-1; i > 0; i--) // reverse order
1836 childCommands[i]->unexecute();
1837 m_doc->afterInsertPage( pageNumber );
1838}
1839
1840FramePaddingStruct::FramePaddingStruct( KWFrame *frame )
1841{
1842 topPadding = frame->paddingTop();
1843 bottomPadding= frame->paddingBottom();
1844 leftPadding = frame->paddingLeft();
1845 rightPadding= frame->paddingRight();
1846}
1847
1848FramePaddingStruct::FramePaddingStruct( double _left, double _top, double _right, double _bottom ):
1849 topPadding(_top),
1850 bottomPadding(_bottom),
1851 leftPadding(_left),
1852 rightPadding(_right)
1853{
1854}
1855
1856
1857KWFrameChangeFramePaddingCommand::KWFrameChangeFramePaddingCommand( const TQString &name, FrameIndex _frameIndex, FramePaddingStruct _framePaddingBegin, FramePaddingStruct _framePaddingEnd ) :
1858 KNamedCommand(name),
1859 m_indexFrame(_frameIndex),
1860 m_framePaddingBegin(_framePaddingBegin),
1861 m_framePaddingEnd(_framePaddingEnd)
1862{
1863}
1864
1865void KWFrameChangeFramePaddingCommand::execute()
1866{
1867 KWFrameSet *frameSet = m_indexFrame.m_pFrameSet;
1868 Q_ASSERT( frameSet );
1869 KWFrame *frame = frameSet->frame(m_indexFrame.m_iFrameIndex);
1870 Q_ASSERT( frame );
1871 frame->setFramePadding( m_framePaddingEnd.leftPadding,m_framePaddingEnd.topPadding , m_framePaddingEnd.rightPadding, m_framePaddingEnd.bottomPadding);
1872 frameSet->kWordDocument()->frameChanged( frame );
1873}
1874
1875void KWFrameChangeFramePaddingCommand::unexecute()
1876{
1877 KWFrameSet *frameSet = m_indexFrame.m_pFrameSet;
1878 Q_ASSERT( frameSet );
1879 KWFrame *frame = frameSet->frame(m_indexFrame.m_iFrameIndex);
1880 Q_ASSERT( frame );
1881 frame->setFramePadding( m_framePaddingBegin.leftPadding,m_framePaddingBegin.topPadding , m_framePaddingBegin.rightPadding, m_framePaddingBegin.bottomPadding);
1882 frameSet->kWordDocument()->frameChanged( frame );
1883}
1884
1885KWChangeFootEndNoteSettingsCommand::KWChangeFootEndNoteSettingsCommand( const TQString &name, KoParagCounter _oldCounter, KoParagCounter _newCounter ,bool _footNote ,KWDocument *_doc):
1886 KNamedCommand(name),
1887 m_oldCounter(_oldCounter),
1888 m_newCounter(_newCounter),
1889 m_footNote( _footNote ),
1890 m_doc(_doc)
1891{
1892}
1893
1894void KWChangeFootEndNoteSettingsCommand::execute()
1895{
1896 changeCounter( m_newCounter);
1897}
1898
1899void KWChangeFootEndNoteSettingsCommand::unexecute()
1900{
1901 changeCounter( m_oldCounter);
1902}
1903
1904void KWChangeFootEndNoteSettingsCommand::changeCounter( KoParagCounter counter)
1905{
1906 if (m_footNote )
1907 {
1908 static_cast<KWVariableSettings*>(m_doc->variableCollection()->variableSetting())->changeFootNoteCounter(counter );
1909 }
1910 else
1911 {
1912 static_cast<KWVariableSettings*>(m_doc->variableCollection()->variableSetting())->changeEndNoteCounter(counter );
1913 }
1914 m_doc->changeFootNoteConfig();
1915}
1916
1917
1918KWChangeTabStopValueCommand::KWChangeTabStopValueCommand( const TQString &name, double _oldValue, double _newValue, KWDocument *_doc):
1919 KNamedCommand(name),
1920 m_doc( _doc ),
1921 m_oldValue(_oldValue),
1922 m_newValue(_newValue)
1923{
1924}
1925
1926void KWChangeTabStopValueCommand::execute()
1927{
1928 m_doc->setTabStopValue ( m_newValue );
1929}
1930
1931void KWChangeTabStopValueCommand::unexecute()
1932{
1933 m_doc->setTabStopValue ( m_oldValue );
1934}
1935
1936
1937
1938FootNoteParameter::FootNoteParameter( KWFootNoteVariable *_var )
1939{
1940 noteType = _var->noteType();
1941 numberingType = _var->numberingType();
1942 manualString = _var->manualString();
1943}
1944
1945FootNoteParameter::FootNoteParameter( NoteType _noteType, KWFootNoteVariable::Numbering _numberingType, const TQString &_manualString)
1946{
1947 noteType= _noteType;
1948 numberingType = _numberingType;
1949 manualString = _manualString;
1950}
1951
1952KWChangeFootNoteParametersCommand::KWChangeFootNoteParametersCommand( const TQString &name, KWFootNoteVariable * _var, FootNoteParameter _oldParameter, FootNoteParameter _newParameter, KWDocument *_doc):
1953 KNamedCommand(name),
1954 m_doc( _doc ),
1955 m_var( _var ),
1956 m_oldParameter( _oldParameter ),
1957 m_newParameter( _newParameter)
1958{
1959}
1960
1961void KWChangeFootNoteParametersCommand::execute()
1962{
1963 changeVariableParameter( m_newParameter );
1964}
1965
1966void KWChangeFootNoteParametersCommand::unexecute()
1967{
1968 changeVariableParameter( m_oldParameter );
1969}
1970
1971void KWChangeFootNoteParametersCommand::changeVariableParameter( FootNoteParameter _param )
1972{
1973 m_var->setNoteType( _param.noteType );
1974 m_var->setNumberingType( _param.numberingType );
1975 m_var->setManualString( _param.manualString );
1976 m_var->setNumDisplay( -1 ); // force renumberFootNotes to recalc
1977 if ( m_var->numberingType()== KWFootNoteVariable::Manual)
1978 {
1979 m_var->resize();
1980 m_var->paragraph()->invalidate(0);
1981 m_var->paragraph()->setChanged( true );
1982 }
1983
1984 KWTextFrameSet * frameset = dynamic_cast<KWTextFrameSet *>( m_doc->frameSet( 0 ));
1985 Q_ASSERT( frameset );
1986 if ( frameset)
1987 frameset->renumberFootNotes();
1988
1989 // Re-layout the footnote/endnote frame
1990 KWFrame* footNoteFrame = m_var->frameSet()->frame( 0 );
1991 int framePage = footNoteFrame->pageNumber();
1992 m_doc->recalcFrames( framePage, -1 );
1993
1994 // Repaint
1995 m_doc->delayedRepaintAllViews();
1996}
1997
1998
1999KWChangeFootNoteLineSeparatorParametersCommand::KWChangeFootNoteLineSeparatorParametersCommand( const TQString &name, SeparatorLinePos _oldValuePos, SeparatorLinePos _newValuePos, int _oldLength, int _newLength, double _oldWidth, double _newWidth, SeparatorLineLineType _oldLineType, SeparatorLineLineType _newLineType, KWDocument *_doc):
2000 KNamedCommand(name),
2001 m_doc( _doc ),
2002 m_oldValuePos(_oldValuePos),
2003 m_newValuePos(_newValuePos),
2004 m_oldLength(_oldLength),
2005 m_newLength(_newLength),
2006 m_oldWidth(_oldWidth),
2007 m_newWidth(_newWidth),
2008 m_oldLineType(_oldLineType),
2009 m_newLineType(_newLineType)
2010
2011{
2012}
2013
2014void KWChangeFootNoteLineSeparatorParametersCommand::execute()
2015{
2016 changeLineSeparatorParameter( m_newValuePos, m_newLength, m_newWidth,m_newLineType );
2017}
2018
2019void KWChangeFootNoteLineSeparatorParametersCommand::unexecute()
2020{
2021 changeLineSeparatorParameter( m_oldValuePos, m_oldLength, m_oldWidth, m_oldLineType);
2022}
2023
2024void KWChangeFootNoteLineSeparatorParametersCommand::changeLineSeparatorParameter( SeparatorLinePos _pos, int _length, double _width, SeparatorLineLineType _type)
2025{
2026 m_doc->setFootNoteSeparatorLinePosition( _pos );
2027 m_doc->setFootNoteSeparatorLineLength( _length);
2028 m_doc->setFootNoteSeparatorLineWidth(_width );
2029 m_doc->setFootNoteSeparatorLineType( _type );
2030 m_doc->repaintAllViews();
2031}
2032
2033
2034KWRenameBookmarkCommand::KWRenameBookmarkCommand( const TQString &name, const TQString & _oldname, const TQString & _newName, KWDocument *_doc):
2035 KNamedCommand(name),
2036 m_doc( _doc ),
2037 m_oldName( _oldname),
2038 m_newName( _newName)
2039{
2040}
2041
2042void KWRenameBookmarkCommand::execute()
2043{
2044 m_doc->renameBookmark( m_oldName, m_newName);
2045}
2046
2047void KWRenameBookmarkCommand::unexecute()
2048{
2049 m_doc->renameBookmark( m_newName, m_oldName);
2050}
2051
2052KWResizeColumnCommand::KWResizeColumnCommand( KWTableFrameSet *table, int col, double oldSize, double newSize ):
2053 KNamedCommand( i18n("Resize Column") ),
2054 m_table( table ),
2055 m_oldSize( oldSize ),
2056 m_newSize( newSize ),
2057 m_col( col )
2058{
2059}
2060
2061void KWResizeColumnCommand::execute()
2062{
2063 m_table->resizeColumn(m_col, m_newSize);
2064 m_table->kWordDocument()->layout();
2065 m_table->kWordDocument()->repaintAllViews();
2066}
2067
2068void KWResizeColumnCommand::unexecute()
2069{
2070 m_table->resizeColumn(m_col, m_oldSize);
2071 m_table->kWordDocument()->layout();
2072 m_table->kWordDocument()->repaintAllViews();
2073}
2074
2075KWResizeRowCommand::KWResizeRowCommand( KWTableFrameSet *table, int row, double oldSize, double newSize ):
2076 KNamedCommand( i18n("Resize Row") ),
2077 m_table( table ),
2078 m_oldSize( oldSize ),
2079 m_newSize( newSize ),
2080 m_row( row )
2081{
2082}
2083
2084void KWResizeRowCommand::execute()
2085{
2086 m_table->resizeRow( m_row, m_newSize );
2087 m_table->kWordDocument()->repaintAllViews();
2088}
2089
2090void KWResizeRowCommand::unexecute()
2091{
2092 m_table->resizeRow( m_row, m_oldSize );
2093 m_table->kWordDocument()->repaintAllViews();
2094}
Command created when deleting a frame.
Definition KWCommand.h:415
The variable showing the footnote number in superscript, in the text.
Definition KWVariable.h:106
void update()
Update the z-ordering around the frame we host the framelist for.
KWFramePropertiesCommand(const TQString &name, KWFrame *_frameBefore, KWFrame *_frameAfter)
A copy of frameAfter is done internally.
Class: KWFrameSet Base type, a frameset holds content as well as frames to show that content.
Definition KWFrameSet.h:62
virtual void deleteFrame(unsigned int num, bool remove=true, bool recalc=true)
Delete a frame from the set of frames this frameSet has.
virtual FrameSetType type() const
The type of frameset.
Definition KWFrameSet.h:76
const TQPtrList< KWFrame > & frameIterator() const
Iterator over the child frames.
Definition KWFrameSet.h:159
int frameFromPtr(KWFrame *frame)
Get frame number.
KWTableFrameSet * groupmanager() const
returns the groupManager this frameset belongs to.
Definition KWFrameSet.h:408
KWFrame * frame(unsigned int _num) const
get a frame by number
TQString name() const
get/set frameset name. For tables in particular, this must be unique
Definition KWFrameSet.h:428
Info frameSetInfo() const
Returns the type of TextFrameSet this is.
Definition KWFrameSet.h:95
bool isVisible(KWViewMode *viewMode=0L) const
Returns true if the frameset is visible.
void setGroupManager(KWTableFrameSet *gm)
make this frameset part of a groupmanager
Definition KWFrameSet.h:406
Command created when applying a framestyle.
Definition KWCommand.h:153
The user-visible style for frames (borders and background).
This class represents a single frame.
Definition KWFrame.h:68
KWFrameSet * frameSet() const
Data stucture methods.
Definition KWFrame.h:143
double paddingTop() const
get top padding
Definition KWFrame.h:240
double paddingBottom() const
get bottom padding
Definition KWFrame.h:242
void setMinimumFrameHeight(double h)
The property minimum frame height is used to make the automatic frame shrinking code stop.
Definition KWFrame.h:279
double paddingLeft() const
get left padding
Definition KWFrame.h:236
double paddingRight() const
get right padding
Definition KWFrame.h:238
int pageNumber() const
The page on which this frame is.
Definition KWFrame.cpp:116
KWFrame * getCopy()
returns a copy of self
Definition KWFrame.cpp:135
void frameBordersChanged()
Marks a frame to have changed position/borders.
Definition KWFrame.cpp:167
KWPage * insertPage(int pageNumber)
Inserts a new page at the specified position in the document.
double height() const
return the height of this page (in pt)
Definition KWPage.cpp:44
A frameset that contains an embedded object (a KWDocumentChild).
This class implements tables by acting as the manager for the frame(set)s which make up the table cel...
void recalcCols(uint column, uint row)
resize and position all cells
Command created when applying a tablestyle.
Definition KWCommand.h:174
Table style (can created/modified/deleted by the user) A table style is simply a paragraph style and ...
This is our KoTextDocument reimplementation, to create KWTextParag instead of KoTextParags,...
KWTextFrameSet * textFrameSet() const
Return the text frameset in which this document is.
Class: KWTextFrameSet Contains text (KoTextObject) and frames to display that text.
KoTextObject * textObject() const
Return the contained text object.
void renumberFootNotes(bool repaint=true)
(Assuming this==main frameset), recalc the foot note numbers
This class extends KoTextParag for KWord-specific formatting stuff, custom items, loading and saving.
Definition KWTextParag.h:41
static KoTextFormat loadFormat(TQDomElement &formatElem, KoTextFormat *refFormat, const TQFont &defaultFont, const TQString &defaultLanguage, bool hyphanation)
Public for loading a style (KWord-1.3 XML).
void loadLayout(TQDomElement &attributes)
Load (from KWord-1.3 XML) and apply paragraph layout.
void loadFormatting(TQDomElement &attributes, int offset=0, bool loadFootNote=true)
Load (from KWord-1.3 XML) and apply <FORMAT> tags (used by KWTextParag::load and by KWPasteCommand).
RemovedRow and RemovedColumn implement the Memento design pattern.
Identifies a frame.
Definition KWCommand.h:98