30#include <tqapplication.h>
31#include <tqcheckbox.h>
32#include <tqclipboard.h>
35#include <tqlineedit.h>
44#include <kfinddialog.h>
45#include <tdemessagebox.h>
47#include <kreplacedialog.h>
53#include <KoDocumentInfo.h>
54#include <KoOasisLoadingContext.h>
55#include <KoOasisSettings.h>
56#include <KoOasisStyles.h>
57#include <KoQueryTrader.h>
58#include <KoStyleStack.h>
61#include <KoXmlWriter.h>
64#include "dependencies.h"
66#include "ksploadinginfo.h"
67#include "ksprsavinginfo.h"
68#include "kspread_canvas.h"
69#include "kspread_cluster.h"
70#include "kspread_condition.h"
71#include "kspread_doc.h"
72#include "kspread_global.h"
73#include "kspread_locale.h"
74#include "kspread_map.h"
75#include "kspread_object.h"
76#include "kspread_sheetprint.h"
77#include "kspread_style.h"
78#include "kspread_style_manager.h"
79#include "kspread_undo.h"
80#include "kspread_util.h"
81#include "kspread_view.h"
82#include "manipulator.h"
83#include "manipulator_data.h"
84#include "KSpreadTableIface.h"
86#include "kspread_sheet.h"
87#include "kspread_sheet.moc"
89#define NO_MODIFICATION_POSSIBLE \
91 KMessageBox::error( 0, i18n ( "You cannot change a protected sheet" ) ); return; \
102CellBinding::CellBinding( Sheet *_sheet,
const TQRect& _area )
104 m_rctDataArea = _area;
107 m_pSheet->addCellBinding(
this );
109 m_bIgnoreChanges =
false;
112CellBinding::~CellBinding()
114 m_pSheet->removeCellBinding(
this );
119 if ( m_bIgnoreChanges )
122 emit changed( _cell );
125bool CellBinding::contains(
int _x,
int _y )
127 return m_rctDataArea.contains( TQPoint( _x, _y ) );
136ChartBinding::ChartBinding( Sheet *_sheet,
const TQRect& _area, EmbeddedChart *_child )
137 : CellBinding( _sheet, _area )
142ChartBinding::~ChartBinding()
146void ChartBinding::cellChanged( Cell* )
148 if ( m_bIgnoreChanges )
154 const TQRect chartGeometry = m_child->geometry().toTQRect();
157 int left = sheet()->leftColumn( chartGeometry.left() , tmp );
158 int top = sheet()->topRow( chartGeometry.top() , tmp );
159 int right = sheet()->rightColumn( chartGeometry.right() );
160 int bottom = sheet()->bottomRow( chartGeometry.bottom() );
162 sheet()->setRegionPaintDirty( TQRect(left,top,right-left,bottom-top) );
169 KoChart::Part *chart = m_child->chart();
170 chart->resizeData( m_rctDataArea.height(), m_rctDataArea.width() );
177 for (
int row = 0; row < m_rctDataArea.height(); row++ ) {
178 for (
int col = 0; col < m_rctDataArea.width(); col++ ) {
179 cell = m_pSheet->cellAt( m_rctDataArea.left() + col,
180 m_rctDataArea.top() + row );
182 chart->setCellData( row, col, cell->
value().
asFloat() );
186 chart->setCellData( row, col, KoChart::Value() );
189 chart->analyzeHeaders( );
194 range.top = m_rctDataArea.top();
195 range.left = m_rctDataArea.left();
196 range.right = m_rctDataArea.right();
197 range.bottom = m_rctDataArea.bottom();
198 range.
sheet = m_pSheet->name(); */
215TextDrag::TextDrag( TQWidget * dragSource,
const char * name )
216 : TQTextDrag( dragSource, name )
225TQByteArray TextDrag::encodedData(
const char * mime )
const
227 if ( strcmp( selectionMimeType(), mime ) == 0)
230 return TQTextDrag::encodedData( mime );
233bool TextDrag::canDecode( TQMimeSource* e )
235 if ( e->provides( selectionMimeType() ) )
237 return TQTextDrag::canDecode(e);
240const char * TextDrag::format(
int i )
const
243 return TQTextDrag::format(i);
245 return selectionMimeType();
249const char * TextDrag::selectionMimeType()
251 return "application/x-kspread-snippet";
271 Sheet::LayoutDirection layoutDirection;
282 bool showFormulaIndicator;
283 bool showCommentIndicator;
286 bool showColumnNumber;
288 bool firstLetterUpper;
293 ColumnCluster columns;
298 RowFormat* defaultRowFormat;
299 ColumnFormat* defaultColumnFormat;
305 Region paintDirtyList;
313 TQPtrList<CellBinding> cellBindings;
317 bool showPageBorders;
332 bool scrollBarUpdates;
345TQIntDict<Sheet>* Sheet::s_mapSheets;
347Sheet* Sheet::find(
int _id )
352 return (*s_mapSheets)[ _id ];
355Sheet::Sheet (Map* map,
356 const TQString &sheetName,
const char *_name )
357 : TQObject( map, _name )
359 if ( s_mapSheets == 0L )
360 s_mapSheets =
new TQIntDict<Sheet>;
366 s_mapSheets->insert( d->id,
this );
368 d->layoutDirection = LeftToRight;
370 d->defaultFormat =
new Format (
this, d->workbook->doc()->styleManager()->defaultStyle());
371 d->emptyPen.setStyle( TQt::NoPen );
376 d->cellBindings.setAutoDelete(
false );
380 d->cells.setAutoDelete(
true );
381 d->rows.setAutoDelete(
true );
382 d->columns.setAutoDelete(
true );
384 d->defaultCell =
new Cell(
this, d->workbook->doc()->styleManager()->defaultStyle(), 0, 0);
385 d->defaultRowFormat =
new RowFormat(
this, 0 );
386 d->defaultRowFormat->setDefault();
387 d->defaultColumnFormat =
new ColumnFormat(
this, 0 );
388 d->defaultColumnFormat->setDefault();
390 d->widget =
new TQWidget();
391 d->painter =
new TQPainter;
392 d->painter->begin( d->widget );
396 d->sizeMaxX = KS_colMax * d->defaultColumnFormat->dblWidth();
397 d->sizeMaxY = KS_rowMax * d->defaultRowFormat->dblHeight();
399 d->scrollBarUpdates =
true;
403 d->showFormula=
false;
404 d->showFormulaIndicator=
true;
405 d->showCommentIndicator=
true;
406 d->showPageBorders =
false;
409 d->showColumnNumber=
false;
411 d->firstLetterUpper=
false;
417 s.sprintf(
"Sheet%i", s_id );
418 TQObject::setName( s.data() );
420 d->print =
new SheetPrint(
this );
426 TQObject::connect( doc(), TQ_SIGNAL( sig_addAreaName(
const TQString & ) ),
427 this, TQ_SLOT( slotAreaModified(
const TQString & ) ) );
429 TQObject::connect( doc(), TQ_SIGNAL( sig_removeAreaName(
const TQString & ) ),
430 this, TQ_SLOT( slotAreaModified(
const TQString & ) ) );
435TQString Sheet::sheetName()
const
440Map* Sheet::workbook()
const
445Doc* Sheet::doc()
const
447 return d->workbook->doc();
455Sheet::LayoutDirection Sheet::layoutDirection()
const
457 return d->layoutDirection;
460void Sheet::setLayoutDirection( LayoutDirection dir )
462 d->layoutDirection = dir;
465bool Sheet::isRightToLeft()
const
467 return d->layoutDirection == RightToLeft;
470bool Sheet::isHidden()
const
475void Sheet::setHidden(
bool hidden )
480bool Sheet::getShowGrid()
const
485void Sheet::setShowGrid(
bool _showGrid )
487 d->showGrid=_showGrid;
490bool Sheet::getShowFormula()
const
492 return d->showFormula;
495void Sheet::setShowFormula(
bool _showFormula )
497 d->showFormula=_showFormula;
500bool Sheet::getShowFormulaIndicator()
const
502 return d->showFormulaIndicator;
505void Sheet::setShowFormulaIndicator(
bool _showFormulaIndicator )
507 d->showFormulaIndicator=_showFormulaIndicator;
510bool Sheet::getShowCommentIndicator()
const
512 return d->showCommentIndicator;
515void Sheet::setShowCommentIndicator(
bool _indic)
517 d->showCommentIndicator=_indic;
520bool Sheet::getLcMode()
const
525void Sheet::setLcMode(
bool _lcMode )
530bool Sheet::getAutoCalc()
const
535void Sheet::setAutoCalc(
bool _AutoCalc )
538 if (d->autoCalc == _AutoCalc)
542 if (_AutoCalc ==
true)
544 updateAllDependencies();
548 d->autoCalc=_AutoCalc;
553bool Sheet::getShowColumnNumber()
const
555 return d->showColumnNumber;
558void Sheet::setShowColumnNumber(
bool _showColumnNumber )
560 d->showColumnNumber=_showColumnNumber;
563bool Sheet::getHideZero()
const
568void Sheet::setHideZero(
bool _hideZero )
570 d->hideZero=_hideZero;
573bool Sheet::getFirstLetterUpper()
const
575 return d->firstLetterUpper;
578void Sheet::setFirstLetterUpper(
bool _firstUpper )
580 d->firstLetterUpper=_firstUpper;
583bool Sheet::isShowPageBorders()
const
585 return d->showPageBorders;
588bool Sheet::isEmpty(
unsigned long int x,
unsigned long int y )
const
590 const Cell* c = cellAt( x, y );
591 if ( !c || c->isEmpty() )
597Cell* Sheet::defaultCell()
const
599 return d->defaultCell;
602Format* Sheet::defaultFormat()
604 return d->defaultFormat;
607const Format* Sheet::defaultFormat()
const
609 return d->defaultFormat;
612const ColumnFormat* Sheet::columnFormat(
int _column )
const
614 const ColumnFormat *p = d->columns.lookup( _column );
618 return d->defaultColumnFormat;
621ColumnFormat* Sheet::columnFormat(
int _column )
623 ColumnFormat *p = d->columns.lookup( _column );
627 return d->defaultColumnFormat;
630const RowFormat* Sheet::rowFormat(
int _row )
const
632 const RowFormat *p = d->rows.lookup( _row );
636 return d->defaultRowFormat;
639RowFormat* Sheet::rowFormat(
int _row )
641 RowFormat *p = d->rows.lookup( _row );
645 return d->defaultRowFormat;
648Value Sheet::value (
int col,
int row)
const
650 Cell *cell = d->cells.lookup (col, row);
652 return cell->
value ();
657Value Sheet::valueRange (
int col1,
int row1,
658 int col2,
int row2)
const
660 return d->cells.valueRange (col1, row1, col2, row2);
663void Sheet::password( TQCString & passwd )
const
665 passwd = d->password;
668bool Sheet::isProtected()
const
670 return !d->password.isNull();
673void Sheet::setProtected( TQCString
const & passwd )
675 d->password = passwd;
678bool Sheet::checkPassword( TQCString
const & passwd )
const
680 return ( passwd == d->password );
683SheetPrint* Sheet::print()
const
688TQPainter& Sheet::painter()
693TQWidget* Sheet::widget()
const
698CellBinding* Sheet::firstCellBinding()
700 return d->cellBindings.first();
703CellBinding* Sheet::nextCellBinding()
705 return d->cellBindings.next();
708void Sheet::setDefaultHeight(
double height )
711 NO_MODIFICATION_POSSIBLE;
713 d->defaultRowFormat->setDblHeight( height );
716void Sheet::setDefaultWidth(
double width )
719 NO_MODIFICATION_POSSIBLE;
721 d->defaultColumnFormat->setDblWidth( width );
724double Sheet::sizeMaxX()
const
729double Sheet::sizeMaxY()
const
734int Sheet::maxColumn()
const
739int Sheet::maxRow()
const
744const TQPen& Sheet::emptyPen()
const
749const TQBrush& Sheet::emptyBrush()
const
751 return d->emptyBrush;
754const TQColor& Sheet::emptyColor()
const
756 return d->emptyColor;
761 return d->dependencies;
764int Sheet::numSelected()
const
768 TQPtrListIterator<EmbeddedObject> it( d->workbook->doc()->embeddedObjects() );
769 for ( ; it.current() ; ++it )
771 if( it.current()->sheet() ==
this && it.current()->isSelected() )
778int Sheet::leftColumn(
double _xpos,
double &_left,
779 const Canvas *_canvas )
const
783 _xpos += _canvas->xOffset();
784 _left = -_canvas->xOffset();
790 double x = columnFormat( col )->dblWidth( _canvas );
794 if ( col >= KS_colMax )
796 kdDebug(36001) <<
"Sheet:leftColumn: invalid column (col: " << col + 1 <<
")" << endl;
797 return KS_colMax + 1;
799 _left += columnFormat( col )->dblWidth( _canvas );
801 x += columnFormat( col )->dblWidth( _canvas );
807int Sheet::rightColumn(
double _xpos,
const Canvas *_canvas )
const
810 _xpos += _canvas->xOffset();
817 if ( col > KS_colMax )
819 kdDebug(36001) <<
"Sheet:rightColumn: invalid column (col: " << col <<
")" << endl;
820 return KS_colMax + 1;
822 x += columnFormat( col )->dblWidth( _canvas );
829TQRect Sheet::visibleRect( Canvas
const *
const _canvas )
const
841 y += _canvas->yOffset() * _canvas->zoom();
842 x += _canvas->xOffset() * _canvas->zoom();
843 width = _canvas->width();
844 height = _canvas->height();
847 double yn = rowFormat( top )->dblHeight( _canvas );
850 if ( top >= KS_rowMax )
854 yn += rowFormat( top )->dblHeight( _canvas );
857 int bottom = top + 1;
862 if ( bottom > KS_rowMax )
866 yn += rowFormat( bottom )->dblHeight( _canvas );
869 double xn = columnFormat( left )->dblWidth( _canvas );
872 if ( left >= KS_colMax )
876 xn += columnFormat( left )->dblWidth( _canvas );
880 int right = left + 1;
884 if ( right > KS_colMax )
888 xn += columnFormat( right )->dblWidth( _canvas );
892 return TQRect( left, top, right - left + 1, bottom - top + 1 );
895int Sheet::topRow(
double _ypos,
double & _top,
896 const Canvas *_canvas )
const
900 _ypos += _canvas->yOffset();
901 _top = -_canvas->yOffset();
907 double y = rowFormat( row )->dblHeight( _canvas );
911 if ( row >= KS_rowMax )
913 kdDebug(36001) <<
"Sheet:topRow: invalid row (row: " << row + 1 <<
")" << endl;
914 return KS_rowMax + 1;
916 _top += rowFormat( row )->dblHeight( _canvas );
918 y += rowFormat( row )->dblHeight( _canvas );
924int Sheet::bottomRow(
double _ypos,
const Canvas *_canvas )
const
927 _ypos += _canvas->yOffset();
934 if ( row > KS_rowMax )
936 kdDebug(36001) <<
"Sheet:bottomRow: invalid row (row: " << row <<
")" << endl;
937 return KS_rowMax + 1;
939 y += rowFormat( row )->dblHeight( _canvas );
946double Sheet::dblColumnPos(
int _col,
const Canvas *_canvas )
const
950 x -= _canvas->xOffset();
951 for (
int col = 1; col < _col; col++ )
954 if ( col > KS_colMax )
956 kdDebug(36001) <<
"Sheet:columnPos: invalid column (col: " << col <<
")" << endl;
960 x += columnFormat( col )->dblWidth( _canvas );
966int Sheet::columnPos(
int _col,
const Canvas *_canvas )
const
968 return (
int)dblColumnPos( _col, _canvas );
972double Sheet::dblRowPos(
int _row,
const Canvas *_canvas )
const
976 y -= _canvas->yOffset();
978 for (
int row = 1 ; row < _row ; row++ )
981 if ( row > KS_rowMax )
983 kdDebug(36001) <<
"Sheet:rowPos: invalid row (row: " << row <<
")" << endl;
987 y += rowFormat( row )->dblHeight( _canvas );
993int Sheet::rowPos(
int _row,
const Canvas *_canvas )
const
995 return (
int)dblRowPos( _row, _canvas );
999void Sheet::adjustSizeMaxX (
double _x )
1004void Sheet::adjustSizeMaxY (
double _y )
1009Cell* Sheet::visibleCellAt(
int _column,
int _row,
bool _scrollbar_update )
1011 Cell* cell = cellAt( _column, _row, _scrollbar_update );
1018Cell* Sheet::firstCell()
const
1020 return d->cells.firstCell();
1023RowFormat* Sheet::firstRow()
const
1025 return d->rows.first();
1028ColumnFormat* Sheet::firstCol()
const
1030 return d->columns.first();
1033Cell* Sheet::cellAt(
int _column,
int _row )
const
1035 Cell *p = d->cells.lookup( _column, _row );
1039 return d->defaultCell;
1042Cell* Sheet::cellAt(
int _column,
int _row,
bool _scrollbar_update )
1044 if ( _scrollbar_update && d->scrollBarUpdates )
1046 checkRangeHBorder( _column );
1047 checkRangeVBorder( _row );
1050 Cell *p = d->cells.lookup( _column, _row );
1054 return d->defaultCell;
1057ColumnFormat* Sheet::nonDefaultColumnFormat(
int _column,
bool force_creation )
1059 ColumnFormat *p = d->columns.lookup( _column );
1060 if ( p != 0L || !force_creation )
1063 p =
new ColumnFormat(
this, _column );
1065 p->setDblWidth( d->defaultColumnFormat->dblWidth() );
1067 d->columns.insertElement( p, _column );
1072RowFormat* Sheet::nonDefaultRowFormat(
int _row,
bool force_creation )
1074 RowFormat *p = d->rows.lookup( _row );
1075 if ( p != 0L || !force_creation )
1078 p =
new RowFormat(
this, _row );
1080 p->setDblHeight( d->defaultRowFormat->dblHeight() );
1082 d->rows.insertElement( p, _row );
1087Cell* Sheet::nonDefaultCell(
int _column,
int _row,
1088 bool _scrollbar_update, Style * _style )
1094 if ( _scrollbar_update && d->scrollBarUpdates )
1096 checkRangeHBorder( _column );
1097 checkRangeVBorder( _row );
1100 Cell * p = d->cells.lookup( _column, _row );
1107 cell =
new Cell(
this, _style, _column, _row );
1109 cell =
new Cell(
this, _column, _row );
1116void Sheet::setText(
int _row,
int _column,
const TQString& _text,
bool asString )
1118 ProtectedCheck prot;
1119 prot.setSheet (
this);
1120 prot.add (TQPoint (_column, _row));
1122 NO_MODIFICATION_POSSIBLE;
1124 DataManipulator *dm =
new DataManipulator ();
1125 dm->setSheet (
this);
1126 dm->setValue (_text);
1127 dm->setParsing (!asString);
1128 dm->add (TQPoint (_column, _row));
1144 if(_text.at(0)==
'!')
1145 emit sig_updateView(
this, Region(_column,_row,_column,_row) );
1148void Sheet::setArrayFormula (Selection *selectionInfo,
const TQString &_text)
1151 ProtectedCheck prot;
1152 prot.setSheet (
this);
1153 prot.add (*selectionInfo);
1155 NO_MODIFICATION_POSSIBLE;
1158 ArrayFormulaManipulator *afm =
new ArrayFormulaManipulator;
1159 afm->setSheet (
this);
1160 afm->setText (_text);
1161 afm->add (*selectionInfo);
1191void Sheet::setLayoutDirtyFlag()
1193 Cell * c = d->cells.firstCell();
1194 for( ; c; c = c->nextCell() )
1195 c->setLayoutDirtyFlag();
1198void Sheet::setCalcDirtyFlag()
1200 Cell* c = d->cells.firstCell();
1201 for( ; c; c = c->nextCell() )
1203 if ( !(c->isObscured() && c->isPartOfMerged()) )
1204 c->setCalcDirtyFlag();
1208void Sheet::updateAllDependencies()
1210 for (Cell* cell = d->cells.firstCell() ; cell ; cell = cell->nextCell())
1213 cellLocation.setSheet(cell->
sheet());
1214 cellLocation.setRow(cell->
row());
1215 cellLocation.setColumn(cell->
column());
1216 d->dependencies->cellChanged(cellLocation);
1225void Sheet::recalc(
bool force )
1227 ElapsedTime et(
"Recalculating " + d->name, ElapsedTime::PrintOnlyTime );
1234 if ( !getAutoCalc() && !force )
1240 if ( !getAutoCalc() )
1241 updateAllDependencies();
1253 c = d->cells.firstCell();
1254 for( ; c; c = c->nextCell() )
1259 c = d->cells.firstCell();
1260 for( ; c; c = c->nextCell() )
1265 if (cur*100/count != percent) {
1266 percent = cur*100/count;
1272 emit sig_updateView(
this );
1275void Sheet::valueChanged (Cell *cell)
1282 c.setRow (cell->
row());
1283 c.setColumn (cell->
column());
1287 if ( getAutoCalc() )
1288 d->dependencies->cellChanged (c);
1389class UndoAction* Sheet::CellWorkerTypeA::createUndoAction( Doc* doc, Sheet* sheet,
const KSpread::Region& region )
1391 TQString title = getUndoTitle();
1392 return new UndoCellFormat( doc, sheet, region, title );
1542Sheet::SelectionType Sheet::workOnCells( Selection* selectionInfo, CellWorker & worker )
1544 Sheet::SelectionType result;
1546 doc()->emitBeginOperation();
1549 bool selected = !(selectionInfo->isSingular());
1552 if ( !doc()->undoLocked() )
1554 UndoAction* undo = worker.createUndoAction(doc(),
this, *selectionInfo);
1558 doc()->addCommand( undo );
1562 Region::ConstIterator endOfList(selectionInfo->constEnd());
1563 for (Region::ConstIterator it = selectionInfo->constBegin(); it != endOfList; ++it)
1566 TQRect range = (*it)->rect().normalize();
1568 int top = range.top();
1569 int left = range.left();
1570 int bottom = range.bottom();
1571 int right = range.right();
1575 Style * s = doc()->styleManager()->defaultStyle();
1577 if ( !worker.type_B && selected && util_isColumnSelected(range) )
1579 for ( RowFormat * rw = d->rows.first(); rw; rw = rw->next() )
1581 if ( worker.testCondition( rw ) )
1583 for (
int col = left; col <= right; ++col )
1585 cell = nonDefaultCell( col, rw->row(),
false, s );
1592 if ( selected && util_isRowSelected(range) )
1594 for (
int row = top; row <= bottom; ++row )
1596 cell = getFirstCellRow( row );
1599 if ( worker.testCondition( cell ) )
1601 if ( worker.type_B )
1602 worker.doWork( cell,
false, cell->
column(), row );
1604 worker.prepareCell( cell );
1606 cell = getNextCellRight( cell->
column(), row );
1610 if ( worker.type_B )
1618 for (
int i = top; i <= bottom; ++i )
1620 RowFormat * rw = nonDefaultRowFormat(i);
1621 worker.doWork( rw );
1624 for (
int row = top; row <= bottom; ++row )
1626 cell = getFirstCellRow( row );
1629 if ( worker.testCondition( cell ) )
1631 worker.doWork( cell,
false, cell->
column(), row );
1633 cell = getNextCellRight( cell->
column(), row );
1638 result = CompleteRows;
1641 else if ( selected && util_isColumnSelected(range) )
1643 for (
int col = range.left(); col <= right; ++col )
1645 cell = getFirstCellColumn( col );
1648 if ( worker.testCondition( cell ) )
1650 if ( worker.type_B )
1651 worker.doWork( cell,
false, col, cell->
row() );
1653 worker.prepareCell( cell );
1656 cell = getNextCellDown( col, cell->
row() );
1660 if ( worker.type_B )
1667 for (
int i = left; i <= right; ++i )
1669 ColumnFormat * cl = nonDefaultColumnFormat( i );
1670 worker.doWork( cl );
1673 for ( RowFormat * rw = d->rows.first(); rw; rw = rw->next() )
1675 if ( worker.testCondition( rw ) )
1677 for (
int i = left; i <= right; ++i )
1679 cell = nonDefaultCell( i, rw->row(),
false, s );
1680 worker.doWork( cell,
false, i, rw->row() );
1685 result = CompleteColumns;
1690 for (
int x = left; x <= right; ++x )
1692 enableScrollBarUpdates(
false);
1693 for (
int y = top; y <= bottom; ++y )
1695 cell = cellAt( x, y );
1696 if ( worker.testCondition( cell ) )
1698 if ( cell == d->defaultCell && worker.create_if_default )
1700 cell =
new Cell(
this, s, x, y );
1703 if ( cell != d->defaultCell )
1706 worker.doWork( cell,
true, x, y );
1710 enableScrollBarUpdates(
true);
1711 checkRangeVBorder(bottom);
1713 checkRangeHBorder(right);
1714 result = CellRegion;
1720 emit sig_updateView(
this );
1722 if (worker.emit_signal)
1724 emit sig_updateView(
this, *selectionInfo );
1730void Sheet::setSelectionFont( Selection* selectionInfo,
1731 const char *_font,
int _size,
1732 signed char _bold,
signed char _italic,
1733 signed char _underline,
signed char _strike)
1735 FontManipulator* manipulator =
new FontManipulator();
1736 manipulator->setSheet(
this);
1737 manipulator->setProperty(Format::PFont);
1738 manipulator->setFontFamily(_font);
1739 manipulator->setFontSize(_size);
1740 manipulator->setFontBold(_bold);
1741 manipulator->setFontItalic(_italic);
1742 manipulator->setFontStrike(_strike);
1743 manipulator->setFontUnderline(_underline);
1744 manipulator->add(*selectionInfo);
1745 manipulator->execute();
1748void Sheet::setSelectionSize(Selection* selectionInfo,
1754 TQPoint marker(selectionInfo->marker());
1756 size = c->format()->textFontSize(marker.x(), marker.y());
1758 FontManipulator* manipulator =
new FontManipulator();
1759 manipulator->setSheet(
this);
1760 manipulator->setProperty(Format::PFont);
1761 manipulator->setFontSize(_size+size);
1762 manipulator->add(*selectionInfo);
1763 manipulator->execute();
1767struct SetSelectionUpperLowerWorker :
public Sheet::CellWorker {
1770 SetSelectionUpperLowerWorker(
int type, Sheet * s )
1771 : Sheet::CellWorker( false ), _type( type ), _s( s ) { }
1773 class UndoAction* createUndoAction( Doc* doc, Sheet* sheet,
const KSpread::Region& region )
1775 return new UndoChangeAreaTextCell( doc, sheet, region );
1777 bool testCondition( Cell* c ) {
1778 return ( !c->value().isNumber() && !c->value().isBoolean() &&!c->isFormula() && !c->isDefault()
1779 && !c->text().isEmpty() && c->text()[0] !=
'*' && c->text()[0] !=
'!'
1780 && !c->isPartOfMerged() );
1782 void doWork( Cell* cell,
bool,
int,
int )
1784 cell->setDisplayDirtyFlag();
1786 cell->setCellText( (cell->text().lower()));
1787 else if ( _type == 1 )
1788 cell->setCellText( (cell->text().upper()));
1789 cell->clearDisplayDirtyFlag();
1793void Sheet::setSelectionUpperLower( Selection* selectionInfo,
1796 SetSelectionUpperLowerWorker w( _type,
this );
1797 workOnCells( selectionInfo, w );
1801struct SetSelectionFirstLetterUpperWorker :
public Sheet::CellWorker
1805 SetSelectionFirstLetterUpperWorker( Sheet * s )
1806 : Sheet::CellWorker( false ), _s( s ) { }
1808 class UndoAction* createUndoAction( Doc* doc, Sheet* sheet,
const KSpread::Region& region ) {
1809 return new UndoChangeAreaTextCell( doc, sheet, region );
1811 bool testCondition( Cell* c ) {
1812 return ( !c->value().isNumber() && !c->value().isBoolean() &&!c->isFormula() && !c->isDefault()
1813 && !c->text().isEmpty() && c->text()[0] !=
'*' && c->text()[0] !=
'!'
1814 && !c->isPartOfMerged() );
1816 void doWork( Cell* cell,
bool,
int,
int )
1819 cell->setDisplayDirtyFlag();
1820 TQString tmp = cell->text();
1821 int len = tmp.length();
1822 cell->setCellText( (tmp.at(0).upper()+tmp.right(len-1)) );
1823 cell->clearDisplayDirtyFlag();
1827void Sheet::setSelectionfirstLetterUpper( Selection* selectionInfo)
1829 SetSelectionFirstLetterUpperWorker w(
this );
1830 workOnCells( selectionInfo, w );
1834struct SetSelectionVerticalTextWorker :
public Sheet::CellWorker {
1836 SetSelectionVerticalTextWorker(
bool b ) : Sheet::CellWorker( ), _b( b ) { }
1838 class UndoAction* createUndoAction( Doc* doc, Sheet* sheet,
const KSpread::Region& region ) {
1839 TQString title=i18n(
"Vertical Text");
1840 return new UndoCellFormat( doc, sheet, region, title );
1842 bool testCondition( Cell* cell ) {
1843 return ( !cell->isPartOfMerged() );
1845 void doWork( Cell* cell,
bool,
int,
int ) {
1846 cell->setDisplayDirtyFlag();
1847 cell->format()->setVerticalText( _b );
1848 cell->format()->setMultiRow(
false );
1849 cell->format()->setAngle( 0 );
1850 cell->clearDisplayDirtyFlag();
1854void Sheet::setSelectionVerticalText( Selection* selectionInfo,
1857 SetSelectionVerticalTextWorker w( _b );
1858 workOnCells( selectionInfo, w );
1862struct SetSelectionCommentWorker :
public Sheet::CellWorker {
1864 SetSelectionCommentWorker( TQString comment ) : Sheet::CellWorker( ), _comment( comment ) { }
1866 class UndoAction* createUndoAction( Doc* doc, Sheet* sheet,
const KSpread::Region& region ) {
1867 TQString title=i18n(
"Add Comment");
1868 return new UndoCellFormat( doc, sheet, region, title );
1870 bool testCondition( Cell* cell ) {
1871 return ( !cell->isPartOfMerged() );
1873 void doWork( Cell* cell,
bool,
int,
int ) {
1874 cell->setDisplayDirtyFlag();
1875 cell->format()->setComment( _comment );
1876 cell->clearDisplayDirtyFlag();
1880void Sheet::setSelectionComment( Selection* selectionInfo,
1881 const TQString &_comment)
1883 SetSelectionCommentWorker w( _comment );
1884 workOnCells( selectionInfo, w );
1888void Sheet::setSelectionAngle( Selection* selectionInfo,
1891 AngleManipulator* manipulator =
new AngleManipulator();
1892 manipulator->setSheet(
this);
1893 manipulator->setProperty(Format::PAngle);
1894 manipulator->setAngle(_value);
1895 manipulator->add(*selectionInfo);
1896 manipulator->execute();
1899struct SetSelectionRemoveCommentWorker :
public Sheet::CellWorker {
1900 SetSelectionRemoveCommentWorker( ) : Sheet::CellWorker( false ) { }
1902 class UndoAction* createUndoAction( Doc* doc, Sheet* sheet,
const KSpread::Region& region ) {
1903 TQString title=i18n(
"Remove Comment");
1904 return new UndoCellFormat( doc, sheet, region, title );
1906 bool testCondition( Cell* cell ) {
1907 return ( !cell->isPartOfMerged() );
1909 void doWork( Cell* cell,
bool,
int,
int ) {
1910 cell->setDisplayDirtyFlag();
1911 cell->format()->setComment(
"" );
1912 cell->clearDisplayDirtyFlag();
1916void Sheet::setSelectionRemoveComment( Selection* selectionInfo )
1918 if (areaIsEmpty(*selectionInfo, Comment))
1921 SetSelectionRemoveCommentWorker w;
1922 workOnCells( selectionInfo, w );
1926void Sheet::setSelectionTextColor( Selection* selectionInfo,
1927 const TQColor &tb_Color )
1929 FontColorManipulator* manipulator =
new FontColorManipulator();
1930 manipulator->setSheet(
this);
1931 manipulator->setProperty(Format::PTextPen);
1932 manipulator->setTextColor(tb_Color);
1933 manipulator->add(*selectionInfo);
1934 manipulator->execute();
1937void Sheet::setSelectionbgColor( Selection* selectionInfo,
1938 const TQColor &bg_Color )
1940 BackgroundColorManipulator* manipulator =
new BackgroundColorManipulator();
1941 manipulator->setSheet(
this);
1942 manipulator->setProperty(Format::PBackgroundColor);
1943 manipulator->setBackgroundColor(bg_Color);
1944 manipulator->add(*selectionInfo);
1945 manipulator->execute();
1949struct SetSelectionBorderColorWorker :
public Sheet::CellWorker {
1950 const TQColor& bd_Color;
1951 SetSelectionBorderColorWorker(
const TQColor& _bd_Color ) : Sheet::CellWorker( false ), bd_Color( _bd_Color ) { }
1953 class UndoAction* createUndoAction( Doc* doc, Sheet* sheet,
const KSpread::Region& region ) {
1954 TQString title=i18n(
"Change Border Color");
1955 return new UndoCellFormat( doc, sheet, region, title );
1957 bool testCondition( Cell* cell ) {
1958 return ( !cell->isPartOfMerged() );
1960 void doWork( Cell* cell,
bool,
int,
int ) {
1961 cell->setDisplayDirtyFlag();
1962 int it_Row = cell->row();
1963 int it_Col = cell->column();
1964 if ( cell->format()->topBorderStyle( it_Row, it_Col )!=TQt::NoPen )
1965 cell->format()->setTopBorderColor( bd_Color );
1966 if ( cell->format()->leftBorderStyle( it_Row, it_Col )!=TQt::NoPen )
1967 cell->format()->setLeftBorderColor( bd_Color );
1968 if ( cell->format()->fallDiagonalStyle( it_Row, it_Col )!=TQt::NoPen )
1969 cell->format()->setFallDiagonalColor( bd_Color );
1970 if ( cell->format()->goUpDiagonalStyle( it_Row, it_Col )!=TQt::NoPen )
1971 cell->format()->setGoUpDiagonalColor( bd_Color );
1972 if ( cell->format()->bottomBorderStyle( it_Row, it_Col )!=TQt::NoPen )
1973 cell->format()->setBottomBorderColor( bd_Color );
1974 if ( cell->format()->rightBorderStyle( it_Row, it_Col )!=TQt::NoPen )
1975 cell->format()->setRightBorderColor( bd_Color );
1976 cell->clearDisplayDirtyFlag();
1980void Sheet::setSelectionBorderColor( Selection* selectionInfo,
1981 const TQColor &bd_Color )
1983 SetSelectionBorderColorWorker w( bd_Color );
1984 workOnCells( selectionInfo, w );
1988void Sheet::setSeries(
const TQPoint &_marker,
double start,
double end,
double step, Series mode, Series type)
1990 doc()->emitBeginOperation();
2001 numberOfCells = (int) ((end - start) / step + 1);
2002 else if ( end <start )
2003 numberOfCells = (int) ((start - end) / step + 1);
2006 if (type == Geometric)
2012 numberOfCells = (int)( (log((
double)end) / log((
double)start)) +
2023 undoRegion.setLeft(_marker.x());
2024 undoRegion.setTop(_marker.y());
2037 if ( mode == Column )
2039 for ( y = _marker.y(); y <= (_marker.y() + numberOfCells - 1) && y <= KS_rowMax; y++ )
2041 cell = cellAt( _marker.x(), y );
2047 undoRegion.setLeft(TQMIN(undoRegion.left(), cell->
column()));
2057 undoRegion.setRight( _marker.x() );
2058 undoRegion.setBottom( y - 1 );
2060 checkRangeVBorder( undoRegion.bottom() );
2062 else if(mode == Row)
2064 for ( x = _marker.x(); x <=(_marker.x() + numberOfCells - 1) && x <= KS_colMax; x++ )
2068 cell = cellAt( x,_marker.y(),
false );
2073 undoRegion.setTop(TQMIN(undoRegion.top(), cell->
row()));
2078 undoRegion.setBottom( _marker.y() );
2079 undoRegion.setRight( x - 1 );
2081 checkRangeHBorder( undoRegion.right() );
2084 kdDebug() <<
"Saving undo information" << endl;
2086 if ( !doc()->undoLocked() )
2088 UndoChangeAreaTextCell *undo =
new
2089 UndoChangeAreaTextCell( doc(),
this, undoRegion );
2090 doc()->addCommand( undo );
2093 kdDebug() <<
"Saving undo information done" << endl;
2095 setRegionPaintDirty( undoRegion );
2102 Style * s = doc()->styleManager()->defaultStyle();
2103 if (step >= 0 && start < end)
2105 for ( incr = start; incr <= end; )
2107 cell = nonDefaultCell( x, y,
false, s );
2116 cell->setNumber( incr );
2124 if ( y > KS_rowMax )
2129 else if (mode == Row)
2136 if ( x > KS_colMax )
2143 kdDebug(36001) <<
"Error in Series::mode" << endl;
2149 else if (type == Geometric)
2153 kdDebug(36001) <<
"Error in Series::type" << endl;
2159 if (step >= 0 && start > end)
2161 for ( incr = start; incr >= end; )
2163 cell = nonDefaultCell( x, y,
false, s );
2171 cell->setNumber( incr );
2179 if ( y > KS_rowMax )
2184 else if (mode == Row)
2191 if ( x > KS_colMax )
2198 kdDebug(36001) <<
"Error in Series::mode" << endl;
2204 else if (type == Geometric)
2208 kdDebug(36001) <<
"Error in Series::type" << endl;
2215 for ( incr = start; incr <= end; )
2217 cell = nonDefaultCell( x, y,
false, s );
2225 cell->setNumber( incr );
2233 if ( y > KS_rowMax )
2238 else if (mode == Row)
2245 if ( x > KS_colMax )
2252 kdDebug(36001) <<
"Error in Series::mode" << endl;
2258 else if (type == Geometric)
2269 kdDebug(36001) <<
"Error in Series::type" << endl;
2277 emit sig_updateView(
this );
2281struct SetSelectionPercentWorker :
public Sheet::CellWorkerTypeA
2284 SetSelectionPercentWorker(
bool _b ) : b( _b ) { }
2286 TQString getUndoTitle() {
return i18n(
"Format Percent"); }
2287 bool testCondition( RowFormat* ) {
2291 void doWork( RowFormat* rw ) {
2293 rw->setFormatType( b ? Percentage_format : Generic_format);
2295 void doWork( ColumnFormat* cl ) {
2296 cl->setFormatType( b ? Percentage_format : Generic_format);
2298 void prepareCell( Cell* cell ) {
2299 cell->format()->clearProperty(Format::PFormatType);
2300 cell->format()->clearNoFallBackProperties( Format::PFormatType );
2302 bool testCondition( Cell* cell ) {
2303 return ( !cell->isPartOfMerged() );
2305 void doWork( Cell* cell,
bool cellRegion,
int,
int ) {
2307 cell->setDisplayDirtyFlag();
2308 cell->format()->setFormatType( b ? Percentage_format : Generic_format);
2310 cell->clearDisplayDirtyFlag();
2314void Sheet::setSelectionPercent( Selection* selectionInfo,
bool b )
2316 SetSelectionPercentWorker w( b );
2317 workOnCells( selectionInfo, w );
2320void Sheet::slotAreaModified (
const TQString &name)
2322 d->dependencies->areaModified (name);
2326void Sheet::refreshRemoveAreaName(
const TQString & _areaName)
2328 Cell * c = d->cells.firstCell();
2329 TQString tmp =
"'" + _areaName +
"'";
2330 for( ;c ; c = c->nextCell() )
2332 if ( c->isFormula() )
2334 if (c->text().find(tmp) != -1)
2336 if ( !c->makeFormula() )
2337 kdError(36001) <<
"ERROR: Syntax ERROR" << endl;
2343void Sheet::refreshChangeAreaName(
const TQString & _areaName)
2345 Cell * c = d->cells.firstCell();
2346 TQString tmp =
"'" + _areaName +
"'";
2347 for( ;c ; c = c->nextCell() )
2349 if ( c->isFormula() )
2351 if (c->text().find(tmp) != -1)
2353 if ( !c->makeFormula() )
2354 kdError(36001) <<
"ERROR: Syntax ERROR" << endl;
2358 c->setCalcDirtyFlag();
2365void Sheet::changeCellTabName( TQString
const & old_name, TQString
const & new_name )
2367 Cell* c = d->cells.firstCell();
2368 for( ;c; c = c->nextCell() )
2370 if( c->isFormula() )
2372 if(c->text().find(old_name)!=-1)
2374 int nb = c->text().contains(old_name+
"!");
2375 TQString tmp=old_name+
"!";
2376 int len = tmp.length();
2379 for(
int i=0; i<nb; i++ )
2381 int pos = tmp.find( old_name+
"!" );
2382 tmp.replace( pos, len, new_name+
"!" );
2384 c->setCellText(tmp);
2390bool Sheet::shiftRow(
const TQRect &rect,
bool makeUndo )
2392 UndoInsertCellRow * undo = 0;
2393 if ( !doc()->undoLocked() &&makeUndo)
2395 undo =
new UndoInsertCellRow( doc(),
this, rect );
2396 doc()->addCommand( undo );
2401 for(
int i=rect.top(); i<=rect.bottom(); i++ )
2403 for(
int j=0; j<=(rect.right()-rect.left()); j++ )
2405 result = d->cells.shiftRow( TQPoint(rect.left(),i) );
2410 TQPtrListIterator<Sheet> it( workbook()->sheetList() );
2411 for( ; it.current(); ++it )
2413 for(
int i = rect.top(); i <= rect.bottom(); i++ )
2414 it.current()->changeNameCellRef( TQPoint( rect.left(), i ),
false,
2415 Sheet::ColumnInsert, name(),
2416 ( rect.right() - rect.left() + 1),
2419 refreshChart(TQPoint(rect.left(),rect.top()),
false, Sheet::ColumnInsert);
2420 refreshMergedCell();
2422 emit sig_updateView(
this );
2427bool Sheet::shiftColumn(
const TQRect& rect,
bool makeUndo )
2429 UndoInsertCellCol * undo = 0;
2430 if ( !doc()->undoLocked() &&makeUndo)
2432 undo =
new UndoInsertCellCol( doc(),
this,rect);
2433 doc()->addCommand( undo );
2438 for(
int i =rect.left(); i<=rect.right(); i++ )
2440 for(
int j=0; j<=(rect.bottom()-rect.top()); j++ )
2442 result = d->cells.shiftColumn( TQPoint(i,rect.top()) );
2448 TQPtrListIterator<Sheet> it( workbook()->sheetList() );
2449 for( ; it.current(); ++it )
2451 for(
int i=rect.left();i<=rect.right();i++)
2452 it.current()->changeNameCellRef( TQPoint( i, rect.top() ),
false,
2453 Sheet::RowInsert, name(),
2454 ( rect.bottom() - rect.top() + 1 ),
2457 refreshChart(TQPoint(rect.left(),rect.top()),
false, Sheet::RowInsert);
2458 refreshMergedCell();
2460 emit sig_updateView(
this );
2465void Sheet::unshiftColumn(
const TQRect & rect,
bool makeUndo )
2467 UndoRemoveCellCol * undo = 0;
2468 if ( !doc()->undoLocked() && makeUndo )
2470 undo =
new UndoRemoveCellCol( doc(),
this, rect );
2471 doc()->addCommand( undo );
2474 for(
int i =rect.top();i<=rect.bottom();i++)
2475 for(
int j=rect.left();j<=rect.right();j++)
2476 d->cells.remove(j,i);
2478 for(
int i =rect.left();i<=rect.right();i++)
2479 for(
int j=0;j<=(rect.bottom()-rect.top());j++)
2480 d->cells.unshiftColumn( TQPoint(i,rect.top()) );
2482 TQPtrListIterator<Sheet> it( workbook()->sheetList() );
2483 for( ; it.current(); ++it )
2484 for(
int i=rect.left();i<=rect.right();i++)
2485 it.current()->changeNameCellRef( TQPoint( i, rect.top() ),
false,
2486 Sheet::RowRemove, name(),
2487 ( rect.bottom() - rect.top() + 1 ),
2490 refreshChart( TQPoint(rect.left(),rect.top()),
false, Sheet::RowRemove );
2491 refreshMergedCell();
2493 emit sig_updateView(
this );
2496void Sheet::unshiftRow(
const TQRect & rect,
bool makeUndo )
2498 UndoRemoveCellRow * undo = 0;
2499 if ( !doc()->undoLocked() && makeUndo )
2501 undo =
new UndoRemoveCellRow( doc(),
this, rect );
2502 doc()->addCommand( undo );
2504 for(
int i =rect.top();i<=rect.bottom();i++)
2505 for(
int j=rect.left();j<=rect.right();j++)
2506 d->cells.remove(j,i);
2508 for(
int i =rect.top();i<=rect.bottom();i++)
2509 for(
int j=0;j<=(rect.right()-rect.left());j++)
2510 d->cells.unshiftRow( TQPoint(rect.left(),i) );
2512 TQPtrListIterator<Sheet> it( workbook()->sheetList() );
2513 for( ; it.current(); ++it )
2514 for(
int i=rect.top();i<=rect.bottom();i++)
2515 it.current()->changeNameCellRef( TQPoint( rect.left(), i ),
false,
2516 Sheet::ColumnRemove, name(),
2517 ( rect.right() - rect.left() + 1 ),
2520 refreshChart(TQPoint(rect.left(),rect.top()),
false, Sheet::ColumnRemove );
2521 refreshMergedCell();
2523 emit sig_updateView(
this );
2526bool Sheet::insertColumn(
int col,
int nbCol,
bool makeUndo )
2528 UndoInsertColumn * undo = 0;
2529 if ( !doc()->undoLocked() && makeUndo)
2531 undo =
new UndoInsertColumn( doc(),
this, col, nbCol );
2532 doc()->addCommand( undo );
2537 for(
int i=0; i<=nbCol; i++ )
2540 d->sizeMaxX -= columnFormat( KS_colMax )->dblWidth();
2542 result = d->cells.insertColumn( col );
2543 d->columns.insertColumn( col );
2548 d->sizeMaxX += columnFormat( col+i )->dblWidth();
2551 TQPtrListIterator<Sheet> it( workbook()->sheetList() );
2552 for( ; it.current(); ++it )
2553 it.current()->changeNameCellRef( TQPoint( col, 1 ),
true,
2554 Sheet::ColumnInsert, name(),
2558 d->print->insertColumn( col, nbCol );
2560 refreshChart( TQPoint( col, 1 ),
true, Sheet::ColumnInsert );
2561 refreshMergedCell();
2563 emit sig_updateHBorder(
this );
2564 emit sig_updateView(
this );
2569bool Sheet::insertRow(
int row,
int nbRow,
bool makeUndo )
2571 UndoInsertRow *undo = 0;
2572 if ( !doc()->undoLocked() && makeUndo)
2574 undo =
new UndoInsertRow( doc(),
this, row, nbRow );
2575 doc()->addCommand( undo );
2580 for(
int i=0; i<=nbRow; i++ )
2583 d->sizeMaxY -= rowFormat( KS_rowMax )->dblHeight();
2585 result = d->cells.insertRow( row );
2586 d->rows.insertRow( row );
2591 d->sizeMaxY += rowFormat( row )->dblHeight();
2594 TQPtrListIterator<Sheet> it( workbook()->sheetList() );
2595 for( ; it.current(); ++it )
2596 it.current()->changeNameCellRef( TQPoint( 1, row ),
true,
2597 Sheet::RowInsert, name(),
2601 d->print->insertRow( row, nbRow );
2603 refreshChart( TQPoint( 1, row ),
true, Sheet::RowInsert );
2604 refreshMergedCell();
2606 emit sig_updateVBorder(
this );
2607 emit sig_updateView(
this );
2612void Sheet::removeColumn(
int col,
int nbCol,
bool makeUndo )
2614 UndoRemoveColumn *undo = 0;
2615 if ( !doc()->undoLocked() && makeUndo)
2617 undo =
new UndoRemoveColumn( doc(),
this, col, nbCol );
2618 doc()->addCommand( undo );
2621 for (
int i = 0; i <= nbCol; ++i )
2624 d->sizeMaxX -= columnFormat( col )->dblWidth();
2626 d->cells.removeColumn( col );
2627 d->columns.removeColumn( col );
2630 d->sizeMaxX += columnFormat( KS_colMax )->dblWidth();
2633 TQPtrListIterator<Sheet> it( workbook()->sheetList() );
2634 for( ; it.current(); ++it )
2635 it.current()->changeNameCellRef( TQPoint( col, 1 ),
true,
2636 Sheet::ColumnRemove, name(),
2640 d->print->removeColumn( col, nbCol );
2642 refreshChart( TQPoint( col, 1 ),
true, Sheet::ColumnRemove );
2643 refreshMergedCell();
2645 emit sig_updateHBorder(
this );
2646 emit sig_updateView(
this );
2649void Sheet::removeRow(
int row,
int nbRow,
bool makeUndo )
2651 UndoRemoveRow *undo = 0;
2652 if ( !doc()->undoLocked() && makeUndo )
2654 undo =
new UndoRemoveRow( doc(),
this, row, nbRow );
2655 doc()->addCommand( undo );
2658 for(
int i=0; i<=nbRow; i++ )
2661 d->sizeMaxY -= rowFormat( row )->dblHeight();
2663 d->cells.removeRow( row );
2664 d->rows.removeRow( row );
2667 d->sizeMaxY += rowFormat( KS_rowMax )->dblHeight();
2670 TQPtrListIterator<Sheet> it( workbook()->sheetList() );
2671 for( ; it.current(); ++it )
2672 it.current()->changeNameCellRef( TQPoint( 1, row ),
true,
2673 Sheet::RowRemove, name(),
2677 d->print->removeRow( row, nbRow );
2679 refreshChart( TQPoint( 1, row ),
true, Sheet::RowRemove );
2680 refreshMergedCell();
2682 emit sig_updateVBorder(
this );
2683 emit sig_updateView(
this );
2686void Sheet::hideRow(
const Region& region)
2688 HideShowManipulator* manipulator =
new HideShowManipulator();
2689 manipulator->setSheet(
this);
2690 manipulator->setManipulateRows(
true);
2691 manipulator->add(region);
2692 manipulator->execute();
2695void Sheet::emitHideRow()
2697 emit sig_updateVBorder(
this );
2698 emit sig_updateView(
this );
2701void Sheet::showRow(
const Region& region)
2703 HideShowManipulator* manipulator =
new HideShowManipulator();
2704 manipulator->setSheet(
this);
2705 manipulator->setManipulateRows(
true);
2706 manipulator->setReverse(
true);
2707 manipulator->add(region);
2708 manipulator->execute();
2712void Sheet::hideColumn(
const Region& region)
2714 HideShowManipulator* manipulator =
new HideShowManipulator();
2715 manipulator->setSheet(
this);
2716 manipulator->setManipulateColumns(
true);
2717 manipulator->add(region);
2718 manipulator->execute();
2721void Sheet::emitHideColumn()
2723 emit sig_updateHBorder(
this );
2724 emit sig_updateView(
this );
2727void Sheet::showColumn(
const Region& region)
2729 HideShowManipulator* manipulator =
new HideShowManipulator();
2730 manipulator->setSheet(
this);
2731 manipulator->setManipulateColumns(
true);
2732 manipulator->setReverse(
true);
2733 manipulator->add(region);
2734 manipulator->execute();
2738void Sheet::refreshChart(
const TQPoint & pos,
bool fullRowOrColumn, ChangeRef ref)
2740 Cell * c = d->cells.firstCell();
2741 for( ;c; c = c->nextCell() )
2743 if ( (ref == ColumnInsert || ref == ColumnRemove) && fullRowOrColumn
2744 && c->column() >= (pos.x() - 1))
2746 if (c->updateChart())
2749 else if ( (ref == ColumnInsert || ref == ColumnRemove )&& !fullRowOrColumn
2750 && c->column() >= (pos.x() - 1) && c->row() == pos.y() )
2752 if (c->updateChart())
2755 else if ((ref == RowInsert || ref == RowRemove) && fullRowOrColumn
2756 && c->row() >= (pos.y() - 1))
2758 if (c->updateChart())
2761 else if ( (ref == RowInsert || ref == RowRemove) && !fullRowOrColumn
2762 && c->column() == pos.x() && c->row() >= (pos.y() - 1) )
2764 if (c->updateChart())
2774 for ( bind = firstCellBinding(); bind != 0L; bind = nextCellBinding() )
2776 bind->cellChanged( 0 );
2785void Sheet::refreshMergedCell()
2787 Cell* c = d->cells.firstCell();
2788 for( ;c; c = c->nextCell() )
2790 if(c->doesMergeCells())
2791 c->mergeCells( c->column(), c->row(), c->extraXCells(), c->extraYCells() );
2796void Sheet::changeNameCellRef(
const TQPoint & pos,
bool fullRowOrColumn,
2797 ChangeRef ref, TQString tabname,
int nbCol,
2798 UndoInsertRemoveAction * undo )
2800 bool correctDefaultSheetName = (tabname == name());
2801 Cell* c = d->cells.firstCell();
2802 for( ;c; c = c->nextCell() )
2804 if( c->isFormula() )
2806 TQString origText = c->text();
2811 bool correctSheetName = correctDefaultSheetName;
2814 for ( ; i < origText.length(); ++i )
2816 origCh = origText[i];
2817 if ( origCh !=
':' && origCh !=
'$' && !origCh.isLetter() )
2821 correctSheetName = correctDefaultSheetName;
2828 bool sheetNameFound =
false;
2829 for( ; ( i < origText.length() ) &&
2830 ( ( origText[i].isLetter() || origText[i].isDigit() || origText[i] ==
'$' ) ||
2831 ( sheetNameFound && origText[i].isSpace() ) )
2835 if ( origText[i] ==
'!' )
2836 sheetNameFound =
true;
2839 if ( origText[i] ==
'!' )
2841 newText += str +
'!';
2843 correctSheetName = ( newText.right( tabname.length()+1 ) == tabname+
"!" );
2849 if ( point.isValid() )
2851 int col = point.pos().x();
2852 int row = point.pos().y();
2856 if ( point.columnFixed() )
2859 if( ref == ColumnInsert
2861 && col + nbCol <= KS_colMax
2863 && ( fullRowOrColumn || row == pos.y() ) )
2867 else if( ref == ColumnRemove
2870 && ( fullRowOrColumn || row == pos.y() ) )
2878 if ( point.rowFixed() )
2881 if( ref == RowInsert
2883 && row + nbCol <= KS_rowMax
2885 && ( fullRowOrColumn || col == pos.x() ) )
2887 newPoint += TQString::number( row + nbCol );
2889 else if( ref == RowRemove
2892 && ( fullRowOrColumn || col == pos.x() ) )
2894 newPoint += TQString::number( row - nbCol );
2897 newPoint += TQString::number( row );
2899 if( correctSheetName &&
2900 ( ( ref == ColumnRemove
2902 && ( fullRowOrColumn || row == pos.y() ) ) ||
2905 && ( fullRowOrColumn || col == pos.x() ) ) ||
2906 ( ref == ColumnInsert
2907 && col + nbCol > KS_colMax
2909 && ( fullRowOrColumn || row == pos.y() ) ) ||
2911 && row + nbCol > KS_rowMax
2913 && ( fullRowOrColumn || col == pos.x() ) ) ) )
2915 newPoint =
"#" + i18n(
"Dependency") +
"!";
2919 newText += newPoint;
2923 kdDebug(36001) <<
"Copying (unchanged) : '" << str <<
"'" << endl;
2927 if ( i < origText.length() ) {
2928 newText += origText[i];
2929 if( origText[i] !=
':' )
2930 correctSheetName = correctDefaultSheetName;
2936 if ( error && undo != 0 )
2938 TQString formulaText = c->text();
2939 int origCol = c->column();
2940 int origRow = c->row();
2942 if ( ref == ColumnInsert && origCol >= pos.x() )
2944 if ( ref == RowInsert && origRow >= pos.y() )
2947 if ( ref == ColumnRemove && origCol >= pos.x() )
2949 if ( ref == RowRemove && origRow >= pos.y() )
2952 undo->saveFormulaReference(
this, origCol, origRow, formulaText );
2955 c->setCellText( newText );
2961void Sheet::replace(
const TQString &_find,
const TQString &_replace,
long options,
2964 Selection* selectionInfo = canvas->view()->selectionInfo();
2967 TQRect region( selectionInfo->selection() );
2968 TQPoint marker( selectionInfo->marker() );
2970 if (options & KReplaceDialog::SelectedText)
2974 if ( util_isRowSelected(region) )
2978 else if ( util_isColumnSelected(region) )
2985 region.setCoords( 1, 1, d->maxRow, d->maxColumn );
2990 KReplace dialog( _find, _replace, options );
2992 &dialog, TQ_SIGNAL( highlight(
const TQString &,
int,
int,
const TQRect & ) ),
2993 canvas, TQ_SLOT( highlight(
const TQString &,
int,
int,
const TQRect & ) ) );
2995 &dialog, TQ_SIGNAL( replace(
const TQString &,
int,
int,
int,
const TQRect & ) ),
2996 canvas, TQ_SLOT( replace(
const TQString &,
int,
int,
int,
const TQRect & ) ) );
2999 if ( !doc()->undoLocked() )
3001 UndoChangeAreaTextCell *undo =
new UndoChangeAreaTextCell( doc(),
this, region );
3002 doc()->addCommand( undo );
3005 TQRect cellRegion( 0, 0, 0, 0 );
3006 bool bck = options & KFindDialog::FindBackwards;
3008 int colStart = !bck ? region.left() : region.right();
3009 int colEnd = !bck ? region.right() : region.left();
3010 int rowStart = !bck ? region.top() :region.bottom();
3011 int rowEnd = !bck ? region.bottom() : region.top();
3012 if ( options & KFindDialog::FromCursor ) {
3013 colStart = marker.x();
3014 rowStart = marker.y();
3017 for (
int row = rowStart ; !bck ? row < rowEnd : row > rowEnd ; !bck ? ++row : --row )
3019 for(
int col = colStart ; !bck ? col < colEnd : col > colEnd ; !bck ? ++col : --col )
3021 cell = cellAt( col, row );
3024 TQString text = cell->
text();
3025 cellRegion.setTop( row );
3026 cellRegion.setLeft( col );
3027 if (!dialog.replace( text, cellRegion ))
3035void Sheet::borderBottom( Selection* selectionInfo,
const TQColor &_color )
3037 BorderManipulator* manipulator =
new BorderManipulator();
3038 manipulator->setSheet(
this);
3039 manipulator->setBottomBorderPen(TQPen(_color, 1, TQt::SolidLine));
3040 manipulator->add(*selectionInfo);
3041 manipulator->execute();
3044void Sheet::borderRight( Selection* selectionInfo,
const TQColor &_color )
3046 BorderManipulator* manipulator =
new BorderManipulator();
3047 manipulator->setSheet(
this);
3048 manipulator->setRightBorderPen(TQPen(_color, 1, TQt::SolidLine));
3049 manipulator->add(*selectionInfo);
3050 manipulator->execute();
3053void Sheet::borderLeft( Selection* selectionInfo,
const TQColor &_color )
3055 BorderManipulator* manipulator =
new BorderManipulator();
3056 manipulator->setSheet(
this);
3057 manipulator->setLeftBorderPen(TQPen(_color, 1, TQt::SolidLine));
3058 manipulator->add(*selectionInfo);
3059 manipulator->execute();
3062void Sheet::borderTop( Selection* selectionInfo,
const TQColor &_color )
3064 BorderManipulator* manipulator =
new BorderManipulator();
3065 manipulator->setSheet(
this);
3066 manipulator->setTopBorderPen(TQPen(_color, 1, TQt::SolidLine));
3067 manipulator->add(*selectionInfo);
3068 manipulator->execute();
3071void Sheet::borderOutline( Selection* selectionInfo,
const TQColor &_color )
3073 BorderManipulator* manipulator =
new BorderManipulator();
3074 manipulator->setSheet(
this);
3075 manipulator->setTopBorderPen(TQPen(_color, 1, TQt::SolidLine));
3076 manipulator->setBottomBorderPen(TQPen(_color, 1, TQt::SolidLine));
3077 manipulator->setLeftBorderPen(TQPen(_color, 1, TQt::SolidLine));
3078 manipulator->setRightBorderPen(TQPen(_color, 1, TQt::SolidLine));
3079 manipulator->add(*selectionInfo);
3080 manipulator->execute();
3083void Sheet::borderAll( Selection * selectionInfo,
3084 const TQColor & _color )
3086 BorderManipulator* manipulator =
new BorderManipulator();
3087 manipulator->setSheet(
this);
3088 manipulator->setTopBorderPen(TQPen(_color, 1, TQt::SolidLine));
3089 manipulator->setBottomBorderPen(TQPen(_color, 1, TQt::SolidLine));
3090 manipulator->setLeftBorderPen(TQPen(_color, 1, TQt::SolidLine));
3091 manipulator->setRightBorderPen(TQPen(_color, 1, TQt::SolidLine));
3092 manipulator->setHorizontalPen(TQPen(_color, 1, TQt::SolidLine));
3093 manipulator->setVerticalPen(TQPen(_color, 1, TQt::SolidLine));
3094 manipulator->add(*selectionInfo);
3095 manipulator->execute();
3098void Sheet::borderRemove( Selection* selectionInfo )
3100 BorderManipulator* manipulator =
new BorderManipulator();
3101 manipulator->setSheet(
this);
3102 manipulator->setTopBorderPen(TQPen(TQt::NoPen));
3103 manipulator->setBottomBorderPen(TQPen(TQt::NoPen));
3104 manipulator->setLeftBorderPen(TQPen(TQt::NoPen));
3105 manipulator->setRightBorderPen(TQPen(TQt::NoPen));
3106 manipulator->setHorizontalPen(TQPen(TQt::NoPen));
3107 manipulator->setVerticalPen(TQPen(TQt::NoPen));
3108 manipulator->add(*selectionInfo);
3109 manipulator->execute();
3113void Sheet::sortByRow(
const TQRect &area,
int ref_row, SortingOrder mode )
3116 point.setSheet(
this);
3117 point.setSheetName (d->name);
3118 point.setPos(area.topLeft());
3119 point.setColumnFixed(
false);
3120 point.setRowFixed(
false);
3122 sortByRow( area, ref_row, 0, 0, mode, mode, mode, 0,
false,
false, point,
true );
3125void Sheet::sortByColumn(
const TQRect &area,
int ref_column, SortingOrder mode )
3128 point.setSheet(
this);
3129 point.setSheetName(d->name);
3130 point.setPos(area.topLeft());
3131 point.setColumnFixed(
false);
3132 point.setRowFixed(
false);
3134 sortByColumn( area, ref_column, 0, 0, mode, mode, mode, 0,
false,
false,
3138void Sheet::checkCellContent(Cell * cell1, Cell * cell2,
int & ret)
3140 if ( cell1->isEmpty() )
3145 else if ( cell1->isObscured() && cell1->isPartOfMerged() )
3150 else if ( cell2->isEmpty() )
3158void Sheet::sortByRow(
const TQRect &area,
int key1,
int key2,
int key3,
3159 SortingOrder order1, SortingOrder order2,
3160 SortingOrder order3,
3161 TQStringList
const * firstKey,
bool copyFormat,
3162 bool headerRow, Point
const & outputPoint,
bool respectCase )
3165 Map::respectCase = respectCase;
3166 Q_ASSERT( order1 == Increase || order1 == Decrease );
3169 Q_ASSERT( util_isColumnSelected(r) ==
false );
3172 if ( util_isRowSelected(r) )
3174 r.setLeft( KS_colMax );
3180 for (
int row = r.top(); row <= r.bottom(); ++row )
3182 Cell * c = getFirstCellRow( row );
3187 if ( !c->isEmpty() )
3189 if ( col > r.right() )
3191 if ( col < r.left() )
3194 c = getNextCellRight( col, row );
3199 if ( r.right() < r.left() )
3201 Map::respectCase =
true;
3206 TQRect target( outputPoint.pos().x(), outputPoint.pos().y(), r.width(), r.height() );
3208 doc()->emitBeginOperation();
3210 if ( !doc()->undoLocked() )
3212 UndoSort *undo =
new UndoSort( doc(),
this, target );
3213 doc()->addCommand( undo );
3216 if (target.topLeft() != r.topLeft())
3218 int targetLeft = target.left();
3219 int targetTop = target.top();
3220 int sourceTop = r.top();
3221 int sourceLeft = r.left();
3223 key1 = key1 - sourceTop + targetTop;
3224 key2 = key2 - sourceTop + targetTop;
3225 key3 = key3 - sourceTop + targetTop;
3227 for (
int x = 0; x < r.width(); ++x)
3229 for (
int y = 0; y < r.height(); ++y )
3232 copyCells( sourceLeft + x, sourceTop + y,
3233 targetLeft + x, targetTop + y, copyFormat );
3247 for (
int d = target.left(); d <= target.right(); ++d )
3249 cell1 = cellAt( d, key1 );
3250 if ( cell1->isObscured() && cell1->isPartOfMerged() )
3252 Cell* obscuring = cell1->obscuringCells().first();
3253 cell = cellAt( obscuring->column(), key1 );
3254 cell1 = cellAt( obscuring->column() + cell->
extraXCells() + 1,
3255 obscuring->column());
3256 d = obscuring->column() + cell->
extraXCells() + 1;
3262 for (
int x = d + 1 ; x <= target.right(); x++ )
3264 cell2 = cellAt( x, key1 );
3266 checkCellContent(cell2, bestCell, status);
3269 else if (status == 2)
3279 int i1 = firstKey->findIndex( cell2->text() );
3280 int i2 = firstKey->findIndex( bestCell->text() );
3282 if ( i1 != -1 && i2 != -1 )
3284 if ( (order1 == Increase && i1 < i2 )
3285 || (order1 == Decrease && i1 > i2) )
3298 Cell * cell22 = cellAt( x, key2 );
3299 Cell * bestCell2 = cellAt( bestX, key2 );
3301 if ( cell22->isEmpty() )
3306 else if ( cell22->isObscured() && cell22->isPartOfMerged() )
3311 else if ( bestCell2->isEmpty() )
3319 if ( (order2 == Increase && *cell22 < *bestCell2)
3320 || (order2 == Decrease && *cell22 > *bestCell2) )
3326 else if ( (order2 == Increase && *cell22 > *bestCell2)
3327 || (order2 == Decrease && *cell22 < *bestCell2) )
3338 Cell * cell23 = cellAt( x, key3 );
3339 Cell * bestCell3 = cellAt( bestX, key3 );
3341 if ( cell23->isEmpty() )
3346 else if ( cell23->isObscured() && cell23->isPartOfMerged() )
3351 else if ( bestCell3->isEmpty() )
3358 if ( (order3 == Increase && *cell23 < *bestCell3)
3359 || (order3 == Decrease && *cell23 > *bestCell3) )
3375 else if ( i1 != -1 && i2 == -1 )
3382 else if ( i2 != -1 && i1 == -1 )
3393 if ( (order1 == Increase && *cell2 < *bestCell)
3394 || (order1 == Decrease && *cell2 > *bestCell) )
3400 else if ( (order1 == Increase && *cell2 > *bestCell)
3401 || (order1 == Decrease && *cell2 < *bestCell) )
3412 Cell * cell22 = cellAt( d, key2 );
3413 Cell * bestCell2 = cellAt( x, key2 );
3415 checkCellContent(cell2, bestCell, status);
3418 else if (status == 2)
3426 if ( (order2 == Increase && *cell22 > *bestCell2)
3427 || (order2 == Decrease && *cell22 < *bestCell2) )
3434 if ( (order2 == Increase && *cell22 > *bestCell2)
3435 || (order2 == Decrease && *cell22 < *bestCell2) )
3445 Cell * cell23 = cellAt( d, key3 );
3446 Cell * bestCell3 = cellAt( x, key3 );
3448 checkCellContent(cell2, bestCell, status);
3451 else if (status == 2)
3458 if ( (order3 == Increase && *cell23 > *bestCell3)
3459 || (order3 == Decrease && *cell23 < *bestCell3) )
3478 int top = target.top();
3482 for(
int y = target.bottom(); y >= top; --y )
3484 if ( y != key1 && y != key2 && y != key3 )
3485 swapCells( d, y, bestX, y, copyFormat );
3488 swapCells( d, key3, bestX, key3, copyFormat );
3490 swapCells( d, key2, bestX, key2, copyFormat );
3491 swapCells( d, key1, bestX, key1, copyFormat );
3494 Map::respectCase =
true;
3496 emit sig_updateView(
this );
3499void Sheet::sortByColumn(
const TQRect &area,
int key1,
int key2,
int key3,
3500 SortingOrder order1, SortingOrder order2,
3501 SortingOrder order3,
3502 TQStringList
const * firstKey,
bool copyFormat,
3504 Point
const & outputPoint,
bool respectCase )
3507 Map::respectCase = respectCase;
3509 Q_ASSERT( order1 == Increase || order1 == Decrease );
3512 Q_ASSERT( util_isRowSelected(r) ==
false );
3515 if ( util_isColumnSelected(r) )
3517 r.setTop( KS_rowMax );
3523 for (
int col = r.left(); col <= r.right(); ++col )
3525 Cell * c = getFirstCellColumn( col );
3530 if ( !c->isEmpty() )
3532 if ( row > r.bottom() )
3534 if ( row < r.top() )
3537 c = getNextCellDown( col, row );
3542 if ( r.bottom() < r.top() )
3544 Map::respectCase =
true;
3548 TQRect target( outputPoint.pos().x(), outputPoint.pos().y(), r.width(), r.height() );
3550 if ( !doc()->undoLocked() )
3552 UndoSort *undo =
new UndoSort( doc(),
this, target );
3553 doc()->addCommand( undo );
3556 doc()->emitBeginOperation();
3558 if (target.topLeft() != r.topLeft())
3560 int targetLeft = target.left();
3561 int targetTop = target.top();
3562 int sourceTop = r.top();
3563 int sourceLeft = r.left();
3565 key1 = key1 - sourceLeft + targetLeft;
3566 key2 = key2 - sourceLeft + targetLeft;
3567 key3 = key3 - sourceLeft + targetLeft;
3569 for (
int x = 0; x < r.width(); ++x)
3571 for (
int y = 0; y < r.height(); ++y )
3574 copyCells( sourceLeft + x, sourceTop + y,
3575 targetLeft + x, targetTop + y, copyFormat );
3591 int d = target.top();
3596 for ( ; d <= target.bottom(); ++d )
3599 cell1 = cellAt( key1, d );
3600 if ( cell1->isObscured() && cell1->isPartOfMerged() )
3602 Cell* obscuring = cell1->obscuringCells().first();
3603 cell = cellAt( key1, obscuring->row() );
3604 cell1 = cellAt( key1, obscuring->row() + cell->
extraYCells() + 1 );
3611 for (
int y = d + 1 ; y <= target.bottom(); ++y )
3613 cell2 = cellAt( key1, y );
3615 if ( cell2->isEmpty() )
3620 else if ( cell2->isObscured() && cell2->isPartOfMerged() )
3625 else if ( bestCell->isEmpty() )
3635 int i1 = firstKey->findIndex( cell2->text() );
3636 int i2 = firstKey->findIndex( bestCell->text() );
3638 if ( i1 != -1 && i2 != -1 )
3640 if ( (order1 == Increase && i1 < i2 )
3641 || (order1 == Decrease && i1 > i2) )
3653 Cell * cell22 = cellAt( key2, d );
3654 Cell * bestCell2 = cellAt( key2, y );
3656 if ( cell22->isEmpty() )
3661 else if ( cell22->isObscured() && cell22->isPartOfMerged() )
3666 else if ( bestCell2->isEmpty() )
3674 if ( (order2 == Increase && *cell22 > *bestCell2)
3675 || (order2 == Decrease && *cell22 < *bestCell2) )
3681 else if ( (order2 == Increase && *cell22 < *bestCell2)
3682 || (order2 == Decrease && *cell22 > *bestCell2) )
3692 Cell * cell23 = cellAt( key3, d );
3693 Cell * bestCell3 = cellAt( key3, y );
3695 checkCellContent(cell2, bestCell, status);
3698 else if (status == 2)
3706 if ( (order3 == Increase && *cell23 < *bestCell3)
3707 || (order3 == Decrease && *cell23 > *bestCell3) )
3723 else if ( i1 != -1 && i2 == -1 )
3730 else if ( i2 != -1 && i1 == -1 )
3742 if ( (order1 == Increase && *cell2 < *bestCell)
3743 || (order1 == Decrease && *cell2 > *bestCell) )
3748 else if ( (order1 == Increase && *cell2 > *bestCell)
3749 || (order1 == Decrease && *cell2 < *bestCell) )
3760 Cell * cell22 = cellAt( key2, y );
3761 Cell * bestCell2 = cellAt( key2, bestY );
3763 if ( cell22->isEmpty() )
3768 else if ( cell22->isObscured() && cell22->isPartOfMerged() )
3773 else if ( bestCell2->isEmpty() )
3781 if ( (order2 == Increase && *cell22 < *bestCell2)
3782 || (order2 == Decrease && *cell22 > *bestCell2) )
3788 else if ( (order2 == Increase && *cell22 > *bestCell2)
3789 || (order2 == Decrease && *cell22 < *bestCell2) )
3798 Cell * cell23 = cellAt( key3, y );
3799 Cell * bestCell3 = cellAt( key3, bestY );
3801 if ( cell23->isEmpty() )
3806 else if ( cell23->isObscured() && cell23->isPartOfMerged() )
3811 else if ( bestCell3->isEmpty() )
3819 if ( (order3 == Increase && *cell23 < *bestCell3)
3820 || (order3 == Decrease && *cell23 > *bestCell3) )
3839 for (
int x = target.left(); x <= target.right(); ++x)
3841 if ( x != key1 && x != key2 && x != key3)
3842 swapCells( x, d, x, bestY, copyFormat );
3845 swapCells( key3, d, key3, bestY, copyFormat );
3847 swapCells( key2, d, key2, bestY, copyFormat );
3848 swapCells( key1, d, key1, bestY, copyFormat );
3852 Map::respectCase =
true;
3853 emit sig_updateView(
this );
3857void Sheet::copyCells(
int x1,
int y1,
int x2,
int y2,
bool cpFormat )
3859 Cell * sourceCell = cellAt( x1, y1 );
3860 Cell * targetCell = cellAt( x2, y2 );
3862 if ( sourceCell->isDefault() && targetCell->isDefault())
3868 targetCell = nonDefaultCell(x2, y2);
3871 targetCell->copyContent( sourceCell );
3888 targetCell->copyFormat( sourceCell );
3920void Sheet::swapCells(
int x1,
int y1,
int x2,
int y2,
bool cpFormat )
3922 Cell * ref1 = cellAt( x1, y1 );
3923 Cell * ref2 = cellAt( x2, y2 );
3925 if ( ref1->isDefault() )
3927 if ( !ref2->isDefault() )
3929 ref1 = nonDefaultCell( x1, y1 );
3936 if ( ref2->isDefault() )
3938 ref2 = nonDefaultCell( x2, y2 );
3947 if (!ref1->isFormula() && !ref2->isFormula())
3949 Cell *tmp =
new Cell(
this, -1, -1 );
3951 tmp->copyContent( ref1 );
3952 ref1->copyContent( ref2 );
3953 ref2->copyContent( tmp );
3958 if ( ref1->isFormula() && ref2->isFormula() )
3960 TQString d = ref1->encodeFormula();
3961 ref1->setCellText( ref1->decodeFormula( ref2->encodeFormula( ) ) );
3962 ref1->setCalcDirtyFlag();
3964 ref2->setCellText( ref2->decodeFormula( d ) );
3965 ref2->setCalcDirtyFlag();
3969 if (ref1->isFormula() && !ref2->isFormula() )
3971 TQString d = ref1->encodeFormula();
3972 ref1->setCellText(ref2->text());
3973 ref2->setCellText(ref2->decodeFormula(d));
3974 ref2->setCalcDirtyFlag();
3978 if (!ref1->isFormula() && ref2->isFormula() )
3980 TQString d = ref2->encodeFormula();
3981 ref2->setCellText(ref1->text());
3982 ref1->setCellText(ref1->decodeFormula(d));
3983 ref1->setCalcDirtyFlag();
3989 Format::Align a = ref1->format()->align( ref1->column(), ref1->row() );
3990 ref1->format()->setAlign( ref2->format()->align( ref2->column(), ref2->row() ) );
3991 ref2->format()->setAlign(a);
3993 Format::AlignY ay = ref1->format()->alignY( ref1->column(), ref1->row() );
3994 ref1->format()->setAlignY( ref2->format()->alignY( ref2->column(), ref2->row() ) );
3995 ref2->format()->setAlignY(ay);
3997 TQFont textFont = ref1->format()->textFont( ref1->column(), ref1->row() );
3998 ref1->format()->setTextFont( ref2->format()->textFont( ref2->column(), ref2->row() ) );
3999 ref2->format()->setTextFont(textFont);
4001 TQColor textColor = ref1->format()->textColor( ref1->column(), ref1->row() );
4002 ref1->format()->setTextColor( ref2->format()->textColor( ref2->column(), ref2->row() ) );
4003 ref2->format()->setTextColor(textColor);
4005 TQColor bgColor = ref1->bgColor( ref1->column(), ref1->row() );
4006 ref1->format()->setBgColor( ref2->bgColor( ref2->column(), ref2->row() ) );
4007 ref2->format()->setBgColor(bgColor);
4009 TQPen lbp = ref1->leftBorderPen( ref1->column(), ref1->row() );
4010 ref1->setLeftBorderPen( ref2->leftBorderPen( ref2->column(), ref2->row() ) );
4011 ref2->setLeftBorderPen(lbp);
4013 TQPen tbp = ref1->topBorderPen( ref1->column(), ref1->row() );
4014 ref1->setTopBorderPen( ref2->topBorderPen( ref2->column(), ref2->row() ) );
4015 ref2->setTopBorderPen(tbp);
4017 TQPen bbp = ref1->bottomBorderPen( ref1->column(), ref1->row() );
4018 ref1->setBottomBorderPen( ref2->bottomBorderPen( ref2->column(), ref2->row() ) );
4019 ref2->setBottomBorderPen(bbp);
4021 TQPen rbp = ref1->rightBorderPen( ref1->column(), ref1->row() );
4022 ref1->setRightBorderPen( ref2->rightBorderPen( ref2->column(), ref2->row() ) );
4023 ref2->setRightBorderPen(rbp);
4025 TQPen fdp = ref1->format()->fallDiagonalPen( ref1->column(), ref1->row() );
4026 ref1->format()->setFallDiagonalPen( ref2->format()->fallDiagonalPen( ref2->column(), ref2->row() ) );
4027 ref2->format()->setFallDiagonalPen(fdp);
4029 TQPen udp = ref1->format()->goUpDiagonalPen( ref1->column(), ref1->row() );
4030 ref1->format()->setGoUpDiagonalPen( ref2->format()->goUpDiagonalPen( ref2->column(), ref2->row() ) );
4031 ref2->format()->setGoUpDiagonalPen(udp);
4033 TQBrush bgBrush = ref1->backGroundBrush( ref1->column(), ref1->row() );
4034 ref1->format()->setBackGroundBrush( ref2->backGroundBrush( ref2->column(), ref2->row() ) );
4035 ref2->format()->setBackGroundBrush(bgBrush);
4037 int pre = ref1->format()->precision( ref1->column(), ref1->row() );
4038 ref1->format()->setPrecision( ref2->format()->precision( ref2->column(), ref2->row() ) );
4039 ref2->format()->setPrecision(pre);
4041 TQString prefix = ref1->format()->prefix( ref1->column(), ref1->row() );
4042 ref1->format()->setPrefix( ref2->format()->prefix( ref2->column(), ref2->row() ) );
4043 ref2->format()->setPrefix(prefix);
4045 TQString postfix = ref1->format()->postfix( ref1->column(), ref1->row() );
4046 ref1->format()->setPostfix( ref2->format()->postfix( ref2->column(), ref2->row() ) );
4047 ref2->format()->setPostfix(postfix);
4049 Format::FloatFormat f = ref1->format()->floatFormat( ref1->column(), ref1->row() );
4050 ref1->format()->setFloatFormat( ref2->format()->floatFormat( ref2->column(), ref2->row() ) );
4051 ref2->format()->setFloatFormat(f);
4053 Format::FloatColor c = ref1->format()->floatColor( ref1->column(), ref1->row() );
4054 ref1->format()->setFloatColor( ref2->format()->floatColor( ref2->column(), ref2->row() ) );
4055 ref2->format()->setFloatColor(c);
4057 bool multi = ref1->format()->multiRow( ref1->column(), ref1->row() );
4058 ref1->format()->setMultiRow( ref2->format()->multiRow( ref2->column(), ref2->row() ) );
4059 ref2->format()->setMultiRow(multi);
4061 bool vert = ref1->format()->verticalText( ref1->column(), ref1->row() );
4062 ref1->format()->setVerticalText( ref2->format()->verticalText( ref2->column(), ref2->row() ) );
4063 ref2->format()->setVerticalText(vert);
4065 bool print = ref1->format()->getDontprintText( ref1->column(), ref1->row() );
4066 ref1->format()->setDontPrintText( ref2->format()->getDontprintText( ref2->column(), ref2->row() ) );
4067 ref2->format()->setDontPrintText(print);
4069 double ind = ref1->format()->getIndent( ref1->column(), ref1->row() );
4070 ref1->format()->setIndent( ref2->format()->getIndent( ref2->column(), ref2->row() ) );
4071 ref2->format()->setIndent( ind );
4073 TQValueList<Conditional> conditionList = ref1->conditionList();
4074 ref1->setConditionList(ref2->conditionList());
4075 ref2->setConditionList(conditionList);
4077 TQString com = ref1->format()->comment( ref1->column(), ref1->row() );
4078 ref1->format()->setComment( ref2->format()->comment( ref2->column(), ref2->row() ) );
4079 ref2->format()->setComment(com);
4081 int angle = ref1->format()->getAngle( ref1->column(), ref1->row() );
4082 ref1->format()->setAngle( ref2->format()->getAngle( ref2->column(), ref2->row() ) );
4083 ref2->format()->setAngle(angle);
4085 FormatType form = ref1->format()->getFormatType( ref1->column(), ref1->row() );
4086 ref1->format()->setFormatType( ref2->format()->getFormatType( ref2->column(), ref2->row() ) );
4087 ref2->format()->setFormatType(form);
4091void Sheet::refreshPreference()
4093 if ( getAutoCalc() )
4096 emit sig_updateHBorder(
this );
4097 emit sig_updateView(
this );
4101bool Sheet::areaIsEmpty(
const Region& region, TestType _type)
4103 Region::ConstIterator endOfList = region.constEnd();
4104 for (Region::ConstIterator it = region.constBegin(); it != endOfList; ++it)
4106 TQRect range = (*it)->rect().normalize();
4110 for (
int row = range.top(); row <= range.bottom(); ++row )
4112 Cell * c = getFirstCellRow( row );
4115 if ( !c->isPartOfMerged())
4120 if ( !c->text().isEmpty())
4124 if ( c->getValidity(0))
4128 if ( !c->format()->comment(c->column(), row).isEmpty())
4131 case ConditionalCellAttribute:
4132 if ( c->conditionList().count()> 0)
4138 c = getNextCellRight( c->column(), row );
4143 else if ((*it)->isColumn())
4145 for (
int col = range.left(); col <= range.right(); ++col )
4147 Cell * c = getFirstCellColumn( col );
4150 if ( !c->isPartOfMerged() )
4155 if ( !c->text().isEmpty())
4159 if ( c->getValidity(0))
4163 if ( !c->format()->comment(col, c->row()).isEmpty())
4166 case ConditionalCellAttribute:
4167 if ( c->conditionList().count()> 0)
4173 c = getNextCellDown( col, c->row() );
4181 int right = range.right();
4182 int bottom = range.bottom();
4183 for (
int x = range.left(); x <= right; ++x )
4184 for (
int y = range.top(); y <= bottom; ++y )
4186 cell = cellAt( x, y );
4192 if ( !cell->
text().isEmpty())
4196 if ( cell->getValidity(0))
4200 if ( !cell->
format()->comment(x, y).isEmpty())
4203 case ConditionalCellAttribute:
4215struct SetSelectionMultiRowWorker :
public Sheet::CellWorker
4218 SetSelectionMultiRowWorker(
bool _enable )
4219 : Sheet::CellWorker( ), enable( _enable ) { }
4221 class UndoAction* createUndoAction( Doc * doc, Sheet * sheet,
const KSpread::Region& region )
4223 TQString title = i18n(
"Multirow");
4224 return new UndoCellFormat( doc, sheet, region, title );
4227 bool testCondition( Cell * cell )
4229 return ( !cell->isPartOfMerged() );
4232 void doWork( Cell * cell,
bool,
int,
int )
4234 cell->setDisplayDirtyFlag();
4235 cell->format()->setMultiRow( enable );
4236 cell->format()->setVerticalText(
false );
4237 cell->format()->setAngle( 0 );
4238 cell->clearDisplayDirtyFlag();
4242void Sheet::setSelectionMultiRow( Selection* selectionInfo,
4245 SetSelectionMultiRowWorker w( enable );
4246 workOnCells( selectionInfo, w );
4249TQString Sheet::guessColumnTitle(TQRect& area,
int col)
4256 if ( (!rg.isValid()) || (col < area.left()) || (col > area.right()))
4271 Value cellValue=value(col,area.top());
4272 return cellValue.asString();
4275TQString Sheet::guessRowTitle(TQRect& area,
int row)
4282 if ( (!rg.isValid()) || (row < area.top()) || (row > area.bottom()) )
4296 Value cellValue=value(area.left(),row);
4297 return cellValue.asString();
4300void Sheet::setSelectionAlign( Selection* selectionInfo,
4301 Format::Align _align )
4303 HorAlignManipulator* manipulator =
new HorAlignManipulator();
4304 manipulator->setSheet(
this);
4305 manipulator->setProperty(Format::PAlign);
4306 manipulator->setHorizontalAlignment(_align);
4307 manipulator->add(*selectionInfo);
4308 manipulator->execute();
4311void Sheet::setSelectionAlignY( Selection* selectionInfo,
4312 Format::AlignY _alignY )
4314 VerAlignManipulator* manipulator =
new VerAlignManipulator();
4315 manipulator->setSheet(
this);
4316 manipulator->setProperty(Format::PAlignY);
4317 manipulator->setVerticalAlignment(_alignY);
4318 manipulator->add(*selectionInfo);
4319 manipulator->execute();
4323struct SetSelectionPrecisionWorker :
public Sheet::CellWorker {
4325 SetSelectionPrecisionWorker(
int delta ) : Sheet::CellWorker( ), _delta( delta ) { }
4327 class UndoAction* createUndoAction( Doc* doc, Sheet* sheet,
const KSpread::Region& region ) {
4328 TQString title=i18n(
"Change Precision");
4329 return new UndoCellFormat( doc, sheet, region, title );
4331 bool testCondition( Cell* cell ) {
4332 return ( !cell->isPartOfMerged() );
4334 void doWork( Cell* cell,
bool,
int,
int ) {
4335 cell->setDisplayDirtyFlag();
4337 cell->incPrecision();
4339 cell->decPrecision();
4340 cell->clearDisplayDirtyFlag();
4344void Sheet::setSelectionPrecision( Selection* selectionInfo,
4347 SetSelectionPrecisionWorker w( _delta );
4348 workOnCells( selectionInfo, w );
4351struct SetSelectionStyleWorker :
public Sheet::CellWorkerTypeA
4354 SetSelectionStyleWorker( Style * style )
4359 TQString getUndoTitle()
4361 return i18n(
"Apply Style");
4364 void doWork( RowFormat* rw )
4366 rw->setStyle( m_style );
4369 void doWork( ColumnFormat* cl )
4371 cl->setStyle( m_style );
4374 bool testCondition( Cell* cell )
4376 return ( !cell->isPartOfMerged() && cell->format()->style() != m_style );
4379 void doWork( Cell* cell,
bool cellRegion,
int,
int )
4382 cell->setDisplayDirtyFlag();
4384 cell->format()->setStyle( m_style );
4387 cell->clearDisplayDirtyFlag();
4392void Sheet::setSelectionStyle( Selection * selectionInfo, Style * style )
4394 SetSelectionStyleWorker w( style );
4395 workOnCells( selectionInfo, w );
4398struct SetSelectionMoneyFormatWorker :
public Sheet::CellWorkerTypeA
4402 SetSelectionMoneyFormatWorker(
bool _b,Doc* _doc ) : b( _b ), m_pDoc(_doc) { }
4403 TQString getUndoTitle() {
return i18n(
"Format Money"); }
4404 bool testCondition( RowFormat* rw ) {
4405 return ( rw->hasProperty( Format::PFormatType )
4406 || rw->hasProperty( Format::PPrecision ) );
4408 void doWork( RowFormat* rw ) {
4409 rw->setFormatType( b ? Money_format : Generic_format );
4410 rw->setPrecision( b ? m_pDoc->locale()->fracDigits() : 0 );
4412 void doWork( ColumnFormat* cl ) {
4413 cl->setFormatType( b ? Money_format : Generic_format );
4414 cl->setPrecision( b ? m_pDoc->locale()->fracDigits() : 0 );
4416 void prepareCell( Cell* c ) {
4417 c->format()->clearProperty( Format::PPrecision );
4418 c->format()->clearNoFallBackProperties( Format::PPrecision );
4419 c->format()->clearProperty( Format::PFormatType );
4420 c->format()->clearNoFallBackProperties( Format::PFormatType );
4422 bool testCondition( Cell* cell ) {
4423 return ( !cell->isPartOfMerged() );
4425 void doWork( Cell* cell,
bool cellRegion,
int,
int ) {
4427 cell->setDisplayDirtyFlag();
4428 cell->format()->setFormatType( b ? Money_format : Generic_format );
4429 cell->format()->setPrecision( b ? m_pDoc->locale()->fracDigits() : 0 );
4431 cell->clearDisplayDirtyFlag();
4436void Sheet::setSelectionMoneyFormat( Selection* selectionInfo,
4439 SetSelectionMoneyFormatWorker w( b,doc() );
4440 workOnCells( selectionInfo, w );
4444struct IncreaseIndentWorker :
public Sheet::CellWorkerTypeA {
4448 IncreaseIndentWorker(
double _tmpIndent,
double _valIndent )
4449 : tmpIndent( _tmpIndent ), valIndent( _valIndent ) { }
4451 TQString getUndoTitle() {
return i18n(
"Increase Indent"); }
4452 bool testCondition( RowFormat* rw ) {
4453 return ( rw->hasProperty( Format::PIndent ) );
4456 void doWork( RowFormat* rw ) {
4457 rw->setIndent( tmpIndent+valIndent );
4460 void doWork( ColumnFormat* cl ) {
4461 cl->setIndent( tmpIndent+valIndent );
4464 void prepareCell( Cell* c ) {
4465 c->format()->clearProperty( Format::PIndent );
4466 c->format()->clearNoFallBackProperties( Format::PIndent );
4470 bool testCondition( Cell* cell ) {
4471 return ( !cell->isPartOfMerged() );
4473 void doWork( Cell* cell,
bool cellRegion,
int x,
int y ) {
4475 if(cell->format()->align(x,y)!=Format::Left)
4480 cell->setDisplayDirtyFlag();
4481 cell->format()->setIndent( cell->format()->getIndent(x,y) +valIndent );
4482 cell->clearDisplayDirtyFlag();
4484 cell->format()->setIndent( tmpIndent+valIndent);
4491void Sheet::increaseIndent(Selection* selectionInfo)
4493 TQPoint marker(selectionInfo->marker());
4494 double valIndent = doc()->getIndentValue();
4495 Cell *c = cellAt( marker );
4496 double tmpIndent = c->format()->getIndent( marker.x(), marker.y() );
4498 IncreaseIndentWorker w( tmpIndent, valIndent );
4499 workOnCells( selectionInfo, w );
4503struct DecreaseIndentWorker :
public Sheet::CellWorkerTypeA {
4504 double tmpIndent, valIndent;
4505 DecreaseIndentWorker(
double _tmpIndent,
double _valIndent ) : tmpIndent( _tmpIndent ), valIndent( _valIndent ) { }
4506 TQString getUndoTitle() {
return i18n(
"Decrease Indent"); }
4507 bool testCondition( RowFormat* rw ) {
4508 return ( rw->hasProperty( Format::PIndent ) );
4510 void doWork( RowFormat* rw ) {
4511 rw->setIndent( TQMAX( 0.0, tmpIndent - valIndent ) );
4513 void doWork( ColumnFormat* cl ) {
4514 cl->setIndent( TQMAX( 0.0, tmpIndent - valIndent ) );
4516 void prepareCell( Cell* c ) {
4517 c->format()->clearProperty( Format::PIndent );
4518 c->format()->clearNoFallBackProperties( Format::PIndent );
4520 bool testCondition( Cell* cell ) {
4521 return ( !cell->isPartOfMerged() );
4523 void doWork( Cell* cell,
bool cellRegion,
int x,
int y ) {
4525 cell->setDisplayDirtyFlag();
4526 cell->format()->setIndent( TQMAX( 0.0, cell->format()->getIndent( x, y ) - valIndent ) );
4527 cell->clearDisplayDirtyFlag();
4529 cell->format()->setIndent( TQMAX( 0.0, tmpIndent - valIndent ) );
4535void Sheet::decreaseIndent( Selection* selectionInfo )
4537 double valIndent = doc()->getIndentValue();
4538 TQPoint marker(selectionInfo->marker());
4539 Cell* c = cellAt( marker );
4540 double tmpIndent = c->format()->getIndent( marker.x(), marker.y() );
4542 DecreaseIndentWorker w( tmpIndent, valIndent );
4543 workOnCells( selectionInfo, w );
4547int Sheet::adjustColumnHelper( Cell * c,
int _col,
int _row )
4549 double long_max = 0.0;
4550 c->calculateTextParameters( painter(), _col, _row );
4551 if ( c->textWidth() > long_max )
4553 double indent = 0.0;
4554 int a = c->format()->align( c->column(), c->row() );
4555 if ( a == Format::Undefined )
4557 if ( c->value().isNumber() || c->isDate() || c->isTime())
4563 if ( a == Format::Left )
4564 indent = c->format()->getIndent( c->column(), c->row() );
4565 long_max = indent + c->textWidth()
4566 + c->format()->leftBorderWidth( c->column(), c->row() )
4567 + c->format()->rightBorderWidth( c->column(), c->row() );
4569 return (
int)long_max;
4572void Sheet::adjustArea(
const Region& region)
4574 AdjustColumnRowManipulator* manipulator =
new AdjustColumnRowManipulator();
4575 manipulator->setSheet(
this);
4576 manipulator->setAdjustColumn(
true);
4577 manipulator->setAdjustRow(
true);
4578 manipulator->add(region);
4579 manipulator->execute();
4582void Sheet::adjustColumn(
const Region& region)
4584 AdjustColumnRowManipulator* manipulator =
new AdjustColumnRowManipulator();
4585 manipulator->setSheet(
this);
4586 manipulator->setAdjustColumn(
true);
4587 manipulator->add(region);
4588 manipulator->execute();
4591void Sheet::adjustRow(
const Region& region)
4593 AdjustColumnRowManipulator* manipulator =
new AdjustColumnRowManipulator();
4594 manipulator->setSheet(
this);
4595 manipulator->setAdjustRow(
true);
4596 manipulator->add(region);
4597 manipulator->execute();
4600struct ClearTextSelectionWorker :
public Sheet::CellWorker {
4603 ClearTextSelectionWorker( Sheet * s )
4604 : Sheet::CellWorker( ), _s( s ) { }
4606 class UndoAction* createUndoAction( Doc* doc, Sheet* sheet,
const KSpread::Region& region ) {
4607 return new UndoChangeAreaTextCell( doc, sheet, region );
4609 bool testCondition( Cell* cell ) {
4610 return ( !cell->isObscured() );
4612 void doWork( Cell* cell,
bool,
int,
int )
4614 cell->setCellText(
"" );
4618void Sheet::clearTextSelection( Selection* selectionInfo )
4620 if (areaIsEmpty(*selectionInfo))
4623 ClearTextSelectionWorker w(
this );
4624 workOnCells( selectionInfo, w );
4628struct ClearValiditySelectionWorker :
public Sheet::CellWorker {
4629 ClearValiditySelectionWorker( ) : Sheet::CellWorker( ) { }
4631 class UndoAction* createUndoAction( Doc* doc, Sheet* sheet,
const KSpread::Region& region ) {
4632 return new UndoConditional( doc, sheet, region );
4634 bool testCondition( Cell* cell ) {
4635 return ( !cell->isObscured() );
4637 void doWork( Cell* cell,
bool,
int,
int ) {
4638 cell->removeValidity();
4642void Sheet::clearValiditySelection( Selection* selectionInfo )
4644 if (areaIsEmpty(*selectionInfo, Validity))
4647 ClearValiditySelectionWorker w;
4648 workOnCells( selectionInfo, w );
4652struct ClearConditionalSelectionWorker :
public Sheet::CellWorker
4654 ClearConditionalSelectionWorker( ) : Sheet::CellWorker( ) { }
4656 class UndoAction* createUndoAction( Doc* doc,
4660 return new UndoConditional( doc, sheet, region );
4662 bool testCondition( Cell* cell )
4664 return ( !cell->isObscured() );
4666 void doWork( Cell* cell,
bool,
int,
int )
4668 TQValueList<Conditional> emptyList;
4669 cell->setConditionList(emptyList);
4673void Sheet::clearConditionalSelection( Selection* selectionInfo )
4675 ClearConditionalSelectionWorker w;
4676 workOnCells( selectionInfo, w );
4679void Sheet::fillSelection( Selection * selectionInfo,
int direction )
4681 TQRect rct( selectionInfo->selection() );
4682 int right = rct.right();
4683 int bottom = rct.bottom();
4684 int left = rct.left();
4685 int top = rct.top();
4686 int width = rct.width();
4687 int height = rct.height();
4689 TQDomDocument undoDoc = saveCellRegion( rct );
4690 loadSelectionUndo( undoDoc, rct, left - 1, top - 1,
false, 0 );
4697 doc = saveCellRegion( TQRect( left, top, 1, height ) );
4701 doc = saveCellRegion( TQRect( left, bottom, width, 1 ) );
4705 doc = saveCellRegion( TQRect( right, top, 1, height ) );
4709 doc = saveCellRegion( TQRect( left, top, width, 1 ) );
4715 buffer.open( IO_WriteOnly );
4716 TQTextStream str( &buffer );
4717 str.setEncoding( TQTextStream::UnicodeUTF8 );
4725 for ( i = left + 1; i <= right; ++i )
4727 paste( buffer.buffer(), TQRect( i, top, 1, 1 ),
false );
4732 for ( i = bottom + 1; i >= top; --i )
4734 paste( buffer.buffer(), TQRect( left, i, 1, 1 ),
false );
4739 for ( i = right - 1; i >= left; --i )
4741 paste( buffer.buffer(), TQRect( i, top, 1, 1 ),
false );
4746 for ( i = top + 1; i <= bottom; ++i )
4748 paste( buffer.buffer(), TQRect( left, i, 1, 1 ),
false );
4753 this->doc()->setModified(
true );
4757struct DefaultSelectionWorker :
public Sheet::CellWorker {
4758 DefaultSelectionWorker( ) : Sheet::CellWorker( true, false, true ) { }
4760 class UndoAction* createUndoAction( Doc* doc, Sheet* sheet,
const KSpread::Region& region ) {
4761 TQString title=i18n(
"Default Parameters");
4762 return new UndoCellFormat( doc, sheet, region, title );
4764 bool testCondition( Cell* ) {
4767 void doWork( Cell* cell,
bool,
int,
int ) {
4768 cell->defaultStyle();
4772void Sheet::defaultSelection( Selection* selectionInfo )
4774 TQRect selection(selectionInfo->selection());
4775 DefaultSelectionWorker w;
4776 SelectionType st = workOnCells( selectionInfo, w );
4780 for (
int i = selection.top(); i <= selection.bottom(); i++ ) {
4781 rw = nonDefaultRowFormat( i );
4782 rw->defaultStyleFormat();
4784 emit sig_updateView(
this, *selectionInfo );
4786 case CompleteColumns:
4788 for (
int i = selection.left(); i <= selection.right(); i++ ) {
4789 cl=nonDefaultColumnFormat( i );
4790 cl->defaultStyleFormat();
4792 emit sig_updateView(
this, *selectionInfo );
4795 emit sig_updateView(
this, *selectionInfo );
4801struct SetConditionalWorker :
public Sheet::CellWorker
4803 TQValueList<Conditional> conditionList;
4804 SetConditionalWorker( TQValueList<Conditional> _tmp ) :
4805 Sheet::CellWorker( ), conditionList( _tmp ) { }
4807 class UndoAction* createUndoAction( Doc* doc,
4810 return new UndoConditional( doc, sheet, region );
4813 bool testCondition( Cell* )
4818 void doWork( Cell* cell,
bool,
int,
int )
4820 if ( !cell->isObscured() )
4822 cell->setConditionList(conditionList);
4823 cell->setDisplayDirtyFlag();
4828void Sheet::setConditional( Selection* selectionInfo,
4829 TQValueList<Conditional>
const & newConditions)
4831 if ( !doc()->undoLocked() )
4833 UndoConditional * undo =
new UndoConditional(doc(),
this, *selectionInfo);
4834 doc()->addCommand( undo );
4837 Region::ConstIterator endOfList = selectionInfo->constEnd();
4838 for (Region::ConstIterator it = selectionInfo->constBegin(); it != endOfList; ++it)
4840 TQRect range = (*it)->rect().normalize();
4842 int l = range.left();
4843 int r = range.right();
4844 int t = range.top();
4845 int b = range.bottom();
4848 Style * s = doc()->styleManager()->defaultStyle();
4849 for (
int x = l; x <= r; ++x)
4851 for (
int y = t; y <= b; ++y)
4853 cell = nonDefaultCell( x, y,
false, s );
4855 cell->setDisplayDirtyFlag();
4860 emit sig_updateView(
this, *selectionInfo );
4864struct SetValidityWorker :
public Sheet::CellWorker {
4866 SetValidityWorker( Validity _tmp ) : Sheet::CellWorker( ), tmp( _tmp ) { }
4868 class UndoAction* createUndoAction( Doc* doc, Sheet* sheet,
const KSpread::Region& region ) {
4869 return new UndoConditional( doc, sheet, region );
4871 bool testCondition( Cell* ) {
4874 void doWork( Cell* cell,
bool,
int,
int ) {
4875 if ( !cell->isObscured() ) {
4876 cell->setDisplayDirtyFlag();
4878 cell->removeValidity();
4881 Validity *tmpValidity = cell->getValidity();
4882 tmpValidity->message=tmp.message;
4883 tmpValidity->title=tmp.title;
4884 tmpValidity->valMin=tmp.valMin;
4885 tmpValidity->valMax=tmp.valMax;
4886 tmpValidity->m_cond=tmp.m_cond;
4887 tmpValidity->m_action=tmp.m_action;
4888 tmpValidity->m_restriction=tmp.m_restriction;
4889 tmpValidity->timeMin=tmp.timeMin;
4890 tmpValidity->timeMax=tmp.timeMax;
4891 tmpValidity->dateMin=tmp.dateMin;
4892 tmpValidity->dateMax=tmp.dateMax;
4893 tmpValidity->displayMessage=tmp.displayMessage;
4894 tmpValidity->allowEmptyCell=tmp.allowEmptyCell;
4895 tmpValidity->displayValidationInformation=tmp.displayValidationInformation;
4896 tmpValidity->titleInfo=tmp.titleInfo;
4897 tmpValidity->messageInfo=tmp.messageInfo;
4898 tmpValidity->listValidity=tmp.listValidity;
4900 cell->clearDisplayDirtyFlag();
4905void Sheet::setValidity(Selection* selectionInfo,
4906 KSpread::Validity tmp )
4908 SetValidityWorker w( tmp );
4909 workOnCells( selectionInfo, w );
4913struct GetWordSpellingWorker :
public Sheet::CellWorker {
4915 GetWordSpellingWorker( TQString& _listWord ) : Sheet::CellWorker( false, false, true ), listWord( _listWord ) { }
4917 class UndoAction* createUndoAction( Doc*, Sheet*,
const KSpread::Region& ) {
4920 bool testCondition( Cell* ) {
4923 void doWork( Cell* c,
bool cellRegion,
int,
int ) {
4924 if ( !c->isObscured() || cellRegion ) {
4925 if ( !c->isFormula() && !c->value().isNumber() && !c->value().asString().isEmpty() && !c->isTime()
4927 && !c->text().isEmpty())
4929 listWord+=c->text()+
'\n';
4935TQString Sheet::getWordSpelling(Selection* selectionInfo )
4938 GetWordSpellingWorker w( listWord );
4939 workOnCells( selectionInfo, w );
4944struct SetWordSpellingWorker :
public Sheet::CellWorker {
4948 SetWordSpellingWorker( TQStringList & _list,Sheet * s )
4949 : Sheet::CellWorker( false, false, true ), list( _list ), pos( 0 ), sheet( s ) { }
4951 class UndoAction* createUndoAction( Doc* doc, Sheet* sheet,
const KSpread::Region& region ) {
4952 return new UndoChangeAreaTextCell( doc, sheet, region );
4954 bool testCondition( Cell* ) {
4957 void doWork( Cell* c,
bool cellRegion,
int,
int )
4959 if ( !c->isObscured() || cellRegion ) {
4960 if ( !c->isFormula() && !c->value().isNumber() && !c->value().asString().isEmpty() && !c->isTime()
4962 && !c->text().isEmpty())
4966 c->setCellText( list[pos] );
4973void Sheet::setWordSpelling(Selection* selectionInfo,
4974 const TQString _listWord )
4976 TQStringList list = TQStringList::split (
'\n', _listWord );
4977 SetWordSpellingWorker w( list,
this );
4978 workOnCells( selectionInfo, w );
4981static TQString cellAsText( Cell* cell,
unsigned int max )
4986 int l = max - cell->strOutText().length();
4989 for (
int i = 0; i < l; ++i )
4991 result += cell->strOutText();
4996 result += cell->strOutText();
4998 for (
int i = 1; i < l; ++i )
5004 int s = (int) l / 2;
5005 for ( i = 0; i < s; ++i )
5007 result += cell->strOutText();
5008 for ( i = s; i < l; ++i )
5014 for (
unsigned int i = 0; i < max; ++i )
5021TQString Sheet::copyAsText( Selection* selectionInfo )
5024 if ( selectionInfo->isSingular() )
5026 Cell * cell = cellAt( selectionInfo->marker() );
5028 return cell->strOutText();
5032 TQRect selection(selectionInfo->selection());
5035 unsigned top = selection.bottom();
5036 unsigned bottom = selection.top();
5037 unsigned left = selection.right();
5038 unsigned right = selection.left();
5041 for( Cell *c = d->cells.firstCell();c; c = c->nextCell() )
5043 if ( !c->isDefault() )
5045 TQPoint p( c->column(), c->row() );
5046 if ( selection.contains( p ) )
5048 top = TQMIN( top, (
unsigned) c->row() );
5049 left = TQMIN( left, (
unsigned) c->column() );
5050 bottom = TQMAX( bottom, (
unsigned) c->row() );
5051 right = TQMAX( right, (
unsigned) c->column() );
5053 if ( c->strOutText().length() > max )
5054 max = c->strOutText().length();
5062 for (
unsigned y = top; y <= bottom; ++y)
5064 for (
unsigned x = left; x <= right; ++x)
5066 Cell *cell = cellAt( x, y );
5067 result += cellAsText( cell, max );
5075void Sheet::copySelection( Selection* selectionInfo )
5077 TQDomDocument doc = saveCellRegion( *selectionInfo,
true );
5081 buffer.open( IO_WriteOnly );
5082 TQTextStream str( &buffer );
5083 str.setEncoding( TQTextStream::UnicodeUTF8 );
5087 TextDrag * kd =
new TextDrag( 0L );
5088 kd->setPlain( copyAsText(selectionInfo) );
5089 kd->setKSpread( buffer.buffer() );
5091 TQApplication::clipboard()->setData( kd );
5094void Sheet::cutSelection( Selection* selectionInfo )
5096 TQDomDocument doc = saveCellRegion(*selectionInfo,
true,
true);
5100 buffer.open( IO_WriteOnly );
5101 TQTextStream str( &buffer );
5102 str.setEncoding( TQTextStream::UnicodeUTF8 );
5106 TextDrag * kd =
new TextDrag( 0L );
5107 kd->setPlain( copyAsText(selectionInfo) );
5108 kd->setKSpread( buffer.buffer() );
5110 TQApplication::clipboard()->setData( kd );
5112 deleteSelection( selectionInfo,
true );
5115void Sheet::paste(
const TQRect& pasteArea,
bool makeUndo,
5117 bool insert,
int insertTo,
bool pasteFC,
5118 TQClipboard::Mode clipboardMode )
5120 TQMimeSource * mime = TQApplication::clipboard()->data( clipboardMode );
5126 if ( mime->provides( TextDrag::selectionMimeType() ) )
5128 b = mime->encodedData( TextDrag::selectionMimeType() );
5130 else if( mime->provides(
"text/plain" ) )
5134 TQString _text = TQApplication::clipboard()->text( clipboardMode );
5135 doc()->emitBeginOperation();
5136 pasteTextPlain( _text, pasteArea );
5137 emit sig_updateView(
this );
5145 doc()->emitBeginOperation();
5146 paste( b, pasteArea, makeUndo, mode, operation, insert, insertTo, pasteFC );
5147 emit sig_updateView(
this );
5152void Sheet::pasteTextPlain( TQString &_text, TQRect pasteArea)
5156 if( _text.isEmpty() )
5159 TQString tmp = _text;
5161 int mx = pasteArea.left();
5162 int my = pasteArea.top();
5164 int len = tmp.length();
5167 for ( i = 0; i < len; ++i )
5169 if ( tmp[i] ==
'\n' )
5173 Cell * cell = nonDefaultCell( mx, my );
5176 if ( !doc()->undoLocked() )
5178 UndoSetText * undo =
new UndoSetText( doc(),
this , cell->
text(), mx, my, cell->
formatType() );
5179 doc()->addCommand( undo );
5184 TQRect rect(mx, my, mx, my + rows - 1);
5185 UndoChangeAreaTextCell * undo =
new UndoChangeAreaTextCell( doc(),
this , rect );
5186 doc()->addCommand( undo );
5201 rowtext = tmp.left(p);
5203 if ( !isProtected() || cell->
format()->notProtected( mx, my + i ) )
5211 cell = nonDefaultCell( mx, my + i );
5213 if (!cell || p == (
int) tmp.length())
5217 tmp = tmp.right(tmp.length() - p - 1);
5221 refreshMergedCell();
5223 emit sig_updateView(
this );
5224 emit sig_updateHBorder(
this );
5225 emit sig_updateVBorder(
this );
5228void Sheet::paste(
const TQByteArray& b,
const TQRect& pasteArea,
bool makeUndo,
5230 bool insert,
int insertTo,
bool pasteFC )
5232 kdDebug(36001) <<
"Parsing " << b.size() <<
" bytes" << endl;
5234 TQBuffer buffer( b );
5235 buffer.open( IO_ReadOnly );
5237 doc.setContent( &buffer );
5242 int mx = pasteArea.left();
5243 int my = pasteArea.top();
5245 loadSelection( doc, pasteArea, mx - 1, my - 1, makeUndo,
5246 mode, operation, insert, insertTo, pasteFC );
5249bool Sheet::loadSelection(
const TQDomDocument& doc,
const TQRect& pasteArea,
5250 int _xshift,
int _yshift,
bool makeUndo,
5252 int insertTo,
bool pasteFC)
5256 if (!isLoading() && makeUndo)
5258 loadSelectionUndo( doc, pasteArea, _xshift, _yshift, insert, insertTo );
5261 TQDomElement root = doc.documentElement();
5263 int rowsInClpbrd = root.attribute(
"rows" ).toInt();
5264 int columnsInClpbrd = root.attribute(
"columns" ).toInt();
5267 const int pasteWidth = ( pasteArea.width() >= columnsInClpbrd
5268 && util_isRowSelected(pasteArea) ==
false
5269 && root.namedItem(
"rows" ).toElement().isNull() )
5270 ? pasteArea.width() : columnsInClpbrd;
5271 const int pasteHeight = ( pasteArea.height() >= rowsInClpbrd
5272 && util_isColumnSelected(pasteArea) ==
false
5273 && root.namedItem(
"columns" ).toElement().isNull())
5274 ? pasteArea.height() : rowsInClpbrd;
5283 TQDomElement e = root.firstChild().toElement();
5284 for (; !e.isNull(); e = e.nextSibling().toElement())
5287 if (e.tagName() ==
"columns" && !isProtected())
5292 int col = e.attribute(
"column").toInt();
5293 int width = e.attribute(
"count").toInt();
5296 for (
int i = col; i < col + width; ++i )
5298 d->cells.clearColumn( _xshift + i );
5299 d->columns.removeElement( _xshift + i );
5304 TQDomElement c = e.firstChild().toElement();
5305 for ( ; !c.isNull(); c = c.nextSibling().toElement() )
5307 if ( c.tagName() ==
"column" )
5309 ColumnFormat *cl =
new ColumnFormat(
this, 0 );
5310 if ( cl->load( c, _xshift, mode, pasteFC ) )
5311 insertColumnFormat( cl );
5319 if (e.tagName() ==
"rows" && !isProtected())
5324 int row = e.attribute(
"row").toInt();
5325 int height = e.attribute(
"count").toInt();
5328 for(
int i = row; i < row + height; ++i )
5330 d->cells.clearRow( _yshift + i );
5331 d->rows.removeElement( _yshift + i );
5336 TQDomElement c = e.firstChild().toElement();
5337 for( ; !c.isNull(); c = c.nextSibling().toElement() )
5339 if ( c.tagName() ==
"row" )
5341 RowFormat *cl =
new RowFormat(
this, 0 );
5342 if ( cl->load( c, _yshift, mode, pasteFC ) )
5343 insertRowFormat( cl );
5350 Cell* refreshCell = 0;
5352 Cell *cellBackup = NULL;
5353 if (e.tagName() ==
"cell")
5355 int row = e.attribute(
"row" ).toInt() + _yshift;
5356 int col = e.attribute(
"column" ).toInt() + _xshift;
5359 for (
int roff = 0; row + roff - _yshift <= pasteHeight; roff += rowsInClpbrd)
5361 for (
int coff = 0; col + coff - _xshift <= pasteWidth; coff += columnsInClpbrd)
5367 cell = nonDefaultCell( col + coff, row + roff );
5368 if (isProtected() && !cell->
format()->notProtected(col + coff, row + roff))
5373 cellBackup =
new Cell(
this, cell->
column(), cell->
row());
5374 cellBackup->copyAll(cell);
5376 if (!cell->load(e, _xshift + coff, _yshift + roff, mode, operation, pasteFC))
5392 cell = cellAt( col + coff, row + roff );
5411 this->doc()->setModified(
true );
5414 refreshMergedCell();
5416 emit sig_updateView(
this );
5417 emit sig_updateHBorder(
this );
5418 emit sig_updateVBorder(
this );
5423void Sheet::loadSelectionUndo(
const TQDomDocument& d,
const TQRect& loadArea,
5424 int _xshift,
int _yshift,
5425 bool insert,
int insertTo)
5427 TQDomElement root = d.documentElement();
5429 int rowsInClpbrd = root.attribute(
"rows" ).toInt();
5430 int columnsInClpbrd = root.attribute(
"columns" ).toInt();
5433 const int pasteWidth = (loadArea.width() >= columnsInClpbrd &&
5434 util_isRowSelected(loadArea) ==
false &&
5435 root.namedItem(
"rows" ).toElement().isNull())
5436 ? loadArea.width() : columnsInClpbrd;
5437 const int pasteHeight = (loadArea.height() >= rowsInClpbrd &&
5438 util_isColumnSelected(loadArea) ==
false &&
5439 root.namedItem(
"columns" ).toElement().isNull())
5440 ? loadArea.height() : rowsInClpbrd;
5446 for (TQDomNode n = root.firstChild(); !n.isNull(); n = n.nextSibling())
5448 TQDomElement e = n.toElement();
5449 if (e.tagName() ==
"columns")
5452 int col = e.attribute(
"column").toInt();
5453 int width = e.attribute(
"count").toInt();
5454 for (
int coff = 0; col + coff <= pasteWidth; coff += columnsInClpbrd)
5456 uint overlap = TQMAX(0, (col - 1 + coff + width) - pasteWidth);
5457 uint effWidth = width - overlap;
5458 region.add(TQRect(_xshift + col + coff, 1, effWidth, KS_rowMax));
5459 numCols += effWidth;
5462 else if (e.tagName() ==
"rows")
5465 int row = e.attribute(
"row").toInt();
5466 int height = e.attribute(
"count").toInt();
5467 for (
int roff = 0; row + roff <= pasteHeight; roff += rowsInClpbrd)
5469 uint overlap = TQMAX(0, (row - 1 + roff + height) - pasteHeight);
5470 uint effHeight = height - overlap;
5471 region.add(TQRect(1, _yshift + row + roff, KS_colMax, effHeight));
5472 numRows += effHeight;
5475 else if (!e.isNull())
5478 int col = e.attribute(
"column").toInt();
5479 int row = e.attribute(
"row").toInt();
5480 for (
int coff = 0; col + coff <= pasteWidth; coff += columnsInClpbrd)
5482 for (
int roff = 0; row + roff <= pasteHeight; roff += rowsInClpbrd)
5484 region.add(TQPoint(_xshift + col + coff, _yshift + row + roff));
5490 if (!doc()->undoLocked())
5492 UndoCellPaste *undo =
new UndoCellPaste( doc(),
this, _xshift, _yshift, region, insert, insertTo );
5493 doc()->addCommand( undo );
5498 TQRect rect = region.boundingRect();
5500 if (insertTo == -1 && numCols == 0 && numRows == 0)
5502 rect.setWidth(rect.width());
5503 shiftRow(rect,
false);
5506 else if (insertTo == 1 && numCols == 0 && numRows == 0)
5508 rect.setHeight(rect.height());
5509 shiftColumn( rect,
false );
5512 else if (insertTo == 0 && numCols == 0 && numRows > 0)
5514 insertRow(rect.top(), rect.height() - 1,
false);
5517 else if (insertTo == 0 && numCols > 0 && numRows == 0)
5519 insertColumn(rect.left(), rect.width() - 1,
false);
5524bool Sheet::testAreaPasteInsert()
const
5526 TQMimeSource* mime = TQApplication::clipboard()->data( TQClipboard::Clipboard );
5532 if ( mime->provides(
"application/x-kspread-snippet" ) )
5533 b = mime->encodedData(
"application/x-kspread-snippet" );
5537 TQBuffer buffer( b );
5538 buffer.open( IO_ReadOnly );
5540 d.setContent( &buffer );
5543 TQDomElement e = d.documentElement();
5544 if ( !e.namedItem(
"columns" ).toElement().isNull() )
5547 if ( !e.namedItem(
"rows" ).toElement().isNull() )
5550 TQDomElement c = e.firstChild().toElement();
5551 for( ; !c.isNull(); c = c.nextSibling().toElement() )
5553 if ( c.tagName() ==
"cell" )
5559void Sheet::deleteCells(
const Region& region)
5562 TQPtrStack<Cell> cellStack;
5564 Region::ConstIterator endOfList = region.constEnd();
5565 for (Region::ConstIterator it = region.constBegin(); it != endOfList; ++it)
5567 TQRect range = (*it)->rect().normalize();
5569 int right = range.right();
5570 int left = range.left();
5571 int bottom = range.bottom();
5573 for (
int row = range.top(); row <= bottom; ++row )
5575 Cell * c = getFirstCellRow( row );
5581 c = getNextCellRight( left - 1, row );
5587 if ( !c->isDefault() )
5588 cellStack.push( c );
5590 c = getNextCellRight( col, row );
5595 d->cells.setAutoDelete(
false );
5598 while ( !cellStack.isEmpty() )
5600 Cell * cell = cellStack.pop();
5602 d->cells.remove( cell->
column(), cell->
row() );
5604 setRegionPaintDirty(cell->
cellRect());
5609 d->cells.setAutoDelete(
true );
5611 setLayoutDirtyFlag();
5616 Cell * c = d->cells.firstCell();
5617 for( ;c; c = c->nextCell() )
5619 if ( c->doesMergeCells() && !c->isDefault() )
5620 c->mergeCells( c->column(), c->row(),
5621 c->extraXCells(), c->extraYCells() );
5623 doc()->setModified(
true );
5626void Sheet::deleteSelection( Selection* selectionInfo,
bool undo )
5628 if ( undo && !doc()->undoLocked() )
5630 UndoDelete *undo =
new UndoDelete( doc(),
this, *selectionInfo );
5631 doc()->addCommand( undo );
5634 Region::ConstIterator endOfList = selectionInfo->constEnd();
5635 for (Region::ConstIterator it = selectionInfo->constBegin(); it != endOfList; ++it)
5637 TQRect range = (*it)->rect().normalize();
5640 if ( util_isRowSelected(range) )
5642 for(
int i = range.top(); i <= range.bottom(); ++i )
5644 d->cells.clearRow( i );
5645 d->rows.removeElement( i );
5648 emit sig_updateVBorder(
this );
5651 else if ( util_isColumnSelected(range) )
5653 for(
int i = range.left(); i <= range.right(); ++i )
5655 d->cells.clearColumn( i );
5656 d->columns.removeElement( i );
5659 emit sig_updateHBorder(
this );
5663 setRegionPaintDirty( range );
5664 deleteCells( range );
5667 refreshMergedCell();
5668 emit sig_updateView(
this );
5671void Sheet::updateView()
5673 emit sig_updateView(
this );
5676void Sheet::updateView( TQRect
const & rect )
5678 emit sig_updateView(
this, rect );
5681void Sheet::updateView(Region* region)
5683 emit sig_updateView(
this, *region );
5686void Sheet::refreshView(
const Region& region )
5689 Region::ConstIterator endOfList = region.constEnd();
5690 for (Region::ConstIterator it = region.constBegin(); it != endOfList; ++it)
5692 TQRect range = (*it)->rect().normalize();
5695 Cell * c = d->cells.firstCell();
5696 for( ;c; c = c->nextCell() )
5698 if ( !c->isDefault() &&
5699 c->row() >= range.top() && c->row() <= range.bottom() &&
5700 c->column() >= range.left() && c->column() <= range.right() )
5702 if (c->doesMergeCells())
5704 int right=TQMAX(tmp.right(),c->column()+c->extraXCells());
5705 int bottom=TQMAX(tmp.bottom(),c->row()+c->extraYCells());
5707 tmp.setRight(right);
5708 tmp.setBottom(bottom);
5712 deleteCells( range );
5715 emit sig_updateView(
this, tmpRegion );
5719void Sheet::mergeCells(
const Region& region,
bool hor,
bool ver)
5724 if( workbook()->isProtected() )
5727 MergeManipulator* manipulator =
new MergeManipulator();
5728 manipulator->setSheet(
this);
5729 manipulator->setHorizontalMerge(hor);
5730 manipulator->setVerticalMerge(ver);
5731 manipulator->add(region);
5732 manipulator->execute();
5735void Sheet::dissociateCells(
const Region& region)
5740 if( workbook()->isProtected() )
5743 Manipulator* manipulator =
new MergeManipulator();
5744 manipulator->setSheet(
this);
5745 manipulator->setReverse(
true);
5746 manipulator->add(region);
5747 manipulator->execute();
5750bool Sheet::testListChoose(Selection* selectionInfo)
5752 TQRect selection( selectionInfo->selection() );
5753 TQPoint marker( selectionInfo->marker() );
5755 Cell *cell = cellAt( marker.x(), marker.y() );
5756 TQString tmp=cell->
text();
5758 Cell* c = firstCell();
5759 bool different=
false;
5761 for( ;c; c = c->nextCell() )
5764 if ( selection.left() <= col && selection.right() >= col &&
5765 !c->isPartOfMerged() &&
5766 !(col==marker.x() && c->row()==marker.y()))
5768 if(!c->isFormula() && !c->value().isNumber() && !c->value().asString().isEmpty()
5769 && !c->isTime() &&!c->isDate() )
5782TQDomDocument Sheet::saveCellRegion(
const Region& region,
bool copy,
bool era)
5784 TQDomDocument dd(
"spreadsheet-snippet" );
5785 dd.appendChild( dd.createProcessingInstruction(
"xml",
"version=\"1.0\" encoding=\"UTF-8\"" ) );
5786 TQDomElement root = dd.createElement(
"spreadsheet-snippet" );
5787 dd.appendChild(root);
5790 TQRect boundingRect = region.boundingRect();
5791 int left = boundingRect.left();
5792 int top = boundingRect.top();
5795 root.setAttribute(
"rows", boundingRect.height() );
5796 root.setAttribute(
"columns", boundingRect.width() );
5798 Region::ConstIterator endOfList = region.constEnd();
5799 for (Region::ConstIterator it = region.constBegin(); it != endOfList; ++it)
5801 TQRect range = (*it)->rect().normalize();
5808 TQDomElement rows = dd.createElement(
"rows");
5809 rows.setAttribute(
"count", range.height() );
5810 rows.setAttribute(
"row", range.top() - top + 1 );
5811 root.appendChild( rows );
5814 for (Cell* cell = d->cells.firstCell(); cell; cell = cell->nextCell())
5818 TQPoint point(cell->
column(), cell->
row());
5819 if (range.contains(point))
5821 root.appendChild(cell->
save( dd, 0, top - 1, copy, copy, era));
5829 for (
int row = range.top(); row <= range.bottom(); ++row)
5831 format = rowFormat( row );
5832 if (format && !format->isDefault())
5834 TQDomElement e = format->save(dd, top - 1, copy);
5837 rows.appendChild( e );
5847 if ((*it)->isColumn())
5849 TQDomElement columns = dd.createElement(
"columns");
5850 columns.setAttribute(
"count", range.width() );
5851 columns.setAttribute(
"column", range.left() - left + 1 );
5852 root.appendChild( columns );
5855 for (Cell* cell = d->cells.firstCell();cell; cell = cell->nextCell())
5859 TQPoint point(cell->
column(), cell->
row());
5860 if (range.contains(point))
5862 root.appendChild(cell->
save( dd, left - 1, 0, copy, copy, era));
5869 ColumnFormat* format;
5870 for (
int col = range.left(); col <= range.right(); ++col)
5872 format = columnFormat(col);
5873 if (format && !format->isDefault())
5875 TQDomElement e = format->save(dd, left - 1, copy);
5878 columns.appendChild(e);
5892 enableScrollBarUpdates(
false);
5893 for (
int col = range.left(); col <= range.right(); ++col)
5895 for (
int row = range.top(); row <= range.bottom(); ++row)
5898 cell = cellAt(col, row);
5899 if (cell == d->defaultCell)
5901 cell =
new Cell(
this, col, row);
5905 root.appendChild(cell->
save(dd, left - 1, top - 1,
true, copy, era));
5908 d->cells.remove(col, row);
5912 enableScrollBarUpdates(
true);
5917TQDomElement Sheet::saveXML( TQDomDocument& dd )
5919 TQDomElement sheet = dd.createElement(
"table" );
5920 sheet.setAttribute(
"name", d->name );
5924 sheet.setAttribute(
"layoutDirection", (d->layoutDirection == RightToLeft) ?
"rtl" :
"ltr" );
5925 sheet.setAttribute(
"columnnumber", (
int)d->showColumnNumber);
5926 sheet.setAttribute(
"borders", (
int)d->showPageBorders);
5927 sheet.setAttribute(
"hide", (
int)d->hide);
5928 sheet.setAttribute(
"hidezero", (
int)d->hideZero);
5929 sheet.setAttribute(
"firstletterupper", (
int)d->firstLetterUpper);
5930 sheet.setAttribute(
"grid", (
int)d->showGrid );
5931 sheet.setAttribute(
"printGrid", (
int)d->print->printGrid() );
5932 sheet.setAttribute(
"printCommentIndicator", (
int)d->print->printCommentIndicator() );
5933 sheet.setAttribute(
"printFormulaIndicator", (
int)d->print->printFormulaIndicator() );
5934 sheet.setAttribute(
"showFormula", (
int)d->showFormula);
5935 sheet.setAttribute(
"showFormulaIndicator", (
int)d->showFormulaIndicator);
5936 sheet.setAttribute(
"showCommentIndicator", (
int)d->showCommentIndicator);
5937 sheet.setAttribute(
"lcmode", (
int)d->lcMode);
5938 sheet.setAttribute(
"autoCalc", (
int)d->autoCalc);
5939 sheet.setAttribute(
"borders1.2", 1);
5940 if ( !d->password.isNull() )
5942 if ( d->password.size() > 0 )
5944 TQCString str = KCodecs::base64Encode( d->password );
5945 sheet.setAttribute(
"protected", TQString( str.data() ) );
5948 sheet.setAttribute(
"protected",
"" );
5952 TQDomElement paper = dd.createElement(
"paper" );
5953 paper.setAttribute(
"format", d->print->paperFormatString() );
5954 paper.setAttribute(
"orientation", d->print->orientationString() );
5955 sheet.appendChild( paper );
5957 TQDomElement borders = dd.createElement(
"borders" );
5958 borders.setAttribute(
"left", d->print->leftBorder() );
5959 borders.setAttribute(
"top", d->print->topBorder() );
5960 borders.setAttribute(
"right", d->print->rightBorder() );
5961 borders.setAttribute(
"bottom", d->print->bottomBorder() );
5962 paper.appendChild( borders );
5964 TQDomElement head = dd.createElement(
"head" );
5965 paper.appendChild( head );
5966 if ( !d->print->headLeft().isEmpty() )
5968 TQDomElement left = dd.createElement(
"left" );
5969 head.appendChild( left );
5970 left.appendChild( dd.createTextNode( d->print->headLeft() ) );
5972 if ( !d->print->headMid().isEmpty() )
5974 TQDomElement center = dd.createElement(
"center" );
5975 head.appendChild( center );
5976 center.appendChild( dd.createTextNode( d->print->headMid() ) );
5978 if ( !d->print->headRight().isEmpty() )
5980 TQDomElement right = dd.createElement(
"right" );
5981 head.appendChild( right );
5982 right.appendChild( dd.createTextNode( d->print->headRight() ) );
5984 TQDomElement foot = dd.createElement(
"foot" );
5985 paper.appendChild( foot );
5986 if ( !d->print->footLeft().isEmpty() )
5988 TQDomElement left = dd.createElement(
"left" );
5989 foot.appendChild( left );
5990 left.appendChild( dd.createTextNode( d->print->footLeft() ) );
5992 if ( !d->print->footMid().isEmpty() )
5994 TQDomElement center = dd.createElement(
"center" );
5995 foot.appendChild( center );
5996 center.appendChild( dd.createTextNode( d->print->footMid() ) );
5998 if ( !d->print->footRight().isEmpty() )
6000 TQDomElement right = dd.createElement(
"right" );
6001 foot.appendChild( right );
6002 right.appendChild( dd.createTextNode( d->print->footRight() ) );
6006 TQDomElement printrange = dd.createElement(
"printrange-rect" );
6007 TQRect _printRange = d->print->printRange();
6008 int left = _printRange.left();
6009 int right = _printRange.right();
6010 int top = _printRange.top();
6011 int bottom = _printRange.bottom();
6013 if ( left == 1 && right == KS_colMax )
6019 if ( top == 1 && bottom == KS_rowMax )
6024 printrange.setAttribute(
"left-rect", left );
6025 printrange.setAttribute(
"right-rect", right );
6026 printrange.setAttribute(
"bottom-rect", bottom );
6027 printrange.setAttribute(
"top-rect", top );
6028 sheet.appendChild( printrange );
6031 TQDomElement printRepeatColumns = dd.createElement(
"printrepeatcolumns" );
6032 printRepeatColumns.setAttribute(
"left", d->print->printRepeatColumns().first );
6033 printRepeatColumns.setAttribute(
"right", d->print->printRepeatColumns().second );
6034 sheet.appendChild( printRepeatColumns );
6037 TQDomElement printRepeatRows = dd.createElement(
"printrepeatrows" );
6038 printRepeatRows.setAttribute(
"top", d->print->printRepeatRows().first );
6039 printRepeatRows.setAttribute(
"bottom", d->print->printRepeatRows().second );
6040 sheet.appendChild( printRepeatRows );
6043 sheet.setAttribute(
"printZoom", d->print->zoom() );
6046 sheet.setAttribute(
"printPageLimitX", d->print->pageLimitX() );
6047 sheet.setAttribute(
"printPageLimitY", d->print->pageLimitY() );
6050 Cell* c = d->cells.firstCell();
6051 for( ;c; c = c->nextCell() )
6053 if ( !c->isDefault() )
6055 TQDomElement e = c->save( dd );
6057 sheet.appendChild( e );
6062 RowFormat* rl = d->rows.first();
6063 for( ; rl; rl = rl->next() )
6065 if ( !rl->isDefault() )
6067 TQDomElement e = rl->save( dd );
6069 return TQDomElement();
6070 sheet.appendChild( e );
6075 ColumnFormat* cl = d->columns.first();
6076 for( ; cl; cl = cl->next() )
6078 if ( !cl->isDefault() )
6080 TQDomElement e = cl->save( dd );
6082 return TQDomElement();
6083 sheet.appendChild( e );
6087 TQPtrListIterator<EmbeddedObject> chl = doc()->embeddedObjects();
6088 for( ; chl.current(); ++chl )
6090 if ( chl.current()->sheet() ==
this )
6092 TQDomElement e = chl.current()->save( dd );
6095 return TQDomElement();
6096 sheet.appendChild( e );
6102bool Sheet::isLoading()
6104 return doc()->isLoading();
6108TQPtrList<EmbeddedObject> Sheet::getSelectedObjects()
6110 TQPtrList<EmbeddedObject> objects;
6111 TQPtrListIterator<EmbeddedObject> it = doc()->embeddedObjects();
6112 for ( ; it.current() ; ++it )
6114 if( it.current()->isSelected()
6115 && it.current()->sheet() ==
this )
6117 objects.append( it.current() );
6123KoRect Sheet::getRealRect(
bool all )
6127 TQPtrListIterator<EmbeddedObject> it( doc()->embeddedObjects() );
6128 for ( ; it.current() ; ++it )
6131 if ( all || ( it.current()->isSelected() && ! it.current()->isProtect() ) )
6132 rect |= it.current()->geometry();
6139KCommand *Sheet::moveObject(View *_view,
double diffx,
double diffy)
6141 bool createCommand=
false;
6142 MoveObjectByCmd *moveByCmd=0L;
6143 Canvas * canvas = _view->canvasWidget();
6144 TQPtrList<EmbeddedObject> _objects;
6145 _objects.setAutoDelete(
false );
6146 TQPtrListIterator<EmbeddedObject> it( doc()->embeddedObjects() );
6147 for ( ; it.current() ; ++it )
6149 if ( it.current()->isSelected() && !it.current()->isProtect())
6151 _objects.append( it.current() );
6152 KoRect geometry = it.current()->geometry();
6153 geometry.moveBy( -canvas->xOffset(), -canvas->yOffset() );
6154 TQRect br = doc()->zoomRect( geometry );
6155 br.moveBy( doc()->zoomItX( diffx ), doc()->zoomItY( diffy ) );
6156 br.moveBy( doc()->zoomItX( -canvas->xOffset() ), doc()->zoomItY( -canvas->yOffset() ) );
6157 canvas->repaint( br );
6158 canvas->repaintObject( it.current() );
6163 moveByCmd =
new MoveObjectByCmd( i18n(
"Move Objects" ), KoPoint( diffx, diffy ),
6164 _objects, doc(),
this );
6171KCommand *Sheet::moveObject(View *_view,
const KoPoint &_move,
bool key)
6173 TQPtrList<EmbeddedObject> _objects;
6174 _objects.setAutoDelete(
false );
6175 MoveObjectByCmd *moveByCmd=0L;
6176 Canvas * canvas = _view->canvasWidget();
6177 TQPtrListIterator<EmbeddedObject> it( doc()->embeddedObjects() );
6178 for ( ; it.current() ; ++it )
6180 if ( it.current()->isSelected() && !it.current()->isProtect()) {
6182 KoRect geometry = it.current()->geometry();
6183 geometry.moveBy( -canvas->xOffset(), -canvas->yOffset() );
6184 TQRect oldBoundingRect = doc()->zoomRect( geometry );
6187 KoRect r = it.current()->geometry();
6188 r.moveBy( _move.x(), _move.y() );
6190 it.current()->setGeometry( r );
6191 _objects.append( it.current() );
6193 canvas->repaint( oldBoundingRect );
6194 canvas->repaintObject( it.current() );
6198 if ( key && !_objects.isEmpty())
6199 moveByCmd =
new MoveObjectByCmd( i18n(
"Move Objects" ),
6201 _objects, doc() ,
this );
6209bool Sheet::objectNameExists( EmbeddedObject *
object, TQPtrList<EmbeddedObject> &list ) {
6210 TQPtrListIterator<EmbeddedObject> it( list );
6212 for ( it.toFirst(); it.current(); ++it ) {
6214 if ( it.current()->getObjectName() ==
object->getObjectName() &&
6215 it.current() != object ) {
6222void Sheet::unifyObjectName( EmbeddedObject *
object ) {
6223 if ( object->getObjectName().isEmpty() ) {
6224 object->setObjectName( object->getTypeString() );
6226 TQString objectName( object->getObjectName() );
6228 TQPtrList<EmbeddedObject> list( doc()->embeddedObjects() );
6232 while ( objectNameExists(
object, list ) ) {
6234 TQRegExp rx(
" \\(\\d{1,3}\\)$" );
6235 if ( rx.search( objectName ) != -1 ) {
6236 objectName.remove( rx );
6238 objectName += TQString(
" (%1)").arg( count );
6239 object->setObjectName( objectName );
6244void Sheet::checkContentDirection( TQString
const & name )
6247 if ( (name.isRightToLeft()) )
6248 setLayoutDirection( RightToLeft );
6250 setLayoutDirection( LeftToRight );
6252 emit sig_refreshView();
6255bool Sheet::loadSheetStyleFormat( TQDomElement *style )
6257 TQString hleft, hmiddle, hright;
6258 TQString fleft, fmiddle, fright;
6259 TQDomNode header = KoDom::namedItemNS( *style, KoXmlNS::style,
"header" );
6261 if ( !header.isNull() )
6263 kdDebug() <<
"Header exists" << endl;
6264 TQDomNode part = KoDom::namedItemNS( header, KoXmlNS::style,
"region-left" );
6265 if ( !part.isNull() )
6267 hleft = getPart( part );
6268 kdDebug() <<
"Header left: " << hleft << endl;
6271 kdDebug() <<
"Style:region:left doesn't exist!" << endl;
6272 part = KoDom::namedItemNS( header, KoXmlNS::style,
"region-center" );
6273 if ( !part.isNull() )
6275 hmiddle = getPart( part );
6276 kdDebug() <<
"Header middle: " << hmiddle << endl;
6278 part = KoDom::namedItemNS( header, KoXmlNS::style,
"region-right" );
6279 if ( !part.isNull() )
6281 hright = getPart( part );
6282 kdDebug() <<
"Header right: " << hright << endl;
6286 TQDomNode headerleft = KoDom::namedItemNS( *style, KoXmlNS::style,
"header-left" );
6287 if ( !headerleft.isNull() )
6289 TQDomElement e = headerleft.toElement();
6290 if ( e.hasAttributeNS( KoXmlNS::style,
"display" ) )
6291 kdDebug()<<
"header.hasAttribute( style:display ) :"<<e.hasAttributeNS( KoXmlNS::style,
"display" )<<endl;
6293 kdDebug()<<
"header left doesn't has attribute style:display \n";
6296 TQDomNode footerleft = KoDom::namedItemNS( *style, KoXmlNS::style,
"footer-left" );
6297 if ( !footerleft.isNull() )
6299 TQDomElement e = footerleft.toElement();
6300 if ( e.hasAttributeNS( KoXmlNS::style,
"display" ) )
6301 kdDebug()<<
"footer.hasAttribute( style:display ) :"<<e.hasAttributeNS( KoXmlNS::style,
"display" )<<endl;
6303 kdDebug()<<
"footer left doesn't has attribute style:display \n";
6306 TQDomNode footer = KoDom::namedItemNS( *style, KoXmlNS::style,
"footer" );
6308 if ( !footer.isNull() )
6310 TQDomNode part = KoDom::namedItemNS( footer, KoXmlNS::style,
"region-left" );
6311 if ( !part.isNull() )
6313 fleft = getPart( part );
6314 kdDebug() <<
"Footer left: " << fleft << endl;
6316 part = KoDom::namedItemNS( footer, KoXmlNS::style,
"region-center" );
6317 if ( !part.isNull() )
6319 fmiddle = getPart( part );
6320 kdDebug() <<
"Footer middle: " << fmiddle << endl;
6322 part = KoDom::namedItemNS( footer, KoXmlNS::style,
"region-right" );
6323 if ( !part.isNull() )
6325 fright = getPart( part );
6326 kdDebug() <<
"Footer right: " << fright << endl;
6330 print()->setHeadFootLine( hleft, hmiddle, hright,
6331 fleft, fmiddle, fright );
6335void Sheet::replaceMacro( TQString & text,
const TQString & old,
const TQString & newS )
6337 int n = text.find( old );
6339 text = text.replace( n, old.length(), newS );
6343TQString Sheet::getPart(
const TQDomNode & part )
6346 TQDomElement e = KoDom::namedItemNS( part, KoXmlNS::text,
"p" );
6347 while ( !e.isNull() )
6349 TQString text = e.text();
6350 kdDebug() <<
"PART: " << text << endl;
6352 TQDomElement macro = KoDom::namedItemNS( e, KoXmlNS::text,
"time" );
6353 if ( !macro.isNull() )
6354 replaceMacro( text, macro.text(),
"<time>" );
6356 macro = KoDom::namedItemNS( e, KoXmlNS::text,
"date" );
6357 if ( !macro.isNull() )
6358 replaceMacro( text, macro.text(),
"<date>" );
6360 macro = KoDom::namedItemNS( e, KoXmlNS::text,
"page-number" );
6361 if ( !macro.isNull() )
6362 replaceMacro( text, macro.text(),
"<page>" );
6364 macro = KoDom::namedItemNS( e, KoXmlNS::text,
"page-count" );
6365 if ( !macro.isNull() )
6366 replaceMacro( text, macro.text(),
"<pages>" );
6368 macro = KoDom::namedItemNS( e, KoXmlNS::text,
"sheet-name" );
6369 if ( !macro.isNull() )
6370 replaceMacro( text, macro.text(),
"<sheet>" );
6372 macro = KoDom::namedItemNS( e, KoXmlNS::text,
"title" );
6373 if ( !macro.isNull() )
6374 replaceMacro( text, macro.text(),
"<name>" );
6376 macro = KoDom::namedItemNS( e, KoXmlNS::text,
"file-name" );
6377 if ( !macro.isNull() )
6378 replaceMacro( text, macro.text(),
"<file>" );
6381 if ( !result.isEmpty() )
6384 e = e.nextSibling().toElement();
6391bool Sheet::loadOasis(
const TQDomElement& sheetElement, KoOasisLoadingContext& oasisContext, TQDict<Style>& styleMap )
6393 d->layoutDirection = LeftToRight;
6394 if ( sheetElement.hasAttributeNS( KoXmlNS::table,
"style-name" ) )
6396 TQString stylename = sheetElement.attributeNS( KoXmlNS::table,
"style-name", TQString() );
6398 const TQDomElement *style = oasisContext.oasisStyles().findStyle( stylename,
"table" );
6403 TQDomElement properties( KoDom::namedItemNS( *style, KoXmlNS::style,
"table-properties" ) );
6404 if ( !properties.isNull() )
6406 if ( properties.hasAttributeNS( KoXmlNS::table,
"display" ) )
6408 bool visible = (properties.attributeNS( KoXmlNS::table,
"display", TQString() ) ==
"true" ? true : false );
6412 if ( style->hasAttributeNS( KoXmlNS::style,
"master-page-name" ) )
6414 TQString masterPageStyleName = style->attributeNS( KoXmlNS::style,
"master-page-name", TQString() );
6416 TQDomElement *masterStyle = oasisContext.oasisStyles().masterPages()[masterPageStyleName];
6420 loadSheetStyleFormat( masterStyle );
6421 if ( masterStyle->hasAttributeNS( KoXmlNS::style,
"page-layout-name" ) )
6423 TQString masterPageLayoutStyleName = masterStyle->attributeNS( KoXmlNS::style,
"page-layout-name", TQString() );
6425 const TQDomElement *masterLayoutStyle = oasisContext.oasisStyles().findStyle( masterPageLayoutStyleName );
6426 if ( masterLayoutStyle )
6429 KoStyleStack styleStack;
6430 styleStack.setTypeProperties(
"page-layout" );
6431 styleStack.push( *masterLayoutStyle );
6432 loadOasisMasterLayoutPage( styleStack );
6441 TQMap<int,TQString> defaultColumnCellStyles;
6445 TQDomNode rowNode = sheetElement.firstChild();
6449 while( !rowNode.isNull() && rowIndex <= KS_rowMax )
6451 kdDebug()<<
" rowIndex :"<<rowIndex<<
" indexCol :"<<indexCol<<endl;
6452 TQDomElement rowElement = rowNode.toElement();
6453 if( !rowElement.isNull() )
6455 kdDebug()<<
" Sheet::loadOasis rowElement.tagName() :"<<rowElement.localName()<<endl;
6456 if ( rowElement.namespaceURI() == KoXmlNS::table )
6458 if ( rowElement.localName()==
"table-column" && indexCol <= KS_colMax )
6460 kdDebug ()<<
" table-column found : index column before "<< indexCol<<endl;
6461 loadColumnFormat( rowElement, oasisContext.oasisStyles(), indexCol , styleMap);
6462 kdDebug ()<<
" table-column found : index column after "<< indexCol<<endl;
6464 else if ( rowElement.localName() ==
"table-header-rows" )
6466 TQDomNode headerRowNode = rowElement.firstChild();
6467 while ( !headerRowNode.isNull() )
6471 loadRowFormat( headerRowNode.toElement(), rowIndex,
6472 oasisContext, styleMap );
6473 headerRowNode = headerRowNode.nextSibling();
6476 else if( rowElement.localName() ==
"table-row" )
6478 kdDebug()<<
" table-row found :index row before "<<rowIndex<<endl;
6479 loadRowFormat( rowElement, rowIndex, oasisContext, styleMap );
6480 kdDebug()<<
" table-row found :index row after "<<rowIndex<<endl;
6482 else if ( rowElement.localName() ==
"shapes" )
6483 loadOasisObjects( rowElement, oasisContext );
6486 rowNode = rowNode.nextSibling();
6489 if ( sheetElement.hasAttributeNS( KoXmlNS::table,
"print-ranges" ) )
6492 TQString range = sheetElement.attributeNS( KoXmlNS::table,
"print-ranges", TQString() );
6493 range = Oasis::decodeFormula( range );
6495 if ( sheetName() == p.sheetName() )
6496 d->print->setPrintRange( p.range() );
6500 if ( sheetElement.attributeNS( KoXmlNS::table,
"protected", TQString() ) ==
"true" )
6502 TQCString passwd(
"" );
6503 if ( sheetElement.hasAttributeNS( KoXmlNS::table,
"protection-key" ) )
6505 TQString p = sheetElement.attributeNS( KoXmlNS::table,
"protection-key", TQString() );
6506 TQCString str( p.latin1() );
6507 kdDebug(30518) <<
"Decoding password: " << str << endl;
6508 passwd = KCodecs::base64Decode( str );
6510 kdDebug(30518) <<
"Password hash: '" << passwd <<
"'" << endl;
6511 d->password = passwd;
6517void Sheet::loadOasisObjects(
const TQDomElement &parent, KoOasisLoadingContext& oasisContext )
6520 TQDomNode n = parent.firstChild();
6521 while( !n.isNull() )
6524 if ( e.localName() ==
"frame" && e.namespaceURI() == KoXmlNS::draw )
6526 EmbeddedObject *obj = 0;
6527 TQDomNode
object = KoDom::namedItemNS( e, KoXmlNS::draw,
"object" );
6528 if ( !
object.isNull() )
6530 if ( !
object.toElement().attributeNS( KoXmlNS::draw,
"notify-on-update-of-ranges", TQString()).isNull() )
6531 obj =
new EmbeddedChart( doc(),
this );
6533 obj =
new EmbeddedKOfficeObject( doc(),
this );
6537 TQDomNode image = KoDom::namedItemNS( e, KoXmlNS::draw,
"image" );
6538 if ( !image.isNull() )
6539 obj =
new EmbeddedPictureObject(
this, doc()->pictureCollection() );
6541 kdDebug() <<
"Object type wasn't loaded!" << endl;
6546 obj->loadOasis( e, oasisContext );
6547 insertObject( obj );
6550 n = n.nextSibling();
6555void Sheet::loadOasisMasterLayoutPage( KoStyleStack &styleStack )
6561 float bottom = 20.0;
6562 float width = 210.0;
6563 float height = 297.0;
6564 TQString orientation =
"Portrait";
6570 if ( styleStack.hasAttributeNS( KoXmlNS::fo,
"page-width" ) )
6572 width = KoUnit::toMM(KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo,
"page-width" ) ) );
6574 if ( styleStack.hasAttributeNS( KoXmlNS::fo,
"page-height" ) )
6576 height = KoUnit::toMM( KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo,
"page-height" ) ) );
6578 if ( styleStack.hasAttributeNS( KoXmlNS::fo,
"margin-top" ) )
6580 top = KoUnit::toMM(KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo,
"margin-top" ) ) );
6582 if ( styleStack.hasAttributeNS( KoXmlNS::fo,
"margin-bottom" ) )
6584 bottom = KoUnit::toMM(KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo,
"margin-bottom" ) ) );
6586 if ( styleStack.hasAttributeNS( KoXmlNS::fo,
"margin-left" ) )
6588 left = KoUnit::toMM(KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo,
"margin-left" ) ) );
6590 if ( styleStack.hasAttributeNS( KoXmlNS::fo,
"margin-right" ) )
6592 right = KoUnit::toMM(KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo,
"margin-right" ) ) );
6594 if ( styleStack.hasAttributeNS( KoXmlNS::style,
"writing-mode" ) )
6596 kdDebug()<<
"styleStack.hasAttribute( style:writing-mode ) :"<<styleStack.hasAttributeNS( KoXmlNS::style,
"writing-mode" )<<endl;
6597 d->layoutDirection = ( styleStack.attributeNS( KoXmlNS::style,
"writing-mode" )==
"lr-tb" ) ? LeftToRight : RightToLeft;
6609 if ( styleStack.hasAttributeNS( KoXmlNS::style,
"print-orientation" ) )
6611 orientation = ( styleStack.attributeNS( KoXmlNS::style,
"print-orientation" )==
"landscape" ) ?
"Landscape" :
"Portrait" ;
6613 if ( styleStack.hasAttributeNS( KoXmlNS::style,
"num-format" ) )
6619 kdDebug()<<
" num-format :"<<styleStack.attributeNS( KoXmlNS::style,
"num-format" )<<endl;
6622 if ( styleStack.hasAttributeNS( KoXmlNS::fo,
"background-color" ) )
6625 kdDebug()<<
" fo:background-color :"<<styleStack.attributeNS( KoXmlNS::fo,
"background-color" )<<endl;
6627 if ( styleStack.hasAttributeNS( KoXmlNS::style,
"print" ) )
6630 TQString str = styleStack.attributeNS( KoXmlNS::style,
"print" );
6631 kdDebug()<<
" style:print :"<<str<<endl;
6633 if (str.contains(
"headers" ) )
6637 if ( str.contains(
"grid" ) )
6639 d->print->setPrintGrid(
true );
6641 if ( str.contains(
"annotations" ) )
6645 if ( str.contains(
"objects" ) )
6649 if ( str.contains(
"charts" ) )
6653 if ( str.contains(
"drawings" ) )
6657 if ( str.contains(
"formulas" ) )
6659 d->showFormula =
true;
6661 if ( str.contains(
"zero-values" ) )
6666 if ( styleStack.hasAttributeNS( KoXmlNS::style,
"table-centering" ) )
6668 TQString str = styleStack.attributeNS( KoXmlNS::style,
"table-centering" );
6670 kdDebug()<<
" styleStack.attribute( style:table-centering ) :"<<str<<endl;
6672 if ( str ==
"horizontal" )
6675 else if ( str ==
"vertical" )
6678 else if ( str ==
"both" )
6681 else if ( str ==
"none" )
6685 kdDebug()<<
" table-centering unknown :"<<str<<endl;
6688 format = TQString(
"%1x%2" ).arg( width ).arg( height );
6689 kdDebug()<<
" format : "<<format<<endl;
6690 d->print->setPaperLayout( left, top, right, bottom, format, orientation );
6692 kdDebug()<<
" left margin :"<<left<<
" right :"<<right<<
" top :"<<top<<
" bottom :"<<bottom<<endl;
6701bool Sheet::loadColumnFormat(
const TQDomElement& column,
const KoOasisStyles& oasisStyles,
int & indexCol,
const TQDict<Style>& styleMap)
6703 kdDebug()<<
"bool Sheet::loadColumnFormat(const TQDomElement& column, const KoOasisStyles& oasisStyles, unsigned int & indexCol ) index Col :"<<indexCol<<endl;
6705 bool isNonDefaultColumn =
false;
6708 if ( column.hasAttributeNS( KoXmlNS::table,
"number-columns-repeated" ) )
6711 int n = column.attributeNS( KoXmlNS::table,
"number-columns-repeated", TQString() ).toInt( &ok );
6716 number = TQMIN( n, KS_colMax - indexCol + 1 );
6717 kdDebug() <<
"Repeated: " << number << endl;
6720 Format layout(
this , doc()->styleManager()->defaultStyle() );
6721 if ( column.hasAttributeNS( KoXmlNS::table,
"default-cell-style-name" ) )
6723 const TQString styleName = column.attributeNS( KoXmlNS::table,
"default-cell-style-name", TQString() );
6724 if ( !styleName.isEmpty() )
6726 Style*
const style = styleMap[ styleName ];
6729 layout.setStyle( style );
6730 isNonDefaultColumn =
true;
6735 bool collapsed =
false;
6736 if ( column.hasAttributeNS( KoXmlNS::table,
"visibility" ) )
6738 const TQString visibility = column.attributeNS( KoXmlNS::table,
"visibility", TQString() );
6739 if ( visibility ==
"visible" )
6741 else if ( visibility ==
"collapse" )
6743 else if ( visibility ==
"filter" )
6745 isNonDefaultColumn =
true;
6748 KoStyleStack styleStack;
6749 if ( column.hasAttributeNS( KoXmlNS::table,
"style-name" ) )
6751 TQString str = column.attributeNS( KoXmlNS::table,
"style-name", TQString() );
6752 const TQDomElement *style = oasisStyles.findStyle( str,
"table-column" );
6755 styleStack.push( *style );
6756 isNonDefaultColumn =
true;
6759 styleStack.setTypeProperties(
"table-column");
6761 double width = -1.0;
6762 if ( styleStack.hasAttributeNS( KoXmlNS::style,
"column-width" ) )
6764 width = KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::style,
"column-width" ) , -1.0 );
6765 kdDebug()<<
" style:column-width : width :"<<width<<endl;
6766 isNonDefaultColumn =
true;
6769 bool insertPageBreak =
false;
6770 if ( styleStack.hasAttributeNS( KoXmlNS::fo,
"break-before" ) )
6772 TQString str = styleStack.attributeNS( KoXmlNS::fo,
"break-before" );
6773 if ( str ==
"page" )
6775 insertPageBreak =
true;
6778 kdDebug()<<
" str :"<<str<<endl;
6779 isNonDefaultColumn =
true;
6782 for (
int i = 0; i < number; ++i )
6786 ColumnFormat* columnFormat;
6787 if ( isNonDefaultColumn )
6789 columnFormat = nonDefaultColumnFormat( indexCol );
6791 if ( width != -1.0 )
6792 columnFormat->setWidth( (
int) width );
6796 columnFormat->setHide(
true );
6800 columnFormat = this->columnFormat( indexCol );
6802 columnFormat->copy( layout );
6811bool Sheet::loadRowFormat(
const TQDomElement& row,
int &rowIndex, KoOasisLoadingContext& oasisContext, TQDict<Style>& styleMap )
6815 int backupRow = rowIndex;
6816 bool isNonDefaultRow =
false;
6818 KoStyleStack styleStack;
6819 if ( row.hasAttributeNS( KoXmlNS::table,
"style-name" ) )
6821 TQString str = row.attributeNS( KoXmlNS::table,
"style-name", TQString() );
6822 const TQDomElement *style = oasisContext.oasisStyles().findStyle( str,
"table-row" );
6825 styleStack.push( *style );
6826 isNonDefaultRow =
true;
6829 styleStack.setTypeProperties(
"table-row" );
6831 Format layout(
this , doc()->styleManager()->defaultStyle() );
6832 if ( row.hasAttributeNS( KoXmlNS::table,
"default-cell-style-name" ) )
6834 const TQString styleName = row.attributeNS( KoXmlNS::table,
"default-cell-style-name", TQString() );
6835 if ( !styleName.isEmpty() )
6837 Style*
const style = styleMap[ styleName ];
6840 layout.setStyle( style );
6841 isNonDefaultRow =
true;
6846 double height = -1.0;
6847 if ( styleStack.hasAttributeNS( KoXmlNS::style,
"row-height" ) )
6849 height = KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::style,
"row-height" ) , -1.0 );
6851 isNonDefaultRow =
true;
6855 if ( row.hasAttributeNS( KoXmlNS::table,
"number-rows-repeated" ) )
6858 int n = row.attributeNS( KoXmlNS::table,
"number-rows-repeated", TQString() ).toInt( &ok );
6863 number = TQMIN( n, KS_rowMax - rowIndex + 1 );
6866 bool collapse =
false;
6867 if ( row.hasAttributeNS( KoXmlNS::table,
"visibility" ) )
6869 const TQString visibility = row.attributeNS( KoXmlNS::table,
"visibility", TQString() );
6870 if ( visibility ==
"visible" )
6872 else if ( visibility ==
"collapse" )
6874 else if ( visibility ==
"filter" )
6876 isNonDefaultRow =
true;
6879 bool insertPageBreak =
false;
6880 if ( styleStack.hasAttributeNS( KoXmlNS::fo,
"break-before" ) )
6882 TQString str = styleStack.attributeNS( KoXmlNS::fo,
"break-before" );
6883 if ( str ==
"page" )
6885 insertPageBreak =
true;
6889 isNonDefaultRow =
true;
6893 for (
int i = 0; i < number; ++i )
6897 RowFormat* rowFormat;
6898 if ( isNonDefaultRow )
6900 rowFormat = nonDefaultRowFormat( rowIndex );
6902 if ( height != -1.0 )
6903 rowFormat->setHeight( (
int) height );
6905 rowFormat->setHide(
true );
6909 rowFormat = this->rowFormat( rowIndex );
6911 rowFormat->copy( layout );
6916 int columnIndex = 0;
6917 TQDomNode cellNode = row.firstChild();
6918 int endRow = min(backupRow+number,KS_rowMax);
6921 while ( !cellNode.isNull() )
6923 TQDomElement cellElement = cellNode.toElement();
6924 if ( !cellElement.isNull() )
6927 TQString localName = cellElement.localName();
6929 if ( ((localName ==
"table-cell") || (localName ==
"covered-table-cell")) && cellElement.namespaceURI() == KoXmlNS::table)
6934 const bool cellHasStyle = cellElement.hasAttributeNS( KoXmlNS::table,
"style-name" );
6937 style = styleMap[ cellElement.attributeNS( KoXmlNS::table ,
"style-name" , TQString() ) ];
6940 Cell*
const cell = nonDefaultCell( columnIndex, backupRow );
6941 cell->
loadOasis( cellElement, oasisContext, style );
6947 if ( (number > 1) || cellElement.hasAttributeNS( KoXmlNS::table,
"number-columns-repeated" ) )
6950 int n = cellElement.attributeNS( KoXmlNS::table,
"number-columns-repeated", TQString() ).toInt( &ok );
6956 cols = TQMIN( n, KS_colMax - columnIndex + 1 );
6958 if ( !cellHasStyle && ( cell->
isEmpty() && cell->
format()->comment( columnIndex, backupRow ).isEmpty() ) )
6961 columnIndex += cols - 1;
6965 for (
int k = cols ; k ; --k )
6970 for (
int newRow = backupRow; newRow < endRow; ++newRow )
6972 Cell* target = nonDefaultCell( columnIndex, newRow );
6975 target->copyAll( cell );
6982 cellNode = cellNode.nextSibling();
6988void Sheet::maxRowCols(
int & maxCols,
int & maxRows )
6990 const Cell * cell = firstCell();
6993 if ( cell->
column() > maxCols )
6994 maxCols = cell->
column();
6996 if ( cell->
row() > maxRows )
6997 maxRows = cell->
row();
6999 cell = cell->nextCell();
7002 const RowFormat * row = firstRow();
7005 if ( row->row() > maxRows )
7006 maxRows = row->row();
7010 const ColumnFormat* col = firstCol();
7013 if ( col->column() > maxCols )
7014 maxCols = col->column();
7021bool Sheet::compareRows(
int row1,
int row2,
int& maxCols )
const
7023 if ( *rowFormat( row1 ) != *rowFormat( row2 ) )
7029 for (
int col = 1; col <= maxCols; ++col )
7031 if ( *cellAt( col, row1 ) != *cellAt( col, row2 ) )
7041void Sheet::saveOasisHeaderFooter( KoXmlWriter &xmlWriter )
const
7043 TQString headerLeft = print()->headLeft();
7044 TQString headerCenter= print()->headMid();
7045 TQString headerRight = print()->headRight();
7047 TQString footerLeft = print()->footLeft();
7048 TQString footerCenter= print()->footMid();
7049 TQString footerRight = print()->footRight();
7051 xmlWriter.startElement(
"style:header");
7052 if ( ( !headerLeft.isEmpty() )
7053 || ( !headerCenter.isEmpty() )
7054 || ( !headerRight.isEmpty() ) )
7056 xmlWriter.startElement(
"style:region-left" );
7057 xmlWriter.startElement(
"text:p" );
7058 convertPart( headerLeft, xmlWriter );
7059 xmlWriter.endElement();
7060 xmlWriter.endElement();
7062 xmlWriter.startElement(
"style:region-center" );
7063 xmlWriter.startElement(
"text:p" );
7064 convertPart( headerCenter, xmlWriter );
7065 xmlWriter.endElement();
7066 xmlWriter.endElement();
7068 xmlWriter.startElement(
"style:region-right" );
7069 xmlWriter.startElement(
"text:p" );
7070 convertPart( headerRight, xmlWriter );
7071 xmlWriter.endElement();
7072 xmlWriter.endElement();
7076 xmlWriter.startElement(
"text:p" );
7078 xmlWriter.startElement(
"text:sheet-name" );
7079 xmlWriter.addTextNode(
"???" );
7080 xmlWriter.endElement();
7082 xmlWriter.endElement();
7084 xmlWriter.endElement();
7087 xmlWriter.startElement(
"style:footer");
7088 if ( ( !footerLeft.isEmpty() )
7089 || ( !footerCenter.isEmpty() )
7090 || ( !footerRight.isEmpty() ) )
7092 xmlWriter.startElement(
"style:region-left" );
7093 xmlWriter.startElement(
"text:p" );
7094 convertPart( footerLeft, xmlWriter );
7095 xmlWriter.endElement();
7096 xmlWriter.endElement();
7098 xmlWriter.startElement(
"style:region-center" );
7099 xmlWriter.startElement(
"text:p" );
7100 convertPart( footerCenter, xmlWriter );
7101 xmlWriter.endElement();
7102 xmlWriter.endElement();
7104 xmlWriter.startElement(
"style:region-right" );
7105 xmlWriter.startElement(
"text:p" );
7106 convertPart( footerRight, xmlWriter );
7107 xmlWriter.endElement();
7108 xmlWriter.endElement();
7112 xmlWriter.startElement(
"text:p" );
7114 xmlWriter.startElement(
"text:sheet-name" );
7115 xmlWriter.addTextNode(
"Page " );
7116 xmlWriter.endElement();
7118 xmlWriter.startElement(
"text:page-number" );
7119 xmlWriter.addTextNode(
"1" );
7120 xmlWriter.endElement();
7122 xmlWriter.endElement();
7124 xmlWriter.endElement();
7129void Sheet::addText(
const TQString & text, KoXmlWriter & writer )
const
7131 if ( !text.isEmpty() )
7132 writer.addTextNode( text );
7135void Sheet::convertPart(
const TQString & part, KoXmlWriter & xmlWriter )
const
7142 uint l = part.length();
7145 if ( inVar || part[i] ==
'<' )
7149 if ( part[i] ==
'>' )
7152 if ( var ==
"<page>" )
7154 addText( text, xmlWriter );
7155 xmlWriter.startElement(
"text:page-number" );
7156 xmlWriter.addTextNode(
"1" );
7157 xmlWriter.endElement();
7159 else if ( var ==
"<pages>" )
7161 addText( text, xmlWriter );
7162 xmlWriter.startElement(
"text:page-count" );
7163 xmlWriter.addTextNode(
"99" );
7164 xmlWriter.endElement();
7166 else if ( var ==
"<date>" )
7168 addText( text, xmlWriter );
7171 TQDomElement t = dd.createElement(
"text:date" );
7172 t.setAttribute(
"text:date-value",
"0-00-00" );
7174 t.appendChild( dd.createTextNode( TQDate::currentDate().toString() ) );
7175 parent.appendChild( t );
7178 else if ( var ==
"<time>" )
7180 addText( text, xmlWriter );
7182 xmlWriter.startElement(
"text:time" );
7183 xmlWriter.addTextNode( TQTime::currentTime().toString() );
7184 xmlWriter.endElement();
7186 else if ( var ==
"<file>" )
7188 addText( text, xmlWriter );
7189 xmlWriter.startElement(
"text:file-name" );
7190 xmlWriter.addAttribute(
"text:display",
"full" );
7191 xmlWriter.addTextNode(
"???" );
7192 xmlWriter.endElement();
7194 else if ( var ==
"<name>" )
7196 addText( text, xmlWriter );
7198 xmlWriter.startElement(
"text:title" );
7199 xmlWriter.addTextNode(
"???" );
7200 xmlWriter.endElement();
7202 else if ( var ==
"<author>" )
7204 Doc* sdoc = d->workbook->doc();
7205 KoDocumentInfo * docInfo = sdoc->documentInfo();
7206 KoDocumentInfoAuthor * authorPage =
static_cast<KoDocumentInfoAuthor*
>( docInfo->page(
"author" ) );
7208 text += authorPage->fullName();
7210 addText( text, xmlWriter );
7212 else if ( var ==
"<email>" )
7214 Doc* sdoc = d->workbook->doc();
7215 KoDocumentInfo * docInfo = sdoc->documentInfo();
7216 KoDocumentInfoAuthor * authorPage =
static_cast<KoDocumentInfoAuthor*
>( docInfo->page(
"author" ) );
7218 text += authorPage->email();
7219 addText( text, xmlWriter );
7222 else if ( var ==
"<org>" )
7224 Doc* sdoc = d->workbook->doc();
7225 KoDocumentInfo * docInfo = sdoc->documentInfo();
7226 KoDocumentInfoAuthor * authorPage =
static_cast<KoDocumentInfoAuthor*
>( docInfo->page(
"author" ) );
7228 text += authorPage->company();
7229 addText( text, xmlWriter );
7232 else if ( var ==
"<sheet>" )
7234 addText( text, xmlWriter );
7236 xmlWriter.startElement(
"text:sheet-name" );
7237 xmlWriter.addTextNode(
"???" );
7238 xmlWriter.endElement();
7244 addText( text, xmlWriter );
7257 if ( !text.isEmpty() || !var.isEmpty() )
7260 addText( text+var, xmlWriter );
7262 kdDebug()<<
" text end :"<<text<<
" var :"<<var<<endl;
7266void Sheet::loadOasisSettings(
const KoOasisSettings::NamedMap &settings )
7269 KoOasisSettings::Items items = settings.entry( d->name );
7270 if ( items.isNull() )
7272 d->hideZero = items.parseConfigItemBool(
"ShowZeroValues" );
7273 d->showGrid = items.parseConfigItemBool(
"ShowGrid" );
7274 d->firstLetterUpper = items.parseConfigItemBool(
"FirstLetterUpper" );
7276 int cursorX = items.parseConfigItemInt(
"CursorPositionX" );
7277 int cursorY = items.parseConfigItemInt(
"CursorPositionY" );
7278 doc()->loadingInfo()->setCursorPosition(
this, TQPoint( cursorX, cursorY ) );
7280 double offsetX = items.parseConfigItemDouble(
"xOffset" );
7281 double offsetY = items.parseConfigItemDouble(
"yOffset" );
7282 doc()->loadingInfo()->setScrollingOffset(
this, KoPoint( offsetX, offsetY ) );
7284 d->showFormulaIndicator = items.parseConfigItemBool(
"ShowFormulaIndicator" );
7285 d->showCommentIndicator = items.parseConfigItemBool(
"ShowCommentIndicator" );
7286 d->showPageBorders = items.parseConfigItemBool(
"ShowPageBorders" );
7287 d->lcMode = items.parseConfigItemBool(
"lcmode" );
7288 d->autoCalc = items.parseConfigItemBool(
"autoCalc" );
7289 d->showColumnNumber = items.parseConfigItemBool(
"ShowColumnNumber" );
7292void Sheet::saveOasisSettings( KoXmlWriter &settingsWriter )
const
7295 settingsWriter.addConfigItem(
"ShowZeroValues", d->hideZero );
7296 settingsWriter.addConfigItem(
"ShowGrid", d->showGrid );
7298 settingsWriter.addConfigItem(
"FirstLetterUpper", d->firstLetterUpper);
7299 settingsWriter.addConfigItem(
"ShowFormulaIndicator", d->showFormulaIndicator );
7300 settingsWriter.addConfigItem(
"ShowCommentIndicator", d->showCommentIndicator );
7301 settingsWriter.addConfigItem(
"ShowPageBorders",d->showPageBorders );
7302 settingsWriter.addConfigItem(
"lcmode", d->lcMode );
7303 settingsWriter.addConfigItem(
"autoCalc", d->autoCalc );
7304 settingsWriter.addConfigItem(
"ShowColumnNumber", d->showColumnNumber );
7307bool Sheet::saveOasis( KoXmlWriter & xmlWriter, KoGenStyles &mainStyles, GenValidationStyles &valStyle, KoStore *store, KoXmlWriter* ,
int &indexObj,
int &partIndexObj )
7311 xmlWriter.startElement(
"table:table" );
7312 xmlWriter.addAttribute(
"table:name", d->name );
7313 xmlWriter.addAttribute(
"table:style-name", saveOasisSheetStyleName(mainStyles ) );
7314 if ( !d->password.isEmpty() )
7316 xmlWriter.addAttribute(
"table:protected",
"true" );
7317 TQCString str = KCodecs::base64Encode( d->password );
7318 xmlWriter.addAttribute(
"table:protection-key", TQString( str.data() ) );
7320 TQRect _printRange = d->print->printRange();
7321 if ( _printRange != ( TQRect( TQPoint( 1, 1 ), TQPoint( KS_colMax, KS_rowMax ) ) ) )
7323 TQString range= convertRangeToRef( d->name, _printRange );
7324 kdDebug()<<
" range : "<<range<<endl;
7325 xmlWriter.addAttribute(
"table:print-ranges", range );
7328 saveOasisObjects( store, xmlWriter, mainStyles, indexObj, partIndexObj );
7329 maxRowCols( maxCols, maxRows );
7330 saveOasisColRowCell( xmlWriter, mainStyles, maxCols, maxRows, valStyle );
7331 xmlWriter.endElement();
7335void Sheet::saveOasisPrintStyleLayout( KoGenStyle &style )
const
7337 TQString printParameter;
7338 if ( d->print->printGrid() )
7339 printParameter=
"grid ";
7340 if ( d->print->printObjects() )
7341 printParameter+=
"objects ";
7342 if ( d->print->printCharts() )
7343 printParameter+=
"charts ";
7344 if ( d->showFormula )
7345 printParameter+=
"formulas ";
7346 if ( !printParameter.isEmpty() )
7348 printParameter+=
"drawings zero-values";
7349 style.addProperty(
"style:print", printParameter );
7353TQString Sheet::saveOasisSheetStyleName( KoGenStyles &mainStyles )
7355 KoGenStyle pageStyle( Doc::STYLE_PAGE,
"table" );
7357 KoGenStyle pageMaster( Doc::STYLE_PAGEMASTER );
7358 pageMaster.addAttribute(
"style:page-layout-name", d->print->saveOasisSheetStyleLayout( mainStyles ) );
7361 buffer.open( IO_WriteOnly );
7362 KoXmlWriter elementWriter( &buffer );
7363 saveOasisHeaderFooter(elementWriter);
7365 TQString elementContents = TQString::fromUtf8( buffer.buffer(), buffer.buffer().size() );
7366 pageMaster.addChildElement(
"headerfooter", elementContents );
7367 pageStyle.addAttribute(
"style:master-page-name", mainStyles.lookup( pageMaster,
"Standard" ) );
7369 pageStyle.addProperty(
"table:display", !d->hide );
7370 return mainStyles.lookup( pageStyle,
"ta" );
7374void Sheet::saveOasisColRowCell( KoXmlWriter& xmlWriter, KoGenStyles &mainStyles,
7375 int maxCols,
int maxRows, GenValidationStyles &valStyle )
7377 kdDebug() <<
"Sheet::saveOasisColRowCell: " << d->name << endl;
7378 kdDebug() <<
"\t Sheet dimension: " << maxCols <<
" x " << maxRows << endl;
7383 while ( i <= maxCols )
7388 ColumnFormat* column = columnFormat( i );
7391 currentColumnStyle.addPropertyPt(
"style:column-width", column->dblWidth() );
7392 currentColumnStyle.addProperty(
"fo:break-before",
"auto" );
7395 KoGenStyle currentDefaultCellStyle;
7396 TQString currentDefaultCellStyleName = column->saveOasisCellStyle( currentDefaultCellStyle, mainStyles );
7399 bool hide = column->isHide();
7400 bool refColumnIsDefault = column->isDefault();
7404 while ( j <= maxCols )
7409 ColumnFormat* nextColumn = d->columns.next( j++ );
7412 if ( !nextColumn || nextColumn->column() != j )
7414 if ( refColumnIsDefault )
7420 repeated = maxCols - i + 1;
7424 repeated = nextColumn->column() - j + 1;
7433 nextColumnStyle.addPropertyPt(
"style:column-width", nextColumn->dblWidth() );
7434 nextColumnStyle.addProperty(
"fo:break-before",
"auto" );
7436 KoGenStyle nextDefaultCellStyle;
7437 TQString nextDefaultCellStyleName = nextColumn->saveOasisCellStyle( nextDefaultCellStyle, mainStyles );
7439 if ( hide != nextColumn->isHide() ||
7440 nextDefaultCellStyleName != currentDefaultCellStyleName ||
7441 !( nextColumnStyle == currentColumnStyle ) )
7446 if ( *column != *nextColumn )
7452 xmlWriter.startElement(
"table:table-column" );
7453 if ( !column->isDefault() )
7455 xmlWriter.addAttribute(
"table:style-name", mainStyles.lookup( currentColumnStyle,
"co" ) );
7457 if ( !currentDefaultCellStyle.isDefaultStyle() )
7458 xmlWriter.addAttribute(
"table:default-cell-style-name", currentDefaultCellStyleName );
7461 xmlWriter.addAttribute(
"table:visibility",
"collapse" );
7465 xmlWriter.addAttribute(
"table:number-columns-repeated", repeated );
7467 xmlWriter.endElement();
7469 kdDebug() <<
"Sheet::saveOasisColRowCell: column " << i <<
" "
7470 <<
"repeated " << repeated <<
" time(s)" << endl;
7477 for ( i = 1; i <= maxRows; ++i )
7479 RowFormat*
const row = rowFormat( i );
7482 currentRowStyle.addPropertyPt(
"style:row-height", row->dblHeight() );
7483 currentRowStyle.addProperty(
"fo:break-before",
"auto" );
7486 KoGenStyle currentDefaultCellStyle;
7487 TQString currentDefaultCellStyleName = row->saveOasisCellStyle( currentDefaultCellStyle, mainStyles );
7489 xmlWriter.startElement(
"table:table-row" );
7491 if ( !row->isDefault() )
7493 xmlWriter.addAttribute(
"table:style-name", mainStyles.lookup( currentRowStyle,
"ro" ) );
7497 if ( !getFirstCellRow( i ) )
7503 bool isDefault = row->isDefault();
7510 while ( j <= maxRows && !getFirstCellRow( j ) )
7512 RowFormat*
const nextRow = rowFormat( j );
7521 if ( !nextRow->isDefault() )
7530 nextRowStyle.addPropertyPt(
"style:row-height", nextRow->dblHeight() );
7531 nextRowStyle.addProperty(
"fo:break-before",
"auto" );
7534 KoGenStyle nextDefaultCellStyle;
7535 TQString nextDefaultCellStyleName = nextRow->saveOasisCellStyle( nextDefaultCellStyle, mainStyles );
7538 if ( isHidden != nextRow->isHide() ||
7539 nextDefaultCellStyleName != currentDefaultCellStyleName ||
7540 !(nextRowStyle == currentRowStyle) )
7545 if ( *row != *nextRow )
7555 xmlWriter.addAttribute(
"table:number-rows-repeated", repeated );
7556 if ( !currentDefaultCellStyle.isDefaultStyle() )
7557 xmlWriter.addAttribute(
"table:default-cell-style-name", currentDefaultCellStyleName );
7558 if ( row->isHide() )
7559 xmlWriter.addAttribute(
"table:visibility",
"collapse" );
7563 xmlWriter.startElement(
"table:table-cell" );
7564 xmlWriter.endElement();
7566 kdDebug() <<
"Sheet::saveOasisColRowCell: empty row " << i <<
' '
7567 <<
"repeated " << repeated <<
" time(s)" << endl;
7574 if ( !currentDefaultCellStyle.isDefaultStyle() )
7575 xmlWriter.addAttribute(
"table:default-cell-style-name", currentDefaultCellStyleName );
7576 if ( row->isHide() )
7577 xmlWriter.addAttribute(
"table:visibility",
"collapse" );
7580 while ( compareRows( i, j, maxCols ) && j <= maxRows )
7587 kdDebug() <<
"Sheet::saveOasisColRowCell: NON-empty row " << i <<
' '
7588 <<
"repeated " << repeated <<
" times" << endl;
7590 xmlWriter.addAttribute(
"table:number-rows-repeated", repeated );
7593 saveOasisCells( xmlWriter, mainStyles, i, maxCols, valStyle );
7598 xmlWriter.endElement();
7602void Sheet::saveOasisCells( KoXmlWriter& xmlWriter, KoGenStyles &mainStyles,
int row,
int maxCols, GenValidationStyles &valStyle )
7605 Cell* cell = cellAt( i, row );
7606 Cell* nextCell = getNextCellRight( i, row );
7611 while ( !cell->
isDefault() || nextCell )
7613 kdDebug() <<
"Sheet::saveOasisCells:"
7617 cell->saveOasis( xmlWriter, mainStyles, row, i, repeated, valStyle );
7622 cell = cellAt( i, row );
7623 nextCell = getNextCellRight( i, row );
7627bool Sheet::loadXML(
const TQDomElement& sheet )
7630 if ( !doc()->loadingInfo() || !doc()->loadingInfo()->loadTemplate() )
7632 d->name = sheet.attribute(
"name" );
7633 if ( d->name.isEmpty() )
7635 doc()->setErrorMessage( i18n(
"Invalid document. Sheet name is empty.") );
7640 bool detectDirection =
true;
7641 d->layoutDirection = LeftToRight;
7642 TQString layoutDir = sheet.attribute(
"layoutDirection" );
7643 if( !layoutDir.isEmpty() )
7645 if( layoutDir ==
"rtl" )
7647 detectDirection =
false;
7648 d->layoutDirection = RightToLeft;
7650 else if( layoutDir ==
"ltr" )
7652 detectDirection =
false;
7653 d->layoutDirection = LeftToRight;
7656 kdDebug()<<
" Direction not implemented : "<<layoutDir<<endl;
7658 if( detectDirection )
7659 checkContentDirection( d->name );
7665 if (d->name[0] ==
' ')
7667 d->name.remove(0,1);
7669 for (
unsigned int i=0; i < d->name.length(); i++)
7671 if ( !(d->name[i].isLetterOrNumber() ||
7672 d->name[i] ==
' ' || d->name[i] ==
'.' ||
7689 while (workbook()->findSheet(testName) != NULL)
7692 testName = baseName +
'_' + TQString::number(nameSuffix);
7696 kdDebug(36001)<<
"Sheet::loadXML: table name="<<d->name<<endl;
7697 setName(d->name.utf8());
7698 (
dynamic_cast<SheetIface*
>(dcopObject()))->sheetNameHasChanged();
7700 if( sheet.hasAttribute(
"grid" ) )
7702 d->showGrid = (int)sheet.attribute(
"grid").toInt( &ok );
7705 if( sheet.hasAttribute(
"printGrid" ) )
7707 d->print->setPrintGrid( (
bool)sheet.attribute(
"printGrid").toInt( &ok ) );
7710 if( sheet.hasAttribute(
"printCommentIndicator" ) )
7712 d->print->setPrintCommentIndicator( (
bool)sheet.attribute(
"printCommentIndicator").toInt( &ok ) );
7715 if( sheet.hasAttribute(
"printFormulaIndicator" ) )
7717 d->print->setPrintFormulaIndicator( (
bool)sheet.attribute(
"printFormulaIndicator").toInt( &ok ) );
7720 if( sheet.hasAttribute(
"hide" ) )
7722 d->hide = (bool)sheet.attribute(
"hide").toInt( &ok );
7725 if( sheet.hasAttribute(
"showFormula" ) )
7727 d->showFormula = (bool)sheet.attribute(
"showFormula").toInt( &ok );
7731 if( sheet.hasAttribute(
"formular" ) )
7733 d->showFormula = (bool)sheet.attribute(
"formular").toInt( &ok );
7736 if( sheet.hasAttribute(
"showFormulaIndicator" ) )
7738 d->showFormulaIndicator = (bool)sheet.attribute(
"showFormulaIndicator").toInt( &ok );
7741 if( sheet.hasAttribute(
"showCommentIndicator" ) )
7743 d->showCommentIndicator = (bool)sheet.attribute(
"showCommentIndicator").toInt( &ok );
7746 if( sheet.hasAttribute(
"borders" ) )
7748 d->showPageBorders = (bool)sheet.attribute(
"borders").toInt( &ok );
7751 if( sheet.hasAttribute(
"lcmode" ) )
7753 d->lcMode = (bool)sheet.attribute(
"lcmode").toInt( &ok );
7756 if ( sheet.hasAttribute(
"autoCalc" ) )
7758 d->autoCalc = ( bool )sheet.attribute(
"autoCalc" ).toInt( &ok );
7761 if( sheet.hasAttribute(
"columnnumber" ) )
7763 d->showColumnNumber = (bool)sheet.attribute(
"columnnumber").toInt( &ok );
7766 if( sheet.hasAttribute(
"hidezero" ) )
7768 d->hideZero = (bool)sheet.attribute(
"hidezero").toInt( &ok );
7771 if( sheet.hasAttribute(
"firstletterupper" ) )
7773 d->firstLetterUpper = (bool)sheet.attribute(
"firstletterupper").toInt( &ok );
7778 TQDomElement paper = sheet.namedItem(
"paper" ).toElement();
7779 if ( !paper.isNull() )
7781 TQString format = paper.attribute(
"format" );
7782 TQString orientation = paper.attribute(
"orientation" );
7785 TQDomElement borders = paper.namedItem(
"borders" ).toElement();
7786 if ( !borders.isNull() )
7788 float left = borders.attribute(
"left" ).toFloat();
7789 float right = borders.attribute(
"right" ).toFloat();
7790 float top = borders.attribute(
"top" ).toFloat();
7791 float bottom = borders.attribute(
"bottom" ).toFloat();
7792 d->print->setPaperLayout( left, top, right, bottom, format, orientation );
7794 TQString hleft, hright, hcenter;
7795 TQString fleft, fright, fcenter;
7797 TQDomElement head = paper.namedItem(
"head" ).toElement();
7798 if ( !head.isNull() )
7800 TQDomElement left = head.namedItem(
"left" ).toElement();
7801 if ( !left.isNull() )
7802 hleft = left.text();
7803 TQDomElement center = head.namedItem(
"center" ).toElement();
7804 if ( !center.isNull() )
7805 hcenter = center.text();
7806 TQDomElement right = head.namedItem(
"right" ).toElement();
7807 if ( !right.isNull() )
7808 hright = right.text();
7811 TQDomElement foot = paper.namedItem(
"foot" ).toElement();
7812 if ( !foot.isNull() )
7814 TQDomElement left = foot.namedItem(
"left" ).toElement();
7815 if ( !left.isNull() )
7816 fleft = left.text();
7817 TQDomElement center = foot.namedItem(
"center" ).toElement();
7818 if ( !center.isNull() )
7819 fcenter = center.text();
7820 TQDomElement right = foot.namedItem(
"right" ).toElement();
7821 if ( !right.isNull() )
7822 fright = right.text();
7824 d->print->setHeadFootLine( hleft, hcenter, hright, fleft, fcenter, fright);
7828 TQDomElement printrange = sheet.namedItem(
"printrange-rect" ).toElement();
7829 if ( !printrange.isNull() )
7831 int left = printrange.attribute(
"left-rect" ).toInt();
7832 int right = printrange.attribute(
"right-rect" ).toInt();
7833 int bottom = printrange.attribute(
"bottom-rect" ).toInt();
7834 int top = printrange.attribute(
"top-rect" ).toInt();
7845 d->print->setPrintRange( TQRect( TQPoint( left, top ), TQPoint( right, bottom ) ) );
7849 if( sheet.hasAttribute(
"printZoom" ) )
7851 double zoom = sheet.attribute(
"printZoom" ).toDouble( &ok );
7854 d->print->setZoom( zoom );
7859 if( sheet.hasAttribute(
"printPageLimitX" ) )
7861 int pageLimit = sheet.attribute(
"printPageLimitX" ).toInt( &ok );
7864 d->print->setPageLimitX( pageLimit );
7869 if( sheet.hasAttribute(
"printPageLimitY" ) )
7871 int pageLimit = sheet.attribute(
"printPageLimitY" ).toInt( &ok );
7874 d->print->setPageLimitY( pageLimit );
7879 TQDomNode n = sheet.firstChild();
7880 while( !n.isNull() )
7882 TQDomElement e = n.toElement();
7885 TQString tagName=e.tagName();
7886 if ( tagName ==
"cell" )
7888 Cell *cell =
new Cell(
this, 0, 0 );
7889 if ( cell->load( e, 0, 0 ) )
7894 else if ( tagName ==
"row" )
7896 RowFormat *rl =
new RowFormat(
this, 0 );
7897 if ( rl->load( e ) )
7898 insertRowFormat( rl );
7902 else if ( tagName ==
"column" )
7904 ColumnFormat *cl =
new ColumnFormat(
this, 0 );
7905 if ( cl->load( e ) )
7906 insertColumnFormat( cl );
7910 else if ( tagName ==
"object" )
7912 EmbeddedKOfficeObject *ch =
new EmbeddedKOfficeObject( doc(),
this );
7913 if ( ch->load( e ) )
7917 ch->embeddedObject()->setDeleted(
true);
7921 else if ( tagName ==
"chart" )
7923 EmbeddedChart *ch =
new EmbeddedChart( doc(),
this );
7924 if ( ch->load( e ) )
7928 ch->embeddedObject()->setDeleted(
true);
7934 n = n.nextSibling();
7939 TQDomElement printrepeatcolumns = sheet.namedItem(
"printrepeatcolumns" ).toElement();
7940 if ( !printrepeatcolumns.isNull() )
7942 int left = printrepeatcolumns.attribute(
"left" ).toInt();
7943 int right = printrepeatcolumns.attribute(
"right" ).toInt();
7944 d->print->setPrintRepeatColumns( qMakePair( left, right ) );
7948 TQDomElement printrepeatrows = sheet.namedItem(
"printrepeatrows" ).toElement();
7949 if ( !printrepeatrows.isNull() )
7951 int top = printrepeatrows.attribute(
"top" ).toInt();
7952 int bottom = printrepeatrows.attribute(
"bottom" ).toInt();
7953 d->print->setPrintRepeatRows( qMakePair( top, bottom ) );
7956 if( !sheet.hasAttribute(
"borders1.2" ) )
7958 convertObscuringBorders();
7961 if ( sheet.hasAttribute(
"protected" ) )
7963 TQString passwd = sheet.attribute(
"protected" );
7965 if ( passwd.length() > 0 )
7967 TQCString str( passwd.latin1() );
7968 d->password = KCodecs::base64Decode( str );
7971 d->password = TQCString(
"" );
7978bool Sheet::loadChildren( KoStore* _store )
7980 TQPtrListIterator<EmbeddedObject> it( doc()->embeddedObjects() );
7981 for( ; it.current(); ++it )
7983 if ( it.current()->sheet() ==
this && ( it.current()->getType() == OBJECT_KOFFICE_PART || it.current()->getType() == OBJECT_CHART ) )
7985 kdDebug() <<
"KSpreadSheet::loadChildren" << endl;
7986 if ( !
dynamic_cast<EmbeddedKOfficeObject*
>( it.current() )->embeddedObject()->loadDocument( _store ) )
7995void Sheet::setShowPageBorders(
bool b )
7997 if ( b == d->showPageBorders )
8000 d->showPageBorders = b;
8001 emit sig_updateView(
this );
8004void Sheet::addCellBinding( CellBinding *_bind )
8006 d->cellBindings.append( _bind );
8008 doc()->setModified(
true );
8011void Sheet::removeCellBinding( CellBinding *_bind )
8013 d->cellBindings.removeRef( _bind );
8015 doc()->setModified(
true );
8018Sheet* Sheet::findSheet(
const TQString & _name )
8023 return workbook()->findSheet( _name );
8027void Sheet::insertCell( Cell *_cell )
8030 d->cells.insert( _cell, _cell->column(), _cell->row() );
8033 if ( d->scrollBarUpdates )
8035 checkRangeHBorder ( _cell->column() );
8036 checkRangeVBorder ( _cell->row() );
8040void Sheet::insertColumnFormat( ColumnFormat *l )
8042 d->columns.insertElement( l, l->column() );
8045void Sheet::insertRowFormat( RowFormat *l )
8047 d->rows.insertElement( l, l->row() );
8052 Cell* c = d->cells.firstCell();
8053 for( ;c; c = c->nextCell() )
8055 updateCell(c, c->column(), c->row());
8059void Sheet::updateCellArea(
const Region& cellArea)
8061 if ( doc()->isLoading() || doc()->delayCalculation() || (!getAutoCalc()))
8064 setRegionPaintDirty( cellArea );
8067void Sheet::updateCell( Cell *,
int _column,
int _row )
8069 TQRect cellArea(TQPoint(_column, _row), TQPoint(_column, _row));
8071 updateCellArea(cellArea);
8074void Sheet::emit_updateRow( RowFormat *_format,
int _row,
bool repaint )
8076 if ( doc()->isLoading() )
8079 Cell* c = d->cells.firstCell();
8080 for( ;c; c = c->nextCell() )
8081 if ( c->row() == _row )
8082 c->setLayoutDirtyFlag(
true );
8088 setRegionPaintDirty( TQRect( 0 , _row , KS_colMax , KS_rowMax) );
8090 emit sig_updateVBorder(
this );
8091 emit sig_updateView(
this );
8093 emit sig_maxRow(maxRow());
8094 _format->clearDisplayDirtyFlag();
8097void Sheet::emit_updateColumn( ColumnFormat *_format,
int _column )
8099 if ( doc()->isLoading() )
8102 Cell* c = d->cells.firstCell();
8103 for( ;c; c = c->nextCell() )
8104 if ( c->column() == _column )
8105 c->setLayoutDirtyFlag(
true );
8109 setRegionPaintDirty( TQRect( _column , 0 , KS_colMax , KS_rowMax) );
8111 emit sig_updateHBorder(
this );
8112 emit sig_updateView(
this );
8113 emit sig_maxColumn( maxColumn() );
8117 _format->clearDisplayDirtyFlag();
8120bool Sheet::insertChart(
const KoRect& _rect, KoDocumentEntry& _e,
const TQRect& _data )
8122 kdDebug(36001) <<
"Creating document" << endl;
8123 KoDocument* dd = _e.createDoc();
8124 kdDebug(36001) <<
"Created" << endl;
8129 kdDebug(36001) <<
"NOW FETCHING INTERFACE" << endl;
8131 if ( !dd->initDoc(KoDocument::InitDocEmbedded) )
8134 EmbeddedChart * ch =
new EmbeddedChart( doc(),
this, dd, _rect );
8135 ch->setDataArea( _data );
8137 ch->chart()->setCanChangeValue(
false );
8139 KoChart::WizardExtension * wiz = ch->chart()->wizardExtension();
8142 dataRange.setRange( _data );
8143 dataRange.setSheet(
this );
8145 TQString rangeString=dataRange.toString();
8148 wiz->show( rangeString );
8155bool Sheet::insertChild(
const KoRect& _rect, KoDocumentEntry& _e )
8157 KoDocument* d = _e.createDoc( doc() );
8160 kdDebug() <<
"Error inserting child!" << endl;
8163 if ( !d->initDoc(KoDocument::InitDocEmbedded) )
8166 EmbeddedKOfficeObject* ch =
new EmbeddedKOfficeObject( doc(),
this, d, _rect );
8171bool Sheet::insertPicture(
const KoPoint& point ,
const KURL& url )
8173 KoPicture picture = doc()->pictureCollection()->downloadPicture( url , 0 );
8175 return insertPicture(point,picture);
8178bool Sheet::insertPicture(
const KoPoint& point , KoPicture& picture )
8181 if (picture.isNull())
8184 KoPictureKey key = picture.getKey();
8186 KoRect destinationRect;
8187 destinationRect.setLeft( point.x() );
8188 destinationRect.setTop( point.y() );
8200 KoSize destinationSize;
8202 double inchWidth = (double)picture.getOriginalSize().width() / KoGlobal::dpiX();
8203 double inchHeight = (double)picture.getOriginalSize().height() / KoGlobal::dpiY();
8205 destinationSize.setWidth( KoUnit::fromUserValue(inchWidth,KoUnit::U_INCH) );
8206 destinationSize.setHeight( KoUnit::fromUserValue(inchHeight,KoUnit::U_INCH) );
8208 destinationRect.setSize( destinationSize);
8210 EmbeddedPictureObject*
object =
new EmbeddedPictureObject(
this, destinationRect, doc()->pictureCollection(),key);
8213 insertObject(
object );
8217bool Sheet::insertPicture(
const KoPoint& point,
const TQPixmap& pixmap )
8220 TQBuffer buffer(data);
8222 buffer.open( IO_ReadWrite );
8223 pixmap.save( &buffer ,
"PNG" );
8230 picture.load( &buffer ,
"PNG" );
8232 doc()->pictureCollection()->insertPicture(picture);
8234 return insertPicture( point , picture );
8237void Sheet::insertObject( EmbeddedObject *_obj )
8239 doc()->insertObject( _obj );
8240 emit sig_updateView( _obj );
8243void Sheet::changeChildGeometry( EmbeddedKOfficeObject *_child,
const KoRect& _rect )
8245 _child->setGeometry( _rect );
8247 emit sig_updateChildGeometry( _child );
8250bool Sheet::saveChildren( KoStore* _store,
const TQString &_path )
8254 TQPtrListIterator<EmbeddedObject> it( doc()->embeddedObjects() );
8255 for( ; it.current(); ++it )
8257 if ( it.current()->sheet() ==
this && ( it.current()->getType() == OBJECT_KOFFICE_PART || it.current()->getType() == OBJECT_CHART ) )
8259 TQString path = TQString(
"%1/%2" ).arg( _path ).arg( i++ );
8260 if ( !
dynamic_cast<EmbeddedKOfficeObject*
>( it.current() )->embeddedObject()->document()->saveToStore( _store, path ) )
8267bool Sheet::saveOasisObjects( KoStore *, KoXmlWriter &xmlWriter, KoGenStyles& mainStyles,
int & indexObj,
int &partIndexObj )
8270 if ( doc()->embeddedObjects().isEmpty() )
8273 bool objectFound =
false;
8274 EmbeddedObject::KSpreadOasisSaveContext sc( xmlWriter, mainStyles, indexObj, partIndexObj );
8275 TQPtrListIterator<EmbeddedObject> it( doc()->embeddedObjects() );
8276 for( ; it.current(); ++it )
8278 if ( it.current()->sheet() ==
this && ( doc()->savingWholeDocument() || it.current()->isSelected() ) )
8282 xmlWriter.startElement(
"table:shapes" );
8285 if ( !it.current()->saveOasisObject(sc) )
8287 xmlWriter.endElement();
8295 xmlWriter.endElement();
8310 s_mapSheets->remove( d->id );
8315 if( s_mapSheets->count()==0)
8318 Cell* c = d->cells.firstCell();
8319 for( ; c; c = c->nextCell() )
8328 delete d->defaultFormat;
8329 delete d->defaultCell;
8330 delete d->defaultRowFormat;
8331 delete d->defaultColumnFormat;
8335 delete d->dependencies;
8343void Sheet::checkRangeHBorder (
int _column )
8345 if ( d->scrollBarUpdates && _column > d->maxColumn )
8347 d->maxColumn = _column;
8348 emit sig_maxColumn( _column );
8352void Sheet::checkRangeVBorder (
int _row )
8354 if ( d->scrollBarUpdates && _row > d->maxRow )
8357 emit sig_maxRow( _row );
8362void Sheet::enableScrollBarUpdates(
bool _enable )
8364 d->scrollBarUpdates = _enable;
8367DCOPObject* Sheet::dcopObject()
8370 d->dcop =
new SheetIface(
this );
8375void Sheet::hideSheet(
bool _hide)
8379 emit sig_SheetHidden(
this);
8381 emit sig_SheetShown(
this);
8384void Sheet::removeSheet()
8386 emit sig_SheetRemoved(
this);
8389bool Sheet::setSheetName(
const TQString& name,
bool init,
bool )
8391 if ( workbook()->findSheet( name ) )
8394 if ( isProtected() )
8397 if ( d->name == name )
8400 TQString old_name = d->name;
8406 TQPtrListIterator<Sheet> it( workbook()->sheetList() );
8407 for ( ; it.current(); ++it )
8408 it.current()->changeCellTabName( old_name, name );
8410 doc()->changeAreaSheetName( old_name, name );
8411 emit sig_nameChanged(
this, old_name );
8413 setName(name.utf8());
8414 (
dynamic_cast<SheetIface*
>(dcopObject()))->sheetNameHasChanged();
8420void Sheet::updateLocale()
8422 doc()->emitBeginOperation(
true);
8423 setRegionPaintDirty(TQRect(TQPoint(1,1), TQPoint(KS_colMax, KS_rowMax)));
8425 Cell* c = d->cells.firstCell();
8426 for( ;c; c = c->nextCell() )
8428 TQString _text = c->text();
8429 c->setCellText( _text );
8431 emit sig_updateView(
this );
8435Cell* Sheet::getFirstCellColumn(
int col)
const
8436{
return d->cells.getFirstCellColumn(col); }
8438Cell* Sheet::getLastCellColumn(
int col)
const
8439{
return d->cells.getLastCellColumn(col); }
8441Cell* Sheet::getFirstCellRow(
int row)
const
8442{
return d->cells.getFirstCellRow(row); }
8444Cell* Sheet::getLastCellRow(
int row)
const
8445{
return d->cells.getLastCellRow(row); }
8447Cell* Sheet::getNextCellUp(
int col,
int row)
const
8448{
return d->cells.getNextCellUp(col, row); }
8450Cell* Sheet::getNextCellDown(
int col,
int row)
const
8451{
return d->cells.getNextCellDown(col, row); }
8453Cell* Sheet::getNextCellLeft(
int col,
int row)
const
8454{
return d->cells.getNextCellLeft(col, row); }
8456Cell* Sheet::getNextCellRight(
int col,
int row)
const
8457{
return d->cells.getNextCellRight(col, row); }
8459void Sheet::convertObscuringBorders()
8474 Cell* c = d->cells.firstCell();
8475 TQPen topPen, bottomPen, leftPen, rightPen;
8476 for( ;c; c = c->nextCell() )
8478 if (c->extraXCells() > 0 || c->extraYCells() > 0)
8480 topPen = c->topBorderPen(c->column(), c->row());
8481 leftPen = c->leftBorderPen(c->column(), c->row());
8482 rightPen = c->rightBorderPen(c->column(), c->row());
8483 bottomPen = c->bottomBorderPen(c->column(), c->row());
8485 c->format()->setTopBorderStyle(TQt::NoPen);
8486 c->format()->setLeftBorderStyle(TQt::NoPen);
8487 c->format()->setRightBorderStyle(TQt::NoPen);
8488 c->format()->setBottomBorderStyle(TQt::NoPen);
8490 for (
int x = c->column(); x < c->column() + c->extraXCells(); x++)
8492 nonDefaultCell( x, c->row() )->setTopBorderPen(topPen);
8493 nonDefaultCell( x, c->row() + c->extraYCells() )->
8494 setBottomBorderPen(bottomPen);
8496 for (
int y = c->row(); y < c->row() + c->extraYCells(); y++)
8498 nonDefaultCell( c->column(), y )->setLeftBorderPen(leftPen);
8499 nonDefaultCell( c->column() + c->extraXCells(), y )->
8500 setRightBorderPen(rightPen);
8511void Sheet::setRegionPaintDirty( Region
const & region )
8513 DilationManipulator manipulator;
8514 manipulator.setSheet(
this);
8515 manipulator.add(region);
8516 manipulator.execute();
8518 d->paintDirtyList.add(manipulator);
8522void Sheet::setRegionPaintDirty( TQRect
const & range )
8524 DilationManipulator manipulator;
8525 manipulator.setSheet(
this);
8526 manipulator.add(range);
8527 manipulator.execute();
8529 d->paintDirtyList.add(manipulator);
8533void Sheet::clearPaintDirtyData()
8535 d->paintDirtyList.clear();
8538bool Sheet::cellIsPaintDirty( TQPoint
const & cell )
const
8540 return d->paintDirtyList.contains(cell);
8544void Sheet::printDebug()
8546 int iMaxColumn = maxColumn();
8547 int iMaxRow = maxRow();
8549 kdDebug(36001) <<
"Cell | Content | DataT | Text" << endl;
8551 for (
int currentrow = 1 ; currentrow < iMaxRow ; ++currentrow )
8553 for (
int currentcolumn = 1 ; currentcolumn < iMaxColumn ; currentcolumn++ )
8555 cell = cellAt( currentcolumn, currentrow );
8558 TQString cellDescr =
Cell::name( currentcolumn, currentrow );
8559 cellDescr = cellDescr.rightJustify( 4,
' ' );
8566 cellDescr += cell->
text();
8568 cellDescr += TQString(
" [result: %1]").arg( cell->
value().
asString() );
8569 kdDebug(36001) << cellDescr << endl;
virtual void cellChanged(Cell *_obj)
Call this function if one of the cells covered by this binding (.
For every cell in the spread sheet there is a Cell object.
FormatType formatType() const
Return the format of this cell.
TQValueList< Conditional > conditionList() const
Gets a copy of the list of current conditions.
TQString text() const
Return the text the user entered.
TQString name() const
Returns the name of the cell.
int row() const
Returns the cell's row.
int defineAlignX()
return align X when align is undefined
const Value value() const
Returns the value that this cell holds.
TQValueList< Cell * > obscuringCells() const
bool updateChart(bool refresh=true)
Refreshing chart.
Sheet * sheet() const
Returns the worksheet which owns this cell.
bool doesMergeCells() const
void setConditionList(const TQValueList< Conditional > &newList)
Replace the old set of conditions with a new one.
int column() const
Returns the cell's column.
void copyAll(Cell *cell)
Copies the format and the content.
bool isEmpty() const
Returns true if this cell has no content, i.e no text and no formula.
bool loadOasis(const TQDomElement &element, KoOasisLoadingContext &oasisContext, Style *style)
Loads a cell from an OASIS XML element.
bool isFormula() const
Returns true if this cell holds a formula.
TQDomElement save(TQDomDocument &doc, int _x_offset=0, int _y_offset=0, bool force=false, bool copy=false, bool era=false)
Save this cell.
void setCalcDirtyFlag()
Set the calcDirtyFlag.
void setCellText(const TQString &_text, bool asString=false)
The high-level method for setting text, when the user inputs it.
Format * format() const
Returns the format object of this cell.
TQString columnName() const
Returns the column name of the cell.
bool isDefault() const
Returns true if this is a default cell (with row and column equal to zero).
bool isPartOfMerged() const
If this cell is part of a merged cell, then the marker may never reside on this cell.
This class manages dependencies.
@ STYLE_COLUMN_AUTO
auto column styles
@ STYLE_ROW_AUTO
auto row styles
The one for all class for points and ranges.
bool isNumber() const
Returns true if the type of this value is either integer or floating-point.
Type type() const
Returns the type of the value.
double asFloat() const
Returns the floating-point value of this value.
TQString asString() const
Returns the string value of this value.
Operation
The current cell value treatment.