1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <boost/shared_ptr.hpp>
31 #include <sot/storage.hxx>
32 #include <vcl/bitmapex.hxx>
34 #include <com/sun/star/util/DateTime.hpp>
35 #include <com/sun/star/util/Date.hpp>
38 // ============================================================================
42 // ============================================================================
44 const sal_Int32 PROPTYPE_INT16
= 2;
45 const sal_Int32 PROPTYPE_INT32
= 3;
46 const sal_Int32 PROPTYPE_FLOAT
= 4;
47 const sal_Int32 PROPTYPE_DOUBLE
= 5;
48 const sal_Int32 PROPTYPE_DATE
= 7;
49 const sal_Int32 PROPTYPE_STRING
= 8;
50 const sal_Int32 PROPTYPE_STATUS
= 10;
51 const sal_Int32 PROPTYPE_BOOL
= 11;
52 const sal_Int32 PROPTYPE_VARIANT
= 12;
53 const sal_Int32 PROPTYPE_INT8
= 16;
54 const sal_Int32 PROPTYPE_UINT8
= 17;
55 const sal_Int32 PROPTYPE_UINT16
= 18;
56 const sal_Int32 PROPTYPE_UINT32
= 19;
57 const sal_Int32 PROPTYPE_INT64
= 20;
58 const sal_Int32 PROPTYPE_UINT64
= 21;
59 const sal_Int32 PROPTYPE_STRING8
= 30;
60 const sal_Int32 PROPTYPE_STRING16
= 31;
61 const sal_Int32 PROPTYPE_FILETIME
= 64;
62 const sal_Int32 PROPTYPE_BLOB
= 65;
63 const sal_Int32 PROPTYPE_CLIPFMT
= 71;
65 // static property IDs
66 const sal_Int32 PROPID_DICTIONARY
= 0;
67 const sal_Int32 PROPID_CODEPAGE
= 1;
68 const sal_Int32 PROPID_FIRSTCUSTOM
= 2;
70 // property IDs for GlobalDocPropertySet
71 const sal_Int32 PROPID_TITLE
= 2;
72 const sal_Int32 PROPID_SUBJECT
= 3;
73 const sal_Int32 PROPID_AUTHOR
= 4;
74 const sal_Int32 PROPID_KEYWORDS
= 5;
75 const sal_Int32 PROPID_COMMENTS
= 6;
76 const sal_Int32 PROPID_TEMPLATE
= 7;
77 const sal_Int32 PROPID_LASTAUTHOR
= 8;
78 const sal_Int32 PROPID_REVNUMBER
= 9;
79 const sal_Int32 PROPID_EDITTIME
= 10;
80 const sal_Int32 PROPID_LASTPRINTED
= 11;
81 const sal_Int32 PROPID_CREATED
= 12;
82 const sal_Int32 PROPID_LASTSAVED
= 13;
83 const sal_Int32 PROPID_THUMBNAIL
= 17;
85 // some Builtin properties
86 const sal_Int32 PROPID_CATEGORY
= 0x2;
87 const sal_Int32 PROPID_COMPANY
= 0xf;
88 const sal_Int32 PROPID_MANAGER
= 0xe;
89 // predefined codepages
90 const sal_uInt16 CODEPAGE_UNKNOWN
= 0;
91 const sal_uInt16 CODEPAGE_UNICODE
= 1200;
92 const sal_uInt16 CODEPAGE_UTF8
= 65001;
94 // predefined clipboard format IDs
95 const sal_Int32 CLIPFMT_WIN
= -1;
97 // predefined clipboard data format IDs
98 const sal_Int32 CLIPDATAFMT_DIB
= 8;
100 // ============================================================================
102 /** Helper for classes that need text encoding settings.
104 Classes derived from this class will include functions to store and use
105 text encoding settings and to convert Windows codepage constants.
107 class SfxOleTextEncoding
110 inline explicit SfxOleTextEncoding() :
111 mxTextEnc( new rtl_TextEncoding( osl_getThreadTextEncoding() ) ) {}
112 inline explicit SfxOleTextEncoding( rtl_TextEncoding eTextEnc
) :
113 mxTextEnc( new rtl_TextEncoding( eTextEnc
) ) {}
114 inline explicit SfxOleTextEncoding( sal_Int16 nCodePage
) :
115 mxTextEnc( new rtl_TextEncoding
) { SetCodePage( nCodePage
); }
117 /** Returns the current text encoding identifier. */
118 inline rtl_TextEncoding
GetTextEncoding() const { return *mxTextEnc
; }
119 /** Sets the passed text encoding. */
120 inline void SetTextEncoding( rtl_TextEncoding eTextEnc
) { *mxTextEnc
= eTextEnc
; }
122 /** Returns true, if this object contains Unicode text encoding. */
123 inline bool IsUnicode() const { return GetTextEncoding() == RTL_TEXTENCODING_UCS2
; }
124 /** Sets Unicode text encoding to this object. */
125 inline void SetUnicode() { SetTextEncoding( RTL_TEXTENCODING_UCS2
); }
127 /** Converts the current settings to a Windows codepage identifier. */
128 sal_uInt16
GetCodePage() const;
129 /** Sets the current text encoding from a Windows codepage identifier. */
130 void SetCodePage( sal_uInt16 nCodePage
);
133 typedef ::boost::shared_ptr
< rtl_TextEncoding
> TextEncRef
;
134 TextEncRef mxTextEnc
;
137 // ============================================================================
139 /** Helper for classes that need to load or save string values.
141 Classes derived from this class contain functions to load and save string
142 values with the text encoding passed in the constructor.
144 class SfxOleStringHelper
: public SfxOleTextEncoding
147 /** Creates a string helper object depending on an external text encoding. */
148 inline explicit SfxOleStringHelper( const SfxOleTextEncoding
& rTextEnc
) :
149 SfxOleTextEncoding( rTextEnc
) {}
150 /** Creates a string helper object with own text encoding. */
151 inline explicit SfxOleStringHelper( rtl_TextEncoding eTextEnc
) :
152 SfxOleTextEncoding( eTextEnc
) {}
154 /** Loads a string from the passed stream with current encoding (maybe Unicode). */
155 String
LoadString8( SvStream
& rStrm
) const;
156 /** Saves a string to the passed stream with current encoding (maybe Unicode). */
157 void SaveString8( SvStream
& rStrm
, const String
& rValue
) const;
159 /** Loads a Unicode string from the passed stream, ignores own encoding. */
160 String
LoadString16( SvStream
& rStrm
) const;
161 /** Saves a Unicode string to the passed stream, ignores own encoding. */
162 void SaveString16( SvStream
& rStrm
, const String
& rValue
) const;
165 String
ImplLoadString8( SvStream
& rStrm
) const;
166 String
ImplLoadString16( SvStream
& rStrm
) const;
167 void ImplSaveString8( SvStream
& rStrm
, const String
& rValue
) const;
168 void ImplSaveString16( SvStream
& rStrm
, const String
& rValue
) const;
171 // ============================================================================
173 /** Base class for all classes related to OLE property sets.
175 Derived calsses have to implement the pure virtual functions ImplLoad() and
178 class SfxOleObjectBase
181 inline explicit SfxOleObjectBase() : mnErrCode( ERRCODE_NONE
) {}
182 virtual ~SfxOleObjectBase();
184 /** Returns true, if an error code (other than ERRCODE_NONE) is set. */
185 inline bool HasError() const { return mnErrCode
!= ERRCODE_NONE
; }
186 /** Returns the current error code. */
187 inline ErrCode
GetError() const { return mnErrCode
; }
189 /** Loads this object from the passed stream. Calls virtual ImplLoad(). */
190 ErrCode
Load( SvStream
& rStrm
);
191 /** Saves this object to the passed stream. Calls virtual ImplSave(). */
192 ErrCode
Save( SvStream
& rStrm
);
195 /** Sets the passed error code. Will be returned by Load() and Save() functions.
196 Always the first error code is stored. Multiple calls have no effect. */
197 inline void SetError( ErrCode nErrCode
) { if( !HasError() ) mnErrCode
= nErrCode
; }
198 /** Loads the passed object from the stream. Sets returned error code as own error. */
199 void LoadObject( SvStream
& rStrm
, SfxOleObjectBase
& rObj
);
200 /** Saves the passed object to the stream. Sets returned error code as own error. */
201 void SaveObject( SvStream
& rStrm
, SfxOleObjectBase
& rObj
);
204 /** Derived classes implement loading the object from the passed steam. */
205 virtual void ImplLoad( SvStream
& rStrm
) = 0;
206 /** Derived classes implement saving the object to the passed steam. */
207 virtual void ImplSave( SvStream
& rStrm
) = 0;
210 ErrCode mnErrCode
; /// Current error code.
213 // ============================================================================
215 /** Base class for all OLE property objects. */
216 class SfxOlePropertyBase
: public SfxOleObjectBase
219 inline explicit SfxOlePropertyBase( sal_Int32 nPropId
, sal_Int32 nPropType
) :
220 mnPropId( nPropId
), mnPropType( nPropType
) {}
222 inline sal_Int32
GetPropId() const { return mnPropId
; }
223 inline sal_Int32
GetPropType() const { return mnPropType
; }
226 inline void SetPropId( sal_Int32 nPropId
) { mnPropId
= nPropId
; }
227 inline void SetPropType( sal_Int32 nPropType
) { mnPropType
= nPropType
; }
231 sal_Int32 mnPropType
;
234 typedef ::boost::shared_ptr
< SfxOlePropertyBase
> SfxOlePropertyRef
;
236 // ============================================================================
237 /** Property representing the codepage used to encode bytestrings in the entire property set. */
238 class SfxOleCodePageProperty
: public SfxOlePropertyBase
, public SfxOleTextEncoding
241 explicit SfxOleCodePageProperty();
244 virtual void ImplLoad( SvStream
& rStrm
);
245 virtual void ImplSave( SvStream
& rStrm
);
248 // ============================================================================
250 /** Property containing custom names for other properties in the property set. */
251 class SfxOleDictionaryProperty
: public SfxOlePropertyBase
, public SfxOleStringHelper
254 explicit SfxOleDictionaryProperty( const SfxOleTextEncoding
& rTextEnc
);
256 /** Returns true, if the property contains at least one custom property name. */
257 inline bool HasPropertyNames() const { return !maPropNameMap
.empty(); }
258 /** Prepares the property for loading. Does not affect contained names for its own. */
259 inline void SetNameCount( sal_Int32 nNameCount
) { SetPropType( nNameCount
); }
261 /** Returns the custom name for the passed property ID, or an empty string, if name not found. */
262 const String
& GetPropertyName( sal_Int32 nPropId
) const;
263 /** Sets a custom name for the passed property ID. */
264 void SetPropertyName( sal_Int32 nPropId
, const String
& rPropName
);
267 virtual void ImplLoad( SvStream
& rStrm
);
268 virtual void ImplSave( SvStream
& rStrm
);
271 typedef ::std::map
< sal_Int32
, String
> SfxOlePropNameMap
;
272 SfxOlePropNameMap maPropNameMap
;
275 // ============================================================================
277 /** A section in a property set. Contains properties with unique identifiers. */
278 class SfxOleSection
: public SfxOleObjectBase
281 typedef ::std::map
< sal_Int32
, SfxOlePropertyRef
> SfxOlePropMap
;
284 explicit SfxOleSection( bool bSupportsDict
);
286 /** Returns the property with the passed ID, or an empty reference, if nothing found. */
287 SfxOlePropertyRef
GetProperty( sal_Int32 nPropId
) const;
288 /** Returns the value of a signed int32 property with the passed ID in rnValue.
289 @return true = Property found, rnValue is valid; false = Property not found. */
290 bool GetInt32Value( sal_Int32
& rnValue
, sal_Int32 nPropId
) const;
291 /** Returns the value of a floating-point property with the passed ID in rfValue.
292 @return true = Property found, rfValue is valid; false = Property not found. */
293 bool GetDoubleValue( double& rfValue
, sal_Int32 nPropId
) const;
294 /** Returns the value of a boolean property with the passed ID in rbValue.
295 @return true = Property found, rbValue is valid; false = Property not found. */
296 bool GetBoolValue( bool& rbValue
, sal_Int32 nPropId
) const;
297 /** Returns the value of a string property with the passed ID in rValue.
298 @return true = Property found, rValue is valid; false = Property not found. */
299 bool GetStringValue( String
& rValue
, sal_Int32 nPropId
) const;
300 /** Returns the value of a time stamp property with the passed ID in rValue.
301 @return true = Property found, rValue is valid; false = Property not found. */
302 bool GetFileTimeValue( ::com::sun::star::util::DateTime
& rValue
, sal_Int32 nPropId
) const;
303 /** Returns the value of a date property with the passed ID in rValue.
304 @return true = Property found, rValue is valid; false = Property not found. */
305 bool GetDateValue( ::com::sun::star::util::Date
& rValue
, sal_Int32 nPropId
) const;
307 /** Adds the passed property to the property set. Drops an existing old property. */
308 void SetProperty( SfxOlePropertyRef xProp
);
309 /** Inserts a signed int32 property with the passed value. */
310 void SetInt32Value( sal_Int32 nPropId
, sal_Int32 nValue
);
311 /** Inserts a floating-point property with the passed value. */
312 void SetDoubleValue( sal_Int32 nPropId
, double fValue
);
313 /** Inserts a boolean property with the passed value. */
314 void SetBoolValue( sal_Int32 nPropId
, bool bValue
);
315 /** Inserts a string property with the passed value.
316 @return true = Property inserted; false = String was empty, property not inserted. */
317 bool SetStringValue( sal_Int32 nPropId
, const String
& rValue
, bool bSkipEmpty
= true );
318 /** Inserts a time stamp property with the passed value. */
319 void SetFileTimeValue( sal_Int32 nPropId
, const ::com::sun::star::util::DateTime
& rValue
);
320 /** Inserts a date property with the passed value. */
321 void SetDateValue( sal_Int32 nPropId
, const ::com::sun::star::util::Date
& rValue
);
322 /** Inserts a thumbnail property from the passed meta file. */
323 void SetThumbnailValue( sal_Int32 nPropId
,
324 const ::com::sun::star::uno::Sequence
<sal_uInt8
> & i_rData
);
325 /** Inserts a BLOB property with the passed data. */
326 void SetBlobValue( sal_Int32 nPropId
,
327 const ::com::sun::star::uno::Sequence
<sal_uInt8
> & i_rData
);
329 /** Returns the value of the property with the passed ID in a UNO any. */
330 com::sun::star::uno::Any
GetAnyValue( sal_Int32 nPropId
) const;
331 /** Inserts a property created from the passed any.
332 @return true = Property converted and inserted; false = Property type not supported. */
333 bool SetAnyValue( sal_Int32 nPropId
, const com::sun::star::uno::Any
& rValue
);
335 /** Returns the custom name for the passed property ID, or an empty string, if name not found. */
336 const String
& GetPropertyName( sal_Int32 nPropId
) const;
337 /** Sets a custom name for the passed property ID. */
338 void SetPropertyName( sal_Int32 nPropId
, const String
& rPropName
);
340 /** Returns the identifiers of all existing properties in the passed vector. */
341 void GetPropertyIds( ::std::vector
< sal_Int32
>& rPropIds
) const;
342 /** Returns a property identifier not used in this section. */
343 sal_Int32
GetFreePropertyId() const;
346 virtual void ImplLoad( SvStream
& rStrm
);
347 virtual void ImplSave( SvStream
& rStrm
);
349 bool SeekToPropertyPos( SvStream
& rStrm
, sal_uInt32 nPropPos
) const;
350 void LoadProperty( SvStream
& rStrm
, sal_Int32 nPropId
);
351 void SaveProperty( SvStream
& rStrm
, SfxOlePropertyBase
& rProp
, sal_Size
& rnPropPosPos
);
354 SfxOlePropMap maPropMap
; /// All properties in this section, by identifier.
355 SfxOleCodePageProperty maCodePageProp
; /// The codepage property.
356 SfxOleDictionaryProperty maDictProp
; /// The dictionary property.
357 sal_Size mnStartPos
; /// Start stream position of the section.
358 bool mbSupportsDict
; /// true = section supports dictionary.
361 typedef ::boost::shared_ptr
< SfxOleSection
> SfxOleSectionRef
;
363 // ============================================================================
365 /** Enumerates different section types in OLE property sets. */
366 enum SfxOleSectionType
368 SECTION_GLOBAL
, /// Globally defined properties.
369 SECTION_BUILTIN
, /// Properties built into MS Office.
370 SECTION_CUSTOM
/// Custom properties.
373 // ============================================================================
375 /** Represents a complete property set, may consist of several property sections. */
376 class SfxOlePropertySet
: public SfxOleObjectBase
379 inline explicit SfxOlePropertySet() {}
381 /** Loads this object from the passed storage. */
382 ErrCode
LoadPropertySet( SotStorage
* pStrg
, const String
& rStrmName
);
383 /** Saves this object to the passed storage. */
384 ErrCode
SavePropertySet( SotStorage
* pStrg
, const String
& rStrmName
);
386 /** Returns the specified section, or an empty reference, if nothing found. */
387 SfxOleSectionRef
GetSection( SfxOleSectionType eSection
) const;
388 /** Returns the specified section, or an empty reference, if nothing found. */
389 SfxOleSectionRef
GetSection( const SvGlobalName
& rSectionGuid
) const;
391 /** Creates and returns the specified section, or just returns it if it already exists. */
392 SfxOleSection
& AddSection( SfxOleSectionType eSection
);
393 /** Creates and returns the specified section, or just returns it if it already exists. */
394 SfxOleSection
& AddSection( const SvGlobalName
& rSectionGuid
);
397 virtual void ImplLoad( SvStream
& rStrm
);
398 virtual void ImplSave( SvStream
& rStrm
);
400 /** Returns the GUID for the specified section. */
401 static const SvGlobalName
& GetSectionGuid( SfxOleSectionType eSection
);
404 typedef ::std::map
< SvGlobalName
, SfxOleSectionRef
> SfxOleSectionMap
;
405 SfxOleSectionMap maSectionMap
;
409 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */