1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef SW_SHELLIO_HXX
20 #define SW_SHELLIO_HXX
23 #include <boost/utility.hpp>
25 #include <com/sun/star/uno/Reference.h>
26 #include <com/sun/star/embed/XStorage.hpp>
27 #include <sfx2/docfile.hxx>
28 #include <sfx2/fcontnr.hxx>
29 #include <sot/formats.hxx>
30 #include <sot/storage.hxx>
31 #include <svtools/parhtml.hxx>
32 #include <tools/string.hxx>
33 #include <tools/date.hxx>
34 #include <tools/time.hxx>
35 #include <tools/datetime.hxx>
36 #include <tools/ref.hxx>
38 #include <swtypes.hxx>
39 #include <docfac.hxx> // SwDocFac
40 #include <iodetect.hxx>
43 class SfxFilterContainer
;
50 class SvxMacroTableDtor
;
59 // Defines the count of chars at which a paragraph read via ASCII/W4W-Reader
60 // is forced to wrap. It has to be always greater than 200!!!
61 #define MAX_ASCII_PARA 10000
64 class SW_DLLPUBLIC SwAsciiOptions
67 rtl_TextEncoding eCharSet
;
73 const String
& GetFontName() const { return sFont
; }
74 void SetFontName( const String
& rFont
) { sFont
= rFont
; }
76 rtl_TextEncoding
GetCharSet() const { return eCharSet
; }
77 void SetCharSet( rtl_TextEncoding nVal
) { eCharSet
= nVal
; }
79 sal_uInt16
GetLanguage() const { return nLanguage
; }
80 void SetLanguage( sal_uInt16 nVal
) { nLanguage
= nVal
; }
82 LineEnd
GetParaFlags() const { return eCRLF_Flag
; }
83 void SetParaFlags( LineEnd eVal
) { eCRLF_Flag
= eVal
; }
88 eCRLF_Flag
= GetSystemLineEnd();
89 eCharSet
= ::osl_getThreadTextEncoding();
92 // for the automatic conversion (mail/news/...)
93 void ReadUserData( const String
& );
94 void WriteUserData( String
& );
96 SwAsciiOptions() { Reset(); }
99 /**************** SwReader/Reader ************************/
100 // Base class of possible options for a special reader.
102 // Calls reader with its options, document, cursor etc.
104 // SwRead is pointer to the read-options base class.
105 typedef Reader
*SwRead
;
107 class SwgReaderOption
109 SwAsciiOptions aASCIIOpts
;
115 sal_Bool bFrmFmts
: 1;
116 sal_Bool bPageDescs
: 1;
117 sal_Bool bTxtFmts
: 1;
118 sal_Bool bNumRules
: 1;
124 void ResetAllFmtsOnly() { What
.bFmtsOnly
= 0; }
125 sal_Bool
IsFmtsOnly() const { return What
.bFmtsOnly
; }
127 sal_Bool
IsFrmFmts() const { return What
.Fmts
.bFrmFmts
; }
128 void SetFrmFmts( const sal_Bool bNew
) { What
.Fmts
.bFrmFmts
= bNew
; }
130 sal_Bool
IsPageDescs() const { return What
.Fmts
.bPageDescs
; }
131 void SetPageDescs( const sal_Bool bNew
) { What
.Fmts
.bPageDescs
= bNew
; }
133 sal_Bool
IsTxtFmts() const { return What
.Fmts
.bTxtFmts
; }
134 void SetTxtFmts( const sal_Bool bNew
) { What
.Fmts
.bTxtFmts
= bNew
; }
136 sal_Bool
IsNumRules() const { return What
.Fmts
.bNumRules
; }
137 void SetNumRules( const sal_Bool bNew
) { What
.Fmts
.bNumRules
= bNew
; }
139 sal_Bool
IsMerge() const { return What
.Fmts
.bMerge
; }
140 void SetMerge( const sal_Bool bNew
) { What
.Fmts
.bMerge
= bNew
; }
142 const SwAsciiOptions
& GetASCIIOpts() const { return aASCIIOpts
; }
143 void SetASCIIOpts( const SwAsciiOptions
& rOpts
) { aASCIIOpts
= rOpts
; }
144 void ResetASCIIOpts() { aASCIIOpts
.Reset(); }
147 { ResetAllFmtsOnly(); aASCIIOpts
.Reset(); }
150 class SwReader
: public SwDocFac
154 com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
> xStg
;
155 SfxMedium
* pMedium
; // Who wants to obtain a Medium (W4W).
163 // Initial reading. Document is created only at Read(...)
164 // or in case it is given, into that.
165 // Special case for Load with Sw3Reader.
166 SwReader( SfxMedium
&, const String
& rFilename
, SwDoc
*pDoc
= 0 );
168 // Read into existing document.
169 // Document and position in document are taken from SwPaM.
170 SwReader( SvStream
&, const String
& rFilename
, const String
& rBaseURL
, SwPaM
& );
171 SwReader( SfxMedium
&, const String
& rFilename
, SwPaM
& );
172 SwReader( const com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
>&, const String
& rFilename
, SwPaM
& );
174 // The only export interface is SwReader::Read(...)!!!
175 sal_Bool
NeedsPasswd( const Reader
& );
176 sal_Bool
CheckPasswd( const String
&, const Reader
& );
177 sal_uLong
Read( const Reader
& );
179 // Ask for glossaries.
180 sal_Bool
HasGlossaries( const Reader
& );
181 sal_Bool
ReadGlossaries( const Reader
&, SwTextBlocks
&, sal_Bool bSaveRelFiles
);
183 const String
& GetBaseURL() const { return sBaseURL
;}
186 void SetBaseURL( const String
& rURL
) { sBaseURL
= rURL
; }
191 /**************** Special Readers ************************/
193 // Special Readers can be both!! (Excel, W4W, .. ).
194 #define SW_STREAM_READER 1
195 #define SW_STORAGE_READER 2
197 class SW_DLLPUBLIC Reader
199 friend class SwReader
;
205 DateTime aChkDateTime
;
210 com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
> xStg
;
211 SfxMedium
* pMedium
; // Who wants to obtain a Medium (W4W).
213 SwgReaderOption aOpt
;
214 sal_Bool bInsertMode
: 1;
215 sal_Bool bTmplBrowseMode
: 1;
216 sal_Bool bReadUTF8
: 1; // Interprete stream as UTF-8.
217 sal_Bool bBlockMode
: 1;
218 sal_Bool bOrganizerMode
: 1;
219 sal_Bool bHasAskTemplateName
: 1;
220 sal_Bool bIgnoreHTMLComments
: 1;
222 virtual String
GetTemplateName() const;
228 virtual int GetReaderType();
229 SwgReaderOption
& GetReaderOpt() { return aOpt
; }
231 virtual void SetFltName( const String
& rFltNm
);
233 // Adapt item-set of a Frm-Format to the old format.
234 static void ResetFrmFmtAttrs( SfxItemSet
&rFrmSet
);
236 // Adapt Frame-/Graphics-/OLE- styles to the old format
237 // (without borders etc.).
238 static void ResetFrmFmts( SwDoc
& rDoc
);
240 // Load filter template, set it and release it again.
241 SwDoc
* GetTemplateDoc();
242 sal_Bool
SetTemplate( SwDoc
& rDoc
);
243 void ClearTemplate();
244 void SetTemplateName( const String
& rDir
);
245 void MakeHTMLDummyTemplateDoc();
247 sal_Bool
IsReadUTF8() const { return bReadUTF8
; }
248 void SetReadUTF8( sal_Bool bSet
) { bReadUTF8
= bSet
; }
250 sal_Bool
IsBlockMode() const { return bBlockMode
; }
251 void SetBlockMode( sal_Bool bSet
) { bBlockMode
= bSet
; }
253 sal_Bool
IsOrganizerMode() const { return bOrganizerMode
; }
254 void SetOrganizerMode( sal_Bool bSet
) { bOrganizerMode
= bSet
; }
256 void SetIgnoreHTMLComments( sal_Bool bSet
) { bIgnoreHTMLComments
= bSet
; }
258 virtual sal_Bool
HasGlossaries() const;
259 virtual sal_Bool
ReadGlossaries( SwTextBlocks
&, sal_Bool bSaveRelFiles
) const;
261 // Read the sections of the document, which is equal to the medium.
262 // Returns the count of it
263 virtual size_t GetSectionList( SfxMedium
& rMedium
,
264 std::vector
<String
*>& rStrings
) const;
266 SotStorageRef
getSotStorageRef() { return pStg
; };
267 void setSotStorageRef(SotStorageRef pStgRef
) { pStg
= pStgRef
; };
270 virtual sal_uLong
Read(SwDoc
&, const String
& rBaseURL
, SwPaM
&,const String
&)=0;
272 // Everyone who does not need the streams / storages open
273 // has to overload the method (W4W!!).
274 virtual int SetStrmStgPtr();
277 class AsciiReader
: public Reader
279 friend class SwReader
;
280 virtual sal_uLong
Read( SwDoc
&, const String
& rBaseURL
, SwPaM
&,const String
&);
282 AsciiReader(): Reader() {}
285 class SW_DLLPUBLIC StgReader
: public Reader
290 sal_uLong
OpenMainStream( SotStorageStreamRef
& rRef
, sal_uInt16
& rBuffSize
);
292 virtual int GetReaderType();
293 const String
& GetFltName() { return aFltName
; }
294 virtual void SetFltName( const String
& r
);
298 // The given stream has to be created dynamically and must
299 // be requested via Stream() before the instance is deleted!
303 class SW_DLLPUBLIC SwTextBlocks
309 SwTextBlocks( const String
& );
315 void ClearDoc(); // Delete Doc-contents.
316 const String
& GetName();
317 void SetName( const String
& );
318 sal_uLong
GetError() const { return nErr
; }
320 String
GetBaseURL() const;
321 void SetBaseURL( const String
& rURL
);
323 sal_Bool
IsOld() const;
324 sal_uLong
ConvertToNew(); // Convert text modules.
326 sal_uInt16
GetCount() const; // Get count text modules.
327 sal_uInt16
GetIndex( const String
& ) const; // Get index of short names.
328 sal_uInt16
GetLongIndex( const String
& ) const; // Get index of long names.
329 const String
& GetShortName( sal_uInt16
) const; // Get short name for index.
330 const String
& GetLongName( sal_uInt16
) const; // Get long name for index.
332 sal_Bool
Delete( sal_uInt16
);
333 sal_uInt16
Rename( sal_uInt16
, const String
*, const String
* );
334 sal_uLong
CopyBlock( SwTextBlocks
& rSource
, String
& rSrcShort
,
335 const String
& rLong
);
337 sal_Bool
BeginGetDoc( sal_uInt16
); // Read text modules.
338 void EndGetDoc(); // Release text modules.
340 sal_Bool
BeginPutDoc( const String
&, const String
& ); // Begin save.
341 sal_uInt16
PutDoc(); // End save.
343 sal_uInt16
PutText( const String
&, const String
&, const String
& ); // Save (short name, text).
345 sal_Bool
IsOnlyTextBlock( sal_uInt16
) const;
346 sal_Bool
IsOnlyTextBlock( const String
& rShort
) const;
348 const String
& GetFileName() const; // Filename of pImp.
349 sal_Bool
IsReadOnly() const; // ReadOnly-flag of pImp.
351 sal_Bool
GetMacroTable( sal_uInt16 nIdx
, SvxMacroTableDtor
& rMacroTbl
);
352 sal_Bool
SetMacroTable( sal_uInt16 nIdx
, const SvxMacroTableDtor
& rMacroTbl
);
354 sal_Bool
StartPutMuchBlockEntries();
355 void EndPutMuchBlockEntries();
358 // BEGIN source/filter/basflt/fltini.cxx
360 extern SwRead ReadAscii
, /*ReadSwg, ReadSw3, */ReadHTML
, ReadXML
;
362 SW_DLLPUBLIC SwRead
SwGetReaderXML();
364 // END source/filter/basflt/fltini.cxx
367 extern sal_Bool
SetHTMLTemplate( SwDoc
&rDoc
); //For templates from HTML before loading shellio.cxx.
373 // Base-class of all writers.
375 class IDocumentSettingAccess
;
376 class IDocumentStylePoolAccess
;
378 class SW_DLLPUBLIC Writer
380 , private ::boost::noncopyable
382 SwAsciiOptions aAscOpts
;
385 void _AddFontItem( SfxItemPool
& rPool
, const SvxFontItem
& rFont
);
386 void _AddFontItems( SfxItemPool
& rPool
, sal_uInt16 nWhichId
);
388 ::std::auto_ptr
<Writer_Impl
> m_pImpl
;
392 SwPaM
* pOrigPam
; // Last Pam that has to be processed.
393 const String
* pOrigFileName
;
396 sal_Bool
CopyNextPam( SwPaM
** );
398 void PutNumFmtFontsInAttrPool();
399 void PutEditEngFontsInAttrPool( bool bIncl_CJK_CTL
= true );
401 virtual sal_uLong
WriteStream() = 0;
402 void SetBaseURL( const String
& rURL
) { sBaseURL
= rURL
; }
404 IDocumentSettingAccess
* getIDocumentSettingAccess();
405 const IDocumentSettingAccess
* getIDocumentSettingAccess() const;
407 IDocumentStylePoolAccess
* getIDocumentStylePoolAccess();
408 const IDocumentStylePoolAccess
* getIDocumentStylePoolAccess() const;
413 sal_Bool bWriteAll
: 1;
414 sal_Bool bShowProgress
: 1;
415 sal_Bool bWriteClipboardDoc
: 1;
416 sal_Bool bWriteOnlyFirstTable
: 1;
417 sal_Bool bASCII_ParaAsCR
: 1;
418 sal_Bool bASCII_ParaAsBlanc
: 1;
419 sal_Bool bASCII_NoLastLineEnd
: 1;
420 sal_Bool bUCS2_WithStartChar
: 1;
421 sal_Bool bExportPargraphNumbering
: 1;
424 sal_Bool bOrganizerMode
: 1;
429 virtual sal_uLong
Write( SwPaM
&, SfxMedium
&, const String
* = 0 );
430 sal_uLong
Write( SwPaM
&, SvStream
&, const String
* = 0 );
431 virtual sal_uLong
Write( SwPaM
&, const com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
>&, const String
* = 0, SfxMedium
* = 0 );
432 virtual sal_uLong
Write( SwPaM
&, SotStorage
&, const String
* = 0 );
434 virtual void SetVersion( const String
&, long );
435 virtual sal_Bool
IsStgWriter() const;
437 void SetShowProgress( sal_Bool bFlag
= sal_False
) { bShowProgress
= bFlag
; }
439 const String
* GetOrigFileName() const { return pOrigFileName
; }
441 const SwAsciiOptions
& GetAsciiOptions() const { return aAscOpts
; }
442 void SetAsciiOptions( const SwAsciiOptions
& rOpt
) { aAscOpts
= rOpt
; }
444 const String
& GetBaseURL() const { return sBaseURL
;}
446 // Look up next bookmark position from bookmark-table.
447 sal_Int32
FindPos_Bkmk( const SwPosition
& rPos
) const;
448 // Build a bookmark table, which is sort by the node position. The
449 // OtherPos of the bookmarks also inserted.
450 void CreateBookmarkTbl();
451 // Search alle Bookmarks in the range and return it in the Array.
452 sal_uInt16
GetBookmarks( const SwCntntNode
& rNd
,
453 xub_StrLen nStt
, xub_StrLen nEnd
,
454 std::vector
< const ::sw::mark::IMark
* >& rArr
);
456 // Create new PaM at position.
457 static SwPaM
* NewSwPaM(SwDoc
& rDoc
,
458 sal_uLong
const nStartIdx
, sal_uLong
const nEndIdx
);
460 // If applicable copy a local file into internet.
461 sal_Bool
CopyLocalFileToINet( String
& rFileNm
);
464 // Stream-specific routines. Do not use in storage-writer!
466 // Optimizing output on stream.
467 SvStream
& OutLong( SvStream
& rStrm
, long nVal
);
468 SvStream
& OutULong( SvStream
& rStrm
, sal_uLong nVal
);
470 inline SvStream
& OutLong( long nVal
) { return OutLong( Strm(), nVal
); }
471 inline SvStream
& OutULong( sal_uLong nVal
) { return OutULong( Strm(), nVal
); }
473 void SetStream(SvStream
*const pStream
);
476 void SetOrganizerMode( sal_Bool bSet
) { bOrganizerMode
= bSet
; }
479 #ifndef SW_DECL_WRITER_DEFINED
480 #define SW_DECL_WRITER_DEFINED
485 // Base class for all storage writers.
486 class SW_DLLPUBLIC StgWriter
: public Writer
491 com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
> xStg
;
493 // Create error at call.
494 virtual sal_uLong
WriteStream();
495 virtual sal_uLong
WriteStorage() = 0;
496 virtual sal_uLong
WriteMedium( SfxMedium
& ) = 0;
501 StgWriter() : Writer() {}
503 virtual sal_Bool
IsStgWriter() const;
505 virtual sal_uLong
Write( SwPaM
&, const com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
>&, const String
* = 0, SfxMedium
* = 0 );
506 virtual sal_uLong
Write( SwPaM
&, SotStorage
&, const String
* = 0 );
508 SotStorage
& GetStorage() const { return *pStg
; }
512 // Interface class for general access on special writers.
518 com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
> xStg
;
528 sal_uLong
Write( WriterRef
& rxWriter
, const String
* = 0);
530 SwWriter( SvStream
&, SwCrsrShell
&,sal_Bool bWriteAll
= sal_False
);
531 SwWriter( SvStream
&, SwDoc
& );
532 SwWriter( SvStream
&, SwPaM
&, sal_Bool bWriteAll
= sal_False
);
534 SwWriter( const com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
>&, SwDoc
& );
536 SwWriter( SfxMedium
&, SwCrsrShell
&,sal_Bool bWriteAll
= sal_False
);
537 SwWriter( SfxMedium
&, SwDoc
& );
542 typedef Reader
* (*FnGetReader
)();
543 typedef void (*FnGetWriter
)(const String
&, const String
& rBaseURL
, WriterRef
&);
544 sal_uLong
SaveOrDelMSVBAStorage( SfxObjectShell
&, SotStorage
&, sal_Bool
, const String
& );
545 sal_uLong
GetSaveWarningOfMSVBAStorage( SfxObjectShell
&rDocS
);
547 struct SwReaderWriterEntry
550 FnGetReader fnGetReader
;
551 FnGetWriter fnGetWriter
;
554 SwReaderWriterEntry( const FnGetReader fnReader
, const FnGetWriter fnWriter
, sal_Bool bDel
)
555 : pReader( NULL
), fnGetReader( fnReader
), fnGetWriter( fnWriter
), bDelReader( bDel
)
558 /// Get access to the reader.
561 /// Get access to the writer.
562 void GetWriter( const String
& rNm
, const String
& rBaseURL
, WriterRef
& xWrt
) const;
565 namespace SwReaderWriter
567 /// Return reader based on ReaderWriterEnum.
568 Reader
* GetReader( ReaderWriterEnum eReader
);
570 /// Return reader based on the name.
571 Reader
* GetReader( const String
& rFltName
);
573 /// Return writer based on the name.
574 void GetWriter( const String
& rFltName
, const String
& rBaseURL
, WriterRef
& xWrt
);
577 void GetRTFWriter( const String
&, const String
&, WriterRef
& );
578 void GetASCWriter( const String
&, const String
&, WriterRef
& );
579 void GetHTMLWriter( const String
&, const String
&, WriterRef
& );
580 void GetXMLWriter( const String
&, const String
&, WriterRef
& );
581 void GetWW8Writer( const String
&, const String
&, WriterRef
& );
585 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */