diff options
Diffstat (limited to 'sw/source/core/doc/docsort.cxx')
-rw-r--r-- | sw/source/core/doc/docsort.cxx | 306 |
1 files changed, 0 insertions, 306 deletions
diff --git a/sw/source/core/doc/docsort.cxx b/sw/source/core/doc/docsort.cxx index 69eaedd17619..c7cfe756d5c6 100644 --- a/sw/source/core/doc/docsort.cxx +++ b/sw/source/core/doc/docsort.cxx @@ -306,312 +306,6 @@ double SwSortBoxElement::GetValue( sal_uInt16 nKey ) const /*-------------------------------------------------------------------- Description: Sort Text in the Document --------------------------------------------------------------------*/ -sal_Bool SwDoc::SortText(const SwPaM& rPaM, const SwSortOptions& rOpt) -{ - // Check if Frame is in the Text - const SwPosition *pStart = rPaM.Start(), *pEnd = rPaM.End(); - - // Set index to the Selection's start - for ( sal_uInt16 n = 0; n < GetSpzFrmFmts()->Count(); ++n ) - { - SwFrmFmt *const pFmt = static_cast<SwFrmFmt*>((*GetSpzFrmFmts())[n]); - SwFmtAnchor const*const pAnchor = &pFmt->GetAnchor(); - SwPosition const*const pAPos = pAnchor->GetCntntAnchor(); - - if (pAPos && (FLY_AT_PARA == pAnchor->GetAnchorId()) && - pStart->nNode <= pAPos->nNode && pAPos->nNode <= pEnd->nNode ) - return sal_False; - } - - // Check if only TextNodes are within the Selection - { - sal_uLong nStart = pStart->nNode.GetIndex(), - nEnd = pEnd->nNode.GetIndex(); - while( nStart <= nEnd ) - // Iterate over a selected Area - if( !GetNodes()[ nStart++ ]->IsTxtNode() ) - return sal_False; - } - - bool const bUndo = GetIDocumentUndoRedo().DoesUndo(); - if( bUndo ) - { - GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL ); - } - - SwPaM* pRedlPam = 0; - SwUndoRedlineSort* pRedlUndo = 0; - SwUndoSort* pUndoSort = 0; - - if( IsRedlineOn() || (!IsIgnoreRedline() && pRedlineTbl->Count() )) - { - pRedlPam = new SwPaM( pStart->nNode, pEnd->nNode, -1, 1 ); - SwCntntNode* pCNd = pRedlPam->GetCntntNode( sal_False ); - if( pCNd ) - pRedlPam->GetMark()->nContent = pCNd->Len(); - - if( IsRedlineOn() && !IsShowOriginal( GetRedlineMode() ) ) - { - if( bUndo ) - { - pRedlUndo = new SwUndoRedlineSort( *pRedlPam,rOpt ); - GetIDocumentUndoRedo().DoUndo(false); - } - // First copy the area - SwNodeIndex aEndIdx( pEnd->nNode, 1 ); - SwNodeRange aRg( pStart->nNode, aEndIdx ); - GetNodes()._Copy( aRg, aEndIdx ); - - // Area is new from pEnd->nNode+1 to aEndIdx - DeleteRedline( *pRedlPam, true, USHRT_MAX ); - - pRedlPam->GetMark()->nNode.Assign( pEnd->nNode.GetNode(), 1 ); - pCNd = pRedlPam->GetCntntNode( sal_False ); - pRedlPam->GetMark()->nContent.Assign( pCNd, 0 ); - - pRedlPam->GetPoint()->nNode.Assign( aEndIdx.GetNode() ); - pCNd = pRedlPam->GetCntntNode( sal_True ); - xub_StrLen nCLen = 0; - if( !pCNd && - 0 != (pCNd = GetNodes()[ aEndIdx.GetIndex()-1 ]->GetCntntNode())) - { - nCLen = pCNd->Len(); - pRedlPam->GetPoint()->nNode.Assign( *pCNd ); - } - pRedlPam->GetPoint()->nContent.Assign( pCNd, nCLen ); - - if( pRedlUndo ) - pRedlUndo->SetValues( rPaM ); - } - else - { - DeleteRedline( *pRedlPam, true, USHRT_MAX ); - delete pRedlPam, pRedlPam = 0; - } - } - - SwNodeIndex aStart(pStart->nNode); - SwSortElement::Init( this, rOpt ); - SwSortElements aSortArr; - while( aStart <= pEnd->nNode ) - { - // Iterate over a selected Area - SwSortTxtElement* pSE = new SwSortTxtElement( aStart ); - aSortArr.Insert(pSE); - aStart++; - } - - // Now comes the tricky part: Move Nodes (and always keep Undo in mind) - sal_uLong nBeg = pStart->nNode.GetIndex(); - SwNodeRange aRg( aStart, aStart ); - - if( bUndo && !pRedlUndo ) - { - pUndoSort = new SwUndoSort(rPaM, rOpt); - GetIDocumentUndoRedo().AppendUndo(pUndoSort); - } - - GetIDocumentUndoRedo().DoUndo(false); - - for ( sal_uInt16 n = 0; n < aSortArr.Count(); ++n ) - { - SwSortTxtElement* pBox = (SwSortTxtElement*)aSortArr[n]; - aStart = nBeg + n; - aRg.aStart = pBox->aPos.GetIndex(); - aRg.aEnd = aRg.aStart.GetIndex() + 1; - - // Move Nodes - MoveNodeRange( aRg, aStart, - IDocumentContentOperations::DOC_MOVEDEFAULT ); - - // Insert Move in Undo - if(pUndoSort) - pUndoSort->Insert(pBox->nOrg, nBeg + n); - } - // Delete all elements from the SortArray - aSortArr.DeleteAndDestroy(0, aSortArr.Count()); - SwSortElement::Finit(); - - if( pRedlPam ) - { - if( pRedlUndo ) - { - pRedlUndo->SetSaveRange( *pRedlPam ); - // UGLY: temp. enable Undo - GetIDocumentUndoRedo().DoUndo(true); - GetIDocumentUndoRedo().AppendUndo( pRedlUndo ); - GetIDocumentUndoRedo().DoUndo(false); - } - - // nBeg is start of sorted range - SwNodeIndex aSttIdx( GetNodes(), nBeg ); - - // the copied range is deleted - SwRedline *const pDeleteRedline( - new SwRedline( nsRedlineType_t::REDLINE_DELETE, *pRedlPam )); - - // pRedlPam points to nodes that may be deleted (hidden) by - // AppendRedline, so adjust it beforehand to prevent ASSERT - pRedlPam->GetPoint()->nNode = aSttIdx; - SwCntntNode* pCNd = aSttIdx.GetNode().GetCntntNode(); - pRedlPam->GetPoint()->nContent.Assign( pCNd, 0 ); - - AppendRedline(pDeleteRedline, true); - - // the sorted range is inserted - AppendRedline( new SwRedline( nsRedlineType_t::REDLINE_INSERT, *pRedlPam ), true); - - if( pRedlUndo ) - { - SwNodeIndex aInsEndIdx( pRedlPam->GetMark()->nNode, -1 ); - pRedlPam->GetMark()->nNode = aInsEndIdx; - SwCntntNode *const pPrevNode = - pRedlPam->GetMark()->nNode.GetNode().GetCntntNode(); - pRedlPam->GetMark()->nContent.Assign( pPrevNode, pPrevNode->Len() ); - - pRedlUndo->SetValues( *pRedlPam ); - } - - if( pRedlUndo ) - pRedlUndo->SetOffset( aSttIdx ); - - delete pRedlPam, pRedlPam = 0; - } - GetIDocumentUndoRedo().DoUndo( bUndo ); - if( bUndo ) - { - GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL ); - } - - return sal_True; -} - -/*-------------------------------------------------------------------- - Description: Sort Table in the Document - --------------------------------------------------------------------*/ -sal_Bool SwDoc::SortTbl(const SwSelBoxes& rBoxes, const SwSortOptions& rOpt) -{ - // Via SwDoc for Undo! - OSL_ENSURE( !rBoxes.empty(), "no valid Box list" ); - SwTableNode* pTblNd = const_cast<SwTableNode*>( rBoxes.begin()->second->GetSttNd()->FindTableNode() ); - if( !pTblNd ) - return sal_False; - - // We begin sorting - // Find all Boxes/Lines - _FndBox aFndBox( 0, 0 ); - { - _FndPara aPara( rBoxes, &aFndBox ); - pTblNd->GetTable().GetTabLines().ForEach( &_FndLineCopyCol, &aPara );; - } - - if(!aFndBox.GetLines().Count()) - return sal_False; - - if( !IsIgnoreRedline() && GetRedlineTbl().Count() ) - DeleteRedline( *pTblNd, true, USHRT_MAX ); - - sal_uInt16 nStart = 0; - if( pTblNd->GetTable().GetRowsToRepeat() > 0 && rOpt.eDirection == SRT_ROWS ) - { - // Uppermost selected Cell - _FndLines& rLines = aFndBox.GetLines(); - - while( nStart < rLines.Count() ) - { - // Respect Split Merge nesting, - // extract the upper most - SwTableLine* pLine = rLines[nStart]->GetLine(); - while ( pLine->GetUpper() ) - pLine = pLine->GetUpper()->GetUpper(); - - if( pTblNd->GetTable().IsHeadline( *pLine ) ) - nStart++; - else - break; - } - // Are all selected in the HeaderLine? -> no Offset - if( nStart == rLines.Count() ) - nStart = 0; - } - - // Switch to relative Formulas - SwTableFmlUpdate aMsgHnt( &pTblNd->GetTable() ); - aMsgHnt.eFlags = TBL_RELBOXNAME; - UpdateTblFlds( &aMsgHnt ); - - // Table as a flat array structure - FlatFndBox aFlatBox(this, aFndBox); - - if(!aFlatBox.IsSymmetric()) - return sal_False; - - // Delete HTML layout - pTblNd->GetTable().SetHTMLTableLayout( 0 ); - - // #i37739# A simple 'MakeFrms' after the node sorting - // does not work if the table is inside a frame and has no prev/next. - SwNode2Layout aNode2Layout( *pTblNd ); - - // Delete the Table's Frames - pTblNd->DelFrms(); - // ? TL_CHART2: ? - - SwUndoSort* pUndoSort = 0; - if (GetIDocumentUndoRedo().DoesUndo()) - { - pUndoSort = new SwUndoSort( rBoxes.begin()->second->GetSttIdx(), - rBoxes.rbegin()->second->GetSttIdx(), - *pTblNd, rOpt, aFlatBox.HasItemSets() ); - GetIDocumentUndoRedo().AppendUndo(pUndoSort); - } - ::sw::UndoGuard const undoGuard(GetIDocumentUndoRedo()); - - // Insert KeyElements - sal_uInt16 nCount = (rOpt.eDirection == SRT_ROWS) ? - aFlatBox.GetRows() : aFlatBox.GetCols(); - - // Sort SortList by Key - SwSortElement::Init( this, rOpt, &aFlatBox ); - SwSortElements aSortList; - - // When sorting, do not include the first row if the HeaderLine is repeated - sal_uInt16 i; - - for( i = nStart; i < nCount; ++i) - { - SwSortBoxElement* pEle = new SwSortBoxElement( i ); - aSortList.Insert(pEle); - } - - // Move after Sorting - SwMovedBoxes aMovedList; - for(i=0; i < aSortList.Count(); ++i) - { - SwSortBoxElement* pBox = (SwSortBoxElement*)aSortList[i]; - if(rOpt.eDirection == SRT_ROWS) - MoveRow(this, aFlatBox, pBox->nRow, i + nStart, aMovedList, pUndoSort); - else - MoveCol(this, aFlatBox, pBox->nRow, i + nStart, aMovedList, pUndoSort); - } - - // Restore table frames: - // #i37739# A simple 'MakeFrms' after the node sorting - // does not work if the table is inside a frame and has no prev/next. - const sal_uLong nIdx = pTblNd->GetIndex(); - aNode2Layout.RestoreUpperFrms( GetNodes(), nIdx, nIdx + 1 ); - - // TL_CHART2: need to inform chart of probably changed cell names - UpdateCharts( pTblNd->GetTable().GetFrmFmt()->GetName() ); - - // Delete all Elements in the SortArray - aSortList.DeleteAndDestroy( 0, aSortList.Count() ); - SwSortElement::Finit(); - - SetModified(); - return sal_True; -} - /*-------------------------------------------------------------------- Description: Move a row --------------------------------------------------------------------*/ |