Update ooo320-m1
[ooovba.git] / sw / source / core / fields / ddetbl.cxx
blobba496601c6fab340a2a942b04a77dcef182f2f7f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ddetbl.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <frmfmt.hxx>
36 #include <doc.hxx>
37 #include <index.hxx>
38 #include <ndtxt.hxx>
39 #include <swtable.hxx>
40 #include <swddetbl.hxx>
41 #include <ddefld.hxx> // fuer den FieldType
42 #include <ndindex.hxx>
43 #include <fldupde.hxx>
44 #include <swtblfmt.hxx>
47 TYPEINIT1( SwDDETable, SwTable );
49 // Constructor movet alle Lines/Boxen aus der SwTable zu sich.
50 // Die SwTable ist danach Leer und muss geloescht werden.
51 SwDDETable::SwDDETable( SwTable& rTable, SwDDEFieldType* pDDEType,
52 BOOL bUpdate )
53 : SwTable( rTable ), aDepend( this, pDDEType )
55 // Kopiere/move die Daten der Tabelle
56 aSortCntBoxes.Insert( &rTable.GetTabSortBoxes(), 0,
57 rTable.GetTabSortBoxes().Count() ); // move die Inh. Boxen
58 rTable.GetTabSortBoxes().Remove( (USHORT)0, rTable.GetTabSortBoxes().Count() );
60 aLines.Insert( &rTable.GetTabLines(),0 ); // move die Lines
61 rTable.GetTabLines().Remove( 0, rTable.GetTabLines().Count() );
63 if( aLines.Count() )
65 const SwNode& rNd = *GetTabSortBoxes()[0]->GetSttNd();
66 if( rNd.GetNodes().IsDocNodes() )
68 // "aktivieren der Updates" (Modify nicht noch mal rufen)
69 aDepend.LockModify();
70 pDDEType->IncRefCnt();
71 aDepend.UnlockModify();
73 // Setzen der Werte in die einzelnen Boxen
74 // update box content only if update flag is set (false in import)
75 if (bUpdate)
76 ChangeContent();
81 __EXPORT SwDDETable::~SwDDETable()
83 SwDDEFieldType* pFldTyp = (SwDDEFieldType*)aDepend.GetRegisteredIn();
84 SwDoc* pDoc = GetFrmFmt()->GetDoc();
85 if( !pDoc->IsInDtor() && aLines.Count() &&
86 GetTabSortBoxes()[0]->GetSttNd()->GetNodes().IsDocNodes() )
87 pFldTyp->DecRefCnt();
89 // sind wir der letzte Abhaengige vom "geloeschten Feld" dann loesche dieses
90 if( pFldTyp->IsDeleted() && pFldTyp->IsLastDepend() )
92 pFldTyp->Remove( &aDepend );
93 delete pFldTyp;
97 void SwDDETable::Modify( SfxPoolItem* pOld, SfxPoolItem* pNew )
99 if( pNew && RES_UPDATEDDETBL == pNew->Which() )
100 ChangeContent();
101 else
102 SwTable::Modify( pOld, pNew );
105 void SwDDETable::ChangeContent()
107 ASSERT( GetFrmFmt(), "Kein FrameFormat" );
109 // Stehen wir im richtigen NodesArray (Wegen UNDO)
110 if( !aLines.Count() )
111 return;
112 ASSERT( GetTabSortBoxes().Count(), "Tabelle ohne Inhalt?" );
113 if( !GetTabSortBoxes()[0]->GetSttNd()->GetNodes().IsDocNodes() )
114 return;
116 // zugriff auf den DDEFldType
117 SwDDEFieldType* pDDEType = (SwDDEFieldType*)aDepend.GetRegisteredIn();
119 String aExpand = pDDEType->GetExpansion();
120 aExpand.EraseAllChars( '\r' );
122 for( USHORT n = 0; n < aLines.Count(); ++n )
124 String aLine = aExpand.GetToken( n, '\n' );
125 SwTableLine* pLine = aLines[ n ];
126 for( USHORT i = 0; i < pLine->GetTabBoxes().Count(); ++i )
128 SwTableBox* pBox = pLine->GetTabBoxes()[ i ];
129 ASSERT( pBox->GetSttIdx(), "keine InhaltsBox" );
130 SwNodeIndex aNdIdx( *pBox->GetSttNd(), 1 );
131 SwTxtNode* pTxtNode = aNdIdx.GetNode().GetTxtNode();
132 ASSERT( pTxtNode, "Kein Node" );
133 SwIndex aCntIdx( pTxtNode, 0 );
134 pTxtNode->EraseText( aCntIdx );
135 pTxtNode->InsertText( aLine.GetToken( i, '\t' ), aCntIdx );
137 SwTableBoxFmt* pBoxFmt = (SwTableBoxFmt*)pBox->GetFrmFmt();
138 pBoxFmt->LockModify();
139 pBoxFmt->ResetFmtAttr( RES_BOXATR_VALUE );
140 pBoxFmt->UnlockModify();
144 const IDocumentSettingAccess* pIDSA = GetFrmFmt()->getIDocumentSettingAccess();
145 SwDoc* pDoc = GetFrmFmt()->GetDoc();
146 if( AUTOUPD_FIELD_AND_CHARTS == pIDSA->getFieldUpdateFlags(true) )
147 pDoc->SetFieldsDirty( true, NULL, 0 );
150 SwDDEFieldType* SwDDETable::GetDDEFldType()
152 return (SwDDEFieldType*)aDepend.GetRegisteredIn();
155 BOOL SwDDETable::NoDDETable()
157 // suche den TabellenNode
158 ASSERT( GetFrmFmt(), "Kein FrameFormat" );
159 SwDoc* pDoc = GetFrmFmt()->GetDoc();
161 // Stehen wir im richtigen NodesArray (Wegen UNDO)
162 if( !aLines.Count() )
163 return FALSE;
164 ASSERT( GetTabSortBoxes().Count(), "Tabelle ohne Inhalt?" );
165 SwNode* pNd = (SwNode*)GetTabSortBoxes()[0]->GetSttNd();
166 if( !pNd->GetNodes().IsDocNodes() )
167 return FALSE;
169 SwTableNode* pTblNd = pNd->FindTableNode();
170 ASSERT( pTblNd, "wo steht denn die Tabelle ?");
172 SwTable* pNewTbl = new SwTable( *this );
174 // Kopiere/move die Daten der Tabelle
175 pNewTbl->GetTabSortBoxes().Insert( &GetTabSortBoxes(), 0,
176 GetTabSortBoxes().Count() ); // move die Inh. Boxen
177 GetTabSortBoxes().Remove( (USHORT)0, GetTabSortBoxes().Count() );
179 pNewTbl->GetTabLines().Insert( &GetTabLines(),0 ); // move die Lines
180 GetTabLines().Remove( 0, GetTabLines().Count() );
182 if( pDoc->GetRootFrm() )
183 ((SwDDEFieldType*)aDepend.GetRegisteredIn())->DecRefCnt();
185 pTblNd->SetNewTable( pNewTbl ); // setze die Tabelle
187 return TRUE;