merge the formfield patch from ooo-build
[ooovba.git] / sfx2 / source / doc / oleprops.hxx
blob924e13181ddf25dea81766804371ab19bcb8f328
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: oleprops.hxx,v $
10 * $Revision: 1.4 $
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 ************************************************************************/
31 #include <map>
32 #include <boost/shared_ptr.hpp>
33 #include <sot/storage.hxx>
34 #include <vcl/bitmapex.hxx>
36 #include <com/sun/star/util/DateTime.hpp>
39 // ============================================================================
41 //namespace {
43 // ============================================================================
44 // property type IDs
45 const sal_Int32 PROPTYPE_INT16 = 2;
46 const sal_Int32 PROPTYPE_INT32 = 3;
47 const sal_Int32 PROPTYPE_FLOAT = 4;
48 const sal_Int32 PROPTYPE_DOUBLE = 5;
49 const sal_Int32 PROPTYPE_DATE = 7;
50 const sal_Int32 PROPTYPE_STRING = 8;
51 const sal_Int32 PROPTYPE_STATUS = 10;
52 const sal_Int32 PROPTYPE_BOOL = 11;
53 const sal_Int32 PROPTYPE_VARIANT = 12;
54 const sal_Int32 PROPTYPE_INT8 = 16;
55 const sal_Int32 PROPTYPE_UINT8 = 17;
56 const sal_Int32 PROPTYPE_UINT16 = 18;
57 const sal_Int32 PROPTYPE_UINT32 = 19;
58 const sal_Int32 PROPTYPE_INT64 = 20;
59 const sal_Int32 PROPTYPE_UINT64 = 21;
60 const sal_Int32 PROPTYPE_STRING8 = 30;
61 const sal_Int32 PROPTYPE_STRING16 = 31;
62 const sal_Int32 PROPTYPE_FILETIME = 64;
63 const sal_Int32 PROPTYPE_BLOB = 65;
64 const sal_Int32 PROPTYPE_CLIPFMT = 71;
66 // static property IDs
67 const sal_Int32 PROPID_DICTIONARY = 0;
68 const sal_Int32 PROPID_CODEPAGE = 1;
69 const sal_Int32 PROPID_FIRSTCUSTOM = 2;
71 // property IDs for GlobalDocPropertySet
72 const sal_Int32 PROPID_TITLE = 2;
73 const sal_Int32 PROPID_SUBJECT = 3;
74 const sal_Int32 PROPID_AUTHOR = 4;
75 const sal_Int32 PROPID_KEYWORDS = 5;
76 const sal_Int32 PROPID_COMMENTS = 6;
77 const sal_Int32 PROPID_TEMPLATE = 7;
78 const sal_Int32 PROPID_LASTAUTHOR = 8;
79 const sal_Int32 PROPID_REVNUMBER = 9;
80 const sal_Int32 PROPID_EDITTIME = 10;
81 const sal_Int32 PROPID_LASTPRINTED = 11;
82 const sal_Int32 PROPID_CREATED = 12;
83 const sal_Int32 PROPID_LASTSAVED = 13;
84 const sal_Int32 PROPID_THUMBNAIL = 17;
86 // some Builtin properties
87 const sal_Int32 PROPID_CATEGORY = 0x2;
88 const sal_Int32 PROPID_COMPANY = 0xf;
89 const sal_Int32 PROPID_MANAGER = 0xe;
90 // predefined codepages
91 const sal_uInt16 CODEPAGE_UNKNOWN = 0;
92 const sal_uInt16 CODEPAGE_UNICODE = 1200;
93 const sal_uInt16 CODEPAGE_UTF8 = 65001;
95 // predefined clipboard format IDs
96 const sal_Int32 CLIPFMT_WIN = -1;
98 // predefined clipboard data format IDs
99 const sal_Int32 CLIPDATAFMT_DIB = 8;
101 // ============================================================================
102 // ============================================================================
104 /** Helper for classes that need text encoding settings.
106 Classes derived from this class will include functions to store and use
107 text encoding settings and to convert Windows codepage constants.
109 class SfxOleTextEncoding
111 public:
112 inline explicit SfxOleTextEncoding() :
113 mxTextEnc( new rtl_TextEncoding( gsl_getSystemTextEncoding() ) ) {}
114 inline explicit SfxOleTextEncoding( rtl_TextEncoding eTextEnc ) :
115 mxTextEnc( new rtl_TextEncoding( eTextEnc ) ) {}
116 inline explicit SfxOleTextEncoding( sal_Int16 nCodePage ) :
117 mxTextEnc( new rtl_TextEncoding ) { SetCodePage( nCodePage ); }
119 /** Returns the current text encoding identifier. */
120 inline rtl_TextEncoding GetTextEncoding() const { return *mxTextEnc; }
121 /** Sets the passed text encoding. */
122 inline void SetTextEncoding( rtl_TextEncoding eTextEnc ) { *mxTextEnc = eTextEnc; }
124 /** Returns true, if this object contains Unicode text encoding. */
125 inline bool IsUnicode() const { return GetTextEncoding() == RTL_TEXTENCODING_UCS2; }
126 /** Sets Unicode text encoding to this object. */
127 inline void SetUnicode() { SetTextEncoding( RTL_TEXTENCODING_UCS2 ); }
129 /** Converts the current settings to a Windows codepage identifier. */
130 sal_uInt16 GetCodePage() const;
131 /** Sets the current text encoding from a Windows codepage identifier. */
132 void SetCodePage( sal_uInt16 nCodePage );
134 private:
135 typedef ::boost::shared_ptr< rtl_TextEncoding > TextEncRef;
136 TextEncRef mxTextEnc;
139 // ============================================================================
141 /** Helper for classes that need to load or save string values.
143 Classes derived from this class contain functions to load and save string
144 values with the text encoding passed in the constructor.
146 class SfxOleStringHelper : public SfxOleTextEncoding
148 public:
149 /** Creates a string helper object depending on an external text encoding. */
150 inline explicit SfxOleStringHelper( const SfxOleTextEncoding& rTextEnc ) :
151 SfxOleTextEncoding( rTextEnc ) {}
152 /** Creates a string helper object with own text encoding. */
153 inline explicit SfxOleStringHelper( rtl_TextEncoding eTextEnc ) :
154 SfxOleTextEncoding( eTextEnc ) {}
156 /** Loads a string from the passed stream with current encoding (maybe Unicode). */
157 String LoadString8( SvStream& rStrm ) const;
158 /** Saves a string to the passed stream with current encoding (maybe Unicode). */
159 void SaveString8( SvStream& rStrm, const String& rValue ) const;
161 /** Loads a Unicode string from the passed stream, ignores own encoding. */
162 String LoadString16( SvStream& rStrm ) const;
163 /** Saves a Unicode string to the passed stream, ignores own encoding. */
164 void SaveString16( SvStream& rStrm, const String& rValue ) const;
166 private:
167 String ImplLoadString8( SvStream& rStrm ) const;
168 String ImplLoadString16( SvStream& rStrm ) const;
169 void ImplSaveString8( SvStream& rStrm, const String& rValue ) const;
170 void ImplSaveString16( SvStream& rStrm, const String& rValue ) const;
174 // ============================================================================
175 // ============================================================================
177 /** Base class for all classes related to OLE property sets.
179 Derived calsses have to implement the pure virtual functions ImplLoad() and
180 ImplSave().
182 class SfxOleObjectBase
184 public:
185 inline explicit SfxOleObjectBase() : mnErrCode( ERRCODE_NONE ) {}
186 virtual ~SfxOleObjectBase();
188 /** Returns true, if an error code (other than ERRCODE_NONE) is set. */
189 inline bool HasError() const { return mnErrCode != ERRCODE_NONE; }
190 /** Returns the current error code. */
191 inline ErrCode GetError() const { return mnErrCode; }
193 /** Loads this object from the passed stream. Calls virtual ImplLoad(). */
194 ErrCode Load( SvStream& rStrm );
195 /** Saves this object to the passed stream. Calls virtual ImplSave(). */
196 ErrCode Save( SvStream& rStrm );
198 protected:
199 /** Sets the passed error code. Will be returned by Load() and Save() functions.
200 Always the first error code is stored. Multiple calls have no effect. */
201 inline void SetError( ErrCode nErrCode ) { if( !HasError() ) mnErrCode = nErrCode; }
202 /** Loads the passed object from the stream. Sets returned error code as own error. */
203 void LoadObject( SvStream& rStrm, SfxOleObjectBase& rObj );
204 /** Saves the passed object to the stream. Sets returned error code as own error. */
205 void SaveObject( SvStream& rStrm, SfxOleObjectBase& rObj );
207 private:
208 /** Derived classes implement loading the object from the passed steam. */
209 virtual void ImplLoad( SvStream& rStrm ) = 0;
210 /** Derived classes implement saving the object to the passed steam. */
211 virtual void ImplSave( SvStream& rStrm ) = 0;
213 private:
214 ErrCode mnErrCode; /// Current error code.
217 // ============================================================================
218 // ============================================================================
220 /** Base class for all OLE property objects. */
221 class SfxOlePropertyBase : public SfxOleObjectBase
223 public:
224 inline explicit SfxOlePropertyBase( sal_Int32 nPropId, sal_Int32 nPropType ) :
225 mnPropId( nPropId ), mnPropType( nPropType ) {}
227 inline sal_Int32 GetPropId() const { return mnPropId; }
228 inline sal_Int32 GetPropType() const { return mnPropType; }
230 protected:
231 inline void SetPropId( sal_Int32 nPropId ) { mnPropId = nPropId; }
232 inline void SetPropType( sal_Int32 nPropType ) { mnPropType = nPropType; }
234 private:
235 sal_Int32 mnPropId;
236 sal_Int32 mnPropType;
239 typedef ::boost::shared_ptr< SfxOlePropertyBase > SfxOlePropertyRef;
241 // ============================================================================
242 /** Property representing the codepage used to encode bytestrings in the entire property set. */
243 class SfxOleCodePageProperty : public SfxOlePropertyBase, public SfxOleTextEncoding
245 public:
246 explicit SfxOleCodePageProperty();
248 private:
249 virtual void ImplLoad( SvStream& rStrm );
250 virtual void ImplSave( SvStream& rStrm );
253 // ============================================================================
254 // ============================================================================
256 /** Property containing custom names for other properties in the property set. */
257 class SfxOleDictionaryProperty : public SfxOlePropertyBase, public SfxOleStringHelper
259 public:
260 explicit SfxOleDictionaryProperty( const SfxOleTextEncoding& rTextEnc );
262 /** Returns true, if the property contains at least one custom property name. */
263 inline bool HasPropertyNames() const { return !maPropNameMap.empty(); }
264 /** Prepares the property for loading. Does not affect contained names for its own. */
265 inline void SetNameCount( sal_Int32 nNameCount ) { SetPropType( nNameCount ); }
267 /** Returns the custom name for the passed property ID, or an empty string, if name not found. */
268 const String& GetPropertyName( sal_Int32 nPropId ) const;
269 /** Sets a custom name for the passed property ID. */
270 void SetPropertyName( sal_Int32 nPropId, const String& rPropName );
272 private:
273 virtual void ImplLoad( SvStream& rStrm );
274 virtual void ImplSave( SvStream& rStrm );
276 private:
277 typedef ::std::map< sal_Int32, String > SfxOlePropNameMap;
278 SfxOlePropNameMap maPropNameMap;
281 // ============================================================================
282 // ============================================================================
284 /** A section in a property set. Contains properties with unique identifiers. */
285 class SfxOleSection : public SfxOleObjectBase
287 private:
288 typedef ::std::map< sal_Int32, SfxOlePropertyRef > SfxOlePropMap;
290 public:
291 explicit SfxOleSection( bool bSupportsDict );
293 /** Returns the property with the passed ID, or an empty reference, if nothing found. */
294 SfxOlePropertyRef GetProperty( sal_Int32 nPropId ) const;
295 /** Returns the value of a signed int32 property with the passed ID in rnValue.
296 @return true = Property found, rnValue is valid; false = Property not found. */
297 bool GetInt32Value( sal_Int32& rnValue, sal_Int32 nPropId ) const;
298 /** Returns the value of a floating-point property with the passed ID in rfValue.
299 @return true = Property found, rfValue is valid; false = Property not found. */
300 bool GetDoubleValue( double& rfValue, sal_Int32 nPropId ) const;
301 /** Returns the value of a boolean property with the passed ID in rbValue.
302 @return true = Property found, rbValue is valid; false = Property not found. */
303 bool GetBoolValue( bool& rbValue, sal_Int32 nPropId ) const;
304 /** Returns the value of a string property with the passed ID in rValue.
305 @return true = Property found, rValue is valid; false = Property not found. */
306 bool GetStringValue( String& rValue, sal_Int32 nPropId ) const;
307 /** Returns the value of a time stamp property with the passed ID in rValue.
308 @return true = Property found, rValue is valid; false = Property not found. */
309 bool GetFileTimeValue( ::com::sun::star::util::DateTime& rValue, sal_Int32 nPropId ) const;
311 /** Adds the passed property to the property set. Drops an existing old property. */
312 void SetProperty( SfxOlePropertyRef xProp );
313 /** Inserts a signed int32 property with the passed value. */
314 void SetInt32Value( sal_Int32 nPropId, sal_Int32 nValue );
315 /** Inserts a foating-point property with the passed value. */
316 void SetDoubleValue( sal_Int32 nPropId, double fValue );
317 /** Inserts a boolean property with the passed value. */
318 void SetBoolValue( sal_Int32 nPropId, bool bValue );
319 /** Inserts a string property with the passed value.
320 @return true = Property inserted; false = String was empty, property not inserted. */
321 bool SetStringValue( sal_Int32 nPropId, const String& rValue, bool bSkipEmpty = true );
322 /** Inserts a time stamp property with the passed value. */
323 void SetFileTimeValue( sal_Int32 nPropId, const ::com::sun::star::util::DateTime& rValue );
324 /** Inserts a thumbnail property from the passed meta file. */
325 void SetThumbnailValue( sal_Int32 nPropId,
326 const ::com::sun::star::uno::Sequence<sal_uInt8> & i_rData);
327 /** Inserts a BLOB property with the passed data. */
328 void SetBlobValue( sal_Int32 nPropId,
329 const ::com::sun::star::uno::Sequence<sal_uInt8> & i_rData);
331 /** Returns the value of the property with the passed ID in a UNO any. */
332 com::sun::star::uno::Any GetAnyValue( sal_Int32 nPropId ) const;
333 /** Inserts a property created from the passed any.
334 @return true = Property converted and inserted; false = Property type not supported. */
335 bool SetAnyValue( sal_Int32 nPropId, const com::sun::star::uno::Any& rValue );
337 /** Returns the custom name for the passed property ID, or an empty string, if name not found. */
338 const String& GetPropertyName( sal_Int32 nPropId ) const;
339 /** Sets a custom name for the passed property ID. */
340 void SetPropertyName( sal_Int32 nPropId, const String& rPropName );
342 /** Returns the identifiers of all existing properties in the passed vector. */
343 void GetPropertyIds( ::std::vector< sal_Int32 >& rPropIds ) const;
344 /** Returns a property identifier not used in this section. */
345 sal_Int32 GetFreePropertyId() const;
347 private:
348 virtual void ImplLoad( SvStream& rStrm );
349 virtual void ImplSave( SvStream& rStrm );
351 bool SeekToPropertyPos( SvStream& rStrm, sal_uInt32 nPropPos ) const;
352 void LoadProperty( SvStream& rStrm, sal_Int32 nPropId );
353 void SaveProperty( SvStream& rStrm, SfxOlePropertyBase& rProp, sal_Size& rnPropPosPos );
355 private:
356 SfxOlePropMap maPropMap; /// All properties in this section, by identifier.
357 SfxOleCodePageProperty maCodePageProp; /// The codepage property.
358 SfxOleDictionaryProperty maDictProp; /// The dictionary property.
359 sal_Size mnStartPos; /// Start stream position of the section.
360 bool mbSupportsDict; /// true = section supports dictionary.
363 typedef ::boost::shared_ptr< SfxOleSection > SfxOleSectionRef;
365 // ============================================================================
366 // ============================================================================
368 /** Enumerates different section types in OLE property sets. */
369 enum SfxOleSectionType
371 SECTION_GLOBAL, /// Globally defined properties.
372 SECTION_BUILTIN, /// Properties built into MS Office.
373 SECTION_CUSTOM /// Custom properties.
376 // ============================================================================
378 /** Represents a complete property set, may consist of several property sections. */
379 class SfxOlePropertySet : public SfxOleObjectBase
381 public:
382 inline explicit SfxOlePropertySet() {}
384 /** Loads this object from the passed storage. */
385 ErrCode LoadPropertySet( SotStorage* pStrg, const String& rStrmName );
386 /** Saves this object to the passed storage. */
387 ErrCode SavePropertySet( SotStorage* pStrg, const String& rStrmName );
389 /** Returns the specified section, or an empty reference, if nothing found. */
390 SfxOleSectionRef GetSection( SfxOleSectionType eSection ) const;
391 /** Returns the specified section, or an empty reference, if nothing found. */
392 SfxOleSectionRef GetSection( const SvGlobalName& rSectionGuid ) const;
394 /** Creates and returns the specified section, or just returns it if it already exists. */
395 SfxOleSection& AddSection( SfxOleSectionType eSection );
396 /** Creates and returns the specified section, or just returns it if it already exists. */
397 SfxOleSection& AddSection( const SvGlobalName& rSectionGuid );
399 private:
400 virtual void ImplLoad( SvStream& rStrm );
401 virtual void ImplSave( SvStream& rStrm );
403 /** Returns the GUID for the specified section. */
404 static const SvGlobalName& GetSectionGuid( SfxOleSectionType eSection );
406 private:
407 typedef ::std::map< SvGlobalName, SfxOleSectionRef > SfxOleSectionMap;
408 SfxOleSectionMap maSectionMap;
411 //};