xref: /trunk/main/sc/source/filter/inc/ftools.hxx (revision 145dc729)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_FTOOLS_HXX
25 #define SC_FTOOLS_HXX
26 
27 #include <vector>
28 #include <map>
29 #include <limits>
30 #include <memory>
31 #include <tools/string.hxx>
32 #include <tools/list.hxx>
33 #include <tools/debug.hxx>
34 #include <oox/helper/helper.hxx>
35 #include "filter.hxx"
36 #include "scdllapi.h"
37 
38 // Common macros ==============================================================
39 
40 /** Expands to a temporary String, created from an ASCII character array. */
41 #define CREATE_STRING( ascii )      String( RTL_CONSTASCII_USTRINGPARAM( ascii ) )
42 
43 // items and item sets --------------------------------------------------------
44 
45 /** Expands to the item (with type 'itemtype') with Which-ID 'which'. */
46 #define GETITEM( itemset, itemtype, which ) \
47     static_cast< const itemtype & >( (itemset).Get( which ) )
48 
49 /** Expands to the value (with type 'valuetype') of the item with Which-ID 'which'. */
50 #define GETITEMVALUE( itemset, itemtype, which, valuetype ) \
51     static_cast< valuetype >( GETITEM( itemset, itemtype, which ).GetValue() )
52 
53 /** Expands to the value of the SfxBoolItem with Which-ID 'which'. */
54 #define GETITEMBOOL( itemset, which ) \
55     GETITEMVALUE( itemset, SfxBoolItem, which, bool )
56 
57 // Global static helpers ======================================================
58 
59 // Value range limit helpers --------------------------------------------------
60 
61 /** Returns the value, if it is not less than nMin, otherwise nMin. */
62 template< typename ReturnType, typename Type >
llimit_cast(Type nValue,ReturnType nMin)63 inline ReturnType llimit_cast( Type nValue, ReturnType nMin )
64 { return static_cast< ReturnType >( ::std::max< Type >( nValue, nMin ) ); }
65 
66 /** Returns the value, if it fits into ReturnType, otherwise the minimum value of ReturnType. */
67 template< typename ReturnType, typename Type >
llimit_cast(Type nValue)68 inline ReturnType llimit_cast( Type nValue )
69 { return llimit_cast( nValue, ::std::numeric_limits< ReturnType >::min() ); }
70 
71 /** Returns the value, if it is not greater than nMax, otherwise nMax. */
72 template< typename ReturnType, typename Type >
ulimit_cast(Type nValue,ReturnType nMax)73 inline ReturnType ulimit_cast( Type nValue, ReturnType nMax )
74 { return static_cast< ReturnType >( ::std::min< Type >( nValue, nMax ) ); }
75 
76 /** Returns the value, if it fits into ReturnType, otherwise the maximum value of ReturnType. */
77 template< typename ReturnType, typename Type >
ulimit_cast(Type nValue)78 inline ReturnType ulimit_cast( Type nValue )
79 { return ulimit_cast( nValue, ::std::numeric_limits< ReturnType >::max() ); }
80 
81 /** Returns the value, if it is not less than nMin and not greater than nMax, otherwise one of the limits. */
82 template< typename ReturnType, typename Type >
limit_cast(Type nValue,ReturnType nMin,ReturnType nMax)83 inline ReturnType limit_cast( Type nValue, ReturnType nMin, ReturnType nMax )
84 { return static_cast< ReturnType >( ::std::max< Type >( ::std::min< Type >( nValue, nMax ), nMin ) ); }
85 
86 /** Returns the value, if it fits into ReturnType, otherwise one of the limits of ReturnType. */
87 template< typename ReturnType, typename Type >
limit_cast(Type nValue)88 inline ReturnType limit_cast( Type nValue )
89 { return limit_cast( nValue, ::std::numeric_limits< ReturnType >::min(), ::std::numeric_limits< ReturnType >::max() ); }
90 
91 // Read from bitfields --------------------------------------------------------
92 
93 /** Returns true, if at least one of the bits set in nMask is set in nBitField. */
94 template< typename Type >
get_flag(Type nBitField,Type nMask)95 inline bool get_flag( Type nBitField, Type nMask )
96 { return (nBitField & nMask) != 0; }
97 
98 /** Returns nSet, if at least one bit of nMask is set in nBitField, otherwise nUnset. */
99 template< typename ReturnType, typename Type >
get_flagvalue(Type nBitField,Type nMask,ReturnType nSet,ReturnType nUnset)100 inline ReturnType get_flagvalue( Type nBitField, Type nMask, ReturnType nSet, ReturnType nUnset )
101 { return ::get_flag( nBitField, nMask ) ? nSet : nUnset; }
102 
103 /** Extracts a value from a bit field.
104     @descr  Returns in rnRet the data fragment from nBitField, that starts at bit nStartBit
105     (0-based, bit 0 is rightmost) with the width of nBitCount. rnRet will be right-aligned (normalized).
106     For instance: extract_value( n, 0x4321, 8, 4 ) stores 3 in n (value in bits 8-11). */
107 template< typename ReturnType, typename Type >
extract_value(Type nBitField,sal_uInt8 nStartBit,sal_uInt8 nBitCount)108 inline ReturnType extract_value( Type nBitField, sal_uInt8 nStartBit, sal_uInt8 nBitCount )
109 { return static_cast< ReturnType >( ((1UL << nBitCount) - 1) & (nBitField >> nStartBit) ); }
110 
111 // Write to bitfields ---------------------------------------------------------
112 
113 /** Sets or clears (according to bSet) all set bits of nMask in rnBitField. */
114 template< typename Type >
set_flag(Type & rnBitField,Type nMask,bool bSet=true)115 inline void set_flag( Type& rnBitField, Type nMask, bool bSet = true )
116 { if( bSet ) rnBitField |= nMask; else rnBitField &= ~nMask; }
117 
118 /** Inserts a value into a bitfield.
119     @descr  Inserts the lower nBitCount bits of nValue into rnBitField, starting
120     there at bit nStartBit. Other contents of rnBitField keep unchanged. */
121 template< typename Type, typename InsertType >
insert_value(Type & rnBitField,InsertType nValue,sal_uInt8 nStartBit,sal_uInt8 nBitCount)122 void insert_value( Type& rnBitField, InsertType nValue, sal_uInt8 nStartBit, sal_uInt8 nBitCount )
123 {
124     unsigned long nMask = ((1UL << nBitCount) - 1);
125     Type nNewValue = static_cast< Type >( nValue & nMask );
126     (rnBitField &= ~(nMask << nStartBit)) |= (nNewValue << nStartBit);
127 }
128 
129 // ============================================================================
130 
131 /** Deriving from this class prevents copy construction. */
132 class ScfNoCopy
133 {
134 private:
135                         ScfNoCopy( const ScfNoCopy& );
136     ScfNoCopy&          operator=( const ScfNoCopy& );
137 protected:
ScfNoCopy()138     inline              ScfNoCopy() {}
139 };
140 
141 // ----------------------------------------------------------------------------
142 
143 /** Deriving from this class prevents construction in general. */
144 class ScfNoInstance : private ScfNoCopy {};
145 
146 // ============================================================================
147 
148 /** Simple shared pointer (NOT thread-save, but faster than boost::shared_ptr). */
149 template< typename Type >
150 class ScfRef
151 {
152     template< typename > friend class ScfRef;
153 
154 public:
155     typedef Type        element_type;
156     typedef ScfRef      this_type;
157 
ScfRef(element_type * pObj=0)158     inline explicit     ScfRef( element_type* pObj = 0 ) { eat( pObj ); }
ScfRef(const this_type & rRef)159     inline /*implicit*/ ScfRef( const this_type& rRef ) { eat( rRef.mpObj, rRef.mpnCount ); }
160     template< typename Type2 >
ScfRef(const ScfRef<Type2> & rRef)161     inline /*implicit*/ ScfRef( const ScfRef< Type2 >& rRef ) { eat( rRef.mpObj, rRef.mpnCount ); }
~ScfRef()162     inline              ~ScfRef() { rel(); }
163 
reset(element_type * pObj=0)164     inline void         reset( element_type* pObj = 0 ) { rel(); eat( pObj ); }
operator =(const this_type & rRef)165     inline this_type&   operator=( const this_type& rRef ) { if( this != &rRef ) { rel(); eat( rRef.mpObj, rRef.mpnCount ); } return *this; }
166     template< typename Type2 >
operator =(const ScfRef<Type2> & rRef)167     inline this_type&   operator=( const ScfRef< Type2 >& rRef ) { rel(); eat( rRef.mpObj, rRef.mpnCount ); return *this; }
168 
get() const169     inline element_type* get() const { return mpObj; }
is() const170     inline bool         is() const { return mpObj != 0; }
171 
operator ->() const172     inline element_type* operator->() const { return mpObj; }
operator *() const173     inline element_type& operator*() const { return *mpObj; }
174 
operator !() const175     inline bool         operator!() const { return mpObj == 0; }
176 
177 private:
eat(element_type * pObj,size_t * pnCount=0)178     inline void         eat( element_type* pObj, size_t* pnCount = 0 ) { mpObj = pObj; mpnCount = mpObj ? (pnCount ? pnCount : new size_t( 0 )) : 0; if( mpnCount ) ++*mpnCount; }
rel()179     inline void         rel() { if( mpnCount && !--*mpnCount ) { DELETEZ( mpObj ); DELETEZ( mpnCount ); } }
180 
181 private:
182     Type*               mpObj;
183     size_t*             mpnCount;
184 };
185 
186 template< typename Type >
operator ==(const ScfRef<Type> & rxRef1,const ScfRef<Type> & rxRef2)187 inline bool operator==( const ScfRef< Type >& rxRef1, const ScfRef< Type >& rxRef2 )
188 {
189     return rxRef1.get() == rxRef2.get();
190 }
191 
192 template< typename Type >
operator !=(const ScfRef<Type> & rxRef1,const ScfRef<Type> & rxRef2)193 inline bool operator!=( const ScfRef< Type >& rxRef1, const ScfRef< Type >& rxRef2 )
194 {
195     return rxRef1.get() != rxRef2.get();
196 }
197 
198 template< typename Type >
operator <(const ScfRef<Type> & rxRef1,const ScfRef<Type> & rxRef2)199 inline bool operator<( const ScfRef< Type >& rxRef1, const ScfRef< Type >& rxRef2 )
200 {
201     return rxRef1.get() < rxRef2.get();
202 }
203 
204 template< typename Type >
operator >(const ScfRef<Type> & rxRef1,const ScfRef<Type> & rxRef2)205 inline bool operator>( const ScfRef< Type >& rxRef1, const ScfRef< Type >& rxRef2 )
206 {
207     return rxRef1.get() > rxRef2.get();
208 }
209 
210 template< typename Type >
operator <=(const ScfRef<Type> & rxRef1,const ScfRef<Type> & rxRef2)211 inline bool operator<=( const ScfRef< Type >& rxRef1, const ScfRef< Type >& rxRef2 )
212 {
213     return rxRef1.get() <= rxRef2.get();
214 }
215 
216 template< typename Type >
operator >=(const ScfRef<Type> & rxRef1,const ScfRef<Type> & rxRef2)217 inline bool operator>=( const ScfRef< Type >& rxRef1, const ScfRef< Type >& rxRef2 )
218 {
219     return rxRef1.get() >= rxRef2.get();
220 }
221 
222 // ----------------------------------------------------------------------------
223 
224 /** Template for a map of ref-counted objects with additional accessor functions. */
225 template< typename KeyType, typename ObjType >
226 class ScfRefMap : public ::std::map< KeyType, ScfRef< ObjType > >
227 {
228 public:
229     typedef KeyType                             key_type;
230     typedef ScfRef< ObjType >                   ref_type;
231     typedef ::std::map< key_type, ref_type >    map_type;
232 
233     /** Returns true, if the object accossiated to the passed key exists. */
has(key_type nKey) const234     inline bool         has( key_type nKey ) const
235                         {
236                             typename map_type::const_iterator aIt = this->find( nKey );
237                             return (aIt != this->end()) && aIt->second.is();
238                         }
239 
240     /** Returns a reference to the object accossiated to the passed key, or 0 on error. */
get(key_type nKey) const241     inline ref_type     get( key_type nKey ) const
242                         {
243                             typename map_type::const_iterator aIt = this->find( nKey );
244                             if( aIt != this->end() ) return aIt->second;
245                             return ref_type();
246                         }
247 };
248 
249 // ============================================================================
250 
251 class Color;
252 class SfxPoolItem;
253 class SfxItemSet;
254 class ScStyleSheet;
255 class ScStyleSheetPool;
256 class SotStorage;
257 class SotStorageRef;
258 class SotStorageStreamRef;
259 class SvStream;
260 
261 /** Contains static methods used anywhere in the filters. */
262 class ScfTools : ScfNoInstance
263 {
264 public:
265 
266 // *** common methods *** -----------------------------------------------------
267 
268     /** Reads a 10-byte-long-double and converts it to double. */
269     static double       ReadLongDouble( SvStream& rStrm );
270     /** Returns system text encoding for byte string conversion. */
271     static rtl_TextEncoding GetSystemTextEncoding();
272     /** Returns a string representing the hexadecimal value of nValue. */
273     static String       GetHexStr( sal_uInt16 nValue );
274 
275     /** Mixes RGB components with given transparence.
276         @param nTrans  Foreground transparence (0x00 == full nFore ... 0x80 = full nBack). */
277     static sal_uInt8    GetMixedColorComp( sal_uInt8 nFore, sal_uInt8 nBack, sal_uInt8 nTrans );
278     /** Mixes colors with given transparence.
279         @param nTrans  Foreground transparence (0x00 == full rFore ... 0x80 = full rBack). */
280     static Color        GetMixedColor( const Color& rFore, const Color& rBack, sal_uInt8 nTrans );
281 
282 // *** conversion of names *** ------------------------------------------------
283 
284     /** Converts a string to a valid Calc defined name or database range name.
285         @descr  Defined names in Calc may contain letters, digits (*), underscores, periods (*),
286         colons (*), question marks, and dollar signs.
287         (*) = not allowed at first position. */
288     static void         ConvertToScDefinedName( String& rName );
289 
290 // *** streams and storages *** -----------------------------------------------
291 
292     /** Tries to open an existing storage with the specified name in the passed storage (read-only). */
293     static SotStorageRef OpenStorageRead( SotStorageRef xStrg, const String& rStrgName );
294     /** Creates and opens a storage with the specified name in the passed storage (read/write). */
295     static SotStorageRef OpenStorageWrite( SotStorageRef xStrg, const String& rStrgName );
296 
297     /** Tries to open an existing stream with the specified name in the passed storage (read-only). */
298     static SotStorageStreamRef OpenStorageStreamRead( SotStorageRef xStrg, const String& rStrmName );
299     /** Creates and opens a stream with the specified name in the passed storage (read/write). */
300     static SotStorageStreamRef OpenStorageStreamWrite( SotStorageRef xStrg, const String& rStrmName );
301 
302 // *** item handling *** ------------------------------------------------------
303 
304     /** Returns true, if the passed item set contains the item.
305         @param bDeep  true = Searches in parent item sets too. */
306     static bool         CheckItem( const SfxItemSet& rItemSet, sal_uInt16 nWhichId, bool bDeep );
307     /** Returns true, if the passed item set contains at least one of the items.
308         @param pnWhichIds  Zero-terminated array of Which-IDs.
309         @param bDeep  true = Searches in parent item sets too. */
310     static bool         CheckItems( const SfxItemSet& rItemSet, const sal_uInt16* pnWhichIds, bool bDeep );
311 
312     /** Puts the item into the passed item set.
313         @descr  The item will be put into the item set, if bSkipPoolDef is false,
314         or if the item differs from the default pool item.
315         @param rItemSet  The destination item set.
316         @param rItem  The item to put into the item set.
317         @param nWhichId  The Which-ID to set with the item.
318         @param bSkipPoolDef  true = Do not put item if it is equal to pool default; false = Always put the item. */
319     static void         PutItem(
320                             SfxItemSet& rItemSet, const SfxPoolItem& rItem,
321                             sal_uInt16 nWhichId, bool bSkipPoolDef );
322 
323     /** Puts the item into the passed item set.
324         @descr  The item will be put into the item set, if bSkipPoolDef is false,
325         or if the item differs from the default pool item.
326         @param rItemSet  The destination item set.
327         @param rItem  The item to put into the item set.
328         @param bSkipPoolDef  true = Do not put item if it is equal to pool default; false = Always put the item. */
329     static void         PutItem( SfxItemSet& rItemSet, const SfxPoolItem& rItem, bool bSkipPoolDef );
330 
331 // *** style sheet handling *** -----------------------------------------------
332 
333     /** Creates and returns a cell style sheet and inserts it into the pool.
334         @descr  If the style sheet is already in the pool, another unused style name is used.
335         @param bForceName  Controls behaviour, if the style already exists:
336         true = Old existing style will be renamed; false = New style gets another name. */
337     static ScStyleSheet& MakeCellStyleSheet(
338                             ScStyleSheetPool& rPool,
339                             const String& rStyleName, bool bForceName );
340     /** Creates and returns a page style sheet and inserts it into the pool.
341         @descr  If the style sheet is already in the pool, another unused style name is used.
342         @param bForceName  Controls behaviour, if the style already exists:
343         true = Old existing style will be renamed; false = New style gets another name. */
344     static ScStyleSheet& MakePageStyleSheet(
345                             ScStyleSheetPool& rPool,
346                             const String& rStyleName, bool bForceName );
347 
348 // *** byte string import operations *** --------------------------------------
349 
350     /** Reads and returns a zero terminted byte string. */
351     static ByteString   ReadCString( SvStream& rStrm );
352     /** Reads and returns a zero terminted byte string. */
ReadCString(SvStream & rStrm,rtl_TextEncoding eTextEnc)353     inline static String ReadCString( SvStream& rStrm, rtl_TextEncoding eTextEnc )
354                             { return String( ReadCString( rStrm ), eTextEnc ); }
355 
356     /** Reads and returns a zero terminted byte string and decreases a stream counter. */
357     static ByteString   ReadCString( SvStream& rStrm, sal_Int32& rnBytesLeft );
358     /** Reads and returns a zero terminted byte string and decreases a stream counter. */
ReadCString(SvStream & rStrm,sal_Int32 & rnBytesLeft,rtl_TextEncoding eTextEnc)359     inline static String ReadCString( SvStream& rStrm, sal_Int32& rnBytesLeft, rtl_TextEncoding eTextEnc )
360                             { return String( ReadCString( rStrm, rnBytesLeft ), eTextEnc ); }
361 
362     /** Appends a zero terminted byte string.
363         @param nLen
364                The previous length of the string, usually rString.Len(), but
365                necessary as this may be called from within AppendCString()
366                where rString is a temporary ByteString to be appended to
367                UniString. */
368     static void         AppendCStringWithLen( SvStream& rStrm, ByteString& rString, sal_uInt32 nLen );
369     /** Appends a zero terminted byte string. */
370     static void         AppendCString( SvStream& rStrm, String& rString, rtl_TextEncoding eTextEnc );
371 
372 // *** HTML table names <-> named range names *** -----------------------------
373 
374     /** Returns the built-in range name for an HTML document. */
375     static const String& GetHTMLDocName();
376     /** Returns the built-in range name for all HTML tables. */
377     static const String& GetHTMLTablesName();
378     /** Returns the built-in range name for an HTML table, specified by table index. */
379     static String       GetNameFromHTMLIndex( sal_uInt32 nIndex );
380     /** Returns the built-in range name for an HTML table, specified by table name. */
381     static String       GetNameFromHTMLName( const String& rTabName );
382 
383     /** Returns true, if rSource is the built-in range name for an HTML document. */
384     static bool         IsHTMLDocName( const String& rSource );
385     /** Returns true, if rSource is the built-in range name for all HTML tables. */
386     static bool         IsHTMLTablesName( const String& rSource );
387     /** Converts a built-in range name to an HTML table name.
388         @param rSource  The string to be determined.
389         @param rName  The HTML table name.
390         @return  true, if conversion was successful. */
391     static bool         GetHTMLNameFromName( const String& rSource, String& rName );
392 
393 private:
394     /** Returns the prefix for table index names. */
395     static const String& GetHTMLIndexPrefix();
396     /** Returns the prefix for table names. */
397     static const String& GetHTMLNamePrefix();
398 };
399 
400 // Containers =================================================================
401 
402 typedef ::std::vector< sal_uInt8 >                  ScfUInt8Vec;
403 typedef ::std::vector< sal_Int16 >                  ScfInt16Vec;
404 typedef ::std::vector< sal_uInt16 >                 ScfUInt16Vec;
405 typedef ::std::vector< sal_Int32 >                  ScfInt32Vec;
406 typedef ::std::vector< sal_uInt32 >                 ScfUInt32Vec;
407 typedef ::std::vector< sal_Int64 >                  ScfInt64Vec;
408 typedef ::std::vector< sal_uInt64 >                 ScfUInt64Vec;
409 typedef ::std::vector< String >                     ScfStringVec;
410 
411 // ----------------------------------------------------------------------------
412 
413 /** Template for a list that owns the contained objects.
414     @descr  This list stores pointers to objects and deletes the objects itself
415     on destruction. The Clear() method deletes all objects too. */
416 template< typename Type > class ScfDelList
417 {
418 public:
ScfDelList(sal_uInt16 nInitSize=16,sal_uInt16 nResize=16)419     inline explicit     ScfDelList( sal_uInt16 nInitSize = 16, sal_uInt16 nResize = 16 ) :
420                             maList( nInitSize, nResize ) {}
421     /** Creates a deep copy of the passed list (copy-constructs all contained objects). */
ScfDelList(const ScfDelList & rSrc)422     inline explicit     ScfDelList( const ScfDelList& rSrc ) { *this = rSrc; }
423     virtual             ~ScfDelList();
424 
425     /** Creates a deep copy of the passed list (copy-constructs all contained objects). */
426     ScfDelList&         operator=( const ScfDelList& rSrc );
427 
Insert(Type * pObj,sal_uLong nIndex)428     inline void         Insert( Type* pObj, sal_uLong nIndex )      { if( pObj ) maList.Insert( pObj, nIndex ); }
Append(Type * pObj)429     inline void         Append( Type* pObj )                    { if( pObj ) maList.Insert( pObj, LIST_APPEND ); }
430     /** Removes the object without deletion. */
Remove(sal_uLong nIndex)431     inline Type*        Remove( sal_uLong nIndex )                  { return static_cast< Type* >( maList.Remove( nIndex ) ); }
432     /** Removes and deletes the object. */
Delete(sal_uLong nIndex)433     inline void         Delete( sal_uLong nIndex )                  { delete Remove( nIndex ); }
434     /** Exchanges the contained object with the passed, returns the old. */
Exchange(Type * pObj,sal_uLong nIndex)435     inline Type*        Exchange( Type* pObj, sal_uLong nIndex )    { return static_cast< Type* >( maList.Replace( pObj, nIndex ) ); }
436     /** Replaces (deletes) the contained object. */
Replace(Type * pObj,sal_uLong nIndex)437     inline void         Replace( Type* pObj, sal_uLong nIndex )     { delete Exchange( pObj, nIndex ); }
438 
439     void                Clear();
Count() const440     inline sal_uLong        Count() const                           { return maList.Count(); }
Empty() const441     inline bool         Empty() const                           { return maList.Count() == 0; }
442 
GetCurObject() const443     inline Type*        GetCurObject() const                    { return static_cast< Type* >( maList.GetCurObject() ); }
GetCurPos() const444     inline sal_uLong        GetCurPos() const                       { return maList.GetCurPos(); }
GetObject(sal_uInt32 nIndex) const445     inline Type*        GetObject( sal_uInt32 nIndex ) const    { return static_cast< Type* >( maList.GetObject( nIndex ) ); }
446 
First() const447     inline Type*        First() const                           { return static_cast< Type* >( maList.First() ); }
Last() const448     inline Type*        Last() const                            { return static_cast< Type* >( maList.Last() ); }
Next() const449     inline Type*        Next() const                            { return static_cast< Type* >( maList.Next() ); }
Prev() const450     inline Type*        Prev() const                            { return static_cast< Type* >( maList.Prev() ); }
451 
452 private:
453     mutable List        maList;     /// The base container object.
454 };
455 
operator =(const ScfDelList & rSrc)456 template< typename Type > ScfDelList< Type >& ScfDelList< Type >::operator=( const ScfDelList& rSrc )
457 {
458     Clear();
459     for( const Type* pObj = rSrc.First(); pObj; pObj = rSrc.Next() )
460         Append( new Type( *pObj ) );
461     return *this;
462 }
463 
~ScfDelList()464 template< typename Type > ScfDelList< Type >::~ScfDelList()
465 {
466     Clear();
467 }
468 
Clear()469 template< typename Type > void ScfDelList< Type >::Clear()
470 {
471     for( Type* pObj = First(); pObj; pObj = Next() )
472         delete pObj;
473     maList.Clear();
474 }
475 
476 // ----------------------------------------------------------------------------
477 
478 /** Template for a stack that owns the contained objects.
479     @descr  This stack stores pointers to objects and deletes the objects
480     itself on destruction. The Clear() method deletes all objects too.
481     The Pop() method removes the top object from stack without deletion. */
482 template< typename Type >
483 class ScfDelStack : private ScfDelList< Type >
484 {
485 public:
ScfDelStack(sal_uInt16 nInitSize=16,sal_uInt16 nResize=16)486     inline              ScfDelStack( sal_uInt16 nInitSize = 16, sal_uInt16 nResize = 16 ) :
487                             ScfDelList< Type >( nInitSize, nResize ) {}
488 
Push(Type * pObj)489     inline void         Push( Type* pObj )      { Append( pObj ); }
490     /** Removes the top object without deletion. */
Pop()491     inline Type*        Pop()                   { return Remove( Count() - 1 ); }
492 
Top() const493     inline Type*        Top() const             { return GetObject( Count() - 1 ); }
494 
495     using               ScfDelList< Type >::Clear;
496     using               ScfDelList< Type >::Count;
497     using               ScfDelList< Type >::Empty;
498 };
499 
500 // ----------------------------------------------------------------------------
501 class ScFormatFilterPluginImpl : public ScFormatFilterPlugin {
502   public:
503     ScFormatFilterPluginImpl();
504     // various import filters
505     virtual FltError ScImportLotus123( SfxMedium&, ScDocument*, CharSet eSrc = RTL_TEXTENCODING_DONTKNOW );
506     virtual FltError ScImportQuattroPro( SfxMedium &rMedium, ScDocument *pDoc );
507     virtual FltError ScImportExcel( SfxMedium&, ScDocument*, const EXCIMPFORMAT );
508         // eFormat == EIF_AUTO	-> passender Filter wird automatisch verwendet
509         // eFormat == EIF_BIFF5	-> nur Biff5-Stream fuehrt zum Erfolg (auch wenn in einem Excel97-Doc)
510         // eFormat == EIF_BIFF8	-> nur Biff8-Stream fuehrt zum Erfolg (nur in Excel97-Docs)
511         // eFormat == EIF_BIFF_LE4 -> nur Nicht-Storage-Dateien _koennen_ zum Erfolg fuehren
512     virtual FltError ScImportStarCalc10( SvStream&, ScDocument* );
513     virtual FltError ScImportDif( SvStream&, ScDocument*, const ScAddress& rInsPos,
514 				 const CharSet eSrc = RTL_TEXTENCODING_DONTKNOW, sal_uInt32 nDifOption = SC_DIFOPT_EXCEL );
515     virtual FltError ScImportRTF( SvStream&, const String& rBaseURL, ScDocument*, ScRange& rRange );
516     virtual FltError ScImportHTML( SvStream&, const String& rBaseURL, ScDocument*, ScRange& rRange,
517                                    double nOutputFactor = 1.0, sal_Bool bCalcWidthHeight = sal_True,
518                                    SvNumberFormatter* pFormatter = NULL, bool bConvertDate = true );
519 
520     virtual ScEEAbsImport *CreateRTFImport( ScDocument* pDoc, const ScRange& rRange );
521     virtual ScEEAbsImport *CreateHTMLImport( ScDocument* pDocP, const String& rBaseURL, const ScRange& rRange, sal_Bool bCalcWidthHeight );
522     virtual String         GetHTMLRangeNameList( ScDocument* pDoc, const String& rOrigName );
523 
524     // various export filters
525 #if ENABLE_LOTUS123_EXPORT
526     virtual FltError ScExportLotus123( SvStream&, ScDocument*, ExportFormatLotus, CharSet eDest );
527 #endif
528     virtual FltError ScExportExcel5( SfxMedium&, ScDocument*, ExportFormatExcel eFormat, CharSet eDest );
529     virtual FltError ScExportDif( SvStream&, ScDocument*, const ScAddress& rOutPos, const CharSet eDest,
530                                  sal_uInt32 nDifOption = SC_DIFOPT_EXCEL );
531     virtual FltError ScExportDif( SvStream&, ScDocument*, const ScRange& rRange, const CharSet eDest,
532 				 sal_uInt32 nDifOption = SC_DIFOPT_EXCEL );
533     virtual FltError ScExportHTML( SvStream&, const String& rBaseURL, ScDocument*, const ScRange& rRange, const CharSet eDest, sal_Bool bAll,
534 				  const String& rStreamPath, String& rNonConvertibleChars );
535     virtual FltError ScExportRTF( SvStream&, ScDocument*, const ScRange& rRange, const CharSet eDest );
536 };
537 
538 // ============================================================================
539 
540 #endif
541