Update ooo320-m1
[ooovba.git] / binfilter / inc / bf_sw / shellio.hxx
blobe26e5eb0c5824402108718951cbdda392decae34
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: shellio.hxx,v $
10 * $Revision: 1.11 $
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 ************************************************************************/
30 #ifndef _SHELLIO_HXX
31 #define _SHELLIO_HXX
33 #ifndef _DATETIME_HXX //autogen
34 #include <tools/datetime.hxx>
35 #endif
36 #ifndef _REF_HXX //autogen
37 #include <tools/ref.hxx>
38 #endif
39 #ifndef _SOT_FORMATS_HXX //autogen
40 #include <sot/formats.hxx>
41 #endif
43 #ifndef _DOCFAC_HXX
44 #include <docfac.hxx> // SwDocFac
45 #endif
46 #include <tools/debug.hxx>
47 class SvStream;
48 namespace binfilter {
49 class SvStorage;
50 class SvStorageStreamRef;
51 class SvPtrarr;
52 class SfxItemPool;
53 class SfxItemSet;
54 class SvStrings;
55 class SvStringsSortDtor;
56 class SvxMacroTableDtor;
58 // einige Forward - Deklarationen
59 class SfxFactoryFilterContainer;
60 class SfxFilter;
61 class SfxMedium;
62 class SvxFontItem;
64 class Sw3Io;
65 class SwCntntNode;
66 class SwCrsrShell;
67 class SwDoc;
68 class SwPaM;
69 struct SwPosition;
70 struct Writer_Impl;
72 // ab so vielen chars wird ein mit einem ASCII/W4W-Reader eingelesener
73 // Absatz zwangsweise umgebrochen. Muss immer groesser als 200 sein !!!
74 #define MAX_ASCII_PARA 10000
77 class SwAsciiOptions
79 String sFont;
80 rtl_TextEncoding eCharSet;
81 USHORT nLanguage;
82 LineEnd eCRLF_Flag;
84 public:
86 const String& GetFontName() const { return sFont; }
87 void SetFontName( const String& rFont ) { sFont = rFont; }
89 rtl_TextEncoding GetCharSet() const { return eCharSet; }
90 void SetCharSet( rtl_TextEncoding nVal ) { eCharSet = nVal; }
92 USHORT GetLanguage() const { return nLanguage; }
93 void SetLanguage( USHORT nVal ) { nLanguage = nVal; }
95 LineEnd GetParaFlags() const { return eCRLF_Flag; }
96 void SetParaFlags( LineEnd eVal ) { eCRLF_Flag = eVal; }
98 void Reset()
100 sFont.Erase();
101 eCRLF_Flag = GetSystemLineEnd();
102 eCharSet = ::gsl_getSystemTextEncoding();
103 nLanguage = 0;
105 // for the automatic conversion (mail/news/...)
106 void ReadUserData( const String& );
108 SwAsciiOptions() { Reset(); }
111 /**************** SwReader/Reader ************************/
112 // Basisklasse der moeglichen Optionen fuer einen speziellen Reader
113 class Reader;
114 // Ruft den Reader mit seinen Optionen, Dokument, Cursor etc.
115 class SwReader;
116 // SwRead ist der Pointer auf die Read-Optionen-Basisklasse
117 typedef Reader *SwRead;
119 class SwgReaderOption
121 SwAsciiOptions aASCIIOpts;
122 union
124 BOOL bFmtsOnly;
125 struct
127 BOOL bFrmFmts: 1;
128 BOOL bPageDescs: 1;
129 BOOL bTxtFmts: 1;
130 BOOL bNumRules: 1;
131 BOOL bMerge:1;
132 } Fmts;
133 } What;
135 public:
136 void ResetAllFmtsOnly() { What.bFmtsOnly = 0; }
137 void SetAllFmtsOnly() { What.bFmtsOnly = (BOOL)0xff; }
138 BOOL IsFmtsOnly() const { return What.bFmtsOnly; }
140 BOOL IsFrmFmts() const { return What.Fmts.bFrmFmts; }
141 void SetFrmFmts( const BOOL bNew) { What.Fmts.bFrmFmts = bNew; }
143 BOOL IsPageDescs() const { return What.Fmts.bPageDescs; }
144 void SetPageDescs( const BOOL bNew) { What.Fmts.bPageDescs = bNew; }
146 BOOL IsTxtFmts() const { return What.Fmts.bTxtFmts; }
147 void SetTxtFmts( const BOOL bNew) { What.Fmts.bTxtFmts = bNew; }
149 BOOL IsNumRules() const { return What.Fmts.bNumRules; }
150 void SetNumRules( const BOOL bNew) { What.Fmts.bNumRules = bNew; }
152 BOOL IsMerge() const { return What.Fmts.bMerge; }
153 void SetMerge( const BOOL bNew ) { What.Fmts.bMerge = bNew; }
155 const SwAsciiOptions& GetASCIIOpts() const { return aASCIIOpts; }
156 void SetASCIIOpts( const SwAsciiOptions& rOpts ) { aASCIIOpts = rOpts; }
157 void ResetASCIIOpts() { aASCIIOpts.Reset(); }
159 SwgReaderOption()
160 { ResetAllFmtsOnly(); aASCIIOpts.Reset(); }
163 class SwReader: public SwDocFac
165 SvStream* pStrm;
166 SvStorage* pStg;
167 SfxMedium* pMedium; // wer ein Medium haben will (W4W)
169 SwPaM* pCrsr;
170 String aFileName;
172 public:
174 * Initiales Einlesen. Dokument wird erst beim Read(..) angelegt.
175 * JP 25.04.95: oder falls es mitgegeben wird, in dieses.
176 * Sonderfall fuer Load mit Sw3Reader
178 SwReader( SvStorage&, const String& rFilename, SwDoc *pDoc = 0 );
179 SwReader( SfxMedium&, const String& rFilename, SwDoc *pDoc = 0 );
181 * In ein existierendes Dokument einlesen, Dokument und
182 * Position im Dokument werden aus dem SwPaM uebernommen.
184 SwReader( SfxMedium&, const String& rFilename, SwPaM& );
187 * Nur SwReader::Read(...) ist die Export-Schnittstelle!!!
189 BOOL NeedsPasswd( const Reader& );
190 BOOL CheckPasswd( const String&, const Reader& );
191 ULONG Read( const Reader& );
193 // ask for glossaries
198 /* \f */
199 /**************** SPEZIELLE Reader ************************/
201 // spezielle - Reader koennen beides sein !! (Excel, W4W, .. )
202 #define SW_STREAM_READER 1
203 #define SW_STORAGE_READER 2
205 class Reader
207 friend class SwReader;
208 SwDoc* pTemplate;
209 String aTemplateNm;
210 Date aDStamp;
211 Time aTStamp;
212 DateTime aChkDateTime;
214 protected:
215 SvStream* pStrm;
216 SvStorage* pStg;
217 SfxMedium* pMedium; // wer ein Medium haben will (W4W)
219 SwgReaderOption aOpt;
220 BOOL bInsertMode : 1;
221 BOOL bTmplBrowseMode : 1;
222 BOOL bReadUTF8: 1; // Stream als UTF-8 interpretieren
223 BOOL bBlockMode: 1;
224 BOOL bOrganizerMode : 1;
225 BOOL bHasAskTemplateName : 1;
226 BOOL bIgnoreHTMLComments : 1;
228 virtual String GetTemplateName() const;
230 public:
231 Reader();
232 virtual ~Reader();
234 virtual int GetReaderType();
235 SwgReaderOption& GetReaderOpt() { return aOpt; }
237 virtual void SetFltName( const String& rFltNm );
238 static void SetNoOutlineNum( SwDoc& rDoc );
240 // den Item-Set eines Frm-Formats an das alte Format anpassen
241 static void ResetFrmFmtAttrs( SfxItemSet &rFrmSet );
243 // die Rahmen-/Grafik-/OLE-Vorlagen an das alte Format (ohne
244 // Umrandung etc.) anpassen
245 static void ResetFrmFmts( SwDoc& rDoc );
247 // Die Filter-Vorlage laden, setzen und wieder freigeben
248 SwDoc* GetTemplateDoc();
249 BOOL SetTemplate( SwDoc& rDoc );
250 void ClearTemplate();
251 void SetTemplateName( const String& rDir );
253 BOOL IsReadUTF8() const { return bReadUTF8; }
254 void SetReadUTF8( BOOL bSet ) { bReadUTF8 = bSet; }
256 BOOL IsBlockMode() const { return bBlockMode; }
257 void SetBlockMode( BOOL bSet ) { bBlockMode = bSet; }
259 BOOL IsOrganizerMode() const { return bOrganizerMode; }
260 void SetOrganizerMode( BOOL bSet ) { bOrganizerMode = bSet; }
262 BOOL IsIgnoreHTMLComments() const { return bIgnoreHTMLComments; }
263 void SetIgnoreHTMLComments( BOOL bSet ) { bIgnoreHTMLComments = bSet; }
266 // read the sections of the document, which is equal to the medium.
267 // returns the count of it
268 private:
269 virtual ULONG Read(SwDoc &,SwPaM &,const String &)=0;
271 // alle die die Streams / Storages nicht geoeffnet brauchen,
272 // muessen die Methode ueberladen (W4W!!)
273 virtual int SetStrmStgPtr();
278 class AsciiReader: public Reader
280 friend class SwReader;
281 virtual ULONG Read( SwDoc &,SwPaM &,const String &){DBG_BF_ASSERT(0, "STRIP"); return 0;} //STRIP001 virtual ULONG Read( SwDoc &,SwPaM &,const String &);
282 public:
283 AsciiReader(): Reader() {}
286 class SwgReader: public Reader
288 virtual ULONG Read( SwDoc &,SwPaM &,const String &);
291 class StgReader : public Reader
293 String aFltName;
295 protected:
296 ULONG OpenMainStream( SvStorageStreamRef& rRef, USHORT& rBuffSize );
298 public:
299 const String& GetFltName() { return aFltName; }
303 class Sw3Reader : public StgReader
305 Sw3Io* pIO;
306 virtual ULONG Read( SwDoc &,SwPaM &,const String &);
307 public:
308 Sw3Reader() : pIO( 0 ) {}
310 Sw3Io* GetSw3Io() { return pIO; }
311 const Sw3Io* GetSw3Io() const { return pIO; }
312 void SetSw3Io( Sw3Io* pIo ) { pIO = pIo; }
314 // read the sections of the document, which is equal to the medium.
315 // returns the count of it
318 /* \f */
319 ////////////////////////////////////////////////////////////////////////////
321 // Der uebergebene Stream muss dynamisch angelegt werden und
322 // vor dem Loeschen der Instanz per Stream() angefordert
323 // und geloescht werden!
325 class SwImpBlocks;
327 class SwTextBlocks
329 friend class Sw2TextBlocks;
330 friend class Sw3IoImp;
331 SwImpBlocks* pImp;
332 ULONG nErr;
334 public:
335 void Flush(){}
337 ULONG GetError() const { return nErr; }
341 extern void _InitFilter();
342 extern void _FinitFilter();
343 extern SwRead ReadRtf, ReadAscii, ReadSwg, ReadSw3, ReadHTML, ReadXML;
345 extern BOOL SetHTMLTemplate( SwDoc &rDoc ); //Fuer Vorlagen aus HTML.vor laden shellio.cxx
348 /* \f */
349 /////////////////////////////////////////////////////////////////////////////
352 * Schreiben, Writer
356 /* Basis-Klasse aller Writer */
358 class Writer : public SvRefBase
360 SwAsciiOptions aAscOpts;
362 void _AddFontItem( SfxItemPool& rPool, const SvxFontItem& rFont );
363 void _AddFontItems( SfxItemPool& rPool, USHORT nWhichId );
365 protected:
366 Writer_Impl* pImpl;
368 SvStream* pStrm;
369 SwPaM* pOrigPam; // der letze zu bearbeitende Pam
370 const String* pOrigFileName;
372 void ResetWriter();
373 BOOL CopyNextPam( SwPaM ** );
375 void PutNumFmtFontsInAttrPool();
376 void PutEditEngFontsInAttrPool( BOOL bIncl_CJK_CTL = TRUE );
378 virtual ULONG WriteStream() = 0;
380 public:
381 SwDoc* pDoc;
382 SwPaM* pCurPam;
383 BOOL bWriteAll : 1;
384 BOOL bShowProgress : 1;
385 BOOL bWriteClipboardDoc : 1;
386 BOOL bWriteOnlyFirstTable : 1;
387 BOOL bASCII_ParaAsCR : 1;
388 BOOL bASCII_ParaAsBlanc : 1;
389 BOOL bASCII_NoLastLineEnd : 1;
390 BOOL bUCS2_WithStartChar : 1;
392 BOOL bBlock : 1;
393 BOOL bOrganizerMode : 1;
395 Writer();
396 virtual ~Writer();
398 ULONG Write( SwPaM&, SvStream&, const String* = 0 );
399 virtual ULONG Write( SwPaM&, SvStorage&, const String* = 0 );
401 virtual BOOL IsStgWriter() const;
402 virtual BOOL IsSw3Writer() const;
404 BOOL ShowProgress() const { return bShowProgress; }
405 void SetShowProgress( BOOL bFlag = FALSE ) { bShowProgress = bFlag; }
407 const String* GetOrigFileName() const { return pOrigFileName; }
409 const SwAsciiOptions& GetAsciiOptions() const { return aAscOpts; }
410 void SetAsciiOptions( const SwAsciiOptions& rOpt ) { aAscOpts = rOpt; }
412 // suche die naechste Bookmark-Position aus der Bookmark-Tabelle
413 // build a bookmark table, which is sort by the node position. The
414 // OtherPos of the bookmarks also inserted.
415 // search alle Bookmarks in the range and return it in the Array
416 // lege einen neuen PaM an der Position an
417 SwPaM* NewSwPaM( SwDoc & rDoc, ULONG nStartIdx, ULONG nEndIdx ) const;
419 // kopiere ggfs. eine lokale Datei ins Internet
421 // Stream-spezifische Routinen, im Storage-Writer NICHT VERWENDEN!
423 // Optimierung der Ausgabe auf den Stream.
424 SvStream& OutLong( SvStream& rStrm, long nVal );
425 SvStream& OutULong( SvStream& rStrm, ULONG nVal );
427 // Hex-Zahl ausgeben, default ist 2.stellige Zahl
428 SvStream& OutHex( SvStream& rStrm, ULONG nHex, BYTE nLen = 2 );
429 // 4-st. Hex-Zahl ausgeben
430 // 8-st. Hex-Zahl ausgeben
432 inline SvStream& OutHex( USHORT nHex, BYTE nLen = 2 ) { return OutHex( Strm(), nHex, nLen ); }
433 inline SvStream& OutHex4( USHORT nHex ) { return OutHex( Strm(), nHex, 4 ); }
434 //STRIP001 inline SvStream& OutHex8( ULONG nHex ) { return OutHex( Strm(), nHex, 8 ); }
435 inline SvStream& OutLong( long nVal ) { return OutLong( Strm(), nVal ); }
436 inline SvStream& OutULong( ULONG nVal ) { return OutULong( Strm(), nVal ); }
438 void SetStrm( SvStream& rStrm ) { pStrm = &rStrm; }
439 #ifdef PRODUCT
440 SvStream& Strm() { return *pStrm; }
441 #else
442 SvStream& Strm();
443 #endif
445 BOOL IsOrganizerMode() const { return bOrganizerMode; }
446 void SetOrganizerMode( BOOL bSet ) { bOrganizerMode = bSet; }
449 #ifndef SW_DECL_WRITER_DEFINED
450 #define SW_DECL_WRITER_DEFINED
451 SV_DECL_REF(Writer)
452 #endif
453 SV_IMPL_REF(Writer)
455 // Basisklasse fuer alle Storage-Writer
457 class StgWriter : public Writer
459 protected:
460 String aFltName;
461 SvStorage* pStg;
463 // Fehler beim Aufruf erzeugen
464 virtual ULONG WriteStream(){DBG_BF_ASSERT(0, "STRIP"); return 0;} //STRIP001 virtual ULONG WriteStream();
465 virtual ULONG WriteStorage() = 0;
467 public:
468 StgWriter() : Writer(), pStg( 0 ) {}
470 virtual ULONG Write( SwPaM&, SvStorage&, const String* = 0 );
472 SvStorage& GetStorage() const { return *pStg; }
473 const String& GetFltName() const { return aFltName; }
474 void SetFltName( const String& r ) { aFltName = r; }
477 class Sw3Writer : public StgWriter
479 Sw3Io* pIO;
480 BOOL bSaveAs : 1;
482 virtual ULONG WriteStorage();
484 public:
485 Sw3Writer() : pIO( 0 ), bSaveAs( FALSE ) {}
487 Sw3Io* GetSw3Io() { return pIO; }
488 const Sw3Io* GetSw3Io() const { return pIO; }
489 void SetSw3Io( Sw3Io* pIo, BOOL bSvAs = FALSE )
490 { pIO = pIo; bSaveAs = bSvAs; }
496 // Schnittstellenklasse fuer den allgemeinen Zugriff auf die
497 // speziellen Writer
499 class SwWriter
501 SvStream* pStrm;
502 SvStorage* pStg;
503 SfxMedium* pMedium;
505 SwPaM* pOutPam;
506 SwCrsrShell *pShell;
507 SwDoc &rDoc;
508 BOOL bWriteAll;
510 public:
511 ULONG Write( WriterRef& rxWriter, const String* = 0);
513 SwWriter( SvStream&, SwPaM &, BOOL bWriteAll = FALSE );
515 // SwWriter( SvStorage&, SwCrsrShell &,BOOL bWriteAll = FALSE );
516 SwWriter( SvStorage&, SwDoc & );
517 // SwWriter( SvStorage&, SwPaM&, BOOL bWriteAll = FALSE );
519 // SwWriter( SfxMedium&, SwPaM&, BOOL bWriteAll = FALSE );
523 /* \f */
524 /////////////////////////////////////////////////////////////////////////////
526 void GetRTFWriter( const String&, WriterRef& );
527 void GetASCWriter( const String&, WriterRef& );
528 void GetSw3Writer( const String&, WriterRef& );
529 void GetXMLWriter( const String&, WriterRef& );
531 // Die folgende Klasse ist ein Wrappe fuer die Basic-I/O-Funktionen
532 // des Writer 3.0. Alles ist statisch. Alle u.a. Filternamen sind die
533 // Writer-internen Namen, d.h. die namen, die in INSTALL.INI vor dem
534 // Gleichheitszeichen stehen, z.b. SWG oder ASCII.
536 class SwIoSystem
538 public:
539 // suche ueber den Filtertext den Filtereintrag
540 static const SfxFilter* GetFilterOfFilterTxt( const String& rFilterNm,
541 const SfxFactoryFilterContainer* pCnt = 0 );
542 // suche ueber den internen FormatNamen den Filtereintrag
543 static const SfxFilter* GetFilterOfFormat( const String& rFormat,
544 const SfxFactoryFilterContainer* pCnt = 0 );
546 // Feststellen des zu verwendenden Filters fuer die uebergebene
547 // Datei. Der Filtername wird zurueckgeliefert. Konnte kein Filter
548 // zurueckgeliefert werden, wird der Name des ASCII-Filters geliefert!
549 static const SfxFilter* GetFileFilter( const String& rFileName,
550 const String& rPrefFltName,
551 SfxMedium* pMedium = 0 );
553 // Feststellen ob das File in dem vorgegebenen Format vorliegt.
554 // Z.z werden nur unsere eigene Filter unterstuetzt!!
555 static FASTBOOL IsFileFilter( SfxMedium& rMedium, const String& rFmtName,
556 const SfxFilter** ppFlt = 0 );
558 static FASTBOOL IsValidStgFilter( SvStorage& , const SfxFilter& );
560 static bool IsDetectableText(const sal_Char* pBuf, ULONG &rLen,
561 CharSet *pCharSet=0, bool *pSwap=0, LineEnd *pLineEnd=0);
562 static bool IsDetectableW4W(const String& rFileName);
564 static const SfxFilter* GetTextFilter(const sal_Char* pBuf, ULONG nLen);
565 // gebe einen bestimmten Reader zurueck
566 static Reader* GetReader( const String& rFltName );
567 // gebe einen bestimmten Writer zurueck
568 static void GetWriter( const String& rFltName, WriterRef& xWrt );
570 static const String GetSubStorageName( const SfxFilter& rFltr );
574 // ----------------------------------
575 // diese Filter sind immer vorhanden und koennen ueber die
576 // Formatnamen gesucht werden. Alle anderen Filter sind nur intern
577 // bekannt. Die UI-Seite benutzt die GetReader()/GetWriter() -Funktionen,
578 // um die speziellen zu erhalten.
580 extern sal_Char __FAR_DATA FILTER_SWG[]; // SWG-Filter
581 extern sal_Char __FAR_DATA FILTER_RTF[]; // RTF-Filter
582 extern sal_Char __FAR_DATA FILTER_TEXT[]; // Text-Filter mit Default-CodeSet
583 extern sal_Char __FAR_DATA FILTER_BAS[]; // StarBasic (identisch mit ANSI)
584 extern sal_Char __FAR_DATA FILTER_W4W[]; // W4W-Filter
585 extern sal_Char __FAR_DATA FILTER_WW8[]; // WinWord 97-Filter
586 extern sal_Char __FAR_DATA FILTER_SW3[]; // SW3-Storage Filter
587 extern sal_Char __FAR_DATA FILTER_SW4[]; // SW4-Storage Filter
588 extern sal_Char __FAR_DATA FILTER_SW4[]; // SW4-Storage Filter
589 extern sal_Char __FAR_DATA FILTER_SW5[]; // SW5-Storage Filter
590 extern sal_Char __FAR_DATA FILTER_SWGV[]; // SWG-Vorlagen Filter
591 extern sal_Char __FAR_DATA FILTER_SW3V[]; // SW3-Storage Vorlagen Filter
592 extern sal_Char __FAR_DATA FILTER_SW4V[]; // SW4-Storage Vorlagen Filter
593 extern sal_Char __FAR_DATA FILTER_SW5V[]; // SW5-Storage Vorlagen Filter
594 extern sal_Char __FAR_DATA FILTER_SWW4V[]; // SW/Web Storage Vorlagen Filter
595 extern sal_Char __FAR_DATA FILTER_SWW5V[]; // SW/Web Storage Vorlagen Filter
596 extern sal_Char __FAR_DATA FILTER_TEXT_DLG[]; // text filter with encoding dialog
597 extern sal_Char __FAR_DATA FILTER_XML[]; // XML filter
598 extern sal_Char __FAR_DATA FILTER_XMLV[]; // XML filter
599 extern sal_Char __FAR_DATA FILTER_XMLVW[]; // XML filter
602 } //namespace binfilter
603 #endif