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