Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <comphelper/string.hxx>
31 : : #include <frmfmt.hxx>
32 : : #include <doc.hxx>
33 : : #include <index.hxx>
34 : : #include <ndtxt.hxx>
35 : : #include <swtable.hxx>
36 : : #include <swddetbl.hxx>
37 : : #include <ddefld.hxx> // fuer den FieldType
38 : : #include <ndindex.hxx>
39 : : #include <fldupde.hxx>
40 : : #include <swtblfmt.hxx>
41 : : #include <fieldhint.hxx>
42 : :
43 [ # # ][ # # ]: 33 : TYPEINIT1( SwDDETable, SwTable );
44 : :
45 : : // Constructor movet alle Lines/Boxen aus der SwTable zu sich.
46 : : // Die SwTable ist danach Leer und muss geloescht werden.
47 : 0 : SwDDETable::SwDDETable( SwTable& rTable, SwDDEFieldType* pDDEType,
48 : : sal_Bool bUpdate )
49 [ # # ]: 0 : : SwTable( rTable ), aDepend( this, pDDEType )
50 : : {
51 : : // Kopiere/move die Daten der Tabelle
52 [ # # ]: 0 : aSortCntBoxes.insert( rTable.GetTabSortBoxes() ); // move die Inh. Boxen
53 : 0 : rTable.GetTabSortBoxes().clear();
54 : :
55 : : aLines.insert( aLines.begin(),
56 [ # # ]: 0 : rTable.GetTabLines().begin(), rTable.GetTabLines().end() ); // move die Lines
57 : 0 : rTable.GetTabLines().clear();
58 : :
59 [ # # ]: 0 : if( !aLines.empty() )
60 : : {
61 [ # # ]: 0 : const SwNode& rNd = *GetTabSortBoxes()[0]->GetSttNd();
62 [ # # ][ # # ]: 0 : if( rNd.GetNodes().IsDocNodes() )
63 : : {
64 : : // mba: swclient refactoring - this code shouldn't have done anything!
65 : : // the ModifyLock Flag is evaluated in SwModify only, though it was accessible via SwClient
66 : : // This has been fixed now
67 : : // aDepend.LockModify();
68 [ # # ]: 0 : pDDEType->IncRefCnt();
69 : : // aDepend.UnlockModify();
70 : :
71 : : // Setzen der Werte in die einzelnen Boxen
72 : : // update box content only if update flag is set (false in import)
73 [ # # ]: 0 : if (bUpdate)
74 [ # # ]: 0 : ChangeContent();
75 : : }
76 : : }
77 : 0 : }
78 : :
79 [ # # ]: 0 : SwDDETable::~SwDDETable()
80 : : {
81 : 0 : SwDDEFieldType* pFldTyp = (SwDDEFieldType*)aDepend.GetRegisteredIn();
82 : 0 : SwDoc* pDoc = GetFrmFmt()->GetDoc();
83 [ # # ][ # # ]: 0 : if( !pDoc->IsInDtor() && !aLines.empty() &&
[ # # ][ # # ]
84 [ # # ][ # # ]: 0 : GetTabSortBoxes()[0]->GetSttNd()->GetNodes().IsDocNodes() )
85 [ # # ]: 0 : pFldTyp->DecRefCnt();
86 : :
87 : : // sind wir der letzte Abhaengige vom "geloeschten Feld" dann loesche dieses
88 [ # # ][ # # ]: 0 : if( pFldTyp->IsDeleted() && pFldTyp->IsLastDepend() )
[ # # ]
89 : : {
90 [ # # ]: 0 : pFldTyp->Remove( &aDepend );
91 [ # # ][ # # ]: 0 : delete pFldTyp;
92 : : }
93 [ # # ]: 0 : }
94 : :
95 : 0 : void SwDDETable::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
96 : : {
97 [ # # ][ # # ]: 0 : if( pNew && RES_UPDATEDDETBL == pNew->Which() )
[ # # ]
98 : 0 : ChangeContent();
99 : : else
100 : 0 : SwTable::Modify( pOld, pNew );
101 : 0 : }
102 : :
103 : 0 : void SwDDETable::SwClientNotify( const SwModify&, const SfxHint& rHint )
104 : : {
105 [ # # ]: 0 : const SwFieldHint* pHint = dynamic_cast<const SwFieldHint*>( &rHint );
106 [ # # ]: 0 : if ( pHint )
107 : : // replace DDETable by real table
108 : 0 : NoDDETable();
109 : 0 : }
110 : :
111 : 0 : void SwDDETable::ChangeContent()
112 : : {
113 : : OSL_ENSURE( GetFrmFmt(), "Kein FrameFormat" );
114 : :
115 : : // Stehen wir im richtigen NodesArray (Wegen UNDO)
116 [ # # ]: 0 : if( aLines.empty() )
117 : : return;
118 : : OSL_ENSURE( !GetTabSortBoxes().empty(), "Tabelle ohne Inhalt?" );
119 [ # # ][ # # ]: 0 : if( !GetTabSortBoxes()[0]->GetSttNd()->GetNodes().IsDocNodes() )
[ # # ]
120 : : return;
121 : :
122 : : // zugriff auf den DDEFldType
123 : 0 : SwDDEFieldType* pDDEType = (SwDDEFieldType*)aDepend.GetRegisteredIn();
124 : :
125 [ # # ][ # # ]: 0 : String aExpand = comphelper::string::remove(pDDEType->GetExpansion(), '\r');
126 : :
127 [ # # ]: 0 : for( sal_uInt16 n = 0; n < aLines.size(); ++n )
128 : : {
129 [ # # ]: 0 : String aLine = aExpand.GetToken( n, '\n' );
130 : 0 : SwTableLine* pLine = aLines[ n ];
131 [ # # ]: 0 : for( sal_uInt16 i = 0; i < pLine->GetTabBoxes().size(); ++i )
132 : : {
133 : 0 : SwTableBox* pBox = pLine->GetTabBoxes()[ i ];
134 : : OSL_ENSURE( pBox->GetSttIdx(), "keine InhaltsBox" );
135 [ # # ]: 0 : SwNodeIndex aNdIdx( *pBox->GetSttNd(), 1 );
136 : 0 : SwTxtNode* pTxtNode = aNdIdx.GetNode().GetTxtNode();
137 : : OSL_ENSURE( pTxtNode, "Kein Node" );
138 [ # # ][ # # ]: 0 : SwIndex aCntIdx( pTxtNode, 0 );
139 [ # # ]: 0 : pTxtNode->EraseText( aCntIdx );
140 [ # # ][ # # ]: 0 : pTxtNode->InsertText( aLine.GetToken( i, '\t' ), aCntIdx );
[ # # ]
141 : :
142 : 0 : SwTableBoxFmt* pBoxFmt = (SwTableBoxFmt*)pBox->GetFrmFmt();
143 : 0 : pBoxFmt->LockModify();
144 [ # # ]: 0 : pBoxFmt->ResetFmtAttr( RES_BOXATR_VALUE );
145 : 0 : pBoxFmt->UnlockModify();
146 [ # # ][ # # ]: 0 : }
147 [ # # ]: 0 : }
148 : :
149 [ # # ]: 0 : const IDocumentSettingAccess* pIDSA = GetFrmFmt()->getIDocumentSettingAccess();
150 : 0 : SwDoc* pDoc = GetFrmFmt()->GetDoc();
151 [ # # ][ # # ]: 0 : if( AUTOUPD_FIELD_AND_CHARTS == pIDSA->getFieldUpdateFlags(true) )
152 [ # # ][ # # ]: 0 : pDoc->SetFieldsDirty( true, NULL, 0 );
153 : : }
154 : :
155 : 0 : SwDDEFieldType* SwDDETable::GetDDEFldType()
156 : : {
157 : 0 : return (SwDDEFieldType*)aDepend.GetRegisteredIn();
158 : : }
159 : :
160 : 0 : sal_Bool SwDDETable::NoDDETable()
161 : : {
162 : : // suche den TabellenNode
163 : : OSL_ENSURE( GetFrmFmt(), "Kein FrameFormat" );
164 : 0 : SwDoc* pDoc = GetFrmFmt()->GetDoc();
165 : :
166 : : // Stehen wir im richtigen NodesArray (Wegen UNDO)
167 [ # # ]: 0 : if( aLines.empty() )
168 : 0 : return sal_False;
169 : : OSL_ENSURE( !GetTabSortBoxes().empty(), "Tabelle ohne Inhalt?" );
170 : 0 : SwNode* pNd = (SwNode*)GetTabSortBoxes()[0]->GetSttNd();
171 [ # # ]: 0 : if( !pNd->GetNodes().IsDocNodes() )
172 : 0 : return sal_False;
173 : :
174 : 0 : SwTableNode* pTblNd = pNd->FindTableNode();
175 : : OSL_ENSURE( pTblNd, "wo steht denn die Tabelle ?");
176 : :
177 [ # # ]: 0 : SwTable* pNewTbl = new SwTable( *this );
178 : :
179 : : // Kopiere/move die Daten der Tabelle
180 : 0 : pNewTbl->GetTabSortBoxes().insert( GetTabSortBoxes() ); // move die Inh. Boxen
181 : 0 : GetTabSortBoxes().clear();
182 : :
183 : 0 : pNewTbl->GetTabLines().insert( pNewTbl->GetTabLines().begin(),
184 : 0 : GetTabLines().begin(), GetTabLines().end() ); // move die Lines
185 : 0 : GetTabLines().clear();
186 : :
187 [ # # ]: 0 : if( pDoc->GetCurrentViewShell() ) //swmod 071108//swmod 071225
188 : 0 : ((SwDDEFieldType*)aDepend.GetRegisteredIn())->DecRefCnt();
189 : :
190 : 0 : pTblNd->SetNewTable( pNewTbl ); // setze die Tabelle
191 : :
192 : 0 : return sal_True;
193 : : }
194 : :
195 : :
196 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|