android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / inc / shellio.hxx
blobf902194c6c00a6952eb6d5e0bb6ed92e8af57a7e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
22 #include <memory>
24 #include <com/sun/star/uno/Reference.h>
25 #include <sot/storage.hxx>
26 #include <tools/date.hxx>
27 #include <tools/time.hxx>
28 #include <tools/datetime.hxx>
29 #include <tools/ref.hxx>
30 #include <rtl/ref.hxx>
31 #include <osl/thread.h>
32 #include <o3tl/deleter.hxx>
33 #include <o3tl/typed_flags_set.hxx>
34 #include "swdllapi.h"
35 #include "docfac.hxx"
36 #include "unocrsr.hxx"
38 class SfxItemPool;
39 class SfxItemSet;
40 class SfxMedium;
41 class SvStream;
42 class SvxFontItem;
43 class SvxMacroTableDtor;
44 class SwContentNode;
45 class SwCursorShell;
46 class SwDoc;
47 class SwPaM;
48 class SwTextBlocks;
49 struct SwPosition;
50 struct Writer_Impl;
51 namespace sw::mark { class IMark; }
52 namespace com::sun::star::embed { class XStorage; }
54 // Defines the count of chars at which a paragraph read via ASCII/W4W-Reader
55 // is forced to wrap. It has to be always greater than 200!!!
56 // Note: since version 4.3, maximum character count changed to 4 GiB from 64 KiB
57 // in a paragraph, but because of the other limitations, we set a lower wrap value
58 // to get a working text editor e.g. without freezing and crash during loading of
59 // a 50 MB text line, or unusably slow editing of a 5 MB text line.
60 #define MAX_ASCII_PARA 250000
62 class SW_DLLPUBLIC SwAsciiOptions
64 OUString m_sFont;
65 rtl_TextEncoding m_eCharSet;
66 LanguageType m_nLanguage;
67 LineEnd m_eCRLF_Flag;
68 bool m_bIncludeBOM; // Whether to include a byte-order-mark in the output.
69 bool m_bIncludeHidden; // Whether to include hidden paragraphs and text.
71 public:
73 const OUString& GetFontName() const { return m_sFont; }
74 void SetFontName( const OUString& rFont ) { m_sFont = rFont; }
76 rtl_TextEncoding GetCharSet() const { return m_eCharSet; }
77 void SetCharSet( rtl_TextEncoding nVal ) { m_eCharSet = nVal; }
79 LanguageType GetLanguage() const { return m_nLanguage; }
80 void SetLanguage( LanguageType nVal ) { m_nLanguage = nVal; }
82 LineEnd GetParaFlags() const { return m_eCRLF_Flag; }
83 void SetParaFlags( LineEnd eVal ) { m_eCRLF_Flag = eVal; }
85 bool GetIncludeBOM() const { return m_bIncludeBOM; }
86 void SetIncludeBOM( bool bVal ) { m_bIncludeBOM = bVal; }
88 bool GetIncludeHidden() const { return m_bIncludeHidden; }
89 void SetIncludeHidden( bool bVal ) { m_bIncludeHidden = bVal; }
91 void Reset();
93 // for the automatic conversion (mail/news/...)
94 void ReadUserData( std::u16string_view );
95 void WriteUserData( OUString& ) const;
97 SwAsciiOptions() { Reset(); }
100 // Base class of possible options for a special reader.
101 class Reader;
103 class SwgReaderOption
105 SwAsciiOptions m_aASCIIOpts;
106 bool m_bFrameFormats;
107 bool m_bPageDescs;
108 bool m_bTextFormats;
109 bool m_bNumRules;
110 bool m_bMerge;
111 css::uno::Reference<css::io::XInputStream> m_xInputStream;
112 public:
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 m_aASCIIOpts; }
132 void SetASCIIOpts( const SwAsciiOptions& rOpts ) { m_aASCIIOpts = rOpts; }
133 void ResetASCIIOpts() { m_aASCIIOpts.Reset(); }
135 css::uno::Reference<css::io::XInputStream>& GetInputStream() { return m_xInputStream; }
136 void SetInputStream(const css::uno::Reference<css::io::XInputStream>& xInputStream)
138 m_xInputStream = xInputStream;
141 SwgReaderOption()
142 { ResetAllFormatsOnly(); m_aASCIIOpts.Reset(); }
145 // Calls reader with its options, document, cursor etc.
146 class SW_DLLPUBLIC SwReader: public SwDocFac
148 SvStream* mpStrm;
149 tools::SvRef<SotStorage> mpStg;
150 css::uno::Reference < css::embed::XStorage > mxStg;
151 SfxMedium* mpMedium; // Who wants to obtain a Medium (W4W).
153 SwPaM* mpCursor;
154 OUString maFileName;
155 OUString msBaseURL;
156 bool mbSkipImages;
158 public:
160 // Initial reading. Document is created only at Read(...)
161 // or in case it is given, into that.
162 // Special case for Load with Sw3Reader.
163 SwReader( SfxMedium&, OUString aFilename, SwDoc *pDoc = nullptr );
165 // Read into existing document.
166 // Document and position in document are taken from SwPaM.
167 SwReader( SvStream&, OUString aFilename, const OUString& rBaseURL, SwPaM& );
168 SwReader( SfxMedium&, OUString aFilename, SwPaM& );
169 SwReader( css::uno::Reference < css::embed::XStorage > , OUString aFilename, SwPaM& );
171 // The only export interface is SwReader::Read(...)!!!
172 ErrCode Read( const Reader& );
174 // Ask for glossaries.
175 bool HasGlossaries( const Reader& );
176 bool ReadGlossaries( const Reader&, SwTextBlocks&, bool bSaveRelFiles );
178 protected:
179 void SetBaseURL( const OUString& rURL ) { msBaseURL = rURL; }
180 void SetSkipImages( bool bSkipImages ) { mbSkipImages = bSkipImages; }
183 typedef std::unique_ptr<SwReader, o3tl::default_delete<SwReader>> SwReaderPtr;
185 // Special Readers can be both!! (Excel, W4W, .. ).
186 enum class SwReaderType {
187 NONE = 0x00,
188 Stream = 0x01,
189 Storage = 0x02
191 namespace o3tl {
192 template<> struct typed_flags<SwReaderType> : is_typed_flags<SwReaderType, 0x03> {};
195 extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportDOC(SvStream &rStream, const OUString &rFltName);
196 extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportDOCX(SvStream &rStream);
197 extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportRTF(SvStream &rStream);
198 extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportHTML(SvStream &rStream);
199 SAL_DLLPUBLIC_EXPORT void FlushFontCache();
201 class SW_DLLPUBLIC Reader
203 friend class SwReader;
204 friend bool TestImportDOC(SvStream &rStream, const OUString &rFltName);
205 friend bool TestImportRTF(SvStream &rStream);
206 friend bool TestImportHTML(SvStream &rStream);
207 rtl::Reference<SwDoc> mxTemplate;
208 OUString m_aTemplateName;
210 Date m_aDateStamp;
211 tools::Time m_aTimeStamp;
212 DateTime m_aCheckDateTime;
214 protected:
215 SvStream* m_pStream;
216 tools::SvRef<SotStorage> m_pStorage;
217 css::uno::Reference < css::embed::XStorage > m_xStorage;
218 SfxMedium* m_pMedium; // Who wants to obtain a Medium (W4W).
220 SwgReaderOption m_aOption;
221 bool m_bInsertMode : 1;
222 bool m_bTemplateBrowseMode : 1;
223 bool m_bReadUTF8: 1; // Interpret stream as UTF-8.
224 bool m_bBlockMode: 1;
225 bool m_bOrganizerMode : 1;
226 bool m_bHasAskTemplateName : 1;
227 bool m_bIgnoreHTMLComments : 1;
228 bool m_bSkipImages : 1;
230 virtual OUString GetTemplateName(SwDoc& rDoc) const;
232 public:
233 Reader();
234 virtual ~Reader();
236 virtual SwReaderType GetReaderType();
237 SwgReaderOption& GetReaderOpt() { return m_aOption; }
239 virtual void SetFltName( const OUString& rFltNm );
241 // Adapt item-set of a Frame-Format to the old format.
242 static void ResetFrameFormatAttrs( SfxItemSet &rFrameSet );
244 // Adapt Frame-/Graphics-/OLE- styles to the old format
245 // (without borders etc.).
246 static void ResetFrameFormats( SwDoc& rDoc );
248 // Load filter template, set it and release it again.
249 SwDoc* GetTemplateDoc(SwDoc& rDoc);
250 bool SetTemplate( SwDoc& rDoc );
251 void ClearTemplate();
252 void SetTemplateName( const OUString& rDir );
253 void MakeHTMLDummyTemplateDoc();
255 bool IsReadUTF8() const { return m_bReadUTF8; }
256 void SetReadUTF8( bool bSet ) { m_bReadUTF8 = bSet; }
258 bool IsBlockMode() const { return m_bBlockMode; }
259 void SetBlockMode( bool bSet ) { m_bBlockMode = bSet; }
261 bool IsOrganizerMode() const { return m_bOrganizerMode; }
262 void SetOrganizerMode( bool bSet ) { m_bOrganizerMode = bSet; }
264 void SetIgnoreHTMLComments( bool bSet ) { m_bIgnoreHTMLComments = bSet; }
266 virtual bool HasGlossaries() const;
267 virtual bool ReadGlossaries( SwTextBlocks&, bool bSaveRelFiles ) const;
269 // Read the sections of the document, which is equal to the medium.
270 // Returns the count of it
271 virtual size_t GetSectionList( SfxMedium& rMedium,
272 std::vector<OUString>& rStrings) const;
274 const tools::SvRef<SotStorage>& getSotStorageRef() const { return m_pStorage; };
275 void setSotStorageRef(const tools::SvRef<SotStorage>& pStgRef) { m_pStorage = pStgRef; };
277 private:
278 virtual ErrCode Read(SwDoc &, const OUString& rBaseURL, SwPaM &, const OUString &)=0;
280 // Everyone who does not need the streams / storages open
281 // has to override the method (W4W!!).
282 virtual bool SetStrmStgPtr();
285 class AsciiReader final : public Reader
287 friend class SwReader;
288 virtual ErrCode Read( SwDoc &, const OUString& rBaseURL, SwPaM &, const OUString &) override;
289 public:
290 AsciiReader(): Reader() {}
293 class SW_DLLPUBLIC StgReader : public Reader
295 OUString m_aFltName;
297 public:
298 virtual SwReaderType GetReaderType() override;
299 const OUString& GetFltName() const { return m_aFltName; }
300 virtual void SetFltName( const OUString& r ) override;
303 // The given stream has to be created dynamically and must
304 // be requested via Stream() before the instance is deleted!
306 class SwImpBlocks;
308 class SW_DLLPUBLIC SwTextBlocks
310 std::unique_ptr<SwImpBlocks> m_pImp;
311 ErrCode m_nErr;
313 public:
314 SwTextBlocks( const OUString& );
315 ~SwTextBlocks();
317 SwDoc* GetDoc();
318 void ClearDoc(); // Delete Doc-contents.
319 OUString GetName() const;
320 void SetName( const OUString& );
321 ErrCode const & GetError() const { return m_nErr; }
323 OUString GetBaseURL() const;
324 void SetBaseURL( const OUString& rURL );
326 sal_uInt16 GetCount() const; // Get count text modules.
327 sal_uInt16 GetIndex( const OUString& ) const; // Get index of short names.
328 sal_uInt16 GetLongIndex( std::u16string_view ) const; // Get index of long names.
329 OUString GetShortName( sal_uInt16 ) const; // Get short name for index.
330 OUString GetLongName( sal_uInt16 ) const; // Get long name for index.
332 bool Delete( sal_uInt16 );
333 void Rename( sal_uInt16, const OUString*, const OUString* );
334 ErrCode const & CopyBlock( SwTextBlocks const & rSource, OUString& rSrcShort,
335 const OUString& rLong );
337 bool BeginGetDoc( sal_uInt16 ); // Read text modules.
338 void EndGetDoc(); // Release text modules.
340 bool BeginPutDoc( const OUString&, const OUString& ); // Begin save.
341 sal_uInt16 PutDoc(); // End save.
343 sal_uInt16 PutText( const OUString&, const OUString&, const OUString& ); // Save (short name, text).
345 bool IsOnlyTextBlock( sal_uInt16 ) const;
346 bool IsOnlyTextBlock( const OUString& rShort ) const;
348 OUString const & GetFileName() const; // Filename of pImp.
349 bool IsReadOnly() const; // ReadOnly-flag of pImp.
351 bool GetMacroTable( sal_uInt16 nIdx, SvxMacroTableDtor& rMacroTable );
352 bool SetMacroTable( sal_uInt16 nIdx, const SvxMacroTableDtor& rMacroTable );
354 bool StartPutMuchBlockEntries();
355 void EndPutMuchBlockEntries();
358 // BEGIN source/filter/basflt/fltini.cxx
360 extern Reader *ReadAscii, *ReadHTML, *ReadXML;
362 SW_DLLPUBLIC Reader* SwGetReaderXML();
364 // END source/filter/basflt/fltini.cxx
366 extern bool SetHTMLTemplate( SwDoc &rDoc ); //For templates from HTML before loading shellio.cxx.
368 // Base-class of all writers.
370 class IDocumentSettingAccess;
371 class IDocumentStylePoolAccess;
373 class SW_DLLPUBLIC Writer
374 : public SvRefBase
376 SwAsciiOptions m_aAsciiOptions;
377 OUString m_sBaseURL;
379 void AddFontItem( SfxItemPool& rPool, const SvxFontItem& rFont );
380 void AddFontItems_( SfxItemPool& rPool, sal_uInt16 nWhichId );
382 std::unique_ptr<Writer_Impl> m_pImpl;
384 Writer(Writer const&) = delete;
385 Writer& operator=(Writer const&) = delete;
387 protected:
389 const OUString* m_pOrigFileName;
391 void ResetWriter();
392 bool CopyNextPam( SwPaM ** );
394 void PutNumFormatFontsInAttrPool();
395 void PutEditEngFontsInAttrPool();
397 virtual ErrCode WriteStream() = 0;
398 void SetBaseURL( const OUString& rURL ) { m_sBaseURL = rURL; }
400 IDocumentSettingAccess& getIDocumentSettingAccess();
401 const IDocumentSettingAccess& getIDocumentSettingAccess() const;
403 IDocumentStylePoolAccess& getIDocumentStylePoolAccess();
404 const IDocumentStylePoolAccess& getIDocumentStylePoolAccess() const;
406 public:
407 SwDoc* m_pDoc;
408 SwPaM* m_pOrigPam; // Last Pam that has to be processed.
409 std::shared_ptr<SwUnoCursor> m_pCurrentPam;
410 bool m_bWriteAll : 1;
411 bool m_bShowProgress : 1;
412 bool m_bWriteClipboardDoc : 1;
413 bool m_bWriteOnlyFirstTable : 1;
414 bool m_bASCII_ParaAsCR : 1;
415 bool m_bASCII_ParaAsBlank : 1;
416 bool m_bASCII_NoLastLineEnd : 1;
417 bool m_bUCS2_WithStartChar : 1;
418 bool m_bExportParagraphNumbering : 1;
420 bool m_bBlock : 1;
421 bool m_bOrganizerMode : 1;
422 bool m_bHideDeleteRedlines : 1;
424 Writer();
425 virtual ~Writer() override;
427 virtual ErrCode Write( SwPaM&, SfxMedium&, const OUString* );
428 ErrCode Write( SwPaM&, SvStream&, const OUString* );
429 virtual ErrCode Write( SwPaM&, const css::uno::Reference < css::embed::XStorage >&, const OUString*, SfxMedium* = nullptr );
430 virtual ErrCode Write( SwPaM&, SotStorage&, const OUString* );
432 virtual void SetupFilterOptions(SfxMedium& rMedium);
434 virtual bool IsStgWriter() const;
436 void SetShowProgress( bool bFlag ) { m_bShowProgress = bFlag; }
438 const OUString* GetOrigFileName() const { return m_pOrigFileName; }
440 const SwAsciiOptions& GetAsciiOptions() const { return m_aAsciiOptions; }
441 void SetAsciiOptions( const SwAsciiOptions& rOpt ) { m_aAsciiOptions = rOpt; }
443 const OUString& GetBaseURL() const { return m_sBaseURL;}
445 // Look up next bookmark position from bookmark-table.
446 sal_Int32 FindPos_Bkmk( const SwPosition& rPos ) const;
447 // Build a bookmark table, which is sort by the node position. The
448 // OtherPos of the bookmarks also inserted.
449 void CreateBookmarkTable();
450 // Search all Bookmarks in the range and return it in the Array.
451 bool GetBookmarks( const SwContentNode& rNd,
452 sal_Int32 nStt, sal_Int32 nEnd,
453 std::vector< const ::sw::mark::IMark* >& rArr );
455 // Create new PaM at position.
456 static std::shared_ptr<SwUnoCursor> NewUnoCursor(SwDoc & rDoc,
457 SwNodeOffset const nStartIdx, SwNodeOffset const nEndIdx);
459 // If applicable copy a local file into internet.
460 bool CopyLocalFileToINet( OUString& rFileNm );
462 // Stream-specific routines. Do not use in storage-writer!
464 void SetStream(SvStream *const pStream);
465 SvStream& Strm();
467 void SetOrganizerMode( bool bSet ) { m_bOrganizerMode = bSet; }
470 typedef tools::SvRef<Writer> WriterRef;
472 // Base class for all storage writers.
473 class SW_DLLPUBLIC StgWriter : public Writer
475 protected:
476 tools::SvRef<SotStorage> m_pStg;
477 css::uno::Reference < css::embed::XStorage > m_xStg;
479 // Create error at call.
480 virtual ErrCode WriteStream() override;
481 virtual ErrCode WriteStorage() = 0;
482 virtual ErrCode WriteMedium( SfxMedium& ) = 0;
484 using Writer::Write;
486 public:
487 StgWriter() : Writer() {}
489 virtual bool IsStgWriter() const override;
491 virtual ErrCode Write( SwPaM&, const css::uno::Reference < css::embed::XStorage >&, const OUString*, SfxMedium* = nullptr ) override;
492 virtual ErrCode Write( SwPaM&, SotStorage&, const OUString* ) override;
494 SotStorage& GetStorage() const { return *m_pStg; }
497 // Interface class for general access on special writers.
499 class SW_DLLPUBLIC SwWriter
501 SvStream* m_pStrm;
502 css::uno::Reference < css::embed::XStorage > m_xStg;
503 SfxMedium* m_pMedium;
505 SwPaM* m_pOutPam;
506 SwCursorShell *m_pShell;
507 SwDoc &m_rDoc;
509 bool m_bWriteAll;
511 public:
512 ErrCode Write( WriterRef const & rxWriter, const OUString* = nullptr);
514 SwWriter( SvStream&, SwCursorShell &, bool bWriteAll = false );
515 SwWriter( SvStream&, SwDoc & );
516 SwWriter( SvStream&, SwPaM &, bool bWriteAll = false );
518 SwWriter( css::uno::Reference < css::embed::XStorage > , SwDoc& );
520 SwWriter( SfxMedium&, SwCursorShell &, bool bWriteAll );
521 SwWriter( SfxMedium&, SwDoc & );
524 typedef Reader* (*FnGetReader)();
525 typedef void (*FnGetWriter)(std::u16string_view, const OUString& rBaseURL, WriterRef&);
526 ErrCode SaveOrDelMSVBAStorage( SfxObjectShell&, SotStorage&, bool, const OUString& );
527 ErrCode GetSaveWarningOfMSVBAStorage( SfxObjectShell &rDocS );
529 struct SwReaderWriterEntry
531 Reader* pReader;
532 FnGetReader fnGetReader;
533 FnGetWriter fnGetWriter;
534 bool bDelReader;
536 SwReaderWriterEntry( const FnGetReader fnReader, const FnGetWriter fnWriter, bool bDel )
537 : pReader( nullptr ), fnGetReader( fnReader ), fnGetWriter( fnWriter ), bDelReader( bDel )
540 /// Get access to the reader.
541 Reader* GetReader();
543 /// Get access to the writer.
544 void GetWriter( std::u16string_view rNm, const OUString& rBaseURL, WriterRef& xWrt ) const;
547 namespace SwReaderWriter
549 SW_DLLPUBLIC Reader* GetRtfReader();
550 SW_DLLPUBLIC Reader* GetDOCXReader();
552 /// Return reader based on the name.
553 Reader* GetReader( const OUString& rFltName );
555 /// Return writer based on the name.
556 SW_DLLPUBLIC void GetWriter( std::u16string_view rFltName, const OUString& rBaseURL, WriterRef& xWrt );
559 void GetRTFWriter( std::u16string_view, const OUString&, WriterRef& );
560 void GetASCWriter( std::u16string_view, const OUString&, WriterRef&);
561 void GetHTMLWriter( std::u16string_view, const OUString&, WriterRef& );
562 void GetXMLWriter( std::u16string_view, const OUString&, WriterRef& );
564 #endif
566 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */