xref: /aoo41x/main/sw/source/core/fields/ddetbl.cxx (revision efeef26f)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*efeef26fSAndrew Rist  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19*efeef26fSAndrew Rist  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <frmfmt.hxx>
29cdf0e10cSrcweir #include <doc.hxx>
30cdf0e10cSrcweir #include <index.hxx>
31cdf0e10cSrcweir #include <ndtxt.hxx>
32cdf0e10cSrcweir #include <swtable.hxx>
33cdf0e10cSrcweir #include <swddetbl.hxx>
34cdf0e10cSrcweir #include <ddefld.hxx>			// fuer den FieldType
35cdf0e10cSrcweir #include <ndindex.hxx>
36cdf0e10cSrcweir #include <fldupde.hxx>
37cdf0e10cSrcweir #include <swtblfmt.hxx>
38cdf0e10cSrcweir #include <fieldhint.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir TYPEINIT1( SwDDETable, SwTable );
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 	// Constructor movet alle Lines/Boxen aus der SwTable zu sich.
43cdf0e10cSrcweir 	// Die SwTable ist danach Leer und muss geloescht werden.
SwDDETable(SwTable & rTable,SwDDEFieldType * pDDEType,sal_Bool bUpdate)44cdf0e10cSrcweir SwDDETable::SwDDETable( SwTable& rTable, SwDDEFieldType* pDDEType,
45cdf0e10cSrcweir 						sal_Bool bUpdate )
46cdf0e10cSrcweir 	: SwTable( rTable ), aDepend( this, pDDEType )
47cdf0e10cSrcweir {
48cdf0e10cSrcweir 	// Kopiere/move die Daten der Tabelle
49cdf0e10cSrcweir 	aSortCntBoxes.Insert( &rTable.GetTabSortBoxes(), 0,
50cdf0e10cSrcweir 						  rTable.GetTabSortBoxes().Count()  ); // move die Inh. Boxen
51cdf0e10cSrcweir 	rTable.GetTabSortBoxes().Remove( (sal_uInt16)0, rTable.GetTabSortBoxes().Count() );
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 	aLines.Insert( &rTable.GetTabLines(),0 );						// move die Lines
54cdf0e10cSrcweir 	rTable.GetTabLines().Remove( 0, rTable.GetTabLines().Count() );
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 	if( aLines.Count() )
57cdf0e10cSrcweir 	{
58cdf0e10cSrcweir         const SwNode& rNd = *GetTabSortBoxes()[0]->GetSttNd();
59cdf0e10cSrcweir 		if( rNd.GetNodes().IsDocNodes() )
60cdf0e10cSrcweir 		{
61cdf0e10cSrcweir             // mba: swclient refactoring - this code shouldn't have done anything!
62cdf0e10cSrcweir             // the ModifyLock Flag is evaluated in SwModify only, though it was accessible via SwClient
63cdf0e10cSrcweir             // This has been fixed now
64cdf0e10cSrcweir //			aDepend.LockModify();
65cdf0e10cSrcweir 			pDDEType->IncRefCnt();
66cdf0e10cSrcweir //			aDepend.UnlockModify();
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 			// Setzen der Werte in die einzelnen Boxen
69cdf0e10cSrcweir 			// update box content only if update flag is set (false in import)
70cdf0e10cSrcweir 			if (bUpdate)
71cdf0e10cSrcweir 				ChangeContent();
72cdf0e10cSrcweir 		}
73cdf0e10cSrcweir 	}
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
~SwDDETable()76cdf0e10cSrcweir __EXPORT SwDDETable::~SwDDETable()
77cdf0e10cSrcweir {
78cdf0e10cSrcweir 	SwDDEFieldType* pFldTyp = (SwDDEFieldType*)aDepend.GetRegisteredIn();
79cdf0e10cSrcweir 	SwDoc* pDoc = GetFrmFmt()->GetDoc();
80cdf0e10cSrcweir 	if( !pDoc->IsInDtor() && aLines.Count() &&
81cdf0e10cSrcweir 		GetTabSortBoxes()[0]->GetSttNd()->GetNodes().IsDocNodes() )
82cdf0e10cSrcweir 		pFldTyp->DecRefCnt();
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 	// sind wir der letzte Abhaengige vom "geloeschten Feld" dann loesche dieses
85cdf0e10cSrcweir 	if( pFldTyp->IsDeleted() && pFldTyp->IsLastDepend() )
86cdf0e10cSrcweir 	{
87cdf0e10cSrcweir 		pFldTyp->Remove( &aDepend );
88cdf0e10cSrcweir 		delete pFldTyp;
89cdf0e10cSrcweir 	}
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)92cdf0e10cSrcweir void SwDDETable::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
93cdf0e10cSrcweir {
94cdf0e10cSrcweir 	if( pNew && RES_UPDATEDDETBL == pNew->Which() )
95cdf0e10cSrcweir 		ChangeContent();
96cdf0e10cSrcweir 	else
97cdf0e10cSrcweir 		SwTable::Modify( pOld, pNew );
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
SwClientNotify(const SwModify &,const SfxHint & rHint)100cdf0e10cSrcweir void SwDDETable::SwClientNotify( const SwModify&, const SfxHint& rHint )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir     const SwFieldHint* pHint = dynamic_cast<const SwFieldHint*>( &rHint );
103cdf0e10cSrcweir     if ( pHint )
104cdf0e10cSrcweir         // replace DDETable by real table
105cdf0e10cSrcweir         NoDDETable();
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
ChangeContent()108cdf0e10cSrcweir void SwDDETable::ChangeContent()
109cdf0e10cSrcweir {
110cdf0e10cSrcweir 	ASSERT( GetFrmFmt(), "Kein FrameFormat" );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	// Stehen wir im richtigen NodesArray (Wegen UNDO)
113cdf0e10cSrcweir 	if( !aLines.Count() )
114cdf0e10cSrcweir 		return;
115cdf0e10cSrcweir 	ASSERT( GetTabSortBoxes().Count(), "Tabelle ohne Inhalt?" );
116cdf0e10cSrcweir 	if( !GetTabSortBoxes()[0]->GetSttNd()->GetNodes().IsDocNodes() )
117cdf0e10cSrcweir 		return;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	// zugriff auf den DDEFldType
120cdf0e10cSrcweir 	SwDDEFieldType* pDDEType = (SwDDEFieldType*)aDepend.GetRegisteredIn();
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 	String aExpand = pDDEType->GetExpansion();
123cdf0e10cSrcweir 	aExpand.EraseAllChars( '\r' );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	for( sal_uInt16 n = 0; n < aLines.Count(); ++n )
126cdf0e10cSrcweir 	{
127cdf0e10cSrcweir 		String aLine = aExpand.GetToken( n, '\n' );
128cdf0e10cSrcweir 		SwTableLine* pLine = aLines[ n ];
129cdf0e10cSrcweir 		for( sal_uInt16 i = 0; i < pLine->GetTabBoxes().Count(); ++i )
130cdf0e10cSrcweir 		{
131cdf0e10cSrcweir 			SwTableBox* pBox = pLine->GetTabBoxes()[ i ];
132cdf0e10cSrcweir 			ASSERT( pBox->GetSttIdx(), "keine InhaltsBox" );
133cdf0e10cSrcweir 			SwNodeIndex aNdIdx( *pBox->GetSttNd(), 1 );
134cdf0e10cSrcweir 			SwTxtNode* pTxtNode = aNdIdx.GetNode().GetTxtNode();
135cdf0e10cSrcweir 			ASSERT( pTxtNode, "Kein Node" );
136cdf0e10cSrcweir 			SwIndex aCntIdx( pTxtNode, 0 );
137cdf0e10cSrcweir             pTxtNode->EraseText( aCntIdx );
138cdf0e10cSrcweir             pTxtNode->InsertText( aLine.GetToken( i, '\t' ), aCntIdx );
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 			SwTableBoxFmt* pBoxFmt = (SwTableBoxFmt*)pBox->GetFrmFmt();
141cdf0e10cSrcweir 			pBoxFmt->LockModify();
142cdf0e10cSrcweir             pBoxFmt->ResetFmtAttr( RES_BOXATR_VALUE );
143cdf0e10cSrcweir 			pBoxFmt->UnlockModify();
144cdf0e10cSrcweir 		}
145cdf0e10cSrcweir 	}
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     const IDocumentSettingAccess* pIDSA = GetFrmFmt()->getIDocumentSettingAccess();
148cdf0e10cSrcweir     SwDoc* pDoc = GetFrmFmt()->GetDoc();
149cdf0e10cSrcweir     if( AUTOUPD_FIELD_AND_CHARTS == pIDSA->getFieldUpdateFlags(true) )
150cdf0e10cSrcweir 		pDoc->SetFieldsDirty( true, NULL, 0 );
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
GetDDEFldType()153cdf0e10cSrcweir SwDDEFieldType* SwDDETable::GetDDEFldType()
154cdf0e10cSrcweir {
155cdf0e10cSrcweir 	return (SwDDEFieldType*)aDepend.GetRegisteredIn();
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
NoDDETable()158cdf0e10cSrcweir sal_Bool SwDDETable::NoDDETable()
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	// suche den TabellenNode
161cdf0e10cSrcweir 	ASSERT( GetFrmFmt(), "Kein FrameFormat" );
162cdf0e10cSrcweir 	SwDoc* pDoc = GetFrmFmt()->GetDoc();
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 	// Stehen wir im richtigen NodesArray (Wegen UNDO)
165cdf0e10cSrcweir 	if( !aLines.Count() )
166cdf0e10cSrcweir 		return sal_False;
167cdf0e10cSrcweir 	ASSERT( GetTabSortBoxes().Count(), "Tabelle ohne Inhalt?" );
168cdf0e10cSrcweir 	SwNode* pNd = (SwNode*)GetTabSortBoxes()[0]->GetSttNd();
169cdf0e10cSrcweir 	if( !pNd->GetNodes().IsDocNodes() )
170cdf0e10cSrcweir 		return sal_False;
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 	SwTableNode* pTblNd = pNd->FindTableNode();
173cdf0e10cSrcweir 	ASSERT( pTblNd, "wo steht denn die Tabelle ?");
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 	SwTable* pNewTbl = new SwTable( *this );
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 	// Kopiere/move die Daten der Tabelle
178cdf0e10cSrcweir 	pNewTbl->GetTabSortBoxes().Insert( &GetTabSortBoxes(), 0,
179cdf0e10cSrcweir 						  GetTabSortBoxes().Count()  ); // move die Inh. Boxen
180cdf0e10cSrcweir 	GetTabSortBoxes().Remove( (sal_uInt16)0, GetTabSortBoxes().Count() );
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 	pNewTbl->GetTabLines().Insert( &GetTabLines(),0 );                      // move die Lines
183cdf0e10cSrcweir 	GetTabLines().Remove( 0, GetTabLines().Count() );
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 	if( pDoc->GetCurrentViewShell() )	//swmod 071108//swmod 071225
186cdf0e10cSrcweir 		((SwDDEFieldType*)aDepend.GetRegisteredIn())->DecRefCnt();
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 	pTblNd->SetNewTable( pNewTbl );       // setze die Tabelle
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 	return sal_True;
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 
194