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"
31#include "kspread_sheetprint.h"
37UndoWrapperCommand::UndoWrapperCommand(
UndoAction* ua )
42void UndoWrapperCommand::execute()
49void UndoWrapperCommand::unexecute()
54TQString UndoWrapperCommand::name()
const
56 return undoAction->getName();
61MergeCellCommand::MergeCellCommand(
Cell* c,
int cs,
int rs )
66 oldColSpan = cell->extraXCells();
67 oldRowSpan = cell->extraYCells();
70 TQRect area( cell->column(), cell->row(), cs+1, rs+1 );
71 rangeName = util_rangeName( area );
75TQString MergeCellCommand::name()
const
77 if( rangeName.isEmpty() )
78 return i18n(
"Merge Cells");
80 return i18n(
"Merge Cells %1").arg( rangeName );
83void MergeCellCommand::execute()
85 Sheet* sheet = cell->sheet();
87 sheet->changeMergedCell( cell->column(), cell->row(), colSpan, rowSpan);
90void MergeCellCommand::unexecute()
92 Sheet* sheet = cell->sheet();
94 sheet->changeMergedCell( cell->column(), cell->row(), oldColSpan, oldRowSpan);
99DissociateCellCommand::DissociateCellCommand(
Cell* c )
103 oldRowSpan = cell->extraYCells();
106TQString DissociateCellCommand::name()
const
108 return i18n(
"Dissociate Cell");
111void DissociateCellCommand::execute()
113 Sheet* sheet = cell->sheet();
115 sheet->changeMergedCell( cell->column(), cell->row(), 0, 0 );
118void DissociateCellCommand::unexecute()
120 Sheet* sheet = cell->sheet();
122 sheet->changeMergedCell( cell->column(), cell->row(), oldColSpan, oldRowSpan);
127RenameSheetCommand::RenameSheetCommand( Sheet* s,
const TQString &name )
130 if( s ) oldName = s->sheetName();
134TQString RenameSheetCommand::name()
const
136 return i18n(
"Rename Sheet");
139void RenameSheetCommand::execute()
142 sheet->setSheetName( newName );
145void RenameSheetCommand::unexecute()
148 sheet->setSheetName( oldName );
153HideSheetCommand::HideSheetCommand( Sheet* sheet )
156 sheetName = sheet->sheetName();
159void HideSheetCommand::execute()
161 Sheet* sheet = doc->map()->findSheet( sheetName );
164 sheet->hideSheet(
true );
167void HideSheetCommand::unexecute()
169 Sheet* sheet = doc->map()->findSheet( sheetName );
172 sheet->hideSheet(
false );
175TQString HideSheetCommand::name()
const
177 TQString n = TQString( i18n(
"Hide Sheet %1") ).arg( sheetName );
178 if( n.length() > 64 ) n = i18n(
"Hide Sheet");
184ShowSheetCommand::ShowSheetCommand( Sheet* sheet )
187 sheetName = sheet->sheetName();
190void ShowSheetCommand::execute()
192 Sheet* sheet = doc->map()->findSheet( sheetName );
195 sheet->hideSheet(
false );
198void ShowSheetCommand::unexecute()
200 Sheet* sheet = doc->map()->findSheet( sheetName );
203 sheet->hideSheet(
true );
206TQString ShowSheetCommand::name()
const
208 TQString n = TQString( i18n(
"Show Sheet %1") ).arg( sheetName );
209 if( n.length() > 64 ) n = i18n(
"Show Sheet");
216AddSheetCommand::AddSheetCommand( Sheet* s )
223void AddSheetCommand::execute()
225 sheet->workbook()->insertSheet( sheet );
226 doc->insertSheet( sheet );
229void AddSheetCommand::unexecute()
231 sheet->workbook()->takeSheet( sheet );
232 doc->takeSheet( sheet );
235TQString AddSheetCommand::name()
const
237 return i18n(
"Add Sheet");
243RemoveSheetCommand::RemoveSheetCommand( Sheet* s )
249void RemoveSheetCommand::execute()
251 sheet->workbook()->takeSheet( sheet );
252 doc->takeSheet( sheet );
255void RemoveSheetCommand::unexecute()
257 sheet->workbook()->insertSheet( sheet );
258 doc->insertSheet( sheet );
261TQString RemoveSheetCommand::name()
const
263 return i18n(
"Remove Sheet");
268SheetPropertiesCommand::SheetPropertiesCommand(
Doc* d, Sheet* s )
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();
285TQString SheetPropertiesCommand::name()
const
287 return i18n(
"Change Sheet Properties");
290void SheetPropertiesCommand::setLayoutDirection( Sheet::LayoutDirection dir )
295void SheetPropertiesCommand::setAutoCalc(
bool b )
300void SheetPropertiesCommand::setShowGrid(
bool b )
305void SheetPropertiesCommand::setShowPageBorders(
bool b )
307 newShowPageBorders = b;
310void SheetPropertiesCommand::setShowFormula(
bool b )
315void SheetPropertiesCommand::setHideZero(
bool b )
320void SheetPropertiesCommand::setShowFormulaIndicator(
bool b )
322 newShowFormulaIndicator = b;
325void SheetPropertiesCommand::setShowCommentIndicator(
bool b )
327 newShowCommentIndicator = b;
330void SheetPropertiesCommand::setColumnAsNumber(
bool b )
332 newColumnAsNumber = b;
335void SheetPropertiesCommand::setLcMode(
bool b )
340void SheetPropertiesCommand::setCapitalizeFirstLetter(
bool b )
342 newCapitalizeFirstLetter = b;
345void SheetPropertiesCommand::execute()
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 ) );
361void SheetPropertiesCommand::unexecute()
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 ) );
380InsertColumnCommand::InsertColumnCommand( Sheet* s ,
unsigned int _column,
unsigned int _nbCol )
383 sheetName = s->sheetName();
384 insertPosColumn = _column;
385 nbColumnInserted = _nbCol;
388void InsertColumnCommand::execute()
390 Sheet* sheet = doc->map()->findSheet( sheetName );
392 sheet->insertColumn( insertPosColumn,nbColumnInserted);
395void InsertColumnCommand::unexecute()
397 Sheet* sheet = doc->map()->findSheet( sheetName );
399 sheet->removeColumn( insertPosColumn,nbColumnInserted );
402TQString InsertColumnCommand::name()
const
404 return i18n(
"Insert Columns");
411DefinePrintRangeCommand::DefinePrintRangeCommand( Sheet *s )
414 sheetName = s->sheetName();
415 printRange = s->print()->printRange();
418void DefinePrintRangeCommand::execute()
420 Sheet* sheet = doc->map()->findSheet( sheetName );
422 sheet->print()->setPrintRange( printRangeRedo );
426void DefinePrintRangeCommand::unexecute()
428 Sheet* sheet = doc->map()->findSheet( sheetName );
430 printRangeRedo = sheet->print()->printRange();
431 sheet->print()->setPrintRange( printRange );
434TQString DefinePrintRangeCommand::name()
const
436 return i18n(
"Set Page Layout");
442PaperLayoutCommand::PaperLayoutCommand( Sheet *s )
445 sheetName = s->sheetName();
446 pl = s->print()->paperLayout();
447 hf = s->print()->headFootLine();
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();
460void PaperLayoutCommand::execute()
462 Sheet* sheet = doc->map()->findSheet( sheetName );
464 SheetPrint* print = sheet->print();
466 print->setPaperLayout( plRedo.ptLeft, plRedo.ptTop,
467 plRedo.ptRight, plRedo.ptBottom,
468 plRedo.format, plRedo.orientation );
470 print->setHeadFootLine( hfRedo.headLeft, hfRedo.headMid, hfRedo.headRight,
471 hfRedo.footLeft, hfRedo.footMid, hfRedo.footRight );
473 doc->setUnit( unitRedo );
475 print->setPrintGrid( printGridRedo );
476 print->setPrintCommentIndicator( printCommentIndicatorRedo );
477 print->setPrintFormulaIndicator( printFormulaIndicatorRedo );
479 print->setPrintRange( printRangeRedo );
480 print->setPrintRepeatColumns( printRepeatColumnsRedo );
481 print->setPrintRepeatRows( printRepeatRowsRedo );
483 print->setZoom( zoomRedo );
485 print->setPageLimitX( pageLimitX );
486 print->setPageLimitY( pageLimitY );
489void PaperLayoutCommand::unexecute()
491 Sheet* sheet = doc->map()->findSheet( sheetName );
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 );
499 hfRedo = print->headFootLine();
500 print->setHeadFootLine( hf.headLeft, hf.headMid, hf.headRight,
501 hf.footLeft, hf.footMid, hf.footRight );
503 unitRedo = doc->unit();
504 doc->setUnit( unit );
506 printGridRedo = print->printGrid();
507 print->setPrintGrid( printGrid );
509 printCommentIndicatorRedo = print->printCommentIndicator();
510 print->setPrintCommentIndicator( printCommentIndicator );
512 printFormulaIndicatorRedo = print->printFormulaIndicator();
513 print->setPrintFormulaIndicator( printFormulaIndicator );
515 printRangeRedo = print->printRange();
516 print->setPrintRange( printRange );
518 printRepeatColumnsRedo = print->printRepeatColumns();
519 print->setPrintRepeatColumns( printRepeatColumns );
521 printRepeatRowsRedo = print->printRepeatRows();
522 print->setPrintRepeatRows( printRepeatRows );
524 zoomRedo = print->zoom();
525 print->setZoom( zoom );
527 pageLimitXRedo = print->pageLimitX();
528 print->setPageLimitX( pageLimitX );
530 pageLimitYRedo = print->pageLimitY();
531 print->setPageLimitY( pageLimitY );
535TQString PaperLayoutCommand::name()
const
537 return i18n(
"Set Page Layout");
540LinkCommand::LinkCommand(
Cell* c,
const TQString& text,
const TQString& link )
543 oldText = cell->
text();
544 oldLink = cell->link();
548 Sheet* s = cell->sheet();
549 if( s ) doc = s->doc();
552void LinkCommand::execute()
556 if( !newText.isEmpty() )
557 cell->setCellText( newText );
558 cell->setLink( newLink );
560 doc->addDamage(
new CellDamage( cell ) );
563void LinkCommand::unexecute()
567 cell->setCellText( oldText );
568 cell->setLink( oldLink );
570 doc->addDamage(
new CellDamage( cell ) );
573TQString LinkCommand::name()
const
575 return newLink.isEmpty() ? i18n(
"Remove Link") : i18n(
"Set Link");
578ChangeObjectGeometryCommand::ChangeObjectGeometryCommand(
EmbeddedObject *_obj,
const KoPoint &_m_diff,
const KoSize &_r_diff )
579 : m_diff( _m_diff ), r_diff( _r_diff )
583 doc = obj->sheet()->doc();
586ChangeObjectGeometryCommand::~ChangeObjectGeometryCommand()
591void ChangeObjectGeometryCommand::execute()
593 doc->repaint( obj->geometry() );
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 );
606void ChangeObjectGeometryCommand::unexecute()
608 doc->repaint( obj->geometry() );
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 );
621TQString ChangeObjectGeometryCommand::name()
const
626 return i18n(
"Resize Object");
629RemoveObjectCommand::RemoveObjectCommand(
EmbeddedObject *_obj,
bool _cut )
633 doc = obj->sheet()->doc();
636RemoveObjectCommand::~RemoveObjectCommand()
641 if ( obj->getType() == OBJECT_CHART )
643 EmbeddedKOfficeObject *chart =
dynamic_cast<EmbeddedKOfficeObject *
>(obj);
644 chart->embeddedObject()->setDeleted(
true);
650void RemoveObjectCommand::execute()
660 doc->embeddedObjects().removeRef( obj );
661 if ( obj->getType() == OBJECT_CHART || obj->getType()== OBJECT_KOFFICE_PART)
663 EmbeddedKOfficeObject *eko =
dynamic_cast<EmbeddedKOfficeObject *
>(obj);
664 eko->embeddedObject()->setDeleted(
true);
667 obj->setSelected(
false );
672void RemoveObjectCommand::unexecute()
674 doc->embeddedObjects().append( obj );
675 if ( obj->getType() == OBJECT_CHART || obj->getType()== OBJECT_KOFFICE_PART)
677 EmbeddedKOfficeObject *eko =
dynamic_cast<EmbeddedKOfficeObject *
>(obj);
678 eko->embeddedObject()->setDeleted(
false);
684TQString RemoveObjectCommand::name()
const
687 return i18n(
"Cut Object");
689 return i18n(
"Remove Object");
692InsertObjectCommand::InsertObjectCommand(
const KoRect& _geometry, KoDocumentEntry& _entry,
Canvas *_canvas )
694 geometry = _geometry;
697 type = OBJECT_KOFFICE_PART;
701InsertObjectCommand::InsertObjectCommand(
const KoRect& _geometry, KoDocumentEntry& _entry,
const TQRect& _data,
Canvas *_canvas )
703 geometry = _geometry;
711InsertObjectCommand::InsertObjectCommand(
const KoRect& _geometry , KURL& _file,
Canvas *_canvas )
714 geometry = _geometry;
717 type = OBJECT_PICTURE;
721InsertObjectCommand::~InsertObjectCommand()
726 if ( obj->getType() == OBJECT_CHART )
728 EmbeddedKOfficeObject *chart =
dynamic_cast<EmbeddedKOfficeObject *
>(obj);
729 chart->embeddedObject()->setDeleted(
true);
735void InsertObjectCommand::execute()
739 canvas->doc()->embeddedObjects().append( obj );
740 canvas->doc()->repaint( obj );
744 bool success =
false;
749 success = canvas->activeSheet()->insertChart( geometry, entry, data );
752 case OBJECT_KOFFICE_PART:
754 success = canvas->activeSheet()->insertChild( geometry, entry );
759 success = canvas->activeSheet()->insertPicture( geometry.topLeft() , file );
767 obj = canvas->doc()->embeddedObjects().last();
768 obj->sheet()->unifyObjectName( obj );
776void InsertObjectCommand::unexecute()
781 canvas->doc()->embeddedObjects().removeRef( obj );
782 obj->setSelected(
false );
783 canvas->doc()->repaint( obj );
788TQString InsertObjectCommand::name()
const
790 return i18n(
"Insert Object");
793RenameNameObjectCommand::RenameNameObjectCommand(
const TQString &_name,
const TQString &_objectName,
795 KNamedCommand( _name ),
796 newObjectName( _objectName ),
800 oldObjectName =
object->getObjectName();
802 m_page =
object->sheet();
805RenameNameObjectCommand::~RenameNameObjectCommand()
809void RenameNameObjectCommand::execute()
811 object->setObjectName( newObjectName );
812 m_page->unifyObjectName(
object );
817void RenameNameObjectCommand::unexecute()
819 object->setObjectName( oldObjectName );
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 )
832 TQPtrListIterator<EmbeddedObject> it( m_objects );
833 for ( ; it.current() ; ++it )
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() );
843GeometryPropertiesCommand::GeometryPropertiesCommand(
const TQString &name, TQValueList<bool> &lst,
844 TQPtrList<EmbeddedObject> &objects,
bool newValue,
845 KgpType type,
Doc *_doc)
846: KNamedCommand( name )
848, m_objects( objects )
849, m_newValue( newValue )
853 TQPtrListIterator<EmbeddedObject> it( m_objects );
854 for ( ; it.current() ; ++it )
855 it.current()->incCmdRef();
858GeometryPropertiesCommand::~GeometryPropertiesCommand()
860 TQPtrListIterator<EmbeddedObject> it( m_objects );
861 for ( ; it.current() ; ++it )
862 it.current()->decCmdRef();
865void GeometryPropertiesCommand::execute()
867 TQPtrListIterator<EmbeddedObject> it( m_objects );
868 for ( ; it.current() ; ++it )
870 if ( m_type == ProtectSize )
872 it.current()->setProtect( m_newValue );
873 if ( it.current()->isSelected() )
874 m_doc->repaint( it.current() );
876 else if ( m_type == KeepRatio)
877 it.current()->setKeepRatio( m_newValue );
881void GeometryPropertiesCommand::unexecute()
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 )
888 obj->setProtect( *m_oldValue.at(i) );
889 if ( obj->isSelected() )
890 m_doc->repaint( obj );
892 else if ( m_type == KeepRatio)
893 obj->setKeepRatio( *m_oldValue.at(i) );
897MoveObjectByCmd::MoveObjectByCmd(
const TQString &_name,
const KoPoint &_diff, TQPtrList<EmbeddedObject> &_objects,
898 Doc *_doc,Sheet *_page )
899 : KNamedCommand( _name ), diff( _diff ), objects( _objects )
901 objects.setAutoDelete(
false );
904 TQPtrListIterator<EmbeddedObject> it( objects );
905 for ( ; it.current() ; ++it )
907 it.current()->incCmdRef();
911MoveObjectByCmd::~MoveObjectByCmd()
913 TQPtrListIterator<EmbeddedObject> it( objects );
914 for ( ; it.current() ; ++it )
915 it.current()->decCmdRef();
918void MoveObjectByCmd::execute()
922 for (
unsigned int i = 0; i < objects.count(); i++ ) {
923 doc->repaint( objects.at( i )->geometry() );
925 KoRect r = objects.at( i )->geometry();
926 r.moveBy( diff.x(), diff.y() );
927 objects.at( i )->setGeometry( r );
929 doc->repaint( objects.at( i ) );
933void MoveObjectByCmd::unexecute()
937 for (
unsigned int i = 0; i < objects.count(); i++ ) {
938 doc->repaint( objects.at( i )->geometry() );
940 KoRect r = objects.at( i )->geometry();
941 r.moveBy( -diff.x(), -diff.y() );
942 objects.at( i )->setGeometry( r );
944 doc->repaint( objects.at( i ) );
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.
This class holds the data that makes up a spreadsheet.
Contains basic information for every object.
void addSheet(Sheet *_sheet)
add sheet to the map, making it active