kspread

commands.cpp
1/* This file is part of the KDE project
2 Copyright 2004 Ariya Hidayat <ariya@kde.org>
3 Copyright 2004 Laurent Montel <montel@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 "commands.h"
22#include "damages.h"
23#include "kspread_canvas.h"
24#include "kspread_doc.h"
25#include "kspread_locale.h"
26#include "kspread_map.h"
27#include "kspread_sheet.h"
28#include "kspread_undo.h"
29#include "kspread_util.h"
30
31#include "kspread_sheetprint.h"
32
33using namespace KSpread;
34
35// ----- UndoWrapperCommand -----
36
37UndoWrapperCommand::UndoWrapperCommand( UndoAction* ua )
38{
39 undoAction = ua;
40}
41
42void UndoWrapperCommand::execute()
43{
44 // This is not really safe and functional, but UndoWrapperCommand
45 // is a workaround anyway. So leave it as it it (Ariya)
46 undoAction->redo();
47}
48
49void UndoWrapperCommand::unexecute()
50{
51 undoAction->undo();
52}
53
54TQString UndoWrapperCommand::name() const
55{
56 return undoAction->getName();
57}
58
59// ----- MergeCellsCommand -----
60
61MergeCellCommand::MergeCellCommand( Cell* c, int cs, int rs )
62{
63 cell = c;
64 colSpan = cs;
65 rowSpan = rs;
66 oldColSpan = cell->extraXCells();
67 oldRowSpan = cell->extraYCells();
68 if( cell )
69 {
70 TQRect area( cell->column(), cell->row(), cs+1, rs+1 );
71 rangeName = util_rangeName( area );
72 }
73}
74
75TQString MergeCellCommand::name() const
76{
77 if( rangeName.isEmpty() )
78 return i18n("Merge Cells");
79 else
80 return i18n("Merge Cells %1").arg( rangeName );
81}
82
83void MergeCellCommand::execute()
84{
85 Sheet* sheet = cell->sheet();
86 if( !sheet ) return;
87 sheet->changeMergedCell( cell->column(), cell->row(), colSpan, rowSpan);
88}
89
90void MergeCellCommand::unexecute()
91{
92 Sheet* sheet = cell->sheet();
93 if( !sheet ) return;
94 sheet->changeMergedCell( cell->column(), cell->row(), oldColSpan, oldRowSpan);
95}
96
97// ----- DissociateCellCommand -----
98
99DissociateCellCommand::DissociateCellCommand( Cell* c )
100{
101 cell = c;
102 oldColSpan = cell->extraXCells();
103 oldRowSpan = cell->extraYCells();
104}
105
106TQString DissociateCellCommand::name() const
107{
108 return i18n("Dissociate Cell");
109}
110
111void DissociateCellCommand::execute()
112{
113 Sheet* sheet = cell->sheet();
114 if( !sheet ) return;
115 sheet->changeMergedCell( cell->column(), cell->row(), 0, 0 );
116}
117
118void DissociateCellCommand::unexecute()
119{
120 Sheet* sheet = cell->sheet();
121 if( !sheet ) return;
122 sheet->changeMergedCell( cell->column(), cell->row(), oldColSpan, oldRowSpan);
123}
124
125// ----- RenameSheetCommand -----
126
127RenameSheetCommand::RenameSheetCommand( Sheet* s, const TQString &name )
128{
129 sheet = s;
130 if( s ) oldName = s->sheetName();
131 newName = name;
132}
133
134TQString RenameSheetCommand::name() const
135{
136 return i18n("Rename Sheet");
137}
138
139void RenameSheetCommand::execute()
140{
141 if( sheet )
142 sheet->setSheetName( newName );
143}
144
145void RenameSheetCommand::unexecute()
146{
147 if( sheet )
148 sheet->setSheetName( oldName );
149}
150
151// ----- HideSheetCommand -----
152
153HideSheetCommand::HideSheetCommand( Sheet* sheet )
154{
155 doc = sheet->doc();
156 sheetName = sheet->sheetName();
157}
158
159void HideSheetCommand::execute()
160{
161 Sheet* sheet = doc->map()->findSheet( sheetName );
162 if( !sheet ) return;
163
164 sheet->hideSheet( true );
165}
166
167void HideSheetCommand::unexecute()
168{
169 Sheet* sheet = doc->map()->findSheet( sheetName );
170 if( !sheet ) return;
171
172 sheet->hideSheet( false );
173}
174
175TQString HideSheetCommand::name() const
176{
177 TQString n = TQString( i18n("Hide Sheet %1") ).arg( sheetName );
178 if( n.length() > 64 ) n = i18n("Hide Sheet");
179 return n;
180}
181
182// ----- ShowSheetCommand -----
183
184ShowSheetCommand::ShowSheetCommand( Sheet* sheet )
185{
186 doc = sheet->doc();
187 sheetName = sheet->sheetName();
188}
189
190void ShowSheetCommand::execute()
191{
192 Sheet* sheet = doc->map()->findSheet( sheetName );
193 if( !sheet ) return;
194
195 sheet->hideSheet( false );
196}
197
198void ShowSheetCommand::unexecute()
199{
200 Sheet* sheet = doc->map()->findSheet( sheetName );
201 if( !sheet ) return;
202
203 sheet->hideSheet( true );
204}
205
206TQString ShowSheetCommand::name() const
207{
208 TQString n = TQString( i18n("Show Sheet %1") ).arg( sheetName );
209 if( n.length() > 64 ) n = i18n("Show Sheet");
210 return n;
211}
212
213
214// ----- AddSheetCommand -----
215
216AddSheetCommand::AddSheetCommand( Sheet* s )
217{
218 sheet = s;
219 doc = sheet->doc();
220 doc->map()->addSheet( s );
221}
222
223void AddSheetCommand::execute()
224{
225 sheet->workbook()->insertSheet( sheet );
226 doc->insertSheet( sheet );
227}
228
229void AddSheetCommand::unexecute()
230{
231 sheet->workbook()->takeSheet( sheet );
232 doc->takeSheet( sheet );
233}
234
235TQString AddSheetCommand::name() const
236{
237 return i18n("Add Sheet");
238}
239
240
241// ----- RemoveSheetCommand -----
242
243RemoveSheetCommand::RemoveSheetCommand( Sheet* s )
244{
245 sheet = s;
246 doc = sheet->doc();
247}
248
249void RemoveSheetCommand::execute()
250{
251 sheet->workbook()->takeSheet( sheet );
252 doc->takeSheet( sheet );
253}
254
255void RemoveSheetCommand::unexecute()
256{
257 sheet->workbook()->insertSheet( sheet );
258 doc->insertSheet( sheet );
259}
260
261TQString RemoveSheetCommand::name() const
262{
263 return i18n("Remove Sheet");
264}
265
266// ----- SheetPropertiesCommand -----
267
268SheetPropertiesCommand::SheetPropertiesCommand( Doc* d, Sheet* s )
269{
270 sheet = s;
271 doc = d;
272 oldDirection = newDirection = sheet->layoutDirection();
273 oldAutoCalc = newAutoCalc = sheet->getAutoCalc();
274 oldShowGrid = newShowGrid = sheet->getShowGrid();
275 oldShowPageBorders = newShowPageBorders = sheet->isShowPageBorders();
276 oldShowFormula = newShowFormula = sheet->getShowFormula();
277 oldHideZero = newHideZero = sheet->getHideZero();
278 oldShowFormulaIndicator = newShowFormulaIndicator = sheet->getShowFormulaIndicator();
279 oldShowCommentIndicator = newShowCommentIndicator = sheet->getShowCommentIndicator();
280 oldColumnAsNumber = newColumnAsNumber = sheet->getShowColumnNumber();
281 oldLcMode = newLcMode = sheet->getLcMode();
282 oldCapitalizeFirstLetter = newCapitalizeFirstLetter = sheet->getFirstLetterUpper();
283}
284
285TQString SheetPropertiesCommand::name() const
286{
287 return i18n("Change Sheet Properties");
288}
289
290void SheetPropertiesCommand::setLayoutDirection( Sheet::LayoutDirection dir )
291{
292 newDirection = dir;
293}
294
295void SheetPropertiesCommand::setAutoCalc( bool b )
296{
297 newAutoCalc = b;
298}
299
300void SheetPropertiesCommand::setShowGrid( bool b )
301{
302 newShowGrid = b;
303}
304
305void SheetPropertiesCommand::setShowPageBorders( bool b )
306{
307 newShowPageBorders = b;
308}
309
310void SheetPropertiesCommand::setShowFormula( bool b )
311{
312 newShowFormula = b;
313}
314
315void SheetPropertiesCommand::setHideZero( bool b )
316{
317 newHideZero = b;
318}
319
320void SheetPropertiesCommand::setShowFormulaIndicator( bool b )
321{
322 newShowFormulaIndicator = b;
323}
324
325void SheetPropertiesCommand::setShowCommentIndicator( bool b )
326{
327 newShowCommentIndicator = b;
328}
329
330void SheetPropertiesCommand::setColumnAsNumber( bool b )
331{
332 newColumnAsNumber = b;
333}
334
335void SheetPropertiesCommand::setLcMode( bool b )
336{
337 newLcMode = b;
338}
339
340void SheetPropertiesCommand::setCapitalizeFirstLetter( bool b )
341{
342 newCapitalizeFirstLetter = b;
343}
344
345void SheetPropertiesCommand::execute()
346{
347 sheet->setLayoutDirection( newDirection );
348 sheet->setAutoCalc( newAutoCalc );
349 sheet->setShowGrid( newShowGrid );
350 sheet->setShowPageBorders( newShowPageBorders );
351 sheet->setShowFormula( newShowFormula );
352 sheet->setHideZero( newHideZero );
353 sheet->setShowFormulaIndicator( newShowFormulaIndicator );
354 sheet->setShowCommentIndicator( newShowCommentIndicator );
355 sheet->setShowColumnNumber( newColumnAsNumber );
356 sheet->setLcMode( newLcMode );
357 sheet->setFirstLetterUpper( newCapitalizeFirstLetter );
358 doc->addDamage( new SheetDamage( sheet, SheetDamage::PropertiesChanged ) );
359}
360
361void SheetPropertiesCommand::unexecute()
362{
363 sheet->setLayoutDirection( oldDirection );
364 sheet->setAutoCalc( oldAutoCalc );
365 sheet->setShowGrid( oldShowGrid );
366 sheet->setShowPageBorders( oldShowPageBorders );
367 sheet->setShowFormula( oldShowFormula );
368 sheet->setHideZero( oldHideZero );
369 sheet->setShowFormulaIndicator( oldShowFormulaIndicator );
370 sheet->setShowCommentIndicator( oldShowCommentIndicator );
371 sheet->setShowColumnNumber( oldColumnAsNumber );
372 sheet->setLcMode( oldLcMode );
373 sheet->setFirstLetterUpper( oldCapitalizeFirstLetter );
374 doc->addDamage( new SheetDamage( sheet, SheetDamage::PropertiesChanged ) );
375}
376
377
378// ----- InsertColumnCommand -----
379
380InsertColumnCommand::InsertColumnCommand( Sheet* s , unsigned int _column, unsigned int _nbCol )
381{
382 doc = s->doc();
383 sheetName = s->sheetName();
384 insertPosColumn = _column;
385 nbColumnInserted = _nbCol;
386}
387
388void InsertColumnCommand::execute()
389{
390 Sheet* sheet = doc->map()->findSheet( sheetName );
391 if( !sheet ) return;
392 sheet->insertColumn( insertPosColumn,nbColumnInserted);
393}
394
395void InsertColumnCommand::unexecute()
396{
397 Sheet* sheet = doc->map()->findSheet( sheetName );
398 if( !sheet ) return;
399 sheet->removeColumn( insertPosColumn,nbColumnInserted );
400}
401
402TQString InsertColumnCommand::name() const
403{
404 return i18n("Insert Columns");
405}
406
407
408// ----- DefinePrintRangeCommand -----
409
410
411DefinePrintRangeCommand::DefinePrintRangeCommand( Sheet *s )
412{
413 doc = s->doc();
414 sheetName = s->sheetName();
415 printRange = s->print()->printRange();
416}
417
418void DefinePrintRangeCommand::execute()
419{
420 Sheet* sheet = doc->map()->findSheet( sheetName );
421 if( !sheet ) return;
422 sheet->print()->setPrintRange( printRangeRedo );
423
424}
425
426void DefinePrintRangeCommand::unexecute()
427{
428 Sheet* sheet = doc->map()->findSheet( sheetName );
429 if( !sheet ) return;
430 printRangeRedo = sheet->print()->printRange();
431 sheet->print()->setPrintRange( printRange );
432}
433
434TQString DefinePrintRangeCommand::name() const
435{
436 return i18n("Set Page Layout");
437}
438
439// ----- PaperLayoutCommand -----
440
441
442PaperLayoutCommand::PaperLayoutCommand( Sheet *s )
443{
444 doc = s->doc();
445 sheetName = s->sheetName();
446 pl = s->print()->paperLayout();
447 hf = s->print()->headFootLine();
448 unit = doc->unit();
449 printGrid = s->print()->printGrid();
450 printCommentIndicator = s->print()->printCommentIndicator();
451 printFormulaIndicator = s->print()->printFormulaIndicator();
452 printRange = s->print()->printRange();
453 printRepeatColumns = s->print()->printRepeatColumns();
454 printRepeatRows = s->print()->printRepeatRows();
455 zoom = s->print()->zoom();
456 pageLimitX = s->print()->pageLimitX();
457 pageLimitY = s->print()->pageLimitY();
458}
459
460void PaperLayoutCommand::execute()
461{
462 Sheet* sheet = doc->map()->findSheet( sheetName );
463 if( !sheet ) return;
464 SheetPrint* print = sheet->print();
465
466 print->setPaperLayout( plRedo.ptLeft, plRedo.ptTop,
467 plRedo.ptRight, plRedo.ptBottom,
468 plRedo.format, plRedo.orientation );
469
470 print->setHeadFootLine( hfRedo.headLeft, hfRedo.headMid, hfRedo.headRight,
471 hfRedo.footLeft, hfRedo.footMid, hfRedo.footRight );
472
473 doc->setUnit( unitRedo );
474
475 print->setPrintGrid( printGridRedo );
476 print->setPrintCommentIndicator( printCommentIndicatorRedo );
477 print->setPrintFormulaIndicator( printFormulaIndicatorRedo );
478
479 print->setPrintRange( printRangeRedo );
480 print->setPrintRepeatColumns( printRepeatColumnsRedo );
481 print->setPrintRepeatRows( printRepeatRowsRedo );
482
483 print->setZoom( zoomRedo );
484
485 print->setPageLimitX( pageLimitX );
486 print->setPageLimitY( pageLimitY );
487}
488
489void PaperLayoutCommand::unexecute()
490{
491 Sheet* sheet = doc->map()->findSheet( sheetName );
492 if( !sheet ) return;
493 SheetPrint* print = sheet->print();
494 plRedo = print->paperLayout();
495 print->setPaperLayout( pl.ptLeft, pl.ptTop,
496 pl.ptRight, pl.ptBottom,
497 pl.format, pl.orientation );
498
499 hfRedo = print->headFootLine();
500 print->setHeadFootLine( hf.headLeft, hf.headMid, hf.headRight,
501 hf.footLeft, hf.footMid, hf.footRight );
502
503 unitRedo = doc->unit();
504 doc->setUnit( unit );
505
506 printGridRedo = print->printGrid();
507 print->setPrintGrid( printGrid );
508
509 printCommentIndicatorRedo = print->printCommentIndicator();
510 print->setPrintCommentIndicator( printCommentIndicator );
511
512 printFormulaIndicatorRedo = print->printFormulaIndicator();
513 print->setPrintFormulaIndicator( printFormulaIndicator );
514
515 printRangeRedo = print->printRange();
516 print->setPrintRange( printRange );
517
518 printRepeatColumnsRedo = print->printRepeatColumns();
519 print->setPrintRepeatColumns( printRepeatColumns );
520
521 printRepeatRowsRedo = print->printRepeatRows();
522 print->setPrintRepeatRows( printRepeatRows );
523
524 zoomRedo = print->zoom();
525 print->setZoom( zoom );
526
527 pageLimitXRedo = print->pageLimitX();
528 print->setPageLimitX( pageLimitX );
529
530 pageLimitYRedo = print->pageLimitY();
531 print->setPageLimitY( pageLimitY );
532
533}
534
535TQString PaperLayoutCommand::name() const
536{
537 return i18n("Set Page Layout");
538}
539
540LinkCommand::LinkCommand( Cell* c, const TQString& text, const TQString& link )
541{
542 cell = c;
543 oldText = cell->text();
544 oldLink = cell->link();
545 newText = text;
546 newLink = link;
547
548 Sheet* s = cell->sheet();
549 if( s ) doc = s->doc();
550}
551
552void LinkCommand::execute()
553{
554 if( !cell ) return;
555
556 if( !newText.isEmpty() )
557 cell->setCellText( newText );
558 cell->setLink( newLink );
559
560 doc->addDamage( new CellDamage( cell ) );
561}
562
563void LinkCommand::unexecute()
564{
565 if( !cell ) return;
566
567 cell->setCellText( oldText );
568 cell->setLink( oldLink );
569
570 doc->addDamage( new CellDamage( cell ) );
571}
572
573TQString LinkCommand::name() const
574{
575 return newLink.isEmpty() ? i18n("Remove Link") : i18n("Set Link");
576}
577
578ChangeObjectGeometryCommand::ChangeObjectGeometryCommand( EmbeddedObject *_obj, const KoPoint &_m_diff, const KoSize &_r_diff )
579 : m_diff( _m_diff ), r_diff( _r_diff )
580{
581 obj = _obj;
582 obj->incCmdRef();
583 doc = obj->sheet()->doc();
584}
585
586ChangeObjectGeometryCommand::~ChangeObjectGeometryCommand()
587{
588 obj->decCmdRef();
589}
590
591void ChangeObjectGeometryCommand::execute()
592{
593 doc->repaint( obj->geometry() );
594
595 KoRect geometry = obj->geometry();
596 geometry.moveBy( m_diff.x(), m_diff.y() );
597 geometry.setWidth( geometry.width() + r_diff.width() );
598 geometry.setHeight( geometry.height() + r_diff.height() );
599 obj->setGeometry( geometry );
600
601// if ( object->isSelected())
602// doc->updateObjectStatusBarItem();
603 doc->repaint( obj );
604}
605
606void ChangeObjectGeometryCommand::unexecute()
607{
608 doc->repaint( obj->geometry() );
609
610 KoRect geometry = obj->geometry();
611 geometry.moveBy( -m_diff.x(), -m_diff.y() );
612 geometry.setWidth( geometry.width() - r_diff.width() );
613 geometry.setHeight( geometry.height() - r_diff.height() );
614 obj->setGeometry( geometry );
615
616// if ( object->isSelected())
617// doc->updateObjectStatusBarItem();
618 doc->repaint( obj );
619}
620
621TQString ChangeObjectGeometryCommand::name() const
622{
623 /*if ( fabs( obj->geometry().width() - newGeometry.width() )<1e-3 && fabs( obj->geometry().height() - newGeometry.height() ) < 1e-3 )
624 return i18n("Move Object");
625 else */
626 return i18n("Resize Object");
627}
628
629RemoveObjectCommand::RemoveObjectCommand( EmbeddedObject *_obj, bool _cut )
630{
631 obj = _obj;
632 cut = _cut;
633 doc = obj->sheet()->doc();
634}
635
636RemoveObjectCommand::~RemoveObjectCommand()
637{
638 if ( !executed )
639 return;
640 //kdDebug() << "*********Deleting object..." << endl;
641 if ( obj->getType() == OBJECT_CHART )
642 {
643 EmbeddedKOfficeObject *chart = dynamic_cast<EmbeddedKOfficeObject *>(obj);
644 chart->embeddedObject()->setDeleted(true);
645 }
646
647 delete obj;
648}
649
650void RemoveObjectCommand::execute()
651{
652
653// I don't think we need this:
654// Make shure that this child has no active embedded view -> activate ourselfs
655// doc()->emitBeginOperation( false );
656// partManager()->setActivePart( koDocument(), this );
657// partManager()->setSelectedPart( 0 );
658// doc()->emitEndOperation( d->activeSheet->visibleRect( d->canvas ) );
659
660 doc->embeddedObjects().removeRef( obj );
661 if ( obj->getType() == OBJECT_CHART || obj->getType()== OBJECT_KOFFICE_PART)
662 {
663 EmbeddedKOfficeObject *eko = dynamic_cast<EmbeddedKOfficeObject *>(obj);
664 eko->embeddedObject()->setDeleted(true);
665 }
666
667 obj->setSelected( false );
668 doc->repaint( obj );
669 executed = true;
670}
671
672void RemoveObjectCommand::unexecute()
673{
674 doc->embeddedObjects().append( obj );
675 if ( obj->getType() == OBJECT_CHART || obj->getType()== OBJECT_KOFFICE_PART)
676 {
677 EmbeddedKOfficeObject *eko = dynamic_cast<EmbeddedKOfficeObject *>(obj);
678 eko->embeddedObject()->setDeleted(false);
679 }
680 doc->repaint( obj );
681 executed = false;
682}
683
684TQString RemoveObjectCommand::name() const
685{
686 if ( cut )
687 return i18n("Cut Object");
688 else
689 return i18n("Remove Object");
690}
691
692InsertObjectCommand::InsertObjectCommand( const KoRect& _geometry, KoDocumentEntry& _entry, Canvas *_canvas ) //child
693{
694 geometry = _geometry;
695 entry = _entry;
696 canvas = _canvas;
697 type = OBJECT_KOFFICE_PART;
698 obj = 0;
699}
700
701InsertObjectCommand::InsertObjectCommand(const KoRect& _geometry, KoDocumentEntry& _entry, const TQRect& _data, Canvas *_canvas ) //chart
702{
703 geometry = _geometry;
704 entry = _entry;
705 data = _data;
706 canvas = _canvas;
707 type = OBJECT_CHART;
708 obj = 0;
709}
710
711InsertObjectCommand::InsertObjectCommand( const KoRect& _geometry , KURL& _file, Canvas *_canvas ) //picture
712{
713 //In the case of pictures, only the top left point of the rectangle is relevant
714 geometry = _geometry;
715 file = _file;
716 canvas = _canvas;
717 type = OBJECT_PICTURE;
718 obj = 0;
719}
720
721InsertObjectCommand::~InsertObjectCommand()
722{
723 if ( executed )
724 return;
725 //kdDebug() << "*********Deleting object..." << endl;
726 if ( obj->getType() == OBJECT_CHART )
727 {
728 EmbeddedKOfficeObject *chart = dynamic_cast<EmbeddedKOfficeObject *>(obj);
729 chart->embeddedObject()->setDeleted(true);
730 }
731
732 delete obj;
733}
734
735void InsertObjectCommand::execute()
736{
737 if ( obj ) //restore the object which was removed from the object list in InsertObjectCommand::unexecute()
738 {
739 canvas->doc()->embeddedObjects().append( obj );
740 canvas->doc()->repaint( obj );
741 }
742 else
743 {
744 bool success = false;
745 switch ( type )
746 {
747 case OBJECT_CHART:
748 {
749 success = canvas->activeSheet()->insertChart( geometry, entry, data );
750 break;
751 }
752 case OBJECT_KOFFICE_PART:
753 {
754 success = canvas->activeSheet()->insertChild( geometry, entry );
755 break;
756 }
757 case OBJECT_PICTURE:
758 {
759 success = canvas->activeSheet()->insertPicture( geometry.topLeft() , file );
760 break;
761 }
762 default:
763 break;
764 }
765 if ( success )
766 {
767 obj = canvas->doc()->embeddedObjects().last();
768 obj->sheet()->unifyObjectName( obj );
769 }
770 else
771 obj = 0;
772 }
773 executed = true;
774}
775
776void InsertObjectCommand::unexecute()
777{
778 if ( !obj )
779 return;
780
781 canvas->doc()->embeddedObjects().removeRef( obj );
782 obj->setSelected( false );
783 canvas->doc()->repaint( obj );
784
785 executed = false;
786}
787
788TQString InsertObjectCommand::name() const
789{
790 return i18n("Insert Object");
791}
792
793RenameNameObjectCommand::RenameNameObjectCommand( const TQString &_name, const TQString &_objectName,
794 EmbeddedObject *_obj, Doc *_doc ):
795 KNamedCommand( _name ),
796 newObjectName( _objectName ),
797 object( _obj ),
798 doc( _doc )
799{
800 oldObjectName = object->getObjectName();
801
802 m_page = object->sheet()/*doc->findPage( object )*/;
803}
804
805RenameNameObjectCommand::~RenameNameObjectCommand()
806{
807}
808
809void RenameNameObjectCommand::execute()
810{
811 object->setObjectName( newObjectName );
812 m_page->unifyObjectName( object );
813
814// doc->updateSideBarItem( m_page );
815}
816
817void RenameNameObjectCommand::unexecute()
818{
819 object->setObjectName( oldObjectName );
820
821// doc->updateSideBarItem( m_page );
822}
823
824GeometryPropertiesCommand::GeometryPropertiesCommand( const TQString &name, TQPtrList<EmbeddedObject> &objects,
825 bool newValue, KgpType type, Doc *_doc )
826: KNamedCommand( name )
827, m_objects( objects )
828, m_newValue( newValue )
829, m_type( type )
830 , m_doc( _doc )
831{
832 TQPtrListIterator<EmbeddedObject> it( m_objects );
833 for ( ; it.current() ; ++it )
834 {
835 it.current()->incCmdRef();
836 if ( m_type == ProtectSize )
837 m_oldValue.append( it.current()->isProtect() );
838 else if ( m_type == KeepRatio)
839 m_oldValue.append( it.current()->isKeepRatio() );
840 }
841}
842
843GeometryPropertiesCommand::GeometryPropertiesCommand( const TQString &name, TQValueList<bool> &lst,
844 TQPtrList<EmbeddedObject> &objects, bool newValue,
845 KgpType type, Doc *_doc)
846: KNamedCommand( name )
847, m_oldValue( lst )
848, m_objects( objects )
849, m_newValue( newValue )
850, m_type( type )
851, m_doc ( _doc )
852{
853 TQPtrListIterator<EmbeddedObject> it( m_objects );
854 for ( ; it.current() ; ++it )
855 it.current()->incCmdRef();
856}
857
858GeometryPropertiesCommand::~GeometryPropertiesCommand()
859{
860 TQPtrListIterator<EmbeddedObject> it( m_objects );
861 for ( ; it.current() ; ++it )
862 it.current()->decCmdRef();
863}
864
865void GeometryPropertiesCommand::execute()
866{
867 TQPtrListIterator<EmbeddedObject> it( m_objects );
868 for ( ; it.current() ; ++it )
869 {
870 if ( m_type == ProtectSize )
871 {
872 it.current()->setProtect( m_newValue );
873 if ( it.current()->isSelected() )
874 m_doc->repaint( it.current() );
875 }
876 else if ( m_type == KeepRatio)
877 it.current()->setKeepRatio( m_newValue );
878 }
879}
880
881void GeometryPropertiesCommand::unexecute()
882{
883 EmbeddedObject *obj = 0;
884 for ( unsigned int i = 0; i < m_objects.count(); ++i ) {
885 obj = m_objects.at( i );
886 if ( m_type == ProtectSize )
887 {
888 obj->setProtect( *m_oldValue.at(i) );
889 if ( obj->isSelected() )
890 m_doc->repaint( obj );
891 }
892 else if ( m_type == KeepRatio)
893 obj->setKeepRatio( *m_oldValue.at(i) );
894 }
895}
896
897MoveObjectByCmd::MoveObjectByCmd( const TQString &_name, const KoPoint &_diff, TQPtrList<EmbeddedObject> &_objects,
898 Doc *_doc,Sheet *_page )
899 : KNamedCommand( _name ), diff( _diff ), objects( _objects )
900{
901 objects.setAutoDelete( false );
902 doc = _doc;
903 m_page=_page;
904 TQPtrListIterator<EmbeddedObject> it( objects );
905 for ( ; it.current() ; ++it )
906 {
907 it.current()->incCmdRef();
908 }
909}
910
911MoveObjectByCmd::~MoveObjectByCmd()
912{
913 TQPtrListIterator<EmbeddedObject> it( objects );
914 for ( ; it.current() ; ++it )
915 it.current()->decCmdRef();
916}
917
918void MoveObjectByCmd::execute()
919{
920 TQRect oldRect;
921
922 for ( unsigned int i = 0; i < objects.count(); i++ ) {
923 doc->repaint( objects.at( i )->geometry() );
924
925 KoRect r = objects.at( i )->geometry();
926 r.moveBy( diff.x(), diff.y() );
927 objects.at( i )->setGeometry( r );
928
929 doc->repaint( objects.at( i ) );
930 }
931}
932
933void MoveObjectByCmd::unexecute()
934{
935 TQRect oldRect;
936
937 for ( unsigned int i = 0; i < objects.count(); i++ ) {
938 doc->repaint( objects.at( i )->geometry() );
939
940 KoRect r = objects.at( i )->geometry();
941 r.moveBy( -diff.x(), -diff.y() );
942 objects.at( i )->setGeometry( r );
943
944 doc->repaint( objects.at( i ) );
945 }
946}
The canvas builds a part of the GUI of KSpread.
For every cell in the spread sheet there is a Cell object.
TQString text() const
Return the text the user entered.
int extraXCells() const
This class holds the data that makes up a spreadsheet.
Definition kspread_doc.h:98
Contains basic information for every object.
void addSheet(Sheet *_sheet)
add sheet to the map, making it active
Abstract base class.
The KSpread namespace.
Definition commands.h:39