48#include <tqapplication.h>
49#include <tqpopupmenu.h>
52#include "kspread_canvas.h"
53#include "kspread_condition.h"
54#include "kspread_doc.h"
55#include "kspread_format.h"
56#include "kspread_global.h"
57#include "kspread_map.h"
58#include "kspread_sheet.h"
59#include "kspread_sheetprint.h"
60#include "kspread_style.h"
61#include "kspread_style_manager.h"
62#include "kspread_util.h"
63#include "ksploadinginfo.h"
64#include "kspread_genvalidationstyle.h"
65#include "kspread_locale.h"
66#include "kspread_value.h"
67#include "kspread_view.h"
68#include "kspread_value.h"
71#include "valueconverter.h"
72#include "valueformatter.h"
73#include "valueparser.h"
75#include <KoStyleStack.h>
79#include <KoXmlWriter.h>
80#include <KoOasisStyles.h>
82#include <tdemessagebox.h>
97 TQChar decimal_point =
'\0';
143 TQValueList<Cell*> obscuringCells;
146 Conditions *conditions;
154 Extra& operator=(
const Extra& );
205 KSpread::Formula *formula;
222 bool hasExtra()
const {
return (cellExtra != 0); };
234Cell::Private::Private()
259Cell::Private::~Private()
266Cell::Extra* Cell::Private::extra()
269 cellExtra =
new Extra;
270 cellExtra->conditions = 0;
271 cellExtra->validity = 0;
273 cellExtra->mergedXCells = 0;
274 cellExtra->mergedYCells = 0;
275 cellExtra->extraXCells = 0;
276 cellExtra->extraYCells = 0;
277 cellExtra->extraWidth = 0.0;
278 cellExtra->extraHeight = 0.0;
279 cellExtra->nbLines = 0;
294Cell::Cell( Sheet * _sheet,
int _column,
int _row )
299 d->format =
new Format(_sheet, _sheet->doc()->styleManager()->defaultStyle());
300 d->format->setCell(
this);
305Cell::Cell( Sheet * _sheet, Style * _style,
int _column,
int _row )
310 d->format =
new Format( _sheet, _style );
311 d->format->setCell(
this);
324 return d->format->sheet();
330 return ( d->column == 0 );
342 kdWarning(36001) <<
"Error: Calling Cell::row() for default cell" << endl;
359 kdWarning(36001) <<
"Error: Calling Cell::column() for default cell" << endl;
371 return name( d->column, d->row );
396 return s->sheetName() +
"!" +
name( col,
row );
409 return d->format->sheet()->doc()->locale();
422 if(
column > 4058115285U )
return TQString(
"@@@");
424 for(
unsigned limit = 26;
column >= limit+offset; limit *= 26, digits++ )
427 for(
unsigned c =
column - offset; digits; --digits, c/=26 )
428 str.prepend( TQChar(
'A' + (c%26) ) );
438 return d->strText[0] ==
'=';
458TQString Cell::strOutText()
const
460 return d->strOutText;
485 if (v.
type() != Value::Error)
494 if ( ( d->value == v ) && ( !
isFormula() ) )
499 setFlag(Flag_LayoutDirty);
500 setFlag(Flag_TextFormatDirty);
506 if (d->value.type() == Value::Error)
507 d->strOutText = d->value.errorMessage ();
525 d->strText =
sheet()->doc()->converter()->asString (v).
asString();
526 if (fmtType != No_format)
527 format()->setFormatType (fmtType);
534Cell* Cell::previousCell()
const
536 return d->previousCell;
539Cell* Cell::nextCell()
const
544void Cell::setPreviousCell( Cell* c )
549void Cell::setNextCell( Cell* c )
554Validity* Cell::getValidity(
int newStruct )
556 if ( (!newStruct) && (!d->hasExtra()))
560 if( ( d->extra()->validity == 0 ) && ( newStruct == -1 ) )
561 d->extra()->validity =
new Validity;
562 return d->extra()->validity;
565void Cell::removeValidity()
570 delete d->extra()->validity;
571 d->extra()->validity = 0;
587 d->value.setFormat(cell->d->value.format());
588 format()->copy(*(cell->format()));
620 TQValueList<Conditional>
conditionList = cell->conditionList();
622 delete d->extra()->conditions;
623 if ( cell->d->hasExtra() && cell->d->extra()->conditions )
627 d->extra()->conditions = 0;
639void Cell::copyContent(
const Cell* cell )
643 if (cell->isFormula() && cell->column() > 0 && cell->row() > 0)
647 TQString d = cell->encodeFormula();
655void Cell::defaultStyle()
657 format()->defaultStyleFormat();
662 if ( d->extra()->conditions )
664 delete d->extra()->conditions;
665 d->extra()->conditions = 0;
668 delete d->extra()->validity;
669 d->extra()->validity = 0L;
679 int extraXCells = d->hasExtra() ? d->extra()->extraXCells : 0;
680 int extraYCells = d->hasExtra() ? d->extra()->extraYCells : 0;
681 for (
int x = _col; x <= _col +
extraXCells; ++x ) {
682 for (
int y = _row; y <= _row +
extraYCells; ++y ) {
683 if ( x != _col || y != _row )
689 if ( _x == 0 && _y == 0 ) {
690 clearFlag( Flag_Merged );
692 d->extra()->extraXCells = 0;
693 d->extra()->extraYCells = 0;
694 d->extra()->extraWidth = 0.0;
695 d->extra()->extraHeight = 0.0;
696 d->extra()->mergedXCells = 0;
697 d->extra()->mergedYCells = 0;
701 setFlag( Flag_LayoutDirty );
706 setFlag(Flag_Merged);
707 d->extra()->extraXCells = _x;
708 d->extra()->extraYCells = _y;
709 d->extra()->mergedXCells = _x;
710 d->extra()->mergedYCells = _y;
713 for (
int x = _col; x <= _col + _x; ++x ) {
714 for (
int y = _row; y <= _row + _y; ++y ) {
715 if ( x != _col || y != _row )
716 format()->sheet()->nonDefaultCell( x, y )->
obscure(
this,
true );
721 setFlag( Flag_LayoutDirty );
728 setDisplayDirtyFlag();
734 d->extra()->obscuringCells.clear();
737 int extraXCells = d->hasExtra() ? d->extra()->extraXCells : 0;
738 int extraYCells = d->hasExtra() ? d->extra()->extraYCells : 0;
741 if ( x != d->column || y != d->row )
743 Cell *cell =
format()->sheet()->nonDefaultCell( x, y );
754 d->extra()->mergedXCells = 0;
755 d->extra()->mergedYCells = 0;
764 setFlag( Flag_LayoutDirty );
766 setFlag( Flag_TextFormatDirty );
771 TQValueList<Cell*>::iterator it = d->extra()->obscuringCells.begin();
772 TQValueList<Cell*>::iterator end = d->extra()->obscuringCells.end();
773 for ( ; it != end; ++it ) {
774 (*it)->setLayoutDirtyFlag(
format );
783 if ( !d->strText.stripWhiteSpace().isEmpty() ) {
788 if (
format()->hasProperty( Format::PTopBorder )
789 ||
format()->hasProperty( Format::PLeftBorder )
790 ||
format()->hasProperty( Format::PRightBorder )
791 ||
format()->hasProperty( Format::PBottomBorder )
792 ||
format()->hasProperty( Format::PFallDiagonal )
793 ||
format()->hasProperty( Format::PGoUpDiagonal ) ) {
798 if (
format()->hasProperty( Format::PBackgroundBrush ) ) {
804 if ( (brush.style() != TQt::NoBrush) &&
805 (brush.color() != TQt::white || brush.pixmap()) )
810 if (
format()->hasProperty( Format::PBackgroundColor ) ) {
811 kdDebug() <<
"needsPrinting: Has background colour" << endl;
815 if (backgroundColor != TQt::white)
824 return isDefault() || d->strText.isEmpty();
847 TQValueList<Cell*>::const_iterator it = d->extra()->obscuringCells.begin();
848 TQValueList<Cell*>::const_iterator end = d->extra()->obscuringCells.end();
849 for ( ; it != end; ++it ) {
852 if (cell->doesMergeCells()) {
857 if (
column() <= cell->column() + cell->d->extra()->mergedXCells
858 &&
row() <= cell->row() + cell->mergedYCells() )
878 return (Cell *)
this;
880 else if (d->extra()->obscuringCells.isEmpty())
881 return (Cell *)
this;
887 TQValueList<Cell*>::const_iterator it = d->extra()->obscuringCells.begin();
888 TQValueList<Cell*>::const_iterator end = d->extra()->obscuringCells.end();
889 for ( ; it != end; ++it ) {
892 if (cell->doesMergeCells()) {
897 if (
column() <= cell->column() + cell->d->extra()->mergedXCells
898 &&
row() <= cell->row() + cell->mergedYCells() )
912 TQValueList<Cell*> empty;
915 return d->extra()->obscuringCells;
918void Cell::clearObscuringCells()
922 d->extra()->obscuringCells.clear();
929 d->extra()->obscuringCells.remove( cell );
930 cell->clearObscuringCells();
934 d->extra()->obscuringCells.prepend( cell );
938 d->extra()->obscuringCells.append( cell );
940 setFlag(Flag_LayoutDirty);
947 d->extra()->obscuringCells.remove( cell );
948 setFlag( Flag_LayoutDirty );
961 if(d->strText.isEmpty())
966 bool onNumber =
false;
967 unsigned int pos = 0;
968 const unsigned int length = d->strText.length();
972 while ( pos < length )
974 if ( d->strText[pos] ==
'"' )
976 erg += d->strText[pos++];
977 while ( pos < length && d->strText[pos] !=
'"' )
979 erg += d->strText[pos++];
981 if ( pos < length && d->strText[pos] ==
'\\' && d->strText[pos+1] ==
'"' )
983 erg += d->strText[pos++];
984 erg += d->strText[pos++];
988 erg += d->strText[pos++];
992 else if ( d->strText[pos].isDigit() )
994 erg += d->strText[pos++];
998 else if ( d->strText[pos] !=
'$' && !d->strText[pos].isLetter() )
1000 erg += d->strText[pos++];
1001 fix1 = fix2 =
false;
1007 if ( d->strText[pos] ==
'$' )
1013 if ( d->strText[pos].isLetter() )
1016 unsigned int pos2 = 0;
1017 while ( pos < length && d->strText[pos].isLetter() )
1019 tmp += d->strText[pos];
1020 buffer[pos2++] = d->strText[pos++];
1022 if ( d->strText[pos] ==
'$' )
1028 if ( d->strText[pos].isDigit() )
1030 const unsigned int oldPos = pos;
1031 while ( pos < length && d->strText[pos].isDigit() ) ++pos;
1033 if ( pos != oldPos )
1034 row = d->strText.mid(oldPos, pos-oldPos).toInt();
1038 if ( ( d->strText[pos] ==
'!' ) ||
1039 d->strText[pos].isLetter() ||
1043 fix1 = fix2 =
false;
1052 erg += TQString(
"$%1" ).arg( col );
1055 erg += TQChar(0xA7) + TQString(
"%1" ).arg( col );
1057 erg += TQString(
"#%1" ).arg( col - _col );
1060 erg += TQString(
"$%1#").arg(
row );
1063 erg += TQChar(0xA7) + TQString(
"%1#" ).arg(
row );
1065 erg += TQString(
"#%1#" ).arg(
row - _row );
1071 fix1 = fix2 =
false;
1086TQString Cell::decodeFormula(
const TQString &_text,
int _col,
int _row)
const
1094 unsigned int pos = 0;
1095 const unsigned int length = _text.length();
1097 if ( _text.isEmpty() )
1100 while ( pos < length )
1102 if ( _text[pos] ==
'"' )
1104 erg += _text[pos++];
1105 while ( pos < length && _text[pos] !=
'"' )
1107 erg += _text[pos++];
1109 if ( pos < length && _text[pos] ==
'\\' && _text[pos+1] ==
'"' )
1111 erg += _text[pos++];
1112 erg += _text[pos++];
1116 erg += _text[pos++];
1118 else if ( _text[pos] ==
'#' || _text[pos] ==
'$' || _text[pos] == TQChar(0xA7))
1125 TQChar _t = _text[pos++];
1128 else if ( _t == TQChar(0xA7) )
1132 unsigned int oldPos = pos;
1133 while ( pos < length && ( _text[pos].isDigit() || _text[pos] ==
'-' ) ) ++pos;
1134 if ( pos != oldPos )
1135 col = _text.mid(oldPos, pos-oldPos).toInt();
1136 if ( !abs1 && !era1 )
1143 else if ( _t == TQChar(0xA7) )
1148 while ( pos < length && ( _text[pos].isDigit() || _text[pos] ==
'-' ) ) ++pos;
1149 if ( pos != oldPos )
1150 row = _text.mid(oldPos, pos-oldPos).toInt();
1151 if ( !abs2 && !era2)
1155 if (
row < 1 || col < 1 || row > KS_rowMax || col > KS_colMax )
1157 kdDebug(36001) <<
"Cell::decodeFormula: row or column out of range (col: " << col <<
" | row: " <<
row <<
")" << endl;
1158 erg =
"=\"#### " + i18n(
"REFERENCE TO COLUMN OR ROW IS OUT OF RANGE") +
"\"";
1167 erg += TQString::number(
row );
1170 erg += _text[pos++];
1177void Cell::freeAllObscuredCells()
1186 for (
int x = d->column + d->extra()->mergedXCells;
1187 x <= d->
column + d->extra()->extraXCells; ++x ) {
1188 for (
int y = d->row + d->extra()->mergedYCells;
1189 y <= d->
row + d->extra()->extraYCells; ++y ) {
1190 if ( x != d->column || y != d->row ) {
1191 Cell *cell =
format()->sheet()->cellAt( x, y );
1197 d->extra()->extraXCells = d->extra()->mergedXCells;
1198 d->extra()->extraYCells = d->extra()->mergedYCells;
1230 if ( !testFlag( Flag_LayoutDirty ) )
1235 d->extra()->nbLines = 0;
1236 clearFlag( Flag_CellTooShortX );
1237 clearFlag( Flag_CellTooShortY );
1241 freeAllObscuredCells();
1244 d->extra()->mergedXCells, d->extra()->mergedYCells );
1248 ColumnFormat *cl1 =
format()->sheet()->columnFormat( _col );
1249 RowFormat *rl1 =
format()->sheet()->rowFormat( _row );
1251 || ( rl1->dblHeight() <=
format()->
sheet()->doc()->unzoomItY( 2 ) ) ) {
1252 clearFlag( Flag_LayoutDirty );
1261 if ( d->strOutText.isEmpty() ) {
1262 d->strOutText = TQString();
1265 clearFlag( Flag_LayoutDirty );
1283 RowFormat *rl =
format()->sheet()->rowFormat( d->row );
1284 ColumnFormat *cl =
format()->sheet()->columnFormat( d->column );
1286 double width = cl->dblWidth();
1287 double height = rl->dblHeight();
1290 if ( testFlag( Flag_Merged ) ) {
1291 int extraXCells = d->hasExtra() ? d->extra()->extraXCells : 0;
1292 int extraYCells = d->hasExtra() ? d->extra()->extraYCells : 0;
1297 for (
int x = _col + 1; x <= _col +
extraXCells; x++ )
1298 width +=
format()->sheet()->columnFormat( x )->dblWidth();
1300 for (
int y = _row + 1; y <= _row +
extraYCells; y++ )
1301 height +=
format()->sheet()->rowFormat( y )->dblHeight();
1307 if (d->hasExtra()) {
1308 d->extra()->extraWidth =
width;
1309 d->extra()->extraHeight =
height;
1312 TQFontMetrics fm = _painter.fontMetrics();
1313 d->fmAscent = fm.ascent();
1323 if ( d->textWidth > (
width - 2 * BORDER_SPACE
1324 -
format()->leftBorderWidth( _col, _row )
1325 -
format()->rightBorderWidth( _col, _row ) )
1326 &&
format()->multiRow( _col, _row ) )
1332 TQString o = d->strOutText;
1337 if ( o.find(
' ') != -1 )
1347 int availableWidth = (int) (
width - 2 * BORDER_SPACE
1348 -
format()->leftBorderWidth( _col, _row )
1349 -
format()->rightBorderWidth( _col, _row ) );
1353 breakpos = o.find(
' ', breakpos );
1354 int linefeed = o.find(
'\n', pos1 );
1359 int work_breakpos = breakpos;
1360 if (pos1 < linefeed && linefeed < breakpos)
1361 work_breakpos = linefeed;
1363 double lineWidth =
format()->sheet()->doc()
1364 ->unzoomItX( fm.width( d->strOutText.mid( start, (pos1 - start) )
1365 + o.mid( pos1, work_breakpos - pos1 ) ) );
1368 if (breakpos > linefeed && linefeed > 0)
1375 if ( lineWidth <= availableWidth ) {
1377 d->strOutText += o.mid( pos1, breakpos - pos1 );
1382 if ( o.at( pos1 ) ==
' ' )
1385 if ( pos1 != 0 && breakpos != -1 ) {
1386 d->strOutText +=
"\n" + o.mid( pos1, breakpos - pos1 );
1390 d->strOutText += o.mid( pos1, breakpos - pos1 );
1397 }
while( o.find(
' ', breakpos ) != -1 );
1401 lines = o.contains(
'\n');
1404 d->textHeight *= lines;
1406 d->extra()->nbLines = lines;
1417 i = d->strOutText.find(
"\n", pos );
1420 t = d->strOutText.mid( pos, d->strOutText.length() - pos );
1422 t = d->strOutText.mid( pos, i - pos );
1426 double tw =
format()->sheet()->doc()->unzoomItX( fm.width( t ) );
1427 if ( tw > d->textWidth )
1429 }
while ( i != -1 );
1433 offsetAlign( _col, _row );
1435 int a = effAlignX();
1438 double indent = 0.0;
1439 if ( a == Format::Left && !
isEmpty() )
1440 indent =
format()->getIndent( _col, _row );
1444 if (
format()->verticalText( _col, _row ) ||
format()->getAngle( _col, _row ) != 0 ) {
1447 if ( d->textHeight >=
height )
1448 setFlag( Flag_CellTooShortX );
1457 if ( d->textWidth + indent > (
width - 2 * BORDER_SPACE
1458 -
format()->leftBorderWidth( _col, _row )
1459 -
format()->rightBorderWidth( _col, _row ) )
1460 && ( !d->hasExtra() || d->extra()->mergedYCells == 0 ) )
1467 ColumnFormat *cl2 =
format()->sheet()->columnFormat( c + 1 );
1468 Cell *cell =
format()->sheet()->visibleCellAt( c + 1, d->row );
1470 if ( cell->isEmpty() ) {
1471 width += cl2->dblWidth() - 1;
1475 if ( d->textWidth + indent <= (
width - 2 * BORDER_SPACE
1476 -
format()->leftBorderWidth( _col, _row )
1477 -
format()->rightBorderWidth( _col, _row ) ) )
1497 if (
format()->align( _col, _row ) == Format::Left
1498 || (
format()->align( _col, _row ) == Format::Undefined
1499 && !
value().isNumber() ) )
1501 if ( c - d->column > d->extra()->mergedXCells ) {
1502 d->extra()->extraXCells = c - d->column;
1503 d->extra()->extraWidth =
width;
1504 for (
int i = d->column + 1; i <= c; ++i ) {
1505 Cell *cell =
format()->sheet()->nonDefaultCell( i, d->row );
1511 setFlag( Flag_CellTooShortX );
1514 setFlag( Flag_CellTooShortX );
1517 setFlag( Flag_CellTooShortX );
1524 if (
format()->multiRow( _col, _row )
1525 && d->textHeight > (
height - 2 * BORDER_SPACE
1526 -
format()->topBorderWidth( _col, _row )
1527 -
format()->bottomBorderWidth( _col, _row ) ) )
1534 RowFormat *rl2 =
format()->sheet()->rowFormat( r + 1 );
1535 Cell *cell =
format()->sheet()->visibleCellAt( d->column, r + 1 );
1537 if ( cell->isEmpty() ) {
1538 height += rl2->dblHeight() - 1.0;
1542 if ( d->textHeight <= (
height - 2 * BORDER_SPACE
1543 -
format()->topBorderWidth( _col, _row )
1544 -
format()->bottomBorderWidth( _col, _row ) ) )
1553 if ( r - d->row > d->extra()->mergedYCells )
1555 d->extra()->extraYCells = r - d->row;
1556 d->extra()->extraHeight =
height;
1558 for (
int i = d->row + 1; i <= r; ++i )
1560 Cell *cell =
format()->sheet()->nonDefaultCell( d->column, i );
1566 setFlag( Flag_CellTooShortY );
1569 setFlag( Flag_CellTooShortY );
1572 clearFlag( Flag_LayoutDirty );
1578void Cell::valueChanged ()
1582 format()->sheet()->valueChanged (
this);
1589void Cell::setOutputText()
1592 d->strOutText = TQString();
1594 if ( d->hasExtra() && d->extra()->conditions )
1595 d->extra()->conditions->checkMatches();
1601 if ( !testFlag(Flag_TextFormatDirty) )
1605 clearFlag( Flag_TextFormatDirty );
1610 && !(
format()->
sheet()->isProtected() &&
format()->isHideFormula( d->column, d->row ) )
1612 d->strOutText = d->strText;
1619 if ( d->hasExtra() && d->extra()->conditions )
1620 d->extra()->conditions->checkMatches();
1629void Cell::offsetAlign(
int _col,
int _row )
1634 bool tmpVerticalText;
1638 && d->extra()->conditions
1639 && d->extra()->conditions->matchedStyle() )
1641 Style *style = d->extra()->conditions->matchedStyle();
1643 if ( style->hasFeature( Style::SAlignX,
true ) )
1644 a = style->alignX();
1646 a =
format()->align( _col, _row );
1648 if ( style->hasFeature( Style::SVerticalText,
true ) )
1649 tmpVerticalText = style->hasProperty( Style::PVerticalText );
1651 tmpVerticalText =
format()->verticalText( _col, _row );
1653 if ( style->hasFeature( Style::SMultiRow,
true ) )
1654 tmpMultiRow = style->hasProperty( Style::PMultiRow );
1656 tmpMultiRow =
format()->multiRow( _col, _row );
1658 if ( style->hasFeature( Style::SAlignY,
true ) )
1659 ay = style->alignY();
1661 ay =
format()->alignY( _col, _row );
1663 if ( style->hasFeature( Style::SAngle,
true ) )
1664 tmpAngle = style->rotateAngle();
1666 tmpAngle =
format()->getAngle( _col, _row );
1669 a =
format()->align( _col, _row );
1670 ay =
format()->alignY( _col, _row );
1671 tmpAngle =
format()->getAngle( _col, _row );
1672 tmpVerticalText =
format()->verticalText( _col, _row );
1673 tmpMultiRow =
format()->multiRow( _col, _row );
1676 RowFormat *rl =
format()->sheet()->rowFormat( _row );
1677 ColumnFormat *cl =
format()->sheet()->columnFormat( _col );
1679 double w = cl->dblWidth();
1680 double h = rl->dblHeight();
1682 if ( d->hasExtra() ) {
1683 if ( d->extra()->extraXCells ) w = d->extra()->extraWidth;
1684 if ( d->extra()->extraYCells ) h = d->extra()->extraHeight;
1687 const double effTop = BORDER_SPACE + 0.5 *
effTopBorderPen( _col, _row ).width();
1688 const double effBottom = h - BORDER_SPACE - 0.5 *
effBottomBorderPen( _col, _row ).width();
1696 if ( tmpAngle == 0 )
1698 d->textY = effTop + (double) d->fmAscent /
format()->sheet()->doc()->zoomedResolutionY();
1700 else if ( tmpAngle < 0 )
1707 + (double) d->fmAscent * cos( tmpAngle * M_PI / 180 ) /
format()->sheet()->doc()->zoomedResolutionY();
1711 case Format::Bottom:
1713 if ( !tmpVerticalText && !tmpMultiRow && !tmpAngle )
1715 d->textY = effBottom;
1717 else if ( tmpAngle != 0 )
1720 if ( effBottom - effTop - d->textHeight > 0 )
1724 d->textY = effBottom - d->textHeight;
1728 d->textY = effBottom - d->textHeight
1729 + ( (double) d->fmAscent * cos( tmpAngle * M_PI / 180 ) /
format()->sheet()->doc()->zoomedResolutionY() );
1741 + ( (double) d->fmAscent * cos( tmpAngle * M_PI / 180 )
1742 /
format()->sheet()->doc()->zoomedResolutionY() );
1746 else if ( tmpMultiRow && !tmpVerticalText )
1749 if ( effBottom - effTop - d->textHeight > 0 )
1751 d->textY = effBottom - d->textHeight
1752 + (double)d->fmAscent /
format()->sheet()->doc()->zoomedResolutionY();
1757 + (double) d->fmAscent /
format()->sheet()->doc()->zoomedResolutionY();
1763 if ( effBottom - effTop - d->textHeight > 0 )
1765 d->textY = effBottom - d->textHeight
1766 + (double)d->fmAscent /
format()->sheet()->doc()->zoomedResolutionY();
1771 + (double) d->fmAscent /
format()->sheet()->doc()->zoomedResolutionY();
1776 case Format::Middle:
1777 case Format::UndefinedY:
1779 if ( !tmpVerticalText && !tmpMultiRow && !tmpAngle )
1781 d->textY = ( h - d->textHeight ) / 2
1782 + (
double) d->fmAscent /
format()->sheet()->doc()->zoomedResolutionY();
1784 else if ( tmpAngle != 0 )
1787 if ( effBottom - effTop - d->textHeight > 0 )
1791 d->textY = ( h - d->textHeight ) / 2;
1795 d->textY = ( h - d->textHeight ) / 2
1796 + (
double) d->fmAscent * cos( tmpAngle * M_PI / 180 ) /
format()->sheet()->doc()->zoomedResolutionY();
1808 + ( (double)d->fmAscent * cos( tmpAngle * M_PI / 180 ) /
format()->sheet()->doc()->zoomedResolutionY() );
1812 else if ( tmpMultiRow && !tmpVerticalText )
1815 if ( effBottom - effTop - d->textHeight > 0 )
1817 d->textY = ( h - d->textHeight ) / 2
1818 + (
double) d->fmAscent /
format()->sheet()->doc()->zoomedResolutionY();
1823 + (double) d->fmAscent /
format()->sheet()->doc()->zoomedResolutionY();
1829 if ( effBottom - effTop - d->textHeight > 0 )
1831 d->textY = ( h - d->textHeight ) / 2
1832 + (
double) d->fmAscent /
format()->sheet()->doc()->zoomedResolutionY();
1836 + (double)d->fmAscent /
format()->sheet()->doc()->zoomedResolutionY();
1844 !(
format()->
sheet()->isProtected() &&
format()->isHideFormula( _col, _row ) ) )
1855 d->textX = w - BORDER_SPACE - d->textWidth
1858 case Format::Center:
1859 d->textX = 0.5 * ( w - BORDER_SPACE - d->textWidth -
1873 TQFontMetrics fm = _paint.fontMetrics();
1879 bool tmpVerticalText;
1880 bool fontUnderlined;
1886 && d->extra()->conditions
1887 && d->extra()->conditions->matchedStyle() )
1889 Style *style = d->extra()->conditions->matchedStyle();
1891 if ( style->hasFeature( Style::SAngle,
true ) )
1892 tmpAngle = style->rotateAngle();
1894 tmpAngle =
format()->getAngle( _col, _row );
1896 if ( style->hasFeature( Style::SVerticalText,
true ) )
1897 tmpVerticalText = style->hasProperty( Style::PVerticalText );
1899 tmpVerticalText =
format()->verticalText( _col, _row );
1901 if ( style->hasFeature( Style::SAlignY,
true ) )
1902 ay = style->alignY();
1904 ay =
format()->alignY( _col, _row );
1906 if ( style->hasFeature( Style::SFontFlag,
true ) )
1907 fontUnderlined = ( style->fontFlags() & (uint) Style::FUnderline );
1909 fontUnderlined =
format()->textFontUnderline( _col, _row );
1913 tmpAngle =
format()->getAngle( _col, _row );
1914 tmpVerticalText =
format()->verticalText( _col, _row );
1915 ay =
format()->alignY( _col, _row );
1916 fontUnderlined =
format()->textFontUnderline( _col, _row );
1921 if ( !tmpVerticalText && !tmpAngle ) {
1924 d->textWidth =
format()->sheet()->doc()->unzoomItX( fm.width( d->strOutText ) );
1926 if ( ( ay == Format::Bottom ) && fontUnderlined ) {
1927 offsetFont = fm.underlinePos() + 1;
1930 d->textHeight =
format()->sheet()->doc()->unzoomItY( fm.ascent() + fm.descent()
1933 else if ( tmpAngle!= 0 ) {
1936 d->textHeight =
format()->sheet()->doc()
1937 ->unzoomItY(
int( cos( tmpAngle * M_PI / 180 )
1938 * ( fm.ascent() + fm.descent() )
1939 + abs(
int( ( fm.width( d->strOutText )
1940 * sin( tmpAngle * M_PI / 180 ) ) ) ) ) );
1942 d->textWidth =
format()->sheet()->doc()
1943 ->unzoomItX(
int( abs(
int( ( sin( tmpAngle * M_PI / 180 )
1944 * ( fm.ascent() + fm.descent() ) ) ) )
1945 + fm.width( d->strOutText )
1946 * cos ( tmpAngle * M_PI / 180 ) ) );
1951 for (
unsigned int i = 0; i < d->strOutText.length(); i++ )
1952 width = TQMAX(
width, fm.width( d->strOutText.at( i ) ) );
1954 d->textWidth =
format()->sheet()->doc()->unzoomItX(
width );
1955 d->textHeight =
format()->sheet()->doc()->unzoomItY( ( fm.ascent() + fm.descent() )
1956 * d->strOutText.length() );
1968 TQFont tmpFont(
format()->textFont( _col, _row ) );
1973 && d->extra()->conditions
1974 && d->extra()->conditions->matchedStyle() ) {
1976 Style * s = d->extra()->conditions->matchedStyle();
1979 if ( s->hasFeature( Style::SFontSize,
true ) )
1980 tmpFont.setPointSizeFloat( s->fontSize() );
1983 if ( s->hasFeature( Style::SFontFlag,
true ) ) {
1984 uint flags = s->fontFlags();
1986 tmpFont.setBold( flags & (uint) Style::FBold );
1987 tmpFont.setUnderline( flags & (uint) Style::FUnderline );
1988 tmpFont.setItalic( flags & (uint) Style::FItalic );
1989 tmpFont.setStrikeOut( flags & (uint) Style::FStrike );
1993 if ( s->hasFeature( Style::SFontFamily,
true ) )
1994 tmpFont.setFamily( s->fontFamily() );
2001 if ( d->extra()->conditions
2002 && d->extra()->conditions->currentCondition( condition )
2005 &&
format()->isHideFormula( d->column, d->row ) ) ) )
2007 if ( condition.fontcond )
2008 tmpFont = *(condition.fontcond);
2010 tmpFont = condition.style->font();
2015 tmpFont.setPointSizeFloat( 0.01 *
format()->
sheet()->doc()->zoom()
2016 * tmpFont.pointSizeFloat() );
2018 painter.setFont( tmpFont );
2024 int _col,
int _row )
2033 offsetAlign( _col, _row );
2046 d->formula->setExpression (d->strText);
2048 if (!d->formula->isValid ()) {
2052 if (
format()->
sheet()->doc()->getShowMessageError())
2054 TQString tmp(i18n(
"Error in cell %1\n\n"));
2056 KMessageBox::error( (TQWidget*)0L, tmp);
2058 setFlag(Flag_ParseError);
2082 if (d->formula == 0)
2084 if ( testFlag( Flag_ParseError ) )
2093 if ( d->formula == 0 )
2098 if ( !testFlag( Flag_CalcDirty ) )
2103 if (
format()->
sheet()->doc()->delayCalculation() )
2107 setFlag(Flag_LayoutDirty);
2108 setFlag(Flag_TextFormatDirty);
2109 clearFlag(Flag_CalcDirty);
2111 Value result = d->formula->eval ();
2116 clearFlag(Flag_CalcDirty);
2117 setFlag(Flag_LayoutDirty);
2138 const KoPoint &coordinate,
2139 const TQPoint &cellRef,
2141 TQPen & rightPen, TQPen & bottomPen,
2142 TQPen & leftPen, TQPen & topPen,
2143 TQValueList<TQPoint> &mergedCellsPainted,
2146 bool paintBorderRight = paintBorder & Border_Right;
2147 bool paintBorderBottom = paintBorder & Border_Bottom;
2148 bool paintBorderLeft = paintBorder & Border_Left;
2149 bool paintBorderTop = paintBorder & Border_Top;
2153 if ( testFlag( Flag_PaintingCell ) )
2157 setFlag( Flag_PaintingCell );
2163 static int paintingObscured = 0;
2166 if (paintingObscured == 0)
2167 kdDebug(36001) <<
"painting cell " <<
name() << endl;
2169 kdDebug(36001) <<
" painting obscured cell " <<
name() << endl;
2174 Q_ASSERT(!(paintingObscured > 0 && d->extra()->obscuringCells.isEmpty()));
2178 || (((cellRef.x() == d->column) && (cellRef.y() == d->row))));
2180 Sheet::LayoutDirection sheetDir =
format()->sheet()->layoutDirection();
2182 double left = coordinate.x();
2184 ColumnFormat * colFormat =
format()->sheet()->columnFormat( cellRef.x() );
2185 RowFormat * rowFormat =
format()->sheet()->rowFormat( cellRef.y() );
2191 double width0 = colFormat->dblWidth();
2192 double height0 = rowFormat->dblHeight();
2193 double width = width0;
2204 if ( sheetDir == Sheet::RightToLeft && paintingObscured == 0
2207 double dwidth = view->doc()->unzoomItX(view->
canvasWidget()->width());
2208 left = dwidth - coordinate.x() -
width;
2214 if (d->hasExtra()) {
2215 if (d->extra()->mergedXCells > 0 || d->extra()->mergedYCells > 0) {
2217 if ( sheetDir == Sheet::RightToLeft ) {
2218 left -= d->extra()->extraWidth -
width;
2220 width0 = d->extra()->extraWidth;
2221 height0 = d->extra()->extraHeight;
2222 width = d->extra()->extraWidth;
2223 height = d->extra()->extraHeight;
2227 width += d->extra()->extraXCells ? d->extra()->extraWidth : 0;
2228 height += d->extra()->extraYCells ? d->extra()->extraHeight : 0;
2231 if ( d->extra()->extraXCells )
2232 width = d->extra()->extraWidth;
2233 if ( d->extra()->extraYCells )
2234 height = d->extra()->extraHeight;
2244 bool selected =
false;
2245 if ( view != NULL ) {
2246 selected = view->selectionInfo()->
contains( cellRef );
2249 Cell *cell =
format()->sheet()->cellAt( view->selectionInfo()->marker() );
2250 TQPoint bottomRight( view->selectionInfo()->marker().x() + cell->extraXCells(),
2251 view->selectionInfo()->marker().y() + cell->extraYCells() );
2252 TQRect markerArea( view->selectionInfo()->marker(), bottomRight );
2253 selected = selected && !( markerArea.contains( cellRef ) );
2256 if ( painter.device()->isExtDev() || !drawCursor )
2268 if ( testFlag( Flag_LayoutDirty ) )
2269 makeLayout( painter, cellRef.x(), cellRef.y() );
2277 const KoRect cellRect0( left, coordinate.y(), width0, height0 );
2278 if ( !
cellRect.intersects( rect ) ) {
2279 clearFlag( Flag_PaintingCell );
2288 TQColor backgroundColor;
2289 if ( d->hasExtra() && d->extra()->conditions
2290 && d->extra()->conditions->matchedStyle()
2291 && d->extra()->conditions->matchedStyle()->hasFeature( Style::SBackgroundColor,
true ) )
2292 backgroundColor = d->extra()->conditions->matchedStyle()->bgColor();
2294 backgroundColor =
bgColor( cellRef.x(), cellRef.y() );
2298 paintBackground( painter, cellRect0, cellRef, selected, backgroundColor );
2302 if ( painter.device()->devType() != TQInternal::Printer
2304 paintDefaultBorders( painter, rect,
cellRect, cellRef,
2305 paintBorderRight, paintBorderBottom,
2306 paintBorderLeft, paintBorderTop,
2307 rightPen, bottomPen, leftPen, topPen );
2317 if (d->hasExtra() && (d->extra()->extraXCells > 0
2318 || d->extra()->extraYCells > 0)) {
2321 paintObscuredCells( rect, painter, view,
cellRect, cellRef,
2322 paintBorderRight, paintBorderBottom,
2323 paintBorderLeft, paintBorderTop,
2324 rightPen, bottomPen, leftPen, topPen,
2325 mergedCellsPainted);
2328 if ( d->extra()->mergedXCells > 0 || d->extra()->mergedYCells > 0 )
2329 mergedCellsPainted.prepend( cellRef );
2339 if ( painter.device()->isExtDev() )
2340 painter.setClipping(
false );
2345 paintCellBorders( painter, rect, cellRect0,
2347 paintBorderRight, paintBorderBottom,
2348 paintBorderLeft, paintBorderTop,
2349 rightPen, bottomPen, leftPen, topPen );
2353 if ( painter.device()->isExtDev() )
2354 painter.setClipping(
true );
2357 paintCellDiagonalLines( painter, cellRect0, cellRef );
2359 paintPageBorders( painter, cellRect0, cellRef,
2360 paintBorderRight, paintBorderBottom );
2367 if ( !painter.device()->isExtDev()
2368 ||
format()->
sheet()->print()->printCommentIndicator() )
2369 paintCommentIndicator( painter,
cellRect, cellRef, backgroundColor );
2372 if ( !painter.device()->isExtDev()
2373 ||
format()->
sheet()->print()->printFormulaIndicator() )
2374 paintFormulaIndicator( painter,
cellRect, backgroundColor );
2377 paintMoreTextIndicator( painter,
cellRect, backgroundColor );
2381 if (highlightBorder != Border_None)
2382 paintCellHighlight ( painter,
cellRect, cellRef, highlightBorder,
2383 rightHighlightPen, bottomHighlightPen,
2384 leftHighlightPen, topHighlightPen );
2391 if ( !d->strOutText.isEmpty()
2392 && ( !painter.device()->isExtDev()
2393 || !
format()->getDontprintText( cellRef.x(), cellRef.y() ) )
2395 &&
format()->isHideAll( cellRef.x(), cellRef.y() ) ) )
2397 paintText( painter,
cellRect, cellRef );
2404 if (
isObscured() && paintingObscured == 0 &&
2405 !( sheetDir == Sheet::RightToLeft && painter.device()->isExtDev() ) )
2415 if (d->hasExtra()) {
2416 TQValueList<TQPoint> listPoints;
2417 TQValueList<Cell*>::iterator it = d->extra()->obscuringCells.begin();
2418 TQValueList<Cell*>::iterator end = d->extra()->obscuringCells.end();
2419 for ( ; it != end; ++it ) {
2420 Cell *obscuringCell = *it;
2422 listPoints.append( TQPoint( obscuringCell->
column(), obscuringCell->
row() ) );
2425 TQValueList<TQPoint>::iterator it1 = listPoints.begin();
2426 TQValueList<TQPoint>::iterator end1 = listPoints.end();
2427 for ( ; it1 != end1; ++it1 ) {
2428 TQPoint obscuringCellRef = *it1;
2435 if ( mergedCellsPainted.contains( obscuringCellRef ) )
2438 Cell *obscuringCell =
format()->sheet()->cellAt( obscuringCellRef.x(),
2439 obscuringCellRef.y() );
2441 if ( obscuringCell != 0 ) {
2442 double x =
format()->sheet()->dblColumnPos( obscuringCellRef.x() );
2443 double y =
format()->sheet()->dblRowPos( obscuringCellRef.y() );
2449 KoPoint corner( x, y );
2456 obscuringCellRef.y() ) );
2458 obscuringCellRef.y() ) );
2460 obscuringCellRef.y() ) );
2462 obscuringCellRef.y() ) );
2473 obscuringCell->
paintCell( rect, painter, view,
2474 corner, obscuringCellRef,
2475 Border_Left|Border_Top|Border_Right|Border_Bottom,
2477 mergedCellsPainted);
2485 clearFlag( Flag_PaintingCell );
2499 if ( d->style == Cell::ST_Button ) {
2500 TQBrush fill( TQt::lightGray );
2501 TQApplication::style().drawControl( TQStyle::CE_PushButton, &_painter,
this,
2502 TQRect( _tx + 1, _ty + 1, w2 - 1, h2 - 1 ),
2503 defaultColorGroup );
2509 else if ( d->style == Cell::ST_Select ) {
2510 TQApplication::style().drawComboButton( &_painter, _tx + 1, _ty + 1,
2512 defaultColorGroup, selected );
2518 void Cell::paintCellHighlight(TQPainter& painter,
2520 const TQPoint& cellRef,
2521 const int highlightBorder,
2522 const TQPen& rightPen,
2523 const TQPen& bottomPen,
2524 const TQPen& leftPen,
2533 painter.setBrush(nullBrush);
2535 TQRect zoomedCellRect =
sheet()->doc()->zoomRect(
cellRect );
2540 zoomedCellRect.setLeft(zoomedCellRect.left()+1);
2542 zoomedCellRect.setTop(zoomedCellRect.top()+1);
2545 if ( cellRef.x() != KS_colMax )
2546 zoomedCellRect.setWidth( zoomedCellRect.width() - 1 );
2547 if ( cellRef.y() != KS_rowMax )
2548 zoomedCellRect.setHeight( zoomedCellRect.height() - 1 );
2550 if (highlightBorder & Border_Top)
2552 painter.setPen(topPen);
2553 painter.drawLine(zoomedCellRect.left(),zoomedCellRect.top(),zoomedCellRect.right(),zoomedCellRect.top());
2555 if (highlightBorder & Border_Left)
2557 painter.setPen(leftPen);
2558 painter.drawLine(zoomedCellRect.left(),zoomedCellRect.top(),zoomedCellRect.left(),zoomedCellRect.bottom());
2560 if (highlightBorder & Border_Right)
2562 painter.setPen(rightPen);
2563 painter.drawLine(zoomedCellRect.right(),zoomedCellRect.top(),zoomedCellRect.right(),zoomedCellRect.bottom());
2565 if (highlightBorder & Border_Bottom)
2567 painter.setPen(bottomPen);
2568 painter.drawLine(zoomedCellRect.left(),zoomedCellRect.bottom(),zoomedCellRect.right(),zoomedCellRect.bottom());
2571 if (highlightBorder & Border_SizeGrip)
2573 TQBrush brush(rightPen.color());
2574 painter.setBrush(brush);
2575 painter.setPen(rightPen);
2576 painter.drawRect(zoomedCellRect.right()-3,zoomedCellRect.bottom()-3,4,4);
2586void Cell::paintObscuredCells(
const KoRect& rect, TQPainter& painter,
2589 const TQPoint &cellRef,
2590 bool paintBorderRight,
2591 bool _paintBorderBottom,
2592 bool paintBorderLeft,
2593 bool _paintBorderTop,
2594 TQPen & rightPen, TQPen & _bottomPen,
2595 TQPen & leftPen, TQPen & _topPen,
2596 TQValueList<TQPoint> &mergedCellsPainted)
2607 for (
int y = 0; y <= maxY; ++y ) {
2609 RowFormat* rl =
format()->sheet()->rowFormat( cellRef.y() + y );
2611 for(
int x = 0; x <= maxX; ++ x ) {
2612 ColumnFormat * cl =
format()->sheet()->columnFormat( cellRef.x() + x );
2613 if ( y != 0 || x != 0 ) {
2614 uint
column = cellRef.x() + x;
2615 uint
row = cellRef.y() + y;
2619 bool paintBorderTop;
2620 bool paintBorderBottom;
2623 KoPoint corner( xpos, ypos );
2630 paintBorderTop = _paintBorderTop;
2635 paintBorderTop =
false;
2645 int penWidth = TQMAX(1,
sheet()->doc()->zoomItY( topPen.width() ));
2646 topPen.setWidth( penWidth );
2653 bottomPen = _bottomPen;
2654 paintBorderBottom = _paintBorderBottom;
2656 int paintBorder = Border_None;
2657 if (paintBorderLeft) paintBorder |= Cell::Border_Left;
2658 if (paintBorderRight) paintBorder |= Cell::Border_Right;
2659 if (paintBorderTop) paintBorder |= Cell::Border_Top;
2660 if (paintBorderBottom) paintBorder |= Cell::Border_Bottom;
2670 TQPoint( cellRef.x() + x, cellRef.y() + y ),
2672 rightPen, bottomPen, leftPen, topPen,
2673 mergedCellsPainted);
2675 xpos += cl->dblWidth();
2678 ypos += rl->dblHeight();
2685void Cell::paintBackground( TQPainter& painter,
const KoRect &
cellRect,
2686 const TQPoint &cellRef,
bool selected,
2687 TQColor &backgroundColor )
2689 TQColorGroup defaultColorGroup = TQApplication::palette().active();
2690 TQRect zoomedCellRect =
sheet()->doc()->zoomRect(
cellRect );
2698 if ( cellRef.x() != KS_colMax )
2699 zoomedCellRect.setWidth( zoomedCellRect.width() - 1 );
2700 if ( cellRef.y() != KS_rowMax )
2701 zoomedCellRect.setHeight( zoomedCellRect.height() - 1 );
2710 int averageColor = (backgroundColor.red() + backgroundColor.green() + backgroundColor.blue()) / 3;
2712 if (averageColor > 180)
2713 if (averageColor > 225)
2716 c = backgroundColor.light( 115 );
2718 c = backgroundColor.light( 125 );
2720 painter.setBackgroundColor( c );
2723 TQColor bg( backgroundColor );
2726 if ( !painter.device()->isExtDev() ) {
2728 painter.setBackgroundColor( bg );
2730 painter.setBackgroundColor( defaultColorGroup.base() );
2736 if ( !bg.isValid() )
2737 bb.setColor( TQt::white );
2739 painter.fillRect( zoomedCellRect, bb );
2745 if ( !painter.device()->isExtDev() )
2746 painter.eraseRect( zoomedCellRect );
2751 && d->extra()->conditions
2752 && d->extra()->conditions->matchedStyle()
2753 && d->extra()->conditions->matchedStyle()->hasFeature( Style::SBackgroundBrush,
true ) )
2754 bb = d->extra()->conditions->matchedStyle()->backGroundBrush();
2759 if ( bb.style() != TQt::NoBrush )
2760 painter.fillRect( zoomedCellRect, bb );
2762 backgroundColor = painter.backgroundColor();
2768void Cell::paintDefaultBorders( TQPainter& painter,
const KoRect &rect,
2770 const TQPoint &cellRef,
2771 bool paintBorderRight,
bool ,
2772 bool paintBorderLeft,
bool paintBorderTop,
2773 TQPen
const & rightPen, TQPen
const & ,
2774 TQPen
const & leftPen, TQPen
const & topPen )
2791 Doc* doc =
sheet()->doc();
2793 Sheet::LayoutDirection sheetDir =
format()->sheet()->layoutDirection();
2794 bool paintingToExternalDevice = painter.device()->isExtDev();
2803 bool paintBottom=
false;
2804 bool paintRight=
false;
2806 paintLeft = ( paintBorderLeft && leftPen.style() == TQt::NoPen
2807 &&
sheet()->getShowGrid() && sheetDir==Sheet::LeftToRight );
2808 paintRight = ( paintBorderRight && rightPen.style() == TQt::NoPen
2809 &&
sheet()->getShowGrid() && sheetDir==Sheet::RightToLeft );
2810 paintTop = ( paintBorderTop && topPen.style() == TQt::NoPen
2811 &&
sheet()->getShowGrid() );
2817 painter.setPen( TQPen(
sheet()->doc()->gridColor(), 1, TQt::SolidLine ) );
2820 if (d->hasExtra()) {
2821 TQValueList<Cell*>::const_iterator it = d->extra()->obscuringCells.begin();
2822 TQValueList<Cell*>::const_iterator end = d->extra()->obscuringCells.end();
2823 for ( ; it != end; ++it ) {
2826 paintTop = paintTop && ( cell->
row() == cellRef.y() );
2827 paintBottom =
false;
2829 if ( sheetDir == Sheet::RightToLeft ) {
2830 paintRight = paintRight && ( cell->
column() == cellRef.x() );
2834 paintLeft = paintLeft && ( cell->
column() == cellRef.x() );
2846 if ( cellRef.x() > 1 ) {
2847 Cell *cell_west =
format()->sheet()->cellAt( cellRef.x() - 1,
2852 if ( t.style() != TQt::NoPen )
2853 dt = ( t.width() + 1 )/2;
2854 if ( b.style() != TQt::NoPen )
2855 db = ( t.width() / 2);
2861 if ( paintingToExternalDevice ) {
2862 if ( sheetDir == Sheet::RightToLeft )
2863 painter.drawLine( doc->zoomItX( TQMAX( rect.left(),
cellRect.right() ) ),
2864 doc->zoomItY( TQMAX( rect.top(),
cellRect.y() + dt ) ),
2865 doc->zoomItX( TQMIN( rect.right(),
cellRect.right() ) ),
2866 doc->zoomItY( TQMIN( rect.bottom(),
cellRect.bottom() - db ) ) );
2868 painter.drawLine( doc->zoomItX( TQMAX( rect.left(),
cellRect.x() ) ),
2869 doc->zoomItY( TQMAX( rect.top(),
cellRect.y() + dt ) ),
2870 doc->zoomItX( TQMIN( rect.right(),
cellRect.x() ) ),
2871 doc->zoomItY( TQMIN( rect.bottom(),
cellRect.bottom() - db ) ) );
2874 if ( sheetDir == Sheet::RightToLeft )
2875 painter.drawLine( doc->zoomItX(
cellRect.right() ),
2878 doc->zoomItY(
cellRect.bottom() - db ) );
2880 painter.drawLine( doc->zoomItX(
cellRect.x() ),
2883 doc->zoomItY(
cellRect.bottom() - db ) );
2894 if ( cellRef.y() > 1 ) {
2895 Cell *cell_north =
format()->sheet()->cellAt( cellRef.x(),
2901 if ( l.style() != TQt::NoPen )
2902 dl = ( l.width() - 1 ) / 2 + 1;
2903 if ( r.style() != TQt::NoPen )
2912 if ( paintingToExternalDevice ) {
2913 painter.drawLine( doc->zoomItX( TQMAX( rect.left(),
cellRect.x() + dl ) ),
2914 doc->zoomItY( TQMAX( rect.top(),
cellRect.y() ) ),
2915 doc->zoomItX( TQMIN( rect.right(),
cellRect.right() - dr ) ),
2916 doc->zoomItY( TQMIN( rect.bottom(),
cellRect.y() ) ) );
2919 painter.drawLine( doc->zoomItX(
cellRect.x() + dl ),
2921 doc->zoomItX(
cellRect.right() - dr ),
2933 if ( cellRef.x() < KS_colMax ) {
2934 Cell *cell_east =
format()->sheet()->cellAt( cellRef.x() + 1,
2940 if ( t.style() != TQt::NoPen )
2941 dt = ( t.width() + 1 ) / 2;
2942 if ( b.style() != TQt::NoPen )
2943 db = ( t.width() / 2);
2951 if ( painter.device()->isExtDev() ) {
2952 if ( sheetDir == Sheet::RightToLeft )
2953 painter.drawLine( doc->zoomItX( TQMAX( rect.left(),
cellRect.x() ) ),
2954 doc->zoomItY( TQMAX( rect.top(),
cellRect.y() + dt ) ),
2955 doc->zoomItX( TQMIN( rect.right(),
cellRect.x() ) ),
2956 doc->zoomItY( TQMIN( rect.bottom(),
cellRect.bottom() - db ) ) );
2958 painter.drawLine( doc->zoomItX( TQMAX( rect.left(),
cellRect.right() ) ),
2959 doc->zoomItY( TQMAX( rect.top(),
cellRect.y() + dt ) ),
2960 doc->zoomItX( TQMIN( rect.right(),
cellRect.right() ) ),
2961 doc->zoomItY( TQMIN( rect.bottom(),
cellRect.bottom() - db ) ) );
2964 if ( sheetDir == Sheet::RightToLeft )
2965 painter.drawLine( doc->zoomItX(
cellRect.x() ),
2968 doc->zoomItY(
cellRect.bottom() - db ) );
2970 painter.drawLine( doc->zoomItX(
cellRect.right() ),
2973 doc->zoomItY(
cellRect.bottom() - db ) );
3016void Cell::paintCommentIndicator( TQPainter& painter,
3019 TQColor &backgroundColor )
3021 Doc * doc =
sheet()->doc();
3025 if ( (
format()->propertiesMask() & (uint) Format::PComment )
3028 && (
sheet()->print()->printCommentIndicator()
3029 || ( !painter.device()->isExtDev() &&
sheet()->getShowCommentIndicator() ) ) ) {
3030 TQColor penColor = TQt::red;
3033 if ( tqRed( backgroundColor.rgb() ) > 127 &&
3034 tqGreen( backgroundColor.rgb() ) < 80 &&
3035 tqBlue( backgroundColor.rgb() ) < 80 )
3037 penColor = TQt::blue;
3041 TQPointArray point( 3 );
3042 if (
format()->
sheet()->layoutDirection()==Sheet::RightToLeft ) {
3043 point.setPoint( 0, doc->zoomItX(
cellRect.x() + 6.0 ),
3045 point.setPoint( 1, doc->zoomItX(
cellRect.x() ),
3047 point.setPoint( 2, doc->zoomItX(
cellRect.x() ),
3048 doc->zoomItY(
cellRect.y() + 6.0 ) );
3051 point.setPoint( 0, doc->zoomItX(
cellRect.right() - 5.0 ),
3053 point.setPoint( 1, doc->zoomItX(
cellRect.right() ),
3055 point.setPoint( 2, doc->zoomItX(
cellRect.right() ),
3056 doc->zoomItY(
cellRect.y() + 5.0 ) );
3060 painter.setBrush( TQBrush( penColor ) );
3061 painter.setPen( TQt::NoPen );
3062 painter.drawPolygon( point );
3070void Cell::paintFormulaIndicator( TQPainter& painter,
3072 TQColor &backgroundColor )
3079 Doc* doc =
sheet()->doc();
3081 TQColor penColor = TQt::blue;
3083 if ( tqRed( backgroundColor.rgb() ) < 80 &&
3084 tqGreen( backgroundColor.rgb() ) < 80 &&
3085 tqBlue( backgroundColor.rgb() ) > 127 )
3087 penColor = TQt::red;
3091 TQPointArray point( 3 );
3092 if (
format()->
sheet()->layoutDirection()==Sheet::RightToLeft ) {
3093 point.setPoint( 0, doc->zoomItX(
cellRect.right() - 6.0 ),
3094 doc->zoomItY(
cellRect.bottom() ) );
3095 point.setPoint( 1, doc->zoomItX(
cellRect.right() ),
3096 doc->zoomItY(
cellRect.bottom() ) );
3097 point.setPoint( 2, doc->zoomItX(
cellRect.right() ),
3098 doc->zoomItY(
cellRect.bottom() - 6.0 ) );
3101 point.setPoint( 0, doc->zoomItX(
cellRect.x() ),
3102 doc->zoomItY(
cellRect.bottom() - 6.0 ) );
3103 point.setPoint( 1, doc->zoomItX(
cellRect.x() ),
3104 doc->zoomItY(
cellRect.bottom() ) );
3105 point.setPoint( 2, doc->zoomItX(
cellRect.x() + 6.0 ),
3106 doc->zoomItY(
cellRect.bottom() ) );
3110 painter.setBrush( TQBrush( penColor ) );
3111 painter.setPen( TQt::NoPen );
3112 painter.drawPolygon( point );
3119void Cell::paintMoreTextIndicator( TQPainter& painter,
3121 TQColor &backgroundColor )
3125 if( testFlag( Flag_CellTooShortX ) &&
3126 !painter.device()->isExtDev() &&
3130 Doc* doc =
sheet()->doc();
3132 TQColor penColor = TQt::red;
3134 if ( tqRed( backgroundColor.rgb() ) > 127
3135 && tqGreen( backgroundColor.rgb() ) < 80
3136 && tqBlue( backgroundColor.rgb() ) < 80 )
3138 penColor = TQt::blue;
3142 TQPointArray point( 3 );
3143 if ( d->strOutText.isRightToLeft() ) {
3144 point.setPoint( 0, doc->zoomItX(
cellRect.left() + 4.0 ),
3146 point.setPoint( 1, doc->zoomItX(
cellRect.left() ),
3148 point.setPoint( 2, doc->zoomItX(
cellRect.left() + 4.0 ),
3152 point.setPoint( 0, doc->zoomItX(
cellRect.right() - 4.0 ),
3154 point.setPoint( 1, doc->zoomItX(
cellRect.right() ),
3156 point.setPoint( 2, doc->zoomItX(
cellRect.right() - 4.0 ),
3161 painter.setBrush( TQBrush( penColor ) );
3162 painter.setPen( TQt::NoPen );
3163 painter.drawPolygon( point );
3170void Cell::paintText( TQPainter& painter,
3172 const TQPoint &cellRef )
3174 Doc *doc =
sheet()->doc();
3176 ColumnFormat *colFormat =
format()->sheet()->columnFormat( cellRef.x() );
3178 TQColorGroup defaultColorGroup = TQApplication::palette().active();
3179 TQColor textColorPrint = effTextColor( cellRef.x(), cellRef.y() );
3182 if ( !textColorPrint.isValid() ) {
3183 if ( painter.device()->isExtDev() )
3184 textColorPrint = TQt::black;
3186 textColorPrint = TQApplication::palette().active().text();
3189 TQPen tmpPen( textColorPrint );
3196 || !d->extra()->conditions
3197 || !d->extra()->conditions->matchedStyle() ) {
3198 if (
value().isNumber()
3201 &&
format()->isHideFormula( d->column, d->row ) ) ) )
3204 if (
format()->floatColor( cellRef.x(), cellRef.y()) == Format::NegRed
3206 tmpPen.setColor( TQt::red );
3212 tmpPen.setColor( TQApplication::palette().active().
link() );
3213 TQFont f = painter.font();
3214 f.setUnderline(
true );
3215 painter.setFont( f );
3235 if ( selected && ( cellRef.x() != marker.x() || cellRef.y() != marker.y() ) )
3238 p.setColor( defaultColorGroup.highlightedText() );
3239 painter.setPen( p );
3242 painter.setPen(tmpPen);
3245 painter.setPen( tmpPen );
3247 TQString tmpText = d->strOutText;
3248 double tmpHeight = d->textHeight;
3249 double tmpWidth = d->textWidth;
3257 if ( testFlag( Flag_CellTooShortX ) ) {
3267 &&
value().isNumber()
3268 &&
value().asFloat() == 0 ) {
3269 d->strOutText = TQString();
3277 if ( colFormat->isHide() || (
cellRect.height() <= 2 ) ) {
3278 freeAllObscuredCells();
3283 double indent = 0.0;
3284 double offsetCellTooShort = 0.0;
3285 int a = effAlignX();
3288 if ( a == Format::Left && !
isEmpty() ) {
3295 && d->extra()->conditions
3296 && d->extra()->conditions->matchedStyle()
3297 && d->extra()->conditions->matchedStyle()->hasFeature( Style::SIndent,
true ) )
3298 indent = d->extra()->conditions->matchedStyle()->indent();
3304 if ( a == Format::Right && !
isEmpty() && testFlag( Flag_CellTooShortX ) )
3305 offsetCellTooShort =
format()->sheet()->doc()->unzoomItX( 4 );
3307 TQFontMetrics fm2 = painter.fontMetrics();
3308 double offsetFont = 0.0;
3312 offsetFont =
format()->sheet()->doc()->unzoomItX( fm2.underlinePos() + 1 );
3316 bool tmpVerticalText;
3320 && d->extra()->conditions
3321 && d->extra()->conditions->matchedStyle() )
3323 Style *matchedStyle = d->extra()->conditions->matchedStyle();
3325 if ( matchedStyle->hasFeature( Style::SAngle,
true ) )
3326 tmpAngle = d->extra()->conditions->matchedStyle()->rotateAngle();
3328 tmpAngle =
format()->getAngle( cellRef.x(), cellRef.y() );
3330 if ( matchedStyle->hasFeature( Style::SVerticalText,
true ) )
3331 tmpVerticalText = matchedStyle->hasProperty( Style::PVerticalText );
3333 tmpVerticalText =
format()->verticalText( cellRef.x(), cellRef.y() );
3335 if ( matchedStyle->hasFeature( Style::SMultiRow,
true ) )
3336 tmpMultiRow = matchedStyle->hasProperty( Style::PMultiRow );
3338 tmpMultiRow =
format()->multiRow( cellRef.x(), cellRef.y() );
3341 tmpAngle =
format()->getAngle( cellRef.x(), cellRef.y() );
3342 tmpVerticalText =
format()->verticalText( cellRef.x(), cellRef.y() );
3343 tmpMultiRow =
format()->multiRow( cellRef.x(), cellRef.y() );
3352 if ( !tmpMultiRow && !tmpVerticalText && !tmpAngle ) {
3355 painter.drawText( doc->zoomItX( indent +
cellRect.x() + d->textX - offsetCellTooShort ),
3356 doc->zoomItY(
cellRect.y() + d->textY - offsetFont ), d->strOutText );
3358 else if ( tmpAngle != 0 ) {
3361 int angle = tmpAngle;
3362 TQFontMetrics fm = painter.fontMetrics();
3364 painter.rotate( angle );
3367 x = indent +
cellRect.x() + d->textX;
3369 x = indent +
cellRect.x() + d->textX
3370 - doc->unzoomItX((
int) (( fm.descent() + fm.ascent() ) * sin( angle * M_PI / 180 )));
3375 y =
cellRect.y() + d->textY + d->textHeight;
3376 painter.drawText( doc->zoomItX( x * cos( angle * M_PI / 180 ) +
3377 y * sin( angle * M_PI / 180 ) ),
3378 doc->zoomItY( -x * sin( angle * M_PI / 180 ) +
3379 y * cos( angle * M_PI / 180 ) ),
3381 painter.rotate( -angle );
3383 else if ( tmpMultiRow && !tmpVerticalText ) {
3390 TQFontMetrics fm = painter.fontMetrics();
3392 i = d->strOutText.find(
"\n", pos );
3394 t = d->strOutText.mid( pos, d->strOutText.length() - pos );
3396 t = d->strOutText.mid( pos, i - pos );
3400 int align = effAlignX();
3403 &&
format()->isHideFormula( d->column, d->row ) ) )
3404 align = Format::Left;
3409 d->textX =
effLeftBorderPen( cellRef.x(), cellRef.y() ).width() + BORDER_SPACE;
3413 d->textX =
cellRect.width() - BORDER_SPACE - doc->unzoomItX( fm.width( t ) )
3417 case Format::Center:
3418 d->textX = (
cellRect.width() - doc->unzoomItX( fm.width( t ) ) ) / 2;
3421 painter.drawText( doc->zoomItX( indent +
cellRect.x() + d->textX ),
3422 doc->zoomItY(
cellRect.y() + d->textY + dy ), t );
3423 dy += doc->unzoomItY( fm.descent() + fm.ascent() );
3424 }
while ( i != -1 );
3426 else if ( tmpVerticalText && !d->strOutText.isEmpty() ) {
3433 TQFontMetrics fm = painter.fontMetrics();
3435 len = d->strOutText.length();
3436 t = d->strOutText.at( i );
3437 painter.drawText( doc->zoomItX( indent +
cellRect.x() + d->textX ),
3438 doc->zoomItY(
cellRect.y() + d->textY + dy ), t );
3439 dy += doc->unzoomItY( fm.descent() + fm.ascent() );
3441 }
while ( i != len );
3445 if ( testFlag( Flag_CellTooShortX ) ) {
3446 d->strOutText = tmpText;
3447 d->textHeight = tmpHeight;
3448 d->textWidth = tmpWidth;
3452 &&
value().asFloat() == 0 )
3453 d->strOutText = tmpText;
3455 if ( colFormat->isHide() || (
cellRect.height() <= 2 ) )
3456 d->strOutText = tmpText;
3462void Cell::paintPageBorders( TQPainter& painter,
3464 const TQPoint &cellRef,
3465 bool paintBorderRight,
3466 bool paintBorderBottom )
3469 if ( painter.device()->isExtDev() )
3475 SheetPrint* print =
format()->sheet()->print();
3477 Sheet::LayoutDirection sheetDir =
format()->sheet()->layoutDirection();
3479 Doc* doc =
sheet()->doc();
3480 int zcellRect_left = doc->zoomItX (
cellRect.left());
3481 int zcellRect_right = doc->zoomItX (
cellRect.right());
3482 int zcellRect_top = doc->zoomItY (
cellRect.top());
3483 int zcellRect_bottom = doc->zoomItY (
cellRect.bottom());
3487 if ( cellRef.x() >= print->printRange().left()
3488 && cellRef.x() <= print->printRange().right() + 1
3489 && cellRef.y() >= print->printRange().top()
3490 && cellRef.y() <= print->printRange().bottom() + 1 )
3492 if ( print->isOnNewPageX( cellRef.x() )
3493 && cellRef.y() <= print->printRange().bottom() )
3495 painter.setPen(
sheet()->doc()->pageBorderColor() );
3497 if ( sheetDir == Sheet::RightToLeft )
3498 painter.drawLine( zcellRect_right, zcellRect_top,
3499 zcellRect_right, zcellRect_bottom );
3501 painter.drawLine( zcellRect_left, zcellRect_top,
3502 zcellRect_left, zcellRect_bottom );
3505 if ( print->isOnNewPageY( cellRef.y() ) &&
3506 ( cellRef.x() <= print->printRange().right() ) )
3508 painter.setPen(
sheet()->doc()->pageBorderColor() );
3509 painter.drawLine( zcellRect_left, zcellRect_top,
3510 zcellRect_right, zcellRect_top );
3513 if ( paintBorderRight ) {
3514 if ( print->isOnNewPageX( cellRef.x() + 1 )
3515 && cellRef.y() <= print->printRange().bottom() ) {
3516 painter.setPen(
sheet()->doc()->pageBorderColor() );
3518 if ( sheetDir == Sheet::RightToLeft )
3519 painter.drawLine( zcellRect_left, zcellRect_top,
3520 zcellRect_left, zcellRect_bottom );
3522 painter.drawLine( zcellRect_right, zcellRect_top,
3523 zcellRect_right, zcellRect_bottom );
3527 if ( paintBorderBottom ) {
3528 if ( print->isOnNewPageY( cellRef.y() + 1 )
3529 && cellRef.x() <= print->printRange().right() ) {
3530 painter.setPen(
sheet()->doc()->pageBorderColor() );
3531 painter.drawLine( zcellRect_left, zcellRect_bottom,
3532 zcellRect_right, zcellRect_bottom );
3541void Cell::paintCellBorders( TQPainter& painter,
const KoRect& rect,
3543 const TQPoint &cellRef,
3544 bool paintRight,
bool paintBottom,
3545 bool paintLeft,
bool paintTop,
3546 TQPen & _rightPen, TQPen & _bottomPen,
3547 TQPen & _leftPen, TQPen & _topPen )
3552 if ( (!paintLeft) && (!paintRight) && (!paintTop) && (!paintBottom) )
3555 Doc * doc =
sheet()->doc();
3557 Sheet::LayoutDirection sheetDir =
format()->sheet()->layoutDirection();
3562 int zrect_left (doc->zoomItX (rect.left()));
3563 int zrect_right (doc->zoomItX (rect.right()));
3564 int zrect_top (doc->zoomItY (rect.top()));
3565 int zrect_bottom (doc->zoomItY (rect.bottom()));
3566 int zcellRect_left (doc->zoomItX (
cellRect.left()));
3567 int zcellRect_right (doc->zoomItX (
cellRect.right()));
3568 int zcellRect_top (doc->zoomItY (
cellRect.top()));
3569 int zcellRect_bottom (doc->zoomItY (
cellRect.bottom()));
3582 if (d->hasExtra()) {
3583 TQValueList<Cell*>::const_iterator it = d->extra()->obscuringCells.begin();
3584 TQValueList<Cell*>::const_iterator end = d->extra()->obscuringCells.end();
3585 for ( ; it != end; ++it ) {
3588 int xDiff = cellRef.x() - cell->
column();
3589 int yDiff = cellRef.y() - cell->
row();
3590 paintLeft = paintLeft && xDiff == 0;
3591 paintTop = paintTop && yDiff == 0;
3595 paintRight = paintRight && cell->
mergedXCells() == xDiff;
3596 paintBottom = paintBottom && cell->
mergedYCells() == yDiff;
3602 TQPen leftPen( _leftPen );
3603 TQPen rightPen( _rightPen );
3604 TQPen topPen( _topPen );
3605 TQPen bottomPen( _bottomPen );
3610 int left_penWidth = TQMAX( 1, doc->zoomItX( leftPen.width() ) );
3611 int right_penWidth = TQMAX( 1, doc->zoomItX( rightPen.width() ) );
3612 int top_penWidth = TQMAX( 1, doc->zoomItY( topPen.width() ) );
3613 int bottom_penWidth = TQMAX( 1, doc->zoomItY( bottomPen.width() ) );
3615 leftPen.setWidth( left_penWidth );
3616 rightPen.setWidth( right_penWidth );
3617 topPen.setWidth( top_penWidth );
3618 bottomPen.setWidth( bottom_penWidth );
3620 if ( paintLeft && leftPen.style() != TQt::NoPen ) {
3621 int top = ( TQMAX( 0, -1 + top_penWidth ) ) / 2 +
3622 ( ( TQMAX( 0, -1 + top_penWidth ) ) % 2 );
3623 int bottom = ( TQMAX( 0, -1 + bottom_penWidth ) ) / 2 + 1;
3625 painter.setPen( leftPen );
3631 if ( painter.device()->isExtDev() ) {
3642 if ( sheetDir == Sheet::RightToLeft )
3643 painter.drawLine( TQMIN( zrect_right, zcellRect_right ),
3644 TQMAX( zrect_top, zcellRect_top - top ),
3645 TQMIN( zrect_right, zcellRect_right ),
3646 TQMIN( zrect_bottom, zcellRect_bottom + bottom ) );
3648 painter.drawLine( TQMAX( zrect_left, zcellRect_left ),
3649 TQMAX( zrect_top, zcellRect_top - top ),
3650 TQMAX( zrect_left, zcellRect_left ),
3651 TQMIN( zrect_bottom, zcellRect_bottom + bottom ) );
3654 if ( sheetDir == Sheet::RightToLeft )
3655 painter.drawLine( zcellRect_right,
3656 zcellRect_top - top,
3658 zcellRect_bottom + bottom );
3660 painter.drawLine( zcellRect_left,
3661 zcellRect_top - top,
3663 zcellRect_bottom + bottom );
3667 if ( paintRight && rightPen.style() != TQt::NoPen ) {
3668 int top = ( TQMAX( 0, -1 + top_penWidth ) ) / 2 +
3669 ( ( TQMAX( 0, -1 + top_penWidth ) ) % 2 );
3670 int bottom = ( TQMAX( 0, -1 + bottom_penWidth ) ) / 2 + 1;
3672 painter.setPen( rightPen );
3678 if ( painter.device()->isExtDev() ) {
3679 if ( sheetDir == Sheet::RightToLeft )
3680 painter.drawLine( TQMAX( zrect_left, zcellRect_left ),
3681 TQMAX( zrect_top, zcellRect_top - top ),
3682 TQMAX( zrect_left, zcellRect_left ),
3683 TQMIN( zrect_bottom, zcellRect_bottom + bottom ) );
3689 if ( zcellRect_right <= zrect_right + right_penWidth / 2)
3690 painter.drawLine( zcellRect_right,
3691 TQMAX( zrect_top, zcellRect_top - top ),
3693 TQMIN( zrect_bottom, zcellRect_bottom + bottom ) );
3697 if ( sheetDir == Sheet::RightToLeft )
3698 painter.drawLine( zcellRect_left,
3699 zcellRect_top - top,
3701 zcellRect_bottom + bottom );
3703 painter.drawLine( zcellRect_right,
3704 zcellRect_top - top,
3706 zcellRect_bottom + bottom );
3710 if ( paintTop && topPen.style() != TQt::NoPen ) {
3711 painter.setPen( topPen );
3719 if ( painter.device()->isExtDev() ) {
3720 if ( zcellRect_top >= zrect_top + top_penWidth / 2)
3721 painter.drawLine( TQMAX( zrect_left, zcellRect_left ),
3723 TQMIN( zrect_right, zcellRect_right ),
3727 painter.drawLine( zcellRect_left, zcellRect_top,
3728 zcellRect_right, zcellRect_top );
3732 if ( paintBottom && bottomPen.style() != TQt::NoPen ) {
3733 painter.setPen( bottomPen );
3741 if ( painter.device()->isExtDev() ) {
3742 if ( zcellRect_bottom <= zrect_bottom + bottom_penWidth / 2)
3743 painter.drawLine( TQMAX( zrect_left, zcellRect_left ),
3745 TQMIN( zrect_right, zcellRect_right ),
3749 painter.drawLine( zcellRect_left, zcellRect_bottom,
3750 zcellRect_right, zcellRect_bottom );
3767 TQPen vert_pen, horz_pen;
3768 int vert_penWidth, horz_penWidth;
3771 Cell *cell_north =
format()->sheet()->cellAt( cellRef.x(),
3773 Cell *cell_northwest =
format()->sheet()->cellAt( cellRef.x() - 1,
3775 Cell *cell_west =
format()->sheet()->cellAt( cellRef.x() - 1,
3777 Cell *cell_northeast =
format()->sheet()->cellAt( cellRef.x() + 1,
3779 Cell *cell_east =
format()->sheet()->cellAt( cellRef.x() + 1,
3781 Cell *cell_south =
format()->sheet()->cellAt( cellRef.x(),
3783 Cell *cell_southwest =
format()->sheet()->cellAt( cellRef.x() - 1,
3785 Cell *cell_southeast =
format()->sheet()->cellAt( cellRef.x() + 1,
3796 vert_penWidth = TQMAX( 1, doc->zoomItX( vert_pen.width() ) );
3797 vert_pen.setWidth( vert_penWidth );
3799 if ( vert_pen.style() != TQt::NoPen ) {
3802 horz_pen = cell_west->
effTopBorderPen( cellRef.x() - 1, cellRef.y() );
3807 horz_penWidth = TQMAX( 1, doc->zoomItY( horz_pen.width() ) );
3808 int bottom = ( TQMAX( 0, -1 + horz_penWidth ) ) / 2 + 1;
3810 painter.setPen( vert_pen );
3813 if ( painter.device()->isExtDev() ) {
3814 if ( sheetDir == Sheet::RightToLeft )
3815 painter.drawLine( TQMAX( zrect_left, zcellRect_right ),
3816 TQMAX( zrect_top, zcellRect_top ),
3817 TQMIN( zrect_right, zcellRect_right ),
3818 TQMIN( zrect_bottom, zcellRect_top + bottom ) );
3820 painter.drawLine( TQMAX( zrect_left, zcellRect_left ),
3821 TQMAX( zrect_top, zcellRect_top ),
3822 TQMIN( zrect_right, zcellRect_left ),
3823 TQMIN( zrect_bottom, zcellRect_top + bottom ) );
3826 if ( sheetDir == Sheet::RightToLeft )
3827 painter.drawLine( zcellRect_right, zcellRect_top,
3828 zcellRect_right, zcellRect_top + bottom );
3830 painter.drawLine( zcellRect_left, zcellRect_top,
3831 zcellRect_left, zcellRect_top + bottom );
3845 vert_penWidth = TQMAX( 1, doc->zoomItX( vert_pen.width() ) );
3846 vert_pen.setWidth( vert_penWidth );
3847 if ( ( vert_pen.style() != TQt::NoPen ) && ( cellRef.x() < KS_colMax ) ) {
3851 horz_pen = cell_east->
effTopBorderPen( cellRef.x() + 1, cellRef.y() );
3857 horz_penWidth = TQMAX( 1, doc->zoomItY( horz_pen.width() ) );
3858 int bottom = ( TQMAX( 0, -1 + horz_penWidth ) ) / 2 + 1;
3860 painter.setPen( vert_pen );
3863 if ( painter.device()->isExtDev() ) {
3864 if ( sheetDir == Sheet::RightToLeft )
3865 painter.drawLine( TQMAX( zrect_left, zcellRect_left ),
3866 TQMAX( zrect_top, zcellRect_top ),
3867 TQMIN( zrect_right, zcellRect_left ),
3868 TQMIN( zrect_bottom, zcellRect_top + bottom ) );
3870 painter.drawLine( TQMAX( zrect_left, zcellRect_right ),
3871 TQMAX( zrect_top, zcellRect_top ),
3872 TQMIN( zrect_right, zcellRect_right ),
3873 TQMIN( zrect_bottom, zcellRect_top + bottom ) );
3876 if ( sheetDir == Sheet::RightToLeft )
3877 painter.drawLine( zcellRect_left, zcellRect_top,
3878 zcellRect_left, zcellRect_top + bottom );
3880 painter.drawLine( zcellRect_right, zcellRect_top,
3881 zcellRect_right, zcellRect_top + bottom );
3886 if ( cellRef.y() < KS_rowMax ) {
3897 vert_penWidth = TQMAX( 1, doc->zoomItY( vert_pen.width() ) );
3898 vert_pen.setWidth( vert_penWidth );
3899 if ( vert_pen.style() != TQt::NoPen ) {
3910 horz_penWidth = TQMAX( 1, doc->zoomItX( horz_pen.width() ) );
3911 int bottom = ( TQMAX( 0, -1 + horz_penWidth ) ) / 2;
3913 painter.setPen( vert_pen );
3916 if ( painter.device()->isExtDev() ) {
3917 if ( sheetDir == Sheet::RightToLeft )
3918 painter.drawLine( TQMAX( zrect_left, zcellRect_right ),
3919 TQMAX( zrect_top, zcellRect_bottom - bottom ),
3920 TQMIN( zrect_right, zcellRect_right ),
3921 TQMIN( zrect_bottom, zcellRect_bottom ) );
3923 painter.drawLine( TQMAX( zrect_left, zcellRect_left ),
3924 TQMAX( zrect_top, zcellRect_bottom - bottom ),
3925 TQMIN( zrect_right, zcellRect_left ),
3926 TQMIN( zrect_bottom, zcellRect_bottom ) );
3929 if ( sheetDir == Sheet::RightToLeft )
3930 painter.drawLine( zcellRect_right, zcellRect_bottom - bottom,
3931 zcellRect_right, zcellRect_bottom );
3933 painter.drawLine( zcellRect_left, zcellRect_bottom - bottom,
3934 zcellRect_left, zcellRect_bottom );
3948 vert_penWidth = TQMAX( 1, doc->zoomItY( vert_pen.width() ) );
3949 vert_pen.setWidth( vert_penWidth );
3950 if ( ( vert_pen.style() != TQt::NoPen ) && ( cellRef.x() < KS_colMax ) ) {
3955 horz_pen =
format()->sheet()->cellAt( cellRef.x() + 1, cellRef.y() )
3958 horz_pen =
format()->sheet()->cellAt( cellRef.x() + 1, cellRef.y() + 1 )
3962 horz_penWidth = TQMAX( 1, doc->zoomItX( horz_pen.width() ) );
3963 int bottom = ( TQMAX( 0, -1 + horz_penWidth ) ) / 2;
3965 painter.setPen( vert_pen );
3968 if ( painter.device()->isExtDev() ) {
3969 if ( sheetDir == Sheet::RightToLeft )
3970 painter.drawLine( TQMAX( zrect_left, zcellRect_left ),
3971 TQMAX( zrect_top, zcellRect_bottom - bottom ),
3972 TQMIN( zrect_right, zcellRect_left ),
3973 TQMIN( zrect_bottom, zcellRect_bottom ) );
3975 painter.drawLine( TQMAX( zrect_left, zcellRect_right ),
3976 TQMAX( zrect_top, zcellRect_bottom - bottom ),
3977 TQMIN( zrect_right, zcellRect_right ),
3978 TQMIN( zrect_bottom, zcellRect_bottom ) );
3981 if ( sheetDir == Sheet::RightToLeft )
3982 painter.drawLine( zcellRect_left, zcellRect_bottom - bottom,
3983 zcellRect_left, zcellRect_bottom );
3985 painter.drawLine( zcellRect_right, zcellRect_bottom - bottom,
3986 zcellRect_right, zcellRect_bottom );
3996void Cell::paintCellDiagonalLines( TQPainter& painter,
3998 const TQPoint &cellRef )
4003 Doc* doc =
sheet()->doc();
4007 painter.drawLine( doc->zoomItX(
cellRect.x() ),
4010 doc->zoomItY(
cellRect.bottom() ) );
4015 painter.drawLine( doc->zoomItX(
cellRect.x() ),
4030 if ( a == Format::Undefined )
4034 a = (d->strOutText.isRightToLeft()) ?
4035 Format::Right : Format::Left;
4048int Cell::effAlignX()
4050 if ( d->hasExtra() && d->extra()->conditions
4051 && d->extra()->conditions->matchedStyle()
4052 && d->extra()->conditions->matchedStyle()->hasFeature( Style::SAlignX,
true ) )
4053 return d->extra()->conditions->matchedStyle()->alignX();
4065 TQFontMetrics fm = _painter.fontMetrics();
4075 int extraXCells = d->hasExtra() ? d->extra()->extraXCells : 0;
4078 ColumnFormat *cl2 =
format()->sheet()->columnFormat( i );
4079 len += cl2->dblWidth() - 1.0;
4083 double tmpIndent = 0.0;
4089 for (
int i = d->strOutText.length(); i != 0; i-- )
4093 if ( a == Format::Left || a == Format::Undefined || isNumeric)
4094 tmp = d->strOutText.left(i);
4095 else if ( a == Format::Right)
4096 tmp = d->strOutText.right(i);
4098 tmp = d->strOutText.mid( ( d->strOutText.length() - i ) / 2, i);
4108 if (!tmp.contains(
'.'))
4109 d->strOutText=TQString().fill(
'#',20);
4113 if (
format()->
sheet()->doc()->unzoomItX( fm.width( tmp ) ) + tmpIndent
4119 RowFormat *rl =
format()->sheet()->rowFormat(
row() );
4120 if ( d->textHeight > rl->dblHeight() )
4122 for (
int j = d->strOutText.length(); j != 0; j-- )
4124 tmp2 = d->strOutText.left( j );
4125 if (
format()->
sheet()->doc()->unzoomItY( fm.width( tmp2 ) ) < rl->dblHeight() - 1.0 )
4127 return d->strOutText.left( TQMIN( tmp.length(), tmp2.length() ) );
4139 return TQString(
"" );
4144 RowFormat *rl =
format()->sheet()->rowFormat(
row() );
4145 double tmpIndent = 0.0;
4149 int extraXCells = d->hasExtra() ? d->extra()->extraXCells : 0;
4152 ColumnFormat *cl2 =
format()->sheet()->columnFormat( i );
4155 len += cl2->dblWidth() - 1.0;
4161 if ( ( d->textWidth + tmpIndent > len ) || d->textWidth == 0.0 )
4162 return TQString(
"" );
4164 for (
int i = d->strOutText.length(); i != 0; i-- ) {
4165 if (
format()->
sheet()->doc()->unzoomItY( fm.ascent() + fm.descent() ) * i
4166 < rl->dblHeight() - 1.0 )
4167 return d->strOutText.left( i );
4170 return TQString(
"" );
4173 ColumnFormat *cl =
format()->sheet()->columnFormat(
column() );
4174 double w = cl->dblWidth();
4176 if ( d->hasExtra() && (d->extra()->extraWidth != 0.0) )
4177 w = d->extra()->extraWidth;
4180 for (
int i = d->strOutText.length(); i != 0; i-- ) {
4181 tmp = d->strOutText.left( i );
4184 if (
format()->
sheet()->doc()->unzoomItX( fm.width( tmp ) ) < w - 4.0 - 1.0 )
4199 if ( testFlag(Flag_Merged) )
4200 return d->extra()->extraWidth;
4202 const ColumnFormat *cl =
format()->sheet()->columnFormat( _col );
4203 return cl->dblWidth( _canvas );
4206 if ( testFlag(Flag_Merged) )
4207 return d->extra()->extraWidth;
4209 const ColumnFormat *cl =
format()->sheet()->columnFormat( _col );
4210 return cl->dblWidth();
4215 return int(
dblWidth( _col, _canvas ) );
4225 if ( testFlag(Flag_Merged) )
4226 return d->extra()->extraHeight;
4228 const RowFormat *rl =
format()->sheet()->rowFormat( _row );
4229 return rl->dblHeight( _canvas );
4232 if ( testFlag(Flag_Merged) )
4233 return d->extra()->extraHeight;
4235 const RowFormat *rl =
format()->sheet()->rowFormat( _row );
4236 return rl->dblHeight();
4241 return int(
dblHeight( _row, _canvas ) );
4253 if ( d->hasExtra() && (!d->extra()->obscuringCells.isEmpty()) )
4255 const Cell* cell = d->extra()->obscuringCells.first();
4256 return cell->backGroundBrush( cell->column(), cell->row() );
4259 return format()->backGroundBrush( _col, _row );
4264 if ( d->hasExtra() && (!d->extra()->obscuringCells.isEmpty()) )
4266 const Cell* cell = d->extra()->obscuringCells.first();
4267 return cell->bgColor( cell->column(), cell->row() );
4270 return format()->bgColor( _col, _row );
4285 if ( cell && cell->format()->hasProperty( Format::PRightBorder )
4287 cell->
format()->clearProperty( Format::PRightBorder );
4290 format()->setLeftBorderPen( p );
4298 if ( cell && cell->format()->hasProperty( Format::PBottomBorder )
4300 cell->
format()->clearProperty( Format::PBottomBorder );
4302 format()->setTopBorderPen( p );
4308 if (
column() < KS_colMax )
4311 if ( cell && cell->format()->hasProperty( Format::PLeftBorder )
4313 cell->
format()->clearProperty( Format::PLeftBorder );
4315 format()->setRightBorderPen( p );
4321 if (
row() < KS_rowMax )
4324 if ( cell && cell->format()->hasProperty( Format::PTopBorder )
4326 cell->
format()->clearProperty( Format::PTopBorder );
4328 format()->setBottomBorderPen( p );
4333 if ( !
format()->hasProperty( Format::PRightBorder ) && ( _col < KS_colMax ) )
4335 Cell * cell =
format()->sheet()->cellAt( _col + 1, _row );
4336 if ( cell && cell->format()->hasProperty( Format::PLeftBorder ) )
4340 return format()->rightBorderPen( _col, _row );
4345 if ( !
format()->hasProperty( Format::PLeftBorder ) )
4347 const Cell * cell =
format()->sheet()->cellAt( _col - 1, _row );
4348 if ( cell && cell->format()->hasProperty( Format::PRightBorder ) )
4352 return format()->leftBorderPen( _col, _row );
4357 if ( !
format()->hasProperty( Format::PBottomBorder ) && ( _row < KS_rowMax ) )
4359 const Cell * cell =
format()->sheet()->cellAt( _col, _row + 1 );
4360 if ( cell && cell->format()->hasProperty( Format::PTopBorder ) )
4364 return format()->bottomBorderPen( _col, _row );
4369 if ( !
format()->hasProperty( Format::PTopBorder ) )
4371 const Cell * cell =
format()->sheet()->cellAt( _col, _row - 1 );
4372 if ( cell->format()->hasProperty( Format::PBottomBorder ) )
4376 return format()->topBorderPen( _col, _row );
4379const TQColor & Cell::effTextColor(
int col,
int row )
const
4381 if ( d->hasExtra() && d->extra()->conditions
4382 && d->extra()->conditions->matchedStyle()
4383 && d->extra()->conditions->matchedStyle()->hasFeature( Style::STextPen,
true ) )
4384 return d->extra()->conditions->matchedStyle()->pen().color();
4393 Cell * cell = d->extra()->obscuringCells.first();
4394 return cell->effLeftBorderPen( cell->column(), cell->row() );
4397 if ( d->hasExtra() && d->extra()->conditions
4398 && d->extra()->conditions->matchedStyle()
4399 && d->extra()->conditions->matchedStyle()->hasFeature( Style::SLeftBorder,
true ) )
4400 return d->extra()->conditions->matchedStyle()->leftBorderPen();
4409 Cell * cell = d->extra()->obscuringCells.first();
4410 return cell->effTopBorderPen( cell->column(), cell->row() );
4413 if ( d->hasExtra() && d->extra()->conditions
4414 && d->extra()->conditions->matchedStyle()
4415 && d->extra()->conditions->matchedStyle()->hasFeature( Style::STopBorder,
true ) )
4416 return d->extra()->conditions->matchedStyle()->topBorderPen();
4425 Cell * cell = d->extra()->obscuringCells.first();
4426 return cell->effRightBorderPen( cell->column(), cell->row() );
4429 if ( d->hasExtra() && d->extra()->conditions
4430 && d->extra()->conditions->matchedStyle()
4431 && d->extra()->conditions->matchedStyle()->hasFeature( Style::SRightBorder,
true ) )
4432 return d->extra()->conditions->matchedStyle()->rightBorderPen();
4441 Cell * cell = d->extra()->obscuringCells.first();
4442 return cell->effBottomBorderPen( cell->column(), cell->row() );
4445 if ( d->hasExtra() && d->extra()->conditions
4446 && d->extra()->conditions->matchedStyle()
4447 && d->extra()->conditions->matchedStyle()->hasFeature( Style::SBottomBorder,
true ) )
4448 return d->extra()->conditions->matchedStyle()->bottomBorderPen();
4455 if ( d->hasExtra() && d->extra()->conditions
4456 && d->extra()->conditions->matchedStyle()
4457 && d->extra()->conditions->matchedStyle()->hasFeature( Style::SGoUpDiagonal,
true ) )
4458 return d->extra()->conditions->matchedStyle()->goUpDiagonalPen();
4460 return format()->goUpDiagonalPen( col,
row );
4465 if ( d->hasExtra() && d->extra()->conditions
4466 && d->extra()->conditions->matchedStyle()
4467 && d->extra()->conditions->matchedStyle()->hasFeature( Style::SFallDiagonal,
true ) )
4468 return d->extra()->conditions->matchedStyle()->fallDiagonalPen();
4470 return format()->fallDiagonalPen( col,
row );
4477 Cell * cell = d->extra()->obscuringCells.first();
4478 return cell->effBottomBorderValue( cell->column(), cell->row() );
4481 if ( d->hasExtra() && d->extra()->conditions
4482 && d->extra()->conditions->matchedStyle() )
4483 return d->extra()->conditions->matchedStyle()->bottomPenValue();
4485 return format()->bottomBorderValue( col,
row );
4492 Cell * cell = d->extra()->obscuringCells.first();
4493 return cell->effRightBorderValue( cell->column(), cell->row() );
4496 if ( d->hasExtra() && d->extra()->conditions
4497 && d->extra()->conditions->matchedStyle() )
4498 return d->extra()->conditions->matchedStyle()->rightPenValue();
4500 return format()->rightBorderValue( col,
row );
4507 Cell * cell = d->extra()->obscuringCells.first();
4508 return cell->effLeftBorderValue( cell->column(), cell->row() );
4511 if ( d->hasExtra() && d->extra()->conditions
4512 && d->extra()->conditions->matchedStyle() )
4513 return d->extra()->conditions->matchedStyle()->leftPenValue();
4515 return format()->leftBorderValue( col,
row );
4522 Cell * cell = d->extra()->obscuringCells.first();
4523 return cell->effTopBorderValue( cell->column(), cell->row() );
4526 if ( d->hasExtra() && d->extra()->conditions
4527 && d->extra()->conditions->matchedStyle() )
4528 return d->extra()->conditions->matchedStyle()->topPenValue();
4530 return format()->topBorderValue( col,
row );
4543 if ( !
value().isNumber() )
4547 if ( tmpPreci == -1 )
4549 int pos = d->strOutText.find(decimal_point);
4551 pos = d->strOutText.find(
'.');
4553 format()->setPrecision(1);
4557 if ( d->strOutText.find(
'%') != -1 )
4559 else if ( d->strOutText.find(
locale()->currencySymbol()) == ((
int)(d->strOutText.length()-
locale()->currencySymbol().length())) )
4560 start =
locale()->currencySymbol().length() + 1;
4561 else if ( (start=d->strOutText.find(
'E')) != -1 )
4562 start = d->strOutText.length() - start;
4565 format()->setPrecision( TQMAX( 0, (
int)d->strOutText.length() - start - pos ) );
4568 else if ( tmpPreci < 10 )
4570 format()->setPrecision( ++tmpPreci );
4572 setFlag(Flag_LayoutDirty);
4579 if ( !
value().isNumber() )
4585 int pos = d->strOutText.find( decimal_point );
4587 if ( d->strOutText.find(
'%') != -1 )
4589 else if ( d->strOutText.find(
locale()->currencySymbol()) == ((
int)(d->strOutText.length()-
locale()->currencySymbol().length())) )
4590 start =
locale()->currencySymbol().length() + 1;
4591 else if ( (start = d->strOutText.find(
'E')) != -1 )
4592 start = d->strOutText.length() - start;
4599 format()->setPrecision(d->strOutText.length() - pos - 2 - start);
4603 else if ( preciTmp > 0 )
4605 format()->setPrecision( --preciTmp );
4607 setFlag( Flag_LayoutDirty );
4612void Cell::setNumber(
double number )
4616 d->strText.setNum( number );
4630 if (_text.length() == 0) {
4631 d->strOutText = d->strText =
"";
4638 d->strOutText = _text;
4645 TQString oldText = d->strText;
4656 bool isLoading =
format()->sheet()->isLoading();
4666 if ( !d->strText.isEmpty() && d->strText[0] ==
'=' )
4668 setFlag(Flag_LayoutDirty);
4669 setFlag(Flag_TextFormatDirty);
4672 kdError(36001) <<
"ERROR: Syntax ERROR" << endl;
4684 setFlag(Flag_LayoutDirty);
4685 setFlag(Flag_TextFormatDirty);
4694 d->extra()->link =
link;
4696 if( !
link.isEmpty() && d->strText.isEmpty() )
4702 return d->hasExtra() ? d->extra()->link : TQString();
4729 if( d->hasExtra() && d->extra()->validity && d->extra()->validity->m_restriction !=
Restriction::None )
4732 if ( d->extra()->validity->allowEmptyCell && d->strText.isEmpty() )
4735 if(
value().isNumber() &&
4738 value().asFloat() == ceil(
value().asFloat()))))
4740 switch( d->extra()->validity->m_cond)
4742 case Conditional::Equal:
4743 valid = (
value().
asFloat() - d->extra()->validity->valMin < DBL_EPSILON
4745 (0.0 - DBL_EPSILON));
4747 case Conditional::DifferentTo:
4748 valid = !( (
value().
asFloat() - d->extra()->validity->valMin < DBL_EPSILON
4750 (0.0 - DBL_EPSILON)) );
4752 case Conditional::Superior:
4753 valid = (
value().
asFloat() > d->extra()->validity->valMin);
4755 case Conditional::Inferior:
4756 valid = (
value().
asFloat() <d->extra()->validity->valMin);
4758 case Conditional::SuperiorEqual:
4759 valid = (
value().
asFloat() >= d->extra()->validity->valMin);
4761 case Conditional::InferiorEqual:
4762 valid = (
value().
asFloat() <= d->extra()->validity->valMin);
4764 case Conditional::Between:
4765 valid = (
value().
asFloat() >= d->extra()->validity->valMin &&
4768 case Conditional::Different:
4769 valid = (
value().
asFloat() < d->extra()->validity->valMin ||
4783 if (
value().isString() && d->extra()->validity->listValidity.contains(
value().asString() ) )
4788 if(
value().isString() )
4790 int len = d->strOutText.length();
4791 switch( d->extra()->validity->m_cond)
4793 case Conditional::Equal:
4794 if (len == d->extra()->validity->valMin)
4797 case Conditional::DifferentTo:
4798 if (len != d->extra()->validity->valMin)
4801 case Conditional::Superior:
4802 if(len > d->extra()->validity->valMin)
4805 case Conditional::Inferior:
4806 if(len < d->extra()->validity->valMin)
4809 case Conditional::SuperiorEqual:
4810 if(len >= d->extra()->validity->valMin)
4813 case Conditional::InferiorEqual:
4814 if(len <= d->extra()->validity->valMin)
4817 case Conditional::Between:
4818 if(len >= d->extra()->validity->valMin && len <= d->extra()->validity->valMax)
4821 case Conditional::Different:
4822 if(len <d->extra()->validity->valMin || len >d->extra()->validity->valMax)
4832 switch( d->extra()->validity->m_cond)
4834 case Conditional::Equal:
4835 valid = (
value().
asTime() == d->extra()->validity->timeMin);
4837 case Conditional::DifferentTo:
4838 valid = (
value().
asTime() != d->extra()->validity->timeMin);
4840 case Conditional::Superior:
4841 valid = (
value().
asTime() > d->extra()->validity->timeMin);
4843 case Conditional::Inferior:
4844 valid = (
value().
asTime() < d->extra()->validity->timeMin);
4846 case Conditional::SuperiorEqual:
4847 valid = (
value().
asTime() >= d->extra()->validity->timeMin);
4849 case Conditional::InferiorEqual:
4850 valid = (
value().
asTime() <= d->extra()->validity->timeMin);
4852 case Conditional::Between:
4853 valid = (
value().
asTime() >= d->extra()->validity->timeMin &&
4854 value().
asTime() <= d->extra()->validity->timeMax);
4856 case Conditional::Different:
4857 valid = (
value().
asTime() < d->extra()->validity->timeMin ||
4858 value().
asTime() > d->extra()->validity->timeMax);
4867 switch( d->extra()->validity->m_cond)
4869 case Conditional::Equal:
4870 valid = (
value().
asDate() == d->extra()->validity->dateMin);
4872 case Conditional::DifferentTo:
4873 valid = (
value().
asDate() != d->extra()->validity->dateMin);
4875 case Conditional::Superior:
4876 valid = (
value().
asDate() > d->extra()->validity->dateMin);
4878 case Conditional::Inferior:
4879 valid = (
value().
asDate() < d->extra()->validity->dateMin);
4881 case Conditional::SuperiorEqual:
4882 valid = (
value().
asDate() >= d->extra()->validity->dateMin);
4884 case Conditional::InferiorEqual:
4885 valid = (
value().
asDate() <= d->extra()->validity->dateMin);
4887 case Conditional::Between:
4888 valid = (
value().
asDate() >= d->extra()->validity->dateMin &&
4889 value().
asDate() <= d->extra()->validity->dateMax);
4891 case Conditional::Different:
4892 valid = (
value().
asDate() < d->extra()->validity->dateMin ||
4893 value().
asDate() > d->extra()->validity->dateMax);
4906 if(!valid &&d->extra()->validity != NULL && d->extra()->validity->displayMessage)
4908 switch (d->extra()->validity->m_action )
4911 KMessageBox::error((TQWidget*)0L, d->extra()->validity->message,
4912 d->extra()->validity->title);
4914 case Action::Warning:
4915 KMessageBox::warningYesNo((TQWidget*)0L, d->extra()->validity->message,
4916 d->extra()->validity->title);
4918 case Action::Information:
4919 KMessageBox::information((TQWidget*)0L, d->extra()->validity->message,
4920 d->extra()->validity->title);
4926 return (valid || d->extra()->validity == NULL || d->extra()->validity->m_action != Action::Stop);
4931 return format()->getFormatType( d->column, d->row );
4936 return d->textWidth;
4941 return d->textHeight;
4946 return d->hasExtra() ? d->extra()->mergedXCells : 0;
4951 return d->hasExtra() ? d->extra()->mergedYCells : 0;
4956 return d->hasExtra() ? d->extra()->extraXCells : 0;
4961 return d->hasExtra() ? d->extra()->extraYCells : 0;
4964double Cell::extraWidth()
const
4966 return d->hasExtra() ? d->extra()->extraWidth : 0;
4969double Cell::extraHeight()
const
4971 return d->hasExtra() ? d->extra()->extraHeight : 0;
4979 return (formatIsDate (ft) || ((ft == Generic_format) &&
4987 return (formatIsTime (ft) || ((ft == Generic_format) &&
4996 clearFlag(Flag_CalcDirty);
4999 setFlag(Flag_CalcDirty);
5007 if ( d->row != 0 && d->column != 0 )
5010 for ( bind =
format()->
sheet()->firstCellBinding(); bind != 0L; bind =
format()->sheet()->nextCellBinding() )
5012 if ( bind->contains( d->column, d->row ) )
5034 TQDate dummy (1900, 1, 1);
5035 return (dummy.daysTo (date) + 1);
5041 return dummy.secsTo( time );
5043 if (
value().isNumber())
5063 d->value.setFormat (Value::fmt_Percent);
5072 d->value.setFormat (Value::fmt_Money);
5087 int msec = (int) ( (
value().asFloat() - (
int)
value().asFloat()) * 1000 );
5088 time = time.addMSecs( msec );
5104 TQDate date(1900, 1, 1);
5105 date = date.addDays( (
int)
value().asFloat() - 1 );
5118 TQString str = d->strText;
5125 d->strText =
locale()->formatTime(
value().asDateTime().time(),
true);
5129 (!d->strText.isEmpty()))
5132 setValue(
Value( str[0].upper() + str.right( str.length()-1 ) ) );
5141 if (
value().asFloat() > 1e+10 )
5142 format()->setFormatType( Scientific_format );
5152 int _x_offset,
int _y_offset,
5153 bool force,
bool copy,
bool era )
5156 TQDomElement cell = doc.createElement(
"cell" );
5157 cell.setAttribute(
"row", d->row - _y_offset );
5158 cell.setAttribute(
"column", d->column - _x_offset );
5162 TQDomElement formatElement =
format()->save( doc, d->column, d->row, force, copy );
5163 if ( formatElement.hasChildNodes() || formatElement.attributes().length() )
5164 cell.appendChild( formatElement );
5169 formatElement.setAttribute(
"colspan",
extraXCells() );
5171 formatElement.setAttribute(
"rowspan",
extraYCells() );
5174 if ( d->hasExtra() && d->extra()->conditions )
5176 TQDomElement conditionElement = d->extra()->conditions->saveConditions( doc );
5178 if ( !conditionElement.isNull() )
5179 cell.appendChild( conditionElement );
5182 if ( d->hasExtra() && (d->extra()->validity != 0) )
5184 TQDomElement validity = doc.createElement(
"validity");
5186 TQDomElement param=doc.createElement(
"param");
5187 param.setAttribute(
"cond",(
int)d->extra()->validity->m_cond);
5188 param.setAttribute(
"action",(
int)d->extra()->validity->m_action);
5189 param.setAttribute(
"allow",(
int)d->extra()->validity->m_restriction);
5190 param.setAttribute(
"valmin",d->extra()->validity->valMin);
5191 param.setAttribute(
"valmax",d->extra()->validity->valMax);
5192 param.setAttribute(
"displaymessage",d->extra()->validity->displayMessage);
5193 param.setAttribute(
"displayvalidationinformation",d->extra()->validity->displayValidationInformation);
5194 param.setAttribute(
"allowemptycell",d->extra()->validity->allowEmptyCell);
5195 if ( !d->extra()->validity->listValidity.isEmpty() )
5196 param.setAttribute(
"listvalidity", d->extra()->validity->listValidity.join(
";" ) );
5197 validity.appendChild(param);
5198 TQDomElement title = doc.createElement(
"title" );
5199 title.appendChild( doc.createTextNode( d->extra()->validity->title ) );
5200 validity.appendChild( title );
5201 TQDomElement message = doc.createElement(
"message" );
5202 message.appendChild( doc.createCDATASection( d->extra()->validity->message ) );
5203 validity.appendChild( message );
5205 TQDomElement inputTitle = doc.createElement(
"inputtitle" );
5206 inputTitle.appendChild( doc.createTextNode( d->extra()->validity->titleInfo ) );
5207 validity.appendChild( inputTitle );
5209 TQDomElement inputMessage = doc.createElement(
"inputmessage" );
5210 inputMessage.appendChild( doc.createTextNode( d->extra()->validity->messageInfo ) );
5211 validity.appendChild( inputMessage );
5216 if ( d->extra()->validity->timeMin.isValid() )
5218 TQDomElement timeMin = doc.createElement(
"timemin" );
5219 tmp=d->extra()->validity->timeMin.toString();
5220 timeMin.appendChild( doc.createTextNode( tmp ) );
5221 validity.appendChild( timeMin );
5223 if ( d->extra()->validity->timeMax.isValid() )
5225 TQDomElement timeMax = doc.createElement(
"timemax" );
5226 tmp=d->extra()->validity->timeMax.toString();
5227 timeMax.appendChild( doc.createTextNode( tmp ) );
5228 validity.appendChild( timeMax );
5231 if ( d->extra()->validity->dateMin.isValid() )
5233 TQDomElement dateMin = doc.createElement(
"datemin" );
5234 TQString tmp(
"%1/%2/%3");
5235 tmp = tmp.arg(d->extra()->validity->dateMin.year()).arg(d->extra()->validity->dateMin.month()).arg(d->extra()->validity->dateMin.day());
5236 dateMin.appendChild( doc.createTextNode( tmp ) );
5237 validity.appendChild( dateMin );
5239 if ( d->extra()->validity->dateMax.isValid() )
5241 TQDomElement dateMax = doc.createElement(
"datemax" );
5242 TQString tmp(
"%1/%2/%3");
5243 tmp = tmp.arg(d->extra()->validity->dateMax.year()).arg(d->extra()->validity->dateMax.month()).arg(d->extra()->validity->dateMax.day());
5244 dateMax.appendChild( doc.createTextNode( tmp ) );
5245 validity.appendChild( dateMax );
5248 cell.appendChild( validity );
5251 if (
format()->comment() )
5253 TQDomElement comment = doc.createElement(
"comment" );
5254 comment.appendChild( doc.createCDATASection( *
format()->comment() ) );
5255 cell.appendChild( comment );
5261 if ( !d->strText.isEmpty() )
5267 TQDomElement
text = doc.createElement(
"text" );
5270 cell.appendChild(
text );
5273 TQDomElement formulaResult = doc.createElement(
"result" );
5274 saveCellResult( doc, formulaResult, d->strOutText );
5275 cell.appendChild( formulaResult );
5282 TQDomElement
text = doc.createElement(
"text" );
5283 TQString qml =
"!<a href=\"" +
link() +
"\">" + d->strText +
"</a>";
5284 text.appendChild( doc.createCDATASection( qml ) );
5285 cell.appendChild(
text );
5290 TQDomElement
text = doc.createElement(
"text" );
5291 saveCellResult( doc,
text, d->strText );
5292 cell.appendChild(
text );
5295 if ( cell.hasChildNodes() || cell.attributes().length() > 2 )
5299 return TQDomElement();
5302bool Cell::saveCellResult( TQDomDocument& doc, TQDomElement& result,
5305 TQString dataType =
"Other";
5307 if (
value().isNumber() )
5315 str = str.arg(dd.year()).arg(dd.month()).arg(dd.day());
5327 if (
value().isInteger())
5328 str = TQString::number(
value().asInteger());
5330 str = TQString::number(
value().asFloat(),
'g', DBL_DIG);
5334 if (
value().isBoolean() )
5340 if (
value().isString() )
5346 result.setAttribute(
"dataType", dataType );
5347 if ( !d->strOutText.isEmpty() )
5348 result.setAttribute(
"outStr", d->strOutText );
5349 result.appendChild( doc.createTextNode( str ) );
5354void Cell::saveOasisAnnotation( KoXmlWriter &xmlwriter )
5356 if (
format()->comment() )
5359 xmlwriter.startElement(
"office:annotation" );
5360 TQStringList
text = TQStringList::split(
"\n", *
format()->comment() );
5361 for ( TQStringList::Iterator it =
text.begin(); it !=
text.end(); ++it ) {
5362 xmlwriter.startElement(
"text:p" );
5363 xmlwriter.addTextNode( *it );
5364 xmlwriter.endElement();
5366 xmlwriter.endElement();
5374 if ( d->hasExtra() && d->extra()->conditions )
5377 currentCellStyle = KoGenStyle( Doc::STYLE_CELL_AUTO,
"table-cell" );
5378 d->extra()->conditions->saveOasisConditions( currentCellStyle );
5380 return format()->saveOasisCellStyle( currentCellStyle, mainStyles );
5384bool Cell::saveOasis( KoXmlWriter& xmlwriter, KoGenStyles &mainStyles,
5386 GenValidationStyles &valStyle )
5389 xmlwriter.startElement(
"table:table-cell" );
5391 xmlwriter.startElement(
"table:covered-table-cell" );
5396 if ( !cell->isDefault() )
5398 font = cell->format()->textFont( i,
row );
5399 m_styles.addFont( font );
5401 if ( cell->format()->hasProperty( Format::PComment ) )
5407 saveOasisValue (xmlwriter);
5409 KoGenStyle currentCellStyle;
5412 if ( !currentCellStyle.isDefaultStyle() )
5413 xmlwriter.addAttribute(
"table:style-name", mainStyles.styles()[currentCellStyle] );
5416 if (
isEmpty() && !
format()->hasProperty( Format::PComment ) &&
5430 if ( refCellIsDefault )
5434 repeated = nextCell->
column() - j + 1;
5442 KoGenStyle nextCellStyle;
5443 nextCell->saveOasisCellStyle( nextCellStyle,mainStyles );
5445 if ( nextCell->isPartOfMerged() || nextCell->doesMergeCells() ||
5446 nextCell->format()->hasProperty( Format::PComment ) ||
5447 !(nextCellStyle == currentCellStyle) )
5453 nextCell =
format()->sheet()->getNextCellRight( j++,
row );
5455 kdDebug() <<
"Cell::saveOasis: empty cell in column " <<
column <<
" "
5456 <<
"repeated " << repeated <<
" time(s)" << endl;
5459 xmlwriter.addAttribute(
"table:number-columns-repeated", TQString::number( repeated ) );
5463 if (d->hasExtra() && d->extra()->validity)
5465 GenValidationStyle styleVal(d->extra()->validity);
5466 xmlwriter.addAttribute(
"table:validation-name", valStyle.lookup( styleVal ) );
5471 TQString formula( convertFormulaToOasisFormat(
text() ) );
5472 xmlwriter.addAttribute(
"table:formula", formula );
5477 xmlwriter.startElement(
"text:p" );
5478 xmlwriter.startElement(
"text:a" );
5480 if ( localReferenceAnchor(
link() ) )
5481 xmlwriter.addAttribute(
" xlink:href", (
"#"+
link() ) );
5483 xmlwriter.addAttribute(
" xlink:href",
link() );
5484 xmlwriter.addTextNode(
text() );
5485 xmlwriter.endElement();
5486 xmlwriter.endElement();
5495 xmlwriter.addAttribute(
"table:number-columns-spanned", TQString::number( colSpan ) );
5498 xmlwriter.addAttribute(
"table:number-rows-spanned", TQString::number( rowSpan ) );
5503 xmlwriter.startElement(
"text:p" );
5504 xmlwriter.addTextNode( strOutText().utf8() );
5505 xmlwriter.endElement();
5508 saveOasisAnnotation( xmlwriter );
5510 xmlwriter.endElement();
5514void Cell::saveOasisValue (KoXmlWriter &xmlWriter)
5518 case Value::fmt_None:
break;
5519 case Value::fmt_Boolean:
5521 xmlWriter.addAttribute(
"office:value-type",
"boolean" );
5522 xmlWriter.addAttribute(
"office:boolean-value", (
value().asBoolean() ?
5523 "true" :
"false" ) );
5526 case Value::fmt_Number:
5528 xmlWriter.addAttribute(
"office:value-type",
"float" );
5529 if (
value().isInteger())
5530 xmlWriter.addAttribute(
"office:value", TQString::number(
value().asInteger() ) );
5532 xmlWriter.addAttribute(
"office:value", TQString::number(
value().asFloat(),
'g', DBL_DIG ) );
5535 case Value::fmt_Percent:
5537 xmlWriter.addAttribute(
"office:value-type",
"percentage" );
5538 xmlWriter.addAttribute(
"office:value",
5539 TQString::number(
value().asFloat() ) );
5542 case Value::fmt_Money:
5544 xmlWriter.addAttribute(
"office:value-type",
"currency" );
5545 Format::Currency currency;
5546 if (
format()->currencyInfo(currency))
5547 xmlWriter.addAttribute(
"office:currency", Currency::getCurrencyCode(currency.type) );
5548 xmlWriter.addAttribute(
"office:value",
5549 TQString::number(
value().asFloat() ) );
5552 case Value::fmt_DateTime:
break;
5553 case Value::fmt_Date:
5555 xmlWriter.addAttribute(
"office:value-type",
"date" );
5556 xmlWriter.addAttribute(
"office:date-value",
5557 value().asDate().toString( TQt::ISODate ) );
5560 case Value::fmt_Time:
5562 xmlWriter.addAttribute(
"office:value-type",
"time" );
5563 xmlWriter.addAttribute(
"office:time-value",
5564 value().asTime().toString(
"PThhHmmMssS" ) );
5567 case Value::fmt_String:
5569 xmlWriter.addAttribute(
"office:value-type",
"string" );
5570 xmlWriter.addAttribute(
"office:string-value",
value().asString() );
5576TQString Cell::convertFormulaToOasisFormat(
const TQString & formula )
const
5579 TQRegExp exp(
"(\\$?)([a-zA-Z]+)(\\$?)([0-9]+)");
5580 int n = exp.search( formula, 0 );
5581 kdDebug() <<
"Exp: " << formula <<
", n: " << n <<
", Length: " << formula.length()
5582 <<
", Matched length: " << exp.matchedLength() << endl;
5584 bool inQuote1 =
false;
5585 bool inQuote2 =
false;
5587 int l = (int) formula.length();
5592 if ( ( n != -1 ) && ( n < i ) )
5594 n = exp.search( formula, i );
5595 kdDebug() <<
"Exp: " << formula.right( l - i ) <<
", n: " << n << endl;
5597 if ( formula[i] ==
'"' )
5599 inQuote1 = !inQuote1;
5604 if ( formula[i] ==
'\'' )
5607 inQuote2 = !inQuote2;
5611 if ( inQuote1 || inQuote2 )
5617 if ( ( formula[i] ==
'=' ) && ( formula[i + 1] ==
'=' ) )
5623 if ( formula[i] ==
'!' )
5630 if ( formula[i] ==
',' )
5638 int ml = exp.matchedLength();
5639 if ( formula[ i + ml ] ==
'!' )
5641 kdDebug() <<
"No cell ref but sheet name" << endl;
5646 if ( ( i > 0 ) && ( formula[i - 1] !=
'!' ) )
5648 for (
int j = 0; j < ml; ++j )
5664void Cell::loadOasisConditional( TQDomElement * style )
5669 forEachElement( e, style->toElement() )
5671 if ( e.localName() ==
"map" && e.namespaceURI() == KoXmlNS::style )
5674 delete d->extra()->conditions;
5675 d->extra()->conditions =
new Conditions(
this );
5676 d->extra()->conditions->loadOasisConditions( e );
5677 d->extra()->conditions->checkMatches();
5688 kdDebug() <<
"*** Loading cell properties ***** at " <<
column() <<
"," <<
row () << endl;
5690 if ( element.hasAttributeNS( KoXmlNS::table,
"style-name" ) )
5692 kdDebug()<<
" table:style-name: "<<element.attributeNS( KoXmlNS::table,
"style-name", TQString() )<<endl;
5693 oasisContext.fillStyleStack( element, KoXmlNS::table,
"styleName",
"table-cell" );
5695 TQString str = element.attributeNS( KoXmlNS::table,
"style-name", TQString() );
5696 const TQDomElement* cellStyle = oasisContext.oasisStyles().findStyle( str,
"table-cell" );
5699 loadOasisConditional(
const_cast<TQDomElement *
>( cellStyle ) );
5704 format()->setStyle( style );
5714 if ( element.hasAttributeNS( KoXmlNS::table,
"formula" ) )
5716 kdDebug()<<
" formula :"<<element.attributeNS( KoXmlNS::table,
"formula", TQString() )<<endl;
5718 TQString oasisFormula( element.attributeNS( KoXmlNS::table,
"formula", TQString() ) );
5720 if (oasisFormula.startsWith(
"oooc:" ) )
5721 oasisFormula= oasisFormula.mid( 5 );
5722 else if (oasisFormula.startsWith(
"kspr:" ) )
5723 oasisFormula= oasisFormula.mid( 5 );
5725 checkForNamedAreas( oasisFormula );
5726 oasisFormula = Oasis::decodeFormula( oasisFormula,
locale() );
5729 else if ( d->strText.at(0) ==
'=' )
5730 d->strText.prepend(
'\'');
5735 if ( element.hasAttributeNS( KoXmlNS::table,
"validation-name" ) )
5737 kdDebug()<<
" validation-name: "<<element.attributeNS( KoXmlNS::table,
"validation-name", TQString() )<<endl;
5738 loadOasisValidation( element.attributeNS( KoXmlNS::table,
"validation-name", TQString() ) );
5744 if( element.hasAttributeNS( KoXmlNS::office,
"value-type" ) )
5746 TQString valuetype = element.attributeNS( KoXmlNS::office,
"value-type", TQString() );
5747 kdDebug()<<
" value-type: " << valuetype << endl;
5748 if( valuetype ==
"boolean" )
5750 TQString val = element.attributeNS( KoXmlNS::office,
"boolean-value", TQString() ).lower();
5751 if( ( val ==
"true" ) || ( val ==
"false" ) )
5753 bool value = val ==
"true";
5759 else if( valuetype ==
"float" )
5762 double value = element.attributeNS( KoXmlNS::office,
"value", TQString() ).toDouble( &ok );
5766 if ( !
isFormula && d->strText.isEmpty())
5768 TQString str =
locale()->formatNumber(
value, 15 );
5774 else if( valuetype ==
"currency" )
5777 double value = element.attributeNS( KoXmlNS::office,
"value", TQString() ).toDouble( &ok );
5782 if (element.hasAttributeNS( KoXmlNS::office,
"currency" ) )
5784 Currency currency(element.attributeNS( KoXmlNS::office,
"currency", TQString() ) );
5785 format()->setCurrency( currency.getIndex(), currency.getDisplayCode() );
5789 else if( valuetype ==
"percentage" )
5792 double v = element.attributeNS( KoXmlNS::office,
"value", TQString() ).toDouble( &ok );
5797 value.setFormat (Value::fmt_Percent);
5800 if ( !
isFormula && d->strText.isEmpty())
5802 TQString str =
locale()->formatNumber( v, 15 );
5806 format()->setFormatType (Percentage_format);
5809 else if ( valuetype ==
"date" )
5811 TQString
value = element.attributeNS( KoXmlNS::office,
"value", TQString() );
5812 if (
value.isEmpty() )
5813 value = element.attributeNS( KoXmlNS::office,
"date-value", TQString() );
5814 kdDebug() <<
"Type: date, value: " <<
value << endl;
5817 int year = 0, month = 0, day = 0;
5820 int p1 =
value.find(
'-' );
5822 year =
value.left( p1 ).toInt( &ok );
5824 kdDebug() <<
"year: " <<
value.left( p1 ) << endl;
5826 int p2 =
value.find(
'-', ++p1 );
5829 month =
value.mid( p1, p2 - p1 ).toInt( &ok );
5831 kdDebug() <<
"month: " <<
value.mid( p1, p2 - p1 ) << endl;
5834 day =
value.right(
value.length() - p2 - 1 ).toInt( &ok );
5836 kdDebug() <<
"day: " <<
value.right(
value.length() - p2 ) << endl;
5842 format()->setFormatType (style->formatType());
5843 kdDebug() <<
"Set TQDate: " << year <<
" - " << month <<
" - " << day << endl;
5847 else if ( valuetype ==
"time" )
5849 TQString
value = element.attributeNS( KoXmlNS::office,
"value", TQString() );
5850 if (
value.isEmpty() )
5851 value = element.attributeNS( KoXmlNS::office,
"time-value", TQString() );
5852 kdDebug() <<
"Type: time: " <<
value << endl;
5854 int hours = 0, minutes = 0, seconds = 0;
5855 int l =
value.length();
5858 for (
int i = 0; i < l; ++i )
5860 if (
value[i].isNumber() )
5865 else if (
value[i] ==
'H' )
5866 hours = num.toInt( &ok );
5867 else if (
value[i] ==
'M' )
5868 minutes = num.toInt( &ok );
5869 else if (
value[i] ==
'S' )
5870 seconds = num.toInt( &ok );
5874 kdDebug() <<
"Num: " << num << endl;
5880 kdDebug() <<
"Hours: " << hours <<
", " << minutes <<
", " << seconds << endl;
5886 setCellValue( TQTime( hours % 24, minutes, seconds ) );
5888 format()->setFormatType (style->formatType());
5891 else if( valuetype ==
"string" )
5893 TQString
value = element.attributeNS( KoXmlNS::office,
"value", TQString() );
5894 if (
value.isEmpty() && element.hasAttributeNS( KoXmlNS::office,
"string-value" ))
5897 value = element.attributeNS( KoXmlNS::office,
"string-value", TQString() );
5900 format()->setFormatType (Text_format);
5903 kdDebug()<<
" type of value found : "<<valuetype<<endl;
5911 if ( element.hasAttributeNS( KoXmlNS::table,
"number-columns-spanned" ) )
5914 int span = element.attributeNS( KoXmlNS::table,
"number-columns-spanned", TQString() ).toInt( &ok );
5915 if( ok ) colSpan = span;
5917 if ( element.hasAttributeNS( KoXmlNS::table,
"number-rows-spanned" ) )
5920 int span = element.attributeNS( KoXmlNS::table,
"number-rows-spanned", TQString() ).toInt( &ok );
5921 if( ok ) rowSpan = span;
5923 if ( colSpan > 1 || rowSpan > 1 )
5924 mergeCells( d->column, d->row, colSpan - 1, rowSpan - 1 );
5929 TQDomElement annotationElement = KoDom::namedItemNS( element, KoXmlNS::office,
"annotation" );
5930 if ( !annotationElement.isNull() )
5933 TQDomNode node = annotationElement.firstChild();
5934 while( !node.isNull() )
5936 TQDomElement commentElement = node.toElement();
5937 if( !commentElement.isNull() )
5938 if( commentElement.localName() ==
"p" && commentElement.namespaceURI() == KoXmlNS::text )
5940 if( !comment.isEmpty() ) comment.append(
'\n' );
5941 comment.append( commentElement.text() );
5944 node = node.nextSibling();
5947 if( !comment.isEmpty() )
5948 format()->setComment( comment );
5951 TQDomElement frame = KoDom::namedItemNS( element, KoXmlNS::draw,
"frame" );
5952 if ( !frame.isNull() )
5953 loadOasisObjects( frame, oasisContext );
5964 TQDomElement textParagraphElement;
5967 bool multipleTextParagraphsFound=
false;
5969 forEachElement( textParagraphElement , parent )
5971 if ( textParagraphElement.localName()==
"p" &&
5972 textParagraphElement.namespaceURI()== KoXmlNS::text )
5975 if (cellText.isEmpty())
5976 cellText = textParagraphElement.text();
5979 cellText +=
"\n"+textParagraphElement.text();
5980 multipleTextParagraphsFound=
true;
5983 TQDomElement textA = KoDom::namedItemNS( textParagraphElement, KoXmlNS::text,
"a" );
5984 if( !textA.isNull() )
5986 if ( textA.hasAttributeNS( KoXmlNS::xlink,
"href" ) )
5988 TQString
link = textA.attributeNS( KoXmlNS::xlink,
"href", TQString() );
5989 cellText = textA.text();
6000 if (!cellText.isNull())
6007 if ( multipleTextParagraphsFound )
6009 format()->setMultiRow(
true);
6013void Cell::loadOasisObjects(
const TQDomElement &parent, KoOasisLoadingContext& oasisContext )
6015 for( TQDomElement e = parent; !e.isNull(); e = e.nextSibling().toElement() )
6017 if ( e.localName() ==
"frame" && e.namespaceURI() == KoXmlNS::draw )
6020 TQDomNode
object = KoDom::namedItemNS( e, KoXmlNS::draw,
"object" );
6021 if ( !
object.isNull() )
6023 if ( !
object.toElement().attributeNS( KoXmlNS::draw,
"notify-on-update-of-ranges", TQString()).isNull() )
6030 TQDomNode image = KoDom::namedItemNS( e, KoXmlNS::draw,
"image" );
6031 if ( !image.isNull() )
6034 kdDebug() <<
"Object type wasn't loaded!" << endl;
6039 obj->loadOasis( e, oasisContext );
6042 TQString ref = e.attributeNS( KoXmlNS::table,
"end-cell-address", TQString() );
6046 ref = Oasis::decodeFormula( ref );
6048 if ( !point.isValid() )
6051 KoRect geometry = obj->geometry();
6052 geometry.setLeft( geometry.left() +
sheet()->columnPos( d->column, 0 ) );
6053 geometry.setTop( geometry.top() +
sheet()->rowPos( d->row, 0 ) );
6055 TQString str = e.attributeNS( KoXmlNS::table,
"end-x", TQString() );
6056 if ( !str.isNull() )
6058 uint end_x = (uint) KoUnit::parseValue( str );
6059 geometry.setRight(
sheet()->columnPos( point.column(), 0) + end_x );
6062 str = e.attributeNS( KoXmlNS::table,
"end-y", TQString() );
6063 if ( !str.isNull() )
6065 uint end_y = (uint) KoUnit::parseValue( str );
6066 geometry.setBottom(
sheet()->rowPos( point.row(), 0) + end_y );
6069 obj->setGeometry( geometry );
6075void Cell::loadOasisValidation(
const TQString& validationName )
6077 TQDomElement element =
sheet()->doc()->
loadingInfo()->validation( validationName);
6079 delete d->extra()->validity;
6080 d->extra()->validity =
new Validity;
6081 if ( element.hasAttributeNS( KoXmlNS::table,
"condition" ) )
6083 TQString valExpression = element.attributeNS( KoXmlNS::table,
"condition", TQString() );
6084 kdDebug()<<
" element.attribute( table:condition ) "<<valExpression<<endl;
6098 if ( valExpression.contains(
"cell-content-text-length()" ) )
6101 valExpression = valExpression.remove(
"oooc:cell-content-text-length()" );
6102 kdDebug()<<
" valExpression = :"<<valExpression<<endl;
6105 loadOasisValidationCondition( valExpression );
6107 else if ( valExpression.contains(
"cell-content-is-text()" ) )
6112 else if ( valExpression.contains(
"cell-content-text-length-is-between" ) )
6115 d->extra()->validity->m_cond = Conditional::Between;
6116 valExpression = valExpression.remove(
"oooc:cell-content-text-length-is-between(" );
6117 kdDebug()<<
" valExpression :"<<valExpression<<endl;
6118 valExpression = valExpression.remove(
")" );
6119 TQStringList listVal = TQStringList::split(
",", valExpression );
6120 loadOasisValidationValue( listVal );
6122 else if ( valExpression.contains(
"cell-content-text-length-is-not-between" ) )
6125 d->extra()->validity->m_cond = Conditional::Different;
6126 valExpression = valExpression.remove(
"oooc:cell-content-text-length-is-not-between(" );
6127 kdDebug()<<
" valExpression :"<<valExpression<<endl;
6128 valExpression = valExpression.remove(
")" );
6129 kdDebug()<<
" valExpression :"<<valExpression<<endl;
6130 TQStringList listVal = TQStringList::split(
",", valExpression );
6131 loadOasisValidationValue( listVal );
6133 else if ( valExpression.contains(
"cell-content-is-in-list(" ) )
6136 valExpression = valExpression.remove(
"oooc:cell-content-is-in-list(" );
6137 kdDebug()<<
" valExpression :"<<valExpression<<endl;
6138 valExpression = valExpression.remove(
")" );
6139 d->extra()->validity->listValidity = TQStringList::split(
";", valExpression );
6145 if (valExpression.contains(
"cell-content-is-whole-number()" ) )
6148 valExpression = valExpression.remove(
"oooc:cell-content-is-whole-number() and " );
6150 else if (valExpression.contains(
"cell-content-is-decimal-number()" ) )
6153 valExpression = valExpression.remove(
"oooc:cell-content-is-decimal-number() and " );
6155 else if (valExpression.contains(
"cell-content-is-date()" ) )
6158 valExpression = valExpression.remove(
"oooc:cell-content-is-date() and " );
6160 else if (valExpression.contains(
"cell-content-is-time()" ) )
6163 valExpression = valExpression.remove(
"oooc:cell-content-is-time() and " );
6165 kdDebug()<<
"valExpression :"<<valExpression<<endl;
6167 if ( valExpression.contains(
"cell-content()" ) )
6169 valExpression = valExpression.remove(
"cell-content()" );
6170 loadOasisValidationCondition( valExpression );
6174 if ( valExpression.contains(
"cell-content-is-between(" ) )
6176 valExpression = valExpression.remove(
"cell-content-is-between(" );
6177 valExpression = valExpression.remove(
")" );
6178 TQStringList listVal = TQStringList::split(
"," , valExpression );
6179 loadOasisValidationValue( listVal );
6180 d->extra()->validity->m_cond = Conditional::Between;
6182 if ( valExpression.contains(
"cell-content-is-not-between(" ) )
6184 valExpression = valExpression.remove(
"cell-content-is-not-between(" );
6185 valExpression = valExpression.remove(
")" );
6186 TQStringList listVal = TQStringList::split(
",", valExpression );
6187 loadOasisValidationValue( listVal );
6188 d->extra()->validity->m_cond = Conditional::Different;
6192 if ( element.hasAttributeNS( KoXmlNS::table,
"allow-empty-cell" ) )
6194 kdDebug()<<
" element.hasAttribute( table:allow-empty-cell ) :"<<element.hasAttributeNS( KoXmlNS::table,
"allow-empty-cell" )<<endl;
6195 d->extra()->validity->allowEmptyCell = ( ( element.attributeNS( KoXmlNS::table,
"allow-empty-cell", TQString() )==
"true" ) ?
true :
false );
6197 if ( element.hasAttributeNS( KoXmlNS::table,
"base-cell-address" ) )
6202 TQDomElement help = KoDom::namedItemNS( element, KoXmlNS::table,
"help-message" );
6203 if ( !help.isNull() )
6205 if ( help.hasAttributeNS( KoXmlNS::table,
"title" ) )
6207 kdDebug()<<
"help.attribute( table:title ) :"<<help.attributeNS( KoXmlNS::table,
"title", TQString() )<<endl;
6208 d->extra()->validity->titleInfo = help.attributeNS( KoXmlNS::table,
"title", TQString() );
6210 if ( help.hasAttributeNS( KoXmlNS::table,
"display" ) )
6212 kdDebug()<<
"help.attribute( table:display ) :"<<help.attributeNS( KoXmlNS::table,
"display", TQString() )<<endl;
6213 d->extra()->validity->displayValidationInformation = ( ( help.attributeNS( KoXmlNS::table,
"display", TQString() )==
"true" ) ?
true :
false );
6215 TQDomElement attrText = KoDom::namedItemNS( help, KoXmlNS::text,
"p" );
6216 if ( !attrText.isNull() )
6218 kdDebug()<<
"help text :"<<attrText.text()<<endl;
6219 d->extra()->validity->messageInfo = attrText.text();
6223 TQDomElement error = KoDom::namedItemNS( element, KoXmlNS::table,
"error-message" );
6224 if ( !error.isNull() )
6226 if ( error.hasAttributeNS( KoXmlNS::table,
"title" ) )
6227 d->extra()->validity->title = error.attributeNS( KoXmlNS::table,
"title", TQString() );
6228 if ( error.hasAttributeNS( KoXmlNS::table,
"message-type" ) )
6230 TQString str = error.attributeNS( KoXmlNS::table,
"message-type", TQString() );
6231 if ( str ==
"warning" )
6232 d->extra()->validity->m_action = Action::Warning;
6233 else if ( str ==
"information" )
6234 d->extra()->validity->m_action = Action::Information;
6235 else if ( str ==
"stop" )
6236 d->extra()->validity->m_action = Action::Stop;
6238 kdDebug()<<
"validation : message type unknown :"<<str<<endl;
6241 if ( error.hasAttributeNS( KoXmlNS::table,
"display" ) )
6243 kdDebug()<<
" display message :"<<error.attributeNS( KoXmlNS::table,
"display", TQString() )<<endl;
6244 d->extra()->validity->displayMessage = (error.attributeNS( KoXmlNS::table,
"display", TQString() )==
"true");
6246 TQDomElement attrText = KoDom::namedItemNS( error, KoXmlNS::text,
"p" );
6247 if ( !attrText.isNull() )
6248 d->extra()->validity->message = attrText.text();
6253void Cell::loadOasisValidationValue(
const TQStringList &listVal )
6256 kdDebug()<<
" listVal[0] :"<<listVal[0]<<
" listVal[1] :"<<listVal[1]<<endl;
6260 d->extra()->validity->dateMin = TQDate::fromString( listVal[0] );
6261 d->extra()->validity->dateMax = TQDate::fromString( listVal[1] );
6265 d->extra()->validity->timeMin = TQTime::fromString( listVal[0] );
6266 d->extra()->validity->timeMax = TQTime::fromString( listVal[1] );
6270 d->extra()->validity->valMin = listVal[0].toDouble(&ok);
6273 d->extra()->validity->valMin = listVal[0].toInt(&ok);
6275 kdDebug()<<
" Try to parse this value :"<<listVal[0]<<endl;
6279 d->extra()->validity->valMin = listVal[0];
6283 d->extra()->validity->valMax = listVal[1].toDouble(&ok);
6286 d->extra()->validity->valMax = listVal[1].toInt(&ok);
6288 kdDebug()<<
" Try to parse this value :"<<listVal[1]<<endl;
6292 d->extra()->validity->valMax = listVal[1];
6298void Cell::loadOasisValidationCondition( TQString &valExpression )
6301 if (valExpression.find(
"<=" )==0 )
6303 value = valExpression.remove( 0,2 );
6304 d->extra()->validity->m_cond = Conditional::InferiorEqual;
6306 else if (valExpression.find(
">=" )==0 )
6308 value = valExpression.remove( 0,2 );
6309 d->extra()->validity->m_cond = Conditional::SuperiorEqual;
6311 else if (valExpression.find(
"!=" )==0 )
6314 value = valExpression.remove( 0,2 );
6315 d->extra()->validity->m_cond = Conditional::DifferentTo;
6317 else if ( valExpression.find(
"<" )==0 )
6319 value = valExpression.remove( 0,1 );
6320 d->extra()->validity->m_cond = Conditional::Inferior;
6322 else if(valExpression.find(
">" )==0 )
6324 value = valExpression.remove( 0,1 );
6325 d->extra()->validity->m_cond = Conditional::Superior;
6327 else if (valExpression.find(
"=" )==0 )
6329 value = valExpression.remove( 0,1 );
6330 d->extra()->validity->m_cond = Conditional::Equal;
6333 kdDebug()<<
" I don't know how to parse it :"<<valExpression<<endl;
6336 d->extra()->validity->dateMin = TQDate::fromString(
value );
6340 d->extra()->validity->timeMin = TQTime::fromString(
value );
6345 d->extra()->validity->valMin =
value.toDouble(&ok);
6348 d->extra()->validity->valMin =
value.toInt(&ok);
6350 kdDebug()<<
" Try to parse this value :"<<
value<<endl;
6354 d->extra()->validity->valMin =
value;
6361bool Cell::load(
const TQDomElement & cell,
int _xshift,
int _yshift,
6370 d->row = cell.attribute(
"row" ).toInt( &ok ) + _yshift;
6371 if ( !ok )
return false;
6372 d->column = cell.attribute(
"column" ).toInt( &ok ) + _xshift;
6373 if ( !ok )
return false;
6376 if ( d->row < 1 || d->row > KS_rowMax )
6378 kdDebug(36001) <<
"Cell::load: Value out of Range Cell:row=" << d->row << endl;
6381 if ( d->column < 1 || d->column > KS_colMax )
6383 kdDebug(36001) <<
"Cell::load: Value out of Range Cell:column=" << d->column << endl;
6390 TQDomElement f = cell.namedItem(
"format" ).toElement();
6396 if ( !
format()->load( f, pm, paste ) )
6399 if ( f.hasAttribute(
"colspan" ) )
6401 int i = f.attribute(
"colspan").toInt( &ok );
6402 if ( !ok )
return false;
6404 if ( i < 0 || i > KS_spanMax )
6406 kdDebug(36001) <<
"Value out of range Cell::colspan=" << i << endl;
6409 if (i || d->hasExtra())
6410 d->extra()->extraXCells = i;
6413 setFlag(Flag_Merged);
6417 if ( f.hasAttribute(
"rowspan" ) )
6419 int i = f.attribute(
"rowspan").toInt( &ok );
6420 if ( !ok )
return false;
6422 if ( i < 0 || i > KS_spanMax )
6424 kdDebug(36001) <<
"Value out of range Cell::rowspan=" << i << endl;
6427 if (i || d->hasExtra())
6428 d->extra()->extraYCells = i;
6431 setFlag(Flag_Merged);
6435 if ( testFlag( Flag_Merged ) )
6438 mergeCells( d->column, d->row, d->extra()->extraXCells, d->extra()->extraYCells );
6446 TQDomElement conditionsElement = cell.namedItem(
"condition" ).toElement();
6447 if ( !conditionsElement.isNull())
6450 delete d->extra()->conditions;
6451 d->extra()->conditions =
new Conditions(
this );
6452 d->extra()->conditions->loadConditions( conditionsElement );
6453 d->extra()->conditions->checkMatches();
6460 delete d->extra()->conditions;
6461 d->extra()->conditions = 0;
6465 TQDomElement validity = cell.namedItem(
"validity" ).toElement();
6466 if ( !validity.isNull())
6468 TQDomElement param = validity.namedItem(
"param" ).toElement();
6471 d->extra()->validity =
new Validity;
6472 if ( param.hasAttribute(
"cond" ) )
6474 d->extra()->validity->m_cond = (Conditional::Type) param.attribute(
"cond").toInt( &ok );
6478 if ( param.hasAttribute(
"action" ) )
6480 d->extra()->validity->m_action = (Action::Type) param.attribute(
"action").toInt( &ok );
6484 if ( param.hasAttribute(
"allow" ) )
6486 d->extra()->validity->m_restriction = (
Restriction::Type) param.attribute(
"allow").toInt( &ok );
6490 if ( param.hasAttribute(
"valmin" ) )
6492 d->extra()->validity->valMin = param.attribute(
"valmin").toDouble( &ok );
6496 if ( param.hasAttribute(
"valmax" ) )
6498 d->extra()->validity->valMax = param.attribute(
"valmax").toDouble( &ok );
6502 if ( param.hasAttribute(
"displaymessage" ) )
6504 d->extra()->validity->displayMessage = ( bool )param.attribute(
"displaymessage").toInt();
6506 if ( param.hasAttribute(
"displayvalidationinformation" ) )
6508 d->extra()->validity->displayValidationInformation = ( bool )param.attribute(
"displayvalidationinformation").toInt();
6510 if ( param.hasAttribute(
"allowemptycell" ) )
6512 d->extra()->validity->allowEmptyCell = ( bool )param.attribute(
"allowemptycell").toInt();
6514 if ( param.hasAttribute(
"listvalidity") )
6516 d->extra()->validity->listValidity=TQStringList::split(
";", param.attribute(
"listvalidity") );
6519 TQDomElement inputTitle = validity.namedItem(
"inputtitle" ).toElement();
6520 if (!inputTitle.isNull())
6522 d->extra()->validity->titleInfo = inputTitle.text();
6524 TQDomElement inputMessage = validity.namedItem(
"inputmessage" ).toElement();
6525 if (!inputMessage.isNull())
6527 d->extra()->validity->messageInfo = inputMessage.text();
6530 TQDomElement title = validity.namedItem(
"title" ).toElement();
6531 if (!title.isNull())
6533 d->extra()->validity->title = title.text();
6535 TQDomElement message = validity.namedItem(
"message" ).toElement();
6536 if (!message.isNull())
6538 d->extra()->validity->message = message.text();
6540 TQDomElement timeMin = validity.namedItem(
"timemin" ).toElement();
6541 if ( !timeMin.isNull() )
6543 d->extra()->validity->timeMin = toTime(timeMin);
6545 TQDomElement timeMax = validity.namedItem(
"timemax" ).toElement();
6546 if ( !timeMax.isNull() )
6548 d->extra()->validity->timeMax = toTime(timeMax);
6550 TQDomElement dateMin = validity.namedItem(
"datemin" ).toElement();
6551 if ( !dateMin.isNull() )
6553 d->extra()->validity->dateMin = toDate(dateMin);
6555 TQDomElement dateMax = validity.namedItem(
"datemax" ).toElement();
6556 if ( !dateMax.isNull() )
6558 d->extra()->validity->dateMax = toDate(dateMax);
6570 TQDomElement comment = cell.namedItem(
"comment" ).toElement();
6573 TQString t = comment.text();
6575 format()->setComment( t );
6584 TQDomElement
text = cell.namedItem(
"text" ).toElement();
6586 if ( !
text.isNull() &&
6592 if ( cell.hasAttribute(
"dataType" ) )
6593 text.setAttribute(
"dataType", cell.attribute(
"dataType" ) );
6595 TQDomElement result = cell.namedItem(
"result" ).toElement();
6596 TQString txt =
text.text();
6602 d->strText = result.text();
6605 loadCellData(
text, op);
6607 if ( !result.isNull() )
6610 TQString t = result.text();
6612 if ( result.hasAttribute(
"dataType" ) )
6613 dataType = result.attribute(
"dataType" );
6614 if ( result.hasAttribute(
"outStr" ) )
6616 d->strOutText = result.attribute(
"outStr" );
6617 if ( !d->strOutText.isEmpty() )
6618 clearFlag( Flag_TextFormatDirty );
6623 if( dataType ==
"Bool" )
6627 else if ( t ==
"true" )
6632 else if( dataType ==
"Num" )
6635 double dd = t.toDouble( &ok );
6641 else if( dataType ==
"Date" )
6644 double dd = t.toDouble( &ok );
6649 int pos = t.find(
'/' );
6650 int year = t.mid( 0, pos ).toInt();
6651 int pos1 = t.find(
'/', pos + 1 );
6652 int month = t.mid( pos + 1, ( ( pos1 - 1 ) - pos ) ).toInt();
6653 int day = t.right( t.length() - pos1 - 1 ).toInt();
6654 TQDate date( year, month, day );
6655 if ( date.isValid() )
6661 else if( dataType ==
"Time" )
6664 double dd = t.toDouble( &ok );
6673 pos = t.find(
':' );
6674 hours = t.mid( 0, pos ).toInt();
6675 pos1 = t.find(
':', pos + 1 );
6676 minutes = t.mid( pos + 1, ( ( pos1 - 1 ) - pos ) ).toInt();
6677 second = t.right( t.length() - pos1 - 1 ).toInt();
6678 TQTime time( hours, minutes, second );
6679 if ( time.isValid() )
6702 TQString t =
text.text();
6703 t = t.stripWhiteSpace();
6705 setFlag(Flag_LayoutDirty);
6706 setFlag(Flag_TextFormatDirty);
6711 t = decodeFormula( t, d->column, d->row );
6714 setFlag(Flag_CalcDirty);
6718 kdError(36001) <<
"ERROR: Syntax ERROR" << endl;
6721 else if (t[0] ==
'!' )
6726 bool inside_tag =
false;
6731 for(
unsigned i = 1; i < t.length(); i++ )
6742 else if( ch ==
'>' )
6747 if( tag.startsWith(
"a href=\"",
true ) )
6748 if( tag.endsWith(
"\"" ) )
6749 qml_link = tag.mid( 8, tag.length()-9 );
6762 if( !qml_link.isEmpty() )
6763 d->extra()->link = qml_link;
6764 d->strText = qml_text;
6769 bool newStyleLoading =
true;
6772 if (
text.hasAttribute(
"dataType" ) )
6774 dataType =
text.attribute(
"dataType" );
6779 if (
isDate() && ( t.contains(
'/') == 2 ))
6781 else if (
isTime() && ( t.contains(
':') == 2 ) )
6788 newStyleLoading =
false;
6792 if ( newStyleLoading )
6798 if( dataType ==
"Bool" )
6800 bool val = (t.lower() ==
"true");
6805 else if( dataType ==
"Num" )
6808 if (t.contains(
'.'))
6809 setValue ( Value( t.toDouble(&ok) ) );
6811 setValue ( Value( t.toLong(&ok) ) );
6814 kdWarning(36001) <<
"Couldn't parse '" << t <<
"' as number." << endl;
6817 TDELocale*
locale =
format()->sheet()->doc()->locale();
6821 int precision = t.length() - t.find(
'.') - 1;
6825 if (
value().isInteger())
6826 t =
locale->formatNumber(
value().asInteger() * 100 );
6828 t =
locale->formatNumber(
value().asFloat() * 100.0, precision );
6834 if (
value().isInteger())
6837 t =
locale->formatNumber(
value().asFloat(), precision);
6843 else if( dataType ==
"Date" )
6845 int pos = t.find(
'/');
6846 int year = t.mid(0,pos).toInt();
6847 int pos1 = t.find(
'/',pos+1);
6848 int month = t.mid(pos+1,((pos1-1)-pos)).toInt();
6849 int day = t.right(t.length()-pos1-1).toInt();
6850 setValue( TQDate(year,month,day) );
6851 if (
value().asDate().isValid() )
6852 d->strText =
locale()->formatDate(
value().asDate(),
true );
6861 else if( dataType ==
"Time" )
6868 hours = t.mid(0,pos).toInt();
6869 pos1 = t.find(
':',pos+1);
6870 minutes = t.mid(pos+1,((pos1-1)-pos)).toInt();
6871 second = t.right(t.length()-pos1-1).toInt();
6872 setValue( TQTime(hours,minutes,second) );
6873 if (
value().asTime().isValid() )
6874 d->strText =
locale()->formatTime(
value().asTime(),
true );
6891 if (
text.hasAttribute(
"outStr" ) )
6893 d->strOutText =
text.attribute(
"outStr" );
6894 if ( !d->strOutText.isEmpty() )
6895 clearFlag( Flag_TextFormatDirty );
6901 if ( d->hasExtra() && d->extra()->conditions )
6902 d->extra()->conditions->checkMatches();
6907TQTime Cell::toTime(
const TQDomElement &element)
6910 TQString t = element.text();
6911 t = t.stripWhiteSpace();
6917 hours = t.mid(0,pos).toInt();
6918 pos1 = t.find(
':',pos+1);
6919 minutes = t.mid(pos+1,((pos1-1)-pos)).toInt();
6920 second = t.right(t.length()-pos1-1).toInt();
6921 setValue( Value( TQTime(hours,minutes,second)) );
6925TQDate Cell::toDate(
const TQDomElement &element)
6927 TQString t = element.text();
6934 year = t.mid(0,pos).toInt();
6935 pos1 = t.find(
'/',pos+1);
6936 month = t.mid(pos+1,((pos1-1)-pos)).toInt();
6937 day = t.right(t.length()-pos1-1).toInt();
6938 setValue( Value( TQDate(year,month,day) ) );
6951 if( !new_text.isEmpty() && new_text[0] ==
'=' )
6953 tmp = new_text.right( new_text.length() - 1 );
6960 if ( old_text.isEmpty() &&
6966 if( !old_text.isEmpty() && old_text[0] ==
'=' )
6968 old = old_text.right( old_text.length() - 1 );
6976 tmp.toDouble( &b1 );
6977 old.toDouble( &b2 );
6978 if (b1 && !b2 && old.length() == 0)
6989 tmp_op = TQString::number(old.toDouble()+tmp.toDouble());
6992 tmp_op = TQString::number(old.toDouble()*tmp.toDouble());
6995 tmp_op = TQString::number(old.toDouble()-tmp.toDouble());
6998 tmp_op = TQString::number(old.toDouble()/tmp.toDouble());
7004 setFlag(Flag_LayoutDirty);
7009 else if ( ( new_text[0] ==
'=' && old_text[0] ==
'=' ) ||
7010 ( b1 && old_text[0] ==
'=' ) || ( new_text[0] ==
'=' && b2 ) )
7015 tmp_op=
"=("+old+
")+"+
"("+tmp+
")";
7018 tmp_op=
"=("+old+
")*"+
"("+tmp+
")";
7021 tmp_op=
"=("+old+
")-"+
"("+tmp+
")";
7024 tmp_op=
"=("+old+
")/"+
"("+tmp+
")";
7030 tmp_op = decodeFormula( tmp_op, d->column, d->row );
7031 setFlag(Flag_LayoutDirty);
7037 tmp = decodeFormula( new_text, d->column, d->row );
7038 setFlag(Flag_LayoutDirty);
7044TQString Cell::testAnchor(
int x,
int y )
const
7049 const Doc* doc =
format()->sheet()->doc();
7050 int x1 = doc->zoomItX( d->textX );
7051 int y1 = doc->zoomItX( d->textY - d->textHeight );
7052 int x2 = doc->zoomItX( d->textX + d->textWidth );
7053 int y2 = doc->zoomItX( d->textY );
7055 if( x > x1 )
if( x < x2 )
7056 if( y > y1 )
if( y < y2 )
7067 d->extra()->extraXCells = 0;
7068 d->extra()->extraYCells = 0;
7069 d->extra()->mergedXCells = 0;
7070 d->extra()->mergedYCells = 0;
7080 d->nextCell->setPreviousCell( d->previousCell );
7081 if ( d->previousCell )
7082 d->previousCell->setNextCell( d->nextCell );
7086 delete d->extra()->validity;
7090 int extraXCells = d->hasExtra() ? d->extra()->extraXCells : 0;
7091 int extraYCells = d->hasExtra() ? d->extra()->extraYCells : 0;
7093 for(
int y = (x == 0) ? 1 : 0;
7096 Cell* cell =
format()->sheet()->cellAt( d->column + x, d->row + y );
7112 if (
value().isNumber() )
7114 if ( cell.value().isNumber() )
7123 else if (cell.value().isNumber())
7132 else if( cell.isDate())
7134 else if( cell.value().isNumber())
7141 if ( Map::respectCase )
7142 return value().
asString().compare(cell.value().asString()) > 0;
7144 return (
value().asString() ).lower().compare(cell.value().asString().lower()) > 0;
7148bool Cell::operator < (
const Cell & cell )
const
7150 if (
value().isNumber() )
7152 if ( cell.value().isNumber() )
7160 return value().
asDateTime().date() < cell.value().asDateTime().date();
7161 else if( cell.value().isNumber())
7179 if ( Map::respectCase )
7186bool Cell::operator==(
const Cell& other )
const
7188 if ( d->strText != other.d->strText )
7190 if ( d->value != other.d->value )
7192 if ( *d->format != *other.d->format )
7194 if ( d->hasExtra() )
7196 if ( !other.d->hasExtra() )
7198 if ( d->extra()->link != other.d->extra()->link )
7200 if ( d->extra()->mergedXCells != other.d->extra()->mergedXCells )
7202 if ( d->extra()->mergedYCells != other.d->extra()->mergedYCells )
7204 if ( d->extra()->conditions )
7206 if ( !other.d->extra()->conditions )
7208 if ( *d->extra()->conditions != *other.d->extra()->conditions )
7211 if ( d->extra()->validity )
7213 if ( !other.d->extra()->validity )
7215 if ( *d->extra()->validity != *other.d->extra()->validity )
7225 return TQRect(TQPoint(d->column, d->row), TQPoint(d->column, d->row));
7230 if ( !d->hasExtra() || !d->extra()->conditions )
7232 TQValueList<Conditional> emptyList;
7236 return d->extra()->conditions->conditionList();
7242 delete d->extra()->conditions;
7243 d->extra()->conditions =
new Conditions(
this );
7244 d->extra()->conditions->setConditionList( newList );
7245 d->extra()->conditions->checkMatches();
7250 return ( testFlag(Flag_ParseError) ||
7251 testFlag(Flag_CircularCalculation) ||
7252 testFlag(Flag_DependancyError));
7257 clearFlag( Flag_ParseError );
7258 clearFlag( Flag_CircularCalculation );
7259 clearFlag( Flag_DependancyError );
7264 return isFormula() ? testFlag( Flag_CalcDirty ) :
false;
7267bool Cell::layoutDirtyFlag()
const
7269 return testFlag( Flag_LayoutDirty );
7272void Cell::clearDisplayDirtyFlag()
7274 clearFlag( Flag_DisplayDirty );
7277void Cell::setDisplayDirtyFlag()
7279 setFlag( Flag_DisplayDirty );
7284 return testFlag( Flag_Merged );
7287void Cell::clearFlag( CellFlags flag )
7289 d->flags &= ~(TQ_UINT32)flag;
7292void Cell::setFlag( CellFlags flag )
7294 d->flags |= (TQ_UINT32)flag;
7297bool Cell::testFlag( CellFlags flag )
const
7299 return ( d->flags & (TQ_UINT32)flag );
7303void Cell::checkForNamedAreas( TQString & formula )
const
7307 kdDebug() <<
"Cell::checkForNamedAreas loadinginfo is NULL" << endl;
7311 int l = formula.length();
7317 if ( formula[i].isLetterOrNumber() )
7323 if ( !word.isEmpty() )
7325 if ( loadinginfo->findWordInAreaList(word) )
7327 formula = formula.replace( start, word.length(),
"'" + word +
"'" );
7328 l = formula.length();
7330 kdDebug() <<
"Formula: " << formula <<
", L: " << l <<
", i: " << i + 1 <<endl;
7338 if ( !word.isEmpty() )
7340 if ( loadinginfo->findWordInAreaList(word) )
7342 formula = formula.replace( start, word.length(),
"'" + word +
"'" );
7343 l = formula.length();
7345 kdDebug() <<
"Formula: " << formula <<
", L: " << l <<
", i: " << i + 1 <<endl;
The canvas builds a part of the GUI of KSpread.
This is an abstract base class only.
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.
double dblHeight(int _row=-1, const Canvas *_canvas=0L) const
FormatType formatType() const
Return the format of this cell.
void setLayoutDirtyFlag(bool format=false)
Causes the format to be recalculated when the cell is drawn next time.
const TQPen & effBottomBorderPen(int col, int row) const
void loadOasisCellText(const TQDomElement &parent)
Load the text paragraphs from an OASIS XML cell description.
TQString encodeFormula(bool _era=false, int _col=-1, int _row=-1) const
encode a formula into a text representation
TQString link() const
Returns the link associated with cell.
TQValueList< Conditional > conditionList() const
Gets a copy of the list of current conditions.
bool calc(bool delay=true)
Starts calculating.
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.
TQString fullName() const
Returns the full name of the cell, i.e.
void setRightBorderPen(const TQPen &p)
int defineAlignX()
return align X when align is undefined
void clearAllErrors()
Clear all error flags from the cell.
void convertToDate()
converts content to date format
const Value value() const
Returns the value that this cell holds.
TQValueList< Cell * > obscuringCells() const
void clearFormula()
Cleans up formula stuff.
bool updateChart(bool refresh=true)
Refreshing chart.
const TQPen & topBorderPen(int col, int row) const
Sheet * sheet() const
Returns the worksheet which owns this cell.
bool doesMergeCells() const
void setLink(const TQString &link)
Sets a link for this cell.
void setConditionList(const TQValueList< Conditional > &newList)
Replace the old set of conditions with a new one.
void setValue(const Value &value)
Sets the value for this cell.
int column() const
Returns the cell's column.
bool calcDirtyFlag()
Checks the calcDirtyFlag.
void copyAll(Cell *cell)
Copies the format and the content.
void paintCell(const KoRect &rect, TQPainter &painter, View *view, const KoPoint &coordinate, const TQPoint &cellRef, int paintBorder, TQPen &rightPen, TQPen &bottomPen, TQPen &leftPen, TQPen &topPen, TQValueList< TQPoint > &mergedCellsPainted, bool drawCursor=true)
Paints the cell.
double getDouble()
return the cell's value as a double
void sheetDies()
This method notifies the cell that the parent sheet is being deleted.
double textHeight() const
return height of the text
TQString textDisplaying(TQPainter &painter)
Called from paintCell to determine the text wich can be displaying.
bool isEmpty() const
Returns true if this cell has no content, i.e no text and no formula.
void setCellValue(const Value &value, FormatType fmtType=No_format, const TQString &inputText=TQString())
Sets the value for this cell and its formatting and input text, if appropriate.
TQString pasteOperation(const TQString &new_text, const TQString &old_text, Paste::Operation op)
Merges the new_text with old_text during a paste operation.
TDELocale * locale() const
Returns the locale setting of this cell.
void calculateTextParameters(TQPainter &painter, int _col, int _row)
Calculates the text parameters stored in cell Applies font to use to painter.
const TQPen & effFallDiagonalPen(int col, int row) const
Cell * ultimateObscuringCell() const
Return the cell that is obscuring this one (merged cells only).
uint effRightBorderValue(int col, int row) const
const TQPen & effTopBorderPen(int col, int row) const
void setDisplayText(const TQString &_text)
Sets the text in the cell when the user inputs it.
const TQPen & leftBorderPen(int col, int row) const
void setTopBorderPen(const TQPen &p)
const TQPen & effRightBorderPen(int col, int row) const
void obscure(Cell *cell, bool isForcing=false)
Tells this cell that the Cell 'cell' obscures this one.
void move(int column, int row)
Moves around the cell.
bool loadOasis(const TQDomElement &element, KoOasisLoadingContext &oasisContext, Style *style)
Loads a cell from an OASIS XML element.
bool needsPrinting() const
void checkTextInput()
Check the input from the user, and determine the contents of the cell accordingly (in particular the ...
void convertToPercent()
converts content to percentageformat
bool isFormula() const
Returns true if this cell holds a formula.
uint effLeftBorderValue(int col, int row) const
uint effTopBorderValue(int col, int row) const
int height(int _row=-1, const Canvas *_canvas=0L) const
TQDomElement save(TQDomDocument &doc, int _x_offset=0, int _y_offset=0, bool force=false, bool copy=false, bool era=false)
Save this cell.
TQString saveOasisCellStyle(KoGenStyle ¤tCellStyle, KoGenStyles &mainStyles)
const TQPen & bottomBorderPen(int col, int row) const
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.
void incPrecision()
Increases the precison of the value displayed.
void convertToMoney()
converts content to money format
const TQPen & effLeftBorderPen(int col, int row) const
Format * format() const
Returns the format object of this cell.
void setBottomBorderPen(const TQPen &p)
bool operator>(const Cell &) const
Used for comparing cells (when sorting).
void convertToTime()
converts content to time format
void makeLayout(TQPainter &_painter, int _col, int _row)
Calculates the layout of the cell, i,e, determines what should be shown for this cell,...
double dblWidth(int _col=-1, const Canvas *_canvas=0L) const
uint effBottomBorderValue(int col, int row) const
void convertToDouble()
converts content to double format
void mergeCells(int _col, int _row, int _x, int _y)
Merge a number of cells, i.e.
void unobscure(Cell *cell)
Tells this cell that it is no longer obscured.
void copyFormat(const int column, const int row)
Copyies the format from the cell at the position (_column|_row).
const TQPen & rightBorderPen(int col, int row) const
void checkNumberFormat()
Automatically chooses between a number format and a scientific format (if the number is too big).
TQString columnName() const
Returns the column name of the cell.
const TQBrush & backGroundBrush(int col, int row) const
bool isDefault() const
Returns true if this is a default cell (with row and column equal to zero).
const TQColor & bgColor(int col, int row) const
void textSize(TQPainter &_paint)
Called from makeFormat() to determine the space needed for the text.
bool isPartOfMerged() const
If this cell is part of a merged cell, then the marker may never reside on this cell.
void applyZoomedFont(TQPainter &painter, int _col, int _row)
Applies the font to use to painter.
bool makeFormula()
Parses the formula.
bool isDate() const
returns true, if cell format is of date type or content is a date
bool isTime() const
returns true, if cell format is of time type or content is a time
const TQPen & effGoUpDiagonalPen(int col, int row) const
bool testValidity() const
return true if value is good else show a messagebox
void decPrecision()
Decreases the precison of the value displayed.
void setLeftBorderPen(const TQPen &p)
double textWidth() const
return width of the text
int width(int _col=-1, const Canvas *_canvas=0L) const
This class holds the data that makes up a spreadsheet.
void emitBeginOperation(bool waitCursor)
Functions to begin a kspread 'operation'.
KSPLoadingInfo * loadingInfo() const
void insertObject(EmbeddedObject *obj)
Inserts an object to the object list.
virtual void emitEndOperation()
Mark the end of an operation and triggers a repaint of any cells or regions of cells which have been ...
Holds an embedded chart object.
Holds an embedded koffice object.
Contains basic information for every object.
bool contains(const TQPoint &point, Sheet *sheet=0) const
The Style class represents a cell style.
void parse(const TQString &str, Cell *cell)
try to parse the text in a given cell and set value accordingly
Provides a wrapper for cell value.
static const Value & empty()
Returns constant reference to empty value.
Value element(unsigned column, unsigned row) const
Return an element in the array value.
void setError(const TQString &msg)
Sets this value to hold error message.
bool isBoolean() const
Returns true if the type of this value is Boolean.
bool isNumber() const
Returns true if the type of this value is either integer or floating-point.
bool isArray() const
Returns true if the type of this value is array.
TQDate asDate() const
Returns the date representation of this value.
Type type() const
Returns the type of the value.
double asFloat() const
Returns the floating-point value of this value.
TQDateTime asDateTime() const
Returns the date/time representation of this value.
TQString asString() const
Returns the string value of this value.
bool isString() const
Returns true if the type of this value is string.
TQTime asTime() const
Returns the time representation of this value.
bool asBoolean() const
Returns the boolean value of this value.
The View class displays a KSpread document.
static TQColor highlightColor()
Returns the default color for highlighting cells and column / row headers.
Canvas * canvasWidget() const
Returns the canvas of the view.
A pointer to the decimal separator.
Operation
The current cell value treatment.
@ Result
Result only, no formula.
@ NoBorder
not the borders
Type
The type of the restriction.
@ Number
Restrict to numbers.
@ Integer
Restrict to integers.
@ TextLength
Restrict text length.
KSPREAD_EXPORT int util_decodeColumnLabelText(const TQString &_col)
Call this function to decode the text of a column label to an integer i.e.