25#include "kspread_cell.h"
26#include "kspread_format.h"
28#include "kspread_cluster.h"
40 : m_first( 0 ), m_autoDelete( false ), m_biggestX(0), m_biggestY(0)
42 m_cluster = (
Cell***)malloc( KSPREAD_CLUSTER_LEVEL1 * KSPREAD_CLUSTER_LEVEL1 *
sizeof(
Cell** ) );
44 for(
int x = 0; x < KSPREAD_CLUSTER_LEVEL1; ++x )
45 for(
int y = 0; y < KSPREAD_CLUSTER_LEVEL1; ++y )
46 m_cluster[ y * KSPREAD_CLUSTER_LEVEL1 + x ] = 0;
53 for(
int x = 0; x < KSPREAD_CLUSTER_LEVEL1; ++x )
54 for(
int y = 0; y < KSPREAD_CLUSTER_LEVEL1; ++y )
56 Cell** cl = m_cluster[ y * KSPREAD_CLUSTER_LEVEL1 + x ];
60 m_cluster[ y * KSPREAD_CLUSTER_LEVEL1 + x ] = 0;
69 Cell* n = cell->nextCell();
80 for(
int x = 0; x < KSPREAD_CLUSTER_LEVEL1; ++x )
81 for(
int y = 0; y < KSPREAD_CLUSTER_LEVEL1; ++y )
83 Cell** cl = m_cluster[ y * KSPREAD_CLUSTER_LEVEL1 + x ];
87 m_cluster[ y * KSPREAD_CLUSTER_LEVEL1 + x ] = 0;
96 Cell* n = cell->nextCell();
103 m_biggestX = m_biggestY = 0;
106Cell* Cluster::lookup(
int x,
int y )
const
108 if ( x >= KSPREAD_CLUSTER_MAX || x < 0 || y >= KSPREAD_CLUSTER_MAX || y < 0 )
110 kdDebug(36001) <<
"Cluster::lookup: invalid column or row value (col: "
111 << x <<
" | row: " << y <<
")" << endl;
114 int cx = x / KSPREAD_CLUSTER_LEVEL2;
115 int cy = y / KSPREAD_CLUSTER_LEVEL2;
116 int dx = x % KSPREAD_CLUSTER_LEVEL2;
117 int dy = y % KSPREAD_CLUSTER_LEVEL2;
119 Cell** cl = m_cluster[ cy * KSPREAD_CLUSTER_LEVEL1 + cx ];
123 return cl[ dy * KSPREAD_CLUSTER_LEVEL2 + dx ];
129 if ( x >= KSPREAD_CLUSTER_MAX || x < 0 || y >= KSPREAD_CLUSTER_MAX || y < 0 )
131 kdDebug(36001) <<
"Cluster::insert: invalid column or row value (col: "
132 << x <<
" | row: " << y <<
")" << endl;
136 int cx = x / KSPREAD_CLUSTER_LEVEL2;
137 int cy = y / KSPREAD_CLUSTER_LEVEL2;
138 int dx = x % KSPREAD_CLUSTER_LEVEL2;
139 int dy = y % KSPREAD_CLUSTER_LEVEL2;
141 Cell** cl = m_cluster[ cy * KSPREAD_CLUSTER_LEVEL1 + cx ];
144 cl = (
Cell**)malloc( KSPREAD_CLUSTER_LEVEL2 * KSPREAD_CLUSTER_LEVEL2 *
sizeof(
Cell* ) );
145 m_cluster[ cy * KSPREAD_CLUSTER_LEVEL1 + cx ] = cl;
147 for(
int a = 0; a < KSPREAD_CLUSTER_LEVEL2; ++a )
148 for(
int b = 0; b < KSPREAD_CLUSTER_LEVEL2; ++b )
149 cl[ b * KSPREAD_CLUSTER_LEVEL2 + a ] = 0;
152 if ( cl[ dy * KSPREAD_CLUSTER_LEVEL2 + dx ] )
155 cl[ dy * KSPREAD_CLUSTER_LEVEL2 + dx ] = cell;
159 cell->setNextCell( m_first );
160 m_first->setPreviousCell( cell );
164 if (x > m_biggestX) m_biggestX = x;
165 if (y > m_biggestY) m_biggestY = y;
171 if ( x >= KSPREAD_CLUSTER_MAX || x < 0 || y >= KSPREAD_CLUSTER_MAX || y < 0 )
173 kdDebug(36001) <<
"Cluster::remove: invalid column or row value (col: "
174 << x <<
" | row: " << y <<
")" << endl;
178 int cx = x / KSPREAD_CLUSTER_LEVEL2;
179 int cy = y / KSPREAD_CLUSTER_LEVEL2;
180 int dx = x % KSPREAD_CLUSTER_LEVEL2;
181 int dy = y % KSPREAD_CLUSTER_LEVEL2;
183 Cell** cl = m_cluster[ cy * KSPREAD_CLUSTER_LEVEL1 + cx ];
187 Cell* c = cl[ dy * KSPREAD_CLUSTER_LEVEL2 + dx ];
191 cl[ dy * KSPREAD_CLUSTER_LEVEL2 + dx ] = 0;
196 m_first = c->nextCell();
206 m_first = c->nextCell();
207 if ( c->previousCell() )
208 c->previousCell()->setNextCell( c->nextCell() );
210 c->nextCell()->setPreviousCell( c->previousCell() );
212 c->setPreviousCell( 0 );
216bool Cluster::shiftRow(
const TQPoint& marker )
219 return shiftRow( marker, dummy );
234void Cluster::unshiftRow(
const TQPoint& marker )
237 unshiftRow( marker, dummy );
240void Cluster::setAutoDelete(
bool b )
245bool Cluster::autoDelete()
const
250Cell* Cluster::firstCell()
const
255bool Cluster::shiftRow(
const TQPoint& marker,
bool& work )
259 if ( marker.x() >= KSPREAD_CLUSTER_MAX || marker.x() < 0 ||
260 marker.y() >= KSPREAD_CLUSTER_MAX || marker.y() < 0 )
262 kdDebug(36001) <<
"Cluster::shiftRow: invalid column or row value (col: "
263 << marker.x() <<
" | row: " << marker.y() <<
")" << endl;
267 int cx = marker.x() / KSPREAD_CLUSTER_LEVEL2;
268 int cy = marker.y() / KSPREAD_CLUSTER_LEVEL2;
269 int dx = marker.x() % KSPREAD_CLUSTER_LEVEL2;
270 int dy = marker.y() % KSPREAD_CLUSTER_LEVEL2;
274 Cell** cl = m_cluster[ cy * KSPREAD_CLUSTER_LEVEL1 + KSPREAD_CLUSTER_LEVEL1 - 1 ];
275 if ( cl && cl[ dy * KSPREAD_CLUSTER_LEVEL2 + KSPREAD_CLUSTER_LEVEL2 - 1 ] )
278 bool a = autoDelete();
279 setAutoDelete(
false );
282 for(
int i = KSPREAD_CLUSTER_LEVEL1 - 1; i >= cx ; --i )
284 Cell** cl = m_cluster[ cy * KSPREAD_CLUSTER_LEVEL1 + i ];
291 int right = KSPREAD_CLUSTER_LEVEL2 - 1;
292 if ( i == KSPREAD_CLUSTER_LEVEL1 - 1 )
293 right = KSPREAD_CLUSTER_LEVEL2 - 2;
294 for(
int k = right; k >= left; --k )
296 Cell* c = cl[ dy * KSPREAD_CLUSTER_LEVEL2 + k ];
316 if ( marker.x() >= KSPREAD_CLUSTER_MAX || marker.x() < 0 ||
317 marker.y() >= KSPREAD_CLUSTER_MAX || marker.y() < 0 )
319 kdDebug(36001) <<
"Cluster::shiftColumn: invalid column or row value (col: "
320 << marker.x() <<
" | row: " << marker.y() <<
")" << endl;
324 int cx = marker.x() / KSPREAD_CLUSTER_LEVEL2;
325 int cy = marker.y() / KSPREAD_CLUSTER_LEVEL2;
326 int dx = marker.x() % KSPREAD_CLUSTER_LEVEL2;
327 int dy = marker.y() % KSPREAD_CLUSTER_LEVEL2;
331 Cell** cl = m_cluster[ KSPREAD_CLUSTER_LEVEL1 * ( KSPREAD_CLUSTER_LEVEL1 - 1 ) + cx ];
332 if ( cl && cl[ KSPREAD_CLUSTER_LEVEL2 * ( KSPREAD_CLUSTER_LEVEL2 - 1 ) + dx ] )
335 bool a = autoDelete();
336 setAutoDelete(
false );
339 for(
int i = KSPREAD_CLUSTER_LEVEL1 - 1; i >= cy ; --i )
341 Cell** cl = m_cluster[ i * KSPREAD_CLUSTER_LEVEL1 + cx ];
349 int bottom = KSPREAD_CLUSTER_LEVEL2 - 1;
350 if ( i == KSPREAD_CLUSTER_LEVEL1 - 1 )
351 bottom = KSPREAD_CLUSTER_LEVEL2 - 2;
352 for(
int k = bottom; k >= top; --k )
354 Cell* c = cl[ k * KSPREAD_CLUSTER_LEVEL2 + dx ];
372 if ( col >= KSPREAD_CLUSTER_MAX || col < 0 )
374 kdDebug(36001) <<
"Cluster::insertColumn: invalid column value (col: "
375 << col <<
")" << endl;
381 for(
int t1 = 0; t1 < KSPREAD_CLUSTER_LEVEL1; ++t1 )
383 Cell** cl = m_cluster[ t1 * KSPREAD_CLUSTER_LEVEL1 + KSPREAD_CLUSTER_LEVEL1 - 1 ];
385 for(
int t2 = 0; t2 < KSPREAD_CLUSTER_LEVEL2; ++t2 )
386 if ( cl[ t2 * KSPREAD_CLUSTER_LEVEL2 + KSPREAD_CLUSTER_LEVEL2 - 1 ] )
390 for(
int t1 = 0; t1 < KSPREAD_CLUSTER_LEVEL1; ++t1 )
393 for(
int t2 = 0; work && t2 < KSPREAD_CLUSTER_LEVEL2; ++t2 )
394 shiftRow( TQPoint( col, t1 * KSPREAD_CLUSTER_LEVEL2 + t2 ), work );
400bool Cluster::insertRow(
int row )
402 if ( row >= KSPREAD_CLUSTER_MAX || row < 0 )
404 kdDebug(36001) <<
"Cluster::insertRow: invalid row value (row: "
405 << row <<
")" << endl;
411 for(
int t1 = 0; t1 < KSPREAD_CLUSTER_LEVEL1; ++t1 )
413 Cell** cl = m_cluster[ KSPREAD_CLUSTER_LEVEL1 * ( KSPREAD_CLUSTER_LEVEL1 - 1 ) + t1 ];
415 for(
int t2 = 0; t2 < KSPREAD_CLUSTER_LEVEL2; ++t2 )
416 if ( cl[ KSPREAD_CLUSTER_LEVEL2 * ( KSPREAD_CLUSTER_LEVEL2 - 1 ) + t2 ] )
420 for(
int t1 = 0; t1 < KSPREAD_CLUSTER_LEVEL1; ++t1 )
423 for(
int t2 = 0; work && t2 < KSPREAD_CLUSTER_LEVEL2; ++t2 )
424 shiftColumn( TQPoint( t1 * KSPREAD_CLUSTER_LEVEL2 + t2, row ), work );
434 if ( marker.x() >= KSPREAD_CLUSTER_MAX || marker.x() < 0 ||
435 marker.y() >= KSPREAD_CLUSTER_MAX || marker.y() < 0 )
437 kdDebug(36001) <<
"Cluster::unshiftColumn: invalid column or row value (col: "
438 << marker.x() <<
" | row: " << marker.y() <<
")" << endl;
442 int cx = marker.x() / KSPREAD_CLUSTER_LEVEL2;
443 int cy = marker.y() / KSPREAD_CLUSTER_LEVEL2;
444 int dx = marker.x() % KSPREAD_CLUSTER_LEVEL2;
445 int dy = marker.y() % KSPREAD_CLUSTER_LEVEL2;
447 bool a = autoDelete();
448 setAutoDelete(
false );
451 for(
int i = cy; i < KSPREAD_CLUSTER_LEVEL1; ++i )
453 Cell** cl = m_cluster[ i * KSPREAD_CLUSTER_LEVEL1 + cx ];
461 int bottom = KSPREAD_CLUSTER_LEVEL2 - 1;
462 for(
int k = top; k <= bottom; ++k )
464 Cell* c = cl[ k * KSPREAD_CLUSTER_LEVEL2 + dx ];
478void Cluster::unshiftRow(
const TQPoint& marker,
bool& work )
482 if ( marker.x() >= KSPREAD_CLUSTER_MAX || marker.x() < 0 ||
483 marker.y() >= KSPREAD_CLUSTER_MAX || marker.y() < 0 )
485 kdDebug(36001) <<
"Cluster::unshiftRow: invalid column or row value (col: "
486 << marker.x() <<
" | row: " << marker.y() <<
")" << endl;
490 int cx = marker.x() / KSPREAD_CLUSTER_LEVEL2;
491 int cy = marker.y() / KSPREAD_CLUSTER_LEVEL2;
492 int dx = marker.x() % KSPREAD_CLUSTER_LEVEL2;
493 int dy = marker.y() % KSPREAD_CLUSTER_LEVEL2;
495 bool a = autoDelete();
496 setAutoDelete(
false );
499 for(
int i = cx; i < KSPREAD_CLUSTER_LEVEL1; ++i )
501 Cell** cl = m_cluster[ cy * KSPREAD_CLUSTER_LEVEL1 + i ];
509 int right = KSPREAD_CLUSTER_LEVEL2 - 1;
510 for(
int k = left; k <= right; ++k )
512 Cell* c = cl[ dy * KSPREAD_CLUSTER_LEVEL2 + k ];
528 if ( col >= KSPREAD_CLUSTER_MAX || col < 0 )
530 kdDebug(36001) <<
"Cluster::removeColumn: invalid column value (col: "
531 << col <<
")" << endl;
535 int cx = col / KSPREAD_CLUSTER_LEVEL2;
536 int dx = col % KSPREAD_CLUSTER_LEVEL2;
538 for(
int y1 = 0; y1 < KSPREAD_CLUSTER_LEVEL1; ++y1 )
540 Cell** cl = m_cluster[ y1 * KSPREAD_CLUSTER_LEVEL1 + cx ];
542 for(
int y2 = 0; y2 < KSPREAD_CLUSTER_LEVEL2; ++y2 )
543 if ( cl[ y2 * KSPREAD_CLUSTER_LEVEL2 + dx ] )
544 remove( col, y1 * KSPREAD_CLUSTER_LEVEL1 + y2 );
547 for(
int t1 = 0; t1 < KSPREAD_CLUSTER_LEVEL1; ++t1 )
550 for(
int t2 = 0; work && t2 < KSPREAD_CLUSTER_LEVEL2; ++t2 )
551 unshiftRow( TQPoint( col, t1 * KSPREAD_CLUSTER_LEVEL2 + t2 ), work );
555void Cluster::removeRow(
int row )
557 if ( row >= KSPREAD_CLUSTER_MAX || row < 0 )
559 kdDebug(36001) <<
"Cluster::removeRow: invalid row value (row: "
560 << row <<
")" << endl;
564 int cy = row / KSPREAD_CLUSTER_LEVEL2;
565 int dy = row % KSPREAD_CLUSTER_LEVEL2;
567 for(
int x1 = 0; x1 < KSPREAD_CLUSTER_LEVEL1; ++x1 )
569 Cell** cl = m_cluster[ cy * KSPREAD_CLUSTER_LEVEL1 + x1 ];
571 for(
int x2 = 0; x2 < KSPREAD_CLUSTER_LEVEL2; ++x2 )
572 if ( cl[ dy * KSPREAD_CLUSTER_LEVEL2 + x2 ] )
573 remove( x1 * KSPREAD_CLUSTER_LEVEL2 + x2, row );
576 for(
int t1 = 0; t1 < KSPREAD_CLUSTER_LEVEL1; ++t1 )
579 for(
int t2 = 0; work && t2 < KSPREAD_CLUSTER_LEVEL2; ++t2 )
580 unshiftColumn( TQPoint( t1 * KSPREAD_CLUSTER_LEVEL2 + t2, row ), work );
586 if ( col >= KSPREAD_CLUSTER_MAX || col < 0 )
588 kdDebug(36001) <<
"Cluster::clearColumn: invalid column value (col: "
589 << col <<
")" << endl;
593 int cx = col / KSPREAD_CLUSTER_LEVEL2;
594 int dx = col % KSPREAD_CLUSTER_LEVEL2;
596 for(
int cy = 0; cy < KSPREAD_CLUSTER_LEVEL1; ++cy )
598 Cell** cl = m_cluster[ cy * KSPREAD_CLUSTER_LEVEL1 + cx ];
600 for(
int dy = 0; dy < KSPREAD_CLUSTER_LEVEL2; ++dy )
601 if ( cl[ dy * KSPREAD_CLUSTER_LEVEL2 + dx ] )
603 int row = cy * KSPREAD_CLUSTER_LEVEL2 + dy ;
609void Cluster::clearRow(
int row )
611 if ( row >= KSPREAD_CLUSTER_MAX || row < 0 )
613 kdDebug(36001) <<
"Cluster::clearRow: invalid row value (row: "
614 << row <<
")" << endl;
618 int cy = row / KSPREAD_CLUSTER_LEVEL2;
619 int dy = row % KSPREAD_CLUSTER_LEVEL2;
621 for(
int cx = 0; cx < KSPREAD_CLUSTER_LEVEL1; ++cx )
623 Cell** cl = m_cluster[ cy * KSPREAD_CLUSTER_LEVEL2 + cx ];
625 for(
int dx = 0; dx < KSPREAD_CLUSTER_LEVEL2; ++dx )
626 if ( cl[ dy * KSPREAD_CLUSTER_LEVEL2 + dx ] )
628 int column = cx * KSPREAD_CLUSTER_LEVEL2 + dx ;
635 int col2,
int row2)
const
642 int p = col1; col1 = col2; col2 = p;
646 int p = row1; row1 = col2; row2 = p;
648 if ((row1 < 0) || (col1 < 0) || (row2 > KSPREAD_CLUSTER_MAX) ||
649 (col2 > KSPREAD_CLUSTER_MAX))
654 if ((row1 > m_biggestY) || (col1 > m_biggestX))
656 int cols = col2 - col1 + 1;
657 int rows = row2 - row1 + 1;
658 Value array (cols, rows);
662 return makeArray (col1, row1, col2, row2);
665Value Cluster::makeArray (
int col1,
int row1,
666 int col2,
int row2)
const
670 int cols = col2 - col1 + 1;
671 int rows = row2 - row1 + 1;
672 Value array (cols, rows);
673 for (
int row = row1; row <= row2; ++row)
674 for (
int col = col1; col <= col2; ++col)
676 Cell *cell = lookup (col, row);
690 Cell* cell = lookup(col, 1);
701 Cell* cell = lookup(col, KS_rowMax);
712 Cell* cell = lookup(1, row);
723 Cell* cell = lookup(KS_colMax, row);
734 int cx = col / KSPREAD_CLUSTER_LEVEL2;
735 int cy = (row - 1) / KSPREAD_CLUSTER_LEVEL2;
736 int dx = col % KSPREAD_CLUSTER_LEVEL2;
737 int dy = (row - 1) % KSPREAD_CLUSTER_LEVEL2;
741 if ( m_cluster[ cy * KSPREAD_CLUSTER_LEVEL1 + cx ] != NULL )
746 if ( m_cluster[ cy*KSPREAD_CLUSTER_LEVEL1 + cx]
747 [ dy*KSPREAD_CLUSTER_LEVEL2 + dx] != NULL )
749 return m_cluster[ cy*KSPREAD_CLUSTER_LEVEL1 + cx ]
750 [ dy*KSPREAD_CLUSTER_LEVEL2 + dx];
756 dy = KSPREAD_CLUSTER_LEVEL2 - 1;
763 int cx = col / KSPREAD_CLUSTER_LEVEL2;
764 int cy = (row + 1) / KSPREAD_CLUSTER_LEVEL2;
765 int dx = col % KSPREAD_CLUSTER_LEVEL2;
766 int dy = (row + 1) % KSPREAD_CLUSTER_LEVEL2;
768 while (cy < KSPREAD_CLUSTER_LEVEL1)
770 if ( m_cluster[ cy * KSPREAD_CLUSTER_LEVEL1 + cx ] != NULL )
772 while (dy < KSPREAD_CLUSTER_LEVEL2)
775 if ( m_cluster[ cy*KSPREAD_CLUSTER_LEVEL1 + cx]
776 [ dy*KSPREAD_CLUSTER_LEVEL2 + dx] != NULL )
778 return m_cluster[ cy*KSPREAD_CLUSTER_LEVEL1 + cx ]
779 [ dy*KSPREAD_CLUSTER_LEVEL2 + dx];
792 int cx = (col - 1) / KSPREAD_CLUSTER_LEVEL2;
793 int cy = row / KSPREAD_CLUSTER_LEVEL2;
794 int dx = (col - 1) % KSPREAD_CLUSTER_LEVEL2;
795 int dy = row % KSPREAD_CLUSTER_LEVEL2;
799 if ( m_cluster[ cy * KSPREAD_CLUSTER_LEVEL1 + cx ] != NULL )
804 if ( m_cluster[ cy*KSPREAD_CLUSTER_LEVEL1 + cx]
805 [ dy*KSPREAD_CLUSTER_LEVEL2 + dx] != NULL )
807 return m_cluster[ cy*KSPREAD_CLUSTER_LEVEL1 + cx ]
808 [ dy*KSPREAD_CLUSTER_LEVEL2 + dx];
814 dx = KSPREAD_CLUSTER_LEVEL2 - 1;
821 int cx = (col + 1) / KSPREAD_CLUSTER_LEVEL2;
822 int cy = row / KSPREAD_CLUSTER_LEVEL2;
823 int dx = (col + 1) % KSPREAD_CLUSTER_LEVEL2;
824 int dy = row % KSPREAD_CLUSTER_LEVEL2;
826 while (cx < KSPREAD_CLUSTER_LEVEL1)
828 if ( m_cluster[ cy * KSPREAD_CLUSTER_LEVEL1 + cx ] != NULL )
830 while (dx < KSPREAD_CLUSTER_LEVEL2)
833 if ( m_cluster[ cy*KSPREAD_CLUSTER_LEVEL1 + cx]
834 [ dy*KSPREAD_CLUSTER_LEVEL2 + dx] != NULL )
836 return m_cluster[ cy*KSPREAD_CLUSTER_LEVEL1 + cx ]
837 [ dy*KSPREAD_CLUSTER_LEVEL2 + dx];
854ColumnCluster::ColumnCluster()
855 : m_first( 0 ), m_autoDelete( false )
857 m_cluster = (ColumnFormat***)malloc( KSPREAD_CLUSTER_LEVEL1 *
sizeof( ColumnFormat** ) );
859 for(
int x = 0; x < KSPREAD_CLUSTER_LEVEL1; ++x )
863ColumnCluster::~ColumnCluster()
865 for(
int x = 0; x < KSPREAD_CLUSTER_LEVEL1; ++x )
867 ColumnFormat** cl = m_cluster[ x ];
877 ColumnFormat* cell = m_first;
880 ColumnFormat* n = cell->next();
890ColumnFormat* ColumnCluster::lookup(
int col )
892 if ( col >= KSPREAD_CLUSTER_MAX || col < 0 )
894 kdDebug(36001) <<
"ColumnCluster::lookup: invalid column value (col: "
895 << col <<
")" << endl;
899 int cx = col / KSPREAD_CLUSTER_LEVEL2;
900 int dx = col % KSPREAD_CLUSTER_LEVEL2;
902 ColumnFormat** cl = m_cluster[ cx ];
909const ColumnFormat* ColumnCluster::lookup(
int col )
const
911 if ( col >= KSPREAD_CLUSTER_MAX || col < 0 )
913 kdDebug(36001) <<
"ColumnCluster::lookup: invalid column value (col: "
914 << col <<
")" << endl;
918 int cx = col / KSPREAD_CLUSTER_LEVEL2;
919 int dx = col % KSPREAD_CLUSTER_LEVEL2;
921 ColumnFormat** cl = m_cluster[ cx ];
928void ColumnCluster::clear()
930 for(
int x = 0; x < KSPREAD_CLUSTER_LEVEL1; ++x )
932 ColumnFormat** cl = m_cluster[ x ];
942 ColumnFormat* cell = m_first;
945 ColumnFormat* n = cell->next();
954void ColumnCluster::insertElement( ColumnFormat* lay,
int col )
956 if ( col >= KSPREAD_CLUSTER_MAX || col < 0 )
958 kdDebug(36001) <<
"ColumnCluster::insertElement: invalid column value (col: "
959 << col <<
")" << endl;
963 int cx = col / KSPREAD_CLUSTER_LEVEL2;
964 int dx = col % KSPREAD_CLUSTER_LEVEL2;
966 ColumnFormat** cl = m_cluster[ cx ];
969 cl = (ColumnFormat**)malloc( KSPREAD_CLUSTER_LEVEL2 *
sizeof( ColumnFormat* ) );
970 m_cluster[ cx ] = cl;
972 for(
int a = 0; a < KSPREAD_CLUSTER_LEVEL2; ++a )
977 removeElement( col );
983 lay->setNext( m_first );
984 m_first->setPrevious( lay );
989void ColumnCluster::removeElement(
int col )
991 if ( col >= KSPREAD_CLUSTER_MAX || col < 0 )
993 kdDebug(36001) <<
"ColumnCluster::removeElement: invalid column value (col: "
994 << col <<
")" << endl;
998 int cx = col / KSPREAD_CLUSTER_LEVEL2;
999 int dx = col % KSPREAD_CLUSTER_LEVEL2;
1001 ColumnFormat** cl = m_cluster[ cx ];
1005 ColumnFormat* c = cl[ dx ];
1014 m_first = c->next();
1020 m_first = c->next();
1021 if ( c->previous() )
1022 c->previous()->setNext( c->next() );
1024 c->next()->setPrevious( c->previous() );
1026 c->setPrevious( 0 );
1030bool ColumnCluster::insertColumn(
int col )
1032 if ( col >= KSPREAD_CLUSTER_MAX || col < 0 )
1034 kdDebug(36001) <<
"ColumnCluster::insertColumn: invalid column value (col: "
1035 << col <<
")" << endl;
1039 int cx = col / KSPREAD_CLUSTER_LEVEL2;
1040 int dx = col % KSPREAD_CLUSTER_LEVEL2;
1044 ColumnFormat** cl = m_cluster[ KSPREAD_CLUSTER_LEVEL1 - 1 ];
1045 if ( cl && cl[ KSPREAD_CLUSTER_LEVEL2 - 1 ] )
1048 bool a = autoDelete();
1049 setAutoDelete(
false );
1051 for(
int i = KSPREAD_CLUSTER_LEVEL1 - 1; i >= cx ; --i )
1053 ColumnFormat** cl = m_cluster[ i ];
1059 int right = KSPREAD_CLUSTER_LEVEL2 - 1;
1060 if ( i == KSPREAD_CLUSTER_LEVEL1 - 1 )
1061 right = KSPREAD_CLUSTER_LEVEL2 - 2;
1062 for(
int k = right; k >= left; --k )
1064 ColumnFormat* c = cl[ k ];
1067 removeElement( c->column() );
1068 c->setColumn( c->column() + 1 );
1069 insertElement( c, c->column() );
1080bool ColumnCluster::removeColumn(
int column )
1082 if ( column >= KSPREAD_CLUSTER_MAX || column < 0 )
1084 kdDebug(36001) <<
"ColumnCluster::removeColumn: invalid column value (col: "
1085 << column <<
")" << endl;
1089 int cx = column / KSPREAD_CLUSTER_LEVEL2;
1090 int dx = column % KSPREAD_CLUSTER_LEVEL2;
1092 removeElement( column );
1094 bool a = autoDelete();
1095 setAutoDelete(
false );
1097 for(
int i = cx; i < KSPREAD_CLUSTER_LEVEL1; ++i )
1099 ColumnFormat** cl = m_cluster[ i ];
1105 int right = KSPREAD_CLUSTER_LEVEL2 - 1;
1106 for(
int k = left; k <= right; ++k )
1108 ColumnFormat* c = cl[ k ];
1111 removeElement( c->column() );
1112 c->setColumn( c->column() - 1 );
1113 insertElement( c, c->column() );
1124void ColumnCluster::setAutoDelete(
bool a )
1129bool ColumnCluster::autoDelete()
const
1131 return m_autoDelete;
1134ColumnFormat* ColumnCluster::next(
int col )
const
1136 if ( col >= KSPREAD_CLUSTER_MAX || col < 0 )
1138 kdDebug(36001) <<
"ColumnCluster::next: invalid column value (col: "
1139 << col <<
")" << endl;
1143 int cx = (col + 1) / KSPREAD_CLUSTER_LEVEL2;
1144 int dx = (col + 1) % KSPREAD_CLUSTER_LEVEL2;
1146 while ( cx < KSPREAD_CLUSTER_LEVEL1 )
1148 if ( m_cluster[ cx ] )
1150 while ( dx < KSPREAD_CLUSTER_LEVEL2 )
1153 if ( m_cluster[ cx ][ dx ] )
1155 return m_cluster[ cx ][ dx ];
1172RowCluster::RowCluster()
1173 : m_first( 0 ), m_autoDelete( false )
1175 m_cluster = (RowFormat***)malloc( KSPREAD_CLUSTER_LEVEL1 *
sizeof( RowFormat** ) );
1177 for(
int x = 0; x < KSPREAD_CLUSTER_LEVEL1; ++x )
1181RowCluster::~RowCluster()
1183 for(
int x = 0; x < KSPREAD_CLUSTER_LEVEL1; ++x )
1185 RowFormat** cl = m_cluster[ x ];
1195 RowFormat* cell = m_first;
1198 RowFormat* n = cell->next();
1207const RowFormat* RowCluster::lookup(
int row )
const
1209 if ( row >= KSPREAD_CLUSTER_MAX || row < 0 )
1211 kdDebug(36001) <<
"RowCluster::lookup: invalid row value (row: "
1212 << row <<
")" << endl;
1216 int cx = row / KSPREAD_CLUSTER_LEVEL2;
1217 int dx = row % KSPREAD_CLUSTER_LEVEL2;
1219 RowFormat** cl = m_cluster[ cx ];
1226RowFormat* RowCluster::lookup(
int row )
1228 if ( row >= KSPREAD_CLUSTER_MAX || row < 0 )
1230 kdDebug(36001) <<
"RowCluster::lookup: invalid row value (row: "
1231 << row <<
")" << endl;
1235 int cx = row / KSPREAD_CLUSTER_LEVEL2;
1236 int dx = row % KSPREAD_CLUSTER_LEVEL2;
1238 RowFormat** cl = m_cluster[ cx ];
1245void RowCluster::clear()
1247 for(
int x = 0; x < KSPREAD_CLUSTER_LEVEL1; ++x )
1249 RowFormat** cl = m_cluster[ x ];
1259 RowFormat* cell = m_first;
1262 RowFormat* n = cell->next();
1271void RowCluster::insertElement( RowFormat* lay,
int row )
1273 if ( row >= KSPREAD_CLUSTER_MAX || row < 0 )
1275 kdDebug(36001) <<
"RowCluster::insertElement: invalid row value (row: "
1276 << row <<
")" << endl;
1280 int cx = row / KSPREAD_CLUSTER_LEVEL2;
1281 int dx = row % KSPREAD_CLUSTER_LEVEL2;
1283 RowFormat** cl = m_cluster[ cx ];
1286 cl = (RowFormat**)malloc( KSPREAD_CLUSTER_LEVEL2 *
sizeof( RowFormat* ) );
1287 m_cluster[ cx ] = cl;
1289 for(
int a = 0; a < KSPREAD_CLUSTER_LEVEL2; ++a )
1294 removeElement( row );
1300 lay->setNext( m_first );
1301 m_first->setPrevious( lay );
1306void RowCluster::removeElement(
int row )
1308 if ( row >= KSPREAD_CLUSTER_MAX || row < 0 )
1310 kdDebug(36001) <<
"RowCluster::removeElement: invalid row value (row: "
1311 << row <<
")" << endl;
1315 int cx = row / KSPREAD_CLUSTER_LEVEL2;
1316 int dx = row % KSPREAD_CLUSTER_LEVEL2;
1318 RowFormat** cl = m_cluster[ cx ];
1322 RowFormat* c = cl[ dx ];
1331 m_first = c->next();
1337 m_first = c->next();
1338 if ( c->previous() )
1339 c->previous()->setNext( c->next() );
1341 c->next()->setPrevious( c->previous() );
1343 c->setPrevious( 0 );
1347bool RowCluster::insertRow(
int row )
1349 if ( row >= KSPREAD_CLUSTER_MAX || row < 0 )
1351 kdDebug(36001) <<
"RowCluster::insertRow: invalid row value (row: "
1352 << row <<
")" << endl;
1356 int cx = row / KSPREAD_CLUSTER_LEVEL2;
1357 int dx = row % KSPREAD_CLUSTER_LEVEL2;
1361 RowFormat** cl = m_cluster[ KSPREAD_CLUSTER_LEVEL1 - 1 ];
1362 if ( cl && cl[ KSPREAD_CLUSTER_LEVEL2 - 1 ] )
1365 bool a = autoDelete();
1366 setAutoDelete(
false );
1368 for(
int i = KSPREAD_CLUSTER_LEVEL1 - 1; i >= cx ; --i )
1370 RowFormat** cl = m_cluster[ i ];
1376 int right = KSPREAD_CLUSTER_LEVEL2 - 1;
1377 if ( i == KSPREAD_CLUSTER_LEVEL1 - 1 )
1378 right = KSPREAD_CLUSTER_LEVEL2 - 2;
1379 for(
int k = right; k >= left; --k )
1381 RowFormat* c = cl[ k ];
1384 removeElement( c->row() );
1385 c->setRow( c->row() + 1 );
1386 insertElement( c, c->row() );
1397bool RowCluster::removeRow(
int row )
1399 if ( row >= KSPREAD_CLUSTER_MAX || row < 0 )
1401 kdDebug(36001) <<
"RowCluster::removeRow: invalid row value (row: "
1402 << row <<
")" << endl;
1406 int cx = row / KSPREAD_CLUSTER_LEVEL2;
1407 int dx = row % KSPREAD_CLUSTER_LEVEL2;
1409 removeElement( row );
1411 bool a = autoDelete();
1412 setAutoDelete(
false );
1414 for(
int i = cx; i < KSPREAD_CLUSTER_LEVEL1; ++i )
1416 RowFormat** cl = m_cluster[ i ];
1422 int right = KSPREAD_CLUSTER_LEVEL2 - 1;
1423 for(
int k = left; k <= right; ++k )
1425 RowFormat* c = cl[ k ];
1428 removeElement( c->row() );
1429 c->setRow( c->row() - 1 );
1430 insertElement( c, c->row() );
1441void RowCluster::setAutoDelete(
bool a )
1446bool RowCluster::autoDelete()
const
1448 return m_autoDelete;
For every cell in the spread sheet there is a Cell object.
int row() const
Returns the cell's row.
const Value value() const
Returns the value that this cell holds.
bool doesMergeCells() const
int column() const
Returns the cell's column.
void move(int column, int row)
Moves around the cell.
void mergeCells(int _col, int _row, int _x, int _y)
Merge a number of cells, i.e.
Cell * getNextCellDown(int col, int row) const
Retrieves the next used cell below the given col/row pair.
Cell * getNextCellRight(int col, int row) const
Retrieves the next used cell to the right of the given col/row pair.
Cell * getNextCellLeft(int col, int row) const
Retrieves the next used cell to the left of the given col/row pair.
Cell * getLastCellRow(int row) const
Retrieve the last used cell in a given row.
Cell * getFirstCellRow(int row) const
Retrieve the first used cell in a given row.
void remove(int x, int y)
Removes the cell at the given position, if there is any.
void clear()
Removes all cells from the sheet and frees memory that was used for the clusters.
void clearColumn(int col)
Removes all elements from the column.
bool shiftColumn(const TQPoint &marker)
Moves all cells in the column marker.x() beginning with the one at marker.y() one position downwards.
Cell * getNextCellUp(int col, int row) const
Retrieves the next used cell above the given col/row pair.
void unshiftColumn(const TQPoint &marker)
Moves all cells in the column marker.x() beginning with the one at marker.y() + 1 one position upward...
Cell * getLastCellColumn(int col) const
Retrieve the last used cell in a given column.
Cell * getFirstCellColumn(int col) const
Retrieve the first used cell in a given column.
bool insertColumn(int col)
Moves all columns beginning with col one position to the right.
Value valueRange(int col1, int row1, int col2, int row2) const
Retrieve a range of values stored in a Value.
void removeColumn(int col)
Removes all elements from the column and move all columns right of col one position to the left.
void insert(Cell *cell, int x, int y)
Inserts a cell at the requested position.
Provides a wrapper for cell value.
void setElement(unsigned column, unsigned row, const Value &value)
Sets an element in the array value.