1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: wrtasc.cxx,v $
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"
33 #include <hintids.hxx>
34 #include <osl/endian.h>
35 #include <tools/stream.hxx>
39 #include <mdiexp.hxx> // ...Percent()
41 #include <fmtcntnt.hxx>
46 #include <statstr.hrc> // ResId fuer Statusleiste
49 //-----------------------------------------------------------------
51 SwASCWriter::SwASCWriter( const String
& rFltNm
)
53 SwAsciiOptions aNewOpts
;
55 switch( 5 <= rFltNm
.Len() ? rFltNm
.GetChar( 4 ) : 0 )
59 aNewOpts
.SetCharSet( RTL_TEXTENCODING_IBM_850
);
60 aNewOpts
.SetParaFlags( LINEEND_CRLF
);
62 if( 5 < rFltNm
.Len() )
63 switch( rFltNm
.Copy( 5 ).ToInt32() )
65 case 437: aNewOpts
.SetCharSet( RTL_TEXTENCODING_IBM_437
); break;
66 case 850: aNewOpts
.SetCharSet( RTL_TEXTENCODING_IBM_850
); break;
67 case 860: aNewOpts
.SetCharSet( RTL_TEXTENCODING_IBM_860
); break;
68 case 861: aNewOpts
.SetCharSet( RTL_TEXTENCODING_IBM_861
); break;
69 case 863: aNewOpts
.SetCharSet( RTL_TEXTENCODING_IBM_863
); break;
70 case 865: aNewOpts
.SetCharSet( RTL_TEXTENCODING_IBM_865
); break;
75 #if !defined(WIN) && !defined(WNT)
76 aNewOpts
.SetCharSet( RTL_TEXTENCODING_MS_1252
);
77 aNewOpts
.SetParaFlags( LINEEND_CRLF
);
82 aNewOpts
.SetCharSet( RTL_TEXTENCODING_APPLE_ROMAN
);
83 aNewOpts
.SetParaFlags( LINEEND_CR
);
88 aNewOpts
.SetCharSet( RTL_TEXTENCODING_MS_1252
);
89 aNewOpts
.SetParaFlags( LINEEND_LF
);
94 if( rFltNm
.Copy( 4 ).EqualsAscii( "_DLG" ))
97 aNewOpts
= GetAsciiOptions();
100 SetAsciiOptions( aNewOpts
);
103 SwASCWriter::~SwASCWriter() {}
105 ULONG
SwASCWriter::WriteStream()
107 sal_Char cLineEnd
[ 3 ];
108 sal_Char
* pCEnd
= cLineEnd
;
109 if( bASCII_ParaAsCR
) // falls vorgegeben ist.
111 else if( bASCII_ParaAsBlanc
)
114 switch( GetAsciiOptions().GetParaFlags() )
116 case LINEEND_CR
: *pCEnd
++ = '\015'; break;
117 case LINEEND_LF
: *pCEnd
++ = '\012'; break;
118 case LINEEND_CRLF
: *pCEnd
++ = '\015', *pCEnd
++ = '\012'; break;
122 sLineEnd
.AssignAscii( cLineEnd
);
124 long nMaxNode
= pDoc
->GetNodes().Count();
127 ::StartProgress( STR_STATSTR_W4WWRITE
, 0, nMaxNode
, pDoc
->GetDocShell() );
129 SwPaM
* pPam
= pOrigPam
;
131 BOOL bWriteSttTag
= bUCS2_WithStartChar
&&
132 (RTL_TEXTENCODING_UCS2
== GetAsciiOptions().GetCharSet() ||
133 RTL_TEXTENCODING_UTF8
== GetAsciiOptions().GetCharSet());
135 rtl_TextEncoding eOld
= Strm().GetStreamCharSet();
136 Strm().SetStreamCharSet( GetAsciiOptions().GetCharSet() );
138 // gebe alle Bereich des Pams in das ASC-File aus.
141 while( pCurPam
->GetPoint()->nNode
.GetIndex() < pCurPam
->GetMark()->nNode
.GetIndex() ||
142 (pCurPam
->GetPoint()->nNode
.GetIndex() == pCurPam
->GetMark()->nNode
.GetIndex() &&
143 pCurPam
->GetPoint()->nContent
.GetIndex() <= pCurPam
->GetMark()->nContent
.GetIndex()) )
145 SwTxtNode
* pNd
= pCurPam
->GetPoint()->nNode
.GetNode().GetTxtNode();
148 // sollten nur Rahmen vorhanden sein?
149 // (Moeglich, wenn Rahmen-Selektion ins Clipboard
151 if( bTstFly
&& bWriteAll
&&
153 !pNd
->GetTxt().Len() &&
155 pDoc
->GetSpzFrmFmts()->Count() &&
156 // nur ein Node im Array
157 pDoc
->GetNodes().GetEndOfExtras().GetIndex() + 3 ==
158 pDoc
->GetNodes().GetEndOfContent().GetIndex() &&
159 // und genau der ist selektiert
160 pDoc
->GetNodes().GetEndOfContent().GetIndex() - 1 ==
161 pCurPam
->GetPoint()->nNode
.GetIndex() )
163 // dann den Inhalt vom Rahmen ausgeben.
164 // dieser steht immer an Position 0 !!
165 SwFrmFmt
* pFmt
= (*pDoc
->GetSpzFrmFmts())[ 0 ];
166 const SwNodeIndex
* pIdx
= pFmt
->GetCntnt().GetCntntIdx();
170 pCurPam
= NewSwPaM( *pDoc
, pIdx
->GetIndex(),
171 pIdx
->GetNode().EndOfSectionIndex() );
173 continue; // while-Schleife neu aufsetzen !!
180 switch(GetAsciiOptions().GetCharSet())
182 case RTL_TEXTENCODING_UTF8
:
183 Strm() << BYTE(0xEF) << BYTE(0xBB) <<
186 case RTL_TEXTENCODING_UCS2
:
187 //Strm().StartWritingUnicodeText();
188 Strm().SetEndianSwap(FALSE
);
190 Strm() << BYTE(0xFF) << BYTE(0xFE);
192 Strm() << BYTE(0xFE) << BYTE(0xFF);
197 bWriteSttTag
= FALSE
;
199 Out( aASCNodeFnTab
, *pNd
, *this );
201 bTstFly
= FALSE
; // eimal Testen reicht
204 if( !pCurPam
->Move( fnMoveForward
, fnGoNode
) )
208 ::SetProgressState( pCurPam
->GetPoint()->nNode
.GetIndex(),
209 pDoc
->GetDocShell() ); // Wie weit ?
212 } while( CopyNextPam( &pPam
) ); // bis alle Pam bearbeitet
214 Strm().SetStreamCharSet( eOld
);
217 ::EndProgress( pDoc
->GetDocShell() );
223 void GetASCWriter( const String
& rFltNm
, const String
& /*rBaseURL*/, WriterRef
& xRet
)
225 xRet
= new SwASCWriter( rFltNm
);