28#include "KWTableFrameSet.h"
29#include "KWDocument.h"
33#include "KWViewMode.h"
35#include "KWordFrameSetIface.h"
36#include "KWordTableFrameSetIface.h"
37#include "KWFrameList.h"
38#include "KWPageManager.h"
40#include "KWOasisSaver.h"
42#include <KoOasisContext.h>
43#include <KoXmlWriter.h>
46#include <KoTextObject.h>
47#include <KoTextParag.h>
49#include <tdemessagebox.h>
52#include <dcopobject.h>
53#include <tqapplication.h>
54#include <tqpopupmenu.h>
55#include <tqclipboard.h>
61 m_rows = m_cols = m_nr_cells = 0;
64 m_frames.setAutoDelete(
false);
66 m_name = doc->generateFramesetName( i18n(
"Table %1" ) );
76KWordFrameSetIface* KWTableFrameSet::dcopObject()
79 m_dcop =
new KWordTableFrameSetIface(
this );
92 for(TableIter c(
this); c; ++c)
93 c.current()->updateFrames( flags );
107 double dx = position.x() - m_colPositions[0];
108 double dy = position.y() - m_rowPositions[0];
112 if (! daCell)
return;
120 cell(0,0)->frame(0)->frameStack()->updateAfterMove( oldPageNumber );
142 return new KWAnchor( txt,
this, frameNum );
145void KWTableFrameSet::createAnchors( KoTextParag * parag,
int index,
bool placeHolderExists ,
152 if ( !placeHolderExists )
153 parag->insert( index, KoTextObject::customItemChar() );
154 parag->setCustomItem( index, anchor, 0 );
155 kdDebug(32004) <<
"KWTableFrameSet::createAnchors setting anchor" << endl;
156 parag->setChanged(
true );
161void KWTableFrameSet::deleteAnchors()
164 kdDebug(32004) <<
"KWTableFrameSet::deleteAnchors anchor=" << anchor << endl;
165 deleteAnchor( anchor );
171 m_rows = kMax( daCell->rowAfter(), m_rows );
172 m_cols = kMax( daCell->columnAfter(), m_cols );
174 if ( m_rowArray.size() < daCell->rowAfter() )
175 m_rowArray.resize( daCell->rowAfter() );
176 for ( uint row = daCell->firstRow() ;row < daCell->rowAfter(); ++row )
178 if ( !m_rowArray[ row ] )
179 m_rowArray.insert( row,
new Row );
180 m_rowArray[ row ]->addCell( daCell );
186 for ( uint row = daCell->firstRow() ; row < daCell->rowAfter(); ++row )
190void KWTableFrameSet::insertRowVector(uint index, Row *r)
192 if(m_rowArray.size() < m_rowArray.count() + 1)
193 m_rowArray.resize(m_rowArray.count() + 1);
195 for(uint i = m_rowArray.count(); i > index; i--)
196 m_rowArray.insert(i, m_rowArray[i-1]);
198 m_rowArray.insert(index, r);
205void KWTableFrameSet::insertEmptyColumn(uint index)
207 for(uint i = 0; i < m_rowArray.count(); ++i) {
208 Row *r = m_rowArray[i];
209 if(r->m_cellArray.size() < m_cols + 1)
211 for(
int j = m_cols - 1; j >= (int)index; --j)
212 r->m_cellArray.insert(j + 1, r->m_cellArray[j]);
213 r->m_cellArray.insert(index, 0);
218KWTableFrameSet::removeRowVector(uint index)
220 Q_ASSERT(index < m_rowArray.count() );
221 Row *ret = m_rowArray.at(index);
223 for(uint i = index; i < m_rowArray.size() - 1; ++i){
224 r = m_rowArray.at(i+1);
225 m_rowArray.remove(i+1);
226 m_rowArray.insert(i,r);
233 KoRect outerRect(m_colPositions[0],
235 m_colPositions.last()-m_colPositions[0],
236 m_rowPositions.last()-m_rowPositions[0]);
244 outerRect.rRight() += m_doc->zoomItX( 1 ) / m_doc->zoomedResolutionX();
245 outerRect.rBottom() += m_doc->zoomItY( 1 ) / m_doc->zoomedResolutionY();
257 top = kMax( top, m_rowPositions[0] + daCell->topBorder() );
266 for (uint i=0; i <
getRows(); i++)
269 left = kMax( left, m_colPositions[0] + daCell->leftBorder() );
277 if ( row < m_rowArray.size() && col < m_rowArray[row]->size() ) {
278 Cell* cell = (*m_rowArray[row])[col];
293 if(f)
return static_cast<KWTableFrameSet::Cell *
> (f->
frameSet());
302 Cell *activeCell = cell(row,col);
303 Q_ASSERT( activeCell );
306 double difference = 0;
308 if(activeCell->
frame(0)->left() - activeCell->leftBorder() != m_colPositions[activeCell->firstColumn()]) {
310 col = activeCell->firstRow();
311 difference = 0-(activeCell->
frame(0)->left() - activeCell->leftBorder() - m_colPositions[activeCell->firstColumn()]);
314 if(activeCell->
frame(0)->right() - activeCell->rightBorder() !=
315 m_colPositions[activeCell->lastColumn()]) {
317 col = activeCell->columnAfter();
318 double difference2 = activeCell->
frame(0)->right() + activeCell->rightBorder() - m_colPositions[activeCell->columnAfter()];
320 double moved=difference2+difference;
321 if(moved > -0.01 && moved < 0.01) {
323 difference = difference2;
324 }
else if(difference2!=0)
325 difference = difference2;
330 double last=col==0?0:m_colPositions[col-1];
331 for(
unsigned int i=col; i < m_colPositions.count(); i++) {
332 double &colPos = m_colPositions[i];
333 colPos = colPos + difference;
334 if(colPos-last < s_minFrameWidth) {
335 difference += s_minFrameWidth - colPos;
336 colPos = s_minFrameWidth + last;
341 if(col>0) m_redrawFromCol--;
352void KWTableFrameSet::recalcRows(
unsigned int col,
unsigned int row) {
353 kdDebug(32004) <<
name() <<
" KWTableFrameSet::recalcRows ("<< col <<
"," << row <<
")" << endl;
356 Cell *activeCell = cell(row,col);
357 Q_ASSERT( activeCell );
360 double difference = 0;
362 if(activeCell->frame(0)->height() != activeCell->frame(0)->minimumFrameHeight() &&
363 activeCell->type() == FT_TEXT) {
369 double minHeightOtherCols=0;
370 double minHeightActiveRow=0;
371 double minHeightMyCol=0;
372 unsigned int rowSpan = activeCell->rowSpan();
373 unsigned int startRow = activeCell->firstRow();
374 for (uint colCount = 0; colCount <
getColumns(); ++colCount )
377 unsigned int rowCount=startRow;
378 double thisColHeight=0;
379 double thisColActiveRow=0;
382 Cell *thisCell=cell(rowCount,colCount);
385 if(thisCell->firstRow() < startRow) {
386 rowSpan += startRow - thisCell->firstRow();
387 startRow = thisCell->firstRow();
390 if(thisCell->rowAfter() > startRow + rowSpan) {
391 rowSpan = thisCell->rowAfter() - startRow;
395 thisColHeight+=thisCell->frame(0)->minimumFrameHeight();
396 thisColHeight+=thisCell->topBorder();
397 thisColHeight+=thisCell->bottomBorder();
399 if(thisCell->firstRow() >= activeCell->firstRow() && thisCell->rowAfter() <= activeCell->rowAfter())
400 thisColActiveRow+=thisCell->frame(0)->minimumFrameHeight();
402 rowCount += thisCell->rowSpan();
403 }
while (rowCount < rowSpan+startRow);
405 if(colCount >= activeCell->firstColumn() &&
406 colCount < activeCell->columnAfter() )
407 minHeightMyCol = thisColHeight;
409 minHeightOtherCols = kMax(minHeightOtherCols, thisColHeight);
410 minHeightActiveRow = kMax(minHeightActiveRow, thisColActiveRow);
414 bool bottomRow = (startRow+rowSpan == activeCell->rowAfter());
416 Cell *bottomCell=cell(startRow+rowSpan-1, activeCell->firstColumn());
417 bottomCell->frame(0)->setHeight(bottomCell->frame(0)->minimumFrameHeight() +
418 minHeightOtherCols - minHeightMyCol);
420 recalcRows(bottomCell->firstColumn(), bottomCell->firstRow());
422 if(activeCell->frame(0)->minimumFrameHeight() > activeCell->frame(0)->height()) {
423 activeCell->frame(0)->setHeight(activeCell->frame(0)->minimumFrameHeight());
426 double newHeight=kMax(activeCell->frame(0)->minimumFrameHeight(),minHeightActiveRow);
428 newHeight=kMax(newHeight, minHeightOtherCols - (minHeightMyCol - activeCell->frame(0)->minimumFrameHeight()));
429 activeCell->frame(0)->setHeight(newHeight);
434 if(activeCell->frame(0)->top() - activeCell->topBorder() != getPositionOfRow(activeCell->firstRow())) {
436 row = activeCell->firstRow();
437 difference = 0 - (activeCell->frame(0)->top() - activeCell->topBorder() - getPositionOfRow(row));
441 if(activeCell->frame(0)->bottom() + activeCell->bottomBorder() !=
442 getPositionOfRow(activeCell->rowAfter())) {
444 row = activeCell->rowAfter();
445 double difference2 = activeCell->frame(0)->bottom() + activeCell->bottomBorder() - getPositionOfRow(row);
446 double moved=difference2+difference;
447 if(moved > -0.01 && moved < 0.01) {
449 difference = difference2;
450 }
else if( difference2!=0)
451 difference = difference2;
454 unsigned int fromRow = m_rows;
455 unsigned int untilRow=0;
456 if( TQABS( difference ) > 1E-10 ) {
457 TQValueList<unsigned int>::iterator pageBound = m_pageBoundaries.begin();
458 TQValueList<double>::iterator j = m_rowPositions.begin();
461 while(j != m_rowPositions.end()) {
463 if(pageBound!=m_pageBoundaries.end()) {
464 if((
int)*pageBound == lineNumber) {
465 if(lineNumber >= (
int)row) {
466 TQValueList<double>::iterator nextJ = j;
468 difference -= *(nextJ)-*(j);
469 kdDebug(32004) <<
"Deleting line with old pos: " << *j << endl;
470 j=m_rowPositions.remove(j);
472 TQValueList<unsigned int>::iterator tmp = pageBound;
474 m_pageBoundaries.remove(tmp);
482 if(lineNumber >= (
int)row) {
483 if(*(j)-last < s_minFrameHeight)
484 difference += s_minFrameHeight - *(j) + last;
486 kdDebug(32004) <<
"moving " << *(j) <<
" by " << difference <<
"; to " << (*j) + difference << endl;
497{ TQValueList<unsigned int>::iterator pb = m_pageBoundaries.begin();
501 double cur=m_rowPositions[i];
502 if(pb!=m_pageBoundaries.end() && *(pb)==i) {
503 kdDebug(32004) <<
"line: " << i <<
": " << cur <<
" *" << (last>cur?
" (ALERT)":
"") << endl;
506 kdDebug(32004) <<
"line: " << i <<
": " << cur << (last>cur?
" (ALERT)":
"") << endl;
509 }
while( i<m_rowPositions.count());
515 unsigned int pageNumber=cell(0,0)->frame(0)->pageNumber() +1;
516 unsigned int lineNumber=1;
517 TQValueList<unsigned int>::iterator pageBound = m_pageBoundaries.begin();
518 TQValueList<double>::iterator j = m_rowPositions.begin();
521 double pageBottom = pageNumber * m_doc->ptPaperHeight() - m_doc->ptBottomBorder();
523 while(++j!=m_rowPositions.end()) {
524 if(pageBound!=m_pageBoundaries.end() && *pageBound == lineNumber ) {
525 if(*j > pageNumber * m_doc->ptPaperHeight() - m_doc->ptBottomBorder() ) {
527 pageBottom = pageNumber * m_doc->ptPaperHeight() - m_doc->ptBottomBorder();
529 untilRow=kMax(untilRow, *pageBound);
535 if((*j) + diff > pageBottom) {
538 bool hugeRow =
false;
539 unsigned int breakRow = lineNumber-1;
544 kdDebug() <<
"i: " << i<< endl;
545 Cell *c= cell(breakRow, i);
546 kdDebug() <<
"c: " << c->firstRow() <<
"," << c->m_col <<
" w: " << c->columnSpan() <<
", h: " << c->rowSpan() << endl;
547 if(c->firstRow() < breakRow) {
548 breakRow = c->firstRow();
552 kdDebug() <<
"breakRow: " << breakRow<< endl;
553 fromRow=kMin(fromRow, breakRow);
554 if(breakRow < lineNumber+1) {
555 for(
unsigned int i=lineNumber+1; i > breakRow;i--)
557 for(
unsigned int i=lineNumber+1; i > breakRow;i--)
559 lineNumber=breakRow+1;
563 for(
unsigned int i=0; i <
getColumns() ; i++) {
564 if(cell(breakRow+1,i) && cell(breakRow+1,i)->
frame(0)->height() > pageHeight)
571 double topOfPage = m_doc->ptPaperHeight() * pageNumber + m_doc->ptTopBorder();
573 TQValueList<double>::iterator tmp = m_rowPositions.at(breakRow);
574 diff += topOfPage - (*tmp);
577 m_rowPositions.insert(j, topOfPage);
580 pageBound = m_pageBoundaries.insert(pageBound, breakRow);
590 pageBottom = pageNumber * m_doc->ptPaperHeight() - m_doc->ptBottomBorder();
592 if((
int)pageNumber > m_doc->numPages()) {
593 int num = m_doc->appendPage();
594 kdDebug(32004) <<
"Have appended page: " << num <<
" (one page mode!)" << endl;
595 m_doc->afterInsertPage( num );
606 for ( TQValueList<double>::iterator itDebug = m_rowPositions.begin(); itDebug != m_rowPositions.end(); ++itDebug, ++i )
608 kdDebug(32004) <<
"m_rowPosition[" << i <<
"]= " << (*itDebug) << endl;
615{ TQValueList<unsigned int>::iterator pb = m_pageBoundaries.begin();
619 double cur=m_rowPositions[i];
620 if(pb!=m_pageBoundaries.end() && *(pb)==i) {
621 kdDebug(32004) <<
"line: " << i <<
": " << cur <<
" *" << (last>cur?
" (ALERT)":
"") << endl;
624 kdDebug(32004) <<
"line: " << i <<
": " << cur << (last>cur?
" (ALERT)":
"") << endl;
627 }
while( i<m_rowPositions.count());
638 for(TableIter cell(
this); cell; ++cell) {
639 if((cell->rowAfter() > fromRow && cell->firstRow() < untilRow) || cell->columnAfter() > m_redrawFromCol)
640 position(cell, (cell==activeCell && cell->frame(0)->isSelected()));
647 TQMap<unsigned int,int> rows;
648 unsigned int top=m_rowPositions.count() - m_pageBoundaries.count()-1;
649 for(
unsigned int i=0; i < top; rows[i++]=0);
652 for(TableIter i(
this); i; ++i) {
653 rows[i->firstRow()] += 1;
656 unsigned int counter=top;
657 int adjustment=m_pageBoundaries.count()-1;
661 if(adjustment >= 0 && counter == m_pageBoundaries[adjustment])
663 if(rows[counter]==0) {
664 kdDebug() << k_funcinfo <<
"no rows at counter=" << counter <<
" -> erasing" << endl;
666 m_rowPositions.erase(m_rowPositions.at(counter+(adjustment>0?adjustment:0)));
667 for (TableIter cell(
this); cell; ++cell) {
668 if(cell->firstRow() < counter && cell->rowAfter() > counter)
669 cell->setRowSpan(cell->rowSpan()-1);
670 if(cell->firstRow() > counter)
671 cell->setFirstRow(cell->firstRow()-1);
674 if(adjustment >= -1) {
675 pageBound = m_pageBoundaries.at(adjustment+1);
676 while(pageBound!=m_pageBoundaries.end()) {
677 (*pageBound)= (*pageBound)-1;
687 for (TableIter cell(
this); cell; ++cell) {
688 if((cell->rowAfter() > fromRow && cell->firstRow() < untilRow)
689 || cell->columnAfter() > m_redrawFromCol)
693 kdDebug(32004) <<
name() <<
" KWTableFrameSet::recalcRows done" << endl;
702 double lastMiddlePos = 0;
703 for ( uint i = 0; i < m_colPositions.count() - 1; i++ ) {
704 double middlePos = ( m_colPositions[i] + m_colPositions[i+1] ) / 2;
705 Q_ASSERT( lastMiddlePos < middlePos );
706 if ( x > lastMiddlePos && x <= middlePos )
708 lastMiddlePos = middlePos;
710 return m_colPositions.count() - 1;
715 double lastMiddlePos = 0;
716 for ( uint i = 0; i < m_rowPositions.count() - 1; i++ ) {
717 double middlePos = ( m_rowPositions[i] + m_rowPositions[i+1] ) / 2;
718 Q_ASSERT( lastMiddlePos < middlePos );
719 if ( y > lastMiddlePos && y <= middlePos )
721 lastMiddlePos = middlePos;
723 return m_rowPositions.count() - 1;
726double KWTableFrameSet::columnSize(
unsigned int col )
728 return m_colPositions[ col ];
731double KWTableFrameSet::rowSize(
unsigned int row )
733 return m_rowPositions[ row ];
738 kdDebug() << k_funcinfo << col <<
"," << x << endl;
739 if ((col != 0) && (x - m_colPositions[ col-1 ] < s_minFrameWidth))
740 m_colPositions[ col ] = m_colPositions[ col-1 ] + s_minFrameWidth;
742 if ((col !=
getColumns()) && (m_colPositions[ col + 1 ] - x < s_minFrameWidth))
743 m_colPositions[col] = m_colPositions[ col + 1 ] - s_minFrameWidth;
745 m_colPositions[ col ] = x;
748 for (TableIter cell(
this); cell; ++cell) {
749 if ( cell->columnAfter() >= col ) {
758 kdDebug() << k_funcinfo << row <<
"," << y << endl;
759 double difference = m_rowPositions[row];
760 if ((row != 0) && (y - m_rowPositions[ row-1 ] < s_minFrameHeight))
761 m_rowPositions[ row ] = m_rowPositions[ row-1 ] + s_minFrameHeight;
763 if ((row !=
getRows()) && (m_rowPositions[ row + 1 ] - y < s_minFrameHeight))
764 m_rowPositions[row] = m_rowPositions[ row + 1 ] - s_minFrameHeight;
766 m_rowPositions[ row ] = y;
767 difference = m_rowPositions[row] - difference;
771 for (
unsigned int i=row+1; i<=
getRows(); i++)
772 m_rowPositions[i] = m_rowPositions[i] + difference;
775 for (TableIter cell(
this); cell; ++cell) {
776 if ( cell->rowAfter() >= row ) {
780 recalcRows( 0, row-1 );
784 Q_ASSERT(width != 0);
786 kdDebug() <<
"bounding width before resize " <<
boundingRect().width() << endl;
792 double moveOffset = m_colPositions[0] * growth - m_colPositions[0];
794 for (uint i=0; i<m_colPositions.count(); i++) {
795 m_colPositions[i] = m_colPositions[i] * growth - moveOffset;
798 kdDebug() <<
"bounding width after resize" <<
boundingRect().width() << endl;
804 m_colPositions.clear();
806 for (TableIter c(
this); c; ++c)
807 cols = kMax(cols, c.current()->columnAfter());
808 double colWidth = rect.width() / cols;
809 if ( widthMode == TblAuto ) {
810 KWPage *page = pageManager()->page(rect);
815 for(
unsigned int i=0; i <= cols;i++) {
816 m_colPositions.append(rect.x() + colWidth * i);
820 m_rowPositions.clear();
821 m_pageBoundaries.clear();
822 double rowHeight = 0;
823 if( heightMode != TblAuto )
824 rowHeight = rect.height() / m_rows;
825 rowHeight=kMax(rowHeight, 22.0);
827 for(
unsigned int i=0; i <= m_rows;i++) {
828 m_rowPositions.append(rect.y() + rowHeight * i);
831 double oneMm = MM_TO_POINT( 1.0 );
832 for (TableIter cell(
this); cell; ++cell) {
834 frame->setPaddingLeft( oneMm );
835 frame->setPaddingRight( oneMm );
836 frame->setPaddingTop( oneMm );
837 frame->setPaddingBottom( oneMm );
838 frame->setNewFrameBehavior( KWFrame::NoFollowup );
839 position(cell,
true);
843void KWTableFrameSet::position( Cell *theCell,
bool setMinFrameHeight ) {
844 if(!theCell->frame(0)) {
845 kdDebug(32004) <<
"errorous table cell!! row:" << theCell->firstRow()
846 <<
", col: " << theCell->firstColumn() << endl;
849 double x = *m_colPositions.at(theCell->firstColumn());
850 double y = getPositionOfRow(theCell->firstRow());
851 double width = (*m_colPositions.at(theCell->columnAfter())) - x;
852 double height = getPositionOfRow(theCell->lastRow(),
true) - y;
855 if(theCell->m_col==0) {
856 kdDebug(32004) <<
"row " << theCell->firstRow() <<
" has top: "
857 << y <<
", and bottom: " << y + height << endl;
862 KWFrame *theFrame = theCell->frame(0);
863 x+=theCell->leftBorder();
864 width-=theCell->leftBorder();
865 width-=theCell->rightBorder();
866 y+=theCell->topBorder();
867 height-=theCell->topBorder();
868 height-=theCell->bottomBorder();
870 theFrame->setRect( x,y,width,height);
871 if( setMinFrameHeight )
874 if(!theCell->isVisible())
875 theCell->setVisible(
true);
878double KWTableFrameSet::getPositionOfRow(
unsigned int row,
bool bottom ) {
879 unsigned int adjustment=0;
880 TQValueList<unsigned int>::iterator pageBound = m_pageBoundaries.begin();
881 while(pageBound != m_pageBoundaries.end() && (*pageBound) <= row + adjustment) {
885 if(m_rowPositions.count() < row+adjustment+(bottom?1:0))
887 return m_rowPositions[row+adjustment+(bottom?1:0)];
892 kdDebug(32004) <<
"KWTableFrameSet(" <<
name() <<
")::moveBy(" << dx<<
","<<dy<<
")\n";
894 if(!(dy > -0.001 && dy < 0.001)) {
896 TQValueList<double>::iterator row = m_rowPositions.begin();
897 while(row != m_rowPositions.end()) {
902 if(!(dx > -0.001 && dx < 0.001)) {
904 TQValueList<double>::iterator col = m_colPositions.begin();
905 while(col != m_colPositions.end()) {
912 for(TableIter cell(
this);cell;++cell)
920 Q_ASSERT(row < m_rowArray.size());
921 const unsigned int rowspan=1;
923 double height= getPositionOfRow(row+rowspan-1,
true) - getPositionOfRow(row);
924 TQValueList<double>::iterator tmp = m_rowPositions.at(row+rowspan);
925 tmp=m_rowPositions.erase(tmp);
926 while(tmp!=m_rowPositions.end()) {
927 (*tmp)= (*tmp)-height;
932 rr.m_rowHeight = height;
933 rr.m_row = m_rowArray[row];
936 for ( TableIter cell(
this); cell; ++cell ) {
937 if ( row >= cell->firstRow() && row < cell->rowAfter()) {
938 if(cell->rowSpan() == 1) {
939 m_frames.remove( cell->frame(0) );
941 cell->setRowSpan(cell->rowSpan()-rowspan);
945 }
else if ( cell->firstRow() > row ) {
947 cell->setFirstRow( cell->firstRow() - rowspan );
952 removeRowVector(row);
954 m_rowArray.resize( m_rows );
958 recalcRows( 0, row-1 );
963 uint row = rr.index();
965 uint rlen = r->count();
970 if ( cell->firstRow() < row && cell->lastRow() >= row ){
971 cell->setRowSpan(cell->rowSpan() + 1);
973 else if(r->
m_cellArray[cell->firstColumn()] == cell.current()) {
974 cell->setRowSpan(cell->rowSpan() + 1);
976 else if ( cell->firstRow() >= row ) {
978 cell->setFirstRow( cell->firstRow() + 1);
983 for(uint i = 0; i < rlen; i++){
984 if( m_frames.findRef((*r)[i]->frame(0)) == -1 )
985 m_frames.append( (*r)[i]->
frame(0) );
990 double d = m_rowPositions.last() + rr.height();
991 m_rowPositions.append(d);
994 TQValueList<double>::iterator top = m_rowPositions.at(row);
995 TQValueList<double>::iterator i = m_rowPositions.at(row+1);
996 i = m_rowPositions.insert(i, *top + rr.height());
998 for(; i != m_rowPositions.end(); ++i) {
999 *i = *i+ rr.height();
1005 insertRowVector(rr.index(), rr.takeRow());
1008 for(TableIter i(
this); i ; ++i)
1009 position(i.current());
1018 unsigned int copyFromRow = idx==0?0:idx-1;
1021 Row *copyRow = m_rowArray[copyFromRow];
1023 uint new_rows = m_rows + 1;
1025 double height = getPositionOfRow(copyFromRow,
true) - getPositionOfRow(copyFromRow);
1028 unsigned int adjustment=0;
1029 unsigned int untilRow=m_rows;
1030 TQValueList<unsigned int>::iterator pageBound = m_pageBoundaries.begin();
1031 while(pageBound != m_pageBoundaries.end() && (*pageBound) <= idx) {
1038 TQValueList<double>::iterator tmp = m_rowPositions.at(idx);
1039 double newPos = *tmp + height;
1041 m_rowPositions.insert(tmp, newPos);
1042 for(
unsigned int i=idx+adjustment+2; i < m_rowPositions.count(); i++) {
1043 double &rowPos = m_rowPositions[i];
1044 kdDebug(32004) <<
"adjusting " << rowPos <<
" -> " << rowPos + height << endl;
1045 rowPos = rowPos + height;
1046 if(*pageBound == i) {
1047 untilRow= *pageBound;
1053 if ( cells->firstRow() >= idx ) {
1054 cells->setFirstRow(cells->firstRow()+1);
1058 insertRowVector(idx,
new Row);
1063 if(idx != 0 && (idx != m_rows)) {
1064 Cell *c = cell(idx - 1, i);
1065 if( c == cell(idx + 1, i) ) {
1066 m_rowArray[idx]->addCell(c);
1067 c->setRowSpan(c->rowSpan() + 1);
1068 i += c->columnSpan();
1074 Cell *newCell=
new Cell(
this, idx, i, TQString() );
1075 newCell->setColumnSpan( cell(copyFromRow,i)->columnSpan() );
1077 newCell->addFrame( theFrame,
false );
1079 i += newCell->columnSpan();
1093 if(!rc.m_initialized) {
1095 rc.m_width = m_colPositions[col+1] - m_colPositions[col];
1099 TQValueList<double>::iterator tmp = m_colPositions.at(col+1);
1100 tmp = m_colPositions.erase(tmp);
1101 while(tmp != m_colPositions.end()) {
1102 (*tmp) = (*tmp) - rc.m_width;
1109 CheckedIter iter(
this);
1110 for(uint i = 0; i < m_rows; ++i) {
1111 Cell *daCell = cell(i, col);
1113 if(!rc.m_initialized) {
1114 rc.m_column.append(daCell);
1115 rc.m_removed.append(daCell->columnSpan() == 1);
1118 if(daCell->columnSpan() == 1) {
1119 if(daCell->firstRow() == i) {
1120 m_frames.remove( daCell->
frame(0) );
1123 m_rowArray[i]->m_cellArray.insert(col, 0);
1126 if(daCell->firstRow() == i) {
1127 daCell->setColumnSpan( daCell->columnSpan() - 1 );
1134 for(; iter; ++iter) {
1135 if (iter->firstColumn() > col ) {
1136 iter->setFirstColumn( iter->firstColumn() - 1);
1137 position(iter.current());
1143 for(uint i = 0; i < m_rows; i++) {
1144 for(uint j = col + 1; j < m_cols; j++)
1145 m_rowArray[i]->m_cellArray.insert(j-1, m_rowArray[i]->m_cellArray[j]);
1148 rc.m_initialized =
true;
1152 recalcRows( col, 0 );
1157 TQValueList<double>::iterator tmp = m_colPositions.at(rc.m_index);
1159 tmp = m_colPositions.insert(tmp, *tmp);
1161 while(tmp != m_colPositions.end()) {
1162 (*tmp) = (*tmp) + rc.m_width;
1170 if ( cells->firstColumn() >= rc.m_index &&
1171 (rc.m_column.at(cells->firstRow()) != cells.current())) {
1173 cells->setFirstColumn(cells->firstColumn() + 1);
1176 insertEmptyColumn(rc.m_index);
1179 for(uint i = 0; i < m_rows; ++i) {
1180 bool removed = rc.m_removed[i];
1181 Cell *daCell = rc.m_column.at(i);
1182 if(i == daCell->firstRow()) {
1184 daCell->setColumnSpan(1);
1185 m_frames.append(daCell->
frame(0));
1189 daCell->setColumnSpan(daCell->columnSpan() + 1);
1201 TQValueList<double>::iterator tmp = m_colPositions.at(idx);
1203 tmp = m_colPositions.insert(tmp, *tmp);
1205 while(tmp!=m_colPositions.end()) {
1206 (*tmp)= (*tmp)+width;
1211 if ( cells->firstColumn() >= idx) {
1212 cells->setFirstColumn(cells->firstColumn() + 1);
1215 insertEmptyColumn(idx);
1217 uint copyCol = (idx == 0) ? 1 : idx - 1 ;
1221 for(
unsigned int i = 0; i <
getRows(); i++ ) {
1226 if(idx != 0 && (idx != m_cols -1)) {
1227 Cell *c = cell(i, idx - 1);
1228 if( c == cell(i, idx + 1) ) {
1230 c->setColumnSpan(c->columnSpan() + 1);
1232 i += c->rowSpan() - 1;
1237 Cell *newCell =
new Cell(
this, i, idx, TQString() );
1239 newCell->addFrame( theFrame,
false );
1256void KWTableFrameSet::group()
1266 Cell *firstCell = cell(rowBegin, colBegin);
1268 if(rowBegin == rowEnd && colBegin == colEnd || cell(rowBegin,colBegin) == cell(rowEnd,colEnd))
1270 TQPtrList<KWFrameSet> listFrameSet;
1271 TQPtrList<KWFrame> listCopyFrame;
1274 for(
unsigned int i=colBegin; i<=colEnd;i++) {
1275 for(
unsigned int j=rowBegin; j<=rowEnd;j++) {
1276 Cell *daCell = cell(j,i);
1277 if(daCell && daCell!=firstCell) {
1278 listFrameSet.append(daCell);
1281 if(!
frame)
continue;
1282 listCopyFrame.append(
frame->getCopy());
1288 Q_ASSERT(firstCell);
1290 firstCell->setColumnSpan(colEnd-colBegin+1);
1291 firstCell->setRowSpan(rowEnd-rowBegin+1);
1293 position(firstCell);
1296 m_doc->updateAllFrames();
1297 m_doc->repaintAllViews();
1298 return new KWJoinCellCommand( i18n(
"Join Cells"),
this,colBegin,rowBegin, colEnd,rowEnd,listFrameSet,listCopyFrame);
1301KCommand *
KWTableFrameSet::splitCell(
unsigned int intoRows,
unsigned int intoCols,
unsigned int col,
unsigned int row, TQPtrList<KWFrameSet> listFrameSet, TQPtrList<KWFrame>listFrame) {
1302 if(intoRows < 1 || intoCols < 1)
1305 kdDebug(32004) <<
"KWTableFrameSet::splitCell" << endl;
1306 Cell *daCell=cell(row,col);
1307 int rowsDiff = intoRows - daCell->rowSpan();
1308 int colsDiff = ((int) intoCols) - daCell->columnSpan();
1311 unsigned int adjustment=0;
1312 TQValueList<unsigned int>::iterator pageBound = m_pageBoundaries.begin();
1313 while(pageBound != m_pageBoundaries.end() && (*pageBound) <= row) {
1317 double height = (m_rowPositions[row+adjustment+1] - m_rowPositions[row+adjustment])/intoRows;
1319 TQValueList<double>::iterator iRow = m_rowPositions.at(adjustment+row);
1320 for (
int i=0; i < rowsDiff; i++) {
1321 double newPos = *iRow + height;
1323 iRow=m_rowPositions.insert(iRow, newPos);
1327 for(
int i = 0; i < rowsDiff; ++i) {
1328 insertRowVector(row+i+1,
new Row);
1337 double width = (m_colPositions[col+1] - m_colPositions[col])/intoCols;
1339 TQValueList<double>::iterator iCol = m_colPositions.at(col);
1340 for (
int i=0; i < colsDiff; i++) {
1341 double newPos = *iCol + width;
1343 iCol=m_colPositions.insert(iCol, newPos);
1346 for(
int i = 0; i < colsDiff; i++) {
1347 insertEmptyColumn(col+i+1);
1356 for (CheckedIter i(
this); i ; ++i) {
1357 if(daCell == i)
continue;
1360 if(row >= i->firstRow()&& row < i->firstRow()+ i->rowSpan())
1361 i->setRowSpan(i->rowSpan() + rowsDiff);
1362 if(i->firstRow() > row) {
1363 i->setFirstRow(i->firstRow() + rowsDiff);
1368 if(col >= i->firstColumn() && col < i->columnAfter())
1369 i->setColumnSpan(i->columnSpan() + colsDiff);
1370 if(i->firstColumn() > col)
1371 i->setFirstColumn(i->firstColumn() + colsDiff);
1376 if ( rowsDiff > 0 || colsDiff > 0 )
1383 for (
unsigned int y = 0; y < intoRows; y++) {
1384 for (
unsigned int x = 0; x < intoCols; x++){
1388 Cell *lastFrameSet=0L;
1390 if(listFrameSet.isEmpty())
1391 lastFrameSet =
new Cell(
this, y + row, x + col );
1397 if(listFrame.isEmpty())
1399 theFrame=firstFrame->
getCopy();
1400 theFrame->setRunAround( KWFrame::RA_NO );
1401 theFrame->setFrameBehavior(KWFrame::AutoExtendFrame);
1402 theFrame->setNewFrameBehavior(KWFrame::NoFollowup);
1403 lastFrameSet->addFrame( theFrame,
false );
1406 lastFrameSet->addFrame( listFrame.at(i)->getCopy(),
false );
1410 if(rowsDiff <0 && y==0)
1411 lastFrameSet->setRowSpan(lastFrameSet->rowSpan() - rowsDiff);
1412 if(colsDiff <0 && x==0)
1413 lastFrameSet->setColumnSpan(lastFrameSet->columnSpan() - colsDiff);
1416 position(lastFrameSet);
1422 int r = (daCell->rowSpan() +1) - intoRows;
1424 daCell->setRowSpan(r);
1426 int c = (daCell->columnSpan() + 1) - intoCols;
1428 daCell->setColumnSpan(c);
1445 for(CheckedIter cells(
this); cells; ++cells) {
1446 if(cells->columnSpan() == 0 || cells->rowSpan() == 0) {
1447 kdDebug(32004) <<
" KWTableFrameSet::validate(): zero dimension" << endl;
1448 kdDebug(32004) << cells->firstRow() <<
" " << cells->firstColumn() <<
" " << cells->rowSpan()
1449 <<
" " << cells->columnSpan() << endl;
1452 for(uint i = cells->firstRow(); i < cells->rowAfter(); ++i) {
1454 for(uint j = cells->firstColumn(); j < cells->columnAfter(); ++j) {
1455 if( cell(i,j) != cells.current() ) {
1457 TQString str = TQString(
"| 0x%1 ").arg( (
unsigned long)cells.current(), 0, 16 );
1458 kdDebug(32004) <<
" KWTableFrameSet::validate() failed " << endl;
1459 kdDebug(32004) <<
"at row: "<< i <<
" col: "<< j <<
" cell: "<< str << endl;
1460 kdDebug(32004) << cells->firstRow() <<
" " << cells->firstColumn() <<
" " << cells->rowSpan()
1461 <<
" " << cells->columnSpan() << endl;
1477 if ( !outerRect.isEmpty() )
1478 emptyRegion = emptyRegion.subtract( outerRect );
1481 for ( ; frameIt.current(); ++frameIt )
1483 TQRect outerRect( viewMode->
normalToView( frameIt.current()->outerRect(viewMode) ) );
1487 if ( !outerRect.isEmpty() )
1488 emptyRegion = emptyRegion.subtract( outerRect );
1492void KWTableFrameSet::drawBorders( TQPainter& painter,
const TQRect &crect,
KWViewMode *viewMode ) {
1500 TQPen previewLinePen( TQApplication::palette().color( TQPalette::Active, TQColorGroup::Mid ) );
1501 TQColor defaultBorderColor = KoTextFormat::defaultTextColor( &painter );
1502 const int minborder = 1;
1507 TQValueList<unsigned int>::iterator pageBound = m_pageBoundaries.begin();
1508 for (
unsigned int i=0 ; i < m_rowPositions.count() ; i++) {
1511 if( (pageBound!=m_pageBoundaries.end() && (*pageBound) == row)
1512 || i == m_rowPositions.count()-1)
1515 const KoBorder *border=0;
1517 for(
unsigned int col=0; col <=
getColumns();) {
1519 Cell *daCell = col <
getColumns() ? cell(bottom?row-1:row, col) : 0;
1523 if(daCell && daCell->firstRow() != (bottom?row-1:row))
1526 if(startPos!=0 && (!daCell || col ==
getColumns() || (
1527 bottom && daCell->frame(0)->bottomBorder()!=*border ||
1528 !bottom && daCell->frame(0)->topBorder()!=*border
1530 if(border->width() > 0 || drawPreviewLines) {
1531 double y = m_rowPositions[i];
1533 y+=border->width() / 2;
1535 y-=border->width() / 2;
1536 int ypix = m_doc->zoomItY(y);
1538 if(border->width() > 0 && col!=
getColumns()) {
1539 if(daCell) offset=daCell->leftBorder();
1541 Cell *c = cell(row-1, col);
1542 if(c) offset=kMax(offset, c->leftBorder());
1545 double x = m_colPositions[col] + offset;
1546 TQPoint topLeft = viewMode->
normalToView(TQPoint(m_doc->zoomItX(startPos), ypix));
1547 TQPoint bottomRight = viewMode->
normalToView(TQPoint(m_doc->zoomItX(x), ypix));
1548 TQRect line = TQRect(topLeft, bottomRight);
1549 if(crect.intersects( line )) {
1551 if(border->width() <= 0)
1552 painter.setPen( previewLinePen );
1554 int borderWidth = KoBorder::zoomWidthY( border->width(), m_doc, minborder );
1555 painter.setPen( KoBorder::borderPen( *border, borderWidth, defaultBorderColor ) );
1558 painter.drawLine( line.left(), line.top(), line.right(), line.bottom());
1564 if(daCell && startPos==0) {
1566 border=&(daCell->frame(0)->bottomBorder());
1568 border=&(daCell->frame(0)->topBorder());
1571 startPos = m_colPositions[col];
1574 if(border->width() > 0) {
1575 if(daCell) offset=daCell->leftBorder();
1577 Cell *c = cell(row-1, col);
1578 if(c) offset=kMax(offset, c->leftBorder());
1581 startPos = m_colPositions[col] - offset;
1584 col += daCell ? daCell->columnSpan() : 1;
1586 if(pageBound!=m_pageBoundaries.end() && (*pageBound) == row)
1593 for (
unsigned int col=0 ; col < m_colPositions.count(); col++) {
1596 if(col == m_colPositions.count()-1)
1598 int cellColumn = right?col-1:col;
1599 Q_ASSERT( cellColumn >= 0 );
1601 const KoBorder *border = 0;
1603 for(
unsigned int row=0; row <=
getRows();) {
1605 Cell *daCell = row <
getRows() ? cell(row, cellColumn) : 0;
1608 if(daCell && daCell->firstColumn() != (uint)cellColumn)
1612 kdDebug() <<
"Condition: startRow:" << (startRow!=-1) << endl;
1613 if ( startRow != -1 ) {
1615 kdDebug() <<
"Other conditions: cell:" << !daCell << endl;
1616 kdDebug() <<
" or last row:" << ( row == ( int )
getRows() ) << endl;
1618 kdDebug() <<
"Different border:" <<
1619 ( ( right && daCell->frame(0)->rightBorder() != *border) ||
1620 ( !right && daCell->frame(0)->leftBorder() != *border) )
1626 if ( !daCell && startRow == -1 && cellColumn == ((
int)m_colPositions.count()-2 ) && right )
1629 int col = cellColumn;
1630 while ( !daCell && col>0 )
1633 daCell = cell(row, col);
1635 if ( daCell && daCell->isJoinedCell() && ( (
int)daCell->columnSpan() + col -1 ) == cellColumn )
1637 border = &(daCell->frame(0)->rightBorder());
1647 if(startRow != -1 &&
1648 (!daCell || row ==
getRows() ||
1649 ( right && daCell->frame(0)->rightBorder() != *border) ||
1650 ( !right && daCell->frame(0)->leftBorder() != *border) )
1652 if(border->width() > 0 || drawPreviewLines) {
1653 double x = m_colPositions[col];
1655 x+=border->width() / 2;
1657 x-=border->width() / 2;
1659 int xpix = m_doc->zoomItX(x);
1660 TQValueList<unsigned int>::iterator pageBound = m_pageBoundaries.begin();
1661 unsigned int topRow=startRow;
1664 while( pageBound != m_pageBoundaries.end() && *(pageBound) < topRow )
1667 unsigned int bottomRow;
1668 if(pageBound == m_pageBoundaries.end())
1669 bottomRow = m_rowPositions.count()-1;
1671 bottomRow = *(pageBound++);
1676 if(border->width() > 0) {
1678 Cell *c=cell(topRow,col);
1679 if(c) offset=c->topBorder();
1681 c=cell(topRow,col-1);
1682 if(c) offset=kMax(offset,c->topBorder());
1684 if(topRow==0) offset=0.0;
1686 double top=m_rowPositions[topRow]-offset;
1688 unsigned int toRow=kMin((uint)row,bottomRow);
1690 if(border->width() > 0 && toRow!=bottomRow) {
1691 if(daCell) offset=daCell->topBorder();
1692 Cell *c=cell(toRow,col-1);
1693 if(c) offset=kMax(offset,c->topBorder());
1695 double bottom=m_rowPositions[toRow] + offset;
1697 TQPoint topLeft = viewMode->
normalToView(TQPoint(xpix, m_doc->zoomItY(top)));
1698 TQPoint bottomRight = viewMode->
normalToView(TQPoint(xpix, m_doc->zoomItY(bottom)));
1699 TQRect line = TQRect(topLeft, bottomRight);
1700 if(crect.intersects( line )) {
1701 if(border->width() <= 0)
1702 painter.setPen( previewLinePen );
1704 int borderWidth = KoBorder::zoomWidthX( border->width(), m_doc, minborder );
1705 painter.setPen(KoBorder::borderPen( *border, borderWidth, defaultBorderColor ));
1708 painter.drawLine( line.left(), line.top(), line.right(), line.bottom());
1712 }
while(topRow < (uint)row && topRow != m_rowPositions.count());
1719 if(daCell && startRow == -1) {
1722 border = &(daCell->frame(0)->rightBorder());
1724 border = &(daCell->frame(0)->leftBorder());
1727 row += daCell ? daCell->rowSpan() : 1;
1733 if(drawPreviewLines) {
1734 TQPen minsizeLinePen( red );
1735 painter.setPen( minsizeLinePen );
1736 for (
unsigned int i = 0; i < m_cells.count(); i++ ) {
1737 Cell *daCell = m_cells.at( i );
1738 double y = daCell->frame(0)->top() + daCell->frame(0)->minimumFrameHeight() + 1.5;
1739 if(y >= daCell->frame(0)->bottom())
continue;
1740 int ypix=m_doc->zoomItY(y);
1741 TQPoint topLeft = viewMode->
normalToView(TQPoint(m_doc->zoomItX(daCell->frame(0)->left()), ypix));
1742 TQPoint bottomRight = viewMode->
normalToView(TQPoint(m_doc->zoomItX(daCell->frame(0)->right()), ypix));
1743 TQRect line = TQRect(topLeft, bottomRight);
1744 if(crect.intersects( line )) {
1745 painter.drawLine( line.left(), line.top(), line.right(), line.bottom());
1755 const TQColorGroup & cg,
bool onlyChanged,
bool resetChanged,
1759 for (TableIter cells(
this) ; cells ; ++cells)
1764 if ( tableEdit->currentCell() && ((
Cell*) cells) == tableEdit->currentCell()->frameSet() )
1766 cells->
drawContents( painter, crect, cg, onlyChanged, resetChanged, tableEdit->currentCell(), viewMode, fvm );
1770 cells->drawContents( painter, crect, cg, onlyChanged, resetChanged, 0L, viewMode, fvm );
1772 drawBorders( *painter, crect, viewMode );
1781 writer.startElement(
"table:table" );
1782 writer.addAttribute(
"table:name",
name() );
1783 KoGenStyle tableStyle( KWDocument::STYLE_TABLE,
"table" );
1784 tableStyle.addProperty(
"table:align",
"margins" );
1785 tableStyle.addPropertyPt(
"style:width", m_colPositions.last()-m_colPositions[0] );
1786 const TQString tableStyleName = context.mainStyles().lookup( tableStyle,
"table" );
1787 writer.addAttribute(
"table:style-name", tableStyleName );
1791 for ( uint colNr = 0; colNr <
getColumns(); ++colNr )
1793 writer.startElement(
"table:table-column" );
1794 KoGenStyle columnStyle( KWDocument::STYLE_TABLE_COLUMN,
"table-column" );
1795 columnStyle.addPropertyPt(
"style:column-width", m_colPositions[colNr+1] - m_colPositions[colNr] );
1796 const TQString colStyleName = context.mainStyles().lookup( columnStyle,
"col" );
1797 writer.addAttribute(
"table:style-name", colStyleName );
1798 writer.endElement();
1803 for ( uint row = 0; row <
getRows(); ++row )
1805 writer.startElement(
"table:table-row" );
1807 KoGenStyle rowStyle( KWDocument::STYLE_TABLE_ROW,
"table-row" );
1808 rowStyle.addPropertyPt(
"table:row-height", m_rowPositions[row+1] - m_rowPositions[row] );
1810 const TQString rowStyleName = context.mainStyles().lookup( rowStyle,
"row" );
1811 writer.addAttribute(
"table:style-name", rowStyleName );
1813 for ( uint col = 0; col <
getColumns(); ++col )
1815 Cell* daCell = cell(row, col);
1820 if ( daCell->isFirstGridPosnFast( row, col ) )
1822 writer.startElement(
"table:table-cell" );
1825 KoGenStyle cellStyle( KWDocument::STYLE_TABLE_CELL_AUTO,
"table-cell" );
1826 daCell->
frame( 0 )->saveBorderProperties( cellStyle );
1827 const TQString colStyleName = context.mainStyles().lookup( cellStyle,
"cell" );
1828 writer.addAttribute(
"table:style-name", colStyleName );
1831 if ( daCell->columnSpan() > 1 )
1832 writer.addAttribute(
"table:number-columns-spanned", daCell->columnSpan() );
1833 if ( daCell->rowSpan() > 1 )
1834 writer.addAttribute(
"table:number-row-spanned", daCell->rowSpan() );
1839 writer.endElement();
1844 writer.startElement(
"table:covered-table-cell" );
1845 writer.endElement();
1848 writer.endElement();
1851 writer.endElement();
1854void KWTableFrameSet::loadOasis(
const TQDomElement& tableTag, KoOasisContext& context )
1857 TQMemArray<double> columnLefts(4);
1858 uint maxColumns = columnLefts.size() - 1;
1861 columnLefts[0] = 0.0;
1863 forEachElement( elem, tableTag )
1865 if ( elem.localName() ==
"table-column" && elem.namespaceURI() == KoXmlNS::table )
1867 uint repeat = elem.attributeNS( KoXmlNS::table,
"number-columns-repeated",
"1").toUInt();
1870 KoStyleStack& styleStack = context.styleStack();
1871 styleStack.setTypeProperties(
"table-column" );
1873 context.fillStyleStack( elem, KoXmlNS::table,
"style-name",
"table-column" );
1875 TQString strWidth = styleStack.attributeNS( KoXmlNS::style,
"column-width" );
1876 double width = KoUnit::parseValue( strWidth );
1880 kdWarning(32004) <<
"Table column width ridiculous, assuming 1 inch!" << endl;
1884 kdDebug(32004) <<
"- style width " << width << endl;
1886 for ( uint j = 0; j < repeat; ++j )
1889 if ( col >= maxColumns )
1893 columnLefts.resize( maxColumns+1, TQGArray::SpeedOptim );
1895 columnLefts[col] = width + columnLefts[col-1];
1896 kdDebug(32004) <<
"Cell column " << col-1 <<
" left " << columnLefts[col-1] <<
" right " << columnLefts[col] << endl;
1898 styleStack.restore();
1904 parseInsideOfTable( tableTag, context, columnLefts, row, column, 0 );
1907void KWTableFrameSet::parseInsideOfTable(
const TQDomElement& parent, KoOasisContext& context,
1908 const TQMemArray<double> & columnLefts, uint& row, uint& column,
1909 double currentRowHeight )
1911 kdDebug(32004) <<
"parseInsideOfTable" << endl;
1912 KoStyleStack& styleStack = context.styleStack();
1915 forEachElement( e, parent )
1917 const TQString localName = e.localName();
1918 const TQString ns = e.namespaceURI();
1919 if ( ns != KoXmlNS::table ) {
1920 kdWarning(32004) <<
"Skipping element " << e.tagName() <<
" (in parseInsideOfTable)" << endl;
1925 if ( localName ==
"table-cell" )
1927 loadOasisCell( e, context, columnLefts, row, column, currentRowHeight );
1930 else if ( localName ==
"covered-table-cell" )
1934 else if ( localName ==
"table-row" )
1936 context.fillStyleStack( e, KoXmlNS::table,
"style-name",
"table-row" );
1937 context.styleStack().setTypeProperties(
"table-row" );
1940 double rowHeight = styleStack.attributeNS( KoXmlNS::table,
"row-height" ).toDouble();
1942 parseInsideOfTable( e, context, columnLefts, row, column, rowHeight );
1945 else if ( localName ==
"table-header-rows" )
1948 parseInsideOfTable( e, context, columnLefts, row, column, currentRowHeight );
1950 else if ( localName ==
"table-column" )
1957 kdWarning(32004) <<
"Skipping element " << localName <<
" (in parseInsideOfTable)" << endl;
1960 styleStack.restore();
1964void KWTableFrameSet::loadOasisCell(
const TQDomElement& element, KoOasisContext& context,
1965 const TQMemArray<double> & columnLefts, uint row, uint column,
1966 double currentRowHeight )
1970 KoStyleStack& styleStack = context.styleStack();
1971 uint rowSpan = element.attributeNS( KoXmlNS::table,
"number-rows-spanned", TQString() ).toUInt();
1974 uint colSpan = element.attributeNS( KoXmlNS::table,
"number-columns-spanned", TQString() ).toUInt();
1979 while(m_rowPositions.count() <= row + rowSpan + m_pageBoundaries.count()) {
1980 m_rowPositions.append(0);
1982 while(m_colPositions.count() <= column + colSpan) {
1983 m_colPositions.append(0);
1986 Cell *daCell =
new Cell(
this, row, column, TQString() );
1988 daCell->setRowSpan( rowSpan );
1989 daCell->setColumnSpan( colSpan );
1992 double width = columnLefts[ TQMIN( column+colSpan, columnLefts.size()-1 ) ] - columnLefts[column];
1993 double height = currentRowHeight > 0 ? currentRowHeight : 20;
1994 KWFrame*
frame =
new KWFrame( daCell, columnLefts[column], 0, width, height );
1995 if ( currentRowHeight > 0 )
1996 frame->setMinimumFrameHeight( height );
1997 frame->setRunAround( KWFrame::RA_NO );
1998 frame->setFrameBehavior( KWFrame::AutoExtendFrame );
1999 frame->setNewFrameBehavior( KWFrame::NoFollowup );
2000 daCell->addFrame(
frame,
false );
2002 context.fillStyleStack( element, KoXmlNS::table,
"style-name",
"table-cell" );
2003 styleStack.setTypeProperties(
"table-cell" );
2005 daCell->frame( 0 )->loadBorderProperties( styleStack );
2007 daCell->loadOasisContent( element, context );
2008 afterLoadingCell( daCell );
2015 for (TableIter cells(
this) ; cells ; ++cells)
2016 cells->save(parentElem, saveFrames);
2017 return TQDomElement();
2023 TQDomElement framesetElem = parentElem.ownerDocument().createElement(
"FRAMESET" );
2024 parentElem.appendChild( framesetElem );
2027 save( framesetElem, saveFrames );
2028 return framesetElem;
2036 TQDomElement cellElem = framesetElem.firstChild().toElement();
2037 for ( ; !cellElem.isNull() ; cellElem = cellElem.nextSibling().toElement() )
2039 if ( cellElem.tagName() ==
"FRAMESET" )
2040 loadCell( cellElem, loadFrames, useNames );
2047 int _row = KWDocument::getAttribute( framesetElem,
"row", 0 );
2048 if(_row <0) _row =0;
2049 unsigned int row=_row;
2050 int _col = KWDocument::getAttribute( framesetElem,
"col", 0 );
2051 if(_col <0) _col =0;
2052 int _rows = KWDocument::getAttribute( framesetElem,
"rows", 1 );
2053 if(_rows <0) _rows = 1;
2054 int _cols = KWDocument::getAttribute( framesetElem,
"cols", 1 );
2055 if(_cols <0) _cols = 1;
2058 while(m_rowPositions.count() <=
static_cast<unsigned int>(row + _rows + m_pageBoundaries.count())) {
2059 m_rowPositions.append(0);
2061 while(m_colPositions.count() <=
static_cast<unsigned int>(_col + _cols)) {
2062 m_colPositions.append(0);
2065 Cell *daCell =
new Cell(
this, row, _col, TQString() );
2066 TQString autoName = daCell->
name();
2068 daCell->
load( framesetElem, loadFrames );
2069 daCell->setRowSpan(_rows);
2070 daCell->setColumnSpan(_cols);
2072 afterLoadingCell( daCell );
2074 daCell->setName( autoName );
2079void KWTableFrameSet::afterLoadingCell( Cell* daCell )
2081 uint row = daCell->firstRow();
2082 uint col = daCell->firstColumn();
2083 uint rowSpan = daCell->rowSpan();
2084 uint colSpan = daCell->columnSpan();
2085 if(m_pageBoundaries.count() > 0) {
2086 unsigned int adjustment=0;
2087 TQValueList<unsigned int>::iterator pageBound = m_pageBoundaries.begin();
2088 while(pageBound != m_pageBoundaries.end() && (*pageBound) <= row + adjustment) {
2095 kdDebug(32004) <<
"loading cell (" << row <<
"," << col <<
")\n";
2096 if(daCell->frame(0)) {
2097 daCell->frame(0)->setMinimumFrameHeight(daCell->frame(0)->height());
2098 TQValueList<double>::iterator tmp = m_colPositions.at(col);
2099 if(*tmp == 0) (*tmp) = daCell->frame(0)->left();
2100 else (*tmp) = (daCell->frame(0)->left() + *tmp) / 2;
2102 tmp = m_colPositions.at(col+colSpan);
2103 if(*tmp == 0) (*tmp) = daCell->frame(0)->right();
2104 else (*tmp) = (daCell->frame(0)->right() + *tmp) / 2;
2106 tmp = m_rowPositions.at(row);
2108 (*tmp) = daCell->frame(0)->top();
2110 if (
static_cast<int>(*tmp/m_doc->pageLayout().ptHeight) <
static_cast<int>(daCell->frame(0)->top()/m_doc->pageLayout().ptHeight)) {
2111 kdDebug(32004) <<
"This cell is on a new page" << endl;
2112 TQValueList<unsigned int>::iterator pageBound = m_pageBoundaries.begin();
2113 while(pageBound != m_pageBoundaries.end() && (*pageBound) < row) ++pageBound;
2114 if(*pageBound!=row) {
2115 m_pageBoundaries.insert(pageBound,row++);
2117 m_rowPositions.insert(tmp,daCell->frame(0)->top());
2120 (*tmp) = (daCell->frame(0)->top() + *tmp) / 2;
2123 tmp = m_rowPositions.at( row + rowSpan );
2125 (*tmp) = daCell->frame(0)->bottom();
2127 if (
static_cast<int>(*tmp/m_doc->pageLayout().ptHeight) >
static_cast<int>(daCell->frame(0)->top()/m_doc->pageLayout().ptHeight)) {
2128 kdDebug(32004) <<
"next cell is on a new page" << endl;
2129 TQValueList<unsigned int>::iterator pageBound = m_pageBoundaries.begin();
2130 while(pageBound != m_pageBoundaries.end() && (*pageBound) < row) ++pageBound;
2131 if(*pageBound!=row) {
2132 m_pageBoundaries.insert(pageBound,row++);
2133 m_rowPositions.insert(tmp,daCell->frame(0)->bottom());
2136 (*tmp) = (daCell->frame(0)->bottom() + *tmp) / 2;
2140 if ( m_rowPositions.count() != m_rows + 1 ) {
2141 kdDebug() <<
name() <<
" loadCell: m_rowPositions=" << m_rowPositions.count() <<
" m_rows= " << m_rows << endl;
2148 for (TableIter cells(
this) ; cells ; ++cells)
2153int KWTableFrameSet::paragraphsSelected()
2156 for (TableIter cells(
this) ; cells ; ++cells)
2161bool KWTableFrameSet::statistics( TQProgressDialog *progress, ulong & charsWithSpace, ulong & charsWithoutSpace, ulong & words,
2162 ulong & sentences, ulong & syllables, ulong & lines,
bool selected )
2164 for (TableIter cells(
this) ; cells ; ++cells)
2165 if( ! cells->statistics( progress, charsWithSpace, charsWithoutSpace, words, sentences, syllables, lines, selected ) )
2173 kdDebug(32004) <<
"KWTableFrameSet::finalize" << endl;
2175 for (TableIter cells(
this) ; cells ; ++cells)
2188 for (TableIter cells(
this) ; cells ; ++cells)
2192void KWTableFrameSet::invalidate()
2194 for (TableIter cells(
this) ; cells ; ++cells)
2195 cells->invalidate();
2200 for (TableIter cells(
this) ; cells ; ++cells)
2201 cells->setVisible( v );
2212 for ( ; frameIt.current(); ++frameIt ) {
2213 if ( frameIt.current()->pageNumber() == num ) {
2220void KWTableFrameSet::addTextFrameSets( TQPtrList<KWTextFrameSet> & lst,
bool onlyReadWrite )
2222 for (TableIter cells(
this) ; cells ; ++cells)
2223 if (!cells->textObject()->protectContent() || onlyReadWrite )
2230 KWTableFrameSet::Cell *tmp =
dynamic_cast<KWTableFrameSet::Cell *
>(obj);
2234 for(TableIter i(
this); i; ++i) {
2235 if(i.current() == tmp) {
2242 TableIter iter(
this);
2246 for(; iter; ++iter) {
2247 KWTextFrameSet *newFrm = iter->nextTextObject( obj );
2248 if(newFrm && newFrm->
textObject()->needSpellCheck())
2257 for( TableIter cells(
this) ; cells ; ++cells ) {
2265TQByteArray KWTableFrameSet::convertTableToText()
2268 for (TableIter cells(
this); cells; ++cells)
2270 cells->textObject()->saveOasisContent( oasisSaver.bodyWriter(), oasisSaver.savingContext() );
2272 if ( !oasisSaver.finish() )
2273 return TQByteArray();
2274 return oasisSaver.data();
2278void KWTableFrameSet::printDebug(
KWFrame * theFrame )
2280 KWTableFrameSet::Cell *daCell =
dynamic_cast<KWTableFrameSet::Cell *
>( theFrame->
frameSet() );
2283 kdDebug(32004) <<
" | |- row :" << daCell->firstRow() << endl;
2284 kdDebug(32004) <<
" | |- col :" << daCell->firstColumn() << endl;
2285 kdDebug(32004) <<
" | |- rows:" << daCell->rowSpan() << endl;
2286 kdDebug(32004) <<
" | +- cols:" << daCell->columnSpan() << endl;
2290void KWTableFrameSet::printArrayDebug() {
2291 kdDebug(32004) <<
" | Row/Cell arrays" << endl;
2292 Q_ASSERT( m_rows == m_rowArray.size() );
2293 for (
unsigned int row = 0; row < m_rows; ++row ) {
2294 TQString str = TQString(
" | Row %1: " ).arg( row );
2295 for (
unsigned int col = 0; col <
getColumns(); ++col )
2296 str += TQString(
"| 0x%1 ").arg( (
unsigned long)(*m_rowArray[row])[col], 0, 16 );
2297 kdDebug(32004) << str<<
" |" << endl;
2301void KWTableFrameSet::printDebug() {
2302 kdDebug(32004) <<
" | Table size (" << m_rows <<
"x" <<
getColumns() <<
")" << endl;
2303 kdDebug(32004) <<
" | col " << 0 <<
": " << m_colPositions[0] << endl;
2304 for(
unsigned int i=1;i<m_colPositions.count(); ++i)
2305 kdDebug(32004) <<
" | | " << i <<
": " << m_colPositions[i] << endl;
2306 kdDebug(32004) <<
" | row " << 0 <<
": " << m_rowPositions[0] << endl;
2307 for(
unsigned int i=1;i<m_rowPositions.count(); ++i)
2308 kdDebug(32004) <<
" | | " << i <<
": " << m_rowPositions[i] << endl;
2311 KWFrameSet::printDebug();
2321 i18n(
"Hello dear translator :), 1 is the table name, 2 and 3 are row and column",
"%1 Cell %2,%3")
2322 .arg( table->
name() ).arg(row).arg(col) )
2328 m_isJoinedCell =
false;
2336 m_row = original.m_row;
2337 m_col = original.m_col;
2338 m_rows = original.m_rows;
2339 m_cols = original.m_cols;
2340 m_isJoinedCell = original.m_isJoinedCell;
2345KWTableFrameSet::Cell::~Cell()
2349bool KWTableFrameSet::Cell::isAboveOrLeftOf(
unsigned row,
unsigned col )
const
2351 return ( m_row < row ) || ( ( m_row == row ) && ( m_col < col ) );
2354bool KWTableFrameSet::Cell::containsCell(
unsigned row,
unsigned col )
const
2356 return ( m_row <= row &&
2359 columnAfter() > col );
2362void KWTableFrameSet::Cell::addFrame(KWFrame *_frame,
bool recalc) {
2365 KWTextFrameSet::addFrame(_frame, recalc);
2374double KWTableFrameSet::Cell::leftBorder() {
2383double KWTableFrameSet::Cell::rightBorder() {
2384 double b=
frame(0)->rightBorder().width();
2387 if(m_col+m_cols==m_groupmanager->
getColumns())
2392double KWTableFrameSet::Cell::topBorder() {
2393 double b =
frame(0)->topBorder().width();
2401double KWTableFrameSet::Cell::bottomBorder() {
2402 double b =
frame(0)->bottomBorder().width();
2405 if(rowAfter() == m_groupmanager->m_rows)
2410void KWTableFrameSet::Cell::setLeftBorder(KoBorder newBorder) {
2411 KWFrame *f =
frame(0);
2412 double diff = f->
leftBorder().width() - newBorder.width();
2413 f->setLeftBorder(newBorder);
2415 if((diff > 0.01 || diff < -0.01) && m_col!=0) {
2417 m_groupmanager->cell(m_row, m_col-1)->setRightBorder(newBorder);
2419 f->setLeft(f->left() - diff);
2422void KWTableFrameSet::Cell::setRightBorder(KoBorder newBorder) {
2423 KWFrame *f =
frame(0);
2424 double diff = f->rightBorder().width() - newBorder.width();
2425 f->setRightBorder(newBorder);
2427 if((diff > 0.01 || diff < -0.01) && m_col+m_cols!=m_groupmanager->getColumns()) {
2429 m_groupmanager->cell(m_row, m_col+1)->setLeftBorder(newBorder);
2431 f->setRight(f->right() + diff);
2434void KWTableFrameSet::Cell::setTopBorder(KoBorder newBorder) {
2435 KWFrame *f =
frame(0);
2436 double diff = f->topBorder().width() - newBorder.width();
2437 f->setTopBorder(newBorder);
2439 if((diff > 0.01 || diff < -0.01) && m_row!=0) {
2441 m_groupmanager->cell(m_row-1, m_col)->setBottomBorder(newBorder);
2443 f->setTop(f->top() - diff);
2446void KWTableFrameSet::Cell::setBottomBorder(KoBorder newBorder) {
2447 KWFrame *f =
frame(0);
2448 double diff = f->bottomBorder().width() - newBorder.width();
2449 f->setBottomBorder(newBorder);
2451 if((diff > 0.01 || diff < -0.01) && rowAfter() != m_groupmanager->m_rows) {
2453 m_groupmanager->cell(m_row+1, m_col)->setTopBorder(newBorder);
2455 f->setBottom(f->bottom() + diff);
2461 for ( ; frameIt.current(); ++frameIt )
2463 (*frameIt)->setZOrder( kWordDocument()->maxZOrder( (*frameIt)->pageNumber() ) + 1 );
2468 const TQColorGroup & cg,
bool onlyChanged,
bool resetChanged,
2471 bool printing = painter->device()->devType() == TQInternal::Printer;
2473 TQRect cellRect = crect;
2474 if(!printing && drawPreviewLines) {
2476 TQRect zoomedRect( m_doc->zoomRect(*
frame(0)) );
2477 TQRect innerFrameRect( viewMode->
normalToView( zoomedRect ) );
2478 innerFrameRect.addCoords(1, 1, -1, -1);
2479 cellRect = innerFrameRect.intersect(crect);
2484KWTableFrameSetEdit::~KWTableFrameSetEdit()
2486 if ( m_currentCell )
2487 m_currentCell->terminate();
2488 delete m_currentCell;
2491void KWTableFrameSetEdit::mousePressEvent( TQMouseEvent * e,
const TQPoint & nPoint,
const KoPoint & dPoint )
2493 setCurrentCell( dPoint );
2494 if ( m_currentCell )
2495 m_currentCell->mousePressEvent( e, nPoint, dPoint );
2500 KWFrameSet *fs = tableFrameSet()->cellByPos( dPoint.x(), dPoint.y() );
2503 if ( textframeSet&& textframeSet->protectContent() && !tableFrameSet()->kWordDocument()->cursorInProtectedArea())
2506 if ( fs && ( !m_currentCell || fs != m_currentCell->frameSet() ) )
2512 bool oldProtectContent =
false;
2514 if ( m_currentCell )
2515 textframeSet =
dynamic_cast<KWTextFrameSet *
>(m_currentCell->frameSet());
2517 oldProtectContent = textframeSet->protectContent();
2519 if ( m_currentCell )
2521 m_currentCell->terminate(eraseSelection);
2522 delete m_currentCell;
2525 textframeSet =
dynamic_cast<KWTextFrameSet *
>(m_currentCell->frameSet());
2528 if ( oldProtectContent != textframeSet->protectContent())
2530 m_canvas->kWordDocument()->updateTextFrameSetEdit();
2537 if ( textframeSetEdit )
2539 textframeSetEdit->ensureCursorVisible();
2541 m_canvas->gui()->getView()->slotUpdateRuler();
2547 return m_currentCell;
2551void KWTableFrameSetEdit::keyPressEvent( TQKeyEvent * e )
2554 if ( !m_currentCell )
2558 bool moveToOtherCell =
true;
2562 KoTextDocument * textdoc = textframeSet->textDocument();
2563 if(textdoc->hasSelection( KoTextDocument::Standard ))
2564 moveToOtherCell=
false;
2566 KWTableFrameSet::Cell *fs = 0L;
2571 switch( e->key() ) {
2574 if(!(
static_cast<KWTextFrameSetEdit *
>(m_currentCell))->cursor()->parag()->prev())
2577 int row = cell->firstRow() - 1;
2578 int col = cell->firstColumn();
2581 row = tableFrame->
getRows() - 1;
2586 row = tableFrame->
getRows() - 1;
2588 fs=tableFrame->cell(row,col);
2598 if(!(
static_cast<KWTextFrameSetEdit *
>(m_currentCell))->cursor()->parag()->next())
2601 unsigned int row = cell->rowAfter();
2602 unsigned int col = cell->firstColumn();
2603 if(row >= tableFrame->
getRows()) {
2612 fs=tableFrame->cell(row,col);
2614 Q_ASSERT( fs->firstRow() == row );
2618 case TQt::Key_Backtab:
2620 if (e->state() & TQt::ControlButton)
2625 KoTextCursor *cur = (
static_cast<KWTextFrameSetEdit *
>(m_currentCell))->cursor();
2626 if ( tab || (!cur->parag()->prev()&&cur->index()==0) )
2629 int row=cell->firstRow();
2630 int col=cell->firstColumn() - 1;
2638 row = (int)tableFrame->
getRows()-1;
2640 fs=tableFrame->cell(row,col);
2650 if (e->state() & TQt::ControlButton)
2653 case TQt::Key_Right:
2655 KoTextCursor *cur = (
static_cast<KWTextFrameSetEdit *
>(m_currentCell))->cursor();
2656 if( tab || (!cur->parag()->next()&&cur->index()==cur->parag()->string()->length()-1) )
2659 unsigned int row = cell->firstRow();
2660 unsigned int col = cell->columnAfter();
2665 if(row >= tableFrame->
getRows()) {
2670 fs=tableFrame->cell(row,col);
2672 Q_ASSERT( fs->firstRow() == row );
2681 if ( fs->
textObject()->protectContent() && !tableFrameSet()->kWordDocument()->cursorInProtectedArea())
2683 setCurrentCell( fs );
2685 else if ( textframeSet )
2687 if ( !textframeSet->
textObject()->protectContent() )
2689 if (tab && (e->state() & TQt::ControlButton) )
2691 TQKeyEvent event(TQEvent::KeyPress, TQt::Key_Tab, 9, 0, TQChar(9));
2692 m_currentCell->keyPressEvent( &event );
2695 m_currentCell->keyPressEvent( e );
2697 else if(e->text().length() > 0)
2698 KMessageBox::information(0L, i18n(
"Read-only content cannot be changed. No modifications will be accepted."));
2702void KWTableFrameSetEdit::keyReleaseEvent( TQKeyEvent * e )
2704 if ( m_currentCell )
2705 m_currentCell->keyReleaseEvent( e );
2708void KWTableFrameSetEdit::imStartEvent( TQIMEvent* e )
2710 if ( m_currentCell )
2711 m_currentCell->imStartEvent( e );
2714void KWTableFrameSetEdit::imComposeEvent( TQIMEvent* e )
2716 if ( m_currentCell )
2717 m_currentCell->imComposeEvent( e );
2720void KWTableFrameSetEdit::imEndEvent( TQIMEvent* e )
2722 if ( m_currentCell )
2723 m_currentCell->imEndEvent( e );
2726void KWTableFrameSetEdit::dragMoveEvent( TQDragMoveEvent * e,
const TQPoint &n,
const KoPoint &d )
2728 kdDebug(32004)<<
"m_currentCell :"<<m_currentCell<<endl;
2729 if ( m_currentCell )
2731 KWFrameSet *fs = tableFrameSet()->cellByPos( d.x(), d.y() );
2732 kdDebug(32004)<<
"fs :"<<fs <<endl;
2733 if(fs && fs != m_currentCell->frameSet())
2734 setCurrentCell(fs,
false);
2736 m_currentCell->dragMoveEvent( e, n, d );
2740 setCurrentCell( d );
2741 kdDebug(32004)<<
"after m_currentCell :"<<m_currentCell<<endl;
2743 m_currentCell->dragMoveEvent( e, n, d );
2747void KWTableFrameSet::Row::addCell(
Cell *cell )
2749 if ( m_cellArray.size() < cell->columnAfter())
2750 m_cellArray.resize( cell->columnAfter() );
2751 for ( uint col = cell->firstColumn() ; col < cell->columnAfter(); ++col )
2752 m_cellArray.insert( col, cell );
2755void KWTableFrameSet::Row::removeCell(
Cell* cell )
2757 for ( uint col = cell->firstColumn() ; col < cell->columnAfter(); ++col )
2758 m_cellArray.remove( col );
2762KWTableFrameSet::Cell*
2763KWTableFrameSet::TableIterator<KWTableFrameSet::VISIT_CELL>::operator++()
2765 if(!m_cell)
return 0;
2771 if(m_table->cell(m_row,m_col)->lastColumn() >= m_limit[RIGHT] ) {
2773 if (m_row >= m_limit[LOW]){
2781 m_col = m_limit[LEFT];
2786 m_col = m_table->cell(m_row, m_col)->columnAfter();
2789 m_cell = m_table->cell(m_row,m_col);
2790 }
while( m_cell && !m_cell->isFirstGridPosnFast(m_row,m_col) );
2796KWTableFrameSet::Cell*
2797KWTableFrameSet::TableIterator<KWTableFrameSet::VISIT_GRID>::operator++()
2799 if(!m_cell)
return 0;
2803 if(m_col == m_limit[RIGHT]) {
2804 if(m_row == m_limit[LOW]) {
2811 m_col = m_limit[LEFT];
2812 m_cell = m_table->cell(m_row, m_col);
2817 m_cell = m_table->cell(m_row, m_col);
2823KWTableFrameSet::MarkedIterator::MarkedIterator(
KWTableFrameSet *table) :
2827 for(GridIter cell(table); cell; ++cell)
2833 current()->setMark();
2838KWTableFrameSet::MarkedIterator::operator++()
2840 Cell *ret = GridIter::operator++();
2842 while ( current() && current()->marked() ) {
2843 GridIter::operator++();
2848 current()->setMark();
2858 set_limits(0, (
int)m_table->getColumns() - 1, 0, (
int)m_table->getRows() - 1);
2861 for(uint i = m_limit[HIGH]; i <= m_limit[LOW]; ++i)
2862 for(uint j = m_limit[LEFT]; j <= m_limit[RIGHT]; ++j) {
2864 c = m_table->cell(i,j);
2865 if(c) c->clearMark();
2880 uint i = m_row; uint j = m_col;
2882 for(; i <= m_limit[LOW]; ++i) {
2884 for(j = 0; j <= m_limit[RIGHT]; ++j) {
2885 m_cell = m_table->cell(i,j);
2886 if( m_cell && !m_cell->marked() ){
2887 m_row = i; m_col = j;
2890 else if(i == m_limit[LOW] && j == m_limit[RIGHT]){
2903KWTableFrameSet::TableIterator<KWTableFrameSet::CHECKED>::toFirstCell ()
2906 for(uint i = m_limit[HIGH]; i <= m_limit[LOW]; ++i)
2907 for(uint j = m_limit[LEFT]; j <= m_limit[RIGHT]; ++j) {
2908 m_cell = m_table->cell(i,j);
2910 m_row = i; m_col = j;
2919RemovedRow::RemovedRow() :
2920 m_row(0), m_index(0), m_rowHeight(0.0)
2925RemovedRow::~RemovedRow()
2934 KWTableFrameSet::Row *ret = m_row;
2939RemovedColumn::RemovedColumn()
2940 : m_column(), m_removed(), m_index(0), m_width(0), m_initialized(false){ }
2943#include "KWTableFrameSet.moc"
An anchor is a special character, or 'custom item'.
Class: KWCanvas This class is responsible for the rendering of the frames to the screen as well as th...
Command created when creating a table.
Command created when deleting a table.
This object is created to edit a particular frameset in a particular view The view's canvas creates i...
KWFrame * m_currentFrame
The Frameset-Edit implementation is responsible for updating that one (to the frame where the current...
Class: KWFrameSet Base type, a frameset holds content as well as frames to show that content.
void repaintChanged(KWFrameSet *frameset)
Emitted when something has changed in this frameset, so that all views repaint it.
KWAnchor * findAnchor(int frameNum)
Return the anchor object for this frame number.
virtual void setVisible(bool v)
set the visibility of the frameset.
virtual void deleteFrame(unsigned int num, bool remove=true, bool recalc=true)
Delete a frame from the set of frames this frameSet has.
const TQPtrList< KWFrame > & frameIterator() const
Iterator over the child frames.
virtual void finalize()
Called once the frameset has been completely loaded or constructed.
virtual KWFrameSetEdit * createFrameSetEdit(KWCanvas *)
Create a framesetedit object to edit this frameset in canvas.
virtual void load(TQDomElement &framesetElem, bool loadFrames=true)
load from XML - when loading
bool isFloating() const
Return true if this frameset is floating (inline), false if it's fixed.
virtual void updateFrames(int flags=0xff)
Called when our frames change, or when another frameset's frames change.
void saveCommon(TQDomElement &parentElem, bool saveFrames)
save the common attributes for the frameset
KWTableFrameSet * groupmanager() const
returns the groupManager this frameset belongs to.
KWFrame * frame(unsigned int _num) const
get a frame by number
TQString name() const
get/set frameset name. For tables in particular, this must be unique
KWFrameSet(KWDocument *doc)
constructor
KWFrame * frameAtPos(double _x, double _y) const
retrieve frame from x and y coords (unzoomed coords)
void setGroupManager(KWTableFrameSet *gm)
make this frameset part of a groupmanager
Class that knows about all the (visible) frames in the document and will act as a manager between the...
This class represents a single frame.
KWFrameSet * frameSet() const
Data stucture methods.
void setMinimumFrameHeight(double h)
The property minimum frame height is used to make the automatic frame shrinking code stop.
int pageNumber() const
The page on which this frame is.
const KoBorder & leftBorder() const
All borders can be custom drawn with their own colors etc.
KWFrame * getCopy()
returns a copy of self
Command created when joining cells.
This is used to save a bunch of paragraphs into a oasis store in memory, as some features do (e....
This class represents a printed page of the document.
double leftMargin() const
return the width of the margin at left (in pt);
double width() const
return the width of this page (in pt)
double rightMargin() const
return the width of the margin at left (in pt);
Command created when splitting a cell.
The object created to edit this table.
virtual KWFrameSetEdit * currentTextEdit()
Return the current most-low-level text edit object.
void setCurrentCell(KWFrameSet *fs, bool eraseSelection=true)
Set the cell which is currently being edited.
virtual void frameDeleted(KWFrame *frm, bool recalc)
Called by deleteFrame when it really deletes a frame (remove=true), to remove it from the table too.
Cell(KWTableFrameSet *table, unsigned int row, unsigned int col, const TQString &name=TQString())
constructor
void drawContents(TQPainter *painter, const TQRect &crect, const TQColorGroup &cg, bool onlyChanged, bool resetChanged, KWFrameSetEdit *edit, KWViewMode *viewMode, KWFrameViewManager *frameViewManager)
Overloaded to not clear any preview borders.
void setZOrder()
set zorder for all frames in this cell
This iterator does not look at the Cell instance variables during traversal, (except m_marker),...
Represents a row, for direct access to cells with m_rowArray[row][column].
TQPtrVector< Cell > m_cellArray
Array of cells in the row.
All the TableIterator templates are the same, except for the pre-increment operator (operator++).
TableIterator(KWTableFrameSet *table)
void resizeWidth(double width)
change the width of the table, keeping the proportions of the cells (if one is wider than the others,...
virtual void finalize()
Called once the frameset has been completely loaded or constructed.
Cell * loadCell(TQDomElement &frameElem, bool loadFrames=true, bool useNames=true)
load one cell
virtual void layout()
relayout text in frames, so that it flows correctly around other frames
void insertNewColumn(uint _idx, double width=KWTableFrameSet::m_sDefaultColWidth)
insert a column of new cells use the getRows() call to decide how many cells are created
void moveBy(double dx, double dy)
move the whole of the table, this is mainly for anchored frames.
virtual KCommand * anchoredObjectCreateCommand(int frameNum)
Store command for creating an anchored object.
void setZOrder()
Sets zOrder for all cells in this table.
virtual KCommand * anchoredObjectDeleteCommand(int frameNum)
Store command for deleting an anchored object.
void resizeColumn(unsigned int col, double x)
move a column edge (i.e.
virtual TQDomElement save(TQDomElement &parentElem, bool saveFrames=true)
override save so we save in table style.
virtual int paragraphs()
Contribute to the document statistics.
virtual void moveFloatingFrame(int frameNum, const KoPoint &position)
Move the frame frameNum to the given position - this is called when the frame is anchored and the anc...
void removeCell(Cell *cell)
Remove a cell from this table (either to delete it, or to move it).
void reInsertRow(RemovedRow &row)
replace a row that was removed with deleteRow()
void ungroup()
release the constrains of the table and allow all frames to be edited apart from each other.
virtual void updateFrames(int flags=0xff)
Called when our frames change, or when another frameset's frames change.
virtual void drawContents(TQPainter *painter, const TQRect &crect, const TQColorGroup &cg, bool onlyChanged, bool resetChanged, KWFrameSetEdit *edit, KWViewMode *viewMode, KWFrameViewManager *frameViewManager)
Paint this frameset.
void validate()
do a number of complex tests to test the validity of the table.
virtual TQDomElement toXML(TQDomElement &parentElem, bool saveFrames=true)
from and to XML - used when copying and pasting a table
virtual void createEmptyRegion(const TQRect &crect, TQRegion &emptyRegion, KWViewMode *viewMode)
KoRect boundingRect()
Calculate the absolute size of the complete table.
void setBoundingRect(KoRect rect, CellSize widthMode, CellSize heightMode)
Layout all cells to fit inside the rect, cells will however use a minimum size, so the table might en...
void deleteColumn(uint _idx, RemovedColumn &rc)
remove all the cells in a certain column
void insertNewRow(uint _idx, bool _recalc=true, bool _removeable=false)
insert a row of new cells, use the getCols() call to decide how many cells are created
KCommand * splitCell(unsigned int intoRows, unsigned int intoColumns, unsigned int column, unsigned int row, TQPtrList< KWFrameSet > listFrameSet=TQPtrList< KWFrameSet >(), TQPtrList< KWFrame >listFrame=TQPtrList< KWFrame >())
split one cell into a number of cells and return a command for undo purposes.
double topWithoutBorder()
Calculate the top postion of the cell(s) in the leftmost column.
virtual KoSize floatingFrameSize(int frameNum=0)
Get the size of the "floating frame" identified by frameNum.
int columnEdgeAt(double x) const
return the number of the column edge closest to x (between 0 and getCols()+1)
virtual void setVisible(bool v)
set the visibility of the frameset.
void reInsertColumn(RemovedColumn &col)
replace a column that was removed with deleteColumn()
void recalcCols(uint column, uint row)
resize and position all cells
unsigned int getColumns() const
returns the number of columns
void resizeRow(unsigned int row, double y)
move a row edge (i.e.
virtual KWAnchor * createAnchor(KoTextDocument *txt, int frameNum)
Create an anchor for the floating frame identified by frameNum.
int rowEdgeAt(double y) const
return the number of the row edge closest to x (between 0 and getRows()+1)
virtual void fromXML(TQDomElement &framesetElem, bool loadFrames=true, bool useNames=true)
load from XML - when pasting from clipboard
void addCell(Cell *cell)
Add a cell to this table, the cell should already have info like row, col and should already have a f...
virtual bool canRemovePage(int num)
Return true if page num can be removed, as far as this frameset is concerned.
double leftWithoutBorder()
Calculate the top postion of the cell(s) in the top row.
virtual void saveOasis(KoXmlWriter &, KoSavingContext &, bool saveFrames) const
Save to OASIS format.
void deleteRow(uint _idx, RemovedRow &rr, bool _recalc=true)
Remove all the cells in a certain row.
KWTableFrameSet(KWDocument *_doc, const TQString &name)
constructor
void viewFormatting(TQPainter &painter, int zoom)
display formatting information
KCommand * joinCells(unsigned int firstColumn, unsigned int firstRow, unsigned int endColumn, unsigned int endRow)
merge cells to one cell.
virtual KWFrameSetEdit * createFrameSetEdit(KWCanvas *canvas)
Create a framesetedit object to edit this frameset in canvas.
virtual ~KWTableFrameSet()
destructor
unsigned int getRows() const
returns the number of rows
Object that is created to edit a Text frame set (KWTextFrameSet).
Class: KWTextFrameSet Contains text (KoTextObject) and frames to display that text.
KoTextObject * textObject() const
Return the contained text object.
KWTextFrameSet(KWDocument *_doc, const TQString &name)
Cnstructor.
virtual void load(TQDomElement &attributes, bool loadFrames=true)
load from XML - when loading
virtual void deleteFrame(unsigned int num, bool remove=true, bool recalc=true)
Delete a frame from the set of frames this frameSet has.
void saveOasisContent(KoXmlWriter &writer, KoSavingContext &context) const
Save the contents of a frame (i.e. the text).
virtual void drawContents(TQPainter *painter, const TQRect &crect, const TQColorGroup &cg, bool onlyChanged, bool resetChanged, KWFrameSetEdit *edit, KWViewMode *viewMode, KWFrameViewManager *frameViewManager)
Paint this frameset.
Abstract base class for KWCanvas's view modes.
virtual TQPoint normalToView(const TQPoint &nPoint)=0
Normal coord -> view coord.
bool drawFrameBorders() const
Should we see frame borders?
RemovedRow and RemovedColumn implement the Memento design pattern.