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