xref: /aoo41x/main/sw/source/filter/writer/writer.cxx (revision dec99bbd)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10efeef26fSAndrew Rist  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19efeef26fSAndrew Rist  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir #include <hintids.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #define _SVSTDARR_STRINGSSORTDTOR
29cdf0e10cSrcweir #include <svl/svstdarr.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <sot/storage.hxx>
32cdf0e10cSrcweir #include <sfx2/docfile.hxx>
33cdf0e10cSrcweir #include <svl/urihelper.hxx>
34cdf0e10cSrcweir #include <svtools/filter.hxx>
35cdf0e10cSrcweir #include <editeng/fontitem.hxx>
36cdf0e10cSrcweir #include <editeng/eeitem.hxx>
37cdf0e10cSrcweir #include <shellio.hxx>
38cdf0e10cSrcweir #include <pam.hxx>
39cdf0e10cSrcweir #include <doc.hxx>
40cdf0e10cSrcweir #include <docary.hxx>
41cdf0e10cSrcweir #include <IMark.hxx>
42cdf0e10cSrcweir #include <numrule.hxx>
43cdf0e10cSrcweir #include <swerror.h>
44cdf0e10cSrcweir #include <boost/bind.hpp>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir using namespace ::com::sun::star;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 
49cdf0e10cSrcweir // Stringbuffer fuer die umgewandelten Zahlen
50cdf0e10cSrcweir static sal_Char aNToABuf[] = "0000000000000000000000000";
51cdf0e10cSrcweir #define NTOABUFLEN (sizeof(aNToABuf))
52cdf0e10cSrcweir 
53cdf0e10cSrcweir DECLARE_TABLE( SwBookmarkNodeTable, SvPtrarr* )
54cdf0e10cSrcweir 
55cdf0e10cSrcweir struct Writer_Impl
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     SvStream * m_pStream;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	SvStringsSortDtor *pSrcArr, *pDestArr;
60cdf0e10cSrcweir 	SvPtrarr* pFontRemoveLst, *pBkmkArr;
61cdf0e10cSrcweir 	SwBookmarkNodeTable* pBkmkNodePos;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     Writer_Impl();
64cdf0e10cSrcweir 	~Writer_Impl();
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 	void RemoveFontList( SwDoc& rDoc );
67cdf0e10cSrcweir 	void InsertBkmk( const ::sw::mark::IMark& rBkmk );
68cdf0e10cSrcweir };
69cdf0e10cSrcweir 
Writer_Impl()70cdf0e10cSrcweir Writer_Impl::Writer_Impl()
71cdf0e10cSrcweir     : m_pStream(0)
72cdf0e10cSrcweir     , pSrcArr( 0 ), pDestArr( 0 ), pFontRemoveLst( 0 ), pBkmkNodePos( 0 )
73cdf0e10cSrcweir {
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
~Writer_Impl()76cdf0e10cSrcweir Writer_Impl::~Writer_Impl()
77cdf0e10cSrcweir {
78cdf0e10cSrcweir 	delete pSrcArr;
79cdf0e10cSrcweir 	delete pDestArr;
80cdf0e10cSrcweir 	delete pFontRemoveLst;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 	if( pBkmkNodePos )
83cdf0e10cSrcweir 	{
84cdf0e10cSrcweir 		for( SvPtrarr* p = pBkmkNodePos->First(); p; p = pBkmkNodePos->Next() )
85cdf0e10cSrcweir 			delete p;
86cdf0e10cSrcweir 		delete pBkmkNodePos;
87cdf0e10cSrcweir 	}
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
RemoveFontList(SwDoc & rDoc)90cdf0e10cSrcweir void Writer_Impl::RemoveFontList( SwDoc& rDoc )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir 	ASSERT( pFontRemoveLst, "wo ist die FontListe?" );
93cdf0e10cSrcweir 	for( sal_uInt16 i = pFontRemoveLst->Count(); i; )
94cdf0e10cSrcweir 	{
95cdf0e10cSrcweir 		SvxFontItem* pItem = (SvxFontItem*)(*pFontRemoveLst)[ --i ];
96cdf0e10cSrcweir 		rDoc.GetAttrPool().Remove( *pItem );
97cdf0e10cSrcweir 	}
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
InsertBkmk(const::sw::mark::IMark & rBkmk)100cdf0e10cSrcweir void Writer_Impl::InsertBkmk(const ::sw::mark::IMark& rBkmk)
101cdf0e10cSrcweir {
102cdf0e10cSrcweir     if( !pBkmkNodePos )
103cdf0e10cSrcweir         pBkmkNodePos = new SwBookmarkNodeTable;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     sal_uLong nNd = rBkmk.GetMarkPos().nNode.GetIndex();
106cdf0e10cSrcweir     SvPtrarr* pArr = pBkmkNodePos->Get( nNd );
107cdf0e10cSrcweir     if( !pArr )
108cdf0e10cSrcweir     {
109cdf0e10cSrcweir         pArr = new SvPtrarr( 1, 4 );
110cdf0e10cSrcweir         pBkmkNodePos->Insert( nNd, pArr );
111cdf0e10cSrcweir     }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     void* p = (void*)&rBkmk;
114cdf0e10cSrcweir     pArr->Insert( p, pArr->Count() );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     if(rBkmk.IsExpanded() && rBkmk.GetOtherMarkPos().nNode != nNd)
117cdf0e10cSrcweir     {
118cdf0e10cSrcweir         nNd = rBkmk.GetOtherMarkPos().nNode.GetIndex();
119cdf0e10cSrcweir         pArr = pBkmkNodePos->Get( nNd );
120cdf0e10cSrcweir         if( !pArr )
121cdf0e10cSrcweir         {
122cdf0e10cSrcweir             pArr = new SvPtrarr( 1, 4 );
123cdf0e10cSrcweir             pBkmkNodePos->Insert( nNd, pArr );
124cdf0e10cSrcweir         }
125cdf0e10cSrcweir         pArr->Insert( p, pArr->Count() );
126cdf0e10cSrcweir     }
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir /*
130cdf0e10cSrcweir  * Dieses Modul ist die Zentrale-Sammelstelle fuer alle Write-Filter
131cdf0e10cSrcweir  * und ist eine DLL !
132cdf0e10cSrcweir  *
133cdf0e10cSrcweir  * Damit der Writer mit den unterschiedlichen Writern arbeiten kann,
134cdf0e10cSrcweir  * muessen fuer diese die Ausgabe-Funktionen der Inhalts tragenden
135cdf0e10cSrcweir  * Objecte auf die verschiedenen Ausgabe-Funktionen gemappt werden.
136cdf0e10cSrcweir  *
137cdf0e10cSrcweir  * Dazu kann fuer jedes Object ueber den Which-Wert in einen Tabelle ge-
138cdf0e10cSrcweir  * griffen werden, um seine Ausgabe-Funktion zu erfragen.
139cdf0e10cSrcweir  * Diese Funktionen stehen in den entsprechenden Writer-DLL's.
140cdf0e10cSrcweir  */
141cdf0e10cSrcweir 
Writer()142cdf0e10cSrcweir Writer::Writer()
143cdf0e10cSrcweir     : m_pImpl(new Writer_Impl)
144cdf0e10cSrcweir     , pOrigPam(0), pOrigFileName(0), pDoc(0), pCurPam(0)
145cdf0e10cSrcweir {
146cdf0e10cSrcweir 	bWriteAll = bShowProgress = bUCS2_WithStartChar = true;
147cdf0e10cSrcweir 	bASCII_NoLastLineEnd = bASCII_ParaAsBlanc = bASCII_ParaAsCR =
148cdf0e10cSrcweir 		bWriteClipboardDoc = bWriteOnlyFirstTable = bBlock =
149cdf0e10cSrcweir 		bOrganizerMode = false;
150cdf0e10cSrcweir     bExportPargraphNumbering = sal_True;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
~Writer()153cdf0e10cSrcweir Writer::~Writer()
154cdf0e10cSrcweir {
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir /*
158cdf0e10cSrcweir  * Document Interface Access
159cdf0e10cSrcweir  */
getIDocumentSettingAccess()160cdf0e10cSrcweir IDocumentSettingAccess* Writer::getIDocumentSettingAccess() { return pDoc; }
getIDocumentSettingAccess() const161cdf0e10cSrcweir const IDocumentSettingAccess* Writer::getIDocumentSettingAccess() const { return pDoc; }
getIDocumentStylePoolAccess()162cdf0e10cSrcweir IDocumentStylePoolAccess* Writer::getIDocumentStylePoolAccess() { return pDoc; }
getIDocumentStylePoolAccess() const163cdf0e10cSrcweir const IDocumentStylePoolAccess* Writer::getIDocumentStylePoolAccess() const { return pDoc; }
164cdf0e10cSrcweir 
ResetWriter()165cdf0e10cSrcweir void Writer::ResetWriter()
166cdf0e10cSrcweir {
167cdf0e10cSrcweir     if (m_pImpl->pFontRemoveLst)
168cdf0e10cSrcweir     {
169cdf0e10cSrcweir         m_pImpl->RemoveFontList( *pDoc );
170cdf0e10cSrcweir     }
171cdf0e10cSrcweir     m_pImpl.reset(new Writer_Impl);
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 	if( pCurPam )
174cdf0e10cSrcweir 	{
175cdf0e10cSrcweir 		while( pCurPam->GetNext() != pCurPam )
176cdf0e10cSrcweir 			delete pCurPam->GetNext();
177cdf0e10cSrcweir 		delete pCurPam;
178cdf0e10cSrcweir 	}
179cdf0e10cSrcweir 	pCurPam = 0;
180cdf0e10cSrcweir 	pOrigFileName = 0;
181cdf0e10cSrcweir 	pDoc = 0;
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 	bShowProgress = bUCS2_WithStartChar = sal_True;
184cdf0e10cSrcweir 	bASCII_NoLastLineEnd = bASCII_ParaAsBlanc = bASCII_ParaAsCR =
185cdf0e10cSrcweir 		bWriteClipboardDoc = bWriteOnlyFirstTable = bBlock =
186cdf0e10cSrcweir 		bOrganizerMode = sal_False;
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
CopyNextPam(SwPaM ** ppPam)189cdf0e10cSrcweir sal_Bool Writer::CopyNextPam( SwPaM ** ppPam )
190cdf0e10cSrcweir {
191cdf0e10cSrcweir 	if( (*ppPam)->GetNext() == pOrigPam )
192cdf0e10cSrcweir 	{
193cdf0e10cSrcweir 		*ppPam = pOrigPam;			// wieder auf den Anfangs-Pam setzen
194cdf0e10cSrcweir 		return sal_False;				// Ende vom Ring
195cdf0e10cSrcweir 	}
196cdf0e10cSrcweir 
197cdf0e10cSrcweir 	// ansonsten kopiere den die Werte aus dem naechsten Pam
198cdf0e10cSrcweir 	*ppPam = ((SwPaM*)(*ppPam)->GetNext() );
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 	*pCurPam->GetPoint() = *(*ppPam)->Start();
201cdf0e10cSrcweir 	*pCurPam->GetMark() = *(*ppPam)->End();
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 	return sal_True;
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir // suche die naechste Bookmark-Position aus der Bookmark-Tabelle
207cdf0e10cSrcweir 
FindPos_Bkmk(const SwPosition & rPos) const208cdf0e10cSrcweir sal_Int32 Writer::FindPos_Bkmk(const SwPosition& rPos) const
209cdf0e10cSrcweir {
210cdf0e10cSrcweir     const IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
211cdf0e10cSrcweir     const IDocumentMarkAccess::const_iterator_t ppBkmk = ::std::lower_bound(
212*dec99bbdSOliver-Rainer Wittmann         pMarkAccess->getAllMarksBegin(),
213*dec99bbdSOliver-Rainer Wittmann         pMarkAccess->getAllMarksEnd(),
214cdf0e10cSrcweir         rPos,
215cdf0e10cSrcweir         ::boost::bind(&::sw::mark::IMark::StartsBefore, _1, _2)); // find the first Mark that does not start before
216*dec99bbdSOliver-Rainer Wittmann     if(ppBkmk != pMarkAccess->getAllMarksEnd())
217*dec99bbdSOliver-Rainer Wittmann         return ppBkmk - pMarkAccess->getAllMarksBegin();
218cdf0e10cSrcweir     return -1;
219cdf0e10cSrcweir }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 
222cdf0e10cSrcweir SwPaM *
NewSwPaM(SwDoc & rDoc,sal_uLong const nStartIdx,sal_uLong const nEndIdx)223cdf0e10cSrcweir Writer::NewSwPaM(SwDoc & rDoc, sal_uLong const nStartIdx, sal_uLong const nEndIdx)
224cdf0e10cSrcweir {
225cdf0e10cSrcweir     SwNodes *const pNds = &rDoc.GetNodes();
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 	SwNodeIndex aStt( *pNds, nStartIdx );
228cdf0e10cSrcweir 	SwCntntNode* pCNode = aStt.GetNode().GetCntntNode();
229cdf0e10cSrcweir 	if( !pCNode && 0 == ( pCNode = pNds->GoNext( &aStt )) )
230cdf0e10cSrcweir     {
231cdf0e10cSrcweir 		ASSERT( false, "An StartPos kein ContentNode mehr" );
232cdf0e10cSrcweir     }
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 	SwPaM* pNew = new SwPaM( aStt );
235cdf0e10cSrcweir 	pNew->SetMark();
236cdf0e10cSrcweir 	aStt = nEndIdx;
237cdf0e10cSrcweir 	if( 0 == (pCNode = aStt.GetNode().GetCntntNode()) &&
238cdf0e10cSrcweir 		0 == (pCNode = pNds->GoPrevious( &aStt )) )
239cdf0e10cSrcweir     {
240cdf0e10cSrcweir 		ASSERT( false, "An StartPos kein ContentNode mehr" );
241cdf0e10cSrcweir     }
242cdf0e10cSrcweir 	pCNode->MakeEndIndex( &pNew->GetPoint()->nContent );
243cdf0e10cSrcweir 	pNew->GetPoint()->nNode = aStt;
244cdf0e10cSrcweir 	return pNew;
245cdf0e10cSrcweir }
246cdf0e10cSrcweir 
247cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////////////
248cdf0e10cSrcweir 
249cdf0e10cSrcweir // Stream-spezifisches
Strm()250cdf0e10cSrcweir SvStream& Writer::Strm()
251cdf0e10cSrcweir {
252cdf0e10cSrcweir     ASSERT( m_pImpl->m_pStream, "Oh-oh. Writer with no Stream!" );
253cdf0e10cSrcweir     return *m_pImpl->m_pStream;
254cdf0e10cSrcweir }
255cdf0e10cSrcweir 
SetStream(SvStream * const pStream)256cdf0e10cSrcweir void Writer::SetStream(SvStream *const pStream)
257cdf0e10cSrcweir { m_pImpl->m_pStream = pStream; }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir 
OutHex(SvStream & rStrm,sal_uLong nHex,sal_uInt8 nLen)260cdf0e10cSrcweir SvStream& Writer::OutHex( SvStream& rStrm, sal_uLong nHex, sal_uInt8 nLen )
261cdf0e10cSrcweir {												   // in einen Stream aus
262cdf0e10cSrcweir 	// Pointer an das Bufferende setzen
263cdf0e10cSrcweir 	sal_Char* pStr = aNToABuf + (NTOABUFLEN-1);
264cdf0e10cSrcweir 	for( sal_uInt8 n = 0; n < nLen; ++n )
265cdf0e10cSrcweir 	{
266cdf0e10cSrcweir 		*(--pStr) = (sal_Char)(nHex & 0xf ) + 48;
267cdf0e10cSrcweir 		if( *pStr > '9' )
268cdf0e10cSrcweir 			*pStr += 39;
269cdf0e10cSrcweir 		nHex >>= 4;
270cdf0e10cSrcweir 	}
271cdf0e10cSrcweir 	return rStrm << pStr;
272cdf0e10cSrcweir }
273cdf0e10cSrcweir 
OutLong(SvStream & rStrm,long nVal)274cdf0e10cSrcweir SvStream& Writer::OutLong( SvStream& rStrm, long nVal )
275cdf0e10cSrcweir {
276cdf0e10cSrcweir 	// Pointer an das Bufferende setzen
277cdf0e10cSrcweir 	sal_Char* pStr = aNToABuf + (NTOABUFLEN-1);
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 	int bNeg = nVal < 0;
280cdf0e10cSrcweir 	if( bNeg )
281cdf0e10cSrcweir 		nVal = -nVal;
282cdf0e10cSrcweir 
283cdf0e10cSrcweir 	do {
284cdf0e10cSrcweir 		*(--pStr) = (sal_Char)(nVal % 10 ) + 48;
285cdf0e10cSrcweir 		nVal /= 10;
286cdf0e10cSrcweir 	} while( nVal );
287cdf0e10cSrcweir 
288cdf0e10cSrcweir 	// Ist Zahl negativ, dann noch -
289cdf0e10cSrcweir 	if( bNeg )
290cdf0e10cSrcweir 		*(--pStr) = '-';
291cdf0e10cSrcweir 
292cdf0e10cSrcweir 	return rStrm << pStr;
293cdf0e10cSrcweir }
294cdf0e10cSrcweir 
OutULong(SvStream & rStrm,sal_uLong nVal)295cdf0e10cSrcweir SvStream& Writer::OutULong( SvStream& rStrm, sal_uLong nVal )
296cdf0e10cSrcweir {
297cdf0e10cSrcweir 	// Pointer an das Bufferende setzen
298cdf0e10cSrcweir 	sal_Char* pStr = aNToABuf + (NTOABUFLEN-1);
299cdf0e10cSrcweir 
300cdf0e10cSrcweir 	do {
301cdf0e10cSrcweir 		*(--pStr) = (sal_Char)(nVal % 10 ) + 48;
302cdf0e10cSrcweir 		nVal /= 10;
303cdf0e10cSrcweir 	} while ( nVal );
304cdf0e10cSrcweir 	return rStrm << pStr;
305cdf0e10cSrcweir }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir 
Write(SwPaM & rPaM,SvStream & rStrm,const String * pFName)308cdf0e10cSrcweir sal_uLong Writer::Write( SwPaM& rPaM, SvStream& rStrm, const String* pFName )
309cdf0e10cSrcweir {
310cdf0e10cSrcweir     if ( IsStgWriter() )
311cdf0e10cSrcweir     {
312cdf0e10cSrcweir         SotStorageRef aRef = new SotStorage( rStrm );
313cdf0e10cSrcweir         sal_uLong nResult = Write( rPaM, *aRef, pFName );
314cdf0e10cSrcweir 		if ( nResult == ERRCODE_NONE )
315cdf0e10cSrcweir 			aRef->Commit();
316cdf0e10cSrcweir 		return nResult;
317cdf0e10cSrcweir     }
318cdf0e10cSrcweir 
319cdf0e10cSrcweir 	pDoc = rPaM.GetDoc();
320cdf0e10cSrcweir 	pOrigFileName = pFName;
321cdf0e10cSrcweir     m_pImpl->m_pStream = &rStrm;
322cdf0e10cSrcweir 
323cdf0e10cSrcweir 	// PaM kopieren, damit er veraendert werden kann
324cdf0e10cSrcweir 	pCurPam = new SwPaM( *rPaM.End(), *rPaM.Start() );
325cdf0e10cSrcweir 	// zum Vergleich auf den akt. Pam sichern
326cdf0e10cSrcweir 	pOrigPam = &rPaM;
327cdf0e10cSrcweir 
328cdf0e10cSrcweir 	sal_uLong nRet = WriteStream();
329cdf0e10cSrcweir 
330cdf0e10cSrcweir 	ResetWriter();
331cdf0e10cSrcweir 
332cdf0e10cSrcweir 	return nRet;
333cdf0e10cSrcweir }
334cdf0e10cSrcweir 
Write(SwPaM & rPam,SfxMedium & rMed,const String * pFileName)335cdf0e10cSrcweir sal_uLong Writer::Write( SwPaM& rPam, SfxMedium& rMed, const String* pFileName )
336cdf0e10cSrcweir {
337cdf0e10cSrcweir 	// This method must be overloaded in SwXMLWriter a storage from medium will be used there.
338cdf0e10cSrcweir 	// The microsoft format can write to storage but the storage will be based on the stream.
339cdf0e10cSrcweir 	return Write( rPam, *rMed.GetOutStream(), pFileName );
340cdf0e10cSrcweir }
341cdf0e10cSrcweir 
Write(SwPaM &,SvStorage &,const String *)342cdf0e10cSrcweir sal_uLong Writer::Write( SwPaM& /*rPam*/, SvStorage&, const String* )
343cdf0e10cSrcweir {
344cdf0e10cSrcweir 	ASSERT( !this, "Schreiben in Storages auf einem Stream?" );
345cdf0e10cSrcweir 	return ERR_SWG_WRITE_ERROR;
346cdf0e10cSrcweir }
347cdf0e10cSrcweir 
Write(SwPaM &,const uno::Reference<embed::XStorage> &,const String *,SfxMedium *)348cdf0e10cSrcweir sal_uLong Writer::Write( SwPaM&, const uno::Reference < embed::XStorage >&, const String*, SfxMedium* )
349cdf0e10cSrcweir {
350cdf0e10cSrcweir 	ASSERT( !this, "Schreiben in Storages auf einem Stream?" );
351cdf0e10cSrcweir 	return ERR_SWG_WRITE_ERROR;
352cdf0e10cSrcweir }
353cdf0e10cSrcweir 
CopyLocalFileToINet(String & rFileNm)354cdf0e10cSrcweir sal_Bool Writer::CopyLocalFileToINet( String& rFileNm )
355cdf0e10cSrcweir {
356cdf0e10cSrcweir 	if( !pOrigFileName )		        // can be happen, by example if we
357cdf0e10cSrcweir 		return sal_False;                   // write into the clipboard
358cdf0e10cSrcweir 
359cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
360cdf0e10cSrcweir 	INetURLObject aFileUrl( rFileNm ), aTargetUrl( *pOrigFileName );
361cdf0e10cSrcweir 
362cdf0e10cSrcweir // JP 01.11.00: what is the correct question for the portal??
363cdf0e10cSrcweir //	if( aFileUrl.GetProtocol() == aFileUrl.GetProtocol() )
364cdf0e10cSrcweir //		return bRet;
365cdf0e10cSrcweir // this is our old without the Mail-Export
366cdf0e10cSrcweir     if( ! ( INET_PROT_FILE == aFileUrl.GetProtocol() &&
367cdf0e10cSrcweir 			INET_PROT_FILE != aTargetUrl.GetProtocol() &&
368cdf0e10cSrcweir         	INET_PROT_FTP <= aTargetUrl.GetProtocol() &&
369cdf0e10cSrcweir         	INET_PROT_NEWS >= aTargetUrl.GetProtocol() ) )
370cdf0e10cSrcweir 		return bRet;
371cdf0e10cSrcweir 
372cdf0e10cSrcweir     if (m_pImpl->pSrcArr)
373cdf0e10cSrcweir 	{
374cdf0e10cSrcweir 		// wurde die Datei schon verschoben
375cdf0e10cSrcweir 		sal_uInt16 nPos;
376cdf0e10cSrcweir         if (m_pImpl->pSrcArr->Seek_Entry( &rFileNm, &nPos ))
377cdf0e10cSrcweir         {
378cdf0e10cSrcweir             rFileNm = *(*m_pImpl->pDestArr)[ nPos ];
379cdf0e10cSrcweir 			return sal_True;
380cdf0e10cSrcweir 		}
381cdf0e10cSrcweir 	}
382cdf0e10cSrcweir 	else
383cdf0e10cSrcweir     {
384cdf0e10cSrcweir         m_pImpl->pSrcArr = new SvStringsSortDtor( 4, 4 );
385cdf0e10cSrcweir         m_pImpl->pDestArr = new SvStringsSortDtor( 4, 4 );
386cdf0e10cSrcweir     }
387cdf0e10cSrcweir 
388cdf0e10cSrcweir 	String *pSrc = new String( rFileNm );
389cdf0e10cSrcweir 	String *pDest = new String( aTargetUrl.GetPartBeforeLastName() );
390cdf0e10cSrcweir 	*pDest += String(aFileUrl.GetName());
391cdf0e10cSrcweir 
392cdf0e10cSrcweir 	SfxMedium aSrcFile( *pSrc, STREAM_READ, sal_False );
393cdf0e10cSrcweir 	SfxMedium aDstFile( *pDest, STREAM_WRITE | STREAM_SHARE_DENYNONE, sal_False );
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 	*aDstFile.GetOutStream() << *aSrcFile.GetInStream();
396cdf0e10cSrcweir 
397cdf0e10cSrcweir 	aSrcFile.Close();
398cdf0e10cSrcweir 	aDstFile.Commit();
399cdf0e10cSrcweir 
400cdf0e10cSrcweir 	bRet = 0 == aDstFile.GetError();
401cdf0e10cSrcweir 
402cdf0e10cSrcweir 	if( bRet )
403cdf0e10cSrcweir     {
404cdf0e10cSrcweir         m_pImpl->pSrcArr->Insert( pSrc );
405cdf0e10cSrcweir         m_pImpl->pDestArr->Insert( pDest );
406cdf0e10cSrcweir 		rFileNm = *pDest;
407cdf0e10cSrcweir 	}
408cdf0e10cSrcweir 	else
409cdf0e10cSrcweir 	{
410cdf0e10cSrcweir 		delete pSrc;
411cdf0e10cSrcweir 		delete pDest;
412cdf0e10cSrcweir 	}
413cdf0e10cSrcweir 
414cdf0e10cSrcweir 	return bRet;
415cdf0e10cSrcweir }
416cdf0e10cSrcweir 
PutNumFmtFontsInAttrPool()417cdf0e10cSrcweir void Writer::PutNumFmtFontsInAttrPool()
418cdf0e10cSrcweir {
419cdf0e10cSrcweir 	// dann gibt es noch in den NumRules ein paar Fonts
420cdf0e10cSrcweir 	// Diese in den Pool putten. Haben sie danach einen RefCount > 1
421cdf0e10cSrcweir 	// kann es wieder entfernt werden - ist schon im Pool
422cdf0e10cSrcweir 	SfxItemPool& rPool = pDoc->GetAttrPool();
423cdf0e10cSrcweir 	const SwNumRuleTbl& rListTbl = pDoc->GetNumRuleTbl();
424cdf0e10cSrcweir 	const SwNumRule* pRule;
425cdf0e10cSrcweir 	const SwNumFmt* pFmt;
426cdf0e10cSrcweir     // --> OD 2006-06-27 #b644095#
427cdf0e10cSrcweir //    const Font *pFont, *pDefFont = &SwNumRule::GetDefBulletFont();
428cdf0e10cSrcweir     const Font* pFont;
429cdf0e10cSrcweir     const Font* pDefFont = &numfunc::GetDefBulletFont();
430cdf0e10cSrcweir     // <--
431cdf0e10cSrcweir 	sal_Bool bCheck = sal_False;
432cdf0e10cSrcweir 
433cdf0e10cSrcweir 	for( sal_uInt16 nGet = rListTbl.Count(); nGet; )
434cdf0e10cSrcweir 		if( pDoc->IsUsed( *(pRule = rListTbl[ --nGet ] )))
435cdf0e10cSrcweir 			for( sal_uInt8 nLvl = 0; nLvl < MAXLEVEL; ++nLvl )
436cdf0e10cSrcweir 				if( SVX_NUM_CHAR_SPECIAL == (pFmt = &pRule->Get( nLvl ))->GetNumberingType() ||
437cdf0e10cSrcweir 					SVX_NUM_BITMAP == pFmt->GetNumberingType() )
438cdf0e10cSrcweir 				{
439cdf0e10cSrcweir 					if( 0 == ( pFont = pFmt->GetBulletFont() ) )
440cdf0e10cSrcweir 						pFont = pDefFont;
441cdf0e10cSrcweir 
442cdf0e10cSrcweir 					if( bCheck )
443cdf0e10cSrcweir 					{
444cdf0e10cSrcweir 						if( *pFont == *pDefFont )
445cdf0e10cSrcweir 							continue;
446cdf0e10cSrcweir 					}
447cdf0e10cSrcweir 					else if( *pFont == *pDefFont )
448cdf0e10cSrcweir 						bCheck = sal_True;
449cdf0e10cSrcweir 
450cdf0e10cSrcweir 					_AddFontItem( rPool, SvxFontItem( pFont->GetFamily(),
451cdf0e10cSrcweir 								pFont->GetName(), pFont->GetStyleName(),
452cdf0e10cSrcweir                                 pFont->GetPitch(), pFont->GetCharSet(), RES_CHRATR_FONT ));
453cdf0e10cSrcweir 				}
454cdf0e10cSrcweir }
455cdf0e10cSrcweir 
PutEditEngFontsInAttrPool(sal_Bool bIncl_CJK_CTL)456cdf0e10cSrcweir void Writer::PutEditEngFontsInAttrPool( sal_Bool bIncl_CJK_CTL )
457cdf0e10cSrcweir {
458cdf0e10cSrcweir 	SfxItemPool& rPool = pDoc->GetAttrPool();
459cdf0e10cSrcweir 	if( rPool.GetSecondaryPool() )
460cdf0e10cSrcweir 	{
461cdf0e10cSrcweir 		_AddFontItems( rPool, EE_CHAR_FONTINFO );
462cdf0e10cSrcweir 		if( bIncl_CJK_CTL )
463cdf0e10cSrcweir 		{
464cdf0e10cSrcweir 			_AddFontItems( rPool, EE_CHAR_FONTINFO_CJK );
465cdf0e10cSrcweir 			_AddFontItems( rPool, EE_CHAR_FONTINFO_CTL );
466cdf0e10cSrcweir 		}
467cdf0e10cSrcweir 	}
468cdf0e10cSrcweir }
469cdf0e10cSrcweir 
PutCJKandCTLFontsInAttrPool()470cdf0e10cSrcweir void Writer::PutCJKandCTLFontsInAttrPool()
471cdf0e10cSrcweir {
472cdf0e10cSrcweir 	SfxItemPool& rPool = pDoc->GetAttrPool();
473cdf0e10cSrcweir 	_AddFontItems( rPool, RES_CHRATR_CJK_FONT );
474cdf0e10cSrcweir 	_AddFontItems( rPool, RES_CHRATR_CTL_FONT );
475cdf0e10cSrcweir }
476cdf0e10cSrcweir 
477cdf0e10cSrcweir 
_AddFontItems(SfxItemPool & rPool,sal_uInt16 nW)478cdf0e10cSrcweir void Writer::_AddFontItems( SfxItemPool& rPool, sal_uInt16 nW )
479cdf0e10cSrcweir {
480cdf0e10cSrcweir 	const SvxFontItem* pFont = (const SvxFontItem*)&rPool.GetDefaultItem( nW );
481cdf0e10cSrcweir 	_AddFontItem( rPool, *pFont );
482cdf0e10cSrcweir 
483cdf0e10cSrcweir 	if( 0 != ( pFont = (const SvxFontItem*)rPool.GetPoolDefaultItem( nW )) )
484cdf0e10cSrcweir 		_AddFontItem( rPool, *pFont );
485cdf0e10cSrcweir 
486cdf0e10cSrcweir 	sal_uInt32 nMaxItem = rPool.GetItemCount2( nW );
487cdf0e10cSrcweir 	for( sal_uInt32 nGet = 0; nGet < nMaxItem; ++nGet )
488cdf0e10cSrcweir 		if( 0 != (pFont = (const SvxFontItem*)rPool.GetItem2( nW, nGet )) )
489cdf0e10cSrcweir 			_AddFontItem( rPool, *pFont );
490cdf0e10cSrcweir }
491cdf0e10cSrcweir 
_AddFontItem(SfxItemPool & rPool,const SvxFontItem & rFont)492cdf0e10cSrcweir void Writer::_AddFontItem( SfxItemPool& rPool, const SvxFontItem& rFont )
493cdf0e10cSrcweir {
494cdf0e10cSrcweir 	const SvxFontItem* pItem;
495cdf0e10cSrcweir 	if( RES_CHRATR_FONT != rFont.Which() )
496cdf0e10cSrcweir 	{
497cdf0e10cSrcweir 		SvxFontItem aFont( rFont );
498cdf0e10cSrcweir 		aFont.SetWhich( RES_CHRATR_FONT );
499cdf0e10cSrcweir 		pItem = (SvxFontItem*)&rPool.Put( aFont );
500cdf0e10cSrcweir 	}
501cdf0e10cSrcweir 	else
502cdf0e10cSrcweir 		pItem = (SvxFontItem*)&rPool.Put( rFont );
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 	if( 1 < pItem->GetRefCount() )
505cdf0e10cSrcweir 		rPool.Remove( *pItem );
506cdf0e10cSrcweir 	else
507cdf0e10cSrcweir     {
508cdf0e10cSrcweir         if (!m_pImpl->pFontRemoveLst)
509cdf0e10cSrcweir         {
510cdf0e10cSrcweir             m_pImpl->pFontRemoveLst = new SvPtrarr( 0, 10 );
511cdf0e10cSrcweir         }
512cdf0e10cSrcweir 
513cdf0e10cSrcweir 		void* p = (void*)pItem;
514cdf0e10cSrcweir         m_pImpl->pFontRemoveLst->Insert( p, m_pImpl->pFontRemoveLst->Count() );
515cdf0e10cSrcweir 	}
516cdf0e10cSrcweir }
517cdf0e10cSrcweir 
518cdf0e10cSrcweir // build a bookmark table, which is sort by the node position. The
519cdf0e10cSrcweir // OtherPos of the bookmarks also inserted.
CreateBookmarkTbl()520cdf0e10cSrcweir void Writer::CreateBookmarkTbl()
521cdf0e10cSrcweir {
522cdf0e10cSrcweir     const IDocumentMarkAccess* const pMarkAccess = pDoc->getIDocumentMarkAccess();
523cdf0e10cSrcweir     for(IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->getBookmarksBegin();
524cdf0e10cSrcweir         ppBkmk != pMarkAccess->getBookmarksEnd();
525cdf0e10cSrcweir         ++ppBkmk)
526cdf0e10cSrcweir     {
527cdf0e10cSrcweir         m_pImpl->InsertBkmk(**ppBkmk);
528cdf0e10cSrcweir     }
529cdf0e10cSrcweir }
530cdf0e10cSrcweir 
531cdf0e10cSrcweir 
532cdf0e10cSrcweir // search alle Bookmarks in the range and return it in the Array
GetBookmarks(const SwCntntNode & rNd,xub_StrLen nStt,xub_StrLen nEnd,SvPtrarr & rArr)533cdf0e10cSrcweir sal_uInt16 Writer::GetBookmarks(const SwCntntNode& rNd, xub_StrLen nStt,
534cdf0e10cSrcweir     xub_StrLen nEnd, SvPtrarr& rArr)
535cdf0e10cSrcweir {
536cdf0e10cSrcweir     ASSERT( !rArr.Count(), "es sind noch Eintraege vorhanden" );
537cdf0e10cSrcweir 
538cdf0e10cSrcweir     sal_uLong nNd = rNd.GetIndex();
539cdf0e10cSrcweir     SvPtrarr* pArr = (m_pImpl->pBkmkNodePos) ?
540cdf0e10cSrcweir         m_pImpl->pBkmkNodePos->Get( nNd ) : 0;
541cdf0e10cSrcweir     if( pArr )
542cdf0e10cSrcweir     {
543cdf0e10cSrcweir         // there exist some bookmarks, search now all which is in the range
544cdf0e10cSrcweir         if( !nStt && nEnd == rNd.Len() )
545cdf0e10cSrcweir             // all
546cdf0e10cSrcweir             rArr.Insert( pArr, 0 );
547cdf0e10cSrcweir         else
548cdf0e10cSrcweir         {
549cdf0e10cSrcweir             sal_uInt16 n;
550cdf0e10cSrcweir             xub_StrLen nCntnt;
551cdf0e10cSrcweir             for( n = 0; n < pArr->Count(); ++n )
552cdf0e10cSrcweir             {
553cdf0e10cSrcweir                 void* p = (*pArr)[ n ];
554cdf0e10cSrcweir                 const ::sw::mark::IMark& rBkmk = *(::sw::mark::IMark *)p;
555cdf0e10cSrcweir                 if( rBkmk.GetMarkPos().nNode == nNd &&
556cdf0e10cSrcweir                     (nCntnt = rBkmk.GetMarkPos().nContent.GetIndex() ) >= nStt &&
557cdf0e10cSrcweir                     nCntnt < nEnd )
558cdf0e10cSrcweir                 {
559cdf0e10cSrcweir                     rArr.Insert( p, rArr.Count() );
560cdf0e10cSrcweir                 }
561cdf0e10cSrcweir                 else if( rBkmk.IsExpanded() && nNd ==
562cdf0e10cSrcweir                         rBkmk.GetOtherMarkPos().nNode.GetIndex() && (nCntnt =
563cdf0e10cSrcweir                         rBkmk.GetOtherMarkPos().nContent.GetIndex() ) >= nStt &&
564cdf0e10cSrcweir                         nCntnt < nEnd )
565cdf0e10cSrcweir                 {
566cdf0e10cSrcweir                     rArr.Insert( p, rArr.Count() );
567cdf0e10cSrcweir                 }
568cdf0e10cSrcweir             }
569cdf0e10cSrcweir         }
570cdf0e10cSrcweir     }
571cdf0e10cSrcweir     return rArr.Count();
572cdf0e10cSrcweir }
573cdf0e10cSrcweir 
574cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////
575cdf0e10cSrcweir 
576cdf0e10cSrcweir // Storage-spezifisches
577cdf0e10cSrcweir 
WriteStream()578cdf0e10cSrcweir sal_uLong StgWriter::WriteStream()
579cdf0e10cSrcweir {
580cdf0e10cSrcweir 	ASSERT( !this, "Schreiben in Streams auf einem Storage?" );
581cdf0e10cSrcweir 	return ERR_SWG_WRITE_ERROR;
582cdf0e10cSrcweir }
583cdf0e10cSrcweir 
Write(SwPaM & rPaM,SvStorage & rStg,const String * pFName)584cdf0e10cSrcweir sal_uLong StgWriter::Write( SwPaM& rPaM, SvStorage& rStg, const String* pFName )
585cdf0e10cSrcweir {
586cdf0e10cSrcweir     SetStream(0);
587cdf0e10cSrcweir 	pStg = &rStg;
588cdf0e10cSrcweir 	pDoc = rPaM.GetDoc();
589cdf0e10cSrcweir 	pOrigFileName = pFName;
590cdf0e10cSrcweir 
591cdf0e10cSrcweir 	// PaM kopieren, damit er veraendert werden kann
592cdf0e10cSrcweir 	pCurPam = new SwPaM( *rPaM.End(), *rPaM.Start() );
593cdf0e10cSrcweir 	// zum Vergleich auf den akt. Pam sichern
594cdf0e10cSrcweir 	pOrigPam = &rPaM;
595cdf0e10cSrcweir 
596cdf0e10cSrcweir 	sal_uLong nRet = WriteStorage();
597cdf0e10cSrcweir 
598cdf0e10cSrcweir 	pStg = NULL;
599cdf0e10cSrcweir 	ResetWriter();
600cdf0e10cSrcweir 
601cdf0e10cSrcweir 	return nRet;
602cdf0e10cSrcweir }
603cdf0e10cSrcweir 
Write(SwPaM & rPaM,const uno::Reference<embed::XStorage> & rStg,const String * pFName,SfxMedium * pMedium)604cdf0e10cSrcweir sal_uLong StgWriter::Write( SwPaM& rPaM, const uno::Reference < embed::XStorage >& rStg, const String* pFName, SfxMedium* pMedium )
605cdf0e10cSrcweir {
606cdf0e10cSrcweir     SetStream(0);
607cdf0e10cSrcweir     pStg = 0;
608cdf0e10cSrcweir     xStg = rStg;
609cdf0e10cSrcweir 	pDoc = rPaM.GetDoc();
610cdf0e10cSrcweir 	pOrigFileName = pFName;
611cdf0e10cSrcweir 
612cdf0e10cSrcweir 	// PaM kopieren, damit er veraendert werden kann
613cdf0e10cSrcweir 	pCurPam = new SwPaM( *rPaM.End(), *rPaM.Start() );
614cdf0e10cSrcweir 	// zum Vergleich auf den akt. Pam sichern
615cdf0e10cSrcweir 	pOrigPam = &rPaM;
616cdf0e10cSrcweir 
617cdf0e10cSrcweir 	sal_uLong nRet = pMedium ? WriteMedium( *pMedium ) : WriteStorage();
618cdf0e10cSrcweir 
619cdf0e10cSrcweir 	pStg = NULL;
620cdf0e10cSrcweir 	ResetWriter();
621cdf0e10cSrcweir 
622cdf0e10cSrcweir 	return nRet;
623cdf0e10cSrcweir }
624cdf0e10cSrcweir 
625