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 INCLUDED_SW_INC_SHELLIO_HXX
20 #define INCLUDED_SW_INC_SHELLIO_HXX
24 #include <com/sun/star/uno/Reference.h>
25 #include <com/sun/star/embed/XStorage.hpp>
26 #include <sfx2/docfile.hxx>
27 #include <sfx2/fcontnr.hxx>
28 #include <sot/formats.hxx>
29 #include <sot/storage.hxx>
30 #include <svtools/parhtml.hxx>
31 #include <tools/date.hxx>
32 #include <tools/time.hxx>
33 #include <tools/datetime.hxx>
34 #include <tools/ref.hxx>
35 #include <rtl/ref.hxx>
37 #include <swtypes.hxx>
39 #include <iodetect.hxx>
42 class SfxFilterContainer
;
49 class SvxMacroTableDtor
;
58 // Defines the count of chars at which a paragraph read via ASCII/W4W-Reader
59 // is forced to wrap. It has to be always greater than 200!!!
60 #define MAX_ASCII_PARA 10000
62 class SW_DLLPUBLIC SwAsciiOptions
65 rtl_TextEncoding eCharSet
;
66 LanguageType nLanguage
;
71 const OUString
& GetFontName() const { return sFont
; }
72 void SetFontName( const OUString
& rFont
) { sFont
= rFont
; }
74 rtl_TextEncoding
GetCharSet() const { return eCharSet
; }
75 void SetCharSet( rtl_TextEncoding nVal
) { eCharSet
= nVal
; }
77 LanguageType
GetLanguage() const { return nLanguage
; }
78 void SetLanguage( LanguageType nVal
) { nLanguage
= nVal
; }
80 LineEnd
GetParaFlags() const { return eCRLF_Flag
; }
81 void SetParaFlags( LineEnd eVal
) { eCRLF_Flag
= eVal
; }
86 eCRLF_Flag
= GetSystemLineEnd();
87 eCharSet
= ::osl_getThreadTextEncoding();
88 nLanguage
= LANGUAGE_SYSTEM
;
90 // for the automatic conversion (mail/news/...)
91 void ReadUserData( const OUString
& );
92 void WriteUserData( OUString
& );
94 SwAsciiOptions() { Reset(); }
97 // Base class of possible options for a special reader.
99 // Calls reader with its options, document, cursor etc.
101 // SwRead is pointer to the read-options base class.
102 typedef Reader
*SwRead
;
104 class SwgReaderOption
106 SwAsciiOptions aASCIIOpts
;
107 bool m_bFrameFormats
;
113 void ResetAllFormatsOnly() { m_bFrameFormats
= m_bPageDescs
= m_bTextFormats
= m_bNumRules
= m_bMerge
= false; }
114 bool IsFormatsOnly() const { return m_bFrameFormats
|| m_bPageDescs
|| m_bTextFormats
|| m_bNumRules
|| m_bMerge
; }
116 bool IsFrameFormats() const { return m_bFrameFormats
; }
117 void SetFrameFormats( const bool bNew
) { m_bFrameFormats
= bNew
; }
119 bool IsPageDescs() const { return m_bPageDescs
; }
120 void SetPageDescs( const bool bNew
) { m_bPageDescs
= bNew
; }
122 bool IsTextFormats() const { return m_bTextFormats
; }
123 void SetTextFormats( const bool bNew
) { m_bTextFormats
= bNew
; }
125 bool IsNumRules() const { return m_bNumRules
; }
126 void SetNumRules( const bool bNew
) { m_bNumRules
= bNew
; }
128 bool IsMerge() const { return m_bMerge
; }
129 void SetMerge( const bool bNew
) { m_bMerge
= bNew
; }
131 const SwAsciiOptions
& GetASCIIOpts() const { return aASCIIOpts
; }
132 void SetASCIIOpts( const SwAsciiOptions
& rOpts
) { aASCIIOpts
= rOpts
; }
133 void ResetASCIIOpts() { aASCIIOpts
.Reset(); }
136 { ResetAllFormatsOnly(); aASCIIOpts
.Reset(); }
139 class SW_DLLPUBLIC SwReader
: public SwDocFac
142 tools::SvRef
<SotStorage
> pStg
;
143 css::uno::Reference
< css::embed::XStorage
> xStg
;
144 SfxMedium
* pMedium
; // Who wants to obtain a Medium (W4W).
153 // Initial reading. Document is created only at Read(...)
154 // or in case it is given, into that.
155 // Special case for Load with Sw3Reader.
156 SwReader( SfxMedium
&, const OUString
& rFilename
, SwDoc
*pDoc
= nullptr );
158 // Read into existing document.
159 // Document and position in document are taken from SwPaM.
160 SwReader( SvStream
&, const OUString
& rFilename
, const OUString
& rBaseURL
, SwPaM
& );
161 SwReader( SfxMedium
&, const OUString
& rFilename
, SwPaM
& );
162 SwReader( const css::uno::Reference
< css::embed::XStorage
>&, const OUString
& rFilename
, SwPaM
& );
164 // The only export interface is SwReader::Read(...)!!!
165 sal_uLong
Read( const Reader
& );
167 // Ask for glossaries.
168 bool HasGlossaries( const Reader
& );
169 bool ReadGlossaries( const Reader
&, SwTextBlocks
&, bool bSaveRelFiles
);
172 void SetBaseURL( const OUString
& rURL
) { sBaseURL
= rURL
; }
173 void SetSkipImages( bool bSkipImages
) { mbSkipImages
= bSkipImages
; }
176 // Special Readers can be both!! (Excel, W4W, .. ).
177 #define SW_STREAM_READER 1
178 #define SW_STORAGE_READER 2
180 extern "C" SAL_DLLPUBLIC_EXPORT
bool SAL_CALL
TestImportDOC(SvStream
&rStream
, const OUString
&rFltName
);
181 extern "C" SAL_DLLPUBLIC_EXPORT
bool SAL_CALL
TestImportRTF(SvStream
&rStream
);
182 SAL_DLLPUBLIC_EXPORT
void FlushFontCache();
184 class SW_DLLPUBLIC Reader
186 friend class SwReader
;
187 friend bool TestImportDOC(SvStream
&rStream
, const OUString
&rFltName
);
188 friend bool TestImportRTF(SvStream
&rStream
);
189 rtl::Reference
<SwDoc
> mxTemplate
;
190 OUString aTemplateNm
;
194 DateTime aChkDateTime
;
198 tools::SvRef
<SotStorage
> pStg
;
199 css::uno::Reference
< css::embed::XStorage
> xStg
;
200 SfxMedium
* pMedium
; // Who wants to obtain a Medium (W4W).
202 SwgReaderOption aOpt
;
203 bool bInsertMode
: 1;
204 bool bTmplBrowseMode
: 1;
205 bool bReadUTF8
: 1; // Interprete stream as UTF-8.
207 bool bOrganizerMode
: 1;
208 bool bHasAskTemplateName
: 1;
209 bool bIgnoreHTMLComments
: 1;
210 bool bSkipImages
: 1;
212 virtual OUString
GetTemplateName() const;
218 virtual int GetReaderType();
219 SwgReaderOption
& GetReaderOpt() { return aOpt
; }
221 virtual void SetFltName( const OUString
& rFltNm
);
223 // Adapt item-set of a Frame-Format to the old format.
224 static void ResetFrameFormatAttrs( SfxItemSet
&rFrameSet
);
226 // Adapt Frame-/Graphics-/OLE- styles to the old format
227 // (without borders etc.).
228 static void ResetFrameFormats( SwDoc
& rDoc
);
230 // Load filter template, set it and release it again.
231 SwDoc
* GetTemplateDoc();
232 bool SetTemplate( SwDoc
& rDoc
);
233 void ClearTemplate();
234 void SetTemplateName( const OUString
& rDir
);
235 void MakeHTMLDummyTemplateDoc();
237 bool IsReadUTF8() const { return bReadUTF8
; }
238 void SetReadUTF8( bool bSet
) { bReadUTF8
= bSet
; }
240 bool IsBlockMode() const { return bBlockMode
; }
241 void SetBlockMode( bool bSet
) { bBlockMode
= bSet
; }
243 bool IsOrganizerMode() const { return bOrganizerMode
; }
244 void SetOrganizerMode( bool bSet
) { bOrganizerMode
= bSet
; }
246 void SetIgnoreHTMLComments( bool bSet
) { bIgnoreHTMLComments
= bSet
; }
248 virtual bool HasGlossaries() const;
249 virtual bool ReadGlossaries( SwTextBlocks
&, bool bSaveRelFiles
) const;
251 // Read the sections of the document, which is equal to the medium.
252 // Returns the count of it
253 virtual size_t GetSectionList( SfxMedium
& rMedium
,
254 std::vector
<OUString
*>& rStrings
) const;
256 const tools::SvRef
<SotStorage
>& getSotStorageRef() { return pStg
; };
257 void setSotStorageRef(const tools::SvRef
<SotStorage
>& pStgRef
) { pStg
= pStgRef
; };
260 virtual sal_uLong
Read(SwDoc
&, const OUString
& rBaseURL
, SwPaM
&, const OUString
&)=0;
262 // Everyone who does not need the streams / storages open
263 // has to override the method (W4W!!).
264 virtual bool SetStrmStgPtr();
267 class AsciiReader
: public Reader
269 friend class SwReader
;
270 virtual sal_uLong
Read( SwDoc
&, const OUString
& rBaseURL
, SwPaM
&, const OUString
&) override
;
272 AsciiReader(): Reader() {}
275 class SW_DLLPUBLIC StgReader
: public Reader
280 virtual int GetReaderType() override
;
281 const OUString
& GetFltName() { return aFltName
; }
282 virtual void SetFltName( const OUString
& r
) override
;
285 // The given stream has to be created dynamically and must
286 // be requested via Stream() before the instance is deleted!
290 class SW_DLLPUBLIC SwTextBlocks
292 std::unique_ptr
<SwImpBlocks
> pImp
;
296 SwTextBlocks( const OUString
& );
300 void ClearDoc(); // Delete Doc-contents.
302 void SetName( const OUString
& );
303 sal_uLong
GetError() const { return nErr
; }
305 OUString
GetBaseURL() const;
306 void SetBaseURL( const OUString
& rURL
);
310 sal_uInt16
GetCount() const; // Get count text modules.
311 sal_uInt16
GetIndex( const OUString
& ) const; // Get index of short names.
312 sal_uInt16
GetLongIndex( const OUString
& ) const; // Get index of long names.
313 OUString
GetShortName( sal_uInt16
) const; // Get short name for index.
314 OUString
GetLongName( sal_uInt16
) const; // Get long name for index.
316 bool Delete( sal_uInt16
);
317 void Rename( sal_uInt16
, const OUString
*, const OUString
* );
318 sal_uLong
CopyBlock( SwTextBlocks
& rSource
, OUString
& rSrcShort
,
319 const OUString
& rLong
);
321 bool BeginGetDoc( sal_uInt16
); // Read text modules.
322 void EndGetDoc(); // Release text modules.
324 bool BeginPutDoc( const OUString
&, const OUString
& ); // Begin save.
325 sal_uInt16
PutDoc(); // End save.
327 sal_uInt16
PutText( const OUString
&, const OUString
&, const OUString
& ); // Save (short name, text).
329 bool IsOnlyTextBlock( sal_uInt16
) const;
330 bool IsOnlyTextBlock( const OUString
& rShort
) const;
332 OUString
GetFileName() const; // Filename of pImp.
333 bool IsReadOnly() const; // ReadOnly-flag of pImp.
335 bool GetMacroTable( sal_uInt16 nIdx
, SvxMacroTableDtor
& rMacroTable
);
336 bool SetMacroTable( sal_uInt16 nIdx
, const SvxMacroTableDtor
& rMacroTable
);
338 bool StartPutMuchBlockEntries();
339 void EndPutMuchBlockEntries();
342 // BEGIN source/filter/basflt/fltini.cxx
344 extern SwRead ReadAscii
, /*ReadSwg, ReadSw3, */ReadHTML
, ReadXML
;
346 SW_DLLPUBLIC SwRead
SwGetReaderXML();
348 // END source/filter/basflt/fltini.cxx
350 extern bool SetHTMLTemplate( SwDoc
&rDoc
); //For templates from HTML before loading shellio.cxx.
352 // Base-class of all writers.
354 class IDocumentSettingAccess
;
355 class IDocumentStylePoolAccess
;
357 class SW_DLLPUBLIC Writer
360 SwAsciiOptions aAscOpts
;
363 void AddFontItem( SfxItemPool
& rPool
, const SvxFontItem
& rFont
);
364 void AddFontItems_( SfxItemPool
& rPool
, sal_uInt16 nWhichId
);
366 std::unique_ptr
<Writer_Impl
> m_pImpl
;
368 Writer(Writer
const&) = delete;
369 Writer
& operator=(Writer
const&) = delete;
373 SwPaM
* pOrigPam
; // Last Pam that has to be processed.
374 const OUString
* pOrigFileName
;
377 bool CopyNextPam( SwPaM
** );
379 void PutNumFormatFontsInAttrPool();
380 void PutEditEngFontsInAttrPool();
382 virtual sal_uLong
WriteStream() = 0;
383 void SetBaseURL( const OUString
& rURL
) { sBaseURL
= rURL
; }
385 IDocumentSettingAccess
& getIDocumentSettingAccess();
386 const IDocumentSettingAccess
& getIDocumentSettingAccess() const;
388 IDocumentStylePoolAccess
& getIDocumentStylePoolAccess();
389 const IDocumentStylePoolAccess
& getIDocumentStylePoolAccess() const;
395 bool bShowProgress
: 1;
396 bool bWriteClipboardDoc
: 1;
397 bool bWriteOnlyFirstTable
: 1;
398 bool bASCII_ParaAsCR
: 1;
399 bool bASCII_ParaAsBlanc
: 1;
400 bool bASCII_NoLastLineEnd
: 1;
401 bool bUCS2_WithStartChar
: 1;
402 bool bExportPargraphNumbering
: 1;
405 bool bOrganizerMode
: 1;
408 virtual ~Writer() override
;
410 virtual sal_uLong
Write( SwPaM
&, SfxMedium
&, const OUString
* );
411 sal_uLong
Write( SwPaM
&, SvStream
&, const OUString
* );
412 virtual sal_uLong
Write( SwPaM
&, const css::uno::Reference
< css::embed::XStorage
>&, const OUString
*, SfxMedium
* = nullptr );
413 virtual sal_uLong
Write( SwPaM
&, SotStorage
&, const OUString
* );
415 virtual void SetupFilterOptions(SfxMedium
& rMedium
);
417 virtual bool IsStgWriter() const;
419 void SetShowProgress( bool bFlag
) { bShowProgress
= bFlag
; }
421 const OUString
* GetOrigFileName() const { return pOrigFileName
; }
423 const SwAsciiOptions
& GetAsciiOptions() const { return aAscOpts
; }
424 void SetAsciiOptions( const SwAsciiOptions
& rOpt
) { aAscOpts
= rOpt
; }
426 const OUString
& GetBaseURL() const { return sBaseURL
;}
428 // Look up next bookmark position from bookmark-table.
429 sal_Int32
FindPos_Bkmk( const SwPosition
& rPos
) const;
430 // Build a bookmark table, which is sort by the node position. The
431 // OtherPos of the bookmarks also inserted.
432 void CreateBookmarkTable();
433 // Search all Bookmarks in the range and return it in the Array.
434 bool GetBookmarks( const SwContentNode
& rNd
,
435 sal_Int32 nStt
, sal_Int32 nEnd
,
436 std::vector
< const ::sw::mark::IMark
* >& rArr
);
438 // Create new PaM at position.
439 static SwPaM
* NewSwPaM(SwDoc
& rDoc
,
440 sal_uLong
const nStartIdx
, sal_uLong
const nEndIdx
);
442 // If applicable copy a local file into internet.
443 bool CopyLocalFileToINet( OUString
& rFileNm
);
445 // Stream-specific routines. Do not use in storage-writer!
447 // Optimizing output on stream.
448 static SvStream
& OutLong( SvStream
& rStrm
, long nVal
);
449 static SvStream
& OutULong( SvStream
& rStrm
, sal_uLong nVal
);
451 void SetStream(SvStream
*const pStream
);
454 void SetOrganizerMode( bool bSet
) { bOrganizerMode
= bSet
; }
457 typedef tools::SvRef
<Writer
> WriterRef
;
459 // Base class for all storage writers.
460 class SW_DLLPUBLIC StgWriter
: public Writer
463 tools::SvRef
<SotStorage
> pStg
;
464 css::uno::Reference
< css::embed::XStorage
> xStg
;
466 // Create error at call.
467 virtual sal_uLong
WriteStream() override
;
468 virtual sal_uLong
WriteStorage() = 0;
469 virtual sal_uLong
WriteMedium( SfxMedium
& ) = 0;
474 StgWriter() : Writer() {}
476 virtual bool IsStgWriter() const override
;
478 virtual sal_uLong
Write( SwPaM
&, const css::uno::Reference
< css::embed::XStorage
>&, const OUString
*, SfxMedium
* = nullptr ) override
;
479 virtual sal_uLong
Write( SwPaM
&, SotStorage
&, const OUString
* ) override
;
481 SotStorage
& GetStorage() const { return *pStg
; }
484 // Interface class for general access on special writers.
486 class SW_DLLPUBLIC SwWriter
489 tools::SvRef
<SotStorage
> pStg
;
490 css::uno::Reference
< css::embed::XStorage
> xStg
;
494 SwCursorShell
*pShell
;
500 sal_uLong
Write( WriterRef
& rxWriter
, const OUString
* = nullptr);
502 SwWriter( SvStream
&, SwCursorShell
&, bool bWriteAll
= false );
503 SwWriter( SvStream
&, SwDoc
& );
504 SwWriter( SvStream
&, SwPaM
&, bool bWriteAll
= false );
506 SwWriter( const css::uno::Reference
< css::embed::XStorage
>&, SwDoc
& );
508 SwWriter( SfxMedium
&, SwCursorShell
&, bool bWriteAll
);
509 SwWriter( SfxMedium
&, SwDoc
& );
512 typedef Reader
* (*FnGetReader
)();
513 typedef void (*FnGetWriter
)(const OUString
&, const OUString
& rBaseURL
, WriterRef
&);
514 sal_uLong
SaveOrDelMSVBAStorage( SfxObjectShell
&, SotStorage
&, bool, const OUString
& );
515 sal_uLong
GetSaveWarningOfMSVBAStorage( SfxObjectShell
&rDocS
);
517 struct SwReaderWriterEntry
520 FnGetReader fnGetReader
;
521 FnGetWriter fnGetWriter
;
524 SwReaderWriterEntry( const FnGetReader fnReader
, const FnGetWriter fnWriter
, bool bDel
)
525 : pReader( nullptr ), fnGetReader( fnReader
), fnGetWriter( fnWriter
), bDelReader( bDel
)
528 /// Get access to the reader.
531 /// Get access to the writer.
532 void GetWriter( const OUString
& rNm
, const OUString
& rBaseURL
, WriterRef
& xWrt
) const;
535 namespace SwReaderWriter
537 SW_DLLPUBLIC Reader
* GetRtfReader();
538 SW_DLLPUBLIC Reader
* GetDOCXReader();
540 /// Return reader based on the name.
541 Reader
* GetReader( const OUString
& rFltName
);
543 /// Return writer based on the name.
544 SW_DLLPUBLIC
void GetWriter( const OUString
& rFltName
, const OUString
& rBaseURL
, WriterRef
& xWrt
);
547 void GetRTFWriter( const OUString
&, const OUString
&, WriterRef
& );
548 void GetASCWriter( const OUString
&, const OUString
&, WriterRef
& );
549 void GetHTMLWriter( const OUString
&, const OUString
&, WriterRef
& );
550 void GetXMLWriter( const OUString
&, const OUString
&, WriterRef
& );
554 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */